@code0-tech/triangulum 0.33.0 → 0.35.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 +4 -4
- package/dist/index.js +160 -100
- package/dist/server.cjs +2 -2
- package/dist/server.js +2 -2
- package/dist/util/schema.util.d.ts +54 -8
- package/dist/{utils-DHs93w48.js → utils-CAOAm6k-.js} +269 -154
- package/dist/utils-oMAOCPrM.cjs +45 -0
- package/package.json +2 -2
- package/dist/utils-9-y-1aUm.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-oMAOCPrM.cjs");let t=require("typescript");t=e.m(t,1);var n=(n,r)=>{let i=e.p(n?.value);if(!i)return`any`;let a=`
|
|
2
2
|
${e.r(r,`unknown`)}
|
|
3
3
|
const tempValue = ${i??`any`};
|
|
4
4
|
`,o=`index.ts`,s=e.t(o,a),c=s.getSourceFile(o),l=s.languageService.getProgram().getTypeChecker(),u=`any`,d=e=>{if(t.default.isVariableDeclaration(e)&&e.name.getText()===`tempValue`){let n=l.getTypeAtLocation(e),r=n=>{if(n.isUnion()){let e=n.types.map(r);return Array.from(new Set(e)).sort().join(` | `)}if(l.isArrayType(n)){let e=n.typeArguments||[],t=e.length>0?r(e[0]):`any`;return e[0]?.isUnion()?`(${t})[]`:`${t}[]`}if(n.getFlags()&t.default.TypeFlags.Object||n.isClassOrInterface()){let t=l.getPropertiesOfType(n);if(t.length>0)return`{ ${t.map(t=>{let n=l.getTypeOfSymbolAtLocation(t,e);return`${t.getName()}: ${r(n)}`}).join(`, `)} }`}let i=l.getBaseTypeOfLiteralType(n);return l.typeToString(i,e)};u=r(n)}t.default.forEachChild(e,d)};return d(c),u},r=(n,r)=>{let i=`
|
|
5
5
|
${e.r(r)}
|
|
6
6
|
type Target = ${n};
|
|
7
|
-
`,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=
|
|
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=
|
|
7
|
+
`,a=`index.ts`,o=e.t(a,i),s=o.getSourceFile(a),c=o.languageService.getProgram().getTypeChecker(),l=s.statements.find(e=>t.default.isTypeAliasDeclaration(e)&&e.name.text===`Target`);if(!l)return{__typename:`LiteralValue`,value:null};let u=c.getTypeAtLocation(l.type),d=(e,n,r=new Set)=>{let i=new Set(r);if(i.has(e))return null;let a=e.getFlags();if(e.isUnion()){if(n.type,t.default.isTypeAliasDeclaration(n)&&n.type&&t.default.isUnionTypeNode(n.type)){let e=c.getTypeFromTypeNode(n.type.types[0]);return d(e,n,i)}let r=e.types.filter(e=>{let n=e.getFlags();return!(n&t.default.TypeFlags.Undefined)&&!(n&t.default.TypeFlags.Null)}),a=r.length>0?r[0]:e.types[0];return d(a,n,i)}if(a&t.default.TypeFlags.StringLiteral)return e.value;if(a&t.default.TypeFlags.String)return``;if(a&t.default.TypeFlags.NumberLiteral)return e.value;if(a&t.default.TypeFlags.Number)return 0;if(a&t.default.TypeFlags.BooleanLiteral)return e.intrinsicName===`true`;if(a&t.default.TypeFlags.Boolean)return!1;if(c.isArrayType(e)){i.add(e);let t=e.typeArguments?.[0]||c.getAnyType(),r=d(t,n,i);return r===null?[]:[r]}if(e.isClassOrInterface()||a&t.default.TypeFlags.Object||e.getProperties().length>0){i.add(e);let t={};return e.getProperties().forEach(e=>{let r=c.getTypeOfSymbolAtLocation(e,n),a=e.valueDeclaration;r&&(t[e.getName()]=d(r,a||n,i))}),t}return null};return{__typename:`LiteralValue`,value:d(u,l)}},i=2345,a=2322,o=2339,s=(e,t,n)=>{if(e.getStart()>t||e.getEnd()<n)return;let r=e;return e.forEachChild(e=>{let i=s(e,t,n);i&&(r=i)}),r},c=(e,n,r)=>{if(e.start===void 0||e.length===void 0)return!1;let c=s(n,e.start,e.start+e.length);if(!c)return!1;if((e.code===i||e.code===a)&&t.default.isExpression(c)){let e=r.getTypeAtLocation(c);if(!e.isUnion())return!1;let n=r.getContextualType(c);return n?e.types.some(e=>(e.flags&(t.default.TypeFlags.Null|t.default.TypeFlags.Undefined))===0&&r.isTypeAssignableTo(e,n)):!1}if(e.code===o&&t.default.isPropertyAccessExpression(c.parent)){let e=r.getNonNullableType(r.getTypeAtLocation(c.parent.expression));if(!e.isUnion())return!1;let t=c.getText();return e.types.some(e=>e.getProperty(t)!==void 0)}return!1},l=(n,r,i)=>{if(!n?.startingNodeId)return{isValid:!1,returnType:`void`,diagnostics:[{nodeId:null,parameterIndex:null,code:0,message:`You need to provide a starting node to be able to execute this flow.`,severity:`error`}]};if(!n.nodes?.nodes?.find(e=>e?.id==n.startingNodeId))return{isValid:!1,returnType:`void`,diagnostics:[{nodeId:null,parameterIndex:null,code:0,message:`The starting node is not linked within the flow. Please make sure the starting node is connected to the rest of the flow.`,severity:`error`}]};let a=new Set(r?.map(e=>e.identifier)),o=(n.nodes?.nodes??[]).filter(e=>e?.functionDefinition&&!a.has(e.functionDefinition.identifier)).map(e=>({nodeId:e.id,parameterIndex:null,code:0,message:`The function definition "${e.functionDefinition.identifier}" is not reachable.`,severity:`error`}));if(o.length>0)return{isValid:!1,returnType:`void`,diagnostics:o};let s=e.n(n,r,i,!1,!1),l=`index.ts`,u=e.t(l,s),d=u.getSourceFile(l),f=u.languageService.getProgram(),p=f.getTypeChecker(),m=f.getSemanticDiagnostics(d).map(e=>{let n=(0,t.flattenDiagnosticMessageText)(e.messageText,`
|
|
8
|
+
`),r,i=null;if(e.start!==void 0){let t=d.getFullText(),n=Math.max(0,e.start-300),a=Math.min(t.length,e.start),o=t.substring(n,a),s=/\/\* @pos ([^ ]+) (\d+|null) \*\//g,c,l=null,u=-1;for(;(c=s.exec(o))!==null;){let t=n+c.index+c[0].length;t<=e.start&&t>u&&(u=t,l=c)}l&&(r=l[1]===`null`?null:l[1],i=parseInt(l[2],10))}let a=c(e,d,p)?`warning`:`error`;return{message:n,code:e.code,severity:a,nodeId:r,parameterIndex:typeof i==`number`&&Number.isSafeInteger(i)?i:null}}).filter(e=>e!==null);return{isValid:!m.some(e=>e?.severity===`error`),returnType:`void`,diagnostics:m}},u=(n,r,i)=>{let a=e.p(r?.value),o=`
|
|
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}},
|
|
12
|
+
`),r=n.includes(`not assignable to parameter of type`)&&(n.includes(`'{}'`)||n.includes(`undefined`))||n.includes(`not assignable to type 'undefined'`)||n.includes(`not assignable to type 'void'`)||n.includes(`may be a mistake because neither type sufficiently overlaps`);return{message:n,code:e.code,severity:r?`warning`:`error`}});return{isValid:!c.some(e=>e.severity===`error`),returnType:`void`,diagnostics:c}},d=(n,r,i,a)=>{let o=e.n(n,i,r),s=`index.ts`,c=e.t(s,o),l=c.getSourceFile(s),u=c.languageService.getProgram().getTypeChecker(),d=n.nodes?.nodes?.find(e=>e?.id===a),y=a?`fn_${d?.functionDefinition?.identifier?.replace(/::/g,`_`)}`:`flow`,b=a?`node_${e.i(a)}`:`flow_${e.i(n.id)}`,x=p(l),S=m(l).get(b),C=x.get(y),w=h(u,S),T=g(u,C,S),E=w?.map((e,n)=>(e.flags&t.default.TypeFlags.Undefined)===0?e:T?.[n]??e),D=(d?.parameters?.nodes??[]).map(e=>e?.value!=null),O=v(u,S,E,T,_(C,w,D),a?x:new Map,a?i:[],D),k=f(u,S,C);return{nodeId:a,parameters:O,return:k?e.s(u,S,k,Array.from(x.values()),i,!1):{input:`generic`}}},f=(e,n,r)=>{if(n?.initializer&&t.default.isCallExpression(n.initializer)){let t=e.getResolvedSignature(n.initializer);if(t)return e.getReturnTypeOfSignature(t)}if(r){let t=e.getSignatureFromDeclaration(r);if(t)return e.getReturnTypeOfSignature(t)}},p=e=>new Map(e.statements.filter(t.default.isFunctionDeclaration).map(e=>[e.name.getText(),e])),m=e=>{let n=[];return e.statements.forEach(e=>{e.forEachChild(function e(r){t.default.isVariableDeclaration(r)&&(r.parent.flags&t.default.NodeFlags.Const)!==0&&n.push([r.name.getText(),r]),r.forEachChild(e)})}),new Map(n)},h=(e,n)=>{if(n?.initializer&&t.default.isCallExpression(n.initializer))return e.getResolvedSignature(n.initializer)?.parameters.map(t=>e.getTypeOfSymbolAtLocation(t,n.initializer))},g=(e,t,n)=>{if(t&&n?.initializer)return t.parameters.map(t=>{let r=e.getSymbolAtLocation(t.name);return e.getTypeOfSymbolAtLocation(r,n.initializer)})},_=(e,n,r=[])=>{let i=e.typeParameters?.map(e=>e.name.getText())||[],a={};e.parameters.forEach((e,n)=>{if(!e.type)return;let r=new Set;e.type.forEachChild(function n(a){if(t.default.isTypeReferenceNode(a)&&t.default.isIdentifier(a.typeName)){let e=a.typeName.text;i.includes(e)&&r.add(e)}if(t.default.isTypeReferenceNode(e.type)&&t.default.isIdentifier(e.type.typeName)){let t=e.type.typeName.text;i.includes(t)&&r.add(t)}a.forEachChild(n)}),r.forEach(e=>{a[e]||(a[e]=[]),a[e].push(n)})});let o=Object.values(a).filter(e=>e.length>1).map(([e,...t])=>t.map(t=>({parameterIndex:t,dependsOnIndex:e}))).flat();return n?o.filter(e=>{if(r[e.dependsOnIndex])return!1;let i=n[e.parameterIndex];if(!i)return!0;let a=(i.flags&t.default.TypeFlags.Null)!==0,o=(i.flags&t.default.TypeFlags.Undefined)!==0;return a||o}):o},v=(n,r,i,a,o,s,c,l)=>{if(!i)return[];let u=e.s(n,r,n.getAnyType(),Array.from(s.values()),c,!0).suggestions;return i.map((i,d)=>{let f=a?.[d],p=f?T(n,f,r):void 0,m=Array.from(s.values()),h=f?e.s(n,r,f,m,c,!1):void 0,g=(i.flags&t.default.TypeFlags.Object)!==0&&!n.isArrayType(i)&&!n.isTupleType(i),_=y(r,d);if(_&&(t.default.isArrayLiteralExpression(_)||t.default.isObjectLiteralExpression(_)&&g)){let a=e.s(n,r,i,m,c,!0,p).suggestions;return{schema:t.default.isArrayLiteralExpression(_)?x(n,r,f,_,m,c,a,u):C(n,r,f,_,m,c,a,u),blockedBy:o.filter(e=>e.parameterIndex===d).map(e=>e.dependsOnIndex)}}let v=e.f(e.s(n,r,i,m,c,!0,p));return{schema:e.d(h,v,l[d]??!1,u),blockedBy:o.filter(e=>e.parameterIndex===d).map(e=>e.dependsOnIndex)}})},y=(e,n)=>{if(e.initializer&&t.default.isCallExpression(e.initializer))return e.initializer.arguments[n]},b=new Set([`select`,`boolean`,`number`,`text`]),x=(t,n,r,i,a,o,s,c)=>{let l=r?e.s(t,n,r,a,o,!1):void 0,u=l!=null&&l.input?.startsWith(`list`)===!0,d=r&&t.isArrayType(r)?t.getTypeArguments(r)[0]:void 0,f=i.elements.map(e=>S(t,n,d,e,a,o,c));return{input:u?l.input:`list`,type:(u?l.type:void 0)??t.typeToString(t.getBaseTypeOfLiteralType(t.getTypeAtLocation(i))),items:f,...s?.length?{suggestions:s}:{}}},S=(n,r,i,a,o,s,c)=>{if(t.default.isArrayLiteralExpression(a))return x(n,r,i,a,o,s,void 0,c);if(t.default.isObjectLiteralExpression(a))return C(n,r,i,a,o,s,void 0,c);let l=i?e.s(n,r,i,o,s,!0):void 0,u=!l||l.input===`generic`,d=n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a));return u?e.o(e.s(n,r,d,o,s,!0),c):b.has(l.input)?{...l,type:n.typeToString(d)}:l},C=(n,r,i,a,o,s,c,l)=>{let u=i?e.s(n,r,i,o,s,!1):void 0,d=u?.input===`data`;if(u&&!d&&u.input!==`generic`)return{...u,type:n.typeToString(n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a))),...c?.length?{suggestions:c}:{}};let f={},p=[];for(let e of a.properties){if(!t.default.isPropertyAssignment(e))continue;let a=t.default.isStringLiteralLike(e.name)||t.default.isNumericLiteral(e.name)?e.name.text:e.name.getText();f[a]=S(n,r,d?w(n,i,a):void 0,e.initializer,o,s,l),p.push(a)}return{input:`data`,type:(d?u.type:void 0)??n.typeToString(n.getBaseTypeOfLiteralType(n.getTypeAtLocation(a))),properties:f,required:p,...c?.length?{suggestions:c}:{}}},w=(e,t,n)=>{let r=e.getPropertyOfType(t,n);if(!r)return;let i=r.valueDeclaration??r.declarations?.[0];return i?e.getTypeOfSymbolAtLocation(r,i):void 0},T=(e,n,r)=>{if((n.flags&t.default.TypeFlags.TypeParameter)!==0){let r=n.symbol?.declarations?.[0];return r&&t.default.isTypeParameterDeclaration(r)&&r.constraint?e.getTypeFromTypeNode(r.constraint):e.getAnyType()}if((n.flags&t.default.TypeFlags.Conditional)!==0)return e.getBaseConstraintOfType(n)??e.getAnyType();if((n.flags&t.default.TypeFlags.Object)!==0&&E(n,e,new Set)){let i=n.aliasSymbol?.getName();if(i){let n=e.getSymbolsInScope(r,t.default.SymbolFlags.Variable).find(e=>e.getName()===`__widen_${i}`);if(n)return e.getTypeOfSymbolAtLocation(n,r)}return e.getAnyType()}return n},E=(e,n,r)=>!r.has(e)&&(r.add(e),!!((e.flags&t.default.TypeFlags.TypeParameter)!==0||(e.flags&t.default.TypeFlags.Object)!==0&&(n.getTypeArguments(e).some(e=>E(e,n,r))||e.aliasTypeArguments?.some(e=>E(e,n,r))))),D=(n,r=[])=>{let i=`index.ts`,a=`${e.r(r)}\ntype MyType = ${n}`,o=e.t(i,a).languageService.getProgram(),s=o?.getSourceFile(i),c=o?.getTypeChecker();if(!s||!c)return;let l=s.statements.filter(e=>t.default.isTypeAliasDeclaration(e)||t.default.isInterfaceDeclaration(e)||t.default.isClassDeclaration(e)).pop();if(!l)return;let u=c.getTypeAtLocation(l);if(u)return e.s(c,void 0,u,[],[],!1)};exports.CUSTOM_INPUT_IDENTIFIERS=e.a,exports.genericNodeSchema=e.o,exports.getFlowValidation=l,exports.getSchema=e.s,exports.getSignatureSchema=d,exports.getTypeFromValue=n,exports.getTypeSchema=D,exports.getValueFromType=r,exports.getValueValidation=u,exports.isCustomInputIdentifier=e.c,exports.isCustomInputKind=e.l,exports.isSubFlow=e.u,exports.mergeSchemas=e.d,exports.normalizeNodeSchema=e.f;
|
package/dist/index.js
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { a as e, c as t,
|
|
2
|
-
import
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./utils-CAOAm6k-.js";
|
|
2
|
+
import p, { flattenDiagnosticMessageText as m } from "typescript";
|
|
3
3
|
//#region src/extraction/getTypeFromValue.ts
|
|
4
|
-
var
|
|
5
|
-
let n =
|
|
4
|
+
var h = (e, t) => {
|
|
5
|
+
let n = c(e?.value);
|
|
6
6
|
if (!n) return "any";
|
|
7
7
|
let r = `
|
|
8
|
-
${
|
|
8
|
+
${l(t, "unknown")}
|
|
9
9
|
const tempValue = ${n ?? "any"};
|
|
10
|
-
`, i = "index.ts", a =
|
|
11
|
-
if (
|
|
12
|
-
let t =
|
|
10
|
+
`, i = "index.ts", a = d(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), u = "any", f = (e) => {
|
|
11
|
+
if (p.isVariableDeclaration(e) && e.name.getText() === "tempValue") {
|
|
12
|
+
let t = s.getTypeAtLocation(e), n = (t) => {
|
|
13
13
|
if (t.isUnion()) {
|
|
14
14
|
let e = t.types.map(n);
|
|
15
15
|
return Array.from(new Set(e)).sort().join(" | ");
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
17
|
+
if (s.isArrayType(t)) {
|
|
18
18
|
let e = t.typeArguments || [], r = e.length > 0 ? n(e[0]) : "any";
|
|
19
19
|
return e[0]?.isUnion() ? `(${r})[]` : `${r}[]`;
|
|
20
20
|
}
|
|
21
|
-
if (t.getFlags() &
|
|
22
|
-
let r =
|
|
21
|
+
if (t.getFlags() & p.TypeFlags.Object || t.isClassOrInterface()) {
|
|
22
|
+
let r = s.getPropertiesOfType(t);
|
|
23
23
|
if (r.length > 0) return `{ ${r.map((t) => {
|
|
24
|
-
let r =
|
|
24
|
+
let r = s.getTypeOfSymbolAtLocation(t, e);
|
|
25
25
|
return `${t.getName()}: ${n(r)}`;
|
|
26
26
|
}).join(", ")} }`;
|
|
27
27
|
}
|
|
28
|
-
let r =
|
|
29
|
-
return
|
|
28
|
+
let r = s.getBaseTypeOfLiteralType(t);
|
|
29
|
+
return s.typeToString(r, e);
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
u = n(t);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
p.forEachChild(e, f);
|
|
34
34
|
};
|
|
35
|
-
return
|
|
36
|
-
},
|
|
35
|
+
return f(o), u;
|
|
36
|
+
}, g = (e, t) => {
|
|
37
37
|
let n = `
|
|
38
|
-
${
|
|
38
|
+
${l(t)}
|
|
39
39
|
type Target = ${e};
|
|
40
|
-
`, r = "index.ts", i =
|
|
41
|
-
if (!
|
|
40
|
+
`, r = "index.ts", i = d(r, n), a = i.getSourceFile(r), o = i.languageService.getProgram().getTypeChecker(), s = a.statements.find((e) => p.isTypeAliasDeclaration(e) && e.name.text === "Target");
|
|
41
|
+
if (!s) return {
|
|
42
42
|
__typename: "LiteralValue",
|
|
43
43
|
value: null
|
|
44
44
|
};
|
|
45
|
-
let
|
|
45
|
+
let c = o.getTypeAtLocation(s.type), u = (e, t, n = /* @__PURE__ */ new Set()) => {
|
|
46
46
|
let r = new Set(n);
|
|
47
47
|
if (r.has(e)) return null;
|
|
48
48
|
let i = e.getFlags();
|
|
49
49
|
if (e.isUnion()) {
|
|
50
|
-
if (t.type,
|
|
51
|
-
let e =
|
|
52
|
-
return
|
|
50
|
+
if (t.type, p.isTypeAliasDeclaration(t) && t.type && p.isUnionTypeNode(t.type)) {
|
|
51
|
+
let e = o.getTypeFromTypeNode(t.type.types[0]);
|
|
52
|
+
return u(e, t, r);
|
|
53
53
|
}
|
|
54
54
|
let n = e.types.filter((e) => {
|
|
55
55
|
let t = e.getFlags();
|
|
56
|
-
return !(t &
|
|
56
|
+
return !(t & p.TypeFlags.Undefined) && !(t & p.TypeFlags.Null);
|
|
57
57
|
}), i = n.length > 0 ? n[0] : e.types[0];
|
|
58
|
-
return
|
|
58
|
+
return u(i, t, r);
|
|
59
59
|
}
|
|
60
|
-
if (i &
|
|
61
|
-
if (i &
|
|
62
|
-
if (i &
|
|
63
|
-
if (i &
|
|
64
|
-
if (i &
|
|
65
|
-
if (i &
|
|
66
|
-
if (
|
|
60
|
+
if (i & p.TypeFlags.StringLiteral) return e.value;
|
|
61
|
+
if (i & p.TypeFlags.String) return "";
|
|
62
|
+
if (i & p.TypeFlags.NumberLiteral) return e.value;
|
|
63
|
+
if (i & p.TypeFlags.Number) return 0;
|
|
64
|
+
if (i & p.TypeFlags.BooleanLiteral) return e.intrinsicName === "true";
|
|
65
|
+
if (i & p.TypeFlags.Boolean) return !1;
|
|
66
|
+
if (o.isArrayType(e)) {
|
|
67
67
|
r.add(e);
|
|
68
|
-
let n = e.typeArguments?.[0] ||
|
|
68
|
+
let n = e.typeArguments?.[0] || o.getAnyType(), i = u(n, t, r);
|
|
69
69
|
return i === null ? [] : [i];
|
|
70
70
|
}
|
|
71
|
-
if (e.isClassOrInterface() || i &
|
|
71
|
+
if (e.isClassOrInterface() || i & p.TypeFlags.Object || e.getProperties().length > 0) {
|
|
72
72
|
r.add(e);
|
|
73
73
|
let n = {};
|
|
74
74
|
return e.getProperties().forEach((e) => {
|
|
75
|
-
let i =
|
|
76
|
-
i && (n[e.getName()] =
|
|
75
|
+
let i = o.getTypeOfSymbolAtLocation(e, t), a = e.valueDeclaration;
|
|
76
|
+
i && (n[e.getName()] = u(i, a || t, r));
|
|
77
77
|
}), n;
|
|
78
78
|
}
|
|
79
79
|
return null;
|
|
80
80
|
};
|
|
81
81
|
return {
|
|
82
82
|
__typename: "LiteralValue",
|
|
83
|
-
value:
|
|
83
|
+
value: u(c, s)
|
|
84
84
|
};
|
|
85
|
-
},
|
|
85
|
+
}, _ = 2345, v = 2322, y = 2339, b = (e, t, n) => {
|
|
86
86
|
if (e.getStart() > t || e.getEnd() < n) return;
|
|
87
87
|
let r = e;
|
|
88
88
|
return e.forEachChild((e) => {
|
|
89
|
-
let i =
|
|
89
|
+
let i = b(e, t, n);
|
|
90
90
|
i && (r = i);
|
|
91
91
|
}), r;
|
|
92
|
-
},
|
|
92
|
+
}, x = (e, t, n) => {
|
|
93
93
|
if (e.start === void 0 || e.length === void 0) return !1;
|
|
94
|
-
let r =
|
|
94
|
+
let r = b(t, e.start, e.start + e.length);
|
|
95
95
|
if (!r) return !1;
|
|
96
|
-
if (e.code ===
|
|
96
|
+
if ((e.code === _ || e.code === v) && p.isExpression(r)) {
|
|
97
97
|
let e = n.getTypeAtLocation(r);
|
|
98
98
|
if (!e.isUnion()) return !1;
|
|
99
99
|
let t = n.getContextualType(r);
|
|
100
|
-
return t ? e.types.some((e) => (e.flags & (
|
|
100
|
+
return t ? e.types.some((e) => (e.flags & (p.TypeFlags.Null | p.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
|
|
101
101
|
}
|
|
102
|
-
if (e.code ===
|
|
102
|
+
if (e.code === y && p.isPropertyAccessExpression(r.parent)) {
|
|
103
103
|
let e = n.getNonNullableType(n.getTypeAtLocation(r.parent.expression));
|
|
104
104
|
if (!e.isUnion()) return !1;
|
|
105
105
|
let t = r.getText();
|
|
106
106
|
return e.types.some((e) => e.getProperty(t) !== void 0);
|
|
107
107
|
}
|
|
108
108
|
return !1;
|
|
109
|
-
},
|
|
109
|
+
}, S = (e, t, n) => {
|
|
110
110
|
if (!e?.startingNodeId) return {
|
|
111
111
|
isValid: !1,
|
|
112
112
|
returnType: "void",
|
|
@@ -129,29 +129,29 @@ var f = (e, t) => {
|
|
|
129
129
|
severity: "error"
|
|
130
130
|
}]
|
|
131
131
|
};
|
|
132
|
-
let r = new Set(t?.map((e) => e.identifier)),
|
|
132
|
+
let r = new Set(t?.map((e) => e.identifier)), i = (e.nodes?.nodes ?? []).filter((e) => e?.functionDefinition && !r.has(e.functionDefinition.identifier)).map((e) => ({
|
|
133
133
|
nodeId: e.id,
|
|
134
134
|
parameterIndex: null,
|
|
135
135
|
code: 0,
|
|
136
136
|
message: `The function definition "${e.functionDefinition.identifier}" is not reachable.`,
|
|
137
137
|
severity: "error"
|
|
138
138
|
}));
|
|
139
|
-
if (
|
|
139
|
+
if (i.length > 0) return {
|
|
140
140
|
isValid: !1,
|
|
141
141
|
returnType: "void",
|
|
142
|
-
diagnostics:
|
|
142
|
+
diagnostics: i
|
|
143
143
|
};
|
|
144
|
-
let
|
|
145
|
-
let t =
|
|
144
|
+
let a = o(e, t, n, !1, !1), s = "index.ts", c = d(s, a), l = c.getSourceFile(s), u = c.languageService.getProgram(), f = u.getTypeChecker(), p = u.getSemanticDiagnostics(l).map((e) => {
|
|
145
|
+
let t = m(e.messageText, "\n"), n, r = null;
|
|
146
146
|
if (e.start !== void 0) {
|
|
147
|
-
let t =
|
|
147
|
+
let t = l.getFullText(), i = Math.max(0, e.start - 300), a = Math.min(t.length, e.start), o = t.substring(i, a), s = /\/\* @pos ([^ ]+) (\d+|null) \*\//g, c, u = null, d = -1;
|
|
148
148
|
for (; (c = s.exec(o)) !== null;) {
|
|
149
149
|
let t = i + c.index + c[0].length;
|
|
150
|
-
t <= e.start && t > d && (d = t,
|
|
150
|
+
t <= e.start && t > d && (d = t, u = c);
|
|
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 = x(e, l, f) ? "warning" : "error";
|
|
155
155
|
return {
|
|
156
156
|
message: t,
|
|
157
157
|
code: e.code,
|
|
@@ -161,16 +161,16 @@ var f = (e, t) => {
|
|
|
161
161
|
};
|
|
162
162
|
}).filter((e) => e !== null);
|
|
163
163
|
return {
|
|
164
|
-
isValid: !
|
|
164
|
+
isValid: !p.some((e) => e?.severity === "error"),
|
|
165
165
|
returnType: "void",
|
|
166
|
-
diagnostics:
|
|
166
|
+
diagnostics: p
|
|
167
167
|
};
|
|
168
|
-
},
|
|
169
|
-
let r =
|
|
170
|
-
${
|
|
168
|
+
}, C = (e, t, n) => {
|
|
169
|
+
let r = c(t?.value), i = `
|
|
170
|
+
${l(n)}
|
|
171
171
|
const testValue: ${e} = ${r};
|
|
172
|
-
`, a = "index.ts",
|
|
173
|
-
let t =
|
|
172
|
+
`, a = "index.ts", o = d(a, i).languageService.getSemanticDiagnostics(a).map((e) => {
|
|
173
|
+
let t = p.flattenDiagnosticMessageText(e.messageText, "\n"), n = t.includes("not assignable to parameter of type") && (t.includes("'{}'") || t.includes("undefined")) || t.includes("not assignable to type 'undefined'") || t.includes("not assignable to type 'void'") || t.includes("may be a mistake because neither type sufficiently overlaps");
|
|
174
174
|
return {
|
|
175
175
|
message: t,
|
|
176
176
|
code: e.code,
|
|
@@ -178,19 +178,19 @@ var f = (e, t) => {
|
|
|
178
178
|
};
|
|
179
179
|
});
|
|
180
180
|
return {
|
|
181
|
-
isValid: !
|
|
181
|
+
isValid: !o.some((e) => e.severity === "error"),
|
|
182
182
|
returnType: "void",
|
|
183
|
-
diagnostics:
|
|
183
|
+
diagnostics: o
|
|
184
184
|
};
|
|
185
|
-
},
|
|
186
|
-
let
|
|
185
|
+
}, w = (e, t, n, r) => {
|
|
186
|
+
let a = o(e, n, t), s = "index.ts", c = d(s, a), l = c.getSourceFile(s), f = c.languageService.getProgram().getTypeChecker(), m = e.nodes?.nodes?.find((e) => e?.id === r), h = r ? `fn_${m?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", g = r ? `node_${i(r)}` : `flow_${i(e.id)}`, _ = E(l), v = D(l).get(g), y = _.get(h), b = O(f, v), x = k(f, y, v), S = b?.map((e, t) => (e.flags & p.TypeFlags.Undefined) === 0 ? e : x?.[t] ?? e), C = (m?.parameters?.nodes ?? []).map((e) => e?.value != null), w = j(f, v, S, x, A(y, b, C), r ? _ : /* @__PURE__ */ new Map(), r ? n : [], C), M = T(f, v, y);
|
|
187
187
|
return {
|
|
188
|
-
nodeId:
|
|
189
|
-
parameters:
|
|
190
|
-
return: M ?
|
|
188
|
+
nodeId: r,
|
|
189
|
+
parameters: w,
|
|
190
|
+
return: M ? u(f, v, M, Array.from(_.values()), n, !1) : { input: "generic" }
|
|
191
191
|
};
|
|
192
|
-
},
|
|
193
|
-
if (t?.initializer &&
|
|
192
|
+
}, T = (e, t, n) => {
|
|
193
|
+
if (t?.initializer && p.isCallExpression(t.initializer)) {
|
|
194
194
|
let n = e.getResolvedSignature(t.initializer);
|
|
195
195
|
if (n) return e.getReturnTypeOfSignature(n);
|
|
196
196
|
}
|
|
@@ -198,31 +198,31 @@ var f = (e, t) => {
|
|
|
198
198
|
let t = e.getSignatureFromDeclaration(n);
|
|
199
199
|
if (t) return e.getReturnTypeOfSignature(t);
|
|
200
200
|
}
|
|
201
|
-
},
|
|
201
|
+
}, E = (e) => new Map(e.statements.filter(p.isFunctionDeclaration).map((e) => [e.name.getText(), e])), D = (e) => {
|
|
202
202
|
let t = [];
|
|
203
203
|
return e.statements.forEach((e) => {
|
|
204
204
|
e.forEachChild(function e(n) {
|
|
205
|
-
|
|
205
|
+
p.isVariableDeclaration(n) && (n.parent.flags & p.NodeFlags.Const) !== 0 && t.push([n.name.getText(), n]), n.forEachChild(e);
|
|
206
206
|
});
|
|
207
207
|
}), new Map(t);
|
|
208
|
-
},
|
|
209
|
-
if (
|
|
210
|
-
},
|
|
211
|
-
if (
|
|
208
|
+
}, O = (e, t) => {
|
|
209
|
+
if (t?.initializer && p.isCallExpression(t.initializer)) return e.getResolvedSignature(t.initializer)?.parameters.map((n) => e.getTypeOfSymbolAtLocation(n, t.initializer));
|
|
210
|
+
}, k = (e, t, n) => {
|
|
211
|
+
if (t && n?.initializer) return t.parameters.map((t) => {
|
|
212
212
|
let r = e.getSymbolAtLocation(t.name);
|
|
213
213
|
return e.getTypeOfSymbolAtLocation(r, n.initializer);
|
|
214
214
|
});
|
|
215
|
-
},
|
|
215
|
+
}, A = (e, t, n = []) => {
|
|
216
216
|
let r = e.typeParameters?.map((e) => e.name.getText()) || [], i = {};
|
|
217
217
|
e.parameters.forEach((e, t) => {
|
|
218
218
|
if (!e.type) return;
|
|
219
219
|
let n = /* @__PURE__ */ new Set();
|
|
220
220
|
e.type.forEachChild(function t(i) {
|
|
221
|
-
if (
|
|
221
|
+
if (p.isTypeReferenceNode(i) && p.isIdentifier(i.typeName)) {
|
|
222
222
|
let e = i.typeName.text;
|
|
223
223
|
r.includes(e) && n.add(e);
|
|
224
224
|
}
|
|
225
|
-
if (
|
|
225
|
+
if (p.isTypeReferenceNode(e.type) && p.isIdentifier(e.type.typeName)) {
|
|
226
226
|
let t = e.type.typeName.text;
|
|
227
227
|
r.includes(t) && n.add(t);
|
|
228
228
|
}
|
|
@@ -239,37 +239,97 @@ var f = (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 & p.TypeFlags.Null) !== 0, a = (r.flags & p.TypeFlags.Undefined) !== 0;
|
|
243
243
|
return i || a;
|
|
244
244
|
}) : a;
|
|
245
|
-
},
|
|
246
|
-
|
|
245
|
+
}, j = (e, t, i, a, o, s, c, l) => {
|
|
246
|
+
if (!i) return [];
|
|
247
|
+
let d = u(e, t, e.getAnyType(), Array.from(s.values()), c, !0).suggestions;
|
|
248
|
+
return i.map((i, f) => {
|
|
249
|
+
let m = a?.[f], h = m ? R(e, m, t) : void 0, g = Array.from(s.values()), _ = m ? u(e, t, m, g, c, !1) : void 0, v = (i.flags & p.TypeFlags.Object) !== 0 && !e.isArrayType(i) && !e.isTupleType(i), y = M(t, f);
|
|
250
|
+
if (y && (p.isArrayLiteralExpression(y) || p.isObjectLiteralExpression(y) && v)) {
|
|
251
|
+
let n = u(e, t, i, g, c, !0, h).suggestions;
|
|
252
|
+
return {
|
|
253
|
+
schema: p.isArrayLiteralExpression(y) ? P(e, t, m, y, g, c, n, d) : I(e, t, m, y, g, c, n, d),
|
|
254
|
+
blockedBy: o.filter((e) => e.parameterIndex === f).map((e) => e.dependsOnIndex)
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
let b = r(u(e, t, i, g, c, !0, h));
|
|
258
|
+
return {
|
|
259
|
+
schema: n(_, b, l[f] ?? !1, d),
|
|
260
|
+
blockedBy: o.filter((e) => e.parameterIndex === f).map((e) => e.dependsOnIndex)
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
}, M = (e, t) => {
|
|
264
|
+
if (e.initializer && p.isCallExpression(e.initializer)) return e.initializer.arguments[t];
|
|
265
|
+
}, N = /* @__PURE__ */ new Set([
|
|
266
|
+
"select",
|
|
267
|
+
"boolean",
|
|
268
|
+
"number",
|
|
269
|
+
"text"
|
|
270
|
+
]), P = (e, t, n, r, i, a, o, s) => {
|
|
271
|
+
let c = n ? u(e, t, n, i, a, !1) : void 0, l = c != null && c.input?.startsWith("list") === !0, d = n && e.isArrayType(n) ? e.getTypeArguments(n)[0] : void 0, f = r.elements.map((n) => F(e, t, d, n, i, a, s));
|
|
272
|
+
return {
|
|
273
|
+
input: l ? c.input : "list",
|
|
274
|
+
type: (l ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
|
|
275
|
+
items: f,
|
|
276
|
+
...o?.length ? { suggestions: o } : {}
|
|
277
|
+
};
|
|
278
|
+
}, F = (e, t, n, r, i, a, o) => {
|
|
279
|
+
if (p.isArrayLiteralExpression(r)) return P(e, t, n, r, i, a, void 0, o);
|
|
280
|
+
if (p.isObjectLiteralExpression(r)) return I(e, t, n, r, i, a, void 0, o);
|
|
281
|
+
let c = n ? u(e, t, n, i, a, !0) : void 0, l = !c || c.input === "generic", d = e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r));
|
|
282
|
+
return l ? s(u(e, t, d, i, a, !0), o) : N.has(c.input) ? {
|
|
283
|
+
...c,
|
|
284
|
+
type: e.typeToString(d)
|
|
285
|
+
} : c;
|
|
286
|
+
}, I = (e, t, n, r, i, a, o, s) => {
|
|
287
|
+
let c = n ? u(e, t, n, i, a, !1) : void 0, l = c?.input === "data";
|
|
288
|
+
if (c && !l && c.input !== "generic") return {
|
|
289
|
+
...c,
|
|
290
|
+
type: e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
|
|
291
|
+
...o?.length ? { suggestions: o } : {}
|
|
292
|
+
};
|
|
293
|
+
let d = {}, f = [];
|
|
294
|
+
for (let o of r.properties) {
|
|
295
|
+
if (!p.isPropertyAssignment(o)) continue;
|
|
296
|
+
let r = p.isStringLiteralLike(o.name) || p.isNumericLiteral(o.name) ? o.name.text : o.name.getText();
|
|
297
|
+
d[r] = F(e, t, l ? L(e, n, r) : void 0, o.initializer, i, a, s), f.push(r);
|
|
298
|
+
}
|
|
247
299
|
return {
|
|
248
|
-
|
|
249
|
-
|
|
300
|
+
input: "data",
|
|
301
|
+
type: (l ? c.type : void 0) ?? e.typeToString(e.getBaseTypeOfLiteralType(e.getTypeAtLocation(r))),
|
|
302
|
+
properties: d,
|
|
303
|
+
required: f,
|
|
304
|
+
...o?.length ? { suggestions: o } : {}
|
|
250
305
|
};
|
|
251
|
-
}
|
|
252
|
-
|
|
306
|
+
}, L = (e, t, n) => {
|
|
307
|
+
let r = e.getPropertyOfType(t, n);
|
|
308
|
+
if (!r) return;
|
|
309
|
+
let i = r.valueDeclaration ?? r.declarations?.[0];
|
|
310
|
+
return i ? e.getTypeOfSymbolAtLocation(r, i) : void 0;
|
|
311
|
+
}, R = (e, t, n) => {
|
|
312
|
+
if ((t.flags & p.TypeFlags.TypeParameter) !== 0) {
|
|
253
313
|
let n = t.symbol?.declarations?.[0];
|
|
254
|
-
return n &&
|
|
314
|
+
return n && p.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
|
|
255
315
|
}
|
|
256
|
-
if ((t.flags &
|
|
257
|
-
if ((t.flags &
|
|
316
|
+
if ((t.flags & p.TypeFlags.Conditional) !== 0) return e.getBaseConstraintOfType(t) ?? e.getAnyType();
|
|
317
|
+
if ((t.flags & p.TypeFlags.Object) !== 0 && z(t, e, /* @__PURE__ */ new Set())) {
|
|
258
318
|
let r = t.aliasSymbol?.getName();
|
|
259
319
|
if (r) {
|
|
260
|
-
let t = e.getSymbolsInScope(n,
|
|
320
|
+
let t = e.getSymbolsInScope(n, p.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
|
|
261
321
|
if (t) return e.getTypeOfSymbolAtLocation(t, n);
|
|
262
322
|
}
|
|
263
323
|
return e.getAnyType();
|
|
264
324
|
}
|
|
265
325
|
return t;
|
|
266
|
-
},
|
|
267
|
-
let n = "index.ts", r = `${
|
|
268
|
-
if (!
|
|
269
|
-
let
|
|
270
|
-
if (!
|
|
271
|
-
let
|
|
272
|
-
if (
|
|
326
|
+
}, z = (e, t, n) => !n.has(e) && (n.add(e), !!((e.flags & p.TypeFlags.TypeParameter) !== 0 || (e.flags & p.TypeFlags.Object) !== 0 && (t.getTypeArguments(e).some((e) => z(e, t, n)) || e.aliasTypeArguments?.some((e) => z(e, t, n))))), B = (e, t = []) => {
|
|
327
|
+
let n = "index.ts", r = `${l(t)}\ntype MyType = ${e}`, i = d(n, r).languageService.getProgram(), a = i?.getSourceFile(n), o = i?.getTypeChecker();
|
|
328
|
+
if (!a || !o) return;
|
|
329
|
+
let s = a.statements.filter((e) => p.isTypeAliasDeclaration(e) || p.isInterfaceDeclaration(e) || p.isClassDeclaration(e)).pop();
|
|
330
|
+
if (!s) return;
|
|
331
|
+
let c = o.getTypeAtLocation(s);
|
|
332
|
+
if (c) return u(o, void 0, c, [], [], !1);
|
|
273
333
|
};
|
|
274
334
|
//#endregion
|
|
275
|
-
export { e as CUSTOM_INPUT_IDENTIFIERS,
|
|
335
|
+
export { e as CUSTOM_INPUT_IDENTIFIERS, s as genericNodeSchema, S as getFlowValidation, u as getSchema, w as getSignatureSchema, h as getTypeFromValue, B as getTypeSchema, g as getValueFromType, C as getValueValidation, t as isCustomInputIdentifier, a as isCustomInputKind, f as isSubFlow, n as mergeSchemas, r as normalizeNodeSchema };
|
package/dist/server.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-
|
|
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(
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-oMAOCPrM.cjs");let t=require("typescript");t=e.m(t,1);let n=require("ts-json-schema-generator");var r={...n.DEFAULT_CONFIG,expose:`none`,topRef:!1,jsDoc:`none`,skipTypeCheck:!0},i=(e,t)=>{let n=Object.keys(e);if(n.length===0)return{};let r=o(a(e,t)),i={};for(let e of n)try{i[e]=s(r.createSchema(e))}catch{i[e]={}}return i},a=(t,n)=>{let r=Object.entries(t).map(([e,t])=>`export type ${e} = ${t};`).join(`
|
|
2
|
+
`);return`${e.r(n)}\n${r}`},o=t=>{let i=e.t(`index.ts`,t).languageService.getProgram();return new n.SchemaGenerator(i,(0,n.createParser)(i,r),(0,n.createFormatter)(r),r)},s=e=>{let{$schema:t,definitions:n,...r}=e,i=n&&Object.keys(n).length>0?{...r,definitions:n}:r;return JSON.parse(JSON.stringify(i))},c=(t,n,r)=>{if(!t)return;let a=`index.ts`,o=e.n(t,n,r),s=e.t(a,o),c=s.getSourceFile(a),d=s.languageService.getProgram().getTypeChecker(),m=i({...f(d,c),...p(d,c,t)},r),h=(t.nodes?.nodes??[]).map(e=>e&&b(e,m));return{...t,inputSchema:m[l]??v(),outputSchema:m[u]??y(),nodes:{...t.nodes,nodes:h}}},l=`Flow_input`,u=`Flow_output`,d=(t,n,r)=>`Node_${e.i(t)}_${n}_${r}`,f=(e,n)=>{let r=n.statements.filter(t.default.isFunctionDeclaration).find(e=>e.name?.getText()===`flow`);if(!r)return{};let i=e.getSignatureFromDeclaration(r);if(!i)return{};let{input:a,output:o}=_(e,i,r);return{[l]:a,[u]:o}},p=(e,t,n)=>{let r=w(t),i={};for(let t of n.nodes?.nodes??[]){if(!t?.id)continue;let n=t.parameters?.nodes;if(!n?.some(x))continue;let a=C(r,t);a&&n.forEach((n,r)=>{if(!x(n))return;let o=a.arguments[r],s=o?e.getTypeAtLocation(o).getCallSignatures()[0]:void 0;if(!s)return;let{input:c,output:l}=m(e,s,o);i[d(t.id,r,`input`)]=c,i[d(t.id,r,`output`)]=l})}return i},m=(e,n,r)=>({input:`{ ${h(e,n,r).join(`; `)} }`,output:(n=>e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation))(e.getReturnTypeOfSignature(n))}),h=(e,n,r)=>{let i=n=>e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation),a=n.getParameters();if(a.length===1){let t=g(e,e.getTypeOfSymbolAtLocation(a[0],a[0].valueDeclaration??r),r);if(t)return t}return a.map(t=>{let n=e.getTypeOfSymbolAtLocation(t,t.valueDeclaration??r),a=S(t)?`?`:``;return`${t.getName()}${a}: ${i(n)}`})},g=(e,n,r)=>{let i=n,a=i.target;if(a&&(a.objectFlags&t.default.ObjectFlags.Tuple)!==0)return e.getTypeArguments(i).map((n,i)=>{let o=a.labeledElementDeclarations?.[i];return`${o?.name&&t.default.isIdentifier(o.name)?o.name.text:`arg${i}`}${(a.elementFlags[i]&t.default.ElementFlags.Optional)===0?``:`?`}: ${e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation)}`})},_=(e,n,r)=>{let i=n=>e.typeToString(n,r,t.default.TypeFormatFlags.NoTruncation);return{input:`{ ${n.parameters.map(t=>{let n=e.getTypeOfSymbolAtLocation(t,t.valueDeclaration??r),a=S(t)?`?`:``;return`${t.getName()}${a}: ${i(n)}`}).join(`; `)} }`,output:i(e.getReturnTypeOfSignature(n))}},v=()=>({type:`object`}),y=()=>({}),b=(e,t)=>{let n=e.parameters?.nodes;if(!n?.some(x))return e;let r=n.map((n,r)=>{if(!x(n))return n;let i={...n.value,inputSchema:t[d(e.id,r,`input`)]??v(),outputSchema:t[d(e.id,r,`output`)]??y()};return{...n,value:i}});return{...e,parameters:{...e.parameters,nodes:r}}},x=e=>e?.value?.__typename===`SubFlowValue`,S=e=>{let n=e.valueDeclaration;return!!n&&t.default.isParameter(n)&&(!!n.questionToken||!!n.initializer||!!n.dotDotDotToken)},C=(n,r)=>{let i=n.get(`node_${e.i(r.id)}`)?.initializer;return i&&t.default.isCallExpression(i)?i:void 0},w=e=>{let n=new Map;return e.statements.forEach(e=>{e.forEachChild(function e(r){t.default.isVariableDeclaration(r)&&(r.parent.flags&t.default.NodeFlags.Const)!==0&&n.set(r.name.getText(),r),r.forEachChild(e)})}),n};exports.getFlowSchemas=c;
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as e, n as t, r as n, t as r } from "./utils-
|
|
1
|
+
import { i as e, n as t, r as n, t as r } from "./utils-CAOAm6k-.js";
|
|
2
2
|
import i from "typescript";
|
|
3
3
|
import { DEFAULT_CONFIG as a, SchemaGenerator as o, createFormatter as s, createParser as c } from "ts-json-schema-generator";
|
|
4
4
|
//#region src/util/jsonSchema.util.ts
|
|
@@ -86,7 +86,7 @@ var l = {
|
|
|
86
86
|
});
|
|
87
87
|
}, S = (e, t, n) => {
|
|
88
88
|
let r = t, a = r.target;
|
|
89
|
-
if (
|
|
89
|
+
if (a && (a.objectFlags & i.ObjectFlags.Tuple) !== 0) return e.getTypeArguments(r).map((t, r) => {
|
|
90
90
|
let o = a.labeledElementDeclarations?.[r];
|
|
91
91
|
return `${o?.name && i.isIdentifier(o.name) ? o.name.text : `arg${r}`}${(a.elementFlags[r] & i.ElementFlags.Optional) === 0 ? "" : "?"}: ${e.typeToString(t, n, i.TypeFormatFlags.NoTruncation)}`;
|
|
92
92
|
});
|
|
@@ -17,11 +17,25 @@ import { FunctionDefinition, LiteralValue, NodeFunction, ReferenceValue, SubFlow
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const CUSTOM_INPUT_IDENTIFIERS: {
|
|
19
19
|
readonly DATE: "date";
|
|
20
|
+
readonly TYPE: "type";
|
|
20
21
|
};
|
|
21
22
|
/** A data type identifier that maps to a custom input. */
|
|
22
23
|
export type CustomInputIdentifier = keyof typeof CUSTOM_INPUT_IDENTIFIERS;
|
|
23
24
|
/** Returns true if the given identifier maps to a custom input. */
|
|
24
25
|
export declare const isCustomInputIdentifier: (identifier: string | null | undefined) => identifier is CustomInputIdentifier;
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if the given input kind is one produced by a custom-input data
|
|
28
|
+
* type (e.g. "date", "type"). Used by {@link mergeSchemas} to let a supplied
|
|
29
|
+
* value narrow the rendered `type` of such an input while the input kind itself
|
|
30
|
+
* is kept.
|
|
31
|
+
*
|
|
32
|
+
* Note this covers the registry-driven kinds only, so it is not the test for
|
|
33
|
+
* "is this input dedicated rather than structural" — COLOR is detected by shape
|
|
34
|
+
* (see isColorType) and never appears here. Code that must not expand a
|
|
35
|
+
* dedicated input back into the shape it was built from checks for the
|
|
36
|
+
* structural kinds it does expand ("data", "generic") instead.
|
|
37
|
+
*/
|
|
38
|
+
export declare const isCustomInputKind: (input: string | undefined) => boolean;
|
|
25
39
|
/**
|
|
26
40
|
* Base interface for all input types.
|
|
27
41
|
* Provides common properties for suggestions and input metadata.
|
|
@@ -179,15 +193,13 @@ export interface ListInput extends Input {
|
|
|
179
193
|
items?: Schema[];
|
|
180
194
|
}
|
|
181
195
|
/**
|
|
182
|
-
* Represents a
|
|
183
|
-
*
|
|
196
|
+
* Represents a type input.
|
|
197
|
+
* Emitted for the TYPE data type so the UI can render a dedicated type picker
|
|
198
|
+
* instead of the plain input its underlying type (`any`) would otherwise
|
|
199
|
+
* produce. Like {@link DateInput}, it carries no additional properties.
|
|
184
200
|
*/
|
|
185
201
|
export interface TypeInput extends Input {
|
|
186
202
|
input?: "type";
|
|
187
|
-
/** Record mapping property names to their schemas */
|
|
188
|
-
properties?: Record<string, Schema | Schema[]>;
|
|
189
|
-
/** Array of required property names */
|
|
190
|
-
required?: string[];
|
|
191
203
|
}
|
|
192
204
|
/**
|
|
193
205
|
* Union type representing all possible schema input types.
|
|
@@ -218,8 +230,42 @@ export type Schema = PrimitiveInput | DateInput | ColorInput | FileInput | ListF
|
|
|
218
230
|
* @param suggestions
|
|
219
231
|
* @returns A Schema object describing how to handle the parameter type
|
|
220
232
|
*/
|
|
221
|
-
export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration | undefined, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[], suggestions?: boolean, suggestionType?: ts.Type, visited?: Set<ts.Type>, recursionCache?: Map<ts.Type, boolean
|
|
222
|
-
|
|
233
|
+
export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration | undefined, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[], suggestions?: boolean, suggestionType?: ts.Type, visited?: Set<ts.Type>, recursionCache?: Map<ts.Type, boolean>, declaredType?: ts.Type) => Schema;
|
|
234
|
+
/**
|
|
235
|
+
* Normalizes a node-side schema so it only contributes concrete resolved types
|
|
236
|
+
* to {@link mergeSchemas}, recursing through `items` and `properties`. It:
|
|
237
|
+
*
|
|
238
|
+
* - Rewrites every specialized list-* input back to the plain `list` kind. The
|
|
239
|
+
* specialized variants are a declared-type (function-side) concern, so a
|
|
240
|
+
* concrete value must never surface one; the resolved element types (via
|
|
241
|
+
* `items`) are kept, and the `list-file` `mimetype` is dropped because a plain
|
|
242
|
+
* list has no such field.
|
|
243
|
+
* - Drops an empty `suggestions` array. Node schemas are built with suggestions
|
|
244
|
+
* enabled and therefore always carry the key — even when empty — whereas the
|
|
245
|
+
* rest of the pipeline omits it entirely when there are none.
|
|
246
|
+
*
|
|
247
|
+
* The function-side schema still drives the final input kind in
|
|
248
|
+
* {@link mergeSchemas}.
|
|
249
|
+
*/
|
|
250
|
+
export declare const normalizeNodeSchema: (schema: Schema) => Schema;
|
|
251
|
+
/**
|
|
252
|
+
* Treats a node-side schema as sitting in a fully generic ("accepts anything")
|
|
253
|
+
* slot: the declared type constrains nothing here, so the value keeps its shape
|
|
254
|
+
* while a select narrowed from a single literal is demoted to its free-form
|
|
255
|
+
* primitive. Recurses through `items` and `properties` so the whole subtree is
|
|
256
|
+
* treated uniformly.
|
|
257
|
+
*
|
|
258
|
+
* Suggestions: nested positions were built value-scoped (the recursion inside
|
|
259
|
+
* {@link getSchema} drops the suggestion scope), so they are replaced with the
|
|
260
|
+
* constant `any` set. The `overrideRoot` flag controls this for the top node
|
|
261
|
+
* only: at a nested position it is `true` (the node's own suggestions are the
|
|
262
|
+
* value-narrowed subset and must be replaced); at a parameter root it is `false`
|
|
263
|
+
* (the node's suggestions were already scoped by `suggestionType`/the
|
|
264
|
+
* type-parameter constraint — e.g. `keyof T` — so they are kept). Descendants are
|
|
265
|
+
* always overridden regardless.
|
|
266
|
+
*/
|
|
267
|
+
export declare const genericNodeSchema: (schema: Schema, anySuggestions?: Input["suggestions"], overrideRoot?: boolean) => Schema;
|
|
268
|
+
export declare const mergeSchemas: (functionSchema: Schema | undefined, nodeSchema: Schema, valueProvided?: boolean, anySuggestions?: Input["suggestions"], topLevel?: boolean) => Schema;
|
|
223
269
|
/**
|
|
224
270
|
* Checks if a type is a callable type (has call signatures).
|
|
225
271
|
*
|