@entifix/transactions 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/contracts/flow-messages.d.ts +3 -3
- package/dist/contracts/flow-messages.d.ts.map +1 -1
- package/dist/contracts/flow-messages.js +7 -3
- package/dist/contracts/flow-messages.js.map +1 -1
- package/dist/engine/index.d.ts +2 -9
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +3 -10
- package/dist/engine/index.js.map +1 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +1 -1
- package/dist/ports/flow-engine.d.ts +17 -8
- package/dist/ports/flow-engine.d.ts.map +1 -1
- package/dist/ports/flow-engine.js +2 -2
- package/dist/ports/flow-engine.js.map +1 -1
- package/dist/ports/participant-client.d.ts +7 -2
- package/dist/ports/participant-client.d.ts.map +1 -1
- package/dist/ports/participant-client.js.map +1 -1
- package/package.json +4 -4
- package/dist/contracts/command.d.ts +0 -59
- package/dist/contracts/command.d.ts.map +0 -1
- package/dist/contracts/command.js +0 -46
- package/dist/contracts/command.js.map +0 -1
- package/dist/contracts/event.d.ts +0 -85
- package/dist/contracts/event.d.ts.map +0 -1
- package/dist/contracts/event.js +0 -81
- package/dist/contracts/event.js.map +0 -1
- package/dist/contracts/messages.d.ts +0 -37
- package/dist/contracts/messages.d.ts.map +0 -1
- package/dist/contracts/messages.js +0 -68
- package/dist/contracts/messages.js.map +0 -1
- package/dist/contracts/record.d.ts +0 -106
- package/dist/contracts/record.d.ts.map +0 -1
- package/dist/contracts/record.js +0 -27
- package/dist/contracts/record.js.map +0 -1
- package/dist/contracts/saga-definition.d.ts +0 -181
- package/dist/contracts/saga-definition.d.ts.map +0 -1
- package/dist/contracts/saga-definition.js +0 -101
- package/dist/contracts/saga-definition.js.map +0 -1
- package/dist/engine/local-saga-dispatcher.d.ts +0 -35
- package/dist/engine/local-saga-dispatcher.d.ts.map +0 -1
- package/dist/engine/local-saga-dispatcher.js +0 -28
- package/dist/engine/local-saga-dispatcher.js.map +0 -1
- package/dist/engine/resolve-template.d.ts +0 -48
- package/dist/engine/resolve-template.d.ts.map +0 -1
- package/dist/engine/resolve-template.js +0 -95
- package/dist/engine/resolve-template.js.map +0 -1
- package/dist/engine/resume-sweep.d.ts +0 -46
- package/dist/engine/resume-sweep.d.ts.map +0 -1
- package/dist/engine/resume-sweep.js +0 -74
- package/dist/engine/resume-sweep.js.map +0 -1
- package/dist/engine/run-saga.d.ts +0 -54
- package/dist/engine/run-saga.d.ts.map +0 -1
- package/dist/engine/run-saga.js +0 -463
- package/dist/engine/run-saga.js.map +0 -1
- package/dist/engine/run-transaction.d.ts +0 -55
- package/dist/engine/run-transaction.d.ts.map +0 -1
- package/dist/engine/run-transaction.js +0 -101
- package/dist/engine/run-transaction.js.map +0 -1
- package/dist/mixins/transaction-mixins.d.ts +0 -20
- package/dist/mixins/transaction-mixins.d.ts.map +0 -1
- package/dist/mixins/transaction-mixins.js +0 -13
- package/dist/mixins/transaction-mixins.js.map +0 -1
- package/dist/ports/lock-service.d.ts +0 -24
- package/dist/ports/lock-service.d.ts.map +0 -1
- package/dist/ports/lock-service.js +0 -5
- package/dist/ports/lock-service.js.map +0 -1
- package/dist/ports/saga-dispatcher.d.ts +0 -46
- package/dist/ports/saga-dispatcher.d.ts.map +0 -1
- package/dist/ports/saga-dispatcher.js +0 -5
- package/dist/ports/saga-dispatcher.js.map +0 -1
- package/dist/ports/saga-store.d.ts +0 -96
- package/dist/ports/saga-store.d.ts.map +0 -1
- package/dist/ports/saga-store.js +0 -19
- package/dist/ports/saga-store.js.map +0 -1
- package/dist/ports/sequence-service.d.ts +0 -17
- package/dist/ports/sequence-service.d.ts.map +0 -1
- package/dist/ports/sequence-service.js +0 -5
- package/dist/ports/sequence-service.js.map +0 -1
- package/dist/ports/transaction-handler.d.ts +0 -66
- package/dist/ports/transaction-handler.d.ts.map +0 -1
- package/dist/ports/transaction-handler.js +0 -5
- package/dist/ports/transaction-handler.js.map +0 -1
- package/dist/ports/transaction-sink.d.ts +0 -120
- package/dist/ports/transaction-sink.d.ts.map +0 -1
- package/dist/ports/transaction-sink.js +0 -28
- package/dist/ports/transaction-sink.js.map +0 -1
- package/dist/ports/transaction-stream-hub.d.ts +0 -28
- package/dist/ports/transaction-stream-hub.d.ts.map +0 -1
- package/dist/ports/transaction-stream-hub.js +0 -5
- package/dist/ports/transaction-stream-hub.js.map +0 -1
- package/dist/stream/transaction-stream-hub.d.ts +0 -18
- package/dist/stream/transaction-stream-hub.d.ts.map +0 -1
- package/dist/stream/transaction-stream-hub.js +0 -50
- package/dist/stream/transaction-stream-hub.js.map +0 -1
- package/dist/use-case/facade.uc.d.ts +0 -22
- package/dist/use-case/facade.uc.d.ts.map +0 -1
- package/dist/use-case/facade.uc.js +0 -55
- package/dist/use-case/facade.uc.js.map +0 -1
|
@@ -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"}
|
package/dist/contracts/event.js
DELETED
|
@@ -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"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { openStruct, registerEvent, registerMessage } from '@entifix/core';
|
|
2
|
-
import { Schema } from 'effect';
|
|
3
|
-
import { TRANSACTION_STATES, transactionEventName } from './event.js';
|
|
4
|
-
/**
|
|
5
|
-
* The transaction-shaped messages, registered by the package that owns them —
|
|
6
|
-
* core's registry is open, so these left core's closed union in 0.11.0 and are
|
|
7
|
-
* deleted with the saga runner and the tracker (#127).
|
|
8
|
-
*
|
|
9
|
-
* Each schema names only what a reader of it branches on and keeps the rest,
|
|
10
|
-
* which is enough to refuse a body that is some other message wearing this
|
|
11
|
-
* one's name.
|
|
12
|
-
*/ const State = Schema.Literals(TRANSACTION_STATES);
|
|
13
|
-
export const TransactionCommandSchema = openStruct({
|
|
14
|
-
transactionId: Schema.String,
|
|
15
|
-
type: Schema.String,
|
|
16
|
-
entity: Schema.String,
|
|
17
|
-
payload: Schema.Unknown
|
|
18
|
-
});
|
|
19
|
-
export const TransactionAcceptedSchema = openStruct({
|
|
20
|
-
transactionId: Schema.String,
|
|
21
|
-
state: State
|
|
22
|
-
});
|
|
23
|
-
export const TransactionRecordSchema = openStruct({
|
|
24
|
-
transactionId: Schema.String,
|
|
25
|
-
entity: Schema.String,
|
|
26
|
-
state: State,
|
|
27
|
-
createdAt: Schema.String,
|
|
28
|
-
updatedAt: Schema.String
|
|
29
|
-
});
|
|
30
|
-
export const SagaResultSchema = openStruct({
|
|
31
|
-
state: Schema.String,
|
|
32
|
-
outcomes: Schema.Array(Schema.Unknown)
|
|
33
|
-
});
|
|
34
|
-
export const SagaInstanceSchema = openStruct({
|
|
35
|
-
sagaId: Schema.String,
|
|
36
|
-
definition: Schema.String,
|
|
37
|
-
state: Schema.String,
|
|
38
|
-
stepIndex: Schema.Number,
|
|
39
|
-
outcomes: Schema.Array(Schema.Unknown)
|
|
40
|
-
});
|
|
41
|
-
export const TransactionEventSchema = openStruct({
|
|
42
|
-
transactionId: Schema.String,
|
|
43
|
-
entity: Schema.String,
|
|
44
|
-
state: State,
|
|
45
|
-
step: Schema.Literals([
|
|
46
|
-
'accepted',
|
|
47
|
-
'completed',
|
|
48
|
-
'failed'
|
|
49
|
-
]),
|
|
50
|
-
at: Schema.String
|
|
51
|
-
});
|
|
52
|
-
registerMessage('command', TransactionCommandSchema);
|
|
53
|
-
registerMessage('transactionAccepted', TransactionAcceptedSchema);
|
|
54
|
-
registerMessage('transactionRecord', TransactionRecordSchema);
|
|
55
|
-
registerMessage('sagaResult', SagaResultSchema);
|
|
56
|
-
registerMessage('sagaInstance', SagaInstanceSchema);
|
|
57
|
-
// ⚠️ Registered audience-free: a transaction event is scoped by the
|
|
58
|
-
// `organizationId` in its `data`, which is what the stream hub filters on
|
|
59
|
-
// today. The flow events that replace these carry a real audience.
|
|
60
|
-
for (const step of [
|
|
61
|
-
'accepted',
|
|
62
|
-
'completed',
|
|
63
|
-
'failed'
|
|
64
|
-
])registerEvent(transactionEventName(step), TransactionEventSchema, {
|
|
65
|
-
audience: 'none'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
//# sourceMappingURL=messages.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/messages.ts"],"sourcesContent":["import { openStruct, registerEvent, registerMessage } from '@entifix/core';\nimport { Schema } from 'effect';\n\nimport { TRANSACTION_STATES, transactionEventName } from './event.js';\n\n/**\n * The transaction-shaped messages, registered by the package that owns them —\n * core's registry is open, so these left core's closed union in 0.11.0 and are\n * deleted with the saga runner and the tracker (#127).\n *\n * Each schema names only what a reader of it branches on and keeps the rest,\n * which is enough to refuse a body that is some other message wearing this\n * one's name.\n */\nconst State = Schema.Literals(TRANSACTION_STATES);\n\nexport const TransactionCommandSchema = openStruct({\n transactionId: Schema.String,\n type: Schema.String,\n entity: Schema.String,\n payload: Schema.Unknown,\n});\n\nexport const TransactionAcceptedSchema = openStruct({\n transactionId: Schema.String,\n state: State,\n});\n\nexport const TransactionRecordSchema = openStruct({\n transactionId: Schema.String,\n entity: Schema.String,\n state: State,\n createdAt: Schema.String,\n updatedAt: Schema.String,\n});\n\nexport const SagaResultSchema = openStruct({\n state: Schema.String,\n outcomes: Schema.Array(Schema.Unknown),\n});\n\nexport const SagaInstanceSchema = openStruct({\n sagaId: Schema.String,\n definition: Schema.String,\n state: Schema.String,\n stepIndex: Schema.Number,\n outcomes: Schema.Array(Schema.Unknown),\n});\n\nexport const TransactionEventSchema = openStruct({\n transactionId: Schema.String,\n entity: Schema.String,\n state: State,\n step: Schema.Literals(['accepted', 'completed', 'failed']),\n at: Schema.String,\n});\n\nregisterMessage('command', TransactionCommandSchema);\nregisterMessage('transactionAccepted', TransactionAcceptedSchema);\nregisterMessage('transactionRecord', TransactionRecordSchema);\nregisterMessage('sagaResult', SagaResultSchema);\nregisterMessage('sagaInstance', SagaInstanceSchema);\n\n// ⚠️ Registered audience-free: a transaction event is scoped by the\n// `organizationId` in its `data`, which is what the stream hub filters on\n// today. The flow events that replace these carry a real audience.\nfor (const step of ['accepted', 'completed', 'failed'] as const)\n registerEvent(transactionEventName(step), TransactionEventSchema, {\n audience: 'none',\n });\n"],"names":["openStruct","registerEvent","registerMessage","Schema","TRANSACTION_STATES","transactionEventName","State","Literals","TransactionCommandSchema","transactionId","String","type","entity","payload","Unknown","TransactionAcceptedSchema","state","TransactionRecordSchema","createdAt","updatedAt","SagaResultSchema","outcomes","Array","SagaInstanceSchema","sagaId","definition","stepIndex","Number","TransactionEventSchema","step","at","audience"],"mappings":"AAAA,SAASA,UAAU,EAAEC,aAAa,EAAEC,eAAe,QAAQ,gBAAgB;AAC3E,SAASC,MAAM,QAAQ,SAAS;AAEhC,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,aAAa;AAEtE;;;;;;;;CAQC,GACD,MAAMC,QAAQH,OAAOI,QAAQ,CAACH;AAE9B,OAAO,MAAMI,2BAA2BR,WAAW;IACjDS,eAAeN,OAAOO,MAAM;IAC5BC,MAAMR,OAAOO,MAAM;IACnBE,QAAQT,OAAOO,MAAM;IACrBG,SAASV,OAAOW,OAAO;AACzB,GAAG;AAEH,OAAO,MAAMC,4BAA4Bf,WAAW;IAClDS,eAAeN,OAAOO,MAAM;IAC5BM,OAAOV;AACT,GAAG;AAEH,OAAO,MAAMW,0BAA0BjB,WAAW;IAChDS,eAAeN,OAAOO,MAAM;IAC5BE,QAAQT,OAAOO,MAAM;IACrBM,OAAOV;IACPY,WAAWf,OAAOO,MAAM;IACxBS,WAAWhB,OAAOO,MAAM;AAC1B,GAAG;AAEH,OAAO,MAAMU,mBAAmBpB,WAAW;IACzCgB,OAAOb,OAAOO,MAAM;IACpBW,UAAUlB,OAAOmB,KAAK,CAACnB,OAAOW,OAAO;AACvC,GAAG;AAEH,OAAO,MAAMS,qBAAqBvB,WAAW;IAC3CwB,QAAQrB,OAAOO,MAAM;IACrBe,YAAYtB,OAAOO,MAAM;IACzBM,OAAOb,OAAOO,MAAM;IACpBgB,WAAWvB,OAAOwB,MAAM;IACxBN,UAAUlB,OAAOmB,KAAK,CAACnB,OAAOW,OAAO;AACvC,GAAG;AAEH,OAAO,MAAMc,yBAAyB5B,WAAW;IAC/CS,eAAeN,OAAOO,MAAM;IAC5BE,QAAQT,OAAOO,MAAM;IACrBM,OAAOV;IACPuB,MAAM1B,OAAOI,QAAQ,CAAC;QAAC;QAAY;QAAa;KAAS;IACzDuB,IAAI3B,OAAOO,MAAM;AACnB,GAAG;AAEHR,gBAAgB,WAAWM;AAC3BN,gBAAgB,uBAAuBa;AACvCb,gBAAgB,qBAAqBe;AACrCf,gBAAgB,cAAckB;AAC9BlB,gBAAgB,gBAAgBqB;AAEhC,oEAAoE;AACpE,0EAA0E;AAC1E,mEAAmE;AACnE,KAAK,MAAMM,QAAQ;IAAC;IAAY;IAAa;CAAS,CACpD5B,cAAcI,qBAAqBwB,OAAOD,wBAAwB;IAChEG,UAAU;AACZ"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import './messages.js';
|
|
2
|
-
import { type EntifixFailure, type EntityId, type ProtocolFailure, type StoreFault } from '@entifix/core';
|
|
3
|
-
import { Context, Effect } from 'effect';
|
|
4
|
-
import type { TransactionEvent, TransactionState } from './event.js';
|
|
5
|
-
/**
|
|
6
|
-
* The the saga tracker's persisted view of a transaction, folded from the
|
|
7
|
-
* events it observes. It is the source of truth a client polls.
|
|
8
|
-
*/
|
|
9
|
-
export interface TransactionRecord {
|
|
10
|
-
transactionId: string;
|
|
11
|
-
entity: string;
|
|
12
|
-
state: TransactionState;
|
|
13
|
-
code?: string;
|
|
14
|
-
entityId?: EntityId;
|
|
15
|
-
error?: string;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
updatedAt: string;
|
|
18
|
-
/**
|
|
19
|
-
* Whose organization this transaction happened in, folded from the event.
|
|
20
|
-
*
|
|
21
|
-
* The `saga` store is control-plane and single-partition — it holds every
|
|
22
|
-
* organization's records by design — so isolation on the read routes has to be
|
|
23
|
-
* this filter. A record written before the member existed carries none and is
|
|
24
|
-
* therefore readable by nobody, which is the direction to fail.
|
|
25
|
-
*/
|
|
26
|
-
organizationId?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Port the manager tracks transactions through. Implemented over Mongo in the
|
|
30
|
-
* service; framework-free here so the engine/manager stay environment-agnostic.
|
|
31
|
-
*/
|
|
32
|
-
export interface TransactionStore {
|
|
33
|
-
/** Folds an event into the record, creating it on first sight. */
|
|
34
|
-
upsertFromEvent(event: TransactionEvent): Effect.Effect<TransactionRecord, StoreFault>;
|
|
35
|
-
get(transactionId: string): Effect.Effect<TransactionRecord | undefined, StoreFault>;
|
|
36
|
-
/** Non-terminal records not updated within `olderThanMs` — recovery input. */
|
|
37
|
-
findStale(olderThanMs: number): Effect.Effect<readonly TransactionRecord[], StoreFault>;
|
|
38
|
-
markStale(transactionId: string): Effect.Effect<void, StoreFault>;
|
|
39
|
-
/**
|
|
40
|
-
* How many records sit in each state — the recovery sweep samples it.
|
|
41
|
-
*
|
|
42
|
-
* ⚠️ **This is a count, and is not the `list` above.** It returns no record,
|
|
43
|
-
* no id and no organization, so it does not reopen the list surface removed
|
|
44
|
-
* `GET /api/transaction` for: an unfiltered *listing* of this store is every
|
|
45
|
-
* organization's transactions, while a total of how many are `STALE` is a
|
|
46
|
-
* fleet health number that names nobody. The distinction is the whole reason
|
|
47
|
-
* one is here and the other is refused.
|
|
48
|
-
*
|
|
49
|
-
* It exists so `STALE` is something a dashboard shows rather than something a
|
|
50
|
-
* poll discovers — which is what the recovery sweep, whose only action is to
|
|
51
|
-
* apply that label, otherwise leaves entirely unobservable.
|
|
52
|
-
*/
|
|
53
|
-
countByState(): Effect.Effect<Record<TransactionState, number>, StoreFault>;
|
|
54
|
-
}
|
|
55
|
-
declare const TransactionStoreTag_base: Context.ServiceClass<TransactionStoreTag, "TransactionStoreTag", TransactionStore>;
|
|
56
|
-
export declare class TransactionStoreTag extends TransactionStoreTag_base {
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* What a service answers a `202` with: the id to poll, and the state it starts
|
|
60
|
-
* in.
|
|
61
|
-
*
|
|
62
|
-
* ⚠️ **Not a {@link TransactionRecord}, which is why it has its own
|
|
63
|
-
* discriminant.** Nothing has been folded yet — there is no `createdAt`, no
|
|
64
|
-
* entity id, and no code, because the write has not run. Framing it as a record
|
|
65
|
-
* meant the browser's accept-shape assertion was checking a name that the
|
|
66
|
-
* by-id route and the bus payload also answered to, so it asserted nothing it
|
|
67
|
-
* claimed to.
|
|
68
|
-
*/
|
|
69
|
-
export interface TransactionAccepted {
|
|
70
|
-
transactionId: string;
|
|
71
|
-
state: TransactionState;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Parses a `202` accept body, for a browser about to start polling.
|
|
75
|
-
*
|
|
76
|
-
* Read for its **shape**, not its contents: it asserts the service really
|
|
77
|
-
* accepted a transaction rather than answering something else with a `2xx`.
|
|
78
|
-
*/
|
|
79
|
-
export declare function readTransactionAcceptedEnvelope(body: unknown): Effect.Effect<TransactionAccepted, ProtocolFailure>;
|
|
80
|
-
/**
|
|
81
|
-
* Parses the tracker's by-id response, which frames a {@link TransactionRecord}.
|
|
82
|
-
*
|
|
83
|
-
* The body is decoded against `transactionRecord`'s registered schema, so a
|
|
84
|
-
* different message wearing the name — an event, which has a `step` and no
|
|
85
|
-
* `createdAt` — is refused rather than handed back typed and wrong.
|
|
86
|
-
*/
|
|
87
|
-
export declare function readTransactionRecordEnvelope(body: unknown): Effect.Effect<TransactionRecord, ProtocolFailure>;
|
|
88
|
-
/**
|
|
89
|
-
* Reads one transaction's record, for a browser reconciling a write it started.
|
|
90
|
-
*
|
|
91
|
-
* ⚠️ **`undefined` means _not tracked yet_, not _failed_.** `accepted` reaches
|
|
92
|
-
* the tracker over the bus, so with the broker down the entity write commits —
|
|
93
|
-
* the outbox is in the same Mongo transaction — while no event is ever
|
|
94
|
-
* published and this answers `404`. That is a write in perfect health, and a
|
|
95
|
-
* caller that rolls back on it un-renders a record that is about to appear, at
|
|
96
|
-
* exactly the moment nobody can tell a UI bug from an outage. Only `FAILED` and
|
|
97
|
-
* `STALE` are terminal.
|
|
98
|
-
*/
|
|
99
|
-
export interface TransactionStatusReader {
|
|
100
|
-
read(transactionId: string): Effect.Effect<TransactionRecord | undefined, EntifixFailure>;
|
|
101
|
-
}
|
|
102
|
-
declare const TransactionStatusReaderTag_base: Context.ServiceClass<TransactionStatusReaderTag, "TransactionStatusReaderTag", TransactionStatusReader>;
|
|
103
|
-
export declare class TransactionStatusReaderTag extends TransactionStatusReaderTag_base {
|
|
104
|
-
}
|
|
105
|
-
export {};
|
|
106
|
-
//# sourceMappingURL=record.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/contracts/record.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,UAAU,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,eAAe,CACb,KAAK,EAAE,gBAAgB,GACtB,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAChD,GAAG,CACD,aAAa,EAAE,MAAM,GACpB,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,SAAS,EAAE,UAAU,CAAC,CAAC;IAM5D,8EAA8E;IAC9E,SAAS,CACP,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,CAAC,SAAS,iBAAiB,EAAE,EAAE,UAAU,CAAC,CAAC;IAC3D,SAAS,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAClE;;;;;;;;;;;;;OAaG;IACH,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;CAC7E;;AAED,qBAAa,mBAAoB,SAAQ,wBAGf;CAAG;AAE7B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAKrD;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAKnD;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,CACF,aAAa,EAAE,MAAM,GACpB,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,SAAS,EAAE,cAAc,CAAC,CAAC;CACjE;;AAED,qBAAa,0BAA2B,SAAQ,+BAGf;CAAG"}
|
package/dist/contracts/record.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Evaluated for its registrations: this reader decodes against them.
|
|
2
|
-
import './messages.js';
|
|
3
|
-
import { decodeEnvelope } from '@entifix/core';
|
|
4
|
-
import { Context, Effect } from 'effect';
|
|
5
|
-
export class TransactionStoreTag extends Context.Service()('TransactionStoreTag') {
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Parses a `202` accept body, for a browser about to start polling.
|
|
9
|
-
*
|
|
10
|
-
* Read for its **shape**, not its contents: it asserts the service really
|
|
11
|
-
* accepted a transaction rather than answering something else with a `2xx`.
|
|
12
|
-
*/ export function readTransactionAcceptedEnvelope(body) {
|
|
13
|
-
return Effect.map(decodeEnvelope(body, 'transactionAccepted'), (envelope)=>envelope.data);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Parses the tracker's by-id response, which frames a {@link TransactionRecord}.
|
|
17
|
-
*
|
|
18
|
-
* The body is decoded against `transactionRecord`'s registered schema, so a
|
|
19
|
-
* different message wearing the name — an event, which has a `step` and no
|
|
20
|
-
* `createdAt` — is refused rather than handed back typed and wrong.
|
|
21
|
-
*/ export function readTransactionRecordEnvelope(body) {
|
|
22
|
-
return Effect.map(decodeEnvelope(body, 'transactionRecord'), (envelope)=>envelope.data);
|
|
23
|
-
}
|
|
24
|
-
export class TransactionStatusReaderTag extends Context.Service()('TransactionStatusReaderTag') {
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=record.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/record.ts"],"sourcesContent":["// Evaluated for its registrations: this reader decodes against them.\nimport './messages.js';\n\nimport {\n decodeEnvelope,\n type EntifixFailure,\n type EntityId,\n type ProtocolFailure,\n type StoreFault,\n} from '@entifix/core';\nimport { Context, Effect } from 'effect';\n\nimport type { TransactionEvent, TransactionState } from './event.js';\n\n/**\n * The the saga tracker's persisted view of a transaction, folded from the\n * events it observes. It is the source of truth a client polls.\n */\nexport interface TransactionRecord {\n transactionId: string;\n entity: string;\n state: TransactionState;\n code?: string;\n entityId?: EntityId;\n error?: string;\n createdAt: string;\n updatedAt: string;\n /**\n * Whose organization this transaction happened in, folded from the event.\n *\n * The `saga` store is control-plane and single-partition — it holds every\n * organization's records by design — so isolation on the read routes has to be\n * this filter. A record written before the member existed carries none and is\n * therefore readable by nobody, which is the direction to fail.\n */\n organizationId?: string;\n}\n\n/**\n * Port the manager tracks transactions through. Implemented over Mongo in the\n * service; framework-free here so the engine/manager stay environment-agnostic.\n */\nexport interface TransactionStore {\n /** Folds an event into the record, creating it on first sight. */\n upsertFromEvent(\n event: TransactionEvent,\n ): Effect.Effect<TransactionRecord, StoreFault>;\n get(\n transactionId: string,\n ): Effect.Effect<TransactionRecord | undefined, StoreFault>;\n // There is deliberately no `list`. The `saga` store is control-plane and\n // single-partition, so an unfiltered index is every organization's\n // transactions — which is why there is no `GET /api/transaction` list.\n // Anything that needs a set of records asks for one narrow enough to scope,\n // the way `findStale` does.\n /** Non-terminal records not updated within `olderThanMs` — recovery input. */\n findStale(\n olderThanMs: number,\n ): Effect.Effect<readonly TransactionRecord[], StoreFault>;\n markStale(transactionId: string): Effect.Effect<void, StoreFault>;\n /**\n * How many records sit in each state — the recovery sweep samples it.\n *\n * ⚠️ **This is a count, and is not the `list` above.** It returns no record,\n * no id and no organization, so it does not reopen the list surface removed\n * `GET /api/transaction` for: an unfiltered *listing* of this store is every\n * organization's transactions, while a total of how many are `STALE` is a\n * fleet health number that names nobody. The distinction is the whole reason\n * one is here and the other is refused.\n *\n * It exists so `STALE` is something a dashboard shows rather than something a\n * poll discovers — which is what the recovery sweep, whose only action is to\n * apply that label, otherwise leaves entirely unobservable.\n */\n countByState(): Effect.Effect<Record<TransactionState, number>, StoreFault>;\n}\n\nexport class TransactionStoreTag extends Context.Service<\n TransactionStoreTag,\n TransactionStore\n>()('TransactionStoreTag') {}\n\n/**\n * What a service answers a `202` with: the id to poll, and the state it starts\n * in.\n *\n * ⚠️ **Not a {@link TransactionRecord}, which is why it has its own\n * discriminant.** Nothing has been folded yet — there is no `createdAt`, no\n * entity id, and no code, because the write has not run. Framing it as a record\n * meant the browser's accept-shape assertion was checking a name that the\n * by-id route and the bus payload also answered to, so it asserted nothing it\n * claimed to.\n */\nexport interface TransactionAccepted {\n transactionId: string;\n state: TransactionState;\n}\n\n/**\n * Parses a `202` accept body, for a browser about to start polling.\n *\n * Read for its **shape**, not its contents: it asserts the service really\n * accepted a transaction rather than answering something else with a `2xx`.\n */\nexport function readTransactionAcceptedEnvelope(\n body: unknown,\n): Effect.Effect<TransactionAccepted, ProtocolFailure> {\n return Effect.map(\n decodeEnvelope(body, 'transactionAccepted'),\n envelope => envelope.data as TransactionAccepted,\n );\n}\n\n/**\n * Parses the tracker's by-id response, which frames a {@link TransactionRecord}.\n *\n * The body is decoded against `transactionRecord`'s registered schema, so a\n * different message wearing the name — an event, which has a `step` and no\n * `createdAt` — is refused rather than handed back typed and wrong.\n */\nexport function readTransactionRecordEnvelope(\n body: unknown,\n): Effect.Effect<TransactionRecord, ProtocolFailure> {\n return Effect.map(\n decodeEnvelope(body, 'transactionRecord'),\n envelope => envelope.data as TransactionRecord,\n );\n}\n\n/**\n * Reads one transaction's record, for a browser reconciling a write it started.\n *\n * ⚠️ **`undefined` means _not tracked yet_, not _failed_.** `accepted` reaches\n * the tracker over the bus, so with the broker down the entity write commits —\n * the outbox is in the same Mongo transaction — while no event is ever\n * published and this answers `404`. That is a write in perfect health, and a\n * caller that rolls back on it un-renders a record that is about to appear, at\n * exactly the moment nobody can tell a UI bug from an outage. Only `FAILED` and\n * `STALE` are terminal.\n */\nexport interface TransactionStatusReader {\n read(\n transactionId: string,\n ): Effect.Effect<TransactionRecord | undefined, EntifixFailure>;\n}\n\nexport class TransactionStatusReaderTag extends Context.Service<\n TransactionStatusReaderTag,\n TransactionStatusReader\n>()('TransactionStatusReaderTag') {}\n"],"names":["decodeEnvelope","Context","Effect","TransactionStoreTag","Service","readTransactionAcceptedEnvelope","body","map","envelope","data","readTransactionRecordEnvelope","TransactionStatusReaderTag"],"mappings":"AAAA,qEAAqE;AACrE,OAAO,gBAAgB;AAEvB,SACEA,cAAc,QAKT,gBAAgB;AACvB,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AAmEzC,OAAO,MAAMC,4BAA4BF,QAAQG,OAAO,GAGpD;AAAwB;AAkB5B;;;;;CAKC,GACD,OAAO,SAASC,gCACdC,IAAa;IAEb,OAAOJ,OAAOK,GAAG,CACfP,eAAeM,MAAM,wBACrBE,CAAAA,WAAYA,SAASC,IAAI;AAE7B;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,8BACdJ,IAAa;IAEb,OAAOJ,OAAOK,GAAG,CACfP,eAAeM,MAAM,sBACrBE,CAAAA,WAAYA,SAASC,IAAI;AAE7B;AAmBA,OAAO,MAAME,mCAAmCV,QAAQG,OAAO,GAG3D;AAA+B"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Richardson's classification, and adopting the vocabulary is most of the answer
|
|
3
|
-
* to "which steps are compensable at all".
|
|
4
|
-
*
|
|
5
|
-
* - `compensatable` — before the point of no return; a failure downstream
|
|
6
|
-
* reverses it.
|
|
7
|
-
* - `pivot` — the point of no return. Once it commits, the saga goes forward.
|
|
8
|
-
* - `retriable` — after the pivot; no compensation exists, so the only path is
|
|
9
|
-
* to retry until it succeeds.
|
|
10
|
-
*/
|
|
11
|
-
export type SagaStepKind = 'compensatable' | 'pivot' | 'retriable';
|
|
12
|
-
/** The HTTP verbs a step may be dispatched with. */
|
|
13
|
-
export type SagaMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
14
|
-
/**
|
|
15
|
-
* One call a step makes, as a template rather than a closure.
|
|
16
|
-
*
|
|
17
|
-
* `path` may carry `{…}` placeholders resolved by field path against the step's
|
|
18
|
-
* recorded outcome — `/api/reservation/{outcome.data.id}`.
|
|
19
|
-
*
|
|
20
|
-
* ⚠️ **A template rather than a callback, and that is the constraint that
|
|
21
|
-
* shaped the whole type.** A callback would have to name the participant's
|
|
22
|
-
* types, and one domain package may not import another — which is exactly the
|
|
23
|
-
* import that has no legal home and the reason a definition is **data** in the
|
|
24
|
-
* first place.
|
|
25
|
-
*/
|
|
26
|
-
export interface SagaCall {
|
|
27
|
-
readonly method: SagaMethod;
|
|
28
|
-
readonly path: string;
|
|
29
|
-
}
|
|
30
|
-
/** One step of a flow. */
|
|
31
|
-
export interface SagaStep {
|
|
32
|
-
/** Unique within the definition; half of the command id `<sagaId>:<stepId>`. */
|
|
33
|
-
readonly id: string;
|
|
34
|
-
/**
|
|
35
|
-
* Which service answers it, as a **configuration key** — never a URI.
|
|
36
|
-
*
|
|
37
|
-
* A URI in a definition is a deployment fact written into a business
|
|
38
|
-
* artifact, and it is what makes a definition untestable and un-relocatable.
|
|
39
|
-
* The same lookup yields the crossing token for that participant, so a
|
|
40
|
-
* definition carries no secret and never could.
|
|
41
|
-
*/
|
|
42
|
-
readonly participant: string;
|
|
43
|
-
readonly command: SagaCall;
|
|
44
|
-
/** Required on a `compensatable` step, forbidden on every other kind. */
|
|
45
|
-
readonly compensation?: SagaCall;
|
|
46
|
-
readonly kind: SagaStepKind;
|
|
47
|
-
/**
|
|
48
|
-
* Dispatch one call per element of this step's input, rather than one call.
|
|
49
|
-
*
|
|
50
|
-
* ⚠️ **Cardinality is data, because it has to be.** Checkout reserves once per
|
|
51
|
-
* vendor and how many vendors is known only from the cart, so writing that as
|
|
52
|
-
* N steps would mean generating a definition per request — at which point it
|
|
53
|
-
* is no longer data, and the whole construction collapses back into the class
|
|
54
|
-
* that has no legal home.
|
|
55
|
-
*
|
|
56
|
-
* The consequence carried by {@link SagaStepOutcome}: **the unit of
|
|
57
|
-
* compensation is the call, not the step.** Five lines with three holds taken
|
|
58
|
-
* and the fourth refused must release exactly three.
|
|
59
|
-
*/
|
|
60
|
-
readonly fanOut?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Fan out over an **earlier step's successful calls** instead of over an
|
|
63
|
-
* input the caller supplied.
|
|
64
|
-
*
|
|
65
|
-
* ⚠️ **Without this a later step cannot address what an earlier one created**,
|
|
66
|
-
* and checkout is the case that proves it. `convert-reservation` needs one
|
|
67
|
-
* call per hold, addressed by the reservation id — which stock-service mints,
|
|
68
|
-
* so the caller cannot know it when it starts the flow. Supplying the ids as
|
|
69
|
-
* input is impossible, and generating a definition per request is the thing
|
|
70
|
-
* a definition-as-data exists to avoid.
|
|
71
|
-
*
|
|
72
|
-
* Each element inherits that call's `organizationId`, so a tenant-plane
|
|
73
|
-
* participant reaches the same tenant it did the first time, and the `path`
|
|
74
|
-
* template resolves against `{outcome.…}` — the same scope a compensation
|
|
75
|
-
* gets, for the same reason: the id being addressed is in the response body.
|
|
76
|
-
*
|
|
77
|
-
* Implies {@link fanOut}. It names a step that must appear **before** this one,
|
|
78
|
-
* and `defineSaga` refuses a forward or self reference at module load.
|
|
79
|
-
*/
|
|
80
|
-
readonly fanOutFrom?: string;
|
|
81
|
-
}
|
|
82
|
-
/** A flow, as the data a generic engine walks. */
|
|
83
|
-
export interface SagaDefinition {
|
|
84
|
-
readonly name: string;
|
|
85
|
-
/**
|
|
86
|
-
* What a caller must hold to run this flow, as a `<domain>:<entity>:<action>`
|
|
87
|
-
* string.
|
|
88
|
-
*
|
|
89
|
-
* ⚠️ **On the definition rather than on the route**, so the route that runs a
|
|
90
|
-
* flow stays generic. The alternative was one permission for every saga, which
|
|
91
|
-
* would make "may run a flow" a single capability regardless of what the flow
|
|
92
|
-
* does — and checkout writes an order.
|
|
93
|
-
*
|
|
94
|
-
* It is a plain string here rather than authz's `Permission`: this package is
|
|
95
|
-
* T2, and `@entifix/authz` sits above it at T4. The service that
|
|
96
|
-
* mounts the route resolves the string against
|
|
97
|
-
* `SERVICE_CROSSING_PERMISSIONS`, which is where the closed list belongs.
|
|
98
|
-
*/
|
|
99
|
-
readonly permission: string;
|
|
100
|
-
readonly steps: readonly SagaStep[];
|
|
101
|
-
}
|
|
102
|
-
/** What one dispatched call returned, kept so its compensation can read it. */
|
|
103
|
-
export interface SagaCallOutcome {
|
|
104
|
-
/** The fan-out element this call was made for; `0` on a single-call step. */
|
|
105
|
-
readonly index: number;
|
|
106
|
-
readonly status: number;
|
|
107
|
-
readonly body: unknown;
|
|
108
|
-
/**
|
|
109
|
-
* The organization this call acted for, carried so its compensation acts on
|
|
110
|
-
* the same one.
|
|
111
|
-
*
|
|
112
|
-
* ⚠️ **Not derivable from the outcome, and its absence is silent.** A
|
|
113
|
-
* tenant-plane participant resolves its storage handle from
|
|
114
|
-
* `x-organization-id`, so a compensation dispatched without it is refused
|
|
115
|
-
* `400` — and the saga strands with every hold still in place while the
|
|
116
|
-
* engine reports it tried. Measured on the live lab: two holds taken, a third
|
|
117
|
-
* line refused, and both releases rejected for a missing header.
|
|
118
|
-
*/
|
|
119
|
-
readonly organizationId?: string;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* What one step is given to work with — one element per call on a `fanOut` step,
|
|
123
|
-
* exactly one otherwise.
|
|
124
|
-
*/
|
|
125
|
-
export interface SagaStepInput {
|
|
126
|
-
/** The body to send. */
|
|
127
|
-
readonly body?: unknown;
|
|
128
|
-
/** The explicit organization, for a tenant-plane participant. */
|
|
129
|
-
readonly organizationId?: string;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* The inputs each step needs, keyed by step id, supplied by the caller.
|
|
133
|
-
*
|
|
134
|
-
* ⚠️ **Here rather than in the engine**, because the durable instance carries
|
|
135
|
-
* it: a resumed walk is a different process reading this off the store, so the
|
|
136
|
-
* port that persists it may not reach up into the engine to name its type.
|
|
137
|
-
*/
|
|
138
|
-
export type SagaInputs = Readonly<Record<string, readonly SagaStepInput[]>>;
|
|
139
|
-
/** Every call one step made, in dispatch order. */
|
|
140
|
-
export interface SagaStepOutcome {
|
|
141
|
-
readonly stepId: string;
|
|
142
|
-
readonly calls: readonly SagaCallOutcome[];
|
|
143
|
-
/**
|
|
144
|
-
* Why this step stopped, when it did — absent on a step that succeeded.
|
|
145
|
-
*
|
|
146
|
-
* ⚠️ **Without it a resumed walk cannot tell a finished step from a refused
|
|
147
|
-
* one.** `calls` holds what succeeded either way, so the two are
|
|
148
|
-
* indistinguishable on the stored document, and the distinction is what
|
|
149
|
-
* decides whether the pivot committed. Guessing it either compensates behind
|
|
150
|
-
* a capture or walks past a refusal.
|
|
151
|
-
*/
|
|
152
|
-
readonly error?: string;
|
|
153
|
-
/**
|
|
154
|
-
* Whether this step's calls have already been given back.
|
|
155
|
-
*
|
|
156
|
-
* ⚠️ **What keeps a resumed unwind from compensating twice.** A second
|
|
157
|
-
* `DELETE` of an order already deleted answers `404`, which the dispatcher
|
|
158
|
-
* classifies as a refusal, which strands a flow that was in fact reversed.
|
|
159
|
-
*/
|
|
160
|
-
readonly compensated?: boolean;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Validate a definition and return it, or throw.
|
|
164
|
-
*
|
|
165
|
-
* ⚠️ **At load, not at the step.** A fault that only appears on the unlucky path
|
|
166
|
-
* is a fault that ships — the same reasoning that makes an unrenderable action
|
|
167
|
-
* cell throw at render. Every definition is therefore constructed through this
|
|
168
|
-
* function at module scope, and loaded in a spec: a definition that never loads
|
|
169
|
-
* is a definition that never fails.
|
|
170
|
-
*/
|
|
171
|
-
export declare function defineSaga(definition: SagaDefinition): SagaDefinition;
|
|
172
|
-
/**
|
|
173
|
-
* The command id one call is dispatched under.
|
|
174
|
-
*
|
|
175
|
-
* `<sagaId>:<stepId>` — the shape `transactionEventId` already uses for events,
|
|
176
|
-
* so the `TransactionInbox` serves saga steps with no second dedup store and
|
|
177
|
-
* no second key. A fan-out step appends the element index, because its calls are
|
|
178
|
-
* separate side effects that must each be claimed on their own.
|
|
179
|
-
*/
|
|
180
|
-
export declare const sagaCommandId: (sagaId: string, stepId: string, index?: number) => string;
|
|
181
|
-
//# sourceMappingURL=saga-definition.d.ts.map
|