@powerlines/schema 0.11.68 → 0.11.70
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/_virtual/_rolldown/runtime.cjs +8 -0
- package/dist/bundle.cjs +8 -0
- package/dist/bundle.d.mts +2 -0
- package/dist/bundle.d.mts.map +1 -1
- package/dist/bundle.mjs +8 -0
- package/dist/bundle.mjs.map +1 -1
- package/dist/codegen.cjs +8 -0
- package/dist/codegen.d.mts +2 -0
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +8 -0
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +8 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +11 -0
- package/dist/extract.d.cts +3 -0
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +5 -0
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +11 -0
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +8 -0
- package/dist/helpers.d.mts +2 -0
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +8 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +8 -0
- package/dist/metadata.cjs +8 -0
- package/dist/metadata.d.mts +2 -0
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +8 -0
- package/dist/metadata.mjs.map +1 -1
- package/dist/persistence.cjs +8 -0
- package/dist/persistence.d.mts +2 -0
- package/dist/persistence.d.mts.map +1 -1
- package/dist/persistence.mjs +8 -0
- package/dist/persistence.mjs.map +1 -1
- package/dist/reflection.cjs +8 -0
- package/dist/reflection.d.mts +2 -0
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +8 -0
- package/dist/reflection.mjs.map +1 -1
- package/dist/resolve.cjs +8 -0
- package/dist/resolve.d.mts +2 -0
- package/dist/resolve.d.mts.map +1 -1
- package/dist/resolve.mjs +8 -0
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +8 -0
- package/dist/type-checks.d.mts +2 -0
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +8 -0
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.mts +2 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/validate.cjs +8 -0
- package/dist/validate.mjs +8 -0
- package/dist/validate.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
10
|
const require_bundle = require('./bundle.cjs');
|
|
3
11
|
const require_constants = require('./constants.cjs');
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
1
3
|
import { BundleOptions, bundle } from "./bundle.mjs";
|
|
2
4
|
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
|
|
3
5
|
import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;YAmBY,UAAA;IACR,EAAA;IACA,KAAA;IACA,WAAA;IACA,IAAA;IACA,KAAA;IACA,IAAA;IACA,UAAA;IACA,MAAA;IACA,MAAA;IACA,QAAA;IACA,OAAA;IACA,QAAA;IACA,QAAA;IACA,SAAA;IACA,eAAA;IACA,gBAAA;IACA,aAAA;IAAA,CACC,OAAA;EAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { bundle } from "./bundle.mjs";
|
|
2
10
|
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
|
|
3
11
|
import { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes } from "./metadata.mjs";
|
package/dist/metadata.cjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
const require_constants = require('./constants.cjs');
|
|
2
10
|
let _stryke_type_checks = require("@stryke/type-checks");
|
|
3
11
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
package/dist/metadata.d.mts
CHANGED
package/dist/metadata.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/metadata.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;;;;;;;;iBAuCgB,uBAAA,CACd,MAAA,EAAQ,UAAA,EACR,QAAA,EAAU,0BAAA,eACT,UAAA;;;AAHH;;;;;;;iBA6BgB,eAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB;;;;;;;iBA6BV,oBAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB"}
|
package/dist/metadata.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { JSON_SCHEMA_METADATA_KEYS } from "./constants.mjs";
|
|
2
10
|
import { isSetString } from "@stryke/type-checks";
|
|
3
11
|
import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object";
|
package/dist/metadata.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.mjs","names":["isSetObject"],"sources":["../src/metadata.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 { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaMetadataKeywords,\n JsonSchemaPrimitiveType,\n JsonSchemaType\n} from \"./types\";\n\ninterface JsonSchemaTypeView {\n type?: JsonSchemaType | readonly JsonSchemaType[];\n}\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applyJsonSchemaMetadata(\n schema: JsonSchema,\n metadata: JsonSchemaMetadataKeywords | undefined\n): JsonSchema {\n if (!metadata || !isSetObject(schema)) {\n return schema;\n }\n\n const result: JsonSchema = { ...schema };\n const mutableResult = result as Record<string, unknown>;\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n mutableResult[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType[] {\n if (!isSetObject(schema)) {\n return [];\n }\n\n const objectSchema = schema as JsonSchemaTypeView;\n\n if (Array.isArray(objectSchema.type)) {\n return objectSchema.type.filter(\n (type: JsonSchemaPrimitiveType): type is JsonSchemaPrimitiveType =>\n isSetString(type)\n );\n }\n if (\n isSetString(objectSchema.type) &&\n objectSchema.type !== \"object\" &&\n objectSchema.type !== \"array\"\n ) {\n return [objectSchema.type];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata.mjs","names":["isSetObject"],"sources":["../src/metadata.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 { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaMetadataKeywords,\n JsonSchemaPrimitiveType,\n JsonSchemaType\n} from \"./types\";\n\ninterface JsonSchemaTypeView {\n type?: JsonSchemaType | readonly JsonSchemaType[];\n}\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applyJsonSchemaMetadata(\n schema: JsonSchema,\n metadata: JsonSchemaMetadataKeywords | undefined\n): JsonSchema {\n if (!metadata || !isSetObject(schema)) {\n return schema;\n }\n\n const result: JsonSchema = { ...schema };\n const mutableResult = result as Record<string, unknown>;\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n mutableResult[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType[] {\n if (!isSetObject(schema)) {\n return [];\n }\n\n const objectSchema = schema as JsonSchemaTypeView;\n\n if (Array.isArray(objectSchema.type)) {\n return objectSchema.type.filter(\n (type: JsonSchemaPrimitiveType): type is JsonSchemaPrimitiveType =>\n isSetString(type)\n );\n }\n if (\n isSetString(objectSchema.type) &&\n objectSchema.type !== \"object\" &&\n objectSchema.type !== \"array\"\n ) {\n return [objectSchema.type];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,wBACd,QACA,UACY;CACZ,IAAI,CAAC,YAAY,CAACA,cAAY,MAAM,GAClC,OAAO;CAGT,MAAM,SAAqB,EAAE,GAAG,OAAO;CACvC,MAAM,gBAAgB;CACtB,KAAK,MAAM,OAAO,2BAA2B;EAC3C,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,UAAa,UAAU,MACnC,cAAc,OAAO;CAEzB;CAEA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,gBACd,QAC2B;CAC3B,IAAI,CAACA,cAAY,MAAM,GACrB,OAAO,CAAC;CAGV,MAAM,eAAe;CAErB,IAAI,MAAM,QAAQ,aAAa,IAAI,GACjC,OAAO,aAAa,KAAK,QACtB,SACC,YAAY,IAAI,CACpB;CAEF,IACE,YAAY,aAAa,IAAI,KAC7B,aAAa,SAAS,YACtB,aAAa,SAAS,SAEtB,OAAO,CAAC,aAAa,IAAI;CAE3B,OAAO,CAAC;AACV;;;;;;;AAQA,SAAgB,qBACd,QACqC;CACrC,IAAI,CAACA,cAAY,MAAM,GACrB;CAGF,OAAO,gBAAgB,MAAM,EAAE,MAAK,SAAQ,SAAS,MAAM;AAC7D"}
|
package/dist/persistence.cjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
const require_type_checks = require('./type-checks.cjs');
|
|
2
10
|
const require_extract = require('./extract.cjs');
|
|
3
11
|
let _stryke_path_join = require("@stryke/path/join");
|
package/dist/persistence.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.mts","names":[],"sources":["../src/persistence.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"persistence.d.mts","names":[],"sources":["../src/persistence.ts"],"mappings":";;;;;;;;;;;;iBA8BgB,iBAAA,CAAkB,OAAgB,EAAP,OAAO;;;;AAAlD;;;;iBAWgB,gBAAA,CAAiB,OAAA,EAAS,OAAA,EAAS,KAAA,EAAO,WAAW;AAArE;;;;;;;AAAA,iBAcsB,WAAA,CAAY,OAAA,EAAS,OAAA,EAAS,MAAA,EAAQ,MAAA,GAAM,OAAA;;AAdG;AAcrE;;;;;iBAoBsB,cAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA;;;;;;;;;iBAsBW,UAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA"}
|
package/dist/persistence.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { isSchema } from "./type-checks.mjs";
|
|
2
10
|
import { extractHash, extractVariant } from "./extract.mjs";
|
|
3
11
|
import { joinPaths } from "@stryke/path/join";
|
package/dist/persistence.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.mjs","names":[],"sources":["../src/persistence.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 { joinPaths } from \"@stryke/path/join\";\nimport { extractHash, extractVariant } from \"./extract\";\nimport { isSchema } from \"./type-checks\";\nimport { Schema, SchemaInput } from \"./types\";\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory(context: Context): string {\n return joinPaths(context.cachePath, \"schemas\");\n}\n\n/**\n * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).\n *\n * @param context - The context object providing access to the cache path.\n * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.\n * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.\n */\nexport function getCacheFilePath(context: Context, input: SchemaInput): string {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n return joinPaths(getCacheDirectory(context), `${hash}.json`);\n}\n\n/**\n * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.\n * @throws Will throw an error if the provided input is not a valid schema.\n */\nexport async function writeSchema(context: Context, schema: Schema) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, schema),\n JSON.stringify(schema.schema)\n );\n}\n\n/**\n * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the cache path provided in the context and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.\n */\nexport async function readSchemaSafe(\n context: Context,\n input: SchemaInput\n): Promise<Schema | undefined> {\n const cacheFilePath = getCacheFilePath(context, input);\n if (!(await context.fs.exists(cacheFilePath))) {\n return undefined;\n }\n\n const data = await context.fs.read(cacheFilePath);\n if (!data) {\n return undefined;\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.\n * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.\n */\nexport async function readSchema(\n context: Context,\n input: SchemaInput\n): Promise<Schema> {\n const schema = await readSchemaSafe(context, input);\n if (!schema) {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n throw new Error(\n `The ${variant} schema with hash \"${\n hash\n }\" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`\n );\n }\n\n return schema;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"persistence.mjs","names":[],"sources":["../src/persistence.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 { joinPaths } from \"@stryke/path/join\";\nimport { extractHash, extractVariant } from \"./extract\";\nimport { isSchema } from \"./type-checks\";\nimport { Schema, SchemaInput } from \"./types\";\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory(context: Context): string {\n return joinPaths(context.cachePath, \"schemas\");\n}\n\n/**\n * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).\n *\n * @param context - The context object providing access to the cache path.\n * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.\n * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.\n */\nexport function getCacheFilePath(context: Context, input: SchemaInput): string {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n return joinPaths(getCacheDirectory(context), `${hash}.json`);\n}\n\n/**\n * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.\n * @throws Will throw an error if the provided input is not a valid schema.\n */\nexport async function writeSchema(context: Context, schema: Schema) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, schema),\n JSON.stringify(schema.schema)\n );\n}\n\n/**\n * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the cache path provided in the context and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.\n */\nexport async function readSchemaSafe(\n context: Context,\n input: SchemaInput\n): Promise<Schema | undefined> {\n const cacheFilePath = getCacheFilePath(context, input);\n if (!(await context.fs.exists(cacheFilePath))) {\n return undefined;\n }\n\n const data = await context.fs.read(cacheFilePath);\n if (!data) {\n return undefined;\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.\n * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.\n */\nexport async function readSchema(\n context: Context,\n input: SchemaInput\n): Promise<Schema> {\n const schema = await readSchemaSafe(context, input);\n if (!schema) {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n throw new Error(\n `The ${variant} schema with hash \"${\n hash\n }\" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`\n );\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBAAkB,SAA0B;CAC1D,OAAO,UAAU,QAAQ,WAAW,SAAS;AAC/C;;;;;;;;AASA,SAAgB,iBAAiB,SAAkB,OAA4B;CAE7E,MAAM,OAAO,YADG,eAAe,KACA,GAAG,KAAK;CAEvC,OAAO,UAAU,kBAAkB,OAAO,GAAG,GAAG,KAAK,MAAM;AAC7D;;;;;;;;AASA,eAAsB,YAAY,SAAkB,QAAgB;CAClE,IAAI,CAAC,SAAS,MAAM,GAClB,MAAM,IAAI,MACR,4LACF;CAGF,MAAM,QAAQ,GAAG,MACf,iBAAiB,SAAS,MAAM,GAChC,KAAK,UAAU,OAAO,MAAM,CAC9B;AACF;;;;;;;;AASA,eAAsB,eACpB,SACA,OAC6B;CAC7B,MAAM,gBAAgB,iBAAiB,SAAS,KAAK;CACrD,IAAI,CAAE,MAAM,QAAQ,GAAG,OAAO,aAAa,GACzC;CAGF,MAAM,OAAO,MAAM,QAAQ,GAAG,KAAK,aAAa;CAChD,IAAI,CAAC,MACH;CAGF,OAAO,KAAK,MAAM,IAAI;AACxB;;;;;;;;;AAUA,eAAsB,WACpB,SACA,OACiB;CACjB,MAAM,SAAS,MAAM,eAAe,SAAS,KAAK;CAClD,IAAI,CAAC,QAAQ;EACX,MAAM,UAAU,eAAe,KAAK;EACpC,MAAM,OAAO,YAAY,SAAS,KAAK;EAEvC,MAAM,IAAI,MACR,OAAO,QAAQ,qBACb,KACD,+OACH;CACF;CAEA,OAAO;AACT"}
|
package/dist/reflection.cjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
10
|
const require_type_checks = require('./type-checks.cjs');
|
|
3
11
|
const require_codegen = require('./codegen.cjs');
|
package/dist/reflection.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;;;;iBAgKgB,sBAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAU"}
|
package/dist/reflection.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { isJsonSchemaObject, isJsonSchemaPrimitiveType, isNullOnlyJsonSchema } from "./type-checks.mjs";
|
|
2
10
|
import { getJsonSchemaType } from "./codegen.mjs";
|
|
3
11
|
import defu from "defu";
|
package/dist/reflection.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflection.mjs","names":[],"sources":["../src/reflection.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 {\n TagsReflection,\n Type,\n TypeClass\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionClass,\n ReflectionKind,\n TypeNumberBrand,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n isBigInt,\n isBoolean,\n isInteger,\n isNull,\n isNumber,\n isRegExp,\n isSetArray,\n isSetObject,\n isSetString,\n isString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { getJsonSchemaType } from \"./codegen\";\nimport {\n isJsonSchemaObject,\n isJsonSchemaPrimitiveType,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaNullable,\n JsonSchemaObject,\n JsonSchemaPrimitiveType\n} from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.\n *\n * @remarks\n * This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.\n *\n * @param brand - The Deepkit numeric brand to convert.\n * @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.\n */\nfunction numberBrandToJsonSchema(\n brand: TypeNumberBrand | undefined\n): JsonSchema {\n switch (brand) {\n case TypeNumberBrand.integer:\n return {\n type: \"integer\",\n format: \"int32\",\n multipleOf: 1\n };\n case TypeNumberBrand.int8:\n return { type: \"integer\", format: \"int8\", multipleOf: 1 };\n case TypeNumberBrand.uint8:\n return { type: \"integer\", format: \"uint8\", multipleOf: 1 };\n case TypeNumberBrand.int16:\n return { type: \"integer\", format: \"int16\", multipleOf: 1 };\n case TypeNumberBrand.uint16:\n return { type: \"integer\", format: \"uint16\", multipleOf: 1 };\n case TypeNumberBrand.int32:\n return { type: \"integer\", format: \"int32\", multipleOf: 1 };\n case TypeNumberBrand.uint32:\n return { type: \"integer\", format: \"uint32\", multipleOf: 1 };\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return { type: \"number\", format: \"float\" };\n case TypeNumberBrand.float64:\n return { type: \"number\", format: \"double\" };\n case undefined:\n default:\n return { type: \"number\" };\n }\n}\n\nfunction withReflectionTags(reflection: Type, schema: JsonSchema): JsonSchema {\n if (\n !isSetObject(schema) ||\n !isSetObject((reflection as { tags?: TagsReflection })?.tags)\n ) {\n return schema;\n }\n\n const updatedSchema = { ...schema };\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n updatedSchema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n updatedSchema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n updatedSchema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n updatedSchema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n updatedSchema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n updatedSchema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n updatedSchema.readOnly = tags.readonly;\n }\n\n return updatedSchema;\n}\n\nfunction withNullable(schema: JsonSchema): JsonSchemaNullable {\n if (!isSetObject(schema)) {\n return {\n anyOf: [schema, { type: \"null\", default: null }]\n };\n }\n\n const rawType = (schema as { type?: string | readonly string[] }).type;\n\n const types = Array.isArray(rawType)\n ? [...rawType]\n : rawType\n ? [rawType]\n : [];\n if (!types.includes(\"null\")) {\n types.push(\"null\");\n }\n\n return {\n ...schema,\n type: types.length === 1 ? types[0] : types\n };\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema(\n reflection: Type\n): JsonSchema | undefined {\n return reflectionToJsonSchemaInner(reflection);\n}\n\nfunction reflectionToJsonSchemaInner(reflection: Type): JsonSchema | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags(reflection, {\n type: \"null\",\n name: reflection.typeName,\n default: null\n });\n case ReflectionKind.string:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags(reflection, numeric);\n }\n case ReflectionKind.bigint:\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\"\n });\n case ReflectionKind.regexp:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n contentMediaType: \"text/regex\"\n });\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (isBigInt(literal)) {\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n const: literal\n });\n }\n\n if (isRegExp(literal)) {\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n\n return withReflectionTags(reflection, {\n type: getJsonSchemaType(literal),\n name: reflection.typeName,\n const: literal\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n isString(value) ||\n isInteger(value) ||\n isBigInt(value) ||\n isNumber(value) ||\n isBoolean(value) ||\n isNull(value)\n ) as (string | number | bigint | boolean | null)[];\n if (values.length === 0) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: []\n });\n }\n\n return withReflectionTags(reflection, {\n type: values.every(value => isString(value))\n ? \"string\"\n : values.every(value => isInteger(value) || isBigInt(value))\n ? \"integer\"\n : values.every(value => isNumber(value))\n ? \"number\"\n : values.every(value => isBoolean(value))\n ? \"boolean\"\n : values.every(value => isNull(value))\n ? \"null\"\n : values.reduce((ret, value) => {\n const type = getJsonSchemaType(value);\n if (\n isJsonSchemaPrimitiveType(type) &&\n !ret.includes(type)\n ) {\n ret.push(type);\n }\n\n return ret;\n }, [] as JsonSchemaPrimitiveType[]),\n name: reflection.typeName,\n description: reflection.description,\n enum: values,\n default: values.length === 1 ? values[0] : undefined\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner(reflection.type);\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items ?? {}\n });\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchemaInner(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items.length === 1 ? items[0] : {}\n });\n }\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n prefixItems: items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((branch): branch is JsonSchema => branch !== undefined);\n if (\n !reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n )\n ) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: branches\n });\n }\n\n const nonNull = branches.filter(branch => !isNullOnlyJsonSchema(branch));\n if (nonNull.length === 0) {\n return withReflectionTags(reflection, {\n type: \"null\",\n default: null\n });\n }\n\n if (nonNull.length === 1) {\n const first = nonNull[0]!;\n\n if (!isSetObject(first)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: [first]\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(first as Record<string, unknown>)\n })\n );\n }\n\n const enumValues = nonNull\n .map(branch =>\n isSetObject(branch)\n ? (branch as { const?: unknown }).const\n : undefined\n )\n .filter(\n (value): value is string | number | bigint | boolean | null =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n typeof value === \"boolean\"\n );\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n enum: enumValues\n })\n );\n }\n\n const discriminator = tryReflectionDiscriminator(reflection.types);\n if (discriminator && isSetObject(discriminator)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(discriminator as Record<string, unknown>)\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n })\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n if (!isSetObject(members[0])) {\n return members[0];\n }\n\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJsonSchema(reflection);\n case ReflectionKind.class: {\n const classType = reflection.classType as { name?: string } | undefined;\n const className = classType?.name;\n switch (className) {\n case \"Date\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner(itemType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"array\",\n items: items ?? {},\n uniqueItems: true\n });\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJsonSchemaInner(valueType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"object\",\n additionalProperties: values ?? true\n });\n }\n case \"Uint8Array\":\n case \"Uint8ClampedArray\":\n case \"Uint16Array\":\n case \"Uint32Array\":\n case \"Int8Array\":\n case \"Int16Array\":\n case \"Int32Array\":\n case \"Float32Array\":\n case \"Float64Array\":\n case \"BigInt64Array\":\n case \"BigUint64Array\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n ...objectReflectionToJsonSchema(reflection)\n });\n }\n }\n case ReflectionKind.symbol:\n case ReflectionKind.property:\n case ReflectionKind.method:\n case ReflectionKind.function:\n case ReflectionKind.parameter:\n case ReflectionKind.typeParameter:\n case ReflectionKind.tupleMember:\n case ReflectionKind.enumMember:\n case ReflectionKind.rest:\n case ReflectionKind.indexSignature:\n case ReflectionKind.propertySignature:\n case ReflectionKind.methodSignature:\n case ReflectionKind.infer:\n case ReflectionKind.callSignature:\n default:\n return undefined;\n }\n}\n\nfunction mergeObjectSchemas(schemas: JsonSchemaObject[]): JsonSchemaObject {\n const merged: JsonSchemaObject = {\n type: \"object\",\n properties: {},\n required: []\n };\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = defu(merged.properties, schema.properties);\n }\n if (schema.required) {\n merged.required = Array.from(\n new Set([...(merged.required ?? []), ...schema.required])\n );\n }\n if (schema.additionalProperties !== undefined) {\n merged.additionalProperties = schema.additionalProperties;\n }\n }\n\n if ((merged.required?.length ?? 0) === 0) {\n delete merged.required;\n }\n\n return merged;\n}\n\nfunction tryReflectionDiscriminator(\n types: readonly Type[]\n): JsonSchema | undefined {\n const nonNullTypes = types.filter(\n t => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined\n );\n const objectBranches: Array<TypeObjectLiteral | TypeClass> =\n nonNullTypes.filter(\n t =>\n t.kind === ReflectionKind.objectLiteral ||\n t.kind === ReflectionKind.class\n );\n\n if (\n objectBranches.length < 2 ||\n objectBranches.length !== nonNullTypes.length\n ) {\n return undefined;\n }\n\n let tagKey: string | undefined;\n const branches: JsonSchemaObject[] = [];\n\n for (const branch of objectBranches) {\n const literalProps: Array<{ name: string; literal: string }> = [];\n for (const member of branch.types) {\n if (\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n typeof member.name === \"string\" &&\n member.type.kind === ReflectionKind.literal &&\n typeof (member.type as { literal?: unknown }).literal === \"string\"\n ) {\n literalProps.push({\n name: member.name,\n literal: (member.type as { literal: string }).literal\n });\n }\n }\n\n if (literalProps.length === 0) {\n return undefined;\n }\n\n const first = literalProps[0]!;\n if (!tagKey) {\n tagKey = first.name;\n } else if (tagKey !== first.name) {\n return undefined;\n }\n\n const filteredBranch = {\n ...branch,\n types: branch.types.filter(\n member =>\n !(\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n member.name === tagKey\n )\n )\n } as TypeObjectLiteral | TypeClass;\n\n const body = objectReflectionToJsonSchema(filteredBranch);\n if (!body || !isJsonSchemaObject(body)) {\n return undefined;\n }\n\n branches.push({\n type: \"object\",\n properties: {\n [tagKey]: { const: first.literal },\n ...(body.properties ?? {})\n },\n required: [tagKey, ...(body.required ?? [])],\n additionalProperties: body.additionalProperties ?? false\n });\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema;\n}\n\nfunction objectReflectionToJsonSchema(\n type: TypeObjectLiteral | TypeClass\n): JsonSchemaObject {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject = {\n type: \"object\",\n name: reflection.getName(),\n description: reflection.getDescription(),\n properties: {},\n required: [],\n readOnly: reflection.isReadonly(),\n ignore: reflection.isIgnored(),\n internal: reflection.isInternal(),\n runtime: reflection.isRuntime(),\n hidden: reflection.isHidden(),\n primaryKey: reflection\n .getPrimaries()\n .map(primary => primary.getNameAsString()),\n ...(isSetString(reflection.databaseSchemaName)\n ? { databaseSchemaName: reflection.databaseSchemaName }\n : {}),\n ...(isSetString(reflection.getName())\n ? { name: reflection.getName() }\n : {}),\n ...(isSetString(reflection.getDescription())\n ? { description: reflection.getDescription() }\n : {}),\n ...(isSetArray(reflection.getAlias())\n ? { alias: reflection.getAlias() }\n : {}),\n ...(isSetString(reflection.getTitle())\n ? { title: reflection.getTitle() }\n : {})\n };\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n schema.additionalProperties =\n reflectionToJsonSchemaInner(propertyReflection.type) ?? true;\n continue;\n }\n\n let property = reflectionToJsonSchemaInner(\n propertyReflection.type\n ) as JsonSchema;\n if (!property) {\n continue;\n }\n\n const propertySchema = isSetObject(property) ? property : {};\n\n property = {\n ...propertySchema,\n name: propertyReflection.getNameAsString(),\n description: propertyReflection.getDescription(),\n readOnly: propertyReflection.isReadonly(),\n ignore: propertyReflection.isIgnored(),\n internal: propertyReflection.isInternal(),\n runtime: propertyReflection.isRuntime(),\n hidden: propertyReflection.isHidden(),\n ...(propertyReflection.hasDefault()\n ? { default: propertyReflection.getDefaultValue() }\n : {}),\n ...(isSetArray(propertyReflection.getGroups())\n ? { tags: propertyReflection.getGroups() }\n : {}),\n ...(isSetArray(propertyReflection.getAlias())\n ? { alias: propertyReflection.getAlias() }\n : {}),\n ...(isSetString(propertyReflection.getTitle())\n ? { title: propertyReflection.getTitle() }\n : {})\n };\n\n if (propertyReflection.isNullable()) {\n property = withNullable(property);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] = property;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiEA,SAAS,wBACP,OACY;CACZ,QAAQ,OAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;GACL,MAAM;GACN,QAAQ;GACR,YAAY;EACd;EACF,KAAK,gBAAgB,MACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAQ,YAAY;EAAE;EAC1D,KAAK,gBAAgB,OACnB,OAAO;GAAE,MAAM;G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,4BACb,mBAAmB,IACrB;EACA,IAAI,CAAC,UACH;EAKF,WAAW;GACT,GAHqB,YAAY,QAAQ,IAAI,WAAW,CAAC;GAIzD,MAAM,mBAAmB,gBAAgB;GACzC,aAAa,mBAAmB,eAAe;GAC/C,UAAU,mBAAmB,WAAW;GACxC,QAAQ,mBAAmB,UAAU;GACrC,UAAU,mBAAmB,WAAW;GACxC,SAAS,mBAAmB,UAAU;GACtC,QAAQ,mBAAmB,SAAS;GACpC,GAAI,mBAAmB,WAAW,IAC9B,EAAE,SAAS,mBAAmB,gBAAgB,EAAE,IAChD,CAAC;GACL,GAAI,WAAW,mBAAmB,UAAU,CAAC,IACzC,EAAE,MAAM,mBAAmB,UAAU,EAAE,IACvC,CAAC;GACL,GAAI,WAAW,mBAAmB,SAAS,CAAC,IACxC,EAAE,OAAO,mBAAmB,SAAS,EAAE,IACvC,CAAC;GACL,GAAI,YAAY,mBAAmB,SAAS,CAAC,IACzC,EAAE,OAAO,mBAAmB,SAAS,EAAE,IACvC,CAAC;EACP;EAEA,IAAI,mBAAmB,WAAW,GAChC,WAAW,aAAa,QAAQ;EAGlC,OAAO,eAAe,CAAC;EACvB,OAAO,WAAW,mBAAmB,QAAQ;EAC7C,IAAI,CAAC,mBAAmB,WAAW,GAAG;GACpC,OAAO,aAAa,CAAC;GACrB,OAAO,SAAS,KAAK,mBAAmB,IAAI;EAC9C;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"reflection.mjs","names":[],"sources":["../src/reflection.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 {\n TagsReflection,\n Type,\n TypeClass\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionClass,\n ReflectionKind,\n TypeNumberBrand,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n isBigInt,\n isBoolean,\n isInteger,\n isNull,\n isNumber,\n isRegExp,\n isSetArray,\n isSetObject,\n isSetString,\n isString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { getJsonSchemaType } from \"./codegen\";\nimport {\n isJsonSchemaObject,\n isJsonSchemaPrimitiveType,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaNullable,\n JsonSchemaObject,\n JsonSchemaPrimitiveType\n} from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.\n *\n * @remarks\n * This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.\n *\n * @param brand - The Deepkit numeric brand to convert.\n * @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.\n */\nfunction numberBrandToJsonSchema(\n brand: TypeNumberBrand | undefined\n): JsonSchema {\n switch (brand) {\n case TypeNumberBrand.integer:\n return {\n type: \"integer\",\n format: \"int32\",\n multipleOf: 1\n };\n case TypeNumberBrand.int8:\n return { type: \"integer\", format: \"int8\", multipleOf: 1 };\n case TypeNumberBrand.uint8:\n return { type: \"integer\", format: \"uint8\", multipleOf: 1 };\n case TypeNumberBrand.int16:\n return { type: \"integer\", format: \"int16\", multipleOf: 1 };\n case TypeNumberBrand.uint16:\n return { type: \"integer\", format: \"uint16\", multipleOf: 1 };\n case TypeNumberBrand.int32:\n return { type: \"integer\", format: \"int32\", multipleOf: 1 };\n case TypeNumberBrand.uint32:\n return { type: \"integer\", format: \"uint32\", multipleOf: 1 };\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return { type: \"number\", format: \"float\" };\n case TypeNumberBrand.float64:\n return { type: \"number\", format: \"double\" };\n case undefined:\n default:\n return { type: \"number\" };\n }\n}\n\nfunction withReflectionTags(reflection: Type, schema: JsonSchema): JsonSchema {\n if (\n !isSetObject(schema) ||\n !isSetObject((reflection as { tags?: TagsReflection })?.tags)\n ) {\n return schema;\n }\n\n const updatedSchema = { ...schema };\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n updatedSchema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n updatedSchema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n updatedSchema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n updatedSchema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n updatedSchema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n updatedSchema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n updatedSchema.readOnly = tags.readonly;\n }\n\n return updatedSchema;\n}\n\nfunction withNullable(schema: JsonSchema): JsonSchemaNullable {\n if (!isSetObject(schema)) {\n return {\n anyOf: [schema, { type: \"null\", default: null }]\n };\n }\n\n const rawType = (schema as { type?: string | readonly string[] }).type;\n\n const types = Array.isArray(rawType)\n ? [...rawType]\n : rawType\n ? [rawType]\n : [];\n if (!types.includes(\"null\")) {\n types.push(\"null\");\n }\n\n return {\n ...schema,\n type: types.length === 1 ? types[0] : types\n };\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema(\n reflection: Type\n): JsonSchema | undefined {\n return reflectionToJsonSchemaInner(reflection);\n}\n\nfunction reflectionToJsonSchemaInner(reflection: Type): JsonSchema | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags(reflection, {\n type: \"null\",\n name: reflection.typeName,\n default: null\n });\n case ReflectionKind.string:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags(reflection, numeric);\n }\n case ReflectionKind.bigint:\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\"\n });\n case ReflectionKind.regexp:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n contentMediaType: \"text/regex\"\n });\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (isBigInt(literal)) {\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n const: literal\n });\n }\n\n if (isRegExp(literal)) {\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n\n return withReflectionTags(reflection, {\n type: getJsonSchemaType(literal),\n name: reflection.typeName,\n const: literal\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n isString(value) ||\n isInteger(value) ||\n isBigInt(value) ||\n isNumber(value) ||\n isBoolean(value) ||\n isNull(value)\n ) as (string | number | bigint | boolean | null)[];\n if (values.length === 0) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: []\n });\n }\n\n return withReflectionTags(reflection, {\n type: values.every(value => isString(value))\n ? \"string\"\n : values.every(value => isInteger(value) || isBigInt(value))\n ? \"integer\"\n : values.every(value => isNumber(value))\n ? \"number\"\n : values.every(value => isBoolean(value))\n ? \"boolean\"\n : values.every(value => isNull(value))\n ? \"null\"\n : values.reduce((ret, value) => {\n const type = getJsonSchemaType(value);\n if (\n isJsonSchemaPrimitiveType(type) &&\n !ret.includes(type)\n ) {\n ret.push(type);\n }\n\n return ret;\n }, [] as JsonSchemaPrimitiveType[]),\n name: reflection.typeName,\n description: reflection.description,\n enum: values,\n default: values.length === 1 ? values[0] : undefined\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner(reflection.type);\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items ?? {}\n });\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchemaInner(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items.length === 1 ? items[0] : {}\n });\n }\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n prefixItems: items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((branch): branch is JsonSchema => branch !== undefined);\n if (\n !reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n )\n ) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: branches\n });\n }\n\n const nonNull = branches.filter(branch => !isNullOnlyJsonSchema(branch));\n if (nonNull.length === 0) {\n return withReflectionTags(reflection, {\n type: \"null\",\n default: null\n });\n }\n\n if (nonNull.length === 1) {\n const first = nonNull[0]!;\n\n if (!isSetObject(first)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: [first]\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(first as Record<string, unknown>)\n })\n );\n }\n\n const enumValues = nonNull\n .map(branch =>\n isSetObject(branch)\n ? (branch as { const?: unknown }).const\n : undefined\n )\n .filter(\n (value): value is string | number | bigint | boolean | null =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n typeof value === \"boolean\"\n );\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n enum: enumValues\n })\n );\n }\n\n const discriminator = tryReflectionDiscriminator(reflection.types);\n if (discriminator && isSetObject(discriminator)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(discriminator as Record<string, unknown>)\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n })\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n if (!isSetObject(members[0])) {\n return members[0];\n }\n\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJsonSchema(reflection);\n case ReflectionKind.class: {\n const classType = reflection.classType as { name?: string } | undefined;\n const className = classType?.name;\n switch (className) {\n case \"Date\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner(itemType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"array\",\n items: items ?? {},\n uniqueItems: true\n });\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJsonSchemaInner(valueType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"object\",\n additionalProperties: values ?? true\n });\n }\n case \"Uint8Array\":\n case \"Uint8ClampedArray\":\n case \"Uint16Array\":\n case \"Uint32Array\":\n case \"Int8Array\":\n case \"Int16Array\":\n case \"Int32Array\":\n case \"Float32Array\":\n case \"Float64Array\":\n case \"BigInt64Array\":\n case \"BigUint64Array\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n ...objectReflectionToJsonSchema(reflection)\n });\n }\n }\n case ReflectionKind.symbol:\n case ReflectionKind.property:\n case ReflectionKind.method:\n case ReflectionKind.function:\n case ReflectionKind.parameter:\n case ReflectionKind.typeParameter:\n case ReflectionKind.tupleMember:\n case ReflectionKind.enumMember:\n case ReflectionKind.rest:\n case ReflectionKind.indexSignature:\n case ReflectionKind.propertySignature:\n case ReflectionKind.methodSignature:\n case ReflectionKind.infer:\n case ReflectionKind.callSignature:\n default:\n return undefined;\n }\n}\n\nfunction mergeObjectSchemas(schemas: JsonSchemaObject[]): JsonSchemaObject {\n const merged: JsonSchemaObject = {\n type: \"object\",\n properties: {},\n required: []\n };\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = defu(merged.properties, schema.properties);\n }\n if (schema.required) {\n merged.required = Array.from(\n new Set([...(merged.required ?? []), ...schema.required])\n );\n }\n if (schema.additionalProperties !== undefined) {\n merged.additionalProperties = schema.additionalProperties;\n }\n }\n\n if ((merged.required?.length ?? 0) === 0) {\n delete merged.required;\n }\n\n return merged;\n}\n\nfunction tryReflectionDiscriminator(\n types: readonly Type[]\n): JsonSchema | undefined {\n const nonNullTypes = types.filter(\n t => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined\n );\n const objectBranches: Array<TypeObjectLiteral | TypeClass> =\n nonNullTypes.filter(\n t =>\n t.kind === ReflectionKind.objectLiteral ||\n t.kind === ReflectionKind.class\n );\n\n if (\n objectBranches.length < 2 ||\n objectBranches.length !== nonNullTypes.length\n ) {\n return undefined;\n }\n\n let tagKey: string | undefined;\n const branches: JsonSchemaObject[] = [];\n\n for (const branch of objectBranches) {\n const literalProps: Array<{ name: string; literal: string }> = [];\n for (const member of branch.types) {\n if (\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n typeof member.name === \"string\" &&\n member.type.kind === ReflectionKind.literal &&\n typeof (member.type as { literal?: unknown }).literal === \"string\"\n ) {\n literalProps.push({\n name: member.name,\n literal: (member.type as { literal: string }).literal\n });\n }\n }\n\n if (literalProps.length === 0) {\n return undefined;\n }\n\n const first = literalProps[0]!;\n if (!tagKey) {\n tagKey = first.name;\n } else if (tagKey !== first.name) {\n return undefined;\n }\n\n const filteredBranch = {\n ...branch,\n types: branch.types.filter(\n member =>\n !(\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n member.name === tagKey\n )\n )\n } as TypeObjectLiteral | TypeClass;\n\n const body = objectReflectionToJsonSchema(filteredBranch);\n if (!body || !isJsonSchemaObject(body)) {\n return undefined;\n }\n\n branches.push({\n type: \"object\",\n properties: {\n [tagKey]: { const: first.literal },\n ...(body.properties ?? {})\n },\n required: [tagKey, ...(body.required ?? [])],\n additionalProperties: body.additionalProperties ?? false\n });\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema;\n}\n\nfunction objectReflectionToJsonSchema(\n type: TypeObjectLiteral | TypeClass\n): JsonSchemaObject {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject = {\n type: \"object\",\n name: reflection.getName(),\n description: reflection.getDescription(),\n properties: {},\n required: [],\n readOnly: reflection.isReadonly(),\n ignore: reflection.isIgnored(),\n internal: reflection.isInternal(),\n runtime: reflection.isRuntime(),\n hidden: reflection.isHidden(),\n primaryKey: reflection\n .getPrimaries()\n .map(primary => primary.getNameAsString()),\n ...(isSetString(reflection.databaseSchemaName)\n ? { databaseSchemaName: reflection.databaseSchemaName }\n : {}),\n ...(isSetString(reflection.getName())\n ? { name: reflection.getName() }\n : {}),\n ...(isSetString(reflection.getDescription())\n ? { description: reflection.getDescription() }\n : {}),\n ...(isSetArray(reflection.getAlias())\n ? { alias: reflection.getAlias() }\n : {}),\n ...(isSetString(reflection.getTitle())\n ? { title: reflection.getTitle() }\n : {})\n };\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n schema.additionalProperties =\n reflectionToJsonSchemaInner(propertyReflection.type) ?? true;\n continue;\n }\n\n let property = reflectionToJsonSchemaInner(\n propertyReflection.type\n ) as JsonSchema;\n if (!property) {\n continue;\n }\n\n const propertySchema = isSetObject(property) ? property : {};\n\n property = {\n ...propertySchema,\n name: propertyReflection.getNameAsString(),\n description: propertyReflection.getDescription(),\n readOnly: propertyReflection.isReadonly(),\n ignore: propertyReflection.isIgnored(),\n internal: propertyReflection.isInternal(),\n runtime: propertyReflection.isRuntime(),\n hidden: propertyReflection.isHidden(),\n ...(propertyReflection.hasDefault()\n ? { default: propertyReflection.getDefaultValue() }\n : {}),\n ...(isSetArray(propertyReflection.getGroups())\n ? { tags: propertyReflection.getGroups() }\n : {}),\n ...(isSetArray(propertyReflection.getAlias())\n ? { alias: propertyReflection.getAlias() }\n : {}),\n ...(isSetString(propertyReflection.getTitle())\n ? { title: propertyReflection.getTitle() }\n : {})\n };\n\n if (propertyReflection.isNullable()) {\n property = withNullable(property);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] = property;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;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from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
10
|
const require_bundle = require('./bundle.cjs');
|
|
3
11
|
let defu = require("defu");
|
package/dist/resolve.d.mts
CHANGED
package/dist/resolve.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;;;;;;;;;iBAsCsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;AAPX;;;;;;;iBA8EsB,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
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { bundle } from "./bundle.mjs";
|
|
2
10
|
import defu from "defu";
|
|
3
11
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
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 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,QA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I,MACR,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"}
|
|
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,IA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AOA,QAAU,IAAI;CACvB,SAAS,OAAO;EACd,MAAM,IAAI,MACR,6CAA6C,cAAc,KAAK,mEAAoE,MAAgB,SACtJ;CACF;MACK,IAAI,cAAc,QACvB,IAAI;EACF,MAAM,OAAO,MAAM,QAAQ,GAAG,KAAK,cAAc,IAAI;EACrD,IAAI,CAAC,YAAY,IAAI,GACnB,MAAM,IAAI,MACR,gBAAgB,cAAc,KAAK,wFACrC;EAGF,OAAOC,MAAU,IAAI;CACvB,SAAS,OAAO;EACd,MAAM,IAAI,MACR,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/dist/type-checks.cjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
const require_constants = require('./constants.cjs');
|
|
2
10
|
let _stryke_type_checks = require("@stryke/type-checks");
|
|
3
11
|
|
package/dist/type-checks.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
1
3
|
import { ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaKeywords, JsonSchemaLiteral, JsonSchemaMap, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRef, JsonSchemaSet, JsonSchemaString, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, Schema as Schema$1 } from "./types.mjs";
|
|
2
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
5
|
import { InputObject, Schema } from "untyped";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;;;;;;;;iBAoGgB,yBAAA,CACd,KAAA,YACC,KAAA,IAAS,uBAAuB;;;;AAFnC;;;iBAegB,gBAAA,CAAiB,KAAA,YAAiB,KAAA,IAAS,cAAc;;;;;AAbtC;AAanC;iBA8QgB,oBAAA,CACd,KAAA,YACC,KAAA,IAAS,kBAAkB;;;;;;;iBAcd,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,a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J;AAgBvE;;;;;iBAoMgB,oBAAA,CACd,KAAA,YACC,KAAA,IAAS,WAAkB;;;AAtM6C;AAqB3E;;;iBAwMgB,QAAA,CAAS,KAAA,YAAiB,KAAA,IAAS,QAAM;;;;;AAtMnC;AA0BtB;iBA8LgB,kBAAA,CAAmB,KAAA,YAAiB,KAAA,IAAS,eAAgB;;;;;;;iBAiB7D,cAAA,CACd,KAAA,YACC,KAAA,IAAS,QAAM,CAAC,gBAAA"}
|
package/dist/type-checks.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import __tsdown_shims_path from 'node:path'
|
|
4
|
+
import __tsdown_shims_url from 'node:url'
|
|
5
|
+
|
|
6
|
+
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
+
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
+
|
|
1
9
|
import { JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES } from "./constants.mjs";
|
|
2
10
|
import { isFunction, isSetObject, isSetString } from "@stryke/type-checks";
|
|
3
11
|
|