@hadoku/platform-wire 0.1.252 → 0.1.254
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/room-requests.d.ts +38 -0
- package/dist/room-requests.js +56 -0
- package/dist/room-view.d.ts +405 -0
- package/dist/room-view.js +76 -0
- package/package.json +11 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `/api/rooms` accepts from any game: one strict schema per route, with the limits every room
|
|
3
|
+
* form enforces before it sends. Each refusal's text lives on the schema that raises it; the server
|
|
4
|
+
* answers the first. A field nobody named is refused, never dropped. A game's own create fields
|
|
5
|
+
* extend {@link roomCreateFields}.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export declare const ROOM_NAME_MAX = 60;
|
|
9
|
+
export declare const ROOM_PASSWORD_MAX = 200;
|
|
10
|
+
/** Watchparty's room id is opaque to us; this only bounds what is hashed. */
|
|
11
|
+
export declare const WATCHPARTY_ROOM_MAX = 200;
|
|
12
|
+
/** A request body: a JSON object naming only the fields its route reads. */
|
|
13
|
+
export declare function roomBody<S extends z.ZodRawShape>(shape: S): z.ZodObject<{ -readonly [P in keyof S]: S[P]; }, z.core.$strict>;
|
|
14
|
+
/** The fields every room is created with, whatever it plays. */
|
|
15
|
+
export declare const roomCreateFields: {
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
password: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
18
|
+
};
|
|
19
|
+
/** `POST /api/rooms` for a game with one room type and nothing of its own to choose at create. */
|
|
20
|
+
export declare function createRoomBodyFor(gameType: string): z.ZodObject<{
|
|
21
|
+
gameType: z.ZodLiteral<string>;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
password: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
/** `POST /api/rooms/:id/join`. No body at all is a join with no password. */
|
|
26
|
+
export declare const JoinRoomBodySchema: z.ZodPrefault<z.ZodObject<{
|
|
27
|
+
password: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
/** `POST /api/rooms/watchparty`: the watchparty room whose game slot this is. */
|
|
30
|
+
export declare const WatchpartyBindBodySchema: z.ZodObject<{
|
|
31
|
+
room: z.ZodString;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
/** `POST /api/rooms/:id/ready`: the caller's own readiness in the room. */
|
|
34
|
+
export declare const ReadyBodySchema: z.ZodObject<{
|
|
35
|
+
ready: z.ZodBoolean;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
/** A request that carries nothing: leave, close, start, stand, play. No body at all is the same as `{}`. */
|
|
38
|
+
export declare const EmptyBodySchema: z.ZodPrefault<z.ZodObject<{}, z.core.$strict>>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `/api/rooms` accepts from any game: one strict schema per route, with the limits every room
|
|
3
|
+
* form enforces before it sends. Each refusal's text lives on the schema that raises it; the server
|
|
4
|
+
* answers the first. A field nobody named is refused, never dropped. A game's own create fields
|
|
5
|
+
* extend {@link roomCreateFields}.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export const ROOM_NAME_MAX = 60;
|
|
9
|
+
export const ROOM_PASSWORD_MAX = 200;
|
|
10
|
+
/** Watchparty's room id is opaque to us; this only bounds what is hashed. */
|
|
11
|
+
export const WATCHPARTY_ROOM_MAX = 200;
|
|
12
|
+
// eslint-disable-next-line no-control-regex
|
|
13
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
14
|
+
/** A request body: a JSON object naming only the fields its route reads. */
|
|
15
|
+
export function roomBody(shape) {
|
|
16
|
+
return z.strictObject(shape, {
|
|
17
|
+
error: (iss) => (iss.code === 'unrecognized_keys' ? `unknown field(s): ${iss.keys.join(', ')}` : 'body must be a JSON object'),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `undefined`, `null` and `""` all mean "no password": a blank form field is an open room, not an
|
|
22
|
+
* error. The messages never echo the value.
|
|
23
|
+
*/
|
|
24
|
+
const passwordField = z
|
|
25
|
+
.string({ error: 'password must be a string' })
|
|
26
|
+
.max(ROOM_PASSWORD_MAX, { error: `password must be at most ${ROOM_PASSWORD_MAX} characters` })
|
|
27
|
+
.nullish()
|
|
28
|
+
.transform((v) => (v === null || v === '' ? undefined : v));
|
|
29
|
+
/** The fields every room is created with, whatever it plays. */
|
|
30
|
+
export const roomCreateFields = {
|
|
31
|
+
name: z
|
|
32
|
+
.string({ error: 'name must be a string' })
|
|
33
|
+
.trim()
|
|
34
|
+
.min(1, { error: `name must be 1–${ROOM_NAME_MAX} characters` })
|
|
35
|
+
.max(ROOM_NAME_MAX, { error: `name must be 1–${ROOM_NAME_MAX} characters` })
|
|
36
|
+
.refine((name) => !CONTROL.test(name), { error: 'name must not contain control characters' }),
|
|
37
|
+
password: passwordField,
|
|
38
|
+
};
|
|
39
|
+
/** `POST /api/rooms` for a game with one room type and nothing of its own to choose at create. */
|
|
40
|
+
export function createRoomBodyFor(gameType) {
|
|
41
|
+
return roomBody({ ...roomCreateFields, gameType: z.literal(gameType, { error: `gameType must be ${gameType}` }) });
|
|
42
|
+
}
|
|
43
|
+
/** `POST /api/rooms/:id/join`. No body at all is a join with no password. */
|
|
44
|
+
export const JoinRoomBodySchema = roomBody({ password: passwordField }).prefault({});
|
|
45
|
+
/** `POST /api/rooms/watchparty`: the watchparty room whose game slot this is. */
|
|
46
|
+
export const WatchpartyBindBodySchema = roomBody({
|
|
47
|
+
room: z
|
|
48
|
+
.string({ error: `room must be 1–${WATCHPARTY_ROOM_MAX} characters` })
|
|
49
|
+
.min(1, { error: `room must be 1–${WATCHPARTY_ROOM_MAX} characters` })
|
|
50
|
+
.max(WATCHPARTY_ROOM_MAX, { error: `room must be 1–${WATCHPARTY_ROOM_MAX} characters` })
|
|
51
|
+
.refine((room) => !CONTROL.test(room), { error: 'room must not contain control characters' }),
|
|
52
|
+
});
|
|
53
|
+
/** `POST /api/rooms/:id/ready`: the caller's own readiness in the room. */
|
|
54
|
+
export const ReadyBodySchema = roomBody({ ready: z.boolean({ error: 'ready must be a boolean' }) });
|
|
55
|
+
/** A request that carries nothing: leave, close, start, stand, play. No body at all is the same as `{}`. */
|
|
56
|
+
export const EmptyBodySchema = roomBody({}).prefault({});
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A room as `/api/rooms` answers with it, the part every game's room has; a game spreads its own
|
|
3
|
+
* fields over {@link roomBaseFields}. The server builds its views as the output types and the
|
|
4
|
+
* browser parses them with these schemas, so the two cannot drift. A body is a room only with an
|
|
5
|
+
* id, a name, a game type, a lock flag and a member list; every other field it lacks, or carries in
|
|
6
|
+
* a shape this build does not read, falls back to its default: a control nobody was given costs
|
|
7
|
+
* less than one handed to the wrong person.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
declare const memberFields: z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
joinedAt: z.ZodCatch<z.ZodString>;
|
|
14
|
+
ready: z.ZodCatch<z.ZodBoolean>;
|
|
15
|
+
avatarId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
16
|
+
look: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
17
|
+
picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
|
|
18
|
+
cosmetics: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
19
|
+
effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
20
|
+
gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
21
|
+
font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
22
|
+
overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
23
|
+
message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
24
|
+
placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
25
|
+
x: z.ZodNumber;
|
|
26
|
+
y: z.ZodNumber;
|
|
27
|
+
r: z.ZodNumber;
|
|
28
|
+
s: z.ZodNumber;
|
|
29
|
+
flip: z.ZodBoolean;
|
|
30
|
+
back: z.ZodBoolean;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
}, z.core.$strip>>>;
|
|
33
|
+
}, z.core.$strip>>>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export type RoomMember = z.infer<typeof memberFields>;
|
|
36
|
+
/** A member with no character has no `avatarId` key at all, so a reader's fallback is one `=== undefined`. */
|
|
37
|
+
export declare const RoomMemberSchema: z.ZodPipe<z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
joinedAt: z.ZodCatch<z.ZodString>;
|
|
41
|
+
ready: z.ZodCatch<z.ZodBoolean>;
|
|
42
|
+
avatarId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
43
|
+
look: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
44
|
+
picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
|
|
45
|
+
cosmetics: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
46
|
+
effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
47
|
+
gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
48
|
+
font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
49
|
+
overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
50
|
+
message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
51
|
+
placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
52
|
+
x: z.ZodNumber;
|
|
53
|
+
y: z.ZodNumber;
|
|
54
|
+
r: z.ZodNumber;
|
|
55
|
+
s: z.ZodNumber;
|
|
56
|
+
flip: z.ZodBoolean;
|
|
57
|
+
back: z.ZodBoolean;
|
|
58
|
+
}, z.core.$strip>>>;
|
|
59
|
+
}, z.core.$strip>>>;
|
|
60
|
+
}, z.core.$strip>>>;
|
|
61
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
joinedAt: string;
|
|
65
|
+
ready: boolean;
|
|
66
|
+
avatarId?: string | undefined;
|
|
67
|
+
look?: {
|
|
68
|
+
picture?: string | undefined;
|
|
69
|
+
cosmetics?: {
|
|
70
|
+
effect?: string | undefined;
|
|
71
|
+
gradient?: string | undefined;
|
|
72
|
+
font?: string | undefined;
|
|
73
|
+
overlay?: string | undefined;
|
|
74
|
+
message?: string | undefined;
|
|
75
|
+
placement?: {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
r: number;
|
|
79
|
+
s: number;
|
|
80
|
+
flip: boolean;
|
|
81
|
+
back: boolean;
|
|
82
|
+
} | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
id: string;
|
|
87
|
+
name: string;
|
|
88
|
+
joinedAt: string;
|
|
89
|
+
ready: boolean;
|
|
90
|
+
avatarId?: string | undefined;
|
|
91
|
+
look?: {
|
|
92
|
+
picture?: string | undefined;
|
|
93
|
+
cosmetics?: {
|
|
94
|
+
effect?: string | undefined;
|
|
95
|
+
gradient?: string | undefined;
|
|
96
|
+
font?: string | undefined;
|
|
97
|
+
overlay?: string | undefined;
|
|
98
|
+
message?: string | undefined;
|
|
99
|
+
placement?: {
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
r: number;
|
|
103
|
+
s: number;
|
|
104
|
+
flip: boolean;
|
|
105
|
+
back: boolean;
|
|
106
|
+
} | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
} | undefined;
|
|
109
|
+
}>>;
|
|
110
|
+
/**
|
|
111
|
+
* What the caller is in this room. `leader` is the only way a browser learns it owns the room's
|
|
112
|
+
* settings, because the leader is a hashed participant id no client can derive. `id` is the
|
|
113
|
+
* caller's member id as the room names them, which can differ from whoami's (an admin session).
|
|
114
|
+
*/
|
|
115
|
+
export declare const RoomYouSchema: z.ZodCatch<z.ZodObject<{
|
|
116
|
+
id: z.ZodCatch<z.ZodString>;
|
|
117
|
+
leader: z.ZodCatch<z.ZodBoolean>;
|
|
118
|
+
ready: z.ZodCatch<z.ZodBoolean>;
|
|
119
|
+
}, z.core.$strip>>;
|
|
120
|
+
export type RoomYou = z.infer<typeof RoomYouSchema>;
|
|
121
|
+
/** Every field a room has whatever game it plays. */
|
|
122
|
+
export declare const roomBaseFields: {
|
|
123
|
+
id: z.ZodString;
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
creator: z.ZodCatch<z.ZodString>;
|
|
126
|
+
leader: z.ZodCatch<z.ZodString>;
|
|
127
|
+
/**
|
|
128
|
+
* What the room plays: any id a `GameTypeSpec` registers (`game-type-spec.ts`), or a game this
|
|
129
|
+
* build does not know, kept as the string it is rather than refused.
|
|
130
|
+
*/
|
|
131
|
+
gameType: z.ZodString;
|
|
132
|
+
/** Whether a password is set: never the password, never any hash of it. */
|
|
133
|
+
locked: z.ZodBoolean;
|
|
134
|
+
members: z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodObject<{
|
|
135
|
+
id: z.ZodString;
|
|
136
|
+
name: z.ZodString;
|
|
137
|
+
joinedAt: z.ZodCatch<z.ZodString>;
|
|
138
|
+
ready: z.ZodCatch<z.ZodBoolean>;
|
|
139
|
+
avatarId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
140
|
+
look: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
141
|
+
picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
|
|
142
|
+
cosmetics: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
143
|
+
effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
144
|
+
gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
145
|
+
font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
146
|
+
overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
147
|
+
message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
148
|
+
placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
149
|
+
x: z.ZodNumber;
|
|
150
|
+
y: z.ZodNumber;
|
|
151
|
+
r: z.ZodNumber;
|
|
152
|
+
s: z.ZodNumber;
|
|
153
|
+
flip: z.ZodBoolean;
|
|
154
|
+
back: z.ZodBoolean;
|
|
155
|
+
}, z.core.$strip>>>;
|
|
156
|
+
}, z.core.$strip>>>;
|
|
157
|
+
}, z.core.$strip>>>;
|
|
158
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
joinedAt: string;
|
|
162
|
+
ready: boolean;
|
|
163
|
+
avatarId?: string | undefined;
|
|
164
|
+
look?: {
|
|
165
|
+
picture?: string | undefined;
|
|
166
|
+
cosmetics?: {
|
|
167
|
+
effect?: string | undefined;
|
|
168
|
+
gradient?: string | undefined;
|
|
169
|
+
font?: string | undefined;
|
|
170
|
+
overlay?: string | undefined;
|
|
171
|
+
message?: string | undefined;
|
|
172
|
+
placement?: {
|
|
173
|
+
x: number;
|
|
174
|
+
y: number;
|
|
175
|
+
r: number;
|
|
176
|
+
s: number;
|
|
177
|
+
flip: boolean;
|
|
178
|
+
back: boolean;
|
|
179
|
+
} | undefined;
|
|
180
|
+
} | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
}, {
|
|
183
|
+
id: string;
|
|
184
|
+
name: string;
|
|
185
|
+
joinedAt: string;
|
|
186
|
+
ready: boolean;
|
|
187
|
+
avatarId?: string | undefined;
|
|
188
|
+
look?: {
|
|
189
|
+
picture?: string | undefined;
|
|
190
|
+
cosmetics?: {
|
|
191
|
+
effect?: string | undefined;
|
|
192
|
+
gradient?: string | undefined;
|
|
193
|
+
font?: string | undefined;
|
|
194
|
+
overlay?: string | undefined;
|
|
195
|
+
message?: string | undefined;
|
|
196
|
+
placement?: {
|
|
197
|
+
x: number;
|
|
198
|
+
y: number;
|
|
199
|
+
r: number;
|
|
200
|
+
s: number;
|
|
201
|
+
flip: boolean;
|
|
202
|
+
back: boolean;
|
|
203
|
+
} | undefined;
|
|
204
|
+
} | undefined;
|
|
205
|
+
} | undefined;
|
|
206
|
+
}>>>>>, z.ZodTransform<{
|
|
207
|
+
id: string;
|
|
208
|
+
name: string;
|
|
209
|
+
joinedAt: string;
|
|
210
|
+
ready: boolean;
|
|
211
|
+
avatarId?: string | undefined;
|
|
212
|
+
look?: {
|
|
213
|
+
picture?: string | undefined;
|
|
214
|
+
cosmetics?: {
|
|
215
|
+
effect?: string | undefined;
|
|
216
|
+
gradient?: string | undefined;
|
|
217
|
+
font?: string | undefined;
|
|
218
|
+
overlay?: string | undefined;
|
|
219
|
+
message?: string | undefined;
|
|
220
|
+
placement?: {
|
|
221
|
+
x: number;
|
|
222
|
+
y: number;
|
|
223
|
+
r: number;
|
|
224
|
+
s: number;
|
|
225
|
+
flip: boolean;
|
|
226
|
+
back: boolean;
|
|
227
|
+
} | undefined;
|
|
228
|
+
} | undefined;
|
|
229
|
+
} | undefined;
|
|
230
|
+
}[], ({
|
|
231
|
+
id: string;
|
|
232
|
+
name: string;
|
|
233
|
+
joinedAt: string;
|
|
234
|
+
ready: boolean;
|
|
235
|
+
avatarId?: string | undefined;
|
|
236
|
+
look?: {
|
|
237
|
+
picture?: string | undefined;
|
|
238
|
+
cosmetics?: {
|
|
239
|
+
effect?: string | undefined;
|
|
240
|
+
gradient?: string | undefined;
|
|
241
|
+
font?: string | undefined;
|
|
242
|
+
overlay?: string | undefined;
|
|
243
|
+
message?: string | undefined;
|
|
244
|
+
placement?: {
|
|
245
|
+
x: number;
|
|
246
|
+
y: number;
|
|
247
|
+
r: number;
|
|
248
|
+
s: number;
|
|
249
|
+
flip: boolean;
|
|
250
|
+
back: boolean;
|
|
251
|
+
} | undefined;
|
|
252
|
+
} | undefined;
|
|
253
|
+
} | undefined;
|
|
254
|
+
} | null)[]>>;
|
|
255
|
+
/** Who holds each game seat, by seat number: a member id, or null for an open one; a member in none is watching. Empty from a server that sends none, so nobody is seated by guesswork. */
|
|
256
|
+
seats: z.ZodCatch<z.ZodArray<z.ZodNullable<z.ZodString>>>;
|
|
257
|
+
createdAt: z.ZodCatch<z.ZodString>;
|
|
258
|
+
/**
|
|
259
|
+
* A seeded testing room (admin-only, never swept, never stale). Absent from a room written before
|
|
260
|
+
* the flag existed, which reads back `false`: every such room is an ordinary one. A room list
|
|
261
|
+
* omits these entirely for a non-admin, so a screen's Testing section is "any room this list
|
|
262
|
+
* carries with `testing: true`", never a client-side tier check.
|
|
263
|
+
*/
|
|
264
|
+
testing: z.ZodCatch<z.ZodBoolean>;
|
|
265
|
+
/** When the event this room was made for starts; null for a room no event made. */
|
|
266
|
+
scheduledFor: z.ZodCatch<z.ZodNullable<z.ZodString>>;
|
|
267
|
+
/** The room's own tier floor: `'friend'` for a friends-only room, absent for none. */
|
|
268
|
+
minTier: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
269
|
+
};
|
|
270
|
+
/** The room every game's room is, before the game's own fields. */
|
|
271
|
+
export declare const PlatformRoomViewSchema: z.ZodObject<{
|
|
272
|
+
id: z.ZodString;
|
|
273
|
+
name: z.ZodString;
|
|
274
|
+
creator: z.ZodCatch<z.ZodString>;
|
|
275
|
+
leader: z.ZodCatch<z.ZodString>;
|
|
276
|
+
gameType: z.ZodString;
|
|
277
|
+
locked: z.ZodBoolean;
|
|
278
|
+
members: z.ZodPipe<z.ZodArray<z.ZodCatch<z.ZodNullable<z.ZodPipe<z.ZodObject<{
|
|
279
|
+
id: z.ZodString;
|
|
280
|
+
name: z.ZodString;
|
|
281
|
+
joinedAt: z.ZodCatch<z.ZodString>;
|
|
282
|
+
ready: z.ZodCatch<z.ZodBoolean>;
|
|
283
|
+
avatarId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
284
|
+
look: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
285
|
+
picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
|
|
286
|
+
cosmetics: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
287
|
+
effect: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
288
|
+
gradient: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
289
|
+
font: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
290
|
+
overlay: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
291
|
+
message: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
292
|
+
placement: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
293
|
+
x: z.ZodNumber;
|
|
294
|
+
y: z.ZodNumber;
|
|
295
|
+
r: z.ZodNumber;
|
|
296
|
+
s: z.ZodNumber;
|
|
297
|
+
flip: z.ZodBoolean;
|
|
298
|
+
back: z.ZodBoolean;
|
|
299
|
+
}, z.core.$strip>>>;
|
|
300
|
+
}, z.core.$strip>>>;
|
|
301
|
+
}, z.core.$strip>>>;
|
|
302
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
303
|
+
id: string;
|
|
304
|
+
name: string;
|
|
305
|
+
joinedAt: string;
|
|
306
|
+
ready: boolean;
|
|
307
|
+
avatarId?: string | undefined;
|
|
308
|
+
look?: {
|
|
309
|
+
picture?: string | undefined;
|
|
310
|
+
cosmetics?: {
|
|
311
|
+
effect?: string | undefined;
|
|
312
|
+
gradient?: string | undefined;
|
|
313
|
+
font?: string | undefined;
|
|
314
|
+
overlay?: string | undefined;
|
|
315
|
+
message?: string | undefined;
|
|
316
|
+
placement?: {
|
|
317
|
+
x: number;
|
|
318
|
+
y: number;
|
|
319
|
+
r: number;
|
|
320
|
+
s: number;
|
|
321
|
+
flip: boolean;
|
|
322
|
+
back: boolean;
|
|
323
|
+
} | undefined;
|
|
324
|
+
} | undefined;
|
|
325
|
+
} | undefined;
|
|
326
|
+
}, {
|
|
327
|
+
id: string;
|
|
328
|
+
name: string;
|
|
329
|
+
joinedAt: string;
|
|
330
|
+
ready: boolean;
|
|
331
|
+
avatarId?: string | undefined;
|
|
332
|
+
look?: {
|
|
333
|
+
picture?: string | undefined;
|
|
334
|
+
cosmetics?: {
|
|
335
|
+
effect?: string | undefined;
|
|
336
|
+
gradient?: string | undefined;
|
|
337
|
+
font?: string | undefined;
|
|
338
|
+
overlay?: string | undefined;
|
|
339
|
+
message?: string | undefined;
|
|
340
|
+
placement?: {
|
|
341
|
+
x: number;
|
|
342
|
+
y: number;
|
|
343
|
+
r: number;
|
|
344
|
+
s: number;
|
|
345
|
+
flip: boolean;
|
|
346
|
+
back: boolean;
|
|
347
|
+
} | undefined;
|
|
348
|
+
} | undefined;
|
|
349
|
+
} | undefined;
|
|
350
|
+
}>>>>>, z.ZodTransform<{
|
|
351
|
+
id: string;
|
|
352
|
+
name: string;
|
|
353
|
+
joinedAt: string;
|
|
354
|
+
ready: boolean;
|
|
355
|
+
avatarId?: string | undefined;
|
|
356
|
+
look?: {
|
|
357
|
+
picture?: string | undefined;
|
|
358
|
+
cosmetics?: {
|
|
359
|
+
effect?: string | undefined;
|
|
360
|
+
gradient?: string | undefined;
|
|
361
|
+
font?: string | undefined;
|
|
362
|
+
overlay?: string | undefined;
|
|
363
|
+
message?: string | undefined;
|
|
364
|
+
placement?: {
|
|
365
|
+
x: number;
|
|
366
|
+
y: number;
|
|
367
|
+
r: number;
|
|
368
|
+
s: number;
|
|
369
|
+
flip: boolean;
|
|
370
|
+
back: boolean;
|
|
371
|
+
} | undefined;
|
|
372
|
+
} | undefined;
|
|
373
|
+
} | undefined;
|
|
374
|
+
}[], ({
|
|
375
|
+
id: string;
|
|
376
|
+
name: string;
|
|
377
|
+
joinedAt: string;
|
|
378
|
+
ready: boolean;
|
|
379
|
+
avatarId?: string | undefined;
|
|
380
|
+
look?: {
|
|
381
|
+
picture?: string | undefined;
|
|
382
|
+
cosmetics?: {
|
|
383
|
+
effect?: string | undefined;
|
|
384
|
+
gradient?: string | undefined;
|
|
385
|
+
font?: string | undefined;
|
|
386
|
+
overlay?: string | undefined;
|
|
387
|
+
message?: string | undefined;
|
|
388
|
+
placement?: {
|
|
389
|
+
x: number;
|
|
390
|
+
y: number;
|
|
391
|
+
r: number;
|
|
392
|
+
s: number;
|
|
393
|
+
flip: boolean;
|
|
394
|
+
back: boolean;
|
|
395
|
+
} | undefined;
|
|
396
|
+
} | undefined;
|
|
397
|
+
} | undefined;
|
|
398
|
+
} | null)[]>>;
|
|
399
|
+
seats: z.ZodCatch<z.ZodArray<z.ZodNullable<z.ZodString>>>;
|
|
400
|
+
createdAt: z.ZodCatch<z.ZodString>;
|
|
401
|
+
testing: z.ZodCatch<z.ZodBoolean>;
|
|
402
|
+
scheduledFor: z.ZodCatch<z.ZodNullable<z.ZodString>>;
|
|
403
|
+
minTier: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
404
|
+
}, z.core.$strip>;
|
|
405
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A room as `/api/rooms` answers with it, the part every game's room has; a game spreads its own
|
|
3
|
+
* fields over {@link roomBaseFields}. The server builds its views as the output types and the
|
|
4
|
+
* browser parses them with these schemas, so the two cannot drift. A body is a room only with an
|
|
5
|
+
* id, a name, a game type, a lock flag and a member list; every other field it lacks, or carries in
|
|
6
|
+
* a shape this build does not read, falls back to its default: a control nobody was given costs
|
|
7
|
+
* less than one handed to the wrong person.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { AVATAR_ID_MAX, LookSchema } from "./look.js";
|
|
11
|
+
import { ROOM_ID_RE } from "./room-feed.js";
|
|
12
|
+
const memberFields = z.object({
|
|
13
|
+
/** A ParticipantId from `identityFromHeaders`. */
|
|
14
|
+
id: z.string(),
|
|
15
|
+
/** `userIdOf(req)`, the same string `/api/whoami` returns as `userId`. */
|
|
16
|
+
name: z.string(),
|
|
17
|
+
joinedAt: z.string().catch(''),
|
|
18
|
+
/**
|
|
19
|
+
* The ROOM's readiness, which is what a room's start waits on. Not a table seat's Ready, which
|
|
20
|
+
* means "my deck is loaded and legal"; this one needs no deck.
|
|
21
|
+
*/
|
|
22
|
+
ready: z.boolean().catch(false),
|
|
23
|
+
/**
|
|
24
|
+
* Watchparty's `sprite` id for the character this member wears: absent or a non-blank string,
|
|
25
|
+
* never `null` and never `''`. Deliberately not checked against watchparty's list, so a character
|
|
26
|
+
* they add still reaches the UI.
|
|
27
|
+
*/
|
|
28
|
+
avatarId: z.string().trim().min(1).max(AVATAR_ID_MAX).optional().catch(undefined),
|
|
29
|
+
/** Their avatar picture and cosmetics (`look.ts`). Absent when they have neither. */
|
|
30
|
+
look: LookSchema.optional().catch(undefined),
|
|
31
|
+
});
|
|
32
|
+
/** A member with no character has no `avatarId` key at all, so a reader's fallback is one `=== undefined`. */
|
|
33
|
+
export const RoomMemberSchema = memberFields.transform(({ avatarId, look, ...member }) => ({
|
|
34
|
+
...member,
|
|
35
|
+
...(avatarId === undefined ? {} : { avatarId }),
|
|
36
|
+
...(look === undefined ? {} : { look }),
|
|
37
|
+
}));
|
|
38
|
+
/**
|
|
39
|
+
* What the caller is in this room. `leader` is the only way a browser learns it owns the room's
|
|
40
|
+
* settings, because the leader is a hashed participant id no client can derive. `id` is the
|
|
41
|
+
* caller's member id as the room names them, which can differ from whoami's (an admin session).
|
|
42
|
+
*/
|
|
43
|
+
export const RoomYouSchema = z
|
|
44
|
+
.object({ id: z.string().catch(''), leader: z.boolean().catch(false), ready: z.boolean().catch(false) })
|
|
45
|
+
.catch(() => ({ id: '', leader: false, ready: false }));
|
|
46
|
+
/** Every field a room has whatever game it plays. */
|
|
47
|
+
export const roomBaseFields = {
|
|
48
|
+
id: z.string().regex(ROOM_ID_RE),
|
|
49
|
+
name: z.string(),
|
|
50
|
+
creator: z.string().catch(''),
|
|
51
|
+
leader: z.string().catch(''),
|
|
52
|
+
/**
|
|
53
|
+
* What the room plays: any id a `GameTypeSpec` registers (`game-type-spec.ts`), or a game this
|
|
54
|
+
* build does not know, kept as the string it is rather than refused.
|
|
55
|
+
*/
|
|
56
|
+
gameType: z.string(),
|
|
57
|
+
/** Whether a password is set: never the password, never any hash of it. */
|
|
58
|
+
locked: z.boolean(),
|
|
59
|
+
members: z.array(RoomMemberSchema.nullable().catch(null)).transform((members) => members.filter((m) => m !== null)),
|
|
60
|
+
/** Who holds each game seat, by seat number: a member id, or null for an open one; a member in none is watching. Empty from a server that sends none, so nobody is seated by guesswork. */
|
|
61
|
+
seats: z.array(z.string().nullable()).catch(() => []),
|
|
62
|
+
createdAt: z.string().catch(''),
|
|
63
|
+
/**
|
|
64
|
+
* A seeded testing room (admin-only, never swept, never stale). Absent from a room written before
|
|
65
|
+
* the flag existed, which reads back `false`: every such room is an ordinary one. A room list
|
|
66
|
+
* omits these entirely for a non-admin, so a screen's Testing section is "any room this list
|
|
67
|
+
* carries with `testing: true`", never a client-side tier check.
|
|
68
|
+
*/
|
|
69
|
+
testing: z.boolean().catch(false),
|
|
70
|
+
/** When the event this room was made for starts; null for a room no event made. */
|
|
71
|
+
scheduledFor: z.string().nullable().catch(null),
|
|
72
|
+
/** The room's own tier floor: `'friend'` for a friends-only room, absent for none. */
|
|
73
|
+
minTier: z.string().optional().catch(undefined),
|
|
74
|
+
};
|
|
75
|
+
/** The room every game's room is, before the game's own fields. */
|
|
76
|
+
export const PlatformRoomViewSchema = z.object(roomBaseFields);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/platform-wire",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.254",
|
|
4
|
+
"gitHead": "bb0a5181a8533bf58094648604fe69db28599068",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"description": "The wire any game speaks: room ids, telemetry, presence, events and tables, the Discord relay, looks, 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.",
|
|
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.",
|
|
8
8
|
"exports": {
|
|
9
9
|
"./room-feed": {
|
|
10
10
|
"types": "./dist/room-feed.d.ts",
|
|
@@ -58,6 +58,14 @@
|
|
|
58
58
|
"types": "./dist/room-settings.d.ts",
|
|
59
59
|
"import": "./dist/room-settings.js"
|
|
60
60
|
},
|
|
61
|
+
"./room-requests": {
|
|
62
|
+
"types": "./dist/room-requests.d.ts",
|
|
63
|
+
"import": "./dist/room-requests.js"
|
|
64
|
+
},
|
|
65
|
+
"./room-view": {
|
|
66
|
+
"types": "./dist/room-view.d.ts",
|
|
67
|
+
"import": "./dist/room-view.js"
|
|
68
|
+
},
|
|
61
69
|
"./external-game-manifest": {
|
|
62
70
|
"types": "./dist/external-game-manifest.d.ts",
|
|
63
71
|
"import": "./dist/external-game-manifest.js"
|