@happyvertical/sql 0.102.2 → 0.102.3

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.
Files changed (30) hide show
  1. package/AGENT.md +1 -1
  2. package/README.md +99 -4
  3. package/dist/chunks/{duckdb-DfikVgov.js → duckdb-LMyfKZGi.js} +3 -3
  4. package/dist/chunks/{duckdb-DfikVgov.js.map → duckdb-LMyfKZGi.js.map} +1 -1
  5. package/dist/chunks/postgres-dialect-Bfswr4Vs.js +2728 -0
  6. package/dist/chunks/postgres-dialect-Bfswr4Vs.js.map +1 -0
  7. package/dist/chunks/{sqlite-Cz2NMiDs.js → sqlite-0PMv1va2.js} +5 -5
  8. package/dist/chunks/{sqlite-Cz2NMiDs.js.map → sqlite-0PMv1va2.js.map} +1 -1
  9. package/dist/chunks/{sqlite-connection-cache-BAakj2HO.js → sqlite-connection-cache-ChWav9iY.js} +2 -2
  10. package/dist/chunks/{sqlite-connection-cache-BAakj2HO.js.map → sqlite-connection-cache-ChWav9iY.js.map} +1 -1
  11. package/dist/chunks/{sqlite-native-ByGwGEbS.js → sqlite-native--z4BnolL.js} +4 -4
  12. package/dist/chunks/{sqlite-native-ByGwGEbS.js.map → sqlite-native--z4BnolL.js.map} +1 -1
  13. package/dist/index.d.ts +5 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +163 -1365
  16. package/dist/index.js.map +1 -1
  17. package/dist/pglite.d.ts +150 -0
  18. package/dist/pglite.d.ts.map +1 -0
  19. package/dist/pglite.js +339 -0
  20. package/dist/pglite.js.map +1 -0
  21. package/dist/postgres.d.ts.map +1 -1
  22. package/dist/shared/postgres-dialect.d.ts +153 -0
  23. package/dist/shared/postgres-dialect.d.ts.map +1 -0
  24. package/dist/shared/types.d.ts +4 -4
  25. package/metadata.json +1 -0
  26. package/package.json +13 -2
  27. package/dist/chunks/connection-cache-Da5UcY5u.js +0 -1305
  28. package/dist/chunks/connection-cache-Da5UcY5u.js.map +0 -1
  29. package/dist/chunks/types-CwWJ-yju.js +0 -139
  30. package/dist/chunks/types-CwWJ-yju.js.map +0 -1
@@ -0,0 +1,150 @@
1
+ /**
2
+ * PGlite adapter: real PostgreSQL compiled to WebAssembly, in the browser and
3
+ * in Node.
4
+ *
5
+ * `@electric-sql/pglite` is an optional peer dependency, imported only when
6
+ * this adapter creates a database. The module's import graph is browser-safe —
7
+ * no `node:` built-ins and no `pg` — so it can be bundled for a page. Import it
8
+ * from `@happyvertical/sql/pglite` there; the package root also reaches
9
+ * Node-only adapters.
10
+ *
11
+ * It speaks the same Postgres dialect as the `pg` adapter (native UUID ids and
12
+ * foreign keys, BIGINT, migrations): both run the statement logic in
13
+ * `./shared/postgres-dialect`.
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import { DatabaseError } from '@happyvertical/utils';
18
+ import type { DatabaseCacheOptions, DatabaseInterface, SchemasOption } from "./shared/types.js";
19
+ /**
20
+ * Thrown when the optional `@electric-sql/pglite` peer cannot be imported.
21
+ */
22
+ export declare class PGlitePeerMissingError extends DatabaseError {
23
+ constructor(cause?: unknown);
24
+ }
25
+ /**
26
+ * The part of a PGlite query result this adapter reads.
27
+ */
28
+ interface PGliteResultLike {
29
+ rows: any[];
30
+ affectedRows?: number;
31
+ rowCount?: number;
32
+ command?: string;
33
+ }
34
+ /**
35
+ * The part of a PGlite transaction object this adapter drives.
36
+ */
37
+ interface PGliteTransactionLike {
38
+ query(sql: string, params?: any[]): Promise<PGliteResultLike>;
39
+ exec(sql: string): Promise<PGliteResultLike[]>;
40
+ rollback(): Promise<void>;
41
+ readonly closed: boolean;
42
+ }
43
+ /**
44
+ * The part of a PGlite instance this adapter drives. A `PGlite` and a
45
+ * `PGliteWorker` both satisfy it.
46
+ */
47
+ export interface PGliteLike {
48
+ query(sql: string, params?: any[]): Promise<PGliteResultLike>;
49
+ exec(sql: string): Promise<PGliteResultLike[]>;
50
+ transaction<T>(callback: (tx: PGliteTransactionLike) => Promise<T>): Promise<T>;
51
+ close(): Promise<void>;
52
+ }
53
+ /**
54
+ * Configuration options for PGlite databases
55
+ */
56
+ export interface PGliteOptions extends DatabaseCacheOptions {
57
+ /**
58
+ * Database type identifier
59
+ */
60
+ type?: 'pglite';
61
+ /**
62
+ * Where the database lives.
63
+ *
64
+ * - `memory://` or omitted: in memory, gone when the instance closes
65
+ * - `idb://<name>`: IndexedDB (browser)
66
+ * - `opfs-ahp://<name>`: Origin Private File System (browser, in a worker)
67
+ * - any other value: a filesystem directory (Node, Bun, Deno)
68
+ *
69
+ * `url` is accepted as an alias so `HAVE_SQL_URL` selects a location.
70
+ */
71
+ dataDir?: string;
72
+ /**
73
+ * Alias for {@link dataDir}.
74
+ */
75
+ url?: string;
76
+ /**
77
+ * PGlite extensions to load, keyed by the name `CREATE EXTENSION` uses.
78
+ * Forwarded as-is to PGlite, so pass the extension objects the PGlite
79
+ * packages export, for example:
80
+ *
81
+ * ```typescript
82
+ * import { vector } from '@electric-sql/pglite-pgvector';
83
+ * await getDatabase({ type: 'pglite', extensions: { vector } });
84
+ * ```
85
+ */
86
+ extensions?: Record<string, unknown>;
87
+ /**
88
+ * Further options forwarded to PGlite's constructor (`relaxedDurability`,
89
+ * `initialMemory`, `loadDataDir`, `fs`, `parsers`, ...). `dataDir` and
90
+ * `extensions` are taken from the options above.
91
+ */
92
+ pglite?: Record<string, unknown>;
93
+ /**
94
+ * Use a PGlite instance you created yourself, such as a `PGliteWorker` that
95
+ * keeps the database off the main thread. The adapter never closes it and
96
+ * never caches the database it builds around it.
97
+ */
98
+ client?: PGliteLike;
99
+ /**
100
+ * Opaque caller-owned cache identity. Calls with the same `dbid` share one
101
+ * database. Without one, a persistent `dataDir` is its own identity — two
102
+ * PGlite instances on the same storage would corrupt it — while an in-memory
103
+ * database is private to the call that made it.
104
+ */
105
+ dbid?: string;
106
+ /**
107
+ * How long a queued transaction — or a statement issued while a transaction
108
+ * is open — waits for the connection, in milliseconds. PGlite runs one
109
+ * connection, so these run one at a time. Must be positive and finite.
110
+ *
111
+ * @default 30000
112
+ */
113
+ transactionQueueTimeout?: number;
114
+ /**
115
+ * Schema definitions for tables.
116
+ *
117
+ * **PGlite ignores this option** — like PostgreSQL, tables are managed by
118
+ * migrations. It exists so callers can pass schemas uniformly to all
119
+ * adapters.
120
+ */
121
+ schemas?: SchemasOption;
122
+ }
123
+ /**
124
+ * Clears the PGlite connection cache, closing every cached database.
125
+ * Useful for test isolation.
126
+ */
127
+ export declare function clearPGliteConnectionCache(): Promise<void>;
128
+ interface PGliteModule {
129
+ PGlite: {
130
+ create(dataDir?: string, options?: Record<string, unknown>): Promise<PGliteLike>;
131
+ };
132
+ messages: {
133
+ DatabaseError: new (...args: any[]) => Error;
134
+ };
135
+ }
136
+ /**
137
+ * Imports the optional peer. Isolated so a missing install becomes a typed
138
+ * {@link PGlitePeerMissingError} instead of a bare module-resolution failure.
139
+ */
140
+ export declare function importPGlite(): Promise<PGliteModule>;
141
+ /**
142
+ * Creates a PGlite database adapter.
143
+ *
144
+ * @param options - PGlite options
145
+ * @returns Database interface for PGlite
146
+ * @throws {PGlitePeerMissingError} When `@electric-sql/pglite` is not installed
147
+ */
148
+ export declare function getDatabase(options?: PGliteOptions): Promise<DatabaseInterface>;
149
+ export {};
150
+ //# sourceMappingURL=pglite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite.d.ts","sourceRoot":"","sources":["../src/pglite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAerD,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EAEjB,aAAa,EAEd,MAAM,mBAAgB,CAAC;AAKxB;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;gBAC3C,KAAK,CAAC,EAAE,OAAO;CAQ5B;AAED;;GAEG;AACH,UAAU,gBAAgB;IACxB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,YAAY,CAAC,EA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,MAAM,CAAC,EAAE,UAAU,CAAC;IAEpB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAID;;;GAGG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAIhE;AAED,UAAU,YAAY;IAEpB,MAAM,EAAE;QACN,MAAM,CACJ,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,UAAU,CAAC,CAAC;KACxB,CAAC;IAEF,QAAQ,EAAE;QAAE,aAAa,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAA;KAAE,CAAC;CAC5D;AAED;;;GAGG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,CAc1D;AAOD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAkB5B"}
package/dist/pglite.js ADDED
@@ -0,0 +1,339 @@
1
+ import { a as createVectorCapabilities, b as DatabaseSchemaManager, c as createTransactionLock, d as validateDatabaseCacheOptions, i as createTransactionErrorTracker, l as ConnectionCache, n as createGetTableSchema, r as createPostgresDialect, t as createAlterTable } from "./chunks/postgres-dialect-Bfswr4Vs.js";
2
+ import { DatabaseError } from "@happyvertical/utils";
3
+ //#region src/pglite.ts
4
+ /**
5
+ * PGlite adapter: real PostgreSQL compiled to WebAssembly, in the browser and
6
+ * in Node.
7
+ *
8
+ * `@electric-sql/pglite` is an optional peer dependency, imported only when
9
+ * this adapter creates a database. The module's import graph is browser-safe —
10
+ * no `node:` built-ins and no `pg` — so it can be bundled for a page. Import it
11
+ * from `@happyvertical/sql/pglite` there; the package root also reaches
12
+ * Node-only adapters.
13
+ *
14
+ * It speaks the same Postgres dialect as the `pg` adapter (native UUID ids and
15
+ * foreign keys, BIGINT, migrations): both run the statement logic in
16
+ * `./shared/postgres-dialect`.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ /** Package an install hint should name. */
21
+ var PGLITE_PACKAGE = "@electric-sql/pglite";
22
+ /**
23
+ * Thrown when the optional `@electric-sql/pglite` peer cannot be imported.
24
+ */
25
+ var PGlitePeerMissingError = class extends DatabaseError {
26
+ constructor(cause) {
27
+ super(`The pglite database type needs the optional peer dependency ${PGLITE_PACKAGE}. Install it with \`pnpm add ${PGLITE_PACKAGE}\` (or the npm/yarn equivalent).`, {
28
+ adapter: "pglite",
29
+ peer: PGLITE_PACKAGE
30
+ }, cause);
31
+ this.name = "PGlitePeerMissingError";
32
+ }
33
+ };
34
+ var connectionCache = new ConnectionCache();
35
+ /**
36
+ * Clears the PGlite connection cache, closing every cached database.
37
+ * Useful for test isolation.
38
+ */
39
+ async function clearPGliteConnectionCache() {
40
+ await connectionCache.clear(async (db) => {
41
+ await db.close?.();
42
+ });
43
+ }
44
+ /**
45
+ * Imports the optional peer. Isolated so a missing install becomes a typed
46
+ * {@link PGlitePeerMissingError} instead of a bare module-resolution failure.
47
+ */
48
+ async function importPGlite() {
49
+ try {
50
+ const loaded = await import("@electric-sql/pglite");
51
+ const module = typeof loaded?.PGlite?.create === "function" ? loaded : loaded?.default;
52
+ if (typeof module?.PGlite?.create !== "function") throw new Error(`${PGLITE_PACKAGE} did not export PGlite`);
53
+ return module;
54
+ } catch (error) {
55
+ throw new PGlitePeerMissingError(error);
56
+ }
57
+ }
58
+ var IN_MEMORY = "memory://";
59
+ var isInMemory = (dataDir) => dataDir === "" || dataDir.startsWith(IN_MEMORY);
60
+ /**
61
+ * Creates a PGlite database adapter.
62
+ *
63
+ * @param options - PGlite options
64
+ * @returns Database interface for PGlite
65
+ * @throws {PGlitePeerMissingError} When `@electric-sql/pglite` is not installed
66
+ */
67
+ async function getDatabase(options = {}) {
68
+ validateDatabaseCacheOptions(options);
69
+ const dataDir = options.dataDir ?? options.url ?? IN_MEMORY;
70
+ const key = options.client ? void 0 : options.dbid ? `pglite:id:${options.dbid}` : isInMemory(dataDir) ? void 0 : `pglite:dir:${dataDir}`;
71
+ return connectionCache.getOrCreate(key, options, () => createDatabase(options, dataDir), async (db) => {
72
+ await db.close?.();
73
+ });
74
+ }
75
+ /**
76
+ * Internal: creates the database. Loads the peer, so it never runs for a
77
+ * cached hit.
78
+ */
79
+ async function createDatabase(options, dataDir) {
80
+ const pglite = await importPGlite();
81
+ const isStatementError = (error) => error instanceof pglite.messages.DatabaseError;
82
+ const ownsClient = !options.client;
83
+ const pg = options.client ?? await pglite.PGlite.create(dataDir, {
84
+ ...options.pglite,
85
+ ...options.extensions ? { extensions: options.extensions } : {}
86
+ });
87
+ const lock = createTransactionLock("pglite", options.transactionQueueTimeout);
88
+ let db;
89
+ let closePromise;
90
+ /**
91
+ * Runs one statement. Without parameters PostgreSQL's simple protocol is
92
+ * used, like `pg`, so a multi-statement script works through `query()`.
93
+ */
94
+ const run = async (target, sql, values) => {
95
+ const result = values && values.length > 0 ? await target.query(sql, values) : (await target.exec(sql)).at(-1);
96
+ if (!result) return {
97
+ rows: [],
98
+ rowCount: 0
99
+ };
100
+ return {
101
+ rows: result.rows,
102
+ rowCount: result.rowCount ?? result.affectedRows ?? result.rows.length
103
+ };
104
+ };
105
+ const client = { query: (sql, values) => lock.run(() => run(pg, sql, values)) };
106
+ /**
107
+ * Binds the statement-error tracking to one PGlite transaction object.
108
+ * See `createTransactionErrorTracker` for why a statement failure has to
109
+ * outlive the `catch` that swallowed it.
110
+ */
111
+ const createTransactionState = (pgTx) => {
112
+ const tracker = createTransactionErrorTracker(isStatementError);
113
+ const executor = { query: (sql, values) => tracker.track(run(pgTx, sql, values), sql) };
114
+ const rawClient = {
115
+ query: (sql, params) => tracker.track(pgTx.query(sql, params), sql),
116
+ exec: (sql) => tracker.track(pgTx.exec(sql), sql)
117
+ };
118
+ /**
119
+ * Fails if the transaction can no longer commit. PostgreSQL answers COMMIT
120
+ * on an aborted transaction with a ROLLBACK tag and no error, and PGlite
121
+ * issues that COMMIT itself, so the aborted state is probed for here while
122
+ * there is still an error to throw.
123
+ */
124
+ const assertCommittable = async () => {
125
+ await tracker.drain();
126
+ const statementError = tracker.getError();
127
+ if (statementError !== void 0) throw statementError;
128
+ try {
129
+ await pgTx.query("SELECT 1");
130
+ } catch (error) {
131
+ throw tracker.getError() ?? tracker.getUnconfirmedError() ?? error;
132
+ }
133
+ const unconfirmed = tracker.getUnconfirmedError();
134
+ if (unconfirmed !== void 0) throw unconfirmed;
135
+ };
136
+ return {
137
+ tracker,
138
+ executor,
139
+ rawClient,
140
+ assertCommittable
141
+ };
142
+ };
143
+ const { serializeRecord, createClientMethods, createNestedTransaction } = createPostgresDialect({
144
+ client,
145
+ probeExecutor: (executor) => executor,
146
+ runInTransaction: (work) => lock.run(() => pg.transaction(async (pgTx) => {
147
+ const state = createTransactionState(pgTx);
148
+ const result = await work(state.executor);
149
+ await state.assertCommittable();
150
+ return result;
151
+ }))
152
+ });
153
+ const { insert, get, list, update, upsert, getOrInsert, delete: deleteRecords, count, table, many, single, pluck, execute, query, oo, oO, ox, xx, tableExists, syncSchema } = createClientMethods(client, false, serializeRecord);
154
+ const getTableSchema = createGetTableSchema({
155
+ many,
156
+ tableExists
157
+ });
158
+ const alterTable = createAlterTable(client);
159
+ /**
160
+ * Builds the interface handed to a transaction callback.
161
+ *
162
+ * There is no `AsyncLocalStorage` in a browser, so nested scopes are not
163
+ * tracked ambiently: each nested callback receives a handle bound to its own
164
+ * savepoint. Nested work must call the handle it was given.
165
+ */
166
+ const createScopedDatabase = (pgTx, extra = () => ({})) => {
167
+ const state = createTransactionState(pgTx);
168
+ let scoped;
169
+ const nested = createNestedTransaction(state.executor, (override) => override ? {
170
+ ...scoped,
171
+ transaction: override
172
+ } : scoped, state.tracker.clearError);
173
+ scoped = {
174
+ url: dataDir,
175
+ client: state.rawClient,
176
+ ...createClientMethods(state.executor, true, serializeRecord, state.tracker.clearError),
177
+ transaction: nested
178
+ };
179
+ Object.assign(scoped, extra(scoped));
180
+ return {
181
+ state,
182
+ nested,
183
+ scoped
184
+ };
185
+ };
186
+ /**
187
+ * Executes a callback within a database transaction. Commits on success and
188
+ * rolls back when the callback throws.
189
+ */
190
+ const transaction = async (callback) => {
191
+ const release = await lock.acquire();
192
+ try {
193
+ return await pg.transaction(async (pgTx) => {
194
+ const { state, nested, scoped } = createScopedDatabase(pgTx);
195
+ try {
196
+ const result = await callback(scoped);
197
+ await nested.drain();
198
+ await state.assertCommittable();
199
+ return result;
200
+ } catch (error) {
201
+ await nested.drain();
202
+ await state.tracker.drain();
203
+ throw error;
204
+ }
205
+ });
206
+ } finally {
207
+ release();
208
+ }
209
+ };
210
+ /**
211
+ * Begins a transaction and returns a handle for manual control.
212
+ *
213
+ * PGlite only offers a callback form, so the callback is held open until the
214
+ * handle is committed or rolled back.
215
+ */
216
+ const beginTransaction = async () => {
217
+ const release = await lock.acquire();
218
+ try {
219
+ let settle;
220
+ const outcome = new Promise((resolve) => {
221
+ settle = resolve;
222
+ });
223
+ let begun;
224
+ let failedToBegin;
225
+ const started = new Promise((resolve, reject) => {
226
+ begun = resolve;
227
+ failedToBegin = reject;
228
+ });
229
+ const finished = pg.transaction(async (pgTx) => {
230
+ begun(pgTx);
231
+ if (await outcome === "rollback") await pgTx.rollback();
232
+ });
233
+ finished.catch(failedToBegin);
234
+ const pgTx = await started;
235
+ let active = true;
236
+ const { state, nested, scoped } = createScopedDatabase(pgTx, () => ({
237
+ commit: () => end("COMMIT"),
238
+ rollback: () => end("ROLLBACK"),
239
+ isActive: () => active
240
+ }));
241
+ const end = async (command) => {
242
+ if (!active) throw new DatabaseError("Transaction already ended", {});
243
+ active = false;
244
+ let failure;
245
+ try {
246
+ await nested.drain();
247
+ await state.tracker.drain();
248
+ if (command === "COMMIT") await state.assertCommittable();
249
+ } catch (error) {
250
+ failure = { error };
251
+ }
252
+ settle(command === "COMMIT" && !failure ? "commit" : "rollback");
253
+ try {
254
+ await finished;
255
+ } catch (error) {
256
+ failure ??= { error };
257
+ } finally {
258
+ release();
259
+ }
260
+ if (failure) throw failure.error;
261
+ };
262
+ return scoped;
263
+ } catch (error) {
264
+ release();
265
+ throw error;
266
+ }
267
+ };
268
+ const initializeSchemas = async (schemaOptions) => {
269
+ const schemaManager = new DatabaseSchemaManager();
270
+ const currentDb = {
271
+ url: dataDir,
272
+ client: pg,
273
+ insert,
274
+ update,
275
+ upsert,
276
+ get,
277
+ getOrInsert,
278
+ delete: deleteRecords,
279
+ count,
280
+ list,
281
+ table,
282
+ many,
283
+ single,
284
+ pluck,
285
+ execute,
286
+ query,
287
+ oo,
288
+ oO,
289
+ ox,
290
+ xx,
291
+ tableExists,
292
+ syncSchema,
293
+ transaction
294
+ };
295
+ await schemaManager.initializeSchemas(currentDb, schemaOptions);
296
+ };
297
+ db = {
298
+ url: dataDir,
299
+ client: pg,
300
+ insert,
301
+ update,
302
+ upsert,
303
+ get,
304
+ getOrInsert,
305
+ delete: deleteRecords,
306
+ count,
307
+ list,
308
+ table,
309
+ many,
310
+ single,
311
+ pluck,
312
+ execute,
313
+ query,
314
+ oo,
315
+ oO,
316
+ ox,
317
+ xx,
318
+ tableExists,
319
+ syncSchema,
320
+ initializeSchemas,
321
+ transaction,
322
+ beginTransaction,
323
+ getTableSchema,
324
+ alterTable,
325
+ vector: createVectorCapabilities(client),
326
+ close: async () => {
327
+ closePromise ??= (async () => {
328
+ connectionCache.forget(db);
329
+ if (ownsClient) await pg.close();
330
+ })();
331
+ return closePromise;
332
+ }
333
+ };
334
+ return db;
335
+ }
336
+ //#endregion
337
+ export { PGlitePeerMissingError, clearPGliteConnectionCache, getDatabase, importPGlite };
338
+
339
+ //# sourceMappingURL=pglite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite.js","names":[],"sources":["../src/pglite.ts"],"sourcesContent":["/**\n * PGlite adapter: real PostgreSQL compiled to WebAssembly, in the browser and\n * in Node.\n *\n * `@electric-sql/pglite` is an optional peer dependency, imported only when\n * this adapter creates a database. The module's import graph is browser-safe —\n * no `node:` built-ins and no `pg` — so it can be bundled for a page. Import it\n * from `@happyvertical/sql/pglite` there; the package root also reaches\n * Node-only adapters.\n *\n * It speaks the same Postgres dialect as the `pg` adapter (native UUID ids and\n * foreign keys, BIGINT, migrations): both run the statement logic in\n * `./shared/postgres-dialect`.\n *\n * @packageDocumentation\n */\n\nimport { DatabaseError } from '@happyvertical/utils';\nimport { DatabaseSchemaManager } from './schema-manager';\nimport {\n ConnectionCache,\n validateDatabaseCacheOptions,\n} from './shared/connection-cache';\nimport {\n createAlterTable,\n createGetTableSchema,\n createPostgresDialect,\n createTransactionErrorTracker,\n createVectorCapabilities,\n type PostgresQueryExecutor,\n} from './shared/postgres-dialect';\nimport { createTransactionLock } from './shared/transaction-lock';\nimport type {\n DatabaseCacheOptions,\n DatabaseInterface,\n SchemaInitializationOptions,\n SchemasOption,\n TransactionHandle,\n} from './shared/types';\n\n/** Package an install hint should name. */\nconst PGLITE_PACKAGE = '@electric-sql/pglite';\n\n/**\n * Thrown when the optional `@electric-sql/pglite` peer cannot be imported.\n */\nexport class PGlitePeerMissingError extends DatabaseError {\n constructor(cause?: unknown) {\n super(\n `The pglite database type needs the optional peer dependency ${PGLITE_PACKAGE}. Install it with \\`pnpm add ${PGLITE_PACKAGE}\\` (or the npm/yarn equivalent).`,\n { adapter: 'pglite', peer: PGLITE_PACKAGE },\n cause,\n );\n this.name = 'PGlitePeerMissingError';\n }\n}\n\n/**\n * The part of a PGlite query result this adapter reads.\n */\ninterface PGliteResultLike {\n rows: any[];\n affectedRows?: number;\n rowCount?: number;\n command?: string;\n}\n\n/**\n * The part of a PGlite transaction object this adapter drives.\n */\ninterface PGliteTransactionLike {\n query(sql: string, params?: any[]): Promise<PGliteResultLike>;\n exec(sql: string): Promise<PGliteResultLike[]>;\n rollback(): Promise<void>;\n readonly closed: boolean;\n}\n\n/**\n * The part of a PGlite instance this adapter drives. A `PGlite` and a\n * `PGliteWorker` both satisfy it.\n */\nexport interface PGliteLike {\n query(sql: string, params?: any[]): Promise<PGliteResultLike>;\n exec(sql: string): Promise<PGliteResultLike[]>;\n transaction<T>(\n callback: (tx: PGliteTransactionLike) => Promise<T>,\n ): Promise<T>;\n close(): Promise<void>;\n}\n\n/**\n * Configuration options for PGlite databases\n */\nexport interface PGliteOptions extends DatabaseCacheOptions {\n /**\n * Database type identifier\n */\n type?: 'pglite';\n\n /**\n * Where the database lives.\n *\n * - `memory://` or omitted: in memory, gone when the instance closes\n * - `idb://<name>`: IndexedDB (browser)\n * - `opfs-ahp://<name>`: Origin Private File System (browser, in a worker)\n * - any other value: a filesystem directory (Node, Bun, Deno)\n *\n * `url` is accepted as an alias so `HAVE_SQL_URL` selects a location.\n */\n dataDir?: string;\n\n /**\n * Alias for {@link dataDir}.\n */\n url?: string;\n\n /**\n * PGlite extensions to load, keyed by the name `CREATE EXTENSION` uses.\n * Forwarded as-is to PGlite, so pass the extension objects the PGlite\n * packages export, for example:\n *\n * ```typescript\n * import { vector } from '@electric-sql/pglite-pgvector';\n * await getDatabase({ type: 'pglite', extensions: { vector } });\n * ```\n */\n extensions?: Record<string, unknown>;\n\n /**\n * Further options forwarded to PGlite's constructor (`relaxedDurability`,\n * `initialMemory`, `loadDataDir`, `fs`, `parsers`, ...). `dataDir` and\n * `extensions` are taken from the options above.\n */\n pglite?: Record<string, unknown>;\n\n /**\n * Use a PGlite instance you created yourself, such as a `PGliteWorker` that\n * keeps the database off the main thread. The adapter never closes it and\n * never caches the database it builds around it.\n */\n client?: PGliteLike;\n\n /**\n * Opaque caller-owned cache identity. Calls with the same `dbid` share one\n * database. Without one, a persistent `dataDir` is its own identity — two\n * PGlite instances on the same storage would corrupt it — while an in-memory\n * database is private to the call that made it.\n */\n dbid?: string;\n\n /**\n * How long a queued transaction — or a statement issued while a transaction\n * is open — waits for the connection, in milliseconds. PGlite runs one\n * connection, so these run one at a time. Must be positive and finite.\n *\n * @default 30000\n */\n transactionQueueTimeout?: number;\n\n /**\n * Schema definitions for tables.\n *\n * **PGlite ignores this option** — like PostgreSQL, tables are managed by\n * migrations. It exists so callers can pass schemas uniformly to all\n * adapters.\n */\n schemas?: SchemasOption;\n}\n\nconst connectionCache = new ConnectionCache<DatabaseInterface>();\n\n/**\n * Clears the PGlite connection cache, closing every cached database.\n * Useful for test isolation.\n */\nexport async function clearPGliteConnectionCache(): Promise<void> {\n await connectionCache.clear(async (db) => {\n await db.close?.();\n });\n}\n\ninterface PGliteModule {\n // biome-ignore lint/style/useNamingConvention: mirrors the package's export\n PGlite: {\n create(\n dataDir?: string,\n options?: Record<string, unknown>,\n ): Promise<PGliteLike>;\n };\n // biome-ignore lint/style/useNamingConvention: mirrors the package's export\n messages: { DatabaseError: new (...args: any[]) => Error };\n}\n\n/**\n * Imports the optional peer. Isolated so a missing install becomes a typed\n * {@link PGlitePeerMissingError} instead of a bare module-resolution failure.\n */\nexport async function importPGlite(): Promise<PGliteModule> {\n try {\n const loaded = (await import('@electric-sql/pglite')) as unknown as\n | (PGliteModule & { default?: PGliteModule })\n | undefined;\n const module =\n typeof loaded?.PGlite?.create === 'function' ? loaded : loaded?.default;\n if (typeof module?.PGlite?.create !== 'function') {\n throw new Error(`${PGLITE_PACKAGE} did not export PGlite`);\n }\n return module;\n } catch (error) {\n throw new PGlitePeerMissingError(error);\n }\n}\n\nconst IN_MEMORY = 'memory://';\n\nconst isInMemory = (dataDir: string): boolean =>\n dataDir === '' || dataDir.startsWith(IN_MEMORY);\n\n/**\n * Creates a PGlite database adapter.\n *\n * @param options - PGlite options\n * @returns Database interface for PGlite\n * @throws {PGlitePeerMissingError} When `@electric-sql/pglite` is not installed\n */\nexport async function getDatabase(\n options: PGliteOptions = {},\n): Promise<DatabaseInterface> {\n validateDatabaseCacheOptions(options);\n const dataDir = options.dataDir ?? options.url ?? IN_MEMORY;\n const key = options.client\n ? undefined\n : options.dbid\n ? `pglite:id:${options.dbid}`\n : isInMemory(dataDir)\n ? undefined\n : `pglite:dir:${dataDir}`;\n return connectionCache.getOrCreate(\n key,\n options,\n () => createDatabase(options, dataDir),\n async (db) => {\n await db.close?.();\n },\n );\n}\n\n/**\n * Internal: creates the database. Loads the peer, so it never runs for a\n * cached hit.\n */\nasync function createDatabase(\n options: PGliteOptions,\n dataDir: string,\n): Promise<DatabaseInterface> {\n const pglite = await importPGlite();\n const isStatementError = (error: unknown): boolean =>\n error instanceof pglite.messages.DatabaseError;\n\n const ownsClient = !options.client;\n const pg: PGliteLike =\n options.client ??\n (await pglite.PGlite.create(dataDir, {\n ...options.pglite,\n ...(options.extensions ? { extensions: options.extensions } : {}),\n }));\n\n // One connection: transactions take turns, and so do top-level statements\n // while a transaction is open. PGlite queues them itself, but without a\n // deadline — a transaction handle that is never ended, or a top-level call\n // made from inside a transaction callback, would hang forever rather than\n // fail with an explanation.\n const lock = createTransactionLock('pglite', options.transactionQueueTimeout);\n\n let db: DatabaseInterface;\n let closePromise: Promise<void> | undefined;\n\n type Target = Pick<PGliteTransactionLike, 'query' | 'exec'>;\n\n /**\n * Runs one statement. Without parameters PostgreSQL's simple protocol is\n * used, like `pg`, so a multi-statement script works through `query()`.\n */\n const run = async (\n target: Target,\n sql: string,\n values?: any[],\n ): Promise<{ rows: any[]; rowCount: number | null }> => {\n const result =\n values && values.length > 0\n ? await target.query(sql, values)\n : (await target.exec(sql)).at(-1);\n if (!result) return { rows: [], rowCount: 0 };\n return {\n rows: result.rows,\n rowCount: result.rowCount ?? result.affectedRows ?? result.rows.length,\n };\n };\n\n // Statements outside a transaction.\n const client: PostgresQueryExecutor = {\n query: (sql, values) => lock.run(() => run(pg, sql, values)),\n };\n\n /**\n * Binds the statement-error tracking to one PGlite transaction object.\n * See `createTransactionErrorTracker` for why a statement failure has to\n * outlive the `catch` that swallowed it.\n */\n const createTransactionState = (pgTx: PGliteTransactionLike) => {\n const tracker = createTransactionErrorTracker(isStatementError);\n const executor: PostgresQueryExecutor = {\n query: (sql, values) => tracker.track(run(pgTx, sql, values), sql),\n };\n // `tx.client` is PGlite's own surface; route it through the tracker too so\n // raw use cannot hide a failure from the commit check.\n const rawClient = {\n query: (sql: string, params?: any[]) =>\n tracker.track(pgTx.query(sql, params), sql),\n exec: (sql: string) => tracker.track(pgTx.exec(sql), sql),\n };\n\n /**\n * Fails if the transaction can no longer commit. PostgreSQL answers COMMIT\n * on an aborted transaction with a ROLLBACK tag and no error, and PGlite\n * issues that COMMIT itself, so the aborted state is probed for here while\n * there is still an error to throw.\n */\n const assertCommittable = async (): Promise<void> => {\n await tracker.drain();\n const statementError = tracker.getError();\n if (statementError !== undefined) throw statementError;\n try {\n await pgTx.query('SELECT 1');\n } catch (error) {\n throw tracker.getError() ?? tracker.getUnconfirmedError() ?? error;\n }\n const unconfirmed = tracker.getUnconfirmedError();\n if (unconfirmed !== undefined) throw unconfirmed;\n };\n\n return { tracker, executor, rawClient, assertCommittable };\n };\n\n const dialect = createPostgresDialect({\n client,\n // One connection, so a probe cannot be answered from a second one.\n probeExecutor: (executor) => executor,\n runInTransaction: (work) =>\n lock.run(() =>\n pg.transaction(async (pgTx) => {\n const state = createTransactionState(pgTx);\n const result = await work(state.executor);\n await state.assertCommittable();\n return result;\n }),\n ),\n });\n const { serializeRecord, createClientMethods, createNestedTransaction } =\n dialect;\n\n const {\n insert,\n get,\n list,\n update,\n upsert,\n getOrInsert,\n delete: deleteRecords,\n count,\n table,\n many,\n single,\n pluck,\n execute,\n query,\n oo,\n oO,\n ox,\n xx,\n tableExists,\n syncSchema,\n } = createClientMethods(client, false, serializeRecord);\n const getTableSchema = createGetTableSchema({ many, tableExists });\n const alterTable = createAlterTable(client);\n\n /**\n * Builds the interface handed to a transaction callback.\n *\n * There is no `AsyncLocalStorage` in a browser, so nested scopes are not\n * tracked ambiently: each nested callback receives a handle bound to its own\n * savepoint. Nested work must call the handle it was given.\n */\n const createScopedDatabase = (\n pgTx: PGliteTransactionLike,\n extra: (scoped: DatabaseInterface) => Record<string, unknown> = () => ({}),\n ) => {\n const state = createTransactionState(pgTx);\n let scoped!: DatabaseInterface;\n const nested = createNestedTransaction(\n state.executor,\n (override) => (override ? { ...scoped, transaction: override } : scoped),\n state.tracker.clearError,\n );\n scoped = {\n url: dataDir,\n client: state.rawClient,\n ...createClientMethods(\n state.executor,\n true,\n serializeRecord,\n state.tracker.clearError,\n ),\n transaction: nested,\n } as DatabaseInterface;\n Object.assign(scoped, extra(scoped));\n return { state, nested, scoped };\n };\n\n /**\n * Executes a callback within a database transaction. Commits on success and\n * rolls back when the callback throws.\n */\n const transaction = async <T>(\n callback: (tx: DatabaseInterface) => Promise<T>,\n ): Promise<T> => {\n const release = await lock.acquire();\n try {\n return await pg.transaction(async (pgTx) => {\n const { state, nested, scoped } = createScopedDatabase(pgTx);\n try {\n const result = await callback(scoped);\n await nested.drain();\n await state.assertCommittable();\n return result;\n } catch (error) {\n // A rejected Promise.all can leave queued savepoint work running;\n // PGlite rolls back as soon as this callback settles.\n await nested.drain();\n await state.tracker.drain();\n throw error;\n }\n });\n } finally {\n release();\n }\n };\n\n /**\n * Begins a transaction and returns a handle for manual control.\n *\n * PGlite only offers a callback form, so the callback is held open until the\n * handle is committed or rolled back.\n */\n const beginTransaction = async (): Promise<TransactionHandle> => {\n const release = await lock.acquire();\n try {\n let settle!: (outcome: 'commit' | 'rollback') => void;\n const outcome = new Promise<'commit' | 'rollback'>((resolve) => {\n settle = resolve;\n });\n let begun!: (tx: PGliteTransactionLike) => void;\n let failedToBegin!: (error: unknown) => void;\n const started = new Promise<PGliteTransactionLike>((resolve, reject) => {\n begun = resolve;\n failedToBegin = reject;\n });\n const finished = pg.transaction(async (pgTx) => {\n begun(pgTx);\n if ((await outcome) === 'rollback') await pgTx.rollback();\n });\n // BEGIN failing rejects `finished` before the callback ever runs.\n finished.catch(failedToBegin);\n const pgTx = await started;\n\n let active = true;\n const { state, nested, scoped } = createScopedDatabase(pgTx, () => ({\n commit: () => end('COMMIT'),\n rollback: () => end('ROLLBACK'),\n isActive: () => active,\n }));\n\n // The transaction is over however this ends, so the connection is\n // returned whether COMMIT succeeds, throws, or was never reachable.\n const end = async (command: 'COMMIT' | 'ROLLBACK'): Promise<void> => {\n if (!active) {\n throw new DatabaseError('Transaction already ended', {});\n }\n active = false;\n let failure: { error: unknown } | undefined;\n try {\n await nested.drain();\n await state.tracker.drain();\n if (command === 'COMMIT') await state.assertCommittable();\n } catch (error) {\n failure = { error };\n }\n settle(command === 'COMMIT' && !failure ? 'commit' : 'rollback');\n try {\n await finished;\n } catch (error) {\n failure ??= { error };\n } finally {\n release();\n }\n if (failure) throw failure.error;\n };\n\n return scoped as TransactionHandle;\n } catch (error) {\n release();\n throw error;\n }\n };\n\n const initializeSchemas = async (\n schemaOptions: SchemaInitializationOptions,\n ): Promise<void> => {\n const schemaManager = new DatabaseSchemaManager();\n const currentDb: DatabaseInterface = {\n url: dataDir,\n client: pg,\n insert,\n update,\n upsert,\n get,\n getOrInsert,\n delete: deleteRecords,\n count,\n list,\n table,\n many,\n single,\n pluck,\n execute,\n query,\n oo,\n oO,\n ox,\n xx,\n tableExists,\n syncSchema,\n transaction,\n };\n\n await schemaManager.initializeSchemas(currentDb, schemaOptions);\n };\n\n db = {\n url: dataDir,\n client: pg,\n insert,\n update,\n upsert,\n get,\n getOrInsert,\n delete: deleteRecords,\n count,\n list,\n table,\n many,\n single,\n pluck,\n execute,\n query,\n oo,\n oO,\n ox,\n xx,\n tableExists,\n syncSchema,\n initializeSchemas,\n transaction,\n beginTransaction,\n getTableSchema,\n alterTable,\n vector: createVectorCapabilities(client),\n close: async () => {\n closePromise ??= (async () => {\n connectionCache.forget(db);\n if (ownsClient) await pg.close();\n })();\n return closePromise;\n },\n };\n\n return db;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA,IAAM,iBAAiB;;;;AAKvB,IAAa,yBAAb,cAA4C,cAAc;CACxD,YAAY,OA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B,OACxB,kBACkB;EAClB,MAAM,gBAAgB,IAAI,sBAAsB;EAChD,MAAM,YAA+B;GACnC,KAAK;GACL,QAAQ;GACR;GACA;GACA;GACA;GACA;GACA,QAAQ;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF;EAEA,MAAM,cAAc,kBAAkB,WAAW,aAAa;CAChE;CAEA,KAAK;EACH,KAAK;EACL,QAAQ;EACR;EACA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ,yBAAyB,MAAM;EACvC,OAAO,YAAY;GACjB,kBAAkB,YAAY;IAC5B,gBAAgB,OAAO,EAAE;IACzB,IAAI,YAAY,MAAM,GAAG,MAAM;GACjC,EAAA,CAAG;GACH,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,eAAe,EAEhB,MAAM,8BAA2B,CAAC;AACnC,OAAO,KAAK,EAIV,oBAAoB,EACpB,iBAAiB,EAYlB,MAAM,mBAAgB,CAAC;AAUxB;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,oBAAoB;IAC3D;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,GAA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