@sonamu-kit/tasks 0.2.0 → 0.3.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/.oxlintrc.json +3 -0
- package/AGENTS.md +21 -0
- package/dist/backend.d.ts +126 -107
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +4 -1
- package/dist/backend.js.map +1 -1
- package/dist/client.d.ts +145 -132
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +219 -213
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +15 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +22 -17
- package/dist/config.js.map +1 -1
- package/dist/core/duration.d.ts +5 -4
- package/dist/core/duration.d.ts.map +1 -1
- package/dist/core/duration.js +54 -59
- package/dist/core/duration.js.map +1 -1
- package/dist/core/error.d.ts +10 -7
- package/dist/core/error.d.ts.map +1 -1
- package/dist/core/error.js +21 -21
- package/dist/core/error.js.map +1 -1
- package/dist/core/json.d.ts +8 -3
- package/dist/core/json.d.ts.map +1 -1
- package/dist/core/result.d.ts +10 -14
- package/dist/core/result.d.ts.map +1 -1
- package/dist/core/result.js +21 -16
- package/dist/core/result.js.map +1 -1
- package/dist/core/retry.d.ts +37 -31
- package/dist/core/retry.d.ts.map +1 -1
- package/dist/core/retry.js +44 -51
- package/dist/core/retry.js.map +1 -1
- package/dist/core/schema.d.ts +57 -53
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/step.d.ts +28 -78
- package/dist/core/step.d.ts.map +1 -1
- package/dist/core/step.js +53 -63
- package/dist/core/step.js.map +1 -1
- package/dist/core/workflow.d.ts +33 -61
- package/dist/core/workflow.d.ts.map +1 -1
- package/dist/core/workflow.js +31 -41
- package/dist/core/workflow.js.map +1 -1
- package/dist/database/backend.d.ts +53 -46
- package/dist/database/backend.d.ts.map +1 -1
- package/dist/database/backend.js +544 -577
- package/dist/database/backend.js.map +1 -1
- package/dist/database/base.js +48 -25
- package/dist/database/base.js.map +1 -1
- package/dist/database/migrations/20251212000000_0_init.d.ts +10 -0
- package/dist/database/migrations/20251212000000_0_init.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_0_init.js +8 -4
- package/dist/database/migrations/20251212000000_0_init.js.map +1 -1
- package/dist/database/migrations/20251212000000_1_tables.d.ts +10 -0
- package/dist/database/migrations/20251212000000_1_tables.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_1_tables.js +81 -83
- package/dist/database/migrations/20251212000000_1_tables.js.map +1 -1
- package/dist/database/migrations/20251212000000_2_fk.d.ts +10 -0
- package/dist/database/migrations/20251212000000_2_fk.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_2_fk.js +20 -43
- package/dist/database/migrations/20251212000000_2_fk.js.map +1 -1
- package/dist/database/migrations/20251212000000_3_indexes.d.ts +10 -0
- package/dist/database/migrations/20251212000000_3_indexes.d.ts.map +1 -0
- package/dist/database/migrations/20251212000000_3_indexes.js +88 -102
- package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -1
- package/dist/database/pubsub.d.ts +7 -16
- package/dist/database/pubsub.d.ts.map +1 -1
- package/dist/database/pubsub.js +75 -73
- package/dist/database/pubsub.js.map +1 -1
- package/dist/execution.d.ts +20 -59
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +175 -188
- package/dist/execution.js.map +1 -1
- package/dist/index.d.ts +5 -8
- package/dist/index.js +5 -5
- package/dist/internal.d.ts +12 -13
- package/dist/internal.js +4 -4
- package/dist/registry.d.ts +33 -27
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +58 -49
- package/dist/registry.js.map +1 -1
- package/dist/worker.d.ts +57 -50
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +194 -199
- package/dist/worker.js.map +1 -1
- package/dist/workflow.d.ts +26 -30
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +20 -15
- package/dist/workflow.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +17 -19
- package/src/backend.ts +25 -9
- package/src/chaos.test.ts +3 -1
- package/src/client.test.ts +2 -0
- package/src/client.ts +30 -8
- package/src/config.test.ts +1 -0
- package/src/config.ts +3 -2
- package/src/core/duration.test.ts +2 -1
- package/src/core/duration.ts +1 -1
- package/src/core/error.test.ts +1 -0
- package/src/core/error.ts +1 -1
- package/src/core/result.test.ts +1 -0
- package/src/core/retry.test.ts +3 -2
- package/src/core/retry.ts +1 -1
- package/src/core/schema.ts +2 -2
- package/src/core/step.test.ts +2 -1
- package/src/core/step.ts +4 -3
- package/src/core/workflow.test.ts +2 -1
- package/src/core/workflow.ts +4 -3
- package/src/database/backend.test.ts +1 -0
- package/src/database/backend.testsuite.ts +44 -40
- package/src/database/backend.ts +207 -25
- package/src/database/base.test.ts +41 -0
- package/src/database/base.ts +51 -2
- package/src/database/migrations/20251212000000_0_init.ts +2 -1
- package/src/database/migrations/20251212000000_1_tables.ts +2 -1
- package/src/database/migrations/20251212000000_2_fk.ts +2 -1
- package/src/database/migrations/20251212000000_3_indexes.ts +2 -1
- package/src/database/pubsub.test.ts +6 -3
- package/src/database/pubsub.ts +55 -33
- package/src/execution.test.ts +2 -0
- package/src/execution.ts +49 -10
- package/src/internal.ts +15 -15
- package/src/practices/01-remote-workflow.ts +1 -0
- package/src/registry.test.ts +1 -0
- package/src/registry.ts +1 -1
- package/src/testing/connection.ts +3 -1
- package/src/worker.test.ts +2 -0
- package/src/worker.ts +30 -9
- package/src/workflow.test.ts +1 -0
- package/src/workflow.ts +3 -3
- package/templates/openworkflow.config.ts +2 -1
- package/tsdown.config.ts +31 -0
- package/.swcrc +0 -17
- package/dist/chaos.test.d.ts +0 -2
- package/dist/chaos.test.d.ts.map +0 -1
- package/dist/chaos.test.js +0 -92
- package/dist/chaos.test.js.map +0 -1
- package/dist/client.test.d.ts +0 -2
- package/dist/client.test.d.ts.map +0 -1
- package/dist/client.test.js +0 -340
- package/dist/client.test.js.map +0 -1
- package/dist/config.test.d.ts +0 -2
- package/dist/config.test.d.ts.map +0 -1
- package/dist/config.test.js +0 -24
- package/dist/config.test.js.map +0 -1
- package/dist/core/duration.test.d.ts +0 -2
- package/dist/core/duration.test.d.ts.map +0 -1
- package/dist/core/duration.test.js +0 -265
- package/dist/core/duration.test.js.map +0 -1
- package/dist/core/error.test.d.ts +0 -2
- package/dist/core/error.test.d.ts.map +0 -1
- package/dist/core/error.test.js +0 -63
- package/dist/core/error.test.js.map +0 -1
- package/dist/core/json.js +0 -3
- package/dist/core/json.js.map +0 -1
- package/dist/core/result.test.d.ts +0 -2
- package/dist/core/result.test.d.ts.map +0 -1
- package/dist/core/result.test.js +0 -19
- package/dist/core/result.test.js.map +0 -1
- package/dist/core/retry.test.d.ts +0 -2
- package/dist/core/retry.test.d.ts.map +0 -1
- package/dist/core/retry.test.js +0 -198
- package/dist/core/retry.test.js.map +0 -1
- package/dist/core/schema.js +0 -4
- package/dist/core/schema.js.map +0 -1
- package/dist/core/step.test.d.ts +0 -2
- package/dist/core/step.test.d.ts.map +0 -1
- package/dist/core/step.test.js +0 -356
- package/dist/core/step.test.js.map +0 -1
- package/dist/core/workflow.test.d.ts +0 -2
- package/dist/core/workflow.test.d.ts.map +0 -1
- package/dist/core/workflow.test.js +0 -172
- package/dist/core/workflow.test.js.map +0 -1
- package/dist/database/backend.test.d.ts +0 -2
- package/dist/database/backend.test.d.ts.map +0 -1
- package/dist/database/backend.test.js +0 -19
- package/dist/database/backend.test.js.map +0 -1
- package/dist/database/backend.testsuite.d.ts +0 -20
- package/dist/database/backend.testsuite.d.ts.map +0 -1
- package/dist/database/backend.testsuite.js +0 -1280
- package/dist/database/backend.testsuite.js.map +0 -1
- package/dist/database/base.d.ts +0 -12
- package/dist/database/base.d.ts.map +0 -1
- package/dist/database/pubsub.test.d.ts +0 -2
- package/dist/database/pubsub.test.d.ts.map +0 -1
- package/dist/database/pubsub.test.js +0 -86
- package/dist/database/pubsub.test.js.map +0 -1
- package/dist/execution.test.d.ts +0 -2
- package/dist/execution.test.d.ts.map +0 -1
- package/dist/execution.test.js +0 -662
- package/dist/execution.test.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal.d.ts.map +0 -1
- package/dist/internal.js.map +0 -1
- package/dist/practices/01-remote-workflow.d.ts +0 -2
- package/dist/practices/01-remote-workflow.d.ts.map +0 -1
- package/dist/practices/01-remote-workflow.js +0 -70
- package/dist/practices/01-remote-workflow.js.map +0 -1
- package/dist/registry.test.d.ts +0 -2
- package/dist/registry.test.d.ts.map +0 -1
- package/dist/registry.test.js +0 -95
- package/dist/registry.test.js.map +0 -1
- package/dist/testing/connection.d.ts +0 -7
- package/dist/testing/connection.d.ts.map +0 -1
- package/dist/testing/connection.js +0 -39
- package/dist/testing/connection.js.map +0 -1
- package/dist/worker.test.d.ts +0 -2
- package/dist/worker.test.d.ts.map +0 -1
- package/dist/worker.test.js +0 -1164
- package/dist/worker.test.js.map +0 -1
- package/dist/workflow.test.d.ts +0 -2
- package/dist/workflow.test.d.ts.map +0 -1
- package/dist/workflow.test.js +0 -73
- package/dist/workflow.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/database/migrations/20251212000000_1_tables.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"20251212000000_1_tables.js","names":[],"sources":["../../../src/database/migrations/20251212000000_1_tables.ts"],"sourcesContent":["import { type Knex } from \"knex\";\n\nimport { DEFAULT_SCHEMA } from \"../base\";\n\nexport async function up(knex: Knex): Promise<void> {\n await knex.schema.withSchema(DEFAULT_SCHEMA).createTable(\"workflow_runs\", (table) => {\n table.text(\"namespace_id\").notNullable();\n table.text(\"id\").notNullable();\n table.text(\"workflow_name\").notNullable();\n table.text(\"version\");\n table.text(\"status\").notNullable();\n table.text(\"idempotency_key\");\n table.jsonb(\"config\").notNullable();\n table.jsonb(\"context\");\n table.jsonb(\"input\");\n table.jsonb(\"output\");\n table.jsonb(\"error\");\n table.integer(\"attempts\").notNullable();\n table.text(\"parent_step_attempt_namespace_id\");\n table.text(\"parent_step_attempt_id\");\n table.text(\"worker_id\");\n table.timestamp(\"available_at\", { useTz: true, precision: 3 });\n table.timestamp(\"deadline_at\", { useTz: true, precision: 3 });\n table.timestamp(\"started_at\", { useTz: true, precision: 3 });\n table.timestamp(\"finished_at\", { useTz: true, precision: 3 });\n table.timestamp(\"created_at\", { useTz: true, precision: 3 }).notNullable();\n table.timestamp(\"updated_at\", { useTz: true, precision: 3 }).notNullable();\n table.primary([\"namespace_id\", \"id\"]);\n });\n\n await knex.schema.withSchema(DEFAULT_SCHEMA).createTable(\"step_attempts\", (table) => {\n table.text(\"namespace_id\").notNullable();\n table.text(\"id\").notNullable();\n table.text(\"workflow_run_id\").notNullable();\n table.text(\"step_name\").notNullable();\n table.text(\"kind\").notNullable();\n table.text(\"status\").notNullable();\n table.jsonb(\"config\").notNullable();\n table.jsonb(\"context\");\n table.jsonb(\"output\");\n table.jsonb(\"error\");\n table.text(\"child_workflow_run_namespace_id\");\n table.text(\"child_workflow_run_id\");\n table.timestamp(\"started_at\", { useTz: true, precision: 3 });\n table.timestamp(\"finished_at\", { useTz: true, precision: 3 });\n table.timestamp(\"created_at\", { useTz: true, precision: 3 }).notNullable();\n table.timestamp(\"updated_at\", { useTz: true, precision: 3 }).notNullable();\n table.primary([\"namespace_id\", \"id\"]);\n });\n}\n\nexport async function down(knex: Knex): Promise<void> {\n await knex.schema.withSchema(DEFAULT_SCHEMA).dropTable(\"workflow_runs\");\n await knex.schema.withSchema(DEFAULT_SCHEMA).dropTable(\"step_attempts\");\n}\n"],"mappings":";;;AAIA,eAAsB,GAAG,MAA2B;AAClD,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,YAAY,kBAAkB,UAAU;AACnF,QAAM,KAAK,eAAe,CAAC,aAAa;AACxC,QAAM,KAAK,KAAK,CAAC,aAAa;AAC9B,QAAM,KAAK,gBAAgB,CAAC,aAAa;AACzC,QAAM,KAAK,UAAU;AACrB,QAAM,KAAK,SAAS,CAAC,aAAa;AAClC,QAAM,KAAK,kBAAkB;AAC7B,QAAM,MAAM,SAAS,CAAC,aAAa;AACnC,QAAM,MAAM,UAAU;AACtB,QAAM,MAAM,QAAQ;AACpB,QAAM,MAAM,SAAS;AACrB,QAAM,MAAM,QAAQ;AACpB,QAAM,QAAQ,WAAW,CAAC,aAAa;AACvC,QAAM,KAAK,mCAAmC;AAC9C,QAAM,KAAK,yBAAyB;AACpC,QAAM,KAAK,YAAY;AACvB,QAAM,UAAU,gBAAgB;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC;AAC9D,QAAM,UAAU,eAAe;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC;AAC7D,QAAM,UAAU,cAAc;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC;AAC5D,QAAM,UAAU,eAAe;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC;AAC7D,QAAM,UAAU,cAAc;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC,CAAC,aAAa;AAC1E,QAAM,UAAU,cAAc;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC,CAAC,aAAa;AAC1E,QAAM,QAAQ,CAAC,gBAAgB,KAAK,CAAC;GACrC;AAEF,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,YAAY,kBAAkB,UAAU;AACnF,QAAM,KAAK,eAAe,CAAC,aAAa;AACxC,QAAM,KAAK,KAAK,CAAC,aAAa;AAC9B,QAAM,KAAK,kBAAkB,CAAC,aAAa;AAC3C,QAAM,KAAK,YAAY,CAAC,aAAa;AACrC,QAAM,KAAK,OAAO,CAAC,aAAa;AAChC,QAAM,KAAK,SAAS,CAAC,aAAa;AAClC,QAAM,MAAM,SAAS,CAAC,aAAa;AACnC,QAAM,MAAM,UAAU;AACtB,QAAM,MAAM,SAAS;AACrB,QAAM,MAAM,QAAQ;AACpB,QAAM,KAAK,kCAAkC;AAC7C,QAAM,KAAK,wBAAwB;AACnC,QAAM,UAAU,cAAc;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC;AAC5D,QAAM,UAAU,eAAe;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC;AAC7D,QAAM,UAAU,cAAc;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC,CAAC,aAAa;AAC1E,QAAM,UAAU,cAAc;GAAE,OAAO;GAAM,WAAW;GAAG,CAAC,CAAC,aAAa;AAC1E,QAAM,QAAQ,CAAC,gBAAgB,KAAK,CAAC;GACrC;;AAGJ,eAAsB,KAAK,MAA2B;AACpD,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,UAAU,gBAAgB;AACvE,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,UAAU,gBAAgB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
//#region src/database/migrations/20251212000000_2_fk.d.ts
|
|
4
|
+
declare function up(knex: Knex): Promise<void>;
|
|
5
|
+
declare function down(knex: Knex): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=20251212000000_2_fk.d.ts.map
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { down, up };
|
|
10
|
+
//# sourceMappingURL=20251212000000_2_fk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20251212000000_2_fk.d.ts","names":[],"sources":["../../../src/database/migrations/20251212000000_2_fk.ts"],"sourcesContent":[],"mappings":";;;iBAIsB,EAAA,OAAS,OAAO;iBA4BhB,IAAA,OAAW,OAAO;AA5BxC"}
|
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
import { DEFAULT_SCHEMA } from "../base.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"child_workflow_run_namespace_id",
|
|
13
|
-
"child_workflow_run_id"
|
|
14
|
-
], "step_attempts_child_workflow_run_fk").references([
|
|
15
|
-
"namespace_id",
|
|
16
|
-
"id"
|
|
17
|
-
]).inTable(`${DEFAULT_SCHEMA}.workflow_runs`).onDelete("set null");
|
|
18
|
-
});
|
|
19
|
-
await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("workflow_runs", (table)=>{
|
|
20
|
-
table.foreign([
|
|
21
|
-
"parent_step_attempt_namespace_id",
|
|
22
|
-
"parent_step_attempt_id"
|
|
23
|
-
], "workflow_runs_parent_step_attempt_fk").references([
|
|
24
|
-
"namespace_id",
|
|
25
|
-
"id"
|
|
26
|
-
]).inTable(`${DEFAULT_SCHEMA}.step_attempts`).onDelete("set null");
|
|
27
|
-
});
|
|
2
|
+
|
|
3
|
+
//#region src/database/migrations/20251212000000_2_fk.ts
|
|
4
|
+
async function up(knex) {
|
|
5
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("step_attempts", (table) => {
|
|
6
|
+
table.foreign(["namespace_id", "workflow_run_id"], "step_attempts_workflow_run_fk").references(["namespace_id", "id"]).inTable(`${DEFAULT_SCHEMA}.workflow_runs`).onDelete("cascade");
|
|
7
|
+
table.foreign(["child_workflow_run_namespace_id", "child_workflow_run_id"], "step_attempts_child_workflow_run_fk").references(["namespace_id", "id"]).inTable(`${DEFAULT_SCHEMA}.workflow_runs`).onDelete("set null");
|
|
8
|
+
});
|
|
9
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("workflow_runs", (table) => {
|
|
10
|
+
table.foreign(["parent_step_attempt_namespace_id", "parent_step_attempt_id"], "workflow_runs_parent_step_attempt_fk").references(["namespace_id", "id"]).inTable(`${DEFAULT_SCHEMA}.step_attempts`).onDelete("set null");
|
|
11
|
+
});
|
|
28
12
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"child_workflow_run_id"
|
|
38
|
-
], "step_attempts_child_workflow_run_fk");
|
|
39
|
-
});
|
|
40
|
-
await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("workflow_runs", (table)=>{
|
|
41
|
-
table.dropForeign([
|
|
42
|
-
"parent_step_attempt_namespace_id",
|
|
43
|
-
"parent_step_attempt_id"
|
|
44
|
-
], "workflow_runs_parent_step_attempt_fk");
|
|
45
|
-
});
|
|
13
|
+
async function down(knex) {
|
|
14
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("step_attempts", (table) => {
|
|
15
|
+
table.dropForeign(["namespace_id", "workflow_run_id"], "step_attempts_workflow_run_fk");
|
|
16
|
+
table.dropForeign(["child_workflow_run_namespace_id", "child_workflow_run_id"], "step_attempts_child_workflow_run_fk");
|
|
17
|
+
});
|
|
18
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("workflow_runs", (table) => {
|
|
19
|
+
table.dropForeign(["parent_step_attempt_namespace_id", "parent_step_attempt_id"], "workflow_runs_parent_step_attempt_fk");
|
|
20
|
+
});
|
|
46
21
|
}
|
|
47
22
|
|
|
23
|
+
//#endregion
|
|
24
|
+
export { down, up };
|
|
48
25
|
//# sourceMappingURL=20251212000000_2_fk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/database/migrations/20251212000000_2_fk.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"20251212000000_2_fk.js","names":[],"sources":["../../../src/database/migrations/20251212000000_2_fk.ts"],"sourcesContent":["import { type Knex } from \"knex\";\n\nimport { DEFAULT_SCHEMA } from \"../base\";\n\nexport async function up(knex: Knex): Promise<void> {\n await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable(\"step_attempts\", (table) => {\n table\n .foreign([\"namespace_id\", \"workflow_run_id\"], \"step_attempts_workflow_run_fk\")\n .references([\"namespace_id\", \"id\"])\n .inTable(`${DEFAULT_SCHEMA}.workflow_runs`)\n .onDelete(\"cascade\");\n table\n .foreign(\n [\"child_workflow_run_namespace_id\", \"child_workflow_run_id\"],\n \"step_attempts_child_workflow_run_fk\",\n )\n .references([\"namespace_id\", \"id\"])\n .inTable(`${DEFAULT_SCHEMA}.workflow_runs`)\n .onDelete(\"set null\");\n });\n await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable(\"workflow_runs\", (table) => {\n table\n .foreign(\n [\"parent_step_attempt_namespace_id\", \"parent_step_attempt_id\"],\n \"workflow_runs_parent_step_attempt_fk\",\n )\n .references([\"namespace_id\", \"id\"])\n .inTable(`${DEFAULT_SCHEMA}.step_attempts`)\n .onDelete(\"set null\");\n });\n}\n\nexport async function down(knex: Knex): Promise<void> {\n await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable(\"step_attempts\", (table) => {\n table.dropForeign([\"namespace_id\", \"workflow_run_id\"], \"step_attempts_workflow_run_fk\");\n table.dropForeign(\n [\"child_workflow_run_namespace_id\", \"child_workflow_run_id\"],\n \"step_attempts_child_workflow_run_fk\",\n );\n });\n await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable(\"workflow_runs\", (table) => {\n table.dropForeign(\n [\"parent_step_attempt_namespace_id\", \"parent_step_attempt_id\"],\n \"workflow_runs_parent_step_attempt_fk\",\n );\n });\n}\n"],"mappings":";;;AAIA,eAAsB,GAAG,MAA2B;AAClD,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,WAAW,kBAAkB,UAAU;AAClF,QACG,QAAQ,CAAC,gBAAgB,kBAAkB,EAAE,gCAAgC,CAC7E,WAAW,CAAC,gBAAgB,KAAK,CAAC,CAClC,QAAQ,GAAG,eAAe,gBAAgB,CAC1C,SAAS,UAAU;AACtB,QACG,QACC,CAAC,mCAAmC,wBAAwB,EAC5D,sCACD,CACA,WAAW,CAAC,gBAAgB,KAAK,CAAC,CAClC,QAAQ,GAAG,eAAe,gBAAgB,CAC1C,SAAS,WAAW;GACvB;AACF,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,WAAW,kBAAkB,UAAU;AAClF,QACG,QACC,CAAC,oCAAoC,yBAAyB,EAC9D,uCACD,CACA,WAAW,CAAC,gBAAgB,KAAK,CAAC,CAClC,QAAQ,GAAG,eAAe,gBAAgB,CAC1C,SAAS,WAAW;GACvB;;AAGJ,eAAsB,KAAK,MAA2B;AACpD,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,WAAW,kBAAkB,UAAU;AAClF,QAAM,YAAY,CAAC,gBAAgB,kBAAkB,EAAE,gCAAgC;AACvF,QAAM,YACJ,CAAC,mCAAmC,wBAAwB,EAC5D,sCACD;GACD;AACF,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,WAAW,kBAAkB,UAAU;AAClF,QAAM,YACJ,CAAC,oCAAoC,yBAAyB,EAC9D,uCACD;GACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
//#region src/database/migrations/20251212000000_3_indexes.d.ts
|
|
4
|
+
declare function up(knex: Knex): Promise<void>;
|
|
5
|
+
declare function down(knex: Knex): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=20251212000000_3_indexes.d.ts.map
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { down, up };
|
|
10
|
+
//# sourceMappingURL=20251212000000_3_indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20251212000000_3_indexes.d.ts","names":[],"sources":["../../../src/database/migrations/20251212000000_3_indexes.ts"],"sourcesContent":[],"mappings":";;;iBAIsB,EAAA,OAAS,OAAO;iBAwChB,IAAA,OAAW,OAAO;AAxCxC"}
|
|
@@ -1,107 +1,93 @@
|
|
|
1
1
|
import { DEFAULT_SCHEMA } from "../base.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"created_at"
|
|
47
|
-
], "step_attempts_workflow_run_step_name_created_at_idx");
|
|
48
|
-
table.index([
|
|
49
|
-
"child_workflow_run_namespace_id",
|
|
50
|
-
"child_workflow_run_id"
|
|
51
|
-
], "step_attempts_child_workflow_run_idx");
|
|
52
|
-
});
|
|
2
|
+
|
|
3
|
+
//#region src/database/migrations/20251212000000_3_indexes.ts
|
|
4
|
+
async function up(knex) {
|
|
5
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).table("workflow_runs", (table) => {
|
|
6
|
+
table.index([
|
|
7
|
+
"namespace_id",
|
|
8
|
+
"status",
|
|
9
|
+
"available_at",
|
|
10
|
+
"created_at"
|
|
11
|
+
], "workflow_runs_status_available_at_created_at_idx");
|
|
12
|
+
table.index([
|
|
13
|
+
"namespace_id",
|
|
14
|
+
"workflow_name",
|
|
15
|
+
"idempotency_key",
|
|
16
|
+
"created_at"
|
|
17
|
+
], "workflow_runs_workflow_name_idempotency_key_created_at_idx");
|
|
18
|
+
table.index(["parent_step_attempt_namespace_id", "parent_step_attempt_id"], "workflow_runs_parent_step_idx");
|
|
19
|
+
table.index(["namespace_id", "created_at"], "workflow_runs_created_at_desc_idx");
|
|
20
|
+
table.index([
|
|
21
|
+
"namespace_id",
|
|
22
|
+
"status",
|
|
23
|
+
"created_at"
|
|
24
|
+
], "workflow_runs_status_created_at_desc_idx");
|
|
25
|
+
table.index([
|
|
26
|
+
"namespace_id",
|
|
27
|
+
"workflow_name",
|
|
28
|
+
"status",
|
|
29
|
+
"created_at"
|
|
30
|
+
], "workflow_runs_workflow_name_status_created_at_desc_idx");
|
|
31
|
+
});
|
|
32
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).table("step_attempts", (table) => {
|
|
33
|
+
table.index([
|
|
34
|
+
"namespace_id",
|
|
35
|
+
"workflow_run_id",
|
|
36
|
+
"created_at"
|
|
37
|
+
], "step_attempts_workflow_run_created_at_idx");
|
|
38
|
+
table.index([
|
|
39
|
+
"namespace_id",
|
|
40
|
+
"workflow_run_id",
|
|
41
|
+
"step_name",
|
|
42
|
+
"created_at"
|
|
43
|
+
], "step_attempts_workflow_run_step_name_created_at_idx");
|
|
44
|
+
table.index(["child_workflow_run_namespace_id", "child_workflow_run_id"], "step_attempts_child_workflow_run_idx");
|
|
45
|
+
});
|
|
53
46
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"workflow_run_id",
|
|
97
|
-
"step_name",
|
|
98
|
-
"created_at"
|
|
99
|
-
], "step_attempts_workflow_run_step_name_created_at_idx");
|
|
100
|
-
table.dropIndex([
|
|
101
|
-
"child_workflow_run_namespace_id",
|
|
102
|
-
"child_workflow_run_id"
|
|
103
|
-
], "step_attempts_child_workflow_run_idx");
|
|
104
|
-
});
|
|
47
|
+
async function down(knex) {
|
|
48
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).table("workflow_runs", (table) => {
|
|
49
|
+
table.dropIndex([
|
|
50
|
+
"namespace_id",
|
|
51
|
+
"status",
|
|
52
|
+
"available_at",
|
|
53
|
+
"created_at"
|
|
54
|
+
], "workflow_runs_status_available_at_created_at_idx");
|
|
55
|
+
table.dropIndex([
|
|
56
|
+
"namespace_id",
|
|
57
|
+
"workflow_name",
|
|
58
|
+
"idempotency_key",
|
|
59
|
+
"created_at"
|
|
60
|
+
], "workflow_runs_workflow_name_idempotency_key_created_at_idx");
|
|
61
|
+
table.dropIndex(["parent_step_attempt_namespace_id", "parent_step_attempt_id"], "workflow_runs_parent_step_idx");
|
|
62
|
+
table.dropIndex(["namespace_id", "created_at"], "workflow_runs_created_at_desc_idx");
|
|
63
|
+
table.dropIndex([
|
|
64
|
+
"namespace_id",
|
|
65
|
+
"status",
|
|
66
|
+
"created_at"
|
|
67
|
+
], "workflow_runs_status_created_at_desc_idx");
|
|
68
|
+
table.dropIndex([
|
|
69
|
+
"namespace_id",
|
|
70
|
+
"workflow_name",
|
|
71
|
+
"status",
|
|
72
|
+
"created_at"
|
|
73
|
+
], "workflow_runs_workflow_name_status_created_at_desc_idx");
|
|
74
|
+
});
|
|
75
|
+
await knex.schema.withSchema(DEFAULT_SCHEMA).table("step_attempts", (table) => {
|
|
76
|
+
table.dropIndex([
|
|
77
|
+
"namespace_id",
|
|
78
|
+
"workflow_run_id",
|
|
79
|
+
"created_at"
|
|
80
|
+
], "step_attempts_workflow_run_created_at_idx");
|
|
81
|
+
table.dropIndex([
|
|
82
|
+
"namespace_id",
|
|
83
|
+
"workflow_run_id",
|
|
84
|
+
"step_name",
|
|
85
|
+
"created_at"
|
|
86
|
+
], "step_attempts_workflow_run_step_name_created_at_idx");
|
|
87
|
+
table.dropIndex(["child_workflow_run_namespace_id", "child_workflow_run_id"], "step_attempts_child_workflow_run_idx");
|
|
88
|
+
});
|
|
105
89
|
}
|
|
106
90
|
|
|
91
|
+
//#endregion
|
|
92
|
+
export { down, up };
|
|
107
93
|
//# sourceMappingURL=20251212000000_3_indexes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/database/migrations/20251212000000_3_indexes.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"20251212000000_3_indexes.js","names":[],"sources":["../../../src/database/migrations/20251212000000_3_indexes.ts"],"sourcesContent":["import { type Knex } from \"knex\";\n\nimport { DEFAULT_SCHEMA } from \"../base\";\n\nexport async function up(knex: Knex): Promise<void> {\n await knex.schema.withSchema(DEFAULT_SCHEMA).table(\"workflow_runs\", (table) => {\n table.index(\n [\"namespace_id\", \"status\", \"available_at\", \"created_at\"],\n \"workflow_runs_status_available_at_created_at_idx\",\n );\n table.index(\n [\"namespace_id\", \"workflow_name\", \"idempotency_key\", \"created_at\"],\n \"workflow_runs_workflow_name_idempotency_key_created_at_idx\",\n );\n table.index(\n [\"parent_step_attempt_namespace_id\", \"parent_step_attempt_id\"],\n \"workflow_runs_parent_step_idx\",\n );\n table.index([\"namespace_id\", \"created_at\"], \"workflow_runs_created_at_desc_idx\");\n table.index(\n [\"namespace_id\", \"status\", \"created_at\"],\n \"workflow_runs_status_created_at_desc_idx\",\n );\n table.index(\n [\"namespace_id\", \"workflow_name\", \"status\", \"created_at\"],\n \"workflow_runs_workflow_name_status_created_at_desc_idx\",\n );\n });\n await knex.schema.withSchema(DEFAULT_SCHEMA).table(\"step_attempts\", (table) => {\n table.index(\n [\"namespace_id\", \"workflow_run_id\", \"created_at\"],\n \"step_attempts_workflow_run_created_at_idx\",\n );\n table.index(\n [\"namespace_id\", \"workflow_run_id\", \"step_name\", \"created_at\"],\n \"step_attempts_workflow_run_step_name_created_at_idx\",\n );\n table.index(\n [\"child_workflow_run_namespace_id\", \"child_workflow_run_id\"],\n \"step_attempts_child_workflow_run_idx\",\n );\n });\n}\n\nexport async function down(knex: Knex): Promise<void> {\n await knex.schema.withSchema(DEFAULT_SCHEMA).table(\"workflow_runs\", (table) => {\n table.dropIndex(\n [\"namespace_id\", \"status\", \"available_at\", \"created_at\"],\n \"workflow_runs_status_available_at_created_at_idx\",\n );\n table.dropIndex(\n [\"namespace_id\", \"workflow_name\", \"idempotency_key\", \"created_at\"],\n \"workflow_runs_workflow_name_idempotency_key_created_at_idx\",\n );\n table.dropIndex(\n [\"parent_step_attempt_namespace_id\", \"parent_step_attempt_id\"],\n \"workflow_runs_parent_step_idx\",\n );\n table.dropIndex([\"namespace_id\", \"created_at\"], \"workflow_runs_created_at_desc_idx\");\n table.dropIndex(\n [\"namespace_id\", \"status\", \"created_at\"],\n \"workflow_runs_status_created_at_desc_idx\",\n );\n table.dropIndex(\n [\"namespace_id\", \"workflow_name\", \"status\", \"created_at\"],\n \"workflow_runs_workflow_name_status_created_at_desc_idx\",\n );\n });\n await knex.schema.withSchema(DEFAULT_SCHEMA).table(\"step_attempts\", (table) => {\n table.dropIndex(\n [\"namespace_id\", \"workflow_run_id\", \"created_at\"],\n \"step_attempts_workflow_run_created_at_idx\",\n );\n table.dropIndex(\n [\"namespace_id\", \"workflow_run_id\", \"step_name\", \"created_at\"],\n \"step_attempts_workflow_run_step_name_created_at_idx\",\n );\n table.dropIndex(\n [\"child_workflow_run_namespace_id\", \"child_workflow_run_id\"],\n \"step_attempts_child_workflow_run_idx\",\n );\n });\n}\n"],"mappings":";;;AAIA,eAAsB,GAAG,MAA2B;AAClD,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,MAAM,kBAAkB,UAAU;AAC7E,QAAM,MACJ;GAAC;GAAgB;GAAU;GAAgB;GAAa,EACxD,mDACD;AACD,QAAM,MACJ;GAAC;GAAgB;GAAiB;GAAmB;GAAa,EAClE,6DACD;AACD,QAAM,MACJ,CAAC,oCAAoC,yBAAyB,EAC9D,gCACD;AACD,QAAM,MAAM,CAAC,gBAAgB,aAAa,EAAE,oCAAoC;AAChF,QAAM,MACJ;GAAC;GAAgB;GAAU;GAAa,EACxC,2CACD;AACD,QAAM,MACJ;GAAC;GAAgB;GAAiB;GAAU;GAAa,EACzD,yDACD;GACD;AACF,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,MAAM,kBAAkB,UAAU;AAC7E,QAAM,MACJ;GAAC;GAAgB;GAAmB;GAAa,EACjD,4CACD;AACD,QAAM,MACJ;GAAC;GAAgB;GAAmB;GAAa;GAAa,EAC9D,sDACD;AACD,QAAM,MACJ,CAAC,mCAAmC,wBAAwB,EAC5D,uCACD;GACD;;AAGJ,eAAsB,KAAK,MAA2B;AACpD,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,MAAM,kBAAkB,UAAU;AAC7E,QAAM,UACJ;GAAC;GAAgB;GAAU;GAAgB;GAAa,EACxD,mDACD;AACD,QAAM,UACJ;GAAC;GAAgB;GAAiB;GAAmB;GAAa,EAClE,6DACD;AACD,QAAM,UACJ,CAAC,oCAAoC,yBAAyB,EAC9D,gCACD;AACD,QAAM,UAAU,CAAC,gBAAgB,aAAa,EAAE,oCAAoC;AACpF,QAAM,UACJ;GAAC;GAAgB;GAAU;GAAa,EACxC,2CACD;AACD,QAAM,UACJ;GAAC;GAAgB;GAAiB;GAAU;GAAa,EACzD,yDACD;GACD;AACF,OAAM,KAAK,OAAO,WAAW,eAAe,CAAC,MAAM,kBAAkB,UAAU;AAC7E,QAAM,UACJ;GAAC;GAAgB;GAAmB;GAAa,EACjD,4CACD;AACD,QAAM,UACJ;GAAC;GAAgB;GAAmB;GAAa;GAAa,EAC9D,sDACD;AACD,QAAM,UACJ,CAAC,mCAAmC,wBAAwB,EAC5D,uCACD;GACD"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private _listeners;
|
|
9
|
-
private _connection;
|
|
10
|
-
private constructor();
|
|
11
|
-
get destroyed(): boolean;
|
|
12
|
-
connect(): Promise<void>;
|
|
13
|
-
destroy(): Promise<void>;
|
|
14
|
-
static create(knex: Knex): Promise<PostgresPubSub>;
|
|
15
|
-
listenEvent(channel: string, callback: OnSubscribed): void;
|
|
16
|
-
}
|
|
1
|
+
import { Result } from "../core/result.js";
|
|
2
|
+
import { Knex } from "knex";
|
|
3
|
+
|
|
4
|
+
//#region src/database/pubsub.d.ts
|
|
5
|
+
type OnSubscribed = (result: Result<string | null>) => void | Promise<void>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { OnSubscribed };
|
|
17
8
|
//# sourceMappingURL=pubsub.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.d.ts","
|
|
1
|
+
{"version":3,"file":"pubsub.d.ts","names":[],"sources":["../../src/database/pubsub.ts"],"sourcesContent":[],"mappings":";;;;KAOY,YAAA,YAAwB,iCAAiC"}
|
package/dist/database/pubsub.js
CHANGED
|
@@ -1,76 +1,78 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
1
|
import { err, ok } from "../core/result.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
|
|
4
|
+
//#region src/database/pubsub.ts
|
|
5
|
+
var PostgresPubSub = class PostgresPubSub {
|
|
6
|
+
_destroyed = false;
|
|
7
|
+
_connecting = false;
|
|
8
|
+
_onClosed;
|
|
9
|
+
_onNotification;
|
|
10
|
+
_onError;
|
|
11
|
+
_listeners = /* @__PURE__ */ new Map();
|
|
12
|
+
_connection = null;
|
|
13
|
+
constructor(knex) {
|
|
14
|
+
this.knex = knex;
|
|
15
|
+
this._onClosed = (async () => {
|
|
16
|
+
if (this._destroyed) return;
|
|
17
|
+
await this.connect();
|
|
18
|
+
}).bind(this);
|
|
19
|
+
this._onNotification = (async ({ channel, payload: rawPayload }) => {
|
|
20
|
+
const payload = typeof rawPayload === "string" && rawPayload.length !== 0 ? rawPayload : null;
|
|
21
|
+
const listeners = this._listeners.get(channel);
|
|
22
|
+
if (!listeners) return;
|
|
23
|
+
const result = ok(payload);
|
|
24
|
+
await Promise.allSettled(Array.from(listeners.values()).map((listener) => Promise.resolve(listener(result))));
|
|
25
|
+
}).bind(this);
|
|
26
|
+
this._onError = (async (error) => {
|
|
27
|
+
const result = err(error);
|
|
28
|
+
await Promise.allSettled(Array.from(this._listeners.values()).flatMap((listeners) => Array.from(listeners)).map((listener) => Promise.resolve(listener(result))));
|
|
29
|
+
}).bind(this);
|
|
30
|
+
}
|
|
31
|
+
get destroyed() {
|
|
32
|
+
return this._destroyed;
|
|
33
|
+
}
|
|
34
|
+
async connect() {
|
|
35
|
+
if (this._connecting) return;
|
|
36
|
+
this._connecting = true;
|
|
37
|
+
try {
|
|
38
|
+
const connection = await this.knex.client.acquireRawConnection();
|
|
39
|
+
connection.on("close", this._onClosed);
|
|
40
|
+
connection.on("notification", this._onNotification);
|
|
41
|
+
connection.on("error", this._onError);
|
|
42
|
+
for (const channel of this._listeners.keys()) connection.query(`LISTEN ${channel}`);
|
|
43
|
+
this._connection = connection;
|
|
44
|
+
} finally {
|
|
45
|
+
this._connecting = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async destroy() {
|
|
49
|
+
if (this._destroyed) return;
|
|
50
|
+
try {
|
|
51
|
+
this._connection.off("close", this._onClosed);
|
|
52
|
+
this._connection.off("notification", this._onNotification);
|
|
53
|
+
this._connection.off("error", this._onError);
|
|
54
|
+
await this.knex.client.destroyRawConnection(this._connection);
|
|
55
|
+
} finally {
|
|
56
|
+
this._destroyed = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
static async create(knex) {
|
|
60
|
+
const listener = new PostgresPubSub(knex);
|
|
61
|
+
await listener.connect();
|
|
62
|
+
return listener;
|
|
63
|
+
}
|
|
64
|
+
listenEvent(channel, callback) {
|
|
65
|
+
if (!this._listeners.has(channel)) {
|
|
66
|
+
this._connection?.query(`LISTEN ${channel}`);
|
|
67
|
+
this._listeners.set(channel, (/* @__PURE__ */ new Set()).add(callback));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const listeners = this._listeners.get(channel);
|
|
71
|
+
assert(listeners, "Listener channel not found");
|
|
72
|
+
listeners.add(callback);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
75
|
|
|
76
|
+
//#endregion
|
|
77
|
+
export { PostgresPubSub };
|
|
76
78
|
//# sourceMappingURL=pubsub.js.map
|