@lunora/replica 1.0.0-alpha.7 → 1.0.0-alpha.70

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 (49) hide show
  1. package/LICENSE.md +214 -0
  2. package/dist/adapters/better-sqlite3.mjs +1 -29
  3. package/dist/adapters/sqlite-wasm.d.mts +2 -2
  4. package/dist/adapters/sqlite-wasm.d.ts +2 -2
  5. package/dist/adapters/sqlite-wasm.mjs +1 -44
  6. package/dist/adapters/sqljs.mjs +1 -55
  7. package/dist/index.d.mts +43 -16
  8. package/dist/index.d.ts +43 -16
  9. package/dist/index.mjs +1 -20
  10. package/dist/packem_shared/EventEmitter-uo75adUL.mjs +1 -0
  11. package/dist/packem_shared/EventLog-B1-yhArT.mjs +1 -0
  12. package/dist/packem_shared/EventLogDO-CaZvpgJN.mjs +1 -0
  13. package/dist/packem_shared/EventLogDOClient-DGDMj5L5.mjs +1 -0
  14. package/dist/packem_shared/EventSource-BC0hKJSA.mjs +1 -0
  15. package/dist/packem_shared/EventsSync-DWyGGZQZ.mjs +1 -0
  16. package/dist/packem_shared/InMemorySnapshotStore-C4taIG5K.mjs +1 -0
  17. package/dist/packem_shared/LocalMirror-BIURA-He.mjs +4 -0
  18. package/dist/packem_shared/MaterializerRuntime-D0HOAe24.mjs +1 -0
  19. package/dist/packem_shared/SubscriptionManager-AhPw3lFc.mjs +1 -0
  20. package/dist/packem_shared/applyDiff-Da160K7_.mjs +1 -0
  21. package/dist/packem_shared/applyDiffToDb-C6ek5Elp.mjs +1 -0
  22. package/dist/packem_shared/classifyChanges-ioMfjjbU.mjs +1 -0
  23. package/dist/packem_shared/defineEvents-DHo-VK7G.mjs +1 -0
  24. package/dist/packem_shared/eventsContext-Dxow9Y7S.mjs +1 -0
  25. package/dist/packem_shared/isClientSeq-D2Xm0_lj.mjs +1 -0
  26. package/dist/packem_shared/{local-mirror.d-CyGOpUES.d.ts → local-mirror.d-ByrYTq4z.d.ts} +2 -2
  27. package/dist/packem_shared/{local-mirror.d-DTavX_y0.d.mts → local-mirror.d-Cip3QuMf.d.mts} +2 -2
  28. package/dist/packem_shared/subscribeToMirror-CX10AaP3.mjs +1 -0
  29. package/dist/react.d.mts +41 -14
  30. package/dist/react.d.ts +41 -14
  31. package/dist/react.mjs +1 -15
  32. package/package.json +1 -1
  33. package/dist/packem_shared/EventEmitter-CMZfct03.mjs +0 -92
  34. package/dist/packem_shared/EventLog-CnK-3Wge.mjs +0 -264
  35. package/dist/packem_shared/EventLogDO-DqlsVx0H.mjs +0 -381
  36. package/dist/packem_shared/EventLogDOClient-F4FO8Si4.mjs +0 -92
  37. package/dist/packem_shared/EventSource-D5yO9_aI.mjs +0 -221
  38. package/dist/packem_shared/EventsSync-BP36tC9O.mjs +0 -123
  39. package/dist/packem_shared/InMemorySnapshotStore-BHVAD-Bp.mjs +0 -24
  40. package/dist/packem_shared/LocalMirror-a-5jEqFN.mjs +0 -219
  41. package/dist/packem_shared/MaterializerRuntime-BoIrsMYB.mjs +0 -224
  42. package/dist/packem_shared/SubscriptionManager-C5xbw0pg.mjs +0 -75
  43. package/dist/packem_shared/applyDiff-98tKzmiW.mjs +0 -67
  44. package/dist/packem_shared/applyDiffToDb-DQ1xZp5J.mjs +0 -58
  45. package/dist/packem_shared/classifyChanges-RcqLBpLs.mjs +0 -41
  46. package/dist/packem_shared/defineEvents-DiBkPTh_.mjs +0 -28
  47. package/dist/packem_shared/eventsContext-Bk_p48hj.mjs +0 -6
  48. package/dist/packem_shared/isClientSeq-C46BkzqJ.mjs +0 -5
  49. package/dist/packem_shared/subscribeToMirror-CiaM-nQ7.mjs +0 -45
package/LICENSE.md CHANGED
@@ -227,5 +227,219 @@ Repository: git+https://github.com/anolilab/lunora.git
227
227
  >
228
228
  > <!-- DEPENDENCIES -->
229
229
  > <!-- /DEPENDENCIES -->
