@baseplate-dev/project-builder-lib 0.2.1 → 0.2.3

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 (191) hide show
  1. package/dist/definition/feature/feature-utils.js +1 -1
  2. package/dist/definition/feature/feature-utils.js.map +1 -1
  3. package/dist/definition/project-definition-container.d.ts +3 -2
  4. package/dist/definition/project-definition-container.d.ts.map +1 -1
  5. package/dist/definition/project-definition-container.js +13 -7
  6. package/dist/definition/project-definition-container.js.map +1 -1
  7. package/dist/definition/project-definition-container.test-utils.d.ts.map +1 -1
  8. package/dist/definition/project-definition-container.test-utils.js +3 -7
  9. package/dist/definition/project-definition-container.test-utils.js.map +1 -1
  10. package/dist/migrations/index.d.ts.map +1 -1
  11. package/dist/migrations/index.js +2 -0
  12. package/dist/migrations/index.js.map +1 -1
  13. package/dist/migrations/migration-015-null-parent-refs.d.ts +17 -0
  14. package/dist/migrations/migration-015-null-parent-refs.d.ts.map +1 -0
  15. package/dist/migrations/migration-015-null-parent-refs.js +20 -0
  16. package/dist/migrations/migration-015-null-parent-refs.js.map +1 -0
  17. package/dist/parser/parser.d.ts +2 -2
  18. package/dist/parser/parser.d.ts.map +1 -1
  19. package/dist/parser/parser.js +11 -7
  20. package/dist/parser/parser.js.map +1 -1
  21. package/dist/plugins/metadata/types.d.ts +8 -0
  22. package/dist/plugins/metadata/types.d.ts.map +1 -1
  23. package/dist/plugins/metadata/types.js +6 -0
  24. package/dist/plugins/metadata/types.js.map +1 -1
  25. package/dist/plugins/migrations/run-migrations.js.map +1 -1
  26. package/dist/plugins/schema/index.d.ts +0 -2
  27. package/dist/plugins/schema/index.d.ts.map +1 -1
  28. package/dist/plugins/schema/index.js +0 -2
  29. package/dist/plugins/schema/index.js.map +1 -1
  30. package/dist/plugins/spec/config-spec.d.ts +3 -3
  31. package/dist/plugins/spec/config-spec.d.ts.map +1 -1
  32. package/dist/plugins/spec/config-spec.js +3 -3
  33. package/dist/plugins/spec/config-spec.js.map +1 -1
  34. package/dist/references/{ref-builder.d.ts → definition-ref-builder.d.ts} +13 -137
  35. package/dist/references/definition-ref-builder.d.ts.map +1 -0
  36. package/dist/references/definition-ref-builder.js +242 -0
  37. package/dist/references/definition-ref-builder.js.map +1 -0
  38. package/dist/references/deserialize-schema.d.ts +12 -1
  39. package/dist/references/deserialize-schema.d.ts.map +1 -1
  40. package/dist/references/deserialize-schema.js +24 -4
  41. package/dist/references/deserialize-schema.js.map +1 -1
  42. package/dist/references/extend-parser-context-with-refs.d.ts +16 -0
  43. package/dist/references/extend-parser-context-with-refs.d.ts.map +1 -0
  44. package/dist/references/extend-parser-context-with-refs.js +82 -0
  45. package/dist/references/extend-parser-context-with-refs.js.map +1 -0
  46. package/dist/references/extract-definition-refs.d.ts +19 -0
  47. package/dist/references/extract-definition-refs.d.ts.map +1 -0
  48. package/dist/references/extract-definition-refs.js +71 -0
  49. package/dist/references/extract-definition-refs.js.map +1 -0
  50. package/dist/references/fix-ref-deletions.d.ts +6 -6
  51. package/dist/references/fix-ref-deletions.d.ts.map +1 -1
  52. package/dist/references/fix-ref-deletions.js +13 -5
  53. package/dist/references/fix-ref-deletions.js.map +1 -1
  54. package/dist/references/index.d.ts +2 -1
  55. package/dist/references/index.d.ts.map +1 -1
  56. package/dist/references/index.js +2 -1
  57. package/dist/references/index.js.map +1 -1
  58. package/dist/references/markers.d.ts +22 -0
  59. package/dist/references/markers.d.ts.map +1 -0
  60. package/dist/references/markers.js +21 -0
  61. package/dist/references/markers.js.map +1 -0
  62. package/dist/references/parse-schema-with-references.d.ts +2 -2
  63. package/dist/references/parse-schema-with-references.d.ts.map +1 -1
  64. package/dist/references/parse-schema-with-references.js +13 -4
  65. package/dist/references/parse-schema-with-references.js.map +1 -1
  66. package/dist/references/resolve-zod-ref-payload-names.d.ts +1 -1
  67. package/dist/references/resolve-zod-ref-payload-names.d.ts.map +1 -1
  68. package/dist/references/serialize-schema.d.ts +2 -2
  69. package/dist/references/serialize-schema.d.ts.map +1 -1
  70. package/dist/references/serialize-schema.js +4 -3
  71. package/dist/references/serialize-schema.js.map +1 -1
  72. package/dist/references/strip-ref-markers.d.ts +7 -0
  73. package/dist/references/strip-ref-markers.d.ts.map +1 -0
  74. package/dist/references/strip-ref-markers.js +22 -0
  75. package/dist/references/strip-ref-markers.js.map +1 -0
  76. package/dist/references/types.d.ts +2 -2
  77. package/dist/references/types.d.ts.map +1 -1
  78. package/dist/schema/apps/admin/app.d.ts +958 -200
  79. package/dist/schema/apps/admin/app.d.ts.map +1 -1
  80. package/dist/schema/apps/admin/app.js +2 -3
  81. package/dist/schema/apps/admin/app.js.map +1 -1
  82. package/dist/schema/apps/admin/sections/base.d.ts +15 -3
  83. package/dist/schema/apps/admin/sections/base.d.ts.map +1 -1
  84. package/dist/schema/apps/admin/sections/base.js +4 -4
  85. package/dist/schema/apps/admin/sections/base.js.map +1 -1
  86. package/dist/schema/apps/admin/sections/crud-form/admin-crud-input.d.ts +12 -6
  87. package/dist/schema/apps/admin/sections/crud-form/admin-crud-input.d.ts.map +1 -1
  88. package/dist/schema/apps/admin/sections/crud-form/admin-crud-input.js +9 -5
  89. package/dist/schema/apps/admin/sections/crud-form/admin-crud-input.js.map +1 -1
  90. package/dist/schema/apps/admin/sections/crud-form/built-in-input.d.ts +19 -19
  91. package/dist/schema/apps/admin/sections/crud-form/built-in-input.d.ts.map +1 -1
  92. package/dist/schema/apps/admin/sections/crud-form/built-in-input.js +18 -19
  93. package/dist/schema/apps/admin/sections/crud-form/built-in-input.js.map +1 -1
  94. package/dist/schema/apps/admin/sections/crud-form/types.d.ts +1 -1
  95. package/dist/schema/apps/admin/sections/crud-form/types.d.ts.map +1 -1
  96. package/dist/schema/apps/admin/sections/crud.d.ts +468 -130
  97. package/dist/schema/apps/admin/sections/crud.d.ts.map +1 -1
  98. package/dist/schema/apps/admin/sections/crud.js +14 -14
  99. package/dist/schema/apps/admin/sections/crud.js.map +1 -1
  100. package/dist/schema/apps/backend/index.d.ts +1 -1
  101. package/dist/schema/apps/types.d.ts +1 -1
  102. package/dist/schema/apps/types.js +1 -1
  103. package/dist/schema/apps/web/index.d.ts +2 -2
  104. package/dist/schema/apps/web/index.d.ts.map +1 -1
  105. package/dist/schema/apps/web/index.js +2 -3
  106. package/dist/schema/apps/web/index.js.map +1 -1
  107. package/dist/schema/auth/index.d.ts +1 -1
  108. package/dist/schema/auth/index.js +1 -1
  109. package/dist/schema/creator/extend-parser-context-with-defaults.d.ts +13 -0
  110. package/dist/schema/creator/extend-parser-context-with-defaults.d.ts.map +1 -0
  111. package/dist/schema/creator/extend-parser-context-with-defaults.js +52 -0
  112. package/dist/schema/creator/extend-parser-context-with-defaults.js.map +1 -0
  113. package/dist/schema/creator/schema-creator.d.ts +3 -2
  114. package/dist/schema/creator/schema-creator.d.ts.map +1 -1
  115. package/dist/schema/creator/schema-creator.js +10 -1
  116. package/dist/schema/creator/schema-creator.js.map +1 -1
  117. package/dist/schema/creator/types.d.ts +57 -2
  118. package/dist/schema/creator/types.d.ts.map +1 -1
  119. package/dist/schema/features/feature.d.ts +29 -15
  120. package/dist/schema/features/feature.d.ts.map +1 -1
  121. package/dist/schema/features/feature.js +7 -4
  122. package/dist/schema/features/feature.js.map +1 -1
  123. package/dist/schema/features/theme.d.ts +12 -12
  124. package/dist/schema/models/enums.d.ts +62 -19
  125. package/dist/schema/models/enums.d.ts.map +1 -1
  126. package/dist/schema/models/enums.js +5 -4
  127. package/dist/schema/models/enums.js.map +1 -1
  128. package/dist/schema/models/graphql.d.ts +139 -55
  129. package/dist/schema/models/graphql.d.ts.map +1 -1
  130. package/dist/schema/models/graphql.js +36 -80
  131. package/dist/schema/models/graphql.js.map +1 -1
  132. package/dist/schema/models/index.d.ts +881 -299
  133. package/dist/schema/models/index.d.ts.map +1 -1
  134. package/dist/schema/models/index.js +24 -19
  135. package/dist/schema/models/index.js.map +1 -1
  136. package/dist/schema/models/transformers/built-in-transformers.d.ts +87 -23
  137. package/dist/schema/models/transformers/built-in-transformers.d.ts.map +1 -1
  138. package/dist/schema/models/transformers/built-in-transformers.js +10 -10
  139. package/dist/schema/models/transformers/built-in-transformers.js.map +1 -1
  140. package/dist/schema/models/transformers/transformers.d.ts +14 -8
  141. package/dist/schema/models/transformers/transformers.d.ts.map +1 -1
  142. package/dist/schema/models/transformers/transformers.js +9 -5
  143. package/dist/schema/models/transformers/transformers.js.map +1 -1
  144. package/dist/schema/models/transformers/types.d.ts +4 -3
  145. package/dist/schema/models/transformers/types.d.ts.map +1 -1
  146. package/dist/schema/models/transformers/types.js +2 -4
  147. package/dist/schema/models/transformers/types.js.map +1 -1
  148. package/dist/schema/plugins/definition.d.ts +64 -70
  149. package/dist/schema/plugins/definition.d.ts.map +1 -1
  150. package/dist/schema/plugins/definition.js +18 -16
  151. package/dist/schema/plugins/definition.js.map +1 -1
  152. package/dist/schema/project-definition.d.ts +2192 -682
  153. package/dist/schema/project-definition.d.ts.map +1 -1
  154. package/dist/schema/project-definition.js +1 -2
  155. package/dist/schema/project-definition.js.map +1 -1
  156. package/dist/schema/settings.d.ts +15 -15
  157. package/dist/schema/template-extractor/index.d.ts +1 -1
  158. package/dist/tools/model-merger/model-merger.d.ts +15 -14
  159. package/dist/tools/model-merger/model-merger.d.ts.map +1 -1
  160. package/dist/tools/model-merger/model-merger.js +8 -4
  161. package/dist/tools/model-merger/model-merger.js.map +1 -1
  162. package/dist/web/hooks/index.d.ts +1 -1
  163. package/dist/web/hooks/index.d.ts.map +1 -1
  164. package/dist/web/hooks/index.js +1 -1
  165. package/dist/web/hooks/index.js.map +1 -1
  166. package/dist/web/hooks/use-definition-schema.d.ts +3 -0
  167. package/dist/web/hooks/use-definition-schema.d.ts.map +1 -0
  168. package/dist/web/hooks/use-definition-schema.js +7 -0
  169. package/dist/web/hooks/use-definition-schema.js.map +1 -0
  170. package/dist/web/hooks/use-project-definition.d.ts +3 -3
  171. package/dist/web/hooks/use-project-definition.d.ts.map +1 -1
  172. package/package.json +6 -6
  173. package/dist/plugins/schema/common.d.ts +0 -6
  174. package/dist/plugins/schema/common.d.ts.map +0 -1
  175. package/dist/plugins/schema/common.js +0 -2
  176. package/dist/plugins/schema/common.js.map +0 -1
  177. package/dist/plugins/schema/parser.d.ts +0 -19
  178. package/dist/plugins/schema/parser.d.ts.map +0 -1
  179. package/dist/plugins/schema/parser.js +0 -41
  180. package/dist/plugins/schema/parser.js.map +0 -1
  181. package/dist/plugins/schema/zod-with-plugins.d.ts +0 -12
  182. package/dist/plugins/schema/zod-with-plugins.d.ts.map +0 -1
  183. package/dist/plugins/schema/zod-with-plugins.js +0 -26
  184. package/dist/plugins/schema/zod-with-plugins.js.map +0 -1
  185. package/dist/references/ref-builder.d.ts.map +0 -1
  186. package/dist/references/ref-builder.js +0 -492
  187. package/dist/references/ref-builder.js.map +0 -1
  188. package/dist/web/hooks/use-plugin-enhanced-schema.d.ts +0 -4
  189. package/dist/web/hooks/use-plugin-enhanced-schema.d.ts.map +0 -1
  190. package/dist/web/hooks/use-plugin-enhanced-schema.js +0 -8
  191. package/dist/web/hooks/use-plugin-enhanced-schema.js.map +0 -1
