@entifix/transactions 0.1.0-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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/dist/contracts/command.d.ts +59 -0
  3. package/dist/contracts/command.d.ts.map +1 -0
  4. package/dist/contracts/command.js +42 -0
  5. package/dist/contracts/command.js.map +1 -0
  6. package/dist/contracts/event.d.ts +84 -0
  7. package/dist/contracts/event.d.ts.map +1 -0
  8. package/dist/contracts/event.js +67 -0
  9. package/dist/contracts/event.js.map +1 -0
  10. package/dist/contracts/inbox.d.ts +80 -0
  11. package/dist/contracts/inbox.d.ts.map +1 -0
  12. package/dist/contracts/inbox.js +5 -0
  13. package/dist/contracts/inbox.js.map +1 -0
  14. package/dist/contracts/outbox.d.ts +137 -0
  15. package/dist/contracts/outbox.d.ts.map +1 -0
  16. package/dist/contracts/outbox.js +5 -0
  17. package/dist/contracts/outbox.js.map +1 -0
  18. package/dist/contracts/record.d.ts +108 -0
  19. package/dist/contracts/record.d.ts.map +1 -0
  20. package/dist/contracts/record.js +27 -0
  21. package/dist/contracts/record.js.map +1 -0
  22. package/dist/contracts/saga-definition.d.ts +186 -0
  23. package/dist/contracts/saga-definition.d.ts.map +1 -0
  24. package/dist/contracts/saga-definition.js +95 -0
  25. package/dist/contracts/saga-definition.js.map +1 -0
  26. package/dist/engine/resolve-template.d.ts +49 -0
  27. package/dist/engine/resolve-template.d.ts.map +1 -0
  28. package/dist/engine/resolve-template.js +106 -0
  29. package/dist/engine/resolve-template.js.map +1 -0
  30. package/dist/engine/run-saga.d.ts +55 -0
  31. package/dist/engine/run-saga.d.ts.map +1 -0
  32. package/dist/engine/run-saga.js +467 -0
  33. package/dist/engine/run-saga.js.map +1 -0
  34. package/dist/engine/run-transaction.d.ts +55 -0
  35. package/dist/engine/run-transaction.d.ts.map +1 -0
  36. package/dist/engine/run-transaction.js +101 -0
  37. package/dist/engine/run-transaction.js.map +1 -0
  38. package/dist/index.d.ts +21 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +22 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/mixins/transaction-mixins.d.ts +20 -0
  43. package/dist/mixins/transaction-mixins.d.ts.map +1 -0
  44. package/dist/mixins/transaction-mixins.js +13 -0
  45. package/dist/mixins/transaction-mixins.js.map +1 -0
  46. package/dist/ports/event-bus.d.ts +98 -0
  47. package/dist/ports/event-bus.d.ts.map +1 -0
  48. package/dist/ports/event-bus.js +5 -0
  49. package/dist/ports/event-bus.js.map +1 -0
  50. package/dist/ports/event-source.d.ts +22 -0
  51. package/dist/ports/event-source.d.ts.map +1 -0
  52. package/dist/ports/event-source.js +20 -0
  53. package/dist/ports/event-source.js.map +1 -0
  54. package/dist/ports/lock-service.d.ts +24 -0
  55. package/dist/ports/lock-service.d.ts.map +1 -0
  56. package/dist/ports/lock-service.js +5 -0
  57. package/dist/ports/lock-service.js.map +1 -0
  58. package/dist/ports/saga-dispatcher.d.ts +47 -0
  59. package/dist/ports/saga-dispatcher.d.ts.map +1 -0
  60. package/dist/ports/saga-dispatcher.js +5 -0
  61. package/dist/ports/saga-dispatcher.js.map +1 -0
  62. package/dist/ports/saga-store.d.ts +98 -0
  63. package/dist/ports/saga-store.d.ts.map +1 -0
  64. package/dist/ports/saga-store.js +20 -0
  65. package/dist/ports/saga-store.js.map +1 -0
  66. package/dist/ports/sequence-service.d.ts +17 -0
  67. package/dist/ports/sequence-service.d.ts.map +1 -0
  68. package/dist/ports/sequence-service.js +5 -0
  69. package/dist/ports/sequence-service.js.map +1 -0
  70. package/dist/ports/transaction-handler.d.ts +68 -0
  71. package/dist/ports/transaction-handler.d.ts.map +1 -0
  72. package/dist/ports/transaction-handler.js +5 -0
  73. package/dist/ports/transaction-handler.js.map +1 -0
  74. package/dist/ports/transaction-sink.d.ts +119 -0
  75. package/dist/ports/transaction-sink.d.ts.map +1 -0
  76. package/dist/ports/transaction-sink.js +28 -0
  77. package/dist/ports/transaction-sink.js.map +1 -0
  78. package/dist/stream/transaction-stream-hub.d.ts +41 -0
  79. package/dist/stream/transaction-stream-hub.d.ts.map +1 -0
  80. package/dist/stream/transaction-stream-hub.js +53 -0
  81. package/dist/stream/transaction-stream-hub.js.map +1 -0
  82. package/dist/use-case/facade.uc.d.ts +22 -0
  83. package/dist/use-case/facade.uc.d.ts.map +1 -0
  84. package/dist/use-case/facade.uc.js +55 -0
  85. package/dist/use-case/facade.uc.js.map +1 -0
  86. package/package.json +65 -0
