Skip to content

Commit 5acdc6b

Browse files
committed
feat: enhance DFlow services to support dependencies for namespace, project, and runtime IDs
1 parent 6bdc7e1 commit 5acdc6b

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

src/components/d-flow-data-type/DFlowDataType.service.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import {ReactiveArrayService} from "../../utils";
22
import {DataTypeView} from "./DFlowDataType.view";
33
import {resolveType} from "../../utils/generics";
4-
import type {
4+
import {
55
DataTypeIdentifier,
66
DataTypeRule,
77
DataTypeRulesContainsKeyConfig,
88
DataTypeRulesInputTypesConfig, Flow,
99
GenericMapper,
1010
LiteralValue,
11-
Maybe,
12-
NodeParameterValue,
11+
Maybe, Namespace, NamespaceProject,
12+
NodeParameterValue, Runtime,
1313
Scalars
1414
} from "@code0-tech/sagittarius-graphql-types";
1515
import {useValueValidation} from "../d-flow-validation/DValueValidation.hook";
1616

17-
export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<DataTypeView> {
17+
export type DFlowDataTypeDependencies = {
18+
namespaceId: Namespace['id']
19+
projectId: NamespaceProject['id']
20+
runtimeId: Runtime['id']
21+
}
22+
23+
export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<DataTypeView, DFlowDataTypeDependencies> {
1824

19-
getDataType (type: DataTypeIdentifier): DataTypeView | undefined {
25+
getDataType (type: DataTypeIdentifier, dependencies?: DFlowDataTypeDependencies): DataTypeView | undefined {
2026
if (!type) return undefined
2127
if ((type as DataTypeIdentifier).genericKey) return undefined
2228
const identifier = (type as DataTypeIdentifier).dataType?.identifier ?? (type as DataTypeIdentifier).genericType?.dataType?.identifier
@@ -26,20 +32,20 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
2632
});
2733
}
2834

29-
getDataTypeFromValue (value: NodeParameterValue, flow?: Flow): DataTypeView | undefined {
35+
getDataTypeFromValue (value: NodeParameterValue, flow?: Flow, dependencies?: DFlowDataTypeDependencies): DataTypeView | undefined {
3036

3137
if (!value) return undefined
3238

3339
if (value.__typename == "LiteralValue") {
3440
//hardcode primitive types (NUMBER, BOOLEAN, TEXT)
3541
if (Array.isArray(value.value) && Array.from(value.value).length > 0) return this.getDataType({dataType: {identifier: "ARRAY"}})
36-
if (typeof value.value === "string") return this.getDataType({dataType: {identifier: "TEXT"}})
37-
if (typeof value.value === "number") return this.getDataType({dataType: {identifier: "NUMBER"}})
38-
if (typeof value.value === "boolean") return this.getDataType({dataType: {identifier: "BOOLEAN"}})
42+
if (typeof value.value === "string") return this.getDataType({dataType: {identifier: "TEXT"}}, dependencies)
43+
if (typeof value.value === "number") return this.getDataType({dataType: {identifier: "NUMBER"}}, dependencies)
44+
if (typeof value.value === "boolean") return this.getDataType({dataType: {identifier: "BOOLEAN"}}, dependencies)
3945
}
4046

4147
//TODO: performance here is bad
42-
const matchingDataTypes = this.values().filter(type => {
48+
const matchingDataTypes = this.values(dependencies).filter(type => {
4349
if (type.identifier === "OBJECT") return false
4450
if (value.__typename === "NodeFunctionIdWrapper" && (type.variant != "NODE" || !flow)) return false
4551
return useValueValidation(value, type, this, flow)
@@ -49,13 +55,13 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
4955

5056
}
5157

52-
getTypeFromValue (value: NodeParameterValue, flow?: Flow): Maybe<DataTypeIdentifier> | undefined {
58+
getTypeFromValue (value: NodeParameterValue, flow?: Flow, dependencies?: DFlowDataTypeDependencies): Maybe<DataTypeIdentifier> | undefined {
5359

5460
if (!value) return undefined
5561

5662
if (value.__typename === "ReferenceValue") return value.dataTypeIdentifier
5763

58-
const dataType = this.getDataTypeFromValue(value, flow)
64+
const dataType = this.getDataTypeFromValue(value, flow, dependencies)
5965
if ((dataType?.genericKeys?.length ?? 0) <= 0 || !dataType?.genericKeys) return {dataType: {id: dataType?.id}}
6066

6167
//TODO: missing generic combinations
@@ -75,7 +81,7 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
7581
sourceDataTypeIdentifiers: [this.getTypeFromValue({
7682
__typename: "LiteralValue",
7783
value: ((value as LiteralValue).value as Array<any>)[0]
78-
}, flow)],
84+
}, flow, dependencies)],
7985
target: genericKey
8086
} as GenericMapper
8187
}
@@ -89,7 +95,7 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
8995
__typename: "LiteralValue",
9096
/* @ts-ignore */
9197
value: (value.value as Object)[((ruleThatIncludesGenericKey.config as DataTypeRulesContainsKeyConfig)?.key ?? "")]
92-
}, flow)],
98+
}, flow, dependencies)],
9399
target: genericKey
94100
} as GenericMapper
95101
}
@@ -98,7 +104,7 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
98104
&& ruleThatIncludesGenericKey.variant == "RETURN_TYPE"
99105
&& dataType.variant === "NODE") {
100106
return {
101-
sourceDataTypeIdentifiers: [this.getTypeFromValue(value, flow)],
107+
sourceDataTypeIdentifiers: [this.getTypeFromValue(value, flow, dependencies)],
102108
target: genericKey
103109
} as GenericMapper
104110
}
@@ -132,9 +138,9 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
132138

