effect-durable-agent 0.1.0-alpha.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- package/dist/{commands-Ce1ec6kH.d.ts → commands-BUquEZVP.d.ts} +31 -12
- package/dist/{compaction-BgDr5VJy.js → compaction-D7WJa899.js} +63 -13
- package/dist/compaction-D7WJa899.js.map +1 -0
- package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-Bezx3drD.d.ts} +16 -40
- package/dist/{core-CYT6DBaS.d.ts → core-BcimKMIv.d.ts} +5 -3
- package/dist/delivery-B_LDTuIB.d.ts +3169 -0
- package/dist/delivery-BoF-NZbZ.js +507 -0
- package/dist/delivery-BoF-NZbZ.js.map +1 -0
- package/dist/domain/command-queues.d.ts +81 -2
- package/dist/domain/command-queues.js +1 -1
- package/dist/domain/command-queues.js.map +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/context-projection.js +1 -1
- package/dist/domain/context-projection.js.map +1 -1
- package/dist/domain/message-transcript.d.ts +36 -2
- package/dist/domain/message-transcript.js +10 -2
- package/dist/domain/message-transcript.js.map +1 -1
- package/dist/domain/model-usage.d.ts +1 -1
- package/dist/domain/model-usage.js +1 -1
- package/dist/domain/reduced-state-schema.d.ts +3 -992
- package/dist/domain/reduced-state-schema.js +126 -7
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +2 -2
- package/dist/domain/reduced-state.js +937 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +2 -0
- package/dist/domain/run-scheduling.js +127 -0
- package/dist/domain/run-scheduling.js.map +1 -0
- package/dist/{durable-br2C1bWK.d.ts → durable-BXqwM70o.d.ts} +8983 -2800
- package/dist/{durable-BGFvX7Mh.js → durable-Da57Rcml.js} +243 -15
- package/dist/durable-Da57Rcml.js.map +1 -0
- package/dist/{envelope-DxQzo5rN.js → envelope-BSI_Xh-f.js} +31 -6
- package/dist/envelope-BSI_Xh-f.js.map +1 -0
- package/dist/{envelope-DkZyMIgp.d.ts → envelope-CJnPfbjC.d.ts} +121 -11
- package/dist/{event-factory-DTFdy0Cb.js → event-factory-BUoBwqAy.js} +7 -3
- package/dist/event-factory-BUoBwqAy.js.map +1 -0
- package/dist/{events-LZFNoESe.d.ts → events-AIIwZ6dS.d.ts} +139 -137
- package/dist/{id-generator-Ckl8_XWW.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
- package/dist/in-memory-E497WhtS.js +150 -0
- package/dist/in-memory-E497WhtS.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/interpreter-BwYN2PCC.js +1453 -0
- package/dist/interpreter-BwYN2PCC.js.map +1 -0
- package/dist/{keep-alive-Chl5SJxy.d.ts → keep-alive-_zFCUvt3.d.ts} +1 -2
- package/dist/{model-resolver-BPPJAsuh.d.ts → model-resolver-O8Kn27GH.d.ts} +11 -5
- package/dist/{model-usage-CdBEkTwU.d.ts → model-usage-mttrPN0j.d.ts} +2 -3
- package/dist/records-D0ZIAOzd.js +675 -0
- package/dist/records-D0ZIAOzd.js.map +1 -0
- package/dist/reduced-state-YbjpihEf.d.ts +52933 -0
- package/dist/reduced-state-schema-B9TYxkP9.d.ts +2338 -0
- package/dist/{reducer-registry-aFjz_ZLT.d.ts → reducer-registry-Bqn5B4JO.d.ts} +12 -6
- package/dist/run-scheduling-wakeup-DX2zRAxd.d.ts +24 -0
- package/dist/services/compaction.d.ts +2 -2
- package/dist/services/compaction.js +2 -2
- package/dist/services/decider.d.ts +2 -0
- package/dist/services/decider.js +97 -0
- package/dist/services/decider.js.map +1 -0
- package/dist/services/id-generator.d.ts +1 -1
- package/dist/services/id-generator.js +6 -12
- package/dist/services/id-generator.js.map +1 -1
- package/dist/services/keep-alive.d.ts +1 -1
- package/dist/services/keep-alive.js.map +1 -1
- package/dist/services/model-call.d.ts +15 -0
- package/dist/services/model-call.js +15 -0
- package/dist/services/model-call.js.map +1 -0
- package/dist/services/model-resolver.d.ts +1 -1
- package/dist/services/model-resolver.js +1 -1
- package/dist/services/model-resolver.js.map +1 -1
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +49 -5
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/reducer-registry.js +19 -6
- package/dist/services/reducer-registry.js.map +1 -1
- package/dist/services/run-scheduler.d.ts +2 -2
- package/dist/services/run-scheduler.js +25 -2
- package/dist/services/run-scheduler.js.map +1 -0
- package/dist/services/run-scheduling-wakeup.d.ts +2 -0
- package/dist/services/run-scheduling-wakeup.js +13 -0
- package/dist/services/run-scheduling-wakeup.js.map +1 -0
- package/dist/services/runtime-layer.d.ts +21 -33
- package/dist/services/runtime-layer.js +24 -16
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +32 -20
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +1 -1
- package/dist/services/session-event-observer.js.map +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +57 -10
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +2 -2
- package/dist/services/session-state.js +2 -1
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +143 -38
- package/dist/services/session-store.js.map +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-checkpoint-store.js +2 -1
- package/dist/services/sink-checkpoint-store.js.map +1 -1
- package/dist/services/sink-registry.d.ts +2 -2
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +7 -1
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +2 -2
- package/dist/services/tool-registry.js +12 -3
- package/dist/services/tool-registry.js.map +1 -1
- package/dist/services/tracing.d.ts +3 -3
- package/dist/services/tracing.js +2 -2
- package/dist/services/tracing.js.map +1 -1
- package/dist/session-admission-WE8J_0z9.js +138 -0
- package/dist/session-admission-WE8J_0z9.js.map +1 -0
- package/dist/{session-event-observer-DaFMKKNc.d.ts → session-event-observer-BWQUJTcN.d.ts} +3 -3
- package/dist/{session-state-Bkc6u-Wr.js → session-state-D02LCVcC.js} +815 -170
- package/dist/session-state-D02LCVcC.js.map +1 -0
- package/dist/session-store-DaSHeg8Q.d.ts +3343 -0
- package/dist/{sink-checkpoint-store-M7qIxoSH.d.ts → sink-checkpoint-store-CUvIVvlZ.d.ts} +3 -4
- package/dist/sink-registry-AOjX5_A1.js +369 -0
- package/dist/sink-registry-AOjX5_A1.js.map +1 -0
- package/dist/subscription-BhwUmsl4.d.ts +966 -0
- package/dist/subscription-D7U4Tziv.js +505 -0
- package/dist/subscription-D7U4Tziv.js.map +1 -0
- package/dist/testkit/layers.d.ts +33 -23
- package/dist/testkit/layers.js +34 -19
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +232 -0
- package/dist/testkit/transcript.js +1526 -0
- package/dist/testkit/transcript.js.map +1 -0
- package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
- package/dist/transcript.d.ts +101 -0
- package/dist/transcript.js +107 -0
- package/dist/transcript.js.map +1 -0
- package/dist/types/commands.d.ts +2 -2
- package/dist/types/commands.js +8 -3
- package/dist/types/commands.js.map +1 -1
- package/dist/types/core.d.ts +2 -2
- package/dist/types/core.js +3 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +5 -5
- package/dist/types/events.js +3 -3
- package/dist/types/tracing.d.ts +1 -1
- package/dist/types/tracing.js.map +1 -1
- package/dist/websocket/events.d.ts +2 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket.d.ts +2123 -2552
- package/dist/websocket.js +628 -442
- package/dist/websocket.js.map +1 -1
- package/dist/window-read-BELSkO-r.d.ts +113 -0
- package/dist/window-read-FJTCDaSq.js +264 -0
- package/dist/window-read-FJTCDaSq.js.map +1 -0
- package/package.json +41 -13
- package/dist/command-queues-DdDB_aYM.d.ts +0 -462
- package/dist/compaction-BgDr5VJy.js.map +0 -1
- package/dist/compaction-ch8z6G9x.d.ts +0 -165
- package/dist/durable-BGFvX7Mh.js.map +0 -1
- package/dist/envelope-DxQzo5rN.js.map +0 -1
- package/dist/event-factory-DTFdy0Cb.js.map +0 -1
- package/dist/event-factory-Di1jwQvm.d.ts +0 -87
- package/dist/index-BVVgDSdq.d.ts +0 -1
- package/dist/message-transcript-DQNlzxle.d.ts +0 -32
- package/dist/prompt-projector-f4ElyXCE.d.ts +0 -39
- package/dist/reduced-state-DF0-6mbR.js +0 -921
- package/dist/reduced-state-DF0-6mbR.js.map +0 -1
- package/dist/run-scheduler-CAt7dF6C.js +0 -21
- package/dist/run-scheduler-CAt7dF6C.js.map +0 -1
- package/dist/run-scheduler-xkhZyto5.d.ts +0 -44
- package/dist/runtime-DDSYP9jS.d.ts +0 -63
- package/dist/session-query-B72HY_0L.d.ts +0 -45
- package/dist/session-state-Bkc6u-Wr.js.map +0 -1
- package/dist/session-state-C9YLSAso.d.ts +0 -862
- package/dist/session-store-Cpi_NwTR.d.ts +0 -206
- package/dist/sink-registry-Bl-vQES6.d.ts +0 -133
- package/dist/sink-registry-NDgeyzO0.js +0 -272
- package/dist/sink-registry-NDgeyzO0.js.map +0 -1
- package/dist/tool-registry-BJaVNtw4.d.ts +0 -51
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
|
|
2
|
-
import { _ as SummaryId, h as SessionId, m as SequenceNumber, n as CommandId } from "./core-CYT6DBaS.js";
|
|
3
|
-
import { n as CommandIdempotencyKey } from "./commands-Ce1ec6kH.js";
|
|
4
|
-
import { r as CompactionSummaryArtifact } from "./context-projection-n6Rdup0N.js";
|
|
5
|
-
import * as Context from "effect/Context";
|
|
6
|
-
import * as Effect from "effect/Effect";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Schema from "effect/Schema";
|
|
9
|
-
import * as Stream from "effect/Stream";
|
|
10
|
-
import * as Cause from "effect/Cause";
|
|
11
|
-
|
|
12
|
-
//#region src/services/session-store.d.ts
|
|
13
|
-
/** A durable event after the store has assigned its replay position. */
|
|
14
|
-
declare const CommittedDurableEvent: Schema.Struct<{
|
|
15
|
-
readonly position: Schema.Struct<{
|
|
16
|
-
readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
17
|
-
readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
|
|
18
|
-
}>;
|
|
19
|
-
readonly event: Schema.Struct<{
|
|
20
|
-
readonly durability: Schema.Literal<"durable">;
|
|
21
|
-
readonly namespace: Schema.NonEmptyString;
|
|
22
|
-
readonly type: Schema.NonEmptyString;
|
|
23
|
-
readonly schemaVersion: Schema.Int;
|
|
24
|
-
readonly eventId: Schema.brand<Schema.String, "EventId">;
|
|
25
|
-
readonly sessionId: Schema.brand<Schema.String, "SessionId">;
|
|
26
|
-
readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
|
|
27
|
-
readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
28
|
-
readonly trace: Schema.withConstructorDefault<Schema.Struct<{
|
|
29
|
-
readonly span: Schema.Struct<{
|
|
30
|
-
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
31
|
-
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
32
|
-
readonly sampled: Schema.Boolean;
|
|
33
|
-
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
34
|
-
}>;
|
|
35
|
-
readonly links: Schema.$Array<Schema.Struct<{
|
|
36
|
-
readonly context: Schema.Struct<{
|
|
37
|
-
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
38
|
-
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
39
|
-
readonly sampled: Schema.Boolean;
|
|
40
|
-
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
41
|
-
}>;
|
|
42
|
-
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
43
|
-
}>>;
|
|
44
|
-
}>>;
|
|
45
|
-
readonly payload: Schema.Unknown;
|
|
46
|
-
}>;
|
|
47
|
-
}>;
|
|
48
|
-
type CommittedDurableEvent = typeof CommittedDurableEvent.Type;
|
|
49
|
-
declare const EDASessionStoreError_base: Schema.Class<EDASessionStoreError, Schema.TaggedStruct<"EDASessionStoreError", {
|
|
50
|
-
readonly message: Schema.String;
|
|
51
|
-
}>, Cause.YieldableError>;
|
|
52
|
-
/**
|
|
53
|
-
* Store-level failure surfaced by durable append, replay, and hydration APIs.
|
|
54
|
-
*
|
|
55
|
-
* The error intentionally stays storage-semantic rather than SQL-specific so
|
|
56
|
-
* framework services can treat SQL-backed hosts, in-memory tests, and future adapters
|
|
57
|
-
* as the same durability boundary.
|
|
58
|
-
*/
|
|
59
|
-
declare class EDASessionStoreError extends EDASessionStoreError_base {}
|
|
60
|
-
/** True when a Cause contains an escaped durable-store failure. */
|
|
61
|
-
declare const hasEDASessionStoreError: (cause: Cause.Cause<unknown>) => boolean;
|
|
62
|
-
/**
|
|
63
|
-
* One logical event to persist in the durable session log.
|
|
64
|
-
*
|
|
65
|
-
* Store adapters may split large logical payload fields into sidecar rows after
|
|
66
|
-
* the event insert assigns `seq`, but callers still provide one fat event.
|
|
67
|
-
*/
|
|
68
|
-
declare const DurableAppendEntry: Schema.Struct<{
|
|
69
|
-
readonly event: Schema.Struct<{
|
|
70
|
-
readonly durability: Schema.Literal<"durable">;
|
|
71
|
-
readonly namespace: Schema.NonEmptyString;
|
|
72
|
-
readonly type: Schema.NonEmptyString;
|
|
73
|
-
readonly schemaVersion: Schema.Int;
|
|
74
|
-
readonly eventId: Schema.brand<Schema.String, "EventId">;
|
|
75
|
-
readonly sessionId: Schema.brand<Schema.String, "SessionId">;
|
|
76
|
-
readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
|
|
77
|
-
readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
78
|
-
readonly trace: Schema.withConstructorDefault<Schema.Struct<{
|
|
79
|
-
readonly span: Schema.Struct<{
|
|
80
|
-
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
81
|
-
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
82
|
-
readonly sampled: Schema.Boolean;
|
|
83
|
-
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
84
|
-
}>;
|
|
85
|
-
readonly links: Schema.$Array<Schema.Struct<{
|
|
86
|
-
readonly context: Schema.Struct<{
|
|
87
|
-
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
88
|
-
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
89
|
-
readonly sampled: Schema.Boolean;
|
|
90
|
-
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
91
|
-
}>;
|
|
92
|
-
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
93
|
-
}>>;
|
|
94
|
-
}>>;
|
|
95
|
-
readonly payload: Schema.Unknown;
|
|
96
|
-
}>;
|
|
97
|
-
}>;
|
|
98
|
-
type DurableAppendEntry = typeof DurableAppendEntry.Type;
|
|
99
|
-
/**
|
|
100
|
-
* Ordered durable append intent. Adapters assign positions in entry order.
|
|
101
|
-
*
|
|
102
|
-
* This is the single write shape exposed to framework services. It avoids raw
|
|
103
|
-
* SQL and public transaction callbacks while still expressing the full atomic
|
|
104
|
-
* transition EDA needs for events, normalized bodies, and metadata.
|
|
105
|
-
*/
|
|
106
|
-
declare const DurableAppendBatch: Schema.Struct<{
|
|
107
|
-
readonly entries: Schema.$Array<Schema.Struct<{
|
|
108
|
-
readonly event: Schema.Struct<{
|
|
109
|
-
readonly durability: Schema.Literal<"durable">;
|
|
110
|
-
readonly namespace: Schema.NonEmptyString;
|
|
111
|
-
readonly type: Schema.NonEmptyString;
|
|
112
|
-
readonly schemaVersion: Schema.Int;
|
|
113
|
-
readonly eventId: Schema.brand<Schema.String, "EventId">;
|
|
114
|
-
readonly sessionId: Schema.brand<Schema.String, "SessionId">;
|
|
115
|
-
readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
|
|
116
|
-
readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
117
|
-
readonly trace: Schema.withConstructorDefault<Schema.Struct<{
|
|
118
|
-
readonly span: Schema.Struct<{
|
|
119
|
-
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
120
|
-
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
121
|
-
readonly sampled: Schema.Boolean;
|
|
122
|
-
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
123
|
-
}>;
|
|
124
|
-
readonly links: Schema.$Array<Schema.Struct<{
|
|
125
|
-
readonly context: Schema.Struct<{
|
|
126
|
-
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
127
|
-
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
128
|
-
readonly sampled: Schema.Boolean;
|
|
129
|
-
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
130
|
-
}>;
|
|
131
|
-
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
132
|
-
}>>;
|
|
133
|
-
}>>;
|
|
134
|
-
readonly payload: Schema.Unknown;
|
|
135
|
-
}>;
|
|
136
|
-
}>>;
|
|
137
|
-
}>;
|
|
138
|
-
type DurableAppendBatch = typeof DurableAppendBatch.Type;
|
|
139
|
-
/** Durable reducer checkpoint row used to hydrate framework and app projections cheaply. */
|
|
140
|
-
interface EDAReducerCheckpoint {
|
|
141
|
-
readonly name: string;
|
|
142
|
-
readonly schemaVersion: number;
|
|
143
|
-
readonly throughSeq: SequenceNumber;
|
|
144
|
-
readonly payload: unknown;
|
|
145
|
-
readonly updatedAtMs: number;
|
|
146
|
-
}
|
|
147
|
-
/** Input for writing one durable reducer checkpoint. */
|
|
148
|
-
interface SaveReducerCheckpointInput {
|
|
149
|
-
readonly name: string;
|
|
150
|
-
readonly schemaVersion: number;
|
|
151
|
-
readonly throughSeq: SequenceNumber;
|
|
152
|
-
readonly payload: unknown;
|
|
153
|
-
readonly updatedAtMs: number;
|
|
154
|
-
}
|
|
155
|
-
/** Indexed command-admission lookup used for idempotent ingress. */
|
|
156
|
-
declare const FindCommandAdmissionInput: Schema.Struct<{
|
|
157
|
-
readonly commandId: Schema.optionalKey<Schema.brand<Schema.String, "CommandId">>;
|
|
158
|
-
readonly idempotencyKey: Schema.optionalKey<Schema.String>;
|
|
159
|
-
}>;
|
|
160
|
-
/** Typed command-admission lookup accepted by the semantic store port. */
|
|
161
|
-
interface FindCommandAdmissionInput {
|
|
162
|
-
readonly commandId?: CommandId;
|
|
163
|
-
readonly idempotencyKey?: CommandIdempotencyKey;
|
|
164
|
-
}
|
|
165
|
-
/** Semantic durable store contract for one EDA session. */
|
|
166
|
-
interface EDASessionStoreShape {
|
|
167
|
-
/**
|
|
168
|
-
* Append durable logical events atomically, preserving input order.
|
|
169
|
-
*
|
|
170
|
-
* Implementations must be idempotent by `eventId`: duplicates return the
|
|
171
|
-
* original committed position and do not advance the durable head. Live publish
|
|
172
|
-
* remains outside the store and is owned by `SessionState` after this succeeds.
|
|
173
|
-
*/
|
|
174
|
-
readonly append: (batch: DurableAppendBatch) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
|
|
175
|
-
/** Replay committed durable events with `seq > afterSeq`. */
|
|
176
|
-
readonly eventsAfter: (afterSeq: SequenceNumber) => Stream.Stream<CommittedDurableEvent, EDASessionStoreError>;
|
|
177
|
-
/** Load committed durable events by exact sequence number for checkpoint pointer hydration. */
|
|
178
|
-
readonly loadCommittedEventsBySeq: (seqs: ReadonlyArray<SequenceNumber>) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
|
|
179
|
-
/** Lookup an admitted command without replaying the full journal. */
|
|
180
|
-
readonly findCommandAdmission: (input: FindCommandAdmissionInput) => Effect.Effect<CommittedDurableEvent | undefined, EDASessionStoreError>;
|
|
181
|
-
/** Load one compacted summary artifact body by id, if it has been saved. */
|
|
182
|
-
readonly loadSummaryArtifact: (summaryId: SummaryId) => Effect.Effect<CompactionSummaryArtifact | undefined, EDASessionStoreError>;
|
|
183
|
-
/** Load one framework or app reducer checkpoint, if it has been saved. */
|
|
184
|
-
readonly loadReducerCheckpoint: (name: string) => Effect.Effect<EDAReducerCheckpoint | undefined, EDASessionStoreError>;
|
|
185
|
-
/** Persist one framework or app reducer checkpoint as a derived cache. */
|
|
186
|
-
readonly saveReducerCheckpoint: (checkpoint: SaveReducerCheckpointInput) => Effect.Effect<void, EDASessionStoreError>;
|
|
187
|
-
/** Persist a reducer checkpoint snapshot atomically across framework and app reducers. */
|
|
188
|
-
readonly saveReducerCheckpoints: (checkpoints: ReadonlyArray<SaveReducerCheckpointInput>) => Effect.Effect<void, EDASessionStoreError>;
|
|
189
|
-
}
|
|
190
|
-
declare const EDASessionStore_base: Context.ServiceClass<EDASessionStore, "@effect-durable-agent/EDASessionStore", EDASessionStoreShape>;
|
|
191
|
-
/**
|
|
192
|
-
* SQL-agnostic durable storage port for one EDA session.
|
|
193
|
-
*
|
|
194
|
-
* Framework services depend on this semantic port rather than raw SQL. Host
|
|
195
|
-
* adapters own physical tables and synchronous transaction mechanics; callers
|
|
196
|
-
* only express durable append/replay/lookup intent.
|
|
197
|
-
*/
|
|
198
|
-
declare class EDASessionStore extends EDASessionStore_base {
|
|
199
|
-
/** Deterministic in-memory implementation used by runtime and recovery tests. */
|
|
200
|
-
static readonly InMemory: (sessionId: SessionId) => Layer.Layer<EDASessionStore, never, never>;
|
|
201
|
-
/** In-memory store seeded with a durable prefix; intended for recovery tests. */
|
|
202
|
-
static readonly InMemorySeeded: (sessionId: SessionId, events: ReadonlyArray<DurableEventEnvelope>) => Layer.Layer<EDASessionStore, never, never>;
|
|
203
|
-
}
|
|
204
|
-
//#endregion
|
|
205
|
-
export { EDASessionStore as a, FindCommandAdmissionInput as c, EDAReducerCheckpoint as i, SaveReducerCheckpointInput as l, DurableAppendBatch as n, EDASessionStoreError as o, DurableAppendEntry as r, EDASessionStoreShape as s, CommittedDurableEvent as t, hasEDASessionStoreError as u };
|
|
206
|
-
//# sourceMappingURL=session-store-Cpi_NwTR.d.ts.map
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { d as PositionedEvent, n as EphemeralEventEnvelope, o as EventType, t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
|
|
2
|
-
import { c as EventId, h as SessionId, m as SequenceNumber, y as TurnId } from "./core-CYT6DBaS.js";
|
|
3
|
-
import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-Cpi_NwTR.js";
|
|
4
|
-
import { S as ReducedState } from "./command-queues-DdDB_aYM.js";
|
|
5
|
-
import { t as IdGenerator } from "./id-generator-Ckl8_XWW.js";
|
|
6
|
-
import { n as EventFactoryShape, r as SessionContext, t as EventFactory } from "./event-factory-Di1jwQvm.js";
|
|
7
|
-
import { t as EDAKeepAlive } from "./keep-alive-Chl5SJxy.js";
|
|
8
|
-
import { t as SessionEventObserver } from "./session-event-observer-DaFMKKNc.js";
|
|
9
|
-
import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-aFjz_ZLT.js";
|
|
10
|
-
import { n as SinkCheckpointStore } from "./sink-checkpoint-store-M7qIxoSH.js";
|
|
11
|
-
import * as Context from "effect/Context";
|
|
12
|
-
import * as Effect from "effect/Effect";
|
|
13
|
-
import * as Layer from "effect/Layer";
|
|
14
|
-
import * as Schema from "effect/Schema";
|
|
15
|
-
import * as Stream from "effect/Stream";
|
|
16
|
-
import * as Scope from "effect/Scope";
|
|
17
|
-
import * as PubSub from "effect/PubSub";
|
|
18
|
-
|
|
19
|
-
//#region src/services/live-event-bus.d.ts
|
|
20
|
-
/** Live-only replay buffer for the currently open turn. */
|
|
21
|
-
interface ActiveTurnEphemeralReplay {
|
|
22
|
-
readonly turnId?: TurnId;
|
|
23
|
-
readonly events: ReadonlyArray<PositionedEvent>;
|
|
24
|
-
readonly overflowed: boolean;
|
|
25
|
-
}
|
|
26
|
-
/** In-memory live fanout plus active-turn replay source for reconnect streams. */
|
|
27
|
-
interface LiveEventBusShape {
|
|
28
|
-
readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;
|
|
29
|
-
readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;
|
|
30
|
-
readonly subscribeQueue: () => Effect.Effect<PubSub.Subscription<PositionedEvent>, never, Scope.Scope>;
|
|
31
|
-
/** Snapshot raw live-only events retained for the currently open turn. */
|
|
32
|
-
readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;
|
|
33
|
-
}
|
|
34
|
-
declare const LiveEventBus_base: Context.ServiceClass<LiveEventBus, "@effect-durable-agent/LiveEventBus", LiveEventBusShape>;
|
|
35
|
-
/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
|
|
36
|
-
declare class LiveEventBus extends LiveEventBus_base {
|
|
37
|
-
static readonly Live: Layer.Layer<LiveEventBus, never, SessionEventObserver>;
|
|
38
|
-
/** Live bus for hosts that do not install an append-driven observer. */
|
|
39
|
-
static readonly Noop: Layer.Layer<LiveEventBus, never, never>;
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/services/sink-registry.d.ts
|
|
43
|
-
/** Cursor-window input delivered to one durable sink drain. */
|
|
44
|
-
interface EDASinkDurableBatch {
|
|
45
|
-
/** All durable events replayed for this cursor window, including uninterested events. */
|
|
46
|
-
readonly allEvents: ReadonlyArray<CommittedDurableEvent>;
|
|
47
|
-
/** Events matching the sink's durable interests. */
|
|
48
|
-
readonly events: ReadonlyArray<CommittedDurableEvent>;
|
|
49
|
-
/** Authoritative reduced state folded exactly through `throughSeq`. */
|
|
50
|
-
readonly stateAfter: ReducedState;
|
|
51
|
-
/** App-specific durable reducer states folded exactly through `throughSeq`. */
|
|
52
|
-
readonly reducerStates: EDAReducerStateSnapshot;
|
|
53
|
-
/** Durable sequence through which the sink may advance after success. */
|
|
54
|
-
readonly throughSeq: SequenceNumber;
|
|
55
|
-
}
|
|
56
|
-
/** Typed, sink-owned durable state stored independently from cursor advancement. */
|
|
57
|
-
interface EDASinkCheckpoint {
|
|
58
|
-
/** Decode current durable state, or return `initial` for a new or legacy cursor row. */
|
|
59
|
-
readonly get: <State>(schema: Schema.Codec<State, unknown, never, never>, initial: State) => Effect.Effect<State, EDASessionStoreError>;
|
|
60
|
-
/** Validate, encode, and durably save state without advancing the sink cursor. */
|
|
61
|
-
readonly save: <State>(schema: Schema.Codec<State, unknown, never, never>, state: State) => Effect.Effect<void, EDASessionStoreError>;
|
|
62
|
-
}
|
|
63
|
-
/** Capabilities exposed to sink processors without granting raw store or bus access. */
|
|
64
|
-
interface EDASinkContext {
|
|
65
|
-
readonly sessionId: SessionId;
|
|
66
|
-
/** Sink-owned checkpoint state, serialized with cursor commits and background writes. */
|
|
67
|
-
readonly checkpoint: EDASinkCheckpoint;
|
|
68
|
-
/** Build a framework durable event if the sink needs to emit one. */
|
|
69
|
-
readonly events: EventFactoryShape;
|
|
70
|
-
/** Mint an app durable event id for staged custom events. */
|
|
71
|
-
readonly makeEventId: () => Effect.Effect<EventId>;
|
|
72
|
-
/** Publish a best-effort live-only event. */
|
|
73
|
-
readonly emitEphemeral: (event: EphemeralEventEnvelope) => Effect.Effect<PositionedEvent, EDASessionStoreError>;
|
|
74
|
-
/** Stage durable events; the runner commits them after the sink succeeds. */
|
|
75
|
-
readonly stageDurable: (event: DurableEventEnvelope) => Effect.Effect<void>;
|
|
76
|
-
/** Fork background sink work into the session scope. */
|
|
77
|
-
readonly forkScoped: (effect: Effect.Effect<unknown, unknown>) => Effect.Effect<void>;
|
|
78
|
-
}
|
|
79
|
-
/** Durable sink definition backed by a checkpoint and an app-owned delivery policy. */
|
|
80
|
-
interface EDADurableSinkDefinition {
|
|
81
|
-
readonly interests?: ReadonlyArray<EventType | string>;
|
|
82
|
-
readonly batchSize?: number;
|
|
83
|
-
readonly process: (batch: EDASinkDurableBatch, ctx: EDASinkContext) => Effect.Effect<void, never>;
|
|
84
|
-
}
|
|
85
|
-
/** Best-effort live-only sink definition. */
|
|
86
|
-
interface EDAEphemeralSinkDefinition {
|
|
87
|
-
readonly interests?: ReadonlyArray<EventType | string>;
|
|
88
|
-
readonly process: (event: PositionedEvent, ctx: EDASinkContext) => Effect.Effect<void, never>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Named app integration hook with optional durable and ephemeral filters.
|
|
92
|
-
*
|
|
93
|
-
* Every sink runs on one serialized position-ordered lane. Sinks own retry and
|
|
94
|
-
* terminal failure handling, so callbacks must have an infallible typed error
|
|
95
|
-
* channel. An unexpected defect is logged and skipped before the durable checkpoint
|
|
96
|
-
* advances. Ephemeral callbacks are best-effort and are only processed after the
|
|
97
|
-
* durable prefix at their anchor sequence has been projected.
|
|
98
|
-
*/
|
|
99
|
-
interface EDASink {
|
|
100
|
-
readonly name: string;
|
|
101
|
-
readonly durable?: EDADurableSinkDefinition;
|
|
102
|
-
readonly ephemeral?: EDAEphemeralSinkDefinition;
|
|
103
|
-
}
|
|
104
|
-
/** Convenience constructor preserving a sink's literal name/type information. */
|
|
105
|
-
declare const EDASink: {
|
|
106
|
-
make: <const Sink extends EDASink>(sink: Sink) => Sink;
|
|
107
|
-
};
|
|
108
|
-
/** Session-owned capabilities needed to start all registered sink runners. */
|
|
109
|
-
interface EDASinkRunnerStartInput {
|
|
110
|
-
readonly appendDurableBatch: (events: ReadonlyArray<DurableEventEnvelope>) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
|
|
111
|
-
readonly initialHead: SequenceNumber;
|
|
112
|
-
readonly publishEphemeral: (event: EphemeralEventEnvelope) => Effect.Effect<PositionedEvent, EDASessionStoreError>;
|
|
113
|
-
readonly scope: Scope.Scope;
|
|
114
|
-
}
|
|
115
|
-
/** Registry service coordinating durable checkpoints and live sink delivery. */
|
|
116
|
-
interface EDASinkRegistryShape {
|
|
117
|
-
readonly sinks: ReadonlyArray<EDASink>;
|
|
118
|
-
/** Start long-lived sink runners. Safe to call once during session-state acquisition. */
|
|
119
|
-
readonly startSinkRunners: (input: EDASinkRunnerStartInput) => Effect.Effect<void, EDASessionStoreError>;
|
|
120
|
-
/** Coalesced non-blocking nudge that the durable log head advanced. */
|
|
121
|
-
readonly notifyDurableHeadAdvanced: (head: SequenceNumber) => Effect.Effect<void>;
|
|
122
|
-
/** Best-effort non-blocking delivery to ephemeral sink workers. */
|
|
123
|
-
readonly publishEphemeralToSinks: (event: PositionedEvent, publishEphemeral: (event: EphemeralEventEnvelope) => Effect.Effect<PositionedEvent, EDASessionStoreError>) => Effect.Effect<void>;
|
|
124
|
-
}
|
|
125
|
-
declare const EDASinkRegistry_base: Context.ServiceClass<EDASinkRegistry, "@effect-durable-agent/EDASinkRegistry", EDASinkRegistryShape>;
|
|
126
|
-
/** Registry and runner for app-provided EDA sinks. */
|
|
127
|
-
declare class EDASinkRegistry extends EDASinkRegistry_base {
|
|
128
|
-
static readonly Empty: Layer.Layer<EDASinkRegistry, never, never>;
|
|
129
|
-
static readonly Live: (sinks: ReadonlyArray<EDASink>) => Layer.Layer<EDASinkRegistry, never, IdGenerator | EDAKeepAlive | EDAReducerRegistry | EDASessionStore | SinkCheckpointStore | LiveEventBus | SessionContext | EventFactory>;
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
|
-
export { EDASinkContext as a, EDASinkRegistryShape as c, EDASinkCheckpoint as i, EDASinkRunnerStartInput as l, EDAEphemeralSinkDefinition as n, EDASinkDurableBatch as o, EDASink as r, EDASinkRegistry as s, EDADurableSinkDefinition as t, LiveEventBus as u };
|
|
133
|
-
//# sourceMappingURL=sink-registry-Bl-vQES6.d.ts.map
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { SequenceNumber, durablePosition } from "./types/core.js";
|
|
2
|
-
import { $n as turnFailedEventType, Qn as turnCompletedEventType, er as turnStartedEventType, tr as turnStoppedEventType } from "./durable-BGFvX7Mh.js";
|
|
3
|
-
import { f as reduceCommittedEvents, o as foldReducedState } from "./reduced-state-DF0-6mbR.js";
|
|
4
|
-
import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from "./services/session-store.js";
|
|
5
|
-
import { IdGenerator } from "./services/id-generator.js";
|
|
6
|
-
import { n as SessionContext, t as EventFactory } from "./event-factory-DTFdy0Cb.js";
|
|
7
|
-
import { annotateEdaSpan } from "./services/tracing.js";
|
|
8
|
-
import { EDAKeepAlive } from "./services/keep-alive.js";
|
|
9
|
-
import { SessionEventObserver } from "./services/session-event-observer.js";
|
|
10
|
-
import { EDAReducerRegistry } from "./services/reducer-registry.js";
|
|
11
|
-
import { EDASinkName, SinkCheckpointStore } from "./services/sink-checkpoint-store.js";
|
|
12
|
-
import * as Context from "effect/Context";
|
|
13
|
-
import * as Effect from "effect/Effect";
|
|
14
|
-
import * as Layer from "effect/Layer";
|
|
15
|
-
import * as Schema from "effect/Schema";
|
|
16
|
-
import * as Stream from "effect/Stream";
|
|
17
|
-
import * as Cause from "effect/Cause";
|
|
18
|
-
import * as Ref from "effect/Ref";
|
|
19
|
-
import * as Scope from "effect/Scope";
|
|
20
|
-
import * as PubSub from "effect/PubSub";
|
|
21
|
-
import * as SynchronizedRef from "effect/SynchronizedRef";
|
|
22
|
-
//#region src/services/live-event-bus.ts
|
|
23
|
-
/** Conservative raw-delta cap for one open turn's live-only reconnect replay. */
|
|
24
|
-
const activeTurnEphemeralReplayCapacity = 4096;
|
|
25
|
-
/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
|
|
26
|
-
var LiveEventBus = class LiveEventBus extends Context.Service()("@effect-durable-agent/LiveEventBus") {
|
|
27
|
-
static Live = Layer.effect(LiveEventBus, Effect.gen(function* () {
|
|
28
|
-
return makeLiveBus(yield* Effect.acquireRelease(PubSub.unbounded(), PubSub.shutdown), yield* Ref.make({
|
|
29
|
-
events: [],
|
|
30
|
-
overflowed: false
|
|
31
|
-
}), yield* SessionEventObserver);
|
|
32
|
-
}));
|
|
33
|
-
/** Live bus for hosts that do not install an append-driven observer. */
|
|
34
|
-
static Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));
|
|
35
|
-
};
|
|
36
|
-
const makeLiveBus = (pubsub, activeTurnReplay, observer) => ({
|
|
37
|
-
publish: (event) => Effect.gen(function* () {
|
|
38
|
-
yield* updateActiveTurnReplay(activeTurnReplay, event);
|
|
39
|
-
yield* observer.onEvent(event);
|
|
40
|
-
return yield* PubSub.publish(pubsub, event);
|
|
41
|
-
}),
|
|
42
|
-
subscribeQueue: () => PubSub.subscribe(pubsub),
|
|
43
|
-
subscribe: () => Effect.map(PubSub.subscribe(pubsub), (subscription) => Stream.fromEffectRepeat(PubSub.take(subscription))),
|
|
44
|
-
activeTurnReplay: () => Ref.get(activeTurnReplay)
|
|
45
|
-
});
|
|
46
|
-
const updateActiveTurnReplay = (ref, event) => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));
|
|
47
|
-
const nextActiveTurnReplay = (state, event) => {
|
|
48
|
-
if (event.event.type === turnStartedEventType) return {
|
|
49
|
-
turnId: event.event.payload.turnId,
|
|
50
|
-
events: [],
|
|
51
|
-
overflowed: false
|
|
52
|
-
};
|
|
53
|
-
if (event.event.type === turnCompletedEventType || event.event.type === turnFailedEventType || event.event.type === turnStoppedEventType) {
|
|
54
|
-
const turnId = event.event.payload.turnId;
|
|
55
|
-
return turnId === void 0 || state.turnId === void 0 || turnId === state.turnId ? {
|
|
56
|
-
events: [],
|
|
57
|
-
overflowed: false
|
|
58
|
-
} : state;
|
|
59
|
-
}
|
|
60
|
-
if (event.event.durability !== "ephemeral" || state.turnId === void 0) return state;
|
|
61
|
-
const events = [...state.events, event];
|
|
62
|
-
if (events.length <= 4096) return {
|
|
63
|
-
...state,
|
|
64
|
-
events
|
|
65
|
-
};
|
|
66
|
-
return {
|
|
67
|
-
...state,
|
|
68
|
-
events: events.slice(events.length - activeTurnEphemeralReplayCapacity),
|
|
69
|
-
overflowed: true
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/services/sink-registry.ts
|
|
74
|
-
/** Convenience constructor preserving a sink's literal name/type information. */
|
|
75
|
-
const EDASink = { make: (sink) => sink };
|
|
76
|
-
/** Registry and runner for app-provided EDA sinks. */
|
|
77
|
-
var EDASinkRegistry = class EDASinkRegistry extends Context.Service()("@effect-durable-agent/EDASinkRegistry") {
|
|
78
|
-
static Empty = Layer.succeed(EDASinkRegistry, {
|
|
79
|
-
sinks: [],
|
|
80
|
-
startSinkRunners: () => Effect.void,
|
|
81
|
-
notifyDurableHeadAdvanced: () => Effect.void,
|
|
82
|
-
publishEphemeralToSinks: () => Effect.void
|
|
83
|
-
});
|
|
84
|
-
static Live = (sinks) => Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));
|
|
85
|
-
};
|
|
86
|
-
const defaultBatchSize = 100;
|
|
87
|
-
const sinkCheckpointFormatVersion = 1;
|
|
88
|
-
const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
89
|
-
const session = yield* SessionContext;
|
|
90
|
-
const store = yield* EDASessionStore;
|
|
91
|
-
const liveBus = yield* LiveEventBus;
|
|
92
|
-
const checkpointStore = yield* SinkCheckpointStore;
|
|
93
|
-
const eventFactory = yield* EventFactory;
|
|
94
|
-
const ids = yield* IdGenerator;
|
|
95
|
-
const reducerRegistry = yield* EDAReducerRegistry;
|
|
96
|
-
const keepAlive = yield* EDAKeepAlive;
|
|
97
|
-
const started = yield* Ref.make(false);
|
|
98
|
-
const baseContext = (staged, publishEphemeral, scope, checkpoint) => ({
|
|
99
|
-
sessionId: session.sessionId,
|
|
100
|
-
checkpoint,
|
|
101
|
-
events: eventFactory,
|
|
102
|
-
makeEventId: ids.makeEventId,
|
|
103
|
-
emitEphemeral: publishEphemeral,
|
|
104
|
-
stageDurable: (event) => Effect.sync(() => staged.push(event)),
|
|
105
|
-
forkScoped: (effect) => effect.pipe(Effect.forkIn(scope), Effect.asVoid)
|
|
106
|
-
});
|
|
107
|
-
const makeSinkRunner = (sink, input) => Effect.gen(function* () {
|
|
108
|
-
const sinkName = EDASinkName.make(sink.name);
|
|
109
|
-
const storedCheckpoint = yield* checkpointStore.load(sinkName);
|
|
110
|
-
const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);
|
|
111
|
-
const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);
|
|
112
|
-
const cursor = storedCheckpoint.afterSeq;
|
|
113
|
-
const prefix = yield* readDurablePrefixThrough(store, cursor);
|
|
114
|
-
const state = yield* Ref.make({
|
|
115
|
-
cursor,
|
|
116
|
-
reduced: reduceCommittedEvents(prefix),
|
|
117
|
-
reducerStates: reducerRegistry.reduce(reducerRegistry.initial, prefix)
|
|
118
|
-
});
|
|
119
|
-
const live = yield* liveBus.subscribeQueue().pipe(Scope.provide(input.scope));
|
|
120
|
-
const processDurableBatch = Effect.fnUntraced(function* (allEvents) {
|
|
121
|
-
if (allEvents.length === 0) return;
|
|
122
|
-
const current = yield* Ref.get(state);
|
|
123
|
-
const fresh = allEvents.filter((entry) => entry.position.seq > current.cursor);
|
|
124
|
-
if (fresh.length === 0) return;
|
|
125
|
-
const durable = sink.durable;
|
|
126
|
-
const throughSeq = fresh.at(-1).position.seq;
|
|
127
|
-
const nextReduced = foldReducedState(current.reduced, fresh);
|
|
128
|
-
const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);
|
|
129
|
-
const eventsForSink = durable === void 0 ? [] : filterInterested(fresh, durable.interests);
|
|
130
|
-
if (durable !== void 0 && eventsForSink.length > 0) yield* Effect.gen(function* () {
|
|
131
|
-
const staged = [];
|
|
132
|
-
if ((yield* durable.process({
|
|
133
|
-
allEvents: fresh,
|
|
134
|
-
events: eventsForSink,
|
|
135
|
-
stateAfter: nextReduced,
|
|
136
|
-
reducerStates: nextReducerStates,
|
|
137
|
-
throughSeq
|
|
138
|
-
}, baseContext(staged, input.publishEphemeral, input.scope, checkpoint)).pipe(Effect.as(true), Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.failCause(cause) : Effect.logError("EDA durable sink violated its infallible contract", {
|
|
139
|
-
cause: Cause.pretty(cause),
|
|
140
|
-
sink: sink.name
|
|
141
|
-
}).pipe(Effect.as(false))))) && staged.length > 0) {
|
|
142
|
-
yield* annotateEdaSpan({ "eda.sink.staged_events": staged.length });
|
|
143
|
-
yield* input.appendDurableBatch(staged);
|
|
144
|
-
}
|
|
145
|
-
}).pipe(Effect.withSpan("agent.sink.drain", { attributes: {
|
|
146
|
-
"eda.sink.name": sink.name,
|
|
147
|
-
"eda.sink.cursor.before": current.cursor,
|
|
148
|
-
"eda.sink.events.read": fresh.length,
|
|
149
|
-
"eda.sink.events.interested": eventsForSink.length,
|
|
150
|
-
"eda.sink.cursor.after": throughSeq
|
|
151
|
-
} }));
|
|
152
|
-
yield* commitSinkCheckpoint(checkpointStore, sinkName, checkpointRef, throughSeq);
|
|
153
|
-
yield* Ref.set(state, {
|
|
154
|
-
cursor: throughSeq,
|
|
155
|
-
reduced: nextReduced,
|
|
156
|
-
reducerStates: nextReducerStates
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
const processDurableBatchWithKeepAlive = (events) => keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));
|
|
160
|
-
const drainDurablesThrough = (targetHead) => Effect.gen(function* () {
|
|
161
|
-
while (true) {
|
|
162
|
-
const current = yield* Ref.get(state);
|
|
163
|
-
if (current.cursor >= targetHead) return;
|
|
164
|
-
const allEvents = yield* readCursorBatchThrough(store, current.cursor, targetHead, sink.durable?.batchSize);
|
|
165
|
-
if (allEvents.length === 0) return;
|
|
166
|
-
yield* processDurableBatchWithKeepAlive(allEvents);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
const processLiveDurable = (event) => Effect.gen(function* () {
|
|
170
|
-
const current = yield* Ref.get(state);
|
|
171
|
-
if (event.position.seq <= current.cursor) return;
|
|
172
|
-
if (event.position.seq > current.cursor + 1) yield* drainDurablesThrough(SequenceNumber.make(event.position.seq - 1));
|
|
173
|
-
const afterCatchup = yield* Ref.get(state);
|
|
174
|
-
if (event.position.seq > afterCatchup.cursor + 1) {
|
|
175
|
-
yield* Effect.logWarning("EDA sink runner could not catch up before live durable", {
|
|
176
|
-
cursor: afterCatchup.cursor,
|
|
177
|
-
eventSeq: event.position.seq,
|
|
178
|
-
sink: sink.name
|
|
179
|
-
});
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);
|
|
183
|
-
});
|
|
184
|
-
const processLiveEphemeral = (event) => Effect.gen(function* () {
|
|
185
|
-
const before = yield* Ref.get(state);
|
|
186
|
-
if (event.position.seq < before.cursor) return;
|
|
187
|
-
if (event.position.seq > before.cursor) yield* drainDurablesThrough(event.position.seq);
|
|
188
|
-
const after = yield* Ref.get(state);
|
|
189
|
-
if (event.position.seq !== after.cursor) return;
|
|
190
|
-
if (sink.ephemeral === void 0 || !matchesInterest(event.event.type, sink.ephemeral.interests)) return;
|
|
191
|
-
yield* sink.ephemeral.process(event, baseContext([], input.publishEphemeral, input.scope, checkpoint)).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink ephemeral projection failed", {
|
|
192
|
-
cause: String(cause),
|
|
193
|
-
sink: sink.name
|
|
194
|
-
})));
|
|
195
|
-
});
|
|
196
|
-
const processLiveEvent = (event) => event.event.durability === "durable" ? processLiveDurable(event) : processLiveEphemeral(event);
|
|
197
|
-
yield* Effect.gen(function* () {
|
|
198
|
-
yield* drainDurablesThrough(input.initialHead);
|
|
199
|
-
return yield* Effect.forever(Effect.gen(function* () {
|
|
200
|
-
yield* processLiveEvent(yield* PubSub.take(live));
|
|
201
|
-
}));
|
|
202
|
-
}).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink runner failed", {
|
|
203
|
-
cause: Cause.pretty(cause),
|
|
204
|
-
sink: sink.name
|
|
205
|
-
}))).pipe(Effect.forkIn(input.scope));
|
|
206
|
-
});
|
|
207
|
-
return {
|
|
208
|
-
sinks,
|
|
209
|
-
startSinkRunners: Effect.fnUntraced(function* (input) {
|
|
210
|
-
if (yield* Ref.getAndSet(started, true)) return;
|
|
211
|
-
yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {
|
|
212
|
-
discard: true,
|
|
213
|
-
concurrency: "unbounded"
|
|
214
|
-
});
|
|
215
|
-
}),
|
|
216
|
-
notifyDurableHeadAdvanced: () => Effect.void,
|
|
217
|
-
publishEphemeralToSinks: () => Effect.void
|
|
218
|
-
};
|
|
219
|
-
});
|
|
220
|
-
const readDurablePrefixThrough = (store, throughSeq) => {
|
|
221
|
-
if (throughSeq <= SequenceNumber.make(0)) return Effect.succeed([]);
|
|
222
|
-
return store.eventsAfter(SequenceNumber.make(0)).pipe(Stream.takeWhile((event) => event.position.seq <= throughSeq), Stream.runCollect, Effect.map((events) => Array.from(events)));
|
|
223
|
-
};
|
|
224
|
-
const makeSinkCheckpoint = (store, sinkName, checkpointRef) => ({
|
|
225
|
-
get: (schema, initial) => SynchronizedRef.get(checkpointRef).pipe(Effect.flatMap((checkpoint) => {
|
|
226
|
-
const serialized = serializedSinkState(checkpoint.payload);
|
|
227
|
-
return serialized === void 0 ? Effect.succeed(initial) : decodeSinkState(schema, serialized.state);
|
|
228
|
-
})),
|
|
229
|
-
save: (schema, state) => encodeSinkState(schema, state).pipe(Effect.flatMap((encoded) => {
|
|
230
|
-
const payload = {
|
|
231
|
-
formatVersion: sinkCheckpointFormatVersion,
|
|
232
|
-
state: encoded,
|
|
233
|
-
updatedAtMs: Date.now()
|
|
234
|
-
};
|
|
235
|
-
return SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) => store.saveState(sinkName, payload).pipe(Effect.as([void 0, {
|
|
236
|
-
afterSeq: checkpoint.afterSeq,
|
|
237
|
-
payload
|
|
238
|
-
}])));
|
|
239
|
-
}))
|
|
240
|
-
});
|
|
241
|
-
const commitSinkCheckpoint = (store, sinkName, checkpointRef, afterSeq) => SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) => store.commit(sinkName, afterSeq, checkpoint.payload).pipe(Effect.as([void 0, {
|
|
242
|
-
afterSeq,
|
|
243
|
-
payload: checkpoint.payload
|
|
244
|
-
}])));
|
|
245
|
-
const serializedSinkState = (payload) => {
|
|
246
|
-
if (typeof payload !== "object" || payload === null || !("formatVersion" in payload) || payload.formatVersion !== sinkCheckpointFormatVersion || !("state" in payload) || !("updatedAtMs" in payload) || typeof payload.updatedAtMs !== "number") return;
|
|
247
|
-
return {
|
|
248
|
-
formatVersion: sinkCheckpointFormatVersion,
|
|
249
|
-
state: payload.state,
|
|
250
|
-
updatedAtMs: payload.updatedAtMs
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
const decodeSinkState = (schema, encoded) => Effect.try({
|
|
254
|
-
try: () => Schema.decodeUnknownSync(schema)(encoded),
|
|
255
|
-
catch: (cause) => sinkCheckpointCodecError("decoding", cause)
|
|
256
|
-
});
|
|
257
|
-
const encodeSinkState = (schema, state) => Effect.try({
|
|
258
|
-
try: () => Schema.encodeUnknownSync(schema)(state),
|
|
259
|
-
catch: (cause) => sinkCheckpointCodecError("encoding", cause)
|
|
260
|
-
});
|
|
261
|
-
const sinkCheckpointCodecError = (operation, cause) => new EDASessionStoreError({ message: cause instanceof Error ? `${operation} sink checkpoint: ${cause.message}` : `${operation} sink checkpoint: ${String(cause)}` });
|
|
262
|
-
const readCursorBatchThrough = (store, afterSeq, throughSeq, batchSize = defaultBatchSize) => store.eventsAfter(afterSeq).pipe(Stream.takeWhile((event) => event.position.seq <= throughSeq), Stream.take(batchSize), Stream.runCollect, Effect.map((events) => Array.from(events)));
|
|
263
|
-
const committedDurableFromPositioned = (event) => CommittedDurableEvent.make({
|
|
264
|
-
event: event.event,
|
|
265
|
-
position: durablePosition(event.position.seq)
|
|
266
|
-
});
|
|
267
|
-
const filterInterested = (events, interests) => events.filter((event) => matchesInterest(event.event.type, interests));
|
|
268
|
-
const matchesInterest = (type, interests) => interests === void 0 || interests.some((interest) => interest === type);
|
|
269
|
-
//#endregion
|
|
270
|
-
export { EDASinkRegistry as n, LiveEventBus as r, EDASink as t };
|
|
271
|
-
|
|
272
|
-
//# sourceMappingURL=sink-registry-NDgeyzO0.js.map
|