@epam/uui-db 4.9.0-alpha.0 → 4.9.0-rc.1

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/index.js CHANGED
@@ -383,7 +383,7 @@ function __classPrivateFieldIn(state, receiver) {
383
383
  "use strict";
384
384
 
385
385
  Object.defineProperty(exports, "__esModule", { value: true });
386
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
386
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
387
387
  (0, tslib_1.__exportStar)(__webpack_require__(/*! ./src */ "./src/index.ts"), exports);
388
388
 
389
389
 
@@ -400,11 +400,11 @@ var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.
400
400
 
401
401
  Object.defineProperty(exports, "__esModule", { value: true });
402
402
  exports.Db = void 0;
403
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
404
- var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
405
- var lodash_isequal_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.isequal */ "lodash.isequal"));
406
- var Db = /** @class */ (function () {
407
- function Db(tables, reusedCache) {
403
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
404
+ const utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
405
+ const lodash_isequal_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.isequal */ "lodash.isequal"));
406
+ class Db {
407
+ constructor(tables, reusedCache) {
408
408
  this.tables = tables;
409
409
  this.viewCache = new Map();
410
410
  /* Views (cached db projections) */
@@ -416,29 +416,29 @@ var Db = /** @class */ (function () {
416
416
  this.viewCache = new Map();
417
417
  }
418
418
  }
419
- Db.prototype.update = function (mutate) {
420
- var clone = new this.constructor(this.tables, this.viewCache);
421
- clone.tables = (0, tslib_1.__assign)({}, this.tables);
419
+ update(mutate) {
420
+ const clone = new this.constructor(this.tables, this.viewCache);
421
+ clone.tables = Object.assign({}, this.tables);
422
422
  mutate(clone);
423
423
  return clone;
424
- };
425
- Db.prototype.with = function (patch) {
426
- return this.update(function (db) {
427
- (0, utils_1.objectKeys)(db.tables).forEach(function (entityName) {
424
+ }
425
+ with(patch) {
426
+ return this.update(db => {
427
+ (0, utils_1.objectKeys)(db.tables).forEach(entityName => {
428
428
  if (patch[entityName]) {
429
429
  db.tables[entityName] = db.tables[entityName].with(patch[entityName]);
430
430
  }
431
431
  });
432
432
  });
433
- };
434
- Db.prototype.runView = function (view, params) {
435
- var cache = this.viewCache.get(view);
433
+ }
434
+ runView(view, params) {
435
+ let cache = this.viewCache.get(view);
436
436
  if (!cache) {
437
437
  cache = new Map();
438
438
  this.viewCache.set(view, cache);
439
439
  }
440
- var key = view.getKey ? view.getKey(params) : JSON.stringify(params);
441
- var cacheItem = cache.get(key);
440
+ const key = view.getKey ? view.getKey(params) : JSON.stringify(params);
441
+ let cacheItem = cache.get(key);
442
442
  if (!cacheItem) {
443
443
  cacheItem = {
444
444
  dependencies: this.valueAbsent,
@@ -447,19 +447,19 @@ var Db = /** @class */ (function () {
447
447
  };
448
448
  cache.set(key, cacheItem);
449
449
  }
450
- var shouldUpdate = this !== cacheItem.computedOnDb;
451
- var dependencies = this.valueAbsent;
450
+ let shouldUpdate = this !== cacheItem.computedOnDb;
451
+ let dependencies = this.valueAbsent;
452
452
  if (view.getDependencies) {
453
- var compare = view.compareDependencies || utils_1.defaultCompareViewDependencies;
453
+ const compare = view.compareDependencies || utils_1.defaultCompareViewDependencies;
454
454
  dependencies = view.getDependencies(this, params);
455
455
  shouldUpdate = !compare(cacheItem.dependencies, dependencies);
456
456
  }
457
- var previousValue = cacheItem.currentValue;
457
+ let previousValue = cacheItem.currentValue;
458
458
  if (shouldUpdate) {
459
459
  cacheItem.dependencies = dependencies;
460
- var newValue = view.compute(this, params, dependencies);
460
+ let newValue = view.compute(this, params, dependencies);
461
461
  cacheItem.computedOnDb = this;
462
- var compareResults = view.compareResults || lodash_isequal_1.default;
462
+ let compareResults = view.compareResults || lodash_isequal_1.default;
463
463
  if (!compareResults(previousValue, newValue)) {
464
464
  if (view.traceDiff) {
465
465
  console.debug((0, utils_1.difference)(previousValue, newValue));
@@ -468,9 +468,8 @@ var Db = /** @class */ (function () {
468
468
  }
469
469
  }
470
470
  return cacheItem.currentValue;
471
- };
472
- return Db;
473
- }());
471
+ }
472
+ }
474
473
  exports.Db = Db;
475
474
 
476
475
 
@@ -487,18 +486,17 @@ exports.Db = Db;
487
486
 
488
487
  Object.defineProperty(exports, "__esModule", { value: true });
489
488
  exports.DbRef = void 0;
490
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
491
- var patchHelpers_1 = __webpack_require__(/*! ./patchHelpers */ "./src/patchHelpers.ts");
492
- var tempIds_1 = __webpack_require__(/*! ./tempIds */ "./src/tempIds.tsx");
493
- var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
494
- var lodash_isempty_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.isempty */ "lodash.isempty"));
495
- var Loader_1 = __webpack_require__(/*! ./Loader */ "./src/Loader.ts");
496
- var uui_core_1 = __webpack_require__(/*! @epam/uui-core */ "@epam/uui-core");
497
- var SimpleLoadingTracker_1 = __webpack_require__(/*! ./SimpleLoadingTracker */ "./src/SimpleLoadingTracker.ts");
498
- var ListLoadingTracker_1 = __webpack_require__(/*! ./ListLoadingTracker */ "./src/ListLoadingTracker.ts");
499
- var DbRef = /** @class */ (function () {
500
- function DbRef(blank) {
501
- var _this = this;
489
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
490
+ const patchHelpers_1 = __webpack_require__(/*! ./patchHelpers */ "./src/patchHelpers.ts");
491
+ const tempIds_1 = __webpack_require__(/*! ./tempIds */ "./src/tempIds.tsx");
492
+ const utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
493
+ const lodash_isempty_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.isempty */ "lodash.isempty"));
494
+ const Loader_1 = __webpack_require__(/*! ./Loader */ "./src/Loader.ts");
495
+ const uui_core_1 = __webpack_require__(/*! @epam/uui-core */ "@epam/uui-core");
496
+ const SimpleLoadingTracker_1 = __webpack_require__(/*! ./SimpleLoadingTracker */ "./src/SimpleLoadingTracker.ts");
497
+ const ListLoadingTracker_1 = __webpack_require__(/*! ./ListLoadingTracker */ "./src/ListLoadingTracker.ts");
498
+ class DbRef {
499
+ constructor(blank) {
502
500
  this.blank = blank;
503
501
  this.log = [];
504
502
  this.autoSave = true;
@@ -511,36 +509,25 @@ var DbRef = /** @class */ (function () {
511
509
  /* Error Subscriptions */
512
510
  this.saveErrorHandlers = [];
513
511
  /* Save scheduling */
514
- this.enqueueSave = (0, uui_core_1.batch)(function () { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
515
- var cumulativePatch, lastLogEntry, response, error_1;
516
- return (0, tslib_1.__generator)(this, function (_a) {
517
- switch (_a.label) {
518
- case 0:
519
- cumulativePatch = this.makeCumulativePatch();
520
- lastLogEntry = this.log.length;
521
- if ((0, lodash_isempty_1.default)(cumulativePatch)) {
522
- return [2 /*return*/];
523
- }
524
- _a.label = 1;
525
- case 1:
526
- _a.trys.push([1, 3, , 4]);
527
- return [4 /*yield*/, this.savePatch(cumulativePatch)];
528
- case 2:
529
- response = _a.sent();
530
- this.applyResponse(response, lastLogEntry);
531
- this.update();
532
- return [3 /*break*/, 4];
533
- case 3:
534
- error_1 = _a.sent();
535
- this.saveError(cumulativePatch, error_1);
536
- this.update();
537
- throw error_1;
538
- case 4: return [2 /*return*/];
539
- }
540
- });
541
- }); });
542
- this.handleBeforeUnload = function (e) {
543
- if (_this.enqueueSave.isBusy) {
512
+ this.enqueueSave = (0, uui_core_1.batch)(() => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
513
+ const cumulativePatch = this.makeCumulativePatch();
514
+ const lastLogEntry = this.log.length;
515
+ if ((0, lodash_isempty_1.default)(cumulativePatch)) {
516
+ return;
517
+ }
518
+ try {
519
+ const response = yield this.savePatch(cumulativePatch);
520
+ this.applyResponse(response, lastLogEntry);
521
+ this.update();
522
+ }
523
+ catch (error) {
524
+ this.saveError(cumulativePatch, error);
525
+ this.update();
526
+ throw error;
527
+ }
528
+ }));
529
+ this.handleBeforeUnload = (e) => {
530
+ if (this.enqueueSave.isBusy) {
544
531
  e.returnValue = false;
545
532
  return false;
546
533
  }
@@ -553,143 +540,139 @@ var DbRef = /** @class */ (function () {
553
540
  window.addEventListener('beforeunload', this.handleBeforeUnload);
554
541
  }
555
542
  /** Saves all committed patches. Useful only if autoSave is off. */
556
- DbRef.prototype.save = function () {
543
+ save() {
557
544
  return this.enqueueSave();
558
- };
559
- DbRef.prototype.getAutoSave = function () {
545
+ }
546
+ getAutoSave() {
560
547
  return this.autoSave;
561
- };
562
- DbRef.prototype.setAutoSave = function (val) {
548
+ }
549
+ setAutoSave(val) {
563
550
  if (this.autoSave != val) {
564
551
  this.autoSave = val;
565
552
  this.autoSave && this.enqueueSave();
566
553
  this.update();
567
554
  }
568
- };
569
- DbRef.prototype.revert = function () {
555
+ }
556
+ revert() {
570
557
  this.db = this.base;
571
558
  this.log = this.log.slice(0, this.savedPoint);
572
559
  this.update();
573
- };
560
+ }
574
561
  /** Concrete DbRef instances should override and implement their save logic in this method */
575
- DbRef.prototype.savePatch = function (patch) {
562
+ savePatch(patch) {
576
563
  return Promise.resolve({ submit: {} });
577
- };
564
+ }
578
565
  /* Db Update logic */
579
- DbRef.prototype.commit = function (patch) {
580
- var dbBeforeUpdate = this.db.with(patch);
566
+ commit(patch) {
567
+ const dbBeforeUpdate = this.db.with(patch);
581
568
  patch = this.beforeUpdate(patch, dbBeforeUpdate.tables, this.db.tables);
582
569
  patch = (0, patchHelpers_1.mergeEntityPatches)(this.db.tables, patch);
583
- this.log.push({ patch: patch });
570
+ this.log.push({ patch });
584
571
  this.db = this.db.with(patch);
585
572
  this.autoSave && this.enqueueSave(null, { throttleMs: this.throttleSaveMs });
586
573
  this.update();
587
- };
588
- DbRef.prototype.beforeUpdate = function (patch, tables, prevTables) {
589
- var _this = this;
590
- var patchAndDependencies = {};
591
- (0, utils_1.objectKeys)(tables).filter(function (entityName) { return patch[entityName] && !tables[entityName].schema.beforeUpdate; }).forEach(function (entityName) {
574
+ }
575
+ beforeUpdate(patch, tables, prevTables) {
576
+ let patchAndDependencies = {};
577
+ (0, utils_1.objectKeys)(tables).filter(entityName => patch[entityName] && !tables[entityName].schema.beforeUpdate).forEach(entityName => {
592
578
  patchAndDependencies[entityName] = patch[entityName];
593
579
  });
594
- (0, utils_1.objectKeys)(tables).filter(function (entityName) { return patch[entityName] && tables[entityName].schema.beforeUpdate; }).forEach(function (entityName) {
595
- var _a;
596
- var schema = tables[entityName].schema;
597
- var beforeUpdate = schema.beforeUpdate;
598
- var context = {
599
- clientIdsMap: _this.tempIdMap,
600
- schema: schema,
601
- tables: tables,
602
- prevTables: prevTables,
580
+ (0, utils_1.objectKeys)(tables).filter(entityName => patch[entityName] && tables[entityName].schema.beforeUpdate).forEach(entityName => {
581
+ const schema = tables[entityName].schema;
582
+ const { beforeUpdate } = schema;
583
+ let context = {
584
+ clientIdsMap: this.tempIdMap,
585
+ schema,
586
+ tables,
587
+ prevTables,
603
588
  };
604
- var results = patch[entityName].map(function (e) { return beforeUpdate(e, context); });
605
- var updatedPatch = (_a = {}, _a[entityName] = results.map(function (result) { return result.entity; }), _a);
606
- var dependentEntityPatchesForUpdate = (0, patchHelpers_1.unionPatches)(results.filter(function (result) { return result.dependentEntities; }).map(function (result) { return result.dependentEntities; }));
607
- var dependentEntityPatches = _this.beforeUpdate(dependentEntityPatchesForUpdate, tables, prevTables);
589
+ const results = patch[entityName].map(e => beforeUpdate(e, context));
590
+ const updatedPatch = { [entityName]: results.map(result => result.entity) };
591
+ const dependentEntityPatchesForUpdate = (0, patchHelpers_1.unionPatches)(results.filter(result => result.dependentEntities).map(result => result.dependentEntities));
592
+ const dependentEntityPatches = this.beforeUpdate(dependentEntityPatchesForUpdate, tables, prevTables);
608
593
  patchAndDependencies = (0, patchHelpers_1.mergeEntityPatches)(tables, (0, patchHelpers_1.unionPatches)([patchAndDependencies, updatedPatch, dependentEntityPatches]));
609
594
  });
610
595
  return patchAndDependencies;
611
- };
612
- DbRef.prototype.commitFetch = function (patch) {
596
+ }
597
+ commitFetch(patch) {
613
598
  patch = this.tempIdMap.serverToClientPatch(patch);
614
599
  this.rebase(this.base.with(patch));
615
600
  this.update();
616
- };
617
- DbRef.prototype.rebase = function (newBase) {
601
+ }
602
+ rebase(newBase) {
618
603
  this.base = newBase;
619
604
  this.db = newBase;
620
- for (var n = this.savedPoint; n < this.log.length; n++) {
605
+ for (let n = this.savedPoint; n < this.log.length; n++) {
621
606
  this.db = this.db.with(this.log[n].patch);
622
607
  }
623
- };
624
- DbRef.prototype.makeCumulativePatch = function () {
625
- var lastLogEntry = this.log.length;
626
- var logEntriesToSave = this.log.slice(this.savedPoint, lastLogEntry);
627
- var cumulativePatch = (0, patchHelpers_1.makeCumulativePatch)(this.db, logEntriesToSave.map(function (t) { return t.patch; }), this.tempIdMap);
608
+ }
609
+ makeCumulativePatch() {
610
+ const lastLogEntry = this.log.length;
611
+ const logEntriesToSave = this.log.slice(this.savedPoint, lastLogEntry);
612
+ let cumulativePatch = (0, patchHelpers_1.makeCumulativePatch)(this.db, logEntriesToSave.map(t => t.patch), this.tempIdMap);
628
613
  cumulativePatch = this.tempIdMap.clientToServerPatch(cumulativePatch);
629
614
  return cumulativePatch;
630
- };
631
- DbRef.prototype.applyResponse = function (response, newSavedPoint) {
615
+ }
616
+ applyResponse(response, newSavedPoint) {
632
617
  this.tempIdMap.appendServerMapping(response);
633
- var serverPatch = (0, patchHelpers_1.flattenResponse)(response.submit, this.db.tables);
618
+ let serverPatch = (0, patchHelpers_1.flattenResponse)(response.submit, this.db.tables);
634
619
  serverPatch = (0, patchHelpers_1.mergeEntityPatches)(this.db.tables, serverPatch);
635
620
  this.savedPoint = newSavedPoint;
636
621
  this.base = this.db;
637
622
  this.commitFetch(serverPatch);
638
- };
639
- DbRef.prototype.subscribe = function (view, params, onUpdate) {
640
- var _this = this;
641
- var id = this.lastSubscriptionId++;
642
- var subscription = {
643
- update: function (params) {
623
+ }
624
+ subscribe(view, params, onUpdate) {
625
+ const id = this.lastSubscriptionId++;
626
+ const subscription = {
627
+ update: (params) => {
644
628
  subscription.currentParams = params;
645
- subscription.currentValue = _this.db.runView(view, params);
629
+ subscription.currentValue = this.db.runView(view, params);
646
630
  return subscription.currentValue;
647
631
  },
648
632
  currentParams: null,
649
633
  currentValue: null,
650
- onUpdate: onUpdate,
651
- unsubscribe: function () { _this.subscriptions.delete(id); },
634
+ onUpdate,
635
+ unsubscribe: () => { this.subscriptions.delete(id); },
652
636
  };
653
637
  subscription.update(params);
654
638
  this.subscriptions.set(id, subscription);
655
639
  return subscription;
656
- };
657
- DbRef.prototype.onUpdate = function (handler) {
640
+ }
641
+ onUpdate(handler) {
658
642
  this.subscribe({
659
- compute: function (db) { return db; },
660
- compareResults: function (a, b) { return a === b; },
643
+ compute: db => db,
644
+ compareResults: (a, b) => a === b,
661
645
  }, null, handler);
662
- };
663
- DbRef.prototype.update = function () {
664
- this.subscriptions.forEach(function (subscription) {
665
- var previousValue = subscription.currentValue;
646
+ }
647
+ update() {
648
+ this.subscriptions.forEach(subscription => {
649
+ const previousValue = subscription.currentValue;
666
650
  subscription.update(subscription.currentParams);
667
651
  if (subscription.currentValue !== previousValue && subscription.onUpdate) {
668
652
  subscription.onUpdate(subscription.currentValue);
669
653
  }
670
654
  });
671
- };
672
- DbRef.prototype.onSaveError = function (handler) {
655
+ }
656
+ onSaveError(handler) {
673
657
  this.saveErrorHandlers.push(handler);
674
- };
675
- DbRef.prototype.saveError = function (request, error) {
676
- this.saveErrorHandlers.forEach(function (handler) { return handler(request, error); });
677
- };
678
- DbRef.prototype.makeLoader = function (options) {
679
- var loader = new Loader_1.Loader(this, function () { return new SimpleLoadingTracker_1.SimpleLoadingTracker(); }, options);
658
+ }
659
+ saveError(request, error) {
660
+ this.saveErrorHandlers.forEach(handler => handler(request, error));
661
+ }
662
+ makeLoader(options) {
663
+ const loader = new Loader_1.Loader(this, () => new SimpleLoadingTracker_1.SimpleLoadingTracker(), options);
680
664
  this.loaders.push(loader);
681
665
  return loader;
682
- };
683
- DbRef.prototype.makeListLoader = function (options) {
684
- var loader = new Loader_1.Loader(this, function () { return new ListLoadingTracker_1.ListLoadingTracker(); }, options);
666
+ }
667
+ makeListLoader(options) {
668
+ const loader = new Loader_1.Loader(this, () => new ListLoadingTracker_1.ListLoadingTracker(), options);
685
669
  this.loaders.push(loader);
686
670
  return loader;
687
- };
688
- DbRef.prototype.reload = function () {
671
+ }
672
+ reload() {
689
673
  this.loaders = [];
690
- };
691
- return DbRef;
692
- }());
674
+ }
675
+ }
693
676
  exports.DbRef = DbRef;
694
677
 
695
678
 
@@ -706,151 +689,144 @@ exports.DbRef = DbRef;
706
689
 
707
690
  Object.defineProperty(exports, "__esModule", { value: true });
708
691
  exports.DbTable = void 0;
709
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
710
- var I = (0, tslib_1.__importStar)(__webpack_require__(/*! immutable */ "immutable"));
711
- var uui_core_1 = __webpack_require__(/*! @epam/uui-core */ "@epam/uui-core");
712
- var immutable_1 = __webpack_require__(/*! immutable */ "immutable");
713
- var DbTable = /** @class */ (function () {
714
- function DbTable(schema, state, q) {
692
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
693
+ const I = (0, tslib_1.__importStar)(__webpack_require__(/*! immutable */ "immutable"));
694
+ const uui_core_1 = __webpack_require__(/*! @epam/uui-core */ "@epam/uui-core");
695
+ const immutable_1 = __webpack_require__(/*! immutable */ "immutable");
696
+ class DbTable {
697
+ constructor(schema, state, q) {
715
698
  this.schema = schema;
716
699
  this.state = state;
717
700
  this.q = q;
718
701
  if (!state) {
719
- var indexes = (schema.indexes || []).map(function (indexDef) {
702
+ const indexes = (schema.indexes || []).map(indexDef => {
720
703
  return {
721
704
  field: indexDef,
722
705
  map: I.Map(),
723
706
  };
724
707
  });
725
- this.state = { pk: I.Map(), indexes: indexes };
708
+ this.state = { pk: I.Map(), indexes };
726
709
  }
727
710
  if (!q) {
728
711
  this.q = {};
729
712
  }
730
713
  }
731
- DbTable.prototype.keyToImmutable = function (id) {
714
+ keyToImmutable(id) {
732
715
  if (Array.isArray(id)) {
733
716
  return I.List(id);
734
717
  }
735
718
  else {
736
719
  return id;
737
720
  }
738
- };
739
- DbTable.prototype.byId = function (id) {
721
+ }
722
+ byId(id) {
740
723
  return this.state.pk.get(this.keyToImmutable(id));
741
- };
742
- DbTable.prototype.getId = function (entity) {
724
+ }
725
+ getId(entity) {
743
726
  if (Array.isArray(this.schema.primaryKey)) {
744
- return this.schema.primaryKey.map(function (key) { return entity[key]; });
727
+ return this.schema.primaryKey.map((key) => entity[key]);
745
728
  }
746
729
  return entity[this.schema.primaryKey];
747
- };
748
- DbTable.prototype.update = function (mutate) {
749
- var clone = new this.constructor(this.schema, this.state, this.q);
730
+ }
731
+ update(mutate) {
732
+ const clone = new this.constructor(this.schema, this.state, this.q);
750
733
  mutate(clone);
751
734
  return clone;
752
- };
735
+ }
753
736
  /* Mutation */
754
- DbTable.prototype.with = function (patch) {
755
- var _this = this;
756
- var updates = patch.map(function (entityPatch) {
757
- var id = _this.getId(entityPatch);
758
- var immId = _this.keyToImmutable(id);
759
- var existing = _this.state.pk.get(immId);
760
- var isDeleted = false;
761
- var updated = entityPatch;
737
+ with(patch) {
738
+ const updates = patch.map(entityPatch => {
739
+ const id = this.getId(entityPatch);
740
+ const immId = this.keyToImmutable(id);
741
+ const existing = this.state.pk.get(immId);
742
+ let isDeleted = false;
743
+ let updated = entityPatch;
762
744
  if (existing) {
763
- updated = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, existing), entityPatch);
764
- if (_this.schema.deleteFlag) {
765
- isDeleted = updated[_this.schema.deleteFlag] === true;
745
+ updated = Object.assign(Object.assign({}, existing), entityPatch);
746
+ if (this.schema.deleteFlag) {
747
+ isDeleted = updated[this.schema.deleteFlag] === true;
766
748
  }
767
749
  }
768
- return { id: id, immId: immId, patch: entityPatch, existing: existing, updated: updated, isNew: !existing, isDeleted: isDeleted };
750
+ return { id, immId, patch: entityPatch, existing, updated, isNew: !existing, isDeleted };
769
751
  });
770
- var idVal = immutable_1.Seq.Keyed(updates.map(function (entity) { return [entity.immId, entity.updated]; }));
771
- var newPk = this.state.pk.merge(idVal);
752
+ const idVal = immutable_1.Seq.Keyed(updates.map(entity => [entity.immId, entity.updated]));
753
+ let newPk = this.state.pk.merge(idVal);
772
754
  // TBD: replace with deleteAll after migrating to immutable 4
773
- updates.filter(function (u) { return u.isDeleted; }).forEach(function (u) {
755
+ updates.filter(u => u.isDeleted).forEach(u => {
774
756
  newPk = newPk.delete(u.immId);
775
757
  });
776
- var newIndexes = this.state.indexes.map(function (index) {
777
- var newMap = index.map;
778
- var _loop_1 = function (n) {
779
- var update = updates[n];
780
- var newKey = update.updated[index.field];
758
+ const newIndexes = this.state.indexes.map(index => {
759
+ let newMap = index.map;
760
+ for (let n = 0; n < updates.length; n++) {
761
+ let update = updates[n];
762
+ const newKey = update.updated[index.field];
781
763
  if (update.existing) {
782
- var oldKey = update.existing[index.field];
764
+ const oldKey = update.existing[index.field];
783
765
  if (oldKey !== newKey || update.isDeleted) {
784
- newMap = newMap.update(oldKey, function (set) { return set.remove(update.immId); });
766
+ newMap = newMap.update(oldKey, set => set.remove(update.immId));
785
767
  }
786
768
  }
787
769
  if (!update.isDeleted) {
788
- newMap = newMap.update(newKey, I.Set(), function (set) { return set.add(update.immId); });
770
+ newMap = newMap.update(newKey, I.Set(), set => set.add(update.immId));
789
771
  }
790
- };
791
- for (var n = 0; n < updates.length; n++) {
792
- _loop_1(n);
793
772
  }
794
- return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, index), { map: newMap });
773
+ return Object.assign(Object.assign({}, index), { map: newMap });
795
774
  });
796
- var newState = { pk: newPk, indexes: newIndexes };
797
- return this.update(function (t) { return t.state = newState; });
798
- };
775
+ const newState = { pk: newPk, indexes: newIndexes };
776
+ return this.update(t => t.state = newState);
777
+ }
799
778
  /* Query */
800
- DbTable.prototype.find = function (filter) {
801
- var _this = this;
802
- return this.update(function (t) { return t.q = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, t.q), { filter: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, _this.q.filter), filter) }); });
803
- };
804
- DbTable.prototype.order = function (order) {
805
- return this.update(function (t) { return t.q = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, t.q), { sorting: order }); });
806
- };
807
- DbTable.prototype.orderBy = function (field, direction) {
808
- if (direction === void 0) { direction = 'asc'; }
809
- return this.update(function (t) { return t.q = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, t.q), { sorting: [{ field: field, direction: direction }] }); });
810
- };
811
- DbTable.prototype.thenBy = function (field, direction) {
812
- return this.update(function (t) { return t.q = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, t.q), { sorting: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], t.q.sorting, true), [{ field: field, direction: direction }], false) }); });
813
- };
814
- DbTable.prototype.search = function (text) {
779
+ find(filter) {
780
+ return this.update(t => t.q = Object.assign(Object.assign({}, t.q), { filter: Object.assign(Object.assign({}, this.q.filter), filter) }));
781
+ }
782
+ order(order) {
783
+ return this.update(t => t.q = Object.assign(Object.assign({}, t.q), { sorting: order }));
784
+ }
785
+ orderBy(field, direction = 'asc') {
786
+ return this.update(t => t.q = Object.assign(Object.assign({}, t.q), { sorting: [{ field, direction }] }));
787
+ }
788
+ thenBy(field, direction) {
789
+ return this.update(t => t.q = Object.assign(Object.assign({}, t.q), { sorting: [...t.q.sorting, { field, direction }] }));
790
+ }
791
+ search(text) {
815
792
  if (!this.schema.searchBy) {
816
- throw new Error("Can't search in the ".concat(this.schema.typeName, " table - searchBy is not defined in the schema."));
793
+ throw new Error(`Can't search in the ${this.schema.typeName} table - searchBy is not defined in the schema.`);
817
794
  }
818
- return this.update(function (t) { return t.q = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, t.q), { search: text }); });
819
- };
795
+ return this.update(t => t.q = Object.assign(Object.assign({}, t.q), { search: text }));
796
+ }
820
797
  /* Materializing */
821
- DbTable.prototype.range = function (from, count) {
822
- return this.runQuery((0, tslib_1.__assign)((0, tslib_1.__assign)({}, this.q), { range: { from: from, count: count } }));
823
- };
824
- DbTable.prototype.count = function () {
798
+ range(from, count) {
799
+ return this.runQuery(Object.assign(Object.assign({}, this.q), { range: { from, count } }));
800
+ }
801
+ count() {
825
802
  return this.runQuery(this.q).length;
826
- };
827
- DbTable.prototype.one = function () {
803
+ }
804
+ one() {
828
805
  return this.runQuery(this.q)[0] || null;
829
- };
830
- DbTable.prototype.toArray = function () {
806
+ }
807
+ toArray() {
831
808
  return this.runQuery(this.q);
832
- };
833
- DbTable.prototype.map = function (fn) {
809
+ }
810
+ map(fn) {
834
811
  return this.toArray().map(fn);
835
- };
812
+ }
836
813
  /* Query implementation */
837
- DbTable.prototype.runQuery = function (q) {
838
- var _this = this;
839
- var result = null;
840
- var filter = q.filter;
814
+ runQuery(q) {
815
+ let result = null;
816
+ let filter = q.filter;
841
817
  if (filter) {
842
- var indexes = this.state.indexes;
818
+ let indexes = this.state.indexes;
843
819
  // Try to use indexes to fulfill filter conditions
844
- for (var n = 0; n < indexes.length; n++) {
845
- var index = indexes[n];
820
+ for (let n = 0; n < indexes.length; n++) {
821
+ const index = indexes[n];
846
822
  if (index.field in filter) {
847
- var _a = filter, _b = index.field, condition = _a[_b], rest = (0, tslib_1.__rest)(_a, [typeof _b === "symbol" ? _b : _b + ""]);
848
- var conditionValues = null;
823
+ const _a = filter, _b = index.field, condition = _a[_b], rest = (0, tslib_1.__rest)(_a, [typeof _b === "symbol" ? _b : _b + ""]);
824
+ let conditionValues = null;
849
825
  if (condition != null && typeof condition === "object") {
850
826
  // Attempt to use index for 'in' and 'isNull' criteria.
851
827
  // We need to be very conservative here, indexed field should work the same way as getPatternPredicate. So
852
828
  // - it's better to leave corner cases to getPatternPredicate
853
- var _c = condition, inCriteria = _c.in, nullCriteria = _c.isNull, restCriteria = (0, tslib_1.__rest)(_c, ["in", "isNull"]);
829
+ const _c = condition, { in: inCriteria, isNull: nullCriteria } = _c, restCriteria = (0, tslib_1.__rest)(_c, ["in", "isNull"]);
854
830
  if (inCriteria && Array.isArray(inCriteria)) {
855
831
  conditionValues = inCriteria;
856
832
  }
@@ -877,12 +853,12 @@ var DbTable = /** @class */ (function () {
877
853
  }
878
854
  if (conditionValues) {
879
855
  result = [];
880
- for (var i = 0; i < conditionValues.length; i++) {
881
- var idsSet = index.map.get(conditionValues[i]);
856
+ for (let i = 0; i < conditionValues.length; i++) {
857
+ const idsSet = index.map.get(conditionValues[i]);
882
858
  if (idsSet) {
883
- var idsArray = idsSet.toArray();
884
- for (var j = 0; j < idsArray.length; j++) {
885
- var item = this.state.pk.get(idsArray[j]);
859
+ const idsArray = idsSet.toArray();
860
+ for (let j = 0; j < idsArray.length; j++) {
861
+ const item = this.state.pk.get(idsArray[j]);
886
862
  result.push(item);
887
863
  }
888
864
  }
@@ -897,24 +873,23 @@ var DbTable = /** @class */ (function () {
897
873
  result = this.state.pk.toArray();
898
874
  }
899
875
  if (filter) {
900
- var predicate = (0, uui_core_1.getPatternPredicate)(q.filter);
876
+ let predicate = (0, uui_core_1.getFilterPredicate)(q.filter);
901
877
  result = result.filter(predicate);
902
878
  }
903
879
  if (q.search) {
904
- var searchFilter_1 = (0, uui_core_1.getSearchFilter)(q.search);
905
- result = result.filter(function (item) { return searchFilter_1(_this.schema.searchBy.map(function (field) { return item[field]; })); });
880
+ let searchFilter = (0, uui_core_1.getSearchFilter)(q.search);
881
+ result = result.filter(item => searchFilter(this.schema.searchBy.map(field => item[field])));
906
882
  }
907
883
  if (q.sorting) {
908
- var comparer = (0, uui_core_1.getOrderComparer)(q.sorting);
884
+ let comparer = (0, uui_core_1.getOrderComparer)(q.sorting);
909
885
  result = result.sort(comparer);
910
886
  }
911
887
  if (q.range) {
912
888
  result = result.slice(q.range.from, q.range.from + q.range.count);
913
889
  }
914
890
  return result;
915
- };
916
- return DbTable;
917
- }());
891
+ }
892
+ }
918
893
  exports.DbTable = DbTable;
919
894
 
920
895
 
@@ -931,16 +906,16 @@ exports.DbTable = DbTable;
931
906
 
932
907
  Object.defineProperty(exports, "__esModule", { value: true });
933
908
  exports.ListLoadingTracker = void 0;
934
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
935
- var ListLoadingTracker = /** @class */ (function () {
936
- function ListLoadingTracker(options) {
909
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
910
+ class ListLoadingTracker {
911
+ constructor(options) {
937
912
  this.options = options;
938
913
  this.cache = new Map();
939
- this.extractList = (options === null || options === void 0 ? void 0 : options.extractList) || (function (r) { return r; });
914
+ this.extractList = (options === null || options === void 0 ? void 0 : options.extractList) || ((r) => r);
940
915
  }
941
- ListLoadingTracker.prototype.prepare = function (request) {
942
- var filter = request.filter, sorting = request.sorting, search = request.search, range = request.range, unknownFields = (0, tslib_1.__rest)(request, ["filter", "sorting", "search", "range"]);
943
- var options = {};
916
+ prepare(request) {
917
+ const { filter, sorting, search, range } = request, unknownFields = (0, tslib_1.__rest)(request, ["filter", "sorting", "search", "range"]);
918
+ const options = {};
944
919
  if (filter) {
945
920
  options.filter = filter;
946
921
  }
@@ -950,17 +925,17 @@ var ListLoadingTracker = /** @class */ (function () {
950
925
  if (search) {
951
926
  options.search = search;
952
927
  }
953
- var keyObject = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), unknownFields);
954
- var key = JSON.stringify(keyObject);
955
- var entry = this.cache.get(key);
928
+ let keyObject = Object.assign(Object.assign({}, options), unknownFields);
929
+ const key = JSON.stringify(keyObject);
930
+ let entry = this.cache.get(key);
956
931
  if (!entry) {
957
- entry = { options: options, count: 0, maxCount: null, isComplete: false };
932
+ entry = { options, count: 0, maxCount: null, isComplete: false };
958
933
  this.cache.set(key, entry);
959
934
  }
960
- return { options: options, range: range, unknownFields: unknownFields, entry: entry };
961
- };
962
- ListLoadingTracker.prototype.diff = function (request) {
963
- var _a = this.prepare(request), options = _a.options, range = _a.range, unknownFields = _a.unknownFields, entry = _a.entry;
935
+ return { options, range, unknownFields, entry };
936
+ }
937
+ diff(request) {
938
+ const { options, range, unknownFields, entry } = this.prepare(request);
964
939
  if (entry.isComplete) {
965
940
  return null;
966
941
  }
@@ -968,27 +943,27 @@ var ListLoadingTracker = /** @class */ (function () {
968
943
  return request;
969
944
  }
970
945
  else {
971
- var requestedMax = request.range.from + request.range.count;
972
- var missingCount = requestedMax - entry.count;
946
+ const requestedMax = request.range.from + request.range.count;
947
+ let missingCount = requestedMax - entry.count;
973
948
  if (entry.maxCount) {
974
949
  missingCount = Math.min(missingCount, entry.maxCount);
975
950
  }
976
951
  if (missingCount > 0) {
977
- return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), unknownFields), { range: { from: entry.count, count: requestedMax - entry.count } });
952
+ return Object.assign(Object.assign(Object.assign({}, options), unknownFields), { range: { from: entry.count, count: requestedMax - entry.count } });
978
953
  }
979
954
  else {
980
955
  return null;
981
956
  }
982
957
  }
983
- };
984
- ListLoadingTracker.prototype.count = function (request) {
985
- var entry = this.prepare(request).entry;
958
+ }
959
+ count(request) {
960
+ const { entry } = this.prepare(request);
986
961
  return { knownCount: Math.max(entry.count, entry.maxCount), exactCount: entry.maxCount };
987
- };
988
- ListLoadingTracker.prototype.append = function (request, response) {
989
- var _a = this.prepare(request), options = _a.options, range = _a.range, unknownFields = _a.unknownFields, entry = _a.entry;
962
+ }
963
+ append(request, response) {
964
+ const { options, range, unknownFields, entry } = this.prepare(request);
990
965
  if (response) {
991
- var list = this.extractList(response);
966
+ const list = this.extractList(response);
992
967
  if (list.count) {
993
968
  entry.maxCount = list.count;
994
969
  }
@@ -998,7 +973,7 @@ var ListLoadingTracker = /** @class */ (function () {
998
973
  entry.isComplete = true;
999
974
  }
1000
975
  else {
1001
- var from = (list.from == null) ? range.from : list.from;
976
+ const from = (list.from == null) ? range.from : list.from;
1002
977
  if (list.items.length > 0) {
1003
978
  entry.count = Math.max(entry.count, from + list.items.length);
1004
979
  }
@@ -1017,9 +992,8 @@ var ListLoadingTracker = /** @class */ (function () {
1017
992
  entry.isComplete = true;
1018
993
  }
1019
994
  }
1020
- };
1021
- return ListLoadingTracker;
1022
- }());
995
+ }
996
+ }
1023
997
  exports.ListLoadingTracker = ListLoadingTracker;
1024
998
 
1025
999
 
@@ -1036,25 +1010,24 @@ exports.ListLoadingTracker = ListLoadingTracker;
1036
1010
 
1037
1011
  Object.defineProperty(exports, "__esModule", { value: true });
1038
1012
  exports.Loader = void 0;
1039
- var Loader = /** @class */ (function () {
1040
- function Loader(dbRef, getTracker, options) {
1041
- var _this = this;
1013
+ class Loader {
1014
+ constructor(dbRef, getTracker, options) {
1042
1015
  this.dbRef = dbRef;
1043
1016
  this.getTracker = getTracker;
1044
1017
  this.options = options;
1045
1018
  this.currentRequests = new Set();
1046
- this.load = function (inputRequest) {
1047
- var result = {
1048
- isComplete: _this.loaded.diff(inputRequest) == null,
1019
+ this.load = (inputRequest) => {
1020
+ const result = {
1021
+ isComplete: this.loaded.diff(inputRequest) == null,
1049
1022
  isLoading: false,
1050
1023
  request: inputRequest,
1051
- missing: _this.loadedAndLoading.diff(inputRequest),
1024
+ missing: this.loadedAndLoading.diff(inputRequest),
1052
1025
  promise: null,
1053
1026
  reload: null,
1054
1027
  };
1055
- result.reload = function () {
1028
+ result.reload = () => {
1056
1029
  result.missing = inputRequest;
1057
- _this.loadImpl(result);
1030
+ this.loadImpl(result);
1058
1031
  };
1059
1032
  if (result.isComplete) {
1060
1033
  // Everything requested is already loaded
@@ -1070,12 +1043,12 @@ var Loader = /** @class */ (function () {
1070
1043
  result.isLoading = true;
1071
1044
  // There's no good way to tell which of current requests is querying requested data - there actually can be 2 of them.
1072
1045
  // So we track all running requests, and await all of them in such case.
1073
- result.promise = Promise.all(_this.currentRequests.entries()).then(function () { });
1046
+ result.promise = Promise.all(this.currentRequests.entries()).then(() => { });
1074
1047
  return result;
1075
1048
  }
1076
1049
  else {
1077
1050
  // Something requested is not loaded, nor being loaded. Need to perform a new request.
1078
- _this.loadImpl(result);
1051
+ this.loadImpl(result);
1079
1052
  return result;
1080
1053
  }
1081
1054
  }
@@ -1083,33 +1056,31 @@ var Loader = /** @class */ (function () {
1083
1056
  this.loaded = getTracker();
1084
1057
  this.loadedAndLoading = getTracker();
1085
1058
  }
1086
- Loader.prototype.loadImpl = function (state) {
1087
- var _this = this;
1059
+ loadImpl(state) {
1088
1060
  this.loadedAndLoading.append(state.missing);
1089
1061
  state.isLoading = true;
1090
- var serverRequest = state.missing;
1062
+ let serverRequest = state.missing;
1091
1063
  if (this.options.clientToServerRequest) {
1092
1064
  serverRequest = this.options.clientToServerRequest(serverRequest);
1093
1065
  }
1094
- state.promise = this.options.api(serverRequest).then(function (result) {
1095
- _this.loaded.append(state.missing, result);
1096
- _this.loadedAndLoading.append(state.missing, result);
1066
+ state.promise = this.options.api(serverRequest).then(result => {
1067
+ this.loaded.append(state.missing, result);
1068
+ this.loadedAndLoading.append(state.missing, result);
1097
1069
  state.missing = null;
1098
1070
  state.isLoading = false;
1099
1071
  state.isComplete = true;
1100
1072
  state.promise = Promise.resolve();
1101
- var flatten = _this.options.convertToPatch(result);
1102
- _this.options.postProcess && _this.options.postProcess(flatten);
1103
- _this.dbRef.commitFetch(flatten);
1073
+ const flatten = this.options.convertToPatch(result);
1074
+ this.options.postProcess && this.options.postProcess(flatten);
1075
+ this.dbRef.commitFetch(flatten);
1104
1076
  });
1105
1077
  this.currentRequests.add(state.promise);
1106
- state.promise.finally(function () {
1107
- _this.currentRequests.delete(state.promise);
1078
+ state.promise.finally(() => {
1079
+ this.currentRequests.delete(state.promise);
1108
1080
  });
1109
1081
  return state.promise;
1110
- };
1111
- return Loader;
1112
- }());
1082
+ }
1083
+ }
1113
1084
  exports.Loader = Loader;
1114
1085
 
1115
1086
 
@@ -1126,21 +1097,20 @@ exports.Loader = Loader;
1126
1097
 
1127
1098
  Object.defineProperty(exports, "__esModule", { value: true });
1128
1099
  exports.SimpleLoadingTracker = void 0;
1129
- var SimpleLoadingTracker = /** @class */ (function () {
1130
- function SimpleLoadingTracker() {
1100
+ class SimpleLoadingTracker {
1101
+ constructor() {
1131
1102
  this.set = new Set();
1132
1103
  }
1133
- SimpleLoadingTracker.prototype.getKey = function (request) {
1104
+ getKey(request) {
1134
1105
  return JSON.stringify(request);
1135
- };
1136
- SimpleLoadingTracker.prototype.diff = function (request) {
1106
+ }
1107
+ diff(request) {
1137
1108
  return this.set.has(this.getKey(request)) ? null : request;
1138
- };
1139
- SimpleLoadingTracker.prototype.append = function (request, result) {
1109
+ }
1110
+ append(request, result) {
1140
1111
  this.set.add(this.getKey(request));
1141
- };
1142
- return SimpleLoadingTracker;
1143
- }());
1112
+ }
1113
+ }
1144
1114
  exports.SimpleLoadingTracker = SimpleLoadingTracker;
1145
1115
 
1146
1116
 
@@ -1156,7 +1126,7 @@ exports.SimpleLoadingTracker = SimpleLoadingTracker;
1156
1126
  "use strict";
1157
1127
 
1158
1128
  Object.defineProperty(exports, "__esModule", { value: true });
1159
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1129
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1160
1130
  (0, tslib_1.__exportStar)(__webpack_require__(/*! ./types */ "./src/types.ts"), exports);
1161
1131
  (0, tslib_1.__exportStar)(__webpack_require__(/*! ./Db */ "./src/Db.ts"), exports);
1162
1132
  (0, tslib_1.__exportStar)(__webpack_require__(/*! ./DbTable */ "./src/DbTable.ts"), exports);
@@ -1180,42 +1150,38 @@ var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.
1180
1150
 
1181
1151
  Object.defineProperty(exports, "__esModule", { value: true });
1182
1152
  exports.getEntityParentDependencies = exports.getParentEntities = exports.hasServerFields = exports.isNew = exports.getId = exports.isClientOnly = exports.makeCumulativePatch = exports.isPatchBlank = exports.flattenResponse = exports.mergeEntityPatches = exports.unionPatches = void 0;
1183
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1184
- var types_1 = __webpack_require__(/*! ./types */ "./src/types.ts");
1185
- var I = (0, tslib_1.__importStar)(__webpack_require__(/*! immutable */ "immutable"));
1186
- var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
1187
- var lodash_groupby_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.groupby */ "lodash.groupby"));
1188
- var lodash_map_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.map */ "lodash.map"));
1189
- var lodash_merge_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.merge */ "lodash.merge"));
1190
- var lodash_countby_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.countby */ "lodash.countby"));
1191
- var lodash_filter_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.filter */ "lodash.filter"));
1192
- var lodash_foreach_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.foreach */ "lodash.foreach"));
1193
- var lodash_pick_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.pick */ "lodash.pick"));
1153
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1154
+ const types_1 = __webpack_require__(/*! ./types */ "./src/types.ts");
1155
+ const I = (0, tslib_1.__importStar)(__webpack_require__(/*! immutable */ "immutable"));
1156
+ const utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
1157
+ const lodash_groupby_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.groupby */ "lodash.groupby"));
1158
+ const lodash_map_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.map */ "lodash.map"));
1159
+ const lodash_merge_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.merge */ "lodash.merge"));
1160
+ const lodash_countby_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.countby */ "lodash.countby"));
1161
+ const lodash_filter_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.filter */ "lodash.filter"));
1162
+ const lodash_foreach_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.foreach */ "lodash.foreach"));
1163
+ const lodash_pick_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.pick */ "lodash.pick"));
1194
1164
  function unionPatches(patches) {
1195
- var result = {};
1196
- patches.forEach(function (patch) {
1197
- (0, utils_1.objectKeys)(patch).forEach(function (tableName) {
1198
- result[tableName] = result[tableName] ? (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], result[tableName], true), patch[tableName], true) : patch[tableName];
1165
+ const result = {};
1166
+ patches.forEach(patch => {
1167
+ (0, utils_1.objectKeys)(patch).forEach(tableName => {
1168
+ result[tableName] = result[tableName] ? [...result[tableName], ...patch[tableName]] : patch[tableName];
1199
1169
  });
1200
1170
  });
1201
1171
  return result;
1202
1172
  }
1203
1173
  exports.unionPatches = unionPatches;
1204
1174
  function mergeEntityPatches(tables, patch) {
1205
- var result = {};
1206
- (0, utils_1.objectKeys)(patch).forEach(function (key) {
1207
- var table = tables[key];
1208
- var groupedEntities = (0, lodash_groupby_1.default)(patch[key], function (item) { return table.getId(item); });
1209
- var tablePatch = (0, lodash_map_1.default)(groupedEntities, function (entities) {
1210
- var result = lodash_merge_1.default.apply(void 0, (0, tslib_1.__spreadArray)([{}], entities, false));
1175
+ const result = {};
1176
+ (0, utils_1.objectKeys)(patch).forEach(key => {
1177
+ const table = tables[key];
1178
+ const groupedEntities = (0, lodash_groupby_1.default)(patch[key], item => table.getId(item));
1179
+ const tablePatch = (0, lodash_map_1.default)(groupedEntities, entities => {
1180
+ const result = (0, lodash_merge_1.default)({}, ...entities);
1211
1181
  if (true) {
1212
- var props = (0, utils_1.objectKeys)(result).filter(function (prop) {
1213
- return Object.keys((0, lodash_countby_1.default)(entities.filter(function (entity) {
1214
- return entity[prop] !== undefined;
1215
- }), function (entity) { return entity[prop]; })).length > 1;
1216
- });
1182
+ const props = (0, utils_1.objectKeys)(result).filter(prop => Object.keys((0, lodash_countby_1.default)(entities.filter(entity => entity[prop] !== undefined), entity => entity[prop])).length > 1);
1217
1183
  if (props.length) {
1218
- console.warn.apply(console, (0, tslib_1.__spreadArray)(['mergeEntityPatches: Different property values found for the same entity.\nProperty names:\n', props, '\nEntities:\n'], entities, false));
1184
+ console.warn('mergeEntityPatches: Different property values found for the same entity.\nProperty names:\n', props, '\nEntities:\n', ...entities);
1219
1185
  }
1220
1186
  }
1221
1187
  return result;
@@ -1227,26 +1193,26 @@ function mergeEntityPatches(tables, patch) {
1227
1193
  exports.mergeEntityPatches = mergeEntityPatches;
1228
1194
  function flattenResponseHelper(result, object, tablesByTypeName) {
1229
1195
  if (Array.isArray(object)) {
1230
- object.forEach(function (item) { return flattenResponseHelper(result, item, tablesByTypeName); });
1196
+ object.forEach(item => flattenResponseHelper(result, item, tablesByTypeName));
1231
1197
  }
1232
1198
  else if (typeof object === 'object') {
1233
- var clone = {};
1234
- var tableKey = void 0;
1235
- var fields = {};
1199
+ const clone = {};
1200
+ let tableKey;
1201
+ let fields = {};
1236
1202
  if ('__typename' in object) {
1237
- var table = tablesByTypeName[object.__typename];
1203
+ const table = tablesByTypeName[object.__typename];
1238
1204
  if (table) {
1239
1205
  tableKey = table.schema.tableName;
1240
1206
  fields = table.schema.fields;
1241
1207
  }
1242
1208
  }
1243
- for (var key in object) {
1244
- var value = object[key];
1245
- var field = fields[key];
1209
+ for (let key in object) {
1210
+ const value = object[key];
1211
+ const field = fields[key];
1246
1212
  if ((field && !!field.disableFlatten)
1247
1213
  || typeof value !== 'object'
1248
1214
  || value === null
1249
- || (Array.isArray(value) && value.every(function (item) { return typeof item !== 'object'; }))) {
1215
+ || (Array.isArray(value) && value.every(item => typeof item !== 'object'))) {
1250
1216
  clone[key] = value;
1251
1217
  }
1252
1218
  else {
@@ -1259,35 +1225,35 @@ function flattenResponseHelper(result, object, tablesByTypeName) {
1259
1225
  }
1260
1226
  }
1261
1227
  function flattenResponse(response, tables) {
1262
- var result = {};
1263
- var tablesByTypeName = {};
1264
- Object.values(tables).forEach(function (table) { return tablesByTypeName[table.schema.typeName] = table; });
1265
- (0, utils_1.objectKeys)(tables).forEach(function (tableName) { return tablesByTypeName; });
1266
- (0, utils_1.objectKeys)(tables).forEach(function (key) { return result[key] = []; });
1228
+ const result = {};
1229
+ let tablesByTypeName = {};
1230
+ Object.values(tables).forEach(table => tablesByTypeName[table.schema.typeName] = table);
1231
+ (0, utils_1.objectKeys)(tables).forEach(tableName => tablesByTypeName);
1232
+ (0, utils_1.objectKeys)(tables).forEach(key => result[key] = []);
1267
1233
  flattenResponseHelper(result, response, tablesByTypeName);
1268
1234
  return result;
1269
1235
  }
1270
1236
  exports.flattenResponse = flattenResponse;
1271
1237
  function isPatchBlank(patch) {
1272
- return !(0, utils_1.objectKeys)(patch).some(function (key) { return patch[key].length > 0; });
1238
+ return !(0, utils_1.objectKeys)(patch).some(key => patch[key].length > 0);
1273
1239
  }
1274
1240
  exports.isPatchBlank = isPatchBlank;
1275
1241
  /**
1276
1242
  * Given several patches, creates a new single patch with all fields from all entities in all patches.
1277
1243
  */
1278
1244
  function makeCumulativePatch(updatedDb, patches, clientIdsMap) {
1279
- var result = {};
1280
- (0, utils_1.objectKeys)(updatedDb.tables).forEach(function (entityName) {
1281
- var table = updatedDb.tables[entityName];
1282
- var schema = table.schema;
1283
- var ids = I.Set();
1284
- patches.forEach(function (patch) {
1285
- var filteredPatch = (patch[entityName] || []).filter(function (entity) { return hasServerFields(entity, schema, clientIdsMap, updatedDb.tables); });
1286
- ids = ids.union(filteredPatch.map(function (e) { return table.getId(e); }));
1245
+ const result = {};
1246
+ (0, utils_1.objectKeys)(updatedDb.tables).forEach(entityName => {
1247
+ const table = updatedDb.tables[entityName];
1248
+ const schema = table.schema;
1249
+ let ids = I.Set();
1250
+ patches.forEach(patch => {
1251
+ let filteredPatch = (patch[entityName] || []).filter(entity => hasServerFields(entity, schema, clientIdsMap, updatedDb.tables));
1252
+ ids = ids.union(filteredPatch.map(e => table.getId(e)));
1287
1253
  });
1288
- var entities = ids
1289
- .map(function (id) { return table.byId(id); })
1290
- .filter(function (e) { return !isClientOnly(e, schema); })
1254
+ const entities = ids
1255
+ .map(id => table.byId(id))
1256
+ .filter(e => !isClientOnly(e, schema))
1291
1257
  .toArray();
1292
1258
  if (entities.length > 0) {
1293
1259
  result[entityName] = entities;
@@ -1307,43 +1273,43 @@ function getId(entity, schema) {
1307
1273
  if (typeof schema.primaryKey == 'string') {
1308
1274
  return entity[schema.primaryKey];
1309
1275
  }
1310
- var result = [];
1311
- (0, lodash_foreach_1.default)((0, lodash_pick_1.default)(entity, schema.primaryKey), function (value) {
1276
+ const result = [];
1277
+ (0, lodash_foreach_1.default)((0, lodash_pick_1.default)(entity, schema.primaryKey), (value) => {
1312
1278
  result.push(value);
1313
1279
  });
1314
1280
  return result;
1315
1281
  }
1316
1282
  exports.getId = getId;
1317
1283
  function isNew(entity, schema, clientIdsMap) {
1318
- var id = getId(entity, schema);
1284
+ const id = getId(entity, schema);
1319
1285
  return !clientIdsMap.clientToServer(id);
1320
1286
  }
1321
1287
  exports.isNew = isNew;
1322
1288
  function hasServerFields(entity, schema, clientIdsMap, tables) {
1323
- var fullEntity = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, tables[schema.tableName].byId(entity.id) || {}), entity);
1289
+ const fullEntity = Object.assign(Object.assign({}, tables[schema.tableName].byId(entity.id) || {}), entity);
1324
1290
  if (isClientOnly(fullEntity, schema)) {
1325
1291
  return false;
1326
1292
  }
1327
- return (0, utils_1.objectKeys)(entity).some(function (fieldName) {
1328
- var fieldSchema = schema.fields[fieldName];
1293
+ return (0, utils_1.objectKeys)(entity).some(fieldName => {
1294
+ const fieldSchema = schema.fields[fieldName];
1329
1295
  return !fieldSchema || !(fieldSchema.isClientOnly || fieldSchema.isReadOnly || (fieldSchema.isGenerated && !isNew(entity, schema, clientIdsMap)));
1330
1296
  });
1331
1297
  }
1332
1298
  exports.hasServerFields = hasServerFields;
1333
1299
  function getParentEntities(patch, tables) {
1334
- var dependenciesPatch = {};
1335
- (0, utils_1.objectKeys)(patch).forEach(function (key) {
1336
- var table = tables[key];
1337
- var tableSchema = table.schema;
1338
- var fields = (0, lodash_filter_1.default)((0, lodash_map_1.default)(tableSchema.fields, function (field, name) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, field), { name: name })); }), function (field) { return field.fk && field.fk.relationType == types_1.DbRelationType.Aggregation; });
1339
- var tablePatch = patch[key];
1340
- fields.forEach(function (field) {
1341
- var tableName = field.fk.tableName, name = field.name;
1342
- tablePatch.forEach(function (entity) {
1343
- var actualTableName = (typeof tableName == 'function' ? tableName(entity) : tableName);
1344
- var dbEntity = table.byId(table.getId(entity));
1345
- var parentEntity = tables[actualTableName].byId(dbEntity[name]);
1346
- var idFields = (0, lodash_pick_1.default)(parentEntity, tables[actualTableName].schema.primaryKey);
1300
+ const dependenciesPatch = {};
1301
+ (0, utils_1.objectKeys)(patch).forEach(key => {
1302
+ const table = tables[key];
1303
+ const tableSchema = table.schema;
1304
+ const fields = (0, lodash_filter_1.default)((0, lodash_map_1.default)(tableSchema.fields, (field, name) => (Object.assign(Object.assign({}, field), { name }))), field => field.fk && field.fk.relationType == types_1.DbRelationType.Aggregation);
1305
+ const tablePatch = patch[key];
1306
+ fields.forEach(field => {
1307
+ const { fk: { tableName }, name } = field;
1308
+ tablePatch.forEach(entity => {
1309
+ const actualTableName = (typeof tableName == 'function' ? tableName(entity) : tableName);
1310
+ const dbEntity = table.byId(table.getId(entity));
1311
+ const parentEntity = tables[actualTableName].byId(dbEntity[name]);
1312
+ const idFields = (0, lodash_pick_1.default)(parentEntity, tables[actualTableName].schema.primaryKey);
1347
1313
  if (parentEntity) {
1348
1314
  dependenciesPatch[actualTableName] = dependenciesPatch[actualTableName] || [];
1349
1315
  dependenciesPatch[actualTableName].push(idFields);
@@ -1355,18 +1321,17 @@ function getParentEntities(patch, tables) {
1355
1321
  }
1356
1322
  exports.getParentEntities = getParentEntities;
1357
1323
  function getEntityParentDependencies(entity, entityName, tables) {
1358
- var _a;
1359
- var patch = (_a = {}, _a[entityName] = [entity], _a);
1360
- var resultPatches = [];
1324
+ let patch = { [entityName]: [entity] };
1325
+ const resultPatches = [];
1361
1326
  while (true) {
1362
- var parents = getParentEntities(patch, tables);
1327
+ let parents = getParentEntities(patch, tables);
1363
1328
  if (isPatchBlank(parents)) {
1364
1329
  break;
1365
1330
  }
1366
1331
  resultPatches.push(parents);
1367
1332
  patch = parents;
1368
1333
  }
1369
- var result = unionPatches((0, tslib_1.__spreadArray)([patch], resultPatches, true));
1334
+ let result = unionPatches([patch, ...resultPatches]);
1370
1335
  result = mergeEntityPatches(tables, result);
1371
1336
  return result;
1372
1337
  }
@@ -1386,20 +1351,19 @@ exports.getEntityParentDependencies = getEntityParentDependencies;
1386
1351
 
1387
1352
  Object.defineProperty(exports, "__esModule", { value: true });
1388
1353
  exports.useDbView = exports.useDbRef = exports.DbContext = void 0;
1389
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1390
- var react_1 = __webpack_require__(/*! react */ "react");
1354
+ const react_1 = __webpack_require__(/*! react */ "react");
1391
1355
  exports.DbContext = (0, react_1.createContext)(null);
1392
1356
  function useDbRef() {
1393
1357
  return (0, react_1.useContext)(exports.DbContext);
1394
1358
  }
1395
1359
  exports.useDbRef = useDbRef;
1396
1360
  function useDbView(fn, params, options) {
1397
- var dbRef = useDbRef();
1398
- var _a = (0, react_1.useState)(), state = _a[0], setState = _a[1];
1399
- var subscription = (0, react_1.useMemo)(function () { return dbRef.subscribe((0, tslib_1.__assign)({ compute: fn }, options), params, setState); }, []);
1361
+ const dbRef = useDbRef();
1362
+ const [state, setState] = (0, react_1.useState)();
1363
+ const subscription = (0, react_1.useMemo)(() => dbRef.subscribe(Object.assign({ compute: fn }, options), params, setState), []);
1400
1364
  subscription.update(params);
1401
- (0, react_1.useEffect)(function () {
1402
- return function () { return subscription.unsubscribe(); };
1365
+ (0, react_1.useEffect)(() => {
1366
+ return () => subscription.unsubscribe();
1403
1367
  }, []);
1404
1368
  return subscription.currentValue;
1405
1369
  }
@@ -1419,9 +1383,8 @@ exports.useDbView = useDbView;
1419
1383
 
1420
1384
  Object.defineProperty(exports, "__esModule", { value: true });
1421
1385
  exports.TempIdMap = exports.isTempId = exports.getTempId = void 0;
1422
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1423
- var utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
1424
- var lastTempId = -1;
1386
+ const utils_1 = __webpack_require__(/*! ./utils */ "./src/utils.ts");
1387
+ let lastTempId = -1;
1425
1388
  function getTempId() {
1426
1389
  return --lastTempId;
1427
1390
  }
@@ -1430,28 +1393,27 @@ function isTempId(val) {
1430
1393
  return typeof val === 'number' && val < 0;
1431
1394
  }
1432
1395
  exports.isTempId = isTempId;
1433
- var TempIdMap = /** @class */ (function () {
1434
- function TempIdMap(db) {
1435
- var _this = this;
1396
+ class TempIdMap {
1397
+ constructor(db) {
1436
1398
  this.db = db;
1437
1399
  this.serverToClientIds = new Map();
1438
1400
  this.clientToServerIds = new Map();
1439
- this.clientToServer = function (id) { return _this.clientToServerIds.get(id); };
1440
- this.serverToClient = function (tableName, id) { return _this.getServerToClientMap(tableName).get(id); };
1441
- this.clientToServerRequest = function (request) {
1442
- request = (0, tslib_1.__assign)({}, request);
1401
+ this.clientToServer = (id) => this.clientToServerIds.get(id);
1402
+ this.serverToClient = (tableName, id) => this.getServerToClientMap(tableName).get(id);
1403
+ this.clientToServerRequest = (request) => {
1404
+ request = Object.assign({}, request);
1443
1405
  if (request.filter) {
1444
- request.filter = _this.clientToServerDataFilter(request.filter);
1406
+ request.filter = this.clientToServerDataFilter(request.filter);
1445
1407
  }
1446
1408
  return request;
1447
1409
  };
1448
- this.clientToServerDataFilter = function (filter) {
1449
- filter = (0, tslib_1.__assign)({}, filter);
1450
- var keys = Object.keys(filter);
1410
+ this.clientToServerDataFilter = (filter) => {
1411
+ filter = Object.assign({}, filter);
1412
+ const keys = Object.keys(filter);
1451
1413
  // I hope that we can rely that there won't be any negative numbers, which are not IDs, in queries.
1452
1414
  // We need to invent better heuristics or a schema otherwise.
1453
- var clientToServer = function (id) {
1454
- var found = _this.clientToServer(id);
1415
+ const clientToServer = (id) => {
1416
+ const found = this.clientToServer(id);
1455
1417
  if (found) {
1456
1418
  return found;
1457
1419
  }
@@ -1459,11 +1421,11 @@ var TempIdMap = /** @class */ (function () {
1459
1421
  return id;
1460
1422
  }
1461
1423
  };
1462
- for (var n = 0; n < keys.length; n++) {
1463
- var key = keys[n];
1464
- var condition = filter[key];
1424
+ for (let n = 0; n < keys.length; n++) {
1425
+ const key = keys[n];
1426
+ let condition = filter[key];
1465
1427
  if (condition != null && typeof condition === "object") {
1466
- condition = (0, tslib_1.__assign)({}, condition);
1428
+ condition = Object.assign({}, condition);
1467
1429
  if ('in' in condition && Array.isArray(condition.in) && condition.in.length) {
1468
1430
  condition.in = condition.in.map(clientToServer);
1469
1431
  }
@@ -1476,76 +1438,74 @@ var TempIdMap = /** @class */ (function () {
1476
1438
  return filter;
1477
1439
  };
1478
1440
  }
1479
- TempIdMap.prototype.copyPatch = function (patch) {
1480
- var newPatch = (0, tslib_1.__assign)({}, patch);
1481
- (0, utils_1.objectKeys)(patch).forEach(function (tableName) {
1482
- var tablePatch = patch[tableName].map(function (entityPatch) { return ((0, tslib_1.__assign)({}, entityPatch)); });
1441
+ copyPatch(patch) {
1442
+ const newPatch = Object.assign({}, patch);
1443
+ (0, utils_1.objectKeys)(patch).forEach(tableName => {
1444
+ let tablePatch = patch[tableName].map(entityPatch => (Object.assign({}, entityPatch)));
1483
1445
  newPatch[tableName] = tablePatch;
1484
1446
  });
1485
1447
  return newPatch;
1486
- };
1448
+ }
1487
1449
  // Iterate thru every field in every patch for every table, matching certain field criteria. The patch is mutated!
1488
- TempIdMap.prototype.mapFields = function (patch, filter, callback) {
1489
- var _this = this;
1490
- (0, utils_1.objectKeys)(patch).forEach(function (tableName) {
1491
- var schema = _this.db.tables[tableName].schema;
1492
- var fields = (0, utils_1.objectKeys)(schema.fields || [])
1493
- .map(function (fieldName) {
1494
- var fieldSchema = schema.fields[fieldName];
1450
+ mapFields(patch, filter, callback) {
1451
+ (0, utils_1.objectKeys)(patch).forEach(tableName => {
1452
+ const schema = this.db.tables[tableName].schema;
1453
+ const fields = (0, utils_1.objectKeys)(schema.fields || [])
1454
+ .map(fieldName => {
1455
+ const fieldSchema = schema.fields[fieldName];
1495
1456
  if (filter(fieldSchema, fieldName)) {
1496
1457
  return { name: fieldName, schema: fieldSchema };
1497
1458
  }
1498
1459
  })
1499
- .filter(function (f) { return !!f; });
1460
+ .filter(f => !!f);
1500
1461
  if (!fields.length) {
1501
1462
  return;
1502
1463
  }
1503
- patch[tableName].forEach(function (entityPatch) {
1504
- for (var n = 0; n < fields.length; n++) {
1505
- var field = fields[n];
1506
- var fieldValue = entityPatch[field.name];
1464
+ patch[tableName].forEach(entityPatch => {
1465
+ for (let n = 0; n < fields.length; n++) {
1466
+ const field = fields[n];
1467
+ const fieldValue = entityPatch[field.name];
1507
1468
  callback(field.name, field.schema, fieldValue, entityPatch, tableName);
1508
1469
  }
1509
1470
  });
1510
1471
  });
1511
- };
1512
- TempIdMap.prototype.getServerToClientMap = function (tableName) {
1513
- var existing = this.serverToClientIds.get(tableName);
1472
+ }
1473
+ getServerToClientMap(tableName) {
1474
+ const existing = this.serverToClientIds.get(tableName);
1514
1475
  if (existing) {
1515
1476
  return existing;
1516
1477
  }
1517
1478
  else {
1518
- var newMap = new Map();
1479
+ const newMap = new Map();
1519
1480
  this.serverToClientIds.set(tableName, newMap);
1520
1481
  return newMap;
1521
1482
  }
1522
- };
1523
- TempIdMap.prototype.serverToClientPatch = function (patch) {
1524
- var _this = this;
1483
+ }
1484
+ serverToClientPatch(patch) {
1525
1485
  patch = this.copyPatch(patch);
1526
1486
  // We map PK in a separate pass, as we need to remap all PKs before re-mapping FKs
1527
- this.mapFields(patch, function (f) { return f.isGenerated; }, function (fieldName, fieldSchema, fieldValue, entityPatch, tableName) {
1528
- var clientId = _this.getServerToClientMap(tableName).get(fieldValue);
1487
+ this.mapFields(patch, f => f.isGenerated, (fieldName, fieldSchema, fieldValue, entityPatch, tableName) => {
1488
+ let clientId = this.getServerToClientMap(tableName).get(fieldValue);
1529
1489
  if (!clientId) {
1530
1490
  clientId = getTempId();
1531
- _this.clientToServerIds.set(clientId, fieldValue);
1532
- _this.getServerToClientMap(tableName).set(fieldValue, clientId);
1491
+ this.clientToServerIds.set(clientId, fieldValue);
1492
+ this.getServerToClientMap(tableName).set(fieldValue, clientId);
1533
1493
  }
1534
1494
  entityPatch[fieldName] = clientId;
1535
1495
  });
1536
- this.mapFields(patch, function (f) { return !!(f.fk || (f.default != null) || f.toClient); }, function (fieldName, fieldSchema, fieldValue, entityPatch, tableName) {
1537
- var isUndefined = typeof (fieldValue) === 'undefined';
1496
+ this.mapFields(patch, f => !!(f.fk || (f.default != null) || f.toClient), (fieldName, fieldSchema, fieldValue, entityPatch, tableName) => {
1497
+ let isUndefined = typeof (fieldValue) === 'undefined';
1538
1498
  if (fieldSchema.default != null && fieldValue == null) {
1539
1499
  fieldValue = fieldSchema.default;
1540
1500
  isUndefined = false;
1541
1501
  }
1542
1502
  if (fieldSchema.fk && fieldValue != null) {
1543
- var fkTableName = typeof fieldSchema.fk.tableName === 'function' ? fieldSchema.fk.tableName(entityPatch) : fieldSchema.fk.tableName;
1544
- var clientId = _this.getServerToClientMap(fkTableName).get(fieldValue);
1503
+ const fkTableName = typeof fieldSchema.fk.tableName === 'function' ? fieldSchema.fk.tableName(entityPatch) : fieldSchema.fk.tableName;
1504
+ let clientId = this.getServerToClientMap(fkTableName).get(fieldValue);
1545
1505
  if (!clientId) {
1546
1506
  clientId = getTempId();
1547
- _this.clientToServerIds.set(clientId, fieldValue);
1548
- _this.getServerToClientMap(fkTableName).set(fieldValue, clientId);
1507
+ this.clientToServerIds.set(clientId, fieldValue);
1508
+ this.getServerToClientMap(fkTableName).set(fieldValue, clientId);
1549
1509
  }
1550
1510
  fieldValue = clientId;
1551
1511
  }
@@ -1557,48 +1517,45 @@ var TempIdMap = /** @class */ (function () {
1557
1517
  }
1558
1518
  });
1559
1519
  return patch;
1560
- };
1561
- TempIdMap.prototype.clientToServerPatch = function (patch) {
1562
- var _this = this;
1520
+ }
1521
+ clientToServerPatch(patch) {
1563
1522
  patch = this.copyPatch(patch);
1564
- this.mapFields(patch, function (f) { return f.isGenerated || !!f.fk; }, function (fieldName, fieldSchema, fieldValue, entityPatch, tableName) {
1523
+ this.mapFields(patch, f => f.isGenerated || !!f.fk, (fieldName, fieldSchema, fieldValue, entityPatch, tableName) => {
1565
1524
  if (fieldValue != null) {
1566
- var existingId = _this.clientToServerIds.get(fieldValue);
1525
+ const existingId = this.clientToServerIds.get(fieldValue);
1567
1526
  if (existingId) {
1568
1527
  entityPatch[fieldName] = existingId;
1569
1528
  }
1570
1529
  }
1571
1530
  });
1572
- this.mapFields(patch, function (f) { return !(f.isClientOnly || f.isReadOnly) && !!f.toServer; }, function (fieldName, fieldSchema, fieldValue, entityPatch, tableName) {
1531
+ this.mapFields(patch, f => !(f.isClientOnly || f.isReadOnly) && !!f.toServer, (fieldName, fieldSchema, fieldValue, entityPatch, tableName) => {
1573
1532
  entityPatch[fieldName] = fieldSchema.toServer(entityPatch[fieldName]);
1574
1533
  });
1575
- this.mapFields(patch, function (meta) { return meta.isClientOnly || meta.isReadOnly; }, function (fieldName, fieldSchema, fieldValue, entityPatch, tableName) {
1534
+ this.mapFields(patch, meta => meta.isClientOnly || meta.isReadOnly, (fieldName, fieldSchema, fieldValue, entityPatch, tableName) => {
1576
1535
  delete entityPatch[fieldName];
1577
1536
  });
1578
1537
  return patch;
1579
- };
1580
- TempIdMap.prototype.appendServerMapping = function (response) {
1581
- var _this = this;
1582
- (0, utils_1.objectKeys)(response.submit).forEach(function (tableName) {
1583
- if (_this.db.tables[tableName]) {
1584
- var tablePatch = response.submit[tableName];
1538
+ }
1539
+ appendServerMapping(response) {
1540
+ (0, utils_1.objectKeys)(response.submit).forEach(tableName => {
1541
+ if (this.db.tables[tableName]) {
1542
+ const tablePatch = response.submit[tableName];
1585
1543
  if (tablePatch) {
1586
- var serverToClientIds_1 = _this.getServerToClientMap(tableName);
1587
- var table_1 = _this.db.tables[tableName];
1588
- tablePatch.forEach(function (patch) {
1544
+ const serverToClientIds = this.getServerToClientMap(tableName);
1545
+ const table = this.db.tables[tableName];
1546
+ tablePatch.forEach(patch => {
1589
1547
  if (isTempId(patch.id)) {
1590
- var clientId = patch.id;
1591
- var serverId = table_1.getId(patch.payload);
1592
- serverToClientIds_1.set(serverId, clientId);
1593
- _this.clientToServerIds.set(clientId, serverId);
1548
+ const clientId = patch.id;
1549
+ const serverId = table.getId(patch.payload);
1550
+ serverToClientIds.set(serverId, clientId);
1551
+ this.clientToServerIds.set(clientId, serverId);
1594
1552
  }
1595
1553
  });
1596
1554
  }
1597
1555
  }
1598
1556
  });
1599
- };
1600
- return TempIdMap;
1601
- }());
1557
+ }
1558
+ }
1602
1559
  exports.TempIdMap = TempIdMap;
1603
1560
 
1604
1561
 
@@ -1635,20 +1592,17 @@ var DbRelationType;
1635
1592
 
1636
1593
  Object.defineProperty(exports, "__esModule", { value: true });
1637
1594
  exports.difference = exports.defaultCompareViewDependencies = exports.objectKeys = void 0;
1638
- var tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1639
- var shallowequal_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! shallowequal */ "shallowequal"));
1640
- var lodash_zip_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.zip */ "lodash.zip"));
1641
- var lodash_transform_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.transform */ "lodash.transform"));
1642
- var lodash_isequal_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.isequal */ "lodash.isequal"));
1595
+ const tslib_1 = __webpack_require__(/*! tslib */ "../node_modules/tslib/tslib.es6.js");
1596
+ const shallowequal_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! shallowequal */ "shallowequal"));
1597
+ const lodash_zip_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.zip */ "lodash.zip"));
1598
+ const lodash_transform_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.transform */ "lodash.transform"));
1599
+ const lodash_isequal_1 = (0, tslib_1.__importDefault)(__webpack_require__(/*! lodash.isequal */ "lodash.isequal"));
1643
1600
  // TBD: New typescript would contain better typing for this. Remove this hack after update.
1644
1601
  exports.objectKeys = Object.keys;
1645
1602
  function defaultCompareViewDependencies(prev, next) {
1646
1603
  if (Array.isArray(prev) && Array.isArray(next)) {
1647
1604
  if (prev.length === next.length) {
1648
- return (0, lodash_zip_1.default)(prev, next).every(function (_a) {
1649
- var p = _a[0], n = _a[1];
1650
- return (0, shallowequal_1.default)(p, n);
1651
- });
1605
+ return (0, lodash_zip_1.default)(prev, next).every(([p, n]) => (0, shallowequal_1.default)(p, n));
1652
1606
  }
1653
1607
  return false;
1654
1608
  }