@arrirpc/schema 0.77.1 → 0.79.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 +57 -1
- package/dist/adapters.d.cts +2 -2
- package/dist/adapters.d.mts +2 -2
- package/dist/adapters.d.ts +2 -2
- package/dist/index.cjs +111 -90
- package/dist/index.d.cts +22 -9
- package/dist/index.d.mts +22 -9
- package/dist/index.d.ts +22 -9
- package/dist/index.mjs +111 -91
- package/dist/shared/{schema.hMebmI3A.d.cts → schema.CS4qvHhE.d.cts} +21 -14
- package/dist/shared/{schema.hMebmI3A.d.mts → schema.CS4qvHhE.d.mts} +21 -14
- package/dist/shared/{schema.hMebmI3A.d.ts → schema.CS4qvHhE.d.ts} +21 -14
- package/package.json +7 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from '@arrirpc/type-defs';
|
|
2
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 AObjectSchemaWithAdapters, k as AObjectSchemaOptions, l as InferObjectOutput,
|
|
4
|
-
export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema,
|
|
3
|
+
import { A as ASchema, a as ASchemaStrict, I as InferType, R as Result, S as SchemaValidator, V as VALIDATOR_KEY, 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 AObjectSchemaWithAdapters, k as AObjectSchemaOptions, l as InferObjectOutput, m as ValidationContext, n as ARecordSchemaWithAdapters, o as ARefSchema, p as ValueError, q as InferSubType } from './shared/schema.CS4qvHhE.cjs';
|
|
4
|
+
export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema, _ as ARefSchemaWithAdapters, C as AScalarSchema, H as AStringEnumSchema, U as InferObjectOptionalKeys, X as InferObjectRawType, M as MaybeNullable, E as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as ResultFailure, v as ResultSuccess, y as SchemaMetadata, t as ValidationException, s as errorMessageFromErrors, F as isAAraySchema, L as isADiscriminatorSchema, T as isAObjectSchema, Q as isARecordSchema, Z as isARefSchema, D as isAScalarSchema, z as isASchema, J as isAStringEnumSchema, Y as isObject, u as isValidationException, r as isValueError, x as newValidationContext } from './shared/schema.CS4qvHhE.cjs';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
|
@@ -55,7 +55,7 @@ type CompiledValidatorWithAdapters<TSchema extends ASchema, TIncludeCode extends
|
|
|
55
55
|
* Create compiled versions of the `decode()`, `validate()`, and `serialize()` functions
|
|
56
56
|
*/
|
|
57
57
|
declare function compile<TSchema extends ASchema<any>, TIncludeCompiled extends boolean = false>(schema: TSchema, includeCompiledCode?: TIncludeCompiled): CompiledValidatorWithAdapters<TSchema, TIncludeCompiled>;
|
|
58
|
-
type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema
|
|
58
|
+
type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema>, TSchema[typeof VALIDATOR_KEY]['optional'] | false>['parse'];
|
|
59
59
|
declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: Schema, shouldCoerce: boolean): {
|
|
60
60
|
fn: CompiledParser<TSchema>;
|
|
61
61
|
code: string;
|
|
@@ -161,7 +161,7 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: s
|
|
|
161
161
|
* })
|
|
162
162
|
* )
|
|
163
163
|
*/
|
|
164
|
-
declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null>;
|
|
164
|
+
declare function nullable<T = any, TOptional extends boolean = false>(schema: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null, TOptional>;
|
|
165
165
|
/**
|
|
166
166
|
* Make an object field optional
|
|
167
167
|
*
|
|
@@ -174,7 +174,18 @@ declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchema
|
|
|
174
174
|
* email: a.optional(a.string())
|
|
175
175
|
* })
|
|
176
176
|
*/
|
|
177
|
-
declare function optional<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchema<T | undefined>;
|
|
177
|
+
declare function optional<T, TOptional extends boolean = false>(input: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchema<T | undefined, true>;
|
|
178
|
+
/**
|
|
179
|
+
* Make an object property able to be `undefined` without making the key optional
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const User = a.object({
|
|
183
|
+
* id: a.string(),
|
|
184
|
+
* // this field can be `string | undefined` but it is still required by TS
|
|
185
|
+
* email: a.undefinable(a.string())
|
|
186
|
+
* })
|
|
187
|
+
*/
|
|
188
|
+
declare function undefinable<T, TOptional extends boolean = false>(input: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchema<T | undefined, TOptional>;
|
|
178
189
|
declare function clone<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T>;
|
|
179
190
|
|
|
180
191
|
declare const int8Min = -128;
|
|
@@ -224,8 +235,8 @@ declare function uint64(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'uint6
|
|
|
224
235
|
* a.validate(Schema, {foo: "", bar: 0}) // true
|
|
225
236
|
* a.validate(Schema, {foo: null, bar: 0}) // false
|
|
226
237
|
*/
|
|
227
|
-
declare function object<TInput extends Record<any, ASchema
|
|
228
|
-
declare function object<TInput extends Record<any, ASchema
|
|
238
|
+
declare function object<TInput extends Record<any, ASchema<any, any>> = any, TAdditionalProps extends boolean = false>(input: TInput, opts?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
|
|
239
|
+
declare function object<TInput extends Record<any, ASchema<any, any>> = any, TAdditionalProps extends boolean = false>(id: string, input: TInput): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
|
|
229
240
|
declare function decodeObjectSchema<T>(schema: AObjectSchemaWithAdapters<T>, input: unknown, context: ValidationContext, coerce?: boolean): T | undefined;
|
|
230
241
|
declare function validateObjectSchema(schema: AObjectSchemaWithAdapters, input: unknown): boolean;
|
|
231
242
|
/**
|
|
@@ -275,7 +286,7 @@ declare function partial<TSchema extends AObjectSchemaWithAdapters<any, any> = a
|
|
|
275
286
|
* )
|
|
276
287
|
* a.validate(ObjectRecord, {foo: {id: "1", date: new Date()}}) // true
|
|
277
288
|
*/
|
|
278
|
-
declare function record<TInnerSchema extends ASchema<any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
|
|
289
|
+
declare function record<TInnerSchema extends ASchema<any, any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
|
|
279
290
|
|
|
280
291
|
type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchemaWithAdapters<T> | ADiscriminatorSchemaWithAdapters<T>;
|
|
281
292
|
/**
|
|
@@ -401,6 +412,7 @@ declare const _namespace_uint16: typeof uint16;
|
|
|
401
412
|
declare const _namespace_uint32: typeof uint32;
|
|
402
413
|
declare const _namespace_uint64: typeof uint64;
|
|
403
414
|
declare const _namespace_uint8: typeof uint8;
|
|
415
|
+
declare const _namespace_undefinable: typeof undefinable;
|
|
404
416
|
declare const _namespace_validate: typeof validate;
|
|
405
417
|
declare namespace _namespace {
|
|
406
418
|
export {
|
|
@@ -443,9 +455,10 @@ declare namespace _namespace {
|
|
|
443
455
|
_namespace_uint32 as uint32,
|
|
444
456
|
_namespace_uint64 as uint64,
|
|
445
457
|
_namespace_uint8 as uint8,
|
|
458
|
+
_namespace_undefinable as undefinable,
|
|
446
459
|
_namespace_validate as validate,
|
|
447
460
|
};
|
|
448
461
|
}
|
|
449
462
|
|
|
450
|
-
export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, 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 };
|
|
463
|
+
export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, InferObjectOutput, InferSubType, InferType, ResolveObject, Result, STR_ESCAPE, SchemaValidator, VALIDATOR_KEY, 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, undefinable, validate, validateObjectSchema };
|
|
451
464
|
export type { CompiledValidator, CompiledValidatorCompiledCode };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from '@arrirpc/type-defs';
|
|
2
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 AObjectSchemaWithAdapters, k as AObjectSchemaOptions, l as InferObjectOutput,
|
|
4
|
-
export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema,
|
|
3
|
+
import { A as ASchema, a as ASchemaStrict, I as InferType, R as Result, S as SchemaValidator, V as VALIDATOR_KEY, 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 AObjectSchemaWithAdapters, k as AObjectSchemaOptions, l as InferObjectOutput, m as ValidationContext, n as ARecordSchemaWithAdapters, o as ARefSchema, p as ValueError, q as InferSubType } from './shared/schema.CS4qvHhE.mjs';
|
|
4
|
+
export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema, _ as ARefSchemaWithAdapters, C as AScalarSchema, H as AStringEnumSchema, U as InferObjectOptionalKeys, X as InferObjectRawType, M as MaybeNullable, E as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as ResultFailure, v as ResultSuccess, y as SchemaMetadata, t as ValidationException, s as errorMessageFromErrors, F as isAAraySchema, L as isADiscriminatorSchema, T as isAObjectSchema, Q as isARecordSchema, Z as isARefSchema, D as isAScalarSchema, z as isASchema, J as isAStringEnumSchema, Y as isObject, u as isValidationException, r as isValueError, x as newValidationContext } from './shared/schema.CS4qvHhE.mjs';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
|
@@ -55,7 +55,7 @@ type CompiledValidatorWithAdapters<TSchema extends ASchema, TIncludeCode extends
|
|
|
55
55
|
* Create compiled versions of the `decode()`, `validate()`, and `serialize()` functions
|
|
56
56
|
*/
|
|
57
57
|
declare function compile<TSchema extends ASchema<any>, TIncludeCompiled extends boolean = false>(schema: TSchema, includeCompiledCode?: TIncludeCompiled): CompiledValidatorWithAdapters<TSchema, TIncludeCompiled>;
|
|
58
|
-
type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema
|
|
58
|
+
type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema>, TSchema[typeof VALIDATOR_KEY]['optional'] | false>['parse'];
|
|
59
59
|
declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: Schema, shouldCoerce: boolean): {
|
|
60
60
|
fn: CompiledParser<TSchema>;
|
|
61
61
|
code: string;
|
|
@@ -161,7 +161,7 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: s
|
|
|
161
161
|
* })
|
|
162
162
|
* )
|
|
163
163
|
*/
|
|
164
|
-
declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null>;
|
|
164
|
+
declare function nullable<T = any, TOptional extends boolean = false>(schema: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null, TOptional>;
|
|
165
165
|
/**
|
|
166
166
|
* Make an object field optional
|
|
167
167
|
*
|
|
@@ -174,7 +174,18 @@ declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchema
|
|
|
174
174
|
* email: a.optional(a.string())
|
|
175
175
|
* })
|
|
176
176
|
*/
|
|
177
|
-
declare function optional<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchema<T | undefined>;
|
|
177
|
+
declare function optional<T, TOptional extends boolean = false>(input: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchema<T | undefined, true>;
|
|
178
|
+
/**
|
|
179
|
+
* Make an object property able to be `undefined` without making the key optional
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const User = a.object({
|
|
183
|
+
* id: a.string(),
|
|
184
|
+
* // this field can be `string | undefined` but it is still required by TS
|
|
185
|
+
* email: a.undefinable(a.string())
|
|
186
|
+
* })
|
|
187
|
+
*/
|
|
188
|
+
declare function undefinable<T, TOptional extends boolean = false>(input: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchema<T | undefined, TOptional>;
|
|
178
189
|
declare function clone<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T>;
|
|
179
190
|
|
|
180
191
|
declare const int8Min = -128;
|
|
@@ -224,8 +235,8 @@ declare function uint64(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'uint6
|
|
|
224
235
|
* a.validate(Schema, {foo: "", bar: 0}) // true
|
|
225
236
|
* a.validate(Schema, {foo: null, bar: 0}) // false
|
|
226
237
|
*/
|
|
227
|
-
declare function object<TInput extends Record<any, ASchema
|
|
228
|
-
declare function object<TInput extends Record<any, ASchema
|
|
238
|
+
declare function object<TInput extends Record<any, ASchema<any, any>> = any, TAdditionalProps extends boolean = false>(input: TInput, opts?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
|
|
239
|
+
declare function object<TInput extends Record<any, ASchema<any, any>> = any, TAdditionalProps extends boolean = false>(id: string, input: TInput): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
|
|
229
240
|
declare function decodeObjectSchema<T>(schema: AObjectSchemaWithAdapters<T>, input: unknown, context: ValidationContext, coerce?: boolean): T | undefined;
|
|
230
241
|
declare function validateObjectSchema(schema: AObjectSchemaWithAdapters, input: unknown): boolean;
|
|
231
242
|
/**
|
|
@@ -275,7 +286,7 @@ declare function partial<TSchema extends AObjectSchemaWithAdapters<any, any> = a
|
|
|
275
286
|
* )
|
|
276
287
|
* a.validate(ObjectRecord, {foo: {id: "1", date: new Date()}}) // true
|
|
277
288
|
*/
|
|
278
|
-
declare function record<TInnerSchema extends ASchema<any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
|
|
289
|
+
declare function record<TInnerSchema extends ASchema<any, any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
|
|
279
290
|
|
|
280
291
|
type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchemaWithAdapters<T> | ADiscriminatorSchemaWithAdapters<T>;
|
|
281
292
|
/**
|
|
@@ -401,6 +412,7 @@ declare const _namespace_uint16: typeof uint16;
|
|
|
401
412
|
declare const _namespace_uint32: typeof uint32;
|
|
402
413
|
declare const _namespace_uint64: typeof uint64;
|
|
403
414
|
declare const _namespace_uint8: typeof uint8;
|
|
415
|
+
declare const _namespace_undefinable: typeof undefinable;
|
|
404
416
|
declare const _namespace_validate: typeof validate;
|
|
405
417
|
declare namespace _namespace {
|
|
406
418
|
export {
|
|
@@ -443,9 +455,10 @@ declare namespace _namespace {
|
|
|
443
455
|
_namespace_uint32 as uint32,
|
|
444
456
|
_namespace_uint64 as uint64,
|
|
445
457
|
_namespace_uint8 as uint8,
|
|
458
|
+
_namespace_undefinable as undefinable,
|
|
446
459
|
_namespace_validate as validate,
|
|
447
460
|
};
|
|
448
461
|
}
|
|
449
462
|
|
|
450
|
-
export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, 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 };
|
|
463
|
+
export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, InferObjectOutput, InferSubType, InferType, ResolveObject, Result, STR_ESCAPE, SchemaValidator, VALIDATOR_KEY, 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, undefinable, validate, validateObjectSchema };
|
|
451
464
|
export type { CompiledValidator, CompiledValidatorCompiledCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from '@arrirpc/type-defs';
|
|
2
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 AObjectSchemaWithAdapters, k as AObjectSchemaOptions, l as InferObjectOutput,
|
|
4
|
-
export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema,
|
|
3
|
+
import { A as ASchema, a as ASchemaStrict, I as InferType, R as Result, S as SchemaValidator, V as VALIDATOR_KEY, 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 AObjectSchemaWithAdapters, k as AObjectSchemaOptions, l as InferObjectOutput, m as ValidationContext, n as ARecordSchemaWithAdapters, o as ARefSchema, p as ValueError, q as InferSubType } from './shared/schema.CS4qvHhE.js';
|
|
4
|
+
export { G as AArraySchemaWithAdapters, K as ADiscriminatorSchema, O as ARecordSchema, _ as ARefSchemaWithAdapters, C as AScalarSchema, H as AStringEnumSchema, U as InferObjectOptionalKeys, X as InferObjectRawType, M as MaybeNullable, E as NumberType, N as NumberTypeValues, P as PartialBy, B as Resolve, w as ResultFailure, v as ResultSuccess, y as SchemaMetadata, t as ValidationException, s as errorMessageFromErrors, F as isAAraySchema, L as isADiscriminatorSchema, T as isAObjectSchema, Q as isARecordSchema, Z as isARefSchema, D as isAScalarSchema, z as isASchema, J as isAStringEnumSchema, Y as isObject, u as isValidationException, r as isValueError, x as newValidationContext } from './shared/schema.CS4qvHhE.js';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
|
@@ -55,7 +55,7 @@ type CompiledValidatorWithAdapters<TSchema extends ASchema, TIncludeCode extends
|
|
|
55
55
|
* Create compiled versions of the `decode()`, `validate()`, and `serialize()` functions
|
|
56
56
|
*/
|
|
57
57
|
declare function compile<TSchema extends ASchema<any>, TIncludeCompiled extends boolean = false>(schema: TSchema, includeCompiledCode?: TIncludeCompiled): CompiledValidatorWithAdapters<TSchema, TIncludeCompiled>;
|
|
58
|
-
type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema
|
|
58
|
+
type CompiledParser<TSchema extends ASchema<any>> = SchemaValidator<InferType<TSchema>, TSchema[typeof VALIDATOR_KEY]['optional'] | false>['parse'];
|
|
59
59
|
declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: Schema, shouldCoerce: boolean): {
|
|
60
60
|
fn: CompiledParser<TSchema>;
|
|
61
61
|
code: string;
|
|
@@ -161,7 +161,7 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: s
|
|
|
161
161
|
* })
|
|
162
162
|
* )
|
|
163
163
|
*/
|
|
164
|
-
declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null>;
|
|
164
|
+
declare function nullable<T = any, TOptional extends boolean = false>(schema: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchemaWithAdapters<T | null, TOptional>;
|
|
165
165
|
/**
|
|
166
166
|
* Make an object field optional
|
|
167
167
|
*
|
|
@@ -174,7 +174,18 @@ declare function nullable<T>(schema: ASchema<T>, opts?: ASchemaOptions): ASchema
|
|
|
174
174
|
* email: a.optional(a.string())
|
|
175
175
|
* })
|
|
176
176
|
*/
|
|
177
|
-
declare function optional<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchema<T | undefined>;
|
|
177
|
+
declare function optional<T, TOptional extends boolean = false>(input: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchema<T | undefined, true>;
|
|
178
|
+
/**
|
|
179
|
+
* Make an object property able to be `undefined` without making the key optional
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const User = a.object({
|
|
183
|
+
* id: a.string(),
|
|
184
|
+
* // this field can be `string | undefined` but it is still required by TS
|
|
185
|
+
* email: a.undefinable(a.string())
|
|
186
|
+
* })
|
|
187
|
+
*/
|
|
188
|
+
declare function undefinable<T, TOptional extends boolean = false>(input: ASchema<T, TOptional>, opts?: ASchemaOptions): ASchema<T | undefined, TOptional>;
|
|
178
189
|
declare function clone<T>(input: ASchema<T>, opts?: ASchemaOptions): ASchemaWithAdapters<T>;
|
|
179
190
|
|
|
180
191
|
declare const int8Min = -128;
|
|
@@ -224,8 +235,8 @@ declare function uint64(opts?: ASchemaOptions): AScalarSchemaWithAdapters<'uint6
|
|
|
224
235
|
* a.validate(Schema, {foo: "", bar: 0}) // true
|
|
225
236
|
* a.validate(Schema, {foo: null, bar: 0}) // false
|
|
226
237
|
*/
|
|
227
|
-
declare function object<TInput extends Record<any, ASchema
|
|
228
|
-
declare function object<TInput extends Record<any, ASchema
|
|
238
|
+
declare function object<TInput extends Record<any, ASchema<any, any>> = any, TAdditionalProps extends boolean = false>(input: TInput, opts?: AObjectSchemaOptions<TAdditionalProps>): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
|
|
239
|
+
declare function object<TInput extends Record<any, ASchema<any, any>> = any, TAdditionalProps extends boolean = false>(id: string, input: TInput): AObjectSchemaWithAdapters<InferObjectOutput<TInput>, TAdditionalProps>;
|
|
229
240
|
declare function decodeObjectSchema<T>(schema: AObjectSchemaWithAdapters<T>, input: unknown, context: ValidationContext, coerce?: boolean): T | undefined;
|
|
230
241
|
declare function validateObjectSchema(schema: AObjectSchemaWithAdapters, input: unknown): boolean;
|
|
231
242
|
/**
|
|
@@ -275,7 +286,7 @@ declare function partial<TSchema extends AObjectSchemaWithAdapters<any, any> = a
|
|
|
275
286
|
* )
|
|
276
287
|
* a.validate(ObjectRecord, {foo: {id: "1", date: new Date()}}) // true
|
|
277
288
|
*/
|
|
278
|
-
declare function record<TInnerSchema extends ASchema<any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
|
|
289
|
+
declare function record<TInnerSchema extends ASchema<any, any>>(schema: TInnerSchema, opts?: ASchemaOptions): ARecordSchemaWithAdapters<TInnerSchema>;
|
|
279
290
|
|
|
280
291
|
type RecursiveCallback<T> = (self: ARefSchema<T>) => AObjectSchemaWithAdapters<T> | ADiscriminatorSchemaWithAdapters<T>;
|
|
281
292
|
/**
|
|
@@ -401,6 +412,7 @@ declare const _namespace_uint16: typeof uint16;
|
|
|
401
412
|
declare const _namespace_uint32: typeof uint32;
|
|
402
413
|
declare const _namespace_uint64: typeof uint64;
|
|
403
414
|
declare const _namespace_uint8: typeof uint8;
|
|
415
|
+
declare const _namespace_undefinable: typeof undefinable;
|
|
404
416
|
declare const _namespace_validate: typeof validate;
|
|
405
417
|
declare namespace _namespace {
|
|
406
418
|
export {
|
|
@@ -443,9 +455,10 @@ declare namespace _namespace {
|
|
|
443
455
|
_namespace_uint32 as uint32,
|
|
444
456
|
_namespace_uint64 as uint64,
|
|
445
457
|
_namespace_uint8 as uint8,
|
|
458
|
+
_namespace_undefinable as undefinable,
|
|
446
459
|
_namespace_validate as validate,
|
|
447
460
|
};
|
|
448
461
|
}
|
|
449
462
|
|
|
450
|
-
export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, 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 };
|
|
463
|
+
export { AArraySchema, ADiscriminatorSchemaWithAdapters, AObjectSchema, AObjectSchemaOptions, AObjectSchemaWithAdapters, ARecordSchemaWithAdapters, ARefSchema, AScalarSchemaWithAdapters, ASchema, ASchemaOptions, ASchemaStrict, ASchemaWithAdapters, AStringEnumSchemaWithAdapters, InferObjectOutput, InferSubType, InferType, ResolveObject, Result, STR_ESCAPE, SchemaValidator, VALIDATOR_KEY, 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, undefinable, validate, validateObjectSchema };
|
|
451
464
|
export type { CompiledValidator, CompiledValidatorCompiledCode };
|