@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.
Files changed (33) hide show
  1. package/dist/browser/index.js +7 -7
  2. package/dist/browser/index.js.map +3 -3
  3. package/dist/node/index.cjs +59 -17
  4. package/dist/node/index.cjs.map +3 -3
  5. package/dist/node/index.js +59 -17
  6. package/dist/node/index.js.map +3 -3
  7. package/dist/ts/test/mock/repositories/mock-memory-repository.assign.test.d.ts +2 -0
  8. package/dist/ts/test/mock/repositories/mock-memory-repository.assign.test.d.ts.map +1 -0
  9. package/dist/ts/test/mock/repositories/mock-memory-repository.basic.test.d.ts +2 -0
  10. package/dist/ts/test/mock/repositories/mock-memory-repository.basic.test.d.ts.map +1 -0
  11. package/dist/ts/test/mock/repositories/mock-memory-repository.bulk-upsert.test.d.ts +2 -0
  12. package/dist/ts/test/mock/repositories/mock-memory-repository.bulk-upsert.test.d.ts.map +1 -0
  13. package/dist/ts/test/mock/repositories/mock-memory-repository.count.test.d.ts +2 -0
  14. package/dist/ts/test/mock/repositories/mock-memory-repository.count.test.d.ts.map +1 -0
  15. package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts +1 -0
  16. package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts.map +1 -0
  17. package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts.map +1 -1
  18. package/dist/ts/test/mock/repositories/mock-memory-repository.search.test.d.ts +2 -0
  19. package/dist/ts/test/mock/repositories/mock-memory-repository.search.test.d.ts.map +1 -0
  20. package/dist/ts/test/mock/repositories/mock-memory-repository.upsert.test.d.ts +2 -0
  21. package/dist/ts/test/mock/repositories/mock-memory-repository.upsert.test.d.ts.map +1 -0
  22. package/package.json +5 -5
  23. package/src/test/mock/repositories/mock-memory-repository.assign.test.ts +215 -0
  24. package/src/test/mock/repositories/mock-memory-repository.basic.test.ts +129 -0
  25. package/src/test/mock/repositories/mock-memory-repository.bulk-upsert.test.ts +159 -0
  26. package/src/test/mock/repositories/mock-memory-repository.count.test.ts +98 -0
  27. package/src/test/mock/repositories/mock-memory-repository.custom-lookup.test.ts +0 -0
  28. package/src/test/mock/repositories/mock-memory-repository.search.test.ts +265 -0
  29. package/src/test/mock/repositories/mock-memory-repository.ts +67 -16
  30. package/src/test/mock/repositories/mock-memory-repository.upsert.test.ts +108 -0
  31. package/dist/ts/test/mock/repositories/mock-memory-repository.test.d.ts +0 -2
  32. package/dist/ts/test/mock/repositories/mock-memory-repository.test.d.ts.map +0 -1
  33. package/src/test/mock/repositories/mock-memory-repository.test.ts +0 -919
@@ -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 items = await Promise.all(inputs.map((input) => this.data.get(input[this.entityMetadata.primaryKey])));
11414
- return items;
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
- const item = await this.data.get(lookup[this.entityMetadata.primaryKey]);
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(lookup[this.entityMetadata.primaryKey], item);
11461
- this.data.delete(lookup[this.entityMetadata.primaryKey]);
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
- const item = await this.trash.get(lookup[this.entityMetadata.primaryKey]);
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(lookup[this.entityMetadata.primaryKey]);
11473
- this.data.set(lookup[this.entityMetadata.primaryKey], item);
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
- const primaryKeyValue = lookup[this.entityMetadata.primaryKey];
11497
- if (!primaryKeyValue) {
11498
- throw new Error("Primary key value must be provided");
11499
- }
11500
- const existingItem = this.data.get(primaryKeyValue);
11501
- if (!existingItem) {
11502
- throw new Error("Item not found");
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(primaryKeyValue, updatedItem);
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=2ABA230E346B7A7A64756E2164756E21
11601
+ //# debugId=34781135054B25FD64756E2164756E21
11560
11602
  //# sourceMappingURL=index.cjs.map