@ultimat3/db 31.45.0 → 31.47.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/README.md CHANGED
@@ -17,6 +17,12 @@ boundary stays thin.
17
17
  ```ts
18
18
  import { db, sql, raw, withTransaction, currentTx, setDbClient } from '@ultimat3/db';
19
19
 
20
+ declare const cache: { restore(id: string): void };
21
+
22
+ declare const orgId: string;
23
+ declare const id: string;
24
+ type Post = { readonly id: string; readonly orgId: string; readonly title: string };
25
+
20
26
  const rows = await db().query<Post>(sql`select * from posts where org_id = ${orgId}`);
21
27
 
22
28
  await withTransaction(async (tx) => {
@@ -184,7 +190,9 @@ policy) live above it, and `@ultimat3/mcp` imports nothing of this package but o
184
190
  `endOfBlockComment` (a nested `/* */` ends where Postgres ends it, `null` when it never closes).
185
191
 
186
192
  ```ts
187
- import { ensureReadOnlyRole, readOnlyQuery } from '@ultimat3/db';
193
+ import { db, ensureReadOnlyRole, readOnlyQuery } from '@ultimat3/db';
194
+
195
+ declare const statement: string;
188
196
 
189
197
  const role = await ensureReadOnlyRole(db()); // layer 1, once at boot
190
198
  const { rows, guards } = await readOnlyQuery(statement, { role }); // layer 2, per statement
@@ -535,6 +543,10 @@ process. The module is resolved on the first statement, never at import, so an i
535
543
  ever talks to a managed Postgres never loads it.
536
544
 
537
545
  ```ts
546
+ import { branchPglite, pgliteClient, pgliteDataDir, setDbClient } from '@ultimat3/db';
547
+
548
+ declare const services: { readonly db: { readonly url: string } };
549
+
538
550
  const dev = pgliteClient({ dataDir: pgliteDataDir(services.db.url) }); // or memory://
539
551
  await dev.ping(); // pay the ~3s boot before serving
540
552
  setDbClient(dev);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/db",
3
- "version": "31.45.0",
3
+ "version": "31.47.0",
4
4
  "description": "Postgres access, transactions, migrations and drift detection",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -45,7 +45,7 @@
45
45
  "test": "bun test"
46
46
  },
47
47
  "dependencies": {
48
- "@ultimat3/core": "31.45.0"
48
+ "@ultimat3/core": "31.47.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@electric-sql/pglite": ">=0.5.0"
@@ -3,6 +3,7 @@
3
3
  // this package's answer and the reader on disk is `@ultimat3/cli`'s — two owners of that question
4
4
  // is a sidecar one of them accepts and the other cannot use.
5
5
 
6
+ import { isJsonObject } from '@ultimat3/core';
6
7
  import { PARTITION_INTERVALS, type PartitionInterval } from './entity-shape';
7
8
  import type {
8
9
  CheckDescription,
@@ -15,11 +16,6 @@ import type {
15
16
  ViewDescription,
16
17
  } from './introspect';
17
18
 
18
- type Row = Record<string, unknown>;
19
-
20
- const isRow = (value: unknown): value is Row =>
21
- typeof value === 'object' && value !== null && !Array.isArray(value);
22
-
23
19
  const str = (value: unknown): value is string => typeof value === 'string';
24
20
  const bool = (value: unknown): value is boolean => typeof value === 'boolean';
25
21
  const nullableStr = (value: unknown): value is string | null => value === null || str(value);
@@ -38,7 +34,7 @@ const directions = (value: unknown): value is readonly ('asc' | 'desc' | null)[]
38
34
  Array.isArray(value) && value.every(order);
39
35
 
40
36
  function column(value: unknown): ColumnDescription | undefined {
41
- if (!isRow(value)) return undefined;
37
+ if (!isJsonObject(value)) return undefined;
42
38
  const {
43
39
  name,
44
40
  dataType,
@@ -75,14 +71,14 @@ function column(value: unknown): ColumnDescription | undefined {
75
71
 
76
72
  /** The predicate is the snapshot's own spelling, so both halves are plain strings or nothing. */
77
73
  function check(value: unknown): CheckDescription | undefined {
78
- if (!isRow(value)) return undefined;
74
+ if (!isJsonObject(value)) return undefined;
79
75
  const { name, expression } = value;
80
76
  if (!str(name) || !str(expression)) return undefined;
81
77
  return { name, expression };
82
78
  }
83
79
 
84
80
  function index(value: unknown): IndexDescription | undefined {
85
- if (!isRow(value)) return undefined;
81
+ if (!isJsonObject(value)) return undefined;
86
82
  const { name, columns, unique, primary, where, order: direction, using } = value;
87
83
  const { expression, orders, include, operatorClass } = value;
88
84
  if (!str(name) || !strings(columns) || !bool(unique) || !bool(primary)) return undefined;
@@ -119,7 +115,7 @@ function index(value: unknown): IndexDescription | undefined {
119
115
  }
120
116
 
121
117
  function foreignKey(value: unknown): ForeignKeyDescription | undefined {
122
- if (!isRow(value)) return undefined;
118
+ if (!isJsonObject(value)) return undefined;
123
119
  const { name, columns, referencedTable, referencedColumns, onDelete } = value;
124
120
  if (!str(name) || !strings(columns) || !str(referencedTable)) return undefined;
125
121
  if (!strings(referencedColumns) || !nullableStr(onDelete)) return undefined;
@@ -139,7 +135,7 @@ function all<T>(value: unknown, one: (item: unknown) => T | undefined): readonly
139
135
  }
140
136
 
141
137
  function trigger(value: unknown): TriggerRecord | undefined {
142
- if (!isRow(value)) return undefined;
138
+ if (!isJsonObject(value)) return undefined;
143
139
  const { name, install, recount } = value;
144
140
  if (!str(name) || !strings(install)) return undefined;
145
141
  // `recount` arrived in 31.23 on counter triggers; a record written before carries none.
@@ -148,7 +144,7 @@ function trigger(value: unknown): TriggerRecord | undefined {
148
144
  }
149
145
 
150
146
  function tableOf(value: unknown): TableDescription | undefined {
151
- if (!isRow(value)) return undefined;
147
+ if (!isJsonObject(value)) return undefined;
152
148
  const { schema, name, primaryKey } = value;
153
149
  if (!str(schema) || !str(name) || !strings(primaryKey)) return undefined;
154
150
  const columns = all(value['columns'], column);
@@ -209,7 +205,7 @@ function tableOf(value: unknown): TableDescription | undefined {
209
205
  * regenerating it. A file that will not parse is *absent* — which the caller already handles.
210
206
  */
211
207
  export function parseSnapshot(value: unknown): SchemaDescription | undefined {
212
- if (!isRow(value)) return undefined;
208
+ if (!isJsonObject(value)) return undefined;
213
209
  const tables = all(value['tables'], tableOf);
214
210
  if (tables === undefined) return undefined;
215
211
  const recorded = value['views'];
@@ -220,7 +216,7 @@ export function parseSnapshot(value: unknown): SchemaDescription | undefined {
220
216
 
221
217
  /** One recorded view: a name, the flag, the statements — anything else is not a snapshot. */
222
218
  function viewOf(value: unknown): ViewDescription | undefined {
223
- if (!isRow(value)) return undefined;
219
+ if (!isJsonObject(value)) return undefined;
224
220
  const { name, materialized, create } = value;
225
221
  if (typeof name !== 'string') return undefined;
226
222
  if (!(materialized === undefined || materialized === true)) return undefined;