@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,263 @@
|
|
|
1
|
+
# SyncedStoreClient API Reference
|
|
2
|
+
|
|
3
|
+
Full reference for the store client returned by `Poe.setupStore(...)`. For the typed wrapper, see `InferSyncedStoreClient<Schema>` in [api-patterns.md](api-patterns.md).
|
|
4
|
+
|
|
5
|
+
## Typed Client
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import type { InferSyncedStoreClient } from "joiner-sdk/v1/client.js";
|
|
9
|
+
import type { TodoSchema } from "./schema";
|
|
10
|
+
|
|
11
|
+
export type TodoStoreClient = InferSyncedStoreClient<TodoSchema>;
|
|
12
|
+
// Gives you typed: store.mutate.setTodo, store.subscribe, store.action.generateWithAI, etc.
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Reading Data
|
|
16
|
+
|
|
17
|
+
### `query(fn)` — One-time read
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const todo = await store.query((ctx) => ctx.table("todos").get("todo-1"));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### `subscribe(queryFn, callback)` — Reactive updates
|
|
24
|
+
|
|
25
|
+
The callback fires once with the current result, then whenever an exact key or
|
|
26
|
+
scan prefix read through `ctx` changes. Reads from values captured outside
|
|
27
|
+
`ctx` are not storage dependencies. After changing a captured value that affects
|
|
28
|
+
the query, call `subscription.refresh()` to re-run the query and replace its
|
|
29
|
+
tracked dependencies.
|
|
30
|
+
|
|
31
|
+
The return value is a `SubscriptionControl`: call it as a function to
|
|
32
|
+
unsubscribe, or call `refresh(): Promise<void>` to refresh the result and its
|
|
33
|
+
dependencies.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
let selectedListId = "inbox";
|
|
37
|
+
const subscription = store.subscribe(
|
|
38
|
+
(ctx) => ctx.table("todos").scan({ prefix: { itemKey: `${selectedListId}/` } }).values().toArray(),
|
|
39
|
+
(todos) => renderTodoList(todos),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
selectedListId = "today";
|
|
43
|
+
await subscription.refresh();
|
|
44
|
+
subscription(); // unsubscribe during cleanup
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Scanning table rows
|
|
48
|
+
|
|
49
|
+
**Signature:** `table.scan(options?: ScanOptions): ScanResult<T>`
|
|
50
|
+
|
|
51
|
+
Available on table handles such as `ctx.table("todos")` in queries,
|
|
52
|
+
subscriptions, mutators, actions, and migrations. `T` is the table's row value
|
|
53
|
+
type. Rows are ordered by `(sortKey, itemKey)`; an omitted sort key is treated
|
|
54
|
+
as `""`.
|
|
55
|
+
|
|
56
|
+
All options are optional:
|
|
57
|
+
|
|
58
|
+
| Option | Type and behavior |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `prefix` | `{ sortKey?: string; itemKey?: string }`. Match the supplied key prefixes; when both are supplied, both must match. |
|
|
61
|
+
| `exactSortKey` | `string`. Match one complete sort key; `""` matches only rows with an empty sort key. Cannot be combined with `prefix.sortKey`. |
|
|
62
|
+
| `cursor` | An `EntryKey` (`{ itemKey: string; sortKey?: string }`), `"$first"`, or `"$last"`. Start strictly past this position in the scan direction, or use it as the anchor for `aroundCursor`. |
|
|
63
|
+
| `limit` | `number`. Return at most this many rows. Without it, there is no result-count bound unless `aroundCursor` is used. Cannot be combined with `aroundCursor`. |
|
|
64
|
+
| `reverse` | `boolean`, default `false`. Return rows in descending `(sortKey, itemKey)` order. |
|
|
65
|
+
| `aroundCursor` | `{ before: number; after: number }`. Return up to `before` rows before the cursor, the cursor row if present, and up to `after` rows after it. Requires `cursor`; both counts must be non-negative. Client-only: server-side scans reject this option. |
|
|
66
|
+
|
|
67
|
+
`scan()` returns an async iterator immediately; do not await the call itself.
|
|
68
|
+
Choose the view you need:
|
|
69
|
+
|
|
70
|
+
| Result view | Each iteration yields |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `scan` itself or `scan.values()` | A row value of type `T` |
|
|
73
|
+
| `scan.entries()` | An `[EntryKey, T]` pair |
|
|
74
|
+
| `scan.keys()` | An `EntryKey` |
|
|
75
|
+
|
|
76
|
+
Consume a view with `for await`. On the server, iteration reads bounded pages.
|
|
77
|
+
Every view also has `.toArray()`, which returns a promise for an array of all
|
|
78
|
+
**remaining** results and retains them in memory. Use it for explicitly limited
|
|
79
|
+
pages or bounded collections. For streaming row updates, see the
|
|
80
|
+
[migration example](architecture-scaling-and-performance.md#store-size-and-row-operations).
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const scan = ctx.table("todos").scan({ limit: 50 });
|
|
84
|
+
const rows = await scan.entries().toArray(); // Array<[EntryKey, Todo]>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For ordering and pagination examples, see
|
|
88
|
+
[scanning ordered data](sort-keys.md#scanning-ordered-data).
|
|
89
|
+
|
|
90
|
+
## Writing Data
|
|
91
|
+
|
|
92
|
+
### `mutate` — Optimistic mutations
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const { id, confirmed } = await store.mutate.setTodo({ id: "abc", text: "Buy milk" });
|
|
96
|
+
await confirmed; // optionally wait for server
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The result may also include `identity: { clientId, id }` (`MutationIdentity`, exported by `joiner-sdk/v1/client.js`). This identifies the originating mutation within its store. `confirmed` means the mutation was processed, including rejection; it does not prove that the requested data was accepted.
|
|
100
|
+
|
|
101
|
+
#### `pendingMutationDedupeKey` — collapse repeated pending mutations
|
|
102
|
+
|
|
103
|
+
Pass `{ pendingMutationDedupeKey }` as the second argument to collapse a run of the same mutation that is waiting to be pushed:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
await store.mutate.setPosition(
|
|
107
|
+
{ playerId, x, y },
|
|
108
|
+
{ pendingMutationDedupeKey: `player-position:${playerId}` },
|
|
109
|
+
);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Use a dedupe key when a mutation only needs to run once per batch, so its first and last positions are enough.** Two kinds of mutation fit:
|
|
113
|
+
|
|
114
|
+
- **Last-value-wins setters**, where intermediate values do not matter: cursor, hover, selection, passive position, drafts.
|
|
115
|
+
- **Idempotent catch-up mutations** that recompute state from their input, such as a periodic `tick`, `sync`, or `refresh` that takes `now`. Running the latest one does everything the skipped ones would have done.
|
|
116
|
+
|
|
117
|
+
What happens to same-key mutations:
|
|
118
|
+
|
|
119
|
+
- **Every call applies optimistically.** The UI sees each value as it is made.
|
|
120
|
+
- **Only the first and the latest queued mutations are sent.** When a third same-key mutation joins the push queue, the ones between the first and the latest are dropped. This happens whenever mutations queue up: offline, while an earlier push is in flight, or when pending mutations are restored from local storage after a reload. With two or fewer queued, nothing is dropped.
|
|
121
|
+
- **A mutation in an in-flight push is not dropped.** If that push fails or times out before it is confirmed, its mutations rejoin the queue and can be dropped there, even though the server may already have run them.
|
|
122
|
+
- **A dropped mutation is not sent again.** One dropped before it was ever sent never runs on the server; one dropped after a failed push may already have run once. Either way its `confirmed` still resolves, and its optimistic writes are rolled back. This is why a dedupe key belongs only on mutations whose effect does not depend on how many copies run.
|
|
123
|
+
- **Keys are compared per store, and only against each other.** Mutations without a key, or with a different key, stay in place and in order between the kept ones.
|
|
124
|
+
- Keys are at most 256 UTF-8 bytes (see [limitations](limitations.md)).
|
|
125
|
+
|
|
126
|
+
Without a key, every queued copy reaches the server and runs. A client that falls behind (offline, a slow connection, a backgrounded tab) replays all of them in order when it reconnects. The backlog drains in consecutive pushes of at most 400 mutations each, or fewer when the push byte budget fills first. For a mutation fired on a timer, a key is the difference between two runs and thousands.
|
|
127
|
+
|
|
128
|
+
Do not use a dedupe key for mutations where each call is a distinct event the server must observe: append, send, counter, toggle, purchase. Also do not use it when a later pending mutation depends on an intermediate same-key write having happened.
|
|
129
|
+
|
|
130
|
+
### `action` — Server-side actions
|
|
131
|
+
|
|
132
|
+
Waits for pending mutations to flush first, then calls the server.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const result = await store.action.generateWithAI({ id: "abc", prompt: "dinner ideas" });
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Connection & State
|
|
139
|
+
|
|
140
|
+
| Property / Method | Returns |
|
|
141
|
+
|-------------------|---------|
|
|
142
|
+
| `state` | `'initializing'` \| `'ended'` |
|
|
143
|
+
| `connectionStatus` | `'connecting'` \| `'connected'` \| `'disconnected'` |
|
|
144
|
+
| `isOnline` | `boolean` |
|
|
145
|
+
| `isBootstrapped` | `boolean` (authoritative data ready to render) |
|
|
146
|
+
| `hasServerData` | `boolean` (first server-origin data event arrived this session) |
|
|
147
|
+
| `isEnded()` | `boolean` |
|
|
148
|
+
| `endReason` | `'kicked'` \| `'auth_failed'` \| `'application'` \| `null` |
|
|
149
|
+
|
|
150
|
+
## Waiting for Data
|
|
151
|
+
|
|
152
|
+
None of these are required — queries and mutations work immediately.
|
|
153
|
+
|
|
154
|
+
| Method | Resolves when |
|
|
155
|
+
|--------|--------------|
|
|
156
|
+
| `waitForLocalData()` | Device storage loaded |
|
|
157
|
+
| `waitForServerData()` | First server-origin data event arrives (which may precede pull completion) |
|
|
158
|
+
| `waitForInitialPull()` | Initial server pull is fully applied |
|
|
159
|
+
| `waitForBootstrap()` | Authoritative data is ready to render (either source) |
|
|
160
|
+
|
|
161
|
+
## Manual Refresh
|
|
162
|
+
|
|
163
|
+
`await store.pullOrThrow()` requests fresh server data and resolves after it
|
|
164
|
+
commits and reaches the client. It rejects on host/server failure, disposal, or
|
|
165
|
+
a 30-second deadline that includes offline time. Shared background sync
|
|
166
|
+
continues after the deadline. `store.pull()` remains best effort; its resolution
|
|
167
|
+
does not establish a successful refresh. Queries still include optimistic
|
|
168
|
+
mutations, so a verified pull does not prove that a pending edit was accepted.
|
|
169
|
+
|
|
170
|
+
A local-read store connection in one iframe allows at most 1,000
|
|
171
|
+
outstanding verified pull requests. Requests awaiting a host reply and successful
|
|
172
|
+
replies waiting for local pagination both count; requests from other iframes do
|
|
173
|
+
not. An excess request rejects immediately, before forwarding to the host.
|
|
174
|
+
Capacity is released when a reply is delivered or rejected, 30 seconds after
|
|
175
|
+
the request's first dispatch, or when the local reader is retired or disposed.
|
|
176
|
+
Replaying the same request does not count twice or restart its deadline.
|
|
177
|
+
|
|
178
|
+
Required use of `pullOrThrow()` or the named `VerifiedPullUnsupportedError`
|
|
179
|
+
export from `joiner-sdk/v1/client.js` requires
|
|
180
|
+
`poeTile({ minSdkVersion: 46 })`. An older host's unverified acknowledgment
|
|
181
|
+
rejects with that error. Optional method detection can protect a call on an
|
|
182
|
+
older SDK, but cannot protect a missing static named import.
|
|
183
|
+
|
|
184
|
+
## IDs
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const ordinal = await store.getClientOrdinal(); // Sequential: 0, 1, 2...
|
|
188
|
+
const id = await store.makeUniqueId(); // Sortable: "5-61"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Pending Mutations
|
|
192
|
+
|
|
193
|
+
Use these APIs when tile behavior depends on server confirmation. Routine sync happens in the background and does not need a visible status indicator.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const pending = await store.getPendingMutations();
|
|
197
|
+
const count = store.getPendingCount();
|
|
198
|
+
await store.waitForSync(); // Wait for all pending to confirm
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`store.onPendingMutationsChanged(fn)` subscribes to pending-queue changes when tile logic needs them.
|
|
202
|
+
|
|
203
|
+
## Subscriptions
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
store.subscribeToConnectionStatus((status) => { /* ... */ });
|
|
207
|
+
store.onOnlineChanged((isOnline) => { /* ... */ });
|
|
208
|
+
store.subscribeToTable("todos", (entries, changes, ctx) => {
|
|
209
|
+
// ctx.userId — current user ID
|
|
210
|
+
// First callback: all entries appear in changes.added (compared against empty)
|
|
211
|
+
// Subsequent: changes.added, changes.modified, changes.removed are deltas
|
|
212
|
+
});
|
|
213
|
+
store.subscribeToScanEntries("user:", (entries, changes) => { /* ... */ });
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`subscribe()` and `subscribeToTable()` return a `SubscriptionControl`. Calling
|
|
217
|
+
it unsubscribes; `await subscription.refresh()` re-runs the query and replaces
|
|
218
|
+
its tracked storage dependencies. Lifecycle and event subscription methods
|
|
219
|
+
return plain unsubscribe functions.
|
|
220
|
+
|
|
221
|
+
## Error & Lifecycle Events
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
store.onFailedMutation((info) => {
|
|
225
|
+
console.error(`${info.mutation.name} failed:`, info.error.message);
|
|
226
|
+
});
|
|
227
|
+
store.onBackgroundError((error) => {
|
|
228
|
+
const message =
|
|
229
|
+
error.kind === "failed_mutation" ? error.info.error.message : error.message;
|
|
230
|
+
showToast(message);
|
|
231
|
+
});
|
|
232
|
+
store.onKicked((reason) => { /* duplicate clientId or admin action */ });
|
|
233
|
+
store.onAuthFailed((reason) => { /* expired token */ });
|
|
234
|
+
store.onDisposed(() => { /* cleanup */ });
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`onFailedMutation` callbacks may include the same optional `info.identity`. Register the listener before starting a write and buffer early callbacks until the mutation result supplies its identity. Compare both fields within the originating store/session. A new `mutate` call, even with identical input, has a different identity; transport replay keeps the original identity. Older runtimes can omit this metadata, so a missing identity leaves the failure uncorrelated. Neither an error's absence nor identity matching proves authoritative acceptance.
|
|
238
|
+
|
|
239
|
+
## Store diagnostics
|
|
240
|
+
|
|
241
|
+
`getDiagnostics()` returns the authoritative live-data usage after the caller
|
|
242
|
+
passes the store's normal authorization policy:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
const diagnostics = await store.getDiagnostics();
|
|
246
|
+
// {
|
|
247
|
+
// liveDataSize: number,
|
|
248
|
+
// maxLiveDataSize: number,
|
|
249
|
+
// unit: "logical_size_units"
|
|
250
|
+
// }
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The unit is UTF-8 bytes, following the formula documented in
|
|
254
|
+
[limitations.md](limitations.md#live-data-quota); it is not SQLite
|
|
255
|
+
file size. A legacy store awaiting the platform backfill
|
|
256
|
+
rejects with `live_data_size_not_initialized` rather than returning an inexact
|
|
257
|
+
number; retry after the backfill reaches that store.
|
|
258
|
+
|
|
259
|
+
## Cleanup
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
store.dispose(); // Closes WebSocket, clears timers. Not reversible.
|
|
263
|
+
```
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Data Visibility Tiers
|
|
2
|
+
|
|
3
|
+
Synced-store enforces visibility at the server API boundary via key prefixes. Every table belongs to exactly one tier — pick it before you design the schema, not after.
|
|
4
|
+
|
|
5
|
+
## The Three Tiers
|
|
6
|
+
|
|
7
|
+
- **Public** (default) — `ctx.table(name)` — synced to every user in the app instance.
|
|
8
|
+
- **Per-user private** — `ctx.privateOfUser(userId).table(name)` — synced only to that user. Write one copy per recipient.
|
|
9
|
+
- **Server-only** — `ctx.serverOnly().table(name)` — never synced to any client; only server-side mutators/actions read it. Expose derived results via actions.
|
|
10
|
+
|
|
11
|
+
## When to Reach for Non-Public Tiers
|
|
12
|
+
|
|
13
|
+
**Role-restricted state** — spymaster's color key in Spy Words, dealer's deck in a card game, judge's secret prompt. Use `privateOfUser(roleHolderId)` and write a copy per role-holder when roles are assigned.
|
|
14
|
+
|
|
15
|
+
**Server-evaluated secrets** — answer keys, RNG seeds, scoring weights, unrevealed puzzle solutions. Use `serverOnly()` and expose results through [actions](actions.md).
|
|
16
|
+
|
|
17
|
+
**Per-user private state** — draft notes, private preferences, unread markers, unshared progress. Use `privateOfUser(userId)`.
|
|
18
|
+
|
|
19
|
+
## Red Flag
|
|
20
|
+
|
|
21
|
+
If you're proposing client-side filtering, client-side encryption, or gating every read through an action just to hide data — you want `privateOfUser` or `serverOnly` instead. The platform already solves this at the API boundary.
|
|
22
|
+
|
|
23
|
+
## Which of your code players can read
|
|
24
|
+
|
|
25
|
+
The tiers above hide **data**. They do not hide **code**. Players can read
|
|
26
|
+
everything in the client bundle, and the client bundle is served to anyone
|
|
27
|
+
holding its URL without signing in. Assume the following is public:
|
|
28
|
+
|
|
29
|
+
| Your code | Shipped to players? | Why |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| Client HTML / JS / CSS | **Yes** | It is the client bundle |
|
|
32
|
+
| Mutator handlers | **Yes** | Mutators run optimistically in the browser, so `client-config.ts` bundles them |
|
|
33
|
+
| Hook handlers | **Yes** | Hooks are wired into `client-config.ts` too |
|
|
34
|
+
| Table names with full field schemas, and mutator/action names with their descriptions and input schemas (plus action output schemas) | **Yes** | The schema endpoint returns them (no handler source), so a field named `correctAnswerHash` or a description saying "checks the hidden answer" is player-readable |
|
|
35
|
+
| Action handlers | **No** | Actions belong only in `backend-config.ts`, which is packed into a separate backend artifact that no route serves. `defineClientConfig` also accepts an `actions` key; never use it. Handlers passed there never run and are bundled into the public client bundle |
|
|
36
|
+
| The compiled backend artifact (handler code, `backend-config.ts`) | **No** | Never served; only the schema's names and shapes are, per the row above |
|
|
37
|
+
| `serverOnly()` rows, other users' `privateOfUser` rows | **No** | Sync-protocol tiers |
|
|
38
|
+
|
|
39
|
+
Consequences:
|
|
40
|
+
|
|
41
|
+
- A rule you want players unable to see (an answer check, a scoring weight, a hidden win condition) belongs in an **action**, or in a mutator behind `if (ctx.isServer)` reading `serverOnly()` data. A mutator that computes the secret on both sides has already shipped it.
|
|
42
|
+
- There is no per-app secret store. Never put an API key or credential in a mutator, hook, or client file; those are world-readable. An action in `backend-config.ts` is the only place a key is protected from players, and even then it is exposed if you publish your source with `visibility: "public"` (the default) or pass the action to `defineClientConfig`.
|
|
43
|
+
- Publishing source is a separate decision from all of the above. `sourceBundle.visibility` in `.poe-tile.json` controls whether anyone can download or remix your source; the field is required whenever the `sourceBundle` block is present, and the scaffold sets it to `"public"`. Set `"owner_only"` and republish to make your source private. Deleting the block only skips uploading new source. It does **not** retract source you already published; the previous bundle and its visibility remain in effect and downloadable. This affects the source archive only; the client bundle is public regardless.
|
|
44
|
+
|
|
45
|
+
## Method Access Matrix
|
|
46
|
+
|
|
47
|
+
| Method | Client | Server |
|
|
48
|
+
|--------|--------|--------|
|
|
49
|
+
| `ctx.table(name)` | Read/write **(public rows only)** | Read/write **(public rows only)** |
|
|
50
|
+
| `ctx.privateOfUser(ctx.userId)` | Read/write (own only) | Read/write |
|
|
51
|
+
| `ctx.privateOfUser(otherUserId)` | Throws | Read/write |
|
|
52
|
+
| `ctx.serverOnly()` | Throws | Read/write |
|
|
53
|
+
|
|
54
|
+
`ctx.table("name")` and `ctx.privateOfUser(userId).table("name")` are **separate namespaces** — even though they share a table name in the schema, the rows live under different storage prefixes (`{table}` vs `$$pu/{userId}/{table}`). Reading or writing one never touches the other.
|
|
55
|
+
|
|
56
|
+
`privateOfUser(userId)` requires a non-empty `userId` without `/`. It also rejects ids longer than 256 UTF-16 code units; every platform-issued member id — user or agent — fits under that ceiling.
|
|
57
|
+
|
|
58
|
+
## Read your own private rows
|
|
59
|
+
|
|
60
|
+
Writing private data via `ctx.privateOfUser(ctx.userId).table(...).set(...)` is the part most people remember. The mirror — that READING your own private rows ALSO needs `privateOfUser` — bites every time.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// In a mutator handler — server fan-out to teammates' private stores
|
|
64
|
+
sendTeamChat: async (ctx, input) => {
|
|
65
|
+
if (!ctx.isServer) return;
|
|
66
|
+
const message = { id: input.id, userId: ctx.userId, text: input.text };
|
|
67
|
+
for (const allyId of [ctx.userId, allyUserId]) {
|
|
68
|
+
await ctx.privateOfUser(allyId).table("teamChat").set({
|
|
69
|
+
itemKey: input.id,
|
|
70
|
+
value: message,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// In the UI — to see your own teamChat row, you MUST go through privateOfUser
|
|
76
|
+
const { data: teamChatRaw } = createLiveQuery(
|
|
77
|
+
() => store,
|
|
78
|
+
() => (tx) => tx.privateOfUser(tx.userId).table("teamChat").entries().toArray(),
|
|
79
|
+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
80
|
+
// NOT tx.table("teamChat") — that namespace is empty
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Same in a one-shot query (e.g. tests)
|
|
84
|
+
const view = await store.query((tx) =>
|
|
85
|
+
tx.privateOfUser(tx.userId).table("teamView").get("state"),
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Reading another user's private rows is rejected on the client with a thrown error; only the server can do that. So in practice, every UI read of a private table goes through `tx.privateOfUser(tx.userId)`.
|
|
90
|
+
|
|
91
|
+
## Hooks can write app private rows
|
|
92
|
+
|
|
93
|
+
System hooks (`onInit`, `onAddUsersV2`, `onRemoveUser`, `onAnonymizeUser`, `onSetTitle`, `onGrantPermission`, `onRevokePermission`, `onAddTileInstanceToRoom`, `onChangeTileParent`, `onAddChildTile`, `onChildInstancesAdded`, `onRoomMemberInstanceMovedOut`) run inside a system mutator, but app-owned public tables, server-only tables, and private tables are still app data. A hook may write `ctx.privateOfUser(otherUserId).table(...)` on the server when the write is a durable per-user projection tied directly to the hook event. Hooks still must not write reserved system tables such as `$users` or `$$system` directly. `onInit` can read the current room topology from `await ctx.table("$$system").get("room")`; `ctx.userId` identifies the initiating user for user/external-store bootstraps. Use it for deterministic bootstrap rows, such as an initial activity message (`"{name} started the group"`). Child-room `onInit` also receives `parentRoomUsers`, a **read-only snapshot** of the parent room's active roster — use it to react to the parent roster (a fresh rootGroup genesis always has an empty `parentRoomUsers`), never to admit members. Membership is platform-owned: the host seats the launcher at genesis (both users when launched from a 2-person room, i.e. a DM), and everyone else joins through the host picker/invite flows. `onAddUsersV2` runs after the `$users` rows are written, so it can read `addedBy`, each user's optional `joinKind` and `invitedBy` (how they came in, and whose invite link they opened), and use each user's optional `addedBatchUserIds` for this operation’s ordered invitation group to auto-seat users or write membership activity such as `"{name} added {usernames...}"`. For user-initiated cross-user fan-out, prefer a regular mutator or an action enqueued with `ctx.enqueueAction(...)`.
|
|
94
|
+
|
|
95
|
+
Wire every hook into both `defineBackendConfig({ hooks })` and `defineClientConfig({ hooks })`. Client hook runs are optimistic seed data for fresh prepared stores, so they must be browser-safe: use public or current-user-readable data, avoid backend imports and platform calls, and guard server-only table/private-other-user writes behind `ctx.isServer`.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# External Stores: Cross-App Reads & Writes
|
|
2
|
+
|
|
3
|
+
Mutators and actions can interact with other store instances on the server. Mutators can write via `ctx.mutateExternal(...)`; mutators and actions can read via `ctx.externalStore(...)`. Receiving code identifies the caller via `ctx.source`.
|
|
4
|
+
|
|
5
|
+
## External Mutations (Writes)
|
|
6
|
+
|
|
7
|
+
A mutator can dispatch mutations to a different store using `ctx.mutateExternal()`. This enables cross-app communication — for example, a child app notifying its parent.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
notifyParent: async (ctx, input) => {
|
|
11
|
+
// Update local state
|
|
12
|
+
await ctx.table("status").set({
|
|
13
|
+
itemKey: "notification",
|
|
14
|
+
value: { sent: true },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Dispatch a mutation to the parent store
|
|
18
|
+
ctx.mutateExternal({
|
|
19
|
+
storeTypeId: input.parentTypeId,
|
|
20
|
+
instanceId: input.parentInstanceId,
|
|
21
|
+
mutationName: "receiveChildNotification",
|
|
22
|
+
input: { message: input.message },
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The target store must have a mutator with the matching name. External mutations are committed atomically after the source mutation succeeds.
|
|
28
|
+
|
|
29
|
+
### Passing the target store identity
|
|
30
|
+
|
|
31
|
+
Since mutators run on both client and server, they can't access client-only APIs like `Poe.parent`. Instead, pass the target store identity as mutation input from client code:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
// Client code — read parent identity from Poe.parent
|
|
35
|
+
await store.mutate.notifyParent({
|
|
36
|
+
parentTypeId: Poe.parent.storeTypeId,
|
|
37
|
+
parentInstanceId: Poe.parent.instanceId,
|
|
38
|
+
message: "hello from child",
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Constraints
|
|
43
|
+
|
|
44
|
+
- Max 200 unique external mutation targets per commit (each target = `(storeTypeId, instanceId)` pair; multiple mutations to the same target count as one)
|
|
45
|
+
- Max depth of 1 — target mutators cannot trigger further external **writes** (`blockExternalMutations: true`). External **reads** are not affected
|
|
46
|
+
- External mutations expire after 5 minutes if not committed
|
|
47
|
+
|
|
48
|
+
## External Reads
|
|
49
|
+
|
|
50
|
+
A mutator or action can read from another store using `ctx.externalStore({ storeTypeId, instanceId })`. The handle exposes `.table(name)` with `get`, `scan`, and `entries` (read-only).
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// In a mutator or action:
|
|
54
|
+
const ext = ctx.externalStore({ storeTypeId: "emoji-prefs", instanceId: ctx.userId });
|
|
55
|
+
const favorites = await ext.table("preferences").get("favorites");
|
|
56
|
+
const recent = await ext.table("entries").scan({ limit: 50 }).values().toArray();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
In actions, the handle also exposes `.action(name, input)` and `.getSchema()`.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// In an action only:
|
|
63
|
+
const ext = ctx.externalStore({ storeTypeId: "chat", instanceId: "room-1" });
|
|
64
|
+
const result = await ext.action("summarize", { limit: 100 });
|
|
65
|
+
const schema = await ext.getSchema();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Reads vs writes
|
|
69
|
+
|
|
70
|
+
- **Server-only path**: on the client, `ctx.externalStore(...).table(...).get(...)` is a no-op stub that returns empty results. Don't depend on optimistic external reads
|
|
71
|
+
- **No depth limit**: reads are stateless (no commits, no broadcasts, no retries) and are allowed inside external dispatch targets and action-invoked mutators — unlike writes
|
|
72
|
+
- **Bounded**: a single scan/list returns at most `MAX_EXTERNAL_READ_ITEMS` (1000) and `MAX_EXTERNAL_READ_BYTES` (1 MB). Response carries a `truncated` flag when limits were hit
|
|
73
|
+
- **Timeout**: `EXTERNAL_READ_TIMEOUT_MS` = 5s for the dispatch RPC
|
|
74
|
+
|
|
75
|
+
### Client-side external reads
|
|
76
|
+
|
|
77
|
+
Iframe apps can read from another store via `Poe.externalStore({ storeTypeId, instanceId })` — call `await ext.waitForBootstrap()` first, then read with `await ext.table(...).get(...)`, `await ext.privateOfUser(userId).table(...).get(...)`, or the older `await ext.query((tx) => tx.table(...).get(...))` callback form. This is a one-shot snapshot read against locally-synced data.
|
|
78
|
+
|
|
79
|
+
For a **live** cross-store read, use `ext.subscribe(queryFn, onResult)` instead of polling or re-reading:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const ext = Poe.externalStore({ storeTypeId: "chat", instanceId: parentRoomId });
|
|
83
|
+
const unsubscribe = ext.subscribe(
|
|
84
|
+
async (tx) => tx.table("$meta").get("_title"),
|
|
85
|
+
(title) => renderGroupName(title),
|
|
86
|
+
);
|
|
87
|
+
// later, e.g. on unmount:
|
|
88
|
+
unsubscribe();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`queryFn` runs immediately against the current local snapshot (possibly empty before the first sync — pair with `waitForBootstrap()` when the initial value matters) and re-runs after each change of the target store, including this device's own not-yet-confirmed writes to it (e.g. another tile mutating that same store on this device) — the preview converges to the authoritative value once the server confirms. Only THIS device's own pending writes can appear this way; a change made from a different device still needs the server round trip. While subscribed, the host keeps the target store syncing. The host bounds how many distinct stores one app can watch at once; `subscribe` throws beyond that limit. Always call the returned unsubscribe function when the UI goes away.
|
|
92
|
+
|
|
93
|
+
## `ctx.source` — identifying the caller
|
|
94
|
+
|
|
95
|
+
`ctx.source` is a `ContextSource` discriminated union exposed on `MutationContext`, `QueryContext`, and `ActionContext`. It tells receiving code who triggered this request.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
type ContextSource =
|
|
99
|
+
| { type: "user"; userId: string }
|
|
100
|
+
| {
|
|
101
|
+
type: "external-store";
|
|
102
|
+
userId: string;
|
|
103
|
+
store: { typeId: string; instanceId: string };
|
|
104
|
+
room: { storeTypeId: string; instanceId: string };
|
|
105
|
+
}
|
|
106
|
+
| { type: "system" };
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| Variant | When you see it |
|
|
110
|
+
|---------|-----------------|
|
|
111
|
+
| `"user"` | Normal client mutation/query/action |
|
|
112
|
+
| `"external-store"` | Dispatched from another store via `ctx.mutateExternal(...)`. `ctx.source.store` carries the **source** identity (typeId + instanceId); `ctx.source.userId` is the user who triggered the source mutation; `ctx.source.room` carries the **source's resolved room ref** (see below) |
|
|
113
|
+
| `"system"` | System mutation (e.g. platform-issued `$addUsers`) or hook invocation. No `userId` field |
|
|
114
|
+
|
|
115
|
+
### Using `ctx.source` in receiving mutators
|
|
116
|
+
|
|
117
|
+
External-dispatch targets typically gate on `ctx.source.type` and read identity from `ctx.source.store` — don't make callers stuff typeId/instanceId into the input.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
receiveActivity: async (ctx, input) => {
|
|
121
|
+
if (ctx.source.type !== "external-store") {
|
|
122
|
+
throw new Error("receiveActivity must be called via external dispatch");
|
|
123
|
+
}
|
|
124
|
+
const { typeId, instanceId } = ctx.source.store;
|
|
125
|
+
const sourceUserId = ctx.source.userId;
|
|
126
|
+
const sourceRoom = ctx.source.room; // always defined on external-store
|
|
127
|
+
// ...
|
|
128
|
+
},
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### `ctx.source` on the client (optimistic) vs server (authoritative)
|
|
132
|
+
|
|
133
|
+
`ctx.source` is populated identically when the mutator runs optimistically on the client and authoritatively on the server, so branching on `ctx.source.type` is rebase-safe. To gate behavior between optimistic and server runs intentionally, use `ctx.isServer`.
|
|
134
|
+
|
|
135
|
+
Note that `userId` is only present on the `"user"` and `"external-store"` variants — `"system"` has no userId. Narrow on `ctx.source.type` before reading it.
|
|
136
|
+
|
|
137
|
+
### Platform-augmented fields on `ctx.source`
|
|
138
|
+
|
|
139
|
+
Joiner stamps extra fields onto `ctx.source` via TypeScript module augmentation. They are populated by the trusted server from authoritative state — never read from app input — and ride through external dispatch automatically (`createExternalStoreOrigin` propagates whole-origin fields from the dispatching source's origin; `room` is freshly resolved server-side from the source's pinned `$$system:room`).
|
|
140
|
+
|
|
141
|
+
| Field | Type | Variants | Populated when |
|
|
142
|
+
|-------|------|----------|----------------|
|
|
143
|
+
| `ctx.source.room` | `{ storeTypeId: string; instanceId: string }` | **external-store only — required** | Every cross-store dispatch carries the source's resolved room ref. If the source's `$$system:room` is `{type:"self"}` (the default for self-contained stores), `room` equals the source store's own identity. If the source is a member of a foreign room, `room` is that room ref. |
|
|
144
|
+
| `ctx.source.parent` | `{ typeId: string; instanceId: string } \| undefined` | all variants | The instance is a sub-app opened via `apps.openChild`. Carries the **immediate parent**'s identity — for a 3-level mount the grandchild's `parent` is the sub-app, not the root. Undefined for root apps. |
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
recordOpenedFromContext: async (ctx, input) => {
|
|
148
|
+
// ctx.source.parent is undefined when the request comes from a root app.
|
|
149
|
+
const parent = ctx.source.parent;
|
|
150
|
+
// ctx.source.room is REQUIRED on external-store — narrow on type first.
|
|
151
|
+
const room = ctx.source.type === "external-store" ? ctx.source.room : null;
|
|
152
|
+
await ctx.table("audit").set({
|
|
153
|
+
itemKey: input.eventId,
|
|
154
|
+
value: {
|
|
155
|
+
sourceRoom: room,
|
|
156
|
+
parentTypeId: parent?.typeId ?? null,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The `parent` field is not stamped on the iframe-side optimistic run of a mutator (`platform_fields` are stamped host-side). Read it under `ctx.isServer` or wait for the server-confirmed row when assertions depend on it. The `room` field is server-resolved per-dispatch and may be missing on optimistic runs; receiving code that depends on `room` should gate on `ctx.isServer` (or wait for the server-confirmed row).
|