@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.
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.cjs +13 -7
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +13 -7
- package/dist/node/index.js.map +3 -3
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts +8 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/test/mock/repositories/mock-memory-repository.test.ts +204 -0
- package/src/test/mock/repositories/mock-memory-repository.ts +24 -9
package/dist/node/index.js
CHANGED
|
@@ -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
|
|
11439
|
-
|
|
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 =
|
|
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 =
|
|
11468
|
+
let existingItem = {};
|
|
11470
11469
|
if (primaryKeyValue) {
|
|
11471
11470
|
existingItem = this.data.get(primaryKeyValue) ?? {};
|
|
11472
11471
|
}
|
|
11473
|
-
const updatedItem =
|
|
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=
|
|
11531
|
+
//# debugId=79EE3AB3B0DB0FAB64756E2164756E21
|
|
11526
11532
|
//# sourceMappingURL=index.js.map
|