@entifix/transactions 0.16.0 → 0.18.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.
@@ -1,8 +1,12 @@
1
1
  import { type AudienceEntry } from '@entifix/core';
2
2
  import { Schema } from 'effect';
3
3
  import type { OutboxEvent } from './outbox.js';
4
- /** The five things a flow announces about itself. */
5
- export declare const FLOW_EVENTS: readonly ["flow.started", "flow.completed", "flow.failed", "flow.suspended", "flow.stranded"];
4
+ /**
5
+ * The six things a flow announces about itself. `flow.waiting` is announced
6
+ * only at a wait **past the commit point**: the caller's write has landed, and
7
+ * what the flow waits for — a courier, a person — is someone else's.
8
+ */
9
+ export declare const FLOW_EVENTS: readonly ["flow.started", "flow.waiting", "flow.completed", "flow.failed", "flow.suspended", "flow.stranded"];
6
10
  export type FlowEventName = (typeof FLOW_EVENTS)[number];
7
11
  /**
8
12
  * What a `flow.*` event carries. A `flow.failed` without a failure, or with a
@@ -43,6 +47,12 @@ export declare const FlowStatusBody: Schema.Struct<{
43
47
  readonly flowId: Schema.String;
44
48
  readonly state: Schema.Literals<readonly ["running", "waiting", "suspended", "completed", "compensated", "failed", "interrupted", "stranded"]>;
45
49
  readonly step: Schema.optionalKey<Schema.String>;
50
+ /**
51
+ * `true` once the flow is past its commit point. A `waiting` flow that says
52
+ * so has landed the caller's write; one that does not is parked before it,
53
+ * and a browser holding it pending keeps it pending.
54
+ */
55
+ readonly committed: Schema.optionalKey<Schema.Boolean>;
46
56
  readonly failure: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{
47
57
  code: Schema.NonEmptyString;
48
58
  category: Schema.NonEmptyString;
@@ -1 +1 @@
1
- {"version":3,"file":"flow-messages.d.ts","sourceRoot":"","sources":["../../src/contracts/flow-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAA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CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,WAAW,+GAOd,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAQzD;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;EAOxB,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAC;AAYtD;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;EAQvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AAIpD;;;;;GAKG;AACH,eAAO,MAAM,cAAc;;;;IAezB;;;;OAIG;;;;;;EAGH,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC;AAIxD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,GACpB,OAAO,cAAc,KACpB,WAAW,CAAC,aAAa,CAU1B,CAAC"}
@@ -1,8 +1,13 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
2
  import { openStruct, registerEvent, registerMessage } from '@entifix/core';
3
3
  import { Schema } from 'effect';
4
- /** The five things a flow announces about itself. */ export const FLOW_EVENTS = [
4
+ /**
5
+ * The six things a flow announces about itself. `flow.waiting` is announced
6
+ * only at a wait **past the commit point**: the caller's write has landed, and
7
+ * what the flow waits for — a courier, a person — is someone else's.
8
+ */ export const FLOW_EVENTS = [
5
9
  'flow.started',
10
+ 'flow.waiting',
6
11
  'flow.completed',
7
12
  'flow.failed',
8
13
  'flow.suspended',
@@ -64,6 +69,11 @@ registerMessage('flowAccepted', FlowAccepted);
64
69
  'stranded'
65
70
  ]),
66
71
  step: Schema.optionalKey(Schema.String),
72
+ /**
73
+ * `true` once the flow is past its commit point. A `waiting` flow that says
74
+ * so has landed the caller's write; one that does not is parked before it,
75
+ * and a browser holding it pending keeps it pending.
76
+ */ committed: Schema.optionalKey(Schema.Boolean),
67
77
  failure: Schema.optionalKey(FlowFailure)
68
78
  });
