@declaro/data 2.0.0-beta.127 → 2.0.0-beta.129

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.
@@ -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=2F46F5B1D5A9235464756E2164756E21
13338
+ //# debugId=B7049DCEB4D8885164756E2164756E21
13311
13339
  //# sourceMappingURL=index.js.map