@standard-community/standard-json 0.2.0 → 0.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -28
- package/dist/index.cjs +62 -1
- package/dist/index.d.cts +2 -223
- package/dist/index.d.ts +2 -223
- package/dist/index.js +60 -1
- package/package.json +25 -11
- package/dist/arktype-Dl6TXwAj.cjs +0 -1
- package/dist/arktype-rPtBJvA_.js +0 -1
- package/dist/effect-Bz0yPX2a.cjs +0 -1
- package/dist/effect-lIj12xeO.js +0 -1
- package/dist/index-BiXjOJ4o.cjs +0 -1
- package/dist/index-BnLYQduk.js +0 -1
- package/dist/valibot-BJZP6MXN.cjs +0 -1
- package/dist/valibot-x7jZH0Fn.js +0 -1
- package/dist/zod-DDSZCko0.cjs +0 -1
- package/dist/zod-UXmI2DWZ.js +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.org/package/@standard-community/standard-json "View this project on NPM")
|
|
4
4
|
[](https://www.npmjs.com/package/@standard-community/standard-json)
|
|
5
|
-
[](LICENSE)
|
|
6
5
|
|
|
7
6
|
Standard Schema Validator's JSON Schema Converter
|
|
8
7
|
|
|
@@ -18,7 +17,7 @@ For some specific vendor, install the respective package also -
|
|
|
18
17
|
|
|
19
18
|
| Vendor | Package |
|
|
20
19
|
| ------- | ------- |
|
|
21
|
-
| Zod
|
|
20
|
+
| Zod v3 | `zod-to-json-schema` |
|
|
22
21
|
| Valibot | `@valibot/to-json-schema` |
|
|
23
22
|
|
|
24
23
|
## Usage
|
|
@@ -26,33 +25,11 @@ For some specific vendor, install the respective package also -
|
|
|
26
25
|
```ts
|
|
27
26
|
import { toJsonSchema } from "@standard-community/standard-json";
|
|
28
27
|
|
|
29
|
-
// Define your schema
|
|
30
|
-
const schema =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
myUnion: v.union([v.number(), v.boolean()]),
|
|
34
|
-
}),
|
|
35
|
-
v.description("My neat object schema"),
|
|
36
|
-
);
|
|
28
|
+
// Define your validation schema
|
|
29
|
+
const schema = {
|
|
30
|
+
// ...
|
|
31
|
+
};
|
|
37
32
|
|
|
38
33
|
// Convert it to JSON Schema
|
|
39
34
|
const jsonSchema = await toJsonSchema(schema);
|
|
40
35
|
```
|
|
41
|
-
|
|
42
|
-
## Compatibility
|
|
43
|
-
|
|
44
|
-
List of supported validators -
|
|
45
|
-
|
|
46
|
-
| Vendor | Supported |
|
|
47
|
-
| ------- | ------- |
|
|
48
|
-
| Zod | ✅ |
|
|
49
|
-
| Valibot | ✅ |
|
|
50
|
-
| ArkType | ✅ |
|
|
51
|
-
| Typebox | ✅ (Using [TypeMap](https://github.com/sinclairzx81/typemap) |
|
|
52
|
-
| Effect Schema | 🛠️ |
|
|
53
|
-
|
|
54
|
-
You can check the compatibility versions at [standardschema.dev](https://standardschema.dev/)
|
|
55
|
-
|
|
56
|
-
## Credit
|
|
57
|
-
|
|
58
|
-
- This project is inspired by the work of [kwaa](https://github.com/kwaa) and their [xsschema](https://xsai.js.org/docs/packages/top-level/xsschema) package.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getToJsonSchemaFn$4 = async () => (schema) => schema.toJsonSchema();
|
|
4
|
+
|
|
5
|
+
const errorMessageWrapper = (message) => `standard-json: ${message}`;
|
|
6
|
+
const tryImport = async (result, name) => {
|
|
7
|
+
try {
|
|
8
|
+
return await result;
|
|
9
|
+
} catch {
|
|
10
|
+
throw new Error(errorMessageWrapper(`Missing dependencies "${name}".`));
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getToJsonSchemaFn$3 = async () => {
|
|
15
|
+
const { JSONSchema } = await tryImport(import('effect'), "effect");
|
|
16
|
+
return (schema) => JSONSchema.make(schema);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getToJsonSchemaFn$2 = async () => {
|
|
20
|
+
const { toJsonSchema } = await tryImport(
|
|
21
|
+
import('@valibot/to-json-schema'),
|
|
22
|
+
"@valibot/to-json-schema"
|
|
23
|
+
);
|
|
24
|
+
return (schema, options) => toJsonSchema(
|
|
25
|
+
schema,
|
|
26
|
+
options
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getToJsonSchemaFn$1 = async () => async (schema, options) => {
|
|
31
|
+
let handler;
|
|
32
|
+
if ("_zod" in schema)
|
|
33
|
+
handler = await tryImport(import('zod/v4/core'), "zod v4").then(
|
|
34
|
+
(mod) => mod.toJSONSchema
|
|
35
|
+
);
|
|
36
|
+
else
|
|
37
|
+
handler = await tryImport(import('zod-to-json-schema'), "zod v3").then(
|
|
38
|
+
(mod) => mod.zodToJsonSchema
|
|
39
|
+
);
|
|
40
|
+
return handler(schema, options);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const vendorToFn = {
|
|
44
|
+
arktype: getToJsonSchemaFn$4,
|
|
45
|
+
effect: getToJsonSchemaFn$3,
|
|
46
|
+
valibot: getToJsonSchemaFn$2,
|
|
47
|
+
zod: getToJsonSchemaFn$1
|
|
48
|
+
};
|
|
49
|
+
const getToJsonSchemaFn = async (vendor) => {
|
|
50
|
+
const venderConvertor = vendorToFn[vendor];
|
|
51
|
+
if (!venderConvertor)
|
|
52
|
+
throw new Error(
|
|
53
|
+
errorMessageWrapper(`Unsupported schema vendor "${vendor}"`)
|
|
54
|
+
);
|
|
55
|
+
return venderConvertor();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const toJsonSchema = (schema) => getToJsonSchemaFn(schema["~standard"].vendor).then(
|
|
59
|
+
(toJsonSchema2) => toJsonSchema2(schema)
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
exports.toJsonSchema = toJsonSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,226 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** The Standard Schema properties. */
|
|
4
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
|
-
}
|
|
6
|
-
declare namespace StandardSchemaV1 {
|
|
7
|
-
/** The Standard Schema properties interface. */
|
|
8
|
-
export interface Props<Input = unknown, Output = Input> {
|
|
9
|
-
/** The version number of the standard. */
|
|
10
|
-
readonly version: 1;
|
|
11
|
-
/** The vendor name of the schema library. */
|
|
12
|
-
readonly vendor: string;
|
|
13
|
-
/** Validates unknown input values. */
|
|
14
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
15
|
-
/** Inferred types associated with the schema. */
|
|
16
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
-
}
|
|
18
|
-
/** The result interface of the validate function. */
|
|
19
|
-
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
|
-
/** The result interface if validation succeeds. */
|
|
21
|
-
export interface SuccessResult<Output> {
|
|
22
|
-
/** The typed output value. */
|
|
23
|
-
readonly value: Output;
|
|
24
|
-
/** The non-existent issues. */
|
|
25
|
-
readonly issues?: undefined;
|
|
26
|
-
}
|
|
27
|
-
/** The result interface if validation fails. */
|
|
28
|
-
export interface FailureResult {
|
|
29
|
-
/** The issues of failed validation. */
|
|
30
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
31
|
-
}
|
|
32
|
-
/** The issue interface of the failure output. */
|
|
33
|
-
export interface Issue {
|
|
34
|
-
/** The error message of the issue. */
|
|
35
|
-
readonly message: string;
|
|
36
|
-
/** The path of the issue, if any. */
|
|
37
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
38
|
-
}
|
|
39
|
-
/** The path segment interface of the issue. */
|
|
40
|
-
export interface PathSegment {
|
|
41
|
-
/** The key representing a path segment. */
|
|
42
|
-
readonly key: PropertyKey;
|
|
43
|
-
}
|
|
44
|
-
/** The Standard Schema types interface. */
|
|
45
|
-
export interface Types<Input = unknown, Output = Input> {
|
|
46
|
-
/** The input type of the schema. */
|
|
47
|
-
readonly input: Input;
|
|
48
|
-
/** The output type of the schema. */
|
|
49
|
-
readonly output: Output;
|
|
50
|
-
}
|
|
51
|
-
/** Infers the input type of a Standard Schema. */
|
|
52
|
-
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
53
|
-
/** Infers the output type of a Standard Schema. */
|
|
54
|
-
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
55
|
-
export { };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ==================================================================================================
|
|
59
|
-
// JSON Schema Draft 07
|
|
60
|
-
// ==================================================================================================
|
|
61
|
-
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
62
|
-
// --------------------------------------------------------------------------------------------------
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Primitive type
|
|
66
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
67
|
-
*/
|
|
68
|
-
type JSONSchema7TypeName =
|
|
69
|
-
| "string" //
|
|
70
|
-
| "number"
|
|
71
|
-
| "integer"
|
|
72
|
-
| "boolean"
|
|
73
|
-
| "object"
|
|
74
|
-
| "array"
|
|
75
|
-
| "null";
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Primitive type
|
|
79
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
80
|
-
*/
|
|
81
|
-
type JSONSchema7Type =
|
|
82
|
-
| string //
|
|
83
|
-
| number
|
|
84
|
-
| boolean
|
|
85
|
-
| JSONSchema7Object
|
|
86
|
-
| JSONSchema7Array
|
|
87
|
-
| null;
|
|
88
|
-
|
|
89
|
-
// Workaround for infinite type recursion
|
|
90
|
-
interface JSONSchema7Object {
|
|
91
|
-
[key: string]: JSONSchema7Type;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Workaround for infinite type recursion
|
|
95
|
-
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
|
96
|
-
interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Meta schema
|
|
100
|
-
*
|
|
101
|
-
* Recommended values:
|
|
102
|
-
* - 'http://json-schema.org/schema#'
|
|
103
|
-
* - 'http://json-schema.org/hyper-schema#'
|
|
104
|
-
* - 'http://json-schema.org/draft-07/schema#'
|
|
105
|
-
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
106
|
-
*
|
|
107
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
108
|
-
*/
|
|
109
|
-
type JSONSchema7Version = string;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* JSON Schema v7
|
|
113
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
114
|
-
*/
|
|
115
|
-
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
116
|
-
interface JSONSchema7 {
|
|
117
|
-
$id?: string | undefined;
|
|
118
|
-
$ref?: string | undefined;
|
|
119
|
-
$schema?: JSONSchema7Version | undefined;
|
|
120
|
-
$comment?: string | undefined;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
|
124
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
|
125
|
-
*/
|
|
126
|
-
$defs?: {
|
|
127
|
-
[key: string]: JSONSchema7Definition;
|
|
128
|
-
} | undefined;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
|
132
|
-
*/
|
|
133
|
-
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
134
|
-
enum?: JSONSchema7Type[] | undefined;
|
|
135
|
-
const?: JSONSchema7Type | undefined;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
|
139
|
-
*/
|
|
140
|
-
multipleOf?: number | undefined;
|
|
141
|
-
maximum?: number | undefined;
|
|
142
|
-
exclusiveMaximum?: number | undefined;
|
|
143
|
-
minimum?: number | undefined;
|
|
144
|
-
exclusiveMinimum?: number | undefined;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
|
148
|
-
*/
|
|
149
|
-
maxLength?: number | undefined;
|
|
150
|
-
minLength?: number | undefined;
|
|
151
|
-
pattern?: string | undefined;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
|
155
|
-
*/
|
|
156
|
-
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
157
|
-
additionalItems?: JSONSchema7Definition | undefined;
|
|
158
|
-
maxItems?: number | undefined;
|
|
159
|
-
minItems?: number | undefined;
|
|
160
|
-
uniqueItems?: boolean | undefined;
|
|
161
|
-
contains?: JSONSchema7Definition | undefined;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
|
165
|
-
*/
|
|
166
|
-
maxProperties?: number | undefined;
|
|
167
|
-
minProperties?: number | undefined;
|
|
168
|
-
required?: string[] | undefined;
|
|
169
|
-
properties?: {
|
|
170
|
-
[key: string]: JSONSchema7Definition;
|
|
171
|
-
} | undefined;
|
|
172
|
-
patternProperties?: {
|
|
173
|
-
[key: string]: JSONSchema7Definition;
|
|
174
|
-
} | undefined;
|
|
175
|
-
additionalProperties?: JSONSchema7Definition | undefined;
|
|
176
|
-
dependencies?: {
|
|
177
|
-
[key: string]: JSONSchema7Definition | string[];
|
|
178
|
-
} | undefined;
|
|
179
|
-
propertyNames?: JSONSchema7Definition | undefined;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
|
183
|
-
*/
|
|
184
|
-
if?: JSONSchema7Definition | undefined;
|
|
185
|
-
then?: JSONSchema7Definition | undefined;
|
|
186
|
-
else?: JSONSchema7Definition | undefined;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
|
190
|
-
*/
|
|
191
|
-
allOf?: JSONSchema7Definition[] | undefined;
|
|
192
|
-
anyOf?: JSONSchema7Definition[] | undefined;
|
|
193
|
-
oneOf?: JSONSchema7Definition[] | undefined;
|
|
194
|
-
not?: JSONSchema7Definition | undefined;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
|
198
|
-
*/
|
|
199
|
-
format?: string | undefined;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
|
203
|
-
*/
|
|
204
|
-
contentMediaType?: string | undefined;
|
|
205
|
-
contentEncoding?: string | undefined;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
|
209
|
-
*/
|
|
210
|
-
definitions?: {
|
|
211
|
-
[key: string]: JSONSchema7Definition;
|
|
212
|
-
} | undefined;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
216
|
-
*/
|
|
217
|
-
title?: string | undefined;
|
|
218
|
-
description?: string | undefined;
|
|
219
|
-
default?: JSONSchema7Type | undefined;
|
|
220
|
-
readOnly?: boolean | undefined;
|
|
221
|
-
writeOnly?: boolean | undefined;
|
|
222
|
-
examples?: JSONSchema7Type | undefined;
|
|
223
|
-
}
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { JSONSchema7 } from 'json-schema';
|
|
224
3
|
|
|
225
4
|
/**
|
|
226
5
|
* Converts a Standard Schema to a JSON schema.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,226 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** The Standard Schema properties. */
|
|
4
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
|
-
}
|
|
6
|
-
declare namespace StandardSchemaV1 {
|
|
7
|
-
/** The Standard Schema properties interface. */
|
|
8
|
-
export interface Props<Input = unknown, Output = Input> {
|
|
9
|
-
/** The version number of the standard. */
|
|
10
|
-
readonly version: 1;
|
|
11
|
-
/** The vendor name of the schema library. */
|
|
12
|
-
readonly vendor: string;
|
|
13
|
-
/** Validates unknown input values. */
|
|
14
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
15
|
-
/** Inferred types associated with the schema. */
|
|
16
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
-
}
|
|
18
|
-
/** The result interface of the validate function. */
|
|
19
|
-
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
|
-
/** The result interface if validation succeeds. */
|
|
21
|
-
export interface SuccessResult<Output> {
|
|
22
|
-
/** The typed output value. */
|
|
23
|
-
readonly value: Output;
|
|
24
|
-
/** The non-existent issues. */
|
|
25
|
-
readonly issues?: undefined;
|
|
26
|
-
}
|
|
27
|
-
/** The result interface if validation fails. */
|
|
28
|
-
export interface FailureResult {
|
|
29
|
-
/** The issues of failed validation. */
|
|
30
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
31
|
-
}
|
|
32
|
-
/** The issue interface of the failure output. */
|
|
33
|
-
export interface Issue {
|
|
34
|
-
/** The error message of the issue. */
|
|
35
|
-
readonly message: string;
|
|
36
|
-
/** The path of the issue, if any. */
|
|
37
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
38
|
-
}
|
|
39
|
-
/** The path segment interface of the issue. */
|
|
40
|
-
export interface PathSegment {
|
|
41
|
-
/** The key representing a path segment. */
|
|
42
|
-
readonly key: PropertyKey;
|
|
43
|
-
}
|
|
44
|
-
/** The Standard Schema types interface. */
|
|
45
|
-
export interface Types<Input = unknown, Output = Input> {
|
|
46
|
-
/** The input type of the schema. */
|
|
47
|
-
readonly input: Input;
|
|
48
|
-
/** The output type of the schema. */
|
|
49
|
-
readonly output: Output;
|
|
50
|
-
}
|
|
51
|
-
/** Infers the input type of a Standard Schema. */
|
|
52
|
-
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
53
|
-
/** Infers the output type of a Standard Schema. */
|
|
54
|
-
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
55
|
-
export { };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ==================================================================================================
|
|
59
|
-
// JSON Schema Draft 07
|
|
60
|
-
// ==================================================================================================
|
|
61
|
-
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
62
|
-
// --------------------------------------------------------------------------------------------------
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Primitive type
|
|
66
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
67
|
-
*/
|
|
68
|
-
type JSONSchema7TypeName =
|
|
69
|
-
| "string" //
|
|
70
|
-
| "number"
|
|
71
|
-
| "integer"
|
|
72
|
-
| "boolean"
|
|
73
|
-
| "object"
|
|
74
|
-
| "array"
|
|
75
|
-
| "null";
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Primitive type
|
|
79
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
80
|
-
*/
|
|
81
|
-
type JSONSchema7Type =
|
|
82
|
-
| string //
|
|
83
|
-
| number
|
|
84
|
-
| boolean
|
|
85
|
-
| JSONSchema7Object
|
|
86
|
-
| JSONSchema7Array
|
|
87
|
-
| null;
|
|
88
|
-
|
|
89
|
-
// Workaround for infinite type recursion
|
|
90
|
-
interface JSONSchema7Object {
|
|
91
|
-
[key: string]: JSONSchema7Type;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Workaround for infinite type recursion
|
|
95
|
-
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
|
96
|
-
interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Meta schema
|
|
100
|
-
*
|
|
101
|
-
* Recommended values:
|
|
102
|
-
* - 'http://json-schema.org/schema#'
|
|
103
|
-
* - 'http://json-schema.org/hyper-schema#'
|
|
104
|
-
* - 'http://json-schema.org/draft-07/schema#'
|
|
105
|
-
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
106
|
-
*
|
|
107
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
108
|
-
*/
|
|
109
|
-
type JSONSchema7Version = string;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* JSON Schema v7
|
|
113
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
114
|
-
*/
|
|
115
|
-
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
116
|
-
interface JSONSchema7 {
|
|
117
|
-
$id?: string | undefined;
|
|
118
|
-
$ref?: string | undefined;
|
|
119
|
-
$schema?: JSONSchema7Version | undefined;
|
|
120
|
-
$comment?: string | undefined;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
|
124
|
-
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
|
125
|
-
*/
|
|
126
|
-
$defs?: {
|
|
127
|
-
[key: string]: JSONSchema7Definition;
|
|
128
|
-
} | undefined;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
|
132
|
-
*/
|
|
133
|
-
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
134
|
-
enum?: JSONSchema7Type[] | undefined;
|
|
135
|
-
const?: JSONSchema7Type | undefined;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
|
139
|
-
*/
|
|
140
|
-
multipleOf?: number | undefined;
|
|
141
|
-
maximum?: number | undefined;
|
|
142
|
-
exclusiveMaximum?: number | undefined;
|
|
143
|
-
minimum?: number | undefined;
|
|
144
|
-
exclusiveMinimum?: number | undefined;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
|
148
|
-
*/
|
|
149
|
-
maxLength?: number | undefined;
|
|
150
|
-
minLength?: number | undefined;
|
|
151
|
-
pattern?: string | undefined;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
|
155
|
-
*/
|
|
156
|
-
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
157
|
-
additionalItems?: JSONSchema7Definition | undefined;
|
|
158
|
-
maxItems?: number | undefined;
|
|
159
|
-
minItems?: number | undefined;
|
|
160
|
-
uniqueItems?: boolean | undefined;
|
|
161
|
-
contains?: JSONSchema7Definition | undefined;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
|
165
|
-
*/
|
|
166
|
-
maxProperties?: number | undefined;
|
|
167
|
-
minProperties?: number | undefined;
|
|
168
|
-
required?: string[] | undefined;
|
|
169
|
-
properties?: {
|
|
170
|
-
[key: string]: JSONSchema7Definition;
|
|
171
|
-
} | undefined;
|
|
172
|
-
patternProperties?: {
|
|
173
|
-
[key: string]: JSONSchema7Definition;
|
|
174
|
-
} | undefined;
|
|
175
|
-
additionalProperties?: JSONSchema7Definition | undefined;
|
|
176
|
-
dependencies?: {
|
|
177
|
-
[key: string]: JSONSchema7Definition | string[];
|
|
178
|
-
} | undefined;
|
|
179
|
-
propertyNames?: JSONSchema7Definition | undefined;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
|
183
|
-
*/
|
|
184
|
-
if?: JSONSchema7Definition | undefined;
|
|
185
|
-
then?: JSONSchema7Definition | undefined;
|
|
186
|
-
else?: JSONSchema7Definition | undefined;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
|
190
|
-
*/
|
|
191
|
-
allOf?: JSONSchema7Definition[] | undefined;
|
|
192
|
-
anyOf?: JSONSchema7Definition[] | undefined;
|
|
193
|
-
oneOf?: JSONSchema7Definition[] | undefined;
|
|
194
|
-
not?: JSONSchema7Definition | undefined;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
|
198
|
-
*/
|
|
199
|
-
format?: string | undefined;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
|
203
|
-
*/
|
|
204
|
-
contentMediaType?: string | undefined;
|
|
205
|
-
contentEncoding?: string | undefined;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
|
209
|
-
*/
|
|
210
|
-
definitions?: {
|
|
211
|
-
[key: string]: JSONSchema7Definition;
|
|
212
|
-
} | undefined;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
216
|
-
*/
|
|
217
|
-
title?: string | undefined;
|
|
218
|
-
description?: string | undefined;
|
|
219
|
-
default?: JSONSchema7Type | undefined;
|
|
220
|
-
readOnly?: boolean | undefined;
|
|
221
|
-
writeOnly?: boolean | undefined;
|
|
222
|
-
examples?: JSONSchema7Type | undefined;
|
|
223
|
-
}
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { JSONSchema7 } from 'json-schema';
|
|
224
3
|
|
|
225
4
|
/**
|
|
226
5
|
* Converts a Standard Schema to a JSON schema.
|
package/dist/index.js
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
const getToJsonSchemaFn$4 = async () => (schema) => schema.toJsonSchema();
|
|
2
|
+
|
|
3
|
+
const errorMessageWrapper = (message) => `standard-json: ${message}`;
|
|
4
|
+
const tryImport = async (result, name) => {
|
|
5
|
+
try {
|
|
6
|
+
return await result;
|
|
7
|
+
} catch {
|
|
8
|
+
throw new Error(errorMessageWrapper(`Missing dependencies "${name}".`));
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getToJsonSchemaFn$3 = async () => {
|
|
13
|
+
const { JSONSchema } = await tryImport(import('effect'), "effect");
|
|
14
|
+
return (schema) => JSONSchema.make(schema);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const getToJsonSchemaFn$2 = async () => {
|
|
18
|
+
const { toJsonSchema } = await tryImport(
|
|
19
|
+
import('@valibot/to-json-schema'),
|
|
20
|
+
"@valibot/to-json-schema"
|
|
21
|
+
);
|
|
22
|
+
return (schema, options) => toJsonSchema(
|
|
23
|
+
schema,
|
|
24
|
+
options
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getToJsonSchemaFn$1 = async () => async (schema, options) => {
|
|
29
|
+
let handler;
|
|
30
|
+
if ("_zod" in schema)
|
|
31
|
+
handler = await tryImport(import('zod/v4/core'), "zod v4").then(
|
|
32
|
+
(mod) => mod.toJSONSchema
|
|
33
|
+
);
|
|
34
|
+
else
|
|
35
|
+
handler = await tryImport(import('zod-to-json-schema'), "zod v3").then(
|
|
36
|
+
(mod) => mod.zodToJsonSchema
|
|
37
|
+
);
|
|
38
|
+
return handler(schema, options);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const vendorToFn = {
|
|
42
|
+
arktype: getToJsonSchemaFn$4,
|
|
43
|
+
effect: getToJsonSchemaFn$3,
|
|
44
|
+
valibot: getToJsonSchemaFn$2,
|
|
45
|
+
zod: getToJsonSchemaFn$1
|
|
46
|
+
};
|
|
47
|
+
const getToJsonSchemaFn = async (vendor) => {
|
|
48
|
+
const venderConvertor = vendorToFn[vendor];
|
|
49
|
+
if (!venderConvertor)
|
|
50
|
+
throw new Error(
|
|
51
|
+
errorMessageWrapper(`Unsupported schema vendor "${vendor}"`)
|
|
52
|
+
);
|
|
53
|
+
return venderConvertor();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const toJsonSchema = (schema) => getToJsonSchemaFn(schema["~standard"].vendor).then(
|
|
57
|
+
(toJsonSchema2) => toJsonSchema2(schema)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export { toJsonSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standard-community/standard-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-rc.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -39,30 +39,44 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
42
|
+
"@standard-schema/spec": "^1.0.0",
|
|
43
|
+
"@types/json-schema": "^7.0.15",
|
|
44
|
+
"@valibot/to-json-schema": "^1.3.0",
|
|
45
|
+
"arktype": "^2.1.20",
|
|
46
|
+
"effect": "^3.16.8",
|
|
47
|
+
"valibot": "^1.1.0",
|
|
48
|
+
"zod": "^3.25.67",
|
|
49
|
+
"zod-to-json-schema": "^3.24.5"
|
|
45
50
|
},
|
|
46
51
|
"peerDependenciesMeta": {
|
|
47
52
|
"@valibot/to-json-schema": {
|
|
48
53
|
"optional": true
|
|
49
54
|
},
|
|
55
|
+
"arktype": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
50
58
|
"effect": {
|
|
51
59
|
"optional": true
|
|
52
60
|
},
|
|
61
|
+
"valibot": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"zod": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
53
67
|
"zod-to-json-schema": {
|
|
54
68
|
"optional": true
|
|
55
69
|
}
|
|
56
70
|
},
|
|
57
71
|
"devDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"valibot": "^1.0.0-rc.4",
|
|
63
|
-
"zod": "^3.24.2"
|
|
72
|
+
"@biomejs/biome": "^2.0.4",
|
|
73
|
+
"pkgroll": "^2.13.1",
|
|
74
|
+
"typescript": "^5.8.3",
|
|
75
|
+
"vitest": "^3.2.4"
|
|
64
76
|
},
|
|
65
77
|
"scripts": {
|
|
66
|
-
"build": "pkgroll --
|
|
78
|
+
"build": "pkgroll --clean-dist",
|
|
79
|
+
"format": "biome check --write .",
|
|
80
|
+
"test": "vitest"
|
|
67
81
|
}
|
|
68
82
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var o=(n,s)=>c(n,"name",{value:s,configurable:!0});const e=o(async()=>n=>n.toJsonSchema(),"getToJsonSchemaFn");exports.getToJsonSchemaFn=e;
|
package/dist/arktype-rPtBJvA_.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.defineProperty;var n=(o,c)=>e(o,"name",{value:c,configurable:!0});const s=n(async()=>o=>o.toJsonSchema(),"getToJsonSchemaFn");export{s as getToJsonSchemaFn};
|
package/dist/effect-Bz0yPX2a.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var s=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});var u=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of i(t))!h.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(c=m(t,r))||c.enumerable});return e};var J=(e,t,n)=>(n=e!=null?s(S(e)):{},u(t||!e||!e.__esModule?a(n,"default",{value:e,enumerable:!0}):n,e));var f=require("./index-BiXjOJ4o.cjs");const g=o(async()=>{const{JSONSchema:e}=await f.tryImport(import("effect"),"effect");return t=>e.make(t)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=g;
|
package/dist/effect-lIj12xeO.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var r=Object.defineProperty;var e=(t,o)=>r(t,"name",{value:o,configurable:!0});import{t as a}from"./index-BnLYQduk.js";const m=e(async()=>{const{JSONSchema:t}=await a(import("effect"),"effect");return o=>t.make(o)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
|
package/dist/index-BiXjOJ4o.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var t=Object.defineProperty;var r=(n,e)=>t(n,"name",{value:e,configurable:!0});const s=r(async(n,e)=>{try{return await n}catch{throw new Error(`standard-json: Missing dependencies "${e}".`)}},"tryImport"),o=r(async n=>{switch(n){case"arktype":return Promise.resolve().then(function(){return require("./arktype-Dl6TXwAj.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"effect":return Promise.resolve().then(function(){return require("./effect-Bz0yPX2a.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"valibot":return Promise.resolve().then(function(){return require("./valibot-BJZP6MXN.cjs")}).then(async({getToJsonSchemaFn:e})=>e());case"zod":return Promise.resolve().then(function(){return require("./zod-DDSZCko0.cjs")}).then(async({getToJsonSchemaFn:e})=>e());default:throw new Error(`standard-json: Unsupported schema vendor "${n}"`)}},"getToJsonSchemaFn"),c=r(async n=>o(n["~standard"].vendor).then(async e=>e(n)),"toJsonSchema");exports.toJsonSchema=c,exports.tryImport=s;
|
package/dist/index-BnLYQduk.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var a=Object.defineProperty;var e=(t,n)=>a(t,"name",{value:n,configurable:!0});const s=e(async(t,n)=>{try{return await t}catch{throw new Error(`standard-json: Missing dependencies "${n}".`)}},"tryImport"),r=e(async t=>{switch(t){case"arktype":return import("./arktype-rPtBJvA_.js").then(async({getToJsonSchemaFn:n})=>n());case"effect":return import("./effect-lIj12xeO.js").then(async({getToJsonSchemaFn:n})=>n());case"valibot":return import("./valibot-x7jZH0Fn.js").then(async({getToJsonSchemaFn:n})=>n());case"zod":return import("./zod-UXmI2DWZ.js").then(async({getToJsonSchemaFn:n})=>n());default:throw new Error(`standard-json: Unsupported schema vendor "${t}"`)}},"getToJsonSchemaFn"),o=e(async t=>r(t["~standard"].vendor).then(async n=>n(t)),"toJsonSchema");export{o as a,s as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var c=Object.create;var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var r=(t,o)=>s(t,"name",{value:o,configurable:!0});var J=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of m(o))!u.call(t,n)&&n!==e&&s(t,n,{get:()=>o[n],enumerable:!(a=i(o,n))||a.enumerable});return t};var S=(t,o,e)=>(e=t!=null?c(h(t)):{},J(o||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t));var g=require("./index-BiXjOJ4o.cjs");const p=r(async()=>{const{toJsonSchema:t}=await g.tryImport(import("@valibot/to-json-schema"),"@valibot/to-json-schema");return(o,e)=>t(o,e)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=p;
|
package/dist/valibot-x7jZH0Fn.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var r=Object.defineProperty;var a=(o,t)=>r(o,"name",{value:t,configurable:!0});import{t as s}from"./index-BnLYQduk.js";const m=a(async()=>{const{toJsonSchema:o}=await s(import("@valibot/to-json-schema"),"@valibot/to-json-schema");return(t,n)=>o(t,n)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
|
package/dist/zod-DDSZCko0.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var c=Object.create;var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var a=(o,t)=>s(o,"name",{value:t,configurable:!0});var u=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of i(t))!d.call(o,n)&&n!==e&&s(o,n,{get:()=>t[n],enumerable:!(r=m(t,n))||r.enumerable});return o};var J=(o,t,e)=>(e=o!=null?c(h(o)):{},u(t||!o||!o.__esModule?s(e,"default",{value:o,enumerable:!0}):e,o));var S=require("./index-BiXjOJ4o.cjs");const T=a(async()=>{const{zodToJsonSchema:o}=await S.tryImport(import("zod-to-json-schema"),"zod-to-json-schema");return(t,e)=>o(t,e)},"getToJsonSchemaFn");exports.getToJsonSchemaFn=T;
|
package/dist/zod-UXmI2DWZ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var s=Object.defineProperty;var n=(o,t)=>s(o,"name",{value:t,configurable:!0});import{t as a}from"./index-BnLYQduk.js";const m=n(async()=>{const{zodToJsonSchema:o}=await a(import("zod-to-json-schema"),"zod-to-json-schema");return(t,r)=>o(t,r)},"getToJsonSchemaFn");export{m as getToJsonSchemaFn};
|