@arcadible/sdk 0.3.1 → 1.1.0
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 -1
- package/dist/bus/protocol.d.ts +3 -5
- package/dist/bus/protocol.js +9 -12
- package/dist/host.d.ts +1 -3
- package/dist/host.js +1 -1
- package/dist/saves/rules.d.ts +0 -1
- package/dist/saves/rules.js +1 -1
- package/dist/saves/server.d.ts +3 -4
- package/dist/saves/server.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ const progress = saved ? JSON.parse(saved) : { level: 1 };
|
|
|
46
46
|
await arcadible.saves.write("progress", JSON.stringify(progress));
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
A save is a name holding one string. `ready` settles once the game's saves have loaded, and never fails; from then on, `readSync` answers from memory. Every call that fails rejects with an `ArcadibleError`, whose `code` says what to do.
|
|
49
|
+
A save is a name holding one string. `ready` settles once the game's saves have loaded, and never fails; from then on, `readSync` answers from memory. Every call that fails rejects (or, for `readSync`, throws) with an `ArcadibleError`, whose `code` says what to do.
|
|
50
50
|
|
|
51
51
|
Off Arcadible, such as on your dev server, the package works on its own, with the same rules and limits: saves are kept on the page's own origin, and `arcadible.build` is `null`.
|
|
52
52
|
|
package/dist/bus/protocol.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export declare const BUS_VERSION = 1;
|
|
2
2
|
export declare const HANDSHAKE_TIMEOUT = 1000;
|
|
3
3
|
export declare const REQUEST_TIMEOUT = 10000;
|
|
4
|
-
export declare const HOST_ORIGINS: readonly string[];
|
|
5
|
-
export declare const LOCAL_ORIGIN: RegExp;
|
|
6
4
|
export declare function isHostOrigin(origin: string, origins: readonly string[] | undefined): boolean;
|
|
7
5
|
export declare const MAX_IN_FLIGHT = 64;
|
|
8
6
|
export declare const MAX_MESSAGE: number;
|
|
@@ -42,7 +40,7 @@ export type Request = {
|
|
|
42
40
|
name: string;
|
|
43
41
|
params?: unknown;
|
|
44
42
|
};
|
|
45
|
-
|
|
43
|
+
type Response = {
|
|
46
44
|
kind: "response";
|
|
47
45
|
id: number;
|
|
48
46
|
result: unknown;
|
|
@@ -51,7 +49,7 @@ export type Response = {
|
|
|
51
49
|
id: number;
|
|
52
50
|
error: ErrorBody;
|
|
53
51
|
};
|
|
54
|
-
|
|
52
|
+
type BusEvent = {
|
|
55
53
|
kind: "event";
|
|
56
54
|
name: string;
|
|
57
55
|
data?: unknown;
|
|
@@ -62,9 +60,9 @@ export declare class ArcadibleError extends Error {
|
|
|
62
60
|
constructor(code: Code, message: string);
|
|
63
61
|
toJSON(): ErrorBody;
|
|
64
62
|
}
|
|
65
|
-
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
66
63
|
export declare function isHello(value: unknown): value is Hello;
|
|
67
64
|
export declare function isWelcome(value: unknown): value is Welcome;
|
|
68
65
|
export declare function isMessage(value: unknown): value is Message;
|
|
69
66
|
export declare function utf8Size(text: string): number;
|
|
70
67
|
export declare function messageSize(value: unknown, limit?: number): number;
|
|
68
|
+
export {};
|
package/dist/bus/protocol.js
CHANGED
|
@@ -9,22 +9,19 @@ export const BUS_VERSION = 1;
|
|
|
9
9
|
export const HANDSHAKE_TIMEOUT = 1000;
|
|
10
10
|
// How long a request waits for its response.
|
|
11
11
|
export const REQUEST_TIMEOUT = 10_000;
|
|
12
|
-
// The play pages a game accepts a welcome from: production's, and `arc
|
|
13
|
-
// serve`'s on this machine. Another development page (play.arcadible.test)
|
|
14
|
-
// is passed with `createClient({ origins })`, never trusted by what games
|
|
15
|
-
// ship, since a hostile network could pose as an http one.
|
|
16
|
-
export const HOST_ORIGINS = ["https://play.arcadible.com"];
|
|
17
|
-
// `arc serve`'s play page, on any port. The network can't pose as loopback,
|
|
18
|
-
// and on Arcadible a build's `frame-ancestors` lets only the play page frame
|
|
19
|
-
// it, so no local page can reach a player's saves there.
|
|
20
|
-
export const LOCAL_ORIGIN = /^http:\/\/localhost:\d+$/u;
|
|
21
12
|
// [function]
|
|
22
13
|
// Whether a game accepts a welcome from `origin`: one of `origins` when it
|
|
23
|
-
// was given, or else
|
|
14
|
+
// was given (tests, and development pages), or else any real origin, `http`
|
|
15
|
+
// included, whatever framed it. Who may frame a build is decided outside the
|
|
16
|
+
// game, where it can change: on Arcadible by each build's `frame-ancestors`,
|
|
17
|
+
// which the browser enforces before the game runs, and elsewhere by whoever
|
|
18
|
+
// serves it. So the host is never trusted with anything of value (DESIGN.md,
|
|
19
|
+
// section 4). Only `null` is refused: a `file://` page or a sandboxed frame,
|
|
20
|
+
// which can't be told apart.
|
|
24
21
|
export function isHostOrigin(origin, origins) {
|
|
25
22
|
return origins
|
|
26
23
|
? origins.includes(origin)
|
|
27
|
-
:
|
|
24
|
+
: origin !== "null" && origin !== "";
|
|
28
25
|
}
|
|
29
26
|
// The most requests one game can have waiting on the page; past it, a
|
|
30
27
|
// request fails with `busy`.
|
|
@@ -65,7 +62,7 @@ export class ArcadibleError extends Error {
|
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
// [function]
|
|
68
|
-
|
|
65
|
+
function isObject(value) {
|
|
69
66
|
return typeof value === "object" && value !== null;
|
|
70
67
|
}
|
|
71
68
|
// [function]
|
package/dist/host.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type ServeOptions = {
|
|
|
7
7
|
backend: Backend;
|
|
8
8
|
now?: () => Date;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type HostOptions = ServeOptions & {
|
|
11
11
|
frame: HTMLIFrameElement;
|
|
12
12
|
origin: string;
|
|
13
13
|
window?: Window;
|
|
@@ -18,6 +18,4 @@ export declare function createHost(options: HostOptions): {
|
|
|
18
18
|
};
|
|
19
19
|
export type { Server } from "./bus/server.js";
|
|
20
20
|
export { indexedDBBackend } from "./saves/backend/indexeddb.js";
|
|
21
|
-
export type { IndexedDBOptions } from "./saves/backend/indexeddb.js";
|
|
22
21
|
export { memoryBackend } from "./saves/backend/memory.js";
|
|
23
|
-
export type { Backend, Change, NewRecord, SaveRecord, Scope, } from "./saves/backend/types.js";
|
package/dist/host.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// The page's side of the bus. The play page uses `createHost`;
|
|
2
2
|
// a game standing alone runs `serve` in its own page.
|
|
3
3
|
// [import]
|
|
4
4
|
import { answerHellos, createServer } from "./bus/server.js";
|
package/dist/saves/rules.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ export type SavesChange = {
|
|
|
28
28
|
save: Save | null;
|
|
29
29
|
revision: number;
|
|
30
30
|
};
|
|
31
|
-
export declare function isWellFormed(text: string): boolean;
|
|
32
31
|
export declare function checkName(name: unknown): ArcadibleError | null;
|
|
33
32
|
export declare function checkWrite(saves: ReadonlyMap<string, {
|
|
34
33
|
info: SaveMeta;
|
package/dist/saves/rules.js
CHANGED
|
@@ -11,7 +11,7 @@ const NAME = /^[A-Za-z0-9_.-]{1,64}$/u;
|
|
|
11
11
|
// A lone surrogate: half a character, which storage and the network corrupt.
|
|
12
12
|
const LONE_SURROGATE = /\p{Surrogate}/u;
|
|
13
13
|
// [function]
|
|
14
|
-
|
|
14
|
+
function isWellFormed(text) {
|
|
15
15
|
return !LONE_SURROGATE.test(text);
|
|
16
16
|
}
|
|
17
17
|
// [function]
|
package/dist/saves/server.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Module, ModuleContext } from "../bus/server.js";
|
|
2
|
-
import type { Backend,
|
|
3
|
-
|
|
4
|
-
export type SavesServerOptions = {
|
|
2
|
+
import type { Backend, Scope } from "./backend/types.js";
|
|
3
|
+
type SavesServerOptions = {
|
|
5
4
|
scope: Scope;
|
|
6
5
|
version: string | null;
|
|
7
6
|
backend: Backend;
|
|
8
7
|
now: () => Date;
|
|
9
8
|
};
|
|
10
|
-
export declare function toSave(record: SaveRecord): Save;
|
|
11
9
|
export declare function savesServer(options: SavesServerOptions): (context: ModuleContext) => Module;
|
|
10
|
+
export {};
|
package/dist/saves/server.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { ArcadibleError, Codes, utf8Size } from "../bus/protocol.js";
|
|
6
6
|
import { checkName, checkWrite, } from "./rules.js";
|
|
7
7
|
// [function]
|
|
8
|
-
|
|
8
|
+
function toSave(record) {
|
|
9
9
|
const { name, data, version, savedAt, size, revision } = record;
|
|
10
10
|
return { name, data, info: { version, savedAt, size, revision } };
|
|
11
11
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "1.1.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED