@cleverbrush/schema 3.1.0 → 4.1.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 (66) hide show
  1. package/README.md +35 -2
  2. package/dist/builders/AnySchemaBuilder.js +1 -1
  3. package/dist/builders/ArraySchemaBuilder.js +1 -1
  4. package/dist/builders/BooleanSchemaBuilder.js +1 -1
  5. package/dist/builders/DateSchemaBuilder.js +1 -1
  6. package/dist/builders/ExternSchemaBuilder.js +1 -1
  7. package/dist/builders/FunctionSchemaBuilder.js +1 -1
  8. package/dist/builders/IntersectionSchemaBuilder.d.ts +124 -0
  9. package/dist/builders/NumberSchemaBuilder.js +1 -1
  10. package/dist/builders/ObjectSchemaBuilder.js +1 -1
  11. package/dist/builders/ParseStringSchemaBuilder.d.ts +9 -0
  12. package/dist/builders/ParseStringSchemaBuilder.js +1 -1
  13. package/dist/builders/PromiseSchemaBuilder.js +1 -1
  14. package/dist/builders/RecordSchemaBuilder.js +1 -1
  15. package/dist/builders/SchemaBuilder.d.ts +13 -7
  16. package/dist/builders/StringSchemaBuilder.js +1 -1
  17. package/dist/builders/TupleSchemaBuilder.js +1 -1
  18. package/dist/builders/UnionSchemaBuilder.js +1 -1
  19. package/dist/chunk-54RHS4F4.js +2 -0
  20. package/dist/chunk-54RHS4F4.js.map +1 -0
  21. package/dist/{chunk-K6Z47OQY.js → chunk-6LSN7NXQ.js} +2 -2
  22. package/dist/{chunk-WQDYWDOE.js → chunk-C6YQOKWB.js} +2 -2
  23. package/dist/{chunk-BUEVZ3KA.js → chunk-ELPPAHNO.js} +2 -2
  24. package/dist/{chunk-QARCEYGO.js → chunk-G424M7GI.js} +2 -2
  25. package/dist/{chunk-WDMJBGBD.js → chunk-JUFZ7PLO.js} +2 -2
  26. package/dist/{chunk-ZC6YBKCP.js → chunk-K4ZLXLE2.js} +2 -2
  27. package/dist/{chunk-NUW3VXZV.js → chunk-KC45JEFL.js} +2 -2
  28. package/dist/{chunk-EIVZX4ZO.js → chunk-NF4CRFMN.js} +2 -2
  29. package/dist/{chunk-YQZHDMRF.js → chunk-ORV2G6ZL.js} +2 -2
  30. package/dist/{chunk-CFIJQ4GP.js → chunk-PQINUGZW.js} +2 -2
  31. package/dist/chunk-REYZ7G7J.js +2 -0
  32. package/dist/chunk-REYZ7G7J.js.map +1 -0
  33. package/dist/chunk-VSU5GILY.js +2 -0
  34. package/dist/chunk-VSU5GILY.js.map +1 -0
  35. package/dist/chunk-XHSBY2QK.js +2 -0
  36. package/dist/chunk-XHSBY2QK.js.map +1 -0
  37. package/dist/{chunk-ZFI27R3L.js → chunk-XL723XFL.js} +2 -2
  38. package/dist/{chunk-HN774HD7.js → chunk-XPLTW5DI.js} +2 -2
  39. package/dist/{chunk-PHE4LIAN.js → chunk-YAOZEA2R.js} +2 -2
  40. package/dist/core.d.ts +4 -2
  41. package/dist/core.js +1 -1
  42. package/dist/extension.d.ts +76 -4
  43. package/dist/extension.js +2 -0
  44. package/dist/extension.js.map +1 -0
  45. package/dist/index.js +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/package.json +6 -2
  48. package/dist/chunk-3JMDGYDT.js +0 -2
  49. package/dist/chunk-3JMDGYDT.js.map +0 -1
  50. package/dist/chunk-DY7J6RNN.js +0 -2
  51. package/dist/chunk-DY7J6RNN.js.map +0 -1
  52. package/dist/chunk-GXPV6UQK.js +0 -2
  53. package/dist/chunk-GXPV6UQK.js.map +0 -1
  54. /package/dist/{chunk-K6Z47OQY.js.map → chunk-6LSN7NXQ.js.map} +0 -0
  55. /package/dist/{chunk-WQDYWDOE.js.map → chunk-C6YQOKWB.js.map} +0 -0
  56. /package/dist/{chunk-BUEVZ3KA.js.map → chunk-ELPPAHNO.js.map} +0 -0
  57. /package/dist/{chunk-QARCEYGO.js.map → chunk-G424M7GI.js.map} +0 -0
  58. /package/dist/{chunk-WDMJBGBD.js.map → chunk-JUFZ7PLO.js.map} +0 -0
  59. /package/dist/{chunk-ZC6YBKCP.js.map → chunk-K4ZLXLE2.js.map} +0 -0
  60. /package/dist/{chunk-NUW3VXZV.js.map → chunk-KC45JEFL.js.map} +0 -0
  61. /package/dist/{chunk-EIVZX4ZO.js.map → chunk-NF4CRFMN.js.map} +0 -0
  62. /package/dist/{chunk-YQZHDMRF.js.map → chunk-ORV2G6ZL.js.map} +0 -0
  63. /package/dist/{chunk-CFIJQ4GP.js.map → chunk-PQINUGZW.js.map} +0 -0
  64. /package/dist/{chunk-ZFI27R3L.js.map → chunk-XL723XFL.js.map} +0 -0
  65. /package/dist/{chunk-HN774HD7.js.map → chunk-XPLTW5DI.js.map} +0 -0
  66. /package/dist/{chunk-PHE4LIAN.js.map → chunk-YAOZEA2R.js.map} +0 -0
