xt-idb-store 0.4.0

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/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Store
2
+
3
+ This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Run `ng generate component component-name --project store` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project store`.
8
+ > Note: Don't forget to add `--project store` or else it will be added to the default project in your `angular.json` file.
9
+
10
+ ## Build
11
+
12
+ Run `ng build store` to build the project. The build artifacts will be stored in the `dist/` directory.
13
+
14
+ ## Publishing
15
+
16
+ After building your library with `ng build store`, go to the dist folder `cd dist/store` and run `npm publish`.
17
+
18
+ ## Running unit tests
19
+
20
+ Run `ng test store` to execute the unit tests via [Karma](https://karma-runner.github.io).
21
+
22
+ ## Further help
23
+
24
+ To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
@@ -0,0 +1,229 @@
1
+ import { Subscription, from } from 'rxjs';
2
+ import Dexie from 'dexie';
3
+ import * as i0 from '@angular/core';
4
+ import { Injectable } from '@angular/core';
5
+ import { AbstractXtStoreProvider, XtStoreProviderHelper } from 'xt-store';
6
+
7
+ /**
8
+ * Allow storing of entities in the browser local database
9
+ */
10
+ class IndexedDbStorageService extends AbstractXtStoreProvider {
11
+ /**
12
+ * Enable test code to close a database between tests
13
+ */
14
+ static forceCloseDatabase() {
15
+ // eslint-disable-next-line no-restricted-syntax
16
+ //console.debug("IndexedDB: In forceCloseDatabase");
17
+ if (this.globalDb != null) {
18
+ // eslint-disable-next-line no-restricted-syntax
19
+ //console.debug("IndexedDB: GlobalDB Exist");
20
+ if (this.globalDb.isOpen()) {
21
+ // eslint-disable-next-line no-restricted-syntax
22
+ //console.debug("IndexedDB: Closing GlobalDB");
23
+ this.globalDb.close();
24
+ // eslint-disable-next-line no-restricted-syntax
25
+ //console.debug("IndexedDB: GlobalDB is closed");
26
+ }
27
+ }
28
+ }
29
+ static forceDeleteDatabase(dbName) {
30
+ // eslint-disable-next-line no-restricted-syntax
31
+ //console.debug("IndexedDB: In forceDeleteDatabase");
32
+ return Dexie.delete(dbName).then(() => {
33
+ // eslint-disable-next-line no-restricted-syntax
34
+ //console.debug("IndexedDB: Database "+dbName+" deleted");
35
+ });
36
+ }
37
+ constructor() {
38
+ super( /*modelMgr*/);
39
+ this.db = null;
40
+ this.dbName = "Dont-code Sandbox Lib";
41
+ this.subscriptions = new Subscription();
42
+ /*this.updateConfig (configService.getConfig());
43
+ this.subscriptions.add (configService.getUpdates().pipe (map ((newConfig) => {
44
+ this.updateConfig(newConfig);
45
+ })).subscribe());*/
46
+ // Let unit tests close or delete the database between tests if needed
47
+ if (self._indexedDbStorageServiceForceClose == null) {
48
+ self._indexedDbStorageServiceForceClose = () => IndexedDbStorageService.forceCloseDatabase();
49
+ }
50
+ if (self._indexedDbStorageServiceForceDelete == null) {
51
+ self._indexedDbStorageServiceForceDelete = (dbName) => IndexedDbStorageService.forceDeleteDatabase(dbName);
52
+ }
53
+ }
54
+ deleteEntity(name, key) {
55
+ return this.ensurePositionCanBeStored(name, false).then(table => {
56
+ return table.delete(key).then(() => {
57
+ return true;
58
+ });
59
+ });
60
+ }
61
+ loadEntity(name, key) {
62
+ return this.ensurePositionCanBeStored(name, false).then(table => {
63
+ return table.get(key);
64
+ }).catch(reason => {
65
+ console.warn("IndexedDB: Cannot load entity " + key + " : " + reason);
66
+ return undefined;
67
+ });
68
+ }
69
+ searchEntities(name, ...criteria) {
70
+ return from(this.ensurePositionCanBeStored(name, false).then(table => {
71
+ return table.toArray().then(list => {
72
+ return XtStoreProviderHelper.applyFilters(list, ...criteria);
73
+ });
74
+ }).catch(reason => {
75
+ // Probably table not found, just returns empty values
76
+ console.warn("IndexedDB: Cannot search entity: " + reason);
77
+ return [];
78
+ }));
79
+ }
80
+ canStoreDocument() {
81
+ return false;
82
+ }
83
+ storeDocuments(toStore) {
84
+ throw new Error("Impossible to store documents in IndexedDB.");
85
+ }
86
+ storeEntity(name, entity) {
87
+ return this.ensurePositionCanBeStored(name, true).then(table => {
88
+ return table.put(entity).then(key => {
89
+ if ((entity._id) && (entity._id !== key)) {
90
+ return Promise.reject("Stored entity with id " + key + " different from " + entity._id);
91
+ }
92
+ else {
93
+ return entity;
94
+ }
95
+ });
96
+ });
97
+ }
98
+ ensureEntityCanBeStored(description, create) {
99
+ if (description)
100
+ return this.ensurePositionCanBeStored(description.name, create);
101
+ else {
102
+ return Promise.reject("Error called with null description");
103
+ }
104
+ }
105
+ ensurePositionCanBeStored(name, create) {
106
+ return this.withDatabase().then(db => {
107
+ // We have to make sure the database is open before we can get the list of tables
108
+ let table;
109
+ try {
110
+ table = db.table(name);
111
+ }
112
+ catch (error) {
113
+ // Just ignore table not found
114
+ }
115
+ if (table != null)
116
+ return Promise.resolve(table);
117
+ if (create) {
118
+ const tableDescription = {};
119
+ tableDescription[name] = '++_id';
120
+ return this.changeSchema(db, tableDescription).then(db => {
121
+ return db.table(name);
122
+ });
123
+ }
124
+ else {
125
+ return Promise.reject(name + ' table not found');
126
+ }
127
+ });
128
+ }
129
+ changeSchema(db, schemaChanges) {
130
+ //console.log("IndexedDB: Closing DB");
131
+ db.close();
132
+ /* const newDb = new Dexie(db.name,{allowEmptyDB:true, autoOpen:false});
133
+
134
+ newDb.on('blocked', ()=>false); // Silence console warning of blocked event.
135
+
136
+ // Workaround: If DB is empty from tables, it needs to be recreated
137
+ if (db.tables.length === 0) {
138
+ return db.delete().then (value => {
139
+ newDb.version(1.5).stores(schemaChanges);
140
+ return newDb.open();
141
+ })
142
+ }
143
+
144
+ // Extract current schema in dexie format:
145
+ const currentSchema = db.tables.reduce((result:{[key:string]:any},{name, schema}) => {
146
+ result[name] = [
147
+ schema.primKey.src,
148
+ ...schema.indexes.map(idx => idx.src)
149
+ ].join(',');
150
+ return result;
151
+ }, {});
152
+ */
153
+ //console.log("Version: " + db.verno);
154
+ //console.log("Current Schema: ", currentSchema);
155
+ // Tell Dexie about current schema:
156
+ // newDb.version(db.verno).stores(currentSchema);
157
+ // Tell Dexie about next schema:
158
+ //console.log("IndexedDB: Versioning DB to "+(db.verno + 1)+ " from tables "+this.allTables(db));
159
+ db.version(db.verno + 1).stores(schemaChanges);
160
+ // Upgrade it:
161
+ //console.log("IndexedDB: Upgrading DB");
162
+ return db.open().then(database => {
163
+ //console.log("IndexedDB: Upgraded DB v"+database.verno+" to tables "+this.allTables(database));
164
+ return database;
165
+ });
166
+ }
167
+ /*updateConfig (newConfig:CommonLibConfig) {
168
+ if ((newConfig.indexedDbName!=null) && (newConfig.indexedDbName.length > 0)) {
169
+ if( newConfig.indexedDbName!=this.dbName) {
170
+ this.dbName=newConfig.indexedDbName;
171
+ if (this.db?.isOpen ()) {
172
+ console.warn ("Changing the name of an Open IndexedDB database to "+newConfig.indexedDbName);
173
+ this.db.close();
174
+ this.db = null; // Force reopen of db next time
175
+ }
176
+ IndexedDbStorageService.forceCloseDatabase();
177
+ }
178
+ }
179
+ }*/
180
+ withDatabase() {
181
+ if (this.db == null) {
182
+ //console.log("IndexedDB: Checking GlobalDB "+this.dbName);
183
+ if (IndexedDbStorageService.globalDb == null) {
184
+ IndexedDbStorageService.globalDb = new Dexie(this.dbName, { allowEmptyDB: true, autoOpen: false });
185
+ //console.log("IndexedDB: GlobalDB "+this.dbName+" created");
186
+ }
187
+ this.db = IndexedDbStorageService.globalDb;
188
+ if (!this.db.isOpen()) {
189
+ //console.log("IndexedDB: Opening DB "+this.dbName);
190
+ return this.db.open().then(database => {
191
+ //console.log ("IndexedDB: DB "+this.dbName+" v"+database.verno+" opened with tables "+this.allTables(database));
192
+ return database;
193
+ });
194
+ }
195
+ }
196
+ return Promise.resolve(this.db);
197
+ }
198
+ ngOnDestroy() {
199
+ //console.log("IndexedDB: ngOnDestroy called");
200
+ this.subscriptions.unsubscribe();
201
+ IndexedDbStorageService.forceCloseDatabase();
202
+ }
203
+ allTables(db) {
204
+ let ret = "";
205
+ for (const table of db.tables) {
206
+ ret = ret + ", " + table.name;
207
+ }
208
+ return ret;
209
+ }
210
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: IndexedDbStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
211
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: IndexedDbStorageService, providedIn: 'root' }); }
212
+ }
213
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: IndexedDbStorageService, decorators: [{
214
+ type: Injectable,
215
+ args: [{
216
+ providedIn: 'root'
217
+ }]
218
+ }], ctorParameters: () => [] });
219
+
220
+ /*
221
+ * Public API Surface of store
222
+ */
223
+
224
+ /**
225
+ * Generated bundle index. Do not edit.
226
+ */
227
+
228
+ export { IndexedDbStorageService };
229
+ //# sourceMappingURL=xt-idb-store.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xt-idb-store.mjs","sources":["../../../projects/idb-store/src/indexeddb/indexed-db-storage.service.ts","../../../projects/idb-store/src/public-api.ts","../../../projects/idb-store/src/xt-idb-store.ts"],"sourcesContent":["/**\n * Allow storing of entities in the browser local database\n */\nimport { from, Observable, Subscription } from 'rxjs';\nimport Dexie, { Table } from 'dexie';\nimport { Injectable, OnDestroy } from '@angular/core';\nimport { AbstractXtStoreProvider, UploadedDocumentInfo, XtStoreCriteria, XtStoreProviderHelper } from 'xt-store';\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport class IndexedDbStorageService<T=never> extends AbstractXtStoreProvider<T> implements OnDestroy {\n\n protected static globalDb: Dexie|null;\n\n protected db: Dexie|null=null;\n\n protected dbName = \"Dont-code Sandbox Lib\";\n\n protected subscriptions = new Subscription ();\n\n /**\n * Enable test code to close a database between tests\n */\n public static forceCloseDatabase () {\n // eslint-disable-next-line no-restricted-syntax\n //console.debug(\"IndexedDB: In forceCloseDatabase\");\n if (this.globalDb!=null) {\n // eslint-disable-next-line no-restricted-syntax\n //console.debug(\"IndexedDB: GlobalDB Exist\");\n if (this.globalDb.isOpen()) {\n // eslint-disable-next-line no-restricted-syntax\n //console.debug(\"IndexedDB: Closing GlobalDB\");\n this.globalDb.close();\n // eslint-disable-next-line no-restricted-syntax\n //console.debug(\"IndexedDB: GlobalDB is closed\");\n }\n }\n }\n\n public static forceDeleteDatabase (dbName:string):Promise<void> {\n // eslint-disable-next-line no-restricted-syntax\n //console.debug(\"IndexedDB: In forceDeleteDatabase\");\n return Dexie.delete(dbName).then(() => {\n // eslint-disable-next-line no-restricted-syntax\n //console.debug(\"IndexedDB: Database \"+dbName+\" deleted\");\n });\n }\n\n constructor(/*protected values: ValueService,\n protected configService: CommonConfigService,\n @Optional () modelMgr?:DontCodeModelManager*/\n ) {\n super(/*modelMgr*/);\n /*this.updateConfig (configService.getConfig());\n this.subscriptions.add (configService.getUpdates().pipe (map ((newConfig) => {\n this.updateConfig(newConfig);\n })).subscribe());*/\n // Let unit tests close or delete the database between tests if needed\n if ((self as any)._indexedDbStorageServiceForceClose == null) {\n (self as any)._indexedDbStorageServiceForceClose = () => IndexedDbStorageService.forceCloseDatabase();\n }\n if ((self as any)._indexedDbStorageServiceForceDelete == null) {\n (self as any)._indexedDbStorageServiceForceDelete = (dbName:string) => IndexedDbStorageService.forceDeleteDatabase(dbName);\n }\n\n}\n\n deleteEntity(name: string, key: any): Promise<boolean> {\n return this.ensurePositionCanBeStored(name, false).then(table => {\n return table.delete(key).then(() => {\n return true;\n });\n });\n\n }\n\n loadEntity(name: string, key: any): Promise<T|undefined> {\n return this.ensurePositionCanBeStored(name, false).then (table => {\n return table.get(key);\n }).catch(reason => {\n console.warn(\"IndexedDB: Cannot load entity \"+key+\" : \"+reason);\n return undefined;\n });\n }\n\n override searchEntities(name: string, ...criteria: XtStoreCriteria[]): Observable<Array<T>> {\n return from (\n this.ensurePositionCanBeStored(name, false).then(table => {\n return table.toArray().then(list => {\n return XtStoreProviderHelper.applyFilters(list, ...criteria);\n });\n }).catch(reason => {\n // Probably table not found, just returns empty values\n console.warn(\"IndexedDB: Cannot search entity: \"+reason);\n return [];\n })\n );\n }\n\n canStoreDocument(): boolean {\n return false;\n }\n storeDocuments(toStore: File[]): Observable<UploadedDocumentInfo> {\n throw new Error(\"Impossible to store documents in IndexedDB.\");\n }\n\n storeEntity(name: string, entity: any): Promise<T> {\n return this.ensurePositionCanBeStored(name, true).then(table => {\n return table.put(entity).then(key => {\n if ((entity._id) && (entity._id!==key)) {\n return Promise.reject(\"Stored entity with id \"+key+\" different from \"+entity._id);\n } else {\n return entity;\n }\n\n });\n });\n }\n\n ensureEntityCanBeStored (description: any, create?:boolean):Promise<Table<T>> {\n if (description)\n return this.ensurePositionCanBeStored(description.name, create);\n else{\n return Promise.reject(\"Error called with null description\");\n }\n }\n\n ensurePositionCanBeStored (name: string, create?:boolean):Promise<Table<T>> {\n return this.withDatabase().then (db => {\n // We have to make sure the database is open before we can get the list of tables\n let table;\n try {\n table = db.table(name);\n } catch (error) {\n // Just ignore table not found\n }\n if (table != null) return Promise.resolve(table);\n\n if (create) {\n const tableDescription: { [key: string]: string } = {};\n tableDescription[name] = '++_id';\n return this.changeSchema(db, tableDescription).then(db => {\n return db.table(name);\n });\n } else {\n return Promise.reject(name + ' table not found');\n }\n });\n }\n\n protected changeSchema(db : Dexie, schemaChanges:any): Promise<Dexie> {\n //console.log(\"IndexedDB: Closing DB\");\n db.close();\n/* const newDb = new Dexie(db.name,{allowEmptyDB:true, autoOpen:false});\n\n newDb.on('blocked', ()=>false); // Silence console warning of blocked event.\n\n // Workaround: If DB is empty from tables, it needs to be recreated\n if (db.tables.length === 0) {\n return db.delete().then (value => {\n newDb.version(1.5).stores(schemaChanges);\n return newDb.open();\n })\n }\n\n // Extract current schema in dexie format:\n const currentSchema = db.tables.reduce((result:{[key:string]:any},{name, schema}) => {\n result[name] = [\n schema.primKey.src,\n ...schema.indexes.map(idx => idx.src)\n ].join(',');\n return result;\n }, {});\n*/\n //console.log(\"Version: \" + db.verno);\n //console.log(\"Current Schema: \", currentSchema);\n\n // Tell Dexie about current schema:\n // newDb.version(db.verno).stores(currentSchema);\n // Tell Dexie about next schema:\n //console.log(\"IndexedDB: Versioning DB to \"+(db.verno + 1)+ \" from tables \"+this.allTables(db));\n db.version(db.verno + 1).stores(schemaChanges);\n // Upgrade it:\n //console.log(\"IndexedDB: Upgrading DB\");\n return db.open().then (database => {\n //console.log(\"IndexedDB: Upgraded DB v\"+database.verno+\" to tables \"+this.allTables(database));\n return database;\n });\n }\n\n /*updateConfig (newConfig:CommonLibConfig) {\n if ((newConfig.indexedDbName!=null) && (newConfig.indexedDbName.length > 0)) {\n if( newConfig.indexedDbName!=this.dbName) {\n this.dbName=newConfig.indexedDbName;\n if (this.db?.isOpen ()) {\n console.warn (\"Changing the name of an Open IndexedDB database to \"+newConfig.indexedDbName);\n this.db.close();\n this.db = null; // Force reopen of db next time\n }\n IndexedDbStorageService.forceCloseDatabase();\n }\n }\n }*/\n\n withDatabase (): Promise<Dexie> {\n if (this.db==null) {\n\n //console.log(\"IndexedDB: Checking GlobalDB \"+this.dbName);\n if(IndexedDbStorageService.globalDb==null) {\n IndexedDbStorageService.globalDb = new Dexie(this.dbName, {allowEmptyDB:true, autoOpen:false});\n //console.log(\"IndexedDB: GlobalDB \"+this.dbName+\" created\");\n }\n this.db=IndexedDbStorageService.globalDb;\n if( !this.db.isOpen()) {\n //console.log(\"IndexedDB: Opening DB \"+this.dbName);\n return this.db.open().then(database => {\n //console.log (\"IndexedDB: DB \"+this.dbName+\" v\"+database.verno+\" opened with tables \"+this.allTables(database));\n return database;\n });\n }\n }\n return Promise.resolve(this.db);\n }\n\n ngOnDestroy () {\n //console.log(\"IndexedDB: ngOnDestroy called\");\n this.subscriptions.unsubscribe();\n IndexedDbStorageService.forceCloseDatabase();\n }\n\n allTables (db:Dexie): string {\n let ret=\"\";\n for (const table of db.tables) {\n ret=ret+\", \"+table.name;\n }\n return ret;\n }\n}\n","/*\n * Public API Surface of store\n */\n\nexport * from './indexeddb/indexed-db-storage.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;;AAEG;AAUG,MAAO,uBAAiC,SAAQ,uBAA0B,CAAA;AAU9E;;AAEG;AACI,IAAA,OAAO,kBAAkB,GAAA;;;AAG9B,QAAA,IAAI,IAAI,CAAC,QAAQ,IAAE,IAAI,EAAE;;;AAGvB,YAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE;;;AAG1B,gBAAA,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;;;;;;IAOpB,OAAO,mBAAmB,CAAE,MAAa,EAAA;;;QAG9C,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAK;;;AAGtC,SAAC,CAAC;;AAGJ,IAAA,WAAA,GAAA;QAIE,KAAK,eAAc;QAtCX,IAAE,CAAA,EAAA,GAAa,IAAI;QAEnB,IAAM,CAAA,MAAA,GAAG,uBAAuB;AAEhC,QAAA,IAAA,CAAA,aAAa,GAAG,IAAI,YAAY,EAAG;AAmC3C;;;AAGmB;;AAEnB,QAAA,IAAK,IAAY,CAAC,kCAAkC,IAAI,IAAI,EAAE;YAC3D,IAAY,CAAC,kCAAkC,GAAG,MAAM,uBAAuB,CAAC,kBAAkB,EAAE;;AAEvG,QAAA,IAAK,IAAY,CAAC,mCAAmC,IAAI,IAAI,EAAE;AAC5D,YAAA,IAAY,CAAC,mCAAmC,GAAG,CAAC,MAAa,KAAK,uBAAuB,CAAC,mBAAmB,CAAC,MAAM,CAAC;;;IAK9H,YAAY,CAAC,IAAY,EAAE,GAAQ,EAAA;AACjC,QAAA,OAAO,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,IAAI,C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,EAAE,CAAC,MAAM,EAAE;YAC7B,GAAG,GAAC,GAAG,GAAC,IAAI,GAAC,KAAK,CAAC,IAAI;;AAEzB,QAAA,OAAO,GAAG;;8GAjOD,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAvB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,uBAAuB,cAFtB,MAAM,EAAA,CAAA,CAAA;;2FAEP,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBAHnC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACXD;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="xt-idb-store" />
5
+ export * from './public-api';
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Allow storing of entities in the browser local database
3
+ */
4
+ import { Observable, Subscription } from 'rxjs';
5
+ import Dexie, { Table } from 'dexie';
6
+ import { OnDestroy } from '@angular/core';
7
+ import { AbstractXtStoreProvider, UploadedDocumentInfo, XtStoreCriteria } from 'xt-store';
8
+ import * as i0 from "@angular/core";
9
+ export declare class IndexedDbStorageService<T = never> extends AbstractXtStoreProvider<T> implements OnDestroy {
10
+ protected static globalDb: Dexie | null;
11
+ protected db: Dexie | null;
12
+ protected dbName: string;
13
+ protected subscriptions: Subscription;
14
+ /**
15
+ * Enable test code to close a database between tests
16
+ */
17
+ static forceCloseDatabase(): void;
18
+ static forceDeleteDatabase(dbName: string): Promise<void>;
19
+ constructor();
20
+ deleteEntity(name: string, key: any): Promise<boolean>;
21
+ loadEntity(name: string, key: any): Promise<T | undefined>;
22
+ searchEntities(name: string, ...criteria: XtStoreCriteria[]): Observable<Array<T>>;
23
+ canStoreDocument(): boolean;
24
+ storeDocuments(toStore: File[]): Observable<UploadedDocumentInfo>;
25
+ storeEntity(name: string, entity: any): Promise<T>;
26
+ ensureEntityCanBeStored(description: any, create?: boolean): Promise<Table<T>>;
27
+ ensurePositionCanBeStored(name: string, create?: boolean): Promise<Table<T>>;
28
+ protected changeSchema(db: Dexie, schemaChanges: any): Promise<Dexie>;
29
+ withDatabase(): Promise<Dexie>;
30
+ ngOnDestroy(): void;
31
+ allTables(db: Dexie): string;
32
+ static ɵfac: i0.ɵɵFactoryDeclaration<IndexedDbStorageService<any>, never>;
33
+ static ɵprov: i0.ɵɵInjectableDeclaration<IndexedDbStorageService<any>>;
34
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "xt-idb-store",
3
+ "version": "0.4.0",
4
+ "peerDependencies": {
5
+ "@angular/common": "^18.2.0",
6
+ "@angular/core": "^18.2.0"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "sideEffects": false,
12
+ "module": "fesm2022/xt-idb-store.mjs",
13
+ "typings": "index.d.ts",
14
+ "exports": {
15
+ "./package.json": {
16
+ "default": "./package.json"
17
+ },
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "default": "./fesm2022/xt-idb-store.mjs"
21
+ }
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export * from './indexeddb/indexed-db-storage.service';