@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.
- package/README.md +1409 -0
- package/dist/builders/AnySchemaBuilder.d.ts +116 -0
- package/dist/builders/AnySchemaBuilder.js +2 -0
- package/dist/builders/AnySchemaBuilder.js.map +1 -0
- package/dist/builders/ArraySchemaBuilder.d.ts +214 -0
- package/dist/builders/ArraySchemaBuilder.js +2 -0
- package/dist/builders/ArraySchemaBuilder.js.map +1 -0
- package/dist/builders/BooleanSchemaBuilder.d.ts +146 -0
- package/dist/builders/BooleanSchemaBuilder.js +2 -0
- package/dist/builders/BooleanSchemaBuilder.js.map +1 -0
- package/dist/builders/DateSchemaBuilder.d.ts +277 -0
- package/dist/builders/DateSchemaBuilder.js +2 -0
- package/dist/builders/DateSchemaBuilder.js.map +1 -0
- package/dist/builders/ExternSchemaBuilder.d.ts +200 -0
- package/dist/builders/ExternSchemaBuilder.js +2 -0
- package/dist/builders/ExternSchemaBuilder.js.map +1 -0
- package/dist/builders/FunctionSchemaBuilder.d.ts +246 -0
- package/dist/builders/FunctionSchemaBuilder.js +2 -0
- package/dist/builders/FunctionSchemaBuilder.js.map +1 -0
- package/dist/builders/LazySchemaBuilder.d.ts +167 -0
- package/dist/builders/NullSchemaBuilder.d.ts +162 -0
- package/dist/builders/NumberSchemaBuilder.d.ts +273 -0
- package/dist/builders/NumberSchemaBuilder.js +2 -0
- package/dist/builders/NumberSchemaBuilder.js.map +1 -0
- package/dist/builders/ObjectSchemaBuilder.d.ts +517 -0
- package/dist/builders/ObjectSchemaBuilder.js +2 -0
- package/dist/builders/ObjectSchemaBuilder.js.map +1 -0
- package/dist/builders/PropertyValidationResult.d.ts +68 -0
- package/dist/builders/RecordSchemaBuilder.d.ts +341 -0
- package/dist/builders/RecordSchemaBuilder.js +2 -0
- package/dist/builders/RecordSchemaBuilder.js.map +1 -0
- package/dist/builders/SchemaBuilder.d.ts +947 -0
- package/dist/builders/StringSchemaBuilder.d.ts +291 -0
- package/dist/builders/StringSchemaBuilder.js +2 -0
- package/dist/builders/StringSchemaBuilder.js.map +1 -0
- package/dist/builders/TupleSchemaBuilder.d.ts +248 -0
- package/dist/builders/TupleSchemaBuilder.js +2 -0
- package/dist/builders/TupleSchemaBuilder.js.map +1 -0
- package/dist/builders/UnionSchemaBuilder.d.ts +227 -0
- package/dist/builders/UnionSchemaBuilder.js +2 -0
- package/dist/builders/UnionSchemaBuilder.js.map +1 -0
- package/dist/chunk-CTP4RHDG.js +2 -0
- package/dist/chunk-CTP4RHDG.js.map +1 -0
- package/dist/chunk-FWUEUW2N.js +2 -0
- package/dist/chunk-FWUEUW2N.js.map +1 -0
- package/dist/chunk-IJ6FO37G.js +2 -0
- package/dist/chunk-IJ6FO37G.js.map +1 -0
- package/dist/chunk-KESLT5EE.js +2 -0
- package/dist/chunk-KESLT5EE.js.map +1 -0
- package/dist/chunk-KFTO7TMB.js +2 -0
- package/dist/chunk-KFTO7TMB.js.map +1 -0
- package/dist/chunk-MKAYFPAR.js +2 -0
- package/dist/chunk-MKAYFPAR.js.map +1 -0
- package/dist/chunk-NXPH3ZUW.js +2 -0
- package/dist/chunk-NXPH3ZUW.js.map +1 -0
- package/dist/chunk-OOPF7RXS.js +2 -0
- package/dist/chunk-OOPF7RXS.js.map +1 -0
- package/dist/chunk-S5TC6NSU.js +2 -0
- package/dist/chunk-S5TC6NSU.js.map +1 -0
- package/dist/chunk-YWBNVHR6.js +2 -0
- package/dist/chunk-YWBNVHR6.js.map +1 -0
- package/dist/chunk-Z72HXYKX.js +2 -0
- package/dist/chunk-Z72HXYKX.js.map +1 -0
- package/dist/chunk-Z7QZ7IXT.js +2 -0
- package/dist/chunk-Z7QZ7IXT.js.map +1 -0
- package/dist/chunk-ZAN4ZHCJ.js +2 -0
- package/dist/chunk-ZAN4ZHCJ.js.map +1 -0
- package/dist/chunk-ZUPYV5TI.js +2 -0
- package/dist/chunk-ZUPYV5TI.js.map +1 -0
- package/dist/core.d.ts +23 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/extension.d.ts +413 -0
- package/dist/extensions/array.d.ts +112 -0
- package/dist/extensions/enum.d.ts +190 -0
- package/dist/extensions/index.d.ts +108 -0
- package/dist/extensions/nullable.d.ts +26 -0
- package/dist/extensions/number.d.ts +228 -0
- package/dist/extensions/string.d.ts +332 -0
- package/dist/extensions/util.d.ts +45 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/transaction.d.ts +69 -0
- package/package.json +104 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { type BRAND, type PreprocessorEntry, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult, type ValidatorEntry } from './SchemaBuilder.js';
|
|
2
|
+
type DateSchemaBuilderCreateProps<T = Date, R extends boolean = true> = Partial<ReturnType<DateSchemaBuilder<T, R, any>['introspect']>>;
|
|
3
|
+
/**
|
|
4
|
+
* Allows to create Date schema. It can be required or optional.
|
|
5
|
+
* It can be restricted to be: equal to a certain value, in future, in past, in a certain range.
|
|
6
|
+
* Supports parsing from JSON string and UNIX epoch (using preprocessors).
|
|
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
|
|
10
|
+
* directly. Use {@link date | date()} function instead.
|
|
11
|
+
*
|
|
12
|
+
* @example ```ts
|
|
13
|
+
* const date = new Date(2020, 0, 2);
|
|
14
|
+
* const schema = date().min(new Date(2020, 0, 1));
|
|
15
|
+
* const result = schema.validate(date);
|
|
16
|
+
* // result.valid === true
|
|
17
|
+
* // result.object === date
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example ```ts
|
|
21
|
+
* const schema = date();
|
|
22
|
+
* const result = schema.validate('2020-01-01');
|
|
23
|
+
* // result.valid === false
|
|
24
|
+
* // result.errors[0].message === 'is expected to be a date'
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example ```ts
|
|
28
|
+
* const schema = date().parseFromJson();
|
|
29
|
+
* const result = schema.validate('2020-01-01T00:00:00.000Z');
|
|
30
|
+
* // result.valid === true
|
|
31
|
+
* // result.object is equal to corresponding Date object
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example ```ts
|
|
35
|
+
* const schema = date().parseFromEpoch();
|
|
36
|
+
* const result = schema.validate(1577836800000);
|
|
37
|
+
* // result.valid === true
|
|
38
|
+
* // result.object is equal to corresponding Date object
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @see {@link date}
|
|
42
|
+
*/
|
|
43
|
+
export declare class DateSchemaBuilder<TResult = Date, TRequired extends boolean = true, TNullable extends boolean = false, THasDefault extends boolean = false, TExtensions = {}> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
|
|
44
|
+
#private;
|
|
45
|
+
/**
|
|
46
|
+
* @hidden
|
|
47
|
+
*/
|
|
48
|
+
static create(props: DateSchemaBuilderCreateProps): DateSchemaBuilder<Date, true, false, false, {}>;
|
|
49
|
+
protected constructor(props: DateSchemaBuilderCreateProps);
|
|
50
|
+
introspect(): {
|
|
51
|
+
/**
|
|
52
|
+
* Min valid value (if defined).
|
|
53
|
+
*/
|
|
54
|
+
min: Date | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Min value validation error message provider.
|
|
57
|
+
* If not provided, default error message will be used.
|
|
58
|
+
*/
|
|
59
|
+
minValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired, false, false, {}>>;
|
|
60
|
+
/**
|
|
61
|
+
* Max valid value (if defined).
|
|
62
|
+
*/
|
|
63
|
+
max: Date | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Max value validation error message provider.
|
|
66
|
+
* If not provided, default error message will be used.
|
|
67
|
+
*/
|
|
68
|
+
maxValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired, false, false, {}>>;
|
|
69
|
+
/**
|
|
70
|
+
* Make sure that date is in future. `false` by default.
|
|
71
|
+
*/
|
|
72
|
+
ensureIsInFuture: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Ensure in future validation error message provider.
|
|
75
|
+
* If not provided, default error message will be used.
|
|
76
|
+
*/
|
|
77
|
+
ensureIsInFutureValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired, false, false, {}>>;
|
|
78
|
+
/**
|
|
79
|
+
* Make sure that date is in past. `false` by default.
|
|
80
|
+
*/
|
|
81
|
+
ensureIsInPast: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Ensure in past validation error message provider.
|
|
84
|
+
* If not provided, default error message will be used.
|
|
85
|
+
*/
|
|
86
|
+
ensureIsInPastValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired, false, false, {}>>;
|
|
87
|
+
/**
|
|
88
|
+
* If set, restrict date to be equal to a certain value.
|
|
89
|
+
*/
|
|
90
|
+
equalsTo: Date | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Equals to validation error message provider.
|
|
93
|
+
* If not provided, default error message will be used.
|
|
94
|
+
*/
|
|
95
|
+
equalsToValidationErrorMessageProvider: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired, false, false, {}>>;
|
|
96
|
+
/**
|
|
97
|
+
* If set, schema will try to parse date from the UNIX epoch (number).
|
|
98
|
+
* `false` by default.
|
|
99
|
+
*/
|
|
100
|
+
parseFromEpoch: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* If set, schema will try to parse date from JSON string.
|
|
103
|
+
* `false` by default.
|
|
104
|
+
*/
|
|
105
|
+
parseFromJson: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Array of preprocessor functions
|
|
108
|
+
*/
|
|
109
|
+
preprocessors: PreprocessorEntry<TResult>[];
|
|
110
|
+
/**
|
|
111
|
+
* Array of validator functions
|
|
112
|
+
*/
|
|
113
|
+
validators: ValidatorEntry<TResult>[];
|
|
114
|
+
type: string;
|
|
115
|
+
isRequired: boolean;
|
|
116
|
+
isNullable: boolean;
|
|
117
|
+
isReadonly: boolean;
|
|
118
|
+
requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
|
|
119
|
+
extensions: {
|
|
120
|
+
[x: string]: unknown;
|
|
121
|
+
};
|
|
122
|
+
hasDefault: boolean;
|
|
123
|
+
defaultValue: TResult | (() => TResult) | undefined;
|
|
124
|
+
description: string | undefined;
|
|
125
|
+
hasCatch: boolean;
|
|
126
|
+
catchValue: TResult | (() => TResult) | undefined;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @inheritdoc
|
|
130
|
+
*/
|
|
131
|
+
hasType<T>(_notUsed?: T): DateSchemaBuilder<T, true, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
132
|
+
/**
|
|
133
|
+
* @inheritdoc
|
|
134
|
+
*/
|
|
135
|
+
clearHasType(): DateSchemaBuilder<Date, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
136
|
+
/** {@inheritDoc SchemaBuilder.validate} */
|
|
137
|
+
validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
138
|
+
/** {@inheritDoc SchemaBuilder.validateAsync} */
|
|
139
|
+
validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
140
|
+
/**
|
|
141
|
+
* Performs synchronous validation of Date schema over `object`.
|
|
142
|
+
* Throws if any preprocessor, validator, or error message provider returns a Promise.
|
|
143
|
+
* @param context Optional `ValidationContext` settings.
|
|
144
|
+
*/
|
|
145
|
+
protected _validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
146
|
+
/**
|
|
147
|
+
* Performs async validation of Date schema over `object`.
|
|
148
|
+
* Supports async preprocessors, validators, and error message providers.
|
|
149
|
+
* @param context Optional `ValidationContext` settings.
|
|
150
|
+
*/
|
|
151
|
+
protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
152
|
+
/**
|
|
153
|
+
* @hidden
|
|
154
|
+
*/
|
|
155
|
+
protected createFromProps<T, TReq extends boolean>(props: DateSchemaBuilderCreateProps<T, TReq>): this;
|
|
156
|
+
/**
|
|
157
|
+
* Restricts Date to be equal to `value`.
|
|
158
|
+
*/
|
|
159
|
+
equals<T extends Date>(value: T,
|
|
160
|
+
/**
|
|
161
|
+
* Custom error message provider.
|
|
162
|
+
*/
|
|
163
|
+
errorMessage?: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>): DateSchemaBuilder<T, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
164
|
+
/**
|
|
165
|
+
* Clears `equals()` call.
|
|
166
|
+
*/
|
|
167
|
+
clearEquals(): DateSchemaBuilder<Date, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
168
|
+
/**
|
|
169
|
+
* @hidden
|
|
170
|
+
*/
|
|
171
|
+
required(errorMessage?: ValidationErrorMessageProvider): DateSchemaBuilder<TResult, true, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
172
|
+
/**
|
|
173
|
+
* @hidden
|
|
174
|
+
*/
|
|
175
|
+
optional(): DateSchemaBuilder<TResult, false, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
176
|
+
/**
|
|
177
|
+
* @hidden
|
|
178
|
+
*/
|
|
179
|
+
default(value: TResult | (() => TResult)): DateSchemaBuilder<TResult, true, TNullable, true, TExtensions> & TExtensions;
|
|
180
|
+
/**
|
|
181
|
+
* @hidden
|
|
182
|
+
*/
|
|
183
|
+
clearDefault(): DateSchemaBuilder<TResult, TRequired, TNullable, false, TExtensions> & TExtensions;
|
|
184
|
+
/**
|
|
185
|
+
* @hidden
|
|
186
|
+
*/
|
|
187
|
+
brand<TBrand extends string | symbol>(_name?: TBrand): DateSchemaBuilder<TResult & {
|
|
188
|
+
readonly [K in BRAND]: TBrand;
|
|
189
|
+
}, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
190
|
+
/**
|
|
191
|
+
* Marks the inferred type as `Readonly<Date>` — prevents mutation of
|
|
192
|
+
* Date methods like `setFullYear()` at the type level. Validation
|
|
193
|
+
* behaviour is unchanged.
|
|
194
|
+
*
|
|
195
|
+
* @see {@link SchemaBuilder.readonly}
|
|
196
|
+
*/
|
|
197
|
+
readonly(): DateSchemaBuilder<Readonly<TResult>, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
198
|
+
/**
|
|
199
|
+
* Accept only dates in the future.
|
|
200
|
+
*/
|
|
201
|
+
isInFuture(
|
|
202
|
+
/**
|
|
203
|
+
* Custom error message provider.
|
|
204
|
+
*/
|
|
205
|
+
errorMessage?: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
206
|
+
/**
|
|
207
|
+
* Cancel `isInFuture()` call.
|
|
208
|
+
*/
|
|
209
|
+
clearIsInFuture(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
210
|
+
/**
|
|
211
|
+
* Accept only dates in the past.
|
|
212
|
+
*/
|
|
213
|
+
isInPast(
|
|
214
|
+
/**
|
|
215
|
+
* Custom error message provider.
|
|
216
|
+
*/
|
|
217
|
+
errorMessage?: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
218
|
+
/**
|
|
219
|
+
* Cancel `isInPast()` call.
|
|
220
|
+
*/
|
|
221
|
+
clearIsInPast(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
222
|
+
/**
|
|
223
|
+
* Set minimal valid Date value for schema.
|
|
224
|
+
*/
|
|
225
|
+
min(minValue: Date,
|
|
226
|
+
/**
|
|
227
|
+
* Custom error message provider.
|
|
228
|
+
*/
|
|
229
|
+
errorMessage?: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
230
|
+
/**
|
|
231
|
+
* Clear `min()` call.
|
|
232
|
+
*/
|
|
233
|
+
clearMin(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
234
|
+
/**
|
|
235
|
+
* Set maximal valid Date value for schema.
|
|
236
|
+
*/
|
|
237
|
+
max(maxValue: Date,
|
|
238
|
+
/**
|
|
239
|
+
* Custom error message provider.
|
|
240
|
+
*/
|
|
241
|
+
errorMessage?: ValidationErrorMessageProvider<DateSchemaBuilder<TResult, TRequired>>): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
242
|
+
/**
|
|
243
|
+
* Clear `max()` call.
|
|
244
|
+
*/
|
|
245
|
+
clearMax(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
246
|
+
/**
|
|
247
|
+
* Accepts JSON string as a valid Date.
|
|
248
|
+
* String must be in ISO format and will be parsed using `JSON.parse()`.
|
|
249
|
+
*/
|
|
250
|
+
acceptJsonString(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
251
|
+
/**
|
|
252
|
+
* Cancel `acceptJsonString()` call.
|
|
253
|
+
*/
|
|
254
|
+
doNotAcceptJsonString(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
255
|
+
/**
|
|
256
|
+
* Accepts epoch number as a valid Date.
|
|
257
|
+
* Epoch number will be parsed using `new Date(epoch)`.
|
|
258
|
+
*/
|
|
259
|
+
acceptEpoch(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
260
|
+
/**
|
|
261
|
+
* Cancel `acceptEpoch()` call.
|
|
262
|
+
*/
|
|
263
|
+
doNotAcceptEpoch(): DateSchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
|
|
264
|
+
/**
|
|
265
|
+
* @hidden
|
|
266
|
+
*/
|
|
267
|
+
nullable(): DateSchemaBuilder<TResult, TRequired, true, THasDefault, TExtensions> & TExtensions;
|
|
268
|
+
/**
|
|
269
|
+
* @hidden
|
|
270
|
+
*/
|
|
271
|
+
notNullable(): DateSchemaBuilder<TResult, TRequired, false, THasDefault, TExtensions> & TExtensions;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Creates a Date schema.
|
|
275
|
+
*/
|
|
276
|
+
export declare const date: () => DateSchemaBuilder<Date, true, false, false, {}>;
|
|
277
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { type BRAND, SchemaBuilder, SYMBOL_HAS_PROPERTIES, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
|
|
3
|
+
type ExternSchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnType<ExternSchemaBuilder<any, R>['introspect']>> & {
|
|
4
|
+
standardSchema: StandardSchemaV1;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Schema builder that wraps an external
|
|
8
|
+
* [Standard Schema v1](https://standardschema.dev/) compatible schema
|
|
9
|
+
* (e.g. Zod, Valibot, ArkType) into a `@cleverbrush/schema` builder.
|
|
10
|
+
*
|
|
11
|
+
* This enables cross-library schema composition — you can use a Zod schema
|
|
12
|
+
* as a property inside a `@cleverbrush/schema` object schema, and the
|
|
13
|
+
* inferred TypeScript type will be correct.
|
|
14
|
+
*
|
|
15
|
+
* Validation is delegated entirely to the external schema's
|
|
16
|
+
* `['~standard'].validate()` method. Standard Schema issues are mapped to
|
|
17
|
+
* `@cleverbrush/schema` `ValidationError` objects, with any issue paths
|
|
18
|
+
* formatted as dotted prefixes (e.g. `"address.city: must be a string"`).
|
|
19
|
+
*
|
|
20
|
+
* When used inside an `object()` schema, the property descriptor tree is
|
|
21
|
+
* built dynamically (via Proxy) from the external schema's output type,
|
|
22
|
+
* so `getErrorsFor(t => t.order.id)` works without any additional
|
|
23
|
+
* configuration.
|
|
24
|
+
*
|
|
25
|
+
* **NOTE** this class is exported only to give opportunity to extend it
|
|
26
|
+
* by inheriting. It is not recommended to create an instance of this class
|
|
27
|
+
* directly. Use the {@link extern | extern()} factory function instead.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { z } from 'zod';
|
|
32
|
+
* import { object, date, extern, InferType } from '@cleverbrush/schema';
|
|
33
|
+
*
|
|
34
|
+
* const zodUser = z.object({ first: z.string(), last: z.string() });
|
|
35
|
+
*
|
|
36
|
+
* const order = object({
|
|
37
|
+
* user: extern(zodUser),
|
|
38
|
+
* date: date(),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* type Order = InferType<typeof order>;
|
|
42
|
+
* // { user: { first: string; last: string }; date: Date }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see {@link extern}
|
|
46
|
+
*/
|
|
47
|
+
export declare class ExternSchemaBuilder<TStandardSchema extends StandardSchemaV1 = StandardSchemaV1, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResult = TExplicitType extends undefined ? StandardSchemaV1.InferOutput<TStandardSchema> : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
|
|
48
|
+
#private;
|
|
49
|
+
/**
|
|
50
|
+
* Always `true` for extern schemas — enables Proxy-based property
|
|
51
|
+
* descriptor trees and nested error propagation in
|
|
52
|
+
* `ObjectSchemaBuilder`.
|
|
53
|
+
*/
|
|
54
|
+
readonly [SYMBOL_HAS_PROPERTIES] = true;
|
|
55
|
+
/**
|
|
56
|
+
* @hidden
|
|
57
|
+
*/
|
|
58
|
+
static create(props: ExternSchemaBuilderCreateProps<any>): ExternSchemaBuilder<StandardSchemaV1<unknown, unknown>, true, false, undefined, false, {}, unknown>;
|
|
59
|
+
protected constructor(props: ExternSchemaBuilderCreateProps<TRequired>);
|
|
60
|
+
/**
|
|
61
|
+
* Returns the wrapped Standard Schema instance.
|
|
62
|
+
*/
|
|
63
|
+
get standardSchema(): TStandardSchema;
|
|
64
|
+
/**
|
|
65
|
+
* @inheritdoc
|
|
66
|
+
*/
|
|
67
|
+
hasType<T>(_notUsed?: T): ExternSchemaBuilder<TStandardSchema, true, TNullable, T, THasDefault, TExtensions> & TExtensions;
|
|
68
|
+
/**
|
|
69
|
+
* @inheritdoc
|
|
70
|
+
*/
|
|
71
|
+
clearHasType(): ExternSchemaBuilder<TStandardSchema, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
72
|
+
/** {@inheritDoc SchemaBuilder.validate} */
|
|
73
|
+
validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
74
|
+
/** {@inheritDoc SchemaBuilder.validateAsync} */
|
|
75
|
+
validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
76
|
+
/**
|
|
77
|
+
* Performs synchronous validation by delegating to the external
|
|
78
|
+
* Standard Schema's `validate()` method.
|
|
79
|
+
*
|
|
80
|
+
* If the external schema returns a `Promise` (async validation),
|
|
81
|
+
* this method throws — use {@link validateAsync} instead.
|
|
82
|
+
*/
|
|
83
|
+
protected _validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Performs async validation by delegating to the external
|
|
86
|
+
* Standard Schema's `validate()` method. Supports external schemas
|
|
87
|
+
* that return a `Promise` from their `validate()`.
|
|
88
|
+
*/
|
|
89
|
+
protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
90
|
+
protected createFromProps<TReq extends boolean>(props: ExternSchemaBuilderCreateProps<TReq>): this;
|
|
91
|
+
/**
|
|
92
|
+
* Returns a snapshot of the builder's internal state.
|
|
93
|
+
* Includes the wrapped `standardSchema` reference.
|
|
94
|
+
*/
|
|
95
|
+
introspect(): {
|
|
96
|
+
standardSchema: TStandardSchema;
|
|
97
|
+
type: string;
|
|
98
|
+
isRequired: boolean;
|
|
99
|
+
isNullable: boolean;
|
|
100
|
+
isReadonly: boolean;
|
|
101
|
+
preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TResult>[];
|
|
102
|
+
validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TResult>[];
|
|
103
|
+
requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
|
|
104
|
+
extensions: {
|
|
105
|
+
[x: string]: unknown;
|
|
106
|
+
};
|
|
107
|
+
hasDefault: boolean;
|
|
108
|
+
defaultValue: TResult | (() => TResult) | undefined;
|
|
109
|
+
description: string | undefined;
|
|
110
|
+
hasCatch: boolean;
|
|
111
|
+
catchValue: TResult | (() => TResult) | undefined;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* @hidden
|
|
115
|
+
*/
|
|
116
|
+
required(errorMessage?: ValidationErrorMessageProvider): ExternSchemaBuilder<TStandardSchema, true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
117
|
+
/**
|
|
118
|
+
* @hidden
|
|
119
|
+
*/
|
|
120
|
+
optional(): ExternSchemaBuilder<TStandardSchema, false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
121
|
+
/**
|
|
122
|
+
* @hidden
|
|
123
|
+
*/
|
|
124
|
+
default(value: TResult | (() => TResult)): ExternSchemaBuilder<TStandardSchema, true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
|
|
125
|
+
/**
|
|
126
|
+
* @hidden
|
|
127
|
+
*/
|
|
128
|
+
clearDefault(): ExternSchemaBuilder<TStandardSchema, TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
|
|
129
|
+
/**
|
|
130
|
+
* @hidden
|
|
131
|
+
*/
|
|
132
|
+
brand<TBrand extends string | symbol>(_name?: TBrand): ExternSchemaBuilder<TStandardSchema, TRequired, TNullable, TResult & {
|
|
133
|
+
readonly [K in BRAND]: TBrand;
|
|
134
|
+
}, THasDefault, TExtensions> & TExtensions;
|
|
135
|
+
/**
|
|
136
|
+
* Marks the inferred type as `Readonly<T>`. Sets the `isReadonly`
|
|
137
|
+
* introspection flag for tooling consistency.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link SchemaBuilder.readonly}
|
|
140
|
+
*/
|
|
141
|
+
readonly(): ExternSchemaBuilder<TStandardSchema, TRequired, TNullable, Readonly<TResult>, THasDefault, TExtensions> & TExtensions;
|
|
142
|
+
/**
|
|
143
|
+
* @hidden
|
|
144
|
+
*/
|
|
145
|
+
nullable(): ExternSchemaBuilder<TStandardSchema, TRequired, true, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
146
|
+
/**
|
|
147
|
+
* @hidden
|
|
148
|
+
*/
|
|
149
|
+
notNullable(): ExternSchemaBuilder<TStandardSchema, TRequired, false, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Wraps an external [Standard Schema v1](https://standardschema.dev/)
|
|
153
|
+
* compatible schema into a `@cleverbrush/schema` builder.
|
|
154
|
+
*
|
|
155
|
+
* This enables cross-library schema composition — use schemas from Zod,
|
|
156
|
+
* Valibot, ArkType, or any Standard Schema v1 compliant library as
|
|
157
|
+
* properties inside `@cleverbrush/schema` object schemas with full type
|
|
158
|
+
* inference.
|
|
159
|
+
*
|
|
160
|
+
* @param standardSchema - A Standard Schema v1 compliant schema instance
|
|
161
|
+
* (any object that exposes a `['~standard']` property with `version: 1`
|
|
162
|
+
* and a `validate` function).
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { z } from 'zod';
|
|
167
|
+
* import { object, date, extern, InferType } from '@cleverbrush/schema';
|
|
168
|
+
*
|
|
169
|
+
* const zodUser = z.object({ first: z.string(), last: z.string() });
|
|
170
|
+
*
|
|
171
|
+
* const order = object({
|
|
172
|
+
* user: extern(zodUser),
|
|
173
|
+
* date: date(),
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* type Order = InferType<typeof order>;
|
|
177
|
+
* // { user: { first: string; last: string }; date: Date }
|
|
178
|
+
*
|
|
179
|
+
* order.validate({
|
|
180
|
+
* user: { first: 'Alice', last: 'Smith' },
|
|
181
|
+
* date: new Date(),
|
|
182
|
+
* }); // { valid: true, object: { user: …, date: … } }
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* // Optional external schema
|
|
188
|
+
* const schema = extern(zodUser).optional();
|
|
189
|
+
* schema.validate(undefined); // valid
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* // Inside an array
|
|
195
|
+
* import { array, extern } from '@cleverbrush/schema';
|
|
196
|
+
* const users = array(extern(zodUser));
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare const extern: <T extends StandardSchemaV1>(standardSchema: T) => ExternSchemaBuilder<T, true>;
|
|
200
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|