@code0-tech/triangulum 0.34.0 → 0.36.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-DawLGwwh.cjs");let t=require("typescript");t=e.p(t,1);var n=(n,r)=>{let i=e.f(n?.value);if(!i)return`any`;let a=`
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=`
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.f(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.p(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.d(e.s(n,r,i,m,c,!0,p));return{schema:e.u(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`,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.isSubFlow=e.l,exports.mergeSchemas=e.u,exports.normalizeNodeSchema=e.d;
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;
package/dist/index.js CHANGED
@@ -1,112 +1,112 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./utils-BZOsWQq3.js";
2
- import f, { flattenDiagnosticMessageText as p } from "typescript";
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";
3
3
  //#region src/extraction/getTypeFromValue.ts
4
- var m = (e, t) => {
5
- let n = r(e?.value);
4
+ var h = (e, t) => {
5
+ let n = c(e?.value);
6
6
  if (!n) return "any";
7
- let i = `
8
- ${c(t, "unknown")}
7
+ let r = `
8
+ ${l(t, "unknown")}
9
9
  const tempValue = ${n ?? "any"};
10
- `, a = "index.ts", o = u(a, i), s = o.getSourceFile(a), l = o.languageService.getProgram().getTypeChecker(), d = "any", p = (e) => {
11
- if (f.isVariableDeclaration(e) && e.name.getText() === "tempValue") {
12
- let t = l.getTypeAtLocation(e), n = (t) => {
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") {
12
+ let t = s.getTypeAtLocation(e), n = (t) => {
13
13
  if (t.isUnion()) {
14
14
  let e = t.types.map(n);
15
15
  return Array.from(new Set(e)).sort().join(" | ");
16
16
  }
17
- if (l.isArrayType(t)) {
17
+ if (s.isArrayType(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() & f.TypeFlags.Object || t.isClassOrInterface()) {
22
- let r = l.getPropertiesOfType(t);
21
+ if (t.getFlags() & p.TypeFlags.Object || t.isClassOrInterface()) {
22
+ let r = s.getPropertiesOfType(t);
23
23
  if (r.length > 0) return `{ ${r.map((t) => {
24
- let r = l.getTypeOfSymbolAtLocation(t, e);
24
+ let r = s.getTypeOfSymbolAtLocation(t, e);
25
25
  return `${t.getName()}: ${n(r)}`;
26
26
  }).join(", ")} }`;
27
27
  }
28
- let r = l.getBaseTypeOfLiteralType(t);
29
- return l.typeToString(r, e);
28
+ let r = s.getBaseTypeOfLiteralType(t);
29
+ return s.typeToString(r, e);
30
30
  };
31
- d = n(t);
31
+ u = n(t);
32
32
  }
33
- f.forEachChild(e, p);
33
+ p.forEachChild(e, f);
34
34
  };
35
- return p(s), d;
36
- }, h = (e, t) => {
35
+ return f(o), u;
36
+ }, g = (e, t) => {
37
37
  let n = `
38
- ${c(t)}
38
+ ${l(t)}
39
39
  type Target = ${e};
40
- `, r = "index.ts", i = u(r, n), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = a.statements.find((e) => f.isTypeAliasDeclaration(e) && e.name.text === "Target");
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");
41
41
  if (!s) return {
42
42
  __typename: "LiteralValue",
43
43
  value: null
44
44
  };
45
- let l = o.getTypeAtLocation(s.type), d = (e, t, n = /* @__PURE__ */ new Set()) => {
45
+ let c = o.getTypeAtLocation(s.type), u = (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, f.isTypeAliasDeclaration(t) && t.type && f.isUnionTypeNode(t.type)) {
50
+ if (t.type, p.isTypeAliasDeclaration(t) && t.type && p.isUnionTypeNode(t.type)) {
51
51
  let e = o.getTypeFromTypeNode(t.type.types[0]);
52
- return d(e, t, r);
52
+ return u(e, t, r);
53
53
  }
54
54
  let n = e.types.filter((e) => {
55
55
  let t = e.getFlags();
56
- return !(t & f.TypeFlags.Undefined) && !(t & f.TypeFlags.Null);
56
+ return !(t & p.TypeFlags.Undefined) && !(t & p.TypeFlags.Null);
57
57
  }), i = n.length > 0 ? n[0] : e.types[0];
58
- return d(i, t, r);
58
+ return u(i, t, r);
59
59
  }
60
- if (i & f.TypeFlags.StringLiteral) return e.value;
61
- if (i & f.TypeFlags.String) return "";
62
- if (i & f.TypeFlags.NumberLiteral) return e.value;
63
- if (i & f.TypeFlags.Number) return 0;
64
- if (i & f.TypeFlags.BooleanLiteral) return e.intrinsicName === "true";
65
- if (i & f.TypeFlags.Boolean) return !1;
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;
66
66
  if (o.isArrayType(e)) {
67
67
  r.add(e);
68
- let n = e.typeArguments?.[0] || o.getAnyType(), i = d(n, t, r);
68
+ let n = e.typeArguments?.[0] || o.getAnyType(), i = u(n, t, r);
69
69
  return i === null ? [] : [i];
70
70
  }
71
- if (e.isClassOrInterface() || i & f.TypeFlags.Object || e.getProperties().length > 0) {
71
+ if (e.isClassOrInterface() || i & p.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()] = d(i, a || t, r));
76
+ i && (n[e.getName()] = u(i, a || t, r));
77
77
  }), n;
78
78
  }
79
79
  return null;
80
80
  };
81
81
  return {
82
82
  __typename: "LiteralValue",
83
- value: d(l, s)
83
+ value: u(c, s)
84
84
  };
85
- }, g = 2345, _ = 2322, v = 2339, y = (e, t, n) => {
85
+ }, _ = 2345, v = 2322, y = 2339, b = (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 = y(e, t, n);
89
+ let i = b(e, t, n);
90
90
  i && (r = i);
91
91
  }), r;
92
- }, b = (e, t, n) => {
92
+ }, x = (e, t, n) => {
93
93
  if (e.start === void 0 || e.length === void 0) return !1;
94
- let r = y(t, e.start, e.start + e.length);
94
+ let r = b(t, e.start, e.start + e.length);
95
95
  if (!r) return !1;
96
- if ((e.code === g || e.code === _) && f.isExpression(r)) {
96
+ if ((e.code === _ || e.code === v) && p.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 & (f.TypeFlags.Null | f.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
100
+ return t ? e.types.some((e) => (e.flags & (p.TypeFlags.Null | p.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
101
101
  }
102
- if (e.code === v && f.isPropertyAccessExpression(r.parent)) {
102
+ if (e.code === y && p.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
- }, x = (e, t, n) => {
109
+ }, S = (e, t, n) => {
110
110
  if (!e?.startingNodeId) return {
111
111
  isValid: !1,
112
112
  returnType: "void",
@@ -141,8 +141,8 @@ var m = (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 = u(s, a), l = c.getSourceFile(s), d = c.languageService.getProgram(), f = d.getTypeChecker(), m = d.getSemanticDiagnostics(l).map((e) => {
145
- let t = p(e.messageText, "\n"), n, r = null;
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;
146
146
  if (e.start !== void 0) {
147
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
148
  for (; (c = s.exec(o)) !== null;) {
@@ -151,7 +151,7 @@ var m = (e, t) => {
151
151
  }
152
152
  u && (n = u[1] === "null" ? null : u[1], r = parseInt(u[2], 10));
153
153
  }
154
- let i = b(e, l, f) ? "warning" : "error";
154
+ let i = x(e, l, f) ? "warning" : "error";
155
155
  return {
156
156
  message: t,
157
157
  code: e.code,
@@ -161,16 +161,16 @@ var m = (e, t) => {
161
161
  };
162
162
  }).filter((e) => e !== null);
163
163
  return {
164
- isValid: !m.some((e) => e?.severity === "error"),
164
+ isValid: !p.some((e) => e?.severity === "error"),
165
165
  returnType: "void",
166
- diagnostics: m
166
+ diagnostics: p
167
167
  };
168
- }, S = (e, t, n) => {
169
- let i = r(t?.value), a = `
170
- ${c(n)}
171
- const testValue: ${e} = ${i};
172
- `, o = "index.ts", s = u(o, a).languageService.getSemanticDiagnostics(o).map((e) => {
173
- let t = f.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");
168
+ }, C = (e, t, n) => {
169
+ let r = c(t?.value), i = `
170
+ ${l(n)}
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");
174
174
  return {
175
175
  message: t,
176
176
  code: e.code,
@@ -178,19 +178,19 @@ var m = (e, t) => {
178
178
  };
179
179
  });
180
180
  return {
181
- isValid: !s.some((e) => e.severity === "error"),
181
+ isValid: !o.some((e) => e.severity === "error"),
182
182
  returnType: "void",
183
- diagnostics: s
183
+ diagnostics: o
184
184
  };
185
- }, C = (e, t, n, r) => {
186
- let a = o(e, n, t), s = "index.ts", c = u(s, a), d = c.getSourceFile(s), p = 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)}`, _ = T(d), v = E(d).get(g), y = _.get(h), b = D(p, v), x = O(p, y, v), S = b?.map((e, t) => (e.flags & f.TypeFlags.Undefined) === 0 ? e : x?.[t] ?? e), C = (m?.parameters?.nodes ?? []).map((e) => e?.value != null), j = A(p, v, S, x, k(y, b, C), r ? _ : /* @__PURE__ */ new Map(), r ? n : [], C), M = w(p, v, y);
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);
187
187
  return {
188
188
  nodeId: r,
189
- parameters: j,
190
- return: M ? l(p, v, M, Array.from(_.values()), n, !1) : { input: "generic" }
189
+ parameters: w,
190
+ return: M ? u(f, v, M, Array.from(_.values()), n, !1) : { input: "generic" }
191
191
  };
192
- }, w = (e, t, n) => {
193
- if (t?.initializer && f.isCallExpression(t.initializer)) {
192
+ }, T = (e, t, n) => {
193
+ if (t?.initializer && p.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 m = (e, t) => {
198
198
  let t = e.getSignatureFromDeclaration(n);
199
199
  if (t) return e.getReturnTypeOfSignature(t);
200
200
  }
201
- }, T = (e) => new Map(e.statements.filter(f.isFunctionDeclaration).map((e) => [e.name.getText(), e])), E = (e) => {
201
+ }, E = (e) => new Map(e.statements.filter(p.isFunctionDeclaration).map((e) => [e.name.getText(), e])), D = (e) => {
202
202
  let t = [];
203
203
  return e.statements.forEach((e) => {
204
204
  e.forEachChild(function e(n) {
205
- f.isVariableDeclaration(n) && (n.parent.flags & f.NodeFlags.Const) !== 0 && t.push([n.name.getText(), n]), n.forEachChild(e);
205
+ p.isVariableDeclaration(n) && (n.parent.flags & p.NodeFlags.Const) !== 0 && t.push([n.name.getText(), n]), n.forEachChild(e);
206
206
  });
207
207
  }), new Map(t);
208
- }, D = (e, t) => {
209
- if (!(!t?.initializer || !f.isCallExpression(t.initializer))) return e.getResolvedSignature(t.initializer)?.parameters.map((n) => e.getTypeOfSymbolAtLocation(n, t.initializer));
210
- }, O = (e, t, n) => {
211
- if (!(!t || !n?.initializer)) return t.parameters.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) => {
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
- }, k = (e, t, n = []) => {
215
+ }, A = (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 (f.isTypeReferenceNode(i) && f.isIdentifier(i.typeName)) {
221
+ if (p.isTypeReferenceNode(i) && p.isIdentifier(i.typeName)) {
222
222
  let e = i.typeName.text;
223
223
  r.includes(e) && n.add(e);
224
224
  }
225
- if (f.isTypeReferenceNode(e.type) && f.isIdentifier(e.type.typeName)) {
225
+ if (p.isTypeReferenceNode(e.type) && p.isIdentifier(e.type.typeName)) {
226
226
  let t = e.type.typeName.text;
227
227
  r.includes(t) && n.add(t);
228
228
  }
@@ -239,91 +239,97 @@ var m = (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 & f.TypeFlags.Null) !== 0, a = (r.flags & f.TypeFlags.Undefined) !== 0;
242
+ let i = (r.flags & p.TypeFlags.Null) !== 0, a = (r.flags & p.TypeFlags.Undefined) !== 0;
243
243
  return i || a;
244
244
  }) : a;
245
- }, A = (e, t, r, i, a, o, s, c) => {
246
- if (!r) return [];
247
- let u = l(e, t, e.getAnyType(), Array.from(o.values()), s, !0).suggestions;
248
- return r.map((r, p) => {
249
- let m = i?.[p], h = m ? L(e, m, t) : void 0, g = Array.from(o.values()), _ = m ? l(e, t, m, g, s, !1) : void 0, v = (r.flags & f.TypeFlags.Object) !== 0 && !e.isArrayType(r) && !e.isTupleType(r), y = j(t, p);
250
- if (y && (f.isArrayLiteralExpression(y) || f.isObjectLiteralExpression(y) && v)) {
251
- let n = l(e, t, r, g, s, !0, h).suggestions;
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;
252
252
  return {
253
- schema: f.isArrayLiteralExpression(y) ? N(e, t, m, y, g, s, n, u) : F(e, t, m, y, g, s, n, u),
254
- blockedBy: a.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
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)
255
255
  };
256
256
  }
257
- let b = n(l(e, t, r, g, s, !0, h));
257
+ let b = r(u(e, t, i, g, c, !0, h));
258
258
  return {
259
- schema: d(_, b, c[p] ?? !1, u),
260
- blockedBy: a.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
259
+ schema: n(_, b, l[f] ?? !1, d),
260
+ blockedBy: o.filter((e) => e.parameterIndex === f).map((e) => e.dependsOnIndex)
261
261
  };
262
262
  });
263
- }, j = (e, t) => {
264
- if (!(!e.initializer || !f.isCallExpression(e.initializer))) return e.initializer.arguments[t];
265
- }, M = /* @__PURE__ */ new Set([
263
+ }, M = (e, t) => {
264
+ if (e.initializer && p.isCallExpression(e.initializer)) return e.initializer.arguments[t];
265
+ }, N = /* @__PURE__ */ new Set([
266
266
  "select",
267
267
  "boolean",
268
268
  "number",
269
269
  "text"
270
- ]), N = (e, t, n, r, i, a, o, s) => {
271
- let c = n ? l(e, t, n, i, a, !1) : void 0, u = c != null && c.input?.startsWith("list") === !0, d = n && e.isArrayType(n) ? e.getTypeArguments(n)[0] : void 0, f = r.elements.map((n) => P(e, t, d, n, i, a, s));
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
272
  return {
273
- input: u ? c.input : "list",
274
- type: (u ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
273
+ input: l ? c.input : "list",
274
+ type: (l ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
275
275
  items: f,
276
276
  ...o?.length ? { suggestions: o } : {}
277
277
  };
278
- }, P = (e, t, n, r, i, a, o) => {
279
- if (f.isArrayLiteralExpression(r)) return N(e, t, n, r, i, a, void 0, o);
280
- if (f.isObjectLiteralExpression(r)) return F(e, t, n, r, i, a, void 0, o);
281
- let c = n ? l(e, t, n, i, a, !0) : void 0, u = !c || c.input === "generic", d = e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r));
282
- return u ? s(l(e, t, d, i, a, !0), o) : M.has(c.input) ? {
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
283
  ...c,
284
284
  type: e.typeToString(d)
285
285
  } : c;
286
- }, F = (e, t, n, r, i, a, o, s) => {
287
- let c = n ? l(e, t, n, i, a, !1) : void 0, u = c?.input === "data", d = {}, p = [];
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 = [];
288
294
  for (let o of r.properties) {
289
- if (!f.isPropertyAssignment(o)) continue;
290
- let r = f.isStringLiteralLike(o.name) || f.isNumericLiteral(o.name) ? o.name.text : o.name.getText();
291
- d[r] = P(e, t, u ? I(e, n, r) : void 0, o.initializer, i, a, s), p.push(r);
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);
292
298
  }
293
299
  return {
294
300
  input: "data",
295
- type: (u ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
301
+ type: (l ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
296
302
  properties: d,
297
- required: p,
303
+ required: f,
298
304
  ...o?.length ? { suggestions: o } : {}
299
305
  };
300
- }, I = (e, t, n) => {
306
+ }, L = (e, t, n) => {
301
307
  let r = e.getPropertyOfType(t, n);
302
308
  if (!r) return;
303
309
  let i = r.valueDeclaration ?? r.declarations?.[0];
304
310
  return i ? e.getTypeOfSymbolAtLocation(r, i) : void 0;
305
- }, L = (e, t, n) => {
306
- if ((t.flags & f.TypeFlags.TypeParameter) !== 0) {
311
+ }, R = (e, t, n) => {
312
+ if ((t.flags & p.TypeFlags.TypeParameter) !== 0) {
307
313
  let n = t.symbol?.declarations?.[0];
308
- return n && f.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
314
+ return n && p.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
309
315
  }
310
- if ((t.flags & f.TypeFlags.Conditional) !== 0) return e.getBaseConstraintOfType(t) ?? e.getAnyType();
311
- if ((t.flags & f.TypeFlags.Object) !== 0 && R(t, e, /* @__PURE__ */ new Set())) {
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())) {
312
318
  let r = t.aliasSymbol?.getName();
313
319
  if (r) {
314
- let t = e.getSymbolsInScope(n, f.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
320
+ let t = e.getSymbolsInScope(n, p.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
315
321
  if (t) return e.getTypeOfSymbolAtLocation(t, n);
316
322
  }
317
323
  return e.getAnyType();
318
324
  }
319
325
  return t;
320
- }, R = (e, t, n) => !n.has(e) && (n.add(e), !!((e.flags & f.TypeFlags.TypeParameter) !== 0 || (e.flags & f.TypeFlags.Object) !== 0 && (t.getTypeArguments(e).some((e) => R(e, t, n)) || e.aliasTypeArguments?.some((e) => R(e, t, n))))), z = (e, t = []) => {
321
- let n = "index.ts", r = `${c(t)}\ntype MyType = ${e}`, i = u(n, r).languageService.getProgram(), a = i?.getSourceFile(n), o = i?.getTypeChecker();
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();
322
328
  if (!a || !o) return;
323
- let s = a.statements.filter((e) => f.isTypeAliasDeclaration(e) || f.isInterfaceDeclaration(e) || f.isClassDeclaration(e)).pop();
329
+ let s = a.statements.filter((e) => p.isTypeAliasDeclaration(e) || p.isInterfaceDeclaration(e) || p.isClassDeclaration(e)).pop();
324
330
  if (!s) return;
325
- let d = o.getTypeAtLocation(s);
326
- if (d) return l(o, void 0, d, [], [], !1);
331
+ let c = o.getTypeAtLocation(s);
332
+ if (c) return u(o, void 0, c, [], [], !1);
327
333
  };
328
334
  //#endregion
329
- export { e as CUSTOM_INPUT_IDENTIFIERS, s as genericNodeSchema, x as getFlowValidation, l as getSchema, C as getSignatureSchema, m as getTypeFromValue, z as getTypeSchema, h as getValueFromType, S as getValueValidation, t as isCustomInputIdentifier, a as isSubFlow, d as mergeSchemas, n as normalizeNodeSchema };
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 };
package/dist/server.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-DawLGwwh.cjs");let t=require("typescript");t=e.p(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
- `);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;
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(`
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-BZOsWQq3.js";
1
+ import { i as e, n as t, r as n, t as r } from "./utils-CAOAm6k-.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
@@ -86,7 +86,7 @@ var l = {
86
86
  });
87
87
  }, S = (e, t, n) => {
88
88
  let r = t, a = r.target;
89
- if (!(!a || (a.objectFlags & i.ObjectFlags.Tuple) === 0)) return e.getTypeArguments(r).map((t, r) => {
89
+ if (a && (a.objectFlags & i.ObjectFlags.Tuple) !== 0) return e.getTypeArguments(r).map((t, r) => {
90
90
  let o = a.labeledElementDeclarations?.[r];
91
91
  return `${o?.name && i.isIdentifier(o.name) ? o.name.text : `arg${r}`}${(a.elementFlags[r] & i.ElementFlags.Optional) === 0 ? "" : "?"}: ${e.typeToString(t, n, i.TypeFormatFlags.NoTruncation)}`;
92
92
  });
@@ -17,11 +17,25 @@ import { FunctionDefinition, LiteralValue, NodeFunction, ReferenceValue, SubFlow
17
17
  */
18
18
  export declare const CUSTOM_INPUT_IDENTIFIERS: {
19
19
  readonly DATE: "date";
20
+ readonly TYPE: "type";
20
21
  };
21
22
  /** A data type identifier that maps to a custom input. */
22
23
  export type CustomInputIdentifier = keyof typeof CUSTOM_INPUT_IDENTIFIERS;
23
24
  /** Returns true if the given identifier maps to a custom input. */
24
25
  export declare const isCustomInputIdentifier: (identifier: string | null | undefined) => identifier is CustomInputIdentifier;
26
+ /**
27
+ * Returns true if the given input kind is one produced by a custom-input data
28
+ * type (e.g. "date", "type"). Used by {@link mergeSchemas} to let a supplied
29
+ * value narrow the rendered `type` of such an input while the input kind itself
30
+ * is kept.
31
+ *
32
+ * Note this covers the registry-driven kinds only, so it is not the test for
33
+ * "is this input dedicated rather than structural" — COLOR is detected by shape
34
+ * (see isColorType) and never appears here. Code that must not expand a
35
+ * dedicated input back into the shape it was built from checks for the
36
+ * structural kinds it does expand ("data", "generic") instead.
37
+ */
38
+ export declare const isCustomInputKind: (input: string | undefined) => boolean;
25
39
  /**
26
40
  * Base interface for all input types.
27
41
  * Provides common properties for suggestions and input metadata.
@@ -179,15 +193,13 @@ export interface ListInput extends Input {
179
193
  items?: Schema[];
180
194
  }
181
195
  /**
182
- * Represents a complex type input with properties and required fields.
183
- * Similar to DataInput but used for type definitions.
196
+ * Represents a type input.
197
+ * Emitted for the TYPE data type so the UI can render a dedicated type picker
198
+ * instead of the plain input its underlying type (`any`) would otherwise
199
+ * produce. Like {@link DateInput}, it carries no additional properties.
184
200
  */
185
201
  export interface TypeInput extends Input {
186
202
  input?: "type";
187
- /** Record mapping property names to their schemas */
188
- properties?: Record<string, Schema | Schema[]>;
189
- /** Array of required property names */
190
- required?: string[];
191
203
  }
192
204
  /**
193
205
  * Union type representing all possible schema input types.
@@ -218,7 +230,7 @@ export type Schema = PrimitiveInput | DateInput | ColorInput | FileInput | ListF
218
230
  * @param suggestions
219
231
  * @returns A Schema object describing how to handle the parameter type
220
232
  */
221
- export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration | undefined, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[], suggestions?: boolean, suggestionType?: ts.Type, visited?: Set<ts.Type>, recursionCache?: Map<ts.Type, boolean>) => Schema;
233
+ export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration | undefined, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[], suggestions?: boolean, suggestionType?: ts.Type, visited?: Set<ts.Type>, recursionCache?: Map<ts.Type, boolean>, declaredType?: ts.Type) => Schema;
222
234
  /**
223
235
  * Normalizes a node-side schema so it only contributes concrete resolved types
224
236
  * to {@link mergeSchemas}, recursing through `items` and `properties`. It: