Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build": "vite build"
},
"devDependencies": {
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2414125487-fbc8a5ec8a2dd07cc76957d4315281c246e98d57",
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2430052572-f89aa9d01636e56a17463920775d073b09dd132b",
"@types/node": "^25.5.0",
"typescript": "^6.0.2",
"vite": "^8.0.3",
Expand All @@ -32,7 +32,7 @@
"@typescript/vfs": "^1.6.4"
},
"peerDependencies": {
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2414125487-fbc8a5ec8a2dd07cc76957d4315281c246e98d57",
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2430052572-f89aa9d01636e56a17463920775d073b09dd132b",
"typescript": "^5.9.3 || ^6.0.2",
"@typescript/vfs": "^1.6.4"
}
Expand Down
37 changes: 28 additions & 9 deletions src/suggestion/getReferenceSuggestions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import ts from "typescript";
import {DataType, Flow, FunctionDefinition, NodeFunction, ReferenceValue} from "@code0-tech/sagittarius-graphql-types";
import {
DataType,
Flow,
FunctionDefinition,
NodeFunction,
ReferencePath,
ReferenceValue
} from "@code0-tech/sagittarius-graphql-types";
import {createCompilerHost, generateFlowSourceCode} from "../utils";

/**
Expand Down Expand Up @@ -41,9 +48,9 @@ const extractObjectProperties = (
type: ts.Type,
checker: ts.TypeChecker,
expectedType: ts.Type,
currentPath: string[] = []
): Array<{ path: string[]; type: ts.Type }> => {
const results: Array<{ path: string[]; type: ts.Type }> = [];
currentPath: ReferencePath[] = []
): Array<{ path: ReferencePath[]; type: ts.Type }> => {
const results: Array<{ path: ReferencePath[]; type: ts.Type }> = [];

// Add the current type if it matches the expected type
if (checker.isTypeAssignableTo(type, expectedType)) {
Expand All @@ -56,7 +63,7 @@ const extractObjectProperties = (
if (properties && properties.length > 0) {
properties.forEach(property => {
const propType = checker.getTypeOfSymbolAtLocation(property, property.valueDeclaration!);
const propName = property.getName();
const propName = property.getName() as ReferencePath;
const newPath = [...currentPath, propName];

// Recursively extract nested properties
Expand Down Expand Up @@ -143,7 +150,7 @@ export const getReferenceSuggestions = (

allSymbols.forEach(symbol => {
const name = symbol.getName();
if (!name.startsWith("node_") && !name.startsWith("p_")) return;
if (!name.startsWith("node_") && !name.startsWith("p_") && !name.startsWith("flow_")) return;

// Get the variable declaration
const declaration = symbol.valueDeclaration || symbol.declarations?.[0];
Expand Down Expand Up @@ -175,7 +182,6 @@ export const getReferenceSuggestions = (
};

if (path.length > 0) {
//@ts-ignore
referenceValue.referencePath = path;
}

Expand Down Expand Up @@ -211,12 +217,10 @@ export const getReferenceSuggestions = (
nodeFunctionId: nodeFunctionId as any,
parameterIndex: isNaN(paramIndexFromName) ? 0 : paramIndexFromName,
inputIndex: tupleIndex,
//@ts-ignore
inputTypeIdentifier: (typeReference.target as any).labeledElementDeclarations?.[tupleIndex].name.getText()
};

if (path.length > 0) {
//@ts-ignore
referenceValue.referencePath = path;
}

Expand All @@ -225,6 +229,21 @@ export const getReferenceSuggestions = (
});
}
}
else if (name.startsWith("flow_")) {
const propertyPaths = extractObjectProperties(symbolType, checker, expectedType)
propertyPaths.forEach(({ path }) => {
const referenceValue: ReferenceValue = {
__typename: 'ReferenceValue',
nodeFunctionId: null
};

if (path.length > 0) {
referenceValue.referencePath = path;
}

referenceValues.push(referenceValue);
})
}
});

return referenceValues;
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export function generateFlowSourceCode(
};

const typeDefs = getSharedTypeDeclarations(dataTypes);
const flowTypeDeclaration = `declare function flow${flow?.signature ?? "(): void"}`
const funcDeclarations = functions?.map(f => `declare function fn_${f.identifier?.replace(/::/g, '_')}${f.signature}`).join('\n');

const nextNodeIds = new Set(nodes.map(n => n?.nextNodeId).filter(id => !!id));
Expand All @@ -217,12 +218,14 @@ export function generateFlowSourceCode(
if (p?.value?.__typename === "NodeFunctionIdWrapper" && p.value.id) subTreeIds.add(p.value.id);
}));

const flowCode = flow ? `const flow_${sanitizeId(flow.id ?? "")} = flow(${flow.settings?.nodes?.map((setting, index) => `/* @pos undefined ${index} */ ${JSON.stringify(setting?.value)}`).join(", ") ?? ""});` : ""

