ngx-indexed-db 9.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/LICENSE +19 -0
- package/README.md +410 -0
- package/bundles/ngx-indexed-db.umd.js +970 -0
- package/bundles/ngx-indexed-db.umd.js.map +1 -0
- package/esm2015/lib/ngx-indexed-db.js +53 -0
- package/esm2015/lib/ngx-indexed-db.meta.js +8 -0
- package/esm2015/lib/ngx-indexed-db.service.js +513 -0
- package/esm2015/lib/ngxindexeddb.module.js +19 -0
- package/esm2015/ngx-indexed-db.js +5 -0
- package/esm2015/public-api.js +4 -0
- package/esm2015/utils/index.js +30 -0
- package/fesm2015/ngx-indexed-db.js +622 -0
- package/fesm2015/ngx-indexed-db.js.map +1 -0
- package/lib/ngx-indexed-db.d.ts +5 -0
- package/lib/ngx-indexed-db.meta.d.ts +42 -0
- package/lib/ngx-indexed-db.service.d.ts +139 -0
- package/lib/ngxindexeddb.module.d.ts +5 -0
- package/ngx-indexed-db.d.ts +4 -0
- package/ngx-indexed-db.metadata.json +1 -0
- package/package.json +38 -0
- package/public-api.d.ts +3 -0
- package/utils/index.d.ts +11 -0
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs'), require('rxjs/operators')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('ngx-indexed-db', ['exports', '@angular/core', '@angular/common', 'rxjs', 'rxjs/operators'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-indexed-db'] = {}, global.ng.core, global.ng.common, global.rxjs, global.rxjs.operators));
|
|
5
|
+
}(this, (function (exports, core, common, rxjs, operators) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/*! *****************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
|
+
var extendStatics = function (d, b) {
|
|
23
|
+
extendStatics = Object.setPrototypeOf ||
|
|
24
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
+
function (d, b) { for (var p in b)
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
27
|
+
d[p] = b[p]; };
|
|
28
|
+
return extendStatics(d, b);
|
|
29
|
+
};
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
if (typeof b !== "function" && b !== null)
|
|
32
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
+
extendStatics(d, b);
|
|
34
|
+
function __() { this.constructor = d; }
|
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
+
}
|
|
37
|
+
var __assign = function () {
|
|
38
|
+
__assign = Object.assign || function __assign(t) {
|
|
39
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
+
s = arguments[i];
|
|
41
|
+
for (var p in s)
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
43
|
+
t[p] = s[p];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
47
|
+
return __assign.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
function __rest(s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s)
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
53
|
+
t[p] = s[p];
|
|
54
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
55
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
56
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
57
|
+
t[p[i]] = s[p[i]];
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
function __decorate(decorators, target, key, desc) {
|
|
62
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
64
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
+
else
|
|
66
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
67
|
+
if (d = decorators[i])
|
|
68
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
69
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
|
+
}
|
|
71
|
+
function __param(paramIndex, decorator) {
|
|
72
|
+
return function (target, key) { decorator(target, key, paramIndex); };
|
|
73
|
+
}
|
|
74
|
+
function __metadata(metadataKey, metadataValue) {
|
|
75
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
76
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
77
|
+
}
|
|
78
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
79
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
80
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
81
|
+
function fulfilled(value) { try {
|
|
82
|
+
step(generator.next(value));
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
reject(e);
|
|
86
|
+
} }
|
|
87
|
+
function rejected(value) { try {
|
|
88
|
+
step(generator["throw"](value));
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
reject(e);
|
|
92
|
+
} }
|
|
93
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
94
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function __generator(thisArg, body) {
|
|
98
|
+
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
99
|
+
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
100
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
101
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
102
|
+
function step(op) {
|
|
103
|
+
if (f)
|
|
104
|
+
throw new TypeError("Generator is already executing.");
|
|
105
|
+
while (_)
|
|
106
|
+
try {
|
|
107
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
108
|
+
return t;
|
|
109
|
+
if (y = 0, t)
|
|
110
|
+
op = [op[0] & 2, t.value];
|
|
111
|
+
switch (op[0]) {
|
|
112
|
+
case 0:
|
|
113
|
+
case 1:
|
|
114
|
+
t = op;
|
|
115
|
+
break;
|
|
116
|
+
case 4:
|
|
117
|
+
_.label++;
|
|
118
|
+
return { value: op[1], done: false };
|
|
119
|
+
case 5:
|
|
120
|
+
_.label++;
|
|
121
|
+
y = op[1];
|
|
122
|
+
op = [0];
|
|
123
|
+
continue;
|
|
124
|
+
case 7:
|
|
125
|
+
op = _.ops.pop();
|
|
126
|
+
_.trys.pop();
|
|
127
|
+
continue;
|
|
128
|
+
default:
|
|
129
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
130
|
+
_ = 0;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
134
|
+
_.label = op[1];
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
138
|
+
_.label = t[1];
|
|
139
|
+
t = op;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (t && _.label < t[2]) {
|
|
143
|
+
_.label = t[2];
|
|
144
|
+
_.ops.push(op);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
if (t[2])
|
|
148
|
+
_.ops.pop();
|
|
149
|
+
_.trys.pop();
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
op = body.call(thisArg, _);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
op = [6, e];
|
|
156
|
+
y = 0;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
f = t = 0;
|
|
160
|
+
}
|
|
161
|
+
if (op[0] & 5)
|
|
162
|
+
throw op[1];
|
|
163
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
167
|
+
if (k2 === undefined)
|
|
168
|
+
k2 = k;
|
|
169
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
170
|
+
}) : (function (o, m, k, k2) {
|
|
171
|
+
if (k2 === undefined)
|
|
172
|
+
k2 = k;
|
|
173
|
+
o[k2] = m[k];
|
|
174
|
+
});
|
|
175
|
+
function __exportStar(m, o) {
|
|
176
|
+
for (var p in m)
|
|
177
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
178
|
+
__createBinding(o, m, p);
|
|
179
|
+
}
|
|
180
|
+
function __values(o) {
|
|
181
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
182
|
+
if (m)
|
|
183
|
+
return m.call(o);
|
|
184
|
+
if (o && typeof o.length === "number")
|
|
185
|
+
return {
|
|
186
|
+
next: function () {
|
|
187
|
+
if (o && i >= o.length)
|
|
188
|
+
o = void 0;
|
|
189
|
+
return { value: o && o[i++], done: !o };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
193
|
+
}
|
|
194
|
+
function __read(o, n) {
|
|
195
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
196
|
+
if (!m)
|
|
197
|
+
return o;
|
|
198
|
+
var i = m.call(o), r, ar = [], e;
|
|
199
|
+
try {
|
|
200
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
201
|
+
ar.push(r.value);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
e = { error: error };
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
try {
|
|
208
|
+
if (r && !r.done && (m = i["return"]))
|
|
209
|
+
m.call(i);
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
if (e)
|
|
213
|
+
throw e.error;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return ar;
|
|
217
|
+
}
|
|
218
|
+
/** @deprecated */
|
|
219
|
+
function __spread() {
|
|
220
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
221
|
+
ar = ar.concat(__read(arguments[i]));
|
|
222
|
+
return ar;
|
|
223
|
+
}
|
|
224
|
+
/** @deprecated */
|
|
225
|
+
function __spreadArrays() {
|
|
226
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
227
|
+
s += arguments[i].length;
|
|
228
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
229
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
230
|
+
r[k] = a[j];
|
|
231
|
+
return r;
|
|
232
|
+
}
|
|
233
|
+
function __spreadArray(to, from) {
|
|
234
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
235
|
+
to[j] = from[i];
|
|
236
|
+
return to;
|
|
237
|
+
}
|
|
238
|
+
function __await(v) {
|
|
239
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
240
|
+
}
|
|
241
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
242
|
+
if (!Symbol.asyncIterator)
|
|
243
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
244
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
245
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
246
|
+
function verb(n) { if (g[n])
|
|
247
|
+
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
248
|
+
function resume(n, v) { try {
|
|
249
|
+
step(g[n](v));
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
settle(q[0][3], e);
|
|
253
|
+
} }
|
|
254
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
255
|
+
function fulfill(value) { resume("next", value); }
|
|
256
|
+
function reject(value) { resume("throw", value); }
|
|
257
|
+
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
258
|
+
resume(q[0][0], q[0][1]); }
|
|
259
|
+
}
|
|
260
|
+
function __asyncDelegator(o) {
|
|
261
|
+
var i, p;
|
|
262
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
263
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
264
|
+
}
|
|
265
|
+
function __asyncValues(o) {
|
|
266
|
+
if (!Symbol.asyncIterator)
|
|
267
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
268
|
+
var m = o[Symbol.asyncIterator], i;
|
|
269
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
270
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
271
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
272
|
+
}
|
|
273
|
+
function __makeTemplateObject(cooked, raw) {
|
|
274
|
+
if (Object.defineProperty) {
|
|
275
|
+
Object.defineProperty(cooked, "raw", { value: raw });
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
cooked.raw = raw;
|
|
279
|
+
}
|
|
280
|
+
return cooked;
|
|
281
|
+
}
|
|
282
|
+
;
|
|
283
|
+
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
284
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
285
|
+
}) : function (o, v) {
|
|
286
|
+
o["default"] = v;
|
|
287
|
+
};
|
|
288
|
+
function __importStar(mod) {
|
|
289
|
+
if (mod && mod.__esModule)
|
|
290
|
+
return mod;
|
|
291
|
+
var result = {};
|
|
292
|
+
if (mod != null)
|
|
293
|
+
for (var k in mod)
|
|
294
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
295
|
+
__createBinding(result, mod, k);
|
|
296
|
+
__setModuleDefault(result, mod);
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
function __importDefault(mod) {
|
|
300
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
301
|
+
}
|
|
302
|
+
function __classPrivateFieldGet(receiver, privateMap) {
|
|
303
|
+
if (!privateMap.has(receiver)) {
|
|
304
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
305
|
+
}
|
|
306
|
+
return privateMap.get(receiver);
|
|
307
|
+
}
|
|
308
|
+
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
309
|
+
if (!privateMap.has(receiver)) {
|
|
310
|
+
throw new TypeError("attempted to set private field on non-instance");
|
|
311
|
+
}
|
|
312
|
+
privateMap.set(receiver, value);
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function openDatabase(indexedDB, dbName, version, upgradeCallback) {
|
|
317
|
+
return new Promise(function (resolve, reject) {
|
|
318
|
+
if (!indexedDB) {
|
|
319
|
+
reject('IndexedDB not available');
|
|
320
|
+
}
|
|
321
|
+
var request = indexedDB.open(dbName, version);
|
|
322
|
+
var db;
|
|
323
|
+
request.onsuccess = function (event) {
|
|
324
|
+
db = request.result;
|
|
325
|
+
resolve(db);
|
|
326
|
+
};
|
|
327
|
+
request.onerror = function (event) {
|
|
328
|
+
reject("IndexedDB error: " + request.error);
|
|
329
|
+
};
|
|
330
|
+
if (typeof upgradeCallback === 'function') {
|
|
331
|
+
request.onupgradeneeded = function (event) {
|
|
332
|
+
upgradeCallback(event, db);
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function CreateObjectStore(indexedDB, dbName, version, storeSchemas, migrationFactory) {
|
|
338
|
+
if (!indexedDB) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
var request = indexedDB.open(dbName, version);
|
|
342
|
+
request.onupgradeneeded = function (event) {
|
|
343
|
+
var database = event.target.result;
|
|
344
|
+
storeSchemas.forEach(function (storeSchema) {
|
|
345
|
+
if (!database.objectStoreNames.contains(storeSchema.store)) {
|
|
346
|
+
var objectStore_1 = database.createObjectStore(storeSchema.store, storeSchema.storeConfig);
|
|
347
|
+
storeSchema.storeSchema.forEach(function (schema) {
|
|
348
|
+
objectStore_1.createIndex(schema.name, schema.keypath, schema.options);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
var storeMigrations = migrationFactory && migrationFactory();
|
|
353
|
+
if (storeMigrations) {
|
|
354
|
+
Object.keys(storeMigrations)
|
|
355
|
+
.map(function (k) { return parseInt(k, 10); })
|
|
356
|
+
.filter(function (v) { return v > event.oldVersion; })
|
|
357
|
+
.sort(function (a, b) { return a - b; })
|
|
358
|
+
.forEach(function (v) {
|
|
359
|
+
storeMigrations[v](database, request.transaction);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
database.close();
|
|
363
|
+
};
|
|
364
|
+
request.onsuccess = function (e) {
|
|
365
|
+
e.target.result.close();
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function validateStoreName(db, storeName) {
|
|
370
|
+
return db.objectStoreNames.contains(storeName);
|
|
371
|
+
}
|
|
372
|
+
function validateBeforeTransaction(db, storeName, reject) {
|
|
373
|
+
if (!db) {
|
|
374
|
+
reject('You need to use the openDatabase function to create a database before you query it!');
|
|
375
|
+
}
|
|
376
|
+
if (!validateStoreName(db, storeName)) {
|
|
377
|
+
reject("objectStore does not exists: " + storeName);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function createTransaction(db, options) {
|
|
381
|
+
var trans = db.transaction(options.storeName, options.dbMode);
|
|
382
|
+
trans.onerror = options.error;
|
|
383
|
+
trans.onabort = options.abort;
|
|
384
|
+
return trans;
|
|
385
|
+
}
|
|
386
|
+
function optionsGenerator(type, storeName, reject, resolve) {
|
|
387
|
+
return {
|
|
388
|
+
storeName: storeName,
|
|
389
|
+
dbMode: type,
|
|
390
|
+
error: function (e) {
|
|
391
|
+
reject(e);
|
|
392
|
+
},
|
|
393
|
+
abort: function (e) {
|
|
394
|
+
reject(e);
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
exports.DBMode = void 0;
|
|
400
|
+
(function (DBMode) {
|
|
401
|
+
DBMode["readonly"] = "readonly";
|
|
402
|
+
DBMode["readwrite"] = "readwrite";
|
|
403
|
+
})(exports.DBMode || (exports.DBMode = {}));
|
|
404
|
+
var CONFIG_TOKEN = new core.InjectionToken(null);
|
|
405
|
+
|
|
406
|
+
var NgxIndexedDBService = /** @class */ (function () {
|
|
407
|
+
function NgxIndexedDBService(dbConfig, platformId) {
|
|
408
|
+
var _this = this;
|
|
409
|
+
this.dbConfig = dbConfig;
|
|
410
|
+
this.platformId = platformId;
|
|
411
|
+
if (!dbConfig.name) {
|
|
412
|
+
throw new Error('NgxIndexedDB: Please, provide the dbName in the configuration');
|
|
413
|
+
}
|
|
414
|
+
if (!dbConfig.version) {
|
|
415
|
+
throw new Error('NgxIndexedDB: Please, provide the db version in the configuration');
|
|
416
|
+
}
|
|
417
|
+
this.isBrowser = common.isPlatformBrowser(this.platformId);
|
|
418
|
+
if (this.isBrowser) {
|
|
419
|
+
this.indexedDB =
|
|
420
|
+
window.indexedDB ||
|
|
421
|
+
window.mozIndexedDB ||
|
|
422
|
+
window.webkitIndexedDB ||
|
|
423
|
+
window.msIndexedDB;
|
|
424
|
+
CreateObjectStore(this.indexedDB, dbConfig.name, dbConfig.version, dbConfig.objectStoresMeta, dbConfig.migrationFactory);
|
|
425
|
+
openDatabase(this.indexedDB, dbConfig.name).then(function (db) {
|
|
426
|
+
if (db.version !== dbConfig.version) {
|
|
427
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
428
|
+
console.warn("\n Your DB Config doesn't match the most recent version of the DB with name " + _this.dbConfig.name + ", please update it\n DB current version: " + db.version + ";\n Your configuration: " + dbConfig.version + ";\n ");
|
|
429
|
+
console.warn("Using latest version " + db.version);
|
|
430
|
+
}
|
|
431
|
+
_this.dbConfig.version = db.version;
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Allows to crate a new object store ad-hoc
|
|
438
|
+
* @param storeName The name of the store to be created
|
|
439
|
+
* @param migrationFactory The migration factory if exists
|
|
440
|
+
*/
|
|
441
|
+
NgxIndexedDBService.prototype.createObjectStore = function (storeSchema, migrationFactory) {
|
|
442
|
+
var storeSchemas = [storeSchema];
|
|
443
|
+
CreateObjectStore(this.indexedDB, this.dbConfig.name, ++this.dbConfig.version, storeSchemas, migrationFactory);
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* Adds new entry in the store and returns its key
|
|
447
|
+
* @param storeName The name of the store to add the item
|
|
448
|
+
* @param value The entry to be added
|
|
449
|
+
* @param key The optional key for the entry
|
|
450
|
+
*/
|
|
451
|
+
NgxIndexedDBService.prototype.add = function (storeName, value, key) {
|
|
452
|
+
var _this = this;
|
|
453
|
+
return new rxjs.Observable(function (obs) {
|
|
454
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
455
|
+
.then(function (db) {
|
|
456
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, obs.error));
|
|
457
|
+
var objectStore = transaction.objectStore(storeName);
|
|
458
|
+
var request = Boolean(key) ? objectStore.add(value, key) : objectStore.add(value);
|
|
459
|
+
request.onsuccess = function (evt) { return __awaiter(_this, void 0, void 0, function () {
|
|
460
|
+
var result, getRequest;
|
|
461
|
+
return __generator(this, function (_a) {
|
|
462
|
+
result = evt.target.result;
|
|
463
|
+
getRequest = objectStore.get(result);
|
|
464
|
+
getRequest.onsuccess = function (event) {
|
|
465
|
+
obs.next(event.target.result);
|
|
466
|
+
obs.complete();
|
|
467
|
+
};
|
|
468
|
+
return [2 /*return*/];
|
|
469
|
+
});
|
|
470
|
+
}); };
|
|
471
|
+
})
|
|
472
|
+
.catch(function (error) { return obs.error(error); });
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Adds new entries in the store and returns its key
|
|
477
|
+
* @param storeName The name of the store to add the item
|
|
478
|
+
* @param values The entries to be added containing optional key attribute
|
|
479
|
+
*/
|
|
480
|
+
NgxIndexedDBService.prototype.bulkAdd = function (storeName, values) {
|
|
481
|
+
var _this = this;
|
|
482
|
+
var promises = values.map(function (value) {
|
|
483
|
+
return new Promise(function (resolve, reject) {
|
|
484
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
485
|
+
.then(function (db) {
|
|
486
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, reject, resolve));
|
|
487
|
+
var objectStore = transaction.objectStore(storeName);
|
|
488
|
+
var key = value.key;
|
|
489
|
+
delete value.key;
|
|
490
|
+
var request = Boolean(key)
|
|
491
|
+
? objectStore.add(value, key)
|
|
492
|
+
: objectStore.add(value);
|
|
493
|
+
request.onsuccess = function (evt) {
|
|
494
|
+
var result = evt.target.result;
|
|
495
|
+
resolve(result);
|
|
496
|
+
};
|
|
497
|
+
})
|
|
498
|
+
.catch(function (reason) { return reject(reason); });
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
return rxjs.forkJoin(promises);
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Delete entries in the store and returns current entries in the store
|
|
505
|
+
* @param storeName The name of the store to add the item
|
|
506
|
+
* @param keys The keys to be deleted
|
|
507
|
+
*/
|
|
508
|
+
NgxIndexedDBService.prototype.bulkDelete = function (storeName, keys) {
|
|
509
|
+
var _this = this;
|
|
510
|
+
var promises = keys.map(function (key) {
|
|
511
|
+
return new Promise(function (resolve, reject) {
|
|
512
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
513
|
+
.then(function (db) {
|
|
514
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, reject, resolve));
|
|
515
|
+
var objectStore = transaction.objectStore(storeName);
|
|
516
|
+
objectStore.delete(key);
|
|
517
|
+
transaction.oncomplete = function () {
|
|
518
|
+
_this.getAll(storeName)
|
|
519
|
+
.pipe(operators.take(1))
|
|
520
|
+
.subscribe(function (newValues) {
|
|
521
|
+
resolve(newValues);
|
|
522
|
+
});
|
|
523
|
+
};
|
|
524
|
+
})
|
|
525
|
+
.catch(function (reason) { return reject(reason); });
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
return rxjs.from(Promise.all(promises));
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Returns entry by key.
|
|
532
|
+
* @param storeName The name of the store to query
|
|
533
|
+
* @param key The entry key
|
|
534
|
+
*/
|
|
535
|
+
NgxIndexedDBService.prototype.getByKey = function (storeName, key) {
|
|
536
|
+
var _this = this;
|
|
537
|
+
return new rxjs.Observable(function (obs) {
|
|
538
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
539
|
+
.then(function (db) {
|
|
540
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error));
|
|
541
|
+
var objectStore = transaction.objectStore(storeName);
|
|
542
|
+
var request = objectStore.get(key);
|
|
543
|
+
request.onsuccess = function (event) {
|
|
544
|
+
obs.next(event.target.result);
|
|
545
|
+
obs.complete();
|
|
546
|
+
};
|
|
547
|
+
request.onerror = function (event) {
|
|
548
|
+
obs.error(event);
|
|
549
|
+
};
|
|
550
|
+
})
|
|
551
|
+
.catch(function (error) { return obs.error(error); });
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* Retrieve multiple entries in the store
|
|
556
|
+
* @param storeName The name of the store to retrieve the items
|
|
557
|
+
* @param keys The ids entries to be retrieve
|
|
558
|
+
*/
|
|
559
|
+
NgxIndexedDBService.prototype.bulkGet = function (storeName, keys) {
|
|
560
|
+
var _this = this;
|
|
561
|
+
var observables = keys.map(function (key) { return _this.getByKey(storeName, key); });
|
|
562
|
+
return new rxjs.Observable(function (obs) {
|
|
563
|
+
rxjs.combineLatest(observables).subscribe(function (values) {
|
|
564
|
+
obs.next(values);
|
|
565
|
+
obs.complete();
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* Returns entry by id.
|
|
571
|
+
* @param storeName The name of the store to query
|
|
572
|
+
* @param id The entry id
|
|
573
|
+
*/
|
|
574
|
+
NgxIndexedDBService.prototype.getByID = function (storeName, id) {
|
|
575
|
+
var _this = this;
|
|
576
|
+
return new rxjs.Observable(function (obs) {
|
|
577
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
578
|
+
.then(function (db) {
|
|
579
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
580
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error, obs.next));
|
|
581
|
+
var objectStore = transaction.objectStore(storeName);
|
|
582
|
+
var request = objectStore.get(id);
|
|
583
|
+
request.onsuccess = function (event) {
|
|
584
|
+
obs.next(event.target.result);
|
|
585
|
+
};
|
|
586
|
+
})
|
|
587
|
+
.catch(function (error) { return obs.error(error); });
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Returns entry by index.
|
|
592
|
+
* @param storeName The name of the store to query
|
|
593
|
+
* @param indexName The index name to filter
|
|
594
|
+
* @param key The entry key.
|
|
595
|
+
*/
|
|
596
|
+
NgxIndexedDBService.prototype.getByIndex = function (storeName, indexName, key) {
|
|
597
|
+
var _this = this;
|
|
598
|
+
return new rxjs.Observable(function (obs) {
|
|
599
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
600
|
+
.then(function (db) {
|
|
601
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
602
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error));
|
|
603
|
+
var objectStore = transaction.objectStore(storeName);
|
|
604
|
+
var index = objectStore.index(indexName);
|
|
605
|
+
var request = index.get(key);
|
|
606
|
+
request.onsuccess = function (event) {
|
|
607
|
+
obs.next(event.target.result);
|
|
608
|
+
obs.complete();
|
|
609
|
+
};
|
|
610
|
+
})
|
|
611
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
612
|
+
});
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Return all elements from one store
|
|
616
|
+
* @param storeName The name of the store to select the items
|
|
617
|
+
*/
|
|
618
|
+
NgxIndexedDBService.prototype.getAll = function (storeName) {
|
|
619
|
+
var _this = this;
|
|
620
|
+
return new rxjs.Observable(function (obs) {
|
|
621
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
622
|
+
.then(function (db) {
|
|
623
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
624
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error, obs.next));
|
|
625
|
+
var objectStore = transaction.objectStore(storeName);
|
|
626
|
+
var request = objectStore.getAll();
|
|
627
|
+
request.onerror = function (evt) {
|
|
628
|
+
obs.error(evt);
|
|
629
|
+
};
|
|
630
|
+
request.onsuccess = function (_a) {
|
|
631
|
+
var ResultAll = _a.target.result;
|
|
632
|
+
obs.next(ResultAll);
|
|
633
|
+
obs.complete();
|
|
634
|
+
};
|
|
635
|
+
})
|
|
636
|
+
.catch(function (error) { return obs.error(error); });
|
|
637
|
+
});
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* Returns all items from the store after update.
|
|
641
|
+
* @param storeName The name of the store to update
|
|
642
|
+
* @param value The new value for the entry
|
|
643
|
+
* @param key The key of the entry to update if exists
|
|
644
|
+
*/
|
|
645
|
+
NgxIndexedDBService.prototype.update = function (storeName, value, key) {
|
|
646
|
+
var _this = this;
|
|
647
|
+
return new rxjs.Observable(function (obs) {
|
|
648
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
649
|
+
.then(function (db) {
|
|
650
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
651
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, obs.error));
|
|
652
|
+
var objectStore = transaction.objectStore(storeName);
|
|
653
|
+
transaction.oncomplete = function () {
|
|
654
|
+
_this.getAll(storeName)
|
|
655
|
+
.pipe(operators.take(1))
|
|
656
|
+
.subscribe(function (newValues) {
|
|
657
|
+
obs.next(newValues);
|
|
658
|
+
obs.complete();
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
key ? objectStore.put(value, key) : objectStore.put(value);
|
|
662
|
+
})
|
|
663
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
664
|
+
});
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Returns the item you updated from the store after the update.
|
|
668
|
+
* @param storeName The name of the store to update
|
|
669
|
+
* @param value The new value for the entry
|
|
670
|
+
* @param key The key of the entry to update
|
|
671
|
+
*/
|
|
672
|
+
NgxIndexedDBService.prototype.updateByKey = function (storeName, value, key) {
|
|
673
|
+
var _this = this;
|
|
674
|
+
return new rxjs.Observable(function (obs) {
|
|
675
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
676
|
+
.then(function (db) {
|
|
677
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
678
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, obs.error));
|
|
679
|
+
var objectStore = transaction.objectStore(storeName);
|
|
680
|
+
transaction.oncomplete = function () {
|
|
681
|
+
var request = objectStore.get(key);
|
|
682
|
+
request.onsuccess = function (event) {
|
|
683
|
+
obs.next(event.target.result);
|
|
684
|
+
};
|
|
685
|
+
request.onerror = function (event) {
|
|
686
|
+
obs.error(event);
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
objectStore.put(value, key);
|
|
690
|
+
})
|
|
691
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
692
|
+
});
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* Returns all items from the store after delete.
|
|
696
|
+
* @param storeName The name of the store to have the entry deleted
|
|
697
|
+
* @param key The key of the entry to be deleted
|
|
698
|
+
*/
|
|
699
|
+
NgxIndexedDBService.prototype.delete = function (storeName, key) {
|
|
700
|
+
var _this = this;
|
|
701
|
+
return new rxjs.Observable(function (obs) {
|
|
702
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
703
|
+
.then(function (db) {
|
|
704
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
705
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, obs.error));
|
|
706
|
+
var objectStore = transaction.objectStore(storeName);
|
|
707
|
+
objectStore.delete(key);
|
|
708
|
+
transaction.oncomplete = function () {
|
|
709
|
+
_this.getAll(storeName)
|
|
710
|
+
.pipe(operators.take(1))
|
|
711
|
+
.subscribe(function (newValues) {
|
|
712
|
+
obs.next(newValues);
|
|
713
|
+
obs.complete();
|
|
714
|
+
});
|
|
715
|
+
};
|
|
716
|
+
})
|
|
717
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
718
|
+
});
|
|
719
|
+
};
|
|
720
|
+
/**
|
|
721
|
+
* Returns true from the store after a successful delete.
|
|
722
|
+
* @param storeName The name of the store to have the entry deleted
|
|
723
|
+
* @param key The key of the entry to be deleted
|
|
724
|
+
*/
|
|
725
|
+
NgxIndexedDBService.prototype.deleteByKey = function (storeName, key) {
|
|
726
|
+
var _this = this;
|
|
727
|
+
return new rxjs.Observable(function (obs) {
|
|
728
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
729
|
+
.then(function (db) {
|
|
730
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
731
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, obs.error));
|
|
732
|
+
var objectStore = transaction.objectStore(storeName);
|
|
733
|
+
transaction.oncomplete = function () {
|
|
734
|
+
obs.next(true);
|
|
735
|
+
obs.complete();
|
|
736
|
+
};
|
|
737
|
+
objectStore.delete(key);
|
|
738
|
+
})
|
|
739
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
740
|
+
});
|
|
741
|
+
};
|
|
742
|
+
/**
|
|
743
|
+
* Returns true if successfully delete all entries from the store.
|
|
744
|
+
* @param storeName The name of the store to have the entries deleted
|
|
745
|
+
*/
|
|
746
|
+
NgxIndexedDBService.prototype.clear = function (storeName) {
|
|
747
|
+
var _this = this;
|
|
748
|
+
return new rxjs.Observable(function (obs) {
|
|
749
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
750
|
+
.then(function (db) {
|
|
751
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
752
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readwrite, storeName, obs.error));
|
|
753
|
+
var objectStore = transaction.objectStore(storeName);
|
|
754
|
+
objectStore.clear();
|
|
755
|
+
transaction.oncomplete = function () {
|
|
756
|
+
obs.next(true);
|
|
757
|
+
obs.complete();
|
|
758
|
+
};
|
|
759
|
+
})
|
|
760
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
761
|
+
});
|
|
762
|
+
};
|
|
763
|
+
/**
|
|
764
|
+
* Returns true if successfully delete the DB.
|
|
765
|
+
*/
|
|
766
|
+
NgxIndexedDBService.prototype.deleteDatabase = function () {
|
|
767
|
+
var _this = this;
|
|
768
|
+
return new rxjs.Observable(function (obs) {
|
|
769
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
770
|
+
.then(function (db) { return __awaiter(_this, void 0, void 0, function () {
|
|
771
|
+
var deleteDBRequest;
|
|
772
|
+
return __generator(this, function (_a) {
|
|
773
|
+
switch (_a.label) {
|
|
774
|
+
case 0: return [4 /*yield*/, db.close()];
|
|
775
|
+
case 1:
|
|
776
|
+
_a.sent();
|
|
777
|
+
deleteDBRequest = this.indexedDB.deleteDatabase(this.dbConfig.name);
|
|
778
|
+
deleteDBRequest.onsuccess = function () {
|
|
779
|
+
obs.next(true);
|
|
780
|
+
obs.complete();
|
|
781
|
+
};
|
|
782
|
+
deleteDBRequest.onerror = function (error) { return obs.error(error); };
|
|
783
|
+
deleteDBRequest.onblocked = function () {
|
|
784
|
+
throw new Error("Unable to delete database because it's blocked");
|
|
785
|
+
};
|
|
786
|
+
return [2 /*return*/];
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}); })
|
|
790
|
+
.catch(function (error) { return obs.error(error); });
|
|
791
|
+
});
|
|
792
|
+
};
|
|
793
|
+
/**
|
|
794
|
+
* Returns the open cursor event
|
|
795
|
+
* @param storeName The name of the store to have the entries deleted
|
|
796
|
+
* @param keyRange The key range which the cursor should be open on
|
|
797
|
+
*/
|
|
798
|
+
NgxIndexedDBService.prototype.openCursor = function (storeName, keyRange) {
|
|
799
|
+
var _this = this;
|
|
800
|
+
return new rxjs.Observable(function (obs) {
|
|
801
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
802
|
+
.then(function (db) {
|
|
803
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
804
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error));
|
|
805
|
+
var objectStore = transaction.objectStore(storeName);
|
|
806
|
+
var request = keyRange === undefined ? objectStore.openCursor() : objectStore.openCursor(keyRange);
|
|
807
|
+
request.onsuccess = function (event) {
|
|
808
|
+
obs.next(event);
|
|
809
|
+
obs.complete();
|
|
810
|
+
};
|
|
811
|
+
})
|
|
812
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* Open a cursor by index filter.
|
|
817
|
+
* @param storeName The name of the store to query.
|
|
818
|
+
* @param indexName The index name to filter.
|
|
819
|
+
* @param keyRange The range value and criteria to apply on the index.
|
|
820
|
+
*/
|
|
821
|
+
NgxIndexedDBService.prototype.openCursorByIndex = function (storeName, indexName, keyRange, mode) {
|
|
822
|
+
if (mode === void 0) { mode = exports.DBMode.readonly; }
|
|
823
|
+
var obs = new rxjs.Subject();
|
|
824
|
+
openDatabase(this.indexedDB, this.dbConfig.name, this.dbConfig.version)
|
|
825
|
+
.then(function (db) {
|
|
826
|
+
validateBeforeTransaction(db, storeName, function (reason) {
|
|
827
|
+
obs.error(reason);
|
|
828
|
+
});
|
|
829
|
+
var transaction = createTransaction(db, optionsGenerator(mode, storeName, function (reason) {
|
|
830
|
+
obs.error(reason);
|
|
831
|
+
}, function () {
|
|
832
|
+
obs.next();
|
|
833
|
+
}));
|
|
834
|
+
var objectStore = transaction.objectStore(storeName);
|
|
835
|
+
var index = objectStore.index(indexName);
|
|
836
|
+
var request = index.openCursor(keyRange);
|
|
837
|
+
request.onsuccess = function (event) {
|
|
838
|
+
obs.next(event);
|
|
839
|
+
};
|
|
840
|
+
})
|
|
841
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
842
|
+
return obs;
|
|
843
|
+
};
|
|
844
|
+
/**
|
|
845
|
+
* Returns all items by an index.
|
|
846
|
+
* @param storeName The name of the store to query
|
|
847
|
+
* @param indexName The index name to filter
|
|
848
|
+
* @param keyRange The range value and criteria to apply on the index.
|
|
849
|
+
*/
|
|
850
|
+
NgxIndexedDBService.prototype.getAllByIndex = function (storeName, indexName, keyRange) {
|
|
851
|
+
var _this = this;
|
|
852
|
+
var data = [];
|
|
853
|
+
return new rxjs.Observable(function (obs) {
|
|
854
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
855
|
+
.then(function (db) {
|
|
856
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
857
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error));
|
|
858
|
+
var objectStore = transaction.objectStore(storeName);
|
|
859
|
+
var index = objectStore.index(indexName);
|
|
860
|
+
var request = index.openCursor(keyRange);
|
|
861
|
+
request.onsuccess = function (event) {
|
|
862
|
+
var cursor = event.target.result;
|
|
863
|
+
if (cursor) {
|
|
864
|
+
data.push(cursor.value);
|
|
865
|
+
cursor.continue();
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
obs.next(data);
|
|
869
|
+
obs.complete();
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
})
|
|
873
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
/**
|
|
877
|
+
* Returns all primary keys by an index.
|
|
878
|
+
* @param storeName The name of the store to query
|
|
879
|
+
* @param indexName The index name to filter
|
|
880
|
+
* @param keyRange The range value and criteria to apply on the index.
|
|
881
|
+
*/
|
|
882
|
+
NgxIndexedDBService.prototype.getAllKeysByIndex = function (storeName, indexName, keyRange) {
|
|
883
|
+
var _this = this;
|
|
884
|
+
var data = [];
|
|
885
|
+
return new rxjs.Observable(function (obs) {
|
|
886
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
887
|
+
.then(function (db) {
|
|
888
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
889
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error));
|
|
890
|
+
var objectStore = transaction.objectStore(storeName);
|
|
891
|
+
var index = objectStore.index(indexName);
|
|
892
|
+
var request = index.openKeyCursor(keyRange);
|
|
893
|
+
request.onsuccess = function (event) {
|
|
894
|
+
var cursor = event.target.result;
|
|
895
|
+
if (cursor) {
|
|
896
|
+
data.push({ primaryKey: cursor.primaryKey, key: cursor.key });
|
|
897
|
+
cursor.continue();
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
obs.next(data);
|
|
901
|
+
obs.complete();
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
})
|
|
905
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
906
|
+
});
|
|
907
|
+
};
|
|
908
|
+
/**
|
|
909
|
+
* Returns the number of rows in a store.
|
|
910
|
+
* @param storeName The name of the store to query
|
|
911
|
+
* @param keyRange The range value and criteria to apply.
|
|
912
|
+
*/
|
|
913
|
+
NgxIndexedDBService.prototype.count = function (storeName, keyRange) {
|
|
914
|
+
var _this = this;
|
|
915
|
+
return new rxjs.Observable(function (obs) {
|
|
916
|
+
openDatabase(_this.indexedDB, _this.dbConfig.name, _this.dbConfig.version)
|
|
917
|
+
.then(function (db) {
|
|
918
|
+
validateBeforeTransaction(db, storeName, obs.error);
|
|
919
|
+
var transaction = createTransaction(db, optionsGenerator(exports.DBMode.readonly, storeName, obs.error));
|
|
920
|
+
var objectStore = transaction.objectStore(storeName);
|
|
921
|
+
var request = objectStore.count(keyRange);
|
|
922
|
+
request.onerror = function (e) { return obs.error(e); };
|
|
923
|
+
request.onsuccess = function (e) {
|
|
924
|
+
obs.next(e.target.result);
|
|
925
|
+
obs.complete();
|
|
926
|
+
};
|
|
927
|
+
})
|
|
928
|
+
.catch(function (reason) { return obs.error(reason); });
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
return NgxIndexedDBService;
|
|
932
|
+
}());
|
|
933
|
+
NgxIndexedDBService.decorators = [
|
|
934
|
+
{ type: core.Injectable }
|
|
935
|
+
];
|
|
936
|
+
NgxIndexedDBService.ctorParameters = function () { return [
|
|
937
|
+
{ type: undefined, decorators: [{ type: core.Inject, args: [CONFIG_TOKEN,] }] },
|
|
938
|
+
{ type: undefined, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] }
|
|
939
|
+
]; };
|
|
940
|
+
|
|
941
|
+
var NgxIndexedDBModule = /** @class */ (function () {
|
|
942
|
+
function NgxIndexedDBModule() {
|
|
943
|
+
}
|
|
944
|
+
NgxIndexedDBModule.forRoot = function (dbConfig) {
|
|
945
|
+
return {
|
|
946
|
+
ngModule: NgxIndexedDBModule,
|
|
947
|
+
providers: [NgxIndexedDBService, { provide: CONFIG_TOKEN, useValue: dbConfig }]
|
|
948
|
+
};
|
|
949
|
+
};
|
|
950
|
+
return NgxIndexedDBModule;
|
|
951
|
+
}());
|
|
952
|
+
NgxIndexedDBModule.decorators = [
|
|
953
|
+
{ type: core.NgModule, args: [{
|
|
954
|
+
declarations: [],
|
|
955
|
+
imports: [common.CommonModule]
|
|
956
|
+
},] }
|
|
957
|
+
];
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Generated bundle index. Do not edit.
|
|
961
|
+
*/
|
|
962
|
+
|
|
963
|
+
exports.CONFIG_TOKEN = CONFIG_TOKEN;
|
|
964
|
+
exports.NgxIndexedDBModule = NgxIndexedDBModule;
|
|
965
|
+
exports.NgxIndexedDBService = NgxIndexedDBService;
|
|
966
|
+
|
|
967
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
968
|
+
|
|
969
|
+
})));
|
|
970
|
+
//# sourceMappingURL=ngx-indexed-db.umd.js.map
|