@powerlines/schema 0.11.72 → 0.11.73
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.
- package/dist/index.cjs +2111 -97
- package/dist/index.d.cts +1841 -11
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1841 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1999 -15
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -5
- package/dist/_virtual/_rolldown/runtime.cjs +0 -37
- package/dist/bundle.cjs +0 -55
- package/dist/bundle.d.cts +0 -21
- package/dist/bundle.d.cts.map +0 -1
- package/dist/bundle.d.mts +0 -23
- package/dist/bundle.d.mts.map +0 -1
- package/dist/bundle.mjs +0 -54
- package/dist/bundle.mjs.map +0 -1
- package/dist/codegen.cjs +0 -81
- package/dist/codegen.d.cts +0 -26
- package/dist/codegen.d.cts.map +0 -1
- package/dist/codegen.d.mts +0 -28
- package/dist/codegen.d.mts.map +0 -1
- package/dist/codegen.mjs +0 -77
- package/dist/codegen.mjs.map +0 -1
- package/dist/constants.cjs +0 -69
- package/dist/constants.d.cts +0 -17
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -19
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs +0 -65
- package/dist/constants.mjs.map +0 -1
- package/dist/extract.cjs +0 -490
- package/dist/extract.d.cts +0 -125
- package/dist/extract.d.cts.map +0 -1
- package/dist/extract.d.mts +0 -127
- package/dist/extract.d.mts.map +0 -1
- package/dist/extract.mjs +0 -480
- package/dist/extract.mjs.map +0 -1
- package/dist/helpers.cjs +0 -171
- package/dist/helpers.d.cts +0 -111
- package/dist/helpers.d.cts.map +0 -1
- package/dist/helpers.d.mts +0 -113
- package/dist/helpers.d.mts.map +0 -1
- package/dist/helpers.mjs +0 -164
- package/dist/helpers.mjs.map +0 -1
- package/dist/metadata.cjs +0 -61
- package/dist/metadata.d.cts +0 -31
- package/dist/metadata.d.cts.map +0 -1
- package/dist/metadata.d.mts +0 -33
- package/dist/metadata.d.mts.map +0 -1
- package/dist/metadata.mjs +0 -60
- package/dist/metadata.mjs.map +0 -1
- package/dist/persistence.cjs +0 -82
- package/dist/persistence.d.cts +0 -47
- package/dist/persistence.d.cts.map +0 -1
- package/dist/persistence.d.mts +0 -49
- package/dist/persistence.d.mts.map +0 -1
- package/dist/persistence.mjs +0 -79
- package/dist/persistence.mjs.map +0 -1
- package/dist/reflection.cjs +0 -434
- package/dist/reflection.d.cts +0 -11
- package/dist/reflection.d.cts.map +0 -1
- package/dist/reflection.d.mts +0 -13
- package/dist/reflection.d.mts.map +0 -1
- package/dist/reflection.mjs +0 -433
- package/dist/reflection.mjs.map +0 -1
- package/dist/resolve.cjs +0 -113
- package/dist/resolve.d.cts +0 -36
- package/dist/resolve.d.cts.map +0 -1
- package/dist/resolve.d.mts +0 -38
- package/dist/resolve.d.mts.map +0 -1
- package/dist/resolve.mjs +0 -110
- package/dist/resolve.mjs.map +0 -1
- package/dist/type-checks.cjs +0 -642
- package/dist/type-checks.d.cts +0 -316
- package/dist/type-checks.d.cts.map +0 -1
- package/dist/type-checks.d.mts +0 -318
- package/dist/type-checks.d.mts.map +0 -1
- package/dist/type-checks.mjs +0 -603
- package/dist/type-checks.mjs.map +0 -1
- package/dist/types.d.cts +0 -1152
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -1154
- package/dist/types.d.mts.map +0 -1
- package/dist/validate.cjs +0 -35
- package/dist/validate.mjs +0 -33
- package/dist/validate.mjs.map +0 -1
package/dist/reflection.mjs
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import __tsdown_shims_path from 'node:path'
|
|
4
|
-
import __tsdown_shims_url from 'node:url'
|
|
5
|
-
|
|
6
|
-
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
-
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
-
|
|
9
|
-
import { isJsonSchemaObject, isJsonSchemaPrimitiveType, isNullOnlyJsonSchema } from "./type-checks.mjs";
|
|
10
|
-
import { getJsonSchemaType } from "./codegen.mjs";
|
|
11
|
-
import defu from "defu";
|
|
12
|
-
import { isBigInt, isBoolean, isInteger, isNull, isNumber, isRegExp, isSetArray, isSetObject, isSetString, isString, isUndefined } from "@stryke/type-checks";
|
|
13
|
-
import { ReflectionClass, ReflectionKind, TypeNumberBrand } from "@powerlines/deepkit/vendor/type";
|
|
14
|
-
|
|
15
|
-
//#region src/reflection.ts
|
|
16
|
-
/**
|
|
17
|
-
* Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.
|
|
18
|
-
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.
|
|
21
|
-
*
|
|
22
|
-
* @param brand - The Deepkit numeric brand to convert.
|
|
23
|
-
* @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.
|
|
24
|
-
*/
|
|
25
|
-
function numberBrandToJsonSchema(brand) {
|
|
26
|
-
switch (brand) {
|
|
27
|
-
case TypeNumberBrand.integer: return {
|
|
28
|
-
type: "integer",
|
|
29
|
-
format: "int32",
|
|
30
|
-
multipleOf: 1
|
|
31
|
-
};
|
|
32
|
-
case TypeNumberBrand.int8: return {
|
|
33
|
-
type: "integer",
|
|
34
|
-
format: "int8",
|
|
35
|
-
multipleOf: 1
|
|
36
|
-
};
|
|
37
|
-
case TypeNumberBrand.uint8: return {
|
|
38
|
-
type: "integer",
|
|
39
|
-
format: "uint8",
|
|
40
|
-
multipleOf: 1
|
|
41
|
-
};
|
|
42
|
-
case TypeNumberBrand.int16: return {
|
|
43
|
-
type: "integer",
|
|
44
|
-
format: "int16",
|
|
45
|
-
multipleOf: 1
|
|
46
|
-
};
|
|
47
|
-
case TypeNumberBrand.uint16: return {
|
|
48
|
-
type: "integer",
|
|
49
|
-
format: "uint16",
|
|
50
|
-
multipleOf: 1
|
|
51
|
-
};
|
|
52
|
-
case TypeNumberBrand.int32: return {
|
|
53
|
-
type: "integer",
|
|
54
|
-
format: "int32",
|
|
55
|
-
multipleOf: 1
|
|
56
|
-
};
|
|
57
|
-
case TypeNumberBrand.uint32: return {
|
|
58
|
-
type: "integer",
|
|
59
|
-
format: "uint32",
|
|
60
|
-
multipleOf: 1
|
|
61
|
-
};
|
|
62
|
-
case TypeNumberBrand.float:
|
|
63
|
-
case TypeNumberBrand.float32: return {
|
|
64
|
-
type: "number",
|
|
65
|
-
format: "float"
|
|
66
|
-
};
|
|
67
|
-
case TypeNumberBrand.float64: return {
|
|
68
|
-
type: "number",
|
|
69
|
-
format: "double"
|
|
70
|
-
};
|
|
71
|
-
case void 0:
|
|
72
|
-
default: return { type: "number" };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function withReflectionTags(reflection, schema) {
|
|
76
|
-
if (!isSetObject(schema) || !isSetObject(reflection?.tags)) return schema;
|
|
77
|
-
const updatedSchema = { ...schema };
|
|
78
|
-
const tags = reflection.tags;
|
|
79
|
-
if (isSetString(tags.title)) updatedSchema.title = tags.title;
|
|
80
|
-
if (isSetArray(tags.alias)) updatedSchema.alias = tags.alias;
|
|
81
|
-
if (!isUndefined(tags.hidden)) updatedSchema.hidden = tags.hidden;
|
|
82
|
-
if (!isUndefined(tags.ignore)) updatedSchema.ignore = tags.ignore;
|
|
83
|
-
if (!isUndefined(tags.internal)) updatedSchema.internal = tags.internal;
|
|
84
|
-
if (!isUndefined(tags.runtime)) updatedSchema.runtime = tags.runtime;
|
|
85
|
-
if (!isUndefined(tags.readonly)) updatedSchema.readOnly = tags.readonly;
|
|
86
|
-
return updatedSchema;
|
|
87
|
-
}
|
|
88
|
-
function withNullable(schema) {
|
|
89
|
-
if (!isSetObject(schema)) return { anyOf: [schema, {
|
|
90
|
-
type: "null",
|
|
91
|
-
default: null
|
|
92
|
-
}] };
|
|
93
|
-
const rawType = schema.type;
|
|
94
|
-
const types = Array.isArray(rawType) ? [...rawType] : rawType ? [rawType] : [];
|
|
95
|
-
if (!types.includes("null")) types.push("null");
|
|
96
|
-
return {
|
|
97
|
-
...schema,
|
|
98
|
-
type: types.length === 1 ? types[0] : types
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.
|
|
103
|
-
*/
|
|
104
|
-
function reflectionToJsonSchema(reflection) {
|
|
105
|
-
return reflectionToJsonSchemaInner(reflection);
|
|
106
|
-
}
|
|
107
|
-
function reflectionToJsonSchemaInner(reflection) {
|
|
108
|
-
switch (reflection.kind) {
|
|
109
|
-
case ReflectionKind.any:
|
|
110
|
-
case ReflectionKind.unknown:
|
|
111
|
-
case ReflectionKind.void:
|
|
112
|
-
case ReflectionKind.object: return withReflectionTags(reflection, { name: reflection.typeName });
|
|
113
|
-
case ReflectionKind.never: return;
|
|
114
|
-
case ReflectionKind.undefined:
|
|
115
|
-
case ReflectionKind.null: return withReflectionTags(reflection, {
|
|
116
|
-
type: "null",
|
|
117
|
-
name: reflection.typeName,
|
|
118
|
-
default: null
|
|
119
|
-
});
|
|
120
|
-
case ReflectionKind.string: return withReflectionTags(reflection, {
|
|
121
|
-
type: "string",
|
|
122
|
-
name: reflection.typeName
|
|
123
|
-
});
|
|
124
|
-
case ReflectionKind.boolean: return withReflectionTags(reflection, {
|
|
125
|
-
type: "boolean",
|
|
126
|
-
name: reflection.typeName
|
|
127
|
-
});
|
|
128
|
-
case ReflectionKind.number: return withReflectionTags(reflection, numberBrandToJsonSchema(reflection.brand));
|
|
129
|
-
case ReflectionKind.bigint: return withReflectionTags(reflection, {
|
|
130
|
-
type: "integer",
|
|
131
|
-
name: reflection.typeName,
|
|
132
|
-
format: "int64"
|
|
133
|
-
});
|
|
134
|
-
case ReflectionKind.regexp: return withReflectionTags(reflection, {
|
|
135
|
-
type: "string",
|
|
136
|
-
name: reflection.typeName,
|
|
137
|
-
format: "regex",
|
|
138
|
-
contentMediaType: "text/regex"
|
|
139
|
-
});
|
|
140
|
-
case ReflectionKind.literal: {
|
|
141
|
-
const { literal } = reflection;
|
|
142
|
-
if (isBigInt(literal)) return withReflectionTags(reflection, {
|
|
143
|
-
type: "integer",
|
|
144
|
-
name: reflection.typeName,
|
|
145
|
-
format: "int64",
|
|
146
|
-
const: literal
|
|
147
|
-
});
|
|
148
|
-
if (isRegExp(literal)) return withReflectionTags(reflection, {
|
|
149
|
-
type: "string",
|
|
150
|
-
name: reflection.typeName,
|
|
151
|
-
format: "regex",
|
|
152
|
-
const: literal.source
|
|
153
|
-
});
|
|
154
|
-
return withReflectionTags(reflection, {
|
|
155
|
-
type: getJsonSchemaType(literal),
|
|
156
|
-
name: reflection.typeName,
|
|
157
|
-
const: literal
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
case ReflectionKind.templateLiteral: return withReflectionTags(reflection, { type: "string" });
|
|
161
|
-
case ReflectionKind.enum: {
|
|
162
|
-
const values = reflection.values.filter((value) => isString(value) || isInteger(value) || isBigInt(value) || isNumber(value) || isBoolean(value) || isNull(value));
|
|
163
|
-
if (values.length === 0) return withReflectionTags(reflection, {
|
|
164
|
-
name: reflection.typeName,
|
|
165
|
-
description: reflection.description,
|
|
166
|
-
enum: []
|
|
167
|
-
});
|
|
168
|
-
return withReflectionTags(reflection, {
|
|
169
|
-
type: values.every((value) => isString(value)) ? "string" : values.every((value) => isInteger(value) || isBigInt(value)) ? "integer" : values.every((value) => isNumber(value)) ? "number" : values.every((value) => isBoolean(value)) ? "boolean" : values.every((value) => isNull(value)) ? "null" : values.reduce((ret, value) => {
|
|
170
|
-
const type = getJsonSchemaType(value);
|
|
171
|
-
if (isJsonSchemaPrimitiveType(type) && !ret.includes(type)) ret.push(type);
|
|
172
|
-
return ret;
|
|
173
|
-
}, []),
|
|
174
|
-
name: reflection.typeName,
|
|
175
|
-
description: reflection.description,
|
|
176
|
-
enum: values,
|
|
177
|
-
default: values.length === 1 ? values[0] : void 0
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
case ReflectionKind.array: {
|
|
181
|
-
const items = reflectionToJsonSchemaInner(reflection.type);
|
|
182
|
-
return withReflectionTags(reflection, {
|
|
183
|
-
type: "array",
|
|
184
|
-
name: reflection.typeName,
|
|
185
|
-
items: items ?? {}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
case ReflectionKind.tuple: {
|
|
189
|
-
const items = reflection.types.map((member) => reflectionToJsonSchemaInner(member.type)).filter((item) => item !== void 0);
|
|
190
|
-
if (items.length <= 1) return withReflectionTags(reflection, {
|
|
191
|
-
type: "array",
|
|
192
|
-
name: reflection.typeName,
|
|
193
|
-
items: items.length === 1 ? items[0] : {}
|
|
194
|
-
});
|
|
195
|
-
return withReflectionTags(reflection, {
|
|
196
|
-
type: "array",
|
|
197
|
-
name: reflection.typeName,
|
|
198
|
-
prefixItems: items,
|
|
199
|
-
minItems: items.length,
|
|
200
|
-
maxItems: items.length
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
case ReflectionKind.union: {
|
|
204
|
-
const branches = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter((branch) => branch !== void 0);
|
|
205
|
-
if (!reflection.types.some((inner) => inner.kind === ReflectionKind.null || inner.kind === ReflectionKind.undefined)) return withReflectionTags(reflection, {
|
|
206
|
-
name: reflection.typeName,
|
|
207
|
-
anyOf: branches
|
|
208
|
-
});
|
|
209
|
-
const nonNull = branches.filter((branch) => !isNullOnlyJsonSchema(branch));
|
|
210
|
-
if (nonNull.length === 0) return withReflectionTags(reflection, {
|
|
211
|
-
type: "null",
|
|
212
|
-
default: null
|
|
213
|
-
});
|
|
214
|
-
if (nonNull.length === 1) {
|
|
215
|
-
const first = nonNull[0];
|
|
216
|
-
if (!isSetObject(first)) return withNullable(withReflectionTags(reflection, {
|
|
217
|
-
name: reflection.typeName,
|
|
218
|
-
anyOf: [first]
|
|
219
|
-
}));
|
|
220
|
-
return withNullable(withReflectionTags(reflection, {
|
|
221
|
-
name: reflection.typeName,
|
|
222
|
-
...first
|
|
223
|
-
}));
|
|
224
|
-
}
|
|
225
|
-
const enumValues = nonNull.map((branch) => isSetObject(branch) ? branch.const : void 0).filter((value) => value === null || typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean");
|
|
226
|
-
if (enumValues.length === nonNull.length) return withNullable(withReflectionTags(reflection, {
|
|
227
|
-
name: reflection.typeName,
|
|
228
|
-
enum: enumValues
|
|
229
|
-
}));
|
|
230
|
-
const discriminator = tryReflectionDiscriminator(reflection.types);
|
|
231
|
-
if (discriminator && isSetObject(discriminator)) return withNullable(withReflectionTags(reflection, {
|
|
232
|
-
name: reflection.typeName,
|
|
233
|
-
...discriminator
|
|
234
|
-
}));
|
|
235
|
-
return withNullable(withReflectionTags(reflection, {
|
|
236
|
-
name: reflection.typeName,
|
|
237
|
-
anyOf: nonNull
|
|
238
|
-
}));
|
|
239
|
-
}
|
|
240
|
-
case ReflectionKind.intersection: {
|
|
241
|
-
const members = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter((item) => item !== void 0);
|
|
242
|
-
if (members.length === 0) return;
|
|
243
|
-
if (members.length === 1) {
|
|
244
|
-
if (!isSetObject(members[0])) return members[0];
|
|
245
|
-
return withReflectionTags(reflection, {
|
|
246
|
-
name: reflection.typeName,
|
|
247
|
-
...members[0]
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
if (members.every(isJsonSchemaObject)) return withReflectionTags(reflection, {
|
|
251
|
-
name: reflection.typeName,
|
|
252
|
-
...mergeObjectSchemas(members)
|
|
253
|
-
});
|
|
254
|
-
return withReflectionTags(reflection, {
|
|
255
|
-
name: reflection.typeName,
|
|
256
|
-
allOf: members
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
case ReflectionKind.promise: return reflectionToJsonSchemaInner(reflection.type);
|
|
260
|
-
case ReflectionKind.objectLiteral: return objectReflectionToJsonSchema(reflection);
|
|
261
|
-
case ReflectionKind.class: switch (reflection.classType?.name) {
|
|
262
|
-
case "Date": return withReflectionTags(reflection, {
|
|
263
|
-
type: "string",
|
|
264
|
-
format: "date-time"
|
|
265
|
-
});
|
|
266
|
-
case "RegExp": return withReflectionTags(reflection, {
|
|
267
|
-
type: "string",
|
|
268
|
-
format: "regex"
|
|
269
|
-
});
|
|
270
|
-
case "URL": return withReflectionTags(reflection, {
|
|
271
|
-
type: "string",
|
|
272
|
-
format: "uri"
|
|
273
|
-
});
|
|
274
|
-
case "Set": {
|
|
275
|
-
const itemType = reflection.arguments?.[0];
|
|
276
|
-
return withReflectionTags(reflection, {
|
|
277
|
-
type: "array",
|
|
278
|
-
items: (itemType ? reflectionToJsonSchemaInner(itemType) : void 0) ?? {},
|
|
279
|
-
uniqueItems: true
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
case "Map": {
|
|
283
|
-
const valueType = reflection.arguments?.[1];
|
|
284
|
-
return withReflectionTags(reflection, {
|
|
285
|
-
type: "object",
|
|
286
|
-
additionalProperties: (valueType ? reflectionToJsonSchemaInner(valueType) : void 0) ?? true
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
case "Uint8Array":
|
|
290
|
-
case "Uint8ClampedArray":
|
|
291
|
-
case "Uint16Array":
|
|
292
|
-
case "Uint32Array":
|
|
293
|
-
case "Int8Array":
|
|
294
|
-
case "Int16Array":
|
|
295
|
-
case "Int32Array":
|
|
296
|
-
case "Float32Array":
|
|
297
|
-
case "Float64Array":
|
|
298
|
-
case "BigInt64Array":
|
|
299
|
-
case "BigUint64Array": return withReflectionTags(reflection, {
|
|
300
|
-
type: "string",
|
|
301
|
-
format: "byte",
|
|
302
|
-
contentEncoding: "base64"
|
|
303
|
-
});
|
|
304
|
-
case void 0:
|
|
305
|
-
default: return withReflectionTags(reflection, {
|
|
306
|
-
name: reflection.typeName,
|
|
307
|
-
description: reflection.description,
|
|
308
|
-
...objectReflectionToJsonSchema(reflection)
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
case ReflectionKind.symbol:
|
|
312
|
-
case ReflectionKind.property:
|
|
313
|
-
case ReflectionKind.method:
|
|
314
|
-
case ReflectionKind.function:
|
|
315
|
-
case ReflectionKind.parameter:
|
|
316
|
-
case ReflectionKind.typeParameter:
|
|
317
|
-
case ReflectionKind.tupleMember:
|
|
318
|
-
case ReflectionKind.enumMember:
|
|
319
|
-
case ReflectionKind.rest:
|
|
320
|
-
case ReflectionKind.indexSignature:
|
|
321
|
-
case ReflectionKind.propertySignature:
|
|
322
|
-
case ReflectionKind.methodSignature:
|
|
323
|
-
case ReflectionKind.infer:
|
|
324
|
-
case ReflectionKind.callSignature:
|
|
325
|
-
default: return;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
function mergeObjectSchemas(schemas) {
|
|
329
|
-
const merged = {
|
|
330
|
-
type: "object",
|
|
331
|
-
properties: {},
|
|
332
|
-
required: []
|
|
333
|
-
};
|
|
334
|
-
for (const schema of schemas) {
|
|
335
|
-
if (schema.properties) merged.properties = defu(merged.properties, schema.properties);
|
|
336
|
-
if (schema.required) merged.required = Array.from(new Set([...merged.required ?? [], ...schema.required]));
|
|
337
|
-
if (schema.additionalProperties !== void 0) merged.additionalProperties = schema.additionalProperties;
|
|
338
|
-
}
|
|
339
|
-
if ((merged.required?.length ?? 0) === 0) delete merged.required;
|
|
340
|
-
return merged;
|
|
341
|
-
}
|
|
342
|
-
function tryReflectionDiscriminator(types) {
|
|
343
|
-
const nonNullTypes = types.filter((t) => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined);
|
|
344
|
-
const objectBranches = nonNullTypes.filter((t) => t.kind === ReflectionKind.objectLiteral || t.kind === ReflectionKind.class);
|
|
345
|
-
if (objectBranches.length < 2 || objectBranches.length !== nonNullTypes.length) return;
|
|
346
|
-
let tagKey;
|
|
347
|
-
const branches = [];
|
|
348
|
-
for (const branch of objectBranches) {
|
|
349
|
-
const literalProps = [];
|
|
350
|
-
for (const member of branch.types) if ((member.kind === ReflectionKind.property || member.kind === ReflectionKind.propertySignature) && typeof member.name === "string" && member.type.kind === ReflectionKind.literal && typeof member.type.literal === "string") literalProps.push({
|
|
351
|
-
name: member.name,
|
|
352
|
-
literal: member.type.literal
|
|
353
|
-
});
|
|
354
|
-
if (literalProps.length === 0) return;
|
|
355
|
-
const first = literalProps[0];
|
|
356
|
-
if (!tagKey) tagKey = first.name;
|
|
357
|
-
else if (tagKey !== first.name) return;
|
|
358
|
-
const body = objectReflectionToJsonSchema({
|
|
359
|
-
...branch,
|
|
360
|
-
types: branch.types.filter((member) => !((member.kind === ReflectionKind.property || member.kind === ReflectionKind.propertySignature) && member.name === tagKey))
|
|
361
|
-
});
|
|
362
|
-
if (!body || !isJsonSchemaObject(body)) return;
|
|
363
|
-
branches.push({
|
|
364
|
-
type: "object",
|
|
365
|
-
properties: {
|
|
366
|
-
[tagKey]: { const: first.literal },
|
|
367
|
-
...body.properties ?? {}
|
|
368
|
-
},
|
|
369
|
-
required: [tagKey, ...body.required ?? []],
|
|
370
|
-
additionalProperties: body.additionalProperties ?? false
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
if (!tagKey) return;
|
|
374
|
-
return {
|
|
375
|
-
oneOf: branches,
|
|
376
|
-
discriminator: { propertyName: tagKey }
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
function objectReflectionToJsonSchema(type) {
|
|
380
|
-
const reflection = ReflectionClass.from(type);
|
|
381
|
-
const schema = {
|
|
382
|
-
type: "object",
|
|
383
|
-
name: reflection.getName(),
|
|
384
|
-
description: reflection.getDescription(),
|
|
385
|
-
properties: {},
|
|
386
|
-
required: [],
|
|
387
|
-
readOnly: reflection.isReadonly(),
|
|
388
|
-
ignore: reflection.isIgnored(),
|
|
389
|
-
internal: reflection.isInternal(),
|
|
390
|
-
runtime: reflection.isRuntime(),
|
|
391
|
-
hidden: reflection.isHidden(),
|
|
392
|
-
primaryKey: reflection.getPrimaries().map((primary) => primary.getNameAsString()),
|
|
393
|
-
...isSetString(reflection.databaseSchemaName) ? { databaseSchemaName: reflection.databaseSchemaName } : {},
|
|
394
|
-
...isSetString(reflection.getName()) ? { name: reflection.getName() } : {},
|
|
395
|
-
...isSetString(reflection.getDescription()) ? { description: reflection.getDescription() } : {},
|
|
396
|
-
...isSetArray(reflection.getAlias()) ? { alias: reflection.getAlias() } : {},
|
|
397
|
-
...isSetString(reflection.getTitle()) ? { title: reflection.getTitle() } : {}
|
|
398
|
-
};
|
|
399
|
-
for (const propertyReflection of reflection.getProperties()) {
|
|
400
|
-
if (propertyReflection.getKind() === ReflectionKind.indexSignature) {
|
|
401
|
-
schema.additionalProperties = reflectionToJsonSchemaInner(propertyReflection.type) ?? true;
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
let property = reflectionToJsonSchemaInner(propertyReflection.type);
|
|
405
|
-
if (!property) continue;
|
|
406
|
-
property = {
|
|
407
|
-
...isSetObject(property) ? property : {},
|
|
408
|
-
name: propertyReflection.getNameAsString(),
|
|
409
|
-
description: propertyReflection.getDescription(),
|
|
410
|
-
readOnly: propertyReflection.isReadonly(),
|
|
411
|
-
ignore: propertyReflection.isIgnored(),
|
|
412
|
-
internal: propertyReflection.isInternal(),
|
|
413
|
-
runtime: propertyReflection.isRuntime(),
|
|
414
|
-
hidden: propertyReflection.isHidden(),
|
|
415
|
-
...propertyReflection.hasDefault() ? { default: propertyReflection.getDefaultValue() } : {},
|
|
416
|
-
...isSetArray(propertyReflection.getGroups()) ? { tags: propertyReflection.getGroups() } : {},
|
|
417
|
-
...isSetArray(propertyReflection.getAlias()) ? { alias: propertyReflection.getAlias() } : {},
|
|
418
|
-
...isSetString(propertyReflection.getTitle()) ? { title: propertyReflection.getTitle() } : {}
|
|
419
|
-
};
|
|
420
|
-
if (propertyReflection.isNullable()) property = withNullable(property);
|
|
421
|
-
schema.properties ??= {};
|
|
422
|
-
schema.properties[propertyReflection.name] = property;
|
|
423
|
-
if (!propertyReflection.isOptional()) {
|
|
424
|
-
schema.required ??= [];
|
|
425
|
-
schema.required.push(propertyReflection.name);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return schema;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
//#endregion
|
|
432
|
-
export { reflectionToJsonSchema };
|
|
433
|
-
//# sourceMappingURL=reflection.mjs.map
|
package/dist/reflection.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reflection.mjs","names":[],"sources":["../src/reflection.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n TagsReflection,\n Type,\n TypeClass\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionClass,\n ReflectionKind,\n TypeNumberBrand,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n isBigInt,\n isBoolean,\n isInteger,\n isNull,\n isNumber,\n isRegExp,\n isSetArray,\n isSetObject,\n isSetString,\n isString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { getJsonSchemaType } from \"./codegen\";\nimport {\n isJsonSchemaObject,\n isJsonSchemaPrimitiveType,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaNullable,\n JsonSchemaObject,\n JsonSchemaPrimitiveType\n} from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.\n *\n * @remarks\n * This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.\n *\n * @param brand - The Deepkit numeric brand to convert.\n * @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.\n */\nfunction numberBrandToJsonSchema(\n brand: TypeNumberBrand | undefined\n): JsonSchema {\n switch (brand) {\n case TypeNumberBrand.integer:\n return {\n type: \"integer\",\n format: \"int32\",\n multipleOf: 1\n };\n case TypeNumberBrand.int8:\n return { type: \"integer\", format: \"int8\", multipleOf: 1 };\n case TypeNumberBrand.uint8:\n return { type: \"integer\", format: \"uint8\", multipleOf: 1 };\n case TypeNumberBrand.int16:\n return { type: \"integer\", format: \"int16\", multipleOf: 1 };\n case TypeNumberBrand.uint16:\n return { type: \"integer\", format: \"uint16\", multipleOf: 1 };\n case TypeNumberBrand.int32:\n return { type: \"integer\", format: \"int32\", multipleOf: 1 };\n case TypeNumberBrand.uint32:\n return { type: \"integer\", format: \"uint32\", multipleOf: 1 };\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return { type: \"number\", format: \"float\" };\n case TypeNumberBrand.float64:\n return { type: \"number\", format: \"double\" };\n case undefined:\n default:\n return { type: \"number\" };\n }\n}\n\nfunction withReflectionTags(reflection: Type, schema: JsonSchema): JsonSchema {\n if (\n !isSetObject(schema) ||\n !isSetObject((reflection as { tags?: TagsReflection })?.tags)\n ) {\n return schema;\n }\n\n const updatedSchema = { ...schema };\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n updatedSchema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n updatedSchema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n updatedSchema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n updatedSchema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n updatedSchema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n updatedSchema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n updatedSchema.readOnly = tags.readonly;\n }\n\n return updatedSchema;\n}\n\nfunction withNullable(schema: JsonSchema): JsonSchemaNullable {\n if (!isSetObject(schema)) {\n return {\n anyOf: [schema, { type: \"null\", default: null }]\n };\n }\n\n const rawType = (schema as { type?: string | readonly string[] }).type;\n\n const types = Array.isArray(rawType)\n ? [...rawType]\n : rawType\n ? [rawType]\n : [];\n if (!types.includes(\"null\")) {\n types.push(\"null\");\n }\n\n return {\n ...schema,\n type: types.length === 1 ? types[0] : types\n };\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema(\n reflection: Type\n): JsonSchema | undefined {\n return reflectionToJsonSchemaInner(reflection);\n}\n\nfunction reflectionToJsonSchemaInner(reflection: Type): JsonSchema | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags(reflection, {\n type: \"null\",\n name: reflection.typeName,\n default: null\n });\n case ReflectionKind.string:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags(reflection, numeric);\n }\n case ReflectionKind.bigint:\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\"\n });\n case ReflectionKind.regexp:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n contentMediaType: \"text/regex\"\n });\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (isBigInt(literal)) {\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n const: literal\n });\n }\n\n if (isRegExp(literal)) {\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n\n return withReflectionTags(reflection, {\n type: getJsonSchemaType(literal),\n name: reflection.typeName,\n const: literal\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n isString(value) ||\n isInteger(value) ||\n isBigInt(value) ||\n isNumber(value) ||\n isBoolean(value) ||\n isNull(value)\n ) as (string | number | bigint | boolean | null)[];\n if (values.length === 0) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: []\n });\n }\n\n return withReflectionTags(reflection, {\n type: values.every(value => isString(value))\n ? \"string\"\n : values.every(value => isInteger(value) || isBigInt(value))\n ? \"integer\"\n : values.every(value => isNumber(value))\n ? \"number\"\n : values.every(value => isBoolean(value))\n ? \"boolean\"\n : values.every(value => isNull(value))\n ? \"null\"\n : values.reduce((ret, value) => {\n const type = getJsonSchemaType(value);\n if (\n isJsonSchemaPrimitiveType(type) &&\n !ret.includes(type)\n ) {\n ret.push(type);\n }\n\n return ret;\n }, [] as JsonSchemaPrimitiveType[]),\n name: reflection.typeName,\n description: reflection.description,\n enum: values,\n default: values.length === 1 ? values[0] : undefined\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner(reflection.type);\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items ?? {}\n });\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchemaInner(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items.length === 1 ? items[0] : {}\n });\n }\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n prefixItems: items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((branch): branch is JsonSchema => branch !== undefined);\n if (\n !reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n )\n ) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: branches\n });\n }\n\n const nonNull = branches.filter(branch => !isNullOnlyJsonSchema(branch));\n if (nonNull.length === 0) {\n return withReflectionTags(reflection, {\n type: \"null\",\n default: null\n });\n }\n\n if (nonNull.length === 1) {\n const first = nonNull[0]!;\n\n if (!isSetObject(first)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: [first]\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(first as Record<string, unknown>)\n })\n );\n }\n\n const enumValues = nonNull\n .map(branch =>\n isSetObject(branch)\n ? (branch as { const?: unknown }).const\n : undefined\n )\n .filter(\n (value): value is string | number | bigint | boolean | null =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n typeof value === \"boolean\"\n );\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n enum: enumValues\n })\n );\n }\n\n const discriminator = tryReflectionDiscriminator(reflection.types);\n if (discriminator && isSetObject(discriminator)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(discriminator as Record<string, unknown>)\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n })\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n if (!isSetObject(members[0])) {\n return members[0];\n }\n\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner(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 withReflectionTags(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner(itemType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"array\",\n items: items ?? {},\n uniqueItems: true\n });\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJsonSchemaInner(valueType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"object\",\n additionalProperties: values ?? true\n });\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 withReflectionTags(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n ...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\nfunction mergeObjectSchemas(schemas: JsonSchemaObject[]): JsonSchemaObject {\n const merged: JsonSchemaObject = {\n type: \"object\",\n properties: {},\n required: []\n };\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = defu(merged.properties, schema.properties);\n }\n if (schema.required) {\n merged.required = Array.from(\n new Set([...(merged.required ?? []), ...schema.required])\n );\n }\n if (schema.additionalProperties !== undefined) {\n merged.additionalProperties = schema.additionalProperties;\n }\n }\n\n if ((merged.required?.length ?? 0) === 0) {\n delete merged.required;\n }\n\n return merged;\n}\n\nfunction tryReflectionDiscriminator(\n types: readonly Type[]\n): JsonSchema | undefined {\n const nonNullTypes = types.filter(\n t => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined\n );\n const objectBranches: Array<TypeObjectLiteral | TypeClass> =\n nonNullTypes.filter(\n t =>\n t.kind === ReflectionKind.objectLiteral ||\n t.kind === ReflectionKind.class\n );\n\n if (\n objectBranches.length < 2 ||\n objectBranches.length !== nonNullTypes.length\n ) {\n return undefined;\n }\n\n let tagKey: string | undefined;\n const branches: JsonSchemaObject[] = [];\n\n for (const branch of objectBranches) {\n const literalProps: Array<{ name: string; literal: string }> = [];\n for (const member of branch.types) {\n if (\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n typeof member.name === \"string\" &&\n member.type.kind === ReflectionKind.literal &&\n typeof (member.type as { literal?: unknown }).literal === \"string\"\n ) {\n literalProps.push({\n name: member.name,\n literal: (member.type as { literal: string }).literal\n });\n }\n }\n\n if (literalProps.length === 0) {\n return undefined;\n }\n\n const first = literalProps[0]!;\n if (!tagKey) {\n tagKey = first.name;\n } else if (tagKey !== first.name) {\n return undefined;\n }\n\n const filteredBranch = {\n ...branch,\n types: branch.types.filter(\n member =>\n !(\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n member.name === tagKey\n )\n )\n } as TypeObjectLiteral | TypeClass;\n\n const body = objectReflectionToJsonSchema(filteredBranch);\n if (!body || !isJsonSchemaObject(body)) {\n return undefined;\n }\n\n branches.push({\n type: \"object\",\n properties: {\n [tagKey]: { const: first.literal },\n ...(body.properties ?? {})\n },\n required: [tagKey, ...(body.required ?? [])],\n additionalProperties: body.additionalProperties ?? false\n });\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema;\n}\n\nfunction objectReflectionToJsonSchema(\n type: TypeObjectLiteral | TypeClass\n): JsonSchemaObject {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject = {\n type: \"object\",\n name: reflection.getName(),\n description: reflection.getDescription(),\n properties: {},\n required: [],\n readOnly: reflection.isReadonly(),\n ignore: reflection.isIgnored(),\n internal: reflection.isInternal(),\n runtime: reflection.isRuntime(),\n hidden: reflection.isHidden(),\n primaryKey: reflection\n .getPrimaries()\n .map(primary => primary.getNameAsString()),\n ...(isSetString(reflection.databaseSchemaName)\n ? { databaseSchemaName: reflection.databaseSchemaName }\n : {}),\n ...(isSetString(reflection.getName())\n ? { name: reflection.getName() }\n : {}),\n ...(isSetString(reflection.getDescription())\n ? { description: reflection.getDescription() }\n : {}),\n ...(isSetArray(reflection.getAlias())\n ? { alias: reflection.getAlias() }\n : {}),\n ...(isSetString(reflection.getTitle())\n ? { title: reflection.getTitle() }\n : {})\n };\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n schema.additionalProperties =\n reflectionToJsonSchemaInner(propertyReflection.type) ?? true;\n continue;\n }\n\n let property = reflectionToJsonSchemaInner(\n propertyReflection.type\n ) as JsonSchema;\n if (!property) {\n continue;\n }\n\n const propertySchema = isSetObject(property) ? property : {};\n\n property = {\n ...propertySchema,\n name: propertyReflection.getNameAsString(),\n description: propertyReflection.getDescription(),\n readOnly: propertyReflection.isReadonly(),\n ignore: propertyReflection.isIgnored(),\n internal: propertyReflection.isInternal(),\n runtime: propertyReflection.isRuntime(),\n hidden: propertyReflection.isHidden(),\n ...(propertyReflection.hasDefault()\n ? { default: propertyReflection.getDefaultValue() }\n : {}),\n ...(isSetArray(propertyReflection.getGroups())\n ? { tags: propertyReflection.getGroups() }\n : {}),\n ...(isSetArray(propertyReflection.getAlias())\n ? { alias: propertyReflection.getAlias() }\n : {}),\n ...(isSetString(propertyReflection.getTitle())\n ? { title: propertyReflection.getTitle() }\n : {})\n };\n\n if (propertyReflection.isNullable()) {\n property = withNullable(property);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] = property;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAS,wBACP,OACY;CACZ,QAAQ,OAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;GACL,MAAM;GACN,QAAQ;GACR,YAAY;EACd;EACF,KAAK,gBAAgB,MACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAQ,YAAY;EAAE;EAC1D,KAAK,gBAAgB,OACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAS,YAAY;EAAE;EAC3D,KAAK,gBAAgB,OACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAS,YAAY;EAAE;EAC3D,KAAK,gBAAgB,QACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAU,YAAY;EAA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;GACxC,QAAQ,mBAAmB,UAAU;GACrC,UAAU,mBAAmB,WAAW;GACxC,SAAS,mBAAmB,UAAU;GACtC,QAAQ,mBAAmB,SAAS;GACpC,GAAI,mBAAmB,WAAW,IAC9B,EAAE,SAAS,mBAAmB,gBAAgB,EAAE,IAChD,CAAC;GACL,GAAI,WAAW,mBAAmB,UAAU,CAAC,IACzC,EAAE,MAAM,mBAAmB,UAAU,EAAE,IACvC,CAAC;GACL,GAAI,WAAW,mBAAmB,SAAS,CAAC,IACxC,EAAE,OAAO,mBAAmB,SAAS,EAAE,IACvC,CAAC;GACL,GAAI,YAAY,mBAAmB,SAAS,CAAC,IACzC,EAAE,OAAO,mBAAmB,SAAS,EAAE,IACvC,CAAC;EACP;EAEA,IAAI,mBAAmB,WAAW,GAChC,WAAW,aAAa,QAAQ;EAGlC,OAAO,eAAe,CAAC;EACvB,OAAO,WAAW,mBAAmB,QAAQ;EAC7C,IAAI,CAAC,mBAAmB,WAAW,GAAG;GACpC,OAAO,aAAa,CAAC;GACrB,OAAO,SAAS,KAAK,mBAAmB,IAAI;EAC9C;CACF;CAEA,OAAO;AACT"}
|
package/dist/resolve.cjs
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import __tsdown_shims_path from 'node:path'
|
|
4
|
-
import __tsdown_shims_url from 'node:url'
|
|
5
|
-
|
|
6
|
-
const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
|
|
7
|
-
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
|
-
|
|
9
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
10
|
-
const require_bundle = require('./bundle.cjs');
|
|
11
|
-
let defu = require("defu");
|
|
12
|
-
defu = require_runtime.__toESM(defu, 1);
|
|
13
|
-
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
14
|
-
let _stryke_path_find = require("@stryke/path/find");
|
|
15
|
-
let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
|
|
16
|
-
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
17
|
-
let _stryke_convert_extract_file_reference = require("@stryke/convert/extract-file-reference");
|
|
18
|
-
let smol_toml = require("smol-toml");
|
|
19
|
-
let yaml = require("yaml");
|
|
20
|
-
|
|
21
|
-
//#region src/resolve.ts
|
|
22
|
-
/**
|
|
23
|
-
* Compiles a type definition to a module and returns the module.
|
|
24
|
-
*
|
|
25
|
-
* @param context - The context object containing the environment paths.
|
|
26
|
-
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
27
|
-
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
28
|
-
* @returns A promise that resolves to the compiled module.
|
|
29
|
-
*/
|
|
30
|
-
async function resolveModule(context, input, overrides) {
|
|
31
|
-
const fileReference = (0, _stryke_convert_extract_file_reference.extractFileReference)(input);
|
|
32
|
-
if (!fileReference) throw new Error(`Failed to extract a file reference from the provided input ${JSON.stringify(input)}. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);
|
|
33
|
-
const result = await require_bundle.bundle(context, fileReference.file, overrides);
|
|
34
|
-
let resolved;
|
|
35
|
-
try {
|
|
36
|
-
resolved = await context.resolver.evalModule(result.text, {
|
|
37
|
-
filename: result.path,
|
|
38
|
-
ext: (0, _stryke_path_find.findFileDotExtension)(result.path)
|
|
39
|
-
});
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(error.message) && new RegExp(`Cannot find module '${context.config.framework?.name || "powerlines"}:.*'`).test(error.message)) {
|
|
42
|
-
const moduleName = error.message.match(new RegExp(`Cannot find module '(${context.config.framework?.name || "powerlines"}:.*)'`))?.[1];
|
|
43
|
-
throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${fileReference.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" ? `
|
|
44
|
-
|
|
45
|
-
Bundle output for module:
|
|
46
|
-
${result.text}` : ""}`);
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`Failed to evaluate the bundled module for "${fileReference.file}". Error: ${error.message}${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
|
|
49
|
-
|
|
50
|
-
Bundle output for module:
|
|
51
|
-
${result.text}` : ""}`);
|
|
52
|
-
}
|
|
53
|
-
return resolved;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Compiles a type definition to a module and returns the specified export from the module.
|
|
57
|
-
*
|
|
58
|
-
* @param context - The context object containing the environment paths.
|
|
59
|
-
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
60
|
-
* @param options - Optional overrides for the ESBuild configuration.
|
|
61
|
-
* @returns A promise that resolves to the compiled module.
|
|
62
|
-
*/
|
|
63
|
-
async function resolve(context, input, options) {
|
|
64
|
-
const fileReference = (0, _stryke_convert_extract_file_reference.extractFileReference)(input);
|
|
65
|
-
if (!fileReference) throw new Error(`Failed to extract a file reference from the provided input. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);
|
|
66
|
-
const extension = (0, _stryke_path_find.findFileExtensionSafe)(fileReference.file);
|
|
67
|
-
if (extension.startsWith("json")) try {
|
|
68
|
-
const json = await context.fs.read(fileReference.file);
|
|
69
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(json)) throw new Error(`The file at "${fileReference.file}" could not be read as a string. Please ensure the file exists and contains valid JSON.`);
|
|
70
|
-
return JSON.parse(json);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
throw new Error(`Failed to read or parse the JSON file at "${fileReference.file}". Please ensure the file exists and contains valid JSON. Error: ${error.message}`);
|
|
73
|
-
}
|
|
74
|
-
else if (extension === "yaml" || extension === "yml") try {
|
|
75
|
-
const yaml$1 = await context.fs.read(fileReference.file);
|
|
76
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(yaml$1)) throw new Error(`The file at "${fileReference.file}" could not be read as a string. Please ensure the file exists and contains valid YAML.`);
|
|
77
|
-
return (0, yaml.parse)(yaml$1);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw new Error(`Failed to read or parse the YAML file at "${fileReference.file}". Please ensure the file exists and contains valid YAML. Error: ${error.message}`);
|
|
80
|
-
}
|
|
81
|
-
else if (extension === "toml") try {
|
|
82
|
-
const toml = await context.fs.read(fileReference.file);
|
|
83
|
-
if (!(0, _stryke_type_checks_is_set_string.isSetString)(toml)) throw new Error(`The file at "${fileReference.file}" could not be read as a string. Please ensure the file exists and contains valid TOML.`);
|
|
84
|
-
return (0, smol_toml.parse)(toml);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
throw new Error(`Failed to read or parse the TOML file at "${fileReference.file}". Please ensure the file exists and contains valid TOML. Error: ${error.message}`);
|
|
87
|
-
}
|
|
88
|
-
const resolved = await resolveModule(context, fileReference, options);
|
|
89
|
-
let exportName = fileReference.export;
|
|
90
|
-
if (!exportName) exportName = "default";
|
|
91
|
-
const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];
|
|
92
|
-
if (resolvedExport === void 0) throw new Error(`The export "${exportName}" could not be resolved in the "${fileReference.file}" module. ${Object.keys(resolved).length === 0 ? `After bundling, no exports were found in the module. Please ensure that the "${fileReference.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.`}`);
|
|
93
|
-
return resolvedExport;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 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.
|
|
97
|
-
*
|
|
98
|
-
* @param context - The context object containing the environment paths.
|
|
99
|
-
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
100
|
-
* @param options - Optional overrides for the ESBuild configuration.
|
|
101
|
-
* @returns A promise that resolves to the Deepkit Type reflection.
|
|
102
|
-
*/
|
|
103
|
-
async function resolveReflection(context, input, options) {
|
|
104
|
-
return (0, _powerlines_deepkit_vendor_type.reflect)(await resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
|
|
105
|
-
reflection: "default",
|
|
106
|
-
level: "all"
|
|
107
|
-
})] })));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
111
|
-
exports.resolve = resolve;
|
|
112
|
-
exports.resolveModule = resolveModule;
|
|
113
|
-
exports.resolveReflection = resolveReflection;
|
package/dist/resolve.d.cts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { BundleOptions } from "./bundle.cjs";
|
|
2
|
-
import { PluginContext, UnresolvedContext } from "@powerlines/core";
|
|
3
|
-
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
4
|
-
import { FileReference, FileReferenceInput } 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 input - The type definition to compile. This can be either a string or a {@link FileReference} 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 UnresolvedContext = UnresolvedContext>(context: TContext, input: FileReferenceInput, 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 FileReference} 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 UnresolvedContext = UnresolvedContext>(context: TContext, input: FileReferenceInput, 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 FileReference} 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: FileReference, options?: BundleOptions): Promise<Type>;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { resolve, resolveModule, resolveReflection };
|
|
36
|
-
//# sourceMappingURL=resolve.d.cts.map
|
package/dist/resolve.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,EAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;;;;;;;;iBAuEW,OAAA,2BAEH,iBAAA,GAAoB,iBAAA,EAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;;;iBAiGW,iBAAA,kBACH,aAAA,GAAgB,aAAA,EAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,aAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,IAAA"}
|