@powerlines/schema 0.11.22 → 0.11.24
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/bundle.mjs.map +1 -1
- package/dist/codegen.cjs +44 -1
- package/dist/codegen.d.cts +19 -1
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +19 -1
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +42 -1
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +19 -0
- package/dist/constants.d.cts +17 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +17 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +18 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/extract.cjs +23 -4
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +23 -4
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +54 -0
- package/dist/helpers.d.cts +26 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +26 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs +52 -0
- package/dist/helpers.mjs.map +1 -0
- package/dist/index.cjs +17 -2
- package/dist/index.d.cts +7 -4
- package/dist/index.d.mts +7 -4
- package/dist/index.mjs +6 -3
- package/dist/jtd.mjs.map +1 -1
- package/dist/persistence.cjs +76 -0
- package/dist/persistence.d.cts +47 -0
- package/dist/persistence.d.cts.map +1 -0
- package/dist/persistence.d.mts +47 -0
- package/dist/persistence.d.mts.map +1 -0
- package/dist/persistence.mjs +71 -0
- package/dist/persistence.mjs.map +1 -0
- package/dist/reflection.cjs +13 -6
- package/dist/reflection.d.cts.map +1 -1
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +12 -6
- package/dist/reflection.mjs.map +1 -1
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +21 -2
- package/dist/type-checks.d.cts +16 -2
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +16 -2
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +21 -4
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +42 -12
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +42 -12
- package/dist/types.d.mts.map +1 -1
- package/package.json +19 -7
package/dist/type-checks.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { isFunction, isSetObject, isSetString } from "@stryke/type-checks";
|
|
2
|
-
import { isJsonSchemaObjectType } from "@stryke/json/schema";
|
|
1
|
+
import { isFunction, isObject, isSetObject, isSetString } from "@stryke/type-checks";
|
|
3
2
|
|
|
4
3
|
//#region src/type-checks.ts
|
|
5
4
|
/**
|
|
@@ -8,8 +7,17 @@ import { isJsonSchemaObjectType } from "@stryke/json/schema";
|
|
|
8
7
|
* @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
|
|
9
8
|
* @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
|
|
10
9
|
*/
|
|
10
|
+
function isJTDSchemaObject(input) {
|
|
11
|
+
return isSetObject(input) && ("properties" in input && isObject(input.properties) || "optionalProperties" in input && isObject(input.optionalProperties));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 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`.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
|
|
17
|
+
* @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
|
|
18
|
+
*/
|
|
11
19
|
function isJTDSchema(input) {
|
|
12
|
-
return
|
|
20
|
+
return isSetObject(input) && (isJTDSchemaObject(input) || "elements" in input || "values" in input || "ref" in input || "type" in input || "enum" in input || "discriminator" in input && isSetString(input.discriminator) && "mapping" in input && isObject(input.mapping));
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
23
|
* 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.
|
|
@@ -65,7 +73,16 @@ function isSchema(input) {
|
|
|
65
73
|
function isExtractedSchema(input) {
|
|
66
74
|
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
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
|
|
78
|
+
*
|
|
79
|
+
* @param input - The input to check for being a {@link ObjectSchema}.
|
|
80
|
+
* @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
|
|
81
|
+
*/
|
|
82
|
+
function isObjectSchema(input) {
|
|
83
|
+
return isSchema(input) && isJTDSchemaObject(input.schema);
|
|
84
|
+
}
|
|
68
85
|
|
|
69
86
|
//#endregion
|
|
70
|
-
export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
|
|
87
|
+
export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
|
|
71
88
|
//# sourceMappingURL=type-checks.mjs.map
|
package/dist/type-checks.mjs.map
CHANGED
|
@@ -1 +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, SchemaMetadata } 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<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is JTDSchemaType<TMetadata> {\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<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is Schema<TMetadata> {\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 TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ExtractedSchema<TMetadata> {\n return (\n isSchema<TMetadata>(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,YACd,OACmC;AACnC,QAAO,uBA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SACZ,YAAY,MAAM,OAAO,IACzB,WAAW,SACX,YAAY,MAAM,MAAM,IACxB,aAAa,SACb,YAAY,MAAM,QAAQ;;;;;;;;AAU9B,SAAgB,kBAEd,OAAqD;AACrD,QACE,SAAoB,MAAM,IAC1B,YAAY,SACZ,YAAY,MAAM,OAAO,IACzB,YAAY,MAAM,UAClB,YAAY,MAAM,OAAO,OAAO,IAChC,aAAa,MAAM,UACnB,YAAY,MAAM,OAAO,QAAQ"}
|
|
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 {\n isFunction,\n isObject,\n isSetObject,\n isSetString\n} 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 {\n ExtractedSchema,\n JTDSchemaObjectType,\n ObjectSchema,\n Schema,\n SchemaMetadata\n} 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 isJTDSchemaObject<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is JTDSchemaObjectType<TMetadata> {\n return (\n isSetObject(input) &&\n ((\"properties\" in input && isObject(input.properties)) ||\n (\"optionalProperties\" in input && isObject(input.optionalProperties)))\n );\n}\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<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is JTDSchemaType<TMetadata> {\n return (\n isSetObject(input) &&\n (isJTDSchemaObject<TMetadata>(input) ||\n \"elements\" in input ||\n \"values\" in input ||\n \"ref\" in input ||\n \"type\" in input ||\n \"enum\" in input ||\n (\"discriminator\" in input &&\n isSetString(input.discriminator) &&\n \"mapping\" in input &&\n isObject(input.mapping)))\n );\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<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is Schema<TMetadata> {\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 TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ExtractedSchema<TMetadata> {\n return (\n isSchema<TMetadata>(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\n/**\n * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ObjectSchema}.\n * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.\n */\nexport function isObjectSchema<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ObjectSchema<TMetadata> {\n return (\n isSchema<TMetadata>(input) && isJTDSchemaObject<TMet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C,WAAW,OAAO,OAAO,GACnD,OAAO;CAGT,OAAO;AACT;;;;;;;AAQA,SAAgB,eAAe,OAA6C;CAC1E,IAAI,CAAC,YAAY,KAAK,GACpB,OAAO;CAGT,MAAM,cAAc;CACpB,IAAI,aAAa,eAAe,CAAC,gBAAgB,YAAY,OAAO,GAClE,OAAO;CAET,IAAI,cAAc,eAAe,CAAC,WAAW,YAAY,QAAQ,GAC/D,OAAO;CAGT,OAAO;AACT;;;;;;;AAQA,SAAgB,SACd,OAC4B;CAC5B,OACE,YAAY,KAAK,KACjB,YAAY,SACZ,YAAY,MAAM,MAAM,KACxB,WAAW,SACX,YAAY,MAAM,KAAK,KACvB,aAAa,SACb,YAAY,MAAM,OAAO;AAE7B;;;;;;;AAQA,SAAgB,kBAEd,OAAqD;CACrD,OACE,SAAoB,KAAK,KACzB,YAAY,SACZ,YAAY,MAAM,MAAM,KACxB,YAAY,MAAM,UAClB,YAAY,MAAM,OAAO,MAAM,KAC/B,aAAa,MAAM,UACnB,YAAY,MAAM,OAAO,OAAO;AAEpC;;;;;;;AAQA,SAAgB,eAEd,OAAkD;CAClD,OACE,SAAoB,KAAK,KAAK,kBAA6B,MAAM,MAAM;AAE3E"}
|
package/dist/types.d.cts
CHANGED
|
@@ -51,6 +51,10 @@ interface JsonSchemaLike {
|
|
|
51
51
|
[key: string]: unknown;
|
|
52
52
|
}
|
|
53
53
|
interface SchemaMetadata {
|
|
54
|
+
/**
|
|
55
|
+
* A name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
56
|
+
*/
|
|
57
|
+
name?: string;
|
|
54
58
|
/**
|
|
55
59
|
* A title for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
56
60
|
*/
|
|
@@ -68,9 +72,20 @@ interface SchemaMetadata {
|
|
|
68
72
|
*/
|
|
69
73
|
examples?: unknown[];
|
|
70
74
|
/**
|
|
71
|
-
*
|
|
75
|
+
* An array of strings indicating groups that the schema belongs to. This property can be used for organizational or categorization purposes in documentation tools or other libraries that support this feature. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The concept of "groups" is not a standard feature of JSON Schema or JSON Type Definition, but it can be a useful convention for organizing schemas in larger projects or for providing additional metadata that can be leveraged by documentation generators or other tools. The specific meaning and usage of groups would depend on the conventions established within the project or the tools being used.
|
|
79
|
+
*/
|
|
80
|
+
groups?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* A visibility level for the schema, which can be used by documentation tools or other libraries that support this feature to determine how the schema should be presented or accessed. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
72
83
|
*/
|
|
73
|
-
|
|
84
|
+
visibility?: "public" | "protected" | "private";
|
|
85
|
+
/**
|
|
86
|
+
* A resource identifier for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
87
|
+
*/
|
|
88
|
+
resourceId?: string;
|
|
74
89
|
/**
|
|
75
90
|
* An indicator specifying if the field should be marked as hidden or not.
|
|
76
91
|
*/
|
|
@@ -107,6 +122,15 @@ interface SchemaMetadata {
|
|
|
107
122
|
union?: JsonSchemaLike[];
|
|
108
123
|
[key: string]: unknown | undefined;
|
|
109
124
|
}
|
|
125
|
+
type JTDSchemaObjectForm<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = {
|
|
126
|
+
properties: Record<string, JTDSchemaType<TMetadata>>;
|
|
127
|
+
optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
128
|
+
additionalProperties?: boolean;
|
|
129
|
+
} | {
|
|
130
|
+
properties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
131
|
+
optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
|
|
132
|
+
additionalProperties?: boolean;
|
|
133
|
+
};
|
|
110
134
|
type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = ({
|
|
111
135
|
ref: string;
|
|
112
136
|
} | {
|
|
@@ -117,15 +141,7 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
|
|
|
117
141
|
elements: JTDSchemaType<TMetadata>;
|
|
118
142
|
} | {
|
|
119
143
|
values: JTDSchemaType<TMetadata>;
|
|
120
|
-
} | {
|
|
121
|
-
properties: Record<string, JTDSchemaType<TMetadata>>;
|
|
122
|
-
optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
123
|
-
additionalProperties?: boolean;
|
|
124
|
-
} | {
|
|
125
|
-
properties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
126
|
-
optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
|
|
127
|
-
additionalProperties?: boolean;
|
|
128
|
-
} | {
|
|
144
|
+
} | JTDSchemaObjectForm<TMetadata> | {
|
|
129
145
|
discriminator: string;
|
|
130
146
|
mapping: Record<string, JTDSchemaType<TMetadata>>;
|
|
131
147
|
} | {}) & {
|
|
@@ -133,16 +149,30 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
|
|
|
133
149
|
metadata?: TMetadata;
|
|
134
150
|
definitions?: Record<string, JTDSchemaType<TMetadata>>;
|
|
135
151
|
};
|
|
152
|
+
type JTDSchemaObjectType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = JTDSchemaObjectForm<TMetadata> & {
|
|
153
|
+
nullable?: boolean;
|
|
154
|
+
metadata?: TMetadata;
|
|
155
|
+
definitions?: Record<string, JTDSchemaType<TMetadata>>;
|
|
156
|
+
};
|
|
136
157
|
type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
|
|
137
158
|
type SchemaInputVariant = SchemaSourceVariant | "type-definition";
|
|
138
159
|
type SchemaSourceInput<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = StandardJSONSchemaV1 | JTDSchemaType<TMetadata> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
|
|
139
160
|
type TypeDefinitionReference = TypeDefinition | string;
|
|
140
161
|
type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
|
|
162
|
+
/**
|
|
163
|
+
* A type representing a schema that has been extracted from a source input. This type includes a `hash` property, which is a string that uniquely identifies the schema based on its content and source; a `variant` property, which indicates the format or type of the original input from which the schema was extracted (e.g., "jtd-schema", "json-schema", "zod3", "untyped", "reflection", or "type-definition"); and a `schema` property, which is the extracted schema itself represented as a JSON Type Definition (JTD) schema object with optional metadata. This type can be used to represent schemas in a standardized format regardless of their original source or representation.
|
|
164
|
+
*/
|
|
141
165
|
interface Schema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> {
|
|
142
166
|
hash: string;
|
|
143
167
|
variant: SchemaInputVariant;
|
|
144
168
|
schema: JTDSchemaType<TMetadata>;
|
|
145
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* A type representing a JSON Type Definition (JTD) schema that specifically has an object form (i.e., it has either a `properties` property that is an object or an `optionalProperties` property that is an object, as per the structure of JTD schema objects). This type extends the base {@link Schema} type and narrows the `schema` property to be a `JTDSchemaObjectType`, which ensures that any schema of this type will have the structure of a JTD object schema.
|
|
172
|
+
*/
|
|
173
|
+
interface ObjectSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> extends Schema<TMetadata> {
|
|
174
|
+
schema: JTDSchemaObjectType<TMetadata>;
|
|
175
|
+
}
|
|
146
176
|
interface BaseSchemaSource {
|
|
147
177
|
hash: string;
|
|
148
178
|
variant: SchemaSourceVariant;
|
|
@@ -177,5 +207,5 @@ interface ExtractedSchema<TMetadata extends Partial<SchemaMetadata> = Partial<Sc
|
|
|
177
207
|
source: SchemaSource;
|
|
178
208
|
}
|
|
179
209
|
//#endregion
|
|
180
|
-
export { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
210
|
+
export { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaObjectForm, JTDSchemaObjectType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ObjectSchema, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
181
211
|
//# 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":";;;;;;;;KAyBY,kBAAA,GAAqB,
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;KAyBY,kBAAA,GAAqB,WAAW;AAAA,KAChC,aAAA,GAAgB,QAAO;AADnC;;;AAAA,KAMY,aAAA;AANgC;AAC5C;;AAD4C,KAmBhC,aAAA;;AAlBuB;AAKnC;KAkBY,OAAA,GAAU,aAAA,GAAgB,aAAa;AAAA,UAElC,cAAA;EACf,IAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA,GAAQ,cAAA,GA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AA;AAAA,UAGV,qBAAA,mBACG,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,WAC5C,gBAAA;EACR,OAAA;EACA,MAAA,EAAQ,aAAA,CAAc,SAAA;AAAA;AAAA,UAGP,sBAAA,SAA+B,gBAAgB;EAC9D,OAAA;EACA,MAAA,EAAQ,cAAA;AAAA;AAAA,UAGO,0BAAA,SAAmC,gBAAgB;EAClE,OAAA;EACA,MAAA,EAAQ,oBAAA;AAAA;AAAA,UAGO,gBAAA,SAAyB,gBAAgB;EACxD,OAAA;EACA,MAAA,EAAQ,EAAA,CAAG,UAAA;AAAA;AAAA,UAGI,sBAAA,SAA+B,gBAAgB;EAC9D,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,mBACG,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,WAC5C,MAAA,CAAO,SAAA;EACf,MAAA,EAAQ,YAAA;AAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -51,6 +51,10 @@ interface JsonSchemaLike {
|
|
|
51
51
|
[key: string]: unknown;
|
|
52
52
|
}
|
|
53
53
|
interface SchemaMetadata {
|
|
54
|
+
/**
|
|
55
|
+
* A name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
56
|
+
*/
|
|
57
|
+
name?: string;
|
|
54
58
|
/**
|
|
55
59
|
* A title for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
56
60
|
*/
|
|
@@ -68,9 +72,20 @@ interface SchemaMetadata {
|
|
|
68
72
|
*/
|
|
69
73
|
examples?: unknown[];
|
|
70
74
|
/**
|
|
71
|
-
*
|
|
75
|
+
* An array of strings indicating groups that the schema belongs to. This property can be used for organizational or categorization purposes in documentation tools or other libraries that support this feature. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The concept of "groups" is not a standard feature of JSON Schema or JSON Type Definition, but it can be a useful convention for organizing schemas in larger projects or for providing additional metadata that can be leveraged by documentation generators or other tools. The specific meaning and usage of groups would depend on the conventions established within the project or the tools being used.
|
|
79
|
+
*/
|
|
80
|
+
groups?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* A visibility level for the schema, which can be used by documentation tools or other libraries that support this feature to determine how the schema should be presented or accessed. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
72
83
|
*/
|
|
73
|
-
|
|
84
|
+
visibility?: "public" | "protected" | "private";
|
|
85
|
+
/**
|
|
86
|
+
* A resource identifier for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
87
|
+
*/
|
|
88
|
+
resourceId?: string;
|
|
74
89
|
/**
|
|
75
90
|
* An indicator specifying if the field should be marked as hidden or not.
|
|
76
91
|
*/
|
|
@@ -107,6 +122,15 @@ interface SchemaMetadata {
|
|
|
107
122
|
union?: JsonSchemaLike[];
|
|
108
123
|
[key: string]: unknown | undefined;
|
|
109
124
|
}
|
|
125
|
+
type JTDSchemaObjectForm<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = {
|
|
126
|
+
properties: Record<string, JTDSchemaType<TMetadata>>;
|
|
127
|
+
optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
128
|
+
additionalProperties?: boolean;
|
|
129
|
+
} | {
|
|
130
|
+
properties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
131
|
+
optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
|
|
132
|
+
additionalProperties?: boolean;
|
|
133
|
+
};
|
|
110
134
|
type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = ({
|
|
111
135
|
ref: string;
|
|
112
136
|
} | {
|
|
@@ -117,15 +141,7 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
|
|
|
117
141
|
elements: JTDSchemaType<TMetadata>;
|
|
118
142
|
} | {
|
|
119
143
|
values: JTDSchemaType<TMetadata>;
|
|
120
|
-
} | {
|
|
121
|
-
properties: Record<string, JTDSchemaType<TMetadata>>;
|
|
122
|
-
optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
123
|
-
additionalProperties?: boolean;
|
|
124
|
-
} | {
|
|
125
|
-
properties?: Record<string, JTDSchemaType<TMetadata>>;
|
|
126
|
-
optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
|
|
127
|
-
additionalProperties?: boolean;
|
|
128
|
-
} | {
|
|
144
|
+
} | JTDSchemaObjectForm<TMetadata> | {
|
|
129
145
|
discriminator: string;
|
|
130
146
|
mapping: Record<string, JTDSchemaType<TMetadata>>;
|
|
131
147
|
} | {}) & {
|
|
@@ -133,16 +149,30 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
|
|
|
133
149
|
metadata?: TMetadata;
|
|
134
150
|
definitions?: Record<string, JTDSchemaType<TMetadata>>;
|
|
135
151
|
};
|
|
152
|
+
type JTDSchemaObjectType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = JTDSchemaObjectForm<TMetadata> & {
|
|
153
|
+
nullable?: boolean;
|
|
154
|
+
metadata?: TMetadata;
|
|
155
|
+
definitions?: Record<string, JTDSchemaType<TMetadata>>;
|
|
156
|
+
};
|
|
136
157
|
type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
|
|
137
158
|
type SchemaInputVariant = SchemaSourceVariant | "type-definition";
|
|
138
159
|
type SchemaSourceInput<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = StandardJSONSchemaV1 | JTDSchemaType<TMetadata> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
|
|
139
160
|
type TypeDefinitionReference = TypeDefinition | string;
|
|
140
161
|
type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
|
|
162
|
+
/**
|
|
163
|
+
* A type representing a schema that has been extracted from a source input. This type includes a `hash` property, which is a string that uniquely identifies the schema based on its content and source; a `variant` property, which indicates the format or type of the original input from which the schema was extracted (e.g., "jtd-schema", "json-schema", "zod3", "untyped", "reflection", or "type-definition"); and a `schema` property, which is the extracted schema itself represented as a JSON Type Definition (JTD) schema object with optional metadata. This type can be used to represent schemas in a standardized format regardless of their original source or representation.
|
|
164
|
+
*/
|
|
141
165
|
interface Schema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> {
|
|
142
166
|
hash: string;
|
|
143
167
|
variant: SchemaInputVariant;
|
|
144
168
|
schema: JTDSchemaType<TMetadata>;
|
|
145
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* A type representing a JSON Type Definition (JTD) schema that specifically has an object form (i.e., it has either a `properties` property that is an object or an `optionalProperties` property that is an object, as per the structure of JTD schema objects). This type extends the base {@link Schema} type and narrows the `schema` property to be a `JTDSchemaObjectType`, which ensures that any schema of this type will have the structure of a JTD object schema.
|
|
172
|
+
*/
|
|
173
|
+
interface ObjectSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> extends Schema<TMetadata> {
|
|
174
|
+
schema: JTDSchemaObjectType<TMetadata>;
|
|
175
|
+
}
|
|
146
176
|
interface BaseSchemaSource {
|
|
147
177
|
hash: string;
|
|
148
178
|
variant: SchemaSourceVariant;
|
|
@@ -177,5 +207,5 @@ interface ExtractedSchema<TMetadata extends Partial<SchemaMetadata> = Partial<Sc
|
|
|
177
207
|
source: SchemaSource;
|
|
178
208
|
}
|
|
179
209
|
//#endregion
|
|
180
|
-
export { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
210
|
+
export { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaObjectForm, JTDSchemaObjectType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ObjectSchema, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
181
211
|
//# 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":";;;;;;;;KAyBY,kBAAA,GAAqB,
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;KAyBY,kBAAA,GAAqB,WAAW;AAAA,KAChC,aAAA,GAAgB,QAAO;AADnC;;;AAAA,KAMY,aAAA;AANgC;AAC5C;;AAD4C,KAmBhC,aAAA;;AAlBuB;AAKnC;KAkBY,OAAA,GAAU,aAAA,GAAgB,aAAa;AAAA,UAElC,cAAA;EACf,IAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA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ACT,MAAA,EAAQ,iBAAiB;AAAA;AAAA,UAGV,qBAAA,mBACG,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,WAC5C,gBAAA;EACR,OAAA;EACA,MAAA,EAAQ,aAAA,CAAc,SAAA;AAAA;AAAA,UAGP,sBAAA,SAA+B,gBAAgB;EAC9D,OAAA;EACA,MAAA,EAAQ,cAAA;AAAA;AAAA,UAGO,0BAAA,SAAmC,gBAAgB;EAClE,OAAA;EACA,MAAA,EAAQ,oBAAA;AAAA;AAAA,UAGO,gBAAA,SAAyB,gBAAgB;EACxD,OAAA;EACA,MAAA,EAAQ,EAAA,CAAG,UAAA;AAAA;AAAA,UAGI,sBAAA,SAA+B,gBAAgB;EAC9D,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,mBACG,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,WAC5C,MAAA,CAAO,SAAA;EACf,MAAA,EAAQ,YAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/schema",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.24",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"keywords": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "github",
|
|
23
23
|
"url": "https://github.com/storm-software/powerlines.git",
|
|
24
|
-
"directory": "packages/
|
|
24
|
+
"directory": "packages/devkit/schema"
|
|
25
25
|
},
|
|
26
26
|
"funding": {
|
|
27
27
|
"type": "github",
|
|
@@ -58,11 +58,23 @@
|
|
|
58
58
|
"import": "./dist/codegen.mjs",
|
|
59
59
|
"require": "./dist/codegen.cjs"
|
|
60
60
|
},
|
|
61
|
+
"./constants": {
|
|
62
|
+
"import": "./dist/constants.mjs",
|
|
63
|
+
"require": "./dist/constants.cjs"
|
|
64
|
+
},
|
|
61
65
|
"./extract": {
|
|
62
66
|
"import": "./dist/extract.mjs",
|
|
63
67
|
"require": "./dist/extract.cjs"
|
|
64
68
|
},
|
|
69
|
+
"./helpers": {
|
|
70
|
+
"import": "./dist/helpers.mjs",
|
|
71
|
+
"require": "./dist/helpers.cjs"
|
|
72
|
+
},
|
|
65
73
|
"./jtd": { "import": "./dist/jtd.mjs", "require": "./dist/jtd.cjs" },
|
|
74
|
+
"./persistence": {
|
|
75
|
+
"import": "./dist/persistence.mjs",
|
|
76
|
+
"require": "./dist/persistence.cjs"
|
|
77
|
+
},
|
|
66
78
|
"./reflection": {
|
|
67
79
|
"import": "./dist/reflection.mjs",
|
|
68
80
|
"require": "./dist/reflection.cjs"
|
|
@@ -84,9 +96,9 @@
|
|
|
84
96
|
"typings": "dist/index.d.mts",
|
|
85
97
|
"files": ["dist"],
|
|
86
98
|
"dependencies": {
|
|
87
|
-
"@powerlines/core": "^0.
|
|
88
|
-
"@powerlines/deepkit": "^0.
|
|
89
|
-
"@powerlines/unplugin": "^0.0.
|
|
99
|
+
"@powerlines/core": "^0.15.22",
|
|
100
|
+
"@powerlines/deepkit": "^0.9.21",
|
|
101
|
+
"@powerlines/unplugin": "^0.0.37",
|
|
90
102
|
"@standard-schema/spec": "^1.1.0",
|
|
91
103
|
"@stryke/hash": "^0.13.29",
|
|
92
104
|
"@stryke/helpers": "^0.10.16",
|
|
@@ -101,9 +113,9 @@
|
|
|
101
113
|
"typescript": "^6.0.3",
|
|
102
114
|
"untyped": "^1.5.2"
|
|
103
115
|
},
|
|
104
|
-
"devDependencies": { "@types/node": "^25.
|
|
116
|
+
"devDependencies": { "@types/node": "^25.9.0", "zod": "^4.4.3" },
|
|
105
117
|
"peerDependencies": { "zod": "^3.25.0 || ^4.0.0" },
|
|
106
118
|
"peerDependenciesMeta": { "zod": { "optional": true } },
|
|
107
119
|
"publishConfig": { "access": "public" },
|
|
108
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "7fb37a42aa27f6cbc6b7412e259d0f7a79bac8ed"
|
|
109
121
|
}
|