@declaro/data 2.0.0-beta.125 → 2.0.0-beta.127
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 +11 -11
- package/dist/browser/index.js.map +6 -6
- package/dist/node/index.cjs +189 -92
- package/dist/node/index.cjs.map +6 -6
- package/dist/node/index.js +181 -84
- package/dist/node/index.js.map +6 -6
- package/dist/ts/application/model-controller.d.ts +15 -5
- package/dist/ts/application/model-controller.d.ts.map +1 -1
- package/dist/ts/application/read-only-model-controller.d.ts +5 -1
- package/dist/ts/application/read-only-model-controller.d.ts.map +1 -1
- package/dist/ts/domain/services/model-service.d.ts +8 -0
- package/dist/ts/domain/services/model-service.d.ts.map +1 -1
- package/dist/ts/domain/services/read-only-model-service.d.ts +8 -0
- package/dist/ts/domain/services/read-only-model-service.d.ts.map +1 -1
- package/dist/ts/shared/utils/schema-inheritance.test.d.ts +2 -0
- package/dist/ts/shared/utils/schema-inheritance.test.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/animal-schema.d.ts +57 -0
- package/dist/ts/shared/utils/test/animal-schema.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/animal-trait-schema.d.ts +55 -0
- package/dist/ts/shared/utils/test/animal-trait-schema.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/elephant-schema.d.ts +30 -0
- package/dist/ts/shared/utils/test/elephant-schema.d.ts.map +1 -0
- package/dist/ts/shared/utils/test/elephant-trait-schema.d.ts +26 -0
- package/dist/ts/shared/utils/test/elephant-trait-schema.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/application/model-controller.ts +110 -59
- package/src/application/read-only-model-controller.ts +43 -25
- package/src/domain/services/model-service.test.ts +280 -0
- package/src/domain/services/model-service.ts +98 -66
- package/src/domain/services/read-only-model-service.test.ts +230 -0
- package/src/domain/services/read-only-model-service.ts +65 -40
- package/src/shared/utils/schema-inheritance.test.ts +295 -0
- package/src/shared/utils/test/animal-schema.ts +46 -0
- package/src/shared/utils/test/animal-trait-schema.ts +45 -0
- package/src/shared/utils/test/elephant-schema.ts +58 -0
- package/src/shared/utils/test/elephant-trait-schema.ts +53 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts +0 -1
- package/dist/ts/test/mock/repositories/mock-memory-repository.custom-lookup.test.d.ts.map +0 -1
- package/src/test/mock/repositories/mock-memory-repository.custom-lookup.test.ts +0 -0
|
@@ -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":""}
|
|
File without changes
|