@arcadible/sdk 1.5.2-next.0 → 1.5.3-next.6

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.
@@ -0,0 +1,71 @@
1
+ // The page's side of `values`: a game's call to its values, passed to
2
+ // wherever the page asks (`call`), which is its own server. The page holds
3
+ // no rule: who may read and write which scope, the limits, and who's
4
+ // playing are its server's to say. The page says only what it must: that
5
+ // the call came from the game it serves.
6
+ // [import]
7
+ import { ArcadibleError, Codes, isObject, log, MAX_MESSAGE, messageSize, } from "../bus/protocol.js";
8
+ import { Names } from "./rules.js";
9
+ // The codes a page's `call` may refuse with; anything else is
10
+ // `unavailable`.
11
+ const REFUSALS = new Set([
12
+ Codes.Busy,
13
+ Codes.Conflict,
14
+ Codes.Denied,
15
+ Codes.Full,
16
+ Codes.Invalid,
17
+ Codes.TooLarge,
18
+ Codes.TooMany,
19
+ Codes.Unavailable,
20
+ ]);
21
+ const MESSAGES = {
22
+ [Codes.Busy]: "Too many calls. Wait a moment, and try again.",
23
+ [Codes.Conflict]: "The value was written since the revision named. Read it again.",
24
+ [Codes.Denied]: "A game reads the developer's and the game's values, and reads and writes its own player's, who's logged in.",
25
+ [Codes.Full]: "The player's storage is used up. Remove something first.",
26
+ [Codes.Invalid]: "Arcadible didn't take the call.",
27
+ [Codes.TooLarge]: "A value, or the call's values together, is too large.",
28
+ [Codes.TooMany]: "A call names up to 32 keys.",
29
+ };
30
+ const UNAVAILABLE = "The game's values can't be reached right now. Try again.";
31
+ // [function]
32
+ export function valuesServer(host) {
33
+ const run = function (verb) {
34
+ return async function (params) {
35
+ const body = params["body"];
36
+ if (typeof body !== "string") {
37
+ throw new ArcadibleError(Codes.Invalid, MESSAGES[Codes.Invalid] ?? "");
38
+ }
39
+ try {
40
+ const text = await host.call(verb, body);
41
+ if (typeof text !== "string")
42
+ throw new TypeError("not text");
43
+ // a read is held to what fits a message where it's kept; an answer
44
+ // that outgrew one on the way is said, not dropped
45
+ if (messageSize({ text }, MAX_MESSAGE) > MAX_MESSAGE - 1024) {
46
+ throw new ArcadibleError(Codes.TooLarge, "The values are too large to read together. Read fewer at once.");
47
+ }
48
+ return { text };
49
+ }
50
+ catch (err) {
51
+ if (err instanceof ArcadibleError)
52
+ throw err;
53
+ const refused = isObject(err) ? err["code"] : undefined;
54
+ if (typeof refused === "string" && REFUSALS.has(refused)) {
55
+ throw new ArcadibleError(refused, MESSAGES[refused] ?? UNAVAILABLE);
56
+ }
57
+ log("warn", "the game's values couldn't be reached.", err);
58
+ throw new ArcadibleError(Codes.Unavailable, UNAVAILABLE);
59
+ }
60
+ };
61
+ };
62
+ return () => ({
63
+ handlers: {
64
+ // beside the queue: each waits on the network, not on storage.
65
+ [Names.List]: { run: run("list"), parallel: true },
66
+ [Names.Read]: { run: run("read"), parallel: true },
67
+ [Names.Remove]: { run: run("remove"), parallel: true },
68
+ [Names.Write]: { run: run("write"), parallel: true },
69
+ },
70
+ });
71
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.5.2-next.0";
1
+ export declare const VERSION = "1.5.3-next.6";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // The client's version, sent in its hello and shown as `arcadible.version`,
2
2
  // for bug reports. It matches package.json (test/unit/protocol.test.ts).
3
- export const VERSION = "1.5.2-next.0";
3
+ export const VERSION = "1.5.3-next.6";
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  ],
44
44
  "type": "module",
45
45
  "types": "./dist/index.d.ts",
46
- "version": "1.5.2-next.0"
46
+ "version": "1.5.3-next.6"
47
47
  }