@code0-tech/triangulum 0.37.1 → 0.38.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.cjs CHANGED
@@ -1,12 +1,12 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-oMAOCPrM.cjs");let t=require("typescript");t=e.m(t,1);var n=(n,r)=>{let i=e.p(n?.value);if(!i)return`any`;let a=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-BftsgxoV.cjs");let t=require("typescript");t=e.b(t,1);var n=(n,r)=>{let i=e.y(n?.value);if(!i)return`any`;let a=`
2
2
  ${e.r(r,`unknown`)}
3
3
  const tempValue = ${i??`any`};
4
4
  `,o=`index.ts`,s=e.t(o,a),c=s.getSourceFile(o),l=s.languageService.getProgram().getTypeChecker(),u=`any`,d=e=>{if(t.default.isVariableDeclaration(e)&&e.name.getText()===`tempValue`){let n=l.getTypeAtLocation(e),r=n=>{if(n.isUnion()){let e=n.types.map(r);return Array.from(new Set(e)).sort().join(` | `)}if(l.isArrayType(n)){let e=n.typeArguments||[],t=e.length>0?r(e[0]):`any`;return e[0]?.isUnion()?`(${t})[]`:`${t}[]`}if(n.getFlags()&t.default.TypeFlags.Object||n.isClassOrInterface()){let t=l.getPropertiesOfType(n);if(t.length>0)return`{ ${t.map(t=>{let n=l.getTypeOfSymbolAtLocation(t,e);return`${t.getName()}: ${r(n)}`}).join(`, `)} }`}let i=l.getBaseTypeOfLiteralType(n);return l.typeToString(i,e)};u=r(n)}t.default.forEachChild(e,d)};return d(c),u},r=(n,r)=>{let i=`
5
5
  ${e.r(r)}
6
6
  type Target = ${n};
7
7
  `,a=`index.ts`,o=e.t(a,i),s=o.getSourceFile(a),c=o.languageService.getProgram().getTypeChecker(),l=s.statements.find(e=>t.default.isTypeAliasDeclaration(e)&&e.name.text===`Target`);if(!l)return{__typename:`LiteralValue`,value:null};let u=c.getTypeAtLocation(l.type),d=(e,n,r=new Set)=>{let i=new Set(r);if(i.has(e))return null;let a=e.getFlags();if(e.isUnion()){if(n.type,t.default.isTypeAliasDeclaration(n)&&n.type&&t.default.isUnionTypeNode(n.type)){let e=c.getTypeFromTypeNode(n.type.types[0]);return d(e,n,i)}let r=e.types.filter(e=>{let n=e.getFlags();return!(n&t.default.TypeFlags.Undefined)&&!(n&t.default.TypeFlags.Null)}),a=r.length>0?r[0]:e.types[0];return d(a,n,i)}if(a&t.default.TypeFlags.StringLiteral)return e.value;if(a&t.default.TypeFlags.String)return``;if(a&t.default.TypeFlags.NumberLiteral)return e.value;if(a&t.default.TypeFlags.Number)return 0;if(a&t.default.TypeFlags.BooleanLiteral)return e.intrinsicName===`true`;if(a&t.default.TypeFlags.Boolean)return!1;if(c.isArrayType(e)){i.add(e);let t=e.typeArguments?.[0]||c.getAnyType(),r=d(t,n,i);return r===null?[]:[r]}if(e.isClassOrInterface()||a&t.default.TypeFlags.Object||e.getProperties().length>0){i.add(e);let t={};return e.getProperties().forEach(e=>{let r=c.getTypeOfSymbolAtLocation(e,n),a=e.valueDeclaration;r&&(t[e.getName()]=d(r,a||n,i))}),t}return null};return{__typename:`LiteralValue`,value:d(u,l)}},i=2345,a=2322,o=2339,s=(e,t,n)=>{if(e.getStart()>t||e.getEnd()<n)return;let r=e;return e.forEachChild(e=>{let i=s(e,t,n);i&&(r=i)}),r},c=(e,n,r)=>{if(e.start===void 0||e.length===void 0)return!1;let c=s(n,e.start,e.start+e.length);if(!c)return!1;if((e.code===i||e.code===a)&&t.default.isExpression(c)){let e=r.getTypeAtLocation(c);if(!e.isUnion())return!1;let n=r.getContextualType(c);return n?e.types.some(e=>(e.flags&(t.default.TypeFlags.Null|t.default.TypeFlags.Undefined))===0&&r.isTypeAssignableTo(e,n)):!1}if(e.code===o&&t.default.isPropertyAccessExpression(c.parent)){let e=r.getNonNullableType(r.getTypeAtLocation(c.parent.expression));if(!e.isUnion())return!1;let t=c.getText();return e.types.some(e=>e.getProperty(t)!==void 0)}return!1},l=(n,r,i)=>{if(!n?.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(!n.nodes?.nodes?.find(e=>e?.id==n.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 a=new Set(r?.map(e=>e.identifier)),o=(n.nodes?.nodes??[]).filter(e=>e?.functionDefinition&&!a.has(e.functionDefinition.identifier)).map(e=>({nodeId:e.id,parameterIndex:null,code:0,message:`The function definition "${e.functionDefinition.identifier}" is not reachable.`,severity:`error`}));if(o.length>0)return{isValid:!1,returnType:`void`,diagnostics:o};let s=e.n(n,r,i,!1,!1),l=`index.ts`,u=e.t(l,s),d=u.getSourceFile(l),f=u.languageService.getProgram(),p=f.getTypeChecker(),m=f.getSemanticDiagnostics(d).map(e=>{let n=(0,t.flattenDiagnosticMessageText)(e.messageText,`
8
- `),r,i=null;if(e.start!==void 0){let t=d.getFullText(),n=Math.max(0,e.start-300),a=Math.min(t.length,e.start),o=t.substring(n,a),s=/\/\* @pos ([^ ]+) (\d+|null) \*\//g,c,l=null,u=-1;for(;(c=s.exec(o))!==null;){let t=n+c.index+c[0].length;t<=e.start&&t>u&&(u=t,l=c)}l&&(r=l[1]===`null`?null:l[1],i=parseInt(l[2],10))}let a=c(e,d,p)?`warning`:`error`;return{message:n,code:e.code,severity:a,nodeId:r,parameterIndex:typeof i==`number`&&Number.isSafeInteger(i)?i:null}}).filter(e=>e!==null);return{isValid:!m.some(e=>e?.severity===`error`),returnType:`void`,diagnostics:m}},u=(n,r,i)=>{let a=e.p(r?.value),o=`
8
+ `),r,i=null;if(e.start!==void 0){let t=d.getFullText(),n=Math.max(0,e.start-300),a=Math.min(t.length,e.start),o=t.substring(n,a),s=/\/\* @pos ([^ ]+) (\d+|null) \*\//g,c,l=null,u=-1;for(;(c=s.exec(o))!==null;){let t=n+c.index+c[0].length;t<=e.start&&t>u&&(u=t,l=c)}l&&(r=l[1]===`null`?null:l[1],i=parseInt(l[2],10))}let a=c(e,d,p)?`warning`:`error`;return{message:n,code:e.code,severity:a,nodeId:r,parameterIndex:typeof i==`number`&&Number.isSafeInteger(i)?i:null}}).filter(e=>e!==null);return{isValid:!m.some(e=>e?.severity===`error`),returnType:`void`,diagnostics:m}},u=(n,r,i)=>{let a=e.y(r?.value),o=`
9
9
  ${e.r(i)}
10
10
  const testValue: ${n} = ${a};
11
11
  `,s=`index.ts`,c=e.t(s,o).languageService.getSemanticDiagnostics(s).map(e=>{let n=t.default.flattenDiagnosticMessageText(e.messageText,`
12
- `),r=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:e.code,severity:r?`warning`:`error`}});return{isValid:!c.some(e=>e.severity===`error`),returnType:`void`,diagnostics:c}},d=(n,r,i,a)=>{let o=e.n(n,i,r),s=`index.ts`,c=e.t(s,o),l=c.getSourceFile(s),u=c.languageService.getProgram().getTypeChecker(),d=n.nodes?.nodes?.find(e=>e?.id===a),y=a?`fn_${d?.functionDefinition?.identifier?.replace(/::/g,`_`)}`:`flow`,b=a?`node_${e.i(a)}`:`flow_${e.i(n.id)}`,x=p(l),S=m(l).get(b),C=x.get(y),w=h(u,S),T=g(u,C,S),E=w?.map((e,n)=>(e.flags&t.default.TypeFlags.Undefined)===0?e:T?.[n]??e),D=(d?.parameters?.nodes??[]).map(e=>e?.value!=null),O=v(u,S,E,T,_(C,w,D),a?x:new Map,a?i:[],D),k=f(u,S,C);return{nodeId:a,parameters:O,return:k?e.s(u,S,k,Array.from(x.values()),i,!1):{input:`generic`}}},f=(e,n,r)=>{if(n?.initializer&&t.default.isCallExpression(n.initializer)){let t=e.getResolvedSignature(n.initializer);if(t)return e.getReturnTypeOfSignature(t)}if(r){let t=e.getSignatureFromDeclaration(r);if(t)return e.getReturnTypeOfSignature(t)}},p=e=>new Map(e.statements.filter(t.default.isFunctionDeclaration).map(e=>[e.name.getText(),e])),m=e=>{let n=[];return e.statements.forEach(e=>{e.forEachChild(function e(r){t.default.isVariableDeclaration(r)&&(r.parent.flags&t.default.NodeFlags.Const)!==0&&n.push([r.name.getText(),r]),r.forEachChild(e)})}),new Map(n)},h=(e,n)=>{if(n?.initializer&&t.default.isCallExpression(n.initializer))return e.getResolvedSignature(n.initializer)?.parameters.map(t=>e.getTypeOfSymbolAtLocation(t,n.initializer))},g=(e,t,n)=>{if(t&&n?.initializer)return t.parameters.map(t=>{let r=e.getSymbolAtLocation(t.name);return e.getTypeOfSymbolAtLocation(r,n.initializer)})},_=(e,n,r=[])=>{let i=e.typeParameters?.map(e=>e.name.getText())||[],a={};e.parameters.forEach((e,n)=>{if(!e.type)return;let r=new Set;e.type.forEachChild(function n(a){if(t.default.isTypeReferenceNode(a)&&t.default.isIdentifier(a.typeName)){let e=a.typeName.text;i.includes(e)&&r.add(e)}if(t.default.isTypeReferenceNode(e.type)&&t.default.isIdentifier(e.type.typeName)){let t=e.type.typeName.text;i.includes(t)&&r.add(t)}a.forEachChild(n)}),r.forEach(e=>{a[e]||(a[e]=[]),a[e].push(n)})});let o=Object.values(a).filter(e=>e.length>1).map(([e,...t])=>t.map(t=>({parameterIndex:t,dependsOnIndex:e}))).flat();return n?o.filter(e=>{if(r[e.dependsOnIndex])return!1;let i=n[e.parameterIndex];if(!i)return!0;let a=(i.flags&t.default.TypeFlags.Null)!==0,o=(i.flags&t.default.TypeFlags.Undefined)!==0;return a||o}):o},v=(n,r,i,a,o,s,c,l)=>{if(!i)return[];let u=e.s(n,r,n.getAnyType(),Array.from(s.values()),c,!0).suggestions;return i.map((i,d)=>{let f=a?.[d],p=f?T(n,f,r):void 0,m=Array.from(s.values()),h=f?e.s(n,r,f,m,c,!1):void 0,g=(i.flags&t.default.TypeFlags.Object)!==0&&!n.isArrayType(i)&&!n.isTupleType(i),_=y(r,d);if(_&&(t.default.isArrayLiteralExpression(_)||t.default.isObjectLiteralExpression(_)&&g)){let a=e.s(n,r,i,m,c,!0,p).suggestions;return{schema:t.default.isArrayLiteralExpression(_)?x(n,r,f,_,m,c,a,u):C(n,r,f,_,m,c,a,u),blockedBy:o.filter(e=>e.parameterIndex===d).map(e=>e.dependsOnIndex)}}let v=e.f(e.s(n,r,i,m,c,!0,p));return{schema:e.d(h,v,l[d]??!1,u),blockedBy:o.filter(e=>e.parameterIndex===d).map(e=>e.dependsOnIndex)}})},y=(e,n)=>{if(e.initializer&&t.default.isCallExpression(e.initializer))return e.initializer.arguments[n]},b=new Set([`select`,`boolean`,`number`,`text`]),x=(t,n,r,i,a,o,s,c)=>{let l=r?e.s(t,n,r,a,o,!1):void 0,u=l!=null&&l.input?.startsWith(`list`)===!0,d=r&&t.isArrayType(r)?t.getTypeArguments(r)[0]:void 0,f=i.elements.map(e=>S(t,n,d,e,a,o,c));return{input:u?l.input:`list`,type:(u?l.type:void 0)??t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),items:f,...s?.length?{suggestions:s}:{}}},S=(n,r,i,a,o,s,c)=>{if(t.default.isArrayLiteralExpression(a))return x(n,r,i,a,o,s,void 0,c);if(t.default.isObjectLiteralExpression(a))return C(n,r,i,a,o,s,void 0,c);let l=i?e.s(n,r,i,o,s,!0):void 0,u=!l||l.input===`generic`,d=n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a));return u?e.o(e.s(n,r,d,o,s,!0),c):b.has(l.input)?{...l,type:n.typeToString(d)}:l},C=(n,r,i,a,o,s,c,l)=>{let u=i?e.s(n,r,i,o,s,!1):void 0,d=u?.input===`data`;if(u&&!d&&u.input!==`generic`)return{...u,type:n.typeToString(n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a))),...c?.length?{suggestions:c}:{}};let f={},p=[];for(let e of a.properties){if(!t.default.isPropertyAssignment(e))continue;let a=t.default.isStringLiteralLike(e.name)||t.default.isNumericLiteral(e.name)?e.name.text:e.name.getText();f[a]=S(n,r,d?w(n,i,a):void 0,e.initializer,o,s,l),p.push(a)}return{input:`data`,type:(d?u.type:void 0)??n.typeToString(n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a))),properties:f,required:p,...c?.length?{suggestions:c}:{}}},w=(e,t,n)=>{let r=e.getPropertyOfType(t,n);if(!r)return;let i=r.valueDeclaration??r.declarations?.[0];return i?e.getTypeOfSymbolAtLocation(r,i):void 0},T=(e,n,r)=>{if((n.flags&t.default.TypeFlags.TypeParameter)!==0){let r=n.symbol?.declarations?.[0];return r&&t.default.isTypeParameterDeclaration(r)&&r.constraint?e.getTypeFromTypeNode(r.constraint):e.getAnyType()}if((n.flags&t.default.TypeFlags.Conditional)!==0)return e.getBaseConstraintOfType(n)??e.getAnyType();if((n.flags&t.default.TypeFlags.Object)!==0&&E(n,e,new Set)){let i=n.aliasSymbol?.getName();if(i){let n=e.getSymbolsInScope(r,t.default.SymbolFlags.Variable).find(e=>e.getName()===`__widen_${i}`);if(n)return e.getTypeOfSymbolAtLocation(n,r)}return e.getAnyType()}return n},E=(e,n,r)=>!r.has(e)&&(r.add(e),!!((e.flags&t.default.TypeFlags.TypeParameter)!==0||(e.flags&t.default.TypeFlags.Object)!==0&&(n.getTypeArguments(e).some(e=>E(e,n,r))||e.aliasTypeArguments?.some(e=>E(e,n,r))))),D=(n,r=[])=>{let i=`index.ts`,a=`${e.r(r)}\ntype MyType = ${n}`,o=e.t(i,a).languageService.getProgram(),s=o?.getSourceFile(i),c=o?.getTypeChecker();if(!s||!c)return;let l=s.statements.filter(e=>t.default.isTypeAliasDeclaration(e)||t.default.isInterfaceDeclaration(e)||t.default.isClassDeclaration(e)).pop();if(!l)return;let u=c.getTypeAtLocation(l);if(u)return e.s(c,void 0,u,[],[],!1)};exports.CUSTOM_INPUT_IDENTIFIERS=e.a,exports.genericNodeSchema=e.o,exports.getFlowValidation=l,exports.getSchema=e.s,exports.getSignatureSchema=d,exports.getTypeFromValue=n,exports.getTypeSchema=D,exports.getValueFromType=r,exports.getValueValidation=u,exports.isCustomInputIdentifier=e.c,exports.isCustomInputKind=e.l,exports.isSubFlow=e.u,exports.mergeSchemas=e.d,exports.normalizeNodeSchema=e.f;
12
+ `),r=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:e.code,severity:r?`warning`:`error`}});return{isValid:!c.some(e=>e.severity===`error`),returnType:`void`,diagnostics:c}},d=(n,r,i,a)=>{let o=e.n(n,i,r),s=`index.ts`,c=e.t(s,o),l=c.getSourceFile(s),u=c.languageService.getProgram().getTypeChecker(),d=n.nodes?.nodes?.find(e=>e?.id===a),y=a?`fn_${d?.functionDefinition?.identifier?.replace(/::/g,`_`)}`:`flow`,b=a?`node_${e.i(a)}`:`flow_${e.i(n.id)}`,x=p(l),S=m(l).get(b),C=x.get(y),w=h(u,S),T=g(u,C,S),E=w?.map((e,n)=>(e.flags&t.default.TypeFlags.Undefined)===0?e:T?.[n]??e),D=(d?.parameters?.nodes??[]).map(e=>e?.value!=null),O=v(u,S,E,T,_(C,w,D),a?x:new Map,a?i:[],D),k=f(u,S,C);return{nodeId:a,parameters:O,return:k?e.l(u,S,k,Array.from(x.values()),i,!1):{input:`generic`}}},f=(e,n,r)=>{if(n?.initializer&&t.default.isCallExpression(n.initializer)){let t=e.getResolvedSignature(n.initializer);if(t)return e.getReturnTypeOfSignature(t)}if(r){let t=e.getSignatureFromDeclaration(r);if(t)return e.getReturnTypeOfSignature(t)}},p=e=>new Map(e.statements.filter(t.default.isFunctionDeclaration).map(e=>[e.name.getText(),e])),m=e=>{let n=[];return e.statements.forEach(e=>{e.forEachChild(function e(r){t.default.isVariableDeclaration(r)&&(r.parent.flags&t.default.NodeFlags.Const)!==0&&n.push([r.name.getText(),r]),r.forEachChild(e)})}),new Map(n)},h=(e,n)=>{if(n?.initializer&&t.default.isCallExpression(n.initializer))return e.getResolvedSignature(n.initializer)?.parameters.map(t=>e.getTypeOfSymbolAtLocation(t,n.initializer))},g=(e,t,n)=>{if(t&&n?.initializer)return t.parameters.map(t=>{let r=e.getSymbolAtLocation(t.name);return e.getTypeOfSymbolAtLocation(r,n.initializer)})},_=(e,n,r=[])=>{let i=e.typeParameters?.map(e=>e.name.getText())||[],a={};e.parameters.forEach((e,n)=>{if(!e.type)return;let r=new Set;e.type.forEachChild(function n(a){if(t.default.isTypeReferenceNode(a)&&t.default.isIdentifier(a.typeName)){let e=a.typeName.text;i.includes(e)&&r.add(e)}if(t.default.isTypeReferenceNode(e.type)&&t.default.isIdentifier(e.type.typeName)){let t=e.type.typeName.text;i.includes(t)&&r.add(t)}a.forEachChild(n)}),r.forEach(e=>{a[e]||(a[e]=[]),a[e].push(n)})});let o=Object.values(a).filter(e=>e.length>1).map(([e,...t])=>t.map(t=>({parameterIndex:t,dependsOnIndex:e}))).flat();return n?o.filter(e=>{if(r[e.dependsOnIndex])return!1;let i=n[e.parameterIndex];if(!i)return!0;let a=(i.flags&t.default.TypeFlags.Null)!==0,o=(i.flags&t.default.TypeFlags.Undefined)!==0;return a||o}):o},v=(n,r,i,a,o,s,c,l)=>{if(!i)return[];let u=e.v(e.l(n,r,n.getAnyType(),Array.from(s.values()),c,!0));return i.map((i,d)=>{let f=a?.[d],p=f?M(n,f,r):void 0,m=Array.from(s.values()),h=f?e.l(n,r,f,m,c,!0):void 0,g=C(n,e.h(i)),_=y(r,d),v=_?T(n,f,_):void 0,b=v??f;if(_&&(t.default.isArrayLiteralExpression(_)||t.default.isObjectLiteralExpression(_)&&(g||v!=null&&C(n,v)))){let a=e.v(e.l(n,r,i,m,c,!0,p));return{schema:t.default.isArrayLiteralExpression(_)?E(n,r,b,_,m,c,a,u):k(n,r,b,_,m,c,a,u),blockedBy:o.filter(e=>e.parameterIndex===d).map(e=>e.dependsOnIndex)}}let x=e.g(e.l(n,r,i,m,c,!0,p));return{schema:e.m(h,x,l[d]??!1,u),blockedBy:o.filter(e=>e.parameterIndex===d).map(e=>e.dependsOnIndex)}})},y=(e,n)=>{if(e.initializer&&t.default.isCallExpression(e.initializer))return e.initializer.arguments[n]},b=new Set([`select`,`boolean`,`number`,`text`]),x=t.default.TypeFlags.Null|t.default.TypeFlags.Undefined|t.default.TypeFlags.Void|t.default.TypeFlags.Never,S=e=>(e.flags&x)!==0,C=(e,n)=>(n.flags&t.default.TypeFlags.Object)!==0&&!e.isArrayType(n)&&!e.isTupleType(n),w=e=>e.properties.filter(t.default.isPropertyAssignment).map(e=>A(e)),T=(n,r,i)=>{if(!r)return;let a=e.h(r);if(!a.isUnion()||e.f(a))return;let o=a.types.filter(e=>(e.flags&(t.default.TypeFlags.Undefined|t.default.TypeFlags.Null))===0);if(o.length<2)return;let s=n.getTypeAtLocation(i);if((s.flags&(t.default.TypeFlags.Any|t.default.TypeFlags.Unknown))===0){let e=o.find(e=>n.isTypeAssignableTo(s,e));if(e)return e}if(t.default.isObjectLiteralExpression(i)){let e=w(i),t,r=0;for(let i of o){let a=e.filter(e=>n.getPropertyOfType(i,e)!=null).length;a>r&&(t=i,r=a)}return t}if(t.default.isArrayLiteralExpression(i))return o.find(e=>n.isArrayType(e)||n.isTupleType(e))},E=(t,n,r,i,a,o,s,c)=>{let l=r?e.l(t,n,r,a,o,!0):void 0,u=l!=null&&l.input?.startsWith(`list`)===!0,d=r?e.h(r):void 0,f=d&&t.isArrayType(d)?t.getTypeArguments(d)[0]:void 0,p=i.elements.map(e=>O(t,n,f,e,a,o,c));return e._({input:u?l.input:`list`,type:(u?l.type:void 0)??t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),items:p,declaredItems:e.o(u?l.items:void 0,c)},s??D(l,c))},D=(t,n)=>!t||t.input===`generic`?n:e.v(t),O=(n,r,i,a,o,s,c)=>{let l=T(n,i,a)??i;if(t.default.isArrayLiteralExpression(a))return E(n,r,l,a,o,s,void 0,c);if(t.default.isObjectLiteralExpression(a))return k(n,r,l,a,o,s,void 0,c);let u=l?e.l(n,r,l,o,s,!0):void 0,d=!u||u.input===`generic`,f=n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a));return d?e.c(e.l(n,r,f,o,s,!0),c):b.has(u.input)?e._({...u,...S(f)?{}:{type:n.typeToString(f)}},e.v(u)):e.s(u,c)},k=(n,r,i,a,o,s,c,l)=>{let u=i?e.l(n,r,i,o,s,!0):void 0,d=u?.input===`data`;if(u&&!d&&u.input!==`generic`)return e._({...u,type:n.typeToString(n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a)))},c??e.v(u));let f=d?u.properties??{}:{},p={};for(let[t,n]of Object.entries(f))p[t]=Array.isArray(n)?n.map(t=>e.s(t,l)):e.s(n,l);let m=[];for(let c of a.properties){if(!t.default.isPropertyAssignment(c))continue;let a=A(c);p[a]=O(n,r,d?j(n,e.h(i),a):void 0,c.initializer,o,s,l),m.push(a)}let h=d?u.required??[]:m;return e._({input:`data`,type:(d?u.type:void 0)??n.typeToString(n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a))),properties:p,required:h},c??D(u,l))},A=e=>t.default.isStringLiteralLike(e.name)||t.default.isNumericLiteral(e.name)?e.name.text:e.name.getText(),j=(e,t,n)=>{let r=e.getPropertyOfType(t,n);if(!r)return;let i=r.valueDeclaration??r.declarations?.[0];return i?e.getTypeOfSymbolAtLocation(r,i):void 0},M=(e,n,r)=>{if((n.flags&t.default.TypeFlags.TypeParameter)!==0){let r=n.symbol?.declarations?.[0];return r&&t.default.isTypeParameterDeclaration(r)&&r.constraint?e.getTypeFromTypeNode(r.constraint):e.getAnyType()}if((n.flags&t.default.TypeFlags.Conditional)!==0)return e.getBaseConstraintOfType(n)??e.getAnyType();if((n.flags&t.default.TypeFlags.Object)!==0&&N(n,e,new Set)){let i=n.aliasSymbol?.getName();if(i){let n=e.getSymbolsInScope(r,t.default.SymbolFlags.Variable).find(e=>e.getName()===`__widen_${i}`);if(n)return e.getTypeOfSymbolAtLocation(n,r)}return e.getAnyType()}return n},N=(e,n,r)=>!r.has(e)&&(r.add(e),!!((e.flags&t.default.TypeFlags.TypeParameter)!==0||(e.flags&t.default.TypeFlags.Object)!==0&&(n.getTypeArguments(e).some(e=>N(e,n,r))||e.aliasTypeArguments?.some(e=>N(e,n,r))))),P=(n,r=[])=>{let i=`index.ts`,a=`${e.r(r)}\ntype MyType = ${n}`,o=e.t(i,a).languageService.getProgram(),s=o?.getSourceFile(i),c=o?.getTypeChecker();if(!s||!c)return;let l=s.statements.filter(e=>t.default.isTypeAliasDeclaration(e)||t.default.isInterfaceDeclaration(e)||t.default.isClassDeclaration(e)).pop();if(!l)return;let u=c.getTypeAtLocation(l);if(u)return e.l(c,void 0,u,[],[],!1)};exports.CUSTOM_INPUT_IDENTIFIERS=e.a,exports.declaredItemsOf=e.o,exports.declaredSchema=e.s,exports.genericNodeSchema=e.c,exports.getFlowValidation=l,exports.getSchema=e.l,exports.getSignatureSchema=d,exports.getTypeFromValue=n,exports.getTypeSchema=P,exports.getValueFromType=r,exports.getValueValidation=u,exports.isCustomInputIdentifier=e.u,exports.isCustomInputKind=e.d,exports.isOptionsUnion=e.f,exports.isSubFlow=e.p,exports.mergeSchemas=e.m,exports.nonNullishType=e.h,exports.normalizeNodeSchema=e.g,exports.withSuggestions=e._;
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./utils-CAOAm6k-.js";
2
- import p, { flattenDiagnosticMessageText as m } from "typescript";
1
+ import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _, y as v } from "./utils-A--QqsC6.js";
2
+ import y, { flattenDiagnosticMessageText as b } from "typescript";
3
3
  //#region src/extraction/getTypeFromValue.ts
