@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,129 @@
|
|
|
1
|
+
import { type PoeUserInfo, usableDisplayName } from "joiner-sdk/v1/shared.js";
|
|
2
|
+
import {
|
|
3
|
+
createEffect,
|
|
4
|
+
createMemo,
|
|
5
|
+
createSignal,
|
|
6
|
+
For,
|
|
7
|
+
type JSX,
|
|
8
|
+
onCleanup,
|
|
9
|
+
} from "solid-js";
|
|
10
|
+
import type { TodoItem, TodoStoreClient } from "../client";
|
|
11
|
+
|
|
12
|
+
export function App(props: { store: TodoStoreClient }): JSX.Element {
|
|
13
|
+
const [rawTodos, setRawTodos] = createSignal<TodoItem[]>([]);
|
|
14
|
+
createEffect(() => {
|
|
15
|
+
const unsubscribe = props.store.subscribe(
|
|
16
|
+
async (tx) => tx.table("items").entries().toArray(),
|
|
17
|
+
(entries) => {
|
|
18
|
+
setRawTodos(() => entries.map(([, v]) => v as TodoItem));
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
onCleanup(unsubscribe);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const todos = createMemo(() =>
|
|
25
|
+
[...rawTodos()].sort((a, b) => a.order - b.order),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// $userInfo is auto-populated when a user first connects to the store.
|
|
29
|
+
const [rawUserInfo, setRawUserInfo] = createSignal<PoeUserInfo[]>([]);
|
|
30
|
+
createEffect(() => {
|
|
31
|
+
const unsubscribe = props.store.subscribe(
|
|
32
|
+
async (tx) => tx.table("$userInfo").entries().toArray(),
|
|
33
|
+
(entries) => {
|
|
34
|
+
setRawUserInfo(() => entries.map(([, v]) => v));
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
onCleanup(unsubscribe);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const userInfoMap = createMemo(() => {
|
|
41
|
+
const map = new Map<string, PoeUserInfo>();
|
|
42
|
+
for (const info of rawUserInfo()) {
|
|
43
|
+
map.set(info.userId, info);
|
|
44
|
+
}
|
|
45
|
+
return map;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function getDisplayName(userId: string): string {
|
|
49
|
+
const info = userInfoMap().get(userId);
|
|
50
|
+
// Never render an internal id (`u_<hex>` / `u_migrated_...` /
|
|
51
|
+
// `private-...`) as a name; the shared masker returns "" when nothing
|
|
52
|
+
// usable is present.
|
|
53
|
+
return usableDisplayName(info) || "Player";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const addTodo = (): void => {
|
|
57
|
+
const input = document.getElementById("todo-input") as HTMLInputElement;
|
|
58
|
+
const text = input.value.trim();
|
|
59
|
+
if (!text) return;
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const maxOrder = todos().reduce((max, t) => Math.max(max, t.order), 0);
|
|
62
|
+
props.store.mutate.setTodo({
|
|
63
|
+
id: crypto.randomUUID(),
|
|
64
|
+
text,
|
|
65
|
+
completed: false,
|
|
66
|
+
createdAt: now,
|
|
67
|
+
order: maxOrder + 1,
|
|
68
|
+
});
|
|
69
|
+
input.value = "";
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const toggleTodo = (todo: TodoItem): void => {
|
|
73
|
+
props.store.mutate.setTodo({ id: todo.id, completed: !todo.completed });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const deleteTodo = (id: string): void => {
|
|
77
|
+
props.store.mutate.removeTodo({ id });
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<h1>{{ APP_NAME }}</h1>
|
|
83
|
+
<div>
|
|
84
|
+
<input
|
|
85
|
+
id="todo-input"
|
|
86
|
+
placeholder="What needs to be done?"
|
|
87
|
+
onKeyDown={(e) => {
|
|
88
|
+
if (e.key === "Enter") addTodo();
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
<button id="add-btn" type="button" onClick={addTodo}>
|
|
92
|
+
Add
|
|
93
|
+
</button>
|
|
94
|
+
</div>
|
|
95
|
+
<ul id="todo-list">
|
|
96
|
+
<For each={todos()}>
|
|
97
|
+
{(todo) => (
|
|
98
|
+
<li>
|
|
99
|
+
<input
|
|
100
|
+
type="checkbox"
|
|
101
|
+
checked={todo.completed}
|
|
102
|
+
onChange={() => toggleTodo(todo)}
|
|
103
|
+
/>
|
|
104
|
+
<span
|
|
105
|
+
style={{
|
|
106
|
+
"text-decoration": todo.completed ? "line-through" : "none",
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{todo.text}
|
|
110
|
+
</span>
|
|
111
|
+
<span
|
|
112
|
+
style={{
|
|
113
|
+
color: "#888",
|
|
114
|
+
"font-size": "0.85em",
|
|
115
|
+
"margin-left": "8px",
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
— {getDisplayName(todo.createdBy)}
|
|
119
|
+
</span>
|
|
120
|
+
<button type="button" onClick={() => deleteTodo(todo.id)}>
|
|
121
|
+
Delete
|
|
122
|
+
</button>
|
|
123
|
+
</li>
|
|
124
|
+
)}
|
|
125
|
+
</For>
|
|
126
|
+
</ul>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { poeTile } from "joiner-sdk/vite";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
import solid from "vite-plugin-solid";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
root: "tile",
|
|
7
|
+
build: {
|
|
8
|
+
outDir: "../dist",
|
|
9
|
+
emptyOutDir: true,
|
|
10
|
+
rollupOptions: {
|
|
11
|
+
output: {
|
|
12
|
+
entryFileNames: "tile-frontend.js",
|
|
13
|
+
assetFileNames: "[name][extname]",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: [solid(), poeTile({ backendEntryPoint: "src/backend.ts" })],
|
|
18
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { afterEach, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
findSourceProblems,
|
|
7
|
+
MAX_SOURCE_LINES,
|
|
8
|
+
} from "../base/scripts/check-source";
|
|
9
|
+
|
|
10
|
+
const SCRIPT = join(import.meta.dir, "../base/scripts/check-source.ts");
|
|
11
|
+
const roots: string[] = [];
|
|
12
|
+
|
|
13
|
+
/** A tile directory holding `files` (relative path to text). */
|
|
14
|
+
function tile(files: Record<string, string>): string {
|
|
15
|
+
const root = mkdtempSync(join(tmpdir(), "check-source-"));
|
|
16
|
+
roots.push(root);
|
|
17
|
+
for (const [path, text] of Object.entries(files)) {
|
|
18
|
+
mkdirSync(dirname(join(root, path)), { recursive: true });
|
|
19
|
+
writeFileSync(join(root, path), text);
|
|
20
|
+
}
|
|
21
|
+
return root;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function linesOf(count: number): string {
|
|
25
|
+
return "export const x = 1;\n".repeat(count);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
for (const root of roots.splice(0)) rmSync(root, { recursive: true });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("a file of exactly MAX_SOURCE_LINES lines passes and one more line fails", () => {
|
|
33
|
+
const root = tile({
|
|
34
|
+
"ui/at-limit.ts": linesOf(MAX_SOURCE_LINES),
|
|
35
|
+
"ui/over-limit.ts": linesOf(MAX_SOURCE_LINES + 1),
|
|
36
|
+
});
|
|
37
|
+
expect(findSourceProblems(root)).toEqual([
|
|
38
|
+
`ui/over-limit.ts: ${MAX_SOURCE_LINES + 1} lines. Split it into focused modules of at most ${MAX_SOURCE_LINES} lines each.`,
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test.each([
|
|
43
|
+
["// @ts-nocheck", "nocheck"],
|
|
44
|
+
[" //@ts-ignore", "ignore"],
|
|
45
|
+
["/* @ts-expect-error */ const y: number = 'a';", "expect-error"],
|
|
46
|
+
["/** @ts-ignore */", "ignore"],
|
|
47
|
+
["{/* @ts-expect-error */}", "expect-error"],
|
|
48
|
+
])("the suppression %p is reported with its line number", (line, directive) => {
|
|
49
|
+
const root = tile({ "synced-store/rules.ts": `const a = 1;\n${line}\n` });
|
|
50
|
+
expect(findSourceProblems(root)).toEqual([
|
|
51
|
+
`synced-store/rules.ts:2: @ts-${directive} hides type errors. Remove it and fix the errors tsc reports.`,
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test.each([
|
|
56
|
+
["/*\n@ts-ignore */", "ignore"],
|
|
57
|
+
["/**\n * @ts-expect-error\n */", "expect-error"],
|
|
58
|
+
])("the suppression on a later line of the block comment %p is reported", (comment, directive) => {
|
|
59
|
+
const root = tile({
|
|
60
|
+
"ui/game.ts": `const a = 1;\n${comment}\nconst b: number = "x";\n`,
|
|
61
|
+
});
|
|
62
|
+
expect(findSourceProblems(root)).toEqual([
|
|
63
|
+
`ui/game.ts:3: @ts-${directive} hides type errors. Remove it and fix the errors tsc reports.`,
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("a directive-shaped line after a closed block comment passes", () => {
|
|
68
|
+
const root = tile({
|
|
69
|
+
"ui/game.ts": '/* note */\nconst tags = ["x"];\n@ts-ignore;\n',
|
|
70
|
+
});
|
|
71
|
+
expect(findSourceProblems(root)).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("prose that names a suppression outside a directive passes", () => {
|
|
75
|
+
const root = tile({
|
|
76
|
+
"ui/help.ts":
|
|
77
|
+
'// Never add a @ts-ignore here.\nexport const tip = "use @ts-nocheck sparingly";\n',
|
|
78
|
+
});
|
|
79
|
+
expect(findSourceProblems(root)).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("JavaScript fails in type-checked folders and passes at the tile root", () => {
|
|
83
|
+
const root = tile({
|
|
84
|
+
"ui/game.js": "export const x = 1;\n",
|
|
85
|
+
"tile/src/entry.jsx": "export const x = 1;\n",
|
|
86
|
+
"client.js": "export const x = 1;\n",
|
|
87
|
+
"postcss.config.js": "export default {};\n",
|
|
88
|
+
"scripts/tool.mjs": "export const x = 1;\n",
|
|
89
|
+
});
|
|
90
|
+
expect(findSourceProblems(root)).toEqual([
|
|
91
|
+
"client.js: JavaScript is not type-checked. Rename it to TypeScript and fix the errors tsc reports.",
|
|
92
|
+
"tile/src/entry.jsx: JavaScript is not type-checked. Rename it to TypeScript and fix the errors tsc reports.",
|
|
93
|
+
"ui/game.js: JavaScript is not type-checked. Rename it to TypeScript and fix the errors tsc reports.",
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("dependencies, build output and dot folders are not scanned", () => {
|
|
98
|
+
const root = tile({
|
|
99
|
+
"node_modules/pkg/index.ts": "// @ts-nocheck\n",
|
|
100
|
+
"dist/index.js": linesOf(MAX_SOURCE_LINES + 1),
|
|
101
|
+
".claude/skills/tile-creator/example.ts": "// @ts-ignore\n",
|
|
102
|
+
".visual-checks/probe.ts": "// @ts-ignore\n",
|
|
103
|
+
"ui/App.ts": "export const ok = true;\n",
|
|
104
|
+
});
|
|
105
|
+
expect(findSourceProblems(root)).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("the script exits 1 and lists every problem when run in a tile", () => {
|
|
109
|
+
const root = tile({
|
|
110
|
+
"ui/a.ts": "// @ts-nocheck\n",
|
|
111
|
+
"ui/b.js": "export const x = 1;\n",
|
|
112
|
+
});
|
|
113
|
+
const result = Bun.spawnSync([process.execPath, SCRIPT], { cwd: root });
|
|
114
|
+
expect(result.exitCode).toBe(1);
|
|
115
|
+
expect(result.stderr.toString()).toBe(
|
|
116
|
+
[
|
|
117
|
+
"Source check failed (scripts/check-source.ts):",
|
|
118
|
+
" ui/a.ts:1: @ts-nocheck hides type errors. Remove it and fix the errors tsc reports.",
|
|
119
|
+
" ui/b.js: JavaScript is not type-checked. Rename it to TypeScript and fix the errors tsc reports.",
|
|
120
|
+
"",
|
|
121
|
+
].join("\n"),
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("the script exits 0 silently on a clean tile", () => {
|
|
126
|
+
const root = tile({ "ui/App.ts": "export const ok = true;\n" });
|
|
127
|
+
const result = Bun.spawnSync([process.execPath, SCRIPT], { cwd: root });
|
|
128
|
+
expect(result.exitCode).toBe(0);
|
|
129
|
+
expect(result.stdout.toString()).toBe("");
|
|
130
|
+
expect(result.stderr.toString()).toBe("");
|
|
131
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Verifies the template's `bun run dev` script:
|
|
4
|
+
* - boots a TestServer + reload-injecting proxy
|
|
5
|
+
* - injects a /__dev_reload_ws client into the top-level HTML
|
|
6
|
+
* - broadcasts "reload" when dist/ changes (after vite rebuilds)
|
|
7
|
+
*
|
|
8
|
+
* Prerequisites: `bun run generate` to scaffold templates into
|
|
9
|
+
* generated-apps/template-<name>/, and `bun install --ignore-scripts` at
|
|
10
|
+
* the monorepo root so workspace deps resolve.
|
|
11
|
+
*
|
|
12
|
+
* Slow because each iteration spawns vite + waits for a real rebuild.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, expect, test } from "bun:test";
|
|
16
|
+
import { type Subprocess, spawn } from "bun";
|
|
17
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { GENERATED_APPS_DIR } from "../scripts/paths.ts";
|
|
20
|
+
|
|
21
|
+
const TEMPLATE = "react";
|
|
22
|
+
const APP_DIR = join(GENERATED_APPS_DIR, `template-${TEMPLATE}`);
|
|
23
|
+
const TYPE_ID = `template-${TEMPLATE}`;
|
|
24
|
+
|
|
25
|
+
if (!existsSync(APP_DIR)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Generated app not found: ${APP_DIR}\nRun "bun run generate" in poe-tile-templates first.`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const dev: Subprocess<"ignore", "pipe", "pipe"> = spawn({
|
|
32
|
+
cmd: ["bun", "scripts/dev.ts"],
|
|
33
|
+
cwd: APP_DIR,
|
|
34
|
+
stdout: "pipe",
|
|
35
|
+
stderr: "pipe",
|
|
36
|
+
env: { ...process.env, FORCE_COLOR: "0" },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Drain stderr into a buffer so timeout errors below can include it. Without
|
|
40
|
+
// this, a TestServer/proxy boot error printed to stderr is invisible in the
|
|
41
|
+
// failure message — we'd only see whatever stdout had buffered.
|
|
42
|
+
let stderrBuffer = "";
|
|
43
|
+
void (async () => {
|
|
44
|
+
const reader = (dev.stderr as ReadableStream<Uint8Array>).getReader();
|
|
45
|
+
const stderrDecoder = new TextDecoder();
|
|
46
|
+
try {
|
|
47
|
+
while (true) {
|
|
48
|
+
// biome-ignore lint/performance/noAwaitInLoops: Existing sequential async loops need case-by-case review; keep rule enabled for new code.
|
|
49
|
+
const { done, value } = await reader.read();
|
|
50
|
+
if (done) break;
|
|
51
|
+
stderrBuffer += stderrDecoder.decode(value, { stream: true });
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
// stream closed during shutdown — fine.
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
afterAll(() => {
|
|
59
|
+
dev.kill("SIGINT");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Tiered readUntil: each call advances `stdoutBuffer` and waits up to
|
|
63
|
+
// `timeoutMs` for `pattern`. Splitting the boot wait into multiple tiers
|
|
64
|
+
// (vite first build → testserver listening → URL printed) means the next CI
|
|
65
|
+
// flake fails at one specific tier and pinpoints which boot phase blew its
|
|
66
|
+
// budget, instead of the previous "the whole 10s envelope expired somewhere
|
|
67
|
+
// in there" failure. The shared `stdoutBuffer` is intentional: a fast tier
|
|
68
|
+
// might finish before its log line is read, so the next tier's match may
|
|
69
|
+
// already be in the buffer from a previous read.
|
|
70
|
+
const decoder = new TextDecoder();
|
|
71
|
+
let stdoutBuffer = "";
|
|
72
|
+
const stdoutReader = (dev.stdout as ReadableStream<Uint8Array>).getReader();
|
|
73
|
+
|
|
74
|
+
async function readUntil(
|
|
75
|
+
pattern: RegExp,
|
|
76
|
+
timeoutMs: number,
|
|
77
|
+
tierName: string,
|
|
78
|
+
): Promise<RegExpMatchArray> {
|
|
79
|
+
let match = stdoutBuffer.match(pattern);
|
|
80
|
+
if (match) return match;
|
|
81
|
+
const deadline = Date.now() + timeoutMs;
|
|
82
|
+
while (Date.now() < deadline) {
|
|
83
|
+
const remaining = deadline - Date.now();
|
|
84
|
+
// biome-ignore lint/performance/noAwaitInLoops: Existing sequential async loops need case-by-case review; keep rule enabled for new code.
|
|
85
|
+
const result = await Promise.race([
|
|
86
|
+
stdoutReader.read(),
|
|
87
|
+
new Promise<null>((r) =>
|
|
88
|
+
// biome-ignore lint: real I/O timeout — slow test waits on child-process stdout
|
|
89
|
+
setTimeout(() => r(null), remaining),
|
|
90
|
+
),
|
|
91
|
+
]);
|
|
92
|
+
if (result === null) break;
|
|
93
|
+
if (result.done) break;
|
|
94
|
+
stdoutBuffer += decoder.decode(result.value, { stream: true });
|
|
95
|
+
match = stdoutBuffer.match(pattern);
|
|
96
|
+
if (match) return match;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Timed out at tier "${tierName}" waiting for /${pattern.source}/ in dev output (${timeoutMs}ms).\n` +
|
|
100
|
+
`Stdout buffered:\n${stdoutBuffer}\n` +
|
|
101
|
+
`Stderr buffered:\n${stderrBuffer}`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Skipped 2026-05-07: chronic CI flake on the "vite first build" tier
|
|
106
|
+
// (8000ms budget). Tracked in PR #2962. Re-observed in PRs #2963 (which
|
|
107
|
+
// added the tier wait + stderr capture) and #2973 (passed on no-cache,
|
|
108
|
+
// failed on cached for the same commit, strong flake signal). Un-skip
|
|
109
|
+
// once the underlying boot-time variance is fixed; the test still runs
|
|
110
|
+
// locally for development.
|
|
111
|
+
test.skip("dev script boots, injects reload script, broadcasts on rebuild", async () => {
|
|
112
|
+
// Tiered boot wait: vite first build (cold prod bundle, the historically
|
|
113
|
+
// slow phase per PR #2816) gets the largest budget; subsequent phases
|
|
114
|
+
// should be near-instant. Total envelope still ~11s so the test stays
|
|
115
|
+
// "fast" per PRINCIPLES.md.
|
|
116
|
+
await readUntil(/\[dev\] vite first build done/, 8_000, "vite first build");
|
|
117
|
+
await readUntil(
|
|
118
|
+
/\[dev\] testserver listening/,
|
|
119
|
+
1_500,
|
|
120
|
+
"testserver listening",
|
|
121
|
+
);
|
|
122
|
+
const urlMatch = await readUntil(
|
|
123
|
+
/URL:\s+(http:\/\/\S+)/,
|
|
124
|
+
1_500,
|
|
125
|
+
"proxy URL printed",
|
|
126
|
+
);
|
|
127
|
+
const url = urlMatch[1]!;
|
|
128
|
+
expect(url).toContain(`/room/${TYPE_ID}/dev/tile/${TYPE_ID}/dev`);
|
|
129
|
+
|
|
130
|
+
const html = await fetch(url).then((r) => r.text());
|
|
131
|
+
expect(html).toContain("/__dev_reload_ws");
|
|
132
|
+
expect(html).toContain("location.reload()");
|
|
133
|
+
|
|
134
|
+
const wsUrl = new URL(url);
|
|
135
|
+
wsUrl.protocol = "ws:";
|
|
136
|
+
wsUrl.pathname = "/__dev_reload_ws";
|
|
137
|
+
wsUrl.search = "";
|
|
138
|
+
|
|
139
|
+
const ws = new WebSocket(wsUrl.toString());
|
|
140
|
+
const reloadMessage = new Promise<string>((resolve, reject) => {
|
|
141
|
+
ws.addEventListener("message", (e) => resolve(String(e.data)));
|
|
142
|
+
ws.addEventListener("error", () => reject(new Error("ws error")));
|
|
143
|
+
});
|
|
144
|
+
await new Promise<void>((resolve, reject) => {
|
|
145
|
+
ws.addEventListener("open", () => resolve());
|
|
146
|
+
ws.addEventListener("error", () => reject(new Error("ws connect failed")));
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const appPath = join(APP_DIR, "ui/App.tsx");
|
|
150
|
+
const original = readFileSync(appPath, "utf-8");
|
|
151
|
+
writeFileSync(appPath, `${original}\n// dev-reload-test ${Date.now()}\n`);
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const message = await Promise.race([
|
|
155
|
+
reloadMessage,
|
|
156
|
+
new Promise<never>((_, r) =>
|
|
157
|
+
// biome-ignore lint: real I/O timeout — slow test waits on vite rebuild + ws broadcast
|
|
158
|
+
setTimeout(() => r(new Error("reload not received in 10s")), 10_000),
|
|
159
|
+
),
|
|
160
|
+
]);
|
|
161
|
+
expect(message).toBe("reload");
|
|
162
|
+
} finally {
|
|
163
|
+
writeFileSync(appPath, original);
|
|
164
|
+
ws.close();
|
|
165
|
+
}
|
|
166
|
+
}, 20_000);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
/** Exercise the emitted manager example with a non-empty app schema and handler. */
|
|
6
|
+
export function writeCustomizedManagerFixture({
|
|
7
|
+
dir,
|
|
8
|
+
managerExample,
|
|
9
|
+
}: {
|
|
10
|
+
dir: string;
|
|
11
|
+
managerExample: string;
|
|
12
|
+
}): void {
|
|
13
|
+
mkdirSync(dir, { recursive: true });
|
|
14
|
+
writeFileSync(
|
|
15
|
+
join(dir, "schema.ts"),
|
|
16
|
+
`
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import { defineSchema, table } from "joiner-sdk/v1/backend.js";
|
|
19
|
+
export const tileSchema = defineSchema({
|
|
20
|
+
schemaVersion: 1,
|
|
21
|
+
tables: { moves: { schema: table(z.object({ count: z.number() })) } },
|
|
22
|
+
mutators: { recordMove: { input: z.object({ count: z.number() }) } },
|
|
23
|
+
});
|
|
24
|
+
`,
|
|
25
|
+
);
|
|
26
|
+
writeFileSync(join(dir, "hooks.ts"), "export const tileHooks = {};\n");
|
|
27
|
+
writeFileSync(
|
|
28
|
+
join(dir, "mutators.ts"),
|
|
29
|
+
`
|
|
30
|
+
import type { InferMutatorHandlers } from "joiner-sdk/v1/client.js";
|
|
31
|
+
import { tileSchema } from "./schema";
|
|
32
|
+
export const tileMutators: InferMutatorHandlers<typeof tileSchema> = {
|
|
33
|
+
recordMove: async (ctx, input) => {
|
|
34
|
+
await ctx.table("moves").set({ itemKey: ctx.userId, value: input });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
`,
|
|
38
|
+
);
|
|
39
|
+
writeFileSync(
|
|
40
|
+
join(dir, "manager.test.ts"),
|
|
41
|
+
managerExample +
|
|
42
|
+
`
|
|
43
|
+
test("the customized app mutation survives the manager example", async () => {
|
|
44
|
+
const h = await createPoeTileInManagerTestHarness({
|
|
45
|
+
tile: { typeId: "customized-app", clientConfig, backendConfig },
|
|
46
|
+
users: ["alice", "bob"],
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
await (await h.tile("alice").poe.store.mutate.recordMove({ count: 7 })).confirmed;
|
|
50
|
+
const bob = h.tile("bob").poe.store;
|
|
51
|
+
await bob.pull();
|
|
52
|
+
const result = await bob.query((ctx) => ctx.table("moves").get("alice"));
|
|
53
|
+
expect(result).toEqual({ count: 7 });
|
|
54
|
+
const count: number | undefined = result?.count;
|
|
55
|
+
expect(count).toBe(7);
|
|
56
|
+
await h.removeUser({ userId: "bob", removedBy: "alice" });
|
|
57
|
+
const alice = h.tile("alice").poe.store;
|
|
58
|
+
await alice.pull();
|
|
59
|
+
expect(await alice.query(async (ctx) => (await ctx.table("$users").get("bob"))?.removedAt)).toBeDefined();
|
|
60
|
+
await h.addUser({ userId: "bob", addedBy: "alice" });
|
|
61
|
+
await bob.pull();
|
|
62
|
+
expect(await bob.query((ctx) => ctx.table("moves").get("alice"))).toEqual({ count: 7 });
|
|
63
|
+
} finally { h.dispose(); }
|
|
64
|
+
});
|
|
65
|
+
`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { defineBackendConfig, defineSchema, table } from "joiner-sdk/v1/backend.js";
|
|
4
|
+
import { defineClientConfig, type InferMutatorHandlers, type InferSyncedStoreClient, type PoeAPI } from "joiner-sdk/v1/client.js";
|
|
5
|
+
import { createPoeTileTestHarness, createPoeTileInManagerTestHarness, waitForKeyMatch } from "joiner-sdk/v1/test-utils.js";
|
|
6
|
+
import { tileSchema } from "../synced-store/schema";
|
|
7
|
+
|
|
8
|
+
// Extend the installed starter, rather than checking a schema unrelated to it.
|
|
9
|
+
const extendedSchema = defineSchema({
|
|
10
|
+
...tileSchema,
|
|
11
|
+
tables: {
|
|
12
|
+
...tileSchema.tables,
|
|
13
|
+
players: {
|
|
14
|
+
schema: table(z.object({
|
|
15
|
+
userId: z.string(),
|
|
16
|
+
mark: z.enum(["X", "O"]).nullable(),
|
|
17
|
+
score: z.number(),
|
|
18
|
+
})),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
mutators: {
|
|
22
|
+
setScore: { input: z.object({ score: z.number() }) },
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
type ExtendedSchema = typeof extendedSchema;
|
|
26
|
+
const mutators: InferMutatorHandlers<ExtendedSchema> = {
|
|
27
|
+
setScore: async (ctx, { score }) => {
|
|
28
|
+
await ctx.table("players").set({
|
|
29
|
+
itemKey: ctx.userId,
|
|
30
|
+
value: { userId: ctx.userId, mark: null, score },
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const backendConfig = defineBackendConfig({ schema: extendedSchema, mutators });
|
|
35
|
+
function createStore() {
|
|
36
|
+
return createPoeTileTestHarness<ExtendedSchema>({ store: { backendConfig } });
|
|
37
|
+
}
|
|
38
|
+
type TodoStore = Awaited<ReturnType<ReturnType<typeof createStore>["createClient"]>>["store"];
|
|
39
|
+
function getPlayer(store: TodoStore, userId: string) {
|
|
40
|
+
return store.query((ctx) => ctx.table("players").get(userId));
|
|
41
|
+
}
|
|
42
|
+
type Player = NonNullable<Awaited<ReturnType<typeof getPlayer>>>;
|
|
43
|
+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends
|
|
44
|
+
(<T>() => T extends B ? 1 : 2) ? true : false;
|
|
45
|
+
type PlayerRow = { userId: string; mark: "X" | "O" | null; score: number };
|
|
46
|
+
// Store reads return rows whose top-level properties are readonly.
|
|
47
|
+
const exactRow: Equal<Player, { readonly userId: string; readonly mark: "X" | "O" | null; readonly score: number }> = true;
|
|
48
|
+
const exactInput: Equal<Parameters<TodoStore["mutate"]["setScore"]>[0], { score: number }> = true;
|
|
49
|
+
void exactRow;
|
|
50
|
+
void exactInput;
|
|
51
|
+
|
|
52
|
+
// Negative checks without a suppression comment, which the scaffold's
|
|
53
|
+
// type-check rejects: each type is false when the argument is refused.
|
|
54
|
+
type Accepts<Param, Arg> = [Arg] extends [Param] ? true : false;
|
|
55
|
+
// The extended mutator accepts a numeric score, not text.
|
|
56
|
+
const rejectsTextScore: Accepts<Parameters<TodoStore["mutate"]["setScore"]>[0], { score: "high" }> = false;
|
|
57
|
+
// Readers receive transactions, not store instances.
|
|
58
|
+
type ReaderContext = Parameters<Parameters<TodoStore["query"]>[0]>[0];
|
|
59
|
+
const rejectsTransactionAsStore: Accepts<Parameters<typeof getPlayer>[0], ReaderContext> = false;
|
|
60
|
+
void rejectsTextScore;
|
|
61
|
+
void rejectsTransactionAsStore;
|
|
62
|
+
|
|
63
|
+
test("installed manager harness preserves the supplied config's Poe client type", async () => {
|
|
64
|
+
const h = await createPoeTileInManagerTestHarness({
|
|
65
|
+
tile: {
|
|
66
|
+
typeId: "typed-manager",
|
|
67
|
+
clientConfig: defineClientConfig<ExtendedSchema>({ schemaVersion: 1, mutators }),
|
|
68
|
+
backendConfig,
|
|
69
|
+
},
|
|
70
|
+
users: ["alice", "bob"],
|
|
71
|
+
});
|
|
72
|
+
try {
|
|
73
|
+
const alice = h.tile("alice").poe;
|
|
74
|
+
const exactClient: Equal<typeof alice, PoeAPI<InferSyncedStoreClient<ExtendedSchema>>> = true;
|
|
75
|
+
void exactClient;
|
|
76
|
+
await (await alice.store.mutate.setScore({ score: 4 })).confirmed;
|
|
77
|
+
const bob = h.tile("bob").poe.store;
|
|
78
|
+
const matched = await waitForKeyMatch(bob, {
|
|
79
|
+
table: "players", key: "alice", match: (player) => player.score === 4,
|
|
80
|
+
});
|
|
81
|
+
const exactMatch: Equal<typeof matched, PlayerRow> = true;
|
|
82
|
+
void exactMatch;
|
|
83
|
+
expect(await getPlayer(bob, "alice")).toEqual({ userId: "alice", mark: null, score: 4 });
|
|
84
|
+
} finally {
|
|
85
|
+
h.dispose();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("an extended scaffold mutator keeps exact input and row types through installed harness clients", async () => {
|
|
90
|
+
const harness = createStore();
|
|
91
|
+
try {
|
|
92
|
+
const { store: alice } = await harness.createClient({ userId: "alice" });
|
|
93
|
+
const { store: bob } = await harness.createClient({ userId: "bob" });
|
|
94
|
+
const result = await alice.mutate.setScore({ score: 3 });
|
|
95
|
+
await result.confirmed;
|
|
96
|
+
await waitForKeyMatch(bob, {
|
|
97
|
+
table: "players", key: "alice", match: (player) => player.score === 3,
|
|
98
|
+
});
|
|
99
|
+
expect(await getPlayer(bob, "alice")).toEqual({ userId: "alice", mark: null, score: 3 });
|
|
100
|
+
// A new client reads authoritative data, not the writer's optimistic overlay.
|
|
101
|
+
const { store: reopened } = await harness.createClient({ userId: "observer" });
|
|
102
|
+
expect(await getPlayer(reopened, "alice")).toEqual({ userId: "alice", mark: null, score: 3 });
|
|
103
|
+
} finally {
|
|
104
|
+
harness.dispose();
|
|
105
|
+
}
|
|
106
|
+
});
|