create-syncular-app 0.1.3 → 0.2.0
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/README.md +70 -27
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +131 -179
- package/dist/constants.d.ts +40 -0
- package/dist/constants.js +46 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/scaffold.d.ts +44 -0
- package/dist/scaffold.js +106 -0
- package/package.json +22 -15
- package/src/cli.ts +174 -0
- package/src/constants.ts +53 -0
- package/src/index.ts +3 -0
- package/src/scaffold.ts +161 -0
- package/template/minimal/README.md +45 -0
- package/template/minimal/gitignore +5 -0
- package/template/minimal/migrations/0001_initial/up.sql +9 -0
- package/template/minimal/package.json +22 -0
- package/template/minimal/src/clients.ts +54 -0
- package/template/minimal/src/make-client.ts +26 -0
- package/template/minimal/src/server.ts +39 -0
- package/template/minimal/src/smoke.test.ts +70 -0
- package/template/minimal/src/syncular.generated.ts +66 -0
- package/template/minimal/syncular.ir.json +66 -0
- package/template/minimal/syncular.json +17 -0
- package/template/minimal/tsconfig.json +16 -0
- package/template/web/README.md +63 -0
- package/template/web/gitignore +5 -0
- package/template/web/migrations/0001_initial/up.sql +11 -0
- package/template/web/package.json +22 -0
- package/template/web/src/frontend/index.html +37 -0
- package/template/web/src/frontend/main.ts +191 -0
- package/template/web/src/frontend/worker.ts +9 -0
- package/template/web/src/server.ts +183 -0
- package/template/web/src/smoke.test.ts +91 -0
- package/template/web/src/syncular.generated.ts +74 -0
- package/template/web/syncular.ir.json +76 -0
- package/template/web/syncular.json +17 -0
- package/template/web/tsconfig.json +16 -0
- package/template/README.md +0 -122
- package/template/_gitignore +0 -5
- package/template/generated/kotlin/SyncularApp.kt +0 -1005
- package/template/generated/rust/diesel_tables.rs +0 -142
- package/template/generated/rust/migrations.rs +0 -32
- package/template/generated/rust/schema.rs +0 -15
- package/template/generated/rust/syncular.rs +0 -926
- package/template/generated/swift/SyncularApp.swift +0 -1191
- package/template/generated/syncular.codegen.json +0 -19
- package/template/index.html +0 -13
- package/template/migrations/0001_initial/down.sql +0 -1
- package/template/migrations/0001_initial/up.sql +0 -8
- package/template/package.json +0 -33
- package/template/scripts/dev.ts +0 -42
- package/template/src/app.tsx +0 -231
- package/template/src/client/syncular.ts +0 -61
- package/template/src/generated/syncular.generated.ts +0 -769
- package/template/src/generated/syncular.server.generated.ts +0 -512
- package/template/src/main.tsx +0 -5
- package/template/src/server/sync-server.ts +0 -129
- package/template/src/styles.css +0 -233
- package/template/syncular.app.ts +0 -23
- package/template/syncular.schema.json +0 -145
- package/template/tsconfig.json +0 -18
- package/template/vite.config.ts +0 -9
package/template/README.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# Syncular starter app
|
|
2
|
-
|
|
3
|
-
A minimal local-first todo app built with [Syncular](https://syncular.dev):
|
|
4
|
-
the client writes to its own SQLite database (persisted in IndexedDB) and
|
|
5
|
-
syncs with a Hono server over HTTP + WebSocket realtime. It works offline and
|
|
6
|
-
reconciles when the connection returns.
|
|
7
|
-
|
|
8
|
-
## Run it
|
|
9
|
-
|
|
10
|
-
```sh
|
|
11
|
-
bun install
|
|
12
|
-
bun dev
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
This starts:
|
|
16
|
-
|
|
17
|
-
- the sync server on `http://127.0.0.1:4100` (health check at `/health`,
|
|
18
|
-
sync routes under `/sync`, data persisted in `data/sync.sqlite`)
|
|
19
|
-
- Vite on `http://127.0.0.1:5173`
|
|
20
|
-
|
|
21
|
-
Open the app in two browser windows and watch edits replicate. Stop the dev
|
|
22
|
-
server while the page stays open: edits queue locally and sync when the
|
|
23
|
-
server is back.
|
|
24
|
-
|
|
25
|
-
> **Why Bun?** The dev script and sync server run on Bun (`Bun.serve`,
|
|
26
|
-
> `bun:sqlite` via `@syncular/server/bun-sqlite`) because Bun runs
|
|
27
|
-
> TypeScript directly and ships SQLite with zero native build steps — one
|
|
28
|
-
> runtime for the server, scripts and tooling. The browser client and the
|
|
29
|
-
> Vite build are runtime-agnostic. If you need a Node server instead, swap
|
|
30
|
-
> the dialect for `@syncular/server/better-sqlite3` and serve the Hono app
|
|
31
|
-
> with `@hono/node-server` + `@hono/node-ws`.
|
|
32
|
-
|
|
33
|
-
## Project structure
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
migrations/ SQL schema, one folder per migration (up.sql/down.sql)
|
|
37
|
-
syncular.app.ts App contract: tables -> subscriptions + scopes
|
|
38
|
-
generated/ Codegen handoff (syncular.codegen.json, Rust/Swift/Kotlin)
|
|
39
|
-
src/generated/ Generated TypeScript client + server modules (committed)
|
|
40
|
-
src/server/ Hono sync server (auth, handlers, server-side tables)
|
|
41
|
-
src/client/syncular.ts Client wiring: local DB, sync lifecycle, managed client
|
|
42
|
-
src/app.tsx React UI built on @syncular/client/react hooks
|
|
43
|
-
scripts/dev.ts Runs sync server + Vite together
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
How a change flows: `useMutations().tasks.insert(...)` writes to the local
|
|
47
|
-
SQLite database and queues an outbox entry → the sync engine pushes it to
|
|
48
|
-
`/sync` → the server handler authorizes it against your scopes and assigns a
|
|
49
|
-
`server_version` → other subscribed clients receive it over the WebSocket and
|
|
50
|
-
`useSyncQuery` re-renders.
|
|
51
|
-
|
|
52
|
-
## Regenerating the client (`bun run codegen`)
|
|
53
|
-
|
|
54
|
-
`src/generated/` is **committed**, so the app installs and runs without any
|
|
55
|
-
extra toolchain. Regenerate it after changing `migrations/` or
|
|
56
|
-
`syncular.app.ts`:
|
|
57
|
-
|
|
58
|
-
```sh
|
|
59
|
-
bun run codegen # npx syncular generate
|
|
60
|
-
bun run codegen:check # CI: verify committed output is current
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
`syncular generate` needs two tools:
|
|
64
|
-
|
|
65
|
-
- **Bun** — runs the TypeScript manifest step (`syncular-typegen`).
|
|
66
|
-
- **Rust (cargo)** — the generator itself is the `syncular-codegen` crate.
|
|
67
|
-
On first run the CLI installs it automatically with
|
|
68
|
-
`cargo install syncular-codegen --locked` into a local cache (get Rust from
|
|
69
|
-
https://rustup.rs). No Rust is needed to run the app itself.
|
|
70
|
-
|
|
71
|
-
## Next steps
|
|
72
|
-
|
|
73
|
-
### Add a table
|
|
74
|
-
|
|
75
|
-
1. Add a migration, e.g. `migrations/0002_projects/up.sql`:
|
|
76
|
-
|
|
77
|
-
```sql
|
|
78
|
-
CREATE TABLE IF NOT EXISTS projects (
|
|
79
|
-
id TEXT PRIMARY KEY,
|
|
80
|
-
name TEXT NOT NULL,
|
|
81
|
-
user_id TEXT NOT NULL,
|
|
82
|
-
server_version BIGINT NOT NULL DEFAULT 0
|
|
83
|
-
) WITHOUT ROWID;
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
(plus a `down.sql` with `DROP TABLE IF EXISTS projects;`)
|
|
87
|
-
|
|
88
|
-
2. Register it in `syncular.app.ts`:
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
projects: syncedTable({
|
|
92
|
-
table: 'projects',
|
|
93
|
-
subscriptionId: 'sub-projects',
|
|
94
|
-
scopes: [scope('user_id', { source: 'actorId', required: true })],
|
|
95
|
-
serverVersion: 'server_version',
|
|
96
|
-
sqliteWithoutRowid: true,
|
|
97
|
-
}),
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
3. Run `bun run codegen`, then mirror the table on the server: add a
|
|
101
|
-
`createServerHandler` for `projects` in `src/server/sync-server.ts` and a
|
|
102
|
-
matching `createTable` in `ensureAppTables`. Subscribe the client by
|
|
103
|
-
adding `projectSubscription({ actorId })` in `src/client/syncular.ts`.
|
|
104
|
-
|
|
105
|
-
### Change scopes
|
|
106
|
-
|
|
107
|
-
Scopes decide which rows each user receives. `scope('user_id', { source:
|
|
108
|
-
'actorId' })` means "sync rows whose `user_id` equals the signed-in actor".
|
|
109
|
-
For shared data, scope by a different column (e.g. `team_id`) and return the
|
|
110
|
-
user's teams from `resolveScopes` on the server.
|
|
111
|
-
|
|
112
|
-
### Real auth
|
|
113
|
-
|
|
114
|
-
The starter authenticates every request as one demo user with a static
|
|
115
|
-
token. Replace `authenticate` in `src/server/sync-server.ts` with your
|
|
116
|
-
session/JWT validation, and have `src/client/syncular.ts` send your real
|
|
117
|
-
token and the signed-in user's id as `actorId`.
|
|
118
|
-
|
|
119
|
-
## Learn more
|
|
120
|
-
|
|
121
|
-
- Docs: https://syncular.dev/docs
|
|
122
|
-
- CLI reference: https://syncular.dev/docs/reference/cli
|