4
- var h = (e, t) => {
5
- let n = c(e?.value);
4
+ var x = (e, t) => {
5
+ let n = v(e?.value);
6
6
  if (!n) return "any";
7
7
  let r = `
8
- ${l(t, "unknown")}
8
+ ${p(t, "unknown")}
9
9
  const tempValue = ${n ?? "any"};
10
- `, i = "index.ts", a = d(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), u = "any", f = (e) => {
11
- if (p.isVariableDeclaration(e) && e.name.getText() === "tempValue") {
10
+ `, i = "index.ts", a = h(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), c = "any", l = (e) => {
11
+ if (y.isVariableDeclaration(e) && e.name.getText() === "tempValue") {
12
12
  let t = s.getTypeAtLocation(e), n = (t) => {
13
13
  if (t.isUnion()) {
14
14
  let e = t.types.map(n);
@@ -18,7 +18,7 @@ var h = (e, t) => {
18
18
  let e = t.typeArguments || [], r = e.length > 0 ? n(e[0]) : "any";
19
19
  return e[0]?.isUnion() ? `(${r})[]` : `${r}[]`;
20
20
  }
21
- if (t.getFlags() & p.TypeFlags.Object || t.isClassOrInterface()) {
21
+ if (t.getFlags() & y.TypeFlags.Object || t.isClassOrInterface()) {
22
22
  let r = s.getPropertiesOfType(t);
23
23
  if (r.length > 0) return `{ ${r.map((t) => {
24
24
  let r = s.getTypeOfSymbolAtLocation(t, e);
@@ -28,85 +28,85 @@ var h = (e, t) => {
28
28
  let r = s.getBaseTypeOfLiteralType(t);
29
29
  return s.typeToString(r, e);
30
30
  };
31
- u = n(t);
31
+ c = n(t);
32
32
  }
33
- p.forEachChild(e, f);
33
+ y.forEachChild(e, l);
34
34
  };
35
- return f(o), u;
36
- }, g = (e, t) => {
35
+ return l(o), c;
36
+ }, S = (e, t) => {
37
37
  let n = `
38
- ${l(t)}
38
+ ${p(t)}
39
39
  type Target = ${e};
40
- `, r = "index.ts", i = d(r, n), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = a.statements.find((e) => p.isTypeAliasDeclaration(e) && e.name.text === "Target");
40
+ `, r = "index.ts", i = h(r, n), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = a.statements.find((e) => y.isTypeAliasDeclaration(e) && e.name.text === "Target");
41
41
  if (!s) return {
42
42
  __typename: "LiteralValue",
43
43
  value: null
44
44
  };
45
- let c = o.getTypeAtLocation(s.type), u = (e, t, n = /* @__PURE__ */ new Set()) => {
45
+ let c = o.getTypeAtLocation(s.type), l = (e, t, n = /* @__PURE__ */ new Set()) => {
46
46
  let r = new Set(n);
47
47
  if (r.has(e)) return null;
48
48
  let i = e.getFlags();
49
49
  if (e.isUnion()) {
50
- if (t.type, p.isTypeAliasDeclaration(t) && t.type && p.isUnionTypeNode(t.type)) {
50
+ if (t.type, y.isTypeAliasDeclaration(t) && t.type && y.isUnionTypeNode(t.type)) {
51
51
  let e = o.getTypeFromTypeNode(t.type.types[0]);
52
- return u(e, t, r);
52
+ return l(e, t, r);
53
53
  }
54
54
  let n = e.types.filter((e) => {
55
55
  let t = e.getFlags();
56
- return !(t & p.TypeFlags.Undefined) && !(t & p.TypeFlags.Null);
56
+ return !(t & y.TypeFlags.Undefined) && !(t & y.TypeFlags.Null);
57
57
  }), i = n.length > 0 ? n[0] : e.types[0];
58
- return u(i, t, r);
58
+ return l(i, t, r);
59
59
  }
60
- if (i & p.TypeFlags.StringLiteral) return e.value;
61
- if (i & p.TypeFlags.String) return "";
62
- if (i & p.TypeFlags.NumberLiteral) return e.value;
63
- if (i & p.TypeFlags.Number) return 0;
64
- if (i & p.TypeFlags.BooleanLiteral) return e.intrinsicName === "true";
65
- if (i & p.TypeFlags.Boolean) return !1;
60
+ if (i & y.TypeFlags.StringLiteral) return e.value;
61
+ if (i & y.TypeFlags.String) return "";
62
+ if (i & y.TypeFlags.NumberLiteral) return e.value;
63
+ if (i & y.TypeFlags.Number) return 0;
64
+ if (i & y.TypeFlags.BooleanLiteral) return e.intrinsicName === "true";
65
+ if (i & y.TypeFlags.Boolean) return !1;
66
66
  if (o.isArrayType(e)) {
67
67
  r.add(e);
68
- let n = e.typeArguments?.[0] || o.getAnyType(), i = u(n, t, r);
68
+ let n = e.typeArguments?.[0] || o.getAnyType(), i = l(n, t, r);
69
69
  return i === null ? [] : [i];
70
70
  }
71
- if (e.isClassOrInterface() || i & p.TypeFlags.Object || e.getProperties().length > 0) {
71
+ if (e.isClassOrInterface() || i & y.TypeFlags.Object || e.getProperties().length > 0) {
72
72
  r.add(e);
73
73
  let n = {};
74
74
  return e.getProperties().forEach((e) => {
75
75
  let i = o.getTypeOfSymbolAtLocation(e, t), a = e.valueDeclaration;
76
- i && (n[e.getName()] = u(i, a || t, r));
76
+ i && (n[e.getName()] = l(i, a || t, r));
77
77
  }), n;
78
78
  }
79
79
  return null;
80
80
  };
81
81
  return {
82
82
  __typename: "LiteralValue",
83
- value: u(c, s)
83
+ value: l(c, s)
84
84
  };
85
- }, _ = 2345, v = 2322, y = 2339, b = (e, t, n) => {
85
+ }, C = 2345, w = 2322, T = 2339, E = (e, t, n) => {
86
86
  if (e.getStart() > t || e.getEnd() < n) return;
87
87
  let r = e;
88
88
  return e.forEachChild((e) => {
89
- let i = b(e, t, n);
89
+ let i = E(e, t, n);
90
90
  i && (r = i);
91
91
  }), r;
92
- }, x = (e, t, n) => {
92
+ }, D = (e, t, n) => {
93
93
  if (e.start === void 0 || e.length === void 0) return !1;
94
- let r = b(t, e.start, e.start + e.length);
94
+ let r = E(t, e.start, e.start + e.length);
95
95
  if (!r) return !1;
96
- if ((e.code === _ || e.code === v) && p.isExpression(r)) {
96
+ if ((e.code === C || e.code === w) && y.isExpression(r)) {
97
97
  let e = n.getTypeAtLocation(r);
98
98
  if (!e.isUnion()) return !1;
99
99
  let t = n.getContextualType(r);
100
- return t ? e.types.some((e) => (e.flags & (p.TypeFlags.Null | p.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
100
+ return t ? e.types.some((e) => (e.flags & (y.TypeFlags.Null | y.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
101
101
  }
102
- if (e.code === y && p.isPropertyAccessExpression(r.parent)) {
102
+ if (e.code === T && y.isPropertyAccessExpression(r.parent)) {
103
103
  let e = n.getNonNullableType(n.getTypeAtLocation(r.parent.expression));
104
104
  if (!e.isUnion()) return !1;
105
105
  let t = r.getText();
106
106
  return e.types.some((e) => e.getProperty(t) !== void 0);
107
107
  }
108
108
  return !1;
109
- }, S = (e, t, n) => {
109
+ }, O = (e, t, n) => {
110
110
  if (!e?.startingNodeId) return {
111
111
  isValid: !1,
112
112
  returnType: "void",
@@ -141,17 +141,17 @@ var h = (e, t) => {
141
141
  returnType: "void",
142
142
  diagnostics: i
143
143
  };
144
- let a = o(e, t, n, !1, !1), s = "index.ts", c = d(s, a), l = c.getSourceFile(s), u = c.languageService.getProgram(), f = u.getTypeChecker(), p = u.getSemanticDiagnostics(l).map((e) => {
145
- let t = m(e.messageText, "\n"), n, r = null;
144
+ let a = u(e, t, n, !1, !1), o = "index.ts", s = h(o, a), c = s.getSourceFile(o), l = s.languageService.getProgram(), d = l.getTypeChecker(), f = l.getSemanticDiagnostics(c).map((e) => {
145
+ let t = b(e.messageText, "\n"), n, r = null;
146
146
  if (e.start !== void 0) {
147
- let t = l.getFullText(), i = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(i, a), s = /\/\* @pos ([^ ]+) (\d+|null) \*\//g, c, u = null, d = -1;
148
- for (; (c = s.exec(o)) !== null;) {
149
- let t = i + c.index + c[0].length;
150
- t <= e.start && t > d && (d = t, u = c);
147
+ let t = c.getFullText(), i = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(i, a), s = /\/\* @pos ([^ ]+) (\d+|null) \*\//g, l, u = null, d = -1;
148
+ for (; (l = s.exec(o)) !== null;) {
149
+ let t = i + l.index + l[0].length;
150
+ t <= e.start && t > d && (d = t, u = l);
151
151
  }
152
152
  u && (n = u[1] === "null" ? null : u[1], r = parseInt(u[2], 10));
153
153
  }
154
- let i = x(e, l, f) ? "warning" : "error";
154
+ let i = D(e, c, d) ? "warning" : "error";
155
155
  return {
156
156
  message: t,
157
157
  code: e.code,
@@ -161,16 +161,16 @@ var h = (e, t) => {
161
161
  };
162
162
  }).filter((e) => e !== null);
163
163
  return {
164
- isValid: !p.some((e) => e?.severity === "error"),
164
+ isValid: !f.some((e) => e?.severity === "error"),
165
165
  returnType: "void",
166
- diagnostics: p
166
+ diagnostics: f
167
167
  };
168
- }, C = (e, t, n) => {
169
- let r = c(t?.value), i = `
170
- ${l(n)}
168
+ }, k = (e, t, n) => {
169
+ let r = v(t?.value), i = `
170
+ ${p(n)}
171
171
  const testValue: ${e} = ${r};
172
- `, a = "index.ts", o = d(a, i).languageService.getSemanticDiagnostics(a).map((e) => {
173
- let t = p.flattenDiagnosticMessageText(e.messageText, "\n"), 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");
172
+ `, a = "index.ts", o = h(a, i).languageService.getSemanticDiagnostics(a).map((e) => {
173
+ let t = y.flattenDiagnosticMessageText(e.messageText, "\n"), 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");
174
174
  return {
175
175
  message: t,
176
176
  code: e.code,
@@ -182,15 +182,15 @@ var h = (e, t) => {
182
182
  returnType: "void",
183
183
  diagnostics: o
184
184
  };
185
- }, w = (e, t, n, r) => {
186
- let a = o(e, n, t), s = "index.ts", c = d(s, a), l = c.getSourceFile(s), f = c.languageService.getProgram().getTypeChecker(), m = e.nodes?.nodes?.find((e) => e?.id === r), h = r ? `fn_${m?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", g = r ? `node_${i(r)}` : `flow_${i(e.id)}`, _ = E(l), v = D(l).get(g), y = _.get(h), b = O(f, v), x = k(f, y, v), S = b?.map((e, t) => (e.flags & p.TypeFlags.Undefined) === 0 ? e : x?.[t] ?? e), C = (m?.parameters?.nodes ?? []).map((e) => e?.value != null), w = j(f, v, S, x, A(y, b, C), r ? _ : /* @__PURE__ */ new Map(), r ? n : [], C), M = T(f, v, y);
185
+ }, A = (e, t, n, r) => {
186
+ let i = u(e, n, t), a = "index.ts", o = h(a, i), l = o.getSourceFile(a), d = o.languageService.getProgram().getTypeChecker(), f = e.nodes?.nodes?.find((e) => e?.id === r), p = r ? `fn_${f?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", m = r ? `node_${s(r)}` : `flow_${s(e.id)}`, g = M(l), _ = N(l).get(m), v = g.get(p), b = P(d, _), x = F(d, v, _), S = b?.map((e, t) => (e.flags & y.TypeFlags.Undefined) === 0 ? e : x?.[t] ?? e), C = (f?.parameters?.nodes ?? []).map((e) => e?.value != null), w = L(d, _, S, x, I(v, b, C), r ? g : /* @__PURE__ */ new Map(), r ? n : [], C), T = j(d, _, v);
187
187
  return {
188
188
  nodeId: r,
189
189
  parameters: w,
190
- return: M ? u(f, v, M, Array.from(_.values()), n, !1) : { input: "generic" }
190
+ return: T ? c(d, _, T, Array.from(g.values()), n, !1) : { input: "generic" }
191
191
  };
192
- }, T = (e, t, n) => {
193
- if (t?.initializer && p.isCallExpression(t.initializer)) {
192
+ }, j = (e, t, n) => {
193
+ if (t?.initializer && y.isCallExpression(t.initializer)) {
194
194
  let n = e.getResolvedSignature(t.initializer);
195
195
  if (n) return e.getReturnTypeOfSignature(n);
196
196
  }
@@ -198,31 +198,31 @@ var h = (e, t) => {
198
198
  let t = e.getSignatureFromDeclaration(n);
199
199
  if (t) return e.getReturnTypeOfSignature(t);
200
200
  }
201
- }, E = (e) => new Map(e.statements.filter(p.isFunctionDeclaration).map((e) => [e.name.getText(), e])), D = (e) => {
201
+ }, M = (e) => new Map(e.statements.filter(y.isFunctionDeclaration).map((e) => [e.name.getText(), e])), N = (e) => {
202
202
  let t = [];
203
203
  return e.statements.forEach((e) => {
204
204
  e.forEachChild(function e(n) {
205
- p.isVariableDeclaration(n) && (n.parent.flags & p.NodeFlags.Const) !== 0 && t.push([n.name.getText(), n]), n.forEachChild(e);
205
+ y.isVariableDeclaration(n) && (n.parent.flags & y.NodeFlags.Const) !== 0 && t.push([n.name.getText(), n]), n.forEachChild(e);
206
206
  });
207
207
  }), new Map(t);
208
- }, O = (e, t) => {
209
- if (t?.initializer && p.isCallExpression(t.initializer)) return e.getResolvedSignature(t.initializer)?.parameters.map((n) => e.getTypeOfSymbolAtLocation(n, t.initializer));
210
- }, k = (e, t, n) => {
208
+ }, P = (e, t) => {
209
+ if (t?.initializer && y.isCallExpression(t.initializer)) return e.getResolvedSignature(t.initializer)?.parameters.map((n) => e.getTypeOfSymbolAtLocation(n, t.initializer));
210
+ }, F = (e, t, n) => {
211
211
  if (t && n?.initializer) return t.parameters.map((t) => {
212
212
  let r = e.getSymbolAtLocation(t.name);
213
213
  return e.getTypeOfSymbolAtLocation(r, n.initializer);
214
214
  });
215
- }, A = (e, t, n = []) => {
215
+ }, I = (e, t, n = []) => {
216
216
  let r = e.typeParameters?.map((e) => e.name.getText()) || [], i = {};
217
217
  e.parameters.forEach((e, t) => {
218
218
  if (!e.type) return;
219
219
  let n = /* @__PURE__ */ new Set();
220
220
  e.type.forEachChild(function t(i) {
221
- if (p.isTypeReferenceNode(i) && p.isIdentifier(i.typeName)) {
221
+ if (y.isTypeReferenceNode(i) && y.isIdentifier(i.typeName)) {
222
222
  let e = i.typeName.text;
223
223
  r.includes(e) && n.add(e);
224
224
  }
225
- if (p.isTypeReferenceNode(e.type) && p.isIdentifier(e.type.typeName)) {
225
+ if (y.isTypeReferenceNode(e.type) && y.isIdentifier(e.type.typeName)) {
226
226
  let t = e.type.typeName.text;
227
227
  r.includes(t) && n.add(t);
228
228
  }
@@ -239,97 +239,119 @@ var h = (e, t) => {
239
239
  if (n[e.dependsOnIndex]) return !1;
240
240
  let r = t[e.parameterIndex];
241
241
  if (!r) return !0;
242
- let i = (r.flags & p.TypeFlags.Null) !== 0, a = (r.flags & p.TypeFlags.Undefined) !== 0;
242
+ let i = (r.flags & y.TypeFlags.Null) !== 0, a = (r.flags & y.TypeFlags.Undefined) !== 0;
243
243
  return i || a;
244
244
  }) : a;
245
- }, j = (e, t, i, a, o, s, c, l) => {
246
- if (!i) return [];
247
- let d = u(e, t, e.getAnyType(), Array.from(s.values()), c, !0).suggestions;
248
- return i.map((i, f) => {
249
- let m = a?.[f], h = m ? R(e, m, t) : void 0, g = Array.from(s.values()), _ = m ? u(e, t, m, g, c, !1) : void 0, v = (i.flags & p.TypeFlags.Object) !== 0 && !e.isArrayType(i) && !e.isTupleType(i), y = M(t, f);
250
- if (y && (p.isArrayLiteralExpression(y) || p.isObjectLiteralExpression(y) && v)) {
251
- let n = u(e, t, i, g, c, !0, h).suggestions;
245
+ }, L = (e, t, n, r, i, s, u, d) => {
246
+ if (!n) return [];
247
+ let f = _(c(e, t, e.getAnyType(), Array.from(s.values()), u, !0));
248
+ return n.map((n, p) => {
249
+ let m = r?.[p], h = m ? Z(e, m, t) : void 0, g = Array.from(s.values()), v = m ? c(e, t, m, g, u, !0) : void 0, b = H(e, o(n)), x = R(t, p), S = x ? W(e, m, x) : void 0, C = S ?? m;
250
+ if (x && (y.isArrayLiteralExpression(x) || y.isObjectLiteralExpression(x) && (b || S != null && H(e, S)))) {
251
+ let r = _(c(e, t, n, g, u, !0, h));
252
252
  return {
253
- schema: p.isArrayLiteralExpression(y) ? P(e, t, m, y, g, c, n, d) : I(e, t, m, y, g, c, n, d),
254
- blockedBy: o.filter((e) => e.parameterIndex === f).map((e) => e.dependsOnIndex)
253
+ schema: y.isArrayLiteralExpression(x) ? G(e, t, C, x, g, u, r, f) : J(e, t, C, x, g, u, r, f),
254
+ blockedBy: i.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
255
255
  };
256
256
  }
257
- let b = r(u(e, t, i, g, c, !0, h));
257
+ let w = a(c(e, t, n, g, u, !0, h));
258
258
  return {
259
- schema: n(_, b, l[f] ?? !1, d),
260
- blockedBy: o.filter((e) => e.parameterIndex === f).map((e) => e.dependsOnIndex)
259
+ schema: l(v, w, d[p] ?? !1, f),
260
+ blockedBy: i.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
261
261
  };
262
262
  });
263
- }, M = (e, t) => {
264
- if (e.initializer && p.isCallExpression(e.initializer)) return e.initializer.arguments[t];
265
- }, N = /* @__PURE__ */ new Set([
263
+ }, R = (e, t) => {
264
+ if (e.initializer && y.isCallExpression(e.initializer)) return e.initializer.arguments[t];
265
+ }, z = /* @__PURE__ */ new Set([
266
266
  "select",
267
267
  "boolean",
268
268
  "number",
269
269
  "text"
270
- ]), P = (e, t, n, r, i, a, o, s) => {
271
- let c = n ? u(e, t, n, i, a, !1) : void 0, l = c != null && c.input?.startsWith("list") === !0, d = n && e.isArrayType(n) ? e.getTypeArguments(n)[0] : void 0, f = r.elements.map((n) => F(e, t, d, n, i, a, s));
272
- return {
273
- input: l ? c.input : "list",
274
- type: (l ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
275
- items: f,
276
- ...o?.length ? { suggestions: o } : {}
277
- };
278
- }, F = (e, t, n, r, i, a, o) => {
279
- if (p.isArrayLiteralExpression(r)) return P(e, t, n, r, i, a, void 0, o);
280
- if (p.isObjectLiteralExpression(r)) return I(e, t, n, r, i, a, void 0, o);
281
- let c = n ? u(e, t, n, i, a, !0) : void 0, l = !c || c.input === "generic", d = e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r));
282
- return l ? s(u(e, t, d, i, a, !0), o) : N.has(c.input) ? {
283
- ...c,
284
- type: e.typeToString(d)
285
- } : c;
286
- }, I = (e, t, n, r, i, a, o, s) => {
287
- let c = n ? u(e, t, n, i, a, !1) : void 0, l = c?.input === "data";
288
- if (c && !l && c.input !== "generic") return {
289
- ...c,
290
- type: e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
291
- ...o?.length ? { suggestions: o } : {}
292
- };
293
- let d = {}, f = [];
294
- for (let o of r.properties) {
295
- if (!p.isPropertyAssignment(o)) continue;
296
- let r = p.isStringLiteralLike(o.name) || p.isNumericLiteral(o.name) ? o.name.text : o.name.getText();
297
- d[r] = F(e, t, l ? L(e, n, r) : void 0, o.initializer, i, a, s), f.push(r);
270
+ ]), B = y.TypeFlags.Null | y.TypeFlags.Undefined | y.TypeFlags.Void | y.TypeFlags.Never, V = (e) => (e.flags & B) !== 0, H = (e, t) => (t.flags & y.TypeFlags.Object) !== 0 && !e.isArrayType(t) && !e.isTupleType(t), U = (e) => e.properties.filter(y.isPropertyAssignment).map((e) => Y(e)), W = (e, t, n) => {
271
+ if (!t) return;
272
+ let r = o(t);
273
+ if (!r.isUnion() || i(r)) return;
274
+ let a = r.types.filter((e) => (e.flags & (y.TypeFlags.Undefined | y.TypeFlags.Null)) === 0);
275
+ if (a.length < 2) return;
276
+ let s = e.getTypeAtLocation(n);
277
+ if ((s.flags & (y.TypeFlags.Any | y.TypeFlags.Unknown)) === 0) {
278
+ let t = a.find((t) => e.isTypeAssignableTo(s, t));
279
+ if (t) return t;
298
280
  }
299
- return {
281
+ if (y.isObjectLiteralExpression(n)) {
282
+ let t = U(n), r, i = 0;
283
+ for (let n of a) {
284
+ let a = t.filter((t) => e.getPropertyOfType(n, t) != null).length;
285
+ a > i && (r = n, i = a);
286
+ }
287
+ return r;
288
+ }
289
+ if (y.isArrayLiteralExpression(n)) return a.find((t) => e.isArrayType(t) || e.isTupleType(t));
290
+ }, G = (t, n, r, i, a, s, l, u) => {
291
+ let f = r ? c(t, n, r, a, s, !0) : void 0, p = f != null && f.input?.startsWith("list") === !0, m = r ? o(r) : void 0, h = m && t.isArrayType(m) ? t.getTypeArguments(m)[0] : void 0, g = i.elements.map((e) => q(t, n, h, e, a, s, u));
292
+ return e({
293
+ input: p ? f.input : "list",
294
+ type: (p ? f.type : void 0) ?? t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),
295
+ items: g,
296
+ declaredItems: d(p ? f.items : void 0, u)
297
+ }, l ?? K(f, u));
298
+ }, K = (e, t) => !e || e.input === "generic" ? t : _(e), q = (t, r, i, a, o, s, l) => {
299
+ let u = W(t, i, a) ?? i;
300
+ if (y.isArrayLiteralExpression(a)) return G(t, r, u, a, o, s, void 0, l);
301
+ if (y.isObjectLiteralExpression(a)) return J(t, r, u, a, o, s, void 0, l);
302
+ let d = u ? c(t, r, u, o, s, !0) : void 0, f = !d || d.input === "generic", p = t.getBaseTypeOfLiteralType(t.getTypeAtLocation(a));
303
+ return f ? n(c(t, r, p, o, s, !0), l) : z.has(d.input) ? e({
304
+ ...d,
305
+ ...V(p) ? {} : { type: t.typeToString(p) }
306
+ }, _(d)) : m(d, l);
307
+ }, J = (t, n, r, i, a, s, l, u) => {
308
+ let d = r ? c(t, n, r, a, s, !0) : void 0, f = d?.input === "data";
309
+ if (d && !f && d.input !== "generic") return e({
310
+ ...d,
311
+ type: t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i)))
312
+ }, l ?? _(d));
313
+ let p = f ? d.properties ?? {} : {}, h = {};
314
+ for (let [e, t] of Object.entries(p)) h[e] = Array.isArray(t) ? t.map((e) => m(e, u)) : m(t, u);
315
+ let g = [];
316
+ for (let e of i.properties) {
317
+ if (!y.isPropertyAssignment(e)) continue;
318
+ let i = Y(e);
319
+ h[i] = q(t, n, f ? X(t, o(r), i) : void 0, e.initializer, a, s, u), g.push(i);
320
+ }
321
+ let v = f ? d.required ?? [] : g;
322
+ return e({
300
323
  input: "data",
301
- type: (l ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
302
- properties: d,
303
- required: f,
304
- ...o?.length ? { suggestions: o } : {}
305
- };
306
- }, L = (e, t, n) => {
324
+ type: (f ? d.type : void 0) ?? t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),
325
+ properties: h,
326
+ required: v
327
+ }, l ?? K(d, u));
328
+ }, Y = (e) => y.isStringLiteralLike(e.name) || y.isNumericLiteral(e.name) ? e.name.text : e.name.getText(), X = (e, t, n) => {
307
329
  let r = e.getPropertyOfType(t, n);
308
330
  if (!r) return;
309
331
  let i = r.valueDeclaration ?? r.declarations?.[0];
310
332
  return i ? e.getTypeOfSymbolAtLocation(r, i) : void 0;
311
- }, R = (e, t, n) => {
312
- if ((t.flags & p.TypeFlags.TypeParameter) !== 0) {
333
+ }, Z = (e, t, n) => {
334
+ if ((t.flags & y.TypeFlags.TypeParameter) !== 0) {
313
335
  let n = t.symbol?.declarations?.[0];
314
- return n && p.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
336
+ return n && y.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
315
337
  }
316
- if ((t.flags & p.TypeFlags.Conditional) !== 0) return e.getBaseConstraintOfType(t) ?? e.getAnyType();
317
- if ((t.flags & p.TypeFlags.Object) !== 0 && z(t, e, /* @__PURE__ */ new Set())) {
338
+ if ((t.flags & y.TypeFlags.Conditional) !== 0) return e.getBaseConstraintOfType(t) ?? e.getAnyType();
339
+ if ((t.flags & y.TypeFlags.Object) !== 0 && Q(t, e, /* @__PURE__ */ new Set())) {
318
340
  let r = t.aliasSymbol?.getName();
319
341
  if (r) {
320
- let t = e.getSymbolsInScope(n, p.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
342
+ let t = e.getSymbolsInScope(n, y.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
321
343
  if (t) return e.getTypeOfSymbolAtLocation(t, n);
322
344
  }
323
345
  return e.getAnyType();
324
346
  }
325
347
  return t;
326
- }, z = (e, t, n) => !n.has(e) && (n.add(e), !!((e.flags & p.TypeFlags.TypeParameter) !== 0 || (e.flags & p.TypeFlags.Object) !== 0 && (t.getTypeArguments(e).some((e) => z(e, t, n)) || e.aliasTypeArguments?.some((e) => z(e, t, n))))), B = (e, t = []) => {
327
- let n = "index.ts", r = `${l(t)}\ntype MyType = ${e}`, i = d(n, r).languageService.getProgram(), a = i?.getSourceFile(n), o = i?.getTypeChecker();
348
+ }, Q = (e, t, n) => !n.has(e) && (n.add(e), !!((e.flags & y.TypeFlags.TypeParameter) !== 0 || (e.flags & y.TypeFlags.Object) !== 0 && (t.getTypeArguments(e).some((e) => Q(e, t, n)) || e.aliasTypeArguments?.some((e) => Q(e, t, n))))), $ = (e, t = []) => {
349
+ let n = "index.ts", r = `${p(t)}\ntype MyType = ${e}`, i = h(n, r).languageService.getProgram(), a = i?.getSourceFile(n), o = i?.getTypeChecker();
328
350
  if (!a || !o) return;
329
- let s = a.statements.filter((e) => p.isTypeAliasDeclaration(e) || p.isInterfaceDeclaration(e) || p.isClassDeclaration(e)).pop();
351
+ let s = a.statements.filter((e) => y.isTypeAliasDeclaration(e) || y.isInterfaceDeclaration(e) || y.isClassDeclaration(e)).pop();
330
352
  if (!s) return;
331
- let c = o.getTypeAtLocation(s);
332
- if (c) return u(o, void 0, c, [], [], !1);
353
+ let l = o.getTypeAtLocation(s);
354
+ if (l) return c(o, void 0, l, [], [], !1);
333
355
  };
334
356
  //#endregion
335
- export { e as CUSTOM_INPUT_IDENTIFIERS, s as genericNodeSchema, S as getFlowValidation, u as getSchema, w as getSignatureSchema, h as getTypeFromValue, B as getTypeSchema, g as getValueFromType, C as getValueValidation, t as isCustomInputIdentifier, a as isCustomInputKind, f as isSubFlow, n as mergeSchemas, r as normalizeNodeSchema };
357
+ export { t as CUSTOM_INPUT_IDENTIFIERS, d as declaredItemsOf, m as declaredSchema, n as genericNodeSchema, O as getFlowValidation, c as getSchema, A as getSignatureSchema, x as getTypeFromValue, $ as getTypeSchema, S as getValueFromType, k as getValueValidation, g as isCustomInputIdentifier, r as isCustomInputKind, i as isOptionsUnion, f as isSubFlow, l as mergeSchemas, o as nonNullishType, a as normalizeNodeSchema, e as withSuggestions };
@@ -8,9 +8,15 @@ export interface NodeSchema {
8
8
  /**
9
9
  * The schema definition for this node parameter. Produced by merging the
10
10
  * function-declared parameter schema with the node's concrete value schema:
11
- * the function schema drives the structural shape, the node schema contributes
12
- * additional suggestions, and a generic function parameter falls back to the
13
- * node's concrete shape (never as a select).
11
+ * the function schema drives the structural shape and the suggestions of every
12
+ * nested position, the node schema contributes the parameter's own suggestion
13
+ * scope plus the shape and `type` the entered value implies, and a generic
14
+ * function parameter falls back to the node's concrete shape (never as a
15
+ * select).
16
+ *
17
+ * Which suggestions a position offers therefore depends on the declared type
18
+ * alone — entering a value changes how many items/properties are rendered and
19
+ * each position's `type`, never the set of candidates it offers.
14
20
  */
15
21
  schema: Schema;
16
22
  /** Array of parameter indices that must be resolved before this parameter */
package/dist/server.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-oMAOCPrM.cjs");let t=require("typescript");t=e.m(t,1);let n=require("ts-json-schema-generator");var r={...n.DEFAULT_CONFIG,expose:`none`,topRef:!1,jsDoc:`none`,skipTypeCheck:!0},i=(e,t)=>{let n=Object.keys(e);if(n.length===0)return{};let r=o(a(e,t)),i={};for(let e of n)try{i[e]=s(r.createSchema(e))}catch{i[e]={}}return i},a=(t,n)=>{let r=Object.entries(t).map(([e,t])=>`export type ${e} = ${t};`).join(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-BftsgxoV.cjs");let t=require("typescript");t=e.b(t,1);let n=require("ts-json-schema-generator");var r={...n.DEFAULT_CONFIG,expose:`none`,topRef:!1,jsDoc:`none`,skipTypeCheck:!0},i=(e,t)=>{let n=Object.keys(e);if(n.length===0)return{};let r=o(a(e,t)),i={};for(let e of n)try{i[e]=s(r.createSchema(e))}catch{i[e]={}}return i},a=(t,n)=>{let r=Object.entries(t).map(([e,t])=>`export type ${e} = ${t};`).join(`
2
2
  `);return`${e.r(n)}\n${r}`},o=t=>{let i=e.t(`index.ts`,t).languageService.getProgram();return new n.SchemaGenerator(i,(0,n.createParser)(i,r),(0,n.createFormatter)(r),r)},s=e=>{let{$schema:t,definitions:n,...r}=e,i=n&&Object.keys(n).length>0?{...r,definitions:n}:r;return JSON.parse(JSON.stringify(i))},c=(t,n,r)=>{if(!t)return;let a=`index.ts`,o=e.n(t,n,r),s=e.t(a,o),c=s.getSourceFile(a),d=s.languageService.getProgram().getTypeChecker(),m=i({...f(d,c),...p(d,c,t)},r),h=(t.nodes?.nodes??[]).map(e=>e&&b(e,m));return{...t,inputSchema:m[l]??v(),outputSchema:m[u]??y(),nodes:{...t.nodes,nodes:h}}},l=`Flow_input`,u=`Flow_output`,d=(t,n,r)=>`Node_${e.i(t)}_${n}_${r}`,f=(e,n)=>{let r=n.statements.filter(t.default.isFunctionDeclaration).find(e=>e.name?.getText()===`flow`);if(!r)return{};let i=e.getSignatureFromDeclaration(r);if(!i)return{};let{input:a,output:o}=_(e,i,r);return{[l]:a,[u]:o}},p=(e,t,n)=>{let r=w(t),i={};for(let t of n.nodes?.nodes??[]){if(!t?.id)continue;let n=t.parameters?.nodes;if(!n?.some(x))continue;let a=C(r,t);a&&n.forEach((n,r)=>{if(!x(n))return;let o=a.arguments[r],s=o?e.getTypeAtLocation(o).getCallSignatures()[0]:void 0;if(!s)return;let{input:c,output:l}=m(e,s,o);i[d(t.id,r,`input`)]=c,i[d(t.id,r,`output`)]=l})}return i},m=(e,n,r)=>({input:`{ ${h(e,n,r).join(`; `)} }`,output:(n=>e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation))(e.getReturnTypeOfSignature(n))}),h=(e,n,r)=>{let i=n=>e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation),a=n.getParameters();if(a.length===1){let t=g(e,e.getTypeOfSymbolAtLocation(a[0],a[0].valueDeclaration??r),r);if(t)return t}return a.map(t=>{let n=e.getTypeOfSymbolAtLocation(t,t.valueDeclaration??r),a=S(t)?`?`:``;return`${t.getName()}${a}: ${i(n)}`})},g=(e,n,r)=>{let i=n,a=i.target;if(a&&(a.objectFlags&t.default.ObjectFlags.Tuple)!==0)return e.getTypeArguments(i).map((n,i)=>{let o=a.labeledElementDeclarations?.[i];return`${o?.name&&t.default.isIdentifier(o.name)?o.name.text:`arg${i}`}${(a.elementFlags[i]&t.default.ElementFlags.Optional)===0?``:`?`}: ${e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation)}`})},_=(e,n,r)=>{let i=n=>e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation);return{input:`{ ${n.parameters.map(t=>{let n=e.getTypeOfSymbolAtLocation(t,t.valueDeclaration??r),a=S(t)?`?`:``;return`${t.getName()}${a}: ${i(n)}`}).join(`; `)} }`,output:i(e.getReturnTypeOfSignature(n))}},v=()=>({type:`object`}),y=()=>({}),b=(e,t)=>{let n=e.parameters?.nodes;if(!n?.some(x))return e;let r=n.map((n,r)=>{if(!x(n))return n;let i={...n.value,inputSchema:t[d(e.id,r,`input`)]??v(),outputSchema:t[d(e.id,r,`output`)]??y()};return{...n,value:i}});return{...e,parameters:{...e.parameters,nodes:r}}},x=e=>e?.value?.__typename===`SubFlowValue`,S=e=>{let n=e.valueDeclaration;return!!n&&t.default.isParameter(n)&&(!!n.questionToken||!!n.initializer||!!n.dotDotDotToken)},C=(n,r)=>{let i=n.get(`node_${e.i(r.id)}`)?.initializer;return i&&t.default.isCallExpression(i)?i:void 0},w=e=>{let n=new Map;return e.statements.forEach(e=>{e.forEachChild(function e(r){t.default.isVariableDeclaration(r)&&(r.parent.flags&t.default.NodeFlags.Const)!==0&&n.set(r.name.getText(),r),r.forEachChild(e)})}),n};exports.getFlowSchemas=c;
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as e, n as t, r as n, t as r } from "./utils-CAOAm6k-.js";
1
+ import { i as e, n as t, r as n, t as r } from "./utils-A--QqsC6.js";
2
2
  import i from "typescript";
3
3
  import { DEFAULT_CONFIG as a, SchemaGenerator as o, createFormatter as s, createParser as c } from "ts-json-schema-generator";
4
4
  //#region src/util/jsonSchema.util.ts
@@ -1,5 +1,6 @@
1
1
  import { default as ts } from 'typescript';
2
- import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphql-types';
2
+ import { FunctionDefinition } from '@code0-tech/sagittarius-graphql-types';
3
+ import { SuggestionCandidate } from './suggestion.util';
3
4
  /**
4
5
  * Filters and transforms function declarations into a collection of compatible node functions.
5
6
  *
@@ -8,6 +9,13 @@ import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphq
8
9
  * are assignable to the specified parameter type. Each node function is enriched with
9
10
  * metadata including function definitions and parameter information.
10
11
  *
12
+ * A callable (sub-flow) parameter is no exception: it is matched by the same
13
+ * rule as every other slot — a function qualifies when the value it produces is
14
+ * assignable to the slot's type. Such a node is offered alongside the
15
+ * {@link getSubFlows} candidates, which bind an existing function as the
16
+ * sub-flow itself; the two kinds are told apart by their `__typename` and may
17
+ * both be present for the same function definition.
18
+ *
11
19
  * @param {ts.TypeChecker} checker - The TypeScript type checker instance used to analyze
12
20
  * type information and verify type compatibility
13
21
  * @param {ts.FunctionDeclaration[]} functionDeclarations - Array of TypeScript function
@@ -17,11 +25,12 @@ import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphq
17
25
  * @param {ts.Type} paramType - The target parameter type used to filter compatible
18
26
  * functions. Only functions with return types assignable to this type are included
19
27
  *
20
- * @returns {NodeFunction[]} Array of node functions that are compatible with the
21
- * specified parameter type. Returns an empty array if the parameter type
22
- * is a sub-flow or if no compatible functions are found
28
+ * @returns {SuggestionCandidate[]} Array of node-function candidates compatible with
29
+ * the specified parameter type, each carrying how certainly its return
30
+ * type produces that type, or an empty array if no compatible functions
31
+ * are found
23
32
  *
24
33
  * @example
25
34
  * const compatibleNodes = getNodes(checker, funcDecls, funcDefs, stringType);
26
35
  */
27
- export declare const getNodes: (checker: ts.TypeChecker, functionDeclarations: ts.FunctionDeclaration[], functions: FunctionDefinition[], paramType: ts.Type) => NodeFunction[];
36
+ export declare const getNodes: (checker: ts.TypeChecker, functionDeclarations: ts.FunctionDeclaration[], functions: FunctionDefinition[], paramType: ts.Type) => SuggestionCandidate[];
@@ -1,5 +1,5 @@
1
1
  import { default as ts } from 'typescript';
2
- import { ReferenceValue } from '@code0-tech/sagittarius-graphql-types';
2
+ import { SuggestionCandidate } from './suggestion.util';
3
3
  /**
4
4
  * Extracts reference values from a collection of TypeScript symbols.
5
5
  *
@@ -11,13 +11,15 @@ import { ReferenceValue } from '@code0-tech/sagittarius-graphql-types';
11
11
  * @param node - The VariableDeclaration context in which symbols are analyzed
12
12
  * @param paramType - The expected parameter type for property matching during extraction
13
13
  * @param symbols - The array of symbols to process and analyze
14
- * @returns An array of ReferenceValue objects representing extracted references with their paths
14
+ * @returns An array of reference candidates representing extracted references with
15
+ * their paths, each carrying how certainly the type at that path produces
16
+ * the expected type
15
17
  *
16
18
  * @example
17
19
  * // Extracts all references from symbols prefixed with node_, p_, or flow_
18
20
  * const references = getReferences(checker, variableDecl, expectedType, [symbol1, symbol2]);
19
21
  */
20
- export declare const getReferences: (checker: ts.TypeChecker, node: ts.VariableDeclaration, paramType: ts.Type, symbols: ts.Symbol[]) => ReferenceValue[];
22
+ export declare const getReferences: (checker: ts.TypeChecker, node: ts.VariableDeclaration, paramType: ts.Type, symbols: ts.Symbol[]) => SuggestionCandidate[];
21
23
  /**
22
24
  * Determines whether an object type participates in a reference cycle, i.e. can
23
25
  * reach itself again through its (non-nullable) property types. Results are