@@ -1,12 +1,6 @@
1
1
  import type { Paths } from 'type-fest';
2
- import type { input, ParseInput, ParseReturnType, TypeOf, ZodTypeAny, ZodTypeDef } from 'zod';
3
- import { z, ZodType } from 'zod';
4
2
  import type { DefinitionEntity, DefinitionEntityType, DefinitionReference, ReferencePath } from './types.js';
5
- /**
6
- * Zod reference ID schema: a string with a minimum length of 1.
7
- */
8
- export declare const zRefId: z.ZodString;
9
- type PathInput<Type> = Exclude<Paths<Type>, number>;
3
+ export type PathInput<Type> = Exclude<Paths<Type>, number>;
10
4
  interface ContextValue {
11
5
  context: string;
12
6
  }
@@ -71,7 +65,7 @@ interface DefinitionEntityInputWithoutParent<TInput, TEntityType extends Definit
71
65
  * Depending on the entity type’s requirements, this type resolves to either the
72
66
  * with- or without-parent version.
73
67
  */
74
- type DefinitionEntityInput<TInput, TEntityType extends DefinitionEntityType, TPath extends PathInput<TInput> | undefined = undefined, TIDKey extends string = 'id'> = TEntityType['parentType'] extends undefined ? DefinitionEntityInputWithoutParent<TInput, TEntityType, TPath, TIDKey> : DefinitionEntityInputWithParent<TInput, TEntityType, TPath, TIDKey>;
68
+ export type DefinitionEntityInput<TInput, TEntityType extends DefinitionEntityType, TPath extends PathInput<TInput> | undefined = undefined, TIDKey extends string = 'id'> = TEntityType['parentType'] extends undefined ? DefinitionEntityInputWithoutParent<TInput, TEntityType, TPath, TIDKey> : DefinitionEntityInputWithParent<TInput, TEntityType, TPath, TIDKey>;
75
69
  /**
76
70
  * Base interface for defining a reference input.
77
71
  * @template TInput - The overall input type.
@@ -91,21 +85,26 @@ interface DefinitionReferenceInputWithoutParent<TInput, TEntityType extends Defi
91
85
  /**
92
86
  * Depending on the entity type’s requirements, defines the input required to create a definition reference.
93
87
  */