const executionCode = nodes
.filter(n => n?.id && !nextNodeIds.has(n.id) && !subTreeIds.has(n.id))
.map(n => generateNodeCode(n!.id!))
.join('\n');

return `${typeDefs}\n${funcDeclarations}\n\n// --- Flow ---\n${executionCode}`;
return `${typeDefs}\n${flowTypeDeclaration}\n${funcDeclarations}\n\n// --- Flow ---\n${flowCode}\n${executionCode}`;
}

export interface InferredTypes {
Expand Down
2 changes: 1 addition & 1 deletion src/validation/getFlowValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getFlowValidation = (
}

if (closestMatch) {
nodeId = closestMatch[1] as NodeFunction['id'];
nodeId = closestMatch[1] === "undefined" ? undefined : closestMatch[1] as NodeFunction['id'];
parameterIndex = parseInt(closestMatch[2], 10);
}
}
Expand Down
14 changes: 3 additions & 11 deletions test/flowValidation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {describe, expect, it} from 'vitest';
import {getFlowValidation} from '../src/validation/getFlowValidation';
import {Flow} from "@code0-tech/sagittarius-graphql-types"; // Pfad ggf. anpassen
// @ts-ignore
import {DATA_TYPES, FUNCTION_SIGNATURES} from "./data";

describe('getFlowValidation - Integrationstest', () => {
Expand Down Expand Up @@ -69,7 +70,6 @@ describe('getFlowValidation - Integrationstest', () => {
expect(result.isValid).toBe(true);
expect(result.diagnostics).toHaveLength(0);
result.diagnostics.forEach((error) => {
expect(error.nodeId).toBeDefined()
expect(error.parameterIndex).toBeDefined()
})
});
Expand Down Expand Up @@ -142,7 +142,6 @@ describe('getFlowValidation - Integrationstest', () => {

expect(result.isValid).toBe(false);
result.diagnostics.forEach((error) => {
expect(error.nodeId).toBeDefined()
expect(error.parameterIndex).toBeDefined()
})
});
Expand Down Expand Up @@ -192,7 +191,6 @@ describe('getFlowValidation - Integrationstest', () => {
expect(result.isValid).toBe(true);
expect(result.diagnostics).toHaveLength(0);
result.diagnostics.forEach((error) => {
expect(error.nodeId).toBeDefined()
expect(error.parameterIndex).toBeDefined()
})
});
Expand Down Expand Up @@ -249,7 +247,6 @@ describe('getFlowValidation - Integrationstest', () => {
expect(result.isValid).toBe(true);
expect(result.diagnostics).toHaveLength(0);
result.diagnostics.forEach((error) => {
expect(error.nodeId).toBeDefined()
expect(error.parameterIndex).toBeDefined()
})
});
Expand All @@ -261,8 +258,7 @@ describe('getFlowValidation - Integrationstest', () => {
"id": "gid://sagittarius/Flow/1",
"createdAt": "2026-03-17T14:02:31Z",
"name": "Test",
"inputType": "REST_ADAPTER_INPUT",
"returnType": "HTTP_RESPONSE",
"signature": "(httpURL: HTTP_URL, httpMethod: HTTP_METHOD): REST_ADAPTER_INPUT<{}>",
"nodes": {
"__typename": "NodeFunctionConnection",
"nodes": [
Expand Down Expand Up @@ -364,7 +360,6 @@ describe('getFlowValidation - Integrationstest', () => {

expect(result.isValid).toBe(false);
result.diagnostics.forEach((error) => {
expect(error.nodeId).toBeDefined()
expect(error.parameterIndex).toBeDefined()
})
});
Expand All @@ -376,8 +371,7 @@ describe('getFlowValidation - Integrationstest', () => {
"id": "gid://sagittarius/Flow/1",
"createdAt": "2026-03-17T14:02:31Z",
"name": "Test",
"inputType": "REST_ADAPTER_INPUT",
"returnType": "HTTP_RESPONSE",
"signature": "(httpURL: HTTP_URL, httpMethod: HTTP_METHOD): REST_ADAPTER_INPUT<{}>",
"nodes": {
"__typename": "NodeFunctionConnection",
"nodes": [
Expand Down Expand Up @@ -539,8 +533,6 @@ describe('getFlowValidation - Integrationstest', () => {

expect(result.isValid).toBe(false);
result.diagnostics.forEach((error) => {

expect(error.nodeId).toBeDefined()
expect(error.parameterIndex).toBeDefined()
})
});
Expand Down
Loading