feat: consume governed datasources and shared graphs
This commit is contained in:
@@ -1,49 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Literal
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
from govoplan_core.core.definition_graphs import (
|
||||
DefinitionConfigField,
|
||||
DefinitionGraphConstraints,
|
||||
DefinitionGraphLibrary,
|
||||
DefinitionNodeCountConstraint,
|
||||
DefinitionNodeType,
|
||||
DefinitionPort,
|
||||
)
|
||||
|
||||
|
||||
NodeCategory = Literal["load", "combine", "filter", "transform", "output"]
|
||||
SqlSupport = Literal["full", "partial", "none"]
|
||||
NodePortDefinition = DefinitionPort
|
||||
NodeConfigField = DefinitionConfigField
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class NodePortDefinition:
|
||||
id: str
|
||||
label: str
|
||||
required: bool = True
|
||||
multiple: bool = False
|
||||
minimum_connections: int = 1
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class NodeConfigField:
|
||||
id: str
|
||||
label: str
|
||||
kind: str
|
||||
required: bool = False
|
||||
description: str | None = None
|
||||
options: tuple[tuple[str, str], ...] = ()
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class NodeTypeDefinition:
|
||||
type: str
|
||||
category: NodeCategory
|
||||
label: str
|
||||
description: str
|
||||
icon: str
|
||||
input_ports: tuple[NodePortDefinition, ...] = ()
|
||||
output_ports: tuple[NodePortDefinition, ...] = (
|
||||
NodePortDefinition(id="output", label="Output"),
|
||||
)
|
||||
config_fields: tuple[NodeConfigField, ...] = ()
|
||||
default_config: dict[str, Any] = field(default_factory=dict)
|
||||
class NodeTypeDefinition(DefinitionNodeType):
|
||||
sql_support: SqlSupport = "full"
|
||||
|
||||
|
||||
NODE_LIBRARY = (
|
||||
_NODE_TYPES = (
|
||||
NodeTypeDefinition(
|
||||
type="source.inline",
|
||||
category="load",
|
||||
@@ -59,18 +40,29 @@ NODE_LIBRARY = (
|
||||
NodeTypeDefinition(
|
||||
type="source.reference",
|
||||
category="load",
|
||||
label="Connector source",
|
||||
description="Load a bounded, fingerprinted table exposed by Connectors.",
|
||||
label="Datasource",
|
||||
description="Load a bounded, fingerprinted state from the Datasources catalogue.",
|
||||
icon="database",
|
||||
config_fields=(
|
||||
NodeConfigField(id="source_ref", label="Source", kind="tabular_source", required=True),
|
||||
NodeConfigField(id="source_ref", label="Datasource", kind="datasource", required=True),
|
||||
NodeConfigField(id="source_name", label="SQL source name", kind="text", required=True),
|
||||
NodeConfigField(id="expected_fingerprint", label="Expected fingerprint", kind="readonly"),
|
||||
NodeConfigField(
|
||||
id="consistency",
|
||||
label="State",
|
||||
kind="select",
|
||||
options=(
|
||||
("current", "Current"),
|
||||
("live", "Live"),
|
||||
("frozen", "Latest frozen"),
|
||||
),
|
||||
),
|
||||
),
|
||||
default_config={
|
||||
"source_ref": "",
|
||||
"source_name": "connector_source",
|
||||
"source_name": "datasource",
|
||||
"expected_fingerprint": "",
|
||||
"consistency": "current",
|
||||
},
|
||||
),
|
||||
NodeTypeDefinition(
|
||||
@@ -278,7 +270,6 @@ NODE_LIBRARY = (
|
||||
),
|
||||
)
|
||||
|
||||
NODE_TYPES = {definition.type: definition for definition in NODE_LIBRARY}
|
||||
CATEGORY_LABELS = {
|
||||
"load": "Load",
|
||||
"combine": "Combine",
|
||||
@@ -286,6 +277,36 @@ CATEGORY_LABELS = {
|
||||
"transform": "Transform",
|
||||
"output": "Output",
|
||||
}
|
||||
DATAFLOW_GRAPH_LIBRARY = DefinitionGraphLibrary(
|
||||
id="dataflow",
|
||||
version="0.1.0",
|
||||
category_labels=CATEGORY_LABELS,
|
||||
node_types=_NODE_TYPES,
|
||||
constraints=DefinitionGraphConstraints(
|
||||
max_nodes=100,
|
||||
max_edges=200,
|
||||
allow_cycles=False,
|
||||
require_connected=True,
|
||||
node_counts=(
|
||||
DefinitionNodeCountConstraint(
|
||||
code="graph.source_count",
|
||||
label="source",
|
||||
minimum=1,
|
||||
maximum=10,
|
||||
type_prefixes=("source.",),
|
||||
),
|
||||
DefinitionNodeCountConstraint(
|
||||
code="graph.output_count",
|
||||
label="output",
|
||||
minimum=1,
|
||||
maximum=1,
|
||||
node_types=("output",),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
NODE_LIBRARY: tuple[NodeTypeDefinition, ...] = _NODE_TYPES
|
||||
NODE_TYPES = {definition.type: definition for definition in NODE_LIBRARY}
|
||||
|
||||
|
||||
def node_definition(node_type: str) -> NodeTypeDefinition | None:
|
||||
@@ -294,6 +315,7 @@ def node_definition(node_type: str) -> NodeTypeDefinition | None:
|
||||
|
||||
__all__ = [
|
||||
"CATEGORY_LABELS",
|
||||
"DATAFLOW_GRAPH_LIBRARY",
|
||||
"NODE_LIBRARY",
|
||||
"NODE_TYPES",
|
||||
"NodeCategory",
|
||||
|
||||
Reference in New Issue
Block a user