@declaro/data 2.0.0-beta.126 → 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.
Files changed (39) hide show
  1. package/dist/browser/index.js +11 -11
  2. package/dist/browser/index.js.map +6 -6
  3. package/dist/node/index.cjs +217 -92
  4. package/dist/node/index.cjs.map +6 -6
  5. package/dist/node/index.js +209 -84
  6. package/dist/node/index.js.map +6 -6
  7. package/dist/ts/application/model-controller.d.ts +15 -5
  8. package/dist/ts/application/model-controller.d.ts.map +1 -1
  9. package/dist/ts/application/read-only-model-controller.d.ts +5 -1
  10. package/dist/ts/application/read-only-model-controller.d.ts.map +1 -1
  11. package/dist/ts/domain/services/model-service.d.ts +27 -0
  12. package/dist/ts/domain/services/model-service.d.ts.map +1 -1
  13. package/dist/ts/domain/services/read-only-model-service.d.ts +8 -0
  14. package/dist/ts/domain/services/read-only-model-service.d.ts.map +1 -1
  15. package/dist/ts/shared/utils/schema-inheritance.test.d.ts +2 -0
  16. package/dist/ts/shared/utils/schema-inheritance.test.d.ts.map +1 -0
  17. package/dist/ts/shared/utils/test/animal-schema.d.ts +57 -0
  18. package/dist/ts/shared/utils/test/animal-schema.d.ts.map +1 -0
  19. package/dist/ts/shared/utils/test/animal-trait-schema.d.ts +55 -0
  20. package/dist/ts/shared/utils/test/animal-trait-schema.d.ts.map +1 -0
  21. package/dist/ts/shared/utils/test/elephant-schema.d.ts +30 -0
  22. package/dist/ts/shared/utils/test/elephant-schema.d.ts.map +1 -0
  23. package/dist/ts/shared/utils/test/elephant-trait-schema.d.ts +26 -0
  24. package/dist/ts/shared/utils/test/elephant-trait-schema.d.ts.map +1 -0
  25. package/package.json +5 -5
  26. package/src/application/model-controller.ts +110 -59
  27. package/src/application/read-only-model-controller.ts +43 -25
  28. package/src/domain/services/model-service.test.ts +460 -0
  29. package/src/domain/services/model-service.ts +165 -67
  30. package/src/domain/services/read-only-model-service.test.ts +230 -0
  31. package/src/domain/services/read-only-model-service.ts +65 -40
  32. package/src/shared/utils/schema-inheritance.test.ts +295 -0
  33. package/src/shared/utils/test/animal-schema.ts +46 -0
  34. package/src/shared/utils/test/animal-trait-schema.ts +45 -0
  35. package/src/shared/utils/test/elephant-schema.ts +58 -0
  36. package/src/shared/utils/test/elephant-trait-schema.ts +53 -0
  37. package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts +0 -1
  38. package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts.map +0 -1
  39. package/src/test/mock/repositories/mock-memory-repository.custom-lookup.test.ts +0 -0
@@ -23,6 +23,11 @@ export interface ILoadOptions extends IActionOptions {
23
23
  * If true, both removed and non-removed records will be returned.
24
24
  */
25
25
  includeRemoved?: boolean
26
+
27
+ /**
28
+ * If true, skips dispatching events for this action.
29
+ */
30
+ doNotDispatchEvents?: boolean
26
31
  }
27
32
  export interface ISearchOptions<TSchema extends AnyModelSchema> extends IActionOptions {
28
33
  pagination?: IPaginationInput
@@ -35,6 +40,10 @@ export interface ISearchOptions<TSchema extends AnyModelSchema> extends IActionO
35
40
  * If true, both removed and non-removed records will be returned.
36
41
  */
37
42
  includeRemoved?: boolean
43
+ /**
44
+ * If true, skips dispatching events for this action.
45
+ */
46
+ doNotDispatchEvents?: boolean
38
47
  }
