@declaro/data 2.0.0-beta.97 → 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 +8 -8
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.cjs +78 -29
- package/dist/node/index.cjs.map +4 -4
- package/dist/node/index.js +78 -29
- package/dist/node/index.js.map +4 -4
- package/dist/ts/domain/services/model-service.d.ts +8 -0
- package/dist/ts/domain/services/model-service.d.ts.map +1 -1
- 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/domain/services/model-service.test.ts +245 -0
- package/src/domain/services/model-service.ts +37 -14
- 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
|
@@ -11211,6 +11211,9 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11211
11211
|
constructor(args) {
|
|
11212
11212
|
super(args);
|
|
11213
11213
|
}
|
|
11214
|
+
async normalizeInput(input) {
|
|
11215
|
+
return input;
|
|
11216
|
+
}
|
|
11214
11217
|
async remove(lookup, options) {
|
|
11215
11218
|
const beforeRemoveEvent = new MutationEvent(this.getDescriptor("beforeRemove" /* BeforeRemove */), lookup);
|
|
11216
11219
|
await this.emitter.emitAsync(beforeRemoveEvent);
|
|
@@ -11228,23 +11231,26 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11228
11231
|
return result;
|
|
11229
11232
|
}
|
|
11230
11233
|
async create(input, options) {
|
|
11231
|
-
const
|
|
11234
|
+
const normalizedInput = await this.normalizeInput(input);
|
|
11235
|
+
const beforeCreateEvent = new MutationEvent(this.getDescriptor("beforeCreate" /* BeforeCreate */), normalizedInput);
|
|
11232
11236
|
await this.emitter.emitAsync(beforeCreateEvent);
|
|
11233
|
-
const result = await this.repository.create(
|
|
11234
|
-
const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */),
|
|
11237
|
+
const result = await this.repository.create(normalizedInput, options);
|
|
11238
|
+
const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), normalizedInput).setResult(result);
|
|
11235
11239
|
await this.emitter.emitAsync(afterCreateEvent);
|
|
11236
11240
|
return result;
|
|
11237
11241
|
}
|
|
11238
11242
|
async update(lookup, input, options) {
|
|
11239
|
-
const
|
|
11243
|
+
const normalizedInput = await this.normalizeInput(input);
|
|
11244
|
+
const beforeUpdateEvent = new MutationEvent(this.getDescriptor("beforeUpdate" /* BeforeUpdate */), normalizedInput);
|
|
11240
11245
|
await this.emitter.emitAsync(beforeUpdateEvent);
|
|
11241
|
-
const result = await this.repository.update(lookup,
|
|
11242
|
-
const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */),
|
|
11246
|
+
const result = await this.repository.update(lookup, normalizedInput, options);
|
|
11247
|
+
const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */), normalizedInput).setResult(result);
|
|
11243
11248
|
await this.emitter.emitAsync(afterUpdateEvent);
|
|
11244
11249
|
return result;
|
|
11245
11250
|
}
|
|
11246
11251
|
async upsert(input, options) {
|
|
11247
|
-
const
|
|
11252
|
+
const normalizedInput = await this.normalizeInput(input);
|
|
11253
|
+
const primaryKeyValue = this.getPrimaryKeyValue(normalizedInput);
|
|
11248
11254
|
let beforeOperation;
|
|
11249
11255
|
let afterOperation;
|
|
11250
11256
|
if (primaryKeyValue === undefined) {
|
|
@@ -11262,10 +11268,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11262
11268
|
afterOperation = "afterCreate" /* AfterCreate */;
|
|
11263
11269
|
}
|
|
11264
11270
|
}
|
|
11265
|
-
const beforeUpsertEvent = new MutationEvent(this.getDescriptor(beforeOperation),
|
|
11271
|
+
const beforeUpsertEvent = new MutationEvent(this.getDescriptor(beforeOperation), normalizedInput);
|
|
11266
11272
|
await this.emitter.emitAsync(beforeUpsertEvent);
|
|
11267
|
-
const result = await this.repository.upsert(
|
|
11268
|
-
const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation),
|
|
11273
|
+
const result = await this.repository.upsert(normalizedInput, options);
|
|
11274
|
+
const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation), normalizedInput).setResult(result);
|
|
11269
11275
|
await this.emitter.emitAsync(afterUpsertEvent);
|
|
11270
11276
|
return result;
|
|
11271
11277
|
}
|
|
@@ -11273,9 +11279,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11273
11279
|
if (inputs.length === 0) {
|
|
11274
11280
|
return [];
|
|
11275
11281
|
}
|
|
11282
|
+
const normalizedInputs = await Promise.all(inputs.map((input) => this.normalizeInput(input)));
|
|
11276
11283
|
const entityInfoMap = new Map;
|
|
11277
11284
|
const inputsWithoutPrimaryKey = [];
|
|
11278
|
-
for (const input of
|
|
11285
|
+
for (const input of normalizedInputs) {
|
|
11279
11286
|
const primaryKeyValue = this.getPrimaryKeyValue(input);
|
|
11280
11287
|
if (primaryKeyValue !== undefined) {
|
|
11281
11288
|
const entityInfo = {
|
|
@@ -11313,7 +11320,7 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11313
11320
|
beforeEvents.push(new MutationEvent(this.getDescriptor("beforeCreate" /* BeforeCreate */), input));
|
|
11314
11321
|
}
|
|
11315
11322
|
await Promise.all(beforeEvents.map((event) => this.emitter.emitAsync(event)));
|
|
11316
|
-
const results = await this.repository.bulkUpsert(
|
|
11323
|
+
const results = await this.repository.bulkUpsert(normalizedInputs, options);
|
|
11317
11324
|
const resultsByPrimaryKey = new Map;
|
|
11318
11325
|
const resultsWithoutPrimaryKey = [];
|
|
11319
11326
|
for (const result of results) {
|
|
@@ -11403,8 +11410,19 @@ class MockMemoryRepository {
|
|
|
11403
11410
|
if (!this.entityMetadata?.primaryKey) {
|
|
11404
11411
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11405
11412
|
}
|
|
11406
|
-
const
|
|
11407
|
-
|
|
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;
|
|
11408
11426
|
}
|
|
11409
11427
|
async search(input, options) {
|
|
11410
11428
|
const pagination = options?.pagination || { page: 1, pageSize: 25 };
|
|
@@ -11446,24 +11464,44 @@ class MockMemoryRepository {
|
|
|
11446
11464
|
if (!this.entityMetadata?.primaryKey) {
|
|
11447
11465
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11448
11466
|
}
|
|
11449
|
-
|
|
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
|
+
}
|
|
11450
11478
|
if (!item) {
|
|
11451
11479
|
throw new Error("Item not found");
|
|
11452
11480
|
}
|
|
11453
|
-
this.trash.set(
|
|
11454
|
-
this.data.delete(
|
|
11481
|
+
this.trash.set(itemKey, item);
|
|
11482
|
+
this.data.delete(itemKey);
|
|
11455
11483
|
return item;
|
|
11456
11484
|
}
|
|
11457
11485
|
async restore(lookup) {
|
|
11458
11486
|
if (!this.entityMetadata?.primaryKey) {
|
|
11459
11487
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11460
11488
|
}
|
|
11461
|
-
|
|
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
|
+
}
|
|
11462
11500
|
if (!item) {
|
|
11463
11501
|
throw new Error("Item not found in trash");
|
|
11464
11502
|
}
|
|
11465
|
-
this.trash.delete(
|
|
11466
|
-
this.data.set(
|
|
11503
|
+
this.trash.delete(itemKey);
|
|
11504
|
+
this.data.set(itemKey, item);
|
|
11467
11505
|
return item;
|
|
11468
11506
|
}
|
|
11469
11507
|
async create(input) {
|
|
@@ -11486,16 +11524,27 @@ class MockMemoryRepository {
|
|
|
11486
11524
|
if (!this.entityMetadata?.primaryKey) {
|
|
11487
11525
|
throw new Error("Primary key is not defined in the schema metadata");
|
|
11488
11526
|
}
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
|
|
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
|
+
}
|
|
11496
11545
|
}
|
|
11497
11546
|
const updatedItem = this.assignInput(existingItem, input);
|
|
11498
|
-
this.data.set(
|
|
11547
|
+
this.data.set(itemKey, updatedItem);
|
|
11499
11548
|
return updatedItem;
|
|
11500
11549
|
}
|
|
11501
11550
|
async count(search, options) {
|
|
@@ -11549,5 +11598,5 @@ class MockMemoryRepository {
|
|
|
11549
11598
|
}
|
|
11550
11599
|
}
|
|
11551
11600
|
|
|
11552
|
-
//# debugId=
|
|
11601
|
+
//# debugId=34781135054B25FD64756E2164756E21
|
|
11553
11602
|
//# sourceMappingURL=index.cjs.map
|