@arrirpc/schema 0.73.0 → 0.74.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/dist/index.d.ts CHANGED
@@ -1,43 +1,61 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { A as ASchema, I as InferType, S as SafeResult, a as ASchemaOptions, b as AArraySchema, c as AScalarSchema, d as AObjectSchema, e as ADiscriminatorSchema, R as ResolveObject, f as AStringEnumSchema, g as AObjectSchemaOptions, h as InferObjectOutput, V as ValidationContext, i as ARecordSchema, j as ARefSchema, k as coerce, l as errors, m as InferSubType, p as parse, s as safeCoerce, n as safeParse, o as serialize, v as validate } from './shared/schema.DLX0nTwB.js';
3
- export { K as InferObjectRawType, M as MaybeNullable, D as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as SCHEMA_METADATA, y as SchemaMetadata, x as SchemaValidator, t as ValidationError, r as ValueError, E as isAAraySchema, G as isADiscriminatorSchema, J as isAObjectSchema, H as isARecordSchema, O as isARefSchema, C as isAScalarSchema, z as isASchema, F as isAStringEnumSchema, L as isObject, u as isValidationError, q as sanitizeJson } from './shared/schema.DLX0nTwB.js';
4
1
  import { Schema } from '@arrirpc/type-defs';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import { A as ASchema, a as ASchemaStrict, I as InferType, R as Result, S as SchemaValidator, b as ASchemaOptions, c as ASchemaWithAdapters, d as AArraySchema, W as WithAdapters, e as AScalarSchemaWithAdapters, f as AObjectSchema, g as ADiscriminatorSchemaWithAdapters, h as ResolveObject, i as AStringEnumSchemaWithAdapters, j as AObjectSchemaOptions, k as AObjectSchemaWithAdapters, l as InferObjectOutput, V as ValidationContext, m as ARecordSchemaWithAdapters, n as ARefSchema, o as ValueError, p as InferSubType } from './shared/schema.BYXPajpl.js';
4
+ export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema, Z as ARefSchemaWithAdapters, C as AScalarSchema, H as AStringEnumSchema, U as InferObjectRawType, M as MaybeNullable, E as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, v as ResultFailure, u as ResultSuccess, y as SchemaMetadata, x as VALIDATOR_KEY, s as ValidationException, r as errorMessageFromErrors, F as isAAraySchema, L as isADiscriminatorSchema, T as isAObjectSchema, Q as isARecordSchema, Y as isARefSchema, D as isAScalarSchema, z as isASchema, J as isAStringEnumSchema, X as isObject, t as isValidationException, q as isValueError, w as newValidationContext } from './shared/schema.BYXPajpl.js';
5
5
 
6
- declare function createParsingTemplate(input: string, schema: Schema): string;
6
+ declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
7
7
 
8
8
  declare function createSerializationV2Template(inputName: string, schema: Schema): string;
9
9
 
10
10
  declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
11
11
 
12
- interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
12
+ interface CompiledValidator<TSchema extends ASchema<any>> {
13
+ schema: ASchemaStrict<TSchema>;
13
14
  /**
14
15
  * Determine if a type matches a schema. This is a type guard.
15
16
  */
16
17
  validate: (input: unknown) => input is InferType<TSchema>;
18
+ /**
19
+ * Parse a JSON string or the result of JSON.parse(). Returns a Result<T>.
20
+ */
21
+ parse: (input: unknown) => Result<InferType<TSchema>>;
17
22
  /**
18
23
  * Parse a JSON string or the result of JSON.parse(). Throws an error if parsing fails.
19
24
  */
20
- parse: (input: unknown) => InferType<TSchema>;
25
+ parseUnsafe: (input: unknown) => InferType<TSchema>;
21
26
  /**
22
- * Parse a JSON string or the result of JSON.parse() without throwing an error
27
+ * Coerce an object into <T>. Returns Result<T>.
23
28
  */
24
- safeParse: (input: unknown) => SafeResult<InferType<TSchema>>;
29
+ coerce: (input: unknown) => Result<InferType<TSchema>>;
30
+ /**
31
+ * Coerce an object into <T>. Throws an error if coercion fails.
32
+ */
33
+ coerceUnsafe: (input: unknown) => InferType<TSchema>;
25
34
  /**
26
35
  * Serialize to JSON
27
36
  */
28
- serialize: (input: InferType<TSchema>) => string;
37
+ serialize: (input: InferType<TSchema>) => Result<string>;
38
+ /**
39
+ * Serialize to JSON. Throws an error if it fails.
40
+ */
41
+ serializeUnsafe: (input: InferType<TSchema>) => string;
42
+ /**
43
+ * The ATD Schema
44
+ */
29
45
  compiledCode: {
30
- serialize: string;
31
46
  parse: string;
47
+ coerce: string;
48
+ serialize: string;
32
49
  validate: string;
33
50
  };
34
51
  }
