@powerlines/schema 0.9.5 → 0.10.0

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 (45) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/bundle.cjs +48 -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 +46 -0
  8. package/dist/bundle.mjs.map +1 -0
  9. package/dist/extract.cjs +90 -1
  10. package/dist/extract.d.cts +37 -1
  11. package/dist/extract.d.cts.map +1 -1
  12. package/dist/extract.d.mts +37 -1
  13. package/dist/extract.d.mts.map +1 -1
  14. package/dist/extract.mjs +87 -3
  15. package/dist/extract.mjs.map +1 -1
  16. package/dist/index.cjs +15 -1
  17. package/dist/index.d.cts +7 -3
  18. package/dist/index.d.mts +7 -3
  19. package/dist/index.mjs +6 -2
  20. package/dist/is-schema-definition.cjs +18 -0
  21. package/dist/is-schema-definition.d.cts +13 -0
  22. package/dist/is-schema-definition.d.cts.map +1 -0
  23. package/dist/is-schema-definition.d.mts +13 -0
  24. package/dist/is-schema-definition.d.mts.map +1 -0
  25. package/dist/is-schema-definition.mjs +17 -0
  26. package/dist/is-schema-definition.mjs.map +1 -0
  27. package/dist/reflection.cjs +191 -0
  28. package/dist/reflection.d.cts +21 -0
  29. package/dist/reflection.d.cts.map +1 -0
  30. package/dist/reflection.d.mts +21 -0
  31. package/dist/reflection.d.mts.map +1 -0
  32. package/dist/reflection.mjs +189 -0
  33. package/dist/reflection.mjs.map +1 -0
  34. package/dist/resolve.cjs +84 -0
  35. package/dist/resolve.d.cts +36 -0
  36. package/dist/resolve.d.cts.map +1 -0
  37. package/dist/resolve.d.mts +36 -0
  38. package/dist/resolve.d.mts.map +1 -0
  39. package/dist/resolve.mjs +80 -0
  40. package/dist/resolve.mjs.map +1 -0
  41. package/dist/types.d.cts +31 -3
  42. package/dist/types.d.cts.map +1 -1
  43. package/dist/types.d.mts +31 -3
  44. package/dist/types.d.mts.map +1 -1
  45. package/package.json +28 -6
