@code0-tech/triangulum 0.2.0 → 0.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.
@@ -1,101 +1,101 @@
1
- import v, { flattenDiagnosticMessageText as Z } from "typescript";
2
- function A() {
3
- return A = Object.assign ? Object.assign.bind() : function(e) {
4
- for (var t = 1; t < arguments.length; t++) {
5
- var n = arguments[t];
6
- for (var r in n) ({}).hasOwnProperty.call(n, r) && (e[r] = n[r]);
1
+ import d, { flattenDiagnosticMessageText as Z } from "typescript";
2
+ function R() {
3
+ return R = Object.assign ? Object.assign.bind() : function(t) {
4
+ for (var n = 1; n < arguments.length; n++) {
5
+ var i = arguments[n];
6
+ for (var r in i) ({}).hasOwnProperty.call(i, r) && (t[r] = i[r]);
7
7
  }
8
- return e;
9
- }, A.apply(null, arguments);
8
+ return t;
9
+ }, R.apply(null, arguments);
10
10
  }
11
- var W = !1;
11
+ var K = !1;
12
12
  try {
13
- W = typeof localStorage < "u";
13
+ K = typeof localStorage < "u";
14
14
  } catch {
15
15
  }
16
- var X = typeof process < "u", ee = W && typeof localStorage.getItem == "function" && /* @__PURE__ */ localStorage.getItem("DEBUG") || X && process.env.DEBUG, J = ee ? console.log : function(e) {
16
+ var X = typeof process < "u", ee = K && typeof localStorage.getItem == "function" && /* @__PURE__ */ localStorage.getItem("DEBUG") || X && process.env.DEBUG, W = ee ? console.log : function(t) {
17
17
  return "";
18
18
  };
19
- function te(e, t, n, r, o) {
19
+ function te(t, n, i, r, g) {
20
20
  r === void 0 && (r = {});
21
- var c = A({}, G(n), r), s = re(e, t, c, n, o), a = s.languageServiceHost, u = s.updateFile, m = s.deleteFile, g = n.createLanguageService(a), p = g.getCompilerOptionsDiagnostics();
22
- if (p.length) {
23
- var i = Y(e, r, n);
24
- throw new Error(n.formatDiagnostics(p, i.compilerHost));
21
+ var l = R({}, Y(i), r), p = re(t, n, l, i, g), u = p.languageServiceHost, c = p.updateFile, f = p.deleteFile, a = i.createLanguageService(u), F = a.getCompilerOptionsDiagnostics();
22
+ if (F.length) {
23
+ var s = G(t, r, i);
24
+ throw new Error(i.formatDiagnostics(F, s.compilerHost));
25
25
  }
26
26
  return {
27
27
  // @ts-ignore
28
28
  name: "vfs",
29
- sys: e,
30
- languageService: g,
31
- getSourceFile: function(F) {
32
- var f;
33
- return (f = g.getProgram()) == null ? void 0 : f.getSourceFile(F);
29
+ sys: t,
30
+ languageService: a,
31
+ getSourceFile: function(e) {
32
+ var o;
33
+ return (o = a.getProgram()) == null ? void 0 : o.getSourceFile(e);
34
34
  },
35
- createFile: function(F, f) {
36
- u(n.createSourceFile(F, f, c.target, !1));
35
+ createFile: function(e, o) {
36
+ c(i.createSourceFile(e, o, l.target, !1));
37
37
  },
38
- updateFile: function(F, f, T) {
39
- var d = g.getProgram().getSourceFile(F);
40
- if (!d)
41
- throw new Error("Did not find a source file for " + F);
42
- var S = d.text, y = T ?? n.createTextSpan(0, S.length), x = S.slice(0, y.start) + f + S.slice(y.start + y.length), h = n.updateSourceFile(d, x, {
43
- span: y,
44
- newLength: f.length
38
+ updateFile: function(e, o, m) {
39
+ var v = a.getProgram().getSourceFile(e);
40
+ if (!v)
41
+ throw new Error("Did not find a source file for " + e);
42
+ var T = v.text, S = m ?? i.createTextSpan(0, T.length), C = T.slice(0, S.start) + o + T.slice(S.start + S.length), w = i.updateSourceFile(v, C, {
43
+ span: S,
44
+ newLength: o.length
45
45
  });
46
- u(h);
46
+ c(w);
47
47
  },
48
- deleteFile: function(F) {
49
- var f = g.getProgram().getSourceFile(F);
50
- f && m(f);
48
+ deleteFile: function(e) {
49
+ var o = a.getProgram().getSourceFile(e);
50
+ o && f(o);
51
51
  }
52
52
  };
53
53
  }
54
- function R(e) {
55
- throw new Error("Method '" + e + "' is not implemented.");
54
+ function I(t) {
55
+ throw new Error("Method '" + t + "' is not implemented.");
56
56
  }
57
- function w(e, t) {
57
+ function k(t, n) {
58
58
  return function() {
59
- for (var n = arguments.length, r = new Array(n), o = 0; o < n; o++)
60
- r[o] = arguments[o];
61
- var c = t.apply(void 0, r), s = typeof c == "string" ? c.slice(0, 80) + "..." : c;
62
- return J.apply(void 0, ["> " + e].concat(r)), J("< " + s), c;
59
+ for (var i = arguments.length, r = new Array(i), g = 0; g < i; g++)
60
+ r[g] = arguments[g];
61
+ var l = n.apply(void 0, r), p = typeof l == "string" ? l.slice(0, 80) + "..." : l;
62
+ return W.apply(void 0, ["> " + t].concat(r)), W("< " + p), l;
63
63
  };
64
64
  }
65
- var G = function(t) {
66
- return A({}, t.getDefaultCompilerOptions(), {
67
- jsx: t.JsxEmit.React,
65
+ var Y = function(n) {
66
+ return R({}, n.getDefaultCompilerOptions(), {
67
+ jsx: n.JsxEmit.React,
68
68
  strict: !0,
69
69
  esModuleInterop: !0,
70
- module: t.ModuleKind.ESNext,
70
+ module: n.ModuleKind.ESNext,
71
71
  suppressOutputPathCheck: !0,
72
72
  skipLibCheck: !0,
73
73
  skipDefaultLibCheck: !0
74
- }, t.versionMajorMinor && Number(t.versionMajorMinor.split(".")[0]) >= 6 ? {
74
+ }, n.versionMajorMinor && Number(n.versionMajorMinor.split(".")[0]) >= 6 ? {
75
75
  ignoreDeprecations: "6.0"
76
76
  } : {
77
- moduleResolution: t.ModuleResolutionKind.NodeJs
77
+ moduleResolution: n.ModuleResolutionKind.NodeJs
78
78
  });
79
- }, K = function(t) {
80
- return t.replace("/", "/lib.").toLowerCase();
79
+ }, J = function(n) {
80
+ return n.replace("/", "/lib.").toLowerCase();
81
81
  };
82
- function ne(e) {
82
+ function ne(t) {
83
83
  return {
84
84
  args: [],
85
85
  createDirectory: function() {
86
- return R("createDirectory");
86
+ return I("createDirectory");
87
87
  },
88
88
  // TODO: could make a real file tree
89
- directoryExists: w("directoryExists", function(t) {
90
- return Array.from(e.keys()).some(function(n) {
91
- return n.startsWith(t);
89
+ directoryExists: k("directoryExists", function(n) {
90
+ return Array.from(t.keys()).some(function(i) {
91
+ return i.startsWith(n);
92
92
  });
93
93
  }),
94
94
  exit: function() {
95
- return R("exit");
95
+ return I("exit");
96
96
  },
97
- fileExists: w("fileExists", function(t) {
98
- return e.has(t) || e.has(K(t));
97
+ fileExists: k("fileExists", function(n) {
98
+ return t.has(n) || t.has(J(n));
99
99
  }),
100
100
  getCurrentDirectory: function() {
101
101
  return "/";
@@ -104,77 +104,77 @@ function ne(e) {
104
104
  return [];
105
105
  },
106
106
  getExecutingFilePath: function() {
107
- return R("getExecutingFilePath");
107
+ return I("getExecutingFilePath");
108
108
  },
109
- readDirectory: w("readDirectory", function(t) {
110
- return t === "/" ? Array.from(e.keys()) : [];
109
+ readDirectory: k("readDirectory", function(n) {
110
+ return n === "/" ? Array.from(t.keys()) : [];
111
111
  }),
112
- readFile: w("readFile", function(t) {
113
- var n;
114
- return (n = e.get(t)) != null ? n : e.get(K(t));
112
+ readFile: k("readFile", function(n) {
113
+ var i;
114
+ return (i = t.get(n)) != null ? i : t.get(J(n));
115
115
  }),
116
- resolvePath: function(n) {
117
- return n;
116
+ resolvePath: function(i) {
117
+ return i;
118
118
  },
119
119
  newLine: `
120
120
  `,
121
121
  useCaseSensitiveFileNames: !0,
122
122
  write: function() {
123
- return R("write");
123
+ return I("write");
124
124
  },
125
- writeFile: function(n, r) {
126
- e.set(n, r);
125
+ writeFile: function(i, r) {
126
+ t.set(i, r);
127
127
  },
128
- deleteFile: function(n) {
129
- e.delete(n);
128
+ deleteFile: function(i) {
129
+ t.delete(i);
130
130
  }
131
131
  };
132
132
  }
133
- function Y(e, t, n) {
134
- var r = /* @__PURE__ */ new Map(), o = function(a) {
135
- return r.set(a.fileName, a), a;
136
- }, c = {
137
- compilerHost: A({}, e, {
138
- getCanonicalFileName: function(a) {
139
- return a;
133
+ function G(t, n, i) {
134
+ var r = /* @__PURE__ */ new Map(), g = function(u) {
135
+ return r.set(u.fileName, u), u;
136
+ }, l = {
137
+ compilerHost: R({}, t, {
138
+ getCanonicalFileName: function(u) {
139
+ return u;
140
140
  },
141
141
  getDefaultLibFileName: function() {
142
- return "/" + n.getDefaultLibFileName(t);
142
+ return "/" + i.getDefaultLibFileName(n);
143
143
  },
144
144
  // '/lib.d.ts',
145
145
  // getDefaultLibLocation: () => '/',
146
146
  getNewLine: function() {
147
- return e.newLine;
147
+ return t.newLine;
148
148
  },
149
- getSourceFile: function(a, u) {
150
- var m;
151
- return r.get(a) || o(n.createSourceFile(a, e.readFile(a), (m = u ?? t.target) != null ? m : G(n).target, !1));
149
+ getSourceFile: function(u, c) {
150
+ var f;
151
+ return r.get(u) || g(i.createSourceFile(u, t.readFile(u), (f = c ?? n.target) != null ? f : Y(i).target, !1));
152
152
  },
153
153
  useCaseSensitiveFileNames: function() {
154
- return e.useCaseSensitiveFileNames;
154
+ return t.useCaseSensitiveFileNames;
155
155
  }
156
156
  }),
157
- updateFile: function(a) {
158
- var u = r.has(a.fileName);
159
- return e.writeFile(a.fileName, a.text), r.set(a.fileName, a), u;
157
+ updateFile: function(u) {
158
+ var c = r.has(u.fileName);
159
+ return t.writeFile(u.fileName, u.text), r.set(u.fileName, u), c;
160
160
  },
161
- deleteFile: function(a) {
162
- var u = r.has(a.fileName);
163
- return r.delete(a.fileName), e.deleteFile(a.fileName), u;
161
+ deleteFile: function(u) {
162
+ var c = r.has(u.fileName);
163
+ return r.delete(u.fileName), t.deleteFile(u.fileName), c;
164
164
  }
165
165
  };
166
- return c;
166
+ return l;
167
167
  }
168
- function re(e, t, n, r, o) {
169
- var c = [].concat(t), s = Y(e, n, r), a = s.compilerHost, u = s.updateFile, m = s.deleteFile, g = /* @__PURE__ */ new Map(), p = 0, i = A({}, a, {
168
+ function re(t, n, i, r, g) {
169
+ var l = [].concat(n), p = G(t, i, r), u = p.compilerHost, c = p.updateFile, f = p.deleteFile, a = /* @__PURE__ */ new Map(), F = 0, s = R({}, u, {
170
170
  getProjectVersion: function() {
171
- return p.toString();
171
+ return F.toString();
172
172
  },
173
173
  getCompilationSettings: function() {
174
- return n;
174
+ return i;
175
175
  },
176
176
  getCustomTransformers: function() {
177
- return o;
177
+ return g;
178
178
  },
179
179
  // A couple weeks of 4.8 TypeScript nightlies had a bug where the Program's
180
180
  // list of files was just a reference to the array returned by this host method,
@@ -185,31 +185,74 @@ function re(e, t, n, r, o) {
185
185
  // is used in bisecting for changes, it needs to guard against being busted in that
186
186
  // couple-week period, so we defensively make a slice here.
187
187
  getScriptFileNames: function() {
188
- return c.slice();
188
+ return l.slice();
189
189
  },
190
- getScriptSnapshot: function(f) {
191
- var T = e.readFile(f);
192
- if (T && typeof T == "string")
193
- return r.ScriptSnapshot.fromString(T);
190
+ getScriptSnapshot: function(o) {
191
+ var m = t.readFile(o);
192
+ if (m && typeof m == "string")
193
+ return r.ScriptSnapshot.fromString(m);
194
194
  },
195
- getScriptVersion: function(f) {
196
- return g.get(f) || "0";
195
+ getScriptVersion: function(o) {
196
+ return a.get(o) || "0";
197
197
  },
198
- writeFile: e.writeFile
199
- }), l = {
200
- languageServiceHost: i,
201
- updateFile: function(f) {
202
- p++, g.set(f.fileName, p.toString()), c.includes(f.fileName) || c.push(f.fileName), u(f);
198
+ writeFile: t.writeFile
199
+ }), y = {
200
+ languageServiceHost: s,
201
+ updateFile: function(o) {
202
+ F++, a.set(o.fileName, F.toString()), l.includes(o.fileName) || l.push(o.fileName), c(o);
203
203
  },
204
- deleteFile: function(f) {
205
- p++, g.set(f.fileName, p.toString());
206
- var T = c.indexOf(f.fileName);
207
- T !== -1 && c.splice(T, 1), m(f);
204
+ deleteFile: function(o) {
205
+ F++, a.set(o.fileName, F.toString());
206
+ var m = l.indexOf(o.fileName);
207
+ m !== -1 && l.splice(m, 1), f(o);
208
208
  }
209
209
  };
210
- return l;
210
+ return y;
211
211
  }
212
- const ie = `
212
+ const ie = (t, n, i) => {
213
+ if (!t) return { parameters: [], returnType: "any" };
214
+ const r = t.id || "temp_node_id", g = {
215
+ ...t,
216
+ id: r,
217
+ parameters: {
218
+ ...t.parameters,
219
+ nodes: t.parameters?.nodes?.map((e) => e?.value ? e : { ...e, value: null }) || []
220
+ }
221
+ }, l = r + "_params", p = {
222
+ ...g,
223
+ id: l,
224
+ parameters: {
225
+ ...g.parameters,
226
+ nodes: g.parameters.nodes.map((e) => e.value?.__typename === "LiteralValue" && e.value.value !== null && typeof e.value.value != "object" ? { ...e, value: null } : e)
227
+ }
228
+ }, c = se({
229
+ nodes: { __typename: "NodeFunctionConnection", nodes: [g, p] }
230
+ }, n, i), f = L(r), a = L(l), F = c.parameters.get(f) || [], s = c.parameters.get(a) || [];
231
+ return {
232
+ parameters: F.map((e, o) => {
233
+ const m = s[o];
234
+ return m && m !== "any" && m !== "unknown" ? m : e;
235
+ }),
236
+ returnType: c.nodes.get(f) || "any"
237
+ };
238
+ };
239
+ var H = /* @__PURE__ */ ((t) => (t[t.PRIMITIVE = 0] = "PRIMITIVE", t[t.TYPE = 1] = "TYPE", t[t.ARRAY = 2] = "ARRAY", t[t.OBJECT = 3] = "OBJECT", t[t.NODE = 4] = "NODE", t))(H || {});
240
+ const q = (t, n) => {
241
+ const r = `
242
+ ${O(n)}
243
+ type TargetType = ${t};
244
+ const val: TargetType = {} as any;
245
+ `, g = "index.ts", l = A(g, r), p = l.getSourceFile(g), c = l.languageService.getProgram().getTypeChecker();
246
+ let f = 1;
247
+ const a = (F) => {
248
+ if (d.isVariableDeclaration(F) && F.name.getText() === "val") {
249
+ const s = c.getTypeAtLocation(F);
250
+ s.getCallSignatures().length > 0 ? f = 4 : c.isArrayType(s) ? f = 2 : s.isStringLiteral() || s.isNumberLiteral() || (s.getFlags() & (d.TypeFlags.String | d.TypeFlags.Number | d.TypeFlags.Boolean | d.TypeFlags.EnumLiteral | d.TypeFlags.BigInt | d.TypeFlags.ESSymbol)) !== 0 ? f = 0 : (s.isClassOrInterface() || (s.getFlags() & d.TypeFlags.Object) !== 0) && s.getProperties().length > 0 ? f = 3 : f = 1;
251
+ }
252
+ d.forEachChild(F, a);
253
+ };
254
+ return a(p), f;
255
+ }, ae = `
213
256
  interface Array<T> {
214
257
  [n: number]: T;
215
258
  length: number;
@@ -223,568 +266,358 @@ const ie = `
223
266
  interface NewableFunction extends Function {}
224
267
  interface IArguments { }
225
268
  interface RegExp { }
269
+ type Record<K extends keyof any, T> = { [P in K]: T; };
226
270
  type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
227
271
  `;
228
- function I(e, t) {
229
- const n = /* @__PURE__ */ new Map();
230
- n.set(e, t), n.set("lib.codezero.d.ts", ie);
231
- const r = ne(n);
232
- return te(r, [e, "lib.codezero.d.ts"], v, oe);
272
+ function A(t, n) {
273
+ const i = /* @__PURE__ */ new Map();
274
+ i.set(t, n), i.set("lib.codezero.d.ts", ae);
275
+ const r = ne(i);
276
+ return te(r, [t, "lib.codezero.d.ts"], d, oe);
233
277
  }
234
278
  const oe = {
235
- target: v.ScriptTarget.Latest,
279
+ target: d.ScriptTarget.Latest,
236
280
  lib: ["lib.codezero.d.ts"],
237
281
  noEmit: !0,
238
282
  strictNullChecks: !0
239
283
  };
240
- function E(e) {
241
- const t = Array.from(new Set(e.flatMap((r) => r.genericKeys || []))).map((r) => `type ${r} = any;`).join(`
242
- `), n = e.map(
243
- (r) => `type ${r.identifier}${r.genericKeys ? `<${r.genericKeys.join(",")}>` : ""} = ${r.type};`
284
+ function O(t) {
285
+ const n = Array.from(new Set(t?.flatMap((r) => r.genericKeys || []))).map((r) => `type ${r} = any;`).join(`
286
+ `), i = t?.map(
287
+ (r) => `type ${r.identifier}${(r.genericKeys?.length ?? 0) > 0 ? `<${r.genericKeys?.join(",")}>` : ""} = ${r.type};`
244
288
  ).join(`
245
289
  `);
246
- return `${t}
247
- ${n}`;
290
+ return `${n}
291
+ ${i}`;
248
292
  }
249
- function ae(e, t) {
250
- let n = e;
251
- for (const r of t) {
252
- if (n == null) return "unknown";
253
- typeof r.path == "string" && (n = n[r.path]);
254
- }
255
- return typeof n;
256
- }
257
- function B(e, t) {
258
- const n = e.nodes;
259
- if (n)
260
- return Array.isArray(n) ? n.find((r) => r.id === t) : n.nodes?.find((r) => r.id === t);
293
+ const L = (t) => t.replace(/[^a-zA-Z0-9]/g, "_");
294
+ function U(t, n, i, r = !1) {
295
+ const g = t?.nodes?.nodes || [], l = new Map(n?.map((e) => [e.identifier, e])), p = /* @__PURE__ */ new Set(), u = (e, o, m) => {
296
+ const v = g.find((P) => P?.id === e);
297
+ if (!v || !v.functionDefinition?.identifier) return "undefined";
298
+ const S = (v.parameters?.nodes || []).map((P, x) => {
299
+ const E = P.value;
300
+ if (!E) return r ? `/* @pos ${e} ${x} */ {}` : `/* @pos ${e} ${x} */ undefined`;
301
+ if (E.__typename === "ReferenceValue") {
302
+ const $ = E;
303
+ if (!$.nodeFunctionId) return `/* @pos ${e} ${x} */ undefined`;
304
+ let N = $.inputIndex !== void 0 ? `p_${L($.nodeFunctionId)}_${$.parameterIndex}[${$.inputIndex}]` : `node_${L($.nodeFunctionId)}`;
305
+ return $.referencePath?.forEach((h) => {
306
+ N += `?.${h.path}`;
307
+ }), `/* @pos ${e} ${x} */ ${N}`;
308
+ }
309
+ return E.__typename === "LiteralValue" ? `/* @pos ${e} ${x} */ ${JSON.stringify(E.value)}` : E.__typename === "NodeFunctionIdWrapper" ? u(E.id, e, x) : r ? `/* @pos ${e} ${x} */ ({} as any)` : `/* @pos ${e} ${x} */ undefined`;
310
+ }).join(", "), w = `${`fn_${v.functionDefinition.identifier.replace(/::/g, "_")}`}(${S})`;
311
+ return o !== void 0 && m !== void 0 ? `${w}` : w;
312
+ }, c = (e, o = "") => {
313
+ if (p.has(e)) return "";
314
+ const m = g.find((N) => N?.id === e);
315
+ if (!m || !m.functionDefinition) return "";
316
+ if (p.add(e), !l.get(m.functionDefinition.identifier)) return `${o}// Error: Function ${m.functionDefinition.identifier} not found
317
+ `;
318
+ let T = { parameters: [] };
319
+ r || (T = ie(m, n, i));
320
+ const C = (m.parameters?.nodes || []).map((N, h) => {
321
+ const b = N.value;
322
+ if (!b) return r ? `/* @pos ${e} ${h} */ {}` : `/* @pos ${e} ${h} */ undefined`;
323
+ if (b.__typename === "ReferenceValue") {
324
+ const _ = b;
325
+ if (!_.nodeFunctionId) return `/* @pos ${e} ${h} */ undefined`;
326
+ let D = _.inputIndex !== void 0 ? `p_${L(_.nodeFunctionId)}_${_.parameterIndex}[${_.inputIndex}]` : `node_${L(_.nodeFunctionId)}`;
327
+ return _.referencePath?.forEach((V) => {
328
+ D += `?.${V.path}`;
329
+ }), `/* @pos ${e} ${h} */ ${D}`;
330
+ }
331
+ if (b.__typename === "LiteralValue") return `/* @pos ${e} ${h} */ ${JSON.stringify(b.value)}`;
332
+ if (b.__typename === "NodeFunctionIdWrapper") {
333
+ const _ = b;
334
+ if (r) {
335
+ const D = `p_${L(e)}_${h}`, V = c(_.id, o + " ");
336
+ return `/* @pos ${e} ${h} */ (...${D}) => {
337
+ ${V}${o}}`;
338
+ } else {
339
+ const D = T.parameters[h];
340
+ if (D ? q(D, i) === H.NODE : !1) {
341
+ const M = `p_${L(e)}_${h}`, j = c(_.id, o + " ");
342
+ return `/* @pos ${e} ${h} */ (...${M}) => {
343
+ ${j}${o}}`;
344
+ } else {
345
+ const M = u(_.id, e, h);
346
+ return `/* @pos ${e} ${h} */ ${M}`;
347
+ }
348
+ }
349
+ }
350
+ return r ? `/* @pos ${e} ${h} */ {}` : `/* @pos ${e} ${h} */ undefined`;
351
+ }).join(", "), w = `node_${L(m.id)}`, P = `fn_${m?.functionDefinition?.identifier?.replace(/::/g, "_")}`, x = C.includes("undefined"), E = m.functionDefinition.identifier === "std::control::return";
352
+ let $ = `${o}${E ? "return " : `const ${w} = `}${P}(${C}) ;
353
+ `;
354
+ return m.nextNodeId && ($ += c(m.nextNodeId, o)), $;
355
+ }, f = O(i), a = n?.map((e) => `declare function fn_${e.identifier?.replace(/::/g, "_")}${e.signature}`).join(`
356
+ `), F = new Set(g.map((e) => e?.nextNodeId).filter((e) => !!e)), s = /* @__PURE__ */ new Set();
357
+ g.forEach((e) => e?.parameters?.nodes?.forEach((o) => {
358
+ o?.value?.__typename === "NodeFunctionIdWrapper" && o.value.id && s.add(o.value.id);
359
+ }));
360
+ const y = g.filter((e) => e?.id && !F.has(e.id) && !s.has(e.id)).map((e) => c(e.id)).join(`
361
+ `);
362
+ return `${f}
363
+ ${a}
364
+
365
+ // --- Flow ---
366
+ ${y}`;
261
367
  }
262
- function q(e, t, n) {
263
- const r = e?.value;
264
- if (!r) return "undefined";
265
- if (r.__typename === "ReferenceValue") {
266
- const o = r, c = B(t, o.nodeFunctionId);
267
- if (!c) return "undefined";
268
- let s = n(t, c).returnType;
269
- if (o.referencePath && o.referencePath.length > 0) {
270
- let a;
271
- const u = c.parameters?.nodes;
272
- if (u && u.length > 0) {
273
- const m = u[0];
274
- m?.value?.__typename === "LiteralValue" && (a = m.value.value);
368
+ function se(t, n, i) {
369
+ const r = U(t, n, i, !0), g = "index.ts", l = A(g, r), p = l.getSourceFile(g), c = l.languageService.getProgram().getTypeChecker(), f = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
370
+ (t?.nodes?.nodes || []).forEach((e) => {
371
+ e?.id && F.set(L(e.id), e);
372
+ });
373
+ const y = (e) => {
374
+ if (d.isVariableDeclaration(e) && e.name.getText().startsWith("node_")) {
375
+ const o = e.name.getText().replace("node_", ""), m = c.getTypeAtLocation(e);
376
+ if (f.set(o, c.typeToString(m, e, d.TypeFormatFlags.NoTruncation)), e.initializer && d.isCallExpression(e.initializer)) {
377
+ const v = c.getResolvedSignature(e.initializer);
378
+ if (v) {
379
+ const T = v.getParameters().map((S) => {
380
+ const C = c.getTypeOfSymbolAtLocation(S, e.initializer);
381
+ return c.typeToString(C, e.initializer, d.TypeFormatFlags.NoTruncation);
382
+ });
383
+ a.set(o, T);
384
+ }
275
385
  }
276
- s = ae(a, o.referencePath);
277
386
  }
278
- return `({} as ${s})`;
279
- }
280
- if (r.__typename === "NodeFunctionIdWrapper") {
281
- const o = r.id, c = B(t, o);
282
- if (!c) return "(() => undefined)";
283
- const s = (m) => {
284
- if (m.functionDefinition?.identifier === "std::control::return")
285
- return m;
286
- const g = m.nextNodeId ? B(t, m.nextNodeId) : void 0;
287
- return g ? s(g) : void 0;
288
- }, a = s(c);
289
- return a ? `(() => ({} as ${n(t, a).returnType}))` : "(() => undefined)";
290
- }
291
- return r.__typename === "LiteralValue" ? JSON.stringify(r.value) : "undefined";
292
- }
293
- const H = (e, t) => {
294
- const n = e.nodes?.nodes;
295
- if (n)
296
- return n.find(
297
- (r) => r?.parameters?.nodes?.some(
298
- (o) => o?.value?.__typename === "NodeFunctionIdWrapper" && o.value.id === t
299
- )
300
- );
301
- }, Q = (e, t, n, r = /* @__PURE__ */ new Set()) => {
302
- const o = t.id;
303
- if (!o || r.has(o)) return !1;
304
- r.add(o);
305
- const c = (a) => {
306
- const u = e.nodes?.nodes?.find((m) => m?.nextNodeId === a);
307
- return u ? u.id === n ? !0 : c(u.id) : !1;
308
- };
309
- if (c(o)) return !0;
310
- const s = H(e, o);
311
- return s ? s.id === n ? !0 : Q(e, s, n, r) : !1;
312
- }, se = (e, t, n) => {
313
- if (!n.nodeFunctionId)
314
- return { isValid: !0 };
315
- if (n.parameterIndex !== void 0 && n.inputIndex !== void 0) {
316
- if (t.id === n.nodeFunctionId) return { isValid: !0 };
317
- let r = H(e, t.id);
318
- for (; r; ) {
319
- if (r.id === n.nodeFunctionId) return { isValid: !0 };
320
- r = H(e, r.id);
387
+ if (d.isReturnStatement(e) && e.expression && d.isCallExpression(e.expression)) {
388
+ const o = e.expression;
389
+ c.getResolvedSignature(o);
321
390
  }
322
- return {
323
- isValid: !1,
324
- error: `Invalid input reference: Node ${t.id} is not in the scope of Node ${n.nodeFunctionId}.`
325
- };
326
- }
327
- return Q(e, t, n.nodeFunctionId) ? { isValid: !0 } : {
328
- isValid: !1,
329
- error: `Node ${n.nodeFunctionId} has not been executed yet or is not visible in this scope.`
391
+ d.forEachChild(e, y);
330
392
  };
331
- }, de = (e) => {
332
- const n = `const tempValue = ${JSON.stringify(e?.value) ?? "any"};`, r = "index.ts", o = I(r, n), c = o.getSourceFile(r), a = o.languageService.getProgram().getTypeChecker();
333
- let u = "any";
334
- const m = (g) => {
335
- if (v.isVariableDeclaration(g) && g.name.getText() === "tempValue") {
336
- const p = a.getTypeAtLocation(g);
337
- u = a.typeToString(
338
- p,
339
- g,
340
- v.TypeFormatFlags.NoTruncation | v.TypeFormatFlags.UseFullyQualifiedType
393
+ return y(p), { nodes: f, parameters: a };
394
+ }
395
+ const ue = (t) => {
396
+ const i = `const tempValue = ${JSON.stringify(t?.value) ?? "any"};`, r = "index.ts", g = A(r, i), l = g.getSourceFile(r), u = g.languageService.getProgram().getTypeChecker();
397
+ let c = "any";
398
+ const f = (a) => {
399
+ if (d.isVariableDeclaration(a) && a.name.getText() === "tempValue") {
400
+ const F = u.getTypeAtLocation(a);
401
+ c = u.typeToString(
402
+ F,
403
+ a,
404
+ d.TypeFormatFlags.NoTruncation | d.TypeFormatFlags.UseFullyQualifiedType
341
405
  );
342
406
  }
343
- v.forEachChild(g, m);
407
+ d.forEachChild(a, f);
344
408
  };
345
- return m(c), u;
346
- };
347
- var ce = /* @__PURE__ */ ((e) => (e[e.PRIMITIVE = 0] = "PRIMITIVE", e[e.TYPE = 1] = "TYPE", e[e.ARRAY = 2] = "ARRAY", e[e.OBJECT = 3] = "OBJECT", e))(ce || {});
348
- const fe = (e, t) => {
349
- const r = `
350
- ${E(t)}
351
- type TargetType = ${e};
352
- const val: TargetType = {} as any;
353
- `, o = "index.ts", c = I(o, r), s = c.getSourceFile(o), u = c.languageService.getProgram().getTypeChecker();
354
- let m = 1;
355
- const g = (p) => {
356
- if (v.isVariableDeclaration(p) && p.name.getText() === "val") {
357
- const i = u.getTypeAtLocation(p);
358
- u.isArrayType(i) ? m = 2 : i.isStringLiteral() || i.isNumberLiteral() || (i.getFlags() & (v.TypeFlags.String | v.TypeFlags.Number | v.TypeFlags.Boolean | v.TypeFlags.EnumLiteral | v.TypeFlags.BigInt | v.TypeFlags.ESSymbol)) !== 0 ? m = 0 : (i.isClassOrInterface() || (i.getFlags() & v.TypeFlags.Object) !== 0) && i.getProperties().length > 0 ? m = 3 : m = 1;
359
- }
360
- v.forEachChild(p, g);
361
- };
362
- return g(s), m;
363
- }, ge = (e, t) => {
364
- const n = `
365
- ${E(t)}
366
- type Target = ${e};
367
- `, r = "index.ts", o = I(r, n), c = o.getSourceFile(r), a = o.languageService.getProgram().getTypeChecker(), u = c.statements.find(
368
- (i) => v.isTypeAliasDeclaration(i) && i.name.text === "Target"
409
+ return f(l), c;
410
+ }, ge = (t, n) => {
411
+ const i = `
412
+ ${O(n)}
413
+ type Target = ${t};
414
+ `, r = "index.ts", g = A(r, i), l = g.getSourceFile(r), u = g.languageService.getProgram().getTypeChecker(), c = l.statements.find(
415
+ (s) => d.isTypeAliasDeclaration(s) && s.name.text === "Target"
369
416
  );
370
- if (!u)
417
+ if (!c)
371
418
  return { __typename: "LiteralValue", value: null };
372
- const m = a.getTypeAtLocation(u.type), g = (i, l, F = /* @__PURE__ */ new Set()) => {
373
- if (F.has(i)) return null;
374
- F.add(i);
375
- const f = i.getFlags();
376
- if (i.isUnion()) {
377
- if (l.type, v.isTypeAliasDeclaration(l) && l.type && v.isUnionTypeNode(l.type)) {
378
- const S = a.getTypeFromTypeNode(l.type.types[0]);
379
- return g(S, l, F);
419
+ const f = u.getTypeAtLocation(c.type), a = (s, y, e = /* @__PURE__ */ new Set()) => {
420
+ if (e.has(s)) return null;
421
+ e.add(s);
422
+ const o = s.getFlags();
423
+ if (s.isUnion()) {
424
+ if (y.type, d.isTypeAliasDeclaration(y) && y.type && d.isUnionTypeNode(y.type)) {
425
+ const T = u.getTypeFromTypeNode(y.type.types[0]);
426
+ return a(T, y, e);
380
427
  }
381
- const T = i.types.filter((S) => {
382
- const y = S.getFlags();
383
- return !(y & v.TypeFlags.Undefined) && !(y & v.TypeFlags.Null);
384
- }), d = T.length > 0 ? T[0] : i.types[0];
385
- return g(d, l, F);
428
+ const m = s.types.filter((T) => {
429
+ const S = T.getFlags();
430
+ return !(S & d.TypeFlags.Undefined) && !(S & d.TypeFlags.Null);
431
+ }), v = m.length > 0 ? m[0] : s.types[0];
432
+ return a(v, y, e);
386
433
  }
387
- if (f & v.TypeFlags.StringLiteral) return i.value;
388
- if (f & v.TypeFlags.String) return "sample";
389
- if (f & v.TypeFlags.NumberLiteral) return i.value;
390
- if (f & v.TypeFlags.Number) return 1;
391
- if (f & v.TypeFlags.BooleanLiteral) return i.intrinsicName === "true";
392
- if (f & v.TypeFlags.Boolean) return !1;
393
- if (a.isArrayType(i)) {
394
- const d = i.typeArguments?.[0] || a.getAnyType();
395
- return [g(d, l, F)];
434
+ if (o & d.TypeFlags.StringLiteral) return s.value;
435
+ if (o & d.TypeFlags.String) return "";
436
+ if (o & d.TypeFlags.NumberLiteral) return s.value;
437
+ if (o & d.TypeFlags.Number) return 0;
438
+ if (o & d.TypeFlags.BooleanLiteral) return s.intrinsicName === "true";
439
+ if (o & d.TypeFlags.Boolean) return !1;
440
+ if (u.isArrayType(s)) {
441
+ const v = s.typeArguments?.[0] || u.getAnyType();
442
+ return [a(v, y, e)];
396
443
  }
397
- if (i.isClassOrInterface() || f & v.TypeFlags.Object || i.getProperties().length > 0) {
398
- const T = {};
399
- return i.getProperties().forEach((S) => {
400
- const y = a.getTypeOfSymbolAtLocation(S, l);
401
- y && (T[S.getName()] = g(y, l, F));
402
- }), T;
444
+ if (s.isClassOrInterface() || o & d.TypeFlags.Object || s.getProperties().length > 0) {
445
+ const m = {};
446
+ return s.getProperties().forEach((T) => {
447
+ const S = u.getTypeOfSymbolAtLocation(T, y);
448
+ S && (m[T.getName()] = a(S, y, e));
449
+ }), m;
403
450
  }
404
451
  return null;
405
452
  };
406
453
  return {
407
- value: g(m, u)
454
+ value: a(f, c)
408
455
  };
409
- }, z = (e, t, n, r) => {
410
- const c = new Map(n.map((h) => [h.identifier, h])).get(t.functionDefinition?.identifier);
411
- if (!c)
412
- return {
413
- isValid: !1,
414
- returnType: "any",
415
- diagnostics: [{ message: `Function ${t.id} not found`, nodeId: t.id, code: 404, severity: "error" }]
456
+ }, pe = (t, n, i) => {
457
+ let r = n;
458
+ const g = t ? q(t, i) : null;
459
+ if (t && n && g !== H.NODE) {
460
+ let l = function(y) {
461
+ const e = y.trim().match(/^<([^>]+)>/);
462
+ return e ? e[1].split(",").map((o) => o.trim()).filter(Boolean).length : 0;
416
463
  };
417
- const s = t.parameters?.nodes || [], a = [];
418
- for (const h of s) {
419
- const N = h.value;
420
- if (N?.__typename === "ReferenceValue") {
421
- const $ = se(e, t, N);
422
- $.isValid || a.push({
423
- message: $.error || "Scope error",
424
- code: 403,
425
- nodeId: t.id,
426
- parameterIndex: s.indexOf(h),
427
- severity: "error"
428
- });
429
- }
464
+ const p = `
465
+ ${O(i)}
466
+ type TargetType = ${t};
467
+ ${n?.map((y, e) => `
468
+ declare function Fu${e}${y.signature};
469
+ type F${e} = ReturnType<typeof Fu${e}${l(y.signature) > 0 ? `<${Array(l(y.signature)).fill("any").join(", ")}>` : ""}>;
470
+ `).join(`
471
+ `)}
472
+ ${n?.map((y, e) => `const check${e}: TargetType = {} as F${e};`).join(`
473
+ `)}
474
+ `, u = "index.ts", c = A(u, p), f = c.getSourceFile(u), F = c.languageService.getProgram().getSemanticDiagnostics(), s = /* @__PURE__ */ new Set();
475
+ F.forEach((y) => {
476
+ y.file === f && y.start !== void 0 && s.add(f.getLineAndCharacterOfPosition(y.start).line);
477
+ }), r = n.filter((y, e) => {
478
+ const o = `const check${e}: TargetType = {} as F${e};`, v = p.split(`
479
+ `).findIndex((T) => T.includes(o));
480
+ return v !== -1 && !s.has(v);
481
+ });
430
482
  }
431
- if (a.length > 0)
432
- return {
433
- isValid: !1,
434
- returnType: "any",
435
- diagnostics: a
436
- };
437
- const u = s.map((h) => q(h, e, (N, $) => z(N, $, n, r))), m = u.map(
438
- (h) => h === "undefined" ? "({} as any)" : h
439
- ).join(", ");
440
- let g = c.signature;
441
- const p = `
442
- ${E(r)}
443
- declare function testFunc${g};
444
- const result = testFunc(${m});
445
- `, i = "index.ts", l = I(i, p), F = l.getSourceFile(i), f = l.languageService.getProgram(), T = f.getTypeChecker(), d = f.getSemanticDiagnostics(F);
446
- let S = "any";
447
- const y = (h) => {
448
- if (v.isVariableDeclaration(h) && h.name.getText() === "result") {
449
- const N = T.getTypeAtLocation(h);
450
- S = T.typeToString(
451
- N,
452
- h,
453
- v.TypeFormatFlags.NoTruncation | v.TypeFormatFlags.UseFullyQualifiedType
454
- );
455
- }
456
- v.forEachChild(h, y);
457
- };
458
- y(F);
459
- const x = d.map((h) => {
460
- const N = v.flattenDiagnosticMessageText(h.messageText, `
461
- `), $ = /\b([TRKV])\b/.test(N), C = 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");
462
- return {
463
- message: N,
464
- code: h.code,
465
- nodeId: t.id,
466
- parameterIndex: (() => {
467
- if (h.start !== void 0) {
468
- const P = s.findIndex((M, L) => {
469
- const b = p.indexOf(u[L]);
470
- return h.start >= b && h.start < b + u[L].length;
471
- });
472
- if (P !== -1) return P;
473
- }
474
- })(),
475
- severity: $ || C ? "warning" : "error"
476
- };
477
- });
478
- return {
479
- isValid: !x.some((h) => h.severity === "error"),
480
- returnType: S,
481
- diagnostics: x
482
- };
483
- }, pe = (e, t, n) => {
484
- const o = new Map(t.map((y) => [y.identifier, y])).get(e.functionDefinition?.identifier);
485
- if (!o)
486
- return {
487
- parameters: [],
488
- returnType: "any"
489
- };
490
- const c = {
491
- id: "gid://sagittarius/Flow/0",
492
- nodes: { __typename: "NodeFunctionConnection", nodes: [e] }
493
- }, u = (e.parameters?.nodes || []).map((y) => q(y, c, (x, h) => z(x, h, t, n))).map((y) => y === "undefined" ? "({} as any)" : y).join(", "), m = o.signature, g = `
494
- ${E(n)}
495
- declare function testFunc${m};
496
- const result = testFunc(${u});
497
- `, p = "index.ts", i = I(p, g), l = i.getSourceFile(p), f = i.languageService.getProgram().getTypeChecker();
498
- let T = "any", d = [];
499
- const S = (y) => {
500
- if (v.isVariableDeclaration(y) && y.name.getText() === "result") {
501
- const x = f.getTypeAtLocation(y);
502
- if (T = f.typeToString(
503
- x,
504
- y,
505
- v.TypeFormatFlags.NoTruncation
506
- ), v.isCallExpression(y.initializer)) {
507
- const h = y.initializer, N = f.getResolvedSignature(h);
508
- N && (d = N.getParameters().map(($) => {
509
- const C = f.getTypeOfSymbolAtLocation($, h);
510
- return f.typeToString(
511
- C,
512
- h,
513
- v.TypeFormatFlags.NoTruncation
514
- );
515
- }));
516
- }
483
+ return r?.map((l) => ({
484
+ __typename: "NodeFunction",
485
+ id: "gid://sagittarius/NodeFunction/1",
486
+ functionDefinition: {
487
+ __typename: "FunctionDefinition",
488
+ id: l.id,
489
+ identifier: l.identifier
490
+ },
491
+ parameters: {
492
+ __typename: "NodeParameterConnection",
493
+ nodes: (l.parameterDefinitions?.nodes || []).map((p) => ({
494
+ __typename: "NodeParameter",
495
+ parameterDefinition: {
496
+ __typename: "ParameterDefinition",
497
+ id: p?.id,
498
+ identifier: p?.identifier
499
+ },
500
+ value: null
501
+ }))
517
502
  }
518
- v.forEachChild(y, S);
519
- };
520
- return S(l), {
521
- parameters: d,
522
- returnType: T
523
- };
524
- };
525
- function me(e, t, n) {
526
- if (!e || !t || t.length === 0)
527
- return [];
528
- function r(i) {
529
- const l = i.match(/<([^>]+)>/);
530
- return l ? l[1].split(",").map((F) => F.trim()).filter(Boolean).length : 0;
503
+ })).filter((l) => l !== null) ?? [];
504
+ }, fe = (t, n, i, r, g) => {
505
+ const l = U(t, r, g, !0), p = "index.ts", u = A(p, l), c = u.getSourceFile(p), a = u.languageService.getProgram().getTypeChecker(), F = c.getFullText(), s = `/* @pos ${n} ${i} */`, e = F.indexOf(s) + s.length;
506
+ function o($, N) {
507
+ let h = $;
508
+ return d.forEachChild($, (b) => {
509
+ b.getStart(c, !0) <= N && b.getEnd() >= N && (h = o(b, N));
510
+ }), h;
531
511
  }
532
- const c = `
533
- ${E(n)}
534
- type TargetType = ${e};
535
- ${t.map((i, l) => `
536
- declare function Fu${l}${i.signature};
537
- type F${l} = ReturnType<typeof Fu${l}${r(i.signature) > 0 ? `<${Array(r(i.signature)).fill("any").join(", ")}>` : ""}>;
538
- `).join(`
539
- `)}
540
- ${t.map((i, l) => `const check${l}: TargetType = {} as F${l};`).join(`
541
- `)}
542
- `, s = "index.ts", a = I(s, c), u = a.getSourceFile(s), g = a.languageService.getProgram().getSemanticDiagnostics(), p = /* @__PURE__ */ new Set();
543
- return g.forEach((i) => {
544
- i.file === u && i.start !== void 0 && p.add(u.getLineAndCharacterOfPosition(i.start).line);
545
- }), t.map((i, l) => {
546
- const F = `const check${l}: TargetType = {} as F${l};`, T = c.split(`
547
- `).findIndex((d) => d.includes(F));
548
- return T !== -1 && p.has(T) ? null : {
549
- __typename: "NodeFunction",
550
- id: "gid://sagittarius/NodeFunction/1",
551
- functionDefinition: {
552
- __typename: "FunctionDefinition",
553
- id: i.identifier,
554
- identifier: i.identifier
555
- },
556
- parameters: {
557
- __typename: "NodeParameterConnection",
558
- nodes: (i.parameterDefinitions?.nodes || []).map((d) => ({
559
- __typename: "NodeParameter",
560
- parameterDefinition: {
561
- __typename: "ParameterDefinition",
562
- id: d?.identifier,
563
- identifier: d?.identifier
564
- },
565
- value: null
566
- }))
512
+ const v = o(c, e);
513
+ let T;
514
+ if (d.isCallExpression(v) && (T = v), !T)
515
+ return [];
516
+ const S = a.getResolvedSignature(T);
517
+ if (!S) return [];
518
+ const C = S.getParameters(), w = C[i] || C[C.length - 1], P = a.getTypeOfSymbolAtLocation(w, v), x = a.getSymbolsInScope(v, d.SymbolFlags.Variable), E = [];
519
+ return x.forEach(($) => {
520
+ const N = $.getName();
521
+ if (!N.startsWith("node_") && !N.startsWith("p_")) return;
522
+ const h = $.valueDeclaration || $.declarations?.[0];
523
+ if (!h || h.getEnd() >= e)
524
+ return;
525
+ const b = a.getTypeOfSymbolAtLocation($, v);
526
+ if (N.startsWith("node_")) {
527
+ if ((b.flags & d.TypeFlags.Void) === 0 && a.isTypeAssignableTo(b, P)) {
528
+ const _ = N.replace("node_", "").replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/");
529
+ E.push({
530
+ __typename: "ReferenceValue",
531
+ nodeFunctionId: _
532
+ // Bei node_ keine Indizes laut Vorgabe
533
+ });
567
534
  }
568
- };
569
- }).filter((i) => i !== null);
570
- }
571
- const ye = (e, t, n, r, o) => {
572
- const c = [], s = e.nodes?.nodes || [], a = s.find((i) => i?.id === t);
573
- if (!a) return [];
574
- const u = E(o), m = (i, l) => {
575
- if (!n || n === "any" || i === "any") return !0;
576
- const F = "index.ts", f = `
577
- ${u}
578
- const val: ${i} = {} as any;
579
- const test: ${n} = val${l ? `.${l}` : ""};
580
- `, T = I(F, f), d = T.getSourceFile(F);
581
- return !T.languageService.getProgram().getSemanticDiagnostics(d).some((x) => x.category === v.DiagnosticCategory.Error);
582
- }, g = (i, l) => {
583
- const F = [], f = "index.ts", T = `
584
- ${u}
585
- const val: ${i} = {} as any;
586
- `, d = I(f, T), S = d.getSourceFile(f), y = d.languageService.getProgram(), x = y.getTypeChecker();
587
- m(i) && F.push({ ...l, referencePath: [] });
588
- const h = ($, C = []) => {
589
- if (C.length > 3) return;
590
- const P = $.getProperties();
591
- for (const M of P) {
592
- const L = M.getName();
593
- let b;
594
- if (x.getPropertyOfType) {
595
- const _ = x.getPropertyOfType($, L);
596
- _ && (b = x.getTypeOfSymbolAtLocation(_, S));
597
- } else {
598
- const _ = $.getProperty(L);
599
- _ && (b = x.getTypeOfSymbolAtLocation(_, S));
600
- }
601
- if (!b) continue;
602
- const D = [...C, L], V = D.join(".");
603
- m(i, V) && F.push({
604
- ...l,
605
- referencePath: D.map((_) => ({
606
- __typename: "ReferencePath",
607
- path: _
608
- }))
609
- }), h(b, D);
535
+ } else if (N.startsWith("p_")) {
536
+ const _ = N.replace("p_", ""), D = _.lastIndexOf("_"), V = _.substring(0, D), M = parseInt(_.substring(D + 1), 10), j = V.replace("p_", "").replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/");
537
+ if (a.isTupleType(b)) {
538
+ const z = b;
539
+ a.getTypeArguments(z).forEach((Q, B) => {
540
+ a.isTypeAssignableTo(Q, P) && E.push({
541
+ __typename: "ReferenceValue",
542
+ nodeFunctionId: j,
543
+ parameterIndex: isNaN(M) ? 0 : M,
544
+ inputIndex: B,
545
+ //@ts-ignore
546
+ inputTypeIdentifier: z.target.labeledElementDeclarations?.[B].name.getText()
547
+ });
548
+ });
610
549
  }
611
- };
612
- if (y.getSemanticDiagnostics(S).length === 0) {
613
- let $;
614
- const C = (P) => {
615
- v.isVariableDeclaration(P) && P.name.getText() === "val" && ($ = x.getTypeAtLocation(P)), v.forEachChild(P, C);
616
- };
617
- C(S), $ && h($);
618
550
  }
619
- return F;
620
- };
621
- if (e.inputType) {
622
- const i = e.inputType || "any";
623
- c.push(...g(i, {}));
624
- }
625
- s.forEach((i) => {
626
- if (!(!i || i.id === t) && ue(e, i, a)) {
627
- const l = z(e, i, r, o);
628
- c.push(...g(l.returnType, {
629
- __typename: "ReferenceValue",
630
- nodeFunctionId: i.id,
631
- referencePath: []
632
- }));
633
- }
634
- });
635
- let p = O(e, t);
636
- for (; p; ) {
637
- if (r.find((l) => l.identifier === p.functionDefinition?.identifier)) {
638
- const l = p.parameters?.nodes?.findIndex((F) => {
639
- const f = F?.value;
640
- if (f?.__typename === "NodeFunctionIdWrapper") {
641
- const T = f;
642
- return T.id === t || U(e, T.id || void 0, t);
643
- }
644
- return !1;
645
- });
646
- l !== void 0 && l !== -1 && c.push(...g("any", {
647
- __typename: "ReferenceValue",
648
- nodeFunctionId: p.id,
649
- parameterIndex: l,
650
- inputIndex: 0,
651
- referencePath: []
652
- }));
653
- }
654
- p = O(e, p.id);
655
- }
656
- return c;
657
- };
658
- function ue(e, t, n) {
659
- const r = e.nodes?.nodes || [];
660
- let o = t.nextNodeId;
661
- const c = /* @__PURE__ */ new Set();
662
- for (; o; ) {
663
- if (o === n.id) return !0;
664
- if (c.has(o)) break;
665
- c.add(o), o = r.find((u) => u?.id === o)?.nextNodeId;
666
- }
667
- let s = O(e, n.id);
668
- for (; s; ) {
669
- if (s.id === t.id) return !0;
670
- s = O(e, s.id);
671
- }
672
- return !1;
673
- }
674
- function O(e, t) {
675
- return e.nodes?.nodes?.find(
676
- (r) => r?.parameters?.nodes?.some(
677
- (o) => o?.value?.__typename === "NodeFunctionIdWrapper" && o.value.id === t
678
- )
679
- ) || void 0;
680
- }
681
- function U(e, t, n) {
682
- if (!t) return !1;
683
- if (t === n) return !0;
684
- const o = (e.nodes?.nodes || []).find((s) => s?.id === t);
685
- return o ? o.nextNodeId && U(e, o.nextNodeId || void 0, n) ? !0 : !!o.parameters?.nodes?.some((s) => {
686
- const a = s?.value;
687
- return a?.__typename === "NodeFunctionIdWrapper" ? U(e, a.id || void 0, n) : !1;
688
- }) : !1;
689
- }
690
- const ve = (e) => {
691
- if (!e) return [];
692
- const t = `type T = ${e}; const val: T = {} as any;`, n = "index.ts", r = I(n, t), o = r.getSourceFile(n), s = r.languageService.getProgram().getTypeChecker(), a = o.statements.find(v.isTypeAliasDeclaration);
693
- if (!a) return [];
694
- const u = s.getTypeAtLocation(a), m = (p) => p.isUnion() ? p.types.flatMap(m) : p.isStringLiteral() ? [p.value] : p.isNumberLiteral() ? [p.value.toString()] : p.intrinsicName === "true" ? ["true"] : p.intrinsicName === "false" ? ["false"] : [];
695
- return Array.from(new Set(m(u))).map((p) => ({
551
+ }), E;
552
+ }, me = (t, n) => {
553
+ if (!t) return [];
554
+ const i = `
555
+ ${O(n)}
556
+ type VALUE = ${t}; const val: VALUE = {} as any;
557
+ `, r = "index.ts", g = A(r, i), l = g.getSourceFile(r), u = g.languageService.getProgram().getTypeChecker(), c = l.statements.find(
558
+ (s) => d.isTypeAliasDeclaration(s) && s.name.text === "VALUE"
559
+ );
560
+ if (!c || !d.isTypeAliasDeclaration(c)) return [];
561
+ const f = u.getTypeAtLocation(c), a = (s) => s.isUnion() ? s.types.flatMap(a) : s.isStringLiteral() ? [s.value] : s.isNumberLiteral() ? [s.value.toString()] : s.intrinsicName === "true" ? ["true"] : s.intrinsicName === "false" ? ["false"] : [];
562
+ return Array.from(new Set(a(f))).map((s) => ({
696
563
  __typename: "LiteralValue",
697
- value: p
564
+ value: s
698
565
  }));
699
- }, k = (e) => e.replace(/[^a-zA-Z0-9]/g, "_"), Fe = (e, t, n) => {
700
- const r = /* @__PURE__ */ new Set(), o = e.nodes?.nodes || [], c = new Map(t.map((d) => [d.identifier, d])), s = (d, S = "") => {
701
- if (r.has(d)) return "";
702
- const y = o.find((L) => L?.id === d);
703
- if (!y || !y.functionDefinition) return "";
704
- r.add(d);
705
- const x = c.get(y.functionDefinition?.identifier);
706
- if (!x) return `${S}// Error: Function ${y.functionDefinition.identifier} not found
707
- `;
708
- const N = (y.parameters?.nodes || []).map((L, b) => {
709
- const D = L.value;
710
- if (!D) return "undefined";
711
- if (D.__typename === "ReferenceValue") {
712
- const V = D;
713
- if (!V.nodeFunctionId) return "undefined";
714
- let _ = V.parameterIndex !== void 0 ? `/* @pos ${d} ${b} */ p_${k(V.nodeFunctionId)}_${V.parameterIndex}` : `/* @pos ${d} ${b} */ node_${k(V.nodeFunctionId)}`;
715
- return V.referencePath?.forEach((j) => {
716
- _ += `?.${j.path}`;
717
- }), _;
718
- }
719
- if (D.__typename === "LiteralValue")
720
- return `/* @pos ${d} ${b} */ ${JSON.stringify(D.value)}`;
721
- if (D.__typename === "NodeFunctionIdWrapper") {
722
- const V = D, _ = `p_${k(y.id)}_${b}`, j = s(V.id, S + " ");
723
- return `/* @pos ${d} ${b} */ (${_}) => {
724
- ${j}${S}}`;
725
- }
726
- return "undefined";
727
- }).join(", "), $ = `node_${k(y.id)}`, C = `fn_${x.identifier?.replace(/::/g, "_")}`, P = N.includes("undefined");
728
- let M = `${S}const ${$} = ${C}(${N})${P ? " as any" : ""} ;
729
- `;
730
- return y.nextNodeId && (M += s(y.nextNodeId, S)), M;
731
- }, a = E(n), u = t.map((d) => `declare function fn_${d.identifier?.replace(/::/g, "_")}${d.signature}`).join(`
732
- `), m = o.map((d) => d?.id ? s(d.id) : "").filter((d) => d !== "").join(`
733
- `), g = `${a}
734
- ${u}
735
-
736
- // --- Flow ---
737
- ${m}`, p = "index.ts", i = I(p, g), l = i.getSourceFile(p), T = i.languageService.getProgram().getSemanticDiagnostics(l).map((d) => {
738
- const S = Z(d.messageText, `
566
+ }, de = (t, n, i) => {
567
+ const r = U(t, n, i), g = "index.ts", l = A(g, r), p = l.getSourceFile(g), f = l.languageService.getProgram().getSemanticDiagnostics(p).map((a) => {
568
+ const F = Z(a.messageText, `
739
569
  `);
740
- if (S.includes("Argument of type 'undefined'") || S.includes("not assignable to type 'undefined'")) return null;
741
- let x, h;
742
- if (d.start !== void 0) {
743
- const C = l.getFullText().substring(0, d.start).match(/\/\* @pos ([^ ]+) (\d+) \*\/\s*$/);
744
- C && (x = C[1], h = parseInt(C[2], 10));
570
+ let s, y;
571
+ if (a.start !== void 0) {
572
+ const e = p.getFullText(), o = Math.max(0, a.start - 300), m = Math.min(e.length, a.start), v = e.substring(o, m), T = /\/\* @pos ([^ ]+) (\d+) \*\//g;
573
+ let S, C = null, w = -1;
574
+ for (; (S = T.exec(v)) !== null; ) {
575
+ const x = o + S.index + S[0].length;
576
+ x <= a.start && x > w && (w = x, C = S);
577
+ }
578
+ C && (s = C[1], y = parseInt(C[2], 10));
745
579
  }
746
580
  return {
747
- message: S,
748
- code: d.code,
581
+ message: F,
582
+ code: a.code,
749
583
  severity: "error",
750
- nodeId: x,
751
- parameterIndex: h
584
+ nodeId: s,
585
+ parameterIndex: y
752
586
  };
753
- }).filter((d) => d !== null);
587
+ }).filter((a) => a !== null);
754
588
  return {
755
- isValid: !T.some((d) => d?.severity === "error"),
589
+ isValid: !f.some((a) => a?.severity === "error"),
756
590
  returnType: "void",
757
- diagnostics: T
591
+ diagnostics: f
758
592
  };
759
- }, he = (e, t, n) => {
760
- const r = JSON.stringify(t.value), o = `
761
- ${E(n)}
762
- const testValue: ${e} = ${r};
763
- `, c = "index.ts", u = I(c, o).languageService.getSemanticDiagnostics(c).map((m) => {
764
- const g = v.flattenDiagnosticMessageText(m.messageText, `
765
- `), p = /\b([TRKV])\b/.test(g), i = g.includes("not assignable to parameter of type") && (g.includes("'{}'") || g.includes("undefined")) || g.includes("not assignable to type 'undefined'") || g.includes("not assignable to type 'void'") || g.includes("may be a mistake because neither type sufficiently overlaps");
593
+ }, ye = (t, n, i) => {
594
+ const r = JSON.stringify(n?.value), g = `
595
+ ${O(i)}
596
+ const testValue: ${t} = ${r};
597
+ `, l = "index.ts", c = A(l, g).languageService.getSemanticDiagnostics(l).map((f) => {
598
+ const a = d.flattenDiagnosticMessageText(f.messageText, `
599
+ `), F = a.includes("not assignable to parameter of type") && (a.includes("'{}'") || a.includes("undefined")) || a.includes("not assignable to type 'undefined'") || a.includes("not assignable to type 'void'") || a.includes("may be a mistake because neither type sufficiently overlaps");
766
600
  return {
767
- message: g,
768
- code: m.code,
769
- severity: p || i ? "warning" : "error"
601
+ message: a,
602
+ code: f.code,
603
+ severity: F ? "warning" : "error"
770
604
  };
771
605
  });
772
606
  return {
773
- isValid: !u.some((m) => m.severity === "error"),
607
+ isValid: !c.some((f) => f.severity === "error"),
774
608
  returnType: "void",
775
- diagnostics: u
609
+ diagnostics: c
776
610
  };
777
611
  };
778
612
  export {
779
- ce as DataTypeVariant,
780
- Fe as getFlowValidation,
781
- me as getNodeSuggestions,
782
- z as getNodeValidation,
783
- ye as getReferenceSuggestions,
784
- de as getTypeFromValue,
785
- fe as getTypeVariant,
786
- pe as getTypesFromNode,
613
+ H as DataTypeVariant,
614
+ de as getFlowValidation,
615
+ pe as getNodeSuggestions,
616
+ fe as getReferenceSuggestions,
617
+ ue as getTypeFromValue,
618
+ q as getTypeVariant,
619
+ ie as getTypesFromNode,
787
620
  ge as getValueFromType,
788
- ve as getValueSuggestions,
789
- he as getValueValidation
621
+ me as getValueSuggestions,
622
+ ye as getValueValidation
790
623
  };