arcadible 1.0.50 → 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.
@@ -98,28 +98,41 @@ export async function resume(current, { channel, ...conf }) {
98
98
  return { channel: where, lifted, paused };
99
99
  }
100
100
  // [function]
101
- // the game's function on each channel, or on one: `{ channel, function,
102
- // paused, requests }`, `function` whether the channel's live build has one
103
- // (a pause and a usage are the channel's, so neither says), `paused` the
104
- // reason it's paused for, or null for none, `requests` what it answered
105
- // this month, and `cpu_ms` its CPU time. With them, what holds it, whichever channels were asked for:
106
- // the game's day against its own limit, its month, and its account's pool
107
- // 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).
108
103
  export async function status(current, { channel, ...conf }) {
109
104
  const where = channelOf(channel);
110
105
  const id = await gameOf(conf);
111
106
  const headers = headersOf(current);
112
- const [pauses, usages] = await Promise.all([
113
- ownedRead(id, gameFunctionPauses(id, null, headers)),
114
- ownedRead(id, gameFunctionUsages(id, null, headers)),
115
- ]);
107
+ const pauses = await ownedRead(id, gameFunctionPauses(id, null, headers));
116
108
  const shown = CHANNELS.filter((each) => !where || each === where);
117
109
  // asked once the game is known to be the caller's, so another account's
118
110
  // game is refused before anything else is asked about it.
119
111
  const has = await Promise.all(shown.map((each) => hasFunction(id, each)));
120
- 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))) ?? [];
121
130
  const [first] = rows;
122
- 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
+ });
123
136
  // null is no limit, and stays null
124
137
  const limit = (value) => value === null ? null : Number(value);
125
138
  return {
@@ -130,15 +143,12 @@ export async function status(current, { channel, ...conf }) {
130
143
  requests: Number(first.pool_used),
131
144
  }
132
145
  : null,
133
- channels: shown.map((each, i) => {
146
+ channels: CHANNELS.filter((each) => !where || each === where).map((each) => {
134
147
  const own = rows.filter((row) => row.channel === each);
135
148
  return {
136
149
  channel: each,
137
- cpu_ms: sum(own, "cpu_ms"),
138
- function: has[i] ?? null,
139
- paused: pausedOf(pauses, each),
140
- requests: sum(own, "requests"),
141
- resumes_at: resumesOf(pauses, each),
150
+ month: counts(own),
151
+ today: counts(own.filter((row) => row.day === today)),
142
152
  };
143
153
  }),
144
154
  month: first
@@ -148,7 +158,11 @@ export async function status(current, { channel, ...conf }) {
148
158
  }
149
159
  : null,
150
160
  today: first
151
- ? { allowance: limit(first.allowance), requests: Number(first.used) }
161
+ ? {
162
+ allowance: limit(first.allowance),
163
+ cpu_ms: counts(rows.filter((row) => row.day === today)).cpu_ms,
164
+ requests: Number(first.used),
165
+ }
152
166
  : null,
153
167
  };
154
168
  }
@@ -9,7 +9,7 @@ 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";
12
+ import { CHANNELS, channelOf, gameOf, headersOf, isRefused, needOf, REFUSED, } from "../game.js";
13
13
  import { DEVELOPER_DIR } from "../../serve/values.js";
14
14
  import { iso } from "../../util/time.js";
15
15
  import { gameNotOwned, valueCallsSpent, valueDirEmpty, valueFileUnread, valueFull, valueHolds, valueKeyInvalid, valueNotFound, valueNotJson, valueSetTwice, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
@@ -243,26 +243,34 @@ export async function remove(current, { channel, key, ...conf }) {
243
243
  return { channel: where, keys: [named] };
244
244
  }
245
245
  // [function]
246
- // what each scope of the game's values holds on a channel, against what it
247
- // may: the developer's, the game's, its players', and its server's. And the
248
- // calls the game's clients made today on that channel, with the game's
249
- // day, its month, and its account's pool, as the API states them; null when they
250
- // 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.
251
252
  export async function usage(current, { channel, ...conf }) {
252
- const where = needOf(channel);
253
+ const where = channelOf(channel);
253
254
  const id = await gameOf(conf);
254
255
  const headers = headersOf(current);
255
- const scopes = (await gameValueUsages(id, where, headers).catch(refused(id, where, headers))) ?? [];
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))) ?? []));
256
258
  const all = await gameValueCalls(id, headers).catch(() => null);
