@code0-tech/triangulum 0.14.4 → 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.
package/dist/triangulum.cjs.js
CHANGED
|
@@ -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,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)){
|
|
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
|
@@ -579,14 +579,11 @@ var w = (t, n) => {
|
|
|
579
579
|
input: "sub-flow",
|
|
580
580
|
...u
|
|
581
581
|
};
|
|
582
|
-
if (Z(t, r)) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
...u
|
|
588
|
-
};
|
|
589
|
-
}
|
|
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
|
|
586
|
+
};
|
|
590
587
|
if ((r.flags & e.TypeFlags.Object) !== 0) {
|
|
591
588
|
let s = {}, c = [];
|
|
592
589
|
for (let l of t.getPropertiesOfType(r)) {
|
|
@@ -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[]>;
|
|
@@ -102,4 +102,3 @@ export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDecla
|
|
|
102
102
|
* @returns True if the type has call signatures, false otherwise
|
|
103
103
|
*/
|
|
104
104
|
export declare function isSubFlow(type: ts.Type): boolean;
|
|
105
|
-
export {};
|