arcadible 1.0.34 → 1.0.36
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.
- package/dist/action/delete/tool.js +2 -2
- package/dist/action/deploy/tool.js +5 -4
- package/dist/action/function/logs.js +238 -0
- package/dist/action/function/tool.js +49 -24
- package/dist/action/game.js +12 -1
- package/dist/action/key/tool.js +7 -7
- package/dist/action/secret/tool.js +7 -7
- package/dist/action/serve/tool.js +2 -0
- package/dist/action/value/tool.js +11 -9
- package/dist/action/wire/tool.js +2 -2
- package/dist/api.js +30 -5
- package/dist/command/function/index.js +5 -4
- package/dist/command/function/logs.js +154 -0
- package/dist/command/function/status.js +26 -9
- package/dist/command/serve.js +5 -0
- package/dist/command/value/usage.js +15 -5
- package/dist/commands.js +1 -1
- package/dist/config/code.js +16 -4
- package/dist/config/limit.js +2 -0
- package/dist/phrase/function.js +80 -17
- package/dist/phrase/game.js +5 -3
- package/dist/phrase/serve.js +6 -0
- package/dist/runner/bundle.js +10 -2
- package/dist/runner/entry.js +59 -3
- package/dist/serve/page.js +25 -8
- package/dist/serve/runner.js +43 -16
- package/dist/serve/server.js +8 -4
- package/dist/serve/wires.js +10 -5
- package/dist/util/error.js +10 -7
- package/dist/util/http.js +6 -1
- package/dist/util/request.js +5 -3
- package/dist/wires/room.js +10 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -88,23 +88,35 @@ const isValueListed = shaped({
|
|
|
88
88
|
const isValueRemoved = shaped({ removed: num });
|
|
89
89
|
const isValueUsage = shaped({
|
|
90
90
|
bytes: num,
|
|
91
|
-
bytes_limit: num,
|
|
91
|
+
bytes_limit: nul(num),
|
|
92
92
|
bytes_most: num,
|
|
93
93
|
channel: str,
|
|
94
94
|
keys: num,
|
|
95
|
-
keys_limit: num,
|
|
95
|
+
keys_limit: nul(num),
|
|
96
96
|
keys_most: num,
|
|
97
97
|
owners: num,
|
|
98
98
|
scope: str,
|
|
99
99
|
});
|
|
100
100
|
const isValueCalls = shaped({
|
|
101
|
-
allowance: num,
|
|
101
|
+
allowance: nul(num),
|
|
102
102
|
channel: str,
|
|
103
|
+
month_used: num,
|
|
104
|
+
pool_allowance: nul(num),
|
|
105
|
+
pool_used: num,
|
|
103
106
|
reads: num,
|
|
104
107
|
used: num,
|
|
105
108
|
writes: num,
|
|
106
109
|
});
|
|
107
|
-
const
|
|
110
|
+
const isLogsToken = shaped({
|
|
111
|
+
expires_at: str,
|
|
112
|
+
token: str,
|
|
113
|
+
url: str,
|
|
114
|
+
});
|
|
115
|
+
const isPause = shaped({
|
|
116
|
+
channel: str,
|
|
117
|
+
reason: str,
|
|
118
|
+
resumes_at: opt(nul(str)),
|
|
119
|
+
});
|
|
108
120
|
const isWireUsage = shaped({
|
|
109
121
|
channel: str,
|
|
110
122
|
connections: opt(nul(either(num, str))),
|
|
@@ -112,9 +124,16 @@ const isWireUsage = shaped({
|
|
|
112
124
|
messages: opt(nul(either(num, str))),
|
|
113
125
|
});
|
|
114
126
|
const isUsage = shaped({
|
|
115
|
-
allowance: either(num, str),
|
|
127
|
+
allowance: nul(either(num, str)),
|
|
116
128
|
channel: str,
|
|
129
|
+
cpu_ms: opt(nul(either(num, str))),
|
|
130
|
+
month_cpu_ms: opt(nul(either(num, str))),
|
|
131
|
+
month_used: either(num, str),
|
|
132
|
+
pool_allowance: nul(either(num, str)),
|
|
133
|
+
pool_cpu_ms: opt(nul(either(num, str))),
|
|
134
|
+
pool_used: either(num, str),
|
|
117
135
|
requests: opt(nul(either(num, str))),
|
|
136
|
+
used: either(num, str),
|
|
118
137
|
});
|
|
119
138
|
// [function]
|
|
120
139
|
// the API's answer, checked as it arrives: `is` says whether it has the
|
|
@@ -306,6 +325,12 @@ export function gameFunctionUsages(id, params, headers) {
|
|
|
306
325
|
return answer(listed(isUsage), "a function's usage", get(endpoint(pathOf `/games/${id}/function_usages`, params), headers));
|
|
307
326
|
}
|
|
308
327
|
// [function]
|
|
328
|
+
// a token to read the caller's own game's function's logs, good for 10
|
|
329
|
+
// minutes.
|
|
330
|
+
export function postGameFunctionLogsToken(id, params, headers) {
|
|
331
|
+
return answer(isLogsToken, "a token for a function's logs", post(endpoint(pathOf `/games/${id}/function_logs/token`, params), null, headers));
|
|
332
|
+
}
|
|
333
|
+
// [function]
|
|
309
334
|
// the usage of the caller's own game's wires this month: a row a channel
|
|
310
335
|
// and a day.
|
|
311
336
|
export function gameWireUsages(id, params, headers) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// arc function: a game's function, the server code Arcadible runs for it:
|
|
2
|
-
// paused and resumed on a channel by the game's owner, with no release,
|
|
3
|
-
// its secrets (./secret/index.ts). All of it is left out of `arc --help`
|
|
2
|
+
// paused and resumed on a channel by the game's owner, with no release, its
|
|
3
|
+
// logs, and its secrets (./secret/index.ts). All of it is left out of `arc --help`
|
|
4
4
|
// until functions ship, with the docs.
|
|
5
5
|
// [import]
|
|
6
6
|
import { defineCommand } from "../../cli/command.js";
|
|
@@ -8,10 +8,11 @@ import secret from "./secret/index.js";
|
|
|
8
8
|
import pause from "./pause.js";
|
|
9
9
|
import resume from "./resume.js";
|
|
10
10
|
import status from "./status.js";
|
|
11
|
+
import logs from "./logs.js";
|
|
11
12
|
// [export]
|
|
12
13
|
export default defineCommand({
|
|
13
|
-
commands: [pause, resume, status, secret],
|
|
14
|
+
commands: [pause, resume, status, logs, secret],
|
|
14
15
|
hidden: true,
|
|
15
16
|
name: "function",
|
|
16
|
-
summary: "Pause, resume, and show the game's function, and its secrets",
|
|
17
|
+
summary: "Pause, resume, and show the game's function, its logs, and its secrets",
|
|
17
18
|
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// arc function logs: what the game's function said, as Arcadible keeps it,
|
|
2
|
+
// for its owner (plan/FUNCTION-LOGS.md, Reading them): the newest 100
|
|
3
|
+
// requests, oldest first, as `tail` prints, or those and then each as it
|
|
4
|
+
// comes, with `--follow`. With `--json`, an entry a line, as the logs
|
|
5
|
+
// Worker answers it, so a follow can be read as it goes (OUTPUT.md,
|
|
6
|
+
// Streams).
|
|
7
|
+
// [import]
|
|
8
|
+
import { resolve as resolvePath } from "node:path";
|
|
9
|
+
// [import]
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
// [import]
|
|
12
|
+
import { ended } from "../../account.js";
|
|
13
|
+
import { defineCommand } from "../../cli/command.js";
|
|
14
|
+
import { of } from "../../cli/channel.js";
|
|
15
|
+
import { CHANNEL_SHOWS, CWD, JSON_OUTPUT } from "../../cli/options.js";
|
|
16
|
+
import { cpuTime, functionLogsNone } from "../../phrase/index.js";
|
|
17
|
+
import { p } from "../../util/log.js";
|
|
18
|
+
import { deepSort } from "../../util/objs.js";
|
|
19
|
+
import { SpinnerWheel } from "../../util/spinner.js";
|
|
20
|
+
import { follow, logs, } from "../../action/function/logs.js";
|
|
21
|
+
import { whoami } from "../../action/whoami/tool.js";
|
|
22
|
+
// [function]
|
|
23
|
+
// a time as the logs show it, in UTC: to the millisecond, with its day
|
|
24
|
+
// when it isn't today's.
|
|
25
|
+
function timeOf(at, now = Date.now()) {
|
|
26
|
+
const iso = new Date(at).toISOString();
|
|
27
|
+
const day = iso.slice(0, 10);
|
|
28
|
+
const time = iso.slice(11, 23);
|
|
29
|
+
return day === new Date(now).toISOString().slice(0, 10)
|
|
30
|
+
? time
|
|
31
|
+
: `${day} ${time}`;
|
|
32
|
+
}
|
|
33
|
+
// [function]
|
|
34
|
+
// text under an entry's first line, indented, each of its lines.
|
|
35
|
+
function under(text, indent) {
|
|
36
|
+
return text
|
|
37
|
+
.split("\n")
|
|
38
|
+
.map((line) => `${indent}${line}`)
|
|
39
|
+
.join("\n");
|
|
40
|
+
}
|
|
41
|
+
// [function]
|
|
42
|
+
// an exception: its name and message, then its stack, which Cloudflare
|
|
43
|
+
// gives as its frames alone, and V8 with the name and message first.
|
|
44
|
+
function exceptionText({ message, name, stack, }) {
|
|
45
|
+
const head = `${name ?? "Error"}: ${message ?? ""}`;
|
|
46
|
+
if (!stack)
|
|
47
|
+
return head;
|
|
48
|
+
return stack.startsWith(head) ? stack : `${head}\n${stack}`;
|
|
49
|
+
}
|
|
50
|
+
// [function]
|
|
51
|
+
// an entry as it's read: its time, channel, build, request, answer, and CPU
|
|
52
|
+
// time on a line, then its lines and exceptions under it, those that are
|
|
53
|
+
// errors in yellow (OUTPUT.md keeps red for headings).
|
|
54
|
+
export function entryText(entry) {
|
|
55
|
+
const outcome = entry.outcome ?? "unknown";
|
|
56
|
+
const answer = entry.status == null
|
|
57
|
+
? outcome
|
|
58
|
+
: outcome === "ok"
|
|
59
|
+
? String(entry.status)
|
|
60
|
+
: `${entry.status} ${outcome}`;
|
|
61
|
+
const head = [
|
|
62
|
+
timeOf(entry.at),
|
|
63
|
+
entry.channel,
|
|
64
|
+
entry.version,
|
|
65
|
+
entry.method ?? "-",
|
|
66
|
+
entry.path ?? "-",
|
|
67
|
+
answer,
|
|
68
|
+
`${cpuTime(entry.cpu_ms ?? 0)} CPU`,
|
|
69
|
+
].join(" ");
|
|
70
|
+
const body = [
|
|
71
|
+
...(entry.lines ?? []).map((line) => {
|
|
72
|
+
const level = line.level ?? "log";
|
|
73
|
+
// a message's later lines under its first
|
|
74
|
+
const text = ` ${level.padEnd(5)} ${under(line.message ?? "", " ".repeat(8)).trimStart()}`;
|
|
75
|
+
return level === "error" ? chalk.yellow(text) : text;
|
|
76
|
+
}),
|
|
77
|
+
...(entry.exceptions ?? []).map((each) => chalk.yellow(under(exceptionText(each), " "))),
|
|
78
|
+
...(entry.truncated ? [" … more than was kept"] : []),
|
|
79
|
+
];
|
|
80
|
+
return [head, ...body].join("\n");
|
|
81
|
+
}
|
|
82
|
+
// [function]
|
|
83
|
+
// an entry, as JSON on a line of its own, or as it's read.
|
|
84
|
+
function show(entry, json) {
|
|
85
|
+
if (json) {
|
|
86
|
+
process.stdout.write(`${JSON.stringify(deepSort(entry))}\n`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
p(entryText(entry));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// [export]
|
|
93
|
+
export default defineCommand({
|
|
94
|
+
name: "logs",
|
|
95
|
+
options: {
|
|
96
|
+
...CHANNEL_SHOWS,
|
|
97
|
+
// a build, by its version: `--version` is arc's own, as in arc play
|
|
98
|
+
release: {
|
|
99
|
+
alias: "r",
|
|
100
|
+
describe: "Only this release's, by its version",
|
|
101
|
+
type: "string",
|
|
102
|
+
},
|
|
103
|
+
since: {
|
|
104
|
+
describe: "From a time: 10m, 2h, 1d, or an ISO time",
|
|
105
|
+
type: "string",
|
|
106
|
+
},
|
|
107
|
+
errors: {
|
|
108
|
+
describe: "Only the requests that failed",
|
|
109
|
+
type: "boolean",
|
|
110
|
+
},
|
|
111
|
+
follow: {
|
|
112
|
+
alias: "f",
|
|
113
|
+
describe: "Keep printing each request as it comes",
|
|
114
|
+
type: "boolean",
|
|
115
|
+
},
|
|
116
|
+
json: JSON_OUTPUT,
|
|
117
|
+
cwd: CWD,
|
|
118
|
+
},
|
|
119
|
+
async run(argv, aborting) {
|
|
120
|
+
const json = argv.json;
|
|
121
|
+
const sw = new SpinnerWheel("Checking… %s");
|
|
122
|
+
aborting.sw = sw;
|
|
123
|
+
const where = of(argv);
|
|
124
|
+
const current = await whoami({}, {
|
|
125
|
+
onAccountRefresh(refresh) {
|
|
126
|
+
sw.start(json);
|
|
127
|
+
return refresh();
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
sw.stop(true);
|
|
131
|
+
const conf = {
|
|
132
|
+
channel: where,
|
|
133
|
+
errors: argv.errors,
|
|
134
|
+
root: resolvePath(process.cwd(), argv.cwd),
|
|
135
|
+
since: argv.since,
|
|
136
|
+
version: argv.release,
|
|
137
|
+
};
|
|
138
|
+
if (argv.follow) {
|
|
139
|
+
await follow(current, conf, (entry) => {
|
|
140
|
+
show(entry, json);
|
|
141
|
+
}).catch(ended(current));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const entries = await logs(current, conf).catch(ended(current));
|
|
145
|
+
for (const entry of entries.reverse())
|
|
146
|
+
show(entry, json);
|
|
147
|
+
if (!entries.length && !json) {
|
|
148
|
+
p(functionLogsNone({
|
|
149
|
+
filtered: Boolean(where || argv.release || argv.since || argv.errors),
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
summary: "Show what the game's function logged, and its failures",
|
|
154
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// [import]
|
|
2
2
|
import { defineCommand } from "../../cli/command.js";
|
|
3
|
-
import {
|
|
3
|
+
import { cpuTime, functionState, functionUsage } from "../../phrase/index.js";
|
|
4
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";
|
|
@@ -12,14 +12,16 @@ function count(value) {
|
|
|
12
12
|
return value.toLocaleString("en-US");
|
|
13
13
|
}
|
|
14
14
|
// [function]
|
|
15
|
-
// each channel's function as a table, a row each
|
|
15
|
+
// each channel's function as a table, a row each: its requests and CPU
|
|
16
|
+
// time this month.
|
|
16
17
|
function rows(channels) {
|
|
17
18
|
return table([
|
|
18
|
-
["CHANNEL", "STATUS", "REQUESTS"],
|
|
19
|
+
["CHANNEL", "STATUS", "REQUESTS", "CPU"],
|
|
19
20
|
...channels.map((each) => [
|
|
20
21
|
each.channel,
|
|
21
22
|
functionState(each),
|
|
22
23
|
count(each.requests),
|
|
24
|
+
cpuTime(each.cpu_ms),
|
|
23
25
|
]),
|
|
24
26
|
]);
|
|
25
27
|
}
|
|
@@ -28,13 +30,28 @@ export default defineCommand({
|
|
|
28
30
|
name: "status",
|
|
29
31
|
options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
|
|
30
32
|
run(argv, aborting) {
|
|
31
|
-
return run(argv, aborting, status, ({ channels, month }) => {
|
|
33
|
+
return run(argv, aborting, status, ({ channels, day, month, pool }) => {
|
|
32
34
|
p(rows(channels));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
// nothing to say of its limits when its usage couldn't be read
|
|
36
|
+
if (day && month && pool) {
|
|
37
|
+
const limit = (value) => value === null ? null : count(value);
|
|
38
|
+
p(functionUsage({
|
|
39
|
+
day: {
|
|
40
|
+
allowance: limit(day.allowance),
|
|
41
|
+
requests: count(day.requests),
|
|
42
|
+
},
|
|
43
|
+
month: {
|
|
44
|
+
cpu: cpuTime(month.cpu_ms),
|
|
45
|
+
requests: count(month.requests),
|
|
46
|
+
},
|
|
47
|
+
pool: {
|
|
48
|
+
allowance: limit(pool.allowance),
|
|
49
|
+
cpu: cpuTime(pool.cpu_ms),
|
|
50
|
+
requests: count(pool.requests),
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
37
54
|
});
|
|
38
55
|
},
|
|
39
|
-
summary: "Show whether the game's function is running, and its usage
|
|
56
|
+
summary: "Show whether the game's function is running, and its usage against its limits",
|
|
40
57
|
});
|
package/dist/command/serve.js
CHANGED
|
@@ -32,7 +32,9 @@ function rows(scopes) {
|
|
|
32
32
|
["SCOPE", "KEYS", "SIZE", "MAY HOLD"],
|
|
33
33
|
...scopes.map((each) => {
|
|
34
34
|
const players = each.scope === "player";
|
|
35
|
-
const limit =
|
|
35
|
+
const limit = each.keys_limit === null && each.bytes_limit === null
|
|
36
|
+
? "no limit"
|
|
37
|
+
: `${each.keys_limit === null ? "any number of" : each.keys_limit.toLocaleString("en-US")} keys, ${each.bytes_limit === null ? "any size" : size(each.bytes_limit)}`;
|
|
36
38
|
return [
|
|
37
39
|
NAMES[each.scope] ?? each.scope,
|
|
38
40
|
players
|
|
@@ -41,17 +43,25 @@ function rows(scopes) {
|
|
|
41
43
|
players
|
|
42
44
|
? `${size(each.bytes)} (${size(each.bytes_most)} at most)`
|
|
43
45
|
: size(each.bytes),
|
|
44
|
-
players ? `${limit} each` : limit,
|
|
46
|
+
players && limit !== "no limit" ? `${limit} each` : limit,
|
|
45
47
|
];
|
|
46
48
|
}),
|
|
47
49
|
]);
|
|
48
50
|
}
|
|
49
51
|
// [function]
|
|
50
|
-
// the game's clients' calls
|
|
51
|
-
// its
|
|
52
|
+
// the game's clients' calls: this channel's today, and the game's against
|
|
53
|
+
// its own limit for a day, which both channels share and the day (UTC)
|
|
54
|
+
// renews; then its month, and its account's, every game's together,
|
|
55
|
+
// against its plan's. Each number is the API's; null is no limit.
|
|
52
56
|
function called(calls) {
|
|
53
57
|
const n = (count) => count.toLocaleString("en-US");
|
|
54
|
-
|
|
58
|
+
const today = calls.allowance === null
|
|
59
|
+
? `${n(calls.used)} for the day, with no limit.`
|
|
60
|
+
: `${n(calls.used)} of ${n(calls.allowance)} for the day, both channels together.`;
|
|
61
|
+
const account = calls.pool_allowance === null
|
|
62
|
+
? `Your account's games together: ${n(calls.pool_used)}, with no limit.`
|
|
63
|
+
: `Your account's games together: ${n(calls.pool_used)} of ${n(calls.pool_allowance)}.`;
|
|
64
|
+
return `Calls from the game today: ${n(calls.reads)} reads, ${n(calls.writes)} writes on ${calls.channel}. ${today}\n${n(calls.month_used)} calls this month. ${account}`;
|
|
55
65
|
}
|
|
56
66
|
// [export]
|
|
57
67
|
export default defineCommand({
|
package/dist/commands.js
CHANGED
|
@@ -83,7 +83,7 @@ export const COMMANDS = [
|
|
|
83
83
|
hidden: true,
|
|
84
84
|
load: () => import("./command/function/index.js"),
|
|
85
85
|
name: "function",
|
|
86
|
-
summary: "Pause, resume, and show the game's function, and its secrets",
|
|
86
|
+
summary: "Pause, resume, and show the game's function, its logs, and its secrets",
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
89
|
hidden: true,
|
package/dist/config/code.js
CHANGED
|
@@ -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:
|
|
50
|
-
// as well as REPO_NOT_CONNECTED and
|
|
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;
|
package/dist/config/limit.js
CHANGED
|
@@ -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;
|
package/dist/phrase/function.js
CHANGED
|
@@ -22,11 +22,15 @@ export function functionPaused({ channel, function: has, }) {
|
|
|
22
22
|
return `Paused the game's function on ${channel}. It stops answering within a minute.`;
|
|
23
23
|
}
|
|
24
24
|
// [function]
|
|
25
|
-
// why a function is paused, as a status says it.
|
|
26
|
-
|
|
25
|
+
// why a function is paused, as a status says it. A limit's pause ends by
|
|
26
|
+
// itself, as the day or the month turns (UTC): `resumes` is when, as the
|
|
27
|
+
// API states it.
|
|
28
|
+
export function functionPause(reason, resumes) {
|
|
27
29
|
const reasons = {
|
|
28
30
|
arcadible: "paused by Arcadible",
|
|
29
|
-
limit:
|
|
31
|
+
limit: resumes
|
|
32
|
+
? `at a limit until ${resumes.slice(0, 10)} (UTC)`
|
|
33
|
+
: "at a limit",
|
|
30
34
|
owner: "paused by you",
|
|
31
35
|
};
|
|
32
36
|
return reasons[reason] ?? "paused";
|
|
@@ -35,8 +39,8 @@ export function functionPause(reason) {
|
|
|
35
39
|
// a channel's function, as a status says it: that there's none, when its
|
|
36
40
|
// live build has none or it has no build, with any pause that waits for one;
|
|
37
41
|
// else why it's paused, or that it's running.
|
|
38
|
-
export function functionState({ function: has, paused, }) {
|
|
39
|
-
const pause = paused ? functionPause(paused) : null;
|
|
42
|
+
export function functionState({ function: has, paused, resumes_at: resumes, }) {
|
|
43
|
+
const pause = paused ? functionPause(paused, resumes) : null;
|
|
40
44
|
if (has === false) {
|
|
41
45
|
return pause ? `no function, ${pause}` : "no function";
|
|
42
46
|
}
|
|
@@ -44,29 +48,60 @@ export function functionState({ function: has, paused, }) {
|
|
|
44
48
|
}
|
|
45
49
|
// [function]
|
|
46
50
|
// a resumed function, with any pause that isn't its owner's still on it.
|
|
47
|
-
export function functionResumed({ channel, paused, }) {
|
|
51
|
+
export function functionResumed({ channel, lifted, paused, }) {
|
|
52
|
+
if (!lifted) {
|
|
53
|
+
return `The game's function isn't paused on ${channel}.`;
|
|
54
|
+
}
|
|
48
55
|
if (paused) {
|
|
49
56
|
return blocks(`Lifted your pause on ${channel}.`, `The game's function stays paused: ${functionPause(paused)}.`);
|
|
50
57
|
}
|
|
51
58
|
return `Resumed the game's function on ${channel}. It answers again within a minute.`;
|
|
52
59
|
}
|
|
53
60
|
// [function]
|
|
54
|
-
// a game's function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
// what holds a game's function, as a status says it under its channels:
|
|
62
|
+
// the game's requests today against its own limit for a day, then its
|
|
63
|
+
// month and its account's, every game's together, against its plan's, then
|
|
64
|
+
// the CPU time of both, which no limit holds. Each number is the API's;
|
|
65
|
+
// null is no limit.
|
|
66
|
+
export function functionUsage({ day, month, pool, }) {
|
|
67
|
+
const today = day.allowance === null
|
|
68
|
+
? `${day.requests} requests today, with no limit for a day.`
|
|
69
|
+
: `${day.requests} of ${day.allowance} requests today, both channels together.`;
|
|
70
|
+
const account = pool.allowance === null
|
|
71
|
+
? `Your account's games together: ${pool.requests}, with no limit.`
|
|
72
|
+
: `Your account's games together: ${pool.requests} of ${pool.allowance}.`;
|
|
73
|
+
const cpu = month.cpu && pool.cpu
|
|
74
|
+
? `\nCPU time this month: ${month.cpu}. Your account's games together: ${pool.cpu}.`
|
|
75
|
+
: "";
|
|
76
|
+
return `${today}\n${month.requests} requests this month. ${account}${cpu}`;
|
|
77
|
+
}
|
|
78
|
+
// [function]
|
|
79
|
+
// a function's CPU time, given in milliseconds, as it's read: "640 ms",
|
|
80
|
+
// "1.2 s", "4.5 min", "1,234.5 h".
|
|
81
|
+
export function cpuTime(ms) {
|
|
82
|
+
const one = (value) => value.toLocaleString("en-US", {
|
|
83
|
+
maximumFractionDigits: 1,
|
|
84
|
+
minimumFractionDigits: 1,
|
|
85
|
+
});
|
|
86
|
+
if (ms < 1000)
|
|
87
|
+
return `${Math.round(ms)} ms`;
|
|
88
|
+
if (ms < 60 * 1000)
|
|
89
|
+
return `${one(ms / 1000)} s`;
|
|
90
|
+
if (ms < 60 * 60 * 1000)
|
|
91
|
+
return `${one(ms / 60 / 1000)} min`;
|
|
92
|
+
return `${one(ms / 60 / 60 / 1000)} h`;
|
|
93
|
+
}
|
|
94
|
+
// [function]
|
|
95
|
+
// a resume with no pause of the owner's to lift, and one of another's: who
|
|
96
|
+
// lifts it.
|
|
97
|
+
export function functionPauseReserved({ channel, paused, }) {
|
|
63
98
|
if (paused === "arcadible") {
|
|
64
99
|
return blocks(`The game's function is paused by Arcadible on ${channel}.`, "Only Arcadible can resume it.");
|
|
65
100
|
}
|
|
66
101
|
if (paused === "limit") {
|
|
67
|
-
return blocks(`The game's function
|
|
102
|
+
return blocks(`The game's function is at a limit on ${channel}.`, "It resumes by itself as the day or the month turns (UTC): `arc function status` says when.");
|
|
68
103
|
}
|
|
69
|
-
return `The game's function
|
|
104
|
+
return `The game's function is paused on ${channel}, and not by you.`;
|
|
70
105
|
}
|
|
71
106
|
// [function]
|
|
72
107
|
export function secretSet({ channel, name, }) {
|
|
@@ -122,6 +157,11 @@ export function runnerBuildFailed(message) {
|
|
|
122
157
|
return `The function didn't build:\n${message}`;
|
|
123
158
|
}
|
|
124
159
|
// [function]
|
|
160
|
+
// a function's bundle past what Arcadible runs.
|
|
161
|
+
export function functionTooLarge(size) {
|
|
162
|
+
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.");
|
|
163
|
+
}
|
|
164
|
+
// [function]
|
|
125
165
|
// a package asked for before the runner it carries was built.
|
|
126
166
|
export function runnerNotBuilt() {
|
|
127
167
|
return blocks("The function isn't built.", "Run `arc build` first.");
|
|
@@ -144,3 +184,26 @@ export function runnerFailed(message) {
|
|
|
144
184
|
export function runnerLabel() {
|
|
145
185
|
return "Function:";
|
|
146
186
|
}
|
|
187
|
+
// [function]
|
|
188
|
+
// no entry that matches: what's kept, and where else lines are printed.
|
|
189
|
+
export function functionLogsNone({ filtered }) {
|
|
190
|
+
return blocks(filtered ? "No logs that match." : "No logs yet.", "Arcadible keeps a function's logs for 7 days.\nUnder `arc serve`, its lines are printed where it runs.");
|
|
191
|
+
}
|
|
192
|
+
// [function]
|
|
193
|
+
export function functionLogsSinceInvalid(text) {
|
|
194
|
+
return blocks(`Not a time to read from: ${text}`, "--since takes a span back from now (10m, 2h, 1d), or an ISO time.");
|
|
195
|
+
}
|
|
196
|
+
// [function]
|
|
197
|
+
export function functionLogsVersionInvalid(text) {
|
|
198
|
+
return blocks(`Not a version: ${text}`, "--release takes a release's version, such as 1.2.0.");
|
|
199
|
+
}
|
|
200
|
+
// [function]
|
|
201
|
+
// a sixth follow of a game's logs, while five are open.
|
|
202
|
+
export function functionLogsBusy() {
|
|
203
|
+
return blocks("The game's logs are followed five times already.", "Stop one of them, then try again.");
|
|
204
|
+
}
|
|
205
|
+
// [function]
|
|
206
|
+
// the logs' refusal, which the CLI didn't expect: its status and code.
|
|
207
|
+
export function functionLogsRefused({ code, status, }) {
|
|
208
|
+
return `Unable to read the function's logs (${status}${code ? `, ${code}` : ""}).`;
|
|
209
|
+
}
|
package/dist/phrase/game.js
CHANGED
|
@@ -20,8 +20,10 @@ export function gameDeletedProject() {
|
|
|
20
20
|
];
|
|
21
21
|
}
|
|
22
22
|
// [function]
|
|
23
|
-
// a game the API won't
|
|
24
|
-
//
|
|
25
|
-
|
|
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
|
}
|
package/dist/phrase/serve.js
CHANGED
|
@@ -29,6 +29,12 @@ export function remoteUnreachable(name) {
|
|
|
29
29
|
return `Unable to reach ${TITLE}, and ${remoteName(name)} isn't saved.\nThe game runs without it until ${TITLE} is back.`;
|
|
30
30
|
}
|
|
31
31
|
// [function]
|
|
32
|
+
// a link the game made, to open in another window as another player
|
|
33
|
+
// (`&player=<name>`).
|
|
34
|
+
export function linkMade(url) {
|
|
35
|
+
return `Link made: ${url}`;
|
|
36
|
+
}
|
|
37
|
+
// [function]
|
|
32
38
|
export function reloaded() {
|
|
33
39
|
return `Reloaded at ${new Date().toTimeString().slice(0, 8)}.`;
|
|
34
40
|
}
|
package/dist/runner/bundle.js
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
// the pipeline as a build is released, and by arc serve (./entry.ts), so no
|
|
6
6
|
// build carries an entry of the day its `arc` was installed.
|
|
7
7
|
// [import]
|
|
8
|
+
import { stat } from "node:fs/promises";
|
|
8
9
|
import { join } from "node:path";
|
|
9
10
|
// [import]
|
|
10
11
|
import { build } from "esbuild";
|
|
11
12
|
import { pathExists } from "fs-extra";
|
|
12
13
|
// [import]
|
|
13
|
-
import { BUILD_FAILED } from "../config/code.js";
|
|
14
|
+
import { BUILD_FAILED, FUNCTION_TOO_LARGE } from "../config/code.js";
|
|
15
|
+
import { FUNCTION_SIZE } from "../config/limit.js";
|
|
14
16
|
import * as phrase from "../phrase/index.js";
|
|
15
17
|
import { ArcError } from "../util/error.js";
|
|
16
18
|
// [declare]
|
|
@@ -29,7 +31,9 @@ export const WRONG = {
|
|
|
29
31
|
};
|
|
30
32
|
// [function]
|
|
31
33
|
// bundles the runner whose code is at `main`, a full path, into `outfile`;
|
|
32
|
-
// code that isn't there, or doesn't build, fails as a build does
|
|
34
|
+
// code that isn't there, or doesn't build, fails as a build does, and a
|
|
35
|
+
// bundle past what Arcadible runs fails as the release would
|
|
36
|
+
// (function_too_large), before it's ever uploaded.
|
|
33
37
|
//
|
|
34
38
|
// `onPackages`, when given, hears the `@arcadible/` packages the bundle took
|
|
35
39
|
// in, by name, each once, so a build can say when a function imports one
|
|
@@ -59,6 +63,10 @@ export async function bundle({ main, onPackages, outfile, }) {
|
|
|
59
63
|
catch (ex) {
|
|
60
64
|
throw new ArcError(BUILD_FAILED, phrase.runnerBuildFailed(ex instanceof Error ? ex.message : String(ex)), { cause: ex });
|
|
61
65
|
}
|
|
66
|
+
const { size } = await stat(outfile);
|
|
67
|
+
if (size > FUNCTION_SIZE) {
|
|
68
|
+
throw new ArcError(FUNCTION_TOO_LARGE, phrase.functionTooLarge(size));
|
|
69
|
+
}
|
|
62
70
|
onPackages?.(packagesOf(inputs));
|
|
63
71
|
return outfile;
|
|
64
72
|
}
|