arcadible 1.0.36 → 1.0.38

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 (69) hide show
  1. package/README.md +1 -1
  2. package/dist/action/build/tool.js +57 -8
  3. package/dist/action/function/logs.js +1 -1
  4. package/dist/action/login/flow.js +8 -1
  5. package/dist/action/pack/limits.js +28 -4
  6. package/dist/action/pack/tool.js +2 -1
  7. package/dist/action/secret/tool.js +3 -5
  8. package/dist/action/serve/tool.js +28 -21
  9. package/dist/action/value/tool.js +18 -12
  10. package/dist/action/wire/tool.js +1 -1
  11. package/dist/api.js +1 -1
  12. package/dist/arc.js +6 -2
  13. package/dist/cli/argv.js +3 -1
  14. package/dist/cli/command.js +12 -2
  15. package/dist/command/function/index.js +4 -5
  16. package/dist/command/function/logs.js +8 -1
  17. package/dist/command/function/pause.js +1 -1
  18. package/dist/command/function/resume.js +1 -1
  19. package/dist/command/function/run.js +1 -1
  20. package/dist/command/function/secret/index.js +1 -1
  21. package/dist/command/function/secret/remove.js +2 -2
  22. package/dist/command/function/secret/run.js +1 -1
  23. package/dist/command/function/secret/set.js +1 -1
  24. package/dist/command/{delete.js → game/delete.js} +14 -13
  25. package/dist/command/game/index.js +12 -0
  26. package/dist/command/login.js +1 -2
  27. package/dist/command/serve.js +9 -3
  28. package/dist/command/server/index.js +3 -4
  29. package/dist/command/server/key/create.js +1 -1
  30. package/dist/command/server/key/index.js +1 -1
  31. package/dist/command/server/key/revoke.js +1 -1
  32. package/dist/command/server/key/run.js +1 -1
  33. package/dist/command/unstable/index.js +23 -0
  34. package/dist/command/value/get.js +1 -1
  35. package/dist/command/value/index.js +6 -6
  36. package/dist/command/value/list.js +1 -1
  37. package/dist/command/value/remove.js +2 -2
  38. package/dist/command/value/set.js +1 -1
  39. package/dist/command/value/usage.js +5 -16
  40. package/dist/command/wire/index.js +4 -5
  41. package/dist/commands.js +3 -29
  42. package/dist/config/code.js +7 -3
  43. package/dist/config/limit.js +13 -0
  44. package/dist/phrase/deploy.js +1 -1
  45. package/dist/phrase/function.js +7 -7
  46. package/dist/phrase/game.js +1 -1
  47. package/dist/phrase/index.js +1 -0
  48. package/dist/phrase/pack.js +17 -0
  49. package/dist/phrase/serve.js +8 -3
  50. package/dist/phrase/server.js +5 -5
  51. package/dist/phrase/unstable.js +6 -0
  52. package/dist/phrase/value.js +30 -5
  53. package/dist/runner/bundle.js +13 -4
  54. package/dist/runner/entry.js +113 -17
  55. package/dist/runner/outbound.js +21 -5
  56. package/dist/schema/check/workflow.js +0 -21
  57. package/dist/schema/game.js +0 -32
  58. package/dist/schema/message.js +2 -3
  59. package/dist/schema/runner.js +8 -6
  60. package/dist/schema/workflow.js +6 -28
  61. package/dist/serve/page.js +1 -1
  62. package/dist/serve/remote.js +14 -6
  63. package/dist/serve/runner.js +89 -6
  64. package/dist/serve/server.js +8 -6
  65. package/dist/util/term.js +8 -0
  66. package/dist/util/zip.js +5 -0
  67. package/dist/wires/room.js +3 -3
  68. package/npm-shrinkwrap.json +33 -33
  69. package/package.json +1 -1
package/README.md CHANGED
@@ -50,10 +50,10 @@ Your repository is the store page: `arcadible.toml` holds the game's settings, `
50
50
  | `arc deploy` | Validates, builds, packages, and publishes, directly or through GitHub Actions |
51
51
  | `arc play` | Plays a deployed game from any channel or version |
52
52
  | `arc open` | Opens a game's store page |
53
- | `arc delete` | Deletes the project's game from Arcadible, for good, asking first |
54
53
  | `arc login` | Logs in to Arcadible with a device code |
55
54
  | `arc logout` | Logs out |
56
55
  | `arc whoami` | Shows the account you're logged in to |
