@cleverbrush/schema 1.1.11 → 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.
Files changed (98) hide show
  1. package/README.md +1721 -104
  2. package/dist/builders/AnySchemaBuilder.d.ts +54 -14
  3. package/dist/builders/AnySchemaBuilder.js +2 -112
  4. package/dist/builders/AnySchemaBuilder.js.map +1 -0
  5. package/dist/builders/ArraySchemaBuilder.d.ts +126 -23
  6. package/dist/builders/ArraySchemaBuilder.js +2 -284
  7. package/dist/builders/ArraySchemaBuilder.js.map +1 -0
  8. package/dist/builders/BooleanSchemaBuilder.d.ts +109 -19
  9. package/dist/builders/BooleanSchemaBuilder.js +2 -150
  10. package/dist/builders/BooleanSchemaBuilder.js.map +1 -0
  11. package/dist/builders/DateSchemaBuilder.d.ts +154 -34
  12. package/dist/builders/DateSchemaBuilder.js +2 -433
  13. package/dist/builders/DateSchemaBuilder.js.map +1 -0
  14. package/dist/builders/ExternSchemaBuilder.d.ts +202 -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 +205 -18
  18. package/dist/builders/FunctionSchemaBuilder.js +2 -113
  19. package/dist/builders/FunctionSchemaBuilder.js.map +1 -0
  20. package/dist/builders/GenericSchemaBuilder.d.ts +294 -0
  21. package/dist/builders/LazySchemaBuilder.d.ts +169 -0
  22. package/dist/builders/NullSchemaBuilder.d.ts +162 -0
  23. package/dist/builders/NumberSchemaBuilder.d.ts +159 -31
  24. package/dist/builders/NumberSchemaBuilder.js +2 -386
  25. package/dist/builders/NumberSchemaBuilder.js.map +1 -0
  26. package/dist/builders/ObjectSchemaBuilder.d.ts +486 -61
  27. package/dist/builders/ObjectSchemaBuilder.js +2 -589
  28. package/dist/builders/ObjectSchemaBuilder.js.map +1 -0
  29. package/dist/builders/ParseStringSchemaBuilder.d.ts +204 -0
  30. package/dist/builders/ParseStringSchemaBuilder.js +2 -0
  31. package/dist/builders/ParseStringSchemaBuilder.js.map +1 -0
  32. package/dist/builders/PromiseSchemaBuilder.d.ts +213 -0
  33. package/dist/builders/PromiseSchemaBuilder.js +2 -0
  34. package/dist/builders/PromiseSchemaBuilder.js.map +1 -0
  35. package/dist/builders/PropertyValidationResult.d.ts +68 -0
  36. package/dist/builders/RecordSchemaBuilder.d.ts +343 -0
  37. package/dist/builders/RecordSchemaBuilder.js +2 -0
  38. package/dist/builders/RecordSchemaBuilder.js.map +1 -0
  39. package/dist/builders/SchemaBuilder.d.ts +907 -30
  40. package/dist/builders/StringSchemaBuilder.d.ts +154 -37
  41. package/dist/builders/StringSchemaBuilder.js +2 -414
  42. package/dist/builders/StringSchemaBuilder.js.map +1 -0
  43. package/dist/builders/TupleSchemaBuilder.d.ts +250 -0
  44. package/dist/builders/TupleSchemaBuilder.js +2 -0
  45. package/dist/builders/TupleSchemaBuilder.js.map +1 -0
  46. package/dist/builders/UnionSchemaBuilder.d.ts +141 -39
  47. package/dist/builders/UnionSchemaBuilder.js +2 -216
  48. package/dist/builders/UnionSchemaBuilder.js.map +1 -0
  49. package/dist/chunk-3JMDGYDT.js +2 -0
  50. package/dist/chunk-3JMDGYDT.js.map +1 -0
  51. package/dist/chunk-BUEVZ3KA.js +2 -0
  52. package/dist/chunk-BUEVZ3KA.js.map +1 -0
  53. package/dist/chunk-CFIJQ4GP.js +2 -0
  54. package/dist/chunk-CFIJQ4GP.js.map +1 -0
  55. package/dist/chunk-DY7J6RNN.js +2 -0
  56. package/dist/chunk-DY7J6RNN.js.map +1 -0
  57. package/dist/chunk-EIVZX4ZO.js +2 -0
  58. package/dist/chunk-EIVZX4ZO.js.map +1 -0
  59. package/dist/chunk-GXPV6UQK.js +2 -0
  60. package/dist/chunk-GXPV6UQK.js.map +1 -0
  61. package/dist/chunk-HN774HD7.js +2 -0
  62. package/dist/chunk-HN774HD7.js.map +1 -0
  63. package/dist/chunk-K6Z47OQY.js +2 -0
  64. package/dist/chunk-K6Z47OQY.js.map +1 -0
  65. package/dist/chunk-NUW3VXZV.js +2 -0
  66. package/dist/chunk-NUW3VXZV.js.map +1 -0
  67. package/dist/chunk-PHE4LIAN.js +2 -0
  68. package/dist/chunk-PHE4LIAN.js.map +1 -0
  69. package/dist/chunk-QARCEYGO.js +2 -0
  70. package/dist/chunk-QARCEYGO.js.map +1 -0
  71. package/dist/chunk-WDMJBGBD.js +2 -0
  72. package/dist/chunk-WDMJBGBD.js.map +1 -0
  73. package/dist/chunk-WQDYWDOE.js +2 -0
  74. package/dist/chunk-WQDYWDOE.js.map +1 -0
  75. package/dist/chunk-YQZHDMRF.js +2 -0
  76. package/dist/chunk-YQZHDMRF.js.map +1 -0
  77. package/dist/chunk-ZC6YBKCP.js +2 -0
  78. package/dist/chunk-ZC6YBKCP.js.map +1 -0
  79. package/dist/chunk-ZFI27R3L.js +2 -0
  80. package/dist/chunk-ZFI27R3L.js.map +1 -0
  81. package/dist/core.d.ts +28 -0
  82. package/dist/core.js +2 -0
  83. package/dist/core.js.map +1 -0
  84. package/dist/extension.d.ts +421 -0
  85. package/dist/extensions/array.d.ts +112 -0
  86. package/dist/extensions/enum.d.ts +190 -0
  87. package/dist/extensions/index.d.ts +112 -0
  88. package/dist/extensions/nullable.d.ts +26 -0
  89. package/dist/extensions/number.d.ts +228 -0
  90. package/dist/extensions/string.d.ts +332 -0
  91. package/dist/extensions/util.d.ts +45 -0
  92. package/dist/index.d.ts +10 -20
  93. package/dist/index.js +2 -19
  94. package/dist/index.js.map +1 -0
  95. package/dist/utils/transaction.d.ts +27 -4
  96. package/package.json +83 -7
  97. package/dist/builders/SchemaBuilder.js +0 -275
  98. package/dist/utils/transaction.js +0 -178
