xdriver 2.0.17 → 2.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/connection.d.ts +1 -0
- package/lib/connection.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -3
- package/package.json +1 -1
- package/src/connection.ts +15 -0
- package/src/index.ts +12 -3
package/lib/connection.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export default class Connection {
|
|
|
18
18
|
constructor(database?: string, version?: number);
|
|
19
19
|
on<T extends EventKey>(event: T, handle: EventMap[T]): this;
|
|
20
20
|
get connected(): boolean;
|
|
21
|
+
get tables(): string[];
|
|
21
22
|
connect(name?: string, version?: number, upgrade?: (idbDatabase: IDBDatabase, event: IDBVersionChangeEvent) => any): Promise<any>;
|
|
22
23
|
drop(): Promise<Event>;
|
|
23
24
|
close(): void;
|
package/lib/connection.js
CHANGED
|
@@ -25,6 +25,23 @@ export default class Connection {
|
|
|
25
25
|
get connected() {
|
|
26
26
|
return this.idbDatabase != void 0;
|
|
27
27
|
}
|
|
28
|
+
get tables() {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!this.connected) {
|
|
31
|
+
throw new Error('Please connect to the database first');
|
|
32
|
+
}
|
|
33
|
+
let tables = [];
|
|
34
|
+
let objectStoreNames = (_a = this.idbDatabase) === null || _a === void 0 ? void 0 : _a.objectStoreNames;
|
|
35
|
+
if (!objectStoreNames)
|
|
36
|
+
return tables;
|
|
37
|
+
for (let i = 0; i < objectStoreNames.length; i++) {
|
|
38
|
+
let item = objectStoreNames.item(i);
|
|
39
|
+
if (!item)
|
|
40
|
+
continue;
|
|
41
|
+
tables.push(item);
|
|
42
|
+
}
|
|
43
|
+
return tables;
|
|
44
|
+
}
|
|
28
45
|
connect(name, version, upgrade) {
|
|
29
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
47
|
var _a;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -21,8 +21,16 @@ export default class Driver {
|
|
|
21
21
|
this.version = version;
|
|
22
22
|
}
|
|
23
23
|
defineTables(...tables) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
for (let table of tables) {
|
|
25
|
+
let index = this.tables.findIndex(t => t.name === table.name);
|
|
26
|
+
if (index >= 0) {
|
|
27
|
+
this.tables[index] = table;
|
|
28
|
+
logger.debug(`Update table: ${table.name}`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
this.tables.push(table);
|
|
32
|
+
logger.debug(`Define table: ${table.name}`);
|
|
33
|
+
}
|
|
26
34
|
return this;
|
|
27
35
|
}
|
|
28
36
|
hasChange(database) {
|
|
@@ -133,7 +141,7 @@ export default class Driver {
|
|
|
133
141
|
database.close();
|
|
134
142
|
yield database.connect(this.name, ++this.version);
|
|
135
143
|
}
|
|
136
|
-
return database;
|
|
144
|
+
return this.database = database;
|
|
137
145
|
});
|
|
138
146
|
}
|
|
139
147
|
}
|
package/package.json
CHANGED
package/src/connection.ts
CHANGED
|
@@ -37,6 +37,21 @@ export default class Connection {
|
|
|
37
37
|
return this.idbDatabase != void 0;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
get tables(): string[] {
|
|
41
|
+
if (!this.connected) {
|
|
42
|
+
throw new Error('Please connect to the database first')
|
|
43
|
+
}
|
|
44
|
+
let tables: Array<string> = [];
|
|
45
|
+
let objectStoreNames = this.idbDatabase?.objectStoreNames
|
|
46
|
+
if (!objectStoreNames) return tables;
|
|
47
|
+
for (let i = 0; i < objectStoreNames.length; i++) {
|
|
48
|
+
let item = objectStoreNames.item(i);
|
|
49
|
+
if (!item) continue;
|
|
50
|
+
tables.push(item);
|
|
51
|
+
}
|
|
52
|
+
return tables;
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
async connect(name?: string, version?: number, upgrade?: (idbDatabase: IDBDatabase, event: IDBVersionChangeEvent) => any): Promise<any> {
|
|
41
56
|
if ((!name || version == void 0) && this.connected) {
|
|
42
57
|
return Promise.resolve(this);
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ const logger = Logger.getLogger("Driver")
|
|
|
10
10
|
export default class Driver {
|
|
11
11
|
private readonly name: string;
|
|
12
12
|
private version: number;
|
|
13
|
+
private database?: Database;
|
|
13
14
|
private readonly tables: Array<TableMeta> = [];
|
|
14
15
|
|
|
15
16
|
constructor(name: string, version: number = 0) {
|
|
@@ -18,8 +19,16 @@ export default class Driver {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
defineTables(...tables: Array<TableMeta>): this {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
for(let table of tables) {
|
|
23
|
+
let index = this.tables.findIndex(t => t.name === table.name);
|
|
24
|
+
if (index >= 0) {
|
|
25
|
+
this.tables[index] = table;
|
|
26
|
+
logger.debug(`Update table: ${table.name}`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
this.tables.push(table);
|
|
30
|
+
logger.debug(`Define table: ${table.name}`);
|
|
31
|
+
}
|
|
23
32
|
return this;
|
|
24
33
|
}
|
|
25
34
|
|
|
@@ -140,7 +149,7 @@ export default class Driver {
|
|
|
140
149
|
await database.connect(this.name, ++this.version)
|
|
141
150
|
}
|
|
142
151
|
|
|
143
|
-
return database;
|
|
152
|
+
return this.database = database;
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
155
|
|