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