@entifix/transactions 0.13.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 (100) hide show
  1. package/README.md +6 -6
  2. package/dist/contracts/flow-messages.d.ts +16 -0
  3. package/dist/contracts/flow-messages.d.ts.map +1 -1
  4. package/dist/contracts/flow-messages.js +20 -0
  5. package/dist/contracts/flow-messages.js.map +1 -1
  6. package/dist/engine/index.d.ts +2 -9
  7. package/dist/engine/index.d.ts.map +1 -1
  8. package/dist/engine/index.js +3 -10
  9. package/dist/engine/index.js.map +1 -1
  10. package/dist/index.d.ts +0 -14
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +0 -14
  13. package/dist/index.js.map +1 -1
  14. package/dist/ports/event-bus.d.ts +2 -2
  15. package/dist/ports/event-bus.d.ts.map +1 -1
  16. package/dist/ports/event-bus.js.map +1 -1
  17. package/dist/ports/participant-client.d.ts +7 -2
  18. package/dist/ports/participant-client.d.ts.map +1 -1
  19. package/dist/ports/participant-client.js.map +1 -1
  20. package/package.json +6 -6
  21. package/dist/contracts/command.d.ts +0 -59
  22. package/dist/contracts/command.d.ts.map +0 -1
  23. package/dist/contracts/command.js +0 -46
  24. package/dist/contracts/command.js.map +0 -1
  25. package/dist/contracts/event.d.ts +0 -85
  26. package/dist/contracts/event.d.ts.map +0 -1
  27. package/dist/contracts/event.js +0 -80
  28. package/dist/contracts/event.js.map +0 -1
  29. package/dist/contracts/messages.d.ts +0 -37
  30. package/dist/contracts/messages.d.ts.map +0 -1
  31. package/dist/contracts/messages.js +0 -68
  32. package/dist/contracts/messages.js.map +0 -1
  33. package/dist/contracts/record.d.ts +0 -106
  34. package/dist/contracts/record.d.ts.map +0 -1
  35. package/dist/contracts/record.js +0 -27
  36. package/dist/contracts/record.js.map +0 -1
  37. package/dist/contracts/saga-definition.d.ts +0 -181
  38. package/dist/contracts/saga-definition.d.ts.map +0 -1
  39. package/dist/contracts/saga-definition.js +0 -95
  40. package/dist/contracts/saga-definition.js.map +0 -1
  41. package/dist/engine/local-saga-dispatcher.d.ts +0 -35
  42. package/dist/engine/local-saga-dispatcher.d.ts.map +0 -1
  43. package/dist/engine/local-saga-dispatcher.js +0 -32
  44. package/dist/engine/local-saga-dispatcher.js.map +0 -1
  45. package/dist/engine/resolve-template.d.ts +0 -48
  46. package/dist/engine/resolve-template.d.ts.map +0 -1
  47. package/dist/engine/resolve-template.js +0 -105
  48. package/dist/engine/resolve-template.js.map +0 -1
  49. package/dist/engine/resume-sweep.d.ts +0 -46
  50. package/dist/engine/resume-sweep.d.ts.map +0 -1
  51. package/dist/engine/resume-sweep.js +0 -74
  52. package/dist/engine/resume-sweep.js.map +0 -1
  53. package/dist/engine/run-saga.d.ts +0 -54
  54. package/dist/engine/run-saga.d.ts.map +0 -1
  55. package/dist/engine/run-saga.js +0 -463
  56. package/dist/engine/run-saga.js.map +0 -1
  57. package/dist/engine/run-transaction.d.ts +0 -55
  58. package/dist/engine/run-transaction.d.ts.map +0 -1
  59. package/dist/engine/run-transaction.js +0 -101
  60. package/dist/engine/run-transaction.js.map +0 -1
  61. package/dist/mixins/transaction-mixins.d.ts +0 -20
  62. package/dist/mixins/transaction-mixins.d.ts.map +0 -1
  63. package/dist/mixins/transaction-mixins.js +0 -13
  64. package/dist/mixins/transaction-mixins.js.map +0 -1
  65. package/dist/ports/lock-service.d.ts +0 -24
  66. package/dist/ports/lock-service.d.ts.map +0 -1
  67. package/dist/ports/lock-service.js +0 -5
  68. package/dist/ports/lock-service.js.map +0 -1
  69. package/dist/ports/saga-dispatcher.d.ts +0 -46
  70. package/dist/ports/saga-dispatcher.d.ts.map +0 -1
  71. package/dist/ports/saga-dispatcher.js +0 -5
  72. package/dist/ports/saga-dispatcher.js.map +0 -1
  73. package/dist/ports/saga-store.d.ts +0 -96
  74. package/dist/ports/saga-store.d.ts.map +0 -1
  75. package/dist/ports/saga-store.js +0 -19
  76. package/dist/ports/saga-store.js.map +0 -1
  77. package/dist/ports/sequence-service.d.ts +0 -17
  78. package/dist/ports/sequence-service.d.ts.map +0 -1
  79. package/dist/ports/sequence-service.js +0 -5
  80. package/dist/ports/sequence-service.js.map +0 -1
  81. package/dist/ports/transaction-handler.d.ts +0 -66
  82. package/dist/ports/transaction-handler.d.ts.map +0 -1
  83. package/dist/ports/transaction-handler.js +0 -5
  84. package/dist/ports/transaction-handler.js.map +0 -1
  85. package/dist/ports/transaction-sink.d.ts +0 -120
  86. package/dist/ports/transaction-sink.d.ts.map +0 -1
  87. package/dist/ports/transaction-sink.js +0 -28
  88. package/dist/ports/transaction-sink.js.map +0 -1
  89. package/dist/ports/transaction-stream-hub.d.ts +0 -28
  90. package/dist/ports/transaction-stream-hub.d.ts.map +0 -1
  91. package/dist/ports/transaction-stream-hub.js +0 -5
  92. package/dist/ports/transaction-stream-hub.js.map +0 -1
  93. package/dist/stream/transaction-stream-hub.d.ts +0 -18
  94. package/dist/stream/transaction-stream-hub.d.ts.map +0 -1
  95. package/dist/stream/transaction-stream-hub.js +0 -50
  96. package/dist/stream/transaction-stream-hub.js.map +0 -1
  97. package/dist/use-case/facade.uc.d.ts +0 -22
  98. package/dist/use-case/facade.uc.d.ts.map +0 -1
  99. package/dist/use-case/facade.uc.js +0 -55
  100. 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
 
