@entifix/transactions 0.11.0 → 0.12.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/dist/contracts/flow-messages.d.ts +3 -2
- package/dist/contracts/flow-messages.d.ts.map +1 -1
- package/dist/contracts/flow-messages.js.map +1 -1
- package/dist/contracts/outbox.d.ts +18 -0
- package/dist/contracts/outbox.d.ts.map +1 -1
- package/dist/contracts/outbox.js +16 -0
- package/dist/contracts/outbox.js.map +1 -1
- package/dist/engine/in-memory-bulkhead.d.ts +20 -0
- package/dist/engine/in-memory-bulkhead.d.ts.map +1 -0
- package/dist/engine/in-memory-bulkhead.js +38 -0
- package/dist/engine/in-memory-bulkhead.js.map +1 -0
- package/dist/engine/in-memory-circuit-breaker.d.ts +28 -0
- package/dist/engine/in-memory-circuit-breaker.d.ts.map +1 -0
- package/dist/engine/in-memory-circuit-breaker.js +151 -0
- package/dist/engine/in-memory-circuit-breaker.js.map +1 -0
- package/dist/engine/index.d.ts +4 -0
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +4 -0
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/outbox-metrics.d.ts +47 -0
- package/dist/engine/outbox-metrics.d.ts.map +1 -0
- package/dist/engine/outbox-metrics.js +68 -0
- package/dist/engine/outbox-metrics.js.map +1 -0
- package/dist/engine/outbox-relay.d.ts +102 -0
- package/dist/engine/outbox-relay.d.ts.map +1 -0
- package/dist/engine/outbox-relay.js +111 -0
- package/dist/engine/outbox-relay.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/ports/bulkhead.d.ts +28 -0
- package/dist/ports/bulkhead.d.ts.map +1 -0
- package/dist/ports/bulkhead.js +18 -0
- package/dist/ports/bulkhead.js.map +1 -0
- package/dist/ports/circuit-breaker.d.ts +62 -0
- package/dist/ports/circuit-breaker.d.ts.map +1 -0
- package/dist/ports/circuit-breaker.js +42 -0
- package/dist/ports/circuit-breaker.js.map +1 -0
- package/dist/ports/event-bus.d.ts +10 -0
- package/dist/ports/event-bus.d.ts.map +1 -1
- package/dist/ports/event-bus.js.map +1 -1
- package/dist/ports/flow-engine.d.ts +6 -0
- package/dist/ports/flow-engine.d.ts.map +1 -1
- package/dist/ports/flow-engine.js.map +1 -1
- package/dist/ports/participant-client.d.ts +32 -0
- package/dist/ports/participant-client.d.ts.map +1 -0
- package/dist/ports/participant-client.js +5 -0
- package/dist/ports/participant-client.js.map +1 -0
- package/dist/reactions/on.d.ts.map +1 -1
- package/dist/reactions/on.js +2 -1
- package/dist/reactions/on.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/engine/outbox-metrics.ts"],"sourcesContent":["import { Effect, Metric } from 'effect';\n\nimport type { OutboxStats } from '../contracts/outbox.js';\n\n/**\n * The outbox half of the framework's first metric set; the bus half is in\n * `@entifix/amqp`.\n *\n * It lives beside the relay that samples it rather than in any one service,\n * because three slices now own an outbox — `catalog`, `order` and `payment` —\n * and the warning below is exactly why a copy per service is not an option: an\n * Effect metric is keyed on its **description**, so three hand-maintained\n * definitions of `outbox_pending_entries` are three series the moment one\n * wording drifts, and a dashboard would go quiet without failing anything.\n *\n * ⚠️ The metric objects are **exported so a reader uses the same instance**. An\n * Effect metric's registry key includes its description, so rebuilding one by\n * name without the description addresses a different series that is permanently\n * zero — a silent way to write a query against nothing.\n *\n * These are gauges rather than counters because they describe a *backlog*: the\n * question is how many are waiting right now, not how many there have ever\n * been. They are sampled by the two daemons that already run on an interval, so\n * nothing new is scheduled to produce them.\n *\n * ⚠️ **A dimensionless gauge reaches Prometheus with a `_ratio` suffix.** That\n * is the OTel exporter's convention for unit `1`, not a mistake here, so\n * `outbox_pending_entries` is queried as `outbox_pending_entries_ratio`.\n * Counters are unaffected. Where a metric has a real unit, tag it — see\n * {@link outboxOldestPendingAge}.\n */\n\n/** Unsent, un-quarantined entries, per database. */\nexport const outboxPending = Metric.gauge('outbox_pending_entries', {\n description: 'Unsent, un-quarantined outbox entries, by database.',\n});\n\n/**\n * Age in seconds of the oldest unsent entry, per database.\n *\n * **The metric that makes a stuck relay visible.** Quarantine gave the relay a\n * ceiling, so an entry that can never publish is quarantined and skipped rather\n * than blocking the head of the line forever — but that is reported only as a\n * log line, so how far behind the outbox has fallen is otherwise unanswerable.\n * A depth that is flat and an age that climbs is the signature of a relay whose\n * head has stopped moving.\n */\nexport const outboxOldestPendingAge: Metric.Gauge<number> = Metric.gauge(\n 'outbox_oldest_pending_age',\n {\n description:\n 'Age of the oldest unsent outbox entry, by database. Zero when ' +\n 'the outbox is empty.',\n },\n).pipe(\n // ⚠️ **The unit is carried as a tag, and that is the only way to set it.**\n // `@effect/opentelemetry`'s producer reads `tags.unit ?? tags.time_unit ??\n // '1'`, so a gauge with no `unit` tag is exported as dimensionless — and the\n // Prometheus exporter then appends `_ratio` to a dimensionless gauge's name.\n // Measured: this series arrived as `outbox_oldest_pending_age_seconds_ratio`,\n // a duration announcing itself as a ratio. Tagging it makes the exporter name\n // it `_seconds`, which is why the name above no longer carries that suffix\n // itself. The cost is a constant `unit` label, because the producer builds the\n // datapoint attributes from the same tag set it reads the unit from.\n Metric.withAttributes({ unit: 's' }),\n);\n\n/** Entries past the ceiling, which nothing retries and nothing deletes. */\nexport const outboxQuarantined = Metric.gauge('outbox_quarantined_entries', {\n description: 'Quarantined outbox entries, by database.',\n});\n\n/** Record one outbox's depth and age. */\nexport const recordOutboxStats = (database: string, stats: OutboxStats) => {\n const tagged = (metric: Metric.Gauge<number>) =>\n Metric.withAttributes(metric, { database });\n\n // Zero when nothing is waiting. The alternative — not reporting the series —\n // reads on most dashboards as \"no data\", which is indistinguishable from the\n // exporter having broken at exactly the moment a healthy relay looks idle.\n const ageSeconds =\n stats.oldestPendingAt === undefined\n ? 0\n : Math.max(0, (Date.now() - Date.parse(stats.oldestPendingAt)) / 1000);\n\n return Metric.update(tagged(outboxPending), stats.pending).pipe(\n Effect.andThen(Metric.update(tagged(outboxOldestPendingAge), ageSeconds)),\n Effect.andThen(Metric.update(tagged(outboxQuarantined), stats.quarantined)),\n );\n};\n"],"names":["Effect","Metric","outboxPending","gauge","description","outboxOldestPendingAge","pipe","withAttributes","unit","outboxQuarantined","recordOutboxStats","database","stats","tagged","metric","ageSeconds","oldestPendingAt","undefined","Math","max","Date","now","parse","update","pending","andThen","quarantined"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAIxC;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GAED,kDAAkD,GAClD,OAAO,MAAMC,gBAAgBD,OAAOE,KAAK,CAAC,0BAA0B;IAClEC,aAAa;AACf,GAAG;AAEH;;;;;;;;;CASC,GACD,OAAO,MAAMC,yBAA+CJ,OAAOE,KAAK,CACtE,6BACA;IACEC,aACE,mEACA;AACJ,GACAE,IAAI,CACJ,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,+EAA+E;AAC/E,qEAAqE;AACrEL,OAAOM,cAAc,CAAC;IAAEC,MAAM;AAAI,IAClC;AAEF,yEAAyE,GACzE,OAAO,MAAMC,oBAAoBR,OAAOE,KAAK,CAAC,8BAA8B;IAC1EC,aAAa;AACf,GAAG;AAEH,uCAAuC,GACvC,OAAO,MAAMM,oBAAoB,CAACC,UAAkBC;IAClD,MAAMC,SAAS,CAACC,SACdb,OAAOM,cAAc,CAACO,QAAQ;YAAEH;QAAS;IAE3C,6EAA6E;IAC7E,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAMI,aACJH,MAAMI,eAAe,KAAKC,YACtB,IACAC,KAAKC,GAAG,CAAC,GAAG,AAACC,CAAAA,KAAKC,GAAG,KAAKD,KAAKE,KAAK,CAACV,MAAMI,eAAe,CAAA,IAAK;IAErE,OAAOf,OAAOsB,MAAM,CAACV,OAAOX,gBAAgBU,MAAMY,OAAO,EAAElB,IAAI,CAC7DN,OAAOyB,OAAO,CAACxB,OAAOsB,MAAM,CAACV,OAAOR,yBAAyBU,cAC7Df,OAAOyB,OAAO,CAACxB,OAAOsB,MAAM,CAACV,OAAOJ,oBAAoBG,MAAMc,WAAW;AAE7E,EAAE"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ShutdownRegistryTag } from '@entifix/business';
|
|
2
|
+
import { Duration, Effect } from 'effect';
|
|
3
|
+
import { type Outbox, type OutboxStats } from '../contracts/outbox.js';
|
|
4
|
+
import type { EventBus } from '../ports/event-bus.js';
|
|
5
|
+
export declare const SWEEP_INTERVAL: Duration.Duration;
|
|
6
|
+
/** Entries drained per pass, per database. */
|
|
7
|
+
export declare const BATCH = 100;
|
|
8
|
+
/**
|
|
9
|
+
* What a relay pass did, for the host to log
|
|
10
|
+
* ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).
|
|
11
|
+
*
|
|
12
|
+
* The relay decides nothing about level or sink: it says what happened and the
|
|
13
|
+
* fork site that started it — the slice's shell — decides how loud that is. A
|
|
14
|
+
* `failure` is whatever the store or the bus failed with; a typed one carries
|
|
15
|
+
* its code and category for the log line.
|
|
16
|
+
*/
|
|
17
|
+
export type RelayOutcome = {
|
|
18
|
+
readonly _tag: 'drained';
|
|
19
|
+
readonly database: string;
|
|
20
|
+
readonly sent: number;
|
|
21
|
+
} | {
|
|
22
|
+
readonly _tag: 'quarantined';
|
|
23
|
+
readonly database: string;
|
|
24
|
+
readonly eventId: string;
|
|
25
|
+
readonly eventName: string;
|
|
26
|
+
readonly attempts: number;
|
|
27
|
+
readonly code: string;
|
|
28
|
+
readonly reason: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly _tag: 'sweepFailed';
|
|
31
|
+
readonly database?: string;
|
|
32
|
+
readonly failure: unknown;
|
|
33
|
+
} | {
|
|
34
|
+
readonly _tag: 'drainFailed';
|
|
35
|
+
readonly database: string;
|
|
36
|
+
readonly failure: unknown;
|
|
37
|
+
};
|
|
38
|
+
/** Where a relay's outcomes go. The host's fork site supplies it. */
|
|
39
|
+
export type RelayOutcomeSink = (outcome: RelayOutcome) => Effect.Effect<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Hears nothing. The default only so a spec can start a relay without one —
|
|
42
|
+
* a host that passes no sink has a relay nobody can watch.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ignoreRelayOutcome: RelayOutcomeSink;
|
|
45
|
+
/** What {@link drainOutbox} needs beyond the ports it publishes through. */
|
|
46
|
+
export interface DrainOptions {
|
|
47
|
+
readonly maxAttempts: number;
|
|
48
|
+
/** The database being drained; carried so a quarantine log names it. */
|
|
49
|
+
readonly database: string;
|
|
50
|
+
/** Where the pass reports what it did; see {@link RelayOutcome}. */
|
|
51
|
+
readonly onOutcome?: RelayOutcomeSink;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Publish one batch of pending entries, oldest first, **in order within each
|
|
55
|
+
* aggregate** ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)),
|
|
56
|
+
* and answer how many went.
|
|
57
|
+
*
|
|
58
|
+
* - A **still-deliverable** failure holds back the rest of its own aggregate
|
|
59
|
+
* for this pass, which is what stops a terminal event overtaking the
|
|
60
|
+
* `accepted` of the same transaction — and only its own: every other
|
|
61
|
+
* aggregate keeps draining.
|
|
62
|
+
* - A **quarantined** failure moves on. An entry that can never publish must
|
|
63
|
+
* not hold its aggregate forever, and a consumer discards whatever older
|
|
64
|
+
* version arrives after a newer one anyway.
|
|
65
|
+
*/
|
|
66
|
+
export declare const drainOutbox: (outbox: Outbox, bus: EventBus, options: DrainOptions) => Effect.Effect<number, import("@entifix/core").StoreFailure, never>;
|
|
67
|
+
/**
|
|
68
|
+
* Sample a sweep's depth and age.
|
|
69
|
+
*
|
|
70
|
+
* Defaults to {@link recordOutboxStats}, and a caller overrides it only to
|
|
71
|
+
* assert what was sampled. There is no "no sink" option on purpose: an outbox
|
|
72
|
+
* whose depth nothing reports is the failure the gauges exist to make visible.
|
|
73
|
+
*/
|
|
74
|
+
export type OutboxStatsSink = (database: string, stats: OutboxStats) => Effect.Effect<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Drain the one database this service owns, then sample its depth.
|
|
77
|
+
*
|
|
78
|
+
* The single-database counterpart to `startTenantOutboxRelay`. A
|
|
79
|
+
* platform-plane store is one named database, so there is nothing to enumerate
|
|
80
|
+
* and `listDatabases` — which needs a `MongoClient` and cluster-wide rights —
|
|
81
|
+
* never comes into it.
|
|
82
|
+
*
|
|
83
|
+
* Stats are sampled **after** the drain, so the gauge reports what is still
|
|
84
|
+
* waiting rather than what was waiting when the pass began.
|
|
85
|
+
*
|
|
86
|
+
* Every failure is caught and reported as `sweepFailed`. This runs inside
|
|
87
|
+
* `Effect.forever`, and an error that escapes ends the daemon silently — a
|
|
88
|
+
* relay that stopped is indistinguishable from a relay with nothing to do.
|
|
89
|
+
*/
|
|
90
|
+
export declare const sweepOutbox: (outbox: Outbox, bus: EventBus, options: DrainOptions & {
|
|
91
|
+
readonly onStats?: OutboxStatsSink;
|
|
92
|
+
}) => Effect.Effect<void, never, never>;
|
|
93
|
+
/**
|
|
94
|
+
* Runs `sweepOnce` every {@link SWEEP_INTERVAL}, and once more on the way out.
|
|
95
|
+
*
|
|
96
|
+
* Interrupting the daemon before that last pass is what stops two sweeps
|
|
97
|
+
* publishing the same entry; running the pass is what the hook is for — an
|
|
98
|
+
* event committed a moment before shutdown would otherwise wait out the next
|
|
99
|
+
* process's whole interval.
|
|
100
|
+
*/
|
|
101
|
+
export declare const runRelayDaemon: (sweepOnce: Effect.Effect<void>) => Effect.Effect<void, never, ShutdownRegistryTag>;
|
|
102
|
+
//# sourceMappingURL=outbox-relay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox-relay.d.ts","sourceRoot":"","sources":["../../src/eng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O,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAAoC,CAAC;AAEtE,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,KAAK,QAAQ,EACb,SAAS,YAAY,uEA6CnB,CAAC;AAEL;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,KACf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAEzB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,KAAK,QAAQ,EACb,SAAS,YAAY,GAAG;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAA;CAAE,sCAc7D,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,oDAazD,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ShutdownRegistryTag } from '@entifix/business';
|
|
2
|
+
import { Duration, Effect, Fiber, Result } from 'effect';
|
|
3
|
+
import { aggregateKey } from '../contracts/outbox.js';
|
|
4
|
+
import { recordOutboxStats } from './outbox-metrics.js';
|
|
5
|
+
/** How often the sweep looks for entries the fast path did not carry. */ /**
|
|
6
|
+
* What an outbox entry records as the reason its publish failed: the failure's
|
|
7
|
+
* own message, or its code when it carries none — never empty, because an
|
|
8
|
+
* operator reading a quarantined entry has nothing else to go on.
|
|
9
|
+
*/ const failureText = (failure)=>failure.message === '' ? failure.code : failure.message;
|
|
10
|
+
export const SWEEP_INTERVAL = Duration.seconds(15);
|
|
11
|
+
/** Entries drained per pass, per database. */ export const BATCH = 100;
|
|
12
|
+
/**
|
|
13
|
+
* Hears nothing. The default only so a spec can start a relay without one —
|
|
14
|
+
* a host that passes no sink has a relay nobody can watch.
|
|
15
|
+
*/ export const ignoreRelayOutcome = ()=>Effect.void;
|
|
16
|
+
/**
|
|
17
|
+
* Publish one batch of pending entries, oldest first, **in order within each
|
|
18
|
+
* aggregate** ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)),
|
|
19
|
+
* and answer how many went.
|
|
20
|
+
*
|
|
21
|
+
* - A **still-deliverable** failure holds back the rest of its own aggregate
|
|
22
|
+
* for this pass, which is what stops a terminal event overtaking the
|
|
23
|
+
* `accepted` of the same transaction — and only its own: every other
|
|
24
|
+
* aggregate keeps draining.
|
|
25
|
+
* - A **quarantined** failure moves on. An entry that can never publish must
|
|
26
|
+
* not hold its aggregate forever, and a consumer discards whatever older
|
|
27
|
+
* version arrives after a newer one anyway.
|
|
28
|
+
*/ export const drainOutbox = (outbox, bus, options)=>Effect.gen(function*() {
|
|
29
|
+
var _options_onOutcome;
|
|
30
|
+
const entries = yield* outbox.pending(BATCH);
|
|
31
|
+
const held = new Set();
|
|
32
|
+
let sent = 0;
|
|
33
|
+
const report = (_options_onOutcome = options.onOutcome) != null ? _options_onOutcome : ignoreRelayOutcome;
|
|
34
|
+
for (const entry of entries){
|
|
35
|
+
const key = aggregateKey(entry.aggregate);
|
|
36
|
+
if (held.has(key)) continue;
|
|
37
|
+
const outcome = yield* Effect.result(bus.publish(entry.event));
|
|
38
|
+
if (Result.isFailure(outcome)) {
|
|
39
|
+
const attempts = entry.attempts + 1;
|
|
40
|
+
const quarantine = attempts >= options.maxAttempts;
|
|
41
|
+
yield* outbox.recordFailure(entry, failureText(outcome.failure), quarantine);
|
|
42
|
+
if (!quarantine) {
|
|
43
|
+
held.add(key);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
yield* report({
|
|
47
|
+
_tag: 'quarantined',
|
|
48
|
+
database: options.database,
|
|
49
|
+
eventId: entry.eventId,
|
|
50
|
+
eventName: entry.event.name,
|
|
51
|
+
attempts,
|
|
52
|
+
code: outcome.failure.code,
|
|
53
|
+
reason: failureText(outcome.failure)
|
|
54
|
+
});
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
yield* outbox.markSent(entry);
|
|
58
|
+
sent += 1;
|
|
59
|
+
}
|
|
60
|
+
yield* report({
|
|
61
|
+
_tag: 'drained',
|
|
62
|
+
database: options.database,
|
|
63
|
+
sent
|
|
64
|
+
});
|
|
65
|
+
return sent;
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Drain the one database this service owns, then sample its depth.
|
|
69
|
+
*
|
|
70
|
+
* The single-database counterpart to `startTenantOutboxRelay`. A
|
|
71
|
+
* platform-plane store is one named database, so there is nothing to enumerate
|
|
72
|
+
* and `listDatabases` — which needs a `MongoClient` and cluster-wide rights —
|
|
73
|
+
* never comes into it.
|
|
74
|
+
*
|
|
75
|
+
* Stats are sampled **after** the drain, so the gauge reports what is still
|
|
76
|
+
* waiting rather than what was waiting when the pass began.
|
|
77
|
+
*
|
|
78
|
+
* Every failure is caught and reported as `sweepFailed`. This runs inside
|
|
79
|
+
* `Effect.forever`, and an error that escapes ends the daemon silently — a
|
|
80
|
+
* relay that stopped is indistinguishable from a relay with nothing to do.
|
|
81
|
+
*/ export const sweepOutbox = (outbox, bus, options)=>Effect.gen(function*() {
|
|
82
|
+
var _options_onStats;
|
|
83
|
+
yield* drainOutbox(outbox, bus, options);
|
|
84
|
+
const sink = (_options_onStats = options.onStats) != null ? _options_onStats : recordOutboxStats;
|
|
85
|
+
yield* sink(options.database, (yield* outbox.stats()));
|
|
86
|
+
}).pipe(Effect.catch((failure)=>{
|
|
87
|
+
var _options_onOutcome;
|
|
88
|
+
return ((_options_onOutcome = options.onOutcome) != null ? _options_onOutcome : ignoreRelayOutcome)({
|
|
89
|
+
_tag: 'sweepFailed',
|
|
90
|
+
database: options.database,
|
|
91
|
+
failure
|
|
92
|
+
});
|
|
93
|
+
}));
|
|
94
|
+
/**
|
|
95
|
+
* Runs `sweepOnce` every {@link SWEEP_INTERVAL}, and once more on the way out.
|
|
96
|
+
*
|
|
97
|
+
* Interrupting the daemon before that last pass is what stops two sweeps
|
|
98
|
+
* publishing the same entry; running the pass is what the hook is for — an
|
|
99
|
+
* event committed a moment before shutdown would otherwise wait out the next
|
|
100
|
+
* process's whole interval.
|
|
101
|
+
*/ export const runRelayDaemon = (sweepOnce)=>Effect.gen(function*() {
|
|
102
|
+
const shutdown = yield* ShutdownRegistryTag;
|
|
103
|
+
const daemon = yield* Effect.forkDetach(sweepOnce.pipe(Effect.delay(SWEEP_INTERVAL), Effect.forever));
|
|
104
|
+
yield* shutdown.register({
|
|
105
|
+
name: 'outbox-relay',
|
|
106
|
+
phase: 'flush',
|
|
107
|
+
run: Fiber.interrupt(daemon).pipe(Effect.andThen(sweepOnce))
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=outbox-relay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/engine/outbox-relay.ts"],"sourcesContent":["import { ShutdownRegistryTag } from '@entifix/business';\nimport { Duration, Effect, Fiber, Result } from 'effect';\n\nimport {\n aggregateKey,\n type Outbox,\n type OutboxStats,\n} from '../contracts/outbox.js';\nimport type { EventBus } from '../ports/event-bus.js';\nimport { recordOutboxStats } from './outbox-metrics.js';\n\n/** How often the sweep looks for entries the fast path did not carry. */\n/**\n * What an outbox entry records as the reason its publish failed: the failure's\n * own message, or its code when it carries none — never empty, because an\n * operator reading a quarantined entry has nothing else to go on.\n */\nconst failureText = (failure: {\n readonly message: string;\n readonly code: string;\n}) => (failure.message === '' ? failure.code : failure.message);\n\nexport const SWEEP_INTERVAL = Duration.seconds(15);\n/** Entries drained per pass, per database. */\nexport const BATCH = 100;\n\n/**\n * What a relay pass did, for the host to log\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * The relay decides nothing about level or sink: it says what happened and the\n * fork site that started it — the slice's shell — decides how loud that is. A\n * `failure` is whatever the store or the bus failed with; a typed one carries\n * its code and category for the log line.\n */\nexport type RelayOutcome =\n | {\n readonly _tag: 'drained';\n readonly database: string;\n readonly sent: number;\n }\n | {\n readonly _tag: 'quarantined';\n readonly database: string;\n readonly eventId: string;\n readonly eventName: string;\n readonly attempts: number;\n readonly code: string;\n readonly reason: string;\n }\n | {\n readonly _tag: 'sweepFailed';\n readonly database?: string;\n readonly failure: unknown;\n }\n | {\n readonly _tag: 'drainFailed';\n readonly database: string;\n readonly failure: unknown;\n };\n\n/** Where a relay's outcomes go. The host's fork site supplies it. */\nexport type RelayOutcomeSink = (outcome: RelayOutcome) => Effect.Effect<void>;\n\n/**\n * Hears nothing. The default only so a spec can start a relay without one —\n * a host that passes no sink has a relay nobody can watch.\n */\nexport const ignoreRelayOutcome: RelayOutcomeSink = () => Effect.void;\n\n/** What {@link drainOutbox} needs beyond the ports it publishes through. */\nexport interface DrainOptions {\n readonly maxAttempts: number;\n /** The database being drained; carried so a quarantine log names it. */\n readonly database: string;\n /** Where the pass reports what it did; see {@link RelayOutcome}. */\n readonly onOutcome?: RelayOutcomeSink;\n}\n\n/**\n * Publish one batch of pending entries, oldest first, **in order within each\n * aggregate** ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)),\n * and answer how many went.\n *\n * - A **still-deliverable** failure holds back the rest of its own aggregate\n * for this pass, which is what stops a terminal event overtaking the\n * `accepted` of the same transaction — and only its own: every other\n * aggregate keeps draining.\n * - A **quarantined** failure moves on. An entry that can never publish must\n * not hold its aggregate forever, and a consumer discards whatever older\n * version arrives after a newer one anyway.\n */\nexport const drainOutbox = (\n outbox: Outbox,\n bus: EventBus,\n options: DrainOptions,\n) =>\n Effect.gen(function* () {\n const entries = yield* outbox.pending(BATCH);\n const held = new Set<string>();\n let sent = 0;\n const report = options.onOutcome ?? ignoreRelayOutcome;\n for (const entry of entries) {\n const key = aggregateKey(entry.aggregate);\n if (held.has(key)) continue;\n\n const outcome = yield* Effect.result(bus.publish(entry.event));\n\n if (Result.isFailure(outcome)) {\n const attempts = entry.attempts + 1;\n const quarantine = attempts >= options.maxAttempts;\n\n yield* outbox.recordFailure(\n entry,\n failureText(outcome.failure),\n quarantine,\n );\n\n if (!quarantine) {\n held.add(key);\n continue;\n }\n\n yield* report({\n _tag: 'quarantined',\n database: options.database,\n eventId: entry.eventId,\n eventName: entry.event.name,\n attempts,\n code: outcome.failure.code,\n reason: failureText(outcome.failure),\n });\n continue;\n }\n\n yield* outbox.markSent(entry);\n sent += 1;\n }\n yield* report({ _tag: 'drained', database: options.database, sent });\n return sent;\n });\n\n/**\n * Sample a sweep's depth and age.\n *\n * Defaults to {@link recordOutboxStats}, and a caller overrides it only to\n * assert what was sampled. There is no \"no sink\" option on purpose: an outbox\n * whose depth nothing reports is the failure the gauges exist to make visible.\n */\nexport type OutboxStatsSink = (\n database: string,\n stats: OutboxStats,\n) => Effect.Effect<void>;\n\n/**\n * Drain the one database this service owns, then sample its depth.\n *\n * The single-database counterpart to `startTenantOutboxRelay`. A\n * platform-plane store is one named database, so there is nothing to enumerate\n * and `listDatabases` — which needs a `MongoClient` and cluster-wide rights —\n * never comes into it.\n *\n * Stats are sampled **after** the drain, so the gauge reports what is still\n * waiting rather than what was waiting when the pass began.\n *\n * Every failure is caught and reported as `sweepFailed`. This runs inside\n * `Effect.forever`, and an error that escapes ends the daemon silently — a\n * relay that stopped is indistinguishable from a relay with nothing to do.\n */\nexport const sweepOutbox = (\n outbox: Outbox,\n bus: EventBus,\n options: DrainOptions & { readonly onStats?: OutboxStatsSink },\n) =>\n Effect.gen(function* () {\n yield* drainOutbox(outbox, bus, options);\n const sink = options.onStats ?? recordOutboxStats;\n yield* sink(options.database, yield* outbox.stats());\n }).pipe(\n Effect.catch(failure =>\n (options.onOutcome ?? ignoreRelayOutcome)({\n _tag: 'sweepFailed',\n database: options.database,\n failure,\n }),\n ),\n );\n\n/**\n * Runs `sweepOnce` every {@link SWEEP_INTERVAL}, and once more on the way out.\n *\n * Interrupting the daemon before that last pass is what stops two sweeps\n * publishing the same entry; running the pass is what the hook is for — an\n * event committed a moment before shutdown would otherwise wait out the next\n * process's whole interval.\n */\nexport const runRelayDaemon = (sweepOnce: Effect.Effect<void>) =>\n Effect.gen(function* () {\n const shutdown = yield* ShutdownRegistryTag;\n\n const daemon = yield* Effect.forkDetach(\n sweepOnce.pipe(Effect.delay(SWEEP_INTERVAL), Effect.forever),\n );\n\n yield* shutdown.register({\n name: 'outbox-relay',\n phase: 'flush',\n run: Fiber.interrupt(daemon).pipe(Effect.andThen(sweepOnce)),\n });\n });\n"],"names":["ShutdownRegistryTag","Duration","Effect","Fiber","Result","aggregateKey","recordOutboxStats","failureText","failure","message","code","SWEEP_INTERVAL","seconds","BATCH","ignoreRelayOutcome","void","drainOutbox","outbox","bus","options","gen","entries","pending","held","Set","sent","report","onOutcome","entry","key","aggregate","has","outcome","result","publish","event","isFailure","attempts","quarantine","maxAttempts","recordFailure","add","_tag","database","eventId","eventName","name","reason","markSent","sweepOutbox","sink","onStats","stats","pipe","catch","runRelayDaemon","sweepOnce","shutdown","daemon","forkDetach","delay","forever","register","phase","run","interrupt","andThen"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,oBAAoB;AACxD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,EAAEC,MAAM,QAAQ,SAAS;AAEzD,SACEC,YAAY,QAGP,yBAAyB;AAEhC,SAASC,iBAAiB,QAAQ,sBAAsB;AAExD,uEAAuE,GACvE;;;;CAIC,GACD,MAAMC,cAAc,CAACC,UAGdA,QAAQC,OAAO,KAAK,KAAKD,Q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;QACV;QACA,OAAOC,OAAO;YAAEgB,MAAM;YAAWC,UAAUxB,QAAQwB,QAAQ;YAAElB;QAAK;QAClE,OAAOA;IACT,GAAG;AAcL;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMwB,cAAc,CACzBhC,QACAC,KACAC,UAEAjB,OAAOkB,GAAG,CAAC;YAEID;QADb,OAAOH,YAAYC,QAAQC,KAAKC;QAChC,MAAM+B,QAAO/B,mBAAAA,QAAQgC,OAAO,YAAfhC,mBAAmBb;QAChC,OAAO4C,KAAK/B,QAAQwB,QAAQ,EAAE,CAAA,OAAO1B,OAAOmC,KAAK,EAAC;IACpD,GAAGC,IAAI,CACLnD,OAAOoD,KAAK,CAAC9C,CAAAA;YACVW;eAAD,EAACA,qBAAAA,QAAQQ,SAAS,YAAjBR,qBAAqBL,oBAAoB;YACxC4B,MAAM;YACNC,UAAUxB,QAAQwB,QAAQ;YAC1BnC;QACF;QAEF;AAEJ;;;;;;;CAOC,GACD,OAAO,MAAM+C,iBAAiB,CAACC,YAC7BtD,OAAOkB,GAAG,CAAC;QACT,MAAMqC,WAAW,OAAOzD;QAExB,MAAM0D,SAAS,OAAOxD,OAAOyD,UAAU,CACrCH,UAAUH,IAAI,CAACnD,OAAO0D,KAAK,CAACjD,iBAAiBT,OAAO2D,OAAO;QAG7D,OAAOJ,SAASK,QAAQ,CAAC;YACvBhB,MAAM;YACNiB,OAAO;YACPC,KAAK7D,MAAM8D,SAAS,CAACP,QAAQL,IAAI,CAACnD,OAAOgE,OAAO,CAACV;QACnD;IACF,GAAG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,13 @@ export * from './contracts/record.js';
|
|
|
9
9
|
export * from './contracts/saga-definition.js';
|
|
10
10
|
export * from './contracts/unit-of-work.js';
|
|
11
11
|
export * from './mixins/transaction-mixins.js';
|
|
12
|
+
export * from './ports/bulkhead.js';
|
|
13
|
+
export * from './ports/circuit-breaker.js';
|
|
12
14
|
export * from './ports/event-bus.js';
|
|
13
15
|
export * from './ports/event-source.js';
|
|
14
16
|
export * from './ports/flow-engine.js';
|
|
15
17
|
export * from './ports/lock-service.js';
|
|
18
|
+
export * from './ports/participant-client.js';
|
|
16
19
|
export * from './ports/retry-budget.js';
|
|
17
20
|
export * from './ports/saga-dispatcher.js';
|
|
18
21
|
export * from './ports/saga-store.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,13 @@ export * from './contracts/record.js';
|
|
|
9
9
|
export * from './contracts/saga-definition.js';
|
|
10
10
|
export * from './contracts/unit-of-work.js';
|
|
11
11
|
export * from './mixins/transaction-mixins.js';
|
|
12
|
+
export * from './ports/bulkhead.js';
|
|
13
|
+
export * from './ports/circuit-breaker.js';
|
|
12
14
|
export * from './ports/event-bus.js';
|
|
13
15
|
export * from './ports/event-source.js';
|
|
14
16
|
export * from './ports/flow-engine.js';
|
|
15
17
|
export * from './ports/lock-service.js';
|
|
18
|
+
export * from './ports/participant-client.js';
|
|
16
19
|
export * from './ports/retry-budget.js';
|
|
17
20
|
export * from './ports/saga-dispatcher.js';
|
|
18
21
|
export * from './ports/saga-store.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/flow-capability.js';\nexport * from './contracts/flow-messages.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/messages.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './contracts/unit-of-work.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/flow-engine.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/retry-budget.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './ports/transaction-stream-hub.js';\nexport * from './reactions/on.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,iCAAiC;AAC/C,cAAc,+BAA+B;AAC7C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,oBAAoB;AAClC,cAAc,0BAA0B"}
|
|
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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context, type Effect, Metric, Schema } from 'effect';
|
|
2
|
+
declare const BulkheadFull_base: Schema.Class<BulkheadFull, Schema.TaggedStruct<"BulkheadFull", {
|
|
3
|
+
readonly dependency: Schema.String;
|
|
4
|
+
}>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"bulkheadFull", "exhausted">>;
|
|
5
|
+
/**
|
|
6
|
+
* The bulkhead for a key had no permit free. `exhausted`, and it stops every
|
|
7
|
+
* retry above it: the calls already in flight are the ones to wait for.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BulkheadFull extends BulkheadFull_base {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Bounds how many calls to one dependency run at once, per key
|
|
13
|
+
* ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)),
|
|
14
|
+
* so a slow participant holds a bounded share of the process rather than all
|
|
15
|
+
* of it. A call that finds no permit is refused at once, never queued.
|
|
16
|
+
*/
|
|
17
|
+
export interface Bulkhead {
|
|
18
|
+
readonly withPermit: (key: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BulkheadFull, R>;
|
|
19
|
+
/** Permits taken now. */
|
|
20
|
+
readonly inUse: (key: string) => Effect.Effect<number>;
|
|
21
|
+
}
|
|
22
|
+
declare const BulkheadTag_base: Context.ServiceClass<BulkheadTag, "@entifix/transactions/Bulkhead", Bulkhead>;
|
|
23
|
+
export declare class BulkheadTag extends BulkheadTag_base {
|
|
24
|
+
}
|
|
25
|
+
/** Permits in use, by key. */
|
|
26
|
+
export declare const bulkheadInUse: Metric.Gauge<number>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=bulkhead.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulkhead.d.ts","sourceRoot":"","sources":["../../src/ports/bulkhead.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAE9D;;;GAGG;AACH,qBAAa,YAAa,SAAQ,iBAQjC;CAAG;AAEJ;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,UAAU,EAAE,CACnB,GAAG,EAAE,MAAM,KACR,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;IAC3C,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CACxD;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG;AAEJ,8BAA8B;AAC9B,eAAO,MAAM,aAAa,sBAExB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Failure } from '@entifix/core';
|
|
2
|
+
import { Context, Metric, Schema } from 'effect';
|
|
3
|
+
/**
|
|
4
|
+
* The bulkhead for a key had no permit free. `exhausted`, and it stops every
|
|
5
|
+
* retry above it: the calls already in flight are the ones to wait for.
|
|
6
|
+
*/ export class BulkheadFull extends Failure.exhausted()('BulkheadFull', 'bulkheadFull', {
|
|
7
|
+
dependency: Schema.String
|
|
8
|
+
}, {
|
|
9
|
+
message: ({ dependency })=>`every permit to '${dependency}' is taken; the call was not made`
|
|
10
|
+
}) {
|
|
11
|
+
}
|
|
12
|
+
export class BulkheadTag extends Context.Service()('@entifix/transactions/Bulkhead') {
|
|
13
|
+
}
|
|
14
|
+
/** Permits in use, by key. */ export const bulkheadInUse = Metric.gauge('entifix_bulkhead_in_use', {
|
|
15
|
+
description: 'Bulkhead permits in use, by key.'
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=bulkhead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ports/bulkhead.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Context, type Effect, Metric, Schema } from 'effect';\n\n/**\n * The bulkhead for a key had no permit free. `exhausted`, and it stops every\n * retry above it: the calls already in flight are the ones to wait for.\n */\nexport class BulkheadFull extends Failure.exhausted<BulkheadFull>()(\n 'BulkheadFull',\n 'bulkheadFull',\n { dependency: Schema.String },\n {\n message: ({ dependency }) =>\n `every permit to '${dependency}' is taken; the call was not made`,\n },\n) {}\n\n/**\n * Bounds how many calls to one dependency run at once, per key\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)),\n * so a slow participant holds a bounded share of the process rather than all\n * of it. A call that finds no permit is refused at once, never queued.\n */\nexport interface Bulkhead {\n readonly withPermit: (\n key: string,\n ) => <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | BulkheadFull, R>;\n /** Permits taken now. */\n readonly inUse: (key: string) => Effect.Effect<number>;\n}\n\nexport class BulkheadTag extends Context.Service<BulkheadTag, Bulkhead>()(\n '@entifix/transactions/Bulkhead',\n) {}\n\n/** Permits in use, by key. */\nexport const bulkheadInUse = Metric.gauge('entifix_bulkhead_in_use', {\n description: 'Bulkhead permits in use, by key.',\n});\n"],"names":["Failure","Context","Metric","Schema","BulkheadFull","exhausted","dependency","String","message","BulkheadTag","Service","bulkheadInUse","gauge","description"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,OAAO,EAAeC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAE9D;;;CAGC,GACD,OAAO,MAAMC,qBAAqBJ,QAAQK,SAAS,GACjD,gBACA,gBACA;IAAEC,YAAYH,OAAOI,MAAM;AAAC,GAC5B;IACEC,SAAS,CAAC,EAAEF,UAAU,EAAE,GACtB,CAAC,iBAAiB,EAAEA,WAAW,iCAAiC,CAAC;AACrE;AACC;AAkBH,OAAO,MAAMG,oBAAoBR,QAAQS,OAAO,GAC9C;AACC;AAEH,4BAA4B,GAC5B,OAAO,MAAMC,gBAAgBT,OAAOU,KAAK,CAAC,2BAA2B;IACnEC,aAAa;AACf,GAAG"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Context, type Effect, Metric, Schema } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Where a breaker stands
|
|
4
|
+
* ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).
|
|
5
|
+
* `forcedOpen` and `disabled` are an operator's: the first refuses every call,
|
|
6
|
+
* the second lets every call through and records none.
|
|
7
|
+
*/
|
|
8
|
+
export type BreakerState = 'closed' | 'open' | 'halfOpen' | 'forcedOpen' | 'disabled';
|
|
9
|
+
/** The dials of one breaker, Resilience4j's names for Resilience4j's model. */
|
|
10
|
+
export interface BreakerDials {
|
|
11
|
+
/** `count` keeps the last `windowSize` calls; `time` the last `windowSize` seconds. */
|
|
12
|
+
readonly windowType: 'count' | 'time';
|
|
13
|
+
readonly windowSize: number;
|
|
14
|
+
/** Fraction of recorded calls that failed, at or above which the breaker opens. */
|
|
15
|
+
readonly failureRateThreshold: number;
|
|
16
|
+
/** Fraction of calls slower than `slowCallDurationMs`, at or above which it opens. */
|
|
17
|
+
readonly slowCallRateThreshold: number;
|
|
18
|
+
readonly slowCallDurationMs: number;
|
|
19
|
+
/** Calls the window must hold before either rate is read into it. */
|
|
20
|
+
readonly minimumCalls: number;
|
|
21
|
+
/** How long it stays open before letting probes through. */
|
|
22
|
+
readonly waitInOpenMs: number;
|
|
23
|
+
/** Calls let through half-open; their outcome closes or reopens it. */
|
|
24
|
+
readonly halfOpenPermits: number;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_BREAKER_DIALS: BreakerDials;
|
|
27
|
+
declare const BreakerOpen_base: Schema.Class<BreakerOpen, Schema.TaggedStruct<"BreakerOpen", {
|
|
28
|
+
readonly dependency: Schema.String;
|
|
29
|
+
}>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"breakerOpen", "unavailable">>;
|
|
30
|
+
/**
|
|
31
|
+
* The breaker for a key refused the call. `unavailable`, because the
|
|
32
|
+
* dependency is, and it stops every retry above it: retrying into an open
|
|
33
|
+
* breaker is what the breaker exists to prevent.
|
|
34
|
+
*/
|
|
35
|
+
export declare class BreakerOpen extends BreakerOpen_base {
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stops calls to a dependency that is failing, per key — a participant, or a
|
|
39
|
+
* participant and a route. Records only technical failures other than
|
|
40
|
+
* `protocol`: a business failure is an answer and never trips it, and a
|
|
41
|
+
* protocol failure is a bug that waiting does not fix.
|
|
42
|
+
*/
|
|
43
|
+
export interface CircuitBreaker {
|
|
44
|
+
readonly guard: (key: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BreakerOpen, R>;
|
|
45
|
+
/** The state now — an elapsed wait in open reads as half-open. */
|
|
46
|
+
readonly state: (key: string) => Effect.Effect<BreakerState>;
|
|
47
|
+
/** An operator's override; `closed` hands the breaker back to its window. */
|
|
48
|
+
readonly force: (key: string, state: 'forcedOpen' | 'disabled' | 'closed') => Effect.Effect<void>;
|
|
49
|
+
}
|
|
50
|
+
declare const CircuitBreakerTag_base: Context.ServiceClass<CircuitBreakerTag, "@entifix/transactions/CircuitBreaker", CircuitBreaker>;
|
|
51
|
+
export declare class CircuitBreakerTag extends CircuitBreakerTag_base {
|
|
52
|
+
}
|
|
53
|
+
/** A breaker's state per key: 0 closed, 1 open, 2 half-open, 3 forced open, 4 disabled. */
|
|
54
|
+
export declare const breakerState: Metric.Gauge<number>;
|
|
55
|
+
/** Transitions, by key, source and target state. */
|
|
56
|
+
export declare const breakerTransitions: Metric.Counter<number>;
|
|
57
|
+
/** Calls an open breaker refused, by key. */
|
|
58
|
+
export declare const breakerRejections: Metric.Counter<number>;
|
|
59
|
+
/** The number each state reports on {@link breakerState}. */
|
|
60
|
+
export declare const BREAKER_STATE_VALUE: Readonly<Record<BreakerState, number>>;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/ports/circuit-breaker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,M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K,EAAE,YAAY,GAAG,UAAU,GAAG,QAAQ,KACxC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC1B;;AAED,qBAAa,iBAAkB,SAAQ,sBAGI;CAAG;AAE9C,2FAA2F;AAC3F,eAAO,MAAM,YAAY,sBAEvB,CAAC;AAEH,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,wBAG9B,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB,wBAG7B,CAAC;AAEF,6DAA6D;AAC7D,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAMtE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Failure } from '@entifix/core';
|
|
2
|
+
import { Context, Metric, Schema } from 'effect';
|
|
3
|
+
export const DEFAULT_BREAKER_DIALS = {
|
|
4
|
+
windowType: 'count',
|
|
5
|
+
windowSize: 20,
|
|
6
|
+
failureRateThreshold: 0.5,
|
|
7
|
+
slowCallRateThreshold: 1,
|
|
8
|
+
slowCallDurationMs: 2000,
|
|
9
|
+
minimumCalls: 5,
|
|
10
|
+
waitInOpenMs: 10000,
|
|
11
|
+
halfOpenPermits: 2
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The breaker for a key refused the call. `unavailable`, because the
|
|
15
|
+
* dependency is, and it stops every retry above it: retrying into an open
|
|
16
|
+
* breaker is what the breaker exists to prevent.
|
|
17
|
+
*/ export class BreakerOpen extends Failure.unavailable()('BreakerOpen', 'breakerOpen', {
|
|
18
|
+
dependency: Schema.String
|
|
19
|
+
}, {
|
|
20
|
+
message: ({ dependency })=>`the circuit to '${dependency}' is open; the call was not made`
|
|
21
|
+
}) {
|
|
22
|
+
}
|
|
23
|
+
export class CircuitBreakerTag extends Context.Service()('@entifix/transactions/CircuitBreaker') {
|
|
24
|
+
}
|
|
25
|
+
/** A breaker's state per key: 0 closed, 1 open, 2 half-open, 3 forced open, 4 disabled. */ export const breakerState = Metric.gauge('entifix_breaker_state', {
|
|
26
|
+
description: 'Circuit breaker state, by key.'
|
|
27
|
+
});
|
|
28
|
+
/** Transitions, by key, source and target state. */ export const breakerTransitions = Metric.counter('entifix_breaker_transitions_total', {
|
|
29
|
+
description: 'Circuit breaker state transitions, by key and states.'
|
|
30
|
+
});
|
|
31
|
+
/** Calls an open breaker refused, by key. */ export const breakerRejections = Metric.counter('entifix_breaker_rejected_total', {
|
|
32
|
+
description: 'Calls refused by an open circuit breaker, by key.'
|
|
33
|
+
});
|
|
34
|
+
/** The number each state reports on {@link breakerState}. */ export const BREAKER_STATE_VALUE = {
|
|
35
|
+
closed: 0,
|
|
36
|
+
open: 1,
|
|
37
|
+
halfOpen: 2,
|
|
38
|
+
forcedOpen: 3,
|
|
39
|
+
disabled: 4
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ports/circuit-breaker.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Context, type Effect, Metric, Schema } from 'effect';\n\n/**\n * Where a breaker stands\n * ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).\n * `forcedOpen` and `disabled` are an operator's: the first refuses every call,\n * the second lets every call through and records none.\n */\nexport type BreakerState =\n 'closed' | 'open' | 'halfOpen' | 'forcedOpen' | 'disabled';\n\n/** The dials of one breaker, Resilience4j's names for Resilience4j's model. */\nexport interface BreakerDials {\n /** `count` keeps the last `windowSize` calls; `time` the last `windowSize` seconds. */\n readonly windowType: 'count' | 'time';\n readonly windowSize: number;\n /** Fraction of recorded calls that failed, at or above which the breaker opens. */\n readonly failureRateThreshold: number;\n /** Fraction of calls slower than `slowCallDurationMs`, at or above which it opens. */\n readonly slowCallRateThreshold: number;\n readonly slowCallDurationMs: number;\n /** Calls the window must hold before either rate is read into it. */\n readonly minimumCalls: number;\n /** How long it stays open before letting probes through. */\n readonly waitInOpenMs: number;\n /** Calls let through half-open; their outcome closes or reopens it. */\n readonly halfOpenPermits: number;\n}\n\nexport const DEFAULT_BREAKER_DIALS: BreakerDials = {\n windowType: 'count',\n windowSize: 20,\n failureRateThreshold: 0.5,\n slowCallRateThreshold: 1,\n slowCallDurationMs: 2_000,\n minimumCalls: 5,\n waitInOpenMs: 10_000,\n halfOpenPermits: 2,\n};\n\n/**\n * The breaker for a key refused the call. `unavailable`, because the\n * dependency is, and it stops every retry above it: retrying into an open\n * breaker is what the breaker exists to prevent.\n */\nexport class BreakerOpen extends Failure.unavailable<BreakerOpen>()(\n 'BreakerOpen',\n 'breakerOpen',\n { dependency: Schema.String },\n {\n message: ({ dependency }) =>\n `the circuit to '${dependency}' is open; the call was not made`,\n },\n) {}\n\n/**\n * Stops calls to a dependency that is failing, per key — a participant, or a\n * participant and a route. Records only technical failures other than\n * `protocol`: a business failure is an answer and never trips it, and a\n * protocol failure is a bug that waiting does not fix.\n */\nexport interface CircuitBreaker {\n readonly guard: (\n key: string,\n ) => <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | BreakerOpen, R>;\n /** The state now — an elapsed wait in open reads as half-open. */\n readonly state: (key: string) => Effect.Effect<BreakerState>;\n /** An operator's override; `closed` hands the breaker back to its window. */\n readonly force: (\n key: string,\n state: 'forcedOpen' | 'disabled' | 'closed',\n ) => Effect.Effect<void>;\n}\n\nexport class CircuitBreakerTag extends Context.Service<\n CircuitBreakerTag,\n CircuitBreaker\n>()('@entifix/transactions/CircuitBreaker') {}\n\n/** A breaker's state per key: 0 closed, 1 open, 2 half-open, 3 forced open, 4 disabled. */\nexport const breakerState = Metric.gauge('entifix_breaker_state', {\n description: 'Circuit breaker state, by key.',\n});\n\n/** Transitions, by key, source and target state. */\nexport const breakerTransitions = Metric.counter(\n 'entifix_breaker_transitions_total',\n { description: 'Circuit breaker state transitions, by key and states.' },\n);\n\n/** Calls an open breaker refused, by key. */\nexport const breakerRejections = Metric.counter(\n 'entifix_breaker_rejected_total',\n { description: 'Calls refused by an open circuit breaker, by key.' },\n);\n\n/** The number each state reports on {@link breakerState}. */\nexport const BREAKER_STATE_VALUE: Readonly<Record<BreakerState, number>> = {\n closed: 0,\n open: 1,\n halfOpen: 2,\n forcedOpen: 3,\n disabled: 4,\n};\n"],"names":["Failure","Context","Metric","Schema","DEFAULT_BREAKER_DIALS","windowType","windowSize","failureRateThreshold","slowCallRateThreshold","slowCallDurationMs","minimumCalls","waitInOpenMs","halfOpenPermits","BreakerOpen","unavailable","dependency","String","message","CircuitBreakerTag","Service","breakerState","gauge","description","breakerTransitions","counter","breakerRejections","BREAKER_STATE_VALUE","closed","open","halfOpen","forcedOpen","disabled"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAASC,OAAO,EAAeC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AA6B9D,OAAO,MAAMC,wBAAsC;IACjDC,YAAY;IACZC,YAAY;IACZC,sBAAsB;IACtBC,uBAAuB;IACvBC,oBAAoB;IACpBC,cAAc;IACdC,cAAc;IACdC,iBAAiB;AACnB,EAAE;AAEF;;;;CAIC,GACD,OAAO,MAAMC,oBAAoBb,QAAQc,WAAW,GAClD,eACA,eACA;IAAEC,YAAYZ,OAAOa,MAAM;AAAC,GAC5B;IACEC,SAAS,CAAC,EAAEF,UAAU,EAAE,GACtB,CAAC,gBAAgB,EAAEA,WAAW,gCAAgC,CAAC;AACnE;AACC;AAuBH,OAAO,MAAMG,0BAA0BjB,QAAQkB,OAAO,GAGlD;AAAyC;AAE7C,yFAAyF,GACzF,OAAO,MAAMC,eAAelB,OAAOmB,KAAK,CAAC,yBAAyB;IAChEC,aAAa;AACf,GAAG;AAEH,kDAAkD,GAClD,OAAO,MAAMC,qBAAqBrB,OAAOsB,OAAO,CAC9C,qCACA;IAAEF,aAAa;AAAwD,GACvE;AAEF,2CAA2C,GAC3C,OAAO,MAAMG,oBAAoBvB,OAAOsB,OAAO,CAC7C,kCACA;IAAEF,aAAa;AAAoD,GACnE;AAEF,2DAA2D,GAC3D,OAAO,MAAMI,sBAA8D;IACzEC,QAAQ;IACRC,MAAM;IACNC,UAAU;IACVC,YAAY;IACZC,UAAU;AACZ,EAAE"}
|
|
@@ -57,6 +57,16 @@ export interface Subscription {
|
|
|
57
57
|
* carried but unenforced there.
|
|
58
58
|
*/
|
|
59
59
|
readonly maxAttempts: number;
|
|
60
|
+
/**
|
|
61
|
+
* The breaker keys whose dependency this consumer cannot work without
|
|
62
|
+
* ([ADR 0017](../../../../../docs/adr/0017-circuit-breaker-and-bulkhead-ports.md)).
|
|
63
|
+
* While any of them is open — or forced open — the adapter stops consuming,
|
|
64
|
+
* and it resumes once all are closed or half-open, so an outage leaves the
|
|
65
|
+
* messages waiting on the queue rather than spending their attempts into
|
|
66
|
+
* quarantine. A delivery refused mid-flight by an open breaker goes back
|
|
67
|
+
* without counting as an attempt.
|
|
68
|
+
*/
|
|
69
|
+
readonly pauseWhileOpen?: readonly string[];
|
|
60
70
|
}
|
|
61
71
|
/**
|
|
62
72
|
* The domain event bus (RabbitMQ in `@entifix/amqp`). Services publish
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/ports/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;I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
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\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;
|
|
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"}
|
|
@@ -45,6 +45,12 @@ export interface FlowEngine {
|
|
|
45
45
|
readonly status: (flowId: string) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;
|
|
46
46
|
/** Completes a durable wait the flow is parked at. */
|
|
47
47
|
readonly signal: (flowId: string, token: string, outcome: unknown) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
|
|
48
|
+
/**
|
|
49
|
+
* Completes a durable wait by what the waiting flow is correlated with —
|
|
50
|
+
* the order a delivery flow follows, say — for a sender that knows that and
|
|
51
|
+
* not the flow's id.
|
|
52
|
+
*/
|
|
53
|
+
readonly signalCorrelated: (correlation: string, token: string, outcome: unknown) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
|
|
48
54
|
readonly interrupt: (flowId: string) => Effect.Effect<void, FlowNotFound | StoreFailure>;
|
|
49
55
|
}
|
|
50
56
|
declare const FlowEngineTag_base: Context.ServiceClass<FlowEngineTag, "@entifix/transactions/FlowEngine", FlowEngine>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-engine.d.ts","sourceRoot":"","sources":["../../src/ports/flow-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,SAAS,GACT,WAAW,GACX,WAAW,GACX,aAAa,GACb,QAAQ,GACR,aAAa,CAAC;AAElB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;;;;AAED,mCAAmC;AACnC,qBAAa,YAAa,SAAQ,iBAIjC;CAAG;;;;;AAEJ;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,uBAIvC;CAAG;AAEJ;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,CACd,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,KACnB,MAAM,CAAC,MAAM,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,YAAY,CAAC,CAAC;IAC9D,QAA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W,UAAU;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,CACd,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,KACnB,MAAM,CAAC,MAAM,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,YAAY,CAAC,CAAC;IAC9D,QAAQ,CAAC,MAAM,EAAE,CACf,MAAM,EAAE,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;IAC5D,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,CACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC3E;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,EAAE,CACzB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC3E,QAAQ,CAAC,SAAS,EAAE,CAClB,MAAM,EAAE,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;CACvD;;AAED,qBAAa,aAAc,SAAQ,kBAElC;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ports/flow-engine.ts"],"sourcesContent":["import type { Slip } from '@entifix/business/flow';\nimport { Failure, type StoreFailure } from '@entifix/core';\nimport { Context, type Effect, Schema } from 'effect';\n\n/**\n * Where a flow stands. `suspended` is a flow past its commit point whose step\n * keeps failing — it is waiting for retries or an operator, never compensated;\n * `waiting` is a flow parked at a durable wait for a signal.\n */\nexport type FlowState =\n | 'running'\n | 'waiting'\n | 'suspended'\n | 'completed'\n | 'compensated'\n | 'failed'\n | 'interrupted';\n\nexport interface FlowStatus {\n readonly flowId: string;\n readonly state: FlowState;\n /** The step in progress, or the one the flow stopped at. */\n readonly step?: string;\n}\n\n/** No flow is known by this id. */\nexport class FlowNotFound extends Failure.notFound<FlowNotFound>()(\n 'FlowNotFound',\n 'flowNotFound',\n { flowId: Schema.String },\n) {}\n\n/**\n * A signal the flow will not take: it is not waiting, it waits for another\n * token, or the wait already timed out. A late signal is an answer, not an\n * outage.\n */\nexport class FlowSignalRejected extends Failure.conflict<FlowSignalRejected>()(\n 'FlowSignalRejected',\n 'flowSignalRejected',\n { flowId: Schema.String, token: Schema.String },\n) {}\n\n/**\n * Runs pinned slips durably\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n *\n * There is deliberately no `await`: a caller learns how a flow ended from its\n * `flow.*` events, pushed, never by holding a request open on it.\n */\nexport interface FlowEngine {\n /** Starts a flow, idempotently: the same key answers the same `flowId`. */\n readonly start: (\n slip: Slip,\n idempotencyKey: string,\n ) => Effect.Effect<{ readonly flowId: string }, StoreFailure>;\n readonly status: (\n flowId: string,\n ) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;\n /** Completes a durable wait the flow is parked at. */\n readonly signal: (\n flowId: string,\n token: string,\n outcome: unknown,\n ) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;\n readonly interrupt: (\n flowId: string,\n ) => Effect.Effect<void, FlowNotFound | StoreFailure>;\n}\n\nexport class FlowEngineTag extends Context.Service<FlowEngineTag, FlowEngine>()(\n '@entifix/transactions/FlowEngine',\n) {}\n"],"names":["Failure","Context","Schema","FlowNotFound","notFound","flowId","String","FlowSignalRejected","conflict","token","FlowEngineTag","Service"],"mappings":"AACA,SAASA,OAAO,QAA2B,gBAAgB;AAC3D,SAASC,OAAO,EAAeC,MAAM,QAAQ,SAAS;AAuBtD,iCAAiC,GACjC,OAAO,MAAMC,qBAAqBH,QAAQI,QAAQ,GAChD,gBACA,gBACA;IAAEC,QAAQH,OAAOI,MAAM;AAAC;AACvB;AAEH;;;;CAIC,GACD,OAAO,MAAMC,2BAA2BP,QAAQQ,QAAQ,GACtD,sBACA,sBACA;IAAEH,QAAQH,OAAOI,MAAM;IAAEG,OAAOP,OAAOI,MAAM;AAAC;AAC7C;
|
|
1
|
+
{"version":3,"sources":["../../src/ports/flow-engine.ts"],"sourcesContent":["import type { Slip } from '@entifix/business/flow';\nimport { Failure, type StoreFailure } from '@entifix/core';\nimport { Context, type Effect, Schema } from 'effect';\n\n/**\n * Where a flow stands. `suspended` is a flow past its commit point whose step\n * keeps failing — it is waiting for retries or an operator, never compensated;\n * `waiting` is a flow parked at a durable wait for a signal.\n */\nexport type FlowState =\n | 'running'\n | 'waiting'\n | 'suspended'\n | 'completed'\n | 'compensated'\n | 'failed'\n | 'interrupted';\n\nexport interface FlowStatus {\n readonly flowId: string;\n readonly state: FlowState;\n /** The step in progress, or the one the flow stopped at. */\n readonly step?: string;\n}\n\n/** No flow is known by this id. */\nexport class FlowNotFound extends Failure.notFound<FlowNotFound>()(\n 'FlowNotFound',\n 'flowNotFound',\n { flowId: Schema.String },\n) {}\n\n/**\n * A signal the flow will not take: it is not waiting, it waits for another\n * token, or the wait already timed out. A late signal is an answer, not an\n * outage.\n */\nexport class FlowSignalRejected extends Failure.conflict<FlowSignalRejected>()(\n 'FlowSignalRejected',\n 'flowSignalRejected',\n { flowId: Schema.String, token: Schema.String },\n) {}\n\n/**\n * Runs pinned slips durably\n * ([ADR 0016](../../../../../docs/adr/0016-a-flow-engine-port-and-a-durable-workflow-adapter.md)).\n *\n * There is deliberately no `await`: a caller learns how a flow ended from its\n * `flow.*` events, pushed, never by holding a request open on it.\n */\nexport interface FlowEngine {\n /** Starts a flow, idempotently: the same key answers the same `flowId`. */\n readonly start: (\n slip: Slip,\n idempotencyKey: string,\n ) => Effect.Effect<{ readonly flowId: string }, StoreFailure>;\n readonly status: (\n flowId: string,\n ) => Effect.Effect<FlowStatus, FlowNotFound | StoreFailure>;\n /** Completes a durable wait the flow is parked at. */\n readonly signal: (\n flowId: string,\n token: string,\n outcome: unknown,\n ) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;\n /**\n * Completes a durable wait by what the waiting flow is correlated with —\n * the order a delivery flow follows, say — for a sender that knows that and\n * not the flow's id.\n */\n readonly signalCorrelated: (\n correlation: string,\n token: string,\n outcome: unknown,\n ) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;\n readonly interrupt: (\n flowId: string,\n ) => Effect.Effect<void, FlowNotFound | StoreFailure>;\n}\n\nexport class FlowEngineTag extends Context.Service<FlowEngineTag, FlowEngine>()(\n '@entifix/transactions/FlowEngine',\n) {}\n"],"names":["Failure","Context","Schema","FlowNotFound","notFound","flowId","String","FlowSignalRejected","conflict","token","FlowEngineTag","Service"],"mappings":"AACA,SAASA,OAAO,QAA2B,gBAAgB;AAC3D,SAASC,OAAO,EAAeC,MAAM,QAAQ,SAAS;AAuBtD,iCAAiC,GACjC,OAAO,MAAMC,qBAAqBH,QAAQI,QAAQ,GAChD,gBACA,gBACA;IAAEC,QAAQH,OAAOI,MAAM;AAAC;AACvB;AAEH;;;;CAIC,GACD,OAAO,MAAMC,2BAA2BP,QAAQQ,QAAQ,GACtD,sBACA,sBACA;IAAEH,QAAQH,OAAOI,MAAM;IAAEG,OAAOP,OAAOI,MAAM;AAAC;AAC7C;AAuCH,OAAO,MAAMI,sBAAsBT,QAAQU,OAAO,GAChD;AACC"}
|