arcadible 1.0.49 → 1.0.51

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 +5 -1
  2. package/dist/action/deploy/result.js +3 -3
  3. package/dist/action/deploy/tool-git.js +1 -1
  4. package/dist/action/deploy/tool.js +1 -1
  5. package/dist/action/deploy/wait.js +1 -1
  6. package/dist/action/function/logs.js +4 -4
  7. package/dist/action/function/tool.js +42 -27
  8. package/dist/action/key/tool.js +10 -4
  9. package/dist/action/secret/tool.js +2 -1
  10. package/dist/action/validate/unknown.js +1 -1
  11. package/dist/action/value/local.js +78 -0
  12. package/dist/action/value/tool.js +81 -35
  13. package/dist/action/wire/tool.js +1 -1
  14. package/dist/api.js +1 -0
  15. package/dist/cli/command.js +13 -1
  16. package/dist/cli/options.js +7 -0
  17. package/dist/cli/prompt.js +1 -1
  18. package/dist/command/deploy/report.js +5 -5
  19. package/dist/command/function/index.js +4 -4
  20. package/dist/command/function/logs.js +4 -4
  21. package/dist/command/function/pause.js +1 -1
  22. package/dist/command/function/resume.js +1 -1
  23. package/dist/command/function/run.js +1 -1
  24. package/dist/command/function/secret/index.js +1 -1
  25. package/dist/command/function/secret/list.js +2 -1
  26. package/dist/command/function/secret/remove.js +2 -2
  27. package/dist/command/function/secret/run.js +1 -1
  28. package/dist/command/function/secret/set.js +1 -1
  29. package/dist/command/function/status.js +7 -36
  30. package/dist/command/function/usage.js +64 -0
  31. package/dist/command/game/delete.js +2 -2
  32. package/dist/command/game/index.js +2 -2
  33. package/dist/command/open.js +1 -1
  34. package/dist/command/play.js +1 -1
  35. package/dist/command/server/index.js +3 -3
  36. package/dist/command/server/key/create.js +4 -4
  37. package/dist/command/server/key/index.js +1 -1
  38. package/dist/command/server/key/list.js +3 -2
  39. package/dist/command/server/key/revoke.js +1 -1
  40. package/dist/command/server/key/run.js +1 -1
  41. package/dist/command/unstable/index.js +8 -13
  42. package/dist/command/value/get.js +12 -8
  43. package/dist/command/value/index.js +4 -4
  44. package/dist/command/value/list.js +14 -6
  45. package/dist/command/value/remove.js +22 -11
  46. package/dist/command/value/run.js +40 -0
  47. package/dist/command/value/set.js +27 -22
  48. package/dist/command/value/usage.js +47 -39
  49. package/dist/command/wire/index.js +1 -2
  50. package/dist/commands.js +28 -0
  51. package/dist/config/code.js +4 -2
  52. package/dist/config/limit.js +5 -5
  53. package/dist/config/retry.js +2 -0
  54. package/dist/parser/project.js +2 -1
  55. package/dist/phrase/common.js +12 -6
  56. package/dist/phrase/deploy.js +4 -3
  57. package/dist/phrase/function.js +27 -21
  58. package/dist/phrase/game.js +3 -3
  59. package/dist/phrase/pack.js +4 -1
  60. package/dist/phrase/serve.js +2 -2
  61. package/dist/phrase/server.js +10 -5
  62. package/dist/phrase/value.js +50 -16
  63. package/dist/schema/client.js +11 -6
  64. package/dist/serve/values.js +2 -2
  65. package/dist/util/output.js +11 -4
  66. package/dist/util/schema.js +5 -3
  67. package/dist/util/time.js +5 -0
  68. package/npm-shrinkwrap.json +2 -2
  69. package/package.json +2 -1
package/README.md CHANGED
@@ -53,7 +53,11 @@ Your repository is the store page: `arcadible.toml` holds the game's settings, `
53
53
  | `arc login` | Logs in to Arcadible with a device code |
54
54
  | `arc logout` | Logs out |
55
55
  | `arc whoami` | Shows the account you're logged in to |
56
- | `arc unstable` | Commands that aren't settled yet, which may change or go in any release |
56
+ | `arc game` | Deletes the project's game on Arcadible |
57
+ | `arc function` | Pauses, resumes, and shows your game's function, its logs, and its secrets |
58
+ | `arc server` | Makes, lists, and revokes your server's keys |
59
+ | `arc value` | Sets, gets, lists, and removes the values you publish for your game |
60
+ | `arc wire` | Shows what your game's wires carried |
57
61
 