230
+ >
231
+ >
232
+ >
233
+ > # Licenses of bundled types
234
+ > The published @lunora/server artifact additionally contains code with the following licenses:
235
+ > Apache-2.0
236
+ >
237
+ > # Bundled types:
238
+ > ## @opentelemetry/api
239
+ > License: Apache-2.0
240
+ > By: OpenTelemetry Authors
241
+ > Repository: open-telemetry/opentelemetry-js
242
+ >
243
+ > > Apache License
244
+ > > Version 2.0, January 2004
245
+ > > http://www.apache.org/licenses/
246
+ > >
247
+ > > TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
248
+ > >
249
+ > > 1. Definitions.
250
+ > >
251
+ > > "License" shall mean the terms and conditions for use, reproduction,
252
+ > > and distribution as defined by Sections 1 through 9 of this document.
253
+ > >
254
+ > > "Licensor" shall mean the copyright owner or entity authorized by
255
+ > > the copyright owner that is granting the License.
256
+ > >
257
+ > > "Legal Entity" shall mean the union of the acting entity and all
258
+ > > other entities that control, are controlled by, or are under common
259
+ > > control with that entity. For the purposes of this definition,
260
+ > > "control" means (i) the power, direct or indirect, to cause the
261
+ > > direction or management of such entity, whether by contract or
262
+ > > otherwise, or (ii) ownership of fifty percent (50%) or more of the
263
+ > > outstanding shares, or (iii) beneficial ownership of such entity.
264
+ > >
265
+ > > "You" (or "Your") shall mean an individual or Legal Entity
266
+ > > exercising permissions granted by this License.
267
+ > >
268
+ > > "Source" form shall mean the preferred form for making modifications,
269
+ > > including but not limited to software source code, documentation
270
+ > > source, and configuration files.
271
+ > >
272
+ > > "Object" form shall mean any form resulting from mechanical
273
+ > > transformation or translation of a Source form, including but
274
+ > > not limited to compiled object code, generated documentation,
275
+ > > and conversions to other media types.
276
+ > >
277
+ > > "Work" shall mean the work of authorship, whether in Source or
278
+ > > Object form, made available under the License, as indicated by a
279
+ > > copyright notice that is included in or attached to the work
280
+ > > (an example is provided in the Appendix below).
281
+ > >
282
+ > > "Derivative Works" shall mean any work, whether in Source or Object
283
+ > > form, that is based on (or derived from) the Work and for which the
284
+ > > editorial revisions, annotations, elaborations, or other modifications
285
+ > > represent, as a whole, an original work of authorship. For the purposes
286
+ > > of this License, Derivative Works shall not include works that remain
287
+ > > separable from, or merely link (or bind by name) to the interfaces of,
288
+ > > the Work and Derivative Works thereof.
289
+ > >
290
+ > > "Contribution" shall mean any work of authorship, including
291
+ > > the original version of the Work and any modifications or additions
292
+ > > to that Work or Derivative Works thereof, that is intentionally
293
+ > > submitted to Licensor for inclusion in the Work by the copyright owner
294
+ > > or by an individual or Legal Entity authorized to submit on behalf of
295
+ > > the copyright owner. For the purposes of this definition, "submitted"
296
+ > > means any form of electronic, verbal, or written communication sent
297
+ > > to the Licensor or its representatives, including but not limited to
298
+ > > communication on electronic mailing lists, source code control systems,
299
+ > > and issue tracking systems that are managed by, or on behalf of, the
300
+ > > Licensor for the purpose of discussing and improving the Work, but
301
+ > > excluding communication that is conspicuously marked or otherwise
302
+ > > designated in writing by the copyright owner as "Not a Contribution."
303
+ > >
304
+ > > "Contributor" shall mean Licensor and any individual or Legal Entity
305
+ > > on behalf of whom a Contribution has been received by Licensor and
306
+ > > subsequently incorporated within the Work.
307
+ > >
308
+ > > 2. Grant of Copyright License. Subject to the terms and conditions of
309
+ > > this License, each Contributor hereby grants to You a perpetual,
310
+ > > worldwide, non-exclusive, no-charge, royalty-free, irrevocable
311
+ > > copyright license to reproduce, prepare Derivative Works of,
312
+ > > publicly display, publicly perform, sublicense, and distribute the
313
+ > > Work and such Derivative Works in Source or Object form.
314
+ > >
315
+ > > 3. Grant of Patent License. Subject to the terms and conditions of
316
+ > > this License, each Contributor hereby grants to You a perpetual,
317
+ > > worldwide, non-exclusive, no-charge, royalty-free, irrevocable
318
+ > > (except as stated in this section) patent license to make, have made,
319
+ > > use, offer to sell, sell, import, and otherwise transfer the Work,
320
+ > > where such license applies only to those patent claims licensable
321
+ > > by such Contributor that are necessarily infringed by their
322
+ > > Contribution(s) alone or by combination of their Contribution(s)
323
+ > > with the Work to which such Contribution(s) was submitted. If You
324
+ > > institute patent litigation against any entity (including a
325
+ > > cross-claim or counterclaim in a lawsuit) alleging that the Work
326
+ > > or a Contribution incorporated within the Work constitutes direct
327
+ > > or contributory patent infringement, then any patent licenses
328
+ > > granted to You under this License for that Work shall terminate
329
+ > > as of the date such litigation is filed.
330
+ > >
331
+ > > 4. Redistribution. You may reproduce and distribute copies of the
332
+ > > Work or Derivative Works thereof in any medium, with or without
333
+ > > modifications, and in Source or Object form, provided that You
334
+ > > meet the following conditions:
335
+ > >
336
+ > > (a) You must give any other recipients of the Work or
337
+ > > Derivative Works a copy of this License; and
338
+ > >
339
+ > > (b) You must cause any modified files to carry prominent notices
340
+ > > stating that You changed the files; and
341
+ > >
342
+ > > (c) You must retain, in the Source form of any Derivative Works
343
+ > > that You distribute, all copyright, patent, trademark, and
344
+ > > attribution notices from the Source form of the Work,
345
+ > > excluding those notices that do not pertain to any part of
346
+ > > the Derivative Works; and
347
+ > >
348
+ > > (d) If the Work includes a "NOTICE" text file as part of its
349
+ > > distribution, then any Derivative Works that You distribute must
350
+ > > include a readable copy of the attribution notices contained
351
+ > > within such NOTICE file, excluding those notices that do not
352
+ > > pertain to any part of the Derivative Works, in at least one
353
+ > > of the following places: within a NOTICE text file distributed
354
+ > > as part of the Derivative Works; within the Source form or
355
+ > > documentation, if provided along with the Derivative Works; or,
356
+ > > within a display generated by the Derivative Works, if and
357
+ > > wherever such third-party notices normally appear. The contents
358
+ > > of the NOTICE file are for informational purposes only and
359
+ > > do not modify the License. You may add Your own attribution
360
+ > > notices within Derivative Works that You distribute, alongside
361
+ > > or as an addendum to the NOTICE text from the Work, provided
362
+ > > that such additional attribution notices cannot be construed
363
+ > > as modifying the License.
364
+ > >
365
+ > > You may add Your own copyright statement to Your modifications and
366
+ > > may provide additional or different license terms and conditions
367
+ > > for use, reproduction, or distribution of Your modifications, or
368
+ > > for any such Derivative Works as a whole, provided Your use,
369
+ > > reproduction, and distribution of the Work otherwise complies with
370
+ > > the conditions stated in this License.
371
+ > >
372
+ > > 5. Submission of Contributions. Unless You explicitly state otherwise,
373
+ > > any Contribution intentionally submitted for inclusion in the Work
374
+ > > by You to the Licensor shall be under the terms and conditions of
375
+ > > this License, without any additional terms or conditions.
376
+ > > Notwithstanding the above, nothing herein shall supersede or modify
377
+ > > the terms of any separate license agreement you may have executed
378
+ > > with Licensor regarding such Contributions.
379
+ > >
380
+ > > 6. Trademarks. This License does not grant permission to use the trade
381
+ > > names, trademarks, service marks, or product names of the Licensor,
382
+ > > except as required for reasonable and customary use in describing the
383
+ > > origin of the Work and reproducing the content of the NOTICE file.
384
+ > >
385
+ > > 7. Disclaimer of Warranty. Unless required by applicable law or
386
+ > > agreed to in writing, Licensor provides the Work (and each
387
+ > > Contributor provides its Contributions) on an "AS IS" BASIS,
388
+ > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
389
+ > > implied, including, without limitation, any warranties or conditions
390
+ > > of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
391
+ > > PARTICULAR PURPOSE. You are solely responsible for determining the
392
+ > > appropriateness of using or redistributing the Work and assume any
393
+ > > risks associated with Your exercise of permissions under this License.
394
+ > >
395
+ > > 8. Limitation of Liability. In no event and under no legal theory,
396
+ > > whether in tort (including negligence), contract, or otherwise,
397
+ > > unless required by applicable law (such as deliberate and grossly
398
+ > > negligent acts) or agreed to in writing, shall any Contributor be
399
+ > > liable to You for damages, including any direct, indirect, special,
400
+ > > incidental, or consequential damages of any character arising as a
401
+ > > result of this License or out of the use or inability to use the
402
+ > > Work (including but not limited to damages for loss of goodwill,
403
+ > > work stoppage, computer failure or malfunction, or any and all
404
+ > > other commercial damages or losses), even if such Contributor
405
+ > > has been advised of the possibility of such damages.
406
+ > >
407
+ > > 9. Accepting Warranty or Additional Liability. While redistributing
408
+ > > the Work or Derivative Works thereof, You may choose to offer,
409
+ > > and charge a fee for, acceptance of support, warranty, indemnity,
410
+ > > or other liability obligations and/or rights consistent with this
411
+ > > License. However, in accepting such obligations, You may act only
412
+ > > on Your own behalf and on Your sole responsibility, not on behalf
413
+ > > of any other Contributor, and only if You agree to indemnify,
414
+ > > defend, and hold each Contributor harmless for any liability
415
+ > > incurred by, or claims asserted against, such Contributor by reason
416
+ > > of your accepting any such warranty or additional liability.
417
+ > >
418
+ > > END OF TERMS AND CONDITIONS
419
+ > >
420
+ > > APPENDIX: How to apply the Apache License to your work.
421
+ > >
422
+ > > To apply the Apache License to your work, attach the following
423
+ > > boilerplate notice, with the fields enclosed by brackets "[]"
424
+ > > replaced with your own identifying information. (Don't include
425
+ > > the brackets!) The text should be enclosed in the appropriate
426
+ > > comment syntax for the file format. We also recommend that a
427
+ > > file or class name and description of purpose be included on the
428
+ > > same "printed page" as the copyright notice for easier
429
+ > > identification within third-party archives.
430
+ > >
431
+ > > Copyright [yyyy] [name of copyright owner]
432
+ > >
433
+ > > Licensed under the Apache License, Version 2.0 (the "License");
434
+ > > you may not use this file except in compliance with the License.
435
+ > > You may obtain a copy of the License at
436
+ > >
437
+ > > http://www.apache.org/licenses/LICENSE-2.0
438
+ > >
439
+ > > Unless required by applicable law or agreed to in writing, software
440
+ > > distributed under the License is distributed on an "AS IS" BASIS,
441
+ > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
442
+ > > See the License for the specific language governing permissions and
443
+ > > limitations under the License.
230
444
 