69
79
  registerMessage('flowStatus', FlowStatusBody);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/flow-messages.ts"],"sourcesContent":["import {\n type AudienceEntry,\n openStruct,\n registerEvent,\n registerMessage,\n} from '@entifix/core';\nimport { Schema } from 'effect';\n\nimport type { OutboxEvent } from './outbox.js';\n\n/** The five things a flow announces about itself. */\nexport const FLOW_EVENTS = [\n 'flow.started',\n 'flow.completed',\n 'flow.failed',\n 'flow.suspended',\n 'flow.stranded',\n] as const;\nexport type FlowEventName = (typeof FLOW_EVENTS)[number];\n\n/** A failure inside an asynchronous message: the problem's code and category. */\nconst FlowFailure = openStruct({\n code: Schema.NonEmptyString,\n category: Schema.NonEmptyString,\n});\n\n/**\n * What a `flow.*` event carries. A `flow.failed` without a failure, or with a\n * failure missing its `code` or `category`, does not decode: a client settling\n * a write must be able to translate why it failed.\n */\nexport const FlowEventData = Schema.Struct({\n flowId: Schema.String,\n definition: Schema.String,\n slipVersion: Schema.Number,\n step: Schema.optionalKey(Schema.String),\n outcome: Schema.optionalKey(Schema.Unknown),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowEventData = typeof FlowEventData.Type;\n\nconst FlowFailedData = Schema.Struct({\n ...FlowEventData.fields,\n failure: FlowFailure,\n});\n\nfor (const name of FLOW_EVENTS)\n registerEvent(name, name === 'flow.failed' ? FlowFailedData : FlowEventData, {\n versioned: true,\n });\n\n/**\n * The `202` body a flow start answers: the flow's id, and where to watch it —\n * its status read and its stream.\n */\nexport const FlowAccepted = Schema.Struct({\n flowId: Schema.String,\n links: Schema.Array(\n Schema.Struct({\n rel: Schema.Literals(['status', 'stream']),\n href: Schema.String,\n }),\n ),\n});\nexport type FlowAccepted = typeof FlowAccepted.Type;\n\nregisterMessage('flowAccepted', FlowAccepted);\n\n/**\n * The body a flow's `status` link answers: where the flow stands, and why it\n * failed when it did. A browser reads it to settle a write whose outcome it\n * did not hear pushed; a `404` from that link means the flow is not projected\n * yet, never that it failed.\n */\nexport const FlowStatusBody = Schema.Struct({\n flowId: Schema.String,\n state: Schema.Literals([\n 'running',\n 'waiting',\n 'suspended',\n 'completed',\n 'compensated',\n 'failed',\n 'interrupted',\n // A wait's timeout stranded it for a person; like `suspended`, a browser\n // holding it pending keeps it pending — the write neither landed nor failed.\n 'stranded',\n ]),\n step: Schema.optionalKey(Schema.String),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowStatusBody = typeof FlowStatusBody.Type;\n\nregisterMessage('flowStatus', FlowStatusBody);\n\nexport interface FlowEventInput {\n readonly name: FlowEventName;\n readonly source: string;\n readonly at: string;\n /** The step this event is about, and its ordinal — the event's version. */\n readonly step: string;\n readonly ordinal: number;\n readonly audience: readonly AudienceEntry[];\n readonly data: FlowEventData;\n}\n\n/**\n * Builds a `flow.*` event: id `<flowId>:<step>` so a redelivered announce is\n * the same message, `correlationId` the flow, the step ordinal as version, and\n * an audience that must not be empty.\n */\nexport const flowEvent = (\n input: FlowEventInput,\n): OutboxEvent<FlowEventData> => ({\n name: input.name,\n id: `${input.data.flowId}:${input.step}`,\n source: input.source,\n at: input.at,\n correlationId: input.data.flowId,\n aggregate: { type: 'flow', id: input.data.flowId },\n version: input.ordinal,\n audience: input.audience,\n data: input.data,\n});\n"],"names":["openStruct","registerEvent","registerMessage","Schema","FLOW_EVENTS","FlowFailure","code","NonEmptyString","category","FlowEventData","Struct","flowId","String","definition","slipVersion","Number","step","optionalKey","outcome","Unknown","failure","FlowFailedData","fields","name","versioned","FlowAccepted","links","Array","rel","Literals","href","FlowStatusBody","state","flowEvent","input","id","data","source","at","correlationId","aggregate","type","version","ordinal","audience"],"mappings":";AAAA,SAEEA,UAAU,EACVC,aAAa,EACbC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAIhC,mDAAmD,GACnD,OAAO,MAAMC,cAAc;IACzB;IACA;IACA;IACA;IACA;CACD,CAAU;AAGX,+EAA+E,GAC/E,MAAMC,cAAcL,WAAW;IAC7BM,MAAMH,OAAOI,cAAc;IAC3BC,UAAUL,OAAOI,cAAc;AACjC;AAEA;;;;CAIC,GACD,OAAO,MAAME,gBAAgBN,OAAOO,MAAM,CAAC;IACzCC,QAAQR,OAAOS,MAAM;IACrBC,YAAYV,OAAOS,MAAM;IACzBE,aAAaX,OAAOY,MAAM;IAC1BC,MAAMb,OAAOc,WAAW,CAACd,OAAOS,MAAM;IACtCM,SAASf,OAAOc,WAAW,CAACd,OAAOgB,OAAO;IAC1CC,SAASjB,OAAOc,WAAW,CAACZ;AAC9B,GAAG;AAGH,MAAMgB,iBAAiBlB,OAAOO,MAAM,CAAC,aAChCD,cAAca,MAAM;IACvBF,SAASf;;AAGX,KAAK,MAAMkB,QAAQnB,YACjBH,cAAcsB,MAAMA,SAAS,gBAAgBF,iBAAiBZ,eAAe;IAC3Ee,WAAW;AACb;AAEF;;;CAGC,GACD,OAAO,MAAMC,eAAetB,OAAOO,MAAM,CAAC;IACxCC,QAAQR,OAAOS,MAAM;IACrBc,OAAOvB,OAAOwB,KAAK,CACjBxB,OAAOO,MAAM,CAAC;QACZkB,KAAKzB,OAAO0B,QAAQ,CAAC;YAAC;YAAU;SAAS;QACzCC,MAAM3B,OAAOS,MAAM;IACrB;AAEJ,GAAG;AAGHV,gBAAgB,gBAAgBuB;AAEhC;;;;;CAKC,GACD,OAAO,MAAMM,iBAAiB5B,OAAOO,MAAM,CAAC;IAC1CC,QAAQR,OAAOS,MAAM;IACrBoB,OAAO7B,OAAO0B,QAAQ,CAAC;QACrB;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yEAAyE;QACzE,6EAA6E;QAC7E;KACD;IACDb,MAAMb,OAAOc,WAAW,CAACd,OAAOS,MAAM;IACtCQ,SAASjB,OAAOc,WAAW,CAACZ;AAC9B,GAAG;AAGHH,gBAAgB,cAAc6B;AAa9B;;;;CAIC,GACD,OAAO,MAAME,YAAY,CACvBC,QACgC,CAAA;QAChCX,MAAMW,MAAMX,IAAI;QAChBY,IAAI,GAAGD,MAAME,IAAI,CAACzB,MAAM,CAAC,CAAC,EAAEuB,MAAMlB,IAAI,EAAE;QACxCqB,QAAQH,MAAMG,MAAM;QACpBC,IAAIJ,MAAMI,EAAE;QACZC,eAAeL,MAAME,IAAI,CAACzB,MAAM;QAChC6B,WAAW;YAAEC,MAAM;YAAQN,IAAID,MAAME,IAAI,CAACzB,MAAM;QAAC;QACjD+B,SAASR,MAAMS,OAAO;QACtBC,UAAUV,MAAMU,QAAQ;QACxBR,MAAMF,MAAME,IAAI;IAClB,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../src/contracts/flow-messages.ts"],"sourcesContent":["import {\n type AudienceEntry,\n openStruct,\n registerEvent,\n registerMessage,\n} from '@entifix/core';\nimport { Schema } from 'effect';\n\nimport type { OutboxEvent } from './outbox.js';\n\n/**\n * The six things a flow announces about itself. `flow.waiting` is announced\n * only at a wait **past the commit point**: the caller's write has landed, and\n * what the flow waits for — a courier, a person — is someone else's.\n */\nexport const FLOW_EVENTS = [\n 'flow.started',\n 'flow.waiting',\n 'flow.completed',\n 'flow.failed',\n 'flow.suspended',\n 'flow.stranded',\n] as const;\nexport type FlowEventName = (typeof FLOW_EVENTS)[number];\n\n/** A failure inside an asynchronous message: the problem's code and category. */\nconst FlowFailure = openStruct({\n code: Schema.NonEmptyString,\n category: Schema.NonEmptyString,\n});\n\n/**\n * What a `flow.*` event carries. A `flow.failed` without a failure, or with a\n * failure missing its `code` or `category`, does not decode: a client settling\n * a write must be able to translate why it failed.\n */\nexport const FlowEventData = Schema.Struct({\n flowId: Schema.String,\n definition: Schema.String,\n slipVersion: Schema.Number,\n step: Schema.optionalKey(Schema.String),\n outcome: Schema.optionalKey(Schema.Unknown),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowEventData = typeof FlowEventData.Type;\n\nconst FlowFailedData = Schema.Struct({\n ...FlowEventData.fields,\n failure: FlowFailure,\n});\n\nfor (const name of FLOW_EVENTS)\n registerEvent(name, name === 'flow.failed' ? FlowFailedData : FlowEventData, {\n versioned: true,\n });\n\n/**\n * The `202` body a flow start answers: the flow's id, and where to watch it —\n * its status read and its stream.\n */\nexport const FlowAccepted = Schema.Struct({\n flowId: Schema.String,\n links: Schema.Array(\n Schema.Struct({\n rel: Schema.Literals(['status', 'stream']),\n href: Schema.String,\n }),\n ),\n});\nexport type FlowAccepted = typeof FlowAccepted.Type;\n\nregisterMessage('flowAccepted', FlowAccepted);\n\n/**\n * The body a flow's `status` link answers: where the flow stands, and why it\n * failed when it did. A browser reads it to settle a write whose outcome it\n * did not hear pushed; a `404` from that link means the flow is not projected\n * yet, never that it failed.\n */\nexport const FlowStatusBody = Schema.Struct({\n flowId: Schema.String,\n state: Schema.Literals([\n 'running',\n 'waiting',\n 'suspended',\n 'completed',\n 'compensated',\n 'failed',\n 'interrupted',\n // A wait's timeout stranded it for a person; like `suspended`, a browser\n // holding it pending keeps it pending — the write neither landed nor failed.\n 'stranded',\n ]),\n step: Schema.optionalKey(Schema.String),\n /**\n * `true` once the flow is past its commit point. A `waiting` flow that says\n * so has landed the caller's write; one that does not is parked before it,\n * and a browser holding it pending keeps it pending.\n */\n committed: Schema.optionalKey(Schema.Boolean),\n failure: Schema.optionalKey(FlowFailure),\n});\nexport type FlowStatusBody = typeof FlowStatusBody.Type;\n\nregisterMessage('flowStatus', FlowStatusBody);\n\nexport interface FlowEventInput {\n readonly name: FlowEventName;\n readonly source: string;\n readonly at: string;\n /** The step this event is about, and its ordinal — the event's version. */\n readonly step: string;\n readonly ordinal: number;\n readonly audience: readonly AudienceEntry[];\n readonly data: FlowEventData;\n}\n\n/**\n * Builds a `flow.*` event: id `<flowId>:<step>` so a redelivered announce is\n * the same message, `correlationId` the flow, the step ordinal as version, and\n * an audience that must not be empty.\n */\nexport const flowEvent = (\n input: FlowEventInput,\n): OutboxEvent<FlowEventData> => ({\n name: input.name,\n id: `${input.data.flowId}:${input.step}`,\n source: input.source,\n at: input.at,\n correlationId: input.data.flowId,\n aggregate: { type: 'flow', id: input.data.flowId },\n version: input.ordinal,\n audience: input.audience,\n data: input.data,\n});\n"],"names":["openStruct","registerEvent","registerMessage","Schema","FLOW_EVENTS","FlowFailure","code","NonEmptyString","category","FlowEventData","Struct","flowId","String","definition","slipVersion","Number","step","optionalKey","outcome","Unknown","failure","FlowFailedData","fields","name","versioned","FlowAccepted","links","Array","rel","Literals","href","FlowStatusBody","state","committed","Boolean","flowEvent","input","id","data","source","at","correlationId","aggregate","type","version","ordinal","audience"],"mappings":";AAAA,SAEEA,UAAU,EACVC,aAAa,EACbC,eAAe,QACV,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAIhC;;;;CAIC,GACD,OAAO,MAAMC,cAAc;IACzB;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AAGX,+EAA+E,GAC/E,MAAMC,cAAcL,WAAW;IAC7BM,MAAMH,OAAOI,cAAc;IAC3BC,UAAUL,OAAOI,cAAc;AACjC;AAEA;;;;CAIC,GACD,OAAO,MAAME,gBAAgBN,OAAOO,MAAM,CAAC;IACzCC,QAAQR,OAAOS,MAAM;IACrBC,YAAYV,OAAOS,MAAM;IACzBE,aAAaX,OAAOY,MAAM;IAC1BC,MAAMb,OAAOc,WAAW,CAACd,OAAOS,MAAM;IACtCM,SAASf,OAAOc,WAAW,CAACd,OAAOgB,OAAO;IAC1CC,SAASjB,OAAOc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,SAASR,MAAMS,OAAO;QACtBC,UAAUV,MAAMU,QAAQ;QACxBR,MAAMF,MAAME,IAAI;IAClB,CAAA,EAAG"}
@@ -152,6 +152,24 @@ export interface Outbox {
152
152
  declare const OutboxTag_base: Context.ServiceClass<OutboxTag, "@entifix/transactions/Outbox", Outbox>;
153
153
  export declare class OutboxTag extends OutboxTag_base {
154
154
  }
155
+ /**
156
+ * One drain of the outbox now, for a writer that just enqueued and wants its
157
+ * event on the bus before the relay's next sweep. Optional: a writer that
158
+ * finds none waits for the sweep, which stays the guarantee either way.
159
+ *
160
+ * ⚠️ **Without it an announcement waits for the sweep** — up to fifteen
161
+ * seconds. The flow engine's `flow.*` events did, so a browser settling a
162
+ * pending write by push heard its checkout complete up to fifteen seconds
163
+ * after it had, and the flow-status projection read from those events lagged
164
+ * by as much (#492).
165
+ */
166
+ export interface OutboxDrain {
167
+ /** Never fails: a drain that cannot run is left to the sweep. */
168
+ readonly now: Effect.Effect<void>;
169
+ }
170
+ declare const OutboxDrainTag_base: Context.ServiceClass<OutboxDrainTag, "@entifix/transactions/OutboxDrain", OutboxDrain>;
171
+ export declare class OutboxDrainTag extends OutboxDrainTag_base {
172
+ }
155
173
  declare const OutboxMaxAttempts_base: Context.ServiceClass<OutboxMaxAttempts, "OutboxMaxAttempts", number>;
156
174
  /**
157
175
  * Publish attempts an outbox entry gets before it is quarantined, from
@@ -1 +1 @@
1
- {"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/contracts/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,KAAK,GAAG,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,GAAG;IAC9D,QAAQ,CAAC,SAAS,EAAE,YAAY,C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;;;GAcG;AACH,qBAAa,iBAAkB,SAAQ,sBAGf;CAAG"}
@@ -2,6 +2,8 @@ import { Context } from 'effect';
2
2
  /** The key an outbox orders and blocks by: `<type>/<id>`. */ export const aggregateKey = (aggregate)=>`${aggregate.type}/${aggregate.id}`;
3
3
  export class OutboxTag extends Context.Service()('@entifix/transactions/Outbox') {
4
4
  }
5
+ export class OutboxDrainTag extends Context.Service()('@entifix/transactions/OutboxDrain') {
6
+ }
5
7
  /**
6
8
  * Publish attempts an outbox entry gets before it is quarantined, from
7
9
  * config-service — the dial every store's drain reads, so it sits with the
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contracts/outbox.ts"],"sourcesContent":["import type { AggregateRef, DomainEvent, StoreFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * An event an outbox accepts: one that says which aggregate it is about and\n * which version of it ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)).\n * The relay keeps order within an aggregate and nowhere else, and a consumer\n * discards a version older than one it applied — neither is possible for an\n * event that names neither.\n */\nexport type OutboxEvent<TData = unknown> = DomainEvent<TData> & {\n readonly aggregate: AggregateRef;\n readonly version: number;\n};\n\n/** The key an outbox orders and blocks by: `<type>/<id>`. */\nexport const aggregateKey = (aggregate: AggregateRef): string =>\n `${aggregate.type}/${aggregate.id}`;\n\n/**\n * A domain event recorded durably *before* it reaches the broker.\n *\n * The point of the outbox is that a state change and the event announcing it\n * become one fact. `execute` used to write Mongo and then call `bus.publish`\n * separately: with the broker down between the two, the write happened and the\n * event never did, so the saga record sat `PENDING` until the sweep mislabelled\n * a successful transaction `STALE`. An entry written in the same transaction as\n * the state change cannot be lost that way, and a relay carries it to the bus\n * afterwards.\n */\nexport interface OutboxEntry {\n /**\n * The message's own id, denormalized out of `event` so the unique index sits\n * on a plain top-level field rather than a nested path.\n *\n * This **is** the idempotency claim: for a transaction step it is\n * `<transactionId>:<step>`, so a replayed command collides here and is\n * recognised as a retry before any lock is taken or work forked.\n */\n eventId: string;\n /** Denormalized out of `event` for the per-aggregate index. */\n aggregate: AggregateRef;\n version: number;\n event: DomainEvent;\n sent: boolean;\n /**\n * Publish attempts already spent on this entry.\n *\n * A failure holds back the later versions of this entry's aggregate, which\n * is what keeps `accepted` ahead of a terminal event — and is also why an\n * entry that can *never* publish would hold its aggregate forever. Counting\n * the attempts is what turns \"retrying\" into a state with an end.\n */\n attempts: number;\n /**\n * Why the last attempt failed. Absent until one has, so its presence alone\n * says this entry has been tried.\n */\n lastError?: string;\n /**\n * Set once the attempts are spent. A quarantined entry is **skipped** rather\n * than retried, so the head of the line moves; nothing deletes it, because a\n * stuck transaction nobody is told about is the same as a lost one.\n */\n quarantined: boolean;\n /**\n * ISO-8601. Entries are read oldest-first, and published in that order\n * **within each aggregate**: a failing head holds back only its own\n * aggregate's later versions.\n */\n createdAt: string;\n}\n\n/**\n * Whether {@link Outbox.enqueue} actually wrote.\n *\n * `duplicate` is not a failure — it is how a *retry* is recognised. The\n * transaction id is the client's idempotency key, so a repeated\n * command must return the first one's answer rather than execute twice. The\n * adapter owns the detection because the mechanism is storage-specific (a Mongo\n * `E11000` against the unique index on `eventId`), and translating it here keeps\n * driver error codes out of route handlers.\n */\nexport type OutboxEnqueueResult = 'enqueued' | 'duplicate';\n\n/**\n * An aggregate view of one outbox, for {@link Outbox.stats}.\n *\n * Counts and one timestamp — **no ids and no payloads**. That is what makes it\n * safe where a listing is not: an outbox holds event payloads, and once\n * `catalog.published` carries a whole offering an unfiltered read of one is a\n * tenant-data surface.\n */\nexport interface OutboxStats {\n /** Unsent, un-quarantined entries — the same set {@link pending} drains. */\n pending: number;\n /**\n * `createdAt` of the oldest such entry, absent when there are none.\n *\n * The age derived from this is the metric that makes a stuck relay visible.\n * An entry that can never publish no longer blocks the ones behind it —\n * quarantine gave the relay a ceiling — but a quarantine is reported only as a log line,\n * so *how far behind* the head has fallen is otherwise unanswerable.\n */\n oldestPendingAt?: string;\n /** Entries past the ceiling, which {@link pending} skips and nothing deletes. */\n quarantined: number;\n}\n\n/**\n * The durable hand-off between a transactional write and the event bus.\n *\n * Deliberately **not** a publisher: it never touches the broker. `enqueue` is\n * the only write, and the relay composes `pending`/`markSent` with an\n * {@link EventBus} — which is what keeps the engine framework-free and lets the\n * relay be tested without either a database or a broker.\n *\n * There is no `enqueueWithin(session)` here on purpose: a driver session in\n * this port would drag a datastore into a framework-free contract. A write that\n * must be atomic with its event runs in a {@link UnitOfWork} instead, whose\n * handle is opaque and whose `emit` records the event inside the same\n * transaction (ADR 0009). `enqueue` is for an event with no write to join.\n */\nexport interface Outbox {\n /** Record an event durably. Idempotent per `event.id`. */\n enqueue(event: OutboxEvent): Effect.Effect<OutboxEnqueueResult, StoreFailure>;\n /**\n * Unsent, un-quarantined entries, oldest first — the relay's input.\n *\n * Excluding the quarantined ones here rather than in the relay is deliberate:\n * a skip the caller has to remember is a skip the next caller forgets.\n */\n pending(limit: number): Effect.Effect<readonly OutboxEntry[], StoreFailure>;\n /**\n * Mark an entry published. A crash between the publish and this call re-sends\n * the event on the next drain, which is why delivery is at-least-once and why\n * a consumer that must not fold twice dedupes on `event.id`.\n */\n markSent(entry: OutboxEntry): Effect.Effect<void, StoreFailure>;\n /**\n * Record a failed publish: increments `attempts` and stores `error`.\n *\n * `quarantine` is the caller's decision rather than the adapter's, because\n * the ceiling is configuration the relay reads and the store has no business\n * knowing it. Once set, {@link pending} must stop returning the entry — that\n * is the whole mechanism by which the queue's head moves.\n */\n recordFailure(\n entry: OutboxEntry,\n error: string,\n quarantine: boolean,\n ): Effect.Effect<void, StoreFailure>;\n /**\n * Depth and age, for the relay to sample once per sweep.\n *\n * An aggregate rather than a read, deliberately: `pending(limit)` truncates at\n * the relay's batch size, so counting what it returns answers \"is the batch\n * full\" and not \"how far behind are we\" — which are the same number right up\n * to the moment the second one starts to matter.\n */\n stats(): Effect.Effect<OutboxStats, StoreFailure>;\n}\n\nexport class OutboxTag extends Context.Service<OutboxTag, Outbox>()(\n '@entifix/transactions/Outbox',\n) {}\n\n/**\n * Publish attempts an outbox entry gets before it is quarantined, from\n * config-service — the dial every store's drain reads, so it sits with the\n * outbox port rather than with one engine.\n *\n * Configuration rather than a constant because it is a genuine operational\n * tunable: raising it while a flaky broker settles is a config edit, and the\n * next sweep reads the new value. That is the opposite of a subscription's\n * `maxAttempts`, which becomes an immutable queue argument and therefore stays\n * a literal beside its declaration.\n *\n * ⚠️ **Read it with `getNumber`, never a cast.** A value of `'five'` casts to\n * `NaN`, every `attempts >= maxAttempts` comparison goes false, and nothing is\n * ever quarantined — a relay that looks healthy while its head never moves.\n */\nexport class OutboxMaxAttempts extends Context.Service<\n OutboxMaxAttempts,\n number\n>()('OutboxMaxAttempts') {}\n"],"names":["Context","aggregateKey","aggregate","type","id","OutboxTag","Service","OutboxMaxAttempts"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AAc9C,2DAA2D,GAC3D,OAAO,MAAMC,eAAe,CAACC,YAC3B,GAAGA,UAAUC,IAAI,CAAC,CAAC,EAAED,UAAUE,EAAE,EAAE,CAAC;AAkJtC,OAAO,MAAMC,kBAAkBL,QAAQM,OAAO,GAC5C;AACC;AAEH;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,0BAA0BP,QAAQM,OAAO,GAGlD;AAAsB"}
1
+ {"version":3,"sources":["../../src/contracts/outbox.ts"],"sourcesContent":["import type { AggregateRef, DomainEvent, StoreFailure } from '@entifix/core';\nimport { Context, type Effect } from 'effect';\n\n/**\n * An event an outbox accepts: one that says which aggregate it is about and\n * which version of it ([ADR 0018](../../../../../docs/adr/0018-one-outbox-ordered-per-aggregate.md)).\n * The relay keeps order within an aggregate and nowhere else, and a consumer\n * discards a version older than one it applied — neither is possible for an\n * event that names neither.\n */\nexport type OutboxEvent<TData = unknown> = DomainEvent<TData> & {\n readonly aggregate: AggregateRef;\n readonly version: number;\n};\n\n/** The key an outbox orders and blocks by: `<type>/<id>`. */\nexport const aggregateKey = (aggregate: AggregateRef): string =>\n `${aggregate.type}/${aggregate.id}`;\n\n/**\n * A domain event recorded durably *before* it reaches the broker.\n *\n * The point of the outbox is that a state change and the event announcing it\n * become one fact. `execute` used to write Mongo and then call `bus.publish`\n * separately: with the broker down between the two, the write happened and the\n * event never did, so the saga record sat `PENDING` until the sweep mislabelled\n * a successful transaction `STALE`. An entry written in the same transaction as\n * the state change cannot be lost that way, and a relay carries it to the bus\n * afterwards.\n */\nexport interface OutboxEntry {\n /**\n * The message's own id, denormalized out of `event` so the unique index sits\n * on a plain top-level field rather than a nested path.\n *\n * This **is** the idempotency claim: for a transaction step it is\n * `<transactionId>:<step>`, so a replayed command collides here and is\n * recognised as a retry before any lock is taken or work forked.\n */\n eventId: string;\n /** Denormalized out of `event` for the per-aggregate index. */\n aggregate: AggregateRef;\n version: number;\n event: DomainEvent;\n sent: boolean;\n /**\n * Publish attempts already spent on this entry.\n *\n * A failure holds back the later versions of this entry's aggregate, which\n * is what keeps `accepted` ahead of a terminal event — and is also why an\n * entry that can *never* publish would hold its aggregate forever. Counting\n * the attempts is what turns \"retrying\" into a state with an end.\n */\n attempts: number;\n /**\n * Why the last attempt failed. Absent until one has, so its presence alone\n * says this entry has been tried.\n */\n lastError?: string;\n /**\n * Set once the attempts are spent. A quarantined entry is **skipped** rather\n * than retried, so the head of the line moves; nothing deletes it, because a\n * stuck transaction nobody is told about is the same as a lost one.\n */\n quarantined: boolean;\n /**\n * ISO-8601. Entries are read oldest-first, and published in that order\n * **within each aggregate**: a failing head holds back only its own\n * aggregate's later versions.\n */\n createdAt: string;\n}\n\n/**\n * Whether {@link Outbox.enqueue} actually wrote.\n *\n * `duplicate` is not a failure — it is how a *retry* is recognised. The\n * transaction id is the client's idempotency key, so a repeated\n * command must return the first one's answer rather than execute twice. The\n * adapter owns the detection because the mechanism is storage-specific (a Mongo\n * `E11000` against the unique index on `eventId`), and translating it here keeps\n * driver error codes out of route handlers.\n */\nexport type OutboxEnqueueResult = 'enqueued' | 'duplicate';\n\n/**\n * An aggregate view of one outbox, for {@link Outbox.stats}.\n *\n * Counts and one timestamp — **no ids and no payloads**. That is what makes it\n * safe where a listing is not: an outbox holds event payloads, and once\n * `catalog.published` carries a whole offering an unfiltered read of one is a\n * tenant-data surface.\n */\nexport interface OutboxStats {\n /** Unsent, un-quarantined entries — the same set {@link pending} drains. */\n pending: number;\n /**\n * `createdAt` of the oldest such entry, absent when there are none.\n *\n * The age derived from this is the metric that makes a stuck relay visible.\n * An entry that can never publish no longer blocks the ones behind it —\n * quarantine gave the relay a ceiling — but a quarantine is reported only as a log line,\n * so *how far behind* the head has fallen is otherwise unanswerable.\n */\n oldestPendingAt?: string;\n /** Entries past the ceiling, which {@link pending} skips and nothing deletes. */\n quarantined: number;\n}\n\n/**\n * The durable hand-off between a transactional write and the event bus.\n *\n * Deliberately **not** a publisher: it never touches the broker. `enqueue` is\n * the only write, and the relay composes `pending`/`markSent` with an\n * {@link EventBus} — which is what keeps the engine framework-free and lets the\n * relay be tested without either a database or a broker.\n *\n * There is no `enqueueWithin(session)` here on purpose: a driver session in\n * this port would drag a datastore into a framework-free contract. A write that\n * must be atomic with its event runs in a {@link UnitOfWork} instead, whose\n * handle is opaque and whose `emit` records the event inside the same\n * transaction (ADR 0009). `enqueue` is for an event with no write to join.\n */\nexport interface Outbox {\n /** Record an event durably. Idempotent per `event.id`. */\n enqueue(event: OutboxEvent): Effect.Effect<OutboxEnqueueResult, StoreFailure>;\n /**\n * Unsent, un-quarantined entries, oldest first — the relay's input.\n *\n * Excluding the quarantined ones here rather than in the relay is deliberate:\n * a skip the caller has to remember is a skip the next caller forgets.\n */\n pending(limit: number): Effect.Effect<readonly OutboxEntry[], StoreFailure>;\n /**\n * Mark an entry published. A crash between the publish and this call re-sends\n * the event on the next drain, which is why delivery is at-least-once and why\n * a consumer that must not fold twice dedupes on `event.id`.\n */\n markSent(entry: OutboxEntry): Effect.Effect<void, StoreFailure>;\n /**\n * Record a failed publish: increments `attempts` and stores `error`.\n *\n * `quarantine` is the caller's decision rather than the adapter's, because\n * the ceiling is configuration the relay reads and the store has no business\n * knowing it. Once set, {@link pending} must stop returning the entry — that\n * is the whole mechanism by which the queue's head moves.\n */\n recordFailure(\n entry: OutboxEntry,\n error: string,\n quarantine: boolean,\n ): Effect.Effect<void, StoreFailure>;\n /**\n * Depth and age, for the relay to sample once per sweep.\n *\n * An aggregate rather than a read, deliberately: `pending(limit)` truncates at\n * the relay's batch size, so counting what it returns answers \"is the batch\n * full\" and not \"how far behind are we\" — which are the same number right up\n * to the moment the second one starts to matter.\n */\n stats(): Effect.Effect<OutboxStats, StoreFailure>;\n}\n\nexport class OutboxTag extends Context.Service<OutboxTag, Outbox>()(\n '@entifix/transactions/Outbox',\n) {}\n\n/**\n * One drain of the outbox now, for a writer that just enqueued and wants its\n * event on the bus before the relay's next sweep. Optional: a writer that\n * finds none waits for the sweep, which stays the guarantee either way.\n *\n * ⚠️ **Without it an announcement waits for the sweep** — up to fifteen\n * seconds. The flow engine's `flow.*` events did, so a browser settling a\n * pending write by push heard its checkout complete up to fifteen seconds\n * after it had, and the flow-status projection read from those events lagged\n * by as much (#492).\n */\nexport interface OutboxDrain {\n /** Never fails: a drain that cannot run is left to the sweep. */\n readonly now: Effect.Effect<void>;\n}\n\nexport class OutboxDrainTag extends Context.Service<\n OutboxDrainTag,\n OutboxDrain\n>()('@entifix/transactions/OutboxDrain') {}\n\n/**\n * Publish attempts an outbox entry gets before it is quarantined, from\n * config-service — the dial every store's drain reads, so it sits with the\n * outbox port rather than with one engine.\n *\n * Configuration rather than a constant because it is a genuine operational\n * tunable: raising it while a flaky broker settles is a config edit, and the\n * next sweep reads the new value. That is the opposite of a subscription's\n * `maxAttempts`, which becomes an immutable queue argument and therefore stays\n * a literal beside its declaration.\n *\n * ⚠️ **Read it with `getNumber`, never a cast.** A value of `'five'` casts to\n * `NaN`, every `attempts >= maxAttempts` comparison goes false, and nothing is\n * ever quarantined — a relay that looks healthy while its head never moves.\n */\nexport class OutboxMaxAttempts extends Context.Service<\n OutboxMaxAttempts,\n number\n>()('OutboxMaxAttempts') {}\n"],"names":["Context","aggregateKey","aggregate","type","id","OutboxTag","Service","OutboxDrainTag","OutboxMaxAttempts"],"mappings":"AACA,SAASA,OAAO,QAAqB,SAAS;AAc9C,2DAA2D,GAC3D,OAAO,MAAMC,eAAe,CAACC,YAC3B,GAAGA,UAAUC,IAAI,CAAC,CAAC,EAAED,UAAUE,EAAE,EAAE,CAAC;AAkJtC,OAAO,MAAMC,kBAAkBL,QAAQM,OAAO,GAC5C;AACC;AAkBH,OAAO,MAAMC,uBAAuBP,QAAQM,OAAO,GAG/C;AAAsC;AAE1C;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAME,0BAA0BR,QAAQM,OAAO,GAGlD;AAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-retry-budget.d.ts","sourceRoot":"","sources":["../../src/engine/in-memory-retry-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAEL,KAAK,WAAW,EAChB,cAAc,EACd,KAAK,UAAU,EAEhB,MAAM,0BAA0B,CAAC;AAYlC,8EAA8E;AAC9E,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAKxC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAS,0BAA+B,KACvC,WAkEF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,wBAAwB,GACnC,UAAS,0BAA+B,8CAC6B,CAAC"}
1
+ {"version":3,"file":"in-memory-retry-budget.d.ts","sourceRoot":"","sources":["../../src/engine/in-memory-retry-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAEL,KAAK,WAAW,EAChB,cAAc,EACd,KAAK,UAAU,EAEhB,MAAM,0BAA0B,CAAC;AAYlC,8EAA8E;AAC9E,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAKxC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAS,0BAA+B,KACvC,WA4EF,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,wBAAwB,GACnC,UAAS,0BAA+B,8CAC6B,CAAC"}
@@ -57,16 +57,19 @@ const keyOf = (key)=>{
57
57
  dials,
58
58
  admitAttempt: (key)=>Effect.sync(()=>{
59
59
  const bucket = bucketFor(key);
60
- bucket.requests.push(now());
61
60
  bucket.tokens = Math.min(cap, bucket.tokens + dials.budgetRatio);
62
61
  if (dials.adaptiveThrottlingK <= 0) return true;
62
+ // Requests that have **ended** — answered, failed, or throttled here.
63
+ // One still in flight is no evidence either way, so a burst of
64
+ // concurrent first calls is admitted until answers say otherwise.
63
65
  const requests = bucket.requests.length;
64
- // Too few requests to say anything: a cold dependency, or one just
65
- // coming back, would otherwise throttle half its first calls before a
66
- // single answer had a chance to arrive.
66
+ // Too few to say anything: a cold dependency, or one just coming back.
67
67
  if (requests < MIN_THROTTLING_SAMPLE) return true;
68
68
  const rejection = Math.max(0, (requests - dials.adaptiveThrottlingK * bucket.accepts.length) / (requests + 1));
69
- return random() >= rejection;
69
+ if (random() >= rejection) return true;
70
+ // Throttled locally: a request the dependency did not accept.
71
+ bucket.requests.push(now());
72
+ return false;
70
73
  }),
71
74
  admitRetry: (key)=>Effect.sync(()=>{
72
75
  const bucket = bucketFor(key);
@@ -75,7 +78,13 @@ const keyOf = (key)=>{
75
78
  return true;
76
79
  }),
77
80
  recordAccepted: (key)=>Effect.sync(()=>{
78
- bucketFor(key).accepts.push(now());
81
+ const bucket = bucketFor(key);
82
+ const at = now();
83
+ bucket.requests.push(at);
84
+ bucket.accepts.push(at);
85
+ }),
86
+ recordFailed: (key)=>Effect.sync(()=>{
87
+ bucketFor(key).requests.push(now());
79
88
  })
80
89
  };
81
90
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/engine/in-memory-retry-budget.ts"],"sourcesContent":["import { Effect, Layer } from 'effect';\n\nimport {\n DEFAULT_RETRY_DIALS,\n type RetryBudget,\n RetryBudgetTag,\n type RetryDials,\n type RetryKey,\n} from '../ports/retry-budget.js';\n\ninterface Bucket {\n /** Retry tokens available. */\n tokens: number;\n /** When the floor last refilled, epoch ms. */\n refilledAt: number;\n /** Adaptive throttling's window: request and accept timestamps. */\n requests: number[];\n accepts: number[];\n}\n\n/** Requests the window must hold before throttling reads anything into it. */\nexport const MIN_THROTTLING_SAMPLE = 10;\n\nconst keyOf = (key: RetryKey) =>\n `${key.dependency}\\u0000${key.organizationId ?? ''}`;\n\nexport interface InMemoryRetryBudgetOptions {\n readonly dials?: Partial<RetryDials>;\n /** The clock, in epoch milliseconds. Injected so a spec can move time. */\n readonly now?: () => number;\n /** A uniform draw in [0, 1). Injected so a spec can pin throttling. */\n readonly random?: () => number;\n}\n\n/**\n * A token-bucket retry budget held in this process\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n *\n * Each first attempt adds `budgetRatio` of a token, so retries can add at most\n * that fraction to the dependency's load; the floor refills\n * `budgetFloorPerSecond` tokens a second regardless, so a quiet dependency can\n * still retry. Tokens are capped at what the floor plus ten seconds of ratio\n * would earn, so a long calm does not bank a stampede.\n *\n * Adaptive throttling is the SRE book's client-side rule: past `K` requests\n * per accept over the window, a first attempt is rejected locally with\n * probability `(requests − K·accepts) / (requests + 1)` — once the window holds\n * {@link MIN_THROTTLING_SAMPLE} requests, so a cold start is not throttled.\n *\n * One process, one budget: replicas do not share it, which is the point — a\n * replica's retries are its own load on the dependency.\n */\nexport const makeInMemoryRetryBudget = (\n options: InMemoryRetryBudgetOptions = {},\n): RetryBudget => {\n const dials: RetryDials = { ...DEFAULT_RETRY_DIALS, ...options.dials };\n const now = options.now ?? Date.now;\n const random = options.random ?? Math.random;\n const buckets = new Map<string, Bucket>();\n const cap = Math.max(1, dials.budgetFloorPerSecond * 10);\n\n const bucketFor = (key: RetryKey): Bucket => {\n const id = keyOf(key);\n let bucket = buckets.get(id);\n if (bucket === undefined) {\n // One second's floor up front, so a dependency's very first failure can\n // be retried.\n bucket = {\n tokens: dials.budgetFloorPerSecond,\n refilledAt: now(),\n requests: [],\n accepts: [],\n };\n buckets.set(id, bucket);\n }\n const at = now();\n const elapsedSeconds = (at - bucket.refilledAt) / 1000;\n bucket.tokens = Math.min(\n cap,\n bucket.tokens + elapsedSeconds * dials.budgetFloorPerSecond,\n );\n bucket.refilledAt = at;\n const horizon = at - dials.adaptiveThrottlingWindowMs;\n bucket.requests = bucket.requests.filter(t => t > horizon);\n bucket.accepts = bucket.accepts.filter(t => t > horizon);\n return bucket;\n };\n\n return {\n dials,\n admitAttempt: key =>\n Effect.sync(() => {\n const bucket = bucketFor(key);\n bucket.requests.push(now());\n bucket.tokens = Math.min(cap, bucket.tokens + dials.budgetRatio);\n if (dials.adaptiveThrottlingK <= 0) return true;\n const requests = bucket.requests.length;\n // Too few requests to say anything: a cold dependency, or one just\n // coming back, would otherwise throttle half its first calls before a\n // single answer had a chance to arrive.\n if (requests < MIN_THROTTLING_SAMPLE) return true;\n const rejection = Math.max(\n 0,\n (requests - dials.adaptiveThrottlingK * bucket.accepts.length) /\n (requests + 1),\n );\n return random() >= rejection;\n }),\n admitRetry: key =>\n Effect.sync(() => {\n const bucket = bucketFor(key);\n if (bucket.tokens < 1) return false;\n bucket.tokens -= 1;\n return true;\n }),\n recordAccepted: key =>\n Effect.sync(() => {\n bucketFor(key).accepts.push(now());\n }),\n };\n};\n\n/** The in-memory budget as a layer, for a host's composition root. */\nexport const InMemoryRetryBudgetLayer = (\n options: InMemoryRetryBudgetOptions = {},\n) => Layer.sync(RetryBudgetTag, () => makeInMemoryRetryBudget(options));\n"],"names":["Effect","Layer","DEFAULT_RETRY_DIALS","RetryBudgetTag","MIN_THROTTLING_SAMPLE","keyOf","key","dependency","organizationId","makeInMemoryRetryBudget","options","dials","now","Date","random","Math","buckets","Map","cap","max","budgetFloorPerSecond","bucketFor","id","bucket","get","undefined","tokens","refilledAt","requests","accepts","set","at","elapsedSeconds","min","horizon","adaptiveThrottlingWindowMs","filter","t","admitAttempt","sync","push","budgetRatio","adaptiveThrottlingK","length","rejection","admitRetry","recordAccepted","InMemoryRetryBudgetLayer"],"mappings":";AAAA,SAASA,MAAM,EAAEC,KAAK,QAAQ,SAAS;AAEvC,SACEC,mBAAmB,EAEnBC,cAAc,QAGT,2BAA2B;AAYlC,4EAA4E,GAC5E,OAAO,MAAMC,wBAAwB,GAAG;AAExC,MAAMC,QAAQ,CAACC;QACaA;WAA1B,GAAGA,IAAIC,UAAU,CAAC,MAAM,GAAED,sBAAAA,IAAIE,cAAc,YAAlBF,sBAAsB,IAAI;;AAUtD;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,MAAMG,0BAA0B,CACrCC,UAAsC,CAAC,CAAC;QAG5BA,cACGA;IAFf,MAAMC,QAAoB,aAAKT,qBAAwBQ,QAAQC,KAAK;IACpE,MAAMC,OAAMF,eAAAA,QAAQE,GAAG,YAAXF,eAAeG,KAAKD,GAAG;IACnC,MAAME,UAASJ,kBAAAA,QAAQI,MAAM,YAAdJ,kBAAkBK,KAAKD,MAAM;IAC5C,MAAME,UAAU,IAA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AC7C,MAAMwC,YAAY7B,KAAKI,GAAG,CACxB,GACA,AAACS,CAAAA,WAAWjB,MAAM+B,mBAAmB,GAAGnB,OAAOM,OAAO,CAACc,MAAM,AAAD,IACzDf,CAAAA,WAAW,CAAA;gBAEhB,OAAOd,YAAY8B;YACrB;QACFC,YAAYvC,CAAAA,MACVN,OAAOuC,IAAI,CAAC;gBACV,MAAMhB,SAASF,UAAUf;gBACzB,IAAIiB,OAAOG,MAAM,GAAG,GAAG,OAAO;gBAC9BH,OAAOG,MAAM,IAAI;gBACjB,OAAO;YACT;QACFoB,gBAAgBxC,CAAAA,MACdN,OAAOuC,IAAI,CAAC;gBACVlB,UAAUf,KAAKuB,OAAO,CAACW,IAAI,CAAC5B;YAC9B;IACJ;AACF,EAAE;AAEF,oEAAoE,GACpE,OAAO,MAAMmC,2BAA2B,CACtCrC,UAAsC,CAAC,CAAC,GACrCT,MAAMsC,IAAI,CAACpC,gBAAgB,IAAMM,wBAAwBC,UAAU"}
1
+ {"version":3,"sources":["../../src/engine/in-memory-retry-budget.ts"],"sourcesContent":["import { Effect, Layer } from 'effect';\n\nimport {\n DEFAULT_RETRY_DIALS,\n type RetryBudget,\n RetryBudgetTag,\n type RetryDials,\n type RetryKey,\n} from '../ports/retry-budget.js';\n\ninterface Bucket {\n /** Retry tokens available. */\n tokens: number;\n /** When the floor last refilled, epoch ms. */\n refilledAt: number;\n /** Adaptive throttling's window: request and accept timestamps. */\n requests: number[];\n accepts: number[];\n}\n\n/** Requests the window must hold before throttling reads anything into it. */\nexport const MIN_THROTTLING_SAMPLE = 10;\n\nconst keyOf = (key: RetryKey) =>\n `${key.dependency}\\u0000${key.organizationId ?? ''}`;\n\nexport interface InMemoryRetryBudgetOptions {\n readonly dials?: Partial<RetryDials>;\n /** The clock, in epoch milliseconds. Injected so a spec can move time. */\n readonly now?: () => number;\n /** A uniform draw in [0, 1). Injected so a spec can pin throttling. */\n readonly random?: () => number;\n}\n\n/**\n * A token-bucket retry budget held in this process\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n *\n * Each first attempt adds `budgetRatio` of a token, so retries can add at most\n * that fraction to the dependency's load; the floor refills\n * `budgetFloorPerSecond` tokens a second regardless, so a quiet dependency can\n * still retry. Tokens are capped at what the floor plus ten seconds of ratio\n * would earn, so a long calm does not bank a stampede.\n *\n * Adaptive throttling is the SRE book's client-side rule: past `K` requests\n * per accept over the window, a first attempt is rejected locally with\n * probability `(requests − K·accepts) / (requests + 1)` — once the window holds\n * {@link MIN_THROTTLING_SAMPLE} requests, so a cold start is not throttled.\n *\n * One process, one budget: replicas do not share it, which is the point — a\n * replica's retries are its own load on the dependency.\n */\nexport const makeInMemoryRetryBudget = (\n options: InMemoryRetryBudgetOptions = {},\n): RetryBudget => {\n const dials: RetryDials = { ...DEFAULT_RETRY_DIALS, ...options.dials };\n const now = options.now ?? Date.now;\n const random = options.random ?? Math.random;\n const buckets = new Map<string, Bucket>();\n const cap = Math.max(1, dials.budgetFloorPerSecond * 10);\n\n const bucketFor = (key: RetryKey): Bucket => {\n const id = keyOf(key);\n let bucket = buckets.get(id);\n if (bucket === undefined) {\n // One second's floor up front, so a dependency's very first failure can\n // be retried.\n bucket = {\n tokens: dials.budgetFloorPerSecond,\n refilledAt: now(),\n requests: [],\n accepts: [],\n };\n buckets.set(id, bucket);\n }\n const at = now();\n const elapsedSeconds = (at - bucket.refilledAt) / 1000;\n bucket.tokens = Math.min(\n cap,\n bucket.tokens + elapsedSeconds * dials.budgetFloorPerSecond,\n );\n bucket.refilledAt = at;\n const horizon = at - dials.adaptiveThrottlingWindowMs;\n bucket.requests = bucket.requests.filter(t => t > horizon);\n bucket.accepts = bucket.accepts.filter(t => t > horizon);\n return bucket;\n };\n\n return {\n dials,\n admitAttempt: key =>\n Effect.sync(() => {\n const bucket = bucketFor(key);\n bucket.tokens = Math.min(cap, bucket.tokens + dials.budgetRatio);\n if (dials.adaptiveThrottlingK <= 0) return true;\n // Requests that have **ended** — answered, failed, or throttled here.\n // One still in flight is no evidence either way, so a burst of\n // concurrent first calls is admitted until answers say otherwise.\n const requests = bucket.requests.length;\n // Too few to say anything: a cold dependency, or one just coming back.\n if (requests < MIN_THROTTLING_SAMPLE) return true;\n const rejection = Math.max(\n 0,\n (requests - dials.adaptiveThrottlingK * bucket.accepts.length) /\n (requests + 1),\n );\n if (random() >= rejection) return true;\n // Throttled locally: a request the dependency did not accept.\n bucket.requests.push(now());\n return false;\n }),\n admitRetry: key =>\n Effect.sync(() => {\n const bucket = bucketFor(key);\n if (bucket.tokens < 1) return false;\n bucket.tokens -= 1;\n return true;\n }),\n recordAccepted: key =>\n Effect.sync(() => {\n const bucket = bucketFor(key);\n const at = now();\n bucket.requests.push(at);\n bucket.accepts.push(at);\n }),\n recordFailed: key =>\n Effect.sync(() => {\n bucketFor(key).requests.push(now());\n }),\n };\n};\n\n/** The in-memory budget as a layer, for a host's composition root. */\nexport const InMemoryRetryBudgetLayer = (\n options: InMemoryRetryBudgetOptions = {},\n) => Layer.sync(RetryBudgetTag, () => makeInMemoryRetryBudget(options));\n"],"names":["Effect","Layer","DEFAULT_RETRY_DIALS","RetryBudgetTag","MIN_THROTTLING_SAMPLE","keyOf","key","dependency","organizationId","makeInMemoryRetryBudget","options","dials","now","Date","random","Math","buckets","Map","cap","max","budgetFloorPerSecond","bucketFor","id","bucket","get","undefined","tokens","refilledAt","requests","accepts","set","at","elapsedSeconds","min","horizon","adaptiveThrottlingWindowMs","filter","t","admitAttempt","sync","budgetRatio","adaptiveThrottlingK","length","rejection","push","admitRetry","recordAccepted","recordFailed","InMemoryRetryBudgetLayer"],"mappings":";AAAA,SAASA,MAAM,EAAEC,KAAK,QAAQ,SAAS;AAEvC,SACEC,mBAAmB,EAEnBC,cAAc,QAGT,2BAA2B;AAYlC,4EAA4E,GAC5E,OAAO,MAAMC,wBAAwB,GAAG;AAExC,MAAMC,QAAQ,CAACC;QACaA;WAA1B,GAAGA,IAAIC,UAAU,CAAC,MA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-37,6 +37,18 @@ export interface RetryBudget {
37
37
  readonly admitRetry: (key: RetryKey) => Effect.Effect<boolean>;
38
38
  /** The dependency answered — an answer, even a refusal, counts as accepted. */
39
39
  readonly recordAccepted: (key: RetryKey) => Effect.Effect<void>;
40
+ /**
41
+ * An attempt ended without an answer: a technical failure. It counts as a
42
+ * request the dependency did not accept.
43
+ *
44
+ * ⚠️ **A request counts when it ends, not when it starts.** Adaptive
45
+ * throttling weighs requests against accepts, and an attempt still in
46
+ * flight is neither: counted at admission, a burst of concurrent first
47
+ * calls against a healthy dependency read as a dependency accepting none of
48
+ * them, and every call past the minimum sample was throttled locally before
49
+ * a single answer could arrive (#492).
50
+ */
51
+ readonly recordFailed: (key: RetryKey) => Effect.Effect<void>;
40
52
  }
41
53
  declare const RetryBudgetTag_base: Context.ServiceClass<RetryBudgetTag, "@entifix/transactions/RetryBudget", RetryBudget>;
42
54
  export declare class RetryBudgetTag extends RetryBudgetTag_base {
@@ -1 +1 @@
1
- {"version":3,"file":"retry-budget.d.ts","sourceRoot":"","sources":["../../src/ports/retry-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,2DAA2D;I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WAAW,EAAE,MAAM,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC;CAC7C;AAED,eAAO,MAAM,mBAAmB,EAAE,UAQjC,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,mFAAmF;IACnF,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjE,sEAAsE;IACtE,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/D,+EAA+E;IAC/E,QAAQ,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChE;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC/D;;AAED,qBAAa,cAAe,SAAQ,mBAGI;CAAG;AAE3C,sCAAsC;AACtC,eAAO,MAAM,aAAa,wBAExB,CAAC;AAEH,iDAAiD;AACjD,eAAO,MAAM,qBAAqB,wBAKjC,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,cAAc,wBAEzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ports/retry-budget.ts"],"sourcesContent":["import { Context, type Effect, Metric } from 'effect';\n\n/**\n * Which budget a retry draws from: one per dependency, and per organization\n * when the call acts for one, so a single tenant's outage cannot spend the\n * retries every other tenant needs\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n */\nexport interface RetryKey {\n readonly dependency: string;\n readonly organizationId?: string;\n}\n\n/** The dials, with ADR 0014's defaults in {@link DEFAULT_RETRY_DIALS}. */\nexport interface RetryDials {\n /** Attempts per call, the first included. */\n readonly maxAttempts: number;\n /** Retries may add at most this fraction to a dependency's first attempts. */\n readonly budgetRatio: number;\n /** Retries admitted per second regardless of the ratio. */\n readonly budgetFloorPerSecond: number;\n readonly backoffBaseMs: number;\n readonly backoffCapMs: number;\n /** Client-side throttling multiplier; `0` turns it off. */\n readonly adaptiveThrottlingK: number;\n readonly adaptiveThrottlingWindowMs: number;\n}\n\nexport const DEFAULT_RETRY_DIALS: RetryDials = {\n maxAttempts: 3,\n budgetRatio: 0.1,\n budgetFloorPerSecond: 1,\n backoffBaseMs: 50,\n backoffCapMs: 2000,\n adaptiveThrottlingK: 2,\n adaptiveThrottlingWindowMs: 120_000,\n};\n\n/**\n * The budget every in-process retry draws from. The port is here, in `.`, so\n * anything that orchestrates calls can reach it; the engine is at `/engine`,\n * where a cell cannot import it.\n */\nexport interface RetryBudget {\n readonly dials: RetryDials;\n /** A first attempt is about to be made. Returns `false` to throttle it locally. */\n readonly admitAttempt: (key: RetryKey) => Effect.Effect<boolean>;\n /** A retry wants to run. Returns `false` when the budget is spent. */\n readonly admitRetry: (key: RetryKey) => Effect.Effect<boolean>;\n /** The dependency answered — an answer, even a refusal, counts as accepted. */\n readonly recordAccepted: (key: RetryKey) => Effect.Effect<void>;\n}\n\nexport class RetryBudgetTag extends Context.Service<\n RetryBudgetTag,\n RetryBudget\n>()('@entifix/transactions/RetryBudget') {}\n\n/** Retries started, by dependency. */\nexport const retryAttempts = Metric.counter('entifix_retry_attempts_total', {\n description: 'In-process retries started, by dependency.',\n});\n\n/** Retries the budget refused, by dependency. */\nexport const retryBudgetRejections = Metric.counter(\n 'entifix_retry_budget_rejections_total',\n {\n description: 'Retries refused because the budget was spent, by dependency.',\n },\n);\n\n/** First attempts throttled locally by adaptive throttling, by dependency. */\nexport const retryThrottled = Metric.counter('entifix_retry_throttled_total', {\n description: 'First attempts rejected locally by adaptive throttling.',\n});\n"],"names":["Context","Metric","DEFAULT_RETRY_DIALS","maxAttempts","budgetRatio","budgetFloorPerSecond","backoffBaseMs","backoffCapMs","adaptiveThrottlingK","adaptiveThrottlingWindowMs","RetryBudgetTag","Service","retryAttempts","counter","description","retryBudgetRejections","retryThrottled"],"mappings":"AAAA,SAASA,OAAO,EAAeC,MAAM,QAAQ,SAAS;AA4BtD,OAAO,MAAMC,sBAAkC;IAC7CC,aAAa;IACbC,aAAa;IACbC,sBAAsB;IACtBC,eAAe;IACfC,cAAc;IACdC,qBAAqB;IACrBC,4BAA4B;AAC9B,EAAE;AAiBF,OAAO,MAAMC,uBAAuBV,QAAQW,OAAO,GAG/C;AAAsC;AAE1C,oCAAoC,GACpC,OAAO,MAAMC,gBAAgBX,OAAOY,OAAO,CAAC,gCAAgC;IAC1EC,aAAa;AACf,GAAG;AAEH,+CAA+C,GAC/C,OAAO,MAAMC,wBAAwBd,OAAOY,OAAO,CACjD,yCACA;IACEC,aAAa;AACf,GACA;AAEF,4EAA4E,GAC5E,OAAO,MAAME,iBAAiBf,OAAOY,OAAO,CAAC,iCAAiC;IAC5EC,aAAa;AACf,GAAG"}
1
+ {"version":3,"sources":["../../src/ports/retry-budget.ts"],"sourcesContent":["import { Context, type Effect, Metric } from 'effect';\n\n/**\n * Which budget a retry draws from: one per dependency, and per organization\n * when the call acts for one, so a single tenant's outage cannot spend the\n * retries every other tenant needs\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n */\nexport interface RetryKey {\n readonly dependency: string;\n readonly organizationId?: string;\n}\n\n/** The dials, with ADR 0014's defaults in {@link DEFAULT_RETRY_DIALS}. */\nexport interface RetryDials {\n /** Attempts per call, the first included. */\n readonly maxAttempts: number;\n /** Retries may add at most this fraction to a dependency's first attempts. */\n readonly budgetRatio: number;\n /** Retries admitted per second regardless of the ratio. */\n readonly budgetFloorPerSecond: number;\n readonly backoffBaseMs: number;\n readonly backoffCapMs: number;\n /** Client-side throttling multiplier; `0` turns it off. */\n readonly adaptiveThrottlingK: number;\n readonly adaptiveThrottlingWindowMs: number;\n}\n\nexport const DEFAULT_RETRY_DIALS: RetryDials = {\n maxAttempts: 3,\n budgetRatio: 0.1,\n budgetFloorPerSecond: 1,\n backoffBaseMs: 50,\n backoffCapMs: 2000,\n adaptiveThrottlingK: 2,\n adaptiveThrottlingWindowMs: 120_000,\n};\n\n/**\n * The budget every in-process retry draws from. The port is here, in `.`, so\n * anything that orchestrates calls can reach it; the engine is at `/engine`,\n * where a cell cannot import it.\n */\nexport interface RetryBudget {\n readonly dials: RetryDials;\n /** A first attempt is about to be made. Returns `false` to throttle it locally. */\n readonly admitAttempt: (key: RetryKey) => Effect.Effect<boolean>;\n /** A retry wants to run. Returns `false` when the budget is spent. */\n readonly admitRetry: (key: RetryKey) => Effect.Effect<boolean>;\n /** The dependency answered — an answer, even a refusal, counts as accepted. */\n readonly recordAccepted: (key: RetryKey) => Effect.Effect<void>;\n /**\n * An attempt ended without an answer: a technical failure. It counts as a\n * request the dependency did not accept.\n *\n * ⚠️ **A request counts when it ends, not when it starts.** Adaptive\n * throttling weighs requests against accepts, and an attempt still in\n * flight is neither: counted at admission, a burst of concurrent first\n * calls against a healthy dependency read as a dependency accepting none of\n * them, and every call past the minimum sample was throttled locally before\n * a single answer could arrive (#492).\n */\n readonly recordFailed: (key: RetryKey) => Effect.Effect<void>;\n}\n\nexport class RetryBudgetTag extends Context.Service<\n RetryBudgetTag,\n RetryBudget\n>()('@entifix/transactions/RetryBudget') {}\n\n/** Retries started, by dependency. */\nexport const retryAttempts = Metric.counter('entifix_retry_attempts_total', {\n description: 'In-process retries started, by dependency.',\n});\n\n/** Retries the budget refused, by dependency. */\nexport const retryBudgetRejections = Metric.counter(\n 'entifix_retry_budget_rejections_total',\n {\n description: 'Retries refused because the budget was spent, by dependency.',\n },\n);\n\n/** First attempts throttled locally by adaptive throttling, by dependency. */\nexport const retryThrottled = Metric.counter('entifix_retry_throttled_total', {\n description: 'First attempts rejected locally by adaptive throttling.',\n});\n"],"names":["Context","Metric","DEFAULT_RETRY_DIALS","maxAttempts","budgetRatio","budgetFloorPerSecond","backoffBaseMs","backoffCapMs","adaptiveThrottlingK","adaptiveThrottlingWindowMs","RetryBudgetTag","Service","retryAttempts","counter","description","retryBudgetRejections","retryThrottled"],"mappings":"AAAA,SAASA,OAAO,EAAeC,MAAM,QAAQ,SAAS;AA4BtD,OAAO,MAAMC,sBAAkC;IAC7CC,aAAa;IACbC,aAAa;IACbC,sBAAsB;IACtBC,eAAe;IACfC,cAAc;IACdC,qBAAqB;IACrBC,4BAA4B;AAC9B,EAAE;AA6BF,OAAO,MAAMC,uBAAuBV,QAAQW,OAAO,GAG/C;AAAsC;AAE1C,oCAAoC,GACpC,OAAO,MAAMC,gBAAgBX,OAAOY,OAAO,CAAC,gCAAgC;IAC1EC,aAAa;AACf,GAAG;AAEH,+CAA+C,GAC/C,OAAO,MAAMC,wBAAwBd,OAAOY,OAAO,CACjD,yCACA;IACEC,aAAa;AACf,GACA;AAEF,4EAA4E,GAC5E,OAAO,MAAME,iBAAiBf,OAAOY,OAAO,CAAC,iCAAiC;IAC5EC,aAAa;AACf,GAAG"}
@@ -30,6 +30,8 @@ export function On(predicate) {
30
30
  yield* budget.recordAccepted(options.key);
31
31
  return yield* Effect.fail(error);
32
32
  }
33
+ // No answer: a request the dependency did not accept.
34
+ yield* budget.recordFailed(options.key);
33
35
  const stop = !(yield* matches(error)) || isFailure(error) && STOPS_RETRIES.has(error._tag) || n >= budget.dials.maxAttempts;
34
36
  if (stop) return yield* Effect.fail(error);
35
37
  const wait = fullJitter(n, budget.dials.backoffBaseMs, budget.dials.backoffCapMs);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/reactions/on.ts"],"sourcesContent":["import {\n type BusinessCategory,\n currentRemainingMs,\n type EffectfulFailurePredicate,\n type FailureGuard,\n isFailure,\n Overloaded,\n} from '@entifix/core';\nimport { type Duration, Effect, Metric } from 'effect';\n\nimport {\n retryAttempts,\n type RetryBudget,\n retryBudgetRejections,\n RetryBudgetTag,\n type RetryKey,\n retryThrottled,\n} from '../ports/retry-budget.js';\n\n/**\n * A retry is legal on a call only when repeating it cannot do the thing twice:\n * a read, or a write carrying an `Idempotency-Key`. The caller states it; the\n * reaction refuses to be built when it is false, so the mistake is a boot\n * failure rather than a second charge.\n */\nexport interface RetryOptions {\n readonly key: RetryKey;\n readonly idempotent: boolean;\n}\n\n/** Tags that stop retries wherever they appear: the dependency asked for less. */\nconst STOPS_RETRIES: ReadonlySet<string> = new Set([\n 'Overloaded',\n 'BreakerOpen',\n 'BulkheadFull',\n]);\n\ntype AdmitsBusiness<S> = S extends { readonly family: 'business' }\n ? true\n : S extends { readonly category: BusinessCategory }\n ? true\n : false;\n\ntype Remaining<E, S, Narrows extends boolean> = Narrows extends true\n ? Exclude<E, S>\n : E;\n\n/**\n * The reactions a shell composes onto an effect, each a plain\n * `(self) => Effect` transform — no rule language, because a reaction is an\n * Effect function and the compiler already checks those\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n */\nexport interface Reactions<S, RP, Narrows extends boolean> {\n /**\n * Retry the matching failures, once per attempt the budget admits, with full\n * jitter, never past the request's deadline\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n *\n * Not available on a predicate that admits a business failure: an answer\n * retried is the same answer, and the type says so before anything runs.\n */\n readonly retry: AdmitsBusiness<S> extends true\n ? never\n : (\n options: RetryOptions,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | Overloaded, R | RP | RetryBudgetTag>;\n /** Wait before letting a matching failure through — pacing, not a retry. */\n readonly delay: (\n duration: Duration.Input,\n ) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | RP>;\n /** Run another effect in place of a matching failure. */\n readonly fallback: <B, E2, R2>(\n other: (failure: S) => Effect.Effect<B, E2, R2>,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows> | E2, R | R2 | RP>;\n /** Answer a matching failure with an outcome. */\n readonly recover: <B>(\n toOutcome: (failure: S) => B,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows>, R | RP>;\n}\n\nconst fullJitter = (attempt: number, base: number, cap: number) =>\n Math.random() * Math.min(cap, base * 2 ** (attempt - 1));\n\nconst count = (counter: Metric.Counter<number>, key: RetryKey) =>\n Metric.update(\n Metric.withAttributes(counter, { dependency: key.dependency }),\n 1,\n );\n\n/**\n * Reactions to the failures `predicate` admits.\n *\n * Given a guard, the reactions that consume a failure narrow `E`; given a\n * guard with a condition (`Failure.when`), they cannot — the condition may say\n * no at run time — and `E` is left as it was.\n */\nexport function On<S>(guard: FailureGuard<S>): Reactions<S, never, true>;\nexport function On<S, RP>(\n predicate: EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, false>;\nexport function On<S, RP>(\n predicate: FailureGuard<S> | EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, boolean> {\n const guard = typeof predicate === 'function' ? predicate : predicate.guard;\n const matches = (failure: unknown): Effect.Effect<boolean, never, RP> =>\n !guard(failure)\n ? Effect.succeed(false)\n : typeof predicate === 'function'\n ? Effect.succeed(true)\n : predicate.condition(failure);\n\n const retry = (options: RetryOptions) => {\n if (!options.idempotent)\n throw new Error(\n `On(…).retry on '${options.key.dependency}' is refused: the call is ` +\n 'not idempotent, so a retry could do it twice. Make it a read or ' +\n 'give it an Idempotency-Key.',\n );\n\n return <A, E, R>(self: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const budget = yield* RetryBudgetTag;\n if (!(yield* budget.admitAttempt(options.key))) {\n yield* count(retryThrottled, options.key);\n return yield* Effect.fail(new Overloaded({}));\n }\n return yield* attempt(self, budget, 1);\n });\n\n function attempt<A, E, R>(\n self: Effect.Effect<A, E, R>,\n budget: RetryBudget,\n n: number,\n ): Effect.Effect<A, E | Overloaded, R | RP> {\n return self.pipe(\n Effect.tap(() => budget.recordAccepted(options.key)),\n Effect.catch(error =>\n Effect.gen(function* () {\n // An answer, even a refusal, is the dependency working.\n if (isFailure(error) && error.family === 'business') {\n yield* budget.recordAccepted(options.key);\n return yield* Effect.fail(error);\n }\n const stop =\n !(yield* matches(error)) ||\n (isFailure(error) && STOPS_RETRIES.has(error._tag)) ||\n n >= budget.dials.maxAttempts;\n if (stop) return yield* Effect.fail(error);\n\n const wait = fullJitter(\n n,\n budget.dials.backoffBaseMs,\n budget.dials.backoffCapMs,\n );\n const remaining = yield* currentRemainingMs;\n if (remaining !== undefined && remaining <= wait)\n return yield* Effect.fail(error);\n\n if (!(yield* budget.admitRetry(options.key))) {\n yield* count(retryBudgetRejections, options.key);\n return yield* Effect.fail(error);\n }\n yield* count(retryAttempts, options.key);\n yield* Effect.sleep(wait);\n return yield* attempt(self, budget, n + 1);\n }),\n ),\n );\n }\n };\n\n return {\n retry: retry as Reactions<S, RP, boolean>['retry'],\n delay: duration => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.sleep(duration).pipe(Effect.andThen(Effect.fail(error)))\n : Effect.fail(error),\n ),\n ),\n ),\n fallback: other => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? (other(error as unknown as S) as Effect.Effect<\n unknown,\n unknown,\n unknown\n >)\n : Effect.fail(error),\n ),\n ),\n ) as never,\n recover: toOutcome => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.succeed(toOutcome(error as unknown as S))\n : Effect.fail(error),\n ),\n ),\n ) as never,\n };\n}\n"],"names":["currentRemainingMs","isFailure","Overloaded","Effect","Metric","retryAttempts","retryBudgetRejections","RetryBudgetTag","retryThrottled","STOPS_RETRIES","Set","fullJitter","attempt","base","cap","Math","random","min","count","counter","key","update","withAttributes","dependency","On","predicate","guard","matches","failure","succeed","condition","retry","options","idempotent","Error","self","gen","budget","admitAttempt","fail","n","pipe","tap","recordAccepted","catch","error","family","stop","has","_tag","dials","maxAttempts","wait","backoffBaseMs","backoffCapMs","remaining","undefined","admitRetry","sleep","delay","duration","flatMap","matched","andThen","fallback","other","recover","toOutcome"],"mappings":"AAAA,SAEEA,kBAAkB,EAGlBC,SAAS,EACTC,UAAU,QACL,gBAAgB;AACvB,SAAwBC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAEvD,SACEC,aAAa,EAEbC,qBAAqB,EACrBC,cAAc,EAEdC,cAAc,QACT,2BAA2B;AAalC,gFAAgF,GAChF,MAAMC,gBAAqC,IAAIC,IAAI;IACjD;IACA;IACA;CACD;AAoDD,MAAMC,aAAa,CAACC,SAAiBC,MAAcC,MACjDC,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAACH,KAAKD,OAAO,KAAMD,CAAAA,UAAU,CAAA;AAEvD,MAAMM,QAAQ,CAACC,SAAiCC,MAC9ChB,OAAOiB,MAAM,CACXjB,OAAOkB,cAAc,CAACH,SAAS;QAAEI,YAAYH,IAAIG,UAAU;IAAC,IAC5D;AAcJ,OAAO,SAASC,GACdC,SAA6D;IAE7D,MAAMC,QAAQ,OAAOD,cAAc,aAAaA,YAAYA,UAAUC,KAAK;IAC3E,MAAMC,UAAU,CAACC,UACf,CAACF,MAAME,WACHzB,OAAO0B,OAAO,CAAC,SACf,OAAOJ,cAAc,aACnBtB,OAAO0B,OAAO,CAAC,QACfJ,UAAUK,SAAS,CAACF;IAE5B,MAAMG,QAAQ,CAACC;QACb,IAAI,CAACA,QAAQC,UAAU,EACrB,MAAM,IAA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,OAAOR,OAAOoB,UAAU,CAACzB,QAAQZ,GAAG,CAAA,GAAI;wBAC5C,OAAOF,MAAMZ,uBAAuB0B,QAAQZ,GAAG;wBAC/C,OAAO,OAAOjB,OAAOoC,IAAI,CAACM;oBAC5B;oBACA,OAAO3B,MAAMb,eAAe2B,QAAQZ,GAAG;oBACvC,OAAOjB,OAAOuD,KAAK,CAACN;oBACpB,OAAO,OAAOxC,QAAQuB,MAAME,QAAQG,IAAI;gBAC1C;QAGN;IACF;IAEA,OAAO;QACLT,OAAOA;QACP4B,OAAOC,CAAAA,WAAYzB,CAAAA,OACjBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO0D,OAAO,CAAClC,QAAQkB,QAAQiB,CAAAA,UAC7BA,UACI3D,OAAOuD,KAAK,CAACE,UAAUnB,IAAI,CAACtC,OAAO4D,OAAO,CAAC5D,OAAOoC,IAAI,CAACM,WACvD1C,OAAOoC,IAAI,CAACM;QAIxBmB,UAAUC,CAAAA,QAAS9B,CAAAA,OACjBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO0D,OAAO,CAAClC,QAAQkB,QAAQiB,CAAAA,UAC7BA,UACKG,MAAMpB,SAKP1C,OAAOoC,IAAI,CAACM;QAIxBqB,SAASC,CAAAA,YAAahC,CAAAA,OACpBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO0D,OAAO,CAAClC,QAAQkB,QAAQiB,CAAAA,UAC7BA,UACI3D,OAAO0B,OAAO,CAACsC,UAAUtB,UACzB1C,OAAOoC,IAAI,CAACM;IAI1B;AACF"}
1
+ {"version":3,"sources":["../../src/reactions/on.ts"],"sourcesContent":["import {\n type BusinessCategory,\n currentRemainingMs,\n type EffectfulFailurePredicate,\n type FailureGuard,\n isFailure,\n Overloaded,\n} from '@entifix/core';\nimport { type Duration, Effect, Metric } from 'effect';\n\nimport {\n retryAttempts,\n type RetryBudget,\n retryBudgetRejections,\n RetryBudgetTag,\n type RetryKey,\n retryThrottled,\n} from '../ports/retry-budget.js';\n\n/**\n * A retry is legal on a call only when repeating it cannot do the thing twice:\n * a read, or a write carrying an `Idempotency-Key`. The caller states it; the\n * reaction refuses to be built when it is false, so the mistake is a boot\n * failure rather than a second charge.\n */\nexport interface RetryOptions {\n readonly key: RetryKey;\n readonly idempotent: boolean;\n}\n\n/** Tags that stop retries wherever they appear: the dependency asked for less. */\nconst STOPS_RETRIES: ReadonlySet<string> = new Set([\n 'Overloaded',\n 'BreakerOpen',\n 'BulkheadFull',\n]);\n\ntype AdmitsBusiness<S> = S extends { readonly family: 'business' }\n ? true\n : S extends { readonly category: BusinessCategory }\n ? true\n : false;\n\ntype Remaining<E, S, Narrows extends boolean> = Narrows extends true\n ? Exclude<E, S>\n : E;\n\n/**\n * The reactions a shell composes onto an effect, each a plain\n * `(self) => Effect` transform — no rule language, because a reaction is an\n * Effect function and the compiler already checks those\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n */\nexport interface Reactions<S, RP, Narrows extends boolean> {\n /**\n * Retry the matching failures, once per attempt the budget admits, with full\n * jitter, never past the request's deadline\n * ([ADR 0014](../../../../../docs/adr/0014-retry-once-at-the-layer-above-under-a-budget.md)).\n *\n * Not available on a predicate that admits a business failure: an answer\n * retried is the same answer, and the type says so before anything runs.\n */\n readonly retry: AdmitsBusiness<S> extends true\n ? never\n : (\n options: RetryOptions,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | Overloaded, R | RP | RetryBudgetTag>;\n /** Wait before letting a matching failure through — pacing, not a retry. */\n readonly delay: (\n duration: Duration.Input,\n ) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | RP>;\n /** Run another effect in place of a matching failure. */\n readonly fallback: <B, E2, R2>(\n other: (failure: S) => Effect.Effect<B, E2, R2>,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows> | E2, R | R2 | RP>;\n /** Answer a matching failure with an outcome. */\n readonly recover: <B>(\n toOutcome: (failure: S) => B,\n ) => <A, E, R>(\n self: Effect.Effect<A, E, R>,\n ) => Effect.Effect<A | B, Remaining<E, S, Narrows>, R | RP>;\n}\n\nconst fullJitter = (attempt: number, base: number, cap: number) =>\n Math.random() * Math.min(cap, base * 2 ** (attempt - 1));\n\nconst count = (counter: Metric.Counter<number>, key: RetryKey) =>\n Metric.update(\n Metric.withAttributes(counter, { dependency: key.dependency }),\n 1,\n );\n\n/**\n * Reactions to the failures `predicate` admits.\n *\n * Given a guard, the reactions that consume a failure narrow `E`; given a\n * guard with a condition (`Failure.when`), they cannot — the condition may say\n * no at run time — and `E` is left as it was.\n */\nexport function On<S>(guard: FailureGuard<S>): Reactions<S, never, true>;\nexport function On<S, RP>(\n predicate: EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, false>;\nexport function On<S, RP>(\n predicate: FailureGuard<S> | EffectfulFailurePredicate<S, RP>,\n): Reactions<S, RP, boolean> {\n const guard = typeof predicate === 'function' ? predicate : predicate.guard;\n const matches = (failure: unknown): Effect.Effect<boolean, never, RP> =>\n !guard(failure)\n ? Effect.succeed(false)\n : typeof predicate === 'function'\n ? Effect.succeed(true)\n : predicate.condition(failure);\n\n const retry = (options: RetryOptions) => {\n if (!options.idempotent)\n throw new Error(\n `On(…).retry on '${options.key.dependency}' is refused: the call is ` +\n 'not idempotent, so a retry could do it twice. Make it a read or ' +\n 'give it an Idempotency-Key.',\n );\n\n return <A, E, R>(self: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const budget = yield* RetryBudgetTag;\n if (!(yield* budget.admitAttempt(options.key))) {\n yield* count(retryThrottled, options.key);\n return yield* Effect.fail(new Overloaded({}));\n }\n return yield* attempt(self, budget, 1);\n });\n\n function attempt<A, E, R>(\n self: Effect.Effect<A, E, R>,\n budget: RetryBudget,\n n: number,\n ): Effect.Effect<A, E | Overloaded, R | RP> {\n return self.pipe(\n Effect.tap(() => budget.recordAccepted(options.key)),\n Effect.catch(error =>\n Effect.gen(function* () {\n // An answer, even a refusal, is the dependency working.\n if (isFailure(error) && error.family === 'business') {\n yield* budget.recordAccepted(options.key);\n return yield* Effect.fail(error);\n }\n // No answer: a request the dependency did not accept.\n yield* budget.recordFailed(options.key);\n const stop =\n !(yield* matches(error)) ||\n (isFailure(error) && STOPS_RETRIES.has(error._tag)) ||\n n >= budget.dials.maxAttempts;\n if (stop) return yield* Effect.fail(error);\n\n const wait = fullJitter(\n n,\n budget.dials.backoffBaseMs,\n budget.dials.backoffCapMs,\n );\n const remaining = yield* currentRemainingMs;\n if (remaining !== undefined && remaining <= wait)\n return yield* Effect.fail(error);\n\n if (!(yield* budget.admitRetry(options.key))) {\n yield* count(retryBudgetRejections, options.key);\n return yield* Effect.fail(error);\n }\n yield* count(retryAttempts, options.key);\n yield* Effect.sleep(wait);\n return yield* attempt(self, budget, n + 1);\n }),\n ),\n );\n }\n };\n\n return {\n retry: retry as Reactions<S, RP, boolean>['retry'],\n delay: duration => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.sleep(duration).pipe(Effect.andThen(Effect.fail(error)))\n : Effect.fail(error),\n ),\n ),\n ),\n fallback: other => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? (other(error as unknown as S) as Effect.Effect<\n unknown,\n unknown,\n unknown\n >)\n : Effect.fail(error),\n ),\n ),\n ) as never,\n recover: toOutcome => self =>\n self.pipe(\n Effect.catch(error =>\n Effect.flatMap(matches(error), matched =>\n matched\n ? Effect.succeed(toOutcome(error as unknown as S))\n : Effect.fail(error),\n ),\n ),\n ) as never,\n };\n}\n"],"names":["currentRemainingMs","isFailure","Overloaded","Effect","Metric","retryAttempts","retryBudgetRejections","RetryBudgetTag","retryThrottled","STOPS_RETRIES","Set","fullJitter","attempt","base","cap","Math","random","min","count","counter","key","update","withAttributes","dependency","On","predicate","guard","matches","failure","succeed","condition","retry","options","idempotent","Error","self","gen","budget","admitAttempt","fail","n","pipe","tap","recordAccepted","catch","error","family","recordFailed","stop","has","_tag","dials","maxAttempts","wait","backoffBaseMs","backoffCapMs","remaining","undefined","admitRetry","sleep","delay","duration","flatMap","matched","andThen","fallback","other","recover","toOutcome"],"mappings":"AAAA,SAEEA,kBAAkB,EAGlBC,SAAS,EACTC,UAAU,QACL,gBAAgB;AACvB,SAAwBC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAEvD,SACEC,aAAa,EAEbC,qBAAqB,EACrBC,cAAc,EAEdC,cAAc,QACT,2BAA2B;AAalC,gFAAgF,GAChF,MAAMC,gBAAqC,IAAIC,IAAI;IACjD;IACA;IACA;CACD;AAoDD,MAAMC,aAAa,CAACC,SAAiBC,MAAcC,MACjDC,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAACH,KAAKD,OAAO,KAAMD,CAAAA,UAAU,CAAA;AAEvD,MAAMM,QAAQ,CAACC,SAAiCC,MAC9ChB,OAAOiB,MAAM,CACXjB,OAAOkB,cAAc,CAACH,SAAS;QAAEI,YAAYH,IAAIG,UAAU;IAAC,IAC5D;AAcJ,OAAO,SAASC,GACdC,SAA6D;IAE7D,MAAMC,QAAQ,OAAOD,cAAc,aAAaA,YAAYA,UAAUC,KAAK;IAC3E,MAAMC,UAAU,CAACC,UACf,CAACF,MAAME,WACHzB,OAAO0B,OAAO,CAAC,SACf,OAAOJ,cAAc,aACnBtB,OAAO0B,OAAO,CAAC,QACfJ,UAAUK,SAAS,CAACF;IAE5B,MAAMG,QAAQ,CAACC;QACb,IAAI,CAACA,QAAQC,UAAU,EACrB,MAAM,IAAIC,MACR,CAAC,gBAAgB,EAAEF,QAAQZ,GAAG,CAACG,UAAU,CAAC,0BAA0B,CAAC,GACnE,qEACA;QAGN,OAAO,CAAUY,OACfhC,OAAOiC,GAAG,CAAC;gBACT,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MAAMZ,uBAAuB0B,QAAQZ,GAAG;wBAC/C,OAAO,OAAOjB,OAAOoC,IAAI,CAACM;oBAC5B;oBACA,OAAO3B,MAAMb,eAAe2B,QAAQZ,GAAG;oBACvC,OAAOjB,OAAOwD,KAAK,CAACN;oBACpB,OAAO,OAAOzC,QAAQuB,MAAME,QAAQG,IAAI;gBAC1C;QAGN;IACF;IAEA,OAAO;QACLT,OAAOA;QACP6B,OAAOC,CAAAA,WAAY1B,CAAAA,OACjBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO2D,OAAO,CAACnC,QAAQkB,QAAQkB,CAAAA,UAC7BA,UACI5D,OAAOwD,KAAK,CAACE,UAAUpB,IAAI,CAACtC,OAAO6D,OAAO,CAAC7D,OAAOoC,IAAI,CAACM,WACvD1C,OAAOoC,IAAI,CAACM;QAIxBoB,UAAUC,CAAAA,QAAS/B,CAAAA,OACjBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO2D,OAAO,CAACnC,QAAQkB,QAAQkB,CAAAA,UAC7BA,UACKG,MAAMrB,SAKP1C,OAAOoC,IAAI,CAACM;QAIxBsB,SAASC,CAAAA,YAAajC,CAAAA,OACpBA,KAAKM,IAAI,CACPtC,OAAOyC,KAAK,CAACC,CAAAA,QACX1C,OAAO2D,OAAO,CAACnC,QAAQkB,QAAQkB,CAAAA,UAC7BA,UACI5D,OAAO0B,OAAO,CAACuC,UAAUvB,UACzB1C,OAAOoC,IAAI,CAACM;IAI1B;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/transactions",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Units of work, inbox and outbox ports, an event bus, and the flow engine and resilience ports a durable flow runs on.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -56,8 +56,8 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@swc/helpers": "0.5.23",
59
- "@entifix/business": "0.16.0",
60
- "@entifix/core": "0.16.0"
59
+ "@entifix/business": "0.18.0",
60
+ "@entifix/core": "0.18.0"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "effect": "^4.0.7"