@cleverbrush/schema 0.0.0-beta-20260410073748

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 (85) hide show
  1. package/README.md +1409 -0
  2. package/dist/builders/AnySchemaBuilder.d.ts +116 -0
  3. package/dist/builders/AnySchemaBuilder.js +2 -0
  4. package/dist/builders/AnySchemaBuilder.js.map +1 -0
  5. package/dist/builders/ArraySchemaBuilder.d.ts +214 -0
  6. package/dist/builders/ArraySchemaBuilder.js +2 -0
  7. package/dist/builders/ArraySchemaBuilder.js.map +1 -0
  8. package/dist/builders/BooleanSchemaBuilder.d.ts +146 -0
  9. package/dist/builders/BooleanSchemaBuilder.js +2 -0
  10. package/dist/builders/BooleanSchemaBuilder.js.map +1 -0
  11. package/dist/builders/DateSchemaBuilder.d.ts +277 -0
  12. package/dist/builders/DateSchemaBuilder.js +2 -0
  13. package/dist/builders/DateSchemaBuilder.js.map +1 -0
  14. package/dist/builders/ExternSchemaBuilder.d.ts +200 -0
  15. package/dist/builders/ExternSchemaBuilder.js +2 -0
  16. package/dist/builders/ExternSchemaBuilder.js.map +1 -0
  17. package/dist/builders/FunctionSchemaBuilder.d.ts +246 -0
  18. package/dist/builders/FunctionSchemaBuilder.js +2 -0
  19. package/dist/builders/FunctionSchemaBuilder.js.map +1 -0
  20. package/dist/builders/LazySchemaBuilder.d.ts +167 -0
  21. package/dist/builders/NullSchemaBuilder.d.ts +162 -0
  22. package/dist/builders/NumberSchemaBuilder.d.ts +273 -0
  23. package/dist/builders/NumberSchemaBuilder.js +2 -0
  24. package/dist/builders/NumberSchemaBuilder.js.map +1 -0
  25. package/dist/builders/ObjectSchemaBuilder.d.ts +517 -0
  26. package/dist/builders/ObjectSchemaBuilder.js +2 -0
  27. package/dist/builders/ObjectSchemaBuilder.js.map +1 -0
  28. package/dist/builders/PropertyValidationResult.d.ts +68 -0
  29. package/dist/builders/RecordSchemaBuilder.d.ts +341 -0
  30. package/dist/builders/RecordSchemaBuilder.js +2 -0
  31. package/dist/builders/RecordSchemaBuilder.js.map +1 -0
  32. package/dist/builders/SchemaBuilder.d.ts +947 -0
  33. package/dist/builders/StringSchemaBuilder.d.ts +291 -0
  34. package/dist/builders/StringSchemaBuilder.js +2 -0
  35. package/dist/builders/StringSchemaBuilder.js.map +1 -0
  36. package/dist/builders/TupleSchemaBuilder.d.ts +248 -0
  37. package/dist/builders/TupleSchemaBuilder.js +2 -0
  38. package/dist/builders/TupleSchemaBuilder.js.map +1 -0
  39. package/dist/builders/UnionSchemaBuilder.d.ts +227 -0
  40. package/dist/builders/UnionSchemaBuilder.js +2 -0
  41. package/dist/builders/UnionSchemaBuilder.js.map +1 -0
  42. package/dist/chunk-CTP4RHDG.js +2 -0
  43. package/dist/chunk-CTP4RHDG.js.map +1 -0
  44. package/dist/chunk-FWUEUW2N.js +2 -0
  45. package/dist/chunk-FWUEUW2N.js.map +1 -0
  46. package/dist/chunk-IJ6FO37G.js +2 -0
  47. package/dist/chunk-IJ6FO37G.js.map +1 -0
  48. package/dist/chunk-KESLT5EE.js +2 -0
  49. package/dist/chunk-KESLT5EE.js.map +1 -0
  50. package/dist/chunk-KFTO7TMB.js +2 -0
  51. package/dist/chunk-KFTO7TMB.js.map +1 -0
  52. package/dist/chunk-MKAYFPAR.js +2 -0
  53. package/dist/chunk-MKAYFPAR.js.map +1 -0
  54. package/dist/chunk-NXPH3ZUW.js +2 -0
  55. package/dist/chunk-NXPH3ZUW.js.map +1 -0
  56. package/dist/chunk-OOPF7RXS.js +2 -0
  57. package/dist/chunk-OOPF7RXS.js.map +1 -0
  58. package/dist/chunk-S5TC6NSU.js +2 -0
  59. package/dist/chunk-S5TC6NSU.js.map +1 -0
  60. package/dist/chunk-YWBNVHR6.js +2 -0
  61. package/dist/chunk-YWBNVHR6.js.map +1 -0
  62. package/dist/chunk-Z72HXYKX.js +2 -0
  63. package/dist/chunk-Z72HXYKX.js.map +1 -0
  64. package/dist/chunk-Z7QZ7IXT.js +2 -0
  65. package/dist/chunk-Z7QZ7IXT.js.map +1 -0
  66. package/dist/chunk-ZAN4ZHCJ.js +2 -0
  67. package/dist/chunk-ZAN4ZHCJ.js.map +1 -0
  68. package/dist/chunk-ZUPYV5TI.js +2 -0
  69. package/dist/chunk-ZUPYV5TI.js.map +1 -0
  70. package/dist/core.d.ts +23 -0
  71. package/dist/core.js +2 -0
  72. package/dist/core.js.map +1 -0
  73. package/dist/extension.d.ts +413 -0
  74. package/dist/extensions/array.d.ts +112 -0
  75. package/dist/extensions/enum.d.ts +190 -0
  76. package/dist/extensions/index.d.ts +108 -0
  77. package/dist/extensions/nullable.d.ts +26 -0
  78. package/dist/extensions/number.d.ts +228 -0
  79. package/dist/extensions/string.d.ts +332 -0
  80. package/dist/extensions/util.d.ts +45 -0
  81. package/dist/index.d.ts +7 -0
  82. package/dist/index.js +2 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/utils/transaction.d.ts +69 -0
  85. package/package.json +104 -0
