@cleverbrush/schema 4.4.3 → 5.0.0

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 (110) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +176 -19
  3. package/dist/builders/AnySchemaBuilder.d.ts +11 -2
  4. package/dist/builders/AnySchemaBuilder.js +1 -1
  5. package/dist/builders/ArraySchemaBuilder.d.ts +15 -4
  6. package/dist/builders/ArraySchemaBuilder.js +1 -1
  7. package/dist/builders/BooleanSchemaBuilder.d.ts +21 -6
  8. package/dist/builders/BooleanSchemaBuilder.js +1 -1
  9. package/dist/builders/DateSchemaBuilder.d.ts +24 -10
  10. package/dist/builders/DateSchemaBuilder.js +1 -1
  11. package/dist/builders/ExternSchemaBuilder.d.ts +3 -2
  12. package/dist/builders/ExternSchemaBuilder.js +1 -1
  13. package/dist/builders/FunctionSchemaBuilder.d.ts +14 -2
  14. package/dist/builders/FunctionSchemaBuilder.js +1 -1
  15. package/dist/builders/GenericSchemaBuilder.d.ts +14 -3
  16. package/dist/builders/IntersectionSchemaBuilder.d.ts +1 -0
  17. package/dist/builders/LazySchemaBuilder.d.ts +1 -0
  18. package/dist/builders/NullSchemaBuilder.d.ts +2 -4
  19. package/dist/builders/NumberSchemaBuilder.d.ts +21 -7
  20. package/dist/builders/NumberSchemaBuilder.js +1 -1
  21. package/dist/builders/ObjectSchemaBuilder.d.ts +15 -4
  22. package/dist/builders/ObjectSchemaBuilder.js +1 -1
  23. package/dist/builders/ParseStringSchemaBuilder.d.ts +1 -0
  24. package/dist/builders/ParseStringSchemaBuilder.js +1 -1
  25. package/dist/builders/PromiseSchemaBuilder.d.ts +13 -2
  26. package/dist/builders/PromiseSchemaBuilder.js +1 -1
  27. package/dist/builders/RecordSchemaBuilder.d.ts +12 -0
  28. package/dist/builders/RecordSchemaBuilder.js +1 -1
  29. package/dist/builders/SchemaBuilder.d.ts +59 -10
  30. package/dist/builders/StringSchemaBuilder.d.ts +23 -8
  31. package/dist/builders/StringSchemaBuilder.js +1 -1
  32. package/dist/builders/TupleSchemaBuilder.d.ts +16 -4
  33. package/dist/builders/TupleSchemaBuilder.js +1 -1
  34. package/dist/builders/UnionSchemaBuilder.d.ts +12 -2
  35. package/dist/builders/UnionSchemaBuilder.js +1 -1
  36. package/dist/chunk-25KL2NBJ.js +2 -0
  37. package/dist/chunk-25KL2NBJ.js.map +1 -0
  38. package/dist/chunk-2BKBVVZ3.js +2 -0
  39. package/dist/chunk-2BKBVVZ3.js.map +1 -0
  40. package/dist/chunk-3E5M6GRR.js +2 -0
  41. package/dist/chunk-3E5M6GRR.js.map +1 -0
  42. package/dist/chunk-66U6MMJ2.js +2 -0
  43. package/dist/chunk-66U6MMJ2.js.map +1 -0
  44. package/dist/chunk-BMA2X7LI.js +2 -0
  45. package/dist/chunk-BMA2X7LI.js.map +1 -0
  46. package/dist/chunk-BTR3ZGES.js +2 -0
  47. package/dist/chunk-BTR3ZGES.js.map +1 -0
  48. package/dist/chunk-CR2QIV5I.js +2 -0
  49. package/dist/chunk-CR2QIV5I.js.map +1 -0
  50. package/dist/chunk-D7RXO2FA.js +2 -0
  51. package/dist/chunk-D7RXO2FA.js.map +1 -0
  52. package/dist/chunk-JEBLDVKG.js +2 -0
  53. package/dist/chunk-JEBLDVKG.js.map +1 -0
  54. package/dist/chunk-JH7VLA6C.js +2 -0
  55. package/dist/chunk-JH7VLA6C.js.map +1 -0
  56. package/dist/chunk-K7TDPKGQ.js +2 -0
  57. package/dist/chunk-K7TDPKGQ.js.map +1 -0
  58. package/dist/chunk-NDESVCWI.js +2 -0
  59. package/dist/chunk-NDESVCWI.js.map +1 -0
  60. package/dist/chunk-VBPZRO7L.js +2 -0
  61. package/dist/chunk-VBPZRO7L.js.map +1 -0
  62. package/dist/chunk-W5D22D4P.js +2 -0
  63. package/dist/chunk-W5D22D4P.js.map +1 -0
  64. package/dist/{chunk-XHSBY2QK.js → chunk-X6CT6I2V.js} +2 -2
  65. package/dist/{chunk-XHSBY2QK.js.map → chunk-X6CT6I2V.js.map} +1 -1
  66. package/dist/chunk-XASMTNON.js +2 -0
  67. package/dist/chunk-XASMTNON.js.map +1 -0
  68. package/dist/chunk-ZYWDTLNL.js +2 -0
  69. package/dist/chunk-ZYWDTLNL.js.map +1 -0
  70. package/dist/core.d.ts +3 -3
  71. package/dist/core.js +1 -1
  72. package/dist/extension.d.ts +4 -1
  73. package/dist/extension.js +1 -1
  74. package/dist/extensions/string.d.ts +2 -4
  75. package/dist/index.js +1 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/metadata-extension.d.ts +196 -0
  78. package/package.json +6 -3
  79. package/dist/chunk-54RHS4F4.js +0 -2
  80. package/dist/chunk-54RHS4F4.js.map +0 -1
  81. package/dist/chunk-6LSN7NXQ.js +0 -2
  82. package/dist/chunk-6LSN7NXQ.js.map +0 -1
  83. package/dist/chunk-C6YQOKWB.js +0 -2
  84. package/dist/chunk-C6YQOKWB.js.map +0 -1
  85. package/dist/chunk-ELPPAHNO.js +0 -2
  86. package/dist/chunk-ELPPAHNO.js.map +0 -1
  87. package/dist/chunk-G424M7GI.js +0 -2
  88. package/dist/chunk-G424M7GI.js.map +0 -1
  89. package/dist/chunk-JUFZ7PLO.js +0 -2
  90. package/dist/chunk-JUFZ7PLO.js.map +0 -1
  91. package/dist/chunk-K4ZLXLE2.js +0 -2
  92. package/dist/chunk-K4ZLXLE2.js.map +0 -1
  93. package/dist/chunk-KC45JEFL.js +0 -2
  94. package/dist/chunk-KC45JEFL.js.map +0 -1
  95. package/dist/chunk-NF4CRFMN.js +0 -2
  96. package/dist/chunk-NF4CRFMN.js.map +0 -1
  97. package/dist/chunk-ORV2G6ZL.js +0 -2
  98. package/dist/chunk-ORV2G6ZL.js.map +0 -1
  99. package/dist/chunk-PQINUGZW.js +0 -2
  100. package/dist/chunk-PQINUGZW.js.map +0 -1
  101. package/dist/chunk-REYZ7G7J.js +0 -2
  102. package/dist/chunk-REYZ7G7J.js.map +0 -1
  103. package/dist/chunk-VSU5GILY.js +0 -2
  104. package/dist/chunk-VSU5GILY.js.map +0 -1
  105. package/dist/chunk-XL723XFL.js +0 -2
  106. package/dist/chunk-XL723XFL.js.map +0 -1
  107. package/dist/chunk-XPLTW5DI.js +0 -2
  108. package/dist/chunk-XPLTW5DI.js.map +0 -1
  109. package/dist/chunk-YAOZEA2R.js +0 -2
  110. package/dist/chunk-YAOZEA2R.js.map +0 -1
