@code0-tech/triangulum 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,4 @@ export * from './suggestion/getNodeSuggestions';
|
|
|
6
6
|
export * from './suggestion/getReferenceSuggestions';
|
|
7
7
|
export * from './suggestion/getValueSuggestions';
|
|
8
8
|
export * from './validation/getFlowValidation';
|
|
9
|
-
export * from './validation/getNodeValidation';
|
|
10
9
|
export * from './validation/getValueValidation';
|
|
@@ -3,4 +3,4 @@ import { DataType, Flow, FunctionDefinition, NodeFunction, ReferenceValue } from
|
|
|
3
3
|
* Calculates all available reference suggestions for a specific target node in a flow
|
|
4
4
|
* and filters them by a required type.
|
|
5
5
|
*/
|
|
6
|
-
export declare const getReferenceSuggestions: (flow?: Flow, nodeId?: NodeFunction["id"],
|
|
6
|
+
export declare const getReferenceSuggestions: (flow?: Flow, nodeId?: NodeFunction["id"], targetIndex?: number, functions?: FunctionDefinition[], dataTypes?: DataType[]) => ReferenceValue[];
|
package/dist/triangulum.cjs.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`,useCaseSensitiveFileNames:!0,write:function(){return
|
|
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 r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}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,r,g){r===void 0&&(r={});var l=R({},q(i),r),p=re(t,n,l,i,g),u=p.languageServiceHost,c=p.updateFile,m=p.deleteFile,a=i.createLanguageService(u),F=a.getCompilerOptionsDiagnostics();if(F.length){var s=G(t,r,i);throw new Error(i.formatDiagnostics(F,s.compilerHost))}return{name:"vfs",sys:t,languageService:a,getSourceFile:function(e){var o;return(o=a.getProgram())==null?void 0:o.getSourceFile(e)},createFile:function(e,o){c(i.createSourceFile(e,o,l.target,!1))},updateFile:function(e,o,d){var T=a.getProgram().getSourceFile(e);if(!T)throw new Error("Did not find a source file for "+e);var v=T.text,S=d??i.createTextSpan(0,v.length),C=v.slice(0,S.start)+o+v.slice(S.start+S.length),w=i.updateSourceFile(T,C,{span:S,newLength:o.length});c(w)},deleteFile:function(e){var o=a.getProgram().getSourceFile(e);o&&m(o)}}}function I(t){throw new Error("Method '"+t+"' is not implemented.")}function k(t,n){return function(){for(var i=arguments.length,r=new Array(i),g=0;g<i;g++)r[g]=arguments[g];var l=n.apply(void 0,r),p=typeof l=="string"?l.slice(0,80)+"...":l;return J.apply(void 0,["> "+t].concat(r)),J("< "+p),l}}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 I("createDirectory")},directoryExists:k("directoryExists",function(n){return Array.from(t.keys()).some(function(i){return i.startsWith(n)})}),exit:function(){return I("exit")},fileExists:k("fileExists",function(n){return t.has(n)||t.has(K(n))}),getCurrentDirectory:function(){return"/"},getDirectories:function(){return[]},getExecutingFilePath:function(){return I("getExecutingFilePath")},readDirectory:k("readDirectory",function(n){return n==="/"?Array.from(t.keys()):[]}),readFile:k("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 I("write")},writeFile:function(i,r){t.set(i,r)},deleteFile:function(i){t.delete(i)}}}function G(t,n,i){var r=new Map,g=function(u){return r.set(u.fileName,u),u},l={compilerHost:R({},t,{getCanonicalFileName:function(u){return u},getDefaultLibFileName:function(){return"/"+i.getDefaultLibFileName(n)},getNewLine:function(){return t.newLine},getSourceFile:function(u,c){var m;return r.get(u)||g(i.createSourceFile(u,t.readFile(u),(m=c??n.target)!=null?m:q(i).target,!1))},useCaseSensitiveFileNames:function(){return t.useCaseSensitiveFileNames}}),updateFile:function(u){var c=r.has(u.fileName);return t.writeFile(u.fileName,u.text),r.set(u.fileName,u),c},deleteFile:function(u){var c=r.has(u.fileName);return r.delete(u.fileName),t.deleteFile(u.fileName),c}};return l}function re(t,n,i,r,g){var l=[].concat(n),p=G(t,i,r),u=p.compilerHost,c=p.updateFile,m=p.deleteFile,a=new Map,F=0,s=R({},u,{getProjectVersion:function(){return F.toString()},getCompilationSettings:function(){return i},getCustomTransformers:function(){return g},getScriptFileNames:function(){return l.slice()},getScriptSnapshot:function(o){var d=t.readFile(o);if(d&&typeof d=="string")return r.ScriptSnapshot.fromString(d)},getScriptVersion:function(o){return a.get(o)||"0"},writeFile:t.writeFile}),y={languageServiceHost:s,updateFile:function(o){F++,a.set(o.fileName,F.toString()),l.includes(o.fileName)||l.push(o.fileName),c(o)},deleteFile:function(o){F++,a.set(o.fileName,F.toString());var d=l.indexOf(o.fileName);d!==-1&&l.splice(d,1),m(o)}};return y}const Q=(t,n,i)=>{if(!t)return{parameters:[],returnType:"any"};const r=t.id||"temp_node_id",g={...t,id:r,parameters:{...t.parameters,nodes:t.parameters?.nodes?.map(e=>e?.value?e:{...e,value:null})||[]}},l=r+"_params",p={...g,id:l,parameters:{...g.parameters,nodes:g.parameters.nodes.map(e=>e.value?.__typename==="LiteralValue"&&e.value.value!==null&&typeof e.value.value!="object"?{...e,value:null}:e)}},c=oe({nodes:{__typename:"NodeFunctionConnection",nodes:[g,p]}},n,i),m=P(r),a=P(l),F=c.parameters.get(m)||[],s=c.parameters.get(a)||[];return{parameters:F.map((e,o)=>{const d=s[o];return d&&d!=="any"&&d!=="unknown"?d:e}),returnType:c.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 U=(t,n)=>{const r=`
|
|
3
|
+
${O(n)}
|
|
4
|
+
type TargetType = ${t};
|
|
5
|
+
const val: TargetType = {} as any;
|
|
6
|
+
`,g="index.ts",l=A(g,r),p=l.getSourceFile(g),c=l.languageService.getProgram().getTypeChecker();let m=1;const a=F=>{if(f.isVariableDeclaration(F)&&F.name.getText()==="val"){const s=c.getTypeAtLocation(F);s.getCallSignatures().length>0?m=4:c.isArrayType(s)?m=2:s.isStringLiteral()||s.isNumberLiteral()||(s.getFlags()&(f.TypeFlags.String|f.TypeFlags.Number|f.TypeFlags.Boolean|f.TypeFlags.EnumLiteral|f.TypeFlags.BigInt|f.TypeFlags.ESSymbol))!==0?m=0:(s.isClassOrInterface()||(s.getFlags()&f.TypeFlags.Object)!==0)&&s.getProperties().length>0?m=3:m=1}f.forEachChild(F,a)};return a(p),m},ie=`
|
|
3
7
|
interface Array<T> {
|
|
4
8
|
[n: number]: T;
|
|
5
9
|
length: number;
|
|
@@ -13,59 +17,41 @@
|
|
|
13
17
|
interface NewableFunction extends Function {}
|
|
14
18
|
interface IArguments { }
|
|
15
19
|
interface RegExp { }
|
|
20
|
+
type Record<K extends keyof any, T> = { [P in K]: T; };
|
|
16
21
|
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
|
|
17
|
-
`;function
|
|
18
|
-
`),
|
|
19
|
-
`);return`${
|
|
20
|
-
${
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
${t?.map((i,g)=>`
|
|
40
|
-
declare function Fu${g}${i.signature};
|
|
41
|
-
type F${g} = ReturnType<typeof Fu${g}${o(i.signature)>0?`<${Array(o(i.signature)).fill("any").join(", ")}>`:""}>;
|
|
22
|
+
`;function A(t,n){const i=new Map;i.set(t,n),i.set("lib.codezero.d.ts",ie);const r=ne(i);return te(r,[t,"lib.codezero.d.ts"],f,ae)}const ae={target:f.ScriptTarget.Latest,lib:["lib.codezero.d.ts"],noEmit:!0,strictNullChecks:!0};function O(t){const n=Array.from(new Set(t?.flatMap(r=>r.genericKeys||[]))).map(r=>`type ${r} = any;`).join(`
|
|
23
|
+
`),i=t?.map(r=>`type ${r.identifier}${(r.genericKeys?.length??0)>0?`<${r.genericKeys?.join(",")}>`:""} = ${r.type};`).join(`
|
|
24
|
+
`);return`${n}
|
|
25
|
+
${i}`}const P=t=>t.replace(/[^a-zA-Z0-9]/g,"_");function z(t,n,i,r=!1){const g=t?.nodes?.nodes||[],l=new Map(n?.map(e=>[e.identifier,e])),p=new Set,u=(e,o,d)=>{const T=g.find(L=>L?.id===e);if(!T||!T.functionDefinition?.identifier)return"undefined";const S=(T.parameters?.nodes||[]).map((L,x)=>{const E=L.value;if(!E)return r?`/* @pos ${e} ${x} */ {}`:`/* @pos ${e} ${x} */ undefined`;if(E.__typename==="ReferenceValue"){const $=E;if(!$.nodeFunctionId)return`/* @pos ${e} ${x} */ undefined`;let N=$.inputIndex!==void 0?`p_${P($.nodeFunctionId)}_${$.parameterIndex}[${$.inputIndex}]`:`node_${P($.nodeFunctionId)}`;return $.referencePath?.forEach(h=>{N+=`?.${h.path}`}),`/* @pos ${e} ${x} */ ${N}`}return E.__typename==="LiteralValue"?`/* @pos ${e} ${x} */ ${JSON.stringify(E.value)}`:E.__typename==="NodeFunctionIdWrapper"?u(E.id,e,x):r?`/* @pos ${e} ${x} */ ({} as any)`:`/* @pos ${e} ${x} */ undefined`}).join(", "),w=`${`fn_${T.functionDefinition.identifier.replace(/::/g,"_")}`}(${S})`;return o!==void 0&&d!==void 0?`${w}`:w},c=(e,o="")=>{if(p.has(e))return"";const d=g.find(N=>N?.id===e);if(!d||!d.functionDefinition)return"";if(p.add(e),!l.get(d.functionDefinition.identifier))return`${o}// Error: Function ${d.functionDefinition.identifier} not found
|
|
26
|
+
`;let v={parameters:[]};r||(v=Q(d,n,i));const C=(d.parameters?.nodes||[]).map((N,h)=>{const b=N.value;if(!b)return r?`/* @pos ${e} ${h} */ {}`:`/* @pos ${e} ${h} */ undefined`;if(b.__typename==="ReferenceValue"){const _=b;if(!_.nodeFunctionId)return`/* @pos ${e} ${h} */ undefined`;let D=_.inputIndex!==void 0?`p_${P(_.nodeFunctionId)}_${_.parameterIndex}[${_.inputIndex}]`:`node_${P(_.nodeFunctionId)}`;return _.referencePath?.forEach(V=>{D+=`?.${V.path}`}),`/* @pos ${e} ${h} */ ${D}`}if(b.__typename==="LiteralValue")return`/* @pos ${e} ${h} */ ${JSON.stringify(b.value)}`;if(b.__typename==="NodeFunctionIdWrapper"){const _=b;if(r){const D=`p_${P(e)}_${h}`,V=c(_.id,o+" ");return`/* @pos ${e} ${h} */ (...${D}) => {
|
|
27
|
+
${V}${o}}`}else{const D=v.parameters[h];if(D?U(D,i)===j.NODE:!1){const M=`p_${P(e)}_${h}`,H=c(_.id,o+" ");return`/* @pos ${e} ${h} */ (...${M}) => {
|
|
28
|
+
${H}${o}}`}else{const M=u(_.id,e,h);return`/* @pos ${e} ${h} */ ${M}`}}}return r?`/* @pos ${e} ${h} */ {}`:`/* @pos ${e} ${h} */ undefined`}).join(", "),w=`node_${P(d.id)}`,L=`fn_${d?.functionDefinition?.identifier?.replace(/::/g,"_")}`,x=C.includes("undefined"),E=d.functionDefinition.identifier==="std::control::return";let $=`${o}${E?"return ":`const ${w} = `}${L}(${C}) ;
|
|
29
|
+
`;return d.nextNodeId&&($+=c(d.nextNodeId,o)),$},m=O(i),a=n?.map(e=>`declare function fn_${e.identifier?.replace(/::/g,"_")}${e.signature}`).join(`
|
|
30
|
+
`),F=new Set(g.map(e=>e?.nextNodeId).filter(e=>!!e)),s=new Set;g.forEach(e=>e?.parameters?.nodes?.forEach(o=>{o?.value?.__typename==="NodeFunctionIdWrapper"&&o.value.id&&s.add(o.value.id)}));const y=g.filter(e=>e?.id&&!F.has(e.id)&&!s.has(e.id)).map(e=>c(e.id)).join(`
|
|
31
|
+
`);return`${m}
|
|
32
|
+
${a}
|
|
33
|
+
|
|
34
|
+
// --- Flow ---
|
|
35
|
+
${y}`}function oe(t,n,i){const r=z(t,n,i,!0),g="index.ts",l=A(g,r),p=l.getSourceFile(g),c=l.languageService.getProgram().getTypeChecker(),m=new Map,a=new Map,F=new Map;(t?.nodes?.nodes||[]).forEach(e=>{e?.id&&F.set(P(e.id),e)});const y=e=>{if(f.isVariableDeclaration(e)&&e.name.getText().startsWith("node_")){const o=e.name.getText().replace("node_",""),d=c.getTypeAtLocation(e);if(m.set(o,c.typeToString(d,e,f.TypeFormatFlags.NoTruncation)),e.initializer&&f.isCallExpression(e.initializer)){const T=c.getResolvedSignature(e.initializer);if(T){const v=T.getParameters().map(S=>{const C=c.getTypeOfSymbolAtLocation(S,e.initializer);return c.typeToString(C,e.initializer,f.TypeFormatFlags.NoTruncation)});a.set(o,v)}}}if(f.isReturnStatement(e)&&e.expression&&f.isCallExpression(e.expression)){const o=e.expression;c.getResolvedSignature(o)}f.forEachChild(e,y)};return y(p),{nodes:m,parameters:a}}const se=t=>{const i=`const tempValue = ${JSON.stringify(t?.value)??"any"};`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker();let c="any";const m=a=>{if(f.isVariableDeclaration(a)&&a.name.getText()==="tempValue"){const F=u.getTypeAtLocation(a);c=u.typeToString(F,a,f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType)}f.forEachChild(a,m)};return m(l),c},ce=(t,n)=>{const i=`
|
|
36
|
+
${O(n)}
|
|
37
|
+
type Target = ${t};
|
|
38
|
+
`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker(),c=l.statements.find(s=>f.isTypeAliasDeclaration(s)&&s.name.text==="Target");if(!c)return{__typename:"LiteralValue",value:null};const m=u.getTypeAtLocation(c.type),a=(s,y,e=new Set)=>{if(e.has(s))return null;e.add(s);const o=s.getFlags();if(s.isUnion()){if(y.type,f.isTypeAliasDeclaration(y)&&y.type&&f.isUnionTypeNode(y.type)){const v=u.getTypeFromTypeNode(y.type.types[0]);return a(v,y,e)}const d=s.types.filter(v=>{const S=v.getFlags();return!(S&f.TypeFlags.Undefined)&&!(S&f.TypeFlags.Null)}),T=d.length>0?d[0]:s.types[0];return a(T,y,e)}if(o&f.TypeFlags.StringLiteral)return s.value;if(o&f.TypeFlags.String)return"";if(o&f.TypeFlags.NumberLiteral)return s.value;if(o&f.TypeFlags.Number)return 0;if(o&f.TypeFlags.BooleanLiteral)return s.intrinsicName==="true";if(o&f.TypeFlags.Boolean)return!1;if(u.isArrayType(s)){const T=s.typeArguments?.[0]||u.getAnyType();return[a(T,y,e)]}if(s.isClassOrInterface()||o&f.TypeFlags.Object||s.getProperties().length>0){const d={};return s.getProperties().forEach(v=>{const S=u.getTypeOfSymbolAtLocation(v,y);S&&(d[v.getName()]=a(S,y,e))}),d}return null};return{value:a(m,c)}},le=(t,n,i)=>{let r=n;const g=t?U(t,i):null;if(t&&n&&g!==j.NODE){let l=function(y){const e=y.trim().match(/^<([^>]+)>/);return e?e[1].split(",").map(o=>o.trim()).filter(Boolean).length:0};const p=`
|
|
39
|
+
${O(i)}
|
|
40
|
+
type TargetType = ${t};
|
|
41
|
+
${n?.map((y,e)=>`
|
|
42
|
+
declare function Fu${e}${y.signature};
|
|
43
|
+
type F${e} = ReturnType<typeof Fu${e}${l(y.signature)>0?`<${Array(l(y.signature)).fill("any").join(", ")}>`:""}>;
|
|
42
44
|
`).join(`
|
|
43
45
|
`)}
|
|
44
|
-
${
|
|
46
|
+
${n?.map((y,e)=>`const check${e}: TargetType = {} as F${e};`).join(`
|
|
45
47
|
`)}
|
|
46
|
-
|
|
47
|
-
`).findIndex(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
type T = ${e}; const val: T = {} as any;
|
|
57
|
-
`,r="index.ts",o=V(r,n),s=o.getSourceFile(r),a=o.languageService.getProgram().getTypeChecker(),u=s.statements.find(y.isTypeAliasDeclaration);if(!u)return[];const p=a.getTypeAtLocation(u),l=i=>i.isUnion()?i.types.flatMap(l):i.isStringLiteral()?[i.value]:i.isNumberLiteral()?[i.value.toString()]:i.intrinsicName==="true"?["true"]:i.intrinsicName==="false"?["false"]:[];return Array.from(new Set(l(p))).map(i=>({__typename:"LiteralValue",value:i}))},k=e=>e.replace(/[^a-zA-Z0-9]/g,"_"),ye=(e,t,n)=>{const r=new Set,o=e?.nodes?.nodes||[],s=new Map(t?.map(f=>[f.identifier,f])),c=(f,S="")=>{if(r.has(f))return"";const m=o.find(I=>I?.id===f);if(!m||!m.functionDefinition)return"";r.add(f);const $=s.get(m.functionDefinition?.identifier);if(!$)return`${S}// Error: Function ${m.functionDefinition.identifier} not found
|
|
58
|
-
`;const N=(m.parameters?.nodes||[]).map((I,b)=>{const D=I.value;if(!D)return"undefined";if(D.__typename==="ReferenceValue"){const L=D;if(!L.nodeFunctionId)return"undefined";let _=L.parameterIndex!==void 0?`/* @pos ${f} ${b} */ p_${k(L.nodeFunctionId)}_${L.parameterIndex}`:`/* @pos ${f} ${b} */ node_${k(L.nodeFunctionId)}`;return L.referencePath?.forEach(B=>{_+=`?.${B.path}`}),_}if(D.__typename==="LiteralValue")return`/* @pos ${f} ${b} */ ${JSON.stringify(D.value)}`;if(D.__typename==="NodeFunctionIdWrapper"){const L=D,_=`p_${k(m.id)}_${b}`,B=c(L.id,S+" ");return`/* @pos ${f} ${b} */ (${_}) => {
|
|
59
|
-
${B}${S}}`}return"undefined"}).join(", "),x=`node_${k(m.id)}`,C=`fn_${$.identifier?.replace(/::/g,"_")}`,P=N.includes("undefined");let M=`${S}const ${x} = ${C}(${N})${P?" as any":""} ;
|
|
60
|
-
`;return m.nextNodeId&&(M+=c(m.nextNodeId,S)),M},a=E(n),u=t?.map(f=>`declare function fn_${f.identifier?.replace(/::/g,"_")}${f.signature}`).join(`
|
|
61
|
-
`),p=o.map(f=>f?.id?c(f.id):"").filter(f=>f!=="").join(`
|
|
62
|
-
`),l=`${a}
|
|
63
|
-
${u}
|
|
64
|
-
|
|
65
|
-
// --- Flow ---
|
|
66
|
-
${p}`,T="index.ts",i=V(T,l),g=i.getSourceFile(T),h=i.languageService.getProgram().getSemanticDiagnostics(g).map(f=>{const S=y.flattenDiagnosticMessageText(f.messageText,`
|
|
67
|
-
`);if(S.includes("Argument of type 'undefined'")||S.includes("not assignable to type 'undefined'"))return null;let $,v;if(f.start!==void 0){const C=g.getFullText().substring(0,f.start).match(/\/\* @pos ([^ ]+) (\d+) \*\/\s*$/);C&&($=C[1],v=parseInt(C[2],10))}return{message:S,code:f.code,severity:"error",nodeId:$,parameterIndex:v}}).filter(f=>f!==null);return{isValid:!h.some(f=>f?.severity==="error"),returnType:"void",diagnostics:h}},Fe=(e,t,n)=>{const r=JSON.stringify(t?.value),o=`
|
|
68
|
-
${E(n)}
|
|
69
|
-
const testValue: ${e} = ${r};
|
|
70
|
-
`,s="index.ts",u=V(s,o).languageService.getSemanticDiagnostics(s).map(p=>{const l=y.flattenDiagnosticMessageText(p.messageText,`
|
|
71
|
-
`),T=/\b([TRKV])\b/.test(l),i=l.includes("not assignable to parameter of type")&&(l.includes("'{}'")||l.includes("undefined"))||l.includes("not assignable to type 'undefined'")||l.includes("not assignable to type 'void'")||l.includes("may be a mistake because neither type sufficiently overlaps");return{message:l,code:p.code,severity:T||i?"warning":"error"}});return{isValid:!u.some(p=>p.severity==="error"),returnType:"void",diagnostics:u}};exports.DataTypeVariant=Z;exports.getFlowValidation=ye;exports.getNodeSuggestions=de;exports.getNodeValidation=j;exports.getReferenceSuggestions=fe;exports.getTypeFromValue=ce;exports.getTypeVariant=ue;exports.getTypesFromNode=ge;exports.getValueFromType=le;exports.getValueSuggestions=me;exports.getValueValidation=Fe;
|
|
48
|
+
`,u="index.ts",c=A(u,p),m=c.getSourceFile(u),F=c.languageService.getProgram().getSemanticDiagnostics(),s=new Set;F.forEach(y=>{y.file===m&&y.start!==void 0&&s.add(m.getLineAndCharacterOfPosition(y.start).line)}),r=n.filter((y,e)=>{const o=`const check${e}: TargetType = {} as F${e};`,T=p.split(`
|
|
49
|
+
`).findIndex(v=>v.includes(o));return T!==-1&&!s.has(T)})}return r?.map(l=>({__typename:"NodeFunction",id:"gid://sagittarius/NodeFunction/1",functionDefinition:{__typename:"FunctionDefinition",id:l.id,identifier:l.identifier},parameters:{__typename:"NodeParameterConnection",nodes:(l.parameterDefinitions?.nodes||[]).map(p=>({__typename:"NodeParameter",parameterDefinition:{__typename:"ParameterDefinition",id:p?.id,identifier:p?.identifier},value:null}))}})).filter(l=>l!==null)??[]},ue=(t,n,i,r,g)=>{const l=z(t,r,g,!0),p="index.ts",u=A(p,l),c=u.getSourceFile(p),a=u.languageService.getProgram().getTypeChecker(),F=c.getFullText(),s=`/* @pos ${n} ${i} */`,e=F.indexOf(s)+s.length;function o($,N){let h=$;return f.forEachChild($,b=>{b.getStart(c,!0)<=N&&b.getEnd()>=N&&(h=o(b,N))}),h}const T=o(c,e);let v;if(f.isCallExpression(T)&&(v=T),!v)return[];const S=a.getResolvedSignature(v);if(!S)return[];const C=S.getParameters(),w=C[i]||C[C.length-1],L=a.getTypeOfSymbolAtLocation(w,T),x=a.getSymbolsInScope(T,f.SymbolFlags.Variable),E=[];return x.forEach($=>{const N=$.getName();if(!N.startsWith("node_")&&!N.startsWith("p_"))return;const h=$.valueDeclaration||$.declarations?.[0];if(!h||h.getEnd()>=e)return;const b=a.getTypeOfSymbolAtLocation($,T);if(N.startsWith("node_")){if((b.flags&f.TypeFlags.Void)===0&&a.isTypeAssignableTo(b,L)){const _=N.replace("node_","").replace(/___/g,"://").replace(/__/g,"/").replace(/_/g,"/");E.push({__typename:"ReferenceValue",nodeFunctionId:_})}}else if(N.startsWith("p_")){const _=N.replace("p_",""),D=_.lastIndexOf("_"),V=_.substring(0,D),M=parseInt(_.substring(D+1),10),H=V.replace("p_","").replace(/___/g,"://").replace(/__/g,"/").replace(/_/g,"/");if(a.isTupleType(b)){const B=b;a.getTypeArguments(B).forEach((Z,W)=>{a.isTypeAssignableTo(Z,L)&&E.push({__typename:"ReferenceValue",nodeFunctionId:H,parameterIndex:isNaN(M)?0:M,inputIndex:W,inputTypeIdentifier:B.target.labeledElementDeclarations?.[W].name.getText()})})}}}),E},ge=(t,n)=>{if(!t)return[];const i=`
|
|
50
|
+
${O(n)}
|
|
51
|
+
type VALUE = ${t}; const val: VALUE = {} as any;
|
|
52
|
+
`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker(),c=l.statements.find(s=>f.isTypeAliasDeclaration(s)&&s.name.text==="VALUE");if(!c||!f.isTypeAliasDeclaration(c))return[];const m=u.getTypeAtLocation(c),a=s=>s.isUnion()?s.types.flatMap(a):s.isStringLiteral()?[s.value]:s.isNumberLiteral()?[s.value.toString()]:s.intrinsicName==="true"?["true"]:s.intrinsicName==="false"?["false"]:[];return Array.from(new Set(a(m))).map(s=>({__typename:"LiteralValue",value:s}))},pe=(t,n,i)=>{const r=z(t,n,i),g="index.ts",l=A(g,r),p=l.getSourceFile(g),m=l.languageService.getProgram().getSemanticDiagnostics(p).map(a=>{const F=f.flattenDiagnosticMessageText(a.messageText,`
|
|
53
|
+
`);let s,y;if(a.start!==void 0){const e=p.getFullText(),o=Math.max(0,a.start-300),d=Math.min(e.length,a.start),T=e.substring(o,d),v=/\/\* @pos ([^ ]+) (\d+) \*\//g;let S,C=null,w=-1;for(;(S=v.exec(T))!==null;){const x=o+S.index+S[0].length;x<=a.start&&x>w&&(w=x,C=S)}C&&(s=C[1],y=parseInt(C[2],10))}return{message:F,code:a.code,severity:"error",nodeId:s,parameterIndex:y}}).filter(a=>a!==null);return{isValid:!m.some(a=>a?.severity==="error"),returnType:"void",diagnostics:m}},fe=(t,n,i)=>{const r=JSON.stringify(n?.value),g=`
|
|
54
|
+
${O(i)}
|
|
55
|
+
const testValue: ${t} = ${r};
|
|
56
|
+
`,l="index.ts",c=A(l,g).languageService.getSemanticDiagnostics(l).map(m=>{const a=f.flattenDiagnosticMessageText(m.messageText,`
|
|
57
|
+
`),F=a.includes("not assignable to parameter of type")&&(a.includes("'{}'")||a.includes("undefined"))||a.includes("not assignable to type 'undefined'")||a.includes("not assignable to type 'void'")||a.includes("may be a mistake because neither type sufficiently overlaps");return{message:a,code:m.code,severity:F?"warning":"error"}});return{isValid:!c.some(m=>m.severity==="error"),returnType:"void",diagnostics:c}};exports.DataTypeVariant=j;exports.getFlowValidation=pe;exports.getNodeSuggestions=le;exports.getReferenceSuggestions=ue;exports.getTypeFromValue=se;exports.getTypeVariant=U;exports.getTypesFromNode=Q;exports.getValueFromType=ce;exports.getValueSuggestions=ge;exports.getValueValidation=fe;
|