@@ -0,0 +1,13 @@
1
+ import { SchemaDefinition } from "./types.cjs";
2
+
3
+ //#region src/is-schema-definition.d.ts
4
+ /**
5
+ * Type guard to check if a given input is a `SchemaDefinition` object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid `SchemaDefinition`; otherwise, it returns `false`.
6
+ *
7
+ * @param input - The input to check for being a `SchemaDefinition`.
8
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
9
+ */
10
+ declare function isSchemaDefinition(input: unknown): input is SchemaDefinition;
11
+ //#endregion
12
+ export { isSchemaDefinition };
13
+ //# sourceMappingURL=is-schema-definition.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-schema-definition.d.cts","names":[],"sources":["../src/is-schema-definition.ts"],"mappings":";;;;;AA4BA;;;;iBAAgB,kBAAA,CAAmB,KAAA,YAAiB,KAAA,IAAS,gBAAA"}
@@ -0,0 +1,13 @@
1
+ import { SchemaDefinition } from "./types.mjs";
2
+
3
+ //#region src/is-schema-definition.d.ts
4
+ /**
5
+ * Type guard to check if a given input is a `SchemaDefinition` object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid `SchemaDefinition`; otherwise, it returns `false`.
6
+ *
7
+ * @param input - The input to check for being a `SchemaDefinition`.
8
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
9
+ */
10
+ declare function isSchemaDefinition(input: unknown): input is SchemaDefinition;
11
+ //#endregion
12
+ export { isSchemaDefinition };
13
+ //# sourceMappingURL=is-schema-definition.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-schema-definition.d.mts","names":[],"sources":["../src/is-schema-definition.ts"],"mappings":";;;;;AA4BA;;;;iBAAgB,kBAAA,CAAmB,KAAA,YAAiB,KAAA,IAAS,gBAAA"}
@@ -0,0 +1,17 @@
1
+ import { isSetObject } from "@stryke/type-checks";
2
+ import { isJsonSchema7ObjectType } from "@stryke/json/schema";
3
+
4
+ //#region src/is-schema-definition.ts
5
+ /**
6
+ * Type guard to check if a given input is a `SchemaDefinition` object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid `SchemaDefinition`; otherwise, it returns `false`.
7
+ *
8
+ * @param input - The input to check for being a `SchemaDefinition`.
9
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
10
+ */
11
+ function isSchemaDefinition(input) {
12
+ return isSetObject(input) && "schema" in input && isJsonSchema7ObjectType(input.schema) && "input" in input && isSetObject(input.input) && "variant" in input && (input.variant === "json-schema" || input.variant === "standard-schema" || input.variant === "zod3" || input.variant === "reflection");
13
+ }
14
+
15
+ //#endregion
16
+ export { isSchemaDefinition };
17
+ //# sourceMappingURL=is-schema-definition.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-schema-definition.mjs","names":[],"sources":["../src/is-schema-definition.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 { isJsonSchema7ObjectType } from \"@stryke/json/schema\";\nimport { isSetObject } from \"@stryke/type-checks\";\nimport { SchemaDefinition } from \"./types\";\n\n/**\n * Type guard to check if a given input is a `SchemaDefinition` object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid `SchemaDefinition`; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a `SchemaDefinition`.\n * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.\n */\nexport function isSchemaDefinition(input: unknown): input is SchemaDefinition {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJsonSchema7ObjectType(input.schema) &&\n \"input\" in input &&\n isSetObject(input.input) &&\n \"variant\" in input &&\n (input.variant === \"json-schema\" ||\n input.variant === \"standard-schema\" ||\n input.variant === \"zod3\" ||\n input.variant === \"reflection\")\n );\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,mBAAmB,OAA2C;AAC5E,QACE,YAAY,MAAM,IAClB,YAAY,SACZ,wBAAwB,MAAM,OAAO,IACrC,WAAW,SACX,YAAY,MAAM,MAAM,IACxB,aAAa,UACZ,MAAM,YAAY,iBACjB,MAAM,YAAY,qBAClB,MAAM,YAAY,UAClB,MAAM,YAAY"}
@@ -0,0 +1,191 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
4
+
5
+ //#region src/reflection.ts
6
+ /**
7
+ * Converts a Deepkit type reflection into a JSON Schema representation.
8
+ *
9
+ * @param reflection - The Deepkit type reflection to convert.
10
+ * @returns The corresponding JSON Schema representation, or `undefined` if the type cannot be represented.
11
+ */
12
+ function reflectionToJsonSchema(reflection) {
13
+ switch (reflection.kind) {
14
+ case _powerlines_deepkit_vendor_type.ReflectionKind.any:
15
+ case _powerlines_deepkit_vendor_type.ReflectionKind.unknown:
16
+ case _powerlines_deepkit_vendor_type.ReflectionKind.void:
17
+ case _powerlines_deepkit_vendor_type.ReflectionKind.object: return {};
18
+ case _powerlines_deepkit_vendor_type.ReflectionKind.never:
19
+ case _powerlines_deepkit_vendor_type.ReflectionKind.undefined: return { not: {} };
20
+ case _powerlines_deepkit_vendor_type.ReflectionKind.null: return { type: "null" };
21
+ case _powerlines_deepkit_vendor_type.ReflectionKind.string: return { type: "string" };
22
+ case _powerlines_deepkit_vendor_type.ReflectionKind.boolean: return { type: "boolean" };
23
+ case _powerlines_deepkit_vendor_type.ReflectionKind.number: {
24
+ const brand = reflection.brand;
25
+ return { type: brand !== void 0 && brand >= _powerlines_deepkit_vendor_type.TypeNumberBrand.integer && brand <= _powerlines_deepkit_vendor_type.TypeNumberBrand.uint32 ? "integer" : "number" };
26
+ }
27
+ case _powerlines_deepkit_vendor_type.ReflectionKind.bigint: return {
28
+ type: "integer",
29
+ format: "int64"
30
+ };
31
+ case _powerlines_deepkit_vendor_type.ReflectionKind.regexp: return { type: "string" };
32
+ case _powerlines_deepkit_vendor_type.ReflectionKind.literal: {
33
+ const { literal } = reflection;
34
+ if (typeof literal === "string") return {
35
+ type: "string",
36
+ const: literal
37
+ };
38
+ if (typeof literal === "number") return {
39
+ type: Number.isInteger(literal) ? "integer" : "number",
40
+ const: literal
41
+ };
42
+ if (typeof literal === "boolean") return {
43
+ type: "boolean",
44
+ const: literal
45
+ };
46
+ if (typeof literal === "bigint") return {
47
+ type: "integer",
48
+ format: "int64"
49
+ };
50
+ if (literal instanceof RegExp) return {
51
+ type: "string",
52
+ pattern: literal.source
53
+ };
54
+ return {};
55
+ }
56
+ case _powerlines_deepkit_vendor_type.ReflectionKind.templateLiteral: return { type: "string" };
57
+ case _powerlines_deepkit_vendor_type.ReflectionKind.enum: {
58
+ const values = reflection.values.filter((value) => typeof value === "string" || typeof value === "number");
59
+ const allStrings = values.every((value) => typeof value === "string");
60
+ const allNumbers = values.every((value) => typeof value === "number");
61
+ return {
62
+ type: allStrings ? "string" : allNumbers ? "number" : ["string", "number"],
63
+ enum: values
64
+ };
65
+ }
66
+ case _powerlines_deepkit_vendor_type.ReflectionKind.array: {
67
+ const items = reflectionToJsonSchema(reflection.type);
68
+ return items ? {
69
+ type: "array",
70
+ items
71
+ } : { type: "array" };
72
+ }
73
+ case _powerlines_deepkit_vendor_type.ReflectionKind.tuple: return {
74
+ type: "array",
75
+ items: reflection.types.map((member) => reflectionToJsonSchema(member.type)).filter((item) => item !== void 0),
76
+ minItems: reflection.types.filter((member) => !member.optional).length,
77
+ maxItems: reflection.types.length
78
+ };
79
+ case _powerlines_deepkit_vendor_type.ReflectionKind.union: {
80
+ const anyOf = reflection.types.map((inner) => reflectionToJsonSchema(inner)).filter((item) => item !== void 0);
81
+ if (anyOf.length === 0) return;
82
+ if (anyOf.length === 1) return anyOf[0];
83
+ return { anyOf };
84
+ }
85
+ case _powerlines_deepkit_vendor_type.ReflectionKind.intersection: {
86
+ const allOf = reflection.types.map((inner) => reflectionToJsonSchema(inner)).filter((item) => item !== void 0);
87
+ if (allOf.length === 0) return;
88
+ if (allOf.length === 1) return allOf[0];
89
+ return { allOf };
90
+ }
91
+ case _powerlines_deepkit_vendor_type.ReflectionKind.promise: return reflectionToJsonSchema(reflection.type);
92
+ case _powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral: return objectReflectionToJsonSchema(reflection);
93
+ case _powerlines_deepkit_vendor_type.ReflectionKind.class: switch (reflection.classType?.name) {
94
+ case "Date": return {
95
+ type: "string",
96
+ format: "date-time"
97
+ };
98
+ case "RegExp": return { type: "string" };
99
+ case "URL": return {
100
+ type: "string",
101
+ format: "uri"
102
+ };
103
+ case "Set": {
104
+ const itemType = reflection.arguments?.[0];
105
+ const items = itemType ? reflectionToJsonSchema(itemType) : void 0;
106
+ return items ? {
107
+ type: "array",
108
+ uniqueItems: true,
109
+ items
110
+ } : {
111
+ type: "array",
112
+ uniqueItems: true
113
+ };
114
+ }
115
+ case "Map": {
116
+ const valueType = reflection.arguments?.[1];
117
+ const additionalProperties = valueType ? reflectionToJsonSchema(valueType) : void 0;
118
+ const schema = { type: "object" };
119
+ if (additionalProperties) schema.additionalProperties = additionalProperties;
120
+ return schema;
121
+ }
122
+ case "Uint8Array":
123
+ case "Uint8ClampedArray":
124
+ case "Uint16Array":
125
+ case "Uint32Array":
126
+ case "Int8Array":
127
+ case "Int16Array":
128
+ case "Int32Array":
129
+ case "Float32Array":
130
+ case "Float64Array":
131
+ case "BigInt64Array":
132
+ case "BigUint64Array": return {
133
+ type: "string",
134
+ contentEncoding: "base64"
135
+ };
136
+ case void 0:
137
+ default: return objectReflectionToJsonSchema(reflection);
138
+ }
139
+ case _powerlines_deepkit_vendor_type.ReflectionKind.symbol:
140
+ case _powerlines_deepkit_vendor_type.ReflectionKind.property:
141
+ case _powerlines_deepkit_vendor_type.ReflectionKind.method:
142
+ case _powerlines_deepkit_vendor_type.ReflectionKind.function:
143
+ case _powerlines_deepkit_vendor_type.ReflectionKind.parameter:
144
+ case _powerlines_deepkit_vendor_type.ReflectionKind.typeParameter:
145
+ case _powerlines_deepkit_vendor_type.ReflectionKind.tupleMember:
146
+ case _powerlines_deepkit_vendor_type.ReflectionKind.enumMember:
147
+ case _powerlines_deepkit_vendor_type.ReflectionKind.rest:
148
+ case _powerlines_deepkit_vendor_type.ReflectionKind.indexSignature:
149
+ case _powerlines_deepkit_vendor_type.ReflectionKind.propertySignature:
150
+ case _powerlines_deepkit_vendor_type.ReflectionKind.methodSignature:
151
+ case _powerlines_deepkit_vendor_type.ReflectionKind.infer:
152
+ case _powerlines_deepkit_vendor_type.ReflectionKind.callSignature:
153
+ default: return;
154
+ }
155
+ }
156
+ /**
157
+ * Builds a JSON Schema object representation from a Deepkit class or object literal type.
158
+ *
159
+ * @param type - The class or object literal type whose members should be serialized.
160
+ * @returns A JSON Schema object describing the type's properties.
161
+ */
162
+ function objectReflectionToJsonSchema(type) {
163
+ const properties = {};
164
+ const required = [];
165
+ let additionalProperties;
166
+ const description = "description" in type && typeof type.description === "string" ? type.description : void 0;
167
+ for (const member of type.types) if (member.kind === _powerlines_deepkit_vendor_type.ReflectionKind.property || member.kind === _powerlines_deepkit_vendor_type.ReflectionKind.propertySignature) {
168
+ const property = member;
169
+ if (typeof property.name !== "string") continue;
170
+ const propertySchema = reflectionToJsonSchema(property.type);
171
+ if (!propertySchema) continue;
172
+ if (typeof property.description === "string") propertySchema.description = property.description;
173
+ properties[property.name] = propertySchema;
174
+ if (!property.optional) required.push(property.name);
175
+ } else if (member.kind === _powerlines_deepkit_vendor_type.ReflectionKind.indexSignature) {
176
+ const valueSchema = reflectionToJsonSchema(member.type);
177
+ if (valueSchema) additionalProperties = valueSchema;
178
+ }
179
+ const schema = {
180
+ type: "object",
181
+ properties
182
+ };
183
+ if (required.length > 0) schema.required = required;
184
+ if (additionalProperties !== void 0) schema.additionalProperties = additionalProperties;
185
+ if (description) schema.description = description;
186
+ return schema;
187
+ }
188
+
189
+ //#endregion
190
+ exports.objectReflectionToJsonSchema = objectReflectionToJsonSchema;
191
+ exports.reflectionToJsonSchema = reflectionToJsonSchema;
@@ -0,0 +1,21 @@
1
+ import { Type, TypeClass, TypeObjectLiteral } from "@powerlines/deepkit/vendor/type";
2
+ import { JsonSchema7Type } from "@stryke/json/types";
3
+
4
+ //#region src/reflection.d.ts
5
+ /**
6
+ * Converts a Deepkit type reflection into a JSON Schema representation.
7
+ *
8
+ * @param reflection - The Deepkit type reflection to convert.
9
+ * @returns The corresponding JSON Schema representation, or `undefined` if the type cannot be represented.
10
+ */
11
+ declare function reflectionToJsonSchema(reflection: Type): JsonSchema7Type | undefined;
12
+ /**
13
+ * Builds a JSON Schema object representation from a Deepkit class or object literal type.
14
+ *
15
+ * @param type - The class or object literal type whose members should be serialized.
16
+ * @returns A JSON Schema object describing the type's properties.
17
+ */
18
+ declare function objectReflectionToJsonSchema(type: TypeObjectLiteral | TypeClass): JsonSchema7Type;
19
+ //#endregion
20
+ export { objectReflectionToJsonSchema, reflectionToJsonSchema };
21
+ //# sourceMappingURL=reflection.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection.d.cts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;AAgCA;;;;;iBAAgB,sBAAA,CACd,UAAA,EAAY,IAAA,GACX,eAAA;;;;AAgMH;;;iBAAgB,4BAAA,CACd,IAAA,EAAM,iBAAA,GAAoB,SAAA,GACzB,eAAA"}
@@ -0,0 +1,21 @@
1
+ import { Type, TypeClass, TypeObjectLiteral } from "@powerlines/deepkit/vendor/type";
2
+ import { JsonSchema7Type } from "@stryke/json/types";
3
+
4
+ //#region src/reflection.d.ts
5
+ /**
6
+ * Converts a Deepkit type reflection into a JSON Schema representation.
7
+ *
8
+ * @param reflection - The Deepkit type reflection to convert.
9
+ * @returns The corresponding JSON Schema representation, or `undefined` if the type cannot be represented.
10
+ */
11
+ declare function reflectionToJsonSchema(reflection: Type): JsonSchema7Type | undefined;
12
+ /**
13
+ * Builds a JSON Schema object representation from a Deepkit class or object literal type.
14
+ *
15
+ * @param type - The class or object literal type whose members should be serialized.
16
+ * @returns A JSON Schema object describing the type's properties.
17
+ */
18
+ declare function objectReflectionToJsonSchema(type: TypeObjectLiteral | TypeClass): JsonSchema7Type;
19
+ //#endregion
20
+ export { objectReflectionToJsonSchema, reflectionToJsonSchema };
21
+ //# sourceMappingURL=reflection.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection.d.mts","names":[],"sources":["../src/reflection.ts"],"mappings":";;;;;AAgCA;;;;;iBAAgB,sBAAA,CACd,UAAA,EAAY,IAAA,GACX,eAAA;;;;AAgMH;;;iBAAgB,4BAAA,CACd,IAAA,EAAM,iBAAA,GAAoB,SAAA,GACzB,eAAA"}
@@ -0,0 +1,189 @@
1
+ import { ReflectionKind, TypeNumberBrand } from "@powerlines/deepkit/vendor/type";
2
+
3
+ //#region src/reflection.ts
4
+ /**
5
+ * Converts a Deepkit type reflection into a JSON Schema representation.
6
+ *
7
+ * @param reflection - The Deepkit type reflection to convert.
8
+ * @returns The corresponding JSON Schema representation, or `undefined` if the type cannot be represented.
9
+ */
10
+ function reflectionToJsonSchema(reflection) {
11
+ switch (reflection.kind) {
12
+ case ReflectionKind.any:
13
+ case ReflectionKind.unknown:
14
+ case ReflectionKind.void:
15
+ case ReflectionKind.object: return {};
16
+ case ReflectionKind.never:
17
+ case ReflectionKind.undefined: return { not: {} };
18
+ case ReflectionKind.null: return { type: "null" };
19
+ case ReflectionKind.string: return { type: "string" };
20
+ case ReflectionKind.boolean: return { type: "boolean" };
21
+ case ReflectionKind.number: {
22
+ const brand = reflection.brand;
23
+ return { type: brand !== void 0 && brand >= TypeNumberBrand.integer && brand <= TypeNumberBrand.uint32 ? "integer" : "number" };
24
+ }
25
+ case ReflectionKind.bigint: return {
26
+ type: "integer",
27
+ format: "int64"
28
+ };
29
+ case ReflectionKind.regexp: return { type: "string" };
30
+ case ReflectionKind.literal: {
31
+ const { literal } = reflection;
32
+ if (typeof literal === "string") return {
33
+ type: "string",
34
+ const: literal
35
+ };
36
+ if (typeof literal === "number") return {
37
+ type: Number.isInteger(literal) ? "integer" : "number",
38
+ const: literal
39
+ };
40
+ if (typeof literal === "boolean") return {
41
+ type: "boolean",
42
+ const: literal
43
+ };
44
+ if (typeof literal === "bigint") return {
45
+ type: "integer",
46
+ format: "int64"
47
+ };
48
+ if (literal instanceof RegExp) return {
49
+ type: "string",
50
+ pattern: literal.source
51
+ };
52
+ return {};
53
+ }
54
+ case ReflectionKind.templateLiteral: return { type: "string" };
55
+ case ReflectionKind.enum: {
56
+ const values = reflection.values.filter((value) => typeof value === "string" || typeof value === "number");
57
+ const allStrings = values.every((value) => typeof value === "string");
58
+ const allNumbers = values.every((value) => typeof value === "number");
59
+ return {
60
+ type: allStrings ? "string" : allNumbers ? "number" : ["string", "number"],
61
+ enum: values
62
+ };
63
+ }
64
+ case ReflectionKind.array: {
65
+ const items = reflectionToJsonSchema(reflection.type);
66
+ return items ? {
67
+ type: "array",
68
+ items
69
+ } : { type: "array" };
70
+ }
71
+ case ReflectionKind.tuple: return {
72
+ type: "array",
73
+ items: reflection.types.map((member) => reflectionToJsonSchema(member.type)).filter((item) => item !== void 0),
74
+ minItems: reflection.types.filter((member) => !member.optional).length,
75
+ maxItems: reflection.types.length
76
+ };
77
+ case ReflectionKind.union: {
78
+ const anyOf = reflection.types.map((inner) => reflectionToJsonSchema(inner)).filter((item) => item !== void 0);
79
+ if (anyOf.length === 0) return;
80
+ if (anyOf.length === 1) return anyOf[0];
81
+ return { anyOf };
82
+ }
83
+ case ReflectionKind.intersection: {
84
+ const allOf = reflection.types.map((inner) => reflectionToJsonSchema(inner)).filter((item) => item !== void 0);
85
+ if (allOf.length === 0) return;
86
+ if (allOf.length === 1) return allOf[0];
87
+ return { allOf };
88
+ }
89
+ case ReflectionKind.promise: return reflectionToJsonSchema(reflection.type);
90
+ case ReflectionKind.objectLiteral: return objectReflectionToJsonSchema(reflection);
91
+ case ReflectionKind.class: switch (reflection.classType?.name) {
92
+ case "Date": return {
93
+ type: "string",
94
+ format: "date-time"
95
+ };
96
+ case "RegExp": return { type: "string" };
97
+ case "URL": return {
98
+ type: "string",
99
+ format: "uri"
100
+ };
101
+ case "Set": {
102
+ const itemType = reflection.arguments?.[0];
103
+ const items = itemType ? reflectionToJsonSchema(itemType) : void 0;
104
+ return items ? {
105
+ type: "array",
106
+ uniqueItems: true,
107
+ items
108
+ } : {
109
+ type: "array",
110
+ uniqueItems: true
111
+ };
112
+ }
113
+ case "Map": {
114
+ const valueType = reflection.arguments?.[1];
115
+ const additionalProperties = valueType ? reflectionToJsonSchema(valueType) : void 0;
116
+ const schema = { type: "object" };
117
+ if (additionalProperties) schema.additionalProperties = additionalProperties;
118
+ return schema;
119
+ }
120
+ case "Uint8Array":
121
+ case "Uint8ClampedArray":
122
+ case "Uint16Array":
123
+ case "Uint32Array":
124
+ case "Int8Array":
125
+ case "Int16Array":
126
+ case "Int32Array":
127
+ case "Float32Array":
128
+ case "Float64Array":
129
+ case "BigInt64Array":
130
+ case "BigUint64Array": return {
131
+ type: "string",
132
+ contentEncoding: "base64"
133
+ };
134
+ case void 0:
135
+ default: return objectReflectionToJsonSchema(reflection);
136
+ }
137
+ case ReflectionKind.symbol:
138
+ case ReflectionKind.property:
139
+ case ReflectionKind.method:
140
+ case ReflectionKind.function:
141
+ case ReflectionKind.parameter:
142
+ case ReflectionKind.typeParameter:
143
+ case ReflectionKind.tupleMember:
144
+ case ReflectionKind.enumMember:
145
+ case ReflectionKind.rest:
146
+ case ReflectionKind.indexSignature:
147
+ case ReflectionKind.propertySignature:
148
+ case ReflectionKind.methodSignature:
149
+ case ReflectionKind.infer:
150
+ case ReflectionKind.callSignature:
151
+ default: return;
152
+ }
153
+ }
154
+ /**
155
+ * Builds a JSON Schema object representation from a Deepkit class or object literal type.
156
+ *
157
+ * @param type - The class or object literal type whose members should be serialized.
158
+ * @returns A JSON Schema object describing the type's properties.
159
+ */
160
+ function objectReflectionToJsonSchema(type) {
161
+ const properties = {};
162
+ const required = [];
163
+ let additionalProperties;
164
+ const description = "description" in type && typeof type.description === "string" ? type.description : void 0;
165
+ for (const member of type.types) if (member.kind === ReflectionKind.property || member.kind === ReflectionKind.propertySignature) {
166
+ const property = member;
167
+ if (typeof property.name !== "string") continue;
168
+ const propertySchema = reflectionToJsonSchema(property.type);
169
+ if (!propertySchema) continue;
170
+ if (typeof property.description === "string") propertySchema.description = property.description;
171
+ properties[property.name] = propertySchema;
172
+ if (!property.optional) required.push(property.name);
173
+ } else if (member.kind === ReflectionKind.indexSignature) {
174
+ const valueSchema = reflectionToJsonSchema(member.type);
175
+ if (valueSchema) additionalProperties = valueSchema;
176
+ }
177
+ const schema = {
178
+ type: "object",
179
+ properties
180
+ };
181
+ if (required.length > 0) schema.required = required;
182
+ if (additionalProperties !== void 0) schema.additionalProperties = additionalProperties;
183
+ if (description) schema.description = description;
184
+ return schema;
185
+ }
186
+
187
+ //#endregion
188
+ export { objectReflectionToJsonSchema, reflectionToJsonSchema };
189
+ //# sourceMappingURL=reflection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection.mjs","names":["indexSignature"],"sources":["../src/reflection.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Type, TypeClass } from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionKind,\n TypeNumberBrand,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport { JsonSchema7Type } from \"@stryke/json/types\";\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema representation.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JSON Schema representation, or `undefined` if the type cannot be represented.\n */\nexport function reflectionToJsonSchema(\n reflection: Type\n): JsonSchema7Type | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return {};\n case ReflectionKind.never:\n case ReflectionKind.undefined:\n return { not: {} };\n case ReflectionKind.null:\n return { type: \"null\" };\n case ReflectionKind.string:\n return { type: \"string\" };\n case ReflectionKind.boolean:\n return { type: \"boolean\" };\n case ReflectionKind.number: {\n const brand = reflection.brand;\n const isInteger =\n brand !== undefined &&\n brand >= TypeNumberBrand.integer &&\n brand <= TypeNumberBrand.uint32;\n\n return { type: isInteger ? \"integer\" : \"number\" };\n }\n case ReflectionKind.bigint:\n return { type: \"integer\", format: \"int64\" };\n case ReflectionKind.regexp:\n return { type: \"string\" };\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (typeof literal === \"string\") {\n return { type: \"string\", const: literal };\n }\n if (typeof literal === \"number\") {\n return {\n type: Number.isInteger(literal) ? \"integer\" : \"number\",\n const: literal\n };\n }\n if (typeof literal === \"boolean\") {\n return { type: \"boolean\", const: literal };\n }\n if (typeof literal === \"bigint\") {\n return { type: \"integer\", format: \"int64\" };\n }\n if (literal instanceof RegExp) {\n return { type: \"string\", pattern: literal.source };\n }\n return {};\n }\n case ReflectionKind.templateLiteral:\n return { type: \"string\" };\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n (value): value is string | number =>\n typeof value === \"string\" || typeof value === \"number\"\n );\n const allStrings = values.every(value => typeof value === \"string\");\n const allNumbers = values.every(value => typeof value === \"number\");\n\n return {\n type: allStrings\n ? \"string\"\n : allNumbers\n ? \"number\"\n : [\"string\", \"number\"],\n enum: values\n };\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchema(reflection.type);\n\n return items ? { type: \"array\", items } : { type: \"array\" };\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchema(member.type))\n .filter((item): item is JsonSchema7Type => item !== undefined);\n const required = reflection.types.filter(\n member => !member.optional\n ).length;\n\n return {\n type: \"array\",\n items,\n minItems: required,\n maxItems: reflection.types.length\n };\n }\n case ReflectionKind.union: {\n const anyOf = reflection.types\n .map(inner => reflectionToJsonSchema(inner))\n .filter((item): item is JsonSchema7Type => item !== undefined);\n if (anyOf.length === 0) {\n return undefined;\n }\n if (anyOf.length === 1) {\n return anyOf[0];\n }\n return { anyOf };\n }\n case ReflectionKind.intersection: {\n const allOf = reflection.types\n .map(inner => reflectionToJsonSchema(inner))\n .filter((item): item is JsonSchema7Type => item !== undefined);\n if (allOf.length === 0) {\n return undefined;\n }\n if (allOf.length === 1) {\n return allOf[0];\n }\n return { allOf };\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchema(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJsonSchema(reflection);\n case ReflectionKind.class: {\n const classType = reflection.classType as { name?: string } | undefined;\n const className = classType?.name;\n switch (className) {\n case \"Date\":\n return { type: \"string\", format: \"date-time\" };\n case \"RegExp\":\n return { type: \"string\" };\n case \"URL\":\n return { type: \"string\", format: \"uri\" };\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType ? reflectionToJsonSchema(itemType) : undefined;\n\n return items\n ? { type: \"array\", uniqueItems: true, items }\n : { type: \"array\", uniqueItems: true };\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const additionalProperties = valueType\n ? reflectionToJsonSchema(valueType)\n : undefined;\n const schema = { type: \"object\" } as JsonSchema7Type;\n if (additionalProperties) {\n (\n schema as { additionalProperties?: JsonSchema7Type }\n ).additionalProperties = additionalProperties;\n }\n return schema;\n }\n case \"Uint8Array\":\n case \"Uint8ClampedArray\":\n case \"Uint16Array\":\n case \"Uint32Array\":\n case \"Int8Array\":\n case \"Int16Array\":\n case \"Int32Array\":\n case \"Float32Array\":\n case \"Float64Array\":\n case \"BigInt64Array\":\n case \"BigUint64Array\":\n return { type: \"string\", contentEncoding: \"base64\" };\n case undefined:\n default:\n return objectReflectionToJsonSchema(reflection);\n }\n }\n\n case ReflectionKind.symbol:\n case ReflectionKind.property:\n case ReflectionKind.method:\n case ReflectionKind.function:\n case ReflectionKind.parameter:\n case ReflectionKind.typeParameter:\n case ReflectionKind.tupleMember:\n case ReflectionKind.enumMember:\n case ReflectionKind.rest:\n case ReflectionKind.indexSignature:\n case ReflectionKind.propertySignature:\n case ReflectionKind.methodSignature:\n case ReflectionKind.infer:\n case ReflectionKind.callSignature:\n default:\n return undefined;\n }\n}\n\n/**\n * Builds a JSON Schema object representation from a Deepkit class or object literal type.\n *\n * @param type - The class or object literal type whose members should be serialized.\n * @returns A JSON Schema object describing the type's properties.\n */\nexport function objectReflectionToJsonSchema(\n type: TypeObjectLiteral | TypeClass\n): JsonSchema7Type {\n const properties: Record<string, JsonSchema7Type> = {};\n const required: string[] = [];\n let additionalProperties: JsonSchema7Type | boolean | undefined;\n const description =\n \"description\" in type && typeof type.description === \"string\"\n ? type.description\n : undefined;\n\n for (const member of type.types) {\n if (\n member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature\n ) {\n const property = member;\n if (typeof property.name !== \"string\") {\n continue;\n }\n const propertySchema = reflectionToJsonSchema(property.type);\n if (!propertySchema) {\n continue;\n }\n if (typeof property.description === \"string\") {\n (propertySchema as { description?: string }).description =\n property.description;\n }\n properties[property.name] = propertySchema;\n if (!property.optional) {\n required.push(property.name);\n }\n } else if (member.kind === ReflectionKind.indexSignature) {\n const indexSignature = member;\n const valueSchema = reflectionToJsonSchema(indexSignature.type);\n if (valueSchema) {\n additionalProperties = valueSchema;\n }\n }\n }\n\n const schema = {\n type: \"object\",\n properties\n } as JsonSchema7Type;\n\n if (required.length > 0) {\n (schema as { required?: string[] }).required = required;\n }\n if (additionalProperties !== undefined) {\n (\n schema as { additionalProperties?: JsonSchema7Type | boolean }\n ).additionalProperties = additionalProperties;\n }\n if (description) {\n (schema as { description?: string }).description = description;\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;AAgCA,SAAgB,uBACd,YAC6B;AAC7B,SAAQ,WAAW,MAAnB;EACE,KAAK,eAAe;EACpB,KAAK,eAAe;EACpB,KAAK,eAAe;EACpB,KAAK,eAAe,OAClB,QAAO,EAAE;EACX,KAAK,eAAe;EACpB,KAAK,eAAe,UAClB,QAAO,EAAE,KAAK,EAAE,EAAE;EACpB,KAAK,eAAe,KAClB,QAAO,EAAE,MAAM,QAAQ;EACzB,KAAK,eAAe,OAClB,QAAO,EAAE,MAAM,UAAU;EAC3B,KAAK,eAAe,QAClB,QAAO,EAAE,MAAM,WAAW;EAC5B,KA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OAC3B,CACE,OACA,uBAAuB;AAE3B,KAAI,YACF,CAAC,OAAoC,cAAc;AAGrD,QAAO"}
@@ -0,0 +1,84 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_bundle = require('./bundle.cjs');
4
+ let defu = require("defu");
5
+ defu = require_runtime.__toESM(defu, 1);
6
+ let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
7
+ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
8
+ let _stryke_convert_parse_type_definition = require("@stryke/convert/parse-type-definition");
9
+ let _stryke_path_find = require("@stryke/path/find");
10
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
11
+
12
+ //#region src/resolve.ts
13
+ /**
14
+ * Compiles a type definition to a module and returns the module.
15
+ *
16
+ * @param context - The context object containing the environment paths.
17
+ * @param type - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.
18
+ * @param overrides - Optional overrides for the ESBuild configuration.
19
+ * @returns A promise that resolves to the compiled module.
20
+ */
21
+ async function resolveModule(context, type, overrides) {
22
+ let typeDefinition;
23
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(type)) typeDefinition = (0, _stryke_convert_parse_type_definition.parseTypeDefinition)(type);
24
+ else typeDefinition = type;
25
+ const result = await require_bundle.bundle(context, typeDefinition.file, overrides);
26
+ let resolved;
27
+ try {
28
+ resolved = await context.resolver.evalModule(result.text, {
29
+ filename: result.path,
30
+ ext: (0, _stryke_path_find.findFileDotExtension)(result.path)
31
+ });
32
+ } catch (error) {
33
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(error.message) && new RegExp(`Cannot find module '${context.config.framework?.name || "powerlines"}:.*'`).test(error.message)) {
34
+ const moduleName = error.message.match(new RegExp(`Cannot find module '(${context.config.framework?.name || "powerlines"}:.*)'`))?.[1];
35
+ throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${typeDefinition.file}". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
36
+
37
+ Bundle output for module:
38
+ ${result.text}` : ""}`);
39
+ }
40
+ throw new Error(`Failed to evaluate the bundled module for "${typeDefinition.file}". Error: ${error.message}${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
41
+
42
+ Bundle output for module:
43
+ ${result.text}` : ""}`);
44
+ }
45
+ return resolved;
46
+ }
47
+ /**
48
+ * Compiles a type definition to a module and returns the specified export from the module.
49
+ *
50
+ * @param context - The context object containing the environment paths.
51
+ * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.
52
+ * @param options - Optional overrides for the ESBuild configuration.
53
+ * @returns A promise that resolves to the compiled module.
54
+ */
55
+ async function resolve(context, input, options) {
56
+ let typeDefinition;
57
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(input)) typeDefinition = (0, _stryke_convert_parse_type_definition.parseTypeDefinition)(input);
58
+ else typeDefinition = input;
59
+ const resolved = await resolveModule(context, typeDefinition, options);
60
+ let exportName = typeDefinition.name;
61
+ if (!exportName) exportName = "default";
62
+ const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];
63
+ if (resolvedExport === void 0) throw new Error(`The export "${exportName}" could not be resolved in the "${typeDefinition.file}" module. ${Object.keys(resolved).length === 0 ? `After bundling, no exports were found in the module. Please ensure that the "${typeDefinition.file}" module has a "${exportName}" export with the desired value.` : `After bundling, the available exports were: ${Object.keys(resolved).join(", ")}. Please ensure that the export exists and is correctly named.`}`);
64
+ return resolvedExport;
65
+ }
66
+ /**
67
+ * Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.
68
+ *
69
+ * @param context - The context object containing the environment paths.
70
+ * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.
71
+ * @param options - Optional overrides for the ESBuild configuration.
72
+ * @returns A promise that resolves to the Deepkit Type reflection.
73
+ */
74
+ async function resolveReflection(context, input, options) {
75
+ return (0, _powerlines_deepkit_vendor_type.reflect)(await resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
76
+ reflection: "default",
77
+ level: "all"
78
+ })] })));
79
+ }
80
+
81
+ //#endregion
82
+ exports.resolve = resolve;
83
+ exports.resolveModule = resolveModule;
84
+ exports.resolveReflection = resolveReflection;
@@ -0,0 +1,36 @@
1
+ import { BundleOptions } from "./bundle.cjs";
2
+ import { PluginContext } from "@powerlines/core";
3
+ import { Type } from "@powerlines/deepkit/vendor/type";
4
+ import { TypeDefinitionParameter } from "@stryke/types/configuration";
5
+
6
+ //#region src/resolve.d.ts
7
+ /**
8
+ * Compiles a type definition to a module and returns the module.
9
+ *
10
+ * @param context - The context object containing the environment paths.
11
+ * @param type - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.
12
+ * @param overrides - Optional overrides for the ESBuild configuration.
13
+ * @returns A promise that resolves to the compiled module.
14
+ */
15
+ declare function resolveModule<TResult, TContext extends PluginContext = PluginContext>(context: TContext, type: TypeDefinitionParameter, overrides?: BundleOptions): Promise<TResult>;
16
+ /**
17
+ * Compiles a type definition to a module and returns the specified export from the module.
18
+ *
19
+ * @param context - The context object containing the environment paths.
20
+ * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.
21
+ * @param options - Optional overrides for the ESBuild configuration.
22
+ * @returns A promise that resolves to the compiled module.
23
+ */
24
+ declare function resolve<TResult, TContext extends PluginContext = PluginContext>(context: TContext, input: TypeDefinitionParameter, options?: BundleOptions): Promise<TResult>;
25
+ /**
26
+ * Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.
27
+ *
28
+ * @param context - The context object containing the environment paths.
29
+ * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.
30
+ * @param options - Optional overrides for the ESBuild configuration.
31
+ * @returns A promise that resolves to the Deepkit Type reflection.
32
+ */
33
+ declare function resolveReflection<TContext extends PluginContext = PluginContext>(context: TContext, input: TypeDefinitionParameter, options?: BundleOptions): Promise<Type>;
34
+ //#endregion
35
+ export { resolve, resolveModule, resolveReflection };
36
+ //# sourceMappingURL=resolve.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAuCA;;;;;;iBAAsB,aAAA,2BAEH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,IAAA,EAAM,uBAAA,EACN,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;;;;;;;;iBAyEW,OAAA,2BAEH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,uBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;;;iBAiDW,iBAAA,kBACH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,uBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,IAAA"}