arcadible 1.0.24 → 1.0.25

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 (53) hide show
  1. package/dist/action/build/tool.js +5 -9
  2. package/dist/action/delete/tool.js +2 -1
  3. package/dist/action/deploy/tool-git.js +4 -9
  4. package/dist/action/deploy/tool.js +3 -8
  5. package/dist/action/deploy/wait.js +1 -1
  6. package/dist/action/function/tool.js +6 -6
  7. package/dist/action/game.js +3 -2
  8. package/dist/action/key/tool.js +6 -5
  9. package/dist/action/open/tool.js +2 -1
  10. package/dist/action/pack/tool.js +13 -15
  11. package/dist/action/play/tool.js +2 -1
  12. package/dist/action/predeploy/ac.js +3 -3
  13. package/dist/action/predeploy/game.js +2 -8
  14. package/dist/action/predeploy/secrets.js +2 -2
  15. package/dist/action/predeploy/tool-git.js +3 -8
  16. package/dist/action/predeploy/tool.js +1 -3
  17. package/dist/action/secret/tool.js +4 -4
  18. package/dist/action/serve/tool.js +26 -5
  19. package/dist/action/value/tool.js +216 -0
  20. package/dist/api.js +190 -38
  21. package/dist/command/inspect.js +2 -1
  22. package/dist/command/open.js +2 -1
  23. package/dist/command/play.js +4 -3
  24. package/dist/command/serve.js +3 -2
  25. package/dist/command/value/get.js +21 -0
  26. package/dist/command/value/index.js +19 -0
  27. package/dist/command/value/key.js +8 -0
  28. package/dist/command/value/list.js +41 -0
  29. package/dist/command/value/remove.js +26 -0
  30. package/dist/command/value/set.js +62 -0
  31. package/dist/command/value/usage.js +69 -0
  32. package/dist/commands.js +8 -1
  33. package/dist/phrase/common.js +9 -0
  34. package/dist/phrase/deploy.js +9 -1
  35. package/dist/phrase/function.js +6 -2
  36. package/dist/phrase/index.js +1 -0
  37. package/dist/phrase/server.js +1 -1
  38. package/dist/phrase/value.js +55 -0
  39. package/dist/runner/bundle.js +10 -60
  40. package/dist/runner/entry.js +57 -0
  41. package/dist/runner/outbound.js +1 -1
  42. package/dist/schema/workflow.js +1 -1
  43. package/dist/serve/page.js +205 -6
  44. package/dist/serve/runner.js +9 -2
  45. package/dist/serve/server.js +7 -1
  46. package/dist/serve/ticket.js +2 -2
  47. package/dist/serve/values.js +317 -0
  48. package/dist/util/objs.js +17 -0
  49. package/dist/util/request.js +15 -3
  50. package/dist/util/schema.js +1 -1
  51. package/dist/util/shape.js +49 -0
  52. package/npm-shrinkwrap.json +2 -2
  53. package/package.json +1 -1
