@broberg/db-sdk 0.1.0 → 0.2.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
@@ -1,12 +1,21 @@
1
1
  # @broberg/db-sdk
2
2
 
3
- The WebHouse fleet's shared **database transport** — one thin facade every
4
- project depends on, instead of scattering driver calls across repos. The same
5
- play as [`@broberg/ai-sdk`](https://www.npmjs.com/package/@broberg/ai-sdk), for
6
- the data layer.
3
+ The broberg.ai fleet's shared **database client** — one thin facade over two
4
+ transports:
7
5
 
8
- **Turso/libSQL today; Postgres/Supabase transports planned** behind the same API.
9
- Pilot consumer: **Buddy Cloud** (F067).
6
+ | Transport | For | Env default |
7
+ |---|---|---|
8
+ | `libsql` (default) | Turso / libSQL, local `file:` databases | `TURSO_DATABASE_URL`, `TURSO_AUTH_TOKEN` |
9
+ | `postgres` | PostgreSQL, including Supabase | `DATABASE_URL` |
10
+
11
+ `createClient()` returns the same `DbClient` from both, so switching transport is
12
+ a change at the call to `createClient` — **for the connection.**
13
+
14
+ > **The SQL is not translated.** libSQL takes `?` placeholders, Postgres takes
15
+ > `$1`, and the two dialects differ in DDL, functions and `PRAGMA`. The facade
16
+ > passes your SQL through untouched: rewriting `?` into `$1` would also rewrite a
17
+ > `?` inside a string literal or a JSON operator. Moving an app between
18
+ > transports means moving its SQL too.
10
19
 
11
20
  ## Install
12
21
 
@@ -20,41 +29,150 @@ bun add @broberg/db-sdk
20
29
  ```ts
21
30
  import { createClient, createReplica, health } from '@broberg/db-sdk';
22
31
 
23
- // Remote (cloud hub). Reads TURSO_DATABASE_URL + TURSO_AUTH_TOKEN from env.
32
+ // Turso (reads TURSO_DATABASE_URL + TURSO_AUTH_TOKEN)
33
+ const db = createClient();
34
+
35
+ // Postgres / Supabase (reads DATABASE_URL)
36
+ const pg = createClient({ backend: 'postgres' });
37
+
38
+ await pg.execute({ sql: 'insert into notes (id, body) values ($1, $2)', args: [1, 'hej'] });
39
+ const { rows } = await pg.execute('select id, body from notes');
40
+ // rows: [{ id: 1, body: 'hej' }]
41
+
42
+ // Several statements in ONE transaction — all apply or none do.
43
+ await db.batch([
44
+ { sql: 'delete from s where edge = ?', args: ['m1'] },
45
+ { sql: 'insert into s (edge, name) values (?, ?)', args: ['m1', 'x'] },
46
+ ], 'write');
47
+
48
+ await health(pg); // { ok: true, transport: 'postgres', version: '16.4' }
49
+ ```
50
+
51
+ `health()` reports the transport that **answered** — read it there rather than
52
+ inferring it from your own config.
53
+
54
+ ### The escape hatch
55
+
56
+ `client.raw` is the underlying driver's own client, typed per transport, for
57
+ anything the facade does not cover:
58
+
59
+ ```ts
60
+ const pg = createClient({ backend: 'postgres' });
61
+ await pg.raw.listen('events', (payload) => { /* … */ }); // postgres.js
62
+
24
63
  const db = createClient();
25
- await health(db); // { ok: true, version: "3.45.1" }
64
+ await db.raw.executeMultiple(script); // @libsql/client
65
+ ```
26
66
 
27
- // Embedded replica (edge daemon): a local file synced from the remote primary.
67
+ ### Embedded replicas (libSQL only)
68
+
69
+ A local SQLite file kept in sync with a remote Turso primary. There is no
70
+ Postgres counterpart, and the config type says so — `backend: 'postgres'` on a
71
+ `ReplicaConfig` is a compile error.
72
+
73
+ ```ts
28
74
  const edge = createReplica({ path: '/data/buddy.db', syncIntervalSeconds: 30 });
29
- // reads hit the local file at SQLite speed; writes forward to the primary
30
75
  await edge.sync(); // or rely on the interval
31
76
  ```
32
77
 
33
- **Thin by design.** No ORM coupling — layer Drizzle in the consumer:
78
+ ### Supabase
79
+
80
+ Use the pooler connection string as `DATABASE_URL`. Prepared statements are
81
+ **always off** in the Postgres transport, because of what they do to Supabase's
82
+ transaction-mode pooler (port 6543). Measured 23 Sep 2026 against a real
83
+ Supabase project (eu-north-1), 40 concurrent queries with prepared statements ON:
84
+
85
+ | Route | Result |
86
+ |---|---|
87
+ | transaction pooler, 6543 | **hung** after 5–8 answers — no error, 3 runs of 3 |
88
+ | session pooler | 40/40 |
89
+ | direct, 5432 | 40/40 |
90
+
91
+ It does not fail — it **hangs**, and only under concurrency, so a sequential
92
+ test and a local Postgres both stay green. The contract suite runs 60
93
+ concurrent queries through the real pooler against a 20-second deadline, and
94
+ turning prepared statements back on turns it red with `HUNG`.
95
+
96
+ Keep the service-role connection string on the server. Supabase auth belongs in
97
+ `@broberg/auth`, storage in `@broberg/media`; this package is the SQL connection
98
+ only.
99
+
100
+ ### ORM
101
+
102
+ The ORM stays in the consumer. Drizzle takes the **driver's** client, so hand it
103
+ `raw`:
34
104
 
35
105
  ```ts
36
- import { drizzle } from 'drizzle-orm/libsql';
37
- import { createClient } from '@broberg/db-sdk';
38
- const orm = drizzle(createClient(), { schema });
106
+ import { drizzle } from 'drizzle-orm/postgres-js';
107
+ const orm = drizzle(createClient({ backend: 'postgres' }).raw, { schema });
39
108
  ```
40
109
 
41
110
  ## API
42
111
 
43
- | Export | Signature | What it does |
44
- |---|---|---|
45
- | `createClient` | `(cfg?: DbConfig) => Client` | Remote client. `cfg`: `{ url?, authToken?, backend? }` (env fallback). |
46
- | `createReplica` | `(cfg: ReplicaConfig) => Client` | Embedded replica. `cfg`: `{ path, syncUrl?, authToken?, syncIntervalSeconds?, backend? }`. |
47
- | `health` | `(client) => Promise<{ ok, version }>` | Liveness + SQLite-version probe. |
112
+ | Export | Signature |
113
+ |---|---|
114
+ | `createClient` | `(cfg?: LibsqlConfig) => DbClient<LibsqlClient>` · `(cfg: PostgresConfig) => DbClient<Sql>` |
115
+ | `createReplica` | `(cfg: ReplicaConfig) => ReplicaClient` — libSQL only |
116
+ | `health` | `(client) => Promise<{ ok, transport, version }>` — throws if unreachable |
48
117
 
49
- Re-exports `Client` / `ResultSet` (from `@libsql/client`) and the config types.
118
+ `DbClient`: `transport`, `raw`, `execute(stmt)`, `batch(stmts, mode?)`, `close()`.
119
+ A statement is `string` or `{ sql, args? }`. A result is
120
+ `{ rows, columns, rowsAffected }`, with rows as plain objects keyed by column.
50
121
 
51
- ## Multi-backend roadmap
122
+ **Values are the driver's own — the facade unifies the shape, not the types.**
123
+ Measured on the same query:
124
+
125
+ | SQL value | libsql | postgres |
126
+ |---|---|---|
127
+ | `count(*)`, `bigint` | `number` | **`string`** (`'1'`) |
128
+ | `numeric` / `1.5` literal | `number` | **`string`** (`'1.5'`) |
129
+ | `integer` | `number` | `number` |
130
+ | `timestamptz` | `string` | `Date` |
131
+ | `jsonb` | `string` | parsed object |
132
+
133
+ Postgres returns int8 and numeric as strings because a JS number cannot hold an
134
+ int8 above 2^53, and the facade does not convert them for the same reason —
135
+ a silent precision loss is worse than a visible string. Wrap with `Number(...)`
136
+ where you know the range is safe. The contract suite pins these, so a driver
137
+ changing them turns it red.
138
+
139
+ `batch` modes are `'write'` and `'deferred'`. There is **no `'read'` mode**: a
140
+ libSQL read batch against a local file was measured executing an INSERT that
141
+ Postgres refused, and a read-only promise that holds on one transport only is not
142
+ one the facade can make.
143
+
144
+ ## Migrating from 0.1.x
145
+
146
+ `createClient()` used to return `@libsql/client`'s own `Client`. It now returns
147
+ `DbClient`. What changed for a caller:
148
+
149
+ - `execute(string | { sql, args })` and `batch(stmts, 'write')` — **unchanged**.
150
+ - `rows[i]['column']` — unchanged. Positional access `rows[i][0]` is gone: rows
151
+ are plain objects now.
152
+ - `lastInsertRowid` — gone from the facade (it is a SQLite concept). Use
153
+ `client.raw.execute(...)`, or `returning id`.
154
+ - Anything else on the libSQL client (`executeMultiple`, `transaction`, `sync`):
155
+ reach it via `client.raw`.
156
+ - **Drizzle:** `drizzle(createClient(), { schema })` — the pattern this README
157
+ used to show — no longer works, because drizzle wants the driver's client.
158
+ Write `drizzle(createClient().raw, { schema })`. Measured working for both
159
+ transports (`drizzle-orm/libsql` and `drizzle-orm/postgres-js`).
160
+ - `type Client` still exists as a deprecated alias of `DbClient`.
161
+
162
+ buddy (`apps/server`), the one known 0.1.x consumer, typechecks and passes its own
163
+ db-sdk test against this version with no source changes.
164
+
165
+ ## Tests
166
+
167
+ ```bash
168
+ DB_SDK_TEST_PG_URL=postgres://… bun test
169
+ ```
52
170
 
53
- `backend` defaults to `'libsql'` (Turso) — the only transport implemented today.
54
- `postgres` / `supabase` are the planned extension points: a new transport lands
55
- under `src/backends/` and widens the `Backend` union, **without changing the
56
- public `createClient` / `createReplica` surface**. The domain layer (ORM, schema,
57
- tenant-scoping) stays in each consumer.
171
+ One contract suite runs the **same** cases against libSQL (a local file), a
172
+ **real** Postgres, and — when `DB_SDK_TEST_PG_POOLER_URL` is set — a real
173
+ Supabase transaction pooler. Without `DB_SDK_TEST_PG_URL` the suite fails rather than
174
+ skipping Postgres — a skipped transport reads as a green one. CI provides a
175
+ Postgres service container.
58
176
 
59
177
  ## License
60
178
 
package/dist/index.d.ts CHANGED
@@ -1,68 +1,142 @@
1
- import { Client } from '@libsql/client';
2
- export { Client, ResultSet } from '@libsql/client';
1
+ import { Client as Client$1 } from '@libsql/client';
2
+ export { Client as LibsqlClient } from '@libsql/client';
3
+ import { Sql } from 'postgres';
4
+ export { Sql } from 'postgres';
3
5
 
4
6
  /** Shared types for @broberg/db-sdk. */
5
7
 
8
+ /** Which database transport backs a client. */
9
+ type Transport = 'libsql' | 'postgres';
10
+ /** One row, keyed by column name. Duplicate column names: the last one wins. */
11
+ type Row = Record<string, unknown>;
12
+ /** The result of one statement — the same shape from every transport. */
13
+ interface DbResult {
14
+ rows: Row[];
15
+ columns: string[];
16
+ /** Rows written by INSERT/UPDATE/DELETE. 0 for reads and DDL. */
17
+ rowsAffected: number;
18
+ }
19
+ /**
20
+ * A statement: bare SQL, or SQL plus positional args.
21
+ *
22
+ * THE SQL IS PASSED THROUGH UNTOUCHED — the facade unifies the transport, not
23
+ * the dialect. libSQL takes `?` placeholders, Postgres takes `$1`. Rewriting one
24
+ * into the other would also rewrite a `?` inside a string literal or a JSON
25
+ * operator, so we do not.
26
+ */
27
+ type Statement = string | {
28
+ sql: string;
29
+ args?: readonly unknown[];
30
+ };
6
31
  /**
7
- * Which database transport backs the client. `libsql` (Turso) is the only
8
- * backend implemented today; `postgres` / `supabase` are the planned extension
9
- * points — adding one widens this union WITHOUT changing the public API.
32
+ * How the batch's transaction begins. `write` takes the write lock up front;
33
+ * `deferred` takes it at the first write.
34
+ *
35
+ * There is NO `read` mode, on purpose. Measured 23/9 2026 by the contract suite:
36
+ * a libSQL `read` batch against a local file executed an INSERT, while Postgres
37
+ * refused it. A mode that is read-only on one transport and not the other is a
38
+ * promise the facade cannot keep.
10
39
  */
11
- type Backend = 'libsql';
12
- /** Connection config for a remote database. Falls back to env. */
13
- interface DbConfig {
40
+ type BatchMode = 'write' | 'deferred';
41
+ /**
42
+ * The one client surface every transport answers. `Raw` is the escape hatch:
43
+ * the underlying driver's own client, for what the facade does not cover
44
+ * (`LISTEN/NOTIFY`, libSQL `sync()`, streaming). Without it a consumer who needs
45
+ * one transport-specific call would route around the whole facade.
46
+ */
47
+ interface DbClient<Raw = unknown> {
48
+ /** The transport that answers — read it here, not from your own config. */
49
+ readonly transport: Transport;
50
+ /** The underlying driver client. */
51
+ readonly raw: Raw;
52
+ execute(stmt: Statement): Promise<DbResult>;
53
+ /** All statements in ONE transaction: all apply or none do. */
54
+ batch(stmts: readonly Statement[], mode?: BatchMode): Promise<DbResult[]>;
55
+ close(): Promise<void>;
56
+ }
57
+ /**
58
+ * The 0.1.x name for the client type. It is now the facade, not
59
+ * `@libsql/client`'s own `Client` — use `DbClient`.
60
+ * @deprecated since 0.2.0
61
+ */
62
+ type Client = DbClient;
63
+ /** Remote libSQL / Turso. */
64
+ interface LibsqlConfig {
65
+ backend?: 'libsql';
14
66
  /** `libsql://…` (remote) or `file:…` (local). Default: `$TURSO_DATABASE_URL`. */
15
67
  url?: string;
16
- /** Auth token. Default: `$TURSO_AUTH_TOKEN`. */
68
+ /** Default: `$TURSO_AUTH_TOKEN`. */
17
69
  authToken?: string;
18
- /** Transport backend. Default `libsql`. */
19
- backend?: Backend;
20
70
  }
21
- /** Embedded-replica config: a local file kept in sync with a remote primary. */
71
+ /** PostgreSQL, including Supabase. */
72
+ interface PostgresConfig {
73
+ backend: 'postgres';
74
+ /** `postgres://…`. Default: `$DATABASE_URL`. */
75
+ url?: string;
76
+ /** Max pooled connections. Default: the driver's (10). */
77
+ max?: number;
78
+ }
79
+ type DbConfig = LibsqlConfig | PostgresConfig;
80
+ /**
81
+ * Embedded-replica config. An embedded replica is a libSQL concept with no
82
+ * Postgres counterpart, so `backend` only accepts `'libsql'` — asking for a
83
+ * Postgres replica is a type error, not a runtime throw.
84
+ */
22
85
  interface ReplicaConfig {
86
+ backend?: 'libsql';
23
87
  /** Local file path for the replica DB (e.g. `/data/buddy.db`). */
24
88
  path: string;
25
89
  /** Remote primary to sync from. Default: `$TURSO_DATABASE_URL`. */
26
90
  syncUrl?: string;
27
- /** Auth token for the remote. Default: `$TURSO_AUTH_TOKEN`. */
91
+ /** Default: `$TURSO_AUTH_TOKEN`. */
28
92
  authToken?: string;
29
- /** Auto-sync interval in seconds. Omit to sync manually via `client.sync()`. */
93
+ /** Auto-sync interval in seconds. Omit to sync manually via `sync()`. */
30
94
  syncIntervalSeconds?: number;
31
- /** Transport backend. Default `libsql` (embedded replicas are libSQL-specific). */
32
- backend?: Backend;
95
+ }
96
+ /** A replica client: the facade plus `sync()`, which pulls from the primary. */
97
+ interface ReplicaClient extends DbClient<Client$1> {
98
+ sync(): Promise<void>;
99
+ }
100
+ /** What `health()` measured. `transport` is who ANSWERED, not who was configured. */
101
+ interface Health {
102
+ ok: true;
103
+ transport: Transport;
104
+ version: string;
33
105
  }
34
106
 
35
107
  /**
36
- * @broberg/db-sdk — the WebHouse fleet's shared database client.
108
+ * @broberg/db-sdk — the broberg.ai fleet's shared database client.
37
109
  *
38
- * One thin facade, every project: instead of scattering driver calls in each
39
- * repo, projects depend on this package and gain a single place to evolve
40
- * transports, limits and observability — the same play as `@broberg/ai-sdk`.
110
+ * One facade over two transports: libSQL/Turso and PostgreSQL (Supabase
111
+ * included). `createClient` returns the same `DbClient` from both, so switching
112
+ * transport is a config change at the call to `createClient` — for the
113
+ * CONNECTION. The SQL itself is passed through untouched: libSQL takes `?`,
114
+ * Postgres takes `$1`, and the facade does not translate between them.
41
115
  *
42
- * Turso/libSQL is the only transport implemented today (Buddy Cloud, F067, is
43
- * the pilot consumer); `postgres` / `supabase` are planned behind the same
44
- * `createClient` / `createReplica` surface (see `Backend`). Intentionally THIN:
45
- * a remote client, an embedded-replica client, and a health probe. ORM stays in
46
- * the consumer (`drizzle(createClient(), { schema })`).
116
+ * Intentionally THIN: a client, an embedded-replica client (libSQL only), and a
117
+ * health probe. ORM, schema and migrations stay in the consumer.
47
118
  */
48
119
 
49
120
  /**
50
- * Create a client against a REMOTE database. With no args it reads
51
- * `TURSO_DATABASE_URL` + `TURSO_AUTH_TOKEN` from the env. Backend defaults to
52
- * `libsql` (Turso).
121
+ * Create a client against a REMOTE database.
122
+ *
123
+ * - libSQL/Turso (default): reads `TURSO_DATABASE_URL` + `TURSO_AUTH_TOKEN`.
124
+ * - `{ backend: 'postgres' }`: reads `DATABASE_URL`.
53
125
  */
54
- declare function createClient(cfg?: DbConfig): Client;
126
+ declare function createClient(cfg?: LibsqlConfig): DbClient<Client$1>;
127
+ declare function createClient(cfg: PostgresConfig): DbClient<Sql>;
55
128
  /**
56
- * Create an EMBEDDED REPLICA: a local SQLite file kept in sync with the remote
57
- * Turso primary. Reads hit the local file at SQLite speed; writes forward to the
58
- * primary; `client.sync()` (or `syncIntervalSeconds`) pulls the latest. This is
59
- * how F067 edge daemons read fleet state fast and tolerate a cloud blip.
129
+ * Create an EMBEDDED REPLICA: a local SQLite file kept in sync with a remote
130
+ * Turso primary. Reads hit the local file; writes forward to the primary;
131
+ * `sync()` (or `syncIntervalSeconds`) pulls the latest. libSQL only — there is
132
+ * no Postgres counterpart, and the config type says so.
60
133
  */
61
- declare function createReplica(cfg: ReplicaConfig): Client;
62
- /** Liveness + SQLite version probe — handy for health endpoints. */
63
- declare function health(client: Client): Promise<{
64
- ok: boolean;
65
- version: string;
66
- }>;
134
+ declare function createReplica(cfg: ReplicaConfig): ReplicaClient;
135
+ /**
136
+ * Liveness + version probe. Asks the transport itself and reports which one
137
+ * answered — read `transport` here rather than inferring it from your config.
138
+ * Throws if the database cannot be reached.
139
+ */
140
+ declare function health(client: DbClient): Promise<Health>;
67
141
 
68
- export { type Backend, type DbConfig, type ReplicaConfig, createClient, createReplica, health };
142
+ export { type BatchMode, type Client, type DbClient, type DbConfig, type DbResult, type Health, type LibsqlConfig, type PostgresConfig, type ReplicaClient, type ReplicaConfig, type Row, type Statement, type Transport, createClient, createReplica, health };
package/dist/index.js CHANGED
@@ -2,48 +2,135 @@
2
2
  import { createClient as createLibsqlClient } from "@libsql/client";
3
3
  function requireUrl(url, what) {
4
4
  if (!url) {
5
- throw new Error(
6
- `@broberg/db-sdk: missing ${what} \u2014 set TURSO_DATABASE_URL or pass it explicitly`
7
- );
5
+ throw new Error(`@broberg/db-sdk: missing ${what} \u2014 set TURSO_DATABASE_URL or pass it explicitly`);
8
6
  }
9
7
  return url;
10
8
  }
9
+ function toLibsql(stmt) {
10
+ if (typeof stmt === "string") return stmt;
11
+ return { sql: stmt.sql, args: stmt.args ?? [] };
12
+ }
13
+ function toResult(rs) {
14
+ const rows = rs.rows.map((r) => {
15
+ const row = {};
16
+ rs.columns.forEach((c, i) => {
17
+ row[c] = r[i];
18
+ });
19
+ return row;
20
+ });
21
+ return { rows, columns: [...rs.columns], rowsAffected: rs.rowsAffected };
22
+ }
23
+ function wrap(raw) {
24
+ return {
25
+ transport: "libsql",
26
+ raw,
27
+ async execute(stmt) {
28
+ return toResult(await raw.execute(toLibsql(stmt)));
29
+ },
30
+ async batch(stmts, mode = "deferred") {
31
+ const results = await raw.batch(stmts.map(toLibsql), mode);
32
+ return results.map(toResult);
33
+ },
34
+ async close() {
35
+ raw.close();
36
+ }
37
+ };
38
+ }
11
39
  function libsqlClient(cfg) {
12
40
  const url = requireUrl(cfg.url ?? process.env.TURSO_DATABASE_URL, "database url");
13
41
  const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;
14
- return createLibsqlClient({ url, authToken });
42
+ return wrap(createLibsqlClient({ url, authToken }));
15
43
  }
16
44
  function libsqlReplica(cfg) {
17
45
  const syncUrl = requireUrl(cfg.syncUrl ?? process.env.TURSO_DATABASE_URL, "sync url");
18
46
  const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;
19
- return createLibsqlClient({
47
+ const raw = createLibsqlClient({
20
48
  url: `file:${cfg.path}`,
21
49
  syncUrl,
22
50
  authToken,
23
51
  syncInterval: cfg.syncIntervalSeconds
24
52
  });
53
+ return {
54
+ ...wrap(raw),
55
+ async sync() {
56
+ await raw.sync();
57
+ }
58
+ };
59
+ }
60
+ async function libsqlVersion(raw) {
61
+ const res = await raw.execute("select sqlite_version() as v");
62
+ return String(res.rows[0]?.v ?? "unknown");
25
63
  }
26
64
 
27
- // src/index.ts
28
- function unsupported(backend) {
29
- return new Error(
30
- `@broberg/db-sdk: backend '${backend}' is not implemented yet \u2014 only 'libsql' (Turso) is available. Add it under src/backends/ and widen the Backend type; the public API stays the same.`
31
- );
65
+ // src/backends/postgres.ts
66
+ import postgres from "postgres";
67
+ var PG_OPTIONS = { prepare: false };
68
+ function toResult2(res) {
69
+ const columns = (res.columns ?? []).map((c) => c.name);
70
+ const rows = Array.from(res, (r) => ({ ...r }));
71
+ const isRead = res.command === "SELECT";
72
+ return { rows, columns, rowsAffected: isRead ? 0 : res.count ?? 0 };
73
+ }
74
+ function parts(stmt) {
75
+ if (typeof stmt === "string") return [stmt, []];
76
+ return [stmt.sql, [...stmt.args ?? []]];
77
+ }
78
+ function run(sql, stmt) {
79
+ const [text, args] = parts(stmt);
80
+ return sql.unsafe(text, args, PG_OPTIONS);
32
81
  }
82
+ function postgresClient(cfg) {
83
+ const url = cfg.url ?? process.env.DATABASE_URL;
84
+ if (!url) {
85
+ throw new Error("@broberg/db-sdk: missing database url \u2014 set DATABASE_URL or pass it explicitly");
86
+ }
87
+ const raw = postgres(url, { ...PG_OPTIONS, max: cfg.max, onnotice: () => {
88
+ } });
89
+ return {
90
+ transport: "postgres",
91
+ raw,
92
+ async execute(stmt) {
93
+ return toResult2(await run(raw, stmt));
94
+ },
95
+ // Postgres has no write-lock-up-front mode, so both BatchModes begin a
96
+ // plain transaction and the mode argument is not read.
97
+ async batch(stmts) {
98
+ const results = await raw.begin(async (tx) => {
99
+ const out = [];
100
+ for (const s of stmts) out.push(toResult2(await run(tx, s)));
101
+ return out;
102
+ });
103
+ return results;
104
+ },
105
+ async close() {
106
+ await raw.end();
107
+ }
108
+ };
109
+ }
110
+ async function postgresVersion(raw) {
111
+ const [row] = await raw.unsafe("show server_version", [], PG_OPTIONS);
112
+ return String(row?.server_version ?? "unknown");
113
+ }
114
+
115
+ // src/index.ts
33
116
  function createClient(cfg = {}) {
34
117
  const backend = cfg.backend ?? "libsql";
35
- if (backend === "libsql") return libsqlClient(cfg);
36
- throw unsupported(backend);
118
+ if (cfg.backend === "postgres") return postgresClient(cfg);
119
+ if (cfg.backend === void 0 || cfg.backend === "libsql") return libsqlClient(cfg);
120
+ throw new Error(`@broberg/db-sdk: unknown backend '${backend}' \u2014 expected 'libsql' or 'postgres'`);
37
121
  }
38
122
  function createReplica(cfg) {
39
123
  const backend = cfg.backend ?? "libsql";
40
- if (backend === "libsql") return libsqlReplica(cfg);
41
- throw unsupported(backend);
124
+ if (backend !== "libsql") {
125
+ throw new Error(`@broberg/db-sdk: embedded replicas are libSQL-only, got backend '${backend}'`);
126
+ }
127
+ return libsqlReplica(cfg);
42
128
  }
43
129
  async function health(client) {
44
- const res = await client.execute("select sqlite_version() as v");
45
- const version = String(res.rows[0]?.v ?? "unknown");
46
- return { ok: true, version };
130
+ if (client.transport === "postgres") {
131
+ return { ok: true, transport: "postgres", version: await postgresVersion(client.raw) };
132
+ }
133
+ return { ok: true, transport: "libsql", version: await libsqlVersion(client.raw) };
47
134
  }
48
135
  export {
49
136
  createClient,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/backends/libsql.ts","../src/index.ts"],"sourcesContent":["/** libSQL / Turso backend for @broberg/db-sdk. */\nimport { createClient as createLibsqlClient } from '@libsql/client';\nimport type { Client } from '@libsql/client';\nimport type { DbConfig, ReplicaConfig } from '../types';\n\nfunction requireUrl(url: string | undefined, what: string): string {\n if (!url) {\n throw new Error(\n `@broberg/db-sdk: missing ${what} — set TURSO_DATABASE_URL or pass it explicitly`,\n );\n }\n return url;\n}\n\n/** Remote libSQL/Turso client. */\nexport function libsqlClient(cfg: DbConfig): Client {\n const url = requireUrl(cfg.url ?? process.env.TURSO_DATABASE_URL, 'database url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n return createLibsqlClient({ url, authToken });\n}\n\n/** Embedded replica: a local SQLite file kept in sync with the remote primary. */\nexport function libsqlReplica(cfg: ReplicaConfig): Client {\n const syncUrl = requireUrl(cfg.syncUrl ?? process.env.TURSO_DATABASE_URL, 'sync url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n return createLibsqlClient({\n url: `file:${cfg.path}`,\n syncUrl,\n authToken,\n syncInterval: cfg.syncIntervalSeconds,\n });\n}\n","/**\n * @broberg/db-sdk — the WebHouse fleet's shared database client.\n *\n * One thin facade, every project: instead of scattering driver calls in each\n * repo, projects depend on this package and gain a single place to evolve\n * transports, limits and observability — the same play as `@broberg/ai-sdk`.\n *\n * Turso/libSQL is the only transport implemented today (Buddy Cloud, F067, is\n * the pilot consumer); `postgres` / `supabase` are planned behind the same\n * `createClient` / `createReplica` surface (see `Backend`). Intentionally THIN:\n * a remote client, an embedded-replica client, and a health probe. ORM stays in\n * the consumer (`drizzle(createClient(), { schema })`).\n */\nimport type { Client, DbConfig, ReplicaConfig } from './types';\nimport { libsqlClient, libsqlReplica } from './backends/libsql';\n\nexport type { Client, ResultSet, DbConfig, ReplicaConfig, Backend } from './types';\n\nfunction unsupported(backend: string): Error {\n return new Error(\n `@broberg/db-sdk: backend '${backend}' is not implemented yet — only 'libsql' (Turso) ` +\n `is available. Add it under src/backends/ and widen the Backend type; the public ` +\n `API stays the same.`,\n );\n}\n\n/**\n * Create a client against a REMOTE database. With no args it reads\n * `TURSO_DATABASE_URL` + `TURSO_AUTH_TOKEN` from the env. Backend defaults to\n * `libsql` (Turso).\n */\nexport function createClient(cfg: DbConfig = {}): Client {\n const backend: string = cfg.backend ?? 'libsql';\n if (backend === 'libsql') return libsqlClient(cfg);\n throw unsupported(backend);\n}\n\n/**\n * Create an EMBEDDED REPLICA: a local SQLite file kept in sync with the remote\n * Turso primary. Reads hit the local file at SQLite speed; writes forward to the\n * primary; `client.sync()` (or `syncIntervalSeconds`) pulls the latest. This is\n * how F067 edge daemons read fleet state fast and tolerate a cloud blip.\n */\nexport function createReplica(cfg: ReplicaConfig): Client {\n const backend: string = cfg.backend ?? 'libsql';\n if (backend === 'libsql') return libsqlReplica(cfg);\n throw unsupported(backend);\n}\n\n/** Liveness + SQLite version probe — handy for health endpoints. */\nexport async function health(client: Client): Promise<{ ok: boolean; version: string }> {\n const res = await client.execute('select sqlite_version() as v');\n const version = String(res.rows[0]?.v ?? 'unknown');\n return { ok: true, version };\n}\n"],"mappings":";AACA,SAAS,gBAAgB,0BAA0B;AAInD,SAAS,WAAW,KAAyB,MAAsB;AACjE,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR,4BAA4B,IAAI;AAAA,IAClC;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,aAAa,KAAuB;AAClD,QAAM,MAAM,WAAW,IAAI,OAAO,QAAQ,IAAI,oBAAoB,cAAc;AAChF,QAAM,YAAY,IAAI,aAAa,QAAQ,IAAI;AAC/C,SAAO,mBAAmB,EAAE,KAAK,UAAU,CAAC;AAC9C;AAGO,SAAS,cAAc,KAA4B;AACxD,QAAM,UAAU,WAAW,IAAI,WAAW,QAAQ,IAAI,oBAAoB,UAAU;AACpF,QAAM,YAAY,IAAI,aAAa,QAAQ,IAAI;AAC/C,SAAO,mBAAmB;AAAA,IACxB,KAAK,QAAQ,IAAI,IAAI;AAAA,IACrB;AAAA,IACA;AAAA,IACA,cAAc,IAAI;AAAA,EACpB,CAAC;AACH;;;ACbA,SAAS,YAAY,SAAwB;AAC3C,SAAO,IAAI;AAAA,IACT,6BAA6B,OAAO;AAAA,EAGtC;AACF;AAOO,SAAS,aAAa,MAAgB,CAAC,GAAW;AACvD,QAAM,UAAkB,IAAI,WAAW;AACvC,MAAI,YAAY,SAAU,QAAO,aAAa,GAAG;AACjD,QAAM,YAAY,OAAO;AAC3B;AAQO,SAAS,cAAc,KAA4B;AACxD,QAAM,UAAkB,IAAI,WAAW;AACvC,MAAI,YAAY,SAAU,QAAO,cAAc,GAAG;AAClD,QAAM,YAAY,OAAO;AAC3B;AAGA,eAAsB,OAAO,QAA2D;AACtF,QAAM,MAAM,MAAM,OAAO,QAAQ,8BAA8B;AAC/D,QAAM,UAAU,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS;AAClD,SAAO,EAAE,IAAI,MAAM,QAAQ;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/backends/libsql.ts","../src/backends/postgres.ts","../src/index.ts"],"sourcesContent":["/** libSQL / Turso transport for @broberg/db-sdk. */\nimport { createClient as createLibsqlClient } from '@libsql/client';\nimport type { Client as LibsqlClient, InStatement, InValue, ResultSet } from '@libsql/client';\nimport type { BatchMode, DbClient, DbResult, LibsqlConfig, ReplicaClient, ReplicaConfig, Row, Statement } from '../types';\n\nfunction requireUrl(url: string | undefined, what: string): string {\n if (!url) {\n throw new Error(`@broberg/db-sdk: missing ${what} — set TURSO_DATABASE_URL or pass it explicitly`);\n }\n return url;\n}\n\nfunction toLibsql(stmt: Statement): InStatement {\n if (typeof stmt === 'string') return stmt;\n return { sql: stmt.sql, args: (stmt.args ?? []) as InValue[] };\n}\n\n/** libSQL rows are array-like objects; the facade hands out plain objects. */\nfunction toResult(rs: ResultSet): DbResult {\n const rows: Row[] = rs.rows.map((r) => {\n const row: Row = {};\n rs.columns.forEach((c, i) => {\n row[c] = r[i];\n });\n return row;\n });\n return { rows, columns: [...rs.columns], rowsAffected: rs.rowsAffected };\n}\n\nfunction wrap(raw: LibsqlClient): DbClient<LibsqlClient> {\n return {\n transport: 'libsql',\n raw,\n async execute(stmt) {\n return toResult(await raw.execute(toLibsql(stmt)));\n },\n async batch(stmts, mode: BatchMode = 'deferred') {\n const results = await raw.batch(stmts.map(toLibsql), mode);\n return results.map(toResult);\n },\n async close() {\n raw.close();\n },\n };\n}\n\n/** Remote libSQL/Turso client. */\nexport function libsqlClient(cfg: LibsqlConfig): DbClient<LibsqlClient> {\n const url = requireUrl(cfg.url ?? process.env.TURSO_DATABASE_URL, 'database url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n return wrap(createLibsqlClient({ url, authToken }));\n}\n\n/** Embedded replica: a local SQLite file kept in sync with the remote primary. */\nexport function libsqlReplica(cfg: ReplicaConfig): ReplicaClient {\n const syncUrl = requireUrl(cfg.syncUrl ?? process.env.TURSO_DATABASE_URL, 'sync url');\n const authToken = cfg.authToken ?? process.env.TURSO_AUTH_TOKEN;\n const raw = createLibsqlClient({\n url: `file:${cfg.path}`,\n syncUrl,\n authToken,\n syncInterval: cfg.syncIntervalSeconds,\n });\n return {\n ...wrap(raw),\n async sync() {\n await raw.sync();\n },\n };\n}\n\nexport async function libsqlVersion(raw: LibsqlClient): Promise<string> {\n const res = await raw.execute('select sqlite_version() as v');\n return String(res.rows[0]?.v ?? 'unknown');\n}\n","/** PostgreSQL transport for @broberg/db-sdk — Supabase included. */\nimport postgres from 'postgres';\nimport type { Sql, TransactionSql } from 'postgres';\nimport type { DbClient, DbResult, PostgresConfig, Row, Statement } from '../types';\n\n/**\n * Prepared statements are OFF, deliberately, and a test fails if they come back.\n *\n * Supabase's connection pooler in transaction mode (port 6543) hands each\n * transaction to whichever server connection is free, so a statement prepared\n * on one is missing on the next. postgres.js prepares by default. With it on,\n * everything passes against a local Postgres and fails against Supabase —\n * green until production.\n */\nexport const PG_OPTIONS = { prepare: false } as const;\n\ntype PgResult = Awaited<ReturnType<Sql['unsafe']>>;\n\nfunction toResult(res: PgResult): DbResult {\n const columns = (res.columns ?? []).map((c) => c.name);\n const rows = Array.from(res, (r) => ({ ...(r as Row) }));\n // count is the command's row count; for a SELECT that is rows returned, which\n // the facade does not call \"affected\".\n const isRead = res.command === 'SELECT';\n return { rows, columns, rowsAffected: isRead ? 0 : (res.count ?? 0) };\n}\n\nfunction parts(stmt: Statement): [string, unknown[]] {\n if (typeof stmt === 'string') return [stmt, []];\n return [stmt.sql, [...(stmt.args ?? [])]];\n}\n\nfunction run(sql: Sql | TransactionSql, stmt: Statement): Promise<PgResult> {\n const [text, args] = parts(stmt);\n return sql.unsafe(text, args as never[], PG_OPTIONS);\n}\n\nexport function postgresClient(cfg: PostgresConfig): DbClient<Sql> {\n const url = cfg.url ?? process.env.DATABASE_URL;\n if (!url) {\n throw new Error('@broberg/db-sdk: missing database url — set DATABASE_URL or pass it explicitly');\n }\n const raw = postgres(url, { ...PG_OPTIONS, max: cfg.max, onnotice: () => {} });\n return {\n transport: 'postgres',\n raw,\n async execute(stmt) {\n return toResult(await run(raw, stmt));\n },\n // Postgres has no write-lock-up-front mode, so both BatchModes begin a\n // plain transaction and the mode argument is not read.\n async batch(stmts) {\n const results = await raw.begin(async (tx) => {\n const out: DbResult[] = [];\n for (const s of stmts) out.push(toResult(await run(tx, s)));\n return out;\n });\n return results as DbResult[];\n },\n async close() {\n await raw.end();\n },\n };\n}\n\nexport async function postgresVersion(raw: Sql): Promise<string> {\n const [row] = await raw.unsafe('show server_version', [], PG_OPTIONS);\n return String((row as Row | undefined)?.server_version ?? 'unknown');\n}\n","/**\n * @broberg/db-sdk — the broberg.ai fleet's shared database client.\n *\n * One facade over two transports: libSQL/Turso and PostgreSQL (Supabase\n * included). `createClient` returns the same `DbClient` from both, so switching\n * transport is a config change at the call to `createClient` — for the\n * CONNECTION. The SQL itself is passed through untouched: libSQL takes `?`,\n * Postgres takes `$1`, and the facade does not translate between them.\n *\n * Intentionally THIN: a client, an embedded-replica client (libSQL only), and a\n * health probe. ORM, schema and migrations stay in the consumer.\n */\nimport type { LibsqlClient, Sql } from './types';\nimport type { DbClient, Health, LibsqlConfig, PostgresConfig, ReplicaClient, ReplicaConfig } from './types';\nimport { libsqlClient, libsqlReplica, libsqlVersion } from './backends/libsql';\nimport { postgresClient, postgresVersion } from './backends/postgres';\n\nexport type {\n BatchMode,\n Client,\n DbClient,\n DbConfig,\n DbResult,\n Health,\n LibsqlClient,\n LibsqlConfig,\n PostgresConfig,\n ReplicaClient,\n ReplicaConfig,\n Row,\n Sql,\n Statement,\n Transport,\n} from './types';\n\n/**\n * Create a client against a REMOTE database.\n *\n * - libSQL/Turso (default): reads `TURSO_DATABASE_URL` + `TURSO_AUTH_TOKEN`.\n * - `{ backend: 'postgres' }`: reads `DATABASE_URL`.\n */\nexport function createClient(cfg?: LibsqlConfig): DbClient<LibsqlClient>;\nexport function createClient(cfg: PostgresConfig): DbClient<Sql>;\nexport function createClient(cfg: LibsqlConfig | PostgresConfig = {}): DbClient<LibsqlClient> | DbClient<Sql> {\n const backend: string = cfg.backend ?? 'libsql';\n if (cfg.backend === 'postgres') return postgresClient(cfg);\n if (cfg.backend === undefined || cfg.backend === 'libsql') return libsqlClient(cfg);\n throw new Error(`@broberg/db-sdk: unknown backend '${backend}' — expected 'libsql' or 'postgres'`);\n}\n\n/**\n * Create an EMBEDDED REPLICA: a local SQLite file kept in sync with a remote\n * Turso primary. Reads hit the local file; writes forward to the primary;\n * `sync()` (or `syncIntervalSeconds`) pulls the latest. libSQL only — there is\n * no Postgres counterpart, and the config type says so.\n */\nexport function createReplica(cfg: ReplicaConfig): ReplicaClient {\n const backend: string = cfg.backend ?? 'libsql';\n if (backend !== 'libsql') {\n throw new Error(`@broberg/db-sdk: embedded replicas are libSQL-only, got backend '${backend}'`);\n }\n return libsqlReplica(cfg);\n}\n\n/**\n * Liveness + version probe. Asks the transport itself and reports which one\n * answered — read `transport` here rather than inferring it from your config.\n * Throws if the database cannot be reached.\n */\nexport async function health(client: DbClient): Promise<Health> {\n if (client.transport === 'postgres') {\n return { ok: true, transport: 'postgres', version: await postgresVersion(client.raw as Sql) };\n }\n return { ok: true, transport: 'libsql', version: await libsqlVersion(client.raw as LibsqlClient) };\n}\n"],"mappings":"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","names":["toResult"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@broberg/db-sdk",
3
- "version": "0.1.0",
4
- "description": "Thin shared database client for the WebHouse fleet — one DB SDK, every project. Turso/libSQL today; Postgres/Supabase transports later. Pilot: Buddy Cloud (F067).",
3
+ "version": "0.2.0",
4
+ "description": "Thin shared database client for the broberg.ai fleet — one DbClient facade over libSQL/Turso and PostgreSQL/Supabase. The SQL dialect is passed through, not translated.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-Apache-2.0",
7
7
  "author": "Christian Broberg <cb@webhouse.dk>",
@@ -10,8 +10,7 @@
10
10
  "url": "git+https://github.com/broberg-ai/db-sdk.git"
11
11
  },
12
12
  "publishConfig": {
13
- "access": "public",
14
- "provenance": true
13
+ "access": "public"
15
14
  },
16
15
  "files": [
17
16
  "dist"
@@ -32,7 +31,8 @@
32
31
  "clean": "rm -rf dist .turbo"
33
32
  },
34
33
  "dependencies": {
35
- "@libsql/client": "^0.17.3"
34
+ "@libsql/client": "^0.17.3",
35
+ "postgres": "^3.4.9"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/bun": "^1.1.0",