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