@hadoku/platform-wire 0.1.125 → 0.1.127
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,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an external game says about itself: the one file a game publishes beside its embed entry,
|
|
3
|
+
* `manifest.json`, which a host reads to make that game a room type. The game owns these facts
|
|
4
|
+
* (its name, how many players it takes, how long it holds a dropped seat); the host owns
|
|
5
|
+
* everything else about it (whether it is hosted at all, who may play it, where its bundle lives),
|
|
6
|
+
* and nothing in a manifest can change those.
|
|
7
|
+
*
|
|
8
|
+
* Written by `@hadoku/ui-shell/embed/vite`'s `embedBuild({ manifest })`, or by hand beside an
|
|
9
|
+
* embed built some other way; read by a host's server, which validates it with this schema and
|
|
10
|
+
* keeps the last good copy. Unknown keys are dropped, not refused, so a game can publish a field
|
|
11
|
+
* a host learns to read later.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
/** The manifest's file name, in the same directory as the embed entry it describes. */
|
|
15
|
+
export declare const EXTERNAL_GAME_MANIFEST_FILE = "manifest.json";
|
|
16
|
+
/** The most seats any external game's room takes: a host's own ceiling, whatever a manifest asks. */
|
|
17
|
+
export declare const EXTERNAL_GAME_MAX_SEATS = 16;
|
|
18
|
+
/** How long a dropped seat is held when a manifest names no hold of its own. */
|
|
19
|
+
export declare const DEFAULT_SEAT_REJOIN_GRACE_MS = 120000;
|
|
20
|
+
/** The longest hold a manifest may ask for. */
|
|
21
|
+
export declare const MAX_SEAT_REJOIN_GRACE_MS: number;
|
|
22
|
+
export declare const externalGameManifest: z.ZodObject<{
|
|
23
|
+
label: z.ZodString;
|
|
24
|
+
seats: z.ZodObject<{
|
|
25
|
+
min: z.ZodNumber;
|
|
26
|
+
max: z.ZodNumber;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
seatRejoinGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
/** A manifest as a game writes it (the hold may be left out). */
|
|
31
|
+
export type ExternalGameManifestInput = z.input<typeof externalGameManifest>;
|
|
32
|
+
/** A manifest as a host reads it, every default applied. */
|
|
33
|
+
export type ExternalGameManifest = z.output<typeof externalGameManifest>;
|
|
34
|
+
/** The manifest's path for an embed entry's path: the same directory, `manifest.json`. */
|
|
35
|
+
export declare function manifestPathOf(embedSrc: string): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an external game says about itself: the one file a game publishes beside its embed entry,
|
|
3
|
+
* `manifest.json`, which a host reads to make that game a room type. The game owns these facts
|
|
4
|
+
* (its name, how many players it takes, how long it holds a dropped seat); the host owns
|
|
5
|
+
* everything else about it (whether it is hosted at all, who may play it, where its bundle lives),
|
|
6
|
+
* and nothing in a manifest can change those.
|
|
7
|
+
*
|
|
8
|
+
* Written by `@hadoku/ui-shell/embed/vite`'s `embedBuild({ manifest })`, or by hand beside an
|
|
9
|
+
* embed built some other way; read by a host's server, which validates it with this schema and
|
|
10
|
+
* keeps the last good copy. Unknown keys are dropped, not refused, so a game can publish a field
|
|
11
|
+
* a host learns to read later.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
/** The manifest's file name, in the same directory as the embed entry it describes. */
|
|
15
|
+
export const EXTERNAL_GAME_MANIFEST_FILE = 'manifest.json';
|
|
16
|
+
/** The most seats any external game's room takes: a host's own ceiling, whatever a manifest asks. */
|
|
17
|
+
export const EXTERNAL_GAME_MAX_SEATS = 16;
|
|
18
|
+
/** How long a dropped seat is held when a manifest names no hold of its own. */
|
|
19
|
+
export const DEFAULT_SEAT_REJOIN_GRACE_MS = 120_000;
|
|
20
|
+
/** The longest hold a manifest may ask for. */
|
|
21
|
+
export const MAX_SEAT_REJOIN_GRACE_MS = 10 * 60_000;
|
|
22
|
+
const seatCount = z.number().int().min(1).max(EXTERNAL_GAME_MAX_SEATS);
|
|
23
|
+
export const externalGameManifest = z.object({
|
|
24
|
+
/** The game's name, as a host's Create room form offers it. */
|
|
25
|
+
label: z.string().trim().min(1).max(40),
|
|
26
|
+
/** Fewest and most seated players a match plays with. One is a solo game (against the game's own bots, say). */
|
|
27
|
+
seats: z.object({ min: seatCount, max: seatCount }).refine((s) => s.min <= s.max, { message: 'seats.min is more than seats.max' }),
|
|
28
|
+
/** How long a dropped seat is held for its player to come back. */
|
|
29
|
+
seatRejoinGraceMs: z.number().int().min(0).max(MAX_SEAT_REJOIN_GRACE_MS).default(DEFAULT_SEAT_REJOIN_GRACE_MS),
|
|
30
|
+
});
|
|
31
|
+
/** The manifest's path for an embed entry's path: the same directory, `manifest.json`. */
|
|
32
|
+
export function manifestPathOf(embedSrc) {
|
|
33
|
+
const slash = embedSrc.lastIndexOf('/');
|
|
34
|
+
return `${embedSrc.slice(0, slash + 1)}${EXTERNAL_GAME_MANIFEST_FILE}`;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/platform-wire",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.127",
|
|
4
|
+
"gitHead": "39cb96a57f7c400e6390c22911b93618ef495ef5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The wire any game speaks: room ids, telemetry, presence, events and tables, the Discord relay, looks, room settings, the restart notice, secure random and a generic server envelope. Knows no game; a game's own part rides as a type parameter. MIT; imports only zod.",
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
"./room-settings": {
|
|
58
58
|
"types": "./dist/room-settings.d.ts",
|
|
59
59
|
"import": "./dist/room-settings.js"
|
|
60
|
+
},
|
|
61
|
+
"./external-game-manifest": {
|
|
62
|
+
"types": "./dist/external-game-manifest.d.ts",
|
|
63
|
+
"import": "./dist/external-game-manifest.js"
|
|
60
64
|
}
|
|
61
65
|
},
|
|
62
66
|
"dependencies": {
|