@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,306 @@
1
+ import { getPrimarySchemaType } from "./metadata.mjs";
2
+ import { isJsonSchema, isJsonSchemaObject } from "./type-checks.mjs";
3
+ import { getPropertiesList, isSchemaNullable, merge } from "./helpers.mjs";
4
+ import { getValidator } from "./validate.mjs";
5
+ import { toBool } from "@stryke/convert/to-bool";
6
+ import { isInteger, isObject, isString } from "@stryke/type-checks";
7
+ import { isBoolean as isBoolean$1 } from "@stryke/type-checks/is-boolean";
8
+ import { isNull as isNull$1 } from "@stryke/type-checks/is-null";
9
+ import { isNumber as isNumber$1 } from "@stryke/type-checks/is-number";
10
+ import { isSetString as isSetString$1 } from "@stryke/type-checks/is-set-string";
11
+ import { isUndefined as isUndefined$1 } from "@stryke/type-checks/is-undefined";
12
+ import standaloneCode from "ajv/dist/standalone/index.js";
13
+
14
+ //#region src/codegen.ts
15
+ /**
16
+ * Stringifies a value for generated TypeScript code.
17
+ */
18
+ function stringifyValue(value, type) {
19
+ return isUndefined$1(value) ? "undefined" : isNull$1(value) ? "null" : type === "boolean" || isBoolean$1(value) ? String(toBool(value)) : type === "number" || isNumber$1(value) ? Number.parseFloat(String(value)).toLocaleString(void 0, { maximumFractionDigits: 20 }) : type === "integer" ? Number.parseInt(String(value)).toLocaleString() : type === "string" || type === "object" || type === "array" ? JSON.stringify(value) : String(value);
20
+ }
21
+ /**
22
+ * Stringifies a JSON Schema fragment into a TypeScript-like type string.
23
+ */
24
+ function stringifyType(schema) {
25
+ if (!schema) return "unknown";
26
+ if (typeof schema === "boolean") return schema ? "unknown" : "never";
27
+ if (isJsonSchemaObject(schema) && isSetString$1(schema.name)) return schema.name;
28
+ const objectSchema = schema;
29
+ if (isSetString$1(objectSchema.$ref)) return /^#\/(?:definitions|\$defs)\/(.+)$/.exec(objectSchema.$ref)?.[1] ?? objectSchema.$ref;
30
+ const primaryType = getPrimarySchemaType(schema);
31
+ if (primaryType) {
32
+ if (primaryType === "integer" || primaryType === "number") return "number";
33
+ return primaryType;
34
+ }
35
+ if (objectSchema.type === "array" && Array.isArray(objectSchema.enum)) return objectSchema.enum.map((value) => JSON.stringify(value)).join(" | ");
36
+ if (objectSchema.const !== void 0) return JSON.stringify(objectSchema.const);
37
+ if (objectSchema.type === "array" || objectSchema.items) return `${stringifyType(Array.isArray(objectSchema.items) ? objectSchema.items[0] : objectSchema.items)}[]`;
38
+ if (objectSchema.type === "object" || objectSchema.properties || objectSchema.additionalProperties) {
39
+ if (isJsonSchema(objectSchema.additionalProperties)) return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;
40
+ if (isJsonSchemaObject(objectSchema)) {
41
+ const required = objectSchema.required ?? [];
42
+ return `{ ${getPropertiesList(objectSchema).map((property) => {
43
+ const suffix = !required.includes(property.name) || isSchemaNullable(property) ? `${!required.includes(property.name) ? "?" : ""}${isSchemaNullable(property) ? " | null" : ""}` : "";
44
+ return `${property.name}${suffix}: ${stringifyType(property)}`;
45
+ }).join(";\n")} }`;
46
+ }
47
+ }
48
+ if (objectSchema.oneOf || objectSchema.anyOf) return (objectSchema.oneOf ?? objectSchema.anyOf ?? []).map((branch) => stringifyType(branch)).join(" | ");
49
+ if (objectSchema.allOf) return "object";
50
+ return "unknown";
51
+ }
52
+ /**
53
+ * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.
54
+ *
55
+ * @param value - The value whose type is to be represented as a string.
56
+ * @returns A string representation of the value's type, which may be influenced by the provided JSON Schema primitive type hint. The function handles various JavaScript types and formats them accordingly, including special handling for `undefined`, `null`, booleans, numbers (with formatting), strings, objects, and arrays. If a specific type hint is provided, it will take precedence in determining the string representation of the value.
57
+ */
58
+ function getJsonSchemaType(value) {
59
+ return isNull$1(value) ? "null" : isBoolean$1(value) ? "boolean" : isInteger(value) ? "integer" : isNumber$1(value) ? "number" : isString(value) ? "string" : isObject(value) ? "object" : Array.isArray(value) ? "array" : void 0;
60
+ }
61
+ /**
62
+ * Resolves a local JSON Schema `$ref` (e.g. `#/$defs/Name`) to the referenced definition name.
63
+ */
64
+ function resolveLocalRefName(ref) {
65
+ return /^#\/(?:definitions|\$defs)\/(.+)$/.exec(ref)?.[1];
66
+ }
67
+ /**
68
+ * Converts an arbitrary definition name into a safe JavaScript identifier suffix.
69
+ */
70
+ function toParserIdentifier(name) {
71
+ const cleaned = name.replace(/[^\w$]/gu, "_");
72
+ return `parse_${/^\d/u.test(cleaned) ? `_${cleaned}` : cleaned}`;
73
+ }
74
+ /**
75
+ * Returns the list of JSON Schema `type` keyword values declared on a fragment,
76
+ * preserving `object` and `array` (which {@link readSchemaTypes} intentionally drops).
77
+ */
78
+ function readDeclaredTypes(schema) {
79
+ const type = schema.type;
80
+ if (Array.isArray(type)) return [...type];
81
+ return type ? [type] : [];
82
+ }
83
+ /**
84
+ * Generates a JavaScript expression that builds a path string for a child element.
85
+ */
86
+ function childPath(pathExpr, segment) {
87
+ return `${pathExpr} + ${JSON.stringify(segment)}`;
88
+ }
89
+ /**
90
+ * Generates standalone parser code for a JSON Schema.
91
+ *
92
+ * @remarks
93
+ * The generated `parse` function reads an arbitrary input value and converts it
94
+ * into the shape described by the schema. It walks the schema recursively to:
95
+ *
96
+ * - resolve local `$ref` pointers (`#/$defs/*` and `#/definitions/*`) into
97
+ * dedicated parser functions so recursive schemas are supported,
98
+ * - apply `default` values for object properties (and root/array values) that
99
+ * are missing from the input,
100
+ * - coerce primitive values to the declared type (for example `"42"` to `42`
101
+ * for an `integer` schema, or `1` to `true` for a `boolean` schema),
102
+ * - validate `const`, `enum`, `oneOf`/`anyOf` and `allOf` constraints, and
103
+ * - collect detailed, path-aware errors and throw a `ParserError` when the
104
+ * input cannot be converted into a valid value.
105
+ *
106
+ * @param schema - The JSON Schema to generate parser code for.
107
+ * @returns The generated standalone parser code as a string.
108
+ */
109
+ function generateParserCode(schema) {
110
+ const rootSchema = typeof schema === "boolean" ? schema : schema;
111
+ const definitions = typeof rootSchema === "boolean" ? {} : {
112
+ ...rootSchema.definitions,
113
+ ...rootSchema.$defs
114
+ };
115
+ /**
116
+ * Generates a JavaScript expression that parses `valueExpr` against `fragment`.
117
+ * The expression has access to an in-scope mutable `errors` array.
118
+ */
119
+ function generateExpression(fragment, valueExpr, pathExpr) {
120
+ if (typeof fragment === "boolean") return fragment ? valueExpr : `((value, path) => { errors.push({ path, message: "No value is allowed at this location" }); return value; })(${valueExpr}, ${pathExpr})`;
121
+ const view = fragment;
122
+ if (isSetString$1(view.$ref)) {
123
+ const refName = resolveLocalRefName(view.$ref);
124
+ if (refName && refName in definitions) return `${toParserIdentifier(refName)}(${valueExpr}, ${pathExpr}, errors)`;
125
+ return valueExpr;
126
+ }
127
+ return `((value, path) => {\n${generateBody(view)}\n})(${valueExpr}, ${pathExpr})`;
128
+ }
129
+ /**
130
+ * Generates the body statements (including a terminating `return`) for the
131
+ * arrow function produced by {@link generateExpression}.
132
+ */
133
+ function generateBody(view) {
134
+ const lines = [];
135
+ const nullable = isSchemaNullable(view);
136
+ if (view.default !== void 0) lines.push(`if (value === undefined) { return ${JSON.stringify(view.default)}; }`);
137
+ else lines.push(`if (value === undefined) { errors.push({ path, message: "A value is required" }); return value; }`);
138
+ if (nullable) lines.push(`if (value === null) { return null; }`);
139
+ if (view.const !== void 0) {
140
+ const constValue = JSON.stringify(view.const);
141
+ lines.push(`if (JSON.stringify(value) !== ${JSON.stringify(constValue)}) { errors.push({ path, message: "Expected the constant value " + ${JSON.stringify(constValue)} }); }`, `return ${constValue};`);
142
+ return lines.join("\n");
143
+ }
144
+ if (Array.isArray(view.enum)) {
145
+ const enumValues = JSON.stringify(view.enum);
146
+ lines.push(`if (!${enumValues}.some(allowed => JSON.stringify(allowed) === JSON.stringify(value))) { errors.push({ path, message: "Expected one of " + ${JSON.stringify(enumValues)} }); }`, `return value;`);
147
+ return lines.join("\n");
148
+ }
149
+ if (Array.isArray(view.oneOf) || Array.isArray(view.anyOf)) {
150
+ const branchFns = (view.oneOf ?? view.anyOf ?? []).map((branch) => `(value, path, errors) => (${generateExpression(branch, "value", "path")})`).join(",\n");
151
+ lines.push(`const branches = [\n${branchFns}\n];`, `for (const branch of branches) {`, ` const branchErrors = [];`, ` const branchResult = branch(value, path, branchErrors);`, ` if (branchErrors.length === 0) { return branchResult; }`, `}`, `errors.push({ path, message: "Value does not match any of the allowed schemas" });`, `return value;`);
152
+ return lines.join("\n");
153
+ }
154
+ if (Array.isArray(view.allOf)) {
155
+ const { allOf, ...rest } = view;
156
+ const merged = merge(rest, ...allOf);
157
+ lines.push(`return ${generateExpression(merged, "value", "path")};`);
158
+ return lines.join("\n");
159
+ }
160
+ const declaredTypes = readDeclaredTypes(view);
161
+ switch (getPrimarySchemaType(view) ?? declaredTypes.find((type) => type !== "null") ?? (view.properties ? "object" : view.items ? "array" : void 0)) {
162
+ case "object":
163
+ lines.push(generateObjectBody(view));
164
+ break;
165
+ case "array":
166
+ lines.push(generateArrayBody(view));
167
+ break;
168
+ case "string":
169
+ lines.push(`if (typeof value === "string") { return value; }`, `if (typeof value === "number" || typeof value === "boolean") { return String(value); }`, `errors.push({ path, message: "Expected a string value" });`, `return value;`);
170
+ break;
171
+ case "integer":
172
+ lines.push(`if (typeof value === "number" && Number.isInteger(value)) { return value; }`, `if (typeof value === "string" && value.trim() !== "" && Number.isInteger(Number(value))) { return Number(value); }`, `if (typeof value === "boolean") { return value ? 1 : 0; }`, `errors.push({ path, message: "Expected an integer value" });`, `return value;`);
173
+ break;
174
+ case "number":
175
+ lines.push(`if (typeof value === "number") { return value; }`, `if (typeof value === "string" && value.trim() !== "" && !Number.isNaN(Number(value))) { return Number(value); }`, `if (typeof value === "boolean") { return value ? 1 : 0; }`, `errors.push({ path, message: "Expected a number value" });`, `return value;`);
176
+ break;
177
+ case "boolean":
178
+ lines.push(`if (typeof value === "boolean") { return value; }`, `if (value === "true" || value === 1) { return true; }`, `if (value === "false" || value === 0) { return false; }`, `errors.push({ path, message: "Expected a boolean value" });`, `return value;`);
179
+ break;
180
+ case "null":
181
+ lines.push(`if (value === null) { return null; }`, `errors.push({ path, message: "Expected a null value" });`, `return value;`);
182
+ break;
183
+ case void 0:
184
+ default:
185
+ lines.push(`return value;`);
186
+ break;
187
+ }
188
+ return lines.join("\n");
189
+ }
190
+ /**
191
+ * Generates the parsing statements for an `object` schema, applying property
192
+ * defaults and recursing into each declared property.
193
+ */
194
+ function generateObjectBody(view) {
195
+ const type = stringifyType(view);
196
+ const lines = [`if (typeof value !== "object" || value === null || Array.isArray(value)) { errors.push({ path, message: "Expected an object value" }); return value; }`, `const result = {}${type ? ` as ${type}` : ""};`];
197
+ const properties = isJsonSchemaObject(view) ? getPropertiesList(view) : [];
198
+ const propertyNames = /* @__PURE__ */ new Set();
199
+ for (const property of properties) {
200
+ const name = property.name;
201
+ propertyNames.add(name);
202
+ const accessor = `value[${JSON.stringify(name)}]`;
203
+ const propertyPath = childPath("path", `.${name}`);
204
+ const propertyExpression = generateExpression(property, accessor, propertyPath);
205
+ const missingBranch = property.default !== void 0 ? `result[${JSON.stringify(name)}] = ${JSON.stringify(property.default)};` : property.required ? `errors.push({ path: ${propertyPath}, message: "Required property is missing" });` : ``;
206
+ lines.push(`if (${accessor} !== undefined) {`, ` result[${JSON.stringify(name)}] = ${propertyExpression};`, `}${missingBranch ? ` else { ${missingBranch} }` : ``}`);
207
+ }
208
+ const additional = view.additionalProperties;
209
+ if (isJsonSchema(additional)) {
210
+ const additionalExpression = generateExpression(additional, `value[key]`, `path + "." + key`);
211
+ lines.push(`for (const key of Object.keys(value)) {`, ` if (${JSON.stringify([...propertyNames])}.includes(key)) { continue; }`, ` result[key] = ${additionalExpression};`, `}`);
212
+ } else if (additional !== false) lines.push(`for (const key of Object.keys(value)) {`, ` if (${JSON.stringify([...propertyNames])}.includes(key)) { continue; }`, ` result[key] = value[key];`, `}`);
213
+ lines.push(`return result;`);
214
+ return lines.join("\n");
215
+ }
216
+ /**
217
+ * Generates the parsing statements for an `array` schema, recursing into each
218
+ * item (supporting both list and tuple `items`/`prefixItems` forms).
219
+ */
220
+ function generateArrayBody(view) {
221
+ const lines = [`if (!Array.isArray(value)) { errors.push({ path, message: "Expected an array value" }); return value; }`];
222
+ const tupleItems = view.prefixItems ?? (Array.isArray(view.items) ? view.items : void 0);
223
+ if (tupleItems) {
224
+ const listItems = !Array.isArray(view.items) ? view.items : void 0;
225
+ const itemExpressions = tupleItems.map((item, index) => `index === ${index} ? (${generateExpression(item, "item", childPath("path", `[${index}]`))})`);
226
+ const fallbackExpression = listItems ? generateExpression(listItems, "item", `path + "[" + index + "]"`) : "item";
227
+ lines.push(`return value.map((item, index) => ${itemExpressions.join(" : ")}${itemExpressions.length > 0 ? " : " : ""}${fallbackExpression});`);
228
+ return lines.join("\n");
229
+ }
230
+ const itemExpression = generateExpression(view.items ?? true, "item", `path + "[" + index + "]"`);
231
+ lines.push(`return value.map((item, index) => ${itemExpression});`);
232
+ return lines.join("\n");
233
+ }
234
+ return `/**
235
+ * Error thrown when an input value cannot be parsed into the type described by the JSON Schema.
236
+ */
237
+ export class ParserError extends Error {
238
+ public override name = "ParserError";
239
+
240
+ public errors: { path: string; message: string }[];
241
+
242
+ public constructor(errors: { path: string; message: string }[]) {
243
+ super(
244
+ "Failed to parse the provided value against the JSON Schema:\\n" +
245
+ errors.map(error => " - " + error.path + ": " + error.message).join("\\n")
246
+ );
247
+
248
+ this.errors = errors;
249
+ }
250
+ }
251
+
252
+ ${Object.entries(definitions).map(([name, definition]) => `function ${toParserIdentifier(name)}(value, path, errors) {\n return ${generateExpression(definition, "value", "path")};\n}`).join("\n\n")}
253
+
254
+ /**
255
+ * Parses an input value into the type described by the JSON Schema.
256
+ *
257
+ * @remarks
258
+ * The parser applies default values for missing properties, coerces primitive values to the declared type, and throws a {@link ParserError} (containing a detailed list of validation errors) when the value cannot be converted into a valid result.
259
+ *
260
+ * @param value - The input value to parse.
261
+ * @returns The parsed value conforming to the schema.
262
+ */
263
+ export function parse(value: unknown)${schema.name ? `: ${stringifyType(schema)}` : ""} {
264
+ const errors: { path: string; message: string }[] = [];
265
+
266
+ const result = ${generateExpression(schema, "value", "\"$\"")};
267
+
268
+ if (errors.length > 0) {
269
+ throw new ParserError(errors);
270
+ }
271
+
272
+ return result;
273
+ }`;
274
+ }
275
+ /**
276
+ * Generates standalone JSON Schema validation code using Ajv.
277
+ *
278
+ * @remarks
279
+ * The generated code includes a validation function that can be used to validate data against the provided JSON Schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.
280
+ *
281
+ * @param schema - The JSON Schema to generate validation code for.
282
+ * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.
283
+ * @returns The generated standalone validation code as a string.
284
+ */
285
+ function generateValidationCode(schema, refsOrFuncts) {
286
+ return standaloneCode(getValidator(schema), refsOrFuncts);
287
+ }
288
+ /**
289
+ * Generates standalone JavaScript code for validating and parsing data according to a JSON Schema.
290
+ *
291
+ * @remarks
292
+ * The generated code includes:
293
+ * - Validation code generated by Ajv for the provided JSON Schema, which can be used to validate data against the schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.
294
+ * - Parsing code generated for the provided JSON Schema, which can be used to parse and validate data against the schema at runtime. The parsing function will apply default values specified in the schema if they are not present in the input data, throw an error if the input data does not conform to the schema (providing detailed information about the validation errors), and return the parsed data if it is valid according to the schema.
295
+ *
296
+ * @param schema - The JSON Schema to generate code for.
297
+ * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.
298
+ * @returns The generated standalone validation and parsing code as a string.
299
+ */
300
+ function generateCode(schema, refsOrFuncts) {
301
+ return `${generateValidationCode(schema, refsOrFuncts)}\n\n${generateParserCode(schema)}`;
302
+ }
303
+
304
+ //#endregion
305
+ export { generateCode, generateParserCode, generateValidationCode, getJsonSchemaType, stringifyType, stringifyValue };
306
+ //# sourceMappingURL=codegen.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.mjs","names":["isUndefined","isNull","isBoolean","isNumber","isSetString"],"sources":["../src/codegen.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 { toBool } from \"@stryke/convert/to-bool\";\nimport { isInteger, isObject, isString } from \"@stryke/type-checks\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList, isSchemaNullable, merge } from \"./helpers\";\nimport { getPrimarySchemaType } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaType } from \"./types\";\nimport { getValidator } from \"./validate\";\n\ninterface JsonSchemaObjectView {\n $ref?: string;\n type?: JsonSchemaType | readonly JsonSchemaType[];\n enum?: readonly unknown[];\n const?: unknown;\n default?: unknown;\n items?: JsonSchema | JsonSchema[];\n prefixItems?: JsonSchema[];\n properties?: Record<string, JsonSchema>;\n additionalProperties?: boolean | JsonSchema;\n required?: string[];\n oneOf?: JsonSchema[];\n anyOf?: JsonSchema[];\n allOf?: JsonSchema[];\n $defs?: Record<string, JsonSchema>;\n definitions?: Record<string, JsonSchema>;\n}\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaType | string\n): string {\n return isUndefined(value)\n ? \"undefined\"\n : isNull(value)\n ? \"null\"\n : type === \"boolean\" || isBoolean(value)\n ? String(toBool(value))\n : type === \"number\" || isNumber(value)\n ? Number.parseFloat(String(value)).toLocaleString(undefined, {\n maximumFractionDigits: 20\n })\n : type === \"integer\"\n ? Number.parseInt(String(value)).toLocaleString()\n : type === \"string\" || type === \"object\" || type === \"array\"\n ? JSON.stringify(value)\n : String(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType(schema?: JsonSchema): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (typeof schema === \"boolean\") {\n return schema ? \"unknown\" : \"never\";\n }\n\n if (isJsonSchemaObject(schema) && isSetString(schema.name)) {\n return schema.name;\n }\n\n const objectSchema = schema as JsonSchemaObjectView;\n\n if (isSetString(objectSchema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(objectSchema.$ref);\n\n return match?.[1] ?? objectSchema.$ref;\n }\n\n const primaryType = getPrimarySchemaType(schema);\n if (primaryType) {\n if (primaryType === \"integer\" || primaryType === \"number\") {\n return \"number\";\n }\n\n return primaryType;\n }\n\n if (objectSchema.type === \"array\" && Array.isArray(objectSchema.enum)) {\n const enumValues = objectSchema.enum as readonly unknown[];\n\n return enumValues\n .map((value: unknown) => JSON.stringify(value))\n .join(\" | \");\n }\n\n if (objectSchema.const !== undefined) {\n return JSON.stringify(objectSchema.const);\n }\n\n if (objectSchema.type === \"array\" || objectSchema.items) {\n const items = Array.isArray(objectSchema.items)\n ? objectSchema.items[0]\n : objectSchema.items;\n\n return `${stringifyType(items)}[]`;\n }\n\n if (\n objectSchema.type === \"object\" ||\n objectSchema.properties ||\n objectSchema.additionalProperties\n ) {\n if (isJsonSchema(objectSchema.additionalProperties)) {\n return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(objectSchema)) {\n const required = objectSchema.required ?? [];\n\n return `{ ${getPropertiesList(objectSchema)\n .map(property => {\n const suffix =\n !required.includes(property.name) || isSchemaNullable(property)\n ? `${!required.includes(property.name) ? \"?\" : \"\"}${isSchemaNullable(property) ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.name}${suffix}: ${stringifyType(property)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (objectSchema.oneOf || objectSchema.anyOf) {\n return (objectSchema.oneOf ?? objectSchema.anyOf ?? [])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (objectSchema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.\n *\n * @param value - The value whose type is to be represented as a string.\n * @returns A string representation of the value's type, which may be influenced by the provided JSON Schema primitive type hint. The function handles various JavaScript types and formats them accordingly, including special handling for `undefined`, `null`, booleans, numbers (with formatting), strings, objects, and arrays. If a specific type hint is provided, it will take precedence in determining the string representation of the value.\n */\nexport function getJsonSchemaType(value?: unknown): JsonSchemaType | undefined {\n return isNull(value)\n ? \"null\"\n : isBoolean(value)\n ? \"boolean\"\n : isInteger(value)\n ? \"integer\"\n : isNumber(value)\n ? \"number\"\n : isString(value)\n ? \"string\"\n : isObject(value)\n ? \"object\"\n : Array.isArray(value)\n ? \"array\"\n : undefined;\n}\n\n/**\n * Resolves a local JSON Schema `$ref` (e.g. `#/$defs/Name`) to the referenced definition name.\n */\nfunction resolveLocalRefName(ref: string): string | undefined {\n return /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(ref)?.[1];\n}\n\n/**\n * Converts an arbitrary definition name into a safe JavaScript identifier suffix.\n */\nfunction toParserIdentifier(name: string): string {\n const cleaned = name.replace(/[^\\w$]/gu, \"_\");\n\n return `parse_${/^\\d/u.test(cleaned) ? `_${cleaned}` : cleaned}`;\n}\n\n/**\n * Returns the list of JSON Schema `type` keyword values declared on a fragment,\n * preserving `object` and `array` (which {@link readSchemaTypes} intentionally drops).\n */\nfunction readDeclaredTypes(schema: JsonSchemaObjectView): JsonSchemaType[] {\n const type = schema.type;\n if (Array.isArray(type)) {\n return [...type];\n }\n\n return type ? [type as JsonSchemaType] : [];\n}\n\n/**\n * Generates a JavaScript expression that builds a path string for a child element.\n */\nfunction childPath(pathExpr: string, segment: string): string {\n return `${pathExpr} + ${JSON.stringify(segment)}`;\n}\n\n/**\n * Generates standalone parser code for a JSON Schema.\n *\n * @remarks\n * The generated `parse` function reads an arbitrary input value and converts it\n * into the shape described by the schema. It walks the schema recursively to:\n *\n * - resolve local `$ref` pointers (`#/$defs/*` and `#/definitions/*`) into\n * dedicated parser functions so recursive schemas are supported,\n * - apply `default` values for object properties (and root/array values) that\n * are missing from the input,\n * - coerce primitive values to the declared type (for example `\"42\"` to `42`\n * for an `integer` schema, or `1` to `true` for a `boolean` schema),\n * - validate `const`, `enum`, `oneOf`/`anyOf` and `allOf` constraints, and\n * - collect detailed, path-aware errors and throw a `ParserError` when the\n * input cannot be converted into a valid value.\n *\n * @param schema - The JSON Schema to generate parser code for.\n * @returns The generated standalone parser code as a string.\n */\nexport function generateParserCode(schema: JsonSchema): string {\n const rootSchema =\n typeof schema === \"boolean\" ? schema : (schema as JsonSchemaObjectView);\n\n const definitions: Record<string, JsonSchema> =\n typeof rootSchema === \"boolean\"\n ? {}\n : { ...rootSchema.definitions, ...rootSchema.$defs };\n\n /**\n * Generates a JavaScript expression that parses `valueExpr` against `fragment`.\n * The expression has access to an in-scope mutable `errors` array.\n */\n function generateExpression(\n fragment: JsonSchema,\n valueExpr: string,\n pathExpr: string\n ): string {\n if (typeof fragment === \"boolean\") {\n return fragment\n ? valueExpr\n : `((value, path) => { errors.push({ path, message: \"No value is allowed at this location\" }); return value; })(${valueExpr}, ${pathExpr})`;\n }\n\n const view = fragment as JsonSchemaObjectView;\n\n if (isSetString(view.$ref)) {\n const refName = resolveLocalRefName(view.$ref);\n if (refName && refName in definitions) {\n return `${toParserIdentifier(refName)}(${valueExpr}, ${pathExpr}, errors)`;\n }\n\n // Unknown / external reference — pass the value through unchanged.\n return valueExpr;\n }\n\n return `((value, path) => {\\n${generateBody(view)}\\n})(${valueExpr}, ${pathExpr})`;\n }\n\n /**\n * Generates the body statements (including a terminating `return`) for the\n * arrow function produced by {@link generateExpression}.\n */\n function generateBody(view: JsonSchemaObjectView): string {\n const lines: string[] = [];\n const nullable = isSchemaNullable(view);\n\n if (view.default !== undefined) {\n lines.push(\n `if (value === undefined) { return ${JSON.stringify(view.default)}; }`\n );\n } else {\n lines.push(\n `if (value === undefined) { errors.push({ path, message: \"A value is required\" }); return value; }`\n );\n }\n\n if (nullable) {\n lines.push(`if (value === null) { return null; }`);\n }\n\n if (view.const !== undefined) {\n const constValue = JSON.stringify(view.const);\n lines.push(\n `if (JSON.stringify(value) !== ${JSON.stringify(constValue)}) { errors.push({ path, message: \"Expected the constant value \" + ${JSON.stringify(constValue)} }); }`,\n `return ${constValue};`\n );\n\n return lines.join(\"\\n\");\n }\n\n if (Array.isArray(view.enum)) {\n const enumValues = JSON.stringify(view.enum);\n lines.push(\n `if (!${enumValues}.some(allowed => JSON.stringify(allowed) === JSON.stringify(value))) { errors.push({ path, message: \"Expected one of \" + ${JSON.stringify(enumValues)} }); }`,\n `return value;`\n );\n\n return lines.join(\"\\n\");\n }\n\n if (Array.isArray(view.oneOf) || Array.isArray(view.anyOf)) {\n const branches = view.oneOf ?? view.anyOf ?? [];\n const branchFns = branches\n .map(\n branch =>\n `(value, path, errors) => (${generateExpression(branch, \"value\", \"path\")})`\n )\n .join(\",\\n\");\n\n lines.push(\n `const branches = [\\n${branchFns}\\n];`,\n `for (const branch of branches) {`,\n ` const branchErrors = [];`,\n ` const branchResult = branch(value, path, branchErrors);`,\n ` if (branchErrors.length === 0) { return branchResult; }`,\n `}`,\n `errors.push({ path, message: \"Value does not match any of the allowed schemas\" });`,\n `return value;`\n );\n\n return lines.join(\"\\n\");\n }\n\n if (Array.isArray(view.allOf)) {\n const { allOf, ...rest } = view;\n const merged = merge(rest, ...allOf);\n lines.push(`return ${generateExpression(merged, \"value\", \"path\")};`);\n\n return lines.join(\"\\n\");\n }\n\n const declaredTypes = readDeclaredTypes(view);\n const primaryType =\n getPrimarySchemaType(view) ??\n declaredTypes.find(type => type !== \"null\") ??\n (view.properties ? \"object\" : view.items ? \"array\" : undefined);\n\n switch (primaryType) {\n case \"object\":\n lines.push(generateObjectBody(view));\n break;\n case \"array\":\n lines.push(generateArrayBody(view));\n break;\n case \"string\":\n lines.push(\n `if (typeof value === \"string\") { return value; }`,\n `if (typeof value === \"number\" || typeof value === \"boolean\") { return String(value); }`,\n `errors.push({ path, message: \"Expected a string value\" });`,\n `return value;`\n );\n break;\n case \"integer\":\n lines.push(\n `if (typeof value === \"number\" && Number.isInteger(value)) { return value; }`,\n `if (typeof value === \"string\" && value.trim() !== \"\" && Number.isInteger(Number(value))) { return Number(value); }`,\n `if (typeof value === \"boolean\") { return value ? 1 : 0; }`,\n `errors.push({ path, message: \"Expected an integer value\" });`,\n `return value;`\n );\n break;\n case \"number\":\n lines.push(\n `if (typeof value === \"number\") { return value; }`,\n `if (typeof value === \"string\" && value.trim() !== \"\" && !Number.isNaN(Number(value))) { return Number(value); }`,\n `if (typeof value === \"boolean\") { return value ? 1 : 0; }`,\n `errors.push({ path, message: \"Expected a number value\" });`,\n `return value;`\n );\n break;\n case \"boolean\":\n lines.push(\n `if (typeof value === \"boolean\") { return value; }`,\n `if (value === \"true\" || value === 1) { return true; }`,\n `if (value === \"false\" || value === 0) { return false; }`,\n `errors.push({ path, message: \"Expected a boolean value\" });`,\n `return value;`\n );\n break;\n case \"null\":\n lines.push(\n `if (value === null) { return null; }`,\n `errors.push({ path, message: \"Expected a null value\" });`,\n `return value;`\n );\n break;\n case undefined:\n default:\n lines.push(`return value;`);\n break;\n }\n\n return lines.join(\"\\n\");\n }\n\n /**\n * Generates the parsing statements for an `object` schema, applying property\n * defaults and recursing into each declared property.\n */\n function generateObjectBody(view: JsonSchemaObjectView): string {\n const type = stringifyType(view);\n\n const lines: string[] = [\n `if (typeof value !== \"object\" || value === null || Array.isArray(value)) { errors.push({ path, message: \"Expected an object value\" }); return value; }`,\n `const result = {}${type ? ` as ${type}` : \"\"};`\n ];\n\n const properties = isJsonSchemaObject(view) ? getPropertiesList(view) : [];\n const propertyNames = new Set<string>();\n\n for (const property of properties) {\n const name = property.name;\n propertyNames.add(name);\n\n const accessor = `value[${JSON.stringify(name)}]`;\n const propertyPath = childPath(\"path\", `.${name}`);\n const propertyExpression = generateExpression(\n property,\n accessor,\n propertyPath\n );\n\n const missingBranch =\n property.default !== undefined\n ? `result[${JSON.stringify(name)}] = ${JSON.stringify(property.default)};`\n : property.required\n ? `errors.push({ path: ${propertyPath}, message: \"Required property is missing\" });`\n : ``;\n\n lines.push(\n `if (${accessor} !== undefined) {`,\n ` result[${JSON.stringify(name)}] = ${propertyExpression};`,\n `}${missingBranch ? ` else { ${missingBranch} }` : ``}`\n );\n }\n\n const additional = view.additionalProperties;\n if (isJsonSchema(additional)) {\n const additionalExpression = generateExpression(\n additional,\n `value[key]`,\n `path + \".\" + key`\n );\n\n lines.push(\n `for (const key of Object.keys(value)) {`,\n ` if (${JSON.stringify([...propertyNames])}.includes(key)) { continue; }`,\n ` result[key] = ${additionalExpression};`,\n `}`\n );\n } else if (additional !== false) {\n lines.push(\n `for (const key of Object.keys(value)) {`,\n ` if (${JSON.stringify([...propertyNames])}.includes(key)) { continue; }`,\n ` result[key] = value[key];`,\n `}`\n );\n }\n\n lines.push(`return result;`);\n\n return lines.join(\"\\n\");\n }\n\n /**\n * Generates the parsing statements for an `array` schema, recursing into each\n * item (supporting both list and tuple `items`/`prefixItems` forms).\n */\n function generateArrayBody(view: JsonSchemaObjectView): string {\n const lines: string[] = [\n `if (!Array.isArray(value)) { errors.push({ path, message: \"Expected an array value\" }); return value; }`\n ];\n\n const tupleItems =\n view.prefixItems ?? (Array.isArray(view.items) ? view.items : undefined);\n\n if (tupleItems) {\n const listItems = !Array.isArray(view.items) ? view.items : undefined;\n const itemExpressions = tupleItems.map(\n (item, index) =>\n `index === ${index} ? (${generateExpression(item, \"item\", childPath(\"path\", `[${index}]`))})`\n );\n const fallbackExpression = listItems\n ? generateExpression(listItems, \"item\", `path + \"[\" + index + \"]\"`)\n : \"item\";\n\n lines.push(\n `return value.map((item, index) => ${itemExpressions.join(\" : \")}${\n itemExpressions.length > 0 ? \" : \" : \"\"\n }${fallbackExpression});`\n );\n\n return lines.join(\"\\n\");\n }\n\n const itemSchema = (view.items ?? true) as JsonSchema;\n const itemExpression = generateExpression(\n itemSchema,\n \"item\",\n `path + \"[\" + index + \"]\"`\n );\n\n lines.push(`return value.map((item, index) => ${itemExpression});`);\n\n return lines.join(\"\\n\");\n }\n\n const parserFunctions = Object.entries(definitions).map(\n ([name, definition]) =>\n `function ${toParserIdentifier(name)}(value, path, errors) {\\n return ${generateExpression(\n definition,\n \"value\",\n \"path\"\n )};\\n}`\n );\n\n return `/**\n * Error thrown when an input value cannot be parsed into the type described by the JSON Schema.\n */\nexport class ParserError extends Error {\n public override name = \"ParserError\";\n\n public errors: { path: string; message: string }[];\n\n public constructor(errors: { path: string; message: string }[]) {\n super(\n \"Failed to parse the provided value against the JSON Schema:\\\\n\" +\n errors.map(error => \" - \" + error.path + \": \" + error.message).join(\"\\\\n\")\n );\n\n this.errors = errors;\n }\n}\n\n${parserFunctions.join(\"\\n\\n\")}\n\n/**\n * Parses an input value into the type described by the JSON Schema.\n *\n * @remarks\n * The parser applies default values for missing properties, coerces primitive values to the declared type, and throws a {@link ParserError} (containing a detailed list of validation errors) when the value cannot be converted into a valid result.\n *\n * @param value - The input value to parse.\n * @returns The parsed value conforming to the schema.\n */\nexport function parse(value: unknown)${\n schema.name ? `: ${stringifyType(schema)}` : \"\"\n } {\n const errors: { path: string; message: string }[] = [];\n\n const result = ${generateExpression(schema, \"value\", '\"$\"')};\n\n if (errors.length > 0) {\n throw new ParserError(errors);\n }\n\n return result;\n}`;\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n *\n * @remarks\n * The generated code includes a validation function that can be used to validate data against the provided JSON Schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.\n *\n * @param schema - The JSON Schema to generate validation code for.\n * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.\n * @returns The generated standalone validation code as a string.\n */\nexport function generateValidationCode(\n schema: JsonSchema,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n return standaloneCode(getValidator(schema), refsOrFuncts);\n}\n\n/**\n * Generates standalone JavaScript code for validating and parsing data according to a JSON Schema.\n *\n * @remarks\n * The generated code includes:\n * - Validation code generated by Ajv for the provided JSON Schema, which can be used to validate data against the schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.\n * - Parsing code generated for the provided JSON Schema, which can be used to parse and validate data against the schema at runtime. The parsing function will apply default values specified in the schema if they are not present in the input data, throw an error if the input data does not conform to the schema (providing detailed information about the validation errors), and return the parsed data if it is valid according to the schema.\n *\n * @param schema - The JSON Schema to generate code for.\n * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.\n * @returns The generated standalone validation and parsing code as a string.\n */\nexport function generateCode(\n schema: JsonSchema,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n return `${generateValidationCode(\n schema,\n refsOrFuncts\n )}\\n\\n${generateParserCode(schema)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,SAAgB,eACd,OACA,MACQ;CACR,OAAOA,cAAY,KAAK,IACpB,cACAC,SAAO,KAAK,IACV,SACA,SAAS,aAAaC,YAAU,KAAK,IACnC,OAAO,OAAO,KAAK,CAAC,IACpB,SAAS,YAAYC,WAAS,KAAK,IACjC,OAAO,WAAW,OAAO,KAAK,CAAC,EAAE,eAAe,QAAW,EACzD,uBAAuB,GACzB,CAAC,IACD,SAAS,YACP,OAAO,SAAS,OAAO,KAAK,CAAC,EAAE,eAAe,IAC9C,SAAS,YAAY,SAAS,YAAY,SAAS,UACjD,KAAK,UAAU,KAAK,IACpB,OAAO,KAAK;AAC5B;;;;AAKA,SAAgB,cAAc,QAA6B;CACzD,IAAI,CAAC,QACH,OAAO;CAGT,IAAI,OAAO,WAAW,WACpB,OAAO,SAAS,YAA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AAM,KAAK,qCAAqC,eAAe,GAAG;EAElE,OAAO,MAAM,KAAK,IAAI;CACxB;CAWA,OAAO;;;;;;;;;;;;;;;;;;EATiB,OAAO,QAAQ,WAAW,EAAE,KACjD,CAAC,MAAM,gBACN,YAAY,mBAAmB,IAAI,EAAE,oCAAoC,mBACvE,YACA,SACA,MACF,EAAE,KAqBQ,EAAE,KAAK,MAAM,EAAE;;;;;;;;;;;uCAY3B,OAAO,OAAO,KAAK,cAAc,MAAM,MAAM,GAC9C;;;mBAGgB,mBAAmB,QAAQ,SAAS,OAAK,EAAE;;;;;;;;AAQ9D;;;;;;;;;;;AAYA,SAAgB,uBACd,QACA,cACA;CACA,OAAO,eAAe,aAAa,MAAM,GAAG,YAAY;AAC1D;;;;;;;;;;;;;AAcA,SAAgB,aACd,QACA,cACA;CACA,OAAO,GAAG,uBACR,QACA,YACF,EAAE,MAAM,mBAAmB,MAAM;AACnC"}
@@ -0,0 +1,61 @@
1
+
2
+ //#region src/constants.ts
3
+ const VALID_SOURCE_FILE_EXTENSIONS = [
4
+ "ts",
5
+ "cts",
6
+ "mts",
7
+ "tsx",
8
+ "js",
9
+ "cjs",
10
+ "mjs",
11
+ "jsx",
12
+ "json",
13
+ "jsonc",
14
+ "json5",
15
+ "yaml",
16
+ "yml",
17
+ "toml"
18
+ ];
19
+ const JsonSchemaTypeNames = {
20
+ STRING: "string",
21
+ NUMBER: "number",
22
+ INTEGER: "integer",
23
+ BOOLEAN: "boolean",
24
+ NULL: "null",
25
+ OBJECT: "object",
26
+ ARRAY: "array"
27
+ };
28
+ const JSON_SCHEMA_PRIMITIVE_TYPES = [
29
+ JsonSchemaTypeNames.STRING,
30
+ JsonSchemaTypeNames.NUMBER,
31
+ JsonSchemaTypeNames.INTEGER,
32
+ JsonSchemaTypeNames.BOOLEAN,
33
+ JsonSchemaTypeNames.NULL
34
+ ];
35
+ const JSON_SCHEMA_TYPES = [
36
+ ...JSON_SCHEMA_PRIMITIVE_TYPES,
37
+ JsonSchemaTypeNames.ARRAY,
38
+ JsonSchemaTypeNames.OBJECT
39
+ ];
40
+ const JSON_SCHEMA_METADATA_KEYS = [
41
+ "docs",
42
+ "deprecated",
43
+ "title",
44
+ "description",
45
+ "examples",
46
+ "hidden",
47
+ "ignore",
48
+ "internal",
49
+ "runtime",
50
+ "readOnly",
51
+ "writeOnly",
52
+ "alias",
53
+ "tags"
54
+ ];
55
+
56
+ //#endregion
57
+ exports.JSON_SCHEMA_METADATA_KEYS = JSON_SCHEMA_METADATA_KEYS;
58
+ exports.JSON_SCHEMA_PRIMITIVE_TYPES = JSON_SCHEMA_PRIMITIVE_TYPES;
59
+ exports.JSON_SCHEMA_TYPES = JSON_SCHEMA_TYPES;
60
+ exports.JsonSchemaTypeNames = JsonSchemaTypeNames;
61
+ exports.VALID_SOURCE_FILE_EXTENSIONS = VALID_SOURCE_FILE_EXTENSIONS;
@@ -0,0 +1,17 @@
1
+ //#region src/constants.d.ts
2
+ declare const VALID_SOURCE_FILE_EXTENSIONS: string[];
3
+ declare const JsonSchemaTypeNames: {
4
+ readonly STRING: "string";
5
+ readonly NUMBER: "number";
6
+ readonly INTEGER: "integer";
7
+ readonly BOOLEAN: "boolean";
8
+ readonly NULL: "null";
9
+ readonly OBJECT: "object";
10
+ readonly ARRAY: "array";
11
+ };
12
+ declare const JSON_SCHEMA_PRIMITIVE_TYPES: readonly ["string", "number", "integer", "boolean", "null"];
13
+ declare const JSON_SCHEMA_TYPES: readonly ["string", "number", "integer", "boolean", "null", "array", "object"];
14
+ declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
15
+ //#endregion
16
+ export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS };
17
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,4BAAA;AAAA,cAiBA,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA"}
@@ -0,0 +1,17 @@
1
+ //#region src/constants.d.ts
2
+ declare const VALID_SOURCE_FILE_EXTENSIONS: string[];
3
+ declare const JsonSchemaTypeNames: {
4
+ readonly STRING: "string";
5
+ readonly NUMBER: "number";
6
+ readonly INTEGER: "integer";
7
+ readonly BOOLEAN: "boolean";
8
+ readonly NULL: "null";
9
+ readonly OBJECT: "object";
10
+ readonly ARRAY: "array";
11
+ };
12
+ declare const JSON_SCHEMA_PRIMITIVE_TYPES: readonly ["string", "number", "integer", "boolean", "null"];
13
+ declare const JSON_SCHEMA_TYPES: readonly ["string", "number", "integer", "boolean", "null", "array", "object"];
14
+ declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
15
+ //#endregion
16
+ export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS };
17
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,4BAAA;AAAA,cAiBA,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA"}
@@ -0,0 +1,57 @@
1
+ //#region src/constants.ts
2
+ const VALID_SOURCE_FILE_EXTENSIONS = [
3
+ "ts",
4
+ "cts",
5
+ "mts",
6
+ "tsx",
7
+ "js",
8
+ "cjs",
9
+ "mjs",
10
+ "jsx",
11
+ "json",
12
+ "jsonc",
13
+ "json5",
14
+ "yaml",
15
+ "yml",
16
+ "toml"
17
+ ];
18
+ const JsonSchemaTypeNames = {
19
+ STRING: "string",
20
+ NUMBER: "number",
21
+ INTEGER: "integer",
22
+ BOOLEAN: "boolean",
23
+ NULL: "null",
24
+ OBJECT: "object",
25
+ ARRAY: "array"
26
+ };
27
+ const JSON_SCHEMA_PRIMITIVE_TYPES = [
28
+ JsonSchemaTypeNames.STRING,
29
+ JsonSchemaTypeNames.NUMBER,
30
+ JsonSchemaTypeNames.INTEGER,
31
+ JsonSchemaTypeNames.BOOLEAN,
32
+ JsonSchemaTypeNames.NULL
33
+ ];
34
+ const JSON_SCHEMA_TYPES = [
35
+ ...JSON_SCHEMA_PRIMITIVE_TYPES,
36
+ JsonSchemaTypeNames.ARRAY,
37
+ JsonSchemaTypeNames.OBJECT
38
+ ];
39
+ const JSON_SCHEMA_METADATA_KEYS = [
40
+ "docs",
41
+ "deprecated",
42
+ "title",
43
+ "description",
44
+ "examples",
45
+ "hidden",
46
+ "ignore",
47
+ "internal",
48
+ "runtime",
49
+ "readOnly",
50
+ "writeOnly",
51
+ "alias",
52
+ "tags"
53
+ ];
54
+
55
+ //#endregion
56
+ export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS };
57
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.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 { JsonSchemaMetadataKeywords } from \"./types\";\n\nexport const VALID_SOURCE_FILE_EXTENSIONS = [\n \"ts\",\n \"cts\",\n \"mts\",\n \"tsx\",\n \"js\",\n \"cjs\",\n \"mjs\",\n \"jsx\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"yaml\",\n \"yml\",\n \"toml\"\n] as const as string[];\n\nexport const JsonSchemaTypeNames = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_PRIMITIVE_TYPES = [\n JsonSchemaTypeNames.STRING,\n JsonSchemaTypeNames.NUMBER,\n JsonSchemaTypeNames.INTEGER,\n JsonSchemaTypeNames.BOOLEAN,\n JsonSchemaTypeNames.NULL\n] as const;\n\nexport const JSON_SCHEMA_TYPES = [\n ...JSON_SCHEMA_PRIMITIVE_TYPES,\n JsonSchemaTypeNames.ARRAY,\n JsonSchemaTypeNames.OBJECT\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"hidden\",\n \"ignore\",\n \"internal\",\n \"runtime\",\n \"readOnly\",\n \"writeOnly\",\n \"alias\",\n \"tags\"\n] satisfies ReadonlyArray<keyof JsonSchemaMetadataKeywords>;\n"],"mappings":";AAoBA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,sBAAsB;CACjC,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;AACT;AAEA,MAAa,8BAA8B;CACzC,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;AACtB;AAEA,MAAa,oBAAoB;CAC/B,GAAG;CACH,oBAAoB;CACpB,oBAAoB;AACtB;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}