@code0-tech/triangulum 0.37.2 → 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 +3 -3
- package/dist/index.js +89 -89
- package/dist/server.cjs +1 -1
- package/dist/server.js +1 -1
- package/dist/util/nodes.util.d.ts +7 -5
- package/dist/util/references.util.d.ts +5 -3
- package/dist/util/schema.util.d.ts +42 -15
- package/dist/util/subflows.util.d.ts +6 -4
- package/dist/util/suggestion.util.d.ts +161 -0
- package/dist/{utils-DSmUMJiO.js → utils-A--QqsC6.js} +235 -203
- package/dist/utils-BftsgxoV.cjs +45 -0
- package/package.json +1 -1
- package/dist/utils-euztPiZI.cjs +0 -45
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-
|
|
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.
|
|
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.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.l(n,r,n.getAnyType(),Array.from(s.values()),c,!0)
|
|
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 { _ 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 _ } from "./utils-
|
|
2
|
-
import
|
|
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
|
|
5
|
-
let n =
|
|
4
|
+
var x = (e, t) => {
|
|
5
|
+
let n = v(e?.value);
|
|
6
6
|
if (!n) return "any";
|
|
7
7
|
let r = `
|
|
8
8
|
${p(t, "unknown")}
|
|
9
9
|
const tempValue = ${n ?? "any"};
|
|
10
10
|
`, i = "index.ts", a = h(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), c = "any", l = (e) => {
|
|
11
|
-
if (
|
|
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 b = (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() &
|
|
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);
|
|
@@ -30,14 +30,14 @@ var b = (e, t) => {
|
|
|
30
30
|
};
|
|
31
31
|
c = n(t);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
y.forEachChild(e, l);
|
|
34
34
|
};
|
|
35
35
|
return l(o), c;
|
|
36
|
-
},
|
|
36
|
+
}, S = (e, t) => {
|
|
37
37
|
let n = `
|
|
38
38
|
${p(t)}
|
|
39
39
|
type Target = ${e};
|
|
40
|
-
`, r = "index.ts", i = h(r, n), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = a.statements.find((e) =>
|
|
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
|
|
@@ -47,28 +47,28 @@ var b = (e, t) => {
|
|
|
47
47
|
if (r.has(e)) return null;
|
|
48
48
|
let i = e.getFlags();
|
|
49
49
|
if (e.isUnion()) {
|
|
50
|
-
if (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
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 &
|
|
56
|
+
return !(t & y.TypeFlags.Undefined) && !(t & y.TypeFlags.Null);
|
|
57
57
|
}), i = n.length > 0 ? n[0] : e.types[0];
|
|
58
58
|
return l(i, t, r);
|
|
59
59
|
}
|
|
60
|
-
if (i &
|
|
61
|
-
if (i &
|
|
62
|
-
if (i &
|
|
63
|
-
if (i &
|
|
64
|
-
if (i &
|
|
65
|
-
if (i &
|
|
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
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 &
|
|
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) => {
|
|
@@ -82,31 +82,31 @@ var b = (e, t) => {
|
|
|
82
82
|
__typename: "LiteralValue",
|
|
83
83
|
value: l(c, s)
|
|
84
84
|
};
|
|
85
|
-
},
|
|
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 =
|
|
89
|
+
let i = E(e, t, n);
|
|
90
90
|
i && (r = i);
|
|
91
91
|
}), r;
|
|
92
|
-
},
|
|
92
|
+
}, D = (e, t, n) => {
|
|
93
93
|
if (e.start === void 0 || e.length === void 0) return !1;
|
|
94
|
-
let r =
|
|
94
|
+
let r = E(t, e.start, e.start + e.length);
|
|
95
95
|
if (!r) return !1;
|
|
96
|
-
if ((e.code ===
|
|
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 & (
|
|
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 ===
|
|
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
|
-
},
|
|
109
|
+
}, O = (e, t, n) => {
|
|
110
110
|
if (!e?.startingNodeId) return {
|
|
111
111
|
isValid: !1,
|
|
112
112
|
returnType: "void",
|
|
@@ -142,7 +142,7 @@ var b = (e, t) => {
|
|
|
142
142
|
diagnostics: i
|
|
143
143
|
};
|
|
144
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 =
|
|
145
|
+
let t = b(e.messageText, "\n"), n, r = null;
|
|
146
146
|
if (e.start !== void 0) {
|
|
147
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
148
|
for (; (l = s.exec(o)) !== null;) {
|
|
@@ -151,7 +151,7 @@ var b = (e, t) => {
|
|
|
151
151
|
}
|
|
152
152
|
u && (n = u[1] === "null" ? null : u[1], r = parseInt(u[2], 10));
|
|
153
153
|
}
|
|
154
|
-
let i =
|
|
154
|
+
let i = D(e, c, d) ? "warning" : "error";
|
|
155
155
|
return {
|
|
156
156
|
message: t,
|
|
157
157
|
code: e.code,
|
|
@@ -165,12 +165,12 @@ var b = (e, t) => {
|
|
|
165
165
|
returnType: "void",
|
|
166
166
|
diagnostics: f
|
|
167
167
|
};
|
|
168
|
-
},
|
|
169
|
-
let r =
|
|
168
|
+
}, k = (e, t, n) => {
|
|
169
|
+
let r = v(t?.value), i = `
|
|
170
170
|
${p(n)}
|
|
171
171
|
const testValue: ${e} = ${r};
|
|
172
172
|
`, a = "index.ts", o = h(a, i).languageService.getSemanticDiagnostics(a).map((e) => {
|
|
173
|
-
let t =
|
|
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 b = (e, t) => {
|
|
|
182
182
|
returnType: "void",
|
|
183
183
|
diagnostics: o
|
|
184
184
|
};
|
|
185
|
-
},
|
|
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 =
|
|
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
190
|
return: T ? c(d, _, T, Array.from(g.values()), n, !1) : { input: "generic" }
|
|
191
191
|
};
|
|
192
|
-
},
|
|
193
|
-
if (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 b = (e, t) => {
|
|
|
198
198
|
let t = e.getSignatureFromDeclaration(n);
|
|
199
199
|
if (t) return e.getReturnTypeOfSignature(t);
|
|
200
200
|
}
|
|
201
|
-
},
|
|
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
|
-
|
|
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
|
-
},
|
|
209
|
-
if (t?.initializer &&
|
|
210
|
-
},
|
|
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
|
-
},
|
|
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 (
|
|
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 (
|
|
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,119 +239,119 @@ var b = (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 &
|
|
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
|
-
},
|
|
245
|
+
}, L = (e, t, n, r, i, s, u, d) => {
|
|
246
246
|
if (!n) return [];
|
|
247
|
-
let f = c(e, t, e.getAnyType(), Array.from(s.values()), u, !0)
|
|
247
|
+
let f = _(c(e, t, e.getAnyType(), Array.from(s.values()), u, !0));
|
|
248
248
|
return n.map((n, p) => {
|
|
249
|
-
let m = r?.[p], h = m ?
|
|
250
|
-
if (
|
|
251
|
-
let r = c(e, t, n, g, u, !0, h)
|
|
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:
|
|
253
|
+
schema: y.isArrayLiteralExpression(x) ? G(e, t, C, x, g, u, r, f) : J(e, t, C, x, g, u, r, f),
|
|
254
254
|
blockedBy: i.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
let
|
|
257
|
+
let w = a(c(e, t, n, g, u, !0, h));
|
|
258
258
|
return {
|
|
259
|
-
schema: l(
|
|
259
|
+
schema: l(v, w, d[p] ?? !1, f),
|
|
260
260
|
blockedBy: i.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
|
|
261
261
|
};
|
|
262
262
|
});
|
|
263
|
-
},
|
|
264
|
-
if (e.initializer &&
|
|
265
|
-
},
|
|
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
|
-
]),
|
|
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
271
|
if (!t) return;
|
|
272
272
|
let r = o(t);
|
|
273
273
|
if (!r.isUnion() || i(r)) return;
|
|
274
|
-
let a = r.types.filter((e) => (e.flags & (
|
|
274
|
+
let a = r.types.filter((e) => (e.flags & (y.TypeFlags.Undefined | y.TypeFlags.Null)) === 0);
|
|
275
275
|
if (a.length < 2) return;
|
|
276
276
|
let s = e.getTypeAtLocation(n);
|
|
277
|
-
if ((s.flags & (
|
|
277
|
+
if ((s.flags & (y.TypeFlags.Any | y.TypeFlags.Unknown)) === 0) {
|
|
278
278
|
let t = a.find((t) => e.isTypeAssignableTo(s, t));
|
|
279
279
|
if (t) return t;
|
|
280
280
|
}
|
|
281
|
-
if (
|
|
282
|
-
let t =
|
|
281
|
+
if (y.isObjectLiteralExpression(n)) {
|
|
282
|
+
let t = U(n), r, i = 0;
|
|
283
283
|
for (let n of a) {
|
|
284
284
|
let a = t.filter((t) => e.getPropertyOfType(n, t) != null).length;
|
|
285
285
|
a > i && (r = n, i = a);
|
|
286
286
|
}
|
|
287
287
|
return r;
|
|
288
288
|
}
|
|
289
|
-
if (
|
|
290
|
-
},
|
|
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) =>
|
|
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
292
|
return e({
|
|
293
293
|
input: p ? f.input : "list",
|
|
294
294
|
type: (p ? f.type : void 0) ?? t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),
|
|
295
295
|
items: g,
|
|
296
296
|
declaredItems: d(p ? f.items : void 0, u)
|
|
297
|
-
}, l ??
|
|
298
|
-
},
|
|
299
|
-
let u =
|
|
300
|
-
if (
|
|
301
|
-
if (
|
|
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
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) :
|
|
303
|
+
return f ? n(c(t, r, p, o, s, !0), l) : z.has(d.input) ? e({
|
|
304
304
|
...d,
|
|
305
|
-
...
|
|
306
|
-
}, d
|
|
307
|
-
},
|
|
305
|
+
...V(p) ? {} : { type: t.typeToString(p) }
|
|
306
|
+
}, _(d)) : m(d, l);
|
|
307
|
+
}, J = (t, n, r, i, a, s, l, u) => {
|
|
308
308
|
let d = r ? c(t, n, r, a, s, !0) : void 0, f = d?.input === "data";
|
|
309
309
|
if (d && !f && d.input !== "generic") return e({
|
|
310
310
|
...d,
|
|
311
311
|
type: t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i)))
|
|
312
|
-
}, l ?? d
|
|
312
|
+
}, l ?? _(d));
|
|
313
313
|
let p = f ? d.properties ?? {} : {}, h = {};
|
|
314
314
|
for (let [e, t] of Object.entries(p)) h[e] = Array.isArray(t) ? t.map((e) => m(e, u)) : m(t, u);
|
|
315
315
|
let g = [];
|
|
316
316
|
for (let e of i.properties) {
|
|
317
|
-
if (!
|
|
318
|
-
let i =
|
|
319
|
-
h[i] =
|
|
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
320
|
}
|
|
321
|
-
let
|
|
321
|
+
let v = f ? d.required ?? [] : g;
|
|
322
322
|
return e({
|
|
323
323
|
input: "data",
|
|
324
324
|
type: (f ? d.type : void 0) ?? t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),
|
|
325
325
|
properties: h,
|
|
326
|
-
required:
|
|
327
|
-
}, l ??
|
|
328
|
-
},
|
|
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) => {
|
|
329
329
|
let r = e.getPropertyOfType(t, n);
|
|
330
330
|
if (!r) return;
|
|
331
331
|
let i = r.valueDeclaration ?? r.declarations?.[0];
|
|
332
332
|
return i ? e.getTypeOfSymbolAtLocation(r, i) : void 0;
|
|
333
|
-
},
|
|
334
|
-
if ((t.flags &
|
|
333
|
+
}, Z = (e, t, n) => {
|
|
334
|
+
if ((t.flags & y.TypeFlags.TypeParameter) !== 0) {
|
|
335
335
|
let n = t.symbol?.declarations?.[0];
|
|
336
|
-
return n &&
|
|
336
|
+
return n && y.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
|
|
337
337
|
}
|
|
338
|
-
if ((t.flags &
|
|
339
|
-
if ((t.flags &
|
|
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())) {
|
|
340
340
|
let r = t.aliasSymbol?.getName();
|
|
341
341
|
if (r) {
|
|
342
|
-
let t = e.getSymbolsInScope(n,
|
|
342
|
+
let t = e.getSymbolsInScope(n, y.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
|
|
343
343
|
if (t) return e.getTypeOfSymbolAtLocation(t, n);
|
|
344
344
|
}
|
|
345
345
|
return e.getAnyType();
|
|
346
346
|
}
|
|
347
347
|
return t;
|
|
348
|
-
},
|
|
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
349
|
let n = "index.ts", r = `${p(t)}\ntype MyType = ${e}`, i = h(n, r).languageService.getProgram(), a = i?.getSourceFile(n), o = i?.getTypeChecker();
|
|
350
350
|
if (!a || !o) return;
|
|
351
|
-
let s = a.statements.filter((e) =>
|
|
351
|
+
let s = a.statements.filter((e) => y.isTypeAliasDeclaration(e) || y.isInterfaceDeclaration(e) || y.isClassDeclaration(e)).pop();
|
|
352
352
|
if (!s) return;
|
|
353
353
|
let l = o.getTypeAtLocation(s);
|
|
354
354
|
if (l) return c(o, void 0, l, [], [], !1);
|
|
355
355
|
};
|
|
356
356
|
//#endregion
|
|
357
|
-
export { t as CUSTOM_INPUT_IDENTIFIERS, d as declaredItemsOf, m as declaredSchema, n as genericNodeSchema,
|
|
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 };
|
package/dist/server.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-
|
|
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-
|
|
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
|
|
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
|
*
|
|
@@ -24,11 +25,12 @@ import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphq
|
|
|
24
25
|
* @param {ts.Type} paramType - The target parameter type used to filter compatible
|
|
25
26
|
* functions. Only functions with return types assignable to this type are included
|
|
26
27
|
*
|
|
27
|
-
* @returns {
|
|
28
|
-
* specified parameter type,
|
|
29
|
-
*
|
|
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
|
|
30
32
|
*
|
|
31
33
|
* @example
|
|
32
34
|
* const compatibleNodes = getNodes(checker, funcDecls, funcDefs, stringType);
|
|
33
35
|
*/
|
|
34
|
-
export declare const getNodes: (checker: ts.TypeChecker, functionDeclarations: ts.FunctionDeclaration[], functions: FunctionDefinition[], paramType: ts.Type) =>
|
|
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 {
|
|
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
|
|
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[]) =>
|
|
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
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { default as ts, FunctionDeclaration } from 'typescript';
|
|
2
|
-
import { FunctionDefinition
|
|
2
|
+
import { FunctionDefinition } from '@code0-tech/sagittarius-graphql-types';
|
|
3
|
+
import { SuggestionCandidate, SuggestionCertainty, SuggestionValue } from './suggestion.util';
|
|
4
|
+
export type { SuggestionCandidate, SuggestionCertainty, SuggestionMatch, SuggestionMatchReason, SuggestionValue, } from './suggestion.util';
|
|
3
5
|
/**
|
|
4
6
|
* Maps a data type identifier to a dedicated input kind.
|
|
5
7
|
*
|
|
@@ -50,7 +52,27 @@ export interface Input {
|
|
|
50
52
|
*/
|
|
51
53
|
type?: string;
|
|
52
54
|
/** Array of suggested values (functions, references, or literals) */
|
|
53
|
-
suggestions?:
|
|
55
|
+
suggestions?: SuggestionValue[];
|
|
56
|
+
/**
|
|
57
|
+
* How certainly each entry of `suggestions` produces this slot's type,
|
|
58
|
+
* index-aligned with it and of the same length — `suggestions[i]` is
|
|
59
|
+
* described by `suggestionCertainty[i]`.
|
|
60
|
+
*
|
|
61
|
+
* A suggestion is `exact` when its own type is assignable to the slot's, and
|
|
62
|
+
* `possible` when the match was only reached by weakening one of the two
|
|
63
|
+
* sides: a generic return matched through its constraint, an `any` that fits
|
|
64
|
+
* everything, a union whose branches do not all fit, a value that may be
|
|
65
|
+
* nullish where the slot is not (see {@link SuggestionCertainty}).
|
|
66
|
+
*
|
|
67
|
+
* Both kinds are listed — a `possible` candidate is often the one the user
|
|
68
|
+
* wants — but the split answers two questions the flat list cannot: whether a
|
|
69
|
+
* slot has *dedicated* producers (which a consumer may want to offer ahead of
|
|
70
|
+
* building a value by hand), and whether picking one is the case that may
|
|
71
|
+
* need a cast to type-check.
|
|
72
|
+
*
|
|
73
|
+
* Present exactly when `suggestions` is.
|
|
74
|
+
*/
|
|
75
|
+
suggestionCertainty?: SuggestionCertainty[];
|
|
54
76
|
}
|
|
55
77
|
/**
|
|
56
78
|
* Represents a generic input type with no specific structure.
|
|
@@ -274,9 +296,10 @@ export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDecla
|
|
|
274
296
|
* concrete value must never surface one; the resolved element types (via
|
|
275
297
|
* `items`) are kept, and the `list-file` `mimetype` is dropped because a plain
|
|
276
298
|
* list has no such field.
|
|
277
|
-
* - Drops an empty `suggestions` array
|
|
278
|
-
* enabled and therefore always carry the
|
|
279
|
-
* rest of the pipeline omits
|
|
299
|
+
* - Drops an empty `suggestions` array (and its `suggestionCertainty` twin). Node
|
|
300
|
+
* schemas are built with suggestions enabled and therefore always carry the
|
|
301
|
+
* keys — even when empty — whereas the rest of the pipeline omits them
|
|
302
|
+
* entirely when there are none.
|
|
280
303
|
*
|
|
281
304
|
* The function-side schema still drives the final input kind in
|
|
282
305
|
* {@link mergeSchemas}.
|
|
@@ -293,13 +316,17 @@ export declare const normalizeNodeSchema: (schema: Schema) => Schema;
|
|
|
293
316
|
*/
|
|
294
317
|
export declare const nonNullishType: (type: ts.Type) => ts.Type;
|
|
295
318
|
/**
|
|
296
|
-
* Sets a schema's
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
319
|
+
* Sets a schema's suggestions to the given candidates, dropping both the
|
|
320
|
+
* `suggestions` key and its `suggestionCertainty` twin entirely when the set is
|
|
321
|
+
* empty or missing. Suggestion-carrying schemas are built with the keys always
|
|
322
|
+
* present (empty arrays when nothing matched), whereas the rest of the pipeline
|
|
323
|
+
* omits them — so every schema that is spread into a result passes through here
|
|
324
|
+
* instead of relying on the spread.
|
|
325
|
+
*
|
|
326
|
+
* Taking candidates rather than two parallel arrays is what keeps the pair
|
|
327
|
+
* aligned: there is no call site that can set one without the other.
|
|
301
328
|
*/
|
|
302
|
-
export declare const withSuggestions: <T extends Schema>(schema: T,
|
|
329
|
+
export declare const withSuggestions: <T extends Schema>(schema: T, candidates: SuggestionCandidate[] | undefined) => T;
|
|
303
330
|
/**
|
|
304
331
|
* A declared (function-side) schema kept as the answer for its position, because
|
|
305
332
|
* the node side has no counterpart to merge into it — e.g. a property the entered
|
|
@@ -311,7 +338,7 @@ export declare const withSuggestions: <T extends Schema>(schema: T, suggestions:
|
|
|
311
338
|
* (see {@link genericNodeSchema}). Empty suggestion arrays are dropped so the
|
|
312
339
|
* result follows the same convention as every other schema.
|
|
313
340
|
*/
|
|
314
|
-
export declare const declaredSchema: (schema: Schema, anySuggestions?:
|
|
341
|
+
export declare const declaredSchema: (schema: Schema, anySuggestions?: SuggestionCandidate[] | undefined) => Schema;
|
|
315
342
|
/**
|
|
316
343
|
* Treats a node-side schema as sitting in a fully generic ("accepts anything")
|
|
317
344
|
* slot: the declared type constrains nothing here, so the value keeps its shape
|
|
@@ -338,9 +365,9 @@ export declare const declaredSchema: (schema: Schema, anySuggestions?: Input["su
|
|
|
338
365
|
* This is what {@link ListInput.declaredItems} carries, and it never depends on the
|
|
339
366
|
* entered value.
|
|
340
367
|
*/
|
|
341
|
-
export declare const declaredItemsOf: (functionItems: Schema[] | undefined, anySuggestions?:
|
|
342
|
-
export declare const genericNodeSchema: (schema: Schema, anySuggestions?:
|
|
343
|
-
export declare const mergeSchemas: (functionSchema: Schema | undefined, nodeSchema: Schema, valueProvided?: boolean, anySuggestions?:
|
|
368
|
+
export declare const declaredItemsOf: (functionItems: Schema[] | undefined, anySuggestions?: SuggestionCandidate[] | undefined) => Schema[];
|
|
369
|
+
export declare const genericNodeSchema: (schema: Schema, anySuggestions?: SuggestionCandidate[] | undefined, overrideRoot?: boolean) => Schema;
|
|
370
|
+
export declare const mergeSchemas: (functionSchema: Schema | undefined, nodeSchema: Schema, valueProvided?: boolean, anySuggestions?: SuggestionCandidate[] | undefined, topLevel?: boolean) => Schema;
|
|
344
371
|
/**
|
|
345
372
|
* Checks whether a union's members are the *options of one input* rather than
|
|
346
373
|
* alternative inputs: a string/number literal union (`'GET' | 'POST' | …`, which
|