@@ -0,0 +1,216 @@
1
+ // a game's developer's values (plan/VALUES.md, The developer's side): JSON
2
+ // under a key, published by the game's owner on a channel, which the game
3
+ // and its server read. Set one at a time, or a folder of them, a file a
4
+ // value; read, listed, and removed. Nothing here keeps one.
5
+ // [import]
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { gameValuesList, gameValuesRead, gameValuesRemove, gameValuesWrite, gameValueCalls, gameValueUsages, } from "../../api.js";
9
+ import { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
10
+ import { ArcError } from "../../util/error.js";
11
+ import { gameOf, headersOf, isStatus, needOf } from "../game.js";
12
+ import { gameUnavailable, valueDirEmpty, valueFileUnread, valueFull, valueKeyInvalid, valueNotFound, valueNotJson, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
13
+ // [declare]
14
+ // a key, as Arcadible takes one (db/function/game_value.sql, value_keys).
15
+ export const KEY = /^[A-Za-z0-9_./-]{1,128}$/u;
16
+ // the most keys a call names, and the most its values are together: under
17
+ // the API's 256 KB, since it counts a value as the database keeps it, which
18
+ // is a little more than its text here.
19
+ const BATCH_KEYS = 32;
20
+ const BATCH_BYTES = 192 * 1024;
21
+ const PAGE = 100;
22
+ const FILE = ".json";
23
+ // [function]
24
+ // a key as it was given, or a refusal before the API is asked.
25
+ function keyOf(key) {
26
+ if (typeof key !== "string" || !KEY.test(key)) {
27
+ throw new ArcError(ARGUMENT_INVALID, valueKeyInvalid(String(key)));
28
+ }
29
+ return key;
30
+ }
31
+ // [function]
32
+ // a value from its JSON text; `source` names where the text is from.
33
+ function parsed(text, source) {
34
+ try {
35
+ return JSON.parse(text);
36
+ }
37
+ catch (err) {
38
+ throw new ArcError(ARGUMENT_INVALID, valueNotJson(source), { cause: err });
39
+ }
40
+ }
41
+ // [function]
42
+ function fileOf(file) {
43
+ try {
44
+ return fs.readFileSync(file, "utf8");
45
+ }
46
+ catch (err) {
47
+ throw new ArcError(ARGUMENT_INVALID, valueFileUnread(file), { cause: err });
48
+ }
49
+ }
50
+ // [function]
51
+ // a folder's values: each .json file under it, its path its key
52
+ // (daily/2026-11-12.json is daily/2026-11-12), in key order.
53
+ function folderOf(dir) {
54
+ let names;
55
+ try {
56
+ names = fs.readdirSync(dir, { recursive: true });
57
+ }
58
+ catch (err) {
59
+ throw new ArcError(ARGUMENT_INVALID, valueFileUnread(dir), { cause: err });
60
+ }
61
+ const items = names
62
+ .filter((name) => name.endsWith(FILE))
63
+ .filter((name) => fs.statSync(path.join(dir, name)).isFile())
64
+ .map((name) => {
65
+ const file = path.join(dir, name);
66
+ const key = keyOf(name.slice(0, -FILE.length).split(path.sep).join("/"));
67
+ return { key, value: parsed(fileOf(file), file) };
68
+ })
69
+ .sort((a, b) => (a.key < b.key ? -1 : 1));
70
+ if (items.length === 0) {
71
+ throw new ArcError(ARGUMENT_INVALID, valueDirEmpty(dir));
72
+ }
73
+ return items;
74
+ }
75
+ // [function]
76
+ // `items` in batches a call takes: up to 32 keys, and their values together
77
+ // under what a call holds.
78
+ function batches(items) {
79
+ const all = [];
80
+ let batch = [];
81
+ let bytes = 0;
82
+ for (const item of items) {
83
+ const size = Buffer.byteLength(JSON.stringify(item.value));
84
+ if (batch.length > 0 &&
85
+ (batch.length === BATCH_KEYS || bytes + size > BATCH_BYTES)) {
86
+ all.push(batch);
87
+ batch = [];
88
+ bytes = 0;
89
+ }
90
+ batch.push(item);
91
+ bytes += size;
92
+ }
93
+ if (batch.length > 0) {
94
+ all.push(batch);
95
+ }
96
+ return all;
97
+ }
98
+ // [function]
99
+ // 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) => {
103
+ if (isStatus(err, 404)) {
104
+ throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
105
+ cause: err,
106
+ });
107
+ }
108
+ if (isStatus(err, 507)) {
109
+ throw new ArcError(API_REFUSED, valueFull(channel), { cause: err });
110
+ }
111
+ throw err;
112
+ };
113
+ }
114
+ // [function]
115
+ // sets one value, from a file or from `input()`, or a folder of them, in
116
+ // batches: each batch is written whole or not at all, and a failure says
117
+ // which key it stopped at. Resolves with the keys set.
118
+ export async function set(current, { channel, dir, file, input, key, ...conf }) {
119
+ if ((key === undefined) === (dir === undefined)) {
120
+ throw new ArcError(ARGUMENT_INVALID, valueSetWhat());
121
+ }
122
+ const named = dir === undefined ? keyOf(key) : null;
123
+ const where = needOf(channel);
124
+ const id = await gameOf(conf);
125
+ const headers = headersOf(current);
126
+ const at = (given) => path.resolve(conf.root, given);
127
+ const items = named === null
128
+ ? folderOf(at(dir ?? ""))
129
+ : [
130
+ {
131
+ key: named,
132
+ value: file === undefined
133
+ ? parsed(await input(), "standard input")
134
+ : parsed(fileOf(at(file)), file),
135
+ },
136
+ ];
137
+ for (const batch of batches(items)) {
138
+ await gameValuesWrite(id, where, batch, headers).catch((err) => {
139
+ if (isStatus(err, 413)) {
140
+ // a batch is under what a call holds, so it's one value's own size
141
+ const [largest] = [...batch].sort((a, b) => JSON.stringify(b.value).length - JSON.stringify(a.value).length);
142
+ throw new ArcError(API_REFUSED, valueTooLarge(largest?.key ?? ""), {
143
+ cause: err,
144
+ });
145
+ }
146
+ return refused(id, where)(err);
147
+ });
148
+ }
149
+ return { channel: where, keys: items.map((item) => item.key) };
150
+ }
151
+ // [function]
152
+ // a value, with its revision and when it was set. One that isn't set, or
153
+ // isn't the game's, is the same to its owner: not found.
154
+ export async function get(current, { channel, key, ...conf }) {
155
+ const named = keyOf(key);
156
+ const where = needOf(channel);
157
+ const id = await gameOf(conf);
158
+ const headers = headersOf(current);
159
+ const [value] = await gameValuesRead(id, where, [named], headers).catch(refused(id, where));
160
+ if (!value) {
161
+ throw new ArcError(API_REFUSED, valueNotFound({ channel: where, key: named }));
162
+ }
163
+ return { channel: where, ...value };
164
+ }
165
+ // [function]
166
+ // every key that starts with `prefix`, in order, each with its size and when
167
+ // it was set, never its value: every page of them.
168
+ export async function list(current, { channel, prefix = "", ...conf }) {
169
+ if (prefix !== "" && !KEY.test(prefix)) {
170
+ throw new ArcError(ARGUMENT_INVALID, valueKeyInvalid(prefix));
171
+ }
172
+ const where = needOf(channel);
173
+ const id = await gameOf(conf);
174
+ const headers = headersOf(current);
175
+ const all = [];
176
+ let after = "";
177
+ for (;;) {
178
+ const page = await gameValuesList(id, where, { after, limit: PAGE, prefix }, headers).catch(refused(id, where));
179
+ all.push(...page.entries);
180
+ if (page.next === null) {
181
+ return all;
182
+ }
183
+ after = page.next;
184
+ }
185
+ }
186
+ // [function]
187
+ // removes a value, and resolves with its key. One that isn't set is not
188
+ // found.
189
+ export async function remove(current, { channel, key, ...conf }) {
190
+ const named = keyOf(key);
191
+ const where = needOf(channel);
192
+ const id = await gameOf(conf);
193
+ const headers = headersOf(current);
194
+ const { removed } = await gameValuesRemove(id, where, [named], headers).catch(refused(id, where));
195
+ if (removed === 0) {
196
+ throw new ArcError(API_REFUSED, valueNotFound({ channel: where, key: named }));
197
+ }
198
+ return { channel: where, keys: [named] };
199
+ }
200
+ // [function]
201
+ // what each scope of the game's values holds on a channel, against what it
202
+ // may: the developer's, the game's, its players', and its server's. And the
203
+ // calls the game's clients made today on that channel, with the game's,
204
+ // both channels together, against its allowance for a day; null when they
205
+ // can't be had, which fails nothing.
206
+ export async function usage(current, { channel, ...conf }) {
207
+ const where = needOf(channel);
208
+ const id = await gameOf(conf);
209
+ const headers = headersOf(current);
210
+ const scopes = (await gameValueUsages(id, where, headers).catch(refused(id, where))) ?? [];
211
+ const calls = await gameValueCalls(id, headers).catch(() => null);
212
+ return {
213
+ calls: calls?.find((each) => each.channel === where) ?? null,
214
+ scopes,
215
+ };
216
+ }
package/dist/api.js CHANGED
@@ -1,15 +1,128 @@
1
1
  // [import]
