@mirascript/typed 0.1.76 → 0.1.79
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.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/json/impl.d.ts +8 -0
- package/dist/json/impl.d.ts.map +1 -0
- package/dist/json/impl.js +51 -0
- package/dist/json/impl.js.map +1 -0
- package/dist/{json.d.ts → json/index.d.ts} +2 -2
- package/dist/json/index.d.ts.map +1 -0
- package/dist/json/index.js +17 -0
- package/dist/json/index.js.map +1 -0
- package/dist/json/literal.d.ts +9 -0
- package/dist/json/literal.d.ts.map +1 -0
- package/dist/json/literal.js +16 -0
- package/dist/json/literal.js.map +1 -0
- package/dist/json/record.d.ts +6 -0
- package/dist/json/record.d.ts.map +1 -0
- package/dist/json/record.js +66 -0
- package/dist/json/record.js.map +1 -0
- package/dist/json/string.d.ts +5 -0
- package/dist/json/string.d.ts.map +1 -0
- package/dist/json/string.js +28 -0
- package/dist/json/string.js.map +1 -0
- package/dist/json/template.d.ts +8 -0
- package/dist/json/template.d.ts.map +1 -0
- package/dist/json/template.js +72 -0
- package/dist/json/template.js.map +1 -0
- package/dist/json/tuple.d.ts +8 -0
- package/dist/json/tuple.d.ts.map +1 -0
- package/dist/json/tuple.js +52 -0
- package/dist/json/tuple.js.map +1 -0
- package/dist/json/union-intersection.d.ts +8 -0
- package/dist/json/union-intersection.d.ts.map +1 -0
- package/dist/json/union-intersection.js +40 -0
- package/dist/json/union-intersection.js.map +1 -0
- package/dist/simplifier/dedup.d.ts +4 -0
- package/dist/simplifier/dedup.d.ts.map +1 -0
- package/dist/simplifier/dedup.js +61 -0
- package/dist/simplifier/dedup.js.map +1 -0
- package/dist/simplifier/impl.d.ts +7 -0
- package/dist/simplifier/impl.d.ts.map +1 -0
- package/dist/simplifier/impl.js +51 -0
- package/dist/simplifier/impl.js.map +1 -0
- package/dist/{simplifier.d.ts → simplifier/index.d.ts} +3 -5
- package/dist/simplifier/index.d.ts.map +1 -0
- package/dist/simplifier/index.js +22 -0
- package/dist/simplifier/index.js.map +1 -0
- package/dist/simplifier/intersection.d.ts +5 -0
- package/dist/simplifier/intersection.d.ts.map +1 -0
- package/dist/simplifier/intersection.js +126 -0
- package/dist/simplifier/intersection.js.map +1 -0
- package/dist/simplifier/record.d.ts +5 -0
- package/dist/simplifier/record.d.ts.map +1 -0
- package/dist/simplifier/record.js +24 -0
- package/dist/simplifier/record.js.map +1 -0
- package/dist/simplifier/top-type.d.ts +5 -0
- package/dist/simplifier/top-type.d.ts.map +1 -0
- package/dist/simplifier/top-type.js +9 -0
- package/dist/simplifier/top-type.js.map +1 -0
- package/dist/simplifier/tuple.d.ts +5 -0
- package/dist/simplifier/tuple.d.ts.map +1 -0
- package/dist/simplifier/tuple.js +17 -0
- package/dist/simplifier/tuple.js.map +1 -0
- package/dist/simplifier/union.d.ts +5 -0
- package/dist/simplifier/union.d.ts.map +1 -0
- package/dist/simplifier/union.js +47 -0
- package/dist/simplifier/union.js.map +1 -0
- package/dist/simplifier/utils.d.ts +12 -0
- package/dist/simplifier/utils.d.ts.map +1 -0
- package/dist/simplifier/utils.js +17 -0
- package/dist/simplifier/utils.js.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +2 -2
- package/src/json/impl.ts +57 -0
- package/src/json/index.ts +28 -0
- package/src/json/literal.ts +20 -0
- package/src/json/record.ts +70 -0
- package/src/json/string.ts +30 -0
- package/src/json/template.ts +71 -0
- package/src/json/tuple.ts +52 -0
- package/src/json/union-intersection.ts +43 -0
- package/src/simplifier/dedup.ts +61 -0
- package/src/simplifier/impl.ts +64 -0
- package/src/simplifier/index.ts +67 -0
- package/src/simplifier/intersection.ts +129 -0
- package/src/simplifier/record.ts +24 -0
- package/src/simplifier/top-type.ts +9 -0
- package/src/simplifier/tuple.ts +20 -0
- package/src/simplifier/union.ts +45 -0
- package/src/simplifier/utils.ts +21 -0
- package/dist/json.d.ts.map +0 -1
- package/dist/json.js +0 -314
- package/dist/json.js.map +0 -1
- package/dist/simplifier.d.ts.map +0 -1
- package/dist/simplifier.js +0 -332
- package/dist/simplifier.js.map +0 -1
- package/src/json.ts +0 -323
- package/src/simplifier.ts +0 -404
package/dist/simplifier.js
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/** Resolves the top types option into an array of top types. */
|
|
2
|
-
function resolveTopTypes(value) {
|
|
3
|
-
if (value === false || value == null)
|
|
4
|
-
return [];
|
|
5
|
-
if (value === true)
|
|
6
|
-
return ['unknown', 'never', 'any'];
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
const DEFAULT_OPTIONS = {
|
|
10
|
-
flattenUnions: true,
|
|
11
|
-
flattenIntersections: true,
|
|
12
|
-
deduplicateUnions: true,
|
|
13
|
-
deduplicateIntersections: true,
|
|
14
|
-
unwrapSingleUnion: true,
|
|
15
|
-
unwrapSingleIntersection: true,
|
|
16
|
-
distributeIntersectionsOverUnions: true,
|
|
17
|
-
mergeRecordIntersections: true,
|
|
18
|
-
expandTupleSpreads: true,
|
|
19
|
-
simplifyTopTypesInUnions: true,
|
|
20
|
-
simplifyTopTypesInIntersections: true,
|
|
21
|
-
normalizeGenericRecord: true,
|
|
22
|
-
normalizeGenericArray: true,
|
|
23
|
-
};
|
|
24
|
-
/** Fills in default simplification options. */
|
|
25
|
-
function normalizeOptions(options) {
|
|
26
|
-
return { ...DEFAULT_OPTIONS, ...options };
|
|
27
|
-
}
|
|
28
|
-
/** Checks whether a type is represented by an object node. */
|
|
29
|
-
function isTypeObject(type) {
|
|
30
|
-
return typeof type === 'object';
|
|
31
|
-
}
|
|
32
|
-
/** Checks whether a record type uses the explicit fields form. */
|
|
33
|
-
function isFieldRecordType(type) {
|
|
34
|
-
return isTypeObject(type) && type.kind === 'record' && 'fields' in type;
|
|
35
|
-
}
|
|
36
|
-
/** Builds a stable key for type-level deduplication within one simplify call. */
|
|
37
|
-
function getTypeDedupKey(type, symbols) {
|
|
38
|
-
if (typeof type === 'string')
|
|
39
|
-
return `string:${type}`;
|
|
40
|
-
if (typeof type === 'symbol') {
|
|
41
|
-
const existing = symbols.get(type);
|
|
42
|
-
if (existing != null)
|
|
43
|
-
return `symbol:${existing}`;
|
|
44
|
-
const next = symbols.size + 1;
|
|
45
|
-
symbols.set(type, next);
|
|
46
|
-
return `symbol:${next}`;
|
|
47
|
-
}
|
|
48
|
-
switch (type.kind) {
|
|
49
|
-
case 'array':
|
|
50
|
-
return `array:${getTypeDedupKey(type.element, symbols)}`;
|
|
51
|
-
case 'union':
|
|
52
|
-
return `union:[${type.types.map((t) => getTypeDedupKey(t, symbols)).join(',')}]`;
|
|
53
|
-
case 'intersection':
|
|
54
|
-
return `intersection:[${type.types.map((t) => getTypeDedupKey(t, symbols)).join(',')}]`;
|
|
55
|
-
case 'record':
|
|
56
|
-
if ('fields' in type) {
|
|
57
|
-
return `recordFields:[${type.fields
|
|
58
|
-
.map((f) => `${f.name}:${String(Boolean(f.optional))}:${getTypeDedupKey(f.type, symbols)}`)
|
|
59
|
-
.join(',')}]`;
|
|
60
|
-
}
|
|
61
|
-
return `recordKV:${type.key == null ? 'none' : getTypeDedupKey(type.key, symbols)}:${getTypeDedupKey(type.value, symbols)}`;
|
|
62
|
-
case 'literal':
|
|
63
|
-
return `literal:${typeof type.value}:${String(type.value)}`;
|
|
64
|
-
case 'template':
|
|
65
|
-
return `template:[${type.parts.map((p) => getTypeDedupKey(p, symbols)).join(',')}]`;
|
|
66
|
-
case 'function':
|
|
67
|
-
return `function:${type.name ?? ''}:<${(type.typeParams ?? []).map((p) => getTypeDedupKey(p, symbols)).join(',')}>(${type.params
|
|
68
|
-
.map((p) => `${p.name}:${String(Boolean(p.spread))}:${getTypeDedupKey(p.type, symbols)}`)
|
|
69
|
-
.join(',')})=>${type.returns == null ? 'void' : getTypeDedupKey(type.returns, symbols)}`;
|
|
70
|
-
case 'tuple':
|
|
71
|
-
return `tuple:[${type.elements
|
|
72
|
-
.map((e) => `${String(Boolean(e.spread))}:${getTypeDedupKey(e.type, symbols)}`)
|
|
73
|
-
.join(',')}]`;
|
|
74
|
-
case 'reflection':
|
|
75
|
-
return `reflection:${type.name}`;
|
|
76
|
-
default:
|
|
77
|
-
return 'unknown';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/** Removes duplicate members from union/intersection type member lists. */
|
|
81
|
-
function deduplicateTypeMembers(types) {
|
|
82
|
-
if (types.length <= 1)
|
|
83
|
-
return types;
|
|
84
|
-
const symbols = new Map();
|
|
85
|
-
const seen = new Set();
|
|
86
|
-
const result = [];
|
|
87
|
-
for (const type of types) {
|
|
88
|
-
const key = getTypeDedupKey(type, symbols);
|
|
89
|
-
if (seen.has(key))
|
|
90
|
-
continue;
|
|
91
|
-
seen.add(key);
|
|
92
|
-
result.push(type);
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
/** Flattens nested union nodes when the corresponding option is enabled. */
|
|
97
|
-
function flattenUnionTypes(types, options) {
|
|
98
|
-
if (!options.flattenUnions)
|
|
99
|
-
return types;
|
|
100
|
-
const result = [];
|
|
101
|
-
for (const type of types) {
|
|
102
|
-
if (isTypeObject(type) && type.kind === 'union') {
|
|
103
|
-
result.push(...flattenUnionTypes(type.types, options));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
result.push(type);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
/** Flattens nested intersection nodes when the corresponding option is enabled. */
|
|
112
|
-
function flattenIntersectionTypes(types, options) {
|
|
113
|
-
if (!options.flattenIntersections)
|
|
114
|
-
return types;
|
|
115
|
-
const result = [];
|
|
116
|
-
for (const type of types) {
|
|
117
|
-
if (isTypeObject(type) && type.kind === 'intersection') {
|
|
118
|
-
result.push(...flattenIntersectionTypes(type.types, options));
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
result.push(type);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
/** Simplifies a record field recursively. */
|
|
127
|
-
function simplifyRecordField(field, options) {
|
|
128
|
-
return {
|
|
129
|
-
...field,
|
|
130
|
-
type: simplifyImpl(field.type, options),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/** Merges explicit record fields across an intersection. */
|
|
134
|
-
function mergeRecordFieldIntersections(types) {
|
|
135
|
-
const merged = new Map();
|
|
136
|
-
for (const record of types) {
|
|
137
|
-
for (const field of record.fields) {
|
|
138
|
-
const prev = merged.get(field.name);
|
|
139
|
-
if (prev == null) {
|
|
140
|
-
merged.set(field.name, {
|
|
141
|
-
optional: field.optional ?? false,
|
|
142
|
-
type: field.type,
|
|
143
|
-
});
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
merged.set(field.name, {
|
|
147
|
-
optional: (prev.optional ?? false) && (field.optional ?? false),
|
|
148
|
-
type: {
|
|
149
|
-
kind: 'intersection',
|
|
150
|
-
types: [prev.type, field.type],
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
kind: 'record',
|
|
157
|
-
fields: Array.from(merged.entries()).map(([name, field]) => ({
|
|
158
|
-
name,
|
|
159
|
-
optional: field.optional,
|
|
160
|
-
type: field.type,
|
|
161
|
-
})),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/** Distributes intersections over unions using a cartesian product. */
|
|
165
|
-
function distributeIntersectionsOverUnions(types, options) {
|
|
166
|
-
let combinations = [[]];
|
|
167
|
-
for (const type of types) {
|
|
168
|
-
const choices = isTypeObject(type) && type.kind === 'union' ? type.types : [type];
|
|
169
|
-
const next = [];
|
|
170
|
-
for (const combo of combinations) {
|
|
171
|
-
for (const choice of choices) {
|
|
172
|
-
next.push([...combo, choice]);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
combinations = next;
|
|
176
|
-
}
|
|
177
|
-
const branches = combinations.map((combo) => simplifyImpl({ kind: 'intersection', types: combo }, {
|
|
178
|
-
...options,
|
|
179
|
-
distributeIntersectionsOverUnions: false,
|
|
180
|
-
}));
|
|
181
|
-
if (branches.length === 1)
|
|
182
|
-
return branches[0];
|
|
183
|
-
return { kind: 'union', types: branches };
|
|
184
|
-
}
|
|
185
|
-
/** Simplifies a Type AST in place, optionally disabling individual normalization passes. */
|
|
186
|
-
function simplifyImpl(type, config) {
|
|
187
|
-
if (typeof type === 'symbol' || typeof type === 'string') {
|
|
188
|
-
return type;
|
|
189
|
-
}
|
|
190
|
-
if (type.kind === 'array') {
|
|
191
|
-
type.element = simplifyImpl(type.element, config);
|
|
192
|
-
if (config.normalizeGenericArray && (type.element === 'any' || type.element === 'unknown')) {
|
|
193
|
-
return 'array';
|
|
194
|
-
}
|
|
195
|
-
return type;
|
|
196
|
-
}
|
|
197
|
-
if (type.kind === 'function') {
|
|
198
|
-
for (const param of type.params) {
|
|
199
|
-
param.type = simplifyImpl(param.type, config);
|
|
200
|
-
}
|
|
201
|
-
if (type.returns != null)
|
|
202
|
-
type.returns = simplifyImpl(type.returns, config);
|
|
203
|
-
return type;
|
|
204
|
-
}
|
|
205
|
-
if (type.kind === 'literal') {
|
|
206
|
-
return type;
|
|
207
|
-
}
|
|
208
|
-
if (type.kind === 'template') {
|
|
209
|
-
type.parts = type.parts.map((part) => simplifyImpl(part, config));
|
|
210
|
-
return type;
|
|
211
|
-
}
|
|
212
|
-
if (type.kind === 'tuple') {
|
|
213
|
-
type.elements = type.elements.flatMap((element) => {
|
|
214
|
-
const simplifiedType = simplifyImpl(element.type, config);
|
|
215
|
-
if (config.expandTupleSpreads &&
|
|
216
|
-
element.spread &&
|
|
217
|
-
typeof simplifiedType === 'object' &&
|
|
218
|
-
simplifiedType.kind === 'tuple') {
|
|
219
|
-
// Inline tuple spread: ..[A, B] → A, B
|
|
220
|
-
return simplifiedType.elements;
|
|
221
|
-
}
|
|
222
|
-
return [{ ...element, type: simplifiedType }];
|
|
223
|
-
});
|
|
224
|
-
return type;
|
|
225
|
-
}
|
|
226
|
-
if (type.kind === 'reflection') {
|
|
227
|
-
return type;
|
|
228
|
-
}
|
|
229
|
-
if (type.kind === 'record') {
|
|
230
|
-
if ('fields' in type) {
|
|
231
|
-
type.fields = type.fields.map((field) => simplifyRecordField(field, config));
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
if (type.key != null)
|
|
235
|
-
type.key = simplifyImpl(type.key, config);
|
|
236
|
-
type.value = simplifyImpl(type.value, config);
|
|
237
|
-
if (config.normalizeGenericRecord && type.key === 'string') {
|
|
238
|
-
delete type.key;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return type;
|
|
242
|
-
}
|
|
243
|
-
if (type.kind === 'union') {
|
|
244
|
-
let simplifiedTypes = flattenUnionTypes(type.types.map((item) => simplifyImpl(item, config)), config);
|
|
245
|
-
// Top-type elimination: unknown | T → unknown, any | T → any, T | never → T
|
|
246
|
-
const topTypes = resolveTopTypes(config.simplifyTopTypesInUnions);
|
|
247
|
-
if (topTypes.length > 0) {
|
|
248
|
-
if (topTypes.includes('any') && simplifiedTypes.includes('any'))
|
|
249
|
-
return 'any';
|
|
250
|
-
if (topTypes.includes('unknown') && simplifiedTypes.includes('unknown'))
|
|
251
|
-
return 'unknown';
|
|
252
|
-
if (topTypes.includes('never')) {
|
|
253
|
-
simplifiedTypes = simplifiedTypes.filter((t) => t !== 'never');
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (config.deduplicateUnions) {
|
|
257
|
-
simplifiedTypes = deduplicateTypeMembers(simplifiedTypes);
|
|
258
|
-
}
|
|
259
|
-
if (config.unwrapSingleUnion) {
|
|
260
|
-
if (simplifiedTypes.length === 1)
|
|
261
|
-
return simplifiedTypes[0];
|
|
262
|
-
if (simplifiedTypes.length === 0)
|
|
263
|
-
return 'never';
|
|
264
|
-
}
|
|
265
|
-
type.types = simplifiedTypes;
|
|
266
|
-
return type;
|
|
267
|
-
}
|
|
268
|
-
if (type.kind === 'intersection') {
|
|
269
|
-
let simplifiedTypes = flattenIntersectionTypes(type.types.map((item) => simplifyImpl(item, config)), config);
|
|
270
|
-
// Top-type elimination: never & T → never, T & unknown → T, T & any → T
|
|
271
|
-
const topTypes = resolveTopTypes(config.simplifyTopTypesInIntersections);
|
|
272
|
-
if (topTypes.length > 0) {
|
|
273
|
-
const typeNames = new Set(simplifiedTypes.filter((t) => typeof t === 'string'));
|
|
274
|
-
if (topTypes.includes('never') && typeNames.has('never'))
|
|
275
|
-
return 'never';
|
|
276
|
-
let filtered = false;
|
|
277
|
-
if (topTypes.includes('unknown') && typeNames.has('unknown')) {
|
|
278
|
-
simplifiedTypes = simplifiedTypes.filter((t) => t !== 'unknown');
|
|
279
|
-
filtered = true;
|
|
280
|
-
}
|
|
281
|
-
if (topTypes.includes('any') && typeNames.has('any')) {
|
|
282
|
-
simplifiedTypes = simplifiedTypes.filter((t) => t !== 'any');
|
|
283
|
-
filtered = true;
|
|
284
|
-
}
|
|
285
|
-
if (filtered) {
|
|
286
|
-
if (simplifiedTypes.length === 1)
|
|
287
|
-
return simplifiedTypes[0];
|
|
288
|
-
if (simplifiedTypes.length === 0) {
|
|
289
|
-
// All members were the same eliminated top type
|
|
290
|
-
return typeNames.has('any') ? 'any' : 'unknown';
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (config.deduplicateIntersections) {
|
|
295
|
-
simplifiedTypes = deduplicateTypeMembers(simplifiedTypes);
|
|
296
|
-
}
|
|
297
|
-
if (config.distributeIntersectionsOverUnions &&
|
|
298
|
-
simplifiedTypes.some((item) => isTypeObject(item) && item.kind === 'union')) {
|
|
299
|
-
return distributeIntersectionsOverUnions(simplifiedTypes, config);
|
|
300
|
-
}
|
|
301
|
-
if (config.mergeRecordIntersections) {
|
|
302
|
-
const recordTypes = simplifiedTypes.filter(isFieldRecordType);
|
|
303
|
-
if (recordTypes.length >= 2) {
|
|
304
|
-
const nonRecordTypes = simplifiedTypes.filter((item) => !isFieldRecordType(item));
|
|
305
|
-
const mergedRecord = simplifyImpl(mergeRecordFieldIntersections(recordTypes), config);
|
|
306
|
-
let mergedTypes = [mergedRecord, ...nonRecordTypes];
|
|
307
|
-
if (config.deduplicateIntersections) {
|
|
308
|
-
mergedTypes = deduplicateTypeMembers(mergedTypes);
|
|
309
|
-
}
|
|
310
|
-
if (config.unwrapSingleIntersection && mergedTypes.length === 1) {
|
|
311
|
-
return mergedTypes[0];
|
|
312
|
-
}
|
|
313
|
-
type.types = mergedTypes;
|
|
314
|
-
return type;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (config.unwrapSingleIntersection && simplifiedTypes.length === 1) {
|
|
318
|
-
return simplifiedTypes[0];
|
|
319
|
-
}
|
|
320
|
-
type.types = simplifiedTypes;
|
|
321
|
-
return type;
|
|
322
|
-
}
|
|
323
|
-
/* c8 ignore next 3 */
|
|
324
|
-
(type);
|
|
325
|
-
return type;
|
|
326
|
-
}
|
|
327
|
-
/** Simplifies a Type AST in place, optionally disabling individual normalization passes. */
|
|
328
|
-
export function simplify(type, options) {
|
|
329
|
-
const config = normalizeOptions(options);
|
|
330
|
-
return simplifyImpl(type, config);
|
|
331
|
-
}
|
|
332
|
-
//# sourceMappingURL=simplifier.js.map
|
package/dist/simplifier.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simplifier.js","sourceRoot":"","sources":["../src/simplifier.ts"],"names":[],"mappings":"AA+CA,gEAAgE;AAChE,SAAS,eAAe,CAAC,KAAsC;IAC3D,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAChD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,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,EAAE,GAAG,cAAc,CAAC,CAAC;gBACpD,IAAI,MAAM,CAAC,wBAAwB,EAAE,CAAC;oBAClC,WAAW,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;gBACtD,CAAC;gBACD,IAAI,MAAM,CAAC,wBAAwB,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC9D,OAAO,WAAW,CAAC,CAAC,CAAE,CAAC;gBAC3B,CAAC;gBACD,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;gBACzB,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,IAAI,MAAM,CAAC,wBAAwB,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClE,OAAO,eAAe,CAAC,CAAC,CAAE,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,sBAAsB;IACtB,CAAC,IAAI,CAAiB,CAAC;IACvB,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,QAAQ,CAAC,IAAU,EAAE,OAAyB;IAC1D,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
package/src/json.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { type JSONSchema, $schema } from 'json-schema-typed';
|
|
2
|
-
import { REG_NUMBER } from '@mirascript/constants';
|
|
3
|
-
import { simplify } from './simplifier.js';
|
|
4
|
-
import type { KnownType, LiteralType, NamedType, TemplateType, Type } from './parser.js';
|
|
5
|
-
|
|
6
|
-
export type { JSONSchema } from 'json-schema-typed';
|
|
7
|
-
|
|
8
|
-
/** Converts a KnownType or NamedType into JSON Schema */
|
|
9
|
-
function string(type: KnownType | NamedType): JSONSchema {
|
|
10
|
-
switch (type) {
|
|
11
|
-
case 'string':
|
|
12
|
-
return { type: 'string' };
|
|
13
|
-
case 'number':
|
|
14
|
-
return { type: 'number' };
|
|
15
|
-
case 'boolean':
|
|
16
|
-
return { type: 'boolean' };
|
|
17
|
-
case 'nil':
|
|
18
|
-
return { type: 'null' };
|
|
19
|
-
case 'array':
|
|
20
|
-
return { type: 'array', items: true };
|
|
21
|
-
case 'record':
|
|
22
|
-
return { type: 'object' };
|
|
23
|
-
case 'extern':
|
|
24
|
-
return true;
|
|
25
|
-
case 'any':
|
|
26
|
-
return true;
|
|
27
|
-
case 'unknown':
|
|
28
|
-
return true;
|
|
29
|
-
case 'never':
|
|
30
|
-
return false;
|
|
31
|
-
default:
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Escapes a literal string for use in a regular expression */
|
|
37
|
-
function escapeRegex(value: string): string {
|
|
38
|
-
return value.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const RE_ANY = '.*?';
|
|
42
|
-
const RE_NUMBER = REG_NUMBER.source;
|
|
43
|
-
const RE_BOOLEAN = 'true|false';
|
|
44
|
-
|
|
45
|
-
/** Converts a template interpolation part into a regex pattern fragment */
|
|
46
|
-
function templatePartPattern(part: Type, grouping: boolean): string {
|
|
47
|
-
let result: string;
|
|
48
|
-
if (typeof part === 'symbol') {
|
|
49
|
-
result = RE_ANY;
|
|
50
|
-
} else if (typeof part === 'string') {
|
|
51
|
-
switch (part) {
|
|
52
|
-
case 'number':
|
|
53
|
-
result = RE_NUMBER;
|
|
54
|
-
break;
|
|
55
|
-
case 'boolean':
|
|
56
|
-
result = RE_BOOLEAN;
|
|
57
|
-
break;
|
|
58
|
-
case 'nil':
|
|
59
|
-
case 'never':
|
|
60
|
-
result = '';
|
|
61
|
-
break;
|
|
62
|
-
case 'array':
|
|
63
|
-
case 'record':
|
|
64
|
-
case 'extern':
|
|
65
|
-
case 'any':
|
|
66
|
-
case 'unknown':
|
|
67
|
-
case 'string':
|
|
68
|
-
default:
|
|
69
|
-
result = RE_ANY;
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
} else if (part.kind === 'literal') {
|
|
73
|
-
if (typeof part.value === 'boolean') {
|
|
74
|
-
result = String(part.value);
|
|
75
|
-
} else {
|
|
76
|
-
result = escapeRegex(part.value);
|
|
77
|
-
}
|
|
78
|
-
} else if (part.kind === 'union') {
|
|
79
|
-
const patterns = new Set(part.types.map((p) => templatePartPattern(p, false)));
|
|
80
|
-
if (patterns.has(RE_ANY)) {
|
|
81
|
-
result = RE_ANY;
|
|
82
|
-
} else {
|
|
83
|
-
const hasEmpty = patterns.delete('');
|
|
84
|
-
result = Array.from(patterns).join('|');
|
|
85
|
-
if (hasEmpty) {
|
|
86
|
-
result = `(${result})?`;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} else if (part.kind === 'intersection') {
|
|
90
|
-
// Regex intersection is not representable in general; keep behavior conservative.
|
|
91
|
-
result = RE_ANY;
|
|
92
|
-
} else {
|
|
93
|
-
result = RE_ANY;
|
|
94
|
-
}
|
|
95
|
-
if (!grouping) return result;
|
|
96
|
-
if (result.startsWith('(')) return result;
|
|
97
|
-
return `(${result})`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Converts a TemplateType into a JSON Schema pattern */
|
|
101
|
-
function templatePattern(type: TemplateType): string {
|
|
102
|
-
return `^${type.parts
|
|
103
|
-
.map((p) => {
|
|
104
|
-
if (typeof p == 'object' && p.kind === 'literal' && typeof p.value === 'string') {
|
|
105
|
-
return templatePartPattern(p, false);
|
|
106
|
-
}
|
|
107
|
-
return templatePartPattern(p, true);
|
|
108
|
-
})
|
|
109
|
-
.join('')}$`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Converts a LiteralType into JSON Schema */
|
|
113
|
-
function literal(type: LiteralType): JSONSchema {
|
|
114
|
-
return { const: type.value };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Converts a union of LiteralTypes into a single JSON Schema enum */
|
|
118
|
-
function literalEnum(types: LiteralType[]): JSONSchema {
|
|
119
|
-
const schema: JSONSchema = {
|
|
120
|
-
enum: types.map((t) => t.value),
|
|
121
|
-
};
|
|
122
|
-
return schema;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Type guard for LiteralType */
|
|
126
|
-
function isLiteralType(type: Type): type is LiteralType {
|
|
127
|
-
return typeof type == 'object' && type.kind === 'literal';
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Options for toJSONSchema */
|
|
131
|
-
export interface ToJSONSchemaOptions {
|
|
132
|
-
/** When true, object schemas allow arbitrary additional properties */
|
|
133
|
-
loose?: boolean;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Converts a Type object into JSON Schema */
|
|
137
|
-
function toJSONSchemaImpl(type: Type, options: Required<ToJSONSchemaOptions>): JSONSchema {
|
|
138
|
-
const { loose } = options;
|
|
139
|
-
const simplified = simplify(type);
|
|
140
|
-
if (typeof simplified == 'symbol') {
|
|
141
|
-
return {};
|
|
142
|
-
}
|
|
143
|
-
if (typeof simplified == 'string') {
|
|
144
|
-
return string(simplified);
|
|
145
|
-
}
|
|
146
|
-
if (simplified.kind === 'array') {
|
|
147
|
-
return {
|
|
148
|
-
type: 'array',
|
|
149
|
-
items: toJSONSchemaImpl(simplified.element, options),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
if (simplified.kind === 'union') {
|
|
153
|
-
const anyOf: JSONSchema[] = [];
|
|
154
|
-
const literals: LiteralType[] = [];
|
|
155
|
-
for (const t of simplified.types) {
|
|
156
|
-
if (isLiteralType(t)) {
|
|
157
|
-
literals.push(t);
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
const child = toJSONSchemaImpl(t, options);
|
|
161
|
-
if (child === true) {
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
if (child === false) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
anyOf.push(child);
|
|
168
|
-
}
|
|
169
|
-
if (literals.length > 0) {
|
|
170
|
-
anyOf.push(literalEnum(literals));
|
|
171
|
-
}
|
|
172
|
-
if (anyOf.length === 0) {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
if (anyOf.length === 1) {
|
|
176
|
-
return anyOf[0]!;
|
|
177
|
-
}
|
|
178
|
-
return { anyOf };
|
|
179
|
-
}
|
|
180
|
-
if (simplified.kind === 'intersection') {
|
|
181
|
-
const allOf = simplified.types.map((t) => toJSONSchemaImpl(t, options));
|
|
182
|
-
if (allOf.length === 1) {
|
|
183
|
-
return allOf[0]!;
|
|
184
|
-
}
|
|
185
|
-
return { allOf };
|
|
186
|
-
}
|
|
187
|
-
if (simplified.kind === 'record') {
|
|
188
|
-
if ('fields' in simplified) {
|
|
189
|
-
const properties: Record<string, JSONSchema> = {};
|
|
190
|
-
const required: string[] = [];
|
|
191
|
-
for (const field of simplified.fields) {
|
|
192
|
-
properties[field.name] = toJSONSchemaImpl(field.type, options);
|
|
193
|
-
if (!field.optional && !loose) {
|
|
194
|
-
required.push(field.name);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const schema: JSONSchema = {
|
|
198
|
-
type: 'object',
|
|
199
|
-
properties,
|
|
200
|
-
additionalProperties: loose,
|
|
201
|
-
};
|
|
202
|
-
if (required.length > 0) {
|
|
203
|
-
schema.required = required;
|
|
204
|
-
}
|
|
205
|
-
return schema;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const valueSchema = toJSONSchemaImpl(simplified.value, options);
|
|
209
|
-
if (simplified.key == null) {
|
|
210
|
-
return {
|
|
211
|
-
type: 'object',
|
|
212
|
-
additionalProperties: valueSchema,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
if (typeof simplified.key == 'object') {
|
|
216
|
-
if (isLiteralType(simplified.key)) {
|
|
217
|
-
const schema: JSONSchema = {
|
|
218
|
-
type: 'object',
|
|
219
|
-
properties: { [String(simplified.key.value)]: valueSchema },
|
|
220
|
-
additionalProperties: loose,
|
|
221
|
-
};
|
|
222
|
-
return schema;
|
|
223
|
-
} else if (simplified.key.kind === 'union' && simplified.key.types.every(isLiteralType)) {
|
|
224
|
-
const schema: JSONSchema = {
|
|
225
|
-
type: 'object',
|
|
226
|
-
properties: Object.fromEntries(simplified.key.types.map((t) => [String(t.value), valueSchema])),
|
|
227
|
-
additionalProperties: loose,
|
|
228
|
-
};
|
|
229
|
-
return schema;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const pattern = templatePartPattern(simplified.key, false);
|
|
233
|
-
if (pattern === RE_ANY) {
|
|
234
|
-
return {
|
|
235
|
-
type: 'object',
|
|
236
|
-
additionalProperties: valueSchema,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
const schema: JSONSchema = {
|
|
240
|
-
type: 'object',
|
|
241
|
-
patternProperties: { [`^${pattern}$`]: valueSchema },
|
|
242
|
-
additionalProperties: loose,
|
|
243
|
-
};
|
|
244
|
-
return schema;
|
|
245
|
-
}
|
|
246
|
-
if (simplified.kind === 'literal') {
|
|
247
|
-
return literal(simplified);
|
|
248
|
-
}
|
|
249
|
-
if (simplified.kind === 'function') {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
if (simplified.kind === 'template') {
|
|
253
|
-
return { type: 'string', pattern: templatePattern(simplified) };
|
|
254
|
-
}
|
|
255
|
-
if (simplified.kind === 'tuple') {
|
|
256
|
-
// Collect element schemas, unwrapping array from rest elements (..T[] → T).
|
|
257
|
-
// Non-array rest (e.g. ..string) is treated as any ({}).
|
|
258
|
-
const elementSchemas = simplified.elements.map((e) => {
|
|
259
|
-
const t = e.type;
|
|
260
|
-
if (!e.spread) return toJSONSchemaImpl(t, options);
|
|
261
|
-
if (typeof t == 'object' && t.kind === 'array') {
|
|
262
|
-
return toJSONSchemaImpl(t.element, options);
|
|
263
|
-
}
|
|
264
|
-
return true;
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const prefixItems = [];
|
|
268
|
-
let i = 0;
|
|
269
|
-
for (; i < elementSchemas.length; i++) {
|
|
270
|
-
const el = simplified.elements[i]!;
|
|
271
|
-
if (el.spread) break;
|
|
272
|
-
prefixItems.push(elementSchemas[i]!);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const items = [];
|
|
276
|
-
let hasAny = false;
|
|
277
|
-
for (; i < elementSchemas.length; i++) {
|
|
278
|
-
const schema = elementSchemas[i]!;
|
|
279
|
-
items.push(schema);
|
|
280
|
-
if (schema === true) {
|
|
281
|
-
hasAny = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const schema: JSONSchema = { type: 'array' };
|
|
286
|
-
if (prefixItems.length > 0) {
|
|
287
|
-
schema.prefixItems = prefixItems;
|
|
288
|
-
}
|
|
289
|
-
if (hasAny) {
|
|
290
|
-
schema.items = true;
|
|
291
|
-
} else if (items.length > 1) {
|
|
292
|
-
schema.items = { anyOf: items };
|
|
293
|
-
} else if (items.length === 1) {
|
|
294
|
-
schema.items = items[0]!;
|
|
295
|
-
} else {
|
|
296
|
-
schema.items = loose;
|
|
297
|
-
}
|
|
298
|
-
return schema;
|
|
299
|
-
}
|
|
300
|
-
if (simplified.kind === 'reflection') {
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
/* c8 ignore next 3 */
|
|
304
|
-
simplified satisfies never;
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/** Converts a Type object into JSON Schema */
|
|
309
|
-
export function toJSONSchema(
|
|
310
|
-
type: Type,
|
|
311
|
-
options?: ToJSONSchemaOptions,
|
|
312
|
-
): JSONSchema.Interface & { $schema: typeof $schema } {
|
|
313
|
-
let schema = toJSONSchemaImpl(type, { loose: options?.loose ?? false });
|
|
314
|
-
if (schema === true) {
|
|
315
|
-
schema = {};
|
|
316
|
-
} else if (schema === false) {
|
|
317
|
-
schema = { not: true };
|
|
318
|
-
}
|
|
319
|
-
return {
|
|
320
|
-
...schema,
|
|
321
|
-
$schema,
|
|
322
|
-
};
|
|
323
|
-
}
|