231
445
  <!-- /TYPE_DEPENDENCIES -->
@@ -1,29 +1 @@
1
- const createBetterSqlite3Adapter = (database) => {
2
- return {
3
- exec(sql, params) {
4
- if (params && params.length > 0) {
5
- database.prepare(sql).run([...params]);
6
- } else {
7
- database.exec(sql);
8
- }
9
- },
10
- query(sql, params) {
11
- const stmt = database.prepare(sql);
12
- const rows = params && params.length > 0 ? stmt.all([...params]) : stmt.all();
13
- return rows;
14
- },
15
- transaction(function_) {
16
- const wrapped = database.transaction(function_);
17
- wrapped();
18
- },
19
- lastInsertRowId() {
20
- const row = database.prepare("SELECT last_insert_rowid() AS id").get();
21
- return Number(row?.id ?? -1);
22
- },
23
- close() {
24
- database.close();
25
- }
26
- };
27
- };
28
-
29
- export { createBetterSqlite3Adapter };
1
+ const c=t=>({exec(e,r){r&&r.length>0?t.prepare(e).run([...r]):t.exec(e)},query(e,r){const n=t.prepare(e);return r&&r.length>0?n.all([...r]):n.all()},transaction(e){t.transaction(e)()},lastInsertRowId(){const e=t.prepare("SELECT last_insert_rowid() AS id").get();return Number(e?.id??-1)},close(){t.close()}});export{c as createBetterSqlite3Adapter};
@@ -10,7 +10,7 @@ import { S as SqliteAdapter } from "../packem_shared/types.d-CkMkSwLJ.mjs";
10
10
  * IMPORTANT (REPLICA-01): the real `oo1.DB.exec()` does NOT return sql.js's
