@lunora/replica 0.0.0 → 1.0.0-alpha.11

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 (39) hide show
  1. package/LICENSE.md +445 -0
  2. package/README.md +194 -29
  3. package/dist/adapters/better-sqlite3.d.mts +28 -0
  4. package/dist/adapters/better-sqlite3.d.ts +28 -0
  5. package/dist/adapters/better-sqlite3.mjs +1 -0
  6. package/dist/adapters/sqlite-wasm.d.mts +36 -0
  7. package/dist/adapters/sqlite-wasm.d.ts +36 -0
  8. package/dist/adapters/sqlite-wasm.mjs +1 -0
  9. package/dist/adapters/sqljs.d.mts +20 -0
  10. package/dist/adapters/sqljs.d.ts +20 -0
  11. package/dist/adapters/sqljs.mjs +1 -0
  12. package/dist/index.d.mts +971 -0
  13. package/dist/index.d.ts +971 -0
  14. package/dist/index.mjs +1 -0
  15. package/dist/packem_shared/EventEmitter-ovTsLeAj.mjs +1 -0
  16. package/dist/packem_shared/EventLog-DmlRY_4Z.mjs +1 -0
  17. package/dist/packem_shared/EventLogDO-Cb-7iN9w.mjs +1 -0
  18. package/dist/packem_shared/EventLogDOClient-C6gA3b3u.mjs +1 -0
  19. package/dist/packem_shared/EventSource-B5UTlkl9.mjs +1 -0
  20. package/dist/packem_shared/EventsSync-pK_hg9KP.mjs +1 -0
  21. package/dist/packem_shared/InMemorySnapshotStore-C4taIG5K.mjs +1 -0
  22. package/dist/packem_shared/LocalMirror-Q7cPH_rX.mjs +4 -0
  23. package/dist/packem_shared/MaterializerRuntime-B-I9jKDe.mjs +1 -0
  24. package/dist/packem_shared/SubscriptionManager-CbSjG_GA.mjs +1 -0
  25. package/dist/packem_shared/applyDiff-BUzddc6r.mjs +1 -0
  26. package/dist/packem_shared/applyDiffToDb-1M2I3BHi.mjs +1 -0
  27. package/dist/packem_shared/classifyChanges-BnOMcDGj.mjs +1 -0
  28. package/dist/packem_shared/defineEvents-CJZV8Bgi.mjs +1 -0
  29. package/dist/packem_shared/eventsContext-Dxow9Y7S.mjs +1 -0
  30. package/dist/packem_shared/isClientSeq-DSXBJskD.mjs +1 -0
  31. package/dist/packem_shared/local-mirror.d-CyGOpUES.d.ts +530 -0
  32. package/dist/packem_shared/local-mirror.d-DTavX_y0.d.mts +530 -0
  33. package/dist/packem_shared/subscribeToMirror-Dru_AYBu.mjs +1 -0
  34. package/dist/packem_shared/types.d-CkMkSwLJ.d.mts +24 -0
  35. package/dist/packem_shared/types.d-CkMkSwLJ.d.ts +24 -0
  36. package/dist/react.d.mts +67 -0
  37. package/dist/react.d.ts +67 -0
  38. package/dist/react.mjs +1 -0
  39. package/package.json +88 -7
