@declaro/data 2.0.0-beta.96 → 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.
@@ -11474,9 +11474,8 @@ class MockMemoryRepository {
11474
11474
  if (primaryKeyValue && this.data.has(primaryKeyValue)) {
11475
11475
  throw new Error("Item with the same primary key already exists");
11476
11476
  }
11477
- const payload = {
11478
- ...input
11479
- };
11477
+ const baseData = {};
11478
+ const payload = this.assignInput(baseData, input);
11480
11479
  if (!payload[this.entityMetadata.primaryKey]) {
11481
11480
  payload[this.entityMetadata.primaryKey] = await this.generatePrimaryKey();
11482
11481
  }
@@ -11495,7 +11494,7 @@ class MockMemoryRepository {
11495
11494
  if (!existingItem) {
11496
11495
  throw new Error("Item not found");
11497
11496
  }
11498
- const updatedItem = Object.assign({}, existingItem, input);
11497
+ const updatedItem = this.assignInput(existingItem, input);
11499
11498
  this.data.set(primaryKeyValue, updatedItem);
11500
11499
  return updatedItem;
11501
11500
  }
@@ -11505,11 +11504,11 @@ class MockMemoryRepository {
11505
11504
  }
11506
11505
  async upsert(input, options) {
11507
11506
  const primaryKeyValue = input[this.entityMetadata.primaryKey];
11508
- let existingItem = undefined;
11507
+ let existingItem = {};
11509
11508
  if (primaryKeyValue) {
11510
11509
  existingItem = this.data.get(primaryKeyValue) ?? {};
11511
11510
  }
11512
- const updatedItem = Object.assign({}, existingItem, input);
11511
+ const updatedItem = this.assignInput(existingItem, input);
11513
11512
  if (!updatedItem[this.entityMetadata.primaryKey]) {
11514
11513
  updatedItem[this.entityMetadata.primaryKey] = await this.generatePrimaryKey();
11515
11514
  }
@@ -11528,6 +11527,13 @@ class MockMemoryRepository {
11528
11527
  }
11529
11528
  });
11530
11529
  }
11530
+ assignInput(existingData, input) {
11531
+ if (typeof this.args.assign === "function") {
11532
+ return this.args.assign(existingData, input);
11533
+ } else {
11534
+ return Object.assign({}, existingData, input);
11535
+ }
11536
+ }
11531
11537
  async generatePrimaryKey() {
11532
11538
  const lookupModel = this.args.schema.definition.lookup;
11533
11539
  const lookupMeta = await lookupModel.toJSONSchema();
@@ -11543,5 +11549,5 @@ class MockMemoryRepository {
11543
11549
  }
11544
11550
  }
11545
11551
 
11546
- //# debugId=A7E2932888C3A17164756E2164756E21
11552
+ //# debugId=C76D81F34A7396E664756E2164756E21
11547
11553
  //# sourceMappingURL=index.cjs.map