@declaro/data 2.0.0-beta.127 → 2.0.0-beta.128
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 +29 -1
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +29 -1
- package/dist/node/index.js.map +3 -3
- package/dist/ts/domain/services/model-service.d.ts +19 -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 +180 -0
- package/src/domain/services/model-service.ts +67 -1
package/dist/node/index.cjs
CHANGED
|
@@ -12831,6 +12831,34 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12831
12831
|
async normalizeInput(input, args) {
|
|
12832
12832
|
return input;
|
|
12833
12833
|
}
|
|
12834
|
+
async detailsToInput(detail) {
|
|
12835
|
+
const inputModel = this.schema.definition.input;
|
|
12836
|
+
const inputJsonSchema = inputModel.toJSONSchema();
|
|
12837
|
+
const inputFields = Object.keys(inputJsonSchema.properties ?? {});
|
|
12838
|
+
const picked = {};
|
|
12839
|
+
for (const field of inputFields) {
|
|
12840
|
+
if (field in detail) {
|
|
12841
|
+
picked[field] = detail[field];
|
|
12842
|
+
}
|
|
12843
|
+
}
|
|
12844
|
+
const result = await inputModel.validate(picked);
|
|
12845
|
+
if ("value" in result) {
|
|
12846
|
+
return result.value;
|
|
12847
|
+
}
|
|
12848
|
+
return picked;
|
|
12849
|
+
}
|
|
12850
|
+
async duplicate(lookup, overrides, options) {
|
|
12851
|
+
const existing = await this.load(lookup);
|
|
12852
|
+
if (!existing) {
|
|
12853
|
+
throw new Error("Item not found");
|
|
12854
|
+
}
|
|
12855
|
+
const input = await this.detailsToInput(existing);
|
|
12856
|
+
if (this.entityMetadata?.primaryKey) {
|
|
12857
|
+
delete input[this.entityMetadata.primaryKey];
|
|
12858
|
+
}
|
|
12859
|
+
const finalInput = overrides ? Object.assign({}, input, overrides) : input;
|
|
12860
|
+
return this.create(finalInput, options);
|
|
12861
|
+
}
|
|
12834
12862
|
async remove(lookup, options) {
|
|
12835
12863
|
const beforeRemoveEvent = new MutationEvent(this.getDescriptor("beforeRemove" /* BeforeRemove */), lookup);
|
|
12836
12864
|
await this.emitter.emitAsync(beforeRemoveEvent);
|
|
@@ -13328,5 +13356,5 @@ class MockMemoryRepository {
|
|
|
13328
13356
|
}
|
|
13329
13357
|
}
|
|
13330
13358
|
|
|
13331
|
-
//# debugId=
|
|
13359
|
+
//# debugId=F7D58E636DC6E2AF64756E2164756E21
|
|
13332
13360
|
//# sourceMappingURL=index.cjs.map
|