@code0-tech/triangulum 0.30.0 → 0.30.2

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,1053 +0,0 @@
1
- import e, { flattenDiagnosticMessageText as t } from "typescript";
2
- import { DEFAULT_CONFIG as n, SchemaGenerator as r, createFormatter as i, createParser as a } from "ts-json-schema-generator";
3
- //#region node_modules/@typescript/vfs/dist/vfs.esm.js
4
- function o() {
5
- return o = Object.assign ? Object.assign.bind() : function(e) {
6
- for (var t = 1; t < arguments.length; t++) {
7
- var n = arguments[t];
8
- for (var r in n) ({}).hasOwnProperty.call(n, r) && (e[r] = n[r]);
9
- }
10
- return e;
11
- }, o.apply(null, arguments);
12
- }
13
- var s = !1;
14
- try {
15
- s = typeof localStorage < "u";
16
- } catch {}
17
- var c = typeof process < "u", l = s && typeof localStorage.getItem == "function" && /*#__PURE__*/ localStorage.getItem("DEBUG") || c && process.env.DEBUG ? console.log : function(e) {
18
- return "";
19
- };
20
- function u(e, t, n, r, i) {
21
- r === void 0 && (r = {});
22
- var a = o({}, p(n), r), s = _(e, t, a, n, i), c = s.languageServiceHost, l = s.updateFile, u = s.deleteFile, d = n.createLanguageService(c), f = d.getCompilerOptionsDiagnostics();
23
- if (f.length) {
24
- var m = g(e, r, n);
25
- throw Error(n.formatDiagnostics(f, m.compilerHost));
26
- }
27
- return {
28
- name: "vfs",
29
- sys: e,
30
- languageService: d,
31
- getSourceFile: function(e) {
32
- return d.getProgram()?.getSourceFile(e);
33
- },
34
- createFile: function(e, t) {
35
- l(n.createSourceFile(e, t, a.target, !1));
36
- },
37
- updateFile: function(e, t, r) {
38
- var i = d.getProgram().getSourceFile(e);
39
- if (!i) throw Error("Did not find a source file for " + e);
40
- var a = i.text, o = r ?? n.createTextSpan(0, a.length), s = a.slice(0, o.start) + t + a.slice(o.start + o.length);
41
- l(n.updateSourceFile(i, s, {
42
- span: o,
43
- newLength: t.length
44
- }));
45
- },
46
- deleteFile: function(e) {
47
- var t = d.getProgram().getSourceFile(e);
48
- t && u(t);
49
- }
50
- };
51
- }
52
- function d(e) {
53
- throw Error("Method '" + e + "' is not implemented.");
54
- }
55
- function f(e, t) {
56
- return function() {
57
- var n = [...arguments], r = t.apply(void 0, n), i = typeof r == "string" ? r.slice(0, 80) + "..." : r;
58
- return l.apply(void 0, ["> " + e].concat(n)), l("< " + i), r;
59
- };
60
- }
61
- var p = function(e) {
62
- return o({}, e.getDefaultCompilerOptions(), {
63
- jsx: e.JsxEmit.React,
64
- strict: !0,
65
- esModuleInterop: !0,
66
- module: e.ModuleKind.ESNext,
67
- suppressOutputPathCheck: !0,
68
- skipLibCheck: !0,
69
- skipDefaultLibCheck: !0
70
- }, e.versionMajorMinor && Number(e.versionMajorMinor.split(".")[0]) >= 6 ? { ignoreDeprecations: "6.0" } : { moduleResolution: e.ModuleResolutionKind.NodeJs });
71
- }, m = function(e) {
72
- return e.replace("/", "/lib.").toLowerCase();
73
- };
74
- function h(e) {
75
- return {
76
- args: [],
77
- createDirectory: function() {
78
- return d("createDirectory");
79
- },
80
- directoryExists: f("directoryExists", function(t) {
81
- return Array.from(e.keys()).some(function(e) {
82
- return e.startsWith(t);
83
- });
84
- }),
85
- exit: function() {
86
- return d("exit");
87
- },
88
- fileExists: f("fileExists", function(t) {
89
- return e.has(t) || e.has(m(t));
90
- }),
91
- getCurrentDirectory: function() {
92
- return "/";
93
- },
94
- getDirectories: function() {
95
- return [];
96
- },
97
- getExecutingFilePath: function() {
98
- return d("getExecutingFilePath");
99
- },
100
- readDirectory: f("readDirectory", function(t) {
101
- return t === "/" ? Array.from(e.keys()) : [];
102
- }),
103
- readFile: f("readFile", function(t) {
104
- return e.get(t) ?? e.get(m(t));
105
- }),
106
- resolvePath: function(e) {
107
- return e;
108
- },
109
- newLine: "\n",
110
- useCaseSensitiveFileNames: !0,
111
- write: function() {
112
- return d("write");
113
- },
114
- writeFile: function(t, n) {
115
- e.set(t, n);
116
- },
117
- deleteFile: function(t) {
118
- e.delete(t);
119
- }
120
- };
121
- }
122
- function g(e, t, n) {
123
- var r = /* @__PURE__ */ new Map(), i = function(e) {
124
- return r.set(e.fileName, e), e;
125
- };
126
- return {
127
- compilerHost: o({}, e, {
128
- getCanonicalFileName: function(e) {
129
- return e;
130
- },
131
- getDefaultLibFileName: function() {
132
- return "/" + n.getDefaultLibFileName(t);
133
- },
134
- getNewLine: function() {
135
- return e.newLine;
136
- },
137
- getSourceFile: function(a, o) {
138
- return r.get(a) || i(n.createSourceFile(a, e.readFile(a), o ?? t.target ?? p(n).target, !1));
139
- },
140
- useCaseSensitiveFileNames: function() {
141
- return e.useCaseSensitiveFileNames;
142
- }
143
- }),
144
- updateFile: function(t) {
145
- var n = r.has(t.fileName);
146
- return e.writeFile(t.fileName, t.text), r.set(t.fileName, t), n;
147
- },
148
- deleteFile: function(t) {
149
- var n = r.has(t.fileName);
150
- return r.delete(t.fileName), e.deleteFile(t.fileName), n;
151
- }
152
- };
153
- }
154
- function _(e, t, n, r, i) {
155
- var a = [].concat(t), s = g(e, n, r), c = s.compilerHost, l = s.updateFile, u = s.deleteFile, d = /* @__PURE__ */ new Map(), f = 0;
156
- return {
157
- languageServiceHost: o({}, c, {
158
- getProjectVersion: function() {
159
- return f.toString();
160
- },
161
- getCompilationSettings: function() {
162
- return n;
163
- },
164
- getCustomTransformers: function() {
165
- return i;
166
- },
167
- getScriptFileNames: function() {
168
- return a.slice();
169
- },
170
- getScriptSnapshot: function(t) {
171
- var n = e.readFile(t);
172
- if (n && typeof n == "string") return r.ScriptSnapshot.fromString(n);
173
- },
174
- getScriptVersion: function(e) {
175
- return d.get(e) || "0";
176
- },
177
- writeFile: e.writeFile
178
- }),
179
- updateFile: function(e) {
180
- f++, d.set(e.fileName, f.toString()), a.includes(e.fileName) || a.push(e.fileName), l(e);
181
- },
182
- deleteFile: function(e) {
183
- f++, d.set(e.fileName, f.toString());
184
- var t = a.indexOf(e.fileName);
185
- t !== -1 && a.splice(t, 1), u(e);
186
- }
187
- };
188
- }
189
- //#endregion
190
- //#region node_modules/lossless-json/lib/esm/utils.js
191
- function v(e) {
192
- return y.test(e);
193
- }
194
- var y = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
195
- //#endregion
196
- //#region node_modules/lossless-json/lib/esm/stringify.js
197
- function b(e, t, n, r) {
198
- let i = x(n);
199
- return a(typeof t == "function" ? t.call({ "": e }, "", e) : e, "");
200
- function a(e, t) {
201
- if (Array.isArray(r)) {
202
- let t = r.find((t) => t.test(e));
203
- if (t) {
204
- let n = t.stringify(e);
205
- if (typeof n != "string" || !v(n)) throw Error(`Invalid JSON number: output of a number stringifier must be a string containing a JSON number (output: ${n})`);
206
- return n;
207
- }
208
- }
209
- if (typeof e == "boolean" || typeof e == "number" || typeof e == "string" || e === null || e instanceof Date || e instanceof Boolean || e instanceof Number || e instanceof String) return JSON.stringify(e);
210
- if (e?.isLosslessNumber || typeof e == "bigint") return e.toString();
211
- if (Array.isArray(e)) return o(e, t);
212
- if (e && typeof e == "object") return s(e, t);
213
- }
214
- function o(e, n) {
215
- if (e.length === 0) return "[]";
216
- let r = i ? n + i : void 0, o = i ? "[\n" : "[";
217
- for (let n = 0; n < e.length; n++) {
218
- let s = typeof t == "function" ? t.call(e, String(n), e[n]) : e[n];
219
- i && (o += r), s !== void 0 && typeof s != "function" ? o += a(s, r) : o += "null", n < e.length - 1 && (o += i ? ",\n" : ",");
220
- }
221
- return o += i ? `\n${n}]` : "]", o;
222
- }
223
- function s(e, r) {
224
- if (typeof e.toJSON == "function") return b(e.toJSON(), t, n, void 0);
225
- let o = Array.isArray(t) ? t.map(String) : Object.keys(e);
226
- if (o.length === 0) return "{}";
227
- let s = i ? r + i : void 0, l = !0, u = i ? "{\n" : "{";
228
- for (let n of o) {
229
- let r = typeof t == "function" ? t.call(e, n, e[n]) : e[n];
230
- if (c(n, r)) {
231
- l ? l = !1 : u += i ? ",\n" : ",";
232
- let e = JSON.stringify(n);
233
- u += i ? `${s + e}: ` : `${e}:`, u += a(r, s);
234
- }
235
- }
236
- return u += i ? `\n${r}}` : "}", u;
237
- }
238
- function c(e, t) {
239
- return t !== void 0 && typeof t != "function" && typeof t != "symbol";
240
- }
241
- }
242
- function x(e) {
243
- if (typeof e == "number") return " ".repeat(e);
244
- if (typeof e == "string" && e !== "") return e;
245
- }
246
- //#endregion
247
- //#region src/util/values.util.ts
248
- var S = (t) => {
249
- if (e.isUnionTypeNode(t)) return t.types.flatMap(S);
250
- if (e.isLiteralTypeNode(t)) {
251
- let n = t.literal;
252
- if (e.isStringLiteral(n)) return [{
253
- value: n.text,
254
- __typename: "LiteralValue"
255
- }];
256
- if (e.isNumericLiteral(n)) return [{ value: Number(n.text) }];
257
- if (n.kind === e.SyntaxKind.TrueKeyword) return [{
258
- value: !0,
259
- __typename: "LiteralValue"
260
- }];
261
- if (n.kind === e.SyntaxKind.FalseKeyword) return [{
262
- value: !1,
263
- __typename: "LiteralValue"
264
- }];
265
- }
266
- return [];
267
- }, C = (t, n) => {
268
- if (n && t.aliasSymbol) {
269
- let n = t.aliasSymbol.declarations?.[0];
270
- if (n && e.isTypeAliasDeclaration(n)) return S(n.type);
271
- }
272
- return t.isUnion() ? t.types.flatMap((e) => C(e, n)) : t.isStringLiteral() ? [{
273
- value: t.value,
274
- __typename: "LiteralValue"
275
- }] : t.isNumberLiteral() ? [{ value: t.value.toString() }] : t.intrinsicName === "true" ? [{
276
- value: !0,
277
- __typename: "LiteralValue"
278
- }] : t.intrinsicName === "false" ? [{
279
- value: !1,
280
- __typename: "LiteralValue"
281
- }] : [];
282
- }, ee = (e, t, n, r) => r.flatMap((r) => {
283
- let i = r.getName();
284
- if (!te(i)) return [];
285
- let a = r.getDeclarations()?.[0];
286
- if (!a || a.getEnd() >= t.getEnd()) return [];
287
- let o = e.getTypeOfSymbolAtLocation(r, t);
288
- return i.startsWith("node_") ? ne(i, o, e, n) : i.startsWith("p_") ? re(i, o, e, n) : i.startsWith("flow_") ? ie(o, e, n) : [];
289
- }), te = (e) => e.startsWith("node_") || e.startsWith("p_") || e.startsWith("flow_"), ne = (t, n, r, i) => {
290
- if ((n.flags & e.TypeFlags.Void) !== 0) return [];
291
- let a = w(t.replace("node_", ""));
292
- return D(n, r, i).flatMap(({ path: e }) => {
293
- let t = {
294
- __typename: "ReferenceValue",
295
- nodeFunctionId: a
296
- };
297
- return e.length > 0 && (t.referencePath = e), t;
298
- });
299
- }, re = (e, t, n, r) => {
300
- let { nodeFunctionId: i, paramIndexFromName: a } = ae(e);
301
- if (!n.isTupleType(t)) return [];
302
- let o = t;
303
- return n.getTypeArguments(o).flatMap((e, t) => D(e, n, r).flatMap(({ path: e }) => {
304
- let n = {
305
- __typename: "ReferenceValue",
306
- nodeFunctionId: i,
307
- parameterIndex: isNaN(a) ? 0 : a,
308
- inputIndex: t,
309
- inputTypeIdentifier: o.target.labeledElementDeclarations?.[t].name.getText()
310
- };
311
- return e.length > 0 && (n.referencePath = e), n;
312
- }));
313
- }, ie = (e, t, n) => D(e, t, n).flatMap(({ path: e }) => {
314
- let t = {
315
- __typename: "ReferenceValue",
316
- nodeFunctionId: null
317
- };
318
- return e.length > 0 && (t.referencePath = e), t;
319
- }), w = (e) => e.replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/"), ae = (e) => {
320
- let t = e.replace("p_", ""), n = t.lastIndexOf("_"), r = t.substring(0, n), i = parseInt(t.substring(n + 1), 10);
321
- return {
322
- nodeFunctionId: w(r),
323
- paramIndexFromName: i
324
- };
325
- }, oe = 7, T = (e, t, n) => {
326
- let r = n.get(e);
327
- if (r !== void 0) return r;
328
- let i = /* @__PURE__ */ new Set(), a = (n) => {
329
- if (i.has(n) || !O(n)) return !1;
330
- i.add(n);
331
- for (let r of n.getProperties()) {
332
- if (!r.valueDeclaration) continue;
333
- let n = t.getNonNullableType(t.getTypeOfSymbolAtLocation(r, r.valueDeclaration));
334
- if (n === e || a(n)) return !0;
335
- }
336
- return !1;
337
- }, o = a(e);
338
- return n.set(e, o), o;
339
- }, E = (t, n, r) => t.isUnion() ? t.types.some((e) => E(n.getNonNullableType(e), n, r)) : (t.flags & e.TypeFlags.Never) === 0 && n.isTypeAssignableTo(t, r), se = (e, t) => e.isUnion() ? e.types.map((e) => t.getNonNullableType(e)).filter(O) : O(e) ? [e] : [], D = (e, t, n, r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map()) => {
340
- let o = [], s = t.getNonNullableType(e);
341
- return E(s, t, n) && o.push({
342
- path: r,
343
- type: e
344
- }), se(s, t).forEach((e) => {
345
- if (i.has(e) || r.length >= oe && T(e, t, a)) return;
346
- let s = e.getProperties();
347
- s && s.length > 0 && (i.add(e), s.forEach((e) => {
348
- let s = t.getTypeOfSymbolAtLocation(e, e.valueDeclaration), c = e.getName(), l = [...r, { path: c }];
349
- o.push(...D(s, t, n, l, i, a));
350
- }), i.delete(e));
351
- }), o;
352
- }, O = (t) => {
353
- let n = e.TypeFlags.String | e.TypeFlags.Number | e.TypeFlags.Boolean | e.TypeFlags.Undefined | e.TypeFlags.Null | e.TypeFlags.BigInt | e.TypeFlags.ESSymbol;
354
- return (t.flags & n) === 0;
355
- }, ce = (e, t, n, r) => R(r) ? [] : t.flatMap((t) => {
356
- let i = le(e, t, n, r);
357
- return i ? [i] : [];
358
- }), le = (t, n, r, i) => {
359
- if (n.parameters.length > 0) return null;
360
- let a = t.getSignatureFromDeclaration(n), o = ue(t, t.getReturnTypeOfSignature(a)), s = t.getNonNullableType(o);
361
- if ((s.flags & e.TypeFlags.Never) !== 0 || !t.isTypeAssignableTo(s, i)) return null;
362
- let c = de(n.name?.getText());
363
- return fe(r.find((e) => e.identifier === c));
364
- }, ue = (e, t) => t.isTypeParameter() ? e.getBaseConstraintOfType(t) || e.getAnyType() : t, de = (e) => e ? e.replace("fn_", "").replace("_", "::").replace("_", "::") : "", fe = (e) => {
365
- let t = (e?.parameterDefinitions?.nodes?.length ?? 0) > 0, n = {
366
- __typename: "NodeFunction",
367
- id: "gid://sagittarius/NodeFunction/1",
368
- functionDefinition: {
369
- __typename: "FunctionDefinition",
370
- id: e?.id,
371
- identifier: e?.identifier,
372
- names: e?.names,
373
- descriptions: e?.descriptions,
374
- displayIcon: e?.displayIcon
375
- }
376
- };
377
- return t && (n.parameters = pe(e?.parameterDefinitions?.nodes || [])), n;
378
- }, pe = (e) => ({
379
- __typename: "NodeParameterConnection",
380
- nodes: e.map((e) => me(e))
381
- }), me = (e) => ({
382
- __typename: "NodeParameter",
383
- parameterDefinition: {
384
- __typename: "ParameterDefinition",
385
- id: e?.id,
386
- identifier: e?.identifier
387
- },
388
- value: e?.defaultValue ? {
389
- __typename: "LiteralValue",
390
- value: e.defaultValue.value
391
- } : null
392
- }), he = (e, t, n, r) => R(r) ? t.flatMap((t) => {
393
- let i = ge(e, t, n, r);
394
- return i ? [i] : [];
395
- }) : [], ge = (e, t, n, r) => {
396
- let i = e.getTypeAtLocation(t);
397
- if (!e.isTypeAssignableTo(i, r)) return null;
398
- let a = _e(t.name?.getText()), o = n.find((e) => e.identifier === a);
399
- return o ? ve(o) : null;
400
- }, _e = (e) => e ? e.replace("fn_", "").replace("_", "::").replace("_", "::") : "", ve = (e) => ({
401
- __typename: "SubFlowValue",
402
- functionDefinition: e,
403
- signature: e.signature,
404
- settings: e.parameterDefinitions?.nodes?.map((e) => ({
405
- __typename: "SubFlowValueSetting",
406
- identifier: e?.identifier,
407
- defaultValue: e?.defaultValue ?? null,
408
- hidden: e?.hidden ?? !1,
409
- optional: e?.optional ?? !1
410
- }))
411
- }), k = { DATE: "date" }, A = (e) => e != null && e in k, ye = 7, j = (t, n, r, i, a, o = !0, s, c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map()) => {
412
- if ((r.flags & e.TypeFlags.TypeParameter) !== 0) {
413
- let u = r.symbol?.declarations?.[0];
414
- if (u && e.isTypeParameterDeclaration(u) && u.constraint) return j(t, n, t.getTypeFromTypeNode(u.constraint), i, a, o, s, c, l);
415
- }
416
- let u = t.typeToString(r), d = s ?? r, f = o ? { suggestions: [
417
- ...C(d, t),
418
- ...n ? ee(t, n, d, t.getSymbolsInScope(n, e.SymbolFlags.Variable)) : [],
419
- ...ce(t, i, a, d),
420
- ...he(t, i, a, d)
421
- ] } : {};
422
- if (r.isUnion()) {
423
- let o = r.types.filter((t) => (t.flags & (e.TypeFlags.Undefined | e.TypeFlags.Null)) === 0);
424
- if (o.length === 1) return {
425
- ...j(t, n, o[0], i, a, !1, void 0, c, l),
426
- type: u,
427
- ...f
428
- };
429
- }
430
- let p = Se(r);
431
- if (p) return {
432
- input: p,
433
- type: u,
434
- ...f
435
- };
436
- if (F(r)) return {
437
- input: "boolean",
438
- type: u,
439
- ...f
440
- };
441
- if (Te(r) || we(r)) return {
442
- input: "select",
443
- type: u,
444
- ...f
445
- };
446
- if (I(r)) return {
447
- input: "number",
448
- type: u,
449
- ...f
450
- };
451
- if (L(r)) return {
452
- input: "text",
453
- type: u,
454
- ...f
455
- };
456
- if (R(r)) return {
457
- input: "sub-flow",
458
- type: u,
459
- ...f
460
- };
461
- if (Ee(t, r)) return {
462
- input: "list",
463
- type: u,
464
- items: t.getTypeArguments(r).flatMap((e) => (e.isUnion() ? e.types : [e]).map((e) => j(t, n, e, i, a, o, void 0, c, l))),
465
- ...f
466
- };
467
- if ((r.flags & e.TypeFlags.Object) !== 0) {
468
- if (c.has(r) || c.size >= ye && T(r, t, l)) return {
469
- input: "data",
470
- type: u,
471
- ...f
472
- };
473
- c.add(r);
474
- let s = {}, d = [];
475
- for (let u of t.getPropertiesOfType(r)) {
476
- let r = u.valueDeclaration ?? u.declarations?.[0];
477
- if (!r) continue;
478
- let f = t.getTypeOfSymbolAtLocation(u, r), p = (u.flags & e.SymbolFlags.Optional) !== 0 || f.isUnion() && f.types.some((t) => (t.flags & (e.TypeFlags.Undefined | e.TypeFlags.Null)) !== 0), m = (f.isUnion() ? f.types.filter((t) => (t.flags & (e.TypeFlags.Undefined | e.TypeFlags.Null)) === 0) : [f]).map((e) => j(t, n, e, i, a, o, void 0, c, l));
479
- s[u.name] = m.length === 1 ? m[0] : m, p || d.push(u.name);
480
- }
481
- return c.delete(r), {
482
- input: "data",
483
- type: u,
484
- properties: s,
485
- required: d,
486
- ...f
487
- };
488
- }
489
- return {
490
- input: "generic",
491
- type: u,
492
- ...f
493
- };
494
- }, M = (e, t, n = !1) => {
495
- if (!e || e.input === "generic") return be(xe(t), n);
496
- let r = P(e.suggestions, t.suggestions);
497
- if (e.input === "data") {
498
- let n = e.properties ?? {}, i = t.input === "data" ? t.properties ?? {} : {}, a = {}, o = new Set([...Object.keys(n), ...Object.keys(i)]);
499
- for (let e of o) {
500
- let t = n[e], r = i[e];
501
- a[e] = N(t, r);
502
- }
503
- return {
504
- ...e,
505
- properties: a,
506
- ...r ? { suggestions: r } : {}
507
- };
508
- }
509
- if (e.input === "list") {
510
- let n = e.items ?? [], i = t.input === "list" ? t.items ?? [] : [], a = n.length === i.length && n.length > 0 ? n.map((e, t) => M(e, i[t])) : n;
511
- return {
512
- ...e,
513
- items: a,
514
- ...r ? { suggestions: r } : {}
515
- };
516
- }
517
- return {
518
- ...e,
519
- ...r ? { suggestions: r } : {}
520
- };
521
- }, N = (e, t) => e && !Array.isArray(e) && t && !Array.isArray(t) ? M(e, t) : e ?? t, P = (e, t) => {
522
- let n = [...e ?? [], ...t ?? []];
523
- if (n.length === 0) return;
524
- let r = /* @__PURE__ */ new Set(), i = [];
525
- for (let e of n) {
526
- let t = JSON.stringify(e);
527
- r.has(t) || (r.add(t), i.push(e));
528
- }
529
- return i;
530
- }, be = (e, t) => !t || e.input !== "generic" ? e : {
531
- input: "data",
532
- ...e.type ? { type: e.type } : {},
533
- properties: {},
534
- required: [],
535
- ...e.suggestions ? { suggestions: e.suggestions } : {}
536
- }, xe = (e) => {
537
- if (e.input !== "select") return e;
538
- let t = e.suggestions ?? [], n = /* @__PURE__ */ new Set();
539
- for (let e of t) {
540
- let t = typeof e.value;
541
- (t === "string" || t === "number" || t === "boolean") && n.add(t);
542
- }
543
- return {
544
- input: n.size === 1 ? {
545
- string: "text",
546
- number: "number",
547
- boolean: "boolean"
548
- }[[...n][0]] : "text",
549
- ...e.type ? { type: e.type } : {},
550
- ...t.length > 0 ? { suggestions: t } : {}
551
- };
552
- };
553
- function Se(e) {
554
- let t = e.aliasSymbol?.getName();
555
- return A(t) ? k[t] : void 0;
556
- }
557
- function F(t) {
558
- if ((t.flags & e.TypeFlags.Boolean) !== 0 || (t.flags & e.TypeFlags.BooleanLiteral) !== 0) return !0;
559
- if (t.isUnion()) {
560
- let n = t.types.filter((t) => (t.flags & (e.TypeFlags.Undefined | e.TypeFlags.Null)) === 0);
561
- return n.length > 0 && n.every((t) => (t.flags & e.TypeFlags.Boolean) !== 0 || (t.flags & e.TypeFlags.BooleanLiteral) !== 0);
562
- }
563
- return !1;
564
- }
565
- function I(t) {
566
- return (t.flags & e.TypeFlags.Number) !== 0 || (t.flags & e.TypeFlags.NumberLiteral) !== 0;
567
- }
568
- function L(t) {
569
- return (t.flags & e.TypeFlags.String) !== 0 || (t.flags & e.TypeFlags.StringLiteral) !== 0;
570
- }
571
- function Ce(e) {
572
- return L(e) || I(e) || F(e);
573
- }
574
- function we(t) {
575
- return (t.flags & e.TypeFlags.StringLiteral) !== 0 || (t.flags & e.TypeFlags.NumberLiteral) !== 0;
576
- }
577
- function Te(t) {
578
- if (!t.isUnion()) return !1;
579
- let n = t.types.filter((t) => (t.flags & (e.TypeFlags.Undefined | e.TypeFlags.Null)) === 0);
580
- return n.length > 0 && n.every(Ce);
581
- }
582
- function Ee(e, t) {
583
- return e.isArrayType(t) || e.isTupleType(t);
584
- }
585
- function R(e) {
586
- return e.getCallSignatures().length > 0;
587
- }
588
- //#endregion
589
- //#region src/utils.ts
590
- var De = "\n interface Array<T> { \n [n: number]: T; \n length: number; \n }\n interface String { readonly length: number; }\n interface Number { }\n interface Boolean { }\n interface Object { }\n interface Function { }\n interface CallableFunction extends Function {}\n interface NewableFunction extends Function {}\n interface IArguments { }\n interface RegExp { }\n \n declare namespace Utils {\n type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;\n }\n\n import ReturnType = Utils.ReturnType;\n";
591
- function z(t, n) {
592
- let r = /* @__PURE__ */ new Map();
593
- return r.set(t, n), r.set("lib.codezero.d.ts", De), u(h(r), [t, "lib.codezero.d.ts"], e, Oe);
594
- }
595
- var Oe = {
596
- target: e.ScriptTarget.Latest,
597
- lib: ["lib.codezero.d.ts"],
598
- noEmit: !0,
599
- strictNullChecks: !0
600
- };
601
- function ke(e) {
602
- let t = [], n = 0, r = null, i = "";
603
- for (let a of e) {
604
- if (r) a === r && (r = null);
605
- else if (a === "'" || a === "\"" || a === "`") r = a;
606
- else if (a === "<" || a === "{" || a === "(" || a === "[") n++;
607
- else if (a === ">" || a === "}" || a === ")" || a === "]") n--;
608
- else if (a === "," && n === 0) {
609
- t.push(i), i = "";
610
- continue;
611
- }
612
- i += a;
613
- }
614
- return t.push(i), t.map((e) => (e.trim().split(/\s+/).find((e) => e !== "const" && e !== "in" && e !== "out") ?? "").match(/^[A-Za-z_$][A-Za-z0-9_$]*/)?.[0] ?? "").filter((e) => e.length > 0);
615
- }
616
- function B(e, t = "any", n = !0) {
617
- let r = Array.from(new Set(e?.flatMap((e) => e.genericKeys || []).flatMap(ke))).map((e) => `type ${e} = ${t};`).join("\n"), i = e?.map((e) => {
618
- let t = (e.genericKeys?.length ?? 0) > 0 ? `<${e.genericKeys?.join(",")}>` : "", n = A(e.identifier) ? `${e.type} & {}` : e.type;
619
- return `type ${e.identifier}${t} = ${n};`;
620
- }).join("\n"), a = e?.filter((e) => (e.genericKeys?.length ?? 0) > 0).map((e) => `declare const __widen_${e.identifier}: ${e.identifier}<${e.genericKeys.map(() => "any").join(", ")}>;`).join("\n") ?? "";
621
- return `${n ? r : ""}\n${i}\n${a}`;
622
- }
623
- var V = (e) => e?.replace(/[^a-zA-Z0-9]/g, "_");
624
- function H(e, t, n, r = !1, i = !0) {
625
- let a = e?.nodes?.nodes || [], o = new Map(t?.map((e) => [e.identifier, e])), s = /* @__PURE__ */ new Set(), c = (t, n = "") => {
626
- let l = a.find((e) => e?.id === t);
627
- if (!l || !l.functionDefinition) return "";
628
- if (t?.includes("NodeFunction") && s.add(t), !o.get(l.functionDefinition.identifier)) return `${n}// Error: Function ${l.functionDefinition.identifier} not found\n`;
629
- let u = (l.parameters?.nodes || []).map((a, o) => {
630
- let s = a.value;
631
- if (!s) return r ? `/* @pos ${t} ${o} */ {}` : `/* @pos ${t} ${o} */ undefined`;
632
- if (s.__typename === "ReferenceValue") {
633
- let n = s, r = typeof n.inputIndex == "number" ? `p_${V(n.nodeFunctionId ?? "undefined")}_${n.parameterIndex}[${n.inputIndex}]` : n.nodeFunctionId ? `node_${V(n.nodeFunctionId)}` : `flow_${V(e?.id ?? "undefined")}`;
634
- return n.referencePath?.forEach((e) => {
635
- r += `?.${e.path}`;
636
- }), `/* @pos ${t} ${o} */ (${r})${i ? "!" : ""}`;
637
- }
638
- if (s.__typename === "LiteralValue") return `/* @pos ${t} ${o} */ ${s?.value !== null && s?.value !== void 0 ? b(s?.value) : void 0}`;
639
- if (s.__typename === "SubFlowValue") {
640
- let e = s;
641
- return `/* @pos ${t} ${o} */ (...${`p_${V(t)}_${o}`}) => {\n${c(e.startingNodeId || e.functionDefinition?.id, n + " ")}${n}}`;
642
- }
643
- return r ? `/* @pos ${t} ${o} */ {}` : `/* @pos ${t} ${o} */ undefined`;
644
- }), d = `node_${V(l.id)}`, f = `fn_${l?.functionDefinition?.identifier?.replace(/::/g, "_")}`;
645
- u.includes("undefined");
646
- let p = `${n}`;
647
- return l.functionDefinition.identifier === "std::control::return" ? (p += `const ${d} = /* @pos ${t} null */ ${f}(${u.join(", ")}) ;\n`, p += `return ${d};\n`) : l.functionDefinition.identifier === "std::control::if" ? (p += `const ${d} = /* @pos ${t} null */ ${f}(${u.join(", ")}) ;\n`, p += `if(${u[0]}) {
648
- ${c(l.parameters?.nodes?.[1]?.value?.startingNodeId || (l.parameters?.nodes?.[1]?.value)?.functionDefinition?.identifier, n + " ")}
649
- }`) : l.functionDefinition.identifier === "std::control::if_else" ? (p += `const ${d} = /* @pos ${t} null */ ${f}(${u.join(", ")}) ;\n`, p += `if(${u[0]}) {
650
- ${c(l.parameters?.nodes?.[1]?.value?.startingNodeId || (l.parameters?.nodes?.[1]?.value)?.functionDefinition?.identifier, n + " ")}
651
- } else {
652
- ${c(l.parameters?.nodes?.[2]?.value?.startingNodeId || (l.parameters?.nodes?.[2]?.value)?.functionDefinition?.identifier, n + " ")}
653
- }`) : p += `const ${d} = /* @pos ${t} null */ ${f}(${u.join(", ")}) ;\n`, l.nextNodeId && (p += c(l.nextNodeId, n)), p;
654
- }, l = B(n), u = `declare function flow${e?.signature ?? "(): void"}`, d = t?.map((e) => `declare function fn_${e.identifier?.replace(/::/g, "_")}${e.signature}`).join("\n"), f = new Set(a.map((e) => e?.nextNodeId).filter((e) => !!e)), p = /* @__PURE__ */ new Set();
655
- return a.forEach((e) => e?.parameters?.nodes?.forEach((e) => {
656
- e?.value?.__typename === "SubFlowValue" && (e.value.startingNodeId || e.value.functionDefinition?.id) && p.add(e.value.startingNodeId || e.value.functionDefinition?.id);
657
- })), `
658
- ${l}\n
659
- ${u}\n
660
- ${d}\n
661
- (() =>
662
- ${e ? `const flow_${V(e.id ?? "")} = /* @pos null null */ flow(${e.settings?.nodes?.map((e, t) => `/* @pos null ${t} */ ${e?.value !== null && e?.value !== void 0 ? b(e?.value) : void 0}`).join(", ") ?? ""});` : ""}
663
- ${a.filter((e) => e?.id && !f.has(e.id) && !p.has(e.id)).map((e) => c(e.id)).join("\n")}
664
- )();
665
- `;
666
- }
667
- //#endregion
668
- //#region src/extraction/getTypeFromValue.ts
669
- var Ae = (t, n) => {
670
- let r = b(t?.value);
671
- if (!r) return "any";
672
- let i = `
673
- ${B(n, "unknown")}
674
- const tempValue = ${r ?? "any"};
675
- `, a = "index.ts", o = z(a, i), s = o.getSourceFile(a), c = o.languageService.getProgram().getTypeChecker(), l = "any", u = (t) => {
676
- if (e.isVariableDeclaration(t) && t.name.getText() === "tempValue") {
677
- let n = c.getTypeAtLocation(t), r = (n) => {
678
- if (n.isUnion()) {
679
- let e = n.types.map(r);
680
- return Array.from(new Set(e)).sort().join(" | ");
681
- }
682
- if (c.isArrayType(n)) {
683
- let e = n.typeArguments || [], t = e.length > 0 ? r(e[0]) : "any";
684
- return e[0]?.isUnion() ? `(${t})[]` : `${t}[]`;
685
- }
686
- if (n.getFlags() & e.TypeFlags.Object || n.isClassOrInterface()) {
687
- let e = c.getPropertiesOfType(n);
688
- if (e.length > 0) return `{ ${e.map((e) => {
689
- let n = c.getTypeOfSymbolAtLocation(e, t);
690
- return `${e.getName()}: ${r(n)}`;
691
- }).join(", ")} }`;
692
- }
693
- let i = c.getBaseTypeOfLiteralType(n);
694
- return c.typeToString(i, t);
695
- };
696
- l = r(n);
697
- }
698
- e.forEachChild(t, u);
699
- };
700
- return u(s), l;
701
- }, je = (t, n) => {
702
- let r = `
703
- ${B(n)}
704
- type Target = ${t};
705
- `, i = "index.ts", a = z(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), c = o.statements.find((t) => e.isTypeAliasDeclaration(t) && t.name.text === "Target");
706
- if (!c) return {
707
- __typename: "LiteralValue",
708
- value: null
709
- };
710
- let l = s.getTypeAtLocation(c.type), u = (t, n, r = /* @__PURE__ */ new Set()) => {
711
- let i = new Set(r);
712
- if (i.has(t)) return null;
713
- let a = t.getFlags();
714
- if (t.isUnion()) {
715
- if (n.type, e.isTypeAliasDeclaration(n) && n.type && e.isUnionTypeNode(n.type)) return u(s.getTypeFromTypeNode(n.type.types[0]), n, i);
716
- let r = t.types.filter((t) => {
717
- let n = t.getFlags();
718
- return !(n & e.TypeFlags.Undefined) && !(n & e.TypeFlags.Null);
719
- });
720
- return u(r.length > 0 ? r[0] : t.types[0], n, i);
721
- }
722
- if (a & e.TypeFlags.StringLiteral) return t.value;
723
- if (a & e.TypeFlags.String) return "";
724
- if (a & e.TypeFlags.NumberLiteral) return t.value;
725
- if (a & e.TypeFlags.Number) return 0;
726
- if (a & e.TypeFlags.BooleanLiteral) return t.intrinsicName === "true";
727
- if (a & e.TypeFlags.Boolean) return !1;
728
- if (s.isArrayType(t)) {
729
- i.add(t);
730
- let e = u(t.typeArguments?.[0] || s.getAnyType(), n, i);
731
- return e === null ? [] : [e];
732
- }
733
- if (t.isClassOrInterface() || a & e.TypeFlags.Object || t.getProperties().length > 0) {
734
- i.add(t);
735
- let e = {};
736
- return t.getProperties().forEach((t) => {
737
- let r = s.getTypeOfSymbolAtLocation(t, n), a = t.valueDeclaration;
738
- r && (e[t.getName()] = u(r, a || n, i));
739
- }), e;
740
- }
741
- return null;
742
- };
743
- return {
744
- __typename: "LiteralValue",
745
- value: u(l, c)
746
- };
747
- }, U = {
748
- ...n,
749
- expose: "none",
750
- topRef: !1,
751
- jsDoc: "none",
752
- skipTypeCheck: !0
753
- }, Me = (e, t) => {
754
- let n = Object.keys(e);
755
- if (n.length === 0) return {};
756
- let r = Pe(Ne(e, t)), i = {};
757
- for (let e of n) try {
758
- i[e] = Fe(r.createSchema(e));
759
- } catch {
760
- i[e] = {};
761
- }
762
- return i;
763
- }, Ne = (e, t) => {
764
- let n = Object.entries(e).map(([e, t]) => `export type ${e} = ${t};`).join("\n");
765
- return `${B(t)}\n${n}`;
766
- }, Pe = (e) => {
767
- let t = z("index.ts", e).languageService.getProgram();
768
- return new r(t, a(t, U), i(U), U);
769
- }, Fe = (e) => {
770
- let { $schema: t, definitions: n, ...r } = e, i = n && Object.keys(n).length > 0 ? {
771
- ...r,
772
- definitions: n
773
- } : r;
774
- return JSON.parse(JSON.stringify(i));
775
- }, Ie = (e, t, n) => {
776
- if (!e) return;
777
- let r = "index.ts", i = z(r, H(e, t, n)), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = Me({
778
- ...Le(o, a),
779
- ...Re(o, a, e)
780
- }, n), c = (e.nodes?.nodes ?? []).map((e) => e && Be(e, s));
781
- return {
782
- ...e,
783
- inputSchema: s[W] ?? J(),
784
- outputSchema: s[G] ?? Y(),
785
- nodes: {
786
- ...e.nodes,
787
- nodes: c
788
- }
789
- };
790
- }, W = "Flow_input", G = "Flow_output", K = (e, t, n) => `Node_${V(e)}_${t}_${n}`, Le = (t, n) => {
791
- let r = n.statements.filter(e.isFunctionDeclaration).find((e) => e.name?.getText() === "flow");
792
- if (!r) return {};
793
- let i = t.getSignatureFromDeclaration(r);
794
- if (!i) return {};
795
- let { input: a, output: o } = q(t, i, r);
796
- return {
797
- [W]: a,
798
- [G]: o
799
- };
800
- }, Re = (e, t, n) => {
801
- let r = Ue(t), i = {};
802
- for (let t of n.nodes?.nodes ?? []) {
803
- if (!t?.id) continue;
804
- let n = t.parameters?.nodes;
805
- if (!n?.some(X)) continue;
806
- let a = He(r, t), o = a ? e.getResolvedSignature(a) : void 0;
807
- o && n.forEach((n, r) => {
808
- if (!X(n)) return;
809
- let s = ze(e, o, a, r);
810
- if (!s) return;
811
- let { input: c, output: l } = q(e, s, a);
812
- i[K(t.id, r, "input")] = c, i[K(t.id, r, "output")] = l;
813
- });
814
- }
815
- return i;
816
- }, ze = (e, t, n, r) => {
817
- let i = t.parameters[r];
818
- if (i) return e.getTypeOfSymbolAtLocation(i, n).getCallSignatures()[0];
819
- }, q = (t, n, r) => {
820
- let i = (n) => t.typeToString(n, r, e.TypeFormatFlags.NoTruncation);
821
- return {
822
- input: `{ ${n.parameters.map((e) => {
823
- let n = t.getTypeOfSymbolAtLocation(e, e.valueDeclaration ?? r), a = Ve(e) ? "?" : "";
824
- return `${e.getName()}${a}: ${i(n)}`;
825
- }).join("; ")} }`,
826
- output: i(t.getReturnTypeOfSignature(n))
827
- };
828
- }, J = () => ({ type: "object" }), Y = () => ({}), Be = (e, t) => {
829
- let n = e.parameters?.nodes;
830
- if (!n?.some(X)) return e;
831
- let r = n.map((n, r) => {
832
- if (!X(n)) return n;
833
- let i = {
834
- ...n.value,
835
- inputSchema: t[K(e.id, r, "input")] ?? J(),
836
- outputSchema: t[K(e.id, r, "output")] ?? Y()
837
- };
838
- return {
839
- ...n,
840
- value: i
841
- };
842
- });
843
- return {
844
- ...e,
845
- parameters: {
846
- ...e.parameters,
847
- nodes: r
848
- }
849
- };
850
- }, X = (e) => e?.value?.__typename === "SubFlowValue", Ve = (t) => {
851
- let n = t.valueDeclaration;
852
- return !!n && e.isParameter(n) && (!!n.questionToken || !!n.initializer || !!n.dotDotDotToken);
853
- }, He = (t, n) => {
854
- let r = t.get(`node_${V(n.id)}`)?.initializer;
855
- return r && e.isCallExpression(r) ? r : void 0;
856
- }, Ue = (t) => {
857
- let n = /* @__PURE__ */ new Map();
858
- return t.statements.forEach((t) => {
859
- t.forEachChild(function t(r) {
860
- e.isVariableDeclaration(r) && (r.parent.flags & e.NodeFlags.Const) !== 0 && n.set(r.name.getText(), r), r.forEachChild(t);
861
- });
862
- }), n;
863
- }, We = 2345, Ge = 2339, Z = (e, t, n) => {
864
- if (e.getStart() > t || e.getEnd() < n) return;
865
- let r = e;
866
- return e.forEachChild((e) => {
867
- let i = Z(e, t, n);
868
- i && (r = i);
869
- }), r;
870
- }, Ke = (t, n, r) => {
871
- if (t.start === void 0 || t.length === void 0) return !1;
872
- let i = Z(n, t.start, t.start + t.length);
873
- if (!i) return !1;
874
- if (t.code === We && e.isExpression(i)) {
875
- let t = r.getTypeAtLocation(i);
876
- if (!t.isUnion()) return !1;
877
- let n = r.getContextualType(i);
878
- return n ? t.types.some((t) => (t.flags & (e.TypeFlags.Null | e.TypeFlags.Undefined)) === 0 && r.isTypeAssignableTo(t, n)) : !1;
879
- }
880
- if (t.code === Ge && e.isPropertyAccessExpression(i.parent)) {
881
- let e = r.getNonNullableType(r.getTypeAtLocation(i.parent.expression));
882
- if (!e.isUnion()) return !1;
883
- let t = i.getText();
884
- return e.types.some((e) => e.getProperty(t) !== void 0);
885
- }
886
- return !1;
887
- }, qe = (e, n, r) => {
888
- if (!e?.startingNodeId) return {
889
- isValid: !1,
890
- returnType: "void",
891
- diagnostics: [{
892
- nodeId: null,
893
- parameterIndex: null,
894
- code: 0,
895
- message: "You need to provide a starting node to be able to execute this flow.",
896
- severity: "error"
897
- }]
898
- };
899
- if (!e.nodes?.nodes?.find((t) => t?.id == e.startingNodeId)) return {
900
- isValid: !1,
901
- returnType: "void",
902
- diagnostics: [{
903
- nodeId: null,
904
- parameterIndex: null,
905
- code: 0,
906
- message: "The starting node is not linked within the flow. Please make sure the starting node is connected to the rest of the flow.",
907
- severity: "error"
908
- }]
909
- };
910
- let i = new Set(n?.map((e) => e.identifier)), a = (e.nodes?.nodes ?? []).filter((e) => e?.functionDefinition && !i.has(e.functionDefinition.identifier)).map((e) => ({
911
- nodeId: e.id,
912
- parameterIndex: null,
913
- code: 0,
914
- message: `The function definition "${e.functionDefinition.identifier}" is not reachable.`,
915
- severity: "error"
916
- }));
917
- if (a.length > 0) return {
918
- isValid: !1,
919
- returnType: "void",
920
- diagnostics: a
921
- };
922
- let o = H(e, n, r, !1, !1), s = "index.ts", c = z(s, o), l = c.getSourceFile(s), u = c.languageService.getProgram(), d = u.getTypeChecker(), f = u.getSemanticDiagnostics(l).map((e) => {
923
- let n = t(e.messageText, "\n"), r, i = null;
924
- if (e.start !== void 0) {
925
- let t = l.getFullText(), n = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(n, a), s = /\/\* @pos ([^ ]+) (\d+|null) \*\//g, c, u = null, d = -1;
926
- for (; (c = s.exec(o)) !== null;) {
927
- let t = n + c.index + c[0].length;
928
- t <= e.start && t > d && (d = t, u = c);
929
- }
930
- u && (r = u[1] === "null" ? null : u[1], i = parseInt(u[2], 10));
931
- }
932
- let a = Ke(e, l, d) ? "warning" : "error";
933
- return {
934
- message: n,
935
- code: e.code,
936
- severity: a,
937
- nodeId: r,
938
- parameterIndex: typeof i == "number" && Number.isSafeInteger(i) ? i : null
939
- };
940
- }).filter((e) => e !== null);
941
- return {
942
- isValid: !f.some((e) => e?.severity === "error"),
943
- returnType: "void",
944
- diagnostics: f
945
- };
946
- }, Je = (t, n, r) => {
947
- let i = b(n?.value), a = `
948
- ${B(r)}
949
- const testValue: ${t} = ${i};
950
- `, o = "index.ts", s = z(o, a).languageService.getSemanticDiagnostics(o).map((t) => {
951
- let n = e.flattenDiagnosticMessageText(t.messageText, "\n"), r = n.includes("not assignable to parameter of type") && (n.includes("'{}'") || n.includes("undefined")) || n.includes("not assignable to type 'undefined'") || n.includes("not assignable to type 'void'") || n.includes("may be a mistake because neither type sufficiently overlaps");
952
- return {
953
- message: n,
954
- code: t.code,
955
- severity: r ? "warning" : "error"
956
- };
957
- });
958
- return {
959
- isValid: !s.some((e) => e.severity === "error"),
960
- returnType: "void",
961
- diagnostics: s
962
- };
963
- }, Ye = (t, n, r, i) => {
964
- let a = H(t, r, n), o = "index.ts", s = z(o, a), c = s.getSourceFile(o), l = s.languageService.getProgram().getTypeChecker(), u = t.nodes?.nodes?.find((e) => e?.id === i), d = i ? `fn_${u?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", f = i ? `node_${V(i)}` : `flow_${V(t.id)}`, p = Xe(c), m = Ze(c).get(f), h = p.get(d), g = Qe(l, m), _ = $e(l, h, m), v = g?.map((t, n) => (t.flags & e.TypeFlags.Undefined) === 0 ? t : _?.[n] ?? t), y = (u?.parameters?.nodes ?? []).map((e) => e?.value != null), b = tt(l, m, v, _, et(h, g, y), i ? p : /* @__PURE__ */ new Map(), i ? r : [], y), x = Q(l, m, h);
965
- return {
966
- nodeId: i,
967
- parameters: b,
968
- return: x ? j(l, m, x, Array.from(p.values()), r, !1) : { input: "generic" }
969
- };
970
- }, Q = (t, n, r) => {
971
- if (n?.initializer && e.isCallExpression(n.initializer)) {
972
- let e = t.getResolvedSignature(n.initializer);
973
- if (e) return t.getReturnTypeOfSignature(e);
974
- }
975
- if (r) {
976
- let e = t.getSignatureFromDeclaration(r);
977
- if (e) return t.getReturnTypeOfSignature(e);
978
- }
979
- }, Xe = (t) => new Map(t.statements.filter(e.isFunctionDeclaration).map((e) => [e.name.getText(), e])), Ze = (t) => {
980
- let n = [];
981
- return t.statements.forEach((t) => {
982
- t.forEachChild(function t(r) {
983
- e.isVariableDeclaration(r) && (r.parent.flags & e.NodeFlags.Const) !== 0 && n.push([r.name.getText(), r]), r.forEachChild(t);
984
- });
985
- }), new Map(n);
986
- }, Qe = (t, n) => {
987
- if (!(!n?.initializer || !e.isCallExpression(n.initializer))) return t.getResolvedSignature(n.initializer)?.parameters.map((e) => t.getTypeOfSymbolAtLocation(e, n.initializer));
988
- }, $e = (e, t, n) => {
989
- if (!(!t || !n?.initializer)) return t.parameters.map((t) => {
990
- let r = e.getSymbolAtLocation(t.name);
991
- return e.getTypeOfSymbolAtLocation(r, n.initializer);
992
- });
993
- }, et = (t, n, r = []) => {
994
- let i = t.typeParameters?.map((e) => e.name.getText()) || [], a = {};
995
- t.parameters.forEach((t, n) => {
996
- if (!t.type) return;
997
- let r = /* @__PURE__ */ new Set();
998
- t.type.forEachChild(function n(a) {
999
- if (e.isTypeReferenceNode(a) && e.isIdentifier(a.typeName)) {
1000
- let e = a.typeName.text;
1001
- i.includes(e) && r.add(e);
1002
- }
1003
- if (e.isTypeReferenceNode(t.type) && e.isIdentifier(t.type.typeName)) {
1004
- let e = t.type.typeName.text;
1005
- i.includes(e) && r.add(e);
1006
- }
1007
- a.forEachChild(n);
1008
- }), r.forEach((e) => {
1009
- a[e] || (a[e] = []), a[e].push(n);
1010
- });
1011
- });
1012
- let o = Object.values(a).filter((e) => e.length > 1).map(([e, ...t]) => t.map((t) => ({
1013
- parameterIndex: t,
1014
- dependsOnIndex: e
1015
- }))).flat();
1016
- return n ? o.filter((t) => {
1017
- if (r[t.dependsOnIndex]) return !1;
1018
- let i = n[t.parameterIndex];
1019
- if (!i) return !0;
1020
- let a = (i.flags & e.TypeFlags.Null) !== 0, o = (i.flags & e.TypeFlags.Undefined) !== 0;
1021
- return a || o;
1022
- }) : o;
1023
- }, tt = (e, t, n, r, i, a, o, s) => n ? n.map((n, c) => {
1024
- let l = r?.[c], u = l ? nt(e, l, t) : void 0, d = j(e, t, n, Array.from(a.values()), o, !0, u);
1025
- return {
1026
- schema: M(l ? j(e, t, l, Array.from(a.values()), o, !1) : void 0, d, s[c] ?? !1),
1027
- blockedBy: i.filter((e) => e.parameterIndex === c).map((e) => e.dependsOnIndex)
1028
- };
1029
- }) : [], nt = (t, n, r) => {
1030
- if ((n.flags & e.TypeFlags.TypeParameter) !== 0) {
1031
- let r = n.symbol?.declarations?.[0];
1032
- return r && e.isTypeParameterDeclaration(r) && r.constraint ? t.getTypeFromTypeNode(r.constraint) : t.getAnyType();
1033
- }
1034
- if ((n.flags & e.TypeFlags.Conditional) !== 0) return t.getBaseConstraintOfType(n) ?? t.getAnyType();
1035
- if ((n.flags & e.TypeFlags.Object) !== 0 && $(n, t, /* @__PURE__ */ new Set())) {
1036
- let i = n.aliasSymbol?.getName();
1037
- if (i) {
1038
- let n = t.getSymbolsInScope(r, e.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${i}`);
1039
- if (n) return t.getTypeOfSymbolAtLocation(n, r);
1040
- }
1041
- return t.getAnyType();
1042
- }
1043
- return n;
1044
- }, $ = (t, n, r) => r.has(t) ? !1 : (r.add(t), !!((t.flags & e.TypeFlags.TypeParameter) !== 0 || (t.flags & e.TypeFlags.Object) !== 0 && (n.getTypeArguments(t).some((e) => $(e, n, r)) || t.aliasTypeArguments?.some((e) => $(e, n, r))))), rt = (t, n = []) => {
1045
- let r = "index.ts", i = z(r, `${B(n)}\ntype MyType = ${t}`).languageService.getProgram(), a = i?.getSourceFile(r), o = i?.getTypeChecker();
1046
- if (!a || !o) return;
1047
- let s = a.statements.filter((t) => e.isTypeAliasDeclaration(t) || e.isInterfaceDeclaration(t) || e.isClassDeclaration(t)).pop();
1048
- if (!s) return;
1049
- let c = o.getTypeAtLocation(s);
1050
- if (c) return j(o, void 0, c, [], [], !1);
1051
- };
1052
- //#endregion
1053
- export { Ie as getFlowSchemas, qe as getFlowValidation, Ye as getSignatureSchema, Ae as getTypeFromValue, rt as getTypeSchema, je as getValueFromType, Je as getValueValidation };