@@ -0,0 +1,55 @@
1
+ import { Effect } from 'effect';
2
+ import { TransactionOutboxTag } from '../contracts/outbox.js';
3
+ import { CommandTag } from '../mixins/transaction-mixins.js';
4
+ import { EventSourceTag } from '../ports/event-source.js';
5
+ import type { LockHandle } from '../ports/lock-service.js';
6
+ /**
7
+ * The saga engine, split at the 202 boundary so validation/lock failures are
8
+ * synchronous (mapped to `400`/`409`) while the write runs asynchronously:
9
+ *
10
+ * - {@link acceptTransaction} — validate -> claim -> lock. Runs before the
11
+ * service answers `202`; its failures are the client's answer.
12
+ * - {@link completeTransaction} — execute -> free, or rollback -> record
13
+ * `failed` -> free. Forked after `202`; `free` always runs via `ensuring`, so
14
+ * locks never leak on a rollback path.
15
+ *
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
18
+ * is the whole fix for the dual write: an event that only ever existed in a
19
+ * `bus.publish` call between two Mongo writes is lost when the broker is down,
20
+ * and the transaction is then mislabelled `STALE` despite having succeeded.
21
+ */
22
+ /**
23
+ * Accept phase (synchronous).
24
+ *
25
+ * The order is deliberate: validate, then **claim, then lock**. The claim is the
26
+ * outbox insert for the `accepted` event, and its uniqueness on
27
+ * the message id (`<transactionId>:<step>`) is what makes the client-generated
28
+ * id an idempotency key — a replayed command is recognised here, before a lock is taken and
29
+ * before any work is forked. Locking first would make a retry queue behind its
30
+ * own original.
31
+ */
32
+ export declare function acceptTransaction(): Effect.Effect<{
33
+ readonly status: "duplicate";
34
+ readonly handles?: undefined;
35
+ } | {
36
+ readonly status: "accepted";
37
+ readonly handles: readonly LockHandle[];
38
+ }, import("@entifix/core").EntifixError, import("../index.js").TransactionHandlerTag | TransactionOutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
39
+ /** What {@link acceptTransaction} decided — a fresh command, or a replay. */
40
+ export type AcceptOutcome = Effect.Effect.Success<ReturnType<typeof acceptTransaction>>;
41
+ /**
42
+ * Execute phase (asynchronous continuation). Never leaks locks.
43
+ *
44
+ * The success arm records **nothing**: `execute` is contractually required to
45
+ * have written the `completed` entry in the same storage transaction as its
46
+ * state change, because only the handler holds the session that can make those
47
+ * two writes one. Recording it here as well would reintroduce the dual write in
48
+ * the opposite direction — an event announcing a write that may have rolled
49
+ * back.
50
+ *
51
+ * The failure arm does record, because there is no state change left to be
52
+ * atomic with: the rollback has already undone it.
53
+ */
54
+ export declare function completeTransaction(handles: readonly LockHandle[]): Effect.Effect<void, never, import("../index.js").TransactionHandlerTag | TransactionOutboxTag | import("../index.js").LockServiceTag | CommandTag | EventSourceTag>;
55
+ //# sourceMappingURL=run-transaction.d.ts.map
@@ -0,0 +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;;;;;;kLAgBhC;AAED,6EAA6E;AAC7E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAC/C,UAAU,CAAC,OAAO,iBAAiB,CAAC,CACrC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,uKA2DjE"}
@@ -0,0 +1,101 @@
1
+ import { Effect } from 'effect';
2
+ import { acceptedEvent, failedEvent } from '../contracts/event.js';
3
+ import { TransactionOutboxTag } from '../contracts/outbox.js';
4
+ import { CommandTag, LockHandlesTag, OutcomeTag } from '../mixins/transaction-mixins.js';
5
+ import { EventSourceTag } from '../ports/event-source.js';
6
+ import { executeUCFactory, freeUCFactory, lockUCFactory, rollbackUCFactory, validateUCFactory } from '../use-case/facade.uc.js';
7
+ /**
8
+ * The saga engine, split at the 202 boundary so validation/lock failures are
9
+ * synchronous (mapped to `400`/`409`) while the write runs asynchronously:
10
+ *
11
+ * - {@link acceptTransaction} — validate -> claim -> lock. Runs before the
12
+ * service answers `202`; its failures are the client's answer.
13
+ * - {@link completeTransaction} — execute -> free, or rollback -> record
14
+ * `failed` -> free. Forked after `202`; `free` always runs via `ensuring`, so
15
+ * locks never leak on a rollback path.
16
+ *
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
19
+ * is the whole fix for the dual write: an event that only ever existed in a
20
+ * `bus.publish` call between two Mongo writes is lost when the broker is down,
21
+ * and the transaction is then mislabelled `STALE` despite having succeeded.
22
+ */ /**
23
+ * Accept phase (synchronous).
24
+ *
25
+ * The order is deliberate: validate, then **claim, then lock**. The claim is the
26
+ * outbox insert for the `accepted` event, and its uniqueness on
27
+ * the message id (`<transactionId>:<step>`) is what makes the client-generated
28
+ * id an idempotency key — a replayed command is recognised here, before a lock is taken and
29
+ * before any work is forked. Locking first would make a retry queue behind its
30
+ * own original.
31
+ */ export function acceptTransaction() {
32
+ return Effect.gen(function*() {
33
+ const command = yield* CommandTag;
34
+ const outbox = yield* TransactionOutboxTag;
35
+ const source = yield* EventSourceTag;
36
+ yield* validateUCFactory();
37
+ const claim = yield* outbox.enqueue(acceptedEvent(command, source));
38
+ if (claim === 'duplicate') {
39
+ return {
40
+ status: 'duplicate'
41
+ };
42
+ }
43
+ const handles = yield* lockUCFactory();
44
+ return {
45
+ status: 'accepted',
46
+ handles
47
+ };
48
+ });
49
+ }
50
+ /**
51
+ * Execute phase (asynchronous continuation). Never leaks locks.
52
+ *
53
+ * The success arm records **nothing**: `execute` is contractually required to
54
+ * have written the `completed` entry in the same storage transaction as its
55
+ * state change, because only the handler holds the session that can make those
56
+ * two writes one. Recording it here as well would reintroduce the dual write in
57
+ * the opposite direction — an event announcing a write that may have rolled
58
+ * back.
59
+ *
60
+ * The failure arm does record, because there is no state change left to be
61
+ * atomic with: the rollback has already undone it.
62
+ */ export function completeTransaction(handles) {
63
+ return Effect.gen(function*() {
64
+ const command = yield* CommandTag;
65
+ const outbox = yield* TransactionOutboxTag;
66
+ const source = yield* EventSourceTag;
67
+ const free = freeUCFactory().pipe(Effect.provideService(LockHandlesTag, handles), Effect.ignore);
68
+ yield* executeUCFactory().pipe(Effect.matchEffect({
69
+ onSuccess: ()=>Effect.void,
70
+ onFailure: (error)=>rollbackUCFactory().pipe(Effect.provideService(OutcomeTag, undefined), // The compensation's own failure is reported before it is
71
+ // discarded. Discarding it is right — the client is polling for a
72
+ // terminal state and must still get one, so the `failed` record
73
+ // below is written either way — but until this line the error
74
+ // reached nothing: not the record, whose `error` is `execute`'s,
75
+ // and not the log. An operator reading `FAILED` then reasonably
76
+ // concluded the write had been undone when it had not.
77
+ //
78
+ // Annotations rather than message arguments, matching the outbox
79
+ // relay: they reach a sink as structured fields, so a stranded
80
+ // transaction is queryable by its id instead of being parsed out of
81
+ // a rendered string.
82
+ //
83
+ // That is true as of this change and was not before it. A service's
84
+ // Effect→tooling logger bridge (`observability.ts`) dropped
85
+ // `annotations` outright and matched Effect's level labels with the
86
+ // wrong casing, so every annotated field was discarded and every
87
+ // level arrived as INFO — measured in Loki while verifying this log.
88
+ Effect.tapError((rollbackError)=>Effect.logError('transaction rollback failed').pipe(Effect.annotateLogs({
89
+ transactionId: command.transactionId,
90
+ entity: command.entity,
91
+ executeError: String(error),
92
+ rollbackError: String(rollbackError)
93
+ }))), Effect.ignore, Effect.andThen(// Best-effort: the transaction already failed, and a store that
94
+ // cannot take the failure record must not turn into an unhandled
95
+ // defect in a forked daemon. The recovery sweep is what notices.
96
+ Effect.ignore(outbox.enqueue(failedEvent(command, error, source)))))
97
+ }), Effect.ensuring(free));
98
+ });
99
+ }
100
+
101
+ //# sourceMappingURL=run-transaction.js.map
@@ -0,0 +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.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,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,OAAOX;QACvB,MAAMY,SAAS,OAAOb;QACtB,MAAMc,SAAS,OAAOV;QAEtB,OAAOK;QAEP,MAAMM,QAAQ,OAAOF,OAAOG,OAAO,CAAClB,cAAcc,SAASE;QAC3D,IAAIC,UAAU,aAAa;YACzB,OAAO;gBAAEE,QAAQ;YAAY;QAC/B;QAEA,MAAMC,UAAU,OAAOX;QACvB,OAAO;YAAEU,QAAQ;YAAYC;QAAQ;IACvC;AACF;AAOA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,oBAAoBD,OAA8B;IAChE,OAAOrB,OAAOc,GAAG,CAAC;QAChB,MAAMC,UAAU,OAAOX;QACvB,MAAMY,SAAS,OAAOb;QACtB,MAAMc,SAAS,OAAOV;QAEtB,MAAMgB,OAAOd,gBAAgBe,IAAI,CAC/BxB,OAAOyB,cAAc,CAACpB,gBAAgBgB,UACtCrB,OAAO0B,MAAM;QAGf,OAAOlB,mBAAmBgB,IAAI,CAC5BxB,OAAO2B,WAAW,CAAC;YACjBC,WAAW,IAAM5B,OAAO6B,IAAI;YAC5BC,WAAWC,CAAAA,QACTpB,oBAAoBa,IAAI,CACtBxB,OAAOyB,cAAc,CAACnB,YAAY0B,YAClC,0DAA0D;gBAC1D,kEAAkE;gBAClE,gEAAgE;gBAChE,8DAA8D;gBAC9D,iEAAiE;gBACjE,gEAAgE;gBAChE,uDAAuD;gBACvD,EAAE;gBACF,iEAAiE;gBACjE,+DAA+D;gBAC/D,oEAAoE;gBACpE,qBAAqB;gBACrB,EAAE;gBACF,oEAAoE;gBACpE,4DAA4D;gBAC5D,oEAAoE;gBACpE,iEAAiE;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"}
@@ -0,0 +1,21 @@
1
+ export * from './contracts/command.js';
2
+ export * from './contracts/event.js';
3
+ export * from './contracts/inbox.js';
4
+ export * from './contracts/outbox.js';
5
+ export * from './contracts/record.js';
6
+ export * from './contracts/saga-definition.js';
7
+ export * from './engine/resolve-template.js';
8
+ export * from './engine/run-saga.js';
9
+ export * from './engine/run-transaction.js';
10
+ export * from './mixins/transaction-mixins.js';
11
+ export * from './ports/event-bus.js';
12
+ export * from './ports/event-source.js';
13
+ export * from './ports/lock-service.js';
14
+ export * from './ports/saga-dispatcher.js';
15
+ export * from './ports/saga-store.js';
16
+ export * from './ports/sequence-service.js';
17
+ export * from './ports/transaction-handler.js';
18
+ export * from './ports/transaction-sink.js';
19
+ export * from './stream/transaction-stream-hub.js';
20
+ export * from './use-case/facade.uc.js';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,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,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ export * from './contracts/command.js';
2
+ export * from './contracts/event.js';
3
+ export * from './contracts/inbox.js';
4
+ export * from './contracts/outbox.js';
5
+ export * from './contracts/record.js';
6
+ export * from './contracts/saga-definition.js';
7
+ export * from './engine/resolve-template.js';
8
+ export * from './engine/run-saga.js';
9
+ export * from './engine/run-transaction.js';
10
+ export * from './mixins/transaction-mixins.js';
11
+ export * from './ports/event-bus.js';
12
+ export * from './ports/event-source.js';
13
+ export * from './ports/lock-service.js';
14
+ export * from './ports/saga-dispatcher.js';
15
+ export * from './ports/saga-store.js';
16
+ export * from './ports/sequence-service.js';
17
+ export * from './ports/transaction-handler.js';
18
+ export * from './ports/transaction-sink.js';
19
+ export * from './stream/transaction-stream-hub.js';
20
+ export * from './use-case/facade.uc.js';
21
+
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 './engine/resolve-template.js';\nexport * from './engine/run-saga.js';\nexport * from './engine/run-transaction.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/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 './stream/transaction-stream-hub.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,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,qCAAqC;AACnD,cAAc,0BAA0B"}
@@ -0,0 +1,20 @@
1
+ import { Context } from 'effect';
2
+ import type { TransactionCommand } from '../contracts/command.js';
3
+ import type { LockHandle } from '../ports/lock-service.js';
4
+ import type { TransactionOutcome } from '../ports/transaction-handler.js';
5
+ declare const CommandTag_base: Context.TagClass<CommandTag, "TransactionCommandTag", TransactionCommand<import("@entifix/core").SerializedEntity>>;
6
+ /**
7
+ * The runtime inputs the facade use-cases yield — the transaction analogue of
8
+ * `EntityTag`/`EntityIdTag`. The engine provides them at the right moment
9
+ * (`LockHandlesTag` after `lock`, `OutcomeTag` before `rollback`).
10
+ */
11
+ export declare class CommandTag extends CommandTag_base {
12
+ }
13
+ declare const LockHandlesTag_base: Context.TagClass<LockHandlesTag, "LockHandlesTag", readonly LockHandle[]>;
14
+ export declare class LockHandlesTag extends LockHandlesTag_base {
15
+ }
16
+ declare const OutcomeTag_base: Context.TagClass<OutcomeTag, "TransactionOutcomeTag", TransactionOutcome | undefined>;
17
+ export declare class OutcomeTag extends OutcomeTag_base {
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=transaction-mixins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-mixins.d.ts","sourceRoot":"","sources":["../../src/mixins/transaction-mixins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;;AAE1E;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,eAG7B;CAAG;;AAEN,qBAAa,cAAe,SAAQ,mBAGjC;CAAG;;AAEN,qBAAa,UAAW,SAAQ,eAG7B;CAAG"}
@@ -0,0 +1,13 @@
1
+ import { Context } from 'effect';
2
+ /**
3
+ * The runtime inputs the facade use-cases yield — the transaction analogue of
4
+ * `EntityTag`/`EntityIdTag`. The engine provides them at the right moment
5
+ * (`LockHandlesTag` after `lock`, `OutcomeTag` before `rollback`).
6
+ */ export class CommandTag extends Context.Tag('TransactionCommandTag')() {
7
+ }
8
+ export class LockHandlesTag extends Context.Tag('LockHandlesTag')() {
9
+ }
10
+ export class OutcomeTag extends Context.Tag('TransactionOutcomeTag')() {
11
+ }
12
+
13
+ //# sourceMappingURL=transaction-mixins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mixins/transaction-mixins.ts"],"sourcesContent":["import { Context } from 'effect';\n\nimport type { TransactionCommand } from '../contracts/command.js';\nimport type { LockHandle } from '../ports/lock-service.js';\nimport type { TransactionOutcome } from '../ports/transaction-handler.js';\n\n/**\n * The runtime inputs the facade use-cases yield — the transaction analogue of\n * `EntityTag`/`EntityIdTag`. The engine provides them at the right moment\n * (`LockHandlesTag` after `lock`, `OutcomeTag` before `rollback`).\n */\nexport class CommandTag extends Context.Tag('TransactionCommandTag')<\n CommandTag,\n TransactionCommand\n>() {}\n\nexport class LockHandlesTag extends Context.Tag('LockHandlesTag')<\n LockHandlesTag,\n readonly LockHandle[]\n>() {}\n\nexport class OutcomeTag extends Context.Tag('TransactionOutcomeTag')<\n OutcomeTag,\n TransactionOutcome | undefined\n>() {}\n"],"names":["Context","CommandTag","Tag","LockHandlesTag","OutcomeTag"],"mappings":"AAAA,SAASA,OAAO,QAAQ,SAAS;AAMjC;;;;CAIC,GACD,OAAO,MAAMC,mBAAmBD,QAAQE,GAAG,CAAC;AAGvC;AAEL,OAAO,MAAMC,uBAAuBH,QAAQE,GAAG,CAAC;AAG3C;AAEL,OAAO,MAAME,mBAAmBJ,QAAQE,GAAG,CAAC;AAGvC"}
@@ -0,0 +1,98 @@
1
+ import type { DomainEvent, EntifixConnError, EntifixError } from '@entifix/core';
2
+ import { Context, type Effect } from 'effect';
3
+ /**
4
+ * How a subscriber's queue is shaped, which is a property of the *workload*
5
+ * rather than of the transport (ADR 0030).
6
+ *
7
+ * - `work` — a named, durable queue that survives the consumer's restart and
8
+ * accumulates while it is gone. Replicas share it, so each message reaches
9
+ * exactly one of them. A projection writer, a fold and a settlement consumer
10
+ * all want this.
11
+ * - `broadcast` — a connection-scoped exclusive queue, so every replica
12
+ * receives every message and nothing is retained across a restart. Correct
13
+ * only when the replicas differ from one another — a socket push holding
14
+ * different clients per process.
15
+ *
16
+ * ADR 0029 built the exclusive queue for every subscriber and gave a stated
17
+ * reason: a shared queue delivers each event to one replica, "which reads as
18
+ * flakiness rather than as a design". That reasoning is right for `broadcast`
19
+ * and wrong for `work`; it picked broadcast semantics for a workload that is
20
+ * work, at a time when the only subscriber made the difference invisible.
21
+ */
22
+ export type SubscriptionMode = 'work' | 'broadcast';
23
+ /**
24
+ * A subscriber's declared interest, together with the delivery policy the
25
+ * broker enforces for it.
26
+ *
27
+ * The shape mirrors `subscriptions` in `tools/slices/*.slice.ts`, so "how does
28
+ * this fail" is answered where it can be checked rather than in a review
29
+ * comment.
30
+ */
31
+ export interface Subscription {
32
+ /**
33
+ * The **subscribing** slice — the `tools/slices/` key, and half of the queue
34
+ * name.
35
+ *
36
+ * Deliberately not `EventSourceTag`, which is the *emitting* slice: one
37
+ * deployment hosts several slices (ADR 0021 co-deploys `transaction` inside
38
+ * marketplace-admin-service), so a process-wide "my slice" would attribute a
39
+ * consumer's queue to whichever slice happened to publish from the same
40
+ * process.
41
+ */
42
+ readonly slice: string;
43
+ /**
44
+ * The event name pattern, used verbatim as the broker's binding —
45
+ * `transaction.*`, `catalog.published`. Filtering in the handler instead is
46
+ * what this exists to prevent: it makes every consumer pay for every
47
+ * publisher's traffic, and it puts the routing rule where no register can
48
+ * check it.
49
+ */
50
+ readonly pattern: string;
51
+ readonly mode: SubscriptionMode;
52
+ /**
53
+ * How many times the broker may deliver a message before dead-lettering it.
54
+ *
55
+ * Enforced by the queue itself rather than by logic each consumer
56
+ * reimplements, so it applies to a redelivery after a crash as well as to one
57
+ * after a nack. `broadcast` queues have no dead-letter path, so the value is
58
+ * carried but unenforced there.
59
+ */
60
+ readonly maxAttempts: number;
61
+ }
62
+ /**
63
+ * The domain event bus (RabbitMQ in `@entifix/amqp`). Services publish
64
+ * what happened; interested slices subscribe to the names they declared.
65
+ *
66
+ * Typed on {@link DomainEvent} rather than on any one publisher's payload: a bus
67
+ * that only knew `TransactionEvent` had nothing for ADR 0009's catalog
68
+ * publication to travel in, which would have meant a second framing and a second
69
+ * transport for the same job.
70
+ *
71
+ * The port stays event-typed rather than envelope-typed — the adapter owns the
72
+ * wire framing — so a handler receives the message and its metadata without
73
+ * ever seeing the envelope that carried them.
74
+ */
75
+ export interface EventBus {
76
+ publish(event: DomainEvent): Effect.Effect<void, EntifixConnError>;
77
+ /**
78
+ * Register a consumer for the events matching `subscription.pattern`.
79
+ *
80
+ * The returned Effect completes once the subscription is established; the
81
+ * handler then runs per delivered event. Delivery is at-least-once, so a
82
+ * handler that is not idempotent must deduplicate on `event.id`.
83
+ *
84
+ * A handler failure is **transient**: the adapter requeues it and the broker
85
+ * counts the redelivery against `maxAttempts`, dead-lettering at the limit. A
86
+ * payload the adapter cannot read is **poison** and is quarantined with zero
87
+ * retries — a message that cannot be deserialized never becomes
88
+ * deserializable, and retrying it only spends the budget of the messages
89
+ * behind it. A *business* failure is neither: that message was processed
90
+ * successfully and already produced its own event (ADR 0030).
91
+ */
92
+ subscribe(subscription: Subscription, handler: (event: DomainEvent) => Effect.Effect<void, EntifixError>): Effect.Effect<void, EntifixConnError>;
93
+ }
94
+ declare const EventBusTag_base: Context.TagClass<EventBusTag, "EventBusTag", EventBus>;
95
+ export declare class EventBusTag extends EventBusTag_base {
96
+ }
97
+ export {};
98
+ //# sourceMappingURL=event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/ports/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACnE;;;;;;;;;;;;;;OAcG;IACH,SAAS,CACP,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,GACjE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;CAC1C;;AAED,qBAAa,WAAY,SAAQ,gBAG9B;CAAG"}
@@ -0,0 +1,5 @@
1
+ import { Context } from 'effect';
2
+ export class EventBusTag extends Context.Tag('EventBusTag')() {
3
+ }
4
+
5
+ //# sourceMappingURL=event-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/event-bus.ts"],"sourcesContent":["import type {\n DomainEvent,\n EntifixConnError,\n EntifixError,\n} from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * How a subscriber's queue is shaped, which is a property of the *workload*\n * rather than of the transport (ADR 0030).\n *\n * - `work` — a named, durable queue that survives the consumer's restart and\n * accumulates while it is gone. Replicas share it, so each message reaches\n * exactly one of them. A projection writer, a fold and a settlement consumer\n * all want this.\n * - `broadcast` — a connection-scoped exclusive queue, so every replica\n * receives every message and nothing is retained across a restart. Correct\n * only when the replicas differ from one another — a socket push holding\n * different clients per process.\n *\n * ADR 0029 built the exclusive queue for every subscriber and gave a stated\n * reason: a shared queue delivers each event to one replica, \"which reads as\n * flakiness rather than as a design\". That reasoning is right for `broadcast`\n * and wrong for `work`; it picked broadcast semantics for a workload that is\n * work, at a time when the only subscriber made the difference invisible.\n */\nexport type SubscriptionMode = 'work' | 'broadcast';\n\n/**\n * A subscriber's declared interest, together with the delivery policy the\n * broker enforces for it.\n *\n * The shape mirrors `subscriptions` in `tools/slices/*.slice.ts`, so \"how does\n * this fail\" is answered where it can be checked rather than in a review\n * comment.\n */\nexport interface Subscription {\n /**\n * The **subscribing** slice — the `tools/slices/` key, and half of the queue\n * name.\n *\n * Deliberately not `EventSourceTag`, which is the *emitting* slice: one\n * deployment hosts several slices (ADR 0021 co-deploys `transaction` inside\n * marketplace-admin-service), so a process-wide \"my slice\" would attribute a\n * consumer's queue to whichever slice happened to publish from the same\n * process.\n */\n readonly slice: string;\n /**\n * The event name pattern, used verbatim as the broker's binding —\n * `transaction.*`, `catalog.published`. Filtering in the handler instead is\n * what this exists to prevent: it makes every consumer pay for every\n * publisher's traffic, and it puts the routing rule where no register can\n * check it.\n */\n readonly pattern: string;\n readonly mode: SubscriptionMode;\n /**\n * How many times the broker may deliver a message before dead-lettering it.\n *\n * Enforced by the queue itself rather than by logic each consumer\n * reimplements, so it applies to a redelivery after a crash as well as to one\n * after a nack. `broadcast` queues have no dead-letter path, so the value is\n * carried but unenforced there.\n */\n readonly maxAttempts: number;\n}\n\n/**\n * The domain event bus (RabbitMQ in `@entifix/amqp`). Services publish\n * what happened; interested slices subscribe to the names they declared.\n *\n * Typed on {@link DomainEvent} rather than on any one publisher's payload: a bus\n * that only knew `TransactionEvent` had nothing for ADR 0009's catalog\n * publication to travel in, which would have meant a second framing and a second\n * transport for the same job.\n *\n * The port stays event-typed rather than envelope-typed — the adapter owns the\n * wire framing — so a handler receives the message and its metadata without\n * ever seeing the envelope that carried them.\n */\nexport interface EventBus {\n publish(event: DomainEvent): Effect.Effect<void, EntifixConnError>;\n /**\n * Register a consumer for the events matching `subscription.pattern`.\n *\n * The returned Effect completes once the subscription is established; the\n * handler then runs per delivered event. Delivery is at-least-once, so a\n * handler that is not idempotent must deduplicate on `event.id`.\n *\n * A handler failure is **transient**: the adapter requeues it and the broker\n * counts the redelivery against `maxAttempts`, dead-lettering at the limit. A\n * payload the adapter cannot read is **poison** and is quarantined with zero\n * retries — a message that cannot be deserialized never becomes\n * deserializable, and retrying it only spends the budget of the messages\n * behind it. A *business* failure is neither: that message was processed\n * successfully and already produced its own event (ADR 0030).\n */\n subscribe(\n subscription: Subscription,\n handler: (event: DomainEvent) => Effect.Effect<void, EntifixError>,\n ): Effect.Effect<void, EntifixConnError>;\n}\n\nexport class EventBusTag extends Context.Tag('EventBusTag')<\n EventBusTag,\n EventBus\n>() {}\n"],"names":["Context","EventBusTag","Tag"],"mappings":"AAKA,SAASA,OAAO,QAAqB,SAAS;AAmG9C,OAAO,MAAMC,oBAAoBD,QAAQE,GAAG,CAAC;AAGxC"}
@@ -0,0 +1,22 @@
1
+ import { Context } from 'effect';
2
+ declare const EventSourceTag_base: Context.TagClass<EventSourceTag, "EventSourceTag", string>;
3
+ /**
4
+ * The name of the slice publishing an event — `marketplace-admin`, `order`.
5
+ *
6
+ * A **slice**, deliberately, and not one of the two nearer alternatives. Not the
7
+ * deployment: co-deploying two slices into one process is reversible, and a
8
+ * `source` that changed when a process moved would rewrite history for a fact
9
+ * that did not change. Not the domain either: a slice may hold several, so the
10
+ * domain does not identify the publisher. The slice is ADR 0020's ownership
11
+ * noun and is already executable in `tools/slices/`, which is what lets the
12
+ * register be checked against what the bus actually carries.
13
+ *
14
+ * Provided at each composition root beside the other environment facts
15
+ * (`TenantDatabasePrefix`, `SagaDatabaseName`) rather than read from an
16
+ * environment variable, so a service that forgets it fails to build its layer
17
+ * instead of publishing events signed by nobody.
18
+ */
19
+ export declare class EventSourceTag extends EventSourceTag_base {
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=event-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-source.d.ts","sourceRoot":"","sources":["../../src/ports/event-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,cAAe,SAAQ,mBAGjC;CAAG"}
@@ -0,0 +1,20 @@
1
+ import { Context } from 'effect';
2
+ /**
3
+ * The name of the slice publishing an event — `marketplace-admin`, `order`.
4
+ *
5
+ * A **slice**, deliberately, and not one of the two nearer alternatives. Not the
6
+ * deployment: co-deploying two slices into one process is reversible, and a
7
+ * `source` that changed when a process moved would rewrite history for a fact
8
+ * that did not change. Not the domain either: a slice may hold several, so the
9
+ * domain does not identify the publisher. The slice is ADR 0020's ownership
10
+ * noun and is already executable in `tools/slices/`, which is what lets the
11
+ * register be checked against what the bus actually carries.
12
+ *
13
+ * Provided at each composition root beside the other environment facts
14
+ * (`TenantDatabasePrefix`, `SagaDatabaseName`) rather than read from an
15
+ * environment variable, so a service that forgets it fails to build its layer
16
+ * instead of publishing events signed by nobody.
17
+ */ export class EventSourceTag extends Context.Tag('EventSourceTag')() {
18
+ }
19
+
20
+ //# sourceMappingURL=event-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/event-source.ts"],"sourcesContent":["import { Context } from 'effect';\n\n/**\n * The name of the slice publishing an event — `marketplace-admin`, `order`.\n *\n * A **slice**, deliberately, and not one of the two nearer alternatives. Not the\n * deployment: co-deploying two slices into one process is reversible, and a\n * `source` that changed when a process moved would rewrite history for a fact\n * that did not change. Not the domain either: a slice may hold several, so the\n * domain does not identify the publisher. The slice is ADR 0020's ownership\n * noun and is already executable in `tools/slices/`, which is what lets the\n * register be checked against what the bus actually carries.\n *\n * Provided at each composition root beside the other environment facts\n * (`TenantDatabasePrefix`, `SagaDatabaseName`) rather than read from an\n * environment variable, so a service that forgets it fails to build its layer\n * instead of publishing events signed by nobody.\n */\nexport class EventSourceTag extends Context.Tag('EventSourceTag')<\n EventSourceTag,\n string\n>() {}\n"],"names":["Context","EventSourceTag","Tag"],"mappings":"AAAA,SAASA,OAAO,QAAQ,SAAS;AAEjC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,uBAAuBD,QAAQE,GAAG,CAAC;AAG3C"}
@@ -0,0 +1,24 @@
1
+ import type { EntifixConnError, EntifixLockError } from '@entifix/core';
2
+ import { Context, type Effect } from 'effect';
3
+ /** A held lock; `token` proves ownership so release only frees our own lock. */
4
+ export interface LockHandle {
5
+ key: string;
6
+ token: string;
7
+ }
8
+ /**
9
+ * Distributed mutual exclusion — the facade's `lock`/`free` steps. Implemented
10
+ * over Redis (`SET NX PX` + bounded retry) in `@entifix/redis`.
11
+ */
12
+ export interface LockService {
13
+ /**
14
+ * Acquire `key`, retrying up to the adapter's bounded budget. Fails with
15
+ * {@link EntifixLockError} on contention (surfaced as `409`), not a `500`.
16
+ */
17
+ acquire(key: string): Effect.Effect<LockHandle, EntifixLockError>;
18
+ release(handle: LockHandle): Effect.Effect<void, EntifixConnError>;
19
+ }
20
+ declare const LockServiceTag_base: Context.TagClass<LockServiceTag, "LockServiceTag", LockService>;
21
+ export declare class LockServiceTag extends LockServiceTag_base {
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=lock-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock-service.d.ts","sourceRoot":"","sources":["../../src/ports/lock-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAClE,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;CACpE;;AAED,qBAAa,cAAe,SAAQ,mBAGjC;CAAG"}
@@ -0,0 +1,5 @@
1
+ import { Context } from 'effect';
2
+ export class LockServiceTag extends Context.Tag('LockServiceTag')() {
3
+ }
4
+
5
+ //# sourceMappingURL=lock-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/lock-service.ts"],"sourcesContent":["import type { EntifixConnError, EntifixLockError } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/** A held lock; `token` proves ownership so release only frees our own lock. */\nexport interface LockHandle {\n key: string;\n token: string;\n}\n\n/**\n * Distributed mutual exclusion — the facade's `lock`/`free` steps. Implemented\n * over Redis (`SET NX PX` + bounded retry) in `@entifix/redis`.\n */\nexport interface LockService {\n /**\n * Acquire `key`, retrying up to the adapter's bounded budget. Fails with\n * {@link EntifixLockError} on contention (surfaced as `409`), not a `500`.\n */\n acquire(key: string): Effect.Effect<LockHandle, EntifixLockError>;\n release(handle: LockHandle): Effect.Effect<void, EntifixConnError>;\n}\n\nexport class LockServiceTag extends Context.Tag('LockServiceTag')<\n LockServiceTag,\n LockService\n>() {}\n"],"names":["Context","LockServiceTag","Tag"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AAqB9C,OAAO,MAAMC,uBAAuBD,QAAQE,GAAG,CAAC;AAG3C"}
@@ -0,0 +1,47 @@
1
+ import type { EntifixConnError } from '@entifix/core';
2
+ import { Context, type Effect } from 'effect';
3
+ import type { SagaCall } from '../contracts/saga-definition.js';
4
+ /** One call the engine wants made, fully resolved. */
5
+ export interface SagaDispatch {
6
+ /** The participant's configuration key — the dispatcher resolves the address. */
7
+ readonly participant: string;
8
+ readonly call: SagaCall;
9
+ /** `<sagaId>:<stepId>[:<index>]`, which the participant claims. */
10
+ readonly commandId: string;
11
+ /**
12
+ * The organization this call acts for, when the participant is tenant-plane.
13
+ *
14
+ * Absent for a platform-plane participant. Present, it becomes ADR 0023's
15
+ * `x-organization-id` — and it is safe only because the crossing token is
16
+ * checked first, so the input the caller controls is never the input that
17
+ * authorizes.
18
+ */
19
+ readonly organizationId?: string;
20
+ readonly body?: unknown;
21
+ }
22
+ /**
23
+ * What a dispatched call answered.
24
+ *
25
+ * ⚠️ **A refusal is not a failure, and the split is the dispatcher's job.** A
26
+ * `409` from reserve is the business answer "not enough stock" and must fail the
27
+ * saga *forward* into compensation; a `503` is a participant that is down and
28
+ * the entry is retried. Collapsing the two either retries an out-of-stock line
29
+ * forever or permanently fails a checkout because a pod was restarting
30
+ * ([ADR 0052](../../../../../../docs/adr/0052-the-checkout-saga.md)).
31
+ *
32
+ * So a `refused` response is a **success** of this port carrying `ok: false`,
33
+ * and only a transport or `5xx` failure is an `EntifixConnError`.
34
+ */
35
+ export interface SagaResponse {
36
+ readonly ok: boolean;
37
+ readonly status: number;
38
+ readonly body: unknown;
39
+ }
40
+ export interface SagaDispatcher {
41
+ dispatch(dispatch: SagaDispatch): Effect.Effect<SagaResponse, EntifixConnError>;
42
+ }
43
+ declare const SagaDispatcherTag_base: Context.TagClass<SagaDispatcherTag, "SagaDispatcherTag", SagaDispatcher>;
44
+ export declare class SagaDispatcherTag extends SagaDispatcherTag_base {
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=saga-dispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saga-dispatcher.d.ts","sourceRoot":"","sources":["../../src/ports/saga-dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAEhE,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,iFAAiF;IACjF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;;;;OAOG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CACN,QAAQ,EAAE,YAAY,GACrB,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;CAClD;;AAED,qBAAa,iBAAkB,SAAQ,sBAGpC;CAAG"}
@@ -0,0 +1,5 @@
1
+ import { Context } from 'effect';
2
+ export class SagaDispatcherTag extends Context.Tag('SagaDispatcherTag')() {
3
+ }
4
+
5
+ //# sourceMappingURL=saga-dispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/saga-dispatcher.ts"],"sourcesContent":["import type { EntifixConnError } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\nimport type { SagaCall } from '../contracts/saga-definition.js';\n\n/** One call the engine wants made, fully resolved. */\nexport interface SagaDispatch {\n /** The participant's configuration key — the dispatcher resolves the address. */\n readonly participant: string;\n readonly call: SagaCall;\n /** `<sagaId>:<stepId>[:<index>]`, which the participant claims. */\n readonly commandId: string;\n /**\n * The organization this call acts for, when the participant is tenant-plane.\n *\n * Absent for a platform-plane participant. Present, it becomes ADR 0023's\n * `x-organization-id` — and it is safe only because the crossing token is\n * checked first, so the input the caller controls is never the input that\n * authorizes.\n */\n readonly organizationId?: string;\n readonly body?: unknown;\n}\n\n/**\n * What a dispatched call answered.\n *\n * ⚠️ **A refusal is not a failure, and the split is the dispatcher's job.** A\n * `409` from reserve is the business answer \"not enough stock\" and must fail the\n * saga *forward* into compensation; a `503` is a participant that is down and\n * the entry is retried. Collapsing the two either retries an out-of-stock line\n * forever or permanently fails a checkout because a pod was restarting\n * ([ADR 0052](../../../../../../docs/adr/0052-the-checkout-saga.md)).\n *\n * So a `refused` response is a **success** of this port carrying `ok: false`,\n * and only a transport or `5xx` failure is an `EntifixConnError`.\n */\nexport interface SagaResponse {\n readonly ok: boolean;\n readonly status: number;\n readonly body: unknown;\n}\n\nexport interface SagaDispatcher {\n dispatch(\n dispatch: SagaDispatch,\n ): Effect.Effect<SagaResponse, EntifixConnError>;\n}\n\nexport class SagaDispatcherTag extends Context.Tag('SagaDispatcherTag')<\n SagaDispatcherTag,\n SagaDispatcher\n>() {}\n"],"names":["Context","SagaDispatcherTag","Tag"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AAgD9C,OAAO,MAAMC,0BAA0BD,QAAQE,GAAG,CAAC;AAG9C"}