@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,216 @@
|
|
|
1
|
+
# File uploads — `store.files.upload()` + the `_requestUploadUrl` grant handler
|
|
2
|
+
|
|
3
|
+
User-file uploads (photos, attachments) into a store are **app-controlled**:
|
|
4
|
+
nothing can be uploaded until the app's schema declares the reserved
|
|
5
|
+
`_requestUploadUrl` action and the backend implements it. The platform runs
|
|
6
|
+
that handler server-side before minting every upload ticket, so it is the
|
|
7
|
+
app's policy gate — who may upload, what, and when. Platform quotas and rate
|
|
8
|
+
limits apply on top.
|
|
9
|
+
|
|
10
|
+
Managed uploads support files up to 100 MiB through a signed storage PUT and an
|
|
11
|
+
authenticated completion step. The platform handles both steps behind
|
|
12
|
+
`store.files.upload()`. Files up to 10 MiB keep full inspection and image
|
|
13
|
+
sanitization. Larger PDFs and validated UTF-8 text retain their content type;
|
|
14
|
+
other large formats are served as downloads.
|
|
15
|
+
|
|
16
|
+
`ctx.files.store(bytes)` is for small files generated inside an action or the
|
|
17
|
+
server-only [live-data-limit hook](live-data-limit-hook.md). The hook publishes
|
|
18
|
+
the file and its reference atomically with its row changes. Its
|
|
19
|
+
4 MiB host payload ceiling is separate from the action's 8 MiB guest heap,
|
|
20
|
+
which also holds app state and base64/JSON copies. An action can exhaust memory
|
|
21
|
+
well below the payload ceiling. Use `store.files.upload()` for large user files;
|
|
22
|
+
their bytes do not pass through the guest VM.
|
|
23
|
+
|
|
24
|
+
Use the regular synced-store client type:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import type { InferSyncedStoreClient } from "joiner-sdk/v1/client.js";
|
|
28
|
+
import type { TileSchema } from "./synced-store/schema";
|
|
29
|
+
|
|
30
|
+
export type TileStoreClient = InferSyncedStoreClient<TileSchema>;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`InferSyncedStoreClient` includes the complete `files` namespace returned by
|
|
34
|
+
`Poe.setupStore()`: quota reads, uploads, and served-URL resolution. Do not add a
|
|
35
|
+
manual extension intersection or search generated `.d.ts` files.
|
|
36
|
+
|
|
37
|
+
## 1. Declare the reserved action in the schema
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
actions: {
|
|
41
|
+
_requestUploadUrl: {
|
|
42
|
+
description: "Approve one photo upload per player per day",
|
|
43
|
+
input: z.object({
|
|
44
|
+
fileId: z.string(),
|
|
45
|
+
sizeBytes: z.number(),
|
|
46
|
+
name: z.string().optional(),
|
|
47
|
+
}),
|
|
48
|
+
output: z.unknown(),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The leading `_` marks it platform-invoked: it is excluded from the client's
|
|
54
|
+
`store.action` surface and cannot be dispatched by clients.
|
|
55
|
+
|
|
56
|
+
## 2. Implement the grant handler (backend actions)
|
|
57
|
+
|
|
58
|
+
The handler runs on a **read-only** action context: table reads and
|
|
59
|
+
`ctx.files.generateUploadUrl` only — `ctx.mutate`, `ctx.enqueueAction`,
|
|
60
|
+
external dispatch, and `ctx.platform.call` all throw. Approve by calling
|
|
61
|
+
`ctx.files.generateUploadUrl(...)` exactly once; deny by throwing an
|
|
62
|
+
`ActionError` whose bounded code the client receives as `error.appCode`:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { ActionError } from "joiner-sdk/v1/backend.js";
|
|
66
|
+
|
|
67
|
+
const actions = {
|
|
68
|
+
_requestUploadUrl: async (ctx, input) => {
|
|
69
|
+
if (input.sizeBytes > 5 * 1024 * 1024) {
|
|
70
|
+
throw new ActionError("photo_too_large");
|
|
71
|
+
}
|
|
72
|
+
await ctx.files.generateUploadUrl({ sizeBytes: input.sizeBytes });
|
|
73
|
+
return null;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Enforce app rules in the CLAIMING MUTATOR, not here.** The handler is
|
|
79
|
+
read-only and records nothing, so it cannot serialize concurrent uploads —
|
|
80
|
+
any grant-time rule (one photo per day, one entry per round) is advisory at
|
|
81
|
+
best, and the mutator that writes the `fileRefs` claim is the authoritative
|
|
82
|
+
gate anyway (a rejected claim just lets the unclaimed upload expire). Gate
|
|
83
|
+
here only what must be decided BEFORE the bytes are uploaded: the size cap,
|
|
84
|
+
or whether uploads are open at all.
|
|
85
|
+
|
|
86
|
+
- `ctx.userId` is the platform-verified uploading member.
|
|
87
|
+
- `generateUploadUrl` takes two DISTINCT optional size params: `sizeBytes`
|
|
88
|
+
(as in the example above) re-asserts the request's declared size — a
|
|
89
|
+
mismatch rejects the grant — while `maxBytes` is an approval CEILING the
|
|
90
|
+
completion enforces, not a size selector. Neither replaces size policy:
|
|
91
|
+
enforce that by throwing before minting.
|
|
92
|
+
- Returning without minting, or minting twice, invalidates the grant
|
|
93
|
+
(`app_grant_invalid` client-side).
|
|
94
|
+
- Handlers may read the clock (actions are server-only), unlike mutators.
|
|
95
|
+
|
|
96
|
+
### Read exact quota usage
|
|
97
|
+
|
|
98
|
+
Client code can read the exact store-instance usage and limits plus the
|
|
99
|
+
acting user's attributed usage:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const usage = await store.files.getQuotaUsage();
|
|
103
|
+
// usage.instance: { bytes, count, limitBytes, limitCount }
|
|
104
|
+
// usage.user: { userId, bytes, count }
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The client method is scoped to the authenticated user. Backend actions,
|
|
108
|
+
including the read-only `_requestUploadUrl` handler, can additionally select
|
|
109
|
+
another user:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const usage = await ctx.files.getQuotaUsage();
|
|
113
|
+
// usage.instance: { bytes, count, limitBytes, limitCount }
|
|
114
|
+
// usage.user: { userId: ctx.userId, bytes, count }
|
|
115
|
+
|
|
116
|
+
const other = await ctx.files.getQuotaUsage({ userId: anotherUserId });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Omitting `userId` selects the acting user. Supplying one lets app backend code
|
|
120
|
+
inspect another user's usage in the same store instance; this does not check
|
|
121
|
+
that the selected ID is currently a member, and an unknown user has zero usage.
|
|
122
|
+
The user counters are informational and are not quota limits. The instance and
|
|
123
|
+
user counters come from one atomic snapshot. They include
|
|
124
|
+
published uploads in `ready`, `active`, and `released` state until lifecycle
|
|
125
|
+
cleanup removes the upload record, so they match quota enforcement rather than
|
|
126
|
+
only currently claimed `$files` rows.
|
|
127
|
+
|
|
128
|
+
## 3. Upload from the client and claim the file
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const file = await store.files.upload({
|
|
132
|
+
data: photoBlob, // Blob | Uint8Array
|
|
133
|
+
name: "capture.jpg", // optional display metadata
|
|
134
|
+
contentType: "image/jpeg", // hint; bytes are inspected server-side
|
|
135
|
+
});
|
|
136
|
+
// file: { status: "staged", fileId, fileKey: null, url: null,
|
|
137
|
+
// sizeBytes, contentType, width, height }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`upload()` resolves after the host durably stages canonical bytes and records
|
|
141
|
+
its upload task. It works offline. Store the returned `fileId`, then write it
|
|
142
|
+
into a field declared under the table's `fileRefs` (`string[]`). The mutation
|
|
143
|
+
appears optimistically; the host holds its server push until publication is
|
|
144
|
+
proven. The server derives the `$files` claim when it accepts the mutation.
|
|
145
|
+
Use `store.files.uploads.get(fileId)` to observe pending or failed uploads.
|
|
146
|
+
|
|
147
|
+
Local staging accepts up to 60 files or 256 MiB per store. Browser staging also
|
|
148
|
+
has a shared ceiling of 100 files or 256 MiB for the signed-in account across
|
|
149
|
+
stores and tabs on the same browser profile and origin. An upload that would
|
|
150
|
+
exceed either limit rejects with `code: "quota_exceeded"` and `quotaScope:
|
|
151
|
+
"store_staging"` or `"device_staging"`. The error message identifies the scope,
|
|
152
|
+
and `retryable: true` means a later retry can succeed after capacity is freed.
|
|
153
|
+
Pending files remain protected, including published files awaiting claim
|
|
154
|
+
settlement. Terminal failure records do not consume pending capacity.
|
|
155
|
+
|
|
156
|
+
Resolve a display URL with `store.files.url(fileId)`. Local staged and cached
|
|
157
|
+
bytes are available without a network download, including after reopening on
|
|
158
|
+
the same device. Cold reads fetch verified bytes and attempt cache admission.
|
|
159
|
+
Display URLs belong to the consuming client and remain readable until the
|
|
160
|
+
store is disposed, even if the disk entry is evicted. Persist only file IDs in
|
|
161
|
+
application rows. The current SDK Node environment uses memory for its file
|
|
162
|
+
caches and task ledger; pending uploads and cached bytes do not survive a
|
|
163
|
+
process restart.
|
|
164
|
+
|
|
165
|
+
Use `store.files.url(fileId, { target: "external" })` for an HTTP URL that can
|
|
166
|
+
be handed to a document opener or another process. An external URL requires
|
|
167
|
+
publication and connectivity when opened.
|
|
168
|
+
|
|
169
|
+
The device cache has a fixed size per store and evicts the least recently used
|
|
170
|
+
files first. To keep some files longer, pass `cachePriorityKey` to
|
|
171
|
+
`loadFile()` or `loadImage()`; pass `cache: false` to load a file without
|
|
172
|
+
caching it. Keyed files are kept over unkeyed ones, and larger keys are kept
|
|
173
|
+
longest, so the row's `sortKey` keeps recent rows' files over older ones.
|
|
174
|
+
`store.files.cache.pin(fileId, { priorityKey })` ranks the same way.
|
|
175
|
+
`unpin(fileId)` removes the original and every resized copy but leaves display
|
|
176
|
+
URLs already returned to this client readable.
|
|
177
|
+
|
|
178
|
+
Both resolve `{ url }`, a device URL for the bytes. For images, use
|
|
179
|
+
`store.files.loadImage(fileId, { size: "small" })`. `size` is
|
|
180
|
+
`thumbnail`, `small`, `medium`, or `large`: exactly 128, 384, 768, or 1536
|
|
181
|
+
pixels wide, not scaled by the screen's pixel density. It keeps the aspect
|
|
182
|
+
ratio and caches the copy on the device, so calling it before display preloads
|
|
183
|
+
the image. It rejects for a source that is not a JPEG, PNG, or WebP image, or
|
|
184
|
+
when the image is not on the device and cannot be downloaded; fall back to
|
|
185
|
+
`store.files.loadFile()`. Omit `size` for the original. `cache.unpin(fileId)`
|
|
186
|
+
removes the original and every resized copy. Check
|
|
187
|
+
`Poe.has("store.files.loadImage.url")` on older hosts. The older
|
|
188
|
+
`store.files.imageUrl(fileId, { displayWidth })` is deprecated.
|
|
189
|
+
|
|
190
|
+
Published unclaimed uploads retain their local staged bytes until an
|
|
191
|
+
authoritative claim or terminal absence is observed. A network or status
|
|
192
|
+
outage does not authorize deleting them. The server eventually expires files
|
|
193
|
+
that no row claims; a claim of an unknown or expired `fileId` rejects the
|
|
194
|
+
mutation that makes it, not the other mutations pushed with it. Publication
|
|
195
|
+
failures after staging are reported by `uploads.get()`; keep the user's draft
|
|
196
|
+
available until its claim is confirmed.
|
|
197
|
+
|
|
198
|
+
`failure.reason` names the last failure. Retryable reasons are `network` (no
|
|
199
|
+
usable server answer), `server_error` (the server answered with a 5xx), and
|
|
200
|
+
`rate_limited`. Refusals are `uploads_disabled`, `denied_by_app` (+`appCode`),
|
|
201
|
+
`quota_exceeded`, `file_too_large`, `not_authorized`, and `invalid_request`.
|
|
202
|
+
Local or lifecycle reasons are `integrity`, `expired`, and `too_many_attempts`.
|
|
203
|
+
New hosts can add reasons, so give unknown reasons a generic message and use
|
|
204
|
+
`failure.retryable` to decide whether the upload is still retrying.
|
|
205
|
+
|
|
206
|
+
Failures reject with a `FileUploadError` (guard with `isFileUploadError` from
|
|
207
|
+
`joiner-sdk/v1/client.js`): `uploads_not_enabled` (no handler declared),
|
|
208
|
+
`upload_denied_by_app` (+`appCode`), `quota_exceeded` (+`quotaScope`:
|
|
209
|
+
`"instance"` for server quota, `"store_staging"` or `"device_staging"` for
|
|
210
|
+
local staging), `rate_limited`, `file_too_large`,
|
|
211
|
+
`idempotency_conflict`, `uploads_disabled` /
|
|
212
|
+
`upload_failed` (deployment or transient; `retryable` marks safe re-invokes).
|
|
213
|
+
|
|
214
|
+
The current `bun run dev` browser host does not authenticate the managed
|
|
215
|
+
upload-ticket route, so an upload there fails with an expected local 401. Do
|
|
216
|
+
not debug that 401 by searching bundled SDK JavaScript.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Getting User Info of Members
|
|
2
|
+
|
|
3
|
+
The platform auto-populates three `$`-prefixed system tables when users connect to an app instance. Use them to render member lists, leaderboards, chat avatars, or anywhere else you need a user's display name or profile picture. Apps using `joiner-sdk`'s `defineSchema` get these tables typed automatically — you do not declare them.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [`$userInfo` — profile data](#userinfo--profile-data)
|
|
7
|
+
- [`$users` — membership roster](#users--membership-roster)
|
|
8
|
+
- [Rendering co-player avatars](#rendering-co-player-avatars)
|
|
9
|
+
- [`$permissions` — permission grants](#permissions--permission-grants)
|
|
10
|
+
- [Current user in the UI](#current-user-in-the-ui)
|
|
11
|
+
- [`getCurrentUserId` helper](#getcurrentuserid-helper)
|
|
12
|
+
- [`getUserInfo` helper](#getuserinfo-helper)
|
|
13
|
+
- [`$$system:createdBy` — who spawned this instance](#system-createdby-—-who-spawned-this-instance)
|
|
14
|
+
|
|
15
|
+
## `$userInfo` — profile data
|
|
16
|
+
|
|
17
|
+
ItemKey is the userId.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
type PoeUserInfo = {
|
|
21
|
+
userId: string;
|
|
22
|
+
username?: string; // deprecated legacy field; do not use for labels
|
|
23
|
+
handle?: string; // public profile handle, when set
|
|
24
|
+
displayName: string;
|
|
25
|
+
profilePicture: string; // URL
|
|
26
|
+
isDev?: boolean; // synthetic dev user
|
|
27
|
+
_pendingSync?: true; // optimistic first-mount row, omitted after server sync
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Retained after a user is removed, so apps can still render historical content (past messages, past moves) with the original author's name and avatar.
|
|
32
|
+
|
|
33
|
+
## `$users` — membership roster
|
|
34
|
+
|
|
35
|
+
Tracks who has joined the store instance. ItemKey is the userId.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
type UserMembership = {
|
|
39
|
+
userId: string;
|
|
40
|
+
addedAt: number; // timestamp
|
|
41
|
+
addedBy: string; // userId of who added them, "system" for auto-add
|
|
42
|
+
removedAt?: number; // set when removed
|
|
43
|
+
removedBy?: string;
|
|
44
|
+
isDev?: boolean;
|
|
45
|
+
_pendingSync?: true; // optimistic first-mount row, omitted after server sync
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// All current members
|
|
49
|
+
store.subscribe(
|
|
50
|
+
(tx) => tx.table("$users").entries().toArray(),
|
|
51
|
+
(entries) => {
|
|
52
|
+
const members = entries
|
|
53
|
+
.map(([, v]) => v as UserMembership)
|
|
54
|
+
.filter((u) => !u.removedAt);
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
When a newly-created instance first mounts, the kernel may seed `$$system.room`,
|
|
60
|
+
`$users`, and `$userInfo` optimistically before the first server pull. Those
|
|
61
|
+
temporary rows carry `_pendingSync: true`; the authoritative server rows omit
|
|
62
|
+
the field.
|
|
63
|
+
|
|
64
|
+
## Rendering co-player avatars
|
|
65
|
+
|
|
66
|
+
Showing the people a user is playing with **and against** — their faces, where
|
|
67
|
+
the action is — is a core part of what makes a social game rewarding, not a
|
|
68
|
+
nice-to-have. It is the shift online poker made in the early 2010s, when player
|
|
69
|
+
avatars and profile pictures replaced anonymous names around the table: an
|
|
70
|
+
otherwise anonymous game became a moment between people.
|
|
71
|
+
Render co-players and opponents beside their in-app representation (their seat,
|
|
72
|
+
their move, their score row) and at the moments that matter (whose turn it is,
|
|
73
|
+
who just moved, the end-of-game results).
|
|
74
|
+
|
|
75
|
+
The recipe is: enumerate current members from `$users`, look each up in
|
|
76
|
+
`$userInfo` for a name + avatar, and render them — designing for the user who
|
|
77
|
+
has not set a photo yet (fall back to initials, never a broken image).
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { usableDisplayName } from "joiner-sdk/v1/shared.js";
|
|
81
|
+
|
|
82
|
+
// Subscribe to the current members and their profiles together. The table
|
|
83
|
+
// reads are async, so the subscribe query must AWAIT them (the callback
|
|
84
|
+
// receives the resolved value). Read each user id from the row VALUE
|
|
85
|
+
// (`UserMembership.userId` / `PoeUserInfo.userId`), not the entry key —
|
|
86
|
+
// `entries().toArray()` yields `[EntryKey, value]` and `EntryKey` is an object
|
|
87
|
+
// (`{ itemKey, sortKey? }`), not the string user id.
|
|
88
|
+
store.subscribe(
|
|
89
|
+
async (tx) => {
|
|
90
|
+
const [memberships, infos] = await Promise.all([
|
|
91
|
+
tx.table("$users").entries().toArray(),
|
|
92
|
+
tx.table("$userInfo").entries().toArray(),
|
|
93
|
+
]);
|
|
94
|
+
const infoByUser = new Map(
|
|
95
|
+
infos.map(([, info]) => [(info as PoeUserInfo).userId, info as PoeUserInfo]),
|
|
96
|
+
);
|
|
97
|
+
return memberships
|
|
98
|
+
.map(([, u]) => u as UserMembership)
|
|
99
|
+
.filter((u) => !u.removedAt)
|
|
100
|
+
.map((u) => {
|
|
101
|
+
const info = infoByUser.get(u.userId);
|
|
102
|
+
// The platform normalizes an absent profilePicture to "" (not
|
|
103
|
+
// undefined), so treat the empty string as missing → initials fallback.
|
|
104
|
+
const photo = info?.profilePicture ? info.profilePicture : null;
|
|
105
|
+
// The shared helper prefers displayName, falls back to the public
|
|
106
|
+
// handle, and rejects internal ids. Choose copy that fits your app
|
|
107
|
+
// when neither is available.
|
|
108
|
+
const name = usableDisplayName(info) || "Player";
|
|
109
|
+
return {
|
|
110
|
+
userId: u.userId,
|
|
111
|
+
displayName: name,
|
|
112
|
+
profilePicture: photo,
|
|
113
|
+
// Avatar derives nothing from displayName — pass `initials` yourself.
|
|
114
|
+
// First letters of up to two name words, e.g. "Ada Lovelace" → "AL".
|
|
115
|
+
initials:
|
|
116
|
+
name
|
|
117
|
+
.split(/\s+/)
|
|
118
|
+
.slice(0, 2)
|
|
119
|
+
.map((w) => w[0]?.toUpperCase() ?? "")
|
|
120
|
+
.join("") || "?",
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
(players) => renderPlayers(players),
|
|
125
|
+
);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Design for the missing photo. A user who has not set a `profilePicture` must
|
|
129
|
+
still read as a person — show their initials (first letters of `displayName`)
|
|
130
|
+
on a colored chip, never a broken `<img>` or an empty circle.
|
|
131
|
+
|
|
132
|
+
Standalone creator/game tiles should render people in the game's own visual
|
|
133
|
+
style. Pass or derive initials yourself for the fallback; do not rely on
|
|
134
|
+
`displayName` being inferred automatically.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## `$permissions` — permission grants
|
|
138
|
+
|
|
139
|
+
ItemKey is `{userId}/{permission}`. Rows are hard-deleted on revocation.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
type UserPermission = {
|
|
143
|
+
userId: string;
|
|
144
|
+
permission: string;
|
|
145
|
+
grantedAt: number;
|
|
146
|
+
grantedBy: string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// In a mutator
|
|
150
|
+
const perm = await ctx.table("$permissions").get(`${ctx.userId}/admin`);
|
|
151
|
+
const isAdmin = perm !== undefined;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Current user in the UI
|
|
155
|
+
|
|
156
|
+
`ctx.userId` is only exposed to mutators and subscribe/query callbacks — not to code that just holds a store reference. Inside a subscribe/query callback, read the current user's row directly:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const [myInfo, setMyInfo] = useState<PoeUserInfo | null>(null);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
const unsub = store.subscribe(
|
|
163
|
+
(tx) => tx.table("$userInfo").get(tx.userId),
|
|
164
|
+
(info) => setMyInfo(info ?? null),
|
|
165
|
+
);
|
|
166
|
+
return unsub;
|
|
167
|
+
}, [store]);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## `getCurrentUserId` helper
|
|
171
|
+
|
|
172
|
+
When you only need the userId itself (not the full profile) and you're outside a subscribe/query callback — e.g. in an async init hook, a SolidJS resource, or a one-shot read at app mount — use `getCurrentUserId`:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { getCurrentUserId } from "joiner-sdk/v1/client.js";
|
|
176
|
+
|
|
177
|
+
// Once at app mount:
|
|
178
|
+
const userId = await getCurrentUserId(store);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
It runs a one-shot query that resolves to `tx.userId`. For per-render reactive access, prefer reading `tx.userId` inside a `store.subscribe()` query callback (see "Current user in the UI" above).
|
|
182
|
+
|
|
183
|
+
## `getUserInfo` helper
|
|
184
|
+
|
|
185
|
+
`getUserInfo` and `usableDisplayName` from `joiner-sdk/v1/shared.js` work
|
|
186
|
+
anywhere you have a `ctx` (mutators, query callbacks, subscribe callbacks):
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import {
|
|
190
|
+
getUserInfo,
|
|
191
|
+
usableDisplayName,
|
|
192
|
+
} from "joiner-sdk/v1/shared.js";
|
|
193
|
+
|
|
194
|
+
const info = await getUserInfo(ctx, ctx.userId);
|
|
195
|
+
const name = usableDisplayName(info) || "Player";
|
|
196
|
+
// info?.displayName, info?.handle, info?.profilePicture
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## `$$system:createdBy` — who spawned this instance
|
|
200
|
+
|
|
201
|
+
Records the app instance that originally opened the current one (via `apps.openChild` or analogous platform entry point). Useful for "open the parent" affordances, attribution in shared timelines, and analytics.
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
type CreatedByValue = {
|
|
205
|
+
storeTypeId: string;
|
|
206
|
+
instanceId: string;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// In a mutator or subscribe/query callback
|
|
210
|
+
const spawner = await ctx.table("$$system").get("createdBy");
|
|
211
|
+
if (spawner) {
|
|
212
|
+
// spawner.storeTypeId, spawner.instanceId
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Semantics:
|
|
217
|
+
|
|
218
|
+
- **First-writer-wins.** Written by the platform on the first request that arrives with a `parent` origin. Never overwritten — even if a different parent later opens the same instance, the original spawner stays recorded.
|
|
219
|
+
- **Absent for root apps.** Apps opened directly (not via `apps.openChild`) have no `createdBy` row.
|
|
220
|
+
- **Absent for cross-store fan-out targets.** Instances first reached only via a system mutator's `mutateExternal` (e.g. a room dispatching `$addUsers` to a member) do NOT record `createdBy` — the row reflects only direct opens.
|
|
221
|
+
- **Absent for legacy instances.** Stores that existed before this feature shipped will not have the row.
|
|
222
|
+
- **Not used for trust.** `createdBy` is observational. Authorize decisions continue to use the live origin and `$$system:room`.
|
|
223
|
+
|
|
224
|
+
App code must always tolerate `undefined`.
|
|
225
|
+
|
|
226
|
+
## Do Not Write to These Tables
|
|
227
|
+
|
|
228
|
+
App mutators can read but not write `$userInfo`, `$users`, `$permissions`, or `$$system`. Only the platform's built-in system mutators and the platform's `beforeMutations` hook produce changes. Treat them as read-only tables populated by the platform.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Synced-store limits
|
|
2
|
+
|
|
3
|
+
This table describes the synced-store behavior shipped on `main`. Sizes are UTF-8 bytes — the same unit as the wire and the live-data quota; multi-byte characters cost 2–4 bytes each — unless a row says otherwise.
|
|
4
|
+
|
|
5
|
+
| Area | Limit or rule | Value | Options and notes |
|
|
6
|
+
| --- | --- | --- | --- |
|
|
7
|
+
| Store data | <a id="live-data-quota"></a>Live-data quota | 1,073,741,824 UTF-8 bytes (1 GiB) per store by default | Counts every live public, private, server-only, system table row as the UTF-8 byte length of `sortKey + storedTableName + itemKey + JSON.stringify(value)`. Non-ASCII text therefore costs more than its character count: 2 bytes for most accented Latin, 3 for CJK, 4 for emoji. Tombstones, metadata, and file/blob contents do not count. The exact boundary is allowed; a growth past it fails with `TotalDatabaseSizeExceededError`. An over-limit store may still shrink. The platform configures this quota; apps should prune or split growing collections. A store still awaiting the platform's exact-accounting backfill is not enforced. |
|
|
8
|
+
| Store data | Total live rows | No count limit | Rows across all tables and users share the live-data byte quota. |
|
|
9
|
+
| Writes | Key length | 1,786 UTF-8 bytes | Measures `tableName + ":" + itemKey` as UTF-8 bytes — the same unit the live-data quota meters, so an ASCII character costs 1 byte and most emoji cost 4. `sortKey` is excluded (it has its own row below). Enforced by client and server with `KeyTooLargeError`. `maxKeyLength` may impose a smaller client limit (also UTF-8 bytes) but cannot raise the server limit. |
|
|
10
|
+
| Keys | Sort key | 65,536 UTF-8 bytes (64 KiB) | Independent of the table/item key allowance. Enforced by client, trusted host, and server with `KeyTooLargeError`; the exact boundary is allowed. Exported as `MAX_SORT_KEY_BYTES`; importing it from the client SDK requires runtime version 38 (`poeTile({ minSdkVersion: 38 })`, also inferred by the Vite plugin). The complete key returned by `getNextSortKey()` includes the namespace, slash, and counter suffix. Scan keys, prefixes, cursors, and pull namespaces use the same byte allowance. Shorten keys or store large content in the value. |
|
|
11
|
+
| Writes | Serialized value | 1,048,576 UTF-8 bytes (1 MiB) | Measures the UTF-8 byte length of `JSON.stringify(value)` — an ASCII string can contain at most 1,048,574 characters (its quotes count), while multi-byte characters cost 2–4 bytes each. Enforced by client and server with `ValueTooLargeError`. `maxValueLength` may impose a smaller client limit (also UTF-8 bytes). Validation, the live-data quota, and the transport all measure UTF-8, so one validated value always fits a push frame — but a whole mutation rides one frame under a budget below the transport limit, and a single over-budget mutation is rejected client-side rather than split. Split or separately send writes when one mutation carries many large values. |
|
|
12
|
+
| Writes | Rows per mutation | No count limit | Client and server mutations remain subject to the live-data byte quota, key/value limits, transport limits, and execution budgets. Keep bulk work bounded to fit those limits. |
|
|
13
|
+
| Writes | Client-side mutation rate breaker | 200 mutations in any fixed 2-second window | Enforced in the trusted host, per mounted tile per tab. This is a breaker for runaway write loops (a mutation re-triggered by its own subscription), not a rate to design toward: apps that commit coalesced results instead of per-frame input (see [architecture-scaling-and-performance.md](architecture-scaling-and-performance.md)) run far below it. If a client exceeds it, the platform unmounts the tile and replaces it with an error UI headed **“This tile was stopped.”** The UI explains that the app sent too many state mutations, shows a reference ID, and offers a **Retry** button. |
|
|
14
|
+
| Writes | `pendingMutationDedupeKey` | 256 UTF-8 bytes | Client-enforced; shorten the key or omit it. |
|
|
15
|
+
| Writes | Mutation atomicity | All or nothing | If a mutator throws or breaches a limit, none of its writes commit. Other mutations in the same push may still commit. Server state is authoritative, so use `onFailedMutation` and `onBackgroundError` for failures discovered after the optimistic pass. |
|
|
16
|
+
| Keys | Reserved characters | `:` and null (`\0`) are forbidden in `tableName`, `itemKey`, and `sortKey`; `itemKey` must be non-empty | `$`-prefixed tables are platform-owned and `$$`-prefixed tables are reserved internals. Choose another key encoding. |
|
|
17
|
+
| Values | Supported types | JSON only | Supported: string, number, boolean, null, arrays, and plain objects. Serialize `Date`, `BigInt`, `Map`, `Set`, `ArrayBuffer`, class instances, and `undefined` before writing. |
|
|
18
|
+
| Transport | Client-to-server message | 5,242,880 UTF-8 bytes (5 MiB) for the entire frame | Breach closes the WebSocket with code `1009`. One push can contain multiple mutations plus envelope overhead, so split or separately send writes when the whole frame approaches the limit. |
|
|
19
|
+
| Transport | Push envelope budget | 4,194,304 UTF-8 bytes (4 MiB) | The frame limit minus the serialized-value cap. The client batches pending mutations into pushes up to this size and splits larger sets across pushes automatically, so every legal single-value mutation stays sendable with framing headroom. A single mutation whose serialized values exceed the budget is rejected client-side rather than split (see the Serialized value row). |
|
|
20
|
+
| Transport | Concurrent pushes | 6 per client | Bounds parallel in-flight WebSocket pushes; additional pushes queue client-side in order and drain as responses arrive. |
|
|
21
|
+
| Transport | Server-to-client message | 33,554,432 UTF-8 bytes (32 MiB) Cloudflare ceiling; synced-store targets pull responses below 8,388,608 UTF-8 bytes (8 MiB) | Large logical sort-key groups are split across numbered response messages, keeping ordinary pull frames comfortably below the deployed transport ceiling. |
|
|
22
|
+
| Transport | Data sharing one `sortKey` | Bounded by the store quota, not by one transport frame | A sort-key group remains atomic to application code. The server may stream it through multiple messages; the client buffers all fragments before applying, persisting, widening its loaded range, or notifying subscribers. A missing or malformed fragment aborts the version seal and retries the pull. Use multiple sort keys for independently pageable data, not to work around frame size. |
|
|
23
|
+
| Pulling | <a id="default-local-pull-budget"></a>Default local pull budget | 100,000 estimated bytes (100 KB) | This is a target, not a hard cap; a whole sort-key group may exceed it. Set `initialLocalBudgetBytes` to change the initial target. There is no load-everything sentinel: `0` disables budgeted expansion and eviction — clients still receive always-loaded (`sortKey: ""`) rows, each outward pull window's initial anchor group, and updates to ranges they already loaded, but nothing expands beyond that. To keep a whole store resident, set a budget comfortably above the store's size — the pull budget meters a separate client-cache estimate (a fast approximation using JavaScript string lengths — most characters count 1 and emoji count 2, so multi-byte text counts fewer than its live-data bytes — plus roughly 50 bytes of per-row overhead), so a store of many small rows needs a budget several times its live-data bytes — and make sure the schema's pull windows cover the rows. The client also adjusts the budget at runtime. |
|
|
24
|
+
| Pulling | <a id="first-render-budget"></a>First-render budget | 25,000 estimated bytes (25 KB) by default | Set schema `firstRenderBytes` to override the target for the first page across all pull windows. Metered by the same client-cache estimate as the local pull budget above — not live-data UTF-8 bytes, so a multi-byte-text-heavy first page can be 2–3× its stated budget in real bytes. A whole sort-key group can exceed it, and always-loaded rows do not consume it. |
|
|
25
|
+
| Pulling | Always-loaded rows | No separate row cap; bounded by the total store quota | `sortKey: ""` is read as one complete logical group. Put growing data behind non-empty sort keys so clients can page and evict it. |
|
|
26
|
+
| Pulling | <a id="always-loaded-bytes"></a>Always-loaded bytes | Exempt from pull budgets; bounded by the total store quota | Always-loaded rows are streamed in bounded transport fragments when needed, but every client still buffers and loads the complete `sortKey: ""` group on every pull. Keep it small for client memory and bandwidth. |
|
|
27
|
+
| Cross-store | External mutation targets per commit | 200 unique `(storeTypeId, instanceId)` pairs | Multiple mutations to one target count once; a breach rejects the mutation. |
|
|
28
|
+
| Cross-store | Direct external mutation depth | 1 | A mutator reached by `mutateExternal` cannot call `mutateExternal` again. Indirect action hops share the 10-hop action-depth limit. |
|
|
29
|
+
| Cross-store | External read items | 1,000 per read | Results are truncated. Page or narrow the read. |
|
|
30
|
+
| Cross-store | External read payload | 1,048,576 bytes (1 MiB) per read | Results are truncated. Page or narrow the read. |
|
|
31
|
+
| Cross-store | External read timeout | 5 seconds | The read fails on timeout. Keep the target query bounded. |
|
|
32
|
+
| Cross-store | Unconfirmed optimistic external | 5 minutes | The client reverts an overlay that remains unconfirmed past the TTL. Dispatch is detached from the source push; retryable infrastructure failures may be retried, so receivers must be idempotent or convergent. Ordinary mutator failures and overload responses are not retried. |
|
|
33
|
+
| Cross-store | Watched external stores | 16 per session | Further watch requests are rejected. Unwatch targets that are no longer needed. |
|
|
34
|
+
| Cross-store | Pending dispatches | 1,000 waiting per target, plus the active RPC | Overflow fails immediately. Reduce source fan-out or target recovery time. |
|
|
35
|
+
| Server execution | <a id="guest-execution-deadline"></a>Guest execution deadline | 30 seconds of wall-clock time per guest execution slice | Measured in wall-clock time while your code runs, per mutator, action, or hook call; trusted host operations refresh the deadline when they settle, so this is not a total wall-clock limit on host I/O. Because the budget is wall time on the instance's single thread, identical compute can take longer under concurrent load — leave headroom rather than designing near the deadline. Bound scans and external work. The deadline is checked against a clock that does not advance while your code computes without awaiting a host operation, so a slice that never yields is not stopped at 30 seconds: it runs until the store's CPU limit (300 seconds) resets the instance, failing every request in flight on that store. Never write an unbounded synchronous loop. |
|
|
36
|
+
| Server execution | <a id="host-wait-bound"></a>Host operation wait | 300,000 milliseconds (5 minutes) per awaited host operation | Applies to every mutator, action, and hook call. When an awaited `ctx.platform.call`, model-stream read, table or scan operation, or `ctx.sleep` has not settled after 300,000 milliseconds, the whole call fails; your code cannot catch it, and the host work is not cancelled. Concurrent host operations awaited together share one bound. Cross-store `.action()` calls and server-action `ctx.mutate` are exempt, because the called code bounds its own host operations. This is not a total wall-clock limit: each settled host operation restarts the bound. |
|
|
37
|
+
| Server execution | `structuredClone` | Available in mutators, actions and module scope | Copies plain objects, arrays, `Date`, `RegExp`, `Map`, `Set`, `ArrayBuffer`, typed arrays and `DataView`, keeping shared references and cycles. Errors keep `message` and `stack` but lose `cause` and other properties. Functions, symbols, `WeakMap`, `WeakSet`, `WeakRef`, `FinalizationRegistry`, `Promise`, iterators and generators (sync or async), `SharedArrayBuffer`, detached or out-of-bounds buffers and views, and a non-empty `transfer` list throw an error named `DataCloneError`; on the server it is an `Error`, not a `DOMException`, so check `error.name`. A `Proxy` (for example reactive-state objects) throws in the browser but is copied as plain data on the server, so do not rely on either. |
|
|
38
|
+
| Server execution | Action retry delays | 30,000 milliseconds cumulative per action invocation | `ctx.sleep(ms)` accepts integer milliseconds from 0 through 30,000. Sequential and concurrent requests share the allowance; exceeding it rejects before creating a timer. It is a retry delay, not a timeout or cancellation mechanism for another host call. |
|
|
39
|
+
| Server execution | <a id="tile-instance-memory"></a>Tile instance memory | 134,217,728 bytes (128 MiB) | Includes QuickJS memory, queued action inputs, pending pokes, and file-upload buffers. |
|
|
40
|
+
| Server execution | <a id="quickjs-guest-heap"></a>QuickJS guest heap | 50,331,648 bytes (48 MiB) per mutation/schema context; 8,388,608 bytes (8 MiB) per action context | Includes loaded code and retained module state. Mutations called from an action share its limit of 8,388,608 bytes (8 MiB). Exceeding the cap fails the operation. Prefer bounded scans over materializing a growing table. These caps are not memory reservations. |
|
|
41
|
+
| Server execution | Shared QuickJS memory | 115,343,360 bytes (110 MiB) of shared WASM engine memory per store instance | All of the store's action and mutation contexts share this capacity, including retained runtimes and allocator overhead. An operation can exhaust the shared capacity before reaching its own guest limit. Host JavaScript and buffers consume additional memory outside this cap. |
|
|
42
|
+
| Server execution | <a id="event-loop-ticks"></a>Event-loop ticks | 50,000 per call | Counts each host operation drained, plus turns that only process queued promises. Exceeding the budget fails the call. Bound loops and recursive work; parallel host operations still count separately. |
|
|
43
|
+
| Server execution | Enqueued-action chain | 10 hops | The next hop is rejected. Intermediate commits are not rolled back. |
|
|
44
|
+
| Server execution | Concurrent QuickJS actions | 8 active per store instance | Additional top-level actions queue. A nested action is rejected immediately when all slots are occupied to avoid deadlock. |
|
|
45
|
+
| Server execution | Active plus queued actions | 64 total (8 active and 56 queued) | Further attempts are refused before execution; connected clients keep waiting and retry with backoff. |
|
|
46
|
+
| Server execution | Action queue wait | 30 seconds | The attempt leaves the server queue without executing; connected clients retry with backoff. This is not a total client wait limit. |
|
|
47
|
+
| Server execution | Optimistic-lock commit retry | 3 retries after the first attempt on retry-enabled paths | App pushes and mutations invoked from server actions are not retried server-side on a conflicted commit; clients re-push conflicted writes with backoff until they commit. Only platform maintenance paths use the bounded retries. |
|
|
48
|
+
| Agent replies | Pending reply attempts | 256 per agent instance, shared across all chats using that instance | Counts queued and in-flight reply attempts, including accepted work still awaiting delivery. A new attempt past the cap is rejected with `Reply observer pending capacity exceeded; retry after earlier replies recover`; retrying an already-accepted attempt is always admitted — reuse the original attempt identity. Back off new submissions while full and retry after earlier replies finish or recover. |
|
|
49
|
+
| Server queueing | Waiting mutation entries | 1,000 | Overflow rejects new queue entries. This is a backpressure bound rather than an app data-model allowance. |
|
|
50
|
+
| Identifiers | `storeTypeId` and instance ID | 128 UTF-8 bytes for a `storeTypeId`, 256 UTF-8 bytes for an instance ID | Enforced where identifiers enter the platform, not on every route: instance creation caps both at 256 bytes, and the tile RPC boundary caps `storeTypeId` at 128 bytes and instance IDs at 256 bytes for external-store pulls and background sync; external-store mounts accept `storeTypeId`s up to 1,000 bytes. Tile handles, which become `storeTypeId`s, are capped at 100 (ASCII only — `a-z`, `0-9`, `-` — so bytes and characters agree). Internal registration paths accept more, but staying within the app-facing bounds above is what guarantees every path accepts the identifier. |
|
|
51
|
+
| Storage | Rows per table | No count limit | No separate per-table cap. Enforce an app-level retention policy and use sort keys for lazy loading. |
|
|
52
|
+
| Storage | Tables per store | Unbounded | Prefer a stable, bounded schema; the live-data byte quota still applies across their rows. |
|
|
53
|
+
| Storage | Server-side rows per transaction | Not counted | Server-only writes, hooks, platform system mutators and schema migrations are bounded by the live-data byte quota and the server execution limits. Keep them bounded yourself. |
|
|
54
|
+
| Storage | Pending mutations while offline | Unbounded | Long offline sessions can accumulate indefinitely; keep mutations small and avoid high-frequency writes while disconnected. |
|
|
55
|
+
| Storage | Tombstone growth | Self-managing, not capped | The platform bounds tombstone accumulation and cleans up incrementally; deleted rows do not count against the live-data quota. |
|
|
56
|
+
| Storage | Concurrent clients per instance | Unbounded by synced-store | Actual capacity is constrained by the hosting process and workload. |
|
|
57
|
+
| Storage | Subscriptions per client | Unbounded | App code should release subscriptions that are no longer needed. |
|
|
58
|
+
| Storage | Search index size | Unbounded | Apply an app-level indexing and retention policy. |
|
|
59
|
+
| Mutators | Determinism | Required | Mutators run optimistically and authoritatively. Pass timestamps, random IDs, and desired final values as inputs; do not generate them with `Date.now()`, `Math.random()`, or toggle expressions. See [mutator rules](mutator-rules.md). |
|
|
60
|
+
| Mutators | External calls | Not allowed | Use [actions](actions.md) for platform calls (`ctx.platform.call`). Store code cannot make direct requests to arbitrary external hosts: the backend runtime's `fetch` throws, and the client iframe's Content Security Policy blocks third-party hosts. `ctx.serverOnly()` and another user's private data are unavailable on the client, so guard server-only access with `ctx.isServer`. |
|
|
61
|
+
| Actions | Client execution | Server-only | Actions have network latency and no optimistic result. `ctx.enqueueAction()` is a no-op during the client pass. |
|
|
62
|
+
| Connections | Duplicate `clientId` | One active connection | The newer connection kicks the older one with code `4000`. Use one stable, unique client ID per tab/session. |
|
|
63
|
+
| Connections | Terminal close codes | `4000` kicked; `4001` auth failed; `4002` library mismatch; `4003` store not found | These do not reconnect automatically. Reload or correct the underlying identity/auth/version issue. |
|
|
64
|
+
| Connections | Reconnectable close codes | `1000` and `1006` | The client reconnects with backoff. Code `1009` means the outbound client frame was too large; shrink the pending mutation or it can repeat after reconnect. |
|
|
65
|
+
| Sync | Fast real-time multiplayer | Works, with visible delay | Every change travels through the instance's one server before other players see it, so shooters, racing, fighting, and other games that sync positions or hits between players many times a second feel laggy and jumpy, and worse for players far from that server. A player's own input feels instant; everyone else's arrives late. Prefer turn-based play, asynchronous competition (score chases, ghost runs, leaderboards), co-op where exact timing does not decide the outcome, or simulating locally and syncing only results. See [live synced state](architecture-scaling-and-performance.md#live-synced-state). |
|
|
66
|
+
| Conflicts | Merge behavior | Last writer wins per row key | There is no field-level merge, CRDT, or custom conflict callback. Use finer-grained rows when independent fields must merge. |
|
|
67
|
+
| Client cache | Eviction threshold | More than 1.2 times the local pull budget | The client evicts least-important cached data and refetches it on a later pull. Raise `initialLocalBudgetBytes`, call the runtime load-more API, or improve pull windows when the working set should stay resident. |
|
|
68
|
+
|
|
69
|
+
Apps can use [the live data limit hook](live-data-limit-hook.md) to compact
|
|
70
|
+
records or archive them to files in the same mutation when a growing store reaches 80% of its
|
|
71
|
+
live data allowance.
|
|
72
|
+
|