@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.
Files changed (303) hide show
  1. package/README.md +30 -2
  2. package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
  3. package/bundled-resources/poe-tile-templates/base/README.md +7 -0
  4. package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
  5. package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
  6. package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
  7. package/bundled-resources/poe-tile-templates/base/package.json +36 -0
  8. package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
  9. package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
  10. package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
  11. package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
  12. package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
  13. package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
  14. package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
  15. package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
  16. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
  17. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
  18. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
  19. package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
  20. package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
  21. package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
  22. package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
  23. package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
  24. package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
  25. package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
  26. package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
  27. package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
  28. package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
  29. package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
  30. package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
  31. package/bundled-resources/poe-tile-templates/index.ts +27 -0
  32. package/bundled-resources/poe-tile-templates/package.json +31 -0
  33. package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
  34. package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
  35. package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
  36. package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
  37. package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
  38. package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
  39. package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
  40. package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
  41. package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
  42. package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
  43. package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
  44. package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
  45. package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
  46. package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
  47. package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
  48. package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
  49. package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
  50. package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
  51. package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
  52. package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
  53. package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
  54. package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
  55. package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
  56. package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
  57. package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
  58. package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
  59. package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
  60. package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
  61. package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
  62. package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
  63. package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
  64. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
  65. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
  66. package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
  67. package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
  68. package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
  69. package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
  70. package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
  71. package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
  72. package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
  73. package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
  74. package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
  75. package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
  76. package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
  77. package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
  78. package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
  79. package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
  80. package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
  81. package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
  82. package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
  83. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
  84. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
  85. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
  86. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
  87. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
  88. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
  89. package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
  90. package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
  91. package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
  92. package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
  93. package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
  94. package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
  95. package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
  96. package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
  97. package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
  98. package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
  99. package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
  100. package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
  101. package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
  102. package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
  103. package/cli.ts +134 -0
  104. package/index.ts +96 -0
  105. package/package.json +48 -5
  106. package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
  107. package/skills/audio-generation/SKILL.md +125 -0
  108. package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
  109. package/skills/finish-prototype/SKILL.md +22 -0
  110. package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
  111. package/skills/help-me-build/SKILL.md +56 -0
  112. package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
  113. package/skills/image-generation/SKILL.md +128 -0
  114. package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
  115. package/skills/one-shot/SKILL.md +22 -0
  116. package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
  117. package/skills/platform-prototype/SKILL.md +60 -0
  118. package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
  119. package/skills/platform-subagent/SKILL.md +16 -0
  120. package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
  121. package/skills/poe-tiles-cli/SKILL.md +609 -0
  122. package/skills/poe-tiles-cli/references/device-motion.md +40 -0
  123. package/skills/poe-tiles-cli/references/player-updates.md +41 -0
  124. package/skills/prototype/.generated-by-poe-templated-docs +0 -0
  125. package/skills/prototype/SKILL.md +149 -0
  126. package/skills/publish/.generated-by-poe-templated-docs +0 -0
  127. package/skills/publish/SKILL.md +73 -0
  128. package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
  129. package/skills/synced-store/SKILL.md +583 -0
  130. package/skills/synced-store/references/actions.md +85 -0
  131. package/skills/synced-store/references/api-patterns.md +245 -0
  132. package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
  133. package/skills/synced-store/references/client-api-reference.md +263 -0
  134. package/skills/synced-store/references/data-visibility.md +95 -0
  135. package/skills/synced-store/references/external-stores.md +162 -0
  136. package/skills/synced-store/references/file-uploads.md +216 -0
  137. package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
  138. package/skills/synced-store/references/limitations.md +72 -0
  139. package/skills/synced-store/references/live-data-limit-hook.md +131 -0
  140. package/skills/synced-store/references/mutator-rules.md +169 -0
  141. package/skills/synced-store/references/platform.md +49 -0
  142. package/skills/synced-store/references/schema-and-bindings.md +85 -0
  143. package/skills/synced-store/references/schema-libraries.md +57 -0
  144. package/skills/synced-store/references/schema-migrations.md +119 -0
  145. package/skills/synced-store/references/searchable-tables.md +27 -0
  146. package/skills/synced-store/references/server-forking.md +115 -0
  147. package/skills/synced-store/references/singleton-tables.md +61 -0
  148. package/skills/synced-store/references/sort-keys.md +253 -0
  149. package/skills/synced-store/references/ui-patterns.md +95 -0
  150. package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
  151. package/skills/tile-creator/SKILL.md +197 -0
  152. package/skills/tile-creator/references/assets.md +124 -0
  153. package/skills/tile-creator/references/backend-api.md +354 -0
  154. package/skills/tile-creator/references/cli-limitations.md +64 -0
  155. package/skills/tile-creator/references/cli.md +604 -0
  156. package/skills/tile-creator/references/client-api.md +2407 -0
  157. package/skills/tile-creator/references/composing-apps.md +166 -0
  158. package/skills/tile-creator/references/e2e-tests.md +55 -0
  159. package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
  160. package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
  161. package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
  162. package/skills/tile-creator/references/native-results.md +100 -0
  163. package/skills/tile-creator/references/platform-integration.md +201 -0
  164. package/skills/tile-creator/references/power-report.md +199 -0
  165. package/skills/tile-creator/references/publish-rollout.md +166 -0
  166. package/skills/tile-creator/references/publishing.md +33 -0
  167. package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
  168. package/skills/tile-creator/references/render-check.md +266 -0
  169. package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
  170. package/skills/tile-creator/references/safe-area-insets.md +79 -0
  171. package/skills/tile-creator/references/sandbox-limitations.md +32 -0
  172. package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
  173. package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
  174. package/skills/tile-creator/references/simulations.md +125 -0
  175. package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
  176. package/skills/tile-creator/references/troubleshooting.md +22 -0
  177. package/skills/tile-creator/references/turn-based-mutator.md +43 -0
  178. package/skills/tile-creator/references/user-erasure.md +14 -0
  179. package/skills/tile-creator/references/vite-plugin.md +166 -0
  180. package/skills/tile-creator/references/workspace-retention.md +72 -0
  181. package/src/admin-conversions-client.ts +28 -0
  182. package/src/admin-reviews-client.ts +36 -0
  183. package/src/api.generated.ts +1527 -0
  184. package/src/auth-token.ts +198 -0
  185. package/src/bounded-read.ts +35 -0
  186. package/src/bun-version.ts +33 -0
  187. package/src/checkout-base.ts +207 -0
  188. package/src/cli-bun-version.ts +16 -0
  189. package/src/cli-env.ts +28 -0
  190. package/src/cli-name.ts +23 -0
  191. package/src/client.ts +2474 -0
  192. package/src/collect-files.ts +226 -0
  193. package/src/commands/accounts.ts +55 -0
  194. package/src/commands/admin-abandon-conversion.ts +60 -0
  195. package/src/commands/admin-reviews.ts +66 -0
  196. package/src/commands/admin.ts +219 -0
  197. package/src/commands/auth.ts +89 -0
  198. package/src/commands/checkout-prototype.ts +67 -0
  199. package/src/commands/creator-source-capability.ts +11 -0
  200. package/src/commands/doctor-bun.ts +145 -0
  201. package/src/commands/doctor-command.ts +64 -0
  202. package/src/commands/doctor-package-json.ts +47 -0
  203. package/src/commands/doctor-sdk-pin.ts +156 -0
  204. package/src/commands/doctor-store-keys-lexer.ts +213 -0
  205. package/src/commands/doctor-store-keys-scan.ts +262 -0
  206. package/src/commands/doctor-store-keys.ts +196 -0
  207. package/src/commands/doctor.ts +371 -0
  208. package/src/commands/init/blank-scaffold-templates.ts +397 -0
  209. package/src/commands/init/index.ts +170 -0
  210. package/src/commands/init/internal-toolchain.ts +49 -0
  211. package/src/commands/init/manager-test-template.ts +107 -0
  212. package/src/commands/init/multiplayer-test-template.ts +217 -0
  213. package/src/commands/init/name-input.tsx +167 -0
  214. package/src/commands/init/no-store-scaffold-templates.ts +281 -0
  215. package/src/commands/init/no-store-scaffold.ts +134 -0
  216. package/src/commands/init/package-json-scripts.ts +72 -0
  217. package/src/commands/init/scaffold.ts +960 -0
  218. package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
  219. package/src/commands/init/sdk-tarball-url.ts +31 -0
  220. package/src/commands/init/template-picker.tsx +147 -0
  221. package/src/commands/inspect-child-entry.ts +107 -0
  222. package/src/commands/inspect-contract.ts +87 -0
  223. package/src/commands/inspect-freshness.ts +217 -0
  224. package/src/commands/inspect-lock.ts +201 -0
  225. package/src/commands/inspect-options.ts +360 -0
  226. package/src/commands/inspect-orchestrate.ts +375 -0
  227. package/src/commands/inspect-process.ts +172 -0
  228. package/src/commands/inspect-ready.ts +65 -0
  229. package/src/commands/inspect-report.ts +235 -0
  230. package/src/commands/inspect-run-state.ts +296 -0
  231. package/src/commands/inspect-run.ts +157 -0
  232. package/src/commands/inspect-watchdog.ts +74 -0
  233. package/src/commands/install-joiner.ts +208 -0
  234. package/src/commands/login.ts +308 -0
  235. package/src/commands/models.ts +40 -0
  236. package/src/commands/parse-options.ts +36 -0
  237. package/src/commands/remix-package-json.ts +64 -0
  238. package/src/commands/remix.ts +379 -0
  239. package/src/commands/sdk-url.ts +141 -0
  240. package/src/commands/simulations.ts +133 -0
  241. package/src/commands/skills.ts +108 -0
  242. package/src/commands/store-files.ts +92 -0
  243. package/src/commands/stores.ts +703 -0
  244. package/src/commands/tiles-channel-commands.ts +115 -0
  245. package/src/commands/tiles-checkout.ts +351 -0
  246. package/src/commands/tiles-gallery-command.ts +95 -0
  247. package/src/commands/tiles-get-helpers.ts +27 -0
  248. package/src/commands/tiles-inspect.ts +276 -0
  249. package/src/commands/tiles-power-command.ts +308 -0
  250. package/src/commands/tiles-power-format.ts +396 -0
  251. package/src/commands/tiles-power-versions.ts +299 -0
  252. package/src/commands/tiles-publish-helpers.ts +145 -0
  253. package/src/commands/tiles-upload-command.ts +277 -0
  254. package/src/commands/tiles-version-commands.ts +201 -0
  255. package/src/commands/tiles-visibility-command.ts +103 -0
  256. package/src/commands/tiles.ts +257 -0
  257. package/src/commands/upgrade.ts +307 -0
  258. package/src/commit-in-progress.ts +42 -0
  259. package/src/creator-source-context.ts +97 -0
  260. package/src/creator-source-publish.ts +52 -0
  261. package/src/deferred-assets.ts +125 -0
  262. package/src/distribution.ts +28 -0
  263. package/src/errors.ts +61 -0
  264. package/src/install-command.ts +43 -0
  265. package/src/output.ts +62 -0
  266. package/src/poe-tile-config-files.ts +100 -0
  267. package/src/poe-tile-config-players.ts +168 -0
  268. package/src/poe-tile-config-remix.ts +166 -0
  269. package/src/poe-tile-config.ts +831 -0
  270. package/src/power-report-client.ts +55 -0
  271. package/src/prototype-startup.ts +21 -0
  272. package/src/publish-change-summary.ts +55 -0
  273. package/src/publish-overrides-validation.ts +49 -0
  274. package/src/publish-pack.ts +167 -0
  275. package/src/publish-phases.ts +57 -0
  276. package/src/publish-retry.ts +51 -0
  277. package/src/publish-tile-from-config.ts +434 -0
  278. package/src/recorder-stream.ts +169 -0
  279. package/src/remix-provenance.ts +156 -0
  280. package/src/resolve-client-credential.ts +71 -0
  281. package/src/resolve-media-uploads.ts +147 -0
  282. package/src/sdk-dependency.ts +54 -0
  283. package/src/sdk-skills.ts +85 -0
  284. package/src/should-skip-client-setup.ts +20 -0
  285. package/src/simulation-snapshot.ts +123 -0
  286. package/src/simulation-types.ts +74 -0
  287. package/src/simulations-client.ts +112 -0
  288. package/src/source-bundle.ts +466 -0
  289. package/src/staged-publish-cleanup.ts +44 -0
  290. package/src/staged-publish-deferred.ts +160 -0
  291. package/src/staged-publish.ts +401 -0
  292. package/src/store-file-upload.ts +268 -0
  293. package/src/store-request.ts +168 -0
  294. package/src/tar-canonical.ts +41 -0
  295. package/src/tar-extensions.ts +159 -0
  296. package/src/tar-extract.ts +193 -0
  297. package/src/tar-parse.ts +224 -0
  298. package/src/tar.ts +231 -0
  299. package/src/template-check-scripts.ts +18 -0
  300. package/src/tile-gallery-client.ts +82 -0
  301. package/src/types.ts +258 -0
  302. package/src/upload-concurrency.ts +54 -0
  303. package/src/whole-tile.ts +52 -0
