@powerlines/schema 0.11.15 → 0.11.17

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/extract.cjs CHANGED
@@ -11,6 +11,7 @@ let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-pl
11
11
  let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
12
12
  let _stryke_hash = require("@stryke/hash");
13
13
  let _stryke_json = require("@stryke/json");
14
+ let _stryke_path_join = require("@stryke/path/join");
14
15
  let _stryke_type_checks = require("@stryke/type-checks");
15
16
  let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
16
17
  let _stryke_zod = require("@stryke/zod");
@@ -199,6 +200,7 @@ async function extractSchema(context, input, options = {}) {
199
200
  };
200
201
  let source;
201
202
  const variant = extractVariant(input);
203
+ const hash = extractHash(variant, input);
202
204
  if (variant === "type-definition") {
203
205
  const resolved = await require_resolve.resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
204
206
  reflection: "default",
@@ -218,7 +220,7 @@ async function extractSchema(context, input, options = {}) {
218
220
  variant,
219
221
  source,
220
222
  schema: await extractSchemaSchema(source.schema, source.variant),
221
- hash: extractHash(variant, input)
223
+ hash
222
224
  };
223
225
  }
224
226
  /**
@@ -250,7 +252,23 @@ async function extractSchema(context, input, options = {}) {
250
252
  * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.
251
253
  */
252
254
  async function extract(context, input, options = {}) {
253
- return await extractSchema(context, input, options);
255
+ if (require_type_checks.isExtractedSchema(input) || require_type_checks.isSchema(input)) return input;
256
+ const variant = extractVariant(input);
257
+ const hash = extractHash(variant, input);
258
+ const cacheFilePath = (0, _stryke_path_join.joinPaths)(context.cachePath, "schemas", `${hash}.json`);
259
+ let result;
260
+ if (context.config.skipCache !== true && context.fs.existsSync(cacheFilePath)) {
261
+ const schema = await context.fs.read(cacheFilePath);
262
+ if (schema) result = {
263
+ variant,
264
+ hash,
265
+ schema: JSON.parse(schema)
266
+ };
267
+ }
268
+ result ??= await extractSchema(context, input, options);
269
+ if (!result?.schema) throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`);
270
+ if (context.config.skipCache !== true) await context.fs.write(cacheFilePath, JSON.stringify(result.schema));
271
+ return result;
254
272
  }
255
273
 
256
274
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAmEA;iBAAgB,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA;;;;;;;;;AA8BT;iBAAgB,iBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CAAc,SAAA;;;;;;;;;;iBAiBnB,iBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,MAAA,YAAkB,aAAA,CAAc,SAAA;;;;;;;;iBAsClB,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAA;;;;AA1CH;;;;iBAuEgB,cAAA,CAAe,KAAA,EAAO,WAAA,GAAc,kBAAA;;;;;;;;;iBAgB9B,mBAAA,mBACF,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CAEpD,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,aAAA,CAAc,SAAA;;;;;;;;AApDzB;iBA6FgB,aAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,OAAA,EAAS,mBAAA,EAAqB,KAAA,EAAO,iBAAA,GAAoB,YAAA;;;;;;;;AAhE3D;;;;;;;;;AAgBA;;;;iBAgHsB,aAAA,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gB,cAAA,CAAe,KAAA,EAAO,WAAA,GAAc,kBAAA;;;;;;;;;iBAgB9B,mBAAA,mBACF,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CAEpD,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,aAAA,CAAc,SAAA;;;;;;;;AApDzB;iBA6FgB,aAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,OAAA,EAAS,mBAAA,EAAqB,KAAA,EAAO,iBAAA,GAAoB,YAAA;;;;;;;;AAhE3D;;;;;;;;;AAgBA;;;;iBAgHsB,aAAA,mBACF,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,oBACnC,OAAA,GAAU,OAAA,CAAA,CAE3B,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;AAzE3B;;;;;iBAoKsB,OAAA,mBACF,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,oBACnC,OAAA,GAAU,OAAA,CAAA,CAE3B,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,SAAA"}
package/dist/extract.mjs CHANGED
@@ -8,6 +8,7 @@ import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
8
8
  import { isType, stringifyType } from "@powerlines/deepkit/vendor/type";
9
9
  import { murmurhash } from "@stryke/hash";
10
10
  import { isJsonSchemaObjectType, isStandardJsonSchema } from "@stryke/json";
11
+ import { joinPaths } from "@stryke/path/join";
11
12
  import { isSetString } from "@stryke/type-checks";
12
13
  import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object";
13
14
  import { extractJsonSchema as extractJsonSchema$1, isZod3Type } from "@stryke/zod";
@@ -196,6 +197,7 @@ async function extractSchema(context, input, options = {}) {
196
197
  };
197
198
  let source;
198
199
  const variant = extractVariant(input);
200
+ const hash = extractHash(variant, input);
199
201
  if (variant === "type-definition") {
200
202
  const resolved = await resolve(context, input, defu(options, { plugins: [esbuildPlugin(context, {
201
203
  reflection: "default",
@@ -215,7 +217,7 @@ async function extractSchema(context, input, options = {}) {
215
217
  variant,
216
218
  source,
217
219
  schema: await extractSchemaSchema(source.schema, source.variant),
218
- hash: extractHash(variant, input)
220
+ hash
219
221
  };
220
222
  }
221
223
  /**
@@ -247,7 +249,23 @@ async function extractSchema(context, input, options = {}) {
247
249
  * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.
248
250
  */
249
251
  async function extract(context, input, options = {}) {
250
- return await extractSchema(context, input, options);
252
+ if (isExtractedSchema(input) || isSchema(input)) return input;
253
+ const variant = extractVariant(input);
254
+ const hash = extractHash(variant, input);
255
+ const cacheFilePath = joinPaths(context.cachePath, "schemas", `${hash}.json`);
256
+ let result;
257
+ if (context.config.skipCache !== true && context.fs.existsSync(cacheFilePath)) {
258
+ const schema = await context.fs.read(cacheFilePath);
259
+ if (schema) result = {
260
+ variant,
261
+ hash,
262
+ schema: JSON.parse(schema)
263
+ };
264
+ }
265
+ result ??= await extractSchema(context, input, options);
266
+ if (!result?.schema) throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`);
267
+ if (context.config.skipCache !== true) await context.fs.write(cacheFilePath, JSON.stringify(result.schema));
268
+ return result;
251
269
  }
252
270
 