58
62
  Run `arc <command> --help` for its options, or see the [CLI reference](https://developer.arcadible.com/references/arcadible-cli).
59
63
 
@@ -6,14 +6,14 @@ import { published } from "../../util/links.js";
6
6
  // release, so the game's links are by id.
7
7
  export function resultOf(deployed, { built, git, held, warnings, }) {
8
8
  const { channel, store, url } = held
9
- ? published({ id: deployed.game, version: deployed.version.to })
9
+ ? published({ id: deployed.game, version: deployed.version })
10
10
  : deployed;
11
11
  return {
12
12
  ...(git ? {} : { built }),
13
13
  channel,
14
- store,
14
+ play_url: url,
15
+ store_url: store,
15
16
  ...("tag" in deployed ? { tag: deployed.tag } : {}),
16
- url,
17
17
  version: deployed.version,
18
18
  warnings,
19
19
  };
@@ -44,6 +44,6 @@ export function deployToolGit(conf, { onDeployBegin }) {
44
44
  ...published(game),
45
45
  game: game.id,
46
46
  tag: tagOf(game.version),
47
- version: { to: game.version },
47
+ version: game.version,
48
48
  }));
49
49
  }
@@ -47,6 +47,6 @@ export function deployTool(current, artifact, conf, { onDeployBegin, onUploadPro
47
47
  // a direct deploy's release shares its upload's id, which `--wait`
48
48
  // follows.
49
49
  release: upload.id,
50
- version: { to: game.version },
50
+ version: game.version,
51
51
  }));
52
52
  }
