Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

Commit a12263b

Browse files
author
David de Regt
committed
0.6.13: Removing ugly dependencies.d.ts and sprinkling the interface dependencies at the local module level, where they belong.
1 parent 9cbba76 commit a12263b

7 files changed

Lines changed: 100 additions & 114 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nosqlprovider",
3-
"version": "0.6.12",
3+
"version": "0.6.13",
44
"description": "A cross-browser/platform indexeddb-like client library",
55
"author": "David de Regt <David.de.Regt@microsoft.com>",
66
"scripts": {

src/CordovaNativeSqliteProvider.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,41 @@ import NoSqlProvider = require('./NoSqlProvider');
1515
import SqlProviderBase = require('./SqlProviderBase');
1616
import TransactionLockHelper, { TransactionToken } from './TransactionLockHelper';
1717

18+
// Extending interfaces that should be in lib.d.ts but aren't for some reason.
19+
declare global {
20+
interface Window {
21+
sqlitePlugin: any;
22+
}
23+
}
24+
25+
// declare enum SQLErrors {
26+
// UNKNOWN_ERR = 0,
27+
// DATABASE_ERR = 1,
28+
// VERSION_ERR = 2,
29+
// TOO_LARGE_ERR = 3,
30+
// QUOTA_ERR = 4,
31+
// SYNTAX_ERR = 5,
32+
// CONSTRAINT_ERR = 6,
33+
// TIMEOUT_ERR = 7
34+
// }
35+
36+
interface SQLError {
37+
code: number;
38+
message: string;
39+
}
40+
41+
interface SQLStatementCallback {
42+
(transaction: SQLTransaction, resultSet: SqlProviderBase.SQLResultSet): void;
43+
}
44+
45+
interface SQLStatementErrorCallback {
46+
(transaction: SQLTransaction, error: SQLError): void;
47+
}
48+
49+
interface SQLTransaction {
50+
executeSql(sqlStatement: string, args?: any[], callback?: SQLStatementCallback, errorCallback?: SQLStatementErrorCallback): void;
51+
}
52+
1853
export type SqliteSuccessCallback = () => void;
1954
export type SqliteErrorCallback = (e: Error) => void;
2055

@@ -32,11 +67,14 @@ export interface SqlitePluginDbParams extends SqlitePluginDbOptionalParams {
3267

3368
export interface SqliteDatabase {
3469
openDBs: string[];
35-
transaction(transaction: CordovaTransaction, error: SQLTransactionErrorCallback, success: SQLTransactionCallback): void;
36-
readTransaction(transaction: CordovaTransaction, error: SQLTransactionErrorCallback, success: SQLTransactionCallback): void;
70+
transaction(transaction: CordovaTransaction, error: SqlProviderBase.SQLTransactionErrorCallback,
71+
success: SqlProviderBase.SQLTransactionCallback): void;
72+
readTransaction(transaction: CordovaTransaction, error: SqlProviderBase.SQLTransactionErrorCallback,
73+
success: SqlProviderBase.SQLTransactionCallback): void;
3774
open(success: SqliteSuccessCallback, error: SqliteErrorCallback): void;
3875
close(success: SqliteSuccessCallback, error: SqliteErrorCallback): void;
39-
executeSql(statement: string, params?: any[], success?: SQLStatementCallback, error?: SQLStatementErrorCallback): void;
76+
executeSql(statement: string, params?: any[], success?: SqlProviderBase.SQLStatementCallback,
77+
error?: SqlProviderBase.SQLStatementErrorCallback): void;
4078
}
4179

4280
export interface SqlitePlugin {
@@ -45,7 +83,7 @@ export interface SqlitePlugin {
4583
sqliteFeatures: { isSQLitePlugin: boolean };
4684
}
4785

48-
export interface CordovaTransaction extends SQLTransaction {
86+
export interface CordovaTransaction extends SqlProviderBase.SQLTransaction {
4987
abort(err?: any): void;
5088
}
5189

src/IndexedDbProvider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ import TransactionLockHelper, { TransactionToken } from './TransactionLockHelper
1717

1818
const IndexPrefix = 'nsp_i_';
1919

20+
// Extending interfaces that should be in lib.d.ts but aren't for some reason.
21+
declare global {
22+
interface Window {
23+
_indexedDB: IDBFactory;
24+
mozIndexedDB: IDBFactory;
25+
webkitIndexedDB: IDBFactory;
26+
msIndexedDB: IDBFactory;
27+
}
28+
}
29+
2030
// The DbProvider implementation for IndexedDB. This one is fairly straightforward since the library's access patterns pretty
2131
// closely mirror IndexedDB's. We mostly do a lot of wrapping of the APIs into JQuery promises and have some fancy footwork to
2232
// do semi-automatic schema upgrades.

src/NoSqlProviderUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import _ = require('lodash');
1010

1111
import { KeyComponentType, KeyPathType, KeyType } from './NoSqlProvider';
1212

13+
// Extending interfaces that should be in lib.d.ts but aren't for some reason.
14+
declare global {
15+
interface Document {
16+
documentMode: number;
17+
}
18+
}
19+
1320
export function isIE() {
1421
return (typeof (document) !== 'undefined' && document.all !== null && document.documentMode <= 11) ||
1522
(typeof (navigator) !== 'undefined' && !!navigator.userAgent && navigator.userAgent.indexOf('Edge/') !== -1);

src/SqlProviderBase.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ import NoSqlProvider = require('./NoSqlProvider');
1414
import { ItemType } from './NoSqlProvider';
1515
import NoSqlProviderUtils = require('./NoSqlProviderUtils');
1616

17+
// Extending interfaces that should be in lib.d.ts but aren't for some reason.
18+
export interface SQLVoidCallback {
19+
(): void;
20+
}
21+
22+
export interface SQLTransactionCallback {
23+
(transaction: SQLTransaction): void;
24+
}
25+
26+
export interface SQLTransactionErrorCallback {
27+
(error: SQLError): void;
28+
}
29+
30+
export interface SQLDatabase {
31+
version: string;
32+
33+
changeVersion(oldVersion: string, newVersion: string, callback?: SQLTransactionCallback,
34+
errorCallback?: SQLTransactionErrorCallback, successCallback?: SQLVoidCallback): void;
35+
transaction(callback?: SQLTransactionCallback, errorCallback?: SQLTransactionErrorCallback,
36+
successCallback?: SQLVoidCallback): void;
37+
readTransaction(callback?: SQLTransactionCallback, errorCallback?: SQLTransactionErrorCallback,
38+
successCallback?: SQLVoidCallback): void;
39+
}
40+
1741
const schemaVersionKey = 'schemaVersion';
1842

1943
// This was taked from the sqlite documentation

src/WebSqlProvider.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ import SyncTasks = require('synctasks');
1212
import NoSqlProvider = require('./NoSqlProvider');
1313
import SqlProviderBase = require('./SqlProviderBase');
1414

15+
// Extending interfaces that should be in lib.d.ts but aren't for some reason.
16+
export interface SQLDatabaseCallback {
17+
(database: SqlProviderBase.SQLDatabase): void;
18+
}
19+
20+
declare global {
21+
interface Window {
22+
openDatabase(database_name: string, database_version: string, database_displayname: string,
23+
database_size?: number, creationCallback?: SQLDatabaseCallback): SqlProviderBase.SQLDatabase;
24+
}
25+
}
26+
1527
// The DbProvider implementation for WebSQL. This provider does a bunch of awkward stuff to pretend that a relational SQL store
1628
// is actually a NoSQL store. We store the raw object as a JSON.encoded string in the nsp_data column, and have an nsp_pk column
1729
// for the primary keypath value, then nsp_i_[index name] columns for each of the indexes.
1830
export class WebSqlProvider extends SqlProviderBase.SqlProviderBase {
19-
private _db: Database|undefined;
31+
private _db: SqlProviderBase.SQLDatabase|undefined;
2032

2133
constructor(supportsFTS3 = true) {
2234
super(supportsFTS3);
@@ -104,11 +116,11 @@ export class WebSqlProvider extends SqlProviderBase.SqlProviderBase {
104116
let ourTrans: SqlProviderBase.SqliteSqlTransaction|undefined;
105117
let finishDefer: SyncTasks.Deferred<void>|undefined = SyncTasks.Defer<void>();
106118
(writeNeeded ? this._db.transaction : this._db.readTransaction).call(this._db,
107-
(trans: SQLTransaction) => {
119+
(trans: SqlProviderBase.SQLTransaction) => {
108120
ourTrans = new WebSqlTransaction(trans, finishDefer!!!.promise(), this._schema!!!, this._verbose!!!, 999,
109121
this._supportsFTS3);
110122
deferred.resolve(ourTrans);
111-
}, (err: SQLError) => {
123+
}, (err: SqlProviderBase.SQLError) => {
112124
if (ourTrans) {
113125
// Got an error from inside the transaction. Error out all pending queries on the
114126
// transaction since they won't exit out gracefully for whatever reason.
@@ -134,7 +146,7 @@ export class WebSqlProvider extends SqlProviderBase.SqlProviderBase {
134146
}
135147

136148
class WebSqlTransaction extends SqlProviderBase.SqliteSqlTransaction {
137-
constructor(protected trans: SQLTransaction,
149+
constructor(protected trans: SqlProviderBase.SQLTransaction,
138150
private _completionPromise: SyncTasks.Promise<void>,
139151
schema: NoSqlProvider.DbSchema,
140152
verbose: boolean,

src/dependencies.d.ts

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)