@code0-tech/triangulum 0.29.0 → 0.30.1

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.
@@ -0,0 +1,57 @@
1
+ import { DataType, Flow, FunctionDefinition, SubFlowValue } from '@code0-tech/sagittarius-graphql-types';
2
+ import { JsonSchema } from '../util/jsonSchema.util';
3
+ /**
4
+ * The input/output JSON schemas computed for a callable signature.
5
+ *
6
+ * Both are derived from the *real* signature — the flow's own signature for the
7
+ * flow, or the callback parameter type (e.g. `(item: T) => void`) for a
8
+ * sub-flow.
9
+ *
10
+ * `inputSchema` is an `object` schema whose `properties` hold one entry per
11
+ * signature parameter, keyed by the parameter name (non-optional parameters are
12
+ * listed in `required`). `outputSchema` describes the return type.
13
+ */
14
+ export interface SignatureSchemas {
15
+ /** Object schema whose properties are the signature's parameters, by name. */
16
+ inputSchema: JsonSchema;
17
+ /** JSON schema describing the signature's return type. */
18
+ outputSchema: JsonSchema;
19
+ }
20
+ /** A {@link SubFlowValue} enriched with its computed input/output schemas. */
21
+ export type SchematizedSubFlowValue = SubFlowValue & SignatureSchemas;
22
+ /**
23
+ * A {@link Flow} enriched with the input/output schemas of its own signature.
24
+ * Every {@link SubFlowValue} nested in a node parameter is additionally enriched
25
+ * in place (see {@link SchematizedSubFlowValue}).
26
+ */
27
+ export type SchematizedFlow = Flow & SignatureSchemas;
28
+ /**
29
+ * Enriches a flow with the input and output JSON schemas of its signature and of
30
+ * every sub-flow it contains.
31
+ *
32
+ * The same flow is returned back, but with two additional fields on the flow
33
+ * itself and on every {@link SubFlowValue} that appears as a node parameter:
34
+ * - `inputSchema` — an `object` JSON schema keyed by the signature's parameter names
35
+ * - `outputSchema` — the JSON schema of the signature's return type
36
+ *
37
+ * The schemas are computed from the real signatures, resolved through the same
38
+ * virtual TypeScript program that {@link generateFlowSourceCode} builds:
39
+ * - For the flow, the schemas come from the flow's own `signature`.
40
+ * - For a sub-flow, the schemas come from the callback parameter type of the
41
+ * surrounding function (e.g. `std::list::for_each`'s `consumer` parameter is
42
+ * typed `(item: T) => void`). Because the type is resolved from the concrete
43
+ * call, generic type parameters (the `T` above) are already instantiated with
44
+ * the real element type at that node.
45
+ *
46
+ * The actual JSON Schema generation is delegated to `ts-json-schema-generator`
47
+ * (see {@link generateJsonSchemas}); this function only resolves the real
48
+ * TypeScript type of each parameter/return and hands it over as a type
49
+ * expression.
50
+ *
51
+ * @param flow - The flow to enrich; returned unchanged when undefined
52
+ * @param functions - Available function definitions (drive the generated code)
53
+ * @param dataTypes - Available data type definitions (drive the type aliases)
54
+ * @returns The same flow, enriched with input/output schemas, or `undefined`
55
+ * when no flow was supplied
56
+ */
57
+ export declare const getFlowSchemas: (flow?: Flow, functions?: FunctionDefinition[], dataTypes?: DataType[]) => SchematizedFlow | undefined;
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-C3jpxxXK.cjs");let t=require("typescript");t=e.c(t,1);var n=(n,r)=>{let i=e.s(n?.value);if(!i)return`any`;let a=`
2
+ ${e.r(r,`unknown`)}
3
+ const tempValue = ${i??`any`};
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
+ ${e.r(r)}
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))return d(c.getTypeFromTypeNode(n.type.types[0]),n,i);let r=e.types.filter(e=>{let n=e.getFlags();return!(n&t.default.TypeFlags.Undefined)&&!(n&t.default.TypeFlags.Null)});return d(r.length>0?r[0]:e.types[0],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=d(e.typeArguments?.[0]||c.getAnyType(),n,i);return t===null?[]:[t]}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=2339,o=(e,t,n)=>{if(e.getStart()>t||e.getEnd()<n)return;let r=e;return e.forEachChild(e=>{let i=o(e,t,n);i&&(r=i)}),r},s=(e,n,r)=>{if(e.start===void 0||e.length===void 0)return!1;let s=o(n,e.start,e.start+e.length);if(!s)return!1;if(e.code===i&&t.default.isExpression(s)){let e=r.getTypeAtLocation(s);if(!e.isUnion())return!1;let n=r.getContextualType(s);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===a&&t.default.isPropertyAccessExpression(s.parent)){let e=r.getNonNullableType(r.getTypeAtLocation(s.parent.expression));if(!e.isUnion())return!1;let t=s.getText();return e.types.some(e=>e.getProperty(t)!==void 0)}return!1},c=(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 c=e.n(n,r,i,!1,!1),l=`index.ts`,u=e.t(l,c),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=s(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}},l=(n,r,i)=>{let a=e.s(r?.value),o=`
9
+ ${e.r(i)}
10
+ const testValue: ${n} = ${a};
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}},u=(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(),v=n.nodes?.nodes?.find(e=>e?.id===a),y=a?`fn_${v?.functionDefinition?.identifier?.replace(/::/g,`_`)}`:`flow`,b=a?`node_${e.i(a)}`:`flow_${e.i(n.id)}`,x=f(l),S=p(l).get(b),C=x.get(y),w=m(u,S),T=h(u,C,S),E=w?.map((e,n)=>(e.flags&t.default.TypeFlags.Undefined)===0?e:T?.[n]??e),D=(v?.parameters?.nodes??[]).map(e=>e?.value!=null),O=_(u,S,E,T,g(C,w,D),a?x:new Map,a?i:[],D),k=d(u,S,C);return{nodeId:a,parameters:O,return:k?e.a(u,S,k,Array.from(x.values()),i,!1):{input:`generic`}}},d=(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)}},f=e=>new Map(e.statements.filter(t.default.isFunctionDeclaration).map(e=>[e.name.getText(),e])),p=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)},m=(e,n)=>{if(!(!n?.initializer||!t.default.isCallExpression(n.initializer)))return e.getResolvedSignature(n.initializer)?.parameters.map(t=>e.getTypeOfSymbolAtLocation(t,n.initializer))},h=(e,t,n)=>{if(!(!t||!n?.initializer))return t.parameters.map(t=>{let r=e.getSymbolAtLocation(t.name);return e.getTypeOfSymbolAtLocation(r,n.initializer)})},g=(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},_=(t,n,r,i,a,o,s,c)=>r?r.map((r,l)=>{let u=i?.[l],d=u?v(t,u,n):void 0,f=e.a(t,n,r,Array.from(o.values()),s,!0,d);return{schema:e.o(u?e.a(t,n,u,Array.from(o.values()),s,!1):void 0,f,c[l]??!1),blockedBy:a.filter(e=>e.parameterIndex===l).map(e=>e.dependsOnIndex)}}):[],v=(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&&y(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},y=(e,n,r)=>r.has(e)?!1:(r.add(e),!!((e.flags&t.default.TypeFlags.TypeParameter)!==0||(e.flags&t.default.TypeFlags.Object)!==0&&(n.getTypeArguments(e).some(e=>y(e,n,r))||e.aliasTypeArguments?.some(e=>y(e,n,r))))),b=(n,r=[])=>{let i=`index.ts`,a=e.t(i,`${e.r(r)}\ntype MyType = ${n}`).languageService.getProgram(),o=a?.getSourceFile(i),s=a?.getTypeChecker();if(!o||!s)return;let c=o.statements.filter(e=>t.default.isTypeAliasDeclaration(e)||t.default.isInterfaceDeclaration(e)||t.default.isClassDeclaration(e)).pop();if(!c)return;let l=s.getTypeAtLocation(c);if(l)return e.a(s,void 0,l,[],[],!1)};exports.getFlowValidation=c,exports.getSignatureSchema=u,exports.getTypeFromValue=n,exports.getTypeSchema=b,exports.getValueFromType=r,exports.getValueValidation=l;
@@ -0,0 +1,272 @@
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./utils-B8zuiBhE.js";
2
+ import s, { flattenDiagnosticMessageText as c } from "typescript";
3
+ //#region src/extraction/getTypeFromValue.ts
4
+ var l = (e, t) => {
5
+ let n = a(e?.value);
6
+ if (!n) return "any";
7
+ let r = `
8
+ ${i(t, "unknown")}
9
+ const tempValue = ${n ?? "any"};
10
+ `, c = "index.ts", l = o(c, r), u = l.getSourceFile(c), d = l.languageService.getProgram().getTypeChecker(), f = "any", p = (e) => {
11
+ if (s.isVariableDeclaration(e) && e.name.getText() === "tempValue") {
12
+ let t = d.getTypeAtLocation(e), n = (t) => {
13
+ if (t.isUnion()) {
14
+ let e = t.types.map(n);
15
+ return Array.from(new Set(e)).sort().join(" | ");
16
+ }
17
+ if (d.isArrayType(t)) {
18
+ let e = t.typeArguments || [], r = e.length > 0 ? n(e[0]) : "any";
19
+ return e[0]?.isUnion() ? `(${r})[]` : `${r}[]`;
20
+ }
21
+ if (t.getFlags() & s.TypeFlags.Object || t.isClassOrInterface()) {
22
+ let r = d.getPropertiesOfType(t);
23
+ if (r.length > 0) return `{ ${r.map((t) => {
24
+ let r = d.getTypeOfSymbolAtLocation(t, e);
25
+ return `${t.getName()}: ${n(r)}`;
26
+ }).join(", ")} }`;
27
+ }
28
+ let r = d.getBaseTypeOfLiteralType(t);
29
+ return d.typeToString(r, e);
30
+ };
31
+ f = n(t);
32
+ }
33
+ s.forEachChild(e, p);
34
+ };
35
+ return p(u), f;
36
+ }, u = (e, t) => {
37
+ let n = `
38
+ ${i(t)}
39
+ type Target = ${e};
40
+ `, r = "index.ts", a = o(r, n), c = a.getSourceFile(r), l = a.languageService.getProgram().getTypeChecker(), u = c.statements.find((e) => s.isTypeAliasDeclaration(e) && e.name.text === "Target");
41
+ if (!u) return {
42
+ __typename: "LiteralValue",
43
+ value: null
44
+ };
45
+ let d = l.getTypeAtLocation(u.type), f = (e, t, n = /* @__PURE__ */ new Set()) => {
46
+ let r = new Set(n);
47
+ if (r.has(e)) return null;
48
+ let i = e.getFlags();
49
+ if (e.isUnion()) {
50
+ if (t.type, s.isTypeAliasDeclaration(t) && t.type && s.isUnionTypeNode(t.type)) return f(l.getTypeFromTypeNode(t.type.types[0]), t, r);
51
+ let n = e.types.filter((e) => {
52
+ let t = e.getFlags();
53
+ return !(t & s.TypeFlags.Undefined) && !(t & s.TypeFlags.Null);
54
+ });
55
+ return f(n.length > 0 ? n[0] : e.types[0], t, r);
56
+ }
57
+ if (i & s.TypeFlags.StringLiteral) return e.value;
58
+ if (i & s.TypeFlags.String) return "";
59
+ if (i & s.TypeFlags.NumberLiteral) return e.value;
60
+ if (i & s.TypeFlags.Number) return 0;
61
+ if (i & s.TypeFlags.BooleanLiteral) return e.intrinsicName === "true";
62
+ if (i & s.TypeFlags.Boolean) return !1;
63
+ if (l.isArrayType(e)) {
64
+ r.add(e);
65
+ let n = f(e.typeArguments?.[0] || l.getAnyType(), t, r);
66
+ return n === null ? [] : [n];
67
+ }
68
+ if (e.isClassOrInterface() || i & s.TypeFlags.Object || e.getProperties().length > 0) {
69
+ r.add(e);
70
+ let n = {};
71
+ return e.getProperties().forEach((e) => {
72
+ let i = l.getTypeOfSymbolAtLocation(e, t), a = e.valueDeclaration;
73
+ i && (n[e.getName()] = f(i, a || t, r));
74
+ }), n;
75
+ }
76
+ return null;
77
+ };
78
+ return {
79
+ __typename: "LiteralValue",
80
+ value: f(d, u)
81
+ };
82
+ }, d = 2345, f = 2339, p = (e, t, n) => {
83
+ if (e.getStart() > t || e.getEnd() < n) return;
84
+ let r = e;
85
+ return e.forEachChild((e) => {
86
+ let i = p(e, t, n);
87
+ i && (r = i);
88
+ }), r;
89
+ }, m = (e, t, n) => {
90
+ if (e.start === void 0 || e.length === void 0) return !1;
91
+ let r = p(t, e.start, e.start + e.length);
92
+ if (!r) return !1;
93
+ if (e.code === d && s.isExpression(r)) {
94
+ let e = n.getTypeAtLocation(r);
95
+ if (!e.isUnion()) return !1;
96
+ let t = n.getContextualType(r);
97
+ return t ? e.types.some((e) => (e.flags & (s.TypeFlags.Null | s.TypeFlags.Undefined)) === 0 && n.isTypeAssignableTo(e, t)) : !1;
98
+ }
99
+ if (e.code === f && s.isPropertyAccessExpression(r.parent)) {
100
+ let e = n.getNonNullableType(n.getTypeAtLocation(r.parent.expression));
101
+ if (!e.isUnion()) return !1;
102
+ let t = r.getText();
103
+ return e.types.some((e) => e.getProperty(t) !== void 0);
104
+ }
105
+ return !1;
106
+ }, h = (e, t, r) => {
107
+ if (!e?.startingNodeId) return {
108
+ isValid: !1,
109
+ returnType: "void",
110
+ diagnostics: [{
111
+ nodeId: null,
112
+ parameterIndex: null,
113
+ code: 0,
114
+ message: "You need to provide a starting node to be able to execute this flow.",
115
+ severity: "error"
116
+ }]
117
+ };
118
+ if (!e.nodes?.nodes?.find((t) => t?.id == e.startingNodeId)) return {
119
+ isValid: !1,
120
+ returnType: "void",
121
+ diagnostics: [{
122
+ nodeId: null,
123
+ parameterIndex: null,
124
+ code: 0,
125
+ message: "The starting node is not linked within the flow. Please make sure the starting node is connected to the rest of the flow.",
126
+ severity: "error"
127
+ }]
128
+ };
129
+ let i = new Set(t?.map((e) => e.identifier)), a = (e.nodes?.nodes ?? []).filter((e) => e?.functionDefinition && !i.has(e.functionDefinition.identifier)).map((e) => ({
130
+ nodeId: e.id,
131
+ parameterIndex: null,
132
+ code: 0,
133
+ message: `The function definition "${e.functionDefinition.identifier}" is not reachable.`,
134
+ severity: "error"
135
+ }));
136
+ if (a.length > 0) return {
137
+ isValid: !1,
138
+ returnType: "void",
139
+ diagnostics: a
140
+ };
141
+ let s = n(e, t, r, !1, !1), l = "index.ts", u = o(l, s), d = u.getSourceFile(l), f = u.languageService.getProgram(), p = f.getTypeChecker(), h = f.getSemanticDiagnostics(d).map((e) => {
142
+ let t = c(e.messageText, "\n"), n, r = null;
143
+ if (e.start !== void 0) {
144
+ let t = d.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, l = null, u = -1;
145
+ for (; (c = s.exec(o)) !== null;) {
146
+ let t = i + c.index + c[0].length;
147
+ t <= e.start && t > u && (u = t, l = c);
148
+ }
149
+ l && (n = l[1] === "null" ? null : l[1], r = parseInt(l[2], 10));
150
+ }
151
+ let i = m(e, d, p) ? "warning" : "error";
152
+ return {
153
+ message: t,
154
+ code: e.code,
155
+ severity: i,
156
+ nodeId: n,
157
+ parameterIndex: typeof r == "number" && Number.isSafeInteger(r) ? r : null
158
+ };
159
+ }).filter((e) => e !== null);
160
+ return {
161
+ isValid: !h.some((e) => e?.severity === "error"),
162
+ returnType: "void",
163
+ diagnostics: h
164
+ };
165
+ }, g = (e, t, n) => {
166
+ let r = a(t?.value), c = `
167
+ ${i(n)}
168
+ const testValue: ${e} = ${r};
169
+ `, l = "index.ts", u = o(l, c).languageService.getSemanticDiagnostics(l).map((e) => {
170
+ let t = s.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");
171
+ return {
172
+ message: t,
173
+ code: e.code,
174
+ severity: n ? "warning" : "error"
175
+ };
176
+ });
177
+ return {
178
+ isValid: !u.some((e) => e.severity === "error"),
179
+ returnType: "void",
180
+ diagnostics: u
181
+ };
182
+ }, _ = (r, i, a, c) => {
183
+ let l = n(r, a, i), u = "index.ts", d = o(u, l), f = d.getSourceFile(u), p = d.languageService.getProgram().getTypeChecker(), m = r.nodes?.nodes?.find((e) => e?.id === c), h = c ? `fn_${m?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", g = c ? `node_${t(c)}` : `flow_${t(r.id)}`, _ = y(f), T = b(f).get(g), E = _.get(h), D = x(p, T), O = S(p, E, T), k = D?.map((e, t) => (e.flags & s.TypeFlags.Undefined) === 0 ? e : O?.[t] ?? e), A = (m?.parameters?.nodes ?? []).map((e) => e?.value != null), j = w(p, T, k, O, C(E, D, A), c ? _ : /* @__PURE__ */ new Map(), c ? a : [], A), M = v(p, T, E);
184
+ return {
185
+ nodeId: c,
186
+ parameters: j,
187
+ return: M ? e(p, T, M, Array.from(_.values()), a, !1) : { input: "generic" }
188
+ };
189
+ }, v = (e, t, n) => {
190
+ if (t?.initializer && s.isCallExpression(t.initializer)) {
191
+ let n = e.getResolvedSignature(t.initializer);
192
+ if (n) return e.getReturnTypeOfSignature(n);
193
+ }
194
+ if (n) {
195
+ let t = e.getSignatureFromDeclaration(n);
196
+ if (t) return e.getReturnTypeOfSignature(t);
197
+ }
198
+ }, y = (e) => new Map(e.statements.filter(s.isFunctionDeclaration).map((e) => [e.name.getText(), e])), b = (e) => {
199
+ let t = [];
200
+ return e.statements.forEach((e) => {
201
+ e.forEachChild(function e(n) {
202
+ s.isVariableDeclaration(n) && (n.parent.flags & s.NodeFlags.Const) !== 0 && t.push([n.name.getText(), n]), n.forEachChild(e);
203
+ });
204
+ }), new Map(t);
205
+ }, x = (e, t) => {
206
+ if (!(!t?.initializer || !s.isCallExpression(t.initializer))) return e.getResolvedSignature(t.initializer)?.parameters.map((n) => e.getTypeOfSymbolAtLocation(n, t.initializer));
207
+ }, S = (e, t, n) => {
208
+ if (!(!t || !n?.initializer)) return t.parameters.map((t) => {
209
+ let r = e.getSymbolAtLocation(t.name);
210
+ return e.getTypeOfSymbolAtLocation(r, n.initializer);
211
+ });
212
+ }, C = (e, t, n = []) => {
213
+ let r = e.typeParameters?.map((e) => e.name.getText()) || [], i = {};
214
+ e.parameters.forEach((e, t) => {
215
+ if (!e.type) return;
216
+ let n = /* @__PURE__ */ new Set();
217
+ e.type.forEachChild(function t(i) {
218
+ if (s.isTypeReferenceNode(i) && s.isIdentifier(i.typeName)) {
219
+ let e = i.typeName.text;
220
+ r.includes(e) && n.add(e);
221
+ }
222
+ if (s.isTypeReferenceNode(e.type) && s.isIdentifier(e.type.typeName)) {
223
+ let t = e.type.typeName.text;
224
+ r.includes(t) && n.add(t);
225
+ }
226
+ i.forEachChild(t);
227
+ }), n.forEach((e) => {
228
+ i[e] || (i[e] = []), i[e].push(t);
229
+ });
230
+ });
231
+ let a = Object.values(i).filter((e) => e.length > 1).map(([e, ...t]) => t.map((t) => ({
232
+ parameterIndex: t,
233
+ dependsOnIndex: e
234
+ }))).flat();
235
+ return t ? a.filter((e) => {
236
+ if (n[e.dependsOnIndex]) return !1;
237
+ let r = t[e.parameterIndex];
238
+ if (!r) return !0;
239
+ let i = (r.flags & s.TypeFlags.Null) !== 0, a = (r.flags & s.TypeFlags.Undefined) !== 0;
240
+ return i || a;
241
+ }) : a;
242
+ }, w = (t, n, i, a, o, s, c, l) => i ? i.map((i, u) => {
243
+ let d = a?.[u], f = d ? T(t, d, n) : void 0, p = e(t, n, i, Array.from(s.values()), c, !0, f);
244
+ return {
245
+ schema: r(d ? e(t, n, d, Array.from(s.values()), c, !1) : void 0, p, l[u] ?? !1),
246
+ blockedBy: o.filter((e) => e.parameterIndex === u).map((e) => e.dependsOnIndex)
247
+ };
248
+ }) : [], T = (e, t, n) => {
249
+ if ((t.flags & s.TypeFlags.TypeParameter) !== 0) {
250
+ let n = t.symbol?.declarations?.[0];
251
+ return n && s.isTypeParameterDeclaration(n) && n.constraint ? e.getTypeFromTypeNode(n.constraint) : e.getAnyType();
252
+ }
253
+ if ((t.flags & s.TypeFlags.Conditional) !== 0) return e.getBaseConstraintOfType(t) ?? e.getAnyType();
254
+ if ((t.flags & s.TypeFlags.Object) !== 0 && E(t, e, /* @__PURE__ */ new Set())) {
255
+ let r = t.aliasSymbol?.getName();
256
+ if (r) {
257
+ let t = e.getSymbolsInScope(n, s.SymbolFlags.Variable).find((e) => e.getName() === `__widen_${r}`);
258
+ if (t) return e.getTypeOfSymbolAtLocation(t, n);
259
+ }
260
+ return e.getAnyType();
261
+ }
262
+ return t;
263
+ }, E = (e, t, n) => n.has(e) ? !1 : (n.add(e), !!((e.flags & s.TypeFlags.TypeParameter) !== 0 || (e.flags & s.TypeFlags.Object) !== 0 && (t.getTypeArguments(e).some((e) => E(e, t, n)) || e.aliasTypeArguments?.some((e) => E(e, t, n))))), D = (t, n = []) => {
264
+ let r = "index.ts", a = o(r, `${i(n)}\ntype MyType = ${t}`).languageService.getProgram(), c = a?.getSourceFile(r), l = a?.getTypeChecker();
265
+ if (!c || !l) return;
266
+ let u = c.statements.filter((e) => s.isTypeAliasDeclaration(e) || s.isInterfaceDeclaration(e) || s.isClassDeclaration(e)).pop();
267
+ if (!u) return;
268
+ let d = l.getTypeAtLocation(u);
269
+ if (d) return e(l, void 0, d, [], [], !1);
270
+ };
271
+ //#endregion
272
+ export { h as getFlowValidation, _ as getSignatureSchema, l as getTypeFromValue, D as getTypeSchema, u as getValueFromType, g as getValueValidation };
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./utils-C3jpxxXK.cjs");let t=require("typescript");t=e.c(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.t(a,e.n(t,n,r)),s=o.getSourceFile(a),c=o.languageService.getProgram().getTypeChecker(),d=i({...f(c,s),...p(c,s,t)},r),m=(t.nodes?.nodes??[]).map(e=>e&&v(e,d));return{...t,inputSchema:d[l]??g(),outputSchema:d[u]??_(),nodes:{...t.nodes,nodes:m}}},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}=h(e,i,r);return{[l]:a,[u]:o}},p=(e,t,n)=>{let r=S(t),i={};for(let t of n.nodes?.nodes??[]){if(!t?.id)continue;let n=t.parameters?.nodes;if(!n?.some(y))continue;let a=x(r,t),o=a?e.getResolvedSignature(a):void 0;o&&n.forEach((n,r)=>{if(!y(n))return;let s=m(e,o,a,r);if(!s)return;let{input:c,output:l}=h(e,s,a);i[d(t.id,r,`input`)]=c,i[d(t.id,r,`output`)]=l})}return i},m=(e,t,n,r)=>{let i=t.parameters[r];if(i)return e.getTypeOfSymbolAtLocation(i,n).getCallSignatures()[0]},h=(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=b(t)?`?`:``;return`${t.getName()}${a}: ${i(n)}`}).join(`; `)} }`,output:i(e.getReturnTypeOfSignature(n))}},g=()=>({type:`object`}),_=()=>({}),v=(e,t)=>{let n=e.parameters?.nodes;if(!n?.some(y))return e;let r=n.map((n,r)=>{if(!y(n))return n;let i={...n.value,inputSchema:t[d(e.id,r,`input`)]??g(),outputSchema:t[d(e.id,r,`output`)]??_()};return{...n,value:i}});return{...e,parameters:{...e.parameters,nodes:r}}},y=e=>e?.value?.__typename===`SubFlowValue`,b=e=>{let n=e.valueDeclaration;return!!n&&t.default.isParameter(n)&&(!!n.questionToken||!!n.initializer||!!n.dotDotDotToken)},x=(n,r)=>{let i=n.get(`node_${e.i(r.id)}`)?.initializer;return i&&t.default.isCallExpression(i)?i:void 0},S=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;
@@ -0,0 +1,2 @@
1
+ export * from './extraction/getFlowSchemas';
2
+ export type { JsonSchema } from './util/jsonSchema.util';
@@ -0,0 +1,123 @@
1
+ import { i as e, n as t, r as n, t as r } from "./utils-B8zuiBhE.js";
2
+ import i from "typescript";
3
+ import { DEFAULT_CONFIG as a, SchemaGenerator as o, createFormatter as s, createParser as c } from "ts-json-schema-generator";
4
+ //#region src/util/jsonSchema.util.ts
5
+ var l = {
6
+ ...a,
7
+ expose: "none",
8
+ topRef: !1,
9
+ jsDoc: "none",
10
+ skipTypeCheck: !0
11
+ }, u = (e, t) => {
12
+ let n = Object.keys(e);
13
+ if (n.length === 0) return {};
14
+ let r = f(d(e, t)), i = {};
15
+ for (let e of n) try {
16
+ i[e] = p(r.createSchema(e));
17
+ } catch {
18
+ i[e] = {};
19
+ }
20
+ return i;
21
+ }, d = (e, t) => {
22
+ let r = Object.entries(e).map(([e, t]) => `export type ${e} = ${t};`).join("\n");
23
+ return `${n(t)}\n${r}`;
24
+ }, f = (e) => {
25
+ let t = r("index.ts", e).languageService.getProgram();
26
+ return new o(t, c(t, l), s(l), l);
27
+ }, p = (e) => {
28
+ let { $schema: t, definitions: n, ...r } = e, i = n && Object.keys(n).length > 0 ? {
29
+ ...r,
30
+ definitions: n
31
+ } : r;
32
+ return JSON.parse(JSON.stringify(i));
33
+ }, m = (e, n, i) => {
34
+ if (!e) return;
35
+ let a = "index.ts", o = r(a, t(e, n, i)), s = o.getSourceFile(a), c = o.languageService.getProgram().getTypeChecker(), l = u({
36
+ ...v(c, s),
37
+ ...y(c, s, e)
38
+ }, i), d = (e.nodes?.nodes ?? []).map((e) => e && w(e, l));
39
+ return {
40
+ ...e,
41
+ inputSchema: l[h] ?? S(),
42
+ outputSchema: l[g] ?? C(),
43
+ nodes: {
44
+ ...e.nodes,
45
+ nodes: d
46
+ }
47
+ };
48
+ }, h = "Flow_input", g = "Flow_output", _ = (t, n, r) => `Node_${e(t)}_${n}_${r}`, v = (e, t) => {
49
+ let n = t.statements.filter(i.isFunctionDeclaration).find((e) => e.name?.getText() === "flow");
50
+ if (!n) return {};
51
+ let r = e.getSignatureFromDeclaration(n);
52
+ if (!r) return {};
53
+ let { input: a, output: o } = x(e, r, n);
54
+ return {
55
+ [h]: a,
56
+ [g]: o
57
+ };
58
+ }, y = (e, t, n) => {
59
+ let r = O(t), i = {};
60
+ for (let t of n.nodes?.nodes ?? []) {
61
+ if (!t?.id) continue;
62
+ let n = t.parameters?.nodes;
63
+ if (!n?.some(T)) continue;
64
+ let a = D(r, t), o = a ? e.getResolvedSignature(a) : void 0;
65
+ o && n.forEach((n, r) => {
66
+ if (!T(n)) return;
67
+ let s = b(e, o, a, r);
68
+ if (!s) return;
69
+ let { input: c, output: l } = x(e, s, a);
70
+ i[_(t.id, r, "input")] = c, i[_(t.id, r, "output")] = l;
71
+ });
72
+ }
73
+ return i;
74
+ }, b = (e, t, n, r) => {
75
+ let i = t.parameters[r];
76
+ if (i) return e.getTypeOfSymbolAtLocation(i, n).getCallSignatures()[0];
77
+ }, x = (e, t, n) => {
78
+ let r = (t) => e.typeToString(t, n, i.TypeFormatFlags.NoTruncation);
79
+ return {
80
+ input: `{ ${t.parameters.map((t) => {
81
+ let i = e.getTypeOfSymbolAtLocation(t, t.valueDeclaration ?? n), a = E(t) ? "?" : "";
82
+ return `${t.getName()}${a}: ${r(i)}`;
83
+ }).join("; ")} }`,
84
+ output: r(e.getReturnTypeOfSignature(t))
85
+ };
86
+ }, S = () => ({ type: "object" }), C = () => ({}), w = (e, t) => {
87
+ let n = e.parameters?.nodes;
88
+ if (!n?.some(T)) return e;
89
+ let r = n.map((n, r) => {
90
+ if (!T(n)) return n;
91
+ let i = {
92
+ ...n.value,
93
+ inputSchema: t[_(e.id, r, "input")] ?? S(),
94
+ outputSchema: t[_(e.id, r, "output")] ?? C()
95
+ };
96
+ return {
97
+ ...n,
98
+ value: i
99
+ };
100
+ });
101
+ return {
102
+ ...e,
103
+ parameters: {
104
+ ...e.parameters,
105
+ nodes: r
106
+ }
107
+ };
108
+ }, T = (e) => e?.value?.__typename === "SubFlowValue", E = (e) => {
109
+ let t = e.valueDeclaration;
110
+ return !!t && i.isParameter(t) && (!!t.questionToken || !!t.initializer || !!t.dotDotDotToken);
111
+ }, D = (t, n) => {
112
+ let r = t.get(`node_${e(n.id)}`)?.initializer;
113
+ return r && i.isCallExpression(r) ? r : void 0;
114
+ }, O = (e) => {
115
+ let t = /* @__PURE__ */ new Map();
116
+ return e.statements.forEach((e) => {
117
+ e.forEachChild(function e(n) {
118
+ i.isVariableDeclaration(n) && (n.parent.flags & i.NodeFlags.Const) !== 0 && t.set(n.name.getText(), n), n.forEachChild(e);
119
+ });
120
+ }), t;
121
+ };
122
+ //#endregion
123
+ export { m as getFlowSchemas };
@@ -0,0 +1,18 @@
1
+ import { Schema } from 'ts-json-schema-generator';
2
+ import { DataType } from '@code0-tech/sagittarius-graphql-types';
3
+ /** A generated JSON Schema, as produced by {@link generateJsonSchemas}. */
4
+ export type JsonSchema = Schema;
5
+ /**
6
+ * Generates JSON schemas for a batch of named TypeScript type expressions.
7
+ *
8
+ * The type strings (e.g. `"{ item: { test: number } }"` or `"NUMBER"`) are
9
+ * resolved through the same shared data-type declarations the rest of the
10
+ * library uses, then handed to `ts-json-schema-generator` for the actual JSON
11
+ * Schema generation — no schema shape is hand-built here.
12
+ *
13
+ * @param typeExpressions - Map of alias name to TypeScript type expression
14
+ * @param dataTypes - Data type definitions used to resolve named types/generics
15
+ * @returns Map of the same alias names to their generated JSON schema; an alias
16
+ * that fails to generate maps to the open schema `{}`
17
+ */
18
+ export declare const generateJsonSchemas: (typeExpressions: Record<string, string>, dataTypes?: DataType[]) => Record<string, JsonSchema>;