@powerlines/schema 0.11.81 → 0.11.82

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 (86) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/bundle.cjs +49 -0
  3. package/dist/bundle.d.cts +21 -0
  4. package/dist/bundle.d.cts.map +1 -0
  5. package/dist/bundle.d.mts +21 -0
  6. package/dist/bundle.d.mts.map +1 -0
  7. package/dist/bundle.mjs +48 -0
  8. package/dist/bundle.mjs.map +1 -0
  9. package/dist/codegen.cjs +312 -0
  10. package/dist/codegen.d.cts +67 -0
  11. package/dist/codegen.d.cts.map +1 -0
  12. package/dist/codegen.d.mts +67 -0
  13. package/dist/codegen.d.mts.map +1 -0
  14. package/dist/codegen.mjs +306 -0
  15. package/dist/codegen.mjs.map +1 -0
  16. package/dist/constants.cjs +61 -0
  17. package/dist/constants.d.cts +17 -0
  18. package/dist/constants.d.cts.map +1 -0
  19. package/dist/constants.d.mts +17 -0
  20. package/dist/constants.d.mts.map +1 -0
  21. package/dist/constants.mjs +57 -0
  22. package/dist/constants.mjs.map +1 -0
  23. package/dist/extract.cjs +482 -0
  24. package/dist/extract.d.cts +125 -0
  25. package/dist/extract.d.cts.map +1 -0
  26. package/dist/extract.d.mts +125 -0
  27. package/dist/extract.d.mts.map +1 -0
  28. package/dist/extract.mjs +472 -0
  29. package/dist/extract.mjs.map +1 -0
  30. package/dist/helpers.cjs +241 -0
  31. package/dist/helpers.d.cts +121 -0
  32. package/dist/helpers.d.cts.map +1 -0
  33. package/dist/helpers.d.mts +121 -0
  34. package/dist/helpers.d.mts.map +1 -0
  35. package/dist/helpers.mjs +234 -0
  36. package/dist/helpers.mjs.map +1 -0
  37. package/dist/index.cjs +95 -2434
  38. package/dist/index.d.cts +11 -1892
  39. package/dist/index.d.cts.map +1 -1
  40. package/dist/index.d.mts +11 -1892
  41. package/dist/index.d.mts.map +1 -1
  42. package/dist/index.mjs +12 -2321
  43. package/dist/metadata.cjs +53 -0
  44. package/dist/metadata.d.cts +31 -0
  45. package/dist/metadata.d.cts.map +1 -0
  46. package/dist/metadata.d.mts +31 -0
  47. package/dist/metadata.d.mts.map +1 -0
  48. package/dist/metadata.mjs +52 -0
  49. package/dist/metadata.mjs.map +1 -0
  50. package/dist/persistence.cjs +74 -0
  51. package/dist/persistence.d.cts +47 -0
  52. package/dist/persistence.d.cts.map +1 -0
  53. package/dist/persistence.d.mts +47 -0
  54. package/dist/persistence.d.mts.map +1 -0
  55. package/dist/persistence.mjs +71 -0
  56. package/dist/persistence.mjs.map +1 -0
  57. package/dist/reflection.cjs +426 -0
  58. package/dist/reflection.d.cts +11 -0
  59. package/dist/reflection.d.cts.map +1 -0
  60. package/dist/reflection.d.mts +11 -0
  61. package/dist/reflection.d.mts.map +1 -0
  62. package/dist/reflection.mjs +425 -0
  63. package/dist/reflection.mjs.map +1 -0
  64. package/dist/resolve.cjs +105 -0
  65. package/dist/resolve.d.cts +36 -0
  66. package/dist/resolve.d.cts.map +1 -0
  67. package/dist/resolve.d.mts +36 -0
  68. package/dist/resolve.d.mts.map +1 -0
  69. package/dist/resolve.mjs +102 -0
  70. package/dist/resolve.mjs.map +1 -0
  71. package/dist/type-checks.cjs +633 -0
  72. package/dist/type-checks.d.cts +316 -0
  73. package/dist/type-checks.d.cts.map +1 -0
  74. package/dist/type-checks.d.mts +316 -0
  75. package/dist/type-checks.d.mts.map +1 -0
  76. package/dist/type-checks.mjs +594 -0
  77. package/dist/type-checks.mjs.map +1 -0
  78. package/dist/types.d.cts +1152 -0
  79. package/dist/types.d.cts.map +1 -0
  80. package/dist/types.d.mts +1152 -0
  81. package/dist/types.d.mts.map +1 -0
  82. package/dist/validate.cjs +27 -0
  83. package/dist/validate.mjs +25 -0
  84. package/dist/validate.mjs.map +1 -0
  85. package/package.json +6 -6
  86. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,53 @@