253
271
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"extract.mjs","names":["isSetObject","extractJsonSchemaZod"],"sources":["../src/extract.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 type { Context } from \"@powerlines/core\";\nimport { isTypeDefinition } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { isType, stringifyType, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { murmurhash } from \"@stryke/hash\";\nimport {\n isJsonSchemaObjectType,\n isStandardJsonSchema,\n JsonSchemaType\n} from \"@stryke/json\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport * as z3 from \"zod/v3\";\nimport { jsonSchemaToJtd } from \"./jtd\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isExtractedSchema,\n isJTDSchema,\n isSchema,\n isUntypedInput,\n isUntypedSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchemaLike,\n JTDSchemaType,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaMetadata,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n TypeDefinitionReference,\n UntypedInputObject,\n UntypedSchema\n} from \"./types\";\n\n/**\n * Creates a hash string for a given schema definition input. The function checks the type of the input and generates a hash based on its content. If the input is a Zod schema, it hashes the JSON representation of its internal definition. If the input is a Standard JSON Schema, it hashes the JSON representation of its internal standard schema. If the input is already a JSON Schema object, it hashes its JSON representation directly. If the input is a reflected Deepkit Type object, it hashes its JSON representation. The resulting hash string can be used for caching or comparison purposes.\n */\nexport function extractHash(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isStandardJsonSchema(input)) {\n return murmurhash({ variant, input: input[\"~standard\"] });\n } else if (isJsonSchemaObjectType(input)) {\n return murmurhash({ variant, input });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\n }\n }\n\n throw new Error(\n `Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.\n *\n * @remarks\n * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.\n *\n * @param reflection - The reflected Deepkit Type to convert.\n * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.\n */\nexport function extractReflection<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema<TMetadata>(reflection);\n}\n\n/**\n * Extracts a JSON Type Definition (RFC 8927) schema from a given schema definition, if possible.\n *\n * @remarks\n * This function checks if the provided input is a Zod schema, a Standard JSON Schema, or already a JSON Schema object, extracts a JSON Schema fragment via the appropriate adapter (Zod and Standard Schema produce draft-07 fragments), and then converts that fragment into a valid JTD form suitable for AJV's JTD validator.\n *\n * @param schema - The schema definition to extract from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.\n * @returns The extracted JTD schema if successful, otherwise undefined.\n */\nexport function extractJsonSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(schema: unknown): JTDSchemaType<TMetadata> | undefined {\n if (\n isSetObject(schema) &&\n (isZod3Type(schema) ||\n isStandardJsonSchema(schema) ||\n isJsonSchemaObjectType(schema) ||\n isUntypedInput(schema) ||\n isUntypedSchema(schema))\n ) {\n let jsonSchema: unknown;\n if (isZod3Type(schema)) {\n jsonSchema = extractJsonSchemaZod(schema);\n } else if (isStandardJsonSchema(schema)) {\n jsonSchema = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n } else if (isUntypedInput(schema)) {\n jsonSchema = schema.$schema;\n } else {\n jsonSchema = schema;\n }\n\n const jtd = jsonSchemaToJtd<TMetadata>(jsonSchema as JsonSchemaLike);\n if (jtd) {\n return jtd;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param input - The input object to extract the schema definition from.\n * @returns A `Schema` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJTDSchema(input)) {\n return \"jtd-schema\";\n } else if (isJsonSchemaObjectType(input)) {\n return \"json-schema\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInput(input) || isUntypedSchema(input)) {\n return \"untyped\";\n }\n }\n\n throw new Error(\n `Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param input - The input object to extract the schema definition from.\n * @returns A `Schema` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isTypeDefinition(input)) {\n return \"type-definition\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts a JSON Schema object from a given schema definition input. The input can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding JSON Schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns the extracted JSON Schema if successful; otherwise, it throws an error.\n *\n * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.\n * @param variant - The variant of the schema definition to extract.\n * @returns The extracted JSON Schema if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport async function extractSchemaSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JTDSchemaType<TMetadata>> {\n if (isExtractedSchema<TMetadata>(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JTDSchemaType<TMetadata> | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\"\n ) {\n const jsonSchema = extractJsonSchema<TMetadata>(input);\n if (jsonSchema) {\n schema = jsonSchemaToJtd<TMetadata>(jsonSchema);\n }\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection<TMetadata>(input as Type);\n } else if (resolvedVariant === \"jtd-schema\") {\n schema = input as JTDSchemaType<TMetadata>;\n }\n\n if (schema) {\n return schema;\n }\n\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param variant - The variant of the schema definition to extract.\n * @param input - The input object to extract the schema definition from.\n * @returns A `Schema` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractSource<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource {\n if (variant === \"zod3\") {\n return {\n hash: extractHash(variant, input),\n variant: \"zod3\",\n schema: input as z3.ZodTypeAny\n };\n } else if (variant === \"untyped\") {\n return {\n hash: extractHash(variant, input),\n variant: \"untyped\",\n schema: input as UntypedInputObject | UntypedSchema\n };\n } else if (variant === \"standard-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"standard-schema\",\n schema: input as StandardJSONSchemaV1\n };\n } else if (variant === \"json-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"json-schema\",\n schema: input as JsonSchemaType\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\n };\n } else if (variant === \"jtd-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"jtd-schema\",\n schema: input as JTDSchemaType<TMetadata>\n };\n }\n\n throw new Error(\n `Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extractSchema(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extractSchema(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extractSchema(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extractSchema(context, reflectionType);\n * ```\n *\n * @param context - The plugin context used for resolving the schema definition input.\n * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.\n * @param options - Optional overrides for the ESBuild configuration used during resolution.\n * @returns A promise that resolves to a {@link ExtractedSchema} containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.\n */\nexport async function extractSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>,\n TContext extends Context = Context\n>(\n context: TContext,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<ExtractedSchema<TMetadata>> {\n if (isExtractedSchema<TMetadata>(input)) {\n return input;\n }\n\n if (isSchema<TMetadata>(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"jtd-schema\", input.schema),\n variant: \"jtd-schema\",\n schema: input.schema\n }\n };\n }\n\n let source: SchemaSource;\n\n const variant = extractVariant(input);\n if (variant === \"type-definition\") {\n const resolved = await resolve<SchemaSourceInput>(\n context,\n input as TypeDefinitionReference,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"jtd-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"reflection\"\n ].includes(variant)\n ) {\n source = extractSource(variant, input as SchemaSourceInput);\n } else {\n throw new Error(\n `Invalid schema definition input \"${\n variant\n }\". The variant must be one of \"type-definition\", \"json-schema\", \"jtd-schema\", \"standard-schema\", \"zod3\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchemaSchema<TMetadata>(source.schema, source.variant),\n hash: extractHash(variant, input)\n };\n}\n\n/**\n * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://github.com/colinhacks/zod\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n * @see https://github.com/unjs/untyped\n * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html\n *\n * @param context - The {@link Context | context} used for resolving the {@link Schema | schema} definition input.\n * @param input - The input object or string to extract the {@link Schema | schema} from. This can be {@link TypeDefinitionReference | a string that references a Typescript module}, a [Zod v3 schema](https://github.com/colinhacks/zod), any type that adheres to [the Standard JSON Schema specification](https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec), a [JSON Schema object](https://json-schema.org/), a [JTD schema object](https://ajv.js.org/json-type-definition.html), an [untyped schema](https://github.com/unjs/untyped), or a [TypeScript type reflection](https://deepkit.io/en/documentation/runtime-types/reflection).\n * @param options - Optional overrides for the [ESBuild configuration](https://esbuild.github.io/api/#general-options) used during resolution.\n * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.\n */\nexport async function extract<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>,\n TContext extends Context = Context\n>(\n context: TContext,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<Schema<TMetadata>> {\n const result = await extractSchema<TMetadata>(context, input, options);\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmEA,SAAgB,YACd,SACA,OACQ;AACR,KAAI,YAAY,MAAM,CACpB,QAAO,WAAW;EAAE;EAAS;EAAO,CAAC;UAC5BA,cAAY,MAAM,EAC3B;MAAI,WAAW,MAAM,CACnB,QAAO,WAAW;GAAE;GAAS,OAAO,MAAM;GAAM,CAAC;WACxC,qBAAqB,MAAM,CACpC,QAAO,WAAW;GAAE;GAAS,OAAO,MAAM;GAAc,CAAC;WAChD,uBAAuB,MAAM,CACtC,QAAO,WAAW;GAAE;GAAS;GAAO,CAAC;WAC5B,OAAO,MAAM,CACtB,QAAO,WAAW;GAAE;GAAS,OAAO,cAAc,MAAM;GAAE,CAAC;;AAI/D,OAAM,IAAI,MACR,6LACD;;;;;;;;;;;AAYH,SAAgB,kBAEd,YAAwD;AACxD,KAAI,CAAC,OAAO,WAAW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oCACE,QACD,sIACF;AAGH,QAAO;EACL;EACA;EACA,QAAQ,MAAM,oBAA+B,OAAO,QAAQ,OAAO,QAAQ;EAC3E,MAAM,YAAY,SAAS,MAAM;EAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BH,eAAsB,QAIpB,SACA,OACA,UAAiC,EAAE,EACP;AAG5B,QAAO,MAFc,cAAyB,SAAS,OAAO,QAAQ"}
1
+ {"version":3,"file":"extract.mjs","names":["isSetObject","extractJsonSchemaZod"],"sources":["../src/extract.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 type { Context } from \"@powerlines/core\";\nimport { isTypeDefinition } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { isType, stringifyType, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { murmurhash } from \"@stryke/hash\";\nimport {\n isJsonSchemaObjectType,\n isStandardJsonSchema,\n JsonSchemaType\n} from \"@stryke/json\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport * as z3 from \"zod/v3\";\nimport { jsonSchemaToJtd } from \"./jtd\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isExtractedSchema,\n isJTDSchema,\n isSchema,\n isUntypedInput,\n isUntypedSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchemaLike,\n JTDSchemaType,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaMetadata,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n TypeDefinitionReference,\n UntypedInputObject,\n UntypedSchema\n} from \"./types\";\n\n/**\n * Creates a hash string for a given schema definition input. The function checks the type of the input and generates a hash based on its content. If the input is a Zod schema, it hashes the JSON representation of its internal definition. If the input is a Standard JSON Schema, it hashes the JSON representation of its internal standard schema. If the input is already a JSON Schema object, it hashes its JSON representation directly. If the input is a reflected Deepkit Type object, it hashes its JSON representation. The resulting hash string can be used for caching or comparison purposes.\n */\nexport function extractHash(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isStandardJsonSchema(input)) {\n return murmurhash({ variant, input: input[\"~standard\"] });\n } else if (isJsonSchemaObjectType(input)) {\n return murmurhash({ variant, input });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\n }\n }\n\n throw new Error(\n `Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.\n *\n * @remarks\n * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.\n *\n * @param reflection - The reflected Deepkit Type to convert.\n * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.\n */\nexport function extractReflection<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema<TMetadata>(reflection);\n}\n\n/**\n * Extracts a JSON Type Definition (RFC 8927) schema from a given schema definition, if possible.\n *\n * @remarks\n * This function checks if the provided input is a Zod schema, a Standard JSON Schema, or already a JSON Schema object, extracts a JSON Schema fragment via the appropriate adapter (Zod and Standard Schema produce draft-07 fragments), and then converts that fragment into a valid JTD form suitable for AJV's JTD validator.\n *\n * @param schema - The schema definition to extract from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.\n * @returns The extracted JTD schema if successful, otherwise undefined.\n */\nexport function extractJsonSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(schema: unknown): JTDSchemaType<TMetadata> | undefined {\n if (\n isSetObject(schema) &&\n (isZod3Type(schema) ||\n isStandardJsonSchema(schema) ||\n isJsonSchemaObjectType(schema) ||\n isUntypedInput(schema) ||\n isUntypedSchema(schema))\n ) {\n let jsonSchema: unknown;\n if (isZod3Type(schema)) {\n jsonSchema = extractJsonSchemaZod(schema);\n } else if (isStandardJsonSchema(schema)) {\n jsonSchema = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n } else if (isUntypedInput(schema)) {\n jsonSchema = schema.$schema;\n } else {\n jsonSchema = schema;\n }\n\n const jtd = jsonSchemaToJtd<TMetadata>(jsonSchema as JsonSchemaLike);\n if (jtd) {\n return jtd;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param input - The input object to extract the schema definition from.\n * @returns A `Schema` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJTDSchema(input)) {\n return \"jtd-schema\";\n } else if (isJsonSchemaObjectType(input)) {\n return \"json-schema\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInput(input) || isUntypedSchema(input)) {\n return \"untyped\";\n }\n }\n\n throw new Error(\n `Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param input - The input object to extract the schema definition from.\n * @returns A `Schema` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isTypeDefinition(input)) {\n return \"type-definition\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts a JSON Schema object from a given schema definition input. The input can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding JSON Schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns the extracted JSON Schema if successful; otherwise, it throws an error.\n *\n * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.\n * @param variant - The variant of the schema definition to extract.\n * @returns The extracted JSON Schema if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport async function extractSchemaSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JTDSchemaType<TMetadata>> {\n if (isExtractedSchema<TMetadata>(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JTDSchemaType<TMetadata> | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\"\n ) {\n const jsonSchema = extractJsonSchema<TMetadata>(input);\n if (jsonSchema) {\n schema = jsonSchemaToJtd<TMetadata>(jsonSchema);\n }\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection<TMetadata>(input as Type);\n } else if (resolvedVariant === \"jtd-schema\") {\n schema = input as JTDSchemaType<TMetadata>;\n }\n\n if (schema) {\n return schema;\n }\n\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param variant - The variant of the schema definition to extract.\n * @param input - The input object to extract the schema definition from.\n * @returns A `Schema` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractSource<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource {\n if (variant === \"zod3\") {\n return {\n hash: extractHash(variant, input),\n variant: \"zod3\",\n schema: input as z3.ZodTypeAny\n };\n } else if (variant === \"untyped\") {\n return {\n hash: extractHash(variant, input),\n variant: \"untyped\",\n schema: input as UntypedInputObject | UntypedSchema\n };\n } else if (variant === \"standard-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"standard-schema\",\n schema: input as StandardJSONSchemaV1\n };\n } else if (variant === \"json-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"json-schema\",\n schema: input as JsonSchemaType\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\n };\n } else if (variant === \"jtd-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"jtd-schema\",\n schema: input as JTDSchemaType<TMetadata>\n };\n }\n\n throw new Error(\n `Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extractSchema(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extractSchema(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extractSchema(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extractSchema(context, reflectionType);\n * ```\n *\n * @param context - The plugin context used for resolving the schema definition input.\n * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.\n * @param options - Optional overrides for the ESBuild configuration used during resolution.\n * @returns A promise that resolves to a {@link ExtractedSchema} containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.\n */\nexport async function extractSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>,\n TContext extends Context = Context\n>(\n context: TContext,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<ExtractedSchema<TMetadata>> {\n if (isExtractedSchema<TMetadata>(input)) {\n return input;\n }\n\n if (isSchema<TMetadata>(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"jtd-schema\", input.schema),\n variant: \"jtd-schema\",\n schema: input.schema\n }\n };\n }\n\n let source: SchemaSource;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n if (variant === \"type-definition\") {\n const resolved = await resolve<SchemaSourceInput>(\n context,\n input as TypeDefinitionReference,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"jtd-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"reflection\"\n ].includes(variant)\n ) {\n source = extractSource(variant, input as SchemaSourceInput);\n } else {\n throw new Error(\n `Invalid schema definition input \"${\n variant\n }\". The variant must be one of \"type-definition\", \"json-schema\", \"jtd-schema\", \"standard-schema\", \"zod3\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchemaSchema<TMetadata>(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://github.com/colinhacks/zod\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n * @see https://github.com/unjs/untyped\n * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html\n *\n * @param context - The {@link Context | context} used for resolving the {@link Schema | schema} definition input.\n * @param input - The input object or string to extract the {@link Schema | schema} from. This can be {@link TypeDefinitionReference | a string that references a Typescript module}, a [Zod v3 schema](https://github.com/colinhacks/zod), any type that adheres to [the Standard JSON Schema specification](https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec), a [JSON Schema object](https://json-schema.org/), a [JTD schema object](https://ajv.js.org/json-type-definition.html), an [untyped schema](https://github.com/unjs/untyped), or a [TypeScript type reflection](https://deepkit.io/en/documentation/runtime-types/reflection).\n * @param options - Optional overrides for the [ESBuild configuration](https://esbuild.github.io/api/#general-options) used during resolution.\n * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.\n */\nexport async function extract<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>,\n TContext extends Context = Context\n>(\n context: TContext,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<Schema<TMetadata>> {\n if (isExtractedSchema<TMetadata>(input) || isSchema<TMetadata>(input)) {\n return input;\n }\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n const cacheFilePath = joinPaths(context.cachePath, \"schemas\", `${hash}.json`);\n\n let result: Schema<TMetadata> | undefined;\n if (\n context.config.skipCache !== true &&\n context.fs.existsSync(cacheFilePath)\n ) {\n const schema = await context.fs.read(cacheFilePath);\n if (schema) {\n result = {\n variant,\n hash,\n schema: JSON.parse(schema) as JTDSchemaType<TMetadata>\n };\n }\n }\n\n result ??= await extractSchema<TMetadata>(context, input, options);\n if (!result?.schema) {\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await context.fs.write(cacheFilePath, JSON.stringify(result.schema));\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,YACd,SACA,OACQ;AACR,KAAI,YAAY,MAAM,CACpB,QAAO,WAAW;EAAE;EAAS;EAAO,CAAC;UAC5BA,cAAY,MAAM,EAC3B;MAAI,WAAW,MAAM,CACnB,QAAO,WAAW;GAAE;GAAS,OAAO,MAAM;GAAM,CAAC;WACxC,qBAAqB,MAAM,CACpC,QAAO,WAAW;GAAE;GAAS,OAAO,MAAM;GAAc,CAAC;WAChD,uBAAuB,MAAM,CACtC,QAAO,WAAW;GAAE;GAAS;GAAO,CAAC;WAC5B,OAAO,MAAM,CACtB,QAAO,WAAW;GAAE;GAAS,OAAO,cAAc,MAAM;GAAE,CAAC;;AAI/D,OAAM,IAAI,MACR,6LACD;;;;;;;;;;;AAYH,SAAgB,kBAEd,YAAwD;AACxD,KAAI,CAAC,OAAO,WAAW,CACrB;AAGF,QAAO,uBAAkC,WAAW;;;;;;;;;;;AAYtD,SAAgB,kBAEd,QAAuD;AACvD,KACEA,cAAY,OAAO,KAClB,WAAW,OAAO,IACjB,qBAAqB,OAAO,IAC5B,uBAAuB,OAAO,IAC9B,eAAe,OAAO,IACtB,gBAAgB,OAAO,GACzB;EACA,IAAI;AACJ,MAAI,WAAW,OAAO,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AA6B,MAAM,IAAI,SAAoB,MAAM,CACnE,QAAO;CAGT,MAAM,UAAU,eAAe,MAAM;CACrC,MAAM,OAAO,YAAY,SAAS,MAAM;CACxC,MAAM,gBAAgB,UAAU,QAAQ,WAAW,WAAW,GAAG,KAAK,OAAO;CAE7E,IAAI;AACJ,KACE,QAAQ,OAAO,cAAc,QAC7B,QAAQ,GAAG,WAAW,cAAc,EACpC;EACA,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK,cAAc;AACnD,MAAI,OACF,UAAS;GACP;GACA;GACA,QAAQ,KAAK,MAAM,OAAO;GAC3B;;AAIL,YAAW,MAAM,cAAyB,SAAS,OAAO,QAAQ;AAClE,KAAI,CAAC,QAAQ,OACX,OAAM,IAAI,MACR,+MACD;AAGH,KAAI,QAAQ,OAAO,cAAc,KAC/B,OAAM,QAAQ,GAAG,MAAM,eAAe,KAAK,UAAU,OAAO,OAAO,CAAC;AAGtE,QAAO"}
@@ -0,0 +1,52 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_type_checks = require('./type-checks.cjs');
4
+ let defu = require("defu");
5
+ let _stryke_type_checks = require("@stryke/type-checks");
6
+
7
+ //#region src/helpers.ts
8
+ /**
9
+ * A helper function to extract the properties from a JTD object schema. This function takes an {@link ObjectSchema} as input and returns a record of its properties, where each key is the property name and the value is the corresponding JTD schema type along with an `optional` flag indicating whether the property is optional (i.e., defined in `optionalProperties`) or required (i.e., defined in `properties`). The function checks both `properties` and `optionalProperties` of the JTD schema to construct the resulting record.
10
+ *
11
+ * @param obj - The {@link ObjectSchema} from which to extract the properties.
12
+ * @returns A record of the properties defined in the JTD object schema, where each key is the property name and the value is an object containing the JTD schema type and an `optional` flag.
13
+ */
14
+ function getProperties(obj) {
15
+ const properties = {};
16
+ const schema = require_type_checks.isObjectSchema(obj) ? obj.schema : obj;
17
+ if ("optionalProperties" in schema && (0, _stryke_type_checks.isSetObject)(schema.optionalProperties)) for (const [key, value] of Object.entries(schema.optionalProperties)) properties[key] = {
18
+ ...value,
19
+ optional: true
20
+ };
21
+ if ("properties" in schema && (0, _stryke_type_checks.isSetObject)(schema.properties)) for (const [key, value] of Object.entries(schema.properties)) properties[key] = {
22
+ ...value,
23
+ optional: false
24
+ };
25
+ return properties;
26
+ }
27
+ /**
28
+ * Merges multiple JTD object schemas into a single schema. This function takes an array of JTD object schemas (either {@link JTDSchemaObjectType} or {@link ObjectSchema}) and combines their properties into a single JTD object schema. The resulting schema will contain all properties from the input schemas, with optional properties marked accordingly. If there are overlapping properties between the input schemas, the function will merge them using a deep merge strategy (via `defu`) if they are both JTD object schemas; otherwise, the property from the first schema in the input array will take precedence.
29
+ *
30
+ * @remarks
31
+ * This function attempts to mimic {@link defu}'s behavior for merging objects, but with special handling for JTD schemas. When merging properties, if a property exists in multiple input schemas and is defined as a JTD object schema in all of them, the function will perform a deep merge of those schemas. If the property is not a JTD object schema in any of the input schemas, the function will simply take the first definition it encounters.
32
+ *
33
+ * @param schemas - An array of JTD object schemas to merge.
34
+ * @returns A single JTD object schema that combines the properties of all input schemas.
35
+ */
36
+ function mergeSchemas(...schemas) {
37
+ const mergedSchema = {
38
+ properties: {},
39
+ optionalProperties: {},
40
+ additionalProperties: false
41
+ };
42
+ for (const schema of schemas.reverse()) {
43
+ const properties = getProperties(schema);
44
+ for (const [key, value] of Object.entries(properties)) if (value.optional) mergedSchema.optionalProperties[key] = mergedSchema.optionalProperties[key] && require_type_checks.isJTDSchemaObject(mergedSchema.optionalProperties[key]) && require_type_checks.isJTDSchemaObject(value) ? (0, defu.defu)(mergedSchema.optionalProperties[key], value) : value;
45
+ else mergedSchema.properties[key] = mergedSchema.properties[key] && require_type_checks.isJTDSchemaObject(mergedSchema.properties[key]) && require_type_checks.isJTDSchemaObject(value) ? (0, defu.defu)(mergedSchema.properties[key], value) : value;
46
+ }
47
+ return mergedSchema;
48
+ }
49
+
50
+ //#endregion
51
+ exports.getProperties = getProperties;
52
+ exports.mergeSchemas = mergeSchemas;
@@ -0,0 +1,25 @@
1
+ import { JTDSchemaObjectType, JTDSchemaType, ObjectSchema, SchemaMetadata } from "./types.cjs";
2
+
3
+ //#region src/helpers.d.ts
4
+ /**
5
+ * A helper function to extract the properties from a JTD object schema. This function takes an {@link ObjectSchema} as input and returns a record of its properties, where each key is the property name and the value is the corresponding JTD schema type along with an `optional` flag indicating whether the property is optional (i.e., defined in `optionalProperties`) or required (i.e., defined in `properties`). The function checks both `properties` and `optionalProperties` of the JTD schema to construct the resulting record.
6
+ *
7
+ * @param obj - The {@link ObjectSchema} from which to extract the properties.
8
+ * @returns A record of the properties defined in the JTD object schema, where each key is the property name and the value is an object containing the JTD schema type and an `optional` flag.
9
+ */
10
+ declare function getProperties<TMetadata extends SchemaMetadata>(obj: ObjectSchema<TMetadata> | JTDSchemaObjectType<TMetadata>): Record<string, JTDSchemaType<TMetadata> & {
11
+ optional: boolean;
12
+ }>;
13
+ /**
14
+ * Merges multiple JTD object schemas into a single schema. This function takes an array of JTD object schemas (either {@link JTDSchemaObjectType} or {@link ObjectSchema}) and combines their properties into a single JTD object schema. The resulting schema will contain all properties from the input schemas, with optional properties marked accordingly. If there are overlapping properties between the input schemas, the function will merge them using a deep merge strategy (via `defu`) if they are both JTD object schemas; otherwise, the property from the first schema in the input array will take precedence.
15
+ *
16
+ * @remarks
17
+ * This function attempts to mimic {@link defu}'s behavior for merging objects, but with special handling for JTD schemas. When merging properties, if a property exists in multiple input schemas and is defined as a JTD object schema in all of them, the function will perform a deep merge of those schemas. If the property is not a JTD object schema in any of the input schemas, the function will simply take the first definition it encounters.
18
+ *
19
+ * @param schemas - An array of JTD object schemas to merge.
20
+ * @returns A single JTD object schema that combines the properties of all input schemas.
21
+ */
22
+ declare function mergeSchemas<TMetadata extends SchemaMetadata>(...schemas: (JTDSchemaObjectType<TMetadata> | ObjectSchema<TMetadata>)[]): JTDSchemaObjectType<TMetadata>;
23
+ //#endregion
24
+ export { getProperties, mergeSchemas };
25
+ //# sourceMappingURL=helpers.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.cts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;;;AAkCA;;;;iBAAgB,aAAA,mBAAgC,cAAA,CAAA,CAC9C,GAAA,EAAK,YAAA,CAAa,SAAA,IAAa,mBAAA,CAAoB,SAAA,IAClD,MAAA,SAAe,aAAA,CAAc,SAAA;EAAe,QAAA;AAAA;;;;;;;;;;iBAkC/B,YAAA,mBAA+B,cAAA,CAAA,CAAA,GAC1C,OAAA,GAAU,mBAAA,CAAoB,SAAA,IAAa,YAAA,CAAa,SAAA,OAC1D,mBAAA,CAAoB,SAAA"}
@@ -0,0 +1,25 @@
1
+ import { JTDSchemaObjectType, JTDSchemaType, ObjectSchema, SchemaMetadata } from "./types.mjs";
2
+
3
+ //#region src/helpers.d.ts
4
+ /**
5
+ * A helper function to extract the properties from a JTD object schema. This function takes an {@link ObjectSchema} as input and returns a record of its properties, where each key is the property name and the value is the corresponding JTD schema type along with an `optional` flag indicating whether the property is optional (i.e., defined in `optionalProperties`) or required (i.e., defined in `properties`). The function checks both `properties` and `optionalProperties` of the JTD schema to construct the resulting record.
6
+ *
7
+ * @param obj - The {@link ObjectSchema} from which to extract the properties.
8
+ * @returns A record of the properties defined in the JTD object schema, where each key is the property name and the value is an object containing the JTD schema type and an `optional` flag.
9
+ */
10
+ declare function getProperties<TMetadata extends SchemaMetadata>(obj: ObjectSchema<TMetadata> | JTDSchemaObjectType<TMetadata>): Record<string, JTDSchemaType<TMetadata> & {
11
+ optional: boolean;
12
+ }>;
13
+ /**
14
+ * Merges multiple JTD object schemas into a single schema. This function takes an array of JTD object schemas (either {@link JTDSchemaObjectType} or {@link ObjectSchema}) and combines their properties into a single JTD object schema. The resulting schema will contain all properties from the input schemas, with optional properties marked accordingly. If there are overlapping properties between the input schemas, the function will merge them using a deep merge strategy (via `defu`) if they are both JTD object schemas; otherwise, the property from the first schema in the input array will take precedence.
15
+ *
16
+ * @remarks
17
+ * This function attempts to mimic {@link defu}'s behavior for merging objects, but with special handling for JTD schemas. When merging properties, if a property exists in multiple input schemas and is defined as a JTD object schema in all of them, the function will perform a deep merge of those schemas. If the property is not a JTD object schema in any of the input schemas, the function will simply take the first definition it encounters.
18
+ *
19
+ * @param schemas - An array of JTD object schemas to merge.
20
+ * @returns A single JTD object schema that combines the properties of all input schemas.
21
+ */
22
+ declare function mergeSchemas<TMetadata extends SchemaMetadata>(...schemas: (JTDSchemaObjectType<TMetadata> | ObjectSchema<TMetadata>)[]): JTDSchemaObjectType<TMetadata>;
23
+ //#endregion
24
+ export { getProperties, mergeSchemas };
25
+ //# sourceMappingURL=helpers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;;;AAkCA;;;;iBAAgB,aAAA,mBAAgC,cAAA,CAAA,CAC9C,GAAA,EAAK,YAAA,CAAa,SAAA,IAAa,mBAAA,CAAoB,SAAA,IAClD,MAAA,SAAe,aAAA,CAAc,SAAA;EAAe,QAAA;AAAA;;;;;;;;;;iBAkC/B,YAAA,mBAA+B,cAAA,CAAA,CAAA,GAC1C,OAAA,GAAU,mBAAA,CAAoB,SAAA,IAAa,YAAA,CAAa,SAAA,OAC1D,mBAAA,CAAoB,SAAA"}
@@ -0,0 +1,50 @@
1
+ import { isJTDSchemaObject, isObjectSchema } from "./type-checks.mjs";
2
+ import { defu as defu$1 } from "defu";
3
+ import { isSetObject } from "@stryke/type-checks";
4
+
5
+ //#region src/helpers.ts
6
+ /**
7
+ * A helper function to extract the properties from a JTD object schema. This function takes an {@link ObjectSchema} as input and returns a record of its properties, where each key is the property name and the value is the corresponding JTD schema type along with an `optional` flag indicating whether the property is optional (i.e., defined in `optionalProperties`) or required (i.e., defined in `properties`). The function checks both `properties` and `optionalProperties` of the JTD schema to construct the resulting record.
8
+ *
9
+ * @param obj - The {@link ObjectSchema} from which to extract the properties.
10
+ * @returns A record of the properties defined in the JTD object schema, where each key is the property name and the value is an object containing the JTD schema type and an `optional` flag.
11
+ */
12
+ function getProperties(obj) {
13
+ const properties = {};
14
+ const schema = isObjectSchema(obj) ? obj.schema : obj;
15
+ if ("optionalProperties" in schema && isSetObject(schema.optionalProperties)) for (const [key, value] of Object.entries(schema.optionalProperties)) properties[key] = {
16
+ ...value,
17
+ optional: true
18
+ };
19
+ if ("properties" in schema && isSetObject(schema.properties)) for (const [key, value] of Object.entries(schema.properties)) properties[key] = {
20
+ ...value,
21
+ optional: false
22
+ };
23
+ return properties;
24
+ }
25
+ /**
26
+ * Merges multiple JTD object schemas into a single schema. This function takes an array of JTD object schemas (either {@link JTDSchemaObjectType} or {@link ObjectSchema}) and combines their properties into a single JTD object schema. The resulting schema will contain all properties from the input schemas, with optional properties marked accordingly. If there are overlapping properties between the input schemas, the function will merge them using a deep merge strategy (via `defu`) if they are both JTD object schemas; otherwise, the property from the first schema in the input array will take precedence.
27
+ *
28
+ * @remarks
29
+ * This function attempts to mimic {@link defu}'s behavior for merging objects, but with special handling for JTD schemas. When merging properties, if a property exists in multiple input schemas and is defined as a JTD object schema in all of them, the function will perform a deep merge of those schemas. If the property is not a JTD object schema in any of the input schemas, the function will simply take the first definition it encounters.
30
+ *
31
+ * @param schemas - An array of JTD object schemas to merge.
32
+ * @returns A single JTD object schema that combines the properties of all input schemas.
33
+ */
34
+ function mergeSchemas(...schemas) {
35
+ const mergedSchema = {
36
+ properties: {},
37
+ optionalProperties: {},
38
+ additionalProperties: false
39
+ };
40
+ for (const schema of schemas.reverse()) {
41
+ const properties = getProperties(schema);
42
+ for (const [key, value] of Object.entries(properties)) if (value.optional) mergedSchema.optionalProperties[key] = mergedSchema.optionalProperties[key] && isJTDSchemaObject(mergedSchema.optionalProperties[key]) && isJTDSchemaObject(value) ? defu$1(mergedSchema.optionalProperties[key], value) : value;
43
+ else mergedSchema.properties[key] = mergedSchema.properties[key] && isJTDSchemaObject(mergedSchema.properties[key]) && isJTDSchemaObject(value) ? defu$1(mergedSchema.properties[key], value) : value;
44
+ }
45
+ return mergedSchema;
46
+ }
47
+
48
+ //#endregion
49
+ export { getProperties, mergeSchemas };
50
+ //# sourceMappingURL=helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.mjs","names":["defu"],"sources":["../src/helpers.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 { isSetObject } from \"@stryke/type-checks\";\nimport { defu } from \"defu\";\nimport { isJTDSchemaObject, isObjectSchema } from \"./type-checks\";\nimport {\n JTDSchemaObjectType,\n JTDSchemaType,\n ObjectSchema,\n SchemaMetadata\n} from \"./types\";\n\n/**\n * A helper function to extract the properties from a JTD object schema. This function takes an {@link ObjectSchema} as input and returns a record of its properties, where each key is the property name and the value is the corresponding JTD schema type along with an `optional` flag indicating whether the property is optional (i.e., defined in `optionalProperties`) or required (i.e., defined in `properties`). The function checks both `properties` and `optionalProperties` of the JTD schema to construct the resulting record.\n *\n * @param obj - The {@link ObjectSchema} from which to extract the properties.\n * @returns A record of the properties defined in the JTD object schema, where each key is the property name and the value is an object containing the JTD schema type and an `optional` flag.\n */\nexport function getProperties<TMetadata extends SchemaMetadata>(\n obj: ObjectSchema<TMetadata> | JTDSchemaObjectType<TMetadata>\n): Record<string, JTDSchemaType<TMetadata> & { optional: boolean }> {\n const properties: Record<\n string,\n JTDSchemaType<TMetadata> & { optional: boolean }\n > = {};\n\n const schema = isObjectSchema(obj) ? obj.schema : obj;\n if (\n \"optionalProperties\" in schema &&\n isSetObject(schema.optionalProperties)\n ) {\n for (const [key, value] of Object.entries(schema.optionalProperties)) {\n properties[key] = { ...value, optional: true };\n }\n }\n\n if (\"properties\" in schema && isSetObject(schema.properties)) {\n for (const [key, value] of Object.entries(schema.properties)) {\n properties[key] = { ...value, optional: false };\n }\n }\n\n return properties;\n}\n\n/**\n * Merges multiple JTD object schemas into a single schema. This function takes an array of JTD object schemas (either {@link JTDSchemaObjectType} or {@link ObjectSchema}) and combines their properties into a single JTD object schema. The resulting schema will contain all properties from the input schemas, with optional properties marked accordingly. If there are overlapping properties between the input schemas, the function will merge them using a deep merge strategy (via `defu`) if they are both JTD object schemas; otherwise, the property from the first schema in the input array will take precedence.\n *\n * @remarks\n * This function attempts to mimic {@link defu}'s behavior for merging objects, but with special handling for JTD schemas. When merging properties, if a property exists in multiple input schemas and is defined as a JTD object schema in all of them, the function will perform a deep merge of those schemas. If the property is not a JTD object schema in any of the input schemas, the function will simply take the first definition it encounters.\n *\n * @param schemas - An array of JTD object schemas to merge.\n * @returns A single JTD object schema that combines the properties of all input schemas.\n */\nexport function mergeSchemas<TMetadata extends SchemaMetadata>(\n ...schemas: (JTDSchemaObjectType<TMetadata> | ObjectSchema<TMetadata>)[]\n): JTDSchemaObjectType<TMetadata> {\n const mergedSchema = {\n properties: {},\n optionalProperties: {},\n additionalProperties: false\n } as JTDSchemaObjectType<TMetadata>;\n for (const schema of schemas.reverse()) {\n const properties = getProperties(schema);\n for (const [key, value] of Object.entries(properties)) {\n if (value.optional) {\n mergedSchema.optionalProperties![key] = (\n mergedSchema.optionalProperties![key] &&\n isJTDSchemaObject(mergedSchema.optionalProperties![key]) &&\n isJTDSchemaObject(value)\n ? defu(mergedSchema.optionalProperties![key], value)\n : value\n ) as JTDSchemaType<TMetadata>;\n } else {\n mergedSchema.properties![key] = (\n mergedSchema.properties![key] &&\n isJTDSchemaObject(mergedSchema.properties![key]) &&\n isJTDSchemaObject(value)\n ? defu(mergedSchema.properties![key], value)\n : value\n ) as JTDSchemaType<TMetadata>;\n }\n }\n }\n\n return mergedSchema;\n}\n"],"mappings":";;;;;;;;;;;AAkCA,SAAgB,cACd,KACkE;CAClE,MAAM,aAGF,EAAE;CAEN,MAAM,SAAS,eAAe,IAAI,GAAG,IAAI,SAAS;AAClD,KACE,wBAAwB,UACxB,YAAY,OAAO,mBAAmB,CAEtC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,mBAAmB,CAClE,YAAW,OAAO;EAAE,GAAG;EAAO,UAAU;EAAM;AAIlD,KAAI,gBAAgB,UAAU,YAAY,OAAO,WAAW,CAC1D,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,WAAW,CAC1D,YAAW,OAAO;EAAE,GAAG;EAAO,UAAU;EAAO;AAInD,QAAO;;;;;;;;;;;AAYT,SAAgB,aACd,GAAG,SAC6B;CAChC,MAAM,eAAe;EACnB,YAAY,EAAE;EACd,oBAAoB,EAAE;EACtB,sBAAsB;EACvB;AACD,MAAK,MAAM,UAAU,QAAQ,SAAS,EAAE;EACtC,MAAM,aAAa,cAAc,OAAO;AACxC,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,WAAW,CACnD,KAAI,MAAM,SACR,cAAa,mBAAoB,OAC/B,aAAa,mBAAoB,QACjC,kBAAkB,aAAa,mBAAoB,KAAK,IACxD,kBAAkB,MAAM,GACpBA,OAAK,aAAa,mBAAoB,MAAM,MAAM,GAClD;MAGN,cAAa,WAAY,OACvB,aAAa,WAAY,QACzB,kBAAkB,aAAa,WAAY,KAAK,IAChD,kBAAkB,MAAM,GACpBA,OAAK,aAAa,WAAY,MAAM,MAAM,GAC1C;;AAMZ,QAAO"}
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ const require_reflection = require('./reflection.cjs');
6
6
  const require_resolve = require('./resolve.cjs');
7
7
  const require_type_checks = require('./type-checks.cjs');
8
8
  const require_extract = require('./extract.cjs');
9
+ const require_helpers = require('./helpers.cjs');
9
10
 
10
11
  exports.bundle = require_bundle.bundle;
11
12
  exports.extract = require_extract.extract;
@@ -18,12 +19,16 @@ exports.extractSchemaSchema = require_extract.extractSchemaSchema;
18
19
  exports.extractSource = require_extract.extractSource;
19
20
  exports.extractVariant = require_extract.extractVariant;
20
21
  exports.generateCode = require_codegen.generateCode;
22
+ exports.getProperties = require_helpers.getProperties;
21
23
  exports.isExtractedSchema = require_type_checks.isExtractedSchema;
22
24
  exports.isJTDSchema = require_type_checks.isJTDSchema;
25
+ exports.isJTDSchemaObject = require_type_checks.isJTDSchemaObject;
26
+ exports.isObjectSchema = require_type_checks.isObjectSchema;
23
27
  exports.isSchema = require_type_checks.isSchema;
24
28
  exports.isUntypedInput = require_type_checks.isUntypedInput;
25
29
  exports.isUntypedSchema = require_type_checks.isUntypedSchema;
26
30
  exports.jsonSchemaToJtd = require_jtd.jsonSchemaToJtd;
31
+ exports.mergeSchemas = require_helpers.mergeSchemas;
27
32
  exports.reflectionToJsonSchema = require_reflection.reflectionToJsonSchema;
28
33
  exports.resolve = require_resolve.resolve;
29
34
  exports.resolveModule = require_resolve.resolveModule;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { BundleOptions, bundle } from "./bundle.cjs";
2
2
  import { generateCode } from "./codegen.cjs";
3
- import { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource } from "./types.cjs";
3
+ import { 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 } from "./types.cjs";
4
4
  import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant } from "./extract.cjs";
