@zaisma/cli 0.21.0 → 0.23.0

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 (2) hide show
  1. package/package.json +1 -1
  2. package/zaisma.mjs +23 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/cli",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "Upload and publish browser games on Zaisma from the command line.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/zaisma.mjs CHANGED
@@ -136,6 +136,8 @@ const COMMANDS = {
136
136
  secrets: { about: "A game's secrets, which its game server reads as server.secrets and room.secrets: their names and when each was set, never the values", arguments: [{ name: "slug" }], flags: {} },
137
137
  "secrets set": { about: "Set a secret for a game's server, replacing one of the same name: the value piped in, or typed without showing; it's never shown again", arguments: [{ name: "slug" }, { name: "secret_name" }], flags: {} },
138
138
  "secrets delete": { about: "Delete one of a game's secrets", arguments: [{ name: "slug" }, { name: "secret_name" }], flags: {} },
139
+ "kept-rooms": { about: "A game's kept rooms (room.setKept), worlds that sleep with nobody in them: each one's code, name, size and when it was last played, and the game's storage", arguments: [{ name: "slug" }], flags: {} },
140
+ "kept-rooms delete": { about: "Delete a kept room's world for good; players in it are sent out", arguments: [{ name: "slug" }, { name: "room_code" }], flags: {} },
139
141
  logs: {
140
142
  about: "What a game's server printed on Zaisma in the last 30 days, oldest first: the newest lines, older ones with --cursor, or new ones as they come with --follow",
141
143
  arguments: [{ name: "slug" }],
@@ -237,7 +239,7 @@ const COMMANDS = {
237
239
  help: { about: "This help; with --json, every command, flag, exit code and error code", arguments: [], flags: {} },
238
240
  };
239
241
  /** Commands with a second word, like zaisma forum post. */
240
- const SUBCOMMANDS = { links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"] };
242
+ const SUBCOMMANDS = { links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"], "kept-rooms": ["delete"] };
241
243
  /** Flags every command takes. */
242
244
  const GLOBAL_FLAGS = {
243
245
  json: { hasValue: false, about: "Print the API's answer as JSON, as-is (on failure its { error }), and nothing else" },
@@ -999,11 +1001,10 @@ async function database(command, values, flags) {
999
1001
  if (!answer.tables.length) console.log("No tables yet. Make one from your game server, or with: zaisma database query <slug> \"CREATE TABLE …\"");
1000
1002
  for (const table of answer.tables) console.log(`${table.sql};`);
1001
1003
  for (const index of answer.indexes) console.log(`${index.sql};`);
1002
- const percent = (used, free) => `${Math.floor((used / free) * 100)}%`;
1004
+ const hosting = answer.hosting_use_this_month;
1003
1005
  console.log(
1004
- `\nThis month: ${use.read_row_count.toLocaleString("en-US")} rows read (${percent(use.read_row_count, use.free_read_row_count)} of the free ${use.free_read_row_count.toLocaleString("en-US")}), ` +
1005
- `${use.written_row_count.toLocaleString("en-US")} written (${percent(use.written_row_count, use.free_written_row_count)} of ${use.free_written_row_count.toLocaleString("en-US")}), ` +
1006
- `${(use.storage_size_bytes / 1024 / 1024).toFixed(1)} MB stored (${percent(use.storage_size_bytes, use.free_storage_size_bytes)} of ${use.free_storage_size_bytes / 1024 / 1024} MB). Resets ${use.reset_date}.`,
1006
+ `\nThis month: ${use.read_row_count.toLocaleString("en-US")} rows read, ${use.written_row_count.toLocaleString("en-US")} written, ${sizeText(use.storage_size_bytes)} stored (a game keeps up to ${sizeText(use.maximum_storage_size_bytes)}). ` +
1007
+ `Free hosting this month: ${hosting.free_used_pct}% used${hosting.is_paused ? ", paused" : ""}. Resets ${hosting.resets_on_date}.`,
1007
1008
  );
1008
1009
  if (answer.restores.length) {
1009
1010
  console.log("\nRestores (newest first; undo with zaisma database undo-restore <slug> <id>):");
@@ -1455,6 +1456,21 @@ async function secrets(command, values) {
1455
1456
  if (answer.next_steps.some((step) => step.tool === "update_game")) console.log(`It calls no other servers yet: list the hosts it uses this with, like zaisma allowed-hosts ${values.slug} discord.com`);
1456
1457
  }
1457
1458
 
1459
+ /** A game's kept rooms (…/games/<slug>/kept-rooms…), as the MCP's list_kept_rooms and delete_kept_room. */
1460
+ async function keptRooms(command, values) {
1461
+ if (command === "kept-rooms") {
1462
+ const answer = await api("GET", `/games/${values.slug}/kept-rooms`);
1463
+ if (isJson) return printJson(answer);
1464
+ if (!answer.kept_rooms.length) console.log(`No kept rooms. A game server keeps one with room.setKept(true).`);
1465
+ for (const keptRoom of answer.kept_rooms) console.log(`${keptRoom.room_code} ${(keptRoom.name ?? "").padEnd(24)} ${sizeText(keptRoom.saved_size_bytes).padStart(9)} played ${keptRoom.last_played_at ? when(keptRoom.last_played_at) : "never"}`);
1466
+ console.log(`Storage: ${sizeText(answer.storage_size_bytes)} of the ${sizeText(answer.maximum_storage_size_bytes)} a game can keep (database and kept rooms).`);
1467
+ return;
1468
+ }
1469
+ const answer = await api("DELETE", `/games/${values.slug}/kept-rooms/${encodeURIComponent(values.room_code)}`);
1470
+ if (isJson) return printJson(answer);
1471
+ console.log(`Deleted kept room ${values.room_code.toUpperCase()} from ${values.slug}, and its world with it.`);
1472
+ }
1473
+
1458
1474
  /** A game server's logs (GET …/games/<slug>/logs), as the MCP's get_logs; --follow asks for new lines every 2 seconds. */
1459
1475
  async function logs(values, flags) {
1460
1476
  if (flags.follow && flags.cursor) refuse("conflicting_flags", { message: "--follow prints new lines, and --cursor older ones.", field: "cursor", fix: `Use one: zaisma logs ${values.slug} --follow, or zaisma logs ${values.slug} --cursor <next_cursor>.` });
@@ -1585,7 +1601,7 @@ function readKeys(given) {
1585
1601
  return keys;
1586
1602
  }
1587
1603
 
1588
- const sizeText = (sizeBytes) => (sizeBytes < 1024 ? `${sizeBytes} B` : sizeBytes < 1048576 ? `${(sizeBytes / 1024).toFixed(1)} KB` : `${(sizeBytes / 1048576).toFixed(1)} MB`);
1604
+ const sizeText = (sizeBytes) => (sizeBytes < 1024 ? `${sizeBytes} B` : sizeBytes < 1048576 ? `${(sizeBytes / 1024).toFixed(1)} KB` : sizeBytes < 1024 ** 3 ? `${(sizeBytes / 1048576).toFixed(1)} MB` : `${(sizeBytes / 1024 ** 3).toFixed(1)} GB`);
1589
1605
 
1590
1606
  /** A statement's rows as a table, then what it read and wrote. Blobs show their size. */
1591
1607
  function printRows({ rows, read_row_count: readRowCount, written_row_count: writtenRowCount }) {
@@ -1673,6 +1689,7 @@ async function run({ command, values, flags, globalFlags, rest }) {
1673
1689
  else if (command === "own-servers") await ownServers(values, flags);
1674
1690
  else if (command === "links" || command.startsWith("links ")) await links(command, values, flags);
1675
1691
  else if (command === "secrets" || command.startsWith("secrets ")) await secrets(command, values);
1692
+ else if (command === "kept-rooms" || command.startsWith("kept-rooms ")) await keptRooms(command, values);
1676
1693
  else if (command === "logs") await logs(values, flags);
1677
1694
  else if (command === "database" || command.startsWith("database ")) await database(command, values, flags);
1678
1695
  else if (command === "saves" || command.startsWith("saves ")) await saves(command, values, flags);