@declaro/data 2.0.0-beta.97 → 2.0.0-beta.98
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 +3 -3
- package/dist/node/index.cjs +20 -13
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +20 -13
- package/dist/node/index.js.map +3 -3
- package/dist/ts/domain/services/model-service.d.ts +8 -0
- package/dist/ts/domain/services/model-service.d.ts.map +1 -1
- 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/dist/node/index.js
CHANGED
|
@@ -11172,6 +11172,9 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11172
11172
|
constructor(args) {
|
|
11173
11173
|
super(args);
|
|
11174
11174
|
}
|
|
11175
|
+
async normalizeInput(input) {
|
|
11176
|
+
return input;
|
|
11177
|
+
}
|
|
11175
11178
|
async remove(lookup, options) {
|
|
11176
11179
|
const beforeRemoveEvent = new MutationEvent(this.getDescriptor("beforeRemove" /* BeforeRemove */), lookup);
|
|
11177
11180
|
await this.emitter.emitAsync(beforeRemoveEvent);
|
|
@@ -11189,23 +11192,26 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11189
11192
|
return result;
|
|
11190
11193
|
}
|
|
11191
11194
|
async create(input, options) {
|
|
11192
|
-
const
|
|
11195
|
+
const normalizedInput = await this.normalizeInput(input);
|
|
11196
|
+
const beforeCreateEvent = new MutationEvent(this.getDescriptor("beforeCreate" /* BeforeCreate */), normalizedInput);
|
|
11193
11197
|
await this.emitter.emitAsync(beforeCreateEvent);
|
|
11194
|
-
const result = await this.repository.create(
|
|
11195
|
-
const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */),
|
|
11198
|
+
const result = await this.repository.create(normalizedInput, options);
|
|
11199
|
+
const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), normalizedInput).setResult(result);
|
|
11196
11200
|
await this.emitter.emitAsync(afterCreateEvent);
|
|
11197
11201
|
return result;
|
|
11198
11202
|
}
|
|
11199
11203
|
async update(lookup, input, options) {
|
|
11200
|
-
const
|
|
11204
|
+
const normalizedInput = await this.normalizeInput(input);
|
|
11205
|
+
const beforeUpdateEvent = new MutationEvent(this.getDescriptor("beforeUpdate" /* BeforeUpdate */), normalizedInput);
|
|
11201
11206
|
await this.emitter.emitAsync(beforeUpdateEvent);
|
|
11202
|
-
const result = await this.repository.update(lookup,
|
|
11203
|
-
const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */),
|
|
11207
|
+
const result = await this.repository.update(lookup, normalizedInput, options);
|
|
11208
|
+
const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */), normalizedInput).setResult(result);
|
|
11204
11209
|
await this.emitter.emitAsync(afterUpdateEvent);
|
|
11205
11210
|
return result;
|
|
11206
11211
|
}
|
|
11207
11212
|
async upsert(input, options) {
|
|
11208
|
-
const
|
|
11213
|
+
const normalizedInput = await this.normalizeInput(input);
|
|
11214
|
+
const primaryKeyValue = this.getPrimaryKeyValue(normalizedInput);
|
|
11209
11215
|
let beforeOperation;
|
|
11210
11216
|
let afterOperation;
|
|
11211
11217
|
if (primaryKeyValue === undefined) {
|
|
@@ -11223,10 +11229,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11223
11229
|
afterOperation = "afterCreate" /* AfterCreate */;
|
|
11224
11230
|
}
|
|
11225
11231
|
}
|
|
11226
|
-
const beforeUpsertEvent = new MutationEvent(this.getDescriptor(beforeOperation),
|
|
11232
|
+
const beforeUpsertEvent = new MutationEvent(this.getDescriptor(beforeOperation), normalizedInput);
|
|
11227
11233
|
await this.emitter.emitAsync(beforeUpsertEvent);
|
|
11228
|
-
const result = await this.repository.upsert(
|
|
11229
|
-
const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation),
|
|
11234
|
+
const result = await this.repository.upsert(normalizedInput, options);
|
|
11235
|
+
const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation), normalizedInput).setResult(result);
|
|
11230
11236
|
await this.emitter.emitAsync(afterUpsertEvent);
|
|
11231
11237
|
return result;
|
|
11232
11238
|
}
|
|
@@ -11234,9 +11240,10 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11234
11240
|
if (inputs.length === 0) {
|
|
11235
11241
|
return [];
|
|
11236
11242
|
}
|
|
11243
|
+
const normalizedInputs = await Promise.all(inputs.map((input) => this.normalizeInput(input)));
|
|
11237
11244
|
const entityInfoMap = new Map;
|
|
11238
11245
|
const inputsWithoutPrimaryKey = [];
|
|
11239
|
-
for (const input of
|
|
11246
|
+
for (const input of normalizedInputs) {
|
|
11240
11247
|
const primaryKeyValue = this.getPrimaryKeyValue(input);
|
|
11241
11248
|
if (primaryKeyValue !== undefined) {
|
|
11242
11249
|
const entityInfo = {
|
|
@@ -11274,7 +11281,7 @@ class ModelService extends ReadOnlyModelService {
|
|
|
11274
11281
|
beforeEvents.push(new MutationEvent(this.getDescriptor("beforeCreate" /* BeforeCreate */), input));
|
|
11275
11282
|
}
|
|
11276
11283
|
await Promise.all(beforeEvents.map((event) => this.emitter.emitAsync(event)));
|
|
11277
|
-
const results = await this.repository.bulkUpsert(
|
|
11284
|
+
const results = await this.repository.bulkUpsert(normalizedInputs, options);
|
|
11278
11285
|
const resultsByPrimaryKey = new Map;
|
|
11279
11286
|
const resultsWithoutPrimaryKey = [];
|
|
11280
11287
|
for (const result of results) {
|
|
@@ -11528,5 +11535,5 @@ export {
|
|
|
11528
11535
|
BaseModelService
|
|
11529
11536
|
};
|
|
11530
11537
|
|
|
11531
|
-
//# debugId=
|
|
11538
|
+
//# debugId=D05B27DAC594136E64756E2164756E21
|
|
11532
11539
|
//# sourceMappingURL=index.js.map
|