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

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.
@@ -12664,13 +12664,37 @@ class BaseModelService {
12664
12664
  }
12665
12665
  // src/domain/services/read-only-model-service.ts
12666
12666
  class ReadOnlyModelService extends BaseModelService {
12667
+ async normalizeDetail(detail) {
12668
+ const detailModel = this.schema.definition.detail;
12669
+ if (detailModel) {
12670
+ const validation = await detailModel.validate(detail, { strict: false });
12671
+ if (validation.issues) {
12672
+ console.warn(`${detailModel.labels.singularLabel} shape did not match the expected schema`);
12673
+ } else {
12674
+ return validation.value;
12675
+ }
12676
+ }
12677
+ return detail;
12678
+ }
12679
+ async normalizeSummary(summary) {
12680
+ const summaryModel = this.schema.definition.summary;
12681
+ if (summaryModel) {
12682
+ const validation = await summaryModel.validate(summary, { strict: false });
12683
+ if (validation.issues) {
12684
+ console.warn(`${summaryModel.labels.singularLabel} shape did not match the expected schema`);
12685
+ } else {
12686
+ return validation.value;
12687
+ }
12688
+ }
12689
+ return summary;
12690
+ }
12667
12691
  async load(lookup, options) {
12668
12692
  const beforeLoadEvent = new QueryEvent(this.getDescriptor("beforeLoad" /* BeforeLoad */, options?.scope), lookup);
12669
12693
  await this.emitter.emitAsync(beforeLoadEvent);
12670
12694
  const details = await this.repository.load(lookup);
12671
12695
  const afterLoadEvent = new QueryEvent(this.getDescriptor("afterLoad" /* AfterLoad */, options?.scope), lookup).setResult(details);
12672
12696
  await this.emitter.emitAsync(afterLoadEvent);
12673
- return details;
12697
+ return await this.normalizeDetail(details);
12674
12698
  }
12675
12699
  async loadMany(lookups, options) {
12676
12700
  const beforeLoadManyEvent = new QueryEvent(this.getDescriptor("beforeLoadMany" /* BeforeLoadMany */, options?.scope), lookups);
@@ -12678,7 +12702,7 @@ class ReadOnlyModelService extends BaseModelService {
12678
12702
  const details = await this.repository.loadMany(lookups);
12679
12703
  const afterLoadManyEvent = new QueryEvent(this.getDescriptor("afterLoadMany" /* AfterLoadMany */, options?.scope), lookups).setResult(details);
12680
12704
  await this.emitter.emitAsync(afterLoadManyEvent);
12681
- return details;
12705
+ return await Promise.all(details.map((detail) => this.normalizeDetail(detail)));
12682
12706
  }
12683
12707
  async search(filters, options) {
12684
12708
  const beforeSearchEvent = new QueryEvent(this.getDescriptor("beforeSearch" /* BeforeSearch */, options?.scope), filters);
@@ -12686,7 +12710,10 @@ class ReadOnlyModelService extends BaseModelService {
12686
12710
  const results = await this.repository.search(filters, options);
12687
12711
  const afterSearchEvent = new QueryEvent(this.getDescriptor("afterSearch" /* AfterSearch */, options?.scope), filters).setResult(results);
12688
12712
  await this.emitter.emitAsync(afterSearchEvent);
12689
- return results;
12713
+ return {
12714
+ ...results,
12715
+ results: await Promise.all(results.results.map((detail) => this.normalizeSummary(detail)))
12716
+ };
12690
12717
  }
12691
12718
  async count(filters, options) {
12692
12719
  const beforeCountEvent = new QueryEvent(this.getDescriptor("beforeCount" /* BeforeCount */, options?.scope), filters);
@@ -12712,7 +12739,7 @@ class ModelService extends ReadOnlyModelService {
12712
12739
  const result = await this.repository.remove(lookup, options);
12713
12740
  const afterRemoveEvent = new MutationEvent(this.getDescriptor("afterRemove" /* AfterRemove */), lookup).setResult(result);
12714
12741
  await this.emitter.emitAsync(afterRemoveEvent);
12715
- return result;
12742
+ return await this.normalizeSummary(result);
12716
12743
  }
12717
12744
  async restore(lookup, options) {
12718
12745
  const beforeRestoreEvent = new MutationEvent(this.getDescriptor("beforeRestore" /* BeforeRestore */), lookup);
@@ -12720,7 +12747,7 @@ class ModelService extends ReadOnlyModelService {
12720
12747
  const result = await this.repository.restore(lookup, options);
12721
12748
  const afterRestoreEvent = new MutationEvent(this.getDescriptor("afterRestore" /* AfterRestore */), lookup).setResult(result);
12722
12749
  await this.emitter.emitAsync(afterRestoreEvent);
12723
- return result;
12750
+ return await this.normalizeSummary(result);
12724
12751
  }
12725
12752
  async create(input, options) {
12726
12753
  const normalizedInput = await this.normalizeInput(input);
@@ -12729,7 +12756,7 @@ class ModelService extends ReadOnlyModelService {
12729
12756
  const result = await this.repository.create(normalizedInput, options);
12730
12757
  const afterCreateEvent = new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), normalizedInput).setResult(result);
12731
12758
  await this.emitter.emitAsync(afterCreateEvent);
12732
- return result;
12759
+ return await this.normalizeDetail(result);
12733
12760
  }
12734
12761
  async update(lookup, input, options) {
12735
12762
  const normalizedInput = await this.normalizeInput(input);
@@ -12738,7 +12765,7 @@ class ModelService extends ReadOnlyModelService {
12738
12765
  const result = await this.repository.update(lookup, normalizedInput, options);
12739
12766
  const afterUpdateEvent = new MutationEvent(this.getDescriptor("afterUpdate" /* AfterUpdate */), normalizedInput).setResult(result);
12740
12767
  await this.emitter.emitAsync(afterUpdateEvent);
12741
- return result;
12768
+ return await this.normalizeDetail(result);
12742
12769
  }
12743
12770
  async upsert(input, options) {
12744
12771
  const normalizedInput = await this.normalizeInput(input);
@@ -12765,7 +12792,7 @@ class ModelService extends ReadOnlyModelService {
12765
12792
  const result = await this.repository.upsert(normalizedInput, options);
12766
12793
  const afterUpsertEvent = new MutationEvent(this.getDescriptor(afterOperation), normalizedInput).setResult(result);
12767
12794
  await this.emitter.emitAsync(afterUpsertEvent);
12768
- return result;
12795
+ return await this.normalizeDetail(result);
12769
12796
  }
12770
12797
  async bulkUpsert(inputs, options) {
12771
12798
  if (inputs.length === 0) {
@@ -12835,7 +12862,7 @@ class ModelService extends ReadOnlyModelService {
12835
12862
  afterEvents.push(new MutationEvent(this.getDescriptor("afterCreate" /* AfterCreate */), input).setResult(matchedResult));
12836
12863
  }
12837
12864
  await Promise.all(afterEvents.map((event) => this.emitter.emitAsync(event)));
12838
- return results;
12865
+ return await Promise.all(results.map((result) => this.normalizeDetail(result)));
12839
12866
  }
12840
12867
  }
12841
12868
  // src/test/mock/models/mock-book-models.ts
@@ -13090,5 +13117,5 @@ class MockMemoryRepository {
13090
13117
  }
13091
13118
  }
13092
13119
 
13093
- //# debugId=63100B44900CBD5A64756E2164756E21
13120
+ //# debugId=0A104DECF42A532164756E2164756E21
13094
13121
  //# sourceMappingURL=index.cjs.map