xsschema 0.4.0-beta.9 → 0.4.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/dist/{effect-D2vKoLgT.js → effect-Df2gY8Wx.js} +1 -1
- package/dist/{index-Cx_srAfm.js → index-DoHiaFQM.js} +8 -19
- package/dist/index.d.ts +48 -33
- package/dist/index.js +1 -1
- package/dist/{sury-DaaR_vre.js → sury-BoOvxlMw.js} +1 -1
- package/dist/{valibot-iYGh1vpl.js → valibot-_ibN3zSD.js} +1 -1
- package/dist/{zod-D6g6461c.js → zod-DjyNjMBF.js} +1 -1
- package/package.json +8 -8
|
@@ -10,6 +10,8 @@ const strictJsonSchema = (schema) => ({
|
|
|
10
10
|
) : schema.properties
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
const isStandardJSONSchemaV1 = (schema) => "jsonSchema" in schema["~standard"];
|
|
14
|
+
|
|
13
15
|
const missingDependenciesUrl = "https://xsai.js.org/docs/packages-top/xsschema#missing-dependencies";
|
|
14
16
|
const tryImport = async (result, name) => {
|
|
15
17
|
try {
|
|
@@ -23,32 +25,19 @@ const getToJsonSchemaFn = async (vendor) => {
|
|
|
23
25
|
case "arktype":
|
|
24
26
|
return import('./arktype-C-GObzDh.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
25
27
|
case "effect":
|
|
26
|
-
return import('./effect-
|
|
28
|
+
return import('./effect-Df2gY8Wx.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
27
29
|
case "sury":
|
|
28
|
-
return import('./sury-
|
|
30
|
+
return import('./sury-BoOvxlMw.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
29
31
|
case "valibot":
|
|
30
|
-
return import('./valibot-
|
|
32
|
+
return import('./valibot-_ibN3zSD.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
31
33
|
case "zod":
|
|
32
|
-
return import('./zod-
|
|
34
|
+
return import('./zod-DjyNjMBF.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
33
35
|
default:
|
|
34
36
|
throw new Error(`xsschema: Unsupported schema vendor "${vendor}". see https://xsai.js.org/docs/packages-top/xsschema#unsupported-schema-vendor`);
|
|
35
37
|
}
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
const toJsonSchema = async (schema) => getToJsonSchemaFn(schema["~standard"].vendor).then(async (toJsonSchema2) => toJsonSchema2(schema));
|
|
39
|
-
|
|
40
|
-
const ToJsonSchemaVendors = /* @__PURE__ */ new Map();
|
|
41
|
-
const initToJsonSchemaSyncVendor = async (vendor) => getToJsonSchemaFn(vendor).then((fn) => ToJsonSchemaVendors.set(vendor, fn));
|
|
42
|
-
const toJsonSchemaSync = (schema) => {
|
|
43
|
-
const { vendor } = schema["~standard"];
|
|
44
|
-
const toJsonSchema = ToJsonSchemaVendors.get(vendor);
|
|
45
|
-
if (!toJsonSchema)
|
|
46
|
-
throw new Error(`xsschema: Unregistered or unsupported schema vendor "${vendor}". Make sure to register the vendor using "await initToJsonSchemaSyncVendor('${vendor}')" before calling toJsonSchemaSync.`);
|
|
47
|
-
const result = toJsonSchema(schema);
|
|
48
|
-
if (result instanceof Promise)
|
|
49
|
-
throw new Error("xsschema: Function returns a Promise. you need to use toJsonSchema instead of toJsonSchemaSync.");
|
|
50
|
-
return result;
|
|
51
|
-
};
|
|
40
|
+
const toJsonSchema = async (schema) => isStandardJSONSchemaV1(schema) ? schema["~standard"].jsonSchema.input({ target: "draft-07" }) : getToJsonSchemaFn(schema["~standard"].vendor).then(async (toJsonSchema2) => toJsonSchema2(schema));
|
|
52
41
|
|
|
53
42
|
const validate = async (schema, input) => {
|
|
54
43
|
let result = schema["~standard"].validate(input);
|
|
@@ -59,4 +48,4 @@ const validate = async (schema, input) => {
|
|
|
59
48
|
return result.value;
|
|
60
49
|
};
|
|
61
50
|
|
|
62
|
-
export { toJsonSchema as a,
|
|
51
|
+
export { toJsonSchema as a, jsonSchema as j, missingDependenciesUrl as m, strictJsonSchema as s, tryImport as t, validate as v };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
2
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
3
|
+
/** The Standard properties. */
|
|
4
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
5
|
+
}
|
|
6
|
+
declare namespace StandardTypedV1 {
|
|
7
|
+
/** The Standard Typed properties interface. */
|
|
8
|
+
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
|
+
/** Inferred types associated with the schema. */
|
|
14
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** The Standard Typed types interface. */
|
|
17
|
+
interface Types<Input = unknown, Output = Input> {
|
|
18
|
+
/** The input type of the schema. */
|
|
19
|
+
readonly input: Input;
|
|
20
|
+
/** The output type of the schema. */
|
|
21
|
+
readonly output: Output;
|
|
22
|
+
}
|
|
23
|
+
/** Infers the input type of a Standard Typed. */
|
|
24
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
25
|
+
/** Infers the output type of a Standard Typed. */
|
|
26
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
27
|
+
}
|
|
1
28
|
/** The Standard Schema interface. */
|
|
2
29
|
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
30
|
/** The Standard Schema properties. */
|
|
@@ -5,54 +32,47 @@ interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
|
5
32
|
}
|
|
6
33
|
declare namespace StandardSchemaV1 {
|
|
7
34
|
/** The Standard Schema properties interface. */
|
|
8
|
-
|
|
9
|
-
/** The version number of the standard. */
|
|
10
|
-
readonly version: 1;
|
|
11
|
-
/** The vendor name of the schema library. */
|
|
12
|
-
readonly vendor: string;
|
|
35
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
13
36
|
/** 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;
|
|
37
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
17
38
|
}
|
|
18
39
|
/** The result interface of the validate function. */
|
|
19
|
-
|
|
40
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
41
|
/** The result interface if validation succeeds. */
|
|
21
|
-
|
|
42
|
+
interface SuccessResult<Output> {
|
|
22
43
|
/** The typed output value. */
|
|
23
44
|
readonly value: Output;
|
|
24
|
-
/**
|
|
45
|
+
/** A falsy value for `issues` indicates success. */
|
|
25
46
|
readonly issues?: undefined;
|
|
26
47
|
}
|
|
48
|
+
interface Options {
|
|
49
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
50
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
51
|
+
}
|
|
27
52
|
/** The result interface if validation fails. */
|
|
28
|
-
|
|
53
|
+
interface FailureResult {
|
|
29
54
|
/** The issues of failed validation. */
|
|
30
55
|
readonly issues: ReadonlyArray<Issue>;
|
|
31
56
|
}
|
|
32
57
|
/** The issue interface of the failure output. */
|
|
33
|
-
|
|
58
|
+
interface Issue {
|
|
34
59
|
/** The error message of the issue. */
|
|
35
60
|
readonly message: string;
|
|
36
61
|
/** The path of the issue, if any. */
|
|
37
62
|
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
38
63
|
}
|
|
39
64
|
/** The path segment interface of the issue. */
|
|
40
|
-
|
|
65
|
+
interface PathSegment {
|
|
41
66
|
/** The key representing a path segment. */
|
|
42
67
|
readonly key: PropertyKey;
|
|
43
68
|
}
|
|
44
|
-
/** The Standard
|
|
45
|
-
|
|
46
|
-
/** The input type of the schema. */
|
|
47
|
-
readonly input: Input;
|
|
48
|
-
/** The output type of the schema. */
|
|
49
|
-
readonly output: Output;
|
|
69
|
+
/** The Standard types interface. */
|
|
70
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
50
71
|
}
|
|
51
|
-
/** Infers the input type of a Standard
|
|
52
|
-
|
|
53
|
-
/** Infers the output type of a Standard
|
|
54
|
-
|
|
55
|
-
export { };
|
|
72
|
+
/** Infers the input type of a Standard. */
|
|
73
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
74
|
+
/** Infers the output type of a Standard. */
|
|
75
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
56
76
|
}
|
|
57
77
|
|
|
58
78
|
// ==================================================================================================
|
|
@@ -222,7 +242,9 @@ interface JSONSchema7 {
|
|
|
222
242
|
examples?: JSONSchema7Type | undefined;
|
|
223
243
|
}
|
|
224
244
|
|
|
245
|
+
/** @deprecated - use `Schema.InferOutput` instead. */
|
|
225
246
|
type Infer<T extends StandardSchemaV1> = StandardSchemaV1.InferOutput<T>;
|
|
247
|
+
/** @deprecated - use `Schema.InferInput` instead. */
|
|
226
248
|
type InferIn<T extends StandardSchemaV1> = StandardSchemaV1.InferInput<T>;
|
|
227
249
|
|
|
228
250
|
declare const jsonSchema: (schema: JSONSchema7) => JSONSchema7;
|
|
@@ -235,15 +257,8 @@ declare const strictJsonSchema: (schema: JSONSchema7) => JSONSchema7;
|
|
|
235
257
|
*/
|
|
236
258
|
declare const toJsonSchema: (schema: StandardSchemaV1) => Promise<JSONSchema7>;
|
|
237
259
|
|
|
238
|
-
type ToJsonSchemaFn = (schema: unknown) => JSONSchema7 | Promise<JSONSchema7>;
|
|
239
|
-
|
|
240
|
-
/** @experimental */
|
|
241
|
-
declare const initToJsonSchemaSyncVendor: (vendor: string) => Promise<Map<string, ToJsonSchemaFn>>;
|
|
242
|
-
/** @experimental */
|
|
243
|
-
declare const toJsonSchemaSync: (schema: StandardSchemaV1) => JSONSchema7;
|
|
244
|
-
|
|
245
260
|
/** @see {@link https://github.com/standard-schema/standard-schema#how-do-i-accept-standard-schemas-in-my-library} */
|
|
246
261
|
declare const validate: <T extends StandardSchemaV1>(schema: T, input: StandardSchemaV1.InferInput<T>) => Promise<StandardSchemaV1.InferOutput<T>>;
|
|
247
262
|
|
|
248
|
-
export { StandardSchemaV1 as Schema,
|
|
263
|
+
export { StandardSchemaV1 as Schema, jsonSchema, strictJsonSchema, toJsonSchema, validate };
|
|
249
264
|
export type { Infer, InferIn, JSONSchema7 as JsonSchema };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { j as jsonSchema, s as strictJsonSchema, a as toJsonSchema, v as validate } from './index-DoHiaFQM.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xsschema",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.0
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "extra-small, Standard Schema-based alternative to typeschema.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"effect": "^3.16.0",
|
|
37
37
|
"sury": "^10.0.0",
|
|
38
38
|
"zod": "^3.25.0 || ^4.0.0",
|
|
39
|
-
"zod-to-json-schema": "^3.
|
|
39
|
+
"zod-to-json-schema": "^3.25.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@valibot/to-json-schema": {
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@standard-schema/spec": "^1.
|
|
62
|
+
"@standard-schema/spec": "^1.1.0",
|
|
63
63
|
"@types/json-schema": "^7.0.15",
|
|
64
64
|
"@valibot/to-json-schema": "^1.0.0",
|
|
65
|
-
"arktype": "^2.1.
|
|
66
|
-
"effect": "^3.
|
|
67
|
-
"sury": "^
|
|
65
|
+
"arktype": "^2.1.29",
|
|
66
|
+
"effect": "^3.19.13",
|
|
67
|
+
"sury": "^11.0.0-alpha.4",
|
|
68
68
|
"valibot": "^1.0.0",
|
|
69
|
-
"zod": "^
|
|
70
|
-
"zod-to-json-schema": "^3.
|
|
69
|
+
"zod": "^4.2.1",
|
|
70
|
+
"zod-to-json-schema": "^3.25.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "pkgroll",
|