2
- import { del, get, post, put } from "./util/request.js";
2
+ import { INTERNAL } from "./config/code.js";
3
+ import { ArcError } from "./util/error.js";
4
+ import { answerUnread } from "./phrase/index.js";
5
+ import { del, get, post, postJson, put } from "./util/request.js";
6
+ import { any, either, listed, nul, num, opt, shaped, str, } from "./util/shape.js";
3
7
  import { HOST_HTTP_API } from "./config/uri.js";
4
8
  // [declare]
5
9
  const VERSION = "v1";
10
+ // [declare]
11
+ // each answer's shape (util/shape.ts): what the CLI reads of it, checked as
12
+ // it arrives. A read with `select` holds only what was asked for, so a
13
+ // game's, a build's, and a release's fields may each be left out.
14
+ const isSession = shaped({
15
+ access_token: str,
16
+ expires_at: num,
17
+ refresh_token: str,
18
+ });
19
+ const isUser = shaped({ display_name: str, id: nul(str) });
20
+ const isAccount = shaped({
21
+ session: isSession,
22
+ user: isUser,
23
+ });
24
+ const isFlowCreated = shaped({ code: str, id: str });
25
+ const isFlow = shaped({ data: opt(nul(isAccount)), status: str });
26
+ const isGame = shaped({
27
+ account: opt(str),
28
+ handle: opt(nul(str)),
29
+ orientation: opt(nul(str)),
30
+ });
31
+ const isManifest = shaped({ function: any });
32
+ const isBuild = shaped({
33
+ channel: opt(str),
34
+ manifest: opt(nul(isManifest)),
35
+ version: opt(str),
36
+ });
37
+ const isRelease = shaped({
38
+ build: any,
39
+ channel: opt(str),
40
+ created_at: opt(str),
41
+ game: opt(nul(str)),
42
+ id: opt(str),
43
+ message: opt(nul(str)),
44
+ reason: opt(nul(str)),
45
+ source: opt(str),
46
+ status: opt(str),
47
+ version: opt(str),
48
+ });
49
+ const isUpload = shaped({ id: str, upload_url: str });
50
+ const isHandleStatus = shaped({ status: str });
51
+ const isKey = shaped({
52
+ channel: str,
53
+ created_at: str,
54
+ id: str,
55
+ name: str,
56
+ shown: str,
57
+ used_at: nul(str),
58
+ });
59
+ const isKeyCreated = shaped({
60
+ channel: str,
61
+ id: str,
62
+ key: str,
63
+ name: str,
64
+ });
65
+ const isKeyRevoked = shaped({ id: str });
66
+ const isSecret = shaped({
67
+ channel: str,
68
+ name: str,
69
+ updated_at: opt(str),
70
+ });
71
+ const isValue = shaped({
72
+ key: str,
73
+ revision: num,
74
+ updated_at: str,
75
+ value: any,
76
+ });
77
+ const isValueEntry = shaped({
78
+ key: str,
79
+ revision: num,
80
+ size: opt(num),
81
+ updated_at: str,
82
+ });
83
+ const isValueEntries = (value) => Array.isArray(value) && value.every(isValueEntry);
84
+ const isValueListed = shaped({
85
+ entries: isValueEntries,
86
+ next: nul(str),
87
+ });
88
+ const isValueRemoved = shaped({ removed: num });
89
+ const isValueUsage = shaped({
90
+ bytes: num,
91
+ bytes_limit: num,
92
+ bytes_most: num,
93
+ channel: str,
94
+ keys: num,
95
+ keys_limit: num,
96
+ keys_most: num,
97
+ owners: num,
98
+ scope: str,
99
+ });
100
+ const isValueCalls = shaped({
101
+ allowance: num,
102
+ channel: str,
103
+ reads: num,
104
+ used: num,
105
+ writes: num,
106
+ });
107
+ const isPause = shaped({ channel: str, reason: str });
108
+ const isUsage = shaped({
109
+ allowance: either(num, str),
110
+ channel: str,
111
+ requests: opt(nul(either(num, str))),
112
+ });
6
113
  // [function]