52
+ type CompiledValidatorWithAdapters<TSchema extends ASchema> = CompiledValidator<TSchema> & StandardSchemaV1<InferType<TSchema>>;
35
53
  /**
36
- * Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
54
+ * Create compiled versions of the `decode()`, `validate()`, and `serialize()` functions
37
55
  */
38
- declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
39
- type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
40
- declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
56
+ declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidatorWithAdapters<TSchema>;
57
+ type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema>>['parse'];
58
+ declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: Schema, shouldCoerce: boolean): {
41
59
  fn: CompiledParser<TSchema>;
42
60
  code: string;
43
61
  };
@@ -49,9 +67,9 @@ declare function getCompiledSerializer<TSchema extends ASchema>(schema: TSchema)
49
67
  /**
50
68
  * Create a schema that accepts anything
51
69
  */
52
- declare function any(options?: ASchemaOptions): ASchema<any>;
70
+ declare function any(options?: ASchemaOptions): ASchemaWithAdapters<any>;
53
71
 
54
- declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSchema, opts?: ASchemaOptions): AArraySchema<TInnerSchema>;
72
+ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSchema, opts?: ASchemaOptions): AArraySchema<TInnerSchema> & WithAdapters<InferType<TInnerSchema>[]>;
55
73
 
56
74
  /**
57
75
  * @example
@@ -59,7 +77,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
59
77
  * a.validate(Schema, true) // true;
60
78
  * a.validate(Schema, false) // true;
61
79
  */
62
- declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
80
+ declare function boolean(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'boolean', boolean>;
63
81
 
64
82
  /**
65
83
  * Create a discriminated union / tagged union
@@ -95,8 +113,8 @@ declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolea
95
113
  * createdAt: new Date(),
96
114
  * }) // false
97
115
  */
98
- declare function discriminator<TDiscriminatorKey extends string, TMapping extends Record<string, AObjectSchema<any>>>(discriminator: TDiscriminatorKey, mapping: TMapping, opts?: ASchemaOptions): ADiscriminatorSchema<InferDiscriminatorType<TDiscriminatorKey, TMapping, JoinedDiscriminator<TDiscriminatorKey, TMapping>>>;
99
- declare function discriminator<TDiscriminatorKey extends string, TMapping extends Record<string, AObjectSchema<any>>>(id: string, discriminator: TDiscriminatorKey, mapping: TMapping): ADiscriminatorSchema<InferDiscriminatorType<TDiscriminatorKey, TMapping, JoinedDiscriminator<TDiscriminatorKey, TMapping>>>;
116
+ declare function discriminator<TDiscriminatorKey extends string, TMapping extends Record<string, AObjectSchema<any>>>(discriminator: TDiscriminatorKey, mapping: TMapping, opts?: ASchemaOptions): ADiscriminatorSchemaWithAdapters<InferDiscriminatorType<TDiscriminatorKey, TMapping, JoinedDiscriminator<TDiscriminatorKey, TMapping>>>;
117
+ declare function discriminator<TDiscriminatorKey extends string, TMapping extends Record<string, AObjectSchema<any>>>(id: string, discriminator: TDiscriminatorKey, mapping: TMapping): ADiscriminatorSchemaWithAdapters<InferDiscriminatorType<TDiscriminatorKey, TMapping, JoinedDiscriminator<TDiscriminatorKey, TMapping>>>;
100
118
  type JoinedDiscriminator<TUnionKey extends string, TInput extends Record<string, AObjectSchema<any>>> = {
101
119
  [TKey in keyof TInput]: InferType<TInput[TKey]> & Record<TUnionKey, TKey>;
102
120
  };
@@ -115,7 +133,7 @@ declare const stringEnum: typeof enumerator;
115
133
  * a.validate(Schema, "B") // true
116
134
  * a.validate(Schema, "C") // false
117
135
  */
118
- declare function enumerator<TKeys extends string, TValues extends TKeys[]>(values: TValues, opts?: ASchemaOptions): AStringEnumSchema<TValues>;
136
+ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(values: TValues, opts?: ASchemaOptions): AStringEnumSchemaWithAdapters<TValues>;
119
137
  /**
120
138
  * An enumeration of string values
121
139
  *
@@ -128,7 +146,7 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(value
128
146
  * a.validate(Schema, "B") // true
129
147
  * a.validate(Schema, "C") // false
130
148
  */
131
- declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: string, values: TValues): AStringEnumSchema<TValues>;
149
+ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: string, values: TValues): AStringEnumSchemaWithAdapters<TValues>;
132
150
 
