@entifix/transactions 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contracts/flow-messages.d.ts +3 -3
- package/dist/contracts/flow-messages.d.ts.map +1 -1
- package/dist/contracts/flow-messages.js +7 -3
- package/dist/contracts/flow-messages.js.map +1 -1
- package/dist/ports/flow-engine.d.ts +17 -8
- package/dist/ports/flow-engine.d.ts.map +1 -1
- package/dist/ports/flow-engine.js +2 -2
- package/dist/ports/flow-engine.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AudienceEntry } from '@entifix/core';
|
|
2
2
|
import { Schema } from 'effect';
|
|
3
3
|
import type { OutboxEvent } from './outbox.js';
|
|
4
|
-
/** The
|
|
5
|
-
export declare const FLOW_EVENTS: readonly ["flow.started", "flow.completed", "flow.failed", "flow.suspended"];
|
|
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"];
|
|
6
6
|
export type FlowEventName = (typeof FLOW_EVENTS)[number];
|
|
7
7
|
/**
|
|
8
8
|
* What a `flow.*` event carries. A `flow.failed` without a failure, or with a
|
|
@@ -41,7 +41,7 @@ export type FlowAccepted = typeof FlowAccepted.Type;
|
|
|
41
41
|
*/
|
|
42
42
|
export declare const FlowStatusBody: Schema.Struct<{
|
|
43
43
|
readonly flowId: Schema.String;
|
|
44
|
-
readonly state: Schema.Literals<readonly ["running", "waiting", "suspended", "completed", "compensated", "failed", "interrupted"]>;
|
|
44
|
+
readonly state: Schema.Literals<readonly ["running", "waiting", "suspended", "completed", "compensated", "failed", "interrupted", "stranded"]>;
|
|
45
45
|
readonly step: Schema.optionalKey<Schema.String>;
|
|
46
46
|
readonly failure: Schema.optionalKey<Schema.StructWithRest<Schema.Struct<{
|
|
47
47
|
code: 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,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,qDAAqD;AACrD,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"flow-messages.d.ts","sourceRoot":"","sources":["../../src/contracts/flow-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,qDAAqD;AACrD,eAAO,MAAM,WAAW,+FAMd,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;;;;;;;;EAgBzB,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,11 +1,12 @@
|
|
|
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
|
|
4
|
+
/** The five things a flow announces about itself. */ export const FLOW_EVENTS = [
|
|
5
5
|
'flow.started',
|
|
6
6
|
'flow.completed',
|
|
7
7
|
'flow.failed',
|
|
8
|
-
'flow.suspended'
|
|
8
|
+
'flow.suspended',
|
|
9
|
+
'flow.stranded'
|
|
9
10
|
];
|
|
10
11
|
/** A failure inside an asynchronous message: the problem's code and category. */ const FlowFailure = openStruct({
|
|
11
12
|
code: Schema.NonEmptyString,
|
|
@@ -57,7 +58,10 @@ registerMessage('flowAccepted', FlowAccepted);
|
|
|
57
58
|
'completed',
|
|
58
59
|
'compensated',
|
|
59
60
|
'failed',
|
|
60
|
-
'interrupted'
|
|
61
|
+
'interrupted',
|
|
62
|
+
// A wait's timeout stranded it for a person; like `suspended`, a browser
|
|
63
|
+
// holding it pending keeps it pending — the write neither landed nor failed.
|
|
64
|
+
'stranded'
|
|
61
65
|
]),
|
|
62
66
|
step: Schema.optionalKey(Schema.String),
|
|
63
67
|
failure: Schema.optionalKey(FlowFailure)
|
|
@@ -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
|
|
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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zB,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"}
|
|
@@ -4,9 +4,11 @@ import { Context, type Effect, Schema } from 'effect';
|
|
|
4
4
|
/**
|
|
5
5
|
* Where a flow stands. `suspended` is a flow past its commit point whose step
|
|
6
6
|
* keeps failing — it is waiting for retries or an operator, never compensated;
|
|
7
|
-
* `waiting` is a flow parked at a durable wait for a signal
|
|
7
|
+
* `waiting` is a flow parked at a durable wait for a signal; `stranded` is a
|
|
8
|
+
* flow whose wait ran out with nothing left it could do on its own, ended for
|
|
9
|
+
* an operator rather than retried.
|
|
8
10
|
*/
|
|
9
|
-
export type FlowState = 'running' | 'waiting' | 'suspended' | 'completed' | 'compensated' | 'failed' | 'interrupted';
|
|
11
|
+
export type FlowState = 'running' | 'waiting' | 'suspended' | 'completed' | 'compensated' | 'failed' | 'interrupted' | 'stranded';
|
|
10
12
|
export interface FlowStatus {
|
|
11
13
|
readonly flowId: string;
|
|
12
14
|
readonly state: FlowState;
|
|
@@ -25,8 +27,8 @@ declare const FlowSignalRejected_base: Schema.Class<FlowSignalRejected, Schema.T
|
|
|
25
27
|
}>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"flowSignalRejected", "conflict">>;
|
|
26
28
|
/**
|
|
27
29
|
* A signal the flow will not take: it is not waiting, it waits for another
|
|
28
|
-
* token,
|
|
29
|
-
* outage.
|
|
30
|
+
* token, its wait is not answered with that outcome, or the wait already
|
|
31
|
+
* timed out. A late signal is an answer, not an outage.
|
|
30
32
|
*/
|
|
31
33
|
export declare class FlowSignalRejected extends FlowSignalRejected_base {
|
|
32
34
|
}
|
|
@@ -46,11 +48,18 @@ export interface FlowEngine {
|
|
|
46
48
|
/** Completes a durable wait the flow is parked at. */
|
|
47
49
|
readonly signal: (flowId: string, token: string, outcome: unknown) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
|
|
48
50
|
/**
|
|
49
|
-
* Completes
|
|
50
|
-
* the
|
|
51
|
-
*
|
|
51
|
+
* Completes whichever durable wait the flow correlated with `correlation` —
|
|
52
|
+
* the shipment a delivery flow follows, say — is parked at, for a sender
|
|
53
|
+
* that knows that and neither the flow's id nor the wait's step name.
|
|
54
|
+
*
|
|
55
|
+
* `signal.outcome` must be one the parked wait declares, or the signal is
|
|
56
|
+
* rejected: a sender's report meant for a later wait is never taken by an
|
|
57
|
+
* earlier one. No flow parked under the correlation answers `FlowNotFound`,
|
|
58
|
+
* which a sender may retry — the flow may simply not have reached its wait.
|
|
52
59
|
*/
|
|
53
|
-
readonly signalCorrelated: (correlation: string,
|
|
60
|
+
readonly signalCorrelated: (correlation: string, signal: {
|
|
61
|
+
readonly outcome: string;
|
|
62
|
+
} & Readonly<Record<string, unknown>>) => Effect.Effect<void, FlowNotFound | FlowSignalRejected | StoreFailure>;
|
|
54
63
|
readonly interrupt: (flowId: string) => Effect.Effect<void, FlowNotFound | StoreFailure>;
|
|
55
64
|
}
|
|
56
65
|
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,CA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,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC3E;;;;;;;;;OASG;IACH,QAAQ,CAAC,gBAAgB,EAAE,CACzB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACrE,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"}
|
|
@@ -6,8 +6,8 @@ import { Context, Schema } from 'effect';
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* A signal the flow will not take: it is not waiting, it waits for another
|
|
9
|
-
* token,
|
|
10
|
-
* outage.
|
|
9
|
+
* token, its wait is not answered with that outcome, or the wait already
|
|
10
|
+
* timed out. A late signal is an answer, not an outage.
|
|
11
11
|
*/ export class FlowSignalRejected extends Failure.conflict()('FlowSignalRejected', 'flowSignalRejected', {
|
|
12
12
|
flowId: Schema.String,
|
|
13
13
|
token: Schema.String
|
|
@@ -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
|
|
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; `stranded` is a\n * flow whose wait ran out with nothing left it could do on its own, ended for\n * an operator rather than retried.\n */\nexport type FlowState =\n | 'running'\n | 'waiting'\n | 'suspended'\n | 'completed'\n | 'compensated'\n | 'failed'\n | 'interrupted'\n | 'stranded';\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, its wait is not answered with that outcome, or the wait already\n * timed out. A late signal is an answer, not an 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 whichever durable wait the flow correlated with `correlation` —\n * the shipment a delivery flow follows, say — is parked at, for a sender\n * that knows that and neither the flow's id nor the wait's step name.\n *\n * `signal.outcome` must be one the parked wait declares, or the signal is\n * rejected: a sender's report meant for a later wait is never taken by an\n * earlier one. No flow parked under the correlation answers `FlowNotFound`,\n * which a sender may retry — the flow may simply not have reached its wait.\n */\n readonly signalCorrelated: (\n correlation: string,\n signal: { readonly outcome: string } & Readonly<Record<string, 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;AA0BtD,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;AA2CH,OAAO,MAAMI,sBAAsBT,QAAQU,OAAO,GAChD;AACC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/transactions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.
|
|
60
|
-
"@entifix/core": "0.
|
|
59
|
+
"@entifix/business": "0.16.0",
|
|
60
|
+
"@entifix/core": "0.16.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"effect": "^4.0.7"
|