@powerlines/schema 0.11.44 → 0.11.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +1 -1
- package/dist/bundle.d.cts +1 -1
- package/dist/bundle.d.mts +1 -1
- package/dist/bundle.mjs +1 -1
- package/dist/bundle.mjs.map +1 -1
- package/dist/codegen.cjs +28 -22
- package/dist/codegen.d.cts +11 -11
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +11 -11
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +36 -30
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +15 -11
- package/dist/constants.d.cts +4 -3
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +4 -3
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +13 -10
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +158 -20
- package/dist/extract.d.cts +55 -16
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +55 -16
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +158 -22
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +43 -8
- package/dist/helpers.d.cts +40 -6
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +40 -6
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +43 -10
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +39 -7
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +7 -7
- package/dist/metadata.cjs +9 -35
- package/dist/metadata.d.cts +5 -26
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts +5 -26
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +9 -33
- package/dist/metadata.mjs.map +1 -1
- package/dist/persistence.d.cts +4 -4
- package/dist/persistence.d.cts.map +1 -1
- package/dist/persistence.d.mts +4 -4
- package/dist/persistence.d.mts.map +1 -1
- package/dist/persistence.mjs.map +1 -1
- package/dist/reflection.cjs +72 -50
- package/dist/reflection.d.cts +1 -1
- package/dist/reflection.d.cts.map +1 -1
- package/dist/reflection.d.mts +1 -1
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +74 -52
- package/dist/reflection.mjs.map +1 -1
- package/dist/resolve.cjs +2 -2
- package/dist/resolve.mjs +2 -2
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +363 -83
- package/dist/type-checks.d.cts +138 -16
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +138 -16
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +336 -85
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +901 -176
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +901 -176
- package/dist/types.d.mts.map +1 -1
- package/dist/validate.mjs.map +1 -1
- package/package.json +5 -5
package/dist/reflection.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isJsonSchemaObject, isJsonSchemaPrimitiveType, isNullOnlyJsonSchema } from "./type-checks.mjs";
|
|
2
|
+
import { getJsonSchemaType } from "./codegen.mjs";
|
|
2
3
|
import defu from "defu";
|
|
3
|
-
import { isSetArray, isSetObject, isSetString, isUndefined } from "@stryke/type-checks";
|
|
4
|
+
import { isBigInt, isBoolean, isInteger, isNull, isNumber, isRegExp, isSetArray, isSetObject, isSetString, isString, isUndefined } from "@stryke/type-checks";
|
|
4
5
|
import { ReflectionClass, ReflectionKind, TypeNumberBrand } from "@powerlines/deepkit/vendor/type";
|
|
5
6
|
|
|
6
7
|
//#region src/reflection.ts
|
|
@@ -64,20 +65,25 @@ function numberBrandToJsonSchema(brand) {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
function withReflectionTags(reflection, schema) {
|
|
67
|
-
if (!isSetObject(reflection?.tags)) return schema;
|
|
68
|
+
if (!isSetObject(schema) || !isSetObject(reflection?.tags)) return schema;
|
|
69
|
+
const updatedSchema = { ...schema };
|
|
68
70
|
const tags = reflection.tags;
|
|
69
|
-
if (isSetString(tags.title))
|
|
70
|
-
if (isSetArray(tags.alias))
|
|
71
|
-
if (!isUndefined(tags.hidden))
|
|
72
|
-
if (!isUndefined(tags.ignore))
|
|
73
|
-
if (!isUndefined(tags.internal))
|
|
74
|
-
if (!isUndefined(tags.runtime))
|
|
75
|
-
if (!isUndefined(tags.readonly))
|
|
76
|
-
return
|
|
71
|
+
if (isSetString(tags.title)) updatedSchema.title = tags.title;
|
|
72
|
+
if (isSetArray(tags.alias)) updatedSchema.alias = tags.alias;
|
|
73
|
+
if (!isUndefined(tags.hidden)) updatedSchema.hidden = tags.hidden;
|
|
74
|
+
if (!isUndefined(tags.ignore)) updatedSchema.ignore = tags.ignore;
|
|
75
|
+
if (!isUndefined(tags.internal)) updatedSchema.internal = tags.internal;
|
|
76
|
+
if (!isUndefined(tags.runtime)) updatedSchema.runtime = tags.runtime;
|
|
77
|
+
if (!isUndefined(tags.readonly)) updatedSchema.readOnly = tags.readonly;
|
|
78
|
+
return updatedSchema;
|
|
77
79
|
}
|
|
78
|
-
function withNullable(schema
|
|
79
|
-
if (!
|
|
80
|
-
|
|
80
|
+
function withNullable(schema) {
|
|
81
|
+
if (!isSetObject(schema)) return { anyOf: [schema, {
|
|
82
|
+
type: "null",
|
|
83
|
+
default: null
|
|
84
|
+
}] };
|
|
85
|
+
const rawType = schema.type;
|
|
86
|
+
const types = Array.isArray(rawType) ? [...rawType] : rawType ? [rawType] : [];
|
|
81
87
|
if (!types.includes("null")) types.push("null");
|
|
82
88
|
return {
|
|
83
89
|
...schema,
|
|
@@ -101,7 +107,7 @@ function reflectionToJsonSchemaInner(reflection) {
|
|
|
101
107
|
case ReflectionKind.null: return withReflectionTags(reflection, {
|
|
102
108
|
type: "null",
|
|
103
109
|
name: reflection.typeName,
|
|
104
|
-
|
|
110
|
+
default: null
|
|
105
111
|
});
|
|
106
112
|
case ReflectionKind.string: return withReflectionTags(reflection, {
|
|
107
113
|
type: "string",
|
|
@@ -115,8 +121,7 @@ function reflectionToJsonSchemaInner(reflection) {
|
|
|
115
121
|
case ReflectionKind.bigint: return withReflectionTags(reflection, {
|
|
116
122
|
type: "integer",
|
|
117
123
|
name: reflection.typeName,
|
|
118
|
-
format: "int64"
|
|
119
|
-
multipleOf: 1
|
|
124
|
+
format: "int64"
|
|
120
125
|
});
|
|
121
126
|
case ReflectionKind.regexp: return withReflectionTags(reflection, {
|
|
122
127
|
type: "string",
|
|
@@ -126,37 +131,42 @@ function reflectionToJsonSchemaInner(reflection) {
|
|
|
126
131
|
});
|
|
127
132
|
case ReflectionKind.literal: {
|
|
128
133
|
const { literal } = reflection;
|
|
129
|
-
if (
|
|
130
|
-
type: typeof literal,
|
|
131
|
-
name: reflection.typeName,
|
|
132
|
-
const: literal
|
|
133
|
-
});
|
|
134
|
-
if (typeof literal === "bigint") return withReflectionTags(reflection, {
|
|
134
|
+
if (isBigInt(literal)) return withReflectionTags(reflection, {
|
|
135
135
|
type: "integer",
|
|
136
136
|
name: reflection.typeName,
|
|
137
137
|
format: "int64",
|
|
138
|
-
|
|
139
|
-
const: String(literal)
|
|
138
|
+
const: literal
|
|
140
139
|
});
|
|
141
|
-
if (literal
|
|
140
|
+
if (isRegExp(literal)) return withReflectionTags(reflection, {
|
|
142
141
|
type: "string",
|
|
143
142
|
name: reflection.typeName,
|
|
144
143
|
format: "regex",
|
|
145
144
|
const: literal.source
|
|
146
145
|
});
|
|
147
|
-
return withReflectionTags(reflection, {
|
|
146
|
+
return withReflectionTags(reflection, {
|
|
147
|
+
type: getJsonSchemaType(literal),
|
|
148
|
+
name: reflection.typeName,
|
|
149
|
+
const: literal
|
|
150
|
+
});
|
|
148
151
|
}
|
|
149
152
|
case ReflectionKind.templateLiteral: return withReflectionTags(reflection, { type: "string" });
|
|
150
153
|
case ReflectionKind.enum: {
|
|
151
|
-
const values = reflection.values.filter((value) =>
|
|
154
|
+
const values = reflection.values.filter((value) => isString(value) || isInteger(value) || isBigInt(value) || isNumber(value) || isBoolean(value) || isNull(value));
|
|
152
155
|
if (values.length === 0) return withReflectionTags(reflection, {
|
|
153
156
|
name: reflection.typeName,
|
|
154
|
-
description: reflection.description
|
|
157
|
+
description: reflection.description,
|
|
158
|
+
enum: []
|
|
155
159
|
});
|
|
156
160
|
return withReflectionTags(reflection, {
|
|
161
|
+
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) => {
|
|
162
|
+
const type = getJsonSchemaType(value);
|
|
163
|
+
if (isJsonSchemaPrimitiveType(type) && !ret.includes(type)) ret.push(type);
|
|
164
|
+
return ret;
|
|
165
|
+
}, []),
|
|
157
166
|
name: reflection.typeName,
|
|
158
167
|
description: reflection.description,
|
|
159
|
-
enum: values
|
|
168
|
+
enum: values,
|
|
169
|
+
default: values.length === 1 ? values[0] : void 0
|
|
160
170
|
});
|
|
161
171
|
}
|
|
162
172
|
case ReflectionKind.array: {
|
|
@@ -172,50 +182,63 @@ function reflectionToJsonSchemaInner(reflection) {
|
|
|
172
182
|
if (items.length <= 1) return withReflectionTags(reflection, {
|
|
173
183
|
type: "array",
|
|
174
184
|
name: reflection.typeName,
|
|
175
|
-
items: items[0]
|
|
185
|
+
items: items.length === 1 ? items[0] : {}
|
|
176
186
|
});
|
|
177
187
|
return withReflectionTags(reflection, {
|
|
178
188
|
type: "array",
|
|
179
189
|
name: reflection.typeName,
|
|
180
|
-
items,
|
|
190
|
+
prefixItems: items,
|
|
181
191
|
minItems: items.length,
|
|
182
192
|
maxItems: items.length
|
|
183
193
|
});
|
|
184
194
|
}
|
|
185
195
|
case ReflectionKind.union: {
|
|
186
|
-
const branches = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter(
|
|
187
|
-
|
|
188
|
-
|
|
196
|
+
const branches = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter((branch) => branch !== void 0);
|
|
197
|
+
if (!reflection.types.some((inner) => inner.kind === ReflectionKind.null || inner.kind === ReflectionKind.undefined)) return withReflectionTags(reflection, {
|
|
198
|
+
name: reflection.typeName,
|
|
199
|
+
anyOf: branches
|
|
200
|
+
});
|
|
201
|
+
const nonNull = branches.filter((branch) => !isNullOnlyJsonSchema(branch));
|
|
189
202
|
if (nonNull.length === 0) return withReflectionTags(reflection, {
|
|
190
203
|
type: "null",
|
|
191
|
-
|
|
204
|
+
default: null
|
|
192
205
|
});
|
|
193
|
-
if (nonNull.length === 1)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
if (nonNull.length === 1) {
|
|
207
|
+
const first = nonNull[0];
|
|
208
|
+
if (!isSetObject(first)) return withNullable(withReflectionTags(reflection, {
|
|
209
|
+
name: reflection.typeName,
|
|
210
|
+
anyOf: [first]
|
|
211
|
+
}));
|
|
212
|
+
return withNullable(withReflectionTags(reflection, {
|
|
213
|
+
name: reflection.typeName,
|
|
214
|
+
...first
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
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");
|
|
198
218
|
if (enumValues.length === nonNull.length) return withNullable(withReflectionTags(reflection, {
|
|
199
219
|
name: reflection.typeName,
|
|
200
220
|
enum: enumValues
|
|
201
|
-
})
|
|
221
|
+
}));
|
|
202
222
|
const discriminator = tryReflectionDiscriminator(reflection.types);
|
|
203
|
-
if (discriminator) return withNullable(withReflectionTags(reflection, {
|
|
223
|
+
if (discriminator && isSetObject(discriminator)) return withNullable(withReflectionTags(reflection, {
|
|
204
224
|
name: reflection.typeName,
|
|
205
225
|
...discriminator
|
|
206
|
-
})
|
|
226
|
+
}));
|
|
207
227
|
return withNullable(withReflectionTags(reflection, {
|
|
208
228
|
name: reflection.typeName,
|
|
209
229
|
anyOf: nonNull
|
|
210
|
-
})
|
|
230
|
+
}));
|
|
211
231
|
}
|
|
212
232
|
case ReflectionKind.intersection: {
|
|
213
233
|
const members = reflection.types.map((inner) => reflectionToJsonSchemaInner(inner)).filter((item) => item !== void 0);
|
|
214
234
|
if (members.length === 0) return;
|
|
215
|
-
if (members.length === 1)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
235
|
+
if (members.length === 1) {
|
|
236
|
+
if (!isSetObject(members[0])) return members[0];
|
|
237
|
+
return withReflectionTags(reflection, {
|
|
238
|
+
name: reflection.typeName,
|
|
239
|
+
...members[0]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
219
242
|
if (members.every(isJsonSchemaObject)) return withReflectionTags(reflection, {
|
|
220
243
|
name: reflection.typeName,
|
|
221
244
|
...mergeObjectSchemas(members)
|
|
@@ -373,7 +396,7 @@ function objectReflectionToJsonSchema(type) {
|
|
|
373
396
|
let property = reflectionToJsonSchemaInner(propertyReflection.type);
|
|
374
397
|
if (!property) continue;
|
|
375
398
|
property = {
|
|
376
|
-
...property,
|
|
399
|
+
...isSetObject(property) ? property : {},
|
|
377
400
|
name: propertyReflection.getNameAsString(),
|
|
378
401
|
description: propertyReflection.getDescription(),
|
|
379
402
|
readOnly: propertyReflection.isReadonly(),
|
|
@@ -381,13 +404,12 @@ function objectReflectionToJsonSchema(type) {
|
|
|
381
404
|
internal: propertyReflection.isInternal(),
|
|
382
405
|
runtime: propertyReflection.isRuntime(),
|
|
383
406
|
hidden: propertyReflection.isHidden(),
|
|
384
|
-
visibility: propertyReflection.isPublic() ? "public" : propertyReflection.isProtected() ? "protected" : propertyReflection.isPrivate() ? "private" : void 0,
|
|
385
407
|
...propertyReflection.hasDefault() ? { default: propertyReflection.getDefaultValue() } : {},
|
|
386
408
|
...isSetArray(propertyReflection.getGroups()) ? { tags: propertyReflection.getGroups() } : {},
|
|
387
409
|
...isSetArray(propertyReflection.getAlias()) ? { alias: propertyReflection.getAlias() } : {},
|
|
388
410
|
...isSetString(propertyReflection.getTitle()) ? { title: propertyReflection.getTitle() } : {}
|
|
389
411
|
};
|
|
390
|
-
if (propertyReflection.isNullable()) property = withNullable(property
|
|
412
|
+
if (propertyReflection.isNullable()) property = withNullable(property);
|
|
391
413
|
schema.properties ??= {};
|
|
392
414
|
schema.properties[propertyReflection.name] = property;
|
|
393
415
|
if (!propertyReflection.isOptional()) {
|
package/dist/reflection.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 isSetArray,\n isSetObject,\n isSetString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaLike,\n JsonSchemaObject,\n JsonSchemaProperty\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<number> {\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<T = unknown>(\n reflection: Type,\n schema: Partial<JsonSchema<T>>\n): JsonSchema<T> {\n if (!isSetObject((reflection as { tags?: TagsReflection })?.tags)) {\n return schema as JsonSchema<T>;\n }\n\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n schema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n schema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n schema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n schema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n schema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n schema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n schema.readOnly = tags.readonly;\n }\n\n return schema as JsonSchema<T>;\n}\n\nfunction withNullable<T = unknown>(\n schema: JsonSchema<T>,\n nullable: boolean\n): JsonSchema<T> {\n if (!nullable) {\n return schema;\n }\n\n const types = Array.isArray(schema.type)\n ? [...schema.type]\n : schema.type\n ? [schema.type]\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 } as JsonSchema<T>;\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema<T = unknown>(\n reflection: Type\n): JsonSchema<T> | undefined {\n return reflectionToJsonSchemaInner<T>(reflection);\n}\n\nfunction reflectionToJsonSchemaInner<T = unknown>(\n reflection: Type\n): JsonSchema<T> | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags<T>(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags<T>(reflection, {\n type: \"null\",\n name: reflection.typeName,\n nullable: true\n });\n case ReflectionKind.string:\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags<T>(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags<T>(reflection, numeric as JsonSchema<T>);\n }\n case ReflectionKind.bigint:\n return withReflectionTags<T>(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n multipleOf: 1\n });\n case ReflectionKind.regexp:\n return withReflectionTags<T>(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 (\n typeof literal === \"string\" ||\n typeof literal === \"number\" ||\n typeof literal === \"boolean\"\n ) {\n return withReflectionTags<T>(reflection, {\n type: typeof literal,\n name: reflection.typeName,\n const: literal\n });\n }\n if (typeof literal === \"bigint\") {\n return withReflectionTags<T>(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n multipleOf: 1,\n const: String(literal)\n });\n }\n if (literal instanceof RegExp) {\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags<T>(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n );\n if (values.length === 0) {\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n description: reflection.description\n });\n }\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: values\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner<T>(reflection.type);\n\n return withReflectionTags<T>(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<T>(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags<T>(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items[0] ?? {}\n });\n }\n return withReflectionTags<T>(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner<T>(inner))\n .filter(isJsonSchema) as JsonSchema<T>[];\n const nullable = reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n );\n const nonNull = branches.filter(\n branch => branch.type !== \"null\" && !isNullOnlyJsonSchema(branch)\n );\n\n if (nonNull.length === 0) {\n return withReflectionTags<T>(reflection, {\n type: \"null\",\n nullable: true\n });\n }\n\n if (nonNull.length === 1) {\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...nonNull[0]\n }),\n nullable\n );\n }\n\n const enumValues = nonNull\n .map(branch => branch.const)\n .filter(value => value !== undefined);\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n enum: enumValues\n }),\n nullable\n );\n }\n\n const discriminator = tryReflectionDiscriminator<T>(reflection.types);\n if (discriminator) {\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...discriminator\n }),\n nullable\n );\n }\n\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n }),\n nullable\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner<T>(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner<T>(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<T>(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner<T>(itemType)\n : undefined;\n\n return withReflectionTags<T>(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<T>(valueType)\n : undefined;\n\n return withReflectionTags<T>(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<T>(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags<T>(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<T = unknown>(\n schemas: JsonSchema<T>[]\n): JsonSchema<T> {\n const merged: JsonSchema<T> = {\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<T = unknown>(\n types: readonly Type[]\n): JsonSchema<T> | 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: JsonSchemaLike[] = [];\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 } as JsonSchemaLike);\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema<T>;\n}\n\nfunction objectReflectionToJsonSchema<\n T extends Record<string, any> = Record<string, any>\n>(type: TypeObjectLiteral | TypeClass): JsonSchema<T> {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject<T> = {\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<any>(propertyReflection.type);\n if (!property) {\n continue;\n }\n\n property = {\n ...property,\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 visibility: propertyReflection.isPublic()\n ? \"public\"\n : propertyReflection.isProtected()\n ? \"protected\"\n : propertyReflection.isPrivate()\n ? \"private\"\n : undefined,\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, true);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] =\n property as JsonSchemaProperty<T>;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyDA,SAAS,wBACP,OACoB;CACpB,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;EAAE;EAC5D,KAAK,gBAAgB,OACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAS,YAAY;EAAE;EAC3D,KAAK,gBAAgB,QACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAU,YAAY;EAAE;EAC5D,KAAK,gBAAgB;EACrB,KAAK,gBAAgB,SACnB,OAAO;GAAE,MAAM;GAAU,QAAQ;EAAQ;EAC3C,KAAK,gBAAgB,SACnB,OAAO;GAAE,MAAM;GAAU,QAAQ;EAAS;EAC5C,KAAK;EACL,SACE,OAAO,EAAE,MAAM,SAAS;CAC5B;AACF;AAEA,SAAS,mBACP,YACA,QACe;CACf,IAAI,CAAC,YAAa,YAA0C,IAAI,GAC9D,OAAO;CAGT,MAAM,OAAQ,WAAwC;CACtD,IAAI,YAAY,KAAK,KAAK,GACxB,OAA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C;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,UAAU,IAAI;EAGxC,OAAO,eAAe,CAAC;EACvB,OAAO,WAAW,mBAAmB,QACnC;EACF,IAAI,CAAC,mBAAmB,WAAW,GAAG;GACpC,OAAO,aAAa,CAAC;GACrB,OAAO,SAAS,KAAK,mBAAmB,IAAI;EAC9C;CACF;CAEA,OAAO;AACT"}
|
|
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,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GACzC,aAAa,mBAAmB,eAAe;GAC/C,UAAU,mBAAmB,WAAW;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
CHANGED
|
@@ -3,8 +3,8 @@ const require_bundle = require('./bundle.cjs');
|
|
|
3
3
|
let defu = require("defu");
|
|
4
4
|
defu = require_runtime.__toESM(defu, 1);
|
|
5
5
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
6
|
+
let _powerlines_deepkit_rolldown_plugin = require("@powerlines/deepkit/rolldown-plugin");
|
|
6
7
|
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
7
|
-
let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
|
|
8
8
|
let _stryke_convert_parse_type_definition = require("@stryke/convert/parse-type-definition");
|
|
9
9
|
let _stryke_path_find = require("@stryke/path/find");
|
|
10
10
|
|
|
@@ -71,7 +71,7 @@ async function resolve(context, input, options) {
|
|
|
71
71
|
* @returns A promise that resolves to the Deepkit Type reflection.
|
|
72
72
|
*/
|
|
73
73
|
async function resolveReflection(context, input, options) {
|
|
74
|
-
return (0, _powerlines_deepkit_vendor_type.reflect)(await resolve(context, input, (0, defu.default)(options, { plugins: [(0,
|
|
74
|
+
return (0, _powerlines_deepkit_vendor_type.reflect)(await resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_rolldown_plugin.rolldownPlugin)(context, {
|
|
75
75
|
reflection: "default",
|
|
76
76
|
level: "all"
|
|
77
77
|
})] })));
|
package/dist/resolve.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { bundle } from "./bundle.mjs";
|
|
2
2
|
import defu from "defu";
|
|
3
3
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
4
|
+
import { rolldownPlugin } from "@powerlines/deepkit/rolldown-plugin";
|
|
4
5
|
import { reflect } from "@powerlines/deepkit/vendor/type";
|
|
5
|
-
import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
|
|
6
6
|
import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
|
|
7
7
|
import { findFileDotExtension } from "@stryke/path/find";
|
|
8
8
|
|
|
@@ -69,7 +69,7 @@ async function resolve(context, input, options) {
|
|
|
69
69
|
* @returns A promise that resolves to the Deepkit Type reflection.
|
|
70
70
|
*/
|
|
71
71
|
async function resolveReflection(context, input, options) {
|
|
72
|
-
return reflect(await resolve(context, input, defu(options, { plugins: [
|
|
72
|
+
return reflect(await resolve(context, input, defu(options, { plugins: [rolldownPlugin(context, {
|
|
73
73
|
reflection: "default",
|
|
74
74
|
level: "all"
|
|
75
75
|
})] })));
|
package/dist/resolve.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":[],"sources":["../src/resolve.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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport {
|
|
1
|
+
{"version":3,"file":"resolve.mjs","names":[],"sources":["../src/resolve.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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { rolldownPlugin } from \"@powerlines/deepkit/rolldown-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { findFileDotExtension } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { bundle, BundleOptions } from \"./bundle\";\nimport { TypeDefinitionReference } from \"./types\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param type - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n type: TypeDefinitionReference,\n overrides?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(type)) {\n typeDefinition = parseTypeDefinition(type) as TypeDefinition;\n } else {\n typeDefinition = type;\n }\n\n const result = await bundle<TContext>(\n context,\n typeDefinition.file,\n overrides\n );\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.code, {\n filename: result.fileName,\n ext: findFileDotExtension(result.fileName)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n typeDefinition.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.code}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n typeDefinition.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.code}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolve<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: TypeDefinitionReference,\n options?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(input)) {\n typeDefinition = parseTypeDefinition(input) as TypeDefinition;\n } else {\n typeDefinition = input;\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n typeDefinition,\n options\n );\n\n let exportName = typeDefinition.name;\n if (!exportName) {\n exportName = \"default\";\n }\n\n const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];\n if (resolvedExport === undefined) {\n throw new Error(\n `The export \"${exportName}\" could not be resolved in the \"${\n typeDefinition.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n typeDefinition.file\n }\" module has a \"${exportName}\" export with the desired value.`\n : `After bundling, the available exports were: ${Object.keys(\n resolved\n ).join(\n \", \"\n )}. Please ensure that the export exists and is correctly named.`\n }`\n );\n }\n\n return resolvedExport;\n}\n\n/**\n * 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.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link TypeDefinition} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the Deepkit Type reflection.\n */\nexport async function resolveReflection<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n input: TypeDefinitionReference,\n options?: BundleOptions\n): Promise<Type> {\n return reflect(\n await resolve<Type>(\n context,\n input,\n defu(options, {\n plugins: [\n rolldownPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n )\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,eAAsB,cAIpB,SACA,MACA,WACkB;CAClB,IAAI;CACJ,IAAI,YAAY,IAAI,GAClB,iBAAiB,oBAAoB,IAAI;MAEzC,iBAAiB;CAGnB,MAAM,SAAS,MAAM,OACnB,SACA,eAAe,MACf,SACF;CAEA,IAAI;CACJ,IAAI;EACF,WAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAAK,qBAAq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