@code0-tech/triangulum 0.14.3 → 0.14.5
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.
|
@@ -8,6 +8,8 @@ export interface NodeSchema {
|
|
|
8
8
|
nodeId: NodeFunction["id"];
|
|
9
9
|
/** The schema definition for this node parameter */
|
|
10
10
|
schema: Schema;
|
|
11
|
+
/** The schema definition for the function parameter */
|
|
12
|
+
functionSchema: Schema;
|
|
11
13
|
/** Array of parameter indices that must be resolved before this parameter */
|
|
12
14
|
blockedBy?: number[];
|
|
13
15
|
}
|
package/dist/triangulum.cjs.js
CHANGED
|
@@ -25,7 +25,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
25
25
|
import ReturnType = Utils.ReturnType;
|
|
26
26
|
`;function T(e,t){let n=new Map;return n.set(e,t),n.set(`lib.codezero.d.ts`,w),p(ee(n),[e,`lib.codezero.d.ts`],c.default,E)}var E={target:c.default.ScriptTarget.Latest,lib:[`lib.codezero.d.ts`],noEmit:!0,strictNullChecks:!0};function D(e,t=`any`,n=!0){let r=Array.from(new Set(e?.flatMap(e=>e.genericKeys||[]))).map(e=>`type ${e} = ${t};`).join(`
|
|
27
27
|
`),i=e?.map(e=>`type ${e.identifier}${(e.genericKeys?.length??0)>0?`<${e.genericKeys?.join(`,`)}>`:``} = ${e.type};`).join(`
|
|
28
|
-
`);return`${n?r:``}\n${i}`}var O=e=>e?.replace(/[^a-zA-Z0-9]/g,`_`);function k(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=``)=>{let c=i.find(e=>e?.id===t);if(!c||!c.functionDefinition)return``;if(o.add(t),!a.get(c.functionDefinition.identifier))return`${n}// Error: Function ${c.functionDefinition.identifier} not found\n`;let l=(c.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_${O(n.nodeFunctionId??`undefined`)}_${n.parameterIndex}[${n.inputIndex}]`:n.nodeFunctionId?`node_${O(n.nodeFunctionId)}`:`flow_${O(e?.id??`undefined`)}`;return n.referencePath?.forEach(e=>{r+=`?.${e.path}`}),`/* @pos ${t} ${a} */ ${r}`}if(o.__typename===`LiteralValue`)return`/* @pos ${t} ${a} */ ${S(o?.value)}`;if(o.__typename===`NodeFunctionIdWrapper`){let e=o;return`/* @pos ${t} ${a} */ (...${`p_${O(t)}_${a}`}) => {\n${s(e.id,n+` `)}${n}}`}return r?`/* @pos ${t} ${a} */ {}`:`/* @pos ${t} ${a} */ undefined`}),u=`node_${O(c.id)}`,d=`fn_${c?.functionDefinition?.identifier?.replace(/::/g,`_`)}`;l.includes(`undefined`);let f=`${n}`;return c.functionDefinition.identifier===`std::control::return`?f+=`return /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`:c.functionDefinition.identifier===`std::control::if`?(f+=`const ${u} = /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`,f+=`if(${l[0]}) {
|
|
28
|
+
`);return`${n?r:``}\n${i}`}var O=e=>e?.replace(/[^a-zA-Z0-9]/g,`_`);function k(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=``)=>{let c=i.find(e=>e?.id===t);if(!c||!c.functionDefinition)return``;if(o.add(t),!a.get(c.functionDefinition.identifier))return`${n}// Error: Function ${c.functionDefinition.identifier} not found\n`;let l=(c.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_${O(n.nodeFunctionId??`undefined`)}_${n.parameterIndex}[${n.inputIndex}]`:n.nodeFunctionId?`node_${O(n.nodeFunctionId)}`:`flow_${O(e?.id??`undefined`)}`;return n.referencePath?.forEach(e=>{r+=`?.${e.path}`}),`/* @pos ${t} ${a} */ ${r}`}if(o.__typename===`LiteralValue`)return`/* @pos ${t} ${a} */ ${S(o?.value)} as const`;if(o.__typename===`NodeFunctionIdWrapper`){let e=o;return`/* @pos ${t} ${a} */ (...${`p_${O(t)}_${a}`}) => {\n${s(e.id,n+` `)}${n}}`}return r?`/* @pos ${t} ${a} */ {}`:`/* @pos ${t} ${a} */ undefined`}),u=`node_${O(c.id)}`,d=`fn_${c?.functionDefinition?.identifier?.replace(/::/g,`_`)}`;l.includes(`undefined`);let f=`${n}`;return c.functionDefinition.identifier===`std::control::return`?f+=`return /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`:c.functionDefinition.identifier===`std::control::if`?(f+=`const ${u} = /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`,f+=`if(${l[0]}) {
|
|
29
29
|
${s(c.parameters?.nodes?.[1]?.value?.id,n+` `)}
|
|
30
30
|
}`):c.functionDefinition.identifier===`std::control::if_else`?(f+=`const ${u} = /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`,f+=`if(${l[0]}) {
|
|
31
31
|
${s(c.parameters?.nodes?.[1]?.value?.id,n+` `)}
|
|
@@ -52,4 +52,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
52
52
|
${D(n)}
|
|
53
53
|
const testValue: ${e} = ${r};
|
|
54
54
|
`,a=`index.ts`,o=T(a,i).languageService.getSemanticDiagnostics(a).map(e=>{let t=c.default.flattenDiagnosticMessageText(e.messageText,`
|
|
55
|
-
`),n=t.includes(`not assignable to parameter of type`)&&(t.includes(`'{}'`)||t.includes(`undefined`))||t.includes(`not assignable to type 'undefined'`)||t.includes(`not assignable to type 'void'`)||t.includes(`may be a mistake because neither type sufficiently overlaps`);return{message:t,code:e.code,severity:n?`warning`:`error`}});return{isValid:!o.some(e=>e.severity===`error`),returnType:`void`,diagnostics:o}},M=e=>e.isUnion()?e.types.flatMap(M):e.isStringLiteral()?[{value:e.value,__typename:`LiteralValue`}]:e.isNumberLiteral()?[{value:e.value.toString()}]:e.intrinsicName===`true`?[{value:!0,__typename:`LiteralValue`}]:e.intrinsicName===`false`?[{value:!1,__typename:`LiteralValue`}]:[],N=(e,t,n,r)=>r.flatMap(r=>{let i=r.getName();if(!P(i))return[];let a=r.getDeclarations()?.[0];if(!a||a.getEnd()>=t.getEnd())return[];let o=e.getTypeOfSymbolAtLocation(r,t);return i.startsWith(`node_`)?F(i,o,e,n):i.startsWith(`p_`)?I(i,o,e,n):i.startsWith(`flow_`)?L(o,e,n):[]}),P=e=>e.startsWith(`node_`)||e.startsWith(`p_`)||e.startsWith(`flow_`),F=(e,t,n,r)=>{if((t.flags&c.default.TypeFlags.Void)!==0)return[];let i=R(e.replace(`node_`,``));return B(t,n,r).flatMap(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:i};return e.length>0&&(t.referencePath=e),t})},I=(e,t,n,r)=>{let{nodeFunctionId:i,paramIndexFromName:a}=z(e);if(!n.isTupleType(t))return[];let o=t;return n.getTypeArguments(o).flatMap((e,t)=>B(e,n,r).flatMap(({path:e})=>{let n={__typename:`ReferenceValue`,nodeFunctionId:i,parameterIndex:isNaN(a)?0:a,inputIndex:t,inputTypeIdentifier:o.target.labeledElementDeclarations?.[t].name.getText()};return e.length>0&&(n.referencePath=e),n}))},L=(e,t,n)=>B(e,t,n).flatMap(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:null};return e.length>0&&(t.referencePath=e),t}),R=e=>e.replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`),z=e=>{let t=e.replace(`p_`,``),n=t.lastIndexOf(`_`),r=t.substring(0,n),i=parseInt(t.substring(n+1),10);return{nodeFunctionId:R(r),paramIndexFromName:i}},B=(e,t,n,r=[])=>{let i=[];if(t.isTypeAssignableTo(e,n)&&i.push({path:r,type:e}),V(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=>{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},H=(e,t,n,r)=>Q(r)?[]:t.flatMap(t=>{let i=U(e,t,n,r);return i?[i]:[]}),U=(e,t,n,r)=>{let i=e.getSignatureFromDeclaration(t),a=W(e,e.getReturnTypeOfSignature(i));if(!e.isTypeAssignableTo(a,r))return null;let o=G(t.name?.getText());return re(n.find(e=>e.identifier===o))},W=(e,t)=>t.isTypeParameter()?e.getBaseConstraintOfType(t)||e.getAnyType():t,G=e=>e?e.replace(`fn_`,``).replace(`_`,`::`).replace(`_`,`::`):``,re=e=>{let t=(e?.parameterDefinitions?.nodes?.length??0)>0,n={__typename:`NodeFunction`,id:`gid://sagittarius/NodeFunction/1`,functionDefinition:{__typename:`FunctionDefinition`,id:e?.id,identifier:e?.identifier,names:e?.names,descriptions:e?.descriptions,displayIcon:e?.displayIcon}};return t&&(n.parameters=K(e?.parameterDefinitions?.nodes||[])),n},K=e=>({__typename:`NodeParameterConnection`,nodes:e.map(e=>q(e))}),q=e=>({__typename:`NodeParameter`,parameterDefinition:{__typename:`ParameterDefinition`,id:e?.id,identifier:e?.identifier},value:e?.defaultValue?{__typename:`LiteralValue`,value:e.defaultValue.value}:null}),J=(e,t,n,r,i)=>{let
|
|
55
|
+
`),n=t.includes(`not assignable to parameter of type`)&&(t.includes(`'{}'`)||t.includes(`undefined`))||t.includes(`not assignable to type 'undefined'`)||t.includes(`not assignable to type 'void'`)||t.includes(`may be a mistake because neither type sufficiently overlaps`);return{message:t,code:e.code,severity:n?`warning`:`error`}});return{isValid:!o.some(e=>e.severity===`error`),returnType:`void`,diagnostics:o}},M=e=>e.isUnion()?e.types.flatMap(M):e.isStringLiteral()?[{value:e.value,__typename:`LiteralValue`}]:e.isNumberLiteral()?[{value:e.value.toString()}]:e.intrinsicName===`true`?[{value:!0,__typename:`LiteralValue`}]:e.intrinsicName===`false`?[{value:!1,__typename:`LiteralValue`}]:[],N=(e,t,n,r)=>r.flatMap(r=>{let i=r.getName();if(!P(i))return[];let a=r.getDeclarations()?.[0];if(!a||a.getEnd()>=t.getEnd())return[];let o=e.getTypeOfSymbolAtLocation(r,t);return i.startsWith(`node_`)?F(i,o,e,n):i.startsWith(`p_`)?I(i,o,e,n):i.startsWith(`flow_`)?L(o,e,n):[]}),P=e=>e.startsWith(`node_`)||e.startsWith(`p_`)||e.startsWith(`flow_`),F=(e,t,n,r)=>{if((t.flags&c.default.TypeFlags.Void)!==0)return[];let i=R(e.replace(`node_`,``));return B(t,n,r).flatMap(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:i};return e.length>0&&(t.referencePath=e),t})},I=(e,t,n,r)=>{let{nodeFunctionId:i,paramIndexFromName:a}=z(e);if(!n.isTupleType(t))return[];let o=t;return n.getTypeArguments(o).flatMap((e,t)=>B(e,n,r).flatMap(({path:e})=>{let n={__typename:`ReferenceValue`,nodeFunctionId:i,parameterIndex:isNaN(a)?0:a,inputIndex:t,inputTypeIdentifier:o.target.labeledElementDeclarations?.[t].name.getText()};return e.length>0&&(n.referencePath=e),n}))},L=(e,t,n)=>B(e,t,n).flatMap(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:null};return e.length>0&&(t.referencePath=e),t}),R=e=>e.replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`),z=e=>{let t=e.replace(`p_`,``),n=t.lastIndexOf(`_`),r=t.substring(0,n),i=parseInt(t.substring(n+1),10);return{nodeFunctionId:R(r),paramIndexFromName:i}},B=(e,t,n,r=[])=>{let i=[];if(t.isTypeAssignableTo(e,n)&&i.push({path:r,type:e}),V(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=>{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},H=(e,t,n,r)=>Q(r)?[]:t.flatMap(t=>{let i=U(e,t,n,r);return i?[i]:[]}),U=(e,t,n,r)=>{let i=e.getSignatureFromDeclaration(t),a=W(e,e.getReturnTypeOfSignature(i));if(!e.isTypeAssignableTo(a,r))return null;let o=G(t.name?.getText());return re(n.find(e=>e.identifier===o))},W=(e,t)=>t.isTypeParameter()?e.getBaseConstraintOfType(t)||e.getAnyType():t,G=e=>e?e.replace(`fn_`,``).replace(`_`,`::`).replace(`_`,`::`):``,re=e=>{let t=(e?.parameterDefinitions?.nodes?.length??0)>0,n={__typename:`NodeFunction`,id:`gid://sagittarius/NodeFunction/1`,functionDefinition:{__typename:`FunctionDefinition`,id:e?.id,identifier:e?.identifier,names:e?.names,descriptions:e?.descriptions,displayIcon:e?.displayIcon}};return t&&(n.parameters=K(e?.parameterDefinitions?.nodes||[])),n},K=e=>({__typename:`NodeParameterConnection`,nodes:e.map(e=>q(e))}),q=e=>({__typename:`NodeParameter`,parameterDefinition:{__typename:`ParameterDefinition`,id:e?.id,identifier:e?.identifier},value:e?.defaultValue?{__typename:`LiteralValue`,value:e.defaultValue.value}:null}),J=(e,t,n,r,i,a=!0)=>{let o=M(n),s=N(e,t,n,e.getSymbolsInScope(t,c.default.SymbolFlags.Variable)),l=H(e,r,i,n),u=a?{suggestions:[...o,...s,...l]}:{};if(Y(n))return{input:`boolean`,...u};if(X(n))return{input:`number`,...u};if(Z(n))return{input:`text`,...u};if(ae(n))return{input:`select`,...u};if(Q(n))return{input:`sub-flow`,...u};if(oe(e,n))return{input:`list`,items:e.getTypeArguments(n).flatMap(n=>(n.isUnion()?n.types:[n]).map(n=>J(e,t,n,r,i,a))),...u};if((n.flags&c.default.TypeFlags.Object)!==0){let o={},s=[];for(let l of e.getPropertiesOfType(n)){let n=l.valueDeclaration??l.declarations?.[0];if(!n)continue;let u=e.getTypeOfSymbolAtLocation(l,n),d=(l.flags&c.default.SymbolFlags.Optional)!==0||u.isUnion()&&u.types.some(e=>(e.flags&c.default.TypeFlags.Undefined)!==0),f=(u.isUnion()?u.types.filter(e=>(e.flags&c.default.TypeFlags.Undefined)===0):[u]).map(n=>J(e,t,n,r,i,a));o[l.name]=f.length===1?f[0]:f,d||s.push(l.name)}return{input:`data`,properties:o,required:s,...u}}return{input:`generic`}};function Y(e){return(e.flags&c.default.TypeFlags.Boolean)!==0||(e.flags&c.default.TypeFlags.BooleanLiteral)!==0}function X(e){return(e.flags&c.default.TypeFlags.Number)!==0||(e.flags&c.default.TypeFlags.NumberLiteral)!==0}function Z(e){return(e.flags&c.default.TypeFlags.String)!==0||(e.flags&c.default.TypeFlags.StringLiteral)!==0}function ie(e){return Z(e)||X(e)||Y(e)}function ae(e){return e.isUnion()?e.types.every(ie):!1}function oe(e,t){return e.isArrayType(t)||e.isTupleType(t)}function Q(e){return e.getCallSignatures().length>0}var $=(e,t,n,r)=>{let i=k(e,n,t),a=`index.ts`,o=T(a,i),s=o.getSourceFile(a),c=o.languageService.getProgram().getTypeChecker(),l=e.nodes?.nodes?.find(e=>e?.id===r),u=r?`fn_${l?.functionDefinition?.identifier?.replace(/::/g,`_`)}`:`flow`,d=r?`node_${O(r)}`:`flow_${O(e.id)}`,f=se(s),p=ce(s).get(d),m=f.get(u);return fe(r,c,p,le(c,p),ue(c,m,p),de(m),r?f:new Map,r?n:[])},se=e=>new Map(e.statements.filter(c.default.isFunctionDeclaration).map(e=>[e.name.getText(),e])),ce=e=>{let t=[];return e.statements.forEach(e=>{e.forEachChild(function e(n){c.default.isVariableDeclaration(n)&&(n.parent.flags&c.default.NodeFlags.Const)!==0&&t.push([n.name.getText(),n]),n.forEachChild(e)})}),new Map(t)},le=(e,t)=>{if(!(!t?.initializer||!c.default.isCallExpression(t.initializer)))return t.initializer?.arguments.map(t=>e.getTypeAtLocation(t))},ue=(e,t,n)=>{if(!(!t||!n?.initializer))return t.parameters.map(t=>{let r=e.getSymbolAtLocation(t.name);return e.getTypeOfSymbolAtLocation(r,n.initializer)})},de=e=>{let t=e.typeParameters?.map(e=>e.name.getText())||[],n={};return e.parameters.forEach((e,r)=>{let i=e.type?.getText()||``;t.forEach(e=>{i.includes(e)&&(n[e]||(n[e]=[]),n[e].push(r))})}),Object.values(n).filter(e=>e.length>1).map(([e,...t])=>t.map(t=>({parameterIndex:t,dependsOnIndex:e}))).flat()},fe=(e,t,n,r,i,a,o,s)=>r?r.map((r,c)=>({nodeId:e,schema:J(t,n,r,Array.from(o.values()),s),functionSchema:J(t,n,i?.[c],Array.from(o.values()),s,!1),blockedBy:a.filter(e=>e.parameterIndex===c).map(e=>e.dependsOnIndex)})):[];exports.getFlowValidation=A,exports.getSignatureSchema=$,exports.getTypeFromValue=te,exports.getValueFromType=ne,exports.getValueValidation=j;
|
package/dist/triangulum.es.js
CHANGED
|
@@ -274,7 +274,7 @@ function C(e, t, n, r = !1) {
|
|
|
274
274
|
r += `?.${e.path}`;
|
|
275
275
|
}), `/* @pos ${t} ${a} */ ${r}`;
|
|
276
276
|
}
|
|
277
|
-
if (o.__typename === "LiteralValue") return `/* @pos ${t} ${a} */ ${g(o?.value)}`;
|
|
277
|
+
if (o.__typename === "LiteralValue") return `/* @pos ${t} ${a} */ ${g(o?.value)} as const`;
|
|
278
278
|
if (o.__typename === "NodeFunctionIdWrapper") {
|
|
279
279
|
let e = o;
|
|
280
280
|
return `/* @pos ${t} ${a} */ (...${`p_${S(t)}_${a}`}) => {\n${s(e.id, n + " ")}${n}}`;
|
|
@@ -553,53 +553,50 @@ var w = (t, n) => {
|
|
|
553
553
|
__typename: "LiteralValue",
|
|
554
554
|
value: e.defaultValue.value
|
|
555
555
|
} : null
|
|
556
|
-
}), G = (t, n, r, i, a) => {
|
|
557
|
-
let
|
|
558
|
-
...o,
|
|
556
|
+
}), G = (t, n, r, i, a, o = !0) => {
|
|
557
|
+
let s = O(r), c = k(t, n, r, t.getSymbolsInScope(n, e.SymbolFlags.Variable)), l = R(t, i, a, r), u = o ? { suggestions: [
|
|
559
558
|
...s,
|
|
560
|
-
...c
|
|
561
|
-
|
|
559
|
+
...c,
|
|
560
|
+
...l
|
|
561
|
+
] } : {};
|
|
562
562
|
if (K(r)) return {
|
|
563
563
|
input: "boolean",
|
|
564
|
-
...
|
|
564
|
+
...u
|
|
565
565
|
};
|
|
566
566
|
if (q(r)) return {
|
|
567
567
|
input: "number",
|
|
568
|
-
...
|
|
568
|
+
...u
|
|
569
569
|
};
|
|
570
570
|
if (J(r)) return {
|
|
571
571
|
input: "text",
|
|
572
|
-
...
|
|
572
|
+
...u
|
|
573
573
|
};
|
|
574
574
|
if (X(r)) return {
|
|
575
575
|
input: "select",
|
|
576
|
-
...
|
|
576
|
+
...u
|
|
577
577
|
};
|
|
578
578
|
if (Q(r)) return {
|
|
579
579
|
input: "sub-flow",
|
|
580
|
-
...
|
|
580
|
+
...u
|
|
581
|
+
};
|
|
582
|
+
if (Z(t, r)) return {
|
|
583
|
+
input: "list",
|
|
584
|
+
items: t.getTypeArguments(r).flatMap((e) => (e.isUnion() ? e.types : [e]).map((e) => G(t, n, e, i, a, o))),
|
|
585
|
+
...u
|
|
581
586
|
};
|
|
582
|
-
if (Z(t, r)) {
|
|
583
|
-
let e = t.getTypeArguments(r)[0], o = (e.isUnion() ? e.types : [e]).map((e) => G(t, n, e, i, a));
|
|
584
|
-
return {
|
|
585
|
-
input: "list",
|
|
586
|
-
items: o.length === 1 ? o[0] : o,
|
|
587
|
-
...l
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
587
|
if ((r.flags & e.TypeFlags.Object) !== 0) {
|
|
591
|
-
let
|
|
592
|
-
for (let
|
|
593
|
-
let r =
|
|
588
|
+
let s = {}, c = [];
|
|
589
|
+
for (let l of t.getPropertiesOfType(r)) {
|
|
590
|
+
let r = l.valueDeclaration ?? l.declarations?.[0];
|
|
594
591
|
if (!r) continue;
|
|
595
|
-
let
|
|
596
|
-
|
|
592
|
+
let u = t.getTypeOfSymbolAtLocation(l, r), d = (l.flags & e.SymbolFlags.Optional) !== 0 || u.isUnion() && u.types.some((t) => (t.flags & e.TypeFlags.Undefined) !== 0), f = (u.isUnion() ? u.types.filter((t) => (t.flags & e.TypeFlags.Undefined) === 0) : [u]).map((e) => G(t, n, e, i, a, o));
|
|
593
|
+
s[l.name] = f.length === 1 ? f[0] : f, d || c.push(l.name);
|
|
597
594
|
}
|
|
598
595
|
return {
|
|
599
596
|
input: "data",
|
|
600
|
-
properties:
|
|
601
|
-
required:
|
|
602
|
-
...
|
|
597
|
+
properties: s,
|
|
598
|
+
required: c,
|
|
599
|
+
...u
|
|
603
600
|
};
|
|
604
601
|
}
|
|
605
602
|
return { input: "generic" };
|
|
@@ -628,8 +625,8 @@ function Q(e) {
|
|
|
628
625
|
//#endregion
|
|
629
626
|
//#region src/schema/getSignatureSchema.ts
|
|
630
627
|
var $ = (e, t, n, r) => {
|
|
631
|
-
let i = C(e, n, t), a = "index.ts", o = y(a, i), s = o.getSourceFile(a), c = o.languageService.getProgram().getTypeChecker(), l = e.nodes?.nodes?.find((e) => e?.id === r), u = r ? `fn_${l?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", d = r ? `node_${S(r)}` : `flow_${S(e.id)}`, f = ee(s), p = te(s).get(d), m = f.get(u)
|
|
632
|
-
return
|
|
628
|
+
let i = C(e, n, t), a = "index.ts", o = y(a, i), s = o.getSourceFile(a), c = o.languageService.getProgram().getTypeChecker(), l = e.nodes?.nodes?.find((e) => e?.id === r), u = r ? `fn_${l?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", d = r ? `node_${S(r)}` : `flow_${S(e.id)}`, f = ee(s), p = te(s).get(d), m = f.get(u);
|
|
629
|
+
return ae(r, c, p, ne(c, p), re(c, m, p), ie(m), r ? f : /* @__PURE__ */ new Map(), r ? n : []);
|
|
633
630
|
}, ee = (t) => new Map(t.statements.filter(e.isFunctionDeclaration).map((e) => [e.name.getText(), e])), te = (t) => {
|
|
634
631
|
let n = [];
|
|
635
632
|
return t.statements.forEach((t) => {
|
|
@@ -638,25 +635,13 @@ var $ = (e, t, n, r) => {
|
|
|
638
635
|
});
|
|
639
636
|
}), new Map(n);
|
|
640
637
|
}, ne = (t, n) => {
|
|
641
|
-
if (!(!n?.initializer || !e.isCallExpression(n.initializer))) return
|
|
638
|
+
if (!(!n?.initializer || !e.isCallExpression(n.initializer))) return n.initializer?.arguments.map((e) => t.getTypeAtLocation(e));
|
|
642
639
|
}, re = (e, t, n) => {
|
|
643
640
|
if (!(!t || !n?.initializer)) return t.parameters.map((t) => {
|
|
644
641
|
let r = e.getSymbolAtLocation(t.name);
|
|
645
642
|
return e.getTypeOfSymbolAtLocation(r, n.initializer);
|
|
646
643
|
});
|
|
647
|
-
}, ie = (e
|
|
648
|
-
if (t) return t.map((t, r) => {
|
|
649
|
-
let i = n?.[r];
|
|
650
|
-
if (!i) return t;
|
|
651
|
-
let a = t.getSymbol(), o = i.getSymbol();
|
|
652
|
-
if (a && o && a === o) return i;
|
|
653
|
-
if (t.isTypeParameter()) {
|
|
654
|
-
let n = e.getBaseConstraintOfType(t);
|
|
655
|
-
if (!n || e.isTypeAssignableTo(i, n)) return i;
|
|
656
|
-
}
|
|
657
|
-
return e.isTypeAssignableTo(i, t) ? i : t;
|
|
658
|
-
});
|
|
659
|
-
}, ae = (e) => {
|
|
644
|
+
}, ie = (e) => {
|
|
660
645
|
let t = e.typeParameters?.map((e) => e.name.getText()) || [], n = {};
|
|
661
646
|
return e.parameters.forEach((e, r) => {
|
|
662
647
|
let i = e.type?.getText() || "";
|
|
@@ -667,10 +652,11 @@ var $ = (e, t, n, r) => {
|
|
|
667
652
|
parameterIndex: t,
|
|
668
653
|
dependsOnIndex: e
|
|
669
654
|
}))).flat();
|
|
670
|
-
},
|
|
655
|
+
}, ae = (e, t, n, r, i, a, o, s) => r ? r.map((r, c) => ({
|
|
671
656
|
nodeId: e,
|
|
672
|
-
schema: G(t, n, r, Array.from(
|
|
673
|
-
|
|
657
|
+
schema: G(t, n, r, Array.from(o.values()), s),
|
|
658
|
+
functionSchema: G(t, n, i?.[c], Array.from(o.values()), s, !1),
|
|
659
|
+
blockedBy: a.filter((e) => e.parameterIndex === c).map((e) => e.dependsOnIndex)
|
|
674
660
|
})) : [];
|
|
675
661
|
//#endregion
|
|
676
662
|
export { E as getFlowValidation, $ as getSignatureSchema, w as getTypeFromValue, T as getValueFromType, D as getValueValidation };
|
|
@@ -4,7 +4,7 @@ import { FunctionDefinition, LiteralValue, NodeFunction, ReferenceValue } from '
|
|
|
4
4
|
* Base interface for all input types.
|
|
5
5
|
* Provides common properties for suggestions and input metadata.
|
|
6
6
|
*/
|
|
7
|
-
interface Input {
|
|
7
|
+
export interface Input {
|
|
8
8
|
/** The type of input (string representation) */
|
|
9
9
|
input?: string;
|
|
10
10
|
/** Array of suggested values (functions, references, or literals) */
|
|
@@ -14,28 +14,28 @@ interface Input {
|
|
|
14
14
|
* Represents a generic input type with no specific structure.
|
|
15
15
|
* Used as a fallback when the type cannot be determined.
|
|
16
16
|
*/
|
|
17
|
-
interface GenericInput extends Input {
|
|
17
|
+
export interface GenericInput extends Input {
|
|
18
18
|
input?: "generic";
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Represents a sub-flow input type (callable/function type).
|
|
22
22
|
* Used for types that have call signatures.
|
|
23
23
|
*/
|
|
24
|
-
interface SubFlowInput extends Input {
|
|
24
|
+
export interface SubFlowInput extends Input {
|
|
25
25
|
input?: "sub-flow";
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Represents primitive input types: boolean, number, text, or select.
|
|
29
29
|
* Extends the base Input interface to include suggestions.
|
|
30
30
|
*/
|
|
31
|
-
interface PrimitiveInput extends Input {
|
|
31
|
+
export interface PrimitiveInput extends Input {
|
|
32
32
|
input?: "boolean" | "number" | "text" | "select";
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Represents a data object input type with structured properties.
|
|
36
36
|
* Includes property definitions and required field tracking.
|
|
37
37
|
*/
|
|
38
|
-
interface DataInput extends Input {
|
|
38
|
+
export interface DataInput extends Input {
|
|
39
39
|
input?: "data";
|
|
40
40
|
/** Record mapping property names to their schemas */
|
|
41
41
|
properties?: Record<string, Schema | Schema[]>;
|
|
@@ -46,16 +46,16 @@ interface DataInput extends Input {
|
|
|
46
46
|
* Represents a list/array input type with item schemas.
|
|
47
47
|
* Supports homogeneous or heterogeneous arrays.
|
|
48
48
|
*/
|
|
49
|
-
interface ListInput extends Input {
|
|
49
|
+
export interface ListInput extends Input {
|
|
50
50
|
input?: "list";
|
|
51
51
|
/** Schema or array of schemas for list items */
|
|
52
|
-
items?: Schema
|
|
52
|
+
items?: Schema[];
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Represents a complex type input with properties and required fields.
|
|
56
56
|
* Similar to DataInput but used for type definitions.
|
|
57
57
|
*/
|
|
58
|
-
interface TypeInput extends Input {
|
|
58
|
+
export interface TypeInput extends Input {
|
|
59
59
|
input?: "type";
|
|
60
60
|
/** Record mapping property names to their schemas */
|
|
61
61
|
properties?: Record<string, Schema | Schema[]>;
|
|
@@ -88,9 +88,10 @@ export type Schema = PrimitiveInput | DataInput | ListInput | TypeInput | SubFlo
|
|
|
88
88
|
* @param parameterType - The type to generate a schema for
|
|
89
89
|
* @param functionDeclarations - Array of function declaration nodes
|
|
90
90
|
* @param functions - Array of function definitions for matching
|
|
91
|
+
* @param suggestions
|
|
91
92
|
* @returns A Schema object describing how to handle the parameter type
|
|
92
93
|
*/
|
|
93
|
-
export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[]) => Schema;
|
|
94
|
+
export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[], suggestions?: boolean) => Schema;
|
|
94
95
|
/**
|
|
95
96
|
* Checks if a type is a callable type (has call signatures).
|
|
96
97
|
*
|
|
@@ -101,4 +102,3 @@ export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDecla
|
|
|
101
102
|
* @returns True if the type has call signatures, false otherwise
|
|
102
103
|
*/
|
|
103
104
|
export declare function isSubFlow(type: ts.Type): boolean;
|
|
104
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code0-tech/triangulum",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/code0-tech/triangulum#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2462825049-b5d5dce99ef9bf2f81df41d896ec36fa5e28559c",
|
|
27
27
|
"@types/node": "^25.6.0",
|
|
28
28
|
"@typescript/vfs": "^1.6.4",
|
|
29
|
-
"typescript": "^6.0.
|
|
29
|
+
"typescript": "^6.0.3",
|
|
30
30
|
"vite": "^8.0.8",
|
|
31
31
|
"vite-plugin-dts": "^4.5.4",
|
|
32
32
|
"vitest": "^4.1.4",
|