@arrirpc/schema 0.74.0 → 0.74.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 +4 -1
- package/dist/adapters.d.cts +1 -1
- package/dist/adapters.d.mts +1 -1
- package/dist/adapters.d.ts +1 -1
- package/dist/index.cjs +14 -48
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +15 -49
- package/dist/shared/{schema.BYXPajpl.d.cts → schema.CGpRJ4kH.d.cts} +1 -1
- package/dist/shared/{schema.BYXPajpl.d.mts → schema.CGpRJ4kH.d.mts} +1 -1
- package/dist/shared/{schema.BYXPajpl.d.ts → schema.CGpRJ4kH.d.ts} +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -988,7 +988,7 @@ const BinaryTreeSchema = a.recursive('BTree', (self) =>
|
|
|
988
988
|
|
|
989
989
|
## Compiled Validators
|
|
990
990
|
|
|
991
|
-
`@arrirpc/schema` comes with a high performance JIT compiler that transforms Arri Schemas into highly optimized validation, parsing, serialization functions. The result of the compilation also implements the [standard-schema](https://github.com/standard-schema/standard-schema) interface, meaning it can be passed into any library that accepts standard-schema.
|
|
991
|
+
`@arrirpc/schema` comes with a high performance JIT compiler that transforms Arri Schemas into highly optimized validation, parsing, coercion, and serialization functions. The result of the compilation also implements the [standard-schema](https://github.com/standard-schema/standard-schema) interface, meaning it can be passed into any library that accepts standard-schema.
|
|
992
992
|
|
|
993
993
|
```ts
|
|
994
994
|
const User = a.object({
|
|
@@ -1002,6 +1002,8 @@ const $$User = a.compile(User);
|
|
|
1002
1002
|
$$User.validate(someInput);
|
|
1003
1003
|
$$User.parse(someJson);
|
|
1004
1004
|
$$User.parseUnsafe(someJson);
|
|
1005
|
+
$$User.coerce(someObject);
|
|
1006
|
+
$$User.coerceUnsafe(someObject);
|
|
1005
1007
|
$$User.serialize({ id: '1', email: null, created: new Date() });
|
|
1006
1008
|
$$User.serializeUnsafe({ id: '1', email: null, created: new Date() });
|
|
1007
1009
|
```
|
|
@@ -1013,6 +1015,7 @@ You can also use `a.compile` for code generation. The compiler result gives you
|
|
|
1013
1015
|
```ts
|
|
1014
1016
|
$$User.compiledCode.validate; // the generated validation code
|
|
1015
1017
|
$$User.compiledCode.parse; // the generated parsing code
|
|
1018
|
+
$$User.compiledCode.coerce; // the generated coercion code
|
|
1016
1019
|
$$User.compiledCode.serialize; // the generated serialization code
|
|
1017
1020
|
```
|
|
1018
1021
|
|
package/dist/adapters.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import { V as ValidationContext, A as ASchema } from './shared/schema.
|
|
2
|
+
import { V as ValidationContext, A as ASchema } from './shared/schema.CGpRJ4kH.cjs';
|
|
3
3
|
import '@arrirpc/type-defs';
|
|
4
4
|
|
|
5
5
|
declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined, vendor?: string): StandardSchemaV1<T>['~standard'];
|
package/dist/adapters.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import { V as ValidationContext, A as ASchema } from './shared/schema.
|
|
2
|
+
import { V as ValidationContext, A as ASchema } from './shared/schema.CGpRJ4kH.mjs';
|
|
3
3
|
import '@arrirpc/type-defs';
|
|
4
4
|
|
|
5
5
|
declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined, vendor?: string): StandardSchemaV1<T>['~standard'];
|
package/dist/adapters.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import { V as ValidationContext, A as ASchema } from './shared/schema.
|
|
2
|
+
import { V as ValidationContext, A as ASchema } from './shared/schema.CGpRJ4kH.js';
|
|
3
3
|
import '@arrirpc/type-defs';
|
|
4
4
|
|
|
5
5
|
declare function createStandardSchemaProperty<T>(validate: (input: unknown) => input is T, parse: (input: unknown, ctx: ValidationContext) => T | undefined, vendor?: string): StandardSchemaV1<T>['~standard'];
|
package/dist/index.cjs
CHANGED
|
@@ -677,9 +677,7 @@ function createSerializationV2Template(inputName, schema) {
|
|
|
677
677
|
instancePath: "",
|
|
678
678
|
outputPrefix: "",
|
|
679
679
|
needsSanitization: [],
|
|
680
|
-
subFunctions
|
|
681
|
-
shouldCoerce: undefined
|
|
682
|
-
};
|
|
680
|
+
subFunctions};
|
|
683
681
|
const result = template(context);
|
|
684
682
|
if (typeDefs.isSchemaFormType(schema) || typeDefs.isSchemaFormEnum(schema)) {
|
|
685
683
|
return result;
|
|
@@ -917,9 +915,7 @@ function objectTemplate$1(input) {
|
|
|
917
915
|
schemaPath: `${input.schemaPath}/properties/${key}`,
|
|
918
916
|
outputPrefix: includeComma ? `,"${key}":` : `"${key}":`,
|
|
919
917
|
needsSanitization: input.needsSanitization,
|
|
920
|
-
subFunctions: input.subFunctions
|
|
921
|
-
shouldCoerce: undefined
|
|
922
|
-
});
|
|
918
|
+
subFunctions: input.subFunctions});
|
|
923
919
|
templateParts.push(innerTemplate);
|
|
924
920
|
}
|
|
925
921
|
if (isAllOptionalKeys) {
|
|
@@ -942,9 +938,7 @@ function objectTemplate$1(input) {
|
|
|
942
938
|
targetVal: input.targetVal,
|
|
943
939
|
outputPrefix: `"${key}":`,
|
|
944
940
|
needsSanitization: input.needsSanitization,
|
|
945
|
-
subFunctions: input.subFunctions
|
|
946
|
-
shouldCoerce: undefined
|
|
947
|
-
});
|
|
941
|
+
subFunctions: input.subFunctions});
|
|
948
942
|
const innerTemplateWithComma = template({
|
|
949
943
|
schema: optionalPropSchema,
|
|
950
944
|
schemaPath: `${input.schemaPath}/optionalProperties/${key}`,
|
|
@@ -953,9 +947,7 @@ function objectTemplate$1(input) {
|
|
|
953
947
|
targetVal: input.targetVal,
|
|
954
948
|
outputPrefix: `,"${key}":`,
|
|
955
949
|
needsSanitization: input.needsSanitization,
|
|
956
|
-
subFunctions: input.subFunctions
|
|
957
|
-
shouldCoerce: undefined
|
|
958
|
-
});
|
|
950
|
+
subFunctions: input.subFunctions});
|
|
959
951
|
templateParts.push(`if (typeof ${innerVal} !== 'undefined') {
|
|
960
952
|
if (${hasFieldsVar}) {
|
|
961
953
|
${innerTemplateWithComma}
|
|
@@ -981,9 +973,7 @@ function objectTemplate$1(input) {
|
|
|
981
973
|
targetVal: "json",
|
|
982
974
|
outputPrefix: `,"${key}":`,
|
|
983
975
|
needsSanitization: input.needsSanitization,
|
|
984
|
-
subFunctions: input.subFunctions
|
|
985
|
-
shouldCoerce: undefined
|
|
986
|
-
});
|
|
976
|
+
subFunctions: input.subFunctions});
|
|
987
977
|
const completeInnerTemplate = `if (typeof ${innerVal} !== 'undefined') {
|
|
988
978
|
${innerTemplate}
|
|
989
979
|
}`;
|
|
@@ -1032,9 +1022,7 @@ function arrayTemplate$1(input) {
|
|
|
1032
1022
|
targetVal: input.targetVal,
|
|
1033
1023
|
outputPrefix: "",
|
|
1034
1024
|
needsSanitization: input.needsSanitization,
|
|
1035
|
-
subFunctions: input.subFunctions
|
|
1036
|
-
shouldCoerce: undefined
|
|
1037
|
-
});
|
|
1025
|
+
subFunctions: input.subFunctions});
|
|
1038
1026
|
templateParts.push(`for (let i = 0; i < ${input.val}.length; i++) {
|
|
1039
1027
|
const ${itemVarName} = ${input.val}[i];
|
|
1040
1028
|
if (i !== 0) {
|
|
@@ -1067,9 +1055,7 @@ function recordTemplate$1(input) {
|
|
|
1067
1055
|
targetVal: input.targetVal,
|
|
1068
1056
|
outputPrefix: "",
|
|
1069
1057
|
needsSanitization: input.needsSanitization,
|
|
1070
|
-
subFunctions: input.subFunctions
|
|
1071
|
-
shouldCoerce: undefined
|
|
1072
|
-
});
|
|
1058
|
+
subFunctions: input.subFunctions});
|
|
1073
1059
|
templateParts.push(`for (let i = 0; i < ${keysVarName}.length; i++) {
|
|
1074
1060
|
const key = ${keysVarName}[i];
|
|
1075
1061
|
const innerVal = ${input.val}[key];
|
|
@@ -1137,9 +1123,7 @@ function discriminatorTemplate$1(input) {
|
|
|
1137
1123
|
discriminatorValue: val,
|
|
1138
1124
|
outputPrefix: input.outputPrefix,
|
|
1139
1125
|
needsSanitization: input.needsSanitization,
|
|
1140
|
-
subFunctions: input.subFunctions
|
|
1141
|
-
shouldCoerce: undefined
|
|
1142
|
-
});
|
|
1126
|
+
subFunctions: input.subFunctions});
|
|
1143
1127
|
templateParts.push(`case '${val}': {
|
|
1144
1128
|
${innerTemplate}
|
|
1145
1129
|
break;
|
|
@@ -1207,13 +1191,10 @@ function createValidationTemplate(inputName, schema) {
|
|
|
1207
1191
|
const subFunctions = {};
|
|
1208
1192
|
const template = schemaTemplate({
|
|
1209
1193
|
val: inputName,
|
|
1210
|
-
targetVal: "",
|
|
1211
1194
|
schema,
|
|
1212
1195
|
schemaPath: ``,
|
|
1213
1196
|
instancePath: "",
|
|
1214
|
-
subFunctions
|
|
1215
|
-
shouldCoerce: undefined
|
|
1216
|
-
});
|
|
1197
|
+
subFunctions});
|
|
1217
1198
|
const subFunctionBodies = Object.keys(subFunctions).map(
|
|
1218
1199
|
(key) => subFunctions[key]
|
|
1219
1200
|
);
|
|
@@ -1333,10 +1314,7 @@ function objectTemplate(input) {
|
|
|
1333
1314
|
schemaPath: `${input.schemaPath}/properties/${key}`,
|
|
1334
1315
|
instancePath: `${input.instancePath}/${key}`,
|
|
1335
1316
|
val: `${input.val}.${key}`,
|
|
1336
|
-
|
|
1337
|
-
subFunctions: input.subFunctions,
|
|
1338
|
-
shouldCoerce: undefined
|
|
1339
|
-
})
|
|
1317
|
+
subFunctions: input.subFunctions})
|
|
1340
1318
|
);
|
|
1341
1319
|
}
|
|
1342
1320
|
if (input.schema.optionalProperties) {
|
|
@@ -1347,10 +1325,7 @@ function objectTemplate(input) {
|
|
|
1347
1325
|
schemaPath: `${input.schemaPath}/optionalProperties/${key}`,
|
|
1348
1326
|
instancePath: `${input.instancePath}/${key}`,
|
|
1349
1327
|
val: `${input.val}.${key}`,
|
|
1350
|
-
|
|
1351
|
-
subFunctions: input.subFunctions,
|
|
1352
|
-
shouldCoerce: undefined
|
|
1353
|
-
});
|
|
1328
|
+
subFunctions: input.subFunctions});
|
|
1354
1329
|
parts.push(
|
|
1355
1330
|
`(typeof ${input.val}.${key} === 'undefined' || (${template}))`
|
|
1356
1331
|
);
|
|
@@ -1384,10 +1359,7 @@ function arrayTemplate(input) {
|
|
|
1384
1359
|
instancePath: `${input.instancePath}/item`,
|
|
1385
1360
|
schemaPath: `${input.schemaPath}/elements`,
|
|
1386
1361
|
schema: input.schema.elements,
|
|
1387
|
-
|
|
1388
|
-
subFunctions: input.subFunctions,
|
|
1389
|
-
shouldCoerce: undefined
|
|
1390
|
-
});
|
|
1362
|
+
subFunctions: input.subFunctions});
|
|
1391
1363
|
if (input.schema.nullable) {
|
|
1392
1364
|
return `((Array.isArray(${input.val}) && ${input.val}.every((item) => ${innerTemplate})) || ${input.val} === null)`;
|
|
1393
1365
|
}
|
|
@@ -1399,10 +1371,7 @@ function recordTemplate(input) {
|
|
|
1399
1371
|
instancePath: `${input.instancePath}`,
|
|
1400
1372
|
schemaPath: `${input.schemaPath}/values`,
|
|
1401
1373
|
val: `${input.val}[key]`,
|
|
1402
|
-
|
|
1403
|
-
subFunctions: input.subFunctions,
|
|
1404
|
-
shouldCoerce: undefined
|
|
1405
|
-
});
|
|
1374
|
+
subFunctions: input.subFunctions});
|
|
1406
1375
|
const mainTemplate = `typeof ${input.val} === 'object' && ${input.val} !== null && Object.keys(${input.val}).every((key) => ${subTemplate})`;
|
|
1407
1376
|
if (input.schema.nullable) {
|
|
1408
1377
|
return `((${mainTemplate}) || ${input.val} === null)`;
|
|
@@ -1419,15 +1388,12 @@ function discriminatorTemplate(input) {
|
|
|
1419
1388
|
parts.push(
|
|
1420
1389
|
objectTemplate({
|
|
1421
1390
|
val: input.val,
|
|
1422
|
-
targetVal: "",
|
|
1423
1391
|
schema: subSchema,
|
|
1424
1392
|
schemaPath: `${input.schemaPath}/mapping/${discriminatorVal}`,
|
|
1425
1393
|
instancePath: input.instancePath,
|
|
1426
1394
|
discriminatorKey: input.schema.discriminator,
|
|
1427
1395
|
discriminatorValue: discriminatorVal,
|
|
1428
|
-
subFunctions: input.subFunctions
|
|
1429
|
-
shouldCoerce: undefined
|
|
1430
|
-
})
|
|
1396
|
+
subFunctions: input.subFunctions})
|
|
1431
1397
|
);
|
|
1432
1398
|
}
|
|
1433
1399
|
let mainTemplate = `typeof ${input.val} === 'object' && ${input.val} !== null && (${parts.join(" || ")})`;
|
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
|
|
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.
|
|
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, V as ValidationContext, m as ARecordSchemaWithAdapters, n as ARefSchema, o as ValueError, p as InferSubType } from './shared/schema.CGpRJ4kH.cjs';
|
|
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.CGpRJ4kH.cjs';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
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
|
|
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.
|
|
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, V as ValidationContext, m as ARecordSchemaWithAdapters, n as ARefSchema, o as ValueError, p as InferSubType } from './shared/schema.CGpRJ4kH.mjs';
|
|
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.CGpRJ4kH.mjs';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
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
|
|
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.
|
|
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, V as ValidationContext, m as ARecordSchemaWithAdapters, n as ARefSchema, o as ValueError, p as InferSubType } from './shared/schema.CGpRJ4kH.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.CGpRJ4kH.js';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isSchemaFormProperties, isSchemaFormValues, isSchemaFormElements, isSchemaFormDiscriminator, isSchemaFormEmpty, isSchemaFormType, isSchemaFormEnum, isSchemaFormRef } from '@arrirpc/type-defs';
|
|
2
|
-
import { i as isAScalarSchema, a as isAObjectSchema, b as isAStringEnumSchema, c as isAAraySchema, d as isARecordSchema, e as isADiscriminatorSchema, f as isARefSchema, g as createStandardSchemaProperty, n as newValidationContext,
|
|
2
|
+
import { i as isAScalarSchema, a as isAObjectSchema, b as isAStringEnumSchema, c as isAAraySchema, d as isARecordSchema, e as isADiscriminatorSchema, f as isARefSchema, g as createStandardSchemaProperty, n as newValidationContext, h as hideInvalidProperties, V as VALIDATOR_KEY, j as isObject } from './shared/schema.CZrExOkx.mjs';
|
|
3
3
|
export { N as NumberTypeValues, k as isASchema } from './shared/schema.CZrExOkx.mjs';
|
|
4
4
|
import { camelCase } from 'scule';
|
|
5
5
|
|
|
@@ -676,9 +676,7 @@ function createSerializationV2Template(inputName, schema) {
|
|
|
676
676
|
instancePath: "",
|
|
677
677
|
outputPrefix: "",
|
|
678
678
|
needsSanitization: [],
|
|
679
|
-
subFunctions
|
|
680
|
-
shouldCoerce: undefined
|
|
681
|
-
};
|
|
679
|
+
subFunctions};
|
|
682
680
|
const result = template(context);
|
|
683
681
|
if (isSchemaFormType(schema) || isSchemaFormEnum(schema)) {
|
|
684
682
|
return result;
|
|
@@ -916,9 +914,7 @@ function objectTemplate$1(input) {
|
|
|
916
914
|
schemaPath: `${input.schemaPath}/properties/${key}`,
|
|
917
915
|
outputPrefix: includeComma ? `,"${key}":` : `"${key}":`,
|
|
918
916
|
needsSanitization: input.needsSanitization,
|
|
919
|
-
subFunctions: input.subFunctions
|
|
920
|
-
shouldCoerce: undefined
|
|
921
|
-
});
|
|
917
|
+
subFunctions: input.subFunctions});
|
|
922
918
|
templateParts.push(innerTemplate);
|
|
923
919
|
}
|
|
924
920
|
if (isAllOptionalKeys) {
|
|
@@ -941,9 +937,7 @@ function objectTemplate$1(input) {
|
|
|
941
937
|
targetVal: input.targetVal,
|
|
942
938
|
outputPrefix: `"${key}":`,
|
|
943
939
|
needsSanitization: input.needsSanitization,
|
|
944
|
-
subFunctions: input.subFunctions
|
|
945
|
-
shouldCoerce: undefined
|
|
946
|
-
});
|
|
940
|
+
subFunctions: input.subFunctions});
|
|
947
941
|
const innerTemplateWithComma = template({
|
|
948
942
|
schema: optionalPropSchema,
|
|
949
943
|
schemaPath: `${input.schemaPath}/optionalProperties/${key}`,
|
|
@@ -952,9 +946,7 @@ function objectTemplate$1(input) {
|
|
|
952
946
|
targetVal: input.targetVal,
|
|
953
947
|
outputPrefix: `,"${key}":`,
|
|
954
948
|
needsSanitization: input.needsSanitization,
|
|
955
|
-
subFunctions: input.subFunctions
|
|
956
|
-
shouldCoerce: undefined
|
|
957
|
-
});
|
|
949
|
+
subFunctions: input.subFunctions});
|
|
958
950
|
templateParts.push(`if (typeof ${innerVal} !== 'undefined') {
|
|
959
951
|
if (${hasFieldsVar}) {
|
|
960
952
|
${innerTemplateWithComma}
|
|
@@ -980,9 +972,7 @@ function objectTemplate$1(input) {
|
|
|
980
972
|
targetVal: "json",
|
|
981
973
|
outputPrefix: `,"${key}":`,
|
|
982
974
|
needsSanitization: input.needsSanitization,
|
|
983
|
-
subFunctions: input.subFunctions
|
|
984
|
-
shouldCoerce: undefined
|
|
985
|
-
});
|
|
975
|
+
subFunctions: input.subFunctions});
|
|
986
976
|
const completeInnerTemplate = `if (typeof ${innerVal} !== 'undefined') {
|
|
987
977
|
${innerTemplate}
|
|
988
978
|
}`;
|
|
@@ -1031,9 +1021,7 @@ function arrayTemplate$1(input) {
|
|
|
1031
1021
|
targetVal: input.targetVal,
|
|
1032
1022
|
outputPrefix: "",
|
|
1033
1023
|
needsSanitization: input.needsSanitization,
|
|
1034
|
-
subFunctions: input.subFunctions
|
|
1035
|
-
shouldCoerce: undefined
|
|
1036
|
-
});
|
|
1024
|
+
subFunctions: input.subFunctions});
|
|
1037
1025
|
templateParts.push(`for (let i = 0; i < ${input.val}.length; i++) {
|
|
1038
1026
|
const ${itemVarName} = ${input.val}[i];
|
|
1039
1027
|
if (i !== 0) {
|
|
@@ -1066,9 +1054,7 @@ function recordTemplate$1(input) {
|
|
|
1066
1054
|
targetVal: input.targetVal,
|
|
1067
1055
|
outputPrefix: "",
|
|
1068
1056
|
needsSanitization: input.needsSanitization,
|
|
1069
|
-
subFunctions: input.subFunctions
|
|
1070
|
-
shouldCoerce: undefined
|
|
1071
|
-
});
|
|
1057
|
+
subFunctions: input.subFunctions});
|
|
1072
1058
|
templateParts.push(`for (let i = 0; i < ${keysVarName}.length; i++) {
|
|
1073
1059
|
const key = ${keysVarName}[i];
|
|
1074
1060
|
const innerVal = ${input.val}[key];
|
|
@@ -1136,9 +1122,7 @@ function discriminatorTemplate$1(input) {
|
|
|
1136
1122
|
discriminatorValue: val,
|
|
1137
1123
|
outputPrefix: input.outputPrefix,
|
|
1138
1124
|
needsSanitization: input.needsSanitization,
|
|
1139
|
-
subFunctions: input.subFunctions
|
|
1140
|
-
shouldCoerce: undefined
|
|
1141
|
-
});
|
|
1125
|
+
subFunctions: input.subFunctions});
|
|
1142
1126
|
templateParts.push(`case '${val}': {
|
|
1143
1127
|
${innerTemplate}
|
|
1144
1128
|
break;
|
|
@@ -1206,13 +1190,10 @@ function createValidationTemplate(inputName, schema) {
|
|
|
1206
1190
|
const subFunctions = {};
|
|
1207
1191
|
const template = schemaTemplate({
|
|
1208
1192
|
val: inputName,
|
|
1209
|
-
targetVal: "",
|
|
1210
1193
|
schema,
|
|
1211
1194
|
schemaPath: ``,
|
|
1212
1195
|
instancePath: "",
|
|
1213
|
-
subFunctions
|
|
1214
|
-
shouldCoerce: undefined
|
|
1215
|
-
});
|
|
1196
|
+
subFunctions});
|
|
1216
1197
|
const subFunctionBodies = Object.keys(subFunctions).map(
|
|
1217
1198
|
(key) => subFunctions[key]
|
|
1218
1199
|
);
|
|
@@ -1332,10 +1313,7 @@ function objectTemplate(input) {
|
|
|
1332
1313
|
schemaPath: `${input.schemaPath}/properties/${key}`,
|
|
1333
1314
|
instancePath: `${input.instancePath}/${key}`,
|
|
1334
1315
|
val: `${input.val}.${key}`,
|
|
1335
|
-
|
|
1336
|
-
subFunctions: input.subFunctions,
|
|
1337
|
-
shouldCoerce: undefined
|
|
1338
|
-
})
|
|
1316
|
+
subFunctions: input.subFunctions})
|
|
1339
1317
|
);
|
|
1340
1318
|
}
|
|
1341
1319
|
if (input.schema.optionalProperties) {
|
|
@@ -1346,10 +1324,7 @@ function objectTemplate(input) {
|
|
|
1346
1324
|
schemaPath: `${input.schemaPath}/optionalProperties/${key}`,
|
|
1347
1325
|
instancePath: `${input.instancePath}/${key}`,
|
|
1348
1326
|
val: `${input.val}.${key}`,
|
|
1349
|
-
|
|
1350
|
-
subFunctions: input.subFunctions,
|
|
1351
|
-
shouldCoerce: undefined
|
|
1352
|
-
});
|
|
1327
|
+
subFunctions: input.subFunctions});
|
|
1353
1328
|
parts.push(
|
|
1354
1329
|
`(typeof ${input.val}.${key} === 'undefined' || (${template}))`
|
|
1355
1330
|
);
|
|
@@ -1383,10 +1358,7 @@ function arrayTemplate(input) {
|
|
|
1383
1358
|
instancePath: `${input.instancePath}/item`,
|
|
1384
1359
|
schemaPath: `${input.schemaPath}/elements`,
|
|
1385
1360
|
schema: input.schema.elements,
|
|
1386
|
-
|
|
1387
|
-
subFunctions: input.subFunctions,
|
|
1388
|
-
shouldCoerce: undefined
|
|
1389
|
-
});
|
|
1361
|
+
subFunctions: input.subFunctions});
|
|
1390
1362
|
if (input.schema.nullable) {
|
|
1391
1363
|
return `((Array.isArray(${input.val}) && ${input.val}.every((item) => ${innerTemplate})) || ${input.val} === null)`;
|
|
1392
1364
|
}
|
|
@@ -1398,10 +1370,7 @@ function recordTemplate(input) {
|
|
|
1398
1370
|
instancePath: `${input.instancePath}`,
|
|
1399
1371
|
schemaPath: `${input.schemaPath}/values`,
|
|
1400
1372
|
val: `${input.val}[key]`,
|
|
1401
|
-
|
|
1402
|
-
subFunctions: input.subFunctions,
|
|
1403
|
-
shouldCoerce: undefined
|
|
1404
|
-
});
|
|
1373
|
+
subFunctions: input.subFunctions});
|
|
1405
1374
|
const mainTemplate = `typeof ${input.val} === 'object' && ${input.val} !== null && Object.keys(${input.val}).every((key) => ${subTemplate})`;
|
|
1406
1375
|
if (input.schema.nullable) {
|
|
1407
1376
|
return `((${mainTemplate}) || ${input.val} === null)`;
|
|
@@ -1418,15 +1387,12 @@ function discriminatorTemplate(input) {
|
|
|
1418
1387
|
parts.push(
|
|
1419
1388
|
objectTemplate({
|
|
1420
1389
|
val: input.val,
|
|
1421
|
-
targetVal: "",
|
|
1422
1390
|
schema: subSchema,
|
|
1423
1391
|
schemaPath: `${input.schemaPath}/mapping/${discriminatorVal}`,
|
|
1424
1392
|
instancePath: input.instancePath,
|
|
1425
1393
|
discriminatorKey: input.schema.discriminator,
|
|
1426
1394
|
discriminatorValue: discriminatorVal,
|
|
1427
|
-
subFunctions: input.subFunctions
|
|
1428
|
-
shouldCoerce: undefined
|
|
1429
|
-
})
|
|
1395
|
+
subFunctions: input.subFunctions})
|
|
1430
1396
|
);
|
|
1431
1397
|
}
|
|
1432
1398
|
let mainTemplate = `typeof ${input.val} === 'object' && ${input.val} !== null && (${parts.join(" || ")})`;
|
|
@@ -169,4 +169,4 @@ interface ARefSchema<T> extends ASchema<T> {
|
|
|
169
169
|
declare function isARefSchema(input: unknown): input is ARefSchema<any>;
|
|
170
170
|
type ARefSchemaWithAdapters<T> = ARefSchema<T> & WithAdapters<T>;
|
|
171
171
|
|
|
172
|
-
export { type ASchema as A, type Resolve as B, type AScalarSchema as C, isAScalarSchema as D, type NumberType as E, isAAraySchema as F, type AArraySchemaWithAdapters as G, type AStringEnumSchema as H, type InferType as I, isAStringEnumSchema as J, type ADiscriminatorSchema as K, isADiscriminatorSchema as L, type MaybeNullable as M, NumberTypeValues as N, type ARecordSchema as O, type PartialBy as P, isARecordSchema as Q, type Result as R, type SchemaValidator as S, isAObjectSchema as T, type InferObjectRawType as U, type ValidationContext as V, type WithAdapters as W, isObject as X, isARefSchema as Y, type ARefSchemaWithAdapters as Z, type ASchemaStrict as a, type ASchemaOptions as b, type ASchemaWithAdapters as c, type AArraySchema as d, type AScalarSchemaWithAdapters as e, type AObjectSchema as f, type ADiscriminatorSchemaWithAdapters as g, type ResolveObject as h, type AStringEnumSchemaWithAdapters as i, type
|
|
172
|
+
export { type ASchema as A, type Resolve as B, type AScalarSchema as C, isAScalarSchema as D, type NumberType as E, isAAraySchema as F, type AArraySchemaWithAdapters as G, type AStringEnumSchema as H, type InferType as I, isAStringEnumSchema as J, type ADiscriminatorSchema as K, isADiscriminatorSchema as L, type MaybeNullable as M, NumberTypeValues as N, type ARecordSchema as O, type PartialBy as P, isARecordSchema as Q, type Result as R, type SchemaValidator as S, isAObjectSchema as T, type InferObjectRawType as U, type ValidationContext as V, type WithAdapters as W, isObject as X, isARefSchema as Y, type ARefSchemaWithAdapters as Z, type ASchemaStrict as a, type ASchemaOptions as b, type ASchemaWithAdapters as c, type AArraySchema as d, type AScalarSchemaWithAdapters as e, type AObjectSchema as f, type ADiscriminatorSchemaWithAdapters as g, type ResolveObject as h, type AStringEnumSchemaWithAdapters as i, type AObjectSchemaWithAdapters as j, type AObjectSchemaOptions as k, type InferObjectOutput as l, type ARecordSchemaWithAdapters as m, type ARefSchema as n, type ValueError as o, type InferSubType as p, isValueError as q, errorMessageFromErrors as r, ValidationException as s, isValidationException as t, type ResultSuccess as u, type ResultFailure as v, newValidationContext as w, VALIDATOR_KEY as x, type SchemaMetadata as y, isASchema as z };
|
|
@@ -169,4 +169,4 @@ interface ARefSchema<T> extends ASchema<T> {
|
|
|
169
169
|
declare function isARefSchema(input: unknown): input is ARefSchema<any>;
|
|
170
170
|
type ARefSchemaWithAdapters<T> = ARefSchema<T> & WithAdapters<T>;
|
|
171
171
|
|
|
172
|
-
export { type ASchema as A, type Resolve as B, type AScalarSchema as C, isAScalarSchema as D, type NumberType as E, isAAraySchema as F, type AArraySchemaWithAdapters as G, type AStringEnumSchema as H, type InferType as I, isAStringEnumSchema as J, type ADiscriminatorSchema as K, isADiscriminatorSchema as L, type MaybeNullable as M, NumberTypeValues as N, type ARecordSchema as O, type PartialBy as P, isARecordSchema as Q, type Result as R, type SchemaValidator as S, isAObjectSchema as T, type InferObjectRawType as U, type ValidationContext as V, type WithAdapters as W, isObject as X, isARefSchema as Y, type ARefSchemaWithAdapters as Z, type ASchemaStrict as a, type ASchemaOptions as b, type ASchemaWithAdapters as c, type AArraySchema as d, type AScalarSchemaWithAdapters as e, type AObjectSchema as f, type ADiscriminatorSchemaWithAdapters as g, type ResolveObject as h, type AStringEnumSchemaWithAdapters as i, type
|
|
172
|
+
export { type ASchema as A, type Resolve as B, type AScalarSchema as C, isAScalarSchema as D, type NumberType as E, isAAraySchema as F, type AArraySchemaWithAdapters as G, type AStringEnumSchema as H, type InferType as I, isAStringEnumSchema as J, type ADiscriminatorSchema as K, isADiscriminatorSchema as L, type MaybeNullable as M, NumberTypeValues as N, type ARecordSchema as O, type PartialBy as P, isARecordSchema as Q, type Result as R, type SchemaValidator as S, isAObjectSchema as T, type InferObjectRawType as U, type ValidationContext as V, type WithAdapters as W, isObject as X, isARefSchema as Y, type ARefSchemaWithAdapters as Z, type ASchemaStrict as a, type ASchemaOptions as b, type ASchemaWithAdapters as c, type AArraySchema as d, type AScalarSchemaWithAdapters as e, type AObjectSchema as f, type ADiscriminatorSchemaWithAdapters as g, type ResolveObject as h, type AStringEnumSchemaWithAdapters as i, type AObjectSchemaWithAdapters as j, type AObjectSchemaOptions as k, type InferObjectOutput as l, type ARecordSchemaWithAdapters as m, type ARefSchema as n, type ValueError as o, type InferSubType as p, isValueError as q, errorMessageFromErrors as r, ValidationException as s, isValidationException as t, type ResultSuccess as u, type ResultFailure as v, newValidationContext as w, VALIDATOR_KEY as x, type SchemaMetadata as y, isASchema as z };
|
|
@@ -169,4 +169,4 @@ interface ARefSchema<T> extends ASchema<T> {
|
|
|
169
169
|
declare function isARefSchema(input: unknown): input is ARefSchema<any>;
|
|
170
170
|
type ARefSchemaWithAdapters<T> = ARefSchema<T> & WithAdapters<T>;
|
|
171
171
|
|
|
172
|
-
export { type ASchema as A, type Resolve as B, type AScalarSchema as C, isAScalarSchema as D, type NumberType as E, isAAraySchema as F, type AArraySchemaWithAdapters as G, type AStringEnumSchema as H, type InferType as I, isAStringEnumSchema as J, type ADiscriminatorSchema as K, isADiscriminatorSchema as L, type MaybeNullable as M, NumberTypeValues as N, type ARecordSchema as O, type PartialBy as P, isARecordSchema as Q, type Result as R, type SchemaValidator as S, isAObjectSchema as T, type InferObjectRawType as U, type ValidationContext as V, type WithAdapters as W, isObject as X, isARefSchema as Y, type ARefSchemaWithAdapters as Z, type ASchemaStrict as a, type ASchemaOptions as b, type ASchemaWithAdapters as c, type AArraySchema as d, type AScalarSchemaWithAdapters as e, type AObjectSchema as f, type ADiscriminatorSchemaWithAdapters as g, type ResolveObject as h, type AStringEnumSchemaWithAdapters as i, type
|
|
172
|
+
export { type ASchema as A, type Resolve as B, type AScalarSchema as C, isAScalarSchema as D, type NumberType as E, isAAraySchema as F, type AArraySchemaWithAdapters as G, type AStringEnumSchema as H, type InferType as I, isAStringEnumSchema as J, type ADiscriminatorSchema as K, isADiscriminatorSchema as L, type MaybeNullable as M, NumberTypeValues as N, type ARecordSchema as O, type PartialBy as P, isARecordSchema as Q, type Result as R, type SchemaValidator as S, isAObjectSchema as T, type InferObjectRawType as U, type ValidationContext as V, type WithAdapters as W, isObject as X, isARefSchema as Y, type ARefSchemaWithAdapters as Z, type ASchemaStrict as a, type ASchemaOptions as b, type ASchemaWithAdapters as c, type AArraySchema as d, type AScalarSchemaWithAdapters as e, type AObjectSchema as f, type ADiscriminatorSchemaWithAdapters as g, type ResolveObject as h, type AStringEnumSchemaWithAdapters as i, type AObjectSchemaWithAdapters as j, type AObjectSchemaOptions as k, type InferObjectOutput as l, type ARecordSchemaWithAdapters as m, type ARefSchema as n, type ValueError as o, type InferSubType as p, isValueError as q, errorMessageFromErrors as r, ValidationException as s, isValidationException as t, type ResultSuccess as u, type ResultFailure as v, newValidationContext as w, VALIDATOR_KEY as x, type SchemaMetadata as y, isASchema as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/schema",
|
|
3
|
-
"version": "0.74.
|
|
3
|
+
"version": "0.74.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@standard-schema/spec": "1.0.0",
|
|
26
26
|
"scule": "^1.3.0",
|
|
27
27
|
"uncrypto": "^0.1.3",
|
|
28
|
-
"@arrirpc/type-defs": "0.74.
|
|
28
|
+
"@arrirpc/type-defs": "0.74.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"ajv": "^8.17.1",
|