@@ -0,0 +1,703 @@
1
+ // owner: jyoung-q
2
+ /* biome-ignore-all lint/nursery/noExcessiveLinesPerFile: existing file exceeds 400 lines; add new tests or code to focused companion files instead. No new exceptions to this rule should be made. */
3
+ /**
4
+ * Store commands: access, schema, mutate
5
+ */
6
+
7
+ import { readFileSync } from "node:fs";
8
+ import { resolve } from "node:path";
9
+ import { Command } from "commander";
10
+ import { cliName } from "../cli-name.js";
11
+ import type {
12
+ FailedMutationInfo,
13
+ JSONValue,
14
+ SlopPoeClient,
15
+ StoreAccessResult,
16
+ StoreActionResult,
17
+ StoreActionSchemaInfo,
18
+ StoreGetResult,
19
+ StoreMutateResult,
20
+ StoreMutatorSchemaInfo,
21
+ StorePullResult,
22
+ StoreReadCursor,
23
+ StoreScanResult,
24
+ StoreSchemaResult,
25
+ } from "../client.js";
26
+ import { CliError } from "../errors.js";
27
+ import { isJsonMode, printJson, printKeyValue, printTable } from "../output.js";
28
+ import {
29
+ parseNonNegativeIntegerOption,
30
+ parsePositiveIntegerOption,
31
+ } from "./parse-options.js";
32
+ import { createStoreFilesCommands } from "./store-files.js";
33
+
34
+ const DEFAULT_MUTATE_TIMEOUT_MS = 15_000;
35
+
36
+ interface MutateCommandOptions {
37
+ input?: string;
38
+ inputFile?: string;
39
+ timeoutMs: string;
40
+ }
41
+
42
+ interface ActionCommandOptions {
43
+ input?: string;
44
+ inputFile?: string;
45
+ }
46
+
47
+ interface PullCommandOptions {
48
+ afterVersion: string;
49
+ targetLocalBytes: string;
50
+ timeoutMs: string;
51
+ }
52
+
53
+ interface ScanCommandOptions {
54
+ sortKeyPrefix?: string;
55
+ itemKeyPrefix?: string;
56
+ cursor?: string;
57
+ limit?: string;
58
+ reverse?: boolean;
59
+ }
60
+
61
+ export function createStoresCommands(client: SlopPoeClient): Command {
62
+ const stores = new Command("stores")
63
+ .alias("store")
64
+ .description("Store operations");
65
+ stores.addCommand(createStoreFilesCommands(client));
66
+
67
+ stores
68
+ .command("access")
69
+ .description("Verify the authenticated user is an active member of a store")
70
+ .argument("<typeId>", "Store type ID")
71
+ .argument("<instanceId>", "Store instance ID")
72
+ .option(
73
+ "--timeout-ms <ms>",
74
+ "WebSocket open and response timeout in milliseconds",
75
+ String(DEFAULT_MUTATE_TIMEOUT_MS),
76
+ )
77
+ .action(async function (
78
+ this: Command,
79
+ typeId: string,
80
+ instanceId: string,
81
+ opts: Pick<MutateCommandOptions, "timeoutMs">,
82
+ ) {
83
+ const timeoutMs = parsePositiveIntegerOption(
84
+ opts.timeoutMs,
85
+ "--timeout-ms",
86
+ );
87
+ const result = await client.checkStoreAccess({
88
+ storeTypeId: typeId,
89
+ instanceId,
90
+ timeoutMs,
91
+ });
92
+
93
+ if (!result.hasAccess) {
94
+ throw new CliError(
95
+ `Current user ${result.userId} is not an active member of ${typeId}/${instanceId}.`,
96
+ );
97
+ }
98
+
99
+ if (isJsonMode(this)) {
100
+ printJson(result);
101
+ } else {
102
+ printAccessResult(result);
103
+ }
104
+ });
105
+
106
+ stores
107
+ .command("pull")
108
+ .description("Run a regular user pull against a store instance")
109
+ .argument("<typeId>", "Store type ID")
110
+ .argument("<instanceId>", "Store instance ID")
111
+ .option(
112
+ "--after-version <version>",
113
+ "Only return patches after this store version",
114
+ "0",
115
+ )
116
+ .option(
117
+ "--target-local-bytes <bytes>",
118
+ "Target local data budget for the pull",
119
+ "1000000",
120
+ )
121
+ .option(
122
+ "--timeout-ms <ms>",
123
+ "WebSocket open and response timeout in milliseconds",
124
+ String(DEFAULT_MUTATE_TIMEOUT_MS),
125
+ )
126
+ .action(async function (
127
+ this: Command,
128
+ typeId: string,
129
+ instanceId: string,
130
+ opts: PullCommandOptions,
131
+ ) {
132
+ const result = await client.pullStore({
133
+ storeTypeId: typeId,
134
+ instanceId,
135
+ afterVersion: parseNonNegativeIntegerOption(
136
+ opts.afterVersion,
137
+ "--after-version",
138
+ ),
139
+ targetLocalBytes: parsePositiveIntegerOption(
140
+ opts.targetLocalBytes,
141
+ "--target-local-bytes",
142
+ ),
143
+ timeoutMs: parsePositiveIntegerOption(opts.timeoutMs, "--timeout-ms"),
144
+ });
145
+
146
+ if (isJsonMode(this)) {
147
+ printJson(result);
148
+ } else {
149
+ printPullResult(result);
150
+ }
151
+ });
152
+
153
+ stores
154
+ .command("get")
155
+ .description("Read one user-visible item from a store table")
156
+ .argument("<typeId>", "Store type ID")
157
+ .argument("<instanceId>", "Store instance ID")
158
+ .argument("<tableName>", "Table name")
159
+ .argument("<itemKey>", "Item key")
160
+ .action(async function (
161
+ this: Command,
162
+ typeId: string,
163
+ instanceId: string,
164
+ tableName: string,
165
+ itemKey: string,
166
+ ) {
167
+ const result = await client.getStoreItem({
168
+ storeTypeId: typeId,
169
+ instanceId,
170
+ tableName,
171
+ key: itemKey,
172
+ });
173
+
174
+ if (isJsonMode(this)) {
175
+ printJson(result);
176
+ } else {
177
+ printGetResult(result);
178
+ }
179
+ });
180
+
181
+ stores
182
+ .command("scan")
183
+ .description("Scan user-visible items from a store table")
184
+ .argument("<typeId>", "Store type ID")
185
+ .argument("<instanceId>", "Store instance ID")
186
+ .argument("<tableName>", "Table name")
187
+ .option("--sort-key-prefix <prefix>", "Only include sort keys with prefix")
188
+ .option("--item-key-prefix <prefix>", "Only include item keys with prefix")
189
+ .option("--cursor <cursor>", 'EntryKey JSON cursor, "$first", or "$last"')
190
+ .option("--limit <count>", "Maximum number of items to return")
191
+ .option("--reverse", "Scan in descending order")
192
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Existing function exceeds the cognitive-complexity limit; keep the rule enabled for new code.
193
+ .action(async function (
194
+ this: Command,
195
+ typeId: string,
196
+ instanceId: string,
197
+ tableName: string,
198
+ opts: ScanCommandOptions,
199
+ ) {
200
+ const prefix =
201
+ opts.sortKeyPrefix !== undefined || opts.itemKeyPrefix !== undefined
202
+ ? {
203
+ ...(opts.sortKeyPrefix !== undefined
204
+ ? { sortKey: opts.sortKeyPrefix }
205
+ : undefined),
206
+ ...(opts.itemKeyPrefix !== undefined
207
+ ? { itemKey: opts.itemKeyPrefix }
208
+ : undefined),
209
+ }
210
+ : undefined;
211
+ const result = await client.scanStore({
212
+ storeTypeId: typeId,
213
+ instanceId,
214
+ tableName,
215
+ ...(prefix !== undefined ? { prefix } : undefined),
216
+ ...(opts.cursor !== undefined
217
+ ? { cursor: parseScanCursor(opts.cursor) }
218
+ : undefined),
219
+ ...(opts.limit !== undefined
220
+ ? { limit: parsePositiveIntegerOption(opts.limit, "--limit") }
221
+ : undefined),
222
+ ...(opts.reverse === true ? { reverse: true } : undefined),
223
+ });
224
+
225
+ if (isJsonMode(this)) {
226
+ printJson(result);
227
+ } else {
228
+ printScanResult(result);
229
+ }
230
+ });
231
+
232
+ stores
233
+ .command("schema")
234
+ .description("Show store schema and CLI commands for available mutators")
235
+ .argument("<typeId>", "Store type ID")
236
+ .argument("<instanceId>", "Store instance ID")
237
+ .option(
238
+ "--timeout-ms <ms>",
239
+ "WebSocket open and response timeout in milliseconds",
240
+ String(DEFAULT_MUTATE_TIMEOUT_MS),
241
+ )
242
+ .action(async function (
243
+ this: Command,
244
+ typeId: string,
245
+ instanceId: string,
246
+ opts: Pick<MutateCommandOptions, "timeoutMs">,
247
+ ) {
248
+ const timeoutMs = parsePositiveIntegerOption(
249
+ opts.timeoutMs,
250
+ "--timeout-ms",
251
+ );
252
+ const result = await client.getStoreSchema({
253
+ storeTypeId: typeId,
254
+ instanceId,
255
+ timeoutMs,
256
+ });
257
+ const commands = buildSchemaCommands(result);
258
+
259
+ if (isJsonMode(this)) {
260
+ printJson({ ...result, commands });
261
+ } else {
262
+ printSchemaResult(result, commands);
263
+ }
264
+ });
265
+
266
+ stores
267
+ .command("action")
268
+ .description("Execute a server-side action as the authenticated user")
269
+ .argument("<typeId>", "Store type ID")
270
+ .argument("<instanceId>", "Store instance ID")
271
+ .argument("<actionName>", "Action name")
272
+ .option("--input <json>", "JSON input to pass to the action")
273
+ .option("--input-file <path>", "Read action input JSON from a file")
274
+ .action(async function (
275
+ this: Command,
276
+ typeId: string,
277
+ instanceId: string,
278
+ actionName: string,
279
+ opts: ActionCommandOptions,
280
+ ) {
281
+ const input = readOptionalJsonInput(opts);
282
+ const result = await client.actionStore({
283
+ storeTypeId: typeId,
284
+ instanceId,
285
+ actionName,
286
+ input,
287
+ });
288
+
289
+ if (isJsonMode(this)) {
290
+ printJson(result);
291
+ } else {
292
+ printActionResult(result);
293
+ }
294
+ });
295
+
296
+ stores
297
+ .command("mutate")
298
+ .description("Dispatch a mutation to a store instance")
299
+ .argument("<typeId>", "Store type ID")
300
+ .argument("<instanceId>", "Store instance ID")
301
+ .argument("<mutationName>", "Mutator name")
302
+ .option("--input <json>", "JSON input to pass to the mutator")
303
+ .option("--input-file <path>", "Read mutator input JSON from a file")
304
+ .option(
305
+ "--timeout-ms <ms>",
306
+ "WebSocket open and response timeout in milliseconds",
307
+ String(DEFAULT_MUTATE_TIMEOUT_MS),
308
+ )
309
+ .action(async function (
310
+ this: Command,
311
+ typeId: string,
312
+ instanceId: string,
313
+ mutationName: string,
314
+ opts: MutateCommandOptions,
315
+ ) {
316
+ const input = readMutationInput(opts);
317
+ const timeoutMs = parsePositiveIntegerOption(
318
+ opts.timeoutMs,
319
+ "--timeout-ms",
320
+ );
321
+
322
+ const result = await client.mutateStore({
323
+ storeTypeId: typeId,
324
+ instanceId,
325
+ mutationName,
326
+ input,
327
+ timeoutMs,
328
+ });
329
+
330
+ if (result.failedMutations.length > 0) {
331
+ throw new CliError(failedMutationMessage(result.failedMutations));
332
+ }
333
+
334
+ if (isJsonMode(this)) {
335
+ printJson(result);
336
+ } else {
337
+ printMutationResult(result);
338
+ }
339
+ });
340
+
341
+ return stores;
342
+ }
343
+
344
+ function readMutationInput(opts: MutateCommandOptions): JSONValue {
345
+ const hasInlineInput = opts.input !== undefined;
346
+ const hasFileInput = opts.inputFile !== undefined;
347
+ if (hasInlineInput === hasFileInput) {
348
+ throw new CliError(
349
+ "Pass exactly one of --input <json> or --input-file <path>.",
350
+ );
351
+ }
352
+
353
+ if (hasInlineInput) {
354
+ return parseJsonInput(opts.input ?? "", "--input");
355
+ }
356
+
357
+ const filePath = resolve(opts.inputFile ?? "");
358
+ let fileContents: string;
359
+ try {
360
+ fileContents = readFileSync(filePath, "utf8");
361
+ } catch (error) {
362
+ throw new CliError(
363
+ `Could not read --input-file ${filePath}: ${errorMessage(error)}`,
364
+ );
365
+ }
366
+ return parseJsonInput(fileContents, `--input-file ${filePath}`);
367
+ }
368
+
369
+ function readOptionalJsonInput(opts: ActionCommandOptions): JSONValue {
370
+ const hasInlineInput = opts.input !== undefined;
371
+ const hasFileInput = opts.inputFile !== undefined;
372
+ if (hasInlineInput && hasFileInput) {
373
+ throw new CliError(
374
+ "Pass at most one of --input <json> or --input-file <path>.",
375
+ );
376
+ }
377
+ if (!hasInlineInput && !hasFileInput) return {};
378
+
379
+ if (hasInlineInput) {
380
+ return parseJsonInput(opts.input ?? "", "--input");
381
+ }
382
+
383
+ const filePath = resolve(opts.inputFile ?? "");
384
+ let fileContents: string;
385
+ try {
386
+ fileContents = readFileSync(filePath, "utf8");
387
+ } catch (error) {
388
+ throw new CliError(
389
+ `Could not read --input-file ${filePath}: ${errorMessage(error)}`,
390
+ );
391
+ }
392
+ return parseJsonInput(fileContents, `--input-file ${filePath}`);
393
+ }
394
+
395
+ function parseJsonInput(text: string, sourceName: string): JSONValue {
396
+ let parsed: unknown;
397
+ try {
398
+ parsed = JSON.parse(text) as unknown;
399
+ } catch (error) {
400
+ throw new CliError(
401
+ `${sourceName} must be valid JSON: ${errorMessage(error)}`,
402
+ );
403
+ }
404
+ if (!isJsonValue(parsed)) {
405
+ throw new CliError(`${sourceName} must be a JSON-compatible value.`);
406
+ }
407
+ return parsed;
408
+ }
409
+
410
+ function isJsonValue(value: unknown): value is JSONValue {
411
+ if (value === null) return true;
412
+ if (typeof value === "string" || typeof value === "boolean") return true;
413
+ if (typeof value === "number") return Number.isFinite(value);
414
+ if (Array.isArray(value)) return value.every(isJsonValue);
415
+ if (typeof value !== "object") return false;
416
+ const prototype = Object.getPrototypeOf(value) as unknown;
417
+ if (prototype !== Object.prototype && prototype !== null) return false;
418
+ return Object.values(value).every(isJsonValue);
419
+ }
420
+
421
+ function isRecord(value: unknown): value is Record<string, unknown> {
422
+ return typeof value === "object" && value !== null && !Array.isArray(value);
423
+ }
424
+
425
+ function parseScanCursor(value: string): StoreReadCursor {
426
+ if (value === "$first" || value === "$last") return value;
427
+ const parsed = parseJsonInput(value, "--cursor");
428
+ if (!isRecord(parsed) || typeof parsed["itemKey"] !== "string") {
429
+ throw new CliError(
430
+ '--cursor must be "$first", "$last", or JSON like {"itemKey":"id","sortKey":"optional"}.',
431
+ );
432
+ }
433
+ if (
434
+ parsed["sortKey"] !== undefined &&
435
+ typeof parsed["sortKey"] !== "string"
436
+ ) {
437
+ throw new CliError("--cursor sortKey must be a string when provided.");
438
+ }
439
+ return {
440
+ ...(parsed["sortKey"] !== undefined
441
+ ? { sortKey: parsed["sortKey"] }
442
+ : undefined),
443
+ itemKey: parsed["itemKey"],
444
+ };
445
+ }
446
+
447
+ function failedMutationMessage(failedMutations: FailedMutationInfo[]): string {
448
+ const details = failedMutations
449
+ .map(
450
+ (failed) =>
451
+ `#${failed.mutation_id} ${failed.error_type}: ${failed.error_message}`,
452
+ )
453
+ .join("\n");
454
+ return `Mutation failed on the server:\n${details}`;
455
+ }
456
+
457
+ function printAccessResult(result: StoreAccessResult): void {
458
+ console.log("Access verified.");
459
+ printKeyValue([
460
+ ["Store Type ID", result.storeTypeId],
461
+ ["Instance ID", result.instanceId],
462
+ ["User ID", result.userId],
463
+ ["Version", result.version],
464
+ ["Schema Version", result.schemaVersion],
465
+ ]);
466
+ }
467
+
468
+ function printMutationResult(result: StoreMutateResult): void {
469
+ console.log("Mutation dispatched.");
470
+ printKeyValue([
471
+ ["Store Type ID", result.storeTypeId],
472
+ ["Instance ID", result.instanceId],
473
+ ["Mutation", result.mutationName],
474
+ ["Version", result.version],
475
+ ["Schema Version", result.schemaVersion],
476
+ ["Request ID", result.requestId],
477
+ ]);
478
+
479
+ if (result.externalDispatchTargets.length === 0) return;
480
+ console.log("");
481
+ // No Status/Version columns: the push response returns at source commit,
482
+ // before the cross-store fan-out runs, so the server has no outcome to
483
+ // report yet. Printing a status here would be a fabrication. Wording says
484
+ // "declared" for the same reason.
485
+ console.log("External dispatches declared (delivered asynchronously):");
486
+ printTable({
487
+ headers: ["Target"],
488
+ rows: result.externalDispatchTargets.map((target) => [
489
+ `${target.targetStoreTypeId}/${target.targetInstanceId}`,
490
+ ]),
491
+ });
492
+ }
493
+
494
+ function printActionResult(result: StoreActionResult): void {
495
+ console.log("Action executed.");
496
+ printKeyValue([
497
+ ["Store Type ID", result.storeTypeId],
498
+ ["Instance ID", result.instanceId],
499
+ ["Action", result.actionName],
500
+ ["Result", JSON.stringify(result.result)],
501
+ ]);
502
+ }
503
+
504
+ function printPullResult(result: StorePullResult): void {
505
+ console.log("Store pull complete.");
506
+ printKeyValue([
507
+ ["Store Type ID", result.storeTypeId],
508
+ ["Instance ID", result.instanceId],
509
+ ["Version", result.finalMetadata.version],
510
+ ["Schema Version", result.finalMetadata.schema_version],
511
+ ["Patch Count", result.patches.length],
512
+ ["Request ID", result.requestId],
513
+ ]);
514
+
515
+ if (result.patches.length === 0) return;
516
+ console.log("");
517
+ console.log("Patches:");
518
+ printTable({
519
+ headers: ["Op", "Table", "Item Key", "Sort Key"],
520
+ rows: result.patches.map((patch) => [
521
+ patch.op,
522
+ patch.tableName,
523
+ patch.itemKey,
524
+ patch.sortKey ?? "",
525
+ ]),
526
+ });
527
+ }
528
+
529
+ function printGetResult(result: StoreGetResult): void {
530
+ console.log(result.found ? "Item found." : "Item not found.");
531
+ printKeyValue([
532
+ ["Store Type ID", result.storeTypeId],
533
+ ["Instance ID", result.instanceId],
534
+ ["Table", result.tableName],
535
+ ["Item Key", result.key],
536
+ ["Store Version", result.storeVersion],
537
+ ["Value", result.found ? JSON.stringify(result.value) : ""],
538
+ ]);
539
+ }
540
+
541
+ function printScanResult(result: StoreScanResult): void {
542
+ console.log("Scan complete.");
543
+ printKeyValue([
544
+ ["Store Type ID", result.storeTypeId],
545
+ ["Instance ID", result.instanceId],
546
+ ["Table", result.tableName],
547
+ ["Store Version", result.storeVersion],
548
+ ["Item Count", result.items.length],
549
+ ["Truncated", String(result.truncated)],
550
+ [
551
+ "Next Cursor",
552
+ result.nextCursor !== undefined ? JSON.stringify(result.nextCursor) : "",
553
+ ],
554
+ ]);
555
+
556
+ if (result.items.length === 0) return;
557
+ console.log("");
558
+ console.log("Items:");
559
+ printTable({
560
+ headers: ["Item Key", "Sort Key", "Value"],
561
+ rows: result.items.map((item) => [
562
+ item.itemKey,
563
+ item.sortKey,
564
+ JSON.stringify(item.value),
565
+ ]),
566
+ });
567
+ }
568
+
569
+ interface StoreSchemaCommands {
570
+ access: string;
571
+ pull: string;
572
+ get: string;
573
+ scan: string;
574
+ mutators: Array<{
575
+ name: string;
576
+ description?: string;
577
+ command: string;
578
+ }>;
579
+ actions: Array<{
580
+ name: string;
581
+ description?: string;
582
+ command: string;
583
+ }>;
584
+ }
585
+
586
+ function buildSchemaCommands(result: StoreSchemaResult): StoreSchemaCommands {
587
+ return {
588
+ access: `${cliName()} stores access ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)}`,
589
+ pull: `${cliName()} stores pull ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)} --after-version 0`,
590
+ get: `${cliName()} stores get ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)} '<tableName>' '<itemKey>'`,
591
+ scan: `${cliName()} stores scan ${shellQuote(result.storeTypeId)} ${shellQuote(result.instanceId)} '<tableName>' --limit 50`,
592
+ mutators: result.schema.mutators.map((mutator) => ({
593
+ name: mutator.name,
594
+ ...(mutator.description !== undefined
595
+ ? { description: mutator.description }
596
+ : undefined),
597
+ command: mutateCommandForSchema(result, mutator),
598
+ })),
599
+ actions: result.schema.actions.map((action) => ({
600
+ name: action.name,
601
+ ...(action.description !== undefined
602
+ ? { description: action.description }
603
+ : undefined),
604
+ command: actionCommandForSchema(result, action),
605
+ })),
606
+ };
607
+ }
608
+
609
+ function mutateCommandForSchema(
610
+ result: StoreSchemaResult,
611
+ mutator: StoreMutatorSchemaInfo,
612
+ ): string {
613
+ return [
614
+ cliName(),
615
+ "stores",
616
+ "mutate",
617
+ shellQuote(result.storeTypeId),
618
+ shellQuote(result.instanceId),
619
+ shellQuote(mutator.name),
620
+ "--input",
621
+ "'<json>'",
622
+ ].join(" ");
623
+ }
624
+
625
+ function actionCommandForSchema(
626
+ result: StoreSchemaResult,
627
+ action: StoreActionSchemaInfo,
628
+ ): string {
629
+ return [
630
+ cliName(),
631
+ "stores",
632
+ "action",
633
+ shellQuote(result.storeTypeId),
634
+ shellQuote(result.instanceId),
635
+ shellQuote(action.name),
636
+ "--input",
637
+ "'<json>'",
638
+ ].join(" ");
639
+ }
640
+
641
+ function printSchemaResult(
642
+ result: StoreSchemaResult,
643
+ commands: StoreSchemaCommands,
644
+ ): void {
645
+ console.log("Store schema.");
646
+ printKeyValue([
647
+ ["Store Type ID", result.storeTypeId],
648
+ ["Instance ID", result.instanceId],
649
+ ["Schema Type", result.schema.type],
650
+ ["Schema Version", result.schema.schemaVersion],
651
+ ]);
652
+
653
+ console.log("");
654
+ console.log("Commands:");
655
+ printKeyValue([
656
+ ["Verify Access", commands.access],
657
+ ["Pull", commands.pull],
658
+ ["Get", commands.get],
659
+ ["Scan", commands.scan],
660
+ ]);
661
+
662
+ if (commands.mutators.length === 0) {
663
+ console.log("");
664
+ console.log("No mutators found.");
665
+ } else {
666
+ console.log("");
667
+ console.log("Mutators:");
668
+ printTable({
669
+ headers: ["Name", "Description", "Command"],
670
+ rows: commands.mutators.map((mutator) => [
671
+ mutator.name,
672
+ mutator.description ?? "",
673
+ mutator.command,
674
+ ]),
675
+ });
676
+ }
677
+
678
+ if (commands.actions.length === 0) {
679
+ console.log("");
680
+ console.log("No actions found.");
681
+ return;
682
+ }
683
+
684
+ console.log("");
685
+ console.log("Actions:");
686
+ printTable({
687
+ headers: ["Name", "Description", "Command"],
688
+ rows: commands.actions.map((action) => [
689
+ action.name,
690
+ action.description ?? "",
691
+ action.command,
692
+ ]),
693
+ });
694
+ }
695
+
696
+ function shellQuote(value: string): string {
697
+ if (/^[A-Za-z0-9_./:@-]+$/.test(value)) return value;
698
+ return `'${value.replaceAll("'", "'\\''")}'`;
699
+ }
700
+
701
+ function errorMessage(error: unknown): string {
702
+ return error instanceof Error ? error.message : String(error);
703
+ }