@sonamu-kit/tasks 0.1.3 → 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.
Files changed (215) hide show
  1. package/.oxlintrc.json +3 -0
  2. package/AGENTS.md +21 -0
  3. package/dist/backend.d.ts +126 -103
  4. package/dist/backend.d.ts.map +1 -1
  5. package/dist/backend.js +4 -1
  6. package/dist/backend.js.map +1 -1
  7. package/dist/client.d.ts +145 -132
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +220 -212
  10. package/dist/client.js.map +1 -1
  11. package/dist/config.d.ts +15 -8
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +22 -17
  14. package/dist/config.js.map +1 -1
  15. package/dist/core/duration.d.ts +5 -4
  16. package/dist/core/duration.d.ts.map +1 -1
  17. package/dist/core/duration.js +54 -59
  18. package/dist/core/duration.js.map +1 -1
  19. package/dist/core/error.d.ts +10 -7
  20. package/dist/core/error.d.ts.map +1 -1
  21. package/dist/core/error.js +21 -21
  22. package/dist/core/error.js.map +1 -1
  23. package/dist/core/json.d.ts +8 -3
  24. package/dist/core/json.d.ts.map +1 -1
  25. package/dist/core/result.d.ts +10 -14
  26. package/dist/core/result.d.ts.map +1 -1
  27. package/dist/core/result.js +21 -16
  28. package/dist/core/result.js.map +1 -1
  29. package/dist/core/retry.d.ts +42 -20
  30. package/dist/core/retry.d.ts.map +1 -1
  31. package/dist/core/retry.js +49 -20
  32. package/dist/core/retry.js.map +1 -1
  33. package/dist/core/schema.d.ts +57 -53
  34. package/dist/core/schema.d.ts.map +1 -1
  35. package/dist/core/step.d.ts +28 -78
  36. package/dist/core/step.d.ts.map +1 -1
  37. package/dist/core/step.js +53 -63
  38. package/dist/core/step.js.map +1 -1
  39. package/dist/core/workflow.d.ts +33 -61
  40. package/dist/core/workflow.d.ts.map +1 -1
  41. package/dist/core/workflow.js +31 -41
  42. package/dist/core/workflow.js.map +1 -1
  43. package/dist/database/backend.d.ts +53 -46
  44. package/dist/database/backend.d.ts.map +1 -1
  45. package/dist/database/backend.js +544 -545
  46. package/dist/database/backend.js.map +1 -1
  47. package/dist/database/base.js +48 -25
  48. package/dist/database/base.js.map +1 -1
  49. package/dist/database/migrations/20251212000000_0_init.d.ts +10 -0
  50. package/dist/database/migrations/20251212000000_0_init.d.ts.map +1 -0
  51. package/dist/database/migrations/20251212000000_0_init.js +8 -4
  52. package/dist/database/migrations/20251212000000_0_init.js.map +1 -1
  53. package/dist/database/migrations/20251212000000_1_tables.d.ts +10 -0
  54. package/dist/database/migrations/20251212000000_1_tables.d.ts.map +1 -0
  55. package/dist/database/migrations/20251212000000_1_tables.js +81 -83
  56. package/dist/database/migrations/20251212000000_1_tables.js.map +1 -1
  57. package/dist/database/migrations/20251212000000_2_fk.d.ts +10 -0
  58. package/dist/database/migrations/20251212000000_2_fk.d.ts.map +1 -0
  59. package/dist/database/migrations/20251212000000_2_fk.js +20 -43
  60. package/dist/database/migrations/20251212000000_2_fk.js.map +1 -1
  61. package/dist/database/migrations/20251212000000_3_indexes.d.ts +10 -0
  62. package/dist/database/migrations/20251212000000_3_indexes.d.ts.map +1 -0
  63. package/dist/database/migrations/20251212000000_3_indexes.js +88 -102
  64. package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -1
  65. package/dist/database/pubsub.d.ts +7 -16
  66. package/dist/database/pubsub.d.ts.map +1 -1
  67. package/dist/database/pubsub.js +75 -73
  68. package/dist/database/pubsub.js.map +1 -1
  69. package/dist/execution.d.ts +20 -57
  70. package/dist/execution.d.ts.map +1 -1
  71. package/dist/execution.js +175 -174
  72. package/dist/execution.js.map +1 -1
  73. package/dist/index.d.ts +5 -8
  74. package/dist/index.js +5 -5
  75. package/dist/internal.d.ts +12 -12
  76. package/dist/internal.js +4 -4
  77. package/dist/registry.d.ts +33 -27
  78. package/dist/registry.d.ts.map +1 -1
  79. package/dist/registry.js +58 -49
  80. package/dist/registry.js.map +1 -1
  81. package/dist/worker.d.ts +57 -50
  82. package/dist/worker.d.ts.map +1 -1
  83. package/dist/worker.js +194 -198
  84. package/dist/worker.js.map +1 -1
  85. package/dist/workflow.d.ts +26 -27
  86. package/dist/workflow.d.ts.map +1 -1
  87. package/dist/workflow.js +20 -15
  88. package/dist/workflow.js.map +1 -1
  89. package/nodemon.json +1 -1
  90. package/package.json +18 -20
  91. package/src/backend.ts +28 -8
  92. package/src/chaos.test.ts +3 -1
  93. package/src/client.test.ts +2 -0
  94. package/src/client.ts +32 -8
  95. package/src/config.test.ts +1 -0
  96. package/src/config.ts +3 -2
  97. package/src/core/duration.test.ts +2 -1
  98. package/src/core/duration.ts +1 -1
  99. package/src/core/error.test.ts +1 -0
  100. package/src/core/error.ts +1 -1
  101. package/src/core/result.test.ts +1 -0
  102. package/src/core/retry.test.ts +181 -11
  103. package/src/core/retry.ts +95 -19
  104. package/src/core/schema.ts +2 -2
  105. package/src/core/step.test.ts +2 -1
  106. package/src/core/step.ts +4 -3
  107. package/src/core/workflow.test.ts +2 -1
  108. package/src/core/workflow.ts +4 -3
  109. package/src/database/backend.test.ts +1 -0
  110. package/src/database/backend.testsuite.ts +162 -39
  111. package/src/database/backend.ts +271 -35
  112. package/src/database/base.test.ts +41 -0
  113. package/src/database/base.ts +51 -2
  114. package/src/database/migrations/20251212000000_0_init.ts +2 -1
  115. package/src/database/migrations/20251212000000_1_tables.ts +2 -1
  116. package/src/database/migrations/20251212000000_2_fk.ts +2 -1
  117. package/src/database/migrations/20251212000000_3_indexes.ts +2 -1
  118. package/src/database/pubsub.test.ts +6 -3
  119. package/src/database/pubsub.ts +55 -33
  120. package/src/execution.test.ts +117 -0
  121. package/src/execution.ts +65 -10
  122. package/src/internal.ts +21 -1
  123. package/src/practices/01-remote-workflow.ts +1 -0
  124. package/src/registry.test.ts +1 -0
  125. package/src/registry.ts +1 -1
  126. package/src/testing/connection.ts +3 -1
  127. package/src/worker.test.ts +2 -0
  128. package/src/worker.ts +31 -9
  129. package/src/workflow.test.ts +1 -0
  130. package/src/workflow.ts +5 -2
  131. package/templates/openworkflow.config.ts +2 -1
  132. package/tsdown.config.ts +31 -0
  133. package/.swcrc +0 -17
  134. package/dist/chaos.test.d.ts +0 -2
  135. package/dist/chaos.test.d.ts.map +0 -1
  136. package/dist/chaos.test.js +0 -92
  137. package/dist/chaos.test.js.map +0 -1
  138. package/dist/client.test.d.ts +0 -2
  139. package/dist/client.test.d.ts.map +0 -1
  140. package/dist/client.test.js +0 -340
  141. package/dist/client.test.js.map +0 -1
  142. package/dist/config.test.d.ts +0 -2
  143. package/dist/config.test.d.ts.map +0 -1
  144. package/dist/config.test.js +0 -24
  145. package/dist/config.test.js.map +0 -1
  146. package/dist/core/duration.test.d.ts +0 -2
  147. package/dist/core/duration.test.d.ts.map +0 -1
  148. package/dist/core/duration.test.js +0 -265
  149. package/dist/core/duration.test.js.map +0 -1
  150. package/dist/core/error.test.d.ts +0 -2
  151. package/dist/core/error.test.d.ts.map +0 -1
  152. package/dist/core/error.test.js +0 -63
  153. package/dist/core/error.test.js.map +0 -1
  154. package/dist/core/json.js +0 -3
  155. package/dist/core/json.js.map +0 -1
  156. package/dist/core/result.test.d.ts +0 -2
  157. package/dist/core/result.test.d.ts.map +0 -1
  158. package/dist/core/result.test.js +0 -19
  159. package/dist/core/result.test.js.map +0 -1
  160. package/dist/core/retry.test.d.ts +0 -2
  161. package/dist/core/retry.test.d.ts.map +0 -1
  162. package/dist/core/retry.test.js +0 -37
  163. package/dist/core/retry.test.js.map +0 -1
  164. package/dist/core/schema.js +0 -4
  165. package/dist/core/schema.js.map +0 -1
  166. package/dist/core/step.test.d.ts +0 -2
  167. package/dist/core/step.test.d.ts.map +0 -1
  168. package/dist/core/step.test.js +0 -356
  169. package/dist/core/step.test.js.map +0 -1
  170. package/dist/core/workflow.test.d.ts +0 -2
  171. package/dist/core/workflow.test.d.ts.map +0 -1
  172. package/dist/core/workflow.test.js +0 -172
  173. package/dist/core/workflow.test.js.map +0 -1
  174. package/dist/database/backend.test.d.ts +0 -2
  175. package/dist/database/backend.test.d.ts.map +0 -1
  176. package/dist/database/backend.test.js +0 -19
  177. package/dist/database/backend.test.js.map +0 -1
  178. package/dist/database/backend.testsuite.d.ts +0 -20
  179. package/dist/database/backend.testsuite.d.ts.map +0 -1
  180. package/dist/database/backend.testsuite.js +0 -1174
  181. package/dist/database/backend.testsuite.js.map +0 -1
  182. package/dist/database/base.d.ts +0 -12
  183. package/dist/database/base.d.ts.map +0 -1
  184. package/dist/database/pubsub.test.d.ts +0 -2
  185. package/dist/database/pubsub.test.d.ts.map +0 -1
  186. package/dist/database/pubsub.test.js +0 -86
  187. package/dist/database/pubsub.test.js.map +0 -1
  188. package/dist/execution.test.d.ts +0 -2
  189. package/dist/execution.test.d.ts.map +0 -1
  190. package/dist/execution.test.js +0 -558
  191. package/dist/execution.test.js.map +0 -1
  192. package/dist/index.d.ts.map +0 -1
  193. package/dist/index.js.map +0 -1
  194. package/dist/internal.d.ts.map +0 -1
  195. package/dist/internal.js.map +0 -1
  196. package/dist/practices/01-remote-workflow.d.ts +0 -2
  197. package/dist/practices/01-remote-workflow.d.ts.map +0 -1
  198. package/dist/practices/01-remote-workflow.js +0 -70
  199. package/dist/practices/01-remote-workflow.js.map +0 -1
  200. package/dist/registry.test.d.ts +0 -2
  201. package/dist/registry.test.d.ts.map +0 -1
  202. package/dist/registry.test.js +0 -95
  203. package/dist/registry.test.js.map +0 -1
  204. package/dist/testing/connection.d.ts +0 -7
  205. package/dist/testing/connection.d.ts.map +0 -1
  206. package/dist/testing/connection.js +0 -39
  207. package/dist/testing/connection.js.map +0 -1
  208. package/dist/worker.test.d.ts +0 -2
  209. package/dist/worker.test.d.ts.map +0 -1
  210. package/dist/worker.test.js +0 -1164
  211. package/dist/worker.test.js.map +0 -1
  212. package/dist/workflow.test.d.ts +0 -2
  213. package/dist/workflow.test.d.ts.map +0 -1
  214. package/dist/workflow.test.js +0 -73
  215. package/dist/workflow.test.js.map +0 -1