7
- // the API's answer, as the shape its endpoint answers with. Nothing checks
8
- // it: this is the one place the CLI takes the API at its word, as the first
9
- // CLI did everywhere, so a field a caller can't do without is still its to
10
- // check. An answer whose shape the CLI doesn't know stays `unknown`.
11
- function answer(data) {
12
- return data;
114
+ // the API's answer, checked as it arrives: `is` says whether it has the
115
+ // shape its endpoint answers with, as far as the CLI reads it. One that
116
+ // doesn't is a failure said plainly, naming `what` was asked for, where a
117
+ // field read later as it isn't would be a wrong branch or `undefined` in a
118
+ // message. An answer the CLI doesn't read stays `unknown`, unchecked.
119
+ function answer(is, what, data) {
120
+ return data.then((value) => {
121
+ if (!is(value)) {
122
+ throw new ArcError(INTERNAL, answerUnread(what));
123
+ }
124
+ return value;
125
+ });
13
126
  }
14
127
  // [function]
15
128
  // an API path with each value encoded as one segment, so a handle or version
@@ -43,36 +156,36 @@ export function postAuthLogout(params, headers) {
43
156
  }
44
157
  // [function]
45
158
  export function postAuthRefresh(form, params, headers) {
46
- return answer(post(endpoint("/auth/refresh", params), form, headers));
159
+ return answer(isSession, "a session", post(endpoint("/auth/refresh", params), form, headers));
47
160
  }
48
161
  // [function]
49
162
  export function postFlow(form, params, headers) {
50
- return answer(post(endpoint("/flows", params), form, headers));
163
+ return answer(isFlowCreated, "a login", post(endpoint("/flows", params), form, headers));
51
164
  }
52
165
  // [function]
53
166
  export function flow(id, params, headers) {
54
- return answer(get(endpoint(pathOf `/flows/${id}`, params), headers));
167
+ return answer(isFlow, "a login", get(endpoint(pathOf `/flows/${id}`, params), headers));
55
168
  }
56
169
  // [function]
57
170
  export function postUpload(form, params, headers) {
58
- return answer(post(endpoint("/uploads", params), form, headers));
171
+ return answer(isUpload, "an upload", post(endpoint("/uploads", params), form, headers));
59
172
  }
60
173
  // [function]
61
174
  export function discoverGame(id, params, headers) {
62
- return answer(get(endpoint(pathOf `/discover/games/${id}`, params), headers));
175
+ return answer(isGame, "a game", get(endpoint(pathOf `/discover/games/${id}`, params), headers));
63
176
  }
64
177
  // [function]
65
178
  export function discoverGameBuilds(id, params, headers) {
66
- return answer(get(endpoint(pathOf `/discover/games/${id}/builds`, params), headers));
179
+ return answer(listed(isBuild), "a game's builds", get(endpoint(pathOf `/discover/games/${id}/builds`, params), headers));
67
180
  }
68
181
  // [function]
69
182
  export function discoverGameBuild(id, version, params, headers) {
70
- return answer(get(endpoint(pathOf `/discover/games/${id}/builds/${version}`, params), headers));
183
+ return answer(isBuild, "a build", get(endpoint(pathOf `/discover/games/${id}/builds/${version}`, params), headers));
71
184
  }
72
185
  // [function]
73
186
  // a game's releases, which anyone can read: what each says about itself.
74
187
  export function discoverGameReleases(id, params, headers) {
75
- return answer(get(endpoint(pathOf `/discover/games/${id}/releases`, params), headers));
188
+ return answer(listed(isRelease), "a game's releases", get(endpoint(pathOf `/discover/games/${id}/releases`, params), headers));
76
189
  }
77
190
  // [function]
78
191
  // the game's connected repository, if it's `owner/name`; otherwise 404.
@@ -81,17 +194,17 @@ export function discoverGameRepo(id, owner, name, params, headers) {
81
194
  }
82
195
  // [function]
83
196
  export function gameBuild(id, version, params, headers) {
84
- return answer(get(endpoint(pathOf `/games/${id}/builds/${version}`, params), headers));
197
+ return answer(isBuild, "a build", get(endpoint(pathOf `/games/${id}/builds/${version}`, params), headers));
85
198
  }
86
199
  // [function]
87
200
  // whether the caller's game could take a handle on a deploy to `channel`:
88
201
  // its status is available, taken, limit, or lapsed.
89
202
  export function gameHandle(id, handle, params, headers) {
90
- return answer(get(endpoint(pathOf `/games/${id}/handles/${handle}`, params), headers));
203
+ return answer(isHandleStatus, "a handle", get(endpoint(pathOf `/games/${id}/handles/${handle}`, params), headers));
91
204
  }
92
205
  // [function]
93
206
  export function release(id, params, headers) {
94
- return answer(get(endpoint(pathOf `/releases/${id}`, params), headers));
207
+ return answer(isRelease, "a release", get(endpoint(pathOf `/releases/${id}`, params), headers));
95
208
  }
96
209
  // [function]
97
210
  // deletes the caller's own game, by its id: at once, and for good. One that
@@ -102,59 +215,98 @@ export function deleteGame(id, params, headers) {
102
215
  // [function]
103
216
  // the live keys of the caller's own game: never the keys themselves.
104
217
  export function gameKeys(id, params, headers) {
105
- return answer(get(endpoint(pathOf `/games/${id}/keys`, params), headers));
218
+ return answer(listed(isKey), "a game's keys", get(endpoint(pathOf `/games/${id}/keys`, params), headers));
106
219
  }
107
220
  // [function]
108
221
  // a new key for the caller's own game, answered once, in `key`.
109
222
  export function postGameKey(id, form, params, headers) {
110
- return answer(post(endpoint(pathOf `/games/${id}/keys`, params), form, headers));
223
+ return answer(isKeyCreated, "a key", post(endpoint(pathOf `/games/${id}/keys`, params), form, headers));
111
224
  }
112
225
  // [function]
113
- // revokes a key of the caller's own game, by the key's id.
114
- export function deleteGameKey(id, key, params, headers) {
115
- return answer(del(endpoint(pathOf `/games/${id}/keys/${key}`, params), headers));
226
+ // revokes a key of one of the caller's own games, by the key's id.
227
+ export function deleteKey(key, params, headers) {
228
+ return answer(isKeyRevoked, "a key", del(endpoint(pathOf `/keys/${key}`, params), headers));
116
229
  }
117
230
  // [function]
118
231
  // the secrets of the caller's own game's runner, by channel and name: never
119
232
  // their values.
120
- export function gameSecrets(id, params, headers) {
121
- return answer(get(endpoint(pathOf `/games/${id}/secrets`, params), headers));
233
+ export function gameFunctionSecrets(id, params, headers) {
234
+ return answer(listed(isSecret), "a function's secrets", get(endpoint(pathOf `/games/${id}/function_secrets`, params), headers));
122
235
  }
123
236
  // [function]
124
237
  // a secret's address: its channel, and its name in lowercase, as the API's
125
238
  // addresses are.
126
239
  function secretPath(id, channel, name) {
127
- return pathOf `/games/${id}/secrets/${channel}/${name.toLowerCase()}`;
240
+ return pathOf `/games/${id}/function_secrets/${channel}/${name.toLowerCase()}`;
128
241
  }
129
242
  // [function]
130
243
  // sets a secret of the caller's own game, with its value in the form.
131
- export function putGameSecret(id, channel, name, form, params, headers) {
132
- return answer(put(endpoint(secretPath(id, channel, name), params), form, headers));
244
+ export function putGameFunctionSecret(id, channel, name, form, params, headers) {
245
+ return answer(isSecret, "a secret", put(endpoint(secretPath(id, channel, name), params), form, headers));
133
246
  }
134
247
  // [function]
135
248
  // removes a secret of the caller's own game.
136
- export function deleteGameSecret(id, channel, name, params, headers) {
137
- return answer(del(endpoint(secretPath(id, channel, name), params), headers));
249
+ export function deleteGameFunctionSecret(id, channel, name, params, headers) {
250
+ return answer(isSecret, "a secret", del(endpoint(secretPath(id, channel, name), params), headers));
251
+ }
252
+ // [function]
253
+ // a call to the developer's values of the caller's own game, on a channel
254
+ // (plan/VALUES.md, The developer's side): its body as JSON, since a value is.
255
+ function gameValues(id, channel, verb, body, headers) {
256
+ return postJson(endpoint(pathOf `/games/${id}/values/${channel}/${verb}`), body, headers);
257
+ }
258
+ // [function]
259
+ // the values under `keys`, in their order: each with its revision, or null
260
+ // for a key with none.
261
+ export function gameValuesRead(id, channel, keys, headers) {
262
+ return answer((value) => Array.isArray(value) &&
263
+ value.every((each) => each === null || isValue(each)), "a game's values", gameValues(id, channel, "read", { keys }, headers));
264
+ }
265
+ // [function]
266
+ // writes `items`, all or none, and answers each one's new revision.
267
+ export function gameValuesWrite(id, channel, items, headers) {
268
+ return answer(isValueEntries, "a game's values", gameValues(id, channel, "write", { items }, headers));
269
+ }
270
+ // [function]
271
+ // removes what `keys` hold, and answers how many held something.
272
+ export function gameValuesRemove(id, channel, keys, headers) {
273
+ return answer(isValueRemoved, "a game's values", gameValues(id, channel, "remove", { keys }, headers));
274
+ }
275
+ // [function]
276
+ // a page of the keys that start with `prefix`, after the key `after`.
277
+ export function gameValuesList(id, channel, page, headers) {
278
+ return answer(isValueListed, "a game's values", gameValues(id, channel, "list", page, headers));
279
+ }
280
+ // [function]
281
+ // what each scope of the caller's own game's values holds on a channel.
282
+ export function gameValueUsages(id, channel, headers) {
283
+ return answer(listed(isValueUsage), "a game's values' usage", get(endpoint(pathOf `/games/${id}/value_usages`, { channel }), headers));
284
+ }
285
+ // [function]
286
+ // the calls the caller's own game's clients made to its values today, a row
287
+ // a channel, against the game's allowance for a day.
288
+ export function gameValueCalls(id, headers) {
289
+ return answer(listed(isValueCalls), "a game's values' calls", get(endpoint(pathOf `/games/${id}/value_calls`), headers));
138
290
  }
139
291
  // [function]
140
292
  // the pauses of the caller's own game's function, by channel and reason.
141
- export function gamePauses(id, params, headers) {
142
- return answer(get(endpoint(pathOf `/games/${id}/pauses`, params), headers));
293
+ export function gameFunctionPauses(id, params, headers) {
294
+ return answer(listed(isPause), "a function's pauses", get(endpoint(pathOf `/games/${id}/function_pauses`, params), headers));
143
295
  }
144
296
  // [function]
145
297
  // the usage of the caller's own game's function this month: a row a channel
146
298
  // and a day, each with the game's allowance.
147
- export function gameUsages(id, params, headers) {
148
- return answer(get(endpoint(pathOf `/games/${id}/usages`, params), headers));
299
+ export function gameFunctionUsages(id, params, headers) {
300
+ return answer(listed(isUsage), "a function's usage", get(endpoint(pathOf `/games/${id}/function_usages`, params), headers));
149
301
  }
150
302
  // [function]
151
303
  // pauses the function of the caller's own game on a channel.
152
- export function putGamePause(id, channel, params, headers) {
153
- return answer(put(endpoint(pathOf `/games/${id}/pauses/${channel}`, params), null, headers));
304
+ export function putGameFunctionPause(id, channel, params, headers) {
305
+ return answer(isPause, "a pause", put(endpoint(pathOf `/games/${id}/function_pauses/${channel}`, params), null, headers));
154
306
  }
155
307
  // [function]
156
308
  // resumes the function of the caller's own game on a channel: lifts its
157
309
  // owner's pause, and no other.
158
- export function deleteGamePause(id, channel, params, headers) {
159
- return del(endpoint(pathOf `/games/${id}/pauses/${channel}`, params), headers);
310
+ export function deleteGameFunctionPause(id, channel, params, headers) {
311
+ return del(endpoint(pathOf `/games/${id}/function_pauses/${channel}`, params), headers);
160
312
  }
@@ -2,6 +2,7 @@
2
2
  import { resolve } from "node:path";
3
3
  // [import]
4
4
  import { defineCommand } from "../cli/command.js";
5
+ import { textOf } from "../util/objs.js";
5
6
  import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
6
7
  import { print } from "../util/output.js";
7
8
  import { inspectTool } from "../action/inspect/tool.js";
@@ -19,7 +20,7 @@ export default defineCommand({
19
20
  },
20
21
  async run(argv) {
21
22
  // a string from the command line; `.arcrc` can give anything.
22
- const selector = argv.selector == null ? null : String(argv.selector);
23
+ const selector = argv.selector == null ? null : textOf(argv.selector);
23
24
  const data = await inspectTool({
24
25
  root: resolve(process.cwd(), argv.cwd),
25
26
  selector,
@@ -5,6 +5,7 @@ import { GAME_ID_MISSING } from "../config/code.js";
5
5
  import { defineCommand } from "../cli/command.js";
6
6
  import { ArcError } from "../util/error.js";
7
7
  import { gameIdMissing } from "../phrase/index.js";
8
+ import { textOf } from "../util/objs.js";
8
9
  import { BROWSER, CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
9
10
  import { launched, print } from "../util/output.js";
10
11
  import { launch } from "../util/shell.js";
@@ -25,7 +26,7 @@ export default defineCommand({
25
26
  async run(argv) {
26
27
  const data = await openTool({
27
28
  // a string from the command line; `.arcrc` can give anything.
28
- game: argv.game ? String(argv.game) : null,
29
+ game: argv.game ? textOf(argv.game) : null,
29
30
  root: resolve(process.cwd(), argv.cwd),
30
31
  });
31
32
  if (!data) {
@@ -6,6 +6,7 @@ import { defineCommand } from "../cli/command.js";
6
6
  import { ArcError } from "../util/error.js";
7
7
  import { gameIdMissing, noProductionRelease } from "../phrase/index.js";
8
8
  import { pw } from "../util/log.js";
9
+ import { textOf } from "../util/objs.js";
9
10
  import { BROWSER, CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
10
11
  import { launched, print } from "../util/output.js";
11
12
  import { launch } from "../util/shell.js";
@@ -51,8 +52,8 @@ export default defineCommand({
51
52
  aborting.sw = sw;
52
53
  const data = await playTool({
53
54
  // strings from the command line; `.arcrc` can give anything.
54
- game: argv.game ? String(argv.game) : null,
55
- release: argv.release ? String(argv.release) : null,
55
+ game: argv.game ? textOf(argv.game) : null,
56
+ release: argv.release ? textOf(argv.release) : null,
56
57
  root: resolve(process.cwd(), argv.cwd),
57
58
  }, handler({ quiet: argv.json || argv.quiet, sw }));
58
59
  const orientation = data?.orientation;
@@ -66,7 +67,7 @@ export default defineCommand({
66
67
  }
67
68
  const where = await (argv.browser
68
69
  ? launch(url)
69
- : launch(`${HOST_APP_PLAY}/${String(orientation)}/${url}`, url));
70
+ : launch(`${HOST_APP_PLAY}/${textOf(orientation)}/${url}`, url));
70
71
  if (argv.json) {
71
72
  // where it opened (app, browser, or null when it couldn't), and the
72
73
  // play link, which names the channel or version it plays.
@@ -6,6 +6,7 @@ import { defineCommand } from "../cli/command.js";
6
6
  import { ArcError } from "../util/error.js";
7
7
  import * as phrase from "../phrase/index.js";
8
8
  import { nlpw, p, pw, result } from "../util/log.js";
9
+ import { textOf } from "../util/objs.js";
9
10
  import { CWD, QUIET } from "../cli/options.js";
10
11
  import { launched } from "../util/output.js";
11
12
  import { launch } from "../util/shell.js";
@@ -29,7 +30,7 @@ function checkUrl(url) {
29
30
  return Promise.resolve(null);
30
31
  }
31
32
  try {
32
- const parsed = new URL(String(url));
33
+ const parsed = new URL(textOf(url));
33
34
  if (parsed.protocol === "http:" || parsed.protocol === "https:") {
34
35
  return Promise.resolve(parsed.href);
35
36
  }
@@ -158,7 +159,7 @@ export default defineCommand({
158
159
  built: served.built,
159
160
  url: served.url,
160
161
  // the project's, as it has it: arc serve doesn't validate it.
161
- version: served.version ? String(served.version) : null,
162
+ version: served.version ? textOf(served.version) : null,
162
163
  }), blocks);
163
164
  if (served.probed && !served.probed.reachable) {
164
165
  nlpw(phrase.urlUnreachable(served.url ?? ""));
@@ -0,0 +1,21 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { p } from "../../util/log.js";
4
+ import { KEY } from "./key.js";
5
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
6
+ import { run } from "../function/secret/run.js";
7
+ import { get } from "../../action/value/tool.js";
8
+ // [export]
9
+ export default defineCommand({
10
+ name: "get",
11
+ options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
12
+ positionals: { key: KEY },
13
+ run(argv, aborting) {
14
+ return run(argv, aborting, (current, conf) => get(current, { ...conf, key: argv.key }),
15
+ // the value alone, as JSON, so it pipes to a file as it was set
16
+ (got) => {
17
+ p(JSON.stringify(got.value, null, 2));
18
+ }, `arc value get ${argv.key}`);
19
+ },
20
+ summary: "Show a value",
21
+ });
@@ -0,0 +1,19 @@
1
+ // arc value: a game's developer's values (plan/VALUES.md), the JSON a game's
2
+ // owner publishes on a channel for the game and its server to read: a daily
3
+ // puzzle, an event's switch, a table of levels. Set, read, listed, and
4
+ // removed, a channel named each time, since nothing is copied between them.
5
+ // Left out of `arc --help` until values ship, with the docs.
6
+ // [import]
7
+ import { defineCommand } from "../../cli/command.js";
8
+ import get from "./get.js";
9
+ import list from "./list.js";
10
+ import remove from "./remove.js";
11
+ import set from "./set.js";
12
+ import usage from "./usage.js";
13
+ // [export]
14
+ export default defineCommand({
15
+ commands: [set, get, list, remove, usage],
16
+ hidden: true,
17
+ name: "value",
18
+ summary: "Set, get, list, and remove the values you publish for the game",
19
+ });