94
- type DefinitionReferenceInput<TInput, TEntityType extends DefinitionEntityType> = TEntityType['parentType'] extends undefined ? DefinitionReferenceInputWithoutParent<TInput, TEntityType> : DefinitionReferenceInputWithParent<TInput, TEntityType>;
88
+ export type DefinitionReferenceInput<TInput, TEntityType extends DefinitionEntityType> = TEntityType['parentType'] extends undefined ? DefinitionReferenceInputWithoutParent<TInput, TEntityType> : DefinitionReferenceInputWithParent<TInput, TEntityType>;
95
89
  /**
96
90
  * Entity with a name resolver.
97
91
  */
98
92
  interface DefinitionEntityWithNameResolver extends Omit<DefinitionEntity, 'name'> {
99
93
  nameResolver: DefinitionEntityNameResolver;
100
94
  }
101
- interface RefBuilderContext {
95
+ export interface RefBuilderContext {
102
96
  pathMap: Map<string, {
103
97
  path: ReferencePath;
104
98
  type: DefinitionEntityType;
105
99
  }>;
106
100
  }
101
+ export interface ZodRefBuilderInterface<TInput> {
102
+ addReference<TEntityType extends DefinitionEntityType>(reference: DefinitionReferenceInput<TInput, TEntityType>): void;
103
+ addEntity<TEntityType extends DefinitionEntityType, TPath extends PathInput<TInput> | undefined = undefined, TIDKey extends string | PathInput<TInput> = 'id'>(entity: DefinitionEntityInput<TInput, TEntityType, TPath, TIDKey>): void;
104
+ addPathToContext(path: PathInput<TInput>, type: DefinitionEntityType, context: string): void;
105
+ }
107
106
  /**
108
- * ZodRefBuilder is responsible for constructing reference paths, and registering
107
+ * DefinitionRefBuilder is responsible for constructing reference paths, and registering
109
108
  * references and entities as defined in a Zod schema.
110
109
  *
111
110
  * The builder uses a prefix (usually the current parsing path) and context (a
@@ -113,7 +112,7 @@ interface RefBuilderContext {
113
112
  *
114
113
  * @template TInput - The type of the input data being parsed.
115
114
  */
116
- export declare class ZodRefBuilder<TInput> {
115
+ export declare class DefinitionRefBuilder<TInput> implements ZodRefBuilderInterface<TInput> {
117
116
  readonly references: DefinitionReference[];
118
117
  readonly entitiesWithNameResolver: DefinitionEntityWithNameResolver[];
119
118
  readonly pathPrefix: ReferencePath;
@@ -208,96 +207,7 @@ export declare class ZodRefBuilder<TInput> {
208
207
  *
209
208
  * @template Input - The input data type.
210
209
  */
211
- type ZodBuilderFunction<Input> = (builder: ZodRefBuilder<Input>, data: Input) => void;
212
- /**
213
- * Definition for a ZodRef wrapper type that adds reference/entity capabilities.
214
- *
215
- * @template T - The inner Zod type.
216
- */
217
- export interface ZodRefDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
218
- innerType: T;
219
- builder?: ZodBuilderFunction<input<T>>;
220
- }
221
- /**
222
- * ZodRef wraps an inner Zod type and enhances it with the ability to register
223
- * and process entity references. During parsing, it delegates to a builder (if present)
224
- * to collect references and entities before delegating to the inner type.
225
- *
226
- * @template T - The inner Zod type.
227
- */
228
- export declare class ZodRef<T extends ZodTypeAny> extends ZodType<TypeOf<T>, ZodRefDef<T>, input<T>> {
229
- /**
230
- * The core parse method that:
231
- * 1. Retrieves (or creates) the builder context from the parent.
232
- * 2. Runs the builder function (if present) to register references/entities.
233
- * 3. Delegates parsing to the inner type.
234
- * 4. Transforms the output to replace entity id placeholders with generated ids.
235
- *
236
- * @param input - The Zod parse input.
237
- * @returns The parse result.
238
- */
239
- _parse(input: ParseInput): ParseReturnType<TypeOf<T>>;
240
- /**
241
- * Returns the inner Zod type.
242
- * @returns The wrapped inner Zod type.
243
- */
244
- innerType(): T;
245
- /**
246
- * Adds an entity registration to the current ZodRef.
247
- *
248
- * @param entity - Either an entity definition or a function that returns one.
249
- * @returns A new ZodRef instance with the entity registration added.
250
- */
251
- addEntity<TEntityType extends DefinitionEntityType, TPath extends PathInput<input<T>> | undefined = undefined, TIDKey extends string = 'id'>(entity: DefinitionEntityInput<input<T>, TEntityType, TPath, TIDKey> | ((data: input<T>) => DefinitionEntityInput<input<T>, TEntityType, TPath, TIDKey>)): ZodRef<T>;
252
- /**
253
- * Adds a reference registration to the current ZodRef.
254
- *
255
- * @param reference - Either a reference definition or a function that returns one.
256
- * @returns A new ZodRef instance with the reference registration added.
257
- */
258
- addReference<TEntityType extends DefinitionEntityType>(reference: DefinitionReferenceInput<input<T>, TEntityType> | ((data: input<T>) => DefinitionReferenceInput<input<T>, TEntityType>)): ZodRef<T>;
259
- /**
260
- * Applies a custom builder function to the ZodRef.
261
- * @param builder - The builder function that registers additional references/entities.
262
- * @returns A new ZodRef instance with the builder applied.
263
- */
264
- refBuilder(builder: ZodBuilderFunction<input<T>>): ZodRef<T>;
265
- /**
266
- * Creates a new ZodRef instance wrapping a given Zod type with an optional builder.
267
- * @param type - The inner Zod type.
268
- * @param builder - Optional builder function to register references/entities.
269
- * @returns A new ZodRef instance.
270
- */
271
- static create: <T_1 extends ZodTypeAny>(type: T_1, builder?: ZodBuilderFunction<input<T_1>>) => ZodRef<T_1>;
272
- }
273
- /**
274
- * Convenience function for creating a ZodRef using a schema and an optional builder.
275
- * @param schema - The base Zod schema.
276
- * @param builder - Optional builder function.
277
- * @returns A new ZodRef instance.
278
- */
279
- export declare function zRefBuilder<T extends z.ZodType>(schema: T, builder?: ZodBuilderFunction<TypeOf<T>>): ZodRef<T>;
280
- /**
281
- * Convenience function for creating a ZodRef with a reference added.
282
- * @param schema - The base Zod schema.
283
- * @param reference - Either a reference definition or a function returning one.
284
- * @returns A new ZodRef instance with the reference registration.
285
- */
286
- export declare function zRef<T extends z.ZodType, TEntityType extends DefinitionEntityType>(schema: T, reference: DefinitionReferenceInput<input<T>, TEntityType> | ((data: input<T>) => DefinitionReferenceInput<input<T>, TEntityType>)): ZodRef<T>;
287
- /**
288
- * Convenience function for creating a ZodRef that registers an entity.
289
- * This function also sets the id key on the schema using zRefId.
290
- *
291
- * @template TObject - The Zod object type.
292
- * @template TEntityType - The entity type.
293
- * @template TPath - The path type.
294
- * @param schema - The base Zod object schema.
295
- * @param entity - Either an entity definition or a function returning one.
296
- * @returns A new ZodRef instance with the entity registration.
297
- */
298
- export declare function zEnt<TObject extends z.SomeZodObject, TEntityType extends DefinitionEntityType, TPath extends PathInput<input<TObject>>>(schema: TObject, entity: DefinitionEntityInput<z.input<TObject>, TEntityType, TPath> | ((data: z.input<TObject>) => DefinitionEntityInput<z.input<TObject>, TEntityType, TPath>)): ZodRef<z.ZodObject<TObject['shape'] & {
299
- id: z.ZodType<string, z.ZodAnyDef, string>;
300
- }, TObject['_def']['unknownKeys'], TObject['_def']['catchall']>>;
210
+ export type ZodBuilderFunction<Input> = (builder: ZodRefBuilderInterface<Input>, data: Input) => void;
301
211
  /**
302
212
  * Payload returned after parsing, containing the data, references, and entities.
303
213
  *
@@ -308,39 +218,5 @@ export interface ZodRefPayload<TData> {
308
218
  references: DefinitionReference[];
309
219
  entitiesWithNameResolver: DefinitionEntityWithNameResolver[];
310
220
  }
311
- /**
312
- * Definition for a ZodRefWrapper, which wraps a schema for collecting references and entities.
313
- *
314
- * @template T - The inner Zod type.
315
- */
316
- export interface ZodRefWrapperDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
317
- innerType: T;
318
- }
319
- /**
320
- * ZodRefWrapper is used for initializing parsing that collects references and entities.
321
- *
322
- * @template T - The inner Zod type.
323
- */
324
- export declare class ZodRefWrapper<T extends ZodTypeAny> extends ZodType<ZodRefPayload<TypeOf<T>>, ZodRefWrapperDef<T>, input<T>> {
325
- /**
326
- * Core parse method that:
327
- * 1. Initializes a fresh reference context.
328
- * 2. Parses using the inner type while injecting the context.
329
- * 3. Returns a payload containing the parsed data, along with references and entities.
330
- *
331
- * @param input - The parse input.
332
- * @returns The parsed payload.
333
- */
334
- _parse(input: ParseInput): ParseReturnType<ZodRefPayload<TypeOf<T>>>;
335
- /**
336
- * Creates a new ZodRefWrapper instance.
337
- * @param type - The inner Zod type.
338
- * @param options - Options for the ZodRefWrapper.
339
- * @param options.skipReferenceNameResolution - Flag to skip resolving references to names (serialized definitions use resolved name references).
340
- * @param options.allowInvalidReferences - Flag to allow invalid references (used for testing deletes).
341
- * @returns A new instance of ZodRefWrapper.
342
- */
343
- static create: <T_1 extends ZodTypeAny>(type: T_1) => ZodRefWrapper<T_1>;
344
- }
345
221
  export {};
346
- //# sourceMappingURL=ref-builder.d.ts.map
222
+ //# sourceMappingURL=definition-ref-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition-ref-builder.d.ts","sourceRoot":"","sources":["../../src/references/definition-ref-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAIvC,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACd,MAAM,YAAY,CAAC;AAIpB,MAAM,MAAM,SAAS,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AAE3D,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;AAE/D;;;;GAIG;AACH,MAAM,WAAW,4BAA4B,CAC3C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,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AAC,MAAM,CAAC,EACvB,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,MAAM,GACd,IAAI;CAGR;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,KAAK,IAAI,CACtC,OAAO,EAAE,sBAAsB,CAAC,KAAK,CAAC,EACtC,IAAI,EAAE,KAAK,KACR,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK;IAClC,IAAI,EAAE,KAAK,CAAC;IACZ,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,wBAAwB,EAAE,gCAAgC,EAAE,CAAC;CAC9D"}
@@ -0,0 +1,242 @@
1
+ import { get } from 'es-toolkit/compat';
2
+ import { stripRefMarkers } from './strip-ref-markers.js';
3
+ /**
4
+ * Creates a definition entity name resolver.
5
+ * @param entityNameResolver - The entity name resolver.
6
+ * @returns The definition entity name resolver.
7
+ */
8
+ export function createDefinitionEntityNameResolver(entityNameResolver) {
9
+ return entityNameResolver;
10
+ }
11
+ /**
12
+ * DefinitionRefBuilder is responsible for constructing reference paths, and registering
13
+ * references and entities as defined in a Zod schema.
14
+ *
15
+ * The builder uses a prefix (usually the current parsing path) and context (a
16
+ * shared map for resolving relative references) to build complete reference paths.
17
+ *
18
+ * @template TInput - The type of the input data being parsed.
19
+ */
20
+ export class DefinitionRefBuilder {
21
+ /**
22
+ * Creates a new builder instance.
23
+ * @param pathPrefix - The starting path for all references.
24
+ * @param context - Shared context including a path map and deserialize flag.
25
+ * @param data - The data being parsed.
26
+ */
27
+ constructor(pathPrefix, context, data) {
28
+ Object.defineProperty(this, "references", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "entitiesWithNameResolver", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+ Object.defineProperty(this, "pathPrefix", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: void 0
45
+ });
46
+ Object.defineProperty(this, "context", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: void 0
51
+ });
52
+ Object.defineProperty(this, "pathMap", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: void 0
57
+ });
58
+ Object.defineProperty(this, "data", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: void 0
63
+ });
64
+ this.references = [];
65
+ this.entitiesWithNameResolver = [];
66
+ this.pathPrefix = pathPrefix;
67
+ this.context = context;
68
+ this.pathMap = new Map();
69
+ this.data = data;
70
+ }
71
+ /**
72
+ * Converts a dot-separated string path into an array of keys.
73
+ * @param path - A string (e.g. "a.b.0.c") representing the path.
74
+ * @returns An array of keys (numbers for numeric strings, otherwise strings).
75
+ */
76
+ _constructPathWithoutPrefix(path) {
77
+ if (!path)
78
+ return [];
79
+ const pathComponents = path
80
+ .split('.')
81
+ .map((key) => (/^[0-9]+$/.test(key) ? Number.parseInt(key, 10) : key));
82
+ return pathComponents;
83
+ }
84
+ /**
85
+ * Prepends the builder's path prefix to the provided path.
86
+ * @param path - The dot-separated path string.
87
+ * @returns The complete reference path as an array.
88
+ */
89
+ _constructPath(path) {
90
+ if (!path)
91
+ return this.pathPrefix;
92
+ return [...this.pathPrefix, ...this._constructPathWithoutPrefix(path)];
93
+ }
94
+ /**
95
+ * Constructs a reference path that may be defined directly as a string or indirectly
96
+ * via a context object. If a context object is provided, the function looks up the
97
+ * actual path from the builder's context.
98
+ *
99
+ * @param path - Either a dot-separated string path or an object with a context key.
100
+ * @param expectedEntityType - The entity type expected for this context.
101
+ * @returns The resolved reference path.
102
+ * @throws If the context cannot be found or its type does not match.
103
+ */
104
+ _constructPathWithContext(path, expectedEntityType) {
105
+ if (typeof path === 'string') {
106
+ return this._constructPath(path);
107
+ }
108
+ // Lookup the context for the given key.
109
+ const pathContext = this.context.pathMap.get(path.context);
110
+ if (!pathContext) {
111
+ throw new Error(`Could not find context for ${path.context} from ${this.pathPrefix.join('.')}`);
112
+ }
113
+ if (pathContext.type !== expectedEntityType) {
114
+ throw new Error(`Attempted to retrieve context for ${path.context} from ${this.pathPrefix.join('.')} expecting ${expectedEntityType.name}, but found ${pathContext.type.name}`);
115
+ }
116
+ return pathContext.path;
117
+ }
118
+ /**
119
+ * Registers a reference based on the provided input definition.
120
+ *
121
+ * Flow:
122
+ * 1. Validate that the parent path is provided if required (and vice versa).
123
+ * 2. Compute the reference path; if the path is empty, use the entire data.
124
+ * 3. If the referenced value is null or undefined, skip adding the reference.
125
+ * 4. Otherwise, add the reference and, if requested, register its context.
126
+ *
127
+ * @param reference - The reference definition.
128
+ * @throws If parent path usage is incorrect.
129
+ */
130
+ addReference(reference) {
131
+ if (!reference.type.parentType && reference.parentPath) {
132
+ throw new Error(`Parent path does nothing since reference does not have parent`);
133
+ }
134
+ if (reference.type.parentType && !reference.parentPath) {
135
+ throw new Error(`Parent path required if reference type has parent type`);
136
+ }
137
+ // Compute the path without prefix once.
138
+ const refPathWithoutPrefix = this._constructPathWithoutPrefix(reference.path);
139
+ // If the path is empty, use the entire data; otherwise, retrieve the value.
140
+ const refValue = refPathWithoutPrefix.length === 0
141
+ ? this.data
142
+ : get(this.data, refPathWithoutPrefix);
143
+ if (refValue === undefined || refValue === null)
144
+ return;
145
+ const fullPath = this._constructPath(reference.path);
146
+ this.references.push({
147
+ type: reference.type,
148
+ path: fullPath,
149
+ parentPath: reference.parentPath &&
150
+ reference.type.parentType &&
151
+ this._constructPathWithContext(reference.parentPath, reference.type.parentType),
152
+ onDelete: reference.onDelete,
153
+ });
154
+ // Optionally, add this path to the shared context.
155
+ if (reference.addContext) {
156
+ this._addPathToContext(fullPath, reference.type, reference.addContext);
157
+ }
158
+ }
159
+ /**
160
+ * Registers an entity based on the provided definition.
161
+ *
162
+ * Flow:
163
+ * 1. Validate that not both a name and a name reference path are provided.
164
+ * 2. Compute the full entity path.
165
+ * 3. Resolve the entity ID:
166
+ * - Use the provided idPath if available; otherwise, default to appending 'id'
167
+ * to the entity path.
168
+ * - If no id is found, generate a new one.
169
+ * 4. Resolve the entity name:
170
+ * - Use the provided resolveName if available; otherwise, default to using the
171
+ * name path.
172
+ * 5. Register the entity in either the direct entities list or the name-ref list.
173
+ * 6. Optionally, add the entity’s id path to the shared context.
174
+ *
175
+ * @param entity - The entity definition.
176
+ * @throws If both name and nameRefPath are provided or if no name is resolved.
177
+ */
178
+ addEntity(entity) {
179
+ // Build the full path for the entity.
180
+ const path = this._constructPath(entity.path);
181
+ // Resolve the id path: if provided use it; otherwise, assume the id is at "entity.path.id"
182
+ const idPath = entity.idPath
183
+ ? this._constructPathWithoutPrefix(entity.idPath)
184
+ : [...this._constructPathWithoutPrefix(entity.path), 'id'];
185
+ const id = get(this.data, idPath);
186
+ if (!id) {
187
+ throw new Error(`No id found for entity ${entity.type.name}`);
188
+ }
189
+ if (!entity.type.isId(id)) {
190
+ throw new Error(`Invalid id: ${id} for entity ${entity.type.name}`);
191
+ }
192
+ // Resolve the name: if getNameResolver is provided, use it to build the name resolver; otherwise,
193
+ // use the default name resolver.
194
+ const getNameResolver = entity.getNameResolver ?? ((value) => get(value, 'name'));
195
+ const nameResolver = getNameResolver(stripRefMarkers(this.data));
196
+ // Base entity definition shared between regular entities and those with a name reference.
197
+ const entityBase = {
198
+ id,
199
+ type: entity.type,
200
+ path,
201
+ idPath: [...this.pathPrefix, ...idPath],
202
+ parentPath: entity.parentPath &&
203
+ entity.type.parentType &&
204
+ this._constructPathWithContext(entity.parentPath, entity.type.parentType),
205
+ };
206
+ this.entitiesWithNameResolver.push({
207
+ ...entityBase,
208
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- needed to allow more specific generic typed to be put in here
209
+ nameResolver: typeof nameResolver === 'string'
210
+ ? { resolveName: () => nameResolver }
211
+ : nameResolver,
212
+ });
213
+ // Optionally add the id path to the context.
214
+ if (entity.addContext) {
215
+ this._addPathToContext([...this.pathPrefix, ...idPath], entity.type, entity.addContext);
216
+ }
217
+ }
218
+ /**
219
+ * Registers a given path into the builder's context map.
220
+ * @param path - The full reference path.
221
+ * @param type - The entity type associated with the path.
222
+ * @param context - A unique key to identify this context.
223
+ * @throws If the context key is already registered.
224
+ */
225
+ _addPathToContext(path, type, context) {
226
+ // For now, allow overriding contexts to maintain compatibility
227
+ this.pathMap.set(context, { path, type });
228
+ // Also register in the shared context for other builders to access
229
+ this.context.pathMap.set(context, { path, type });
230
+ }
231
+ /**
232
+ * Convenience method that builds a full path from a dot-separated string and
233
+ * adds it to the context.
234
+ * @param path - The dot-separated string path.
235
+ * @param type - The entity type.
236
+ * @param context - The context key.
237
+ */
238
+ addPathToContext(path, type, context) {
239
+ this._addPathToContext(this._constructPath(path), type, context);
240
+ }
241
+ }
242
+ //# sourceMappingURL=definition-ref-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition-ref-builder.js","sourceRoot":"","sources":["../../src/references/definition-ref-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AASxC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAkCzD;;;;GAIG;AACH,MAAM,UAAU,kCAAkC,CAGhD,kBAA4D;IAE5D,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAwID;;;;;;;;GAQG;AACH,MAAM,OAAO,oBAAoB;IAa/B;;;;;OAKG;IACH,YACE,UAAyB,EACzB,OAA0B,EAC1B,IAAY;QAnBL;;;;;WAAkC;QAClC;;;;;WAA6D;QAC7D;;;;;WAA0B;QAC1B;;;;;WAA2B;QAC3B;;;;;WAGP;QACO;;;;;WAAa;QAapB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,wBAAwB,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,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EACvB,IAA0B,EAC1B,OAAe;QAEf,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;CACF"}
@@ -1,4 +1,15 @@
1
1
  import type { TypeOf, z } from 'zod';
