@declaro/data 2.0.0-beta.98 → 2.0.0-beta.99
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 +7 -7
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.cjs +59 -17
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +59 -17
- package/dist/node/index.js.map +3 -3
- package/dist/ts/test/mock/repositories/mock-memory-repository.assign.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.assign.test.d.ts.map +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.basic.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.basic.test.d.ts.map +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.bulk-upsert.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.bulk-upsert.test.d.ts.map +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.count.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.count.test.d.ts.map +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts.map +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts.map +1 -1
- package/dist/ts/test/mock/repositories/mock-memory-repository.search.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.search.test.d.ts.map +1 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.upsert.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.upsert.test.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/test/mock/repositories/mock-memory-repository.assign.test.ts +215 -0
- package/src/test/mock/repositories/mock-memory-repository.basic.test.ts +129 -0
- package/src/test/mock/repositories/mock-memory-repository.bulk-upsert.test.ts +159 -0
- package/src/test/mock/repositories/mock-memory-repository.count.test.ts +98 -0
- package/src/test/mock/repositories/mock-memory-repository.custom-lookup.test.ts +0 -0
- package/src/test/mock/repositories/mock-memory-repository.search.test.ts +265 -0
- package/src/test/mock/repositories/mock-memory-repository.ts +67 -16
- package/src/test/mock/repositories/mock-memory-repository.upsert.test.ts +108 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.test.d.ts +0 -2
- package/dist/ts/test/mock/repositories/mock-memory-repository.test.d.ts.map +0 -1
- package/src/test/mock/repositories/mock-memory-repository.test.ts +0 -919
package/dist/node/index.cjs
CHANGED
|
@@ -11410,8 +11410,19 @@ class MockMemoryRepository {
|
|
|
11410
11410
|
if (!this.entityMetadata?.primaryKey) {
|
|
11411
11411
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11412
11412
|
}
|
|
11413
|
-
const
|
|
11414
|
-
|
|
11413
|
+
const results = [];
|
|
11414
|
+
for (const input of inputs) {
|
|
11415
|
+
let item;
|
|
11416
|
+
if (typeof this.args.lookup === "function") {
|
|
11417
|
+
item = Array.from(this.data.values()).find((data) => this.args.lookup(data, input));
|
|
11418
|
+
} else {
|
|
11419
|
+
item = this.data.get(input[this.entityMetadata.primaryKey]);
|
|
11420
|
+
}
|
|
11421
|
+
if (item) {
|
|
11422
|
+
results.push(item);
|
|
11423
|
+
}
|
|
11424
|
+
}
|
|
11425
|
+
return results;
|
|
11415
11426
|
}
|
|
11416
11427
|
async search(input, options) {
|
|
11417
11428
|
const pagination = options?.pagination || { page: 1, pageSize: 25 };
|
|
@@ -11453,24 +11464,44 @@ class MockMemoryRepository {
|
|
|
11453
11464
|
if (!this.entityMetadata?.primaryKey) {
|
|
11454
11465
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11455
11466
|
}
|
|
11456
|
-
|
|
11467
|
+
let item;
|
|
11468
|
+
let itemKey;
|
|
11469
|
+
if (typeof this.args.lookup === "function") {
|
|
11470
|
+
item = Array.from(this.data.values()).find((data) => this.args.lookup(data, lookup));
|
|
11471
|
+
if (item) {
|
|
11472
|
+
itemKey = item[this.entityMetadata.primaryKey];
|
|
11473
|
+
}
|
|
11474
|
+
} else {
|
|
11475
|
+
itemKey = lookup[this.entityMetadata.primaryKey];
|
|
11476
|
+
item = this.data.get(itemKey);
|
|
11477
|
+
}
|
|
11457
11478
|
if (!item) {
|
|
11458
11479
|
throw new Error("Item not found");
|
|
11459
11480
|
}
|
|
11460
|
-
this.trash.set(
|
|
11461
|
-
this.data.delete(
|
|
11481
|
+
this.trash.set(itemKey, item);
|
|
11482
|
+
this.data.delete(itemKey);
|
|
11462
11483
|
return item;
|
|
11463
11484
|
}
|
|
11464
11485
|
async restore(lookup) {
|
|
11465
11486
|
if (!this.entityMetadata?.primaryKey) {
|
|
11466
11487
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11467
11488
|
}
|
|
11468
|
-
|
|
11489
|
+
let item;
|
|
11490
|
+
let itemKey;
|
|
11491
|
+
if (typeof this.args.lookup === "function") {
|
|
11492
|
+
item = Array.from(this.trash.values()).find((data) => this.args.lookup(data, lookup));
|
|
11493
|
+
if (item) {
|
|
11494
|
+
itemKey = item[this.entityMetadata.primaryKey];
|
|
11495
|
+
}
|
|
11496
|
+
} else {
|
|
11497
|
+
itemKey = lookup[this.entityMetadata.primaryKey];
|
|
11498
|
+
item = this.trash.get(itemKey);
|
|
11499
|
+
}
|
|
11469
11500
|
if (!item) {
|
|
11470
11501
|
throw new Error("Item not found in trash");
|
|
11471
11502
|
}
|
|
11472
|
-
this.trash.delete(
|
|
11473
|
-
this.data.set(
|
|
11503
|
+
this.trash.delete(itemKey);
|
|
11504
|
+
this.data.set(itemKey, item);
|
|
11474
11505
|
return item;
|
|
11475
11506
|
}
|
|
11476
11507
|
async create(input) {
|
|
@@ -11493,16 +11524,27 @@ class MockMemoryRepository {
|
|
|
11493
11524
|
if (!this.entityMetadata?.primaryKey) {
|
|
11494
11525
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11495
11526
|
}
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11527
|
+
let existingItem;
|
|
11528
|
+
let itemKey;
|
|
11529
|
+
if (typeof this.args.lookup === "function") {
|
|
11530
|
+
existingItem = Array.from(this.data.values()).find((data) => this.args.lookup(data, lookup));
|
|
11531
|
+
if (existingItem) {
|
|
11532
|
+
itemKey = existingItem[this.entityMetadata.primaryKey];
|
|
11533
|
+
} else {
|
|
11534
|
+
throw new Error("Item not found");
|
|
11535
|
+
}
|
|
11536
|
+
} else {
|
|
11537
|
+
itemKey = lookup[this.entityMetadata.primaryKey];
|
|
11538
|
+
if (!itemKey) {
|
|
11539
|
+
throw new Error("Primary key value must be provided");
|
|
11540
|
+
}
|
|
11541
|
+
existingItem = this.data.get(itemKey);
|
|
11542
|
+
if (!existingItem) {
|
|
11543
|
+
throw new Error("Item not found");
|
|
11544
|
+
}
|
|
11503
11545
|
}
|
|
11504
11546
|
const updatedItem = this.assignInput(existingItem, input);
|
|
11505
|
-
this.data.set(
|
|
11547
|
+
this.data.set(itemKey, updatedItem);
|
|
11506
11548
|
return updatedItem;
|
|
11507
11549
|
}
|
|
11508
11550
|
async count(search, options) {
|
|
@@ -11556,5 +11598,5 @@ class MockMemoryRepository {
|
|
|
11556
11598
|
}
|
|
11557
11599
|
}
|
|
11558
11600
|
|
|
11559
|
-
//# debugId=
|
|
11601
|
+
//# debugId=34781135054B25FD64756E2164756E21
|
|
11560
11602
|
//# sourceMappingURL=index.cjs.map
|