39
48
 
40
49
  export class ReadOnlyModelService<TSchema extends AnyModelSchema> extends BaseModelService<TSchema> {
@@ -69,21 +78,25 @@ export class ReadOnlyModelService<TSchema extends AnyModelSchema> extends BaseMo
69
78
  */
70
79
  async load(lookup: InferLookup<TSchema>, options?: ILoadOptions): Promise<InferDetail<TSchema>> {
71
80
  // Emit the before load event
72
- const beforeLoadEvent = new QueryEvent<InferDetail<TSchema>, InferLookup<TSchema>>(
73
- this.getDescriptor(ModelQueryEvent.BeforeLoad, options?.scope),
74
- lookup,
75
- )
76
- await this.emitter.emitAsync(beforeLoadEvent)
81
+ if (!options?.doNotDispatchEvents) {
82
+ const beforeLoadEvent = new QueryEvent<InferDetail<TSchema>, InferLookup<TSchema>>(
83
+ this.getDescriptor(ModelQueryEvent.BeforeLoad, options?.scope),
84
+ lookup,
85
+ )
86
+ await this.emitter.emitAsync(beforeLoadEvent)
87
+ }
77
88
 
78
89
  // Load the details from the repository
79
90
  const details = await this.repository.load(lookup, options)
80
91
 
81
92
  // Emit the after load event
82
- const afterLoadEvent = new QueryEvent<InferDetail<TSchema>, InferLookup<TSchema>>(
83
- this.getDescriptor(ModelQueryEvent.AfterLoad, options?.scope),
84
- lookup,
85
- ).setResult(details)
86
- await this.emitter.emitAsync(afterLoadEvent)
93
+ if (!options?.doNotDispatchEvents) {
94
+ const afterLoadEvent = new QueryEvent<InferDetail<TSchema>, InferLookup<TSchema>>(
95
+ this.getDescriptor(ModelQueryEvent.AfterLoad, options?.scope),
96
+ lookup,
97
+ ).setResult(details)
98
+ await this.emitter.emitAsync(afterLoadEvent)
99
+ }
87
100
 
88
101
  return await this.normalizeDetail(details)
89
102
  }
@@ -96,21 +109,25 @@ export class ReadOnlyModelService<TSchema extends AnyModelSchema> extends BaseMo
96
109
  */
97
110
  async loadMany(lookups: InferLookup<TSchema>[], options?: ILoadOptions): Promise<InferDetail<TSchema>[]> {
98
111
  // Emit the before load many event
99
- const beforeLoadManyEvent = new QueryEvent<InferDetail<TSchema>[], InferLookup<TSchema>[]>(
100
- this.getDescriptor(ModelQueryEvent.BeforeLoadMany, options?.scope),
101
- lookups,
102
- )
103
- await this.emitter.emitAsync(beforeLoadManyEvent)
112
+ if (!options?.doNotDispatchEvents) {
113
+ const beforeLoadManyEvent = new QueryEvent<InferDetail<TSchema>[], InferLookup<TSchema>[]>(
114
+ this.getDescriptor(ModelQueryEvent.BeforeLoadMany, options?.scope),
115
+ lookups,
116
+ )
117
+ await this.emitter.emitAsync(beforeLoadManyEvent)
118
+ }
104
119
 
105
120
  // Load the details from the repository
106
121
  const details = await this.repository.loadMany(lookups, options)
107
122
 
108
123
  // Emit the after load many event
109
- const afterLoadManyEvent = new QueryEvent<InferDetail<TSchema>[], InferLookup<TSchema>[]>(
110
- this.getDescriptor(ModelQueryEvent.AfterLoadMany, options?.scope),
111
- lookups,
112
- ).setResult(details)
113
- await this.emitter.emitAsync(afterLoadManyEvent)
124
+ if (!options?.doNotDispatchEvents) {
125
+ const afterLoadManyEvent = new QueryEvent<InferDetail<TSchema>[], InferLookup<TSchema>[]>(
126
+ this.getDescriptor(ModelQueryEvent.AfterLoadMany, options?.scope),
127
+ lookups,
128
+ ).setResult(details)
129
+ await this.emitter.emitAsync(afterLoadManyEvent)
130
+ }
114
131
 
115
132
  return await Promise.all(details.map((detail) => this.normalizeDetail(detail)))
116
133
  }
@@ -126,21 +143,25 @@ export class ReadOnlyModelService<TSchema extends AnyModelSchema> extends BaseMo
126
143
  options?: ISearchOptions<TSchema>,
127
144
  ): Promise<InferSearchResults<TSchema>> {
128
145
  // Emit the before search event
129
- const beforeSearchEvent = new QueryEvent<InferSearchResults<TSchema>, InferFilters<TSchema>>(
130
- this.getDescriptor(ModelQueryEvent.BeforeSearch, options?.scope),
131
- filters,
132
- )
133
- await this.emitter.emitAsync(beforeSearchEvent)
146
+ if (!options?.doNotDispatchEvents) {
147
+ const beforeSearchEvent = new QueryEvent<InferSearchResults<TSchema>, InferFilters<TSchema>>(
148
+ this.getDescriptor(ModelQueryEvent.BeforeSearch, options?.scope),
149
+ filters,
150
+ )
151
+ await this.emitter.emitAsync(beforeSearchEvent)
152
+ }
134
153
 
135
154
  // Search the repository with the provided filters
136
155
  const results = await this.repository.search(filters, options)
137
156
 
138
157
  // Emit the after search event
139
- const afterSearchEvent = new QueryEvent<InferSearchResults<TSchema>, InferFilters<TSchema>>(
140
- this.getDescriptor(ModelQueryEvent.AfterSearch, options?.scope),
141
- filters,
142
- ).setResult(results)
143
- await this.emitter.emitAsync(afterSearchEvent)
158
+ if (!options?.doNotDispatchEvents) {
159
+ const afterSearchEvent = new QueryEvent<InferSearchResults<TSchema>, InferFilters<TSchema>>(
160
+ this.getDescriptor(ModelQueryEvent.AfterSearch, options?.scope),
161
+ filters,
162
+ ).setResult(results)
163
+ await this.emitter.emitAsync(afterSearchEvent)
164
+ }
144
165
 
145
166
  // Return the search results
146
167
  return {
@@ -156,21 +177,25 @@ export class ReadOnlyModelService<TSchema extends AnyModelSchema> extends BaseMo
156
177
  */
157
178
  async count(filters: InferFilters<TSchema>, options?: ISearchOptions<TSchema>): Promise<number> {
158
179
  // Emit the before count event
159
- const beforeCountEvent = new QueryEvent<number, InferFilters<TSchema>>(
160
- this.getDescriptor(ModelQueryEvent.BeforeCount, options?.scope),
161
- filters,
162
- )
163
- await this.emitter.emitAsync(beforeCountEvent)
180
+ if (!options?.doNotDispatchEvents) {
181
+ const beforeCountEvent = new QueryEvent<number, InferFilters<TSchema>>(
182
+ this.getDescriptor(ModelQueryEvent.BeforeCount, options?.scope),
183
+ filters,
184
+ )
185
+ await this.emitter.emitAsync(beforeCountEvent)
186
+ }
164
187
 
165
188
  // Count the records in the repository
166
189
  const count = await this.repository.count(filters, options)
167
190
 
168
191
  // Emit the after count event
169
- const afterCountEvent = new QueryEvent<number, InferFilters<TSchema>>(
170
- this.getDescriptor(ModelQueryEvent.AfterCount, options?.scope),
171
- filters,
172
- ).setResult(count)
173
- await this.emitter.emitAsync(afterCountEvent)
192
+ if (!options?.doNotDispatchEvents) {
193
+ const afterCountEvent = new QueryEvent<number, InferFilters<TSchema>>(
194
+ this.getDescriptor(ModelQueryEvent.AfterCount, options?.scope),
195
+ filters,
196
+ ).setResult(count)
197
+ await this.emitter.emitAsync(afterCountEvent)
198
+ }
174
199
 
175
200
  // Return the count
176
201
  return count
@@ -0,0 +1,295 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import type { ChildSchema } from './schema-inheritance'
3
+ import type { IAnimalTraitSchema } from './test/animal-trait-schema'
4
+ import type { IElephantSchema } from './test/elephant-schema'
5
+ import type { IAnimalSchema } from './test/animal-schema'
6
+ import type { IElephantTraitSchema } from './test/elephant-trait-schema'
7
+ import type { InferDetail } from './schema-inference'
8
+
9
+ // Service Classes using ChildSchema
10
+
11
+ class AnimalService<TSchema extends ChildSchema<IAnimalSchema>> {
12
+ getTraits(animal?: InferDetail<TSchema>): InferDetail<IAnimalTraitSchema>[] {
13
+ return animal?.traits ?? []
14
+ }
15
+ }
16
+
17
+ class ElephantService extends AnimalService<IElephantSchema> {
18
+ getTrunkLength(elephant?: InferDetail<IElephantSchema>): number {
19
+ return elephant?.trunkLength ?? 0
20
+ }
21
+ }
22
+
23
+ class AnimalTraitService<TSchema extends ChildSchema<IAnimalTraitSchema>> {
24
+ isTitleLong(trait?: InferDetail<TSchema>): boolean {
25
+ return (trait?.title.length ?? 0) > 10
26
+ }
27
+ }
28
+
29
+ class ElephantTraitService extends AnimalTraitService<IElephantTraitSchema> {
30
+ isSharpTrait(trait?: InferDetail<IElephantTraitSchema>): boolean {
31
+ return trait?.isSharp ?? false
32
+ }
33
+ }
34
+
35
+ describe('Schema Inheritance Utils', () => {
36
+ describe('AnimalService', () => {
37
+ test('should get traits from animal detail', () => {
38
+ const service = new AnimalService()
39
+ const animal = {
40
+ name: 'Lion',
41
+ sound: 'Roar',
42
+ traits: [
43
+ { title: 'Carnivore', description: 'Eats meat', animal: undefined },
44
+ { title: 'Predator', description: 'Hunts prey', animal: undefined },
45
+ ],
46
+ }
47
+
48
+ const traits = service.getTraits(animal)
49
+
50
+ expect(traits).toHaveLength(2)
51
+ expect(traits[0].title).toBe('Carnivore')
52
+ expect(traits[1].title).toBe('Predator')
53
+ })
54
+
55
+ test('should return empty array when animal has no traits', () => {
56
+ const service = new AnimalService()
57
+ const animal = {
58
+ name: 'Lion',
59
+ sound: 'Roar',
60
+ traits: [],
61
+ }
62
+
63
+ const traits = service.getTraits(animal)
64
+
65
+ expect(traits).toEqual([])
66
+ })
67
+
68
+ test('should return empty array when animal is undefined', () => {
69
+ const service = new AnimalService()
70
+
71
+ const traits = service.getTraits(undefined)
72
+
73
+ expect(traits).toEqual([])
74
+ })
75
+ })
76
+
77
+ describe('ElephantService', () => {
78
+ test('should inherit getTraits from AnimalService', () => {
79
+ const service = new ElephantService()
80
+ const elephant = {
81
+ name: 'Dumbo',
82
+ sound: 'Trumpet',
83
+ trunkLength: 150,
84
+ traits: [
85
+ {
86
+ title: 'Long trunk',
87
+ description: 'Very long trunk',
88
+ isSharp: false,
89
+ length: 150,
90
+ animal: undefined,
91
+ },
92
+ ],
93
+ }
94
+
95
+ const traits = service.getTraits(elephant)
96
+
97
+ expect(traits).toHaveLength(1)
98
+ expect(traits[0].title).toBe('Long trunk')
99
+ })
100
+
101
+ test('should get trunk length from elephant', () => {
102
+ const service = new ElephantService()
103
+ const elephant = {
104
+ name: 'Dumbo',
105
+ sound: 'Trumpet',
106
+ trunkLength: 150,
107
+ traits: [],
108
+ }
109
+
110
+ const trunkLength = service.getTrunkLength(elephant)
111
+
112
+ expect(trunkLength).toBe(150)
113
+ })
114
+
115
+ test('should return 0 when elephant is undefined', () => {
116
+ const service = new ElephantService()
117
+
118
+ const trunkLength = service.getTrunkLength(undefined)
119
+
120
+ expect(trunkLength).toBe(0)
121
+ })
122
+
123
+ test('should handle elephant with zero trunk length', () => {
124
+ const service = new ElephantService()
125
+ const elephant = {
126
+ name: 'Baby Elephant',
127
+ sound: 'Squeak',
128
+ trunkLength: 0,
129
+ traits: [],
130
+ }
131
+
132
+ const trunkLength = service.getTrunkLength(elephant)
133
+
134
+ expect(trunkLength).toBe(0)
135
+ })
136
+ })
137
+
138
+ describe('AnimalTraitService', () => {
139
+ test('should identify long titles', () => {
140
+ const service = new AnimalTraitService()
141
+ const trait = {
142
+ title: 'This is a very long title',
143
+ description: 'Description',
144
+ animal: undefined,
145
+ }
146
+
147
+ const isLong = service.isTitleLong(trait)
148
+
149
+ expect(isLong).toBe(true)
150
+ })
151
+
152
+ test('should identify short titles', () => {
153
+ const service = new AnimalTraitService()
154
+ const trait = {
155
+ title: 'Short',
156
+ description: 'Description',
157
+ animal: undefined,
158
+ }
159
+
160
+ const isLong = service.isTitleLong(trait)
161
+
162
+ expect(isLong).toBe(false)
163
+ })
164
+
165
+ test('should handle exactly 10 character titles as short', () => {
166
+ const service = new AnimalTraitService()
167
+ const trait = {
168
+ title: '1234567890',
169
+ description: 'Description',
170
+ animal: undefined,
171
+ }
172
+
173
+ const isLong = service.isTitleLong(trait)
174
+
175
+ expect(isLong).toBe(false)
176
+ })
177
+
178
+ test('should return false when trait is undefined', () => {
179
+ const service = new AnimalTraitService()
180
+
181
+ const isLong = service.isTitleLong(undefined)
182
+
183
+ expect(isLong).toBe(false)
184
+ })
185
+ })
186
+
187
+ describe('ElephantTraitService', () => {
188
+ test('should inherit isTitleLong from AnimalTraitService', () => {
189
+ const service = new ElephantTraitService()
190
+ const trait = {
191
+ title: 'Very long elephant trait title',
192
+ description: 'Description',
193
+ isSharp: true,
194
+ length: 50,
195
+ animal: undefined,
196
+ }
197
+
198
+ const isLong = service.isTitleLong(trait)
199
+
200
+ expect(isLong).toBe(true)
201
+ })
202
+
203
+ test('should identify sharp traits', () => {
204
+ const service = new ElephantTraitService()
205
+ const trait = {
206
+ title: 'Sharp tusk',
207
+ description: 'A sharp tusk',
208
+ isSharp: true,
209
+ length: 100,
210
+ animal: undefined,
211
+ }
212
+
213
+ const isSharp = service.isSharpTrait(trait)
214
+
215
+ expect(isSharp).toBe(true)
216
+ })
217
+
218
+ test('should identify non-sharp traits', () => {
219
+ const service = new ElephantTraitService()
220
+ const trait = {
221
+ title: 'Soft ear',
222
+ description: 'A soft ear',
223
+ isSharp: false,
224
+ length: 50,
225
+ animal: undefined,
226
+ }
227
+
228
+ const isSharp = service.isSharpTrait(trait)
229
+
230
+ expect(isSharp).toBe(false)
231
+ })
232
+
233
+ test('should return false when trait is undefined', () => {
234
+ const service = new ElephantTraitService()
235
+
236
+ const isSharp = service.isSharpTrait(undefined)
237
+
238
+ expect(isSharp).toBe(false)
239
+ })
240
+
241
+ test('should handle both inherited and own methods', () => {
242
+ const service = new ElephantTraitService()
243
+ const trait = {
244
+ title: 'Long and sharp tusk trait',
245
+ description: 'Description',
246
+ isSharp: true,
247
+ length: 150,
248
+ animal: undefined,
249
+ }
250
+
251
+ const isLong = service.isTitleLong(trait)
252
+ const isSharp = service.isSharpTrait(trait)
253
+
254
+ expect(isLong).toBe(true)
255
+ expect(isSharp).toBe(true)
256
+ })
257
+ })
258
+
259
+ describe('Schema Inheritance Type Safety', () => {
260
+ test('should allow ElephantService to work with elephant-specific properties', () => {
261
+ const service = new ElephantService()
262
+ const elephant = {
263
+ name: 'Babar',
264
+ sound: 'Trumpet',
265
+ trunkLength: 200,
266
+ traits: [],
267
+ }
268
+
269
+ // Should compile and work with both animal and elephant properties
270
+ const traits = service.getTraits(elephant)
271
+ const trunkLength = service.getTrunkLength(elephant)
272
+
273
+ expect(traits).toEqual([])
274
+ expect(trunkLength).toBe(200)
275
+ })
276
+
277
+ test('should allow ElephantTraitService to work with elephant trait properties', () => {
278
+ const service = new ElephantTraitService()
279
+ const trait = {
280
+ title: 'Trait',
281
+ description: 'Desc',
282
+ isSharp: true,
283
+ length: 75,
284
+ animal: undefined,
285
+ }
286
+
287
+ // Should compile and work with both animal trait and elephant trait properties
288
+ const isLong = service.isTitleLong(trait)
289
+ const isSharp = service.isSharpTrait(trait)
290
+
291
+ expect(isLong).toBe(false)
292
+ expect(isSharp).toBe(true)
293
+ })
294
+ })
295
+ })
@@ -0,0 +1,46 @@
1
+ // Animal Schema
2
+
3
+ import { ModelSchema } from '@declaro/core'
4
+ import { sortArray, ZodModel } from '@declaro/zod'
5
+ import z4 from 'zod/v4'
6
+ import { AnimalTraitsDetailSchema, AnimalTraitsSummarySchema } from './animal-trait-schema'
7
+
8
+ export const AnimalDetailSchema = z4.object({
9
+ name: z4.string(),
10
+ sound: z4.string(),
11
+ get traits() {
12
+ return z4.array(AnimalTraitsDetailSchema)
13
+ },
14
+ })
15
+
16
+ export const AnimalLookupSchema = z4.object({
17
+ id: z4.number(),
18
+ })
19
+
20
+ export const AnimalFiltersSchema = z4.object({
21
+ text: z4.string().optional(),
22
+ sound: z4.string().optional(),
23
+ })
24
+
25
+ export const AnimalSortSchema = sortArray(['name', 'sound'])
26
+
27
+ export const AnimalSummarySchema = z4.object({
28
+ name: z4.string(),
29
+ sound: z4.string(),
30
+ get traits() {
31
+ return z4.array(AnimalTraitsSummarySchema)
32
+ },
33
+ })
34
+
35
+ export const AnimalSchema = ModelSchema.create('AnimalSchema')
36
+ .read({
37
+ detail: (h) => new ZodModel('AnimalDetail', AnimalDetailSchema),
38
+ lookup: (h) => new ZodModel('AnimalLookup', AnimalLookupSchema),
39
+ })
40
+ .search({
41
+ filters: (h) => new ZodModel('AnimalFilters', AnimalFiltersSchema),
42
+ sort: (h) => new ZodModel('AnimalSort', AnimalSortSchema),
43
+ summary: (h) => new ZodModel('AnimalSummary', AnimalSummarySchema),
44
+ })
45
+
46
+ export type IAnimalSchema = typeof AnimalSchema
@@ -0,0 +1,45 @@
1
+ import { sortArray, ZodModel } from '@declaro/zod'
2
+ import { AnimalDetailSchema, AnimalSummarySchema } from './animal-schema'
3
+
4
+ // Animal Traits Schema
5
+
6
+ import { ModelSchema } from '@declaro/core'
7
+ import z4 from 'zod/v4'
8
+
9
+ export const AnimalTraitsDetailSchema = z4.object({
10
+ title: z4.string(),
11
+ description: z4.string(),
12
+ get animal() {
13
+ return AnimalDetailSchema.optional()
14
+ },
15
+ })
16
+
17
+ export const AnimalTraitsSummarySchema = z4.object({
18
+ title: z4.string(),
19
+ get animal() {
20
+ return AnimalSummarySchema.optional()
21
+ },
22
+ })
23
+
24
+ export const AnimalTraitsLookupSchema = z4.object({
25
+ id: z4.number(),
26
+ })
27
+
28
+ export const AnimalTraitsFiltersSchema = z4.object({
29
+ text: z4.string().optional(),
30
+ })
31
+
32
+ export const AnimalTraitsSortSchema = sortArray(['title'])
33
+
34
+ export const AnimalTraitsSchema = ModelSchema.create('AnimalTraitsSchema')
35
+ .read({
36
+ detail: (h) => new ZodModel('AnimalTraitsDetail', AnimalTraitsDetailSchema),
37
+ lookup: (h) => new ZodModel('AnimalTraitsLookup', AnimalTraitsLookupSchema),
38
+ })
39
+ .search({
40
+ filters: (h) => new ZodModel('AnimalTraitsFilters', AnimalTraitsFiltersSchema),
41
+ sort: (h) => new ZodModel('AnimalTraitsSort', AnimalTraitsSortSchema),
42
+ summary: (h) => new ZodModel('AnimalTraitsSummary', AnimalTraitsSummarySchema),
43
+ })
44
+
45
+ export type IAnimalTraitSchema = typeof AnimalTraitsSchema
@@ -0,0 +1,58 @@
1
+ // Elephant Schema inheriting from Animal Schema
2
+
3
+ import z4 from 'zod/v4'
4
+ import {
5
+ AnimalDetailSchema,
6
+ AnimalFiltersSchema,
7
+ AnimalLookupSchema,
8
+ AnimalSortSchema,
9
+ AnimalSummarySchema,
10
+ } from './animal-schema'
11
+ import { ModelSchema } from '@declaro/core'
12
+ import { ZodModel } from '@declaro/zod'
13
+ import { ElephantTraitsDetailSchema, ElephantTraitsSummarySchema } from './elephant-trait-schema'
14
+
15
+ export const ElephantDetailSchema = z4.object({
16
+ ...AnimalDetailSchema.shape,
17
+ trunkLength: z4.number(),
18
+ get traits() {
19
+ return z4.array(ElephantTraitsDetailSchema)
20
+ },
21
+ get elephantDetails() {
22
+ return z4.object({
23
+ favoriteFood: z4.string(),
24
+ weight: z4.number(),
25
+ })
26
+ },
27
+ })
28
+
29
+ export const ElephantSummarySchema = z4.object({
30
+ ...AnimalSummarySchema.shape,
31
+ trunkLength: z4.number(),
32
+ get traits() {
33
+ return z4.array(ElephantTraitsSummarySchema)
34
+ },
35
+ })
36
+
37
+ export const ElephantLookupSchema = z4.object({
38
+ ...AnimalLookupSchema.shape,
39
+ })
40
+
41
+ export const ElephantFiltersSchema = z4.object({
42
+ ...AnimalFiltersSchema.shape,
43
+ minTrunkLength: z4.number().optional(),
44
+ maxTrunkLength: z4.number().optional(),
45
+ })
46
+
47
+ export const ElephantSchema = ModelSchema.create('ElephantSchema')
48
+ .read({
49
+ detail: (h) => new ZodModel('ElephantDetail', ElephantDetailSchema),
50
+ lookup: (h) => new ZodModel('ElephantLookup', ElephantLookupSchema),
51
+ })
52
+ .search({
53
+ filters: (h) => new ZodModel('ElephantFilters', ElephantFiltersSchema),
54
+ sort: (h) => new ZodModel('ElephantSort', AnimalSortSchema),
55
+ summary: (h) => new ZodModel('ElephantSummary', ElephantSummarySchema),
56
+ })
57
+
58
+ export type IElephantSchema = typeof ElephantSchema
@@ -0,0 +1,53 @@
1
+ // Elephant Traits Schema inheriting from Animal Traits Schema
2
+
3
+ import z4 from 'zod/v4'
4
+ import { ModelSchema } from '@declaro/core'
5
+ import { ZodModel } from '@declaro/zod'
6
+ import {
7
+ AnimalTraitsDetailSchema,
8
+ AnimalTraitsFiltersSchema,
9
+ AnimalTraitsLookupSchema,
10
+ AnimalTraitsSortSchema,
11
+ AnimalTraitsSummarySchema,
12
+ } from './animal-trait-schema'
13
+ import { ElephantDetailSchema, ElephantSummarySchema } from './elephant-schema'
14
+
15
+ export const ElephantTraitsDetailSchema = z4.object({
16
+ ...AnimalTraitsDetailSchema.shape,
17
+ isSharp: z4.boolean(),
18
+ length: z4.number(),
19
+ get animal() {
20
+ return ElephantDetailSchema.optional()
21
+ },
22
+ })
23
+
24
+ export const ElephantTraitsSummarySchema = z4.object({
25
+ ...AnimalTraitsSummarySchema.shape,
26
+ isSharp: z4.boolean(),
27
+ length: z4.number(),
28
+ get animal() {
29
+ return ElephantSummarySchema.optional()
30
+ },
31
+ })
32
+
33
+ export const ElephantTraitsLookupSchema = z4.object({
34
+ ...AnimalTraitsLookupSchema.shape,
35
+ })
36
+
37
+ export const ElephantTraitsFiltersSchema = z4.object({
38
+ ...AnimalTraitsFiltersSchema.shape,
39
+ isSharp: z4.boolean().optional(),
40
+ })
41
+
42
+ export const ElephantTraitsSchema = ModelSchema.create('ElephantTraitsSchema')
43
+ .read({
44
+ detail: (h) => new ZodModel('ElephantTraitsDetail', ElephantTraitsDetailSchema),
45
+ lookup: (h) => new ZodModel('ElephantTraitsLookup', ElephantTraitsLookupSchema),
46
+ })
47
+ .search({
48
+ filters: (h) => new ZodModel('ElephantTraitsFilters', ElephantTraitsFiltersSchema),
49
+ sort: (h) => new ZodModel('ElephantTraitsSort', AnimalTraitsSortSchema),
50
+ summary: (h) => new ZodModel('ElephantTraitsSummary', ElephantTraitsSummarySchema),
51
+ })
52
+
53
+ export type IElephantTraitSchema = typeof ElephantTraitsSchema
@@ -1 +0,0 @@
1
- //# sourceMappingURL=mock-memory-repository.custom-lookup.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mock-memory-repository.custom-lookup.test.d.ts","sourceRoot":"","sources":["../../../../../src/test/mock/repositories/mock-memory-repository.custom-lookup.test.ts"],"names":[],"mappings":""}