@powerlines/schema 0.11.45 → 0.11.46

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 (69) hide show
  1. package/dist/bundle.cjs +1 -1
  2. package/dist/bundle.d.cts +1 -1
  3. package/dist/bundle.d.mts +1 -1
  4. package/dist/bundle.mjs +1 -1
  5. package/dist/bundle.mjs.map +1 -1
  6. package/dist/codegen.cjs +28 -22
  7. package/dist/codegen.d.cts +11 -11
  8. package/dist/codegen.d.cts.map +1 -1
  9. package/dist/codegen.d.mts +11 -11
  10. package/dist/codegen.d.mts.map +1 -1
  11. package/dist/codegen.mjs +36 -30
  12. package/dist/codegen.mjs.map +1 -1
  13. package/dist/constants.cjs +15 -11
  14. package/dist/constants.d.cts +4 -3
  15. package/dist/constants.d.cts.map +1 -1
  16. package/dist/constants.d.mts +4 -3
  17. package/dist/constants.d.mts.map +1 -1
  18. package/dist/constants.mjs +13 -10
  19. package/dist/constants.mjs.map +1 -1
  20. package/dist/extract.cjs +158 -20
  21. package/dist/extract.d.cts +55 -16
  22. package/dist/extract.d.cts.map +1 -1
  23. package/dist/extract.d.mts +55 -16
  24. package/dist/extract.d.mts.map +1 -1
  25. package/dist/extract.mjs +158 -22
  26. package/dist/extract.mjs.map +1 -1
  27. package/dist/helpers.cjs +43 -8
  28. package/dist/helpers.d.cts +40 -6
  29. package/dist/helpers.d.cts.map +1 -1
  30. package/dist/helpers.d.mts +40 -6
  31. package/dist/helpers.d.mts.map +1 -1
  32. package/dist/helpers.mjs +43 -10
  33. package/dist/helpers.mjs.map +1 -1
  34. package/dist/index.cjs +39 -7
  35. package/dist/index.d.cts +8 -8
  36. package/dist/index.d.mts +8 -8
  37. package/dist/index.mjs +7 -7
  38. package/dist/metadata.cjs +9 -35
  39. package/dist/metadata.d.cts +5 -26
  40. package/dist/metadata.d.cts.map +1 -1
  41. package/dist/metadata.d.mts +5 -26
  42. package/dist/metadata.d.mts.map +1 -1
  43. package/dist/metadata.mjs +9 -33
  44. package/dist/metadata.mjs.map +1 -1
  45. package/dist/persistence.d.cts +4 -4
  46. package/dist/persistence.d.cts.map +1 -1
  47. package/dist/persistence.d.mts +4 -4
  48. package/dist/persistence.d.mts.map +1 -1
  49. package/dist/persistence.mjs.map +1 -1
  50. package/dist/reflection.cjs +72 -50
  51. package/dist/reflection.d.cts +1 -1
  52. package/dist/reflection.d.cts.map +1 -1
  53. package/dist/reflection.d.mts +1 -1
  54. package/dist/reflection.d.mts.map +1 -1
  55. package/dist/reflection.mjs +74 -52
  56. package/dist/reflection.mjs.map +1 -1
  57. package/dist/type-checks.cjs +363 -83
  58. package/dist/type-checks.d.cts +138 -16
  59. package/dist/type-checks.d.cts.map +1 -1
  60. package/dist/type-checks.d.mts +138 -16
  61. package/dist/type-checks.d.mts.map +1 -1
  62. package/dist/type-checks.mjs +336 -85
  63. package/dist/type-checks.mjs.map +1 -1
  64. package/dist/types.d.cts +901 -176
  65. package/dist/types.d.cts.map +1 -1
  66. package/dist/types.d.mts +901 -176
  67. package/dist/types.d.mts.map +1 -1
  68. package/dist/validate.mjs.map +1 -1
  69. package/package.json +5 -5
package/dist/metadata.mjs CHANGED
@@ -10,43 +10,17 @@ import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object"
10
10
  * @param metadata - The Powerlines schema metadata to apply.
11
11
  * @returns A new JSON Schema fragment with the metadata applied.
12
12
  */
