@sumaris-net/ngx-components 1.4.6 → 1.4.7
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/bundles/sumaris-net.ngx-components.umd.js +52 -43
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/src/app/core/services/storage/entities-storage.service.js +7 -4
- package/esm2015/src/app/core/services/storage/entity-store.class.js +5 -1
- package/esm2015/src/app/shared/functions.js +2 -4
- package/fesm2015/sumaris-net.ngx-components.js +11 -6
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/core/services/storage/entity-store.class.d.ts +1 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -511,9 +511,7 @@
|
|
|
511
511
|
return value.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
|
512
512
|
}
|
|
513
513
|
function removeDiacritics(text) {
|
|
514
|
-
return text.normalize('NFD')
|
|
515
|
-
//
|
|
516
|
-
.replace(/[\u0300-\u036f]/g, '');
|
|
514
|
+
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
517
515
|
}
|
|
518
516
|
function suggestFromArray(items, value, opts) {
|
|
519
517
|
var _this = this;
|
|
@@ -12148,6 +12146,14 @@
|
|
|
12148
12146
|
this._storageKey = ENTITIES_STORAGE_KEY_PREFIX + '#' + name;
|
|
12149
12147
|
this._mapToLightEntity = this.createLightEntityMapFn(this.policy);
|
|
12150
12148
|
}
|
|
12149
|
+
Object.defineProperty(EntityStore.prototype, "length", {
|
|
12150
|
+
get: function () {
|
|
12151
|
+
var _a;
|
|
12152
|
+
return ((_a = this._cache) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
12153
|
+
},
|
|
12154
|
+
enumerable: false,
|
|
12155
|
+
configurable: true
|
|
12156
|
+
});
|
|
12151
12157
|
Object.defineProperty(EntityStore.prototype, "cache", {
|
|
12152
12158
|
get: function () {
|
|
12153
12159
|
return this._cache;
|
|
@@ -12186,12 +12192,12 @@
|
|
|
12186
12192
|
};
|
|
12187
12193
|
EntityStore.prototype.load = function (id, opts) {
|
|
12188
12194
|
return __awaiter(this, void 0, void 0, function () {
|
|
12189
|
-
return __generator(this, function (
|
|
12190
|
-
switch (
|
|
12195
|
+
return __generator(this, function (_b) {
|
|
12196
|
+
switch (_b.label) {
|
|
12191
12197
|
case 0:
|
|
12192
12198
|
if (!(this._mapToLightEntity && (!opts || opts.fullLoad !== false))) return [3 /*break*/, 2];
|
|
12193
12199
|
return [4 /*yield*/, this.loadFullEntity(id, opts)];
|
|
12194
|
-
case 1: return [2 /*return*/,
|
|
12200
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
12195
12201
|
case 2: return [2 /*return*/, this.loadCachedEntity(id, opts)];
|
|
12196
12202
|
}
|
|
12197
12203
|
});
|
|
@@ -12231,20 +12237,20 @@
|
|
|
12231
12237
|
*/
|
|
12232
12238
|
EntityStore.prototype.loadAll = function (variables, opts) {
|
|
12233
12239
|
return __awaiter(this, void 0, void 0, function () {
|
|
12234
|
-
var res,
|
|
12240
|
+
var res, _b;
|
|
12235
12241
|
var _this = this;
|
|
12236
|
-
return __generator(this, function (
|
|
12237
|
-
switch (
|
|
12242
|
+
return __generator(this, function (_c) {
|
|
12243
|
+
switch (_c.label) {
|
|
12238
12244
|
case 0:
|
|
12239
12245
|
res = this.reduceAndSort(this._cache, variables);
|
|
12240
12246
|
if (!(this._mapToLightEntity && isNotEmptyArray(res.data) && (opts && opts.fullLoad === true))) return [3 /*break*/, 2];
|
|
12241
12247
|
// Load full entities, one by one
|
|
12242
|
-
|
|
12248
|
+
_b = res;
|
|
12243
12249
|
return [4 /*yield*/, chainPromises((res.data || []).map(function (e) { return function () { return _this.load(e.id); }; }))];
|
|
12244
12250
|
case 1:
|
|
12245
12251
|
// Load full entities, one by one
|
|
12246
|
-
|
|
12247
|
-
|
|
12252
|
+
_b.data = _c.sent();
|
|
12253
|
+
_c.label = 2;
|
|
12248
12254
|
case 2: return [2 /*return*/, res];
|
|
12249
12255
|
}
|
|
12250
12256
|
});
|
|
@@ -12361,8 +12367,8 @@
|
|
|
12361
12367
|
return __awaiter(this, void 0, void 0, function () {
|
|
12362
12368
|
var dirtyIndexes, entities;
|
|
12363
12369
|
var _this = this;
|
|
12364
|
-
return __generator(this, function (
|
|
12365
|
-
switch (
|
|
12370
|
+
return __generator(this, function (_b) {
|
|
12371
|
+
switch (_b.label) {
|
|
12366
12372
|
case 0:
|
|
12367
12373
|
opts = Object.assign({ skipIfPristine: this.policy.skipNonLocalEntities }, opts);
|
|
12368
12374
|
// Skip is not dirty
|
|
@@ -12386,7 +12392,7 @@
|
|
|
12386
12392
|
return [4 /*yield*/, this.storage.remove(this._storageKey)];
|
|
12387
12393
|
case 1:
|
|
12388
12394
|
// Clean the local storage
|
|
12389
|
-
|
|
12395
|
+
_b.sent();
|
|
12390
12396
|
return [3 /*break*/, 7];
|
|
12391
12397
|
case 2:
|
|
12392
12398
|
if (!this.isByIdMode) return [3 /*break*/, 5];
|
|
@@ -12394,7 +12400,7 @@
|
|
|
12394
12400
|
return [4 /*yield*/, this.storage.set(this.storageKeyById, entities.filter(isNotNil).map(function (e) { return e.id; }))];
|
|
12395
12401
|
case 3:
|
|
12396
12402
|
// Save ids
|
|
12397
|
-
|
|
12403
|
+
_b.sent();
|
|
12398
12404
|
// Saved dirty entities
|
|
12399
12405
|
return [4 /*yield*/, Promise.all(dirtyIndexes
|
|
12400
12406
|
.map(function (index) {
|
|
@@ -12404,15 +12410,15 @@
|
|
|
12404
12410
|
}))];
|
|
12405
12411
|
case 4:
|
|
12406
12412
|
// Saved dirty entities
|
|
12407
|
-
|
|
12413
|
+
_b.sent();
|
|
12408
12414
|
console.info("[entity-storage] Persisting " + dirtyIndexes.length + "/" + entities.length + " " + this.name + "(s)...");
|
|
12409
12415
|
return [3 /*break*/, 7];
|
|
12410
12416
|
case 5:
|
|
12411
12417
|
console.info("[entity-storage] Persisting " + entities.length + " " + this.name + "(s)...");
|
|
12412
12418
|
return [4 /*yield*/, this.storage.set(this._storageKey, entities)];
|
|
12413
12419
|
case 6:
|
|
12414
|
-
|
|
12415
|
-
|
|
12420
|
+
_b.sent();
|
|
12421
|
+
_b.label = 7;
|
|
12416
12422
|
case 7: return [2 /*return*/, entities.length];
|
|
12417
12423
|
}
|
|
12418
12424
|
});
|
|
@@ -12422,14 +12428,14 @@
|
|
|
12422
12428
|
return __awaiter(this, void 0, void 0, function () {
|
|
12423
12429
|
var entities, res, values, ids, migration, oldKeysToClean, storageKeys, storageKeys, err_1;
|
|
12424
12430
|
var _this = this;
|
|
12425
|
-
return __generator(this, function (
|
|
12426
|
-
switch (
|
|
12431
|
+
return __generator(this, function (_b) {
|
|
12432
|
+
switch (_b.label) {
|
|
12427
12433
|
case 0: return [4 /*yield*/, Promise.all([
|
|
12428
12434
|
this.storage.get(this._storageKey),
|
|
12429
12435
|
this.storage.get(this.storageKeyById)
|
|
12430
12436
|
])];
|
|
12431
12437
|
case 1:
|
|
12432
|
-
res =
|
|
12438
|
+
res = _b.sent();
|
|
12433
12439
|
values = res[0] && Array.isArray(res[0]) ? res[0] : null;
|
|
12434
12440
|
ids = res[1] && Array.isArray(res[1]) ? res[1] : null;
|
|
12435
12441
|
migration = false;
|
|
@@ -12438,7 +12444,7 @@
|
|
|
12438
12444
|
storageKeys = ids.map(function (id) { return _this._storageKey + '#' + id; });
|
|
12439
12445
|
return [4 /*yield*/, chainPromises(storageKeys.map(function (key) { return function () { return _this.storage.get(key); }; }))];
|
|
12440
12446
|
case 2:
|
|
12441
|
-
entities =
|
|
12447
|
+
entities = _b.sent();
|
|
12442
12448
|
return [3 /*break*/, 4];
|
|
12443
12449
|
case 3:
|
|
12444
12450
|
if (isNotNil(values)) {
|
|
@@ -12446,7 +12452,7 @@
|
|
|
12446
12452
|
migration = true;
|
|
12447
12453
|
oldKeysToClean = [this._storageKey];
|
|
12448
12454
|
}
|
|
12449
|
-
|
|
12455
|
+
_b.label = 4;
|
|
12450
12456
|
case 4: return [3 /*break*/, 8];
|
|
12451
12457
|
case 5:
|
|
12452
12458
|
if (!isNotNil(values)) return [3 /*break*/, 6];
|
|
@@ -12458,10 +12464,10 @@
|
|
|
12458
12464
|
return [4 /*yield*/, chainPromises(storageKeys.map(function (key) { return function () { return _this.storage.get(key); }; }))];
|
|
12459
12465
|
case 7:
|
|
12460
12466
|
// Load entity by id (one by one)
|
|
12461
|
-
entities =
|
|
12467
|
+
entities = _b.sent();
|
|
12462
12468
|
migration = true;
|
|
12463
12469
|
oldKeysToClean = __spread(storageKeys, [this.storageKeyById]);
|
|
12464
|
-
|
|
12470
|
+
_b.label = 8;
|
|
12465
12471
|
case 8:
|
|
12466
12472
|
// OK, there is something in storage...
|
|
12467
12473
|
if (isNotEmptyArray(entities)) {
|
|
@@ -12476,23 +12482,23 @@
|
|
|
12476
12482
|
this.setEntities(entities || [], Object.assign(Object.assign({}, opts), { emitEvent: false }));
|
|
12477
12483
|
this._dirty = false;
|
|
12478
12484
|
if (!migration) return [3 /*break*/, 14];
|
|
12479
|
-
|
|
12485
|
+
_b.label = 9;
|
|
12480
12486
|
case 9:
|
|
12481
|
-
|
|
12487
|
+
_b.trys.push([9, 13, , 14]);
|
|
12482
12488
|
console.warn("[entity-storage] - Migrate " + this.name + " into {mode: '" + this.policy.mode + "'}...");
|
|
12483
12489
|
// Force to persist, using the new mode
|
|
12484
12490
|
return [4 /*yield*/, this.persist({ skipIfPristine: false /* force persist using the new mode */ })];
|
|
12485
12491
|
case 10:
|
|
12486
12492
|
// Force to persist, using the new mode
|
|
12487
|
-
|
|
12493
|
+
_b.sent();
|
|
12488
12494
|
if (!isNotEmptyArray(oldKeysToClean)) return [3 /*break*/, 12];
|
|
12489
12495
|
return [4 /*yield*/, chainPromises(oldKeysToClean.map(function (key) { return function () { return _this.storage.remove(key); }; }))];
|
|
12490
12496
|
case 11:
|
|
12491
|
-
|
|
12492
|
-
|
|
12497
|
+
_b.sent();
|
|
12498
|
+
_b.label = 12;
|
|
12493
12499
|
case 12: return [3 /*break*/, 14];
|
|
12494
12500
|
case 13:
|
|
12495
|
-
err_1 =
|
|
12501
|
+
err_1 = _b.sent();
|
|
12496
12502
|
console.error(err_1);
|
|
12497
12503
|
throw { code: ErrorCodes$2.ENTITY_STORAGE_MIGRATION_FAILED, message: 'ERROR.ENTITY_STORAGE_MIGRATION_FAILED', details: err_1 };
|
|
12498
12504
|
case 14:
|
|
@@ -12513,10 +12519,10 @@
|
|
|
12513
12519
|
}
|
|
12514
12520
|
};
|
|
12515
12521
|
EntityStore.prototype.markAsPristine = function (opts) {
|
|
12516
|
-
var e_1,
|
|
12522
|
+
var e_1, _b;
|
|
12517
12523
|
try {
|
|
12518
|
-
for (var
|
|
12519
|
-
var s =
|
|
12524
|
+
for (var _c = __values(this._statusById.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
12525
|
+
var s = _d.value;
|
|
12520
12526
|
if (isNotNil(s)) {
|
|
12521
12527
|
s.dirty = false;
|
|
12522
12528
|
}
|
|
@@ -12525,7 +12531,7 @@
|
|
|
12525
12531
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
12526
12532
|
finally {
|
|
12527
12533
|
try {
|
|
12528
|
-
if (
|
|
12534
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
12529
12535
|
}
|
|
12530
12536
|
finally { if (e_1) throw e_1.error; }
|
|
12531
12537
|
}
|
|
@@ -12546,8 +12552,8 @@
|
|
|
12546
12552
|
EntityStore.prototype.loadFullEntity = function (id, opts) {
|
|
12547
12553
|
return __awaiter(this, void 0, void 0, function () {
|
|
12548
12554
|
var status, index, fullData;
|
|
12549
|
-
return __generator(this, function (
|
|
12550
|
-
switch (
|
|
12555
|
+
return __generator(this, function (_b) {
|
|
12556
|
+
switch (_b.label) {
|
|
12551
12557
|
case 0:
|
|
12552
12558
|
status = this._statusById.get(id);
|
|
12553
12559
|
index = status && status.index;
|
|
@@ -12557,10 +12563,10 @@
|
|
|
12557
12563
|
console.debug("[entity-storage] Full reloading " + this.name + "#" + id + "...");
|
|
12558
12564
|
return [4 /*yield*/, this.storage.get(this._storageKey + '#' + id)];
|
|
12559
12565
|
case 1:
|
|
12560
|
-
fullData =
|
|
12566
|
+
fullData = _b.sent();
|
|
12561
12567
|
if (fullData)
|
|
12562
12568
|
return [2 /*return*/, fullData];
|
|
12563
|
-
|
|
12569
|
+
_b.label = 2;
|
|
12564
12570
|
case 2:
|
|
12565
12571
|
// Load from the cache, if dirty OR if storage is not splited by id
|
|
12566
12572
|
return [2 /*return*/, this._cache[index]];
|
|
@@ -13227,14 +13233,17 @@
|
|
|
13227
13233
|
console.warn("[entities-storage] Persisting " + entityName + ": store not found!");
|
|
13228
13234
|
return;
|
|
13229
13235
|
}
|
|
13236
|
+
// SKip store if not dirty
|
|
13230
13237
|
if (!entityStore.dirty)
|
|
13231
|
-
return;
|
|
13238
|
+
return Promise.resolve(); // Skip
|
|
13232
13239
|
// Persist store
|
|
13233
|
-
return entityStore.persist()
|
|
13240
|
+
return (entityStore.dirty ? entityStore.persist() : Promise.resolve(entityStore.length))
|
|
13234
13241
|
.then(function (count) {
|
|
13235
13242
|
// If no entity found, remove from the entity names array
|
|
13236
13243
|
if (!count) {
|
|
13237
|
-
entityNames.
|
|
13244
|
+
var entityNameIndex = entityNames.findIndex(function (e) { return e === entityName; });
|
|
13245
|
+
if (entityNameIndex !== -1)
|
|
13246
|
+
entityNames.splice(entityNameIndex, 1);
|
|
13238
13247
|
}
|
|
13239
13248
|
});
|
|
13240
13249
|
}; }))
|