@@ -33,6 +33,22 @@ export declare const FlowAccepted: Schema.Struct<{
33
33
  }>>;
34
34
  }>;
35
35
  export type FlowAccepted = typeof FlowAccepted.Type;
36
+ /**
37
+ * The body a flow's `status` link answers: where the flow stands, and why it
38
+ * failed when it did. A browser reads it to settle a write whose outcome it
39
+ * did not hear pushed; a `404` from that link means the flow is not projected
40
+ * yet, never that it failed.
41
+ */
42
+ export declare const FlowStatusBody: Schema.Struct<{
43
+ readonly flowId: Schema.String;
44
+ readonly state: Schema.Literals<readonly ["running", "waiting", "suspended", "completed", "compensated", "failed", "interrupted"]>;
45
+ readonly step: Schema.optionalKey<Schema.String>;
46
+ readonly failure: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{
47
+ code: Schema.NonEmptyString;
48
+ category: Schema.NonEmptyString;
49
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
50
+ }>;
51
+ export type FlowStatusBody = typeof FlowStatusBody.Type;
36
52
  export interface FlowEventInput {
37
53
  readonly name: FlowEventName;
38
54
  readonly source: string;
@@ -1 +1 @@
1
- {"version":3,"file":"flow-messages.d.ts","sourceRoot":"","sources":["../../src/contracts/flow-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,qDAAqD;AACrD,eAAO,MAAM,WAAW,8EAKd,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAQzD;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;EAOxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAC;AAYtD;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;EAQvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AAIpD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,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,CAU1B,CAAC"}
@@ -43,6 +43,26 @@ for (const name of FLOW_EVENTS)registerEvent(name, name === 'flow.failed' ? Flow
43
43
  }))
44
44
  });
