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,103 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { discoverGame, discoverGameBuild, discoverGameRepo, } from "../../api.js";
|
|
3
|
+
import { GAME_HANDLE_CHANGED, GAME_NOT_DEPLOYED, REPO_NOT_CONNECTED, WARNING, } from "../../config/code.js";
|
|
4
|
+
import { ArcError } from "../../util/error.js";
|
|
5
|
+
import { releasing } from "./game.js";
|
|
6
|
+
import { ensureClean, ensureRemote, ensureRepo, ensureRoot, ensureTagFree, ensureWorkflow, originRepo, } from "./git.js";
|
|
7
|
+
import { HttpError } from "../../util/http.js";
|
|
8
|
+
import { gameHandleChanged, gameNotDeployed, repoNotConnected, versionUnchecked, } from "../../phrase/index.js";
|
|
9
|
+
import { studioUrl } from "../../util/links.js";
|
|
10
|
+
import { ensureLockFile } from "./pm.js";
|
|
11
|
+
import { refuse } from "./published.js";
|
|
12
|
+
// [function]
|
|
13
|
+
// a public lookup's answer: found (200, with its data), missing (404), or
|
|
14
|
+
// null for any other answer, such as when the API can't be reached.
|
|
15
|
+
function answerOf(request) {
|
|
16
|
+
return request.then((data) => ({ data, status: 200 }), (err) => err instanceof HttpError && err.status === 404 ? { status: 404 } : null);
|
|
17
|
+
}
|
|
18
|
+
// [function]
|
|
19
|
+
// what Arcadible would refuse in the release, refused before the tag is pushed: a
|
|
20
|
+
// game that was never deployed (a release can't create one), a version
|
|
21
|
+
// that's already published, and a handle that isn't the game's (only a
|
|
22
|
+
// direct deploy changes one, so a collaborator's push can't). The lookups
|
|
23
|
+
// are public, so this needs no login.
|
|
24
|
+
// when Arcadible can't be reached, it warns and pushes anyway: a release
|
|
25
|
+
// shouldn't depend on the API, and Arcadible still checks.
|
|
26
|
+
function ensurePublishable({ handle, id, version }, handler) {
|
|
27
|
+
return Promise.all([
|
|
28
|
+
answerOf(discoverGame(id)),
|
|
29
|
+
answerOf(discoverGameBuild(id, version)),
|
|
30
|
+
]).then(([game, build]) => {
|
|
31
|
+
if (game?.status === 404) {
|
|
32
|
+
throw new ArcError(GAME_NOT_DEPLOYED, gameNotDeployed(handle ?? id));
|
|
33
|
+
}
|
|
34
|
+
if (game === null || build === null) {
|
|
35
|
+
if (handler.onWarning) {
|
|
36
|
+
handler.onWarning({
|
|
37
|
+
code: WARNING.VERSION_UNCHECKED,
|
|
38
|
+
message: versionUnchecked(version),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (build.status === 200) {
|
|
44
|
+
return refuse(id, version);
|
|
45
|
+
}
|
|
46
|
+
const current = game.data.handle ?? null;
|
|
47
|
+
if (handle !== current) {
|
|
48
|
+
throw new ArcError(GAME_HANDLE_CHANGED, gameHandleChanged(handle, current));
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// [function]
|
|
54
|
+
// the project's checks: a lockfile when there's a package.json, and a clean
|
|
55
|
+
// repository, whose root is the project, with the release workflow and a
|
|
56
|
+
// reachable origin.
|
|
57
|
+
function ensureProject(root) {
|
|
58
|
+
return ensureLockFile(root)
|
|
59
|
+
.then(() => ensureRepo(root))
|
|
60
|
+
.then(() => ensureRoot(root))
|
|
61
|
+
.then(() => ensureClean(root))
|
|
62
|
+
.then(() => ensureWorkflow(root))
|
|
63
|
+
.then(() => ensureRemote(root));
|
|
64
|
+
}
|
|
65
|
+
// [function]
|
|
66
|
+
// fails when origin isn't the game's connected repository, which Arcadible
|
|
67
|
+
// would refuse (repo_not_connected) once GitHub Actions had built it. It's
|
|
68
|
+
// asked by name, which needs no login, so it checks whoever pushes. Skipped
|
|
69
|
+
// when origin is a path on this machine, or Arcadible can't be reached.
|
|
70
|
+
function ensureConnected(root, { handle, id }) {
|
|
71
|
+
return originRepo(root).then((repo) => {
|
|
72
|
+
if (!repo) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return answerOf(discoverGameRepo(id, repo.owner, repo.name)).then((connected) => {
|
|
76
|
+
if (connected?.status === 404) {
|
|
77
|
+
throw new ArcError(REPO_NOT_CONNECTED, repoNotConnected(handle ?? id, `${repo.owner}/${repo.name}`, studioUrl(id, "repository")));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// [function]
|
|
83
|
+
// the release's checks: its tag is free, Arcadible would publish it, and
|
|
84
|
+
// origin is its connected repository. resolves with the version.
|
|
85
|
+
function ensureRelease(root, game, handler) {
|
|
86
|
+
return ensureTagFree(root, game.version)
|
|
87
|
+
.then(() => ensurePublishable(game, handler))
|
|
88
|
+
.then(() => ensureConnected(root, game))
|
|
89
|
+
.then(() => ({ to: game.version }));
|
|
90
|
+
}
|
|
91
|
+
// [function]
|
|
92
|
+
// a git deploy needs no login, and never uses one: anyone who can push can
|
|
93
|
+
// release, and so can tools other than arc. Every lookup is public, so its
|
|
94
|
+
// answer is the same whoever runs it, and true when it's asked; the release
|
|
95
|
+
// pipeline has the final word.
|
|
96
|
+
export function predeployToolGit(conf, { onPredeployBegin, ...handler }) {
|
|
97
|
+
const root = conf.root;
|
|
98
|
+
if (onPredeployBegin) {
|
|
99
|
+
onPredeployBegin();
|
|
100
|
+
}
|
|
101
|
+
const game = releasing(conf.project.game);
|
|
102
|
+
return ensureProject(root).then(() => ensureRelease(root, game, handler));
|
|
103
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { ensureId, ensureUnpublished } from "./ac.js";
|
|
3
|
+
import { releasing } from "./game.js";
|
|
4
|
+
// [function]
|
|
5
|
+
// a direct deploy needs a login. Each lookup uses its token or not, as it
|
|
6
|
+
// needs, and its answer is true when it's asked.
|
|
7
|
+
export function predeployTool(current, conf, { onPredeployBegin, ...handler }) {
|
|
8
|
+
if (onPredeployBegin) {
|
|
9
|
+
onPredeployBegin({ root: conf.root });
|
|
10
|
+
}
|
|
11
|
+
return ensureId(current, releasing(conf.project.game), handler)
|
|
12
|
+
.then((game) => ensureUnpublished(current, game))
|
|
13
|
+
.then((game) => ({ held: game.held, to: game.version }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// a runner's secrets: the values a game's runner needs and its repository
|
|
2
|
+
// mustn't hold, such as another service's key. Each is for one game and one
|
|
3
|
+
// channel, by the name the manifest declares (function.secrets), set by the
|
|
4
|
+
// game's owner, and never shown again. Nothing here keeps one.
|
|
5
|
+
import { deleteGameFunctionSecret, gameFunctionSecrets, putGameFunctionSecret, } from "../../api.js";
|
|
6
|
+
import { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
|
|
7
|
+
import { ArcError } from "../../util/error.js";
|
|
8
|
+
import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
|
|
9
|
+
import { gameUnavailable, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
|
|
10
|
+
// [declare]
|
|
11
|
+
// a secret's name, as an environment variable is named; ARCADIBLE_ is kept
|
|
12
|
+
// for Arcadible's own.
|
|
13
|
+
const NAME = /^(?!ARCADIBLE_)[A-Z][A-Z0-9_]{0,63}$/u;
|
|
14
|
+
const VALUE_MAX = 4096;
|
|
15
|
+
// [function]
|
|
16
|
+
// a secret's name as it was given, or a refusal before the API is asked.
|
|
17
|
+
function nameOf(name) {
|
|
18
|
+
if (typeof name !== "string" || !NAME.test(name)) {
|
|
19
|
+
throw new ArcError(ARGUMENT_INVALID, secretNameInvalid());
|
|
20
|
+
}
|
|
21
|
+
return name;
|
|
22
|
+
}
|
|
23
|
+
// [function]
|
|
24
|
+
// sets a secret, as `{ name, channel }`. `value()` resolves with its value,
|
|
25
|
+
// asked for only once the rest holds, so nothing is typed for a refusal.
|
|
26
|
+
export async function set(current, { channel, name, value, ...conf }) {
|
|
27
|
+
const named = nameOf(name);
|
|
28
|
+
const where = needOf(channel);
|
|
29
|
+
const id = await gameOf(conf);
|
|
30
|
+
const headers = headersOf(current);
|
|
31
|
+
const secret = await value();
|
|
32
|
+
if (typeof secret !== "string" ||
|
|
33
|
+
secret === "" ||
|
|
34
|
+
Buffer.byteLength(secret) > VALUE_MAX) {
|
|
35
|
+
throw new ArcError(ARGUMENT_INVALID, secretValueInvalid());
|
|
36
|
+
}
|
|
37
|
+
const form = new FormData();
|
|
38
|
+
form.append("value", secret);
|
|
39
|
+
try {
|
|
40
|
+
const kept = await putGameFunctionSecret(id, where, named, form, null, headers);
|
|
41
|
+
return { channel: kept.channel, name: kept.name };
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (isStatus(err, 404)) {
|
|
45
|
+
throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
|
|
46
|
+
cause: err,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (isStatus(err, 409)) {
|
|
50
|
+
throw new ArcError(API_REFUSED, secretLimitReached(where), {
|
|
51
|
+
cause: err,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// [function]
|
|
58
|
+
// the game's secrets, by channel and name, of one channel or both: each as
|
|
59
|
+
// `{ name, channel, updated_at }`, never a value.
|
|
60
|
+
export async function list(current, { channel, ...conf }) {
|
|
61
|
+
const where = channelOf(channel);
|
|
62
|
+
const id = await gameOf(conf);
|
|
63
|
+
const headers = headersOf(current);
|
|
64
|
+
const secrets = await gameFunctionSecrets(id, null, headers);
|
|
65
|
+
return (secrets ?? [])
|
|
66
|
+
.filter((secret) => !where || secret.channel === where)
|
|
67
|
+
.map((secret) => ({
|
|
68
|
+
channel: secret.channel,
|
|
69
|
+
name: secret.name,
|
|
70
|
+
updated_at: secret.updated_at,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
// [function]
|
|
74
|
+
// removes a secret, and resolves with `{ name, channel }`. One that isn't
|
|
75
|
+
// set, or isn't the game's, is the same to its owner: not found.
|
|
76
|
+
export async function remove(current, { channel, name, ...conf }) {
|
|
77
|
+
const named = nameOf(name);
|
|
78
|
+
const where = needOf(channel);
|
|
79
|
+
const id = await gameOf(conf);
|
|
80
|
+
const headers = headersOf(current);
|
|
81
|
+
try {
|
|
82
|
+
const gone = await deleteGameFunctionSecret(id, where, named, null, headers);
|
|
83
|
+
return { channel: gone.channel, name: gone.name };
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (isStatus(err, 404)) {
|
|
87
|
+
throw new ArcError(API_REFUSED, secretNotFound({ channel: where, name: named }), { cause: err });
|
|
88
|
+
}
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// arc serve: builds the project unless told not to, then serves deploy_dir
|
|
2
|
+
// framed in a local play page (src/serve), reloading the game when deploy_dir
|
|
3
|
+
// changes.
|
|
4
|
+
// [import]
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join, relative, resolve as resolvePath } from "node:path";
|
|
7
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
8
|
+
// [import]
|
|
9
|
+
import { pathExists } from "fs-extra";
|
|
10
|
+
// [import]
|
|
11
|
+
import { ARGUMENT_INVALID, DEPLOY_DIR_MISSING, PORT_IN_USE, } from "../../config/code.js";
|
|
12
|
+
import { buildCommand } from "../../util/command.js";
|
|
13
|
+
import { ArcError } from "../../util/error.js";
|
|
14
|
+
import { dirFiles } from "../../serve/files.js";
|
|
15
|
+
import { given } from "../../parser/given.js";
|
|
16
|
+
import * as phrase from "../../phrase/index.js";
|
|
17
|
+
import { media } from "../../parser/media.js";
|
|
18
|
+
import { textOf } from "../../util/objs.js";
|
|
19
|
+
import { configDir } from "../../util/os.js";
|
|
20
|
+
import { title, tool } from "../../config/product.js";
|
|
21
|
+
import { watchDir } from "../../serve/reload.js";
|
|
22
|
+
import { remoteFiles } from "../../serve/remote.js";
|
|
23
|
+
import { serve } from "../../serve/server.js";
|
|
24
|
+
import { playerOf } from "../../serve/ticket.js";
|
|
25
|
+
import { buildTool } from "../build/tool.js";
|
|
26
|
+
import { ARCADIBLE_SDK, HOST_HTTP_PLAY } from "../../config/uri.js";
|
|
27
|
+
// [declare]
|
|
28
|
+
// what build.channel says while served locally (docs: arc-serve.md).
|
|
29
|
+
const CHANNEL = "local";
|
|
30
|
+
// the saves of a game with no id yet, kept apart from any other's.
|
|
31
|
+
const UNNAMED = "local";
|
|
32
|
+
// [declare]
|
|
33
|
+
// the headers a page needs for the play page to frame it: the play page is
|
|
34
|
+
// cross-origin isolated, so a cross-origin frame must be too, and allow it.
|
|
35
|
+
const FRAMEABLE = {
|
|
36
|
+
"cross-origin-embedder-policy": ["credentialless", "require-corp"],
|
|
37
|
+
"cross-origin-resource-policy": ["cross-origin"],
|
|
38
|
+
};
|
|
39
|
+
// [declare]
|
|
40
|
+
// how long `url` has to answer before it counts as unreachable: a server
|
|
41
|
+
// that takes the connection and never answers would otherwise hold `arc
|
|
42
|
+
// serve` for minutes.
|
|
43
|
+
const PROBE_MS = 10000;
|
|
44
|
+
// [function]
|
|
45
|
+
// what `url` says when asked: `{ reachable, frameable }`, where `frameable`
|
|
46
|
+
// says whether it sends the headers the play page needs to frame it.
|
|
47
|
+
async function probe(url) {
|
|
48
|
+
try {
|
|
49
|
+
// null when it hasn't answered in time
|
|
50
|
+
const res = await Promise.race([
|
|
51
|
+
fetch(url, { method: "GET" }),
|
|
52
|
+
sleep(PROBE_MS, null, { ref: false }),
|
|
53
|
+
]);
|
|
54
|
+
if (!res) {
|
|
55
|
+
return { frameable: false, reachable: false };
|
|
56
|
+
}
|
|
57
|
+
await res.body?.cancel();
|
|
58
|
+
const frameable = Object.entries(FRAMEABLE).every(([name, values]) => {
|
|
59
|
+
const sent = res.headers.get(name)?.trim().toLowerCase();
|
|
60
|
+
return sent !== undefined && values.includes(sent);
|
|
61
|
+
});
|
|
62
|
+
return { frameable, reachable: true };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return { frameable: false, reachable: false };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// [function]
|
|
69
|
+
// one of the project's art files, read, or null for a field with none.
|
|
70
|
+
function readArt(root, file) {
|
|
71
|
+
return typeof file === "string" && file ? readFile(join(root, file)) : null;
|
|
72
|
+
}
|
|
73
|
+
// [function]
|
|
74
|
+
// the project's store icon, .arcadible/icon.png, or null: found by its exact
|
|
75
|
+
// name, as `arc deploy` finds it, each time it's asked for.
|
|
76
|
+
function storeIcon(root) {
|
|
77
|
+
return async () => {
|
|
78
|
+
const { game } = await media(root);
|
|
79
|
+
return readArt(root, game?.["icon"]);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// [function]
|
|
83
|
+
// the loading screen's art: the project's splash, else its banner, else its
|
|
84
|
+
// cover, as the play page picks it, or null; each time it's asked for.
|
|
85
|
+
function storeArt(root) {
|
|
86
|
+
return async () => {
|
|
87
|
+
const { game } = await media(root);
|
|
88
|
+
return readArt(root, game?.["splash"] ?? game?.["banner"] ?? game?.["cover"]);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// [function]
|
|
92
|
+
// listens, turning a port in use into its code.
|
|
93
|
+
async function listen(options) {
|
|
94
|
+
try {
|
|
95
|
+
return await serve(options);
|
|
96
|
+
}
|
|
97
|
+
catch (ex) {
|
|
98
|
+
if (ex instanceof Error && "code" in ex && ex.code === "EADDRINUSE") {
|
|
99
|
+
throw new ArcError(PORT_IN_USE, phrase.portInUse(options.port), {
|
|
100
|
+
cause: ex,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
throw ex;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// [function]
|
|
107
|
+
// a value of the manifest's as text, when it's text: the project is as it
|
|
108
|
+
// was parsed.
|
|
109
|
+
function text(value) {
|
|
110
|
+
return typeof value === "string" && value ? value : null;
|
|
111
|
+
}
|
|
112
|
+
// [function]
|
|
113
|
+
// the strings of a list the manifest has, or none: the project is as it was
|
|
114
|
+
// parsed, and arc serve doesn't validate it.
|
|
115
|
+
function strings(value) {
|
|
116
|
+
return Array.isArray(value)
|
|
117
|
+
? value.filter((item) => typeof item === "string")
|
|
118
|
+
: [];
|
|
119
|
+
}
|
|
120
|
+
// [function]
|
|
121
|
+
// serves the project at `conf.root`. `conf.build` false skips the build, and
|
|
122
|
+
// `conf.url` frames that server's page instead of serving deploy_dir.
|
|
123
|
+
// `conf.handler` hears `onBuild()` as a build starts, `onRemote(name, file,
|
|
124
|
+
// error)` for each of Arcadible's files, and `onReload()` for each reload.
|
|
125
|
+
// resolves with `{ page, game, built, deployDir, url, probed, version,
|
|
126
|
+
// close() }`, where `probed` is what `conf.url` answered.
|
|
127
|
+
export async function serveTool(conf) {
|
|
128
|
+
const { port, root, url } = conf;
|
|
129
|
+
const handler = {
|
|
130
|
+
onBuild() { },
|
|
131
|
+
onReload() { },
|
|
132
|
+
onRemote() { },
|
|
133
|
+
onRunnerError() { },
|
|
134
|
+
onRunnerInstall() { },
|
|
135
|
+
onRunnerStart() { },
|
|
136
|
+
...conf.handler,
|
|
137
|
+
};
|
|
138
|
+
const project = await given(conf);
|
|
139
|
+
const game = project.game;
|
|
140
|
+
// who the game runs for, by name (`--player`), or a guest
|
|
141
|
+
const player = playerOf(game.id ?? UNNAMED, conf.player);
|
|
142
|
+
if (player === false) {
|
|
143
|
+
throw new ArcError(ARGUMENT_INVALID, phrase.playerInvalid());
|
|
144
|
+
}
|
|
145
|
+
// whether to say how a server finds this arc serve: only for a game with
|
|
146
|
+
// servers of its own, or run for a player
|
|
147
|
+
const forServer = Boolean(project.server) || Boolean(player);
|
|
148
|
+
// the game's runner, when the project has one: its code, where its runtime
|
|
149
|
+
// is kept, and who hears how it's doing
|
|
150
|
+
const runs = project.function;
|
|
151
|
+
const main = runs?.main;
|
|
152
|
+
if (runs && typeof main !== "string") {
|
|
153
|
+
throw new TypeError("function.main must be a path.");
|
|
154
|
+
}
|
|
155
|
+
const runnerMain = typeof main === "string" ? resolvePath(root, main) : null;
|
|
156
|
+
const options = {
|
|
157
|
+
art: storeArt(root),
|
|
158
|
+
icon: storeIcon(root),
|
|
159
|
+
info: {
|
|
160
|
+
channel: CHANNEL,
|
|
161
|
+
id: game.id ?? UNNAMED,
|
|
162
|
+
title: text(game.title) ?? text(game.handle) ?? title,
|
|
163
|
+
version: game.version ?? null,
|
|
164
|
+
},
|
|
165
|
+
// arc serve's own tickets, signed with a key kept beside the session
|
|
166
|
+
keyFile: join(configDir(), tool, "ticket-key.json"),
|
|
167
|
+
onRemote: handler.onRemote,
|
|
168
|
+
player,
|
|
169
|
+
port,
|
|
170
|
+
root,
|
|
171
|
+
remote: remoteFiles({
|
|
172
|
+
dir: join(configDir(), tool, "sdk"),
|
|
173
|
+
host: HOST_HTTP_PLAY,
|
|
174
|
+
sdk: ARCADIBLE_SDK,
|
|
175
|
+
}),
|
|
176
|
+
...(runs && runnerMain
|
|
177
|
+
? {
|
|
178
|
+
runner: {
|
|
179
|
+
dir: join(configDir(), tool, "runner"),
|
|
180
|
+
handler: {
|
|
181
|
+
onError: handler.onRunnerError,
|
|
182
|
+
onInstall: handler.onRunnerInstall,
|
|
183
|
+
onStart: handler.onRunnerStart,
|
|
184
|
+
},
|
|
185
|
+
hosts: strings(runs.outbound_hosts),
|
|
186
|
+
main: runnerMain,
|
|
187
|
+
// the secrets the manifest names, from this process's own
|
|
188
|
+
// environment: one that isn't set is undefined in the code, as
|
|
189
|
+
// on Arcadible
|
|
190
|
+
secrets: Object.fromEntries(strings(runs.secrets).flatMap((name) => {
|
|
191
|
+
const value = process.env[name];
|
|
192
|
+
return typeof value === "string" ? [[name, value]] : [];
|
|
193
|
+
})),
|
|
194
|
+
},
|
|
195
|
+
}
|
|
196
|
+
: {}),
|
|
197
|
+
servers: strings(project.server?.origins),
|
|
198
|
+
...(conf.host ? { hostFile: resolvePath(root, conf.host) } : {}),
|
|
199
|
+
};
|
|
200
|
+
// the runner's code, watched: a change runs the new code
|
|
201
|
+
const watchRunner = function (served) {
|
|
202
|
+
const running = served.runner;
|
|
203
|
+
if (!running || !runnerMain) {
|
|
204
|
+
return () => null;
|
|
205
|
+
}
|
|
206
|
+
return watchDir(dirname(runnerMain), () => {
|
|
207
|
+
void running.restart();
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
const version = game.version ?? null;
|
|
211
|
+
if (url) {
|
|
212
|
+
const served = await listen({ ...options, src: url });
|
|
213
|
+
const probed = await probe(url);
|
|
214
|
+
const unwatch = watchRunner(served);
|
|
215
|
+
return {
|
|
216
|
+
...served,
|
|
217
|
+
built: false,
|
|
218
|
+
close() {
|
|
219
|
+
unwatch();
|
|
220
|
+
served.close();
|
|
221
|
+
},
|
|
222
|
+
deployDir: null,
|
|
223
|
+
forServer,
|
|
224
|
+
probed,
|
|
225
|
+
url,
|
|
226
|
+
version,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// arc serve validates nothing, so a deploy_dir that isn't a path is said
|
|
230
|
+
// as what it is, a folder that isn't there
|
|
231
|
+
const dir = project.workflow.deploy_dir;
|
|
232
|
+
if (typeof dir !== "string") {
|
|
233
|
+
throw new ArcError(DEPLOY_DIR_MISSING, phrase.deployDirMissing(textOf(dir) || "deploy_dir"));
|
|
234
|
+
}
|
|
235
|
+
const built = conf.build !== false && Boolean(buildCommand(project.workflow.build));
|
|
236
|
+
if (built) {
|
|
237
|
+
handler.onBuild();
|
|
238
|
+
await buildTool({
|
|
239
|
+
project: {
|
|
240
|
+
function: project.function,
|
|
241
|
+
workflow: { build: project.workflow.build, deploy_dir: dir },
|
|
242
|
+
},
|
|
243
|
+
root,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const deployDir = resolvePath(root, dir);
|
|
247
|
+
if (!(await pathExists(deployDir))) {
|
|
248
|
+
throw new ArcError(DEPLOY_DIR_MISSING, phrase.deployDirMissing(relative(root, deployDir) || "."));
|
|
249
|
+
}
|
|
250
|
+
const served = await listen({ ...options, files: dirFiles(deployDir) });
|
|
251
|
+
const stop = watchDir(deployDir, () => {
|
|
252
|
+
served.reload();
|
|
253
|
+
handler.onReload();
|
|
254
|
+
});
|
|
255
|
+
const unwatch = watchRunner(served);
|
|
256
|
+
return {
|
|
257
|
+
...served,
|
|
258
|
+
built,
|
|
259
|
+
close() {
|
|
260
|
+
stop();
|
|
261
|
+
unwatch();
|
|
262
|
+
served.close();
|
|
263
|
+
},
|
|
264
|
+
deployDir,
|
|
265
|
+
forServer,
|
|
266
|
+
probed: null,
|
|
267
|
+
url: null,
|
|
268
|
+
version,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { VALIDATION_FAILED } from "../../config/code.js";
|
|
3
|
+
import { ArcError } from "../../util/error.js";
|
|
4
|
+
import { issuesFound } from "../../phrase/index.js";
|
|
5
|
+
import { project } from "../../parser/project.js";
|
|
6
|
+
import { validateTool } from "./tool.js";
|
|
7
|
+
// [function]
|
|
8
|
+
// whether a project is checked, which it is when validating it found no
|
|
9
|
+
// issues: each table then passed its schema, which changes nothing it reads.
|
|
10
|
+
function isChecked(_parsed, issues) {
|
|
11
|
+
return !issues.length;
|
|
12
|
+
}
|
|
13
|
+
// [function]
|
|
14
|
+
// parses and validates the project at `root` for a command that goes on from
|
|
15
|
+
// it (arc build, arc pack, arc deploy): resolves with the parsed project, or
|
|
16
|
+
// rejects as validation_failed with its issues in `data`. `onWarnings` gets
|
|
17
|
+
// the warnings either way, for --json to list beside the result or the error.
|
|
18
|
+
export async function checked(root, onWarnings) {
|
|
19
|
+
const parsed = await project(root);
|
|
20
|
+
const { issues, warnings } = await validateTool({ project: parsed, root });
|
|
21
|
+
onWarnings(warnings);
|
|
22
|
+
if (!isChecked(parsed, issues)) {
|
|
23
|
+
throw new ArcError(VALIDATION_FAILED, issuesFound(issues.length), {
|
|
24
|
+
data: { issues },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { game } from "../../schema/game.js";
|
|
3
|
+
import { given } from "../../parser/given.js";
|
|
4
|
+
import { readme } from "../../schema/readme.js";
|
|
5
|
+
import { read } from "../../parser/readme-file.js";
|
|
6
|
+
import { runner } from "../../schema/runner.js";
|
|
7
|
+
import { compare, validator } from "../../util/schema.js";
|
|
8
|
+
import { split } from "../../parser/sections.js";
|
|
9
|
+
import { server } from "../../schema/server.js";
|
|
10
|
+
import { unknown } from "./unknown.js";
|
|
11
|
+
import { unsound } from "./unsound.js";
|
|
12
|
+
import { workflow } from "../../schema/workflow.js";
|
|
13
|
+
// [define]
|
|
14
|
+
const gameValidator = validator("game", game);
|
|
15
|
+
const readmeValidator = validator("game", readme);
|
|
16
|
+
const runnerValidator = validator("function", runner);
|
|
17
|
+
const serverValidator = validator("server", server);
|
|
18
|
+
const workflowValidator = validator("workflow", workflow);
|
|
19
|
+
// [function]
|
|
20
|
+
// the README's structure, for its validator, or null without a README.
|
|
21
|
+
function structure(root) {
|
|
22
|
+
return read(root).then((file) => {
|
|
23
|
+
if (!file) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const { rules, trailing } = split(file.doc);
|
|
27
|
+
return { file: file.file, rules, trailing };
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// [function]
|
|
31
|
+
function validate(proj, readmeStructure, { root }) {
|
|
32
|
+
const results = [
|
|
33
|
+
gameValidator(proj.game, { root }),
|
|
34
|
+
workflowValidator(proj.workflow, { root }),
|
|
35
|
+
];
|
|
36
|
+
if (proj.function) {
|
|
37
|
+
results.push(runnerValidator(proj.function));
|
|
38
|
+
}
|
|
39
|
+
if (proj.server) {
|
|
40
|
+
results.push(serverValidator(proj.server));
|
|
41
|
+
}
|
|
42
|
+
if (readmeStructure) {
|
|
43
|
+
const { file, ...value } = readmeStructure;
|
|
44
|
+
results.push(readmeValidator(value, { file }));
|
|
45
|
+
}
|
|
46
|
+
return results.flatMap((result) => result.issues).sort(compare);
|
|
47
|
+
}
|
|
48
|
+
// [function]
|
|
49
|
+
// the project's issues, which fail it, and its warnings, which don't.
|
|
50
|
+
export function validateTool(conf) {
|
|
51
|
+
const root = conf.root;
|
|
52
|
+
return Promise.all([given(conf), structure(root), unknown(root)]).then(([proj, readmeStructure, warnings]) => ({
|
|
53
|
+
issues: validate(proj, readmeStructure, { root }),
|
|
54
|
+
warnings: [...warnings, ...unsound(proj)].sort(compare),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { WARNING } from "../../config/code.js";
|
|
3
|
+
import { game } from "../../schema/game.js";
|
|
4
|
+
import { didYouMean, unknownField, unknownTable } from "../../phrase/index.js";
|
|
5
|
+
import { manifest } from "../../parser/manifest.js";
|
|
6
|
+
import { isTable } from "../../util/objs.js";
|
|
7
|
+
import { runner } from "../../schema/runner.js";
|
|
8
|
+
import { server } from "../../schema/server.js";
|
|
9
|
+
import { closest } from "../../util/strs.js";
|
|
10
|
+
import { workflow } from "../../schema/workflow.js";
|
|
11
|
+
// [function]
|
|
12
|
+
// the fields each table takes, from its schema.
|
|
13
|
+
function known(root) {
|
|
14
|
+
return {
|
|
15
|
+
function: Object.keys(runner().shape),
|
|
16
|
+
game: Object.keys(game({}, { root }).shape),
|
|
17
|
+
server: Object.keys(server().shape),
|
|
18
|
+
workflow: Object.keys(workflow({}, { root }).shape),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// [function]
|
|
22
|
+
// a warning, in an issue's shape: Arcadible ignores what it doesn't know, so
|
|
23
|
+
// it's reported without failing, with the name it might have meant.
|
|
24
|
+
function warning(path, message, near) {
|
|
25
|
+
return {
|
|
26
|
+
code: WARNING.FIELD_UNKNOWN,
|
|
27
|
+
details: near ? [didYouMean(near)] : [],
|
|
28
|
+
link: null,
|
|
29
|
+
message,
|
|
30
|
+
path,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// [function]
|
|
34
|
+
// a value outside any table, such as a `handle` above `[game]`: the field
|
|
35
|
+
// it is, in the table that takes it, if any.
|
|
36
|
+
function untabled(fields, name) {
|
|
37
|
+
const table = Object.keys(fields).find((each) => (fields[each] ?? []).includes(name));
|
|
38
|
+
return warning(name, unknownField(), table ? `${table}.${name}` : null);
|
|
39
|
+
}
|
|
40
|
+
// [function]
|
|
41
|
+
// the tables and fields in arcadible.toml that Arcadible doesn't know, such
|
|
42
|
+
// as a misspelled `genre`, as warnings.
|
|
43
|
+
export function unknown(root) {
|
|
44
|
+
const fields = known(root);
|
|
45
|
+
const tables = Object.keys(fields);
|
|
46
|
+
return manifest(root).then((conf) => Object.entries(conf).flatMap(([table, values]) => {
|
|
47
|
+
const taken = Object.hasOwn(fields, table) ? fields[table] : undefined;
|
|
48
|
+
if (!isTable(values)) {
|
|
49
|
+
return taken ? [] : [untabled(fields, table)];
|
|
50
|
+
}
|
|
51
|
+
if (!taken) {
|
|
52
|
+
return [warning(table, unknownTable(), closest(table, tables))];
|
|
53
|
+
}
|
|
54
|
+
return Object.keys(values)
|
|
55
|
+
.filter((field) => !taken.includes(field))
|
|
56
|
+
.map((field) => warning(`${table}.${field}`, unknownField(), closest(field, taken)));
|
|
57
|
+
}));
|
|
58
|
+
}
|