@entifix/transactions 0.14.0 → 0.15.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 (93) hide show
  1. package/README.md +6 -6
  2. package/dist/engine/index.d.ts +2 -9
  3. package/dist/engine/index.d.ts.map +1 -1
  4. package/dist/engine/index.js +3 -10
  5. package/dist/engine/index.js.map +1 -1
  6. package/dist/index.d.ts +0 -14
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +0 -14
  9. package/dist/index.js.map +1 -1
  10. package/dist/ports/participant-client.d.ts +7 -2
  11. package/dist/ports/participant-client.d.ts.map +1 -1
  12. package/dist/ports/participant-client.js.map +1 -1
  13. package/package.json +4 -4
  14. package/dist/contracts/command.d.ts +0 -59
  15. package/dist/contracts/command.d.ts.map +0 -1
  16. package/dist/contracts/command.js +0 -46
  17. package/dist/contracts/command.js.map +0 -1
  18. package/dist/contracts/event.d.ts +0 -85
  19. package/dist/contracts/event.d.ts.map +0 -1
  20. package/dist/contracts/event.js +0 -81
  21. package/dist/contracts/event.js.map +0 -1
  22. package/dist/contracts/messages.d.ts +0 -37
  23. package/dist/contracts/messages.d.ts.map +0 -1
  24. package/dist/contracts/messages.js +0 -68
  25. package/dist/contracts/messages.js.map +0 -1
  26. package/dist/contracts/record.d.ts +0 -106
  27. package/dist/contracts/record.d.ts.map +0 -1
  28. package/dist/contracts/record.js +0 -27
  29. package/dist/contracts/record.js.map +0 -1
  30. package/dist/contracts/saga-definition.d.ts +0 -181
  31. package/dist/contracts/saga-definition.d.ts.map +0 -1
  32. package/dist/contracts/saga-definition.js +0 -101
  33. package/dist/contracts/saga-definition.js.map +0 -1
  34. package/dist/engine/local-saga-dispatcher.d.ts +0 -35
  35. package/dist/engine/local-saga-dispatcher.d.ts.map +0 -1
  36. package/dist/engine/local-saga-dispatcher.js +0 -28
  37. package/dist/engine/local-saga-dispatcher.js.map +0 -1
  38. package/dist/engine/resolve-template.d.ts +0 -48
  39. package/dist/engine/resolve-template.d.ts.map +0 -1
  40. package/dist/engine/resolve-template.js +0 -95
  41. package/dist/engine/resolve-template.js.map +0 -1
  42. package/dist/engine/resume-sweep.d.ts +0 -46
  43. package/dist/engine/resume-sweep.d.ts.map +0 -1
  44. package/dist/engine/resume-sweep.js +0 -74
  45. package/dist/engine/resume-sweep.js.map +0 -1
  46. package/dist/engine/run-saga.d.ts +0 -54
  47. package/dist/engine/run-saga.d.ts.map +0 -1
  48. package/dist/engine/run-saga.js +0 -463
  49. package/dist/engine/run-saga.js.map +0 -1
  50. package/dist/engine/run-transaction.d.ts +0 -55
  51. package/dist/engine/run-transaction.d.ts.map +0 -1
  52. package/dist/engine/run-transaction.js +0 -101
  53. package/dist/engine/run-transaction.js.map +0 -1
  54. package/dist/mixins/transaction-mixins.d.ts +0 -20
  55. package/dist/mixins/transaction-mixins.d.ts.map +0 -1
  56. package/dist/mixins/transaction-mixins.js +0 -13
  57. package/dist/mixins/transaction-mixins.js.map +0 -1
  58. package/dist/ports/lock-service.d.ts +0 -24
  59. package/dist/ports/lock-service.d.ts.map +0 -1
  60. package/dist/ports/lock-service.js +0 -5
  61. package/dist/ports/lock-service.js.map +0 -1
  62. package/dist/ports/saga-dispatcher.d.ts +0 -46
  63. package/dist/ports/saga-dispatcher.d.ts.map +0 -1
  64. package/dist/ports/saga-dispatcher.js +0 -5
  65. package/dist/ports/saga-dispatcher.js.map +0 -1
  66. package/dist/ports/saga-store.d.ts +0 -96
  67. package/dist/ports/saga-store.d.ts.map +0 -1
  68. package/dist/ports/saga-store.js +0 -19
  69. package/dist/ports/saga-store.js.map +0 -1
  70. package/dist/ports/sequence-service.d.ts +0 -17
  71. package/dist/ports/sequence-service.d.ts.map +0 -1
  72. package/dist/ports/sequence-service.js +0 -5
  73. package/dist/ports/sequence-service.js.map +0 -1
  74. package/dist/ports/transaction-handler.d.ts +0 -66
  75. package/dist/ports/transaction-handler.d.ts.map +0 -1
  76. package/dist/ports/transaction-handler.js +0 -5
  77. package/dist/ports/transaction-handler.js.map +0 -1
  78. package/dist/ports/transaction-sink.d.ts +0 -120
  79. package/dist/ports/transaction-sink.d.ts.map +0 -1
  80. package/dist/ports/transaction-sink.js +0 -28
  81. package/dist/ports/transaction-sink.js.map +0 -1
  82. package/dist/ports/transaction-stream-hub.d.ts +0 -28
  83. package/dist/ports/transaction-stream-hub.d.ts.map +0 -1
  84. package/dist/ports/transaction-stream-hub.js +0 -5
  85. package/dist/ports/transaction-stream-hub.js.map +0 -1
  86. package/dist/stream/transaction-stream-hub.d.ts +0 -18
  87. package/dist/stream/transaction-stream-hub.d.ts.map +0 -1
  88. package/dist/stream/transaction-stream-hub.js +0 -50
  89. package/dist/stream/transaction-stream-hub.js.map +0 -1
  90. package/dist/use-case/facade.uc.d.ts +0 -22
  91. package/dist/use-case/facade.uc.d.ts.map +0 -1
  92. package/dist/use-case/facade.uc.js +0 -55
  93. package/dist/use-case/facade.uc.js.map +0 -1
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @entifix/transactions
2
2
 
3
- Writes that span more than one step. A client mints the transaction id, which is also the idempotency key; the event announcing a write is enqueued in an outbox inside the same database transaction as the write itself; and a flow across several services is a saga — a declarative definition, run and resumed from its own record.
3
+ Writes that span more than one step. The event announcing a write is enqueued in an outbox inside the same unit of work as the write itself, ordered per aggregate; a redelivered message is claimed once through the inbox; and a flow across several services is a composed slip run by a durable engine behind the `FlowEngineTag` port, whose participants are guarded by a circuit breaker, a bulkhead and a retry budget.
4
4
 
