@code0-tech/triangulum 0.37.1 → 0.37.2
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 +149 -127
- package/dist/schema/getSignatureSchema.d.ts +9 -3
- package/dist/server.cjs +1 -1
- package/dist/server.js +1 -1
- package/dist/util/nodes.util.d.ts +9 -2
- package/dist/util/schema.util.d.ts +94 -1
- package/dist/{utils-CAOAm6k-.js → utils-DSmUMJiO.js} +214 -162
- package/dist/utils-euztPiZI.cjs +45 -0
- package/package.json +1 -1
- package/dist/utils-oMAOCPrM.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-euztPiZI.cjs");let t=require("typescript");t=e.y(t,1);var n=(n,r)=>{let i=e.v(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.v(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.
|
|
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).suggestions;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.l(n,r,i,m,c,!0,p).suggestions;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=(e,t)=>!e||e.input===`generic`?t:e.suggestions,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)}},u.suggestions):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??u.suggestions);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 {
|
|
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 _ } from "./utils-DSmUMJiO.js";
|
|
2
|
+
import v, { flattenDiagnosticMessageText as y } from "typescript";
|
|
3
3
|
//#region src/extraction/getTypeFromValue.ts
|
|
4
|
-
var
|
|
5
|
-
let n =
|
|
4
|
+
var b = (e, t) => {
|
|
5
|
+
let n = _(e?.value);
|
|
6
6
|
if (!n) return "any";
|
|
7
7
|
let r = `
|
|
8
|
-
${
|
|
8
|
+
${p(t, "unknown")}
|
|
9
9
|
const tempValue = ${n ?? "any"};
|
|
10
|
-
`, i = "index.ts", a =
|
|
11
|
-
if (
|
|
10
|
+
`, i = "index.ts", a = h(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), c = "any", l = (e) => {
|
|
11
|
+
if (v.isVariableDeclaration(e) && e.name.getText() === "tempValue") {
|
|
12
12
|
let t = s.getTypeAtLocation(e), n = (t) => {
|
|
13
13
|
if (t.isUnion()) {
|
|
14
14
|
let e = t.types.map(n);
|
|
@@ -18,7 +18,7 @@ var h = (e, t) => {
|
|
|
18
18
|
let e = t.typeArguments || [], r = e.length > 0 ? n(e[0]) : "any";
|
|
19
19
|
return e[0]?.isUnion() ? `(${r})[]` : `${r}[]`;
|
|
20
20
|
}
|
|
21
|
-
if (t.getFlags() &
|
|
21
|
+
if (t.getFlags() & v.TypeFlags.Object || t.isClassOrInterface()) {
|
|
22
22
|
let r = s.getPropertiesOfType(t);
|
|
23
23
|
if (r.length > 0) return `{ ${r.map((t) => {
|
|
24
24
|
let r = s.getTypeOfSymbolAtLocation(t, e);
|
|
@@ -28,85 +28,85 @@ var h = (e, t) => {
|
|
|
28
28
|
let r = s.getBaseTypeOfLiteralType(t);
|
|
29
29
|
return s.typeToString(r, e);
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
c = n(t);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
v.forEachChild(e, l);
|
|
34
34
|
};
|
|
35
|
-
return
|
|
36
|
-
},
|
|
35
|
+
return l(o), c;
|
|
36
|
+
}, x = (e, t) => {
|
|
37
37
|
let n = `
|
|
38
|
-
${
|
|
38
|
+
${p(t)}
|
|
39
39
|
type Target = ${e};
|
|
40
|
-
`, r = "index.ts", i =
|
|
40
|
+
`, r = "index.ts", i = h(r, n), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = a.statements.find((e) => v.isTypeAliasDeclaration(e) && e.name.text === "Target");
|
|
41
41
|
if (!s) return {
|
|
42
42
|
__typename: "LiteralValue",
|
|
43
43
|
value: null
|
|
44
44
|
};
|
|
45
|
-
let c = o.getTypeAtLocation(s.type),
|
|
45
|
+
let c = o.getTypeAtLocation(s.type), l = (e, t, n = /* @__PURE__ */ new Set()) => {
|
|
46
46
|
let r = new Set(n);
|
|
47
47
|
if (r.has(e)) return null;
|
|
48
48
|
let i = e.getFlags();
|
|
49
49
|
if (e.isUnion()) {
|
|
50
|
-
if (t.type,
|
|
50
|
+
if (t.type, v.isTypeAliasDeclaration(t) && t.type && v.isUnionTypeNode(t.type)) {
|
|
51
51
|
let e = o.getTypeFromTypeNode(t.type.types[0]);
|
|
52
|
-
return
|
|
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 & v.TypeFlags.Undefined) && !(t & v.TypeFlags.Null);
|
|
57
57
|
}), i = n.length > 0 ? n[0] : e.types[0];
|
|
58
|
-
return
|
|
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 & v.TypeFlags.StringLiteral) return e.value;
|
|
61
|
+
if (i & v.TypeFlags.String) return "";
|
|
62
|
+
if (i & v.TypeFlags.NumberLiteral) return e.value;
|
|
63
|
+
if (i & v.TypeFlags.Number) return 0;
|
|
64
|
+
if (i & v.TypeFlags.BooleanLiteral) return e.intrinsicName === "true";
|
|
65
|
+
if (i & v.TypeFlags.Boolean) return !1;
|
|
66
66
|
if (o.isArrayType(e)) {
|
|
67
67
|
r.add(e);
|
|
68
|
-
let n = e.typeArguments?.[0] || o.getAnyType(), i =
|
|
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 & v.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()] =
|
|
76
|
+
i && (n[e.getName()] = l(i, a || t, r));
|
|
77
77
|
}), n;
|
|
78
78
|
}
|
|
79
79
|
return null;
|
|
80
80
|
};
|
|
81
81
|
return {
|
|
82
82
|
__typename: "LiteralValue",
|
|
83
|
-
value:
|
|
83
|
+
value: l(c, s)
|
|
84
84
|
};
|
|
85
|
-
},
|
|
85
|
+
}, S = 2345, C = 2322, w = 2339, T = (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 = T(e, t, n);
|
|
90
90
|
i && (r = i);
|
|
91
91
|
}), r;
|
|
92
|
-
},
|
|
92
|
+
}, E = (e, t, n) => {
|
|
93
93
|
if (e.start === void 0 || e.length === void 0) return !1;
|
|
94
|
-
let r =
|
|
94
|
+
let r = T(t, e.start, e.start + e.length);
|
|
95
95
|
if (!r) return !1;
|
|
96
|
-
if ((e.code ===
|
|
96
|
+
if ((e.code === S || e.code === C) && v.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 & (v.TypeFlags.Null | v.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
|
|
101
101
|
}
|
|
102
|
-
if (e.code ===
|
|
102
|
+
if (e.code === w && v.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
|
+
}, D = (e, t, n) => {
|
|
110
110
|
if (!e?.startingNodeId) return {
|
|
111
111
|
isValid: !1,
|
|
112
112
|
returnType: "void",
|
|
@@ -141,17 +141,17 @@ var h = (e, t) => {
|
|
|
141
141
|
returnType: "void",
|
|
142
142
|
diagnostics: i
|
|
143
143
|
};
|
|
144
|
-
let a =
|
|
145
|
-
let t =
|
|
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 = y(e.messageText, "\n"), n, r = null;
|
|
146
146
|
if (e.start !== void 0) {
|
|
147
|
-
let t =
|
|
148
|
-
for (; (
|
|
149
|
-
let t = i +
|
|
150
|
-
t <= e.start && t > d && (d = t, u =
|
|
147
|
+
let t = c.getFullText(), i = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(i, a), s = /\/\* @pos ([^ ]+) (\d+|null) \*\//g, l, u = null, d = -1;
|
|
148
|
+
for (; (l = s.exec(o)) !== null;) {
|
|
149
|
+
let t = i + l.index + l[0].length;
|
|
150
|
+
t <= e.start && t > d && (d = t, u = l);
|
|
151
151
|
}
|
|
152
152
|
u && (n = u[1] === "null" ? null : u[1], r = parseInt(u[2], 10));
|
|
153
153
|
}
|
|
154
|
-
let i =
|
|
154
|
+
let i = E(e, c, d) ? "warning" : "error";
|
|
155
155
|
return {
|
|
156
156
|
message: t,
|
|
157
157
|
code: e.code,
|
|
@@ -161,16 +161,16 @@ var h = (e, t) => {
|
|
|
161
161
|
};
|
|
162
162
|
}).filter((e) => e !== null);
|
|
163
163
|
return {
|
|
164
|
-
isValid: !
|
|
164
|
+
isValid: !f.some((e) => e?.severity === "error"),
|
|
165
165
|
returnType: "void",
|
|
166
|
-
diagnostics:
|
|
166
|
+
diagnostics: f
|
|
167
167
|
};
|
|
168
|
-
},
|
|
169
|
-
let r =
|
|
170
|
-
${
|
|
168
|
+
}, O = (e, t, n) => {
|
|
169
|
+
let r = _(t?.value), i = `
|
|
170
|
+
${p(n)}
|
|
171
171
|
const testValue: ${e} = ${r};
|
|
172
|
-
`, a = "index.ts", o =
|
|
173
|
-
let t =
|
|
172
|
+
`, a = "index.ts", o = h(a, i).languageService.getSemanticDiagnostics(a).map((e) => {
|
|
173
|
+
let t = v.flattenDiagnosticMessageText(e.messageText, "\n"), n = t.includes("not assignable to parameter of type") && (t.includes("'{}'") || t.includes("undefined")) || t.includes("not assignable to type 'undefined'") || t.includes("not assignable to type 'void'") || t.includes("may be a mistake because neither type sufficiently overlaps");
|
|
174
174
|
return {
|
|
175
175
|
message: t,
|
|
176
176
|
code: e.code,
|
|
@@ -182,15 +182,15 @@ var h = (e, t) => {
|
|
|
182
182
|
returnType: "void",
|
|
183
183
|
diagnostics: o
|
|
184
184
|
};
|
|
185
|
-
},
|
|
186
|
-
let
|
|
185
|
+
}, k = (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 = j(l), _ = M(l).get(m), y = g.get(p), b = N(d, _), x = P(d, y, _), S = b?.map((e, t) => (e.flags & v.TypeFlags.Undefined) === 0 ? e : x?.[t] ?? e), C = (f?.parameters?.nodes ?? []).map((e) => e?.value != null), w = I(d, _, S, x, F(y, b, C), r ? g : /* @__PURE__ */ new Map(), r ? n : [], C), T = A(d, _, y);
|
|
187
187
|
return {
|
|
188
188
|
nodeId: r,
|
|
189
189
|
parameters: w,
|
|
190
|
-
return:
|
|
190
|
+
return: T ? c(d, _, T, Array.from(g.values()), n, !1) : { input: "generic" }
|
|
191
191
|
};
|
|
192
|
-
},
|
|
193
|
-
if (t?.initializer &&
|
|
192
|
+
}, A = (e, t, n) => {
|
|
193
|
+
if (t?.initializer && v.isCallExpression(t.initializer)) {
|
|
194
194
|
let n = e.getResolvedSignature(t.initializer);
|
|
195
195
|
if (n) return e.getReturnTypeOfSignature(n);
|
|
196
196
|
}
|
|
@@ -198,31 +198,31 @@ var h = (e, t) => {
|
|
|
198
198
|
let t = e.getSignatureFromDeclaration(n);
|
|
199
199
|
if (t) return e.getReturnTypeOfSignature(t);
|
|
200
200
|
}
|
|
201
|
-
},
|
|
201
|
+
}, j = (e) => new Map(e.statements.filter(v.isFunctionDeclaration).map((e) => [e.name.getText(), e])), M = (e) => {
|
|
202
202
|
let t = [];
|
|
203
203
|
return e.statements.forEach((e) => {
|
|
204
204
|
e.forEachChild(function e(n) {
|
|
205
|
-
|
|
205
|
+
v.isVariableDeclaration(n) && (n.parent.flags & v.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
|
+
}, N = (e, t) => {
|
|
209
|
+
if (t?.initializer && v.isCallExpression(t.initializer)) return e.getResolvedSignature(t.initializer)?.parameters.map((n) => e.getTypeOfSymbolAtLocation(n, t.initializer));
|
|
210
|
+
}, P = (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
|
+
}, F = (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 (v.isTypeReferenceNode(i) && v.isIdentifier(i.typeName)) {
|
|
222
222
|
let e = i.typeName.text;
|
|
223
223
|
r.includes(e) && n.add(e);
|
|
224
224
|
}
|
|
225
|
-
if (
|
|
225
|
+
if (v.isTypeReferenceNode(e.type) && v.isIdentifier(e.type.typeName)) {
|
|
226
226
|
let t = e.type.typeName.text;
|
|
227
227
|
r.includes(t) && n.add(t);
|
|
228
228
|
}
|
|
@@ -239,97 +239,119 @@ var h = (e, t) => {
|
|
|
239
239
|
if (n[e.dependsOnIndex]) return !1;
|
|
240
240
|
let r = t[e.parameterIndex];
|
|
241
241
|
if (!r) return !0;
|
|
242
|
-
let i = (r.flags &
|
|
242
|
+
let i = (r.flags & v.TypeFlags.Null) !== 0, a = (r.flags & v.TypeFlags.Undefined) !== 0;
|
|
243
243
|
return i || a;
|
|
244
244
|
}) : a;
|
|
245
|
-
},
|
|
246
|
-
if (!
|
|
247
|
-
let
|
|
248
|
-
return
|
|
249
|
-
let m =
|
|
250
|
-
if (
|
|
251
|
-
let
|
|
245
|
+
}, I = (e, t, n, r, i, s, u, d) => {
|
|
246
|
+
if (!n) return [];
|
|
247
|
+
let f = c(e, t, e.getAnyType(), Array.from(s.values()), u, !0).suggestions;
|
|
248
|
+
return n.map((n, p) => {
|
|
249
|
+
let m = r?.[p], h = m ? X(e, m, t) : void 0, g = Array.from(s.values()), _ = m ? c(e, t, m, g, u, !0) : void 0, y = V(e, o(n)), b = L(t, p), x = b ? U(e, m, b) : void 0, S = x ?? m;
|
|
250
|
+
if (b && (v.isArrayLiteralExpression(b) || v.isObjectLiteralExpression(b) && (y || x != null && V(e, x)))) {
|
|
251
|
+
let r = c(e, t, n, g, u, !0, h).suggestions;
|
|
252
252
|
return {
|
|
253
|
-
schema:
|
|
254
|
-
blockedBy:
|
|
253
|
+
schema: v.isArrayLiteralExpression(b) ? W(e, t, S, b, g, u, r, f) : q(e, t, S, b, g, u, r, f),
|
|
254
|
+
blockedBy: i.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
let
|
|
257
|
+
let C = a(c(e, t, n, g, u, !0, h));
|
|
258
258
|
return {
|
|
259
|
-
schema:
|
|
260
|
-
blockedBy:
|
|
259
|
+
schema: l(_, C, d[p] ?? !1, f),
|
|
260
|
+
blockedBy: i.filter((e) => e.parameterIndex === p).map((e) => e.dependsOnIndex)
|
|
261
261
|
};
|
|
262
262
|
});
|
|
263
|
-
},
|
|
264
|
-
if (e.initializer &&
|
|
265
|
-
},
|
|
263
|
+
}, L = (e, t) => {
|
|
264
|
+
if (e.initializer && v.isCallExpression(e.initializer)) return e.initializer.arguments[t];
|
|
265
|
+
}, R = /* @__PURE__ */ new Set([
|
|
266
266
|
"select",
|
|
267
267
|
"boolean",
|
|
268
268
|
"number",
|
|
269
269
|
"text"
|
|
270
|
-
]),
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (p.isObjectLiteralExpression(r)) return I(e, t, n, r, i, a, void 0, o);
|
|
281
|
-
let c = n ? u(e, t, n, i, a, !0) : void 0, l = !c || c.input === "generic", d = e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r));
|
|
282
|
-
return l ? s(u(e, t, d, i, a, !0), o) : N.has(c.input) ? {
|
|
283
|
-
...c,
|
|
284
|
-
type: e.typeToString(d)
|
|
285
|
-
} : c;
|
|
286
|
-
}, I = (e, t, n, r, i, a, o, s) => {
|
|
287
|
-
let c = n ? u(e, t, n, i, a, !1) : void 0, l = c?.input === "data";
|
|
288
|
-
if (c && !l && c.input !== "generic") return {
|
|
289
|
-
...c,
|
|
290
|
-
type: e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
|
|
291
|
-
...o?.length ? { suggestions: o } : {}
|
|
292
|
-
};
|
|
293
|
-
let d = {}, f = [];
|
|
294
|
-
for (let o of r.properties) {
|
|
295
|
-
if (!p.isPropertyAssignment(o)) continue;
|
|
296
|
-
let r = p.isStringLiteralLike(o.name) || p.isNumericLiteral(o.name) ? o.name.text : o.name.getText();
|
|
297
|
-
d[r] = F(e, t, l ? L(e, n, r) : void 0, o.initializer, i, a, s), f.push(r);
|
|
270
|
+
]), z = v.TypeFlags.Null | v.TypeFlags.Undefined | v.TypeFlags.Void | v.TypeFlags.Never, B = (e) => (e.flags & z) !== 0, V = (e, t) => (t.flags & v.TypeFlags.Object) !== 0 && !e.isArrayType(t) && !e.isTupleType(t), H = (e) => e.properties.filter(v.isPropertyAssignment).map((e) => J(e)), U = (e, t, n) => {
|
|
271
|
+
if (!t) return;
|
|
272
|
+
let r = o(t);
|
|
273
|
+
if (!r.isUnion() || i(r)) return;
|
|
274
|
+
let a = r.types.filter((e) => (e.flags & (v.TypeFlags.Undefined | v.TypeFlags.Null)) === 0);
|
|
275
|
+
if (a.length < 2) return;
|
|
276
|
+
let s = e.getTypeAtLocation(n);
|
|
277
|
+
if ((s.flags & (v.TypeFlags.Any | v.TypeFlags.Unknown)) === 0) {
|
|
278
|
+
let t = a.find((t) => e.isTypeAssignableTo(s, t));
|
|
279
|
+
if (t) return t;
|
|
298
280
|
}
|
|
299
|
-
|
|
281
|
+
if (v.isObjectLiteralExpression(n)) {
|
|
282
|
+
let t = H(n), r, i = 0;
|
|
283
|
+
for (let n of a) {
|
|
284
|
+
let a = t.filter((t) => e.getPropertyOfType(n, t) != null).length;
|
|
285
|
+
a > i && (r = n, i = a);
|
|
286
|
+
}
|
|
287
|
+
return r;
|
|
288
|
+
}
|
|
289
|
+
if (v.isArrayLiteralExpression(n)) return a.find((t) => e.isArrayType(t) || e.isTupleType(t));
|
|
290
|
+
}, W = (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) => K(t, n, h, e, a, s, u));
|
|
292
|
+
return e({
|
|
293
|
+
input: p ? f.input : "list",
|
|
294
|
+
type: (p ? f.type : void 0) ?? t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),
|
|
295
|
+
items: g,
|
|
296
|
+
declaredItems: d(p ? f.items : void 0, u)
|
|
297
|
+
}, l ?? G(f, u));
|
|
298
|
+
}, G = (e, t) => !e || e.input === "generic" ? t : e.suggestions, K = (t, r, i, a, o, s, l) => {
|
|
299
|
+
let u = U(t, i, a) ?? i;
|
|
300
|
+
if (v.isArrayLiteralExpression(a)) return W(t, r, u, a, o, s, void 0, l);
|
|
301
|
+
if (v.isObjectLiteralExpression(a)) return q(t, r, u, a, o, s, void 0, l);
|
|
302
|
+
let d = u ? c(t, r, u, o, s, !0) : void 0, f = !d || d.input === "generic", p = t.getBaseTypeOfLiteralType(t.getTypeAtLocation(a));
|
|
303
|
+
return f ? n(c(t, r, p, o, s, !0), l) : R.has(d.input) ? e({
|
|
304
|
+
...d,
|
|
305
|
+
...B(p) ? {} : { type: t.typeToString(p) }
|
|
306
|
+
}, d.suggestions) : m(d, l);
|
|
307
|
+
}, q = (t, n, r, i, a, s, l, u) => {
|
|
308
|
+
let d = r ? c(t, n, r, a, s, !0) : void 0, f = d?.input === "data";
|
|
309
|
+
if (d && !f && d.input !== "generic") return e({
|
|
310
|
+
...d,
|
|
311
|
+
type: t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i)))
|
|
312
|
+
}, l ?? d.suggestions);
|
|
313
|
+
let p = f ? d.properties ?? {} : {}, h = {};
|
|
314
|
+
for (let [e, t] of Object.entries(p)) h[e] = Array.isArray(t) ? t.map((e) => m(e, u)) : m(t, u);
|
|
315
|
+
let g = [];
|
|
316
|
+
for (let e of i.properties) {
|
|
317
|
+
if (!v.isPropertyAssignment(e)) continue;
|
|
318
|
+
let i = J(e);
|
|
319
|
+
h[i] = K(t, n, f ? Y(t, o(r), i) : void 0, e.initializer, a, s, u), g.push(i);
|
|
320
|
+
}
|
|
321
|
+
let _ = f ? d.required ?? [] : g;
|
|
322
|
+
return e({
|
|
300
323
|
input: "data",
|
|
301
|
-
type: (
|
|
302
|
-
properties:
|
|
303
|
-
required:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}, L = (e, t, n) => {
|
|
324
|
+
type: (f ? d.type : void 0) ?? t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),
|
|
325
|
+
properties: h,
|
|
326
|
+
required: _
|
|
327
|
+
}, l ?? G(d, u));
|
|
328
|
+
}, J = (e) => v.isStringLiteralLike(e.name) || v.isNumericLiteral(e.name) ? e.name.text : e.name.getText(), Y = (e, t, n) => {
|
|
307
329
|
let r = e.getPropertyOfType(t, n);
|
|
308
330
|
if (!r) return;
|
|
309
331
|
let i = r.valueDeclaration ?? r.declarations?.[0];
|
|
310
332
|
return i ? e.getTypeOfSymbolAtLocation(r, i) : void 0;
|
|
311
|
-
},
|
|
312
|
-
if ((t.flags &
|
|
333
|
+
}, X = (e, t, n) => {
|
|
334
|
+
if ((t.flags & v.TypeFlags.TypeParameter) !== 0) {
|
|
313
335
|
let n = t.symbol?.declarations?.[0];
|
|
314
|
-
return n &&
|
|
336
|
+
return n && v.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
|
|
315
337
|
}
|
|
316
|
-
if ((t.flags &
|
|
317
|
-
if ((t.flags &
|
|
338
|
+
if ((t.flags & v.TypeFlags.Conditional) !== 0) return e.getBaseConstraintOfType(t) ?? e.getAnyType();
|
|
339
|
+
if ((t.flags & v.TypeFlags.Object) !== 0 && Z(t, e, /* @__PURE__ */ new Set())) {
|
|
318
340
|
let r = t.aliasSymbol?.getName();
|
|
319
341
|
if (r) {
|
|
320
|
-
let t = e.getSymbolsInScope(n,
|
|
342
|
+
let t = e.getSymbolsInScope(n, v.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
|
|
321
343
|
if (t) return e.getTypeOfSymbolAtLocation(t, n);
|
|
322
344
|
}
|
|
323
345
|
return e.getAnyType();
|
|
324
346
|
}
|
|
325
347
|
return t;
|
|
326
|
-
},
|
|
327
|
-
let n = "index.ts", r = `${
|
|
348
|
+
}, Z = (e, t, n) => !n.has(e) && (n.add(e), !!((e.flags & v.TypeFlags.TypeParameter) !== 0 || (e.flags & v.TypeFlags.Object) !== 0 && (t.getTypeArguments(e).some((e) => Z(e, t, n)) || e.aliasTypeArguments?.some((e) => Z(e, t, n))))), Q = (e, t = []) => {
|
|
349
|
+
let n = "index.ts", r = `${p(t)}\ntype MyType = ${e}`, i = h(n, r).languageService.getProgram(), a = i?.getSourceFile(n), o = i?.getTypeChecker();
|
|
328
350
|
if (!a || !o) return;
|
|
329
|
-
let s = a.statements.filter((e) =>
|
|
351
|
+
let s = a.statements.filter((e) => v.isTypeAliasDeclaration(e) || v.isInterfaceDeclaration(e) || v.isClassDeclaration(e)).pop();
|
|
330
352
|
if (!s) return;
|
|
331
|
-
let
|
|
332
|
-
if (
|
|
353
|
+
let l = o.getTypeAtLocation(s);
|
|
354
|
+
if (l) return c(o, void 0, l, [], [], !1);
|
|
333
355
|
};
|
|
334
356
|
//#endregion
|
|
335
|
-
export {
|
|
357
|
+
export { t as CUSTOM_INPUT_IDENTIFIERS, d as declaredItemsOf, m as declaredSchema, n as genericNodeSchema, D as getFlowValidation, c as getSchema, k as getSignatureSchema, b as getTypeFromValue, Q as getTypeSchema, x as getValueFromType, O as getValueValidation, g as isCustomInputIdentifier, r as isCustomInputKind, i as isOptionsUnion, f as isSubFlow, l as mergeSchemas, o as nonNullishType, a as normalizeNodeSchema, e as withSuggestions };
|
|
@@ -8,9 +8,15 @@ export interface NodeSchema {
|
|
|
8
8
|
/**
|
|
9
9
|
* The schema definition for this node parameter. Produced by merging the
|
|
10
10
|
* function-declared parameter schema with the node's concrete value schema:
|
|
11
|
-
* the function schema drives the structural shape
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* the function schema drives the structural shape and the suggestions of every
|
|
12
|
+
* nested position, the node schema contributes the parameter's own suggestion
|
|
13
|
+
* scope plus the shape and `type` the entered value implies, and a generic
|
|
14
|
+
* function parameter falls back to the node's concrete shape (never as a
|
|
15
|
+
* select).
|
|
16
|
+
*
|
|
17
|
+
* Which suggestions a position offers therefore depends on the declared type
|
|
18
|
+
* alone — entering a value changes how many items/properties are rendered and
|
|
19
|
+
* each position's `type`, never the set of candidates it offers.
|
|
14
20
|
*/
|
|
15
21
|
schema: Schema;
|
|
16
22
|
/** Array of parameter indices that must be resolved before this parameter */
|
package/dist/server.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-euztPiZI.cjs");let t=require("typescript");t=e.y(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-DSmUMJiO.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
|
|
@@ -8,6 +8,13 @@ import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphq
|
|
|
8
8
|
* are assignable to the specified parameter type. Each node function is enriched with
|
|
9
9
|
* metadata including function definitions and parameter information.
|
|
10
10
|
*
|
|
11
|
+
* A callable (sub-flow) parameter is no exception: it is matched by the same
|
|
12
|
+
* rule as every other slot — a function qualifies when the value it produces is
|
|
13
|
+
* assignable to the slot's type. Such a node is offered alongside the
|
|
14
|
+
* {@link getSubFlows} candidates, which bind an existing function as the
|
|
15
|
+
* sub-flow itself; the two kinds are told apart by their `__typename` and may
|
|
16
|
+
* both be present for the same function definition.
|
|
17
|
+
*
|
|
11
18
|
* @param {ts.TypeChecker} checker - The TypeScript type checker instance used to analyze
|
|
12
19
|
* type information and verify type compatibility
|
|
13
20
|
* @param {ts.FunctionDeclaration[]} functionDeclarations - Array of TypeScript function
|
|
@@ -18,8 +25,8 @@ import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphq
|
|
|
18
25
|
* functions. Only functions with return types assignable to this type are included
|
|
19
26
|
*
|
|
20
27
|
* @returns {NodeFunction[]} Array of node functions that are compatible with the
|
|
21
|
-
* specified parameter type
|
|
22
|
-
*
|
|
28
|
+
* specified parameter type, or an empty array if no compatible
|
|
29
|
+
* functions are found
|
|
23
30
|
*
|
|
24
31
|
* @example
|
|
25
32
|
* const compatibleNodes = getNodes(checker, funcDecls, funcDefs, stringType);
|