@code0-tech/triangulum 0.12.3 → 0.13.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/triangulum.cjs.js +4 -4
- package/dist/triangulum.es.js +29 -7
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/triangulum.cjs.js
CHANGED
|
@@ -29,13 +29,13 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
29
29
|
import ReturnType = Utils.ReturnType;
|
|
30
30
|
`;function k(e,t){let n=new Map;return n.set(e,t),n.set(`lib.codezero.d.ts`,O),p(v(n),[e,`lib.codezero.d.ts`],c.default,A)}var A={target:c.default.ScriptTarget.Latest,lib:[`lib.codezero.d.ts`],noEmit:!0,strictNullChecks:!0};function j(e,t=`any`,n=!0){let r=Array.from(new Set(e?.flatMap(e=>e.genericKeys||[]))).map(e=>`type ${e} = ${t};`).join(`
|
|
31
31
|
`),i=e?.map(e=>`type ${e.identifier}${(e.genericKeys?.length??0)>0?`<${e.genericKeys?.join(`,`)}>`:``} = ${e.type};`).join(`
|
|
32
|
-
`);return`${n?r:``}\n${i}`}var M=e=>e.replace(/[^a-zA-Z0-9]/g,`_`);function N(e,t,n,r=!1){let i=e?.nodes?.nodes||[],a=new Map(t?.map(e=>[e.identifier,e])),o=new Set,s=(t,n,a)=>{let o=i.find(e=>e?.id===t);if(!o||!o.functionDefinition?.identifier)return`undefined`;let c=(o.parameters?.nodes||[]).map((n,i)=>{let a=n.value;if(!a)return r?`/* @pos ${t} ${i} */ {}`:`/* @pos ${t} ${i} */ undefined`;if(a.__typename===`ReferenceValue`){let n=a,r=typeof n.inputIndex==`number`?`p_${M(n.nodeFunctionId??`undefined`)}_${n.parameterIndex}[${n.inputIndex}]`:n.nodeFunctionId?`node_${M(n.nodeFunctionId)}`:`flow_${M(e?.id??`undefined`)}`;return n.referencePath?.forEach(e=>{r+=`?.${e.path}`}),`/* @pos ${t} ${i} */ ${r}`}return a.__typename===`LiteralValue`?`/* @pos ${t} ${i} */ ${E(a?.value)}`:a.__typename===`NodeFunctionIdWrapper`?s(a.id,t,i):r?`/* @pos ${t} ${i} */ ({} as any)`:`/* @pos ${t} ${i} */ undefined`}).join(`, `),l=`${
|
|
32
|
+
`);return`${n?r:``}\n${i}`}var M=e=>e.replace(/[^a-zA-Z0-9]/g,`_`);function N(e,t,n,r=!1){let i=e?.nodes?.nodes||[],a=new Map(t?.map(e=>[e.identifier,e])),o=new Set,s=(t,n,a)=>{let o=i.find(e=>e?.id===t);if(!o||!o.functionDefinition?.identifier)return`undefined`;let c=(o.parameters?.nodes||[]).map((n,i)=>{let a=n.value;if(!a)return r?`/* @pos ${t} ${i} */ {}`:`/* @pos ${t} ${i} */ undefined`;if(a.__typename===`ReferenceValue`){let n=a,r=typeof n.inputIndex==`number`?`p_${M(n.nodeFunctionId??`undefined`)}_${n.parameterIndex}[${n.inputIndex}]`:n.nodeFunctionId?`node_${M(n.nodeFunctionId)}`:`flow_${M(e?.id??`undefined`)}`;return n.referencePath?.forEach(e=>{r+=`?.${e.path}`}),`/* @pos ${t} ${i} */ ${r}`}return a.__typename===`LiteralValue`?`/* @pos ${t} ${i} */ ${E(a?.value)}`:a.__typename===`NodeFunctionIdWrapper`?s(a.id,t,i):r?`/* @pos ${t} ${i} */ ({} as any)`:`/* @pos ${t} ${i} */ undefined`}).join(`, `),l=`${`/* @pos ${t} null */ fn_${o.functionDefinition.identifier.replace(/::/g,`_`)}`}(${c})`;return n!==void 0&&a!==void 0?`${l}`:l},c=(t,l=``)=>{if(o.has(t))return``;let u=i.find(e=>e?.id===t);if(!u||!u.functionDefinition)return``;o.add(t);let d=a.get(u.functionDefinition.identifier);if(!d)return`${l}// Error: Function ${u.functionDefinition.identifier} not found\n`;let f={parameters:[]};r||(f=C(d));let p=(u.parameters?.nodes||[]).map((i,a)=>{let o=i.value;if(!o)return r?`/* @pos ${t} ${a} */ {}`:`/* @pos ${t} ${a} */ undefined`;if(o.__typename===`ReferenceValue`){let n=o,r=typeof n.inputIndex==`number`?`p_${M(n.nodeFunctionId??`undefined`)}_${n.parameterIndex}[${n.inputIndex}]`:n.nodeFunctionId?`node_${M(n.nodeFunctionId)}`:`flow_${M(e?.id??`undefined`)}`;return n.referencePath?.forEach(e=>{r+=`?.${e.path}`}),`/* @pos ${t} ${a} */ ${r}`}if(o.__typename===`LiteralValue`)return`/* @pos ${t} ${a} */ ${E(o?.value)}`;if(o.__typename===`NodeFunctionIdWrapper`){let e=o;if(r)return`/* @pos ${t} ${a} */ (...${`p_${M(t)}_${a}`}) => {\n${c(e.id,l+` `)}${l}}`;{let r=f.parameters[a];return r&&S(r,n)[0].variant===x.NODE?`/* @pos ${t} ${a} */ (...${`p_${M(t)}_${a}`}) => {\n${c(e.id,l+` `)}${l}}`:`/* @pos ${t} ${a} */ ${s(e.id,t,a)}`}}return r?`/* @pos ${t} ${a} */ {}`:`/* @pos ${t} ${a} */ undefined`}).join(`, `),m=`node_${M(u.id)}`,h=`fn_${u?.functionDefinition?.identifier?.replace(/::/g,`_`)}`;p.includes(`undefined`);let g=`${l}${u.functionDefinition.identifier===`std::control::return`?`return `:`const ${m} = `}/* @pos ${t} null */ ${h}(${p}) ;\n`;return u.nextNodeId&&(g+=c(u.nextNodeId,l)),g},l=j(n),u=`declare function flow${e?.signature??`(): void`}`,d=t?.map(e=>`declare function fn_${e.identifier?.replace(/::/g,`_`)}${e.signature}`).join(`
|
|
33
33
|
`),f=new Set(i.map(e=>e?.nextNodeId).filter(e=>!!e)),p=new Set;return i.forEach(e=>e?.parameters?.nodes?.forEach(e=>{e?.value?.__typename===`NodeFunctionIdWrapper`&&e.value.id&&p.add(e.value.id)})),`
|
|
34
34
|
${l}\n
|
|
35
35
|
${u}\n
|
|
36
36
|
${d}\n
|
|
37
37
|
(() =>
|
|
38
|
-
${e?`const flow_${M(e.id??``)} = flow(${e.settings?.nodes?.map((e,t)=>`/* @pos
|
|
38
|
+
${e?`const flow_${M(e.id??``)} = /* @pos null null */ flow(${e.settings?.nodes?.map((e,t)=>`/* @pos null ${t} */ ${E(e?.value)}`).join(`, `)??``});`:``}
|
|
39
39
|
${i.filter(e=>e?.id&&!f.has(e.id)&&!p.has(e.id)).map(e=>c(e.id)).join(`
|
|
40
40
|
`)}
|
|
41
41
|
)();
|
|
@@ -59,8 +59,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
59
59
|
`).findIndex(e=>e.includes(n));return r!==-1&&!u.has(r)})}return r?.map(e=>({__typename:`NodeFunction`,id:`gid://sagittarius/NodeFunction/1`,functionDefinition:{__typename:`FunctionDefinition`,id:e.id,identifier:e.identifier},parameters:{__typename:`NodeParameterConnection`,nodes:(e.parameterDefinitions?.nodes||[]).map(e=>({__typename:`NodeParameter`,parameterDefinition:{__typename:`ParameterDefinition`,id:e?.id,identifier:e?.identifier},value:e?.defaultValue?{__typename:`LiteralValue`,value:e.defaultValue.value}:null}))}})).filter(e=>e!==null)??[]},z=e=>{let t=c.default.TypeFlags.String|c.default.TypeFlags.Number|c.default.TypeFlags.Boolean|c.default.TypeFlags.Undefined|c.default.TypeFlags.Null|c.default.TypeFlags.BigInt|c.default.TypeFlags.ESSymbol;return(e.flags&t)===0},B=(e,t,n,r=[])=>{let i=[];if(t.isTypeAssignableTo(e,n)&&i.push({path:r,type:e}),z(e)){let a=e.getProperties();a&&a.length>0&&a.forEach(e=>{let a=t.getTypeOfSymbolAtLocation(e,e.valueDeclaration),o=e.getName(),s=[...r,{path:o}];i.push(...B(a,t,n,s))})}return i},V=(e,t,n,r,i)=>{let a=e?.nodes?.nodes?.findIndex(e=>e?.id==t);typeof a==`number`&&a>=0&&typeof n==`number`&&n>=0&&e?.nodes?.nodes?.[a]?.parameters?.nodes?.[n]&&(e.nodes.nodes[a].parameters.nodes[n].value=null);let o=N(e,r,i,!0),s=`index.ts`,l=k(s,o),u=l.getSourceFile(s),d=l.languageService.getProgram().getTypeChecker(),f=u.getFullText(),p=`/* @pos ${t} ${n} */`,m=f.indexOf(p)+p.length;function h(e,t){let n=e;return c.default.forEachChild(e,e=>{e.getStart(u,!0)<=t&&e.getEnd()>=t&&(n=h(e,t))}),n}let g=h(u,m),_;if(c.default.isCallExpression(g)&&(_=g),!_)return[];let v=d.getResolvedSignature(_);if(!v)return[];let y=v.getParameters(),b=y[n]||y[y.length-1],x=d.getTypeOfSymbolAtLocation(b,g),S=d.getSymbolsInScope(g,c.default.SymbolFlags.Variable),C=[];return S.forEach(e=>{let t=e.getName();if(!t.startsWith(`node_`)&&!t.startsWith(`p_`)&&!t.startsWith(`flow_`))return;let n=e.valueDeclaration||e.declarations?.[0];if(!n||n.getEnd()>=m)return;let r=d.getTypeOfSymbolAtLocation(e,g);if(t.startsWith(`node_`)){if((r.flags&c.default.TypeFlags.Void)===0){let e=t.replace(`node_`,``).replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`);B(r,d,x).forEach(({path:t})=>{let n={__typename:`ReferenceValue`,nodeFunctionId:e};t.length>0&&(n.referencePath=t),C.push(n)})}}else if(t.startsWith(`p_`)){let e=t.replace(`p_`,``),n=e.lastIndexOf(`_`),i=e.substring(0,n),a=parseInt(e.substring(n+1),10),o=i.replace(`p_`,``).replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`);if(d.isTupleType(r)){let e=r;d.getTypeArguments(e).forEach((t,n)=>{B(t,d,x).forEach(({path:t})=>{let r={__typename:`ReferenceValue`,nodeFunctionId:o,parameterIndex:isNaN(a)?0:a,inputIndex:n,inputTypeIdentifier:e.target.labeledElementDeclarations?.[n].name.getText()};t.length>0&&(r.referencePath=t),C.push(r)})})}}else t.startsWith(`flow_`)&&B(r,d,x).forEach(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:null};e.length>0&&(t.referencePath=e),C.push(t)})}),C},H=(e,t)=>{if(!e)return[];let n=`
|
|
60
60
|
${j(t)}
|
|
61
61
|
type VALUE = ${e}; const val: VALUE = {} as any;
|
|
62
|
-
`,r=`index.ts`,i=k(r,n),a=i.getSourceFile(r),o=i.languageService.getProgram().getTypeChecker(),s=a.statements.find(e=>c.default.isTypeAliasDeclaration(e)&&e.name.text===`VALUE`);if(!s||!c.default.isTypeAliasDeclaration(s))return[];let l=o.getTypeAtLocation(s),u=e=>e.isUnion()?e.types.flatMap(u):e.isStringLiteral()?[e.value]:e.isNumberLiteral()?[e.value.toString()]:e.intrinsicName===`true`?[`true`]:e.intrinsicName===`false`?[`false`]:[];return Array.from(new Set(u(l))).map(e=>({__typename:`LiteralValue`,value:e}))},U=(e,t,n)=>{let r=N(e,t,n),i=`index.ts`,a=k(i,r),o=a.getSourceFile(i),s=a.languageService.getProgram().getSemanticDiagnostics(o).map(e=>{let t=(0,c.flattenDiagnosticMessageText)(e.messageText,`
|
|
63
|
-
`),n,r;if(e.start!==void 0){let t=o.getFullText(),i=Math.max(0,e.start-300),a=Math.min(t.length,e.start),s=t.substring(i,a),c=/\/\* @pos ([^ ]+) (\d
|
|
62
|
+
`,r=`index.ts`,i=k(r,n),a=i.getSourceFile(r),o=i.languageService.getProgram().getTypeChecker(),s=a.statements.find(e=>c.default.isTypeAliasDeclaration(e)&&e.name.text===`VALUE`);if(!s||!c.default.isTypeAliasDeclaration(s))return[];let l=o.getTypeAtLocation(s),u=e=>e.isUnion()?e.types.flatMap(u):e.isStringLiteral()?[e.value]:e.isNumberLiteral()?[e.value.toString()]:e.intrinsicName===`true`?[`true`]:e.intrinsicName===`false`?[`false`]:[];return Array.from(new Set(u(l))).map(e=>({__typename:`LiteralValue`,value:e}))},U=(e,t,n)=>{if(!e?.startingNodeId)return{isValid:!1,returnType:`void`,diagnostics:[{nodeId:null,parameterIndex:null,code:0,message:`You need to provide a starting node to be able to execute this flow.`,severity:`error`}]};if(!e.nodes?.nodes?.find(t=>t?.id==e.startingNodeId))return{isValid:!1,returnType:`void`,diagnostics:[{nodeId:null,parameterIndex:null,code:0,message:`The starting node is not linked within the flow. Please make sure the starting node is connected to the rest of the flow.`,severity:`error`}]};let r=N(e,t,n),i=`index.ts`,a=k(i,r),o=a.getSourceFile(i),s=a.languageService.getProgram().getSemanticDiagnostics(o).map(e=>{let t=(0,c.flattenDiagnosticMessageText)(e.messageText,`
|
|
63
|
+
`),n,r=null;if(e.start!==void 0){let t=o.getFullText(),i=Math.max(0,e.start-300),a=Math.min(t.length,e.start),s=t.substring(i,a),c=/\/\* @pos ([^ ]+) (\d+|null) \*\//g,l,u=null,d=-1;for(;(l=c.exec(s))!==null;){let t=i+l.index+l[0].length;t<=e.start&&t>d&&(d=t,u=l)}u&&(n=u[1]===`null`?null:u[1],r=parseInt(u[2],10))}return{message:t,code:e.code,severity:`error`,nodeId:n,parameterIndex:typeof r==`number`&&Number.isSafeInteger(r)?r:null}}).filter(e=>e!==null);return{isValid:!s.some(e=>e?.severity===`error`),returnType:`void`,diagnostics:s}},W=(e,t,n)=>{let r=E(t?.value),i=`
|
|
64
64
|
${j(n)}
|
|
65
65
|
const testValue: ${e} = ${r};
|
|
66
66
|
`,a=`index.ts`,o=k(a,i).languageService.getSemanticDiagnostics(a).map(e=>{let t=c.default.flattenDiagnosticMessageText(e.messageText,`
|
package/dist/triangulum.es.js
CHANGED
|
@@ -382,7 +382,7 @@ function E(e, t, n, r = !1) {
|
|
|
382
382
|
}), `/* @pos ${t} ${i} */ ${r}`;
|
|
383
383
|
}
|
|
384
384
|
return a.__typename === "LiteralValue" ? `/* @pos ${t} ${i} */ ${y(a?.value)}` : a.__typename === "NodeFunctionIdWrapper" ? s(a.id, t, i) : r ? `/* @pos ${t} ${i} */ ({} as any)` : `/* @pos ${t} ${i} */ undefined`;
|
|
385
|
-
}).join(", "), l = `${
|
|
385
|
+
}).join(", "), l = `${`/* @pos ${t} null */ fn_${o.functionDefinition.identifier.replace(/::/g, "_")}`}(${c})`;
|
|
386
386
|
return n !== void 0 && a !== void 0 ? `${l}` : l;
|
|
387
387
|
}, c = (t, l = "") => {
|
|
388
388
|
if (o.has(t)) return "";
|
|
@@ -414,7 +414,7 @@ function E(e, t, n, r = !1) {
|
|
|
414
414
|
return r ? `/* @pos ${t} ${a} */ {}` : `/* @pos ${t} ${a} */ undefined`;
|
|
415
415
|
}).join(", "), _ = `node_${T(u.id)}`, v = `fn_${u?.functionDefinition?.identifier?.replace(/::/g, "_")}`;
|
|
416
416
|
p.includes("undefined");
|
|
417
|
-
let b = `${l}${u.functionDefinition.identifier === "std::control::return" ? "return " : `const ${_} = `}${v}(${p}) ;\n`;
|
|
417
|
+
let b = `${l}${u.functionDefinition.identifier === "std::control::return" ? "return " : `const ${_} = `}/* @pos ${t} null */ ${v}(${p}) ;\n`;
|
|
418
418
|
return u.nextNodeId && (b += c(u.nextNodeId, l)), b;
|
|
419
419
|
}, l = w(n), u = `declare function flow${e?.signature ?? "(): void"}`, d = t?.map((e) => `declare function fn_${e.identifier?.replace(/::/g, "_")}${e.signature}`).join("\n"), f = new Set(i.map((e) => e?.nextNodeId).filter((e) => !!e)), p = /* @__PURE__ */ new Set();
|
|
420
420
|
return i.forEach((e) => e?.parameters?.nodes?.forEach((e) => {
|
|
@@ -424,7 +424,7 @@ function E(e, t, n, r = !1) {
|
|
|
424
424
|
${u}\n
|
|
425
425
|
${d}\n
|
|
426
426
|
(() =>
|
|
427
|
-
${e ? `const flow_${T(e.id ?? "")} = flow(${e.settings?.nodes?.map((e, t) => `/* @pos
|
|
427
|
+
${e ? `const flow_${T(e.id ?? "")} = /* @pos null null */ flow(${e.settings?.nodes?.map((e, t) => `/* @pos null ${t} */ ${y(e?.value)}`).join(", ") ?? ""});` : ""}
|
|
428
428
|
${i.filter((e) => e?.id && !f.has(e.id) && !p.has(e.id)).map((e) => c(e.id)).join("\n")}
|
|
429
429
|
)();
|
|
430
430
|
`;
|
|
@@ -714,22 +714,44 @@ var O = (t, n) => {
|
|
|
714
714
|
value: e
|
|
715
715
|
}));
|
|
716
716
|
}, I = (e, n, r) => {
|
|
717
|
+
if (!e?.startingNodeId) return {
|
|
718
|
+
isValid: !1,
|
|
719
|
+
returnType: "void",
|
|
720
|
+
diagnostics: [{
|
|
721
|
+
nodeId: null,
|
|
722
|
+
parameterIndex: null,
|
|
723
|
+
code: 0,
|
|
724
|
+
message: "You need to provide a starting node to be able to execute this flow.",
|
|
725
|
+
severity: "error"
|
|
726
|
+
}]
|
|
727
|
+
};
|
|
728
|
+
if (!e.nodes?.nodes?.find((t) => t?.id == e.startingNodeId)) return {
|
|
729
|
+
isValid: !1,
|
|
730
|
+
returnType: "void",
|
|
731
|
+
diagnostics: [{
|
|
732
|
+
nodeId: null,
|
|
733
|
+
parameterIndex: null,
|
|
734
|
+
code: 0,
|
|
735
|
+
message: "The starting node is not linked within the flow. Please make sure the starting node is connected to the rest of the flow.",
|
|
736
|
+
severity: "error"
|
|
737
|
+
}]
|
|
738
|
+
};
|
|
717
739
|
let i = E(e, n, r), a = "index.ts", o = S(a, i), s = o.getSourceFile(a), c = o.languageService.getProgram().getSemanticDiagnostics(s).map((e) => {
|
|
718
|
-
let n = t(e.messageText, "\n"), r, i;
|
|
740
|
+
let n = t(e.messageText, "\n"), r, i = null;
|
|
719
741
|
if (e.start !== void 0) {
|
|
720
|
-
let t = s.getFullText(), n = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(n, a), c = /\/\* @pos ([^ ]+) (\d
|
|
742
|
+
let t = s.getFullText(), n = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(n, a), c = /\/\* @pos ([^ ]+) (\d+|null) \*\//g, l, u = null, d = -1;
|
|
721
743
|
for (; (l = c.exec(o)) !== null;) {
|
|
722
744
|
let t = n + l.index + l[0].length;
|
|
723
745
|
t <= e.start && t > d && (d = t, u = l);
|
|
724
746
|
}
|
|
725
|
-
u && (r = u[1] === "
|
|
747
|
+
u && (r = u[1] === "null" ? null : u[1], i = parseInt(u[2], 10));
|
|
726
748
|
}
|
|
727
749
|
return {
|
|
728
750
|
message: n,
|
|
729
751
|
code: e.code,
|
|
730
752
|
severity: "error",
|
|
731
753
|
nodeId: r,
|
|
732
|
-
parameterIndex: i
|
|
754
|
+
parameterIndex: typeof i == "number" && Number.isSafeInteger(i) ? i : null
|
|
733
755
|
};
|
|
734
756
|
}).filter((e) => e !== null);
|
|
735
757
|
return {
|
package/dist/utils.d.ts
CHANGED