@joiner-platform/cli 0.0.0-stage → 0.1.1
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 +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +149 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +197 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +354 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Actions
|
|
2
|
+
|
|
3
|
+
Actions execute on the server. Use them when you need things mutators can't do: randomness, calling another store's action, or accessing server-only data. Actions have no general network access: the backend runtime's `fetch` throws, so a third-party HTTP API cannot be called from an action. Outbound work goes through `ctx.platform.call(...)` for platform services (see [platform.md](platform.md)) and `ctx.externalStore(...)` for other stores (see [external-stores.md](external-stores.md)); neither gives general HTTP access.
|
|
4
|
+
|
|
5
|
+
> **Security boundary:** server execution does not make an action's writes
|
|
6
|
+
> action-only. Actions write through `ctx.mutate(...)`, and ordinary schema
|
|
7
|
+
> mutators are also directly callable by clients. Validate caller-controlled
|
|
8
|
+
> input accordingly. The current app API has no backend-enforced app-internal
|
|
9
|
+
> mutator or transactional action-write primitive; `$`-prefixed mutators are
|
|
10
|
+
> reserved for trusted platform system work and cannot be called from an
|
|
11
|
+
> ordinary app action.
|
|
12
|
+
|
|
13
|
+
| | Mutator | Action |
|
|
14
|
+
|---|---------|--------|
|
|
15
|
+
| Runs on | Client + Server | Server only |
|
|
16
|
+
| Instant UI update | Yes (optimistic) | No (waits for server) |
|
|
17
|
+
| Use when | Client has all data needed | Needs platform capabilities, or server-only data |
|
|
18
|
+
|
|
19
|
+
## Declaring Actions in the Schema
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { TILE_SCHEMA_VERSION } from "./tile-schema-version";
|
|
23
|
+
|
|
24
|
+
const schema = defineSchema({
|
|
25
|
+
schemaVersion: TILE_SCHEMA_VERSION,
|
|
26
|
+
tables: { /* ... */ },
|
|
27
|
+
mutators: { /* ... */ },
|
|
28
|
+
actions: {
|
|
29
|
+
rollDice: {
|
|
30
|
+
description: "Roll a die on the server",
|
|
31
|
+
input: z.object({ id: z.string() }),
|
|
32
|
+
output: z.object({ roll: z.number() }),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Actions are also exposed as MCP tools, so AI models can call them directly.
|
|
39
|
+
|
|
40
|
+
## Implementing Actions in the Backend Config
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
export const todoBackendConfig = defineBackendConfig<typeof todoSchema>({
|
|
44
|
+
schema: todoSchema,
|
|
45
|
+
mutators: { /* ... */ },
|
|
46
|
+
actions: {
|
|
47
|
+
rollDice: async (ctx, input) => {
|
|
48
|
+
const roll = 1 + Math.floor(Math.random() * 6);
|
|
49
|
+
await ctx.mutate("setRoll", { id: input.id, roll });
|
|
50
|
+
return { roll };
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Calling Actions from the Client
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const { roll } = await store.action.rollDice({ id: "todo-1" });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Enqueuing Actions from Mutators
|
|
63
|
+
|
|
64
|
+
Mutators can trigger actions as a side effect. `ctx.enqueueAction()` is a no-op on the client; on the server it runs the action after the mutation commits. Call it unconditionally — no `ctx.isServer` guard needed.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
mutators: {
|
|
68
|
+
createAndGenerate: async (ctx, input) => {
|
|
69
|
+
// Instant: create a placeholder todo
|
|
70
|
+
await ctx.table("todos").set({
|
|
71
|
+
itemKey: input.id,
|
|
72
|
+
value: { id: input.id, text: "Rolling...", completed: false, status: "rolling" },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Queued: server will run this after the mutation commits
|
|
76
|
+
ctx.enqueueAction("rollDice", { id: input.id });
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## When NOT to use an Action
|
|
83
|
+
|
|
84
|
+
- Data changes that the client can compute — use a mutator (optimistic, no round trip).
|
|
85
|
+
- Secrets the client should never see — use `serverOnly()` tables; an action can expose a derived result.
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# Synced-Store API Patterns
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [Schema Definition](#schema-definition)
|
|
5
|
+
- [Mutator Context API](#mutator-context-api)
|
|
6
|
+
- [Client Config & Backend Config](#client-config--backend-config)
|
|
7
|
+
- [Entry Point Wiring](#entry-point-wiring)
|
|
8
|
+
- [Framework Bindings](#framework-bindings)
|
|
9
|
+
- [Package Conventions](#package-conventions)
|
|
10
|
+
|
|
11
|
+
## Schema Definition
|
|
12
|
+
|
|
13
|
+
Schema version lives in its own zero-dep file (`synced-store/tile-schema-version.ts`) so both `schema.ts` and `client-config.ts` can read it without importing Zod:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// synced-store/tile-schema-version.ts
|
|
17
|
+
export const TILE_SCHEMA_VERSION = 1;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import { defineSchema, singletonTable, table } from "joiner-sdk/v1/backend.js";
|
|
23
|
+
import { TILE_SCHEMA_VERSION } from "./tile-schema-version";
|
|
24
|
+
|
|
25
|
+
export const tileSchema = defineSchema({
|
|
26
|
+
schemaVersion: TILE_SCHEMA_VERSION,
|
|
27
|
+
tables: {
|
|
28
|
+
game: {
|
|
29
|
+
schema: table(z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
status: z.string(),
|
|
32
|
+
createdAt: z.number(),
|
|
33
|
+
})),
|
|
34
|
+
},
|
|
35
|
+
moves: {
|
|
36
|
+
schema: table(z.object({
|
|
37
|
+
id: z.string(),
|
|
38
|
+
moveIndex: z.number(),
|
|
39
|
+
playedBy: z.string(),
|
|
40
|
+
})),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
mutators: {
|
|
44
|
+
makeMove: {
|
|
45
|
+
description: "Record a player move",
|
|
46
|
+
input: z.object({ from: z.string(), to: z.string() }),
|
|
47
|
+
},
|
|
48
|
+
resetRound: {
|
|
49
|
+
description: "Reset the round",
|
|
50
|
+
input: z.object({}),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
export type TileSchema = typeof tileSchema;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Single-row tables**: Use `table(schema)` with a fixed itemKey like `"game"` for records that always have exactly one row (e.g., game state). To expose a typed settings bag where keys carry distinct value types, use `singletonTable(item(key, schema), ...)` — see [singleton-tables.md](singleton-tables.md). There is no no-key `singletonTable(schema)` form.
|
|
58
|
+
|
|
59
|
+
## Mutator Context API
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import type { InferMutatorHandlers, InferSchemaTableTypes } from "joiner-sdk/v1/client.js";
|
|
63
|
+
|
|
64
|
+
export type TileTableTypes = InferSchemaTableTypes<TileSchema>;
|
|
65
|
+
export type RoundRecord = TileTableTypes["game"];
|
|
66
|
+
|
|
67
|
+
export const tileMutators: InferMutatorHandlers<TileSchema> = {
|
|
68
|
+
makeMove: async (ctx, input) => {
|
|
69
|
+
// READ a single record
|
|
70
|
+
const game = await ctx.table("game").get("game"); // returns value | undefined
|
|
71
|
+
|
|
72
|
+
// READ entries one at a time; do not collect an entire growing table
|
|
73
|
+
for await (const [key, value] of ctx.table("moves").entries()) {
|
|
74
|
+
// Process this row before advancing to the next one.
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// WRITE a record — itemKey + value required
|
|
78
|
+
await ctx.table("moves").set({
|
|
79
|
+
itemKey: "move-1",
|
|
80
|
+
value: { id: "move-1", moveIndex: 0, playedBy: ctx.userId },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// DELETE a record
|
|
84
|
+
await ctx.table("moves").delete("move-1");
|
|
85
|
+
|
|
86
|
+
// Current user
|
|
87
|
+
const userId: string = ctx.userId;
|
|
88
|
+
|
|
89
|
+
// Server check
|
|
90
|
+
if (ctx.isServer) { /* server-only logic */ }
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Shared Read Helpers
|
|
96
|
+
|
|
97
|
+
Use `InferReadContext<Schema>` for data-loading helpers that only read tables.
|
|
98
|
+
Those helpers can be reused from query callbacks, mutators, and actions without
|
|
99
|
+
deriving a context type from a specific handler.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import type { InferReadContext, InferSchemaTableTypes } from "joiner-sdk/v1/client.js";
|
|
103
|
+
import type { TileSchema } from "./schema";
|
|
104
|
+
|
|
105
|
+
export type TileTableTypes = InferSchemaTableTypes<TileSchema>;
|
|
106
|
+
export type RoundRecord = TileTableTypes["game"];
|
|
107
|
+
export type TileReadCtx = InferReadContext<TileSchema>;
|
|
108
|
+
|
|
109
|
+
export async function readRound(ctx: TileReadCtx): Promise<RoundRecord | undefined> {
|
|
110
|
+
return (await ctx.table("game").get("game")) as RoundRecord | undefined;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Use `InferMutationContext<Schema>` only for helpers that need writes,
|
|
115
|
+
`enqueueAction`, or mutator-only fields. Use `InferActionContext<Schema>` for
|
|
116
|
+
helpers that need action-only fields such as `ctx.mutate`.
|
|
117
|
+
|
|
118
|
+
## Client Config & Backend Config
|
|
119
|
+
|
|
120
|
+
**Client** (`synced-store/client-config.ts`):
|
|
121
|
+
```typescript
|
|
122
|
+
import { defineClientConfig } from "joiner-sdk/v1/client.js";
|
|
123
|
+
import type { tileSchema } from "./schema"; // type-only import!
|
|
124
|
+
import { tileMutators } from "./mutators/index";
|
|
125
|
+
import { tileHooks } from "./hooks";
|
|
126
|
+
import { TILE_SCHEMA_VERSION } from "./tile-schema-version";
|
|
127
|
+
|
|
128
|
+
export const tileClientConfig = defineClientConfig<typeof tileSchema>({
|
|
129
|
+
mutators: tileMutators,
|
|
130
|
+
hooks: tileHooks,
|
|
131
|
+
schemaVersion: TILE_SCHEMA_VERSION,
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Backend** (`synced-store/backend-config.ts`):
|
|
136
|
+
```typescript
|
|
137
|
+
import { defineBackendConfig } from "joiner-sdk/v1/backend.js";
|
|
138
|
+
import { tileSchema } from "./schema"; // runtime import
|
|
139
|
+
import { tileMutators } from "./mutators/index";
|
|
140
|
+
import { tileHooks } from "./hooks";
|
|
141
|
+
|
|
142
|
+
export const tileBackendConfig = defineBackendConfig({
|
|
143
|
+
schema: tileSchema,
|
|
144
|
+
mutators: tileMutators,
|
|
145
|
+
hooks: tileHooks,
|
|
146
|
+
actions: {},
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Every hook in `backend-config.ts` should also be wired in `client-config.ts`. The client only runs hook names it declares, and those optimistic hook runs are what make fresh prepared stores render hook-derived rows before the first server pull. Keep hook modules browser-safe; split or guard any server-only tail with `ctx.isServer`.
|
|
151
|
+
|
|
152
|
+
**Backend entry** (`tile/src/backend.ts`):
|
|
153
|
+
```typescript
|
|
154
|
+
import { tileBackendConfig } from "../../synced-store/backend-config";
|
|
155
|
+
export default tileBackendConfig;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Entry Point Wiring
|
|
159
|
+
|
|
160
|
+
**Preact** (`tile/src/entry.tsx`):
|
|
161
|
+
```typescript
|
|
162
|
+
import { createPoe, PostMessageEnvironment } from "joiner-sdk/v1/client.js";
|
|
163
|
+
import { render } from "preact";
|
|
164
|
+
import { tileClientConfig } from "../../client";
|
|
165
|
+
import { App } from "../../ui/App";
|
|
166
|
+
|
|
167
|
+
const environment = new PostMessageEnvironment();
|
|
168
|
+
const Poe = createPoe({ environment });
|
|
169
|
+
const store = Poe.setupStore(tileClientConfig);
|
|
170
|
+
render(<App store={store} />, document.getElementById("root")!);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**React**: Same pattern but use `createRoot(root).render(<App store={store} />)` and add `registerPoeTileElement(environment)`.
|
|
174
|
+
|
|
175
|
+
**SolidJS**: Same pattern but use `render(() => <App store={store} />, root)`.
|
|
176
|
+
|
|
177
|
+
## Framework Bindings
|
|
178
|
+
|
|
179
|
+
Two optional packages provide framework-specific hooks on top of the core store client:
|
|
180
|
+
|
|
181
|
+
### `joiner-sdk/v1/react` — React hook
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { useLiveQuery } from "joiner-sdk/v1/react";
|
|
185
|
+
|
|
186
|
+
function MessageList({ store }: { store: TileStoreClient }) {
|
|
187
|
+
const { data: messages, isLoading } = useLiveQuery(
|
|
188
|
+
store,
|
|
189
|
+
(tx) => tx.table("messages").entries().toArray(),
|
|
190
|
+
);
|
|
191
|
+
if (isLoading) return <div>Loading...</div>;
|
|
192
|
+
return <ul>{messages.map(([, m]) => <li key={m.id}>{m.text}</li>)}</ul>;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- Returns `{ data: T | undefined, isLoading: boolean }`
|
|
197
|
+
- Resubscribes when `queryFn` reference changes; keeps previous data until new results arrive
|
|
198
|
+
- Accepts `null` for the store parameter (returns loading state)
|
|
199
|
+
|
|
200
|
+
### `joiner-sdk/v1/solid` — SolidJS integration
|
|
201
|
+
|
|
202
|
+
Provides `subscribeToTable` on the store client for fine-grained reactivity:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import "joiner-sdk/v1/solid"; // augments the store client with subscribeToTable
|
|
206
|
+
|
|
207
|
+
const unsub = store.subscribeToTable("items", (entries, changes) => {
|
|
208
|
+
// entries: full table snapshot as [[key, value], ...]
|
|
209
|
+
// changes: { added: string[], modified: string[], removed: string[] }
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Use with `createStore` + `reconcile()` to preserve DOM nodes across updates (see [ui-patterns.md](ui-patterns.md)).
|
|
214
|
+
|
|
215
|
+
**When to use which**: Most Joiner tiles use `store.subscribe()` (built into the core client) directly. Use the framework bindings when you want `useLiveQuery`'s loading state management (React) or `subscribeToTable`'s change diffs (SolidJS animations).
|
|
216
|
+
|
|
217
|
+
## Package Conventions
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"name": "@poe-tile/my-app",
|
|
222
|
+
"version": "0.0.1",
|
|
223
|
+
"type": "module",
|
|
224
|
+
"dependencies": { "joiner-sdk": "^1" },
|
|
225
|
+
"scripts": {
|
|
226
|
+
"build": "vite build",
|
|
227
|
+
"test": "bun test tests/mutators.test.ts",
|
|
228
|
+
"test:playwright": "bun run build && bunx playwright test",
|
|
229
|
+
"lint": "biome lint --error-on-warnings .",
|
|
230
|
+
"format:check": "biome format ."
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Re-exports** (`client.ts`):
|
|
236
|
+
```typescript
|
|
237
|
+
import type { InferSyncedStoreClient } from "joiner-sdk/v1/client.js";
|
|
238
|
+
import type { TileSchema } from "./synced-store/schema";
|
|
239
|
+
|
|
240
|
+
export type { TileSchema, tileSchema } from "./synced-store/schema"; // type-only!
|
|
241
|
+
export type TileStoreClient = InferSyncedStoreClient<TileSchema>;
|
|
242
|
+
export type { TileTableTypes } from "./synced-store/data/todos";
|
|
243
|
+
export { tileMutators } from "./synced-store/mutators/index";
|
|
244
|
+
export { tileClientConfig } from "./synced-store/client-config";
|
|
245
|
+
```
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Architecture, scaling, and performance
|
|
2
|
+
|
|
3
|
+
Your tile contains frontend code that runs on each user's Joiner client and
|
|
4
|
+
backend code that runs on our servers in datacenters around the world.
|
|
5
|
+
|
|
6
|
+
## Static assets
|
|
7
|
+
|
|
8
|
+
Your tile's UI and other static assets are served from the edge network, close
|
|
9
|
+
to every player.
|
|
10
|
+
|
|
11
|
+
## Live synced state
|
|
12
|
+
|
|
13
|
+
Most user actions in your tile will involve modifying and reading session
|
|
14
|
+
state that is persisted to our servers and synced to all members of the
|
|
15
|
+
session. We refer to this collection of state as the "synced store".
|
|
16
|
+
|
|
17
|
+
Four types of server operations interact with the synced store:
|
|
18
|
+
1. **Mutations** modify store state. For example, a user sending a message in a
|
|
19
|
+
tile that contains messaging might trigger a mutation that appends a row to the
|
|
20
|
+
store's message table. Most mutations run both on the acting user's client to
|
|
21
|
+
produce an "optimistic" result and on the server to produce an authoritative
|
|
22
|
+
result. Mutations run sequentially in the order they enter the mutation queue on the server, and each mutation has a time limit of 30 seconds.
|
|
23
|
+
2. **Actions** run only on the server and have a 10 minute time limit. They are good for asynchronous server-side
|
|
24
|
+
work, e.g. making a call to an LLM to ask a
|
|
25
|
+
question or generate an image. Actions use mutations under the hood to modify
|
|
26
|
+
store state, but these mutations are initiated on the server so they do not
|
|
27
|
+
produce any optimistic results.
|
|
28
|
+
3. **Pokes** are store updates that the server proactively pushes to
|
|
29
|
+
connected clients.
|
|
30
|
+
4. **Pulls** are the data fetches that clients make when they first
|
|
31
|
+
connect to the store, need to catch up after missing pokes, or want to fetch
|
|
32
|
+
the next page of data in paginated datasets.
|
|
33
|
+
|
|
34
|
+
Each tile instance has its own synced store in a single location: the best datacenter for the user who started the instance. Every mutation
|
|
35
|
+
updates that store, every poke fans out from it, and every pull is served
|
|
36
|
+
from it. Tile instances involving users around the world may have a higher
|
|
37
|
+
network latency, especially for sending updates to and receiving requests from
|
|
38
|
+
users far away from the synced store's datacenter.
|
|
39
|
+
|
|
40
|
+
### Each tile instance is single-threaded
|
|
41
|
+
|
|
42
|
+
The tile instance processes mutations, actions, pokes, and pulls on a single
|
|
43
|
+
thread.
|
|
44
|
+
|
|
45
|
+
Mutations use a queue and run sequentially in the order they arrive at the server. Each mutation must complete before the next mutation can start, so there are never multiple mutations running concurrently against the same store.
|
|
46
|
+
|
|
47
|
+
On the other hand, actions and pulls can interleave. Mutations triggered by actions
|
|
48
|
+
enter the same mutation queue based on the time the mutation was triggered, not
|
|
49
|
+
based on the time the action started. Actions can wait for external work like
|
|
50
|
+
calling an LLM without occupying the single thread.
|
|
51
|
+
|
|
52
|
+
Make sure your tile's mutations and actions are fast enough to support the
|
|
53
|
+
expected volume of live interactions and number of concurrent players in a
|
|
54
|
+
session. If there is more than one second of total work per second occupying the
|
|
55
|
+
instance's single thread, state updates can back up and slow down synchronization
|
|
56
|
+
between players.
|
|
57
|
+
|
|
58
|
+
### Tile instance memory
|
|
59
|
+
|
|
60
|
+
Tile instances have a 128 MiB memory limit. Things that use memory include the following:
|
|
61
|
+
|
|
62
|
+
- **Queued actions.** Actions waiting to execute still use up server memory to
|
|
63
|
+
hold the actions' inputs.
|
|
64
|
+
- **Pending pokes.** Pokes waiting for delivery consume memory, and memory usage
|
|
65
|
+
grows with the number of members in the instance, including offline members.
|
|
66
|
+
Memory usage does NOT grow with the number of connected devices per member.
|
|
67
|
+
- **File uploads from actions.** Calling `ctx.files.store(...)` creates an
|
|
68
|
+
in-memory copy of the file bytes for the upload, so that amount of server memory
|
|
69
|
+
is used for the duration of the upload. Note that this is specific to actions and is not the same thing as uploading files from the client.
|
|
70
|
+
- **Concurrent actions.** Each action uses memory, so several actions with modest
|
|
71
|
+
individual memory use can add up to a large total.
|
|
72
|
+
|
|
73
|
+
See [here](limitations.md#tile-instance-memory) for the full list of what uses memory.
|
|
74
|
+
|
|
75
|
+
Memory pressure can therefore degrade performance even at low throughput. When
|
|
76
|
+
the instance is overloaded, pulls retry with backoff and pending mutations stay
|
|
77
|
+
saved locally while their uploads slow down.
|
|
78
|
+
|
|
79
|
+
### Optimistic updates for mutations
|
|
80
|
+
|
|
81
|
+
Optimistic updates hide network and server latency from the user interacting with the
|
|
82
|
+
tile instance. Each user-triggered mutation (i.e. not triggered by an action) runs
|
|
83
|
+
immediately on the user's own device against their local copy of the store, and
|
|
84
|
+
their UI re-renders using that local "optimistic" result without waiting for a server
|
|
85
|
+
response. At the same time, the mutation is sent to the server, which runs it
|
|
86
|
+
against the server's authoritative copy of the
|
|
87
|
+
store and generates a new authoritative store state. The server pokes all users connected to
|
|
88
|
+
the tile instance so they can all update their local store and render the tile
|
|
89
|
+
UI based on the most up-to-date state. The user who triggered the mutation also
|
|
90
|
+
gets poked and replaces their optimistic local state with the server's
|
|
91
|
+
authoritative one.
|
|
92
|
+
|
|
93
|
+
### Paginated pulls
|
|
94
|
+
|
|
95
|
+
A joining client does not necessarily download the whole store. The tile can use
|
|
96
|
+
pagination to handle a large amount of data while keeping the store
|
|
97
|
+
fast for users. It does so by setting a [`sortKey`](sort-keys.md) on data rows to establish
|
|
98
|
+
a priority on them; lower priority rows can be hidden behind pagination boundaries (i.e. "paged out"). For example, each message in a
|
|
99
|
+
chat tile can have a `sortKey` that indicates its order in the chat history, such that the
|
|
100
|
+
oldest messages can be paged out and hidden behind a "load earlier messages" button.
|
|
101
|
+
|
|
102
|
+
During a pull on a tile that uses pagination, the server first sends the joining client a small chunk of data prioritized by `sortKey` of a size up to
|
|
103
|
+
[`firstRenderBytes`](limitations.md#first-render-budget): the default is 25KB but this is configurable by the tile creator. While the client begins rendering the tile UI using that chunk of data, the server gradually streams more store data to the client up to a size of [`initialLocalBudgetBytes`](limitations.md#default-local-pull-budget)
|
|
104
|
+
(default of 100KB, also configurable). Anything beyond `initialLocalBudgetBytes` loads on demand as the user
|
|
105
|
+
pages; these paging operations are also pulls and contribute to pull traffic.
|
|
106
|
+
|
|
107
|
+
Store data that is assigned the empty sort key ([`sortKey: ""`](sort-keys.md#the-performance-model-eager-vs-lazy-download)) is always sent to the client,
|
|
108
|
+
regardless of `firstRenderBytes` and `initialLocalBudgetBytes` (see
|
|
109
|
+
[always-loaded bytes](limitations.md#always-loaded-bytes)). Data written to the store
|
|
110
|
+
uses the empty sort key by default, so pagination is disabled unless the tile explicitly
|
|
111
|
+
sets [`sortKey`](sort-keys.md) during its store writes.
|
|
112
|
+
|
|
113
|
+
### Catch-up pulls after missing pokes
|
|
114
|
+
|
|
115
|
+
Pokes are not guaranteed to deliver to clients. Offline clients do not
|
|
116
|
+
receive pokes, and heavy server load may cause some pokes to get dropped.
|
|
117
|
+
Data from missed pokes is recovered by the client's next pull. Clients
|
|
118
|
+
automatically run recovery pulls immediately when the app
|
|
119
|
+
reconnects or returns to the foreground. Clients also pull immediately when
|
|
120
|
+
they receive a poke that has a higher version number than expected,
|
|
121
|
+
indicating that they missed a poke.
|
|
122
|
+
|
|
123
|
+
## Tile session user limit: 200 users
|
|
124
|
+
A single tile session can hold a maximum of 200 users. Even if your tile seats
|
|
125
|
+
much fewer users (e.g. a board game with a maximum of 4 players), additional
|
|
126
|
+
users can be added to the session to spectate or participate in the chat.
|
|
127
|
+
The server also pokes those spectating users with store updates, regardless of
|
|
128
|
+
whether or not those users can mutate the store state themselves. To restrict the
|
|
129
|
+
set of viewers to a subset of the session's members (e.g. only the active
|
|
130
|
+
players of the game), use [`privateOfUser`](data-visibility.md#method-access-matrix).
|
|
131
|
+
|
|
132
|
+
## Store size and row operations
|
|
133
|
+
|
|
134
|
+
We enforce a [live-data byte limit](limitations.md#live-data-quota) per store
|
|
135
|
+
but we do not enforce a limit on the number of tables or table rows.
|
|
136
|
+
However, mutations and actions that perform many row operations can take
|
|
137
|
+
longer to run and may hit the
|
|
138
|
+
[50,000 event-loop-tick limit](limitations.md#event-loop-ticks). Ticks count
|
|
139
|
+
host operations, such as scan-page reads or row writes, and turns that
|
|
140
|
+
process queued promises. CPU-heavy work between host operations can hit the
|
|
141
|
+
[30-second guest execution deadline](limitations.md#guest-execution-deadline).
|
|
142
|
+
Completing host operations refreshes that deadline for the next guest slice.
|
|
143
|
+
A slice that computes without ever awaiting a host operation is not caught by
|
|
144
|
+
that deadline; it runs until the store's 300-second CPU limit resets the whole
|
|
145
|
+
instance.
|
|
146
|
+
|
|
147
|
+
Store migrations are treated as mutations and are subject to the same guest
|
|
148
|
+
deadline and [event-loop-tick limit](limitations.md#event-loop-ticks). Stores
|
|
149
|
+
with many rows may therefore fail a migration that exceeds these budgets.
|
|
150
|
+
Migrations are also
|
|
151
|
+
subject to the [mutation memory limit](limitations.md#quickjs-guest-heap), so
|
|
152
|
+
avoid loading large amounts of store data into memory.
|
|
153
|
+
|
|
154
|
+
For example, prefer processing rows directly from the
|
|
155
|
+
[scan](client-api-reference.md#scanning-table-rows) iterator:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const todos = ctx.table("todos");
|
|
159
|
+
for await (const [key, value] of todos.scan().entries()) {
|
|
160
|
+
await todos.set({ ...key, value: { ...value, priority: 0 } });
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
over collecting the entire scan into an in-memory array before processing it:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const todos = ctx.table("todos");
|
|
168
|
+
const rows = await todos.scan().entries().toArray();
|
|
169
|
+
for (const [key, value] of rows) {
|
|
170
|
+
await todos.set({ ...key, value: { ...value, priority: 0 } });
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Streaming reduces memory use, but both examples still perform a write for
|
|
175
|
+
each row and remain subject to the
|
|
176
|
+
[event-loop-tick limit](limitations.md#event-loop-ticks).
|
|
177
|
+
|
|
178
|
+
If you publish a migration that consistently fails, follow the steps in
|
|
179
|
+
[Recovering from a failed migration](schema-migrations.md#recovering-from-a-failed-migration).
|
|
180
|
+
|
|
181
|
+
## Performance tips
|
|
182
|
+
|
|
183
|
+
- **If you're storing data only one user needs, use [`privateOfUser`](data-visibility.md#method-access-matrix) .** Per-user state in `privateOfUser` tables pokes one user instead of all members of the session.
|
|
184
|
+
- **Choose the right row size for your use cases.** A patch carries the full serialized value
|
|
185
|
+
of every key the mutation wrote, not a diff: updating one field of a
|
|
186
|
+
100 KB row pokes all 100 KB to every member. On the other hand, each row read
|
|
187
|
+
or written adds processing overhead, so splitting related data into many tiny rows can make
|
|
188
|
+
mutations and actions do more work than necessary. Keep independently updated
|
|
189
|
+
state in separate rows, and group data that you usually read or update together.
|
|
190
|
+
- **Batch logical changes into fewer mutations.** Prefer to batch rapid small
|
|
191
|
+
client-side changes (e.g. strokes in a drawing tile) into fewer large mutations.
|
|
192
|
+
- **Use pagination for large stores.** Use [`sortKey`](sort-keys.md)s to take advantage of
|
|
193
|
+
[`firstRenderBytes`](limitations.md#first-render-budget) and
|
|
194
|
+
[`initialLocalBudgetBytes`](limitations.md#default-local-pull-budget).
|
|
195
|
+
Configure those budgets according to the needs of the tile.
|
|
196
|
+
- **Avoid waiting on server responses.** For mutations that do not require
|
|
197
|
+
an authoritative answer from the server, rely on optimistic updates to
|
|
198
|
+
make your tile feel more responsive to users: render from store
|
|
199
|
+
subscriptions instead of awaiting a mutation's `confirmed` promise.
|
|
200
|
+
- **Offload file contents to file storage.** Use the [file upload API](file-uploads.md)
|
|
201
|
+
to keep large static content like images, attachments, and other files outside
|
|
202
|
+
of the synced store. Only the file references and metadata should be in the
|
|
203
|
+
synced store.
|
|
204
|
+
|
|
205
|
+
## Server load examples
|
|
206
|
+
|
|
207
|
+
### 20-player game
|
|
208
|
+
|
|
209
|
+
20 players make a combined 5 score updates/s. Each mutation reads all 20 player
|
|
210
|
+
rows, updates one player's score, and rewrites a shared leaderboard row containing
|
|
211
|
+
everyone's scores and ranks.
|
|
212
|
+
|
|
213
|
+
**Server work:** 100 reads of player rows, 5 leaderboard recalculations, and 10 row
|
|
214
|
+
writes per second. Each score change sends the updated player row and the full
|
|
215
|
+
leaderboard to all 20 members, for up to 5 × 20 = 100 pokes/s. Each poke
|
|
216
|
+
contains both changed rows.
|
|
217
|
+
|
|
218
|
+
**Improvement:** Update only the affected player's score row and derive the
|
|
219
|
+
displayed ranking from the synced scores on the client. The server then performs
|
|
220
|
+
5 row reads and 5 writes per second, with no full leaderboard row to
|
|
221
|
+
rebuild or send. There are still up to 100 pokes/s, but each carries only the
|
|
222
|
+
updated player row.
|
|
223
|
+
|
|
224
|
+
### 100-member chat with read receipts
|
|
225
|
+
|
|
226
|
+
100 members exchange one message/s. Each of the other 99 members sends a separate
|
|
227
|
+
mutation that creates a public read-receipt row for that message.
|
|
228
|
+
|
|
229
|
+
**Server work:** One message produces 100 mutations and 100 new rows. Each of the
|
|
230
|
+
99 receipt updates fans out to all 100 members. The message and its receipts
|
|
231
|
+
produce up to 100 × 100 = 10,000 pokes/s. Catching up on old messages produces
|
|
232
|
+
another burst of receipt mutations.
|
|
233
|
+
|
|
234
|
+
These improvements can be applied independently:
|
|
235
|
+
|
|
236
|
+
1. **Show receipts only to the message author.** Store each receipt in the author's
|
|
237
|
+
[`privateOfUser`](data-visibility.md#method-access-matrix) rows from a
|
|
238
|
+
server-guarded mutator. Each receipt mutation produces up to two pokes: one
|
|
239
|
+
carrying receipt data to the author and one confirming the mutation to the
|
|
240
|
+
reader. The mutation count stays at 100/s, while pokes fall to up to
|
|
241
|
+
100 + 99 × 2 = 298/s.
|
|
242
|
+
|
|
243
|
+
**Product tradeoff:** Other members can no longer see who has read someone
|
|
244
|
+
else's messages.
|
|
245
|
+
|
|
246
|
+
2. **Batch read progress.** Keep one public "read up to message N" row per reader
|
|
247
|
+
and update it once when they catch up on a group of messages. A reader catching
|
|
248
|
+
up on ten messages needs one mutation, one row write, and up to 100 pokes,
|
|
249
|
+
instead of ten mutations, ten row writes, and up to 1,000 pokes.
|
|
250
|
+
|
|
251
|
+
**Product tradeoff:** Read status arrives after each batch, and the tile treats
|
|
252
|
+
every message through N as read rather than tracking each message separately.
|
|
253
|
+
|
|
254
|
+
### 200-member quiz
|
|
255
|
+
|
|
256
|
+
One host runs a quiz for 199 players. All players answer within two seconds of
|
|
257
|
+
each question. Each answer mutation writes a public answer row, then scans all
|
|
258
|
+
answers collected so far for that round to rebuild the shared results.
|
|
259
|
+
|
|
260
|
+
**Server work:** 199 mutations arrive in a two-second burst. Repeatedly scanning
|
|
261
|
+
the answers reads 1 + 2 + … + 199 = 19,900 rows. Public answers and the changing
|
|
262
|
+
results fan out to all 200 members, producing up to 199 × 200 = 39,800 pokes
|
|
263
|
+
per round.
|
|
264
|
+
|
|
265
|
+
**Improvement:** Store each answer in that player's
|
|
266
|
+
[`privateOfUser`](data-visibility.md#method-access-matrix) rows. Once the round
|
|
267
|
+
closes, have the host trigger one server-guarded mutation that reads the 199
|
|
268
|
+
answers, computes the results, and publishes one shared summary. This reduces
|
|
269
|
+
answer reads from 19,900 to 199 per round and avoids broadcasting individual
|
|
270
|
+
answers to the whole group. There are up to 199 private answer pokes plus 200
|
|
271
|
+
shared result pokes: 399 pokes per round.
|
|
272
|
+
|
|
273
|
+
### 10-member drawing tile
|
|
274
|
+
|
|
275
|
+
10 members draw continuously, each producing 100 points/s. Each point triggers one mutation.
|
|
276
|
+
|
|
277
|
+
**Server work:** 1,000 mutations per second. All 1,000 updates
|
|
278
|
+
fan out to all 10 members, for up to 1,000 × 10 = 10,000 pokes/s.
|
|
279
|
+
|
|
280
|
+
**Improvement:** Render each point locally right away but batch points, flushing them into a mutation every 500ms. This reduces the load to 20 mutations per second and up to 20 × 10 = 200 pokes/s. This reduces mutation and poke overhead while sending the same points to all 10 members, with the tradeoff of making updates choppier (which can be smoothed via the tile's frontend logic).
|