45
45
  registerMessage('flowAccepted', FlowAccepted);
46
+ /**
47
+ * The body a flow's `status` link answers: where the flow stands, and why it
48
+ * failed when it did. A browser reads it to settle a write whose outcome it
49
+ * did not hear pushed; a `404` from that link means the flow is not projected
50
+ * yet, never that it failed.
51
+ */ export const FlowStatusBody = Schema.Struct({
52
+ flowId: Schema.String,
53
+ state: Schema.Literals([
54
+ 'running',
55
+ 'waiting',
56
+ 'suspended',
57
+ 'completed',
58
+ 'compensated',
59
+ 'failed',
60
+ 'interrupted'
61
+ ]),
62
+ step: Schema.optionalKey(Schema.String),
63
+ failure: Schema.optionalKey(FlowFailure)
64
+ });
65
+ registerMessage('flowStatus', FlowStatusBody);
46
66
  /**
47
67
  * Builds a `flow.*` event: id `<flowId>:<step>` so a redelivered announce is
48
68
  * the same message, `correlationId` the flow, the step ordinal as version, and
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/flow-messages.ts"],"sourcesContent":["import {\n type AudienceEntry,\n openStruct,\n registerEvent,\n registerMessage,\n} from '@entifix/core';\nimport { Schema } from 'effect';\n\nimport type { OutboxEvent } from './outbox.js';\n\n/** The four things a flow announces about itself. */\nexport const FLOW_EVENTS = [\n 'flow.started',\n 'flow.completed',\n 'flow.failed',\n 'flow.suspended',\n] as const;\nexport type FlowEventName = (typeof FLOW_EVENTS)[number];\n\n/** A failure inside an asynchronous message: the problem's code and category. */\nconst FlowFailure = openStruct({\n code: Schema.NonEmptyString,\n category: Schema.NonEmptyString,\n});\n\n/**\n * What a `flow.*` event carries. A `flow.failed` without a failure, or with a\n * failure missing its `code` or `category`, does not decode: a client settling\n * a write must be able to translate why it failed.\n */\nexport const FlowEventData = Schema.Struct({\n flowId: Schema.String,\n definition: Schema.String,\n slipVersion: Schema.Number,\n step: Schema.optionalKey(Schema.String),\n outcome: Schema.optionalKey(Schema.Unknown),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowEventData = typeof FlowEventData.Type;\n\nconst FlowFailedData = Schema.Struct({\n ...FlowEventData.fields,\n failure: FlowFailure,\n});\n\nfor (const name of FLOW_EVENTS)\n registerEvent(name, name === 'flow.failed' ? FlowFailedData : FlowEventData, {\n versioned: true,\n });\n\n/**\n * The `202` body a flow start answers: the flow's id, and where to watch it —\n * its status read and its stream.\n */\nexport const FlowAccepted = Schema.Struct({\n flowId: Schema.String,\n links: Schema.Array(\n Schema.Struct({\n rel: Schema.Literals(['status', 'stream']),\n href: Schema.String,\n }),\n ),\n});\nexport type FlowAccepted = typeof FlowAccepted.Type;\n\nregisterMessage('flowAccepted', FlowAccepted);\n\nexport interface FlowEventInput {\n readonly name: FlowEventName;\n readonly source: string;\n readonly at: string;\n /** The step this event is about, and its ordinal — the event's version. */\n readonly step: string;\n readonly ordinal: number;\n readonly audience: readonly AudienceEntry[];\n readonly data: FlowEventData;\n}\n\n/**\n * Builds a `flow.*` event: id `<flowId>:<step>` so a redelivered announce is\n * the same message, `correlationId` the flow, the step ordinal as version, and\n * an audience that must not be empty.\n */\nexport const flowEvent = (\n input: FlowEventInput,\n): OutboxEvent<FlowEventData> => ({\n name: input.name,\n id: `${input.data.flowId}:${input.step}`,\n source: input.source,\n at: input.at,\n correlationId: input.data.flowId,\n aggregate: { type: 'flow', id: input.data.flowId },\n version: input.ordinal,\n audience: input.audience,\n data: input.data,\n});\n"],"names":["openStruct","registerEvent","registerMessage","Schema","FLOW_EVENTS","FlowFailure","code","NonEmptyString","category","FlowEventData","Struct","flowId","String","definition","slipVersion","Number","step","optionalKey","outcome","Unknown","failure","FlowFailedData","fields","name","versioned","FlowAccepted","links","Array","rel","Literals","href","flowEvent","input","id","data","source","at","correlationId","aggregate","type","version","ordinal","audience"],"mappings":";AAAA,SAEEA,UAAU,EACVC,aAAa,EACbC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAI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AAME,IAAI,CAACvB,MAAM;QAAC;QACjD6B,SAASR,MAAMS,OAAO;QACtBC,UAAUV,MAAMU,QAAQ;QACxBR,MAAMF,MAAME,IAAI;IAClB,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../src/contracts/flow-messages.ts"],"sourcesContent":["import {\n type AudienceEntry,\n openStruct,\n registerEvent,\n registerMessage,\n} from '@entifix/core';\nimport { Schema } from 'effect';\n\nimport type { OutboxEvent } from './outbox.js';\n\n/** The four things a flow announces about itself. */\nexport const FLOW_EVENTS = [\n 'flow.started',\n 'flow.completed',\n 'flow.failed',\n 'flow.suspended',\n] as const;\nexport type FlowEventName = (typeof FLOW_EVENTS)[number];\n\n/** A failure inside an asynchronous message: the problem's code and category. */\nconst FlowFailure = openStruct({\n code: Schema.NonEmptyString,\n category: Schema.NonEmptyString,\n});\n\n/**\n * What a `flow.*` event carries. A `flow.failed` without a failure, or with a\n * failure missing its `code` or `category`, does not decode: a client settling\n * a write must be able to translate why it failed.\n */\nexport const FlowEventData = Schema.Struct({\n flowId: Schema.String,\n definition: Schema.String,\n slipVersion: Schema.Number,\n step: Schema.optionalKey(Schema.String),\n outcome: Schema.optionalKey(Schema.Unknown),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowEventData = typeof FlowEventData.Type;\n\nconst FlowFailedData = Schema.Struct({\n ...FlowEventData.fields,\n failure: FlowFailure,\n});\n\nfor (const name of FLOW_EVENTS)\n registerEvent(name, name === 'flow.failed' ? FlowFailedData : FlowEventData, {\n versioned: true,\n });\n\n/**\n * The `202` body a flow start answers: the flow's id, and where to watch it —\n * its status read and its stream.\n */\nexport const FlowAccepted = Schema.Struct({\n flowId: Schema.String,\n links: Schema.Array(\n Schema.Struct({\n rel: Schema.Literals(['status', 'stream']),\n href: Schema.String,\n }),\n ),\n});\nexport type FlowAccepted = typeof FlowAccepted.Type;\n\nregisterMessage('flowAccepted', FlowAccepted);\n\n/**\n * The body a flow's `status` link answers: where the flow stands, and why it\n * failed when it did. A browser reads it to settle a write whose outcome it\n * did not hear pushed; a `404` from that link means the flow is not projected\n * yet, never that it failed.\n */\nexport const FlowStatusBody = Schema.Struct({\n flowId: Schema.String,\n state: Schema.Literals([\n 'running',\n 'waiting',\n 'suspended',\n 'completed',\n 'compensated',\n 'failed',\n 'interrupted',\n ]),\n step: Schema.optionalKey(Schema.String),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowStatusBody = typeof FlowStatusBody.Type;\n\nregisterMessage('flowStatus', FlowStatusBody);\n\nexport interface FlowEventInput {\n readonly name: FlowEventName;\n readonly source: string;\n readonly at: string;\n /** The step this event is about, and its ordinal — the event's version. */\n readonly step: string;\n readonly ordinal: number;\n readonly audience: readonly AudienceEntry[];\n readonly data: FlowEventData;\n}\n\n/**\n * Builds a `flow.*` event: id `<flowId>:<step>` so a redelivered announce is\n * the same message, `correlationId` the flow, the step ordinal as version, and\n * an audience that must not be empty.\n */\nexport const flowEvent = (\n input: FlowEventInput,\n): OutboxEvent<FlowEventData> => ({\n name: input.name,\n id: `${input.data.flowId}:${input.step}`,\n source: input.source,\n at: input.at,\n correlationId: input.data.flowId,\n aggregate: { type: 'flow', id: input.data.flowId },\n version: input.ordinal,\n audience: input.audience,\n data: input.data,\n});\n"],"names":["openStruct","registerEvent","registerMessage","Schema","FLOW_EVENTS","FlowFailure","code","NonEmptyString","category","FlowEventData","Struct","flowId","String","definition","slipVersion","Number","step","optionalKey","outcome","Unknown","failure","FlowFailedData","fields","name","versioned","FlowAccepted","links","Array","rel","Literals","href","FlowStatusBody","state","flowEvent","input","id","data","source","at","correlationId","aggregate","type","version","ordinal","audience"],"mappings":";AAAA,SAEEA,UAAU,EACVC,aAAa,EACbC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAIhC,mDAAmD,GACnD,OAAO,MAAMC,cAAc;IACzB;IACA;IACA;IACA;CACD,CAAU;AAGX,+EAA+E,GAC/E,MAAMC,cAAcL,WAAW;IAC7BM,MAAMH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EAAEuB,MAAMlB,IAAI,EAAE;QACxCqB,QAAQH,MAAMG,MAAM;QACpBC,IAAIJ,MAAMI,EAAE;QACZC,eAAeL,MAAME,IAAI,CAACzB,MAAM;QAChC6B,WAAW;YAAEC,MAAM;YAAQN,IAAID,MAAME,IAAI,CAACzB,MAAM;QAAC;QACjD+B,SAASR,MAAMS,OAAO;QACtBC,UAAUV,MAAMU,QAAQ;QACxBR,MAAMF,MAAME,IAAI;IAClB,CAAA,EAAG"}
@@ -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"}
@@ -1,4 +1,4 @@
1
- import type { DomainEvent, StoreFailure, TransitionalFailure } from '@entifix/core';
1
+ import type { DomainEvent, EntifixFailure, StoreFailure } from '@entifix/core';
2
2
  import { Context, type Effect } from 'effect';
3
3
  /**
4
4
  * How a subscriber's queue is shaped, which is a property of the *workload*
@@ -98,7 +98,7 @@ export interface EventBus {
98
98
  * behind it. A *business* failure is neither: that message was processed
99
99
  * successfully and already produced its own event.
100
100
  */
101
- subscribe(subscription: Subscription, handler: (event: DomainEvent) => Effect.Effect<void, TransitionalFailure>): Effect.Effect<void, StoreFailure>;
101
+ subscribe(subscription: Subscription, handler: (event: DomainEvent) => Effect.Effect<void, EntifixFailure>): Effect.Effect<void, StoreFailure>;
102
102
  }
103
103
  declare const EventBusTag_base: Context.ServiceClass<EventBusTag, "EventBusTag", EventBus>;
104
104
  export declare class EventBusTag extends EventBusTag_base {
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/ports/event-bus.ts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AE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;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;IAC7B;;;;;;;;OAQG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC/D;;;;;;;;;;;;;;OAcG;IACH,SAAS,CACP,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,GACnE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;CACtC;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ports/event-bus.ts"],"sourcesContent":["import type {\n DomainEvent,\n StoreFailure,\n TransitionalFailure,\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.\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 * The bus first built the exclusive queue for every subscriber, with 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 may host several slices, 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 * The breaker keys whose dependency this consumer cannot work without\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).\n * While any of them is open — or forced open — the adapter stops consuming,\n * and it resumes once all are closed or half-open, so an outage leaves the\n * messages waiting on the queue rather than spending their attempts into\n * quarantine. A delivery refused mid-flight by an open breaker goes back\n * without counting as an attempt.\n */\n readonly pauseWhileOpen?: readonly string[];\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 a publication event to\n * 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, StoreFailure>;\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.\n */\n subscribe(\n subscription: Subscription,\n handler: (event: DomainEvent) => Effect.Effect<void, TransitionalFailure>,\n ): Effect.Effect<void, StoreFailure>;\n}\n\nexport class EventBusTag extends Context.Service<EventBusTag, EventBus>()(\n 'EventBusTag',\n) {}\n"],"names":["Context","EventBusTag","Service"],"mappings":"AAKA,SAASA,OAAO,QAAqB,SAAS;AA4G9C,OAAO,MAAMC,oBAAoBD,QAAQE,OAAO,GAC9C;AACC"}
1
+ {"version":3,"sources":["../../src/ports/event-bus.ts"],"sourcesContent":["import type { DomainEvent, EntifixFailure, StoreFailure } 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.\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 * The bus first built the exclusive queue for every subscriber, with 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 may host several slices, 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 * The breaker keys whose dependency this consumer cannot work without\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).\n * While any of them is open — or forced open — the adapter stops consuming,\n * and it resumes once all are closed or half-open, so an outage leaves the\n * messages waiting on the queue rather than spending their attempts into\n * quarantine. A delivery refused mid-flight by an open breaker goes back\n * without counting as an attempt.\n */\n readonly pauseWhileOpen?: readonly string[];\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 a publication event to\n * 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, StoreFailure>;\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.\n */\n subscribe(\n subscription: Subscription,\n handler: (event: DomainEvent) => Effect.Effect<void, EntifixFailure>,\n ): Effect.Effect<void, StoreFailure>;\n}\n\nexport class EventBusTag extends Context.Service<EventBusTag, EventBus>()(\n 'EventBusTag',\n) {}\n"],"names":["Context","EventBusTag","Service"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AA4G9C,OAAO,MAAMC,oBAAoBD,QAAQE,OAAO,GAC9C;AACC"}
@@ -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.13.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,13 +56,13 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@swc/helpers": "0.5.23",
59
- "@entifix/business": "0.13.0",
60
- "@entifix/core": "0.13.0"
59
+ "@entifix/business": "0.15.0",
60
+ "@entifix/core": "0.15.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "effect": "^4.0.6"
63
+ "effect": "^4.0.7"
64
64
  },
65
65
  "devDependencies": {
66
- "effect": "4.0.6"
66
+ "effect": "4.0.7"
67
67
  }
68
68
  }
@@ -1,59 +0,0 @@
1
- import './messages.js';
2
- import { EntifixBuildError, type EntifixEnvelope, type 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 `requireOrganization` 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>, EntifixBuildError | 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,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EAEpB,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,CACd,kBAAkB,CAAC,QAAQ,CAAC,EAC5B,iBAAiB,GAAG,eAAe,CACpC,CAuBA"}
@@ -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, EntifixBuildError, 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 EntifixBuildError('command envelope carried no valid command', undefined, {
33
- body
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 EntifixBuildError,\n type EntifixEnvelope,\n type 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 `requireOrganization` 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<\n TransactionCommand<TPayload>,\n EntifixBuildError | InvalidEnvelope\n> {\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 EntifixBuildError(\n 'command envelope carried no valid command',\n undefined,\n {\n body,\n },\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","EntifixBuildError","makeEnvelope","Effect","makeCommandEnvelope","command","entity","UUID","isTransactionId","value","test","readCommandEnvelope","body","gen","envelope","data","transactionId","fail","undefined","organizationId","_ignored","trusted"],"mappings":";AAAA,qEAAqE;AACrE,OAAO,gBAAgB;AAEvB,SACEA,qBAAqB,EACrBC,iBAAiB,EAGjBC,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;IAKb,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,kBACF,6CACAiB,WACA;gBACEN;YACF;QAGN;QACA,wEAAwE;QACxE,4EAA4E;QAC5E,gEAAgE;QAChE,MAAM,EAAEO,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,EACd,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBA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