This commit is contained in:
elpresidank 2026-04-05 21:09:33 -05:00
parent 9e9307a2aa
commit e26caa0b12
123 changed files with 3478 additions and 10078 deletions

View file

@ -0,0 +1,32 @@
/**
* Consumer specification declares a message consumer for a flow.
*
* Python reference: trustgraph-base/trustgraph/base/consumer_spec.py
*/
import type { Spec } from "./types.js";
import type { PubSubBackend } from "../backend/types.js";
import type { Flow, FlowDefinition } from "../processor/flow.js";
import { Consumer, type MessageHandler } from "../messaging/consumer.js";
export class ConsumerSpec<T> implements Spec {
constructor(
public readonly name: string,
private readonly handler: MessageHandler<T>,
private readonly concurrency = 1,
) {}
async add(flow: Flow, pubsub: PubSubBackend, definition: FlowDefinition): Promise<void> {
const topic = definition.topics?.[this.name] ?? this.name;
const consumer = new Consumer<T>({
pubsub,
topic,
subscription: `${flow.processorId}-${flow.name}-${this.name}`,
handler: this.handler,
concurrency: this.concurrency,
});
flow.registerConsumer(this.name, consumer as Consumer<unknown>);
}
}

View file

@ -0,0 +1,4 @@
export type { Spec } from "./types.js";
export { ConsumerSpec } from "./consumer-spec.js";
export { ProducerSpec } from "./producer-spec.js";
export { ParameterSpec } from "./parameter-spec.js";

View file

@ -0,0 +1,18 @@
/**
* Parameter specification declares a configuration parameter for a flow.
*
* Python reference: trustgraph-base/trustgraph/base/parameter_spec.py
*/
import type { Spec } from "./types.js";
import type { PubSubBackend } from "../backend/types.js";
import type { Flow, FlowDefinition } from "../processor/flow.js";
export class ParameterSpec implements Spec {
constructor(public readonly name: string) {}
async add(flow: Flow, _pubsub: PubSubBackend, definition: FlowDefinition): Promise<void> {
const value = definition.parameters?.[this.name];
flow.setParameter(this.name, value);
}
}

View file

@ -0,0 +1,21 @@
/**
* Producer specification declares a message producer for a flow.
*
* Python reference: trustgraph-base/trustgraph/base/producer_spec.py
*/
import type { Spec } from "./types.js";
import type { PubSubBackend } from "../backend/types.js";
import type { Flow, FlowDefinition } from "../processor/flow.js";
import { Producer } from "../messaging/producer.js";
export class ProducerSpec<T> implements Spec {
constructor(public readonly name: string) {}
async add(flow: Flow, pubsub: PubSubBackend, definition: FlowDefinition): Promise<void> {
const topic = definition.topics?.[this.name] ?? this.name;
const producer = new Producer<T>(pubsub, topic);
await producer.start();
flow.registerProducer(this.name, producer as Producer<unknown>);
}
}

View file

@ -0,0 +1,13 @@
/**
* Specification types for declarative flow configuration.
*
* Python reference: trustgraph-base/trustgraph/base/spec.py and siblings
*/
import type { PubSubBackend } from "../backend/types.js";
import type { Flow, FlowDefinition } from "../processor/flow.js";
export interface Spec {
name: string;
add(flow: Flow, pubsub: PubSubBackend, definition: FlowDefinition): Promise<void>;
}