1
+ const require_constants = require('./constants.cjs');
2
+ let _stryke_type_checks = require("@stryke/type-checks");
3
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
4
+
5
+ //#region src/metadata.ts
6
+ /**
7
+ * Applies Powerlines schema metadata onto a JSON Schema fragment.
8
+ *
9
+ * @param schema - The JSON Schema fragment to apply metadata to.
10
+ * @param metadata - The Powerlines schema metadata to apply.
11
+ * @returns A new JSON Schema fragment with the metadata applied.
12
+ */
13
+ function applyJsonSchemaMetadata(schema, metadata) {
14
+ if (!metadata || !(0, _stryke_type_checks_is_set_object.isSetObject)(schema)) return schema;
15
+ const result = { ...schema };
16
+ const mutableResult = result;
17
+ for (const key of require_constants.JSON_SCHEMA_METADATA_KEYS) {
18
+ const value = metadata[key];
19
+ if (value !== void 0 && value !== null) mutableResult[key] = value;
20
+ }
21
+ return result;
22
+ }
23
+ /**
24
+ * Normalizes the JSON Schema `type` keyword to a string array.
25
+ *
26
+ * @remarks
27
+ * 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.
28
+ *
29
+ * @param schema - The JSON Schema fragment to read types from.
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.
31
+ */
32
+ function readSchemaTypes(schema) {
33
+ if (!(0, _stryke_type_checks_is_set_object.isSetObject)(schema)) return [];
34
+ const objectSchema = schema;
35
+ if (Array.isArray(objectSchema.type)) return objectSchema.type.filter((type) => (0, _stryke_type_checks.isSetString)(type));
36
+ if ((0, _stryke_type_checks.isSetString)(objectSchema.type) && objectSchema.type !== "object" && objectSchema.type !== "array") return [objectSchema.type];
37
+ return [];
38
+ }
39
+ /**
40
+ * Returns the primary non-null JSON Schema type name for a fragment.
41
+ *
42
+ * @param schema - The JSON Schema fragment to check.
43
+ * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
44
+ */
45
+ function getPrimarySchemaType(schema) {
46
+ if (!(0, _stryke_type_checks_is_set_object.isSetObject)(schema)) return;
47
+ return readSchemaTypes(schema).find((type) => type !== "null");
48
+ }
49
+
50
+ //#endregion
51
+ exports.applyJsonSchemaMetadata = applyJsonSchemaMetadata;
52
+ exports.getPrimarySchemaType = getPrimarySchemaType;
53
+ exports.readSchemaTypes = readSchemaTypes;
@@ -0,0 +1,31 @@
1
+ import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaPrimitiveType } from "./types.cjs";
2
+
3
+ //#region src/metadata.d.ts
4
+ /**
5
+ * Applies Powerlines schema metadata onto a JSON Schema fragment.
6
+ *
7
+ * @param schema - The JSON Schema fragment to apply metadata to.
8
+ * @param metadata - The Powerlines schema metadata to apply.
9
+ * @returns A new JSON Schema fragment with the metadata applied.
10
+ */
11
+ declare function applyJsonSchemaMetadata(schema: JsonSchema, metadata: JsonSchemaMetadataKeywords | undefined): JsonSchema;
12
+ /**
13
+ * Normalizes the JSON Schema `type` keyword to a string array.
14
+ *
15
+ * @remarks
16
+ * 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.
17
+ *
18
+ * @param schema - The JSON Schema fragment to read types from.
19
+ * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
20
+ */
21
+ declare function readSchemaTypes(schema?: JsonSchema): JsonSchemaPrimitiveType[];
22
+ /**
23
+ * Returns the primary non-null JSON Schema type name for a fragment.
24
+ *
25
+ * @param schema - The JSON Schema fragment to check.
26
+ * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
27
+ */
28
+ declare function getPrimarySchemaType(schema?: JsonSchema): JsonSchemaPrimitiveType | undefined;
29
+ //#endregion
30
+ export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
31
+ //# sourceMappingURL=metadata.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.cts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;AAuCA;;;;;iBAAgB,uBAAA,CACd,MAAA,EAAQ,UAAA,EACR,QAAA,EAAU,0BAAA,eACT,UAAA;;;;;;;;;AAAU;iBA0BG,eAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB;;;;;;;iBA6BV,oBAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB"}
@@ -0,0 +1,31 @@
1
+ import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaPrimitiveType } from "./types.mjs";
2
+
3
+ //#region src/metadata.d.ts
4
+ /**
5
+ * Applies Powerlines schema metadata onto a JSON Schema fragment.
6
+ *
7
+ * @param schema - The JSON Schema fragment to apply metadata to.
8
+ * @param metadata - The Powerlines schema metadata to apply.
9
+ * @returns A new JSON Schema fragment with the metadata applied.
10
+ */
11
+ declare function applyJsonSchemaMetadata(schema: JsonSchema, metadata: JsonSchemaMetadataKeywords | undefined): JsonSchema;
12
+ /**
13
+ * Normalizes the JSON Schema `type` keyword to a string array.
14
+ *
15
+ * @remarks
16
+ * 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.
17
+ *
18
+ * @param schema - The JSON Schema fragment to read types from.
19
+ * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
20
+ */
21
+ declare function readSchemaTypes(schema?: JsonSchema): JsonSchemaPrimitiveType[];
22
+ /**
23
+ * Returns the primary non-null JSON Schema type name for a fragment.
24
+ *
25
+ * @param schema - The JSON Schema fragment to check.
26
+ * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
27
+ */
28
+ declare function getPrimarySchemaType(schema?: JsonSchema): JsonSchemaPrimitiveType | undefined;
29
+ //#endregion
30
+ export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
31
+ //# sourceMappingURL=metadata.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;AAuCA;;;;;iBAAgB,uBAAA,CACd,MAAA,EAAQ,UAAA,EACR,QAAA,EAAU,0BAAA,eACT,UAAA;;;;;;;;;AAAU;iBA0BG,eAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB;;;;;;;iBA6BV,oBAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB"}
@@ -0,0 +1,52 @@
1
+ import { JSON_SCHEMA_METADATA_KEYS } from "./constants.mjs";
2
+ import { isSetString } from "@stryke/type-checks";
3
+ import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object";
4
+
5
+ //#region src/metadata.ts
6
+ /**
7
+ * Applies Powerlines schema metadata onto a JSON Schema fragment.
8
+ *
9
+ * @param schema - The JSON Schema fragment to apply metadata to.
10
+ * @param metadata - The Powerlines schema metadata to apply.
11
+ * @returns A new JSON Schema fragment with the metadata applied.
12
+ */
13
+ function applyJsonSchemaMetadata(schema, metadata) {
14
+ if (!metadata || !isSetObject$1(schema)) return schema;
15
+ const result = { ...schema };
16
+ const mutableResult = result;
17
+ for (const key of JSON_SCHEMA_METADATA_KEYS) {
18
+ const value = metadata[key];
19
+ if (value !== void 0 && value !== null) mutableResult[key] = value;
20
+ }
21
+ return result;
22
+ }
23
+ /**
24
+ * Normalizes the JSON Schema `type` keyword to a string array.
25
+ *
26
+ * @remarks
27
+ * 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.
28
+ *
29
+ * @param schema - The JSON Schema fragment to read types from.
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.
31
+ */
32
+ function readSchemaTypes(schema) {
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];
37
+ return [];
38
+ }
39
+ /**
40
+ * Returns the primary non-null JSON Schema type name for a fragment.
41
+ *
42
+ * @param schema - The JSON Schema fragment to check.
43
+ * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
44
+ */
45
+ function getPrimarySchemaType(schema) {
46
+ if (!isSetObject$1(schema)) return;
47
+ return readSchemaTypes(schema).find((type) => type !== "null");
48
+ }
49
+
50
+ //#endregion
51
+ export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
52
+ //# sourceMappingURL=metadata.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.mjs","names":["isSetObject"],"sources":["../src/metadata.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaMetadataKeywords,\n JsonSchemaPrimitiveType,\n JsonSchemaType\n} from \"./types\";\n\ninterface JsonSchemaTypeView {\n type?: JsonSchemaType | readonly JsonSchemaType[];\n}\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applyJsonSchemaMetadata(\n schema: JsonSchema,\n metadata: JsonSchemaMetadataKeywords | undefined\n): JsonSchema {\n if (!metadata || !isSetObject(schema)) {\n return schema;\n }\n\n const result: JsonSchema = { ...schema };\n const mutableResult = result as Record<string, unknown>;\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n mutableResult[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType[] {\n if (!isSetObject(schema)) {\n return [];\n }\n\n const objectSchema = schema as JsonSchemaTypeView;\n\n if (Array.isArray(objectSchema.type)) {\n return objectSchema.type.filter(\n (type: JsonSchemaPrimitiveType): type is JsonSchemaPrimitiveType =>\n isSetString(type)\n );\n }\n if (\n isSetString(objectSchema.type) &&\n objectSchema.type !== \"object\" &&\n objectSchema.type !== \"array\"\n ) {\n return [objectSchema.type];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n"],"mappings":";;;;;;;;;;;;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"}
@@ -0,0 +1,74 @@
1
+ const require_type_checks = require('./type-checks.cjs');
2
+ const require_extract = require('./extract.cjs');
3
+ let _stryke_path_join = require("@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 (0, _stryke_path_join.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 = require_extract.extractHash(require_extract.extractVariant(input), input);
24
+ return (0, _stryke_path_join.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 (!require_type_checks.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 JSON 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 = require_extract.extractVariant(input);
63
+ const hash = require_extract.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
+ exports.getCacheDirectory = getCacheDirectory;
71
+ exports.getCacheFilePath = getCacheFilePath;
72
+ exports.readSchema = readSchema;
73
+ exports.readSchemaSafe = readSchemaSafe;
74
+ exports.writeSchema = writeSchema;
@@ -0,0 +1,47 @@
1
+ import { Schema, SchemaInput } from "./types.cjs";
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(context: Context, schema: Schema): 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(context: Context, input: SchemaInput): Promise<Schema | 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(context: Context, input: SchemaInput): Promise<Schema>;
45
+ //#endregion
46
+ export { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema };
47
+ //# sourceMappingURL=persistence.d.cts.map
@@ -0,0 +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,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"}
@@ -0,0 +1,47 @@
1
+ import { Schema, SchemaInput } 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(context: Context, schema: Schema): 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(context: Context, input: SchemaInput): Promise<Schema | 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(context: Context, input: SchemaInput): Promise<Schema>;
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,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"}
@@ -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 JSON 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 } 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"}