@@ -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
- export async function up(knex) {
3
- await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("step_attempts", (table)=>{
4
- table.foreign([
5
- "namespace_id",
6
- "workflow_run_id"
7
- ], "step_attempts_workflow_run_fk").references([
8
- "namespace_id",
9
- "id"
10
- ]).inTable(`${DEFAULT_SCHEMA}.workflow_runs`).onDelete("cascade");
11
- table.foreign([
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
- export async function down(knex) {
30
- await knex.schema.withSchema(DEFAULT_SCHEMA).alterTable("step_attempts", (table)=>{
31
- table.dropForeign([
32
- "namespace_id",
33
- "workflow_run_id"
34
- ], "step_attempts_workflow_run_fk");
35
- table.dropForeign([
36
- "child_workflow_run_namespace_id",
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 { Knex } from \"knex\";\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"],"names":["DEFAULT_SCHEMA","up","knex","schema","withSchema","alterTable","table","foreign","references","inTable","onDelete","down","dropForeign"],"mappings":"AACA,SAASA,cAAc,QAAQ,aAAU;AAEzC,OAAO,eAAeC,GAAGC,IAAU;IACjC,MAAMA,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,UAAU,CAAC,iBAAiB,CAACC;QACxEA,MACGC,OAAO,CAAC;YAAC;YAAgB;SAAkB,EAAE,iCAC7CC,UAAU,CAAC;YAAC;YAAgB;SAAK,EACjCC,OAAO,CAAC,GAAGT,eAAe,cAAc,CAAC,EACzCU,QAAQ,CAAC;QACZJ,MACGC,OAAO,CACN;YAAC;YAAmC;SAAwB,EAC5D,uCAEDC,UAAU,CAAC;YAAC;YAAgB;SAAK,EACjCC,OAAO,CAAC,GAAGT,eAAe,cAAc,CAAC,EACzCU,QAAQ,CAAC;IACd;IACA,MAAMR,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,UAAU,CAAC,iBAAiB,CAACC;QACxEA,MACGC,OAAO,CACN;YAAC;YAAoC;SAAyB,EAC9D,wCAEDC,UAAU,CAAC;YAAC;YAAgB;SAAK,EACjCC,OAAO,CAAC,GAAGT,eAAe,cAAc,CAAC,EACzCU,QAAQ,CAAC;IACd;AACF;AAEA,OAAO,eAAeC,KAAKT,IAAU;IACnC,MAAMA,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,UAAU,CAAC,iBAAiB,CAACC;QACxEA,MAAMM,WAAW,CAAC;YAAC;YAAgB;SAAkB,EAAE;QACvDN,MAAMM,WAAW,CACf;YAAC;YAAmC;SAAwB,EAC5D;IAEJ;IACA,MAAMV,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,UAAU,CAAC,iBAAiB,CAACC;QACxEA,MAAMM,WAAW,CACf;YAAC;YAAoC;SAAyB,EAC9D;IAEJ;AACF"}
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
- export async function up(knex) {
3
- await knex.schema.withSchema(DEFAULT_SCHEMA).table("workflow_runs", (table)=>{
4
- table.index([
5
- "namespace_id",
6
- "status",
7
- "available_at",
8
- "created_at"
9
- ], "workflow_runs_status_available_at_created_at_idx");
10
- table.index([
11
- "namespace_id",
12
- "workflow_name",
13
- "idempotency_key",
14
- "created_at"
15
- ], "workflow_runs_workflow_name_idempotency_key_created_at_idx");
16
- table.index([
17
- "parent_step_attempt_namespace_id",
18
- "parent_step_attempt_id"
19
- ], "workflow_runs_parent_step_idx");
20
- table.index([
21
- "namespace_id",
22
- "created_at"
23
- ], "workflow_runs_created_at_desc_idx");
24
- table.index([
25
- "namespace_id",
26
- "status",
27
- "created_at"
28
- ], "workflow_runs_status_created_at_desc_idx");
29
- table.index([
30
- "namespace_id",
31
- "workflow_name",
32
- "status",
33
- "created_at"
34
- ], "workflow_runs_workflow_name_status_created_at_desc_idx");
35
- });
36
- await knex.schema.withSchema(DEFAULT_SCHEMA).table("step_attempts", (table)=>{
37
- table.index([
38
- "namespace_id",
39
- "workflow_run_id",
40
- "created_at"
41
- ], "step_attempts_workflow_run_created_at_idx");
42
- table.index([
43
- "namespace_id",
44
- "workflow_run_id",
45
- "step_name",
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
- export async function down(knex) {
55
- await knex.schema.withSchema(DEFAULT_SCHEMA).table("workflow_runs", (table)=>{
56
- table.dropIndex([
57
- "namespace_id",
58
- "status",
59
- "available_at",
60
- "created_at"
61
- ], "workflow_runs_status_available_at_created_at_idx");
62
- table.dropIndex([
63
- "namespace_id",
64
- "workflow_name",
65
- "idempotency_key",
66
- "created_at"
67
- ], "workflow_runs_workflow_name_idempotency_key_created_at_idx");
68
- table.dropIndex([
69
- "parent_step_attempt_namespace_id",
70
- "parent_step_attempt_id"
71
- ], "workflow_runs_parent_step_idx");
72
- table.dropIndex([
73
- "namespace_id",
74
- "created_at"
75
- ], "workflow_runs_created_at_desc_idx");
76
- table.dropIndex([
77
- "namespace_id",
78
- "status",
79
- "created_at"
80
- ], "workflow_runs_status_created_at_desc_idx");
81
- table.dropIndex([
82
- "namespace_id",
83
- "workflow_name",
84
- "status",
85
- "created_at"
86
- ], "workflow_runs_workflow_name_status_created_at_desc_idx");
87
- });
88
- await knex.schema.withSchema(DEFAULT_SCHEMA).table("step_attempts", (table)=>{
89
- table.dropIndex([
90
- "namespace_id",
91
- "workflow_run_id",
92
- "created_at"
93
- ], "step_attempts_workflow_run_created_at_idx");
94
- table.dropIndex([
95
- "namespace_id",
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 { Knex } from \"knex\";\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"],"names":["DEFAULT_SCHEMA","up","knex","schema","withSchema","table","index","down","dropIndex"],"mappings":"AACA,SAASA,cAAc,QAAQ,aAAU;AAEzC,OAAO,eAAeC,GAAGC,IAAU;IACjC,MAAMA,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,KAAK,CAAC,iBAAiB,CAACA;QACnEA,MAAMC,KAAK,CACT;YAAC;YAAgB;YAAU;YAAgB;SAAa,EACxD;QAEFD,MAAMC,KAAK,CACT;YAAC;YAAgB;YAAiB;YAAmB;SAAa,EAClE;QAEFD,MAAMC,KAAK,CACT;YAAC;YAAoC;SAAyB,EAC9D;QAEFD,MAAMC,KAAK,CAAC;YAAC;YAAgB;SAAa,EAAE;QAC5CD,MAAMC,KAAK,CACT;YAAC;YAAgB;YAAU;SAAa,EACxC;QAEFD,MAAMC,KAAK,CACT;YAAC;YAAgB;YAAiB;YAAU;SAAa,EACzD;IAEJ;IACA,MAAMJ,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,KAAK,CAAC,iBAAiB,CAACA;QACnEA,MAAMC,KAAK,CACT;YAAC;YAAgB;YAAmB;SAAa,EACjD;QAEFD,MAAMC,KAAK,CACT;YAAC;YAAgB;YAAmB;YAAa;SAAa,EAC9D;QAEFD,MAAMC,KAAK,CACT;YAAC;YAAmC;SAAwB,EAC5D;IAEJ;AACF;AAEA,OAAO,eAAeC,KAAKL,IAAU;IACnC,MAAMA,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,KAAK,CAAC,iBAAiB,CAACA;QACnEA,MAAMG,SAAS,CACb;YAAC;YAAgB;YAAU;YAAgB;SAAa,EACxD;QAEFH,MAAMG,SAAS,CACb;YAAC;YAAgB;YAAiB;YAAmB;SAAa,EAClE;QAEFH,MAAMG,SAAS,CACb;YAAC;YAAoC;SAAyB,EAC9D;QAEFH,MAAMG,SAAS,CAAC;YAAC;YAAgB;SAAa,EAAE;QAChDH,MAAMG,SAAS,CACb;YAAC;YAAgB;YAAU;SAAa,EACxC;QAEFH,MAAMG,SAAS,CACb;YAAC;YAAgB;YAAiB;YAAU;SAAa,EACzD;IAEJ;IACA,MAAMN,KAAKC,MAAM,CAACC,UAAU,CAACJ,gBAAgBK,KAAK,CAAC,iBAAiB,CAACA;QACnEA,MAAMG,SAAS,CACb;YAAC;YAAgB;YAAmB;SAAa,EACjD;QAEFH,MAAMG,SAAS,CACb;YAAC;YAAgB;YAAmB;YAAa;SAAa,EAC9D;QAEFH,MAAMG,SAAS,CACb;YAAC;YAAmC;SAAwB,EAC5D;IAEJ;AACF"}
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 type { Knex } from "knex";
2
- import { type Result } from "../core/result";
3
- export type OnSubscribed = (result: Result<string | null>) => void | Promise<void>;
4
- export declare class PostgresPubSub {
5
- private readonly knex;
6
- private _destroyed;
7
- private _onClosed;
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","sourceRoot":"","sources":["../../src/database/pubsub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnF,qBAAa,cAAc;IAQL,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPzC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,UAAU,CAAwC;IAG1D,OAAO,CAAC,WAAW,CAAoB;IAEvC,OAAO;IAWP,IAAI,SAAS,YAEZ;IAGK,OAAO;IAoCP,OAAO;WAaA,MAAM,CAAC,IAAI,EAAE,IAAI;IAO9B,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY;CAWpD"}
1
+ {"version":3,"file":"pubsub.d.ts","names":[],"sources":["../../src/database/pubsub.ts"],"sourcesContent":[],"mappings":";;;;KAOY,YAAA,YAAwB,iCAAiC"}
@@ -1,76 +1,78 @@
1
- import assert from "assert";
2
1
  import { err, ok } from "../core/result.js";
3
- export class PostgresPubSub {
4
- knex;
5
- _destroyed = false;
6
- _onClosed;
7
- _listeners = new Map();
8
- // biome-ignore lint/suspicious/noExplicitAny: Knex exposes a connection as any
9
- _connection = null;
10
- constructor(knex){
11
- this.knex = knex;
12
- // Re-connect to the database when the connection is closed and not destroyed manually
13
- this._onClosed = (async ()=>{
14
- if (this._destroyed) {
15
- return;
16
- }
17
- await this.connect();
18
- }).bind(this);
19
- }
20
- get destroyed() {
21
- return this._destroyed;
22
- }
23
- // acquire new raw connection and set up listeners
24
- async connect() {
25
- const connection = await this.knex.client.acquireRawConnection();
26
- connection.on("close", this._onClosed);
27
- connection.on("notification", async ({ channel, payload: rawPayload })=>{
28
- const payload = typeof rawPayload === "string" && rawPayload.length !== 0 ? rawPayload : null;
29
- const listeners = this._listeners.get(channel);
30
- if (!listeners) {
31
- return;
32
- }
33
- const result = ok(payload);
34
- await Promise.allSettled(Array.from(listeners.values()).map((listener)=>Promise.resolve(listener(result))));
35
- });
36
- connection.on("error", async (error)=>{
37
- const result = err(error);
38
- await Promise.allSettled(Array.from(this._listeners.values()).flatMap((listeners)=>Array.from(listeners)).map((listener)=>Promise.resolve(listener(result))));
39
- });
40
- for (const channel of this._listeners.keys()){
41
- connection.query(`LISTEN ${channel}`);
42
- }
43
- this._connection = connection;
44
- }
45
- // destroy the listener and close the connection, do not destroy the knex connection
46
- async destroy() {
47
- if (this._destroyed) {
48
- return;
49
- }
50
- try {
51
- this._connection.off("close", this._onClosed);
52
- await this.knex.client.destroyRawConnection(this._connection);
53
- } finally{
54
- this._destroyed = true;
55
- }
56
- }
57
- // create a new listener and connect to the database
58
- static async create(knex) {
59
- const listener = new PostgresPubSub(knex);
60
- await listener.connect();
61
- return listener;
62
- }
63
- // add a new listener to the channel
64
- listenEvent(channel, callback) {
65
- if (!this._listeners.has(channel)) {
66
- this._connection?.query(`LISTEN ${channel}`);
67
- this._listeners.set(channel, 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
- }
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/database/pubsub.ts"],"sourcesContent":["import assert from \"assert\";\nimport type { Knex } from \"knex\";\nimport { err, ok, type Result } from \"../core/result\";\n\nexport type OnSubscribed = (result: Result<string | null>) => void | Promise<void>;\n\nexport class PostgresPubSub {\n private _destroyed = false;\n private _onClosed: () => Promise<void>;\n private _listeners = new Map<string, Set<OnSubscribed>>();\n\n // biome-ignore lint/suspicious/noExplicitAny: Knex exposes a connection as any\n private _connection: any | null = null;\n\n private constructor(private readonly knex: Knex) {\n // Re-connect to the database when the connection is closed and not destroyed manually\n this._onClosed = (async () => {\n if (this._destroyed) {\n return;\n }\n\n await this.connect();\n }).bind(this);\n }\n\n get destroyed() {\n return this._destroyed;\n }\n\n // acquire new raw connection and set up listeners\n async connect() {\n const connection = await this.knex.client.acquireRawConnection();\n connection.on(\"close\", this._onClosed);\n connection.on(\n \"notification\",\n async ({ channel, payload: rawPayload }: { channel: string; payload: unknown }) => {\n const payload =\n typeof rawPayload === \"string\" && rawPayload.length !== 0 ? rawPayload : null;\n const listeners = this._listeners.get(channel);\n if (!listeners) {\n return;\n }\n\n const result = ok(payload);\n await Promise.allSettled(\n Array.from(listeners.values()).map((listener) => Promise.resolve(listener(result))),\n );\n },\n );\n connection.on(\"error\", async (error: Error) => {\n const result = err(error);\n await Promise.allSettled(\n Array.from(this._listeners.values())\n .flatMap((listeners) => Array.from(listeners))\n .map((listener) => Promise.resolve(listener(result))),\n );\n });\n\n for (const channel of this._listeners.keys()) {\n connection.query(`LISTEN ${channel}`);\n }\n\n this._connection = connection;\n }\n\n // destroy the listener and close the connection, do not destroy the knex connection\n async destroy() {\n if (this._destroyed) {\n return;\n }\n try {\n this._connection.off(\"close\", this._onClosed);\n await this.knex.client.destroyRawConnection(this._connection);\n } finally {\n this._destroyed = true;\n }\n }\n\n // create a new listener and connect to the database\n static async create(knex: Knex) {\n const listener = new PostgresPubSub(knex);\n await listener.connect();\n return listener;\n }\n\n // add a new listener to the channel\n listenEvent(channel: string, callback: OnSubscribed) {\n if (!this._listeners.has(channel)) {\n this._connection?.query(`LISTEN ${channel}`);\n this._listeners.set(channel, new Set<OnSubscribed>().add(callback));\n return;\n }\n\n const listeners = this._listeners.get(channel);\n assert(listeners, \"Listener channel not found\");\n listeners.add(callback);\n }\n}\n"],"names":["assert","err","ok","PostgresPubSub","_destroyed","_onClosed","_listeners","Map","_connection","knex","connect","bind","destroyed","connection","client","acquireRawConnection","on","channel","payload","rawPayload","length","listeners","get","result","Promise","allSettled","Array","from","values","map","listener","resolve","error","flatMap","keys","query","destroy","off","destroyRawConnection","create","listenEvent","callback","has","set","Set","add"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,SAASC,GAAG,EAAEC,EAAE,QAAqB,oBAAiB;AAItD,OAAO,MAAMC;;IACHC,aAAa,MAAM;IACnBC,UAA+B;IAC/BC,aAAa,IAAIC,MAAiC;IAE1D,+EAA+E;IACvEC,cAA0B,KAAK;IAEvC,YAAoB,AAAiBC,IAAU,CAAE;aAAZA,OAAAA;QACnC,sFAAsF;QACtF,IAAI,CAACJ,SAAS,GAAG,AAAC,CAAA;YAChB,IAAI,IAAI,CAACD,UAAU,EAAE;gBACnB;YACF;YAEA,MAAM,IAAI,CAACM,OAAO;QACpB,CAAA,EAAGC,IAAI,CAAC,IAAI;IACd;IAEA,IAAIC,YAAY;QACd,OAAO,IAAI,CAACR,UAAU;IACxB;IAEA,kDAAkD;IAClD,MAAMM,UAAU;QACd,MAAMG,aAAa,MAAM,IAAI,CAACJ,IAAI,CAACK,MAAM,CAACC,oBAAoB;QAC9DF,WAAWG,EAAE,CAAC,SAAS,IAAI,CAACX,SAAS;QACrCQ,WAAWG,EAAE,CACX,gBACA,OAAO,EAAEC,OAAO,EAAEC,SAASC,UAAU,EAAyC;YAC5E,MAAMD,UACJ,OAAOC,eAAe,YAAYA,WAAWC,MAAM,KAAK,IAAID,aAAa;YAC3E,MAAME,YAAY,IAAI,CAACf,UAAU,CAACgB,GAAG,CAACL;YACtC,IAAI,CAACI,WAAW;gBACd;YACF;YAEA,MAAME,SAASrB,GAAGgB;YAClB,MAAMM,QAAQC,UAAU,CACtBC,MAAMC,IAAI,CAACN,UAAUO,MAAM,IAAIC,GAAG,CAAC,CAACC,WAAaN,QAAQO,OAAO,CAACD,SAASP;QAE9E;QAEFV,WAAWG,EAAE,CAAC,SAAS,OAAOgB;YAC5B,MAAMT,SAAStB,IAAI+B;YACnB,MAAMR,QAAQC,UAAU,CACtBC,MAAMC,IAAI,CAAC,IAAI,CAACrB,UAAU,CAACsB,MAAM,IAC9BK,OAAO,CAAC,CAACZ,YAAcK,MAAMC,IAAI,CAACN,YAClCQ,GAAG,CAAC,CAACC,WAAaN,QAAQO,OAAO,CAACD,SAASP;QAElD;QAEA,KAAK,MAAMN,WAAW,IAAI,CAACX,UAAU,CAAC4B,IAAI,GAAI;YAC5CrB,WAAWsB,KAAK,CAAC,CAAC,OAAO,EAAElB,SAAS;QACtC;QAEA,IAAI,CAACT,WAAW,GAAGK;IACrB;IAEA,oFAAoF;IACpF,MAAMuB,UAAU;QACd,IAAI,IAAI,CAAChC,UAAU,EAAE;YACnB;QACF;QACA,IAAI;YACF,IAAI,CAACI,WAAW,CAAC6B,GAAG,CAAC,SAAS,IAAI,CAAChC,SAAS;YAC5C,MAAM,IAAI,CAACI,IAAI,CAACK,MAAM,CAACwB,oBAAoB,CAAC,IAAI,CAAC9B,WAAW;QAC9D,SAAU;YACR,IAAI,CAACJ,UAAU,GAAG;QACpB;IACF;IAEA,oDAAoD;IACpD,aAAamC,OAAO9B,IAAU,EAAE;QAC9B,MAAMqB,WAAW,IAAI3B,eAAeM;QACpC,MAAMqB,SAASpB,OAAO;QACtB,OAAOoB;IACT;IAEA,oCAAoC;IACpCU,YAAYvB,OAAe,EAAEwB,QAAsB,EAAE;QACnD,IAAI,CAAC,IAAI,CAACnC,UAAU,CAACoC,GAAG,CAACzB,UAAU;YACjC,IAAI,CAACT,WAAW,EAAE2B,MAAM,CAAC,OAAO,EAAElB,SAAS;YAC3C,IAAI,CAACX,UAAU,CAACqC,GAAG,CAAC1B,SAAS,IAAI2B,MAAoBC,GAAG,CAACJ;YACzD;QACF;QAEA,MAAMpB,YAAY,IAAI,CAACf,UAAU,CAACgB,GAAG,CAACL;QACtCjB,OAAOqB,WAAW;QAClBA,UAAUwB,GAAG,CAACJ;IAChB;AACF"}
1
+ {"version":3,"file":"pubsub.js","names":["knex: Knex"],"sources":["../../src/database/pubsub.ts"],"sourcesContent":["import assert from \"assert\";\n\nimport { type Knex } from \"knex\";\n\nimport { err, ok } from \"../core/result\";\nimport { type Result } from \"../core/result\";\n\nexport type OnSubscribed = (result: Result<string | null>) => void | Promise<void>;\n\nexport class PostgresPubSub {\n private _destroyed = false;\n private _connecting = false;\n private _onClosed: () => Promise<void>;\n private _onNotification: (msg: { channel: string; payload: unknown }) => Promise<void>;\n private _onError: (error: Error) => Promise<void>;\n private _listeners = new Map<string, Set<OnSubscribed>>();\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any -- Knex exposes a connection as any\n private _connection: any | null = null;\n\n private constructor(private readonly knex: Knex) {\n // Re-connect to the database when the connection is closed and not destroyed manually\n this._onClosed = (async () => {\n if (this._destroyed) {\n return;\n }\n\n await this.connect();\n }).bind(this);\n\n this._onNotification = (async ({\n channel,\n payload: rawPayload,\n }: {\n channel: string;\n payload: unknown;\n }) => {\n const payload = typeof rawPayload === \"string\" && rawPayload.length !== 0 ? rawPayload : null;\n const listeners = this._listeners.get(channel);\n if (!listeners) {\n return;\n }\n\n const result = ok(payload);\n await Promise.allSettled(\n Array.from(listeners.values()).map((listener) => Promise.resolve(listener(result))),\n );\n }).bind(this);\n\n this._onError = (async (error: Error) => {\n const result = err(error);\n await Promise.allSettled(\n Array.from(this._listeners.values())\n .flatMap((listeners) => Array.from(listeners))\n .map((listener) => Promise.resolve(listener(result))),\n );\n }).bind(this);\n }\n\n get destroyed() {\n return this._destroyed;\n }\n\n // acquire new raw connection and set up listeners\n async connect() {\n // 동시 재연결 시도로 인한 연결 누수를 방지합니다.\n if (this._connecting) return;\n this._connecting = true;\n\n try {\n const connection = await this.knex.client.acquireRawConnection();\n connection.on(\"close\", this._onClosed);\n connection.on(\"notification\", this._onNotification);\n connection.on(\"error\", this._onError);\n\n for (const channel of this._listeners.keys()) {\n connection.query(`LISTEN ${channel}`);\n }\n\n this._connection = connection;\n } finally {\n this._connecting = false;\n }\n }\n\n // destroy the listener and close the connection, do not destroy the knex connection\n async destroy() {\n if (this._destroyed) {\n return;\n }\n try {\n this._connection.off(\"close\", this._onClosed);\n this._connection.off(\"notification\", this._onNotification);\n this._connection.off(\"error\", this._onError);\n await this.knex.client.destroyRawConnection(this._connection);\n } finally {\n this._destroyed = true;\n }\n }\n\n // create a new listener and connect to the database\n static async create(knex: Knex) {\n const listener = new PostgresPubSub(knex);\n await listener.connect();\n return listener;\n }\n\n // add a new listener to the channel\n listenEvent(channel: string, callback: OnSubscribed) {\n if (!this._listeners.has(channel)) {\n this._connection?.query(`LISTEN ${channel}`);\n this._listeners.set(channel, new Set<OnSubscribed>().add(callback));\n return;\n }\n\n const listeners = this._listeners.get(channel);\n assert(listeners, \"Listener channel not found\");\n listeners.add(callback);\n }\n}\n"],"mappings":";;;;AASA,IAAa,iBAAb,MAAa,eAAe;CAC1B,AAAQ,aAAa;CACrB,AAAQ,cAAc;CACtB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ,6BAAa,IAAI,KAAgC;CAGzD,AAAQ,cAA0B;CAElC,AAAQ,YAAY,AAAiBA,MAAY;EAAZ;AAEnC,OAAK,aAAa,YAAY;AAC5B,OAAI,KAAK,WACP;AAGF,SAAM,KAAK,SAAS;KACnB,KAAK,KAAK;AAEb,OAAK,mBAAmB,OAAO,EAC7B,SACA,SAAS,iBAIL;GACJ,MAAM,UAAU,OAAO,eAAe,YAAY,WAAW,WAAW,IAAI,aAAa;GACzF,MAAM,YAAY,KAAK,WAAW,IAAI,QAAQ;AAC9C,OAAI,CAAC,UACH;GAGF,MAAM,SAAS,GAAG,QAAQ;AAC1B,SAAM,QAAQ,WACZ,MAAM,KAAK,UAAU,QAAQ,CAAC,CAAC,KAAK,aAAa,QAAQ,QAAQ,SAAS,OAAO,CAAC,CAAC,CACpF;KACA,KAAK,KAAK;AAEb,OAAK,YAAY,OAAO,UAAiB;GACvC,MAAM,SAAS,IAAI,MAAM;AACzB,SAAM,QAAQ,WACZ,MAAM,KAAK,KAAK,WAAW,QAAQ,CAAC,CACjC,SAAS,cAAc,MAAM,KAAK,UAAU,CAAC,CAC7C,KAAK,aAAa,QAAQ,QAAQ,SAAS,OAAO,CAAC,CAAC,CACxD;KACA,KAAK,KAAK;;CAGf,IAAI,YAAY;AACd,SAAO,KAAK;;CAId,MAAM,UAAU;AAEd,MAAI,KAAK,YAAa;AACtB,OAAK,cAAc;AAEnB,MAAI;GACF,MAAM,aAAa,MAAM,KAAK,KAAK,OAAO,sBAAsB;AAChE,cAAW,GAAG,SAAS,KAAK,UAAU;AACtC,cAAW,GAAG,gBAAgB,KAAK,gBAAgB;AACnD,cAAW,GAAG,SAAS,KAAK,SAAS;AAErC,QAAK,MAAM,WAAW,KAAK,WAAW,MAAM,CAC1C,YAAW,MAAM,UAAU,UAAU;AAGvC,QAAK,cAAc;YACX;AACR,QAAK,cAAc;;;CAKvB,MAAM,UAAU;AACd,MAAI,KAAK,WACP;AAEF,MAAI;AACF,QAAK,YAAY,IAAI,SAAS,KAAK,UAAU;AAC7C,QAAK,YAAY,IAAI,gBAAgB,KAAK,gBAAgB;AAC1D,QAAK,YAAY,IAAI,SAAS,KAAK,SAAS;AAC5C,SAAM,KAAK,KAAK,OAAO,qBAAqB,KAAK,YAAY;YACrD;AACR,QAAK,aAAa;;;CAKtB,aAAa,OAAO,MAAY;EAC9B,MAAM,WAAW,IAAI,eAAe,KAAK;AACzC,QAAM,SAAS,SAAS;AACxB,SAAO;;CAIT,YAAY,SAAiB,UAAwB;AACnD,MAAI,CAAC,KAAK,WAAW,IAAI,QAAQ,EAAE;AACjC,QAAK,aAAa,MAAM,UAAU,UAAU;AAC5C,QAAK,WAAW,IAAI,0BAAS,IAAI,KAAmB,EAAC,IAAI,SAAS,CAAC;AACnE;;EAGF,MAAM,YAAY,KAAK,WAAW,IAAI,QAAQ;AAC9C,SAAO,WAAW,6BAA6B;AAC/C,YAAU,IAAI,SAAS"}