@@ -0,0 +1,67 @@
1
+ import { L as LocalMirror } from "./packem_shared/local-mirror.d-CyGOpUES.js";
2
+ import "./packem_shared/types.d-CkMkSwLJ.js";
3
+ /**
4
+ * Options for the {@link useLocalQuery} hook.
5
+ * @experimental
6
+ */
7
+ interface UseLocalQueryOptions {
8
+ /**
9
+ * Optional shard key (reserved for future use; currently unused).
10
+ *
11
+ * Intended for multi-mirror setups where a single app maintains multiple
12
+ * SQLite databases sharded by a key (e.g. user id, tenant id). Currently
13
+ * has no effect — the hook always queries the mirror passed as the first
14
+ * argument.
15
+ */
16
+ shardKey?: string;
17
+ }
18
+ /**
19
+ * React hook that subscribes to a local SQLite query and returns
20
+ * live-updating results whenever the mirror applies a diff.
21
+ *
22
+ * Uses `useSyncExternalStore` to subscribe to the mirror's `onChange`
23
+ * callback — every diff triggers a re-query against the local SQLite.
24
+ *
25
+ * The hook works with React 18+ concurrent features, Suspense, and
26
+ * server-side rendering. During SSR the same value is returned as on
27
+ * the client (the mirror's current state at render time).
28
+ * @param mirror The {@link LocalMirror} instance to query. Must have been
29
+ * constructed with an {@link import("./adapters/types").SqliteAdapter}.
30
+ * @param sql Parameterised SQL query string. Use `?` placeholders for
31
+ * bound parameters (the adapter forwards them to the underlying SQLite
32
+ * engine without rewriting).
33
+ * @param params Optional positional bound parameters matching `?`
34
+ * placeholders in `sql`.
35
+ * @param _options Optional configuration (currently unused; reserved for
36
+ * future features like shard key routing).
37
+ * @returns An array of result rows typed via the generic parameter `T`, or
38
+ * `undefined` if the query fails (e.g. the target table doesn't exist yet
39
+ * because no matching diff has been applied). Treat `undefined` as a
40
+ * "loading" or "no data yet" signal in your component.
41
+ *
42
+ * **Error handling**: The hook catches SQL errors internally and returns
43
+ * `undefined`. Use a try-catch around `mirror.query(...)` directly if you
44
+ * need finer-grained error diagnostics.
45
+ * @example
46
+ * ```tsx
47
+ * import { useLocalQuery } from "@lunora/replica/react";
48
+ * import { mirror } from "./mirror";
49
+ *
50
+ * function UserList() {
51
+ * const users = useLocalQuery<{ id: string; name: string }>(
52
+ * mirror,
53
+ * "SELECT id, name FROM fn_todos_list WHERE name LIKE ?",
54
+ * ["%alice%"],
55
+ * );
56
+ *
57
+ * if (users === undefined) {
58
+ * return <p>Waiting for data…</p>;
59
+ * }
60
+ *
61
+ * return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
62
+ * }
63
+ * ```
64
+ * @experimental
65
+ */
66
+ declare const useLocalQuery: <T = Record<string, unknown>>(mirror: LocalMirror, sql: string, params?: ReadonlyArray<unknown>, _options?: UseLocalQueryOptions) => T[] | undefined;
67
+ export { UseLocalQueryOptions, useLocalQuery };
package/dist/react.mjs ADDED
@@ -0,0 +1 @@
1
+ import{useSyncExternalStore as t}from"react";const c=(r,e,n,s)=>{t(o=>r.onChange(o),()=>r.version,()=>r.version);try{return r.query(e,n)}catch{return}};export{c as useLocalQuery};
package/package.json CHANGED
@@ -1,10 +1,91 @@
1
1
  {
2
2
  "name": "@lunora/replica",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @lunora/replica",
3
+ "version": "1.0.0-alpha.11",
4
+ "description": "Local-first replica runtime + local SQLite mirror for Lunora",
5
5
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
6
+ "cloudflare",
7
+ "durable-objects",
8
+ "event-sourcing",
9
+ "local-first",
10
+ "lunora",
11
+ "replica",
12
+ "sqlite",
13
+ "sync",
14
+ "workers"
15
+ ],
16
+ "homepage": "https://lunora.sh",
17
+ "bugs": "https://github.com/anolilab/lunora/issues",
18
+ "license": "FSL-1.1-Apache-2.0",
19
+ "author": {
20
+ "name": "Daniel Bannert",
21
+ "email": "d.bannert@anolilab.de"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/anolilab/lunora.git",
26
+ "directory": "packages/replica"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE.md"
32
+ ],
33
+ "type": "module",
34
+ "sideEffects": false,
35
+ "main": "./dist/index.mjs",
36
+ "module": "./dist/index.mjs",
37
+ "types": "./dist/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "import": "./dist/index.mjs"
42
+ },
43
+ "./react": {
44
+ "types": "./dist/react.d.ts",
45
+ "import": "./dist/react.mjs"
46
+ },
47
+ "./adapters/sqljs": {
48
+ "types": "./dist/adapters/sqljs.d.ts",
49
+ "import": "./dist/adapters/sqljs.mjs"
50
+ },
51
+ "./adapters/better-sqlite3": {
52
+ "types": "./dist/adapters/better-sqlite3.d.ts",
53
+ "import": "./dist/adapters/better-sqlite3.mjs"
54
+ },
55
+ "./adapters/sqlite-wasm": {
56
+ "types": "./dist/adapters/sqlite-wasm.d.ts",
57
+ "import": "./dist/adapters/sqlite-wasm.mjs"
58
+ },
59
+ "./package.json": "./package.json"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "peerDependencies": {
65
+ "@lunora/server": ">=1.0.0-alpha.24 <2.0.0-0",
66
+ "@sqlite.org/sqlite-wasm": "*",
67
+ "better-sqlite3": "*",
68
+ "react": "^18.0.0 || ^19.0.0",
69
+ "sql.js": "^1.0.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@lunora/server": {
73
+ "optional": true
74
+ },
75
+ "@sqlite.org/sqlite-wasm": {
76
+ "optional": true
77
+ },
78
+ "better-sqlite3": {
79
+ "optional": true
80
+ },
81
+ "react": {
82
+ "optional": true
83
+ },
84
+ "sql.js": {
85
+ "optional": true
86
+ }
87
+ },
88
+ "engines": {
89
+ "node": "^22.15.0 || >=24.11.0"
90
+ }
91
+ }