@arrirpc/schema 0.70.1 → 0.71.1
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 +217 -81
- package/dist/index.cjs +35 -28
- package/dist/index.d.cts +17 -10
- package/dist/index.d.mts +17 -10
- package/dist/index.d.ts +17 -10
- package/dist/index.mjs +35 -30
- package/dist/shared/{schema.TlNJgMz1.cjs → schema.COiEWm_0.cjs} +389 -256
- package/dist/shared/{schema.C-0ZU_OQ.d.cts → schema.DLX0nTwB.d.cts} +4 -3
- package/dist/shared/{schema.C-0ZU_OQ.d.mts → schema.DLX0nTwB.d.mts} +4 -3
- package/dist/shared/{schema.C-0ZU_OQ.d.ts → schema.DLX0nTwB.d.ts} +4 -3
- package/dist/shared/{schema.lowJcmic.mjs → schema.PNAcAdz3.mjs} +388 -257
- package/dist/testSuites.cjs +10 -10
- package/dist/testSuites.d.cts +6 -5
- package/dist/testSuites.d.mts +6 -5
- package/dist/testSuites.d.ts +6 -5
- package/dist/testSuites.mjs +10 -10
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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.cjs';
|
|
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.cjs';
|
|
3
4
|
import { Schema } from '@arrirpc/type-defs';
|
|
4
5
|
|
|
5
6
|
declare function createParsingTemplate(input: string, schema: Schema): string;
|
|
@@ -8,7 +9,7 @@ declare function createSerializationV2Template(inputName: string, schema: Schema
|
|
|
8
9
|
|
|
9
10
|
declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
|
|
10
11
|
|
|
11
|
-
interface CompiledValidator<TSchema extends ASchema<any>> {
|
|
12
|
+
interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
|
|
12
13
|
/**
|
|
13
14
|
* Determine if a type matches a schema. This is a type guard.
|
|
14
15
|
*/
|
|
@@ -35,7 +36,7 @@ interface CompiledValidator<TSchema extends ASchema<any>> {
|
|
|
35
36
|
* Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
|
|
36
37
|
*/
|
|
37
38
|
declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
|
|
38
|
-
type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>[
|
|
39
|
+
type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
|
|
39
40
|
declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
|
|
40
41
|
fn: CompiledParser<TSchema>;
|
|
41
42
|
code: string;
|
|
@@ -58,7 +59,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
|
|
|
58
59
|
* a.validate(Schema, true) // true;
|
|
59
60
|
* a.validate(Schema, false) // true;
|
|
60
61
|
*/
|
|
61
|
-
declare function boolean(opts?: ASchemaOptions): AScalarSchema<
|
|
62
|
+
declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Create a discriminated union / tagged union
|
|
@@ -173,8 +174,8 @@ declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
|
|
|
173
174
|
declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
|
|
174
175
|
declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
|
|
175
176
|
declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
|
|
176
|
-
declare function int64(opts?: ASchemaOptions): AScalarSchema<
|
|
177
|
-
declare function uint64(opts?: ASchemaOptions): AScalarSchema<
|
|
177
|
+
declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
|
|
178
|
+
declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
|
|
178
179
|
|
|
179
180
|
/**
|
|
180
181
|
* Create an object schema
|
|
@@ -285,7 +286,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
|
|
|
285
286
|
* a.validate(StringSchema, "hello world") // true
|
|
286
287
|
* a.validate(StringSchema, 10) // false
|
|
287
288
|
*/
|
|
288
|
-
declare function string(opts?: ASchemaOptions): AScalarSchema<
|
|
289
|
+
declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
|
|
289
290
|
declare function serializeString(input: string): string;
|
|
290
291
|
declare const STR_ESCAPE: RegExp;
|
|
291
292
|
declare function serializeSmallString(input: string): string;
|
|
@@ -297,7 +298,7 @@ declare function serializeSmallString(input: string): string;
|
|
|
297
298
|
* const Schema = a.timestamp();
|
|
298
299
|
* a.validate(Schema, new Date()) // true
|
|
299
300
|
*/
|
|
300
|
-
declare function timestamp(opts?: ASchemaOptions): AScalarSchema<
|
|
301
|
+
declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
|
|
301
302
|
|
|
302
303
|
declare const _namespace_any: typeof any;
|
|
303
304
|
declare const _namespace_array: typeof array;
|
|
@@ -361,4 +362,10 @@ declare const int64Max: bigint;
|
|
|
361
362
|
declare const uint64Min: bigint;
|
|
362
363
|
declare const uint64Max: bigint;
|
|
363
364
|
|
|
364
|
-
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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.mjs';
|
|
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.mjs';
|
|
3
4
|
import { Schema } from '@arrirpc/type-defs';
|
|
4
5
|
|
|
5
6
|
declare function createParsingTemplate(input: string, schema: Schema): string;
|
|
@@ -8,7 +9,7 @@ declare function createSerializationV2Template(inputName: string, schema: Schema
|
|
|
8
9
|
|
|
9
10
|
declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
|
|
10
11
|
|
|
11
|
-
interface CompiledValidator<TSchema extends ASchema<any>> {
|
|
12
|
+
interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
|
|
12
13
|
/**
|
|
13
14
|
* Determine if a type matches a schema. This is a type guard.
|
|
14
15
|
*/
|
|
@@ -35,7 +36,7 @@ interface CompiledValidator<TSchema extends ASchema<any>> {
|
|
|
35
36
|
* Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
|
|
36
37
|
*/
|
|
37
38
|
declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
|
|
38
|
-
type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>[
|
|
39
|
+
type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
|
|
39
40
|
declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
|
|
40
41
|
fn: CompiledParser<TSchema>;
|
|
41
42
|
code: string;
|
|
@@ -58,7 +59,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
|
|
|
58
59
|
* a.validate(Schema, true) // true;
|
|
59
60
|
* a.validate(Schema, false) // true;
|
|
60
61
|
*/
|
|
61
|
-
declare function boolean(opts?: ASchemaOptions): AScalarSchema<
|
|
62
|
+
declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Create a discriminated union / tagged union
|
|
@@ -173,8 +174,8 @@ declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
|
|
|
173
174
|
declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
|
|
174
175
|
declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
|
|
175
176
|
declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
|
|
176
|
-
declare function int64(opts?: ASchemaOptions): AScalarSchema<
|
|
177
|
-
declare function uint64(opts?: ASchemaOptions): AScalarSchema<
|
|
177
|
+
declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
|
|
178
|
+
declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
|
|
178
179
|
|
|
179
180
|
/**
|
|
180
181
|
* Create an object schema
|
|
@@ -285,7 +286,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
|
|
|
285
286
|
* a.validate(StringSchema, "hello world") // true
|
|
286
287
|
* a.validate(StringSchema, 10) // false
|
|
287
288
|
*/
|
|
288
|
-
declare function string(opts?: ASchemaOptions): AScalarSchema<
|
|
289
|
+
declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
|
|
289
290
|
declare function serializeString(input: string): string;
|
|
290
291
|
declare const STR_ESCAPE: RegExp;
|
|
291
292
|
declare function serializeSmallString(input: string): string;
|
|
@@ -297,7 +298,7 @@ declare function serializeSmallString(input: string): string;
|
|
|
297
298
|
* const Schema = a.timestamp();
|
|
298
299
|
* a.validate(Schema, new Date()) // true
|
|
299
300
|
*/
|
|
300
|
-
declare function timestamp(opts?: ASchemaOptions): AScalarSchema<
|
|
301
|
+
declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
|
|
301
302
|
|
|
302
303
|
declare const _namespace_any: typeof any;
|
|
303
304
|
declare const _namespace_array: typeof array;
|
|
@@ -361,4 +362,10 @@ declare const int64Max: bigint;
|
|
|
361
362
|
declare const uint64Min: bigint;
|
|
362
363
|
declare const uint64Max: bigint;
|
|
363
364
|
|
|
364
|
-
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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';
|
|
3
4
|
import { Schema } from '@arrirpc/type-defs';
|
|
4
5
|
|
|
5
6
|
declare function createParsingTemplate(input: string, schema: Schema): string;
|
|
@@ -8,7 +9,7 @@ declare function createSerializationV2Template(inputName: string, schema: Schema
|
|
|
8
9
|
|
|
9
10
|
declare function createValidationTemplate(inputName: string, schema: ASchema<any>): string;
|
|
10
11
|
|
|
11
|
-
interface CompiledValidator<TSchema extends ASchema<any>> {
|
|
12
|
+
interface CompiledValidator<TSchema extends ASchema<any>> extends StandardSchemaV1<InferType<TSchema>> {
|
|
12
13
|
/**
|
|
13
14
|
* Determine if a type matches a schema. This is a type guard.
|
|
14
15
|
*/
|
|
@@ -35,7 +36,7 @@ interface CompiledValidator<TSchema extends ASchema<any>> {
|
|
|
35
36
|
* Create compiled versions of the `parse()`, `validate()`, and `serialize()` functions
|
|
36
37
|
*/
|
|
37
38
|
declare function compile<TSchema extends ASchema<any>>(schema: TSchema): CompiledValidator<TSchema>;
|
|
38
|
-
type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>[
|
|
39
|
+
type CompiledParser<TSchema extends ASchema<any>> = CompiledValidator<TSchema>['parse'];
|
|
39
40
|
declare function getCompiledParser<TSchema extends ASchema<any>>(input: string, schema: TSchema): {
|
|
40
41
|
fn: CompiledParser<TSchema>;
|
|
41
42
|
code: string;
|
|
@@ -58,7 +59,7 @@ declare function array<TInnerSchema extends ASchema<any> = any>(schema: TInnerSc
|
|
|
58
59
|
* a.validate(Schema, true) // true;
|
|
59
60
|
* a.validate(Schema, false) // true;
|
|
60
61
|
*/
|
|
61
|
-
declare function boolean(opts?: ASchemaOptions): AScalarSchema<
|
|
62
|
+
declare function boolean(opts?: ASchemaOptions): AScalarSchema<'boolean', boolean>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Create a discriminated union / tagged union
|
|
@@ -173,8 +174,8 @@ declare function int16(opts?: ASchemaOptions): AScalarSchema<"int16", number>;
|
|
|
173
174
|
declare function uint16(opts?: ASchemaOptions): AScalarSchema<"uint16", number>;
|
|
174
175
|
declare function int32(opts?: ASchemaOptions): AScalarSchema<"int32", number>;
|
|
175
176
|
declare function uint32(opts?: ASchemaOptions): AScalarSchema<"uint32", number>;
|
|
176
|
-
declare function int64(opts?: ASchemaOptions): AScalarSchema<
|
|
177
|
-
declare function uint64(opts?: ASchemaOptions): AScalarSchema<
|
|
177
|
+
declare function int64(opts?: ASchemaOptions): AScalarSchema<'int64', bigint>;
|
|
178
|
+
declare function uint64(opts?: ASchemaOptions): AScalarSchema<'uint64', bigint>;
|
|
178
179
|
|
|
179
180
|
/**
|
|
180
181
|
* Create an object schema
|
|
@@ -285,7 +286,7 @@ declare function recursive<T = any>(id: string, callback: RecursiveCallback<T>):
|
|
|
285
286
|
* a.validate(StringSchema, "hello world") // true
|
|
286
287
|
* a.validate(StringSchema, 10) // false
|
|
287
288
|
*/
|
|
288
|
-
declare function string(opts?: ASchemaOptions): AScalarSchema<
|
|
289
|
+
declare function string(opts?: ASchemaOptions): AScalarSchema<'string', string>;
|
|
289
290
|
declare function serializeString(input: string): string;
|
|
290
291
|
declare const STR_ESCAPE: RegExp;
|
|
291
292
|
declare function serializeSmallString(input: string): string;
|
|
@@ -297,7 +298,7 @@ declare function serializeSmallString(input: string): string;
|
|
|
297
298
|
* const Schema = a.timestamp();
|
|
298
299
|
* a.validate(Schema, new Date()) // true
|
|
299
300
|
*/
|
|
300
|
-
declare function timestamp(opts?: ASchemaOptions): AScalarSchema<
|
|
301
|
+
declare function timestamp(opts?: ASchemaOptions): AScalarSchema<'timestamp', Date>;
|
|
301
302
|
|
|
302
303
|
declare const _namespace_any: typeof any;
|
|
303
304
|
declare const _namespace_array: typeof array;
|
|
@@ -361,4 +362,10 @@ declare const int64Max: bigint;
|
|
|
361
362
|
declare const uint64Min: bigint;
|
|
362
363
|
declare const uint64Max: bigint;
|
|
363
364
|
|
|
364
|
-
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isSchemaFormProperties, isSchemaFormValues, isSchemaFormElements, isSchemaFormDiscriminator, isSchemaFormEmpty, isSchemaFormType, isSchemaFormEnum, isSchemaFormRef } from '@arrirpc/type-defs';
|
|
2
2
|
import { camelCase } from 'scule';
|
|
3
|
-
import { u as uint8Max, a as uint8Min, b as uint16Max, c as uint16Min, d as uint32Max, e as uint32Min, i as int8Max, f as int8Min, g as int16Max, h as int16Min, j as int32Max, k as int32Min, l as isAScalarSchema, m as isAObjectSchema, n as isAStringEnumSchema, o as isAAraySchema, p as isARecordSchema, q as isADiscriminatorSchema, r as isARefSchema, s as errors, V as ValidationError, t as
|
|
4
|
-
export {
|
|
3
|
+
import { u as uint8Max, a as uint8Min, b as uint16Max, c as uint16Min, d as uint32Max, e as uint32Min, i as int8Max, f as int8Min, g as int16Max, h as int16Min, j as int32Max, k as int32Min, l as isAScalarSchema, m as isAObjectSchema, n as isAStringEnumSchema, o as isAAraySchema, p as isARecordSchema, q as isADiscriminatorSchema, r as isARefSchema, s as errors, V as ValidationError, t as createStandardSchemaProperty, v as any, w as array, x as boolean, y as clone, z as coerce, A as discriminator, B as enumerator, C as extend, D as float32, E as float64, F as int16, G as int32, H as int64, I as int8, J as nullable, K as number, L as object, M as omit, N as optional, O as parse, P as partial, Q as pick, R as record, S as recursive, T as safeCoerce, U as safeParse, W as serialize, X as string, Y as stringEnum, Z as timestamp, _ as uint16, $ as uint32, a0 as uint64, a1 as uint8, a2 as validate, a3 as SCHEMA_METADATA } from './shared/schema.PNAcAdz3.mjs';
|
|
4
|
+
export { ah as NumberTypeValues, ac as STR_ESCAPE, aj as hideInvalidProperties, a5 as int64Max, a4 as int64Min, ag as isASchema, ai as isObject, af as isValidationError, a8 as parseObjectSchema, ae as sanitizeJson, aa as serializeObject, ad as serializeSmallString, ab as serializeString, a7 as uint64Max, a6 as uint64Min, a9 as validateObjectSchema } from './shared/schema.PNAcAdz3.mjs';
|
|
5
5
|
|
|
6
6
|
function createParsingTemplate(input, schema) {
|
|
7
7
|
const fallbackTemplate = `
|
|
@@ -1366,33 +1366,31 @@ function compile(schema) {
|
|
|
1366
1366
|
const parseFn = parser.fn;
|
|
1367
1367
|
const serializer = getCompiledSerializer(schema);
|
|
1368
1368
|
const serializeFn = serializer.fn;
|
|
1369
|
-
const validate = new Function(
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
} catch (err) {
|
|
1379
|
-
const errors$1 = errors(schema, input);
|
|
1380
|
-
let errorMessage = err instanceof Error ? err.message : "";
|
|
1381
|
-
if (errors$1.length) {
|
|
1382
|
-
errorMessage = errors$1[0].message ?? `Parsing error at ${errors$1[0].instancePath}`;
|
|
1383
|
-
}
|
|
1384
|
-
throw new ValidationError({
|
|
1385
|
-
message: errorMessage,
|
|
1386
|
-
errors: errors$1
|
|
1387
|
-
});
|
|
1369
|
+
const validate = new Function("input", validateCode);
|
|
1370
|
+
const parse = (input) => {
|
|
1371
|
+
try {
|
|
1372
|
+
return parseFn(input);
|
|
1373
|
+
} catch (err) {
|
|
1374
|
+
const errors$1 = errors(schema, input);
|
|
1375
|
+
let errorMessage = err instanceof Error ? err.message : "";
|
|
1376
|
+
if (errors$1.length) {
|
|
1377
|
+
errorMessage = errors$1[0].message ?? `Parsing error at ${errors$1[0].instancePath}`;
|
|
1388
1378
|
}
|
|
1389
|
-
|
|
1379
|
+
throw new ValidationError({
|
|
1380
|
+
message: errorMessage,
|
|
1381
|
+
errors: errors$1
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
const result = {
|
|
1386
|
+
validate,
|
|
1387
|
+
parse,
|
|
1390
1388
|
safeParse(input) {
|
|
1391
1389
|
try {
|
|
1392
|
-
const
|
|
1390
|
+
const result2 = parseFn(input);
|
|
1393
1391
|
return {
|
|
1394
1392
|
success: true,
|
|
1395
|
-
value:
|
|
1393
|
+
value: result2
|
|
1396
1394
|
};
|
|
1397
1395
|
} catch (err) {
|
|
1398
1396
|
const errors$1 = errors(schema, input);
|
|
@@ -1425,8 +1423,10 @@ function compile(schema) {
|
|
|
1425
1423
|
validate: validateCode,
|
|
1426
1424
|
parse: parser.code,
|
|
1427
1425
|
serialize: serializer.code
|
|
1428
|
-
}
|
|
1426
|
+
},
|
|
1427
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
1429
1428
|
};
|
|
1429
|
+
return result;
|
|
1430
1430
|
}
|
|
1431
1431
|
function getCompiledParser(input, schema) {
|
|
1432
1432
|
const code = createParsingTemplate(input, schema);
|
|
@@ -2133,7 +2133,7 @@ function isAdaptedSchema(input) {
|
|
|
2133
2133
|
return input.metadata[SCHEMA_METADATA]._isAdapted === true;
|
|
2134
2134
|
}
|
|
2135
2135
|
function validatorFromAdaptedSchema(schema) {
|
|
2136
|
-
|
|
2136
|
+
const result = {
|
|
2137
2137
|
compiledCode: {
|
|
2138
2138
|
parse: "",
|
|
2139
2139
|
serialize: "",
|
|
@@ -2155,13 +2155,13 @@ function validatorFromAdaptedSchema(schema) {
|
|
|
2155
2155
|
errors: []
|
|
2156
2156
|
};
|
|
2157
2157
|
try {
|
|
2158
|
-
const
|
|
2158
|
+
const result2 = schema.metadata[SCHEMA_METADATA].parse(
|
|
2159
2159
|
input,
|
|
2160
2160
|
context
|
|
2161
2161
|
);
|
|
2162
2162
|
return {
|
|
2163
2163
|
success: true,
|
|
2164
|
-
value:
|
|
2164
|
+
value: result2
|
|
2165
2165
|
};
|
|
2166
2166
|
} catch (err) {
|
|
2167
2167
|
if (err instanceof ValidationError) {
|
|
@@ -2186,8 +2186,13 @@ function validatorFromAdaptedSchema(schema) {
|
|
|
2186
2186
|
errors: []
|
|
2187
2187
|
};
|
|
2188
2188
|
return schema.metadata[SCHEMA_METADATA].serialize(input, context);
|
|
2189
|
-
}
|
|
2189
|
+
},
|
|
2190
|
+
"~standard": createStandardSchemaProperty(
|
|
2191
|
+
schema.metadata[SCHEMA_METADATA].validate,
|
|
2192
|
+
schema.metadata[SCHEMA_METADATA].parse
|
|
2193
|
+
)
|
|
2190
2194
|
};
|
|
2195
|
+
return result;
|
|
2191
2196
|
}
|
|
2192
2197
|
|
|
2193
|
-
export { SCHEMA_METADATA, ValidationError, _namespace as a, any, array, boolean, clone, coerce, compile, discriminator, enumerator, errors, extend, float32, float64, getCompiledParser, getCompiledSerializer, createParsingTemplate as getSchemaParsingCode, createSerializationV2Template as getSchemaSerializationCode, createValidationTemplate as getSchemaValidationCode, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int8, int8Max, int8Min, isAAraySchema, isADiscriminatorSchema, isAObjectSchema, isARecordSchema, isARefSchema, isAScalarSchema, isAStringEnumSchema, isAdaptedSchema, nullable, number, object, omit, optional, parse, partial, pick, record, recursive, safeCoerce, safeParse, serialize, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint8, uint8Max, uint8Min, validate, validatorFromAdaptedSchema };
|
|
2198
|
+
export { SCHEMA_METADATA, ValidationError, _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, int16, int16Max, int16Min, int32, int32Max, int32Min, int64, int8, int8Max, int8Min, isAAraySchema, isADiscriminatorSchema, isAObjectSchema, isARecordSchema, isARefSchema, isAScalarSchema, isAStringEnumSchema, isAdaptedSchema, nullable, number, object, omit, optional, parse, partial, pick, record, recursive, safeCoerce, safeParse, serialize, string, stringEnum, timestamp, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint8, uint8Max, uint8Min, validate, validatorFromAdaptedSchema };
|