@somewhere-cloud/cli 0.38.153 → 0.38.155
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/CHANGELOG.md +11 -0
- package/dist/docs/adopt.md +39 -0
- package/dist/docs/analytics.md +161 -0
- package/dist/docs/api-reference.md +339 -0
- package/dist/docs/api-surface.md +2067 -0
- package/dist/docs/app-mcp.md +162 -0
- package/dist/docs/architecture-patterns.md +334 -0
- package/dist/docs/auth-client.md +531 -0
- package/dist/docs/billing.md +76 -0
- package/dist/docs/browser.md +639 -0
- package/dist/docs/calendar.md +298 -0
- package/dist/docs/changes.md +323 -0
- package/dist/docs/cli.md +407 -0
- package/dist/docs/common-mistakes.md +199 -0
- package/dist/docs/connect-agent.md +72 -0
- package/dist/docs/cors.md +114 -0
- package/dist/docs/cron.md +167 -0
- package/dist/docs/database-engine.md +167 -0
- package/dist/docs/declared-data.md +1656 -0
- package/dist/docs/declared-files.md +475 -0
- package/dist/docs/deploy-intelligence.md +188 -0
- package/dist/docs/deploy.md +733 -0
- package/dist/docs/design-system.md +273 -0
- package/dist/docs/dev-environments.md +496 -0
- package/dist/docs/domain-ownership.md +31 -0
- package/dist/docs/domains.md +370 -0
- package/dist/docs/feedback.md +88 -0
- package/dist/docs/file-tools.md +116 -0
- package/dist/docs/functions.md +489 -0
- package/dist/docs/getting-started.md +238 -0
- package/dist/docs/github.md +95 -0
- package/dist/docs/google-calendar.md +212 -0
- package/dist/docs/groups.md +836 -0
- package/dist/docs/guarantees.md +58 -0
- package/dist/docs/handled-for-you.md +224 -0
- package/dist/docs/inspect.md +171 -0
- package/dist/docs/limits.md +68 -0
- package/dist/docs/live-data.md +197 -0
- package/dist/docs/live.md +92 -0
- package/dist/docs/local-dev.md +30 -0
- package/dist/docs/migration-supabase.md +58 -0
- package/dist/docs/payments.md +1102 -0
- package/dist/docs/portability.md +194 -0
- package/dist/docs/postgres.md +301 -0
- package/dist/docs/pricing-comparison.md +42 -0
- package/dist/docs/pricing.md +39 -0
- package/dist/docs/project-groups.md +107 -0
- package/dist/docs/projects.md +380 -0
- package/dist/docs/recipe-ai-agent.md +112 -0
- package/dist/docs/recipe-ai-features.md +227 -0
- package/dist/docs/recipe-ai-receipts.md +783 -0
- package/dist/docs/recipe-background-jobs.md +369 -0
- package/dist/docs/recipe-booking.md +348 -0
- package/dist/docs/recipe-csv-import.md +390 -0
- package/dist/docs/recipe-ecommerce.md +127 -0
- package/dist/docs/recipe-email.md +282 -0
- package/dist/docs/recipe-escalation.md +133 -0
- package/dist/docs/recipe-file-uploads.md +159 -0
- package/dist/docs/recipe-import-app.md +110 -0
- package/dist/docs/recipe-login.md +457 -0
- package/dist/docs/recipe-multi-chat.md +198 -0
- package/dist/docs/recipe-paid-api.md +161 -0
- package/dist/docs/recipe-pdfs.md +205 -0
- package/dist/docs/recipe-push-notifications.md +107 -0
- package/dist/docs/recipe-seo.md +200 -0
- package/dist/docs/recipe-signed-in-app.md +330 -0
- package/dist/docs/render.md +99 -0
- package/dist/docs/rooms.md +554 -0
- package/dist/docs/sdk.md +287 -0
- package/dist/docs/sdks.md +24 -0
- package/dist/docs/search.md +199 -0
- package/dist/docs/security-model.md +168 -0
- package/dist/docs/setup.md +212 -0
- package/dist/docs/smoke.md +102 -0
- package/dist/docs/speed.md +298 -0
- package/dist/docs/sql-compatibility.md +96 -0
- package/dist/docs/sw.agent.md +248 -0
- package/dist/docs/sw.ai.md +1291 -0
- package/dist/docs/sw.auth.md +1811 -0
- package/dist/docs/sw.billing.md +171 -0
- package/dist/docs/sw.db.md +2128 -0
- package/dist/docs/sw.email.md +661 -0
- package/dist/docs/sw.endpoint.md +187 -0
- package/dist/docs/sw.env.md +303 -0
- package/dist/docs/sw.fetch.md +115 -0
- package/dist/docs/sw.fs.md +424 -0
- package/dist/docs/sw.groups.md +836 -0
- package/dist/docs/sw.image.md +69 -0
- package/dist/docs/sw.jobs.md +520 -0
- package/dist/docs/sw.logs.md +61 -0
- package/dist/docs/sw.mail.md +106 -0
- package/dist/docs/sw.notifications.md +78 -0
- package/dist/docs/sw.push.md +161 -0
- package/dist/docs/sw.rateLimit.md +67 -0
- package/dist/docs/sw.web.md +128 -0
- package/dist/docs/tasks.md +269 -0
- package/dist/docs/test.md +220 -0
- package/dist/docs/tool-reference-account.md +7 -0
- package/dist/docs/tool-reference-ai.md +121 -0
- package/dist/docs/tool-reference-analytics.md +37 -0
- package/dist/docs/tool-reference-api.md +19 -0
- package/dist/docs/tool-reference-artifacts.md +35 -0
- package/dist/docs/tool-reference-auth.md +163 -0
- package/dist/docs/tool-reference-browser.md +114 -0
- package/dist/docs/tool-reference-code.md +26 -0
- package/dist/docs/tool-reference-connect.md +21 -0
- package/dist/docs/tool-reference-cron.md +48 -0
- package/dist/docs/tool-reference-db.md +282 -0
- package/dist/docs/tool-reference-domains.md +107 -0
- package/dist/docs/tool-reference-email.md +55 -0
- package/dist/docs/tool-reference-env.md +19 -0
- package/dist/docs/tool-reference-feedback.md +56 -0
- package/dist/docs/tool-reference-fs.md +265 -0
- package/dist/docs/tool-reference-github.md +57 -0
- package/dist/docs/tool-reference-groups.md +85 -0
- package/dist/docs/tool-reference-help.md +29 -0
- package/dist/docs/tool-reference-jobs.md +39 -0
- package/dist/docs/tool-reference-live.md +48 -0
- package/dist/docs/tool-reference-logs.md +16 -0
- package/dist/docs/tool-reference-payments.md +44 -0
- package/dist/docs/tool-reference-project.md +706 -0
- package/dist/docs/tool-reference-push.md +78 -0
- package/dist/docs/tool-reference-rate-limit.md +18 -0
- package/dist/docs/tool-reference-search.md +68 -0
- package/dist/docs/tool-reference-security.md +42 -0
- package/dist/docs/tool-reference-smoke.md +17 -0
- package/dist/docs/tool-reference-stock-photos.md +20 -0
- package/dist/docs/tool-reference-tasks.md +73 -0
- package/dist/docs/tool-reference-telegram.md +32 -0
- package/dist/docs/tool-reference-usage.md +9 -0
- package/dist/docs/tool-reference-web.md +71 -0
- package/dist/docs/tool-reference-webhooks.md +9 -0
- package/dist/docs/troubleshooting.md +411 -0
- package/dist/docs/typed-functions.md +94 -0
- package/dist/docs/verify-before-deploy.md +67 -0
- package/dist/docs/vs-supabase.md +75 -0
- package/dist/docs/vs-vercel.md +103 -0
- package/dist/lib/bundle.js +303 -221
- package/dist/lib/bundle.js.map +3 -3
- package/dist/types/lib/test-session.d.ts +8 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -2
- package/runtime/DECLARED-DATA-VENDOR.json +5 -5
- package/runtime/PLATFORM-SOURCE.json +1 -1
- package/runtime/SOURCE-LINT-VENDOR.json +2 -2
- package/runtime/declared-data.cjs +37 -19
- package/runtime/source-lint.cjs +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Live data — one poller, fan out to every client
|
|
2
|
+
|
|
3
|
+
**A recipe, not a separate primitive.** It combines a `cron` schedule (or a
|
|
4
|
+
job), a function that writes with `sw.db.server`, and a declared live view
|
|
5
|
+
(`docs({ topic: 'live' })`). You write the poller.
|
|
6
|
+
|
|
7
|
+
The golden path for any app that shows the SAME live value to many
|
|
8
|
+
viewers at once: live scores, a price ticker, a leaderboard, an auction
|
|
9
|
+
count, a status board. There is a right way and a wrong way, and the
|
|
10
|
+
wrong way is the one most agents reach for first.
|
|
11
|
+
|
|
12
|
+
**Anti-pattern (don't): per-client polling.** Every viewer hits the
|
|
13
|
+
source on a timer. A World-Cup-style live-scores page where 5,000
|
|
14
|
+
viewers each poll the source every 12 seconds makes ~25,000 calls/minute
|
|
15
|
+
to that source — your rate limits trip, the source may ban you, and the
|
|
16
|
+
cost scales with your audience. Worse with every viewer you add.
|
|
17
|
+
|
|
18
|
+
**Pattern (do): one server-side poller, one declared live view.** Fetch
|
|
19
|
+
the source ONCE on the server per tick, write the snapshot to your
|
|
20
|
+
database, and let every client's declared live view re-read it. Load on
|
|
21
|
+
the source is O(1) — the same single fetch whether one person or a
|
|
22
|
+
million are watching.
|
|
23
|
+
|
|
24
|
+
## Step 0 — taking over a project you didn't build
|
|
25
|
+
|
|
26
|
+
Adding live data usually means editing an app you didn't write. Orient
|
|
27
|
+
first, with the dependable sequence:
|
|
28
|
+
|
|
29
|
+
1. project_files_list { project_id } — the file tree (paths only).
|
|
30
|
+
2. project_grep { project_id, pattern } — find where things live
|
|
31
|
+
(e.g. the polling code, the page that renders the value).
|
|
32
|
+
3. project_file_read { project_id, path } — read the few files that
|
|
33
|
+
matched.
|
|
34
|
+
|
|
35
|
+
## The pattern, end to end
|
|
36
|
+
|
|
37
|
+
1. A scheduled function (cron) fetches the live source ONCE per tick.
|
|
38
|
+
2. It writes the snapshot to a table with the structured builder, so a
|
|
39
|
+
client connecting mid-stream reads the current value immediately and
|
|
40
|
+
the write invalidates every subscribed view.
|
|
41
|
+
3. A second function DECLARES the live view over that table.
|
|
42
|
+
4. Each client calls that function once for first paint, then re-reads
|
|
43
|
+
it on every invalidation. No client ever polls the source.
|
|
44
|
+
|
|
45
|
+
Declare the snapshot table in `db/schema.ts` — it is the same value for
|
|
46
|
+
everyone, so `shared()`. `players` is the reference table the roster job
|
|
47
|
+
below fills; only your functions touch it, so `serverOnly()`:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// db/schema.ts
|
|
51
|
+
import { schema, table, id, text, integer, timestamp, shared, serverOnly } from 'somewhere/db'
|
|
52
|
+
|
|
53
|
+
export default schema({
|
|
54
|
+
live_snapshot: table({
|
|
55
|
+
id: id(), key: text({ unique: true }), json: text(),
|
|
56
|
+
updated_at: timestamp({ default: 'now' }),
|
|
57
|
+
}, { scope: shared() }),
|
|
58
|
+
players: table({
|
|
59
|
+
id: id(), key: text({ unique: true }), team: text(), name: text(),
|
|
60
|
+
number: integer({ nullable: true }), position: text({ nullable: true }),
|
|
61
|
+
}, { scope: serverOnly() }),
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Server — the poller (a scheduled function)
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// api/poll-scores.ts — fetch once, write the snapshot. Runs only when the scheduler calls it.
|
|
69
|
+
export default async function (req: Request, sw: SomewhereRuntimeContext): Promise<Response> {
|
|
70
|
+
if (!(await sw.jobs.verifyInvocation(req))) return new Response('forbidden', { status: 403 })
|
|
71
|
+
|
|
72
|
+
const res = await fetch('https://example.com/api/scores/live')
|
|
73
|
+
if (!res.ok) return new Response('source returned ' + res.status, { status: 502 })
|
|
74
|
+
const scores = await res.json()
|
|
75
|
+
|
|
76
|
+
// A scheduled run has no signed-in user, so it writes with server authority
|
|
77
|
+
// and names the author explicitly: null marks a system row no app user wrote.
|
|
78
|
+
// The composed write is what invalidates every live view over this table;
|
|
79
|
+
// onConflict: 'update' replaces the row for the same key instead of adding one.
|
|
80
|
+
// Raw sw.db.query never feeds a live view — and on a project with a
|
|
81
|
+
// db/schema.ts it cannot write at all.
|
|
82
|
+
await sw.db.server.insert('live_snapshot',
|
|
83
|
+
{ key: 'scores', json: JSON.stringify(scores), _sw_author_id: null },
|
|
84
|
+
{ onConflict: 'update' })
|
|
85
|
+
return Response.json({ ok: true })
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Server — the declared view the browser subscribes to
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// api/scores.ts
|
|
93
|
+
export default async function (_req: Request, sw: SomewhereRuntimeContext) {
|
|
94
|
+
return Response.json(await sw.rooms.live('scores.current', sw.db.from('live_snapshot', {
|
|
95
|
+
where: { key: 'scores' },
|
|
96
|
+
columns: ['id', 'key', 'json'],
|
|
97
|
+
order: [['id', 'asc']],
|
|
98
|
+
limit: 1,
|
|
99
|
+
})))
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Viewers read this as signed-in users: a `shared()` read with no signed-in
|
|
104
|
+
user is refused `401 AUTH_REQUIRED`, and live views are the signed-in
|
|
105
|
+
browser path (`docs({ topic: 'live' })`).
|
|
106
|
+
|
|
107
|
+
Schedule the poller to refresh once a minute:
|
|
108
|
+
|
|
109
|
+
```text
|
|
110
|
+
cron_create({ project_id: "my-app", schedule: "*/5 * * * *", handler: "/api/poll-scores" })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Client — read once, then subscribe (never poll)
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { watchLive } from '/__sw/rooms/client.js'
|
|
117
|
+
|
|
118
|
+
// First paint AND every update come from the same call: watchLive loads
|
|
119
|
+
// through your function, then re-loads whenever the platform says the
|
|
120
|
+
// declared view may be stale. The source is never touched from the browser.
|
|
121
|
+
watchLive(
|
|
122
|
+
() => fetch('/api/scores', { credentials: 'include' }).then(r => r.json()),
|
|
123
|
+
(rows) => render(JSON.parse(rows[0].json)),
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Every frame on that socket is control only — "this view may now be stale" —
|
|
128
|
+
so the browser always re-reads through your function and never applies a row
|
|
129
|
+
off the wire. `watchLive` also refreshes on reconnect, on tab focus, when the network
|
|
130
|
+
comes back and every 60 seconds, so a lost notice self-heals.
|
|
131
|
+
|
|
132
|
+
Caller-chosen channels are not an option here. The supported browser
|
|
133
|
+
path is the signed invalidation channel created by `sw.rooms.live`; see
|
|
134
|
+
`docs({ topic: 'rooms' })` under "Live lists".
|
|
135
|
+
|
|
136
|
+
## Sub-minute updates (live sports, finance)
|
|
137
|
+
|
|
138
|
+
**Cron cannot go sub-minute — a hard floor.** A 5-field cron expression has
|
|
139
|
+
no seconds field, so you cannot schedule "every 10 seconds," and your plan
|
|
140
|
+
may set a wider minimum than a minute on top of that (`cron_list` reports
|
|
141
|
+
it as `policy.min_interval_minutes`). For sub-minute live data you do NOT
|
|
142
|
+
lean on cron for the cadence:
|
|
143
|
+
|
|
144
|
+
- If you RECEIVE the data (a webhook, an inbound feed, a user action),
|
|
145
|
+
write the snapshot the instant it arrives — the composed write
|
|
146
|
+
invalidates every subscribed view immediately, with no schedule at all.
|
|
147
|
+
- If you must PULL it, run the cron poller at the tightest interval your
|
|
148
|
+
plan allows to keep the snapshot fresh; anything arriving faster is
|
|
149
|
+
written from wherever it enters your system.
|
|
150
|
+
|
|
151
|
+
Either way the rule holds: every viewer re-reads one snapshot through your
|
|
152
|
+
own function — the source is hit O(1), never once-per-viewer.
|
|
153
|
+
|
|
154
|
+
## Reference data: enrich into a table, don't hardcode it
|
|
155
|
+
|
|
156
|
+
Seed/reference data — a squad roster, a product catalog, a venue list —
|
|
157
|
+
does NOT belong inline in your frontend. Hardcoding it means every
|
|
158
|
+
correction is a redeploy. Instead, write a RE-RUNNABLE job that builds
|
|
159
|
+
the dataset into `sw.db` (or a `sw.fs` JSON file), and have the page
|
|
160
|
+
read it at runtime:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// api/jobs/build-rosters.ts — fetch sources, extract to a schema, store. Re-runnable.
|
|
164
|
+
export default async function (req: Request, sw: SomewhereRuntimeContext): Promise<Response> {
|
|
165
|
+
if (!(await sw.jobs.verifyInvocation(req))) return new Response('forbidden', { status: 403 })
|
|
166
|
+
const res = await fetch('https://example.com/teams')
|
|
167
|
+
if (!res.ok) return new Response('source returned ' + res.status, { status: 502 })
|
|
168
|
+
const raw = await res.text()
|
|
169
|
+
const result = await sw.ai.chat({
|
|
170
|
+
messages: [{ role: 'user', content:
|
|
171
|
+
`Extract every player from this page as a JSON array of
|
|
172
|
+
{team, name, number, position}. Return ONLY the JSON.\n\n${raw}` }],
|
|
173
|
+
})
|
|
174
|
+
const players = JSON.parse(result.text)
|
|
175
|
+
if (!Array.isArray(players)) return new Response('extraction did not return a list', { status: 502 })
|
|
176
|
+
// players is the serverOnly() table in db/schema.ts above; a job has no
|
|
177
|
+
// signed-in user, so it writes with server authority. The upsert on the
|
|
178
|
+
// unique key replaces a player's row on the next run instead of adding one.
|
|
179
|
+
let upserted = 0
|
|
180
|
+
for (const p of players) {
|
|
181
|
+
if (typeof p?.team !== 'string' || typeof p?.name !== 'string') continue
|
|
182
|
+
await sw.db.server.insert('players', {
|
|
183
|
+
key: `${p.team}:${p.name}`, team: p.team, name: p.name,
|
|
184
|
+
number: Number.isInteger(p.number) ? p.number : null,
|
|
185
|
+
position: typeof p.position === 'string' ? p.position : null,
|
|
186
|
+
}, { onConflict: 'update' })
|
|
187
|
+
upserted++
|
|
188
|
+
}
|
|
189
|
+
return Response.json({ upserted })
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Run it as a job (`sw.jobs.create({ handler: '/api/jobs/build-rosters' })`) or
|
|
194
|
+
on a cron (`cron_create`) to refresh. The frontend
|
|
195
|
+
fetches `/api/players`, so correcting a roster updates the live app
|
|
196
|
+
with NO redeploy. Same shape for any "fetch sources → extract to a
|
|
197
|
+
schema → serve" job.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Live updates — rooms and live lists
|
|
2
|
+
|
|
3
|
+
Realtime in an app is one surface, rooms (`docs({ topic: 'rooms' })`):
|
|
4
|
+
|
|
5
|
+
- a room is one row that people change together (shared state, who is here,
|
|
6
|
+
quick messages);
|
|
7
|
+
- a live list keeps a list of rows fresh in every open tab.
|
|
8
|
+
|
|
9
|
+
There is no caller-named channel API: nothing publishes or broadcasts on a
|
|
10
|
+
channel you pick. Application state and events belong in the database.
|
|
11
|
+
|
|
12
|
+
## Live lists
|
|
13
|
+
|
|
14
|
+
Declare the list in a function with `sw.rooms.live(name, sw.db.from(...))`
|
|
15
|
+
and follow it with `watchLive` from `/__sw/rooms/client.js`. Each change to
|
|
16
|
+
the list's rows sends a "refresh now" notice, and the browser re-calls your
|
|
17
|
+
function for fresh rows, so every access rule applies. No row, SQL, table
|
|
18
|
+
name, predicate or owner travels on the connection.
|
|
19
|
+
|
|
20
|
+
| Table rule | Who can follow the list |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `owner()` | the signed-in user, for their own rows; with `owner({ visitors: true })`, an anonymous visitor for their own rows |
|
|
23
|
+
| `shared()`, `member()`, `group()`, `appRole()` | signed-in users who may read the rows |
|
|
24
|
+
| `serverOnly()` | nobody: deploy refuses the list |
|
|
25
|
+
|
|
26
|
+
The list below reads an `owner()` table, so each refresh returns only the
|
|
27
|
+
signed-in user's notes:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
// db/schema.ts
|
|
31
|
+
import { schema, table, id, text, boolean, timestamp, owner } from 'somewhere/db'
|
|
32
|
+
|
|
33
|
+
export default schema({
|
|
34
|
+
notes: table({
|
|
35
|
+
id: id(), title: text(), done: boolean({ default: false }),
|
|
36
|
+
created_at: timestamp({ default: 'now' }),
|
|
37
|
+
}, { scope: owner() }),
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// api/open-notes.ts
|
|
43
|
+
export default async function (_req: Request, sw: SomewhereRuntimeContext) {
|
|
44
|
+
return Response.json(await sw.rooms.live('notes.open', sw.db.from('notes', {
|
|
45
|
+
where: { done: false },
|
|
46
|
+
columns: ['id', 'title', 'done', 'created_at'],
|
|
47
|
+
order: [['created_at', 'desc'], ['id', 'asc']],
|
|
48
|
+
limit: 20,
|
|
49
|
+
})))
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
// browser
|
|
55
|
+
import { watchLive } from '/__sw/rooms/client.js'
|
|
56
|
+
|
|
57
|
+
const stop = watchLive(
|
|
58
|
+
() => fetch('/api/open-notes', { credentials: 'include' }).then((r) => {
|
|
59
|
+
if (!r.ok) throw new Error('Could not load notes (' + r.status + ').')
|
|
60
|
+
return r.json()
|
|
61
|
+
}),
|
|
62
|
+
(rows) => render(rows),
|
|
63
|
+
(err) => showProblem(err.message), // optional; console.error otherwise
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Anonymous visitors sharing one row (a game between two people with links, a
|
|
68
|
+
public board) use a room on that row instead of a list.
|
|
69
|
+
|
|
70
|
+
The declaration rules, what triggers a refresh, recovery after a dropped
|
|
71
|
+
connection, and `live_delivery` are in `docs({ topic: 'rooms' })` under
|
|
72
|
+
"Live lists".
|
|
73
|
+
|
|
74
|
+
## Platform system events
|
|
75
|
+
|
|
76
|
+
Two reserved, signed channels carry platform lifecycle events to developer
|
|
77
|
+
tooling. They are subscribe-only, developer-authority only, and carry no
|
|
78
|
+
application data — an app-user or visitor session is never admitted:
|
|
79
|
+
|
|
80
|
+
events_subscribe_project({ project_id: 'my-app' })
|
|
81
|
+
// → { channel: 'system:project', websocket_url, event_types: [...] }
|
|
82
|
+
|
|
83
|
+
events_subscribe_user({})
|
|
84
|
+
// → { channel: 'system:user', websocket_url, event_types: ['feedback_resolved'] }
|
|
85
|
+
|
|
86
|
+
The `system:project` channel emits deploy lifecycle, database health, quota
|
|
87
|
+
warning, and auth administration events. The `system:user` channel emits
|
|
88
|
+
`feedback_resolved` for tickets submitted by the authenticated developer.
|
|
89
|
+
The returned WebSocket URLs authenticate as that developer; keep them private.
|
|
90
|
+
On close code 4001 (`reauthorize`), reconnect with `since=<last received seq>`
|
|
91
|
+
so the new connection checks your current access and resumes available events.
|
|
92
|
+
A replay gap means you should reload the current state before continuing.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Local dev — `somewhere dev`
|
|
2
|
+
|
|
3
|
+
# somewhere dev — the frontend loop
|
|
4
|
+
|
|
5
|
+
`somewhere dev` serves your browser application on localhost with hot
|
|
6
|
+
reload while you shape the UI. If the frontend doesn't already have Vite,
|
|
7
|
+
install it with `npm install -D vite`. The backend you rely on is the deployed one:
|
|
8
|
+
`api/` functions, `sw.*` calls, the database and files are reached
|
|
9
|
+
through your project's live URL. Deploying is how you see the real app —
|
|
10
|
+
the platform compiles raw source on deploy — so for anything behind an API
|
|
11
|
+
call the loop is `somewhere deploy` then `somewhere verify`.
|
|
12
|
+
|
|
13
|
+
Data the local app saves goes to the project's own database and files, the
|
|
14
|
+
same ones your users' app reads, so local writes change production data.
|
|
15
|
+
|
|
16
|
+
somewhere dev # serve the frontend on http://localhost:8787
|
|
17
|
+
somewhere deploy # publish; the platform compiles
|
|
18
|
+
somewhere verify # prove the live app in a real browser
|
|
19
|
+
|
|
20
|
+
If port 8787 is in use, run `somewhere dev --port 8788` and open the URL it prints.
|
|
21
|
+
|
|
22
|
+
Do not run a build step before `somewhere dev` or `somewhere deploy`;
|
|
23
|
+
the platform compiles raw source. Local dev never needs a developer key or
|
|
24
|
+
a browser database client.
|
|
25
|
+
|
|
26
|
+
To try changes without touching production data, `somewhere preview` runs
|
|
27
|
+
the whole app hosted on a private URL against an isolated, populated copy of
|
|
28
|
+
your production database; nothing your users see changes until you promote
|
|
29
|
+
that preview. Which plans include it, and how to start one:
|
|
30
|
+
docs({ topic: 'dev-environments' }).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Migrating a Supabase app
|
|
2
|
+
|
|
3
|
+
Somewhere is not a drop-in Supabase replacement. Migrate the app's data and
|
|
4
|
+
access contract; changing an import does not migrate queries, permissions,
|
|
5
|
+
authentication, files, or live-update behavior.
|
|
6
|
+
|
|
7
|
+
If you would rather keep your data in PostgreSQL than port it to the managed
|
|
8
|
+
database, you can: attach your own database and query it with the provider's
|
|
9
|
+
driver (`docs({ topic: 'postgres' })`). That decision is only about the
|
|
10
|
+
data layer — auth, files, functions and live updates are still the separate
|
|
11
|
+
moves described below, and an attached database gets none of the declared
|
|
12
|
+
permissions this page is about.
|
|
13
|
+
|
|
14
|
+
## Declare the data contract
|
|
15
|
+
|
|
16
|
+
Declare tables, fields, access scopes, relations, and browser operation grants
|
|
17
|
+
in `db/schema.ts`. The platform generates the typed `somewhere:data` client
|
|
18
|
+
for permitted browser operations. Use `sw.db` inside functions for business
|
|
19
|
+
logic. A foreign key describes a relationship; it does not grant access.
|
|
20
|
+
|
|
21
|
+
An existing `from().select()` call is not the new browser data API. Rewrite
|
|
22
|
+
ordinary browser reads and writes against the generated operations. See
|
|
23
|
+
docs({ topic: 'declared-data' }) and docs({ topic: 'sw.db' }) for exact syntax,
|
|
24
|
+
supported relations, and the rules for adopting existing tables.
|
|
25
|
+
|
|
26
|
+
## Keep authentication and files explicit
|
|
27
|
+
|
|
28
|
+
Use same-origin cookie sessions for browser authentication. The optional
|
|
29
|
+
`@somewhere-cloud/sdk` auth and function helpers do not make an existing
|
|
30
|
+
Supabase app source-compatible. Never put a developer key in browser code.
|
|
31
|
+
See docs({ topic: 'auth-client' }) for setup and docs({ topic: 'sw.auth' })
|
|
32
|
+
for session behavior.
|
|
33
|
+
|
|
34
|
+
Copy files with their intended visibility; private files need authenticated
|
|
35
|
+
access or signed URLs. Review old public URLs rather than assuming they keep
|
|
36
|
+
working. See docs({ topic: 'sw.fs' }).
|
|
37
|
+
|
|
38
|
+
## Users
|
|
39
|
+
|
|
40
|
+
Importing users with their existing passwords is not available
|
|
41
|
+
(`POST /v1/auth/import` answers 501 `AUTH_FEATURE_UNAVAILABLE`). Today each
|
|
42
|
+
user creates their account again with the same email address: password
|
|
43
|
+
sign-up, a sign-in link, or Google, GitHub or Discord sign-in. New accounts get
|
|
44
|
+
new user IDs, so map each old ID to the new one by email and rewrite every
|
|
45
|
+
ownership column and foreign key that pointed at it. Sessions do not carry
|
|
46
|
+
over.
|
|
47
|
+
|
|
48
|
+
## Move data before switching traffic
|
|
49
|
+
|
|
50
|
+
Keep a verified export before modifying the source app. Map old user IDs,
|
|
51
|
+
row ownership, and foreign keys explicitly. Test the imported app with two
|
|
52
|
+
users and a signed-out visitor, including denied access and writes, before
|
|
53
|
+
switching traffic. A column named `user_id` does not declare its policy.
|
|
54
|
+
See docs({ topic: 'portability' }) for export and import capabilities.
|
|
55
|
+
|
|
56
|
+
Supabase channels are not the browser live-data contract. Use the supported
|
|
57
|
+
named live-view path described in docs({ topic: 'live' }); its scope
|
|
58
|
+
limits apply. Do not assume every declared table supports subscriptions.
|