@crombolo/data 0.22.0 → 0.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/data",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -28,6 +28,6 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@crombolo/core": "0.22.0"
31
+ "@crombolo/core": "0.23.0"
32
32
  }
33
33
  }
@@ -340,6 +340,14 @@ export class DocumentRepository {
340
340
  return this.#inTreeLock ? fn() : this.#db.locks.withLock(KINDS[this.kind].lock, fn)
341
341
  }
342
342
 
343
+ /**
344
+ * Runs `fn` under the tree lock in one transaction, with a repository bound to
345
+ * it, so several writes commit together or not at all (story 170).
346
+ */
347
+ async atomically<T>(fn: (repo: DocumentRepository) => Promise<T>): Promise<T> {
348
+ return this.#withTree(() => this.#db.transaction((tx) => fn(this.#child(tx))))
349
+ }
350
+
343
351
  #child(tx: Db): DocumentRepository {
344
352
  return new DocumentRepository(tx, {
345
353
  nodeState: this.#nodeState,