@po-ui/ng-storage 5.22.2 → 5.22.3
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 +16 -16
- package/bundles/po-ui-ng-storage.umd.js +1228 -1228
- package/bundles/po-ui-ng-storage.umd.js.map +1 -1
- package/esm2015/lib/drivers/lokijs/po-loki-driver.js +209 -209
- package/esm2015/lib/index.js +3 -3
- package/esm2015/lib/po-storage.module.js +29 -29
- package/esm2015/lib/services/po-storage-config.interface.js +11 -11
- package/esm2015/lib/services/po-storage.service.js +546 -546
- package/esm2015/po-ui-ng-storage.js +5 -5
- package/esm2015/public-api.js +2 -2
- package/fesm2015/po-ui-ng-storage.js +770 -770
- package/fesm2015/po-ui-ng-storage.js.map +1 -1
- package/lib/drivers/lokijs/po-loki-driver.d.ts +30 -30
- package/lib/index.d.ts +3 -3
- package/lib/po-storage.module.d.ts +10 -10
- package/lib/services/po-storage-config.interface.d.ts +27 -27
- package/lib/services/po-storage.service.d.ts +378 -378
- package/package.json +2 -2
- package/po-ui-ng-storage-5.22.3.tgz +0 -0
- package/po-ui-ng-storage.d.ts +5 -5
- package/public-api.d.ts +1 -1
- package/schematics/README.md +91 -91
- package/schematics/collection.json +10 -10
- package/schematics/ng-add/index.d.ts +7 -7
- package/schematics/ng-add/index.js +28 -28
- package/schematics/ng-add/index.spec.d.ts +1 -1
- package/schematics/ng-add/index.spec.js +50 -50
- package/schematics/ng-add/schema.json +6 -6
- package/po-ui-ng-storage-5.22.2.tgz +0 -0
|
@@ -31,1242 +31,1242 @@
|
|
|
31
31
|
var Loki__default = /*#__PURE__*/_interopDefaultLegacy(Loki);
|
|
32
32
|
var LokiIndexedAdapter__default = /*#__PURE__*/_interopDefaultLegacy(LokiIndexedAdapter);
|
|
33
33
|
|
|
34
|
-
/*! *****************************************************************************
|
|
35
|
-
Copyright (c) Microsoft Corporation.
|
|
36
|
-
|
|
37
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
38
|
-
purpose with or without fee is hereby granted.
|
|
39
|
-
|
|
40
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
41
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
42
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
43
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
44
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
45
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
46
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
47
|
-
***************************************************************************** */
|
|
48
|
-
/* global Reflect, Promise */
|
|
49
|
-
var extendStatics = function (d, b) {
|
|
50
|
-
extendStatics = Object.setPrototypeOf ||
|
|
51
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
52
|
-
function (d, b) { for (var p in b)
|
|
53
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
54
|
-
d[p] = b[p]; };
|
|
55
|
-
return extendStatics(d, b);
|
|
56
|
-
};
|
|
57
|
-
function __extends(d, b) {
|
|
58
|
-
if (typeof b !== "function" && b !== null)
|
|
59
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
60
|
-
extendStatics(d, b);
|
|
61
|
-
function __() { this.constructor = d; }
|
|
62
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
63
|
-
}
|
|
64
|
-
var __assign = function () {
|
|
65
|
-
__assign = Object.assign || function __assign(t) {
|
|
66
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
67
|
-
s = arguments[i];
|
|
68
|
-
for (var p in s)
|
|
69
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
70
|
-
t[p] = s[p];
|
|
71
|
-
}
|
|
72
|
-
return t;
|
|
73
|
-
};
|
|
74
|
-
return __assign.apply(this, arguments);
|
|
75
|
-
};
|
|
76
|
-
function __rest(s, e) {
|
|
77
|
-
var t = {};
|
|
78
|
-
for (var p in s)
|
|
79
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
80
|
-
t[p] = s[p];
|
|
81
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
82
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
83
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
84
|
-
t[p[i]] = s[p[i]];
|
|
85
|
-
}
|
|
86
|
-
return t;
|
|
87
|
-
}
|
|
88
|
-
function __decorate(decorators, target, key, desc) {
|
|
89
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
90
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
91
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
92
|
-
else
|
|
93
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
94
|
-
if (d = decorators[i])
|
|
95
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
96
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
97
|
-
}
|
|
98
|
-
function __param(paramIndex, decorator) {
|
|
99
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
100
|
-
}
|
|
101
|
-
function __metadata(metadataKey, metadataValue) {
|
|
102
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
103
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
104
|
-
}
|
|
105
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
106
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
107
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
108
|
-
function fulfilled(value) { try {
|
|
109
|
-
step(generator.next(value));
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
reject(e);
|
|
113
|
-
} }
|
|
114
|
-
function rejected(value) { try {
|
|
115
|
-
step(generator["throw"](value));
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
reject(e);
|
|
119
|
-
} }
|
|
120
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
121
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
function __generator(thisArg, body) {
|
|
125
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
126
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
127
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
128
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
129
|
-
function step(op) {
|
|
130
|
-
if (f)
|
|
131
|
-
throw new TypeError("Generator is already executing.");
|
|
132
|
-
while (_)
|
|
133
|
-
try {
|
|
134
|
-
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)
|
|
135
|
-
return t;
|
|
136
|
-
if (y = 0, t)
|
|
137
|
-
op = [op[0] & 2, t.value];
|
|
138
|
-
switch (op[0]) {
|
|
139
|
-
case 0:
|
|
140
|
-
case 1:
|
|
141
|
-
t = op;
|
|
142
|
-
break;
|
|
143
|
-
case 4:
|
|
144
|
-
_.label++;
|
|
145
|
-
return { value: op[1], done: false };
|
|
146
|
-
case 5:
|
|
147
|
-
_.label++;
|
|
148
|
-
y = op[1];
|
|
149
|
-
op = [0];
|
|
150
|
-
continue;
|
|
151
|
-
case 7:
|
|
152
|
-
op = _.ops.pop();
|
|
153
|
-
_.trys.pop();
|
|
154
|
-
continue;
|
|
155
|
-
default:
|
|
156
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
157
|
-
_ = 0;
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
161
|
-
_.label = op[1];
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
165
|
-
_.label = t[1];
|
|
166
|
-
t = op;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
if (t && _.label < t[2]) {
|
|
170
|
-
_.label = t[2];
|
|
171
|
-
_.ops.push(op);
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (t[2])
|
|
175
|
-
_.ops.pop();
|
|
176
|
-
_.trys.pop();
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
op = body.call(thisArg, _);
|
|
180
|
-
}
|
|
181
|
-
catch (e) {
|
|
182
|
-
op = [6, e];
|
|
183
|
-
y = 0;
|
|
184
|
-
}
|
|
185
|
-
finally {
|
|
186
|
-
f = t = 0;
|
|
187
|
-
}
|
|
188
|
-
if (op[0] & 5)
|
|
189
|
-
throw op[1];
|
|
190
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
194
|
-
if (k2 === undefined)
|
|
195
|
-
k2 = k;
|
|
196
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
197
|
-
}) : (function (o, m, k, k2) {
|
|
198
|
-
if (k2 === undefined)
|
|
199
|
-
k2 = k;
|
|
200
|
-
o[k2] = m[k];
|
|
201
|
-
});
|
|
202
|
-
function __exportStar(m, o) {
|
|
203
|
-
for (var p in m)
|
|
204
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
205
|
-
__createBinding(o, m, p);
|
|
206
|
-
}
|
|
207
|
-
function __values(o) {
|
|
208
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
209
|
-
if (m)
|
|
210
|
-
return m.call(o);
|
|
211
|
-
if (o && typeof o.length === "number")
|
|
212
|
-
return {
|
|
213
|
-
next: function () {
|
|
214
|
-
if (o && i >= o.length)
|
|
215
|
-
o = void 0;
|
|
216
|
-
return { value: o && o[i++], done: !o };
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
220
|
-
}
|
|
221
|
-
function __read(o, n) {
|
|
222
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
223
|
-
if (!m)
|
|
224
|
-
return o;
|
|
225
|
-
var i = m.call(o), r, ar = [], e;
|
|
226
|
-
try {
|
|
227
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
228
|
-
ar.push(r.value);
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
e = { error: error };
|
|
232
|
-
}
|
|
233
|
-
finally {
|
|
234
|
-
try {
|
|
235
|
-
if (r && !r.done && (m = i["return"]))
|
|
236
|
-
m.call(i);
|
|
237
|
-
}
|
|
238
|
-
finally {
|
|
239
|
-
if (e)
|
|
240
|
-
throw e.error;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return ar;
|
|
244
|
-
}
|
|
245
|
-
/** @deprecated */
|
|
246
|
-
function __spread() {
|
|
247
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
248
|
-
ar = ar.concat(__read(arguments[i]));
|
|
249
|
-
return ar;
|
|
250
|
-
}
|
|
251
|
-
/** @deprecated */
|
|
252
|
-
function __spreadArrays() {
|
|
253
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
254
|
-
s += arguments[i].length;
|
|
255
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
256
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
257
|
-
r[k] = a[j];
|
|
258
|
-
return r;
|
|
259
|
-
}
|
|
260
|
-
function __spreadArray(to, from, pack) {
|
|
261
|
-
if (pack || arguments.length === 2)
|
|
262
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
263
|
-
if (ar || !(i in from)) {
|
|
264
|
-
if (!ar)
|
|
265
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
266
|
-
ar[i] = from[i];
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
270
|
-
}
|
|
271
|
-
function __await(v) {
|
|
272
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
273
|
-
}
|
|
274
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
275
|
-
if (!Symbol.asyncIterator)
|
|
276
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
277
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
278
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
279
|
-
function verb(n) { if (g[n])
|
|
280
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
281
|
-
function resume(n, v) { try {
|
|
282
|
-
step(g[n](v));
|
|
283
|
-
}
|
|
284
|
-
catch (e) {
|
|
285
|
-
settle(q[0][3], e);
|
|
286
|
-
} }
|
|
287
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
288
|
-
function fulfill(value) { resume("next", value); }
|
|
289
|
-
function reject(value) { resume("throw", value); }
|
|
290
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
291
|
-
resume(q[0][0], q[0][1]); }
|
|
292
|
-
}
|
|
293
|
-
function __asyncDelegator(o) {
|
|
294
|
-
var i, p;
|
|
295
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
296
|
-
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; }
|
|
297
|
-
}
|
|
298
|
-
function __asyncValues(o) {
|
|
299
|
-
if (!Symbol.asyncIterator)
|
|
300
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
301
|
-
var m = o[Symbol.asyncIterator], i;
|
|
302
|
-
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);
|
|
303
|
-
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); }); }; }
|
|
304
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
305
|
-
}
|
|
306
|
-
function __makeTemplateObject(cooked, raw) {
|
|
307
|
-
if (Object.defineProperty) {
|
|
308
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
cooked.raw = raw;
|
|
312
|
-
}
|
|
313
|
-
return cooked;
|
|
314
|
-
}
|
|
315
|
-
;
|
|
316
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
317
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
318
|
-
}) : function (o, v) {
|
|
319
|
-
o["default"] = v;
|
|
320
|
-
};
|
|
321
|
-
function __importStar(mod) {
|
|
322
|
-
if (mod && mod.__esModule)
|
|
323
|
-
return mod;
|
|
324
|
-
var result = {};
|
|
325
|
-
if (mod != null)
|
|
326
|
-
for (var k in mod)
|
|
327
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
328
|
-
__createBinding(result, mod, k);
|
|
329
|
-
__setModuleDefault(result, mod);
|
|
330
|
-
return result;
|
|
331
|
-
}
|
|
332
|
-
function __importDefault(mod) {
|
|
333
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
334
|
-
}
|
|
335
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
336
|
-
if (kind === "a" && !f)
|
|
337
|
-
throw new TypeError("Private accessor was defined without a getter");
|
|
338
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
339
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
340
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
341
|
-
}
|
|
342
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
343
|
-
if (kind === "m")
|
|
344
|
-
throw new TypeError("Private method is not writable");
|
|
345
|
-
if (kind === "a" && !f)
|
|
346
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
347
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
348
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
349
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
34
|
+
/*! *****************************************************************************
|
|
35
|
+
Copyright (c) Microsoft Corporation.
|
|
36
|
+
|
|
37
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
38
|
+
purpose with or without fee is hereby granted.
|
|
39
|
+
|
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
41
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
42
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
43
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
44
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
45
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
46
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
47
|
+
***************************************************************************** */
|
|
48
|
+
/* global Reflect, Promise */
|
|
49
|
+
var extendStatics = function (d, b) {
|
|
50
|
+
extendStatics = Object.setPrototypeOf ||
|
|
51
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
52
|
+
function (d, b) { for (var p in b)
|
|
53
|
+
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
54
|
+
d[p] = b[p]; };
|
|
55
|
+
return extendStatics(d, b);
|
|
56
|
+
};
|
|
57
|
+
function __extends(d, b) {
|
|
58
|
+
if (typeof b !== "function" && b !== null)
|
|
59
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
60
|
+
extendStatics(d, b);
|
|
61
|
+
function __() { this.constructor = d; }
|
|
62
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
63
|
+
}
|
|
64
|
+
var __assign = function () {
|
|
65
|
+
__assign = Object.assign || function __assign(t) {
|
|
66
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
67
|
+
s = arguments[i];
|
|
68
|
+
for (var p in s)
|
|
69
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
70
|
+
t[p] = s[p];
|
|
71
|
+
}
|
|
72
|
+
return t;
|
|
73
|
+
};
|
|
74
|
+
return __assign.apply(this, arguments);
|
|
75
|
+
};
|
|
76
|
+
function __rest(s, e) {
|
|
77
|
+
var t = {};
|
|
78
|
+
for (var p in s)
|
|
79
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
80
|
+
t[p] = s[p];
|
|
81
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
82
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
83
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
84
|
+
t[p[i]] = s[p[i]];
|
|
85
|
+
}
|
|
86
|
+
return t;
|
|
87
|
+
}
|
|
88
|
+
function __decorate(decorators, target, key, desc) {
|
|
89
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
90
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
91
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
92
|
+
else
|
|
93
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
94
|
+
if (d = decorators[i])
|
|
95
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
96
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
97
|
+
}
|
|
98
|
+
function __param(paramIndex, decorator) {
|
|
99
|
+
return function (target, key) { decorator(target, key, paramIndex); };
|
|
100
|
+
}
|
|
101
|
+
function __metadata(metadataKey, metadataValue) {
|
|
102
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
103
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
104
|
+
}
|
|
105
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
106
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
107
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
108
|
+
function fulfilled(value) { try {
|
|
109
|
+
step(generator.next(value));
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
reject(e);
|
|
113
|
+
} }
|
|
114
|
+
function rejected(value) { try {
|
|
115
|
+
step(generator["throw"](value));
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
reject(e);
|
|
119
|
+
} }
|
|
120
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
121
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function __generator(thisArg, body) {
|
|
125
|
+
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
126
|
+
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
127
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
128
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
129
|
+
function step(op) {
|
|
130
|
+
if (f)
|
|
131
|
+
throw new TypeError("Generator is already executing.");
|
|
132
|
+
while (_)
|
|
133
|
+
try {
|
|
134
|
+
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)
|
|
135
|
+
return t;
|
|
136
|
+
if (y = 0, t)
|
|
137
|
+
op = [op[0] & 2, t.value];
|
|
138
|
+
switch (op[0]) {
|
|
139
|
+
case 0:
|
|
140
|
+
case 1:
|
|
141
|
+
t = op;
|
|
142
|
+
break;
|
|
143
|
+
case 4:
|
|
144
|
+
_.label++;
|
|
145
|
+
return { value: op[1], done: false };
|
|
146
|
+
case 5:
|
|
147
|
+
_.label++;
|
|
148
|
+
y = op[1];
|
|
149
|
+
op = [0];
|
|
150
|
+
continue;
|
|
151
|
+
case 7:
|
|
152
|
+
op = _.ops.pop();
|
|
153
|
+
_.trys.pop();
|
|
154
|
+
continue;
|
|
155
|
+
default:
|
|
156
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
157
|
+
_ = 0;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
161
|
+
_.label = op[1];
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
165
|
+
_.label = t[1];
|
|
166
|
+
t = op;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
if (t && _.label < t[2]) {
|
|
170
|
+
_.label = t[2];
|
|
171
|
+
_.ops.push(op);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (t[2])
|
|
175
|
+
_.ops.pop();
|
|
176
|
+
_.trys.pop();
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
op = body.call(thisArg, _);
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
op = [6, e];
|
|
183
|
+
y = 0;
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
f = t = 0;
|
|
187
|
+
}
|
|
188
|
+
if (op[0] & 5)
|
|
189
|
+
throw op[1];
|
|
190
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
194
|
+
if (k2 === undefined)
|
|
195
|
+
k2 = k;
|
|
196
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
197
|
+
}) : (function (o, m, k, k2) {
|
|
198
|
+
if (k2 === undefined)
|
|
199
|
+
k2 = k;
|
|
200
|
+
o[k2] = m[k];
|
|
201
|
+
});
|
|
202
|
+
function __exportStar(m, o) {
|
|
203
|
+
for (var p in m)
|
|
204
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
205
|
+
__createBinding(o, m, p);
|
|
206
|
+
}
|
|
207
|
+
function __values(o) {
|
|
208
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
209
|
+
if (m)
|
|
210
|
+
return m.call(o);
|
|
211
|
+
if (o && typeof o.length === "number")
|
|
212
|
+
return {
|
|
213
|
+
next: function () {
|
|
214
|
+
if (o && i >= o.length)
|
|
215
|
+
o = void 0;
|
|
216
|
+
return { value: o && o[i++], done: !o };
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
220
|
+
}
|
|
221
|
+
function __read(o, n) {
|
|
222
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
223
|
+
if (!m)
|
|
224
|
+
return o;
|
|
225
|
+
var i = m.call(o), r, ar = [], e;
|
|
226
|
+
try {
|
|
227
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
228
|
+
ar.push(r.value);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
e = { error: error };
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
try {
|
|
235
|
+
if (r && !r.done && (m = i["return"]))
|
|
236
|
+
m.call(i);
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
if (e)
|
|
240
|
+
throw e.error;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return ar;
|
|
244
|
+
}
|
|
245
|
+
/** @deprecated */
|
|
246
|
+
function __spread() {
|
|
247
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
248
|
+
ar = ar.concat(__read(arguments[i]));
|
|
249
|
+
return ar;
|
|
250
|
+
}
|
|
251
|
+
/** @deprecated */
|
|
252
|
+
function __spreadArrays() {
|
|
253
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
254
|
+
s += arguments[i].length;
|
|
255
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
256
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
257
|
+
r[k] = a[j];
|
|
258
|
+
return r;
|
|
259
|
+
}
|
|
260
|
+
function __spreadArray(to, from, pack) {
|
|
261
|
+
if (pack || arguments.length === 2)
|
|
262
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
263
|
+
if (ar || !(i in from)) {
|
|
264
|
+
if (!ar)
|
|
265
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
266
|
+
ar[i] = from[i];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
270
|
+
}
|
|
271
|
+
function __await(v) {
|
|
272
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
273
|
+
}
|
|
274
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
275
|
+
if (!Symbol.asyncIterator)
|
|
276
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
277
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
278
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
279
|
+
function verb(n) { if (g[n])
|
|
280
|
+
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
281
|
+
function resume(n, v) { try {
|
|
282
|
+
step(g[n](v));
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
settle(q[0][3], e);
|
|
286
|
+
} }
|
|
287
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
288
|
+
function fulfill(value) { resume("next", value); }
|
|
289
|
+
function reject(value) { resume("throw", value); }
|
|
290
|
+
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
291
|
+
resume(q[0][0], q[0][1]); }
|
|
292
|
+
}
|
|
293
|
+
function __asyncDelegator(o) {
|
|
294
|
+
var i, p;
|
|
295
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
296
|
+
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; }
|
|
297
|
+
}
|
|
298
|
+
function __asyncValues(o) {
|
|
299
|
+
if (!Symbol.asyncIterator)
|
|
300
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
301
|
+
var m = o[Symbol.asyncIterator], i;
|
|
302
|
+
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);
|
|
303
|
+
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); }); }; }
|
|
304
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
305
|
+
}
|
|
306
|
+
function __makeTemplateObject(cooked, raw) {
|
|
307
|
+
if (Object.defineProperty) {
|
|
308
|
+
Object.defineProperty(cooked, "raw", { value: raw });
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
cooked.raw = raw;
|
|
312
|
+
}
|
|
313
|
+
return cooked;
|
|
314
|
+
}
|
|
315
|
+
;
|
|
316
|
+
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
317
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
318
|
+
}) : function (o, v) {
|
|
319
|
+
o["default"] = v;
|
|
320
|
+
};
|
|
321
|
+
function __importStar(mod) {
|
|
322
|
+
if (mod && mod.__esModule)
|
|
323
|
+
return mod;
|
|
324
|
+
var result = {};
|
|
325
|
+
if (mod != null)
|
|
326
|
+
for (var k in mod)
|
|
327
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
328
|
+
__createBinding(result, mod, k);
|
|
329
|
+
__setModuleDefault(result, mod);
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
function __importDefault(mod) {
|
|
333
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
334
|
+
}
|
|
335
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
336
|
+
if (kind === "a" && !f)
|
|
337
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
338
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
339
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
340
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
341
|
+
}
|
|
342
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
343
|
+
if (kind === "m")
|
|
344
|
+
throw new TypeError("Private method is not writable");
|
|
345
|
+
if (kind === "a" && !f)
|
|
346
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
347
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
348
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
349
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
-
var keyField = 'key';
|
|
353
|
-
var PoLokiDriver = /** @class */ (function () {
|
|
354
|
-
function PoLokiDriver() {
|
|
355
|
-
var self = this;
|
|
356
|
-
this.driver = {
|
|
357
|
-
_driver: 'lokijs',
|
|
358
|
-
_initStorage: function (options) {
|
|
359
|
-
return self.initStorage(options);
|
|
360
|
-
},
|
|
361
|
-
clear: function () {
|
|
362
|
-
return self.clear(this);
|
|
363
|
-
},
|
|
364
|
-
getItem: function (key) {
|
|
365
|
-
return self.getItem(this, key);
|
|
366
|
-
},
|
|
367
|
-
iterate: function (iteratorCallback) {
|
|
368
|
-
return self.iterate(this, iteratorCallback);
|
|
369
|
-
},
|
|
370
|
-
key: function (n) {
|
|
371
|
-
return self.key(this, n);
|
|
372
|
-
},
|
|
373
|
-
keys: function () {
|
|
374
|
-
return self.keys(this);
|
|
375
|
-
},
|
|
376
|
-
length: function () {
|
|
377
|
-
return self.length(this);
|
|
378
|
-
},
|
|
379
|
-
removeItem: function (key) {
|
|
380
|
-
return self.removeItem(this, key);
|
|
381
|
-
},
|
|
382
|
-
setItem: function (key, value) {
|
|
383
|
-
return self.setItem(this, key, value);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
// Funções de iteração
|
|
388
|
-
PoLokiDriver.prototype.clear = function (localforage) {
|
|
389
|
-
var _this = this;
|
|
390
|
-
return new Promise(function (resolve) {
|
|
391
|
-
localforage.ready().then(function () {
|
|
392
|
-
if (_this.hasCollectionAndDataInCollection()) {
|
|
393
|
-
_this.clearCollection();
|
|
394
|
-
}
|
|
395
|
-
resolve(null);
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
};
|
|
399
|
-
PoLokiDriver.prototype.getItem = function (localforage, key) {
|
|
400
|
-
var _this = this;
|
|
401
|
-
return new Promise(function (resolve) {
|
|
402
|
-
localforage.ready().then(function () {
|
|
403
|
-
if (_this.hasCollectionAndDataInCollection()) {
|
|
404
|
-
var item = _this.getItemInCollectionBy(keyField, key);
|
|
405
|
-
if (item) {
|
|
406
|
-
resolve(item.value);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
resolve(null);
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
};
|
|
413
|
-
PoLokiDriver.prototype.initStorage = function (options) {
|
|
414
|
-
var _this = this;
|
|
415
|
-
return new Promise(function (resolve) {
|
|
416
|
-
try {
|
|
417
|
-
_this.configureLokiStorage(options, _this.databaseInitialize.bind(_this, options, resolve));
|
|
418
|
-
}
|
|
419
|
-
catch (_a) {
|
|
420
|
-
throw new Error("Cannot configure Loki Storage");
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
};
|
|
424
|
-
PoLokiDriver.prototype.iterate = function (localforage, iteratorCallback) {
|
|
425
|
-
var _this = this;
|
|
426
|
-
return new Promise(function (resolve) {
|
|
427
|
-
localforage.ready().then(function () {
|
|
428
|
-
if (_this.hasCollectionAndDataInCollection()) {
|
|
429
|
-
_this.iterateWithDataItem(iteratorCallback);
|
|
430
|
-
}
|
|
431
|
-
resolve(null);
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
PoLokiDriver.prototype.key = function (localforage, n) {
|
|
436
|
-
var _this = this;
|
|
437
|
-
return new Promise(function (resolve) {
|
|
438
|
-
localforage.ready().then(function () {
|
|
439
|
-
if (_this.hasCollection()) {
|
|
440
|
-
var map = _this.getLokiMap();
|
|
441
|
-
resolve(map[n]);
|
|
442
|
-
}
|
|
443
|
-
resolve(null);
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
};
|
|
447
|
-
PoLokiDriver.prototype.keys = function (localforage) {
|
|
448
|
-
var _this = this;
|
|
449
|
-
return new Promise(function (resolve) {
|
|
450
|
-
localforage.ready().then(function () {
|
|
451
|
-
var e_1, _b;
|
|
452
|
-
if (_this.hasCollection()) {
|
|
453
|
-
var keys = [];
|
|
454
|
-
var map = _this.getLokiMap();
|
|
455
|
-
try {
|
|
456
|
-
for (var _c = __values(Object.keys(map)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
457
|
-
var key = _d.value;
|
|
458
|
-
keys.push(map[key]);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
462
|
-
finally {
|
|
463
|
-
try {
|
|
464
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
465
|
-
}
|
|
466
|
-
finally { if (e_1) throw e_1.error; }
|
|
467
|
-
}
|
|
468
|
-
resolve(keys);
|
|
469
|
-
}
|
|
470
|
-
resolve(null);
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
};
|
|
474
|
-
PoLokiDriver.prototype.length = function (localforage) {
|
|
475
|
-
var _this = this;
|
|
476
|
-
return new Promise(function (resolve) {
|
|
477
|
-
localforage.ready().then(function () {
|
|
478
|
-
if (_this.hasCollection()) {
|
|
479
|
-
resolve(_this.getNumberItensInCollection());
|
|
480
|
-
}
|
|
481
|
-
resolve(0);
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
};
|
|
485
|
-
PoLokiDriver.prototype.removeItem = function (localforage, key) {
|
|
486
|
-
var _this = this;
|
|
487
|
-
return new Promise(function (resolve) {
|
|
488
|
-
localforage.ready().then(function () {
|
|
489
|
-
if (_this.hasCollection()) {
|
|
490
|
-
_this.findAndRemoveItem(key);
|
|
491
|
-
}
|
|
492
|
-
resolve(null);
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
PoLokiDriver.prototype.setItem = function (localforage, key, value) {
|
|
497
|
-
var _this = this;
|
|
498
|
-
return new Promise(function (resolve) {
|
|
499
|
-
localforage.ready().then(function () {
|
|
500
|
-
if (_this.hasCollection()) {
|
|
501
|
-
var item = void 0;
|
|
502
|
-
if (_this.hasDataInCollection()) {
|
|
503
|
-
item = _this.getItemInCollectionBy(keyField, key);
|
|
504
|
-
}
|
|
505
|
-
_this.insertOrUpdate(item, value, key);
|
|
506
|
-
}
|
|
507
|
-
resolve(value);
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
};
|
|
511
|
-
// Funções de acesso ao storage
|
|
512
|
-
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
513
|
-
PoLokiDriver.prototype.getDriver = function () {
|
|
514
|
-
return this.driver;
|
|
515
|
-
};
|
|
516
|
-
PoLokiDriver.prototype.addCollection = function (options) {
|
|
517
|
-
return this.db.addCollection(options.storeName, { unique: [keyField] });
|
|
518
|
-
};
|
|
519
|
-
PoLokiDriver.prototype.clearCollection = function () {
|
|
520
|
-
this.collection.clear({ removeIndices: false });
|
|
521
|
-
};
|
|
522
|
-
PoLokiDriver.prototype.configureLokiStorage = function (options, databaseInitialize) {
|
|
523
|
-
var idbAdapter = new LokiIndexedAdapter__default['default']();
|
|
524
|
-
this.db = new Loki__default['default'](options.name, {
|
|
525
|
-
adapter: idbAdapter,
|
|
526
|
-
autoload: true,
|
|
527
|
-
autoloadCallback: databaseInitialize,
|
|
528
|
-
autosave: true,
|
|
529
|
-
autosaveInterval: 4000
|
|
530
|
-
});
|
|
531
|
-
};
|
|
532
|
-
PoLokiDriver.prototype.findAndRemoveItem = function (key) {
|
|
533
|
-
var _b;
|
|
534
|
-
this.collection.findAndRemove((_b = {}, _b[keyField] = key, _b));
|
|
535
|
-
};
|
|
536
|
-
PoLokiDriver.prototype.getCollection = function (options) {
|
|
537
|
-
return this.db.getCollection(options.storeName);
|
|
538
|
-
};
|
|
539
|
-
PoLokiDriver.prototype.databaseInitialize = function (options, resolve) {
|
|
540
|
-
this.collection = this.getCollection(options);
|
|
541
|
-
if (!this.hasCollection()) {
|
|
542
|
-
this.collection = this.addCollection(options);
|
|
543
|
-
}
|
|
544
|
-
resolve();
|
|
545
|
-
};
|
|
546
|
-
PoLokiDriver.prototype.getItemInCollectionBy = function (fieldKey, key) {
|
|
547
|
-
return this.collection.by(fieldKey, key);
|
|
548
|
-
};
|
|
549
|
-
PoLokiDriver.prototype.getLokiMap = function () {
|
|
550
|
-
return this.collection.constraints.unique[keyField].lokiMap;
|
|
551
|
-
};
|
|
552
|
-
PoLokiDriver.prototype.hasCollection = function () {
|
|
553
|
-
return this.collection;
|
|
554
|
-
};
|
|
555
|
-
PoLokiDriver.prototype.hasDataInCollection = function () {
|
|
556
|
-
return this.collection.data && this.collection.data.length;
|
|
557
|
-
};
|
|
558
|
-
PoLokiDriver.prototype.hasCollectionAndDataInCollection = function () {
|
|
559
|
-
return this.hasCollection() && this.hasDataInCollection();
|
|
560
|
-
};
|
|
561
|
-
PoLokiDriver.prototype.insertOrUpdate = function (item, value, key) {
|
|
562
|
-
var _b;
|
|
563
|
-
if (item) {
|
|
564
|
-
item.value = value;
|
|
565
|
-
this.collection.update(item);
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
this.collection.insert((_b = {}, _b[keyField] = key, _b.value = value, _b));
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
PoLokiDriver.prototype.iterateWithDataItem = function (iteratorcallback) {
|
|
572
|
-
this.collection.data.forEach(function (element) {
|
|
573
|
-
iteratorcallback(element.value, element[keyField], element.$loki);
|
|
574
|
-
});
|
|
575
|
-
};
|
|
576
|
-
PoLokiDriver.prototype.getNumberItensInCollection = function () {
|
|
577
|
-
return this.collection.count();
|
|
578
|
-
};
|
|
579
|
-
return PoLokiDriver;
|
|
352
|
+
var keyField = 'key';
|
|
353
|
+
var PoLokiDriver = /** @class */ (function () {
|
|
354
|
+
function PoLokiDriver() {
|
|
355
|
+
var self = this;
|
|
356
|
+
this.driver = {
|
|
357
|
+
_driver: 'lokijs',
|
|
358
|
+
_initStorage: function (options) {
|
|
359
|
+
return self.initStorage(options);
|
|
360
|
+
},
|
|
361
|
+
clear: function () {
|
|
362
|
+
return self.clear(this);
|
|
363
|
+
},
|
|
364
|
+
getItem: function (key) {
|
|
365
|
+
return self.getItem(this, key);
|
|
366
|
+
},
|
|
367
|
+
iterate: function (iteratorCallback) {
|
|
368
|
+
return self.iterate(this, iteratorCallback);
|
|
369
|
+
},
|
|
370
|
+
key: function (n) {
|
|
371
|
+
return self.key(this, n);
|
|
372
|
+
},
|
|
373
|
+
keys: function () {
|
|
374
|
+
return self.keys(this);
|
|
375
|
+
},
|
|
376
|
+
length: function () {
|
|
377
|
+
return self.length(this);
|
|
378
|
+
},
|
|
379
|
+
removeItem: function (key) {
|
|
380
|
+
return self.removeItem(this, key);
|
|
381
|
+
},
|
|
382
|
+
setItem: function (key, value) {
|
|
383
|
+
return self.setItem(this, key, value);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
// Funções de iteração
|
|
388
|
+
PoLokiDriver.prototype.clear = function (localforage) {
|
|
389
|
+
var _this = this;
|
|
390
|
+
return new Promise(function (resolve) {
|
|
391
|
+
localforage.ready().then(function () {
|
|
392
|
+
if (_this.hasCollectionAndDataInCollection()) {
|
|
393
|
+
_this.clearCollection();
|
|
394
|
+
}
|
|
395
|
+
resolve(null);
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
PoLokiDriver.prototype.getItem = function (localforage, key) {
|
|
400
|
+
var _this = this;
|
|
401
|
+
return new Promise(function (resolve) {
|
|
402
|
+
localforage.ready().then(function () {
|
|
403
|
+
if (_this.hasCollectionAndDataInCollection()) {
|
|
404
|
+
var item = _this.getItemInCollectionBy(keyField, key);
|
|
405
|
+
if (item) {
|
|
406
|
+
resolve(item.value);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
resolve(null);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
PoLokiDriver.prototype.initStorage = function (options) {
|
|
414
|
+
var _this = this;
|
|
415
|
+
return new Promise(function (resolve) {
|
|
416
|
+
try {
|
|
417
|
+
_this.configureLokiStorage(options, _this.databaseInitialize.bind(_this, options, resolve));
|
|
418
|
+
}
|
|
419
|
+
catch (_a) {
|
|
420
|
+
throw new Error("Cannot configure Loki Storage");
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
PoLokiDriver.prototype.iterate = function (localforage, iteratorCallback) {
|
|
425
|
+
var _this = this;
|
|
426
|
+
return new Promise(function (resolve) {
|
|
427
|
+
localforage.ready().then(function () {
|
|
428
|
+
if (_this.hasCollectionAndDataInCollection()) {
|
|
429
|
+
_this.iterateWithDataItem(iteratorCallback);
|
|
430
|
+
}
|
|
431
|
+
resolve(null);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
PoLokiDriver.prototype.key = function (localforage, n) {
|
|
436
|
+
var _this = this;
|
|
437
|
+
return new Promise(function (resolve) {
|
|
438
|
+
localforage.ready().then(function () {
|
|
439
|
+
if (_this.hasCollection()) {
|
|
440
|
+
var map = _this.getLokiMap();
|
|
441
|
+
resolve(map[n]);
|
|
442
|
+
}
|
|
443
|
+
resolve(null);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
PoLokiDriver.prototype.keys = function (localforage) {
|
|
448
|
+
var _this = this;
|
|
449
|
+
return new Promise(function (resolve) {
|
|
450
|
+
localforage.ready().then(function () {
|
|
451
|
+
var e_1, _b;
|
|
452
|
+
if (_this.hasCollection()) {
|
|
453
|
+
var keys = [];
|
|
454
|
+
var map = _this.getLokiMap();
|
|
455
|
+
try {
|
|
456
|
+
for (var _c = __values(Object.keys(map)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
457
|
+
var key = _d.value;
|
|
458
|
+
keys.push(map[key]);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
462
|
+
finally {
|
|
463
|
+
try {
|
|
464
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
465
|
+
}
|
|
466
|
+
finally { if (e_1) throw e_1.error; }
|
|
467
|
+
}
|
|
468
|
+
resolve(keys);
|
|
469
|
+
}
|
|
470
|
+
resolve(null);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
PoLokiDriver.prototype.length = function (localforage) {
|
|
475
|
+
var _this = this;
|
|
476
|
+
return new Promise(function (resolve) {
|
|
477
|
+
localforage.ready().then(function () {
|
|
478
|
+
if (_this.hasCollection()) {
|
|
479
|
+
resolve(_this.getNumberItensInCollection());
|
|
480
|
+
}
|
|
481
|
+
resolve(0);
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
PoLokiDriver.prototype.removeItem = function (localforage, key) {
|
|
486
|
+
var _this = this;
|
|
487
|
+
return new Promise(function (resolve) {
|
|
488
|
+
localforage.ready().then(function () {
|
|
489
|
+
if (_this.hasCollection()) {
|
|
490
|
+
_this.findAndRemoveItem(key);
|
|
491
|
+
}
|
|
492
|
+
resolve(null);
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
PoLokiDriver.prototype.setItem = function (localforage, key, value) {
|
|
497
|
+
var _this = this;
|
|
498
|
+
return new Promise(function (resolve) {
|
|
499
|
+
localforage.ready().then(function () {
|
|
500
|
+
if (_this.hasCollection()) {
|
|
501
|
+
var item = void 0;
|
|
502
|
+
if (_this.hasDataInCollection()) {
|
|
503
|
+
item = _this.getItemInCollectionBy(keyField, key);
|
|
504
|
+
}
|
|
505
|
+
_this.insertOrUpdate(item, value, key);
|
|
506
|
+
}
|
|
507
|
+
resolve(value);
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
};
|
|
511
|
+
// Funções de acesso ao storage
|
|
512
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
513
|
+
PoLokiDriver.prototype.getDriver = function () {
|
|
514
|
+
return this.driver;
|
|
515
|
+
};
|
|
516
|
+
PoLokiDriver.prototype.addCollection = function (options) {
|
|
517
|
+
return this.db.addCollection(options.storeName, { unique: [keyField] });
|
|
518
|
+
};
|
|
519
|
+
PoLokiDriver.prototype.clearCollection = function () {
|
|
520
|
+
this.collection.clear({ removeIndices: false });
|
|
521
|
+
};
|
|
522
|
+
PoLokiDriver.prototype.configureLokiStorage = function (options, databaseInitialize) {
|
|
523
|
+
var idbAdapter = new LokiIndexedAdapter__default['default']();
|
|
524
|
+
this.db = new Loki__default['default'](options.name, {
|
|
525
|
+
adapter: idbAdapter,
|
|
526
|
+
autoload: true,
|
|
527
|
+
autoloadCallback: databaseInitialize,
|
|
528
|
+
autosave: true,
|
|
529
|
+
autosaveInterval: 4000
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
PoLokiDriver.prototype.findAndRemoveItem = function (key) {
|
|
533
|
+
var _b;
|
|
534
|
+
this.collection.findAndRemove((_b = {}, _b[keyField] = key, _b));
|
|
535
|
+
};
|
|
536
|
+
PoLokiDriver.prototype.getCollection = function (options) {
|
|
537
|
+
return this.db.getCollection(options.storeName);
|
|
538
|
+
};
|
|
539
|
+
PoLokiDriver.prototype.databaseInitialize = function (options, resolve) {
|
|
540
|
+
this.collection = this.getCollection(options);
|
|
541
|
+
if (!this.hasCollection()) {
|
|
542
|
+
this.collection = this.addCollection(options);
|
|
543
|
+
}
|
|
544
|
+
resolve();
|
|
545
|
+
};
|
|
546
|
+
PoLokiDriver.prototype.getItemInCollectionBy = function (fieldKey, key) {
|
|
547
|
+
return this.collection.by(fieldKey, key);
|
|
548
|
+
};
|
|
549
|
+
PoLokiDriver.prototype.getLokiMap = function () {
|
|
550
|
+
return this.collection.constraints.unique[keyField].lokiMap;
|
|
551
|
+
};
|
|
552
|
+
PoLokiDriver.prototype.hasCollection = function () {
|
|
553
|
+
return this.collection;
|
|
554
|
+
};
|
|
555
|
+
PoLokiDriver.prototype.hasDataInCollection = function () {
|
|
556
|
+
return this.collection.data && this.collection.data.length;
|
|
557
|
+
};
|
|
558
|
+
PoLokiDriver.prototype.hasCollectionAndDataInCollection = function () {
|
|
559
|
+
return this.hasCollection() && this.hasDataInCollection();
|
|
560
|
+
};
|
|
561
|
+
PoLokiDriver.prototype.insertOrUpdate = function (item, value, key) {
|
|
562
|
+
var _b;
|
|
563
|
+
if (item) {
|
|
564
|
+
item.value = value;
|
|
565
|
+
this.collection.update(item);
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
this.collection.insert((_b = {}, _b[keyField] = key, _b.value = value, _b));
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
PoLokiDriver.prototype.iterateWithDataItem = function (iteratorcallback) {
|
|
572
|
+
this.collection.data.forEach(function (element) {
|
|
573
|
+
iteratorcallback(element.value, element[keyField], element.$loki);
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
PoLokiDriver.prototype.getNumberItensInCollection = function () {
|
|
577
|
+
return this.collection.count();
|
|
578
|
+
};
|
|
579
|
+
return PoLokiDriver;
|
|
580
580
|
}());
|
|
581
581
|
|
|
582
|
-
var PO_STORAGE_CONFIG_TOKEN = new core.InjectionToken('PO_STORAGE_CONFIG_TOKEN');
|
|
583
|
-
/**
|
|
584
|
-
* @description
|
|
585
|
-
*
|
|
586
|
-
* O PO Storage é uma biblioteca que fornece um serviço para armazenamento de dados no dispositivo local, sendo semelhante
|
|
587
|
-
* ao funcionamento do [IonicStorage](https://ionicframework.com/docs/storage/).
|
|
588
|
-
* É possível utilizar os drivers [Websql](https://dev.w3.org/html5/webdatabase/), [Indexeddb](https://www.w3.org/TR/IndexedDB/),
|
|
589
|
-
* [LocalStorage](https://html.spec.whatwg.org/multipage/webstorage.html) e também [LokiJS](https://github.com/techfort/LokiJS/wiki).
|
|
590
|
-
*
|
|
591
|
-
* Para um melhor ganho de performance ao buscar e salvar dados, recomendamos a utilização do `LokiJS`, um *database*
|
|
592
|
-
* orientado a documento semelhante ao MongoDB, que além de permitir a persistência dos dados no dispositivo possibilita
|
|
593
|
-
* também o armazenamento dos dados em memória. Outra vantagem, é o aumento do limite de armazenamento para
|
|
594
|
-
* aproximadamente `300mb`.
|
|
595
|
-
*
|
|
596
|
-
* A estrutura utilizada para armazenar os dados é a de chave/valor, onde uma chave funciona como um identificador exclusivo.
|
|
597
|
-
*
|
|
598
|
-
* #### Instalando o PO Storage
|
|
599
|
-
*
|
|
600
|
-
* Para instalar o `po-storage` em sua aplicação execute o seguinte comando:
|
|
601
|
-
*
|
|
602
|
-
* ```shell
|
|
603
|
-
* ng add @po-ui/ng-storage
|
|
604
|
-
* ```
|
|
605
|
-
* Será instalado o pacote `@po-ui/ng-storage` e também já importará `PoStorageModule` no módulo principal da sua aplicação, conforme abaixo:
|
|
606
|
-
*
|
|
607
|
-
* ```typescript
|
|
608
|
-
* import { PoStorageModule } from '@po-ui/ng-storage';
|
|
609
|
-
*
|
|
610
|
-
* @NgModule({
|
|
611
|
-
* declarations: [...],
|
|
612
|
-
* imports: [
|
|
613
|
-
* // Importação do módulo PoStorageModule
|
|
614
|
-
* PoStorageModule.forRoot(),
|
|
615
|
-
* ],
|
|
616
|
-
* bootstrap: [IonicApp],
|
|
617
|
-
* providers: [...]
|
|
618
|
-
* })
|
|
619
|
-
* export class AppModule {}
|
|
620
|
-
* ```
|
|
621
|
-
*
|
|
622
|
-
* Com a declaração do módulo, é criada uma base de dados no armazenamento local e o serviço `PoStorageService` estará
|
|
623
|
-
* pronto para ser utilizada na sua aplicação.
|
|
624
|
-
*
|
|
625
|
-
* #### Configurando as opções de armazenamento
|
|
626
|
-
*
|
|
627
|
-
* Na importação do módulo, o método `PoStorageModule.forRoot()` pode receber como parâmetro um objeto do tipo
|
|
628
|
-
* [`PoStorageConfig`](documentation/po-storage#po-storage-config),
|
|
629
|
-
* que serve para configurar as opções personalizadas do armazenamento, como por exemplo: o tipo de armazenamento
|
|
630
|
-
* preferêncial.
|
|
631
|
-
*
|
|
632
|
-
* Caso não seja passada nenhuma configuração a ordem padrão será: ['websql', 'indexeddb', 'localstorage', 'lokijs'].
|
|
633
|
-
*
|
|
634
|
-
* Abaixo segue um exemplo de configuração onde o storage preferencial passa a ser o `lokijs`:
|
|
635
|
-
*
|
|
636
|
-
* ```typescript
|
|
637
|
-
* import { PoStorageModule } from '@po-ui/ng-storage';
|
|
638
|
-
*
|
|
639
|
-
* @NgModule({
|
|
640
|
-
* declarations: [...],
|
|
641
|
-
* imports: [
|
|
642
|
-
* // Importação do módulo PoStorageModule com a configuração personalizada
|
|
643
|
-
* PoStorageModule.forRoot({
|
|
644
|
-
* name: 'mystorage',
|
|
645
|
-
* storeName: '_mystore',
|
|
646
|
-
* driverOrder: ['lokijs', 'websql', 'indexeddb', 'localstorage']
|
|
647
|
-
* }),
|
|
648
|
-
* ],
|
|
649
|
-
* bootstrap: [IonicApp],
|
|
650
|
-
* providers: [...]
|
|
651
|
-
* })
|
|
652
|
-
* export class AppModule {}
|
|
653
|
-
* ```
|
|
654
|
-
*/
|
|
655
|
-
var PoStorageService = /** @class */ (function () {
|
|
656
|
-
function PoStorageService(config) {
|
|
657
|
-
this.driver = null;
|
|
658
|
-
this.idleQueue = new IdleQueue__default['default']();
|
|
659
|
-
this.lokijsDriver = new PoLokiDriver();
|
|
660
|
-
this.setStoragePromise(config);
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Retorna a configuração padrão para o armazenamento. Caso nenhuma configuração seja inserida,
|
|
664
|
-
* essa configuração será utilizada.
|
|
665
|
-
*
|
|
666
|
-
* @returns {PoStorageConfig} Objeto com a configuração padrão do armazenamento.
|
|
667
|
-
*/
|
|
668
|
-
PoStorageService.getDefaultConfig = function () {
|
|
669
|
-
return {
|
|
670
|
-
name: '_postorage',
|
|
671
|
-
storeName: '_pokv',
|
|
672
|
-
driverOrder: ['websql', 'indexeddb', 'localstorage', 'lokijs']
|
|
673
|
-
};
|
|
674
|
-
};
|
|
675
|
-
/**
|
|
676
|
-
* Cria uma instância do `PoStorageService` com a configuração de armazenamento passada como parâmetro.
|
|
677
|
-
*
|
|
678
|
-
* @param {PoStorageConfig} storageConfig Configuração para o armazenamento.
|
|
679
|
-
* @returns {PoStorageService} Instância do `PoStorageService`.
|
|
680
|
-
*/
|
|
681
|
-
PoStorageService.providePoStorage = function (storageConfig) {
|
|
682
|
-
return new PoStorageService(PoStorageService.getConfig(storageConfig));
|
|
683
|
-
};
|
|
684
|
-
PoStorageService.getConfig = function (storageConfig) {
|
|
685
|
-
return storageConfig || PoStorageService.getDefaultConfig();
|
|
686
|
-
};
|
|
687
|
-
/**
|
|
688
|
-
* Busca uma lista armazenada pela chave e concatena com a lista passada por parâmetro.
|
|
689
|
-
*
|
|
690
|
-
* Por exemplo:
|
|
691
|
-
*
|
|
692
|
-
* ``` typescript
|
|
693
|
-
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
694
|
-
*
|
|
695
|
-
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
696
|
-
*
|
|
697
|
-
* ...
|
|
698
|
-
*
|
|
699
|
-
* const newClients = [ { name: 'Lisa', age: 36 }, { name: 'Bruce', age: 18 } ];
|
|
700
|
-
*
|
|
701
|
-
* this.poStorageService.appendArrayToArray('clientKey', newClients).then(() => {
|
|
702
|
-
* // A lista agora será:
|
|
703
|
-
* // [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }, { name: 'Lisa', age: 36 }, { name: 'Bruce', age: 18 }];
|
|
704
|
-
* });
|
|
705
|
-
* ```
|
|
706
|
-
*
|
|
707
|
-
* @param {string} key Chave da lista armazenada.
|
|
708
|
-
* @param {Array} value Lista que será concatenada.
|
|
709
|
-
*
|
|
710
|
-
* @returns {Promise<any>} Promessa que é resolvida após as duas listas serem concatenadas e armazenadas localmente.
|
|
711
|
-
*/
|
|
712
|
-
PoStorageService.prototype.appendArrayToArray = function (key, value) {
|
|
713
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
714
|
-
var data, newData;
|
|
715
|
-
return __generator(this, function (_b) {
|
|
716
|
-
switch (_b.label) {
|
|
717
|
-
case 0: return [4 /*yield*/, this.getArrayOfStorage(key)];
|
|
718
|
-
case 1:
|
|
719
|
-
data = _b.sent();
|
|
720
|
-
newData = __spreadArray(__spreadArray([], __read(data)), __read(value));
|
|
721
|
-
return [2 /*return*/, this.set(key, newData)];
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
});
|
|
725
|
-
};
|
|
726
|
-
/**
|
|
727
|
-
* Acrescenta um item em uma lista armazenada pela chave.
|
|
728
|
-
*
|
|
729
|
-
* @param {string} key Chave da lista armazenada.
|
|
730
|
-
* @param {Array} value Item que será acrescentado na lista.
|
|
731
|
-
*
|
|
732
|
-
* @returns {Promise<any>} Promessa que é resolvida após o item ser acrescentado na lista armazenada.
|
|
733
|
-
*/
|
|
734
|
-
PoStorageService.prototype.appendItemToArray = function (key, value) {
|
|
735
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
736
|
-
var data;
|
|
737
|
-
return __generator(this, function (_b) {
|
|
738
|
-
switch (_b.label) {
|
|
739
|
-
case 0: return [4 /*yield*/, this.getArrayOfStorage(key)];
|
|
740
|
-
case 1:
|
|
741
|
-
data = _b.sent();
|
|
742
|
-
data.push(value);
|
|
743
|
-
return [2 /*return*/, this.set(key, data)];
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
};
|
|
748
|
-
/**
|
|
749
|
-
* Remove todos os itens da base de dados local configurada na declaração do módulo `PoStorageModule`.
|
|
750
|
-
*
|
|
751
|
-
* > Utilize este método com cautela, para evitar a perda indesejada de dados.
|
|
752
|
-
*
|
|
753
|
-
* @returns {Promise<void>} Promessa que é resolvida após todos os itens da base de dados local serem removidos.
|
|
754
|
-
*/
|
|
755
|
-
PoStorageService.prototype.clear = function () {
|
|
756
|
-
return this.storagePromise.then(function (store) { return store.clear(); });
|
|
757
|
-
};
|
|
758
|
-
/**
|
|
759
|
-
* Verifica se existe um valor dentro de uma determinada chave.
|
|
760
|
-
*
|
|
761
|
-
* @param {string} key Chave que será verificada.
|
|
762
|
-
*
|
|
763
|
-
* @returns {Promise<boolean>} Promessa que é resolvida quando a verificação da existência do valor na chave é concluída.
|
|
764
|
-
*/
|
|
765
|
-
PoStorageService.prototype.exists = function (key) {
|
|
766
|
-
return this.get(key).then(function (data) { return Promise.resolve(data !== null); });
|
|
767
|
-
};
|
|
768
|
-
/**
|
|
769
|
-
* Itera sobre todas as chaves armazenadas.
|
|
770
|
-
*
|
|
771
|
-
* @param {any} iteratorCallback Função de `callback` que é chamada a cada iteração, com os seguintes parâmetros:
|
|
772
|
-
* valor, chave e número da iteração.
|
|
773
|
-
*
|
|
774
|
-
* Exemplo de utilização:
|
|
775
|
-
*
|
|
776
|
-
* ``` typescript
|
|
777
|
-
* this.poStorageService.forEach((value: any, key: string, iterationNumber: number) => {
|
|
778
|
-
* // Iteração sobre cada chave armazenada.
|
|
779
|
-
* });
|
|
780
|
-
* ```
|
|
781
|
-
*
|
|
782
|
-
* @returns {Promise<void>} Promessa que é resolvida após a iteração sobre todas as chaves armazenadas.
|
|
783
|
-
*/
|
|
784
|
-
PoStorageService.prototype.forEach = function (iteratorCallback) {
|
|
785
|
-
return this.storagePromise.then(function (store) { return store.iterate(iteratorCallback); });
|
|
786
|
-
};
|
|
787
|
-
/**
|
|
788
|
-
* Retorna o valor armazenado em uma determinada chave.
|
|
789
|
-
*
|
|
790
|
-
* @param {string} key Chave que identifica o item.
|
|
791
|
-
* @param {boolean} lock Define se irá travar a leitura e a escrita da base de dados para não ser acessada de forma paralela.
|
|
792
|
-
* Caso outra leitura/escrita já tenha sido iniciada, este método irá esperar o outro terminar para então começar.
|
|
793
|
-
*
|
|
794
|
-
* Padrão: `false`.
|
|
795
|
-
*
|
|
796
|
-
* > Esta definição só será válida se o outro acesso paralelo a este método também estiver com o parâmetro *lock* ativado.
|
|
797
|
-
* @returns {Promise<any>} Promessa que é resolvida após o item ser buscado.
|
|
798
|
-
*/
|
|
799
|
-
PoStorageService.prototype.get = function (key, lock) {
|
|
800
|
-
if (lock === void 0) { lock = false; }
|
|
801
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
802
|
-
var _this = this;
|
|
803
|
-
return __generator(this, function (_b) {
|
|
804
|
-
switch (_b.label) {
|
|
805
|
-
case 0:
|
|
806
|
-
if (!lock) return [3 /*break*/, 3];
|
|
807
|
-
return [4 /*yield*/, this.requestIdlePromise()];
|
|
808
|
-
case 1:
|
|
809
|
-
_b.sent();
|
|
810
|
-
return [4 /*yield*/, this.idleQueue.wrapCall(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
811
|
-
return __generator(this, function (_b) {
|
|
812
|
-
switch (_b.label) {
|
|
813
|
-
case 0: return [4 /*yield*/, this.getImmutableItem(key)];
|
|
814
|
-
case 1:
|
|
815
|
-
_b.sent();
|
|
816
|
-
return [2 /*return*/];
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
}); })];
|
|
820
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
821
|
-
case 3: return [4 /*yield*/, this.getImmutableItem(key)];
|
|
822
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
};
|
|
827
|
-
/**
|
|
828
|
-
* Retorna o nome do *driver* que está sendo usado para armazenar os dados, por exemplo: localStorage.
|
|
829
|
-
*
|
|
830
|
-
* @returns {string | null} Nome do *driver*.
|
|
831
|
-
*/
|
|
832
|
-
PoStorageService.prototype.getDriver = function () {
|
|
833
|
-
return this.driver;
|
|
834
|
-
};
|
|
835
|
-
/**
|
|
836
|
-
* Retorna o primeiro item de uma lista para uma determinada chave.
|
|
837
|
-
*
|
|
838
|
-
* @param {string} key Chave da lista.
|
|
839
|
-
* @returns {Promise<any>} Promessa que é resolvida após o primeiro item ser encontrado.
|
|
840
|
-
*/
|
|
841
|
-
PoStorageService.prototype.getFirstItem = function (key) {
|
|
842
|
-
return this.get(key).then(function (data) { return Promise.resolve(data ? data[0] : null); });
|
|
843
|
-
};
|
|
844
|
-
/**
|
|
845
|
-
* Remove o primeiro item de uma lista a partir da chave.
|
|
846
|
-
*
|
|
847
|
-
* @param {string} key Chave da lista que será removido o primeiro item.
|
|
848
|
-
* @returns {Promise<any>} Promessa que é resolvida após o primeiro item da lista ser removido.
|
|
849
|
-
*/
|
|
850
|
-
PoStorageService.prototype.getItemAndRemove = function (key) {
|
|
851
|
-
var _this = this;
|
|
852
|
-
return this.get(key).then(function (data) {
|
|
853
|
-
if (data === null) {
|
|
854
|
-
return null;
|
|
855
|
-
}
|
|
856
|
-
var item = data.shift();
|
|
857
|
-
return _this.set(key, data).then(function () { return Promise.resolve(item); });
|
|
858
|
-
});
|
|
859
|
-
};
|
|
860
|
-
/**
|
|
861
|
-
* Busca o primeiro objeto encontrado dentro de uma lista pelo do valor de um campo.
|
|
862
|
-
*
|
|
863
|
-
* Por exemplo:
|
|
864
|
-
*
|
|
865
|
-
* ``` typescript
|
|
866
|
-
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
867
|
-
*
|
|
868
|
-
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
869
|
-
*
|
|
870
|
-
* ...
|
|
871
|
-
*
|
|
872
|
-
* this.poStorageService.getItemByField('clientKey', 'name', 'Marie').then(client => {
|
|
873
|
-
* // Resultado do console.log: { name: 'Marie', age: 23 }
|
|
874
|
-
* console.log(client);
|
|
875
|
-
* });
|
|
876
|
-
* ```
|
|
877
|
-
*
|
|
878
|
-
* @param {string} key Chave da lista.
|
|
879
|
-
* @param {string} fieldName O campo a ser filtrado.
|
|
880
|
-
* @param {any} fieldValue O valor do campo.
|
|
881
|
-
* @returns {Promise<any>} Promessa que é resolvida com o item que foi encontrado.
|
|
882
|
-
*/
|
|
883
|
-
PoStorageService.prototype.getItemByField = function (key, fieldName, fieldValue) {
|
|
884
|
-
return this.get(key).then(function (storageRecords) {
|
|
885
|
-
var storageRecordsFiltered = storageRecords.find(function (storageRecord) { return storageRecord[fieldName] === fieldValue; });
|
|
886
|
-
storageRecordsFiltered = storageRecordsFiltered || null;
|
|
887
|
-
return Promise.resolve(storageRecordsFiltered);
|
|
888
|
-
});
|
|
889
|
-
};
|
|
890
|
-
/**
|
|
891
|
-
* Lista com todas as chaves armazenadas.
|
|
892
|
-
*
|
|
893
|
-
* @returns {Promise<Array<string>>} Promessa que é resolvida com todas as chaves armazenadas.
|
|
894
|
-
*/
|
|
895
|
-
PoStorageService.prototype.keys = function () {
|
|
896
|
-
return this.storagePromise.then(function (store) { return store.keys(); });
|
|
897
|
-
};
|
|
898
|
-
/**
|
|
899
|
-
* Quantidade de chaves armazenadas.
|
|
900
|
-
*
|
|
901
|
-
* @returns {Promise<number>} Promessa que é resolvida com o número de chaves armazenadas.
|
|
902
|
-
*/
|
|
903
|
-
PoStorageService.prototype.length = function () {
|
|
904
|
-
return this.storagePromise.then(function (store) { return store.length(); });
|
|
905
|
-
};
|
|
906
|
-
/**
|
|
907
|
-
* Utilizado para gerenciar o bloqueio e desbloqueio de recursos no `PoStorageService`.
|
|
908
|
-
* Aguardando a liberação da utilização dos recursos que participam deste comportamento e posteriormente envolve o recurso
|
|
909
|
-
* passado como parâmetro em um comportamento de bloqueio e desbloqueio.
|
|
910
|
-
*
|
|
911
|
-
* Este método se comporta igual a utilização em conjunta dos métodos: `PoStorageService.requestIdlePromise()`,
|
|
912
|
-
* `PoStorageService.lock()` e `PoStorageService.unlook()`.
|
|
913
|
-
*
|
|
914
|
-
* Veja mais no método: [`PoStorage.requestIdlePromise()`](documentation/po-storage#request-idle-promise).
|
|
915
|
-
*
|
|
916
|
-
* @param {Function} limitedResource Função que será envolvida no comportamento de bloqueio e desbloqueio.
|
|
917
|
-
*/
|
|
918
|
-
PoStorageService.prototype.limitedCallWrap = function (limitedResource) {
|
|
919
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
920
|
-
return __generator(this, function (_b) {
|
|
921
|
-
switch (_b.label) {
|
|
922
|
-
case 0: return [4 /*yield*/, this.requestIdlePromise()];
|
|
923
|
-
case 1:
|
|
924
|
-
_b.sent();
|
|
925
|
-
return [2 /*return*/, this.idleQueue.wrapCall(limitedResource)];
|
|
926
|
-
}
|
|
927
|
-
});
|
|
928
|
-
});
|
|
929
|
-
};
|
|
930
|
-
/**
|
|
931
|
-
* Incrementa um valor na fila de bloqueio do `PoStorageService`. Utilizado juntamente com o método `unlock` para poder
|
|
932
|
-
* controlar a execução de uma determinada tarefa com o `PoStorage.requestIdlePromise()`.
|
|
933
|
-
*
|
|
934
|
-
* Veja mais no método: [`PoStorage.requestIdlePromise()`](documentation/po-storage#request-idle-promise).
|
|
935
|
-
*/
|
|
936
|
-
PoStorageService.prototype.lock = function () {
|
|
937
|
-
this.idleQueue.lock();
|
|
938
|
-
};
|
|
939
|
-
/**
|
|
940
|
-
* Determina se o processo de inicialização do *driver* assíncrono foi concluído.
|
|
941
|
-
*
|
|
942
|
-
* @returns {Promise<LocalForage>} Promessa que é resolvida quando o processo de inicialização do *driver* assíncrono
|
|
943
|
-
* for concluído.
|
|
944
|
-
*/
|
|
945
|
-
PoStorageService.prototype.ready = function () {
|
|
946
|
-
return this.storagePromise;
|
|
947
|
-
};
|
|
948
|
-
/**
|
|
949
|
-
* Remove um valor associado a uma chave.
|
|
950
|
-
*
|
|
951
|
-
* @param {key} key Chave do valor que será removido.
|
|
952
|
-
* @returns {Promise<any>} Promessa que é resolvida após o valor ser removido.
|
|
953
|
-
*/
|
|
954
|
-
PoStorageService.prototype.remove = function (key) {
|
|
955
|
-
return this.storagePromise.then(function (store) { return store.removeItem(key); });
|
|
956
|
-
};
|
|
957
|
-
/**
|
|
958
|
-
* Remove uma propriedade de um objeto armazenado.
|
|
959
|
-
*
|
|
960
|
-
* @param {string} key Chave do objeto armazenado.
|
|
961
|
-
* @param {string} property Propriedade que será removida.
|
|
962
|
-
*
|
|
963
|
-
* @returns {Promise<any>} Promessa que é resolvida após a propriedade ser removida.
|
|
964
|
-
*/
|
|
965
|
-
PoStorageService.prototype.removeIndexFromObject = function (key, property) {
|
|
966
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
967
|
-
var data;
|
|
968
|
-
return __generator(this, function (_b) {
|
|
969
|
-
switch (_b.label) {
|
|
970
|
-
case 0: return [4 /*yield*/, this.getObjectOfStorage(key)];
|
|
971
|
-
case 1:
|
|
972
|
-
data = _b.sent();
|
|
973
|
-
delete data[property];
|
|
974
|
-
return [2 /*return*/, this.set(key, data)];
|
|
975
|
-
}
|
|
976
|
-
});
|
|
977
|
-
});
|
|
978
|
-
};
|
|
979
|
-
/**
|
|
980
|
-
* Remove um objeto de uma lista armazenada pelo valor de uma propriedade.
|
|
981
|
-
*
|
|
982
|
-
* Por exemplo:
|
|
983
|
-
*
|
|
984
|
-
* ``` typescript
|
|
985
|
-
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
986
|
-
*
|
|
987
|
-
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
988
|
-
*
|
|
989
|
-
* ...
|
|
990
|
-
*
|
|
991
|
-
* this.poStorageService.removeItemFromArray('clientKey', 'name', 'Marie').then(() => {
|
|
992
|
-
* // O objeto { name: 'Marie', age: 23 } foi removido da lista que está na chave 'clientKey'
|
|
993
|
-
* });
|
|
994
|
-
* ```
|
|
995
|
-
*
|
|
996
|
-
* @param {string} key Chave da lista que contém o item que será removido.
|
|
997
|
-
* @param {string} field O campo a ser filtrado no item.
|
|
998
|
-
* @param {string} value O valor do filtro.
|
|
999
|
-
* @returns {Promise<any>} Promessa que é resolvida quando o objeto for removido da lista.
|
|
1000
|
-
*/
|
|
1001
|
-
PoStorageService.prototype.removeItemFromArray = function (key, field, value) {
|
|
1002
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1003
|
-
var data;
|
|
1004
|
-
return __generator(this, function (_b) {
|
|
1005
|
-
switch (_b.label) {
|
|
1006
|
-
case 0: return [4 /*yield*/, this.getArrayOfStorage(key)];
|
|
1007
|
-
case 1:
|
|
1008
|
-
data = _b.sent();
|
|
1009
|
-
data = data.filter(function (item) { return item[field] !== value; });
|
|
1010
|
-
return [2 /*return*/, this.set(key, data)];
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
});
|
|
1014
|
-
};
|
|
1015
|
-
/**
|
|
1016
|
-
* <a id="request-idle-promise"></a>
|
|
1017
|
-
* Método que verifica se o acesso a base de dados configurada está liberado.
|
|
1018
|
-
*
|
|
1019
|
-
* Utilizado em conjunto com os métodos `lock()` e `unlock()` entre tarefas que não podem ser executadas de forma
|
|
1020
|
-
* paralela, para não causar inconsistências nos dados.
|
|
1021
|
-
*
|
|
1022
|
-
* Exemplo de utilização:
|
|
1023
|
-
*
|
|
1024
|
-
* ```
|
|
1025
|
-
* // Aguarda a liberação para continuar
|
|
1026
|
-
* await this.poStorage.requestIdlePromise();
|
|
1027
|
-
*
|
|
1028
|
-
* this.poStorage.lock();
|
|
1029
|
-
*
|
|
1030
|
-
* // Executa uma tarefa que irá ler e/ou escrever na base de dados configurada.
|
|
1031
|
-
*
|
|
1032
|
-
* this.poStorage.unlock();
|
|
1033
|
-
* ```
|
|
1034
|
-
*
|
|
1035
|
-
* > É importante sempre utilizá-lo antes de executar os métodos `lock()` e `unlock()` para garantir que a tarefa só
|
|
1036
|
-
* será executada caso o acesso esteja livre.
|
|
1037
|
-
*
|
|
1038
|
-
* @returns {Promise<any>} Promessa que é resolvida quando o acesso a base de dados configurada estiver liberado.
|
|
1039
|
-
*/
|
|
1040
|
-
PoStorageService.prototype.requestIdlePromise = function () {
|
|
1041
|
-
return this.idleQueue.requestIdlePromise();
|
|
1042
|
-
};
|
|
1043
|
-
/**
|
|
1044
|
-
* Grava um valor em uma determinada chave.
|
|
1045
|
-
*
|
|
1046
|
-
* @param {string} key Chave para o valor que será gravado.
|
|
1047
|
-
* @param {any} value Valor que será gravado.
|
|
1048
|
-
* @param {boolean} lock Define se irá travar a leitura e a escrita da base de dados para não ser acessada de forma paralela.
|
|
1049
|
-
* Caso outra leitura/escrita já tenha sido iniciada, este método irá esperar o outro terminar para então começar.
|
|
1050
|
-
*
|
|
1051
|
-
* Padrão: `false`.
|
|
1052
|
-
*
|
|
1053
|
-
* > Esta definição só será válida se o outro acesso paralelo a este método também estiver com o parâmetro *lock* ativado.
|
|
1054
|
-
* @returns {Promise<any>} Promessa que é resolvida após o valor ter sido gravado.
|
|
1055
|
-
*/
|
|
1056
|
-
PoStorageService.prototype.set = function (key, value, lock) {
|
|
1057
|
-
if (lock === void 0) { lock = false; }
|
|
1058
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1059
|
-
var store, newValue;
|
|
1060
|
-
return __generator(this, function (_b) {
|
|
1061
|
-
switch (_b.label) {
|
|
1062
|
-
case 0: return [4 /*yield*/, this.storagePromise];
|
|
1063
|
-
case 1:
|
|
1064
|
-
store = _b.sent();
|
|
1065
|
-
newValue = typeof value === 'object' ? JSON.parse(JSON.stringify(value)) : value;
|
|
1066
|
-
if (!lock) return [3 /*break*/, 3];
|
|
1067
|
-
return [4 /*yield*/, this.requestIdlePromise()];
|
|
1068
|
-
case 2:
|
|
1069
|
-
_b.sent();
|
|
1070
|
-
return [2 /*return*/, this.idleQueue.wrapCall(function () { return store.setItem(key, newValue); })];
|
|
1071
|
-
case 3: return [2 /*return*/, store.setItem(key, newValue)];
|
|
1072
|
-
}
|
|
1073
|
-
});
|
|
1074
|
-
});
|
|
1075
|
-
};
|
|
1076
|
-
/**
|
|
1077
|
-
* Atribui um valor a uma propriedade de um objeto armazenado pela chave.
|
|
1078
|
-
*
|
|
1079
|
-
* Por exemplo:
|
|
1080
|
-
*
|
|
1081
|
-
* ``` typescript
|
|
1082
|
-
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
1083
|
-
*
|
|
1084
|
-
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
1085
|
-
*
|
|
1086
|
-
* ...
|
|
1087
|
-
*
|
|
1088
|
-
* this.poStorageService.setIndexToObject('clientKey', 'name', 'Clare').then(() => {
|
|
1089
|
-
* // O objeto { name: 'Marie', age: 23 } passa a ser { name: 'Clare', age: 23 }
|
|
1090
|
-
* });
|
|
1091
|
-
* ```
|
|
1092
|
-
*
|
|
1093
|
-
* @param {string} key Chave do objeto.
|
|
1094
|
-
* @param {string} property Nome da propriedade do objeto.
|
|
1095
|
-
* @param {any} value Valor que será gravado na propriedade do objeto.
|
|
1096
|
-
*/
|
|
1097
|
-
PoStorageService.prototype.setIndexToObject = function (key, property, value) {
|
|
1098
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1099
|
-
var data;
|
|
1100
|
-
return __generator(this, function (_b) {
|
|
1101
|
-
switch (_b.label) {
|
|
1102
|
-
case 0: return [4 /*yield*/, this.getObjectOfStorage(key)];
|
|
1103
|
-
case 1:
|
|
1104
|
-
data = _b.sent();
|
|
1105
|
-
data[property] = value;
|
|
1106
|
-
return [2 /*return*/, this.set(key, data)];
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
|
-
});
|
|
1110
|
-
};
|
|
1111
|
-
/**
|
|
1112
|
-
* Decrementa um valor na fila de bloqueio. Utilizado juntamente com o método `lock` para poder
|
|
1113
|
-
* controlar a execução de uma determinada tarefa com o `PoStorage.requestIdlePromise()`.
|
|
1114
|
-
*
|
|
1115
|
-
* Veja mais no método: [`PoStorage.requestIdlePromise()`](documentation/po-storage#request-idle-promise).
|
|
1116
|
-
*/
|
|
1117
|
-
PoStorageService.prototype.unlock = function () {
|
|
1118
|
-
this.idleQueue.unlock();
|
|
1119
|
-
};
|
|
1120
|
-
PoStorageService.prototype.getArrayOfStorage = function (key) {
|
|
1121
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1122
|
-
var data;
|
|
1123
|
-
return __generator(this, function (_b) {
|
|
1124
|
-
switch (_b.label) {
|
|
1125
|
-
case 0: return [4 /*yield*/, this.get(key)];
|
|
1126
|
-
case 1:
|
|
1127
|
-
data = _b.sent();
|
|
1128
|
-
return [2 /*return*/, data || []];
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
});
|
|
1132
|
-
};
|
|
1133
|
-
PoStorageService.prototype.getImmutableItem = function (key) {
|
|
1134
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1135
|
-
var store, items;
|
|
1136
|
-
return __generator(this, function (_b) {
|
|
1137
|
-
switch (_b.label) {
|
|
1138
|
-
case 0: return [4 /*yield*/, this.storagePromise];
|
|
1139
|
-
case 1:
|
|
1140
|
-
store = _b.sent();
|
|
1141
|
-
return [4 /*yield*/, store.getItem(key)];
|
|
1142
|
-
case 2:
|
|
1143
|
-
items = _b.sent();
|
|
1144
|
-
return [2 /*return*/, items ? JSON.parse(JSON.stringify(items)) : null];
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
});
|
|
1148
|
-
};
|
|
1149
|
-
PoStorageService.prototype.defineLocalForageDriver = function (localForageInstance, driverOrder) {
|
|
1150
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1151
|
-
return __generator(this, function (_b) {
|
|
1152
|
-
switch (_b.label) {
|
|
1153
|
-
case 0: return [4 /*yield*/, localForageInstance.defineDriver(this.lokijsDriver.getDriver())];
|
|
1154
|
-
case 1:
|
|
1155
|
-
_b.sent();
|
|
1156
|
-
return [4 /*yield*/, this.setDriver(localForageInstance, driverOrder)];
|
|
1157
|
-
case 2:
|
|
1158
|
-
_b.sent();
|
|
1159
|
-
return [2 /*return*/, localForageInstance];
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
});
|
|
1163
|
-
};
|
|
1164
|
-
PoStorageService.prototype.getDriverOrder = function (driverOrder) {
|
|
1165
|
-
return driverOrder.map(function (driver) {
|
|
1166
|
-
switch (driver) {
|
|
1167
|
-
case 'indexeddb':
|
|
1168
|
-
return LocalForage__namespace.INDEXEDDB;
|
|
1169
|
-
case 'websql':
|
|
1170
|
-
return LocalForage__namespace.WEBSQL;
|
|
1171
|
-
case 'localstorage':
|
|
1172
|
-
return LocalForage__namespace.LOCALSTORAGE;
|
|
1173
|
-
default:
|
|
1174
|
-
return driver;
|
|
1175
|
-
}
|
|
1176
|
-
});
|
|
1177
|
-
};
|
|
1178
|
-
PoStorageService.prototype.getObjectOfStorage = function (key) {
|
|
1179
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1180
|
-
var data;
|
|
1181
|
-
return __generator(this, function (_b) {
|
|
1182
|
-
switch (_b.label) {
|
|
1183
|
-
case 0: return [4 /*yield*/, this.get(key)];
|
|
1184
|
-
case 1:
|
|
1185
|
-
data = _b.sent();
|
|
1186
|
-
return [2 /*return*/, data || {}];
|
|
1187
|
-
}
|
|
1188
|
-
});
|
|
1189
|
-
});
|
|
1190
|
-
};
|
|
1191
|
-
PoStorageService.prototype.setDriver = function (localForageInstance, driverOrder) {
|
|
1192
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1193
|
-
return __generator(this, function (_b) {
|
|
1194
|
-
switch (_b.label) {
|
|
1195
|
-
case 0: return [4 /*yield*/, localForageInstance.setDriver(this.getDriverOrder(driverOrder))];
|
|
1196
|
-
case 1:
|
|
1197
|
-
_b.sent();
|
|
1198
|
-
this.driver = localForageInstance.driver();
|
|
1199
|
-
return [2 /*return*/];
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
});
|
|
1203
|
-
};
|
|
1204
|
-
PoStorageService.prototype.setStoragePromise = function (config) {
|
|
1205
|
-
this.storagePromise = this.getStorageInstance(config);
|
|
1206
|
-
};
|
|
1207
|
-
PoStorageService.prototype.getStorageInstance = function (config) {
|
|
1208
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1209
|
-
var defaultConfig, actualConfig, localForageInstance, _a_1;
|
|
1210
|
-
return __generator(this, function (_b) {
|
|
1211
|
-
switch (_b.label) {
|
|
1212
|
-
case 0:
|
|
1213
|
-
defaultConfig = PoStorageService.getDefaultConfig();
|
|
1214
|
-
actualConfig = Object.assign(defaultConfig, config || {});
|
|
1215
|
-
localForageInstance = LocalForage__namespace.createInstance(actualConfig);
|
|
1216
|
-
_b.label = 1;
|
|
1217
|
-
case 1:
|
|
1218
|
-
_b.trys.push([1, 3, , 4]);
|
|
1219
|
-
return [4 /*yield*/, this.defineLocalForageDriver(localForageInstance, actualConfig.driverOrder)];
|
|
1220
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
1221
|
-
case 3:
|
|
1222
|
-
_a_1 = _b.sent();
|
|
1223
|
-
throw new Error("Cannot use this drivers: " + actualConfig.driverOrder.join(', ') + ".");
|
|
1224
|
-
case 4: return [2 /*return*/];
|
|
1225
|
-
}
|
|
1226
|
-
});
|
|
1227
|
-
});
|
|
1228
|
-
};
|
|
1229
|
-
return PoStorageService;
|
|
1230
|
-
}());
|
|
1231
|
-
PoStorageService.decorators = [
|
|
1232
|
-
{ type: core.Injectable }
|
|
1233
|
-
];
|
|
1234
|
-
PoStorageService.ctorParameters = function () { return [
|
|
1235
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [PO_STORAGE_CONFIG_TOKEN,] }] }
|
|
582
|
+
var PO_STORAGE_CONFIG_TOKEN = new core.InjectionToken('PO_STORAGE_CONFIG_TOKEN');
|
|
583
|
+
/**
|
|
584
|
+
* @description
|
|
585
|
+
*
|
|
586
|
+
* O PO Storage é uma biblioteca que fornece um serviço para armazenamento de dados no dispositivo local, sendo semelhante
|
|
587
|
+
* ao funcionamento do [IonicStorage](https://ionicframework.com/docs/storage/).
|
|
588
|
+
* É possível utilizar os drivers [Websql](https://dev.w3.org/html5/webdatabase/), [Indexeddb](https://www.w3.org/TR/IndexedDB/),
|
|
589
|
+
* [LocalStorage](https://html.spec.whatwg.org/multipage/webstorage.html) e também [LokiJS](https://github.com/techfort/LokiJS/wiki).
|
|
590
|
+
*
|
|
591
|
+
* Para um melhor ganho de performance ao buscar e salvar dados, recomendamos a utilização do `LokiJS`, um *database*
|
|
592
|
+
* orientado a documento semelhante ao MongoDB, que além de permitir a persistência dos dados no dispositivo possibilita
|
|
593
|
+
* também o armazenamento dos dados em memória. Outra vantagem, é o aumento do limite de armazenamento para
|
|
594
|
+
* aproximadamente `300mb`.
|
|
595
|
+
*
|
|
596
|
+
* A estrutura utilizada para armazenar os dados é a de chave/valor, onde uma chave funciona como um identificador exclusivo.
|
|
597
|
+
*
|
|
598
|
+
* #### Instalando o PO Storage
|
|
599
|
+
*
|
|
600
|
+
* Para instalar o `po-storage` em sua aplicação execute o seguinte comando:
|
|
601
|
+
*
|
|
602
|
+
* ```shell
|
|
603
|
+
* ng add @po-ui/ng-storage
|
|
604
|
+
* ```
|
|
605
|
+
* Será instalado o pacote `@po-ui/ng-storage` e também já importará `PoStorageModule` no módulo principal da sua aplicação, conforme abaixo:
|
|
606
|
+
*
|
|
607
|
+
* ```typescript
|
|
608
|
+
* import { PoStorageModule } from '@po-ui/ng-storage';
|
|
609
|
+
*
|
|
610
|
+
* @NgModule({
|
|
611
|
+
* declarations: [...],
|
|
612
|
+
* imports: [
|
|
613
|
+
* // Importação do módulo PoStorageModule
|
|
614
|
+
* PoStorageModule.forRoot(),
|
|
615
|
+
* ],
|
|
616
|
+
* bootstrap: [IonicApp],
|
|
617
|
+
* providers: [...]
|
|
618
|
+
* })
|
|
619
|
+
* export class AppModule {}
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* Com a declaração do módulo, é criada uma base de dados no armazenamento local e o serviço `PoStorageService` estará
|
|
623
|
+
* pronto para ser utilizada na sua aplicação.
|
|
624
|
+
*
|
|
625
|
+
* #### Configurando as opções de armazenamento
|
|
626
|
+
*
|
|
627
|
+
* Na importação do módulo, o método `PoStorageModule.forRoot()` pode receber como parâmetro um objeto do tipo
|
|
628
|
+
* [`PoStorageConfig`](documentation/po-storage#po-storage-config),
|
|
629
|
+
* que serve para configurar as opções personalizadas do armazenamento, como por exemplo: o tipo de armazenamento
|
|
630
|
+
* preferêncial.
|
|
631
|
+
*
|
|
632
|
+
* Caso não seja passada nenhuma configuração a ordem padrão será: ['websql', 'indexeddb', 'localstorage', 'lokijs'].
|
|
633
|
+
*
|
|
634
|
+
* Abaixo segue um exemplo de configuração onde o storage preferencial passa a ser o `lokijs`:
|
|
635
|
+
*
|
|
636
|
+
* ```typescript
|
|
637
|
+
* import { PoStorageModule } from '@po-ui/ng-storage';
|
|
638
|
+
*
|
|
639
|
+
* @NgModule({
|
|
640
|
+
* declarations: [...],
|
|
641
|
+
* imports: [
|
|
642
|
+
* // Importação do módulo PoStorageModule com a configuração personalizada
|
|
643
|
+
* PoStorageModule.forRoot({
|
|
644
|
+
* name: 'mystorage',
|
|
645
|
+
* storeName: '_mystore',
|
|
646
|
+
* driverOrder: ['lokijs', 'websql', 'indexeddb', 'localstorage']
|
|
647
|
+
* }),
|
|
648
|
+
* ],
|
|
649
|
+
* bootstrap: [IonicApp],
|
|
650
|
+
* providers: [...]
|
|
651
|
+
* })
|
|
652
|
+
* export class AppModule {}
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
var PoStorageService = /** @class */ (function () {
|
|
656
|
+
function PoStorageService(config) {
|
|
657
|
+
this.driver = null;
|
|
658
|
+
this.idleQueue = new IdleQueue__default['default']();
|
|
659
|
+
this.lokijsDriver = new PoLokiDriver();
|
|
660
|
+
this.setStoragePromise(config);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Retorna a configuração padrão para o armazenamento. Caso nenhuma configuração seja inserida,
|
|
664
|
+
* essa configuração será utilizada.
|
|
665
|
+
*
|
|
666
|
+
* @returns {PoStorageConfig} Objeto com a configuração padrão do armazenamento.
|
|
667
|
+
*/
|
|
668
|
+
PoStorageService.getDefaultConfig = function () {
|
|
669
|
+
return {
|
|
670
|
+
name: '_postorage',
|
|
671
|
+
storeName: '_pokv',
|
|
672
|
+
driverOrder: ['websql', 'indexeddb', 'localstorage', 'lokijs']
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Cria uma instância do `PoStorageService` com a configuração de armazenamento passada como parâmetro.
|
|
677
|
+
*
|
|
678
|
+
* @param {PoStorageConfig} storageConfig Configuração para o armazenamento.
|
|
679
|
+
* @returns {PoStorageService} Instância do `PoStorageService`.
|
|
680
|
+
*/
|
|
681
|
+
PoStorageService.providePoStorage = function (storageConfig) {
|
|
682
|
+
return new PoStorageService(PoStorageService.getConfig(storageConfig));
|
|
683
|
+
};
|
|
684
|
+
PoStorageService.getConfig = function (storageConfig) {
|
|
685
|
+
return storageConfig || PoStorageService.getDefaultConfig();
|
|
686
|
+
};
|
|
687
|
+
/**
|
|
688
|
+
* Busca uma lista armazenada pela chave e concatena com a lista passada por parâmetro.
|
|
689
|
+
*
|
|
690
|
+
* Por exemplo:
|
|
691
|
+
*
|
|
692
|
+
* ``` typescript
|
|
693
|
+
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
694
|
+
*
|
|
695
|
+
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
696
|
+
*
|
|
697
|
+
* ...
|
|
698
|
+
*
|
|
699
|
+
* const newClients = [ { name: 'Lisa', age: 36 }, { name: 'Bruce', age: 18 } ];
|
|
700
|
+
*
|
|
701
|
+
* this.poStorageService.appendArrayToArray('clientKey', newClients).then(() => {
|
|
702
|
+
* // A lista agora será:
|
|
703
|
+
* // [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }, { name: 'Lisa', age: 36 }, { name: 'Bruce', age: 18 }];
|
|
704
|
+
* });
|
|
705
|
+
* ```
|
|
706
|
+
*
|
|
707
|
+
* @param {string} key Chave da lista armazenada.
|
|
708
|
+
* @param {Array} value Lista que será concatenada.
|
|
709
|
+
*
|
|
710
|
+
* @returns {Promise<any>} Promessa que é resolvida após as duas listas serem concatenadas e armazenadas localmente.
|
|
711
|
+
*/
|
|
712
|
+
PoStorageService.prototype.appendArrayToArray = function (key, value) {
|
|
713
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
714
|
+
var data, newData;
|
|
715
|
+
return __generator(this, function (_b) {
|
|
716
|
+
switch (_b.label) {
|
|
717
|
+
case 0: return [4 /*yield*/, this.getArrayOfStorage(key)];
|
|
718
|
+
case 1:
|
|
719
|
+
data = _b.sent();
|
|
720
|
+
newData = __spreadArray(__spreadArray([], __read(data)), __read(value));
|
|
721
|
+
return [2 /*return*/, this.set(key, newData)];
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
/**
|
|
727
|
+
* Acrescenta um item em uma lista armazenada pela chave.
|
|
728
|
+
*
|
|
729
|
+
* @param {string} key Chave da lista armazenada.
|
|
730
|
+
* @param {Array} value Item que será acrescentado na lista.
|
|
731
|
+
*
|
|
732
|
+
* @returns {Promise<any>} Promessa que é resolvida após o item ser acrescentado na lista armazenada.
|
|
733
|
+
*/
|
|
734
|
+
PoStorageService.prototype.appendItemToArray = function (key, value) {
|
|
735
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
736
|
+
var data;
|
|
737
|
+
return __generator(this, function (_b) {
|
|
738
|
+
switch (_b.label) {
|
|
739
|
+
case 0: return [4 /*yield*/, this.getArrayOfStorage(key)];
|
|
740
|
+
case 1:
|
|
741
|
+
data = _b.sent();
|
|
742
|
+
data.push(value);
|
|
743
|
+
return [2 /*return*/, this.set(key, data)];
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Remove todos os itens da base de dados local configurada na declaração do módulo `PoStorageModule`.
|
|
750
|
+
*
|
|
751
|
+
* > Utilize este método com cautela, para evitar a perda indesejada de dados.
|
|
752
|
+
*
|
|
753
|
+
* @returns {Promise<void>} Promessa que é resolvida após todos os itens da base de dados local serem removidos.
|
|
754
|
+
*/
|
|
755
|
+
PoStorageService.prototype.clear = function () {
|
|
756
|
+
return this.storagePromise.then(function (store) { return store.clear(); });
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* Verifica se existe um valor dentro de uma determinada chave.
|
|
760
|
+
*
|
|
761
|
+
* @param {string} key Chave que será verificada.
|
|
762
|
+
*
|
|
763
|
+
* @returns {Promise<boolean>} Promessa que é resolvida quando a verificação da existência do valor na chave é concluída.
|
|
764
|
+
*/
|
|
765
|
+
PoStorageService.prototype.exists = function (key) {
|
|
766
|
+
return this.get(key).then(function (data) { return Promise.resolve(data !== null); });
|
|
767
|
+
};
|
|
768
|
+
/**
|
|
769
|
+
* Itera sobre todas as chaves armazenadas.
|
|
770
|
+
*
|
|
771
|
+
* @param {any} iteratorCallback Função de `callback` que é chamada a cada iteração, com os seguintes parâmetros:
|
|
772
|
+
* valor, chave e número da iteração.
|
|
773
|
+
*
|
|
774
|
+
* Exemplo de utilização:
|
|
775
|
+
*
|
|
776
|
+
* ``` typescript
|
|
777
|
+
* this.poStorageService.forEach((value: any, key: string, iterationNumber: number) => {
|
|
778
|
+
* // Iteração sobre cada chave armazenada.
|
|
779
|
+
* });
|
|
780
|
+
* ```
|
|
781
|
+
*
|
|
782
|
+
* @returns {Promise<void>} Promessa que é resolvida após a iteração sobre todas as chaves armazenadas.
|
|
783
|
+
*/
|
|
784
|
+
PoStorageService.prototype.forEach = function (iteratorCallback) {
|
|
785
|
+
return this.storagePromise.then(function (store) { return store.iterate(iteratorCallback); });
|
|
786
|
+
};
|
|
787
|
+
/**
|
|
788
|
+
* Retorna o valor armazenado em uma determinada chave.
|
|
789
|
+
*
|
|
790
|
+
* @param {string} key Chave que identifica o item.
|
|
791
|
+
* @param {boolean} lock Define se irá travar a leitura e a escrita da base de dados para não ser acessada de forma paralela.
|
|
792
|
+
* Caso outra leitura/escrita já tenha sido iniciada, este método irá esperar o outro terminar para então começar.
|
|
793
|
+
*
|
|
794
|
+
* Padrão: `false`.
|
|
795
|
+
*
|
|
796
|
+
* > Esta definição só será válida se o outro acesso paralelo a este método também estiver com o parâmetro *lock* ativado.
|
|
797
|
+
* @returns {Promise<any>} Promessa que é resolvida após o item ser buscado.
|
|
798
|
+
*/
|
|
799
|
+
PoStorageService.prototype.get = function (key, lock) {
|
|
800
|
+
if (lock === void 0) { lock = false; }
|
|
801
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
802
|
+
var _this = this;
|
|
803
|
+
return __generator(this, function (_b) {
|
|
804
|
+
switch (_b.label) {
|
|
805
|
+
case 0:
|
|
806
|
+
if (!lock) return [3 /*break*/, 3];
|
|
807
|
+
return [4 /*yield*/, this.requestIdlePromise()];
|
|
808
|
+
case 1:
|
|
809
|
+
_b.sent();
|
|
810
|
+
return [4 /*yield*/, this.idleQueue.wrapCall(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
811
|
+
return __generator(this, function (_b) {
|
|
812
|
+
switch (_b.label) {
|
|
813
|
+
case 0: return [4 /*yield*/, this.getImmutableItem(key)];
|
|
814
|
+
case 1:
|
|
815
|
+
_b.sent();
|
|
816
|
+
return [2 /*return*/];
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
}); })];
|
|
820
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
821
|
+
case 3: return [4 /*yield*/, this.getImmutableItem(key)];
|
|
822
|
+
case 4: return [2 /*return*/, _b.sent()];
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
/**
|
|
828
|
+
* Retorna o nome do *driver* que está sendo usado para armazenar os dados, por exemplo: localStorage.
|
|
829
|
+
*
|
|
830
|
+
* @returns {string | null} Nome do *driver*.
|
|
831
|
+
*/
|
|
832
|
+
PoStorageService.prototype.getDriver = function () {
|
|
833
|
+
return this.driver;
|
|
834
|
+
};
|
|
835
|
+
/**
|
|
836
|
+
* Retorna o primeiro item de uma lista para uma determinada chave.
|
|
837
|
+
*
|
|
838
|
+
* @param {string} key Chave da lista.
|
|
839
|
+
* @returns {Promise<any>} Promessa que é resolvida após o primeiro item ser encontrado.
|
|
840
|
+
*/
|
|
841
|
+
PoStorageService.prototype.getFirstItem = function (key) {
|
|
842
|
+
return this.get(key).then(function (data) { return Promise.resolve(data ? data[0] : null); });
|
|
843
|
+
};
|
|
844
|
+
/**
|
|
845
|
+
* Remove o primeiro item de uma lista a partir da chave.
|
|
846
|
+
*
|
|
847
|
+
* @param {string} key Chave da lista que será removido o primeiro item.
|
|
848
|
+
* @returns {Promise<any>} Promessa que é resolvida após o primeiro item da lista ser removido.
|
|
849
|
+
*/
|
|
850
|
+
PoStorageService.prototype.getItemAndRemove = function (key) {
|
|
851
|
+
var _this = this;
|
|
852
|
+
return this.get(key).then(function (data) {
|
|
853
|
+
if (data === null) {
|
|
854
|
+
return null;
|
|
855
|
+
}
|
|
856
|
+
var item = data.shift();
|
|
857
|
+
return _this.set(key, data).then(function () { return Promise.resolve(item); });
|
|
858
|
+
});
|
|
859
|
+
};
|
|
860
|
+
/**
|
|
861
|
+
* Busca o primeiro objeto encontrado dentro de uma lista pelo do valor de um campo.
|
|
862
|
+
*
|
|
863
|
+
* Por exemplo:
|
|
864
|
+
*
|
|
865
|
+
* ``` typescript
|
|
866
|
+
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
867
|
+
*
|
|
868
|
+
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
869
|
+
*
|
|
870
|
+
* ...
|
|
871
|
+
*
|
|
872
|
+
* this.poStorageService.getItemByField('clientKey', 'name', 'Marie').then(client => {
|
|
873
|
+
* // Resultado do console.log: { name: 'Marie', age: 23 }
|
|
874
|
+
* console.log(client);
|
|
875
|
+
* });
|
|
876
|
+
* ```
|
|
877
|
+
*
|
|
878
|
+
* @param {string} key Chave da lista.
|
|
879
|
+
* @param {string} fieldName O campo a ser filtrado.
|
|
880
|
+
* @param {any} fieldValue O valor do campo.
|
|
881
|
+
* @returns {Promise<any>} Promessa que é resolvida com o item que foi encontrado.
|
|
882
|
+
*/
|
|
883
|
+
PoStorageService.prototype.getItemByField = function (key, fieldName, fieldValue) {
|
|
884
|
+
return this.get(key).then(function (storageRecords) {
|
|
885
|
+
var storageRecordsFiltered = storageRecords.find(function (storageRecord) { return storageRecord[fieldName] === fieldValue; });
|
|
886
|
+
storageRecordsFiltered = storageRecordsFiltered || null;
|
|
887
|
+
return Promise.resolve(storageRecordsFiltered);
|
|
888
|
+
});
|
|
889
|
+
};
|
|
890
|
+
/**
|
|
891
|
+
* Lista com todas as chaves armazenadas.
|
|
892
|
+
*
|
|
893
|
+
* @returns {Promise<Array<string>>} Promessa que é resolvida com todas as chaves armazenadas.
|
|
894
|
+
*/
|
|
895
|
+
PoStorageService.prototype.keys = function () {
|
|
896
|
+
return this.storagePromise.then(function (store) { return store.keys(); });
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* Quantidade de chaves armazenadas.
|
|
900
|
+
*
|
|
901
|
+
* @returns {Promise<number>} Promessa que é resolvida com o número de chaves armazenadas.
|
|
902
|
+
*/
|
|
903
|
+
PoStorageService.prototype.length = function () {
|
|
904
|
+
return this.storagePromise.then(function (store) { return store.length(); });
|
|
905
|
+
};
|
|
906
|
+
/**
|
|
907
|
+
* Utilizado para gerenciar o bloqueio e desbloqueio de recursos no `PoStorageService`.
|
|
908
|
+
* Aguardando a liberação da utilização dos recursos que participam deste comportamento e posteriormente envolve o recurso
|
|
909
|
+
* passado como parâmetro em um comportamento de bloqueio e desbloqueio.
|
|
910
|
+
*
|
|
911
|
+
* Este método se comporta igual a utilização em conjunta dos métodos: `PoStorageService.requestIdlePromise()`,
|
|
912
|
+
* `PoStorageService.lock()` e `PoStorageService.unlook()`.
|
|
913
|
+
*
|
|
914
|
+
* Veja mais no método: [`PoStorage.requestIdlePromise()`](documentation/po-storage#request-idle-promise).
|
|
915
|
+
*
|
|
916
|
+
* @param {Function} limitedResource Função que será envolvida no comportamento de bloqueio e desbloqueio.
|
|
917
|
+
*/
|
|
918
|
+
PoStorageService.prototype.limitedCallWrap = function (limitedResource) {
|
|
919
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
920
|
+
return __generator(this, function (_b) {
|
|
921
|
+
switch (_b.label) {
|
|
922
|
+
case 0: return [4 /*yield*/, this.requestIdlePromise()];
|
|
923
|
+
case 1:
|
|
924
|
+
_b.sent();
|
|
925
|
+
return [2 /*return*/, this.idleQueue.wrapCall(limitedResource)];
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* Incrementa um valor na fila de bloqueio do `PoStorageService`. Utilizado juntamente com o método `unlock` para poder
|
|
932
|
+
* controlar a execução de uma determinada tarefa com o `PoStorage.requestIdlePromise()`.
|
|
933
|
+
*
|
|
934
|
+
* Veja mais no método: [`PoStorage.requestIdlePromise()`](documentation/po-storage#request-idle-promise).
|
|
935
|
+
*/
|
|
936
|
+
PoStorageService.prototype.lock = function () {
|
|
937
|
+
this.idleQueue.lock();
|
|
938
|
+
};
|
|
939
|
+
/**
|
|
940
|
+
* Determina se o processo de inicialização do *driver* assíncrono foi concluído.
|
|
941
|
+
*
|
|
942
|
+
* @returns {Promise<LocalForage>} Promessa que é resolvida quando o processo de inicialização do *driver* assíncrono
|
|
943
|
+
* for concluído.
|
|
944
|
+
*/
|
|
945
|
+
PoStorageService.prototype.ready = function () {
|
|
946
|
+
return this.storagePromise;
|
|
947
|
+
};
|
|
948
|
+
/**
|
|
949
|
+
* Remove um valor associado a uma chave.
|
|
950
|
+
*
|
|
951
|
+
* @param {key} key Chave do valor que será removido.
|
|
952
|
+
* @returns {Promise<any>} Promessa que é resolvida após o valor ser removido.
|
|
953
|
+
*/
|
|
954
|
+
PoStorageService.prototype.remove = function (key) {
|
|
955
|
+
return this.storagePromise.then(function (store) { return store.removeItem(key); });
|
|
956
|
+
};
|
|
957
|
+
/**
|
|
958
|
+
* Remove uma propriedade de um objeto armazenado.
|
|
959
|
+
*
|
|
960
|
+
* @param {string} key Chave do objeto armazenado.
|
|
961
|
+
* @param {string} property Propriedade que será removida.
|
|
962
|
+
*
|
|
963
|
+
* @returns {Promise<any>} Promessa que é resolvida após a propriedade ser removida.
|
|
964
|
+
*/
|
|
965
|
+
PoStorageService.prototype.removeIndexFromObject = function (key, property) {
|
|
966
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
967
|
+
var data;
|
|
968
|
+
return __generator(this, function (_b) {
|
|
969
|
+
switch (_b.label) {
|
|
970
|
+
case 0: return [4 /*yield*/, this.getObjectOfStorage(key)];
|
|
971
|
+
case 1:
|
|
972
|
+
data = _b.sent();
|
|
973
|
+
delete data[property];
|
|
974
|
+
return [2 /*return*/, this.set(key, data)];
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Remove um objeto de uma lista armazenada pelo valor de uma propriedade.
|
|
981
|
+
*
|
|
982
|
+
* Por exemplo:
|
|
983
|
+
*
|
|
984
|
+
* ``` typescript
|
|
985
|
+
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
986
|
+
*
|
|
987
|
+
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
988
|
+
*
|
|
989
|
+
* ...
|
|
990
|
+
*
|
|
991
|
+
* this.poStorageService.removeItemFromArray('clientKey', 'name', 'Marie').then(() => {
|
|
992
|
+
* // O objeto { name: 'Marie', age: 23 } foi removido da lista que está na chave 'clientKey'
|
|
993
|
+
* });
|
|
994
|
+
* ```
|
|
995
|
+
*
|
|
996
|
+
* @param {string} key Chave da lista que contém o item que será removido.
|
|
997
|
+
* @param {string} field O campo a ser filtrado no item.
|
|
998
|
+
* @param {string} value O valor do filtro.
|
|
999
|
+
* @returns {Promise<any>} Promessa que é resolvida quando o objeto for removido da lista.
|
|
1000
|
+
*/
|
|
1001
|
+
PoStorageService.prototype.removeItemFromArray = function (key, field, value) {
|
|
1002
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1003
|
+
var data;
|
|
1004
|
+
return __generator(this, function (_b) {
|
|
1005
|
+
switch (_b.label) {
|
|
1006
|
+
case 0: return [4 /*yield*/, this.getArrayOfStorage(key)];
|
|
1007
|
+
case 1:
|
|
1008
|
+
data = _b.sent();
|
|
1009
|
+
data = data.filter(function (item) { return item[field] !== value; });
|
|
1010
|
+
return [2 /*return*/, this.set(key, data)];
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
};
|
|
1015
|
+
/**
|
|
1016
|
+
* <a id="request-idle-promise"></a>
|
|
1017
|
+
* Método que verifica se o acesso a base de dados configurada está liberado.
|
|
1018
|
+
*
|
|
1019
|
+
* Utilizado em conjunto com os métodos `lock()` e `unlock()` entre tarefas que não podem ser executadas de forma
|
|
1020
|
+
* paralela, para não causar inconsistências nos dados.
|
|
1021
|
+
*
|
|
1022
|
+
* Exemplo de utilização:
|
|
1023
|
+
*
|
|
1024
|
+
* ```
|
|
1025
|
+
* // Aguarda a liberação para continuar
|
|
1026
|
+
* await this.poStorage.requestIdlePromise();
|
|
1027
|
+
*
|
|
1028
|
+
* this.poStorage.lock();
|
|
1029
|
+
*
|
|
1030
|
+
* // Executa uma tarefa que irá ler e/ou escrever na base de dados configurada.
|
|
1031
|
+
*
|
|
1032
|
+
* this.poStorage.unlock();
|
|
1033
|
+
* ```
|
|
1034
|
+
*
|
|
1035
|
+
* > É importante sempre utilizá-lo antes de executar os métodos `lock()` e `unlock()` para garantir que a tarefa só
|
|
1036
|
+
* será executada caso o acesso esteja livre.
|
|
1037
|
+
*
|
|
1038
|
+
* @returns {Promise<any>} Promessa que é resolvida quando o acesso a base de dados configurada estiver liberado.
|
|
1039
|
+
*/
|
|
1040
|
+
PoStorageService.prototype.requestIdlePromise = function () {
|
|
1041
|
+
return this.idleQueue.requestIdlePromise();
|
|
1042
|
+
};
|
|
1043
|
+
/**
|
|
1044
|
+
* Grava um valor em uma determinada chave.
|
|
1045
|
+
*
|
|
1046
|
+
* @param {string} key Chave para o valor que será gravado.
|
|
1047
|
+
* @param {any} value Valor que será gravado.
|
|
1048
|
+
* @param {boolean} lock Define se irá travar a leitura e a escrita da base de dados para não ser acessada de forma paralela.
|
|
1049
|
+
* Caso outra leitura/escrita já tenha sido iniciada, este método irá esperar o outro terminar para então começar.
|
|
1050
|
+
*
|
|
1051
|
+
* Padrão: `false`.
|
|
1052
|
+
*
|
|
1053
|
+
* > Esta definição só será válida se o outro acesso paralelo a este método também estiver com o parâmetro *lock* ativado.
|
|
1054
|
+
* @returns {Promise<any>} Promessa que é resolvida após o valor ter sido gravado.
|
|
1055
|
+
*/
|
|
1056
|
+
PoStorageService.prototype.set = function (key, value, lock) {
|
|
1057
|
+
if (lock === void 0) { lock = false; }
|
|
1058
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1059
|
+
var store, newValue;
|
|
1060
|
+
return __generator(this, function (_b) {
|
|
1061
|
+
switch (_b.label) {
|
|
1062
|
+
case 0: return [4 /*yield*/, this.storagePromise];
|
|
1063
|
+
case 1:
|
|
1064
|
+
store = _b.sent();
|
|
1065
|
+
newValue = typeof value === 'object' ? JSON.parse(JSON.stringify(value)) : value;
|
|
1066
|
+
if (!lock) return [3 /*break*/, 3];
|
|
1067
|
+
return [4 /*yield*/, this.requestIdlePromise()];
|
|
1068
|
+
case 2:
|
|
1069
|
+
_b.sent();
|
|
1070
|
+
return [2 /*return*/, this.idleQueue.wrapCall(function () { return store.setItem(key, newValue); })];
|
|
1071
|
+
case 3: return [2 /*return*/, store.setItem(key, newValue)];
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
});
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* Atribui um valor a uma propriedade de um objeto armazenado pela chave.
|
|
1078
|
+
*
|
|
1079
|
+
* Por exemplo:
|
|
1080
|
+
*
|
|
1081
|
+
* ``` typescript
|
|
1082
|
+
* const clients = [ { name: 'Marie', age: 23 }, { name: 'Pether', age: 39 }];
|
|
1083
|
+
*
|
|
1084
|
+
* this.poStorageService.set('clientKey', clients).then(() => {});
|
|
1085
|
+
*
|
|
1086
|
+
* ...
|
|
1087
|
+
*
|
|
1088
|
+
* this.poStorageService.setIndexToObject('clientKey', 'name', 'Clare').then(() => {
|
|
1089
|
+
* // O objeto { name: 'Marie', age: 23 } passa a ser { name: 'Clare', age: 23 }
|
|
1090
|
+
* });
|
|
1091
|
+
* ```
|
|
1092
|
+
*
|
|
1093
|
+
* @param {string} key Chave do objeto.
|
|
1094
|
+
* @param {string} property Nome da propriedade do objeto.
|
|
1095
|
+
* @param {any} value Valor que será gravado na propriedade do objeto.
|
|
1096
|
+
*/
|
|
1097
|
+
PoStorageService.prototype.setIndexToObject = function (key, property, value) {
|
|
1098
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1099
|
+
var data;
|
|
1100
|
+
return __generator(this, function (_b) {
|
|
1101
|
+
switch (_b.label) {
|
|
1102
|
+
case 0: return [4 /*yield*/, this.getObjectOfStorage(key)];
|
|
1103
|
+
case 1:
|
|
1104
|
+
data = _b.sent();
|
|
1105
|
+
data[property] = value;
|
|
1106
|
+
return [2 /*return*/, this.set(key, data)];
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
/**
|
|
1112
|
+
* Decrementa um valor na fila de bloqueio. Utilizado juntamente com o método `lock` para poder
|
|
1113
|
+
* controlar a execução de uma determinada tarefa com o `PoStorage.requestIdlePromise()`.
|
|
1114
|
+
*
|
|
1115
|
+
* Veja mais no método: [`PoStorage.requestIdlePromise()`](documentation/po-storage#request-idle-promise).
|
|
1116
|
+
*/
|
|
1117
|
+
PoStorageService.prototype.unlock = function () {
|
|
1118
|
+
this.idleQueue.unlock();
|
|
1119
|
+
};
|
|
1120
|
+
PoStorageService.prototype.getArrayOfStorage = function (key) {
|
|
1121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1122
|
+
var data;
|
|
1123
|
+
return __generator(this, function (_b) {
|
|
1124
|
+
switch (_b.label) {
|
|
1125
|
+
case 0: return [4 /*yield*/, this.get(key)];
|
|
1126
|
+
case 1:
|
|
1127
|
+
data = _b.sent();
|
|
1128
|
+
return [2 /*return*/, data || []];
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
});
|
|
1132
|
+
};
|
|
1133
|
+
PoStorageService.prototype.getImmutableItem = function (key) {
|
|
1134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1135
|
+
var store, items;
|
|
1136
|
+
return __generator(this, function (_b) {
|
|
1137
|
+
switch (_b.label) {
|
|
1138
|
+
case 0: return [4 /*yield*/, this.storagePromise];
|
|
1139
|
+
case 1:
|
|
1140
|
+
store = _b.sent();
|
|
1141
|
+
return [4 /*yield*/, store.getItem(key)];
|
|
1142
|
+
case 2:
|
|
1143
|
+
items = _b.sent();
|
|
1144
|
+
return [2 /*return*/, items ? JSON.parse(JSON.stringify(items)) : null];
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
};
|
|
1149
|
+
PoStorageService.prototype.defineLocalForageDriver = function (localForageInstance, driverOrder) {
|
|
1150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1151
|
+
return __generator(this, function (_b) {
|
|
1152
|
+
switch (_b.label) {
|
|
1153
|
+
case 0: return [4 /*yield*/, localForageInstance.defineDriver(this.lokijsDriver.getDriver())];
|
|
1154
|
+
case 1:
|
|
1155
|
+
_b.sent();
|
|
1156
|
+
return [4 /*yield*/, this.setDriver(localForageInstance, driverOrder)];
|
|
1157
|
+
case 2:
|
|
1158
|
+
_b.sent();
|
|
1159
|
+
return [2 /*return*/, localForageInstance];
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
};
|
|
1164
|
+
PoStorageService.prototype.getDriverOrder = function (driverOrder) {
|
|
1165
|
+
return driverOrder.map(function (driver) {
|
|
1166
|
+
switch (driver) {
|
|
1167
|
+
case 'indexeddb':
|
|
1168
|
+
return LocalForage__namespace.INDEXEDDB;
|
|
1169
|
+
case 'websql':
|
|
1170
|
+
return LocalForage__namespace.WEBSQL;
|
|
1171
|
+
case 'localstorage':
|
|
1172
|
+
return LocalForage__namespace.LOCALSTORAGE;
|
|
1173
|
+
default:
|
|
1174
|
+
return driver;
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
};
|
|
1178
|
+
PoStorageService.prototype.getObjectOfStorage = function (key) {
|
|
1179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1180
|
+
var data;
|
|
1181
|
+
return __generator(this, function (_b) {
|
|
1182
|
+
switch (_b.label) {
|
|
1183
|
+
case 0: return [4 /*yield*/, this.get(key)];
|
|
1184
|
+
case 1:
|
|
1185
|
+
data = _b.sent();
|
|
1186
|
+
return [2 /*return*/, data || {}];
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
});
|
|
1190
|
+
};
|
|
1191
|
+
PoStorageService.prototype.setDriver = function (localForageInstance, driverOrder) {
|
|
1192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1193
|
+
return __generator(this, function (_b) {
|
|
1194
|
+
switch (_b.label) {
|
|
1195
|
+
case 0: return [4 /*yield*/, localForageInstance.setDriver(this.getDriverOrder(driverOrder))];
|
|
1196
|
+
case 1:
|
|
1197
|
+
_b.sent();
|
|
1198
|
+
this.driver = localForageInstance.driver();
|
|
1199
|
+
return [2 /*return*/];
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
});
|
|
1203
|
+
};
|
|
1204
|
+
PoStorageService.prototype.setStoragePromise = function (config) {
|
|
1205
|
+
this.storagePromise = this.getStorageInstance(config);
|
|
1206
|
+
};
|
|
1207
|
+
PoStorageService.prototype.getStorageInstance = function (config) {
|
|
1208
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1209
|
+
var defaultConfig, actualConfig, localForageInstance, _a_1;
|
|
1210
|
+
return __generator(this, function (_b) {
|
|
1211
|
+
switch (_b.label) {
|
|
1212
|
+
case 0:
|
|
1213
|
+
defaultConfig = PoStorageService.getDefaultConfig();
|
|
1214
|
+
actualConfig = Object.assign(defaultConfig, config || {});
|
|
1215
|
+
localForageInstance = LocalForage__namespace.createInstance(actualConfig);
|
|
1216
|
+
_b.label = 1;
|
|
1217
|
+
case 1:
|
|
1218
|
+
_b.trys.push([1, 3, , 4]);
|
|
1219
|
+
return [4 /*yield*/, this.defineLocalForageDriver(localForageInstance, actualConfig.driverOrder)];
|
|
1220
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
1221
|
+
case 3:
|
|
1222
|
+
_a_1 = _b.sent();
|
|
1223
|
+
throw new Error("Cannot use this drivers: " + actualConfig.driverOrder.join(', ') + ".");
|
|
1224
|
+
case 4: return [2 /*return*/];
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
});
|
|
1228
|
+
};
|
|
1229
|
+
return PoStorageService;
|
|
1230
|
+
}());
|
|
1231
|
+
PoStorageService.decorators = [
|
|
1232
|
+
{ type: core.Injectable }
|
|
1233
|
+
];
|
|
1234
|
+
PoStorageService.ctorParameters = function () { return [
|
|
1235
|
+
{ type: undefined, decorators: [{ type: core.Inject, args: [PO_STORAGE_CONFIG_TOKEN,] }] }
|
|
1236
1236
|
]; };
|
|
1237
1237
|
|
|
1238
|
-
/**
|
|
1239
|
-
* @description
|
|
1240
|
-
*
|
|
1241
|
-
* Módulo do componente PoStorage responsável por manipular o storage do browser.
|
|
1242
|
-
*/
|
|
1243
|
-
var PoStorageModule = /** @class */ (function () {
|
|
1244
|
-
function PoStorageModule() {
|
|
1245
|
-
}
|
|
1246
|
-
PoStorageModule.forRoot = function (storageConfig) {
|
|
1247
|
-
return {
|
|
1248
|
-
ngModule: PoStorageModule,
|
|
1249
|
-
providers: [
|
|
1250
|
-
{
|
|
1251
|
-
provide: PO_STORAGE_CONFIG_TOKEN,
|
|
1252
|
-
useValue: storageConfig || PoStorageService.getDefaultConfig()
|
|
1253
|
-
},
|
|
1254
|
-
{
|
|
1255
|
-
provide: PoStorageService,
|
|
1256
|
-
useFactory: PoStorageService.providePoStorage,
|
|
1257
|
-
deps: [PO_STORAGE_CONFIG_TOKEN]
|
|
1258
|
-
}
|
|
1259
|
-
]
|
|
1260
|
-
};
|
|
1261
|
-
};
|
|
1262
|
-
return PoStorageModule;
|
|
1263
|
-
}());
|
|
1264
|
-
PoStorageModule.decorators = [
|
|
1265
|
-
{ type: core.NgModule }
|
|
1238
|
+
/**
|
|
1239
|
+
* @description
|
|
1240
|
+
*
|
|
1241
|
+
* Módulo do componente PoStorage responsável por manipular o storage do browser.
|
|
1242
|
+
*/
|
|
1243
|
+
var PoStorageModule = /** @class */ (function () {
|
|
1244
|
+
function PoStorageModule() {
|
|
1245
|
+
}
|
|
1246
|
+
PoStorageModule.forRoot = function (storageConfig) {
|
|
1247
|
+
return {
|
|
1248
|
+
ngModule: PoStorageModule,
|
|
1249
|
+
providers: [
|
|
1250
|
+
{
|
|
1251
|
+
provide: PO_STORAGE_CONFIG_TOKEN,
|
|
1252
|
+
useValue: storageConfig || PoStorageService.getDefaultConfig()
|
|
1253
|
+
},
|
|
1254
|
+
{
|
|
1255
|
+
provide: PoStorageService,
|
|
1256
|
+
useFactory: PoStorageService.providePoStorage,
|
|
1257
|
+
deps: [PO_STORAGE_CONFIG_TOKEN]
|
|
1258
|
+
}
|
|
1259
|
+
]
|
|
1260
|
+
};
|
|
1261
|
+
};
|
|
1262
|
+
return PoStorageModule;
|
|
1263
|
+
}());
|
|
1264
|
+
PoStorageModule.decorators = [
|
|
1265
|
+
{ type: core.NgModule }
|
|
1266
1266
|
];
|
|
1267
1267
|
|
|
1268
|
-
/**
|
|
1269
|
-
* Generated bundle index. Do not edit.
|
|
1268
|
+
/**
|
|
1269
|
+
* Generated bundle index. Do not edit.
|
|
1270
1270
|
*/
|
|
1271
1271
|
|
|
1272
1272
|
exports.PoStorageModule = PoStorageModule;
|