257
- const calls = all?.find((each) => each.channel === where) ?? null;
259
+ const calls = all?.[0] ?? null;
260
+ const own = (each) => all?.find((row) => row.channel === each);
258
261
  return {
259
262
  account: calls
260
263
  ? { allowance: calls.pool_allowance, calls: calls.pool_used }
261
264
  : null,
262
- channel: where,
263
- channel_today: calls ? { reads: calls.reads, writes: calls.writes } : 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
+ }),
264
273
  month: calls ? { calls: calls.month_used } : null,
265
- scopes: scopes.map(scopeOf),
266
274
  today: calls ? { allowance: calls.allowance, calls: calls.used } : null,
267
275
  };
268
276
  }
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)),
@@ -7,10 +7,11 @@ import secret from "./secret/index.js";
7
7
  import pause from "./pause.js";
8
8
  import resume from "./resume.js";
9
9
  import status from "./status.js";
10
+ import usage from "./usage.js";
10
11
  import logs from "./logs.js";
11
12
  // [export]
12
13
  export default defineCommand({
13
- commands: [pause, resume, status, logs, secret],
14
+ commands: [pause, resume, status, usage, logs, secret],
14
15
  name: "function",
15
16
  summary: "Pause, resume, and show the game's function, its logs, and its secrets",
16
17
  });
@@ -1,28 +1,18 @@
1
1
  // [import]
2
2
  import { defineCommand } from "../../cli/command.js";
