@lunora/cli 1.0.0-alpha.21 → 1.0.0-alpha.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +33 -0
- package/README.md +1 -1
- package/__assets__/package-og.svg +1 -1
- package/dist/bin.mjs +2 -10
- package/dist/index.d.mts +731 -341
- package/dist/index.d.ts +731 -341
- package/dist/index.mjs +1 -19
- package/dist/packem_chunks/handler.mjs +1 -150
- package/dist/packem_chunks/handler10.mjs +4 -22
- package/dist/packem_chunks/handler11.mjs +2 -192
- package/dist/packem_chunks/handler12.mjs +1 -131
- package/dist/packem_chunks/handler13.mjs +1 -65
- package/dist/packem_chunks/handler14.mjs +1 -58
- package/dist/packem_chunks/handler15.mjs +1 -79
- package/dist/packem_chunks/handler16.mjs +3 -43
- package/dist/packem_chunks/handler17.mjs +1 -105
- package/dist/packem_chunks/handler18.mjs +1 -170
- package/dist/packem_chunks/handler19.mjs +7 -89
- package/dist/packem_chunks/handler2.mjs +2 -114
- package/dist/packem_chunks/handler20.mjs +1 -94
- package/dist/packem_chunks/handler21.mjs +2 -311
- package/dist/packem_chunks/handler22.mjs +3 -0
- package/dist/packem_chunks/handler23.mjs +3 -0
- package/dist/packem_chunks/handler24.mjs +1 -0
- package/dist/packem_chunks/handler25.mjs +99 -0
- package/dist/packem_chunks/handler26.mjs +10 -0
- package/dist/packem_chunks/handler3.mjs +1 -204
- package/dist/packem_chunks/handler4.mjs +1 -33
- package/dist/packem_chunks/handler5.mjs +1 -49
- package/dist/packem_chunks/handler6.mjs +1 -91
- package/dist/packem_chunks/handler7.mjs +3 -42
- package/dist/packem_chunks/handler8.mjs +1 -174
- package/dist/packem_chunks/handler9.mjs +1 -16
- package/dist/packem_chunks/planDevCommand.mjs +7 -500
- package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
- package/dist/packem_chunks/runDeployCommand.mjs +1 -504
- package/dist/packem_chunks/runInitCommand.mjs +118 -1383
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +9 -395
- package/dist/packem_chunks/runResetCommand.mjs +1 -41
- package/dist/packem_chunks/runRpcCommand.mjs +1 -68
- package/dist/packem_shared/COMMANDS-BKhYrmpZ.mjs +1 -0
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Nf7GsE6v.mjs +1 -0
- package/dist/packem_shared/admin-token-rxXZbVMZ.mjs +1 -0
- package/dist/packem_shared/admin-url-Cil3Or6N.mjs +1 -0
- package/dist/packem_shared/advisory-gate-Cl8IEFIj.mjs +1 -0
- package/dist/packem_shared/api-spec-lYyq4vL6.mjs +1 -0
- package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
- package/dist/packem_shared/buildRegistryIndex-Zi3bBqpc.mjs +1 -0
- package/dist/packem_shared/cli-CrC0a7dH.mjs +3 -0
- package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
- package/dist/packem_shared/command-DwC11Cwe.mjs +1 -0
- package/dist/packem_shared/commands-BNKj7r1R.mjs +19 -0
- package/dist/packem_shared/createLogger-hGafwf-3.mjs +2 -0
- package/dist/packem_shared/createRecordingSpawner-DJlNacZ6.mjs +1 -0
- package/dist/packem_shared/deploy-target-D9GPy_tq.mjs +1 -0
- package/dist/packem_shared/diffSnapshots-CIOFQN_a.mjs +5 -0
- package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
- package/dist/packem_shared/import-CrVGrOt3.mjs +12 -0
- package/dist/packem_shared/insertSchemaExtension-DY4pA8wE.mjs +8 -0
- package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
- package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
- package/dist/packem_shared/output-format-DfogXx0p.mjs +2 -0
- package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
- package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
- package/dist/packem_shared/platform-diagnostics-uOXqysk3.mjs +4 -0
- package/dist/packem_shared/prompt-cancelled-C8Sj7OqI.mjs +1 -0
- package/dist/packem_shared/resolve-DZAGzg67.mjs +1 -0
- package/dist/packem_shared/resolve-target-BRvw8Pf7.mjs +1 -0
- package/dist/packem_shared/runAddCommand-D1Dj8-pK.mjs +1 -0
- package/dist/packem_shared/runExportCommand-DmXKEWSq.mjs +5 -0
- package/dist/packem_shared/schema-drift-gate-DARCKocg.mjs +1 -0
- package/dist/packem_shared/schemaIrToSnapshot-qpRoV7HY.mjs +1 -0
- package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
- package/dist/packem_shared/storage-wIUel5Az.mjs +1 -0
- package/dist/packem_shared/tui-prompts-Dd0pDuNr.mjs +4 -0
- package/dist/packem_shared/vectorize-metadata-DbziRKpX.mjs +1 -0
- package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
- package/dist/packem_shared/wrangler-secrets-CCdt0mUl.mjs +1 -0
- package/package.json +39 -17
- package/skills/README.md +35 -17
- package/skills/lunora/SKILL.md +65 -9
- package/skills/lunora-functions/SKILL.md +38 -3
- package/skills/lunora-migration-helper/SKILL.md +70 -17
- package/skills/lunora-performance-audit/SKILL.md +36 -6
- package/skills/lunora-quickstart/SKILL.md +90 -24
- package/skills/lunora-realtime/SKILL.md +58 -30
- package/dist/packem_shared/COMMANDS-D3h9Iwvl.mjs +0 -944
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
- package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
- package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
- package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
- package/dist/packem_shared/command-BC30oSBW.mjs +0 -14
- package/dist/packem_shared/commands-hl0mRqqg.mjs +0 -845
- package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
- package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
- package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
- package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
- package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
- package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
- package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
- package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
- package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
- package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
- package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
- package/dist/packem_shared/runAddCommand-vJdgiR5t.mjs +0 -4
- package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
- package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
- package/dist/packem_shared/storage-B7hHSTZP.mjs +0 -84
- package/dist/packem_shared/tui-prompts-M6OWsuyw.mjs +0 -663
- package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
|
@@ -31,9 +31,12 @@ Set up a working Lunora project as fast as possible.
|
|
|
31
31
|
Lunora into the current project.
|
|
32
32
|
4. Run `lunora codegen` to generate `lunora/_generated/` and typecheck the
|
|
33
33
|
schema + functions. This is the agent's feedback loop.
|
|
34
|
-
5. Start the dev loop
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
5. Start the dev loop. As an agent, run `lunora dev --background` — it starts
|
|
35
|
+
the server as a managed detached process, blocks until it accepts requests,
|
|
36
|
+
prints the URL + PID, and returns (under a detected AI agent, plain
|
|
37
|
+
`lunora dev` does this automatically, with JSON logs). Never leave a bare
|
|
38
|
+
`lunora dev` running in your own shell — it is long-running and does not
|
|
39
|
+
exit.
|
|
37
40
|
6. Verify a query/mutation round-trip works end to end.
|
|
38
41
|
|
|
39
42
|
## Path 1: New Project (Recommended)
|
|
@@ -42,27 +45,69 @@ Set up a working Lunora project as fast as possible.
|
|
|
42
45
|
plugin + `lunora/` already wired together).
|
|
43
46
|
|
|
44
47
|
```bash
|
|
45
|
-
lunora init my-app --
|
|
48
|
+
lunora init my-app --vite react
|
|
46
49
|
cd my-app
|
|
47
50
|
pnpm install
|
|
48
51
|
```
|
|
49
52
|
|
|
50
|
-
### Pick a template
|
|
53
|
+
### Pick a stack: `--vite` (SPA) or `-t` (bespoke template)
|
|
54
|
+
|
|
55
|
+
There are **two scaffold paths**, and they take different flags:
|
|
56
|
+
|
|
57
|
+
**`--vite <framework>` — the create-vite overlay.** Fetches the official
|
|
58
|
+
create-vite base and applies the Lunora layer on top. Use it for a plain SPA:
|
|
59
|
+
|
|
60
|
+
| `--vite` value | Stack |
|
|
61
|
+
| -------------- | ----------------------------------------------- |
|
|
62
|
+
| `react` | React SPA (**the default**) |
|
|
63
|
+
| `vue` | Vue SPA |
|
|
64
|
+
| `solid` | Solid SPA |
|
|
65
|
+
| `svelte` | Svelte SPA |
|
|
66
|
+
| `vanilla` | No framework (overlay-only — not in the picker) |
|
|
67
|
+
|
|
68
|
+
**`-t` / `--template <type>` — a bespoke Lunora template.** Whole-project
|
|
69
|
+
templates fetched remotely (via `giget`) from
|
|
70
|
+
`gh:anolilab/lunora/templates/<type>`:
|
|
71
|
+
|
|
72
|
+
| `-t` value | Stack |
|
|
73
|
+
| ---------------------- | ---------------------------------------------------------- |
|
|
74
|
+
| `next` | Next.js (App Router, OpenNext on Cloudflare) |
|
|
75
|
+
| `tanstack-start-react` | TanStack Start (React) — SSR with live-loader routes |
|
|
76
|
+
| `tanstack-start-solid` | TanStack Start (Solid) |
|
|
77
|
+
| `solid-v2` | Solid 2.0 SPA (`@solidjs/web`, `vite-plugin-solid` 3) |
|
|
78
|
+
| `react-router` | React Router v7 (framework mode), SSR in the Lunora worker |
|
|
79
|
+
| `astro` | Astro + a standalone Lunora worker |
|
|
80
|
+
| `analog` | AnalogJS (Angular) — single worker, Lunora in Nitro |
|
|
81
|
+
| `nuxt` | Nuxt (Vue) — single worker, Lunora in Nitro |
|
|
82
|
+
| `sveltekit` | SvelteKit + a standalone Lunora worker |
|
|
83
|
+
| `expo` | React Native (Expo) — iOS/Android/web + a Lunora worker |
|
|
84
|
+
| `standalone` | Worker-only Lunora backend, no frontend |
|
|
85
|
+
|
|
86
|
+
> There is **no `--template vite`.** SPAs go through `--vite <framework>`; `-t`
|
|
87
|
+
> is only for the bespoke templates above. The one exception is `solid-v2`:
|
|
88
|
+
> create-vite's Solid base is still 1.x, and Solid 2.0 needs its own renderer
|
|
89
|
+
> package, `jsxImportSource`, and Vite plugin major — so it ships as a template
|
|
90
|
+
> rather than an overlay. `--vite solid` stays on Solid 1.x.
|
|
91
|
+
|
|
92
|
+
With neither flag, an interactive run shows the framework picker (defaulting to
|
|
93
|
+
the React overlay) and a **non-interactive run errors out** — so as an agent,
|
|
94
|
+
always pass `--vite` or `-t` explicitly. If the user stated no preference,
|
|
95
|
+
use `--vite react`.
|
|
96
|
+
|
|
97
|
+
### Useful `init` flags
|
|
51
98
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
| `sveltekit` | SvelteKit |
|
|
59
|
-
| `tanstack-start-react` | TanStack Start (React) |
|
|
60
|
-
| `tanstack-start-solid` | TanStack Start (Solid) |
|
|
99
|
+
```bash
|
|
100
|
+
lunora init my-app --vite react --ci github # + a GitHub Actions deploy pipeline (or --ci gitlab)
|
|
101
|
+
lunora init my-app -t next --add auth,email # scaffold capabilities non-interactively
|
|
102
|
+
lunora init my-app --vite react --yes # skip the interactive auth/email offer
|
|
103
|
+
lunora init my-app --vite react --dry-run # walk every step, write nothing
|
|
104
|
+
```
|
|
61
105
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
local
|
|
106
|
+
`--add` accepts a comma-separated list of `ai | auth | backup | browser |
|
|
107
|
+
cloudflare-access | crons | email | flags | hyperdrive | payment | presence |
|
|
108
|
+
queue | storage | workflow`. `--ref <branch|tag|commit>` pins the template
|
|
109
|
+
source (e.g. `--ref alpha`); `--from <dir>` copies from a local templates root
|
|
110
|
+
offline (expects `<type>/` subdirs).
|
|
66
111
|
|
|
67
112
|
### Generate types and push the first run
|
|
68
113
|
|
|
@@ -87,7 +132,23 @@ not exit, so:
|
|
|
87
132
|
|
|
88
133
|
- **Local development (user at the keyboard):** ask the user to run `lunora dev`
|
|
89
134
|
in a terminal.
|
|
90
|
-
- **
|
|
135
|
+
- **Agents:** run `lunora dev --background`. It detaches the server, waits until
|
|
136
|
+
it answers HTTP, prints `Dev server running at <url> (pid <n>)`, and exits —
|
|
137
|
+
no orphaned shell, no PID bookkeeping. When Lunora detects an AI agent
|
|
138
|
+
(Claude Code, Cursor, Codex, …), plain `lunora dev` flips into this mode
|
|
139
|
+
automatically with JSON logs; `LUNORA_AGENT_MODE=0` opts out.
|
|
140
|
+
|
|
141
|
+
Manage the running server afterwards:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
lunora dev status --json # machine-readable: url, pid, uptime, logFile
|
|
145
|
+
lunora dev logs --lines 50 # tail the captured output (.lunora/dev.log)
|
|
146
|
+
lunora dev stop # idempotent — succeeds even if nothing runs
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
A second `lunora dev` never double-starts: it reports the existing instance
|
|
150
|
+
(`.lunora/dev.json` is the lockfile). Probe readiness or liveness at
|
|
151
|
+
`GET /_lunora/status` (`{"ok":true}`).
|
|
91
152
|
|
|
92
153
|
Vite serves on `http://localhost:5173` by default; the Worker is served on the
|
|
93
154
|
same origin via `@cloudflare/vite-plugin`.
|
|
@@ -132,9 +193,12 @@ createRoot(document.querySelector("#root")!).render(
|
|
|
132
193
|
);
|
|
133
194
|
```
|
|
134
195
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
`
|
|
196
|
+
Every client adapter has a matching provider: `@lunora/vue`, `@lunora/solid`,
|
|
197
|
+
`@lunora/svelte`, `@lunora/angular` (`provideLunora` / `injectLunoraClient`),
|
|
198
|
+
and `@lunora/react-native` (`createLunoraClient`, re-exporting `@lunora/react`).
|
|
199
|
+
For meta-frameworks, `@lunora/astro` and `@lunora/nuxt` mount Lunora on the
|
|
200
|
+
server side. `VITE_LUNORA_URL` is optional — it defaults to `location.origin`,
|
|
201
|
+
which is correct for the single-origin dev setup.
|
|
138
202
|
|
|
139
203
|
## Writing Your First Function
|
|
140
204
|
|
|
@@ -233,8 +297,10 @@ ids, `.dev.vars` secrets, and container exports.
|
|
|
233
297
|
## Checklist
|
|
234
298
|
|
|
235
299
|
- [ ] Determined starting point: new project or existing app.
|
|
236
|
-
- [ ] New project: scaffolded with `lunora init --
|
|
300
|
+
- [ ] New project: scaffolded with `lunora init --vite <framework>` (SPA) or
|
|
301
|
+
`lunora init -t <template>` (bespoke) — never `--template vite`.
|
|
237
302
|
- [ ] Existing app: ran `lunora init --here` and wired `LunoraProvider`.
|
|
238
303
|
- [ ] Ran `lunora codegen`: `lunora/_generated/` exists and typecheck is clean.
|
|
239
|
-
- [ ]
|
|
304
|
+
- [ ] Dev server is running — user terminal, or `lunora dev --background`
|
|
305
|
+
(check with `lunora dev status`).
|
|
240
306
|
- [ ] Verified a query/mutation round-trip re-renders the client live.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
name: lunora-realtime
|
|
3
3
|
description: Wires Lunora's live data into a client. Use for `LunoraClient`/`LunoraProvider`,
|
|
4
4
|
reactive `useQuery`/`useSubscription`, `useMutation` with optimistic updates,
|
|
5
|
-
pagination, connection status, the React/Vue/Solid/Svelte
|
|
6
|
-
`@lunora/db` TanStack binding.
|
|
5
|
+
pagination, connection status, the React/Vue/Solid/Svelte/Angular/React Native
|
|
6
|
+
adapters, and the `@lunora/db` TanStack binding.
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# Lunora Realtime
|
|
@@ -15,7 +15,8 @@ automatic rollback.
|
|
|
15
15
|
|
|
16
16
|
## When to Use
|
|
17
17
|
|
|
18
|
-
- Wiring a frontend to a Lunora backend (React, Vue, Solid, Svelte
|
|
18
|
+
- Wiring a frontend to a Lunora backend (React, Vue, Solid, Svelte, Angular,
|
|
19
|
+
React Native/Expo, or an Astro/Nuxt meta-framework).
|
|
19
20
|
- Adding optimistic updates, pagination, or presence to the UI.
|
|
20
21
|
- Choosing between live hooks and the `@lunora/db` collection layer.
|
|
21
22
|
|
|
@@ -42,6 +43,19 @@ const client = new LunoraClient({ url });
|
|
|
42
43
|
Vue / Solid / Svelte have matching providers in `@lunora/vue`, `@lunora/solid`,
|
|
43
44
|
`@lunora/svelte`; the hook names and semantics below mirror across them.
|
|
44
45
|
|
|
46
|
+
Two adapters differ in shape:
|
|
47
|
+
|
|
48
|
+
- **`@lunora/angular`** is signal-based rather than hook-based: register with
|
|
49
|
+
`provideLunora(...)`, read the client via `injectLunoraClient()`, and use
|
|
50
|
+
`liveQuery(...)` / `mutate(...)` / `connectionStatus(...)` in place of the
|
|
51
|
+
hooks below.
|
|
52
|
+
- **`@lunora/react-native`** re-exports all of `@lunora/react` and adds
|
|
53
|
+
`createLunoraClient` (plus `@lunora/react-native/auth` for the better-auth
|
|
54
|
+
Expo bridge) — build the client with that instead of `new LunoraClient`.
|
|
55
|
+
|
|
56
|
+
For SSR meta-frameworks, `@lunora/astro` and `@lunora/nuxt` compose Lunora into
|
|
57
|
+
the server (Nitro for Nuxt) and ship reactive-loader server helpers.
|
|
58
|
+
|
|
45
59
|
## Live Queries
|
|
46
60
|
|
|
47
61
|
`useQuery(reference, args)` opens a subscription and returns the value, or
|
|
@@ -67,33 +81,32 @@ const todos = useQuery(api.todos.list, {}) as Doc<"todos">[] | undefined;
|
|
|
67
81
|
|
|
68
82
|
## Authorization & Live Queries
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
actions/queries) where identity is always present.
|
|
84
|
+
**Live queries are identity-aware.** At the WebSocket upgrade the runtime
|
|
85
|
+
stamps the caller's verified identity onto the socket (from the server-minted
|
|
86
|
+
`x-lunora-userid` / `x-lunora-identity` headers, which a client cannot forge).
|
|
87
|
+
Every subscription re-run, shape resolution, and poke-driven refresh executes
|
|
88
|
+
under that socket's own identity, passed by value so a concurrent RPC can't
|
|
89
|
+
clobber it.
|
|
90
|
+
|
|
91
|
+
Practically, this means:
|
|
92
|
+
|
|
93
|
+
- `.use(rls(...))` and `ctx.auth.userId` work the same in a subscribed query as
|
|
94
|
+
in a one-shot read. Shape subscriptions AND-merge the shape predicate with
|
|
95
|
+
the table's RLS read base-where, so the membership query the poke protocol
|
|
96
|
+
runs is RLS-correct by construction — never the client's word for it.
|
|
97
|
+
- An **anonymous** socket carries no identity, so an RLS/`ctx.auth` query fails
|
|
98
|
+
closed (empty/denied) rather than leaking another user's rows.
|
|
99
|
+
- **Token expiry is enforced on the socket.** When the resolved credential
|
|
100
|
+
carries an expiry, the DO sends a `TOKEN_EXPIRED` error frame and closes with
|
|
101
|
+
code `4001` at the next send at or after that instant. `LunoraClient`
|
|
102
|
+
reconnects automatically and re-resolves a fresh identity — but surface it in
|
|
103
|
+
the UI if a re-login is required.
|
|
104
|
+
|
|
105
|
+
You can still scope data structurally when it fits the domain — `.shardBy(userId)`
|
|
106
|
+
(or tenant/room) partitions state so a subscription is narrow by construction,
|
|
107
|
+
and explicit query args keep subscriptions cheap (see the args-scoping note
|
|
108
|
+
above). Prefer those for _performance_; use `rls()` / `ctx.auth` for
|
|
109
|
+
_authorization_. They compose.
|
|
97
110
|
|
|
98
111
|
## Mutations + Optimistic Updates
|
|
99
112
|
|
|
@@ -154,6 +167,13 @@ schema + functions into live TanStack DB collections). Reach for it when the app
|
|
|
154
167
|
needs client-side indexes/joins or a persistent optimistic outbox; raw `useQuery`
|
|
155
168
|
/`useMutation` are enough for straightforward live lists.
|
|
156
169
|
|
|
170
|
+
Call `defineCollections` **once** at module scope and treat the returned
|
|
171
|
+
collections as the single source of truth for each table. Don't mirror rows into
|
|
172
|
+
a parallel store, and never build derived indexes (trees, search, undo captures)
|
|
173
|
+
from a copy — optimistic writes and sync deltas land only on the Lunora
|
|
174
|
+
collection, so code reading a copy silently reads stale rows while `useLiveQuery`
|
|
175
|
+
renders fresh data.
|
|
176
|
+
|
|
157
177
|
## Common Pitfalls
|
|
158
178
|
|
|
159
179
|
1. **Creating `LunoraClient` inside a component.** It re-opens the socket every
|
|
@@ -165,6 +185,12 @@ needs client-side indexes/joins or a persistent optimistic outbox; raw `useQuery
|
|
|
165
185
|
4. **Optimistic shape drift.** The provisional value must match the query's
|
|
166
186
|
element shape (including `_id`/`_creationTime`) or the UI flickers when the
|
|
167
187
|
real delta lands.
|
|
188
|
+
5. **Two sources of truth for the same rows.** `defineCollections` more than once
|
|
189
|
+
per table (or a parallel store of your own) mints copies that drift. Reads
|
|
190
|
+
through `useLiveQuery` look fine, but derived indexes built from the copy can
|
|
191
|
+
**miss rows** — rows written to the collection after the copy was taken never
|
|
192
|
+
appear in the index — or **hold stale rows** — rows updated or deleted in the
|
|
193
|
+
collection still show their old value. One instance, one collection per table.
|
|
168
194
|
|
|
169
195
|
## Checklist
|
|
170
196
|
|
|
@@ -175,3 +201,5 @@ needs client-side indexes/joins or a persistent optimistic outbox; raw `useQuery
|
|
|
175
201
|
- [ ] Query `args` scoped narrowly to avoid over-broad re-renders.
|
|
176
202
|
- [ ] Pagination via `usePaginatedQuery`/`useInfiniteQuery` over `.paginate`.
|
|
177
203
|
- [ ] Considered `@lunora/db` if the app needs local indexes/joins or an outbox.
|
|
204
|
+
- [ ] `@lunora/db`: one `defineCollections` instance; no parallel copy of rows;
|
|
205
|
+
derived indexes built from the same collection the UI renders.
|