@entifix/transactions 0.10.2 → 0.11.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.
Files changed (48) hide show
  1. package/dist/contracts/command.d.ts +1 -0
  2. package/dist/contracts/command.d.ts.map +1 -1
  3. package/dist/contracts/command.js +7 -3
  4. package/dist/contracts/command.js.map +1 -1
  5. package/dist/contracts/event.d.ts +5 -4
  6. package/dist/contracts/event.d.ts.map +1 -1
  7. package/dist/contracts/event.js +14 -1
  8. package/dist/contracts/event.js.map +1 -1
  9. package/dist/contracts/flow-capability.d.ts +22 -0
  10. package/dist/contracts/flow-capability.d.ts.map +1 -0
  11. package/dist/contracts/flow-capability.js +26 -0
  12. package/dist/contracts/flow-capability.js.map +1 -0
  13. package/dist/contracts/flow-messages.d.ts +51 -0
  14. package/dist/contracts/flow-messages.d.ts.map +1 -0
  15. package/dist/contracts/flow-messages.js +65 -0
  16. package/dist/contracts/flow-messages.js.map +1 -0
  17. package/dist/contracts/inbox.d.ts +19 -2
  18. package/dist/contracts/inbox.d.ts.map +1 -1
  19. package/dist/contracts/inbox.js +16 -1
  20. package/dist/contracts/inbox.js.map +1 -1
  21. package/dist/contracts/messages.d.ts +37 -0
  22. package/dist/contracts/messages.d.ts.map +1 -0
  23. package/dist/contracts/messages.js +68 -0
  24. package/dist/contracts/messages.js.map +1 -0
  25. package/dist/contracts/outbox.d.ts +32 -12
  26. package/dist/contracts/outbox.d.ts.map +1 -1
  27. package/dist/contracts/outbox.js +2 -1
  28. package/dist/contracts/outbox.js.map +1 -1
  29. package/dist/contracts/record.d.ts +7 -8
  30. package/dist/contracts/record.d.ts.map +1 -1
  31. package/dist/contracts/record.js +8 -8
  32. package/dist/contracts/record.js.map +1 -1
  33. package/dist/contracts/unit-of-work.d.ts +3 -2
  34. package/dist/contracts/unit-of-work.d.ts.map +1 -1
  35. package/dist/contracts/unit-of-work.js.map +1 -1
  36. package/dist/engine/run-transaction.d.ts +4 -4
  37. package/dist/engine/run-transaction.d.ts.map +1 -1
  38. package/dist/engine/run-transaction.js +4 -4
  39. package/dist/engine/run-transaction.js.map +1 -1
  40. package/dist/index.d.ts +4 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +4 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/ports/flow-engine.d.ts +54 -0
  45. package/dist/ports/flow-engine.d.ts.map +1 -0
  46. package/dist/ports/flow-engine.js +19 -0
  47. package/dist/ports/flow-engine.js.map +1 -0
  48. package/package.json +3 -3
@@ -1,7 +1,20 @@
1
- import type { DomainEvent, StoreFailure } from '@entifix/core';
1
+ import type { AggregateRef, DomainEvent, StoreFailure } from '@entifix/core';
2
2
  import { Context, type Effect } from 'effect';
3
3
  /**
4
- * A transaction event recorded durably *before* it reaches the broker.
4
+ * An event an outbox accepts: one that says which aggregate it is about and
5
+ * which version of it ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)).
6
+ * The relay keeps order within an aggregate and nowhere else, and a consumer
7
+ * discards a version older than one it applied — neither is possible for an
8
+ * event that names neither.
9
+ */
10
+ export type OutboxEvent<TData = unknown> = DomainEvent<TData> & {
11
+ readonly aggregate: AggregateRef;
12
+ readonly version: number;
13
+ };
14
+ /** The key an outbox orders and blocks by: `<type>/<id>`. */
15
+ export declare const aggregateKey: (aggregate: AggregateRef) => string;
16
+ /**
17
+ * A domain event recorded durably *before* it reaches the broker.
5
18
  *
6
19
  * The point of the outbox is that a state change and the event announcing it
7
20
  * become one fact. `execute` used to write Mongo and then call `bus.publish`
@@ -21,14 +34,17 @@ export interface OutboxEntry {
21
34
  * recognised as a retry before any lock is taken or work forked.
22
35
  */
23
36
  eventId: string;
37
+ /** Denormalized out of `event` for the per-aggregate index. */
38
+ aggregate: AggregateRef;
39
+ version: number;
24
40
  event: DomainEvent;
25
41
  sent: boolean;
26
42
  /**
27
43
  * Publish attempts already spent on this entry.
28
44
  *
29
- * The relay drains in order and stops at the first failure, which is what
30
- * keeps `accepted` ahead of a terminal event — and is also why an entry that
31
- * can *never* publish used to block everything behind it forever. Counting
45
+ * A failure holds back the later versions of this entry's aggregate, which
46
+ * is what keeps `accepted` ahead of a terminal event — and is also why an
47
+ * entry that can *never* publish would hold its aggregate forever. Counting
32
48
  * the attempts is what turns "retrying" into a state with an end.
33
49
  */
34
50
  attempts: number;
@@ -43,11 +59,15 @@ export interface OutboxEntry {
43
59
  * stuck transaction nobody is told about is the same as a lost one.
44
60
  */
45
61
  quarantined: boolean;
46
- /** ISO-8601, and the drain order: entries publish oldest-first. */
62
+ /**
63
+ * ISO-8601. Entries are read oldest-first, and published in that order
64
+ * **within each aggregate**: a failing head holds back only its own
65
+ * aggregate's later versions.
66
+ */
47
67
  createdAt: string;
48
68
  }
49
69
  /**
50
- * Whether {@link TransactionOutbox.enqueue} actually wrote.
70
+ * Whether {@link Outbox.enqueue} actually wrote.
51
71
  *
52
72
  * `duplicate` is not a failure — it is how a *retry* is recognised. The
53
73
  * transaction id is the client's idempotency key, so a repeated
@@ -58,7 +78,7 @@ export interface OutboxEntry {
58
78
  */
59
79
  export type OutboxEnqueueResult = 'enqueued' | 'duplicate';
60
80
  /**
61
- * An aggregate view of one outbox, for {@link TransactionOutbox.stats}.
81
+ * An aggregate view of one outbox, for {@link Outbox.stats}.
62
82
  *
63
83
  * Counts and one timestamp — **no ids and no payloads**. That is what makes it
64
84
  * safe where a listing is not: an outbox holds event payloads, and once
@@ -94,9 +114,9 @@ export interface OutboxStats {
94
114
  * handle is opaque and whose `emit` records the event inside the same
95
115
  * transaction (ADR 0009). `enqueue` is for an event with no write to join.
96
116
  */
