@effectstream/db 0.100.15 → 0.100.16

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/README.md CHANGED
@@ -5,6 +5,11 @@ connection pool, ships every pgtyped-generated SQL query the runtime
5
5
  needs, owns the snapshot loop, and provides a mutex needed for safe
6
6
  single-threaded PgLite access.
7
7
 
8
+ - Pooled Postgres client plus every pgtyped query the runtime needs.
9
+ - Snapshot loop (`runSnapshotLoop`) and `acquireDBMutex` / `releaseDBMutex` for PgLite.
10
+ - Subpath scripts for in-memory PgLite, migrations, and version checks.
11
+ - `getConnection()` is the dominant entry point, ~31 call sites across the repo.
12
+
8
13
  ## Install
9
14
 
10
15
  ```bash
@@ -62,34 +67,34 @@ can rejoin without re-syncing from genesis.
62
67
 
63
68
  Connection management (heavily used):
64
69
 
65
- - `getConnection(creds?)` — pooled `Pool` singleton. The dominant entry point (~31 cross-package call sites).
66
- - `acquireDBMutex(name, priority?)` / `releaseDBMutex(name)` — coordination for PgLite (~7 cross-package call sites each).
70
+ - `getConnection(creds?)`: pooled `Pool` singleton. Dominant entry point (~31 call sites across the repo).
71
+ - `acquireDBMutex(name, priority?)` and `releaseDBMutex(name)` coordinate PgLite access; ~7 call sites each.
67
72
  - `waitUntilFree()` — companion to the mutex.
68
- - `getPersistentConnection(creds)` — a non-pooled `Client` for long-lived listeners.
73
+ - `getPersistentConnection(creds)` returns a non-pooled `Client` for long-lived listeners.
69
74
 
70
75
  Queries (pgtyped-generated, shipped under one umbrella):
71
76
 
72
- - `getBlockHeights`, `getBlockByHash`, `blockHeightDone`, `saveLastBlock`, `getLatestProcessedBlockHeight` — block bookkeeping.
73
- - `getAchievementProgress`, `setAchievementProgress` — achievements.
77
+ - Block bookkeeping: `getBlockHeights`, `getBlockByHash`, `blockHeightDone`, `saveLastBlock`, `getLatestProcessedBlockHeight`.
78
+ - Achievements: `getAchievementProgress`, `setAchievementProgress`.
74
79
  - Re-exports of `*.queries.ts` for statistics, nonces, rollup inputs, accounts, events, sync protocol pages, primitives, system, tables.
75
80
 
76
81
  Snapshots:
77
82
 
78
83
  - `runSnapshotLoop` — periodic `pg_dump` of synced state.
79
- - `createSnapshot` — single-shot snapshot helper.
80
- - `SnapshotConfig`, `SnapshotRetentionConfig` — config types.
84
+ - `createSnapshot`: single-shot snapshot helper.
85
+ - `SnapshotConfig`, `SnapshotRetentionConfig`: config types.
81
86
 
82
87
  Dynamic table / event helpers:
83
88
 
84
- - `createDynamicTables` — register tables a primitive wants to own.
85
- - `createIndexesForEvents`, `registerEventHandlers` — register pgtyped indexes for app events.
89
+ - `createDynamicTables` registers tables a primitive wants to own.
90
+ - `createIndexesForEvents` creates pgtyped indexes for app events; `registerEventTypes` records each event's topic/name in the database.
86
91
 
87
92
  Subpath entry points (executable scripts):
88
93
 
89
- - `@effectstream/db/start-pglite` — boot a PgLite instance.
94
+ - `@effectstream/db/start-pglite`: boot a PgLite instance.
90
95
  - `@effectstream/db/apply-migrations` — apply SQL migrations against the active DB.
91
- - `@effectstream/db/db-wait` — block until the DB accepts a connection.
92
- - `@effectstream/db/pgtyped-update` — regenerate pgtyped types.
96
+ - `@effectstream/db/db-wait`: block until the DB accepts a connection.
97
+ - `@effectstream/db/pgtyped-update`: regenerate pgtyped types.
93
98
  - `@effectstream/db/version` — print schema version.
94
99
 
95
100
  ## Examples
@@ -100,4 +105,4 @@ Subpath entry points (executable scripts):
100
105
  ## Links
101
106
 
102
107
  - Docs: https://effectstream.github.io/docs/packages/node/db
103
- - Source: https://github.com/PaimaStudios/paima-engine/tree/main/packages/node-sdk/db
108
+ - Source: https://github.com/effectstream/effectstream/tree/main/packages/node-sdk/db
@@ -104,12 +104,15 @@ export function* getLastBlockHeight(
104
104
  dbConn: Client,
105
105
  ): Operation<number> {
106
106
  yield* acquireDBMutex("get-last-block-height");
107
- const v = versionInfo.is_empty
108
- ? 0
109
- : (yield* until(getLatestProcessedBlockHeight.run(undefined, dbConn)))[0]
110
- .block_height;
111
- releaseDBMutex("get-last-block-height");
112
- return v;
107
+ try {
108
+ if (versionInfo.is_empty) return 0;
109
+ const rows = yield* until(
110
+ getLatestProcessedBlockHeight.run(undefined, dbConn),
111
+ );
112
+ return rows[0]?.block_height ?? 0;
113
+ } finally {
114
+ releaseDBMutex("get-last-block-height");
115
+ }
113
116
  }
114
117
 
115
118
  export function* getVersionInfo(dbConn: Client): Operation<VersionInfo> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/db",
3
- "version": "0.100.15",
3
+ "version": "0.100.16",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -21,11 +21,11 @@
21
21
  "./version": "./migrations/system-version.ts"
22
22
  },
23
23
  "dependencies": {
24
- "@effectstream/coroutine": "0.100.15",
25
- "@effectstream/log": "0.100.15",
26
- "@effectstream/runtime": "0.100.15",
27
- "@effectstream/sync": "0.100.15",
28
- "@effectstream/utils": "0.100.15",
24
+ "@effectstream/coroutine": "0.100.16",
25
+ "@effectstream/log": "0.100.16",
26
+ "@effectstream/runtime": "0.100.16",
27
+ "@effectstream/sync": "0.100.16",
28
+ "@effectstream/utils": "0.100.16",
29
29
  "@electric-sql/pglite": "^0.3.14",
30
30
  "@pgtyped/runtime": "2.4.2",
31
31
  "@pgtyped/parser": "2.4.2",