2
+ import type { DefinitionSchemaCreator, DefinitionSchemaCreatorOptions } from '#src/schema/creator/types.js';
2
3
  import type { ResolvedZodRefPayload } from './types.js';
3
- export declare function deserializeSchemaWithReferences<TSchema extends z.ZodType>(schema: TSchema, input: unknown): ResolvedZodRefPayload<TypeOf<TSchema>>;
4
+ /**
5
+ * Deserialize a schema with references using the new transform-based approach.
6
+ * This function converts human-readable names back to entity IDs.
7
+ *
8
+ * @template T - The schema creator type
9
+ * @param schemaCreator - The schema creator function
10
+ * @param input - The input data with names instead of IDs
11
+ * @param options - Options for the schema creator (excluding transformReferences)
12
+ * @returns The resolved payload with IDs instead of names
13
+ */
14
+ export declare function deserializeSchemaWithTransformedReferences<T extends DefinitionSchemaCreator>(schemaCreator: T, input: unknown, options: Omit<DefinitionSchemaCreatorOptions, 'transformReferences'>): ResolvedZodRefPayload<ReturnType<T> extends z.ZodType ? TypeOf<ReturnType<T>> : unknown>;
4
15
  //# sourceMappingURL=deserialize-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deserialize-schema.d.ts","sourceRoot":"","sources":["../../src/references/deserialize-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMrC,OAAO,KAAK,EAAoB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQ1E,wBAAgB,+BAA+B,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,EACvE,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,OAAO,GACb,qBAAqB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CA0FxC"}
