@powerlines/schema 0.11.22 → 0.11.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/bundle.mjs.map +1 -1
  2. package/dist/codegen.cjs +44 -1
  3. package/dist/codegen.d.cts +19 -1
  4. package/dist/codegen.d.cts.map +1 -1
  5. package/dist/codegen.d.mts +19 -1
  6. package/dist/codegen.d.mts.map +1 -1
  7. package/dist/codegen.mjs +42 -1
  8. package/dist/codegen.mjs.map +1 -1
  9. package/dist/constants.cjs +19 -0
  10. package/dist/constants.d.cts +17 -0
  11. package/dist/constants.d.cts.map +1 -0
  12. package/dist/constants.d.mts +17 -0
  13. package/dist/constants.d.mts.map +1 -0
  14. package/dist/constants.mjs +18 -0
  15. package/dist/constants.mjs.map +1 -0
  16. package/dist/extract.cjs +23 -4
  17. package/dist/extract.d.cts.map +1 -1
  18. package/dist/extract.d.mts.map +1 -1
  19. package/dist/extract.mjs +23 -4
  20. package/dist/extract.mjs.map +1 -1
  21. package/dist/helpers.cjs +54 -0
  22. package/dist/helpers.d.cts +26 -0
  23. package/dist/helpers.d.cts.map +1 -0
  24. package/dist/helpers.d.mts +26 -0
  25. package/dist/helpers.d.mts.map +1 -0
  26. package/dist/helpers.mjs +52 -0
  27. package/dist/helpers.mjs.map +1 -0
  28. package/dist/index.cjs +17 -2
  29. package/dist/index.d.cts +7 -4
  30. package/dist/index.d.mts +7 -4
  31. package/dist/index.mjs +6 -3
  32. package/dist/jtd.mjs.map +1 -1
  33. package/dist/persistence.cjs +76 -0
  34. package/dist/persistence.d.cts +47 -0
  35. package/dist/persistence.d.cts.map +1 -0
  36. package/dist/persistence.d.mts +47 -0
  37. package/dist/persistence.d.mts.map +1 -0
  38. package/dist/persistence.mjs +71 -0
  39. package/dist/persistence.mjs.map +1 -0
  40. package/dist/reflection.cjs +13 -6
  41. package/dist/reflection.d.cts.map +1 -1
  42. package/dist/reflection.d.mts.map +1 -1
  43. package/dist/reflection.mjs +12 -6
  44. package/dist/reflection.mjs.map +1 -1
  45. package/dist/resolve.mjs.map +1 -1
  46. package/dist/type-checks.cjs +21 -2
  47. package/dist/type-checks.d.cts +16 -2
  48. package/dist/type-checks.d.cts.map +1 -1
  49. package/dist/type-checks.d.mts +16 -2
  50. package/dist/type-checks.d.mts.map +1 -1
  51. package/dist/type-checks.mjs +21 -4
  52. package/dist/type-checks.mjs.map +1 -1
  53. package/dist/types.d.cts +42 -12
  54. package/dist/types.d.cts.map +1 -1
  55. package/dist/types.d.mts +42 -12
  56. package/dist/types.d.mts.map +1 -1
  57. package/package.json +19 -7