package/README.md CHANGED
@@ -3,11 +3,11 @@
3
3
  [![CI](https://github.com/cleverbrush/framework/actions/workflows/ci.yml/badge.svg)](https://github.com/cleverbrush/framework/actions/workflows/ci.yml)
4
4
  [![Standard Schema v1](https://img.shields.io/badge/Standard%20Schema-v1-blue)](https://standardschema.dev/)
5
5
  <!-- bundle-badge-start -->
6
- [![Bundle size](https://img.shields.io/badge/bundle-19.9%20KB%20gzip-green)](https://github.com/cleverbrush/framework/blob/master/libs/schema)
6
+ [![Bundle size](https://img.shields.io/badge/bundle-20.2%20KB%20gzip-green)](https://github.com/cleverbrush/framework/blob/master/libs/schema)
7
7
  <!-- bundle-badge-end -->
8
8
  [![License: BSD-3-Clause](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](../../LICENSE)
9
9
  <!-- coverage-badge-start -->
10
- ![Coverage](https://img.shields.io/badge/coverage-96.8%25-brightgreen)
10
+ ![Coverage](https://img.shields.io/badge/coverage-98%25-brightgreen)
11
11
  <!-- coverage-badge-end -->
12
12
 
13
13
  A schema definition and validation library for TypeScript — faster than Zod in 14/15 benchmarks (up to 204× faster on invalid input), 3× smaller than Zod v4, and compatible with 50+ ecosystem tools via [Standard Schema v1](https://standardschema.dev/).
@@ -137,6 +137,7 @@ The following builder functions are available:
137
137
  | `tuple([...schemas])` | Fixed-length array with per-position types. Each index validated against its own schema — mirrors TypeScript tuple types. | `.rest(schema)`, `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)` |
138
138
  | `record(keySchema, valSchema)` | Object with dynamic string keys. Every key must satisfy `keySchema` (a string schema) and every value must satisfy `valSchema` — mirrors TypeScript's `Record<K, V>`. | `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)`, `.addValidator(fn)` |
139
139
  | `union(schema)` | Union of schemas — e.g. `string \| number`. | `.or(schema)`, `.validate(data)`, `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)` |
140
+ | `intersection(left, right)` | Intersection of two schemas — both must pass. Merges validated outputs. Use `.acceptUnknownProps()` on object schemas. | `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)`, `.addValidator(fn)` |
140
141
  | `enumOf(...values)` | String enum — sugar for `string().oneOf(...)`. | `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)` |
141
142
  | `lazy(getter)` | Recursive/self-referential schema. The getter is called once and its result is cached. Enables tree structures, linked lists, and other recursive types. | `.resolve()`, `.optional()`, `.addValidator(fn)`, `.default(value)` |
142
143
  | `generic(fn)` | Parameterized schema template. Call `.apply(...schemas)` with concrete schemas to obtain a fully typed concrete schema builder. TypeScript infers the result type from the template function's own generic signature. Optionally pass a `defaults` array as the first argument to enable direct validation without calling `.apply()`. | `.apply(...schemas)`, `.optional()`, `.nullable()`, `.default(value)` |
@@ -199,6 +200,16 @@ const TeamSchema = object({
199
200
  const IdOrEmail = union(string().minLength(1)).or(
200
201
  string().matches(/^[^@]+@[^@]+$/)
201
202
  );
203
+
204
+ // Intersection types — combine two schemas into one (both must pass)
205
+ import { intersection } from '@cleverbrush/schema';
206
+
207
+ const NameAndAge = intersection(
208
+ object({ name: string() }).acceptUnknownProps(),
209
+ object({ age: number() }).acceptUnknownProps()
210
+ );
211
+ const person = NameAndAge.parse({ name: 'Alice', age: 30 });
212
+ // typeof person === { name: string } & { age: number }
202
213
  ```
203
214
 
204
215
  ## Generic Schemas
@@ -541,6 +552,18 @@ const result = RouteSchema.validate('/orders/abc/bad-uuid');
541
552
  // result.errors[0].message → "id: expected an integer number"
542
553
  ```
543
554
 
555
+ **Raw template access** — the original `{Property}` pattern is exposed via the `.template` getter. This enables consumers to use a parse-string schema as a Serilog-style message template (used by `@cleverbrush/log` for typed log events):
556
+
557
+ ```typescript
558
+ const TodoCreated = parseString(
559
+ object({ TodoId: number(), Title: string(), UserId: string() }),
560
+ $t => $t`Todo #${t => t.TodoId} "${t => t.Title}" created by ${t => t.UserId}`
561
+ );
562
+
563
+ TodoCreated.template;
564
+ // → 'Todo #{TodoId} "{Title}" created by {UserId}'
565
+ ```
566
+
544
567
  ## Coercion
545
568
 
546
569
  The `number()`, `boolean()`, and `date()` builders each have a `.coerce()` method that adds a preprocessor to convert string values to the target type. This is especially useful with parse-string schemas where captured segments are always strings, but also works standalone for URL parameters, form inputs, or any other string source.
@@ -1754,6 +1777,16 @@ const UserSchema = object({
1754
1777
  const standardSchema = UserSchema['~standard'];
1755
1778
  ```
1756
1779
 
1780
+ The `['~standard'].validate()` method returns a `Promise`, supporting both sync
1781
+ and async preprocessors, validators, and error message providers:
1782
+
1783
+ ```ts
1784
+ const result = await UserSchema['~standard'].validate(input);
1785
+ if ('issues' in result) {
1786
+ console.error(result.issues[0].message);
1787
+ }
1788
+ ```
1789
+
1757
1790
  Confirmed integrations: **tRPC**, **TanStack Form**, **React Hook Form**, **T3 Env**, **Hono**, **Elysia**, **next-safe-action**, and 50+ others listed on [standardschema.dev](https://standardschema.dev/).
1758
1791
 
1759
1792
  ## Code Quality
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-HN774HD7.js";import"../chunk-3JMDGYDT.js";export{a as AnySchemaBuilder,b as any};
1
+ import{a,b}from"../chunk-XPLTW5DI.js";import"../chunk-REYZ7G7J.js";export{a as AnySchemaBuilder,b as any};
2
2
  //# sourceMappingURL=AnySchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-NUW3VXZV.js";import"../chunk-3JMDGYDT.js";export{a as ArraySchemaBuilder,b as array};
1
+ import{a,b}from"../chunk-KC45JEFL.js";import"../chunk-REYZ7G7J.js";export{a as ArraySchemaBuilder,b as array};
2
2
  //# sourceMappingURL=ArraySchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-CFIJQ4GP.js";import"../chunk-3JMDGYDT.js";export{a as BooleanSchemaBuilder,b as boolean};
1
+ import{a,b}from"../chunk-PQINUGZW.js";import"../chunk-REYZ7G7J.js";export{a as BooleanSchemaBuilder,b as boolean};
2
2
  //# sourceMappingURL=BooleanSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-EIVZX4ZO.js";import"../chunk-3JMDGYDT.js";export{a as DateSchemaBuilder,b as date};
1
+ import{a,b}from"../chunk-NF4CRFMN.js";import"../chunk-REYZ7G7J.js";export{a as DateSchemaBuilder,b as date};
2
2
  //# sourceMappingURL=DateSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-PHE4LIAN.js";import"../chunk-3JMDGYDT.js";export{a as ExternSchemaBuilder,b as extern};
1
+ import{a,b}from"../chunk-YAOZEA2R.js";import"../chunk-REYZ7G7J.js";export{a as ExternSchemaBuilder,b as extern};
2
2
  //# sourceMappingURL=ExternSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-ZC6YBKCP.js";import"../chunk-3JMDGYDT.js";export{a as FunctionSchemaBuilder,b as func};
1
+ import{a,b}from"../chunk-K4ZLXLE2.js";import"../chunk-REYZ7G7J.js";export{a as FunctionSchemaBuilder,b as func};
2
2
  //# sourceMappingURL=FunctionSchemaBuilder.js.map
@@ -0,0 +1,124 @@
1
+ import { type BRAND, type InferType, SchemaBuilder, type ValidationContext, type ValidationResult } from './SchemaBuilder.js';
2
+ type IntersectionSchemaBuilderCreateProps<TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>, R extends boolean = true> = Partial<ReturnType<IntersectionSchemaBuilder<TLeft, TRight, R>['introspect']>>;
3
+ type SchemaIntersection<TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>> = InferType<TLeft> & InferType<TRight>;
4
+ export type IntersectionSchemaValidationResult<T> = ValidationResult<T>;
5
+ export declare class IntersectionSchemaBuilder<TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}> extends SchemaBuilder<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, TRequired, TNullable, THasDefault, TExtensions> {
6
+ #private;
7
+ /**
8
+ * @hidden
9
+ */
10
+ static create(props: IntersectionSchemaBuilderCreateProps<any, any>): IntersectionSchemaBuilder<any, any, true, false, undefined, false, {}>;
11
+ protected constructor(props: IntersectionSchemaBuilderCreateProps<TLeft, TRight, TRequired>);
12
+ introspect(): {
13
+ left: TLeft;
14
+ right: TRight;
15
+ type: string;
16
+ isRequired: boolean;
17
+ isNullable: boolean;
18
+ isReadonly: boolean;
19
+ preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>[];
20
+ validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>[];
21
+ requiredValidationErrorMessageProvider: import("./SchemaBuilder.js").ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
22
+ extensions: {
23
+ [x: string]: unknown;
24
+ };
25
+ hasDefault: boolean;
26
+ defaultValue: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | undefined;
27
+ description: string | undefined;
28
+ schemaName: string | undefined;
29
+ hasCatch: boolean;
30
+ catchValue: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | undefined;
31
+ example: unknown;
32
+ };
33
+ /**
34
+ * @override
35
+ */
36
+ protected get isNullRequiredViolation(): boolean;
37
+ /**
38
+ * @inheritdoc
39
+ */
40
+ hasType<T>(_notUsed?: T): IntersectionSchemaBuilder<TLeft, TRight, true, TNullable, T, THasDefault, TExtensions> & TExtensions;
41
+ /**
42
+ * @inheritdoc
43
+ */
44
+ clearHasType(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
45
+ /**
46
+ * @inheritdoc
47
+ */
48
+ validate(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>;
49
+ /**
50
+ * @inheritdoc
51
+ */
52
+ validateAsync(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): Promise<IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>>;
53
+ /**
54
+ * Performs synchronous validation.
55
+ * Validates left schema first, then right schema.
56
+ * Both must pass for the intersection to be valid.
57
+ */
58
+ protected _validate(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>;
59
+ /**
60
+ * Performs async validation.
61
+ */
62
+ protected _validateAsync(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): Promise<IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>>;
63
+ protected createFromProps<TL extends SchemaBuilder<any, any, any, any, any>, TR extends SchemaBuilder<any, any, any, any, any>, TReq extends boolean>(props: IntersectionSchemaBuilderCreateProps<TL, TR, TReq>): this;
64
+ /**
65
+ * @hidden
66
+ */
67
+ required(errorMessage?: any): IntersectionSchemaBuilder<TLeft, TRight, true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
68
+ /**
69
+ * @hidden
70
+ */
71
+ optional(): IntersectionSchemaBuilder<TLeft, TRight, false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
72
+ /**
73
+ * @hidden
74
+ */
75
+ default(value: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType)): IntersectionSchemaBuilder<TLeft, TRight, true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
76
+ /**
77
+ * @hidden
78
+ */
79
+ clearDefault(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
80
+ /**
81
+ * @hidden
82
+ */
83
+ brand<TBrand extends string | symbol>(_name?: TBrand): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) & {
84
+ readonly [K in BRAND]: TBrand;
85
+ }, THasDefault, TExtensions> & TExtensions;
86
+ /**
87
+ * @hidden
88
+ */
89
+ readonly(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, Readonly<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>, THasDefault, TExtensions> & TExtensions;
90
+ /**
91
+ * @hidden
92
+ */
93
+ nullable(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, true, TExplicitType, THasDefault, TExtensions> & TExtensions;
94
+ /**
95
+ * @hidden
96
+ */
97
+ notNullable(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, false, TExplicitType, THasDefault, TExtensions> & TExtensions;
98
+ /**
99
+ * Gets the left side of this intersection.
100
+ */
101
+ get leftSchema(): TLeft;
102
+ /**
103
+ * Gets the right side of this intersection.
104
+ */
105
+ get rightSchema(): TRight;
106
+ }
107
+ /**
108
+ * Creates an intersection schema.
109
+ * The resulting schema validates that the input satisfies both `left` and `right` schemas.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const schema = intersection(
114
+ * object({ name: string() }),
115
+ * object({ age: number() })
116
+ * );
117
+ * // InferType<typeof schema> === { name: string } & { age: number }
118
+ * ```
119
+ *
120
+ * @param left - first schema
121
+ * @param right - second schema
122
+ */
123
+ export declare const intersection: <TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>>(left: TLeft, right: TRight) => IntersectionSchemaBuilder<TLeft, TRight>;
124
+ export {};
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-BUEVZ3KA.js";import"../chunk-3JMDGYDT.js";export{a as NumberSchemaBuilder,b as number};
1
+ import{a,b}from"../chunk-ELPPAHNO.js";import"../chunk-REYZ7G7J.js";export{a as NumberSchemaBuilder,b as number};
2
2
  //# sourceMappingURL=NumberSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-K6Z47OQY.js";import"../chunk-3JMDGYDT.js";export{a as ObjectSchemaBuilder,b as object};
1
+ import{a,b}from"../chunk-6LSN7NXQ.js";import"../chunk-REYZ7G7J.js";export{a as ObjectSchemaBuilder,b as object};
2
2
  //# sourceMappingURL=ObjectSchemaBuilder.js.map
@@ -52,6 +52,15 @@ export declare class ParseStringSchemaBuilder<TResult = any, TRequired extends b
52
52
  */
53
53
  static create(props: ParseStringSchemaBuilderCreateProps): ParseStringSchemaBuilder<any, true, false, false, {}>;
54
54
  protected constructor(props: ParseStringSchemaBuilderCreateProps);
55
+ /**
56
+ * The human-readable message template pattern with `{property}` holes,
57
+ * e.g. `"Todo created: #{TodoId} \"{Title}\" by user {UserId}"`.
58
+ *
59
+ * Useful for structured logging — pass this as the log `messageTemplate`
60
+ * so events with the same shape can be grouped, and pass
61
+ * `serialize(params)` as the rendered message.
62
+ */
63
+ get template(): string;
55
64
  /**
56
65
  * Return a snapshot of this builder's configuration.
57
66
  *
@@ -1,2 +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};
1
+ import{a,b}from"../chunk-XHSBY2QK.js";import"../chunk-6LSN7NXQ.js";import"../chunk-REYZ7G7J.js";export{a as ParseStringSchemaBuilder,b as parseString};
2
2
  //# sourceMappingURL=ParseStringSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-WDMJBGBD.js";import"../chunk-3JMDGYDT.js";export{a as PromiseSchemaBuilder,b as promise};
1
+ import{a,b}from"../chunk-JUFZ7PLO.js";import"../chunk-REYZ7G7J.js";export{a as PromiseSchemaBuilder,b as promise};
2
2
  //# sourceMappingURL=PromiseSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-ZFI27R3L.js";import"../chunk-3JMDGYDT.js";export{a as RecordSchemaBuilder,b as record};
1
+ import{a,b}from"../chunk-XL723XFL.js";import"../chunk-REYZ7G7J.js";export{a as RecordSchemaBuilder,b as record};
2
2
  //# sourceMappingURL=RecordSchemaBuilder.js.map
@@ -317,8 +317,8 @@ export type PropertySetterOptions = {
317
317
  * Extracts the inner property descriptor type from a `PropertyDescriptor`.
318
318
  * Returns `undefined` if `T` is not a valid `PropertyDescriptor`.
319
319
  */
320
- export type PropertyDescriptorInnerFromPropertyDescriptor<T> = T extends PropertyDescriptor<infer TSchema, infer TPropertySchema, infer TParentPropertyDescriptor> ? PropertyDescriptorInner<TSchema, TPropertySchema, TParentPropertyDescriptor> : undefined;
321
- export type PropertyDescriptorInner<TSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TPropertySchema, TParentPropertyDescriptor> = {
320
+ export type PropertyDescriptorInnerFromPropertyDescriptor<T> = T extends PropertyDescriptor<infer TSchema, infer TPropertySchema, infer TParentPropertyDescriptor, infer TPropertyKey extends string> ? PropertyDescriptorInner<TSchema, TPropertySchema, TParentPropertyDescriptor, TPropertyKey> : undefined;
321
+ export type PropertyDescriptorInner<TSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TPropertySchema, TParentPropertyDescriptor, TPropertyKey extends string = string> = {
322
322
  /**
323
323
  * Sets a new value to the property. If the process was successful,
324
324
  * the method returns `true`, otherwise `false`.
@@ -374,8 +374,14 @@ export type PropertyDescriptorInner<TSchema extends ObjectSchemaBuilder<any, any
374
374
  /**
375
375
  * The name of this property within its parent object, or `undefined`
376
376
  * for the root descriptor.
377
+ *
378
+ * When the property was created from a `PropertyDescriptorTree` leaf the
379
+ * type narrows to the literal key string (e.g. `'id'`), enabling
380
+ * accessor-function-based column inference in query builders.
381
+ *
382
+ * @typeParam TPropertyKey - The literal property name, or `string` for root/unknown descriptors.
377
383
  */
378
- propertyName: string | undefined;
384
+ propertyName: TPropertyKey | undefined;
379
385
  /**
380
386
  * Returns a JSON Pointer (RFC 6901) string representing this
381
387
  * property's path from the root descriptor.
@@ -390,15 +396,15 @@ export type PropertyDescriptorInner<TSchema extends ObjectSchemaBuilder<any, any
390
396
  * holds a {@link PropertyDescriptorInner} for a particular property within
391
397
  * an object schema. Used to get/set property values on validated objects.
392
398
  */
393
- export type PropertyDescriptor<TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TPropertySchema, TParentPropertyDescriptor> = {
394
- [SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]: PropertyDescriptorInner<TRootSchema, TPropertySchema, TParentPropertyDescriptor>;
399
+ export type PropertyDescriptor<TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TPropertySchema, TParentPropertyDescriptor, TPropertyKey extends string = string> = {
400
+ [SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]: PropertyDescriptorInner<TRootSchema, TPropertySchema, TParentPropertyDescriptor, TPropertyKey>;
395
401
  };
396
402
  /**
397
403
  * A tree of property descriptors for the schema.
398
404
  * Has a possibility to filter properties by the type (`TAssignableTo` type parameter).
399
405
  */
400
406
  export type PropertyDescriptorTree<TSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any> = TSchema, TAssignableTo = any, TParentPropertyDescriptor = undefined> = PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor> & (TSchema extends ObjectSchemaBuilder<infer TProperties, any, any> ? {
401
- [K in keyof TProperties]: TProperties[K] extends ObjectSchemaBuilder<any, any, any> ? PropertyDescriptorTree<TProperties[K], TRootSchema, any, PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : TProperties[K] extends ExternSchemaBuilder<any, any, any, any, any, any, infer TExternResult> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> & ExternOutputPropertyDescriptors<TExternResult, TRootSchema, PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>>> : TProperties[K] extends ArraySchemaBuilder<infer TArrayElement, any, any> ? TArrayElement extends ObjectSchemaBuilder<any, any, any, any, any> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : never : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : never;
407
+ [K in keyof TProperties]: TProperties[K] extends ObjectSchemaBuilder<any, any, any> ? PropertyDescriptorTree<TProperties[K], TRootSchema, any, PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>> : TProperties[K] extends ExternSchemaBuilder<any, any, any, any, any, any, infer TExternResult> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> & ExternOutputPropertyDescriptors<TExternResult, TRootSchema, PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string>> : TProperties[K] extends ArraySchemaBuilder<infer TArrayElement, any, any> ? TArrayElement extends ObjectSchemaBuilder<any, any, any, any, any> ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : never : InferType<TProperties[K]> extends TAssignableTo ? PropertyDescriptor<TRootSchema, TProperties[K], PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor>, K & string> : never;
402
408
  } : never);
403
409
  /**
404
410
  * Recursively maps the keys of an extern schema's output type into
@@ -409,7 +415,7 @@ export type PropertyDescriptorTree<TSchema extends ObjectSchemaBuilder<any, any,
409
415
  * @internal
410
416
  */
411
417
  type ExternOutputPropertyDescriptors<TOutput, TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>, TParentPropertyDescriptor> = TOutput extends Date | Function | readonly any[] | string | number | boolean | symbol | bigint | null | undefined ? {} : TOutput extends Record<string, any> ? {
412
- [K in keyof TOutput]: PropertyDescriptor<TRootSchema, SchemaBuilder<TOutput[K], true, false, false, {}>, TParentPropertyDescriptor> & ExternOutputPropertyDescriptors<TOutput[K], TRootSchema, PropertyDescriptor<TRootSchema, SchemaBuilder<TOutput[K], true, false, false, {}>, TParentPropertyDescriptor>>;
418
+ [K in keyof TOutput]: PropertyDescriptor<TRootSchema, SchemaBuilder<TOutput[K], true, false, false, {}>, TParentPropertyDescriptor, K & string> & ExternOutputPropertyDescriptors<TOutput[K], TRootSchema, PropertyDescriptor<TRootSchema, SchemaBuilder<TOutput[K], true, false, false, {}>, TParentPropertyDescriptor, K & string>>;
413
419
  } : {};
414
420
  /**
415
421
  * Creates an array augmented with non-enumerable NestedValidationResult
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-YQZHDMRF.js";import"../chunk-3JMDGYDT.js";export{a as StringSchemaBuilder,b as string};
1
+ import{a,b}from"../chunk-ORV2G6ZL.js";import"../chunk-REYZ7G7J.js";export{a as StringSchemaBuilder,b as string};
2
2
  //# sourceMappingURL=StringSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-QARCEYGO.js";import"../chunk-3JMDGYDT.js";export{a as TupleSchemaBuilder,b as tuple};
1
+ import{a,b}from"../chunk-G424M7GI.js";import"../chunk-REYZ7G7J.js";export{a as TupleSchemaBuilder,b as tuple};
2
2
  //# sourceMappingURL=TupleSchemaBuilder.js.map
@@ -1,2 +1,2 @@
1
- import{a,b}from"../chunk-WQDYWDOE.js";import"../chunk-3JMDGYDT.js";export{a as UnionSchemaBuilder,b as union};
1
+ import{a,b}from"../chunk-C6YQOKWB.js";import"../chunk-REYZ7G7J.js";export{a as UnionSchemaBuilder,b as union};
2
2
  //# sourceMappingURL=UnionSchemaBuilder.js.map
@@ -0,0 +1,2 @@
1
+ import{a as P,b as w}from"./chunk-C6YQOKWB.js";import{a as B,b as R}from"./chunk-K4ZLXLE2.js";import{a as S,b}from"./chunk-ELPPAHNO.js";import{a as g,b as F}from"./chunk-6LSN7NXQ.js";import{a as M,b as A}from"./chunk-JUFZ7PLO.js";import{a as N,b as D}from"./chunk-XL723XFL.js";import{a as _,b as v}from"./chunk-ORV2G6ZL.js";import{a as V,b as C}from"./chunk-G424M7GI.js";import{a as c,b as T}from"./chunk-XPLTW5DI.js";import{a as x,b as p}from"./chunk-KC45JEFL.js";import{a as m,b as E}from"./chunk-PQINUGZW.js";import{a as h,b as f}from"./chunk-NF4CRFMN.js";import{f as u}from"./chunk-REYZ7G7J.js";var d=class o extends u{#e;#n;#t;static create(e){return new o({type:"generic",...e})}constructor(e){super(e),this.#e=e.templateFn,this.#n=e.defaults,this.apply=(...n)=>{if(!this.#e)throw new Error("GenericSchemaBuilder: no template function defined");return this.#e(...n)}}introspect(){return{...super.introspect(),templateFn:this.#e,defaults:this.#n}}#a(){if(!(!this.#e||!this.#n))return this.#t||(this.#t=this.#e(...this.#n)),this.#t}#r(e,n){let{valid:r,transaction:s,errors:i}=e;if(!r)return{valid:r,errors:i};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{valid:!0,object:a};let t=this.#a();return t?t.validate(a,n):{valid:!1,errors:[{message:"This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic()."}]}}async#s(e,n){let{valid:r,transaction:s,errors:i}=e;if(!r)return{valid:r,errors:i};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{valid:!0,object:a};let t=this.#a();return t?await t.validateAsync(a,n):{valid:!1,errors:[{message:"This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic()."}]}}validate(e,n){return super.validate(e,n)}async validateAsync(e,n){return super.validateAsync(e,n)}_validate(e,n){return this.#r(this.preValidateSync(e,n),n)}async _validateAsync(e,n){return this.#s(await super.preValidateAsync(e,n),n)}createFromProps(e){return o.create(e)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}required(e){return super.required(e)}optional(){return super.optional()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}};function j(o,e){let n=e!==void 0?e:o,r=e!==void 0?o:void 0;return d.create({isRequired:!0,templateFn:n,defaults:r})}var y={string:_,number:S,boolean:m,date:h,object:g,array:x,tuple:V,record:N,union:P,func:B,any:c,promise:M,generic:d},q={string:v,number:b,boolean:E,date:f,object:F,array:p,tuple:C,record:D,union:w,func:R,any:T,promise:A,generic:j},ee="__cleverbrush_method_literal_brand__";var ne="__cleverbrush_extra_type_brand__";var G=new Set(["validate","validateAsync","parse","parseAsync","safeParse","safeParseAsync","introspect","optional","required","addPreprocessor","clearPreprocessors","addValidator","clearValidators","hasType","clearHasType","createFromProps","preValidate","preValidateSync","preValidateAsync","getValidationErrorMessage","getValidationErrorMessageSync","assureValidationErrorMessageProvider","withExtension","getExtension"]);function te(o){let e={};for(let n of Object.keys(o)){if(!(n in y))throw new Error(`Unknown builder type "${n}". Valid types: ${Object.keys(y).join(", ")}`);let r=o[n];if(!r||typeof r!="object")throw new Error(`Extension config for "${n}" must be an object of methods`);e[n]={};for(let s of Object.keys(r)){if(G.has(s))throw new Error(`Cannot override reserved method "${s}" on "${n}"`);let i=r[s];if(typeof i!="function")throw new Error(`Extension method "${n}.${s}" must be a function`);e[n][s]=function(...a){let t=i.apply(this,a);return t&&typeof t=="object"&&typeof t.withExtension=="function"&&(typeof t.getExtension!="function"||t.getExtension(s)===void 0)?t.withExtension(s,a.length===1?a[0]:a.length===0?!0:a):t}}}return{config:e}}function ae(...o){let e=new Map;for(let r of o)for(let s of Object.keys(r.config)){e.has(s)||e.set(s,new Map);let i=e.get(s),a=r.config[s];for(let t of Object.keys(a)){if(i.has(t))throw new Error(`Extension method collision: "${t}" is defined by multiple extensions for "${s}"`);i.set(t,a[t])}}let n={};for(let r of Object.keys(y)){let s=e.get(r);if(!s||s.size===0){n[r]=q[r];continue}let i=y[r],a=class extends i{constructor(...t){super(...t)}static create(t){return new a({...t})}createFromProps(t){return a.create(t)}};for(let[t,l]of s)Object.defineProperty(a.prototype,t,{value:l,writable:!0,configurable:!0,enumerable:!1});n[r]=(...t)=>{let l=q[r](...t);return Object.setPrototypeOf(l,a.prototype),l}}return n}export{d as a,j as b,ee as c,ne as d,te as e,ae as f};
2
+ //# sourceMappingURL=chunk-54RHS4F4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/builders/GenericSchemaBuilder.ts","../src/extension.ts"],"sourcesContent":["import {\n type BRAND,\n SchemaBuilder,\n type ValidationContext,\n type ValidationErrorMessageProvider,\n type ValidationResult\n} from './SchemaBuilder.js';\n\ntype GenericSchemaBuilderCreateProps<TRequired extends boolean = true> =\n Partial<ReturnType<GenericSchemaBuilder<any, TRequired>['introspect']>>;\n\n/**\n * Schema builder that wraps a generic template function, enabling reusable\n * parameterized schemas. Call {@link GenericSchemaBuilder.apply | `.apply()`}\n * with concrete schema arguments to obtain a fully typed concrete schema\n * builder whose TypeScript type is inferred from the template function's\n * generic signature.\n *\n * **NOTE** this class is exported only to give opportunity to extend it\n * by inheriting. It is not recommended to create an instance of this class\n * directly. Use {@link generic | generic()} function instead.\n *\n * @example Single type parameter\n * ```ts\n * import { generic, object, array, number, string, InferType } from '@cleverbrush/schema';\n *\n * const PaginatedList = generic(\n * <T extends SchemaBuilder<any, any, any, any, any>>(itemSchema: T) =>\n * object({\n * items: array(itemSchema),\n * total: number(),\n * page: number(),\n * })\n * );\n *\n * const userSchema = object({ name: string(), age: number() });\n * const PaginatedUsers = PaginatedList.apply(userSchema);\n *\n * type PaginatedUsersType = InferType<typeof PaginatedUsers>;\n * // → { items: { name: string; age: number }[]; total: number; page: number }\n * ```\n *\n * @example Multiple type parameters\n * ```ts\n * const Result = generic(\n * <T extends SchemaBuilder<any, any, any, any, any>,\n * E extends SchemaBuilder<any, any, any, any, any>>(\n * valueSchema: T,\n * errorSchema: E\n * ) =>\n * object({\n * ok: boolean(),\n * value: valueSchema.optional(),\n * error: errorSchema.optional(),\n * })\n * );\n *\n * const StringResult = Result.apply(string(), number());\n * // InferType → { ok: boolean; value?: string; error?: number }\n * ```\n *\n * @example With default arguments (enables direct `.validate()` on the template)\n * ```ts\n * const AnyList = generic(\n * [any()], // default args — one per template parameter\n * <T extends SchemaBuilder<any, any, any, any, any>>(itemSchema: T) =>\n * object({ items: array(itemSchema), total: number() })\n * );\n *\n * // Validate directly using defaults:\n * AnyList.validate({ items: [1, 'two', true], total: 3 }); // valid\n *\n * // Or apply concrete schemas first:\n * AnyList.apply(string()).validate({ items: ['a', 'b'], total: 2 }); // valid\n * ```\n *\n * @see {@link generic}\n *\n * @typeParam TFn - The generic template function type. Its return type\n * determines `TResult` (the validated value type) when no explicit type\n * override has been applied via `.hasType<T>()`.\n * @typeParam TRequired - `true` when the schema is required (default),\n * `false` after calling `.optional()`. Governs whether `undefined` is a\n * valid value.\n * @typeParam TNullable - `true` after calling `.nullable()`. Governs whether\n * `null` is a valid value.\n * @typeParam TExplicitType - Type override set via `.hasType<T>()`. When\n * `undefined` (the default), `TResult` is derived from `TFn`'s return type.\n * @typeParam THasDefault - `true` after calling `.default(value)`. Governs\n * whether `InferType` emits `T` instead of `T | undefined` for optional\n * schemas with a default.\n * @typeParam TExtensions - Object type carrying extension methods added via\n * `withExtensions()`. Defaults to `{}`.\n * @typeParam TResult - The inferred result type: `TExplicitType` when set,\n * otherwise the value type inferred from `ReturnType<TFn>`.\n */\nexport class GenericSchemaBuilder<\n TFn extends (...args: any[]) => SchemaBuilder<any, any, any, any, any>,\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n TExplicitType = undefined,\n THasDefault extends boolean = false,\n TExtensions = {},\n TResult = TExplicitType extends undefined\n ? ReturnType<TFn> extends SchemaBuilder<infer R, any, any, any, any>\n ? R\n : any\n : TExplicitType\n> extends SchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n> {\n #templateFn?: (...args: any[]) => SchemaBuilder<any, any, any, any, any>;\n #defaults?: readonly any[];\n #cachedDefaultSchema?: SchemaBuilder<any, any, any, any, any>;\n\n /**\n * Applies the template function with concrete schema arguments, returning\n * a fully typed concrete schema builder. TypeScript infers the result type\n * from the template function's own generic signature.\n *\n * The returned builder is independent of this `GenericSchemaBuilder` and\n * can be used like any other schema: `.validate()`, `.optional()`, etc.\n *\n * @example\n * ```ts\n * const Wrapper = generic(\n * <T extends SchemaBuilder<any, any, any, any, any>>(schema: T) =>\n * object({ data: schema })\n * );\n *\n * const s = Wrapper.apply(string());\n * // InferType<typeof s> → { data: string }\n * s.validate({ data: 'hello' }); // { valid: true }\n * ```\n */\n // Set to the actual function in the constructor; declared here for TypeScript.\n public declare readonly apply: TFn;\n\n /**\n * @hidden\n */\n public static create(props: GenericSchemaBuilderCreateProps<any>) {\n return new GenericSchemaBuilder({\n type: 'generic',\n ...props\n });\n }\n\n protected constructor(props: GenericSchemaBuilderCreateProps<TRequired>) {\n super(props as any);\n this.#templateFn = (props as any).templateFn;\n this.#defaults = (props as any).defaults;\n\n // Own property: typed as TFn so generic inference works at call sites.\n (this as any).apply = (...args: any[]) => {\n if (!this.#templateFn) {\n throw new Error(\n 'GenericSchemaBuilder: no template function defined'\n );\n }\n return this.#templateFn(...args);\n };\n }\n\n /**\n * Returns an object describing the current schema configuration.\n *\n * In addition to the base fields exposed by {@link SchemaBuilder.introspect},\n * the following fields are included:\n *\n * - `templateFn` — the template function passed to {@link generic}.\n * - `defaults` — the default argument list passed to the two-argument\n * form of {@link generic}, or `undefined` when no defaults were provided.\n *\n * @example\n * ```ts\n * const schema = generic([string()], <T>(s: T) => object({ data: s }));\n *\n * const info = schema.introspect();\n * // info.type → 'generic'\n * // info.templateFn → [Function]\n * // info.defaults → [StringSchemaBuilder]\n * ```\n */\n public introspect() {\n return {\n ...super.introspect(),\n /** Template function passed to {@link generic}. */\n templateFn: this.#templateFn,\n /** Default positional arguments for the template function, or `undefined`. */\n defaults: this.#defaults\n };\n }\n\n #getOrCreateDefaultSchema():\n | SchemaBuilder<any, any, any, any, any>\n | undefined {\n if (!this.#templateFn || !this.#defaults) {\n return undefined;\n }\n if (!this.#cachedDefaultSchema) {\n this.#cachedDefaultSchema = this.#templateFn(...this.#defaults);\n }\n return this.#cachedDefaultSchema;\n }\n\n #buildResult(\n superResult: ReturnType<\n GenericSchemaBuilder<TFn, TRequired>['preValidateSync']\n >,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n const {\n valid,\n transaction: preValidationTransaction,\n errors\n } = superResult;\n\n if (!valid) {\n return { valid, errors };\n }\n\n const {\n object: { validatedObject: objToValidate }\n } = preValidationTransaction!;\n\n if (\n (typeof objToValidate === 'undefined' && !this.isRequired) ||\n (objToValidate === null && (!this.isRequired || this.isNullable))\n ) {\n return { valid: true, object: objToValidate };\n }\n\n const defaultSchema = this.#getOrCreateDefaultSchema();\n if (!defaultSchema) {\n return {\n valid: false,\n errors: [\n {\n message:\n 'This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic().'\n }\n ]\n };\n }\n\n return defaultSchema.validate(\n objToValidate,\n context\n ) as ValidationResult<TResult>;\n }\n\n async #buildAsyncResult(\n superResult: Awaited<\n ReturnType<GenericSchemaBuilder<TFn, TRequired>['preValidateAsync']>\n >,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n const {\n valid,\n transaction: preValidationTransaction,\n errors\n } = superResult;\n\n if (!valid) {\n return { valid, errors };\n }\n\n const {\n object: { validatedObject: objToValidate }\n } = preValidationTransaction!;\n\n if (\n (typeof objToValidate === 'undefined' && !this.isRequired) ||\n (objToValidate === null && (!this.isRequired || this.isNullable))\n ) {\n return { valid: true, object: objToValidate };\n }\n\n const defaultSchema = this.#getOrCreateDefaultSchema();\n if (!defaultSchema) {\n return {\n valid: false,\n errors: [\n {\n message:\n 'This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic().'\n }\n ]\n };\n }\n\n return (await defaultSchema.validateAsync(\n objToValidate,\n context\n )) as ValidationResult<TResult>;\n }\n\n /** {@inheritDoc SchemaBuilder.validate} */\n public validate(\n object: TResult,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n return super.validate(object, context) as ValidationResult<TResult>;\n }\n\n /** {@inheritDoc SchemaBuilder.validateAsync} */\n public async validateAsync(\n object: TResult,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return super.validateAsync(object, context) as Promise<\n ValidationResult<TResult>\n >;\n }\n\n /**\n * Performs synchronous validation of the schema over `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n * @param context Optional `ValidationContext` settings.\n */\n protected _validate(\n object: TResult,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n return this.#buildResult(\n this.preValidateSync(object, context),\n context\n );\n }\n\n /**\n * Performs async validation of the schema over `object`.\n * Supports async preprocessors, validators, and error message providers.\n * @param context Optional `ValidationContext` settings.\n */\n protected async _validateAsync(\n object: TResult,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return this.#buildAsyncResult(\n await super.preValidateAsync(object, context),\n context\n );\n }\n\n protected createFromProps<TReq extends boolean>(\n props: GenericSchemaBuilderCreateProps<TReq>\n ): this {\n return GenericSchemaBuilder.create(props as any) as any;\n }\n\n /**\n * @hidden\n */\n public hasType<T>(\n _notUsed?: T\n ): GenericSchemaBuilder<TFn, true, TNullable, T, THasDefault, TExtensions> &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n /**\n * @hidden\n */\n public clearHasType(): GenericSchemaBuilder<\n TFn,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n /**\n * @hidden\n */\n public required(\n errorMessage?: ValidationErrorMessageProvider\n ): GenericSchemaBuilder<\n TFn,\n true,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.required(errorMessage);\n }\n\n /**\n * @hidden\n */\n public optional(): GenericSchemaBuilder<\n TFn,\n false,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.optional();\n }\n\n /**\n * @hidden\n */\n public nullable(): GenericSchemaBuilder<\n TFn,\n TRequired,\n true,\n TExplicitType,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.nullable() as any;\n }\n\n /**\n * @hidden\n */\n public notNullable(): GenericSchemaBuilder<\n TFn,\n TRequired,\n false,\n TExplicitType,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.notNullable() as any;\n }\n\n /**\n * @hidden\n */\n public default(\n value: TResult | (() => TResult)\n ): GenericSchemaBuilder<\n TFn,\n true,\n TNullable,\n TExplicitType,\n true,\n TExtensions\n > &\n TExtensions {\n return super.default(value) as any;\n }\n\n /**\n * @hidden\n */\n public clearDefault(): GenericSchemaBuilder<\n TFn,\n TRequired,\n TNullable,\n TExplicitType,\n false,\n TExtensions\n > &\n TExtensions {\n return super.clearDefault() as any;\n }\n\n /**\n * @hidden\n */\n public brand<TBrand extends string | symbol>(\n _name?: TBrand\n ): GenericSchemaBuilder<\n TFn,\n TRequired,\n TNullable,\n TResult & { readonly [K in BRAND]: TBrand },\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.brand(_name);\n }\n\n /**\n * @hidden\n */\n public readonly(): GenericSchemaBuilder<\n TFn,\n TRequired,\n TNullable,\n Readonly<TResult>,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.readonly();\n }\n}\n\n/**\n * Creates a generic schema template — a reusable, parameterized schema factory\n * whose TypeScript type is inferred from the template function's generic\n * signature.\n *\n * Call {@link GenericSchemaBuilder.apply | `.apply()`} on the returned builder\n * to instantiate the template with concrete schema arguments and receive a\n * fully typed concrete schema.\n *\n * There are two overloads:\n *\n * 1. **`generic(templateFn)`** — Provide only the template function. The\n * template must be called via `.apply()` before validation.\n * 2. **`generic(defaults, templateFn)`** — Provide positional default arguments\n * followed by the template function. The template can be validated directly\n * using those defaults (without calling `.apply()` first).\n *\n * @param templateFn - A (generic) function that accepts schema arguments and\n * returns a concrete schema. TypeScript infers the result type from this\n * function's generic signature when `.apply()` is called.\n *\n * @returns A new {@link GenericSchemaBuilder} with `isRequired` set to `true`.\n *\n * @example Single type parameter\n * ```ts\n * import { generic, object, array, number, string, any, InferType } from '@cleverbrush/schema';\n *\n * const PaginatedList = generic(\n * <T extends SchemaBuilder<any, any, any, any, any>>(itemSchema: T) =>\n * object({ items: array(itemSchema), total: number(), page: number() })\n * );\n *\n * const UserList = PaginatedList.apply(object({ name: string() }));\n * type UserListType = InferType<typeof UserList>;\n * // → { items: { name: string }[]; total: number; page: number }\n *\n * UserList.validate({ items: [{ name: 'Alice' }], total: 1, page: 1 }); // valid\n * ```\n *\n * @example Multiple type parameters\n * ```ts\n * const Result = generic(\n * <T extends SchemaBuilder<any, any, any, any, any>,\n * E extends SchemaBuilder<any, any, any, any, any>>(\n * valueSchema: T,\n * errorSchema: E\n * ) =>\n * union(\n * object({ ok: boolean().equalsTo(true), value: valueSchema }),\n * object({ ok: boolean().equalsTo(false), error: errorSchema })\n * )\n * );\n *\n * const StringResult = Result.apply(string(), number());\n * ```\n *\n * @example With defaults (enables direct validation on the template)\n * ```ts\n * const AnyList = generic(\n * [any()], // default args — positional, one per template parameter\n * <T extends SchemaBuilder<any, any, any, any, any>>(itemSchema: T) =>\n * object({ items: array(itemSchema), total: number() })\n * );\n *\n * // Validate directly — uses the default any() schema:\n * AnyList.validate({ items: [1, 'two'], total: 2 }); // valid\n *\n * // Or apply concrete schemas first:\n * AnyList.apply(string()).validate({ items: ['x'], total: 1 }); // valid\n * ```\n *\n * @see {@link GenericSchemaBuilder}\n */\nexport function generic<\n TFn extends (...args: any[]) => SchemaBuilder<any, any, any, any, any>\n>(\n templateFn: TFn\n): GenericSchemaBuilder<TFn, true, false, undefined, false, {}>;\nexport function generic<\n TFn extends (...args: any[]) => SchemaBuilder<any, any, any, any, any>\n>(\n defaults: readonly any[],\n templateFn: TFn\n): GenericSchemaBuilder<TFn, true, false, undefined, false, {}>;\nexport function generic<\n TFn extends (...args: any[]) => SchemaBuilder<any, any, any, any, any>\n>(\n fnOrDefaults: TFn | readonly any[],\n templateFn?: TFn\n): GenericSchemaBuilder<TFn, true, false, undefined, false, {}> {\n const fn = templateFn !== undefined ? templateFn : (fnOrDefaults as TFn);\n const defaults =\n templateFn !== undefined ? (fnOrDefaults as readonly any[]) : undefined;\n return GenericSchemaBuilder.create({\n isRequired: true,\n templateFn: fn,\n defaults\n }) as any;\n}\n","/**\n * @module extension\n *\n * The **extension system** for `@cleverbrush/schema` allows third-party and\n * first-party code to add custom methods to any schema builder type\n * (`string`, `number`, `date`, `object`, …) without modifying the core\n * library.\n *\n * ## Overview\n *\n * Extensions follow a two-step workflow:\n *\n * 1. **Define** an extension with {@link defineExtension} — declare which\n * builder types it targets and what methods it adds.\n * 2. **Apply** one or more extensions with {@link withExtensions} — get back\n * augmented factory functions (`string()`, `number()`, …) whose return\n * types include the new methods.\n *\n * ## Ergonomic authoring\n *\n * Extension methods do **not** need to call `withExtension()` manually.\n * The system automatically attaches metadata using the method name as the\n * extension key and the method arguments as the value. This keeps extension\n * definitions concise:\n *\n * ```ts\n * const slugExt = defineExtension({\n * string: {\n * slug(this: StringSchemaBuilder) {\n * return this.addValidator((val) => {\n * const valid = /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(val);\n * return { valid, errors: valid ? [] : [{ message: 'must be a valid URL slug' }] };\n * });\n * }\n * }\n * });\n * ```\n *\n * If you need **custom metadata** (e.g. a different key or a transformed\n * value), call `this.withExtension(key, value)` explicitly — the auto-infer\n * logic will detect the existing key and skip the automatic attachment.\n *\n * ## Stacking and composition\n *\n * Multiple extensions can target the same builder type. Pass them all to\n * `withExtensions()` and the methods are merged. A runtime error is thrown\n * if two extensions define the same method name on the same builder type.\n *\n * ```ts\n * const s = withExtensions(emailExt, slugExt, rangeExt);\n * const schema = s.string().email().slug(); // both methods available\n * ```\n *\n * ## Introspection\n *\n * Extension metadata is accessible via `schema.introspect().extensions`.\n * Each key corresponds to an extension method name and its value is whatever\n * was passed (or auto-inferred) as the extension data.\n *\n * @see {@link defineExtension} — define an extension\n * @see {@link withExtensions} — apply extensions to builder factories\n * @see {@link ExtensionConfig} — shape of the configuration object\n * @see {@link ExtensionDescriptor} — branded descriptor returned by `defineExtension`\n */\nimport { AnySchemaBuilder, any } from './builders/AnySchemaBuilder.js';\nimport { ArraySchemaBuilder, array } from './builders/ArraySchemaBuilder.js';\nimport {\n BooleanSchemaBuilder,\n boolean\n} from './builders/BooleanSchemaBuilder.js';\nimport { DateSchemaBuilder, date } from './builders/DateSchemaBuilder.js';\nimport {\n FunctionSchemaBuilder,\n func\n} from './builders/FunctionSchemaBuilder.js';\nimport {\n GenericSchemaBuilder,\n generic\n} from './builders/GenericSchemaBuilder.js';\nimport { NumberSchemaBuilder, number } from './builders/NumberSchemaBuilder.js';\nimport { ObjectSchemaBuilder, object } from './builders/ObjectSchemaBuilder.js';\nimport {\n PromiseSchemaBuilder,\n promise\n} from './builders/PromiseSchemaBuilder.js';\nimport { RecordSchemaBuilder, record } from './builders/RecordSchemaBuilder.js';\nimport type {\n PropertyDescriptorTree,\n SchemaBuilder\n} from './builders/SchemaBuilder.js';\nimport { StringSchemaBuilder, string } from './builders/StringSchemaBuilder.js';\nimport { TupleSchemaBuilder, tuple } from './builders/TupleSchemaBuilder.js';\nimport { UnionSchemaBuilder, union } from './builders/UnionSchemaBuilder.js';\n\n// ---------------------------------------------------------------------------\n// Builder type name mapping\n// ---------------------------------------------------------------------------\n\n/**\n * Maps each builder type name to the corresponding generic builder class.\n *\n * Used internally to type-check extension method `this` bindings — for\n * example, an extension targeting `\"string\"` receives `this: StringSchemaBuilder`.\n *\n * @internal Not exported — used only by the extension type machinery.\n */\ntype BuilderMap = {\n string: StringSchemaBuilder<any, any, any, any, any>;\n number: NumberSchemaBuilder<any, any, any, any, any>;\n boolean: BooleanSchemaBuilder<any, any, any, any, any, any, any>;\n date: DateSchemaBuilder<any, any, any, any, any>;\n object: ObjectSchemaBuilder<any, any, any, any, any, any, any>;\n array: ArraySchemaBuilder<any, any, any, any, any, any, any>;\n tuple: TupleSchemaBuilder<any, any, any, any, any, any, any>;\n record: RecordSchemaBuilder<any, any, any, any, any, any, any>;\n union: UnionSchemaBuilder<any, any, any, any, any, any>;\n func: FunctionSchemaBuilder<any, any, any, any, any>;\n any: AnySchemaBuilder<any, any, any, any, any, any>;\n promise: PromiseSchemaBuilder<any, any, any, any, any>;\n generic: GenericSchemaBuilder<any, any, any, any, any, any>;\n};\n\ntype BuilderTypeName = keyof BuilderMap;\n\n// Runtime mapping from type name to the actual class constructor\nconst builderClasses: Record<BuilderTypeName, typeof SchemaBuilder> = {\n string: StringSchemaBuilder as any,\n number: NumberSchemaBuilder as any,\n boolean: BooleanSchemaBuilder as any,\n date: DateSchemaBuilder as any,\n object: ObjectSchemaBuilder as any,\n array: ArraySchemaBuilder as any,\n tuple: TupleSchemaBuilder as any,\n record: RecordSchemaBuilder as any,\n union: UnionSchemaBuilder as any,\n func: FunctionSchemaBuilder as any,\n any: AnySchemaBuilder as any,\n promise: PromiseSchemaBuilder as any,\n generic: GenericSchemaBuilder as any\n};\n\n// Runtime mapping from type name to factory function\nconst builderFactories: Record<BuilderTypeName, (...args: any[]) => any> = {\n string,\n number,\n boolean,\n date,\n object,\n array,\n tuple,\n record,\n union,\n func,\n any,\n promise,\n generic\n};\n\n// ---------------------------------------------------------------------------\n// Extension configuration types\n// ---------------------------------------------------------------------------\n\n/**\n * Defines the shape of an extension configuration object passed to\n * {@link defineExtension}.\n *\n * Each key is a **builder type name** — one of `\"string\"`, `\"number\"`,\n * `\"boolean\"`, `\"date\"`, `\"object\"`, `\"array\"`, `\"union\"`, `\"func\"`, or\n * `\"any\"`. The value is a record of **method implementations** to add to\n * that builder type.\n *\n * Method implementations receive `this` bound to the target builder instance\n * (e.g. `StringSchemaBuilder` for the `\"string\"` key) and **must** return a\n * builder of the same type to support fluent chaining.\n *\n * @remarks\n * Extension methods that only add validators/preprocessors do not need to\n * call `this.withExtension()` — the system will auto-attach metadata using\n * the method name as the key and the arguments as the value. Call\n * `this.withExtension(key, value)` explicitly only when you need custom\n * metadata (e.g. a transformed value or a different key).\n *\n * @example\n * ```ts\n * // Minimal extension config — auto-inferred metadata\n * const config: ExtensionConfig = {\n * string: {\n * slug(this: StringSchemaBuilder) {\n * return this.addValidator((v) => ({ valid: /^[a-z0-9-]+$/.test(v), errors: [] }));\n * }\n * },\n * number: {\n * port(this: NumberSchemaBuilder) {\n * return this.isInteger().min(1).max(65535);\n * }\n * }\n * };\n * ```\n *\n * @see {@link defineExtension}\n */\nexport type ExtensionConfig = {\n [K in BuilderTypeName]?: Record<\n string,\n (this: BuilderMap[K], ...args: any[]) => any\n >;\n};\n\n/**\n * A branded descriptor returned by {@link defineExtension}.\n *\n * The descriptor captures the extension's method signatures at the **type\n * level** so that {@link withExtensions} can produce correctly-typed factory\n * functions. At runtime it holds the (possibly wrapped) configuration object.\n *\n * Extension descriptors are intentionally **opaque** — consumers should not\n * access `config` directly. Instead, pass descriptors to\n * {@link withExtensions} to obtain augmented builder factories.\n *\n * @typeParam T - The concrete {@link ExtensionConfig} shape. Inferred\n * automatically by `defineExtension`; you rarely need to specify it.\n *\n * @example\n * ```ts\n * // The type is inferred — no need to annotate\n * const myExt: ExtensionDescriptor<{ string: { slug: ... } }> = defineExtension({ ... });\n * ```\n *\n * @see {@link defineExtension}\n * @see {@link withExtensions}\n */\nexport type ExtensionDescriptor<T extends ExtensionConfig = ExtensionConfig> = {\n readonly __brand: unique symbol;\n readonly config: T;\n};\n\n// ---------------------------------------------------------------------------\n// Type-level extraction of extension methods per builder type\n// ---------------------------------------------------------------------------\n\n/** Extracts the method signatures an extension adds to a given builder type. */\ntype ExtractMethods<\n TExt extends ExtensionConfig,\n TType extends BuilderTypeName\n> =\n TExt[TType] extends Record<string, (...args: any[]) => any>\n ? TExt[TType]\n : {};\n\n/** Merges the methods from multiple extensions for a given builder type. */\ntype MergeExtensionMethods<\n TExts extends readonly ExtensionDescriptor<any>[],\n TType extends BuilderTypeName\n> = TExts extends readonly [\n ExtensionDescriptor<infer TFirst>,\n ...infer TRest extends readonly ExtensionDescriptor<any>[]\n]\n ? ExtractMethods<TFirst, TType> & MergeExtensionMethods<TRest, TType>\n : {};\n\n// ---------------------------------------------------------------------------\n// Return types for withExtensions()\n// ---------------------------------------------------------------------------\n\n/**\n * Unique string-literal brand key used by {@link FixedMethods} to detect\n * extension methods whose first-argument literal should be accumulated in the\n * return type.\n *\n * Declare the return type of any extension method as\n * `this & { readonly [METHOD_LITERAL_BRAND]?: N }` (where `N extends string`)\n * and `FixedMethods` will automatically make it generic so the literal name\n * flows through the type system and accumulates across multiple calls.\n *\n * This powers scope-name autocomplete in `SchemaQueryBuilder.scoped()`.\n */\nconst METHOD_LITERAL_BRAND = '__cleverbrush_method_literal_brand__' as const;\n\nexport { METHOD_LITERAL_BRAND };\nexport type MethodLiteralBrandSymbol = typeof METHOD_LITERAL_BRAND;\n\n/**\n * Generic accumulator brand for extension methods that want to thread\n * a `Record<name, readonly string[]>` map through the builder chain.\n *\n * Extension authors can declare a method's return type as\n * `this & { readonly [EXTRA_TYPE_BRAND]?: { [name]: TKeys } }`\n * and {@link FixedMethods} will automatically:\n * - Make the first argument const-generic (to capture the literal name).\n * - Make the second argument const-generic when it is a `readonly string[]`\n * tuple (to capture the literal key list).\n * - Accumulate both into the 4th `TExtraTypes` parameter of `FixedMethods`\n * so the information survives subsequent method calls on the same builder.\n *\n * This is deliberately projection-agnostic — any extension that follows the\n * `(name: string, data: readonly string[] | function)` signature convention\n * can use it. Projection-specific semantics (e.g. `PROJECTION_BRAND`) live\n * in the consuming library, not here.\n *\n * @see {@link FixedMethods} for how the accumulation works.\n */\nconst EXTRA_TYPE_BRAND = '__cleverbrush_extra_type_brand__' as const;\n\nexport { EXTRA_TYPE_BRAND };\nexport type ExtraTypeBrandSymbol = typeof EXTRA_TYPE_BRAND;\n\n/** @internal Drops the first element of a tuple type. */\ntype TailArgs<T> = T extends readonly [unknown, ...infer R] ? R : [];\n\n/**\n * Intersected onto consumer-facing builder types to make `withExtension`\n * and `getExtension` uncallable (`never`). Using an intersection instead\n * of `Omit` preserves the class identity so extended builders remain\n * assignable to `SchemaBuilder<any, any, any, any, any>`.\n */\nexport type HiddenExtensionMethods = {\n /** @internal Extension-author only — use inside `defineExtension()`. */\n withExtension: never;\n /** @internal Extension-author only — use inside `defineExtension()`. */\n getExtension: never;\n};\n\n/**\n * Overrides extension method return types so they always return the full\n * extended builder type. This ensures extension methods preserve all other\n * extension methods through chaining (e.g. `s.string().email().slug()`).\n *\n * The self-reference (`FixedMethods` appears in its own mapped return\n * types) is resolved lazily by TypeScript because the recursion sits\n * inside a function-return position within a conditional mapped type.\n *\n * The optional third parameter `TAccum` accumulates literal string names\n * registered by methods whose raw return type includes\n * `{ readonly [METHOD_LITERAL_BRAND]?: any }`. Those methods are rewritten\n * as `const`-generic so the literal flows through; all other methods thread\n * the accumulator unchanged.\n *\n * The optional fourth parameter `TExtraTypes` accumulates a\n * `Record<name, readonly string[]>` map contributed by methods whose raw\n * return type includes `{ readonly [EXTRA_TYPE_BRAND]?: any }`. Those\n * methods are rewritten as const-generic for both the name and the keys\n * tuple so the mapping flows through; all other methods thread it unchanged.\n *\n * For object-schema methods the accessor-form callback parameter is\n * automatically typed as `PropertyDescriptorTree<TBase, TBase>` when\n * `TBase` is an `ObjectSchemaBuilder`, giving callers IDE autocomplete over\n * the schema's own properties.\n */\nexport type FixedMethods<\n TRawMethods,\n TBase,\n TAccum extends string = never,\n TExtraTypes extends Record<string, readonly string[]> = Record<never, never>\n> = {\n [K in keyof TRawMethods]: TRawMethods[K] extends (\n this: any,\n ...args: infer A\n ) => infer R\n ? R extends { readonly [EXTRA_TYPE_BRAND]?: any }\n ? // Extra-type-brand method: rest-param shape `(name, ...columns)`.\n // Each column is a property-name string or an accessor callback.\n // The string-literal union accumulates into `TKey` and lands in\n // the `EXTRA_TYPE_BRAND` under `TName` as `readonly TKey[]`.\n // When `TBase` is an `ObjectSchemaBuilder` the callback `t` is\n // typed as `PropertyDescriptorTree<TBase, TBase>` so callers get\n // IDE autocomplete over the schema's own properties.\n <const TName extends string & A[0], const TKey extends string>(\n name: TName,\n ...columns: ReadonlyArray<\n | TKey\n | (TBase extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >\n ? (t: PropertyDescriptorTree<TBase, TBase>) => any\n : (t: any) => any)\n >\n ) => TBase &\n FixedMethods<\n TRawMethods,\n TBase,\n TAccum,\n TExtraTypes & Record<TName, readonly TKey[]>\n > &\n HiddenExtensionMethods & {\n readonly [EXTRA_TYPE_BRAND]?: TExtraTypes &\n Record<TName, readonly TKey[]>;\n } & ([TAccum] extends [never]\n ? {}\n : { readonly [METHOD_LITERAL_BRAND]?: TAccum })\n : R extends { readonly [METHOD_LITERAL_BRAND]?: any }\n ? // Literal-brand method: becomes const-generic so the first-arg\n // literal accumulates in TAccum and in the [METHOD_LITERAL_BRAND]\n // property of the return type.\n <const TName extends string & A[0]>(\n name: TName,\n ...rest: TailArgs<A>\n ) => TBase &\n FixedMethods<\n TRawMethods,\n TBase,\n TAccum | TName,\n TExtraTypes\n > &\n HiddenExtensionMethods & {\n readonly [METHOD_LITERAL_BRAND]?: TAccum | TName;\n } & ([keyof TExtraTypes] extends [never]\n ? {}\n : { readonly [EXTRA_TYPE_BRAND]?: TExtraTypes })\n : // Regular method: threads both accumulators through so literals\n // defined earlier in the chain are not lost.\n (\n ...args: A\n ) => TBase &\n FixedMethods<TRawMethods, TBase, TAccum, TExtraTypes> &\n HiddenExtensionMethods &\n ([TAccum] extends [never]\n ? {}\n : { readonly [METHOD_LITERAL_BRAND]?: TAccum }) &\n ([keyof TExtraTypes] extends [never]\n ? {}\n : { readonly [EXTRA_TYPE_BRAND]?: TExtraTypes })\n : TRawMethods[K];\n};\n\n/**\n * Produces the consumer-facing type for an extended builder: the base\n * builder intersected with its fixed extension methods, with\n * `withExtension` / `getExtension` overridden to `never` so they\n * don't appear as callable in consumer code.\n */\nexport type CleanExtended<TBuilder, TExt> = TBuilder &\n FixedMethods<TExt, TBuilder> &\n HiddenExtensionMethods;\n\n// -- Factory types that return builders with corrected extension methods ------\n\ntype ExtendedStringFactory<TExt> = {\n (): CleanExtended<\n StringSchemaBuilder<string, true, false, false, TExt>,\n TExt\n >;\n <T extends string>(\n equals: T\n ): CleanExtended<StringSchemaBuilder<T, true, false, false, TExt>, TExt>;\n};\n\ntype ExtendedNumberFactory<TExt> = {\n (): CleanExtended<\n NumberSchemaBuilder<number, true, false, false, TExt>,\n TExt\n >;\n <T extends number>(\n equals: T\n ): CleanExtended<NumberSchemaBuilder<T, true, false, false, TExt>, TExt>;\n};\n\ntype ExtendedBooleanFactory<TExt> = () => CleanExtended<\n BooleanSchemaBuilder<boolean, true, false, undefined, false, TExt>,\n TExt\n>;\n\ntype ExtendedDateFactory<TExt> = () => CleanExtended<\n DateSchemaBuilder<Date, true, false, false, TExt>,\n TExt\n>;\n\ntype ExtendedObjectFactory<TExt> = <\n P extends Record<string, SchemaBuilder<any, any, any, any, any>>\n>(\n properties?: P\n) => CleanExtended<\n ObjectSchemaBuilder<P, true, false, undefined, false, TExt, []>,\n TExt\n>;\n\ntype ExtendedArrayFactory<TExt> = <\n TElementSchema extends SchemaBuilder<any, any, any, any, any>\n>(\n elementSchema?: TElementSchema\n) => CleanExtended<\n ArraySchemaBuilder<TElementSchema, true, false, undefined, false, TExt>,\n TExt\n>;\n\ntype ExtendedUnionFactory<TExt> = <\n T extends SchemaBuilder<any, any, any, any, any>\n>(\n schema: T\n) => CleanExtended<\n UnionSchemaBuilder<[T], true, false, undefined, false, TExt>,\n TExt\n>;\n\ntype ExtendedFuncFactory<TExt> = () => CleanExtended<\n FunctionSchemaBuilder<true, false, undefined, false, TExt>,\n TExt\n>;\n\ntype ExtendedAnyFactory<TExt> = () => CleanExtended<\n AnySchemaBuilder<true, false, undefined, false, TExt>,\n TExt\n>;\n\ntype ExtendedTupleFactory<TExt> = <\n const TElements extends readonly SchemaBuilder<any, any, any, any, any>[]\n>(\n elements: [...TElements]\n) => CleanExtended<\n TupleSchemaBuilder<TElements, true, false, undefined, false, TExt>,\n TExt\n>;\n\ntype ExtendedRecordFactory<TExt> = <\n TKeySchema extends StringSchemaBuilder<any, any, any, any>,\n TValueSchema extends SchemaBuilder<any, any, any, any, any>\n>(\n keySchema: TKeySchema,\n valueSchema: TValueSchema\n) => CleanExtended<\n RecordSchemaBuilder<\n TKeySchema,\n TValueSchema,\n true,\n false,\n undefined,\n false,\n TExt\n >,\n TExt\n>;\n\ntype ExtendedPromiseFactory<TExt> = <\n TSchema extends SchemaBuilder<any, any, any, any, any>\n>(\n resolvedTypeSchema?: TSchema\n) => CleanExtended<\n PromiseSchemaBuilder<true, false, undefined, false, TExt, TSchema>,\n TExt\n>;\n\ntype ExtendedGenericFactory<TExt> = <\n TFn extends (...args: any[]) => SchemaBuilder<any, any, any, any, any>\n>(\n templateFn: TFn\n) => CleanExtended<\n GenericSchemaBuilder<TFn, true, false, undefined, false, TExt>,\n TExt\n>;\n\n/**\n * The return type of {@link withExtensions}.\n *\n * Contains a factory function for every builder type (`string`, `number`,\n * `boolean`, `date`, `object`, `array`, `union`, `func`, `any`). Each\n * factory returns a builder whose type includes the methods contributed\n * by all provided extension descriptors.\n *\n * @typeParam TExts - Tuple of extension descriptors passed to `withExtensions`.\n *\n * @see {@link withExtensions}\n */\ntype WithExtensionsResult<TExts extends readonly ExtensionDescriptor<any>[]> = {\n string: ExtendedStringFactory<MergeExtensionMethods<TExts, 'string'>>;\n number: ExtendedNumberFactory<MergeExtensionMethods<TExts, 'number'>>;\n boolean: ExtendedBooleanFactory<MergeExtensionMethods<TExts, 'boolean'>>;\n date: ExtendedDateFactory<MergeExtensionMethods<TExts, 'date'>>;\n object: ExtendedObjectFactory<MergeExtensionMethods<TExts, 'object'>>;\n array: ExtendedArrayFactory<MergeExtensionMethods<TExts, 'array'>>;\n tuple: ExtendedTupleFactory<MergeExtensionMethods<TExts, 'tuple'>>;\n record: ExtendedRecordFactory<MergeExtensionMethods<TExts, 'record'>>;\n union: ExtendedUnionFactory<MergeExtensionMethods<TExts, 'union'>>;\n func: ExtendedFuncFactory<MergeExtensionMethods<TExts, 'func'>>;\n any: ExtendedAnyFactory<MergeExtensionMethods<TExts, 'any'>>;\n promise: ExtendedPromiseFactory<MergeExtensionMethods<TExts, 'promise'>>;\n generic: ExtendedGenericFactory<MergeExtensionMethods<TExts, 'generic'>>;\n};\n\n// ---------------------------------------------------------------------------\n// Reserved method names — cannot be overridden by extensions\n// ---------------------------------------------------------------------------\n\n/**\n * Method names on `SchemaBuilder` that extensions are **not** allowed to\n * override. An error is thrown at definition time if an extension tries\n * to use any of these names.\n *\n * @internal\n */\nconst RESERVED_METHODS = new Set([\n 'validate',\n 'validateAsync',\n 'parse',\n 'parseAsync',\n 'safeParse',\n 'safeParseAsync',\n 'introspect',\n 'optional',\n 'required',\n 'addPreprocessor',\n 'clearPreprocessors',\n 'addValidator',\n 'clearValidators',\n 'hasType',\n 'clearHasType',\n 'createFromProps',\n 'preValidate',\n 'preValidateSync',\n 'preValidateAsync',\n 'getValidationErrorMessage',\n 'getValidationErrorMessageSync',\n 'assureValidationErrorMessageProvider',\n 'withExtension',\n 'getExtension'\n]);\n\n// ---------------------------------------------------------------------------\n// defineExtension()\n// ---------------------------------------------------------------------------\n\n/**\n * Defines an extension targeting one or more schema builder types.\n *\n * Each extension is a plain object keyed by builder type name (`\"string\"`,\n * `\"number\"`, `\"date\"`, …) whose values are method implementations.\n * Methods receive `this` bound to the builder instance and must return a\n * builder to support fluent chaining.\n *\n * ## Ergonomic metadata (auto-infer)\n *\n * Extension methods **do not** have to call `this.withExtension()`. The\n * system wraps each method and automatically attaches\n * `withExtension(methodName, args)` to the returned builder when the key\n * is not already present. This eliminates the most common source of\n * duplication in extension code.\n *\n * - **Zero-arg methods** → metadata value is `true`\n * - **Single-arg methods** → metadata value is the argument itself\n * - **Multi-arg methods** → metadata value is the arguments array\n *\n * If you need **custom metadata** (e.g. a different key, a transformed\n * value, or a structured object), call `this.withExtension(key, value)`\n * explicitly inside the method — the auto-infer logic detects the existing\n * key and skips automatic attachment.\n *\n * ## Validation\n *\n * `defineExtension` validates the configuration eagerly:\n * - Unknown builder type names throw immediately.\n * - {@link RESERVED_METHODS | Reserved method names} (e.g. `validate`,\n * `introspect`) cannot be overridden.\n * - Non-function values in the method record are rejected.\n *\n * @param config - An {@link ExtensionConfig} object mapping builder type\n * names to method records.\n * @returns A branded {@link ExtensionDescriptor} ready to pass to\n * {@link withExtensions}.\n *\n * @example Simple extension (auto-inferred metadata)\n * ```ts\n * const slugExt = defineExtension({\n * string: {\n * slug(this: StringSchemaBuilder) {\n * return this.addValidator((val) => {\n * const valid = /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(val);\n * return { valid, errors: valid ? [] : [{ message: 'invalid slug' }] };\n * });\n * }\n * }\n * });\n *\n * // Usage:\n * const s = withExtensions(slugExt);\n * const schema = s.string().slug();\n * schema.introspect().extensions.slug; // true\n * ```\n *\n * @example Extension with custom metadata\n * ```ts\n * const currencyExt = defineExtension({\n * number: {\n * currency(this: NumberSchemaBuilder, opts?: { maxDecimals?: number }) {\n * const maxDec = opts?.maxDecimals ?? 2;\n * return this.withExtension('currency', { maxDecimals: maxDec })\n * .min(0)\n * .addValidator((val) => {\n * const decimals = (String(val).split('.')[1] ?? '').length;\n * const valid = decimals <= maxDec;\n * return { valid, errors: valid ? [] : [{ message: `max ${maxDec} decimals` }] };\n * });\n * }\n * }\n * });\n * ```\n *\n * @example Multi-builder extension\n * ```ts\n * const myExt = defineExtension({\n * string: {\n * email(this: StringSchemaBuilder) { return this.addValidator(...); }\n * },\n * number: {\n * port(this: NumberSchemaBuilder) { return this.isInteger().min(1).max(65535); }\n * }\n * });\n * ```\n *\n * @throws {Error} If a builder type name is unknown.\n * @throws {Error} If a method name is reserved.\n * @throws {Error} If a method value is not a function.\n *\n * @see {@link withExtensions} — apply the defined extension\n * @see {@link ExtensionConfig} — configuration shape\n */\nexport function defineExtension<T extends ExtensionConfig>(\n config: T\n): ExtensionDescriptor<T> {\n // Validate at definition time and wrap methods for auto-infer extension key\n const wrappedConfig: any = {};\n for (const builderName of Object.keys(config) as BuilderTypeName[]) {\n if (!(builderName in builderClasses)) {\n throw new Error(\n `Unknown builder type \"${builderName}\". Valid types: ${Object.keys(builderClasses).join(', ')}`\n );\n }\n\n const methods = config[builderName];\n if (!methods || typeof methods !== 'object') {\n throw new Error(\n `Extension config for \"${builderName}\" must be an object of methods`\n );\n }\n\n wrappedConfig[builderName] = {};\n for (const methodName of Object.keys(methods)) {\n if (RESERVED_METHODS.has(methodName)) {\n throw new Error(\n `Cannot override reserved method \"${methodName}\" on \"${builderName}\"`\n );\n }\n const origMethod = methods[methodName];\n if (typeof origMethod !== 'function') {\n throw new Error(\n `Extension method \"${builderName}.${methodName}\" must be a function`\n );\n }\n // Wrap the method to auto-infer extension key if not already set\n wrappedConfig[builderName][methodName] = function (\n this: any,\n ...args: any[]\n ) {\n const result = (origMethod as any).apply(this, args);\n // If result is a builder and does not have the extension key, auto-apply withExtension\n if (\n result &&\n typeof result === 'object' &&\n typeof result.withExtension === 'function' &&\n // Only auto-apply if the extension key is not already present\n (typeof result.getExtension !== 'function' ||\n result.getExtension(methodName) === undefined)\n ) {\n // Only auto-apply if the original method did not call withExtension\n return result.withExtension(\n methodName,\n args.length === 1\n ? args[0]\n : args.length === 0\n ? true\n : args\n );\n }\n return result;\n };\n }\n }\n\n return { config: wrappedConfig } as ExtensionDescriptor<T>;\n}\n\n// ---------------------------------------------------------------------------\n// withExtensions()\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a set of schema factory functions with the provided extensions\n * applied.\n *\n * Each factory function (`string()`, `number()`, `date()`, …) returned by\n * `withExtensions` produces builder instances whose prototypes include the\n * extension methods. All built-in builder methods remain available and\n * fully chainable alongside the new ones.\n *\n * ## Stacking multiple extensions\n *\n * Pass any number of {@link ExtensionDescriptor}s — their methods are\n * merged per builder type. If two extensions define the **same** method\n * name on the same builder type, a runtime error is thrown to prevent\n * silent conflicts.\n *\n * ## Type safety\n *\n * The return type is fully inferred: TypeScript knows exactly which\n * extension methods are available on each builder factory. Extension\n * methods return the full extended builder type, so chaining like\n * `s.string().email().slug().minLength(3)` is fully typed.\n *\n * ## Builder types without extensions\n *\n * Builders that have no methods from any of the provided extensions\n * use the standard (unextended) factory, so there is zero overhead.\n *\n * @param extensions - One or more {@link ExtensionDescriptor}s created\n * by {@link defineExtension}.\n * @returns An object with factory functions for all builder types\n * (`string`, `number`, `boolean`, `date`, `object`, `array`, `union`,\n * `func`, `any`), each returning augmented builders.\n *\n * @example Basic usage\n * ```ts\n * const s = withExtensions(emailExt, rangeExt);\n *\n * // string() now has .email()\n * const emailSchema = s.string().email().minLength(5);\n *\n * // number() now has .range()\n * const rangeSchema = s.number().range(0, 100);\n *\n * // builders without targeted extensions work as normal\n * const dateSchema = s.date();\n * ```\n *\n * @example Stacking extensions on the same builder\n * ```ts\n * const s = withExtensions(emailExt, slugExt, trimmedExt);\n * const schema = s.string().email().slug().trimmed();\n * ```\n *\n * @example Using extensions in object schemas\n * ```ts\n * const s = withExtensions(emailExt, portExt);\n * const ServerConfig = s.object({\n * host: s.string().email(),\n * port: s.number().port()\n * });\n * ```\n *\n * @throws {Error} If two extensions define the same method name on the\n * same builder type.\n *\n * @see {@link defineExtension} — create extension descriptors\n * @see {@link ExtensionDescriptor}\n */\nexport function withExtensions<\n const TExts extends readonly ExtensionDescriptor<any>[]\n>(...extensions: TExts): WithExtensionsResult<TExts> {\n // Collect all methods per builder type and check for collisions\n const methodsByBuilder = new Map<BuilderTypeName, Map<string, Function>>();\n\n for (const ext of extensions) {\n for (const builderName of Object.keys(\n ext.config\n ) as BuilderTypeName[]) {\n if (!methodsByBuilder.has(builderName)) {\n methodsByBuilder.set(builderName, new Map());\n }\n const methods = methodsByBuilder.get(builderName)!;\n const extMethods = ext.config[builderName]!;\n\n for (const methodName of Object.keys(extMethods)) {\n if (methods.has(methodName)) {\n throw new Error(\n `Extension method collision: \"${methodName}\" is defined by multiple extensions for \"${builderName}\"`\n );\n }\n methods.set(methodName, extMethods[methodName]);\n }\n }\n }\n\n // For each builder type, create a dynamic subclass if there are extension methods\n const factories: Record<string, (...args: any[]) => any> = {};\n\n for (const builderName of Object.keys(\n builderClasses\n ) as BuilderTypeName[]) {\n const methods = methodsByBuilder.get(builderName);\n\n if (!methods || methods.size === 0) {\n // No extensions for this builder type — use the standard factory\n factories[builderName] = builderFactories[builderName];\n continue;\n }\n\n const BaseClass = builderClasses[builderName] as any;\n\n // Create a dynamic subclass\n const ExtendedClass = class extends BaseClass {\n // biome-ignore lint/complexity/noUselessConstructor: required\n constructor(...args: any[]) {\n super(...args);\n }\n\n static create(props: any) {\n return new ExtendedClass({\n ...props\n });\n }\n\n protected createFromProps(props: any): any {\n return ExtendedClass.create(props);\n }\n };\n\n // Add extension methods to the subclass prototype\n for (const [methodName, methodFn] of methods) {\n Object.defineProperty(ExtendedClass.prototype, methodName, {\n value: methodFn,\n writable: true,\n configurable: true,\n enumerable: false\n });\n }\n\n // Create a factory that uses the extended class\n factories[builderName] = (...args: any[]) => {\n // Delegate to the original factory to get an initialized instance,\n // then upgrade its prototype so it gains the extension methods.\n // Note: Object.setPrototypeOf can cause V8 hidden-class deoptimization\n // on the mutated object, but avoids the double allocation and\n // introspect() round-trip of the previous approach.\n const original = builderFactories[builderName](...args);\n Object.setPrototypeOf(original, ExtendedClass.prototype);\n return original;\n };\n }\n\n return factories as WithExtensionsResult<TExts>;\n}\n"],"mappings":"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","names":["GenericSchemaBuilder","_GenericSchemaBuilder","SchemaBuilder","#templateFn","#defaults","#cachedDefaultSchema","props","args","#getOrCreateDefaultSchema","#buildResult","superResult","context","valid","preValidationTransaction","errors","objToValidate","defaultSchema","#buildAsyncResult","object","_notUsed","errorMessage","value","_name","generic","fnOrDefaults","templateFn","fn","defaults","builderClasses","StringSchemaBuilder","NumberSchemaBuilder","BooleanSchemaBuilder","DateSchemaBuilder","ObjectSchemaBuilder","ArraySchemaBuilder","TupleSchemaBuilder","RecordSchemaBuilder","UnionSchemaBuilder","FunctionSchemaBuilder","AnySchemaBuilder","PromiseSchemaBuilder","GenericSchemaBuilder","builderFactories","string","number","boolean","date","object","array","tuple","record","union","func","any","promise","generic","METHOD_LITERAL_BRAND","EXTRA_TYPE_BRAND","RESERVED_METHODS","defineExtension","config","wrappedConfig","builderName","builderClasses","methods","methodName","origMethod","args","result","withExtensions","extensions","methodsByBuilder","ext","extMethods","factories","builderFactories","BaseClass","ExtendedClass","props","methodFn","original"]}