3
- import { cpuTime, functionState, functionUsage } from "../../phrase/index.js";
4
- import { nlp, p } from "../../util/log.js";
3
+ import { functionState } from "../../phrase/index.js";
4
+ import { p } from "../../util/log.js";
5
5
  import { CHANNEL_SHOWS, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
6
6
  import { run } from "./run.js";
7
7
  import { table } from "../../util/table.js";
8
8
  import { status } from "../../action/function/tool.js";
9
9
  // [function]
10
- // a count as it's read: 1,000,000.
11
- function count(value) {
12
- return value.toLocaleString("en-US");
13
- }
14
- // [function]
15
- // each channel's function as a table, a row each: its requests and CPU
16
- // time this month.
10
+ // each channel's function as a table, a row each: running, or why it's
11
+ // paused and until when. Its numbers are `arc function usage`'s.
17
12
  function rows(channels) {
18
13
  return table([
19
- ["CHANNEL", "STATUS", "REQUESTS", "CPU"],
20
- ...channels.map((each) => [
21
- each.channel,
22
- functionState(each),
23
- count(each.requests),
24
- cpuTime(each.cpu_ms),
25
- ]),
14
+ ["CHANNEL", "STATUS"],
15
+ ...channels.map((each) => [each.channel, functionState(each)]),
26
16
  ]);
27
17
  }
28
18
  // [export]
@@ -30,28 +20,9 @@ export default defineCommand({
30
20
  name: "status",
31
21
  options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
32
22
  run(argv, aborting) {
33
- return run(argv, aborting, status, ({ account, channels, month, today }) => {
23
+ return run(argv, aborting, status, ({ channels }) => {
34
24
  p(rows(channels));
35
- // nothing to say of its limits when its usage couldn't be read
36
- if (today && month && account) {
37
- const limit = (value) => value === null ? null : count(value);
38
- nlp(functionUsage({
39
- account: {
40
- allowance: limit(account.allowance),
41
- cpu: cpuTime(account.cpu_ms),
42
- requests: count(account.requests),
43
- },
44
- month: {
45
- cpu: cpuTime(month.cpu_ms),
46
- requests: count(month.requests),
47
- },
48
- today: {
49
- allowance: limit(today.allowance),
50
- requests: count(today.requests),
51
- },
52
- }));
53
- }
54
25
  });
55
26
  },
56
- summary: "Show whether the game's function is running, and its usage against its limits",
27
+ summary: "Show whether the game's function is running, on each channel",
57
28
  });
@@ -0,0 +1,64 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { cpuTime, functionUsage } from "../../phrase/index.js";
4
+ import { nlp, p } from "../../util/log.js";
5
+ import { CHANNEL_SHOWS, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
6
+ import { run } from "./run.js";
7
+ import { table } from "../../util/table.js";
8
+ import { usage } from "../../action/function/tool.js";
9
+ // [function]
10
+ // a count as it's read: 1,000,000.
11
+ function count(value) {
12
+ return value.toLocaleString("en-US");
13
+ }
14
+ // [function]
15
+ // each channel's own as a table, a row each: its requests and CPU time
16
+ // today and this month.
17
+ function rows(channels) {
18
+ return table([
19
+ [
20
+ "CHANNEL",
21
+ "REQUESTS TODAY",
22
+ "CPU TODAY",
23
+ "REQUESTS THIS MONTH",
24
+ "CPU THIS MONTH",
25
+ ],
26
+ ...channels.map((each) => [
27
+ each.channel,
28
+ count(each.today.requests),
29
+ cpuTime(each.today.cpu_ms),
30
+ count(each.month.requests),
31
+ cpuTime(each.month.cpu_ms),
32
+ ]),
33
+ ]);
34
+ }
35
+ // [export]
36
+ export default defineCommand({
37
+ name: "usage",
38
+ options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
39
+ run(argv, aborting) {
40
+ return run(argv, aborting, usage, ({ account, channels, month, today }) => {
41
+ p(rows(channels));
42
+ // nothing to say of its limits when its usage couldn't be read
43
+ if (today && month && account) {
44
+ const limit = (value) => value === null ? null : count(value);
45
+ nlp(functionUsage({
46
+ account: {
47
+ allowance: limit(account.allowance),
48
+ cpu: cpuTime(account.cpu_ms),
49
+ requests: count(account.requests),
50
+ },
51
+ month: {
52
+ cpu: cpuTime(month.cpu_ms),
53
+ requests: count(month.requests),
54
+ },
55
+ today: {
56
+ allowance: limit(today.allowance),
57
+ requests: count(today.requests),
58
+ },
59
+ }));
60
+ }
61
+ });
62
+ },
63
+ summary: "Show what the game's function answered, today and this month, against its limits",
64
+ });
@@ -1,7 +1,7 @@
1
1
  // [import]
2
2
  import { defineCommand } from "../../cli/command.js";
3
3
  import { nlp, p } from "../../util/log.js";
4
- import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
4
+ import { CHANNEL_SHOWS, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
5
5
  import { run } from "../function/secret/run.js";
6
6
  import { table } from "../../util/table.js";
7
7
  import { valueHolds, valueSize } from "../../phrase/index.js";
@@ -12,16 +12,17 @@ function count(value) {
12
12
  return value.toLocaleString("en-US");
13
13
  }
14
14
  // [function]
15
- // the scopes as a table, each by its own name. A player's row counts every
16
- // player's together, and its limit is what each may hold, so the most any
17
- // one holds is beside it.
18
- function rows(scopes) {
15
+ // each channel's scopes as a table, a row a scope, each by its own name. A
16
+ // player's row counts every player's together, and its limit is what each
17
+ // may hold, so the most any one holds is beside it.
18
+ function rows(channels) {
19
19
  return table([
20
- ["SCOPE", "KEYS", "SIZE", "MAY HOLD"],
21
- ...scopes.map((each) => {
20
+ ["CHANNEL", "SCOPE", "KEYS", "SIZE", "MAY HOLD"],
21
+ ...channels.flatMap(({ channel, scopes }) => scopes.map((each) => {
22
22
  const players = each.scope === "player";
23
23
  const limit = valueHolds(each.limit);
24
24
  return [
25
+ channel,
25
26
  each.scope,
26
27
  players
27
28
  ? `${count(each.keys)} (${count(each.owners)} ${each.owners === 1 ? "player" : "players"}, ${count(each.owner_max.keys)} at most)`
@@ -31,24 +32,26 @@ function rows(scopes) {
31
32
  : valueSize(each.bytes),
32
33
  players && limit !== "no limit" ? `${limit} each` : limit,
33
34
  ];
34
- }),
35
+ })),
35
36
  ]);
36
37
  }
37
38
  // [function]
38
- // the game's clients' calls: this channel's today, and the game's against
39
- // its own limit for a day, which both channels share and the day (UTC)
40
- // renews; then its month, and its account's, every game's together,
41
- // against its plan's: a figure a line, its account's under it. Each number
42
- // is the API's; null is no limit.
43
- function called({ account, channel, channel_today: mine, month, today, }) {
44
- if (!account || !mine || !month || !today) {
39
+ // the game's clients' calls: the game's today, both channels together,
40
+ // against its own limit for a day, which the day (UTC) renews, with each
41
+ // channel's reads and writes under it; then its month, and its account's,
42
+ // every game's together, against its plan's: a figure a line, what makes it
43
+ // up under it. Each number is the API's; null is no limit.
44
+ function called({ account, channels, month, today }) {
45
+ if (!account || !month || !today) {
45
46
  return null;
46
47
  }
47
48
  return [
48
- `Calls from the game today: ${count(mine.reads)} reads, ${count(mine.writes)} writes on ${channel}`,
49
49
  today.allowance === null
50
- ? ` Both channels together: ${count(today.calls)}, with no limit for a day`
51
- : ` Both channels together: ${count(today.calls)} of ${count(today.allowance)}`,
50
+ ? `${count(today.calls)} calls today, with no limit for a day`
51
+ : `${count(today.calls)} of ${count(today.allowance)} calls today, both channels together`,
52
+ ...channels.map(({ channel, today: own }) => own
53
+ ? ` ${channel}: ${count(own.reads)} reads, ${count(own.writes)} writes`
54
+ : ` ${channel}: none`),
52
55
  `${count(month.calls)} calls this month`,
53
56
  account.allowance === null
54
57
  ? ` Your account's games together: ${count(account.calls)}, with no limit`
@@ -58,15 +61,16 @@ function called({ account, channel, channel_today: mine, month, today, }) {
58
61
  // [export]
59
62
  export default defineCommand({
60
63
  name: "usage",
61
- options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
64
+ options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
62
65
  run(argv, aborting) {
66
+ // a reader: both channels unless one is named (cli:16a)
63
67
  return run(argv, aborting, usage, (used) => {
64
- p(rows(used.scopes));
68
+ p(rows(used.channels));
65
69
  const calls = called(used);
66
70
  if (calls) {
67
71
  nlp(calls);
68
72
  }
69
- }, "arc value usage");
73
+ });
70
74
  },
71
75
  summary: "Show how much the game's values hold, by scope",
72
76
  });
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "name": "arcadible",
45
- "version": "1.0.50"
45
+ "version": "1.0.51"
46
46
  },
47
47
  "node_modules/@cacheable/memory": {
48
48
  "dependencies": {
@@ -2433,5 +2433,5 @@
2433
2433
  }
2434
2434
  },
2435
2435
  "requires": true,
2436
- "version": "1.0.50"
2436
+ "version": "1.0.51"
2437
2437
  }
package/package.json CHANGED
@@ -68,5 +68,5 @@
68
68
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
69
69
  },
70
70
  "type": "module",
71
- "version": "1.0.50"
71
+ "version": "1.0.51"
72
72
  }