@@ -0,0 +1,47 @@
1
+ import { Schema, SchemaInput, SchemaMetadata } from "./types.mjs";
2
+ import { Context } from "@powerlines/core";
3
+
4
+ //#region src/persistence.d.ts
5
+ /**
6
+ * 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.
7
+ *
8
+ * @param context - The context object providing access to the cache path.
9
+ * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the "schemas" subdirectory.
10
+ */
11
+ declare function getCacheDirectory(context: Context): string;
12
+ /**
13
+ * 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).
14
+ *
15
+ * @param context - The context object providing access to the cache path.
16
+ * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.
17
+ * @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.
18
+ */
19
+ declare function getCacheFilePath(context: Context, input: SchemaInput): string;
20
+ /**
21
+ * 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.
22
+ *
23
+ * @param context - The context object providing access to the file system and cache path.
24
+ * @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.
25
+ * @throws Will throw an error if the provided input is not a valid schema.
26
+ */
27
+ declare function writeSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>, TContext extends Context = Context>(context: TContext, schema: Schema<TMetadata>): Promise<void>;
28
+ /**
29
+ * 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.
30
+ *
31
+ * @param context - The context object providing access to the file system and cache path.
32
+ * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
33
+ * @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.
34
+ */
35
+ declare function readSchemaSafe<TContext extends Context = Context, TMetadata extends SchemaMetadata = SchemaMetadata>(context: TContext, input: SchemaInput): Promise<Schema<TMetadata> | undefined>;
36
+ /**
37
+ * 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.
38
+ *
39
+ * @param context - The context object providing access to the file system and cache path.
40
+ * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
41
+ * @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.
42
+ * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.
43
+ */
44
+ declare function readSchema<TContext extends Context = Context, TMetadata extends SchemaMetadata = SchemaMetadata>(context: TContext, input: SchemaInput): Promise<Schema<TMetadata>>;
45
+ //#endregion
46
+ export { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
47
+ //# sourceMappingURL=persistence.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.d.mts","names":[],"sources":["../src/persistence.ts"],"mappings":";;;;;;AA8BA;;;;iBAAgB,iBAAA,CAAkB,OAAgB,EAAP,OAAO;AAWlD;;;;;;;AAAA,iBAAgB,gBAAA,CAAiB,OAAA,EAAS,OAAA,EAAS,KAAA,EAAO,WAAW;;AAAA;AAcrE;;;;;iBAAsB,WAAA,mBACF,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,oBACnC,OAAA,GAAU,OAAA,CAAA,CAC3B,OAAA,EAAS,QAAA,EAAU,MAAA,EAAQ,MAAA,CAAO,SAAA,IAAU,OAAA;;;;;;;;iBAoBxB,cAAA,kBACH,OAAA,GAAU,OAAA,oBACT,cAAA,GAAiB,cAAA,CAAA,CAEnC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA,CAAO,SAAA;;;;;;;;;iBAsBI,UAAA,kBACH,OAAA,GAAU,OAAA,oBACT,cAAA,GAAiB,cAAA,CAAA,CACnC,OAAA,EAAS,QAAA,EAAU,KAAA,EAAO,WAAA,GAAc,OAAA,CAAQ,MAAA,CAAO,SAAA"}
@@ -0,0 +1,71 @@
1
+ import { isSchema } from "./type-checks.mjs";
2
+ import { extractHash, extractVariant } from "./extract.mjs";
3
+ import { joinPaths } from "@stryke/path/join";
4
+
5
+ //#region src/persistence.ts
6
+ /**
7
+ * 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.
8
+ *
9
+ * @param context - The context object providing access to the cache path.
10
+ * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the "schemas" subdirectory.
11
+ */
12
+ function getCacheDirectory(context) {
13
+ return joinPaths(context.cachePath, "schemas");
14
+ }
15
+ /**
16
+ * 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).
17
+ *
18
+ * @param context - The context object providing access to the cache path.
19
+ * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.
20
+ * @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.
21
+ */
22
+ function getCacheFilePath(context, input) {
23
+ const hash = extractHash(extractVariant(input), input);
24
+ return joinPaths(getCacheDirectory(context), `${hash}.json`);
25
+ }
26
+ /**
27
+ * 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.
28
+ *
29
+ * @param context - The context object providing access to the file system and cache path.
30
+ * @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.
31
+ * @throws Will throw an error if the provided input is not a valid schema.
32
+ */
33
+ async function writeSchema(context, schema) {
34
+ if (!isSchema(schema)) throw new Error(`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 JTD schema object.`);
35
+ await context.fs.write(getCacheFilePath(context, schema), JSON.stringify(schema.schema));
36
+ }
37
+ /**
38
+ * 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.
39
+ *
40
+ * @param context - The context object providing access to the file system and cache path.
41
+ * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
42
+ * @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.
43
+ */
44
+ async function readSchemaSafe(context, input) {
45
+ const cacheFilePath = getCacheFilePath(context, input);
46
+ if (!await context.fs.exists(cacheFilePath)) return;
47
+ const data = await context.fs.read(cacheFilePath);
48
+ if (!data) return;
49
+ return JSON.parse(data);
50
+ }
51
+ /**
52
+ * 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.
53
+ *
54
+ * @param context - The context object providing access to the file system and cache path.
55
+ * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
56
+ * @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.
57
+ * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.
58
+ */
59
+ async function readSchema(context, input) {
60
+ const schema = await readSchemaSafe(context, input);
61
+ if (!schema) {
62
+ const variant = extractVariant(input);
63
+ const hash = extractHash(variant, input);
64
+ throw new Error(`The ${variant} schema with hash "${hash}" 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.`);
65
+ }
66
+ return schema;
67
+ }
68
+
69
+ //#endregion
70
+ export { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
71
+ //# sourceMappingURL=persistence.mjs.map
@@ -0,0 +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, SchemaMetadata } 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<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>,\n TContext extends Context = Context\n>(context: TContext, schema: Schema<TMetadata>) {\n if (!isSchema<TMetadata>(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 JTD 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 TContext extends Context = Context,\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(\n context: TContext,\n input: SchemaInput\n): Promise<Schema<TMetadata> | 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 TContext extends Context = Context,\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(context: TContext, input: SchemaInput): Promise<Schema<TMetadata>> {\n const schema = await readSchemaSafe<TContext, TMetadata>(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,YAGpB,SAAmB,QAA2B;CAC9C,IAAI,CAAC,SAAoB,MAAM,GAC7B,MAAM,IAAI,MACR,2LACF;CAGF,MAAM,QAAQ,GAAG,MACf,iBAAiB,SAAS,MAAM,GAChC,KAAK,UAAU,OAAO,MAAM,CAC9B;AACF;;;;;;;;AASA,eAAsB,eAIpB,SACA,OACwC;CACxC,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,WAGpB,SAAmB,OAAgD;CACnE,MAAM,SAAS,MAAM,eAAoC,SAAS,KAAK;CACvE,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"}
@@ -1,7 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
3
+ let defu = require("defu");
4
+ defu = require_runtime.__toESM(defu, 1);
4
5
  let _stryke_type_checks = require("@stryke/type-checks");
6
+ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
5
7
 
6
8
  //#region src/reflection.ts
7
9
  /**
@@ -307,10 +309,10 @@ function mergePropertiesForms(forms) {
307
309
  optionalProperties: {}
308
310
  };
309
311
  for (const form of forms) {
310
- const p = form.properties;
311
- const o = form.optionalProperties;
312
- if (p) Object.assign(merged.properties, p);
313
- if (o) Object.assign(merged.optionalProperties, o);
312
+ const properties = form.properties;
313
+ const optionalProperties = form.optionalProperties;
314
+ if (properties) (0, defu.default)(merged.properties, properties);
315
+ if (optionalProperties) (0, defu.default)(merged.optionalProperties, optionalProperties);
314
316
  if (form.additionalProperties) merged.additionalProperties = true;
315
317
  }
316
318
  const hasProperties = Object.keys(merged.properties).length > 0;
@@ -372,7 +374,8 @@ function objectReflectionToJtd(type) {
372
374
  schema.metadata.isInternal = reflection.isInternal();
373
375
  schema.metadata.isRuntime = reflection.isRuntime();
374
376
  schema.metadata.isHidden = reflection.isHidden();
375
- if ((0, _stryke_type_checks.isSetString)(reflection.databaseSchemaName)) schema.metadata.table = reflection.databaseSchemaName;
377
+ if ((0, _stryke_type_checks.isSetString)(reflection.databaseSchemaName)) schema.metadata.resourceId = reflection.databaseSchemaName;
378
+ if ((0, _stryke_type_checks.isSetString)(reflection.getName())) schema.metadata.name = reflection.getName();
376
379
  if ((0, _stryke_type_checks.isSetString)(reflection.getDescription())) schema.metadata.description = reflection.getDescription();
377
380
  if ((0, _stryke_type_checks.isSetArray)(reflection.getAlias())) schema.metadata.alias = reflection.getAlias();
378
381
  if ((0, _stryke_type_checks.isSetString)(reflection.getTitle())) schema.metadata.title = reflection.getTitle();
@@ -395,7 +398,11 @@ function objectReflectionToJtd(type) {
395
398
  property.metadata.isRuntime = propertyReflection.isRuntime();
396
399
  property.metadata.isPrimaryKey = propertyReflection.isPrimaryKey();
397
400
  property.metadata.isHidden = propertyReflection.isHidden();
401
+ property.nullable = propertyReflection.isNullable();
402
+ property.metadata.visibility = propertyReflection.isPublic() ? "public" : propertyReflection.isProtected() ? "protected" : propertyReflection.isPrivate() ? "private" : void 0;
398
403
  if (propertyReflection.hasDefault()) property.metadata.default = propertyReflection.getDefaultValue();
404
+ if ((0, _stryke_type_checks.isSetString)(propertyReflection.getNameAsString())) property.metadata.name = propertyReflection.getNameAsString();
405
+ if ((0, _stryke_type_checks.isSetArray)(propertyReflection.getGroups())) property.metadata.groups = propertyReflection.getGroups();
399
406
  if ((0, _stryke_type_checks.isSetString)(propertyReflection.getDescription())) property.metadata.description = propertyReflection.getDescription();
400
407
  if ((0, _stryke_type_checks.isSetArray)(propertyReflection.getAlias())) property.metadata.alias = propertyReflection.getAlias();
401
408
  if ((0, _stryke_type_checks.isSetString)(propertyReflection.getTitle())) property.metadata.title = propertyReflection.getTitle();
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.d.cts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AA2FA;;;;;;;;;;;;;;iBAAgB,sBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CAAc,SAAA"}
1
+ {"version":3,"file":"reflection.d.cts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AA4FA;;;;;;;;;;;;;;iBAAgB,sBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CAAc,SAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AA2FA;;;;;;;;;;;;;;iBAAgB,sBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CAAc,SAAA"}
1
+ {"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AA4FA;;;;;;;;;;;;;;iBAAgB,sBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CAAc,SAAA"}
@@ -1,5 +1,6 @@
1
- import { ReflectionClass, ReflectionKind, TypeNumberBrand } from "@powerlines/deepkit/vendor/type";
1
+ import defu from "defu";
2
2
  import { isSetArray, isSetObject, isSetString } from "@stryke/type-checks";
3
+ import { ReflectionClass, ReflectionKind, TypeNumberBrand } from "@powerlines/deepkit/vendor/type";
3
4
 
4
5
  //#region src/reflection.ts
5
6
  /**
@@ -305,10 +306,10 @@ function mergePropertiesForms(forms) {
305
306
  optionalProperties: {}
306
307
  };
307
308
  for (const form of forms) {
308
- const p = form.properties;
309
- const o = form.optionalProperties;
310
- if (p) Object.assign(merged.properties, p);
311
- if (o) Object.assign(merged.optionalProperties, o);
309
+ const properties = form.properties;
310
+ const optionalProperties = form.optionalProperties;
311
+ if (properties) defu(merged.properties, properties);
312
+ if (optionalProperties) defu(merged.optionalProperties, optionalProperties);
312
313
  if (form.additionalProperties) merged.additionalProperties = true;
313
314
  }
314
315
  const hasProperties = Object.keys(merged.properties).length > 0;
@@ -370,7 +371,8 @@ function objectReflectionToJtd(type) {
370
371
  schema.metadata.isInternal = reflection.isInternal();
371
372
  schema.metadata.isRuntime = reflection.isRuntime();
372
373
  schema.metadata.isHidden = reflection.isHidden();
373
- if (isSetString(reflection.databaseSchemaName)) schema.metadata.table = reflection.databaseSchemaName;
374
+ if (isSetString(reflection.databaseSchemaName)) schema.metadata.resourceId = reflection.databaseSchemaName;
375
+ if (isSetString(reflection.getName())) schema.metadata.name = reflection.getName();
374
376
  if (isSetString(reflection.getDescription())) schema.metadata.description = reflection.getDescription();
375
377
  if (isSetArray(reflection.getAlias())) schema.metadata.alias = reflection.getAlias();
376
378
  if (isSetString(reflection.getTitle())) schema.metadata.title = reflection.getTitle();
@@ -393,7 +395,11 @@ function objectReflectionToJtd(type) {
393
395
  property.metadata.isRuntime = propertyReflection.isRuntime();
394
396
  property.metadata.isPrimaryKey = propertyReflection.isPrimaryKey();
395
397
  property.metadata.isHidden = propertyReflection.isHidden();
398
+ property.nullable = propertyReflection.isNullable();
399
+ property.metadata.visibility = propertyReflection.isPublic() ? "public" : propertyReflection.isProtected() ? "protected" : propertyReflection.isPrivate() ? "private" : void 0;
396
400
  if (propertyReflection.hasDefault()) property.metadata.default = propertyReflection.getDefaultValue();
401
+ if (isSetString(propertyReflection.getNameAsString())) property.metadata.name = propertyReflection.getNameAsString();
402
+ if (isSetArray(propertyReflection.getGroups())) property.metadata.groups = propertyReflection.getGroups();
397
403
  if (isSetString(propertyReflection.getDescription())) property.metadata.description = propertyReflection.getDescription();
398
404
  if (isSetArray(propertyReflection.getAlias())) property.metadata.alias = propertyReflection.getAlias();
399
405
  if (isSetString(propertyReflection.getTitle())) property.metadata.title = propertyReflection.getTitle();
@@ -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 { isSetArray, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport { JTDSchemaType, SchemaMetadata } from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to the JTD numeric `type` keyword that best preserves the underlying width and signedness.\n *\n * @param brand - The Deepkit `TypeNumberBrand` of a numeric reflection, or `undefined` when no brand is set.\n * @returns The JTD numeric `type` keyword to use.\n */\nfunction numberBrandToJtdType(\n brand: TypeNumberBrand | undefined\n):\n | \"int8\"\n | \"uint8\"\n | \"int16\"\n | \"uint16\"\n | \"int32\"\n | \"uint32\"\n | \"float32\"\n | \"float64\" {\n switch (brand) {\n case TypeNumberBrand.integer:\n return \"int32\";\n case TypeNumberBrand.int8:\n return \"int8\";\n case TypeNumberBrand.uint8:\n return \"uint8\";\n case TypeNumberBrand.int16:\n return \"int16\";\n case TypeNumberBrand.uint16:\n return \"uint16\";\n case TypeNumberBrand.int32:\n return \"int32\";\n case TypeNumberBrand.uint32:\n return \"uint32\";\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return \"float32\";\n case TypeNumberBrand.float64:\n return \"float64\";\n case undefined:\n default:\n return \"float64\";\n }\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Type Definition (RFC 8927) form suitable for AJV's JTD validator.\n *\n * @remarks\n * Some TypeScript constructs have no direct JTD equivalent and are handled with the closest available form:\n *\n * - `null` and `undefined` become the empty JTD form with `nullable: true`.\n * - Unions of primitives that cannot be expressed as a JTD enum collapse to the empty form (which validates any value).\n * - String/number/bigint literal unions are emitted as a JTD enum (non-string members are stringified, as JTD requires string enum members).\n * - Tuples are emitted as a JTD elements form whose element schema is the single tuple member type, or the empty schema for mixed tuples.\n * - `Date` is emitted as `{ type: \"timestamp\" }`.\n * - Discriminated unions of object literals (a shared string-literal tag property) are emitted as a JTD discriminator form.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nexport function reflectionToJsonSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const result = reflectionToJtd<TMetadata>(reflection);\n\n return result;\n}\n\n/**\n * Internal worker that performs the recursive Deepkit reflection → JTD conversion.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nfunction reflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const schema = {} as JTDSchemaType<TMetadata>;\n\n if (isSetObject((reflection as { tags?: TagsReflection })?.tags)) {\n const tags = (reflection as { tags: TagsReflection }).tags;\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n if (tags.readonly === true) {\n schema.metadata.isReadonly = true;\n }\n if (tags.ignore === true) {\n schema.metadata.isIgnored = true;\n }\n if (tags.internal === true) {\n schema.metadata.isInternal = true;\n }\n if (tags.runtime === true) {\n schema.metadata.isRuntime = true;\n }\n if (tags.hidden === true) {\n schema.metadata.isHidden = true;\n }\n if (isSetArray(tags.alias)) {\n schema.metadata.alias = tags.alias;\n }\n if (isSetString(tags.title)) {\n schema.metadata.title = tags.title;\n }\n }\n\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return {};\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return { nullable: true };\n case ReflectionKind.string:\n return { ...schema, type: \"string\" };\n case ReflectionKind.boolean:\n return { ...schema, type: \"boolean\" };\n case ReflectionKind.number:\n return {\n ...schema,\n type: numberBrandToJtdType(reflection.brand)\n };\n case ReflectionKind.bigint:\n // JTD has no native 64-bit integer type — float64 is the widest numeric form.\n return { ...schema, type: \"float64\" };\n case ReflectionKind.regexp:\n return { ...schema, type: \"string\" };\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (typeof literal === \"string\") {\n return { ...schema, enum: [literal] };\n }\n\n if (typeof literal === \"number\" || typeof literal === \"bigint\") {\n return {\n ...schema,\n enum: [String(literal)]\n };\n }\n\n if (typeof literal === \"boolean\") {\n // JTD has no boolean literal — emit the type form.\n return { ...schema, type: \"boolean\" };\n }\n\n if (literal instanceof RegExp) {\n return { ...schema, type: \"string\" };\n }\n\n return schema;\n }\n case ReflectionKind.templateLiteral:\n return { ...schema, type: \"string\" };\n case ReflectionKind.enum: {\n const values = reflection.values\n .filter(\n (value): value is string | number =>\n typeof value === \"string\" || typeof value === \"number\"\n )\n .map(value => String(value));\n\n const unique = Array.from(new Set(values));\n if (unique.length === 0) {\n return schema;\n }\n\n return { ...schema, enum: unique };\n }\n case ReflectionKind.array: {\n const items = reflectionToJtd<TMetadata>(reflection.type);\n\n return { ...schema, elements: items ?? {} };\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJtd<TMetadata>(member.type))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n if (items.length === 0) {\n return { ...schema, elements: {} };\n }\n\n if (items.length === 1) {\n return { ...schema, elements: items[0]! };\n }\n\n // JTD has no tuple form — accept any element shape.\n return { ...schema, elements: {} };\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n\n const nullable = reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n );\n const nonNull = branches.filter(b => !isPureNullable(b));\n\n if (nonNull.length === 0) {\n return { ...schema, nullable: true };\n }\n\n if (nonNull.length === 1) {\n const only = nonNull[0]!;\n if (nullable) {\n (only as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...only };\n }\n\n // String-enum union: combine all enum branches into one JTD enum.\n if (nonNull.every(isEnumForm)) {\n const merged = Array.from(\n new Set(nonNull.flatMap(b => (b as { enum: string[] }).enum))\n );\n const form: JTDSchemaType<TMetadata> = { ...schema, enum: merged };\n\n if (nullable) {\n (form as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...form };\n }\n\n // Discriminated union of object literals: detect a shared string-literal tag.\n const discriminator = tryReflectionDiscriminator<TMetadata>(\n reflection.types\n );\n if (discriminator) {\n if (nullable) {\n (discriminator as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...discriminator };\n }\n\n // Fallback — JTD has no general union; allow any value.\n const fallback: JTDSchemaType<TMetadata> = {};\n if (nullable) {\n (fallback as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...fallback };\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter(\n (item): item is JTDSchemaType<TMetadata> | undefined =>\n item !== undefined\n );\n if (members.length === 0) {\n return undefined as JTDSchemaType<TMetadata> | undefined;\n }\n\n if (members.length === 1) {\n return { ...schema, ...members[0] };\n }\n\n if (\n members.every(member => member && isPropertiesForm<TMetadata>(member))\n ) {\n return mergePropertiesForms<TMetadata>(\n members as JTDSchemaType<TMetadata>[]\n );\n }\n\n return { ...schema, ...members[0] };\n }\n case ReflectionKind.promise:\n return reflectionToJtd<TMetadata>(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJtd<TMetadata>(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 { ...schema, type: \"timestamp\" };\n case \"RegExp\":\n return { ...schema, type: \"string\" };\n case \"URL\":\n return { ...schema, type: \"string\" };\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJtd<TMetadata>(itemType)\n : undefined;\n\n return { ...schema, elements: items ?? {} };\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJtd<TMetadata>(valueType)\n : undefined;\n\n return { ...schema, values: values ?? {} };\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 // Base64-encoded binary payload — represented as a plain string in JTD.\n return { ...schema, type: \"string\" };\n case undefined:\n default:\n return objectReflectionToJtd<TMetadata>(reflection);\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\n/**\n * Tests whether a JTD form is an enum form.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD enum form.\n */\nfunction isEnumForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is { enum: string[]; nullable?: boolean; metadata?: TMetadata } {\n return Array.isArray((form as { enum?: unknown[] }).enum);\n}\n\n/**\n * Tests whether a JTD form is a properties form (object).\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD properties form.\n */\nfunction isPropertiesForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n nullable?: boolean;\n metadata?: TMetadata;\n} {\n return (\n \"properties\" in (form as object) || \"optionalProperties\" in (form as object)\n );\n}\n\n/**\n * Tests whether a JTD form is the empty `{ nullable: true }` placeholder.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form has no shape constraints beyond `nullable`.\n */\nfunction isPureNullable<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(form: JTDSchemaType<TMetadata>): boolean {\n const keys = Object.keys(form as object).filter(\n k => k !== \"nullable\" && k !== \"metadata\"\n );\n\n return (\n keys.length === 0 && (form as { nullable?: boolean }).nullable === true\n );\n}\n\n/**\n * Shallow-merges two JTD properties forms, unioning their `properties` and `optionalProperties` maps.\n *\n * @param forms - The JTD properties forms to merge.\n * @returns The merged JTD properties form.\n */\nfunction mergePropertiesForms<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(forms: JTDSchemaType<TMetadata>[]): JTDSchemaType<TMetadata> {\n const merged: {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n } = {\n properties: {},\n optionalProperties: {}\n };\n\n for (const form of forms) {\n const p = (\n form as { properties?: Record<string, JTDSchemaType<TMetadata>> }\n ).properties;\n const o = (\n form as { optionalProperties?: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties;\n if (p) {\n Object.assign(merged.properties, p);\n }\n if (o) {\n Object.assign(merged.optionalProperties, o);\n }\n if ((form as { additionalProperties?: boolean }).additionalProperties) {\n merged.additionalProperties = true;\n }\n }\n\n const hasProperties = Object.keys(merged.properties).length > 0;\n const hasOptional = Object.keys(merged.optionalProperties).length > 0;\n const result: JTDSchemaType<TMetadata> = {};\n\n if (hasProperties) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = merged.properties;\n } else if (!hasOptional) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = {};\n }\n\n if (hasOptional) {\n (\n result as { optionalProperties: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties = merged.optionalProperties;\n }\n\n if (merged.additionalProperties) {\n (result as { additionalProperties: boolean }).additionalProperties = true;\n }\n\n return result;\n}\n\n/**\n * Detects whether a Deepkit union represents a tagged union and, when so, emits the corresponding JTD discriminator form.\n *\n * @param types - The Deepkit reflection types that make up the union branches.\n * @returns A JTD discriminator form if every non-null branch is an object literal that shares a string-literal tag property, otherwise `undefined`.\n */\nfunction tryReflectionDiscriminator<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(types: readonly Type[]): JTDSchemaType<TMetadata> | 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 mapping: Record<string, JTDSchemaType<TMetadata>> = {};\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 // Build the branch body excluding the discriminator property.\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 = objectReflectionToJtd<TMetadata>(filteredBranch);\n if (!body || !isPropertiesForm<TMetadata>(body)) {\n return undefined;\n }\n\n mapping[first.literal] = body;\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return { discriminator: tagKey, mapping };\n}\n\n/**\n * Internal worker that produces a JTD properties form (or `values` form for index signatures alone) from a Deepkit object-like type.\n *\n * @param type - The class or object literal type whose members should be serialized.\n * @returns A JTD properties or values form describing the type's members.\n */\nfunction objectReflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(type: TypeObjectLiteral | TypeClass): JTDSchemaType<TMetadata> {\n const reflection = ReflectionClass.from(type);\n\n const schema = {} as {\n properties?: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n metadata?: TMetadata;\n };\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n schema.metadata.isReadonly = reflection.isReadonly();\n schema.metadata.isIgnored = reflection.isIgnored();\n schema.metadata.isInternal = reflection.isInternal();\n schema.metadata.isRuntime = reflection.isRuntime();\n schema.metadata.isHidden = reflection.isHidden();\n\n if (isSetString(reflection.databaseSchemaName)) {\n schema.metadata.table = reflection.databaseSchemaName;\n }\n if (isSetString(reflection.getDescription())) {\n schema.metadata.description = reflection.getDescription();\n }\n if (isSetArray(reflection.getAlias())) {\n schema.metadata.alias = reflection.getAlias();\n }\n if (isSetString(reflection.getTitle())) {\n schema.metadata.title = reflection.getTitle();\n }\n\n const properties: Record<string, JTDSchemaType<TMetadata>> = {};\n const optionalProperties: Record<string, JTDSchemaType<TMetadata>> = {};\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n const valueSchema = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (valueSchema) {\n return {\n ...schema,\n values: valueSchema,\n additionalProperties: true\n };\n }\n } else {\n const property = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (!property) {\n continue;\n }\n\n property.metadata = (property.metadata ?? {}) as TMetadata;\n property.metadata.isReadonly = propertyReflection.isReadonly();\n property.metadata.isIgnored = propertyReflection.isIgnored();\n property.metadata.isInternal = propertyReflection.isInternal();\n property.metadata.isRuntime = propertyReflection.isRuntime();\n property.metadata.isPrimaryKey = propertyReflection.isPrimaryKey();\n property.metadata.isHidden = propertyReflection.isHidden();\n\n if (propertyReflection.hasDefault()) {\n property.metadata.default = propertyReflection.getDefaultValue();\n }\n if (isSetString(propertyReflection.getDescription())) {\n property.metadata.description = propertyReflection.getDescription();\n }\n if (isSetArray(propertyReflection.getAlias())) {\n property.metadata.alias = propertyReflection.getAlias();\n }\n if (isSetString(propertyReflection.getTitle())) {\n property.metadata.title = propertyReflection.getTitle();\n }\n\n if (propertyReflection.isOptional()) {\n optionalProperties[propertyReflection.name] = property;\n } else {\n properties[propertyReflection.name] = property;\n }\n }\n }\n\n if (Object.keys(properties).length > 0) {\n schema.properties = properties;\n } else if (Object.keys(optionalProperties).length > 0) {\n schema.optionalProperties = optionalProperties;\n } else {\n schema.properties = {};\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;AAsCA,SAAS,qBACP,OASY;AACZ,SAAQ,OAAR;EACE,KAAK,gBAAgB,QACnB,QAAO;EACT,KAAK,gBAAgB,KACnB,QAAO;EACT,KAAK,gBAAgB,MACnB,QAAO;EACT,KAAK,gBAAgB,MACnB,QAAO;EACT,KAAK,gBAAgB,OACnB,QAAO;EACT,KAAK,gBAAgB,MACnB,QAAO;EACT,KAAK,gBAAgB,OACnB,QAAO;EACT,KAAK,gBAAgB;EACrB,KAAK,gBAAgB,QACnB,QAAO;EACT,KAAK,gBAAgB,QACnB,QAAO;EACT,KAAK;EACL,QACE,QAAO;;;;;;;;;;;;;;;;;;;AAoBb,SAAgB,uBAEd,YAAwD;AAGxD,QAFe,gBAA2B,WAE7B;;;;;;;;AASf,SAAS,gBAEP,YAAwD;CACxD,MAAM,SAAS,EAAE;AAEjB,KAAI,YAAa,YAA0C,KAAK,EAAE;EAChE,MAAM,OAAQ,WAAwC;AAEtD,SAAO,WAAY,OAAO,YAAY,EAAE;AACxC,MAAI,KAAK,aAAa,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aAAa,mBAAmB,YAAY;AAC9D,WAAS,SAAS,YAAY,mBAAmB,WAAW;AAC5D,WAAS,SAAS,aAAa,mBAAmB,YAAY;AAC9D,WAAS,SAAS,YAAY,mBAAmB,WAAW;AAC5D,WAAS,SAAS,eAAe,mBAAmB,cAAc;AAClE,WAAS,SAAS,WAAW,mBAAmB,UAAU;AAE1D,MAAI,mBAAmB,YAAY,CACjC,UAAS,SAAS,UAAU,mBAAmB,iBAAiB;AAElE,MAAI,YAAY,mBAAmB,gBAAgB,CAAC,CAClD,UAAS,SAAS,cAAc,mBAAmB,gBAAgB;AAErE,MAAI,WAAW,mBAAmB,UAAU,CAAC,CAC3C,UAAS,SAAS,QAAQ,mBAAmB,UAAU;AAEzD,MAAI,YAAY,mBAAmB,UAAU,CAAC,CAC5C,UAAS,SAAS,QAAQ,mBAAmB,UAAU;AAGzD,MAAI,mBAAmB,YAAY,CACjC,oBAAmB,mBAAmB,QAAQ;MAE9C,YAAW,mBAAmB,QAAQ;;AAK5C,KAAI,OAAO,KAAK,WAAW,CAAC,SAAS,EACnC,QAAO,aAAa;UACX,OAAO,KAAK,mBAAmB,CAAC,SAAS,EAClD,QAAO,qBAAqB;KAE5B,QAAO,aAAa,EAAE;AAGxB,QAAO"}
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 { isSetArray, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { JTDSchemaType, SchemaMetadata } from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to the JTD numeric `type` keyword that best preserves the underlying width and signedness.\n *\n * @param brand - The Deepkit `TypeNumberBrand` of a numeric reflection, or `undefined` when no brand is set.\n * @returns The JTD numeric `type` keyword to use.\n */\nfunction numberBrandToJtdType(\n brand: TypeNumberBrand | undefined\n):\n | \"int8\"\n | \"uint8\"\n | \"int16\"\n | \"uint16\"\n | \"int32\"\n | \"uint32\"\n | \"float32\"\n | \"float64\" {\n switch (brand) {\n case TypeNumberBrand.integer:\n return \"int32\";\n case TypeNumberBrand.int8:\n return \"int8\";\n case TypeNumberBrand.uint8:\n return \"uint8\";\n case TypeNumberBrand.int16:\n return \"int16\";\n case TypeNumberBrand.uint16:\n return \"uint16\";\n case TypeNumberBrand.int32:\n return \"int32\";\n case TypeNumberBrand.uint32:\n return \"uint32\";\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return \"float32\";\n case TypeNumberBrand.float64:\n return \"float64\";\n case undefined:\n default:\n return \"float64\";\n }\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Type Definition (RFC 8927) form suitable for AJV's JTD validator.\n *\n * @remarks\n * Some TypeScript constructs have no direct JTD equivalent and are handled with the closest available form:\n *\n * - `null` and `undefined` become the empty JTD form with `nullable: true`.\n * - Unions of primitives that cannot be expressed as a JTD enum collapse to the empty form (which validates any value).\n * - String/number/bigint literal unions are emitted as a JTD enum (non-string members are stringified, as JTD requires string enum members).\n * - Tuples are emitted as a JTD elements form whose element schema is the single tuple member type, or the empty schema for mixed tuples.\n * - `Date` is emitted as `{ type: \"timestamp\" }`.\n * - Discriminated unions of object literals (a shared string-literal tag property) are emitted as a JTD discriminator form.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nexport function reflectionToJsonSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const result = reflectionToJtd<TMetadata>(reflection);\n\n return result;\n}\n\n/**\n * Internal worker that performs the recursive Deepkit reflection → JTD conversion.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nfunction reflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const schema = {} as JTDSchemaType<TMetadata>;\n\n if (isSetObject((reflection as { tags?: TagsReflection })?.tags)) {\n const tags = (reflection as { tags: TagsReflection }).tags;\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n if (tags.readonly === true) {\n schema.metadata.isReadonly = true;\n }\n if (tags.ignore === true) {\n schema.metadata.isIgnored = true;\n }\n if (tags.internal === true) {\n schema.metadata.isInternal = true;\n }\n if (tags.runtime === true) {\n schema.metadata.isRuntime = true;\n }\n if (tags.hidden === true) {\n schema.metadata.isHidden = true;\n }\n if (isSetArray(tags.alias)) {\n schema.metadata.alias = tags.alias;\n }\n if (isSetString(tags.title)) {\n schema.metadata.title = tags.title;\n }\n }\n\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return {};\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return { nullable: true };\n case ReflectionKind.string:\n return { ...schema, type: \"string\" };\n case ReflectionKind.boolean:\n return { ...schema, type: \"boolean\" };\n case ReflectionKind.number:\n return {\n ...schema,\n type: numberBrandToJtdType(reflection.brand)\n };\n case ReflectionKind.bigint:\n // JTD has no native 64-bit integer type — float64 is the widest numeric form.\n return { ...schema, type: \"float64\" };\n case ReflectionKind.regexp:\n return { ...schema, type: \"string\" };\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (typeof literal === \"string\") {\n return { ...schema, enum: [literal] };\n }\n\n if (typeof literal === \"number\" || typeof literal === \"bigint\") {\n return {\n ...schema,\n enum: [String(literal)]\n };\n }\n\n if (typeof literal === \"boolean\") {\n // JTD has no boolean literal — emit the type form.\n return { ...schema, type: \"boolean\" };\n }\n\n if (literal instanceof RegExp) {\n return { ...schema, type: \"string\" };\n }\n\n return schema;\n }\n case ReflectionKind.templateLiteral:\n return { ...schema, type: \"string\" };\n case ReflectionKind.enum: {\n const values = reflection.values\n .filter(\n (value): value is string | number =>\n typeof value === \"string\" || typeof value === \"number\"\n )\n .map(value => String(value));\n\n const unique = Array.from(new Set(values));\n if (unique.length === 0) {\n return schema;\n }\n\n return { ...schema, enum: unique };\n }\n case ReflectionKind.array: {\n const items = reflectionToJtd<TMetadata>(reflection.type);\n\n return { ...schema, elements: items ?? {} };\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJtd<TMetadata>(member.type))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n if (items.length === 0) {\n return { ...schema, elements: {} };\n }\n\n if (items.length === 1) {\n return { ...schema, elements: items[0]! };\n }\n\n // JTD has no tuple form — accept any element shape.\n return { ...schema, elements: {} };\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n\n const nullable = reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n );\n const nonNull = branches.filter(b => !isPureNullable(b));\n\n if (nonNull.length === 0) {\n return { ...schema, nullable: true };\n }\n\n if (nonNull.length === 1) {\n const only = nonNull[0]!;\n if (nullable) {\n (only as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...only };\n }\n\n // String-enum union: combine all enum branches into one JTD enum.\n if (nonNull.every(isEnumForm)) {\n const merged = Array.from(\n new Set(nonNull.flatMap(b => (b as { enum: string[] }).enum))\n );\n const form: JTDSchemaType<TMetadata> = { ...schema, enum: merged };\n\n if (nullable) {\n (form as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...form };\n }\n\n // Discriminated union of object literals: detect a shared string-literal tag.\n const discriminator = tryReflectionDiscriminator<TMetadata>(\n reflection.types\n );\n if (discriminator) {\n if (nullable) {\n (discriminator as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...discriminator };\n }\n\n // Fallback — JTD has no general union; allow any value.\n const fallback: JTDSchemaType<TMetadata> = {};\n if (nullable) {\n (fallback as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...fallback };\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter(\n (item): item is JTDSchemaType<TMetadata> | undefined =>\n item !== undefined\n );\n if (members.length === 0) {\n return undefined as JTDSchemaType<TMetadata> | undefined;\n }\n\n if (members.length === 1) {\n return { ...schema, ...members[0] };\n }\n\n if (\n members.every(member => member && isPropertiesForm<TMetadata>(member))\n ) {\n return mergePropertiesForms<TMetadata>(\n members as JTDSchemaType<TMetadata>[]\n );\n }\n\n return { ...schema, ...members[0] };\n }\n case ReflectionKind.promise:\n return reflectionToJtd<TMetadata>(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJtd<TMetadata>(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 { ...schema, type: \"timestamp\" };\n case \"RegExp\":\n return { ...schema, type: \"string\" };\n case \"URL\":\n return { ...schema, type: \"string\" };\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJtd<TMetadata>(itemType)\n : undefined;\n\n return { ...schema, elements: items ?? {} };\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJtd<TMetadata>(valueType)\n : undefined;\n\n return { ...schema, values: values ?? {} };\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 // Base64-encoded binary payload — represented as a plain string in JTD.\n return { ...schema, type: \"string\" };\n case undefined:\n default:\n return objectReflectionToJtd<TMetadata>(reflection);\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\n/**\n * Tests whether a JTD form is an enum form.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD enum form.\n */\nfunction isEnumForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is { enum: string[]; nullable?: boolean; metadata?: TMetadata } {\n return Array.isArray((form as { enum?: unknown[] }).enum);\n}\n\n/**\n * Tests whether a JTD form is a properties form (object).\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD properties form.\n */\nfunction isPropertiesForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n nullable?: boolean;\n metadata?: TMetadata;\n} {\n return (\n \"properties\" in (form as object) || \"optionalProperties\" in (form as object)\n );\n}\n\n/**\n * Tests whether a JTD form is the empty `{ nullable: true }` placeholder.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form has no shape constraints beyond `nullable`.\n */\nfunction isPureNullable<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(form: JTDSchemaType<TMetadata>): boolean {\n const keys = Object.keys(form as object).filter(\n k => k !== \"nullable\" && k !== \"metadata\"\n );\n\n return (\n keys.length === 0 && (form as { nullable?: boolean }).nullable === true\n );\n}\n\n/**\n * Shallow-merges two JTD properties forms, unioning their `properties` and `optionalProperties` maps.\n *\n * @param forms - The JTD properties forms to merge.\n * @returns The merged JTD properties form.\n */\nfunction mergePropertiesForms<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(forms: JTDSchemaType<TMetadata>[]): JTDSchemaType<TMetadata> {\n const merged: {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n } = {\n properties: {},\n optionalProperties: {}\n };\n\n for (const form of forms) {\n const properties = (\n form as { properties?: Record<string, JTDSchemaType<TMetadata>> }\n ).properties;\n const optionalProperties = (\n form as { optionalProperties?: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties;\n if (properties) {\n defu(merged.properties, properties);\n }\n if (optionalProperties) {\n defu(merged.optionalProperties, optionalProperties);\n }\n if ((form as { additionalProperties?: boolean }).additionalProperties) {\n merged.additionalProperties = true;\n }\n }\n\n const hasProperties = Object.keys(merged.properties).length > 0;\n const hasOptional = Object.keys(merged.optionalProperties).length > 0;\n const result: JTDSchemaType<TMetadata> = {};\n\n if (hasProperties) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = merged.properties;\n } else if (!hasOptional) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = {};\n }\n\n if (hasOptional) {\n (\n result as { optionalProperties: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties = merged.optionalProperties;\n }\n\n if (merged.additionalProperties) {\n (result as { additionalProperties: boolean }).additionalProperties = true;\n }\n\n return result;\n}\n\n/**\n * Detects whether a Deepkit union represents a tagged union and, when so, emits the corresponding JTD discriminator form.\n *\n * @param types - The Deepkit reflection types that make up the union branches.\n * @returns A JTD discriminator form if every non-null branch is an object literal that shares a string-literal tag property, otherwise `undefined`.\n */\nfunction tryReflectionDiscriminator<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(types: readonly Type[]): JTDSchemaType<TMetadata> | 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 mapping: Record<string, JTDSchemaType<TMetadata>> = {};\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 // Build the branch body excluding the discriminator property.\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 = objectReflectionToJtd<TMetadata>(filteredBranch);\n if (!body || !isPropertiesForm<TMetadata>(body)) {\n return undefined;\n }\n\n mapping[first.literal] = body;\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return { discriminator: tagKey, mapping };\n}\n\n/**\n * Internal worker that produces a JTD properties form (or `values` form for index signatures alone) from a Deepkit object-like type.\n *\n * @param type - The class or object literal type whose members should be serialized.\n * @returns A JTD properties or values form describing the type's members.\n */\nfunction objectReflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(type: TypeObjectLiteral | TypeClass): JTDSchemaType<TMetadata> {\n const reflection = ReflectionClass.from(type);\n\n const schema = {} as {\n properties?: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n metadata?: TMetadata;\n };\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n schema.metadata.isReadonly = reflection.isReadonly();\n schema.metadata.isIgnored = reflection.isIgnored();\n schema.metadata.isInternal = reflection.isInternal();\n schema.metadata.isRuntime = reflection.isRuntime();\n schema.metadata.isHidden = reflection.isHidden();\n\n if (isSetString(reflection.databaseSchemaName)) {\n schema.metadata.resourceId = reflection.databaseSchemaName;\n }\n if (isSetString(reflection.getName())) {\n schema.metadata.name = reflection.getName();\n }\n if (isSetString(reflection.getDescription())) {\n schema.metadata.description = reflection.getDescription();\n }\n if (isSetArray(reflection.getAlias())) {\n schema.metadata.alias = reflection.getAlias();\n }\n if (isSetString(reflection.getTitle())) {\n schema.metadata.title = reflection.getTitle();\n }\n\n const properties: Record<string, JTDSchemaType<TMetadata>> = {};\n const optionalProperties: Record<string, JTDSchemaType<TMetadata>> = {};\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n const valueSchema = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (valueSchema) {\n return {\n ...schema,\n values: valueSchema,\n additionalProperties: true\n };\n }\n } else {\n const property = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (!property) {\n continue;\n }\n\n property.metadata = (property.metadata ?? {}) as TMetadata;\n property.metadata.isReadonly = propertyReflection.isReadonly();\n property.metadata.isIgnored = propertyReflection.isIgnored();\n property.metadata.isInternal = propertyReflection.isInternal();\n property.metadata.isRuntime = propertyReflection.isRuntime();\n property.metadata.isPrimaryKey = propertyReflection.isPrimaryKey();\n property.metadata.isHidden = propertyReflection.isHidden();\n property.nullable = propertyReflection.isNullable();\n property.metadata.visibility = propertyReflection.isPublic()\n ? \"public\"\n : propertyReflection.isProtected()\n ? \"protected\"\n : propertyReflection.isPrivate()\n ? \"private\"\n : undefined;\n\n if (propertyReflection.hasDefault()) {\n property.metadata.default = propertyReflection.getDefaultValue();\n }\n if (isSetString(propertyReflection.getNameAsString())) {\n property.metadata.name = propertyReflection.getNameAsString();\n }\n if (isSetArray(propertyReflection.getGroups())) {\n property.metadata.groups = propertyReflection.getGroups();\n }\n if (isSetString(propertyReflection.getDescription())) {\n property.metadata.description = propertyReflection.getDescription();\n }\n if (isSetArray(propertyReflection.getAlias())) {\n property.metadata.alias = propertyReflection.getAlias();\n }\n if (isSetString(propertyReflection.getTitle())) {\n property.metadata.title = propertyReflection.getTitle();\n }\n\n if (propertyReflection.isOptional()) {\n optionalProperties[propertyReflection.name] = property;\n } else {\n properties[propertyReflection.name] = property;\n }\n }\n }\n\n if (Object.keys(properties).length > 0) {\n schema.properties = properties;\n } else if (Object.keys(optionalProperties).length > 0) {\n schema.optionalProperties = optionalProperties;\n } else {\n schema.properties = {};\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;AAuCA,SAAS,qBACP,OASY;CACZ,QAAQ,OAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;EACT,KAAK,gBAAgB,MACnB,OAAO;EACT,KAAK,gBAAgB,OACnB,OAAO;EACT,KAAK,gBAAgB,OACnB,OAAO;EACT,KAAK,gBAAgB,QACnB,OAAO;EACT,KAAK,gBAAgB,OACnB,OAAO;EACT,KAAK,gBAAgB,QACnB,OAAO;EACT,KAAK,gBAAgB;EACrB,KAAK,gBAAgB,SACnB,OAAO;EACT,KA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;EAExD,IAAI,YAAY,mBAAmB,SAAS,CAAC,GAC3C,SAAS,SAAS,QAAQ,mBAAmB,SAAS;EAGxD,IAAI,mBAAmB,WAAW,GAChC,mBAAmB,mBAAmB,QAAQ;OAE9C,WAAW,mBAAmB,QAAQ;CAE1C;CAGF,IAAI,OAAO,KAAK,UAAU,EAAE,SAAS,GACnC,OAAO,aAAa;MACf,IAAI,OAAO,KAAK,kBAAkB,EAAE,SAAS,GAClD,OAAO,qBAAqB;MAE5B,OAAO,aAAa,CAAC;CAGvB,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.mjs","names":[],"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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { findFileDotExtension } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { bundle, BundleOptions } from \"./bundle\";\nimport { TypeDefinitionReference } from \"./types\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param type - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n type: TypeDefinitionReference,\n overrides?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(type)) {\n typeDefinition = parseTypeDefinition(type) as TypeDefinition;\n } else {\n typeDefinition = type;\n }\n\n const result = await bundle<TContext>(\n context,\n typeDefinition.file,\n overrides\n );\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.text, {\n filename: result.path,\n ext: findFileDotExtension(result.path)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n typeDefinition.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n typeDefinition.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} 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: TypeDefinitionReference,\n options?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(input)) {\n typeDefinition = parseTypeDefinition(input) as TypeDefinition;\n } else {\n typeDefinition = input;\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n typeDefinition,\n options\n );\n\n let exportName = typeDefinition.name;\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 typeDefinition.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n typeDefinition.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 TypeDefinition} 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: TypeDefinitionReference,\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":";;;;;;;;;;;;;;;;;AAqCA,eAAsB,cAIpB,SACA,MACA,WACkB;CAClB,IAAI;AACJ,KAAI,YAAY,KAAK,CACnB,kBAAiB,oBAAoB,KAAK;KAE1C,kBAAiB;CAGnB,MAAM,SAAS,MAAM,OACnB,SACA,eAAe,MACf,UACD;CAED,IAAI;AACJ,KAAI;AACF,aAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAA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AO;EACR,CAAC,CACH,EACF,CAAC,CACH,CACF"}
1
+ {"version":3,"file":"resolve.mjs","names":[],"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 { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { findFileDotExtension } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { bundle, BundleOptions } from \"./bundle\";\nimport { TypeDefinitionReference } from \"./types\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param type - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n type: TypeDefinitionReference,\n overrides?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(type)) {\n typeDefinition = parseTypeDefinition(type) as TypeDefinition;\n } else {\n typeDefinition = type;\n }\n\n const result = await bundle<TContext>(\n context,\n typeDefinition.file,\n overrides\n );\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.text, {\n filename: result.path,\n ext: findFileDotExtension(result.path)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n typeDefinition.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n typeDefinition.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} 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: TypeDefinitionReference,\n options?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(input)) {\n typeDefinition = parseTypeDefinition(input) as TypeDefinition;\n } else {\n typeDefinition = input;\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n typeDefinition,\n options\n );\n\n let exportName = typeDefinition.name;\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 typeDefinition.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n typeDefinition.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 TypeDefinition} 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: TypeDefinitionReference,\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":";;;;;;;;;;;;;;;;;AAqCA,eAAsB,cAIpB,SACA,MACA,WACkB;CAClB,IAAI;CACJ,IAAI,YAAY,IAAI,GAClB,iBAAiB,oBAAoB,IAAI;MAEzC,iBAAiB;CAGnB,MAAM,SAAS,MAAM,OACnB,SACA,eAAe,MACf,SACF;CAEA,IAAI;CACJ,IAAI;EACF,WAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAAK,qBAAqB,OAAO,IAAI;EACvC,CAAC;CACH,SAAS,OAAO;EACd,IACE,YAAa,MAAgB,OAAO,KACpC,IAAI,OACF,uBAAuB,QAAQ,OAAO,WAAW,QAAQ,aAAa,KACxE,EAAE,KAAM,MAAgB,OAAO,GAC/B;GACA,MAAM,aAAc,MAAgB,QAAQ,MAC1C,IAAI,OACF,wBAAwB,QAAQ,OAAO,WAAW,QAAQ,aAAa,MACzE,CACF,IAAI;GACJ,MAAM,IAAI,MACR,eAAe,WAAW,4CACxB,eAAe,KAChB,uHACC,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGZ,OAAO,SACK,IAER;EACF;EAEA,MAAM,IAAI,MACR,8CACE,eAAe,KAChB,YAAa,MAAgB,UAC5B,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGV,OAAO,SACG,IAER;CACF;CAEA,OAAO;AACT;;;;;;;;;AAUA,eAAsB,QAIpB,SACA,OACA,SACkB;CAClB,IAAI;CACJ,IAAI,YAAY,KAAK,GACnB,iBAAiB,oBAAoB,KAAK;MAE1C,iBAAiB;CAGnB,MAAM,WAAW,MAAM,cACrB,SACA,gBACA,OACF;CAEA,IAAI,aAAa,eAAe;CAChC,IAAI,CAAC,YACH,aAAa;CAGf,MAAM,iBAAiB,SAAS,eAAe,SAAS,MAAM;CAC9D,IAAI,mBAAmB,QACrB,MAAM,IAAI,MACR,eAAe,WAAW,kCACxB,eAAe,KAChB,YACC,OAAO,KAAK,QAAQ,EAAE,WAAW,IAC7B,gFACE,eAAe,KAChB,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,7 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
3
  let _stryke_type_checks = require("@stryke/type-checks");
4
- let _stryke_json_schema = require("@stryke/json/schema");
5
4
 
6
5
  //#region src/type-checks.ts
7
6
  /**
@@ -10,8 +9,17 @@ let _stryke_json_schema = require("@stryke/json/schema");
10
9
  * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
11
10
  * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
12
11
  */
12
+ function isJTDSchemaObject(input) {
13
+ return (0, _stryke_type_checks.isSetObject)(input) && ("properties" in input && (0, _stryke_type_checks.isObject)(input.properties) || "optionalProperties" in input && (0, _stryke_type_checks.isObject)(input.optionalProperties));
14
+ }
15
+ /**
16
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
17
+ *
18
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
19
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
20
+ */
13
21
  function isJTDSchema(input) {
14
- return (0, _stryke_json_schema.isJsonSchemaObjectType)(input) && "jtd" in input && input.jtd === true;
22
+ return (0, _stryke_type_checks.isSetObject)(input) && (isJTDSchemaObject(input) || "elements" in input || "values" in input || "ref" in input || "type" in input || "enum" in input || "discriminator" in input && (0, _stryke_type_checks.isSetString)(input.discriminator) && "mapping" in input && (0, _stryke_type_checks.isObject)(input.mapping));
15
23
  }
16
24
  /**
17
25
  * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
@@ -67,10 +75,21 @@ function isSchema(input) {
67
75
  function isExtractedSchema(input) {
68
76
  return isSchema(input) && "source" in input && (0, _stryke_type_checks.isSetObject)(input.source) && "schema" in input.source && isJTDSchema(input.source.schema) && "variant" in input.source && (0, _stryke_type_checks.isSetString)(input.source.variant);
69
77
  }
78
+ /**
79
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
80
+ *
81
+ * @param input - The input to check for being a {@link ObjectSchema}.
82
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
83
+ */
84
+ function isObjectSchema(input) {
85
+ return isSchema(input) && isJTDSchemaObject(input.schema);
86
+ }
70
87
 
71
88
  //#endregion
72
89
  exports.isExtractedSchema = isExtractedSchema;
73
90
  exports.isJTDSchema = isJTDSchema;
91
+ exports.isJTDSchemaObject = isJTDSchemaObject;
92
+ exports.isObjectSchema = isObjectSchema;
74
93
  exports.isSchema = isSchema;
75
94
  exports.isUntypedInput = isUntypedInput;
76
95
  exports.isUntypedSchema = isUntypedSchema;
@@ -1,8 +1,15 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
1
+ import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
2
2
  import { InputObject, Schema } from "untyped";
3
3
  import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
4
 
5
5
  //#region src/type-checks.d.ts
6
+ /**
7
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
+ *
9
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
10
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
11
+ */
12
+ declare function isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
6
13
  /**
7
14
  * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
15
  *
@@ -38,6 +45,13 @@ declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(inp
38
45
  * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
39
46
  */
40
47
  declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
48
+ /**
49
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
50
+ *
51
+ * @param input - The input to check for being a {@link ObjectSchema}.
52
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
53
+ */
54
+ declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
41
55
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
56
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
43
57
  //# sourceMappingURL=type-checks.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAUV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;AAxBnB;;;;;iBA0CgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA"}
1
+ {"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;AAhB+B;iBAsCzC,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;;;;;;;iBAwDvD,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;;AAtGgB;AAsBnC;;;iBAkGgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA;;;;;AApG2B;AAwDvE;iBA8DgB,cAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,YAAA,CAAa,SAAA"}
@@ -1,8 +1,15 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
1
+ import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
2
2
  import { InputObject, Schema } from "untyped";
3
3
  import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
4
 
5
5
  //#region src/type-checks.d.ts
6
+ /**
7
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
+ *
9
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
10
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
11
+ */
12
+ declare function isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
6
13
  /**
7
14
  * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
15
  *
@@ -38,6 +45,13 @@ declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(inp
38
45
  * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
39
46
  */
40
47
  declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
48
+ /**
49
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
50
+ *
51
+ * @param input - The input to check for being a {@link ObjectSchema}.
52
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
53
+ */
54
+ declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
41
55
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
56
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
43
57
  //# sourceMappingURL=type-checks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAUV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;AAxBnB;;;;;iBA0CgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA"}
1
+ {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;AAhB+B;iBAsCzC,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;;;;;;;iBAwDvD,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,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