5
- This package holds the ports and the engine only. The storage and transport behind them come from `@entifix/mongo/transactions`, `@entifix/redis/transactions` and `@entifix/amqp/transactions`.
5
+ This package holds the ports and the in-memory resilience engines only. The storage and transport behind them come from `@entifix/mongo/transactions`, `@entifix/sql/transactions`, `@entifix/amqp/transactions` and `@entifix/workflow`.
6
6
 
7
7
  ## Install
8
8
 
@@ -12,10 +12,10 @@ pnpm add @entifix/transactions effect
12
12
 
13
13
  ## Entry points
14
14
 
15
- | Import | What it holds |
16
- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
- | `@entifix/transactions` | Command envelopes, transaction events, the unit of work, inbox / outbox / event-bus / lock / sequence / saga ports, `defineSaga`, the facade use case, `TransactionStreamHubTag` |
18
- | `@entifix/transactions/engine` | The mechanism behind those ports: `runSaga`, `resumeSaga`, `resumeStaleSagas` / `startSagaResume`, `acceptTransaction` / `completeTransaction`, `makeLocalSagaDispatcher`, the stream hub's factories |
15
+ | Import | What it holds |
16
+ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | `@entifix/transactions` | The unit of work; inbox, outbox and event-bus ports; the flow engine, participant client, circuit breaker, bulkhead and retry budget ports; flow messages and capabilities; `On` |
18
+ | `@entifix/transactions/engine` | The in-memory circuit breaker, bulkhead and retry budget, and the outbox relay and its metrics |
19
19
 
20
20
  ---
21
21
 
@@ -1,22 +1,15 @@
1
1
  /**
2
- * The mechanism behind `@entifix/transactions`' ports: the saga runner and its
3
- * resume sweep, the single-step transaction engine, the in-process dispatcher
4
- * and the stream hub.
2
+ * The mechanism behind `@entifix/transactions`' ports: the in-memory circuit
3
+ * breaker, bulkhead and retry budget, and the outbox relay and its metrics.
5
4
  *
6
5
  * A subpath rather than part of `.` although it installs nothing `.` does not,
7
6
  * because a consumer that writes against the contracts — a cell, a route, a
8
7
  * participant — must be able to ban the engine by name, and a ban matches a
9
8
  * specifier (ADR 0006).
10
9
  */
11
- export * from '../stream/transaction-stream-hub.js';
12
10
  export * from './in-memory-bulkhead.js';
13
11
  export * from './in-memory-circuit-breaker.js';
14
12
  export * from './in-memory-retry-budget.js';
15
- export * from './local-saga-dispatcher.js';
16
13
  export * from './outbox-metrics.js';
17
14
  export * from './outbox-relay.js';
18
- export * from './resolve-template.js';
19
- export * from './resume-sweep.js';
20
- export * from './run-saga.js';
21
- export * from './run-transaction.js';
22
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -1,22 +1,15 @@
1
1
  /**
2
- * The mechanism behind `@entifix/transactions`' ports: the saga runner and its
3
- * resume sweep, the single-step transaction engine, the in-process dispatcher
4
- * and the stream hub.
2
+ * The mechanism behind `@entifix/transactions`' ports: the in-memory circuit
3
+ * breaker, bulkhead and retry budget, and the outbox relay and its metrics.
5
4
  *
6
5
  * A subpath rather than part of `.` although it installs nothing `.` does not,
7
6
  * because a consumer that writes against the contracts — a cell, a route, a
8
7
  * participant — must be able to ban the engine by name, and a ban matches a
9
8
  * specifier (ADR 0006).
10
- */ export * from '../stream/transaction-stream-hub.js';
11
- export * from './in-memory-bulkhead.js';
9
+ */ export * from './in-memory-bulkhead.js';
12
10
  export * from './in-memory-circuit-breaker.js';
13
11
  export * from './in-memory-retry-budget.js';
14
- export * from './local-saga-dispatcher.js';
15
12
  export * from './outbox-metrics.js';
16
13
  export * from './outbox-relay.js';
17
- export * from './resolve-template.js';
18
- export * from './resume-sweep.js';
19
- export * from './run-saga.js';
20
- export * from './run-transaction.js';
21
14
 
22
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/engine/index.ts"],"sourcesContent":["/**\n * The mechanism behind `@entifix/transactions`' ports: the saga runner and its\n * resume sweep, the single-step transaction engine, the in-process dispatcher\n * and the stream hub.\n *\n * A subpath rather than part of `.` although it installs nothing `.` does not,\n * because a consumer that writes against the contracts — a cell, a route, a\n * participant — must be able to ban the engine by name, and a ban matches a\n * specifier (ADR 0006).\n */\nexport * from '../stream/transaction-stream-hub.js';\nexport * from './in-memory-bulkhead.js';\nexport * from './in-memory-circuit-breaker.js';\nexport * from './in-memory-retry-budget.js';\nexport * from './local-saga-dispatcher.js';\nexport * from './outbox-metrics.js';\nexport * from './outbox-relay.js';\nexport * from './resolve-template.js';\nexport * from './resume-sweep.js';\nexport * from './run-saga.js';\nexport * from './run-transaction.js';\n"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GACD,cAAc,sCAAsC;AACpD,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,6BAA6B;AAC3C,cAAc,sBAAsB;AACpC,cAAc,oBAAoB;AAClC,cAAc,wBAAwB;AACtC,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,uBAAuB"}
1
+ {"version":3,"sources":["../../src/engine/index.ts"],"sourcesContent":["/**\n * The mechanism behind `@entifix/transactions`' ports: the in-memory circuit\n * breaker, bulkhead and retry budget, and the outbox relay and its metrics.\n *\n * A subpath rather than part of `.` although it installs nothing `.` does not,\n * because a consumer that writes against the contracts — a cell, a route, a\n * participant — must be able to ban the engine by name, and a ban matches a\n * specifier (ADR 0006).\n */\nexport * from './in-memory-bulkhead.js';\nexport * from './in-memory-circuit-breaker.js';\nexport * from './in-memory-retry-budget.js';\nexport * from './outbox-metrics.js';\nexport * from './outbox-relay.js';\n"],"names":[],"mappings":"AAAA;;;;;;;;CAQC,GACD,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,sBAAsB;AACpC,cAAc,oBAAoB"}
package/dist/index.d.ts CHANGED
@@ -1,28 +1,14 @@
1
- export * from './contracts/command.js';
2
- export * from './contracts/event.js';
3
1
  export * from './contracts/flow-capability.js';
4
2
  export * from './contracts/flow-messages.js';
5
3
  export * from './contracts/inbox.js';
6
- export * from './contracts/messages.js';
7
4
  export * from './contracts/outbox.js';
8
- export * from './contracts/record.js';
9
- export * from './contracts/saga-definition.js';
10
5
  export * from './contracts/unit-of-work.js';
11
- export * from './mixins/transaction-mixins.js';
12
6
  export * from './ports/bulkhead.js';
13
7
  export * from './ports/circuit-breaker.js';
