@code0-tech/triangulum 0.13.2 → 0.14.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.d.ts +1 -6
- package/dist/schema/getSignatureSchema.d.ts +34 -0
- package/dist/triangulum.cjs.js +18 -36
- package/dist/triangulum.es.js +227 -315
- package/dist/util/nodes.util.d.ts +27 -0
- package/dist/util/references.util.d.ts +20 -0
- package/dist/util/schema.util.d.ts +104 -0
- package/dist/util/values.util.d.ts +23 -0
- package/dist/utils.d.ts +0 -8
- package/package.json +1 -1
- package/dist/extraction/getTypeVariant.d.ts +0 -19
- package/dist/extraction/getTypesFromFunction.d.ts +0 -9
- package/dist/extraction/getTypesFromNode.d.ts +0 -9
- package/dist/suggestion/getNodeSuggestions.d.ts +0 -6
- package/dist/suggestion/getReferenceSuggestions.d.ts +0 -16
- package/dist/suggestion/getValueSuggestions.d.ts +0 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
export * from './extraction/getTypeFromValue';
|
|
2
|
-
export * from './extraction/getTypeVariant';
|
|
3
2
|
export * from './extraction/getValueFromType';
|
|
4
|
-
export * from './extraction/getTypesFromNode';
|
|
5
|
-
export * from './extraction/getTypesFromFunction';
|
|
6
|
-
export * from './suggestion/getNodeSuggestions';
|
|
7
|
-
export * from './suggestion/getReferenceSuggestions';
|
|
8
|
-
export * from './suggestion/getValueSuggestions';
|
|
9
3
|
export * from './validation/getFlowValidation';
|
|
10
4
|
export * from './validation/getValueValidation';
|
|
5
|
+
export * from './schema/getSignatureSchema';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DataType, Flow, FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
+
import { Schema } from '../util/schema.util';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the schema information for a node parameter.
|
|
5
|
+
* Includes the parameter's schema definition and any parameter dependencies that block it.
|
|
6
|
+
*/
|
|
7
|
+
interface NodeSchema {
|
|
8
|
+
/** The schema definition for this node parameter */
|
|
9
|
+
schema: Schema;
|
|
10
|
+
/** Array of parameter indices that must be resolved before this parameter */
|
|
11
|
+
blockedBy?: number[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generates node schemas for all parameters of a specified function node.
|
|
15
|
+
*
|
|
16
|
+
* This function analyzes a TypeScript flow's AST to extract type information for node parameters.
|
|
17
|
+
* It resolves parameter types by combining information from both the node's call expression and
|
|
18
|
+
* the function definition, accounting for type parameters and generic constraints.
|
|
19
|
+
*
|
|
20
|
+
* @param flow - The data flow object containing nodes and their relationships
|
|
21
|
+
* @param dataTypes - Array of available data type definitions
|
|
22
|
+
* @param functions - Array of available function definitions
|
|
23
|
+
* @param nodeId - Optional specific node ID to analyze; if provided, only that node's schema is processed
|
|
24
|
+
*
|
|
25
|
+
* @returns Array of NodeSchema objects, each containing a schema and optional blocked dependencies
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const schemas = getNodeSchema(flow, dataTypes, functions, nodeId);
|
|
29
|
+
* schemas.forEach(({ schema, blockedBy }) => {
|
|
30
|
+
* console.log(`Parameter schema: ${schema}, blocked by: ${blockedBy?.join(',')}`);
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export declare const getSignatureSchema: (flow: Flow, dataTypes: DataType[], functions: FunctionDefinition[], nodeId?: NodeFunction["id"]) => NodeSchema[];
|
|
34
|
+
export {};
|
package/dist/triangulum.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`typescript`);c=s(c,1);function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l.apply(null,arguments)}var u=!1;try{u=typeof localStorage<`u`}catch{}var d=typeof process<`u`,f=u&&typeof localStorage.getItem==`function`&&localStorage.getItem(`DEBUG`)||d&&process.env.DEBUG?console.log:function(e){return``};function p(e,t,n,r,i){r===void 0&&(r={});var a=l({},g(n),r),o=
|
|
2
|
-
`,useCaseSensitiveFileNames:!0,write:function(){return m(`write`)},writeFile:function(t,n){e.set(t,n)},deleteFile:function(t){e.delete(t)}}}function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`typescript`);c=s(c,1);function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l.apply(null,arguments)}var u=!1;try{u=typeof localStorage<`u`}catch{}var d=typeof process<`u`,f=u&&typeof localStorage.getItem==`function`&&localStorage.getItem(`DEBUG`)||d&&process.env.DEBUG?console.log:function(e){return``};function p(e,t,n,r,i){r===void 0&&(r={});var a=l({},g(n),r),o=y(e,t,a,n,i),s=o.languageServiceHost,c=o.updateFile,u=o.deleteFile,d=n.createLanguageService(s),f=d.getCompilerOptionsDiagnostics();if(f.length){var p=v(e,r,n);throw Error(n.formatDiagnostics(f,p.compilerHost))}return{name:`vfs`,sys:e,languageService:d,getSourceFile:function(e){return d.getProgram()?.getSourceFile(e)},createFile:function(e,t){c(n.createSourceFile(e,t,a.target,!1))},updateFile:function(e,t,r){var i=d.getProgram().getSourceFile(e);if(!i)throw Error(`Did not find a source file for `+e);var a=i.text,o=r??n.createTextSpan(0,a.length),s=a.slice(0,o.start)+t+a.slice(o.start+o.length);c(n.updateSourceFile(i,s,{span:o,newLength:t.length}))},deleteFile:function(e){var t=d.getProgram().getSourceFile(e);t&&u(t)}}}function m(e){throw Error(`Method '`+e+`' is not implemented.`)}function h(e,t){return function(){for(var n=arguments.length,r=Array(n),i=0;i<n;i++)r[i]=arguments[i];var a=t.apply(void 0,r),o=typeof a==`string`?a.slice(0,80)+`...`:a;return f.apply(void 0,[`> `+e].concat(r)),f(`< `+o),a}}var g=function(e){return l({},e.getDefaultCompilerOptions(),{jsx:e.JsxEmit.React,strict:!0,esModuleInterop:!0,module:e.ModuleKind.ESNext,suppressOutputPathCheck:!0,skipLibCheck:!0,skipDefaultLibCheck:!0},e.versionMajorMinor&&Number(e.versionMajorMinor.split(`.`)[0])>=6?{ignoreDeprecations:`6.0`}:{moduleResolution:e.ModuleResolutionKind.NodeJs})},_=function(e){return e.replace(`/`,`/lib.`).toLowerCase()};function ee(e){return{args:[],createDirectory:function(){return m(`createDirectory`)},directoryExists:h(`directoryExists`,function(t){return Array.from(e.keys()).some(function(e){return e.startsWith(t)})}),exit:function(){return m(`exit`)},fileExists:h(`fileExists`,function(t){return e.has(t)||e.has(_(t))}),getCurrentDirectory:function(){return`/`},getDirectories:function(){return[]},getExecutingFilePath:function(){return m(`getExecutingFilePath`)},readDirectory:h(`readDirectory`,function(t){return t===`/`?Array.from(e.keys()):[]}),readFile:h(`readFile`,function(t){return e.get(t)??e.get(_(t))}),resolvePath:function(e){return e},newLine:`
|
|
2
|
+
`,useCaseSensitiveFileNames:!0,write:function(){return m(`write`)},writeFile:function(t,n){e.set(t,n)},deleteFile:function(t){e.delete(t)}}}function v(e,t,n){var r=new Map,i=function(e){return r.set(e.fileName,e),e};return{compilerHost:l({},e,{getCanonicalFileName:function(e){return e},getDefaultLibFileName:function(){return`/`+n.getDefaultLibFileName(t)},getNewLine:function(){return e.newLine},getSourceFile:function(a,o){return r.get(a)||i(n.createSourceFile(a,e.readFile(a),o??t.target??g(n).target,!1))},useCaseSensitiveFileNames:function(){return e.useCaseSensitiveFileNames}}),updateFile:function(t){var n=r.has(t.fileName);return e.writeFile(t.fileName,t.text),r.set(t.fileName,t),n},deleteFile:function(t){var n=r.has(t.fileName);return r.delete(t.fileName),e.deleteFile(t.fileName),n}}}function y(e,t,n,r,i){var a=[].concat(t),o=v(e,n,r),s=o.compilerHost,c=o.updateFile,u=o.deleteFile,d=new Map,f=0;return{languageServiceHost:l({},s,{getProjectVersion:function(){return f.toString()},getCompilationSettings:function(){return n},getCustomTransformers:function(){return i},getScriptFileNames:function(){return a.slice()},getScriptSnapshot:function(t){var n=e.readFile(t);if(n&&typeof n==`string`)return r.ScriptSnapshot.fromString(n)},getScriptVersion:function(e){return d.get(e)||`0`},writeFile:e.writeFile}),updateFile:function(e){f++,d.set(e.fileName,f.toString()),a.includes(e.fileName)||a.push(e.fileName),c(e)},deleteFile:function(e){f++,d.set(e.fileName,f.toString());var t=a.indexOf(e.fileName);t!==-1&&a.splice(t,1),u(e)}}}function b(e){return x.test(e)}var x=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function S(e,t,n,r){let i=C(n);return a(typeof t==`function`?t.call({"":e},``,e):e,``);function a(e,t){if(Array.isArray(r)){let t=r.find(t=>t.test(e));if(t){let n=t.stringify(e);if(typeof n!=`string`||!b(n))throw Error(`Invalid JSON number: output of a number stringifier must be a string containing a JSON number (output: ${n})`);return n}}if(typeof e==`boolean`||typeof e==`number`||typeof e==`string`||e===null||e instanceof Date||e instanceof Boolean||e instanceof Number||e instanceof String)return JSON.stringify(e);if(e?.isLosslessNumber||typeof e==`bigint`)return e.toString();if(Array.isArray(e))return o(e,t);if(e&&typeof e==`object`)return s(e,t)}function o(e,n){if(e.length===0)return`[]`;let r=i?n+i:void 0,o=i?`[
|
|
3
3
|
`:`[`;for(let n=0;n<e.length;n++){let s=typeof t==`function`?t.call(e,String(n),e[n]):e[n];i&&(o+=r),s!==void 0&&typeof s!=`function`?o+=a(s,r):o+=`null`,n<e.length-1&&(o+=i?`,
|
|
4
|
-
`:`,`)}return o+=i?`\n${n}]`:`]`,o}function s(e,r){if(typeof e.toJSON==`function`)return
|
|
4
|
+
`:`,`)}return o+=i?`\n${n}]`:`]`,o}function s(e,r){if(typeof e.toJSON==`function`)return S(e.toJSON(),t,n,void 0);let o=Array.isArray(t)?t.map(String):Object.keys(e);if(o.length===0)return`{}`;let s=i?r+i:void 0,l=!0,u=i?`{
|
|
5
5
|
`:`{`;for(let n of o){let r=typeof t==`function`?t.call(e,n,e[n]):e[n];if(c(n,r)){l?l=!1:u+=i?`,
|
|
6
|
-
`:`,`;let e=JSON.stringify(n);u+=i?`${s+e}: `:`${e}:`,u+=a(r,s)}}return u+=i?`\n${r}}`:`}`,u}function c(e,t){return t!==void 0&&typeof t!=`function`&&typeof t!=`symbol`}}function
|
|
6
|
+
`:`,`;let e=JSON.stringify(n);u+=i?`${s+e}: `:`${e}:`,u+=a(r,s)}}return u+=i?`\n${r}}`:`}`,u}function c(e,t){return t!==void 0&&typeof t!=`function`&&typeof t!=`symbol`}}function C(e){if(typeof e==`number`)return` `.repeat(e);if(typeof e==`string`&&e!==``)return e}var w=`
|
|
7
7
|
interface Array<T> {
|
|
8
8
|
[n: number]: T;
|
|
9
9
|
length: number;
|
|
@@ -23,51 +23,33 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
import ReturnType = Utils.ReturnType;
|
|
26
|
-
`;function
|
|
26
|
+
`;function T(e,t){let n=new Map;return n.set(e,t),n.set(`lib.codezero.d.ts`,w),p(ee(n),[e,`lib.codezero.d.ts`],c.default,E)}var E={target:c.default.ScriptTarget.Latest,lib:[`lib.codezero.d.ts`],noEmit:!0,strictNullChecks:!0};function D(e,t=`any`,n=!0){let r=Array.from(new Set(e?.flatMap(e=>e.genericKeys||[]))).map(e=>`type ${e} = ${t};`).join(`
|
|
27
27
|
`),i=e?.map(e=>`type ${e.identifier}${(e.genericKeys?.length??0)>0?`<${e.genericKeys?.join(`,`)}>`:``} = ${e.type};`).join(`
|
|
28
|
-
`);return`${n?r:``}\n${i}`}var
|
|
28
|
+
`);return`${n?r:``}\n${i}`}var O=e=>e?.replace(/[^a-zA-Z0-9]/g,`_`);function k(e,t,n,r=!1){let i=e?.nodes?.nodes||[],a=new Map(t?.map(e=>[e.identifier,e])),o=new Set,s=(t,n=``)=>{let c=i.find(e=>e?.id===t);if(!c||!c.functionDefinition)return``;if(o.add(t),!a.get(c.functionDefinition.identifier))return`${n}// Error: Function ${c.functionDefinition.identifier} not found\n`;let l=(c.parameters?.nodes||[]).map((i,a)=>{let o=i.value;if(!o)return r?`/* @pos ${t} ${a} */ {}`:`/* @pos ${t} ${a} */ undefined`;if(o.__typename===`ReferenceValue`){let n=o,r=typeof n.inputIndex==`number`?`p_${O(n.nodeFunctionId??`undefined`)}_${n.parameterIndex}[${n.inputIndex}]`:n.nodeFunctionId?`node_${O(n.nodeFunctionId)}`:`flow_${O(e?.id??`undefined`)}`;return n.referencePath?.forEach(e=>{r+=`?.${e.path}`}),`/* @pos ${t} ${a} */ ${r}`}if(o.__typename===`LiteralValue`)return`/* @pos ${t} ${a} */ ${S(o?.value)}`;if(o.__typename===`NodeFunctionIdWrapper`){let e=o;return`/* @pos ${t} ${a} */ (...${`p_${O(t)}_${a}`}) => {\n${s(e.id,n+` `)}${n}}`}return r?`/* @pos ${t} ${a} */ {}`:`/* @pos ${t} ${a} */ undefined`}),u=`node_${O(c.id)}`,d=`fn_${c?.functionDefinition?.identifier?.replace(/::/g,`_`)}`;l.includes(`undefined`);let f=`${n}`;return c.functionDefinition.identifier===`std::control::return`?f+=`return /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`:c.functionDefinition.identifier===`std::control::if`?(f+=`const ${u} = /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`,f+=`if(${l[0]}) {
|
|
29
29
|
${s(c.parameters?.nodes?.[1]?.value?.id,n+` `)}
|
|
30
|
-
}
|
|
30
|
+
}`):c.functionDefinition.identifier===`std::control::if_else`?(f+=`const ${u} = /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`,f+=`if(${l[0]}) {
|
|
31
31
|
${s(c.parameters?.nodes?.[1]?.value?.id,n+` `)}
|
|
32
32
|
} else {
|
|
33
33
|
${s(c.parameters?.nodes?.[2]?.value?.id,n+` `)}
|
|
34
|
-
}
|
|
34
|
+
}`):f+=`const ${u} = /* @pos ${t} null */ ${d}(${l.join(`, `)}) ;\n`,c.nextNodeId&&(f+=s(c.nextNodeId,n)),f},c=D(n),l=`declare function flow${e?.signature??`(): void`}`,u=t?.map(e=>`declare function fn_${e.identifier?.replace(/::/g,`_`)}${e.signature}`).join(`
|
|
35
35
|
`),d=new Set(i.map(e=>e?.nextNodeId).filter(e=>!!e)),f=new Set;return i.forEach(e=>e?.parameters?.nodes?.forEach(e=>{e?.value?.__typename===`NodeFunctionIdWrapper`&&e.value.id&&f.add(e.value.id)})),`
|
|
36
36
|
${c}\n
|
|
37
37
|
${l}\n
|
|
38
38
|
${u}\n
|
|
39
39
|
(() =>
|
|
40
|
-
${e?`const flow_${
|
|
40
|
+
${e?`const flow_${O(e.id??``)} = /* @pos null null */ flow(${e.settings?.nodes?.map((e,t)=>`/* @pos null ${t} */ ${S(e?.value)}`).join(`, `)??``});`:``}
|
|
41
41
|
${i.filter(e=>e?.id&&!d.has(e.id)&&!f.has(e.id)).map(e=>s(e.id)).join(`
|
|
42
42
|
`)}
|
|
43
43
|
)();
|
|
44
|
-
`}
|
|
45
|
-
${
|
|
44
|
+
`}var te=(e,t)=>{let n=S(e?.value);if(!n)return`any`;let r=`
|
|
45
|
+
${D(t,`unknown`)}
|
|
46
46
|
const tempValue = ${n??`any`};
|
|
47
|
-
`,i=`index.ts`,a=
|
|
48
|
-
|
|
49
|
-
${u?`type TargetType = ${u};`:``}
|
|
50
|
-
const val: TargetType = {} as any;
|
|
51
|
-
`,f=`index.ts`,p=E(f,d),m=p.getSourceFile(f),h=p.languageService.getProgram().getTypeChecker(),g=N.TYPE,_=e=>{if(c.default.isVariableDeclaration(e)&&e.name.getText()===`val`){let t=h.getTypeAtLocation(e);g=t.getCallSignatures().length>0?N.NODE:h.isArrayType(t)?N.ARRAY:t.isStringLiteral()||t.isNumberLiteral()||(t.getFlags()&(c.default.TypeFlags.String|c.default.TypeFlags.Number|c.default.TypeFlags.Boolean|c.default.TypeFlags.EnumLiteral|c.default.TypeFlags.BigInt|c.default.TypeFlags.ESSymbol))!==0?N.PRIMITIVE:t.isClassOrInterface()||(t.getFlags()&c.default.TypeFlags.Object)!==0?N.OBJECT:N.TYPE}c.default.forEachChild(e,_)};_(m),s.push({identifier:l,variant:g})}return s},F=(e,t)=>{let n=`
|
|
52
|
-
${O(t)}
|
|
47
|
+
`,i=`index.ts`,a=T(i,r),o=a.getSourceFile(i),s=a.languageService.getProgram().getTypeChecker(),l=`any`,u=e=>{if(c.default.isVariableDeclaration(e)&&e.name.getText()===`tempValue`){let t=s.getTypeAtLocation(e),n=s.getSymbolsInScope(e,c.default.SymbolFlags.TypeAlias),r=t=>{if(t.isUnion()){let e=t.types.map(r);return Array.from(new Set(e)).sort().join(` | `)}if(s.isArrayType(t)){let e=t.typeArguments||[],n=e.length>0?r(e[0]):`any`;return e[0]?.isUnion()?`(${n})[]`:`${n}[]`}if(t.getFlags()&c.default.TypeFlags.Object||t.isClassOrInterface()){let n=s.getPropertiesOfType(t);if(n.length>0)return`{ ${n.map(t=>{let n=s.getTypeOfSymbolAtLocation(t,e);return`${t.getName()}: ${r(n)}`}).join(`, `)} }`}let i=n.filter(e=>s.isTypeAssignableTo(t,s.getDeclaredTypeOfSymbol(e)));return i.length>0?i.sort((e,t)=>{let n=s.getDeclaredTypeOfSymbol(e),r=s.getDeclaredTypeOfSymbol(t),i=s.isTypeAssignableTo(n,r),a=s.isTypeAssignableTo(r,n);return i&&!a?-1:a&&!i?1:e.getName().length-t.getName().length||e.getName().localeCompare(t.getName())})[0].getName():s.typeToString(t,e)};l=r(t)}c.default.forEachChild(e,u)};return u(o),l},ne=(e,t)=>{let n=`
|
|
48
|
+
${D(t)}
|
|
53
49
|
type Target = ${e};
|
|
54
|
-
`,r=`index.ts`,i=
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
${t?.map((e,t)=>`
|
|
58
|
-
declare function Fu${t}${e.signature};
|
|
59
|
-
type F${t} = ReturnType<typeof Fu${t}${a(e.signature)>0?`<${Array(a(e.signature)).fill(`any`).join(`, `)}>`:``}>;
|
|
60
|
-
`).join(`
|
|
61
|
-
`)}
|
|
62
|
-
${t?.map((e,t)=>`const check${t}: TargetType = {} as F${t};`).join(`
|
|
63
|
-
`)}
|
|
64
|
-
`,o=`index.ts`,s=E(o,i),c=s.getSourceFile(o),l=s.languageService.getProgram().getSemanticDiagnostics(),u=new Set;l.forEach(e=>{e.file===c&&e.start!==void 0&&u.add(c.getLineAndCharacterOfPosition(e.start).line)}),r=t.filter((e,t)=>{let n=`const check${t}: TargetType = {} as F${t};`,r=i.split(`
|
|
65
|
-
`).findIndex(e=>e.includes(n));return r!==-1&&!u.has(r)})}return r?.map(e=>({__typename:`NodeFunction`,id:`gid://sagittarius/NodeFunction/1`,functionDefinition:{__typename:`FunctionDefinition`,id:e.id,identifier:e.identifier},parameters:{__typename:`NodeParameterConnection`,nodes:(e.parameterDefinitions?.nodes||[]).map(e=>({__typename:`NodeParameter`,parameterDefinition:{__typename:`ParameterDefinition`,id:e?.id,identifier:e?.identifier},value:e?.defaultValue?{__typename:`LiteralValue`,value:e.defaultValue.value}:null}))}})).filter(e=>e!==null)??[]},z=e=>{let t=c.default.TypeFlags.String|c.default.TypeFlags.Number|c.default.TypeFlags.Boolean|c.default.TypeFlags.Undefined|c.default.TypeFlags.Null|c.default.TypeFlags.BigInt|c.default.TypeFlags.ESSymbol;return(e.flags&t)===0},B=(e,t,n,r=[])=>{let i=[];if(t.isTypeAssignableTo(e,n)&&i.push({path:r,type:e}),z(e)){let a=e.getProperties();a&&a.length>0&&a.forEach(e=>{let a=t.getTypeOfSymbolAtLocation(e,e.valueDeclaration),o=e.getName(),s=[...r,{path:o}];i.push(...B(a,t,n,s))})}return i},V=(e,t,n,r,i)=>{let a=e?.nodes?.nodes?.findIndex(e=>e?.id==t);typeof a==`number`&&a>=0&&typeof n==`number`&&n>=0&&e?.nodes?.nodes?.[a]?.parameters?.nodes?.[n]&&(e.nodes.nodes[a].parameters.nodes[n].value=null);let o=A(e,r,i,!0),s=`index.ts`,l=E(s,o),u=l.getSourceFile(s),d=l.languageService.getProgram().getTypeChecker(),f=u.getFullText(),p=`/* @pos ${t} ${n} */`,m=f.indexOf(p)+p.length;function h(e,t){let n=e;return c.default.forEachChild(e,e=>{e.getStart(u,!0)<=t&&e.getEnd()>=t&&(n=h(e,t))}),n}let g=h(u,m),_;if(c.default.isCallExpression(g)&&(_=g),!_)return[];let v=d.getResolvedSignature(_);if(!v)return[];let y=v.getParameters(),b=y[n]||y[y.length-1],x=d.getTypeOfSymbolAtLocation(b,g),S=d.getSymbolsInScope(g,c.default.SymbolFlags.Variable),C=[];return S.forEach(e=>{let t=e.getName();if(!t.startsWith(`node_`)&&!t.startsWith(`p_`)&&!t.startsWith(`flow_`))return;let n=e.valueDeclaration||e.declarations?.[0];if(!n||n.getEnd()>=m)return;let r=d.getTypeOfSymbolAtLocation(e,g);if(t.startsWith(`node_`)){if((r.flags&c.default.TypeFlags.Void)===0){let e=t.replace(`node_`,``).replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`);B(r,d,x).forEach(({path:t})=>{let n={__typename:`ReferenceValue`,nodeFunctionId:e};t.length>0&&(n.referencePath=t),C.push(n)})}}else if(t.startsWith(`p_`)){let e=t.replace(`p_`,``),n=e.lastIndexOf(`_`),i=e.substring(0,n),a=parseInt(e.substring(n+1),10),o=i.replace(`p_`,``).replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`);if(d.isTupleType(r)){let e=r;d.getTypeArguments(e).forEach((t,n)=>{B(t,d,x).forEach(({path:t})=>{let r={__typename:`ReferenceValue`,nodeFunctionId:o,parameterIndex:isNaN(a)?0:a,inputIndex:n,inputTypeIdentifier:e.target.labeledElementDeclarations?.[n].name.getText()};t.length>0&&(r.referencePath=t),C.push(r)})})}}else t.startsWith(`flow_`)&&B(r,d,x).forEach(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:null};e.length>0&&(t.referencePath=e),C.push(t)})}),C},H=(e,t)=>{if(!e)return[];let n=`
|
|
66
|
-
${O(t)}
|
|
67
|
-
type VALUE = ${e}; const val: VALUE = {} as any;
|
|
68
|
-
`,r=`index.ts`,i=E(r,n),a=i.getSourceFile(r),o=i.languageService.getProgram().getTypeChecker(),s=a.statements.find(e=>c.default.isTypeAliasDeclaration(e)&&e.name.text===`VALUE`);if(!s||!c.default.isTypeAliasDeclaration(s))return[];let l=o.getTypeAtLocation(s),u=e=>e.isUnion()?e.types.flatMap(u):e.isStringLiteral()?[e.value]:e.isNumberLiteral()?[e.value.toString()]:e.intrinsicName===`true`?[`true`]:e.intrinsicName===`false`?[`false`]:[];return Array.from(new Set(u(l))).map(e=>({__typename:`LiteralValue`,value:e}))},U=(e,t,n)=>{if(!e?.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(!e.nodes?.nodes?.find(t=>t?.id==e.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 r=A(e,t,n),i=`index.ts`,a=E(i,r),o=a.getSourceFile(i),s=a.languageService.getProgram().getSemanticDiagnostics(o).map(e=>{let t=(0,c.flattenDiagnosticMessageText)(e.messageText,`
|
|
69
|
-
`),n,r=null;if(e.start!==void 0){let t=o.getFullText(),i=Math.max(0,e.start-300),a=Math.min(t.length,e.start),s=t.substring(i,a),c=/\/\* @pos ([^ ]+) (\d+|null) \*\//g,l,u=null,d=-1;for(;(l=c.exec(s))!==null;){let t=i+l.index+l[0].length;t<=e.start&&t>d&&(d=t,u=l)}u&&(n=u[1]===`null`?null:u[1],r=parseInt(u[2],10))}return{message:t,code:e.code,severity:`error`,nodeId:n,parameterIndex:typeof r==`number`&&Number.isSafeInteger(r)?r:null}}).filter(e=>e!==null);return{isValid:!s.some(e=>e?.severity===`error`),returnType:`void`,diagnostics:s}},W=(e,t,n)=>{let r=C(t?.value),i=`
|
|
70
|
-
${O(n)}
|
|
50
|
+
`,r=`index.ts`,i=T(r,n),a=i.getSourceFile(r),o=i.languageService.getProgram().getTypeChecker(),s=a.statements.find(e=>c.default.isTypeAliasDeclaration(e)&&e.name.text===`Target`);if(!s)return{__typename:`LiteralValue`,value:null};let l=o.getTypeAtLocation(s.type),u=(e,t,n=new Set)=>{let r=new Set(n);if(r.has(e))return null;let i=e.getFlags();if(e.isUnion()){if(t.type,c.default.isTypeAliasDeclaration(t)&&t.type&&c.default.isUnionTypeNode(t.type))return u(o.getTypeFromTypeNode(t.type.types[0]),t,r);let n=e.types.filter(e=>{let t=e.getFlags();return!(t&c.default.TypeFlags.Undefined)&&!(t&c.default.TypeFlags.Null)});return u(n.length>0?n[0]:e.types[0],t,r)}if(i&c.default.TypeFlags.StringLiteral)return e.value;if(i&c.default.TypeFlags.String)return``;if(i&c.default.TypeFlags.NumberLiteral)return e.value;if(i&c.default.TypeFlags.Number)return 0;if(i&c.default.TypeFlags.BooleanLiteral)return e.intrinsicName===`true`;if(i&c.default.TypeFlags.Boolean)return!1;if(o.isArrayType(e)){r.add(e);let n=u(e.typeArguments?.[0]||o.getAnyType(),t,r);return n===null?[]:[n]}if(e.isClassOrInterface()||i&c.default.TypeFlags.Object||e.getProperties().length>0){r.add(e);let n={};return e.getProperties().forEach(e=>{let i=o.getTypeOfSymbolAtLocation(e,t),a=e.valueDeclaration;i&&(n[e.getName()]=u(i,a||t,r))}),n}return null};return{__typename:`LiteralValue`,value:u(l,s)}},A=(e,t,n)=>{if(!e?.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(!e.nodes?.nodes?.find(t=>t?.id==e.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 r=k(e,t,n),i=`index.ts`,a=T(i,r),o=a.getSourceFile(i),s=a.languageService.getProgram().getSemanticDiagnostics(o).map(e=>{let t=(0,c.flattenDiagnosticMessageText)(e.messageText,`
|
|
51
|
+
`),n,r=null;if(e.start!==void 0){let t=o.getFullText(),i=Math.max(0,e.start-300),a=Math.min(t.length,e.start),s=t.substring(i,a),c=/\/\* @pos ([^ ]+) (\d+|null) \*\//g,l,u=null,d=-1;for(;(l=c.exec(s))!==null;){let t=i+l.index+l[0].length;t<=e.start&&t>d&&(d=t,u=l)}u&&(n=u[1]===`null`?null:u[1],r=parseInt(u[2],10))}return{message:t,code:e.code,severity:`error`,nodeId:n,parameterIndex:typeof r==`number`&&Number.isSafeInteger(r)?r:null}}).filter(e=>e!==null);return{isValid:!s.some(e=>e?.severity===`error`),returnType:`void`,diagnostics:s}},j=(e,t,n)=>{let r=S(t?.value),i=`
|
|
52
|
+
${D(n)}
|
|
71
53
|
const testValue: ${e} = ${r};
|
|
72
|
-
`,a=`index.ts`,o=
|
|
73
|
-
`),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`);return{message:t,code:e.code,severity:n?`warning`:`error`}});return{isValid:!o.some(e=>e.severity===`error`),returnType:`void`,diagnostics:o}};
|
|
54
|
+
`,a=`index.ts`,o=T(a,i).languageService.getSemanticDiagnostics(a).map(e=>{let t=c.default.flattenDiagnosticMessageText(e.messageText,`
|
|
55
|
+
`),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`);return{message:t,code:e.code,severity:n?`warning`:`error`}});return{isValid:!o.some(e=>e.severity===`error`),returnType:`void`,diagnostics:o}},M=e=>e.isUnion()?e.types.flatMap(M):e.isStringLiteral()?[{value:e.value,__typename:`LiteralValue`}]:e.isNumberLiteral()?[{value:e.value.toString()}]:e.intrinsicName===`true`?[{value:`true`,__typename:`LiteralValue`}]:e.intrinsicName===`false`?[{value:`false`,__typename:`LiteralValue`}]:[],N=(e,t,n,r)=>r.flatMap(r=>{let i=r.getName();if(!P(i))return[];let a=r.getDeclarations()?.[0];if(!a||a.getEnd()>=t.getEnd())return[];let o=e.getTypeOfSymbolAtLocation(r,t);return i.startsWith(`node_`)?F(i,o,e,n):i.startsWith(`p_`)?I(i,o,e,n):i.startsWith(`flow_`)?L(o,e,n):[]}),P=e=>e.startsWith(`node_`)||e.startsWith(`p_`)||e.startsWith(`flow_`),F=(e,t,n,r)=>{if((t.flags&c.default.TypeFlags.Void)!==0)return[];let i=R(e.replace(`node_`,``));return B(t,n,r).flatMap(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:i};return e.length>0&&(t.referencePath=e),t})},I=(e,t,n,r)=>{let{nodeFunctionId:i,paramIndexFromName:a}=z(e);if(!n.isTupleType(t))return[];let o=t;return n.getTypeArguments(o).flatMap((e,t)=>B(e,n,r).flatMap(({path:e})=>{let n={__typename:`ReferenceValue`,nodeFunctionId:i,parameterIndex:isNaN(a)?0:a,inputIndex:t,inputTypeIdentifier:o.target.labeledElementDeclarations?.[t].name.getText()};return e.length>0&&(n.referencePath=e),n}))},L=(e,t,n)=>B(e,t,n).flatMap(({path:e})=>{let t={__typename:`ReferenceValue`,nodeFunctionId:null};return e.length>0&&(t.referencePath=e),t}),R=e=>e.replace(/___/g,`://`).replace(/__/g,`/`).replace(/_/g,`/`),z=e=>{let t=e.replace(`p_`,``),n=t.lastIndexOf(`_`),r=t.substring(0,n),i=parseInt(t.substring(n+1),10);return{nodeFunctionId:R(r),paramIndexFromName:i}},B=(e,t,n,r=[])=>{let i=[];if(t.isTypeAssignableTo(e,n)&&i.push({path:r,type:e}),V(e)){let a=e.getProperties();a&&a.length>0&&a.forEach(e=>{let a=t.getTypeOfSymbolAtLocation(e,e.valueDeclaration),o=e.getName(),s=[...r,{path:o}];i.push(...B(a,t,n,s))})}return i},V=e=>{let t=c.default.TypeFlags.String|c.default.TypeFlags.Number|c.default.TypeFlags.Boolean|c.default.TypeFlags.Undefined|c.default.TypeFlags.Null|c.default.TypeFlags.BigInt|c.default.TypeFlags.ESSymbol;return(e.flags&t)===0},H=(e,t,n,r)=>Q(r)?[]:t.flatMap(t=>{let i=U(e,t,n,r);return i?[i]:[]}),U=(e,t,n,r)=>{let i=e.getSignatureFromDeclaration(t),a=W(e,e.getReturnTypeOfSignature(i));if(!e.isTypeAssignableTo(a,r))return null;let o=G(t.name?.getText());return re(n.find(e=>e.identifier===o))},W=(e,t)=>t.isTypeParameter()?e.getBaseConstraintOfType(t)||e.getAnyType():t,G=e=>e?e.replace(`fn_`,``).replace(`_`,`::`).replace(`_`,`::`):``,re=e=>{let t=(e?.parameterDefinitions?.nodes?.length??0)>0,n={__typename:`NodeFunction`,id:`gid://sagittarius/NodeFunction/1`,functionDefinition:{__typename:`FunctionDefinition`,id:e?.id,identifier:e?.identifier}};return t&&(n.parameters=K(e?.parameterDefinitions?.nodes||[])),n},K=e=>({__typename:`NodeParameterConnection`,nodes:e.map(e=>q(e))}),q=e=>({__typename:`NodeParameter`,parameterDefinition:{__typename:`ParameterDefinition`,id:e?.id,identifier:e?.identifier},value:e?.defaultValue?{__typename:`LiteralValue`,value:e.defaultValue.value}:null}),J=(e,t,n,r,i)=>{let a=M(n),o=N(e,t,n,e.getSymbolsInScope(t,c.default.SymbolFlags.Variable)),s=H(e,r,i,n),l={suggestions:[...a,...o,...s]};if(ae(n))return{input:`select`,...l};if(Y(n))return{input:`boolean`,...l};if(X(n))return{input:`number`,...l};if(Z(n))return{input:`text`,...l};if(Q(n))return{input:`sub-flow`,...l};if(oe(e,n)){let a=e.getTypeArguments(n)[0],o=(a.isUnion()?a.types:[a]).map(n=>J(e,t,n,r,i));return{input:`list`,items:o.length===1?o[0]:o,...l}}if((n.flags&c.default.TypeFlags.Object)!==0){let a={},o=[];for(let s of e.getPropertiesOfType(n)){let n=s.valueDeclaration??s.declarations?.[0];if(!n)continue;let l=e.getTypeOfSymbolAtLocation(s,n),u=(s.flags&c.default.SymbolFlags.Optional)!==0||l.isUnion()&&l.types.some(e=>(e.flags&c.default.TypeFlags.Undefined)!==0),d=(l.isUnion()?l.types.filter(e=>(e.flags&c.default.TypeFlags.Undefined)===0):[l]).map(n=>J(e,t,n,r,i));a[s.name]=d.length===1?d[0]:d,u||o.push(s.name)}return{input:`data`,properties:a,required:o,...l}}return{input:`generic`}};function Y(e){return(e.flags&c.default.TypeFlags.Boolean)!==0||(e.flags&c.default.TypeFlags.BooleanLiteral)!==0}function X(e){return(e.flags&c.default.TypeFlags.Number)!==0||(e.flags&c.default.TypeFlags.NumberLiteral)!==0}function Z(e){return(e.flags&c.default.TypeFlags.String)!==0||(e.flags&c.default.TypeFlags.StringLiteral)!==0}function ie(e){return Z(e)||X(e)||Y(e)}function ae(e){return e.isUnion()?e.types.every(ie):!1}function oe(e,t){return e.isArrayType(t)||e.isTupleType(t)}function Q(e){return e.getCallSignatures().length>0}var $=(e,t,n,r)=>{let i=k(e,n,t),a=`index.ts`,o=T(a,i),s=o.getSourceFile(a),c=o.languageService.getProgram().getTypeChecker(),l=e.nodes?.nodes?.find(e=>e?.id===r),u=r?`fn_${l?.functionDefinition?.identifier?.replace(/::/g,`_`)}`:`flow`,d=r?`node_${O(r)}`:`flow_${O(e.id)}`,f=se(s),p=ce(s).get(d),m=f.get(u),h=le(c,p);return pe(c,p,de(c,ue(c,m,p),h),fe(m),r?f:new Map,r?n:[])},se=e=>new Map(e.statements.filter(c.default.isFunctionDeclaration).map(e=>[e.name.getText(),e])),ce=e=>{let t=[];return e.statements.forEach(e=>{e.forEachChild(function e(n){c.default.isVariableDeclaration(n)&&(n.parent.flags&c.default.NodeFlags.Const)!==0&&t.push([n.name.getText(),n]),n.forEachChild(e)})}),new Map(t)},le=(e,t)=>{if(!(!t?.initializer||!c.default.isCallExpression(t.initializer)))return e.getResolvedSignature(t.initializer)?.parameters.map(n=>e.getTypeOfSymbolAtLocation(n,t.initializer))},ue=(e,t,n)=>{if(!(!t||!n?.initializer))return t.parameters.map(t=>{let r=e.getSymbolAtLocation(t.name);return e.getTypeOfSymbolAtLocation(r,n.initializer)})},de=(e,t,n)=>{if(t)return t.map((t,r)=>{let i=n?.[r];if(!i)return t;let a=t.getSymbol(),o=i.getSymbol();if(a&&o&&a===o)return i;if(t.isTypeParameter()){let n=e.getBaseConstraintOfType(t);if(!n||e.isTypeAssignableTo(i,n))return i}return e.isTypeAssignableTo(i,t)?i:t})},fe=e=>{let t=e.typeParameters?.map(e=>e.name.getText())||[],n={};return e.parameters.forEach((e,r)=>{let i=e.type?.getText()||``;t.forEach(e=>{i.includes(e)&&(n[e]||(n[e]=[]),n[e].push(r))})}),Object.values(n).filter(e=>e.length>1).map(([e,...t])=>t.map(t=>({parameterIndex:t,dependsOnIndex:e}))).flat()},pe=(e,t,n,r,i,a)=>n?n.map((n,o)=>({schema:J(e,t,n,Array.from(i.values()),a),blockedBy:r.filter(e=>e.parameterIndex===o).map(e=>e.dependsOnIndex)})):[];exports.getFlowValidation=A,exports.getSignatureSchema=$,exports.getTypeFromValue=te,exports.getValueFromType=ne,exports.getValueValidation=j;
|
package/dist/triangulum.es.js
CHANGED
|
@@ -259,7 +259,7 @@ function x(e, t = "any", n = !0) {
|
|
|
259
259
|
let r = Array.from(new Set(e?.flatMap((e) => e.genericKeys || []))).map((e) => `type ${e} = ${t};`).join("\n"), i = e?.map((e) => `type ${e.identifier}${(e.genericKeys?.length ?? 0) > 0 ? `<${e.genericKeys?.join(",")}>` : ""} = ${e.type};`).join("\n");
|
|
260
260
|
return `${n ? r : ""}\n${i}`;
|
|
261
261
|
}
|
|
262
|
-
var S = (e) => e
|
|
262
|
+
var S = (e) => e?.replace(/[^a-zA-Z0-9]/g, "_");
|
|
263
263
|
function C(e, t, n, r = !1) {
|
|
264
264
|
let i = e?.nodes?.nodes || [], a = new Map(t?.map((e) => [e.identifier, e])), o = /* @__PURE__ */ new Set(), s = (t, n = "") => {
|
|
265
265
|
let c = i.find((e) => e?.id === t);
|
|
@@ -283,13 +283,13 @@ function C(e, t, n, r = !1) {
|
|
|
283
283
|
}), u = `node_${S(c.id)}`, d = `fn_${c?.functionDefinition?.identifier?.replace(/::/g, "_")}`;
|
|
284
284
|
l.includes("undefined");
|
|
285
285
|
let f = `${n}`;
|
|
286
|
-
return c.functionDefinition.identifier === "std::control::return" ? f += `return /* @pos ${t} null */ ${d}(${l.join(", ")}) ;\n` : c.functionDefinition.identifier === "std::control::if" ? f +=
|
|
286
|
+
return c.functionDefinition.identifier === "std::control::return" ? f += `return /* @pos ${t} null */ ${d}(${l.join(", ")}) ;\n` : c.functionDefinition.identifier === "std::control::if" ? (f += `const ${u} = /* @pos ${t} null */ ${d}(${l.join(", ")}) ;\n`, f += `if(${l[0]}) {
|
|
287
287
|
${s(c.parameters?.nodes?.[1]?.value?.id, n + " ")}
|
|
288
|
-
}` : c.functionDefinition.identifier === "std::control::if_else" ? f +=
|
|
288
|
+
}`) : c.functionDefinition.identifier === "std::control::if_else" ? (f += `const ${u} = /* @pos ${t} null */ ${d}(${l.join(", ")}) ;\n`, f += `if(${l[0]}) {
|
|
289
289
|
${s(c.parameters?.nodes?.[1]?.value?.id, n + " ")}
|
|
290
290
|
} else {
|
|
291
291
|
${s(c.parameters?.nodes?.[2]?.value?.id, n + " ")}
|
|
292
|
-
}` : f += `const ${u} = /* @pos ${t} null */ ${d}(${l.join(", ")}) ;\n`, c.nextNodeId && (f += s(c.nextNodeId, n)), f;
|
|
292
|
+
}`) : f += `const ${u} = /* @pos ${t} null */ ${d}(${l.join(", ")}) ;\n`, c.nextNodeId && (f += s(c.nextNodeId, n)), f;
|
|
293
293
|
}, c = x(n), l = `declare function flow${e?.signature ?? "(): void"}`, u = t?.map((e) => `declare function fn_${e.identifier?.replace(/::/g, "_")}${e.signature}`).join("\n"), d = new Set(i.map((e) => e?.nextNodeId).filter((e) => !!e)), f = /* @__PURE__ */ new Set();
|
|
294
294
|
return i.forEach((e) => e?.parameters?.nodes?.forEach((e) => {
|
|
295
295
|
e?.value?.__typename === "NodeFunctionIdWrapper" && e.value.id && f.add(e.value.id);
|
|
@@ -303,39 +303,9 @@ function C(e, t, n, r = !1) {
|
|
|
303
303
|
)();
|
|
304
304
|
`;
|
|
305
305
|
}
|
|
306
|
-
function w(t, n, r) {
|
|
307
|
-
let i = C(t, n, r, !0), a = "index.ts", o = y(a, i), s = o.getSourceFile(a), c = o.languageService.getProgram().getTypeChecker(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
|
|
308
|
-
(t?.nodes?.nodes || []).forEach((e) => {
|
|
309
|
-
e?.id && d.set(S(e.id), e);
|
|
310
|
-
});
|
|
311
|
-
let f = (t) => {
|
|
312
|
-
if (e.isVariableDeclaration(t) && t.name.getText().startsWith("node_")) {
|
|
313
|
-
let n = t.name.getText().replace("node_", ""), r = c.getTypeAtLocation(t);
|
|
314
|
-
if (l.set(n, c.typeToString(r, t, e.TypeFormatFlags.NoTruncation)), t.initializer && e.isCallExpression(t.initializer)) {
|
|
315
|
-
let r = c.getResolvedSignature(t.initializer);
|
|
316
|
-
if (r) {
|
|
317
|
-
let i = r.getParameters().map((n) => {
|
|
318
|
-
let r = c.getTypeOfSymbolAtLocation(n, t.initializer);
|
|
319
|
-
return c.typeToString(r, t.initializer, e.TypeFormatFlags.NoTruncation);
|
|
320
|
-
});
|
|
321
|
-
u.set(n, i);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
if (e.isReturnStatement(t) && t.expression && e.isCallExpression(t.expression)) {
|
|
326
|
-
let e = t.expression;
|
|
327
|
-
c.getResolvedSignature(e);
|
|
328
|
-
}
|
|
329
|
-
e.forEachChild(t, f);
|
|
330
|
-
};
|
|
331
|
-
return f(s), {
|
|
332
|
-
nodes: l,
|
|
333
|
-
parameters: u
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
306
|
//#endregion
|
|
337
307
|
//#region src/extraction/getTypeFromValue.ts
|
|
338
|
-
var
|
|
308
|
+
var w = (t, n) => {
|
|
339
309
|
let r = g(t?.value);
|
|
340
310
|
if (!r) return "any";
|
|
341
311
|
let i = `
|
|
@@ -370,32 +340,7 @@ var T = (t, n) => {
|
|
|
370
340
|
e.forEachChild(t, u);
|
|
371
341
|
};
|
|
372
342
|
return u(s), l;
|
|
373
|
-
},
|
|
374
|
-
return e[e.PRIMITIVE = 0] = "PRIMITIVE", e[e.TYPE = 1] = "TYPE", e[e.ARRAY = 2] = "ARRAY", e[e.OBJECT = 3] = "OBJECT", e[e.NODE = 4] = "NODE", e;
|
|
375
|
-
}({}), D = (t, n) => {
|
|
376
|
-
let r = x(n), i = typeof t == "string", a = Array.isArray(t), o = a ? t : i ? [{
|
|
377
|
-
identifier: t,
|
|
378
|
-
type: t
|
|
379
|
-
}] : [t], s = a ? t.map((e) => e.identifier) : i ? [t] : [t.identifier], c = [];
|
|
380
|
-
for (let n = 0; n < o.length; n++) {
|
|
381
|
-
let a = o[n], l = s[n], u = i ? t : a.type, d = `
|
|
382
|
-
${r}
|
|
383
|
-
${u ? `type TargetType = ${u};` : ""}
|
|
384
|
-
const val: TargetType = {} as any;
|
|
385
|
-
`, f = "index.ts", p = y(f, d), m = p.getSourceFile(f), h = p.languageService.getProgram().getTypeChecker(), g = E.TYPE, _ = (t) => {
|
|
386
|
-
if (e.isVariableDeclaration(t) && t.name.getText() === "val") {
|
|
387
|
-
let n = h.getTypeAtLocation(t);
|
|
388
|
-
g = n.getCallSignatures().length > 0 ? E.NODE : h.isArrayType(n) ? E.ARRAY : n.isStringLiteral() || n.isNumberLiteral() || (n.getFlags() & (e.TypeFlags.String | e.TypeFlags.Number | e.TypeFlags.Boolean | e.TypeFlags.EnumLiteral | e.TypeFlags.BigInt | e.TypeFlags.ESSymbol)) !== 0 ? E.PRIMITIVE : n.isClassOrInterface() || (n.getFlags() & e.TypeFlags.Object) !== 0 ? E.OBJECT : E.TYPE;
|
|
389
|
-
}
|
|
390
|
-
e.forEachChild(t, _);
|
|
391
|
-
};
|
|
392
|
-
_(m), c.push({
|
|
393
|
-
identifier: l,
|
|
394
|
-
variant: g
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
return c;
|
|
398
|
-
}, O = (t, n) => {
|
|
343
|
+
}, T = (t, n) => {
|
|
399
344
|
let r = `
|
|
400
345
|
${x(n)}
|
|
401
346
|
type Target = ${t};
|
|
@@ -441,258 +386,7 @@ var T = (t, n) => {
|
|
|
441
386
|
__typename: "LiteralValue",
|
|
442
387
|
value: u(l, c)
|
|
443
388
|
};
|
|
444
|
-
},
|
|
445
|
-
if (!e) return {
|
|
446
|
-
parameters: [],
|
|
447
|
-
returnType: "any"
|
|
448
|
-
};
|
|
449
|
-
let r = e.id || "temp_node_id", i = {
|
|
450
|
-
...e,
|
|
451
|
-
id: r,
|
|
452
|
-
parameters: {
|
|
453
|
-
...e.parameters,
|
|
454
|
-
nodes: e.parameters?.nodes?.map((e) => e?.value ? e : {
|
|
455
|
-
...e,
|
|
456
|
-
value: null
|
|
457
|
-
}) || []
|
|
458
|
-
}
|
|
459
|
-
}, a = r + "_params", o = w({
|
|
460
|
-
id: "gid://sagittarius/Flow/0",
|
|
461
|
-
nodes: {
|
|
462
|
-
__typename: "NodeFunctionConnection",
|
|
463
|
-
nodes: [i, {
|
|
464
|
-
...i,
|
|
465
|
-
id: a,
|
|
466
|
-
parameters: {
|
|
467
|
-
...i.parameters,
|
|
468
|
-
nodes: i.parameters.nodes.map((e) => e.value?.__typename === "LiteralValue" && e.value.value !== null && typeof e.value.value != "object" ? {
|
|
469
|
-
...e,
|
|
470
|
-
value: null
|
|
471
|
-
} : e)
|
|
472
|
-
}
|
|
473
|
-
}]
|
|
474
|
-
}
|
|
475
|
-
}, t, n), s = S(r), c = S(a), l = o.parameters.get(s) || [], u = o.parameters.get(c) || [];
|
|
476
|
-
return {
|
|
477
|
-
parameters: l.map((e, t) => {
|
|
478
|
-
let n = u[t];
|
|
479
|
-
return n && n !== "any" && n !== "unknown" ? n : e;
|
|
480
|
-
}),
|
|
481
|
-
returnType: o.nodes.get(s) || "any"
|
|
482
|
-
};
|
|
483
|
-
}, A = (e) => {
|
|
484
|
-
let t = e.signature;
|
|
485
|
-
if (!t) return {
|
|
486
|
-
parameters: [],
|
|
487
|
-
returnType: "any"
|
|
488
|
-
};
|
|
489
|
-
let n = 0;
|
|
490
|
-
if (t.trim().startsWith("<")) {
|
|
491
|
-
let e = 0;
|
|
492
|
-
for (let r = 0; r < t.length; r++) {
|
|
493
|
-
let i = t[r];
|
|
494
|
-
if (i === "<") e++;
|
|
495
|
-
else if (i === ">" && (e--, e === 0)) {
|
|
496
|
-
n = r + 1;
|
|
497
|
-
break;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
let r = t.indexOf("(", n);
|
|
502
|
-
if (r === -1) return {
|
|
503
|
-
parameters: [],
|
|
504
|
-
returnType: "any"
|
|
505
|
-
};
|
|
506
|
-
let i = -1, a = 0;
|
|
507
|
-
for (let e = r; e < t.length; e++) {
|
|
508
|
-
let n = t[e];
|
|
509
|
-
if (n === "(") a++;
|
|
510
|
-
else if (n === ")" && (a--, a === 0)) {
|
|
511
|
-
i = e;
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
if (i === -1) return {
|
|
516
|
-
parameters: [],
|
|
517
|
-
returnType: "any"
|
|
518
|
-
};
|
|
519
|
-
let o = t.substring(r + 1, i), s = t.substring(i + 1).trim();
|
|
520
|
-
s.startsWith(":") && (s = s.substring(1).trim());
|
|
521
|
-
let c = s || "void", l = [];
|
|
522
|
-
if (o.trim()) {
|
|
523
|
-
let e = "", t = 0, n = 0, r = 0, i = 0, a = (e) => {
|
|
524
|
-
let t = -1, n = 0, r = 0, i = 0, a = 0;
|
|
525
|
-
for (let o = 0; o < e.length; o++) {
|
|
526
|
-
let s = e[o];
|
|
527
|
-
if (s === "{") n++;
|
|
528
|
-
else if (s === "}") n--;
|
|
529
|
-
else if (s === "[") r++;
|
|
530
|
-
else if (s === "]") r--;
|
|
531
|
-
else if (s === "(") i++;
|
|
532
|
-
else if (s === ")") i--;
|
|
533
|
-
else if (s === "<") a++;
|
|
534
|
-
else if (s === ">") a--;
|
|
535
|
-
else if (s === ":" && n === 0 && r === 0 && i === 0 && a === 0) {
|
|
536
|
-
t = o;
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
t === -1 ? l.push("any") : l.push(e.substring(t + 1).trim());
|
|
541
|
-
};
|
|
542
|
-
for (let s of o) {
|
|
543
|
-
if (s === "(") t++;
|
|
544
|
-
else if (s === ")") t--;
|
|
545
|
-
else if (s === "<") n++;
|
|
546
|
-
else if (s === ">") n--;
|
|
547
|
-
else if (s === "{") r++;
|
|
548
|
-
else if (s === "}") r--;
|
|
549
|
-
else if (s === "[") i++;
|
|
550
|
-
else if (s === "]") i--;
|
|
551
|
-
else if (s === "," && t === 0 && n === 0 && r === 0 && i === 0) {
|
|
552
|
-
a(e.trim()), e = "";
|
|
553
|
-
continue;
|
|
554
|
-
}
|
|
555
|
-
e += s;
|
|
556
|
-
}
|
|
557
|
-
e.trim() && a(e.trim());
|
|
558
|
-
}
|
|
559
|
-
return {
|
|
560
|
-
parameters: l,
|
|
561
|
-
returnType: c
|
|
562
|
-
};
|
|
563
|
-
}, j = (e, t, n) => {
|
|
564
|
-
let r = t, i = e ? D(e, n)[0].variant : null;
|
|
565
|
-
if (e && t && i !== E.NODE) {
|
|
566
|
-
function i(e) {
|
|
567
|
-
let t = e.trim().match(/^<([^>]+)>/);
|
|
568
|
-
return t ? t[1].split(",").map((e) => e.trim()).filter(Boolean).length : 0;
|
|
569
|
-
}
|
|
570
|
-
let a = `
|
|
571
|
-
${x(n)}
|
|
572
|
-
type TargetType = ${e};
|
|
573
|
-
${t?.map((e, t) => `
|
|
574
|
-
declare function Fu${t}${e.signature};
|
|
575
|
-
type F${t} = ReturnType<typeof Fu${t}${i(e.signature) > 0 ? `<${Array(i(e.signature)).fill("any").join(", ")}>` : ""}>;
|
|
576
|
-
`).join("\n")}
|
|
577
|
-
${t?.map((e, t) => `const check${t}: TargetType = {} as F${t};`).join("\n")}
|
|
578
|
-
`, o = "index.ts", s = y(o, a), c = s.getSourceFile(o), l = s.languageService.getProgram().getSemanticDiagnostics(), u = /* @__PURE__ */ new Set();
|
|
579
|
-
l.forEach((e) => {
|
|
580
|
-
e.file === c && e.start !== void 0 && u.add(c.getLineAndCharacterOfPosition(e.start).line);
|
|
581
|
-
}), r = t.filter((e, t) => {
|
|
582
|
-
let n = `const check${t}: TargetType = {} as F${t};`, r = a.split("\n").findIndex((e) => e.includes(n));
|
|
583
|
-
return r !== -1 && !u.has(r);
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
return r?.map((e) => ({
|
|
587
|
-
__typename: "NodeFunction",
|
|
588
|
-
id: "gid://sagittarius/NodeFunction/1",
|
|
589
|
-
functionDefinition: {
|
|
590
|
-
__typename: "FunctionDefinition",
|
|
591
|
-
id: e.id,
|
|
592
|
-
identifier: e.identifier
|
|
593
|
-
},
|
|
594
|
-
parameters: {
|
|
595
|
-
__typename: "NodeParameterConnection",
|
|
596
|
-
nodes: (e.parameterDefinitions?.nodes || []).map((e) => ({
|
|
597
|
-
__typename: "NodeParameter",
|
|
598
|
-
parameterDefinition: {
|
|
599
|
-
__typename: "ParameterDefinition",
|
|
600
|
-
id: e?.id,
|
|
601
|
-
identifier: e?.identifier
|
|
602
|
-
},
|
|
603
|
-
value: e?.defaultValue ? {
|
|
604
|
-
__typename: "LiteralValue",
|
|
605
|
-
value: e.defaultValue.value
|
|
606
|
-
} : null
|
|
607
|
-
}))
|
|
608
|
-
}
|
|
609
|
-
})).filter((e) => e !== null) ?? [];
|
|
610
|
-
}, M = (t) => {
|
|
611
|
-
let n = e.TypeFlags.String | e.TypeFlags.Number | e.TypeFlags.Boolean | e.TypeFlags.Undefined | e.TypeFlags.Null | e.TypeFlags.BigInt | e.TypeFlags.ESSymbol;
|
|
612
|
-
return (t.flags & n) === 0;
|
|
613
|
-
}, N = (e, t, n, r = []) => {
|
|
614
|
-
let i = [];
|
|
615
|
-
if (t.isTypeAssignableTo(e, n) && i.push({
|
|
616
|
-
path: r,
|
|
617
|
-
type: e
|
|
618
|
-
}), M(e)) {
|
|
619
|
-
let a = e.getProperties();
|
|
620
|
-
a && a.length > 0 && a.forEach((e) => {
|
|
621
|
-
let a = t.getTypeOfSymbolAtLocation(e, e.valueDeclaration), o = e.getName(), s = [...r, { path: o }];
|
|
622
|
-
i.push(...N(a, t, n, s));
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
return i;
|
|
626
|
-
}, P = (t, n, r, i, a) => {
|
|
627
|
-
let o = t?.nodes?.nodes?.findIndex((e) => e?.id == n);
|
|
628
|
-
typeof o == "number" && o >= 0 && typeof r == "number" && r >= 0 && t?.nodes?.nodes?.[o]?.parameters?.nodes?.[r] && (t.nodes.nodes[o].parameters.nodes[r].value = null);
|
|
629
|
-
let s = C(t, i, a, !0), c = "index.ts", l = y(c, s), u = l.getSourceFile(c), d = l.languageService.getProgram().getTypeChecker(), f = u.getFullText(), p = `/* @pos ${n} ${r} */`, m = f.indexOf(p) + p.length;
|
|
630
|
-
function h(t, n) {
|
|
631
|
-
let r = t;
|
|
632
|
-
return e.forEachChild(t, (e) => {
|
|
633
|
-
e.getStart(u, !0) <= n && e.getEnd() >= n && (r = h(e, n));
|
|
634
|
-
}), r;
|
|
635
|
-
}
|
|
636
|
-
let g = h(u, m), _;
|
|
637
|
-
if (e.isCallExpression(g) && (_ = g), !_) return [];
|
|
638
|
-
let v = d.getResolvedSignature(_);
|
|
639
|
-
if (!v) return [];
|
|
640
|
-
let b = v.getParameters(), x = b[r] || b[b.length - 1], S = d.getTypeOfSymbolAtLocation(x, g), w = d.getSymbolsInScope(g, e.SymbolFlags.Variable), T = [];
|
|
641
|
-
return w.forEach((t) => {
|
|
642
|
-
let n = t.getName();
|
|
643
|
-
if (!n.startsWith("node_") && !n.startsWith("p_") && !n.startsWith("flow_")) return;
|
|
644
|
-
let r = t.valueDeclaration || t.declarations?.[0];
|
|
645
|
-
if (!r || r.getEnd() >= m) return;
|
|
646
|
-
let i = d.getTypeOfSymbolAtLocation(t, g);
|
|
647
|
-
if (n.startsWith("node_")) {
|
|
648
|
-
if ((i.flags & e.TypeFlags.Void) === 0) {
|
|
649
|
-
let e = n.replace("node_", "").replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/");
|
|
650
|
-
N(i, d, S).forEach(({ path: t }) => {
|
|
651
|
-
let n = {
|
|
652
|
-
__typename: "ReferenceValue",
|
|
653
|
-
nodeFunctionId: e
|
|
654
|
-
};
|
|
655
|
-
t.length > 0 && (n.referencePath = t), T.push(n);
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
} else if (n.startsWith("p_")) {
|
|
659
|
-
let e = n.replace("p_", ""), t = e.lastIndexOf("_"), r = e.substring(0, t), a = parseInt(e.substring(t + 1), 10), o = r.replace("p_", "").replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/");
|
|
660
|
-
if (d.isTupleType(i)) {
|
|
661
|
-
let e = i;
|
|
662
|
-
d.getTypeArguments(e).forEach((t, n) => {
|
|
663
|
-
N(t, d, S).forEach(({ path: t }) => {
|
|
664
|
-
let r = {
|
|
665
|
-
__typename: "ReferenceValue",
|
|
666
|
-
nodeFunctionId: o,
|
|
667
|
-
parameterIndex: isNaN(a) ? 0 : a,
|
|
668
|
-
inputIndex: n,
|
|
669
|
-
inputTypeIdentifier: e.target.labeledElementDeclarations?.[n].name.getText()
|
|
670
|
-
};
|
|
671
|
-
t.length > 0 && (r.referencePath = t), T.push(r);
|
|
672
|
-
});
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
} else n.startsWith("flow_") && N(i, d, S).forEach(({ path: e }) => {
|
|
676
|
-
let t = {
|
|
677
|
-
__typename: "ReferenceValue",
|
|
678
|
-
nodeFunctionId: null
|
|
679
|
-
};
|
|
680
|
-
e.length > 0 && (t.referencePath = e), T.push(t);
|
|
681
|
-
});
|
|
682
|
-
}), T;
|
|
683
|
-
}, F = (t, n) => {
|
|
684
|
-
if (!t) return [];
|
|
685
|
-
let r = `
|
|
686
|
-
${x(n)}
|
|
687
|
-
type VALUE = ${t}; const val: VALUE = {} as any;
|
|
688
|
-
`, i = "index.ts", a = y(i, r), o = a.getSourceFile(i), s = a.languageService.getProgram().getTypeChecker(), c = o.statements.find((t) => e.isTypeAliasDeclaration(t) && t.name.text === "VALUE");
|
|
689
|
-
if (!c || !e.isTypeAliasDeclaration(c)) return [];
|
|
690
|
-
let l = s.getTypeAtLocation(c), u = (e) => e.isUnion() ? e.types.flatMap(u) : e.isStringLiteral() ? [e.value] : e.isNumberLiteral() ? [e.value.toString()] : e.intrinsicName === "true" ? ["true"] : e.intrinsicName === "false" ? ["false"] : [];
|
|
691
|
-
return Array.from(new Set(u(l))).map((e) => ({
|
|
692
|
-
__typename: "LiteralValue",
|
|
693
|
-
value: e
|
|
694
|
-
}));
|
|
695
|
-
}, I = (e, n, r) => {
|
|
389
|
+
}, E = (e, n, r) => {
|
|
696
390
|
if (!e?.startingNodeId) return {
|
|
697
391
|
isValid: !1,
|
|
698
392
|
returnType: "void",
|
|
@@ -738,7 +432,7 @@ var T = (t, n) => {
|
|
|
738
432
|
returnType: "void",
|
|
739
433
|
diagnostics: c
|
|
740
434
|
};
|
|
741
|
-
},
|
|
435
|
+
}, D = (t, n, r) => {
|
|
742
436
|
let i = g(n?.value), a = `
|
|
743
437
|
${x(r)}
|
|
744
438
|
const testValue: ${t} = ${i};
|
|
@@ -755,6 +449,224 @@ var T = (t, n) => {
|
|
|
755
449
|
returnType: "void",
|
|
756
450
|
diagnostics: s
|
|
757
451
|
};
|
|
452
|
+
}, O = (e) => e.isUnion() ? e.types.flatMap(O) : e.isStringLiteral() ? [{
|
|
453
|
+
value: e.value,
|
|
454
|
+
__typename: "LiteralValue"
|
|
455
|
+
}] : e.isNumberLiteral() ? [{ value: e.value.toString() }] : e.intrinsicName === "true" ? [{
|
|
456
|
+
value: "true",
|
|
457
|
+
__typename: "LiteralValue"
|
|
458
|
+
}] : e.intrinsicName === "false" ? [{
|
|
459
|
+
value: "false",
|
|
460
|
+
__typename: "LiteralValue"
|
|
461
|
+
}] : [], k = (e, t, n, r) => r.flatMap((r) => {
|
|
462
|
+
let i = r.getName();
|
|
463
|
+
if (!A(i)) return [];
|
|
464
|
+
let a = r.getDeclarations()?.[0];
|
|
465
|
+
if (!a || a.getEnd() >= t.getEnd()) return [];
|
|
466
|
+
let o = e.getTypeOfSymbolAtLocation(r, t);
|
|
467
|
+
return i.startsWith("node_") ? j(i, o, e, n) : i.startsWith("p_") ? M(i, o, e, n) : i.startsWith("flow_") ? N(o, e, n) : [];
|
|
468
|
+
}), A = (e) => e.startsWith("node_") || e.startsWith("p_") || e.startsWith("flow_"), j = (t, n, r, i) => {
|
|
469
|
+
if ((n.flags & e.TypeFlags.Void) !== 0) return [];
|
|
470
|
+
let a = P(t.replace("node_", ""));
|
|
471
|
+
return I(n, r, i).flatMap(({ path: e }) => {
|
|
472
|
+
let t = {
|
|
473
|
+
__typename: "ReferenceValue",
|
|
474
|
+
nodeFunctionId: a
|
|
475
|
+
};
|
|
476
|
+
return e.length > 0 && (t.referencePath = e), t;
|
|
477
|
+
});
|
|
478
|
+
}, M = (e, t, n, r) => {
|
|
479
|
+
let { nodeFunctionId: i, paramIndexFromName: a } = F(e);
|
|
480
|
+
if (!n.isTupleType(t)) return [];
|
|
481
|
+
let o = t;
|
|
482
|
+
return n.getTypeArguments(o).flatMap((e, t) => I(e, n, r).flatMap(({ path: e }) => {
|
|
483
|
+
let n = {
|
|
484
|
+
__typename: "ReferenceValue",
|
|
485
|
+
nodeFunctionId: i,
|
|
486
|
+
parameterIndex: isNaN(a) ? 0 : a,
|
|
487
|
+
inputIndex: t,
|
|
488
|
+
inputTypeIdentifier: o.target.labeledElementDeclarations?.[t].name.getText()
|
|
489
|
+
};
|
|
490
|
+
return e.length > 0 && (n.referencePath = e), n;
|
|
491
|
+
}));
|
|
492
|
+
}, N = (e, t, n) => I(e, t, n).flatMap(({ path: e }) => {
|
|
493
|
+
let t = {
|
|
494
|
+
__typename: "ReferenceValue",
|
|
495
|
+
nodeFunctionId: null
|
|
496
|
+
};
|
|
497
|
+
return e.length > 0 && (t.referencePath = e), t;
|
|
498
|
+
}), P = (e) => e.replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/"), F = (e) => {
|
|
499
|
+
let t = e.replace("p_", ""), n = t.lastIndexOf("_"), r = t.substring(0, n), i = parseInt(t.substring(n + 1), 10);
|
|
500
|
+
return {
|
|
501
|
+
nodeFunctionId: P(r),
|
|
502
|
+
paramIndexFromName: i
|
|
503
|
+
};
|
|
504
|
+
}, I = (e, t, n, r = []) => {
|
|
505
|
+
let i = [];
|
|
506
|
+
if (t.isTypeAssignableTo(e, n) && i.push({
|
|
507
|
+
path: r,
|
|
508
|
+
type: e
|
|
509
|
+
}), L(e)) {
|
|
510
|
+
let a = e.getProperties();
|
|
511
|
+
a && a.length > 0 && a.forEach((e) => {
|
|
512
|
+
let a = t.getTypeOfSymbolAtLocation(e, e.valueDeclaration), o = e.getName(), s = [...r, { path: o }];
|
|
513
|
+
i.push(...I(a, t, n, s));
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return i;
|
|
517
|
+
}, L = (t) => {
|
|
518
|
+
let n = e.TypeFlags.String | e.TypeFlags.Number | e.TypeFlags.Boolean | e.TypeFlags.Undefined | e.TypeFlags.Null | e.TypeFlags.BigInt | e.TypeFlags.ESSymbol;
|
|
519
|
+
return (t.flags & n) === 0;
|
|
520
|
+
}, R = (e, t, n, r) => Q(r) ? [] : t.flatMap((t) => {
|
|
521
|
+
let i = z(e, t, n, r);
|
|
522
|
+
return i ? [i] : [];
|
|
523
|
+
}), z = (e, t, n, r) => {
|
|
524
|
+
let i = e.getSignatureFromDeclaration(t), a = B(e, e.getReturnTypeOfSignature(i));
|
|
525
|
+
if (!e.isTypeAssignableTo(a, r)) return null;
|
|
526
|
+
let o = V(t.name?.getText());
|
|
527
|
+
return H(n.find((e) => e.identifier === o));
|
|
528
|
+
}, B = (e, t) => t.isTypeParameter() ? e.getBaseConstraintOfType(t) || e.getAnyType() : t, V = (e) => e ? e.replace("fn_", "").replace("_", "::").replace("_", "::") : "", H = (e) => {
|
|
529
|
+
let t = (e?.parameterDefinitions?.nodes?.length ?? 0) > 0, n = {
|
|
530
|
+
__typename: "NodeFunction",
|
|
531
|
+
id: "gid://sagittarius/NodeFunction/1",
|
|
532
|
+
functionDefinition: {
|
|
533
|
+
__typename: "FunctionDefinition",
|
|
534
|
+
id: e?.id,
|
|
535
|
+
identifier: e?.identifier
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
return t && (n.parameters = U(e?.parameterDefinitions?.nodes || [])), n;
|
|
539
|
+
}, U = (e) => ({
|
|
540
|
+
__typename: "NodeParameterConnection",
|
|
541
|
+
nodes: e.map((e) => W(e))
|
|
542
|
+
}), W = (e) => ({
|
|
543
|
+
__typename: "NodeParameter",
|
|
544
|
+
parameterDefinition: {
|
|
545
|
+
__typename: "ParameterDefinition",
|
|
546
|
+
id: e?.id,
|
|
547
|
+
identifier: e?.identifier
|
|
548
|
+
},
|
|
549
|
+
value: e?.defaultValue ? {
|
|
550
|
+
__typename: "LiteralValue",
|
|
551
|
+
value: e.defaultValue.value
|
|
552
|
+
} : null
|
|
553
|
+
}), G = (t, n, r, i, a) => {
|
|
554
|
+
let o = O(r), s = k(t, n, r, t.getSymbolsInScope(n, e.SymbolFlags.Variable)), c = R(t, i, a, r), l = { suggestions: [
|
|
555
|
+
...o,
|
|
556
|
+
...s,
|
|
557
|
+
...c
|
|
558
|
+
] };
|
|
559
|
+
if (X(r)) return {
|
|
560
|
+
input: "select",
|
|
561
|
+
...l
|
|
562
|
+
};
|
|
563
|
+
if (K(r)) return {
|
|
564
|
+
input: "boolean",
|
|
565
|
+
...l
|
|
566
|
+
};
|
|
567
|
+
if (q(r)) return {
|
|
568
|
+
input: "number",
|
|
569
|
+
...l
|
|
570
|
+
};
|
|
571
|
+
if (J(r)) return {
|
|
572
|
+
input: "text",
|
|
573
|
+
...l
|
|
574
|
+
};
|
|
575
|
+
if (Q(r)) return {
|
|
576
|
+
input: "sub-flow",
|
|
577
|
+
...l
|
|
578
|
+
};
|
|
579
|
+
if (Z(t, r)) {
|
|
580
|
+
let e = t.getTypeArguments(r)[0], o = (e.isUnion() ? e.types : [e]).map((e) => G(t, n, e, i, a));
|
|
581
|
+
return {
|
|
582
|
+
input: "list",
|
|
583
|
+
items: o.length === 1 ? o[0] : o,
|
|
584
|
+
...l
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
if ((r.flags & e.TypeFlags.Object) !== 0) {
|
|
588
|
+
let o = {}, s = [];
|
|
589
|
+
for (let c of t.getPropertiesOfType(r)) {
|
|
590
|
+
let r = c.valueDeclaration ?? c.declarations?.[0];
|
|
591
|
+
if (!r) continue;
|
|
592
|
+
let l = t.getTypeOfSymbolAtLocation(c, r), u = (c.flags & e.SymbolFlags.Optional) !== 0 || l.isUnion() && l.types.some((t) => (t.flags & e.TypeFlags.Undefined) !== 0), d = (l.isUnion() ? l.types.filter((t) => (t.flags & e.TypeFlags.Undefined) === 0) : [l]).map((e) => G(t, n, e, i, a));
|
|
593
|
+
o[c.name] = d.length === 1 ? d[0] : d, u || s.push(c.name);
|
|
594
|
+
}
|
|
595
|
+
return {
|
|
596
|
+
input: "data",
|
|
597
|
+
properties: o,
|
|
598
|
+
required: s,
|
|
599
|
+
...l
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
return { input: "generic" };
|
|
758
603
|
};
|
|
604
|
+
function K(t) {
|
|
605
|
+
return (t.flags & e.TypeFlags.Boolean) !== 0 || (t.flags & e.TypeFlags.BooleanLiteral) !== 0;
|
|
606
|
+
}
|
|
607
|
+
function q(t) {
|
|
608
|
+
return (t.flags & e.TypeFlags.Number) !== 0 || (t.flags & e.TypeFlags.NumberLiteral) !== 0;
|
|
609
|
+
}
|
|
610
|
+
function J(t) {
|
|
611
|
+
return (t.flags & e.TypeFlags.String) !== 0 || (t.flags & e.TypeFlags.StringLiteral) !== 0;
|
|
612
|
+
}
|
|
613
|
+
function Y(e) {
|
|
614
|
+
return J(e) || q(e) || K(e);
|
|
615
|
+
}
|
|
616
|
+
function X(e) {
|
|
617
|
+
return e.isUnion() ? e.types.every(Y) : !1;
|
|
618
|
+
}
|
|
619
|
+
function Z(e, t) {
|
|
620
|
+
return e.isArrayType(t) || e.isTupleType(t);
|
|
621
|
+
}
|
|
622
|
+
function Q(e) {
|
|
623
|
+
return e.getCallSignatures().length > 0;
|
|
624
|
+
}
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/schema/getSignatureSchema.ts
|
|
627
|
+
var $ = (e, t, n, r) => {
|
|
628
|
+
let i = C(e, n, t), a = "index.ts", o = y(a, i), s = o.getSourceFile(a), c = o.languageService.getProgram().getTypeChecker(), l = e.nodes?.nodes?.find((e) => e?.id === r), u = r ? `fn_${l?.functionDefinition?.identifier?.replace(/::/g, "_")}` : "flow", d = r ? `node_${S(r)}` : `flow_${S(e.id)}`, f = ee(s), p = te(s).get(d), m = f.get(u), h = ne(c, p);
|
|
629
|
+
return oe(c, p, ie(c, re(c, m, p), h), ae(m), r ? f : /* @__PURE__ */ new Map(), r ? n : []);
|
|
630
|
+
}, ee = (t) => new Map(t.statements.filter(e.isFunctionDeclaration).map((e) => [e.name.getText(), e])), te = (t) => {
|
|
631
|
+
let n = [];
|
|
632
|
+
return t.statements.forEach((t) => {
|
|
633
|
+
t.forEachChild(function t(r) {
|
|
634
|
+
e.isVariableDeclaration(r) && (r.parent.flags & e.NodeFlags.Const) !== 0 && n.push([r.name.getText(), r]), r.forEachChild(t);
|
|
635
|
+
});
|
|
636
|
+
}), new Map(n);
|
|
637
|
+
}, ne = (t, n) => {
|
|
638
|
+
if (!(!n?.initializer || !e.isCallExpression(n.initializer))) return t.getResolvedSignature(n.initializer)?.parameters.map((e) => t.getTypeOfSymbolAtLocation(e, n.initializer));
|
|
639
|
+
}, re = (e, t, n) => {
|
|
640
|
+
if (!(!t || !n?.initializer)) return t.parameters.map((t) => {
|
|
641
|
+
let r = e.getSymbolAtLocation(t.name);
|
|
642
|
+
return e.getTypeOfSymbolAtLocation(r, n.initializer);
|
|
643
|
+
});
|
|
644
|
+
}, ie = (e, t, n) => {
|
|
645
|
+
if (t) return t.map((t, r) => {
|
|
646
|
+
let i = n?.[r];
|
|
647
|
+
if (!i) return t;
|
|
648
|
+
let a = t.getSymbol(), o = i.getSymbol();
|
|
649
|
+
if (a && o && a === o) return i;
|
|
650
|
+
if (t.isTypeParameter()) {
|
|
651
|
+
let n = e.getBaseConstraintOfType(t);
|
|
652
|
+
if (!n || e.isTypeAssignableTo(i, n)) return i;
|
|
653
|
+
}
|
|
654
|
+
return e.isTypeAssignableTo(i, t) ? i : t;
|
|
655
|
+
});
|
|
656
|
+
}, ae = (e) => {
|
|
657
|
+
let t = e.typeParameters?.map((e) => e.name.getText()) || [], n = {};
|
|
658
|
+
return e.parameters.forEach((e, r) => {
|
|
659
|
+
let i = e.type?.getText() || "";
|
|
660
|
+
t.forEach((e) => {
|
|
661
|
+
i.includes(e) && (n[e] || (n[e] = []), n[e].push(r));
|
|
662
|
+
});
|
|
663
|
+
}), Object.values(n).filter((e) => e.length > 1).map(([e, ...t]) => t.map((t) => ({
|
|
664
|
+
parameterIndex: t,
|
|
665
|
+
dependsOnIndex: e
|
|
666
|
+
}))).flat();
|
|
667
|
+
}, oe = (e, t, n, r, i, a) => n ? n.map((n, o) => ({
|
|
668
|
+
schema: G(e, t, n, Array.from(i.values()), a),
|
|
669
|
+
blockedBy: r.filter((e) => e.parameterIndex === o).map((e) => e.dependsOnIndex)
|
|
670
|
+
})) : [];
|
|
759
671
|
//#endregion
|
|
760
|
-
export { E as
|
|
672
|
+
export { E as getFlowValidation, $ as getSignatureSchema, w as getTypeFromValue, T as getValueFromType, D as getValueValidation };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { default as ts } from 'typescript';
|
|
2
|
+
import { FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphql-types';
|
|
3
|
+
/**
|
|
4
|
+
* Filters and transforms function declarations into a collection of compatible node functions.
|
|
5
|
+
*
|
|
6
|
+
* This utility function analyzes TypeScript function declarations and matches them against
|
|
7
|
+
* a target parameter type. It returns node functions for all functions whose return types
|
|
8
|
+
* are assignable to the specified parameter type. Each node function is enriched with
|
|
9
|
+
* metadata including function definitions and parameter information.
|
|
10
|
+
*
|
|
11
|
+
* @param {ts.TypeChecker} checker - The TypeScript type checker instance used to analyze
|
|
12
|
+
* type information and verify type compatibility
|
|
13
|
+
* @param {ts.FunctionDeclaration[]} functionDeclarations - Array of TypeScript function
|
|
14
|
+
* declarations to be filtered and analyzed
|
|
15
|
+
* @param {FunctionDefinition[]} functions - Array of function definitions containing
|
|
16
|
+
* metadata about functions, including identifiers and parameter definitions
|
|
17
|
+
* @param {ts.Type} paramType - The target parameter type used to filter compatible
|
|
18
|
+
* functions. Only functions with return types assignable to this type are included
|
|
19
|
+
*
|
|
20
|
+
* @returns {NodeFunction[]} Array of node functions that are compatible with the
|
|
21
|
+
* specified parameter type. Returns an empty array if the parameter type
|
|
22
|
+
* is a sub-flow or if no compatible functions are found
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const compatibleNodes = getNodes(checker, funcDecls, funcDefs, stringType);
|
|
26
|
+
*/
|
|
27
|
+
export declare const getNodes: (checker: ts.TypeChecker, functionDeclarations: ts.FunctionDeclaration[], functions: FunctionDefinition[], paramType: ts.Type) => NodeFunction[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { default as ts } from 'typescript';
|
|
2
|
+
import { ReferenceValue } from '@code0-tech/sagittarius-graphql-types';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts reference values from a collection of TypeScript symbols.
|
|
5
|
+
*
|
|
6
|
+
* This function processes symbols with specific prefixes (node_, p_, flow_) and creates
|
|
7
|
+
* corresponding ReferenceValue objects. It filters out invalid symbols and symbols that
|
|
8
|
+
* are declared after the current node position.
|
|
9
|
+
*
|
|
10
|
+
* @param checker - TypeScript TypeChecker instance for type information resolution
|
|
11
|
+
* @param node - The VariableDeclaration context in which symbols are analyzed
|
|
12
|
+
* @param paramType - The expected parameter type for property matching during extraction
|
|
13
|
+
* @param symbols - The array of symbols to process and analyze
|
|
14
|
+
* @returns An array of ReferenceValue objects representing extracted references with their paths
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Extracts all references from symbols prefixed with node_, p_, or flow_
|
|
18
|
+
* const references = getReferences(checker, variableDecl, expectedType, [symbol1, symbol2]);
|
|
19
|
+
*/
|
|
20
|
+
export declare const getReferences: (checker: ts.TypeChecker, node: ts.VariableDeclaration, paramType: ts.Type, symbols: ts.Symbol[]) => ReferenceValue[];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { default as ts, FunctionDeclaration } from 'typescript';
|
|
2
|
+
import { FunctionDefinition, LiteralValue, NodeFunction, ReferenceValue } from '@code0-tech/sagittarius-graphql-types';
|
|
3
|
+
/**
|
|
4
|
+
* Base interface for all input types.
|
|
5
|
+
* Provides common properties for suggestions and input metadata.
|
|
6
|
+
*/
|
|
7
|
+
interface Input {
|
|
8
|
+
/** The type of input (string representation) */
|
|
9
|
+
input?: string;
|
|
10
|
+
/** Array of suggested values (functions, references, or literals) */
|
|
11
|
+
suggestions?: (NodeFunction | ReferenceValue | LiteralValue)[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a generic input type with no specific structure.
|
|
15
|
+
* Used as a fallback when the type cannot be determined.
|
|
16
|
+
*/
|
|
17
|
+
interface GenericInput {
|
|
18
|
+
input?: "generic";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents a sub-flow input type (callable/function type).
|
|
22
|
+
* Used for types that have call signatures.
|
|
23
|
+
*/
|
|
24
|
+
interface SubFlowInput {
|
|
25
|
+
input?: "sub-flow";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents primitive input types: boolean, number, text, or select.
|
|
29
|
+
* Extends the base Input interface to include suggestions.
|
|
30
|
+
*/
|
|
31
|
+
interface PrimitiveInput extends Input {
|
|
32
|
+
input?: "boolean" | "number" | "text" | "select";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a data object input type with structured properties.
|
|
36
|
+
* Includes property definitions and required field tracking.
|
|
37
|
+
*/
|
|
38
|
+
interface DataInput extends Input {
|
|
39
|
+
input?: "data";
|
|
40
|
+
/** Record mapping property names to their schemas */
|
|
41
|
+
properties?: Record<string, Schema | Schema[]>;
|
|
42
|
+
/** Array of required property names */
|
|
43
|
+
required?: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Represents a list/array input type with item schemas.
|
|
47
|
+
* Supports homogeneous or heterogeneous arrays.
|
|
48
|
+
*/
|
|
49
|
+
interface ListInput extends Input {
|
|
50
|
+
input?: "list";
|
|
51
|
+
/** Schema or array of schemas for list items */
|
|
52
|
+
items?: Schema | Schema[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Represents a complex type input with properties and required fields.
|
|
56
|
+
* Similar to DataInput but used for type definitions.
|
|
57
|
+
*/
|
|
58
|
+
interface TypeInput extends Input {
|
|
59
|
+
input?: "type";
|
|
60
|
+
/** Record mapping property names to their schemas */
|
|
61
|
+
properties?: Record<string, Schema | Schema[]>;
|
|
62
|
+
/** Array of required property names */
|
|
63
|
+
required?: string[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Union type representing all possible schema input types.
|
|
67
|
+
* Discriminated union based on the 'input' field.
|
|
68
|
+
*/
|
|
69
|
+
export type Schema = PrimitiveInput | DataInput | ListInput | TypeInput | SubFlowInput | GenericInput;
|
|
70
|
+
/**
|
|
71
|
+
* Generates a schema definition for a given TypeScript type.
|
|
72
|
+
*
|
|
73
|
+
* This function analyzes a TypeScript type and produces a structured schema
|
|
74
|
+
* that describes how the type should be presented and validated. It handles:
|
|
75
|
+
* - Primitive types (boolean, number, string)
|
|
76
|
+
* - Union types of primitives
|
|
77
|
+
* - Array/Tuple types
|
|
78
|
+
* - Complex object types with properties
|
|
79
|
+
* - Sub-flow types (callables)
|
|
80
|
+
*
|
|
81
|
+
* For each type, the function also collects suggestions from:
|
|
82
|
+
* - Literal values from the type definition
|
|
83
|
+
* - Variable references available in scope
|
|
84
|
+
* - Function node suggestions based on parameter type
|
|
85
|
+
*
|
|
86
|
+
* @param checker - TypeScript type checker for type analysis
|
|
87
|
+
* @param node - The variable declaration node being analyzed
|
|
88
|
+
* @param parameterType - The type to generate a schema for
|
|
89
|
+
* @param functionDeclarations - Array of function declaration nodes
|
|
90
|
+
* @param functions - Array of function definitions for matching
|
|
91
|
+
* @returns A Schema object describing how to handle the parameter type
|
|
92
|
+
*/
|
|
93
|
+
export declare const getSchema: (checker: ts.TypeChecker, node: ts.VariableDeclaration, parameterType: ts.Type, functionDeclarations: FunctionDeclaration[], functions: FunctionDefinition[]) => Schema;
|
|
94
|
+
/**
|
|
95
|
+
* Checks if a type is a callable type (has call signatures).
|
|
96
|
+
*
|
|
97
|
+
* A type with call signatures can be invoked like a function. This is used
|
|
98
|
+
* to identify sub-flow types that represent workflow steps.
|
|
99
|
+
*
|
|
100
|
+
* @param type - The type to check
|
|
101
|
+
* @returns True if the type has call signatures, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
export declare function isSubFlow(type: ts.Type): boolean;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { default as ts } from 'typescript';
|
|
2
|
+
import { LiteralValue } from '@code0-tech/sagittarius-graphql-types';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts literal values from a TypeScript type.
|
|
5
|
+
*
|
|
6
|
+
* This function recursively processes TypeScript types and extracts all literal values,
|
|
7
|
+
* including string literals, number literals, and boolean literals. For union types,
|
|
8
|
+
* it flattens and combines all literal values from each constituent type.
|
|
9
|
+
*
|
|
10
|
+
* @param type - The TypeScript type to extract values from
|
|
11
|
+
* @returns An array of LiteralValue objects representing all literal values found in the type
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // For a type like "red" | "blue" | 42
|
|
15
|
+
* const values = getValues(type);
|
|
16
|
+
* // Returns:
|
|
17
|
+
* // [
|
|
18
|
+
* // { value: "red", __typename: "LiteralValue" },
|
|
19
|
+
* // { value: "blue", __typename: "LiteralValue" },
|
|
20
|
+
* // { value: "42" }
|
|
21
|
+
* // ]
|
|
22
|
+
*/
|
|
23
|
+
export declare const getValues: (type: ts.Type) => LiteralValue[];
|
package/dist/utils.d.ts
CHANGED
|
@@ -39,11 +39,3 @@ export declare const sanitizeId: (id: string) => string;
|
|
|
39
39
|
* Generates TypeScript source code for a flow, suitable for validation and type inference.
|
|
40
40
|
*/
|
|
41
41
|
export declare function generateFlowSourceCode(flow?: Flow, functions?: FunctionDefinition[], dataTypes?: DataType[], isForInference?: boolean): string;
|
|
42
|
-
export interface InferredTypes {
|
|
43
|
-
nodes: Map<string, string>;
|
|
44
|
-
parameters: Map<string, string[]>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Infers types for all nodes and parameters in a flow using the TypeScript compiler.
|
|
48
|
-
*/
|
|
49
|
-
export declare function getInferredTypesFromFlow(flow?: Flow, functions?: FunctionDefinition[], dataTypes?: DataType[]): InferredTypes;
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { DataType } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
-
export declare enum DataTypeVariant {
|
|
3
|
-
PRIMITIVE = 0,
|
|
4
|
-
TYPE = 1,
|
|
5
|
-
ARRAY = 2,
|
|
6
|
-
OBJECT = 3,
|
|
7
|
-
NODE = 4
|
|
8
|
-
}
|
|
9
|
-
export interface TypeVariantResult {
|
|
10
|
-
identifier: string;
|
|
11
|
-
variant: DataTypeVariant;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Determines the variant of a given TypeScript types string or DataType(s) using the TS compiler.
|
|
15
|
-
* - If types is a string: returns one result with the string as identifier
|
|
16
|
-
* - If types is a DataType: returns one result with DataType.identifier
|
|
17
|
-
* - If types is a DataType[]: returns results for each DataType with their identifiers
|
|
18
|
-
*/
|
|
19
|
-
export declare const getTypeVariant: (types?: string | DataType | DataType[], dataTypes?: DataType[]) => TypeVariantResult[];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FunctionDefinition } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
-
export interface FunctionTypes {
|
|
3
|
-
parameters: string[];
|
|
4
|
-
returnType: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Resolves the types of the parameters and the return type of a NodeFunction.
|
|
8
|
-
*/
|
|
9
|
-
export declare const getTypesFromFunction: (functionDefinition: FunctionDefinition) => FunctionTypes;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DataType, FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
-
export interface NodeTypes {
|
|
3
|
-
parameters: string[];
|
|
4
|
-
returnType: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Resolves the types of the parameters and the return type of a NodeFunction.
|
|
8
|
-
*/
|
|
9
|
-
export declare const getTypesFromNode: (node?: NodeFunction, functions?: FunctionDefinition[], dataTypes?: DataType[]) => NodeTypes;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { DataType, FunctionDefinition, NodeFunction } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
-
/**
|
|
3
|
-
* Suggests NodeFunctions based on a given type and a list of available FunctionDefinitions.
|
|
4
|
-
* Returns functions whose return type is compatible with the target type.
|
|
5
|
-
*/
|
|
6
|
-
export declare const getNodeSuggestions: (type?: string, functions?: FunctionDefinition[], dataTypes?: DataType[]) => NodeFunction[];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DataType, Flow, FunctionDefinition, NodeFunction, ReferenceValue } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
-
/**
|
|
3
|
-
* Calculates all available reference suggestions for a specific target parameter in a flow.
|
|
4
|
-
*
|
|
5
|
-
* This function analyzes the flow's generated source code to find all variables
|
|
6
|
-
* (node_ and p_ prefixed) that are in scope and compatible with the target parameter's
|
|
7
|
-
* expected type. For object types, it also extracts nested properties and their access paths.
|
|
8
|
-
*
|
|
9
|
-
* @param flow The flow configuration
|
|
10
|
-
* @param nodeId The ID of the node containing the target parameter
|
|
11
|
-
* @param targetIndex The index of the target parameter
|
|
12
|
-
* @param functions Available function definitions for type resolution
|
|
13
|
-
* @param dataTypes Available data type definitions
|
|
14
|
-
* @returns Array of ReferenceValue objects representing available suggestions
|
|
15
|
-
*/
|
|
16
|
-
export declare const getReferenceSuggestions: (flow?: Flow, nodeId?: NodeFunction["id"], targetIndex?: number, functions?: FunctionDefinition[], dataTypes?: DataType[]) => ReferenceValue[];
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DataType, LiteralValue } from '@code0-tech/sagittarius-graphql-types';
|
|
2
|
-
/**
|
|
3
|
-
* Extracts possible literal values from a type string to provide suggestions.
|
|
4
|
-
*/
|
|
5
|
-
export declare const getValueSuggestions: (type?: string, dataTypes?: DataType[]) => LiteralValue[];
|