@powerlines/schema 0.8.67 → 0.9.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 +36 -22
- package/dist/bundle.d.cts +2 -2
- package/dist/bundle.d.cts.map +1 -1
- package/dist/bundle.d.mts +2 -2
- package/dist/bundle.d.mts.map +1 -1
- package/dist/bundle.mjs.map +1 -1
- package/dist/extract.cjs +200 -51
- package/dist/extract.d.cts +82 -16
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +82 -16
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +198 -54
- package/dist/extract.mjs.map +1 -1
- package/dist/index.cjs +13 -2
- package/dist/index.d.cts +5 -4
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +4 -3
- package/dist/jtd.cjs +362 -0
- package/dist/jtd.d.cts +16 -0
- package/dist/jtd.d.cts.map +1 -0
- package/dist/jtd.d.mts +16 -0
- package/dist/jtd.d.mts.map +1 -0
- package/dist/jtd.mjs +361 -0
- package/dist/jtd.mjs.map +1 -0
- package/dist/reflection.cjs +229 -108
- package/dist/reflection.d.cts +17 -7
- package/dist/reflection.d.cts.map +1 -1
- package/dist/reflection.d.mts +17 -7
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +229 -108
- package/dist/reflection.mjs.map +1 -1
- package/dist/resolve.d.cts +5 -5
- package/dist/resolve.d.cts.map +1 -1
- package/dist/resolve.d.mts +5 -5
- package/dist/resolve.d.mts.map +1 -1
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +76 -0
- package/dist/type-checks.d.cts +43 -0
- package/dist/type-checks.d.cts.map +1 -0
- package/dist/type-checks.d.mts +43 -0
- package/dist/type-checks.d.mts.map +1 -0
- package/dist/type-checks.mjs +71 -0
- package/dist/type-checks.mjs.map +1 -0
- package/dist/types.d.cts +80 -24
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +80 -24
- package/dist/types.d.mts.map +1 -1
- package/package.json +21 -19
- package/dist/is-schema-definition.cjs +0 -18
- package/dist/is-schema-definition.d.cts +0 -13
- package/dist/is-schema-definition.d.cts.map +0 -1
- package/dist/is-schema-definition.d.mts +0 -13
- package/dist/is-schema-definition.d.mts.map +0 -1
- package/dist/is-schema-definition.mjs +0 -17
- package/dist/is-schema-definition.mjs.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _stryke_type_checks = require("@stryke/type-checks");
|
|
4
|
+
let _stryke_json_schema = require("@stryke/json/schema");
|
|
5
|
+
|
|
6
|
+
//#region src/type-checks.ts
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
|
|
9
|
+
*
|
|
10
|
+
* @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
|
|
11
|
+
* @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
|
|
12
|
+
*/
|
|
13
|
+
function isJTDSchema(input) {
|
|
14
|
+
return (0, _stryke_json_schema.isJsonSchemaObjectType)(input) && "jtd" in input && input.jtd === true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
|
|
18
|
+
*
|
|
19
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
|
|
20
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
|
|
21
|
+
*/
|
|
22
|
+
function isUntypedSchema(input) {
|
|
23
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
24
|
+
const schema = input;
|
|
25
|
+
if ("id" in schema && !(0, _stryke_type_checks.isSetString)(schema.id)) return false;
|
|
26
|
+
if ("title" in schema && !(0, _stryke_type_checks.isSetString)(schema.title)) return false;
|
|
27
|
+
if ("description" in schema && !(0, _stryke_type_checks.isSetString)(schema.description)) return false;
|
|
28
|
+
if ("$schema" in schema && !(0, _stryke_type_checks.isSetString)(schema.$schema)) return false;
|
|
29
|
+
if ("tsType" in schema && !(0, _stryke_type_checks.isSetString)(schema.tsType)) return false;
|
|
30
|
+
if ("markdownType" in schema && !(0, _stryke_type_checks.isSetString)(schema.markdownType)) return false;
|
|
31
|
+
if ("type" in schema && !(0, _stryke_type_checks.isSetString)(schema.type) && !Array.isArray(schema.type)) return false;
|
|
32
|
+
if ("required" in schema && !Array.isArray(schema.required)) return false;
|
|
33
|
+
if ("tags" in schema && !Array.isArray(schema.tags)) return false;
|
|
34
|
+
if ("args" in schema && !Array.isArray(schema.args)) return false;
|
|
35
|
+
if ("properties" in schema && !(0, _stryke_type_checks.isSetObject)(schema.properties)) return false;
|
|
36
|
+
if ("resolve" in schema && !(0, _stryke_type_checks.isFunction)(schema.resolve)) return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.
|
|
41
|
+
*
|
|
42
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
|
|
43
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
|
|
44
|
+
*/
|
|
45
|
+
function isUntypedInput(input) {
|
|
46
|
+
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
47
|
+
const inputObject = input;
|
|
48
|
+
if ("$schema" in inputObject && !isUntypedSchema(inputObject.$schema)) return false;
|
|
49
|
+
if ("$resolve" in inputObject && !(0, _stryke_type_checks.isFunction)(inputObject.$resolve)) return false;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.
|
|
54
|
+
*
|
|
55
|
+
* @param input - The input to check for being a {@link Schema}.
|
|
56
|
+
* @returns `true` if the input is a {@link Schema}, otherwise `false`.
|
|
57
|
+
*/
|
|
58
|
+
function isSchema(input) {
|
|
59
|
+
return (0, _stryke_type_checks.isSetObject)(input) && "schema" in input && isJTDSchema(input.schema) && "input" in input && (0, _stryke_type_checks.isSetObject)(input.input) && "variant" in input && (0, _stryke_type_checks.isSetString)(input.variant);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.
|
|
63
|
+
*
|
|
64
|
+
* @param input - The input to check for being a {@link ExtractedSchema}.
|
|
65
|
+
* @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
|
|
66
|
+
*/
|
|
67
|
+
function isExtractedSchema(input) {
|
|
68
|
+
return isSchema(input) && "source" in input && (0, _stryke_type_checks.isSetObject)(input.source) && "schema" in input.source && isJTDSchema(input.source.schema) && "variant" in input.source && (0, _stryke_type_checks.isSetString)(input.source.variant);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
exports.isExtractedSchema = isExtractedSchema;
|
|
73
|
+
exports.isJTDSchema = isJTDSchema;
|
|
74
|
+
exports.isSchema = isSchema;
|
|
75
|
+
exports.isUntypedInput = isUntypedInput;
|
|
76
|
+
exports.isUntypedSchema = isUntypedSchema;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ExtractedSchema, Schema as Schema$1 } from "./types.cjs";
|
|
2
|
+
import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
|
|
3
|
+
import { InputObject, Schema } from "untyped";
|
|
4
|
+
|
|
5
|
+
//#region src/type-checks.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
|
|
8
|
+
*
|
|
9
|
+
* @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
|
|
10
|
+
* @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
|
|
11
|
+
*/
|
|
12
|
+
declare function isJTDSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>>(input: unknown): input is JTDSchemaType<T, D>;
|
|
13
|
+
/**
|
|
14
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
|
|
17
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
|
|
18
|
+
*/
|
|
19
|
+
declare function isUntypedSchema(input: unknown): input is Schema;
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.
|
|
22
|
+
*
|
|
23
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
|
|
24
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
|
|
25
|
+
*/
|
|
26
|
+
declare function isUntypedInput(input: unknown): input is InputObject;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.
|
|
29
|
+
*
|
|
30
|
+
* @param input - The input to check for being a {@link Schema}.
|
|
31
|
+
* @returns `true` if the input is a {@link Schema}, otherwise `false`.
|
|
32
|
+
*/
|
|
33
|
+
declare function isSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>>(input: unknown): input is Schema$1<T, D>;
|
|
34
|
+
/**
|
|
35
|
+
* Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.
|
|
36
|
+
*
|
|
37
|
+
* @param input - The input to check for being a {@link ExtractedSchema}.
|
|
38
|
+
* @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
|
|
39
|
+
*/
|
|
40
|
+
declare function isExtractedSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>>(input: unknown): input is ExtractedSchema<T, D>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
|
|
43
|
+
//# sourceMappingURL=type-checks.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,wBAEJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,KAAA,YAAiB,KAAA,IAAS,aAAA,CAAc,CAAA,EAAG,CAAA;;;;;;;iBAU7B,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;AAxDzD;;;;iBA8EgB,QAAA,wBAEJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,KAAA,YAAiB,KAAA,IAAS,QAAA,CAAO,CAAA,EAAG,CAAA;;;;;AAzBtC;;iBA2CgB,iBAAA,wBAEJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,CAAA,EAAG,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ExtractedSchema, Schema as Schema$1 } from "./types.mjs";
|
|
2
|
+
import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
|
|
3
|
+
import { InputObject, Schema } from "untyped";
|
|
4
|
+
|
|
5
|
+
//#region src/type-checks.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
|
|
8
|
+
*
|
|
9
|
+
* @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
|
|
10
|
+
* @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
|
|
11
|
+
*/
|
|
12
|
+
declare function isJTDSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>>(input: unknown): input is JTDSchemaType<T, D>;
|
|
13
|
+
/**
|
|
14
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
|
|
17
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
|
|
18
|
+
*/
|
|
19
|
+
declare function isUntypedSchema(input: unknown): input is Schema;
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.
|
|
22
|
+
*
|
|
23
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
|
|
24
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
|
|
25
|
+
*/
|
|
26
|
+
declare function isUntypedInput(input: unknown): input is InputObject;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.
|
|
29
|
+
*
|
|
30
|
+
* @param input - The input to check for being a {@link Schema}.
|
|
31
|
+
* @returns `true` if the input is a {@link Schema}, otherwise `false`.
|
|
32
|
+
*/
|
|
33
|
+
declare function isSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>>(input: unknown): input is Schema$1<T, D>;
|
|
34
|
+
/**
|
|
35
|
+
* Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.
|
|
36
|
+
*
|
|
37
|
+
* @param input - The input to check for being a {@link ExtractedSchema}.
|
|
38
|
+
* @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
|
|
39
|
+
*/
|
|
40
|
+
declare function isExtractedSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>>(input: unknown): input is ExtractedSchema<T, D>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
|
|
43
|
+
//# sourceMappingURL=type-checks.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,wBAEJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,KAAA,YAAiB,KAAA,IAAS,aAAA,CAAc,CAAA,EAAG,CAAA;;;;;;;iBAU7B,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;AAxDzD;;;;iBA8EgB,QAAA,wBAEJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,KAAA,YAAiB,KAAA,IAAS,QAAA,CAAO,CAAA,EAAG,CAAA;;;;;AAzBtC;;iBA2CgB,iBAAA,wBAEJ,MAAA,oBAA0B,MAAA,kBAAA,CACpC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,CAAA,EAAG,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isFunction, isSetObject, isSetString } from "@stryke/type-checks";
|
|
2
|
+
import { isJsonSchemaObjectType } from "@stryke/json/schema";
|
|
3
|
+
|
|
4
|
+
//#region src/type-checks.ts
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
|
|
7
|
+
*
|
|
8
|
+
* @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
|
|
9
|
+
* @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
|
|
10
|
+
*/
|
|
11
|
+
function isJTDSchema(input) {
|
|
12
|
+
return isJsonSchemaObjectType(input) && "jtd" in input && input.jtd === true;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
|
|
16
|
+
*
|
|
17
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
|
|
18
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
|
|
19
|
+
*/
|
|
20
|
+
function isUntypedSchema(input) {
|
|
21
|
+
if (!isSetObject(input)) return false;
|
|
22
|
+
const schema = input;
|
|
23
|
+
if ("id" in schema && !isSetString(schema.id)) return false;
|
|
24
|
+
if ("title" in schema && !isSetString(schema.title)) return false;
|
|
25
|
+
if ("description" in schema && !isSetString(schema.description)) return false;
|
|
26
|
+
if ("$schema" in schema && !isSetString(schema.$schema)) return false;
|
|
27
|
+
if ("tsType" in schema && !isSetString(schema.tsType)) return false;
|
|
28
|
+
if ("markdownType" in schema && !isSetString(schema.markdownType)) return false;
|
|
29
|
+
if ("type" in schema && !isSetString(schema.type) && !Array.isArray(schema.type)) return false;
|
|
30
|
+
if ("required" in schema && !Array.isArray(schema.required)) return false;
|
|
31
|
+
if ("tags" in schema && !Array.isArray(schema.tags)) return false;
|
|
32
|
+
if ("args" in schema && !Array.isArray(schema.args)) return false;
|
|
33
|
+
if ("properties" in schema && !isSetObject(schema.properties)) return false;
|
|
34
|
+
if ("resolve" in schema && !isFunction(schema.resolve)) return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.
|
|
39
|
+
*
|
|
40
|
+
* @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
|
|
41
|
+
* @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
|
|
42
|
+
*/
|
|
43
|
+
function isUntypedInput(input) {
|
|
44
|
+
if (!isSetObject(input)) return false;
|
|
45
|
+
const inputObject = input;
|
|
46
|
+
if ("$schema" in inputObject && !isUntypedSchema(inputObject.$schema)) return false;
|
|
47
|
+
if ("$resolve" in inputObject && !isFunction(inputObject.$resolve)) return false;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.
|
|
52
|
+
*
|
|
53
|
+
* @param input - The input to check for being a {@link Schema}.
|
|
54
|
+
* @returns `true` if the input is a {@link Schema}, otherwise `false`.
|
|
55
|
+
*/
|
|
56
|
+
function isSchema(input) {
|
|
57
|
+
return isSetObject(input) && "schema" in input && isJTDSchema(input.schema) && "input" in input && isSetObject(input.input) && "variant" in input && isSetString(input.variant);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.
|
|
61
|
+
*
|
|
62
|
+
* @param input - The input to check for being a {@link ExtractedSchema}.
|
|
63
|
+
* @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
|
|
64
|
+
*/
|
|
65
|
+
function isExtractedSchema(input) {
|
|
66
|
+
return isSchema(input) && "source" in input && isSetObject(input.source) && "schema" in input.source && isJTDSchema(input.source.schema) && "variant" in input.source && isSetString(input.source.variant);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
|
|
71
|
+
//# sourceMappingURL=type-checks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isJsonSchemaObjectType } from \"@stryke/json/schema\";\nimport { isFunction, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport { JTDSchemaType } from \"ajv/dist/types/jtd-schema\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport { ExtractedSchema, Schema } from \"./types\";\n\n/**\n * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).\n * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.\n */\nexport function isJTDSchema<\n T = unknown,\n D extends Record<string, unknown> = Record<string, unknown>\n>(input: unknown): input is JTDSchemaType<T, D> {\n return isJsonSchemaObjectType(input) && \"jtd\" in input && input.jtd === true;\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link Schema}.\n * @returns `true` if the input is a {@link Schema}, otherwise `false`.\n */\nexport function isSchema<\n T = unknown,\n D extends Record<string, unknown> = Record<string, unknown>\n>(input: unknown): input is Schema<T, D> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJTDSchema(input.schema) &&\n \"input\" in input &&\n isSetObject(input.input) &&\n \"variant\" in input &&\n isSetString(input.variant)\n );\n}\n\n/**\n * Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ExtractedSchema}.\n * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.\n */\nexport function isExtractedSchema<\n T = unknown,\n D extends Record<string, unknown> = Record<string, unknown>\n>(input: unknown): input is ExtractedSchema<T, D> {\n return (\n isSchema<T, D>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n isJTDSchema(input.source.schema) &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n"],"mappings":";;;;;;;;;;AAiCA,SAAgB,YAGd,OAA8C;AAC9C,QAAO,uBAAuB,MAAM,IAAI,SAAS,SAAS,MAAM,QAAQ;;;;;;;;AAS1E,SAAgB,gBAAgB,OAAwC;AACtE,KAAI,CAAC,YAAY,MAAM,CACrB,QAAO;CAGT,MAAM,SAAS;AACf,KAAI,QAAQ,UAAU,CAAC,YAAY,OAAO,GAAG,CAC3C,QAAO;AAET,KAAI,WAAW,UAAU,CAAC,YAAY,OAAO,MAAM,CACjD,QAAO;AAET,KAAI,iBAAiB,UAAU,CAAC,YAAY,OAAO,YAAY,CAC7D,QAAO;AAET,KAAI,aAAa,UAAU,CAAC,YAAY,OAAO,QAAQ,CACrD,QAAO;AAET,KAAI,YAAY,UAAU,CAAC,YAAY,OAAO,OAAO,CACnD,QAAO;AAET,KAAI,kBAAkB,UAAU,CAAC,YAAY,OAAO,aAAa,CAC/D,QAAO;AAET,KACE,UAAU,UACV,CAAC,YAAY,OAAO,KAAK,IACzB,CAAC,MAAM,QAAQ,OAAO,KAAK,CAE3B,QAAO;AAET,KAAI,cAAc,UAAU,CAAC,MAAM,QAAQ,OAAO,SAAS,CACzD,QAAO;AAET,KAAI,UAAU,UAAU,CAAC,MAAM,QAAQ,OAAO,KAAK,CACjD,QAAO;AAET,KAAI,UAAU,UAAU,CAAC,MAAM,QAAQ,OAAO,KAAK,CACjD,QAAO;AAET,KAAI,gBAAgB,UAAU,CAAC,YAAY,OAAO,WAAW,CAC3D,QAAO;AAET,KAAI,aAAa,UAAU,CAAC,WAAW,OAAO,QAAQ,CACpD,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,eAAe,OAA6C;AAC1E,KAAI,CAAC,YAAY,MAAM,CACrB,QAAO;CAGT,MAAM,cAAc;AACpB,KAAI,aAAa,eAAe,CAAC,gBAAgB,YAAY,QAAQ,CACnE,QAAO;AAET,KAAI,cAAc,eAAe,CAAC,WAAW,YAAY,SAAS,CAChE,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,SAGd,OAAuC;AACvC,QACE,YAAY,MAAM,IAClB,YAAY,SACZ,YAAY,MAAM,OAAO,IACzB,WAAW,SACX,YAAY,MAAM,MAAM,IACxB,aAAa,SACb,YAAY,MAAM,QAAQ;;;;;;;;AAU9B,SAAgB,kBAGd,OAAgD;AAChD,QACE,SAAe,MAAM,IACrB,YAAY,SACZ,YAAY,MAAM,OAAO,IACzB,YAAY,MAAM,UAClB,YAAY,MAAM,OAAO,OAAO,IAChC,aAAa,MAAM,UACnB,YAAY,MAAM,OAAO,QAAQ"}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,39 +1,95 @@
|
|
|
1
1
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
2
|
-
import {
|
|
2
|
+
import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
|
|
3
3
|
import { StandardJSONSchemaV1 } from "@standard-schema/spec";
|
|
4
|
-
import {
|
|
4
|
+
import { JsonSchemaType } from "@stryke/json/types";
|
|
5
|
+
import { TypeDefinition } from "@stryke/types/configuration";
|
|
6
|
+
import { InputObject, Schema as Schema$1 } from "untyped";
|
|
5
7
|
import * as z3 from "zod/v3";
|
|
6
8
|
|
|
7
9
|
//#region src/types.d.ts
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
type UntypedInputObject = InputObject;
|
|
11
|
+
type UntypedSchema = Schema$1;
|
|
12
|
+
/**
|
|
13
|
+
* The set of numeric `type` strings supported by JSON Type Definition (RFC 8927).
|
|
14
|
+
*/
|
|
15
|
+
type JtdNumberType = "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32";
|
|
16
|
+
/**
|
|
17
|
+
* The set of `type` strings supported by JSON Type Definition (RFC 8927).
|
|
18
|
+
*/
|
|
19
|
+
type JtdType = JtdNumberType | "string" | "timestamp" | "boolean";
|
|
20
|
+
interface JsonSchemaLike {
|
|
21
|
+
type?: string | string[];
|
|
22
|
+
format?: string;
|
|
23
|
+
enum?: unknown[];
|
|
24
|
+
const?: unknown;
|
|
25
|
+
items?: JsonSchemaLike | JsonSchemaLike[];
|
|
26
|
+
properties?: Record<string, JsonSchemaLike>;
|
|
27
|
+
patternProperties?: Record<string, JsonSchemaLike>;
|
|
28
|
+
additionalProperties?: boolean | JsonSchemaLike;
|
|
29
|
+
required?: string[];
|
|
30
|
+
anyOf?: JsonSchemaLike[];
|
|
31
|
+
oneOf?: JsonSchemaLike[];
|
|
32
|
+
allOf?: JsonSchemaLike[];
|
|
33
|
+
$ref?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
default?: unknown;
|
|
37
|
+
examples?: unknown[];
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
exclusiveMinimum?: number | boolean;
|
|
41
|
+
exclusiveMaximum?: number | boolean;
|
|
42
|
+
nullable?: boolean;
|
|
43
|
+
definitions?: Record<string, JsonSchemaLike>;
|
|
44
|
+
$defs?: Record<string, JsonSchemaLike>;
|
|
45
|
+
discriminator?: {
|
|
46
|
+
propertyName?: string;
|
|
47
|
+
} | string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
|
|
51
|
+
type SchemaInputVariant = SchemaSourceVariant | "type-definition";
|
|
52
|
+
type SchemaSourceInput<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> = StandardJSONSchemaV1 | JTDSchemaType<T, D> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
|
|
53
|
+
type TypeDefinitionReference = TypeDefinition | string;
|
|
54
|
+
type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
|
|
55
|
+
interface Schema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> {
|
|
56
|
+
hash: string;
|
|
57
|
+
variant: SchemaInputVariant;
|
|
58
|
+
schema: JTDSchemaType<T, D>;
|
|
59
|
+
}
|
|
60
|
+
interface BaseSchemaSource {
|
|
61
|
+
hash: string;
|
|
62
|
+
variant: SchemaSourceVariant;
|
|
63
|
+
schema: SchemaSourceInput;
|
|
64
|
+
}
|
|
65
|
+
interface JTDSchemaSchemaSource<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> extends BaseSchemaSource {
|
|
66
|
+
variant: "jtd-schema";
|
|
67
|
+
schema: JTDSchemaType<T, D>;
|
|
68
|
+
}
|
|
69
|
+
interface JsonSchemaSchemaSource extends BaseSchemaSource {
|
|
16
70
|
variant: "json-schema";
|
|
17
|
-
|
|
71
|
+
schema: JsonSchemaType;
|
|
18
72
|
}
|
|
19
|
-
interface
|
|
20
|
-
schema: JsonSchema7Type;
|
|
73
|
+
interface StandardSchemaSchemaSource extends BaseSchemaSource {
|
|
21
74
|
variant: "standard-schema";
|
|
22
|
-
|
|
75
|
+
schema: StandardJSONSchemaV1;
|
|
23
76
|
}
|
|
24
|
-
interface
|
|
25
|
-
schema: JsonSchema7Type;
|
|
77
|
+
interface Zod3SchemaSource extends BaseSchemaSource {
|
|
26
78
|
variant: "zod3";
|
|
27
|
-
|
|
79
|
+
schema: z3.ZodTypeAny;
|
|
28
80
|
}
|
|
29
|
-
interface
|
|
30
|
-
schema: JsonSchema7Type;
|
|
81
|
+
interface ReflectionSchemaSource extends BaseSchemaSource {
|
|
31
82
|
variant: "reflection";
|
|
32
|
-
|
|
83
|
+
schema: Type;
|
|
84
|
+
}
|
|
85
|
+
interface UntypedSchemaSource extends BaseSchemaSource {
|
|
86
|
+
variant: "untyped";
|
|
87
|
+
schema: UntypedInputObject | UntypedSchema;
|
|
88
|
+
}
|
|
89
|
+
type SchemaSource = JsonSchemaSchemaSource | JTDSchemaSchemaSource | StandardSchemaSchemaSource | Zod3SchemaSource | UntypedSchemaSource | ReflectionSchemaSource;
|
|
90
|
+
interface ExtractedSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> extends Schema<T, D> {
|
|
91
|
+
source: SchemaSource;
|
|
33
92
|
}
|
|
34
|
-
type SchemaDefinition = SchemaDefinitionJsonSchema | SchemaDefinitionStandardSchema | SchemaDefinitionZod3 | SchemaDefinitionReflection;
|
|
35
|
-
type SchemaDefinitionInput = SchemaDefinition | JsonSchema7Type | StandardJSONSchemaV1 | z3.ZodTypeAny | Type;
|
|
36
|
-
type SchemaDefinitionParameter = SchemaDefinitionInput | TypeDefinitionParameter;
|
|
37
93
|
//#endregion
|
|
38
|
-
export {
|
|
94
|
+
export { BaseSchemaSource, ExtractedSchema, JTDSchemaSchemaSource, JsonSchemaLike, JsonSchemaSchemaSource, JtdNumberType, JtdType, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
39
95
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;KA0BY,kBAAA,GAAqB,WAAA;AAAA,KACrB,aAAA,GAAgB,QAAA;AAD5B;;;AAAA,KAMY,aAAA;;AALZ;;KAkBY,OAAA,GAAU,aAAA;AAAA,UAEL,cAAA;EACf,IAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA,GAAQ,cAAA,GAAiB,cAAA;EACzB,UAAA,GAAa,MAAA,SAAe,cAAA;EAC5B,iBAAA,GAAoB,MAAA,SAAe,cAAA;EACnC,oBAAA,aAAiC,cAAA;EACjC,QAAA;EACA,KAAA,GAAQ,cAAA;EACR,KAAA,GAAQ,cAAA;EACR,KAAA,GAAQ,cAAA;EACR,IAAA;EACA,WAAA;EACA,KAAA;EACA,OAAA;EACA,QAAA;EACA,OAAA;EACA,OAAA;EACA,gBAAA;EACA,gBAAA;EACA,QAAA;EACA,WAAA,GAAc,MAAA,SAAe,cAAA;EAC7B,KAAA,GAAQ,MAAA,SAAe,cAAA;EACvB,aAAA;IAAkB,YAAA;EAAA;EAAA,CACjB,GAAA;AAAA;AAAA,KAGS,mBAAA;AAAA,KAQA,kBAAA,GAAqB,mBAAA;AAAA,KAErB,iBAAA,wBAEA,MAAA,oBAA0B,MAAA,qBAElC,oBAAA,GACA,aAAA,CAAc,CAAA,EAAG,CAAA,IACjB,cAAA,GACA,EAAA,CAAG,UAAA,GACH,kBAAA,GACA,aAAA,GACA,IAAA;AAAA,KAEQ,uBAAA,GAA0B,cAAA;AAAA,KAE1B,WAAA,GAAc,iBAAA,GAAoB,MAAA,GAAS,uBAAA;AAAA,UAEtC,MAAA,wBAEL,MAAA,oBAA0B,MAAA;EAEpC,IAAA;EACA,OAAA,EAAS,kBAAA;EACT,MAAA,EAAQ,aAAA,CAAc,CAAA,EAAG,CAAA;AAAA;AAAA,UAGV,gBAAA;EACf,IAAA;EACA,OAAA,EAAS,mBAAA;EACT,MAAA,EAAQ,iBAAA;AAAA;AAAA,UAGO,qBAAA,wBAEL,MAAA,oBAA0B,MAAA,2BAC5B,gBAAA;EACR,OAAA;EACA,MAAA,EAAQ,aAAA,CAAc,CAAA,EAAG,CAAA;AAAA;AAAA,UAGV,sBAAA,SAA+B,gBAAA;EAC9C,OAAA;EACA,MAAA,EAAQ,cAAA;AAAA;AAAA,UAGO,0BAAA,SAAmC,gBAAA;EAClD,OAAA;EACA,MAAA,EAAQ,oBAAA;AAAA;AAAA,UAGO,gBAAA,SAAyB,gBAAA;EACxC,OAAA;EACA,MAAA,EAAQ,EAAA,CAAG,UAAA;AAAA;AAAA,UAGI,sBAAA,SAA+B,gBAAA;EAC9C,OAAA;EACA,MAAA,EAAQ,IAAA;AAAA;AAAA,UAGO,mBAAA,SAA4B,gBAAA;EAC3C,OAAA;EACA,MAAA,EAAQ,kBAAA,GAAqB,aAAA;AAAA;AAAA,KAGnB,YAAA,GACR,sBAAA,GACA,qBAAA,GACA,0BAAA,GACA,gBAAA,GACA,mBAAA,GACA,sBAAA;AAAA,UAEa,eAAA,wBAEL,MAAA,oBAA0B,MAAA,2BAC5B,MAAA,CAAO,CAAA,EAAG,CAAA;EAClB,MAAA,EAAQ,YAAA;AAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,39 +1,95 @@
|
|
|
1
1
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
2
|
-
import {
|
|
2
|
+
import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
|
|
3
3
|
import { StandardJSONSchemaV1 } from "@standard-schema/spec";
|
|
4
|
-
import {
|
|
4
|
+
import { JsonSchemaType } from "@stryke/json/types";
|
|
5
|
+
import { TypeDefinition } from "@stryke/types/configuration";
|
|
6
|
+
import { InputObject, Schema as Schema$1 } from "untyped";
|
|
5
7
|
import * as z3 from "zod/v3";
|
|
6
8
|
|
|
7
9
|
//#region src/types.d.ts
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
type UntypedInputObject = InputObject;
|
|
11
|
+
type UntypedSchema = Schema$1;
|
|
12
|
+
/**
|
|
13
|
+
* The set of numeric `type` strings supported by JSON Type Definition (RFC 8927).
|
|
14
|
+
*/
|
|
15
|
+
type JtdNumberType = "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32";
|
|
16
|
+
/**
|
|
17
|
+
* The set of `type` strings supported by JSON Type Definition (RFC 8927).
|
|
18
|
+
*/
|
|
19
|
+
type JtdType = JtdNumberType | "string" | "timestamp" | "boolean";
|
|
20
|
+
interface JsonSchemaLike {
|
|
21
|
+
type?: string | string[];
|
|
22
|
+
format?: string;
|
|
23
|
+
enum?: unknown[];
|
|
24
|
+
const?: unknown;
|
|
25
|
+
items?: JsonSchemaLike | JsonSchemaLike[];
|
|
26
|
+
properties?: Record<string, JsonSchemaLike>;
|
|
27
|
+
patternProperties?: Record<string, JsonSchemaLike>;
|
|
28
|
+
additionalProperties?: boolean | JsonSchemaLike;
|
|
29
|
+
required?: string[];
|
|
30
|
+
anyOf?: JsonSchemaLike[];
|
|
31
|
+
oneOf?: JsonSchemaLike[];
|
|
32
|
+
allOf?: JsonSchemaLike[];
|
|
33
|
+
$ref?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
default?: unknown;
|
|
37
|
+
examples?: unknown[];
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
exclusiveMinimum?: number | boolean;
|
|
41
|
+
exclusiveMaximum?: number | boolean;
|
|
42
|
+
nullable?: boolean;
|
|
43
|
+
definitions?: Record<string, JsonSchemaLike>;
|
|
44
|
+
$defs?: Record<string, JsonSchemaLike>;
|
|
45
|
+
discriminator?: {
|
|
46
|
+
propertyName?: string;
|
|
47
|
+
} | string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
|
|
51
|
+
type SchemaInputVariant = SchemaSourceVariant | "type-definition";
|
|
52
|
+
type SchemaSourceInput<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> = StandardJSONSchemaV1 | JTDSchemaType<T, D> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
|
|
53
|
+
type TypeDefinitionReference = TypeDefinition | string;
|
|
54
|
+
type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
|
|
55
|
+
interface Schema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> {
|
|
56
|
+
hash: string;
|
|
57
|
+
variant: SchemaInputVariant;
|
|
58
|
+
schema: JTDSchemaType<T, D>;
|
|
59
|
+
}
|
|
60
|
+
interface BaseSchemaSource {
|
|
61
|
+
hash: string;
|
|
62
|
+
variant: SchemaSourceVariant;
|
|
63
|
+
schema: SchemaSourceInput;
|
|
64
|
+
}
|
|
65
|
+
interface JTDSchemaSchemaSource<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> extends BaseSchemaSource {
|
|
66
|
+
variant: "jtd-schema";
|
|
67
|
+
schema: JTDSchemaType<T, D>;
|
|
68
|
+
}
|
|
69
|
+
interface JsonSchemaSchemaSource extends BaseSchemaSource {
|
|
16
70
|
variant: "json-schema";
|
|
17
|
-
|
|
71
|
+
schema: JsonSchemaType;
|
|
18
72
|
}
|
|
19
|
-
interface
|
|
20
|
-
schema: JsonSchema7Type;
|
|
73
|
+
interface StandardSchemaSchemaSource extends BaseSchemaSource {
|
|
21
74
|
variant: "standard-schema";
|
|
22
|
-
|
|
75
|
+
schema: StandardJSONSchemaV1;
|
|
23
76
|
}
|
|
24
|
-
interface
|
|
25
|
-
schema: JsonSchema7Type;
|
|
77
|
+
interface Zod3SchemaSource extends BaseSchemaSource {
|
|
26
78
|
variant: "zod3";
|
|
27
|
-
|
|
79
|
+
schema: z3.ZodTypeAny;
|
|
28
80
|
}
|
|
29
|
-
interface
|
|
30
|
-
schema: JsonSchema7Type;
|
|
81
|
+
interface ReflectionSchemaSource extends BaseSchemaSource {
|
|
31
82
|
variant: "reflection";
|
|
32
|
-
|
|
83
|
+
schema: Type;
|
|
84
|
+
}
|
|
85
|
+
interface UntypedSchemaSource extends BaseSchemaSource {
|
|
86
|
+
variant: "untyped";
|
|
87
|
+
schema: UntypedInputObject | UntypedSchema;
|
|
88
|
+
}
|
|
89
|
+
type SchemaSource = JsonSchemaSchemaSource | JTDSchemaSchemaSource | StandardSchemaSchemaSource | Zod3SchemaSource | UntypedSchemaSource | ReflectionSchemaSource;
|
|
90
|
+
interface ExtractedSchema<T = unknown, D extends Record<string, unknown> = Record<string, unknown>> extends Schema<T, D> {
|
|
91
|
+
source: SchemaSource;
|
|
33
92
|
}
|
|
34
|
-
type SchemaDefinition = SchemaDefinitionJsonSchema | SchemaDefinitionStandardSchema | SchemaDefinitionZod3 | SchemaDefinitionReflection;
|
|
35
|
-
type SchemaDefinitionInput = SchemaDefinition | JsonSchema7Type | StandardJSONSchemaV1 | z3.ZodTypeAny | Type;
|
|
36
|
-
type SchemaDefinitionParameter = SchemaDefinitionInput | TypeDefinitionParameter;
|
|
37
93
|
//#endregion
|
|
38
|
-
export {
|
|
94
|
+
export { BaseSchemaSource, ExtractedSchema, JTDSchemaSchemaSource, JsonSchemaLike, JsonSchemaSchemaSource, JtdNumberType, JtdType, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
39
95
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;KA0BY,kBAAA,GAAqB,WAAA;AAAA,KACrB,aAAA,GAAgB,QAAA;AAD5B;;;AAAA,KAMY,aAAA;;AALZ;;KAkBY,OAAA,GAAU,aAAA;AAAA,UAEL,cAAA;EACf,IAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA,GAAQ,cAAA,GAAiB,cAAA;EACzB,UAAA,GAAa,MAAA,SAAe,cAAA;EAC5B,iBAAA,GAAoB,MAAA,SAAe,cAAA;EACnC,oBAAA,aAAiC,cAAA;EACjC,QAAA;EACA,KAAA,GAAQ,cAAA;EACR,KAAA,GAAQ,cAAA;EACR,KAAA,GAAQ,cAAA;EACR,IAAA;EACA,WAAA;EACA,KAAA;EACA,OAAA;EACA,QAAA;EACA,OAAA;EACA,OAAA;EACA,gBAAA;EACA,gBAAA;EACA,QAAA;EACA,WAAA,GAAc,MAAA,SAAe,cAAA;EAC7B,KAAA,GAAQ,MAAA,SAAe,cAAA;EACvB,aAAA;IAAkB,YAAA;EAAA;EAAA,CACjB,GAAA;AAAA;AAAA,KAGS,mBAAA;AAAA,KAQA,kBAAA,GAAqB,mBAAA;AAAA,KAErB,iBAAA,wBAEA,MAAA,oBAA0B,MAAA,qBAElC,oBAAA,GACA,aAAA,CAAc,CAAA,EAAG,CAAA,IACjB,cAAA,GACA,EAAA,CAAG,UAAA,GACH,kBAAA,GACA,aAAA,GACA,IAAA;AAAA,KAEQ,uBAAA,GAA0B,cAAA;AAAA,KAE1B,WAAA,GAAc,iBAAA,GAAoB,MAAA,GAAS,uBAAA;AAAA,UAEtC,MAAA,wBAEL,MAAA,oBAA0B,MAAA;EAEpC,IAAA;EACA,OAAA,EAAS,kBAAA;EACT,MAAA,EAAQ,aAAA,CAAc,CAAA,EAAG,CAAA;AAAA;AAAA,UAGV,gBAAA;EACf,IAAA;EACA,OAAA,EAAS,mBAAA;EACT,MAAA,EAAQ,iBAAA;AAAA;AAAA,UAGO,qBAAA,wBAEL,MAAA,oBAA0B,MAAA,2BAC5B,gBAAA;EACR,OAAA;EACA,MAAA,EAAQ,aAAA,CAAc,CAAA,EAAG,CAAA;AAAA;AAAA,UAGV,sBAAA,SAA+B,gBAAA;EAC9C,OAAA;EACA,MAAA,EAAQ,cAAA;AAAA;AAAA,UAGO,0BAAA,SAAmC,gBAAA;EAClD,OAAA;EACA,MAAA,EAAQ,oBAAA;AAAA;AAAA,UAGO,gBAAA,SAAyB,gBAAA;EACxC,OAAA;EACA,MAAA,EAAQ,EAAA,CAAG,UAAA;AAAA;AAAA,UAGI,sBAAA,SAA+B,gBAAA;EAC9C,OAAA;EACA,MAAA,EAAQ,IAAA;AAAA;AAAA,UAGO,mBAAA,SAA4B,gBAAA;EAC3C,OAAA;EACA,MAAA,EAAQ,kBAAA,GAAqB,aAAA;AAAA;AAAA,KAGnB,YAAA,GACR,sBAAA,GACA,qBAAA,GACA,0BAAA,GACA,gBAAA,GACA,mBAAA,GACA,sBAAA;AAAA,UAEa,eAAA,wBAEL,MAAA,oBAA0B,MAAA,2BAC5B,MAAA,CAAO,CAAA,EAAG,CAAA;EAClB,MAAA,EAAQ,YAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"keywords": [
|
|
@@ -58,10 +58,7 @@
|
|
|
58
58
|
"import": "./dist/extract.mjs",
|
|
59
59
|
"require": "./dist/extract.cjs"
|
|
60
60
|
},
|
|
61
|
-
"./
|
|
62
|
-
"import": "./dist/is-schema-definition.mjs",
|
|
63
|
-
"require": "./dist/is-schema-definition.cjs"
|
|
64
|
-
},
|
|
61
|
+
"./jtd": { "import": "./dist/jtd.mjs", "require": "./dist/jtd.cjs" },
|
|
65
62
|
"./reflection": {
|
|
66
63
|
"import": "./dist/reflection.mjs",
|
|
67
64
|
"require": "./dist/reflection.cjs"
|
|
@@ -70,6 +67,10 @@
|
|
|
70
67
|
"import": "./dist/resolve.mjs",
|
|
71
68
|
"require": "./dist/resolve.cjs"
|
|
72
69
|
},
|
|
70
|
+
"./type-checks": {
|
|
71
|
+
"import": "./dist/type-checks.mjs",
|
|
72
|
+
"require": "./dist/type-checks.cjs"
|
|
73
|
+
},
|
|
73
74
|
"./types": { "import": "./dist/types.mjs", "require": "./dist/types.cjs" },
|
|
74
75
|
"./package.json": "./package.json"
|
|
75
76
|
},
|
|
@@ -79,25 +80,26 @@
|
|
|
79
80
|
"typings": "dist/index.d.mts",
|
|
80
81
|
"files": ["dist"],
|
|
81
82
|
"dependencies": {
|
|
82
|
-
"@powerlines/core": "^0.
|
|
83
|
-
"@powerlines/deepkit": "^0.
|
|
84
|
-
"@powerlines/unplugin": "^0.0.
|
|
83
|
+
"@powerlines/core": "^0.9.0",
|
|
84
|
+
"@powerlines/deepkit": "^0.9.0",
|
|
85
|
+
"@powerlines/unplugin": "^0.0.13",
|
|
85
86
|
"@standard-schema/spec": "^1.1.0",
|
|
86
|
-
"@
|
|
87
|
-
"@stryke/
|
|
88
|
-
"@stryke/
|
|
89
|
-
"@stryke/
|
|
90
|
-
"@stryke/
|
|
91
|
-
"@stryke/
|
|
92
|
-
"@stryke/
|
|
93
|
-
"
|
|
87
|
+
"@stryke/hash": "^0.13.29",
|
|
88
|
+
"@stryke/helpers": "^0.10.16",
|
|
89
|
+
"@stryke/json": "^0.15.0",
|
|
90
|
+
"@stryke/path": "^0.29.3",
|
|
91
|
+
"@stryke/type-checks": "^0.6.9",
|
|
92
|
+
"@stryke/types": "^0.12.4",
|
|
93
|
+
"@stryke/zod": "^0.3.22",
|
|
94
|
+
"ajv": "^8.20.0",
|
|
94
95
|
"defu": "^6.1.7",
|
|
95
96
|
"esbuild": "^0.27.7",
|
|
96
|
-
"typescript": "^6.0.3"
|
|
97
|
+
"typescript": "^6.0.3",
|
|
98
|
+
"untyped": "^1.5.2"
|
|
97
99
|
},
|
|
98
|
-
"devDependencies": { "
|
|
100
|
+
"devDependencies": { "@types/node": "^25.8.0", "zod": "^4.4.3" },
|
|
99
101
|
"peerDependencies": { "zod": "^3.25.0 || ^4.0.0" },
|
|
100
102
|
"peerDependenciesMeta": { "zod": { "optional": true } },
|
|
101
103
|
"publishConfig": { "access": "public" },
|
|
102
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "8e3c08ac9b40e909814a16d808fae1a98d392d65"
|
|
103
105
|
}
|