14
8
  export * from './ports/event-bus.js';
15
9
  export * from './ports/event-source.js';
16
10
  export * from './ports/flow-engine.js';
17
- export * from './ports/lock-service.js';
18
11
  export * from './ports/participant-client.js';
19
12
  export * from './ports/retry-budget.js';
20
- export * from './ports/saga-dispatcher.js';
21
- export * from './ports/saga-store.js';
22
- export * from './ports/sequence-service.js';
23
- export * from './ports/transaction-handler.js';
24
- export * from './ports/transaction-sink.js';
25
- export * from './ports/transaction-stream-hub.js';
26
13
  export * from './reactions/on.js';
27
- export * from './use-case/facade.uc.js';
28
14
  //# sourceMappingURL=index.d.ts.map
@@ -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,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,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,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,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,29 +1,15 @@
1
- export * from './contracts/command.js';
2
- export * from './contracts/event.js';
3
1
  export * from './contracts/flow-capability.js';
4
2
  export * from './contracts/flow-messages.js';
5
3
  export * from './contracts/inbox.js';
6
- export * from './contracts/messages.js';
7
4
  export * from './contracts/outbox.js';
8
- export * from './contracts/record.js';
9
- export * from './contracts/saga-definition.js';
10
5
  export * from './contracts/unit-of-work.js';
11
- export * from './mixins/transaction-mixins.js';
12
6
  export * from './ports/bulkhead.js';
13
7
  export * from './ports/circuit-breaker.js';
14
8
  export * from './ports/event-bus.js';
15
9
  export * from './ports/event-source.js';
16
10
  export * from './ports/flow-engine.js';
17
- export * from './ports/lock-service.js';
18
11
  export * from './ports/participant-client.js';
19
12
  export * from './ports/retry-budget.js';
20
- export * from './ports/saga-dispatcher.js';
21
- export * from './ports/saga-store.js';
22
- export * from './ports/sequence-service.js';
23
- export * from './ports/transaction-handler.js';
24
- export * from './ports/transaction-sink.js';
25
- export * from './ports/transaction-stream-hub.js';
26
13
  export * from './reactions/on.js';
27
- export * from './use-case/facade.uc.js';
28
14
 
29
15
  //# sourceMappingURL=index.js.map
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/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/bulkhead.js';\nexport * from './ports/circuit-breaker.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/participant-client.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,sBAAsB;AACpC,cAAc,6BAA6B;AAC3C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,gCAAgC;AAC9C,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/flow-capability.js';\nexport * from './contracts/flow-messages.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/unit-of-work.js';\nexport * from './ports/bulkhead.js';\nexport * from './ports/circuit-breaker.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/flow-engine.js';\nexport * from './ports/participant-client.js';\nexport * from './ports/retry-budget.js';\nexport * from './reactions/on.js';\n"],"names":[],"mappings":"AAAA,cAAc,iCAAiC;AAC/C,cAAc,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,sBAAsB;AACpC,cAAc,6BAA6B;AAC3C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,gCAAgC;AAC9C,cAAc,0BAA0B;AACxC,cAAc,oBAAoB"}
@@ -11,8 +11,13 @@ export interface ParticipantCall {
11
11
  * `Idempotency-Key`, stable across every redelivery and resume.
12
12
  */
13
13
  readonly idempotencyKey: string;
14
- /** What earlier steps answered, by step — the inputs a step may name. */
15
- readonly outputs: Readonly<Record<string, unknown>>;
14
+ /**
15
+ * Everything the call is given, flat: the step's pinned parameters, the keys
16
+ * it consumes as earlier steps bound them, and — for an undoing — what its
17
+ * own action answered. A path's `:name` and the request body read this and
18
+ * nothing else.
19
+ */
20
+ readonly inputs: Readonly<Record<string, unknown>>;
16
21
  }
