@cleverbrush/schema 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/builders/AnySchemaBuilder.js +1 -1
- package/dist/builders/ArraySchemaBuilder.js +1 -1
- package/dist/builders/BooleanSchemaBuilder.js +1 -1
- package/dist/builders/DateSchemaBuilder.js +1 -1
- package/dist/builders/ExternSchemaBuilder.js +1 -1
- package/dist/builders/FunctionSchemaBuilder.js +1 -1
- package/dist/builders/NumberSchemaBuilder.js +1 -1
- package/dist/builders/ObjectSchemaBuilder.js +1 -1
- package/dist/builders/ParseStringSchemaBuilder.d.ts +9 -0
- package/dist/builders/ParseStringSchemaBuilder.js +1 -1
- package/dist/builders/PromiseSchemaBuilder.js +1 -1
- package/dist/builders/RecordSchemaBuilder.js +1 -1
- package/dist/builders/SchemaBuilder.d.ts +13 -7
- package/dist/builders/StringSchemaBuilder.js +1 -1
- package/dist/builders/TupleSchemaBuilder.js +1 -1
- package/dist/builders/UnionSchemaBuilder.js +1 -1
- package/dist/{chunk-NUW3VXZV.js → chunk-3K7MOEPS.js} +2 -2
- package/dist/{chunk-K6Z47OQY.js → chunk-4RMOR7SV.js} +2 -2
- package/dist/{chunk-ZFI27R3L.js → chunk-57AZDIBB.js} +2 -2
- package/dist/chunk-C4LSLV6T.js +2 -0
- package/dist/chunk-C4LSLV6T.js.map +1 -0
- package/dist/{chunk-WQDYWDOE.js → chunk-EBGC6ZBF.js} +2 -2
- package/dist/{chunk-CFIJQ4GP.js → chunk-ETJPB3TR.js} +2 -2
- package/dist/{chunk-WDMJBGBD.js → chunk-FTA66XZT.js} +2 -2
- package/dist/{chunk-3JMDGYDT.js → chunk-G6HTNXRO.js} +1 -1
- package/dist/chunk-G6HTNXRO.js.map +1 -0
- package/dist/{chunk-ZC6YBKCP.js → chunk-OJJHAZZ4.js} +2 -2
- package/dist/{chunk-BUEVZ3KA.js → chunk-PUWIYD4T.js} +2 -2
- package/dist/{chunk-YQZHDMRF.js → chunk-QG254RGI.js} +2 -2
- package/dist/{chunk-PHE4LIAN.js → chunk-QWYVMYJ2.js} +2 -2
- package/dist/chunk-SY5EYKF2.js +2 -0
- package/dist/chunk-SY5EYKF2.js.map +1 -0
- package/dist/{chunk-QARCEYGO.js → chunk-VRRKXJ2H.js} +2 -2
- package/dist/{chunk-EIVZX4ZO.js → chunk-YYE5HQCL.js} +2 -2
- package/dist/chunk-ZC2HTRZF.js +2 -0
- package/dist/chunk-ZC2HTRZF.js.map +1 -0
- package/dist/{chunk-HN774HD7.js → chunk-ZHBJ46HB.js} +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +1 -1
- package/dist/extension.d.ts +76 -4
- package/dist/extension.js +2 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/dist/chunk-3JMDGYDT.js.map +0 -1
- package/dist/chunk-DY7J6RNN.js +0 -2
- package/dist/chunk-DY7J6RNN.js.map +0 -1
- package/dist/chunk-GXPV6UQK.js +0 -2
- package/dist/chunk-GXPV6UQK.js.map +0 -1
- /package/dist/{chunk-NUW3VXZV.js.map → chunk-3K7MOEPS.js.map} +0 -0
- /package/dist/{chunk-K6Z47OQY.js.map → chunk-4RMOR7SV.js.map} +0 -0
- /package/dist/{chunk-ZFI27R3L.js.map → chunk-57AZDIBB.js.map} +0 -0
- /package/dist/{chunk-WQDYWDOE.js.map → chunk-EBGC6ZBF.js.map} +0 -0
- /package/dist/{chunk-CFIJQ4GP.js.map → chunk-ETJPB3TR.js.map} +0 -0
- /package/dist/{chunk-WDMJBGBD.js.map → chunk-FTA66XZT.js.map} +0 -0
- /package/dist/{chunk-ZC6YBKCP.js.map → chunk-OJJHAZZ4.js.map} +0 -0
- /package/dist/{chunk-BUEVZ3KA.js.map → chunk-PUWIYD4T.js.map} +0 -0
- /package/dist/{chunk-YQZHDMRF.js.map → chunk-QG254RGI.js.map} +0 -0
- /package/dist/{chunk-PHE4LIAN.js.map → chunk-QWYVMYJ2.js.map} +0 -0
- /package/dist/{chunk-QARCEYGO.js.map → chunk-VRRKXJ2H.js.map} +0 -0
- /package/dist/{chunk-EIVZX4ZO.js.map → chunk-YYE5HQCL.js.map} +0 -0
- /package/dist/{chunk-HN774HD7.js.map → chunk-ZHBJ46HB.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/transaction.ts","../src/builders/SchemaBuilder.ts"],"sourcesContent":["const TRANSACTION_SYMBOL = Symbol('transaction');\n\nconst defaultNonTransactionalTypes = [Error, RegExp, Date];\n\n/**\n * Options for customizing transaction behavior.\n */\nexport type TransactionOptions = {\n /**\n * An optional callback returning boolean. Called for every\n * nested object's property (recursively) which is not\n * null `Object`. Using this function you can define if `child`\n * should be wrapped with transaction. It is useful for\n * some cases like Error, Map, etc. when you want to preserve a link,\n * instead of creation of the new transaction.\n * By default it's filtering all instances inheriting from Error and RegExp\n * If `true` is returned from this function `child` will not be wrapped with\n * nested transaction object.\n */\n shouldNotWrapWithTransaction?: (child: any) => boolean;\n};\n\nconst defaultTransactionOptions: TransactionOptions = {\n shouldNotWrapWithTransaction: child =>\n !!defaultNonTransactionalTypes.find(t => child instanceof t)\n};\n\n/**\n * A transaction wrapper around an object. Provides copy-on-write semantics:\n * modifications to `object` are isolated from the original until `commit()` is called.\n * Use `rollback()` to discard changes, and `isDirty()` to check for pending modifications.\n */\nexport type Transaction<T> = {\n /**\n * Transaction object you can modify (equals to `initial` right after the call).\n * All changes to `object` will not be reflected to `initial` until `commit`\n * is called.\n */\n object: T;\n /**\n * Commits transaction, all changes to `object` will be reflected to `initial`\n * after the call of this function.\n */\n commit: () => T;\n /**\n * Rollbacks transaction moving it to the initial state (`object` will be equal to `initial`\n * after the call of this function).\n */\n rollback: () => T;\n /**\n * Returns `true` if there are any changes to `object` which make it different from `initial`.\n */\n isDirty: () => boolean;\n};\n\n/**\n * Starts a transaction over the `initial` object. The returned `object` is a\n * proxy (for plain objects) or a shallow copy (for arrays) that tracks mutations\n * without modifying `initial`. Call `commit()` to apply or `rollback()` to discard changes.\n *\n * @param initial - the object or array to wrap in a transaction\n * @param options - optional configuration to control which nested values are wrapped\n * @returns a {@link Transaction} with `object`, `commit`, `rollback`, and `isDirty` members\n */\nexport const transaction = <T extends {}>(\n initial: T,\n options?: TransactionOptions\n): Transaction<T> => {\n let newProperties: Record<string | symbol, any> = {};\n let deletedProperties = new Map<keyof T, true>();\n\n options = Object.assign({}, defaultTransactionOptions, options || {});\n\n const { shouldNotWrapWithTransaction } =\n options as Required<TransactionOptions>;\n\n const isDirty = () =>\n !!Object.keys(newProperties).find(key => {\n if (newProperties[key]?.[TRANSACTION_SYMBOL]) {\n return newProperties[key][TRANSACTION_SYMBOL].isDirty();\n }\n return true;\n }) || ((deletedProperties.size > 0) as any);\n\n const commit = () => {\n const result = {} as Record<string, any>;\n Object.keys(initial).forEach(key => {\n result[key] = (initial as any)[key];\n });\n\n Object.keys(newProperties).forEach(key => {\n const value = newProperties[key];\n if (value[TRANSACTION_SYMBOL]) {\n const { commit: childCommit } = value[TRANSACTION_SYMBOL];\n result[key] = childCommit();\n } else {\n result[key] = newProperties[key];\n }\n });\n\n for (const key of deletedProperties.keys()) {\n delete result[key as string];\n }\n\n newProperties = {};\n deletedProperties = new Map<keyof T, true>();\n\n return result as T;\n };\n\n const rollback = () => {\n for (const key in newProperties) {\n const value = newProperties[key];\n if (\n value &&\n typeof value === 'object' &&\n value[TRANSACTION_SYMBOL]\n ) {\n // this is nested transaction, let's rollback it as well\n value[TRANSACTION_SYMBOL].rollback();\n }\n }\n newProperties = {};\n deletedProperties = new Map<keyof T, true>();\n return initial;\n };\n\n if (Array.isArray(initial)) {\n const result = initial.map(el =>\n typeof el === 'object' && el && !shouldNotWrapWithTransaction(el)\n ? transaction(el).object\n : el\n );\n const commitArray = () =>\n result.map(el =>\n el && typeof el[TRANSACTION_SYMBOL] === 'object'\n ? el[TRANSACTION_SYMBOL].commit()\n : el\n );\n\n const isDirtyArray = () => {\n return !!result.find((val, index) => {\n if (val && typeof val[TRANSACTION_SYMBOL] === 'object') {\n return val[TRANSACTION_SYMBOL].isDirty();\n }\n return result[index] !== initial[index];\n });\n };\n Object.defineProperty(result, TRANSACTION_SYMBOL, {\n writable: false,\n configurable: false,\n value: {\n initial,\n object: result,\n commit: commitArray as any,\n rollback: () => initial,\n isDirty: isDirtyArray\n }\n });\n return {\n object: result as any,\n commit: commitArray as any,\n rollback: () => initial,\n isDirty: isDirtyArray\n };\n }\n\n const proxy = new Proxy<T>(initial, {\n set: (target, property, value) => {\n if (target && (target as any)[property] === value) {\n delete newProperties[property];\n return true;\n }\n newProperties[property] = value;\n deletedProperties.delete(property as any);\n return true;\n },\n ownKeys: target => {\n return [\n ...Object.keys(target).filter(\n (k: any) => !deletedProperties.has(k)\n ),\n ...Object.keys(newProperties).filter((k: any) => !(k in target))\n ];\n },\n getOwnPropertyDescriptor: (target, prop: any) => {\n if (deletedProperties.has(prop)) {\n return undefined;\n }\n\n if (prop in newProperties) {\n return Object.getOwnPropertyDescriptor(newProperties, prop);\n }\n\n return Object.getOwnPropertyDescriptor(target, prop);\n },\n has: (target, prop: any) => {\n if (deletedProperties.has(prop)) {\n return false;\n }\n\n if (prop in newProperties) {\n return true;\n }\n\n return prop in target;\n },\n get: (target, prop) => {\n if (typeof prop === 'symbol') {\n if (prop === TRANSACTION_SYMBOL) {\n return {\n initial,\n object: proxy,\n commit,\n rollback,\n isDirty\n };\n }\n return (target as any)[prop];\n }\n\n if (prop in newProperties) {\n return newProperties[prop];\n }\n\n if (deletedProperties.has(prop as any)) {\n return undefined;\n }\n\n if (\n !isTransaction((target as any)[prop]) &&\n typeof (target as any)[prop] === 'object' &&\n (target as any)[prop] &&\n !shouldNotWrapWithTransaction((target as any)[prop])\n ) {\n const { object } = transaction((target as any)[prop], options);\n newProperties[prop] = object;\n return object;\n }\n\n return (target as any)[prop];\n },\n deleteProperty: (target, p) => {\n if (p in newProperties) {\n if (\n newProperties[p] &&\n typeof newProperties[p][TRANSACTION_SYMBOL] === 'object'\n ) {\n newProperties[p][TRANSACTION_SYMBOL].rollback();\n }\n delete newProperties[p];\n }\n if (p in target) {\n deletedProperties.set(p as any, true);\n }\n return true;\n }\n });\n\n return {\n object: proxy,\n commit,\n rollback,\n isDirty\n };\n};\n\n/**\n * Creates a lightweight no-op transaction that wraps the `initial` value\n * without any Proxy or copy-on-write overhead. `commit()` and `rollback()`\n * simply return the original object, and `isDirty()` is always `false`.\n *\n * Use this when no preprocessors or validators are defined — there is no\n * risk of mutation, so the full transaction machinery can be skipped.\n */\nexport const noopTransaction = <T extends {}>(initial: T): Transaction<T> => ({\n object: initial,\n commit: () => initial,\n rollback: () => initial,\n isDirty: () => false\n});\n\n/**\n * Checks if `obj` is an instance of a transaction.\n * @param obj object to check if it's a transaction\n * @returns `true` if `obj` is a transaction, `false` otherwise\n */\nexport const isTransaction = (obj: any) =>\n obj && typeof obj === 'object' && Object.hasOwn(obj, TRANSACTION_SYMBOL);\n","import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n noopTransaction,\n type Transaction,\n transaction\n} from '../utils/transaction.js';\nimport type { ArraySchemaBuilder } from './ArraySchemaBuilder.js';\nimport type { ExternSchemaBuilder } from './ExternSchemaBuilder.js';\nimport type { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';\n\n/** @internal Symbol used as the key for the type brand on schema builders. */\ndeclare const __type: unique symbol;\n/** @internal */\nexport type SchemaTypeBrand = typeof __type;\n\n/** @internal Symbol used as the key for the default-value brand on schema builders. */\ndeclare const __hasDefault: unique symbol;\n/** @internal */\nexport type HasDefaultBrand = typeof __hasDefault;\n\n/** Symbol used as the key for branded/opaque types. */\ndeclare const __brand: unique symbol;\n/** Symbol used as the key for branded/opaque types. */\nexport type BRAND = typeof __brand;\n\n/**\n * Intersects a base type with a phantom brand tag.\n * The brand exists only at the type level — zero runtime cost.\n *\n * @example\n * ```ts\n * type Email = Brand<string, 'Email'>;\n * type UserId = Brand<number, 'UserId'>;\n * ```\n */\nexport type Brand<T, TBrand extends string | symbol> = T & {\n readonly [K in BRAND]: TBrand;\n};\n\n/**\n * Infers the TypeScript type that a `SchemaBuilder` instance validates.\n * Takes into account type optimizations (via `optimize()`) and whether the schema is optional.\n *\n * @example\n * ```ts\n * const userSchema = object({ name: string(), age: number().optional() });\n * type User = InferType<typeof userSchema>;\n * // { name: string; age?: number }\n * ```\n */\nexport type InferType<T> = T extends {\n optimize: (...args: any[]) => {\n readonly [K in SchemaTypeBrand]: infer TOptimized;\n };\n}\n ? TOptimized\n : T extends { readonly [K in SchemaTypeBrand]: infer TType }\n ? TType\n : T;\n\n/**\n * Represents a single validation error with a human-readable error message.\n *\n * When returned from an object-level validator (via {@link SchemaBuilder.addValidator | addValidator}),\n * the optional `property` selector can route the error to a specific property\n * so that {@link ObjectSchemaValidationResult.getErrorsFor | getErrorsFor()} reports it\n * on that property rather than only on the root object.\n *\n * ```ts\n * .addValidator((v) => ({\n * valid: false,\n * errors: [{\n * message: 'Passwords do not match',\n * property: (t) => t.confirmPassword\n * }]\n * }))\n * ```\n */\nexport type ValidationError = {\n message: string;\n /**\n * Optional property selector that targets this error to a specific\n * property of the validated object. Uses the same selector signature\n * as `getErrorsFor()` and react-form's `forProperty`.\n */\n property?: (tree: any) => any;\n};\n\n/**\n * Used to represent a validation result for nested\n * objects/properties. Contains a list of errors and\n * the value that caused them.\n */\nexport type NestedValidationResult<\n TSchema,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TParentPropertyDescriptor\n> = {\n /**\n * Value that property had and which caused error or errors\n */\n seenValue?: InferType<TSchema>;\n /**\n * A list of errors, empty if object satisfies a schema\n */\n errors: ReadonlyArray<string>;\n\n /**\n * Whether validation passed for this property and all of its children.\n */\n isValid: boolean;\n\n get descriptor(): PropertyDescriptorInner<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >;\n};\n\n/**\n * Utility type that makes a value `T` optional (i.e. `T | undefined`).\n * Used internally by {@link InferType} to represent optional schema fields.\n */\nexport type MakeOptional<T> = { prop?: T }['prop'];\n\n/**\n * Type of the function that provides a validation error message for\n * the given `seenValue` and `schema`. Can be a string or a function\n * returning a string or a promise of a string.\n * Should be used to provide a custom validation error message.\n */\nexport type ValidationErrorMessageProvider<\n TSchema extends SchemaBuilder<any, any, any, any, any> = SchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >\n> =\n | string\n | ((\n seenValue: InferType<TSchema>,\n schema: TSchema\n ) => string | Promise<string>);\n\nexport type ValidationResult<T> = {\n /**\n * If `true` - object satisfies schema\n */\n valid: boolean;\n /**\n * Contains validated object. Can be different (if there are any preprocessors in the schema) from object\n * passed to the `validate` method of the `SchemaBuilder` class.\n */\n object?: T;\n errors?: ValidationError[];\n};\n\n/**\n * Error thrown by {@link SchemaBuilder.parse | parse()} and\n * {@link SchemaBuilder.parseAsync | parseAsync()} when validation fails.\n * Carries the full array of {@link ValidationError | validation errors}.\n */\nexport class SchemaValidationError extends Error {\n public readonly errors: ValidationError[];\n\n constructor(errors: ValidationError[]) {\n const message =\n errors.length > 0\n ? errors.map(e => e.message).join('; ')\n : 'Validation failed';\n super(message);\n this.name = 'SchemaValidationError';\n this.errors = errors;\n }\n}\n\n/**\n * Internal result returned by the `preValidate` step of `SchemaBuilder`.\n * Contains the validation context, any early errors, and the transaction\n * wrapping the (possibly preprocessed) value.\n */\nexport type PreValidationResult<T, TTransactionType> = Omit<\n ValidationResult<T>,\n 'object'\n> & {\n context: ValidationContext;\n transaction?: Transaction<TTransactionType>;\n rootPropertyDescriptor?: PropertyDescriptor<any, any, undefined>;\n};\n\ntype ValidatorResult<T> = Omit<ValidationResult<T>, 'object' | 'errors'> & {\n errors?: ValidationError[];\n};\n\n/**\n * A function that transforms the value before validation.\n * Preprocessors run in order before validators and can modify or replace the value.\n *\n * @param object - the current value to preprocess\n * @returns the transformed value, or a Promise resolving to it\n */\nexport type Preprocessor<T> = (object: T) => Promise<T> | T;\n\n/**\n * A custom validation function that checks a value and returns a result\n * indicating whether the value is valid, along with optional error messages.\n *\n * @param object - the value to validate\n * @returns a result with `valid` boolean and optional `errors` array, or a Promise resolving to it\n */\nexport type Validator<T> = (\n object: T\n) => Promise<ValidatorResult<T>> | ValidatorResult<T>;\n\n/**\n * Internal wrapper that pairs a preprocessor function with metadata\n * indicating whether it may mutate the value.\n */\nexport type PreprocessorEntry<T> = { fn: Preprocessor<T>; mutates: boolean };\n\n/**\n * Internal wrapper that pairs a validator function with metadata\n * indicating whether it may mutate the value.\n */\nexport type ValidatorEntry<T> = { fn: Validator<T>; mutates: boolean };\n\n/**\n * Configuration properties used to construct a `SchemaBuilder` instance.\n * Contains the schema type identifier, requirement flag, and lists of\n * preprocessors and validators.\n */\nexport type SchemaBuilderProps<T> = {\n type: string;\n isRequired?: boolean;\n isNullable?: boolean;\n isReadonly?: boolean;\n preprocessors: PreprocessorEntry<T>[];\n validators: ValidatorEntry<T>[];\n requiredValidationErrorMessageProvider?: ValidationErrorMessageProvider;\n extensions?: Record<string, unknown>;\n defaultValue?: T | (() => T);\n catchValue?: T | (() => T);\n hasCatch?: boolean;\n description?: string;\n schemaName?: string;\n example?: unknown;\n};\n\nexport type ValidationContext<\n TSchema extends SchemaBuilder<any, any, any, any> = SchemaBuilder<\n any,\n any,\n any,\n any\n >\n> = {\n /**\n * Optional. By default validation will stop after the first validation error, in case if\n * you want to receive all validation erors, please set this flag to `true`.\n * You might need it to display validation errors.\n */\n doNotStopOnFirstError?: boolean;\n\n /**\n * Optional. If you define a `rootPropertyDescriptor` while validating an object,\n * it will report all validation errors with the path starting from the root property.\n * Normally it's used internally by the library for validation of nested objects and\n * should not be used directly (but who knows, maybe you will find a use case for it).\n */\n rootPropertyDescriptor?: TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n >\n ? PropertyDescriptor<TSchema, TSchema, undefined>\n : never;\n\n /**\n * Optional. This is a property descriptor for the current object being validated.\n * This descriptor is descendant of the `rootPropertyDescriptor` and is used to provide\n * a path to the current object being validated in the root object.\n * Normally it's used internally by the library for validation of nested objects and\n * should not be used directly (but who knows, maybe you will find a use case for it).\n */\n currentPropertyDescriptor?: TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any\n >\n ? PropertyDescriptor<TSchema, TSchema, unknown>\n : never;\n\n /**\n * Optional. Used along with `rootPropertyDescriptor` and `currentPropertyDescriptor` to provide\n * a root validation object, this object will be used to retrieve the value of properties\n * using the `rootPropertyDescriptor` because the `rootPropertyDescriptor` is a property descriptor\n * for the root object, and it needs the root object along with the whole structure to get the\n * value of the property.\n *\n * Normally it's used internally by the library for validation of nested objects and\n * should not be used directly (but who knows, maybe you will find a use case for it).\n */\n rootValidationObject?: InferType<TSchema>;\n};\n\n/**\n * A symbol to mark property descriptors in the schema.\n * Normally, you should not use it directly unless you want\n * to develop some advanced features or extend the library.\n * In normal conditions it's used internally by the library.\n */\nexport const SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR = Symbol();\n\n/**\n * A symbol that marks a schema as having sub-properties that can\n * participate in property descriptor trees. When a schema exposes\n * `[SYMBOL_HAS_PROPERTIES] = true` **and** its `introspect()` returns\n * a `properties` record, it will be recursed into by\n * `ObjectSchemaBuilder.getPropertiesFor()` — the same way nested\n * `ObjectSchemaBuilder` instances are.\n *\n * Currently implemented by `ObjectSchemaBuilder` (always) and\n * `ExternSchemaBuilder` (when created with an explicit property map).\n */\nexport const SYMBOL_HAS_PROPERTIES = Symbol();\n\n/**\n * Describes a property in a schema. And gives you\n * a possibility to access property value and set it.\n * suppose you have a schema like this:\n * ```ts\n * const schema = object({\n * name: string(),\n * address: object({\n * city: string(),\n * country: string()\n * }),\n * id: number()\n * });\n * ```\n * then you can get a property descriptor for the `address.city` property\n * like this:\n * ```ts\n * const addressCityDescriptor = object.getPropertiesFor(schema).address.city;\n * ```\n *\n * And then you can use it to get and set the value of this property having the object:\n * ```ts\n * const obj = {\n * name: 'Leo',\n * address: {\n * city: 'Kozelsk',\n * country: 'Russia'\n * },\n * id: 123\n * };\n *\n * const success = addressCityDescriptor.setValue(obj, 'Venyov');\n * // this returns you a boolean value indicating if the value was set successfully\n * ```\n */\n\nexport type PropertySetterOptions = {\n /**\n * If set to `true`, the method will create missing structure\n * in the object to set the value. For example, if you have a schema\n * and property descriptor like this:\n * ```ts\n * const schema = object({\n * address: object({\n * city: string(),\n * country: string()\n * }),\n * });\n * const addressCityDescriptor = object.getPropertiesFor(schema).address.city;\n * ```\n * And then you try to set a new value to the `address.city` property on the object\n * which does not have `address` property:\n * ```ts\n * const obj = {\n * name: 'Leo'\n * };\n * const success = addressCityDescriptor.setValue(obj, 'Venyov', { createMissingStructure: true });\n * // success === true\n * // obj === {\n * // name: 'Leo',\n * // address: {\n * // city: 'Venyov'\n * // }\n * // }\n */\n createMissingStructure?: boolean;\n};\n\n/**\n * Extracts the inner property descriptor type from a `PropertyDescriptor`.\n * Returns `undefined` if `T` is not a valid `PropertyDescriptor`.\n */\nexport type PropertyDescriptorInnerFromPropertyDescriptor<T> =\n T extends PropertyDescriptor<\n infer TSchema,\n infer TPropertySchema,\n infer TParentPropertyDescriptor,\n infer TPropertyKey extends string\n >\n ? PropertyDescriptorInner<\n TSchema,\n TPropertySchema,\n TParentPropertyDescriptor,\n TPropertyKey\n >\n : undefined;\n\nexport type PropertyDescriptorInner<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TPropertySchema,\n TParentPropertyDescriptor,\n TPropertyKey extends string = string\n> = {\n /**\n * Sets a new value to the property. If the process was successful,\n * the method returns `true`, otherwise `false`.\n * It can return `false` if the property could not be set to the object\n * which can happen if the `setValue` method is called with an object\n * which does not comply with the schema.\n * for example, if you have a schema and property descriptopr like this:\n * ```ts\n * const schema = object({\n * name: string(),\n * address: object({\n * city: string(),\n * country: string()\n * }),\n * id: number()\n * });\n *\n * const addressCityDescriptor = object.getPropertiesFor(schema).address.city;\n * ```\n * And then you try to set a new value to the `address.city` property on the object\n * which does not have `address` property:\n * ```ts\n * const obj = {\n * name: 'Leo'\n * };\n *\n * const success = addressCityDescriptor.setValue(obj, 'Venyov');\n * // success === false\n * ```\n *\n * @param obj Object to set the value to\n * @param value a new value to set to the property\n * @param options additional optional parameters to control the process\n * @returns\n */\n setValue: (\n obj: InferType<TSchema>,\n value: InferType<TPropertySchema>,\n options?: PropertySetterOptions\n ) => boolean;\n /**\n * Gets the value of the property from the object.\n * @param obj object to get the value from\n * @returns an object containing a `value` and `success` properties. `value` is the value of the property\n * if it was found in the object, `success` is a boolean value indicating if the property was found in the object.\n */\n getValue: (obj: InferType<TSchema>) => {\n value?: InferType<TPropertySchema>;\n success: boolean;\n };\n\n /**\n * Gets the schema for the property described by the property descriptor.\n * @returns a schema for the property\n */\n getSchema: () => TPropertySchema;\n\n parent: PropertyDescriptorInnerFromPropertyDescriptor<TParentPropertyDescriptor>;\n // extends PropertyDescriptor<\n // any,\n // any,\n // any\n // >\n // ? TParentPropertyDescriptor\n // : never;\n\n /**\n * The name of this property within its parent object, or `undefined`\n * for the root descriptor.\n *\n * When the property was created from a `PropertyDescriptorTree` leaf the\n * type narrows to the literal key string (e.g. `'id'`), enabling\n * accessor-function-based column inference in query builders.\n *\n * @typeParam TPropertyKey - The literal property name, or `string` for root/unknown descriptors.\n */\n propertyName: TPropertyKey | undefined;\n\n /**\n * Returns a JSON Pointer (RFC 6901) string representing this\n * property's path from the root descriptor.\n *\n * Property names are escaped per RFC 6901 (`~` → `~0`, `/` → `~1`).\n * The root descriptor returns an empty string (`''`).\n */\n toJsonPointer: () => string;\n};\n\n/**\n * A wrapper object keyed by {@link SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR} that\n * holds a {@link PropertyDescriptorInner} for a particular property within\n * an object schema. Used to get/set property values on validated objects.\n */\nexport type PropertyDescriptor<\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TPropertySchema,\n TParentPropertyDescriptor,\n TPropertyKey extends string = string\n> = {\n [SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]: PropertyDescriptorInner<\n TRootSchema,\n TPropertySchema,\n TParentPropertyDescriptor,\n TPropertyKey\n >;\n};\n\n/**\n * A tree of property descriptors for the schema.\n * Has a possibility to filter properties by the type (`TAssignableTo` type parameter).\n */\nexport type PropertyDescriptorTree<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any> = TSchema,\n TAssignableTo = any,\n TParentPropertyDescriptor = undefined\n> = PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor> &\n (TSchema extends ObjectSchemaBuilder<infer TProperties, any, any>\n ? {\n [K in keyof TProperties]: TProperties[K] extends ObjectSchemaBuilder<\n any,\n any,\n any\n >\n ? PropertyDescriptorTree<\n TProperties[K],\n TRootSchema,\n any,\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n >\n : TProperties[K] extends ExternSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n infer TExternResult\n >\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >,\n K & string\n > &\n ExternOutputPropertyDescriptors<\n TExternResult,\n TRootSchema,\n PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >,\n K & string\n >\n >\n : TProperties[K] extends ArraySchemaBuilder<\n infer TArrayElement,\n any,\n any\n >\n ? TArrayElement extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >,\n K & string\n >\n : InferType<TProperties[K]> extends TAssignableTo\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >,\n K & string\n >\n : never\n : InferType<TProperties[K]> extends TAssignableTo\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >,\n K & string\n >\n : never;\n }\n : never);\n\n/**\n * Recursively maps the keys of an extern schema's output type into\n * property descriptors. When a value is a plain-object type its keys\n * are expanded recursively; primitives, arrays, Dates, and functions\n * are treated as leaves.\n *\n * @internal\n */\ntype ExternOutputPropertyDescriptors<\n TOutput,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TParentPropertyDescriptor\n> = TOutput extends\n | Date\n | Function\n | readonly any[]\n | string\n | number\n | boolean\n | symbol\n | bigint\n | null\n | undefined\n ? {}\n : TOutput extends Record<string, any>\n ? {\n [K in keyof TOutput]: PropertyDescriptor<\n TRootSchema,\n SchemaBuilder<TOutput[K], true, false, false, {}>,\n TParentPropertyDescriptor,\n K & string\n > &\n ExternOutputPropertyDescriptors<\n TOutput[K],\n TRootSchema,\n PropertyDescriptor<\n TRootSchema,\n SchemaBuilder<TOutput[K], true, false, false, {}>,\n TParentPropertyDescriptor,\n K & string\n >\n >;\n }\n : {};\n\n/**\n * Creates an array augmented with non-enumerable NestedValidationResult\n * properties (`seenValue`, `errors`, `isValid`, `descriptor`).\n * Used by UnionSchemaBuilder and ArraySchemaBuilder to return hybrid\n * arrays from `getErrorsFor()`.\n */\nexport function createHybridErrorArray<T extends any[]>(\n items: T,\n seenValue: () => any,\n errors: () => ReadonlyArray<string>,\n descriptor: () => any\n): T {\n Object.defineProperties(items, {\n seenValue: {\n get: seenValue,\n enumerable: false\n },\n errors: {\n get: errors,\n enumerable: false\n },\n isValid: {\n get: () => errors().length === 0,\n enumerable: false\n },\n descriptor: {\n get: descriptor,\n enumerable: false\n }\n });\n return items;\n}\n\n/**\n * Resolves the full output type of a schema, accounting for `TRequired` and\n * `TNullable` modifiers. Mirrors the branded `[__type]` computation so that\n * the `~standard` Standard Schema property carries the correct inferred type.\n *\n * - When `TRequired = true` and `TNullable = false` the result is `TResult`.\n * - When `TRequired = true` and `TNullable = true` the result is `TResult | null`.\n * - When `TRequired = false` the result is wrapped by {@link MakeOptional},\n * adding `| undefined` (and `| null` when also nullable).\n *\n * @internal\n */\ntype ResolvedSchemaType<\n TResult,\n TRequired extends boolean,\n TNullable extends boolean\n> = TRequired extends true\n ? TNullable extends true\n ? TResult | null\n : TResult\n : MakeOptional<TNullable extends true ? TResult | null : TResult>;\n\n/**\n * Base class for all schema builders. Provides basic functionality for schema building.\n *\n * **Note:** this class is not intended to be used directly, use one of the subclasses instead.\n * @typeparam TResult Type of the object that will be returned by `validate()` method.\n * @typeparam TRequired If `true`, object will be required. If `false`, object will be optional.\n */\nexport abstract class SchemaBuilder<\n TResult = any,\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n THasDefault extends boolean = false,\n // biome-ignore lint/correctness/noUnusedVariables: used in extensions\n TExtensions = {}\n> {\n #isRequired = true;\n #isNullable = false;\n #isReadonly = false;\n #description: string | undefined;\n #schemaName: string | undefined;\n #preprocessors: PreprocessorEntry<TResult>[] = [];\n #validators: ValidatorEntry<TResult>[] = [];\n #hasMutating = false;\n #canSkipPreValidation = true;\n #extensions: Record<string, unknown> = {};\n #type = 'base';\n #defaultRequiredErrorMessageProvider: ValidationErrorMessageProvider =\n 'is required';\n #requiredErrorMessageProvider: ValidationErrorMessageProvider =\n 'is required';\n #defaultValue: TResult | (() => TResult) | undefined = undefined;\n #catchValue: TResult | (() => TResult) | undefined = undefined;\n #hasCatch = false;\n #example: unknown | undefined = undefined;\n /**\n * Cached result of the first `['~standard']` access. Stored so that\n * repeated property reads return the exact same object reference, which\n * is required by the Standard Schema spec.\n */\n #standardProps:\n | StandardSchemaV1.Props<\n ResolvedSchemaType<TResult, TRequired, TNullable>\n >\n | undefined;\n\n /**\n * Type-level brand encoding the inferred type of this schema.\n * Not emitted at runtime — used only by {@link InferType}.\n * @internal\n */\n declare readonly [__type]: TRequired extends true\n ? TNullable extends true\n ? TResult | null\n : TResult\n : MakeOptional<TNullable extends true ? TResult | null : TResult>;\n\n /**\n * Type-level brand encoding whether this schema has a default value.\n * Not emitted at runtime — used by input type inference.\n * @internal\n */\n declare readonly [__hasDefault]: THasDefault;\n\n /**\n * Standard Schema v1 interface.\n *\n * Exposes this schema as a [Standard Schema v1](https://standardschema.dev/)\n * validator, enabling out-of-the-box interoperability with any library that\n * consumes the spec — including tRPC, TanStack Form, React Hook Form, T3 Env,\n * Hono, Elysia, next-safe-action, and 50+ other tools.\n *\n * Every `SchemaBuilder` subclass (all 13 builders) inherits this property\n * automatically — no additional setup required.\n *\n * **Shape of the returned object:**\n * - `version` — always `1` (Standard Schema spec version)\n * - `vendor` — `'@cleverbrush/schema'`\n * - `validate(value)` — synchronous; wraps this builder's own `.validate()`\n * and converts its result to the Standard Schema `Result<Output>` format:\n * - Success: `{ value: <validated output> }`\n * - Failure: `{ issues: [{ message: string }, …] }`\n *\n * The returned object is **cached** after the first access so repeated reads\n * return the same reference (required by the spec).\n *\n * @example\n * ```ts\n * import { object, string, number } from '@cleverbrush/schema';\n *\n * const UserSchema = object({\n * name: string().minLength(2),\n * email: string().email(),\n * age: number().min(18).optional(),\n * });\n *\n * // Grab the Standard Schema interface\n * const std = UserSchema['~standard'];\n * // std.version === 1\n * // std.vendor === '@cleverbrush/schema'\n *\n * const ok = std.validate({ name: 'Alice', email: 'alice@example.com' });\n * // { value: { name: 'Alice', email: 'alice@example.com', age: undefined } }\n *\n * const fail = std.validate({ name: 'A', email: 'not-an-email' });\n * // { issues: [{ message: 'minLength' }, { message: 'email' }] }\n *\n * // Pass directly to TanStack Form, T3 Env, tRPC, etc.:\n * // validators: { onChange: UserSchema, onBlur: UserSchema }\n * ```\n *\n * @see https://standardschema.dev/\n */\n get ['~standard'](): StandardSchemaV1.Props<\n ResolvedSchemaType<TResult, TRequired, TNullable>\n > {\n if (this.#standardProps) return this.#standardProps;\n // Capture `this` for the closure so the validate callback can call\n // the schema's own validate method.\n const self = this;\n this.#standardProps = {\n version: 1 as const,\n vendor: '@cleverbrush/schema',\n validate(\n value: unknown\n ): StandardSchemaV1.Result<\n ResolvedSchemaType<TResult, TRequired, TNullable>\n > {\n // Standard Schema validate accepts `unknown`, while the\n // schema's own validate() has a typed parameter. The cast\n // is safe because validate() performs full runtime\n // validation regardless of the compile-time input type.\n const result = self.validate(value as any);\n if (result.valid) {\n return {\n value: result.object as ResolvedSchemaType<\n TResult,\n TRequired,\n TNullable\n >\n };\n }\n return {\n issues: (result.errors ?? []).map(e => ({\n message: e.message\n }))\n };\n }\n };\n return this.#standardProps;\n }\n\n /**\n * Set type of schema explicitly. `notUsed` param is needed only for case when JS is used. E.g. when you\n * can't call method like `schema.hasType<Date>()`, so instead you can call `schema.hasType(new Date())`\n * with the same result.\n */\n public abstract hasType<T>(notUsed?: T): any;\n\n /**\n * Clears type set by call to `.hasType<T>()`, default schema type inference will be used\n * for schema returned by this call.\n */\n public abstract clearHasType(): any;\n\n /**\n * Protected method used to create a new instance of the Builder\n * defined by the `props` object. Should be used to instantiate new\n * builders to keep builder's immutability.\n * @param props arbitrary props object\n */\n protected abstract createFromProps(props: any): this;\n\n /**\n * The string identifier of the schema type (e.g. `'string'`, `'number'`, `'object'`).\n */\n protected get type() {\n return this.#type;\n }\n\n /**\n * Sets the schema type identifier. Must be a non-empty string.\n */\n protected set type(value: string) {\n if (typeof value !== 'string' || !value)\n throw new Error('value should be non empty string');\n this.#type = value;\n }\n\n /**\n * A list of preprocessors associated with\n * the Builder\n */\n protected get preprocessors() {\n return this.#preprocessors;\n }\n\n /**\n * A list of validators associated with\n * the Builder\n */\n protected get validators() {\n return this.#validators;\n }\n\n /**\n * Whether the schema requires a non-null/non-undefined value.\n */\n protected get isRequired(): TRequired {\n return this.#isRequired as TRequired;\n }\n\n /**\n * Whether `null` is an accepted value for this schema.\n */\n protected get isNullable(): boolean {\n return this.#isNullable;\n }\n\n /**\n * Sets the requirement flag. Must be a boolean.\n */\n protected set isRequired(value: boolean) {\n if (typeof value !== 'boolean')\n throw new Error('should be a boolean value');\n this.#isRequired = value as any;\n }\n\n /**\n * The error message provider used for the \"is required\" error.\n * Exposed for fast-path validation in subclasses.\n */\n protected get requiredErrorMessage(): ValidationErrorMessageProvider {\n return this.#requiredErrorMessageProvider;\n }\n\n /**\n * Whether this schema has a default value configured via `.default()`.\n * Exposed for fast-path validation in subclasses.\n */\n protected get hasDefault(): boolean {\n return this.#defaultValue !== undefined;\n }\n\n /**\n * Whether this schema has a catch/fallback value configured via `.catch()`.\n */\n protected get hasCatch(): boolean {\n return this.#hasCatch;\n }\n\n /**\n * Resolves the catch/fallback value. If the stored value is a factory function,\n * it is called to produce the value (useful for mutable fallbacks like `() => []`).\n */\n protected resolveCatchValue(): TResult {\n return typeof this.#catchValue === 'function'\n ? (this.#catchValue as () => TResult)()\n : (this.#catchValue as TResult);\n }\n\n /**\n * Whether this schema is marked as readonly.\n * Type-level only — no runtime enforcement.\n */\n protected get isReadonly(): boolean {\n return this.#isReadonly;\n }\n\n /**\n * Resolves the default value. If the stored default is a function,\n * it is called to produce the value (useful for mutable defaults).\n */\n protected resolveDefaultValue(): TResult {\n return typeof this.#defaultValue === 'function'\n ? (this.#defaultValue as () => TResult)()\n : (this.#defaultValue as TResult);\n }\n\n /**\n * Whether `preValidateSync` can be skipped entirely.\n * True when there are no preprocessors and no validators,\n * so the only work would be the required check and wrapping\n * in a noop transaction — which subclasses can do inline.\n */\n protected get canSkipPreValidation(): boolean {\n return this.#canSkipPreValidation;\n }\n\n /**\n * Whether `null` should count as a required-constraint violation.\n *\n * By default `null` is treated the same as `undefined` for the purposes\n * of the required check — i.e. a required schema rejects both.\n * Subclasses that may legally receive `null` as a value (e.g.\n * `UnionSchemaBuilder` when a `NullSchemaBuilder` option is present)\n * can override this to `false` so that `null` bypasses the required\n * check and is passed directly to their option-validation logic.\n *\n * @protected\n */\n protected get isNullRequiredViolation(): boolean {\n return true;\n }\n\n /**\n * Shared setup for both {@link preValidateSync} and {@link preValidateAsync}.\n * Builds the validation context, creates the initial transaction, and\n * returns mutable state for the caller to drive.\n */\n #initPreValidation(object: any, context?: ValidationContext) {\n const doNotStopOnFirstError = context?.doNotStopOnFirstError ?? false;\n\n const resultingContext: ValidationContext = {\n doNotStopOnFirstError,\n rootPropertyDescriptor: context?.rootPropertyDescriptor,\n currentPropertyDescriptor: context?.currentPropertyDescriptor\n };\n\n const needsTransaction = this.#hasMutating;\n\n return {\n doNotStopOnFirstError,\n resultingContext,\n transaction: needsTransaction\n ? transaction({ validatedObject: object })\n : noopTransaction({ validatedObject: object }),\n errors: [] as ValidationError[]\n };\n }\n\n /**\n * Builds the failed early-return result used when\n * `doNotStopOnFirstError` is false.\n */\n #earlyFailResult(\n errors: ValidationError[],\n resultingContext: ValidationContext\n ): PreValidationResult<any, { validatedObject: any }> {\n return {\n valid: false,\n errors: [errors[0]].filter(e => e),\n context: resultingContext\n };\n }\n\n /**\n * Builds the error entries for a validator that reported `valid: false`.\n */\n #validatorFailureErrors(\n index: number,\n name: string | undefined,\n validatorErrors: ValidationError[] | undefined\n ): ValidationError[] {\n if (Array.isArray(validatorErrors) && validatorErrors.length) {\n return validatorErrors;\n }\n return [\n {\n message: `Validator #${index}${\n name ? ` (${name})` : ''\n } didn't pass.`\n }\n ];\n }\n\n /**\n * Assembles the final {@link PreValidationResult} after all preprocessors,\n * validators, and the required check have run.\n */\n #buildPreValidationResult(\n errors: ValidationError[],\n doNotStopOnFirstError: boolean,\n resultingContext: ValidationContext,\n trans: Transaction<{ validatedObject: any }>\n ): PreValidationResult<any, { validatedObject: any }> {\n if (errors.length > 0) {\n return {\n valid: false,\n errors: errors\n .filter(e => e)\n .filter((_e, i) =>\n doNotStopOnFirstError ? true : i === 0\n ),\n context: resultingContext,\n transaction: trans\n };\n }\n\n return {\n valid: true,\n context: resultingContext,\n transaction: trans\n };\n }\n\n /**\n * Synchronous version of {@link preValidateAsync}.\n * Throws at runtime if any preprocessor or validator returns a Promise.\n *\n * @param object - the value to pre-validate\n * @param context - optional validation context settings\n * @returns a `PreValidationResult` containing the preprocessed transaction, context, and any errors\n * @throws Error if a preprocessor or validator returns a Promise (use {@link preValidateAsync} instead)\n */\n protected preValidateSync(\n object: any,\n context?: ValidationContext\n ): PreValidationResult<any, { validatedObject: any }> {\n const state = this.#initPreValidation(object, context);\n const { doNotStopOnFirstError, resultingContext, errors } = state;\n let preprocessingTransaction = state.transaction;\n let preprocessedObject =\n preprocessingTransaction.object.validatedObject;\n\n if (this.#preprocessors.length > 0) {\n let currentPrepropIndex = 0;\n for (const entry of this.#preprocessors) {\n try {\n const result = entry.fn(preprocessedObject);\n if (result instanceof Promise) {\n throw new Error(\n `Preprocessor #${currentPrepropIndex}${entry.fn.name ? ` (${entry.fn.name})` : ''} returned a Promise. Use validateAsync() for schemas with async preprocessors.`\n );\n }\n preprocessedObject = result;\n } catch (err) {\n if (\n (err as Error).message?.includes('Use validateAsync()')\n ) {\n throw err;\n }\n errors.push({\n message: `Preprocessor #${currentPrepropIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentPrepropIndex++;\n }\n }\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (typeof preprocessedObject === 'undefined' && this.hasDefault) {\n preprocessedObject = this.resolveDefaultValue();\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (\n this.#validators.length > 0 &&\n !(preprocessedObject == null && !this.isRequired) &&\n !(preprocessedObject === null && this.#isNullable)\n ) {\n let currentValidatorIndex = 0;\n for (const entry of this.#validators) {\n try {\n const validatorResult = entry.fn(preprocessedObject);\n if (validatorResult instanceof Promise) {\n throw new Error(\n `Validator #${currentValidatorIndex}${entry.fn.name ? ` (${entry.fn.name})` : ''} returned a Promise. Use validateAsync() for schemas with async validators.`\n );\n }\n const { valid, errors: validatorErrors } = validatorResult;\n if (!valid) {\n errors.push(\n ...this.#validatorFailureErrors(\n currentValidatorIndex,\n entry.fn.name,\n validatorErrors\n )\n );\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(\n errors,\n resultingContext\n );\n }\n }\n } catch (err) {\n if (\n (err as Error).message?.includes('Use validateAsync()')\n ) {\n throw err;\n }\n errors.push({\n message: `Validator #${currentValidatorIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentValidatorIndex++;\n }\n }\n }\n\n if (\n this.isRequired &&\n (typeof preprocessedObject === 'undefined' ||\n (preprocessedObject === null &&\n this.isNullRequiredViolation &&\n !this.#isNullable))\n ) {\n errors.push({\n message: this.getValidationErrorMessageSync(\n this.#requiredErrorMessageProvider,\n preprocessedObject\n )\n });\n if (!doNotStopOnFirstError) {\n preprocessingTransaction.rollback();\n return this.#earlyFailResult(errors, resultingContext);\n }\n }\n\n return this.#buildPreValidationResult(\n errors,\n doNotStopOnFirstError,\n resultingContext,\n preprocessingTransaction\n );\n }\n\n /**\n * Async version of pre-validation. Runs preprocessors, validators, and the\n * required/optional check on `object`. Supports async preprocessors,\n * validators, and error message providers.\n *\n * @param object - the value to pre-validate\n * @param context - optional validation context settings\n * @returns a `PreValidationResult` containing the preprocessed transaction, context, and any errors\n */\n protected async preValidateAsync(\n object: any,\n context?: ValidationContext\n ): Promise<PreValidationResult<any, { validatedObject: any }>> {\n const state = this.#initPreValidation(object, context);\n const { doNotStopOnFirstError, resultingContext, errors } = state;\n let preprocessingTransaction = state.transaction;\n let preprocessedObject =\n preprocessingTransaction.object.validatedObject;\n\n if (this.#preprocessors.length > 0) {\n let currentPrepropIndex = 0;\n for (const entry of this.#preprocessors) {\n try {\n preprocessedObject = await Promise.resolve(\n entry.fn(preprocessedObject)\n );\n } catch (err) {\n errors.push({\n message: `Preprocessor #${currentPrepropIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentPrepropIndex++;\n }\n }\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (typeof preprocessedObject === 'undefined' && this.hasDefault) {\n preprocessedObject = this.resolveDefaultValue();\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (\n this.#validators.length > 0 &&\n !(preprocessedObject == null && !this.isRequired) &&\n !(preprocessedObject === null && this.#isNullable)\n ) {\n let currentValidatorIndex = 0;\n for (const entry of this.#validators) {\n try {\n const { valid, errors: validatorErrors } =\n await Promise.resolve(entry.fn(preprocessedObject));\n if (!valid) {\n errors.push(\n ...this.#validatorFailureErrors(\n currentValidatorIndex,\n entry.fn.name,\n validatorErrors\n )\n );\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(\n errors,\n resultingContext\n );\n }\n }\n } catch (err) {\n errors.push({\n message: `Validator #${currentValidatorIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentValidatorIndex++;\n }\n }\n }\n\n if (\n this.isRequired &&\n (typeof preprocessedObject === 'undefined' ||\n (preprocessedObject === null &&\n this.isNullRequiredViolation &&\n !this.#isNullable))\n ) {\n errors.push({\n message: await this.getValidationErrorMessage(\n this.#requiredErrorMessageProvider,\n preprocessedObject\n )\n });\n if (!doNotStopOnFirstError) {\n preprocessingTransaction.rollback();\n return this.#earlyFailResult(errors, resultingContext);\n }\n }\n\n return this.#buildPreValidationResult(\n errors,\n doNotStopOnFirstError,\n resultingContext,\n preprocessingTransaction\n );\n }\n\n /**\n * @deprecated Use {@link preValidateAsync} instead. This alias will be removed in a future version.\n */\n protected preValidate(\n object: any,\n context?: ValidationContext\n ): Promise<PreValidationResult<any, { validatedObject: any }>> {\n return this.preValidateAsync(object, context);\n }\n\n /**\n * Generates a serializable object describing the defined schema\n */\n public introspect() {\n return {\n /**\n * String `id` of schema type, e.g. `string', `number` or `object`.\n */\n type: this.type,\n /**\n * If set to `false`, schema will be optional (`null` or `undefined` values\n * will be considered as valid).\n */\n isRequired: this.#isRequired,\n /**\n * If set to `true`, schema values of `null` are considered valid.\n */\n isNullable: this.#isNullable,\n /**\n * If set to `true`, the inferred type is marked as readonly.\n * Type-level only — no runtime enforcement.\n */\n isReadonly: this.#isReadonly,\n /**\n * Array of preprocessor functions\n */\n preprocessors: [\n ...this.preprocessors\n ] as readonly PreprocessorEntry<TResult>[],\n /**\n * Array of validator functions\n */\n validators: [\n ...this.validators\n ] as readonly ValidatorEntry<TResult>[],\n /**\n * Custom error message provider for the 'is required' validation error.\n */\n requiredValidationErrorMessageProvider:\n this.#requiredErrorMessageProvider,\n /**\n * Extension metadata. Stores custom state set by schema extensions.\n */\n extensions: { ...this.#extensions },\n /**\n * Whether a default value (or factory) has been set on this schema.\n */\n hasDefault: this.#defaultValue !== undefined,\n /**\n * The default value or factory function.\n */\n defaultValue: this.#defaultValue,\n /**\n * The human-readable description attached to this schema via `.describe()`,\n * or `undefined` if none was set.\n */\n description: this.#description,\n /**\n * The logical name attached to this schema via `.schemaName()`,\n * or `undefined` if none was set.\n */\n schemaName: this.#schemaName,\n /**\n * Whether a catch/fallback value has been set on this schema via `.catch()`.\n */\n\n hasCatch: this.#hasCatch,\n /**\n * The catch/fallback value or factory function set via `.catch()`.\n */\n catchValue: this.#catchValue,\n /**\n * An example value attached to this schema via `.example()`,\n * or `undefined` if none was set.\n */\n example: this.#example\n };\n }\n\n /**\n * Makes schema optional (consider `null` and `undefined` as valid objects for this schema)\n */\n public optional() {\n return this.createFromProps({\n ...this.introspect(),\n isRequired: false\n }) as any;\n }\n\n /**\n * Makes schema nullable — `null` is accepted as a valid value.\n *\n * Unlike `.optional()` which accepts `undefined`, `.nullable()` accepts\n * `null`. The inferred type changes from `T` to `T | null`. Combine with\n * `.optional()` to accept both `null` and `undefined`.\n */\n public nullable() {\n return this.createFromProps({\n ...this.introspect(),\n isNullable: true\n }) as any;\n }\n\n /**\n * Removes the nullable mark — `null` is no longer accepted as a valid\n * value. This is the counterpart of `.nullable()`.\n */\n public notNullable() {\n return this.createFromProps({\n ...this.introspect(),\n isNullable: false\n }) as any;\n }\n\n /**\n * Sets a default value for this schema. When the input is `undefined`,\n * the default value is used instead. The default is still validated\n * against the schema's constraints.\n *\n * Accepts either a static value or a factory function (useful for\n * mutable defaults like `() => new Date()` or `() => []`).\n *\n * @example\n * ```ts\n * const schema = string().default('hello');\n * schema.validate(undefined); // { valid: true, object: 'hello' }\n * schema.validate('world'); // { valid: true, object: 'world' }\n * ```\n *\n * @example\n * ```ts\n * // Factory function for mutable defaults\n * const schema = array(string()).default(() => []);\n * ```\n */\n public default(value: TResult | (() => TResult)) {\n return this.createFromProps({\n ...this.introspect(),\n defaultValue: value\n }) as any;\n }\n\n /**\n * Sets a fallback value for this schema. When validation **fails** for any reason,\n * the fallback value is returned as a successful result instead of validation errors.\n *\n * This is useful for graceful degradation — for example, providing a safe default\n * when parsing untrusted input that might not conform to the schema.\n *\n * Accepts either a static value or a factory function. Factory functions are called\n * each time the fallback is needed (useful for mutable values like `() => []`).\n *\n * Unlike {@link default}, which only fires when the input is `undefined`, `.catch()`\n * fires on **any** validation failure — type mismatch, constraint violation, etc.\n *\n * When `.catch()` is set, {@link parse} and {@link parseAsync} will **never throw**.\n *\n * @param value - the fallback value, or a factory function producing the fallback\n *\n * @example\n * ```ts\n * const schema = string().catch('unknown');\n * schema.validate(42); // { valid: true, object: 'unknown' }\n * schema.validate('hello'); // { valid: true, object: 'hello' }\n * schema.parse(42); // 'unknown' (no throw)\n * ```\n *\n * @example\n * ```ts\n * // Factory function for mutable fallbacks\n * const schema = array(string()).catch(() => []);\n * schema.validate(null); // { valid: true, object: [] }\n * ```\n *\n * @example\n * ```ts\n * // Contrast with .default() — default fires only on undefined\n * const d = string().default('anon');\n * d.validate(undefined); // { valid: true, object: 'anon' } ← fires\n * d.validate(42); // { valid: false, errors: [...] } ← does NOT fire\n *\n * const c = string().catch('anon');\n * c.validate(undefined); // { valid: true, object: 'anon' } ← fires\n * c.validate(42); // { valid: true, object: 'anon' } ← also fires\n * ```\n */\n public catch(value: TResult | (() => TResult)): this {\n return this.createFromProps({\n ...this.introspect(),\n catchValue: value,\n hasCatch: true\n }) as unknown as this;\n }\n\n /**\n * Removes the default value set by a previous call to `.default()`.\n */\n public clearDefault() {\n return this.createFromProps({\n ...this.introspect(),\n defaultValue: undefined\n }) as any;\n }\n\n /**\n * Attaches a human-readable description to this schema as runtime metadata.\n *\n * The description has no effect on validation — it is purely informational.\n * It is accessible via `.introspect().description` and is emitted as the\n * `description` field by `toJsonSchema()` from `@cleverbrush/schema-json`.\n *\n * Useful for documentation generation, form labels, and AI tool descriptions.\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string().describe('The user\\'s full name'),\n * age: number().optional().describe('Age in years'),\n * }).describe('A user object');\n *\n * schema.introspect().description; // 'A user object'\n * ```\n */\n public describe(text: string): this {\n return this.createFromProps({\n ...this.introspect(),\n description: text\n }) as unknown as this;\n }\n\n /**\n * Attaches an example value to this schema instance.\n *\n * The example is purely metadata — it has no effect on validation.\n * It is accessible via `.introspect().example` and is emitted as the\n * `example` keyword in JSON Schema output and OpenAPI spec generation.\n *\n * @example\n * ```ts\n * import { string } from '@cleverbrush/schema';\n *\n * const Email = string().example('user@example.com');\n *\n * Email.introspect().example; // 'user@example.com'\n * ```\n */\n public example(value: TResult): this {\n return this.createFromProps({\n ...this.introspect(),\n example: value\n }) as unknown as this;\n }\n\n /**\n * Attaches a logical name to this schema instance.\n *\n * The name is purely metadata — it has no effect on validation. It is\n * accessible via `.introspect().schemaName` and can be consumed by any\n * tool that introspects schemas at runtime, such as OpenAPI spec\n * generators, documentation tools, form libraries, or code generators.\n *\n * **Uniqueness** is the responsibility of the consuming tool. Passing the\n * same constant (same object reference) to multiple consumers is always\n * safe; how conflicts between different instances with the same name are\n * handled depends on the tool.\n *\n * @example\n * ```ts\n * import { object, string, number } from '@cleverbrush/schema';\n *\n * export const UserSchema = object({\n * id: number(),\n * name: string(),\n * }).schemaName('User');\n *\n * UserSchema.introspect().schemaName; // 'User'\n * ```\n */\n public schemaName(name: string): this {\n return this.createFromProps({\n ...this.introspect(),\n schemaName: name\n }) as unknown as this;\n }\n\n /**\n * Brands the schema with a phantom type tag, preventing structural mixing\n * of semantically different values at the type level. Zero runtime cost.\n *\n * The optional `_name` parameter is only needed when using plain JavaScript\n * (where generic type parameters are unavailable). In TypeScript, prefer\n * the generic form: `schema.brand<'Email'>()`.\n *\n * @example\n * ```ts\n * const Email = string().brand<'Email'>();\n * const Username = string().brand<'Username'>();\n * type Email = InferType<typeof Email>; // string & { readonly [BRAND]: 'Email' }\n * type Username = InferType<typeof Username>; // string & { readonly [BRAND]: 'Username' }\n * ```\n */\n public brand<TBrand extends string | symbol>(_name?: TBrand) {\n return this.createFromProps({\n ...this.introspect()\n }) as any;\n }\n\n /**\n * Marks the inferred type as readonly. For objects, produces `Readonly<T>`.\n * For arrays, produces `ReadonlyArray<T>`. Primitives are unchanged.\n * Type-level only — no runtime enforcement.\n *\n * @example\n * ```ts\n * const schema = object({ name: string(), age: number() }).readonly();\n * type T = InferType<typeof schema>; // Readonly<{ name: string; age: number }>\n * ```\n *\n * @example\n * ```ts\n * const schema = array(string()).readonly();\n * type T = InferType<typeof schema>; // ReadonlyArray<string>\n * ```\n */\n public readonly() {\n return this.createFromProps({\n ...this.introspect(),\n isReadonly: true\n }) as any;\n }\n\n /**\n * Makes schema required (consider `null` and `undefined` as invalid objects for this schema)\n * @param errorMessage - optional custom error message or provider for the 'is required' validation error\n */\n public required(errorMessage?: ValidationErrorMessageProvider) {\n return this.createFromProps({\n ...this.introspect(),\n isRequired: true,\n ...(errorMessage !== undefined\n ? {\n requiredValidationErrorMessageProvider:\n this.assureValidationErrorMessageProvider(\n errorMessage,\n this.#defaultRequiredErrorMessageProvider\n )\n }\n : {})\n }) as any;\n }\n\n /**\n * Adds a `preprocessor` to a preprocessors list\n */\n public addPreprocessor(\n preprocessor: Preprocessor<TResult>,\n options?: { mutates?: boolean }\n ): this {\n if (typeof preprocessor !== 'function') {\n throw new Error('preprocessor must be a function');\n }\n return this.createFromProps({\n ...this.introspect(),\n preprocessors: [\n ...this.preprocessors,\n { fn: preprocessor, mutates: options?.mutates ?? true }\n ]\n });\n }\n\n /**\n * Remove all preprocessors for this schema.\n */\n public clearPreprocessors(): this {\n return this.createFromProps({\n ...this.introspect(),\n preprocessors: []\n });\n }\n\n /**\n * Adds a `validator` to validators list.\n */\n public addValidator(\n validator: Validator<TResult>,\n options?: { mutates?: boolean }\n ): this {\n if (typeof validator !== 'function') {\n throw new Error('validator must be a function');\n }\n return this.createFromProps({\n ...this.introspect(),\n validators: [\n ...this.validators,\n { fn: validator, mutates: options?.mutates ?? false }\n ]\n });\n }\n\n /**\n * Remove all validators for this schema.\n */\n public clearValidators(): this {\n return this.createFromProps({\n ...this.introspect(),\n validators: []\n });\n }\n\n /**\n * Perform synchronous schema validation on `object`.\n * Throws at runtime if any preprocessor, validator, or error message\n * provider returns a Promise — use {@link validateAsync} instead.\n * @internal Override this in subclasses. External callers use {@link validate}.\n */\n protected abstract _validate(\n object: any,\n context?: ValidationContext\n ): ValidationResult<any>;\n\n /**\n * Perform asynchronous schema validation on `object`.\n * Supports async preprocessors, validators, and error message providers.\n * @internal Override this in subclasses. External callers use {@link validateAsync}.\n */\n protected abstract _validateAsync(\n object: any,\n context?: ValidationContext\n ): Promise<ValidationResult<any>>;\n\n /**\n * Perform synchronous schema validation on `object`.\n * Throws at runtime if any preprocessor, validator, or error message\n * provider returns a Promise — use {@link validateAsync} instead.\n *\n * If a fallback has been set via {@link catch}, a failed validation result\n * is replaced by a successful result built from the fallback value, preserving\n * the specialized result shape (e.g. `getErrorsFor` / `getNestedErrors` methods).\n */\n public validate(\n /**\n * Object to validate\n */\n object: any,\n /**\n * Optional `ValidationContext` settings\n */\n context?: ValidationContext\n ): ValidationResult<any> {\n const result = this._validate(object, context);\n if (!result.valid && this.#hasCatch) {\n const catchValue = this.resolveCatchValue();\n // Re-validate the fallback value so the returned result has the same\n // specialized shape as a normal successful result (e.g. getErrorsFor /\n // getNestedErrors helper methods are present and reflect success semantics).\n const catchResult = this._validate(catchValue, context);\n if (catchResult.valid) {\n return catchResult;\n }\n // Fallback value did not pass validation (user error) – return a plain\n // valid result as best-effort so that .catch() still suppresses the error.\n // Note: in this case specialized result methods such as getErrorsFor() /\n // getNestedErrors() will NOT be present on the returned object. This is an\n // edge case caused by the caller supplying a catch value that itself fails\n // schema validation; the type system should prevent this under normal use.\n return { valid: true, object: catchValue };\n }\n return result;\n }\n\n /**\n * Perform asynchronous schema validation on `object`.\n * Supports async preprocessors, validators, and error message providers.\n *\n * If a fallback has been set via {@link catch}, a failed validation result\n * is replaced by a successful result built from the fallback value, preserving\n * the specialized result shape (e.g. `getErrorsFor` / `getNestedErrors` methods).\n */\n public async validateAsync(\n /**\n * Object to validate\n */\n object: any,\n /**\n * Optional `ValidationContext` settings\n */\n context?: ValidationContext\n ): Promise<ValidationResult<any>> {\n const result = await this._validateAsync(object, context);\n if (!result.valid && this.#hasCatch) {\n const catchValue = this.resolveCatchValue();\n // Re-validate the fallback value so the returned result has the same\n // specialized shape as a normal successful result (e.g. getErrorsFor /\n // getNestedErrors helper methods are present and reflect success semantics).\n const catchResult = await this._validateAsync(catchValue, context);\n if (catchResult.valid) {\n return catchResult;\n }\n // Fallback value did not pass validation (user error) – return a plain\n // valid result as best-effort so that .catch() still suppresses the error.\n // Note: in this case specialized result methods such as getErrorsFor() /\n // getNestedErrors() will NOT be present on the returned object. This is an\n // edge case caused by the caller supplying a catch value that itself fails\n // schema validation; the type system should prevent this under normal use.\n return { valid: true, object: catchValue };\n }\n return result;\n }\n\n /**\n * Synchronously resolves a `ValidationErrorMessageProvider` to a string.\n * Throws if the provider function returns a Promise.\n *\n * @param provider - the error message provider (string or sync function)\n * @param seenValue - the value that caused the validation error\n * @returns the resolved error message string\n * @throws Error if the provider returns a Promise (use {@link getValidationErrorMessage} with {@link validateAsync})\n */\n protected getValidationErrorMessageSync(\n provider: ValidationErrorMessageProvider<any>,\n seenValue: TResult\n ): string {\n if (typeof provider === 'string') {\n return provider;\n }\n\n if (typeof provider === 'function') {\n const result = provider(seenValue, this);\n if (result instanceof Promise) {\n throw new Error(\n 'Async error message providers require validateAsync(). Use a string or sync function instead.'\n );\n }\n return result;\n }\n\n throw new Error(\n 'Invalid error message provider must be a string or a function returning a string'\n );\n }\n\n /**\n * Resolves a `ValidationErrorMessageProvider` to a string error message.\n * Handles both string providers and function providers (sync or async).\n *\n * @param provider - the error message provider (string or function)\n * @param seenValue - the value that caused the validation error\n * @returns the resolved error message string\n */\n protected async getValidationErrorMessage(\n provider: ValidationErrorMessageProvider<any>,\n seenValue: TResult\n ): Promise<string> {\n if (typeof provider === 'string') {\n return provider;\n }\n\n if (typeof provider === 'function') {\n return provider(seenValue, this);\n }\n\n throw new Error(\n 'Invalid error message provider must be a string or a function returning a string or a promise of a string'\n );\n }\n\n /**\n * Ensures a `ValidationErrorMessageProvider` is valid.\n * If `provider` is `undefined`, falls back to `defaultValue`.\n * Function providers are bound to `this` for access to schema state.\n *\n * @param provider - the provider to validate, or `undefined`\n * @param defaultValue - fallback provider when `provider` is not supplied\n * @returns a valid `ValidationErrorMessageProvider`\n */\n protected assureValidationErrorMessageProvider(\n provider: ValidationErrorMessageProvider<any> | undefined,\n defaultValue: ValidationErrorMessageProvider<any>\n ): ValidationErrorMessageProvider<any> {\n if (typeof provider === 'string') {\n return provider;\n }\n if (typeof provider === 'function') {\n return provider.bind(this);\n }\n\n if (typeof defaultValue === 'function') {\n return defaultValue.bind(this);\n }\n\n return defaultValue;\n }\n\n /**\n * Sets extension metadata by key. Returns a new schema instance with the\n * extension data stored. The data survives fluent chaining.\n * @internal Used by extension authors inside `defineExtension()` callbacks.\n */\n public withExtension(key: string, value: unknown): this {\n return this.createFromProps({\n ...this.introspect(),\n extensions: {\n ...this.#extensions,\n [key]: value\n }\n });\n }\n\n /**\n * Retrieves extension metadata by key.\n * @internal Used by extension authors inside `defineExtension()` callbacks.\n */\n public getExtension(key: string): unknown {\n return this.#extensions[key];\n }\n\n /**\n * Synchronously validates the value and returns it if valid.\n * Throws a {@link SchemaValidationError} if validation fails.\n *\n * @param object - the value to parse\n * @param context - optional validation context\n * @returns the validated value\n * @throws SchemaValidationError if validation fails\n * @throws Error if the schema contains async preprocessors, validators, or error message providers\n */\n public parse(object: any, context?: ValidationContext): TResult {\n const result = this.validate(object, context);\n if (!result.valid) {\n throw new SchemaValidationError(result.errors || []);\n }\n return result.object as TResult;\n }\n\n /**\n * Asynchronously validates the value and returns it if valid.\n * Throws a {@link SchemaValidationError} if validation fails.\n *\n * @param object - the value to parse\n * @param context - optional validation context\n * @returns the validated value\n * @throws SchemaValidationError if validation fails\n */\n public async parseAsync(\n object: any,\n context?: ValidationContext\n ): Promise<TResult> {\n const result = await this.validateAsync(object, context);\n if (!result.valid) {\n throw new SchemaValidationError(result.errors || []);\n }\n return result.object as TResult;\n }\n\n /**\n * Alias for {@link validate}. Synchronously validates and returns a result object.\n * Provided for familiarity with the zod API.\n */\n public safeParse(\n object: any,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n return this.validate(object, context) as ValidationResult<TResult>;\n }\n\n /**\n * Alias for {@link validateAsync}. Asynchronously validates and returns a result object.\n * Provided for familiarity with the zod API.\n */\n public safeParseAsync(\n object: any,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return this.validateAsync(object, context) as Promise<\n ValidationResult<TResult>\n >;\n }\n\n protected constructor(props: SchemaBuilderProps<TResult>) {\n if (!(typeof props === 'object' && props))\n throw new Error('SchemaBuilder props must be an object');\n const { type, preprocessors, validators, isRequired } = props;\n this.type = type;\n if (typeof isRequired === 'boolean') this.isRequired = isRequired;\n if (typeof props.isNullable === 'boolean')\n this.#isNullable = props.isNullable;\n if (typeof props.isReadonly === 'boolean')\n this.#isReadonly = props.isReadonly;\n if (Array.isArray(preprocessors)) {\n this.#preprocessors = [...preprocessors];\n }\n\n if (Array.isArray(validators)) {\n this.#validators = [...validators];\n }\n\n this.#hasMutating =\n this.#preprocessors.some(p => p.mutates) ||\n this.#validators.some(v => v.mutates);\n\n this.#canSkipPreValidation =\n this.#preprocessors.length === 0 && this.#validators.length === 0;\n\n if (typeof props.extensions === 'object' && props.extensions) {\n this.#extensions = { ...props.extensions };\n }\n\n if (props.defaultValue !== undefined) {\n this.#defaultValue = props.defaultValue;\n }\n\n if (props.hasCatch) {\n this.#hasCatch = true;\n this.#catchValue = props.catchValue;\n }\n\n if (typeof props.description === 'string') {\n this.#description = props.description;\n }\n\n if (typeof props.schemaName === 'string') {\n this.#schemaName = props.schemaName;\n }\n\n if (props.example !== undefined) {\n this.#example = props.example;\n }\n\n this.#requiredErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.requiredValidationErrorMessageProvider,\n this.#defaultRequiredErrorMessageProvider\n );\n }\n}\n"],"mappings":"AAAA,IAAMA,EAAqB,OAAO,aAAa,EAEzCC,EAA+B,CAAC,MAAO,OAAQ,IAAI,EAoBnDC,EAAgD,CAClD,6BAA8BC,GAC1B,CAAC,CAACF,EAA6B,KAAKG,GAAKD,aAAiBC,CAAC,CACnE,EAuCaC,EAAc,CACvBC,EACAC,IACiB,CACjB,IAAIC,EAA8C,CAAC,EAC/CC,EAAoB,IAAI,IAE5BF,EAAU,OAAO,OAAO,CAAC,EAAGL,EAA2BK,GAAW,CAA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G7C,CAEU,YAAYmC,EAAoC,CACtD,GAAI,EAAE,OAAOA,GAAU,UAAYA,GAC/B,MAAM,IAAI,MAAM,uCAAuC,EAC3D,GAAM,CAAE,KAAAC,EAAM,cAAAC,EAAe,WAAAC,EAAY,WAAAC,CAAW,EAAIJ,EACxD,KAAK,KAAOC,EACR,OAAOG,GAAe,YAAW,KAAK,WAAaA,GACnD,OAAOJ,EAAM,YAAe,YAC5B,KAAKzD,GAAcyD,EAAM,YACzB,OAAOA,EAAM,YAAe,YAC5B,KAAKxD,GAAcwD,EAAM,YACzB,MAAM,QAAQE,CAAa,IAC3B,KAAKvD,GAAiB,CAAC,GAAGuD,CAAa,GAGvC,MAAM,QAAQC,CAAU,IACxB,KAAKvD,GAAc,CAAC,GAAGuD,CAAU,GAGrC,KAAKtD,GACD,KAAKF,GAAe,KAAK0D,GAAKA,EAAE,OAAO,GACvC,KAAKzD,GAAY,KAAK0D,GAAKA,EAAE,OAAO,EAExC,KAAKxD,GACD,KAAKH,GAAe,SAAW,GAAK,KAAKC,GAAY,SAAW,EAEhE,OAAOoD,EAAM,YAAe,UAAYA,EAAM,aAC9C,KAAKjD,GAAc,CAAE,GAAGiD,EAAM,UAAW,GAGzCA,EAAM,eAAiB,SACvB,KAAK7C,GAAgB6C,EAAM,cAG3BA,EAAM,WACN,KAAK3C,GAAY,GACjB,KAAKD,GAAc4C,EAAM,YAGzB,OAAOA,EAAM,aAAgB,WAC7B,KAAKvD,GAAeuD,EAAM,aAG1B,OAAOA,EAAM,YAAe,WAC5B,KAAKtD,GAAcsD,EAAM,YAGzBA,EAAM,UAAY,SAClB,KAAK1C,GAAW0C,EAAM,SAG1B,KAAK9C,GACD,KAAK,qCACD8C,EAAM,uCACN,KAAK/C,EACT,CACR,CACJ","names":["TRANSACTION_SYMBOL","defaultNonTransactionalTypes","defaultTransactionOptions","child","t","transaction","initial","options","newProperties","deletedProperties","shouldNotWrapWithTransaction","isDirty","key","commit","result","value","childCommit","rollback","el","commitArray","isDirtyArray","val","index","proxy","target","property","k","prop","isTransaction","object","p","noopTransaction","obj","SchemaValidationError","errors","message","e","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","SYMBOL_HAS_PROPERTIES","createHybridErrorArray","items","seenValue","descriptor","SchemaBuilder","#isRequired","#isNullable","#isReadonly","#description","#schemaName","#preprocessors","#validators","#hasMutating","#canSkipPreValidation","#extensions","#type","#defaultRequiredErrorMessageProvider","#requiredErrorMessageProvider","#defaultValue","#catchValue","#hasCatch","#example","#standardProps","self","value","result","#initPreValidation","object","context","doNotStopOnFirstError","resultingContext","needsTransaction","transaction","noopTransaction","#earlyFailResult","#validatorFailureErrors","index","name","validatorErrors","#buildPreValidationResult","trans","_e","i","state","preprocessingTransaction","preprocessedObject","currentPrepropIndex","entry","err","currentValidatorIndex","validatorResult","valid","text","_name","errorMessage","preprocessor","options","validator","catchValue","catchResult","provider","defaultValue","key","props","type","preprocessors","validators","isRequired","p","v"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as n}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as n}from"./chunk-G6HTNXRO.js";var r=class s extends n{#e=[];#a;static create(e){return new s({type:"function",...e})}constructor(e){super(e),Array.isArray(e.parameters)&&(this.#e=e.parameters.filter(a=>a instanceof n)),e.returnType instanceof n&&(this.#a=e.returnType)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}introspect(){return{...super.introspect(),parameters:[...this.#e],returnType:this.#a}}#t(e){let{valid:a,transaction:i,errors:u}=e;if(!a)return{valid:a,errors:u};let{object:{validatedObject:t}}=i;return typeof t>"u"&&!this.isRequired||t===null&&(!this.isRequired||this.isNullable)?{valid:!0,object:t}:typeof t!="function"?{valid:!1,errors:[{message:`expected type function, but saw ${typeof t}`}]}:{valid:!0,object:t}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){return this.#t(this.preValidateSync(e,a))}async _validateAsync(e,a){return this.#t(await super.preValidateAsync(e,a))}createFromProps(e){return s.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}nullable(){return super.nullable()}addParameter(e){return this.createFromProps({...this.introspect(),parameters:[...this.#e,e]})}hasReturnType(e){return this.createFromProps({...this.introspect(),returnType:e})}notNullable(){return super.notNullable()}},T=()=>r.create({isRequired:!0});export{r as a,T as b};
|
|
2
|
+
//# sourceMappingURL=chunk-OJJHAZZ4.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as l}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as l}from"./chunk-G6HTNXRO.js";var n=class i extends l{#e;#b=function(){return`expected to be at least ${this.#e}`};#a=this.#b;#r;#N=function(){return`expected to be no more than or equal to ${this.#r}`};#u=this.#N;#s;#E=function(){return`expected to be equal to ${this.#s}`};#n=this.#E;#t=!0;#l=function(){return"is not expected to be NaN"};#o=this.#l;#d=!0;#T=function(){return"is expected to be a finite number"};#m=this.#T;#h=!0;#i=function(){return"is expected to be an integer"};#c=this.#i;static create(e){return new i({type:"number",...e})}constructor(e){super(e),typeof e.min=="number"&&(this.#e=e.min),this.#a=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#b),typeof e.max=="number"&&(this.#r=e.max),this.#u=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#N),typeof e.ensureNotNaN=="boolean"&&(this.#t=e.ensureNotNaN),this.#o=this.assureValidationErrorMessageProvider(e.ensureNotNaNErrorMessageProvider,this.#l),typeof e.ensureIsFinite=="boolean"&&(this.#d=e.ensureIsFinite),this.#m=this.assureValidationErrorMessageProvider(e.ensureIsFiniteErrorMessageProvider,this.#T),typeof e.isInteger=="boolean"&&(this.#h=e.isInteger),this.#c=this.assureValidationErrorMessageProvider(e.ensureIsIntegerErrorMessageProvider,this.#i),(typeof e.equalsTo=="number"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#n=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#E)}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#a,max:this.#r,maxValidationErrorMessageProvider:this.#u,ensureNotNaN:this.#t,ensureNotNaNErrorMessageProvider:this.#o,ensureIsFinite:this.#d,ensureIsFiniteErrorMessageProvider:this.#m,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#n,isInteger:this.#h,ensureIsIntegerErrorMessageProvider:this.#c,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#f(e){return typeof e!="number"?{message:`expected type number, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#n}:this.#t&&Number.isNaN(e)?{provider:this.#o}:this.#d&&!Number.isFinite(e)&&this.#t&&!Number.isNaN(e)?{provider:this.#m}:this.#h&&!Number.isNaN(e)&&Number.isFinite(e)&&!Number.isInteger(e)?{provider:this.#c}:typeof this.#e<"u"&&e<this.#e?{provider:this.#a}:typeof this.#r<"u"&&e>this.#r?{provider:this.#u}:null}#R(e){let{valid:r,transaction:s,errors:t}=e;if(!r)return{done:!0,result:{valid:r,errors:t}};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:a}};let u=this.#f(a);return u?"message"in u?{done:!0,result:{valid:!1,errors:[{message:u.message}]}}:{done:!1,provider:u.provider,objToValidate:a}:{done:!0,result:{valid:!0,object:s.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let t=this.#f(e);return t?"message"in t?{valid:!1,errors:[{message:t.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,e)}]}:{valid:!0,object:e}}let s=this.#R(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#R(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return i.create(e)}equals(e,r){if(typeof e!="number")throw new Error("number expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}isFloat(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}clearIsInteger(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}isInteger(e){return this.createFromProps({...this.introspect(),isInteger:!0,ensureIsIntegerErrorMessageProvider:e})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}notNaN(e){return this.createFromProps({...this.introspect(),ensureNotNaN:!0,ensureNotNaNErrorMessageProvider:e})}canBeNaN(){return this.createFromProps({...this.introspect(),ensureNotNaN:!1,ensureNotNaNErrorMessageProvider:this.#l})}isFinite(e){return this.createFromProps({...this.introspect(),ensureIsFinite:!0,ensureIsFiniteErrorMessageProvider:e})}canBeInfinite(){return this.createFromProps({...this.introspect(),ensureIsFinite:!1,ensureIsFiniteErrorMessageProvider:this.#T})}coerce(){return this.addPreprocessor((e=>typeof e=="string"?Number(e):e),{mutates:!0})}min(e,r){if(typeof e!="number")throw new Error("minValue must be a number");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(typeof e!="number")throw new Error("maxValue must be a number");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}};function d(i){return typeof i=="number"?n.create({isRequired:!0,equalsTo:i}):n.create({isRequired:!0})}export{n as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-PUWIYD4T.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as o}from"./chunk-G6HTNXRO.js";var l=class a extends o{#t;#T=function(){return`is expected to have a length of at least ${this.#t} characters`};#n=this.#T;#i;#g=function(){return`is expected to have a length of no more than ${this.#i} characters`};#l=this.#g;#s;#c=function(e){return`is expected to be equal to "${this.#s}" but saw "${e}"`};#o=this.#c;#e;#m=function(){return`is expected to start with "${this.#e}"`};#u=this.#m;#r;#E=function(){return`is expected to end with "${this.#r}"`};#d=this.#E;#a;#f=function(){return`is expected to match the pattern ${this.#a}`};#h=this.#f;static create(e){return new a({type:"string",...e})}constructor(e){super(e),typeof e.minLength=="number"&&(this.#t=e.minLength),this.#n=this.assureValidationErrorMessageProvider(e.minLengthValidationErrorMessageProvider,this.#T),typeof e.maxLength=="number"&&(this.#i=e.maxLength),this.#l=this.assureValidationErrorMessageProvider(e.maxLengthValidationErrorMessageProvider,this.#g),(typeof e.equalsTo=="string"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#o=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#c),typeof e.startsWith=="string"&&e.startsWith.length>0&&(this.#e=e.startsWith),this.#u=this.assureValidationErrorMessageProvider(e.startsWithValidationErrorMessageProvider,this.#m),typeof e.endsWith=="string"&&e.endsWith.length>0&&(this.#r=e.endsWith),this.#d=this.assureValidationErrorMessageProvider(e.endsWithValidationErrorMessageProvider,this.#E),e.matches instanceof RegExp&&(this.#a=e.matches),this.#h=this.assureValidationErrorMessageProvider(e.matchesValidationErrorMessageProvider,this.#f)}introspect(){return{...super.introspect(),minLength:this.#t,minLengthValidationErrorMessageProvider:this.#n,maxLength:this.#i,maxLengthValidationErrorMessageProvider:this.#l,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#o,startsWith:this.#e,startsWithValidationErrorMessageProvider:this.#u,endsWith:this.#r,endsWithValidationErrorMessageProvider:this.#d,matches:this.#a,matchesValidationErrorMessageProvider:this.#h,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#R(e){return typeof e!="string"?{message:`expected type string, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#o}:typeof this.#e=="string"&&this.#e.length>0&&!e.startsWith(this.#e)?{provider:this.#u}:typeof this.#r=="string"&&this.#r.length>0&&!e.endsWith(this.#r)?{provider:this.#d}:typeof this.#t<"u"&&e.length<this.#t?{provider:this.#n}:typeof this.#i<"u"&&e.length>this.#i?{provider:this.#l}:this.#a instanceof RegExp&&!this.#a.test(e)?{provider:this.#h}:null}#p(e){let{valid:r,transaction:t,errors:i}=e;if(!r)return{done:!0,result:{valid:r,errors:i}};let{object:{validatedObject:s}}=t;if(typeof s>"u"&&!this.isRequired||s===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:s}};let n=this.#R(s);return n?"message"in n?{done:!0,result:{valid:!1,errors:[{message:n.message}]}}:{done:!1,provider:n.provider,objToValidate:s}:{done:!0,result:{valid:!0,object:s}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let i=this.#R(e);return i?"message"in i?{valid:!1,errors:[{message:i.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(i.provider,e)}]}:{valid:!0,object:e}}let t=this.#p(this.preValidateSync(e,r));return t.done?t.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,t.objToValidate)}]}}async _validateAsync(e,r){let t=this.#p(await super.preValidateAsync(e,r));return t.done?t.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(t.provider,t.objToValidate)}]}}createFromProps(e){return a.create(e)}equals(e,r){if(typeof e!="string")throw new Error("string expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}minLength(e,r){if(typeof e!="number")throw new Error("length must be a number");return this.createFromProps({...this.introspect(),minLength:e,minLengthValidationErrorMessageProvider:r})}clearMinLength(){let e=this.introspect();return delete e.minLength,this.createFromProps({...e})}maxLength(e,r){if(typeof e!="number")throw new Error("length must be a number");return this.createFromProps({...this.introspect(),maxLength:e,maxLengthValidationErrorMessageProvider:r})}clearMaxLength(){let e=this.introspect();return delete e.maxLength,this.createFromProps({...e})}startsWith(e,r){if(typeof e!="string"||!e)throw new Error("non empty string expected");return this.createFromProps({...this.introspect(),startsWith:e,startsWithValidationErrorMessageProvider:r})}clearStartsWith(){let e=this.introspect();return delete e.startsWith,this.createFromProps({...e})}endsWith(e,r){if(typeof e!="string"||!e)throw new Error("non empty string expected");return this.createFromProps({...this.introspect(),endsWith:e,endsWithValidationErrorMessageProvider:r})}clearEndsWith(){let e=this.introspect();return delete e.endsWith,this.createFromProps({...e})}matches(e,r){if(!(e instanceof RegExp))throw new Error("regexp expected");return this.createFromProps({...this.introspect(),matches:e,matchesValidationErrorMessageProvider:r})}clearMatches(){let e=this.introspect();return delete e.matches,this.createFromProps({...e})}};function d(a,e){return typeof a=="string"?l.create({isRequired:!0,equalsTo:a,equalsToValidationErrorMessageProvider:e}):l.create({isRequired:!0})}export{l as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-QG254RGI.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d as p,f as h}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{d as p,f as h}from"./chunk-G6HTNXRO.js";function S(s){return typeof s=="object"&&s!==null&&"key"in s?String(s.key):String(s)}function m(s){return s.map(S).join(".")}var T=class s extends h{#e;[p]=!0;static create(e){return new s({type:"extern",...e})}constructor(e){super(e),this.#e=e.standardSchema}get standardSchema(){return this.#e}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#a(e){return e.map(t=>({message:t.path&&t.path.length>0?`${m(t.path)}: ${t.message}`:t.message}))}#t(e,t){let i=new Map,o=[];for(let r of e)if(r.path&&r.path.length>0){let a=S(r.path[0]),d=r.path.slice(1),c=d.length>0?`${m(d)}: ${r.message}`:r.message;i.has(a)||(i.set(a,[]),o.push(a)),i.get(a).push(c)}let l=new WeakMap,n=t?.currentPropertyDescriptor;if(n)for(let r of o){let a=n[r];a&&typeof a=="object"&&l.set(a,r)}return{fn:r=>{let a;if(typeof r=="function"?a=r(n):a=n,!a||typeof a!="object")return{isValid:!0,errors:[]};let d=l.get(a),c=d?i.get(d)||[]:[];return{isValid:c.length===0,errors:c}},errorPropertyNames:o}}validate(e,t){return super.validate(e,t)}async validateAsync(e,t){return super.validateAsync(e,t)}_validate(e,t){let i=this.preValidateSync(e,t);if(!i.valid)return{valid:!1,errors:i.errors};let{transaction:o}=i,l=o.object.validatedObject;if(l==null)return{valid:!0,object:l};let n=this.#e["~standard"].validate(l);if(n instanceof Promise)throw new Error("The external Standard Schema returned a Promise from validate(). Use validateAsync() for schemas with async validation.");if("value"in n){let{fn:a}=this.#t([],t);return{valid:!0,object:n.value,getErrorsFor:a}}let{fn:u,errorPropertyNames:r}=this.#t(n.issues,t);return{valid:!1,errors:this.#a(n.issues),getErrorsFor:u,__externErrorPropertyNames:r}}async _validateAsync(e,t){let i=await this.preValidateAsync(e,t);if(!i.valid)return{valid:!1,errors:i.errors};let{transaction:o}=i,l=o.object.validatedObject;if(l==null)return{valid:!0,object:l};let n=await this.#e["~standard"].validate(l);if("value"in n){let{fn:a}=this.#t([],t);return{valid:!0,object:n.value,getErrorsFor:a}}let{fn:u,errorPropertyNames:r}=this.#t(n.issues,t);return{valid:!1,errors:this.#a(n.issues),getErrorsFor:u,__externErrorPropertyNames:r}}createFromProps(e){return s.create(e)}introspect(){return{...super.introspect(),standardSchema:this.#e}}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},f=s=>T.create({isRequired:!0,standardSchema:s});export{T as a,f as b};
|
|
2
|
+
//# sourceMappingURL=chunk-QWYVMYJ2.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as m}from"./chunk-4RMOR7SV.js";import{c as f,f as S}from"./chunk-G6HTNXRO.js";function x(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function P(o,e){let r=o;for(let a of e.split(".")){if(r==null)return;r=r[a]}return r}function b(o){let e=[];function r(a){return new Proxy(a,{get(t,s){if(s===f)return t[f];if(typeof s!="string")return t[s];let l=t[s];return typeof l!="object"||l===null?l:(e.push(s),r(l))}})}return{proxy:r(o),getPath:()=>e}}var R=class o extends S{#n;#e;#t=null;static create(e){return new o({type:"parseString",...e})}constructor(e){super(e),this.#n=e.objectSchema,this.#e=e.templateDefinition}#s(){if(this.#t)return this.#t;let{literals:e,segments:r}=this.#e,a="^";for(let t=0;t<r.length;t++){a+=x(e[t]);let s=t===r.length-1,l=e[t+1]??"";a+=s&&l===""?"(.*)":"(.*?)"}return a+=x(e[r.length]??""),a+="$",this.#t=new RegExp(a),this.#t}#r(){let{literals:e,segments:r}=this.#e,a="";for(let t=0;t<r.length;t++)a+=e[t]+`{${r[t].path}}`;return a+=e[r.length]??"",a}get template(){return this.#r()}introspect(){return{...super.introspect(),objectSchema:this.#n,templateDefinition:this.#e}}serialize(e){let{literals:r,segments:a}=this.#e,t="";for(let s=0;s<a.length;s++){t+=r[s];let l=a[s].path,d=P(e,l);if(d==null)throw new Error(`Missing required parameter "${l}" for template ${this.#r()}`);t+=String(d)}return t+=r[a.length]??"",t}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){return typeof e>"u"||e===null?typeof e>"u"&&this.hasDefault?(e=this.resolveDefaultValue(),{valid:!0,object:e}):!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]}:this.#a(e,r,(a,t)=>a.validate(t))}async _validateAsync(e,r){return typeof e>"u"||e===null?typeof e>"u"&&this.hasDefault?(e=this.resolveDefaultValue(),{valid:!0,object:e}):!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:await this.getValidationErrorMessage(this.requiredErrorMessage,e)}]}:this.#a(e,r,(a,t)=>a.validateAsync(t))}#a(e,r,a){if(typeof e!="string")return{valid:!1,errors:[{message:`expected a string to parse, but saw ${typeof e}`}]};let{segments:t}=this.#e;if(t.length===0){let n=this.#e.literals[0]??"";return e!==n?{valid:!1,errors:[{message:`expected "${n}" but saw "${e}"`}]}:{valid:!0,object:{}}}let l=this.#s().exec(e);if(!l)return{valid:!1,errors:[{message:`does not match the parse-string pattern ${this.#r()}`}]};let d=r?.doNotStopOnFirstError??!1,p=new Proxy([],{get:(n,u,c)=>{if(u==="length")return t.length;let i=typeof u=="string"?Number(u):Number.NaN;return Number.isInteger(i)&&i>=0&&i<t.length?(i in n||(n[i]=a(t[i].schema,l[i+1])),n[i]):Reflect.get(n,u,c)}});if(d)for(let n=0;n<t.length;n++)p[n];let g=p[0];if(g&&typeof g.then=="function")return(async()=>{let n=[],u={};for(let c=0;c<t.length;c++){let i=await p[c];if(!i.valid){let h=i.errors?.[0]?.message??"validation failed";if(n.push({message:`${t[c].path}: ${h}`}),!d)return{valid:!1,errors:n};continue}t[c].descriptor.setValue(u,i.object,{createMissingStructure:!0})}return n.length>0?{valid:!1,errors:n}:{valid:!0,object:u}})();let y=[],T={};for(let n=0;n<t.length;n++){let u=p[n];if(!u.valid){let c=u.errors?.[0]?.message??"validation failed";if(y.push({message:`${t[n].path}: ${c}`}),!d)return{valid:!1,errors:y};continue}t[n].descriptor.setValue(T,u.object,{createMissingStructure:!0})}return y.length>0?{valid:!1,errors:y}:{valid:!0,object:T}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}createFromProps(e){return o.create(e)}};function v(o,e){if(!(o instanceof m))throw new Error("First argument must be an ObjectSchemaBuilder instance");let r=m.getPropertiesFor(o),t=e(((s,...l)=>{let d=new Set,p=[];for(let g of l){if(typeof g!="function")throw new Error("Template expressions must be property selector functions (e.g. t => t.id)");let{proxy:y,getPath:T}=b(r),n=g(y);if(!n||typeof n!="object"||!(f in n))throw new Error("Template expression must select a property from the schema (e.g. t => t.id)");let u=n[f],c=u.getSchema(),i=T();if(i.length===0)throw new Error("Template expression must select a specific property (e.g. t => t.id), not the root object");let h=i.join(".");if(d.has(h))throw new Error(`Duplicate template parameter: "${h}" is already used in this template`);d.add(h),p.push({schema:c,path:h,descriptor:u})}return{literals:[...s],segments:p}}));return R.create({isRequired:!0,objectSchema:o,templateDefinition:t})}export{R as a,v as b};
|
|
2
|
+
//# sourceMappingURL=chunk-SY5EYKF2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/builders/ParseStringSchemaBuilder.ts"],"sourcesContent":["import { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';\nimport {\n type BRAND,\n type InferType,\n type PropertyDescriptor,\n type PropertyDescriptorInner,\n type PropertyDescriptorTree,\n SchemaBuilder,\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR,\n type ValidationContext,\n type ValidationErrorMessageProvider,\n type ValidationResult\n} from './SchemaBuilder.js';\n\n// ---------------------------------------------------------------------------\n// Internal types\n// ---------------------------------------------------------------------------\n\n/** Descriptor for a single interpolation segment captured at creation time. */\ntype SegmentDef = {\n /** The property schema for this segment. */\n schema: SchemaBuilder<any, any, any, any, any>;\n /** Dot-separated property path (e.g. `'order.id'`) — used in error messages. */\n path: string;\n /** The property descriptor inner — used to set parsed values on the result object. */\n descriptor: PropertyDescriptorInner<any, any, any>;\n};\n\n/** Internal data captured by the `$template` tagged-template invocation. */\ntype ParseStringTemplateDefinition = {\n /** Literal string fragments from the tagged template. */\n literals: readonly string[];\n /** One segment per interpolation expression, in order. */\n segments: readonly SegmentDef[];\n};\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\n/**\n * The typed tagged-template function passed to the `parseString`\n * callback. Template expressions must be property-selector lambdas that\n * navigate the {@link PropertyDescriptorTree} of the object schema.\n *\n * Only properties whose inferred type extends `string | number | boolean | Date`\n * are selectable — nested `ObjectSchemaBuilder` children are navigable but\n * not themselves endpoints.\n */\nexport type ParseStringTemplateTag<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n> = (\n strings: TemplateStringsArray,\n ...selectors: Array<\n (\n tree: PropertyDescriptorTree<\n TSchema,\n TSchema,\n string | number | boolean | Date\n >\n ) => PropertyDescriptor<TSchema, any, any>\n >\n) => ParseStringTemplateDefinition;\n\ntype ParseStringSchemaBuilderCreateProps<\n T = any,\n R extends boolean = true\n> = Partial<ReturnType<ParseStringSchemaBuilder<T, R>['introspect']>>;\n\n// ---------------------------------------------------------------------------\n// Regex helper\n// ---------------------------------------------------------------------------\n\n/** Escapes characters that have special meaning in a regular expression. */\nfunction escapeRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n/**\n * Resolves a dot-separated property path on a (possibly nested) object.\n *\n * For flat paths like `'id'` this is equivalent to `obj['id']`.\n * For nested paths like `'order.id'` it traverses `obj.order.id`.\n */\nfunction resolvePath(obj: any, path: string): unknown {\n let current: any = obj;\n for (const part of path.split('.')) {\n if (current == null) return undefined;\n current = current[part];\n }\n return current;\n}\n\n// ---------------------------------------------------------------------------\n// Path-tracking Proxy (used at schema creation time)\n// ---------------------------------------------------------------------------\n\n/**\n * Wraps a `PropertyDescriptorTree` in a Proxy that records the traversed\n * property path. When the result is accessed via\n * `SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR` we know we've reached a leaf, so we\n * return the real descriptor. All other property accesses are captured as\n * path segments and the proxy recurses.\n *\n * @returns A proxy that looks identical to the tree from TypeScript's\n * perspective but captures `[propName, propName, …]` as the user\n * navigates via `t => t.order.id`.\n */\nfunction createPathTrackingProxy(tree: any): {\n proxy: any;\n getPath: () => string[];\n} {\n // Shared mutable array — child proxy pushes propagate to parent's getPath\n const pathSegments: string[] = [];\n\n function wrapProxy(target: any): any {\n return new Proxy(target, {\n get(t, prop) {\n // Property descriptor access — return real descriptor\n if (prop === SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR) {\n return t[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR];\n }\n\n // Symbol / non-string — pass through\n if (typeof prop !== 'string') {\n return t[prop];\n }\n\n const child = t[prop];\n if (typeof child !== 'object' || child === null) {\n return child;\n }\n\n // Record this segment and recurse\n pathSegments.push(prop);\n return wrapProxy(child);\n }\n });\n }\n\n return {\n proxy: wrapProxy(tree),\n getPath: () => pathSegments\n };\n}\n\n// ---------------------------------------------------------------------------\n// Builder\n// ---------------------------------------------------------------------------\n\n/**\n * Validates a string against a template pattern and parses it\n * into a strongly-typed object.\n *\n * Created via the {@link parseString} factory:\n *\n * ```ts\n * const RouteSchema = parseString(\n * object({ userId: string().uuid(), id: number() }),\n * $t => $t`/orders/${t => t.id}/${t => t.userId}`\n * );\n *\n * const result = RouteSchema.validate('/orders/42/550e8400-...');\n * // result.object === { id: 42, userId: '550e8400-...' }\n * ```\n *\n * @see {@link parseString}\n */\nexport class ParseStringSchemaBuilder<\n TResult = any,\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n THasDefault extends boolean = false,\n TExtensions = {}\n> extends SchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n> {\n #objectSchema: ObjectSchemaBuilder<any, any, any, any, any, any, any>;\n #templateDef: ParseStringTemplateDefinition;\n #compiledRegex: RegExp | null = null;\n\n /**\n * @hidden\n */\n public static create(props: ParseStringSchemaBuilderCreateProps) {\n return new ParseStringSchemaBuilder({\n type: 'parseString',\n ...props\n });\n }\n\n protected constructor(props: ParseStringSchemaBuilderCreateProps) {\n super(props as any);\n\n this.#objectSchema = props.objectSchema!;\n this.#templateDef = props.templateDefinition!;\n }\n\n // -- Regex ---------------------------------------------------------------\n\n #buildRegex(): RegExp {\n if (this.#compiledRegex) return this.#compiledRegex;\n const { literals, segments } = this.#templateDef;\n let pattern = '^';\n for (let i = 0; i < segments.length; i++) {\n pattern += escapeRegex(literals[i]);\n // Use non-greedy unless this is the last capture AND the\n // trailing literal is empty (nothing to anchor to).\n const isLast = i === segments.length - 1;\n const trailingLiteral = literals[i + 1] ?? '';\n pattern += isLast && trailingLiteral === '' ? '(.*)' : '(.*?)';\n }\n // Append the trailing literal (after all segments)\n pattern += escapeRegex(literals[segments.length] ?? '');\n pattern += '$';\n this.#compiledRegex = new RegExp(pattern);\n return this.#compiledRegex;\n }\n\n /** Builds a human-readable pattern like `/orders/{id}/{userId}` for error messages. */\n #humanPattern(): string {\n const { literals, segments } = this.#templateDef;\n let result = '';\n for (let i = 0; i < segments.length; i++) {\n result += literals[i] + `{${segments[i].path}}`;\n }\n result += literals[segments.length] ?? '';\n return result;\n }\n\n /**\n * The human-readable message template pattern with `{property}` holes,\n * e.g. `\"Todo created: #{TodoId} \\\"{Title}\\\" by user {UserId}\"`.\n *\n * Useful for structured logging — pass this as the log `messageTemplate`\n * so events with the same shape can be grouped, and pass\n * `serialize(params)` as the rendered message.\n */\n get template(): string {\n return this.#humanPattern();\n }\n\n // -- Introspect ----------------------------------------------------------\n\n /**\n * Return a snapshot of this builder's configuration.\n *\n * Includes all base-class fields plus:\n * - `objectSchema` — the object schema defining the result shape.\n * - `templateDefinition` — the parsed template (literals and selector segments).\n */\n public introspect() {\n return {\n ...super.introspect(),\n /** The object schema defining the result shape. */\n objectSchema: this.#objectSchema,\n /** The template definition (literals + segments). */\n templateDefinition: this.#templateDef\n };\n }\n\n // -- Serialize -----------------------------------------------------------\n\n /**\n * Builds a string from the template by substituting parameter values.\n *\n * This is the reverse of {@link validate}: where `validate` parses a\n * string into a typed object, `serialize` takes a params object and\n * produces the string.\n *\n * @param params - An object matching the template's parsed result type.\n * Nested properties are resolved via dot-paths (e.g. `order.id`).\n * Values are coerced to strings via `String()`.\n * @returns The reconstructed string with all segments replaced.\n * @throws {Error} If a required parameter is missing (`undefined`).\n *\n * @example\n * ```ts\n * const Route = parseString(\n * object({ id: number().coerce() }),\n * $t => $t`/todos/${t => t.id}`\n * );\n *\n * Route.serialize({ id: 42 }); // '/todos/42'\n * ```\n */\n public serialize(params: TResult): string {\n const { literals, segments } = this.#templateDef;\n let result = '';\n for (let i = 0; i < segments.length; i++) {\n result += literals[i];\n const key = segments[i].path;\n const value = resolvePath(params, key);\n if (value === undefined || value === null) {\n throw new Error(\n `Missing required parameter \"${key}\" for template ${this.#humanPattern()}`\n );\n }\n result += String(value);\n }\n result += literals[segments.length] ?? '';\n return result;\n }\n\n // -- Validate (sync) -----------------------------------------------------\n\n /** {@inheritDoc SchemaBuilder.validate} */\n public validate(\n object: string,\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: string,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return super.validateAsync(object, context) as Promise<\n ValidationResult<TResult>\n >;\n }\n\n protected _validate(\n object: any,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n // Handle optional / nullable / default at the top\n if (typeof object === 'undefined' || object === null) {\n if (typeof object === 'undefined' && this.hasDefault) {\n object = this.resolveDefaultValue();\n return { valid: true, object: object as TResult };\n }\n if (!this.isRequired || (object === null && this.isNullable)) {\n return { valid: true, object: object as any };\n }\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n this.requiredErrorMessage,\n object\n )\n }\n ]\n };\n }\n\n return this.#matchAndValidate(object, context, (schema, raw) =>\n schema.validate(raw)\n );\n }\n\n // -- Validate (async) ----------------------------------------------------\n\n protected async _validateAsync(\n object: any,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n // Handle optional / nullable / default\n if (typeof object === 'undefined' || object === null) {\n if (typeof object === 'undefined' && this.hasDefault) {\n object = this.resolveDefaultValue();\n return { valid: true, object: object as TResult };\n }\n if (!this.isRequired || (object === null && this.isNullable)) {\n return { valid: true, object: object as any };\n }\n return {\n valid: false,\n errors: [\n {\n message: await this.getValidationErrorMessage(\n this.requiredErrorMessage,\n object\n )\n }\n ]\n };\n }\n\n return this.#matchAndValidate(object, context, (schema, raw) =>\n schema.validateAsync(raw)\n );\n }\n\n /**\n * Shared regex-match + per-segment validation logic used by both\n * `_validate` (sync) and `_validateAsync` (async).\n *\n * The caller supplies `validateSegment` which is either the sync\n * `schema.validate` or async `schema.validateAsync`.\n */\n #matchAndValidate<\n R extends ValidationResult<unknown> | Promise<ValidationResult<unknown>>\n >(\n object: any,\n context: ValidationContext | undefined,\n validateSegment: (\n schema: SchemaBuilder<any, any, any, any, any>,\n raw: string\n ) => R\n ): R extends Promise<any>\n ? Promise<ValidationResult<TResult>>\n : ValidationResult<TResult> {\n if (typeof object !== 'string') {\n return {\n valid: false,\n errors: [\n {\n message: `expected a string to parse, but saw ${typeof object}`\n }\n ]\n } as any;\n }\n\n const { segments } = this.#templateDef;\n\n // Degenerate case: no segments — just compare literals\n if (segments.length === 0) {\n const expected = this.#templateDef.literals[0] ?? '';\n if (object !== expected) {\n return {\n valid: false,\n errors: [\n {\n message: `expected \"${expected}\" but saw \"${object}\"`\n }\n ]\n } as any;\n }\n return { valid: true, object: {} as TResult } as any;\n }\n\n const regex = this.#buildRegex();\n const match = regex.exec(object);\n\n if (!match) {\n return {\n valid: false,\n errors: [\n {\n message: `does not match the parse-string pattern ${this.#humanPattern()}`\n }\n ]\n } as any;\n }\n\n const doNotStop = context?.doNotStopOnFirstError ?? false;\n\n // Compute segment validation results lazily so fail-fast mode can\n // short-circuit without eagerly validating later segments. When\n // doNotStopOnFirstError is enabled, prestart all validations to\n // preserve the existing eager/parallel behavior.\n const segResults = new Proxy([] as R[], {\n get: (target, prop, receiver) => {\n if (prop === 'length') return segments.length;\n\n const index =\n typeof prop === 'string' ? Number(prop) : Number.NaN;\n if (\n Number.isInteger(index) &&\n index >= 0 &&\n index < segments.length\n ) {\n if (!(index in target)) {\n target[index] = validateSegment(\n segments[index].schema,\n match[index + 1]\n );\n }\n return target[index];\n }\n\n return Reflect.get(target, prop, receiver);\n }\n }) as R[];\n\n if (doNotStop) {\n for (let i = 0; i < segments.length; i++) {\n void segResults[i];\n }\n }\n\n // If first result is a promise, the whole pipeline is async\n const firstResult = segResults[0];\n if (firstResult && typeof (firstResult as any).then === 'function') {\n return (async () => {\n const errors: { message: string }[] = [];\n const resultObj = {} as any;\n for (let i = 0; i < segments.length; i++) {\n const segResult = (await segResults[\n i\n ]) as ValidationResult<unknown>;\n if (!segResult.valid) {\n const inner =\n segResult.errors?.[0]?.message ??\n 'validation failed';\n errors.push({\n message: `${segments[i].path}: ${inner}`\n });\n if (!doNotStop) return { valid: false, errors };\n continue;\n }\n segments[i].descriptor.setValue(\n resultObj,\n segResult.object,\n { createMissingStructure: true }\n );\n }\n if (errors.length > 0) return { valid: false, errors };\n return { valid: true, object: resultObj as TResult };\n })() as any;\n }\n\n // Sync path\n const errors: { message: string }[] = [];\n const resultObj = {} as any;\n for (let i = 0; i < segments.length; i++) {\n const segResult = segResults[i] as ValidationResult<unknown>;\n if (!segResult.valid) {\n const inner =\n segResult.errors?.[0]?.message ?? 'validation failed';\n errors.push({\n message: `${segments[i].path}: ${inner}`\n });\n if (!doNotStop) return { valid: false, errors } as any;\n continue;\n }\n segments[i].descriptor.setValue(resultObj, segResult.object, {\n createMissingStructure: true\n });\n }\n if (errors.length > 0) return { valid: false, errors } as any;\n return { valid: true, object: resultObj as TResult } as any;\n }\n\n // -- Fluent overrides (return type narrowing) ----------------------------\n\n /**\n * @inheritdoc\n */\n public hasType<T>(\n _notUsed?: T\n ): ParseStringSchemaBuilder<T, true, TNullable, THasDefault, TExtensions> &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n /**\n * @inheritdoc\n */\n public clearHasType(): ParseStringSchemaBuilder<\n any,\n TRequired,\n TNullable,\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 nullable(): ParseStringSchemaBuilder<\n TResult,\n TRequired,\n true,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.nullable() as any;\n }\n\n /**\n * @hidden\n */\n public notNullable(): ParseStringSchemaBuilder<\n TResult,\n TRequired,\n false,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.notNullable() as any;\n }\n\n /**\n * @hidden\n */\n public required(\n errorMessage?: ValidationErrorMessageProvider\n ): ParseStringSchemaBuilder<\n TResult,\n true,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.required(errorMessage);\n }\n\n /**\n * @hidden\n */\n public optional(): ParseStringSchemaBuilder<\n TResult,\n false,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.optional();\n }\n\n /**\n * @hidden\n */\n public default(\n value: TResult | (() => TResult)\n ): ParseStringSchemaBuilder<TResult, true, TNullable, true, TExtensions> &\n TExtensions {\n return super.default(value) as any;\n }\n\n /**\n * @hidden\n */\n public clearDefault(): ParseStringSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\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 ): ParseStringSchemaBuilder<\n TResult & { readonly [K in BRAND]: TBrand },\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.brand(_name);\n }\n\n /**\n * @hidden\n */\n public readonly(): ParseStringSchemaBuilder<\n Readonly<TResult>,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.readonly();\n }\n\n protected createFromProps<T, TReq extends boolean>(\n props: ParseStringSchemaBuilderCreateProps<T, TReq>\n ): this {\n return ParseStringSchemaBuilder.create(props as any) as any;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a parse-string schema that validates a string against a\n * template pattern and parses it into a strongly-typed object.\n *\n * The first argument defines the result shape via `object(...)`, and the\n * second argument is a callback receiving a typed `$template` tagged-template\n * function whose template expressions are type-safe property selectors.\n *\n * @example\n * ```ts\n * const RouteSchema = parseString(\n * object({\n * userId: string().uuid(),\n * id: number()\n * }),\n * $t => $t`/orders/${t => t.id}/${t => t.userId}`\n * );\n *\n * const result = RouteSchema.validate('/orders/42/550e8400-e29b-41d4-a716-446655440000');\n * // result.valid === true\n * // result.object === { id: 42, userId: '550e8400-e29b-41d4-a716-446655440000' }\n *\n * type Route = InferType<typeof RouteSchema>;\n * // { id: number; userId: string }\n * ```\n *\n * @example Nested objects\n * ```ts\n * const schema = parseString(\n * object({\n * order: object({ id: number() }),\n * user: object({ name: string() })\n * }),\n * $t => $t`/orders/${t => t.order.id}/by/${t => t.user.name}`\n * );\n * ```\n *\n * @param objectSchema - An `ObjectSchemaBuilder` defining the result type and\n * per-property validation schemas.\n * @param templateBuilder - Callback receiving the typed `$template`\n * tagged-template function. Must return the result of invoking `$template`.\n * @returns A `ParseStringSchemaBuilder` whose `validate()` accepts a\n * string and whose `InferType` is the object schema's inferred type.\n */\nexport function parseString<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n>(\n objectSchema: TSchema,\n templateBuilder: (\n $template: ParseStringTemplateTag<TSchema>\n ) => ParseStringTemplateDefinition\n): ParseStringSchemaBuilder<InferType<TSchema>> {\n if (!(objectSchema instanceof ObjectSchemaBuilder)) {\n throw new Error(\n 'First argument must be an ObjectSchemaBuilder instance'\n );\n }\n\n // Get the PropertyDescriptorTree for the object schema\n const tree = ObjectSchemaBuilder.getPropertiesFor(objectSchema as any);\n\n // Build the $template tagged-template function\n const $template = ((\n strings: TemplateStringsArray,\n ...selectors: Array<(t: any) => any>\n ): ParseStringTemplateDefinition => {\n const seenPaths = new Set<string>();\n const segments: SegmentDef[] = [];\n\n for (const selector of selectors) {\n if (typeof selector !== 'function') {\n throw new Error(\n 'Template expressions must be property selector functions (e.g. t => t.id)'\n );\n }\n\n // Create a path-tracking proxy for this selector invocation\n const { proxy, getPath } = createPathTrackingProxy(tree);\n const descriptor = selector(proxy);\n\n if (\n !descriptor ||\n typeof descriptor !== 'object' ||\n !(SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR in descriptor)\n ) {\n throw new Error(\n 'Template expression must select a property from the schema (e.g. t => t.id)'\n );\n }\n\n const inner: PropertyDescriptorInner<any, any, any> =\n descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR];\n const schema = inner.getSchema();\n const path = getPath();\n\n if (path.length === 0) {\n throw new Error(\n 'Template expression must select a specific property (e.g. t => t.id), not the root object'\n );\n }\n\n const pathStr = path.join('.');\n\n if (seenPaths.has(pathStr)) {\n throw new Error(\n `Duplicate template parameter: \"${pathStr}\" is already used in this template`\n );\n }\n seenPaths.add(pathStr);\n\n segments.push({\n schema,\n path: pathStr,\n descriptor: inner\n });\n }\n\n return {\n literals: [...strings],\n segments\n };\n }) as ParseStringTemplateTag<TSchema>;\n\n const templateDef = templateBuilder($template);\n\n return ParseStringSchemaBuilder.create({\n isRequired: true,\n objectSchema: objectSchema as any,\n templateDefinition: templateDef\n }) as any;\n}\n"],"mappings":"uFA0EA,SAASA,EAAYC,EAAmB,CACpC,OAAOA,EAAE,QAAQ,sBAAuB,MAAM,CAClD,CAQA,SAASC,EAAYC,EAAUC,EAAuB,CAClD,IAAIC,EAAeF,EACnB,QAAWG,KAAQF,EAAK,MAAM,GAAG,EAAG,CAChC,GAAIC,GAAW,KAAM,OACrBA,EAAUA,EAAQC,CAAI,CAC1B,CACA,OAAOD,CACX,CAiBA,SAASE,EAAwBC,EAG/B,CAEE,IAAMC,EAAyB,CAAC,EAEhC,SAASC,EAAUC,EAAkB,CACjC,OAAO,IAAI,MAAMA,EAAQ,CACrB,IAAI,EAAGC,EAAM,CAET,GAAIA,IAASC,EACT,OAAO,EAAEA,CAAiC,EAI9C,GAAI,OAAOD,GAAS,SAChB,OAAO,EAAEA,CAAI,EAGjB,IAAME,EAAQ,EAAEF,CAAI,EACpB,OAAI,OAAOE,GAAU,UAAYA,IAAU,KAChCA,GAIXL,EAAa,KAAKG,CAAI,EACfF,EAAUI,CAAK,EAC1B,CACJ,CAAC,CACL,CAEA,MAAO,CACH,MAAOJ,EAAUF,CAAI,EACrB,QAAS,IAAMC,CACnB,CACJ,CAwBO,IAAMM,EAAN,MAAMC,UAMHC,CAMR,CACEC,GACAC,GACAC,GAAgC,KAKhC,OAAc,OAAOC,EAA4C,CAC7D,OAAO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,SAAW,EAChB,MAAM,IAAI,MACN,2FACJ,EAGJ,IAAM8D,EAAU9D,EAAK,KAAK,GAAG,EAE7B,GAAIyD,EAAU,IAAIK,CAAO,EACrB,MAAM,IAAI,MACN,kCAAkCA,CAAO,oCAC7C,EAEJL,EAAU,IAAIK,CAAO,EAErB1C,EAAS,KAAK,CACV,OAAAa,EACA,KAAM6B,EACN,WAAYhB,CAChB,CAAC,CACL,CAEA,MAAO,CACH,SAAU,CAAC,GAAGS,CAAO,EACrB,SAAAnC,CACJ,CACJ,EAE6C,EAE7C,OAAOT,EAAyB,OAAO,CACnC,WAAY,GACZ,aAAcwC,EACd,mBAAoBG,CACxB,CAAC,CACL","names":["escapeRegex","s","resolvePath","obj","path","current","part","createPathTrackingProxy","tree","pathSegments","wrapProxy","target","prop","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","child","ParseStringSchemaBuilder","_ParseStringSchemaBuilder","SchemaBuilder","#objectSchema","#templateDef","#compiledRegex","props","#buildRegex","literals","segments","pattern","i","isLast","trailingLiteral","#humanPattern","result","params","key","value","object","context","#matchAndValidate","schema","raw","validateSegment","expected","match","doNotStop","segResults","receiver","index","firstResult","errors","resultObj","segResult","inner","_notUsed","errorMessage","_name","parseString","objectSchema","templateBuilder","ObjectSchemaBuilder","templateDef","strings","selectors","seenPaths","selector","proxy","getPath","descriptor","pathStr"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as p,e as f,f as T}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as p,e as f,f as T}from"./chunk-G6HTNXRO.js";var m=class h extends T{#e;#t;static create(e){return new h({type:"tuple",...e})}constructor(e){super(e),Array.isArray(e.elements)?this.#e=e.elements:this.#e=[],e.restSchema instanceof T&&(this.#t=e.restSchema)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#a(e){if(e.length<this.#e.length){let l=this.#e.length;return`expected a tuple with at least ${l} element${l===1?"":"s"}, got ${e.length}`}if(!(this.#t instanceof T)&&e.length!==this.#e.length){let l=this.#e.length;return`expected a tuple of exactly ${l} element${l===1?"":"s"}, got ${e.length}`}return null}#n(e,l){let{valid:o,context:r,errors:a,transaction:n}=l,i={[p]:{setValue:()=>!1,getValue:t=>({success:!0,value:t}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},d=[],y=f([],()=>e,()=>d,()=>i[p]),c=(()=>y);if(!o)return d.push(...(a||[]).map(t=>t.message||String(t))),{needsElementValidation:!1,result:{valid:o,errors:a,getNestedErrors:c}};let{object:{validatedObject:u}}=n;return typeof u>"u"&&!this.isRequired||u===null&&(!this.isRequired||this.isNullable)?{needsElementValidation:!1,result:{valid:!0,object:u,getNestedErrors:c}}:Array.isArray(u)?{needsElementValidation:!0,objToValidate:u,prevalidationContext:r,getNestedErrors:c,elementResults:y,rootErrors:d}:(d.push("array expected"),{needsElementValidation:!1,result:{valid:!1,errors:[{message:"array expected"}],getNestedErrors:c}})}#r(e,l,o){let r=!0;for(let a=0;a<e.length;a++)e[a]?.valid||(r=!1),l[a]=e[a];return Object.assign({valid:r,getNestedErrors:o},r?{}:{errors:e.map(a=>a?.errors).filter(a=>a).flatMap(a=>a?.map(n=>({...n})))},r?{object:e.map(a=>a?.object)}:{})}validate(e,l){return super.validate(e,l)}async validateAsync(e,l){return super.validateAsync(e,l)}_validate(e,l){if(this.canSkipPreValidation&&!l?.doNotStopOnFirstError){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let n=this;return{valid:!0,object:e,getNestedErrors(){return n.#s(e,l).getNestedErrors()}}}else return this.#s(e,l);if(!Array.isArray(e))return this.#s(e,l);let o=this.#a(e);if(o){let n=this;return{valid:!1,errors:[{message:o}],getNestedErrors(){return n.#s(e,l).getNestedErrors()}}}let r=new Array(e.length);for(let n=0;n<this.#e.length;n++){let i=this.#e[n].validate(e[n]);if(!i.valid){let d=this;return{valid:!1,errors:i.errors&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors(){return d.#s(e,l).getNestedErrors()}}}r[n]=i.object}if(this.#t instanceof T)for(let n=this.#e.length;n<e.length;n++){let i=this.#t.validate(e[n]);if(!i.valid){let d=this;return{valid:!1,errors:i.errors&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors(){return d.#s(e,l).getNestedErrors()}}}r[n]=i.object}let a=this;return{valid:!0,object:r,getNestedErrors(){return a.#s(e,l).getNestedErrors()}}}return this.#s(e,l)}#s(e,l){let o=this.#n(e,this.preValidateSync(e,l));if(!o.needsElementValidation)return o.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:n,elementResults:i,rootErrors:d}=o,y=this.#a(r);if(y)return d.push(y),{valid:!1,errors:[{message:y}],getNestedErrors:n};let c=this.#t instanceof T?r.length:this.#e.length;if(a.doNotStopOnFirstError){let u=new Array(c);for(let t=0;t<this.#e.length;t++)u[t]=this.#e[t].validate(r[t],{...a});if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++)u[t]=this.#t.validate(r[t],{...a});return this.#r(u,i,n)}else{let u=new Array(c);for(let t=0;t<this.#e.length;t++){let s=this.#e[t].validate(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++){let s=this.#t.validate(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}return{valid:!0,object:u,getNestedErrors:n}}}async _validateAsync(e,l){let o=this.#n(e,await super.preValidateAsync(e,l));if(!o.needsElementValidation)return o.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:n,elementResults:i,rootErrors:d}=o,y=this.#a(r);if(y)return d.push(y),{valid:!1,errors:[{message:y}],getNestedErrors:n};let c=this.#t instanceof T?r.length:this.#e.length;if(a.doNotStopOnFirstError){let u=new Array(c);for(let s=0;s<this.#e.length;s++)u[s]=this.#e[s].validateAsync(r[s],{...a});if(this.#t instanceof T)for(let s=this.#e.length;s<r.length;s++)u[s]=this.#t.validateAsync(r[s],{...a});let t=await Promise.all(u);return this.#r(t,i,n)}else{let u=new Array(c);for(let t=0;t<this.#e.length;t++){let s=await this.#e[t].validateAsync(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++){let s=await this.#t.validateAsync(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}return{valid:!0,object:u,getNestedErrors:n}}}createFromProps(e){return h.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}introspect(){return{...super.introspect(),elements:this.#e,restSchema:this.#t}}rest(e){return h.create({...this.introspect(),restSchema:e})}clearRest(){return h.create({...this.introspect(),restSchema:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},R=h=>m.create({isRequired:!0,elements:h});export{m as a,R as b};
|
|
2
|
+
//# sourceMappingURL=chunk-VRRKXJ2H.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as u,f as l}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as u,f as l}from"./chunk-G6HTNXRO.js";var d=t=>{if(typeof t>"u")return t;if(typeof t=="string"){let e=Date.parse(t);return Number.isNaN(e)?t:new Date(e)}return t},T=t=>{if(typeof t>"u")return t;if(typeof t=="number"){let e=new Date(t);return Number.isNaN(e.getTime())?t:e}return t},o=class t extends l{#e;#c=function(){return`is expected to be after ${this.#e} (${this.#e?.getTime()})`};#i=this.#c;#r;#h=function(){return`is expected to be before ${this.#r} (${this.#r?.getTime()})`};#n=this.#h;#t;#m=function(){return`is expected to be equal ${this.#t} (${this.#t?.getTime()})`};#u=this.#m;#o=!1;#f=function(){return"is expected to be in future"};#l=this.#f;#d=!1;#p=function(){return"is expected to be in past"};#T=this.#p;#s=!1;#a=!1;#E=!0;static create(e){return new t({type:"date",...e})}constructor(e){super(e),e.min instanceof Date&&(this.#e=e.min),this.#i=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#c),e.max instanceof Date&&(this.#r=e.max),this.#n=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#h),typeof e.ensureIsInFuture=="boolean"&&(this.#o=e.ensureIsInFuture),this.#l=this.assureValidationErrorMessageProvider(e.ensureIsInFutureValidationErrorMessageProvider,this.#f),typeof e.ensureIsInPast=="boolean"&&(this.#d=e.ensureIsInPast),this.#T=this.assureValidationErrorMessageProvider(e.ensureIsInPastValidationErrorMessageProvider,this.#p),typeof e.parseFromJson=="boolean"&&(this.#s=e.parseFromJson),typeof e.parseFromEpoch=="boolean"&&(this.#a=e.parseFromEpoch),(e.equalsTo instanceof Date||typeof e.equalsTo>"u")&&(this.#t=e.equalsTo),this.#u=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#m),this.#E=this.canSkipPreValidation&&!this.#s&&!this.#a}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#i,max:this.#r,maxValidationErrorMessageProvider:this.#n,ensureIsInFuture:this.#o,ensureIsInFutureValidationErrorMessageProvider:this.#l,ensureIsInPast:this.#d,ensureIsInPastValidationErrorMessageProvider:this.#T,equalsTo:this.#t,equalsToValidationErrorMessageProvider:this.#u,parseFromEpoch:this.#a,parseFromJson:this.#s,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#R(e){return e instanceof Date?typeof this.#t<"u"&&e.getTime()!==this.#t.getTime()?{provider:this.#u}:this.#o&&e<=new Date?{provider:this.#l}:this.#d&&e>=new Date?{provider:this.#T}:typeof this.#e<"u"&&e<this.#e?{provider:this.#i}:typeof this.#r<"u"&&e>this.#r?{provider:this.#n}:null:{message:`expected instance of Date, but saw ${typeof e}`}}#D(e){let{valid:r,errors:s}=e;if(!r)return{done:!0,result:{valid:r,errors:s}};let{transaction:a}=e,{object:{validatedObject:i}}=a;if(typeof i>"u"&&!this.isRequired||i===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:i}};this.#s&&(a=u({validatedObject:d(i)}),i=a.object.validatedObject),this.#a&&(a=u({validatedObject:T(i)}),i=a.object.validatedObject);let n=this.#R(i);return n?"message"in n?{done:!0,result:{valid:!1,errors:[{message:n.message}]}}:{done:!1,provider:n.provider,objToValidate:i}:{done:!0,result:{valid:!0,object:a.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.#E){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let a=this.#R(e);return a?"message"in a?{valid:!1,errors:[{message:a.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(a.provider,e)}]}:{valid:!0,object:e}}let s=this.#D(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#D(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return t.create(e)}equals(e,r){if(!(e instanceof Date))throw new Error("Date expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}isInFuture(e){return this.createFromProps({...this.introspect(),ensureIsInFuture:!0,ensureIsInFutureValidationErrorMessageProvider:e})}clearIsInFuture(){return this.createFromProps({...this.introspect(),ensureIsInFuture:!1})}isInPast(e){return this.createFromProps({...this.introspect(),ensureIsInPast:!0,ensureIsInPastValidationErrorMessageProvider:e})}clearIsInPast(){return this.createFromProps({...this.introspect(),ensureIsInPast:!1})}min(e,r){if(!(e instanceof Date))throw new Error("minValue must be a Date");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(!(e instanceof Date))throw new Error("maxValue must be a Date");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}coerce(){return this.addPreprocessor((e=>{if(typeof e=="string"){let r=new Date(e);return Number.isNaN(r.getTime())?e:r}return e}),{mutates:!0})}acceptJsonString(){return this.createFromProps({...this.introspect(),parseFromJson:!0})}doNotAcceptJsonString(){return this.createFromProps({...this.introspect(),parseFromJson:!1})}acceptEpoch(){return this.createFromProps({...this.introspect(),parseFromEpoch:!0})}doNotAcceptEpoch(){return this.createFromProps({...this.introspect(),parseFromEpoch:!1})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},m=()=>o.create({isRequired:!0});export{o as a,m as b};
|
|
2
|
+
//# sourceMappingURL=chunk-YYE5HQCL.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as P,b as w}from"./chunk-EBGC6ZBF.js";import{a as B,b as R}from"./chunk-OJJHAZZ4.js";import{a as S,b}from"./chunk-PUWIYD4T.js";import{a as g,b as F}from"./chunk-4RMOR7SV.js";import{a as M,b as A}from"./chunk-FTA66XZT.js";import{a as N,b as D}from"./chunk-57AZDIBB.js";import{a as _,b as v}from"./chunk-QG254RGI.js";import{a as V,b as C}from"./chunk-VRRKXJ2H.js";import{a as c,b as T}from"./chunk-ZHBJ46HB.js";import{a as x,b as p}from"./chunk-3K7MOEPS.js";import{a as m,b as E}from"./chunk-ETJPB3TR.js";import{a as h,b as f}from"./chunk-YYE5HQCL.js";import{f as u}from"./chunk-G6HTNXRO.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-ZC2HTRZF.js.map
|