@hadoku/platform-wire 0.1.254 → 0.1.255
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/dist/external-game-spec.d.ts +51 -12
- package/dist/external-game-spec.js +46 -0
- package/dist/room-settings.d.ts +1 -14
- package/dist/room-settings.js +0 -16
- package/package.json +2 -2
|
@@ -1,20 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An external game as a room type: what the host decided about it (its id, whether it runs on the
|
|
3
|
-
* relay, its tier floor) together with what the game says about itself in its
|
|
4
|
-
* (`external-game-manifest.ts`: its seat range and seat hold). The host's half
|
|
3
|
+
* relay, its tier floor, where its bundle is) together with what the game says about itself in its
|
|
4
|
+
* `manifest.json` (`external-game-manifest.ts`: its name, seat range and seat hold). The host's half
|
|
5
5
|
* never comes from the manifest, so a game cannot widen who may play it.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* A host keeps its half as data, one `ExternalGameConfigSchema` entry per game, and builds each
|
|
8
|
+
* game's spec through `externalGameSpec`; a test that needs a relay room type builds one the same
|
|
9
|
+
* way rather than re-typing the fields. What it tells a browser about each game it hosts is a
|
|
10
|
+
* `HostedGameEntrySchema`.
|
|
9
11
|
*/
|
|
10
|
-
import
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { type ExternalGameManifest } from './external-game-manifest.js';
|
|
11
14
|
import type { GameTypeSpec } from './game-type-spec.js';
|
|
12
|
-
|
|
15
|
+
declare const hostedGameFields: {
|
|
16
|
+
/** The room's wire `gameType`. */
|
|
17
|
+
id: z.ZodString;
|
|
18
|
+
/** `'relay'`: its match is the host's relay. Absent: the game plays on its own server, and the room has no match behind it. */
|
|
19
|
+
runtime: z.ZodOptional<z.ZodLiteral<"relay">>;
|
|
20
|
+
/** Every room of the game is above the app's floor: hidden from and refused to anyone below it. */
|
|
21
|
+
minTier: z.ZodOptional<z.ZodEnum<{
|
|
22
|
+
friend: "friend";
|
|
23
|
+
}>>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* One game a host may host, as its list file holds it. Strict: a field the host does not read is a
|
|
27
|
+
* mistake in the file, refused rather than ignored.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ExternalGameConfigSchema: z.ZodObject<{
|
|
30
|
+
embedSrc: z.ZodString;
|
|
31
|
+
e2eOnly: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
manifest: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
label: z.ZodString;
|
|
34
|
+
seats: z.ZodObject<{
|
|
35
|
+
min: z.ZodNumber;
|
|
36
|
+
max: z.ZodNumber;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
seatRejoinGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
runtime: z.ZodOptional<z.ZodLiteral<"relay">>;
|
|
42
|
+
minTier: z.ZodOptional<z.ZodEnum<{
|
|
43
|
+
friend: "friend";
|
|
44
|
+
}>>;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
export type ExternalGameConfig = z.output<typeof ExternalGameConfigSchema>;
|
|
13
47
|
/** The host's own half of an external game. */
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
48
|
+
export type HostedGame = Pick<ExternalGameConfig, keyof typeof hostedGameFields>;
|
|
49
|
+
/** A hosted game as a browser is told of it: its name, its bundle, and what the create form needs to know. */
|
|
50
|
+
export declare const HostedGameEntrySchema: z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
label: z.ZodString;
|
|
53
|
+
embedSrc: z.ZodString;
|
|
54
|
+
relay: z.ZodBoolean;
|
|
55
|
+
friendsOnly: z.ZodBoolean;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
export type HostedGameEntry = z.output<typeof HostedGameEntrySchema>;
|
|
20
58
|
export declare function externalGameSpec(game: HostedGame, manifest: ExternalGameManifest): GameTypeSpec;
|
|
59
|
+
export {};
|
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An external game as a room type: what the host decided about it (its id, whether it runs on the
|
|
3
|
+
* relay, its tier floor, where its bundle is) together with what the game says about itself in its
|
|
4
|
+
* `manifest.json` (`external-game-manifest.ts`: its name, seat range and seat hold). The host's half
|
|
5
|
+
* never comes from the manifest, so a game cannot widen who may play it.
|
|
6
|
+
*
|
|
7
|
+
* A host keeps its half as data, one `ExternalGameConfigSchema` entry per game, and builds each
|
|
8
|
+
* game's spec through `externalGameSpec`; a test that needs a relay room type builds one the same
|
|
9
|
+
* way rather than re-typing the fields. What it tells a browser about each game it hosts is a
|
|
10
|
+
* `HostedGameEntrySchema`.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { externalGameManifest } from "./external-game-manifest.js";
|
|
14
|
+
import { ROOM_FLOOR_TIERS } from "./tiers.js";
|
|
15
|
+
const hostedGameFields = {
|
|
16
|
+
/** The room's wire `gameType`. */
|
|
17
|
+
id: z.string().min(1),
|
|
18
|
+
/** `'relay'`: its match is the host's relay. Absent: the game plays on its own server, and the room has no match behind it. */
|
|
19
|
+
runtime: z.literal('relay').optional(),
|
|
20
|
+
/** Every room of the game is above the app's floor: hidden from and refused to anyone below it. */
|
|
21
|
+
minTier: z.enum(ROOM_FLOOR_TIERS).optional(),
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* One game a host may host, as its list file holds it. Strict: a field the host does not read is a
|
|
25
|
+
* mistake in the file, refused rather than ignored.
|
|
26
|
+
*/
|
|
27
|
+
export const ExternalGameConfigSchema = z.strictObject({
|
|
28
|
+
...hostedGameFields,
|
|
29
|
+
/** The same-origin path a browser loads the game's bundle from; its `manifest.json` is beside it. */
|
|
30
|
+
embedSrc: z.string().startsWith('/'),
|
|
31
|
+
/** A fixture that proves the mechanism rather than any real game: hosted only where a host asks for its fixtures too. */
|
|
32
|
+
e2eOnly: z.boolean().optional(),
|
|
33
|
+
/** A fixture's manifest, since no publisher serves one for it. A real game's is always its own file. */
|
|
34
|
+
manifest: externalGameManifest.optional(),
|
|
35
|
+
});
|
|
36
|
+
/** A hosted game as a browser is told of it: its name, its bundle, and what the create form needs to know. */
|
|
37
|
+
export const HostedGameEntrySchema = z.object({
|
|
38
|
+
id: z.string(),
|
|
39
|
+
/** The name the game's manifest gives. */
|
|
40
|
+
label: z.string(),
|
|
41
|
+
embedSrc: z.string(),
|
|
42
|
+
/** Its match runs on the host's relay, so its bundle gets a channel there. */
|
|
43
|
+
relay: z.boolean(),
|
|
44
|
+
/** Every room of it is friends-only already. */
|
|
45
|
+
friendsOnly: z.boolean(),
|
|
46
|
+
});
|
|
1
47
|
export function externalGameSpec(game, manifest) {
|
|
2
48
|
return {
|
|
3
49
|
id: game.id,
|
package/dist/room-settings.d.ts
CHANGED
|
@@ -47,18 +47,11 @@ export interface ChoiceField<T extends string = string> extends FieldBase<T> {
|
|
|
47
47
|
label: string;
|
|
48
48
|
}[];
|
|
49
49
|
}
|
|
50
|
-
/** A number in `[min, max]`, in steps of `step`. */
|
|
51
|
-
export interface NumberField extends FieldBase<number> {
|
|
52
|
-
kind: 'number';
|
|
53
|
-
min: number;
|
|
54
|
-
max: number;
|
|
55
|
-
step: number;
|
|
56
|
-
}
|
|
57
50
|
/** Anything else (Magic's pick timer, an object). The panel cannot draw it: the game draws its own row. */
|
|
58
51
|
export interface CustomField<T = unknown> extends FieldBase<T> {
|
|
59
52
|
kind: 'custom';
|
|
60
53
|
}
|
|
61
|
-
export type SettingField = ToggleField | ChoiceField |
|
|
54
|
+
export type SettingField = ToggleField | ChoiceField | CustomField;
|
|
62
55
|
export type SettingFields = Readonly<Record<string, SettingField>>;
|
|
63
56
|
/** The settings object a set of fields declares. */
|
|
64
57
|
export type SettingsOf<F extends SettingFields> = {
|
|
@@ -73,12 +66,6 @@ export declare function toggle(fallback: boolean, opts: FieldOptions): ToggleFie
|
|
|
73
66
|
export declare function choice<const T extends string>(values: readonly [T, ...T[]], fallback: NoInfer<T>, opts: FieldOptions & {
|
|
74
67
|
labels?: Readonly<Partial<Record<T, string>>>;
|
|
75
68
|
}): ChoiceField<T>;
|
|
76
|
-
/** A whole number when `step` is (the default, 1); otherwise any number in range. */
|
|
77
|
-
export declare function bounded(range: {
|
|
78
|
-
min: number;
|
|
79
|
-
max: number;
|
|
80
|
-
step?: number;
|
|
81
|
-
}, fallback: number, opts: FieldOptions): NumberField;
|
|
82
69
|
/** A value of any shape `schema` admits; `must` says what that is. */
|
|
83
70
|
export declare function custom<T>(schema: z.ZodType<T>, fallback: T, opts: FieldOptions & {
|
|
84
71
|
must: string;
|
package/dist/room-settings.js
CHANGED
|
@@ -38,22 +38,6 @@ export function choice(values, fallback, opts) {
|
|
|
38
38
|
...rest,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
/** A whole number when `step` is (the default, 1); otherwise any number in range. */
|
|
42
|
-
export function bounded(range, fallback, opts) {
|
|
43
|
-
const step = range.step ?? 1;
|
|
44
|
-
const whole = Number.isInteger(step);
|
|
45
|
-
const base = whole ? z.int() : z.number();
|
|
46
|
-
return {
|
|
47
|
-
kind: 'number',
|
|
48
|
-
default: fallback,
|
|
49
|
-
min: range.min,
|
|
50
|
-
max: range.max,
|
|
51
|
-
step,
|
|
52
|
-
must: `must be ${whole ? 'an integer' : 'a number'} ${range.min}–${range.max}`,
|
|
53
|
-
schema: base.min(range.min).max(range.max),
|
|
54
|
-
...opts,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
41
|
/** A value of any shape `schema` admits; `must` says what that is. */
|
|
58
42
|
export function custom(schema, fallback, opts) {
|
|
59
43
|
return { kind: 'custom', default: fallback, schema, ...opts };
|
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.255",
|
|
4
|
+
"gitHead": "bd56441796a344d86f4ec3864896652db6ef01b5",
|
|
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, the room request bodies and room view, room settings, the game-type registry, 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.",
|