@luna-park/plugin 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist-hc-SHkAg.mjs +600 -0
- package/dist/extractor.d.mts +85 -0
- package/dist/extractor.mjs +611 -0
- package/dist/index-X3hhfmWd.d.mts +368 -0
- package/dist/index.d.mts +941 -0
- package/dist/index.mjs +887 -0
- package/dist/preview.d.mts +8 -0
- package/dist/preview.mjs +47 -0
- package/dist/style.css +8 -0
- package/package.json +28 -29
- package/dist/chunk-rCEYsGS8.cjs +0 -1
- package/dist/dist-BUZt4gnZ.js +0 -421
- package/dist/dist-BkSFkjuo.cjs +0 -5
- package/dist/extractor.cjs +0 -14
- package/dist/extractor.d.ts +0 -1
- package/dist/extractor.js +0 -512
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2962
- package/dist/plugin.css +0 -2
- package/dist/preview.cjs +0 -1
- package/dist/preview.d.ts +0 -1
- package/dist/preview.js +0 -29
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
//#region ../utils/dist/index.mjs
|
|
2
|
+
function cloneDeep(object) {
|
|
3
|
+
if (typeof object !== "object") return object;
|
|
4
|
+
const strategies = [
|
|
5
|
+
() => JSON.parse(JSON.stringify(object)),
|
|
6
|
+
() => structuredClone(object),
|
|
7
|
+
() => safeClone(object)
|
|
8
|
+
];
|
|
9
|
+
let lastError;
|
|
10
|
+
for (const strategy of strategies) try {
|
|
11
|
+
return strategy();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
lastError = error;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
console.error("Failed to deep clone object:", object);
|
|
17
|
+
throw new Error(lastError);
|
|
18
|
+
}
|
|
19
|
+
function safeClone(object) {
|
|
20
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
21
|
+
return recursiveClone(object);
|
|
22
|
+
function recursiveClone(object) {
|
|
23
|
+
if (typeof object !== "object") return object;
|
|
24
|
+
if (seen.has(object)) return { recursive: true };
|
|
25
|
+
seen.add(object);
|
|
26
|
+
if (Array.isArray(object)) return object.map((element) => recursiveClone(element));
|
|
27
|
+
const descriptors = Object.getOwnPropertyDescriptors(object);
|
|
28
|
+
const clone = {};
|
|
29
|
+
for (const [key, descriptor] of Object.entries(descriptors)) clone[key] = recursiveClone(descriptor.value);
|
|
30
|
+
return clone;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function cloneWithFunctions(object) {
|
|
34
|
+
if (Array.isArray(object)) return object.map(cloneWithFunctions);
|
|
35
|
+
if (typeof object !== "object") return object;
|
|
36
|
+
const clone = {};
|
|
37
|
+
for (const [key, value] of Object.entries(object)) {
|
|
38
|
+
if (typeof value === "function") {
|
|
39
|
+
clone[key] = value;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
clone[key] = cloneWithFunctions(value);
|
|
43
|
+
}
|
|
44
|
+
return clone;
|
|
45
|
+
}
|
|
46
|
+
function objectMap(source, func) {
|
|
47
|
+
if (!source) return {};
|
|
48
|
+
return Object.fromEntries(Object.entries(source).map(([key, value]) => [key, func({
|
|
49
|
+
key,
|
|
50
|
+
value
|
|
51
|
+
})]));
|
|
52
|
+
}
|
|
53
|
+
function objectFilter(source, func) {
|
|
54
|
+
if (!source) return {};
|
|
55
|
+
return Object.fromEntries(Object.entries(source).filter(([key, value]) => func({
|
|
56
|
+
key,
|
|
57
|
+
value
|
|
58
|
+
})));
|
|
59
|
+
}
|
|
60
|
+
function cleanObject(target) {
|
|
61
|
+
target = cloneDeep(target);
|
|
62
|
+
for (const key in target) cleanDeep(target, key);
|
|
63
|
+
function cleanDeep(value, key) {
|
|
64
|
+
if (typeof value[key] === "object") {
|
|
65
|
+
for (const childKey in value[key]) cleanDeep(value[key], childKey);
|
|
66
|
+
if (Object.keys(value[key]).length === 0) delete value[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return target;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region ../logicnodes/dist/index.mjs
|
|
73
|
+
let EVarType = /* @__PURE__ */ function(EVarType) {
|
|
74
|
+
EVarType["exec"] = "exec";
|
|
75
|
+
EVarType["number"] = "number";
|
|
76
|
+
EVarType["string"] = "string";
|
|
77
|
+
EVarType["boolean"] = "boolean";
|
|
78
|
+
EVarType["object"] = "object";
|
|
79
|
+
EVarType["record"] = "record";
|
|
80
|
+
EVarType["array"] = "array";
|
|
81
|
+
EVarType["interface"] = "interface";
|
|
82
|
+
EVarType["type"] = "type";
|
|
83
|
+
EVarType["function"] = "function";
|
|
84
|
+
EVarType["union"] = "union";
|
|
85
|
+
EVarType["unknown"] = "unknown";
|
|
86
|
+
EVarType["undefined"] = "undefined";
|
|
87
|
+
EVarType["void"] = "void";
|
|
88
|
+
return EVarType;
|
|
89
|
+
}({});
|
|
90
|
+
const LogicType = {
|
|
91
|
+
array: (items, args = {}) => {
|
|
92
|
+
return {
|
|
93
|
+
...args,
|
|
94
|
+
items,
|
|
95
|
+
type: EVarType.array
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
boolean: (args = {}) => {
|
|
99
|
+
return {
|
|
100
|
+
...args,
|
|
101
|
+
type: EVarType.boolean
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
exec: (args = {}) => {
|
|
105
|
+
return {
|
|
106
|
+
...args,
|
|
107
|
+
type: EVarType.exec
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
function: (inputs = {
|
|
111
|
+
properties: {},
|
|
112
|
+
type: EVarType.object
|
|
113
|
+
}, output = { type: EVarType.void }, args = {}) => {
|
|
114
|
+
return {
|
|
115
|
+
...args,
|
|
116
|
+
inputs,
|
|
117
|
+
output,
|
|
118
|
+
type: EVarType.function
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
interface: (interfaceClass, args = {}) => {
|
|
122
|
+
return {
|
|
123
|
+
...args,
|
|
124
|
+
className: typeof interfaceClass === "string" ? interfaceClass : interfaceClass.name,
|
|
125
|
+
type: EVarType.interface
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
number: (args = {}) => {
|
|
129
|
+
return {
|
|
130
|
+
...args,
|
|
131
|
+
type: EVarType.number
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
object: (properties = {}, args = {}) => {
|
|
135
|
+
return {
|
|
136
|
+
...args,
|
|
137
|
+
properties,
|
|
138
|
+
type: EVarType.object
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
record: (key, value, args = {}) => {
|
|
142
|
+
return {
|
|
143
|
+
...args,
|
|
144
|
+
key,
|
|
145
|
+
type: EVarType.record,
|
|
146
|
+
value
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
string: (args = {}) => {
|
|
150
|
+
return {
|
|
151
|
+
...args,
|
|
152
|
+
type: EVarType.string
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
type: (target, args = {}) => {
|
|
156
|
+
return {
|
|
157
|
+
...args,
|
|
158
|
+
target,
|
|
159
|
+
type: EVarType.type
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
undefined: (args = {}) => {
|
|
163
|
+
return {
|
|
164
|
+
...args,
|
|
165
|
+
type: EVarType.undefined
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
union: (elements, args = {}) => {
|
|
169
|
+
return {
|
|
170
|
+
...args,
|
|
171
|
+
elements,
|
|
172
|
+
type: EVarType.union
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
unknown: (args = {}) => {
|
|
176
|
+
return {
|
|
177
|
+
...args,
|
|
178
|
+
type: EVarType.unknown
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
void: (args = {}) => {
|
|
182
|
+
return {
|
|
183
|
+
...args,
|
|
184
|
+
type: EVarType.void
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const LogicUtil = {
|
|
189
|
+
omit(target, keys) {
|
|
190
|
+
return {
|
|
191
|
+
...target,
|
|
192
|
+
properties: objectFilter(target.properties, ({ key }) => !keys.includes(key))
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
partial(target, force = false) {
|
|
196
|
+
return {
|
|
197
|
+
...target,
|
|
198
|
+
properties: objectMap(target.properties, ({ value }) => ({
|
|
199
|
+
...value,
|
|
200
|
+
optional: !force || !value.required
|
|
201
|
+
}))
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
pick(target, keys) {
|
|
205
|
+
return {
|
|
206
|
+
...target,
|
|
207
|
+
properties: objectFilter(target.properties, ({ key }) => keys.includes(key))
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
promise(target) {
|
|
211
|
+
return {
|
|
212
|
+
...target,
|
|
213
|
+
promise: true
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
required(target) {
|
|
217
|
+
return {
|
|
218
|
+
...target,
|
|
219
|
+
properties: objectMap(target.properties, ({ value }) => ({
|
|
220
|
+
...value,
|
|
221
|
+
optional: false
|
|
222
|
+
}))
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
let ELogicType = /* @__PURE__ */ function(ELogicType) {
|
|
227
|
+
ELogicType["function"] = "function";
|
|
228
|
+
ELogicType["macro"] = "macro";
|
|
229
|
+
ELogicType["operation"] = "operation";
|
|
230
|
+
return ELogicType;
|
|
231
|
+
}({});
|
|
232
|
+
let ELogicScope = /* @__PURE__ */ function(ELogicScope) {
|
|
233
|
+
ELogicScope["Frontend"] = "frontend";
|
|
234
|
+
ELogicScope["Backend"] = "backend";
|
|
235
|
+
ELogicScope["Desktop"] = "desktop";
|
|
236
|
+
ELogicScope["Shared"] = "shared";
|
|
237
|
+
return ELogicScope;
|
|
238
|
+
}({});
|
|
239
|
+
function makeLogicNode(node) {
|
|
240
|
+
return node;
|
|
241
|
+
}
|
|
242
|
+
function scanner(input) {
|
|
243
|
+
const elements = [];
|
|
244
|
+
input = input.replaceAll(/ +/g, " ");
|
|
245
|
+
input = input.replaceAll(/\s*\n\s*/g, "\n");
|
|
246
|
+
while (input.length) {
|
|
247
|
+
if ([" ", "\n"].includes(input[0])) {
|
|
248
|
+
input = input.slice(1);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (input.startsWith("/*")) {
|
|
252
|
+
const commentEnd = input.indexOf("*/");
|
|
253
|
+
elements.push(input.slice(0, commentEnd + 2));
|
|
254
|
+
input = input.slice(commentEnd + 2);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const startingWord = input.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];
|
|
258
|
+
if (startingWord) {
|
|
259
|
+
input = input.slice(startingWord.length);
|
|
260
|
+
elements.push(startingWord);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const startingNumber = input.match(/^([0-9]+)/)?.[0];
|
|
264
|
+
if (startingNumber) {
|
|
265
|
+
input = input.slice(startingNumber.length);
|
|
266
|
+
elements.push(startingNumber);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (input[0] === ">" && elements.at(-1) === "=") {
|
|
270
|
+
elements.pop();
|
|
271
|
+
elements.push("=>");
|
|
272
|
+
input = input.slice(1);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
elements.push(input[0]);
|
|
276
|
+
input = input.slice(1);
|
|
277
|
+
}
|
|
278
|
+
return elements;
|
|
279
|
+
}
|
|
280
|
+
const wrappers = [
|
|
281
|
+
["(", ")"],
|
|
282
|
+
["[", "]"],
|
|
283
|
+
["{", "}"],
|
|
284
|
+
["<", ">"],
|
|
285
|
+
["'", "'"],
|
|
286
|
+
["\"", "\""]
|
|
287
|
+
];
|
|
288
|
+
function lexer(scan) {
|
|
289
|
+
return cleanArray(splitUntil(scan, ";"));
|
|
290
|
+
}
|
|
291
|
+
function getUntil(scan, until, depth = 1) {
|
|
292
|
+
const result = [];
|
|
293
|
+
const opening = wrappers.find((wrapper) => wrapper[1] === until)?.[0];
|
|
294
|
+
while (scan.length) {
|
|
295
|
+
if (scan[0] === opening) {}
|
|
296
|
+
if (scan[0] === until) {
|
|
297
|
+
depth--;
|
|
298
|
+
if (depth <= 0) break;
|
|
299
|
+
}
|
|
300
|
+
const element = getFirstElement(scan);
|
|
301
|
+
result.push(element);
|
|
302
|
+
if (depth === 0 && typeof element === "object" && element.type === "wrap" && element.style.endsWith(until)) break;
|
|
303
|
+
}
|
|
304
|
+
scan.shift();
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
function eraseUntil(scan, until) {
|
|
308
|
+
while (scan.length) {
|
|
309
|
+
if (scan[0] === until) {
|
|
310
|
+
scan.shift();
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
scan.shift();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function splitUntil(scan, until) {
|
|
317
|
+
const result = [[]];
|
|
318
|
+
while (scan.length) {
|
|
319
|
+
if (scan[0] === until) {
|
|
320
|
+
result.push([]);
|
|
321
|
+
scan.shift();
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
result.at(-1).push(getFirstElement(scan));
|
|
325
|
+
}
|
|
326
|
+
return result.filter((chunk) => chunk.length);
|
|
327
|
+
}
|
|
328
|
+
function getFirstElement(scan) {
|
|
329
|
+
let element = scan.shift();
|
|
330
|
+
let exportFlag = false;
|
|
331
|
+
if (element === "export") {
|
|
332
|
+
exportFlag = true;
|
|
333
|
+
element = scan.shift();
|
|
334
|
+
if (element === "=") return {
|
|
335
|
+
type: "export",
|
|
336
|
+
content: scan.shift()
|
|
337
|
+
};
|
|
338
|
+
if (element === "as") {
|
|
339
|
+
eraseUntil(scan, ";");
|
|
340
|
+
return getFirstElement(scan);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (element === "declare") element = scan.shift();
|
|
344
|
+
if (element === "namespace") {
|
|
345
|
+
const name = scan.shift();
|
|
346
|
+
scan.shift();
|
|
347
|
+
const content = splitUntil(getUntil(scan, "}", 0), ";");
|
|
348
|
+
scan.unshift(";");
|
|
349
|
+
return {
|
|
350
|
+
name,
|
|
351
|
+
type: element,
|
|
352
|
+
content,
|
|
353
|
+
export: exportFlag
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
if (element === "function") {
|
|
357
|
+
const name = scan.shift();
|
|
358
|
+
const then = scan.shift();
|
|
359
|
+
const result = {
|
|
360
|
+
name,
|
|
361
|
+
type: element
|
|
362
|
+
};
|
|
363
|
+
if (then === "<") {
|
|
364
|
+
result.template = getUntil(scan, ">");
|
|
365
|
+
scan.shift();
|
|
366
|
+
}
|
|
367
|
+
const params = splitUntil(getUntil(scan, ")", 0), ",");
|
|
368
|
+
result.export = exportFlag;
|
|
369
|
+
result.params = params;
|
|
370
|
+
if (scan[0] === ":") {
|
|
371
|
+
scan.shift();
|
|
372
|
+
result.returns = getUntil(scan, ";");
|
|
373
|
+
}
|
|
374
|
+
scan.unshift(";");
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
if (element === "interface") {
|
|
378
|
+
const name = scan.shift();
|
|
379
|
+
scan.shift();
|
|
380
|
+
const content = splitUntil(getUntil(scan, "}", 0), ";");
|
|
381
|
+
scan.unshift(";");
|
|
382
|
+
return {
|
|
383
|
+
name,
|
|
384
|
+
type: "interface",
|
|
385
|
+
content
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (element === "type" && /^[A-Za-z0-9]*$/.test(scan[0])) {
|
|
389
|
+
const name = scan.shift();
|
|
390
|
+
const then = scan.shift();
|
|
391
|
+
const result = {
|
|
392
|
+
name,
|
|
393
|
+
type: element
|
|
394
|
+
};
|
|
395
|
+
if (then === "<") {
|
|
396
|
+
result.template = getUntil(scan, ">");
|
|
397
|
+
scan.shift();
|
|
398
|
+
}
|
|
399
|
+
result.content = getUntil(scan, ";");
|
|
400
|
+
scan.unshift(";");
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
if (element === "enum") {
|
|
404
|
+
const name = scan.shift();
|
|
405
|
+
scan.shift();
|
|
406
|
+
const content = getUntil(scan, "}");
|
|
407
|
+
scan.unshift(";");
|
|
408
|
+
return {
|
|
409
|
+
name,
|
|
410
|
+
type: "enum",
|
|
411
|
+
options: Object.fromEntries(content.join("").split(",").filter((item) => item.trim()).map((item) => {
|
|
412
|
+
if (item.includes("=")) {
|
|
413
|
+
const [name, value] = item.split("=");
|
|
414
|
+
return [JSON.parse(value), name];
|
|
415
|
+
}
|
|
416
|
+
return [name, name];
|
|
417
|
+
}))
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (typeof element === "string" && element.startsWith("/*")) return {
|
|
421
|
+
type: "comment",
|
|
422
|
+
content: cleanComment(element)
|
|
423
|
+
};
|
|
424
|
+
for (const wrapper of wrappers) if (element === wrapper[0]) return {
|
|
425
|
+
type: "wrap",
|
|
426
|
+
content: splitUntil(getUntil(scan, wrapper[1]), ";").map((item) => splitUntil(item, ",")).map((item) => splitUntil(item, "|")),
|
|
427
|
+
style: wrapper.join("")
|
|
428
|
+
};
|
|
429
|
+
return element;
|
|
430
|
+
}
|
|
431
|
+
function cleanArray(input) {
|
|
432
|
+
if (Array.isArray(input)) {
|
|
433
|
+
if (input.length === 1) return cleanArray(input[0]);
|
|
434
|
+
return input.map((element) => cleanArray(element));
|
|
435
|
+
}
|
|
436
|
+
if (typeof input === "object" && input !== null) return objectMap(input, ({ value }) => cleanArray(value));
|
|
437
|
+
return input;
|
|
438
|
+
}
|
|
439
|
+
function cleanComment(comment) {
|
|
440
|
+
comment = comment.trim();
|
|
441
|
+
if (!(comment.startsWith("/**") && comment.endsWith("*/"))) return comment;
|
|
442
|
+
comment = comment.slice(3, -2).split("\n").map((line) => {
|
|
443
|
+
const trim = line.trim();
|
|
444
|
+
if (trim.startsWith("* ")) return trim.slice(2);
|
|
445
|
+
return trim;
|
|
446
|
+
}).join("\n").trim();
|
|
447
|
+
return comment.trim();
|
|
448
|
+
}
|
|
449
|
+
function cleanUnion(schema) {
|
|
450
|
+
if (schema.elements.find((element) => [EVarType.undefined, EVarType.void].includes(element.type))) {
|
|
451
|
+
schema.optional = true;
|
|
452
|
+
schema.elements = schema.elements.filter((element) => ![EVarType.undefined, EVarType.void].includes(element.type));
|
|
453
|
+
}
|
|
454
|
+
const childUnions = schema.elements.filter((element) => element.type === EVarType.union);
|
|
455
|
+
if (childUnions.length > 0) {
|
|
456
|
+
schema.elements = schema.elements.filter((element) => element.type !== EVarType.union);
|
|
457
|
+
for (const childUnion of childUnions) schema.elements.push(...childUnion.elements);
|
|
458
|
+
}
|
|
459
|
+
const stringElements = schema.elements.filter((element) => element.type === EVarType.string);
|
|
460
|
+
if (stringElements.length > 1) {
|
|
461
|
+
const enumValues = [];
|
|
462
|
+
let anyFlag = false;
|
|
463
|
+
for (const element of stringElements) if (element.enum) enumValues.push(...element.enum);
|
|
464
|
+
else anyFlag = true;
|
|
465
|
+
schema.elements = schema.elements.filter((element) => element.type !== EVarType.string);
|
|
466
|
+
if (anyFlag) schema.elements.push(LogicType.string());
|
|
467
|
+
else schema.elements.push(LogicType.string({ enum: enumValues }));
|
|
468
|
+
}
|
|
469
|
+
const numberElements = schema.elements.filter((element) => element.type === EVarType.number);
|
|
470
|
+
if (numberElements.length > 1) {
|
|
471
|
+
const enumValues = [];
|
|
472
|
+
let anyFlag = false;
|
|
473
|
+
for (const element of numberElements) if (element.enum) enumValues.push(...element.enum);
|
|
474
|
+
else anyFlag = true;
|
|
475
|
+
schema.elements = schema.elements.filter((element) => element.type !== EVarType.number);
|
|
476
|
+
if (anyFlag) schema.elements.push(LogicType.number());
|
|
477
|
+
else schema.elements.push(LogicType.number({ enum: enumValues }));
|
|
478
|
+
}
|
|
479
|
+
if (schema.elements.length === 1) {
|
|
480
|
+
const simpleSchema = schema.elements[0];
|
|
481
|
+
simpleSchema.optional = schema.optional;
|
|
482
|
+
return simpleSchema;
|
|
483
|
+
}
|
|
484
|
+
if (schema.elements.length === 0) return LogicType.void();
|
|
485
|
+
return schema;
|
|
486
|
+
}
|
|
487
|
+
function cleanInterface(schema) {
|
|
488
|
+
if (schema.className === "Array") return LogicType.array(schema.options.template[0]);
|
|
489
|
+
if (schema.className === "keyof") return LogicType.string();
|
|
490
|
+
if (schema.className === "Record") return LogicType.object({});
|
|
491
|
+
if (schema.className === "PropertyKey") return LogicType.union([LogicType.string(), LogicType.number()]);
|
|
492
|
+
if ([
|
|
493
|
+
"Promise",
|
|
494
|
+
"Partial",
|
|
495
|
+
"Required"
|
|
496
|
+
].includes(schema.className)) return LogicUtil[schema.className.toLocaleLowerCase()](schema.options.template[0]);
|
|
497
|
+
if (["Omit", "Pick"].includes(schema.className)) return LogicUtil[schema.className.toLocaleLowerCase()](schema.options.template[0], schema.options.template[1]?.enum);
|
|
498
|
+
return schema;
|
|
499
|
+
}
|
|
500
|
+
function parser(element, options = {}) {
|
|
501
|
+
if (typeof element === "string") {
|
|
502
|
+
if (element === "string") return LogicType.string(options);
|
|
503
|
+
if (element === "number") return LogicType.number(options);
|
|
504
|
+
if (element === "boolean") return LogicType.boolean(options);
|
|
505
|
+
if (element === "undefined") return LogicType.void(options);
|
|
506
|
+
if (["unknown", "any"].includes(element)) return LogicType.unknown(options);
|
|
507
|
+
if (["undefined", "null"].includes(element)) return LogicType.undefined(options);
|
|
508
|
+
return cleanInterface(LogicType.interface(element, options));
|
|
509
|
+
}
|
|
510
|
+
if (Array.isArray(element)) {
|
|
511
|
+
if (element[0] === "readonly") element.shift();
|
|
512
|
+
if (element.length === 1) return parser(element[0], options);
|
|
513
|
+
if (element.includes("|")) return cleanUnion(LogicType.union(separate(element, (element) => element === "|").map((element) => parser(element)), options));
|
|
514
|
+
if (element.includes("&")) return cleanUnion(LogicType.union(separate(element, (element) => element === "&").map((element) => parser(element)), options));
|
|
515
|
+
if (element.at(-1)?.type === "wrap" && element.at(-1).style === "[]") return LogicType.array(parser(element.slice(0, -1)), options);
|
|
516
|
+
if (element[0] === "import" && element[2] === ".") return parser(element.slice(3), options);
|
|
517
|
+
if (element.length === 2) {
|
|
518
|
+
if (element[1].type === "wrap") {
|
|
519
|
+
if (element[1].style === "<>") {
|
|
520
|
+
let template = element[1].content;
|
|
521
|
+
if (!Array.isArray(template)) template = [template];
|
|
522
|
+
if (!Array.isArray(template[0])) if (template.some((element) => element.type === "wrap" && element.style === "[]") || template.some((element) => element.type === "wrap" && element.style === "<>") || template.includes("&") || template.includes("|")) template = [template];
|
|
523
|
+
else template = template.map((element) => [element]);
|
|
524
|
+
template = template.map((element) => parser(element));
|
|
525
|
+
return cleanInterface(LogicType.interface(element[0], {
|
|
526
|
+
...options,
|
|
527
|
+
options: { template }
|
|
528
|
+
}));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (element.length === 3) {
|
|
533
|
+
if (element[1] === "=>") {
|
|
534
|
+
const parameters = !element[0].content.length || Array.isArray(element[0].content[0]) ? element[0].content : [element[0].content];
|
|
535
|
+
return LogicType.function(LogicType.object(Object.fromEntries(parameters.map((parameter) => {
|
|
536
|
+
return [parameter[0], parser(parameter.slice(2))];
|
|
537
|
+
}))), parser(element[2]));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return parser(element[0], options);
|
|
541
|
+
}
|
|
542
|
+
if (typeof element === "object" && element !== null) {
|
|
543
|
+
if (element.type === "wrap") {
|
|
544
|
+
if (["''", "\"\""].includes(element.style)) return LogicType.string({
|
|
545
|
+
...options,
|
|
546
|
+
enum: [element.content]
|
|
547
|
+
});
|
|
548
|
+
if (element.style === "{}") {
|
|
549
|
+
const content = !element.content.length || Array.isArray(element.content[0]) ? element.content : [element.content];
|
|
550
|
+
return LogicType.object(Object.fromEntries(content.filter((element) => typeof element[0] === "string").map((element) => [element[0], element[1] === "?" ? parser(element.slice(3), { optional: true }) : parser(element.slice(2))])), options);
|
|
551
|
+
}
|
|
552
|
+
if (element.style === "[]") {
|
|
553
|
+
if (element.content[1] === ":") return LogicType.array(parser(element.content.slice(2)), options);
|
|
554
|
+
return LogicType.array(parser(element.content), options);
|
|
555
|
+
}
|
|
556
|
+
if (element.style === "()") return parser(element.content, options);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
console.log("Unknown element");
|
|
560
|
+
console.log(element);
|
|
561
|
+
return LogicType.unknown();
|
|
562
|
+
}
|
|
563
|
+
function separate(result, separator) {
|
|
564
|
+
const output = [[]];
|
|
565
|
+
for (const element of result) if (separator(element)) output.push([]);
|
|
566
|
+
else output[output.length - 1].push(element);
|
|
567
|
+
return output;
|
|
568
|
+
}
|
|
569
|
+
function typeToSchema(type) {
|
|
570
|
+
try {
|
|
571
|
+
if (/^[A-Za-z]+\??:/.test(type)) {
|
|
572
|
+
const [, name, optional, rest] = type.match(/([A-Za-z]+)(\??):(.*)/);
|
|
573
|
+
const schema = parser(lexer(scanner(rest)));
|
|
574
|
+
schema.name = name;
|
|
575
|
+
if (optional === "?") schema.optional = true;
|
|
576
|
+
return schema;
|
|
577
|
+
}
|
|
578
|
+
return parser(lexer(scanner(type)));
|
|
579
|
+
} catch (error) {
|
|
580
|
+
console.error("Failed to parse type", type);
|
|
581
|
+
console.error(error);
|
|
582
|
+
return LogicType.unknown();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function schemaLoop(schema, func, key) {
|
|
586
|
+
schema = func({
|
|
587
|
+
key,
|
|
588
|
+
schema
|
|
589
|
+
}) || schema;
|
|
590
|
+
if (schema.type === EVarType.object) for (const key in schema.properties) schema.properties[key] = schemaLoop(schema.properties[key], func, key);
|
|
591
|
+
if (schema.type === EVarType.array) schema.items = schemaLoop(schema.items, func);
|
|
592
|
+
if (schema.type === EVarType.function) {
|
|
593
|
+
schema.inputs = schemaLoop(schema.inputs, func);
|
|
594
|
+
schema.output = schemaLoop(schema.output, func);
|
|
595
|
+
}
|
|
596
|
+
if (schema.type === EVarType.union) for (const key in schema.elements) schema.elements[key] = schemaLoop(schema.elements[key], func);
|
|
597
|
+
return schema;
|
|
598
|
+
}
|
|
599
|
+
//#endregion
|
|
600
|
+
export { LogicUtil as a, typeToSchema as c, objectMap as d, LogicType as i, cleanObject as l, ELogicType as n, makeLogicNode as o, EVarType as r, schemaLoop as s, ELogicScope as t, cloneWithFunctions as u };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { l as TSchema } from "./index-X3hhfmWd.mjs";
|
|
2
|
+
import * as ts$1 from "typescript";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
//#region src/extractor/export/type.d.ts
|
|
6
|
+
type TExportResult = {
|
|
7
|
+
components: Record<string, TExportComponent>;
|
|
8
|
+
functions: Record<string, TExportFunction>;
|
|
9
|
+
types: Record<string, TExportType>;
|
|
10
|
+
};
|
|
11
|
+
type TExportComponent = {
|
|
12
|
+
emits?: Record<string, Array<TExportType>>;
|
|
13
|
+
models?: Record<string, TExportType>;
|
|
14
|
+
properties?: Record<string, TExportType>;
|
|
15
|
+
slots?: Record<string, TExportType>;
|
|
16
|
+
};
|
|
17
|
+
type TExportFunction = {
|
|
18
|
+
description?: string;
|
|
19
|
+
parameters?: Array<{
|
|
20
|
+
default?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
optional?: boolean;
|
|
24
|
+
type: string;
|
|
25
|
+
}>;
|
|
26
|
+
return: {
|
|
27
|
+
description?: string;
|
|
28
|
+
type: string;
|
|
29
|
+
};
|
|
30
|
+
type: string;
|
|
31
|
+
};
|
|
32
|
+
type TExportType = {
|
|
33
|
+
default?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
optional?: boolean;
|
|
36
|
+
properties?: Record<string, TExportType>;
|
|
37
|
+
type: string | Record<string, TExportType>;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/extractor/export/index.d.ts
|
|
41
|
+
declare class CTypeExport {
|
|
42
|
+
program: ts.Program;
|
|
43
|
+
checker: ts.TypeChecker;
|
|
44
|
+
index?: ts.SourceFile;
|
|
45
|
+
private cache;
|
|
46
|
+
private result?;
|
|
47
|
+
constructor(program: ts.Program);
|
|
48
|
+
get(target: string): TExportResult;
|
|
49
|
+
exportModule(module: ts.Symbol): void;
|
|
50
|
+
exportComponent(name: string, type: ts.Type): void;
|
|
51
|
+
exportFunction(name: string, signature: ts.Signature): void;
|
|
52
|
+
extractType(type: ts.Type, ctxNode?: ts.Node): void;
|
|
53
|
+
typeToString(type: ts.Type, flags?: number): string;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/extractor/generator.d.ts
|
|
57
|
+
type TExportNodeFunction = {
|
|
58
|
+
description?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
parameters?: Array<TSchema>;
|
|
61
|
+
return?: TSchema;
|
|
62
|
+
};
|
|
63
|
+
type TExportLogicComponent = {
|
|
64
|
+
emits: Record<string, TSchema>;
|
|
65
|
+
models: Record<string, TSchema>;
|
|
66
|
+
properties: Record<string, TSchema>;
|
|
67
|
+
slots: Record<string, TSchema>;
|
|
68
|
+
};
|
|
69
|
+
type TExportLogicResult = {
|
|
70
|
+
components: Record<string, TExportLogicComponent>;
|
|
71
|
+
functions: Record<string, TExportNodeFunction>;
|
|
72
|
+
types: Record<string, TSchema>;
|
|
73
|
+
};
|
|
74
|
+
declare function generateNodes(exportResult: TExportResult, packageName?: string): TExportLogicResult;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/extractor/source.d.ts
|
|
77
|
+
declare function getSourceFile(moduleName: string): {
|
|
78
|
+
program: ts$1.Program;
|
|
79
|
+
sourceFile: ts$1.SourceFile;
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/extractor/index.d.ts
|
|
83
|
+
declare function extractFile(filePath: string, target: string): Promise<void>;
|
|
84
|
+
//#endregion
|
|
85
|
+
export { CTypeExport, extractFile, generateNodes, getSourceFile };
|