@luna-park/plugin 1.8.0 → 2.0.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.
@@ -1,608 +0,0 @@
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: "array"
96
- };
97
- },
98
- boolean: (args = {}) => {
99
- return {
100
- ...args,
101
- type: "boolean"
102
- };
103
- },
104
- exec: (args = {}) => {
105
- return {
106
- ...args,
107
- type: "exec"
108
- };
109
- },
110
- function: createFunction,
111
- interface: (interfaceClass, args = {}) => {
112
- return {
113
- ...args,
114
- className: typeof interfaceClass === "string" ? interfaceClass : interfaceClass.name,
115
- type: "interface"
116
- };
117
- },
118
- number: (args = {}) => {
119
- return {
120
- ...args,
121
- type: "number"
122
- };
123
- },
124
- object: (properties = {}, args = {}) => {
125
- return {
126
- ...args,
127
- properties,
128
- type: "object"
129
- };
130
- },
131
- record: (key, value, args = {}) => {
132
- return {
133
- ...args,
134
- key,
135
- type: "record",
136
- value
137
- };
138
- },
139
- string: (args = {}) => {
140
- return {
141
- ...args,
142
- type: "string"
143
- };
144
- },
145
- type: createType,
146
- undefined: (args = {}) => {
147
- return {
148
- ...args,
149
- type: "undefined"
150
- };
151
- },
152
- union: (elements, args = {}) => {
153
- return {
154
- ...args,
155
- elements,
156
- type: "union"
157
- };
158
- },
159
- unknown: (args = {}) => {
160
- return {
161
- ...args,
162
- type: "unknown"
163
- };
164
- },
165
- void: (args = {}) => {
166
- return {
167
- ...args,
168
- type: "void"
169
- };
170
- }
171
- };
172
- function createFunction(inputs = [], output = LogicType.void(), args = {}) {
173
- if (Array.isArray(inputs)) return createFunction(LogicType.object(Object.fromEntries(inputs)), output, args);
174
- return {
175
- ...args,
176
- inputs,
177
- output,
178
- type: "function"
179
- };
180
- }
181
- function createType(target, args = {}) {
182
- return {
183
- ...args,
184
- target,
185
- type: "type"
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
- const wrappers = [
243
- ["(", ")"],
244
- ["[", "]"],
245
- ["{", "}"],
246
- ["<", ">"],
247
- ["'", "'"],
248
- ["\"", "\""]
249
- ];
250
- function lexer(scan) {
251
- return cleanArray(splitUntil(scan, ";"));
252
- }
253
- function getUntil(scan, until, depth = 1) {
254
- const result = [];
255
- const opening = wrappers.find((wrapper) => wrapper[1] === until)?.[0];
256
- while (scan.length) {
257
- if (scan[0] === opening) {}
258
- if (scan[0] === until) {
259
- depth--;
260
- if (depth <= 0) break;
261
- }
262
- const element = getFirstElement(scan);
263
- result.push(element);
264
- if (depth === 0 && typeof element === "object" && element.type === "wrap" && element.style.endsWith(until)) break;
265
- }
266
- scan.shift();
267
- return result;
268
- }
269
- function eraseUntil(scan, until) {
270
- while (scan.length) {
271
- if (scan[0] === until) {
272
- scan.shift();
273
- break;
274
- }
275
- scan.shift();
276
- }
277
- }
278
- function splitUntil(scan, until) {
279
- const result = [[]];
280
- while (scan.length) {
281
- if (scan[0] === until) {
282
- result.push([]);
283
- scan.shift();
284
- continue;
285
- }
286
- result.at(-1).push(getFirstElement(scan));
287
- }
288
- return result.filter((chunk) => chunk.length);
289
- }
290
- function getFirstElement(scan) {
291
- let element = scan.shift();
292
- let exportFlag = false;
293
- if (element === "export") {
294
- exportFlag = true;
295
- element = scan.shift();
296
- if (element === "=") return {
297
- content: scan.shift(),
298
- type: "export"
299
- };
300
- if (element === "as") {
301
- eraseUntil(scan, ";");
302
- return getFirstElement(scan);
303
- }
304
- }
305
- if (element === "declare") element = scan.shift();
306
- if (element === "namespace") {
307
- const name = scan.shift();
308
- scan.shift();
309
- const content = splitUntil(getUntil(scan, "}", 0), ";");
310
- scan.unshift(";");
311
- return {
312
- content,
313
- export: exportFlag,
314
- name,
315
- type: element
316
- };
317
- }
318
- if (element === "function") {
319
- const name = scan.shift();
320
- const then = scan.shift();
321
- const result = {
322
- name,
323
- type: element
324
- };
325
- if (then === "<") {
326
- result.template = getUntil(scan, ">");
327
- scan.shift();
328
- }
329
- const params = splitUntil(getUntil(scan, ")", 0), ",");
330
- result.export = exportFlag;
331
- result.params = params;
332
- if (scan[0] === ":") {
333
- scan.shift();
334
- result.returns = getUntil(scan, ";");
335
- }
336
- scan.unshift(";");
337
- return result;
338
- }
339
- if (element === "interface") {
340
- const name = scan.shift();
341
- scan.shift();
342
- const content = splitUntil(getUntil(scan, "}", 0), ";");
343
- scan.unshift(";");
344
- return {
345
- content,
346
- name,
347
- type: "interface"
348
- };
349
- }
350
- if (element === "type" && /^[A-Za-z0-9]*$/.test(scan[0])) {
351
- const name = scan.shift();
352
- const then = scan.shift();
353
- const result = {
354
- name,
355
- type: element
356
- };
357
- if (then === "<") {
358
- result.template = getUntil(scan, ">");
359
- scan.shift();
360
- }
361
- result.content = getUntil(scan, ";");
362
- scan.unshift(";");
363
- return result;
364
- }
365
- if (element === "enum") {
366
- const name = scan.shift();
367
- scan.shift();
368
- const content = getUntil(scan, "}");
369
- scan.unshift(";");
370
- return {
371
- name,
372
- options: Object.fromEntries(content.join("").split(",").filter((item) => item.trim()).map((item) => {
373
- if (item.includes("=")) {
374
- const [name, value] = item.split("=");
375
- return [JSON.parse(value), name];
376
- }
377
- return [name, name];
378
- })),
379
- type: "enum"
380
- };
381
- }
382
- if (typeof element === "string" && element.startsWith("/*")) return {
383
- content: cleanComment(element),
384
- type: "comment"
385
- };
386
- for (const wrapper of wrappers) if (element === wrapper[0]) return {
387
- content: splitUntil(getUntil(scan, wrapper[1]), ";").map((item) => splitUntil(item, ",")).map((item) => splitUntil(item, "|")),
388
- style: wrapper.join(""),
389
- type: "wrap"
390
- };
391
- return element;
392
- }
393
- function cleanArray(input) {
394
- if (Array.isArray(input)) {
395
- if (input.length === 1) return cleanArray(input[0]);
396
- return input.map((element) => cleanArray(element));
397
- }
398
- if (typeof input === "object" && input !== null) return objectMap(input, ({ value }) => cleanArray(value));
399
- return input;
400
- }
401
- function cleanComment(comment) {
402
- comment = comment.trim();
403
- if (!(comment.startsWith("/**") && comment.endsWith("*/"))) return comment;
404
- comment = comment.slice(3, -2).split("\n").map((line) => {
405
- const trim = line.trim();
406
- if (trim.startsWith("* ")) return trim.slice(2);
407
- return trim;
408
- }).join("\n").trim();
409
- return comment.trim();
410
- }
411
- function cleanUnion(schema) {
412
- if (schema.elements.find((element) => ["undefined", "void"].includes(element.type))) {
413
- schema.optional = true;
414
- schema.elements = schema.elements.filter((element) => !["undefined", "void"].includes(element.type));
415
- }
416
- const childUnions = schema.elements.filter((element) => element.type === "union");
417
- if (childUnions.length > 0) {
418
- schema.elements = schema.elements.filter((element) => element.type !== "union");
419
- for (const childUnion of childUnions) schema.elements.push(...childUnion.elements);
420
- }
421
- const stringElements = schema.elements.filter((element) => element.type === "string");
422
- if (stringElements.length > 1) {
423
- const enumValues = [];
424
- let anyFlag = false;
425
- for (const element of stringElements) if (element.enum) enumValues.push(...element.enum);
426
- else anyFlag = true;
427
- schema.elements = schema.elements.filter((element) => element.type !== "string");
428
- if (anyFlag) schema.elements.push(LogicType.string());
429
- else schema.elements.push(LogicType.string({ enum: enumValues }));
430
- }
431
- const numberElements = schema.elements.filter((element) => element.type === "number");
432
- if (numberElements.length > 1) {
433
- const enumValues = [];
434
- let anyFlag = false;
435
- for (const element of numberElements) if (element.enum) enumValues.push(...element.enum);
436
- else anyFlag = true;
437
- schema.elements = schema.elements.filter((element) => element.type !== "number");
438
- if (anyFlag) schema.elements.push(LogicType.number());
439
- else schema.elements.push(LogicType.number({ enum: enumValues }));
440
- }
441
- if (schema.elements.length === 1) {
442
- const simpleSchema = schema.elements[0];
443
- simpleSchema.optional = schema.optional;
444
- return simpleSchema;
445
- }
446
- if (schema.elements.length === 0) return LogicType.void();
447
- return schema;
448
- }
449
- function cleanInterface(schema) {
450
- if (schema.className === "Array") return LogicType.array(schema.options.template[0]);
451
- if (schema.className === "Type" && schema.options?.template?.[0]?.enum?.length) {
452
- const reference = schema.options.template[0].enum[0];
453
- const target = (Array.isArray(reference) ? reference.join("") : String(reference)).split("/");
454
- return LogicType.type(target, schema.optional ? { optional: true } : {});
455
- }
456
- if (schema.className === "keyof") return LogicType.string();
457
- if (schema.className === "Record") return LogicType.object({});
458
- if (schema.className === "PropertyKey") return LogicType.union([LogicType.string(), LogicType.number()]);
459
- if ([
460
- "Promise",
461
- "Partial",
462
- "Required"
463
- ].includes(schema.className)) return LogicUtil[schema.className.toLocaleLowerCase()](schema.options.template[0]);
464
- if (["Omit", "Pick"].includes(schema.className)) return LogicUtil[schema.className.toLocaleLowerCase()](schema.options.template[0], schema.options.template[1]?.enum);
465
- return schema;
466
- }
467
- function scanner(input) {
468
- const elements = [];
469
- input = input.replaceAll(/ +/g, " ");
470
- input = input.replaceAll(/\s*\n\s*/g, "\n");
471
- while (input.length) {
472
- if ([" ", "\n"].includes(input[0])) {
473
- input = input.slice(1);
474
- continue;
475
- }
476
- if (input.startsWith("/*")) {
477
- const commentEnd = input.indexOf("*/");
478
- elements.push(input.slice(0, commentEnd + 2));
479
- input = input.slice(commentEnd + 2);
480
- continue;
481
- }
482
- const startingWord = input.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];
483
- if (startingWord) {
484
- input = input.slice(startingWord.length);
485
- elements.push(startingWord);
486
- continue;
487
- }
488
- const startingNumber = input.match(/^([0-9]+)/)?.[0];
489
- if (startingNumber) {
490
- input = input.slice(startingNumber.length);
491
- elements.push(startingNumber);
492
- continue;
493
- }
494
- if (input[0] === ">" && elements.at(-1) === "=") {
495
- elements.pop();
496
- elements.push("=>");
497
- input = input.slice(1);
498
- continue;
499
- }
500
- elements.push(input[0]);
501
- input = input.slice(1);
502
- }
503
- return elements;
504
- }
505
- function parser(element, options = {}) {
506
- if (typeof element === "string") {
507
- if (element === "string") return LogicType.string(options);
508
- if (element === "number") return LogicType.number(options);
509
- if (element === "boolean") return LogicType.boolean(options);
510
- if (element === "undefined") return LogicType.void(options);
511
- if (["unknown", "any"].includes(element)) return LogicType.unknown(options);
512
- if (["undefined", "null"].includes(element)) return LogicType.undefined(options);
513
- return cleanInterface(LogicType.interface(element, options));
514
- }
515
- if (Array.isArray(element)) {
516
- if (element[0] === "readonly") element.shift();
517
- if (element.length === 1) return parser(element[0], options);
518
- if (element.includes("|")) return cleanUnion(LogicType.union(separate(element, (element) => element === "|").map((element) => parser(element)), options));
519
- if (element.includes("&")) return cleanUnion(LogicType.union(separate(element, (element) => element === "&").map((element) => parser(element)), options));
520
- if (element.at(-1)?.type === "wrap" && element.at(-1).style === "[]") return LogicType.array(parser(element.slice(0, -1)), options);
521
- if (element[0] === "import" && element[2] === ".") return parser(element.slice(3), options);
522
- if (element.length === 2) {
523
- if (element[1].type === "wrap") {
524
- if (element[1].style === "<>") {
525
- let template = element[1].content;
526
- if (!Array.isArray(template)) template = [template];
527
- if (!Array.isArray(template[0])) {
528
- if (template.some((element) => element.type === "wrap" && element.style === "[]") || template.some((element) => element.type === "wrap" && element.style === "<>") || template.includes("&") || template.includes("|")) template = [template];
529
- else template = template.map((element) => [element]);
530
- }
531
- template = template.map((element) => parser(element));
532
- return cleanInterface(LogicType.interface(element[0], {
533
- ...options,
534
- options: { template }
535
- }));
536
- }
537
- }
538
- }
539
- if (element.length === 3) {
540
- if (element[1] === "=>") {
541
- const parameters = !element[0].content.length || Array.isArray(element[0].content[0]) ? element[0].content : [element[0].content];
542
- return LogicType.function(LogicType.object(Object.fromEntries(parameters.map((parameter) => {
543
- return [parameter[0], parser(parameter.slice(2))];
544
- }))), parser(element[2]));
545
- }
546
- }
547
- return parser(element[0], options);
548
- }
549
- if (typeof element === "object" && element !== null) {
550
- if (element.type === "wrap") {
551
- if (["''", "\"\""].includes(element.style)) return LogicType.string({
552
- ...options,
553
- enum: [element.content]
554
- });
555
- if (element.style === "{}") {
556
- const content = !element.content.length || Array.isArray(element.content[0]) ? element.content : [element.content];
557
- 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);
558
- }
559
- if (element.style === "[]") {
560
- if (element.content[1] === ":") return LogicType.array(parser(element.content.slice(2)), options);
561
- return LogicType.array(parser(element.content), options);
562
- }
563
- if (element.style === "()") return parser(element.content, options);
564
- }
565
- }
566
- console.log("Unknown element");
567
- console.log(element);
568
- return LogicType.unknown();
569
- }
570
- function separate(result, separator) {
571
- const output = [[]];
572
- for (const element of result) if (separator(element)) output.push([]);
573
- else output[output.length - 1].push(element);
574
- return output;
575
- }
576
- function typeToSchema(type) {
577
- try {
578
- if (/^[A-Za-z]+\??:/.test(type)) {
579
- const [, name, optional, rest] = type.match(/([A-Za-z]+)(\??):(.*)/);
580
- const schema = parser(lexer(scanner(rest)));
581
- schema.name = name;
582
- if (optional === "?") schema.optional = true;
583
- return schema;
584
- }
585
- return parser(lexer(scanner(type)));
586
- } catch (error) {
587
- console.error("Failed to parse type", type);
588
- console.error(error);
589
- return LogicType.unknown();
590
- }
591
- }
592
- function schemaLoop(schema, func, key) {
593
- schema = func({
594
- key,
595
- schema
596
- }) || schema;
597
- if (schema.type === "object") for (const key in schema.properties) schema.properties[key] = schemaLoop(schema.properties[key], func, key);
598
- if (schema.type === "array") schema.items = schemaLoop(schema.items, func);
599
- if (schema.type === "record") schema.value = schemaLoop(schema.value, func);
600
- if (schema.type === "function") {
601
- schema.inputs = schemaLoop(schema.inputs, func);
602
- schema.output = schemaLoop(schema.output, func);
603
- }
604
- if (schema.type === "union") for (const key in schema.elements) schema.elements[key] = schemaLoop(schema.elements[key], func);
605
- return schema;
606
- }
607
- //#endregion
608
- 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 };