1
+ {"version":3,"file":"deserialize-schema.d.ts","sourceRoot":"","sources":["../../src/references/deserialize-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMrC,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAoB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQ1E;;;;;;;;;GASG;AACH,wBAAgB,0CAA0C,CACxD,CAAC,SAAS,uBAAuB,EAEjC,aAAa,EAAE,CAAC,EAChB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,IAAI,CAAC,8BAA8B,EAAE,qBAAqB,CAAC,GACnE,qBAAqB,CACtB,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAClE,CAYA"}
@@ -1,15 +1,35 @@
1
1
  import { toposort } from '@baseplate-dev/utils';
2
2
  import { groupBy, keyBy, uniq } from 'es-toolkit';
3
3
  import { get, set } from 'es-toolkit/compat';
4
- import { parseSchemaWithReferences } from './parse-schema-with-references.js';
4
+ import { parseSchemaWithTransformedReferences } from './parse-schema-with-references.js';
5
5
  function referenceToNameParentId(name, parentId) {
6
6
  return JSON.stringify({ name, parentId });
7
7
  }
8
- export function deserializeSchemaWithReferences(schema, input) {
9
- const payload = parseSchemaWithReferences(schema, input, {
8
+ /**
9
+ * Deserialize a schema with references using the new transform-based approach.
10
+ * This function converts human-readable names back to entity IDs.
11
+ *
12
+ * @template T - The schema creator type
13
+ * @param schemaCreator - The schema creator function
14
+ * @param input - The input data with names instead of IDs
15
+ * @param options - Options for the schema creator (excluding transformReferences)
16
+ * @returns The resolved payload with IDs instead of names
17
+ */
18
+ export function deserializeSchemaWithTransformedReferences(schemaCreator, input, options) {
19
+ const payload = parseSchemaWithTransformedReferences(schemaCreator, input, options, {
10
20
  skipReferenceNameResolution: true,
11
21
  });
12
- // resolve all references
22
+ // Use the same resolution logic as the original function
23
+ return resolveReferencesToIds(payload);
24
+ }
25
+ /**
26
+ * Internal function to resolve entity names to IDs in the payload.
27
+ * This is shared logic between the old and new approaches.
28
+ *
29
+ * @param payload - The parsed payload with entities and references
30
+ * @returns The payload with references resolved to IDs
31
+ */
32
+ function resolveReferencesToIds(payload) {
13
33
  const { references, entities, data } = payload;
14
34
  // check we don't have more entities than IDs
15
35
  const entitiesById = groupBy(entities, (entity) => entity.id);
@@ -1 +1 @@
1
- {"version":3,"file":"deserialize-schema.js","sourceRoot":"","sources":["../../src/references/deserialize-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAI7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,SAAS,uBAAuB,CAAC,IAAY,EAAE,QAAiB;IAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,MAAe,EACf,KAAc;IAEd,MAAM,OAAO,GAAG,yBAAyB,CAAC,MAAM,EAAE,KAAK,EAAE;QACvD,2BAA2B,EAAE,IAAI;KAClC,CAAC,CAAC;IAEH,yBAAyB;IACzB,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAE/C,6CAA6C;IAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC9D,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAC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AU;gBACzB,CAAC,CAAE,GAAG,CAAC,IAAI,EAAE,UAAU,CAAY;gBACnC,CAAC,CAAC,SAAS,CAAC;YAEd,IAAI,UAAU,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAC/C,MAAM,IAAI,KAAK,CACb,kCAAkC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CACzD,CAAC;YACJ,CAAC;YAED,OAAO,uBAAuB,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEL,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAW,CAAC;YAC3C,mFAAmF;YACnF,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,IAAK,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAY,CAAC;YACzE,MAAM,YAAY,GAAG,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAE7D,MAAM,cAAc,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAC;YAC5D,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACb,gCAAgC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAChD,GAAG,CAAC,IAAI,CAAC,IACX,IAAI,YAAY,GAAG,CACpB,CAAC;YACJ,CAAC;YACD,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Paths } from 'type-fest';
2
+ import { z } from 'zod';
3
+ import type { DefinitionEntityType } from '#src/index.js';
4
+ import type { DefinitionSchemaCreatorOptions } from '#src/schema/index.js';
5
+ import type { DefinitionEntityInput, DefinitionReferenceInput, ZodBuilderFunction } from './definition-ref-builder.js';
6
+ export type WithRefType = <TEntityType extends DefinitionEntityType>(reference: DefinitionReferenceInput<string, TEntityType>) => z.ZodEffects<z.ZodString>;
7
+ type PathInput<Type> = Exclude<Paths<Type>, number>;
8
+ export type WithEntType = <TObject extends z.SomeZodObject, TEntityType extends DefinitionEntityType, TPath extends PathInput<z.input<TObject>>>(schema: TObject, entity: DefinitionEntityInput<z.input<TObject>, TEntityType, TPath>) => z.ZodEffects<TObject>;
9
+ export type WithRefBuilder = <T extends z.ZodType>(schema: T, builder?: ZodBuilderFunction<z.TypeOf<T>>) => z.ZodEffects<T>;
10
+ export declare function extendParserContextWithRefs({ transformReferences, }: DefinitionSchemaCreatorOptions): {
11
+ withRef: WithRefType;
12
+ withEnt: WithEntType;
13
+ withRefBuilder: WithRefBuilder;
14
+ };
15
+ export {};
16
+ //# sourceMappingURL=extend-parser-context-with-refs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extend-parser-context-with-refs.d.ts","sourceRoot":"","sources":["../../src/references/extend-parser-context-with-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAEnB,MAAM,6BAA6B,CAAC;AAWrC,MAAM,MAAM,WAAW,GAAG,CAAC,WAAW,SAAS,oBAAoB,EACjE,SAAS,EAAE,wBAAwB,CAAC,MAAM,EAAE,WAAW,CAAC,KACrD,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE/B,KAAK,SAAS,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG,CACxB,OAAO,SAAS,CAAC,CAAC,aAAa,EAC/B,WAAW,SAAS,oBAAoB,EACxC,KAAK,SAAS,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAEzC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,KAChE,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAE3B,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC/C,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KACtC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAErB,wBAAgB,2BAA2B,CAAC,EAC1C,mBAAmB,GACpB,EAAE,8BAA8B,GAAG;IAClC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,cAAc,CAAC;CAChC,CA4GA"}
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ import { DefinitionReferenceMarker, REF_ANNOTATIONS_MARKER_SYMBOL, } from './markers.js';
3
+ export function extendParserContextWithRefs({ transformReferences, }) {
4
+ function withRef(reference) {
5
+ return z.string().transform((value) => {
6
+ if (transformReferences && value) {
7
+ return new DefinitionReferenceMarker(value, reference);
8
+ }
9
+ return value;
10
+ });
11
+ }
12
+ function withEnt(schema, entity) {
13
+ if (!('id' in schema.shape)) {
14
+ throw new Error(`Entity must have an id field. Entity type: ${entity.type.name}. Schema keys: ${Object.keys(schema.shape).join(', ')}`);
15
+ }
16
+ return schema.transform((value) => {
17
+ // Check if the id is valid
18
+ if (!('id' in value) || !entity.type.isId(value.id)) {
19
+ throw new Error(`Invalid id for entity ${entity.type.name}. Id: ${value.id}`);
20
+ }
21
+ if (transformReferences) {
22
+ const existingAnnotations = REF_ANNOTATIONS_MARKER_SYMBOL in value
23
+ ? value[REF_ANNOTATIONS_MARKER_SYMBOL]
24
+ : undefined;
25
+ return {
26
+ ...value,
27
+ [REF_ANNOTATIONS_MARKER_SYMBOL]: {
28
+ entities: [...(existingAnnotations?.entities ?? []), entity],
29
+ references: existingAnnotations?.references ?? [],
30
+ contextPaths: existingAnnotations?.contextPaths ?? [],
31
+ },
32
+ };
33
+ }
34
+ return value;
35
+ });
36
+ }
37
+ function withRefBuilder(schema, builder) {
38
+ return schema.transform((value) => {
39
+ if (!value) {
40
+ return value;
41
+ }
42
+ if (typeof value !== 'object') {
43
+ throw new TypeError(`refBuilder requires an object, but got ${typeof value}`);
44
+ }
45
+ const existingAnnotations = REF_ANNOTATIONS_MARKER_SYMBOL in value
46
+ ? value[REF_ANNOTATIONS_MARKER_SYMBOL]
47
+ : undefined;
48
+ const entities = existingAnnotations?.entities ?? [];
49
+ const references = existingAnnotations?.references ?? [];
50
+ const contextPaths = existingAnnotations?.contextPaths ?? [];
51
+ const refBuilder = {
52
+ addReference: (reference) => {
53
+ references.push(reference);
54
+ },
55
+ addEntity: (entity) => {
56
+ entities.push(entity);
57
+ },
58
+ addPathToContext: (path, type, context) => {
59
+ contextPaths.push({ path, type, context });
60
+ },
61
+ };
62
+ builder?.(refBuilder, value);
63
+ if (transformReferences) {
64
+ return {
65
+ ...value,
66
+ [REF_ANNOTATIONS_MARKER_SYMBOL]: {
67
+ entities,
68
+ references,
69
+ contextPaths,
70
+ },
71
+ };
72
+ }
73
+ return value;
74
+ });
75
+ }
76
+ return {
77
+ withRef,
78
+ withEnt,
79
+ withRefBuilder,
80
+ };
81
+ }
82
+ //# sourceMappingURL=extend-parser-context-with-refs.js.map