@@ -0,0 +1,204 @@
1
+ import { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';
2
+ import { type BRAND, type InferType, type PropertyDescriptor, type PropertyDescriptorInner, type PropertyDescriptorTree, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
3
+ /** Descriptor for a single interpolation segment captured at creation time. */
4
+ type SegmentDef = {
5
+ /** The property schema for this segment. */
6
+ schema: SchemaBuilder<any, any, any, any, any>;
7
+ /** Dot-separated property path (e.g. `'order.id'`) — used in error messages. */
8
+ path: string;
9
+ /** The property descriptor inner — used to set parsed values on the result object. */
10
+ descriptor: PropertyDescriptorInner<any, any, any>;
11
+ };
12
+ /** Internal data captured by the `$template` tagged-template invocation. */
13
+ type ParseStringTemplateDefinition = {
14
+ /** Literal string fragments from the tagged template. */
15
+ literals: readonly string[];
16
+ /** One segment per interpolation expression, in order. */
17
+ segments: readonly SegmentDef[];
18
+ };
19
+ /**
20
+ * The typed tagged-template function passed to the `parseString`
21
+ * callback. Template expressions must be property-selector lambdas that
22
+ * navigate the {@link PropertyDescriptorTree} of the object schema.
23
+ *
24
+ * Only properties whose inferred type extends `string | number | boolean | Date`
25
+ * are selectable — nested `ObjectSchemaBuilder` children are navigable but
26
+ * not themselves endpoints.
27
+ */
28
+ export type ParseStringTemplateTag<TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>> = (strings: TemplateStringsArray, ...selectors: Array<(tree: PropertyDescriptorTree<TSchema, TSchema, string | number | boolean | Date>) => PropertyDescriptor<TSchema, any, any>>) => ParseStringTemplateDefinition;
29
+ type ParseStringSchemaBuilderCreateProps<T = any, R extends boolean = true> = Partial<ReturnType<ParseStringSchemaBuilder<T, R>['introspect']>>;
30
+ /**
31
+ * Validates a string against a template pattern and parses it
32
+ * into a strongly-typed object.
33
+ *
34
+ * Created via the {@link parseString} factory:
35
+ *
36
+ * ```ts
37
+ * const RouteSchema = parseString(
38
+ * object({ userId: string().uuid(), id: number() }),
39
+ * $t => $t`/orders/${t => t.id}/${t => t.userId}`
40
+ * );
41
+ *
42
+ * const result = RouteSchema.validate('/orders/42/550e8400-...');
43
+ * // result.object === { id: 42, userId: '550e8400-...' }
44
+ * ```
45
+ *
46
+ * @see {@link parseString}
47
+ */
48
+ export declare class ParseStringSchemaBuilder<TResult = any, TRequired extends boolean = true, TNullable extends boolean = false, THasDefault extends boolean = false, TExtensions = {}> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
49
+ #private;
50
+ /**
51
+ * @hidden
52
+ */
53
+ static create(props: ParseStringSchemaBuilderCreateProps): ParseStringSchemaBuilder<any, true, false, false, {}>;
54
+ protected constructor(props: ParseStringSchemaBuilderCreateProps);
55
+ /**
56
+ * Return a snapshot of this builder's configuration.
57
+ *
58
+ * Includes all base-class fields plus:
59
+ * - `objectSchema` — the object schema defining the result shape.
60
+ * - `templateDefinition` — the parsed template (literals and selector segments).
61
+ */
62
+ introspect(): {
63
+ /** The object schema defining the result shape. */
64
+ objectSchema: ObjectSchemaBuilder<any, any, any, any, any, any, any>;
65
+ /** The template definition (literals + segments). */
66
+ templateDefinition: ParseStringTemplateDefinition;
67
+ type: string;
68
+ isRequired: boolean;
69
+ isNullable: boolean;
70
+ isReadonly: boolean;
71
+ preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TResult>[];
72
+ validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TResult>[];
73
+ requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
74
+ extensions: {
75
+ [x: string]: unknown;
76
+ };
77
+ hasDefault: boolean;
78
+ defaultValue: TResult | (() => TResult) | undefined;
79
+ description: string | undefined;
80
+ schemaName: string | undefined;
81
+ hasCatch: boolean;
82
+ catchValue: TResult | (() => TResult) | undefined;
83
+ example: unknown;
84
+ };
85
+ /**
86
+ * Builds a string from the template by substituting parameter values.
87
+ *
88
+ * This is the reverse of {@link validate}: where `validate` parses a
89
+ * string into a typed object, `serialize` takes a params object and
90
+ * produces the string.
91
+ *
92
+ * @param params - An object matching the template's parsed result type.
93
+ * Nested properties are resolved via dot-paths (e.g. `order.id`).
94
+ * Values are coerced to strings via `String()`.
95
+ * @returns The reconstructed string with all segments replaced.
96
+ * @throws {Error} If a required parameter is missing (`undefined`).
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const Route = parseString(
101
+ * object({ id: number().coerce() }),
102
+ * $t => $t`/todos/${t => t.id}`
103
+ * );
104
+ *
105
+ * Route.serialize({ id: 42 }); // '/todos/42'
106
+ * ```
107
+ */
108
+ serialize(params: TResult): string;
109
+ /** {@inheritDoc SchemaBuilder.validate} */
110
+ validate(object: string, context?: ValidationContext): ValidationResult<TResult>;
111
+ /** {@inheritDoc SchemaBuilder.validateAsync} */
112
+ validateAsync(object: string, context?: ValidationContext): Promise<ValidationResult<TResult>>;
113
+ protected _validate(object: any, context?: ValidationContext): ValidationResult<TResult>;
114
+ protected _validateAsync(object: any, context?: ValidationContext): Promise<ValidationResult<TResult>>;
115
+ /**
116
+ * @inheritdoc
117
+ */
118
+ hasType<T>(_notUsed?: T): ParseStringSchemaBuilder<T, true, TNullable, THasDefault, TExtensions> & TExtensions;
119
+ /**
120
+ * @inheritdoc
121
+ */
122
+ clearHasType(): ParseStringSchemaBuilder<any, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
123
+ /**
124
+ * @hidden
125
+ */
126
+ nullable(): ParseStringSchemaBuilder<TResult, TRequired, true, THasDefault, TExtensions> & TExtensions;
127
+ /**
128
+ * @hidden
129
+ */
130
+ notNullable(): ParseStringSchemaBuilder<TResult, TRequired, false, THasDefault, TExtensions> & TExtensions;
131
+ /**
132
+ * @hidden
133
+ */
134
+ required(errorMessage?: ValidationErrorMessageProvider): ParseStringSchemaBuilder<TResult, true, TNullable, THasDefault, TExtensions> & TExtensions;
135
+ /**
136
+ * @hidden
137
+ */
138
+ optional(): ParseStringSchemaBuilder<TResult, false, TNullable, THasDefault, TExtensions> & TExtensions;
139
+ /**
140
+ * @hidden
141
+ */
142
+ default(value: TResult | (() => TResult)): ParseStringSchemaBuilder<TResult, true, TNullable, true, TExtensions> & TExtensions;
143
+ /**
144
+ * @hidden
145
+ */
146
+ clearDefault(): ParseStringSchemaBuilder<TResult, TRequired, TNullable, false, TExtensions> & TExtensions;
147
+ /**
148
+ * @hidden
149
+ */
150
+ brand<TBrand extends string | symbol>(_name?: TBrand): ParseStringSchemaBuilder<TResult & {
151
+ readonly [K in BRAND]: TBrand;
152
+ }, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
153
+ /**
154
+ * @hidden
155
+ */
156
+ readonly(): ParseStringSchemaBuilder<Readonly<TResult>, TRequired, TNullable, THasDefault, TExtensions> & TExtensions;
157
+ protected createFromProps<T, TReq extends boolean>(props: ParseStringSchemaBuilderCreateProps<T, TReq>): this;
158
+ }
159
+ /**
160
+ * Creates a parse-string schema that validates a string against a
161
+ * template pattern and parses it into a strongly-typed object.
162
+ *
163
+ * The first argument defines the result shape via `object(...)`, and the
164
+ * second argument is a callback receiving a typed `$template` tagged-template
165
+ * function whose template expressions are type-safe property selectors.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * const RouteSchema = parseString(
170
+ * object({
171
+ * userId: string().uuid(),
172
+ * id: number()
173
+ * }),
174
+ * $t => $t`/orders/${t => t.id}/${t => t.userId}`
175
+ * );
176
+ *
177
+ * const result = RouteSchema.validate('/orders/42/550e8400-e29b-41d4-a716-446655440000');
178
+ * // result.valid === true
179
+ * // result.object === { id: 42, userId: '550e8400-e29b-41d4-a716-446655440000' }
180
+ *
181
+ * type Route = InferType<typeof RouteSchema>;
182
+ * // { id: number; userId: string }
183
+ * ```
184
+ *
185
+ * @example Nested objects
186
+ * ```ts
187
+ * const schema = parseString(
188
+ * object({
189
+ * order: object({ id: number() }),
190
+ * user: object({ name: string() })
191
+ * }),
192
+ * $t => $t`/orders/${t => t.order.id}/by/${t => t.user.name}`
193
+ * );
194
+ * ```
195
+ *
196
+ * @param objectSchema - An `ObjectSchemaBuilder` defining the result type and
197
+ * per-property validation schemas.
198
+ * @param templateBuilder - Callback receiving the typed `$template`
199
+ * tagged-template function. Must return the result of invoking `$template`.
200
+ * @returns A `ParseStringSchemaBuilder` whose `validate()` accepts a
201
+ * string and whose `InferType` is the object schema's inferred type.
202
+ */
203
+ export declare function parseString<TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>>(objectSchema: TSchema, templateBuilder: ($template: ParseStringTemplateTag<TSchema>) => ParseStringTemplateDefinition): ParseStringSchemaBuilder<InferType<TSchema>>;
204
+ export {};
@@ -0,0 +1,2 @@
1
+ import{a,b}from"../chunk-DY7J6RNN.js";import"../chunk-K6Z47OQY.js";import"../chunk-3JMDGYDT.js";export{a as ParseStringSchemaBuilder,b as parseString};
2
+ //# sourceMappingURL=ParseStringSchemaBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,213 @@
1
+ import { type BRAND, type InferType, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
2
+ type PromiseSchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnType<PromiseSchemaBuilder<R>['introspect']>>;
3
+ /**
4
+ * Schema builder for promise-like values. Validates that a value is a
5
+ * thenable (for example, an actual `Promise` or any object with a `then`
6
+ * function) and optionally carries a typed resolved-value schema so that
7
+ * the inferred TypeScript type is `Promise<T>` instead of `Promise<any>`.
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 promise | promise()} function instead.
12
+ *
13
+ * @example Basic validation
14
+ * ```ts
15
+ * const schema = promise();
16
+ * const result = schema.validate(Promise.resolve(42));
17
+ * // result.valid === true
18
+ * ```
19
+ *
20
+ * @example Optional promise schema
21
+ * ```ts
22
+ * const schema = promise().optional();
23
+ * const result = schema.validate(undefined);
24
+ * // result.valid === true
25
+ * // result.object === undefined
26
+ * ```
27
+ *
28
+ * @example Typed resolved value
29
+ * ```ts
30
+ * import { promise, string, InferType } from '@cleverbrush/schema';
31
+ *
32
+ * const schema = promise(string());
33
+ *
34
+ * type PromiseResult = InferType<typeof schema>;
35
+ * // → Promise<string>
36
+ *
37
+ * // Introspect at runtime
38
+ * const info = schema.introspect();
39
+ * // info.resolvedType → StringSchemaBuilder
40
+ * ```
41
+ *
42
+ * @see {@link promise}
43
+ */
44
+ export declare class PromiseSchemaBuilder<TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResolvedTypeSchema extends SchemaBuilder<any, any, any, any, any> | undefined = undefined, TResult = TExplicitType extends undefined ? TResolvedTypeSchema extends SchemaBuilder<any, any, any, any, any> ? Promise<InferType<TResolvedTypeSchema>> : Promise<any> : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
45
+ #private;
46
+ /**
47
+ * @hidden
48
+ */
49
+ static create(props: PromiseSchemaBuilderCreateProps<any>): PromiseSchemaBuilder<true, false, undefined, false, {}, undefined, Promise<any>>;
50
+ protected constructor(props: PromiseSchemaBuilderCreateProps<TRequired>);
51
+ /**
52
+ * @hidden
53
+ */
54
+ hasType<T>(_notUsed?: T): PromiseSchemaBuilder<true, TNullable, T, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
55
+ /**
56
+ * @hidden
57
+ */
58
+ clearHasType(): PromiseSchemaBuilder<TRequired, TNullable, undefined, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
59
+ /**
60
+ * Returns an object describing the current schema configuration.
61
+ *
62
+ * In addition to the base fields exposed by {@link SchemaBuilder.introspect},
63
+ * the following field is included:
64
+ *
65
+ * - `resolvedType` — the {@link SchemaBuilder} set via {@link hasResolvedType},
66
+ * or `undefined` when no resolved-type schema has been configured.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const schema = promise(string());
71
+ *
72
+ * const info = schema.introspect();
73
+ * // info.resolvedType instanceof StringSchemaBuilder
74
+ * ```
75
+ */
76
+ introspect(): {
77
+ /** Resolved-value schema set via {@link hasResolvedType}, or `undefined` if not set. */
78
+ resolvedType: SchemaBuilder<any, any, any, any, any> | undefined;
79
+ type: string;
80
+ isRequired: boolean;
81
+ isNullable: boolean;
82
+ isReadonly: boolean;
83
+ preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TResult>[];
84
+ validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TResult>[];
85
+ requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
86
+ extensions: {
87
+ [x: string]: unknown;
88
+ };
89
+ hasDefault: boolean;
90
+ defaultValue: TResult | (() => TResult) | undefined;
91
+ description: string | undefined;
92
+ schemaName: string | undefined;
93
+ hasCatch: boolean;
94
+ catchValue: TResult | (() => TResult) | undefined;
95
+ example: unknown;
96
+ };
97
+ /** {@inheritDoc SchemaBuilder.validate} */
98
+ validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
99
+ /** {@inheritDoc SchemaBuilder.validateAsync} */
100
+ validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
101
+ /**
102
+ * Performs synchronous validation of the schema over `object`.
103
+ * Throws if any preprocessor, validator, or error message provider returns a Promise.
104
+ * @param context Optional `ValidationContext` settings.
105
+ */
106
+ protected _validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
107
+ /**
108
+ * Performs async validation of the schema over `object`.
109
+ * Supports async preprocessors, validators, and error message providers.
110
+ * @param context Optional `ValidationContext` settings.
111
+ */
112
+ protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
113
+ protected createFromProps<TReq extends boolean>(props: PromiseSchemaBuilderCreateProps<TReq>): this;
114
+ /**
115
+ * @hidden
116
+ */
117
+ required(errorMessage?: ValidationErrorMessageProvider): PromiseSchemaBuilder<true, TNullable, TExplicitType, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
118
+ /**
119
+ * @hidden
120
+ */
121
+ optional(): PromiseSchemaBuilder<false, TNullable, TExplicitType, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
122
+ /**
123
+ * @hidden
124
+ */
125
+ default(value: TResult | (() => TResult)): PromiseSchemaBuilder<true, TNullable, TExplicitType, true, TExtensions, TResolvedTypeSchema> & TExtensions;
126
+ /**
127
+ * @hidden
128
+ */
129
+ clearDefault(): PromiseSchemaBuilder<TRequired, TNullable, TExplicitType, false, TExtensions, TResolvedTypeSchema> & TExtensions;
130
+ /**
131
+ * @hidden
132
+ */
133
+ brand<TBrand extends string | symbol>(_name?: TBrand): PromiseSchemaBuilder<TRequired, TNullable, TResult & {
134
+ readonly [K in BRAND]: TBrand;
135
+ }, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
136
+ /**
137
+ * Marks the inferred type as `Readonly<Promise<T>>`. Sets the
138
+ * `isReadonly` introspection flag for tooling consistency.
139
+ *
140
+ * @see {@link SchemaBuilder.readonly}
141
+ */
142
+ readonly(): PromiseSchemaBuilder<TRequired, TNullable, Readonly<TResult>, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
143
+ /**
144
+ * @hidden
145
+ */
146
+ nullable(): PromiseSchemaBuilder<TRequired, true, TExplicitType, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
147
+ /**
148
+ * @hidden
149
+ */
150
+ notNullable(): PromiseSchemaBuilder<TRequired, false, TExplicitType, THasDefault, TExtensions, TResolvedTypeSchema> & TExtensions;
151
+ /**
152
+ * Sets the schema for the resolved value of the `Promise`.
153
+ *
154
+ * The inferred TypeScript type becomes `Promise<T>` where `T` is the type
155
+ * produced by `schema`. The schema is accessible at runtime via
156
+ * `introspect().resolvedType`.
157
+ *
158
+ * @param schema - The schema describing the resolved value of the promise.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const schema = promise().hasResolvedType(string());
163
+ *
164
+ * type Resolved = InferType<typeof schema>;
165
+ * // → Promise<string>
166
+ *
167
+ * schema.introspect().resolvedType; // StringSchemaBuilder
168
+ * ```
169
+ */
170
+ hasResolvedType<TSchema extends SchemaBuilder<any, any, any, any, any>>(schema: TSchema): PromiseSchemaBuilder<TRequired, TNullable, TExplicitType, THasDefault, TExtensions, TSchema> & TExtensions;
171
+ }
172
+ /**
173
+ * Creates a `promise` schema that validates the value is a JavaScript `Promise`.
174
+ *
175
+ * The returned builder is immutable and fully chainable. Pass an optional
176
+ * schema to {@link promise} to annotate the type of the resolved value —
177
+ * the inferred TypeScript type becomes `Promise<T>`.
178
+ *
179
+ * Alternatively, call {@link PromiseSchemaBuilder.hasResolvedType} on the
180
+ * returned builder to set or replace the resolved-value schema at any point
181
+ * in the chain.
182
+ *
183
+ * @param resolvedTypeSchema - Optional schema describing the resolved value of
184
+ * the promise. When provided, `InferType<typeof schema>` becomes
185
+ * `Promise<InferType<typeof resolvedTypeSchema>>`.
186
+ *
187
+ * @returns A new {@link PromiseSchemaBuilder} with `isRequired` set to `true`.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * import { promise, string, number, InferType } from '@cleverbrush/schema';
192
+ *
193
+ * // Untyped — accepts any Promise
194
+ * const anyPromise = promise();
195
+ * type AnyPromise = InferType<typeof anyPromise>; // Promise<any>
196
+ *
197
+ * anyPromise.validate(Promise.resolve(42)); // { valid: true }
198
+ * anyPromise.validate('not a promise' as any); // { valid: false }
199
+ *
200
+ * // Typed resolved value
201
+ * const stringPromise = promise(string());
202
+ * type StringPromise = InferType<typeof stringPromise>; // Promise<string>
203
+ *
204
+ * // Optional promise
205
+ * const optPromise = promise(number()).optional();
206
+ * type OptPromise = InferType<typeof optPromise>; // Promise<number> | undefined
207
+ * ```
208
+ *
209
+ * @see {@link PromiseSchemaBuilder}
210
+ */
211
+ export declare function promise(): PromiseSchemaBuilder<true>;
212
+ export declare function promise<TSchema extends SchemaBuilder<any, any, any, any, any>>(resolvedTypeSchema: TSchema): PromiseSchemaBuilder<true, false, undefined, false, {}, TSchema>;
213
+ export {};
@@ -0,0 +1,2 @@
1
+ import{a,b}from"../chunk-WDMJBGBD.js";import"../chunk-3JMDGYDT.js";export{a as PromiseSchemaBuilder,b as promise};
2
+ //# sourceMappingURL=PromiseSchemaBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,68 @@
1
+ import { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';
2
+ import { type InferType, type NestedValidationResult, type PropertyDescriptorInner, type PropertyDescriptorTree } from './SchemaBuilder.js';
3
+ /**
4
+ * Mutable container for nested validation results associated with a specific
5
+ * property descriptor. Implements {@link NestedValidationResult} and tracks
6
+ * the seen value, accumulated error messages, and child results for
7
+ * nested object properties.
8
+ *
9
+ * Used internally by `ObjectSchemaBuilder` during validation to build up
10
+ * a tree of per-property validation results.
11
+ */
12
+ export declare class PropertyValidationResult<TSchema extends ObjectSchemaBuilder<any, any, any, any, any> = ObjectSchemaBuilder<any, any, any, any, any>, TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any> = ObjectSchemaBuilder<any, any, any, any, any>, TParentPropertyDescriptor = any> implements NestedValidationResult<TSchema, TRootSchema, TParentPropertyDescriptor> {
13
+ #private;
14
+ /**
15
+ * The value that was seen at the property location described by the descriptor.
16
+ * Retrieves the value from the root object using the property descriptor's `getValue` method.
17
+ * Returns `undefined` if the property is not found.
18
+ */
19
+ get seenValue(): InferType<TSchema> | undefined;
20
+ /**
21
+ * The list of validation error messages accumulated for this property.
22
+ */
23
+ get errors(): ReadonlyArray<string>;
24
+ /**
25
+ * Whether validation passed for this property and all of its children.
26
+ * Returns `true` only when there are no errors and no child errors.
27
+ */
28
+ get isValid(): boolean;
29
+ /**
30
+ * Returns the list of child `NestedValidationResult` instances
31
+ * representing validation results for nested properties.
32
+ */
33
+ getChildErrors(): ReadonlyArray<NestedValidationResult<any, any, any>>;
34
+ /**
35
+ * The inner property descriptor providing `getValue`, `setValue`, and `getSchema`
36
+ * operations for the property this error relates to.
37
+ */
38
+ get descriptor(): PropertyDescriptorInner<TRootSchema, TSchema, TParentPropertyDescriptor>;
39
+ /**
40
+ * Creates a new `PropertyValidationResult`.
41
+ *
42
+ * @param descriptor - the property descriptor tree node this error is associated with;
43
+ * must be a valid descriptor (checked via `ObjectSchemaBuilder.isValidPropertyDescriptor`)
44
+ * @param rootObjectValue - the root object being validated, used to resolve property values
45
+ * @param errors - optional initial list of error message strings
46
+ * @throws if `descriptor` is not a valid property descriptor
47
+ */
48
+ constructor(descriptor: PropertyDescriptorTree<TSchema, TRootSchema, any, TParentPropertyDescriptor>, rootObjectValue: InferType<TRootSchema> | undefined, errors?: string[]);
49
+ /**
50
+ * Appends a validation error message to this property's error list.
51
+ * @param error - the error message string to add
52
+ */
53
+ addError(error: string): void;
54
+ /**
55
+ * Appends a child `NestedValidationResult` for a nested property.
56
+ * @param childError - the child validation result to add
57
+ */
58
+ addChildError(childError: NestedValidationResult<any, any, any>): void;
59
+ /**
60
+ * Returns a JSON-serializable representation of this validation result.
61
+ * This ensures `JSON.stringify` includes `isValid` and `errors`,
62
+ * which are otherwise non-enumerable prototype getters.
63
+ */
64
+ toJSON(): {
65
+ isValid: boolean;
66
+ errors: ReadonlyArray<string>;
67
+ };
68
+ }