@@ -0,0 +1,291 @@
1
+ import { type BRAND, type PreprocessorEntry, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult, type ValidatorEntry } from './SchemaBuilder.js';
2
+ type StringSchemaBuilderCreateProps<T = string, R extends boolean = true> = Partial<ReturnType<StringSchemaBuilder<T, R>['introspect']>>;
3
+ /**
4
+ * Allows to define a schema for a string. It can be: required or optional,
5
+ * restricted to be equal to a certain value, restricted to have a certain
6
+ * length, restricted to start with a certain value, restricted to end with
7
+ * a certain value, restricted to match a certain regular expression.
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
11
+ * directly. Use {@link string | string()} function instead.
12
+ *
13
+ * @example ```ts
14
+ * const schema = string().equals('hello');
15
+ * const result = schema.validate('hello');
16
+ * // result.valid === true
17
+ * // result.object === 'hello'
18
+ * ```
19
+ *
20
+ * @example ```ts
21
+ * const schema = string().equals('hello');
22
+ * const result = schema.validate('world');
23
+ * // result.valid === false
24
+ * // result.errors[0].message === "is expected to be equal to 'hello'"
25
+ * ```
26
+ *
27
+ * @example ```ts
28
+ * const schema = string().minLength(5);
29
+ * const result = schema.validate('hello');
30
+ * // result.valid === true
31
+ * // result.object === 'hello'
32
+ * ```
33
+ *
34
+ * @example ```ts
35
+ * const schema = string().minLength(5);
36
+ * const result = schema.validate('hi');
37
+ * // result.valid === false
38
+ * // result.errors[0].message === 'is expected to have a length of at least 5'
39
+ * ```
40
+ *
41
+ * @example ```ts
42
+ * const schema = string().minLength(2).maxLength(5);
43
+ * const result = schema.validate('yes');
44
+ * // result.valid === true
45
+ * // result.object === 'yes'
46
+ * ```
47
+ *
48
+ * @example ```ts
49
+ * const schema = string('no');
50
+ * const result = schema.validate('yes');
51
+ * // result.valid === false
52
+ * // result.errors[0].message === "is expected to be equal to 'no'"
53
+ * ```
54
+ *
55
+ * @see {@link string}
56
+ */
57
+ 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
+ #private;
59
+ /**
60
+ * @hidden
61
+ */
62
+ static create(props: StringSchemaBuilderCreateProps): StringSchemaBuilder<string, true, false, false, {}>;
63
+ protected constructor(props: StringSchemaBuilderCreateProps);
64
+ introspect(): {
65
+ /**
66
+ * Min length of the string (if defined).
67
+ */
68
+ minLength: number | undefined;
69
+ /**
70
+ * Min length validation error message provider.
71
+ * If not provided, default error message will be used.
72
+ */
73
+ minLengthValidationErrorMessageProvider: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired, false, false, {}>>;
74
+ /**
75
+ * Max length of the string (if defined).
76
+ */
77
+ maxLength: number | undefined;
78
+ /**
79
+ * Max length validation error message provider.
80
+ * If not provided, default error message will be used.
81
+ */
82
+ maxLengthValidationErrorMessageProvider: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired, false, false, {}>>;
83
+ /**
84
+ * If set, restrict object to be equal to a certain value.
85
+ */
86
+ equalsTo: string | undefined;
87
+ /**
88
+ * Equals validation error message provider.
89
+ * If not provided, default error message will be used.
90
+ */
91
+ equalsToValidationErrorMessageProvider: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired, false, false, {}>>;
92
+ /**
93
+ * If set, restrict string to start with a certain value.
94
+ */
95
+ startsWith: string | undefined;
96
+ /**
97
+ * Starts with validation error message provider.
98
+ * If not provided, default error message will be used.
99
+ */
100
+ startsWithValidationErrorMessageProvider: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired, false, false, {}>>;
101
+ /**
102
+ * If set, restrict string to end with a certain value.
103
+ */
104
+ endsWith: string | undefined;
105
+ /**
106
+ * Ends with validation error message provider.
107
+ * If not provided, default error message will be used.
108
+ */
109
+ endsWithValidationErrorMessageProvider: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired, false, false, {}>>;
110
+ /**
111
+ * If set, restrict string to match a certain regular expression.
112
+ */
113
+ matches: RegExp | undefined;
114
+ /**
115
+ * Matches validation error message provider.
116
+ * If not provided, default error message will be used.
117
+ */
118
+ matchesValidationErrorMessageProvider: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired, false, false, {}>>;
119
+ /**
120
+ * Array of preprocessor functions
121
+ */
122
+ preprocessors: PreprocessorEntry<TResult>[];
123
+ /**
124
+ * Array of validator functions
125
+ */
126
+ validators: ValidatorEntry<TResult>[];
127
+ type: string;
128
+ isRequired: boolean;
129
+ isNullable: boolean;
130
+ isReadonly: boolean;
131
+ requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
132
+ extensions: {
133
+ [x: string]: unknown;
134
+ };
135
+ hasDefault: boolean;
136
+ defaultValue: TResult | (() => TResult) | undefined;
137
+ description: string | undefined;
138
+ hasCatch: boolean;
139
+ catchValue: TResult | (() => TResult) | undefined;
140
+ };
141
+ /**
142
+ * @inheritdoc
143
+ */
144
+ hasType<T>(_notUsed?: T): StringSchemaBuilder<T, true, TNullable, THasDefault, TExtensions> & TExtensions;
145
+ /**
146
+ * @inheritdoc
147
+ */
148
+ clearHasType(): StringSchemaBuilder<string, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
149
+ /** {@inheritDoc SchemaBuilder.validate} */
150
+ validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
151
+ /** {@inheritDoc SchemaBuilder.validateAsync} */
152
+ validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
153
+ /**
154
+ * Performs synchronous validation of string schema over `object`.
155
+ * Throws if any preprocessor, validator, or error message provider returns a Promise.
156
+ * @param context Optional `ValidationContext` settings.
157
+ */
158
+ protected _validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
159
+ /**
160
+ * Performs async validation of string schema over `object`.
161
+ * Supports async preprocessors, validators, and error message providers.
162
+ * @param context Optional `ValidationContext` settings.
163
+ */
164
+ protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
165
+ protected createFromProps<T, TReq extends boolean>(props: StringSchemaBuilderCreateProps<T, TReq>): this;
166
+ /**
167
+ * Restricts string to be equal to `value`.
168
+ */
169
+ equals<T extends string>(value: T,
170
+ /**
171
+ * Custom error message provider.
172
+ */
173
+ errorMessage?: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>): StringSchemaBuilder<T, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
174
+ /**
175
+ * Cancels `equals()` call.
176
+ */
177
+ clearEquals(): StringSchemaBuilder<string, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
178
+ /**
179
+ * @hidden
180
+ */
181
+ nullable(): StringSchemaBuilder<TResult, TRequired, true, THasDefault, TExtensions> & TExtensions;
182
+ /**
183
+ * @hidden
184
+ */
185
+ notNullable(): StringSchemaBuilder<TResult, TRequired, false, THasDefault, TExtensions> & TExtensions;
186
+ /**
187
+ * @hidden
188
+ */
189
+ required(errorMessage?: ValidationErrorMessageProvider): StringSchemaBuilder<TResult, true, TNullable, THasDefault, TExtensions> & TExtensions;
190
+ /**
191
+ * @hidden
192
+ */
193
+ optional(): StringSchemaBuilder<TResult, false, TNullable, THasDefault, TExtensions> & TExtensions;
194
+ /**
195
+ * @hidden
196
+ */
197
+ default(value: TResult | (() => TResult)): StringSchemaBuilder<TResult, true, TNullable, true, TExtensions> & TExtensions;
198
+ /**
199
+ * @hidden
200
+ */
201
+ clearDefault(): StringSchemaBuilder<TResult, TRequired, TNullable, false, TExtensions> & TExtensions;
202
+ /**
203
+ * @hidden
204
+ */
205
+ brand<TBrand extends string | symbol>(_name?: TBrand): StringSchemaBuilder<TResult & {
206
+ readonly [K in BRAND]: TBrand;
207
+ }, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
208
+ /**
209
+ * Marks the inferred type as `Readonly<string>`. Since strings are
210
+ * already immutable this is an identity operation, but it sets the
211
+ * `isReadonly` introspection flag for tooling consistency.
212
+ *
213
+ * @see {@link SchemaBuilder.readonly}
214
+ */
215
+ readonly(): StringSchemaBuilder<Readonly<TResult>, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
216
+ /**
217
+ * Set minimal length of the valid value for schema.
218
+ * @param length minimum string length
219
+ */
220
+ minLength(length: number,
221
+ /**
222
+ * Custom error message provider.
223
+ */
224
+ errorMessage?: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>): StringSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
225
+ /**
226
+ * Cancel `minLength()` call.
227
+ */
228
+ clearMinLength(): StringSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
229
+ /**
230
+ * Set maximal length of the valid value for schema.
231
+ * @param length maximum string length
232
+ */
233
+ maxLength(length: number,
234
+ /**
235
+ * Custom error message provider.
236
+ */
237
+ errorMessage?: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>): StringSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
238
+ /**
239
+ * Cancel `maxLength()` call.
240
+ */
241
+ clearMaxLength(): StringSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
242
+ /**
243
+ * Restricts string to start with `val`.
244
+ */
245
+ startsWith<T extends string>(val: T,
246
+ /**
247
+ * Custom error message provider.
248
+ */
249
+ errorMessage?: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>): StringSchemaBuilder<TResult extends string ? `${T}${TResult}` : TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
250
+ /**
251
+ * Cancels `startsWith()` call.
252
+ */
253
+ clearStartsWith(): StringSchemaBuilder<string, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
254
+ /**
255
+ * Restricts string to end with `val`.
256
+ */
257
+ endsWith<T extends string>(val: T,
258
+ /**
259
+ * Custom error message provider.
260
+ */
261
+ errorMessage?: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>): StringSchemaBuilder<TResult extends string ? `${TResult}${T}` : TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
262
+ /**
263
+ * Cancels `endsWith()` call.
264
+ */
265
+ clearEndsWith(): StringSchemaBuilder<string, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
266
+ /**
267
+ * Restricts string to match `regexp`.
268
+ * @param regexp regular expression pattern to match against
269
+ */
270
+ matches(regexp: RegExp,
271
+ /**
272
+ * Custom error message provider.
273
+ */
274
+ errorMessage?: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>): StringSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
275
+ /**
276
+ * Cancels `matches()` call.
277
+ */
278
+ clearMatches(): StringSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
279
+ }
280
+ /**
281
+ * Creates a string schema restricted to be equal to `equals`.
282
+ * @param equals string value the schema is restricted to
283
+ */
284
+ export declare function string<T extends string>(equals: T): StringSchemaBuilder<T, true>;
285
+ /**
286
+ * Creates a string schema restricted to be equal to `equals` with a custom error message.
287
+ * @param equals string value the schema is restricted to
288
+ */
289
+ export declare function string<T extends string>(equals: T, errorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<T, true>>): StringSchemaBuilder<T, true>;
290
+ export declare function string(): StringSchemaBuilder<string, true>;
291
+ export {};
@@ -0,0 +1,2 @@
1
+ import{a,b}from"../chunk-FWUEUW2N.js";import"../chunk-CTP4RHDG.js";export{a as StringSchemaBuilder,b as string};
2
+ //# sourceMappingURL=StringSchemaBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,248 @@
1
+ import type { ObjectSchemaBuilder, ObjectSchemaValidationResult } from './ObjectSchemaBuilder.js';
2
+ import { type BRAND, type InferType, type NestedValidationResult, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
3
+ import type { UnionSchemaBuilder, UnionSchemaValidationResult } from './UnionSchemaBuilder.js';
4
+ /**
5
+ * Maps a tuple of schema builders to a tuple of their per-position
6
+ * validation result types.
7
+ * Union schema elements get `UnionSchemaValidationResult`,
8
+ * object schema elements get `ObjectSchemaValidationResult`,
9
+ * other types get `ValidationResult`.
10
+ */
11
+ export type TupleElementValidationResults<TElements extends readonly SchemaBuilder<any, any, any, any, any>[]> = {
12
+ [K in keyof TElements]: TElements[K] extends UnionSchemaBuilder<infer UOptions extends readonly SchemaBuilder<any, any, any, any, any>[], any, any> ? UnionSchemaValidationResult<InferType<TElements[K]>, UOptions> : TElements[K] extends ObjectSchemaBuilder<any, any, any, any, any> ? ObjectSchemaValidationResult<InferType<TElements[K]>, TElements[K]> : ValidationResult<InferType<TElements[K]>>;
13
+ };
14
+ /**
15
+ * Validation result type returned by `TupleSchemaBuilder.validate()`.
16
+ * Extends `ValidationResult` with `getNestedErrors` for root-level tuple
17
+ * errors and per-position validation results.
18
+ */
19
+ export type TupleSchemaValidationResult<TResult, TElements extends readonly SchemaBuilder<any, any, any, any, any>[]> = ValidationResult<TResult> & {
20
+ /**
21
+ * Returns root-level tuple validation errors combined with
22
+ * per-position validation results.
23
+ * The returned value has both `NestedValidationResult` properties
24
+ * (`errors`, `isValid`, `descriptor`, `seenValue`) and indexed
25
+ * position results (`[0]`, `[1]`, etc.).
26
+ */
27
+ getNestedErrors(): TupleElementValidationResults<TElements> & NestedValidationResult<any, any, any>;
28
+ };
29
+ type TupleSchemaBuilderCreateProps<TElements extends readonly SchemaBuilder<any, any, any, any, any>[], TRestSchema extends SchemaBuilder<any, any, any, any, any> | undefined = undefined, R extends boolean = true, N extends boolean = false> = Partial<ReturnType<TupleSchemaBuilder<TElements, R, N, undefined, false, {}, TRestSchema>['introspect']>>;
30
+ /**
31
+ * Fixed-length array schema builder with per-position type validation.
32
+ * Similar to TypeScript's tuple types — each element at a specific array index
33
+ * is validated against its own schema.
34
+ *
35
+ * Use it when you need to validate function arguments, CSV rows, coordinate
36
+ * pairs, structured event payloads, or any other fixed-structure array.
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
40
+ * directly. Use {@link tuple | tuple()} function instead.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const schema = tuple([string(), number(), boolean()]);
45
+ * // Inferred TypeScript type: [string, number, boolean]
46
+ *
47
+ * schema.validate(['hello', 42, true]);
48
+ * // result.valid === true
49
+ * // result.object === ['hello', 42, true]
50
+ *
51
+ * schema.validate(['hello', 42]);
52
+ * // result.valid === false (too few elements)
53
+ *
54
+ * schema.validate(['hello', 'oops', true]);
55
+ * // result.valid === false (wrong type at position 1)
56
+ * ```
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // Tuple with variadic rest elements
61
+ * const schema = tuple([string(), number()]).rest(boolean());
62
+ * // Inferred TypeScript type: [string, number, ...boolean[]]
63
+ *
64
+ * schema.validate(['hello', 42, true, false]);
65
+ * // result.valid === true — any number of extra booleans allowed
66
+ * ```
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * // Nested tuple combining with object schemas
71
+ * const point = tuple([number(), number()]);
72
+ * const segment = tuple([point, point]);
73
+ *
74
+ * segment.validate([[0, 0], [10, 20]]);
75
+ * // result.valid === true
76
+ * ```
77
+ *
78
+ * @see {@link tuple}
79
+ */
80
+ export declare class TupleSchemaBuilder<TElements extends readonly SchemaBuilder<any, any, any, any, any>[], TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TRestSchema extends SchemaBuilder<any, any, any, any, any> | undefined = undefined, TResult = TExplicitType extends undefined ? TRestSchema extends SchemaBuilder<any, any, any, any, any> ? [
81
+ ...{
82
+ [K in keyof TElements]: InferType<TElements[K]>;
83
+ },
84
+ ...Array<InferType<TRestSchema>>
85
+ ] : {
86
+ [K in keyof TElements]: InferType<TElements[K]>;
87
+ } : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
88
+ #private;
89
+ /**
90
+ * @hidden
91
+ */
92
+ static create(props: TupleSchemaBuilderCreateProps<any, any, any, any>): TupleSchemaBuilder<readonly SchemaBuilder<any, any, any, any, any>[], true, false, undefined, false, {}, undefined, readonly any[]>;
93
+ protected constructor(props: TupleSchemaBuilderCreateProps<TElements, TRestSchema, TRequired, TNullable>);
94
+ /**
95
+ * @inheritdoc
96
+ */
97
+ hasType<T>(_notUsed?: T): TupleSchemaBuilder<TElements, true, TNullable, T, THasDefault, TExtensions, TRestSchema> & TExtensions;
98
+ /**
99
+ * @inheritdoc
100
+ */
101
+ clearHasType(): TupleSchemaBuilder<TElements, TRequired, TNullable, undefined, THasDefault, TExtensions, TRestSchema> & TExtensions;
102
+ /**
103
+ * Performs synchronous validation of the schema over `object`. {@inheritDoc SchemaBuilder.validate}
104
+ */
105
+ validate(object: TResult, context?: ValidationContext): TupleSchemaValidationResult<TResult, TElements>;
106
+ /**
107
+ * Performs asynchronous validation of the schema over `object`. {@inheritDoc SchemaBuilder.validateAsync}
108
+ */
109
+ validateAsync(object: TResult, context?: ValidationContext): Promise<TupleSchemaValidationResult<TResult, TElements>>;
110
+ /**
111
+ * Performs synchronous validation of the schema over `object`.
112
+ * Throws if any preprocessor, validator, or error message provider returns a Promise.
113
+ * @param context Optional `ValidationContext` settings.
114
+ */
115
+ protected _validate(object: TResult, context?: ValidationContext): TupleSchemaValidationResult<TResult, TElements>;
116
+ /**
117
+ * Performs async validation of the schema over `object`.
118
+ * Supports async preprocessors, validators, and error message providers.
119
+ * @param context Optional `ValidationContext` settings.
120
+ */
121
+ protected _validateAsync(object: TResult, context?: ValidationContext): Promise<TupleSchemaValidationResult<TResult, TElements>>;
122
+ /**
123
+ * @hidden
124
+ */
125
+ protected createFromProps<TReq extends boolean>(props: TupleSchemaBuilderCreateProps<TElements, TRestSchema, TReq>): this;
126
+ /**
127
+ * @hidden
128
+ */
129
+ required(errorMessage?: ValidationErrorMessageProvider): TupleSchemaBuilder<TElements, true, TNullable, TExplicitType, THasDefault, TExtensions, TRestSchema> & TExtensions;
130
+ /**
131
+ * @hidden
132
+ */
133
+ optional(): TupleSchemaBuilder<TElements, false, TNullable, TExplicitType, THasDefault, TExtensions, TRestSchema> & TExtensions;
134
+ /**
135
+ * @hidden
136
+ */
137
+ default(value: TResult | (() => TResult)): TupleSchemaBuilder<TElements, true, TNullable, TExplicitType, true, TExtensions, TRestSchema> & TExtensions;
138
+ /**
139
+ * @hidden
140
+ */
141
+ clearDefault(): TupleSchemaBuilder<TElements, TRequired, TNullable, TExplicitType, false, TExtensions, TRestSchema> & TExtensions;
142
+ /**
143
+ * @hidden
144
+ */
145
+ brand<TBrand extends string | symbol>(_name?: TBrand): TupleSchemaBuilder<TElements, TRequired, TNullable, TResult & {
146
+ readonly [K in BRAND]: TBrand;
147
+ }, THasDefault, TExtensions, TRestSchema> & TExtensions;
148
+ introspect(): {
149
+ /**
150
+ * Per-position element schemas defining the fixed tuple structure.
151
+ */
152
+ elements: TElements;
153
+ /**
154
+ * Optional schema for elements beyond the fixed positions.
155
+ * When set, additional elements are validated against this schema.
156
+ * Mirrors TypeScript's rest element syntax: `[string, number, ...boolean[]]`.
157
+ */
158
+ restSchema: (TRestSchema & SchemaBuilder<any, any, any, any, any>) | undefined;
159
+ type: string;
160
+ isRequired: boolean;
161
+ isNullable: boolean;
162
+ isReadonly: boolean;
163
+ preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TResult>[];
164
+ validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TResult>[];
165
+ requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
166
+ extensions: {
167
+ [x: string]: unknown;
168
+ };
169
+ hasDefault: boolean;
170
+ defaultValue: TResult | (() => TResult) | undefined;
171
+ description: string | undefined;
172
+ hasCatch: boolean;
173
+ catchValue: TResult | (() => TResult) | undefined;
174
+ };
175
+ /**
176
+ * Sets a schema that all elements beyond the fixed positions must satisfy.
177
+ * Mirrors TypeScript's variadic tuple tail: `[string, number, ...boolean[]]`.
178
+ *
179
+ * When set, the tuple length must be at least equal to the number of fixed
180
+ * elements, and any additional elements are validated against `schema`.
181
+ * When not set, the tuple length must be exactly equal to the fixed count.
182
+ *
183
+ * @param schema Schema that extra array elements must satisfy.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const schema = tuple([string(), number()]).rest(boolean());
188
+ * // Inferred TypeScript type: [string, number, ...boolean[]]
189
+ *
190
+ * schema.validate(['hello', 42]); // valid
191
+ * schema.validate(['hello', 42, true]); // valid
192
+ * schema.validate(['hello', 42, true, false]); // valid
193
+ * schema.validate(['hello', 42, 'extra']); // invalid — 'extra' not boolean
194
+ * ```
195
+ */
196
+ rest<TSchema extends SchemaBuilder<any, any, any, any, any>>(schema: TSchema): TupleSchemaBuilder<TElements, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TSchema> & TExtensions;
197
+ /**
198
+ * Removes the rest schema set by `rest()`. After this call, the tuple
199
+ * length must be exactly equal to the number of fixed element schemas.
200
+ */
201
+ clearRest(): TupleSchemaBuilder<TElements, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, undefined> & TExtensions;
202
+ /**
203
+ * @hidden
204
+ */
205
+ nullable(): TupleSchemaBuilder<TElements, TRequired, true, TExplicitType, THasDefault, TExtensions, TRestSchema> & TExtensions;
206
+ /**
207
+ * @hidden
208
+ */
209
+ notNullable(): TupleSchemaBuilder<TElements, TRequired, false, TExplicitType, THasDefault, TExtensions, TRestSchema> & TExtensions;
210
+ }
211
+ /**
212
+ * Creates a fixed-length array schema (tuple) where each element at a
213
+ * specific index is validated against its own schema.
214
+ *
215
+ * @param elements Array of per-position schemas. The length of this array
216
+ * determines the required tuple length (unless `.rest()` is used).
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * import { tuple, string, number, boolean } from '@cleverbrush/schema';
221
+ *
222
+ * const schema = tuple([string(), number(), boolean()]);
223
+ * // Inferred TypeScript type: [string, number, boolean]
224
+ *
225
+ * schema.validate(['hello', 42, true]); // valid
226
+ * schema.validate(['hello', 42]); // invalid — too few elements
227
+ * schema.validate(['hello', 'oops', true]); // invalid — wrong type at [1]
228
+ * ```
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * // 2-D coordinate pair
233
+ * const point = tuple([number(), number()]);
234
+ * const result = point.validate([10.5, 20.3]);
235
+ * // result.valid === true
236
+ * // result.object === [10.5, 20.3]
237
+ * ```
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * // Optional tuple with default value
242
+ * const schema = tuple([string(), number()])
243
+ * .optional()
244
+ * .default(() => ['', 0]);
245
+ * ```
246
+ */
247
+ export declare const tuple: <const TElements extends readonly SchemaBuilder<any, any, any, any, any>[]>(elements: [...TElements]) => TupleSchemaBuilder<TElements, true>;
248
+ export {};
@@ -0,0 +1,2 @@
1
+ import{a,b}from"../chunk-S5TC6NSU.js";import"../chunk-CTP4RHDG.js";export{a as TupleSchemaBuilder,b as tuple};
2
+ //# sourceMappingURL=TupleSchemaBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}