arcadible 1.0.40-next.0 → 1.0.40-next.1

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.
@@ -543,7 +543,9 @@ function skipsOf(body) {
543
543
  // but a player's, a guest's call for a player's, or a player who isn't the
544
544
  // one playing is 403. Only JSON is taken, as for a ticket, so a page
545
545
  // elsewhere can't ask. A refusal is its status, with no body, but a
546
- // conflict's (409), which names its items: `{ data: { conflicts } }`.
546
+ // conflict's (409), which names its items: `{ data: { conflicts } }`, and
547
+ // one that names its code (`too_many`), `{ data: { code, retry } }`, as the
548
+ // play site passes the API's on.
547
549
  async function sendGameValues(req, res, verb, { player, values }) {
548
550
  const refuse = function (status) {
549
551
  res.writeHead(status, HEADERS).end();
@@ -561,6 +563,16 @@ async function sendGameValues(req, res, verb, { player, values }) {
561
563
  let single = true;
562
564
  const answer = function (given, shape) {
563
565
  if (given.status !== 200 && given.status !== 409) {
566
+ if (given.code) {
567
+ res.writeHead(given.status, {
568
+ ...HEADERS,
569
+ "content-type": "application/json; charset=utf-8",
570
+ });
571
+ res.end(JSON.stringify({
572
+ data: { code: given.code, retry: retryOf(given.code) },
573
+ }));
574
+ return;
575
+ }
564
576
  refuse(given.status);
565
577
  return;
566
578
  }
@@ -684,9 +696,9 @@ function windowOf(pathname, named) {
684
696
  // [function]
685
697
  // a refusal in the API's own envelope: what it says of the status, and,
686
698
  // for a conflict, the items it names.
687
- function sendRefusal(req, res, status, conflicts) {
699
+ function sendRefusal(req, res, status, conflicts, named) {
688
700
  const [title, message] = REFUSALS[status] ?? ["", ""];
689
- const code = REFUSAL_CODES[status] ?? "invalid";
701
+ const code = named ?? REFUSAL_CODES[status] ?? "invalid";
690
702
  sendData(req, res, status, {
691
703
  code,
692
704
  message,
@@ -720,7 +732,7 @@ async function sendValues(req, res, verb, values) {
720
732
  sendRefusal(req, res, 409, conflictsAnswer(given.conflicts, single));
721
733
  }
722
734
  else {
723
- sendRefusal(req, res, given.status);
735
+ sendRefusal(req, res, given.status, undefined, given.code);
724
736
  }
725
737
  };
726
738
  if (verb === "list") {
@@ -807,8 +819,13 @@ async function sendServer(req, res, route, { game, tickets, values, wires, }) {
807
819
  }
808
820
  const asked = listed.split(",").map((id) => id.trim());
809
821
  const ids = [...new Set(asked)];
822
+ // past a call's players is too_many, as the API's PLAYERS_MAX answers
823
+ // it, where ids that aren't ids are invalid
824
+ if (ids.length > PLAYERS_MAX) {
825
+ sendRefusal(req, res, 400, undefined, "too_many");
826
+ return;
827
+ }
810
828
  if (asked.length > PLAYERS_ASKED_MAX ||
811
- ids.length > PLAYERS_MAX ||
812
829
  !ids.every((id) => PLAYER_ID.test(id))) {
813
830
  sendRefusal(req, res, 400);
814
831
  return;
@@ -20,6 +20,7 @@ const RETRIES = {
20
20
  no_function: "no",
21
21
  not_found: "no",
22
22
  too_large: "no",
23
+ too_many: "no",
23
24
  unavailable: "yes",
24
25
  };
25
26
  // [function]
@@ -61,15 +61,20 @@ function isRevision(value) {
61
61
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
62
62
  }
63
63
  // [function]
64
- // a call's items, or null: 1 to a call's keys, each an object with a scope,
64
+ // a call that names more items than a call takes: `too_many`, as the API's
65
+ // ITEMS_MAX answers it, where any other call that isn't one is `invalid`.
66
+ const TOO_MANY = { code: "too_many", data: null, status: 400 };
67
+ // [function]
68
+ // a call's items, or null, or TOO_MANY past a call's keys: 1 to a call's keys, each an object with a scope,
65
69
  // an owner, and a key, none named twice, and each of the verb's own fields
66
70
  // (`fields`) a revision where it's given; `value`, for a write, there.
67
71
  function itemsOf(given, fields, needsValue) {
68
- if (!Array.isArray(given) ||
69
- given.length < 1 ||
70
- given.length > LIMITS.callKeys) {
72
+ if (!Array.isArray(given) || given.length < 1) {
71
73
  return null;
72
74
  }
75
+ if (given.length > LIMITS.callKeys) {
76
+ return TOO_MANY;
77
+ }
73
78
  const seen = new Set();
74
79
  for (const item of given) {
75
80
  if (!isTable(item) ||
@@ -203,6 +208,9 @@ export function values({ isPlayer, now = () => Date.now(), root, }) {
203
208
  if (!items) {
204
209
  return { data: null, status: 400 };
205
210
  }
211
+ if (!Array.isArray(items)) {
212
+ return items;
213
+ }
206
214
  const refused = refusalOf(items);
207
215
  if (refused) {
208
216
  return { data: null, status: refused };
@@ -237,6 +245,9 @@ export function values({ isPlayer, now = () => Date.now(), root, }) {
237
245
  if (!items) {
238
246
  return { data: null, status: 400 };
239
247
  }
248
+ if (!Array.isArray(items)) {
249
+ return items;
250
+ }
240
251
  const refused = refusalOf(items);
241
252
  if (refused) {
242
253
  return { data: null, status: refused };
@@ -293,6 +304,9 @@ export function values({ isPlayer, now = () => Date.now(), root, }) {
293
304
  if (!items) {
294
305
  return { data: null, status: 400 };
295
306
  }
307
+ if (!Array.isArray(items)) {
308
+ return items;
309
+ }
296
310
  const refused = refusalOf(items);
297
311
  if (refused) {
298
312
  return { data: null, status: refused };
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "name": "arcadible",
45
- "version": "1.0.40-next.0"
45
+ "version": "1.0.40-next.1"
46
46
  },
47
47
  "node_modules/@cacheable/memory": {
48
48
  "dependencies": {
@@ -2433,5 +2433,5 @@
2433
2433
  }
2434
2434
  },
2435
2435
  "requires": true,
2436
- "version": "1.0.40-next.0"
2436
+ "version": "1.0.40-next.1"
2437
2437
  }
package/package.json CHANGED
@@ -66,5 +66,5 @@
66
66
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
67
67
  },
68
68
  "type": "module",
69
- "version": "1.0.40-next.0"
69
+ "version": "1.0.40-next.1"
70
70
  }