@powerlines/schema 0.11.60 → 0.11.62
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 +2 -1
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +2 -1
- package/dist/extract.mjs.map +1 -1
- package/dist/resolve.cjs +7 -8
- package/dist/resolve.d.cts +2 -2
- package/dist/resolve.d.cts.map +1 -1
- package/dist/resolve.d.mts +2 -2
- package/dist/resolve.d.mts.map +1 -1
- package/dist/resolve.mjs +7 -8
- package/dist/resolve.mjs.map +1 -1
- package/package.json +14 -14
package/dist/extract.cjs
CHANGED
|
@@ -388,7 +388,8 @@ async function extractSchemaWithSource(context, input, options = {}) {
|
|
|
388
388
|
if (variant === "file-reference") {
|
|
389
389
|
const fileReference = (0, _stryke_convert_extract_file_reference.extractFileReference)(input);
|
|
390
390
|
if (!fileReference) throw new Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(input)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);
|
|
391
|
-
|
|
391
|
+
const extension = (0, _stryke_path_find.findFileExtensionSafe)(fileReference.file);
|
|
392
|
+
if (extension && !require_constants.VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) throw new Error(`The provided schema file input "${fileReference.file}" has an invalid file extension (.${extension}). Please ensure that the file has one of the following extensions: ${(0, _stryke_string_format_list.list)(require_constants.VALID_SOURCE_FILE_EXTENSIONS, { conjunction: "or" })}.`);
|
|
392
393
|
const resolved = await require_resolve.resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
|
|
393
394
|
reflection: "default",
|
|
394
395
|
level: "all"
|
package/dist/extract.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;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,GAAS,aAAA,GACR,OAAA,CAAQ,eAAA;;;;;AA3EI;AAuEf;;;;;;;;;;;;;;;;;;;AAI0B;AAoH1B;;;;;iBAAsB,OAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,MAAA"}
|
package/dist/extract.mjs
CHANGED
|
@@ -386,7 +386,8 @@ async function extractSchemaWithSource(context, input, options = {}) {
|
|
|
386
386
|
if (variant === "file-reference") {
|
|
387
387
|
const fileReference = extractFileReference(input);
|
|
388
388
|
if (!fileReference) throw new Error(`Failed to extract a valid file reference from the provided input "${JSON.stringify(input)}". Please ensure that the input is correctly formatted as a file reference (e.g. "./schema.ts#MySchema") and that the file exists at the specified path.`);
|
|
389
|
-
|
|
389
|
+
const extension = findFileExtensionSafe(fileReference.file);
|
|
390
|
+
if (extension && !VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) throw new Error(`The provided schema file input "${fileReference.file}" has an invalid file extension (.${extension}). Please ensure that the file has one of the following extensions: ${list(VALID_SOURCE_FILE_EXTENSIONS, { conjunction: "or" })}.`);
|
|
390
391
|
const resolved = await resolve(context, input, defu(options, { plugins: [esbuildPlugin(context, {
|
|
391
392
|
reflection: "default",
|
|
392
393
|
level: "all"
|
package/dist/extract.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.mjs","names":["isSetObject","extractJsonSchema","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 { isFileReference } 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 { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { list } from \"@stryke/string-format/list\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { FileReferenceInput } from \"@stryke/types\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport * as z3 from \"zod/v3\";\nimport { BundleOptions } from \"./bundle\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isSchemaWithSource,\n isUntypedInput,\n isUntypedInputStrict,\n isUntypedSchema,\n isUntypedSchemaStrict,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\n\nconst SCHEMA_BUNDLE_BASE_URI = \"https://powerlines.invalid/\";\n\nfunction normalizeUri(uri: string): string {\n return uri.endsWith(\"#\") ? uri.slice(0, -1) : uri;\n}\n\nfunction stripUriFragment(uri: string): string {\n const hashIndex = uri.indexOf(\"#\");\n\n return hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;\n}\n\nfunction escapeJsonPointerToken(token: string): string {\n return token.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction toJsonPointer(path: string[]): string {\n if (path.length === 0) {\n return \"\";\n }\n\n return `/${path.map(segment => escapeJsonPointerToken(segment)).join(\"/\")}`;\n}\n\nfunction resolveUri(reference: string, baseUri: string): string {\n try {\n return normalizeUri(new URL(reference, baseUri).toString());\n } catch {\n return normalizeUri(reference);\n }\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n const pointer = toJsonPointer(path);\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n const currentDocumentUri = stripUriFragment(currentBaseUri);\n\n uriToPointer.set(currentBaseUri, pointer);\n uriToPointer.set(currentDocumentUri, pointer);\n\n if (isSetString(schema.$anchor)) {\n uriToPointer.set(`${currentDocumentUri}#${schema.$anchor}`, pointer);\n }\n\n if (isSetString(schema.$dynamicAnchor)) {\n const dynamicTarget = `${currentDocumentUri}#${schema.$dynamicAnchor}`;\n uriToPointer.set(dynamicTarget, pointer);\n dynamicUriToFragment.set(dynamicTarget, `#${schema.$dynamicAnchor}`);\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n collectReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n collectReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\nfunction rewriteReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n if (isSetString(schema.$ref)) {\n const resolvedRefUri = resolveUri(schema.$ref, currentBaseUri);\n const pointer =\n uriToPointer.get(resolvedRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedRefUri));\n\n if (pointer !== undefined) {\n schema.$ref = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n\n if (isSetString(schema.$dynamicRef)) {\n const resolvedDynamicRefUri = resolveUri(\n schema.$dynamicRef,\n currentBaseUri\n );\n const dynamicFragment = dynamicUriToFragment.get(resolvedDynamicRefUri);\n\n if (dynamicFragment) {\n schema.$dynamicRef = dynamicFragment;\n } else {\n const pointer =\n uriToPointer.get(resolvedDynamicRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedDynamicRefUri));\n\n if (pointer !== undefined) {\n schema.$dynamicRef = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n rewriteReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n rewriteReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\n/**\n * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.\n *\n * @param schema - The JSON Schema to bundle references for.\n * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.\n */\nexport function bundleReferences(schema: JsonSchema): JsonSchema {\n if (!isSetObject(schema)) {\n return schema;\n }\n\n const bundledSchema = deepClone(schema) as Record<string, unknown>;\n const baseUri = isSetString(bundledSchema.$id)\n ? resolveUri(bundledSchema.$id, SCHEMA_BUNDLE_BASE_URI)\n : SCHEMA_BUNDLE_BASE_URI;\n\n const uriToPointer = new Map<string, string>();\n const dynamicUriToFragment = new Map<string, string>();\n\n collectReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n rewriteReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n return bundledSchema;\n}\n\nfunction convertNestedUntypedSchema(value: unknown): unknown {\n if (isUntypedSchema(value)) {\n return convertUntypedSchemaToJsonSchema(value);\n }\n\n if (isSetObject(value)) {\n if (isUntypedInput(value)) {\n return convertUntypedInputToJsonSchema(value);\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n return convertUntypedSchemaToJsonSchema(nested.$schema);\n }\n }\n\n return value;\n}\n\nfunction convertNestedUntypedSchemaArray(value: unknown): unknown {\n if (!Array.isArray(value)) {\n return value;\n }\n\n return value.map(item => convertNestedUntypedSchema(item));\n}\n\nfunction convertValibotSchemaToJsonSchema(schema: unknown): JsonSchema {\n return toJsonSchema(schema as never, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n}\n\nfunction convertUntypedSchemaToJsonSchema(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema {\n const source = schema as Record<string, unknown>;\n const jsonSchema: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(source)) {\n if (\n key === \"tsType\" ||\n key === \"markdownType\" ||\n key === \"tags\" ||\n key === \"args\" ||\n key === \"resolve\"\n ) {\n continue;\n }\n\n if (key === \"id\" && isSetString(value)) {\n jsonSchema.$id = value;\n continue;\n }\n\n if (\n key === \"properties\" ||\n key === \"patternProperties\" ||\n key === \"dependentSchemas\" ||\n key === \"$defs\" ||\n key === \"definitions\"\n ) {\n if (!isSetObject(value)) {\n jsonSchema[key] = value;\n continue;\n }\n\n jsonSchema[key] = Object.fromEntries(\n Object.entries(value).map(([propertyKey, propertyValue]) => [\n propertyKey,\n convertNestedUntypedSchema(propertyValue)\n ])\n );\n continue;\n }\n\n if (\n key === \"items\" ||\n key === \"contains\" ||\n key === \"if\" ||\n key === \"then\" ||\n key === \"else\" ||\n key === \"not\" ||\n key === \"propertyNames\" ||\n key === \"additionalProperties\" ||\n key === \"unevaluatedProperties\"\n ) {\n jsonSchema[key] = convertNestedUntypedSchema(value);\n continue;\n }\n\n if (key === \"oneOf\" || key === \"anyOf\" || key === \"allOf\") {\n jsonSchema[key] = convertNestedUntypedSchemaArray(value);\n continue;\n }\n\n jsonSchema[key] = value;\n }\n\n return jsonSchema;\n}\n\nfunction convertUntypedInputToJsonSchema(\n input: UntypedInputObject\n): JsonSchema {\n const inputObject = input as Record<string, unknown>;\n const base = isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema(inputObject.$schema)\n : {};\n const properties: Record<string, JsonSchema> = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n if (key.startsWith(\"$\")) {\n continue;\n }\n\n if (!isSetObject(value)) {\n continue;\n }\n\n if (isUntypedInput(value)) {\n properties[key] = convertUntypedInputToJsonSchema(value);\n continue;\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n properties[key] = convertUntypedSchemaToJsonSchema(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema(value);\n }\n }\n\n if (!isJsonSchemaObject(base)) {\n throw new Error(\n `Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`\n );\n }\n\n const baseProperties = isSetObject(base.properties) ? base.properties : {};\n const mergedProperties = {\n ...baseProperties,\n ...properties\n };\n\n return {\n ...base,\n type: base.type ?? \"object\",\n ...(Object.keys(mergedProperties).length > 0\n ? { properties: mergedProperties }\n : {})\n };\n}\n\n/**\n * Creates a hash string for a given schema definition input.\n */\nexport function extractHash(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (typeof input === \"boolean\") {\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 (isJsonSchema(input)) {\n return murmurhash({ variant, input });\n } else if (isValibotSchema(input)) {\n return murmurhash({\n variant,\n input: convertValibotSchemaToJsonSchema(input)\n });\n } else if (isUntypedInput(input)) {\n return murmurhash({\n variant,\n input: convertUntypedInputToJsonSchema(input)\n });\n } else if (isUntypedSchema(input)) {\n return murmurhash({\n variant,\n input: convertUntypedSchemaToJsonSchema(input)\n });\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, a Valibot BaseSchema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-2020-12) representation.\n */\nexport function extractReflection(reflection: Type): JsonSchema | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n */\nexport function extractJsonSchema(schema: unknown): JsonSchema | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n }\n if (isUntypedInputStrict(schema)) {\n return convertUntypedInputToJsonSchema(schema);\n }\n if (isUntypedSchemaStrict(schema)) {\n return convertUntypedSchemaToJsonSchema(schema);\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema(schema);\n }\n if (isJsonSchema(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves the concrete source variant for a schema source input.\n *\n * @param input - The schema source input to inspect.\n * @returns The resolved schema source variant.\n * @throws Will throw an error when the input cannot be mapped to a supported source variant.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (typeof input === \"boolean\") {\n return \"json-schema\";\n }\n\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isUntypedInputStrict(input) || isUntypedSchemaStrict(input)) {\n return \"untyped\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJsonSchema(input)) {\n return \"json-schema\";\n } else if (isValibotSchema(input)) {\n return \"valibot\";\n } else if (isType(input)) {\n return \"reflection\";\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 Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\n/**\n * Determines the top-level input variant for schema extraction.\n *\n * @param input - The schema input to classify.\n * @returns The resolved schema input variant.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isFileReference(input)) {\n return \"file-reference\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts and normalizes a JSON Schema from a concrete schema source input.\n *\n * @param input - The schema source input to extract from.\n * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.\n * @returns A promise that resolves to a bundled JSON Schema.\n * @throws Will throw an error if no valid JSON Schema can be extracted from the input.\n */\nexport async function extractSchema(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema> {\n if (isSchemaWithSource(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return bundleReferences(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 Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Builds source metadata for a schema input using a known source variant.\n *\n * @param variant - The schema source variant associated with the input.\n * @param input - The schema source input to wrap.\n * @returns The normalized schema source payload, including the source hash and variant.\n * @throws Will throw an error if the provided variant is unsupported.\n */\nexport function extractSource(\n variant: SchemaSourceVariant,\n input: SchemaSourceInput\n): 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 JsonSchema\n };\n } else if (variant === \"valibot\") {\n return {\n hash: extractHash(variant, input),\n variant: \"valibot\",\n schema: input as ValibotSchema\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\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, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\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://zod.dev/\n * @see https://valibot.dev/\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 *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.\n * @param options - Optional overrides for the Rolldown configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.\n */\nexport async function extractSchemaWithSource(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<ExtractedSchema> {\n if (isSchemaWithSource(input)) {\n return input;\n }\n\n if (isSchema(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"json-schema\", input.schema),\n variant: \"json-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 === \"file-reference\") {\n const fileReference = extractFileReference(input as FileReferenceInput);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a valid file reference from the provided input \"${JSON.stringify(\n input\n )}\". Please ensure that the input is correctly formatted as a file reference (e.g. \"./schema.ts#MySchema\") and that the file exists at the specified path.`\n );\n }\n\n if (\n !VALID_SOURCE_FILE_EXTENSIONS.includes(\n findFileExtensionSafe(fileReference.file)\n )\n ) {\n throw new Error(\n `The provided schema file input \"${\n fileReference.file\n }\" has an invalid file extension. Please ensure that the file has one of the following extensions: ${list(\n VALID_SOURCE_FILE_EXTENSIONS,\n { conjunction: \"or\" }\n )}.`\n );\n }\n\n const resolved = await resolve<SchemaSourceInput>(\n context,\n input as FileReferenceInput,\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 \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"valibot\",\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 \"file-reference\", \"json-schema\", \"standard-schema\", \"zod3\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchema(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\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://zod.dev/\n * @see https://valibot.dev/\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 context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the Rolldown configuration used during extraction.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.\n * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.\n */\nexport async function extract(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<Schema> {\n if (isSchemaWithSource(input) || isSchema(input)) {\n return input;\n }\n\n let result: Schema | undefined;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n const cacheFilePath = joinPaths(getCacheDirectory(context), `${hash}.json`);\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 JsonSchema\n };\n }\n }\n\n result ??= await extractSchemaWithSource(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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await writeSchema(context, result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAM,yBAAyB;AAE/B,SAAS,aAAa,KAAqB;CACzC,OAAO,IAAI,SAAS,GAAG,IAAI,IAAI,MAAM,GAAG,EAAE,IAAI;AAChD;AAEA,SAAS,iBAAiB,KAAqB;CAC7C,MAAM,YAAY,IAAI,QAAQ,GAAG;CAEjC,OAAO,aAAa,IAAI,IAAI,MAAM,GAAG,SAAS,IAAI;AACpD;AAEA,SAAS,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QAAQ,MAAM,cAAc,OAAO,QAAQ,OAAO,OAAO;EACzD;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,QACpB,SACA,OACA,UAAyB,CAAC,GACT;CACjB,IAAI,mBAAmB,KAAK,KAAK,SAAS,KAAK,GAC7C,OAAO;CAGT,IAAI;CAEJ,MAAM,UAAU,eAAe,KAAK;CACpC,MAAM,OAAO,YAAY,SAAS,KAAK;CAEvC,MAAM,gBAAgB,UAAU,kBAAkB,OAAO,GAAG,GAAG,KAAK,MAAM;CAC1E,IACE,QAAQ,OAAO,cAAc,QAC7B,QAAQ,GAAG,WAAW,aAAa,GACnC;EACA,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK,aAAa;EAClD,IAAI,QACF,SAAS;GACP;GACA;GACA,QAAQ,KAAK,MAAM,MAAM;EAC3B;CAEJ;CAEA,WAAW,MAAM,wBAAwB,SAAS,OAAO,OAAO;CAChE,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MACR,+NACF;CAGF,IAAI,QAAQ,OAAO,cAAc,MAC/B,MAAM,YAAY,SAAS,MAAM;CAGnC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"extract.mjs","names":["isSetObject","extractJsonSchema","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 { isFileReference } 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 { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { list } from \"@stryke/string-format/list\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { FileReferenceInput } from \"@stryke/types\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport * as z3 from \"zod/v3\";\nimport { BundleOptions } from \"./bundle\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isSchemaWithSource,\n isUntypedInput,\n isUntypedInputStrict,\n isUntypedSchema,\n isUntypedSchemaStrict,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\n\nconst SCHEMA_BUNDLE_BASE_URI = \"https://powerlines.invalid/\";\n\nfunction normalizeUri(uri: string): string {\n return uri.endsWith(\"#\") ? uri.slice(0, -1) : uri;\n}\n\nfunction stripUriFragment(uri: string): string {\n const hashIndex = uri.indexOf(\"#\");\n\n return hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;\n}\n\nfunction escapeJsonPointerToken(token: string): string {\n return token.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction toJsonPointer(path: string[]): string {\n if (path.length === 0) {\n return \"\";\n }\n\n return `/${path.map(segment => escapeJsonPointerToken(segment)).join(\"/\")}`;\n}\n\nfunction resolveUri(reference: string, baseUri: string): string {\n try {\n return normalizeUri(new URL(reference, baseUri).toString());\n } catch {\n return normalizeUri(reference);\n }\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n const pointer = toJsonPointer(path);\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n const currentDocumentUri = stripUriFragment(currentBaseUri);\n\n uriToPointer.set(currentBaseUri, pointer);\n uriToPointer.set(currentDocumentUri, pointer);\n\n if (isSetString(schema.$anchor)) {\n uriToPointer.set(`${currentDocumentUri}#${schema.$anchor}`, pointer);\n }\n\n if (isSetString(schema.$dynamicAnchor)) {\n const dynamicTarget = `${currentDocumentUri}#${schema.$dynamicAnchor}`;\n uriToPointer.set(dynamicTarget, pointer);\n dynamicUriToFragment.set(dynamicTarget, `#${schema.$dynamicAnchor}`);\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n collectReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n collectReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\nfunction rewriteReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n if (isSetString(schema.$ref)) {\n const resolvedRefUri = resolveUri(schema.$ref, currentBaseUri);\n const pointer =\n uriToPointer.get(resolvedRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedRefUri));\n\n if (pointer !== undefined) {\n schema.$ref = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n\n if (isSetString(schema.$dynamicRef)) {\n const resolvedDynamicRefUri = resolveUri(\n schema.$dynamicRef,\n currentBaseUri\n );\n const dynamicFragment = dynamicUriToFragment.get(resolvedDynamicRefUri);\n\n if (dynamicFragment) {\n schema.$dynamicRef = dynamicFragment;\n } else {\n const pointer =\n uriToPointer.get(resolvedDynamicRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedDynamicRefUri));\n\n if (pointer !== undefined) {\n schema.$dynamicRef = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n rewriteReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n rewriteReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\n/**\n * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.\n *\n * @param schema - The JSON Schema to bundle references for.\n * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.\n */\nexport function bundleReferences(schema: JsonSchema): JsonSchema {\n if (!isSetObject(schema)) {\n return schema;\n }\n\n const bundledSchema = deepClone(schema) as Record<string, unknown>;\n const baseUri = isSetString(bundledSchema.$id)\n ? resolveUri(bundledSchema.$id, SCHEMA_BUNDLE_BASE_URI)\n : SCHEMA_BUNDLE_BASE_URI;\n\n const uriToPointer = new Map<string, string>();\n const dynamicUriToFragment = new Map<string, string>();\n\n collectReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n rewriteReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n return bundledSchema;\n}\n\nfunction convertNestedUntypedSchema(value: unknown): unknown {\n if (isUntypedSchema(value)) {\n return convertUntypedSchemaToJsonSchema(value);\n }\n\n if (isSetObject(value)) {\n if (isUntypedInput(value)) {\n return convertUntypedInputToJsonSchema(value);\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n return convertUntypedSchemaToJsonSchema(nested.$schema);\n }\n }\n\n return value;\n}\n\nfunction convertNestedUntypedSchemaArray(value: unknown): unknown {\n if (!Array.isArray(value)) {\n return value;\n }\n\n return value.map(item => convertNestedUntypedSchema(item));\n}\n\nfunction convertValibotSchemaToJsonSchema(schema: unknown): JsonSchema {\n return toJsonSchema(schema as never, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n}\n\nfunction convertUntypedSchemaToJsonSchema(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema {\n const source = schema as Record<string, unknown>;\n const jsonSchema: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(source)) {\n if (\n key === \"tsType\" ||\n key === \"markdownType\" ||\n key === \"tags\" ||\n key === \"args\" ||\n key === \"resolve\"\n ) {\n continue;\n }\n\n if (key === \"id\" && isSetString(value)) {\n jsonSchema.$id = value;\n continue;\n }\n\n if (\n key === \"properties\" ||\n key === \"patternProperties\" ||\n key === \"dependentSchemas\" ||\n key === \"$defs\" ||\n key === \"definitions\"\n ) {\n if (!isSetObject(value)) {\n jsonSchema[key] = value;\n continue;\n }\n\n jsonSchema[key] = Object.fromEntries(\n Object.entries(value).map(([propertyKey, propertyValue]) => [\n propertyKey,\n convertNestedUntypedSchema(propertyValue)\n ])\n );\n continue;\n }\n\n if (\n key === \"items\" ||\n key === \"contains\" ||\n key === \"if\" ||\n key === \"then\" ||\n key === \"else\" ||\n key === \"not\" ||\n key === \"propertyNames\" ||\n key === \"additionalProperties\" ||\n key === \"unevaluatedProperties\"\n ) {\n jsonSchema[key] = convertNestedUntypedSchema(value);\n continue;\n }\n\n if (key === \"oneOf\" || key === \"anyOf\" || key === \"allOf\") {\n jsonSchema[key] = convertNestedUntypedSchemaArray(value);\n continue;\n }\n\n jsonSchema[key] = value;\n }\n\n return jsonSchema;\n}\n\nfunction convertUntypedInputToJsonSchema(\n input: UntypedInputObject\n): JsonSchema {\n const inputObject = input as Record<string, unknown>;\n const base = isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema(inputObject.$schema)\n : {};\n const properties: Record<string, JsonSchema> = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n if (key.startsWith(\"$\")) {\n continue;\n }\n\n if (!isSetObject(value)) {\n continue;\n }\n\n if (isUntypedInput(value)) {\n properties[key] = convertUntypedInputToJsonSchema(value);\n continue;\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n properties[key] = convertUntypedSchemaToJsonSchema(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema(value);\n }\n }\n\n if (!isJsonSchemaObject(base)) {\n throw new Error(\n `Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`\n );\n }\n\n const baseProperties = isSetObject(base.properties) ? base.properties : {};\n const mergedProperties = {\n ...baseProperties,\n ...properties\n };\n\n return {\n ...base,\n type: base.type ?? \"object\",\n ...(Object.keys(mergedProperties).length > 0\n ? { properties: mergedProperties }\n : {})\n };\n}\n\n/**\n * Creates a hash string for a given schema definition input.\n */\nexport function extractHash(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (typeof input === \"boolean\") {\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 (isJsonSchema(input)) {\n return murmurhash({ variant, input });\n } else if (isValibotSchema(input)) {\n return murmurhash({\n variant,\n input: convertValibotSchemaToJsonSchema(input)\n });\n } else if (isUntypedInput(input)) {\n return murmurhash({\n variant,\n input: convertUntypedInputToJsonSchema(input)\n });\n } else if (isUntypedSchema(input)) {\n return murmurhash({\n variant,\n input: convertUntypedSchemaToJsonSchema(input)\n });\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, a Valibot BaseSchema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-2020-12) representation.\n */\nexport function extractReflection(reflection: Type): JsonSchema | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n */\nexport function extractJsonSchema(schema: unknown): JsonSchema | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n }\n if (isUntypedInputStrict(schema)) {\n return convertUntypedInputToJsonSchema(schema);\n }\n if (isUntypedSchemaStrict(schema)) {\n return convertUntypedSchemaToJsonSchema(schema);\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema(schema);\n }\n if (isJsonSchema(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves the concrete source variant for a schema source input.\n *\n * @param input - The schema source input to inspect.\n * @returns The resolved schema source variant.\n * @throws Will throw an error when the input cannot be mapped to a supported source variant.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (typeof input === \"boolean\") {\n return \"json-schema\";\n }\n\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isUntypedInputStrict(input) || isUntypedSchemaStrict(input)) {\n return \"untyped\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJsonSchema(input)) {\n return \"json-schema\";\n } else if (isValibotSchema(input)) {\n return \"valibot\";\n } else if (isType(input)) {\n return \"reflection\";\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 Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\n/**\n * Determines the top-level input variant for schema extraction.\n *\n * @param input - The schema input to classify.\n * @returns The resolved schema input variant.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isFileReference(input)) {\n return \"file-reference\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts and normalizes a JSON Schema from a concrete schema source input.\n *\n * @param input - The schema source input to extract from.\n * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.\n * @returns A promise that resolves to a bundled JSON Schema.\n * @throws Will throw an error if no valid JSON Schema can be extracted from the input.\n */\nexport async function extractSchema(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema> {\n if (isSchemaWithSource(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return bundleReferences(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 Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Builds source metadata for a schema input using a known source variant.\n *\n * @param variant - The schema source variant associated with the input.\n * @param input - The schema source input to wrap.\n * @returns The normalized schema source payload, including the source hash and variant.\n * @throws Will throw an error if the provided variant is unsupported.\n */\nexport function extractSource(\n variant: SchemaSourceVariant,\n input: SchemaSourceInput\n): 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 JsonSchema\n };\n } else if (variant === \"valibot\") {\n return {\n hash: extractHash(variant, input),\n variant: \"valibot\",\n schema: input as ValibotSchema\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\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, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\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://zod.dev/\n * @see https://valibot.dev/\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 *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.\n * @param options - Optional overrides for the Rolldown configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.\n */\nexport async function extractSchemaWithSource(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<ExtractedSchema> {\n if (isSchemaWithSource(input)) {\n return input;\n }\n\n if (isSchema(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"json-schema\", input.schema),\n variant: \"json-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 === \"file-reference\") {\n const fileReference = extractFileReference(input as FileReferenceInput);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a valid file reference from the provided input \"${JSON.stringify(\n input\n )}\". Please ensure that the input is correctly formatted as a file reference (e.g. \"./schema.ts#MySchema\") and that the file exists at the specified path.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension && !VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) {\n throw new Error(\n `The provided schema file input \"${\n fileReference.file\n }\" has an invalid file extension (.${\n extension\n }). Please ensure that the file has one of the following extensions: ${list(\n VALID_SOURCE_FILE_EXTENSIONS,\n { conjunction: \"or\" }\n )}.`\n );\n }\n\n const resolved = await resolve<SchemaSourceInput>(\n context,\n input as FileReferenceInput,\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 \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"valibot\",\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 \"file-reference\", \"json-schema\", \"standard-schema\", \"zod3\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchema(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\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://zod.dev/\n * @see https://valibot.dev/\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 context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the Rolldown configuration used during extraction.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.\n * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.\n */\nexport async function extract(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<Schema> {\n if (isSchemaWithSource(input) || isSchema(input)) {\n return input;\n }\n\n let result: Schema | undefined;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n const cacheFilePath = joinPaths(getCacheDirectory(context), `${hash}.json`);\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 JsonSchema\n };\n }\n }\n\n result ??= await extractSchemaWithSource(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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await writeSchema(context, result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAM,yBAAyB;AAE/B,SAAS,aAAa,KAAqB;CACzC,OAAO,IAAI,SAAS,GAAG,IAAI,IAAI,MAAM,GAAG,EAAE,IAAI;AAChD;AAEA,SAAS,iBAAiB,KAAqB;CAC7C,MAAM,YAAY,IAAI,QAAQ,GAAG;CAEjC,OAAO,aAAa,IAAI,IAAI,MAAM,GAAG,SAAS,IAAI;AACpD;AAEA,SAAS,uBAAuB,OAAuB;CACrD,OAAO,MAAM,WAAW,KAAK,IAAI,EAAE,WAAW,KAAK,IAAI;AACzD;AAEA,SAAS,cAAc,MAAwB;C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;;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,QACpB,SACA,OACA,UAAyB,CAAC,GACT;CACjB,IAAI,mBAAmB,KAAK,KAAK,SAAS,KAAK,GAC7C,OAAO;CAGT,IAAI;CAEJ,MAAM,UAAU,eAAe,KAAK;CACpC,MAAM,OAAO,YAAY,SAAS,KAAK;CAEvC,MAAM,gBAAgB,UAAU,kBAAkB,OAAO,GAAG,GAAG,KAAK,MAAM;CAC1E,IACE,QAAQ,OAAO,cAAc,QAC7B,QAAQ,GAAG,WAAW,aAAa,GACnC;EACA,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK,aAAa;EAClD,IAAI,QACF,SAAS;GACP;GACA;GACA,QAAQ,KAAK,MAAM,MAAM;EAC3B;CAEJ;CAEA,WAAW,MAAM,wBAAwB,SAAS,OAAO,OAAO;CAChE,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MACR,+NACF;CAGF,IAAI,QAAQ,OAAO,cAAc,MAC/B,MAAM,YAAY,SAAS,MAAM;CAGnC,OAAO;AACT"}
|
package/dist/resolve.cjs
CHANGED
|
@@ -15,15 +15,14 @@ let yaml = require("yaml");
|
|
|
15
15
|
* Compiles a type definition to a module and returns the module.
|
|
16
16
|
*
|
|
17
17
|
* @param context - The context object containing the environment paths.
|
|
18
|
-
* @param
|
|
18
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
19
19
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
20
20
|
* @returns A promise that resolves to the compiled module.
|
|
21
21
|
*/
|
|
22
|
-
async function resolveModule(context,
|
|
23
|
-
|
|
24
|
-
if ((
|
|
25
|
-
|
|
26
|
-
const result = await require_bundle.bundle(context, typeDefinition.file, overrides);
|
|
22
|
+
async function resolveModule(context, input, overrides) {
|
|
23
|
+
const fileReference = (0, _stryke_convert_extract_file_reference.extractFileReference)(input);
|
|
24
|
+
if (!fileReference) throw new Error(`Failed to extract a file reference from the provided input ${JSON.stringify(input)}. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);
|
|
25
|
+
const result = await require_bundle.bundle(context, fileReference.file, overrides);
|
|
27
26
|
let resolved;
|
|
28
27
|
try {
|
|
29
28
|
resolved = await context.resolver.evalModule(result.text, {
|
|
@@ -33,12 +32,12 @@ async function resolveModule(context, type, overrides) {
|
|
|
33
32
|
} catch (error) {
|
|
34
33
|
if ((0, _stryke_type_checks_is_set_string.isSetString)(error.message) && new RegExp(`Cannot find module '${context.config.framework?.name || "powerlines"}:.*'`).test(error.message)) {
|
|
35
34
|
const moduleName = error.message.match(new RegExp(`Cannot find module '(${context.config.framework?.name || "powerlines"}:.*)'`))?.[1];
|
|
36
|
-
throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${
|
|
35
|
+
throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${fileReference.file}". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
|
|
37
36
|
|
|
38
37
|
Bundle output for module:
|
|
39
38
|
${result.text}` : ""}`);
|
|
40
39
|
}
|
|
41
|
-
throw new Error(`Failed to evaluate the bundled module for "${
|
|
40
|
+
throw new Error(`Failed to evaluate the bundled module for "${fileReference.file}". Error: ${error.message}${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
|
|
42
41
|
|
|
43
42
|
Bundle output for module:
|
|
44
43
|
${result.text}` : ""}`);
|
package/dist/resolve.d.cts
CHANGED
|
@@ -8,11 +8,11 @@ import { FileReference, FileReferenceInput } from "@stryke/types/configuration";
|
|
|
8
8
|
* Compiles a type definition to a module and returns the module.
|
|
9
9
|
*
|
|
10
10
|
* @param context - The context object containing the environment paths.
|
|
11
|
-
* @param
|
|
11
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
12
12
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
13
13
|
* @returns A promise that resolves to the compiled module.
|
|
14
14
|
*/
|
|
15
|
-
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext,
|
|
15
|
+
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, input: FileReferenceInput, overrides?: BundleOptions): Promise<TResult>;
|
|
16
16
|
/**
|
|
17
17
|
* Compiles a type definition to a module and returns the specified export from the module.
|
|
18
18
|
*
|
package/dist/resolve.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,
|
|
1
|
+
{"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;;;;;;;;iBAuEW,OAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;;;iBAiGW,iBAAA,kBACH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,aAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,IAAA"}
|
package/dist/resolve.d.mts
CHANGED
|
@@ -8,11 +8,11 @@ import { FileReference, FileReferenceInput } from "@stryke/types/configuration";
|
|
|
8
8
|
* Compiles a type definition to a module and returns the module.
|
|
9
9
|
*
|
|
10
10
|
* @param context - The context object containing the environment paths.
|
|
11
|
-
* @param
|
|
11
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
12
12
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
13
13
|
* @returns A promise that resolves to the compiled module.
|
|
14
14
|
*/
|
|
15
|
-
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext,
|
|
15
|
+
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, input: FileReferenceInput, overrides?: BundleOptions): Promise<TResult>;
|
|
16
16
|
/**
|
|
17
17
|
* Compiles a type definition to a module and returns the specified export from the module.
|
|
18
18
|
*
|
package/dist/resolve.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,
|
|
1
|
+
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;;;;;;;;iBAuEW,OAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;;;iBAiGW,iBAAA,kBACH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,aAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,IAAA"}
|
package/dist/resolve.mjs
CHANGED
|
@@ -13,15 +13,14 @@ import { parse as parse$1 } from "yaml";
|
|
|
13
13
|
* Compiles a type definition to a module and returns the module.
|
|
14
14
|
*
|
|
15
15
|
* @param context - The context object containing the environment paths.
|
|
16
|
-
* @param
|
|
16
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
17
17
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
18
18
|
* @returns A promise that resolves to the compiled module.
|
|
19
19
|
*/
|
|
20
|
-
async function resolveModule(context,
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
const result = await bundle(context, typeDefinition.file, overrides);
|
|
20
|
+
async function resolveModule(context, input, overrides) {
|
|
21
|
+
const fileReference = extractFileReference(input);
|
|
22
|
+
if (!fileReference) throw new Error(`Failed to extract a file reference from the provided input ${JSON.stringify(input)}. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);
|
|
23
|
+
const result = await bundle(context, fileReference.file, overrides);
|
|
25
24
|
let resolved;
|
|
26
25
|
try {
|
|
27
26
|
resolved = await context.resolver.evalModule(result.text, {
|
|
@@ -31,12 +30,12 @@ async function resolveModule(context, type, overrides) {
|
|
|
31
30
|
} catch (error) {
|
|
32
31
|
if (isSetString(error.message) && new RegExp(`Cannot find module '${context.config.framework?.name || "powerlines"}:.*'`).test(error.message)) {
|
|
33
32
|
const moduleName = error.message.match(new RegExp(`Cannot find module '(${context.config.framework?.name || "powerlines"}:.*)'`))?.[1];
|
|
34
|
-
throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${
|
|
33
|
+
throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${fileReference.file}". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
|
|
35
34
|
|
|
36
35
|
Bundle output for module:
|
|
37
36
|
${result.text}` : ""}`);
|
|
38
37
|
}
|
|
39
|
-
throw new Error(`Failed to evaluate the bundled module for "${
|
|
38
|
+
throw new Error(`Failed to evaluate the bundled module for "${fileReference.file}". Error: ${error.message}${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
|
|
40
39
|
|
|
41
40
|
Bundle output for module:
|
|
42
41
|
${result.text}` : ""}`);
|
package/dist/resolve.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":["parseYaml","parseToml"],"sources":["../src/resolve.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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { findFileDotExtension, findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { FileReference, FileReferenceInput } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { parse as parseYaml } from \"yaml\";\nimport { bundle, BundleOptions } from \"./bundle\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param type - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n type: FileReference,\n overrides?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: FileReference;\n if (isSetString(type)) {\n typeDefinition = extractFileReference(type) as FileReference;\n } else {\n typeDefinition = type;\n }\n\n const result = await bundle<TContext>(\n context,\n typeDefinition.file,\n overrides\n );\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.text, {\n filename: result.path,\n ext: findFileDotExtension(result.path)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n typeDefinition.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n typeDefinition.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolve<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n options?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension.startsWith(\"json\")) {\n try {\n const json = await context.fs.read(fileReference.file);\n if (!isSetString(json)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid JSON.`\n );\n }\n\n return JSON.parse(json) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the JSON file at \"${fileReference.file}\". Please ensure the file exists and contains valid JSON. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"yaml\" || extension === \"yml\") {\n try {\n const yaml = await context.fs.read(fileReference.file);\n if (!isSetString(yaml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid YAML.`\n );\n }\n\n return parseYaml(yaml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the YAML file at \"${fileReference.file}\". Please ensure the file exists and contains valid YAML. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"toml\") {\n try {\n const toml = await context.fs.read(fileReference.file);\n if (!isSetString(toml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid TOML.`\n );\n }\n\n return parseToml(toml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the TOML file at \"${fileReference.file}\". Please ensure the file exists and contains valid TOML. Error: ${(error as Error).message}`\n );\n }\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n fileReference,\n options\n );\n\n let exportName = fileReference.export;\n if (!exportName) {\n exportName = \"default\";\n }\n\n const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];\n if (resolvedExport === undefined) {\n throw new Error(\n `The export \"${exportName}\" could not be resolved in the \"${\n fileReference.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n fileReference.file\n }\" module has a \"${exportName}\" export with the desired value.`\n : `After bundling, the available exports were: ${Object.keys(\n resolved\n ).join(\n \", \"\n )}. Please ensure that the export exists and is correctly named.`\n }`\n );\n }\n\n return resolvedExport;\n}\n\n/**\n * Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the Deepkit Type reflection.\n */\nexport async function resolveReflection<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n input: FileReference,\n options?: BundleOptions\n): Promise<Type> {\n return reflect(\n await resolve<Type>(\n context,\n input,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n )\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,eAAsB,cAIpB,SACA,MACA,WACkB;CAClB,IAAI;CACJ,IAAI,YAAY,IAAI,GAClB,iBAAiB,qBAAqB,IAAI;MAE1C,iBAAiB;CAGnB,MAAM,SAAS,MAAM,OACnB,SACA,eAAe,MACf,SACF;CAEA,IAAI;CACJ,IAAI;EACF,WAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAAK,qBAAqB,OAAO,IAAI;EACvC,CAAC;CACH,SAAS,OAAO;EACd,IACE,YAAa,MAAgB,OAAO,KACpC,IAAI,OACF,uBAAuB,QAAQ,OAAO,WAAW,QAAQ,aAAa,KACxE,EAAE,KAAM,MAAgB,OAAO,GAC/B;GACA,MAAM,aAAc,MAAgB,QAAQ,MAC1C,IAAI,OACF,wBAAwB,QAAQ,OAAO,WAAW,QAAQ,aAAa,MACzE,CACF,IAAI;GACJ,MAAM,IAAI,MACR,eAAe,WAAW,4CACxB,eAAe,KAChB,uHACC,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGZ,OAAO,SACK,IAER;EACF;EAEA,MAAM,IAAI,MACR,8CACE,eAAe,KAChB,YAAa,MAAgB,UAC5B,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGV,OAAO,SACG,IAER;CACF;CAEA,OAAO;AACT;;;;;;;;;AAUA,eAAsB,QAIpB,SACA,OACA,SACkB;CAClB,MAAM,gBA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E,cAAc,KACf,kBAAkB,WAAW,oCAC9B,+CAA+C,OAAO,KACpD,QACF,EAAE,KACA,IACF,EAAE,iEAEV;CAGF,OAAO;AACT;;;;;;;;;AAUA,eAAsB,kBAGpB,SACA,OACA,SACe;CACf,OAAO,QACL,MAAM,QACJ,SACA,OACA,KAAK,SAAS,EACZ,SAAS,CACP,cAAc,SAAS;EACrB,YAAY;EACZ,OAAO;CACT,CAAC,CACH,EACF,CAAC,CACH,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"resolve.mjs","names":["parseYaml","parseToml"],"sources":["../src/resolve.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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { findFileDotExtension, findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { FileReference, FileReferenceInput } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { parse as parseYaml } from \"yaml\";\nimport { bundle, BundleOptions } from \"./bundle\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n overrides?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input ${JSON.stringify(\n input\n )}. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const result = await bundle<TContext>(context, fileReference.file, overrides);\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.text, {\n filename: result.path,\n ext: findFileDotExtension(result.path)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n fileReference.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n fileReference.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolve<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n options?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension.startsWith(\"json\")) {\n try {\n const json = await context.fs.read(fileReference.file);\n if (!isSetString(json)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid JSON.`\n );\n }\n\n return JSON.parse(json) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the JSON file at \"${fileReference.file}\". Please ensure the file exists and contains valid JSON. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"yaml\" || extension === \"yml\") {\n try {\n const yaml = await context.fs.read(fileReference.file);\n if (!isSetString(yaml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid YAML.`\n );\n }\n\n return parseYaml(yaml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the YAML file at \"${fileReference.file}\". Please ensure the file exists and contains valid YAML. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"toml\") {\n try {\n const toml = await context.fs.read(fileReference.file);\n if (!isSetString(toml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid TOML.`\n );\n }\n\n return parseToml(toml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the TOML file at \"${fileReference.file}\". Please ensure the file exists and contains valid TOML. Error: ${(error as Error).message}`\n );\n }\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n fileReference,\n options\n );\n\n let exportName = fileReference.export;\n if (!exportName) {\n exportName = \"default\";\n }\n\n const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];\n if (resolvedExport === undefined) {\n throw new Error(\n `The export \"${exportName}\" could not be resolved in the \"${\n fileReference.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n fileReference.file\n }\" module has a \"${exportName}\" export with the desired value.`\n : `After bundling, the available exports were: ${Object.keys(\n resolved\n ).join(\n \", \"\n )}. Please ensure that the export exists and is correctly named.`\n }`\n );\n }\n\n return resolvedExport;\n}\n\n/**\n * Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the Deepkit Type reflection.\n */\nexport async function resolveReflection<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n input: FileReference,\n options?: BundleOptions\n): Promise<Type> {\n return reflect(\n await resolve<Type>(\n context,\n input,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n )\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,eAAsB,cAIpB,SACA,OACA,WACkB;CAClB,MAAM,gBAAgB,qBAAqB,KAAK;CAChD,IAAI,CAAC,eACH,MAAM,IAAI,MACR,8DAA8D,KAAK,UACjE,KACF,EAAE,wHACJ;CAGF,MAAM,SAAS,MAAM,OAAiB,SAAS,cAAc,MAAM,SAAS;CAE5E,IAAI;CACJ,IAAI;EACF,WAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAAK,qBAAqB,OAAO,IAAI;EACvC,CAAC;CACH,SAAS,OAAO;EACd,IACE,YAAa,MAAgB,OAAO,KACpC,IAAI,OACF,uBAAuB,QAAQ,OAAO,WAAW,QAAQ,aAAa,KACxE,EAAE,KAAM,MAAgB,OAAO,GAC/B;GACA,MAAM,aAAc,MAAgB,QAAQ,MAC1C,IAAI,OACF,wBAAwB,QAAQ,OAAO,WAAW,QAAQ,aAAa,MACzE,CACF,IAAI;GACJ,MAAM,IAAI,MACR,eAAe,WAAW,4CACxB,cAAc,KACf,uHACC,QAAQ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ACR,6CAA6C,cAAc,KAAK,mEAAoE,MAAgB,SACtJ;CACF;CAGF,MAAM,WAAW,MAAM,cACrB,SACA,eACA,OACF;CAEA,IAAI,aAAa,cAAc;CAC/B,IAAI,CAAC,YACH,aAAa;CAGf,MAAM,iBAAiB,SAAS,eAAe,SAAS,MAAM;CAC9D,IAAI,mBAAmB,QACrB,MAAM,IAAI,MACR,eAAe,WAAW,kCACxB,cAAc,KACf,YACC,OAAO,KAAK,QAAQ,EAAE,WAAW,IAC7B,gFACE,cAAc,KACf,kBAAkB,WAAW,oCAC9B,+CAA+C,OAAO,KACpD,QACF,EAAE,KACA,IACF,EAAE,iEAEV;CAGF,OAAO;AACT;;;;;;;;;AAUA,eAAsB,kBAGpB,SACA,OACA,SACe;CACf,OAAO,QACL,MAAM,QACJ,SACA,OACA,KAAK,SAAS,EACZ,SAAS,CACP,cAAc,SAAS;EACrB,YAAY;EACZ,OAAO;CACT,CAAC,CACH,EACF,CAAC,CACH,CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/schema",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.62",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"keywords": [
|
|
@@ -59,19 +59,19 @@
|
|
|
59
59
|
"typings": "dist/index.d.mts",
|
|
60
60
|
"files": ["dist"],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@powerlines/core": "^0.48.
|
|
63
|
-
"@powerlines/deepkit": "^0.9.
|
|
64
|
-
"@powerlines/unplugin": "^0.0.
|
|
62
|
+
"@powerlines/core": "^0.48.21",
|
|
63
|
+
"@powerlines/deepkit": "^0.9.53",
|
|
64
|
+
"@powerlines/unplugin": "^0.0.69",
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
66
|
-
"@stryke/convert": "^0.7.
|
|
67
|
-
"@stryke/hash": "^0.13.
|
|
68
|
-
"@stryke/helpers": "^0.10.
|
|
69
|
-
"@stryke/json": "^0.15.
|
|
70
|
-
"@stryke/path": "^0.29.
|
|
71
|
-
"@stryke/string-format": "^0.17.
|
|
72
|
-
"@stryke/type-checks": "^0.6.
|
|
73
|
-
"@stryke/types": "^0.12.
|
|
74
|
-
"@stryke/zod": "^0.3.
|
|
66
|
+
"@stryke/convert": "^0.7.10",
|
|
67
|
+
"@stryke/hash": "^0.13.32",
|
|
68
|
+
"@stryke/helpers": "^0.10.19",
|
|
69
|
+
"@stryke/json": "^0.15.3",
|
|
70
|
+
"@stryke/path": "^0.29.6",
|
|
71
|
+
"@stryke/string-format": "^0.17.21",
|
|
72
|
+
"@stryke/type-checks": "^0.6.12",
|
|
73
|
+
"@stryke/types": "^0.12.7",
|
|
74
|
+
"@stryke/zod": "^0.3.25",
|
|
75
75
|
"@valibot/to-json-schema": "^1.7.0",
|
|
76
76
|
"ajv": "^8.20.0",
|
|
77
77
|
"ajv-formats": "^3.0.1",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"zod": { "optional": true }
|
|
97
97
|
},
|
|
98
98
|
"publishConfig": { "access": "public" },
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "522229ca4642e0d36d6e5426a70522b711a9fa91"
|
|
100
100
|
}
|