arcadible 1.0.23 → 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.
- package/README.md +1 -0
- package/bin/arc.js +1 -85
- package/dist/account.js +197 -0
- package/dist/action/build/tool.js +61 -0
- package/dist/action/delete/tool.js +47 -0
- package/dist/action/deploy/rebuilt.js +25 -0
- package/dist/action/deploy/result.js +36 -0
- package/dist/action/deploy/timeout.js +18 -0
- package/dist/action/deploy/tool-git.js +49 -0
- package/dist/action/deploy/tool.js +49 -0
- package/dist/action/deploy/wait.js +104 -0
- package/dist/action/function/tool.js +127 -0
- package/dist/action/game.js +62 -0
- package/dist/action/init/manifest.js +64 -0
- package/dist/action/init/tool-patch.js +15 -0
- package/dist/action/init/tool.js +64 -0
- package/dist/action/inspect/tool.js +13 -0
- package/dist/action/key/tool.js +88 -0
- package/dist/action/login/flow.js +69 -0
- package/dist/action/login/tool.js +8 -0
- package/dist/action/logout/tool.js +8 -0
- package/dist/action/open/tool.js +30 -0
- package/dist/action/pack/limits.js +46 -0
- package/dist/action/pack/tool.js +148 -0
- package/dist/action/pack/unsound.js +51 -0
- package/dist/action/play/tool.js +84 -0
- package/dist/action/predeploy/ac.js +75 -0
- package/dist/action/predeploy/game.js +6 -0
- package/dist/action/predeploy/git.js +151 -0
- package/dist/action/predeploy/pm.js +20 -0
- package/dist/action/predeploy/published.js +54 -0
- package/dist/action/predeploy/secrets.js +35 -0
- package/dist/action/predeploy/tool-git.js +103 -0
- package/dist/action/predeploy/tool.js +14 -0
- package/dist/action/secret/tool.js +91 -0
- package/dist/action/serve/tool.js +270 -0
- package/dist/action/validate/checked.js +28 -0
- package/dist/action/validate/tool.js +56 -0
- package/dist/action/validate/unknown.js +58 -0
- package/dist/action/validate/unsound.js +99 -0
- package/dist/action/value/tool.js +216 -0
- package/dist/action/whoami/tool.js +7 -0
- package/dist/api.js +312 -0
- package/dist/arc.js +41 -0
- package/dist/cli/argv.js +61 -0
- package/dist/cli/channel.js +29 -0
- package/dist/cli/command.js +163 -0
- package/dist/cli/confirm.js +39 -0
- package/dist/cli/options.js +62 -0
- package/dist/cli/rc.js +103 -0
- package/dist/cli/yargs.js +40 -0
- package/dist/command/build.js +68 -0
- package/dist/command/delete.js +66 -0
- package/dist/command/deploy.js +308 -0
- package/dist/command/function/index.js +17 -0
- package/dist/command/function/pause.js +18 -0
- package/dist/command/function/resume.js +18 -0
- package/dist/command/function/run.js +41 -0
- package/dist/command/function/secret/index.js +15 -0
- package/dist/command/function/secret/list.js +27 -0
- package/dist/command/function/secret/name.js +8 -0
- package/dist/command/function/secret/remove.js +26 -0
- package/dist/command/function/secret/run.js +52 -0
- package/dist/command/function/secret/set.js +48 -0
- package/dist/command/function/status.js +40 -0
- package/dist/command/init.js +128 -0
- package/dist/command/inspect.js +39 -0
- package/dist/command/login.js +108 -0
- package/dist/command/logout.js +24 -0
- package/dist/command/open.js +49 -0
- package/dist/command/pack.js +90 -0
- package/dist/command/play.js +81 -0
- package/dist/command/serve.js +177 -0
- package/dist/command/server/index.js +17 -0
- package/dist/command/server/key/create.js +36 -0
- package/dist/command/server/key/index.js +15 -0
- package/dist/command/server/key/list.js +34 -0
- package/dist/command/server/key/revoke.js +24 -0
- package/dist/command/server/key/run.js +54 -0
- package/dist/command/validate.js +47 -0
- package/dist/command/value/get.js +21 -0
- package/dist/command/value/index.js +19 -0
- package/dist/command/value/key.js +8 -0
- package/dist/command/value/list.js +41 -0
- package/dist/command/value/remove.js +26 -0
- package/dist/command/value/set.js +62 -0
- package/dist/command/value/usage.js +69 -0
- package/dist/command/whoami.js +55 -0
- package/dist/commands.js +100 -0
- package/dist/config/ai.js +2 -0
- package/dist/config/art.js +13 -0
- package/dist/config/audience.js +2 -0
- package/dist/config/code.js +129 -0
- package/dist/config/file.js +13 -0
- package/dist/config/genre.js +19 -0
- package/{src → dist}/config/html.js +2 -7
- package/dist/config/image.js +5 -0
- package/dist/config/input.js +11 -0
- package/dist/config/json.js +23 -0
- package/dist/config/limit.js +14 -0
- package/dist/config/orientation.js +11 -0
- package/dist/config/package.js +8 -0
- package/dist/config/product.js +14 -0
- package/dist/config/template.js +37 -0
- package/dist/config/uri.js +18 -0
- package/dist/config/url.js +11 -0
- package/dist/config/video.js +5 -0
- package/dist/config/visibility.js +2 -0
- package/dist/config/workflow.js +7 -0
- package/dist/parser/env.js +61 -0
- package/dist/parser/given.js +8 -0
- package/dist/parser/manifest.js +45 -0
- package/dist/parser/media.js +57 -0
- package/dist/parser/project.js +129 -0
- package/dist/parser/readme-file.js +44 -0
- package/dist/parser/readme.js +70 -0
- package/dist/parser/sections.js +92 -0
- package/dist/parser/self.js +16 -0
- package/dist/phrase/account.js +35 -0
- package/dist/phrase/common.js +139 -0
- package/dist/phrase/deploy.js +192 -0
- package/dist/phrase/function.js +139 -0
- package/dist/phrase/game.js +27 -0
- package/dist/phrase/index.js +16 -0
- package/dist/phrase/init.js +53 -0
- package/dist/phrase/internal.js +61 -0
- package/dist/phrase/manifest.js +120 -0
- package/dist/phrase/media.js +90 -0
- package/dist/phrase/pack.js +69 -0
- package/dist/phrase/serve.js +84 -0
- package/dist/phrase/server.js +38 -0
- package/dist/phrase/value.js +55 -0
- package/dist/runner/bundle.js +45 -0
- package/dist/runner/entry.js +57 -0
- package/dist/runner/outbound.js +69 -0
- package/dist/schema/check/game.js +29 -0
- package/dist/schema/check/workflow.js +57 -0
- package/dist/schema/game.js +462 -0
- package/dist/schema/message.js +61 -0
- package/dist/schema/readme.js +27 -0
- package/dist/schema/runner.js +43 -0
- package/dist/schema/server.js +91 -0
- package/dist/schema/workflow.js +99 -0
- package/dist/serve/files.js +39 -0
- package/dist/serve/game.js +172 -0
- package/dist/serve/page.js +689 -0
- package/dist/serve/reload.js +55 -0
- package/dist/serve/remote.js +114 -0
- package/dist/serve/runner.js +303 -0
- package/dist/serve/server.js +169 -0
- package/dist/serve/ticket.js +232 -0
- package/dist/serve/values.js +317 -0
- package/dist/util/bytes.js +16 -0
- package/dist/util/chars.js +19 -0
- package/dist/util/command.js +11 -0
- package/dist/util/delay.js +36 -0
- package/dist/util/doc.js +59 -0
- package/dist/util/error.js +35 -0
- package/dist/util/http.js +13 -0
- package/dist/util/image.js +64 -0
- package/dist/util/links.js +45 -0
- package/dist/util/lockfile.js +17 -0
- package/dist/util/log.js +101 -0
- package/dist/util/md.js +37 -0
- package/dist/util/media.js +27 -0
- package/dist/util/objs.js +46 -0
- package/dist/util/os.js +13 -0
- package/dist/util/output.js +133 -0
- package/dist/util/paths.js +8 -0
- package/dist/util/progress.js +57 -0
- package/dist/util/promise.js +18 -0
- package/dist/util/request.js +103 -0
- package/dist/util/s3.js +67 -0
- package/dist/util/schema.js +151 -0
- package/dist/util/screenshot.js +24 -0
- package/dist/util/shape.js +49 -0
- package/dist/util/shell.js +64 -0
- package/dist/util/size.js +32 -0
- package/dist/util/spinner.js +35 -0
- package/dist/util/strs.js +46 -0
- package/dist/util/table.js +18 -0
- package/dist/util/term.js +21 -0
- package/dist/util/time.js +16 -0
- package/dist/util/toml.js +28 -0
- package/{src → dist}/util/uris.js +8 -14
- package/dist/util/video.js +113 -0
- package/dist/util/zip.js +62 -0
- package/npm-shrinkwrap.json +3256 -0
- package/package.json +41 -39
- package/bin/arc-build.js +0 -139
- package/bin/arc-default.js +0 -65
- package/bin/arc-deploy.js +0 -456
- package/bin/arc-init.js +0 -187
- package/bin/arc-inspect.js +0 -97
- package/bin/arc-login.js +0 -165
- package/bin/arc-logout.js +0 -75
- package/bin/arc-open.js +0 -104
- package/bin/arc-pack.js +0 -146
- package/bin/arc-play.js +0 -140
- package/bin/arc-serve.js +0 -214
- package/bin/arc-validate.js +0 -112
- package/bin/arc-whoami.js +0 -119
- package/src/account.js +0 -249
- package/src/action/build/tool.js +0 -80
- package/src/action/deploy/tool-git.js +0 -90
- package/src/action/deploy/tool.js +0 -88
- package/src/action/deploy/wait.js +0 -151
- package/src/action/init/manifest.js +0 -83
- package/src/action/init/tool-patch.js +0 -32
- package/src/action/init/tool.js +0 -97
- package/src/action/inspect/tool.js +0 -26
- package/src/action/login/flow.js +0 -101
- package/src/action/login/tool.js +0 -16
- package/src/action/logout/tool.js +0 -15
- package/src/action/open/tool.js +0 -38
- package/src/action/pack/limits.js +0 -51
- package/src/action/pack/tool.js +0 -171
- package/src/action/pack/unsound.js +0 -69
- package/src/action/play/tool.js +0 -109
- package/src/action/predeploy/ac.js +0 -112
- package/src/action/predeploy/git.js +0 -223
- package/src/action/predeploy/pm.js +0 -37
- package/src/action/predeploy/published.js +0 -82
- package/src/action/predeploy/tool-git.js +0 -154
- package/src/action/predeploy/tool.js +0 -29
- package/src/action/serve/tool.js +0 -209
- package/src/action/validate/checked.js +0 -37
- package/src/action/validate/tool.js +0 -67
- package/src/action/validate/unknown.js +0 -86
- package/src/action/validate/unsound.js +0 -138
- package/src/action/whoami/tool.js +0 -15
- package/src/api.js +0 -163
- package/src/cli/build.js +0 -15
- package/src/cli/deploy.js +0 -21
- package/src/cli/init.js +0 -17
- package/src/cli/inspect.js +0 -15
- package/src/cli/login.js +0 -15
- package/src/cli/logout.js +0 -15
- package/src/cli/open.js +0 -15
- package/src/cli/pack.js +0 -15
- package/src/cli/play.js +0 -15
- package/src/cli/predeploy.js +0 -21
- package/src/cli/serve.js +0 -15
- package/src/cli/validate.js +0 -15
- package/src/cli/whoami.js +0 -15
- package/src/config/ai.js +0 -5
- package/src/config/art.js +0 -16
- package/src/config/audience.js +0 -5
- package/src/config/code.js +0 -142
- package/src/config/file.js +0 -23
- package/src/config/genre.js +0 -22
- package/src/config/image.js +0 -7
- package/src/config/input.js +0 -14
- package/src/config/limit.js +0 -21
- package/src/config/orientation.js +0 -14
- package/src/config/package.js +0 -5
- package/src/config/product.js +0 -5
- package/src/config/template.js +0 -45
- package/src/config/uri.js +0 -27
- package/src/config/url.js +0 -20
- package/src/config/video.js +0 -7
- package/src/config/visibility.js +0 -5
- package/src/config/workflow.js +0 -18
- package/src/parser/env.js +0 -84
- package/src/parser/given.js +0 -17
- package/src/parser/manifest.js +0 -80
- package/src/parser/media.js +0 -90
- package/src/parser/project.js +0 -166
- package/src/parser/readme-file.js +0 -76
- package/src/parser/readme.js +0 -96
- package/src/parser/sections.js +0 -107
- package/src/parser/self.js +0 -27
- package/src/phrase.js +0 -1294
- package/src/schema/check/game.js +0 -61
- package/src/schema/check/workflow.js +0 -99
- package/src/schema/game.js +0 -649
- package/src/schema/message.js +0 -85
- package/src/schema/readme.js +0 -44
- package/src/schema/workflow.js +0 -150
- package/src/serve/files.js +0 -61
- package/src/serve/game.js +0 -191
- package/src/serve/page.js +0 -345
- package/src/serve/reload.js +0 -68
- package/src/serve/remote.js +0 -121
- package/src/serve/server.js +0 -128
- package/src/util/argv.js +0 -116
- package/src/util/bytes.js +0 -25
- package/src/util/chars.js +0 -30
- package/src/util/command.js +0 -18
- package/src/util/delay.js +0 -52
- package/src/util/doc.js +0 -72
- package/src/util/error.js +0 -50
- package/src/util/http.js +0 -25
- package/src/util/image.js +0 -93
- package/src/util/links.js +0 -78
- package/src/util/lockfile.js +0 -35
- package/src/util/log.js +0 -149
- package/src/util/md.js +0 -61
- package/src/util/media.js +0 -40
- package/src/util/objs.js +0 -45
- package/src/util/os.js +0 -27
- package/src/util/output.js +0 -174
- package/src/util/paths.js +0 -21
- package/src/util/progress.js +0 -85
- package/src/util/promise.js +0 -29
- package/src/util/rc.js +0 -144
- package/src/util/request.js +0 -89
- package/src/util/s3.js +0 -92
- package/src/util/schema.js +0 -189
- package/src/util/screenshot.js +0 -37
- package/src/util/shell.js +0 -84
- package/src/util/size.js +0 -53
- package/src/util/spinner.js +0 -52
- package/src/util/strs.js +0 -73
- package/src/util/term.js +0 -28
- package/src/util/time.js +0 -29
- package/src/util/toml.js +0 -14
- package/src/util/video.js +0 -157
- package/src/util/zip.js +0 -88
- /package/{src/serve → assets}/favicon.ico +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// [import]
|
|
4
|
+
import semver from "semver";
|
|
5
|
+
// [import]
|
|
6
|
+
import { ART as cfgart } from "../../config/art.js";
|
|
7
|
+
import { WARNING } from "../../config/code.js";
|
|
8
|
+
import { MEDIA } from "../../config/file.js";
|
|
9
|
+
import { artVideoUnpaired, didYouMean, fieldUnset, screenshotNameInvalid, } from "../../phrase/index.js";
|
|
10
|
+
import { warning as outputWarning } from "../../util/output.js";
|
|
11
|
+
import { SCREENSHOT } from "../../util/screenshot.js";
|
|
12
|
+
// [use]
|
|
13
|
+
const extname = path.extname;
|
|
14
|
+
const parse = path.parse;
|
|
15
|
+
const posixBasename = path.posix.basename;
|
|
16
|
+
const prerelease = semver.prerelease;
|
|
17
|
+
const validSemver = semver.valid;
|
|
18
|
+
// [declare]
|
|
19
|
+
// the art fields, such as `icon`, each of which may have a `_video`.
|
|
20
|
+
const ART = cfgart
|
|
21
|
+
.map((file) => parse(file).name)
|
|
22
|
+
.filter((name) => !name.endsWith("_video"));
|
|
23
|
+
// a name one case or separator away from a screenshot's: `Screenshot_01`,
|
|
24
|
+
// `screenshot-01`, `screenshot01`, with any qualifier after it.
|
|
25
|
+
const SCREENSHOT_NEAR = /^screenshot[-_ ]?(\d+)(?:[-_ ](.+))?$/iu;
|
|
26
|
+
// [function]
|
|
27
|
+
// a warning about a field, in an issue's shape, with its details.
|
|
28
|
+
function warning(code, field, [message = "", ...details]) {
|
|
29
|
+
return { ...outputWarning(code, message, field), details };
|
|
30
|
+
}
|
|
31
|
+
// [function]
|
|
32
|
+
// the fields a release leaves out whose defaults it may not mean: a release
|
|
33
|
+
// version's `visibility` and `title`, and a public one's `inputs`. A
|
|
34
|
+
// prerelease changes no store page, so it's never warned about.
|
|
35
|
+
function unset(game) {
|
|
36
|
+
const version = game["version"];
|
|
37
|
+
// only a string is a version: semver reads nothing else as one.
|
|
38
|
+
if (typeof version !== "string" ||
|
|
39
|
+
!validSemver(version) ||
|
|
40
|
+
prerelease(version)) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const fields = [
|
|
44
|
+
"visibility",
|
|
45
|
+
"title",
|
|
46
|
+
...(game["visibility"] === "public" ? ["inputs"] : []),
|
|
47
|
+
];
|
|
48
|
+
return fields
|
|
49
|
+
.filter((field) => typeof game[field] === "undefined")
|
|
50
|
+
.map((field) => warning(WARNING.FIELD_UNSET, `game.${field}`, fieldUnset(field) ?? []));
|
|
51
|
+
}
|
|
52
|
+
// [function]
|
|
53
|
+
// each art video without its PNG, such as `icon_video` without `icon`.
|
|
54
|
+
function unpaired(game) {
|
|
55
|
+
return ART.filter((art) => game[`${art}_video`] && !game[art]).map((art) => warning(WARNING.ART_VIDEO_UNPAIRED, `game.${art}_video`, artVideoUnpaired(art, `${MEDIA}/${art}.png`)));
|
|
56
|
+
}
|
|
57
|
+
// [function]
|
|
58
|
+
// the gallery's file names, or none when it isn't a list of paths, which
|
|
59
|
+
// its issues report.
|
|
60
|
+
function galleryNames(game) {
|
|
61
|
+
const gallery = game["gallery"];
|
|
62
|
+
if (!Array.isArray(gallery)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
return gallery
|
|
66
|
+
.filter((file) => typeof file === "string")
|
|
67
|
+
.map((file) => posixBasename(file));
|
|
68
|
+
}
|
|
69
|
+
// [function]
|
|
70
|
+
// a gallery file named almost as a screenshot, with the name it might mean.
|
|
71
|
+
function misnamed(names) {
|
|
72
|
+
return names.flatMap((name) => {
|
|
73
|
+
if (SCREENSHOT.test(name)) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const ext = extname(name);
|
|
77
|
+
const match = SCREENSHOT_NEAR.exec(parse(name).name);
|
|
78
|
+
if (!match) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const qualifier = match[2] ? `_${match[2]}` : "";
|
|
82
|
+
const near = `screenshot_${match[1]}${qualifier}${ext}`;
|
|
83
|
+
return [
|
|
84
|
+
warning(WARNING.SCREENSHOT_NAME_INVALID, "game.gallery", [
|
|
85
|
+
screenshotNameInvalid(name),
|
|
86
|
+
didYouMean(near),
|
|
87
|
+
]),
|
|
88
|
+
];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// [function]
|
|
92
|
+
// what the resolved manifest has that's sound by its rules but almost never
|
|
93
|
+
// meant, as warnings: facts about the project, never a guess at how the
|
|
94
|
+
// store will show it (OUTPUT.md, Codes).
|
|
95
|
+
export function unsound(proj) {
|
|
96
|
+
const game = proj?.game ?? {};
|
|
97
|
+
const names = galleryNames(game);
|
|
98
|
+
return [...unset(game), ...unpaired(game), ...misnamed(names)];
|
|
99
|
+
}
|
|
@@ -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
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// [import]
|
|
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";
|
|
7
|
+
import { HOST_HTTP_API } from "./config/uri.js";
|
|
8
|
+
// [declare]
|
|
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
|
+
});
|
|
113
|
+
// [function]
|
|
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
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// [function]
|
|
128
|
+
// an API path with each value encoded as one segment, so a handle or version
|
|
129
|
+
// can't add a segment or a query: pathOf`/games/${id}`.
|
|
130
|
+
function pathOf(strings, ...values) {
|
|
131
|
+
return strings.reduce((out, each, i) => out +
|
|
132
|
+
each +
|
|
133
|
+
(i < values.length ? encodeURIComponent(values[i] ?? "") : ""), "");
|
|
134
|
+
}
|
|
135
|
+
// [function]
|
|
136
|
+
// the full URL of an API path, with `params` as its query. Undefined and null
|
|
137
|
+
// params are left out.
|
|
138
|
+
function endpoint(path, params) {
|
|
139
|
+
const url = new URL(`${HOST_HTTP_API}/${VERSION}${path}`);
|
|
140
|
+
for (const [key, value] of Object.entries(params ?? {})) {
|
|
141
|
+
if ((value ?? null) !== null) {
|
|
142
|
+
url.searchParams.set(key, String(value));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return url.href;
|
|
146
|
+
}
|
|
147
|
+
// [function]
|
|
148
|
+
// the headers that authenticate a request with an access token.
|
|
149
|
+
export function auth(token) {
|
|
150
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
151
|
+
}
|
|
152
|
+
// [function]
|
|
153
|
+
// ends the session the access token belongs to, and only that one.
|
|
154
|
+
export function postAuthLogout(params, headers) {
|
|
155
|
+
return post(endpoint("/auth/logout", params), null, headers);
|
|
156
|
+
}
|
|
157
|
+
// [function]
|
|
158
|
+
export function postAuthRefresh(form, params, headers) {
|
|
159
|
+
return answer(isSession, "a session", post(endpoint("/auth/refresh", params), form, headers));
|
|
160
|
+
}
|
|
161
|
+
// [function]
|
|
162
|
+
export function postFlow(form, params, headers) {
|
|
163
|
+
return answer(isFlowCreated, "a login", post(endpoint("/flows", params), form, headers));
|
|
164
|
+
}
|
|
165
|
+
// [function]
|
|
166
|
+
export function flow(id, params, headers) {
|
|
167
|
+
return answer(isFlow, "a login", get(endpoint(pathOf `/flows/${id}`, params), headers));
|
|
168
|
+
}
|
|
169
|
+
// [function]
|
|
170
|
+
export function postUpload(form, params, headers) {
|
|
171
|
+
return answer(isUpload, "an upload", post(endpoint("/uploads", params), form, headers));
|
|
172
|
+
}
|
|
173
|
+
// [function]
|
|
174
|
+
export function discoverGame(id, params, headers) {
|
|
175
|
+
return answer(isGame, "a game", get(endpoint(pathOf `/discover/games/${id}`, params), headers));
|
|
176
|
+
}
|
|
177
|
+
// [function]
|
|
178
|
+
export function discoverGameBuilds(id, params, headers) {
|
|
179
|
+
return answer(listed(isBuild), "a game's builds", get(endpoint(pathOf `/discover/games/${id}/builds`, params), headers));
|
|
180
|
+
}
|
|
181
|
+
// [function]
|
|
182
|
+
export function discoverGameBuild(id, version, params, headers) {
|
|
183
|
+
return answer(isBuild, "a build", get(endpoint(pathOf `/discover/games/${id}/builds/${version}`, params), headers));
|
|
184
|
+
}
|
|
185
|
+
// [function]
|
|
186
|
+
// a game's releases, which anyone can read: what each says about itself.
|
|
187
|
+
export function discoverGameReleases(id, params, headers) {
|
|
188
|
+
return answer(listed(isRelease), "a game's releases", get(endpoint(pathOf `/discover/games/${id}/releases`, params), headers));
|
|
189
|
+
}
|
|
190
|
+
// [function]
|
|
191
|
+
// the game's connected repository, if it's `owner/name`; otherwise 404.
|
|
192
|
+
export function discoverGameRepo(id, owner, name, params, headers) {
|
|
193
|
+
return get(endpoint(pathOf `/discover/games/${id}/repos/${owner}/${name}`, params), headers);
|
|
194
|
+
}
|
|
195
|
+
// [function]
|
|
196
|
+
export function gameBuild(id, version, params, headers) {
|
|
197
|
+
return answer(isBuild, "a build", get(endpoint(pathOf `/games/${id}/builds/${version}`, params), headers));
|
|
198
|
+
}
|
|
199
|
+
// [function]
|
|
200
|
+
// whether the caller's game could take a handle on a deploy to `channel`:
|
|
201
|
+
// its status is available, taken, limit, or lapsed.
|
|
202
|
+
export function gameHandle(id, handle, params, headers) {
|
|
203
|
+
return answer(isHandleStatus, "a handle", get(endpoint(pathOf `/games/${id}/handles/${handle}`, params), headers));
|
|
204
|
+
}
|
|
205
|
+
// [function]
|
|
206
|
+
export function release(id, params, headers) {
|
|
207
|
+
return answer(isRelease, "a release", get(endpoint(pathOf `/releases/${id}`, params), headers));
|
|
208
|
+
}
|
|
209
|
+
// [function]
|
|
210
|
+
// deletes the caller's own game, by its id: at once, and for good. One that
|
|
211
|
+
// isn't the caller's, isn't on Arcadible, or is deleted already is a 404.
|
|
212
|
+
export function deleteGame(id, params, headers) {
|
|
213
|
+
return del(endpoint(pathOf `/games/${id}`, params), headers);
|
|
214
|
+
}
|
|
215
|
+
// [function]
|
|
216
|
+
// the live keys of the caller's own game: never the keys themselves.
|
|
217
|
+
export function gameKeys(id, params, headers) {
|
|
218
|
+
return answer(listed(isKey), "a game's keys", get(endpoint(pathOf `/games/${id}/keys`, params), headers));
|
|
219
|
+
}
|
|
220
|
+
// [function]
|
|
221
|
+
// a new key for the caller's own game, answered once, in `key`.
|
|
222
|
+
export function postGameKey(id, form, params, headers) {
|
|
223
|
+
return answer(isKeyCreated, "a key", post(endpoint(pathOf `/games/${id}/keys`, params), form, headers));
|
|
224
|
+
}
|
|
225
|
+
// [function]
|
|
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));
|
|
229
|
+
}
|
|
230
|
+
// [function]
|
|
231
|
+
// the secrets of the caller's own game's runner, by channel and name: never
|
|
232
|
+
// their values.
|
|
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));
|
|
235
|
+
}
|
|
236
|
+
// [function]
|
|
237
|
+
// a secret's address: its channel, and its name in lowercase, as the API's
|
|
238
|
+
// addresses are.
|
|
239
|
+
function secretPath(id, channel, name) {
|
|
240
|
+
return pathOf `/games/${id}/function_secrets/${channel}/${name.toLowerCase()}`;
|
|
241
|
+
}
|
|
242
|
+
// [function]
|
|
243
|
+
// sets a secret of the caller's own game, with its value in the form.
|
|
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));
|
|
246
|
+
}
|
|
247
|
+
// [function]
|
|
248
|
+
// removes a secret of the caller's own game.
|
|
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));
|
|
290
|
+
}
|
|
291
|
+
// [function]
|
|
292
|
+
// the pauses of the caller's own game's function, by channel and reason.
|
|
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));
|
|
295
|
+
}
|
|
296
|
+
// [function]
|
|
297
|
+
// the usage of the caller's own game's function this month: a row a channel
|
|
298
|
+
// and a day, each with the game's allowance.
|
|
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));
|
|
301
|
+
}
|
|
302
|
+
// [function]
|
|
303
|
+
// pauses the function of the caller's own game on a channel.
|
|
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));
|
|
306
|
+
}
|
|
307
|
+
// [function]
|
|
308
|
+
// resumes the function of the caller's own game on a channel: lifts its
|
|
309
|
+
// owner's pause, and no other.
|
|
310
|
+
export function deleteGameFunctionPause(id, channel, params, headers) {
|
|
311
|
+
return del(endpoint(pathOf `/games/${id}/function_pauses/${channel}`, params), headers);
|
|
312
|
+
}
|
package/dist/arc.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// the entry: runs the command the first argument names, or with none, or
|
|
2
|
+
// one that isn't a command, prints the help, the version, or what's wrong.
|
|
3
|
+
// [import]
|
|
4
|
+
import { normalize } from "./cli/argv.js";
|
|
5
|
+
import { execute } from "./cli/command.js";
|
|
6
|
+
import { COMMANDS } from "./commands.js";
|
|
7
|
+
import { version } from "./config/package.js";
|
|
8
|
+
import { tool } from "./config/product.js";
|
|
9
|
+
import { hideBin, yargs } from "./cli/yargs.js";
|
|
10
|
+
// [declare]
|
|
11
|
+
const TOOL = tool;
|
|
12
|
+
const VERSION = version;
|
|
13
|
+
// [function]
|
|
14
|
+
// `arc` with no command: the help, which lists every command that isn't
|
|
15
|
+
// hidden, the version, or an argument that isn't a command, refused.
|
|
16
|
+
async function help(args) {
|
|
17
|
+
const cli = COMMANDS.filter((each) => !each.hidden)
|
|
18
|
+
.reduce((each, { name, summary }) => each.command(name, summary), yargs(normalize(args)).scriptName(TOOL).usage("$0 <command> [options]"))
|
|
19
|
+
.help("help")
|
|
20
|
+
.alias("help", "h")
|
|
21
|
+
.version(VERSION)
|
|
22
|
+
.alias("version", "v")
|
|
23
|
+
.strict();
|
|
24
|
+
const argv = await cli.parse();
|
|
25
|
+
if (!argv._.length) {
|
|
26
|
+
cli.showHelp();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// [function]
|
|
30
|
+
// a command is one only as the first argument.
|
|
31
|
+
async function main(args) {
|
|
32
|
+
const entry = COMMANDS.find((each) => each.name === args[0]);
|
|
33
|
+
if (!entry) {
|
|
34
|
+
await help(args);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const command = await entry.load();
|
|
38
|
+
await execute(command.default, args.slice(1));
|
|
39
|
+
}
|
|
40
|
+
// [start]
|
|
41
|
+
await main(hideBin(process.argv));
|