@declaro/data 2.0.0-beta.95 → 2.0.0-beta.97

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.
@@ -11435,9 +11435,8 @@ class MockMemoryRepository {
11435
11435
  if (primaryKeyValue && this.data.has(primaryKeyValue)) {
11436
11436
  throw new Error("Item with the same primary key already exists");
11437
11437
  }
11438
- const payload = {
11439
- ...input
11440
- };
11438
+ const baseData = {};
11439
+ const payload = this.assignInput(baseData, input);
11441
11440
  if (!payload[this.entityMetadata.primaryKey]) {
11442
11441
  payload[this.entityMetadata.primaryKey] = await this.generatePrimaryKey();
11443
11442
  }
@@ -11456,7 +11455,7 @@ class MockMemoryRepository {
11456
11455
  if (!existingItem) {
11457
11456
  throw new Error("Item not found");
11458
11457
  }
11459
- const updatedItem = Object.assign({}, existingItem, input);
11458
+ const updatedItem = this.assignInput(existingItem, input);
11460
11459
  this.data.set(primaryKeyValue, updatedItem);
11461
11460
  return updatedItem;
11462
11461
  }
@@ -11466,11 +11465,11 @@ class MockMemoryRepository {
11466
11465
  }
11467
11466
  async upsert(input, options) {
11468
11467
  const primaryKeyValue = input[this.entityMetadata.primaryKey];
11469
- let existingItem = undefined;
11468
+ let existingItem = {};
11470
11469
  if (primaryKeyValue) {
11471
11470
  existingItem = this.data.get(primaryKeyValue) ?? {};
11472
11471
  }
11473
- const updatedItem = Object.assign({}, existingItem, input);
11472
+ const updatedItem = this.assignInput(existingItem, input);
11474
11473
  if (!updatedItem[this.entityMetadata.primaryKey]) {
11475
11474
  updatedItem[this.entityMetadata.primaryKey] = await this.generatePrimaryKey();
11476
11475
  }
@@ -11489,6 +11488,13 @@ class MockMemoryRepository {
11489
11488
  }
11490
11489
  });
11491
11490
  }
11491
+ assignInput(existingData, input) {
11492
+ if (typeof this.args.assign === "function") {
11493
+ return this.args.assign(existingData, input);
11494
+ } else {
11495
+ return Object.assign({}, existingData, input);
11496
+ }
11497
+ }
11492
11498
  async generatePrimaryKey() {
11493
11499
  const lookupModel = this.args.schema.definition.lookup;
11494
11500
  const lookupMeta = await lookupModel.toJSONSchema();
@@ -11522,5 +11528,5 @@ export {
11522
11528
  BaseModelService
11523
11529
  };
11524
11530
 
11525
- //# debugId=B0A3A934FC74BE6964756E2164756E21
11531
+ //# debugId=79EE3AB3B0DB0FAB64756E2164756E21
11526
11532
  //# sourceMappingURL=index.js.map