arcadible 1.0.33 → 1.0.35

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.
@@ -6,7 +6,7 @@ import { GAME_ID_MISSING, GAME_UNAVAILABLE } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
7
  import { headersOf, isStatus } from "../game.js";
8
8
  import { given } from "../../parser/given.js";
9
- import { gameIdMissing, gameUndeletable } from "../../phrase/index.js";
9
+ import { gameIdMissing, gameNotOwned } from "../../phrase/index.js";
10
10
  import { textOf } from "../../util/objs.js";
11
11
  // [function]
12
12
  // a value of the manifest's as a name, when it's text with something in it.
@@ -38,7 +38,7 @@ export async function deleteTool(current, { id }) {
38
38
  }
39
39
  catch (err) {
40
40
  if (isStatus(err, 404)) {
41
- throw new ArcError(GAME_UNAVAILABLE, gameUndeletable(id), {
41
+ throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
42
42
  cause: err,
43
43
  });
44
44
  }
@@ -3,7 +3,7 @@ import { auth, postUpload } from "../../api.js";
3
3
  import { DEPLOY_RATE_LIMITED, GAME_UNAVAILABLE } from "../../config/code.js";
4
4
  import { ArcError } from "../../util/error.js";
5
5
  import { releasing } from "../predeploy/game.js";
6
- import { HttpError } from "../../util/http.js";
6
+ import { isRefused } from "../game.js";
7
7
  import { deployRateLimited, gameUnavailable } from "../../phrase/index.js";
8
8
  import { published } from "../../util/links.js";
9
9
  import { upload as s3Upload } from "../../util/s3.js";
@@ -18,13 +18,14 @@ function uploadBuild(current, artifact, { id, version }, onProgress) {
18
18
  form.append("size", String(artifact.size));
19
19
  return postUpload(form, null, auth(current?.session.access_token)).then((upload) => s3Upload(upload.upload_url, artifact, onProgress).then(() => upload), (err) => {
20
20
  // the API refuses a game that was deleted or is another account's
21
- // (403), and the same version deployed again within 5 minutes (429).
22
- if (err instanceof HttpError && err.status === 403) {
21
+ // (403), and the same version deployed again within 5 minutes (429),
22
+ // each by its code.
23
+ if (isRefused(err, GAME_UNAVAILABLE, 403)) {
23
24
  throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
24
25
  cause: err,
25
26
  });
26
27
  }
27
- if (err instanceof HttpError && err.status === 429) {
28
+ if (isRefused(err, DEPLOY_RATE_LIMITED, 429)) {
28
29
  throw new ArcError(DEPLOY_RATE_LIMITED, deployRateLimited(version), {
29
30
  cause: err,
30
31
  });
@@ -3,10 +3,10 @@
3
3
  // too, and so can its allowance, spent: a pause has a reason, and an owner
4
4
  // lifts only their own.
5
5
  import { deleteGameFunctionPause, discoverGameBuilds, gameFunctionPauses, gameFunctionUsages, putGameFunctionPause, } from "../../api.js";
6
- import { API_REFUSED, GAME_UNAVAILABLE } from "../../config/code.js";
6
+ import { FUNCTION_PAUSE_RESERVED, GAME_UNAVAILABLE, } from "../../config/code.js";
7
7
  import { ArcError } from "../../util/error.js";
8
8
  import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, } from "../game.js";
9
- import { functionNotPaused, gameUnavailable } from "../../phrase/index.js";
9
+ import { functionPauseReserved, gameNotOwned } from "../../phrase/index.js";
10
10
  // [declare]
11
11
  // the reasons a function is paused for, the one that holds longest first:
12
12
  // what a status says when there's more than one.
@@ -57,7 +57,7 @@ export async function pause(current, { channel, ...conf }) {
57
57
  }
58
58
  catch (err) {
59
59
  if (isStatus(err, 404)) {
60
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
60
+ throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
61
61
  cause: err,
62
62
  });
63
63
  }
@@ -66,9 +66,10 @@ export async function pause(current, { channel, ...conf }) {
66
66
  }
67
67
  // [function]
68
68
  // resumes the game's function on a channel: lifts its owner's pause, and
69
- // resolves with `{ channel, paused }`, `paused` the reason it's still paused
70
- // for, or null. With no pause of the owner's to lift, it says why: one that
71
- // is Arcadible's or its allowance's isn't theirs to lift.
69
+ // resolves with `{ channel, lifted, paused }`, `paused` the reason it's
70
+ // still paused for, or null. One that isn't paused stays as it was, as `pause` leaves one
71
+ // that's paused already. A pause of Arcadible's, or its allowance's, isn't
72
+ // its owner's to lift: function_pause_reserved, saying who lifts it.
72
73
  export async function resume(current, { channel, ...conf }) {
73
74
  const where = needOf(channel);
74
75
  const id = await gameOf(conf);
@@ -84,10 +85,10 @@ export async function resume(current, { channel, ...conf }) {
84
85
  lifted = false;
85
86
  }
86
87
  const paused = pausedOf(await gameFunctionPauses(id, null, headers), where);
87
- if (!lifted) {
88
- throw new ArcError(API_REFUSED, functionNotPaused({ channel: where, paused }));
88
+ if (!lifted && paused) {
89
+ throw new ArcError(FUNCTION_PAUSE_RESERVED, functionPauseReserved({ channel: where, paused }));
89
90
  }
90
- return { channel: where, paused };
91
+ return { channel: where, lifted, paused };
91
92
  }
92
93
  // [function]
93
94
  // the game's function on each channel, or on one: `{ channel, function,
@@ -3,7 +3,7 @@
3
3
  // command names, the session's headers, and telling the API's refusals
4
4
  // apart.
5
5
  import { auth } from "../api.js";
6
- import { ARGUMENT_INVALID, GAME_ID_MISSING, NOT_LOGGED_IN, } from "../config/code.js";
6
+ import { ALL, ARGUMENT_INVALID, GAME_ID_MISSING, NOT_LOGGED_IN, } from "../config/code.js";
7
7
  import { ArcError } from "../util/error.js";
8
8
  import { given } from "../parser/given.js";
9
9
  import { HttpError } from "../util/http.js";
@@ -60,3 +60,14 @@ export function headersOf(current) {
60
60
  export function isStatus(err, status) {
61
61
  return err instanceof HttpError && err.status === status;
62
62
  }
63
+ // [function]
64
+ // whether a failure is the API's refusal with this code, which the
65
+ // database names (ERRORS.md): read first, and, from an API that doesn't say
66
+ // one, its status.
67
+ export function isRefused(err, code, status) {
68
+ if (!(err instanceof HttpError))
69
+ return false;
70
+ if (err.code === code)
71
+ return true;
72
+ return (err.status === status && (err.code === undefined || !ALL.has(err.code)));
73
+ }
@@ -2,10 +2,10 @@
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 { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
5
+ import { ARGUMENT_INVALID, GAME_UNAVAILABLE, KEY_LIMIT_REACHED, KEY_NOT_FOUND, } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
- import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
8
- import { gameUnavailable, keyLimitReached, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
7
+ import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
8
+ import { gameNotOwned, keyLimitReached, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
9
9
  // [declare]
10
10
  const NAME_MAX = 64;
11
11
  // the name a key gets when none is given.
@@ -36,12 +36,12 @@ export async function create(current, { channel, name, ...conf }) {
36
36
  }
37
37
  catch (err) {
38
38
  if (isStatus(err, 404)) {
39
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
39
+ throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
40
40
  cause: err,
41
41
  });
42
42
  }
43
- if (isStatus(err, 409)) {
44
- throw new ArcError(API_REFUSED, keyLimitReached(where), {
43
+ if (isRefused(err, KEY_LIMIT_REACHED, 409)) {
44
+ throw new ArcError(KEY_LIMIT_REACHED, keyLimitReached(where), {
45
45
  cause: err,
46
46
  });
47
47
  }
@@ -79,7 +79,7 @@ export async function revoke(current, { id, ...conf }) {
79
79
  }
80
80
  catch (err) {
81
81
  if (isStatus(err, 404) || isStatus(err, 400)) {
82
- throw new ArcError(API_REFUSED, keyNotFound(id), {
82
+ throw new ArcError(KEY_NOT_FOUND, keyNotFound(id), {
83
83
  cause: err,
84
84
  });
85
85
  }
@@ -3,10 +3,10 @@
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
- import { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
6
+ import { ARGUMENT_INVALID, GAME_UNAVAILABLE, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, } from "../../config/code.js";
7
7
  import { ArcError } from "../../util/error.js";
8
- import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
9
- import { gameUnavailable, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
8
+ import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
9
+ import { gameNotOwned, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
10
10
  // [declare]
11
11
  // a secret's name, as an environment variable is named; ARCADIBLE_ is kept
12
12
  // for Arcadible's own.
@@ -42,12 +42,12 @@ export async function set(current, { channel, name, value, ...conf }) {
42
42
  }
43
43
  catch (err) {
44
44
  if (isStatus(err, 404)) {
45
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
45
+ throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
46
46
  cause: err,
47
47
  });
48
48
  }
49
- if (isStatus(err, 409)) {
50
- throw new ArcError(API_REFUSED, secretLimitReached(where), {
49
+ if (isRefused(err, SECRET_LIMIT_REACHED, 409)) {
50
+ throw new ArcError(SECRET_LIMIT_REACHED, secretLimitReached(where), {
51
51
  cause: err,
52
52
  });
53
53
  }
@@ -84,7 +84,7 @@ export async function remove(current, { channel, name, ...conf }) {
84
84
  }
85
85
  catch (err) {
86
86
  if (isStatus(err, 404)) {
87
- throw new ArcError(API_REFUSED, secretNotFound({ channel: where, name: named }), { cause: err });
87
+ throw new ArcError(SECRET_NOT_FOUND, secretNotFound({ channel: where, name: named }), { cause: err });
88
88
  }
89
89
  throw err;
90
90
  }
@@ -130,6 +130,7 @@ export async function serveTool(conf) {
130
130
  const { port, root, url } = conf;
131
131
  const handler = {
132
132
  onBuild() { },
133
+ onLink() { },
133
134
  onReload() { },
134
135
  onRemote() { },
135
136
  onRunnerError() { },
@@ -167,6 +168,7 @@ export async function serveTool(conf) {
167
168
  },
168
169
  // arc serve's own tickets, signed with a key kept beside the session
169
170
  keyFile: join(configDir(), "ticket-key.json"),
171
+ onLink: (url) => handler.onLink(url),
170
172
  onRemote: handler.onRemote,
171
173
  player,
172
174
  port,
@@ -204,6 +206,7 @@ export async function serveTool(conf) {
204
206
  server_origins: servers,
205
207
  }),
206
208
  ...(conf.host ? { hostFile: resolvePath(root, conf.host) } : {}),
209
+ wiresDrop: conf.wiresDrop ?? null,
207
210
  };
208
211
  // the runner's code, watched: a change runs the new code
209
212
  const watchRunner = function (served) {
@@ -6,10 +6,10 @@
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import { gameValuesList, gameValuesRead, gameValuesRemove, gameValuesWrite, gameValueCalls, gameValueUsages, } from "../../api.js";
9
- import { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
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 { gameUnavailable, valueDirEmpty, valueFileUnread, valueFull, valueKeyInvalid, valueNotFound, valueNotJson, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
12
+ import { gameNotOwned, valueDirEmpty, valueFileUnread, valueFull, 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;
@@ -101,12 +101,14 @@ function batches(items) {
101
101
  function refused(id, channel) {
102
102
  return (err) => {
103
103
  if (isStatus(err, 404)) {
104
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
104
+ throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
105
105
  cause: err,
106
106
  });
107
107
  }
108
108
  if (isStatus(err, 507)) {
109
- throw new ArcError(API_REFUSED, valueFull(channel), { cause: err });
109
+ throw new ArcError(VALUE_STORAGE_FULL, valueFull(channel), {
110
+ cause: err,
111
+ });
110
112
  }
111
113
  throw err;
112
114
  };
@@ -139,7 +141,7 @@ export async function set(current, { channel, dir, file, input, key, ...conf })
139
141
  if (isStatus(err, 413)) {
140
142
  // a batch is under what a call holds, so it's one value's own size
141
143
  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 ?? ""), {
144
+ throw new ArcError(VALUE_TOO_LARGE, valueTooLarge(largest?.key ?? ""), {
143
145
  cause: err,
144
146
  });
145
147
  }
@@ -158,7 +160,7 @@ export async function get(current, { channel, key, ...conf }) {
158
160
  const headers = headersOf(current);
159
161
  const [value] = await gameValuesRead(id, where, [named], headers).catch(refused(id, where));
160
162
  if (!value) {
161
- throw new ArcError(API_REFUSED, valueNotFound({ channel: where, key: named }));
163
+ throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
162
164
  }
163
165
  return { channel: where, ...value };
164
166
  }
@@ -193,7 +195,7 @@ export async function remove(current, { channel, key, ...conf }) {
193
195
  const headers = headersOf(current);
194
196
  const { removed } = await gameValuesRemove(id, where, [named], headers).catch(refused(id, where));
195
197
  if (removed === 0) {
196
- throw new ArcError(API_REFUSED, valueNotFound({ channel: where, key: named }));
198
+ throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
197
199
  }
198
200
  return { channel: where, keys: [named] };
199
201
  }
@@ -0,0 +1,36 @@
1
+ // arc wire: a game's wires (plan/SDKWIRES.md), live messages between its
2
+ // players. What its owner sees of them is their usage: wires keep nothing,
3
+ // and nothing about one is set from here.
4
+ import { gameWireUsages } from "../../api.js";
5
+ import { GAME_UNAVAILABLE } from "../../config/code.js";
6
+ import { ArcError } from "../../util/error.js";
7
+ import { channelOf, CHANNELS, gameOf, headersOf, } from "../game.js";
8
+ import { gameNotOwned } from "../../phrase/index.js";
9
+ // [function]
10
+ // what the game's wires carried on each channel, or on one: this month's,
11
+ // and today's of it.
12
+ export async function usage(current, { channel, ...conf }) {
13
+ const where = channelOf(channel);
14
+ const id = await gameOf(conf);
15
+ const rows = (await gameWireUsages(id, null, headersOf(current))) ?? [];
16
+ // its owner always reads today's row for each channel: no rows at all is
17
+ // a game that isn't the caller's
18
+ if (rows.length === 0) {
19
+ throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id));
20
+ }
21
+ const today = new Date().toISOString().slice(0, 10);
22
+ const sum = (of) => ({
23
+ connections: of.reduce((total, each) => total + Number(each.connections ?? 0), 0),
24
+ messages: of.reduce((total, each) => total + Number(each.messages ?? 0), 0),
25
+ });
26
+ return {
27
+ channels: CHANNELS.filter((each) => !where || each === where).map((each) => {
28
+ const own = rows.filter((row) => row.channel === each);
29
+ return {
30
+ channel: each,
31
+ month: sum(own),
32
+ today: sum(own.filter((row) => row.day === today)),
33
+ };
34
+ }),
35
+ };
36
+ }
package/dist/api.js CHANGED
@@ -105,6 +105,12 @@ const isValueCalls = shaped({
105
105
  writes: num,
106
106
  });
107
107
  const isPause = shaped({ channel: str, reason: str });
108
+ const isWireUsage = shaped({
109
+ channel: str,
110
+ connections: opt(nul(either(num, str))),
111
+ day: str,
112
+ messages: opt(nul(either(num, str))),
113
+ });
108
114
  const isUsage = shaped({
109
115
  allowance: either(num, str),
110
116
  channel: str,
@@ -300,6 +306,12 @@ export function gameFunctionUsages(id, params, headers) {
300
306
  return answer(listed(isUsage), "a function's usage", get(endpoint(pathOf `/games/${id}/function_usages`, params), headers));
301
307
  }
302
308
  // [function]
309
+ // the usage of the caller's own game's wires this month: a row a channel
310
+ // and a day.
311
+ export function gameWireUsages(id, params, headers) {
312
+ return answer(listed(isWireUsage), "a game's wires' usage", get(endpoint(pathOf `/games/${id}/wire_usages`, params), headers));
313
+ }
314
+ // [function]
303
315
  // pauses the function of the caller's own game on a channel.
304
316
  export function putGameFunctionPause(id, channel, params, headers) {
305
317
  return answer(isPause, "a pause", put(endpoint(pathOf `/games/${id}/function_pauses/${channel}`, params), null, headers));
@@ -41,6 +41,19 @@ function checkUrl(url) {
41
41
  return Promise.reject(new ArcError(ARGUMENT_INVALID, phrase.urlInvalid()));
42
42
  }
43
43
  // [function]
44
+ // the seconds --wires-drop names, or null without it; a failure for what
45
+ // isn't a time to wait.
46
+ function checkDrop(seconds) {
47
+ if (seconds === null || typeof seconds === "undefined") {
48
+ return Promise.resolve(null);
49
+ }
50
+ const drop = Number(seconds);
51
+ if (Number.isFinite(drop) && drop > 0 && drop <= 3600) {
52
+ return Promise.resolve(drop);
53
+ }
54
+ return Promise.reject(new ArcError(ARGUMENT_INVALID, phrase.wiresDropInvalid()));
55
+ }
56
+ // [function]
44
57
  // warns once for each of Arcadible's files that's a kept copy, or can't be
45
58
  // had, rather than on every request.
46
59
  function remoteWarnings({ quiet }) {
@@ -60,25 +73,25 @@ function remoteWarnings({ quiet }) {
60
73
  export default defineCommand({
61
74
  name: "serve",
62
75
  options: {
63
- port: {
76
+ "port": {
64
77
  alias: "p",
65
78
  default: PORT,
66
79
  describe: "Serve on this port",
67
80
  rc: true,
68
81
  type: "number",
69
82
  },
70
- build: {
83
+ "build": {
71
84
  default: true,
72
85
  describe: "Run the build command first",
73
86
  rc: true,
74
87
  type: "boolean",
75
88
  },
76
- url: {
89
+ "url": {
77
90
  describe: "Frame another server's page instead of deploy_dir",
78
91
  rc: true,
79
92
  type: "string",
80
93
  },
81
- open: {
94
+ "open": {
82
95
  alias: "o",
83
96
  default: false,
84
97
  describe: "Open the play page in a web browser",
@@ -88,12 +101,16 @@ export default defineCommand({
88
101
  // run the game for a logged-in player of this name, the same one each
89
102
  // run; without it, a guest. Left out of the help until tickets ship,
90
103
  // with the docs.
91
- player: { hidden: true, rc: true, type: "string" },
104
+ "player": { hidden: true, rc: true, type: "string" },
92
105
  // serve a play page's host built here, for working on the host itself;
93
106
  // without it, Arcadible's own. Left out of the help.
94
- host: { hidden: true, rc: true, type: "string" },
95
- quiet: QUIET,
96
- cwd: CWD,
107
+ "host": { hidden: true, rc: true, type: "string" },
108
+ // drop each wire's connection this many seconds after it comes on, to
109
+ // try a game's rejoin. Left out of the help until wires ship, with the
110
+ // docs.
111
+ "wires-drop": { hidden: true, rc: true, type: "number" },
112
+ "quiet": QUIET,
113
+ "cwd": CWD,
97
114
  },
98
115
  // resolves with nothing, so the process goes on serving until it's
99
116
  // stopped.
@@ -106,10 +123,16 @@ export default defineCommand({
106
123
  aborting.sw = sw;
107
124
  await checkPort(port);
108
125
  const url = await checkUrl(argv.url);
126
+ const wiresDrop = await checkDrop(argv["wires-drop"]);
109
127
  const served = await serveTool({
110
128
  build: argv.build,
111
129
  handler: {
112
130
  onBuild: () => sw.start(quiet),
131
+ onLink(url) {
132
+ if (!quiet) {
133
+ p(phrase.linkMade(url));
134
+ }
135
+ },
113
136
  onReload() {
114
137
  if (!quiet) {
115
138
  p(phrase.reloaded());
@@ -135,6 +158,7 @@ export default defineCommand({
135
158
  port,
136
159
  root,
137
160
  url,
161
+ wiresDrop,
138
162
  });
139
163
  sw.stop(true);
140
164
  const stop = () => {
@@ -0,0 +1,14 @@
1
+ // arc wire: a game's wires (plan/SDKWIRES.md), live messages between its
2
+ // players, relayed and never kept. A game makes and joins them itself, so
3
+ // what's here is what they came to: their usage, by channel. Left out of
4
+ // `arc --help` until wires ship, with the docs.
5
+ // [import]
6
+ import { defineCommand } from "../../cli/command.js";
7
+ import usage from "./usage.js";
8
+ // [export]
9
+ export default defineCommand({
10
+ commands: [usage],
11
+ hidden: true,
12
+ name: "wire",
13
+ summary: "Show what the game's wires carried",
14
+ });
@@ -0,0 +1,43 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { p } from "../../util/log.js";
4
+ import { CHANNEL_SHOWS, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
5
+ import { run } from "../function/run.js";
6
+ import { table } from "../../util/table.js";
7
+ import { usage } from "../../action/wire/tool.js";
8
+ // [function]
9
+ // a count as it's read: 1,000,000.
10
+ function count(value) {
11
+ return value.toLocaleString("en-US");
12
+ }
13
+ // [function]
14
+ // each channel's wires as a table, a row each: today's, then the month's.
15
+ function rows(channels) {
16
+ return table([
17
+ [
18
+ "CHANNEL",
19
+ "MESSAGES TODAY",
20
+ "CONNECTIONS TODAY",
21
+ "MESSAGES THIS MONTH",
22
+ "CONNECTIONS THIS MONTH",
23
+ ],
24
+ ...channels.map((each) => [
25
+ each.channel,
26
+ count(each.today.messages),
27
+ count(each.today.connections),
28
+ count(each.month.messages),
29
+ count(each.month.connections),
30
+ ]),
31
+ ]);
32
+ }
33
+ // [export]
34
+ export default defineCommand({
35
+ name: "usage",
36
+ options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
37
+ run(argv, aborting) {
38
+ return run(argv, aborting, usage, ({ channels }) => {
39
+ p(rows(channels));
40
+ });
41
+ },
42
+ summary: "Show what the game's wires carried today and this month",
43
+ });
package/dist/commands.js CHANGED
@@ -77,7 +77,7 @@ export const COMMANDS = [
77
77
  name: "logout",
78
78
  summary: `Log out of ${title}`,
79
79
  },
80
- // left out of `arc --help` until functions, keys, and values ship, with the
80
+ // left out of `arc --help` until functions, keys, values, and wires ship, with the
81
81
  // docs.
82
82
  {
83
83
  hidden: true,
@@ -97,4 +97,10 @@ export const COMMANDS = [
97
97
  name: "value",
98
98
  summary: "Set, get, list, and remove the values you publish for the game",
99
99
  },
100
+ {
101
+ hidden: true,
102
+ load: () => import("./command/wire/index.js"),
103
+ name: "wire",
104
+ summary: "Show what the game's wires carried",
105
+ },
100
106
  ];
@@ -11,6 +11,7 @@ const CLI = {
11
11
  BUILD_FAILED: "build_failed",
12
12
  DEPLOY_DIR_MISSING: "deploy_dir_missing",
13
13
  DEPLOY_RATE_LIMITED: "deploy_rate_limited",
14
+ FUNCTION_PAUSE_RESERVED: "function_pause_reserved",
14
15
  GAME_HANDLE_TAKEN: "game_handle_taken",
15
16
  GAME_ID_MISSING: "game_id_missing",
16
17
  GAME_NOT_DEPLOYED: "game_not_deployed",
@@ -22,6 +23,8 @@ const CLI = {
22
23
  GIT_TAG_EXISTS: "git_tag_exists",
23
24
  GIT_TAG_PUSH_FAILED: "git_tag_push_failed",
24
25
  GIT_UNCOMMITTED: "git_uncommitted",
26
+ KEY_LIMIT_REACHED: "key_limit_reached",
27
+ KEY_NOT_FOUND: "key_not_found",
25
28
  LOCKFILE_MISSING: "lockfile_missing",
26
29
  LOGIN_CODE_EXPIRED: "login_code_expired",
27
30
  LOGIN_FAILED: "login_failed",
@@ -37,19 +40,28 @@ const CLI = {
37
40
  PATH_NOT_FOUND: "path_not_found",
38
41
  PORT_IN_USE: "port_in_use",
39
42
  PROJECT_NOT_REPO_ROOT: "project_not_repo_root",
43
+ SECRET_LIMIT_REACHED: "secret_limit_reached",
44
+ SECRET_NOT_FOUND: "secret_not_found",
40
45
  SESSION_EXPIRED: "session_expired",
41
46
  TEMPLATE_MISSING: "template_missing",
42
47
  TEMPLATE_UNAVAILABLE: "template_unavailable",
48
+ UNEXPECTED: "unexpected",
43
49
  UPLOAD_FAILED: "upload_failed",
44
50
  VALIDATION_FAILED: "validation_failed",
51
+ VALUE_NOT_FOUND: "value_not_found",
52
+ VALUE_STORAGE_FULL: "value_storage_full",
53
+ VALUE_TOO_LARGE: "value_too_large",
45
54
  WAIT_TIMED_OUT: "wait_timed_out",
46
55
  };
47
56
  // a release's reasons, from the pipeline (the API's
48
57
  // db/type/release_reason.sql). The CLI shares them, so a name means the same
49
- // thing wherever it appears: GAME_HANDLE_CHANGED, GAME_UNAVAILABLE, INTERNAL,
50
- // as well as REPO_NOT_CONNECTED and VERSION_EXISTS, are the CLI's too.
58
+ // thing wherever it appears: FUNCTION_TOO_LARGE, GAME_HANDLE_CHANGED,
59
+ // GAME_UNAVAILABLE, INTERNAL, as well as REPO_NOT_CONNECTED and
60
+ // VERSION_EXISTS, are the CLI's too.
51
61
  export const RELEASE = {
52
62
  BUILD_RATE_LIMITED: "build_rate_limited",
63
+ FUNCTION_INVALID: "function_invalid",
64
+ FUNCTION_TOO_LARGE: "function_too_large",
53
65
  GAME_HANDLE_CHANGED: "game_handle_changed",
54
66
  GAME_LIMIT_REACHED: "game_limit_reached",
55
67
  GAME_MISMATCH: "game_mismatch",
@@ -124,6 +136,6 @@ export const ISSUES = new Set(Object.values(ISSUE));
124
136
  export const WARNINGS = new Set(Object.values(WARNING));
125
137
  // [declare]
126
138
  // each error code by its own name too: `cfgcode.NOT_LOGGED_IN`.
127
- export const { API_REFUSED, API_UNREACHABLE, ARGUMENT_INVALID, BUILD_FAILED, DEPLOY_DIR_MISSING, DEPLOY_RATE_LIMITED, GAME_HANDLE_TAKEN, GAME_ID_MISSING, GAME_NOT_DEPLOYED, GAME_NOT_FOUND, GIT_REMOTE_MISSING, GIT_REMOTE_UNREACHABLE, GIT_REPO_MISSING, GIT_TAG_CREATE_FAILED, GIT_TAG_EXISTS, GIT_TAG_PUSH_FAILED, GIT_UNCOMMITTED, LOCKFILE_MISSING, LOGIN_CODE_EXPIRED, LOGIN_FAILED, MANIFEST_MISSING, NOT_LOGGED_IN, PACKAGE_FILE_TOO_LARGE, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, PARSE_FAILED, PATH_NOT_FOUND, PORT_IN_USE, PROJECT_NOT_REPO_ROOT, SESSION_EXPIRED, TEMPLATE_MISSING, TEMPLATE_UNAVAILABLE, UPLOAD_FAILED, VALIDATION_FAILED, WAIT_TIMED_OUT, } = CLI;
128
- export const { BUILD_RATE_LIMITED, GAME_HANDLE_CHANGED, GAME_LIMIT_REACHED, GAME_MISMATCH, GAME_UNAVAILABLE, GITHUB_APP_NOT_INSTALLED, INTERNAL, MANIFEST_INVALID, RELEASE_EXPIRED, REPO_NOT_CONNECTED, VERSION_EXISTS, VERSION_MISMATCH, ZIP_INVALID, ZIP_MISSING, ZIP_TOO_LARGE, } = RELEASE;
139
+ export const { API_REFUSED, API_UNREACHABLE, ARGUMENT_INVALID, BUILD_FAILED, DEPLOY_DIR_MISSING, DEPLOY_RATE_LIMITED, FUNCTION_PAUSE_RESERVED, GAME_HANDLE_TAKEN, GAME_ID_MISSING, GAME_NOT_DEPLOYED, GAME_NOT_FOUND, GIT_REMOTE_MISSING, GIT_REMOTE_UNREACHABLE, GIT_REPO_MISSING, GIT_TAG_CREATE_FAILED, GIT_TAG_EXISTS, GIT_TAG_PUSH_FAILED, GIT_UNCOMMITTED, KEY_LIMIT_REACHED, KEY_NOT_FOUND, LOCKFILE_MISSING, LOGIN_CODE_EXPIRED, LOGIN_FAILED, MANIFEST_MISSING, NOT_LOGGED_IN, PACKAGE_FILE_TOO_LARGE, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, PARSE_FAILED, PATH_NOT_FOUND, PORT_IN_USE, PROJECT_NOT_REPO_ROOT, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, SESSION_EXPIRED, TEMPLATE_MISSING, TEMPLATE_UNAVAILABLE, UNEXPECTED, UPLOAD_FAILED, VALIDATION_FAILED, VALUE_NOT_FOUND, VALUE_STORAGE_FULL, VALUE_TOO_LARGE, WAIT_TIMED_OUT, } = CLI;
140
+ export const { BUILD_RATE_LIMITED, FUNCTION_INVALID, FUNCTION_TOO_LARGE, GAME_HANDLE_CHANGED, GAME_LIMIT_REACHED, GAME_MISMATCH, GAME_UNAVAILABLE, GITHUB_APP_NOT_INSTALLED, INTERNAL, MANIFEST_INVALID, RELEASE_EXPIRED, REPO_NOT_CONNECTED, VERSION_EXISTS, VERSION_MISMATCH, ZIP_INVALID, ZIP_MISSING, ZIP_TOO_LARGE, } = RELEASE;
129
141
  export const { GIT_TAG_INVALID, WORKFLOW_MISSING } = GITHUB;
@@ -12,3 +12,5 @@ export const FILE_SIZE = 64 * MB;
12
12
  export const TOTAL_SIZE = 256 * MB;
13
13
  // the zip of deploy_dir alone, compressed.
14
14
  export const ZIP_SIZE = 64 * MB;
15
+ // a function's bundle, as Arcadible runs it (the subscriber's RUNNER_MAX).
16
+ export const FUNCTION_SIZE = 1 * MB;
@@ -44,7 +44,10 @@ export function functionState({ function: has, paused, }) {
44
44
  }
45
45
  // [function]
46
46
  // a resumed function, with any pause that isn't its owner's still on it.
47
- export function functionResumed({ channel, paused, }) {
47
+ export function functionResumed({ channel, lifted, paused, }) {
48
+ if (!lifted) {
49
+ return `The game's function isn't paused on ${channel}.`;
50
+ }
48
51
  if (paused) {
49
52
  return blocks(`Lifted your pause on ${channel}.`, `The game's function stays paused: ${functionPause(paused)}.`);
50
53
  }
@@ -58,15 +61,16 @@ export function functionMonth({ allowance, requests, }) {
58
61
  : `${requests} of ${allowance} requests this month, both channels together.`;
59
62
  }
60
63
  // [function]
61
- // a resume with no pause of the owner's to lift: one of another's, or none.
62
- export function functionNotPaused({ channel, paused, }) {
64
+ // a resume with no pause of the owner's to lift, and one of another's: who
65
+ // lifts it.
66
+ export function functionPauseReserved({ channel, paused, }) {
63
67
  if (paused === "arcadible") {
64
68
  return blocks(`The game's function is paused by Arcadible on ${channel}.`, "Only Arcadible can resume it.");
65
69
  }
66
70
  if (paused === "limit") {
67
71
  return blocks(`The game's function has spent its allowance on ${channel}.`, "It resumes by itself when the allowance renews.");
68
72
  }
69
- return `The game's function isn't paused on ${channel}.`;
73
+ return `The game's function is paused on ${channel}, and not by you.`;
70
74
  }
71
75
  // [function]
72
76
  export function secretSet({ channel, name, }) {
@@ -122,6 +126,11 @@ export function runnerBuildFailed(message) {
122
126
  return `The function didn't build:\n${message}`;
123
127
  }
124
128
  // [function]
129
+ // a function's bundle past what Arcadible runs.
130
+ export function functionTooLarge(size) {
131
+ return blocks(`The function's bundle is ${Math.ceil(size / 1024).toLocaleString("en-US")} KB, over 1 MB.`, "Import less into it: keep large data out of its code, in values or the game's files.");
132
+ }
133
+ // [function]
125
134
  // a package asked for before the runner it carries was built.
126
135
  export function runnerNotBuilt() {
127
136
  return blocks("The function isn't built.", "Run `arc build` first.");
@@ -20,8 +20,10 @@ export function gameDeletedProject() {
20
20
  ];
21
21
  }
22
22
  // [function]
23
- // a game the API won't delete: to anyone but its owner, one that isn't on
24
- // Arcadible, one that's deleted already, and another account's are the same.
25
- export function gameUndeletable(id) {
23
+ // a game the API won't let its owner's commands reach (delete it, its
24
+ // values, keys, secrets, function, and wires): to anyone but its owner, one
25
+ // that isn't on Arcadible, one that's deleted already, and another account's
26
+ // are the same.
27
+ export function gameNotOwned(id) {
26
28
  return blocks(`Game unavailable: ${id}\nIt was never deployed, was deleted, or belongs to another account.`, `${cmdWhoami()} shows the account you're logged in to.`);
27
29
  }