@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.js
CHANGED
|
@@ -12792,6 +12792,34 @@ class ModelService extends ReadOnlyModelService {
|
|
|
12792
12792
|
async normalizeInput(input, args) {
|
|
12793
12793
|
return input;
|
|
12794
12794
|
}
|
|
12795
|
+
async detailsToInput(detail) {
|
|
12796
|
+
const inputModel = this.schema.definition.input;
|
|
12797
|
+
const inputJsonSchema = inputModel.toJSONSchema();
|
|
12798
|
+
const inputFields = Object.keys(inputJsonSchema.properties ?? {});
|
|
12799
|
+
const picked = {};
|
|
12800
|
+
for (const field of inputFields) {
|
|
12801
|
+
if (field in detail) {
|
|
12802
|
+
picked[field] = detail[field];
|
|
12803
|
+
}
|
|
12804
|
+
}
|
|
12805
|
+
const result = await inputModel.validate(picked);
|
|
12806
|
+
if ("value" in result) {
|
|
12807
|
+
return result.value;
|
|
12808
|
+
}
|
|
12809
|
+
return picked;
|
|
12810
|
+
}
|
|
12811
|
+
async duplicate(lookup, overrides, options) {
|
|
12812
|
+
const existing = await this.load(lookup);
|
|
12813
|
+
if (!existing) {
|
|
12814
|
+
throw new Error("Item not found");
|
|
12815
|
+
}
|
|
12816
|
+
const input = await this.detailsToInput(existing);
|
|
12817
|
+
if (this.entityMetadata?.primaryKey) {
|
|
12818
|
+
delete input[this.entityMetadata.primaryKey];
|
|
12819
|
+
}
|
|
12820
|
+
const finalInput = overrides ? Object.assign({}, input, overrides) : input;
|
|
12821
|
+
return this.create(finalInput, options);
|
|
12822
|
+
}
|
|
12795
12823
|
async remove(lookup, options) {
|
|
12796
12824
|
const beforeRemoveEvent = new MutationEvent(this.getDescriptor("beforeRemove" /* BeforeRemove */), lookup);
|
|
12797
12825
|
await this.emitter.emitAsync(beforeRemoveEvent);
|
|
@@ -13307,5 +13335,5 @@ export {
|
|
|
13307
13335
|
BaseModelService
|
|
13308
13336
|
};
|
|
13309
13337
|
|
|
13310
|
-
//# debugId=
|
|
13338
|
+
//# debugId=B7049DCEB4D8885164756E2164756E21
|
|
13311
13339
|
//# sourceMappingURL=index.js.map
|