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