mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-02 02:58:10 +02:00
refactor(ts): make port effect native
This commit is contained in:
parent
2868ced2d3
commit
b6759e75df
113 changed files with 4140 additions and 4554 deletions
|
|
@ -5,24 +5,17 @@
|
|||
*/
|
||||
|
||||
import { Effect } from "effect";
|
||||
import * as S from "effect/Schema";
|
||||
import type { Spec } from "./types.js";
|
||||
import type { SpecRuntimeRequirements } from "./types.js";
|
||||
import type { Flow, FlowDefinition } from "../processor/flow.js";
|
||||
import { type MessageHandler } from "../messaging/consumer.js";
|
||||
import {
|
||||
ConsumerFactory,
|
||||
type EffectMessageHandler,
|
||||
} from "../messaging/runtime.js";
|
||||
import {
|
||||
messagingHandlerError,
|
||||
TooManyRequestsError,
|
||||
type MessagingHandlerError,
|
||||
type PubSubError,
|
||||
} from "../errors.js";
|
||||
|
||||
const isTooManyRequestsError = S.is(TooManyRequestsError);
|
||||
|
||||
declare const ConsumerSpecType: unique symbol;
|
||||
|
||||
export interface ConsumerSpec<T, E = never, R = never> extends Spec<R> {
|
||||
|
|
@ -62,26 +55,5 @@ export function makeConsumerSpec<T, E = never, R = never>(
|
|||
return {
|
||||
name,
|
||||
addEffect,
|
||||
add: (flow, pubsub, definition, context) =>
|
||||
flow.runInCompatibilityScope(addEffect(flow, definition), pubsub, context),
|
||||
};
|
||||
}
|
||||
|
||||
export function makeConsumerSpecFromPromise<T>(
|
||||
name: string,
|
||||
handler: MessageHandler<T>,
|
||||
concurrency = 1,
|
||||
): ConsumerSpec<T, TooManyRequestsError | MessagingHandlerError> {
|
||||
return makeConsumerSpec<T, TooManyRequestsError | MessagingHandlerError>(
|
||||
name,
|
||||
(message, properties, flow) =>
|
||||
Effect.tryPromise({
|
||||
try: () => handler(message, properties, flow),
|
||||
catch: (error) =>
|
||||
isTooManyRequestsError(error)
|
||||
? error
|
||||
: messagingHandlerError(name, `${flow.id}-${flow.name}-${name}`, error),
|
||||
}),
|
||||
concurrency,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export type { Spec, SpecRuntimeError, SpecRuntimeRequirements } from "./types.js";
|
||||
export { makeConsumerSpec, makeConsumerSpecFromPromise, type ConsumerSpec } from "./consumer-spec.js";
|
||||
export { makeConsumerSpec, type ConsumerSpec } from "./consumer-spec.js";
|
||||
export { makeProducerSpec, type ProducerSpec } from "./producer-spec.js";
|
||||
export { makeParameterSpec, type ParameterSpec } from "./parameter-spec.js";
|
||||
export { makeRequestResponseSpec, type RequestResponseSpec } from "./request-response-spec.js";
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
* Python reference: trustgraph-base/trustgraph/base/parameter_spec.py
|
||||
*/
|
||||
|
||||
import { Effect, type Context } from "effect";
|
||||
import { Effect } from "effect";
|
||||
import * as S from "effect/Schema";
|
||||
import type { PubSubBackend } from "../backend/types.js";
|
||||
import type { SpecRuntimeRequirements } from "./types.js";
|
||||
import type { Flow, FlowDefinition } from "../processor/flow.js";
|
||||
import type { PubSubError } from "../errors.js";
|
||||
|
|
@ -23,12 +22,6 @@ export interface ParameterSpec<T = unknown> {
|
|||
flow: Flow<Requirements>,
|
||||
definition: FlowDefinition,
|
||||
) => Effect.Effect<void, PubSubError, SpecRuntimeRequirements | Requirements>;
|
||||
readonly add: <Requirements = never>(
|
||||
flow: Flow<Requirements>,
|
||||
pubsub: PubSubBackend,
|
||||
definition: FlowDefinition,
|
||||
context: Context.Context<Requirements>,
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
export function makeParameterSpec(name: string): ParameterSpec<unknown>;
|
||||
|
|
@ -51,12 +44,5 @@ export function makeParameterSpec<T>(
|
|||
name,
|
||||
schema: parameterSchema,
|
||||
addEffect,
|
||||
add: <Requirements = never>(
|
||||
flow: Flow<Requirements>,
|
||||
pubsub: PubSubBackend,
|
||||
definition: FlowDefinition,
|
||||
context: Context.Context<Requirements>,
|
||||
) =>
|
||||
flow.runInCompatibilityScope(addEffect(flow, definition), pubsub, context),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
* Python reference: trustgraph-base/trustgraph/base/producer_spec.py
|
||||
*/
|
||||
|
||||
import { Effect, type Context } from "effect";
|
||||
import { Effect } from "effect";
|
||||
import type { SpecRuntimeRequirements } from "./types.js";
|
||||
import type { Flow, FlowDefinition } from "../processor/flow.js";
|
||||
import type { PubSubBackend } from "../backend/types.js";
|
||||
import {
|
||||
flowResourceNotFoundError,
|
||||
type FlowResourceNotFoundError,
|
||||
|
|
@ -27,12 +26,6 @@ export interface ProducerSpec<T> {
|
|||
flow: Flow<Requirements>,
|
||||
definition: FlowDefinition,
|
||||
) => Effect.Effect<void, PubSubError, SpecRuntimeRequirements | Requirements>;
|
||||
readonly add: <Requirements = never>(
|
||||
flow: Flow<Requirements>,
|
||||
pubsub: PubSubBackend,
|
||||
definition: FlowDefinition,
|
||||
context: Context.Context<Requirements>,
|
||||
) => Promise<void>;
|
||||
readonly producerEffect: <Requirements = never>(
|
||||
flow: Flow<Requirements>,
|
||||
) => Effect.Effect<EffectProducer<T>, FlowResourceNotFoundError>;
|
||||
|
|
@ -84,7 +77,5 @@ export function makeProducerSpec<T>(name: string): ProducerSpec<T> {
|
|||
name,
|
||||
producerEffect,
|
||||
addEffect,
|
||||
add: (flow, pubsub, definition, context) =>
|
||||
flow.runInCompatibilityScope(addEffect(flow, definition), pubsub, context),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@
|
|||
* Python reference: trustgraph-base/trustgraph/base/prompt_client_spec.py
|
||||
*/
|
||||
|
||||
import { Effect, type Context } from "effect";
|
||||
import { Effect } from "effect";
|
||||
import type { SpecRuntimeRequirements } from "./types.js";
|
||||
import type { Flow, FlowDefinition } from "../processor/flow.js";
|
||||
import type { PubSubBackend } from "../backend/types.js";
|
||||
import {
|
||||
flowResourceNotFoundError,
|
||||
type FlowResourceNotFoundError,
|
||||
|
|
@ -33,12 +32,6 @@ export interface RequestResponseSpec<TReq, TRes> {
|
|||
flow: Flow<Requirements>,
|
||||
definition: FlowDefinition,
|
||||
) => Effect.Effect<void, PubSubError, SpecRuntimeRequirements | Requirements>;
|
||||
readonly add: <Requirements = never>(
|
||||
flow: Flow<Requirements>,
|
||||
pubsub: PubSubBackend,
|
||||
definition: FlowDefinition,
|
||||
context: Context.Context<Requirements>,
|
||||
) => Promise<void>;
|
||||
readonly requestorEffect: <Requirements = never>(
|
||||
flow: Flow<Requirements>,
|
||||
) => Effect.Effect<EffectRequestResponse<TReq, TRes>, FlowResourceNotFoundError>;
|
||||
|
|
@ -99,7 +92,5 @@ export function makeRequestResponseSpec<TReq, TRes>(
|
|||
name,
|
||||
requestorEffect,
|
||||
addEffect,
|
||||
add: (flow, pubsub, definition, context) =>
|
||||
flow.runInCompatibilityScope(addEffect(flow, definition), pubsub, context),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
* Python reference: trustgraph-base/trustgraph/base/spec.py and siblings
|
||||
*/
|
||||
|
||||
import type { Context, Effect, Scope } from "effect";
|
||||
import type { PubSubBackend } from "../backend/types.js";
|
||||
import type { Effect, Scope } from "effect";
|
||||
import type {
|
||||
ConsumerFactory,
|
||||
ProducerFactory,
|
||||
|
|
@ -28,10 +27,4 @@ export interface Spec<Requirements = never> {
|
|||
flow: Flow<Requirements>,
|
||||
definition: FlowDefinition,
|
||||
): Effect.Effect<void, SpecRuntimeError, SpecRuntimeRequirements | Requirements>;
|
||||
add(
|
||||
flow: Flow<Requirements>,
|
||||
pubsub: PubSubBackend,
|
||||
definition: FlowDefinition,
|
||||
context: Context.Context<Requirements>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue