@lunora/replica 0.0.0 → 1.0.0-alpha.100

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 (42) hide show
  1. package/LICENSE.md +445 -0
  2. package/README.md +239 -29
  3. package/dist/adapters/better-sqlite3.d.mts +29 -0
  4. package/dist/adapters/better-sqlite3.d.ts +29 -0
  5. package/dist/adapters/better-sqlite3.mjs +1 -0
  6. package/dist/adapters/sqlite-wasm.d.mts +30 -0
  7. package/dist/adapters/sqlite-wasm.d.ts +30 -0
  8. package/dist/adapters/sqlite-wasm.mjs +1 -0
  9. package/dist/adapters/sqljs.d.mts +22 -0
  10. package/dist/adapters/sqljs.d.ts +22 -0
  11. package/dist/adapters/sqljs.mjs +1 -0
  12. package/dist/index.d.mts +1074 -0
  13. package/dist/index.d.ts +1074 -0
  14. package/dist/index.mjs +1 -0
  15. package/dist/packem_shared/EventEmitter-uo75adUL.mjs +1 -0
  16. package/dist/packem_shared/EventLog-SuC_BKwj.mjs +1 -0
  17. package/dist/packem_shared/EventLogDO-BgUx2GGL.mjs +1 -0
  18. package/dist/packem_shared/EventLogDOClient-DWerZ3_n.mjs +1 -0
  19. package/dist/packem_shared/EventSource-Bg6zNmRn.mjs +1 -0
  20. package/dist/packem_shared/EventsSync-B3wzXm-b.mjs +1 -0
  21. package/dist/packem_shared/InMemorySnapshotStore-C4taIG5K.mjs +1 -0
  22. package/dist/packem_shared/LocalMirror-Bn22hyEB.mjs +4 -0
  23. package/dist/packem_shared/MaterializerRuntime-DFXi-aqd.mjs +1 -0
  24. package/dist/packem_shared/SubscriptionManager-AhPw3lFc.mjs +1 -0
  25. package/dist/packem_shared/applyDiff-CZAqAC8Y.mjs +1 -0
  26. package/dist/packem_shared/applyDiffToDb-CK-Dcy17.mjs +1 -0
  27. package/dist/packem_shared/classifyChanges-BBc0-770.mjs +1 -0
  28. package/dist/packem_shared/defineEvents-DHo-VK7G.mjs +1 -0
  29. package/dist/packem_shared/eventsContext-Dxow9Y7S.mjs +1 -0
  30. package/dist/packem_shared/fnv1a-BNN96GYb.mjs +1 -0
  31. package/dist/packem_shared/int64-CCVxepl4.mjs +1 -0
  32. package/dist/packem_shared/isClientSeq-D2Xm0_lj.mjs +1 -0
  33. package/dist/packem_shared/local-mirror.d-DzREvGNM.d.mts +562 -0
  34. package/dist/packem_shared/local-mirror.d-wbGXkXaE.d.ts +562 -0
  35. package/dist/packem_shared/subscribeToMirror-DSn8n1IR.mjs +1 -0
  36. package/dist/packem_shared/types.d-BuLTPLaQ.d.mts +22 -0
  37. package/dist/packem_shared/types.d-BuLTPLaQ.d.ts +22 -0
  38. package/dist/packem_shared/wire-key-DfMHAtqH.mjs +1 -0
  39. package/dist/react.d.mts +77 -0
  40. package/dist/react.d.ts +77 -0
  41. package/dist/react.mjs +1 -0
  42. package/package.json +88 -7
package/README.md CHANGED
@@ -1,45 +1,255 @@
1
- # @lunora/replica
1
+ <!-- START_PACKAGE_OG_IMAGE_PLACEHOLDER -->
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ <a href="https://www.anolilab.com/open-source" align="center">
4
4
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ <img src="__assets__/package-og.svg" alt="replica" />
6
6
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
7
+ </a>
8
8
 