11
11
  * `{ columns, values }[]` result shape — with `rowMode: "object"` and
12
12
  * `returnValue: "resultRows"` it returns the rows directly, as
13
- * `Record&lt;string, unknown>[]`. This adapter is written against that real
13
+ * `Record<string, unknown>[]`. This adapter is written against that real
14
14
  * shape; `lastInsertRowId` uses the driver's `selectValue()` convenience
15
15
  * method (a single-scalar query helper) rather than parsing a result-row
16
16
  * array.
@@ -18,7 +18,7 @@ import { S as SqliteAdapter } from "../packem_shared/types.d-CkMkSwLJ.mjs";
18
18
  * @param database.close Tear down the database connection.
19
19
  * @param database.exec Execute SQL with optional bind params. With
20
20
  * `{ returnValue: "resultRows", rowMode: "object" }` it returns the matched
21
- * rows directly (`Record&lt;string, unknown>[]`); otherwise (DDL/DML/BEGIN/
21
+ * rows directly (`Record<string, unknown>[]`); otherwise (DDL/DML/BEGIN/
22
22
  * COMMIT/ROLLBACK) its return value is unused here.
23
23
  * @param database.selectValue Run a query and return the first column of the
24
24
  * first row as a single scalar — used for `SELECT last_insert_rowid()`.
@@ -10,7 +10,7 @@ import { S as SqliteAdapter } from "../packem_shared/types.d-CkMkSwLJ.js";
10
10
  * IMPORTANT (REPLICA-01): the real `oo1.DB.exec()` does NOT return sql.js's
11
11
  * `{ columns, values }[]` result shape — with `rowMode: "object"` and
12
12
  * `returnValue: "resultRows"` it returns the rows directly, as
13
- * `Record&lt;string, unknown>[]`. This adapter is written against that real
13
+ * `Record<string, unknown>[]`. This adapter is written against that real
14
14
  * shape; `lastInsertRowId` uses the driver's `selectValue()` convenience
15
15
  * method (a single-scalar query helper) rather than parsing a result-row
16
16
  * array.
@@ -18,7 +18,7 @@ import { S as SqliteAdapter } from "../packem_shared/types.d-CkMkSwLJ.js";
18
18
  * @param database.close Tear down the database connection.
19
19
  * @param database.exec Execute SQL with optional bind params. With
20
20
  * `{ returnValue: "resultRows", rowMode: "object" }` it returns the matched
21
- * rows directly (`Record&lt;string, unknown>[]`); otherwise (DDL/DML/BEGIN/
21
+ * rows directly (`Record<string, unknown>[]`); otherwise (DDL/DML/BEGIN/
22
22
  * COMMIT/ROLLBACK) its return value is unused here.
23
23
  * @param database.selectValue Run a query and return the first column of the
24
24
  * first row as a single scalar — used for `SELECT last_insert_rowid()`.
@@ -1,44 +1 @@
1
- const createSqliteWasmAdapter = (database) => {
2
- return {
3
- exec(sql, params) {
4
- if (params && params.length > 0) {
5
- database.exec(sql, { bind: [...params] });
6
- } else {
7
- database.exec(sql);
8
- }
9
- },
10
- query(sql, params) {
11
- const rows = database.exec(sql, {
12
- bind: params && params.length > 0 ? [...params] : void 0,
13
- returnValue: "resultRows",
14
- rowMode: "object"
15
- });
16
- return rows ?? [];
17
- },
18
- transaction(function_) {
19
- database.exec("BEGIN");
20
- try {
21
- function_();
22
- database.exec("COMMIT");
23
- } catch (error) {
24
- database.exec("ROLLBACK");
25
- throw error;
26
- }
27
- },
28
- lastInsertRowId() {
29
- const value = database.selectValue("SELECT last_insert_rowid()");
30
- if (typeof value === "number") {
31
- return value;
32
- }
33
- if (typeof value === "bigint") {
34
- return Number(value);
35
- }
36
- return -1;
37
- },
38
- close() {
39
- database.close();
40
- }
41
- };
42
- };
43
-
44
- export { createSqliteWasmAdapter };
1
+ const n=t=>({exec(e,r){r&&r.length>0?t.exec(e,{bind:[...r]}):t.exec(e)},query(e,r){return t.exec(e,{bind:r&&r.length>0?[...r]:void 0,returnValue:"resultRows",rowMode:"object"})??[]},transaction(e){t.exec("BEGIN");try{e(),t.exec("COMMIT")}catch(r){throw t.exec("ROLLBACK"),r}},lastInsertRowId(){const e=t.selectValue("SELECT last_insert_rowid()");return typeof e=="number"?e:typeof e=="bigint"?Number(e):-1},close(){t.close()}});export{n as createSqliteWasmAdapter};
@@ -1,55 +1 @@
1
- const createSqlJsAdapter = (database) => {
2
- return {
3
- exec(sql, params) {
4
- if (params && params.length > 0) {
5
- database.run(sql, [...params]);
6
- } else {
7
- database.exec(sql);
8
- }
9
- },
10
- query(sql, params) {
11
- const result = params && params.length > 0 ? database.exec(sql, [...params]) : database.exec(sql);
12
- const first = result[0];
13
- if (!first) {
14
- return [];
15
- }
16
- const colNames = first.columns;
17
- const rows = [];
18
- for (const row of first.values) {
19
- const object = {};
20
- for (const [i, column] of colNames.entries()) {
21
- object[column] = row[i];
22
- }
23
- rows.push(object);
24
- }
25
- return rows;
26
- },
27
- transaction(function_) {
28
- database.run("BEGIN");
29
- try {
30
- function_();
31
- database.run("COMMIT");
32
- } catch (error) {
33
- database.run("ROLLBACK");
34
- throw error;
35
- }
36
- },
37
- lastInsertRowId() {
38
- const result = database.exec("SELECT last_insert_rowid() AS id");
39
- const firstRow = result[0];
40
- if (result.length === 0 || !firstRow || firstRow.values.length === 0) {
41
- return -1;
42
- }
43
- const value = firstRow.values[0];
44
- if (!value || value.length === 0) {
45
- return -1;
46
- }
47
- return Number(value[0]);
48
- },
49
- close() {
50
- database.close();
51
- }
52
- };
53
- };
54
-
55
- export { createSqlJsAdapter };
1
+ const h=n=>({exec(r,e){e&&e.length>0?n.run(r,[...e]):n.exec(r)},query(r,e){const o=(e&&e.length>0?n.exec(r,[...e]):n.exec(r))[0];if(!o)return[];const l=o.columns,c=[];for(const s of o.values){const u={};for(const[i,f]of l.entries())u[f]=s[i];c.push(u)}return c},transaction(r){n.run("BEGIN");try{r(),n.run("COMMIT")}catch(e){throw n.run("ROLLBACK"),e}},lastInsertRowId(){const r=n.exec("SELECT last_insert_rowid() AS id"),e=r[0];if(r.length===0||!e||e.values.length===0)return-1;const t=e.values[0];return!t||t.length===0?-1:Number(t[0])},close(){n.close()}});export{h as createSqlJsAdapter};
package/dist/index.d.mts CHANGED
@@ -1,9 +1,24 @@
1
- export { createBetterSqlite3Adapter } from "./adapters/better-sqlite3.mjs";
1
+ export {
2
+ /**
3
+ * \@lunora/replica — Event sourcing runtime + local SQLite mirror for Lunora
4
+ *
5
+ * ## Modules
6
+ *
7
+ * - **EventEmitter** — type-safe event emitter with typed + wildcard listeners.
8
+ * - **EventSource** — event-sourcing runtime that derives state from an
9
+ * append-only log via a reducer.
10
+ * - **SubscriptionManager** — manages state and event-type subscriptions.
11
+ * - **SnapshotStore** — interface + in-memory store for persisting
12
+ * event-sourced state snapshots.
13
+ * - **LocalMirror** — local SQLite mirror that applies typed table diffs.
14
+ * - **EventLog** — append-only log for events and catch-up replication.
15
+ */
16
+ createBetterSqlite3Adapter } from "./adapters/better-sqlite3.mjs";
2
17
  export { createSqliteWasmAdapter } from "./adapters/sqlite-wasm.mjs";
3
18
  export { createSqlJsAdapter } from "./adapters/sqljs.mjs";
4
19
  import { S as SqliteAdapter } from "./packem_shared/types.d-CkMkSwLJ.mjs";
5
- import { T as TableDiff, I as InputEvent, S as Seq, E as EventLogEntry, a as EventLog, A as AppendOptions, L as LocalMirror } from "./packem_shared/local-mirror.d-DTavX_y0.mjs";
6
- export { type C as ClientSeq, type b as EventLogOptions, type c as EventLogSnapshot, type G as GlobalSeq, type d as LocalMirrorOptions, type M as MirrorTableDef, type R as RowChange, e as classifyChanges, f as createTableDiff, g as diffSize, i as isClientSeq, h as isDiffEmpty, j as isGlobalSeq, k as isInputEvent, m as mergeDiffs } from "./packem_shared/local-mirror.d-DTavX_y0.mjs";
20
+ import { T as TableDiff, I as InputEvent, S as Seq, E as EventLogEntry, a as EventLog, A as AppendOptions, L as LocalMirror } from "./packem_shared/local-mirror.d-Cip3QuMf.mjs";
21
+ export { type C as ClientSeq, type b as EventLogOptions, type c as EventLogSnapshot, type G as GlobalSeq, type d as LocalMirrorOptions, type M as MirrorTableDef, type R as RowChange, e as classifyChanges, f as createTableDiff, g as diffSize, i as isClientSeq, h as isDiffEmpty, j as isGlobalSeq, k as isInputEvent, m as mergeDiffs } from "./packem_shared/local-mirror.d-Cip3QuMf.mjs";
7
22
  /**
8
23
  * Apply a single {@link TableDiff} to an in-memory row map and return
9
24
  * the updated map.
@@ -30,15 +45,16 @@ declare const applyDiff: (current: ReadonlyMap<string, Record<string, unknown>>,
30
45
  /**
31
46
  * Apply an array of diffs **in order**, returning the final row map.
32
47
  *
33
- * This is equivalent to calling {@link applyDiff} repeatedly but avoids
34
- * intermediate map copies.
48
+ * This is equivalent to calling {@link applyDiff} repeatedly but copies the
49
+ * input map exactly once rather than once per diff — catch-up replay of an
50
+ * N-diff backlog is a single copy, not N+1.
35
51
  * @experimental
36
52
  */
37
53
  declare const applyDiffs: (current: ReadonlyMap<string, Record<string, unknown>>, diffs: ReadonlyArray<TableDiff>) => Map<string, Record<string, unknown>>;
38
54
  /**
39
55
  * Merge the row-level effect of a {@link TableDiff} into plain JSON
40
56
  * state keyed by table name, returning a new snapshot.
41
- * @param snapshot Current snapshot, e.g. `{ users: Map&lt;id, row>, posts: Map&lt;id, row> }`.
57
+ * @param snapshot Current snapshot, e.g. `{ users: Map<id, row>, posts: Map<id, row> }`.
42
58
  * @param diff Contains the target table name and the row-level changes to merge.
43
59
  * @returns A shallow copy of `snapshot` with `diff.table`'s map updated.
44
60
  * @experimental
@@ -105,7 +121,7 @@ interface DefineEventsOptions {
105
121
  /**
106
122
  * Optional version prefix for all event types.
107
123
  *
108
- * When set, every qualified event type is prefixed with `"v&lt;N>."`, enabling
124
+ * When set, every qualified event type is prefixed with `"v<N>."`, enabling
109
125
  * versioned event naming like `"v1.chat.messageSent"` or `"v2.chat.messageSent"`.
110
126
  * This allows materializers to evolve their handling logic based on the event
111
127
  * version without breaking backward compatibility.
@@ -271,8 +287,8 @@ type UnknownEventHandling = "warn" | "ignore" | "fail" | ((entry: EventLogEntry)
271
287
  * Events emitted by the {@link EventSource} runtime.
272
288
  *
273
289
  * A `type` (not `interface`) so it satisfies `EventEmitter`'s
274
- * `Record&lt;string, unknown>` constraint — interfaces have no implicit index
275
- * signature and aren't assignable to `Record&lt;string, unknown>`.
290
+ * `Record<string, unknown>` constraint — interfaces have no implicit index
291
+ * signature and aren't assignable to `Record<string, unknown>`.
276
292
  * @experimental
277
293
  */
278
294
  type EventSourceEvents = {
@@ -408,8 +424,10 @@ declare class EventSource<S extends Record<string, unknown> = Record<string, unk
408
424
  * starting from the events currently in the log and continuing with
409
425
  * every future `applyEvent` / `replayFromLog` call.
410
426
  *
411
- * The generator runs indefinitely it never returns. Callers should
412
- * break out of the `for await` loop or use an `AbortSignal` to stop.
427
+ * The generator runs indefinitely unless given a `signal` callers
428
+ * should break out of the `for await` loop or pass an `AbortSignal` to
429
+ * stop it (an abort settles the generator, `done: true`, on its next
430
+ * iteration step; it does not throw).
413
431
  * @example
414
432
  * ```ts
415
433
  * for await (const entry of source.events()) {
@@ -506,9 +524,9 @@ declare const defineMaterializer: <S>(definition: MaterializerDef<S>) => Materia
506
524
  * A materializer of any state shape. The {@link MaterializerRuntime} holds a
507
525
  * heterogeneous collection and only ever calls `apply(entry)` / `setState(...)`
508
526
  * (with cast values) / reads `def.name` — it never needs the concrete state
509
- * type. `Materializer&lt;unknown>` won't do: `setState(state: S)` makes
510
- * `Materializer&lt;S>` invariant in `S`, so `Materializer&lt;number>` isn't assignable
511
- * to `Materializer&lt;unknown>`. Erasing the type param is the idiomatic fix.
527
+ * type. `Materializer<unknown>` won't do: `setState(state: S)` makes
528
+ * `Materializer<S>` invariant in `S`, so `Materializer<number>` isn't assignable
529
+ * to `Materializer<unknown>`. Erasing the type param is the idiomatic fix.
512
530
  */
513
531
  type AnyMaterializer = Materializer<any>;
514
532
  /**
@@ -895,8 +913,17 @@ interface EventsSyncOptions {
895
913
  * Produce {@link TableDiff | TableDiffs} from the current derived state.
896
914
  *
897
915
  * Called after every batch of events has been applied. The consumer
898
- * compares the state _before_ and _after_ the batch and returns the
899
- * diffs needed to bring the LocalMirror up to date.
916
+ * **recomputes a full diff from the current mirror-vs-source state** and
917
+ * returns the diffs needed to bring the LocalMirror up to date.
918
+ *
919
+ * **MUST be idempotent** — it must NOT advance a one-shot cursor as a side
920
+ * effect. A batch that fails partway (a `mirror.applyDiff` throws) is
921
+ * retried on the next poll from the same watermark; if this call consumed a
922
+ * cursor on the first attempt it would return `[]` on the retry and the
923
+ * un-mirrored diffs would be lost forever. Recompute-from-current-state has
924
+ * no such hazard: calling it again with no new events returns the same
925
+ * diffs, and calling it after a partial mirror write returns exactly the
926
+ * diffs still missing from the mirror.
900
927
  *
901
928
  * Return an empty array when there are no changes to push to the mirror.
902
929
  */
package/dist/index.d.ts CHANGED
@@ -1,9 +1,24 @@
1
- export { createBetterSqlite3Adapter } from "./adapters/better-sqlite3.js";
1
+ export {
2
+ /**
3
+ * \@lunora/replica — Event sourcing runtime + local SQLite mirror for Lunora
4
+ *
5
+ * ## Modules
6
+ *
7
+ * - **EventEmitter** — type-safe event emitter with typed + wildcard listeners.
8
+ * - **EventSource** — event-sourcing runtime that derives state from an
9
+ * append-only log via a reducer.
10
+ * - **SubscriptionManager** — manages state and event-type subscriptions.
11
+ * - **SnapshotStore** — interface + in-memory store for persisting
12
+ * event-sourced state snapshots.
13
+ * - **LocalMirror** — local SQLite mirror that applies typed table diffs.
14
+ * - **EventLog** — append-only log for events and catch-up replication.
15
+ */
16
+ createBetterSqlite3Adapter } from "./adapters/better-sqlite3.js";
2
17
  export { createSqliteWasmAdapter } from "./adapters/sqlite-wasm.js";
3
18
  export { createSqlJsAdapter } from "./adapters/sqljs.js";
4
19
  import { S as SqliteAdapter } from "./packem_shared/types.d-CkMkSwLJ.js";
5
- import { T as TableDiff, I as InputEvent, S as Seq, E as EventLogEntry, a as EventLog, A as AppendOptions, L as LocalMirror } from "./packem_shared/local-mirror.d-CyGOpUES.js";
6
- export { type C as ClientSeq, type b as EventLogOptions, type c as EventLogSnapshot, type G as GlobalSeq, type d as LocalMirrorOptions, type M as MirrorTableDef, type R as RowChange, e as classifyChanges, f as createTableDiff, g as diffSize, i as isClientSeq, h as isDiffEmpty, j as isGlobalSeq, k as isInputEvent, m as mergeDiffs } from "./packem_shared/local-mirror.d-CyGOpUES.js";
20
+ import { T as TableDiff, I as InputEvent, S as Seq, E as EventLogEntry, a as EventLog, A as AppendOptions, L as LocalMirror } from "./packem_shared/local-mirror.d-ByrYTq4z.js";
21
+ export { type C as ClientSeq, type b as EventLogOptions, type c as EventLogSnapshot, type G as GlobalSeq, type d as LocalMirrorOptions, type M as MirrorTableDef, type R as RowChange, e as classifyChanges, f as createTableDiff, g as diffSize, i as isClientSeq, h as isDiffEmpty, j as isGlobalSeq, k as isInputEvent, m as mergeDiffs } from "./packem_shared/local-mirror.d-ByrYTq4z.js";
7
22
  /**
8
23
  * Apply a single {@link TableDiff} to an in-memory row map and return
9
24
  * the updated map.
@@ -30,15 +45,16 @@ declare const applyDiff: (current: ReadonlyMap<string, Record<string, unknown>>,
30
45
  /**
31
46
  * Apply an array of diffs **in order**, returning the final row map.
32
47
  *
33
- * This is equivalent to calling {@link applyDiff} repeatedly but avoids
34
- * intermediate map copies.
48
+ * This is equivalent to calling {@link applyDiff} repeatedly but copies the
49
+ * input map exactly once rather than once per diff — catch-up replay of an
50
+ * N-diff backlog is a single copy, not N+1.
35
51
  * @experimental
36
52
  */
37
53
  declare const applyDiffs: (current: ReadonlyMap<string, Record<string, unknown>>, diffs: ReadonlyArray<TableDiff>) => Map<string, Record<string, unknown>>;
38
54
  /**
39
55
  * Merge the row-level effect of a {@link TableDiff} into plain JSON
40
56
  * state keyed by table name, returning a new snapshot.
41
- * @param snapshot Current snapshot, e.g. `{ users: Map&lt;id, row>, posts: Map&lt;id, row> }`.
57
+ * @param snapshot Current snapshot, e.g. `{ users: Map<id, row>, posts: Map<id, row> }`.
42
58
  * @param diff Contains the target table name and the row-level changes to merge.
43
59
  * @returns A shallow copy of `snapshot` with `diff.table`'s map updated.
44
60
  * @experimental
@@ -105,7 +121,7 @@ interface DefineEventsOptions {
105
121
  /**
106
122
  * Optional version prefix for all event types.
107
123
  *
108
- * When set, every qualified event type is prefixed with `"v&lt;N>."`, enabling
124
+ * When set, every qualified event type is prefixed with `"v<N>."`, enabling
109
125
  * versioned event naming like `"v1.chat.messageSent"` or `"v2.chat.messageSent"`.
110
126
  * This allows materializers to evolve their handling logic based on the event
111
127
  * version without breaking backward compatibility.
@@ -271,8 +287,8 @@ type UnknownEventHandling = "warn" | "ignore" | "fail" | ((entry: EventLogEntry)
271
287
  * Events emitted by the {@link EventSource} runtime.
272
288
  *
273
289
  * A `type` (not `interface`) so it satisfies `EventEmitter`'s
274
- * `Record&lt;string, unknown>` constraint — interfaces have no implicit index
275
- * signature and aren't assignable to `Record&lt;string, unknown>`.
290
+ * `Record<string, unknown>` constraint — interfaces have no implicit index
291
+ * signature and aren't assignable to `Record<string, unknown>`.
276
292
  * @experimental
277
293
  */
278
294
  type EventSourceEvents = {
@@ -408,8 +424,10 @@ declare class EventSource<S extends Record<string, unknown> = Record<string, unk
408
424
  * starting from the events currently in the log and continuing with
409
425
  * every future `applyEvent` / `replayFromLog` call.
410
426
  *
411
- * The generator runs indefinitely it never returns. Callers should
412
- * break out of the `for await` loop or use an `AbortSignal` to stop.
427
+ * The generator runs indefinitely unless given a `signal` callers
428
+ * should break out of the `for await` loop or pass an `AbortSignal` to
429
+ * stop it (an abort settles the generator, `done: true`, on its next
430
+ * iteration step; it does not throw).
413
431
  * @example
414
432
  * ```ts
415
433
  * for await (const entry of source.events()) {
@@ -506,9 +524,9 @@ declare const defineMaterializer: <S>(definition: MaterializerDef<S>) => Materia
506
524
  * A materializer of any state shape. The {@link MaterializerRuntime} holds a
507
525
  * heterogeneous collection and only ever calls `apply(entry)` / `setState(...)`
508
526
  * (with cast values) / reads `def.name` — it never needs the concrete state
509
- * type. `Materializer&lt;unknown>` won't do: `setState(state: S)` makes
510
- * `Materializer&lt;S>` invariant in `S`, so `Materializer&lt;number>` isn't assignable
511
- * to `Materializer&lt;unknown>`. Erasing the type param is the idiomatic fix.
527
+ * type. `Materializer<unknown>` won't do: `setState(state: S)` makes
528
+ * `Materializer<S>` invariant in `S`, so `Materializer<number>` isn't assignable
529
+ * to `Materializer<unknown>`. Erasing the type param is the idiomatic fix.
512
530
  */
513
531
  type AnyMaterializer = Materializer<any>;
514
532
  /**
@@ -895,8 +913,17 @@ interface EventsSyncOptions {
895
913
  * Produce {@link TableDiff | TableDiffs} from the current derived state.
896
914
  *
897
915
  * Called after every batch of events has been applied. The consumer
898
- * compares the state _before_ and _after_ the batch and returns the
899
- * diffs needed to bring the LocalMirror up to date.
916
+ * **recomputes a full diff from the current mirror-vs-source state** and
917
+ * returns the diffs needed to bring the LocalMirror up to date.
918
+ *
919
+ * **MUST be idempotent** — it must NOT advance a one-shot cursor as a side
920
+ * effect. A batch that fails partway (a `mirror.applyDiff` throws) is
921
+ * retried on the next poll from the same watermark; if this call consumed a
922
+ * cursor on the first attempt it would return `[]` on the retry and the
923
+ * un-mirrored diffs would be lost forever. Recompute-from-current-state has
924
+ * no such hazard: calling it again with no new events returns the same
925
+ * diffs, and calling it after a partial mirror write returns exactly the
926
+ * diffs still missing from the mirror.
900
927
  *
901
928
  * Return an empty array when there are no changes to push to the mirror.
902
929
  */
package/dist/index.mjs CHANGED
@@ -1,20 +1 @@
1
- export { createBetterSqlite3Adapter } from './adapters/better-sqlite3.mjs';
2
- export { createSqliteWasmAdapter } from './adapters/sqlite-wasm.mjs';
3
- export { createSqlJsAdapter } from './adapters/sqljs.mjs';
4
- export { applyDiff, applyDiffToSnapshot, applyDiffs } from './packem_shared/applyDiff-98tKzmiW.mjs';
5
- export { defineEvents } from './packem_shared/defineEvents-DiBkPTh_.mjs';
6
- export { MaterializerRuntime, defineMaterializer } from './packem_shared/MaterializerRuntime-BoIrsMYB.mjs';
7
- export { applyDiffToDb, applyDiffsToDb } from './packem_shared/applyDiffToDb-DQ1xZp5J.mjs';
8
- export { EventEmitter } from './packem_shared/EventEmitter-CMZfct03.mjs';
9
- export { EventLog } from './packem_shared/EventLog-CnK-3Wge.mjs';
10
- export { EventLogDO } from './packem_shared/EventLogDO-DqlsVx0H.mjs';
11
- export { EventLogDOClient } from './packem_shared/EventLogDOClient-F4FO8Si4.mjs';
12
- export { EventSource, UNHANDLED } from './packem_shared/EventSource-D5yO9_aI.mjs';
13
- export { eventsContext } from './packem_shared/eventsContext-Bk_p48hj.mjs';
14
- export { LocalMirror } from './packem_shared/LocalMirror-a-5jEqFN.mjs';
15
- export { isClientSeq, isGlobalSeq, isInputEvent } from './packem_shared/isClientSeq-C46BkzqJ.mjs';
16
- export { InMemorySnapshotStore } from './packem_shared/InMemorySnapshotStore-BHVAD-Bp.mjs';
17
- export { subscribeToMirror } from './packem_shared/subscribeToMirror-CiaM-nQ7.mjs';
18
- export { SubscriptionManager } from './packem_shared/SubscriptionManager-C5xbw0pg.mjs';
19
- export { EventsSync } from './packem_shared/EventsSync-BP36tC9O.mjs';
20
- export { classifyChanges, createTableDiff, diffSize, isDiffEmpty, mergeDiffs } from './packem_shared/classifyChanges-RcqLBpLs.mjs';
1
+ import{createBetterSqlite3Adapter as o}from"./adapters/better-sqlite3.mjs";import{createSqliteWasmAdapter as f}from"./adapters/sqlite-wasm.mjs";import{createSqlJsAdapter as i}from"./adapters/sqljs.mjs";import{applyDiff as m,applyDiffToSnapshot as n,applyDiffs as x}from"./packem_shared/applyDiff-Da160K7_.mjs";import{defineEvents as l}from"./packem_shared/defineEvents-DHo-VK7G.mjs";import{MaterializerRuntime as S,defineMaterializer as E}from"./packem_shared/MaterializerRuntime-D0HOAe24.mjs";import{applyDiffToDb as v,applyDiffsToDb as y}from"./packem_shared/applyDiffToDb-C6ek5Elp.mjs";import{EventEmitter as d}from"./packem_shared/EventEmitter-uo75adUL.mjs";import{EventLog as M}from"./packem_shared/EventLog-B1-yhArT.mjs";import{EventLogDO as u}from"./packem_shared/EventLogDO-CaZvpgJN.mjs";import{EventLogDOClient as T}from"./packem_shared/EventLogDOClient-DGDMj5L5.mjs";import{EventSource as C,UNHANDLED as h}from"./packem_shared/EventSource-BC0hKJSA.mjs";import{eventsContext as I}from"./packem_shared/eventsContext-Dxow9Y7S.mjs";import{LocalMirror as O}from"./packem_shared/LocalMirror-BIURA-He.mjs";import{isClientSeq as G,isGlobalSeq as H,isInputEvent as J}from"./packem_shared/isClientSeq-D2Xm0_lj.mjs";import{InMemorySnapshotStore as U}from"./packem_shared/InMemorySnapshotStore-C4taIG5K.mjs";import{subscribeToMirror as j}from"./packem_shared/subscribeToMirror-CX10AaP3.mjs";import{SubscriptionManager as w}from"./packem_shared/SubscriptionManager-AhPw3lFc.mjs";import{EventsSync as K}from"./packem_shared/EventsSync-DWyGGZQZ.mjs";import{classifyChanges as Q,createTableDiff as V,diffSize as X,isDiffEmpty as Y,mergeDiffs as Z}from"./packem_shared/classifyChanges-ioMfjjbU.mjs";export{d as EventEmitter,M as EventLog,u as EventLogDO,T as EventLogDOClient,C as EventSource,K as EventsSync,U as InMemorySnapshotStore,O as LocalMirror,S as MaterializerRuntime,w as SubscriptionManager,h as UNHANDLED,m as applyDiff,v as applyDiffToDb,n as applyDiffToSnapshot,x as applyDiffs,y as applyDiffsToDb,Q as classifyChanges,o as createBetterSqlite3Adapter,i as createSqlJsAdapter,f as createSqliteWasmAdapter,V as createTableDiff,l as defineEvents,E as defineMaterializer,X as diffSize,I as eventsContext,G as isClientSeq,Y as isDiffEmpty,H as isGlobalSeq,J as isInputEvent,Z as mergeDiffs,j as subscribeToMirror};