2025-09-03 23:39:11 +01:00
|
|
|
from typing import Dict, Any, Tuple, Optional
|
2026-02-23 15:56:29 +00:00
|
|
|
from ...schema import RowsQueryRequest, RowsQueryResponse
|
2025-09-03 23:39:11 +01:00
|
|
|
from .base import MessageTranslator
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
2026-02-23 15:56:29 +00:00
|
|
|
class RowsQueryRequestTranslator(MessageTranslator):
|
|
|
|
|
"""Translator for RowsQueryRequest schema objects"""
|
|
|
|
|
|
Pub/sub abstraction: decouple from Pulsar (#751)
Remove Pulsar-specific concepts from application code so that
the pub/sub backend is swappable via configuration.
Rename translators:
- to_pulsar/from_pulsar → decode/encode across all translator
classes, dispatch handlers, and tests (55+ files)
- from_response_with_completion → encode_with_completion
- Remove pulsar.schema.Record from translator base class
Queue naming (CLASS:TOPICSPACE:TOPIC):
- Replace topic() helper with queue() using new format:
flow:tg:name, request:tg:name, response:tg:name, state:tg:name
- Queue class implies persistence/TTL (no QoS in names)
- Update Pulsar backend map_topic() to parse new format
- Librarian queues use flow class (persistent, for chunking)
- Config push uses state class (persistent, last-value)
- Remove 15 dead topic imports from schema files
- Update init_trustgraph.py namespace: config → state
Confine Pulsar to pulsar_backend.py:
- Delete legacy PulsarClient class from pubsub.py
- Move add_args to add_pubsub_args() with standalone flag
for CLI tools (defaults to localhost)
- PulsarBackendConsumer.receive() catches _pulsar.Timeout,
raises standard TimeoutError
- Remove Pulsar imports from: async_processor, flow_processor,
log_level, all 11 client files, 4 storage writers, gateway
service, gateway config receiver
- Remove log_level/LoggerLevel from client API
- Rewrite tg-monitor-prompts to use backend abstraction
- Update tg-dump-queues to use add_pubsub_args
Also: pubsub-abstraction.md tech spec covering problem statement,
design goals, as-is requirements, candidate broker assessment,
approach, and implementation order.
2026-04-01 20:16:53 +01:00
|
|
|
def decode(self, data: Dict[str, Any]) -> RowsQueryRequest:
|
2026-02-23 15:56:29 +00:00
|
|
|
return RowsQueryRequest(
|
2025-09-03 23:39:11 +01:00
|
|
|
collection=data.get("collection", "default"),
|
|
|
|
|
query=data.get("query", ""),
|
|
|
|
|
variables=data.get("variables", {}),
|
|
|
|
|
operation_name=data.get("operation_name", None)
|
|
|
|
|
)
|
2026-02-23 15:56:29 +00:00
|
|
|
|
Pub/sub abstraction: decouple from Pulsar (#751)
Remove Pulsar-specific concepts from application code so that
the pub/sub backend is swappable via configuration.
Rename translators:
- to_pulsar/from_pulsar → decode/encode across all translator
classes, dispatch handlers, and tests (55+ files)
- from_response_with_completion → encode_with_completion
- Remove pulsar.schema.Record from translator base class
Queue naming (CLASS:TOPICSPACE:TOPIC):
- Replace topic() helper with queue() using new format:
flow:tg:name, request:tg:name, response:tg:name, state:tg:name
- Queue class implies persistence/TTL (no QoS in names)
- Update Pulsar backend map_topic() to parse new format
- Librarian queues use flow class (persistent, for chunking)
- Config push uses state class (persistent, last-value)
- Remove 15 dead topic imports from schema files
- Update init_trustgraph.py namespace: config → state
Confine Pulsar to pulsar_backend.py:
- Delete legacy PulsarClient class from pubsub.py
- Move add_args to add_pubsub_args() with standalone flag
for CLI tools (defaults to localhost)
- PulsarBackendConsumer.receive() catches _pulsar.Timeout,
raises standard TimeoutError
- Remove Pulsar imports from: async_processor, flow_processor,
log_level, all 11 client files, 4 storage writers, gateway
service, gateway config receiver
- Remove log_level/LoggerLevel from client API
- Rewrite tg-monitor-prompts to use backend abstraction
- Update tg-dump-queues to use add_pubsub_args
Also: pubsub-abstraction.md tech spec covering problem statement,
design goals, as-is requirements, candidate broker assessment,
approach, and implementation order.
2026-04-01 20:16:53 +01:00
|
|
|
def encode(self, obj: RowsQueryRequest) -> Dict[str, Any]:
|
2025-09-03 23:39:11 +01:00
|
|
|
result = {
|
|
|
|
|
"collection": obj.collection,
|
|
|
|
|
"query": obj.query,
|
|
|
|
|
"variables": dict(obj.variables) if obj.variables else {}
|
|
|
|
|
}
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
if obj.operation_name:
|
|
|
|
|
result["operation_name"] = obj.operation_name
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
2026-02-23 15:56:29 +00:00
|
|
|
class RowsQueryResponseTranslator(MessageTranslator):
|
|
|
|
|
"""Translator for RowsQueryResponse schema objects"""
|
|
|
|
|
|
Pub/sub abstraction: decouple from Pulsar (#751)
Remove Pulsar-specific concepts from application code so that
the pub/sub backend is swappable via configuration.
Rename translators:
- to_pulsar/from_pulsar → decode/encode across all translator
classes, dispatch handlers, and tests (55+ files)
- from_response_with_completion → encode_with_completion
- Remove pulsar.schema.Record from translator base class
Queue naming (CLASS:TOPICSPACE:TOPIC):
- Replace topic() helper with queue() using new format:
flow:tg:name, request:tg:name, response:tg:name, state:tg:name
- Queue class implies persistence/TTL (no QoS in names)
- Update Pulsar backend map_topic() to parse new format
- Librarian queues use flow class (persistent, for chunking)
- Config push uses state class (persistent, last-value)
- Remove 15 dead topic imports from schema files
- Update init_trustgraph.py namespace: config → state
Confine Pulsar to pulsar_backend.py:
- Delete legacy PulsarClient class from pubsub.py
- Move add_args to add_pubsub_args() with standalone flag
for CLI tools (defaults to localhost)
- PulsarBackendConsumer.receive() catches _pulsar.Timeout,
raises standard TimeoutError
- Remove Pulsar imports from: async_processor, flow_processor,
log_level, all 11 client files, 4 storage writers, gateway
service, gateway config receiver
- Remove log_level/LoggerLevel from client API
- Rewrite tg-monitor-prompts to use backend abstraction
- Update tg-dump-queues to use add_pubsub_args
Also: pubsub-abstraction.md tech spec covering problem statement,
design goals, as-is requirements, candidate broker assessment,
approach, and implementation order.
2026-04-01 20:16:53 +01:00
|
|
|
def decode(self, data: Dict[str, Any]) -> RowsQueryResponse:
|
2025-09-03 23:39:11 +01:00
|
|
|
raise NotImplementedError("Response translation to Pulsar not typically needed")
|
2026-02-23 15:56:29 +00:00
|
|
|
|
Pub/sub abstraction: decouple from Pulsar (#751)
Remove Pulsar-specific concepts from application code so that
the pub/sub backend is swappable via configuration.
Rename translators:
- to_pulsar/from_pulsar → decode/encode across all translator
classes, dispatch handlers, and tests (55+ files)
- from_response_with_completion → encode_with_completion
- Remove pulsar.schema.Record from translator base class
Queue naming (CLASS:TOPICSPACE:TOPIC):
- Replace topic() helper with queue() using new format:
flow:tg:name, request:tg:name, response:tg:name, state:tg:name
- Queue class implies persistence/TTL (no QoS in names)
- Update Pulsar backend map_topic() to parse new format
- Librarian queues use flow class (persistent, for chunking)
- Config push uses state class (persistent, last-value)
- Remove 15 dead topic imports from schema files
- Update init_trustgraph.py namespace: config → state
Confine Pulsar to pulsar_backend.py:
- Delete legacy PulsarClient class from pubsub.py
- Move add_args to add_pubsub_args() with standalone flag
for CLI tools (defaults to localhost)
- PulsarBackendConsumer.receive() catches _pulsar.Timeout,
raises standard TimeoutError
- Remove Pulsar imports from: async_processor, flow_processor,
log_level, all 11 client files, 4 storage writers, gateway
service, gateway config receiver
- Remove log_level/LoggerLevel from client API
- Rewrite tg-monitor-prompts to use backend abstraction
- Update tg-dump-queues to use add_pubsub_args
Also: pubsub-abstraction.md tech spec covering problem statement,
design goals, as-is requirements, candidate broker assessment,
approach, and implementation order.
2026-04-01 20:16:53 +01:00
|
|
|
def encode(self, obj: RowsQueryResponse) -> Dict[str, Any]:
|
2025-09-03 23:39:11 +01:00
|
|
|
result = {}
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
# Handle GraphQL response data
|
|
|
|
|
if obj.data:
|
|
|
|
|
try:
|
|
|
|
|
result["data"] = json.loads(obj.data)
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
result["data"] = obj.data
|
|
|
|
|
else:
|
|
|
|
|
result["data"] = None
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
# Handle GraphQL errors
|
|
|
|
|
if obj.errors:
|
|
|
|
|
result["errors"] = []
|
|
|
|
|
for error in obj.errors:
|
|
|
|
|
error_dict = {
|
|
|
|
|
"message": error.message
|
|
|
|
|
}
|
|
|
|
|
if error.path:
|
|
|
|
|
error_dict["path"] = list(error.path)
|
|
|
|
|
if error.extensions:
|
|
|
|
|
error_dict["extensions"] = dict(error.extensions)
|
|
|
|
|
result["errors"].append(error_dict)
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
# Handle extensions
|
|
|
|
|
if obj.extensions:
|
|
|
|
|
result["extensions"] = dict(obj.extensions)
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
# Handle system-level error
|
|
|
|
|
if obj.error:
|
|
|
|
|
result["error"] = {
|
|
|
|
|
"type": obj.error.type,
|
|
|
|
|
"message": obj.error.message
|
|
|
|
|
}
|
2026-02-23 15:56:29 +00:00
|
|
|
|
2025-09-03 23:39:11 +01:00
|
|
|
return result
|
2026-02-23 15:56:29 +00:00
|
|
|
|
Pub/sub abstraction: decouple from Pulsar (#751)
Remove Pulsar-specific concepts from application code so that
the pub/sub backend is swappable via configuration.
Rename translators:
- to_pulsar/from_pulsar → decode/encode across all translator
classes, dispatch handlers, and tests (55+ files)
- from_response_with_completion → encode_with_completion
- Remove pulsar.schema.Record from translator base class
Queue naming (CLASS:TOPICSPACE:TOPIC):
- Replace topic() helper with queue() using new format:
flow:tg:name, request:tg:name, response:tg:name, state:tg:name
- Queue class implies persistence/TTL (no QoS in names)
- Update Pulsar backend map_topic() to parse new format
- Librarian queues use flow class (persistent, for chunking)
- Config push uses state class (persistent, last-value)
- Remove 15 dead topic imports from schema files
- Update init_trustgraph.py namespace: config → state
Confine Pulsar to pulsar_backend.py:
- Delete legacy PulsarClient class from pubsub.py
- Move add_args to add_pubsub_args() with standalone flag
for CLI tools (defaults to localhost)
- PulsarBackendConsumer.receive() catches _pulsar.Timeout,
raises standard TimeoutError
- Remove Pulsar imports from: async_processor, flow_processor,
log_level, all 11 client files, 4 storage writers, gateway
service, gateway config receiver
- Remove log_level/LoggerLevel from client API
- Rewrite tg-monitor-prompts to use backend abstraction
- Update tg-dump-queues to use add_pubsub_args
Also: pubsub-abstraction.md tech spec covering problem statement,
design goals, as-is requirements, candidate broker assessment,
approach, and implementation order.
2026-04-01 20:16:53 +01:00
|
|
|
def encode_with_completion(self, obj: RowsQueryResponse) -> Tuple[Dict[str, Any], bool]:
|
2025-09-03 23:39:11 +01:00
|
|
|
"""Returns (response_dict, is_final)"""
|
Pub/sub abstraction: decouple from Pulsar (#751)
Remove Pulsar-specific concepts from application code so that
the pub/sub backend is swappable via configuration.
Rename translators:
- to_pulsar/from_pulsar → decode/encode across all translator
classes, dispatch handlers, and tests (55+ files)
- from_response_with_completion → encode_with_completion
- Remove pulsar.schema.Record from translator base class
Queue naming (CLASS:TOPICSPACE:TOPIC):
- Replace topic() helper with queue() using new format:
flow:tg:name, request:tg:name, response:tg:name, state:tg:name
- Queue class implies persistence/TTL (no QoS in names)
- Update Pulsar backend map_topic() to parse new format
- Librarian queues use flow class (persistent, for chunking)
- Config push uses state class (persistent, last-value)
- Remove 15 dead topic imports from schema files
- Update init_trustgraph.py namespace: config → state
Confine Pulsar to pulsar_backend.py:
- Delete legacy PulsarClient class from pubsub.py
- Move add_args to add_pubsub_args() with standalone flag
for CLI tools (defaults to localhost)
- PulsarBackendConsumer.receive() catches _pulsar.Timeout,
raises standard TimeoutError
- Remove Pulsar imports from: async_processor, flow_processor,
log_level, all 11 client files, 4 storage writers, gateway
service, gateway config receiver
- Remove log_level/LoggerLevel from client API
- Rewrite tg-monitor-prompts to use backend abstraction
- Update tg-dump-queues to use add_pubsub_args
Also: pubsub-abstraction.md tech spec covering problem statement,
design goals, as-is requirements, candidate broker assessment,
approach, and implementation order.
2026-04-01 20:16:53 +01:00
|
|
|
return self.encode(obj), True
|