133
151
  /**
134
152
  * Transforms a schema into a nullable type
@@ -142,7 +160,7 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: s
142
160
  * })
143
161
  * )
144
162
  */
145
- declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchema<T | null>;
163
+ declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null>;
146
164
  /**
147
165
  * Make an object field optional
148
166
  *
@@ -156,7 +174,7 @@ declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchema
156
174
  * })
157
175
  */
158
176
  declare function optional<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchema<T | undefined>;
159
- declare function clone<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchema<T>;
177
+ declare function clone<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T>;
160
178
 
161
179
  /**
162
180
  * Alias for float64 as that is the only number type that Javascript uses
@@ -165,17 +183,17 @@ declare function clone<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchema<T>;
165
183
  * const Schema = a.number()
166
184
  * a.validate(Schema, 1.5) // true
167
185
  */
168
- declare function number(opts?: ASchemaOptions): AScalarSchema<"float64", number>;
169
- declare function float32(opts?: ASchemaOptions): AScalarSchema<"float32", number>;
170
- declare function float64(opts?: ASchemaOptions): AScalarSchema<"float64", number>;
171
- declare function int8(opts?: ASchemaOptions): AScalarSchema<"int8", number>;
172
- declare function uint8(opts?: ASchemaOptions): AScalarSchema<"uint8", number>;
173
- declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
174
- declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
175
- declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
176
- declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
177
- declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
178
- declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
186
+ declare function number(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"float64", number>;
187
+ declare function float32(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"float32", number>;
188
+ declare function float64(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"float64", number>;
189
+ declare function int8(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"int8", number>;
190
+ declare function uint8(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"uint8", number>;
191
+ declare function int16(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"int16", number>;
192
+ declare function uint16(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"uint16", number>;
193
+ declare function int32(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"int32", number>;
194
+ declare function uint32(opts?: ASchemaOptions): AScalarSchemaWithAdapters<"uint32", number>;
195
+ declare function int64(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'int64', bigint>;
196
+ declare function uint64(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'uint64', bigint>;
179
197
 
180
198
  /**
181
199
  * Create an object schema
@@ -188,10 +206,10 @@ declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
188
206
  * a.validate(Schema, {foo: "", bar: 0}) // true
189
207
  * a.validate(Schema, {foo: null, bar: 0}) // false
190
208
  */
191
- declare function object<TInput extends Record<any, ASchema> = any, TAdditionalProps extends boolean = false>(input: TInput, opts?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchema<InferObjectOutput<TInput>, TAdditionalProps>;
192
- declare function object<TInput extends Record<any, ASchema> = any, TAdditionalProps extends boolean = false>(id: string, input: TInput): AObjectSchema<InferObjectOutput<TInput>, TAdditionalProps>;
193
- declare function parseObjectSchema<T>(schema: AObjectSchema<T>, input: unknown, data: ValidationContext, coerce?: boolean): T | undefined;
194
- declare function validateObjectSchema(schema: AObjectSchema, input: unknown): boolean;
209
+ declare function object<TInput extends Record<any, ASchema> = any, TAdditionalProps extends boolean = false>(input: TInput, opts?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
210
+ declare function object<TInput extends Record<any, ASchema> = any, TAdditionalProps extends boolean = false>(id: string, input: TInput): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
211
+ declare function decodeObjectSchema<T>(schema: AObjectSchemaWithAdapters<T>, input: unknown, context: ValidationContext, coerce?: boolean): T | undefined;
212
+ declare function validateObjectSchema(schema: AObjectSchemaWithAdapters, input: unknown): boolean;
195
213
  /**
196
214
  * Create an object schema using a subset of keys from another object schema
197
215
  *
@@ -204,7 +222,7 @@ declare function validateObjectSchema(schema: AObjectSchema, input: unknown): bo
204
222
  *
205
223
  * const SubObject = a.pick(User, ['foo']) // { foo: string; }
206
224
  */
207
- declare function pick<TSchema extends AObjectSchema<any, any> = any, TKeys extends keyof InferType<TSchema> = any, TAdditionalProps extends boolean = false>(inputSchema: TSchema, keys: TKeys[], options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchema<Pick<InferType<TSchema>, TKeys>, TAdditionalProps>;
225
+ declare function pick<TSchema extends AObjectSchemaWithAdapters<any, any> = any, TKeys extends keyof InferType<TSchema> = any, TStrict extends boolean = false>(inputSchema: TSchema, keys: TKeys[], options?: AObjectSchemaOptions<TStrict>): AObjectSchemaWithAdapters<Pick<InferType<TSchema>, TKeys>, TStrict>;
208
226
  /**
209
227
  * Create an object schema by omitting keys from another object schema
210
228
  *
@@ -217,10 +235,10 @@ declare function pick<TSchema extends AObjectSchema<any, any> = any, TKeys exten
217
235
  *
218
236
  * const SubObject = a.omit(BaseObject, ['foo']) // { bar: string; baz: string; }
219
237
  */
220
- declare function omit<TSchema extends AObjectSchema<any, any> = any, TKeys extends keyof InferType<TSchema> = any, TAdditionalProps extends boolean = false>(inputSchema: TSchema, keys: TKeys[], options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchema<Omit<InferType<TSchema>, TKeys>, TAdditionalProps>;
221
- declare function serializeObject(schema: AObjectSchema, input: any, data: ValidationContext): string;
222
- declare function extend<TBaseSchema extends AObjectSchema<any, any> = any, TSchema extends AObjectSchema<any, any> = any, TAdditionalProps extends boolean = false>(baseSchema: TBaseSchema, inputSchema: TSchema, options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchema<ResolveObject<InferType<TBaseSchema> & InferType<TSchema>>, TAdditionalProps>;
223
- declare function partial<TSchema extends AObjectSchema<any, any> = any, TAdditionalProps extends boolean = false>(schema: TSchema, options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchema<Partial<InferType<TSchema>>, TAdditionalProps>;
238
+ declare function omit<TSchema extends AObjectSchemaWithAdapters<any, any> = any, TKeys extends keyof InferType<TSchema> = any, TAdditionalProps extends boolean = false>(inputSchema: TSchema, keys: TKeys[], options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<Omit<InferType<TSchema>, TKeys>, TAdditionalProps>;
239
+ declare function serializeObject(schema: AObjectSchemaWithAdapters, input: any, context: ValidationContext): string;
240
+ declare function extend<TBaseSchema extends AObjectSchemaWithAdapters<any, any> = any, TSchema extends AObjectSchemaWithAdapters<any, any> = any, TAdditionalProps extends boolean = false>(baseSchema: TBaseSchema, inputSchema: TSchema, options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<ResolveObject<InferType<TBaseSchema> & InferType<TSchema>>, TAdditionalProps>;
241
+ declare function partial<TSchema extends AObjectSchemaWithAdapters<any, any> = any, TAdditionalProps extends boolean = false>(schema: TSchema, options?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<Partial<InferType<TSchema>>, TAdditionalProps>;
224
242
 
225
243
  /**
226
244
  * Create a schema for a record with strings keys
@@ -239,9 +257,9 @@ declare function partial<TSchema extends AObjectSchema<any, any> = any, TAdditio
239
257
  * )
240
258
  * a.validate(ObjectRecord, {foo: {id: "1", date: new Date()}}) // true
241
259
  */
242
- declare function record<TInnerSchema extends ASchema<any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchema<TInnerSchema>;
260
+ declare function record<TInnerSchema extends ASchema<any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
243
261
 
244
- type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchema<T> | ADiscriminatorSchema<T>;
262
+ type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchemaWithAdapters<T> | ADiscriminatorSchemaWithAdapters<T>;
245
263
  /**
246
264
  * @example
247
265
  * ```ts
@@ -258,7 +276,7 @@ type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchema<T> | ADiscrim
258
276
  * );
259
277
  * ```
260
278
  */
261
- declare function recursive<T = any>(callback: RecursiveCallback<T>, metadata?: ASchemaOptions): AObjectSchema<T> | ADiscriminatorSchema<T>;
279
+ declare function recursive<T = any>(callback: RecursiveCallback<T>, metadata?: ASchemaOptions): AObjectSchemaWithAdapters<T> | ADiscriminatorSchemaWithAdapters<T>;
262
280
  /**
263
281
  * Recursive ID Shorthand
264
282
  *
@@ -278,7 +296,7 @@ declare function recursive<T = any>(callback: RecursiveCallback<T>, metadata?: A
278
296
  * );
279
297
  * ```
280
298
  */
281
- declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>): AObjectSchema<T> | ADiscriminatorSchema<T>;
299
+ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>): AObjectSchemaWithAdapters<T> | ADiscriminatorSchemaWithAdapters<T>;
282
300
 
283
301
  /**
284
302
  * @example
@@ -286,7 +304,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
286
304
  * a.validate(StringSchema, "hello world") // true
287
305
  * a.validate(StringSchema, 10) // false
288
306
  */
289
- declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
307
+ declare function string(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'string', string>;
290
308
  declare function serializeString(input: string): string;
291
309
  declare const STR_ESCAPE: RegExp;
292
310
  declare function serializeSmallString(input: string): string;
@@ -298,13 +316,42 @@ declare function serializeSmallString(input: string): string;
298
316
  * const Schema = a.timestamp();
299
317
  * a.validate(Schema, new Date()) // true
300
318
  */
301
- declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
319
+ declare function timestamp(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'timestamp', Date>;
320
+
321
+ declare function sanitizeJson(json: string): string;
322
+ /**
323
+ * Check if the input matches the specified schema. This is a type guard.
324
+ */
325
+ declare function validate<T = any>(schema: ASchema<T>, input: unknown): input is T;
326
+ /**
327
+ * Parse a JSON string or the result of JSON.parse() without throwing an error.
328
+ */
329
+ declare function parse<T = any>(schema: ASchema<T>, input: unknown): Result<T>;
330
+ /**
331
+ * Parse a JSON string or the result of JSON.parse(). Throws a [ValidationException] if parsing fails.
332
+ */
333
+ declare function parseUnsafe<T = any>(schema: ASchema<T>, input: unknown): T;
334
+ /**
335
+ * Convert a value into the specified schema without throwing an error.
336
+ */
337
+ declare function coerce<T = any>(schema: ASchema<T>, input: unknown): Result<T>;
338
+ /**
339
+ * Try to convert input to match the specified schema. Throws a [ValidationException] if conversion fails.
340
+ */
341
+ declare function coerceUnsafe<T = any>(schema: ASchema<T>, input: unknown): T;
342
+ /**
343
+ * Serialize a value into a JSON string.
344
+ */
345
+ declare function serialize<T = any>(schema: ASchema<T>, input: T): Result<string>;
346
+ declare function serializeUnsafe<T = any>(schema: ASchema<T>, input: T): string;
347
+ declare function errors(schema: ASchema, input: unknown, exitOnFirstError?: boolean): ValueError[];
302
348
 
303
349
  declare const _namespace_any: typeof any;
304
350
  declare const _namespace_array: typeof array;
305
351
  declare const _namespace_boolean: typeof boolean;
306
352
  declare const _namespace_clone: typeof clone;
307
353
  declare const _namespace_coerce: typeof coerce;
354
+ declare const _namespace_coerceUnsafe: typeof coerceUnsafe;
308
355
  declare const _namespace_compile: typeof compile;
309
356
  declare const _namespace_discriminator: typeof discriminator;
310
357
  declare const _namespace_enumerator: typeof enumerator;
@@ -322,13 +369,13 @@ declare const _namespace_object: typeof object;
322
369
  declare const _namespace_omit: typeof omit;
323
370
  declare const _namespace_optional: typeof optional;
324
371
  declare const _namespace_parse: typeof parse;
372
+ declare const _namespace_parseUnsafe: typeof parseUnsafe;
325
373
  declare const _namespace_partial: typeof partial;
326
374
  declare const _namespace_pick: typeof pick;
327
375
  declare const _namespace_record: typeof record;
328
376
  declare const _namespace_recursive: typeof recursive;
329
- declare const _namespace_safeCoerce: typeof safeCoerce;
330
- declare const _namespace_safeParse: typeof safeParse;
331
377
  declare const _namespace_serialize: typeof serialize;
378
+ declare const _namespace_serializeUnsafe: typeof serializeUnsafe;
332
379
  declare const _namespace_string: typeof string;
333
380
  declare const _namespace_stringEnum: typeof stringEnum;
334
381
  declare const _namespace_timestamp: typeof timestamp;
@@ -338,13 +385,9 @@ declare const _namespace_uint64: typeof uint64;
338
385
  declare const _namespace_uint8: typeof uint8;
339
386
  declare const _namespace_validate: typeof validate;
340
387
  declare namespace _namespace {
341
- export { _namespace_any as any, _namespace_array as array, _namespace_boolean as boolean, _namespace_clone as clone, _namespace_coerce as coerce, _namespace_compile as compile, _namespace_discriminator as discriminator, _namespace_enumerator as enumerator, _namespace_errors as errors, _namespace_extend as extend, _namespace_float32 as float32, _namespace_float64 as float64, InferType as infer, InferSubType as inferSubType, _namespace_int16 as int16, _namespace_int32 as int32, _namespace_int64 as int64, _namespace_int8 as int8, _namespace_nullable as nullable, _namespace_number as number, _namespace_object as object, _namespace_omit as omit, _namespace_optional as optional, _namespace_parse as parse, _namespace_partial as partial, _namespace_pick as pick, _namespace_record as record, _namespace_recursive as recursive, _namespace_safeCoerce as safeCoerce, _namespace_safeParse as safeParse, _namespace_serialize as serialize, _namespace_string as string, _namespace_stringEnum as stringEnum, _namespace_timestamp as timestamp, _namespace_uint16 as uint16, _namespace_uint32 as uint32, _namespace_uint64 as uint64, _namespace_uint8 as uint8, _namespace_validate as validate };
388
+ export { _namespace_any as any, _namespace_array as array, _namespace_boolean as boolean, _namespace_clone as clone, _namespace_coerce as coerce, _namespace_coerceUnsafe as coerceUnsafe, _namespace_compile as compile, _namespace_discriminator as discriminator, _namespace_enumerator as enumerator, _namespace_errors as errors, _namespace_extend as extend, _namespace_float32 as float32, _namespace_float64 as float64, InferType as infer, InferSubType as inferSubType, _namespace_int16 as int16, _namespace_int32 as int32, _namespace_int64 as int64, _namespace_int8 as int8, _namespace_nullable as nullable, _namespace_number as number, _namespace_object as object, _namespace_omit as omit, _namespace_optional as optional, _namespace_parse as parse, _namespace_parseUnsafe as parseUnsafe, _namespace_partial as partial, _namespace_pick as pick, _namespace_record as record, _namespace_recursive as recursive, _namespace_serialize as serialize, _namespace_serializeUnsafe as serializeUnsafe, _namespace_string as string, _namespace_stringEnum as stringEnum, _namespace_timestamp as timestamp, _namespace_uint16 as uint16, _namespace_uint32 as uint32, _namespace_uint64 as uint64, _namespace_uint8 as uint8, _namespace_validate as validate };
342
389
  }
343
390
 
344
- type ValidationAdapter = <T>(input: any) => ASchema<T>;
345
- declare function isAdaptedSchema(input: ASchema): boolean;
346
- declare function validatorFromAdaptedSchema(schema: ASchema): ReturnType<typeof compile>;
347
-
348
391
  declare const int8Min = -128;
349
392
  declare const int8Max = 127;
350
393
  declare const uint8Min = 0;
@@ -362,10 +405,4 @@ declare const int64Max: bigint;
362
405
  declare const uint64Min: bigint;
363
406
  declare const uint64Max: bigint;
364
407
 
365
- declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined): StandardSchemaV1<T>['~standard'];
366
- /**
367
- * Ensure that non ATD compliant properties get hidden when serialized to JSON
368
- */
369
- declare function hideInvalidProperties(schema: ASchema): void;
370
-
371
- export { AArraySchema, ADiscriminatorSchema, AObjectSchema, AObjectSchemaOptions, ARecordSchema, ARefSchema, AScalarSchema, ASchema, ASchemaOptions, AStringEnumSchema, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, STR_ESCAPE, SafeResult, type ValidationAdapter, ValidationContext, _namespace as a, any, array, boolean, clone, coerce, compile, createStandardSchemaProperty, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, hideInvalidProperties, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, isAdaptedSchema, nullable, number, object, omit, optional, parse, parseObjectSchema, partial, pick, record, recursive, safeCoerce, safeParse, serialize, serializeObject, serializeSmallString, serializeString, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema, validatorFromAdaptedSchema };
408
+ export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, type CompiledValidator, InferObjectOutput, InferSubType, InferType, ResolveObject, Result, STR_ESCAPE, SchemaValidator, ValidationContext, ValueError, WithAdapters, _namespace as a, any, array, boolean, clone, coerce, coerceUnsafe, compile, decodeObjectSchema, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaDecodingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int64Max, int64Min, int8, int8Max, int8Min, nullable, number, object, omit, optional, parse, parseUnsafe, partial, pick, record, recursive, sanitizeJson, serialize, serializeObject, serializeSmallString, serializeString, serializeUnsafe, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, validate, validateObjectSchema };