@cleverbrush/schema 2.0.0 → 3.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.
- package/README.md +412 -8
- package/dist/builders/AnySchemaBuilder.js +1 -1
- package/dist/builders/ArraySchemaBuilder.d.ts +2 -0
- package/dist/builders/ArraySchemaBuilder.js +1 -1
- package/dist/builders/BooleanSchemaBuilder.d.ts +15 -0
- package/dist/builders/BooleanSchemaBuilder.js +1 -1
- package/dist/builders/DateSchemaBuilder.d.ts +20 -0
- package/dist/builders/DateSchemaBuilder.js +1 -1
- package/dist/builders/ExternSchemaBuilder.d.ts +2 -0
- package/dist/builders/ExternSchemaBuilder.js +1 -1
- package/dist/builders/FunctionSchemaBuilder.d.ts +162 -18
- package/dist/builders/FunctionSchemaBuilder.js +1 -1
- package/dist/builders/GenericSchemaBuilder.d.ts +294 -0
- package/dist/builders/LazySchemaBuilder.d.ts +2 -0
- package/dist/builders/NumberSchemaBuilder.d.ts +16 -0
- package/dist/builders/NumberSchemaBuilder.js +1 -1
- package/dist/builders/ObjectSchemaBuilder.d.ts +262 -42
- package/dist/builders/ObjectSchemaBuilder.js +1 -1
- package/dist/builders/ParseStringSchemaBuilder.d.ts +204 -0
- package/dist/builders/ParseStringSchemaBuilder.js +2 -0
- package/dist/builders/ParseStringSchemaBuilder.js.map +1 -0
- package/dist/builders/PromiseSchemaBuilder.d.ts +213 -0
- package/dist/builders/PromiseSchemaBuilder.js +2 -0
- package/dist/builders/PromiseSchemaBuilder.js.map +1 -0
- package/dist/builders/RecordSchemaBuilder.d.ts +2 -0
- package/dist/builders/RecordSchemaBuilder.js +1 -1
- package/dist/builders/SchemaBuilder.d.ts +89 -0
- package/dist/builders/StringSchemaBuilder.d.ts +2 -0
- package/dist/builders/StringSchemaBuilder.js +1 -1
- package/dist/builders/TupleSchemaBuilder.d.ts +2 -0
- package/dist/builders/TupleSchemaBuilder.js +1 -1
- package/dist/builders/UnionSchemaBuilder.d.ts +8 -0
- package/dist/builders/UnionSchemaBuilder.js +1 -1
- package/dist/chunk-3JMDGYDT.js +2 -0
- package/dist/chunk-3JMDGYDT.js.map +1 -0
- package/dist/{chunk-KESLT5EE.js → chunk-BUEVZ3KA.js} +2 -2
- package/dist/{chunk-KESLT5EE.js.map → chunk-BUEVZ3KA.js.map} +1 -1
- package/dist/{chunk-KFTO7TMB.js → chunk-CFIJQ4GP.js} +2 -2
- package/dist/{chunk-KFTO7TMB.js.map → chunk-CFIJQ4GP.js.map} +1 -1
- package/dist/chunk-DY7J6RNN.js +2 -0
- package/dist/chunk-DY7J6RNN.js.map +1 -0
- package/dist/{chunk-YWBNVHR6.js → chunk-EIVZX4ZO.js} +2 -2
- package/dist/{chunk-YWBNVHR6.js.map → chunk-EIVZX4ZO.js.map} +1 -1
- package/dist/chunk-GXPV6UQK.js +2 -0
- package/dist/chunk-GXPV6UQK.js.map +1 -0
- package/dist/{chunk-ZAN4ZHCJ.js → chunk-HN774HD7.js} +2 -2
- package/dist/chunk-K6Z47OQY.js +2 -0
- package/dist/chunk-K6Z47OQY.js.map +1 -0
- package/dist/chunk-NUW3VXZV.js +2 -0
- package/dist/chunk-NUW3VXZV.js.map +1 -0
- package/dist/{chunk-MKAYFPAR.js → chunk-PHE4LIAN.js} +2 -2
- package/dist/chunk-QARCEYGO.js +2 -0
- package/dist/chunk-QARCEYGO.js.map +1 -0
- package/dist/chunk-WDMJBGBD.js +2 -0
- package/dist/chunk-WDMJBGBD.js.map +1 -0
- package/dist/chunk-WQDYWDOE.js +2 -0
- package/dist/chunk-WQDYWDOE.js.map +1 -0
- package/dist/{chunk-FWUEUW2N.js → chunk-YQZHDMRF.js} +2 -2
- package/dist/chunk-ZC6YBKCP.js +2 -0
- package/dist/chunk-ZC6YBKCP.js.map +1 -0
- package/dist/{chunk-IJ6FO37G.js → chunk-ZFI27R3L.js} +2 -2
- package/dist/core.d.ts +7 -2
- package/dist/core.js +1 -1
- package/dist/extension.d.ts +10 -2
- package/dist/extensions/index.d.ts +5 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -4
- package/dist/chunk-BFCMDDTX.js +0 -2
- package/dist/chunk-BFCMDDTX.js.map +0 -1
- package/dist/chunk-CTP4RHDG.js +0 -2
- package/dist/chunk-CTP4RHDG.js.map +0 -1
- package/dist/chunk-EUQ5AE3H.js +0 -2
- package/dist/chunk-EUQ5AE3H.js.map +0 -1
- package/dist/chunk-NXPH3ZUW.js +0 -2
- package/dist/chunk-NXPH3ZUW.js.map +0 -1
- package/dist/chunk-S5TC6NSU.js +0 -2
- package/dist/chunk-S5TC6NSU.js.map +0 -1
- package/dist/chunk-Z7QZ7IXT.js +0 -2
- package/dist/chunk-Z7QZ7IXT.js.map +0 -1
- package/dist/chunk-ZUPYV5TI.js +0 -2
- package/dist/chunk-ZUPYV5TI.js.map +0 -1
- /package/dist/{chunk-ZAN4ZHCJ.js.map → chunk-HN774HD7.js.map} +0 -0
- /package/dist/{chunk-MKAYFPAR.js.map → chunk-PHE4LIAN.js.map} +0 -0
- /package/dist/{chunk-FWUEUW2N.js.map → chunk-YQZHDMRF.js.map} +0 -0
- /package/dist/{chunk-IJ6FO37G.js.map → chunk-ZFI27R3L.js.map} +0 -0
|
@@ -6,12 +6,78 @@ import { type BRAND, type InferType, type NestedValidationResult, type PreValida
|
|
|
6
6
|
* from the schema for the further usage. e.g. to select source and destination
|
|
7
7
|
* properties for object mappings
|
|
8
8
|
*/
|
|
9
|
-
export type SchemaPropertySelector<TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any>, TPropertySchema extends SchemaBuilder<any, any, any, any, any>, TAssignableTo = any, TParentPropertyDescriptor = undefined> = (l: PropertyDescriptorTree<TSchema, TSchema, TAssignableTo>) => PropertyDescriptor<TSchema, TPropertySchema, TParentPropertyDescriptor>;
|
|
9
|
+
export type SchemaPropertySelector<TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>, TPropertySchema extends SchemaBuilder<any, any, any, any, any>, TAssignableTo = any, TParentPropertyDescriptor = undefined> = (l: PropertyDescriptorTree<TSchema, TSchema, TAssignableTo>) => PropertyDescriptor<TSchema, TPropertySchema, TParentPropertyDescriptor>;
|
|
10
10
|
type ObjectSchemaBuilderProps<T extends Record<string, SchemaBuilder> = {}, TRequired extends boolean = true> = ReturnType<ObjectSchemaBuilder<T, TRequired>['introspect']>;
|
|
11
11
|
type ObjectSchemaBuilderCreateProps<T extends Record<string, SchemaBuilder> = {}, TRequired extends boolean = true> = Partial<ObjectSchemaBuilderProps<T, TRequired>>;
|
|
12
12
|
type Id<T> = T extends infer U ? {
|
|
13
13
|
[K in keyof U]: U[K];
|
|
14
14
|
} : never;
|
|
15
|
+
/**
|
|
16
|
+
* Extracts the positional argument types from a schema whose inferred type is a
|
|
17
|
+
* function. When the branded `InferType<T>` resolves to a function type the
|
|
18
|
+
* parameter tuple is extracted; otherwise `any[]` is used as a safe fallback.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* type Args = ConstructorParams<typeof func().addParameter(string()).addParameter(number())>;
|
|
23
|
+
* // → [string, number]
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
type ConstructorParams<T extends SchemaBuilder<any, any, any, any, any>> = InferType<T> extends (...args: infer A) => any ? A : any[];
|
|
27
|
+
/**
|
|
28
|
+
* Converts a tuple of `FunctionSchemaBuilder`s into an intersection of
|
|
29
|
+
* `new (...args) => TInstance` call signatures, producing overloaded
|
|
30
|
+
* construct signatures in the inferred type.
|
|
31
|
+
*
|
|
32
|
+
* The recursion peels schemas off the front of `TSchemas` one at a time,
|
|
33
|
+
* each contributing one construct overload to the intersection.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* type Sigs = ConstructorSignatures<
|
|
38
|
+
* [typeof func().addParameter(string()), typeof func().addParameter(number())],
|
|
39
|
+
* { name: string }
|
|
40
|
+
* >;
|
|
41
|
+
* // → { new (p0: string): { name: string } }
|
|
42
|
+
* // & { new (p0: number): { name: string } }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
type ConstructorSignatures<TSchemas extends SchemaBuilder<any, any, any, any, any>[], TInstance> = TSchemas extends [
|
|
46
|
+
infer THead extends SchemaBuilder<any, any, any, any, any>,
|
|
47
|
+
...infer TTail extends SchemaBuilder<any, any, any, any, any>[]
|
|
48
|
+
] ? {
|
|
49
|
+
new (...args: ConstructorParams<THead>): TInstance;
|
|
50
|
+
} & ConstructorSignatures<TTail, TInstance> : unknown;
|
|
51
|
+
/**
|
|
52
|
+
* Wraps `TInstance` with constructor overload signatures derived from
|
|
53
|
+
* `TSchemas`. When the tuple is empty the type is returned unchanged
|
|
54
|
+
* (no-op); otherwise the result is an intersection of all construct
|
|
55
|
+
* signatures with `TInstance`.
|
|
56
|
+
*
|
|
57
|
+
* This is the type projected onto `InferType<ObjectSchemaBuilder>` when one
|
|
58
|
+
* or more constructors have been registered via `.addConstructor()`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* // No constructors — passthrough
|
|
63
|
+
* type A = WithConstructors<[], { name: string }>;
|
|
64
|
+
* // → { name: string }
|
|
65
|
+
*
|
|
66
|
+
* // One constructor
|
|
67
|
+
* type B = WithConstructors<[typeof func().addParameter(string())], { name: string }>;
|
|
68
|
+
* // → { new (p0: string): { name: string } } & { name: string }
|
|
69
|
+
*
|
|
70
|
+
* // Two constructors → overloaded construct signatures
|
|
71
|
+
* type C = WithConstructors<
|
|
72
|
+
* [typeof func().addParameter(string()), typeof func().addParameter(number())],
|
|
73
|
+
* { name: string }
|
|
74
|
+
* >;
|
|
75
|
+
* // → { new (p0: string): { name: string } }
|
|
76
|
+
* // & { new (p0: number): { name: string } }
|
|
77
|
+
* // & { name: string }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
type WithConstructors<TSchemas extends SchemaBuilder<any, any, any, any, any>[], TInstance> = TSchemas extends [] ? TInstance : ConstructorSignatures<TSchemas, TInstance> & TInstance;
|
|
15
81
|
export type RespectPropsOptionality<T extends Record<string, SchemaBuilder<any, any, any, any, any>>> = {
|
|
16
82
|
[K in RequiredProps<T>]: InferType<T[K]>;
|
|
17
83
|
} & {
|
|
@@ -34,7 +100,7 @@ type MakeChildrenOptional<T extends Record<string, SchemaBuilder<any, any, any,
|
|
|
34
100
|
* unions, primitives) are only made optional at the top level.
|
|
35
101
|
*/
|
|
36
102
|
type DeepMakeChildrenOptional<T extends Record<string, SchemaBuilder<any, any, any, any, any>>> = {
|
|
37
|
-
[K in keyof T]: T[K] extends ObjectSchemaBuilder<infer P extends Record<string, SchemaBuilder<any, any, any, any, any>>, any, any, any, any, any> ? ReturnType<ReturnType<T[K]['deepPartial']>['optional']> : ReturnType<T[K]['optional']>;
|
|
103
|
+
[K in keyof T]: T[K] extends ObjectSchemaBuilder<infer P extends Record<string, SchemaBuilder<any, any, any, any, any>>, any, any, any, any, any, any> ? ReturnType<ReturnType<T[K]['deepPartial']>['optional']> : ReturnType<T[K]['optional']>;
|
|
38
104
|
};
|
|
39
105
|
type MakeChildOptional<T extends Record<any, SchemaBuilder<any, any, any, any, any>>, TProp extends keyof T> = {
|
|
40
106
|
[K in keyof T]: K extends TProp ? ReturnType<T[K]['optional']> : T[K];
|
|
@@ -45,7 +111,7 @@ type MakeChildRequired<T extends Record<any, SchemaBuilder<any, any, any, any, a
|
|
|
45
111
|
type ModifyPropSchema<T extends Record<any, SchemaBuilder<any, any, any, any, any>>, TProp extends keyof T, TSchema extends SchemaBuilder<any, any, any, any, any>> = {
|
|
46
112
|
[K in keyof T]: K extends TProp ? TSchema : T[K];
|
|
47
113
|
};
|
|
48
|
-
export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any, any>, TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any> = TRootSchema> = Omit<ValidationResult<T>, 'errors'> & {
|
|
114
|
+
export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>, TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any> = TRootSchema> = Omit<ValidationResult<T>, 'errors'> & {
|
|
49
115
|
/**
|
|
50
116
|
* A flat list of validation errors.
|
|
51
117
|
*
|
|
@@ -63,7 +129,16 @@ export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuil
|
|
|
63
129
|
*
|
|
64
130
|
* @param selector a callback function to select property from the schema.
|
|
65
131
|
*/
|
|
66
|
-
getErrorsFor<TPropertySchema, TParentPropertyDescriptor>(selector?: (properties: PropertyDescriptorTree<TSchema, TRootSchema>) => PropertyDescriptor<TRootSchema, TPropertySchema, TParentPropertyDescriptor>): TPropertySchema extends ObjectSchemaBuilder<any, any, any, any, any, any> ? PropertyValidationResult<TPropertySchema, TRootSchema, TParentPropertyDescriptor> : NestedValidationResult<TPropertySchema, TRootSchema, TParentPropertyDescriptor>;
|
|
132
|
+
getErrorsFor<TPropertySchema, TParentPropertyDescriptor>(selector?: (properties: PropertyDescriptorTree<TSchema, TRootSchema>) => PropertyDescriptor<TRootSchema, TPropertySchema, TParentPropertyDescriptor>): TPropertySchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any> ? PropertyValidationResult<TPropertySchema, TRootSchema, TParentPropertyDescriptor> : NestedValidationResult<TPropertySchema, TRootSchema, TParentPropertyDescriptor>;
|
|
133
|
+
/**
|
|
134
|
+
* Returns a list of all property validation results that have direct
|
|
135
|
+
* validation errors. Each entry exposes `.descriptor` (with
|
|
136
|
+
* `.toJsonPointer()` for the property's path) and `.errors`.
|
|
137
|
+
*
|
|
138
|
+
* This is useful for collecting all errors with their full JSON Pointer
|
|
139
|
+
* paths, e.g. for building RFC 9457 Problem Details responses.
|
|
140
|
+
*/
|
|
141
|
+
getInvalidProperties(): ReadonlyArray<NestedValidationResult<any, TRootSchema, any>>;
|
|
67
142
|
};
|
|
68
143
|
/**
|
|
69
144
|
* Object schema builder class. Similar to the `object` type
|
|
@@ -151,14 +226,14 @@ export type ObjectSchemaValidationResult<T, TRootSchema extends ObjectSchemaBuil
|
|
|
151
226
|
* ```
|
|
152
227
|
* @see {@link object}
|
|
153
228
|
*/
|
|
154
|
-
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 = {}> extends SchemaBuilder<undefined extends TExplicitType ? RespectPropsOptionality<TProperties
|
|
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> {
|
|
155
230
|
#private;
|
|
156
231
|
/** Marks this builder as having sub-properties for descriptor tree recursion. */
|
|
157
232
|
readonly [SYMBOL_HAS_PROPERTIES] = true;
|
|
158
233
|
/**
|
|
159
234
|
* @hidden
|
|
160
235
|
*/
|
|
161
|
-
static create<P extends Record<string, SchemaBuilder>, R extends boolean>(props: ObjectSchemaBuilderCreateProps<P, R>): ObjectSchemaBuilder<{}, true, false, undefined, false, {}>;
|
|
236
|
+
static create<P extends Record<string, SchemaBuilder>, R extends boolean>(props: ObjectSchemaBuilderCreateProps<P, R>): ObjectSchemaBuilder<{}, true, false, undefined, false, {}, []>;
|
|
162
237
|
protected createFromProps<T extends Record<string, SchemaBuilder>, R extends boolean = true>(props: ObjectSchemaBuilderCreateProps<T, R>): this;
|
|
163
238
|
protected constructor(props: ObjectSchemaBuilderCreateProps);
|
|
164
239
|
introspect(): {
|
|
@@ -173,57 +248,101 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
|
|
|
173
248
|
* Set to `false` by default
|
|
174
249
|
*/
|
|
175
250
|
acceptUnknownProps: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* The list of constructor schemas registered via `.addConstructor()`.
|
|
253
|
+
* Each element is a `FunctionSchemaBuilder` whose inferred function
|
|
254
|
+
* type provides one overloaded construct signature in `InferType`.
|
|
255
|
+
* Empty array when no constructors have been added.
|
|
256
|
+
*/
|
|
257
|
+
constructorSchemas: TConstructorSchemas;
|
|
176
258
|
type: string;
|
|
177
259
|
isRequired: boolean;
|
|
178
260
|
isNullable: boolean;
|
|
179
261
|
isReadonly: boolean;
|
|
180
|
-
preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<undefined extends TExplicitType ? RespectPropsOptionality<TProperties
|
|
181
|
-
validators: readonly import("./SchemaBuilder.js").ValidatorEntry<undefined extends TExplicitType ? RespectPropsOptionality<TProperties
|
|
262
|
+
preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType>[];
|
|
263
|
+
validators: readonly import("./SchemaBuilder.js").ValidatorEntry<undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType>[];
|
|
182
264
|
requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
|
|
183
265
|
extensions: {
|
|
184
266
|
[x: string]: unknown;
|
|
185
267
|
};
|
|
186
268
|
hasDefault: boolean;
|
|
187
|
-
defaultValue: (undefined extends TExplicitType ? RespectPropsOptionality<TProperties
|
|
269
|
+
defaultValue: (undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | (() => undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | undefined;
|
|
188
270
|
description: string | undefined;
|
|
271
|
+
schemaName: string | undefined;
|
|
189
272
|
hasCatch: boolean;
|
|
190
|
-
catchValue: (undefined extends TExplicitType ? RespectPropsOptionality<TProperties
|
|
273
|
+
catchValue: (undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | (() => undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) | undefined;
|
|
274
|
+
example: unknown;
|
|
191
275
|
};
|
|
192
276
|
/**
|
|
193
277
|
* @hidden
|
|
194
278
|
*/
|
|
195
|
-
required(errorMessage?: ValidationErrorMessageProvider): ObjectSchemaBuilder<TProperties, true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
279
|
+
required(errorMessage?: ValidationErrorMessageProvider): ObjectSchemaBuilder<TProperties, true, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
196
280
|
/**
|
|
197
281
|
* @hidden
|
|
198
282
|
*/
|
|
199
|
-
optional(): ObjectSchemaBuilder<TProperties, false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
283
|
+
optional(): ObjectSchemaBuilder<TProperties, false, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
200
284
|
/**
|
|
201
285
|
* @hidden
|
|
202
286
|
*/
|
|
203
|
-
default(value: (undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType) | (() => undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType)): ObjectSchemaBuilder<TProperties, true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
|
|
287
|
+
default(value: (undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType) | (() => undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType)): ObjectSchemaBuilder<TProperties, true, TNullable, TExplicitType, true, TExtensions, TConstructorSchemas> & TExtensions;
|
|
204
288
|
/**
|
|
205
289
|
* @hidden
|
|
206
290
|
*/
|
|
207
|
-
clearDefault(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
|
|
291
|
+
clearDefault(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, false, TExtensions, TConstructorSchemas> & TExtensions;
|
|
208
292
|
/**
|
|
209
293
|
* @hidden
|
|
210
294
|
*/
|
|
211
295
|
brand<TBrand extends string | symbol>(_name?: TBrand): ObjectSchemaBuilder<TProperties, TRequired, TNullable, (undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType) & {
|
|
212
296
|
readonly [K in BRAND]: TBrand;
|
|
213
|
-
}, THasDefault, TExtensions> & TExtensions;
|
|
297
|
+
}, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
214
298
|
/**
|
|
215
299
|
* Marks the inferred type as `Readonly<T>` — all top-level properties
|
|
216
300
|
* become `readonly` at the type level. Validation behaviour is unchanged.
|
|
217
301
|
*
|
|
218
302
|
* @see {@link SchemaBuilder.readonly}
|
|
219
303
|
*/
|
|
220
|
-
readonly(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, Readonly<undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType>, THasDefault, TExtensions> & TExtensions;
|
|
304
|
+
readonly(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, Readonly<undefined extends TExplicitType ? RespectPropsOptionality<TProperties> : TExplicitType>, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
221
305
|
protected preValidateSync(object: any, context?: ValidationContext<this>): PreValidationResult<InferType<SchemaBuilder<undefined extends TExplicitType ? Id<RespectPropsOptionality<TProperties>> : TExplicitType, TRequired>>, {
|
|
222
306
|
validatedObject: any;
|
|
223
307
|
}>;
|
|
224
308
|
protected preValidateAsync(object: any, context?: ValidationContext<this>): Promise<PreValidationResult<InferType<SchemaBuilder<undefined extends TExplicitType ? Id<RespectPropsOptionality<TProperties>> : TExplicitType, TRequired>>, {
|
|
225
309
|
validatedObject: any;
|
|
226
310
|
}>>;
|
|
311
|
+
/**
|
|
312
|
+
* Adds a `validator` to validators list.
|
|
313
|
+
*
|
|
314
|
+
* Object-level validators can return errors with a `property` selector
|
|
315
|
+
* to route the error to a specific property, making it visible via
|
|
316
|
+
* `getErrorsFor()`.
|
|
317
|
+
*
|
|
318
|
+
* ```ts
|
|
319
|
+
* schema.addValidator((value) => ({
|
|
320
|
+
* valid: false,
|
|
321
|
+
* errors: [{
|
|
322
|
+
* message: 'Passwords do not match',
|
|
323
|
+
* property: (t) => t.confirmPassword
|
|
324
|
+
* }]
|
|
325
|
+
* }));
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* The `property` selector uses the same `PropertyDescriptorTree`
|
|
329
|
+
* as `getErrorsFor()` and react-form's `forProperty`.
|
|
330
|
+
*/
|
|
331
|
+
addValidator(validator: (object: undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, RespectPropsOptionality<TProperties>> : TExplicitType) => {
|
|
332
|
+
valid: boolean;
|
|
333
|
+
errors?: Array<{
|
|
334
|
+
message: string;
|
|
335
|
+
property?: (properties: PropertyDescriptorTree<ObjectSchemaBuilder<TProperties>>) => PropertyDescriptor<any, any, any>;
|
|
336
|
+
}>;
|
|
337
|
+
} | Promise<{
|
|
338
|
+
valid: boolean;
|
|
339
|
+
errors?: Array<{
|
|
340
|
+
message: string;
|
|
341
|
+
property?: (properties: PropertyDescriptorTree<ObjectSchemaBuilder<TProperties>>) => PropertyDescriptor<any, any, any>;
|
|
342
|
+
}>;
|
|
343
|
+
}>, options?: {
|
|
344
|
+
mutates?: boolean;
|
|
345
|
+
}): this;
|
|
227
346
|
/**
|
|
228
347
|
* Performs synchronous validation of object schema over the `object`.
|
|
229
348
|
* Throws if any preprocessor, validator, or error message provider returns a Promise.
|
|
@@ -263,20 +382,121 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
|
|
|
263
382
|
* Fields not defined in `properties` will not be validated
|
|
264
383
|
* and will be passed through the validation.
|
|
265
384
|
*/
|
|
266
|
-
acceptUnknownProps(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
385
|
+
acceptUnknownProps(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
267
386
|
/**
|
|
268
387
|
* Fields not defined in `properties` will be considered
|
|
269
388
|
* as schema violation. This is the default behavior.
|
|
270
389
|
*/
|
|
271
|
-
notAcceptUnknownProps(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
390
|
+
notAcceptUnknownProps(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
272
391
|
/**
|
|
273
392
|
* @inheritdoc
|
|
274
393
|
*/
|
|
275
|
-
hasType<T>(_notUsed?: T): ObjectSchemaBuilder<TProperties, TRequired, TNullable, T, THasDefault, TExtensions> & TExtensions;
|
|
394
|
+
hasType<T>(_notUsed?: T): ObjectSchemaBuilder<TProperties, TRequired, TNullable, T, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
276
395
|
/**
|
|
277
396
|
* @inheritdoc
|
|
278
397
|
*/
|
|
279
|
-
clearHasType(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
398
|
+
clearHasType(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, undefined, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
399
|
+
/**
|
|
400
|
+
* Appends a constructor overload to the object schema.
|
|
401
|
+
*
|
|
402
|
+
* Each call extends the set of construct signatures on the inferred type by
|
|
403
|
+
* one overload. The accumulated argument lists are taken from the
|
|
404
|
+
* `FunctionSchemaBuilder` passed in — specifically from the positional
|
|
405
|
+
* parameter schemas registered via `.addParameter()`.
|
|
406
|
+
*
|
|
407
|
+
* At **runtime** the schema continues to validate plain objects; the
|
|
408
|
+
* constructor information is purely a TypeScript-level annotation and is
|
|
409
|
+
* stored in `introspect().constructorSchemas` for tooling use.
|
|
410
|
+
*
|
|
411
|
+
* Multiple calls are supported and produce **overloaded** construct
|
|
412
|
+
* signatures in the inferred type, modelling a class that exposes several
|
|
413
|
+
* constructor overloads.
|
|
414
|
+
*
|
|
415
|
+
* @param schema - A `FunctionSchemaBuilder` describing one constructor
|
|
416
|
+
* overload. Use `.addParameter()` on the function schema to declare the
|
|
417
|
+
* parameter types. The return type, if set via `.hasReturnType()`, is
|
|
418
|
+
* ignored — the return type of a constructor is always the instance type
|
|
419
|
+
* derived from the object schema's properties.
|
|
420
|
+
*
|
|
421
|
+
* @returns A new `ObjectSchemaBuilder` whose `TConstructorSchemas` tuple has
|
|
422
|
+
* been extended by `schema`, updating `InferType` to include the new
|
|
423
|
+
* construct signature.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* import { object, string, number, func, InferType } from '@cleverbrush/schema';
|
|
428
|
+
*
|
|
429
|
+
* // Single constructor
|
|
430
|
+
* const PersonSchema = object({ name: string(), age: number() })
|
|
431
|
+
* .addConstructor(
|
|
432
|
+
* func().addParameter(string()).addParameter(number())
|
|
433
|
+
* );
|
|
434
|
+
*
|
|
435
|
+
* type Person = InferType<typeof PersonSchema>;
|
|
436
|
+
* // → { new (p0: string, p1: number): { name: string; age: number } }
|
|
437
|
+
* // & { name: string; age: number }
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* import { object, string, number, func, InferType } from '@cleverbrush/schema';
|
|
443
|
+
*
|
|
444
|
+
* // Multiple constructors via chained calls → overloaded signatures
|
|
445
|
+
* const PointSchema = object({ x: number(), y: number() })
|
|
446
|
+
* .addConstructor(func()) // no-arg ctor
|
|
447
|
+
* .addConstructor(func().addParameter(number()).addParameter(number())); // (x, y) ctor
|
|
448
|
+
*
|
|
449
|
+
* type Point = InferType<typeof PointSchema>;
|
|
450
|
+
* // → { new (): { x: number; y: number } }
|
|
451
|
+
* // & { new (p0: number, p1: number): { x: number; y: number } }
|
|
452
|
+
* // & { x: number; y: number }
|
|
453
|
+
*
|
|
454
|
+
* // Validation still operates on plain objects — the constructor type is
|
|
455
|
+
* // a compile-time annotation only.
|
|
456
|
+
* const result = PointSchema.validate({ x: 1, y: 2 });
|
|
457
|
+
* // result.valid === true
|
|
458
|
+
*
|
|
459
|
+
* // Introspect the registered constructor schemas at runtime:
|
|
460
|
+
* const info = PointSchema.introspect();
|
|
461
|
+
* // info.constructorSchemas.length === 2
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
addConstructor<TFunc extends SchemaBuilder<any, any, any, any, any>>(schema: TFunc): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, [
|
|
465
|
+
...TConstructorSchemas,
|
|
466
|
+
TFunc
|
|
467
|
+
]> & TExtensions;
|
|
468
|
+
/**
|
|
469
|
+
* Removes all constructor overloads previously registered via
|
|
470
|
+
* `.addConstructor()`, resetting the `TConstructorSchemas` tuple to `[]`.
|
|
471
|
+
*
|
|
472
|
+
* After calling this method `InferType` reverts to the plain object type
|
|
473
|
+
* derived from the schema's properties — no construct signatures are
|
|
474
|
+
* included.
|
|
475
|
+
*
|
|
476
|
+
* `introspect().constructorSchemas` will return an empty array.
|
|
477
|
+
*
|
|
478
|
+
* @returns A new `ObjectSchemaBuilder` with `TConstructorSchemas = []`.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* import { object, string, func, InferType } from '@cleverbrush/schema';
|
|
483
|
+
*
|
|
484
|
+
* const WithCtor = object({ name: string() })
|
|
485
|
+
* .addConstructor(func().addParameter(string()));
|
|
486
|
+
*
|
|
487
|
+
* type WithCtorType = InferType<typeof WithCtor>;
|
|
488
|
+
* // → { new (p0: string): { name: string } } & { name: string }
|
|
489
|
+
*
|
|
490
|
+
* const Plain = WithCtor.clearConstructors();
|
|
491
|
+
*
|
|
492
|
+
* type PlainType = InferType<typeof Plain>;
|
|
493
|
+
* // → { name: string }
|
|
494
|
+
*
|
|
495
|
+
* Plain.introspect().constructorSchemas; // []
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
clearConstructors(): ObjectSchemaBuilder<TProperties, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, [
|
|
499
|
+
]> & TExtensions;
|
|
280
500
|
/**
|
|
281
501
|
* Adds a new property to the object schema. The new property
|
|
282
502
|
* will be validated according to the provided schema.
|
|
@@ -285,7 +505,7 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
|
|
|
285
505
|
*/
|
|
286
506
|
addProp<TType extends SchemaBuilder<any, any, any, any, any>, TName extends string>(propName: TName, schema: TType): ObjectSchemaBuilder<TProperties & {
|
|
287
507
|
[k in TName]: TType;
|
|
288
|
-
}, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
508
|
+
}, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
289
509
|
/**
|
|
290
510
|
* @hidden
|
|
291
511
|
* @deprecated this is for internal use, do not use if you are
|
|
@@ -300,62 +520,62 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
|
|
|
300
520
|
* comments were lost. Hopefully it will be fixed in the future by Typescript team or somebody will
|
|
301
521
|
* find a workaround/fix and create a pull request.
|
|
302
522
|
*/
|
|
303
|
-
optimize(): SchemaBuilder<undefined extends TExplicitType ? Id<RespectPropsOptionality<TProperties
|
|
523
|
+
optimize(): SchemaBuilder<undefined extends TExplicitType ? WithConstructors<TConstructorSchemas, Id<RespectPropsOptionality<TProperties>>> : TExplicitType, TRequired, TNullable, THasDefault, TExtensions>;
|
|
304
524
|
/**
|
|
305
525
|
* Adds new properties to the object schema. The same as `.addProp()` but
|
|
306
526
|
* allows to add multiple properties with one call. The new properties
|
|
307
527
|
* will be validated according to the provided schemas.
|
|
308
528
|
* @param props a key/schema object map.
|
|
309
529
|
*/
|
|
310
|
-
addProps<TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>>(props: TProps): ObjectSchemaBuilder<TProperties & TProps, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
530
|
+
addProps<TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>>(props: TProps): ObjectSchemaBuilder<TProperties & TProps, TRequired, TNullable, undefined, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
311
531
|
/**
|
|
312
532
|
* Adds all properties from the `schema` object schema to the current schema.
|
|
313
533
|
* @param schema an instance of `ObjectSchemaBuilder`
|
|
314
534
|
*/
|
|
315
|
-
addProps<K extends ObjectSchemaBuilder<any, any, any, any, any, any>>(schema: K): K extends ObjectSchemaBuilder<infer TProp, infer _, any, infer __> ? ObjectSchemaBuilder<Omit<TProperties, keyof TProp> & TProp, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions : never;
|
|
535
|
+
addProps<K extends ObjectSchemaBuilder<any, any, any, any, any, any, any>>(schema: K): K extends ObjectSchemaBuilder<infer TProp, infer _, any, infer __> ? ObjectSchemaBuilder<Omit<TProperties, keyof TProp> & TProp, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions : never;
|
|
316
536
|
/**
|
|
317
537
|
* Omits properties listed in `properties` from the schema.
|
|
318
538
|
* Consider `Omit<Type, 'prop1'|'prop2'...>` as a good illustration
|
|
319
539
|
* from the TS world.
|
|
320
540
|
* @param properties - array of property names (strings) to remove from the schema.
|
|
321
541
|
*/
|
|
322
|
-
omit<K extends keyof TProperties>(properties: K[]): ObjectSchemaBuilder<Omit<TProperties, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
542
|
+
omit<K extends keyof TProperties>(properties: K[]): ObjectSchemaBuilder<Omit<TProperties, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
323
543
|
/**
|
|
324
544
|
* Removes `propName` from the list of properties.
|
|
325
545
|
* @param propName property name to remove. Schema should contain
|
|
326
546
|
* this property. An error will be thrown otherwise.
|
|
327
547
|
*/
|
|
328
|
-
omit<TProperty extends keyof TProperties>(propName: TProperty): ObjectSchemaBuilder<Omit<TProperties, TProperty>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
548
|
+
omit<TProperty extends keyof TProperties>(propName: TProperty): ObjectSchemaBuilder<Omit<TProperties, TProperty>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
329
549
|
/**
|
|
330
550
|
* Removes all properties of `schema` from the current schema.
|
|
331
551
|
* `Omit<TSchema, keyof TAnotherSchema>` as a good illustration
|
|
332
552
|
* from the TS world.
|
|
333
553
|
* @param schema schema builder to take properties from.
|
|
334
554
|
*/
|
|
335
|
-
omit<T>(schema: T): T extends ObjectSchemaBuilder<infer TProps, infer TRequired, any, infer TExplicitType> ? ObjectSchemaBuilder<Omit<TProperties, keyof TProps>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions : never;
|
|
555
|
+
omit<T>(schema: T): T extends ObjectSchemaBuilder<infer TProps, infer TRequired, any, infer TExplicitType> ? ObjectSchemaBuilder<Omit<TProperties, keyof TProps>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions : never;
|
|
336
556
|
/**
|
|
337
557
|
* Adds all properties from `schema` to the current schema.
|
|
338
558
|
* `TSchema & TAnotherSchema` is a good example of the similar concept
|
|
339
559
|
* in the TS type system.
|
|
340
560
|
* @param schema an object schema to take properties from
|
|
341
561
|
*/
|
|
342
|
-
intersect<T extends ObjectSchemaBuilder<any, any, any, any, any, any>>(schema: T): T extends ObjectSchemaBuilder<infer TProps, infer _, any, infer TExplType> ? ObjectSchemaBuilder<Omit<TProperties, keyof TProps> & TProps, TRequired, TNullable, TExplType, THasDefault, TExtensions> & TExtensions : never;
|
|
562
|
+
intersect<T extends ObjectSchemaBuilder<any, any, any, any, any, any, any>>(schema: T): T extends ObjectSchemaBuilder<infer TProps, infer _, any, infer TExplType> ? ObjectSchemaBuilder<Omit<TProperties, keyof TProps> & TProps, TRequired, TNullable, TExplType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions : never;
|
|
343
563
|
/**
|
|
344
564
|
* Marks all properties in the current schema as optional.
|
|
345
565
|
* It is the same as call `.optional('propname')` where `propname` is the name
|
|
346
566
|
* of every property in the schema.
|
|
347
567
|
*/
|
|
348
|
-
partial(): ObjectSchemaBuilder<MakeChildrenOptional<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
568
|
+
partial(): ObjectSchemaBuilder<MakeChildrenOptional<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
349
569
|
/**
|
|
350
570
|
* Marks all properties from `properties` as optional in the schema.
|
|
351
571
|
* @param properties list of property names (string) to make optional
|
|
352
572
|
*/
|
|
353
|
-
partial<K extends keyof TProperties>(properties: K[]): ObjectSchemaBuilder<Omit<TProperties, K> & Pick<MakeChildrenOptional<TProperties>, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
573
|
+
partial<K extends keyof TProperties>(properties: K[]): ObjectSchemaBuilder<Omit<TProperties, K> & Pick<MakeChildrenOptional<TProperties>, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
354
574
|
/**
|
|
355
575
|
* Marks property `propName` as optional in the schema.
|
|
356
576
|
* @param propName the name of the property (string).
|
|
357
577
|
*/
|
|
358
|
-
partial<TProperty extends keyof TProperties>(propName: TProperty): ObjectSchemaBuilder<Omit<TProperties, TProperty> & Pick<MakeChildrenOptional<TProperties>, TProperty>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
578
|
+
partial<TProperty extends keyof TProperties>(propName: TProperty): ObjectSchemaBuilder<Omit<TProperties, TProperty> & Pick<MakeChildrenOptional<TProperties>, TProperty>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
359
579
|
/**
|
|
360
580
|
* Recursively marks all properties — and all properties of nested
|
|
361
581
|
* `object()` schemas — as optional. Useful for PATCH API bodies
|
|
@@ -414,27 +634,27 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
|
|
|
414
634
|
*
|
|
415
635
|
* @see {@link partial} for shallow-only property optionality.
|
|
416
636
|
*/
|
|
417
|
-
deepPartial(): ObjectSchemaBuilder<DeepMakeChildrenOptional<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
637
|
+
deepPartial(): ObjectSchemaBuilder<DeepMakeChildrenOptional<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
418
638
|
/**
|
|
419
639
|
* Returns a new schema containing only properties listed in
|
|
420
640
|
* `properties` array.
|
|
421
641
|
* @param properties array of property names (strings)
|
|
422
642
|
*/
|
|
423
|
-
pick<K extends keyof TProperties>(properties: K[]): ObjectSchemaBuilder<Pick<TProperties, K>, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
643
|
+
pick<K extends keyof TProperties>(properties: K[]): ObjectSchemaBuilder<Pick<TProperties, K>, TRequired, TNullable, undefined, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
424
644
|
/**
|
|
425
645
|
* Returns new schema based on the current schema. This new schema
|
|
426
646
|
* will consists only from properties which names are taken from the
|
|
427
647
|
* `schema` object schema.
|
|
428
648
|
* @param schema schema to take property names list from
|
|
429
649
|
*/
|
|
430
|
-
pick<K extends ObjectSchemaBuilder<any, any, any, any, any, any>>(schema: K): K extends ObjectSchemaBuilder<infer TProps, infer _, any, infer __> ? ObjectSchemaBuilder<Omit<TProperties, keyof Omit<TProperties, keyof TProps>>, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions : never;
|
|
650
|
+
pick<K extends ObjectSchemaBuilder<any, any, any, any, any, any, any>>(schema: K): K extends ObjectSchemaBuilder<infer TProps, infer _, any, infer __> ? ObjectSchemaBuilder<Omit<TProperties, keyof Omit<TProperties, keyof TProps>>, TRequired, TNullable, undefined, THasDefault, TExtensions, TConstructorSchemas> & TExtensions : never;
|
|
431
651
|
/**
|
|
432
652
|
* Returns a new schema consisting of only one property
|
|
433
653
|
* (taken from the `property` property name). If the property
|
|
434
654
|
* does not exists in the current schema, an error will be thrown.
|
|
435
655
|
* @param property the name of the property (string).
|
|
436
656
|
*/
|
|
437
|
-
pick<K extends keyof TProperties>(property: K): ObjectSchemaBuilder<Pick<TProperties, K>, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
657
|
+
pick<K extends keyof TProperties>(property: K): ObjectSchemaBuilder<Pick<TProperties, K>, TRequired, TNullable, undefined, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
438
658
|
/**
|
|
439
659
|
* Modify schema for `propName` and return a new schema.
|
|
440
660
|
* Could be useful if you want to leave all schema intact, but
|
|
@@ -444,33 +664,33 @@ export declare class ObjectSchemaBuilder<TProperties extends Record<string, Sche
|
|
|
444
664
|
* you will receive an old schema for `propName`.
|
|
445
665
|
* @returns
|
|
446
666
|
*/
|
|
447
|
-
modifyPropSchema<K extends keyof TProperties, R extends SchemaBuilder<any, any, any, any, any>>(propName: K, callback: (builder: TProperties[K]) => R): ObjectSchemaBuilder<ModifyPropSchema<TProperties, K, R>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
667
|
+
modifyPropSchema<K extends keyof TProperties, R extends SchemaBuilder<any, any, any, any, any>>(propName: K, callback: (builder: TProperties[K]) => R): ObjectSchemaBuilder<ModifyPropSchema<TProperties, K, R>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
448
668
|
/**
|
|
449
669
|
* An alias for `.partial(prop: string)`
|
|
450
670
|
* @param prop name of the property
|
|
451
671
|
*/
|
|
452
|
-
makePropOptional<K extends keyof TProperties>(prop: K): ObjectSchemaBuilder<MakeChildOptional<TProperties, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
672
|
+
makePropOptional<K extends keyof TProperties>(prop: K): ObjectSchemaBuilder<MakeChildOptional<TProperties, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
453
673
|
/**
|
|
454
674
|
* Marks `prop` as required property.
|
|
455
675
|
* If `prop` does not exists in the current schema,
|
|
456
676
|
* an error will be thrown.
|
|
457
677
|
* @param prop name of the property
|
|
458
678
|
*/
|
|
459
|
-
makePropRequired<K extends keyof TProperties>(prop: K): ObjectSchemaBuilder<MakeChildRequired<TProperties, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
679
|
+
makePropRequired<K extends keyof TProperties>(prop: K): ObjectSchemaBuilder<MakeChildRequired<TProperties, K>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
460
680
|
/**
|
|
461
681
|
* `Partial<T>` would be a good example of the
|
|
462
682
|
* same operation in the TS world.
|
|
463
683
|
*/
|
|
464
|
-
makeAllPropsOptional(): ObjectSchemaBuilder<MakeChildrenOptional<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
684
|
+
makeAllPropsOptional(): ObjectSchemaBuilder<MakeChildrenOptional<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
465
685
|
/**
|
|
466
686
|
* `Required<T>` would be a good example of the
|
|
467
687
|
* same operation in the TS world.
|
|
468
688
|
*/
|
|
469
|
-
makeAllPropsRequired(): ObjectSchemaBuilder<MakeChildrenRequired<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
689
|
+
makeAllPropsRequired(): ObjectSchemaBuilder<MakeChildrenRequired<TProperties>, TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TConstructorSchemas> & TExtensions;
|
|
470
690
|
static getPropertiesFor<TProperties extends Record<string, SchemaBuilder<any, any, any, any, any>> = {}, TRequired extends boolean = true, TExplicitType = undefined, TSchema extends ObjectSchemaBuilder<any, any, any, any> = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>>(schema: TSchema): PropertyDescriptorTree<TSchema, TSchema>;
|
|
471
691
|
static isValidPropertyDescriptor(descriptor: PropertyDescriptor<any, any, any>): boolean;
|
|
472
|
-
nullable(): ObjectSchemaBuilder<TProperties, TRequired, true, TExplicitType, THasDefault, TExtensions>;
|
|
473
|
-
notNullable(): ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType, THasDefault, TExtensions>;
|
|
692
|
+
nullable(): ObjectSchemaBuilder<TProperties, TRequired, true, TExplicitType, THasDefault, TExtensions, TConstructorSchemas>;
|
|
693
|
+
notNullable(): ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType, THasDefault, TExtensions, TConstructorSchemas>;
|
|
474
694
|
}
|
|
475
695
|
export interface Object {
|
|
476
696
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-K6Z47OQY.js";import"../chunk-3JMDGYDT.js";export{a as ObjectSchemaBuilder,b as object};
|
|
2
2
|
//# sourceMappingURL=ObjectSchemaBuilder.js.map
|