@arrirpc/schema 0.81.1 → 0.81.3
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 +74 -0
- 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 +134 -0
- package/dist/index.d.cts +73 -47
- package/dist/index.d.mts +73 -47
- package/dist/index.d.ts +73 -47
- package/dist/index.mjs +133 -1
- package/dist/shared/{schema.CS4qvHhE.d.cts → schema.puFjotry.d.cts} +2 -2
- package/dist/shared/{schema.CS4qvHhE.d.mts → schema.puFjotry.d.mts} +2 -2
- package/dist/shared/{schema.CS4qvHhE.d.ts → schema.puFjotry.d.ts} +2 -2
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ Originally this library was created as a way for building schemas for [Json Type
|
|
|
53
53
|
- [Serialize](#serialize)
|
|
54
54
|
- [Serialize Unsafe](#serialize-unsafe)
|
|
55
55
|
- [Errors](#errors)
|
|
56
|
+
- [To JSON Schema](#to-json-schema)
|
|
56
57
|
- [Metadata](#metadata)
|
|
57
58
|
- [Compiled Validators](#compiled-validators)
|
|
58
59
|
- [Benchmarks](#benchmarks)
|
|
@@ -989,6 +990,79 @@ a.errors(User, { id: 1, date: 'hello world' });
|
|
|
989
990
|
*/
|
|
990
991
|
```
|
|
991
992
|
|
|
993
|
+
### To JSON Schema
|
|
994
|
+
|
|
995
|
+
Use `a.toJsonSchema()` to convert an Arri schema to [JSON Schema](https://json-schema.org/) format. This is useful for:
|
|
996
|
+
|
|
997
|
+
- **Editor support** - YAML/JSON files using Arri-defined schemas can get autocomplete in VS Code, IntelliJ, etc.
|
|
998
|
+
- **Interoperability** - Integration with tools that consume JSON Schema (OpenAPI, documentation generators, etc.)
|
|
999
|
+
- **Configuration validation** - Users defining config files can reference a JSON Schema URL for validation
|
|
1000
|
+
|
|
1001
|
+
```ts
|
|
1002
|
+
const User = a.object(
|
|
1003
|
+
{
|
|
1004
|
+
id: a.string(),
|
|
1005
|
+
name: a.string(),
|
|
1006
|
+
email: a.nullable(a.string()),
|
|
1007
|
+
role: a.enumerator(['USER', 'ADMIN']),
|
|
1008
|
+
createdAt: a.timestamp(),
|
|
1009
|
+
},
|
|
1010
|
+
{ id: 'User', description: 'A user in the system' },
|
|
1011
|
+
);
|
|
1012
|
+
|
|
1013
|
+
const jsonSchema = a.toJsonSchema(User, {
|
|
1014
|
+
$id: 'https://example.com/schemas/user.json',
|
|
1015
|
+
title: 'User Schema',
|
|
1016
|
+
});
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
**Result:**
|
|
1020
|
+
|
|
1021
|
+
```json
|
|
1022
|
+
{
|
|
1023
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1024
|
+
"$id": "https://example.com/schemas/user.json",
|
|
1025
|
+
"title": "User Schema",
|
|
1026
|
+
"type": "object",
|
|
1027
|
+
"properties": {
|
|
1028
|
+
"id": { "type": "string" },
|
|
1029
|
+
"name": { "type": "string" },
|
|
1030
|
+
"email": { "type": ["string", "null"] },
|
|
1031
|
+
"role": { "type": "string", "enum": ["USER", "ADMIN"] },
|
|
1032
|
+
"createdAt": { "type": "string", "format": "date-time" }
|
|
1033
|
+
},
|
|
1034
|
+
"required": ["id", "name", "email", "role", "createdAt"]
|
|
1035
|
+
}
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
#### Options
|
|
1039
|
+
|
|
1040
|
+
| Option | Type | Description |
|
|
1041
|
+
| ------------- | ------ | --------------------------------------------------------------------------------------- |
|
|
1042
|
+
| `$id` | string | The `$id` to use for the root schema |
|
|
1043
|
+
| `title` | string | The title to use for the root schema |
|
|
1044
|
+
| `description` | string | The description to use for the root schema |
|
|
1045
|
+
| `$schema` | string | The JSON Schema draft version (default: `https://json-schema.org/draft/2020-12/schema`) |
|
|
1046
|
+
|
|
1047
|
+
#### Type Mappings
|
|
1048
|
+
|
|
1049
|
+
| Arri Schema | JSON Schema Equivalent |
|
|
1050
|
+
| ------------------- | -------------------------------------------------------------- |
|
|
1051
|
+
| `a.any()` | `{}` (any) |
|
|
1052
|
+
| `a.string()` | `{ "type": "string" }` |
|
|
1053
|
+
| `a.boolean()` | `{ "type": "boolean" }` |
|
|
1054
|
+
| `a.timestamp()` | `{ "type": "string", "format": "date-time" }` |
|
|
1055
|
+
| `a.float32/64()` | `{ "type": "number" }` |
|
|
1056
|
+
| `a.int8/16/32()` | `{ "type": "integer", "minimum": X, "maximum": Y }` |
|
|
1057
|
+
| `a.uint8/16/32()` | `{ "type": "integer", "minimum": 0, "maximum": Y }` |
|
|
1058
|
+
| `a.int64/uint64()` | `{ "type": "string", "pattern": "^-?[0-9]+$" }` |
|
|
1059
|
+
| `a.enumerator()` | `{ "type": "string", "enum": [...] }` |
|
|
1060
|
+
| `a.array()` | `{ "type": "array", "items": {...} }` |
|
|
1061
|
+
| `a.object()` | `{ "type": "object", "properties": {...}, "required": [...] }` |
|
|
1062
|
+
| `a.record()` | `{ "type": "object", "additionalProperties": {...} }` |
|
|
1063
|
+
| `a.discriminator()` | `{ "oneOf": [...] }` with const discriminator |
|
|
1064
|
+
| `a.nullable()` | Adds `"null"` to type array |
|
|
1065
|
+
|
|
992
1066
|
## Metadata
|
|
993
1067
|
|
|
994
1068
|
Metadata is used during cross-language code generation. Arri schemas allow you to specify the following metadata fields:
|
package/dist/adapters.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import { m as ValidationContext, A as ASchema } from './shared/schema.
|
|
2
|
+
import { m as ValidationContext, A as ASchema } from './shared/schema.puFjotry.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 { m as ValidationContext, A as ASchema } from './shared/schema.
|
|
2
|
+
import { m as ValidationContext, A as ASchema } from './shared/schema.puFjotry.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 { m as ValidationContext, A as ASchema } from './shared/schema.
|
|
2
|
+
import { m as ValidationContext, A as ASchema } from './shared/schema.puFjotry.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
|
@@ -2818,6 +2818,136 @@ function enumerator(paramA, paramB) {
|
|
|
2818
2818
|
return result;
|
|
2819
2819
|
}
|
|
2820
2820
|
|
|
2821
|
+
function toJsonSchema(schema, options) {
|
|
2822
|
+
return applyRootOptions(
|
|
2823
|
+
schemaToJsonSchema(schema),
|
|
2824
|
+
options
|
|
2825
|
+
);
|
|
2826
|
+
}
|
|
2827
|
+
function schemaToJsonSchema(schema) {
|
|
2828
|
+
return convertSchema(schema);
|
|
2829
|
+
}
|
|
2830
|
+
function applyRootOptions(schema, options) {
|
|
2831
|
+
return {
|
|
2832
|
+
...schema,
|
|
2833
|
+
$schema: options?.$schema ?? "https://json-schema.org/draft/2020-12/schema",
|
|
2834
|
+
...options?.$id && { $id: options.$id },
|
|
2835
|
+
...options?.title && { title: options.title },
|
|
2836
|
+
...options?.description && { description: options.description }
|
|
2837
|
+
};
|
|
2838
|
+
}
|
|
2839
|
+
const SCALAR_MAPPINGS = {
|
|
2840
|
+
string: { type: "string" },
|
|
2841
|
+
boolean: { type: "boolean" },
|
|
2842
|
+
timestamp: { type: "string", format: "date-time" },
|
|
2843
|
+
float32: { type: "number" },
|
|
2844
|
+
float64: { type: "number" },
|
|
2845
|
+
int8: { type: "integer", minimum: int8Min, maximum: int8Max },
|
|
2846
|
+
uint8: { type: "integer", minimum: uint8Min, maximum: uint8Max },
|
|
2847
|
+
int16: { type: "integer", minimum: int16Min, maximum: int16Max },
|
|
2848
|
+
uint16: { type: "integer", minimum: uint16Min, maximum: uint16Max },
|
|
2849
|
+
int32: { type: "integer", minimum: int32Min, maximum: int32Max },
|
|
2850
|
+
uint32: { type: "integer", minimum: uint32Min, maximum: uint32Max },
|
|
2851
|
+
int64: { type: "string", pattern: "^-?[0-9]+$" },
|
|
2852
|
+
uint64: { type: "string", pattern: "^[0-9]+$" }
|
|
2853
|
+
};
|
|
2854
|
+
function convertSchema(schema) {
|
|
2855
|
+
const base = getBaseSchema(schema);
|
|
2856
|
+
return schema.isNullable ? makeNullable(base, schema) : applyMetadata(base, schema);
|
|
2857
|
+
}
|
|
2858
|
+
function getBaseSchema(schema) {
|
|
2859
|
+
if (typeDefs.isSchemaFormType(schema)) {
|
|
2860
|
+
const mapping = SCALAR_MAPPINGS[schema.type];
|
|
2861
|
+
return mapping ? { ...mapping } : {};
|
|
2862
|
+
}
|
|
2863
|
+
if (typeDefs.isSchemaFormEnum(schema)) {
|
|
2864
|
+
return {
|
|
2865
|
+
type: "string",
|
|
2866
|
+
enum: [...schema.enum]
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
if (typeDefs.isSchemaFormElements(schema)) {
|
|
2870
|
+
return {
|
|
2871
|
+
type: "array",
|
|
2872
|
+
items: convertSchema(schema.elements)
|
|
2873
|
+
};
|
|
2874
|
+
}
|
|
2875
|
+
if (typeDefs.isSchemaFormProperties(schema)) {
|
|
2876
|
+
return convertObject(schema);
|
|
2877
|
+
}
|
|
2878
|
+
if (typeDefs.isSchemaFormValues(schema)) {
|
|
2879
|
+
return {
|
|
2880
|
+
type: "object",
|
|
2881
|
+
additionalProperties: convertSchema(schema.values)
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
if (typeDefs.isSchemaFormDiscriminator(schema)) {
|
|
2885
|
+
return convertDiscriminator(schema);
|
|
2886
|
+
}
|
|
2887
|
+
if (typeDefs.isSchemaFormRef(schema)) {
|
|
2888
|
+
return { $ref: `#/$defs/${schema.ref}` };
|
|
2889
|
+
}
|
|
2890
|
+
if (typeDefs.isSchemaFormEmpty(schema)) return {};
|
|
2891
|
+
return {};
|
|
2892
|
+
}
|
|
2893
|
+
function convertObject(schema) {
|
|
2894
|
+
const properties = {};
|
|
2895
|
+
const required = [];
|
|
2896
|
+
for (const [key, prop] of Object.entries(schema.properties ?? {})) {
|
|
2897
|
+
properties[key] = convertSchema(prop);
|
|
2898
|
+
required.push(key);
|
|
2899
|
+
}
|
|
2900
|
+
for (const [key, prop] of Object.entries(schema.optionalProperties ?? {})) {
|
|
2901
|
+
properties[key] = convertSchema(prop);
|
|
2902
|
+
}
|
|
2903
|
+
return {
|
|
2904
|
+
type: "object",
|
|
2905
|
+
properties,
|
|
2906
|
+
...required.length > 0 && { required },
|
|
2907
|
+
...schema.isStrict && { additionalProperties: false }
|
|
2908
|
+
};
|
|
2909
|
+
}
|
|
2910
|
+
function convertDiscriminator(schema) {
|
|
2911
|
+
const oneOf = Object.entries(schema.mapping).map(
|
|
2912
|
+
([value, mappingSchema]) => {
|
|
2913
|
+
const variant = convertObject(mappingSchema);
|
|
2914
|
+
variant.properties = {
|
|
2915
|
+
...variant.properties,
|
|
2916
|
+
[schema.discriminator]: { type: "string", const: value }
|
|
2917
|
+
};
|
|
2918
|
+
variant.required = [
|
|
2919
|
+
...variant.required ?? [],
|
|
2920
|
+
schema.discriminator
|
|
2921
|
+
];
|
|
2922
|
+
return variant;
|
|
2923
|
+
}
|
|
2924
|
+
);
|
|
2925
|
+
return { oneOf };
|
|
2926
|
+
}
|
|
2927
|
+
function makeNullable(jsonSchema, atdSchema) {
|
|
2928
|
+
if (jsonSchema.$ref || jsonSchema.oneOf) {
|
|
2929
|
+
return applyMetadata(
|
|
2930
|
+
{ anyOf: [jsonSchema, { type: "null" }] },
|
|
2931
|
+
atdSchema
|
|
2932
|
+
);
|
|
2933
|
+
}
|
|
2934
|
+
if (jsonSchema.type) {
|
|
2935
|
+
const types = Array.isArray(jsonSchema.type) ? jsonSchema.type : [jsonSchema.type];
|
|
2936
|
+
jsonSchema.type = types.includes("null") ? types : [...types, "null"];
|
|
2937
|
+
return applyMetadata(jsonSchema, atdSchema);
|
|
2938
|
+
}
|
|
2939
|
+
return applyMetadata({ anyOf: [jsonSchema, { type: "null" }] }, atdSchema);
|
|
2940
|
+
}
|
|
2941
|
+
function applyMetadata(jsonSchema, { metadata }) {
|
|
2942
|
+
if (!metadata) return jsonSchema;
|
|
2943
|
+
return {
|
|
2944
|
+
...jsonSchema,
|
|
2945
|
+
...metadata.id && { title: metadata.id },
|
|
2946
|
+
...metadata.description && { description: metadata.description },
|
|
2947
|
+
...metadata.isDeprecated && { deprecated: true }
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2821
2951
|
function nullable(schema, opts = {}) {
|
|
2822
2952
|
const isType = (val) => {
|
|
2823
2953
|
if (val === null) {
|
|
@@ -4279,11 +4409,13 @@ const _namespace = {
|
|
|
4279
4409
|
pick: pick,
|
|
4280
4410
|
record: record,
|
|
4281
4411
|
recursive: recursive,
|
|
4412
|
+
schemaToJsonSchema: schemaToJsonSchema,
|
|
4282
4413
|
serialize: serialize,
|
|
4283
4414
|
serializeUnsafe: serializeUnsafe,
|
|
4284
4415
|
string: string,
|
|
4285
4416
|
stringEnum: stringEnum,
|
|
4286
4417
|
timestamp: timestamp,
|
|
4418
|
+
toJsonSchema: toJsonSchema,
|
|
4287
4419
|
uint16: uint16,
|
|
4288
4420
|
uint32: uint32,
|
|
4289
4421
|
uint64: uint64,
|
|
@@ -4353,6 +4485,7 @@ exports.pick = pick;
|
|
|
4353
4485
|
exports.record = record;
|
|
4354
4486
|
exports.recursive = recursive;
|
|
4355
4487
|
exports.sanitizeJson = sanitizeJson;
|
|
4488
|
+
exports.schemaToJsonSchema = schemaToJsonSchema;
|
|
4356
4489
|
exports.serialize = serialize;
|
|
4357
4490
|
exports.serializeObject = serializeObject;
|
|
4358
4491
|
exports.serializeSmallString = serializeSmallString;
|
|
@@ -4361,6 +4494,7 @@ exports.serializeUnsafe = serializeUnsafe;
|
|
|
4361
4494
|
exports.string = string;
|
|
4362
4495
|
exports.stringEnum = stringEnum;
|
|
4363
4496
|
exports.timestamp = timestamp;
|
|
4497
|
+
exports.toJsonSchema = toJsonSchema;
|
|
4364
4498
|
exports.uint16 = uint16;
|
|
4365
4499
|
exports.uint16Max = uint16Max;
|
|
4366
4500
|
exports.uint16Min = uint16Min;
|
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, 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.
|
|
4
|
-
export {
|
|
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.puFjotry.cjs';
|
|
4
|
+
export { r as AArraySchemaWithAdapters, s as ADiscriminatorSchema, t as ARecordSchema, u as ARefSchemaWithAdapters, v as AScalarSchema, w as AStringEnumSchema, x as InferObjectOptionalKeys, y as InferObjectRawType, M as MaybeNullable, N as NumberType, z as NumberTypeValues, P as PartialBy, B as Resolve, C as ResultFailure, D as ResultSuccess, E as SchemaMetadata, F as ValidationException, G as errorMessageFromErrors, H as isAAraySchema, J as isADiscriminatorSchema, K as isAObjectSchema, L as isARecordSchema, O as isARefSchema, Q as isAScalarSchema, T as isASchema, U as isAStringEnumSchema, X as isObject, Y as isValidationException, Z as isValueError, _ as newValidationContext } from './shared/schema.puFjotry.cjs';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
|
@@ -149,6 +149,69 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(value
|
|
|
149
149
|
*/
|
|
150
150
|
declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: string, values: TValues): AStringEnumSchemaWithAdapters<TValues>;
|
|
151
151
|
|
|
152
|
+
type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
153
|
+
interface JsonSchema {
|
|
154
|
+
$schema?: string;
|
|
155
|
+
$id?: string;
|
|
156
|
+
$ref?: string;
|
|
157
|
+
$defs?: Record<string, JsonSchema>;
|
|
158
|
+
title?: string;
|
|
159
|
+
description?: string;
|
|
160
|
+
deprecated?: boolean;
|
|
161
|
+
type?: JsonSchemaType | JsonSchemaType[];
|
|
162
|
+
pattern?: string;
|
|
163
|
+
format?: string;
|
|
164
|
+
minLength?: number;
|
|
165
|
+
maxLength?: number;
|
|
166
|
+
minimum?: number;
|
|
167
|
+
maximum?: number;
|
|
168
|
+
exclusiveMinimum?: number;
|
|
169
|
+
exclusiveMaximum?: number;
|
|
170
|
+
enum?: unknown[];
|
|
171
|
+
const?: unknown;
|
|
172
|
+
items?: JsonSchema;
|
|
173
|
+
minItems?: number;
|
|
174
|
+
maxItems?: number;
|
|
175
|
+
properties?: Record<string, JsonSchema>;
|
|
176
|
+
required?: string[];
|
|
177
|
+
additionalProperties?: boolean | JsonSchema;
|
|
178
|
+
oneOf?: JsonSchema[];
|
|
179
|
+
anyOf?: JsonSchema[];
|
|
180
|
+
allOf?: JsonSchema[];
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
}
|
|
183
|
+
interface ToJsonSchemaOptions {
|
|
184
|
+
/** The $id to use for the root schema */
|
|
185
|
+
$id?: string;
|
|
186
|
+
/** The title to use for the root schema */
|
|
187
|
+
title?: string;
|
|
188
|
+
/** The description to use for the root schema */
|
|
189
|
+
description?: string;
|
|
190
|
+
/** The JSON Schema draft version to target */
|
|
191
|
+
$schema?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Convert an Arri schema to JSON Schema format
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const User = a.object({
|
|
198
|
+
* id: a.string(),
|
|
199
|
+
* name: a.string(),
|
|
200
|
+
* email: a.nullable(a.string()),
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* const jsonSchema = toJsonSchema(User, {
|
|
204
|
+
* $id: 'https://example.com/schemas/user.json',
|
|
205
|
+
* title: 'User',
|
|
206
|
+
* });
|
|
207
|
+
*/
|
|
208
|
+
declare function toJsonSchema<T>(schema: ASchema<T>, options?: ToJsonSchemaOptions): JsonSchema;
|
|
209
|
+
/**
|
|
210
|
+
* Convert a raw ATD Schema object to JSON Schema format.
|
|
211
|
+
* This is useful when working with plain schema objects from AppDefinition.
|
|
212
|
+
*/
|
|
213
|
+
declare function schemaToJsonSchema(schema: Schema): JsonSchema;
|
|
214
|
+
|
|
152
215
|
/**
|
|
153
216
|
* Transforms a schema into a nullable type
|
|
154
217
|
*
|
|
@@ -375,6 +438,8 @@ declare function serialize<T = any>(schema: ASchema<T>, input: T): Result<string
|
|
|
375
438
|
declare function serializeUnsafe<T = any>(schema: ASchema<T>, input: T): string;
|
|
376
439
|
declare function errors(schema: ASchema, input: unknown, exitOnFirstError?: boolean): ValueError[];
|
|
377
440
|
|
|
441
|
+
type _namespace_JsonSchema = JsonSchema;
|
|
442
|
+
type _namespace_ToJsonSchemaOptions = ToJsonSchemaOptions;
|
|
378
443
|
declare const _namespace_any: typeof any;
|
|
379
444
|
declare const _namespace_array: typeof array;
|
|
380
445
|
declare const _namespace_boolean: typeof boolean;
|
|
@@ -403,11 +468,13 @@ declare const _namespace_partial: typeof partial;
|
|
|
403
468
|
declare const _namespace_pick: typeof pick;
|
|
404
469
|
declare const _namespace_record: typeof record;
|
|
405
470
|
declare const _namespace_recursive: typeof recursive;
|
|
471
|
+
declare const _namespace_schemaToJsonSchema: typeof schemaToJsonSchema;
|
|
406
472
|
declare const _namespace_serialize: typeof serialize;
|
|
407
473
|
declare const _namespace_serializeUnsafe: typeof serializeUnsafe;
|
|
408
474
|
declare const _namespace_string: typeof string;
|
|
409
475
|
declare const _namespace_stringEnum: typeof stringEnum;
|
|
410
476
|
declare const _namespace_timestamp: typeof timestamp;
|
|
477
|
+
declare const _namespace_toJsonSchema: typeof toJsonSchema;
|
|
411
478
|
declare const _namespace_uint16: typeof uint16;
|
|
412
479
|
declare const _namespace_uint32: typeof uint32;
|
|
413
480
|
declare const _namespace_uint64: typeof uint64;
|
|
@@ -415,50 +482,9 @@ declare const _namespace_uint8: typeof uint8;
|
|
|
415
482
|
declare const _namespace_undefinable: typeof undefinable;
|
|
416
483
|
declare const _namespace_validate: typeof validate;
|
|
417
484
|
declare namespace _namespace {
|
|
418
|
-
export {
|
|
419
|
-
|
|
420
|
-
_namespace_array as array,
|
|
421
|
-
_namespace_boolean as boolean,
|
|
422
|
-
_namespace_clone as clone,
|
|
423
|
-
_namespace_coerce as coerce,
|
|
424
|
-
_namespace_coerceUnsafe as coerceUnsafe,
|
|
425
|
-
_namespace_compile as compile,
|
|
426
|
-
_namespace_discriminator as discriminator,
|
|
427
|
-
_namespace_enumerator as enumerator,
|
|
428
|
-
_namespace_errors as errors,
|
|
429
|
-
_namespace_extend as extend,
|
|
430
|
-
_namespace_float32 as float32,
|
|
431
|
-
_namespace_float64 as float64,
|
|
432
|
-
InferType as infer,
|
|
433
|
-
InferSubType as inferSubType,
|
|
434
|
-
_namespace_int16 as int16,
|
|
435
|
-
_namespace_int32 as int32,
|
|
436
|
-
_namespace_int64 as int64,
|
|
437
|
-
_namespace_int8 as int8,
|
|
438
|
-
_namespace_nullable as nullable,
|
|
439
|
-
_namespace_number as number,
|
|
440
|
-
_namespace_object as object,
|
|
441
|
-
_namespace_omit as omit,
|
|
442
|
-
_namespace_optional as optional,
|
|
443
|
-
_namespace_parse as parse,
|
|
444
|
-
_namespace_parseUnsafe as parseUnsafe,
|
|
445
|
-
_namespace_partial as partial,
|
|
446
|
-
_namespace_pick as pick,
|
|
447
|
-
_namespace_record as record,
|
|
448
|
-
_namespace_recursive as recursive,
|
|
449
|
-
_namespace_serialize as serialize,
|
|
450
|
-
_namespace_serializeUnsafe as serializeUnsafe,
|
|
451
|
-
_namespace_string as string,
|
|
452
|
-
_namespace_stringEnum as stringEnum,
|
|
453
|
-
_namespace_timestamp as timestamp,
|
|
454
|
-
_namespace_uint16 as uint16,
|
|
455
|
-
_namespace_uint32 as uint32,
|
|
456
|
-
_namespace_uint64 as uint64,
|
|
457
|
-
_namespace_uint8 as uint8,
|
|
458
|
-
_namespace_undefinable as undefinable,
|
|
459
|
-
_namespace_validate as validate,
|
|
460
|
-
};
|
|
485
|
+
export { _namespace_any as any, _namespace_array as array, _namespace_boolean as boolean, _namespace_clone as clone, _namespace_coerce as coerce, _namespace_coerceUnsafe as coerceUnsafe, _namespace_compile as compile, _namespace_discriminator as discriminator, _namespace_enumerator as enumerator, _namespace_errors as errors, _namespace_extend as extend, _namespace_float32 as float32, _namespace_float64 as float64, InferType as infer, InferSubType as inferSubType, _namespace_int16 as int16, _namespace_int32 as int32, _namespace_int64 as int64, _namespace_int8 as int8, _namespace_nullable as nullable, _namespace_number as number, _namespace_object as object, _namespace_omit as omit, _namespace_optional as optional, _namespace_parse as parse, _namespace_parseUnsafe as parseUnsafe, _namespace_partial as partial, _namespace_pick as pick, _namespace_record as record, _namespace_recursive as recursive, _namespace_schemaToJsonSchema as schemaToJsonSchema, _namespace_serialize as serialize, _namespace_serializeUnsafe as serializeUnsafe, _namespace_string as string, _namespace_stringEnum as stringEnum, _namespace_timestamp as timestamp, _namespace_toJsonSchema as toJsonSchema, _namespace_uint16 as uint16, _namespace_uint32 as uint32, _namespace_uint64 as uint64, _namespace_uint8 as uint8, _namespace_undefinable as undefinable, _namespace_validate as validate };
|
|
486
|
+
export type { _namespace_JsonSchema as JsonSchema, _namespace_ToJsonSchemaOptions as ToJsonSchemaOptions };
|
|
461
487
|
}
|
|
462
488
|
|
|
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 };
|
|
464
|
-
export type { CompiledValidator, CompiledValidatorCompiledCode };
|
|
489
|
+
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, schemaToJsonSchema, serialize, serializeObject, serializeSmallString, serializeString, serializeUnsafe, string, stringEnum, timestamp, toJsonSchema, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, undefinable, validate, validateObjectSchema };
|
|
490
|
+
export type { CompiledValidator, CompiledValidatorCompiledCode, JsonSchema, JsonSchemaType, ToJsonSchemaOptions };
|
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, 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.
|
|
4
|
-
export {
|
|
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.puFjotry.mjs';
|
|
4
|
+
export { r as AArraySchemaWithAdapters, s as ADiscriminatorSchema, t as ARecordSchema, u as ARefSchemaWithAdapters, v as AScalarSchema, w as AStringEnumSchema, x as InferObjectOptionalKeys, y as InferObjectRawType, M as MaybeNullable, N as NumberType, z as NumberTypeValues, P as PartialBy, B as Resolve, C as ResultFailure, D as ResultSuccess, E as SchemaMetadata, F as ValidationException, G as errorMessageFromErrors, H as isAAraySchema, J as isADiscriminatorSchema, K as isAObjectSchema, L as isARecordSchema, O as isARefSchema, Q as isAScalarSchema, T as isASchema, U as isAStringEnumSchema, X as isObject, Y as isValidationException, Z as isValueError, _ as newValidationContext } from './shared/schema.puFjotry.mjs';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
|
@@ -149,6 +149,69 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(value
|
|
|
149
149
|
*/
|
|
150
150
|
declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: string, values: TValues): AStringEnumSchemaWithAdapters<TValues>;
|
|
151
151
|
|
|
152
|
+
type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
153
|
+
interface JsonSchema {
|
|
154
|
+
$schema?: string;
|
|
155
|
+
$id?: string;
|
|
156
|
+
$ref?: string;
|
|
157
|
+
$defs?: Record<string, JsonSchema>;
|
|
158
|
+
title?: string;
|
|
159
|
+
description?: string;
|
|
160
|
+
deprecated?: boolean;
|
|
161
|
+
type?: JsonSchemaType | JsonSchemaType[];
|
|
162
|
+
pattern?: string;
|
|
163
|
+
format?: string;
|
|
164
|
+
minLength?: number;
|
|
165
|
+
maxLength?: number;
|
|
166
|
+
minimum?: number;
|
|
167
|
+
maximum?: number;
|
|
168
|
+
exclusiveMinimum?: number;
|
|
169
|
+
exclusiveMaximum?: number;
|
|
170
|
+
enum?: unknown[];
|
|
171
|
+
const?: unknown;
|
|
172
|
+
items?: JsonSchema;
|
|
173
|
+
minItems?: number;
|
|
174
|
+
maxItems?: number;
|
|
175
|
+
properties?: Record<string, JsonSchema>;
|
|
176
|
+
required?: string[];
|
|
177
|
+
additionalProperties?: boolean | JsonSchema;
|
|
178
|
+
oneOf?: JsonSchema[];
|
|
179
|
+
anyOf?: JsonSchema[];
|
|
180
|
+
allOf?: JsonSchema[];
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
}
|
|
183
|
+
interface ToJsonSchemaOptions {
|
|
184
|
+
/** The $id to use for the root schema */
|
|
185
|
+
$id?: string;
|
|
186
|
+
/** The title to use for the root schema */
|
|
187
|
+
title?: string;
|
|
188
|
+
/** The description to use for the root schema */
|
|
189
|
+
description?: string;
|
|
190
|
+
/** The JSON Schema draft version to target */
|
|
191
|
+
$schema?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Convert an Arri schema to JSON Schema format
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const User = a.object({
|
|
198
|
+
* id: a.string(),
|
|
199
|
+
* name: a.string(),
|
|
200
|
+
* email: a.nullable(a.string()),
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* const jsonSchema = toJsonSchema(User, {
|
|
204
|
+
* $id: 'https://example.com/schemas/user.json',
|
|
205
|
+
* title: 'User',
|
|
206
|
+
* });
|
|
207
|
+
*/
|
|
208
|
+
declare function toJsonSchema<T>(schema: ASchema<T>, options?: ToJsonSchemaOptions): JsonSchema;
|
|
209
|
+
/**
|
|
210
|
+
* Convert a raw ATD Schema object to JSON Schema format.
|
|
211
|
+
* This is useful when working with plain schema objects from AppDefinition.
|
|
212
|
+
*/
|
|
213
|
+
declare function schemaToJsonSchema(schema: Schema): JsonSchema;
|
|
214
|
+
|
|
152
215
|
/**
|
|
153
216
|
* Transforms a schema into a nullable type
|
|
154
217
|
*
|
|
@@ -375,6 +438,8 @@ declare function serialize<T = any>(schema: ASchema<T>, input: T): Result<string
|
|
|
375
438
|
declare function serializeUnsafe<T = any>(schema: ASchema<T>, input: T): string;
|
|
376
439
|
declare function errors(schema: ASchema, input: unknown, exitOnFirstError?: boolean): ValueError[];
|
|
377
440
|
|
|
441
|
+
type _namespace_JsonSchema = JsonSchema;
|
|
442
|
+
type _namespace_ToJsonSchemaOptions = ToJsonSchemaOptions;
|
|
378
443
|
declare const _namespace_any: typeof any;
|
|
379
444
|
declare const _namespace_array: typeof array;
|
|
380
445
|
declare const _namespace_boolean: typeof boolean;
|
|
@@ -403,11 +468,13 @@ declare const _namespace_partial: typeof partial;
|
|
|
403
468
|
declare const _namespace_pick: typeof pick;
|
|
404
469
|
declare const _namespace_record: typeof record;
|
|
405
470
|
declare const _namespace_recursive: typeof recursive;
|
|
471
|
+
declare const _namespace_schemaToJsonSchema: typeof schemaToJsonSchema;
|
|
406
472
|
declare const _namespace_serialize: typeof serialize;
|
|
407
473
|
declare const _namespace_serializeUnsafe: typeof serializeUnsafe;
|
|
408
474
|
declare const _namespace_string: typeof string;
|
|
409
475
|
declare const _namespace_stringEnum: typeof stringEnum;
|
|
410
476
|
declare const _namespace_timestamp: typeof timestamp;
|
|
477
|
+
declare const _namespace_toJsonSchema: typeof toJsonSchema;
|
|
411
478
|
declare const _namespace_uint16: typeof uint16;
|
|
412
479
|
declare const _namespace_uint32: typeof uint32;
|
|
413
480
|
declare const _namespace_uint64: typeof uint64;
|
|
@@ -415,50 +482,9 @@ declare const _namespace_uint8: typeof uint8;
|
|
|
415
482
|
declare const _namespace_undefinable: typeof undefinable;
|
|
416
483
|
declare const _namespace_validate: typeof validate;
|
|
417
484
|
declare namespace _namespace {
|
|
418
|
-
export {
|
|
419
|
-
|
|
420
|
-
_namespace_array as array,
|
|
421
|
-
_namespace_boolean as boolean,
|
|
422
|
-
_namespace_clone as clone,
|
|
423
|
-
_namespace_coerce as coerce,
|
|
424
|
-
_namespace_coerceUnsafe as coerceUnsafe,
|
|
425
|
-
_namespace_compile as compile,
|
|
426
|
-
_namespace_discriminator as discriminator,
|
|
427
|
-
_namespace_enumerator as enumerator,
|
|
428
|
-
_namespace_errors as errors,
|
|
429
|
-
_namespace_extend as extend,
|
|
430
|
-
_namespace_float32 as float32,
|
|
431
|
-
_namespace_float64 as float64,
|
|
432
|
-
InferType as infer,
|
|
433
|
-
InferSubType as inferSubType,
|
|
434
|
-
_namespace_int16 as int16,
|
|
435
|
-
_namespace_int32 as int32,
|
|
436
|
-
_namespace_int64 as int64,
|
|
437
|
-
_namespace_int8 as int8,
|
|
438
|
-
_namespace_nullable as nullable,
|
|
439
|
-
_namespace_number as number,
|
|
440
|
-
_namespace_object as object,
|
|
441
|
-
_namespace_omit as omit,
|
|
442
|
-
_namespace_optional as optional,
|
|
443
|
-
_namespace_parse as parse,
|
|
444
|
-
_namespace_parseUnsafe as parseUnsafe,
|
|
445
|
-
_namespace_partial as partial,
|
|
446
|
-
_namespace_pick as pick,
|
|
447
|
-
_namespace_record as record,
|
|
448
|
-
_namespace_recursive as recursive,
|
|
449
|
-
_namespace_serialize as serialize,
|
|
450
|
-
_namespace_serializeUnsafe as serializeUnsafe,
|
|
451
|
-
_namespace_string as string,
|
|
452
|
-
_namespace_stringEnum as stringEnum,
|
|
453
|
-
_namespace_timestamp as timestamp,
|
|
454
|
-
_namespace_uint16 as uint16,
|
|
455
|
-
_namespace_uint32 as uint32,
|
|
456
|
-
_namespace_uint64 as uint64,
|
|
457
|
-
_namespace_uint8 as uint8,
|
|
458
|
-
_namespace_undefinable as undefinable,
|
|
459
|
-
_namespace_validate as validate,
|
|
460
|
-
};
|
|
485
|
+
export { _namespace_any as any, _namespace_array as array, _namespace_boolean as boolean, _namespace_clone as clone, _namespace_coerce as coerce, _namespace_coerceUnsafe as coerceUnsafe, _namespace_compile as compile, _namespace_discriminator as discriminator, _namespace_enumerator as enumerator, _namespace_errors as errors, _namespace_extend as extend, _namespace_float32 as float32, _namespace_float64 as float64, InferType as infer, InferSubType as inferSubType, _namespace_int16 as int16, _namespace_int32 as int32, _namespace_int64 as int64, _namespace_int8 as int8, _namespace_nullable as nullable, _namespace_number as number, _namespace_object as object, _namespace_omit as omit, _namespace_optional as optional, _namespace_parse as parse, _namespace_parseUnsafe as parseUnsafe, _namespace_partial as partial, _namespace_pick as pick, _namespace_record as record, _namespace_recursive as recursive, _namespace_schemaToJsonSchema as schemaToJsonSchema, _namespace_serialize as serialize, _namespace_serializeUnsafe as serializeUnsafe, _namespace_string as string, _namespace_stringEnum as stringEnum, _namespace_timestamp as timestamp, _namespace_toJsonSchema as toJsonSchema, _namespace_uint16 as uint16, _namespace_uint32 as uint32, _namespace_uint64 as uint64, _namespace_uint8 as uint8, _namespace_undefinable as undefinable, _namespace_validate as validate };
|
|
486
|
+
export type { _namespace_JsonSchema as JsonSchema, _namespace_ToJsonSchemaOptions as ToJsonSchemaOptions };
|
|
461
487
|
}
|
|
462
488
|
|
|
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 };
|
|
464
|
-
export type { CompiledValidator, CompiledValidatorCompiledCode };
|
|
489
|
+
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, schemaToJsonSchema, serialize, serializeObject, serializeSmallString, serializeString, serializeUnsafe, string, stringEnum, timestamp, toJsonSchema, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, undefinable, validate, validateObjectSchema };
|
|
490
|
+
export type { CompiledValidator, CompiledValidatorCompiledCode, JsonSchema, JsonSchemaType, ToJsonSchemaOptions };
|
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, 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.
|
|
4
|
-
export {
|
|
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.puFjotry.js';
|
|
4
|
+
export { r as AArraySchemaWithAdapters, s as ADiscriminatorSchema, t as ARecordSchema, u as ARefSchemaWithAdapters, v as AScalarSchema, w as AStringEnumSchema, x as InferObjectOptionalKeys, y as InferObjectRawType, M as MaybeNullable, N as NumberType, z as NumberTypeValues, P as PartialBy, B as Resolve, C as ResultFailure, D as ResultSuccess, E as SchemaMetadata, F as ValidationException, G as errorMessageFromErrors, H as isAAraySchema, J as isADiscriminatorSchema, K as isAObjectSchema, L as isARecordSchema, O as isARefSchema, Q as isAScalarSchema, T as isASchema, U as isAStringEnumSchema, X as isObject, Y as isValidationException, Z as isValueError, _ as newValidationContext } from './shared/schema.puFjotry.js';
|
|
5
5
|
|
|
6
6
|
declare function createParsingTemplate(input: string, schema: Schema, shouldCoerce?: boolean): string;
|
|
7
7
|
|
|
@@ -149,6 +149,69 @@ declare function enumerator<TKeys extends string, TValues extends TKeys[]>(value
|
|
|
149
149
|
*/
|
|
150
150
|
declare function enumerator<TKeys extends string, TValues extends TKeys[]>(id: string, values: TValues): AStringEnumSchemaWithAdapters<TValues>;
|
|
151
151
|
|
|
152
|
+
type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
153
|
+
interface JsonSchema {
|
|
154
|
+
$schema?: string;
|
|
155
|
+
$id?: string;
|
|
156
|
+
$ref?: string;
|
|
157
|
+
$defs?: Record<string, JsonSchema>;
|
|
158
|
+
title?: string;
|
|
159
|
+
description?: string;
|
|
160
|
+
deprecated?: boolean;
|
|
161
|
+
type?: JsonSchemaType | JsonSchemaType[];
|
|
162
|
+
pattern?: string;
|
|
163
|
+
format?: string;
|
|
164
|
+
minLength?: number;
|
|
165
|
+
maxLength?: number;
|
|
166
|
+
minimum?: number;
|
|
167
|
+
maximum?: number;
|
|
168
|
+
exclusiveMinimum?: number;
|
|
169
|
+
exclusiveMaximum?: number;
|
|
170
|
+
enum?: unknown[];
|
|
171
|
+
const?: unknown;
|
|
172
|
+
items?: JsonSchema;
|
|
173
|
+
minItems?: number;
|
|
174
|
+
maxItems?: number;
|
|
175
|
+
properties?: Record<string, JsonSchema>;
|
|
176
|
+
required?: string[];
|
|
177
|
+
additionalProperties?: boolean | JsonSchema;
|
|
178
|
+
oneOf?: JsonSchema[];
|
|
179
|
+
anyOf?: JsonSchema[];
|
|
180
|
+
allOf?: JsonSchema[];
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
}
|
|
183
|
+
interface ToJsonSchemaOptions {
|
|
184
|
+
/** The $id to use for the root schema */
|
|
185
|
+
$id?: string;
|
|
186
|
+
/** The title to use for the root schema */
|
|
187
|
+
title?: string;
|
|
188
|
+
/** The description to use for the root schema */
|
|
189
|
+
description?: string;
|
|
190
|
+
/** The JSON Schema draft version to target */
|
|
191
|
+
$schema?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Convert an Arri schema to JSON Schema format
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const User = a.object({
|
|
198
|
+
* id: a.string(),
|
|
199
|
+
* name: a.string(),
|
|
200
|
+
* email: a.nullable(a.string()),
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* const jsonSchema = toJsonSchema(User, {
|
|
204
|
+
* $id: 'https://example.com/schemas/user.json',
|
|
205
|
+
* title: 'User',
|
|
206
|
+
* });
|
|
207
|
+
*/
|
|
208
|
+
declare function toJsonSchema<T>(schema: ASchema<T>, options?: ToJsonSchemaOptions): JsonSchema;
|
|
209
|
+
/**
|
|
210
|
+
* Convert a raw ATD Schema object to JSON Schema format.
|
|
211
|
+
* This is useful when working with plain schema objects from AppDefinition.
|
|
212
|
+
*/
|
|
213
|
+
declare function schemaToJsonSchema(schema: Schema): JsonSchema;
|
|
214
|
+
|
|
152
215
|
/**
|
|
153
216
|
* Transforms a schema into a nullable type
|
|
154
217
|
*
|
|
@@ -375,6 +438,8 @@ declare function serialize<T = any>(schema: ASchema<T>, input: T): Result<string
|
|
|
375
438
|
declare function serializeUnsafe<T = any>(schema: ASchema<T>, input: T): string;
|
|
376
439
|
declare function errors(schema: ASchema, input: unknown, exitOnFirstError?: boolean): ValueError[];
|
|
377
440
|
|
|
441
|
+
type _namespace_JsonSchema = JsonSchema;
|
|
442
|
+
type _namespace_ToJsonSchemaOptions = ToJsonSchemaOptions;
|
|
378
443
|
declare const _namespace_any: typeof any;
|
|
379
444
|
declare const _namespace_array: typeof array;
|
|
380
445
|
declare const _namespace_boolean: typeof boolean;
|
|
@@ -403,11 +468,13 @@ declare const _namespace_partial: typeof partial;
|
|
|
403
468
|
declare const _namespace_pick: typeof pick;
|
|
404
469
|
declare const _namespace_record: typeof record;
|
|
405
470
|
declare const _namespace_recursive: typeof recursive;
|
|
471
|
+
declare const _namespace_schemaToJsonSchema: typeof schemaToJsonSchema;
|
|
406
472
|
declare const _namespace_serialize: typeof serialize;
|
|
407
473
|
declare const _namespace_serializeUnsafe: typeof serializeUnsafe;
|
|
408
474
|
declare const _namespace_string: typeof string;
|
|
409
475
|
declare const _namespace_stringEnum: typeof stringEnum;
|
|
410
476
|
declare const _namespace_timestamp: typeof timestamp;
|
|
477
|
+
declare const _namespace_toJsonSchema: typeof toJsonSchema;
|
|
411
478
|
declare const _namespace_uint16: typeof uint16;
|
|
412
479
|
declare const _namespace_uint32: typeof uint32;
|
|
413
480
|
declare const _namespace_uint64: typeof uint64;
|
|
@@ -415,50 +482,9 @@ declare const _namespace_uint8: typeof uint8;
|
|
|
415
482
|
declare const _namespace_undefinable: typeof undefinable;
|
|
416
483
|
declare const _namespace_validate: typeof validate;
|
|
417
484
|
declare namespace _namespace {
|
|
418
|
-
export {
|
|
419
|
-
|
|
420
|
-
_namespace_array as array,
|
|
421
|
-
_namespace_boolean as boolean,
|
|
422
|
-
_namespace_clone as clone,
|
|
423
|
-
_namespace_coerce as coerce,
|
|
424
|
-
_namespace_coerceUnsafe as coerceUnsafe,
|
|
425
|
-
_namespace_compile as compile,
|
|
426
|
-
_namespace_discriminator as discriminator,
|
|
427
|
-
_namespace_enumerator as enumerator,
|
|
428
|
-
_namespace_errors as errors,
|
|
429
|
-
_namespace_extend as extend,
|
|
430
|
-
_namespace_float32 as float32,
|
|
431
|
-
_namespace_float64 as float64,
|
|
432
|
-
InferType as infer,
|
|
433
|
-
InferSubType as inferSubType,
|
|
434
|
-
_namespace_int16 as int16,
|
|
435
|
-
_namespace_int32 as int32,
|
|
436
|
-
_namespace_int64 as int64,
|
|
437
|
-
_namespace_int8 as int8,
|
|
438
|
-
_namespace_nullable as nullable,
|
|
439
|
-
_namespace_number as number,
|
|
440
|
-
_namespace_object as object,
|
|
441
|
-
_namespace_omit as omit,
|
|
442
|
-
_namespace_optional as optional,
|
|
443
|
-
_namespace_parse as parse,
|
|
444
|
-
_namespace_parseUnsafe as parseUnsafe,
|
|
445
|
-
_namespace_partial as partial,
|
|
446
|
-
_namespace_pick as pick,
|
|
447
|
-
_namespace_record as record,
|
|
448
|
-
_namespace_recursive as recursive,
|
|
449
|
-
_namespace_serialize as serialize,
|
|
450
|
-
_namespace_serializeUnsafe as serializeUnsafe,
|
|
451
|
-
_namespace_string as string,
|
|
452
|
-
_namespace_stringEnum as stringEnum,
|
|
453
|
-
_namespace_timestamp as timestamp,
|
|
454
|
-
_namespace_uint16 as uint16,
|
|
455
|
-
_namespace_uint32 as uint32,
|
|
456
|
-
_namespace_uint64 as uint64,
|
|
457
|
-
_namespace_uint8 as uint8,
|
|
458
|
-
_namespace_undefinable as undefinable,
|
|
459
|
-
_namespace_validate as validate,
|
|
460
|
-
};
|
|
485
|
+
export { _namespace_any as any, _namespace_array as array, _namespace_boolean as boolean, _namespace_clone as clone, _namespace_coerce as coerce, _namespace_coerceUnsafe as coerceUnsafe, _namespace_compile as compile, _namespace_discriminator as discriminator, _namespace_enumerator as enumerator, _namespace_errors as errors, _namespace_extend as extend, _namespace_float32 as float32, _namespace_float64 as float64, InferType as infer, InferSubType as inferSubType, _namespace_int16 as int16, _namespace_int32 as int32, _namespace_int64 as int64, _namespace_int8 as int8, _namespace_nullable as nullable, _namespace_number as number, _namespace_object as object, _namespace_omit as omit, _namespace_optional as optional, _namespace_parse as parse, _namespace_parseUnsafe as parseUnsafe, _namespace_partial as partial, _namespace_pick as pick, _namespace_record as record, _namespace_recursive as recursive, _namespace_schemaToJsonSchema as schemaToJsonSchema, _namespace_serialize as serialize, _namespace_serializeUnsafe as serializeUnsafe, _namespace_string as string, _namespace_stringEnum as stringEnum, _namespace_timestamp as timestamp, _namespace_toJsonSchema as toJsonSchema, _namespace_uint16 as uint16, _namespace_uint32 as uint32, _namespace_uint64 as uint64, _namespace_uint8 as uint8, _namespace_undefinable as undefinable, _namespace_validate as validate };
|
|
486
|
+
export type { _namespace_JsonSchema as JsonSchema, _namespace_ToJsonSchemaOptions as ToJsonSchemaOptions };
|
|
461
487
|
}
|
|
462
488
|
|
|
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 };
|
|
464
|
-
export type { CompiledValidator, CompiledValidatorCompiledCode };
|
|
489
|
+
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, schemaToJsonSchema, serialize, serializeObject, serializeSmallString, serializeString, serializeUnsafe, string, stringEnum, timestamp, toJsonSchema, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, undefinable, validate, validateObjectSchema };
|
|
490
|
+
export type { CompiledValidator, CompiledValidatorCompiledCode, JsonSchema, JsonSchemaType, ToJsonSchemaOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -2817,6 +2817,136 @@ function enumerator(paramA, paramB) {
|
|
|
2817
2817
|
return result;
|
|
2818
2818
|
}
|
|
2819
2819
|
|
|
2820
|
+
function toJsonSchema(schema, options) {
|
|
2821
|
+
return applyRootOptions(
|
|
2822
|
+
schemaToJsonSchema(schema),
|
|
2823
|
+
options
|
|
2824
|
+
);
|
|
2825
|
+
}
|
|
2826
|
+
function schemaToJsonSchema(schema) {
|
|
2827
|
+
return convertSchema(schema);
|
|
2828
|
+
}
|
|
2829
|
+
function applyRootOptions(schema, options) {
|
|
2830
|
+
return {
|
|
2831
|
+
...schema,
|
|
2832
|
+
$schema: options?.$schema ?? "https://json-schema.org/draft/2020-12/schema",
|
|
2833
|
+
...options?.$id && { $id: options.$id },
|
|
2834
|
+
...options?.title && { title: options.title },
|
|
2835
|
+
...options?.description && { description: options.description }
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
const SCALAR_MAPPINGS = {
|
|
2839
|
+
string: { type: "string" },
|
|
2840
|
+
boolean: { type: "boolean" },
|
|
2841
|
+
timestamp: { type: "string", format: "date-time" },
|
|
2842
|
+
float32: { type: "number" },
|
|
2843
|
+
float64: { type: "number" },
|
|
2844
|
+
int8: { type: "integer", minimum: int8Min, maximum: int8Max },
|
|
2845
|
+
uint8: { type: "integer", minimum: uint8Min, maximum: uint8Max },
|
|
2846
|
+
int16: { type: "integer", minimum: int16Min, maximum: int16Max },
|
|
2847
|
+
uint16: { type: "integer", minimum: uint16Min, maximum: uint16Max },
|
|
2848
|
+
int32: { type: "integer", minimum: int32Min, maximum: int32Max },
|
|
2849
|
+
uint32: { type: "integer", minimum: uint32Min, maximum: uint32Max },
|
|
2850
|
+
int64: { type: "string", pattern: "^-?[0-9]+$" },
|
|
2851
|
+
uint64: { type: "string", pattern: "^[0-9]+$" }
|
|
2852
|
+
};
|
|
2853
|
+
function convertSchema(schema) {
|
|
2854
|
+
const base = getBaseSchema(schema);
|
|
2855
|
+
return schema.isNullable ? makeNullable(base, schema) : applyMetadata(base, schema);
|
|
2856
|
+
}
|
|
2857
|
+
function getBaseSchema(schema) {
|
|
2858
|
+
if (isSchemaFormType(schema)) {
|
|
2859
|
+
const mapping = SCALAR_MAPPINGS[schema.type];
|
|
2860
|
+
return mapping ? { ...mapping } : {};
|
|
2861
|
+
}
|
|
2862
|
+
if (isSchemaFormEnum(schema)) {
|
|
2863
|
+
return {
|
|
2864
|
+
type: "string",
|
|
2865
|
+
enum: [...schema.enum]
|
|
2866
|
+
};
|
|
2867
|
+
}
|
|
2868
|
+
if (isSchemaFormElements(schema)) {
|
|
2869
|
+
return {
|
|
2870
|
+
type: "array",
|
|
2871
|
+
items: convertSchema(schema.elements)
|
|
2872
|
+
};
|
|
2873
|
+
}
|
|
2874
|
+
if (isSchemaFormProperties(schema)) {
|
|
2875
|
+
return convertObject(schema);
|
|
2876
|
+
}
|
|
2877
|
+
if (isSchemaFormValues(schema)) {
|
|
2878
|
+
return {
|
|
2879
|
+
type: "object",
|
|
2880
|
+
additionalProperties: convertSchema(schema.values)
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
if (isSchemaFormDiscriminator(schema)) {
|
|
2884
|
+
return convertDiscriminator(schema);
|
|
2885
|
+
}
|
|
2886
|
+
if (isSchemaFormRef(schema)) {
|
|
2887
|
+
return { $ref: `#/$defs/${schema.ref}` };
|
|
2888
|
+
}
|
|
2889
|
+
if (isSchemaFormEmpty(schema)) return {};
|
|
2890
|
+
return {};
|
|
2891
|
+
}
|
|
2892
|
+
function convertObject(schema) {
|
|
2893
|
+
const properties = {};
|
|
2894
|
+
const required = [];
|
|
2895
|
+
for (const [key, prop] of Object.entries(schema.properties ?? {})) {
|
|
2896
|
+
properties[key] = convertSchema(prop);
|
|
2897
|
+
required.push(key);
|
|
2898
|
+
}
|
|
2899
|
+
for (const [key, prop] of Object.entries(schema.optionalProperties ?? {})) {
|
|
2900
|
+
properties[key] = convertSchema(prop);
|
|
2901
|
+
}
|
|
2902
|
+
return {
|
|
2903
|
+
type: "object",
|
|
2904
|
+
properties,
|
|
2905
|
+
...required.length > 0 && { required },
|
|
2906
|
+
...schema.isStrict && { additionalProperties: false }
|
|
2907
|
+
};
|
|
2908
|
+
}
|
|
2909
|
+
function convertDiscriminator(schema) {
|
|
2910
|
+
const oneOf = Object.entries(schema.mapping).map(
|
|
2911
|
+
([value, mappingSchema]) => {
|
|
2912
|
+
const variant = convertObject(mappingSchema);
|
|
2913
|
+
variant.properties = {
|
|
2914
|
+
...variant.properties,
|
|
2915
|
+
[schema.discriminator]: { type: "string", const: value }
|
|
2916
|
+
};
|
|
2917
|
+
variant.required = [
|
|
2918
|
+
...variant.required ?? [],
|
|
2919
|
+
schema.discriminator
|
|
2920
|
+
];
|
|
2921
|
+
return variant;
|
|
2922
|
+
}
|
|
2923
|
+
);
|
|
2924
|
+
return { oneOf };
|
|
2925
|
+
}
|
|
2926
|
+
function makeNullable(jsonSchema, atdSchema) {
|
|
2927
|
+
if (jsonSchema.$ref || jsonSchema.oneOf) {
|
|
2928
|
+
return applyMetadata(
|
|
2929
|
+
{ anyOf: [jsonSchema, { type: "null" }] },
|
|
2930
|
+
atdSchema
|
|
2931
|
+
);
|
|
2932
|
+
}
|
|
2933
|
+
if (jsonSchema.type) {
|
|
2934
|
+
const types = Array.isArray(jsonSchema.type) ? jsonSchema.type : [jsonSchema.type];
|
|
2935
|
+
jsonSchema.type = types.includes("null") ? types : [...types, "null"];
|
|
2936
|
+
return applyMetadata(jsonSchema, atdSchema);
|
|
2937
|
+
}
|
|
2938
|
+
return applyMetadata({ anyOf: [jsonSchema, { type: "null" }] }, atdSchema);
|
|
2939
|
+
}
|
|
2940
|
+
function applyMetadata(jsonSchema, { metadata }) {
|
|
2941
|
+
if (!metadata) return jsonSchema;
|
|
2942
|
+
return {
|
|
2943
|
+
...jsonSchema,
|
|
2944
|
+
...metadata.id && { title: metadata.id },
|
|
2945
|
+
...metadata.description && { description: metadata.description },
|
|
2946
|
+
...metadata.isDeprecated && { deprecated: true }
|
|
2947
|
+
};
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2820
2950
|
function nullable(schema, opts = {}) {
|
|
2821
2951
|
const isType = (val) => {
|
|
2822
2952
|
if (val === null) {
|
|
@@ -4278,11 +4408,13 @@ const _namespace = {
|
|
|
4278
4408
|
pick: pick,
|
|
4279
4409
|
record: record,
|
|
4280
4410
|
recursive: recursive,
|
|
4411
|
+
schemaToJsonSchema: schemaToJsonSchema,
|
|
4281
4412
|
serialize: serialize,
|
|
4282
4413
|
serializeUnsafe: serializeUnsafe,
|
|
4283
4414
|
string: string,
|
|
4284
4415
|
stringEnum: stringEnum,
|
|
4285
4416
|
timestamp: timestamp,
|
|
4417
|
+
toJsonSchema: toJsonSchema,
|
|
4286
4418
|
uint16: uint16,
|
|
4287
4419
|
uint32: uint32,
|
|
4288
4420
|
uint64: uint64,
|
|
@@ -4291,4 +4423,4 @@ const _namespace = {
|
|
|
4291
4423
|
validate: validate
|
|
4292
4424
|
};
|
|
4293
4425
|
|
|
4294
|
-
export { STR_ESCAPE, VALIDATOR_KEY, ValidationException, _namespace as a, any, array, boolean, clone, coerce, coerceUnsafe, compile, decodeObjectSchema, discriminator, enumerator, errorMessageFromErrors, 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, isAAraySchema, isADiscriminatorSchema, isAObjectSchema, isARecordSchema, isARefSchema, isAScalarSchema, isAStringEnumSchema, isObject, isValidationException, isValueError, newValidationContext, 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 };
|
|
4426
|
+
export { STR_ESCAPE, VALIDATOR_KEY, ValidationException, _namespace as a, any, array, boolean, clone, coerce, coerceUnsafe, compile, decodeObjectSchema, discriminator, enumerator, errorMessageFromErrors, 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, isAAraySchema, isADiscriminatorSchema, isAObjectSchema, isARecordSchema, isARefSchema, isAScalarSchema, isAStringEnumSchema, isObject, isValidationException, isValueError, newValidationContext, nullable, number, object, omit, optional, parse, parseUnsafe, partial, pick, record, recursive, sanitizeJson, schemaToJsonSchema, serialize, serializeObject, serializeSmallString, serializeString, serializeUnsafe, string, stringEnum, timestamp, toJsonSchema, uint16, uint16Max, uint16Min, uint32, uint32Max, uint32Min, uint64, uint64Max, uint64Min, uint8, uint8Max, uint8Min, undefinable, validate, validateObjectSchema };
|
|
@@ -176,5 +176,5 @@ interface ARefSchema<T> extends ASchema<T> {
|
|
|
176
176
|
declare function isARefSchema(input: unknown): input is ARefSchema<any>;
|
|
177
177
|
type ARefSchemaWithAdapters<T> = ARefSchema<T> & WithAdapters<T>;
|
|
178
178
|
|
|
179
|
-
export {
|
|
180
|
-
export type { ASchema as A, Resolve as B,
|
|
179
|
+
export { ValidationException as F, errorMessageFromErrors as G, isAAraySchema as H, isADiscriminatorSchema as J, isAObjectSchema as K, isARecordSchema as L, isARefSchema as O, isAScalarSchema as Q, isASchema as T, isAStringEnumSchema as U, VALIDATOR_KEY as V, isObject as X, isValidationException as Y, isValueError as Z, newValidationContext as _, NumberTypeValues as z };
|
|
180
|
+
export type { ASchema as A, Resolve as B, ResultFailure as C, ResultSuccess as D, SchemaMetadata as E, InferType as I, MaybeNullable as M, NumberType as N, PartialBy as P, Result as R, SchemaValidator as S, WithAdapters as W, ASchemaStrict as a, ASchemaOptions as b, ASchemaWithAdapters as c, AArraySchema as d, AScalarSchemaWithAdapters as e, AObjectSchema as f, ADiscriminatorSchemaWithAdapters as g, ResolveObject as h, AStringEnumSchemaWithAdapters as i, AObjectSchemaWithAdapters as j, AObjectSchemaOptions as k, InferObjectOutput as l, ValidationContext as m, ARecordSchemaWithAdapters as n, ARefSchema as o, ValueError as p, InferSubType as q, AArraySchemaWithAdapters as r, ADiscriminatorSchema as s, ARecordSchema as t, ARefSchemaWithAdapters as u, AScalarSchema as v, AStringEnumSchema as w, InferObjectOptionalKeys as x, InferObjectRawType as y };
|
|
@@ -176,5 +176,5 @@ interface ARefSchema<T> extends ASchema<T> {
|
|
|
176
176
|
declare function isARefSchema(input: unknown): input is ARefSchema<any>;
|
|
177
177
|
type ARefSchemaWithAdapters<T> = ARefSchema<T> & WithAdapters<T>;
|
|
178
178
|
|
|
179
|
-
export {
|
|
180
|
-
export type { ASchema as A, Resolve as B,
|
|
179
|
+
export { ValidationException as F, errorMessageFromErrors as G, isAAraySchema as H, isADiscriminatorSchema as J, isAObjectSchema as K, isARecordSchema as L, isARefSchema as O, isAScalarSchema as Q, isASchema as T, isAStringEnumSchema as U, VALIDATOR_KEY as V, isObject as X, isValidationException as Y, isValueError as Z, newValidationContext as _, NumberTypeValues as z };
|
|
180
|
+
export type { ASchema as A, Resolve as B, ResultFailure as C, ResultSuccess as D, SchemaMetadata as E, InferType as I, MaybeNullable as M, NumberType as N, PartialBy as P, Result as R, SchemaValidator as S, WithAdapters as W, ASchemaStrict as a, ASchemaOptions as b, ASchemaWithAdapters as c, AArraySchema as d, AScalarSchemaWithAdapters as e, AObjectSchema as f, ADiscriminatorSchemaWithAdapters as g, ResolveObject as h, AStringEnumSchemaWithAdapters as i, AObjectSchemaWithAdapters as j, AObjectSchemaOptions as k, InferObjectOutput as l, ValidationContext as m, ARecordSchemaWithAdapters as n, ARefSchema as o, ValueError as p, InferSubType as q, AArraySchemaWithAdapters as r, ADiscriminatorSchema as s, ARecordSchema as t, ARefSchemaWithAdapters as u, AScalarSchema as v, AStringEnumSchema as w, InferObjectOptionalKeys as x, InferObjectRawType as y };
|
|
@@ -176,5 +176,5 @@ interface ARefSchema<T> extends ASchema<T> {
|
|
|
176
176
|
declare function isARefSchema(input: unknown): input is ARefSchema<any>;
|
|
177
177
|
type ARefSchemaWithAdapters<T> = ARefSchema<T> & WithAdapters<T>;
|
|
178
178
|
|
|
179
|
-
export {
|
|
180
|
-
export type { ASchema as A, Resolve as B,
|
|
179
|
+
export { ValidationException as F, errorMessageFromErrors as G, isAAraySchema as H, isADiscriminatorSchema as J, isAObjectSchema as K, isARecordSchema as L, isARefSchema as O, isAScalarSchema as Q, isASchema as T, isAStringEnumSchema as U, VALIDATOR_KEY as V, isObject as X, isValidationException as Y, isValueError as Z, newValidationContext as _, NumberTypeValues as z };
|
|
180
|
+
export type { ASchema as A, Resolve as B, ResultFailure as C, ResultSuccess as D, SchemaMetadata as E, InferType as I, MaybeNullable as M, NumberType as N, PartialBy as P, Result as R, SchemaValidator as S, WithAdapters as W, ASchemaStrict as a, ASchemaOptions as b, ASchemaWithAdapters as c, AArraySchema as d, AScalarSchemaWithAdapters as e, AObjectSchema as f, ADiscriminatorSchemaWithAdapters as g, ResolveObject as h, AStringEnumSchemaWithAdapters as i, AObjectSchemaWithAdapters as j, AObjectSchemaOptions as k, InferObjectOutput as l, ValidationContext as m, ARecordSchemaWithAdapters as n, ARefSchema as o, ValueError as p, InferSubType as q, AArraySchemaWithAdapters as r, ADiscriminatorSchema as s, ARecordSchema as t, ARefSchemaWithAdapters as u, AScalarSchema as v, AStringEnumSchema as w, InferObjectOptionalKeys as x, InferObjectRawType as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/schema",
|
|
3
|
-
"version": "0.81.
|
|
3
|
+
"version": "0.81.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@standard-schema/spec": "1.
|
|
25
|
+
"@standard-schema/spec": "1.1.0",
|
|
26
26
|
"scule": "^1.3.0",
|
|
27
27
|
"uncrypto": "^0.1.3",
|
|
28
|
-
"@arrirpc/type-defs": "0.81.
|
|
28
|
+
"@arrirpc/type-defs": "0.81.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@samchon/openapi": "^
|
|
32
|
-
"@sinclair/typebox": "^0.34.
|
|
31
|
+
"@samchon/openapi": "^6.0.1",
|
|
32
|
+
"@sinclair/typebox": "^0.34.48",
|
|
33
33
|
"ajv": "^8.17.1",
|
|
34
|
-
"arktype": "^2.1.
|
|
34
|
+
"arktype": "^2.1.29",
|
|
35
35
|
"benny": "^3.7.1",
|
|
36
|
-
"typia": "^
|
|
36
|
+
"typia": "^11.0.3",
|
|
37
37
|
"valibot": "1.2.0",
|
|
38
|
-
"zod": "^4.
|
|
38
|
+
"zod": "^4.3.6"
|
|
39
39
|
}
|
|
40
40
|
}
|