@code0-tech/triangulum 0.2.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/LICENSE +1 -1
- package/dist/extraction/getTypeFromValue.d.ts +1 -1
- package/dist/extraction/getTypeVariant.d.ts +3 -2
- package/dist/extraction/getTypesFromNode.d.ts +1 -1
- package/dist/extraction/getValueFromType.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/suggestion/getNodeSuggestions.d.ts +1 -1
- package/dist/suggestion/getReferenceSuggestions.d.ts +1 -1
- package/dist/suggestion/getValueSuggestions.d.ts +2 -2
- package/dist/triangulum.cjs.js +41 -52
- package/dist/triangulum.es.js +455 -622
- package/dist/utils.d.ts +15 -10
- package/dist/validation/getFlowValidation.d.ts +1 -1
- package/dist/validation/getValueValidation.d.ts +1 -1
- package/package.json +1 -1
- package/dist/validation/getNodeValidation.d.ts +0 -6
package/LICENSE
CHANGED
|
@@ -6,4 +6,4 @@ The above copyright notice and this permission notice shall be included in all c
|
|
|
6
6
|
|
|
7
7
|
AI Usage Restriction: Notwithstanding the permissions granted above, this Software and its source code may not be used, in whole or in part, for the purpose of training, fine-tuning, or developing artificial intelligence (AI) models or machine learning algorithms without prior written consent from the Copyright Holder.
|
|
8
8
|
|
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -2,4 +2,4 @@ import { LiteralValue } from '@code0-tech/sagittarius-graphql-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Uses the TypeScript compiler to generate a precise type string from any runtime value.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getTypeFromValue: (value
|
|
5
|
+
export declare const getTypeFromValue: (value?: LiteralValue | null) => string;
|
|
@@ -3,9 +3,10 @@ export declare enum DataTypeVariant {
|
|
|
3
3
|
PRIMITIVE = 0,
|
|
4
4
|
TYPE = 1,
|
|
5
5
|
ARRAY = 2,
|
|
6
|
-
OBJECT = 3
|
|
6
|
+
OBJECT = 3,
|
|
7
|
+
NODE = 4
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Determines the variant of a given TypeScript type string using the TS compiler.
|
|
10
11
|
*/
|
|
11
|
-
export declare const getTypeVariant: (type
|
|
12
|
+
export declare const getTypeVariant: (type?: string, dataTypes?: DataType[]) => DataTypeVariant;
|
|
@@ -6,4 +6,4 @@ export interface NodeTypes {
|
|
|
6
6
|
/**
|
|
7
7
|
* Resolves the types of the parameters and the return type of a NodeFunction.
|
|
8
8
|
*/
|
|
9
|
-
export declare const getTypesFromNode: (node
|
|
9
|
+
export declare const getTypesFromNode: (node?: NodeFunction, functions?: FunctionDefinition[], dataTypes?: DataType[]) => NodeTypes;
|
|
@@ -2,4 +2,4 @@ import { DataType, LiteralValue } from '@code0-tech/sagittarius-graphql-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Generates a sample LiteralValue from a TypeScript type string.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getValueFromType: (type
|
|
5
|
+
export declare const getValueFromType: (type?: string, dataTypes?: DataType[]) => LiteralValue;
|
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, FunctionDefinition, NodeFunction } from '@code0-tech/sagittar
|
|
|
3
3
|
* Suggests NodeFunctions based on a given type and a list of available FunctionDefinitions.
|
|
4
4
|
* Returns functions whose return type is compatible with the target type.
|
|
5
5
|
*/
|
|
6
|
-
export declare
|
|
6
|
+
export declare const getNodeSuggestions: (type?: string, functions?: FunctionDefinition[], dataTypes?: DataType[]) => NodeFunction[];
|
|
@@ -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
|
|
6
|
+
export declare const getReferenceSuggestions: (flow?: Flow, nodeId?: NodeFunction["id"], targetIndex?: number, functions?: FunctionDefinition[], dataTypes?: DataType[]) => ReferenceValue[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LiteralValue } from '@code0-tech/sagittarius-graphql-types';
|
|
1
|
+
import { DataType, LiteralValue } from '@code0-tech/sagittarius-graphql-types';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts possible literal values from a type string to provide suggestions.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getValueSuggestions: (type
|
|
5
|
+
export declare const getValueSuggestions: (type?: string, dataTypes?: DataType[]) => LiteralValue[];
|
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,56 +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
|
-
${E(r)}
|
|
29
|
-
declare function testFunc${f};
|
|
30
|
-
const result = testFunc(${m});
|
|
31
|
-
`,i="index.ts",l=D(i,p),v=l.getSourceFile(i),d=l.languageService.getProgram(),h=d.getTypeChecker(),g=d.getSemanticDiagnostics(v);let S="any";const y=T=>{if(F.isVariableDeclaration(T)&&T.name.getText()==="result"){const N=h.getTypeAtLocation(T);S=h.typeToString(N,T,F.TypeFormatFlags.NoTruncation|F.TypeFormatFlags.UseFullyQualifiedType)}F.forEachChild(T,y)};y(v);const $=g.map(T=>{const N=F.flattenDiagnosticMessageText(T.messageText,`
|
|
32
|
-
`),x=/\b([TRKV])\b/.test(N),C=N.includes("not assignable to parameter of type")&&(N.includes("'{}'")||N.includes("undefined"))||N.includes("not assignable to type 'undefined'")||N.includes("not assignable to type 'void'")||N.includes("may be a mistake because neither type sufficiently overlaps");return{message:N,code:T.code,nodeId:t.id,parameterIndex:(()=>{if(T.start!==void 0){const P=s.findIndex((M,I)=>{const b=p.indexOf(u[I]);return T.start>=b&&T.start<b+u[I].length});if(P!==-1)return P}})(),severity:x||C?"warning":"error"}});return{isValid:!$.some(T=>T.severity==="error"),returnType:S,diagnostics:$}},ge=(e,t,n)=>{const o=new Map(t.map(y=>[y.identifier,y])).get(e.functionDefinition?.identifier);if(!o)return{parameters:[],returnType:"any"};const c={id:"gid://sagittarius/Flow/0",nodes:{__typename:"NodeFunctionConnection",nodes:[e]}},u=(e.parameters?.nodes||[]).map(y=>q(y,c,($,T)=>j($,T,t,n))).map(y=>y==="undefined"?"({} as any)":y).join(", "),m=o.signature,f=`
|
|
33
|
-
${E(n)}
|
|
34
|
-
declare function testFunc${m};
|
|
35
|
-
const result = testFunc(${u});
|
|
36
|
-
`,p="index.ts",i=D(p,f),l=i.getSourceFile(p),d=i.languageService.getProgram().getTypeChecker();let h="any",g=[];const S=y=>{if(F.isVariableDeclaration(y)&&y.name.getText()==="result"){const $=d.getTypeAtLocation(y);if(h=d.typeToString($,y,F.TypeFormatFlags.NoTruncation),F.isCallExpression(y.initializer)){const T=y.initializer,N=d.getResolvedSignature(T);N&&(g=N.getParameters().map(x=>{const C=d.getTypeOfSymbolAtLocation(x,T);return d.typeToString(C,T,F.TypeFormatFlags.NoTruncation)}))}}F.forEachChild(y,S)};return S(l),{parameters:g,returnType:h}};function de(e,t,n){if(!e||!t||t.length===0)return[];function r(i){const l=i.match(/<([^>]+)>/);return l?l[1].split(",").map(v=>v.trim()).filter(Boolean).length:0}const c=`
|
|
37
|
-
${E(n)}
|
|
38
|
-
type TargetType = ${e};
|
|
39
|
-
${t.map((i,l)=>`
|
|
40
|
-
declare function Fu${l}${i.signature};
|
|
41
|
-
type F${l} = ReturnType<typeof Fu${l}${r(i.signature)>0?`<${Array(r(i.signature)).fill("any").join(", ")}>`:""}>;
|
|
42
|
-
`).join(`
|
|
43
|
-
`)}
|
|
44
|
-
${t.map((i,l)=>`const check${l}: TargetType = {} as F${l};`).join(`
|
|
45
|
-
`)}
|
|
46
|
-
`,s="index.ts",a=D(s,c),u=a.getSourceFile(s),f=a.languageService.getProgram().getSemanticDiagnostics(),p=new Set;return f.forEach(i=>{i.file===u&&i.start!==void 0&&p.add(u.getLineAndCharacterOfPosition(i.start).line)}),t.map((i,l)=>{const v=`const check${l}: TargetType = {} as F${l};`,h=c.split(`
|
|
47
|
-
`).findIndex(g=>g.includes(v));return h!==-1&&p.has(h)?null:{__typename:"NodeFunction",id:"gid://sagittarius/NodeFunction/1",functionDefinition:{__typename:"FunctionDefinition",id:i.identifier,identifier:i.identifier},parameters:{__typename:"NodeParameterConnection",nodes:(i.parameterDefinitions?.nodes||[]).map(g=>({__typename:"NodeParameter",parameterDefinition:{__typename:"ParameterDefinition",id:g?.identifier,identifier:g?.identifier},value:null}))}}}).filter(i=>i!==null)}const fe=(e,t,n,r,o)=>{const c=[],s=e.nodes?.nodes||[],a=s.find(i=>i?.id===t);if(!a)return[];const u=E(o),m=(i,l)=>{if(!n||n==="any"||i==="any")return!0;const v="index.ts",d=`
|
|
48
|
-
${u}
|
|
49
|
-
const val: ${i} = {} as any;
|
|
50
|
-
const test: ${n} = val${l?`.${l}`:""};
|
|
51
|
-
`,h=D(v,d),g=h.getSourceFile(v);return!h.languageService.getProgram().getSemanticDiagnostics(g).some($=>$.category===F.DiagnosticCategory.Error)},f=(i,l)=>{const v=[],d="index.ts",h=`
|
|
52
|
-
${u}
|
|
53
|
-
const val: ${i} = {} as any;
|
|
54
|
-
`,g=D(d,h),S=g.getSourceFile(d),y=g.languageService.getProgram(),$=y.getTypeChecker();m(i)&&v.push({...l,referencePath:[]});const T=(x,C=[])=>{if(C.length>3)return;const P=x.getProperties();for(const M of P){const I=M.getName();let b;if($.getPropertyOfType){const _=$.getPropertyOfType(x,I);_&&(b=$.getTypeOfSymbolAtLocation(_,S))}else{const _=x.getProperty(I);_&&(b=$.getTypeOfSymbolAtLocation(_,S))}if(!b)continue;const V=[...C,I],L=V.join(".");m(i,L)&&v.push({...l,referencePath:V.map(_=>({__typename:"ReferencePath",path:_}))}),T(b,V)}};if(y.getSemanticDiagnostics(S).length===0){let x;const C=P=>{F.isVariableDeclaration(P)&&P.name.getText()==="val"&&(x=$.getTypeAtLocation(P)),F.forEachChild(P,C)};C(S),x&&T(x)}return v};if(e.inputType){const i=e.inputType||"any";c.push(...f(i,{}))}s.forEach(i=>{if(!(!i||i.id===t)&&pe(e,i,a)){const l=j(e,i,r,o);c.push(...f(l.returnType,{__typename:"ReferenceValue",nodeFunctionId:i.id,referencePath:[]}))}});let p=O(e,t);for(;p;){if(r.find(l=>l.identifier===p.functionDefinition?.identifier)){const l=p.parameters?.nodes?.findIndex(v=>{const d=v?.value;if(d?.__typename==="NodeFunctionIdWrapper"){const h=d;return h.id===t||z(e,h.id||void 0,t)}return!1});l!==void 0&&l!==-1&&c.push(...f("any",{__typename:"ReferenceValue",nodeFunctionId:p.id,parameterIndex:l,inputIndex:0,referencePath:[]}))}p=O(e,p.id)}return c};function pe(e,t,n){const r=e.nodes?.nodes||[];let o=t.nextNodeId;const c=new Set;for(;o;){if(o===n.id)return!0;if(c.has(o))break;c.add(o),o=r.find(u=>u?.id===o)?.nextNodeId}let s=O(e,n.id);for(;s;){if(s.id===t.id)return!0;s=O(e,s.id)}return!1}function O(e,t){return e.nodes?.nodes?.find(r=>r?.parameters?.nodes?.some(o=>o?.value?.__typename==="NodeFunctionIdWrapper"&&o.value.id===t))||void 0}function z(e,t,n){if(!t)return!1;if(t===n)return!0;const o=(e.nodes?.nodes||[]).find(s=>s?.id===t);return o?o.nextNodeId&&z(e,o.nextNodeId||void 0,n)?!0:!!o.parameters?.nodes?.some(s=>{const a=s?.value;return a?.__typename==="NodeFunctionIdWrapper"?z(e,a.id||void 0,n):!1}):!1}const me=e=>{if(!e)return[];const t=`type T = ${e}; const val: T = {} as any;`,n="index.ts",r=D(n,t),o=r.getSourceFile(n),s=r.languageService.getProgram().getTypeChecker(),a=o.statements.find(F.isTypeAliasDeclaration);if(!a)return[];const u=s.getTypeAtLocation(a),m=p=>p.isUnion()?p.types.flatMap(m):p.isStringLiteral()?[p.value]:p.isNumberLiteral()?[p.value.toString()]:p.intrinsicName==="true"?["true"]:p.intrinsicName==="false"?["false"]:[];return Array.from(new Set(m(u))).map(p=>({__typename:"LiteralValue",value:p}))},k=e=>e.replace(/[^a-zA-Z0-9]/g,"_"),ye=(e,t,n)=>{const r=new Set,o=e.nodes?.nodes||[],c=new Map(t.map(g=>[g.identifier,g])),s=(g,S="")=>{if(r.has(g))return"";const y=o.find(I=>I?.id===g);if(!y||!y.functionDefinition)return"";r.add(g);const $=c.get(y.functionDefinition?.identifier);if(!$)return`${S}// Error: Function ${y.functionDefinition.identifier} not found
|
|
55
|
-
`;const N=(y.parameters?.nodes||[]).map((I,b)=>{const V=I.value;if(!V)return"undefined";if(V.__typename==="ReferenceValue"){const L=V;if(!L.nodeFunctionId)return"undefined";let _=L.parameterIndex!==void 0?`/* @pos ${g} ${b} */ p_${k(L.nodeFunctionId)}_${L.parameterIndex}`:`/* @pos ${g} ${b} */ node_${k(L.nodeFunctionId)}`;return L.referencePath?.forEach(B=>{_+=`?.${B.path}`}),_}if(V.__typename==="LiteralValue")return`/* @pos ${g} ${b} */ ${JSON.stringify(V.value)}`;if(V.__typename==="NodeFunctionIdWrapper"){const L=V,_=`p_${k(y.id)}_${b}`,B=s(L.id,S+" ");return`/* @pos ${g} ${b} */ (${_}) => {
|
|
56
|
-
${B}${S}}`}return"undefined"}).join(", "),x=`node_${k(y.id)}`,C=`fn_${$.identifier?.replace(/::/g,"_")}`,P=N.includes("undefined");let M=`${S}const ${x} = ${C}(${N})${P?" as any":""} ;
|
|
57
|
-
`;return y.nextNodeId&&(M+=s(y.nextNodeId,S)),M},a=E(n),u=t.map(g=>`declare function fn_${g.identifier?.replace(/::/g,"_")}${g.signature}`).join(`
|
|
58
|
-
`),m=o.map(g=>g?.id?s(g.id):"").filter(g=>g!=="").join(`
|
|
59
|
-
`),f=`${a}
|
|
60
|
-
${u}
|
|
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}
|
|
61
33
|
|
|
62
34
|
// --- Flow ---
|
|
63
|
-
${
|
|
64
|
-
|
|
65
|
-
${
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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(", ")}>`:""}>;
|
|
44
|
+
`).join(`
|
|
45
|
+
`)}
|
|
46
|
+
${n?.map((y,e)=>`const check${e}: TargetType = {} as F${e};`).join(`
|
|
47
|
+
`)}
|
|
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;
|