5
+ import { getProperties, mergeSchemas } from "./helpers.cjs";
5
6
  import { jsonSchemaToJtd } from "./jtd.cjs";
6
7
  import { reflectionToJsonSchema } from "./reflection.cjs";
7
8
  import { resolve, resolveModule, resolveReflection } from "./resolve.cjs";
8
- import { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.cjs";
9
- export { BaseSchemaSource, BundleOptions, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema, jsonSchemaToJtd, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
9
+ import { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.cjs";
10
+ export { BaseSchemaSource, BundleOptions, 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, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, getProperties, isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema, jsonSchemaToJtd, mergeSchemas, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { BundleOptions, bundle } from "./bundle.mjs";
2
2
  import { generateCode } from "./codegen.mjs";
3
- import { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource } from "./types.mjs";
3
+ import { 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 } from "./types.mjs";
4
4
  import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant } from "./extract.mjs";
5
+ import { getProperties, mergeSchemas } from "./helpers.mjs";
5
6
  import { jsonSchemaToJtd } from "./jtd.mjs";
6
7
  import { reflectionToJsonSchema } from "./reflection.mjs";
7
8
  import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
8
- import { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
9
- export { BaseSchemaSource, BundleOptions, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema, jsonSchemaToJtd, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
9
+ import { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
10
+ export { BaseSchemaSource, BundleOptions, 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, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, getProperties, isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema, jsonSchemaToJtd, mergeSchemas, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
package/dist/index.mjs CHANGED
@@ -3,7 +3,8 @@ import { generateCode } from "./codegen.mjs";
3
3
  import { jsonSchemaToJtd } from "./jtd.mjs";
4
4
  import { reflectionToJsonSchema } from "./reflection.mjs";
5
5
  import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
6
- import { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
6
+ import { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
7
7
  import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant } from "./extract.mjs";
8
+ import { getProperties, mergeSchemas } from "./helpers.mjs";
8
9
 
9
- export { bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema, jsonSchemaToJtd, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
10
+ export { bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, getProperties, isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema, jsonSchemaToJtd, mergeSchemas, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
@@ -1,7 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
3
  let _stryke_type_checks = require("@stryke/type-checks");
4
- let _stryke_json_schema = require("@stryke/json/schema");
5
4
 
6
5
  //#region src/type-checks.ts
7
6
  /**
@@ -10,8 +9,17 @@ let _stryke_json_schema = require("@stryke/json/schema");
10
9
  * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
11
10
  * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
12
11
  */
12
+ function isJTDSchemaObject(input) {
13
+ return (0, _stryke_type_checks.isSetObject)(input) && ("properties" in input && (0, _stryke_type_checks.isObject)(input.properties) || "optionalProperties" in input && (0, _stryke_type_checks.isObject)(input.optionalProperties));
14
+ }
15
+ /**
16
+ * 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`.
17
+ *
18
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
19
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
20
+ */
13
21
  function isJTDSchema(input) {
14
- return (0, _stryke_json_schema.isJsonSchemaObjectType)(input) && "jtd" in input && input.jtd === true;
22
+ return (0, _stryke_type_checks.isSetObject)(input) && (isJTDSchemaObject(input) || "elements" in input || "values" in input || "ref" in input || "type" in input || "enum" in input || "discriminator" in input && (0, _stryke_type_checks.isSetString)(input.discriminator) && "mapping" in input && (0, _stryke_type_checks.isObject)(input.mapping));
15
23
  }
16
24
  /**
17
25
  * 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.
@@ -67,10 +75,21 @@ function isSchema(input) {
67
75
  function isExtractedSchema(input) {
68
76
  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
77
  }
78
+ /**
79
+ * 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`.
80
+ *
81
+ * @param input - The input to check for being a {@link ObjectSchema}.
82
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
83
+ */
84
+ function isObjectSchema(input) {
85
+ return isSchema(input) && isJTDSchemaObject(input.schema);
86
+ }
70
87
 
71
88
  //#endregion
72
89
  exports.isExtractedSchema = isExtractedSchema;
73
90
  exports.isJTDSchema = isJTDSchema;
91
+ exports.isJTDSchemaObject = isJTDSchemaObject;
92
+ exports.isObjectSchema = isObjectSchema;
74
93
  exports.isSchema = isSchema;
75
94
  exports.isUntypedInput = isUntypedInput;
76
95
  exports.isUntypedSchema = isUntypedSchema;
@@ -1,8 +1,15 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
1
+ import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
2
2
  import { InputObject, Schema } from "untyped";
3
3
  import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
4
 
5
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 isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
6
13
  /**
7
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`.
8
15
  *
@@ -38,6 +45,13 @@ declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(inp
38
45
  * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
39
46
  */
40
47
  declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
48
+ /**
49
+ * 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`.
50
+ *
51
+ * @param input - The input to check for being a {@link ObjectSchema}.
52
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
53
+ */
54
+ declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
41
55
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
56
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
43
57
  //# sourceMappingURL=type-checks.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAUV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;AAxBnB;;;;;iBA0CgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA"}
1
+ {"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAsBV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;;;AAhFnB;;;iBAkGgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA;;;;;;AA5C5C;iBA8DgB,cAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,YAAA,CAAa,SAAA"}
@@ -1,8 +1,15 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
1
+ import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
2
2
  import { InputObject, Schema } from "untyped";
3
3
  import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
4
 
5
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 isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
6
13
  /**
7
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`.
8
15
  *
@@ -38,6 +45,13 @@ declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(inp
38
45
  * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
39
46
  */
40
47
  declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
48
+ /**
49
+ * 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`.
50
+ *
51
+ * @param input - The input to check for being a {@link ObjectSchema}.
52
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
53
+ */
54
+ declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
41
55
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
56
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
43
57
  //# sourceMappingURL=type-checks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAUV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;AAxBnB;;;;;iBA0CgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA"}
1
+ {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAsBV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;;;AAhFnB;;;iBAkGgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA;;;;;;AA5C5C;iBA8DgB,cAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,YAAA,CAAa,SAAA"}
@@ -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 isJsonSchemaObjectType(input) && "jtd" in input && input.jtd === true;
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
@@ -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,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,SACd,OAC4B;AAC5B,QACE,YAAY,MAAM,IAClB,YAAY,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<TMetadata>(input.schema)\n );\n}\n"],"mappings":";;;;;;;;;AA2CA,SAAgB,kBAEd,OAAyD;AACzD,QACE,YAAY,MAAM,KAChB,gBAAgB,SAAS,SAAS,MAAM,WAAW,IAClD,wBAAwB,SAAS,SAAS,MAAM,mBAAmB;;;;;;;;AAU1E,SAAgB,YACd,OACmC;AACnC,QACE,YAAY,MAAM,KACjB,kBAA6B,MAAM,IAClC,cAAc,SACd,YAAY,SACZ,SAAS,SACT,UAAU,SACV,UAAU,SACT,mBAAmB,SAClB,YAAY,MAAM,cAAc,IAChC,aAAa,SACb,SAAS,MAAM,QAAQ;;;;;;;;AAU/B,SAAgB,gBAAgB,OAAw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AY,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;;;;;;;;AAUrC,SAAgB,eAEd,OAAkD;AAClD,QACE,SAAoB,MAAM,IAAI,kBAA6B,MAAM,OAAO"}
package/dist/types.d.cts CHANGED
@@ -107,6 +107,15 @@ interface SchemaMetadata {
107
107
  union?: JsonSchemaLike[];
108
108
  [key: string]: unknown | undefined;
109
109
  }
110
+ type JTDSchemaObjectForm<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = {
111
+ properties: Record<string, JTDSchemaType<TMetadata>>;
112
+ optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
113
+ additionalProperties?: boolean;
114
+ } | {
115
+ properties?: Record<string, JTDSchemaType<TMetadata>>;
116
+ optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
117
+ additionalProperties?: boolean;
118
+ };
110
119
  type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = ({
111
120
  ref: string;
112
121
  } | {
@@ -117,15 +126,7 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
117
126
  elements: JTDSchemaType<TMetadata>;
118
127
  } | {
119
128
  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
- } | {
129
+ } | JTDSchemaObjectForm<TMetadata> | {
129
130
  discriminator: string;
130
131
  mapping: Record<string, JTDSchemaType<TMetadata>>;
131
132
  } | {}) & {
@@ -133,16 +134,30 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
133
134
  metadata?: TMetadata;
134
135
  definitions?: Record<string, JTDSchemaType<TMetadata>>;
135
136
  };
137
+ type JTDSchemaObjectType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = JTDSchemaObjectForm<TMetadata> & {
138
+ nullable?: boolean;
139
+ metadata?: TMetadata;
140
+ definitions?: Record<string, JTDSchemaType<TMetadata>>;
141
+ };
136
142
  type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
137
143
  type SchemaInputVariant = SchemaSourceVariant | "type-definition";
138
144
  type SchemaSourceInput<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = StandardJSONSchemaV1 | JTDSchemaType<TMetadata> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
139
145
  type TypeDefinitionReference = TypeDefinition | string;
140
146
  type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
147
+ /**
148
+ * 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.
149
+ */
141
150
  interface Schema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> {
142
151
  hash: string;
143
152
  variant: SchemaInputVariant;
144
153
  schema: JTDSchemaType<TMetadata>;
145
154
  }
155
+ /**
156
+ * 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.
157
+ */
158
+ interface ObjectSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> extends Schema<TMetadata> {
159
+ schema: JTDSchemaObjectType<TMetadata>;
160
+ }
146
161
  interface BaseSchemaSource {
147
162
  hash: string;
148
163
  variant: SchemaSourceVariant;
@@ -177,5 +192,5 @@ interface ExtractedSchema<TMetadata extends Partial<SchemaMetadata> = Partial<Sc
177
192
  source: SchemaSource;
178
193
  }
179
194
  //#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 };
195
+ 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
196
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;KAyBY,kBAAA,GAAqB,WAAA;AAAA,KACrB,aAAA,GAAgB,QAAA;AAD5B;;;AAAA,KAMY,aAAA;;AALZ;;KAkBY,aAAA;;;AAbZ;KAkBY,OAAA,GAAU,aAAA,GAAgB,aAAA;AAAA,UAErB,cAAA;EACf,IAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA,GAAQ,cAAA,GAAiB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ACf,MAAA,EAAQ,YAAA;AAAA"}
package/dist/types.d.mts CHANGED
@@ -107,6 +107,15 @@ interface SchemaMetadata {
107
107
  union?: JsonSchemaLike[];
108
108
  [key: string]: unknown | undefined;
109
109
  }
110
+ type JTDSchemaObjectForm<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = {
111
+ properties: Record<string, JTDSchemaType<TMetadata>>;
112
+ optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
113
+ additionalProperties?: boolean;
114
+ } | {
115
+ properties?: Record<string, JTDSchemaType<TMetadata>>;
116
+ optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
117
+ additionalProperties?: boolean;
118
+ };
110
119
  type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = ({
111
120
  ref: string;
112
121
  } | {
@@ -117,15 +126,7 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
117
126
  elements: JTDSchemaType<TMetadata>;
118
127
  } | {
119
128
  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
- } | {
129
+ } | JTDSchemaObjectForm<TMetadata> | {
129
130
  discriminator: string;
130
131
  mapping: Record<string, JTDSchemaType<TMetadata>>;
131
132
  } | {}) & {
@@ -133,16 +134,30 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
133
134
  metadata?: TMetadata;
134
135
  definitions?: Record<string, JTDSchemaType<TMetadata>>;
135
136
  };
137
+ type JTDSchemaObjectType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = JTDSchemaObjectForm<TMetadata> & {
138
+ nullable?: boolean;
139
+ metadata?: TMetadata;
140
+ definitions?: Record<string, JTDSchemaType<TMetadata>>;
141
+ };
136
142
  type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
137
143
  type SchemaInputVariant = SchemaSourceVariant | "type-definition";
138
144
  type SchemaSourceInput<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = StandardJSONSchemaV1 | JTDSchemaType<TMetadata> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
139
145
  type TypeDefinitionReference = TypeDefinition | string;
140
146
  type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
147
+ /**
148
+ * 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.
149
+ */
141
150
  interface Schema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> {
142
151
  hash: string;
143
152
  variant: SchemaInputVariant;
144
153
  schema: JTDSchemaType<TMetadata>;
145
154
  }
155
+ /**
156
+ * 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.
157
+ */
158
+ interface ObjectSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> extends Schema<TMetadata> {
159
+ schema: JTDSchemaObjectType<TMetadata>;
160
+ }
146
161
  interface BaseSchemaSource {
147
162
  hash: string;
148
163
  variant: SchemaSourceVariant;
@@ -177,5 +192,5 @@ interface ExtractedSchema<TMetadata extends Partial<SchemaMetadata> = Partial<Sc
177
192
  source: SchemaSource;
178
193
  }
179
194
  //#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 };
195
+ 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
196
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;KAyBY,kBAAA,GAAqB,WAAA;AAAA,KACrB,aAAA,GAAgB,QAAA;AAD5B;;;AAAA,KAMY,aAAA;;AALZ;;KAkBY,aAAA;;;AAbZ;KAkBY,OAAA,GAAU,aAAA,GAAgB,aAAA;AAAA,UAErB,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;E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A;;;;UAMP,YAAA,mBACG,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,WAC5C,MAAA,CAAO,SAAA;EACf,MAAA,EAAQ,mBAAA,CAAoB,SAAA;AAAA;AAAA,UAGb,gBAAA;EACf,IAAA;EACA,OAAA,EAAS,mBAAA;EACT,MAAA,EAAQ,iBAAA;AAAA;AAAA,UAGO,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,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,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.15",
3
+ "version": "0.11.17",
4
4
  "private": false,
5
5
  "description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
6
6
  "keywords": [
@@ -62,6 +62,10 @@
62
62
  "import": "./dist/extract.mjs",
63
63
  "require": "./dist/extract.cjs"
64
64
  },
65
+ "./helpers": {
66
+ "import": "./dist/helpers.mjs",
67
+ "require": "./dist/helpers.cjs"
68
+ },
65
69
  "./jtd": { "import": "./dist/jtd.mjs", "require": "./dist/jtd.cjs" },
66
70
  "./reflection": {
67
71
  "import": "./dist/reflection.mjs",
@@ -84,9 +88,9 @@
84
88
  "typings": "dist/index.d.mts",
85
89
  "files": ["dist"],
86
90
  "dependencies": {
87
- "@powerlines/core": "^0.15.15",
88
- "@powerlines/deepkit": "^0.9.14",
89
- "@powerlines/unplugin": "^0.0.30",
91
+ "@powerlines/core": "^0.15.16",
92
+ "@powerlines/deepkit": "^0.9.15",
93
+ "@powerlines/unplugin": "^0.0.31",
90
94
  "@standard-schema/spec": "^1.1.0",
91
95
  "@stryke/hash": "^0.13.29",
92
96
  "@stryke/helpers": "^0.10.16",
@@ -105,5 +109,5 @@
105
109
  "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" },
106
110
  "peerDependenciesMeta": { "zod": { "optional": true } },
107
111
  "publishConfig": { "access": "public" },
108
- "gitHead": "33ca9cb50ef67b292d3ab7c4090abfb6b9435237"
112
+ "gitHead": "e48e90aee8dfeb7676f098c9dc2ccd73fe0a2de3"
109
113
  }