@code0-tech/triangulum 0.1.0 → 0.2.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/{src/extraction → extraction}/getTypeVariant.d.ts +2 -2
- package/dist/{src/extraction → extraction}/getTypesFromNode.d.ts +2 -3
- package/dist/extraction/getValueFromType.d.ts +5 -0
- package/dist/index.d.ts +10 -2
- package/dist/{src/suggestion → suggestion}/getNodeSuggestions.d.ts +2 -3
- package/dist/suggestion/getReferenceSuggestions.d.ts +6 -0
- package/dist/triangulum.cjs.js +49 -49
- package/dist/triangulum.es.js +665 -459
- package/dist/{src/utils.d.ts → utils.d.ts} +8 -13
- 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/getValueFromType.d.ts +0 -6
- package/dist/src/index.d.ts +0 -10
- package/dist/src/suggestion/getReferenceSuggestions.d.ts +0 -7
- 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/{src/suggestion → suggestion}/getValueSuggestions.d.ts +0 -0
package/dist/triangulum.es.js
CHANGED
|
@@ -1,5 +1,215 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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]);
|
|
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 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));
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
// @ts-ignore
|
|
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);
|
|
34
|
+
},
|
|
35
|
+
createFile: function(F, f) {
|
|
36
|
+
u(n.createSourceFile(F, f, c.target, !1));
|
|
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
|
|
45
|
+
});
|
|
46
|
+
u(h);
|
|
47
|
+
},
|
|
48
|
+
deleteFile: function(F) {
|
|
49
|
+
var f = g.getProgram().getSourceFile(F);
|
|
50
|
+
f && m(f);
|
|
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 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;
|
|
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
|
+
}, c = {
|
|
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 m;
|
|
151
|
+
return r.get(a) || o(n.createSourceFile(a, e.readFile(a), (m = u ?? t.target) != null ? m : 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 c;
|
|
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, {
|
|
170
|
+
getProjectVersion: function() {
|
|
171
|
+
return p.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 c.slice();
|
|
189
|
+
},
|
|
190
|
+
getScriptSnapshot: function(f) {
|
|
191
|
+
var T = e.readFile(f);
|
|
192
|
+
if (T && typeof T == "string")
|
|
193
|
+
return r.ScriptSnapshot.fromString(T);
|
|
194
|
+
},
|
|
195
|
+
getScriptVersion: function(f) {
|
|
196
|
+
return g.get(f) || "0";
|
|
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);
|
|
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);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
return l;
|
|
211
|
+
}
|
|
212
|
+
const ie = `
|
|
3
213
|
interface Array<T> {
|
|
4
214
|
[n: number]: T;
|
|
5
215
|
length: number;
|
|
@@ -15,570 +225,566 @@ 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"], v, oe);
|
|
37
233
|
}
|
|
38
|
-
const
|
|
39
|
-
target:
|
|
40
|
-
lib: ["lib.
|
|
234
|
+
const oe = {
|
|
235
|
+
target: v.ScriptTarget.Latest,
|
|
236
|
+
lib: ["lib.codezero.d.ts"],
|
|
41
237
|
noEmit: !0,
|
|
42
238
|
strictNullChecks: !0
|
|
43
239
|
};
|
|
44
|
-
function E(
|
|
45
|
-
const
|
|
46
|
-
`),
|
|
47
|
-
(
|
|
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};`
|
|
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 =
|
|
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);
|
|
71
267
|
if (!c) return "undefined";
|
|
72
|
-
let
|
|
268
|
+
let s = n(t, c).returnType;
|
|
73
269
|
if (o.referencePath && o.referencePath.length > 0) {
|
|
74
|
-
let
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
|
|
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);
|
|
79
275
|
}
|
|
80
|
-
|
|
276
|
+
s = ae(a, o.referencePath);
|
|
81
277
|
}
|
|
82
|
-
return `({} as ${
|
|
278
|
+
return `({} as ${s})`;
|
|
83
279
|
}
|
|
84
|
-
if (
|
|
85
|
-
const o =
|
|
280
|
+
if (r.__typename === "NodeFunctionIdWrapper") {
|
|
281
|
+
const o = r.id, c = B(t, o);
|
|
86
282
|
if (!c) return "(() => undefined)";
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
return
|
|
90
|
-
const
|
|
91
|
-
return
|
|
92
|
-
},
|
|
93
|
-
return
|
|
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)";
|
|
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 c = (
|
|
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 c = (a) => {
|
|
306
|
+
const u = e.nodes?.nodes?.find((m) => m?.nextNodeId === a);
|
|
307
|
+
return u ? u.id === n ? !0 : c(u.id) : !1;
|
|
112
308
|
};
|
|
113
309
|
if (c(o)) return !0;
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
},
|
|
117
|
-
if (!
|
|
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)
|
|
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
|
+
}, 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
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
v.forEachChild(g, m);
|
|
344
|
+
};
|
|
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"
|
|
369
|
+
);
|
|
370
|
+
if (!u)
|
|
371
|
+
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);
|
|
161
380
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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);
|
|
386
|
+
}
|
|
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)];
|
|
396
|
+
}
|
|
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;
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
};
|
|
406
|
+
return {
|
|
407
|
+
value: g(m, u)
|
|
408
|
+
};
|
|
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" }]
|
|
416
|
+
};
|
|
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
|
+
}
|
|
430
|
+
}
|
|
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 {
|
|
177
463
|
message: N,
|
|
178
|
-
code:
|
|
179
|
-
|
|
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"
|
|
180
476
|
};
|
|
181
|
-
})
|
|
477
|
+
});
|
|
182
478
|
return {
|
|
183
|
-
isValid: h.
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
517
|
+
}
|
|
518
|
+
v.forEachChild(y, S);
|
|
519
|
+
};
|
|
520
|
+
return S(l), {
|
|
521
|
+
parameters: d,
|
|
522
|
+
returnType: T
|
|
186
523
|
};
|
|
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)
|
|
524
|
+
};
|
|
525
|
+
function me(e, t, n) {
|
|
526
|
+
if (!e || !t || t.length === 0)
|
|
198
527
|
return [];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return i ? i[1].split(",").map((g) => g.trim()).filter(Boolean).length : 0;
|
|
528
|
+
function r(i) {
|
|
529
|
+
const l = i.match(/<([^>]+)>/);
|
|
530
|
+
return l ? l[1].split(",").map((F) => F.trim()).filter(Boolean).length : 0;
|
|
203
531
|
}
|
|
204
532
|
const c = `
|
|
205
|
-
${
|
|
206
|
-
type TargetType = ${
|
|
207
|
-
${
|
|
208
|
-
declare function Fu${
|
|
209
|
-
type F${
|
|
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(", ")}>` : ""}>;
|
|
210
538
|
`).join(`
|
|
211
539
|
`)}
|
|
212
|
-
${
|
|
540
|
+
${t.map((i, l) => `const check${l}: TargetType = {} as F${l};`).join(`
|
|
213
541
|
`)}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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 : {
|
|
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 : {
|
|
225
549
|
__typename: "NodeFunction",
|
|
226
550
|
id: "gid://sagittarius/NodeFunction/1",
|
|
227
551
|
functionDefinition: {
|
|
228
552
|
__typename: "FunctionDefinition",
|
|
229
|
-
id:
|
|
230
|
-
identifier:
|
|
553
|
+
id: i.identifier,
|
|
554
|
+
identifier: i.identifier
|
|
231
555
|
},
|
|
232
556
|
parameters: {
|
|
233
557
|
__typename: "NodeParameterConnection",
|
|
234
|
-
nodes: (
|
|
558
|
+
nodes: (i.parameterDefinitions?.nodes || []).map((d) => ({
|
|
235
559
|
__typename: "NodeParameter",
|
|
236
560
|
parameterDefinition: {
|
|
237
561
|
__typename: "ParameterDefinition",
|
|
238
|
-
id:
|
|
239
|
-
identifier:
|
|
562
|
+
id: d?.identifier,
|
|
563
|
+
identifier: d?.identifier
|
|
240
564
|
},
|
|
241
565
|
value: null
|
|
242
566
|
}))
|
|
243
567
|
}
|
|
244
568
|
};
|
|
245
|
-
}).filter((
|
|
569
|
+
}).filter((i) => i !== null);
|
|
246
570
|
}
|
|
247
|
-
const
|
|
248
|
-
const c =
|
|
249
|
-
if (!
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
};
|
|
255
|
-
const u = s.parameters?.nodes || [], d = [];
|
|
256
|
-
for (const F of u) {
|
|
257
|
-
const S = F.value;
|
|
258
|
-
if (S?.__typename === "ReferenceValue") {
|
|
259
|
-
const $ = z(n, s, S);
|
|
260
|
-
$.isValid || d.push({
|
|
261
|
-
message: $.error || "Scope error",
|
|
262
|
-
code: 403,
|
|
263
|
-
severity: "error"
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (d.length > 0)
|
|
268
|
-
return {
|
|
269
|
-
isValid: !1,
|
|
270
|
-
inferredType: "any",
|
|
271
|
-
errors: d
|
|
272
|
-
};
|
|
273
|
-
const p = u.map((F) => K(F, n, (S, $) => W(S, $, r, e))).map(
|
|
274
|
-
(F) => F === "undefined" ? "({} as any)" : F
|
|
275
|
-
).join(", ");
|
|
276
|
-
let m = c.signature;
|
|
277
|
-
const a = `
|
|
278
|
-
${E(e)}
|
|
279
|
-
declare function testFunc${m};
|
|
280
|
-
const result = testFunc(${p});
|
|
281
|
-
`, i = "node_virtual.ts", g = t.createSourceFile(i, a, t.ScriptTarget.Latest), _ = I(i, a, g), T = t.createProgram([i], x, _), h = T.getTypeChecker(), f = T.getSemanticDiagnostics(g);
|
|
282
|
-
let N = "any";
|
|
283
|
-
const l = (F) => {
|
|
284
|
-
if (t.isVariableDeclaration(F) && F.name.getText() === "result") {
|
|
285
|
-
const S = h.getTypeAtLocation(F);
|
|
286
|
-
N = h.typeToString(
|
|
287
|
-
S,
|
|
288
|
-
F,
|
|
289
|
-
t.TypeFormatFlags.NoTruncation | t.TypeFormatFlags.UseFullyQualifiedType
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
t.forEachChild(F, l);
|
|
293
|
-
};
|
|
294
|
-
l(g);
|
|
295
|
-
const v = f.map((F) => {
|
|
296
|
-
const S = t.flattenDiagnosticMessageText(F.messageText, `
|
|
297
|
-
`), $ = /\b([TRKV])\b/.test(S), C = S.includes("not assignable to parameter of type") && (S.includes("'{}'") || S.includes("undefined")) || S.includes("not assignable to type 'undefined'") || S.includes("not assignable to type 'void'") || S.includes("may be a mistake because neither type sufficiently overlaps");
|
|
298
|
-
return {
|
|
299
|
-
message: S,
|
|
300
|
-
code: F.code,
|
|
301
|
-
severity: $ || C ? "warning" : "error"
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
return {
|
|
305
|
-
isValid: !v.some((F) => F.severity === "error"),
|
|
306
|
-
inferredType: N,
|
|
307
|
-
errors: v
|
|
308
|
-
};
|
|
309
|
-
}, ee = (n, s, r, e, o) => {
|
|
310
|
-
const c = [], u = n.nodes?.nodes || [], d = u.find((i) => i?.id === s);
|
|
311
|
-
if (!d) return [];
|
|
312
|
-
const y = E(o), p = (i, g) => {
|
|
313
|
-
if (!r || r === "any" || i === "any") return !0;
|
|
314
|
-
const _ = `suggestion_check_${Math.random().toString(36).substring(7)}.ts`, T = `
|
|
315
|
-
${y}
|
|
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}
|
|
316
578
|
const val: ${i} = {} as any;
|
|
317
|
-
const test: ${
|
|
318
|
-
`,
|
|
319
|
-
return !
|
|
320
|
-
},
|
|
321
|
-
const
|
|
322
|
-
${
|
|
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}
|
|
323
585
|
const val: ${i} = {} as any;
|
|
324
|
-
`,
|
|
325
|
-
|
|
326
|
-
const
|
|
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 = []) => {
|
|
327
589
|
if (C.length > 3) return;
|
|
328
|
-
const
|
|
329
|
-
for (const
|
|
330
|
-
const
|
|
331
|
-
let
|
|
332
|
-
if (
|
|
333
|
-
const
|
|
334
|
-
|
|
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));
|
|
335
597
|
} else {
|
|
336
|
-
const
|
|
337
|
-
|
|
598
|
+
const _ = $.getProperty(L);
|
|
599
|
+
_ && (b = x.getTypeOfSymbolAtLocation(_, S));
|
|
338
600
|
}
|
|
339
|
-
if (!
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
...
|
|
343
|
-
referencePath:
|
|
601
|
+
if (!b) continue;
|
|
602
|
+
const D = [...C, L], V = D.join(".");
|
|
603
|
+
m(i, V) && F.push({
|
|
604
|
+
...l,
|
|
605
|
+
referencePath: D.map((_) => ({
|
|
344
606
|
__typename: "ReferencePath",
|
|
345
|
-
path:
|
|
607
|
+
path: _
|
|
346
608
|
}))
|
|
347
|
-
}),
|
|
609
|
+
}), h(b, D);
|
|
348
610
|
}
|
|
349
611
|
};
|
|
350
|
-
if (
|
|
612
|
+
if (y.getSemanticDiagnostics(S).length === 0) {
|
|
351
613
|
let $;
|
|
352
|
-
const C = (
|
|
353
|
-
|
|
614
|
+
const C = (P) => {
|
|
615
|
+
v.isVariableDeclaration(P) && P.name.getText() === "val" && ($ = x.getTypeAtLocation(P)), v.forEachChild(P, C);
|
|
354
616
|
};
|
|
355
|
-
C(
|
|
617
|
+
C(S), $ && h($);
|
|
356
618
|
}
|
|
357
|
-
return
|
|
619
|
+
return F;
|
|
358
620
|
};
|
|
359
|
-
if (
|
|
360
|
-
const i =
|
|
361
|
-
c.push(...
|
|
362
|
-
__typename: "ReferenceValue",
|
|
363
|
-
nodeFunctionId: null,
|
|
364
|
-
parameterIndex: 0,
|
|
365
|
-
referencePath: []
|
|
366
|
-
}));
|
|
621
|
+
if (e.inputType) {
|
|
622
|
+
const i = e.inputType || "any";
|
|
623
|
+
c.push(...g(i, {}));
|
|
367
624
|
}
|
|
368
|
-
|
|
369
|
-
if (!(!i || i.id ===
|
|
370
|
-
const
|
|
371
|
-
c.push(...
|
|
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, {
|
|
372
629
|
__typename: "ReferenceValue",
|
|
373
630
|
nodeFunctionId: i.id,
|
|
374
631
|
referencePath: []
|
|
375
632
|
}));
|
|
376
633
|
}
|
|
377
634
|
});
|
|
378
|
-
let
|
|
379
|
-
for (;
|
|
380
|
-
if (
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
return
|
|
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);
|
|
386
643
|
}
|
|
387
644
|
return !1;
|
|
388
645
|
});
|
|
389
|
-
|
|
646
|
+
l !== void 0 && l !== -1 && c.push(...g("any", {
|
|
390
647
|
__typename: "ReferenceValue",
|
|
391
|
-
nodeFunctionId:
|
|
392
|
-
parameterIndex:
|
|
648
|
+
nodeFunctionId: p.id,
|
|
649
|
+
parameterIndex: l,
|
|
393
650
|
inputIndex: 0,
|
|
394
651
|
referencePath: []
|
|
395
652
|
}));
|
|
396
653
|
}
|
|
397
|
-
|
|
654
|
+
p = O(e, p.id);
|
|
398
655
|
}
|
|
399
656
|
return c;
|
|
400
657
|
};
|
|
401
|
-
function
|
|
402
|
-
const
|
|
403
|
-
let o =
|
|
658
|
+
function ue(e, t, n) {
|
|
659
|
+
const r = e.nodes?.nodes || [];
|
|
660
|
+
let o = t.nextNodeId;
|
|
404
661
|
const c = /* @__PURE__ */ new Set();
|
|
405
662
|
for (; o; ) {
|
|
406
|
-
if (o ===
|
|
663
|
+
if (o === n.id) return !0;
|
|
407
664
|
if (c.has(o)) break;
|
|
408
|
-
c.add(o), o =
|
|
665
|
+
c.add(o), o = r.find((u) => u?.id === o)?.nextNodeId;
|
|
409
666
|
}
|
|
410
|
-
let
|
|
411
|
-
for (;
|
|
412
|
-
if (
|
|
413
|
-
|
|
667
|
+
let s = O(e, n.id);
|
|
668
|
+
for (; s; ) {
|
|
669
|
+
if (s.id === t.id) return !0;
|
|
670
|
+
s = O(e, s.id);
|
|
414
671
|
}
|
|
415
672
|
return !1;
|
|
416
673
|
}
|
|
417
|
-
function
|
|
418
|
-
return
|
|
419
|
-
(
|
|
420
|
-
(o) => o?.value?.__typename === "NodeFunctionIdWrapper" && o.value.id ===
|
|
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
|
|
421
678
|
)
|
|
422
679
|
) || void 0;
|
|
423
680
|
}
|
|
424
|
-
function U(
|
|
425
|
-
if (!
|
|
426
|
-
if (
|
|
427
|
-
const o = (
|
|
428
|
-
return o ? o.nextNodeId && U(
|
|
429
|
-
const
|
|
430
|
-
return
|
|
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;
|
|
431
688
|
}) : !1;
|
|
432
689
|
}
|
|
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
|
-
t.forEachChild(a, m);
|
|
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, _);
|
|
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) => ({
|
|
696
|
+
__typename: "LiteralValue",
|
|
697
|
+
value: p
|
|
698
|
+
}));
|
|
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
|
+
}), _;
|
|
482
718
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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, `
|
|
739
|
+
`);
|
|
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));
|
|
505
745
|
}
|
|
506
|
-
return
|
|
507
|
-
|
|
746
|
+
return {
|
|
747
|
+
message: S,
|
|
748
|
+
code: d.code,
|
|
749
|
+
severity: "error",
|
|
750
|
+
nodeId: x,
|
|
751
|
+
parameterIndex: h
|
|
752
|
+
};
|
|
753
|
+
}).filter((d) => d !== null);
|
|
508
754
|
return {
|
|
509
|
-
|
|
755
|
+
isValid: !T.some((d) => d?.severity === "error"),
|
|
756
|
+
returnType: "void",
|
|
757
|
+
diagnostics: T
|
|
510
758
|
};
|
|
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)
|
|
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");
|
|
533
766
|
return {
|
|
534
|
-
|
|
535
|
-
|
|
767
|
+
message: g,
|
|
768
|
+
code: m.code,
|
|
769
|
+
severity: p || i ? "warning" : "error"
|
|
536
770
|
};
|
|
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
|
|
771
|
+
});
|
|
772
|
+
return {
|
|
773
|
+
isValid: !u.some((m) => m.severity === "error"),
|
|
774
|
+
returnType: "void",
|
|
775
|
+
diagnostics: u
|
|
570
776
|
};
|
|
571
777
|
};
|
|
572
778
|
export {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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,
|
|
787
|
+
ge as getValueFromType,
|
|
788
|
+
ve as getValueSuggestions,
|
|
789
|
+
he as getValueValidation
|
|
584
790
|
};
|