@entifix/workflow 0.23.20 → 0.23.21
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,9 +1,22 @@
|
|
|
1
1
|
import { Effect, Layer } from 'effect';
|
|
2
2
|
import { SqlClient } from 'effect/sql';
|
|
3
3
|
import { type FlowStatusStore, FlowStatusStoreTag } from '../status/flow-status-store.js';
|
|
4
|
+
/**
|
|
5
|
+
* The advisory lock the table creation holds, so two replicas booting against
|
|
6
|
+
* one empty database create the table one after the other.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FLOW_STATUS_TABLE_LOCK = "entifix:flow-status-table";
|
|
4
9
|
/**
|
|
5
10
|
* Creates the flow status table if it is missing, and adds a column a table
|
|
6
11
|
* created by an earlier release lacks. Idempotent.
|
|
12
|
+
*
|
|
13
|
+
* ⚠️ **Serialized, because `IF NOT EXISTS` is not.** Every replica builds this
|
|
14
|
+
* layer at boot — a service's HTTP process and its runner among them — and two
|
|
15
|
+
* sessions can both see the table missing, so the second `CREATE` failed on a
|
|
16
|
+
* catalog index (`23505`, read as `DuplicateKey`) and that replica died. The
|
|
17
|
+
* DDL runs in one transaction behind a transaction-scoped advisory lock, as
|
|
18
|
+
* `ensureSqlTransactionTables` does: the second caller waits for the first to
|
|
19
|
+
* commit, then finds the table there.
|
|
7
20
|
*/
|
|
8
21
|
export declare const ensureFlowStatusTable: (sql: SqlClient.SqlClient) => Effect.Effect<void, import("@entifix/core").StoreFailure, never>;
|
|
9
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-flow-status-store.d.ts","sourceRoot":"","sources":["../../src/postgres/sql-flow-status-store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAEL,KAAK,eAAe,EACpB,kBAAkB,EAEnB,MAAM,gCAAgC,CAAC;AAgCxC;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,KAAK,SAAS,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"sql-flow-status-store.d.ts","sourceRoot":"","sources":["../../src/postgres/sql-flow-status-store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAEL,KAAK,eAAe,EACpB,kBAAkB,EAEnB,MAAM,gCAAgC,CAAC;AAgCxC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,8BAA8B,CAAC;AAElE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,GAAI,KAAK,SAAS,CAAC,SAAS,qEA4BR,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,KAAK,SAAS,CAAC,SAAS,KACvB,eA8DD,CAAC;AAEH,mEAAmE;AACnE,eAAO,MAAM,uBAAuB,4FAOnC,CAAC"}
|
|
@@ -21,10 +21,23 @@ const recordOf = (row)=>_extends({
|
|
|
21
21
|
accepts: acceptsOf(row.accepts)
|
|
22
22
|
});
|
|
23
23
|
const fault = (error)=>translateSqlError(error);
|
|
24
|
+
/**
|
|
25
|
+
* The advisory lock the table creation holds, so two replicas booting against
|
|
26
|
+
* one empty database create the table one after the other.
|
|
27
|
+
*/ export const FLOW_STATUS_TABLE_LOCK = 'entifix:flow-status-table';
|
|
24
28
|
/**
|
|
25
29
|
* Creates the flow status table if it is missing, and adds a column a table
|
|
26
30
|
* created by an earlier release lacks. Idempotent.
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ **Serialized, because `IF NOT EXISTS` is not.** Every replica builds this
|
|
33
|
+
* layer at boot — a service's HTTP process and its runner among them — and two
|
|
34
|
+
* sessions can both see the table missing, so the second `CREATE` failed on a
|
|
35
|
+
* catalog index (`23505`, read as `DuplicateKey`) and that replica died. The
|
|
36
|
+
* DDL runs in one transaction behind a transaction-scoped advisory lock, as
|
|
37
|
+
* `ensureSqlTransactionTables` does: the second caller waits for the first to
|
|
38
|
+
* commit, then finds the table there.
|
|
27
39
|
*/ export const ensureFlowStatusTable = (sql)=>Effect.gen(function*() {
|
|
40
|
+
yield* sql`SELECT pg_advisory_xact_lock(hashtext(${FLOW_STATUS_TABLE_LOCK}))`;
|
|
28
41
|
yield* sql`
|
|
29
42
|
CREATE TABLE IF NOT EXISTS entifix_flow_status (
|
|
30
43
|
flow_id text PRIMARY KEY,
|
|
@@ -50,7 +63,7 @@ const fault = (error)=>translateSqlError(error);
|
|
|
50
63
|
yield* sql`
|
|
51
64
|
CREATE INDEX IF NOT EXISTS entifix_flow_status_terminal_at
|
|
52
65
|
ON entifix_flow_status (terminal_at) WHERE purged_at IS NULL`;
|
|
53
|
-
}).pipe(Effect.mapError(fault));
|
|
66
|
+
}).pipe(sql.withTransaction, Effect.mapError(fault));
|
|
54
67
|
/**
|
|
55
68
|
* The flow status store over SQL, beside the workflow engine's own tables. A
|
|
56
69
|
* registration inserts under the key or answers the flow already there, in one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/sql-flow-status-store.ts"],"sourcesContent":["import { translateSqlError } from '@entifix/sql';\nimport type { FlowState } from '@entifix/transactions';\nimport { Effect, Layer, Option } from 'effect';\nimport { SqlClient } from 'effect/sql';\n\nimport {\n type FlowRecord,\n type FlowStatusStore,\n FlowStatusStoreTag,\n isTerminalFlowState,\n} from '../status/flow-status-store.js';\n\n// A type alias, not an interface: a row must be assignable to the record a\n// driver hands back, and an interface has no index signature.\ntype FlowStatusRow = {\n readonly flow_id: string;\n readonly execution_id: string;\n readonly state: FlowState;\n readonly step: string | null;\n readonly waiting_for: string | null;\n readonly correlation: string | null;\n /** The parked wait's outcomes, as a JSON array. */\n readonly accepts: string | null;\n};\n\nconst acceptsOf = (text: string): readonly string[] => {\n const parsed: unknown = JSON.parse(text);\n return Array.isArray(parsed) ? parsed.map(String) : [];\n};\n\nconst recordOf = (row: FlowStatusRow): FlowRecord => ({\n flowId: row.flow_id,\n executionId: row.execution_id,\n state: row.state,\n ...(row.step === null ? {} : { step: row.step }),\n ...(row.waiting_for === null ? {} : { waitingFor: row.waiting_for }),\n ...(row.correlation === null ? {} : { correlation: row.correlation }),\n ...(row.accepts === null ? {} : { accepts: acceptsOf(row.accepts) }),\n});\n\nconst fault = (error: unknown) => translateSqlError(error);\n\n/**\n * Creates the flow status table if it is missing, and adds a column a table\n * created by an earlier release lacks. Idempotent.\n */\nexport const ensureFlowStatusTable = (sql: SqlClient.SqlClient) =>\n Effect.gen(function* () {\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_flow_status (\n flow_id text PRIMARY KEY,\n idempotency_key text NOT NULL UNIQUE,\n execution_id text NOT NULL,\n state text NOT NULL,\n step text,\n waiting_for text,\n correlation text,\n accepts text,\n terminal_at timestamptz,\n purged_at timestamptz\n )`;\n yield* sql`\n ALTER TABLE entifix_flow_status ADD COLUMN IF NOT EXISTS accepts text`;\n yield* sql`\n ALTER TABLE entifix_flow_status\n ADD COLUMN IF NOT EXISTS terminal_at timestamptz`;\n yield* sql`\n ALTER TABLE entifix_flow_status\n ADD COLUMN IF NOT EXISTS purged_at timestamptz`;\n // What the journal purge walks: ended flows whose journal is still held.\n yield* sql`\n CREATE INDEX IF NOT EXISTS entifix_flow_status_terminal_at\n ON entifix_flow_status (terminal_at) WHERE purged_at IS NULL`;\n }).pipe(Effect.mapError(fault));\n\n/**\n * The flow status store over SQL, beside the workflow engine's own tables. A\n * registration inserts under the key or answers the flow already there, in one\n * statement and a read.\n */\nexport const makeSqlFlowStatusStore = (\n sql: SqlClient.SqlClient,\n): FlowStatusStore => ({\n register: (key, record) =>\n Effect.gen(function* () {\n const [inserted] = yield* sql<FlowStatusRow>`\n INSERT INTO entifix_flow_status\n (flow_id, idempotency_key, execution_id, state)\n VALUES (${record.flowId}, ${key}, ${record.executionId}, ${record.state})\n ON CONFLICT DO NOTHING\n RETURNING *`;\n if (inserted !== undefined) return recordOf(inserted);\n const [existing] = yield* sql<FlowStatusRow>`\n SELECT * FROM entifix_flow_status\n WHERE idempotency_key = ${key} OR flow_id = ${record.flowId}`;\n // Gone between the two statements cannot happen: nothing deletes a\n // flow's row — the journal purge empties its payload and keeps it.\n return recordOf(existing as FlowStatusRow);\n }).pipe(Effect.mapError(fault)),\n\n find: flowId =>\n sql<FlowStatusRow>`\n SELECT * FROM entifix_flow_status WHERE flow_id = ${flowId}`.pipe(\n Effect.map(([row]) =>\n row === undefined ? Option.none() : Option.some(recordOf(row)),\n ),\n Effect.mapError(fault),\n ),\n\n findByCorrelation: correlation =>\n sql<FlowStatusRow>`\n SELECT * FROM entifix_flow_status\n WHERE correlation = ${correlation}`.pipe(\n Effect.map(([row]) =>\n row === undefined ? Option.none() : Option.some(recordOf(row)),\n ),\n Effect.mapError(fault),\n ),\n\n update: (flowId, patch) =>\n sql`\n UPDATE entifix_flow_status\n SET state = ${patch.state}, step = ${patch.step ?? null},\n waiting_for = ${patch.waitingFor ?? null},\n correlation = ${patch.correlation ?? null},\n accepts = ${\n patch.accepts === undefined ? null : JSON.stringify(patch.accepts)\n },\n -- When the flow ended, kept from the first terminal write: the\n -- journal purge counts its retention from here.\n terminal_at = CASE WHEN ${isTerminalFlowState(patch.state)}\n THEN COALESCE(terminal_at, now()) END\n WHERE flow_id = ${flowId}`.pipe(Effect.asVoid, Effect.mapError(fault)),\n\n claimWait: (flowId, token) =>\n sql<{ readonly flow_id: string }>`\n UPDATE entifix_flow_status\n SET state = 'running', step = ${token}, waiting_for = NULL,\n accepts = NULL\n WHERE flow_id = ${flowId} AND state = 'waiting' AND waiting_for = ${token}\n RETURNING flow_id`.pipe(\n Effect.map(rows => rows.length > 0),\n Effect.mapError(fault),\n ),\n});\n\n/** The SQL status store, its table ensured as the layer builds. */\nexport const SqlFlowStatusStoreLayer = Layer.effect(\n FlowStatusStoreTag,\n Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n yield* ensureFlowStatusTable(sql);\n return makeSqlFlowStatusStore(sql);\n }),\n);\n"],"names":["translateSqlError","Effect","Layer","Option","SqlClient","FlowStatusStoreTag","isTerminalFlowState","acceptsOf","text","parsed","JSON","parse","Array","isArray","map","String","recordOf","row","flowId","flow_id","executionId","execution_id","state","step","waiting_for","waitingFor","correlation","accepts","fault","error","ensureFlowStatusTable","sql","gen","pipe","mapError","makeSqlFlowStatusStore","register","key","record","inserted","undefined","existing","find","none","some","findByCorrelation","update","patch","stringify","asVoid","claimWait","token","rows","length","SqlFlowStatusStoreLayer","effect"],"mappings":";AAAA,SAASA,iBAAiB,QAAQ,eAAe;AAEjD,SAASC,MAAM,EAAEC,KAAK,EAAEC,MAAM,QAAQ,SAAS;AAC/C,SAASC,SAAS,QAAQ,aAAa;AAEvC,SAGEC,kBAAkB,EAClBC,mBAAmB,QACd,iCAAiC;AAexC,MAAMC,YAAY,CAACC;IACjB,MAAMC,SAAkBC,KAAKC,KAAK,CAACH;IACnC,OAAOI,MAAMC,OAAO,CAACJ,UAAUA,OAAOK,GAAG,CAACC,UAAU,EAAE;AACxD;AAEA,MAAMC,WAAW,CAACC,MAAoC;QACpDC,QAAQD,IAAIE,OAAO;QACnBC,aAAaH,IAAII,YAAY;QAC7BC,OAAOL,IAAIK,KAAK;OACZL,IAAIM,IAAI,KAAK,OAAO,CAAC,IAAI;QAAEA,MAAMN,IAAIM,IAAI;IAAC,GAC1CN,IAAIO,WAAW,KAAK,OAAO,CAAC,IAAI;QAAEC,YAAYR,IAAIO,WAAW;IAAC,GAC9DP,IAAIS,WAAW,KAAK,OAAO,CAAC,IAAI;QAAEA,aAAaT,IAAIS,WAAW;IAAC,GAC/DT,IAAIU,OAAO,KAAK,OAAO,CAAC,IAAI;QAAEA,SAASpB,UAAUU,IAAIU,OAAO;IAAE;AAGpE,MAAMC,QAAQ,CAACC,QAAmB7B,kBAAkB6B;AAEpD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from '@entifix/sql';\nimport type { FlowState } from '@entifix/transactions';\nimport { Effect, Layer, Option } from 'effect';\nimport { SqlClient } from 'effect/sql';\n\nimport {\n type FlowRecord,\n type FlowStatusStore,\n FlowStatusStoreTag,\n isTerminalFlowState,\n} from '../status/flow-status-store.js';\n\n// A type alias, not an interface: a row must be assignable to the record a\n// driver hands back, and an interface has no index signature.\ntype FlowStatusRow = {\n readonly flow_id: string;\n readonly execution_id: string;\n readonly state: FlowState;\n readonly step: string | null;\n readonly waiting_for: string | null;\n readonly correlation: string | null;\n /** The parked wait's outcomes, as a JSON array. */\n readonly accepts: string | null;\n};\n\nconst acceptsOf = (text: string): readonly string[] => {\n const parsed: unknown = JSON.parse(text);\n return Array.isArray(parsed) ? parsed.map(String) : [];\n};\n\nconst recordOf = (row: FlowStatusRow): FlowRecord => ({\n flowId: row.flow_id,\n executionId: row.execution_id,\n state: row.state,\n ...(row.step === null ? {} : { step: row.step }),\n ...(row.waiting_for === null ? {} : { waitingFor: row.waiting_for }),\n ...(row.correlation === null ? {} : { correlation: row.correlation }),\n ...(row.accepts === null ? {} : { accepts: acceptsOf(row.accepts) }),\n});\n\nconst fault = (error: unknown) => translateSqlError(error);\n\n/**\n * The advisory lock the table creation holds, so two replicas booting against\n * one empty database create the table one after the other.\n */\nexport const FLOW_STATUS_TABLE_LOCK = 'entifix:flow-status-table';\n\n/**\n * Creates the flow status table if it is missing, and adds a column a table\n * created by an earlier release lacks. Idempotent.\n *\n * ⚠️ **Serialized, because `IF NOT EXISTS` is not.** Every replica builds this\n * layer at boot — a service's HTTP process and its runner among them — and two\n * sessions can both see the table missing, so the second `CREATE` failed on a\n * catalog index (`23505`, read as `DuplicateKey`) and that replica died. The\n * DDL runs in one transaction behind a transaction-scoped advisory lock, as\n * `ensureSqlTransactionTables` does: the second caller waits for the first to\n * commit, then finds the table there.\n */\nexport const ensureFlowStatusTable = (sql: SqlClient.SqlClient) =>\n Effect.gen(function* () {\n yield* sql`SELECT pg_advisory_xact_lock(hashtext(${FLOW_STATUS_TABLE_LOCK}))`;\n yield* sql`\n CREATE TABLE IF NOT EXISTS entifix_flow_status (\n flow_id text PRIMARY KEY,\n idempotency_key text NOT NULL UNIQUE,\n execution_id text NOT NULL,\n state text NOT NULL,\n step text,\n waiting_for text,\n correlation text,\n accepts text,\n terminal_at timestamptz,\n purged_at timestamptz\n )`;\n yield* sql`\n ALTER TABLE entifix_flow_status ADD COLUMN IF NOT EXISTS accepts text`;\n yield* sql`\n ALTER TABLE entifix_flow_status\n ADD COLUMN IF NOT EXISTS terminal_at timestamptz`;\n yield* sql`\n ALTER TABLE entifix_flow_status\n ADD COLUMN IF NOT EXISTS purged_at timestamptz`;\n // What the journal purge walks: ended flows whose journal is still held.\n yield* sql`\n CREATE INDEX IF NOT EXISTS entifix_flow_status_terminal_at\n ON entifix_flow_status (terminal_at) WHERE purged_at IS NULL`;\n }).pipe(sql.withTransaction, Effect.mapError(fault));\n\n/**\n * The flow status store over SQL, beside the workflow engine's own tables. A\n * registration inserts under the key or answers the flow already there, in one\n * statement and a read.\n */\nexport const makeSqlFlowStatusStore = (\n sql: SqlClient.SqlClient,\n): FlowStatusStore => ({\n register: (key, record) =>\n Effect.gen(function* () {\n const [inserted] = yield* sql<FlowStatusRow>`\n INSERT INTO entifix_flow_status\n (flow_id, idempotency_key, execution_id, state)\n VALUES (${record.flowId}, ${key}, ${record.executionId}, ${record.state})\n ON CONFLICT DO NOTHING\n RETURNING *`;\n if (inserted !== undefined) return recordOf(inserted);\n const [existing] = yield* sql<FlowStatusRow>`\n SELECT * FROM entifix_flow_status\n WHERE idempotency_key = ${key} OR flow_id = ${record.flowId}`;\n // Gone between the two statements cannot happen: nothing deletes a\n // flow's row — the journal purge empties its payload and keeps it.\n return recordOf(existing as FlowStatusRow);\n }).pipe(Effect.mapError(fault)),\n\n find: flowId =>\n sql<FlowStatusRow>`\n SELECT * FROM entifix_flow_status WHERE flow_id = ${flowId}`.pipe(\n Effect.map(([row]) =>\n row === undefined ? Option.none() : Option.some(recordOf(row)),\n ),\n Effect.mapError(fault),\n ),\n\n findByCorrelation: correlation =>\n sql<FlowStatusRow>`\n SELECT * FROM entifix_flow_status\n WHERE correlation = ${correlation}`.pipe(\n Effect.map(([row]) =>\n row === undefined ? Option.none() : Option.some(recordOf(row)),\n ),\n Effect.mapError(fault),\n ),\n\n update: (flowId, patch) =>\n sql`\n UPDATE entifix_flow_status\n SET state = ${patch.state}, step = ${patch.step ?? null},\n waiting_for = ${patch.waitingFor ?? null},\n correlation = ${patch.correlation ?? null},\n accepts = ${\n patch.accepts === undefined ? null : JSON.stringify(patch.accepts)\n },\n -- When the flow ended, kept from the first terminal write: the\n -- journal purge counts its retention from here.\n terminal_at = CASE WHEN ${isTerminalFlowState(patch.state)}\n THEN COALESCE(terminal_at, now()) END\n WHERE flow_id = ${flowId}`.pipe(Effect.asVoid, Effect.mapError(fault)),\n\n claimWait: (flowId, token) =>\n sql<{ readonly flow_id: string }>`\n UPDATE entifix_flow_status\n SET state = 'running', step = ${token}, waiting_for = NULL,\n accepts = NULL\n WHERE flow_id = ${flowId} AND state = 'waiting' AND waiting_for = ${token}\n RETURNING flow_id`.pipe(\n Effect.map(rows => rows.length > 0),\n Effect.mapError(fault),\n ),\n});\n\n/** The SQL status store, its table ensured as the layer builds. */\nexport const SqlFlowStatusStoreLayer = Layer.effect(\n FlowStatusStoreTag,\n Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n yield* ensureFlowStatusTable(sql);\n return makeSqlFlowStatusStore(sql);\n }),\n);\n"],"names":["translateSqlError","Effect","Layer","Option","SqlClient","FlowStatusStoreTag","isTerminalFlowState","acceptsOf","text","parsed","JSON","parse","Array","isArray","map","String","recordOf","row","flowId","flow_id","executionId","execution_id","state","step","waiting_for","waitingFor","correlation","accepts","fault","error","FLOW_STATUS_TABLE_LOCK","ensureFlowStatusTable","sql","gen","pipe","withTransaction","mapError","makeSqlFlowStatusStore","register","key","record","inserted","undefined","existing","find","none","some","findByCorrel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A,aACjBA,mBACAA;mBAJtBjB,GAAG,CAAC;;kBAEU,EAAEiB,MAAM3B,KAAK,CAAC,SAAS,GAAE2B,cAAAA,MAAM1B,IAAI,YAAV0B,cAAc,KAAK;wBACtC,GAAEA,oBAAAA,MAAMxB,UAAU,YAAhBwB,oBAAoB,KAAK;wBAC3B,GAAEA,qBAAAA,MAAMvB,WAAW,YAAjBuB,qBAAqB,KAAK;oBAChC,EACRA,MAAMtB,OAAO,KAAKe,YAAY,OAAOhC,KAAKwC,SAAS,CAACD,MAAMtB,OAAO,EAClE;;;kCAGuB,EAAErB,oBAAoB2C,MAAM3B,KAAK,EAAE;;sBAE/C,EAAEJ,OAAO,CAAC,CAACgB,IAAI,CAACjC,OAAOkD,MAAM,EAAElD,OAAOmC,QAAQ,CAACR;;QAEnEwB,WAAW,CAAClC,QAAQmC,QAClBrB,GAAiC,CAAC;;oCAEF,EAAEqB,MAAM;;sBAEtB,EAAEnC,OAAO,yCAAyC,EAAEmC,MAAM;uBACzD,CAAC,CAACnB,IAAI,CACvBjC,OAAOa,GAAG,CAACwC,CAAAA,OAAQA,KAAKC,MAAM,GAAG,IACjCtD,OAAOmC,QAAQ,CAACR;IAEtB,CAAA,EAAG;AAEH,iEAAiE,GACjE,OAAO,MAAM4B,0BAA0BtD,MAAMuD,MAAM,CACjDpD,oBACAJ,OAAOgC,GAAG,CAAC;IACT,MAAMD,MAAM,OAAO5B,UAAUA,SAAS;IACtC,OAAO2B,sBAAsBC;IAC7B,OAAOK,uBAAuBL;AAChC,IACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/workflow",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.21",
|
|
4
4
|
"description": "Durable flows: the slip interpreter on Effect Workflow, behind the flow engine port, with Postgres storage and socket runners.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -89,16 +89,16 @@
|
|
|
89
89
|
},
|
|
90
90
|
"dependencies": {
|
|
91
91
|
"@swc/helpers": "0.5.23",
|
|
92
|
-
"@entifix/business": "0.23.
|
|
93
|
-
"@entifix/core": "0.23.
|
|
94
|
-
"@entifix/sql": "0.23.
|
|
95
|
-
"@entifix/transactions": "0.23.
|
|
92
|
+
"@entifix/business": "0.23.21",
|
|
93
|
+
"@entifix/core": "0.23.21",
|
|
94
|
+
"@entifix/sql": "0.23.21",
|
|
95
|
+
"@entifix/transactions": "0.23.21"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@effect/platform-node": "4.0.7",
|
|
99
99
|
"@effect/sql-pg": "4.0.7",
|
|
100
100
|
"effect": "4.0.7",
|
|
101
|
-
"@entifix/testing-unit": "0.23.
|
|
101
|
+
"@entifix/testing-unit": "0.23.21"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@effect/platform-node": "^4.0.7",
|