xsschema 0.2.0-beta.1 → 0.2.0-beta.2
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/arktype-C-GObzDh.js +3 -0
- package/dist/effect-CE0Pj37O.js +8 -0
- package/dist/index-DtiOmYCK.js +47 -0
- package/dist/index.js +1 -36
- package/dist/valibot-C0gMwA8F.js +8 -0
- package/dist/zod-DvRxrLZA.js +8 -0
- package/package.json +8 -8
- package/dist/arktype-YFDDSIC4.js +0 -5
- package/dist/chunk-ZNYPDRYE.js +0 -27
- package/dist/effect-EMJALC2C.js +0 -12
- package/dist/valibot-LSZESPGJ.js +0 -12
- package/dist/zod-ARMX3IJ3.js +0 -12
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const tryImport = async (result, name) => {
|
|
2
|
+
try {
|
|
3
|
+
return await result;
|
|
4
|
+
} catch {
|
|
5
|
+
throw new Error(`xsschema: Missing dependencies "${name}".`);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
const getToJsonSchemaFn = async (vendor) => {
|
|
9
|
+
switch (vendor) {
|
|
10
|
+
case "arktype":
|
|
11
|
+
return import('./arktype-C-GObzDh.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
12
|
+
case "effect":
|
|
13
|
+
return import('./effect-CE0Pj37O.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
14
|
+
case "valibot":
|
|
15
|
+
return import('./valibot-C0gMwA8F.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
16
|
+
case "zod":
|
|
17
|
+
return import('./zod-DvRxrLZA.js').then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`xsschema: Unsupported schema vendor "${vendor}"`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const toJsonSchema = async (schema) => getToJsonSchemaFn(schema["~standard"].vendor).then(async (toJsonSchema2) => toJsonSchema2(schema));
|
|
24
|
+
|
|
25
|
+
const ToJsonSchemaVendors = /* @__PURE__ */ new Map();
|
|
26
|
+
const initToJsonSchemaSyncVendor = async (vendor) => getToJsonSchemaFn(vendor).then((fn) => ToJsonSchemaVendors.set(vendor, fn));
|
|
27
|
+
const toJsonSchemaSync = (schema) => {
|
|
28
|
+
const { vendor } = schema["~standard"];
|
|
29
|
+
const toJsonSchema = ToJsonSchemaVendors.get(vendor);
|
|
30
|
+
if (!toJsonSchema)
|
|
31
|
+
throw new Error(`xsschema: Unregistered or unsupported schema vendor "${vendor}". Make sure to register the vendor using "await initToJsonSchemaSyncVendor('${vendor}')" before calling toJsonSchemaSync.`);
|
|
32
|
+
const result = toJsonSchema(schema);
|
|
33
|
+
if (result instanceof Promise)
|
|
34
|
+
throw new Error("xsschema: Function returns a Promise. you need to use toJsonSchema instead of toJsonSchemaSync.");
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const validate = async (schema, input) => {
|
|
39
|
+
let result = schema["~standard"].validate(input);
|
|
40
|
+
if (result instanceof Promise)
|
|
41
|
+
result = await result;
|
|
42
|
+
if (result.issues)
|
|
43
|
+
throw new Error(JSON.stringify(result.issues, null, 2));
|
|
44
|
+
return result.value;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { toJsonSchema as a, toJsonSchemaSync as b, initToJsonSchemaSyncVendor as i, tryImport as t, validate as v };
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
getToJsonSchemaFn
|
|
3
|
-
} from "./chunk-ZNYPDRYE.js";
|
|
4
|
-
|
|
5
|
-
// src/to-json-schema/async.ts
|
|
6
|
-
var toJsonSchema = async (schema) => getToJsonSchemaFn(schema["~standard"].vendor).then(async (toJsonSchema2) => toJsonSchema2(schema));
|
|
7
|
-
|
|
8
|
-
// src/to-json-schema/sync.ts
|
|
9
|
-
var ToJsonSchemaVendors = /* @__PURE__ */ new Map();
|
|
10
|
-
var initToJsonSchemaSyncVendor = async (vendor) => getToJsonSchemaFn(vendor).then((fn) => ToJsonSchemaVendors.set(vendor, fn));
|
|
11
|
-
var toJsonSchemaSync = (schema) => {
|
|
12
|
-
const { vendor } = schema["~standard"];
|
|
13
|
-
const toJsonSchema2 = ToJsonSchemaVendors.get(vendor);
|
|
14
|
-
if (!toJsonSchema2)
|
|
15
|
-
throw new Error(`xsschema: Unregistered or unsupported schema vendor "${vendor}". Make sure to register the vendor using "await initToJsonSchemaSyncVendor('${vendor}')" before calling toJsonSchemaSync.`);
|
|
16
|
-
const result = toJsonSchema2(schema);
|
|
17
|
-
if (result instanceof Promise)
|
|
18
|
-
throw new Error("xsschema: Function returns a Promise. you need to use toJsonSchema instead of toJsonSchemaSync.");
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/validate.ts
|
|
23
|
-
var validate = async (schema, input) => {
|
|
24
|
-
let result = schema["~standard"].validate(input);
|
|
25
|
-
if (result instanceof Promise)
|
|
26
|
-
result = await result;
|
|
27
|
-
if (result.issues)
|
|
28
|
-
throw new Error(JSON.stringify(result.issues, null, 2));
|
|
29
|
-
return result.value;
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
initToJsonSchemaSyncVendor,
|
|
33
|
-
toJsonSchema,
|
|
34
|
-
toJsonSchemaSync,
|
|
35
|
-
validate
|
|
36
|
-
};
|
|
1
|
+
export { i as initToJsonSchemaSyncVendor, a as toJsonSchema, b as toJsonSchemaSync, v as validate } from './index-DtiOmYCK.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as tryImport } from './index-DtiOmYCK.js';
|
|
2
|
+
|
|
3
|
+
const getToJsonSchemaFn = async () => {
|
|
4
|
+
const { toJsonSchema } = await tryImport(import('@valibot/to-json-schema'), "@valibot/to-json-schema");
|
|
5
|
+
return (schema) => toJsonSchema(schema);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { getToJsonSchemaFn };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as tryImport } from './index-DtiOmYCK.js';
|
|
2
|
+
|
|
3
|
+
const getToJsonSchemaFn = async () => {
|
|
4
|
+
const { zodToJsonSchema } = await tryImport(import('zod-to-json-schema'), "zod-to-json-schema");
|
|
5
|
+
return (schema) => zodToJsonSchema(schema);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { getToJsonSchemaFn };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xsschema",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.0-beta.
|
|
4
|
+
"version": "0.2.0-beta.2",
|
|
5
5
|
"description": "extra-small, Standard Schema-based alternative to typeschema.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
],
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@valibot/to-json-schema": "^1.0.0",
|
|
35
|
-
"arktype": "^2.1.
|
|
36
|
-
"effect": "^3.14.
|
|
37
|
-
"zod-to-json-schema": "^3.24.
|
|
35
|
+
"arktype": "^2.1.13",
|
|
36
|
+
"effect": "^3.14.2",
|
|
37
|
+
"zod-to-json-schema": "^3.24.5"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@valibot/to-json-schema": {
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"@standard-schema/spec": "^1.0.0",
|
|
55
55
|
"@types/json-schema": "^7.0.15",
|
|
56
56
|
"@valibot/to-json-schema": "^1.0.0",
|
|
57
|
-
"arktype": "^2.1.
|
|
58
|
-
"effect": "^3.14.
|
|
57
|
+
"arktype": "^2.1.13",
|
|
58
|
+
"effect": "^3.14.2",
|
|
59
59
|
"valibot": "^1.0.0",
|
|
60
60
|
"zod": "^3.24.2",
|
|
61
|
-
"zod-to-json-schema": "^3.24.
|
|
61
|
+
"zod-to-json-schema": "^3.24.5"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
|
-
"build": "
|
|
64
|
+
"build": "pkgroll",
|
|
65
65
|
"test": "vitest run",
|
|
66
66
|
"test:watch": "vitest"
|
|
67
67
|
},
|
package/dist/arktype-YFDDSIC4.js
DELETED
package/dist/chunk-ZNYPDRYE.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/to-json-schema/vendors/index.ts
|
|
2
|
-
var tryImport = async (result, name) => {
|
|
3
|
-
try {
|
|
4
|
-
return await result;
|
|
5
|
-
} catch {
|
|
6
|
-
throw new Error(`xsschema: Missing dependencies "${name}".`);
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
var getToJsonSchemaFn = async (vendor) => {
|
|
10
|
-
switch (vendor) {
|
|
11
|
-
case "arktype":
|
|
12
|
-
return import("./arktype-YFDDSIC4.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
13
|
-
case "effect":
|
|
14
|
-
return import("./effect-EMJALC2C.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
15
|
-
case "valibot":
|
|
16
|
-
return import("./valibot-LSZESPGJ.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
17
|
-
case "zod":
|
|
18
|
-
return import("./zod-ARMX3IJ3.js").then(async ({ getToJsonSchemaFn: getToJsonSchemaFn2 }) => getToJsonSchemaFn2());
|
|
19
|
-
default:
|
|
20
|
-
throw new Error(`xsschema: Unsupported schema vendor "${vendor}"`);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
tryImport,
|
|
26
|
-
getToJsonSchemaFn
|
|
27
|
-
};
|
package/dist/effect-EMJALC2C.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tryImport
|
|
3
|
-
} from "./chunk-ZNYPDRYE.js";
|
|
4
|
-
|
|
5
|
-
// src/to-json-schema/vendors/effect.ts
|
|
6
|
-
var getToJsonSchemaFn = async () => {
|
|
7
|
-
const { JSONSchema } = await tryImport(import("effect"), "effect");
|
|
8
|
-
return (schema) => JSONSchema.make(schema);
|
|
9
|
-
};
|
|
10
|
-
export {
|
|
11
|
-
getToJsonSchemaFn
|
|
12
|
-
};
|
package/dist/valibot-LSZESPGJ.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tryImport
|
|
3
|
-
} from "./chunk-ZNYPDRYE.js";
|
|
4
|
-
|
|
5
|
-
// src/to-json-schema/vendors/valibot.ts
|
|
6
|
-
var getToJsonSchemaFn = async () => {
|
|
7
|
-
const { toJsonSchema } = await tryImport(import("@valibot/to-json-schema"), "@valibot/to-json-schema");
|
|
8
|
-
return (schema) => toJsonSchema(schema);
|
|
9
|
-
};
|
|
10
|
-
export {
|
|
11
|
-
getToJsonSchemaFn
|
|
12
|
-
};
|
package/dist/zod-ARMX3IJ3.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tryImport
|
|
3
|
-
} from "./chunk-ZNYPDRYE.js";
|
|
4
|
-
|
|
5
|
-
// src/to-json-schema/vendors/zod.ts
|
|
6
|
-
var getToJsonSchemaFn = async () => {
|
|
7
|
-
const { zodToJsonSchema } = await tryImport(import("zod-to-json-schema"), "zod-to-json-schema");
|
|
8
|
-
return (schema) => zodToJsonSchema(schema);
|
|
9
|
-
};
|
|
10
|
-
export {
|
|
11
|
-
getToJsonSchemaFn
|
|
12
|
-
};
|