97
- export interface TransactionOutbox {
117
+ export interface Outbox {
98
118
  /** Record an event durably. Idempotent per `event.id`. */
99
- enqueue(event: DomainEvent): Effect.Effect<OutboxEnqueueResult, StoreFailure>;
119
+ enqueue(event: OutboxEvent): Effect.Effect<OutboxEnqueueResult, StoreFailure>;
100
120
  /**
101
121
  * Unsent, un-quarantined entries, oldest first — the relay's input.
102
122
  *
@@ -129,8 +149,8 @@ export interface TransactionOutbox {
129
149
  */
130
150
  stats(): Effect.Effect<OutboxStats, StoreFailure>;
131
151
  }
132
- declare const TransactionOutboxTag_base: Context.ServiceClass<TransactionOutboxTag, "TransactionOutboxTag", TransactionOutbox>;
133
- export declare class TransactionOutboxTag extends TransactionOutboxTag_base {
152
+ declare const OutboxTag_base: Context.ServiceClass<OutboxTag, "@entifix/transactions/Outbox", Outbox>;
153
+ export declare class OutboxTag extends OutboxTag_base {
134
154
  }
135
155
  export {};
136
156
  //# sourceMappingURL=outbox.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/contracts/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,WAAW,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GA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AAK,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;CACnD;;AAED,qBAAa,SAAU,SAAQ,cAE9B;CAAG"}
@@ -1,5 +1,6 @@
1
1
  import { Context } from 'effect';
2
- export class TransactionOutboxTag extends Context.Service()('TransactionOutboxTag') {
2
+ /** The key an outbox orders and blocks by: `<type>/<id>`. */ export const aggregateKey = (aggregate)=>`${aggregate.type}/${aggregate.id}`;
3
+ export class OutboxTag extends Context.Service()('@entifix/transactions/Outbox') {
3
4
  }
4
5
 
5
6
  //# sourceMappingURL=outbox.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/outbox.ts"],"sourcesContent":["import type { DomainEvent, StoreFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * A transaction event recorded durably *before* it reaches the broker.\n *\n * The point of the outbox is that a state change and the event announcing it\n * become one fact. `execute` used to write Mongo and then call `bus.publish`\n * separately: with the broker down between the two, the write happened and the\n * event never did, so the saga record sat `PENDING` until the sweep mislabelled\n * a successful transaction `STALE`. An entry written in the same transaction as\n * the state change cannot be lost that way, and a relay carries it to the bus\n * afterwards.\n */\nexport interface OutboxEntry {\n /**\n * The message's own id, denormalized out of `event` so the unique index sits\n * on a plain top-level field rather than a nested path.\n *\n * This **is** the idempotency claim: for a transaction step it is\n * `<transactionId>:<step>`, so a replayed command collides here and is\n * recognised as a retry before any lock is taken or work forked.\n */\n eventId: string;\n event: DomainEvent;\n sent: boolean;\n /**\n * Publish attempts already spent on this entry.\n *\n * The relay drains in order and stops at the first failure, which is what\n * keeps `accepted` ahead of a terminal event — and is also why an entry that\n * can *never* publish used to block everything behind it forever. Counting\n * the attempts is what turns \"retrying\" into a state with an end.\n */\n attempts: number;\n /**\n * Why the last attempt failed. Absent until one has, so its presence alone\n * says this entry has been tried.\n */\n lastError?: string;\n /**\n * Set once the attempts are spent. A quarantined entry is **skipped** rather\n * than retried, so the head of the line moves; nothing deletes it, because a\n * stuck transaction nobody is told about is the same as a lost one.\n */\n quarantined: boolean;\n /** ISO-8601, and the drain order: entries publish oldest-first. */\n createdAt: string;\n}\n\n/**\n * Whether {@link TransactionOutbox.enqueue} actually wrote.\n *\n * `duplicate` is not a failure — it is how a *retry* is recognised. The\n * transaction id is the client's idempotency key, so a repeated\n * command must return the first one's answer rather than execute twice. The\n * adapter owns the detection because the mechanism is storage-specific (a Mongo\n * `E11000` against the unique index on `eventId`), and translating it here keeps\n * driver error codes out of route handlers.\n */\nexport type OutboxEnqueueResult = 'enqueued' | 'duplicate';\n\n/**\n * An aggregate view of one outbox, for {@link TransactionOutbox.stats}.\n *\n * Counts and one timestamp — **no ids and no payloads**. That is what makes it\n * safe where a listing is not: an outbox holds event payloads, and once\n * `catalog.published` carries a whole offering an unfiltered read of one is a\n * tenant-data surface.\n */\nexport interface OutboxStats {\n /** Unsent, un-quarantined entries — the same set {@link pending} drains. */\n pending: number;\n /**\n * `createdAt` of the oldest such entry, absent when there are none.\n *\n * The age derived from this is the metric that makes a stuck relay visible.\n * An entry that can never publish no longer blocks the ones behind it —\n * quarantine gave the relay a ceiling — but a quarantine is reported only as a log line,\n * so *how far behind* the head has fallen is otherwise unanswerable.\n */\n oldestPendingAt?: string;\n /** Entries past the ceiling, which {@link pending} skips and nothing deletes. */\n quarantined: number;\n}\n\n/**\n * The durable hand-off between a transactional write and the event bus.\n *\n * Deliberately **not** a publisher: it never touches the broker. `enqueue` is\n * the only write, and the relay composes `pending`/`markSent` with an\n * {@link EventBus} — which is what keeps the engine framework-free and lets the\n * relay be tested without either a database or a broker.\n *\n * There is no `enqueueWithin(session)` here on purpose: a driver session in\n * this port would drag a datastore into a framework-free contract. A write that\n * must be atomic with its event runs in a {@link UnitOfWork} instead, whose\n * handle is opaque and whose `emit` records the event inside the same\n * transaction (ADR 0009). `enqueue` is for an event with no write to join.\n */\nexport interface TransactionOutbox {\n /** Record an event durably. Idempotent per `event.id`. */\n enqueue(event: DomainEvent): Effect.Effect<OutboxEnqueueResult, StoreFailure>;\n /**\n * Unsent, un-quarantined entries, oldest first — the relay's input.\n *\n * Excluding the quarantined ones here rather than in the relay is deliberate:\n * a skip the caller has to remember is a skip the next caller forgets.\n */\n pending(limit: number): Effect.Effect<readonly OutboxEntry[], StoreFailure>;\n /**\n * Mark an entry published. A crash between the publish and this call re-sends\n * the event on the next drain, which is why delivery is at-least-once and why\n * a consumer that must not fold twice dedupes on `event.id`.\n */\n markSent(entry: OutboxEntry): Effect.Effect<void, StoreFailure>;\n /**\n * Record a failed publish: increments `attempts` and stores `error`.\n *\n * `quarantine` is the caller's decision rather than the adapter's, because\n * the ceiling is configuration the relay reads and the store has no business\n * knowing it. Once set, {@link pending} must stop returning the entry — that\n * is the whole mechanism by which the queue's head moves.\n */\n recordFailure(\n entry: OutboxEntry,\n error: string,\n quarantine: boolean,\n ): Effect.Effect<void, StoreFailure>;\n /**\n * Depth and age, for the relay to sample once per sweep.\n *\n * An aggregate rather than a read, deliberately: `pending(limit)` truncates at\n * the relay's batch size, so counting what it returns answers \"is the batch\n * full\" and not \"how far behind are we\" — which are the same number right up\n * to the moment the second one starts to matter.\n */\n stats(): Effect.Effect<OutboxStats, StoreFailure>;\n}\n\nexport class TransactionOutboxTag extends Context.Service<\n TransactionOutboxTag,\n TransactionOutbox\n>()('TransactionOutboxTag') {}\n"],"names":["Context","TransactionOutboxTag","Service"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AA2I9C,OAAO,MAAMC,6BAA6BD,QAAQE,OAAO,GAGrD;AAAyB"}
1
+ {"version":3,"sources":["../../src/contracts/outbox.ts"],"sourcesContent":["import type { AggregateRef, DomainEvent, StoreFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * An event an outbox accepts: one that says which aggregate it is about and\n * which version of it ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)).\n * The relay keeps order within an aggregate and nowhere else, and a consumer\n * discards a version older than one it applied — neither is possible for an\n * event that names neither.\n */\nexport type OutboxEvent<TData = unknown> = DomainEvent<TData> & {\n readonly aggregate: AggregateRef;\n readonly version: number;\n};\n\n/** The key an outbox orders and blocks by: `<type>/<id>`. */\nexport const aggregateKey = (aggregate: AggregateRef): string =>\n `${aggregate.type}/${aggregate.id}`;\n\n/**\n * A domain event recorded durably *before* it reaches the broker.\n *\n * The point of the outbox is that a state change and the event announcing it\n * become one fact. `execute` used to write Mongo and then call `bus.publish`\n * separately: with the broker down between the two, the write happened and the\n * event never did, so the saga record sat `PENDING` until the sweep mislabelled\n * a successful transaction `STALE`. An entry written in the same transaction as\n * the state change cannot be lost that way, and a relay carries it to the bus\n * afterwards.\n */\nexport interface OutboxEntry {\n /**\n * The message's own id, denormalized out of `event` so the unique index sits\n * on a plain top-level field rather than a nested path.\n *\n * This **is** the idempotency claim: for a transaction step it is\n * `<transactionId>:<step>`, so a replayed command collides here and is\n * recognised as a retry before any lock is taken or work forked.\n */\n eventId: string;\n /** Denormalized out of `event` for the per-aggregate index. */\n aggregate: AggregateRef;\n version: number;\n event: DomainEvent;\n sent: boolean;\n /**\n * Publish attempts already spent on this entry.\n *\n * A failure holds back the later versions of this entry's aggregate, which\n * is what keeps `accepted` ahead of a terminal event — and is also why an\n * entry that can *never* publish would hold its aggregate forever. Counting\n * the attempts is what turns \"retrying\" into a state with an end.\n */\n attempts: number;\n /**\n * Why the last attempt failed. Absent until one has, so its presence alone\n * says this entry has been tried.\n */\n lastError?: string;\n /**\n * Set once the attempts are spent. A quarantined entry is **skipped** rather\n * than retried, so the head of the line moves; nothing deletes it, because a\n * stuck transaction nobody is told about is the same as a lost one.\n */\n quarantined: boolean;\n /**\n * ISO-8601. Entries are read oldest-first, and published in that order\n * **within each aggregate**: a failing head holds back only its own\n * aggregate's later versions.\n */\n createdAt: string;\n}\n\n/**\n * Whether {@link Outbox.enqueue} actually wrote.\n *\n * `duplicate` is not a failure — it is how a *retry* is recognised. The\n * transaction id is the client's idempotency key, so a repeated\n * command must return the first one's answer rather than execute twice. The\n * adapter owns the detection because the mechanism is storage-specific (a Mongo\n * `E11000` against the unique index on `eventId`), and translating it here keeps\n * driver error codes out of route handlers.\n */\nexport type OutboxEnqueueResult = 'enqueued' | 'duplicate';\n\n/**\n * An aggregate view of one outbox, for {@link Outbox.stats}.\n *\n * Counts and one timestamp — **no ids and no payloads**. That is what makes it\n * safe where a listing is not: an outbox holds event payloads, and once\n * `catalog.published` carries a whole offering an unfiltered read of one is a\n * tenant-data surface.\n */\nexport interface OutboxStats {\n /** Unsent, un-quarantined entries — the same set {@link pending} drains. */\n pending: number;\n /**\n * `createdAt` of the oldest such entry, absent when there are none.\n *\n * The age derived from this is the metric that makes a stuck relay visible.\n * An entry that can never publish no longer blocks the ones behind it —\n * quarantine gave the relay a ceiling — but a quarantine is reported only as a log line,\n * so *how far behind* the head has fallen is otherwise unanswerable.\n */\n oldestPendingAt?: string;\n /** Entries past the ceiling, which {@link pending} skips and nothing deletes. */\n quarantined: number;\n}\n\n/**\n * The durable hand-off between a transactional write and the event bus.\n *\n * Deliberately **not** a publisher: it never touches the broker. `enqueue` is\n * the only write, and the relay composes `pending`/`markSent` with an\n * {@link EventBus} — which is what keeps the engine framework-free and lets the\n * relay be tested without either a database or a broker.\n *\n * There is no `enqueueWithin(session)` here on purpose: a driver session in\n * this port would drag a datastore into a framework-free contract. A write that\n * must be atomic with its event runs in a {@link UnitOfWork} instead, whose\n * handle is opaque and whose `emit` records the event inside the same\n * transaction (ADR 0009). `enqueue` is for an event with no write to join.\n */\nexport interface Outbox {\n /** Record an event durably. Idempotent per `event.id`. */\n enqueue(event: OutboxEvent): Effect.Effect<OutboxEnqueueResult, StoreFailure>;\n /**\n * Unsent, un-quarantined entries, oldest first — the relay's input.\n *\n * Excluding the quarantined ones here rather than in the relay is deliberate:\n * a skip the caller has to remember is a skip the next caller forgets.\n */\n pending(limit: number): Effect.Effect<readonly OutboxEntry[], StoreFailure>;\n /**\n * Mark an entry published. A crash between the publish and this call re-sends\n * the event on the next drain, which is why delivery is at-least-once and why\n * a consumer that must not fold twice dedupes on `event.id`.\n */\n markSent(entry: OutboxEntry): Effect.Effect<void, StoreFailure>;\n /**\n * Record a failed publish: increments `attempts` and stores `error`.\n *\n * `quarantine` is the caller's decision rather than the adapter's, because\n * the ceiling is configuration the relay reads and the store has no business\n * knowing it. Once set, {@link pending} must stop returning the entry — that\n * is the whole mechanism by which the queue's head moves.\n */\n recordFailure(\n entry: OutboxEntry,\n error: string,\n quarantine: boolean,\n ): Effect.Effect<void, StoreFailure>;\n /**\n * Depth and age, for the relay to sample once per sweep.\n *\n * An aggregate rather than a read, deliberately: `pending(limit)` truncates at\n * the relay's batch size, so counting what it returns answers \"is the batch\n * full\" and not \"how far behind are we\" — which are the same number right up\n * to the moment the second one starts to matter.\n */\n stats(): Effect.Effect<OutboxStats, StoreFailure>;\n}\n\nexport class OutboxTag extends Context.Service<OutboxTag, Outbox>()(\n '@entifix/transactions/Outbox',\n) {}\n"],"names":["Context","aggregateKey","aggregate","type","id","OutboxTag","Service"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AAc9C,2DAA2D,GAC3D,OAAO,MAAMC,eAAe,CAACC,YAC3B,GAAGA,UAAUC,IAAI,CAAC,CAAC,EAAED,UAAUE,EAAE,EAAE,CAAC;AAkJtC,OAAO,MAAMC,kBAAkBL,QAAQM,OAAO,GAC5C;AACC"}
@@ -1,4 +1,5 @@
1
- import { type EntifixConnError, type EntityId, type InvalidEnvelope, type TransitionalFailure } from '@entifix/core';
1
+ import './messages.js';
2
+ import { type EntifixConnError, type EntityId, type ProtocolFailure, type TransitionalFailure } from '@entifix/core';
2
3
  import { Context, Effect } from 'effect';
3
4
  import type { TransactionEvent, TransactionState } from './event.js';
4
5
  /**
@@ -75,17 +76,15 @@ export interface TransactionAccepted {
75
76
  * Read for its **shape**, not its contents: it asserts the service really
76
77
  * accepted a transaction rather than answering something else with a `2xx`.
77
78
  */
78
- export declare function readTransactionAcceptedEnvelope(body: unknown): Effect.Effect<TransactionAccepted, InvalidEnvelope>;
79
+ export declare function readTransactionAcceptedEnvelope(body: unknown): Effect.Effect<TransactionAccepted, ProtocolFailure>;
79
80
  /**
80
81
  * Parses the tracker's by-id response, which frames a {@link TransactionRecord}.
81
82
  *
82
- * ⚠️ **`readEnvelope` validates the discriminant and then *casts* the payload**
83
- * — it checks no members. So a discriminant shared by two shapes hands back
84
- * whichever one the caller asked for, typed and wrong: a record read as an
85
- * event has no `step`, no `at`, and a `state` the caller is about to branch on.
86
- * That is the reason the four transaction-shaped discriminants are four.
83
+ * The body is decoded against `transactionRecord`'s registered schema, so a
84
+ * different message wearing the name — an event, which has a `step` and no
85
+ * `createdAt` — is refused rather than handed back typed and wrong.
87
86
  */
88
- export declare function readTransactionRecordEnvelope(body: unknown): Effect.Effect<TransactionRecord, InvalidEnvelope>;
87
+ export declare function readTransactionRecordEnvelope(body: unknown): Effect.Effect<TransactionRecord, ProtocolFailure>;
89
88
  /**
90
89
  * Reads one transaction's record, for a browser reconciling a write it started.
91
90
  *
@@ -1 +1 @@
1
- {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/contracts/record.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC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,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACxE;;;;;;;;;;;;;OAaG;IACH,YAAY,IAAI,MAAM,CAAC,MAAM,CAC3B,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,EAChC,gBAAgB,CACjB,CAAC;CACH;;AAED,qBAAa,mBAAoB,SAAQ,wBAGf;CAAG;AAE7B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAKrD;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAKnD;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,CACF,aAAa,EAAE,MAAM,GACpB,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,SAAS,EAAE,mBAAmB,CAAC,CAAC;CACtE;;AAED,qBAAa,0BAA2B,SAAQ,+BAGf;CAAG"}
@@ -1,4 +1,6 @@
1
- import { readEnvelope } from '@entifix/core';
1
+ // Evaluated for its registrations: this reader decodes against them.
2
+ import './messages.js';
3
+ import { decodeEnvelope } from '@entifix/core';
2
4
  import { Context, Effect } from 'effect';
3
5
  export class TransactionStoreTag extends Context.Service()('TransactionStoreTag') {
4
6
  }
@@ -8,18 +10,16 @@ export class TransactionStoreTag extends Context.Service()('TransactionStoreTag'
8
10
  * Read for its **shape**, not its contents: it asserts the service really
9
11
  * accepted a transaction rather than answering something else with a `2xx`.
10
12
  */ export function readTransactionAcceptedEnvelope(body) {
11
- return Effect.map(readEnvelope(body, 'transactionAccepted', 'transactionAccepted'), (envelope)=>envelope.data);
13
+ return Effect.map(decodeEnvelope(body, 'transactionAccepted'), (envelope)=>envelope.data);
12
14
  }
13
15
  /**
14
16
  * Parses the tracker's by-id response, which frames a {@link TransactionRecord}.
15
17
  *
16
- * ⚠️ **`readEnvelope` validates the discriminant and then *casts* the payload**
17
- * — it checks no members. So a discriminant shared by two shapes hands back
18
- * whichever one the caller asked for, typed and wrong: a record read as an
19
- * event has no `step`, no `at`, and a `state` the caller is about to branch on.
20
- * That is the reason the four transaction-shaped discriminants are four.
18
+ * The body is decoded against `transactionRecord`'s registered schema, so a
19
+ * different message wearing the name — an event, which has a `step` and no
20
+ * `createdAt` — is refused rather than handed back typed and wrong.
21
21
  */ export function readTransactionRecordEnvelope(body) {
22
- return Effect.map(readEnvelope(body, 'transactionRecord', 'transactionRecord'), (envelope)=>envelope.data);
22
+ return Effect.map(decodeEnvelope(body, 'transactionRecord'), (envelope)=>envelope.data);
23
23
  }
24
24
  export class TransactionStatusReaderTag extends Context.Service()('TransactionStatusReaderTag') {
25
25
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/record.ts"],"sourcesContent":["import {\n type EntifixConnError,\n type EntityId,\n type InvalidEnvelope,\n readEnvelope,\n type TransitionalFailure,\n} from '@entifix/core';\nimport { Context, Effect } from 'effect';\n\nimport type { TransactionEvent, TransactionState } from './event.js';\n\n/**\n * The the saga tracker's persisted view of a transaction, folded from the\n * events it observes. It is the source of truth a client polls.\n */\nexport interface TransactionRecord {\n transactionId: string;\n entity: string;\n state: TransactionState;\n code?: string;\n entityId?: EntityId;\n error?: string;\n createdAt: string;\n updatedAt: string;\n /**\n * Whose organization this transaction happened in, folded from the event.\n *\n * The `saga` store is control-plane and single-partition — it holds every\n * organization's records by design — so isolation on the read routes has to be\n * this filter. A record written before the member existed carries none and is\n * therefore readable by nobody, which is the direction to fail.\n */\n organizationId?: string;\n}\n\n/**\n * Port the manager tracks transactions through. Implemented over Mongo in the\n * service; framework-free here so the engine/manager stay environment-agnostic.\n */\nexport interface TransactionStore {\n /** Folds an event into the record, creating it on first sight. */\n upsertFromEvent(\n event: TransactionEvent,\n ): Effect.Effect<TransactionRecord, EntifixConnError>;\n get(\n transactionId: string,\n ): Effect.Effect<TransactionRecord | undefined, EntifixConnError>;\n // There is deliberately no `list`. The `saga` store is control-plane and\n // single-partition, so an unfiltered index is every organization's\n // transactions — which is why there is no `GET /api/transaction` list.\n // Anything that needs a set of records asks for one narrow enough to scope,\n // the way `findStale` does.\n /** Non-terminal records not updated within `olderThanMs` — recovery input. */\n findStale(\n olderThanMs: number,\n ): Effect.Effect<readonly TransactionRecord[], EntifixConnError>;\n markStale(transactionId: string): Effect.Effect<void, EntifixConnError>;\n /**\n * How many records sit in each state — the recovery sweep samples it.\n *\n * ⚠️ **This is a count, and is not the `list` above.** It returns no record,\n * no id and no organization, so it does not reopen the list surface removed\n * `GET /api/transaction` for: an unfiltered *listing* of this store is every\n * organization's transactions, while a total of how many are `STALE` is a\n * fleet health number that names nobody. The distinction is the whole reason\n * one is here and the other is refused.\n *\n * It exists so `STALE` is something a dashboard shows rather than something a\n * poll discovers — which is what the recovery sweep, whose only action is to\n * apply that label, otherwise leaves entirely unobservable.\n */\n countByState(): Effect.Effect<\n Record<TransactionState, number>,\n EntifixConnError\n >;\n}\n\nexport class TransactionStoreTag extends Context.Service<\n TransactionStoreTag,\n TransactionStore\n>()('TransactionStoreTag') {}\n\n/**\n * What a service answers a `202` with: the id to poll, and the state it starts\n * in.\n *\n * ⚠️ **Not a {@link TransactionRecord}, which is why it has its own\n * discriminant.** Nothing has been folded yet — there is no `createdAt`, no\n * entity id, and no code, because the write has not run. Framing it as a record\n * meant the browser's accept-shape assertion was checking a name that the\n * by-id route and the bus payload also answered to, so it asserted nothing it\n * claimed to.\n */\nexport interface TransactionAccepted {\n transactionId: string;\n state: TransactionState;\n}\n\n/**\n * Parses a `202` accept body, for a browser about to start polling.\n *\n * Read for its **shape**, not its contents: it asserts the service really\n * accepted a transaction rather than answering something else with a `2xx`.\n */\nexport function readTransactionAcceptedEnvelope(\n body: unknown,\n): Effect.Effect<TransactionAccepted, InvalidEnvelope> {\n return Effect.map(\n readEnvelope<TransactionAccepted>(\n body,\n 'transactionAccepted',\n 'transactionAccepted',\n ),\n envelope => envelope.data,\n );\n}\n\n/**\n * Parses the tracker's by-id response, which frames a {@link TransactionRecord}.\n *\n * ⚠️ **`readEnvelope` validates the discriminant and then *casts* the payload**\n * — it checks no members. So a discriminant shared by two shapes hands back\n * whichever one the caller asked for, typed and wrong: a record read as an\n * event has no `step`, no `at`, and a `state` the caller is about to branch on.\n * That is the reason the four transaction-shaped discriminants are four.\n */\nexport function readTransactionRecordEnvelope(\n body: unknown,\n): Effect.Effect<TransactionRecord, InvalidEnvelope> {\n return Effect.map(\n readEnvelope<TransactionRecord>(\n body,\n 'transactionRecord',\n 'transactionRecord',\n ),\n envelope => envelope.data,\n );\n}\n\n/**\n * Reads one transaction's record, for a browser reconciling a write it started.\n *\n * ⚠️ **`undefined` means _not tracked yet_, not _failed_.** `accepted` reaches\n * the tracker over the bus, so with the broker down the entity write commits —\n * the outbox is in the same Mongo transaction — while no event is ever\n * published and this answers `404`. That is a write in perfect health, and a\n * caller that rolls back on it un-renders a record that is about to appear, at\n * exactly the moment nobody can tell a UI bug from an outage. Only `FAILED` and\n * `STALE` are terminal.\n */\nexport interface TransactionStatusReader {\n read(\n transactionId: string,\n ): Effect.Effect<TransactionRecord | undefined, TransitionalFailure>;\n}\n\nexport class TransactionStatusReaderTag extends Context.Service<\n TransactionStatusReaderTag,\n TransactionStatusReader\n>()('TransactionStatusReaderTag') {}\n"],"names":["readEnvelope","Context","Effect","TransactionStoreTag","Service","readTransactionAcceptedEnvelope","body","map","envelope","data","readTransactionRecordEnvelope","TransactionStatusReaderTag"],"mappings":"AAAA,SAIEA,YAAY,QAEP,gBAAgB;AACvB,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AAsEzC,OAAO,MAAMC,4BAA4BF,QAAQG,OAAO,GAGpD;AAAwB;AAkB5B;;;;;CAKC,GACD,OAAO,SAASC,gCACdC,IAAa;IAEb,OAAOJ,OAAOK,GAAG,CACfP,aACEM,MACA,uBACA,wBAEFE,CAAAA,WAAYA,SAASC,IAAI;AAE7B;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASC,8BACdJ,IAAa;IAEb,OAAOJ,OAAOK,GAAG,CACfP,aACEM,MACA,qBACA,sBAEFE,CAAAA,WAAYA,SAASC,IAAI;AAE7B;AAmBA,OAAO,MAAME,mCAAmCV,QAAQG,OAAO,GAG3D;AAA+B"}
1
+ {"version":3,"sources":["../../src/contracts/record.ts"],"sourcesContent":["// Evaluated for its registrations: this reader decodes against them.\nimport './messages.js';\n\nimport {\n decodeEnvelope,\n type EntifixConnError,\n type EntityId,\n type ProtocolFailure,\n type TransitionalFailure,\n} from '@entifix/core';\nimport { Context, Effect } from 'effect';\n\nimport type { TransactionEvent, TransactionState } from './event.js';\n\n/**\n * The the saga tracker's persisted view of a transaction, folded from the\n * events it observes. It is the source of truth a client polls.\n */\nexport interface TransactionRecord {\n transactionId: string;\n entity: string;\n state: TransactionState;\n code?: string;\n entityId?: EntityId;\n error?: string;\n createdAt: string;\n updatedAt: string;\n /**\n * Whose organization this transaction happened in, folded from the event.\n *\n * The `saga` store is control-plane and single-partition — it holds every\n * organization's records by design — so isolation on the read routes has to be\n * this filter. A record written before the member existed carries none and is\n * therefore readable by nobody, which is the direction to fail.\n */\n organizationId?: string;\n}\n\n/**\n * Port the manager tracks transactions through. Implemented over Mongo in the\n * service; framework-free here so the engine/manager stay environment-agnostic.\n */\nexport interface TransactionStore {\n /** Folds an event into the record, creating it on first sight. */\n upsertFromEvent(\n event: TransactionEvent,\n ): Effect.Effect<TransactionRecord, EntifixConnError>;\n get(\n transactionId: string,\n ): Effect.Effect<TransactionRecord | undefined, EntifixConnError>;\n // There is deliberately no `list`. The `saga` store is control-plane and\n // single-partition, so an unfiltered index is every organization's\n // transactions — which is why there is no `GET /api/transaction` list.\n // Anything that needs a set of records asks for one narrow enough to scope,\n // the way `findStale` does.\n /** Non-terminal records not updated within `olderThanMs` — recovery input. */\n findStale(\n olderThanMs: number,\n ): Effect.Effect<readonly TransactionRecord[], EntifixConnError>;\n markStale(transactionId: string): Effect.Effect<void, EntifixConnError>;\n /**\n * How many records sit in each state — the recovery sweep samples it.\n *\n * ⚠️ **This is a count, and is not the `list` above.** It returns no record,\n * no id and no organization, so it does not reopen the list surface removed\n * `GET /api/transaction` for: an unfiltered *listing* of this store is every\n * organization's transactions, while a total of how many are `STALE` is a\n * fleet health number that names nobody. The distinction is the whole reason\n * one is here and the other is refused.\n *\n * It exists so `STALE` is something a dashboard shows rather than something a\n * poll discovers — which is what the recovery sweep, whose only action is to\n * apply that label, otherwise leaves entirely unobservable.\n */\n countByState(): Effect.Effect<\n Record<TransactionState, number>,\n EntifixConnError\n >;\n}\n\nexport class TransactionStoreTag extends Context.Service<\n TransactionStoreTag,\n TransactionStore\n>()('TransactionStoreTag') {}\n\n/**\n * What a service answers a `202` with: the id to poll, and the state it starts\n * in.\n *\n * ⚠️ **Not a {@link TransactionRecord}, which is why it has its own\n * discriminant.** Nothing has been folded yet — there is no `createdAt`, no\n * entity id, and no code, because the write has not run. Framing it as a record\n * meant the browser's accept-shape assertion was checking a name that the\n * by-id route and the bus payload also answered to, so it asserted nothing it\n * claimed to.\n */\nexport interface TransactionAccepted {\n transactionId: string;\n state: TransactionState;\n}\n\n/**\n * Parses a `202` accept body, for a browser about to start polling.\n *\n * Read for its **shape**, not its contents: it asserts the service really\n * accepted a transaction rather than answering something else with a `2xx`.\n */\nexport function readTransactionAcceptedEnvelope(\n body: unknown,\n): Effect.Effect<TransactionAccepted, ProtocolFailure> {\n return Effect.map(\n decodeEnvelope(body, 'transactionAccepted'),\n envelope => envelope.data as TransactionAccepted,\n );\n}\n\n/**\n * Parses the tracker's by-id response, which frames a {@link TransactionRecord}.\n *\n * The body is decoded against `transactionRecord`'s registered schema, so a\n * different message wearing the name — an event, which has a `step` and no\n * `createdAt` — is refused rather than handed back typed and wrong.\n */\nexport function readTransactionRecordEnvelope(\n body: unknown,\n): Effect.Effect<TransactionRecord, ProtocolFailure> {\n return Effect.map(\n decodeEnvelope(body, 'transactionRecord'),\n envelope => envelope.data as TransactionRecord,\n );\n}\n\n/**\n * Reads one transaction's record, for a browser reconciling a write it started.\n *\n * ⚠️ **`undefined` means _not tracked yet_, not _failed_.** `accepted` reaches\n * the tracker over the bus, so with the broker down the entity write commits —\n * the outbox is in the same Mongo transaction — while no event is ever\n * published and this answers `404`. That is a write in perfect health, and a\n * caller that rolls back on it un-renders a record that is about to appear, at\n * exactly the moment nobody can tell a UI bug from an outage. Only `FAILED` and\n * `STALE` are terminal.\n */\nexport interface TransactionStatusReader {\n read(\n transactionId: string,\n ): Effect.Effect<TransactionRecord | undefined, TransitionalFailure>;\n}\n\nexport class TransactionStatusReaderTag extends Context.Service<\n TransactionStatusReaderTag,\n TransactionStatusReader\n>()('TransactionStatusReaderTag') {}\n"],"names":["decodeEnvelope","Context","Effect","TransactionStoreTag","Service","readTransactionAcceptedEnvelope","body","map","envelope","data","readTransactionRecordEnvelope","TransactionStatusReaderTag"],"mappings":"AAAA,qEAAqE;AACrE,OAAO,gBAAgB;AAEvB,SACEA,cAAc,QAKT,gBAAgB;AACvB,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AAsEzC,OAAO,MAAMC,4BAA4BF,QAAQG,OAAO,GAGpD;AAAwB;AAkB5B;;;;;CAKC,GACD,OAAO,SAASC,gCACdC,IAAa;IAEb,OAAOJ,OAAOK,GAAG,CACfP,eAAeM,MAAM,wBACrBE,CAAAA,WAAYA,SAASC,IAAI;AAE7B;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,8BACdJ,IAAa;IAEb,OAAOJ,OAAOK,GAAG,CACfP,eAAeM,MAAM,sBACrBE,CAAAA,WAAYA,SAASC,IAAI;AAE7B;AAmBA,OAAO,MAAME,mCAAmCV,QAAQG,OAAO,GAG3D;AAA+B"}
@@ -1,5 +1,6 @@
1
- import type { DomainEvent, StoreFault } from '@entifix/core';
1
+ import type { StoreFault } from '@entifix/core';
2
2
  import type { Effect, Option } from 'effect';
3
+ import type { OutboxEvent } from './outbox.js';
3
4
  /**
4
5
  * What a unit of work deduplicates on, if anything. At most one per unit.
5
6
  *
@@ -38,7 +39,7 @@ export interface Unit<H> {
38
39
  * same transaction, so the state change and its announcement are one fact,
39
40
  * and the relay carries it to the bus afterwards.
40
41
  */
41
- emit(event: DomainEvent): void;
42
+ emit(event: OutboxEvent): void;
42
43
  }
43
44
  /**
44
45
  * How a unit ended. A failure of the store itself is not one of these — it is
@@ -1 +1 @@
1
- {"version":3,"file":"unit-of-work.d.ts","sourceRoot":"","sources":["../../src/contracts/unit-of-work.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,SAAS,GACjB;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IACxB;IAAE,QAAQ,CAA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SAAS,CAAC;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IACxC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;CACxD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACT,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC/C,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAC7B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IACxE;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;CAC9E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/unit-of-work.ts"],"sourcesContent":["import type { DomainEvent, StoreFault } from '@entifix/core';\nimport type { Effect, Option } from 'effect';\n\n/**\n * What a unit of work deduplicates on, if anything. At most one per unit.\n *\n * Two kinds, because there are two directions a duplicate arrives from:\n *\n * - `event` — a consumer folding a bus message. Keyed on `(consumer, eventId)`,\n * the inbox's compound key: two consumers legitimately process one event,\n * and a key on `eventId` alone would let whichever claimed first starve the\n * other.\n * - `command` — a participant answering a dispatched command. Keyed on the\n * command id alone, and it **remembers an answer**: a redelivered command must\n * be told what the first delivery decided, not that it was a duplicate.\n */\nexport type UnitClaim =\n | {\n readonly kind: 'event';\n readonly consumer: string;\n readonly eventId: string;\n }\n | { readonly kind: 'command'; readonly commandId: string };\n\n/**\n * The view a unit's body gets of the transaction it runs in.\n *\n * `handle` is the store's own — a driver session and the database it is bound\n * to, for Mongo. It is opaque to this package on purpose: the contract states\n * what commits together, and only the adapter that implements it (and the\n * persistence code written against that adapter) ever looks inside.\n */\nexport interface Unit<H> {\n readonly handle: H;\n /**\n * Record an event to publish **if and only if** the unit commits.\n *\n * Recorded, not published. The adapter writes it to the outbox inside the\n * same transaction, so the state change and its announcement are one fact,\n * and the relay carries it to the bus afterwards.\n */\n emit(event: DomainEvent): void;\n}\n\n/**\n * How a unit ended. A failure of the store itself is not one of these — it is\n * the `StoreFault` in the error channel of {@link UnitOfWork.run}.\n *\n * - `committed` — every write, every event and the claim are durable.\n * - `duplicate` — the claim was already taken, so the body's work had already\n * committed once. Nothing was written. `replay` is what the first run asked\n * to be remembered (`command` claims only).\n * - `aborted` — the body failed with a business reason. Nothing was written.\n * This is how a refusal leaves a unit: as a typed value, never as a thrown\n * sentinel caught three frames up.\n */\nexport type UnitOutcome<A, E> =\n | { readonly _tag: 'committed'; readonly value: A }\n | { readonly _tag: 'duplicate'; readonly replay: Option.Option<unknown> }\n | { readonly _tag: 'aborted'; readonly reason: E };\n\nexport interface UnitRunOptions<A, R = never> {\n readonly claim?: UnitClaim;\n /**\n * What a later duplicate of this `command` claim is answered with, derived\n * from the committed value. Stored with the claim, in the same transaction.\n *\n * It must be JSON: it is written to the store and read back by a different\n * process, possibly after a restart.\n */\n readonly replay?: (value: A) => unknown;\n /**\n * Runs once the unit has committed, and never otherwise — the place to drain\n * the outbox inline so the event leaves now rather than at the next sweep.\n *\n * Its failure does not undo the commit, and is not reported as the unit's: a\n * drain that fails here is retried by the sweep, which is exactly the\n * fallback the outbox exists to provide.\n */\n readonly afterCommit?: Effect.Effect<void, unknown, R>;\n}\n\n/**\n * One storage transaction that the outbox, the inbox and a command claim all\n * join: domain writes, zero or more events, and at most one claim, which commit\n * or vanish together.\n *\n * The body may run **more than once**. A store that retries a transient\n * conflict re-runs it from the start, so the body must be a pure function of\n * its inputs and the handle — no clock read that has to match a value already\n * returned, no call to another service, no counter drawn from outside the\n * store. Do those before the unit and pass the results in.\n *\n * The body's typed failure is the abort: `run` rolls back and answers\n * `aborted` with it. A `StoreFault` is the exception — the store failing\n * is not a business decision, so it rolls back and surfaces in `run`'s own\n * error channel instead.\n *\n * Reads through the handle see the unit's own uncommitted writes.\n */\nexport interface UnitOfWork<H> {\n run<A, E, R>(\n body: (unit: Unit<H>) => Effect.Effect<A, E, R>,\n options?: UnitRunOptions<A, R>,\n ): Effect.Effect<UnitOutcome<A, Exclude<E, StoreFault>>, StoreFault, R>;\n /**\n * What the run that took this `command` claim asked to be remembered, or\n * `none` if no run has taken it — for a caller that has to answer a duplicate\n * outside a unit.\n */\n replay(commandId: string): Effect.Effect<Option.Option<unknown>, StoreFault>;\n}\n"],"names":[],"mappings":"AAkFA;;;;;;;;;;;;;;;;;CAiBC,GACD,WAWC"}
1
+ {"version":3,"sources":["../../src/contracts/unit-of-work.ts"],"sourcesContent":["import type { StoreFault } from '@entifix/core';\nimport type { Effect, Option } from 'effect';\n\nimport type { OutboxEvent } from './outbox.js';\n\n/**\n * What a unit of work deduplicates on, if anything. At most one per unit.\n *\n * Two kinds, because there are two directions a duplicate arrives from:\n *\n * - `event` — a consumer folding a bus message. Keyed on `(consumer, eventId)`,\n * the inbox's compound key: two consumers legitimately process one event,\n * and a key on `eventId` alone would let whichever claimed first starve the\n * other.\n * - `command` — a participant answering a dispatched command. Keyed on the\n * command id alone, and it **remembers an answer**: a redelivered command must\n * be told what the first delivery decided, not that it was a duplicate.\n */\nexport type UnitClaim =\n | {\n readonly kind: 'event';\n readonly consumer: string;\n readonly eventId: string;\n }\n | { readonly kind: 'command'; readonly commandId: string };\n\n/**\n * The view a unit's body gets of the transaction it runs in.\n *\n * `handle` is the store's own — a driver session and the database it is bound\n * to, for Mongo. It is opaque to this package on purpose: the contract states\n * what commits together, and only the adapter that implements it (and the\n * persistence code written against that adapter) ever looks inside.\n */\nexport interface Unit<H> {\n readonly handle: H;\n /**\n * Record an event to publish **if and only if** the unit commits.\n *\n * Recorded, not published. The adapter writes it to the outbox inside the\n * same transaction, so the state change and its announcement are one fact,\n * and the relay carries it to the bus afterwards.\n */\n emit(event: OutboxEvent): void;\n}\n\n/**\n * How a unit ended. A failure of the store itself is not one of these — it is\n * the `StoreFault` in the error channel of {@link UnitOfWork.run}.\n *\n * - `committed` — every write, every event and the claim are durable.\n * - `duplicate` — the claim was already taken, so the body's work had already\n * committed once. Nothing was written. `replay` is what the first run asked\n * to be remembered (`command` claims only).\n * - `aborted` — the body failed with a business reason. Nothing was written.\n * This is how a refusal leaves a unit: as a typed value, never as a thrown\n * sentinel caught three frames up.\n */\nexport type UnitOutcome<A, E> =\n | { readonly _tag: 'committed'; readonly value: A }\n | { readonly _tag: 'duplicate'; readonly replay: Option.Option<unknown> }\n | { readonly _tag: 'aborted'; readonly reason: E };\n\nexport interface UnitRunOptions<A, R = never> {\n readonly claim?: UnitClaim;\n /**\n * What a later duplicate of this `command` claim is answered with, derived\n * from the committed value. Stored with the claim, in the same transaction.\n *\n * It must be JSON: it is written to the store and read back by a different\n * process, possibly after a restart.\n */\n readonly replay?: (value: A) => unknown;\n /**\n * Runs once the unit has committed, and never otherwise — the place to drain\n * the outbox inline so the event leaves now rather than at the next sweep.\n *\n * Its failure does not undo the commit, and is not reported as the unit's: a\n * drain that fails here is retried by the sweep, which is exactly the\n * fallback the outbox exists to provide.\n */\n readonly afterCommit?: Effect.Effect<void, unknown, R>;\n}\n\n/**\n * One storage transaction that the outbox, the inbox and a command claim all\n * join: domain writes, zero or more events, and at most one claim, which commit\n * or vanish together.\n *\n * The body may run **more than once**. A store that retries a transient\n * conflict re-runs it from the start, so the body must be a pure function of\n * its inputs and the handle — no clock read that has to match a value already\n * returned, no call to another service, no counter drawn from outside the\n * store. Do those before the unit and pass the results in.\n *\n * The body's typed failure is the abort: `run` rolls back and answers\n * `aborted` with it. A `StoreFault` is the exception — the store failing\n * is not a business decision, so it rolls back and surfaces in `run`'s own\n * error channel instead.\n *\n * Reads through the handle see the unit's own uncommitted writes.\n */\nexport interface UnitOfWork<H> {\n run<A, E, R>(\n body: (unit: Unit<H>) => Effect.Effect<A, E, R>,\n options?: UnitRunOptions<A, R>,\n ): Effect.Effect<UnitOutcome<A, Exclude<E, StoreFault>>, StoreFault, R>;\n /**\n * What the run that took this `command` claim asked to be remembered, or\n * `none` if no run has taken it — for a caller that has to answer a duplicate\n * outside a unit.\n */\n replay(commandId: string): Effect.Effect<Option.Option<unknown>, StoreFault>;\n}\n"],"names":[],"mappings":"AAoFA;;;;;;;;;;;;;;;;;CAiBC,GACD,WAWC"}
@@ -1,5 +1,5 @@
1
1
  import { Effect } from 'effect';
2
- import { TransactionOutboxTag } from '../contracts/outbox.js';
2
+ import { OutboxTag } from '../contracts/outbox.js';
3
3
  import { CommandTag } from '../mixins/transaction-mixins.js';
4
4
  import { EventSourceTag } from '../ports/event-source.js';
5
5
  import type { LockHandle } from '../ports/lock-service.js';
@@ -14,7 +14,7 @@ import type { LockHandle } from '../ports/lock-service.js';
14
14
  * locks never leak on a rollback path.
15
15
  *
16
16
  * **The engine never publishes.** Every event it produces goes to the
17
- * {@link TransactionOutbox}, and a relay carries the outbox to the broker. That
17
+ * {@link Outbox}, and a relay carries the outbox to the broker. That
18
18
  * is the whole fix for the dual write: an event that only ever existed in a
19
19
  * `bus.publish` call between two Mongo writes is lost when the broker is down,
20
20
  * and the transaction is then mislabelled `STALE` despite having succeeded.
@@ -35,7 +35,7 @@ export declare function acceptTransaction(): Effect.Effect<{
35
35
  } | {
36
36
  readonly status: "accepted";
37
37
  readonly handles: readonly LockHandle[];
38
- }, import("@entifix/core").EntifixError | import("@entifix/core").StoreFailure, import("../index.js").TransactionHandlerTag | TransactionOutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
38
+ }, import("@entifix/core").EntifixError | import("@entifix/core").StoreFailure, import("../index.js").TransactionHandlerTag | OutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
39
39
  /** What {@link acceptTransaction} decided — a fresh command, or a replay. */
40
40
  export type AcceptOutcome = Effect.Success<ReturnType<typeof acceptTransaction>>;
41
41
  /**
@@ -51,5 +51,5 @@ export type AcceptOutcome = Effect.Success<ReturnType<typeof acceptTransaction>>
51
51
  * The failure arm does record, because there is no state change left to be
52
52
  * atomic with: the rollback has already undone it.
53
53
  */
54
- export declare function completeTransaction(handles: readonly LockHandle[]): Effect.Effect<void, never, import("../index.js").TransactionHandlerTag | TransactionOutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
54
+ export declare function completeTransaction(handles: readonly LockHandle[]): Effect.Effect<void, never, import("../index.js").TransactionHandlerTag | OutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
55
55
  //# sourceMappingURL=run-transaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-transaction.d.ts","sourceRoot":"","sources":["../../src/engine/run-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,UAAU,EAGX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAS3D;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;;;;;;yNAgBhC;AAED,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CACxC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CACrC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,uKA2DjE"}
1
+ {"version":3,"file":"run-transaction.d.ts","sourceRoot":"","sources":["../../src/engine/run-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,UAAU,EAGX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAS3D;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;;;;;;8MAgBhC;AAED,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CACxC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CACrC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,4JA2DjE"}
@@ -1,6 +1,6 @@
1
1
  import { Effect } from 'effect';
2
2
  import { acceptedEvent, failedEvent } from '../contracts/event.js';
3
- import { TransactionOutboxTag } from '../contracts/outbox.js';
3
+ import { OutboxTag } from '../contracts/outbox.js';
4
4
  import { CommandTag, LockHandlesTag, OutcomeTag } from '../mixins/transaction-mixins.js';
5
5
  import { EventSourceTag } from '../ports/event-source.js';
6
6
  import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, validateUCFactory } from '../use-case/facade.uc.js';
@@ -15,7 +15,7 @@ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, vali
15
15
  * locks never leak on a rollback path.
16
16
  *
17
17
  * **The engine never publishes.** Every event it produces goes to the
18
- * {@link TransactionOutbox}, and a relay carries the outbox to the broker. That
18
+ * {@link Outbox}, and a relay carries the outbox to the broker. That
19
19
  * is the whole fix for the dual write: an event that only ever existed in a
20
20
  * `bus.publish` call between two Mongo writes is lost when the broker is down,
21
21
  * and the transaction is then mislabelled `STALE` despite having succeeded.
@@ -31,7 +31,7 @@ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, vali
31
31
  */ export function acceptTransaction() {
32
32
  return Effect.gen(function*() {
33
33
  const command = yield* CommandTag;
34
- const outbox = yield* TransactionOutboxTag;
34
+ const outbox = yield* OutboxTag;
35
35
  const source = yield* EventSourceTag;
36
36
  yield* validateUCFactory();
37
37
  const claim = yield* outbox.enqueue(acceptedEvent(command, source));
@@ -62,7 +62,7 @@ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, vali
62
62
  */ export function completeTransaction(handles) {
63
63
  return Effect.gen(function*() {
64
64
  const command = yield* CommandTag;
65
- const outbox = yield* TransactionOutboxTag;
65
+ const outbox = yield* OutboxTag;
66
66
  const source = yield* EventSourceTag;
67
67
  const free = freeUCFactory().pipe(Effect.provideService(LockHandlesTag, handles), Effect.ignore);
68
68
  yield* executeUCFactory().pipe(Effect.matchEffect({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/engine/run-transaction.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { acceptedEvent, failedEvent } from '../contracts/event.js';\nimport { TransactionOutboxTag } from '../contracts/outbox.js';\nimport {\n CommandTag,\n LockHandlesTag,\n OutcomeTag,\n} from '../mixins/transaction-mixins.js';\nimport { EventSourceTag } from '../ports/event-source.js';\nimport type { LockHandle } from '../ports/lock-service.js';\nimport {\n executeUCFactory,\n freeUCFactory,\n lockUCFactory,\n rollbackUCFactory,\n validateUCFactory,\n} from '../use-case/facade.uc.js';\n\n/**\n * The saga engine, split at the 202 boundary so validation/lock failures are\n * synchronous (mapped to `400`/`409`) while the write runs asynchronously:\n *\n * - {@link acceptTransaction} — validate -> claim -> lock. Runs before the\n * service answers `202`; its failures are the client's answer.\n * - {@link completeTransaction} — execute -> free, or rollback -> record\n * `failed` -> free. Forked after `202`; `free` always runs via `ensuring`, so\n * locks never leak on a rollback path.\n *\n * **The engine never publishes.** Every event it produces goes to the\n * {@link TransactionOutbox}, and a relay carries the outbox to the broker. That\n * is the whole fix for the dual write: an event that only ever existed in a\n * `bus.publish` call between two Mongo writes is lost when the broker is down,\n * and the transaction is then mislabelled `STALE` despite having succeeded.\n */\n\n/**\n * Accept phase (synchronous).\n *\n * The order is deliberate: validate, then **claim, then lock**. The claim is the\n * outbox insert for the `accepted` event, and its uniqueness on\n * the message id (`<transactionId>:<step>`) is what makes the client-generated\n * id an idempotency key — a replayed command is recognised here, before a lock is taken and\n * before any work is forked. Locking first would make a retry queue behind its\n * own original.\n */\nexport function acceptTransaction() {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* TransactionOutboxTag;\n const source = yield* EventSourceTag;\n\n yield* validateUCFactory();\n\n const claim = yield* outbox.enqueue(acceptedEvent(command, source));\n if (claim === 'duplicate') {\n return { status: 'duplicate' } as const;\n }\n\n const handles = yield* lockUCFactory();\n return { status: 'accepted', handles } as const;\n });\n}\n\n/** What {@link acceptTransaction} decided — a fresh command, or a replay. */\nexport type AcceptOutcome = Effect.Success<\n ReturnType<typeof acceptTransaction>\n>;\n\n/**\n * Execute phase (asynchronous continuation). Never leaks locks.\n *\n * The success arm records **nothing**: `execute` is contractually required to\n * have written the `completed` entry in the same storage transaction as its\n * state change, because only the handler holds the session that can make those\n * two writes one. Recording it here as well would reintroduce the dual write in\n * the opposite direction — an event announcing a write that may have rolled\n * back.\n *\n * The failure arm does record, because there is no state change left to be\n * atomic with: the rollback has already undone it.\n */\nexport function completeTransaction(handles: readonly LockHandle[]) {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* TransactionOutboxTag;\n const source = yield* EventSourceTag;\n\n const free = freeUCFactory().pipe(\n Effect.provideService(LockHandlesTag, handles),\n Effect.ignore,\n );\n\n yield* executeUCFactory().pipe(\n Effect.matchEffect({\n onSuccess: () => Effect.void,\n onFailure: error =>\n rollbackUCFactory().pipe(\n Effect.provideService(OutcomeTag, undefined),\n // The compensation's own failure is reported before it is\n // discarded. Discarding it is right — the client is polling for a\n // terminal state and must still get one, so the `failed` record\n // below is written either way — but until this line the error\n // reached nothing: not the record, whose `error` is `execute`'s,\n // and not the log. An operator reading `FAILED` then reasonably\n // concluded the write had been undone when it had not.\n //\n // Annotations rather than message arguments, matching the outbox\n // relay: they reach a sink as structured fields, so a stranded\n // transaction is queryable by its id instead of being parsed out of\n // a rendered string.\n //\n // That is true as of this change and was not before it. A service's\n // Effect→tooling logger bridge (`observability.ts`) dropped\n // `annotations` outright and matched Effect's level labels with the\n // wrong casing, so every annotated field was discarded and every\n // level arrived as INFO — measured in Loki while verifying this log.\n Effect.tapError(rollbackError =>\n Effect.logError('transaction rollback failed').pipe(\n Effect.annotateLogs({\n transactionId: command.transactionId,\n entity: command.entity,\n executeError: String(error),\n rollbackError: String(rollbackError),\n }),\n ),\n ),\n Effect.ignore,\n Effect.andThen(\n // Best-effort: the transaction already failed, and a store that\n // cannot take the failure record must not turn into an unhandled\n // defect in a forked daemon. The recovery sweep is what notices.\n Effect.ignore(\n outbox.enqueue(failedEvent(command, error, source)),\n ),\n ),\n ),\n }),\n Effect.ensuring(free),\n );\n });\n}\n"],"names":["Effect","acceptedEvent","failedEvent","TransactionOutboxTag","CommandTag","LockHandlesTag","OutcomeTag","EventSourceTag","executeUCFactory","freeUCFactory","lockUCFactory","rollbackUCFactory","validateUCFactory","acceptTransaction","gen","command","outbox","source","claim","enqueue","status","handles","completeTransaction","free","pipe","provideService","ignore","matchEffect","onSuccess","void","onFailure","error","undefined","tapError","rollbackError","logError","annotateLogs","transactionId","entity","executeError","String","andThen","ensuring"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,EAAEC,WAAW,QAAQ,wBAAwB;AACnE,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SACEC,UAAU,EACVC,cAAc,EACdC,UAAU,QACL,kCAAkC;AACzC,S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E;gBACjE,qEAAqE;gBACrEhC,OAAOiC,QAAQ,CAACC,CAAAA,gBACdlC,OAAOmC,QAAQ,CAAC,+BAA+BX,IAAI,CACjDxB,OAAOoC,YAAY,CAAC;wBAClBC,eAAetB,QAAQsB,aAAa;wBACpCC,QAAQvB,QAAQuB,MAAM;wBACtBC,cAAcC,OAAOT;wBACrBG,eAAeM,OAAON;oBACxB,MAGJlC,OAAO0B,MAAM,EACb1B,OAAOyC,OAAO,CACZ,gEAAgE;gBAChE,iEAAiE;gBACjE,iEAAiE;gBACjEzC,OAAO0B,MAAM,CACXV,OAAOG,OAAO,CAACjB,YAAYa,SAASgB,OAAOd;QAIrD,IACAjB,OAAO0C,QAAQ,CAACnB;IAEpB;AACF"}
1
+ {"version":3,"sources":["../../src/engine/run-transaction.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { acceptedEvent, failedEvent } from '../contracts/event.js';\nimport { OutboxTag } from '../contracts/outbox.js';\nimport {\n CommandTag,\n LockHandlesTag,\n OutcomeTag,\n} from '../mixins/transaction-mixins.js';\nimport { EventSourceTag } from '../ports/event-source.js';\nimport type { LockHandle } from '../ports/lock-service.js';\nimport {\n executeUCFactory,\n freeUCFactory,\n lockUCFactory,\n rollbackUCFactory,\n validateUCFactory,\n} from '../use-case/facade.uc.js';\n\n/**\n * The saga engine, split at the 202 boundary so validation/lock failures are\n * synchronous (mapped to `400`/`409`) while the write runs asynchronously:\n *\n * - {@link acceptTransaction} — validate -> claim -> lock. Runs before the\n * service answers `202`; its failures are the client's answer.\n * - {@link completeTransaction} — execute -> free, or rollback -> record\n * `failed` -> free. Forked after `202`; `free` always runs via `ensuring`, so\n * locks never leak on a rollback path.\n *\n * **The engine never publishes.** Every event it produces goes to the\n * {@link Outbox}, and a relay carries the outbox to the broker. That\n * is the whole fix for the dual write: an event that only ever existed in a\n * `bus.publish` call between two Mongo writes is lost when the broker is down,\n * and the transaction is then mislabelled `STALE` despite having succeeded.\n */\n\n/**\n * Accept phase (synchronous).\n *\n * The order is deliberate: validate, then **claim, then lock**. The claim is the\n * outbox insert for the `accepted` event, and its uniqueness on\n * the message id (`<transactionId>:<step>`) is what makes the client-generated\n * id an idempotency key — a replayed command is recognised here, before a lock is taken and\n * before any work is forked. Locking first would make a retry queue behind its\n * own original.\n */\nexport function acceptTransaction() {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* OutboxTag;\n const source = yield* EventSourceTag;\n\n yield* validateUCFactory();\n\n const claim = yield* outbox.enqueue(acceptedEvent(command, source));\n if (claim === 'duplicate') {\n return { status: 'duplicate' } as const;\n }\n\n const handles = yield* lockUCFactory();\n return { status: 'accepted', handles } as const;\n });\n}\n\n/** What {@link acceptTransaction} decided — a fresh command, or a replay. */\nexport type AcceptOutcome = Effect.Success<\n ReturnType<typeof acceptTransaction>\n>;\n\n/**\n * Execute phase (asynchronous continuation). Never leaks locks.\n *\n * The success arm records **nothing**: `execute` is contractually required to\n * have written the `completed` entry in the same storage transaction as its\n * state change, because only the handler holds the session that can make those\n * two writes one. Recording it here as well would reintroduce the dual write in\n * the opposite direction — an event announcing a write that may have rolled\n * back.\n *\n * The failure arm does record, because there is no state change left to be\n * atomic with: the rollback has already undone it.\n */\nexport function completeTransaction(handles: readonly LockHandle[]) {\n return Effect.gen(function* () {\n const command = yield* CommandTag;\n const outbox = yield* OutboxTag;\n const source = yield* EventSourceTag;\n\n const free = freeUCFactory().pipe(\n Effect.provideService(LockHandlesTag, handles),\n Effect.ignore,\n );\n\n yield* executeUCFactory().pipe(\n Effect.matchEffect({\n onSuccess: () => Effect.void,\n onFailure: error =>\n rollbackUCFactory().pipe(\n Effect.provideService(OutcomeTag, undefined),\n // The compensation's own failure is reported before it is\n // discarded. Discarding it is right — the client is polling for a\n // terminal state and must still get one, so the `failed` record\n // below is written either way — but until this line the error\n // reached nothing: not the record, whose `error` is `execute`'s,\n // and not the log. An operator reading `FAILED` then reasonably\n // concluded the write had been undone when it had not.\n //\n // Annotations rather than message arguments, matching the outbox\n // relay: they reach a sink as structured fields, so a stranded\n // transaction is queryable by its id instead of being parsed out of\n // a rendered string.\n //\n // That is true as of this change and was not before it. A service's\n // Effect→tooling logger bridge (`observability.ts`) dropped\n // `annotations` outright and matched Effect's level labels with the\n // wrong casing, so every annotated field was discarded and every\n // level arrived as INFO — measured in Loki while verifying this log.\n Effect.tapError(rollbackError =>\n Effect.logError('transaction rollback failed').pipe(\n Effect.annotateLogs({\n transactionId: command.transactionId,\n entity: command.entity,\n executeError: String(error),\n rollbackError: String(rollbackError),\n }),\n ),\n ),\n Effect.ignore,\n Effect.andThen(\n // Best-effort: the transaction already failed, and a store that\n // cannot take the failure record must not turn into an unhandled\n // defect in a forked daemon. The recovery sweep is what notices.\n Effect.ignore(\n outbox.enqueue(failedEvent(command, error, source)),\n ),\n ),\n ),\n }),\n Effect.ensuring(free),\n );\n });\n}\n"],"names":["Effect","acceptedEvent","failedEvent","OutboxTag","CommandTag","LockHandlesTag","OutcomeTag","EventSourceTag","executeUCFactory","freeUCFactory","lockUCFactory","rollbackUCFactory","validateUCFactory","acceptTransaction","gen","command","outbox","source","claim","enqueue","status","handles","completeTransaction","free","pipe","provideService","ignore","matchEffect","onSuccess","void","onFailure","error","undefined","tapError","rollbackError","logError","annotateLogs","transactionId","entity","executeError","String","andThen","ensuring"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,EAAEC,WAAW,QAAQ,wBAAwB;AACnE,SAASC,SAAS,QAAQ,yBAAyB;AACnD,SACEC,UAAU,EACVC,cAAc,EACdC,UAAU,QACL,kCAAkC;AACzC,SAASC,cAAc,QAAQ,2BAA2B;AAE1D,SACEC,gBAAgB,EAChBC,aAAa,EACbC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QACZ,2BAA2B;AAElC;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GACD,OAAO,SAASC;IACd,OAAOb,OAAOc,GAAG,CAAC;QAChB,MAAMC,UAAU,OAA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oBACxB,MAGJlC,OAAO0B,MAAM,EACb1B,OAAOyC,OAAO,CACZ,gEAAgE;gBAChE,iEAAiE;gBACjE,iEAAiE;gBACjEzC,OAAO0B,MAAM,CACXV,OAAOG,OAAO,CAACjB,YAAYa,SAASgB,OAAOd;QAIrD,IACAjB,OAAO0C,QAAQ,CAACnB;IAEpB;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './contracts/command.js';
2
2
  export * from './contracts/event.js';
3
+ export * from './contracts/flow-capability.js';
4
+ export * from './contracts/flow-messages.js';
3
5
  export * from './contracts/inbox.js';
6
+ export * from './contracts/messages.js';
4
7
  export * from './contracts/outbox.js';
5
8
  export * from './contracts/record.js';
6
9
  export * from './contracts/saga-definition.js';
@@ -8,6 +11,7 @@ export * from './contracts/unit-of-work.js';
8
11
  export * from './mixins/transaction-mixins.js';
9
12
  export * from './ports/event-bus.js';
10
13
  export * from './ports/event-source.js';
14
+ export * from './ports/flow-engine.js';
11
15
  export * from './ports/lock-service.js';
12
16
  export * from './ports/retry-budget.js';
13
17
  export * from './ports/saga-dispatcher.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './contracts/command.js';
2
2
  export * from './contracts/event.js';
3
+ export * from './contracts/flow-capability.js';
4
+ export * from './contracts/flow-messages.js';
3
5
  export * from './contracts/inbox.js';
6
+ export * from './contracts/messages.js';
4
7
  export * from './contracts/outbox.js';
5
8
  export * from './contracts/record.js';
6
9
  export * from './contracts/saga-definition.js';
@@ -8,6 +11,7 @@ export * from './contracts/unit-of-work.js';
8
11
  export * from './mixins/transaction-mixins.js';
9
12
  export * from './ports/event-bus.js';
10
13
  export * from './ports/event-source.js';
14
+ export * from './ports/flow-engine.js';
11
15
  export * from './ports/lock-service.js';
12
16
  export * from './ports/retry-budget.js';
13
17
  export * from './ports/saga-dispatcher.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './contracts/unit-of-work.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/retry-budget.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './ports/transaction-stream-hub.js';\nexport * from './reactions/on.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,oBAAoB;AAClC,cAAc,0BAA0B"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/flow-capability.js';\nexport * from './contracts/flow-messages.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/messages.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './contracts/unit-of-work.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/flow-engine.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/retry-budget.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './ports/transaction-stream-hub.js';\nexport * from './reactions/on.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,iCAAiC;AAC/C,cAAc,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,oBAAoB;AAClC,cAAc,0BAA0B"}
@@ -0,0 +1,54 @@
1
+ import type { Slip } from '@entifix/business/flow';
2
+ import { type StoreFailure } from '@entifix/core';
3
+ import { Context, type Effect, Schema } from 'effect';
4
+ /**
5
+ * Where a flow stands. `suspended` is a flow past its commit point whose step
6
+ * keeps failing — it is waiting for retries or an operator, never compensated;
7
+ * `waiting` is a flow parked at a durable wait for a signal.
8
+ */
9
+ export type FlowState = 'running' | 'waiting' | 'suspended' | 'completed' | 'compensated' | 'failed' | 'interrupted';
10
+ export interface FlowStatus {
11
+ readonly flowId: string;
12
+ readonly state: FlowState;
13
+ /** The step in progress, or the one the flow stopped at. */
14
+ readonly step?: string;
15
+ }
16
+ declare const FlowNotFound_base: Schema.Class<FlowNotFound, Schema.TaggedStruct<"FlowNotFound", {
17
+ readonly flowId: Schema.String;
18
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"flowNotFound", "notFound">>;
19
+ /** No flow is known by this id. */
20
+ export declare class FlowNotFound extends FlowNotFound_base {
21
+ }
22
+ declare const FlowSignalRejected_base: Schema.Class<FlowSignalRejected, Schema.TaggedStruct<"FlowSignalRejected", {
23
+ readonly flowId: Schema.String;
24
+ readonly token: Schema.String;
25
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"flowSignalRejected", "conflict">>;
26
+ /**
27
+ * A signal the flow will not take: it is not waiting, it waits for another
28
+ * token, or the wait already timed out. A late signal is an answer, not an
29
+ * outage.
30
+ */
31
+ export declare class FlowSignalRejected extends FlowSignalRejected_base {
32
+ }
33
+ /**
34
+ * Runs pinned slips durably
35
+ * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).
36
+ *
37
+ * There is deliberately no `await`: a caller learns how a flow ended from its
38
+ * `flow.*` events, pushed, never by holding a request open on it.
39
+ */
40
+ export interface FlowEngine {
41
+ /** Starts a flow, idempotently: the same key answers the same `flowId`. */
42
+ readonly start: (slip: Slip, idempotencyKey: string) => Effect.Effect<{
43
+ readonly flowId: string;
44
+ }, StoreFailure>;
45
+ readonly status: (flowId: string) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;
46
+ /** Completes a durable wait the flow is parked at. */
47
+ readonly signal: (flowId: string, token: string, outcome: unknown) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
48
+ readonly interrupt: (flowId: string) => Effect.Effect<void, FlowNotFound | StoreFailure>;
49
+ }
50
+ declare const FlowEngineTag_base: Context.ServiceClass<FlowEngineTag, "@entifix/transactions/FlowEngine", FlowEngine>;
51
+ export declare class FlowEngineTag extends FlowEngineTag_base {
52
+ }
53
+ export {};
54
+ //# sourceMappingURL=flow-engine.d.ts.map
@@ -0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AAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC3E,QAAQ,CAAC,SAAS,EAAE,CAClB,MAAM,EAAE,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;CACvD;;AAED,qBAAa,aAAc,SAAQ,kBAElC;CAAG"}
@@ -0,0 +1,19 @@
1
+ import { Failure } from '@entifix/core';
2
+ import { Context, Schema } from 'effect';
3
+ /** No flow is known by this id. */ export class FlowNotFound extends Failure.notFound()('FlowNotFound', 'flowNotFound', {
4
+ flowId: Schema.String
5
+ }) {
6
+ }
7
+ /**
8
+ * A signal the flow will not take: it is not waiting, it waits for another
9
+ * token, or the wait already timed out. A late signal is an answer, not an
10
+ * outage.
11
+ */ export class FlowSignalRejected extends Failure.conflict()('FlowSignalRejected', 'flowSignalRejected', {
12
+ flowId: Schema.String,
13
+ token: Schema.String
14
+ }) {
15
+ }
16
+ export class FlowEngineTag extends Context.Service()('@entifix/transactions/FlowEngine') {
17
+ }
18
+
19
+ //# sourceMappingURL=flow-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/flow-engine.ts"],"sourcesContent":["import type { Slip } from '@entifix/business/flow';\nimport { Failure, type StoreFailure } from '@entifix/core';\nimport { Context, type Effect, Schema } from 'effect';\n\n/**\n * Where a flow stands. `suspended` is a flow past its commit point whose step\n * keeps failing — it is waiting for retries or an operator, never compensated;\n * `waiting` is a flow parked at a durable wait for a signal.\n */\nexport type FlowState =\n | 'running'\n | 'waiting'\n | 'suspended'\n | 'completed'\n | 'compensated'\n | 'failed'\n | 'interrupted';\n\nexport interface FlowStatus {\n readonly flowId: string;\n readonly state: FlowState;\n /** The step in progress, or the one the flow stopped at. */\n readonly step?: string;\n}\n\n/** No flow is known by this id. */\nexport class FlowNotFound extends Failure.notFound<FlowNotFound>()(\n 'FlowNotFound',\n 'flowNotFound',\n { flowId: Schema.String },\n) {}\n\n/**\n * A signal the flow will not take: it is not waiting, it waits for another\n * token, or the wait already timed out. A late signal is an answer, not an\n * outage.\n */\nexport class FlowSignalRejected extends Failure.conflict<FlowSignalRejected>()(\n 'FlowSignalRejected',\n 'flowSignalRejected',\n { flowId: Schema.String, token: Schema.String },\n) {}\n\n/**\n * Runs pinned slips durably\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n *\n * There is deliberately no `await`: a caller learns how a flow ended from its\n * `flow.*` events, pushed, never by holding a request open on it.\n */\nexport interface FlowEngine {\n /** Starts a flow, idempotently: the same key answers the same `flowId`. */\n readonly start: (\n slip: Slip,\n idempotencyKey: string,\n ) => Effect.Effect<{ readonly flowId: string }, StoreFailure>;\n readonly status: (\n flowId: string,\n ) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;\n /** Completes a durable wait the flow is parked at. */\n readonly signal: (\n flowId: string,\n token: string,\n outcome: unknown,\n ) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;\n readonly interrupt: (\n flowId: string,\n ) => Effect.Effect<void, FlowNotFound | StoreFailure>;\n}\n\nexport class FlowEngineTag extends Context.Service<FlowEngineTag, FlowEngine>()(\n '@entifix/transactions/FlowEngine',\n) {}\n"],"names":["Failure","Context","Schema","FlowNotFound","notFound","flowId","String","FlowSignalRejected","conflict","token","FlowEngineTag","Service"],"mappings":"AACA,SAASA,OAAO,QAA2B,gBAAgB;AAC3D,SAASC,OAAO,EAAeC,MAAM,QAAQ,SAAS;AAuBtD,iCAAiC,GACjC,OAAO,MAAMC,qBAAqBH,QAAQI,QAAQ,GAChD,gBACA,gBACA;IAAEC,QAAQH,OAAOI,MAAM;AAAC;AACvB;AAEH;;;;CAIC,GACD,OAAO,MAAMC,2BAA2BP,QAAQQ,QAAQ,GACtD,sBACA,sBACA;IAAEH,QAAQH,OAAOI,MAAM;IAAEG,OAAOP,OAAOI,MAAM;AAAC;AAC7C;AA6BH,OAAO,MAAMI,sBAAsBT,QAAQU,OAAO,GAChD;AACC"}