@declaro/data 2.0.0-beta.110 → 2.0.0-beta.111

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.
@@ -12625,13 +12625,37 @@ class BaseModelService {
12625
12625
  }
12626
12626
  // src/domain/services/read-only-model-service.ts
12627
12627
  class ReadOnlyModelService extends BaseModelService {
12628
+ async normalizeDetail(detail) {
12629
+ const detailModel = this.schema.definition.detail;
12630
+ if (detailModel) {
12631
+ const validation = await detailModel.validate(detail, { strict: false });
12632
+ if (validation.issues) {
12633
+ console.warn(`${detailModel.labels.singularLabel} shape did not match the expected schema`);
12634
+ } else {
12635
+ return validation.value;
12636
+ }
12637
+ }
12638
+ return detail;
12639
+ }
12640
+ async normalizeSummary(summary) {
12641
+ const summaryModel = this.schema.definition.summary;
12642
+ if (summaryModel) {
12643
+ const validation = await summaryModel.validate(summary, { strict: false });
12644
+ if (validation.issues) {
12645
+ console.warn(`${summaryModel.labels.singularLabel} shape did not match the expected schema`);
12646
+ } else {
12647
+ return validation.value;
12648
+ }
12649
+ }
12650
+ return summary;
12651
+ }
12628
12652
  async load(lookup, options) {
12629
12653
  const beforeLoadEvent = new QueryEvent(this.getDescriptor("beforeLoad" /* BeforeLoad */, options?.scope), lookup);
12630
12654
  await this.emitter.emitAsync(beforeLoadEvent);
12631
12655
  const details = await this.repository.load(lookup);
12632
12656
  const afterLoadEvent = new QueryEvent(this.getDescriptor("afterLoad" /* AfterLoad */, options?.scope), lookup).setResult(details);
12633
12657
  await this.emitter.emitAsync(afterLoadEvent);
12634
- return details;
12658
+ return await this.normalizeDetail(details);
12635
12659
  }
12636
12660
  async loadMany(lookups, options) {
12637
12661
  const beforeLoadManyEvent = new QueryEvent(this.getDescriptor("beforeLoadMany" /* BeforeLoadMany */, options?.scope), lookups);
@@ -12639,7 +12663,7 @@ class ReadOnlyModelService extends BaseModelService {
12639
12663
  const details = await this.repository.loadMany(lookups);
12640
12664
  const afterLoadManyEvent = new QueryEvent(this.getDescriptor("afterLoadMany" /* AfterLoadMany */, options?.scope), lookups).setResult(details);
12641
12665
  await this.emitter.emitAsync(afterLoadManyEvent);
12642
- return details;
12666
+ return await Promise.all(details.map((detail) => this.normalizeDetail(detail)));
12643
12667
  }
12644
12668
  async search(filters, options) {
12645
12669
  const beforeSearchEvent = new QueryEvent(this.getDescriptor("beforeSearch" /* BeforeSearch */, options?.scope), filters);
@@ -12647,7 +12671,10 @@ class ReadOnlyModelService extends BaseModelService {
12647
12671
  const results = await this.repository.search(filters, options);
12648
12672
  const afterSearchEvent = new QueryEvent(this.getDescriptor("afterSearch" /* AfterSearch */, options?.scope), filters).setResult(results);
12649
12673
  await this.emitter.emitAsync(afterSearchEvent);
12650
- return results;
12674
+ return {
12675
+ ...results,
12676
+ results: await Promise.all(results.results.map((detail) => this.normalizeSummary(detail)))
12677
+ };
12651
12678
  }
12652
12679
  async count(filters, options) {
12653
12680
  const beforeCountEvent = new QueryEvent(this.getDescriptor("beforeCount" /* BeforeCount */, options?.scope), filters);
@@ -12673,7 +12700,7 @@ class ModelService extends ReadOnlyModelService {
12673
12700
  const result = await this.repository.remove(lookup, options);
12674
12701
  const afterRemoveEvent = new MutationEvent(this.getDescriptor("afterRemove" /* AfterRemove */), lookup).setResult(result);
12675
12702
  await this.emitter.emitAsync(afterRemoveEvent);
12676
- return result;
12703
+ return await this.normalizeSummary(result);
12677
12704
  }
12678
12705
  async restore(lookup, options) {
12679
12706
  const beforeRestoreEvent = new MutationEvent(this.getDescriptor("beforeRestore" /* BeforeRestore */), lookup);
@@ -12681,7 +12708,7 @@ class ModelService extends ReadOnlyModelService {
12681
12708
  const result = await this.repository.restore(lookup, options);
12682
12709
  const afterRestoreEvent = new MutationEvent(this.getDescriptor("afterRestore" /* AfterRestore */), lookup).setResult(result);
12683
12710
  await this.emitter.emitAsync(afterRestoreEvent);
12684
- return result;
12711
+ return await this.normalizeSummary(result);
12685
12712
  }
12686
12713
  async create(input, options) {
12687
12714
  const normalizedInput = await this.normalizeInput(input);
@@ -12690,7 +12717,7 @@ class ModelService extends ReadOnlyModelService {
12690
12717
  const result = await this.repository.create(normalizedInput, options);
12691
12718
  const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), normalizedInput).setResult(result);
12692
12719
  await this.emitter.emitAsync(afterCreateEvent);
12693
- return result;
12720
+ return await this.normalizeDetail(result);
12694
12721
  }
12695
12722
  async update(lookup, input, options) {
12696
12723
  const normalizedInput = await this.normalizeInput(input);
@@ -12699,7 +12726,7 @@ class ModelService extends ReadOnlyModelService {
12699
12726
  const result = await this.repository.update(lookup, normalizedInput, options);
12700
12727
  const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */), normalizedInput).setResult(result);
12701
12728
  await this.emitter.emitAsync(afterUpdateEvent);
12702
- return result;
12729
+ return await this.normalizeDetail(result);
12703
12730
  }
12704
12731
  async upsert(input, options) {
12705
12732
  const normalizedInput = await this.normalizeInput(input);
@@ -12726,7 +12753,7 @@ class ModelService extends ReadOnlyModelService {
12726
12753
  const result = await this.repository.upsert(normalizedInput, options);
12727
12754
  const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation), normalizedInput).setResult(result);
12728
12755
  await this.emitter.emitAsync(afterUpsertEvent);
12729
- return result;
12756
+ return await this.normalizeDetail(result);
12730
12757
  }
12731
12758
  async bulkUpsert(inputs, options) {
12732
12759
  if (inputs.length === 0) {
@@ -12796,7 +12823,7 @@ class ModelService extends ReadOnlyModelService {
12796
12823
  afterEvents.push(new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), input).setResult(matchedResult));
12797
12824
  }
12798
12825
  await Promise.all(afterEvents.map((event) => this.emitter.emitAsync(event)));
12799
- return results;
12826
+ return await Promise.all(results.map((result) => this.normalizeDetail(result)));
12800
12827
  }
12801
12828
  }
12802
12829
  // src/test/mock/models/mock-book-models.ts
@@ -13069,5 +13096,5 @@ export {
13069
13096
  BaseModelService
13070
13097
  };
13071
13098
 
13072
- //# debugId=16140025E800A8D064756E2164756E21
13099
+ //# debugId=82F6D21CEB65533F64756E2164756E21
13073
13100
  //# sourceMappingURL=index.js.map