56
+ | `arc unstable` | Commands for what isn't released yet, which may change or go in any release |
57
57
 
58
58
  Run `arc <command> --help` for its options, or see the [CLI reference](https://developer.arcadible.com/references/arcadible-cli).
59
59
 
@@ -1,6 +1,7 @@
1
1
  // [import]
2
2
  import cp from "node:child_process";
3
- import { resolve as resolvePath } from "node:path";
3
+ import { readFile } from "node:fs/promises";
4
+ import { join, resolve as resolvePath } from "node:path";
4
5
  // [import]
5
6
  import { pathExists } from "fs-extra";
6
7
  // [import]
@@ -8,6 +9,7 @@ import { BUILT, bundle } from "../../runner/bundle.js";
8
9
  import { BUILD_FAILED } from "../../config/code.js";
9
10
  import { buildCommand } from "../../util/command.js";
10
11
  import { ArcError } from "../../util/error.js";
12
+ import { detect } from "../../util/lockfile.js";
11
13
  import * as phrase from "../../phrase/index.js";
12
14
  // [function]
13
15
  // a build's output has no limit: exec's default maxBuffer, 1 MB, would kill a
@@ -37,7 +39,7 @@ function build(command, { cwdPath, outputPath }) {
37
39
  : Promise.resolve(null);
38
40
  }
39
41
  // [function]
40
- // the game's runner, bundled after the project's own build, which may have
42
+ // the game's function, bundled after the project's own build, which may have
41
43
  // written the code it's made from: resolves with the bundle's path, or null
42
44
  // for a game with none.
43
45
  function buildRunner(root, main) {
@@ -49,13 +51,60 @@ function buildRunner(root, main) {
49
51
  : Promise.resolve(null);
50
52
  }
51
53
  // [function]
54
+ // whether the project's packages were never installed: its package.json names
55
+ // dependencies, and it has neither node_modules nor Yarn's Plug'n'Play file,
56
+ // which stands in for node_modules there.
57
+ export async function uninstalled(root) {
58
+ let conf;
59
+ try {
60
+ conf = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ if (typeof conf !== "object" || conf === null) {
66
+ return false;
67
+ }
68
+ const named = ["dependencies", "devDependencies"].some((key) => {
69
+ const table = conf[key];
70
+ return typeof table === "object" && table !== null
71
+ ? Object.keys(table).length > 0
72
+ : false;
73
+ });
74
+ if (!named) {
75
+ return false;
76
+ }
77
+ const [modules, pnp] = await Promise.all([
78
+ pathExists(join(root, "node_modules")),
79
+ pathExists(join(root, ".pnp.cjs")),
80
+ ]);
81
+ return !modules && !pnp;
82
+ }
83
+ // [function]
84
+ // a failed build, said first to be from packages never installed when they
85
+ // weren't: the build's own error (a bundler's, or a tool not found) says
86
+ // nothing of why.
87
+ async function explain(ex, root) {
88
+ if (!(ex instanceof ArcError) ||
89
+ ex.code !== BUILD_FAILED ||
90
+ !(await uninstalled(root))) {
91
+ return ex;
92
+ }
93
+ return new ArcError(BUILD_FAILED, phrase.packagesUninstalled(ex.message, detect(root) || "npm"), { cause: ex });
94
+ }
95
+ // [function]
52
96
  // builds the project: its own build, then its runner, when it has one. The
53
97
  // result is the build's, with `function`, the bundle's path, beside it.
54
98
  export async function buildTool({ project: { function: runner, workflow }, root, }) {
55
- const artifact = await build(buildCommand(workflow.build), {
56
- cwdPath: root,
57
- outputPath: resolvePath(root, workflow.deploy_dir),
58
- });
59
- const bundled = await buildRunner(root, runner?.main);
60
- return bundled ? { ...artifact, function: bundled } : artifact;
99
+ try {
100
+ const artifact = await build(buildCommand(workflow.build), {
101
+ cwdPath: root,
102
+ outputPath: resolvePath(root, workflow.deploy_dir),
103
+ });
104
+ const bundled = await buildRunner(root, runner?.main);
105
+ return bundled ? { ...artifact, function: bundled } : artifact;
106
+ }
107
+ catch (ex) {
108
+ throw await explain(ex, root);
109
+ }
61
110
  }
@@ -87,7 +87,7 @@ function refused(status, code) {
87
87
  }
88
88
  // [function]
89
89
  // a token for the game's logs: the game is the caller's, or
90
- // game_unavailable, as for the rest of `arc function`.
90
+ // game_unavailable, as for the rest of `arc unstable function`.
91
91
  async function tokenOf(id, headers) {
92
92
  try {
93
93
  return await postGameFunctionLogsToken(id, null, headers);
@@ -29,10 +29,17 @@ function getFlow({ id, secret: token }) {
29
29
  return apiFlow(id, null, auth(token));
30
30
  }
31
31
  // [function]
32
+ // the link page with `code` in its address (`/link/<code>`), which the account
33
+ // site fills in, in capitals, as it's printed. Lowercase, as the API gives
34
+ // it: the site redirects a path with capitals to its lowercase first.
35
+ export function linkTo(code) {
36
+ return `${LINK}/${code.toLowerCase()}`;
37
+ }
38
+ // [function]
32
39
  function createFlow({ expiresAt, secret, type }, onLoginCreated) {
33
40
  return postFlow({ expiresAt, secret, type }).then(({ code, id }) => {
34
41
  if (onLoginCreated) {
35
- onLoginCreated({ code, secret, url: LINK });
42
+ onLoginCreated({ code, link: linkTo(code), url: LINK });
36
43
  }
37
44
  return { id };
38
45
  });
@@ -2,19 +2,43 @@
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  // [import]
5
- import { PACKAGE_FILE_TOO_LARGE, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, } from "../../config/code.js";
5
+ import { PACKAGE_FILE_TOO_LARGE, PACKAGE_PATH_INVALID, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
- import { packageFileTooLarge, packageTooManyFiles, packageUncompressedTooLarge, } from "../../phrase/index.js";
8
- import { FILE_SIZE, FILES, TOTAL_SIZE } from "../../config/limit.js";
7
+ import { packageFileTooLarge, packagePathInvalid, packageTooManyEntries, packageTooManyFiles, packageUncompressedTooLarge, } from "../../phrase/index.js";
8
+ import { ENTRIES, FILE_SIZE, FILES, TOTAL_SIZE } from "../../config/limit.js";
9
9
  import { toMb } from "../../util/size.js";
10
10
  // [declare]
11
11
  export const MAX_FILES = FILES;
12
+ export const MAX_ENTRIES = ENTRIES;
12
13
  export const MAX_FILE_SIZE = FILE_SIZE;
13
14
  export const MAX_TOTAL_SIZE = TOTAL_SIZE;
14
15
  // [function]
16
+ // whether a name is one the router serves as it is: no `.` or `..` part, no
17
+ // backslash, and no escape that decodes to `.`, `/`, or `\\` (`%2e`, `%2f`,
18
+ // `%5c`, in any case), each of which a URL reads as another path. The
19
+ // pipeline refuses the same, with the same code (its `isPlain`, zip.mts).
20
+ export function isPlain(name) {
21
+ return (!name.includes("\\") &&
22
+ !/%(?:2e|2f|5c)/iu.test(name) &&
23
+ !name.split("/").some((part) => part === "." || part === ".."));
24
+ }
25
+ // [function]
26
+ // throws for more entries than the pipeline reads, files and folders
27
+ // together.
28
+ export function checkEntries(count) {
29
+ if (count > MAX_ENTRIES) {
30
+ throw new ArcError(PACKAGE_TOO_MANY_FILES, packageTooManyEntries(MAX_ENTRIES));
31
+ }
32
+ }
33
+ // [function]
15
34
  // checks a zip's files against the limits, and throws for the first one it
16
- // breaks: a file over 64 MB, more than 10,000 files, or over 256 MB in all.
35
+ // breaks: a name that isn't plain, a file over 64 MB, more than 10,000 files,
36
+ // or over 256 MB in all.
17
37
  export function check(entries) {
38
+ const unplain = entries.find((entry) => !isPlain(entry.name));
39
+ if (unplain) {
40
+ throw new ArcError(PACKAGE_PATH_INVALID, packagePathInvalid(unplain.name));
41
+ }
18
42
  const large = entries.find((entry) => entry.size > MAX_FILE_SIZE);
19
43
  if (large) {
20
44
  throw new ArcError(PACKAGE_FILE_TOO_LARGE, packageFileTooLarge(large.name, toMb(MAX_FILE_SIZE)));
@@ -9,7 +9,7 @@ import { ArcError } from "../../util/error.js";
9
9
  import { MEDIA, PACKAGED } from "../../config/file.js";
10
10
  import { deployDirMissing, packageIndexMissing, packagePathReserved, packageTooLarge, runnerNotBuilt, unableToFind, } from "../../phrase/index.js";
11
11
  import { ZIP_SIZE } from "../../config/limit.js";
12
- import { check, measure } from "./limits.js";
12
+ import { check, checkEntries, measure } from "./limits.js";
13
13
  import { favicon } from "../../util/favicon.js";
14
14
  import { handle, tool } from "../../config/product.js";
15
15
  import { toMb } from "../../util/size.js";
@@ -85,6 +85,7 @@ function verifyPartial(zip) {
85
85
  // [function]
86
86
  function verifyTotal(zip) {
87
87
  check(zip.entries());
88
+ checkEntries(zip.count());
88
89
  return zip;
89
90
  }
90
91
  // [function]
@@ -1,21 +1,19 @@
1
- // a runner's secrets: the values a game's runner needs and its repository
1
+ // a runner's secrets: the values a game's function needs and its repository
2
2
  // mustn't hold, such as another service's key. Each is for one game and one
3
3
  // channel, by the name the manifest declares (function.secrets), set by the
4
4
  // game's owner, and never shown again. Nothing here keeps one.
5
5
  import { deleteGameFunctionSecret, gameFunctionSecrets, putGameFunctionSecret, } from "../../api.js";
6
6
  import { ARGUMENT_INVALID, GAME_UNAVAILABLE, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, } from "../../config/code.js";
7
+ import { SECRET_NAME } from "../../config/limit.js";
7
8
  import { ArcError } from "../../util/error.js";
8
9
  import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
9
10
  import { gameNotOwned, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
10
11
  // [declare]
11
- // a secret's name, as an environment variable is named; ARCADIBLE_ is kept
12
- // for Arcadible's own.
13
- const NAME = /^(?!ARCADIBLE_)[A-Z][A-Z0-9_]{0,63}$/u;
14
12
  const VALUE_MAX = 4096;
15
13
  // [function]
16
14
  // a secret's name as it was given, or a refusal before the API is asked.
17
15
  function nameOf(name) {
18
- if (typeof name !== "string" || !NAME.test(name)) {
16
+ if (typeof name !== "string" || !SECRET_NAME.test(name)) {
19
17
  throw new ArcError(ARGUMENT_INVALID, secretNameInvalid());
20
18
  }
21
19
  return name;
@@ -3,7 +3,8 @@
3
3
  // changes.
4
4
  // [import]
5
5
  import { readFile } from "node:fs/promises";
6
- import { dirname, join, relative, resolve as resolvePath } from "node:path";
6
+ import { connect } from "node:net";
7
+ import { join, relative, resolve as resolvePath } from "node:path";
7
8
  import { setTimeout as sleep } from "node:timers/promises";
8
9
  // [import]
9
10
  import { pathExists } from "fs-extra";
@@ -22,7 +23,7 @@ import { configDir } from "../../util/os.js";
22
23
  import { title } from "../../config/product.js";
23
24
  import { watchDir } from "../../serve/reload.js";
24
25
  import { remoteFiles } from "../../serve/remote.js";
25
- import { serve } from "../../serve/server.js";
26
+ import { LOOPBACK, serve, } from "../../serve/server.js";
26
27
  import { playerOf } from "../../serve/ticket.js";
27
28
  import { buildTool } from "../build/tool.js";
28
29
  import { ARCADIBLE_SDK, HOST_HTTP_PLAY } from "../../config/uri.js";
@@ -91,8 +92,31 @@ function storeArt(root) {
91
92
  };
92
93
  }
93
94
  // [function]
94
- // listens, turning a port in use into its code.
95
+ // whether something answers on `port` at `address` already. Listening alone
96
+ // doesn't say: on macOS, a program that holds the port on every IPv6 address
97
+ // (`*:<port>`) still lets 127.0.0.1 and ::1 be listened on, so the page would
98
+ // start beside it, answering some requests and not others.
99
+ function answers(port, address) {
100
+ return new Promise((resolve) => {
101
+ const socket = connect({ host: address, port });
102
+ const done = function (found) {
103
+ socket.destroy();
104
+ resolve(found);
105
+ };
106
+ socket.setTimeout(1000, () => done(false));
107
+ socket.once("connect", () => done(true));
108
+ socket.once("error", () => done(false));
109
+ });
110
+ }
111
+ // [function]
112
+ // listens, turning a port in use into its code: one another program answers
113
+ // on, on either loopback, or one listening fails on.
95
114
  async function listen(options) {
115
+ const found = options.port !== 0 &&
116
+ (await Promise.all(LOOPBACK.map((address) => answers(options.port, address)))).some(Boolean);
117
+ if (found) {
118
+ throw new ArcError(PORT_IN_USE, phrase.portInUse(options.port));
119
+ }
96
120
  try {
97
121
  return await serve(options);
98
122
  }
@@ -149,7 +173,7 @@ export async function serveTool(conf) {
149
173
  // servers of its own, or run for a player
150
174
  const servers = strings(project.client?.server_origins);
151
175
  const forServer = servers.length > 0 || Boolean(player);
152
- // the game's runner, when the project has one: its code, where its runtime
176
+ // the game's function, when the project has one: its code, where its runtime
153
177
  // is kept, and who hears how it's doing
154
178
  const runs = project.function;
155
179
  const main = runs?.main;
@@ -208,28 +232,13 @@ export async function serveTool(conf) {
208
232
  ...(conf.host ? { hostFile: resolvePath(root, conf.host) } : {}),
209
233
  wiresDrop: conf.wiresDrop ?? null,
210
234
  };
211
- // the runner's code, watched: a change runs the new code
212
- const watchRunner = function (served) {
213
- const running = served.runner;
214
- if (!running || !runnerMain) {
215
- return () => null;
216
- }
217
- return watchDir(dirname(runnerMain), () => {
218
- void running.restart();
219
- });
220
- };
221
235
  const version = game.version ?? null;
222
236
  if (url) {
223
237
  const served = await listen({ ...options, src: url });
224
238
  const probed = await probe(url);
225
- const unwatch = watchRunner(served);
226
239
  return {
227
240
  ...served,
228
241
  built: false,
229
- close() {
230
- unwatch();
231
- served.close();
232
- },
233
242
  deployDir: null,
234
243
  forServer,
235
244
  probed,
@@ -270,13 +279,11 @@ export async function serveTool(conf) {
270
279
  served.reload();
271
280
  handler.onReload();
272
281
  });
273
- const unwatch = watchRunner(served);
274
282
  return {
275
283
  ...served,
276
284
  built,
277
285
  close() {
278
286
  stop();
279
- unwatch();
280
287
  served.close();
281
288
  },
282
289
  deployDir,
@@ -9,7 +9,7 @@ import { gameValuesList, gameValuesRead, gameValuesRemove, gameValuesWrite, game
9
9
  import { ARGUMENT_INVALID, GAME_UNAVAILABLE, VALUE_NOT_FOUND, VALUE_STORAGE_FULL, VALUE_TOO_LARGE, } from "../../config/code.js";
10
10
  import { ArcError } from "../../util/error.js";
11
11
  import { gameOf, headersOf, isStatus, needOf } from "../game.js";
12
- import { gameNotOwned, valueDirEmpty, valueFileUnread, valueFull, valueKeyInvalid, valueNotFound, valueNotJson, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
12
+ import { gameNotOwned, valueDirEmpty, valueFileUnread, valueFull, valueHolds, valueKeyInvalid, valueNotFound, valueNotJson, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
13
13
  // [declare]
14
14
  // a key, as Arcadible takes one (db/function/game_value.sql, value_keys).
15
15
  export const KEY = /^[A-Za-z0-9_./-]{1,128}$/u;
@@ -96,19 +96,25 @@ function batches(items) {
96
96
  return all;
97
97
  }
98
98
  // [function]
99
+ // what the developer's values on `channel` may hold, as the API states it
100
+ // for the account's plan, or null when it can't be had.
101
+ async function holds(id, channel, headers) {
102
+ const scopes = await gameValueUsages(id, channel, headers).catch(() => null);
103
+ const mine = scopes?.find((each) => each.scope === "developer" && each.channel === channel);
104
+ return mine ? valueHolds(mine) : null;
105
+ }
106
+ // [function]
99
107
  // the API's refusals, said for a developer's values: a game that isn't the
100
- // caller's, and a scope that's full.
101
- function refused(id, channel) {
102
- return (err) => {
108
+ // caller's, and a scope that's full, with what it may hold.
109
+ function refused(id, channel, headers) {
110
+ return async (err) => {
103
111
  if (isStatus(err, 404)) {
104
112
  throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
105
113
  cause: err,
106
114
  });
107
115
  }
108
116
  if (isStatus(err, 507)) {
109
- throw new ArcError(VALUE_STORAGE_FULL, valueFull(channel), {
110
- cause: err,
111
- });
117
+ throw new ArcError(VALUE_STORAGE_FULL, valueFull(channel, await holds(id, channel, headers)), { cause: err });
112
118
  }
113
119
  throw err;
114
120
  };
@@ -145,7 +151,7 @@ export async function set(current, { channel, dir, file, input, key, ...conf })
145
151
  cause: err,
146
152
  });
147
153
  }
148
- return refused(id, where)(err);
154
+ return refused(id, where, headers)(err);
149
155
  });
150
156
  }
151
157
  return { channel: where, keys: items.map((item) => item.key) };
@@ -158,7 +164,7 @@ export async function get(current, { channel, key, ...conf }) {
158
164
  const where = needOf(channel);
159
165
  const id = await gameOf(conf);
160
166
  const headers = headersOf(current);
161
- const [value] = await gameValuesRead(id, where, [named], headers).catch(refused(id, where));
167
+ const [value] = await gameValuesRead(id, where, [named], headers).catch(refused(id, where, headers));
162
168
  if (!value) {
163
169
  throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
164
170
  }
@@ -177,7 +183,7 @@ export async function list(current, { channel, prefix = "", ...conf }) {
177
183
  const all = [];
178
184
  let after = "";
179
185
  for (;;) {
180
- const page = await gameValuesList(id, where, { after, limit: PAGE, prefix }, headers).catch(refused(id, where));
186
+ const page = await gameValuesList(id, where, { after, limit: PAGE, prefix }, headers).catch(refused(id, where, headers));
181
187
  all.push(...page.entries);
182
188
  if (page.next === null) {
183
189
  return all;
@@ -193,7 +199,7 @@ export async function remove(current, { channel, key, ...conf }) {
193
199
  const where = needOf(channel);
194
200
  const id = await gameOf(conf);
195
201
  const headers = headersOf(current);
196
- const { removed } = await gameValuesRemove(id, where, [named], headers).catch(refused(id, where));
202
+ const { removed } = await gameValuesRemove(id, where, [named], headers).catch(refused(id, where, headers));
197
203
  if (removed === 0) {
198
204
  throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
199
205
  }
@@ -209,7 +215,7 @@ export async function usage(current, { channel, ...conf }) {
209
215
  const where = needOf(channel);
210
216
  const id = await gameOf(conf);
211
217
  const headers = headersOf(current);
212
- const scopes = (await gameValueUsages(id, where, headers).catch(refused(id, where))) ?? [];
218
+ const scopes = (await gameValueUsages(id, where, headers).catch(refused(id, where, headers))) ?? [];
213
219
  const calls = await gameValueCalls(id, headers).catch(() => null);
214
220
  return {
215
221
  calls: calls?.find((each) => each.channel === where) ?? null,
@@ -1,4 +1,4 @@
1
- // arc wire: a game's wires (plan/SDKWIRES.md), live messages between its
1
+ // arc unstable wire: a game's wires (plan/SDKWIRES.md), live messages between its
2
2
  // players. What its owner sees of them is their usage: wires keep nothing,
3
3
  // and nothing about one is set from here.
4
4
  import { gameWireUsages } from "../../api.js";
package/dist/api.js CHANGED
@@ -253,7 +253,7 @@ export function deleteKey(key, params, headers) {
253
253
  return answer(isKeyRevoked, "a key", del(endpoint(pathOf `/keys/${key}`, params), headers));
254
254
  }
255
255
  // [function]
256
- // the secrets of the caller's own game's runner, by channel and name: never
256
+ // the secrets of the caller's own game's function, by channel and name: never
257
257
  // their values.
258
258
  export function gameFunctionSecrets(id, params, headers) {
259
259
  return answer(listed(isSecret), "a function's secrets", get(endpoint(pathOf `/games/${id}/function_secrets`, params), headers));
package/dist/arc.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // the entry: runs the command the first argument names, or with none, or
2
2
  // one that isn't a command, prints the help, the version, or what's wrong.
3
3
  // [import]
4
- import { normalize } from "./cli/argv.js";
4
+ import { fail, normalize } from "./cli/argv.js";
5
5
  import { execute } from "./cli/command.js";
6
6
  import { COMMANDS } from "./commands.js";
7
7
  import { version } from "./config/package.js";
@@ -12,14 +12,18 @@ const TOOL = tool;
12
12
  const VERSION = version;
13
13
  // [function]
14
14
  // `arc` with no command: the help, which lists every command that isn't
15
- // hidden, the version, or an argument that isn't a command, refused.
15
+ // hidden, the version, or an argument that isn't a command, refused as an
16
+ // unknown option on a command is (argument_invalid), as JSON with --json,
17
+ // which is known here, so it's never the refused argument.
16
18
  async function help(args) {
17
19
  const cli = COMMANDS.filter((each) => !each.hidden)
18
20
  .reduce((each, { name, summary }) => each.command(name, summary), yargs(normalize(args)).scriptName(TOOL).usage("$0 <command> [options]"))
21
+ .option("json", { alias: "j", hidden: true, type: "boolean" })
19
22
  .help("help")
20
23
  .alias("help", "h")
21
24
  .version(VERSION)
22
25
  .alias("version", "v")
26
+ .fail(fail(args))
23
27
  .strict();
24
28
  const argv = await cli.parse();
25
29
  if (!argv._.length) {
package/dist/cli/argv.js CHANGED
@@ -49,10 +49,12 @@ export function fail(args) {
49
49
  throw ex;
50
50
  }
51
51
  if (asJson) {
52
- // it exits, once stdout has written the document: not waited for.
52
+ // it exits, once stdout has written the document: not waited for, and
53
+ // nothing else is written meanwhile, so stderr stays empty.
53
54
  void abort("", new ArcError(ARGUMENT_INVALID, String(message)), {
54
55
  json: asJson,
55
56
  });
57
+ return;
56
58
  }
57
59
  cli.showHelp("error");
58
60
  console.error(`\n${message}`);
@@ -127,6 +127,17 @@ function parser(command, args, conf, matched) {
127
127
  return (takesJson(command) ? built.fail(fail(args)) : built).strict();
128
128
  }
129
129
  // [function]
130
+ // the section of `.arcrc` a command's options are read from: the top-level
131
+ // command's, for a family's commands too, or in a namespace, the name of
132
+ // the command under it that the arguments give.
133
+ function section(command, args) {
134
+ if (!isFamily(command) || !command.namespace) {
135
+ return command.name;
136
+ }
137
+ const names = new Set(command.commands.map((each) => each.name));
138
+ return args.find((arg) => names.has(arg)) ?? command.name;
139
+ }
140
+ // [function]
130
141
  // runs the command's flow, and ends as it says: with its exit code, or by
131
142
  // the one error path.
132
143
  async function run({ command, heading, parsed }) {
@@ -148,8 +159,7 @@ async function run({ command, heading, parsed }) {
148
159
  // runs a top-level command with `args`, the arguments after its name.
149
160
  // `--help`, `--version`, and an argument error end inside the parser.
150
161
  export async function execute(command, args) {
151
- // the section is the top-level command's, for a family's commands too.
152
- const conf = await findRc(TOOL, command.name, args);
162
+ const conf = await findRc(TOOL, section(command, args), args);
153
163
  const matches = [];
154
164
  const parsed = await parser(command, args, conf, (match) => {
155
165
  matches.push(match);
@@ -1,7 +1,7 @@
1
- // arc function: a game's function, the server code Arcadible runs for it:
2
- // paused and resumed on a channel by the game's owner, with no release, its
3
- // logs, and its secrets (./secret/index.ts). All of it is left out of `arc --help`
4
- // until functions ship, with the docs.
1
+ // arc unstable function: a game's function, the server code Arcadible runs
2
+ // for it: paused and resumed on a channel by the game's owner, with no
3
+ // release, its logs, and its secrets (./secret/index.ts). Under
4
+ // `arc unstable` until functions ship, with the docs.
5
5
  // [import]
6
6
  import { defineCommand } from "../../cli/command.js";
7
7
  import secret from "./secret/index.js";
@@ -12,7 +12,6 @@ import logs from "./logs.js";
12
12
  // [export]
13
13
  export default defineCommand({
14
14
  commands: [pause, resume, status, logs, secret],
15
- hidden: true,
16
15
  name: "function",
17
16
  summary: "Pause, resume, and show the game's function, its logs, and its secrets",
18
17
  });
@@ -1,4 +1,4 @@
1
- // arc function logs: what the game's function said, as Arcadible keeps it,
1
+ // arc unstable function logs: what the game's function said, as Arcadible keeps it,
2
2
  // for its owner (plan/FUNCTION-LOGS.md, Reading them): the newest 100
3
3
  // requests, oldest first, as `tail` prints, or those and then each as it
4
4
  // comes, with `--follow`. With `--json`, an entry a line, as the logs
@@ -17,6 +17,7 @@ import { cpuTime, functionLogsNone } from "../../phrase/index.js";
17
17
  import { p } from "../../util/log.js";
18
18
  import { deepSort } from "../../util/objs.js";
19
19
  import { SpinnerWheel } from "../../util/spinner.js";
20
+ import { interrupted } from "../../util/term.js";
20
21
  import { follow, logs, } from "../../action/function/logs.js";
21
22
  import { whoami } from "../../action/whoami/tool.js";
22
23
  // [function]
@@ -136,6 +137,12 @@ export default defineCommand({
136
137
  version: argv.release,
137
138
  };
138
139
  if (argv.follow) {
140
+ // it runs until stopped: a Ctrl+C ends it as a signal does (130), on
141
+ // a line of its own.
142
+ process.once("SIGINT", () => {
143
+ interrupted();
144
+ process.exit(130);
145
+ });
139
146
  await follow(current, conf, (entry) => {
140
147
  show(entry, json);
141
148
  }).catch(ended(current));
@@ -12,7 +12,7 @@ export default defineCommand({
12
12
  run(argv, aborting) {
13
13
  return run(argv, aborting, pause, (paused) => {
14
14
  p(functionPaused(paused));
15
- }, "arc function pause");
15
+ }, "arc unstable function pause");
16
16
  },
17
17
  summary: "Pause the game's function on a channel",
18
18
  });
@@ -12,7 +12,7 @@ export default defineCommand({
12
12
  run(argv, aborting) {
13
13
  return run(argv, aborting, resume, (resumed) => {
14
14
  p(functionResumed(resumed));
15
- }, "arc function resume");
15
+ }, "arc unstable function resume");
16
16
  },
17
17
  summary: "Resume the game's function on a channel",
18
18
  });
@@ -1,4 +1,4 @@
1
- // what `arc function`'s own commands share: running one as the logged-in
1
+ // what `arc unstable function`'s own commands share: running one as the logged-in
2
2
  // account.
3
3
  // [import]
4
4
  import { resolve as resolvePath } from "node:path";
@@ -1,4 +1,4 @@
1
- // arc function secret: a function's secrets, the values a game's function
1
+ // arc unstable function secret: a function's secrets, the values a game's function
2
2
  // needs and its repository mustn't hold. `set` takes the value from standard
3
3
  // input, or asks for it at a terminal, so it's never an argument, in a
4
4
  // shell's history or a process list.
@@ -14,12 +14,12 @@ export default defineCommand({
14
14
  run(argv, aborting) {
15
15
  return run(argv, aborting, (current, conf) => remove(current, { ...conf, name: argv.name }), (gone) => {
16
16
  p(secretRemoved(gone));
17
- }, `arc function secret remove ${argv.name}`, (where) => ({
17
+ }, `arc unstable function secret remove ${argv.name}`, (where) => ({
18
18
  question: secretRemoveQuestion({
19
19
  channel: String(where),
20
20
  name: argv.name,
21
21
  }),
22
- usage: `arc function secret remove ${argv.name} --${where}`,
22
+ usage: `arc unstable function secret remove ${argv.name} --${where}`,
23
23
  }));
24
24
  },
25
25
  summary: "Remove a secret",
@@ -1,4 +1,4 @@
1
- // what `arc function secret`'s commands share: running one as the logged-in
1
+ // what `arc unstable function secret`'s commands share: running one as the logged-in
2
2
  // account.
3
3
  // [import]
4
4
  import { resolve as resolvePath } from "node:path";
@@ -42,7 +42,7 @@ export default defineCommand({
42
42
  value: () => valueOf(argv.name, argv.json),
43
43
  }), (kept) => {
44
44
  p(secretSet(kept));
45
- }, `arc function secret set ${argv.name}`);
45
+ }, `arc unstable function secret set ${argv.name}`);
46
46
  },
47
47
  summary: "Set a secret, its value from standard input",
48
48
  });