13
- function applySchemaMetadata(schema, metadata) {
14
- if (!metadata) return schema;
13
+ function applyJsonSchemaMetadata(schema, metadata) {
14
+ if (!metadata || !isSetObject$1(schema)) return schema;
15
15
  const result = { ...schema };
16
+ const mutableResult = result;
16
17
  for (const key of JSON_SCHEMA_METADATA_KEYS) {
17
18
  const value = metadata[key];
18
- if (value !== void 0 && value !== null) result[key] = value;
19
+ if (value !== void 0 && value !== null) mutableResult[key] = value;
19
20
  }
20
21
  return result;
21
22
  }
22
23
  /**
23
- * Returns whether a JSON Schema fragment accepts `null`.
24
- *
25
- * @remarks
26
- * This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
27
- *
28
- * @param schema - The JSON Schema fragment to check.
29
- * @returns `true` if the schema accepts `null`, otherwise `false`.
30
- */
31
- function isSchemaNullable(schema) {
32
- if (!isSetObject$1(schema)) return false;
33
- if (schema.nullable === true) return true;
34
- return readSchemaTypes(schema).includes("null");
35
- }
36
- /**
37
- * Returns whether an object property is optional (not listed in `required`).
38
- *
39
- * @remarks
40
- * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.
41
- *
42
- * @param parent - The parent JSON Schema object containing the property.
43
- * @param propertyName - The name of the property to check for optionality.
44
- * @returns `true` if the property is optional, otherwise `false`.
45
- */
46
- function isPropertyOptional(parent, propertyName) {
47
- return !(parent.required ?? []).includes(propertyName) && !isSchemaNullable(parent.properties[propertyName]);
48
- }
49
- /**
50
24
  * Normalizes the JSON Schema `type` keyword to a string array.
51
25
  *
52
26
  * @remarks
@@ -56,8 +30,10 @@ function isPropertyOptional(parent, propertyName) {
56
30
  * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
57
31
  */
58
32
  function readSchemaTypes(schema) {
59
- if (Array.isArray(schema?.type)) return schema.type.filter(isSetString);
60
- if (isSetString(schema?.type)) return [schema.type];
33
+ if (!isSetObject$1(schema)) return [];
34
+ const objectSchema = schema;
35
+ if (Array.isArray(objectSchema.type)) return objectSchema.type.filter((type) => isSetString(type));
36
+ if (isSetString(objectSchema.type) && objectSchema.type !== "object" && objectSchema.type !== "array") return [objectSchema.type];
61
37
  return [];
62
38
  }
63
39
  /**
@@ -72,5 +48,5 @@ function getPrimarySchemaType(schema) {
72
48
  }
73
49
 
74
50
  //#endregion
75
- export { applySchemaMetadata, getPrimarySchemaType, isPropertyOptional, isSchemaNullable, readSchemaTypes };
51
+ export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
76
52
  //# sourceMappingURL=metadata.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.mjs","names":["isSetObject"],"sources":["../src/metadata.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaNullable,\n JsonSchemaObject,\n JsonSchemaPrimitiveType,\n SchemaMetadata\n} from \"./types\";\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applySchemaMetadata<\n T = unknown,\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(schema: JsonSchema<T>, metadata: TMetadata | undefined): JsonSchema<T> {\n if (!metadata) {\n return schema;\n }\n\n const result: JsonSchema<T> = { ...schema };\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n result[key as keyof JsonSchema<T>] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Returns whether a JSON Schema fragment accepts `null`.\n *\n * @remarks\n * This is true if the schema has `nullable: true` or if its `type` includes `\"null\"`.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns `true` if the schema accepts `null`, otherwise `false`.\n */\nexport function isSchemaNullable<T = unknown>(schema?: JsonSchema<T>): boolean {\n if (!isSetObject(schema)) {\n return false;\n }\n\n if ((schema as JsonSchemaNullable<T>).nullable === true) {\n return true;\n }\n\n const types = readSchemaTypes(schema);\n\n return types.includes(\"null\");\n}\n\n/**\n * Returns whether an object property is optional (not listed in `required`).\n *\n * @remarks\n * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.\n *\n * @param parent - The parent JSON Schema object containing the property.\n * @param propertyName - The name of the property to check for optionality.\n * @returns `true` if the property is optional, otherwise `false`.\n */\nexport function isPropertyOptional<\n T extends Record<string, any> = Record<string, any>\n>(parent: JsonSchemaObject<T>, propertyName: string): boolean {\n const required = parent.required ?? [];\n\n return (\n !required.includes(propertyName) &&\n !isSchemaNullable<T>(parent.properties[propertyName] as JsonSchema<T>)\n );\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes<T = unknown>(\n schema?: JsonSchema<T>\n): JsonSchemaPrimitiveType[] {\n if (Array.isArray(schema?.type)) {\n return schema.type.filter(isSetString) as JsonSchemaPrimitiveType[];\n }\n if (isSetString(schema?.type)) {\n return [schema.type as JsonSchemaPrimitiveType];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType<T = unknown>(\n schema?: JsonSchema<T>\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,SAAgB,oBAGd,QAAuB,UAAgD;CACvE,IAAI,CAAC,UACH,OAAO;CAGT,MAAM,SAAwB,EAAE,GAAG,OAAO;CAC1C,KAAK,MAAM,OAAO,2BAA2B;EAC3C,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,UAAa,UAAU,MACnC,OAAO,OAA8B;CAEzC;CAEA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,iBAA8B,QAAiC;CAC7E,IAAI,CAACA,cAAY,MAAM,GACrB,OAAO;CAGT,IAAK,OAAiC,aAAa,MACjD,OAAO;CAKT,OAFc,gBAAgB,MAEnB,EAAE,SAAS,MAAM;AAC9B;;;;;;;;;;;AAYA,SAAgB,mBAEd,QAA6B,cAA+B;CAG5D,OACE,EAHe,OAAO,YAAY,CAAC,GAGzB,SAAS,YAAY,KAC/B,CAAC,iBAAoB,OAAO,WAAW,aAA8B;AAEzE;;;;;;;;;;AAWA,SAAgB,gBACd,QAC2B;CAC3B,IAAI,MAAM,QAAQ,QAAQ,IAAI,GAC5B,OAAO,OAAO,KAAK,OAAO,WAAW;CAEvC,IAAI,YAAY,QAAQ,IAAI,GAC1B,OAAO,CAAC,OAAO,IAA+B;CAEhD,OAAO,CAAC;AACV;;;;;;;AAQA,SAAgB,qBACd,QACqC;CACrC,IAAI,CAACA,cAAY,MAAM,GACrB;CAGF,OAAO,gBAAgB,MAAM,EAAE,MAAK,SAAQ,SAAS,MAAM;AAC7D"}
1
+ {"version":3,"file":"metadata.mjs","names":["isSetObject"],"sources":["../src/metadata.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaMetadataKeywords,\n JsonSchemaPrimitiveType,\n JsonSchemaType\n} from \"./types\";\n\ninterface JsonSchemaTypeView {\n type?: JsonSchemaType | readonly JsonSchemaType[];\n}\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applyJsonSchemaMetadata(\n schema: JsonSchema,\n metadata: JsonSchemaMetadataKeywords | undefined\n): JsonSchema {\n if (!metadata || !isSetObject(schema)) {\n return schema;\n }\n\n const result: JsonSchema = { ...schema };\n const mutableResult = result as Record<string, unknown>;\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n mutableResult[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType[] {\n if (!isSetObject(schema)) {\n return [];\n }\n\n const objectSchema = schema as JsonSchemaTypeView;\n\n if (Array.isArray(objectSchema.type)) {\n return objectSchema.type.filter(\n (type: JsonSchemaPrimitiveType): type is JsonSchemaPrimitiveType =>\n isSetString(type)\n );\n }\n if (\n isSetString(objectSchema.type) &&\n objectSchema.type !== \"object\" &&\n objectSchema.type !== \"array\"\n ) {\n return [objectSchema.type];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,SAAgB,wBACd,QACA,UACY;CACZ,IAAI,CAAC,YAAY,CAACA,cAAY,MAAM,GAClC,OAAO;CAGT,MAAM,SAAqB,EAAE,GAAG,OAAO;CACvC,MAAM,gBAAgB;CACtB,KAAK,MAAM,OAAO,2BAA2B;EAC3C,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,UAAa,UAAU,MACnC,cAAc,OAAO;CAEzB;CAEA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,gBACd,QAC2B;CAC3B,IAAI,CAACA,cAAY,MAAM,GACrB,OAAO,CAAC;CAGV,MAAM,eAAe;CAErB,IAAI,MAAM,QAAQ,aAAa,IAAI,GACjC,OAAO,aAAa,KAAK,QACtB,SACC,YAAY,IAAI,CACpB;CAEF,IACE,YAAY,aAAa,IAAI,KAC7B,aAAa,SAAS,YACtB,aAAa,SAAS,SAEtB,OAAO,CAAC,aAAa,IAAI;CAE3B,OAAO,CAAC;AACV;;;;;;;AAQA,SAAgB,qBACd,QACqC;CACrC,IAAI,CAACA,cAAY,MAAM,GACrB;CAGF,OAAO,gBAAgB,MAAM,EAAE,MAAK,SAAQ,SAAS,MAAM;AAC7D"}
@@ -16,7 +16,7 @@ declare function getCacheDirectory(context: Context): string;
16
16
  * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.
17
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
18
  */
19
- declare function getCacheFilePath<T = unknown>(context: Context, input: SchemaInput<T>): string;
19
+ declare function getCacheFilePath(context: Context, input: SchemaInput): string;
20
20
  /**
21
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
22
  *
@@ -24,7 +24,7 @@ declare function getCacheFilePath<T = unknown>(context: Context, input: SchemaIn
24
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
25
  * @throws Will throw an error if the provided input is not a valid schema.
26
26
  */
27
- declare function writeSchema<T = unknown>(context: Context, schema: Schema<T>): Promise<void>;
27
+ declare function writeSchema(context: Context, schema: Schema): Promise<void>;
28
28
  /**
29
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
30
  *
@@ -32,7 +32,7 @@ declare function writeSchema<T = unknown>(context: Context, schema: Schema<T>):
32
32
  * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
33
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
34
  */
35
- declare function readSchemaSafe<T = unknown>(context: Context, input: SchemaInput<T>): Promise<Schema<T> | undefined>;
35
+ declare function readSchemaSafe(context: Context, input: SchemaInput): Promise<Schema | undefined>;
36
36
  /**
37
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
38
  *
@@ -41,7 +41,7 @@ declare function readSchemaSafe<T = unknown>(context: Context, input: SchemaInpu
41
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
42
  * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.
43
43
  */
44
- declare function readSchema<T = unknown>(context: Context, input: SchemaInput<T>): Promise<Schema<T>>;
44
+ declare function readSchema(context: Context, input: SchemaInput): Promise<Schema>;
45
45
  //#endregion
46
46
  export { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
47
47
  //# sourceMappingURL=persistence.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.d.cts","names":[],"sources":["../src/persistence.ts"],"mappings":";;;;;;AA8BA;;;;iBAAgB,iBAAA,CAAkB,OAAgB,EAAP,OAAO;AAWlD;;;;;;;AAAA,iBAAgB,gBAAA,aAAA,CACd,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;;;;;iBAeC,WAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAE,OAAA;AAFnB;;;;;;;AAAA,iBAuBsB,cAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,OAAA,CAAQ,MAAA,CAAO,CAAA;;;;;;;;;iBAsBI,UAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
1
+ {"version":3,"file":"persistence.d.cts","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,CAAY,OAAA,EAAS,OAAA,EAAS,MAAA,EAAQ,MAAA,GAAM,OAAA;;;;;;;;iBAoB5C,cAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA;AAvBuD;AAoBlE;;;;;;;AApBkE,iBA6C5C,UAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA"}
@@ -16,7 +16,7 @@ declare function getCacheDirectory(context: Context): string;
16
16
  * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.
17
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
18
  */
19
- declare function getCacheFilePath<T = unknown>(context: Context, input: SchemaInput<T>): string;
19
+ declare function getCacheFilePath(context: Context, input: SchemaInput): string;
20
20
  /**
21
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
22
  *
@@ -24,7 +24,7 @@ declare function getCacheFilePath<T = unknown>(context: Context, input: SchemaIn
24
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
25
  * @throws Will throw an error if the provided input is not a valid schema.
26
26
  */
27
- declare function writeSchema<T = unknown>(context: Context, schema: Schema<T>): Promise<void>;
27
+ declare function writeSchema(context: Context, schema: Schema): Promise<void>;
28
28
  /**
29
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
30
  *
@@ -32,7 +32,7 @@ declare function writeSchema<T = unknown>(context: Context, schema: Schema<T>):
32
32
  * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.
33
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
34
  */
35
- declare function readSchemaSafe<T = unknown>(context: Context, input: SchemaInput<T>): Promise<Schema<T> | undefined>;
35
+ declare function readSchemaSafe(context: Context, input: SchemaInput): Promise<Schema | undefined>;
36
36
  /**
37
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
38
  *
@@ -41,7 +41,7 @@ declare function readSchemaSafe<T = unknown>(context: Context, input: SchemaInpu
41
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
42
  * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.
43
43
  */
44
- declare function readSchema<T = unknown>(context: Context, input: SchemaInput<T>): Promise<Schema<T>>;
44
+ declare function readSchema(context: Context, input: SchemaInput): Promise<Schema>;
45
45
  //#endregion
46
46
  export { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
47
47
  //# sourceMappingURL=persistence.d.mts.map
@@ -1 +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,aAAA,CACd,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;;;;;iBAeC,WAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAE,OAAA;AAFnB;;;;;;;AAAA,iBAuBsB,cAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,OAAA,CAAQ,MAAA,CAAO,CAAA;;;;;;;;;iBAsBI,UAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
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,CAAY,OAAA,EAAS,OAAA,EAAS,MAAA,EAAQ,MAAA,GAAM,OAAA;;;;;;;;iBAoB5C,cAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA;AAvBuD;AAoBlE;;;;;;;AApBkE,iBA6C5C,UAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,GACN,OAAA,CAAQ,MAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.mjs","names":[],"sources":["../src/persistence.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Context } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { extractHash, extractVariant } from \"./extract\";\nimport { isSchema } from \"./type-checks\";\nimport { Schema, SchemaInput } from \"./types\";\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory(context: Context): string {\n return joinPaths(context.cachePath, \"schemas\");\n}\n\n/**\n * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).\n *\n * @param context - The context object providing access to the cache path.\n * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.\n * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.\n */\nexport function getCacheFilePath<T = unknown>(\n context: Context,\n input: SchemaInput<T>\n): 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<T = unknown>(\n context: Context,\n schema: Schema<T>\n) {\n if (!isSchema<T>(schema)) {\n throw new Error(\n `The provided input is not a valid schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, schema),\n JSON.stringify(schema.schema)\n );\n}\n\n/**\n * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the cache path provided in the context and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.\n */\nexport async function readSchemaSafe<T = unknown>(\n context: Context,\n input: SchemaInput<T>\n): Promise<Schema<T> | 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<T = unknown>(\n context: Context,\n input: SchemaInput<T>\n): Promise<Schema<T>> {\n const schema = await readSchemaSafe<T>(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,iBACd,SACA,OACQ;CAER,MAAM,OAAO,YADG,eAAe,KACA,GAAG,KAAK;CAEvC,OAAO,UAAU,kBAAkB,OAAO,GAAG,GAAG,KAAK,MAAM;AAC7D;;;;;;;;AASA,eAAsB,YACpB,SACA,QACA;CACA,IAAI,CAAC,SAAY,MAAM,GACrB,MAAM,IAAI,MACR,4LACF;CAGF,MAAM,QAAQ,GAAG,MACf,iBAAiB,SAAS,MAAM,GAChC,KAAK,UAAU,OAAO,MAAM,CAC9B;AACF;;;;;;;;AASA,eAAsB,eACpB,SACA,OACgC;CAChC,MAAM,gBAAgB,iBAAiB,SAAS,KAAK;CACrD,IAAI,CAAE,MAAM,QAAQ,GAAG,OAAO,aAAa,GACzC;CAGF,MAAM,OAAO,MAAM,QAAQ,GAAG,KAAK,aAAa;CAChD,IAAI,CAAC,MACH;CAGF,OAAO,KAAK,MAAM,IAAI;AACxB;;;;;;;;;AAUA,eAAsB,WACpB,SACA,OACoB;CACpB,MAAM,SAAS,MAAM,eAAkB,SAAS,KAAK;CACrD,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
+ {"version":3,"file":"persistence.mjs","names":[],"sources":["../src/persistence.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Context } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { extractHash, extractVariant } from \"./extract\";\nimport { isSchema } from \"./type-checks\";\nimport { Schema, SchemaInput } from \"./types\";\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory(context: Context): string {\n return joinPaths(context.cachePath, \"schemas\");\n}\n\n/**\n * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).\n *\n * @param context - The context object providing access to the cache path.\n * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.\n * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.\n */\nexport function getCacheFilePath(context: Context, input: SchemaInput): string {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n return joinPaths(getCacheDirectory(context), `${hash}.json`);\n}\n\n/**\n * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.\n * @throws Will throw an error if the provided input is not a valid schema.\n */\nexport async function writeSchema(context: Context, schema: Schema) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, schema),\n JSON.stringify(schema.schema)\n );\n}\n\n/**\n * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the cache path provided in the context and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.\n */\nexport async function readSchemaSafe(\n context: Context,\n input: SchemaInput\n): Promise<Schema | undefined> {\n const cacheFilePath = getCacheFilePath(context, input);\n if (!(await context.fs.exists(cacheFilePath))) {\n return undefined;\n }\n\n const data = await context.fs.read(cacheFilePath);\n if (!data) {\n return undefined;\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.\n * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.\n */\nexport async function readSchema(\n context: Context,\n input: SchemaInput\n): Promise<Schema> {\n const schema = await readSchemaSafe(context, input);\n if (!schema) {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n throw new Error(\n `The ${variant} schema with hash \"${\n hash\n }\" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`\n );\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,kBAAkB,SAA0B;CAC1D,OAAO,UAAU,QAAQ,WAAW,SAAS;AAC/C;;;;;;;;AASA,SAAgB,iBAAiB,SAAkB,OAA4B;CAE7E,MAAM,OAAO,YADG,eAAe,KACA,GAAG,KAAK;CAEvC,OAAO,UAAU,kBAAkB,OAAO,GAAG,GAAG,KAAK,MAAM;AAC7D;;;;;;;;AASA,eAAsB,YAAY,SAAkB,QAAgB;CAClE,IAAI,CAAC,SAAS,MAAM,GAClB,MAAM,IAAI,MACR,4LACF;CAGF,MAAM,QAAQ,GAAG,MACf,iBAAiB,SAAS,MAAM,GAChC,KAAK,UAAU,OAAO,MAAM,CAC9B;AACF;;;;;;;;AASA,eAAsB,eACpB,SACA,OAC6B;CAC7B,MAAM,gBAAgB,iBAAiB,SAAS,KAAK;CACrD,IAAI,CAAE,MAAM,QAAQ,GAAG,OAAO,aAAa,GACzC;CAGF,MAAM,OAAO,MAAM,QAAQ,GAAG,KAAK,aAAa;CAChD,IAAI,CAAC,MACH;CAGF,OAAO,KAAK,MAAM,IAAI;AACxB;;;;;;;;;AAUA,eAAsB,WACpB,SACA,OACiB;CACjB,MAAM,SAAS,MAAM,eAAe,SAAS,KAAK;CAClD,IAAI,CAAC,QAAQ;EACX,MAAM,UAAU,eAAe,KAAK;EACpC,MAAM,OAAO,YAAY,SAAS,KAAK;EAEvC,MAAM,IAAI,MACR,OAAO,QAAQ,qBACb,KACD,+OACH;CACF;CAEA,OAAO;AACT"}
@@ -1,5 +1,6 @@
1
1
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
2
  const require_type_checks = require('./type-checks.cjs');
3
+ const require_codegen = require('./codegen.cjs');
3
4
  let defu = require("defu");
4
5
  defu = require_runtime.__toESM(defu, 1);
5
6
  let _stryke_type_checks = require("@stryke/type-checks");
@@ -66,20 +67,25 @@ function numberBrandToJsonSchema(brand) {
66
67
  }
67
68
  }
68
69
  function withReflectionTags(reflection, schema) {
69
- if (!(0, _stryke_type_checks.isSetObject)(reflection?.tags)) return schema;
70
+ if (!(0, _stryke_type_checks.isSetObject)(schema) || !(0, _stryke_type_checks.isSetObject)(reflection?.tags)) return schema;
71
+ const updatedSchema = { ...schema };
70
72
  const tags = reflection.tags;
71
- if ((0, _stryke_type_checks.isSetString)(tags.title)) schema.title = tags.title;
72
- if ((0, _stryke_type_checks.isSetArray)(tags.alias)) schema.alias = tags.alias;
73
- if (!(0, _stryke_type_checks.isUndefined)(tags.hidden)) schema.hidden = tags.hidden;
74
- if (!(0, _stryke_type_checks.isUndefined)(tags.ignore)) schema.ignore = tags.ignore;
75
- if (!(0, _stryke_type_checks.isUndefined)(tags.internal)) schema.internal = tags.internal;
76
- if (!(0, _stryke_type_checks.isUndefined)(tags.runtime)) schema.runtime = tags.runtime;
77
- if (!(0, _stryke_type_checks.isUndefined)(tags.readonly)) schema.readOnly = tags.readonly;
78
- return schema;
73
+ if ((0, _stryke_type_checks.isSetString)(tags.title)) updatedSchema.title = tags.title;
74
+ if ((0, _stryke_type_checks.isSetArray)(tags.alias)) updatedSchema.alias = tags.alias;
75
+ if (!(0, _stryke_type_checks.isUndefined)(tags.hidden)) updatedSchema.hidden = tags.hidden;
76
+ if (!(0, _stryke_type_checks.isUndefined)(tags.ignore)) updatedSchema.ignore = tags.ignore;
77
+ if (!(0, _stryke_type_checks.isUndefined)(tags.internal)) updatedSchema.internal = tags.internal;
78
+ if (!(0, _stryke_type_checks.isUndefined)(tags.runtime)) updatedSchema.runtime = tags.runtime;
79
+ if (!(0, _stryke_type_checks.isUndefined)(tags.readonly)) updatedSchema.readOnly = tags.readonly;
80
+ return updatedSchema;
79
81
  }
80
- function withNullable(schema, nullable) {
81
- if (!nullable) return schema;
82
- const types = Array.isArray(schema.type) ? [...schema.type] : schema.type ? [schema.type] : [];
82
+ function withNullable(schema) {
83
+ if (!(0, _stryke_type_checks.isSetObject)(schema)) return { anyOf: [schema, {
84
+ type: "null",
85
+ default: null
86
+ }] };
87
+ const rawType = schema.type;
88
+ const types = Array.isArray(rawType) ? [...rawType] : rawType ? [rawType] : [];
83
89
  if (!types.includes("null")) types.push("null");
84
90
  return {
85
91
  ...schema,
@@ -103,7 +109,7 @@ function reflectionToJsonSchemaInner(reflection) {
103
109
  case _powerlines_deepkit_vendor_type.ReflectionKind.null: return withReflectionTags(reflection, {
104
110
  type: "null",
105
111
  name: reflection.typeName,
106
- nullable: true
112
+ default: null
107
113
  });
108
114
  case _powerlines_deepkit_vendor_type.ReflectionKind.string: return withReflectionTags(reflection, {
109
115
  type: "string",
@@ -117,8 +123,7 @@ function reflectionToJsonSchemaInner(reflection) {
117
123
  case _powerlines_deepkit_vendor_type.ReflectionKind.bigint: return withReflectionTags(reflection, {
118
124
  type: "integer",
119
125
  name: reflection.typeName,
120
- format: "int64",
121
- multipleOf: 1
126
+ format: "int64"
122
127
  });
123
128
  case _powerlines_deepkit_vendor_type.ReflectionKind.regexp: return withReflectionTags(reflection, {
124
129
  type: "string",
@@ -128,37 +133,42 @@ function reflectionToJsonSchemaInner(reflection) {
128
133
  });
129
134
  case _powerlines_deepkit_vendor_type.ReflectionKind.literal: {
130
135
  const { literal } = reflection;
131
- if (typeof literal === "string" || typeof literal === "number" || typeof literal === "boolean") return withReflectionTags(reflection, {
132
- type: typeof literal,
133
- name: reflection.typeName,
134
- const: literal
135
- });
136
- if (typeof literal === "bigint") return withReflectionTags(reflection, {
136
+ if ((0, _stryke_type_checks.isBigInt)(literal)) return withReflectionTags(reflection, {
137
137
  type: "integer",
138
138
  name: reflection.typeName,
139
139
  format: "int64",
140
- multipleOf: 1,
141
- const: String(literal)
140
+ const: literal
142
141
  });
143
- if (literal instanceof RegExp) return withReflectionTags(reflection, {
142
+ if ((0, _stryke_type_checks.isRegExp)(literal)) return withReflectionTags(reflection, {
144
143
  type: "string",
145
144
  name: reflection.typeName,
146
145
  format: "regex",
147
146
  const: literal.source
148
147
  });
149
- return withReflectionTags(reflection, { name: reflection.typeName });
148
+ return withReflectionTags(reflection, {
149
+ type: require_codegen.getJsonSchemaType(literal),
150
+ name: reflection.typeName,
151
+ const: literal
152
+ });
150
153
  }
151
154
  case _powerlines_deepkit_vendor_type.ReflectionKind.templateLiteral: return withReflectionTags(reflection, { type: "string" });
152
155
  case _powerlines_deepkit_vendor_type.ReflectionKind.enum: {
153
- const values = reflection.values.filter((value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean");
156
+ const values = reflection.values.filter((value) => (0, _stryke_type_checks.isString)(value) || (0, _stryke_type_checks.isInteger)(value) || (0, _stryke_type_checks.isBigInt)(value) || (0, _stryke_type_checks.isNumber)(value) || (0, _stryke_type_checks.isBoolean)(value) || (0, _stryke_type_checks.isNull)(value));
154
157
  if (values.length === 0) return withReflectionTags(reflection, {
155
158
  name: reflection.typeName,
156
- description: reflection.description
159
+ description: reflection.description,
160
+ enum: []
157
161
  });
158
162
  return withReflectionTags(reflection, {
163
+ type: values.every((value) => (0, _stryke_type_checks.isString)(value)) ? "string" : values.every((value) => (0, _stryke_type_checks.isInteger)(value) || (0, _stryke_type_checks.isBigInt)(value)) ? "integer" : values.every((value) => (0, _stryke_type_checks.isNumber)(value)) ? "number" : values.every((value) => (0, _stryke_type_checks.isBoolean)(value)) ? "boolean" : values.every((value) => (0, _stryke_type_checks.isNull)(value)) ? "null" : values.reduce((ret, value) => {
164
+ const type = require_codegen.getJsonSchemaType(value);
165
+ if (require_type_checks.isJsonSchemaPrimitiveType(type) && !ret.includes(type)) ret.push(type);
166
+ return ret;
167
+ }, []),
159
168
  name: reflection.typeName,
160
169
  description: reflection.description,
161
- enum: values
170
+ enum: values,
171
+ default: values.length === 1 ? values[0] : void 0
162
172
  });
163
173
  }
164
174
  case _powerlines_deepkit_vendor_type.ReflectionKind.array: {
@@ -174,50 +184,63 @@ function reflectionToJsonSchemaInner(reflection) {
174
184
  if (items.length <= 1) return withReflectionTags(reflection, {
175
185
  type: "array",
176
186
  name: reflection.typeName,
177
- items: items[0] ?? {}
187
+ items: items.length === 1 ? items[0] : {}
178
188
  });
179
189
  return withReflectionTags(reflection, {
180
190
  type: "array",
181
191
  name: reflection.typeName,
182
- items,
192
+ prefixItems: items,
183
193
  minItems: items.length,
184
194
  maxItems: items.length
185
195
  });
186
196
  }
187
197
  case _powerlines_deepkit_vendor_type.ReflectionKind.union: {
188
- const branches = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter(require_type_checks.isJsonSchema);
189
- const nullable = reflection.types.some((inner) => inner.kind === _powerlines_deepkit_vendor_type.ReflectionKind.null || inner.kind === _powerlines_deepkit_vendor_type.ReflectionKind.undefined);
190
- const nonNull = branches.filter((branch) => branch.type !== "null" && !require_type_checks.isNullOnlyJsonSchema(branch));
198
+ const branches = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter((branch) => branch !== void 0);
199
+ if (!reflection.types.some((inner) => inner.kind === _powerlines_deepkit_vendor_type.ReflectionKind.null || inner.kind === _powerlines_deepkit_vendor_type.ReflectionKind.undefined)) return withReflectionTags(reflection, {
200
+ name: reflection.typeName,
201
+ anyOf: branches
202
+ });
203
+ const nonNull = branches.filter((branch) => !require_type_checks.isNullOnlyJsonSchema(branch));
191
204
  if (nonNull.length === 0) return withReflectionTags(reflection, {
192
205
  type: "null",
193
- nullable: true
206
+ default: null
194
207
  });
195
- if (nonNull.length === 1) return withNullable(withReflectionTags(reflection, {
196
- name: reflection.typeName,
197
- ...nonNull[0]
198
- }), nullable);
199
- const enumValues = nonNull.map((branch) => branch.const).filter((value) => value !== void 0);
208
+ if (nonNull.length === 1) {
209
+ const first = nonNull[0];
210
+ if (!(0, _stryke_type_checks.isSetObject)(first)) return withNullable(withReflectionTags(reflection, {
211
+ name: reflection.typeName,
212
+ anyOf: [first]
213
+ }));
214
+ return withNullable(withReflectionTags(reflection, {
215
+ name: reflection.typeName,
216
+ ...first
217
+ }));
218
+ }
219
+ const enumValues = nonNull.map((branch) => (0, _stryke_type_checks.isSetObject)(branch) ? branch.const : void 0).filter((value) => value === null || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean");
200
220
  if (enumValues.length === nonNull.length) return withNullable(withReflectionTags(reflection, {
201
221
  name: reflection.typeName,
202
222
  enum: enumValues
203
- }), nullable);
223
+ }));
204
224
  const discriminator = tryReflectionDiscriminator(reflection.types);
205
- if (discriminator) return withNullable(withReflectionTags(reflection, {
225
+ if (discriminator && (0, _stryke_type_checks.isSetObject)(discriminator)) return withNullable(withReflectionTags(reflection, {
206
226
  name: reflection.typeName,
207
227
  ...discriminator
208
- }), nullable);
228
+ }));
209
229
  return withNullable(withReflectionTags(reflection, {
210
230
  name: reflection.typeName,
211
231
  anyOf: nonNull
212
- }), nullable);
232
+ }));
213
233
  }
214
234
  case _powerlines_deepkit_vendor_type.ReflectionKind.intersection: {
215
235
  const members = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter((item) => item !== void 0);
216
236
  if (members.length === 0) return;
217
- if (members.length === 1) return withReflectionTags(reflection, {
218
- name: reflection.typeName,
219
- ...members[0]
220
- });
237
+ if (members.length === 1) {
238
+ if (!(0, _stryke_type_checks.isSetObject)(members[0])) return members[0];
239
+ return withReflectionTags(reflection, {
240
+ name: reflection.typeName,
241
+ ...members[0]
242
+ });
243
+ }
221
244
  if (members.every(require_type_checks.isJsonSchemaObject)) return withReflectionTags(reflection, {
222
245
  name: reflection.typeName,
223
246
  ...mergeObjectSchemas(members)
@@ -375,7 +398,7 @@ function objectReflectionToJsonSchema(type) {
375
398
  let property = reflectionToJsonSchemaInner(propertyReflection.type);
376
399
  if (!property) continue;
377
400
  property = {
378
- ...property,
401
+ ...(0, _stryke_type_checks.isSetObject)(property) ? property : {},
379
402
  name: propertyReflection.getNameAsString(),
380
403
  description: propertyReflection.getDescription(),
381
404
  readOnly: propertyReflection.isReadonly(),
@@ -383,13 +406,12 @@ function objectReflectionToJsonSchema(type) {
383
406
  internal: propertyReflection.isInternal(),
384
407
  runtime: propertyReflection.isRuntime(),
385
408
  hidden: propertyReflection.isHidden(),
386
- visibility: propertyReflection.isPublic() ? "public" : propertyReflection.isProtected() ? "protected" : propertyReflection.isPrivate() ? "private" : void 0,
387
409
  ...propertyReflection.hasDefault() ? { default: propertyReflection.getDefaultValue() } : {},
388
410
  ...(0, _stryke_type_checks.isSetArray)(propertyReflection.getGroups()) ? { tags: propertyReflection.getGroups() } : {},
389
411
  ...(0, _stryke_type_checks.isSetArray)(propertyReflection.getAlias()) ? { alias: propertyReflection.getAlias() } : {},
390
412
  ...(0, _stryke_type_checks.isSetString)(propertyReflection.getTitle()) ? { title: propertyReflection.getTitle() } : {}
391
413
  };
392
- if (propertyReflection.isNullable()) property = withNullable(property, true);
414
+ if (propertyReflection.isNullable()) property = withNullable(property);
393
415
  schema.properties ??= {};
394
416
  schema.properties[propertyReflection.name] = property;
395
417
  if (!propertyReflection.isOptional()) {
@@ -5,7 +5,7 @@ import { Type } from "@powerlines/deepkit/vendor/type";
5
5
  /**
6
6
  * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.
7
7
  */
8
- declare function reflectionToJsonSchema<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
8
+ declare function reflectionToJsonSchema(reflection: Type): JsonSchema | undefined;
9
9
  //#endregion
10
10
  export { reflectionToJsonSchema };
11
11
  //# sourceMappingURL=reflection.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.d.cts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AAsJA;iBAAgB,sBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA"}
1
+ {"version":3,"file":"reflection.d.cts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AAgKA;iBAAgB,sBAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAU"}
@@ -5,7 +5,7 @@ import { Type } from "@powerlines/deepkit/vendor/type";
5
5
  /**
6
6
  * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.
7
7
  */
8
- declare function reflectionToJsonSchema<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
8
+ declare function reflectionToJsonSchema(reflection: Type): JsonSchema | undefined;
9
9
  //#endregion
10
10
  export { reflectionToJsonSchema };
11
11
  //# sourceMappingURL=reflection.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AAsJA;iBAAgB,sBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA"}
1
+ {"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;;AAgKA;iBAAgB,sBAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAU"}