17
22
  /**
18
23
  * How a flow reaches its participants
@@ -1 +1 @@
1
- {"version":3,"file":"participant-client.d.ts","sourceRoot":"","sources":["../../src/ports/participant-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,CACb,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;CAC7C;;AAED,qBAAa,oBAAqB,SAAQ,yBAGI;CAAG"}
1
+ {"version":3,"file":"participant-client.d.ts","sourceRoot":"","sources":["../../src/ports/participant-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,CACb,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;CAC7C;;AAED,qBAAa,oBAAqB,SAAQ,yBAGI;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ports/participant-client.ts"],"sourcesContent":["import type { SlipStep } from '@entifix/business/flow';\nimport type { EntifixFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/** One call a flow makes to a participant, for a step or for its undoing. */\nexport interface ParticipantCall {\n readonly step: SlipStep;\n /** `action` runs the step's call, `compensation` the call that undoes it. */\n readonly kind: 'action' | 'compensation';\n /**\n * `<flowId>:<step>`, with `:compensation` for an undoing — the participant's\n * `Idempotency-Key`, stable across every redelivery and resume.\n */\n readonly idempotencyKey: string;\n /** What earlier steps answered, by step — the inputs a step may name. */\n readonly outputs: Readonly<Record<string, unknown>>;\n}\n\n/**\n * How a flow reaches its participants\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n * The interpreter calls this and nothing else, so the transport — HTTP with a\n * crossing token, or an in-process double — is the composition root's choice.\n * A refusal is the participant's typed failure; anything that kept the call\n * from being answered is a technical one.\n */\nexport interface ParticipantClient {\n readonly call: (\n request: ParticipantCall,\n ) => Effect.Effect<unknown, EntifixFailure>;\n}\n\nexport class ParticipantClientTag extends Context.Service<\n ParticipantClientTag,\n ParticipantClient\n>()('@entifix/transactions/ParticipantClient') {}\n"],"names":["Context","ParticipantClientTag","Service"],"mappings":"AAEA,SAASA,OAAO,QAAqB,SAAS;AA8B9C,OAAO,MAAMC,6BAA6BD,QAAQE,OAAO,GAGrD;AAA4C"}
1
+ {"version":3,"sources":["../../src/ports/participant-client.ts"],"sourcesContent":["import type { SlipStep } from '@entifix/business/flow';\nimport type { EntifixFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/** One call a flow makes to a participant, for a step or for its undoing. */\nexport interface ParticipantCall {\n readonly step: SlipStep;\n /** `action` runs the step's call, `compensation` the call that undoes it. */\n readonly kind: 'action' | 'compensation';\n /**\n * `<flowId>:<step>`, with `:compensation` for an undoing — the participant's\n * `Idempotency-Key`, stable across every redelivery and resume.\n */\n readonly idempotencyKey: string;\n /**\n * Everything the call is given, flat: the step's pinned parameters, the keys\n * it consumes as earlier steps bound them, and — for an undoing — what its\n * own action answered. A path's `:name` and the request body read this and\n * nothing else.\n */\n readonly inputs: Readonly<Record<string, unknown>>;\n}\n\n/**\n * How a flow reaches its participants\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n * The interpreter calls this and nothing else, so the transport — HTTP with a\n * crossing token, or an in-process double — is the composition root's choice.\n * A refusal is the participant's typed failure; anything that kept the call\n * from being answered is a technical one.\n */\nexport interface ParticipantClient {\n readonly call: (\n request: ParticipantCall,\n ) => Effect.Effect<unknown, EntifixFailure>;\n}\n\nexport class ParticipantClientTag extends Context.Service<\n ParticipantClientTag,\n ParticipantClient\n>()('@entifix/transactions/ParticipantClient') {}\n"],"names":["Context","ParticipantClientTag","Service"],"mappings":"AAEA,SAASA,OAAO,QAAqB,SAAS;AAmC9C,OAAO,MAAMC,6BAA6BD,QAAQE,OAAO,GAGrD;AAA4C"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@entifix/transactions",
3
- "version": "0.14.0",
4
- "description": "Commands, transactions and sagas: inbox and outbox ports, an event bus, locks, and a declarative saga runner.",
3
+ "version": "0.15.0",
4
+ "description": "Units of work, inbox and outbox ports, an event bus, and the flow engine and resilience ports a durable flow runs on.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -56,8 +56,8 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@swc/helpers": "0.5.23",
59
- "@entifix/core": "0.14.0",
60
- "@entifix/business": "0.14.0"
59
+ "@entifix/business": "0.15.0",
60
+ "@entifix/core": "0.15.0"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "effect": "^4.0.7"
@@ -1,59 +0,0 @@
1
- import './messages.js';
2
- import { type EntifixEnvelope, InvalidEnvelope, type SerializedEntity } from '@entifix/core';
3
- import { Effect } from 'effect';
4
- /**
5
- * A write intent in CQRS terms. A client no longer mutates directly — it issues
6
- * a command, the service runs the transaction facade over it, and answers with a
7
- * transaction id. `payload` is a serialized entity (the same wire shape the
8
- * entity envelopes carry), so a command round-trips through the existing
9
- * (de)serializer.
10
- */
11
- export interface TransactionCommand<TPayload = SerializedEntity> {
12
- /**
13
- * Correlates every event and record for this run, and **the client mints it**.
14
- *
15
- * It is also the stored entity's id and the idempotency key: re-sending a
16
- * command with the same id returns the first one's answer instead of writing
17
- * twice. That makes it untrusted input which becomes a primary key, so
18
- * {@link readCommandEnvelope} constrains it to a UUID rather than accepting
19
- * any string.
20
- */
21
- transactionId: string;
22
- /** What to do — only `create` in phase 1. */
23
- type: 'create';
24
- /** The target entity's `key` (e.g. `product`), the routing/lock subject. */
25
- entity: string;
26
- /** The serialized entity to act on. */
27
- payload: TPayload;
28
- /**
29
- * Whose organization this command acts in — **stamped by the route from the
30
- * verified token, never read from the wire**.
31
- *
32
- * {@link readCommandEnvelope} drops whatever a caller sent under this name, so
33
- * a client cannot name another tenant by writing one into the body. It is the
34
- * same rule the id already follows (`entity.id = params.id`), and the same
35
- * rule the organization guard states: the organization comes from the token and
36
- * nowhere else.
37
- *
38
- * Optional because the parser produces a command without it and the route
39
- * fills it in a moment later. A command that reaches the engine still carrying
40
- * `undefined` emits events that no tenant-scoped stream connection receives —
41
- * which is the intended direction to fail.
42
- */
43
- organizationId?: string;
44
- }
45
- export type CommandEnvelope<TPayload = SerializedEntity> = EntifixEnvelope<TransactionCommand<TPayload>>;
46
- /** Frames a command as a transport-free `command` envelope. */
47
- export declare function makeCommandEnvelope<TPayload = SerializedEntity>(command: TransactionCommand<TPayload>): CommandEnvelope<TPayload>;
48
- /** Whether a value is a usable transaction id. */
49
- export declare const isTransactionId: (value: unknown) => value is string;
50
- /**
51
- * Parses a `command` envelope, failing on a wrong shape/type.
52
- *
53
- * A command carrying no valid transaction id is rejected outright — there is no
54
- * server-side fallback that mints one. That is deliberate: the id is the
55
- * idempotency key, and a caller who omits it silently loses retry safety while
56
- * appearing to succeed.
57
- */
58
- export declare function readCommandEnvelope<TPayload = SerializedEntity>(body: unknown): Effect.Effect<TransactionCommand<TPayload>, InvalidEnvelope>;
59
- //# sourceMappingURL=command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/contracts/command.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAEL,KAAK,eAAe,EACpB,eAAe,EAEf,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB,CAAC,QAAQ,GAAG,gBAAgB;IAC7D;;;;;;;;OAQG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,IAAI,EAAE,QAAQ,CAAC;IACf,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,OAAO,EAAE,QAAQ,CAAC;IAClB;;;;;;;;;;;;;;OAcG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,eAAe,CAAC,QAAQ,GAAG,gBAAgB,IAAI,eAAe,CACxE,kBAAkB,CAAC,QAAQ,CAAC,CAC7B,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,mBAAmB,CAAC,QAAQ,GAAG,gBAAgB,EAC7D,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GACpC,eAAe,CAAC,QAAQ,CAAC,CAE3B;AAaD,kDAAkD;AAClD,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACX,CAAC;AAEhD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,GAAG,gBAAgB,EAC7D,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC,CAmB9D"}
@@ -1,46 +0,0 @@
1
- import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
2
- // Evaluated for its registrations: this reader decodes against them.
3
- import './messages.js';
4
- import { decodeRequestEnvelope, InvalidEnvelope, makeEnvelope } from '@entifix/core';
5
- import { Effect } from 'effect';
6
- /** Frames a command as a transport-free `command` envelope. */ export function makeCommandEnvelope(command) {
7
- return makeEnvelope('command', command.entity, command);
8
- }
9
- /**
10
- * A canonical RFC 9562 UUID — any version, standard variant.
11
- *
12
- * The transaction id arrives from the client and becomes a primary key, so the
13
- * key space it may address has to be fixed rather than "whatever string was
14
- * sent". Accepting every version keeps v4 (random) and v7 (time-ordered) both
15
- * usable without the wire format becoming a second decision.
16
- */ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
17
- /** Whether a value is a usable transaction id. */ export const isTransactionId = (value)=>typeof value === 'string' && UUID.test(value);
18
- /**
19
- * Parses a `command` envelope, failing on a wrong shape/type.
20
- *
21
- * A command carrying no valid transaction id is rejected outright — there is no
22
- * server-side fallback that mints one. That is deliberate: the id is the
23
- * idempotency key, and a caller who omits it silently loses retry safety while
24
- * appearing to succeed.
25
- */ export function readCommandEnvelope(body) {
26
- return Effect.gen(function*() {
27
- const envelope = yield* decodeRequestEnvelope(body, 'command', 'command');
28
- const command = envelope.data;
29
- // The registered schema already proved the frame; what it cannot say is
30
- // that the id is a UUID, which is what makes it safe as a primary key.
31
- if (!isTransactionId(command.transactionId)) {
32
- return yield* Effect.fail(new InvalidEnvelope({
33
- reason: 'command envelope carried no valid command'
34
- }));
35
- }
36
- // `organizationId` is deliberately **not** carried over from the parsed
37
- // body. Spreading the caller's object here would let a request name another
38
- // tenant, which is precisely the scoping the stream depends on.
39
- const { organizationId: _ignored } = command, trusted = _object_without_properties_loose(command, [
40
- "organizationId"
41
- ]);
42
- return trusted;
43
- });
44
- }
45
-
46
- //# sourceMappingURL=command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/contracts/command.ts"],"sourcesContent":["// Evaluated for its registrations: this reader decodes against them.\nimport './messages.js';\n\nimport {\n decodeRequestEnvelope,\n type EntifixEnvelope,\n InvalidEnvelope,\n makeEnvelope,\n type SerializedEntity,\n} from '@entifix/core';\nimport { Effect } from 'effect';\n\n/**\n * A write intent in CQRS terms. A client no longer mutates directly — it issues\n * a command, the service runs the transaction facade over it, and answers with a\n * transaction id. `payload` is a serialized entity (the same wire shape the\n * entity envelopes carry), so a command round-trips through the existing\n * (de)serializer.\n */\nexport interface TransactionCommand<TPayload = SerializedEntity> {\n /**\n * Correlates every event and record for this run, and **the client mints it**.\n *\n * It is also the stored entity's id and the idempotency key: re-sending a\n * command with the same id returns the first one's answer instead of writing\n * twice. That makes it untrusted input which becomes a primary key, so\n * {@link readCommandEnvelope} constrains it to a UUID rather than accepting\n * any string.\n */\n transactionId: string;\n /** What to do — only `create` in phase 1. */\n type: 'create';\n /** The target entity's `key` (e.g. `product`), the routing/lock subject. */\n entity: string;\n /** The serialized entity to act on. */\n payload: TPayload;\n /**\n * Whose organization this command acts in — **stamped by the route from the\n * verified token, never read from the wire**.\n *\n * {@link readCommandEnvelope} drops whatever a caller sent under this name, so\n * a client cannot name another tenant by writing one into the body. It is the\n * same rule the id already follows (`entity.id = params.id`), and the same\n * rule the organization guard states: the organization comes from the token and\n * nowhere else.\n *\n * Optional because the parser produces a command without it and the route\n * fills it in a moment later. A command that reaches the engine still carrying\n * `undefined` emits events that no tenant-scoped stream connection receives —\n * which is the intended direction to fail.\n */\n organizationId?: string;\n}\n\nexport type CommandEnvelope<TPayload = SerializedEntity> = EntifixEnvelope<\n TransactionCommand<TPayload>\n>;\n\n/** Frames a command as a transport-free `command` envelope. */\nexport function makeCommandEnvelope<TPayload = SerializedEntity>(\n command: TransactionCommand<TPayload>,\n): CommandEnvelope<TPayload> {\n return makeEnvelope('command', command.entity, command);\n}\n\n/**\n * A canonical RFC 9562 UUID — any version, standard variant.\n *\n * The transaction id arrives from the client and becomes a primary key, so the\n * key space it may address has to be fixed rather than \"whatever string was\n * sent\". Accepting every version keeps v4 (random) and v7 (time-ordered) both\n * usable without the wire format becoming a second decision.\n */\nconst UUID =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\n/** Whether a value is a usable transaction id. */\nexport const isTransactionId = (value: unknown): value is string =>\n typeof value === 'string' && UUID.test(value);\n\n/**\n * Parses a `command` envelope, failing on a wrong shape/type.\n *\n * A command carrying no valid transaction id is rejected outright — there is no\n * server-side fallback that mints one. That is deliberate: the id is the\n * idempotency key, and a caller who omits it silently loses retry safety while\n * appearing to succeed.\n */\nexport function readCommandEnvelope<TPayload = SerializedEntity>(\n body: unknown,\n): Effect.Effect<TransactionCommand<TPayload>, InvalidEnvelope> {\n return Effect.gen(function* () {\n const envelope = yield* decodeRequestEnvelope(body, 'command', 'command');\n const command = envelope.data as TransactionCommand<TPayload>;\n // The registered schema already proved the frame; what it cannot say is\n // that the id is a UUID, which is what makes it safe as a primary key.\n if (!isTransactionId(command.transactionId)) {\n return yield* Effect.fail(\n new InvalidEnvelope({\n reason: 'command envelope carried no valid command',\n }),\n );\n }\n // `organizationId` is deliberately **not** carried over from the parsed\n // body. Spreading the caller's object here would let a request name another\n // tenant, which is precisely the scoping the stream depends on.\n const { organizationId: _ignored, ...trusted } = command;\n return trusted as TransactionCommand<TPayload>;\n });\n}\n"],"names":["decodeRequestEnvelope","InvalidEnvelope","makeEnvelope","Effect","makeCommandEnvelope","command","entity","UUID","isTransactionId","value","test","readCommandEnvelope","body","gen","envelope","data","transactionId","fail","reason","organizationId","_ignored","trusted"],"mappings":";AAAA,qEAAqE;AACrE,OAAO,gBAAgB;AAEvB,SACEA,qBAAqB,EAErBC,eAAe,EACfC,YAAY,QAEP,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAgDhC,6DAA6D,GAC7D,OAAO,SAASC,oBACdC,OAAqC;IAErC,OAAOH,aAAa,WAAWG,QAAQC,MAAM,EAAED;AACjD;AAEA;;;;;;;CAOC,GACD,MAAME,OACJ;AAEF,gDAAgD,GAChD,OAAO,MAAMC,kBAAkB,CAACC,QAC9B,OAAOA,UAAU,YAAYF,KAAKG,IAAI,CAACD,OAAO;AAEhD;;;;;;;CAOC,GACD,OAAO,SAASE,oBACdC,IAAa;IAEb,OAAOT,OAAOU,GAAG,CAAC;QAChB,MAAMC,WAAW,OAAOd,sBAAsBY,MAAM,WAAW;QAC/D,MAAMP,UAAUS,SAASC,IAAI;QAC7B,wEAAwE;QACxE,uEAAuE;QACvE,IAAI,CAACP,gBAAgBH,QAAQW,aAAa,GAAG;YAC3C,OAAO,OAAOb,OAAOc,IAAI,CACvB,IAAIhB,gBAAgB;gBAClBiB,QAAQ;YACV;QAEJ;QACA,wEAAwE;QACxE,4EAA4E;QAC5E,gEAAgE;QAChE,MAAM,EAAEC,gBAAgBC,QAAQ,EAAc,GAAGf,SAAZgB,2CAAYhB;;;QACjD,OAAOgB;IACT;AACF"}
@@ -1,85 +0,0 @@
1
- import { type EntifixEnvelope, type EntityId } from '@entifix/core';
2
- import type { TransactionOutcome } from '../ports/transaction-handler.js';
3
- import type { TransactionCommand } from './command.js';
4
- import type { OutboxEvent } from './outbox.js';
5
- /**
6
- * The lifecycle states a transaction record settles into.
7
- *
8
- * A const array rather than a bare union because something has to **enumerate**
9
- * them: a by-state gauge must report every state including the ones at zero, and
10
- * a series that simply stops being reported reads on most dashboards as "no
11
- * data" rather than as "none" — so `STALE` falling to zero would look exactly
12
- * like the metric having broken.
13
- *
14
- * Note there are four states but only three {@link TransactionStep}s: `STALE` is
15
- * applied by the recovery sweep and has no event of its own.
16
- */
17
- export declare const TRANSACTION_STATES: readonly ["PENDING", "COMPLETED", "FAILED", "STALE"];
18
- /** The lifecycle state a transaction record settles into. */
19
- export type TransactionState = (typeof TRANSACTION_STATES)[number];
20
- /** The facade step a given event reports. */
21
- export type TransactionStep = 'accepted' | 'completed' | 'failed';
22
- /**
23
- * What a service reports as its transaction progresses — the **payload** of a
24
- * {@link DomainEvent}, not the message itself. The saga tracker is a passive
25
- * consumer of these: for a single-step write it dispatches nothing and only
26
- * records what the events tell it, which is what keeps such a write
27
- * choreographed. A flow spanning slices is orchestrated instead, from a
28
- * declarative definition, and its coordinator both reads these and
29
- * issues the next step — but that engine is not built, and single-step writes
30
- * stay exactly as described here when it is.
31
- *
32
- * `transactionId` and `at` are also reachable as the message's `correlationId`
33
- * and `at`. That duplication is deliberate and standard (CloudEvents' `subject`
34
- * does the same): metadata is what the *transport* routes and deduplicates on,
35
- * and the payload has to stand on its own for a consumer that has already
36
- * unwrapped it.
37
- */
38
- export interface TransactionEvent {
39
- transactionId: string;
40
- /** The target entity's `key`. */
41
- entity: string;
42
- state: TransactionState;
43
- step: TransactionStep;
44
- /** The assigned code once executed (`product-001`). */
45
- code?: string;
46
- /** The stored entity id once executed. */
47
- entityId?: EntityId;
48
- /** Failure detail when `step === 'failed'`. */
49
- error?: string;
50
- /** ISO-8601 emission time. */
51
- at: string;
52
- /**
53
- * Whose organization this happened in — the per-connection scoping key for
54
- * the reactive stream.
55
- *
56
- * In `data` rather than in `meta`, under the envelope's rule: `meta` describes the
57
- * message, `data` describes the occurrence, and which vendor's catalog a
58
- * record was written in is a fact about what happened.
59
- *
60
- * **Optional, and absence is not a wildcard.** An event carrying no
61
- * organization is delivered to no tenant-scoped connection. Defaulting the
62
- * other way would make every event emitted before this member existed a
63
- * cross-tenant delivery, and it fails silently in the direction that matters.
64
- */
65
- organizationId?: string;
66
- }
67
- /** The register's name for a transaction message: `transaction.completed`. */
68
- export declare const transactionEventName: (step: TransactionStep) => string;
69
- /**
70
- * The message id for one step of one transaction — and therefore the
71
- * deduplication key.
72
- *
73
- * It is the transaction id **and** the step, never the transaction id alone.
74
- * One transaction emits up to three messages, so a consumer keying on the
75
- * transaction id would treat `completed` as a redelivery of `accepted` and drop
76
- * the outcome. The outbox's unique index is on exactly this value, which is what
77
- * keeps the idempotency claim and the dedup key the same fact rather than two
78
- * that can drift.
79
- */
80
- export declare const transactionEventId: (transactionId: string, step: TransactionStep) => string;
81
- export declare const acceptedEvent: (command: TransactionCommand, source: string) => OutboxEvent<TransactionEvent>;
82
- export declare const completedEvent: (command: TransactionCommand, outcome: TransactionOutcome, source: string) => OutboxEvent<TransactionEvent>;
83
- export declare const failedEvent: (command: TransactionCommand, error: unknown, source: string) => OutboxEvent<TransactionEvent>;
84
- export type TransactionEventEnvelope = EntifixEnvelope<TransactionEvent>;
85
- //# sourceMappingURL=event.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/contracts/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,QAAQ,EAEd,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,sDAKrB,CAAC;AAEX,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,eAAe,CAAC;IACtB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAID,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,GAAI,MAAM,eAAe,KAAG,MACtC,CAAC;AAExB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAC7B,eAAe,MAAM,EACrB,MAAM,eAAe,KACpB,MAAoC,CAAC;AA2BxC,eAAO,MAAM,aAAa,GACxB,SAAS,kBAAkB,EAC3B,QAAQ,MAAM,KACb,WAAW,CAAC,gBAAgB,CAQ3B,CAAC;AAEL,eAAO,MAAM,cAAc,GACzB,SAAS,kBAAkB,EAC3B,SAAS,kBAAkB,EAC3B,QAAQ,MAAM,KACb,WAAW,CAAC,gBAAgB,CAU3B,CAAC;AAEL,eAAO,MAAM,WAAW,GACtB,SAAS,kBAAkB,EAC3B,OAAO,OAAO,EACd,QAAQ,MAAM,KACb,WAAW,CAAC,gBAAgB,CAS3B,CAAC;AAEL,MAAM,MAAM,wBAAwB,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
@@ -1,81 +0,0 @@
1
- import { messageOf } from '@entifix/core';
2
- /**
3
- * The lifecycle states a transaction record settles into.
4
- *
5
- * A const array rather than a bare union because something has to **enumerate**
6
- * them: a by-state gauge must report every state including the ones at zero, and
7
- * a series that simply stops being reported reads on most dashboards as "no
8
- * data" rather than as "none" — so `STALE` falling to zero would look exactly
9
- * like the metric having broken.
10
- *
11
- * Note there are four states but only three {@link TransactionStep}s: `STALE` is
12
- * applied by the recovery sweep and has no event of its own.
13
- */ export const TRANSACTION_STATES = [
14
- 'PENDING',
15
- 'COMPLETED',
16
- 'FAILED',
17
- 'STALE'
18
- ];
19
- const now = ()=>new Date().toISOString();
20
- /** The register's name for a transaction message: `transaction.completed`. */ export const transactionEventName = (step)=>`transaction.${step}`;
21
- /**
22
- * The message id for one step of one transaction — and therefore the
23
- * deduplication key.
24
- *
25
- * It is the transaction id **and** the step, never the transaction id alone.
26
- * One transaction emits up to three messages, so a consumer keying on the
27
- * transaction id would treat `completed` as a redelivery of `accepted` and drop
28
- * the outcome. The outbox's unique index is on exactly this value, which is what
29
- * keeps the idempotency claim and the dedup key the same fact rather than two
30
- * that can drift.
31
- */ export const transactionEventId = (transactionId, step)=>`${transactionId}:${step}`;
32
- /** Each step's version of its transaction: `accepted` first, then its end. */ const STEP_VERSION = {
33
- accepted: 0,
34
- completed: 1,
35
- failed: 1
36
- };
37
- /**
38
- * Wraps a payload as a routable message from `source`. The transaction is the
39
- * aggregate, so the outbox keeps `accepted` ahead of the step that ends it.
40
- */ const message = (source, data)=>({
41
- name: transactionEventName(data.step),
42
- id: transactionEventId(data.transactionId, data.step),
43
- source,
44
- at: data.at,
45
- correlationId: data.transactionId,
46
- aggregate: {
47
- type: 'transaction',
48
- id: data.transactionId
49
- },
50
- version: STEP_VERSION[data.step],
51
- data
52
- });
53
- export const acceptedEvent = (command, source)=>message(source, {
54
- transactionId: command.transactionId,
55
- entity: command.entity,
56
- state: 'PENDING',
57
- step: 'accepted',
58
- at: now(),
59
- organizationId: command.organizationId
60
- });
61
- export const completedEvent = (command, outcome, source)=>message(source, {
62
- transactionId: command.transactionId,
63
- entity: command.entity,
64
- state: 'COMPLETED',
65
- step: 'completed',
66
- code: outcome.code,
67
- entityId: outcome.entityId,
68
- at: now(),
69
- organizationId: command.organizationId
70
- });
71
- export const failedEvent = (command, error, source)=>message(source, {
72
- transactionId: command.transactionId,
73
- entity: command.entity,
74
- state: 'FAILED',
75
- step: 'failed',
76
- error: messageOf(error),
77
- at: now(),
78
- organizationId: command.organizationId
79
- });
80
-
81
- //# sourceMappingURL=event.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/contracts/event.ts"],"sourcesContent":["import {\n type DomainEvent,\n type EntifixEnvelope,\n type EntityId,\n messageOf,\n} from '@entifix/core';\n\nimport type { TransactionOutcome } from '../ports/transaction-handler.js';\nimport type { TransactionCommand } from './command.js';\nimport type { OutboxEvent } from './outbox.js';\n\n/**\n * The lifecycle states a transaction record settles into.\n *\n * A const array rather than a bare union because something has to **enumerate**\n * them: a by-state gauge must report every state including the ones at zero, and\n * a series that simply stops being reported reads on most dashboards as \"no\n * data\" rather than as \"none\" — so `STALE` falling to zero would look exactly\n * like the metric having broken.\n *\n * Note there are four states but only three {@link TransactionStep}s: `STALE` is\n * applied by the recovery sweep and has no event of its own.\n */\nexport const TRANSACTION_STATES = [\n 'PENDING',\n 'COMPLETED',\n 'FAILED',\n 'STALE',\n] as const;\n\n/** The lifecycle state a transaction record settles into. */\nexport type TransactionState = (typeof TRANSACTION_STATES)[number];\n\n/** The facade step a given event reports. */\nexport type TransactionStep = 'accepted' | 'completed' | 'failed';\n\n/**\n * What a service reports as its transaction progresses — the **payload** of a\n * {@link DomainEvent}, not the message itself. The saga tracker is a passive\n * consumer of these: for a single-step write it dispatches nothing and only\n * records what the events tell it, which is what keeps such a write\n * choreographed. A flow spanning slices is orchestrated instead, from a\n * declarative definition, and its coordinator both reads these and\n * issues the next step — but that engine is not built, and single-step writes\n * stay exactly as described here when it is.\n *\n * `transactionId` and `at` are also reachable as the message's `correlationId`\n * and `at`. That duplication is deliberate and standard (CloudEvents' `subject`\n * does the same): metadata is what the *transport* routes and deduplicates on,\n * and the payload has to stand on its own for a consumer that has already\n * unwrapped it.\n */\nexport interface TransactionEvent {\n transactionId: string;\n /** The target entity's `key`. */\n entity: string;\n state: TransactionState;\n step: TransactionStep;\n /** The assigned code once executed (`product-001`). */\n code?: string;\n /** The stored entity id once executed. */\n entityId?: EntityId;\n /** Failure detail when `step === 'failed'`. */\n error?: string;\n /** ISO-8601 emission time. */\n at: string;\n /**\n * Whose organization this happened in — the per-connection scoping key for\n * the reactive stream.\n *\n * In `data` rather than in `meta`, under the envelope's rule: `meta` describes the\n * message, `data` describes the occurrence, and which vendor's catalog a\n * record was written in is a fact about what happened.\n *\n * **Optional, and absence is not a wildcard.** An event carrying no\n * organization is delivered to no tenant-scoped connection. Defaulting the\n * other way would make every event emitted before this member existed a\n * cross-tenant delivery, and it fails silently in the direction that matters.\n */\n organizationId?: string;\n}\n\nconst now = (): string => new Date().toISOString();\n\n/** The register's name for a transaction message: `transaction.completed`. */\nexport const transactionEventName = (step: TransactionStep): string =>\n `transaction.${step}`;\n\n/**\n * The message id for one step of one transaction — and therefore the\n * deduplication key.\n *\n * It is the transaction id **and** the step, never the transaction id alone.\n * One transaction emits up to three messages, so a consumer keying on the\n * transaction id would treat `completed` as a redelivery of `accepted` and drop\n * the outcome. The outbox's unique index is on exactly this value, which is what\n * keeps the idempotency claim and the dedup key the same fact rather than two\n * that can drift.\n */\nexport const transactionEventId = (\n transactionId: string,\n step: TransactionStep,\n): string => `${transactionId}:${step}`;\n\n/** Each step's version of its transaction: `accepted` first, then its end. */\nconst STEP_VERSION: Record<TransactionStep, number> = {\n accepted: 0,\n completed: 1,\n failed: 1,\n};\n\n/**\n * Wraps a payload as a routable message from `source`. The transaction is the\n * aggregate, so the outbox keeps `accepted` ahead of the step that ends it.\n */\nconst message = (\n source: string,\n data: TransactionEvent,\n): OutboxEvent<TransactionEvent> => ({\n name: transactionEventName(data.step),\n id: transactionEventId(data.transactionId, data.step),\n source,\n at: data.at,\n correlationId: data.transactionId,\n aggregate: { type: 'transaction', id: data.transactionId },\n version: STEP_VERSION[data.step],\n data,\n});\n\nexport const acceptedEvent = (\n command: TransactionCommand,\n source: string,\n): OutboxEvent<TransactionEvent> =>\n message(source, {\n transactionId: command.transactionId,\n entity: command.entity,\n state: 'PENDING',\n step: 'accepted',\n at: now(),\n organizationId: command.organizationId,\n });\n\nexport const completedEvent = (\n command: TransactionCommand,\n outcome: TransactionOutcome,\n source: string,\n): OutboxEvent<TransactionEvent> =>\n message(source, {\n transactionId: command.transactionId,\n entity: command.entity,\n state: 'COMPLETED',\n step: 'completed',\n code: outcome.code,\n entityId: outcome.entityId,\n at: now(),\n organizationId: command.organizationId,\n });\n\nexport const failedEvent = (\n command: TransactionCommand,\n error: unknown,\n source: string,\n): OutboxEvent<TransactionEvent> =>\n message(source, {\n transactionId: command.transactionId,\n entity: command.entity,\n state: 'FAILED',\n step: 'failed',\n error: messageOf(error),\n at: now(),\n organizationId: command.organizationId,\n });\n\nexport type TransactionEventEnvelope = EntifixEnvelope<TransactionEvent>;\n"],"names":["messageOf","TRANSACTION_STATES","now","Date","toISOString","transactionEventName","step","transactionEventId","transactionId","STEP_VERSION","accepted","completed","failed","message","source","data","name","id","at","correlationId","aggregate","type","version","acceptedEvent","command","entity","state","organizationId","completedEvent","outcome","code","entityId","failedEvent","error"],"mappings":"AAAA,SAIEA,SAAS,QACJ,gBAAgB;AAMvB;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,qBAAqB;IAChC;IACA;IACA;IACA;CACD,CAAU;AAsDX,MAAMC,MAAM,IAAc,IAAIC,OAAOC,WAAW;AAEhD,4EAA4E,GAC5E,OAAO,MAAMC,uBAAuB,CAACC,OACnC,CAAC,YAAY,EAAEA,MAAM,CAAC;AAExB;;;;;;;;;;CAUC,GACD,OAAO,MAAMC,qBAAqB,CAChCC,eACAF,OACW,GAAGE,cAAc,CAAC,EAAEF,MAAM,CAAC;AAExC,4EAA4E,GAC5E,MAAMG,eAAgD;IACpDC,UAAU;IACVC,WAAW;IACXC,QAAQ;AACV;AAEA;;;CAGC,GACD,MAAMC,UAAU,CACdC,QACAC,OACmC,CAAA;QACnCC,MAAMX,qBAAqBU,KAAKT,IAAI;QACpCW,IAAIV,mBAAmBQ,KAAKP,aAAa,EAAEO,KAAKT,IAAI;QACpDQ;QACAI,IAAIH,KAAKG,EAAE;QACXC,eAAeJ,KAAKP,aAAa;QACjCY,WAAW;YAAEC,MAAM;YAAeJ,IAAIF,KAAKP,aAAa;QAAC;QACzDc,SAASb,YAAY,CAACM,KAAKT,IAAI,CAAC;QAChCS;IACF,CAAA;AAEA,OAAO,MAAMQ,gBAAgB,CAC3BC,SACAV,SAEAD,QAAQC,QAAQ;QACdN,eAAegB,QAAQhB,aAAa;QACpCiB,QAAQD,QAAQC,MAAM;QACtBC,OAAO;QACPpB,MAAM;QACNY,IAAIhB;QACJyB,gBAAgBH,QAAQG,cAAc;IACxC,GAAG;AAEL,OAAO,MAAMC,iBAAiB,CAC5BJ,SACAK,SACAf,SAEAD,QAAQC,QAAQ;QACdN,eAAegB,QAAQhB,aAAa;QACpCiB,QAAQD,QAAQC,MAAM;QACtBC,OAAO;QACPpB,MAAM;QACNwB,MAAMD,QAAQC,IAAI;QAClBC,UAAUF,QAAQE,QAAQ;QAC1Bb,IAAIhB;QACJyB,gBAAgBH,QAAQG,cAAc;IACxC,GAAG;AAEL,OAAO,MAAMK,cAAc,CACzBR,SACAS,OACAnB,SAEAD,QAAQC,QAAQ;QACdN,eAAegB,QAAQhB,aAAa;QACpCiB,QAAQD,QAAQC,MAAM;QACtBC,OAAO;QACPpB,MAAM;QACN2B,OAAOjC,UAAUiC;QACjBf,IAAIhB;QACJyB,gBAAgBH,QAAQG,cAAc;IACxC,GAAG"}
@@ -1,37 +0,0 @@
1
- import { Schema } from 'effect';
2
- export declare const TransactionCommandSchema: Schema.StructWithRest<Schema.Struct<{
3
- transactionId: Schema.String;
4
- type: Schema.String;
5
- entity: Schema.String;
6
- payload: Schema.Unknown;
7
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
8
- export declare const TransactionAcceptedSchema: Schema.StructWithRest<Schema.Struct<{
9
- transactionId: Schema.String;
10
- state: Schema.Literals<readonly ["PENDING", "COMPLETED", "FAILED", "STALE"]>;
11
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
12
- export declare const TransactionRecordSchema: Schema.StructWithRest<Schema.Struct<{
13
- transactionId: Schema.String;
14
- entity: Schema.String;
15
- state: Schema.Literals<readonly ["PENDING", "COMPLETED", "FAILED", "STALE"]>;
16
- createdAt: Schema.String;
17
- updatedAt: Schema.String;
18
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
19
- export declare const SagaResultSchema: Schema.StructWithRest<Schema.Struct<{
20
- state: Schema.String;
21
- outcomes: Schema.$Array<Schema.Unknown>;
22
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
23
- export declare const SagaInstanceSchema: Schema.StructWithRest<Schema.Struct<{
24
- sagaId: Schema.String;
25
- definition: Schema.String;
26
- state: Schema.String;
27
- stepIndex: Schema.Number;
28
- outcomes: Schema.$Array<Schema.Unknown>;
29
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
30
- export declare const TransactionEventSchema: Schema.StructWithRest<Schema.Struct<{
31
- transactionId: Schema.String;
32
- entity: Schema.String;
33
- state: Schema.Literals<readonly ["PENDING", "COMPLETED", "FAILED", "STALE"]>;
34
- step: Schema.Literals<readonly ["accepted", "completed", "failed"]>;
35
- at: Schema.String;
36
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
37
- //# sourceMappingURL=messages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/contracts/messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAehC,eAAO,MAAM,wBAAwB;;;;;6DAKnC,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;6DAGpC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;6DAMlC,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;6DAG3B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;6DAM7B,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;6DAMjC,CAAC"}