@@ -7,8 +7,8 @@ type GenericSchemaBuilderCreateProps<TRequired extends boolean = true> = Partial
7
7
  * builder whose TypeScript type is inferred from the template function's
8
8
  * generic signature.
9
9
  *
10
- * **NOTE** this class is exported only to give opportunity to extend it
11
- * by inheriting. It is not recommended to create an instance of this class
10
+ * **NOTE** this class is exported for type annotations and advanced use.
11
+ * Customize via extensions rather than subclassing. Avoid instantiating it
12
12
  * directly. Use {@link generic | generic()} function instead.
13
13
  *
14
14
  * @example Single type parameter
@@ -50,7 +50,7 @@ type GenericSchemaBuilderCreateProps<TRequired extends boolean = true> = Partial
50
50
  * // InferType → { ok: boolean; value?: string; error?: number }
51
51
  * ```
52
52
  *
53
- * @example With default arguments (enables direct `.validate()` on the template)
53
+ * @example With default arguments
54
54
  * ```ts
55
55
  * const AnyList = generic(
56
56
  * [any()], // default args — one per template parameter
@@ -87,6 +87,16 @@ type GenericSchemaBuilderCreateProps<TRequired extends boolean = true> = Partial
87
87
  */
88
88
  export declare class GenericSchemaBuilder<TFn extends (...args: any[]) => SchemaBuilder<any, any, any, any, any>, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResult = TExplicitType extends undefined ? ReturnType<TFn> extends SchemaBuilder<infer R, any, any, any, any> ? R : any : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
89
89
  #private;
90
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
91
+ readonly __cleverbrush_builder_type__: readonly [
92
+ 'generic',
93
+ TFn,
94
+ TRequired,
95
+ TNullable,
96
+ TExplicitType,
97
+ THasDefault,
98
+ TResult
99
+ ];
90
100
  /**
91
101
  * Applies the template function with concrete schema arguments, returning
92
102
  * a fully typed concrete schema builder. TypeScript infers the result type
@@ -152,6 +162,7 @@ export declare class GenericSchemaBuilder<TFn extends (...args: any[]) => Schema
152
162
  defaultValue: TResult | (() => TResult) | undefined;
153
163
  description: string | undefined;
154
164
  schemaName: string | undefined;
165
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
155
166
  hasCatch: boolean;
156
167
  catchValue: TResult | (() => TResult) | undefined;
157
168
  example: unknown;
@@ -26,6 +26,7 @@ export declare class IntersectionSchemaBuilder<TLeft extends SchemaBuilder<any,
26
26
  defaultValue: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | undefined;
27
27
  description: string | undefined;
28
28
  schemaName: string | undefined;
29
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
29
30
  hasCatch: boolean;
30
31
  catchValue: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | undefined;
31
32
  example: unknown;
@@ -69,6 +69,7 @@ export declare class LazySchemaBuilder<TResult = any, TRequired extends boolean
69
69
  defaultValue: TResult | (() => TResult) | undefined;
70
70
  description: string | undefined;
71
71
  schemaName: string | undefined;
72
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
72
73
  hasCatch: boolean;
73
74
  catchValue: TResult | (() => TResult) | undefined;
74
75
  example: unknown;
@@ -11,8 +11,8 @@ type NullSchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnType
11
11
  * in a typed schema, for example in discriminated-union branches or when
12
12
  * modelling a JSON payload that may carry a JSON `null` value.
13
13
  *
14
- * **NOTE** this class is exported only to give opportunity to extend it
15
- * by inheriting. It is not recommended to create an instance of this class
14
+ * **NOTE** this class is exported for type annotations and advanced use.
15
+ * Customize via extensions rather than subclassing. Avoid instantiating it
16
16
  * directly. Use {@link nul | nul()} function instead.
17
17
  *
18
18
  * @example
@@ -74,12 +74,10 @@ export declare class NullSchemaBuilder<TRequired extends boolean = true, TNullab
74
74
  validateAsync(object: null, context?: ValidationContext): Promise<ValidationResult<null>>;
75
75
  /**
76
76
  * Performs synchronous validation of the schema over `object`.
77
- * @param context Optional `ValidationContext` settings.
78
77
  */
79
78
  protected _validate(object: null, _context?: ValidationContext): ValidationResult<null>;
80
79
  /**
81
80
  * Performs async validation of the schema over `object`.
82
- * @param context Optional `ValidationContext` settings.
83
81
  */
84
82
  protected _validateAsync(object: null, _context?: ValidationContext): Promise<ValidationResult<null>>;
85
83
  protected createFromProps<TReq extends boolean>(props: NullSchemaBuilderCreateProps<TReq>): this;
@@ -5,30 +5,34 @@ type NumberSchemaBuilderCreateProps<T = number, R extends boolean = true> = Part
5
5
  * Can be required or optional, can be restricted to be equal to a certain value,
6
6
  * can be restricted to be in a certain range, can be restricted to be integer.
7
7
  *
8
- * **NOTE** this class is exported only to give opportunity to extend it
9
- * by inheriting. It is not recommended to create an instance of this class
8
+ * **NOTE** this class is exported for type annotations and advanced use.
9
+ * Customize via extensions rather than subclassing. Avoid instantiating it
10
10
  * directly. Use {@link number | number()} function instead.
11
11
  *
12
- * @example ```ts
12
+ * @example
13
+ * ```ts
13
14
  * const schema = number().equals(42);
14
15
  * const result = schema.validate(42);
15
16
  * // result.valid === true
16
17
  * // result.object === 42
17
18
  * ```
18
- * @example ```ts
19
+ * @example
20
+ * ```ts
19
21
  * const schema = number();
20
22
  * const result = schema.validate('42');
21
23
  * // result.valid === false
22
24
  * // result.errors[0].message === 'is expected to be a number'
23
25
  * ```
24
- * @example ```ts
26
+ * @example
27
+ * ```ts
25
28
  * const schema = number().min(0).max(100);
26
29
  * const result = schema.validate(42);
27
30
  * // result.valid === true
28
31
  * // result.object === 42
29
32
  * ```
30
33
  *
31
- * @example ```ts
34
+ * @example
35
+ * ```ts
32
36
  * const schema = number().min(0).max(100);
33
37
  * const result = schema.validate(142.5);
34
38
  * // result.valid === false
@@ -39,6 +43,14 @@ type NumberSchemaBuilderCreateProps<T = number, R extends boolean = true> = Part
39
43
  */
40
44
  export declare class NumberSchemaBuilder<TResult = number, TRequired extends boolean = true, TNullable extends boolean = false, THasDefault extends boolean = false, TExtensions = {}> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
41
45
  #private;
46
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
47
+ readonly __cleverbrush_builder_type__: readonly [
48
+ 'number',
49
+ TResult,
50
+ TRequired,
51
+ TNullable,
52
+ THasDefault
53
+ ];
42
54
  /**
43
55
  * @hidden
44
56
  */
@@ -118,6 +130,7 @@ export declare class NumberSchemaBuilder<TResult = number, TRequired extends boo
118
130
  defaultValue: TResult | (() => TResult) | undefined;
119
131
  description: string | undefined;
120
132
  schemaName: string | undefined;
133
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
121
134
  hasCatch: boolean;
122
135
  catchValue: TResult | (() => TResult) | undefined;
123
136
  example: unknown;
@@ -236,7 +249,8 @@ export declare class NumberSchemaBuilder<TResult = number, TRequired extends boo
236
249
  * a string source (e.g. a parse-string schema, URL parameter,
237
250
  * or form input).
238
251
  *
239
- * @example ```ts
252
+ * @example
253
+ * ```ts
240
254
  * const schema = number().coerce();
241
255
  * const result = schema.validate('42');
242
256
  * // result.valid === true
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-ELPPAHNO.js";import"../chunk-REYZ7G7J.js";export{a as NumberSchemaBuilder,b as number};
1
+ import{a,b}from"../chunk-BTR3ZGES.js";import"../chunk-2BKBVVZ3.js";export{a as NumberSchemaBuilder,b as number};
2
2
  //# sourceMappingURL=NumberSchemaBuilder.js.map
@@ -125,7 +125,7 @@ export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuil
125
125
  * This is the **recommended** way to inspect validation errors — it provides type-safe,
126
126
  * per-property error details including `isValid`, `errors`, and `seenValue`.
127
127
  *
128
- * Prefer this over the deprecated `errors` array.
128
+ * Inspect root or property-specific validation errors with a selector.
129
129
  *
130
130
  * @param selector a callback function to select property from the schema.
131
131
  */
@@ -150,8 +150,8 @@ export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuil
150
150
  * Which means that you can define nested objects and arrays of
151
151
  * any complexity.
152
152
  *
153
- * **NOTE** this class is exported only to give opportunity to extend it
154
- * by inheriting. It is not recommended to create an instance of this class
153
+ * **NOTE** this class is exported for type annotations and advanced use.
154
+ * Customize via extensions rather than subclassing. Avoid instantiating it
155
155
  * directly. Use {@link object | object()} function instead.
156
156
  *
157
157
  * @example
@@ -195,7 +195,7 @@ export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuil
195
195
  * });
196
196
  *
197
197
  * // result.valid === false
198
- * // result.errors is deprecated — use result.getErrorsFor() instead
198
+ * // Inspect property errors using result.getErrorsFor().
199
199
  * // result.getErrorsFor((p) => p.age).errors // ["is expected to have property 'age'"]
200
200
  * ```
201
201
  *
@@ -228,6 +228,16 @@ export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuil
228
228
  */
229
229
  export declare class ObjectSchemaBuilder<TProperties extends Record<string, SchemaBuilder<any, any, any, any, any>> = {}, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TConstructorSchemas extends SchemaBuilder<any, any, any, any, any>[] = []> extends SchemaBuilder<undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType, TRequired, TNullable, THasDefault, TExtensions> {
230
230
  #private;
231
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
232
+ readonly __cleverbrush_builder_type__: readonly [
233
+ 'object',
234
+ TProperties,
235
+ TRequired,
236
+ TNullable,
237
+ TExplicitType,
238
+ THasDefault,
239
+ TConstructorSchemas
240
+ ];
231
241
  /** Marks this builder as having sub-properties for descriptor tree recursion. */
232
242
  readonly [SYMBOL_HAS_PROPERTIES] = true;
233
243
  /**
@@ -269,6 +279,7 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
269
279
  defaultValue: (undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | (() => undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | undefined;
270
280
  description: string | undefined;
271
281
  schemaName: string | undefined;
282
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
272
283
  hasCatch: boolean;
273
284
  catchValue: (undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | (() => undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | undefined;
274
285
  example: unknown;
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-6LSN7NXQ.js";import"../chunk-REYZ7G7J.js";export{a as ObjectSchemaBuilder,b as object};
1
+ import{a,b}from"../chunk-JEBLDVKG.js";import"../chunk-2BKBVVZ3.js";export{a as ObjectSchemaBuilder,b as object};
2
2
  //# sourceMappingURL=ObjectSchemaBuilder.js.map
@@ -87,6 +87,7 @@ export declare class ParseStringSchemaBuilder<TResult = any, TRequired extends b
87
87
  defaultValue: TResult | (() => TResult) | undefined;
88
88
  description: string | undefined;
89
89
  schemaName: string | undefined;
90
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
90
91
  hasCatch: boolean;
91
92
  catchValue: TResult | (() => TResult) | undefined;
92
93
  example: unknown;
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-XHSBY2QK.js";import"../chunk-6LSN7NXQ.js";import"../chunk-REYZ7G7J.js";export{a as ParseStringSchemaBuilder,b as parseString};
1
+ import{a,b}from"../chunk-X6CT6I2V.js";import"../chunk-JEBLDVKG.js";import"../chunk-2BKBVVZ3.js";export{a as ParseStringSchemaBuilder,b as parseString};
2
2
  //# sourceMappingURL=ParseStringSchemaBuilder.js.map
@@ -6,8 +6,8 @@ type PromiseSchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnT
6
6
  * function) and optionally carries a typed resolved-value schema so that
7
7
  * the inferred TypeScript type is `Promise<T>` instead of `Promise<any>`.
8
8
  *
9
- * **NOTE** this class is exported only to give opportunity to extend it
10
- * by inheriting. It is not recommended to create an instance of this class
9
+ * **NOTE** this class is exported for type annotations and advanced use.
10
+ * Customize via extensions rather than subclassing. Avoid instantiating it
11
11
  * directly. Use {@link promise | promise()} function instead.
12
12
  *
13
13
  * @example Basic validation
@@ -43,6 +43,16 @@ type PromiseSchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnT
43
43
  */
44
44
  export declare class PromiseSchemaBuilder<TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResolvedTypeSchema extends SchemaBuilder<any, any, any, any, any> | undefined = undefined, TResult = TExplicitType extends undefined ? TResolvedTypeSchema extends SchemaBuilder<any, any, any, any, any> ? Promise<InferType<TResolvedTypeSchema>> : Promise<any> : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
45
45
  #private;
46
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
47
+ readonly __cleverbrush_builder_type__: readonly [
48
+ 'promise',
49
+ TRequired,
50
+ TNullable,
51
+ TExplicitType,
52
+ THasDefault,
53
+ TResolvedTypeSchema,
54
+ TResult
55
+ ];
46
56
  /**
47
57
  * @hidden
48
58
  */
@@ -90,6 +100,7 @@ export declare class PromiseSchemaBuilder<TRequired extends boolean = true, TNul
90
100
  defaultValue: TResult | (() => TResult) | undefined;
91
101
  description: string | undefined;
92
102
  schemaName: string | undefined;
103
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
93
104
  hasCatch: boolean;
94
105
  catchValue: TResult | (() => TResult) | undefined;
95
106
  example: unknown;
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-JUFZ7PLO.js";import"../chunk-REYZ7G7J.js";export{a as PromiseSchemaBuilder,b as promise};
1
+ import{a,b}from"../chunk-25KL2NBJ.js";import"../chunk-2BKBVVZ3.js";export{a as PromiseSchemaBuilder,b as promise};
2
2
  //# sourceMappingURL=PromiseSchemaBuilder.js.map
@@ -186,6 +186,17 @@ type RecordSchemaBuilderCreateProps<TKeySchema extends StringSchemaBuilder<any,
186
186
  */
187
187
  export declare class RecordSchemaBuilder<TKeySchema extends StringSchemaBuilder<any, any, any, any>, TValueSchema extends SchemaBuilder<any, any, any, any, any>, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResult = TExplicitType extends undefined ? Record<InferType<TKeySchema>, InferType<TValueSchema>> : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
188
188
  #private;
189
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
190
+ readonly __cleverbrush_builder_type__: readonly [
191
+ 'record',
192
+ TKeySchema,
193
+ TValueSchema,
194
+ TRequired,
195
+ TNullable,
196
+ TExplicitType,
197
+ THasDefault,
198
+ TResult
199
+ ];
189
200
  /**
190
201
  * @hidden
191
202
  */
@@ -251,6 +262,7 @@ export declare class RecordSchemaBuilder<TKeySchema extends StringSchemaBuilder<
251
262
  defaultValue: TResult | (() => TResult) | undefined;
252
263
  description: string | undefined;
253
264
  schemaName: string | undefined;
265
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
254
266
  hasCatch: boolean;
255
267
  catchValue: TResult | (() => TResult) | undefined;
256
268
  example: unknown;
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-XL723XFL.js";import"../chunk-REYZ7G7J.js";export{a as RecordSchemaBuilder,b as record};
1
+ import{a,b}from"../chunk-W5D22D4P.js";import"../chunk-2BKBVVZ3.js";export{a as RecordSchemaBuilder,b as record};
2
2
  //# sourceMappingURL=RecordSchemaBuilder.js.map
@@ -51,7 +51,7 @@ export type InferType<T> = T extends {
51
51
  *
52
52
  * When returned from an object-level validator (via {@link SchemaBuilder.addValidator | addValidator}),
53
53
  * the optional `property` selector can route the error to a specific property
54
- * so that {@link ObjectSchemaValidationResult.getErrorsFor | getErrorsFor()} reports it
54
+ * so that `ObjectSchemaValidationResult.getErrorsFor()` reports it
55
55
  * on that property rather than only on the root object.
56
56
  *
57
57
  * ```ts
@@ -192,6 +192,8 @@ export type SchemaBuilderProps<T> = {
192
192
  hasCatch?: boolean;
193
193
  description?: string;
194
194
  schemaName?: string;
195
+ /** @internal Canonical named definition for a use-site-only derivative. */
196
+ referenceTarget?: SchemaBuilder<any, any, any, any, any>;
195
197
  example?: unknown;
196
198
  };
197
199
  export type ValidationContext<TSchema extends SchemaBuilder<any, any, any, any> = SchemaBuilder<any, any, any, any>> = {
@@ -404,8 +406,18 @@ export type PropertyDescriptor<TRootSchema extends ObjectSchemaBuilder<any, any,
404
406
  * Has a possibility to filter properties by the type (`TAssignableTo` type parameter).
405
407
  */
406
408
  export type PropertyDescriptorTree<TSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any> = TSchema, TAssignableTo = any, TParentPropertyDescriptor = undefined> = PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor> & (TSchema extends ObjectSchemaBuilder<infer TProperties, any, any> ? {
407
- [K in keyof TProperties]: TProperties[K] extends ObjectSchemaBuilder<any, any, any> ? PropertyDescriptorTree<TProperties[K], TRootSchema, any, PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : TProperties[K] extends ExternSchemaBuilder<any, any, any, any, any, any, infer TExternResult> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> & ExternOutputPropertyDescriptors<TExternResult, TRootSchema, PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string>> : TProperties[K] extends ArraySchemaBuilder<infer TArrayElement, any, any> ? TArrayElement extends ObjectSchemaBuilder<any, any, any, any, any> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : never : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : never;
409
+ [K in keyof TProperties]: TProperties[K] extends ObjectSchemaBuilder<any, any, any> ? PropertyDescriptorTree<TProperties[K], TRootSchema, any, PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : TProperties[K] extends ExternSchemaBuilder<any, any, any, any, any, any, infer TExternResult> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> & ExternOutputPropertyDescriptors<TExternResult, TRootSchema, PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string>> : TProperties[K] extends ArraySchemaBuilder<infer TArrayElement, any, any> ? TArrayElement extends ObjectSchemaBuilder<any, any, any, any, any> ? IndexedPropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : InferType<TProperties[K]> extends TAssignableTo ? IndexedPropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : never : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : never;
408
410
  } : never);
411
+ /**
412
+ * A descriptor that preserves its array binding and exposes lazy indexed child
413
+ * descriptors. Indices are non-negative integers; they are positions, not item
414
+ * identities. Object and nested-array elements retain their schema types.
415
+ *
416
+ * @example `object.getPropertiesFor(schema).addresses[0].city`
417
+ */
418
+ export type IndexedPropertyDescriptor<TRoot extends ObjectSchemaBuilder<any, any, any, any, any>, TSchema, TParent, TKey extends string = string> = PropertyDescriptor<TRoot, TSchema, TParent, TKey> & (TSchema extends ObjectSchemaBuilder<any, any, any> ? PropertyDescriptorTree<TSchema, TRoot, any, TParent> : TSchema extends ArraySchemaBuilder<infer TElement, any, any> ? {
419
+ readonly [index: number]: IndexedPropertyDescriptor<TRoot, TElement, PropertyDescriptor<TRoot, TSchema, TParent, TKey>>;
420
+ } : {});
409
421
  /**
410
422
  * Recursively maps the keys of an extern schema's output type into
411
423
  * property descriptors. When a value is a plain-object type its keys
@@ -441,8 +453,8 @@ type ResolvedSchemaType<TResult, TRequired extends boolean, TNullable extends bo
441
453
  * Base class for all schema builders. Provides basic functionality for schema building.
442
454
  *
443
455
  * **Note:** this class is not intended to be used directly, use one of the subclasses instead.
444
- * @typeparam TResult Type of the object that will be returned by `validate()` method.
445
- * @typeparam TRequired If `true`, object will be required. If `false`, object will be optional.
456
+ * @typeParam TResult Type of the object that will be returned by `validate()` method.
457
+ * @typeParam TRequired If `true`, object will be required. If `false`, object will be optional.
446
458
  */
447
459
  export declare abstract class SchemaBuilder<TResult = any, TRequired extends boolean = true, TNullable extends boolean = false, THasDefault extends boolean = false, TExtensions = {}> {
448
460
  #private;
@@ -466,13 +478,13 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
466
478
  * consumes the spec — including tRPC, TanStack Form, React Hook Form, T3 Env,
467
479
  * Hono, Elysia, next-safe-action, and 50+ other tools.
468
480
  *
469
- * Every `SchemaBuilder` subclass (all 13 builders) inherits this property
481
+ * Every `SchemaBuilder` subclass inherits this property
470
482
  * automatically — no additional setup required.
471
483
  *
472
484
  * **Shape of the returned object:**
473
485
  * - `version` — always `1` (Standard Schema spec version)
474
486
  * - `vendor` — `'@cleverbrush/schema'`
475
- * - `validate(value)` — synchronous; wraps this builder's own `.validate()`
487
+ * - `validate(value)` — asynchronous; wraps this builder's `.validateAsync()`
476
488
  * and converts its result to the Standard Schema `Result<Output>` format:
477
489
  * - Success: `{ value: <validated output> }`
478
490
  * - Failure: `{ issues: [{ message: string }, …] }`
@@ -526,6 +538,17 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
526
538
  * @param props arbitrary props object
527
539
  */
528
540
  protected abstract createFromProps(props: any): this;
541
+ /**
542
+ * Constructs an immutable derivative through the existing subclass hook.
543
+ * Shape, rule and extension changes detach from inherited component names
544
+ * by default. Only presence, nullability, annotations and type-only changes
545
+ * may preserve the canonical definition. Preserve chains collapse to their
546
+ * original target; an unnamed derivative never reconnects automatically.
547
+ * @param props - Complete introspection properties for the new builder.
548
+ * @param preserveReference - Whether only use-site metadata changed.
549
+ * @internal
550
+ */
551
+ protected derive(props: any, preserveReference?: boolean): this;
529
552
  /**
530
553
  * The string identifier of the schema type (e.g. `'string'`, `'number'`, `'object'`).
531
554
  */
@@ -693,6 +716,14 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
693
716
  * or `undefined` if none was set.
694
717
  */
695
718
  schemaName: string | undefined;
719
+ /**
720
+ * Canonical named definition retained by use-site modifiers.
721
+ * Exporters must compose local annotations/nullability around this
722
+ * target before resolving the derivative's inherited name.
723
+ * Structural and validation-rule derivatives have no target.
724
+ * @internal
725
+ */
726
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
696
727
  /**
697
728
  * Whether a catch/fallback value has been set on this schema via `.catch()`.
698
729
  */
@@ -761,7 +792,10 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
761
792
  *
762
793
  * When `.catch()` is set, {@link parse} and {@link parseAsync} will **never throw**.
763
794
  *
764
- * @param value - the fallback value, or a factory function producing the fallback
795
+ * @param value - A value (or factory) compatible with the resolved output:
796
+ * optional schemas allow undefined; nullable schemas allow null.
797
+ * @remarks Legacy optional schemas also accept null at runtime, so
798
+ * catch(undefined) does not normalize null. Use an explicit preprocessor.
765
799
  *
766
800
  * @example
767
801
  * ```ts
@@ -790,7 +824,7 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
790
824
  * c.validate(42); // { valid: true, object: 'anon' } ← also fires
791
825
  * ```
792
826
  */
793
- catch(value: TResult | (() => TResult)): this;
827
+ catch(value: ResolvedSchemaType<TResult, TRequired, TNullable> | (() => ResolvedSchemaType<TResult, TRequired, TNullable>)): this;
794
828
  /**
795
829
  * Removes the default value set by a previous call to `.default()`.
796
830
  */
@@ -845,6 +879,15 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
845
879
  * safe; how conflicts between different instances with the same name are
846
880
  * handled depends on the tool.
847
881
  *
882
+ * Ordinary presence, nullability, annotation and type-only modifiers retain
883
+ * this canonical definition for document exporters. Shape, validation-rule,
884
+ * default, fallback and extension changes discard the inherited name. Apply
885
+ * `schemaName` after those edits to give the derivative its own component.
886
+ * Calling this method always establishes a fresh definition, even on an alias.
887
+ *
888
+ * @param name - Component name for this independent schema definition.
889
+ * @returns A new named builder without an inherited canonical target.
890
+ *
848
891
  * @example
849
892
  * ```ts
850
893
  * import { object, string, number } from '@cleverbrush/schema';
@@ -899,9 +942,15 @@ export declare abstract class SchemaBuilder<TResult = any, TRequired extends boo
899
942
  */
900
943
  required(errorMessage?: ValidationErrorMessageProvider): any;
901
944
  /**
902
- * Adds a `preprocessor` to a preprocessors list
945
+ * Adds an immutable preprocessing step. It may return the resolved value,
946
+ * including undefined for optional schemas and null for nullable schemas.
947
+ * @param preprocessor - Existing value-to-value conversion, optionally async.
948
+ * @param options - Whether the callback can mutate its argument.
949
+ * @returns A new builder preserving the original schema.
950
+ * @remarks Legacy callback parameter typing is preserved for compatibility.
951
+ * Unknown external data still needs runtime validation.
903
952
  */
904
- addPreprocessor(preprocessor: Preprocessor<TResult>, options?: {
953
+ addPreprocessor(preprocessor: (object: TResult) => ResolvedSchemaType<TResult, TRequired, TNullable> | Promise<ResolvedSchemaType<TResult, TRequired, TNullable>>, options?: {
905
954
  mutates?: boolean;
906
955
  }): this;
907
956
  /**
@@ -6,46 +6,52 @@ type StringSchemaBuilderCreateProps<T = string, R extends boolean = true> = Part
6
6
  * length, restricted to start with a certain value, restricted to end with
7
7
  * a certain value, restricted to match a certain regular expression.
8
8
  *
9
- * **NOTE** this class is exported only to give opportunity to extend it
10
- * by inheriting. It is not recommended to create an instance of this class
9
+ * **NOTE** this class is exported for type annotations and advanced use.
10
+ * Customize via extensions rather than subclassing. Avoid instantiating it
11
11
  * directly. Use {@link string | string()} function instead.
12
12
  *
13
- * @example ```ts
13
+ * @example
14
+ * ```ts
14
15
  * const schema = string().equals('hello');
15
16
  * const result = schema.validate('hello');
16
17
  * // result.valid === true
17
18
  * // result.object === 'hello'
18
19
  * ```
19
20
  *
20
- * @example ```ts
21
+ * @example
22
+ * ```ts
21
23
  * const schema = string().equals('hello');
22
24
  * const result = schema.validate('world');
23
25
  * // result.valid === false
24
26
  * // result.errors[0].message === "is expected to be equal to 'hello'"
25
27
  * ```
26
28
  *
27
- * @example ```ts
29
+ * @example
30
+ * ```ts
28
31
  * const schema = string().minLength(5);
29
32
  * const result = schema.validate('hello');
30
33
  * // result.valid === true
31
34
  * // result.object === 'hello'
32
35
  * ```
33
36
  *
34
- * @example ```ts
37
+ * @example
38
+ * ```ts
35
39
  * const schema = string().minLength(5);
36
40
  * const result = schema.validate('hi');
37
41
  * // result.valid === false
38
42
  * // result.errors[0].message === 'is expected to have a length of at least 5'
39
43
  * ```
40
44
  *
41
- * @example ```ts
45
+ * @example
46
+ * ```ts
42
47
  * const schema = string().minLength(2).maxLength(5);
43
48
  * const result = schema.validate('yes');
44
49
  * // result.valid === true
45
50
  * // result.object === 'yes'
46
51
  * ```
47
52
  *
48
- * @example ```ts
53
+ * @example
54
+ * ```ts
49
55
  * const schema = string('no');
50
56
  * const result = schema.validate('yes');
51
57
  * // result.valid === false
@@ -56,6 +62,14 @@ type StringSchemaBuilderCreateProps<T = string, R extends boolean = true> = Part
56
62
  */
57
63
  export declare class StringSchemaBuilder<TResult = string, TRequired extends boolean = true, TNullable extends boolean = false, THasDefault extends boolean = false, TExtensions = {}> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
58
64
  #private;
65
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
66
+ readonly __cleverbrush_builder_type__: readonly [
67
+ 'string',
68
+ TResult,
69
+ TRequired,
70
+ TNullable,
71
+ THasDefault
72
+ ];
59
73
  /**
60
74
  * @hidden
61
75
  */
@@ -136,6 +150,7 @@ export declare class StringSchemaBuilder<TResult = string, TRequired extends boo
136
150
  defaultValue: TResult | (() => TResult) | undefined;
137
151
  description: string | undefined;
138
152
  schemaName: string | undefined;
153
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
139
154
  hasCatch: boolean;
140
155
  catchValue: TResult | (() => TResult) | undefined;
141
156
  example: unknown;
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-ORV2G6ZL.js";import"../chunk-REYZ7G7J.js";export{a as StringSchemaBuilder,b as string};
1
+ import{a,b}from"../chunk-JH7VLA6C.js";import"../chunk-2BKBVVZ3.js";export{a as StringSchemaBuilder,b as string};
2
2
  //# sourceMappingURL=StringSchemaBuilder.js.map
@@ -35,8 +35,8 @@ type TupleSchemaBuilderCreateProps<TElements extends readonly SchemaBuilder<any,
35
35
  * Use it when you need to validate function arguments, CSV rows, coordinate
36
36
  * pairs, structured event payloads, or any other fixed-structure array.
37
37
  *
38
- * **NOTE** this class is exported only to give opportunity to extend it
39
- * by inheriting. It is not recommended to create an instance of this class
38
+ * **NOTE** this class is exported for type annotations and advanced use.
39
+ * Customize via extensions rather than subclassing. Avoid instantiating it
40
40
  * directly. Use {@link tuple | tuple()} function instead.
41
41
  *
42
42
  * @example
@@ -86,6 +86,17 @@ export declare class TupleSchemaBuilder<TElements extends readonly SchemaBuilder
86
86
  [K in keyof TElements]: InferType<TElements[K]>;
87
87
  } : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
88
88
  #private;
89
+ /** Native type parameters for extension rebinding; never emitted at runtime. @internal */
90
+ readonly __cleverbrush_builder_type__: readonly [
91
+ 'tuple',
92
+ TElements,
93
+ TRequired,
94
+ TNullable,
95
+ TExplicitType,
96
+ THasDefault,
97
+ TRestSchema,
98
+ TResult
99
+ ];
89
100
  /**
90
101
  * @hidden
91
102
  */
@@ -100,11 +111,11 @@ export declare class TupleSchemaBuilder<TElements extends readonly SchemaBuilder
100
111
  */
101
112
  clearHasType(): TupleSchemaBuilder<TElements, TRequired, TNullable, undefined, THasDefault, TExtensions, TRestSchema> & TExtensions;
102
113
  /**
103
- * Performs synchronous validation of the schema over `object`. {@inheritDoc SchemaBuilder.validate}
114
+ * {@inheritDoc SchemaBuilder.validate}
104
115
  */
105
116
  validate(object: TResult, context?: ValidationContext): TupleSchemaValidationResult<TResult, TElements>;
106
117
  /**
107
- * Performs asynchronous validation of the schema over `object`. {@inheritDoc SchemaBuilder.validateAsync}
118
+ * {@inheritDoc SchemaBuilder.validateAsync}
108
119
  */
109
120
  validateAsync(object: TResult, context?: ValidationContext): Promise<TupleSchemaValidationResult<TResult, TElements>>;
110
121
  /**
@@ -170,6 +181,7 @@ export declare class TupleSchemaBuilder<TElements extends readonly SchemaBuilder
170
181
  defaultValue: TResult | (() => TResult) | undefined;
171
182
  description: string | undefined;
172
183
  schemaName: string | undefined;
184
+ referenceTarget: SchemaBuilder<any, any, any, any, any> | undefined;
173
185
  hasCatch: boolean;
174
186
  catchValue: TResult | (() => TResult) | undefined;
175
187
  example: unknown;
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-G424M7GI.js";import"../chunk-REYZ7G7J.js";export{a as TupleSchemaBuilder,b as tuple};
1
+ import{a,b}from"../chunk-VBPZRO7L.js";import"../chunk-2BKBVVZ3.js";export{a as TupleSchemaBuilder,b as tuple};
2
2
  //# sourceMappingURL=TupleSchemaBuilder.js.map