@iterativeflow/mysql 2.0.0-alpha.5 → 2.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -48,4 +48,21 @@ declare const ddl: (prefix?: string) => string[];
48
48
  /** Apply the schema DDL (idempotent). Run once before use. */
49
49
  declare const applySchema: (sql: Sql, prefix?: string) => Promise<void>;
50
50
  //#endregion
51
- export { type MysqlBackendOpts, type Sql, applySchema, createMysqlBackend, ddl, mysqlPool };
51
+ //#region src/tx.d.ts
52
+ /**
53
+ * Run `fn` inside one MySQL transaction, handing it a {@link Backend} bound to that
54
+ * transaction plus the raw {@link Sql} for the caller's own writes. Every `submit` /
55
+ * `startRun` / `enqueue` on that backend commits ATOMICALLY with the caller's writes on
56
+ * `tx` — the transactional-enqueue guarantee: business work and workflow dispatch land
57
+ * together or not at all. A throw rolls back both, so a failed request never leaves an
58
+ * orphan run or a dangling job.
59
+ *
60
+ * @example
61
+ * await inTx(pool, async (backend, tx) => {
62
+ * await tx.query("INSERT INTO orders (id) VALUES (?)", [orderId]);
63
+ * await submit(backend, fulfilOrder, { orderId }); // enqueued iff the order commits
64
+ * });
65
+ */
66
+ declare const inTx: <T>(pool: Pool, fn: (backend: Backend, tx: Sql) => Promise<T>, opts?: MysqlBackendOpts) => Promise<T>;
67
+ //#endregion
68
+ export { type MysqlBackendOpts, type Sql, applySchema, createMysqlBackend, ddl, inTx, mysqlPool };
package/dist/index.mjs CHANGED
@@ -627,4 +627,21 @@ const mysqlPool = (pool) => {
627
627
  };
628
628
  };
629
629
  //#endregion
630
- export { applySchema, createMysqlBackend, ddl, mysqlPool };
630
+ //#region src/tx.ts
631
+ /**
632
+ * Run `fn` inside one MySQL transaction, handing it a {@link Backend} bound to that
633
+ * transaction plus the raw {@link Sql} for the caller's own writes. Every `submit` /
634
+ * `startRun` / `enqueue` on that backend commits ATOMICALLY with the caller's writes on
635
+ * `tx` — the transactional-enqueue guarantee: business work and workflow dispatch land
636
+ * together or not at all. A throw rolls back both, so a failed request never leaves an
637
+ * orphan run or a dangling job.
638
+ *
639
+ * @example
640
+ * await inTx(pool, async (backend, tx) => {
641
+ * await tx.query("INSERT INTO orders (id) VALUES (?)", [orderId]);
642
+ * await submit(backend, fulfilOrder, { orderId }); // enqueued iff the order commits
643
+ * });
644
+ */
645
+ const inTx = (pool, fn, opts) => mysqlPool(pool).tx((tx) => fn(createMysqlBackend(tx, opts), tx));
646
+ //#endregion
647
+ export { applySchema, createMysqlBackend, ddl, inTx, mysqlPool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iterativeflow/mysql",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "build": "tsdown"
29
29
  },
30
30
  "dependencies": {
31
- "@iterativeflow/core": "2.0.0-alpha.5"
31
+ "@iterativeflow/core": "2.0.0-alpha.6"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "mysql2": ">=3.0.0"