133139
}
134140

135-
hasDataTypes(types: DataTypeIdentifier[]): boolean {
141+
hasDataTypes(types: DataTypeIdentifier[], dependencies?: DFlowDataTypeDependencies): boolean {
136142
return types.every(type => {
137-
return this.values().find(value => {
143+
return this.values(dependencies).find(value => {
138144
return value.id === (type.genericType?.dataType?.id ?? type.dataType?.id)
139145
})
140146
})
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import {ReactiveArrayService} from "../../utils";
22
import {FunctionDefinitionView} from "./DFlowFunction.view";
3-
import type {FunctionDefinition} from "@code0-tech/sagittarius-graphql-types";
3+
import {FunctionDefinition, Namespace, NamespaceProject, Runtime} from "@code0-tech/sagittarius-graphql-types";
44

5+
export type DFlowFunctionDependencies = {
6+
namespaceId: Namespace['id']
7+
projectId: NamespaceProject['id']
8+
runtimeId: Runtime['id']
9+
}
510

6-
export abstract class DFlowFunctionReactiveService extends ReactiveArrayService<FunctionDefinitionView> {
11+
export abstract class DFlowFunctionReactiveService extends ReactiveArrayService<FunctionDefinitionView, DFlowFunctionDependencies> {
712

8-
getById(id: FunctionDefinition['id']): FunctionDefinitionView | undefined {
9-
return this.values().find(functionDefinition => functionDefinition.id === id)
13+
getById(id: FunctionDefinition['id'], dependencies?: DFlowFunctionDependencies): FunctionDefinitionView | undefined {
14+
return this.values(dependencies).find(functionDefinition => functionDefinition.id === id)
1015
}
1116

1217
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import {ReactiveArrayService} from "../../utils";
22
import {FlowTypeView} from "./DFlowType.view";
3-
import type {FlowType} from "@code0-tech/sagittarius-graphql-types";
3+
import {FlowType, Namespace, NamespaceProject, Runtime} from "@code0-tech/sagittarius-graphql-types";
44

5-
export abstract class DFlowTypeReactiveService extends ReactiveArrayService<FlowTypeView> {
5+
export type DFlowTypeDependencies = {
6+
namespaceId: Namespace['id']
7+
projectId: NamespaceProject['id']
8+
runtimeId: Runtime['id']
9+
}
610

7-
getById(id: FlowType['id']): FlowTypeView | undefined {
8-
return this.values().find(value => value.id === id);
11+
export abstract class DFlowTypeReactiveService extends ReactiveArrayService<FlowTypeView, DFlowTypeDependencies> {
12+
13+
getById(id: FlowType['id'], dependencies?: DFlowTypeDependencies): FlowTypeView | undefined {
14+
return this.values(dependencies).find(value => value.id === id);
915
}
1016

1117
}

0 commit comments

Comments
 (0)