@@ -101,7 +101,7 @@ function pollRelease(find, timeout, onRelease) {
101
101
  export function wait(current, deployed, { git: isGit, root, since, timeout }, { onRelease } = {}) {
102
102
  const game = deployed.game;
103
103
  const find = isGit || !("release" in deployed)
104
- ? findGit({ game, since, version: deployed.version.to })
104
+ ? findGit({ game, since, version: deployed.version })
105
105
  : findDirect(deployed.release, current);
106
106
  return Promise.all([
107
107
  pollRelease(find, timeout, onRelease),
@@ -54,7 +54,7 @@ export function sinceOf(text, now = Date.now()) {
54
54
  }
55
55
  // [function]
56
56
  // the query a page or a follow asks with.
57
- function queryOf({ errors, since, version }, channel) {
57
+ function queryOf({ failed, since, version }, channel) {
58
58
  const query = new URLSearchParams();
59
59
  if (channel)
60
60
  query.set("channel", channel);
@@ -66,7 +66,7 @@ function queryOf({ errors, since, version }, channel) {
66
66
  }
67
67
  if (since)
68
68
  query.set("since", sinceOf(since));
69
- if (errors)
69
+ if (failed)
70
70
  query.set("outcome", "error");
71
71
  return query;
72
72
  }
@@ -81,7 +81,7 @@ function isPage(value) {
81
81
  function isEntry(value) {
82
82
  return (isTable(value) &&
83
83
  typeof value["id"] === "number" &&
84
- typeof value["at"] === "number");
84
+ typeof value["at"] === "string");
85
85
  }
86
86
  // [function]
87
87
  // the Worker's refusal as the CLI's failure, read as the API's is (codeOf):
@@ -132,7 +132,7 @@ function toldInText(text) {
132
132
  }
133
133
  // [function]
134
134
  // a token for the game's logs: the game is the caller's, or
135
- // game_not_found, as for the rest of `arc unstable function`.
135
+ // game_not_found, as for the rest of `arc function`.
136
136
  async function tokenOf(id, headers) {
137
137
  try {
138
138
  return await postGameFunctionLogsToken(id, null, headers);
@@ -6,6 +6,7 @@ import { deleteGameFunctionPause, discoverGameBuilds, gameFunctionPauses, gameFu
6
6
  import { FUNCTION_PAUSE_NOT_OWNED, GAME_NOT_FOUND } from "../../config/code.js";
7
7
  import { ArcError } from "../../util/error.js";
8
8
  import { channelOf, CHANNELS, gameOf, headersOf, isRefused, REFUSED, needOf, ownedRead, } from "../game.js";
9
+ import { iso } from "../../util/time.js";
9
10
  import { functionPauseNotOwned, gameNotOwned } from "../../phrase/index.js";
10
11
  // [declare]
11
12
  // the reasons a function is paused for, the one that holds longest first:
@@ -23,7 +24,7 @@ function pausedOf(pauses, channel) {
23
24
  // [function]
24
25
  // when a channel's pause for a limit ends by itself, or null for none.
25
26
  function resumesOf(pauses, channel) {
26
- return ((pauses ?? []).find((pause) => pause.channel === channel && pause.reason === "limit")?.resumes_at ?? null);
27
+ return iso((pauses ?? []).find((pause) => pause.channel === channel && pause.reason === "limit")?.resumes_at);
27
28
  }
28
29
  // [function]
29
30
  // whether a channel's live build has a function: true, false, or null when
@@ -97,56 +98,70 @@ export async function resume(current, { channel, ...conf }) {
97
98
  return { channel: where, lifted, paused };
98
99
  }
99
100
  // [function]
100
- // the game's function on each channel, or on one: `{ channel, function,
101
- // paused, requests }`, `function` whether the channel's live build has one
102
- // (a pause and a usage are the channel's, so neither says), `paused` the
103
- // reason it's paused for, or null for none, `requests` what it answered
104
- // this month, and `cpu_ms` its CPU time. With them, what holds it, whichever channels were asked for:
105
- // the game's day against its own limit, its month, and its account's pool
106
- // against its plan's, each as the API states it.
101
+ // the game's function on each channel, or on one: whether it has one,
102
+ // and whether it's paused, why, and until when (Status).
107
103
  export async function status(current, { channel, ...conf }) {
108
104
  const where = channelOf(channel);
109
105
  const id = await gameOf(conf);
110
106
  const headers = headersOf(current);
111
- const [pauses, usages] = await Promise.all([
112
- ownedRead(id, gameFunctionPauses(id, null, headers)),
113
- ownedRead(id, gameFunctionUsages(id, null, headers)),
114
- ]);
107
+ const pauses = await ownedRead(id, gameFunctionPauses(id, null, headers));
115
108
  const shown = CHANNELS.filter((each) => !where || each === where);
116
109
  // asked once the game is known to be the caller's, so another account's
117
110
  // game is refused before anything else is asked about it.
118
111
  const has = await Promise.all(shown.map((each) => hasFunction(id, each)));
119
- const rows = usages ?? [];
112
+ return {
113
+ channels: shown.map((each, i) => ({
114
+ channel: each,
115
+ function: has[i] ?? null,
116
+ paused: pausedOf(pauses, each),
117
+ resumes_at: resumesOf(pauses, each),
118
+ })),
119
+ };
120
+ }
121
+ // [function]
122
+ // what the game's function answered, on each channel or on one, today and
123
+ // this month, and what holds it, each as the API states it (Usage). A day
124
+ // is UTC's, as the API keeps it.
125
+ export async function usage(current, { channel, ...conf }) {
126
+ const where = channelOf(channel);
127
+ const id = await gameOf(conf);
128
+ const headers = headersOf(current);
129
+ const rows = (await ownedRead(id, gameFunctionUsages(id, null, headers))) ?? [];
120
130
  const [first] = rows;
121
- const sum = (of, field) => of.reduce((total, each) => total + Number(each[field] ?? 0), 0);
131
+ const today = new Date().toISOString().slice(0, 10);
132
+ const counts = (of) => ({
133
+ cpu_ms: of.reduce((total, each) => total + Number(each.cpu_ms ?? 0), 0),
134
+ requests: of.reduce((total, each) => total + Number(each.requests), 0),
135
+ });
122
136
  // null is no limit, and stays null
123
137
  const limit = (value) => value === null ? null : Number(value);
124
138
  return {
125
- channels: shown.map((each, i) => {
139
+ account: first
140
+ ? {
141
+ allowance: limit(first.pool_allowance),
142
+ cpu_ms: Number(first.pool_cpu_ms ?? 0),
143
+ requests: Number(first.pool_used),
144
+ }
145
+ : null,
146
+ channels: CHANNELS.filter((each) => !where || each === where).map((each) => {
126
147
  const own = rows.filter((row) => row.channel === each);
127
148
  return {
128
149
  channel: each,
129
- cpu_ms: sum(own, "cpu_ms"),
130
- function: has[i] ?? null,
131
- paused: pausedOf(pauses, each),
132
- requests: sum(own, "requests"),
133
- resumes_at: resumesOf(pauses, each),
150
+ month: counts(own),
151
+ today: counts(own.filter((row) => row.day === today)),
134
152
  };
135
153
  }),
136
- day: first
137
- ? { allowance: limit(first.allowance), requests: Number(first.used) }
138
- : null,
139
154
  month: first
140
155
  ? {
141
156
  cpu_ms: Number(first.month_cpu_ms ?? 0),
142
157
  requests: Number(first.month_used),
143
158
  }
144
159
  : null,
145
- pool: first
160
+ today: first
146
161
  ? {
147
- allowance: limit(first.pool_allowance),
148
- cpu_ms: Number(first.pool_cpu_ms ?? 0),
149
- requests: Number(first.pool_used),
162
+ allowance: limit(first.allowance),
163
+ cpu_ms: counts(rows.filter((row) => row.day === today)).cpu_ms,
164
+ requests: Number(first.used),
150
165
  }
151
166
  : null,
152
167
  };
@@ -2,10 +2,11 @@
2
2
  // is for one game and one channel, made by the game's owner, shown once, and
3
3
  // revoked at once. Nothing here keeps one.
4
4
  import { deleteKey, gameKeys, postGameKey, } from "../../api.js";
5
- import { ARGUMENT_INVALID, GAME_NOT_FOUND, KEY_QUOTA_FULL, KEY_NOT_FOUND, } from "../../config/code.js";
5
+ import { ARGUMENT_INVALID, GAME_NOT_FOUND, KEY_CREATE_RATE_LIMITED, KEY_QUOTA_FULL, KEY_NOT_FOUND, } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
7
  import { channelOf, gameOf, headersOf, isRefused, REFUSED, needOf, ownedRead, } from "../game.js";
8
- import { gameNotOwned, keyQuotaFull, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
8
+ import { iso } from "../../util/time.js";
9
+ import { gameNotOwned, keyCreateRateLimited, keyQuotaFull, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
9
10
  // [declare]
10
11
  const NAME_MAX = 64;
11
12
  // the name a key gets when none is given.
@@ -45,6 +46,11 @@ export async function create(current, { channel, name, ...conf }) {
45
46
  cause: err,
46
47
  });
47
48
  }
49
+ if (isRefused(err, KEY_CREATE_RATE_LIMITED)) {
50
+ throw new ArcError(KEY_CREATE_RATE_LIMITED, keyCreateRateLimited(), {
51
+ cause: err,
52
+ });
53
+ }
48
54
  throw err;
49
55
  }
50
56
  }
@@ -60,11 +66,11 @@ export async function list(current, { channel, ...conf }) {
60
66
  .filter((key) => !where || key.channel === where)
61
67
  .map((key) => ({
62
68
  channel: key.channel,
63
- created_at: key.created_at,
69
+ created_at: iso(key.created_at),
64
70
  id: key.id,
65
71
  name: key.name,
66
72
  shown: key.shown,
67
- used_at: key.used_at,
73
+ used_at: iso(key.used_at),
68
74
  }));
69
75
  }
70
76
  // [function]
@@ -7,6 +7,7 @@ import { ARGUMENT_INVALID, GAME_NOT_FOUND, SECRET_QUOTA_FULL, SECRET_NOT_FOUND,
7
7
  import { SECRET_NAME } from "../../config/limit.js";
8
8
  import { ArcError } from "../../util/error.js";
9
9
  import { channelOf, gameOf, headersOf, isRefused, REFUSED, needOf, ownedRead, } from "../game.js";
10
+ import { iso } from "../../util/time.js";
10
11
  import { gameNotOwned, secretQuotaFull, secretNameInvalid, secretNotFound, secretTooLarge, secretValueInvalid, } from "../../phrase/index.js";
11
12
  // [declare]
12
13
  const VALUE_MAX = 4096;
@@ -66,7 +67,7 @@ export async function list(current, { channel, ...conf }) {
66
67
  .map((secret) => ({
67
68
  channel: secret.channel,
68
69
  name: secret.name,
69
- updated_at: secret.updated_at,
70
+ updated_at: iso(secret.updated_at),
70
71
  }));
71
72
  }
72
73
  // [function]
@@ -25,7 +25,7 @@ function warning(path, message, near) {
25
25
  return {
26
26
  code: WARNING.FIELD_UNKNOWN,
27
27
  details: near ? [didYouMean(near)] : [],
28
- link: null,
28
+ docs_url: null,
29
29
  message,
30
30
  path,
31
31
  };
@@ -0,0 +1,78 @@
1
+ // the developer's values in the project's own folder, `.arcadible-data/values/`,
2
+ // a file a value, its path its key: the local channel `arc serve` reads,
3
+ // which `arc value` works on when it's given no channel (cli:13a). Nothing
4
+ // is asked of Arcadible, and no login is needed. `set` makes the folders
5
+ // it needs, as the command that first needs a folder makes it (DEVELOPING.md).
6
+ // [import]
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { VALUE_NOT_FOUND } from "../../config/code.js";
10
+ import { ArcError } from "../../util/error.js";
11
+ import { DEVELOPER_DIR, developerRows } from "../../serve/values.js";
12
+ import { valueNotFound } from "../../phrase/index.js";
13
+ import { keyOf } from "./tool.js";
14
+ // [declare]
15
+ // the channel the local values are, as `arc serve` names it.
16
+ export const LOCAL = "local";
17
+ // [function]
18
+ // the project's values folder.
19
+ function dirOf(root) {
20
+ return path.join(root, DEVELOPER_DIR);
21
+ }
22
+ // [function]
23
+ // a key's file in the folder: daily/2026-11-12 is daily/2026-11-12.json.
24
+ function fileOf(root, key) {
25
+ return path.join(dirOf(root), ...key.split("/")) + ".json";
26
+ }
27
+ // [function]
28
+ // a value, as `arc serve` reads it, or not found.
29
+ function rowOf(root, key) {
30
+ const row = developerRows(dirOf(root)).get(key);
31
+ if (!row) {
32
+ throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: LOCAL, key }));
33
+ }
34
+ return {
35
+ key: row.key,
36
+ revision: row.revision,
37
+ updated_at: row.updated_at,
38
+ value: row.value,
39
+ };
40
+ }
41
+ // [function]
42
+ // writes a value to its file, making the folders it needs, as JSON a
43
+ // person reads, and resolves with its key.
44
+ export function setLocal(root, key, value) {
45
+ const named = keyOf(key);
46
+ const file = fileOf(root, named);
47
+ fs.mkdirSync(path.dirname(file), { recursive: true });
48
+ fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
49
+ return { channel: LOCAL, keys: [named] };
50
+ }
51
+ // [function]
52
+ // a value, with its revision (when its file was last written) and when.
53
+ export function getLocal(root, key) {
54
+ return { channel: LOCAL, ...rowOf(root, keyOf(key)) };
55
+ }
56
+ // [function]
57
+ // every key that starts with `prefix`, in order, with its size and when it
58
+ // was set, never its value.
59
+ export function listLocal(root, prefix = "") {
60
+ return [...developerRows(dirOf(root)).values()]
61
+ .filter((row) => row.key.startsWith(prefix))
62
+ .sort((a, b) => Buffer.compare(Buffer.from(a.key), Buffer.from(b.key)))
63
+ .map(({ key, revision, size, updated_at: updated }) => ({
64
+ key,
65
+ revision,
66
+ size,
67
+ updated_at: updated,
68
+ }));
69
+ }
70
+ // [function]
71
+ // removes a value's file, and resolves with its key; one that isn't there
72
+ // is not found. A folder it leaves empty stays.
73
+ export function removeLocal(root, key) {
74
+ const named = keyOf(key);
75
+ rowOf(root, named);
76
+ fs.rmSync(fileOf(root, named));
77
+ return { channel: LOCAL, keys: [named] };
78
+ }
@@ -9,8 +9,10 @@ import { gameValuesList, gameValuesRead, gameValuesRemove, gameValuesWrite, game
9
9
  import { ARGUMENT_INVALID, GAME_NOT_FOUND, LIMIT_REACHED, PARSE_FAILED, PATH_NOT_FOUND, VALUE_NOT_FOUND, VALUE_STORAGE_QUOTA_FULL, VALUE_TOO_LARGE, } from "../../config/code.js";
10
10
  import { ArcError } from "../../util/error.js";
11
11
  import { HttpError } from "../../util/http.js";
12
- import { gameOf, headersOf, isRefused, needOf, REFUSED } from "../game.js";
13
- import { gameNotOwned, valueCallsSpent, valueDirEmpty, valueFileUnread, valueFull, valueHolds, valueKeyInvalid, valueNotFound, valueNotJson, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
12
+ import { CHANNELS, channelOf, gameOf, headersOf, isRefused, needOf, REFUSED, } from "../game.js";
13
+ import { DEVELOPER_DIR } from "../../serve/values.js";
14
+ import { iso } from "../../util/time.js";
15
+ import { gameNotOwned, valueCallsSpent, valueDirEmpty, valueFileUnread, valueFull, valueHolds, valueKeyInvalid, valueNotFound, valueNotJson, valueSetTwice, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
14
16
  // [declare]
15
17
  // a key, as Arcadible takes one (db/function/game_value.sql, value_keys).
16
18
  export const KEY = /^[A-Za-z0-9_./-]{1,128}$/u;
@@ -23,7 +25,7 @@ const PAGE = 100;
23
25
  const FILE = ".json";
24
26
  // [function]
25
27
  // a key as it was given, or a refusal before the API is asked.
26
- function keyOf(key) {
28
+ export function keyOf(key) {
27
29
  if (typeof key !== "string" || !KEY.test(key)) {
28
30
  throw new ArcError(ARGUMENT_INVALID, valueKeyInvalid(String(key)));
29
31
  }
@@ -31,7 +33,7 @@ function keyOf(key) {
31
33
  }
32
34
  // [function]
33
35
  // a value from its JSON text; `source` names where the text is from.
34
- function parsed(text, source) {
36
+ export function parsed(text, source) {
35
37
  try {
36
38
  return JSON.parse(text);
37
39
  }
@@ -49,15 +51,17 @@ function fileOf(file) {
49
51
  }
50
52
  }
51
53
  // [function]
52
- // a folder's values: each .json file under it, its path its key
53
- // (daily/2026-11-12.json is daily/2026-11-12), in key order.
54
- function folderOf(dir) {
55
- let names;
54
+ // the project's values: each .json file under its folder, its path its key
55
+ // (daily/2026-11-12.json is daily/2026-11-12), in key order. A folder
56
+ // that isn't there holds none.
57
+ function folderOf(root) {
58
+ const dir = path.join(root, DEVELOPER_DIR);
59
+ let names = [];
56
60
  try {
57
61
  names = fs.readdirSync(dir, { recursive: true });
58
62
  }
59
- catch (err) {
60
- throw new ArcError(PATH_NOT_FOUND, valueFileUnread(dir), { cause: err });
63
+ catch {
64
+ // none yet
61
65
  }
62
66
  const items = names
63
67
  .filter((name) => name.endsWith(FILE))
@@ -69,7 +73,7 @@ function folderOf(dir) {
69
73
  })
70
74
  .sort((a, b) => (a.key < b.key ? -1 : 1));
71
75
  if (items.length === 0) {
72
- throw new ArcError(ARGUMENT_INVALID, valueDirEmpty(dir));
76
+ throw new ArcError(ARGUMENT_INVALID, valueDirEmpty());
73
77
  }
74
78
  return items;
75
79
  }
@@ -97,12 +101,24 @@ function batches(items) {
97
101
  return all;
98
102
  }
99
103
  // [function]
104
+ // a scope as the API states it, as `usage` says it.
105
+ function scopeOf(row) {
106
+ return {
107
+ bytes: row.bytes,
108
+ keys: row.keys,
109
+ limit: { bytes: row.bytes_limit, keys: row.keys_limit },
110
+ owner_max: { bytes: row.bytes_most, keys: row.keys_most },
111
+ owners: row.owners,
112
+ scope: row.scope,
113
+ };
114
+ }
115
+ // [function]
100
116
  // what the developer's values on `channel` may hold, as the API states it
101
117
  // for the account's plan, or null when it can't be had.
102
118
  async function holds(id, channel, headers) {
103
119
  const scopes = await gameValueUsages(id, channel, headers).catch(() => null);
104
120
  const mine = scopes?.find((each) => each.scope === "developer" && each.channel === channel);
105
- return mine ? valueHolds(mine) : null;
121
+ return mine ? valueHolds(scopeOf(mine).limit) : null;
106
122
  }
107
123
  // [function]
108
124
  // the API's refusals, said for a developer's values: a game that isn't the
@@ -126,26 +142,38 @@ function refused(id, channel, headers) {
126
142
  };
127
143
  }
128
144
  // [function]
129
- // sets one value, from a file or from `input()`, or a folder of them, in
130
- // batches: each batch is written whole or not at all, and a failure says
131
- // which key it stopped at. Resolves with the keys set.
132
- export async function set(current, { channel, dir, file, input, key, ...conf }) {
133
- if ((key === undefined) === (dir === undefined)) {
145
+ // a value to set, from where it was given: the command line, a file, or
146
+ // standard input, one of them.
147
+ export async function valueOf(root, { file, input, value }) {
148
+ if (value !== undefined && file !== undefined) {
149
+ throw new ArcError(ARGUMENT_INVALID, valueSetTwice());
150
+ }
151
+ if (value !== undefined) {
152
+ return parsed(value, "the command line");
153
+ }
154
+ if (file !== undefined) {
155
+ return parsed(fileOf(path.resolve(root, file)), file);
156
+ }
157
+ return parsed(await input(), "standard input");
158
+ }
159
+ // [function]
160
+ // sets one value, or, with no key, every value in the project's folder
161
+ // (DEVELOPER_DIR), in batches: each batch is written whole or not at all,
162
+ // and a failure says which key it stopped at. Resolves with the keys set.
163
+ export async function set(current, { channel, file, input, key, value, ...conf }) {
164
+ if (key === undefined && (value !== undefined || file !== undefined)) {
134
165
  throw new ArcError(ARGUMENT_INVALID, valueSetWhat());
135
166
  }
136
- const named = dir === undefined ? keyOf(key) : null;
167
+ const named = key === undefined ? null : keyOf(key);
137
168
  const where = needOf(channel);
138
169
  const id = await gameOf(conf);
139
170
  const headers = headersOf(current);
140
- const at = (given) => path.resolve(conf.root, given);
141
171
  const items = named === null
142
- ? folderOf(at(dir ?? ""))
172
+ ? folderOf(conf.root)
143
173
  : [
144
174
  {
145
175
  key: named,
146
- value: file === undefined
147
- ? parsed(await input(), "standard input")
148
- : parsed(fileOf(at(file)), file),
176
+ value: await valueOf(conf.root, { file, input, value }),
149
177
  },
150
178
  ];
151
179
  for (const batch of batches(items)) {
@@ -174,7 +202,7 @@ export async function get(current, { channel, key, ...conf }) {
174
202
  if (!value) {
175
203
  throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
176
204
  }
177
- return { channel: where, ...value };
205
+ return { channel: where, ...value, updated_at: iso(value.updated_at) };
178
206
  }
179
207
  // [function]
180
208
  // every key that starts with `prefix`, in order, each with its size and when
@@ -190,7 +218,10 @@ export async function list(current, { channel, prefix = "", ...conf }) {
190
218
  let after = "";
191
219
  for (;;) {
192
220
  const page = await gameValuesList(id, where, { after, limit: PAGE, prefix }, headers).catch(refused(id, where, headers));
193
- all.push(...page.entries);
221
+ all.push(...page.entries.map((entry) => ({
222
+ ...entry,
223
+ updated_at: iso(entry.updated_at),
224
+ })));
194
225
  if (page.next === null) {
195
226
  return all;
196
227
  }
@@ -212,19 +243,34 @@ export async function remove(current, { channel, key, ...conf }) {
212
243
  return { channel: where, keys: [named] };
213
244
  }
214
245
  // [function]
215
- // what each scope of the game's values holds on a channel, against what it
216
- // may: the developer's, the game's, its players', and its server's. And the
217
- // calls the game's clients made today on that channel, with the game's
218
- // day, its month, and its account's pool, as the API states them; null when they
219
- // can't be had, which fails nothing.
246
+ // what each scope of the game's values holds, on each channel or on the
247
+ // one named, against what it may: the developer's, the game's, its
248
+ // players', and its server's. And the calls the game's clients made today,
249
+ // each channel's, with the game's day, its month, and its account's month,
250
+ // as the API states them; null when they can't be had, which fails
251
+ // nothing.
220
252
  export async function usage(current, { channel, ...conf }) {
221
- const where = needOf(channel);
253
+ const where = channelOf(channel);
222
254
  const id = await gameOf(conf);
223
255
  const headers = headersOf(current);
224
- const scopes = (await gameValueUsages(id, where, headers).catch(refused(id, where, headers))) ?? [];
225
- const calls = await gameValueCalls(id, headers).catch(() => null);
256
+ const shown = CHANNELS.filter((each) => !where || each === where);
257
+ const scopes = await Promise.all(shown.map(async (each) => (await gameValueUsages(id, each, headers).catch(refused(id, each, headers))) ?? []));
258
+ const all = await gameValueCalls(id, headers).catch(() => null);
259
+ const calls = all?.[0] ?? null;
260
+ const own = (each) => all?.find((row) => row.channel === each);
226
261
  return {
227
- calls: calls?.find((each) => each.channel === where) ?? null,
228
- scopes,
262
+ account: calls
263
+ ? { allowance: calls.pool_allowance, calls: calls.pool_used }
264
+ : null,
265
+ channels: shown.map((each, i) => {
266
+ const mine = own(each);
267
+ return {
268
+ channel: each,
269
+ scopes: (scopes[i] ?? []).map(scopeOf),
270
+ today: mine ? { reads: mine.reads, writes: mine.writes } : null,
271
+ };
272
+ }),
273
+ month: calls ? { calls: calls.month_used } : null,
274
+ today: calls ? { allowance: calls.allowance, calls: calls.used } : null,
229
275
  };
230
276
  }
@@ -1,4 +1,4 @@
1
- // arc unstable wire: a game's wires (plan/SDKWIRES.md), live messages between its
1
+ // arc 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
@@ -128,6 +128,7 @@ const isUsage = shaped({
128
128
  allowance: nul(either(num, str)),
129
129
  channel: str,
130
130
  cpu_ms: opt(nul(either(num, str))),
131
+ day: str,
131
132
  month_cpu_ms: opt(nul(either(num, str))),
132
133
  month_used: either(num, str),
133
134
  pool_allowance: nul(either(num, str)),
@@ -105,7 +105,19 @@ function withCommands(cli, family, conf, matched) {
105
105
  });
106
106
  });
107
107
  }, cli);
108
- const demanded = added.demandCommand(1);
108
+ // a family with no commands, as `arc unstable` is between them, takes
109
+ // nothing: yargs knows no command to call another unknown, so it's said
110
+ // here, as yargs says it
111
+ const demanded = family.commands.length > 0
112
+ ? added.demandCommand(1)
113
+ : added.demandCommand(1).check((argv) => {
114
+ const given = argv._.map(String);
115
+ const extra = given.slice(given.indexOf(family.name) + 1);
116
+ if (extra.length > 0) {
117
+ throw new Error(`Unknown argument: ${extra.join(", ")}`);
118
+ }
119
+ return true;
120
+ });
109
121
  return family.epilogue ? demanded.epilogue(family.epilogue) : demanded;
110
122
  }
111
123
  // [function]
@@ -54,6 +54,13 @@ export const CHANNEL = {
54
54
  staging: { describe: "On staging", type: "boolean" },
55
55
  };
56
56
  // [declare]
57
+ // the pair for `arc value`'s commands, which, given neither, work on the
58
+ // project's own values, the local channel `arc serve` reads (cli:13a).
59
+ export const CHANNEL_VALUES = {
60
+ production: { describe: "On Arcadible's production", type: "boolean" },
61
+ staging: { describe: "On Arcadible's staging", type: "boolean" },
62
+ };
63
+ // [declare]
57
64
  // the pair for a command that only shows, which takes one, or neither for
58
65
  // both.
59
66
  export const CHANNEL_SHOWS = {
@@ -1,6 +1,6 @@
1
1
  // the three questions arc asks at a terminal, on `node:readline`: a yes or
2
2
  // no (./confirm.ts), `arc init`'s choice of a starter, and a secret typed
3
- // unseen (`arc unstable function secret set`). Each is asked only where
3
+ // unseen (`arc function secret set`). Each is asked only where
4
4
  // there's a terminal; a caller without one never gets here. Ctrl+C ends a
5
5
  // question with `Cancelled`, which the one error path ends as 130
6
6
  // (./command.ts). No test has a terminal, so each is tried by hand before a