9
- ## Purpose
9
+ <h3 align="center">Local-first replica runtime + local SQLite mirror for Lunora</h3>
10
10
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@lunora/replica`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
11
+ <!-- END_PACKAGE_OG_IMAGE_PLACEHOLDER -->
15
12
 
16
- ## What is OIDC Trusted Publishing?
13
+ > **Experimental** — this package is outside the Lunora 1.0 stability promise: its API may change in any release, without a major version bump.
17
14
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
15
+ <br />
19
16
 
20
- ## Setup Instructions
17
+ <div align="center">
21
18
 
22
- To properly configure OIDC trusted publishing for this package:
19
+ [![typescript-image][typescript-badge]][typescript-url]
20
+ [![FSL-1.1-Apache-2.0 licence][license-badge]][license]
21
+ [![npm version][npm-version-badge]][npm-version]
22
+ [![npm downloads][npm-downloads-badge]][npm-downloads]
23
+ [![PRs Welcome][prs-welcome-badge]][prs-welcome]
23
24
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
25
+ </div>
28
26
 
29
- ## DO NOT USE THIS PACKAGE
27
+ ---
28
+
29
+ <div align="center">
30
+ <p>
31
+ <sup>
32
+ Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
33
+ </sup>
34
+ </p>
35
+ </div>
30
36
 
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
37
+ ---
36
38
 
37
- ## More Information
39
+ Local-first replica runtime and local SQLite mirror for [Lunora](https://lunora.sh).
38
40
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
41
+ **Events layer** — derive state from an append-only event log via reducers, persist
42
+ events through a Durable Object, and subscribe to typed events.
42
43
 
43
- ---
44
+ **Local mirror** — a client-side SQLite mirror that maintains a replica
45
+ of server tables by applying typed row-level diffs. Choose the SQLite backend
46
+ that fits your runtime:
44
47
 
45
- **Maintained for OIDC setup purposes only**
48
+ | Backend | Entry point | Runtime |
49
+ | ----------------------- | ----------------------------------------- | ------------------------------ |
50
+ | sql.js (WASM) | `@lunora/replica/adapters/sqljs` | Browser, Node, Service Workers |
51
+ | better-sqlite3 (native) | `@lunora/replica/adapters/better-sqlite3` | Node.js |
52
+ | @sqlite.org/sqlite-wasm | `@lunora/replica/adapters/sqlite-wasm` | Browser, Node (official WASM) |
53
+ | Custom | Write your own `SqliteAdapter` | Any |
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ pnpm add @lunora/replica
59
+ # Choose one SQLite backend:
60
+ pnpm add sql.js # browser + Node (WASM)
61
+ pnpm add better-sqlite3 # Node.js only (native)
62
+ pnpm add @sqlite.org/sqlite-wasm # browser (official WASM)
63
+ # @lunora/server is optional — needed only for the EventLogDO:
64
+ pnpm add @lunora/server
65
+ ```
66
+
67
+ ## Exports
68
+
69
+ | Entry point | Contents |
70
+ | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71
+ | `@lunora/replica` | `EventSource`, `EventEmitter`, `defineEvents`, `defineMaterializer`, `EventLogDO`, `EventLogDOClient`, `SubscriptionManager`, `InMemorySnapshotStore`, `eventsContext`, `LocalMirror`, `EventLog`, `EventsSync`, `subscribeToMirror`, `applyDiff`, `TableDiff` helpers, `createSqlJsAdapter`, `createBetterSqlite3Adapter`, `createSqliteWasmAdapter` |
72
+ | `@lunora/replica/react` | `useLocalQuery` React hook |
73
+ | `@lunora/replica/adapters/sqljs` | `createSqlJsAdapter` (sql.js) |
74
+ | `@lunora/replica/adapters/better-sqlite3` | `createBetterSqlite3Adapter` (better-sqlite3) |
75
+ | `@lunora/replica/adapters/sqlite-wasm` | `createSqliteWasmAdapter` (@sqlite.org/sqlite-wasm) |
76
+
77
+ ## EventSource
78
+
79
+ The core runtime — a typed reducer that derives state from an append-only log:
80
+
81
+ ```ts
82
+ import { EventSource } from "@lunora/replica";
83
+
84
+ interface MyState {
85
+ count: number;
86
+ items: string[];
87
+ }
88
+
89
+ const source = new EventSource<MyState>({ count: 0, items: [] }, (state, entry) => {
90
+ switch (entry.type) {
91
+ case "item:added":
92
+ return { count: state.count + 1, items: [...state.items, entry.payload as string] };
93
+ default:
94
+ return state;
95
+ }
96
+ });
97
+
98
+ source.applyEvent("item:added", "hello");
99
+ console.log(source.state.count); // 1
100
+ ```
101
+
102
+ ## LocalMirror
103
+
104
+ An SQLite mirror that applies typed row-level diffs. Create it with your
105
+ chosen backend:
106
+
107
+ ```ts
108
+ import initSqlJs from "sql.js";
109
+ import { createSqlJsAdapter, LocalMirror } from "@lunora/replica";
110
+
111
+ const SQL = await initSqlJs();
112
+ const adapter = createSqlJsAdapter(new SQL.Database());
113
+ const mirror = new LocalMirror({ db: adapter });
114
+
115
+ // A diff is `{ table, timestamp, changes }` (plus an optional stable `id`).
116
+ // `createTableDiff("todos", changes)` fills the timestamp and id for you.
117
+ mirror.applyDiff({
118
+ table: "todos",
119
+ timestamp: Date.now(),
120
+ changes: [{ type: "insert", data: { id: "1", title: "hello", done: false } }],
121
+ });
122
+
123
+ const todos = mirror.query<{ id: string; title: string }>("SELECT id, title FROM todos");
124
+ ```
125
+
126
+ For `better-sqlite3`:
127
+
128
+ ```ts
129
+ import Database from "better-sqlite3";
130
+ import { createBetterSqlite3Adapter, LocalMirror } from "@lunora/replica";
131
+
132
+ const adapter = createBetterSqlite3Adapter(new Database(":memory:"));
133
+ const mirror = new LocalMirror({ db: adapter });
134
+ ```
135
+
136
+ ### EventsSync
137
+
138
+ Periodically polls a server-side event log, replays events through a state
139
+ machine, and pushes the resulting diffs to the mirror:
140
+
141
+ ```ts
142
+ import { EventsSync } from "@lunora/replica";
143
+
144
+ const sync = new EventsSync({
145
+ // `getSince` answers ONE bounded page; EventsSync keeps calling with the
146
+ // advanced watermark until the log is exhausted.
147
+ fetchEventsSince: async (seq) => (await eventLogClient.getSince(seq)).entries,
148
+ applyEvents: (events) => {
149
+ /* feed events into your state machine */
150
+ },
151
+ getTableDiffs: () => {
152
+ /* compare state before/after → TableDiff[] */
153
+ },
154
+ mirror,
155
+ pollInterval: 3000,
156
+ });
157
+
158
+ sync.start(); // begin polling
159
+ // sync.sync(); // one-shot sync
160
+ // sync.stop(); // halt polling
161
+ ```
162
+
163
+ See the [EventsSync JSDoc](src/sync-events.ts) for full API details.
164
+
165
+ ### useLocalQuery (React)
166
+
167
+ Live-updating hook that re-queries the mirror whenever a diff is applied. It
168
+ returns a discriminated union — `{ data }` on success, `{ error }` when the
169
+ query fails (malformed SQL, or the table doesn't exist yet because no matching
170
+ diff has been applied). A failure is never collapsed to `undefined`, so check
171
+ `error` explicitly rather than reading a missing `data` as "still loading".
172
+
173
+ ```tsx
174
+ import { useLocalQuery } from "@lunora/replica/react";
175
+
176
+ function TodoList() {
177
+ const { data: todos, error } = useLocalQuery<{ id: string; title: string; done: boolean }>(mirror, "SELECT id, title, done FROM todos WHERE done = ?", [
178
+ false,
179
+ ]);
180
+
181
+ if (error) {
182
+ return <p>Query failed: {error.message}</p>;
183
+ }
184
+
185
+ if (todos === undefined) {
186
+ return <p>Waiting for data…</p>;
187
+ }
188
+
189
+ return (
190
+ <ul>
191
+ {todos.map((t) => (
192
+ <li key={t.id}>{t.title}</li>
193
+ ))}
194
+ </ul>
195
+ );
196
+ }
197
+ ```
198
+
199
+ The hook uses `useSyncExternalStore` under the hood, so it integrates with
200
+ React 18+ concurrent features and Suspense-based frameworks (Next.js, Remix).
201
+
202
+ ## EventLogDO
203
+
204
+ A Durable Object that persists the event log to DO SQLite storage.
205
+
206
+ Re-export the class from your worker entry so Wrangler can find it:
207
+
208
+ ```ts
209
+ // src/worker.ts
210
+ export { EventLogDO } from "@lunora/replica";
211
+ ```
212
+
213
+ Then declare the binding in `wrangler.jsonc`. The DO uses `state.storage.sql`,
214
+ so its migration **must** use `new_sqlite_classes` — `new_classes` gives the
215
+ instance a key-value store with no `.sql`, and every request fails at the first
216
+ statement:
217
+
218
+ ```jsonc
219
+ {
220
+ "durable_objects": {
221
+ "bindings": [{ "name": "EVENT_LOG_DO", "class_name": "EventLogDO" }],
222
+ },
223
+ "migrations": [{ "tag": "v1", "new_sqlite_classes": ["EventLogDO"] }],
224
+ }
225
+ ```
226
+
227
+ `EventLogDOClient` wraps the DO's `fetch()` RPC surface. Its only option is
228
+ `fetch` — a function that dispatches a request to the instance you want, which
229
+ is where the namespace and instance id are chosen:
230
+
231
+ ```ts
232
+ const client = new EventLogDOClient({
233
+ fetch: (request) => env.EVENT_LOG_DO.get(env.EVENT_LOG_DO.idFromName("my-app")).fetch(request),
234
+ });
235
+
236
+ // Append takes an ARRAY of events and returns them with their assigned `seq`s.
237
+ const [entry] = await client.append([{ type: "order:placed", payload: { orderId: "123" } }]);
238
+
239
+ // Read back by sequence number — the log is append-only and ordered, so
240
+ // there is no filter-by-type query. Every read is ONE bounded page (500
241
+ // entries by default, 1000 max): walk `cursor` while `truncated` is true.
242
+ const { entries, truncated, cursor } = await client.getSince(entry.seq);
243
+ const page = await client.getSince(0, 50);
244
+ const size = await client.getSize();
245
+ ```
246
+
247
+ ## Custom adapters
248
+
249
+ See the [custom adapter guide](docs/guides/custom-adapter.mdx) for writing
250
+ `SqliteAdapter` implementations for `expo-sqlite`, `bun:sqlite`, or any other
251
+ SQLite runtime.
252
+
253
+ ## License
254
+
255
+ [FSL-1.1-Apache-2.0](./LICENSE.md)
@@ -0,0 +1,29 @@
1
+ import { S as SqliteAdapter } from "../packem_shared/types.d-BuLTPLaQ.mjs";
2
+ /**
3
+ * Create a {@link SqliteAdapter} backed by [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)
4
+ * (a synchronous SQLite3 binding for Node.js).
5
+ *
6
+ * The adapter takes a structural projection of better-sqlite3's `Database` so
7
+ * the package never imports from `better-sqlite3` directly — consumers install
8
+ * it themselves and pass in their database instance.
9
+ * @param database An already-initialised better-sqlite3 `Database` instance.
10
+ * @param database.close Tear down the database connection.
11
+ * @param database.exec Execute one or more SQL statements (no params, no results).
12
+ * @param database.prepare Prepare a SQL statement for repeated execution.
13
+ * @param database.transaction Wrap a function so its statements run in a transaction.
14
+ * @experimental
15
+ */
16
+ declare const createBetterSqlite3Adapter: (database: {
17
+ close: () => void;
18
+ exec: (sql: string) => void;
19
+ prepare: (sql: string) => {
20
+ all: (params?: unknown[]) => unknown[];
21
+ get: (params?: unknown[]) => unknown;
22
+ run: (params?: unknown[]) => {
23
+ lastInsertRowid: number | bigint;
24
+ };
25
+ safeIntegers: (toggle?: boolean) => unknown;
26
+ };
27
+ transaction: (function_: () => void) => () => void;
28
+ }) => SqliteAdapter;
29
+ export { createBetterSqlite3Adapter };
@@ -0,0 +1,29 @@
1
+ import { S as SqliteAdapter } from "../packem_shared/types.d-BuLTPLaQ.js";
2
+ /**
3
+ * Create a {@link SqliteAdapter} backed by [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)
4
+ * (a synchronous SQLite3 binding for Node.js).
5
+ *
6
+ * The adapter takes a structural projection of better-sqlite3's `Database` so
7
+ * the package never imports from `better-sqlite3` directly — consumers install
8
+ * it themselves and pass in their database instance.
9
+ * @param database An already-initialised better-sqlite3 `Database` instance.
10
+ * @param database.close Tear down the database connection.
11
+ * @param database.exec Execute one or more SQL statements (no params, no results).
12
+ * @param database.prepare Prepare a SQL statement for repeated execution.
13
+ * @param database.transaction Wrap a function so its statements run in a transaction.
14
+ * @experimental
15
+ */
16
+ declare const createBetterSqlite3Adapter: (database: {
17
+ close: () => void;
18
+ exec: (sql: string) => void;
19
+ prepare: (sql: string) => {
20
+ all: (params?: unknown[]) => unknown[];
21
+ get: (params?: unknown[]) => unknown;
22
+ run: (params?: unknown[]) => {
23
+ lastInsertRowid: number | bigint;
24
+ };
25
+ safeIntegers: (toggle?: boolean) => unknown;
26
+ };
27
+ transaction: (function_: () => void) => () => void;
28
+ }) => SqliteAdapter;
29
+ export { createBetterSqlite3Adapter };
@@ -0,0 +1 @@
1
+ import{n as c}from"../packem_shared/int64-CCVxepl4.mjs";const p=t=>({exec(r,e){e&&e.length>0?t.prepare(r).run([...e]):t.exec(r)},query(r,e){const n=t.prepare(r);n.safeIntegers(!0);const o=e&&e.length>0?n.all([...e]):n.all();return c(o)},transaction(r){t.transaction(r)()},close(){t.close()}});export{p as createBetterSqlite3Adapter};
@@ -0,0 +1,30 @@
1
+ import { S as SqliteAdapter } from "../packem_shared/types.d-BuLTPLaQ.mjs";
2
+ /**
3
+ * Create a {@link SqliteAdapter} backed by the [official SQLite Wasm](https://www.npmjs.com/package/@sqlite.org/sqlite-wasm)
4
+ * (a WebAssembly build of SQLite that runs in browsers and Node.js).
5
+ *
6
+ * The adapter takes a structural projection of the OO API (`sqlite3.oo1.DB`) so
7
+ * the package never imports from `@sqlite.org/sqlite-wasm` directly — consumers
8
+ * install it themselves and pass in their database instance.
9
+ *
10
+ * IMPORTANT (REPLICA-01): the real `oo1.DB.exec()` does NOT return sql.js's
11
+ * `{ columns, values }[]` result shape — with `rowMode: "object"` and
12
+ * `returnValue: "resultRows"` it returns the rows directly, as
13
+ * `Record<string, unknown>[]`. This adapter is written against that real shape.
14
+ * @param database An already-initialised `sqlite3.oo1.DB` instance.
15
+ * @param database.close Tear down the database connection.
16
+ * @param database.exec Execute SQL with optional bind params. With
17
+ * `{ returnValue: "resultRows", rowMode: "object" }` it returns the matched
18
+ * rows directly (`Record<string, unknown>[]`); otherwise (DDL/DML/BEGIN/
19
+ * COMMIT/ROLLBACK) its return value is unused here.
20
+ * @experimental
21
+ */
22
+ declare const createSqliteWasmAdapter: (database: {
23
+ close: () => void;
24
+ exec: (sql: string, options?: {
25
+ bind?: unknown[];
26
+ returnValue?: "resultRows";
27
+ rowMode?: "object";
28
+ }) => Record<string, unknown>[] | undefined;
29
+ }) => SqliteAdapter;
30
+ export { createSqliteWasmAdapter };
@@ -0,0 +1,30 @@
1
+ import { S as SqliteAdapter } from "../packem_shared/types.d-BuLTPLaQ.js";
2
+ /**
3
+ * Create a {@link SqliteAdapter} backed by the [official SQLite Wasm](https://www.npmjs.com/package/@sqlite.org/sqlite-wasm)
4
+ * (a WebAssembly build of SQLite that runs in browsers and Node.js).
5
+ *
6
+ * The adapter takes a structural projection of the OO API (`sqlite3.oo1.DB`) so
7
+ * the package never imports from `@sqlite.org/sqlite-wasm` directly — consumers
8
+ * install it themselves and pass in their database instance.
9
+ *
10
+ * IMPORTANT (REPLICA-01): the real `oo1.DB.exec()` does NOT return sql.js's
11
+ * `{ columns, values }[]` result shape — with `rowMode: "object"` and
12
+ * `returnValue: "resultRows"` it returns the rows directly, as
13
+ * `Record<string, unknown>[]`. This adapter is written against that real shape.
14
+ * @param database An already-initialised `sqlite3.oo1.DB` instance.
15
+ * @param database.close Tear down the database connection.
16
+ * @param database.exec Execute SQL with optional bind params. With
17
+ * `{ returnValue: "resultRows", rowMode: "object" }` it returns the matched
18
+ * rows directly (`Record<string, unknown>[]`); otherwise (DDL/DML/BEGIN/
19
+ * COMMIT/ROLLBACK) its return value is unused here.
20
+ * @experimental
21
+ */
22
+ declare const createSqliteWasmAdapter: (database: {
23
+ close: () => void;
24
+ exec: (sql: string, options?: {
25
+ bind?: unknown[];
26
+ returnValue?: "resultRows";
27
+ rowMode?: "object";
28
+ }) => Record<string, unknown>[] | undefined;
29
+ }) => SqliteAdapter;
30
+ export { createSqliteWasmAdapter };
@@ -0,0 +1 @@
1
+ import{n}from"../packem_shared/int64-CCVxepl4.mjs";const x=r=>({exec(o,e){e&&e.length>0?r.exec(o,{bind:[...e]}):r.exec(o)},query(o,e){const c=r.exec(o,{bind:e&&e.length>0?[...e]:void 0,returnValue:"resultRows",rowMode:"object"});return n(c??[])},transaction(o){r.exec("BEGIN");try{o(),r.exec("COMMIT")}catch(e){throw r.exec("ROLLBACK"),e}},close(){r.close()}});export{x as createSqliteWasmAdapter};
@@ -0,0 +1,22 @@
1
+ import { S as SqliteAdapter } from "../packem_shared/types.d-BuLTPLaQ.mjs";
2
+ /**
3
+ * Create a {@link SqliteAdapter} backed by [sql.js](https://sql.js.org)
4
+ * (a WebAssembly build of SQLite that runs in browsers, Node, and
5
+ * React Native).
6
+ * @param database An already-initialised sql.js database instance.
7
+ * @param database.run Execute a parameterised SQL statement (no results).
8
+ * @param database.exec Execute SQL and return result rows.
9
+ * @param database.close Tear down the database connection.
10
+ * @experimental
11
+ */
12
+ declare const createSqlJsAdapter: (database: {
13
+ close: () => void;
14
+ exec: (sql: string, params?: unknown[], config?: {
15
+ useBigInt?: boolean;
16
+ }) => {
17
+ columns: string[];
18
+ values: unknown[][];
19
+ }[];
20
+ run: (sql: string, params?: unknown[]) => void;
21
+ }) => SqliteAdapter;
22
+ export { createSqlJsAdapter };
@@ -0,0 +1,22 @@
1
+ import { S as SqliteAdapter } from "../packem_shared/types.d-BuLTPLaQ.js";
2
+ /**
3
+ * Create a {@link SqliteAdapter} backed by [sql.js](https://sql.js.org)
4
+ * (a WebAssembly build of SQLite that runs in browsers, Node, and
5
+ * React Native).
6
+ * @param database An already-initialised sql.js database instance.
7
+ * @param database.run Execute a parameterised SQL statement (no results).
8
+ * @param database.exec Execute SQL and return result rows.
9
+ * @param database.close Tear down the database connection.
10
+ * @experimental
11
+ */
12
+ declare const createSqlJsAdapter: (database: {
13
+ close: () => void;
14
+ exec: (sql: string, params?: unknown[], config?: {
15
+ useBigInt?: boolean;
16
+ }) => {
17
+ columns: string[];
18
+ values: unknown[][];
19
+ }[];
20
+ run: (sql: string, params?: unknown[]) => void;
21
+ }) => SqliteAdapter;
22
+ export { createSqlJsAdapter };
@@ -0,0 +1 @@
1
+ import{n as i}from"../packem_shared/int64-CCVxepl4.mjs";const w=o=>({exec(e,r){r&&r.length>0?o.run(e,[...r]):o.exec(e)},query(e,r){const n=o.exec(e,r&&r.length>0?[...r]:void 0,{useBigInt:!0})[0];if(!n)return[];const u=n.columns,t=[];for(const s of n.values){const c={};for(const[l,f]of u.entries())c[f]=s[l];t.push(c)}return i(t)},transaction(e){o.run("BEGIN");try{e(),o.run("COMMIT")}catch(r){throw o.run("ROLLBACK"),r}},close(){o.close()}});export{w as createSqlJsAdapter};