arcadible 0.1.44 → 0.1.45

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/package.json CHANGED
@@ -75,5 +75,5 @@
75
75
  "scripts": {
76
76
  "test": "node --test \"test/**/*.test.js\""
77
77
  },
78
- "version": "0.1.44"
78
+ "version": "0.1.45"
79
79
  }
@@ -3,7 +3,7 @@
3
3
  // [import]
4
4
 
5
5
  const links = require("../../util/links");
6
- const project = require("../../parser/project");
6
+ const self = require("../../parser/self");
7
7
 
8
8
  // [function]
9
9
 
@@ -20,7 +20,7 @@ const open = function (id) {
20
20
  // [function]
21
21
 
22
22
  const openSelf = function (root) {
23
- return project(root).then(({ game }) => openUrl(game?.handle ?? game?.id));
23
+ return self(root).then((game) => openUrl(game?.handle ?? game?.id));
24
24
  };
25
25
 
26
26
  // [function]
@@ -44,6 +44,8 @@ const SIZE_PARTIAL = size.mb(64);
44
44
 
45
45
  // [function]
46
46
 
47
+ // the files' own limits come first, since they name what to fix, such as
48
+ // the one file over 64 MB that makes the zip too large.
47
49
  const verifyPartial = function (zip) {
48
50
  if (!zip.has(MAIN)) {
49
51
  throw new ArcError(
@@ -51,6 +53,7 @@ const verifyPartial = function (zip) {
51
53
  phrase.packageFileMissing(MAIN),
52
54
  );
53
55
  }
56
+ limits.check(zip.entries());
54
57
  if (zip.stat().size > SIZE_PARTIAL) {
55
58
  throw new ArcError(
56
59
  cfgcode.PACKAGE_TOO_LARGE,
@@ -7,7 +7,7 @@ const cfgcode = require("../../config/code");
7
7
  const error = require("../../util/error");
8
8
  const links = require("../../util/links");
9
9
  const phrase = require("../../phrase");
10
- const project = require("../../parser/project");
10
+ const self = require("../../parser/self");
11
11
 
12
12
  // [use]
13
13
 
@@ -78,8 +78,8 @@ const play = function (id, release) {
78
78
  // this project's game: its orientation comes from the manifest. With a
79
79
  // chosen release, it makes no API call.
80
80
  const playSelf = function (root, release) {
81
- return project(root)
82
- .then(({ game }) => {
81
+ return self(root)
82
+ .then((game) => {
83
83
  const id = game?.handle ?? game?.id;
84
84
  if (!id) {
85
85
  return [null, null];
@@ -14,16 +14,19 @@ const ArcError = error.ArcError;
14
14
 
15
15
  // [function]
16
16
 
17
- // fails when `idOrHandle` is another game's, or this game's on another
18
- // account. A game that isn't on Arcadible yet passes.
19
- const ensureGame = function (current, idOrHandle, id) {
20
- return api.discoverGame(idOrHandle).then(
17
+ // fails when the game is on Arcadible on another account: it was deleted
18
+ // (the API doesn't find it, and the upload is refused), or it's someone
19
+ // else's. A game that isn't on Arcadible yet passes.
20
+ const ensureOwned = function (current, id) {
21
+ return api.discoverGame(id).then(
21
22
  (game) => {
22
- // a token's account isn't known yet, so only the id is compared; the
23
- // server checks ownership when it authorizes the upload.
24
- const owned = current?.token || game.account === current?.user?.id;
25
- if (!owned || game.id !== id) {
26
- throw new ArcError(cfgcode.GAME_EXISTS, phrase.gameExists(idOrHandle));
23
+ // a token's account isn't known yet; the server checks ownership when
24
+ // it authorizes the upload.
25
+ if (!current?.token && game.account !== current?.user?.id) {
26
+ throw new ArcError(
27
+ cfgcode.GAME_UNAVAILABLE,
28
+ phrase.gameUnavailable(id),
29
+ );
27
30
  }
28
31
  },
29
32
  (err) => {
@@ -36,12 +39,27 @@ const ensureGame = function (current, idOrHandle, id) {
36
39
 
37
40
  // [function]
38
41
 
39
- // a game without a handle has none to check.
40
- const ensureHandle = function (current, { handle, id }) {
42
+ // fails when the handle is another game's, whoever owns it. A game without a
43
+ // handle has none to check.
44
+ const ensureHandle = function ({ handle, id }) {
41
45
  if ((handle ?? null) === null) {
42
46
  return Promise.resolve(null);
43
47
  }
44
- return ensureGame(current, handle, id);
48
+ return api.discoverGame(handle).then(
49
+ (game) => {
50
+ if (game.id !== id) {
51
+ throw new ArcError(
52
+ cfgcode.GAME_HANDLE_TAKEN,
53
+ phrase.gameHandleTaken(handle),
54
+ );
55
+ }
56
+ },
57
+ (err) => {
58
+ if (err.status !== 404) {
59
+ throw err;
60
+ }
61
+ },
62
+ );
45
63
  };
46
64
 
47
65
  // [function]
@@ -49,8 +67,8 @@ const ensureHandle = function (current, { handle, id }) {
49
67
  // resolves with the game once its id, and its handle if it has one, are
50
68
  // free or already its own.
51
69
  const ensureId = function (current, game) {
52
- return ensureGame(current, game.id, game.id)
53
- .then(() => ensureHandle(current, game))
70
+ return ensureOwned(current, game.id)
71
+ .then(() => ensureHandle(game))
54
72
  .then(() => game);
55
73
  };
56
74
 
@@ -13,7 +13,7 @@ const CLI = {
13
13
  ARGUMENT_INVALID: "argument_invalid",
14
14
  BUILD_FAILED: "build_failed",
15
15
  DEPLOY_DIR_MISSING: "deploy_dir_missing",
16
- GAME_EXISTS: "game_exists",
16
+ GAME_HANDLE_TAKEN: "game_handle_taken",
17
17
  GAME_ID_MISSING: "game_id_missing",
18
18
  GAME_NOT_DEPLOYED: "game_not_deployed",
19
19
  GAME_NOT_FOUND: "game_not_found",
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const cfgcode = require("../config/code");
6
+ const project = require("./project");
7
+
8
+ // [function]
9
+
10
+ // the game of the project at `root`, for `arc play` and `arc open` with no
11
+ // game named; null outside a project, so they ask for a game
12
+ // (game_id_missing) rather than for a project.
13
+ const main = function (root) {
14
+ return project(root).then(
15
+ ({ game }) => game,
16
+ (ex) => {
17
+ if (ex.code === cfgcode.MANIFEST_MISSING) {
18
+ return null;
19
+ }
20
+ throw ex;
21
+ },
22
+ );
23
+ };
24
+
25
+ // [export]
26
+
27
+ module.exports = main;
package/src/phrase.js CHANGED
@@ -165,8 +165,11 @@ const errorCode = function (code) {
165
165
 
166
166
  // [function]
167
167
 
168
- const gameExists = function (idOrHandle) {
169
- return `Game exists: ${idOrHandle}`;
168
+ const gameHandleTaken = function (handle) {
169
+ return blocks(
170
+ `Handle taken: ${handle}`,
171
+ "Choose another handle in arcadible.toml.",
172
+ );
170
173
  };
171
174
 
172
175
  // [function]
@@ -390,7 +393,7 @@ const loginFailed = function () {
390
393
  const noGameId = function () {
391
394
  return blocks(
392
395
  "No game handle or ID.",
393
- `Pass one, or run ${cmdInit()} to add an ID.`,
396
+ `Pass one, or run it in a project after ${cmdInit()} has added an ID.`,
394
397
  );
395
398
  };
396
399
 
@@ -794,7 +797,7 @@ module.exports = {
794
797
  docTagUnallowed,
795
798
  docUnsupported,
796
799
  errorCode,
797
- gameExists,
800
+ gameHandleTaken,
798
801
  gameNotDeployed,
799
802
  gameNotFound,
800
803
  gameRepoMissing,