@caisual/kit 0.21.0 → 0.23.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.
Files changed (44) hide show
  1. package/README.md +12 -9
  2. package/dist/host.d.ts +1 -0
  3. package/dist/host.js +169 -0
  4. package/dist/kit.js +2 -4
  5. package/dist/kit.js.map +4 -4
  6. package/dist/node.js +193 -427
  7. package/dist/runtime.js +241 -269
  8. package/dist/types/api.d.ts +1 -1
  9. package/dist/types/contracts/connessione.d.ts +1 -0
  10. package/dist/types/contracts/giornata.d.ts +1 -0
  11. package/dist/types/contracts/index.d.ts +3 -2
  12. package/dist/types/contracts/manifest.d.ts +7 -50
  13. package/dist/types/contracts/network-budget.d.ts +53 -0
  14. package/dist/types/contracts/versioni.d.ts +0 -1
  15. package/dist/types/crew/index.d.ts +4 -0
  16. package/dist/types/handshake.d.ts +0 -4
  17. package/dist/types/{overlay/host-bridge.d.ts → host/index.d.ts} +60 -37
  18. package/dist/types/index.d.ts +66 -57
  19. package/dist/types/node/index.d.ts +5 -25
  20. package/dist/types/protocollo.d.ts +2 -21
  21. package/dist/types/runtime/index.d.ts +3 -13
  22. package/dist/types/runtime/network-probe.d.ts +4 -0
  23. package/dist/types/server/index.d.ts +1 -11
  24. package/dist/types/stanza/nucleo.d.ts +8 -16
  25. package/dist/types/stanza/tipi.d.ts +3 -21
  26. package/dist/types/voce/index.d.ts +0 -1
  27. package/package.json +15 -17
  28. package/dist/overlay.d.ts +0 -1
  29. package/dist/overlay.js +0 -2157
  30. package/dist/overlay.js.map +0 -7
  31. package/dist/types/contracts/overlay.d.ts +0 -235
  32. package/dist/types/contracts/replay.d.ts +0 -83
  33. package/dist/types/overlay/bridge.d.ts +0 -3
  34. package/dist/types/overlay/i18n.d.ts +0 -128
  35. package/dist/types/overlay/index.d.ts +0 -9
  36. package/dist/types/overlay/locale.d.ts +0 -4
  37. package/dist/types/overlay/shortcut.d.ts +0 -4
  38. package/dist/types/overlay/styles.d.ts +0 -1
  39. package/dist/types/overlay/ui-model.d.ts +0 -53
  40. package/dist/types/overlay/ui.d.ts +0 -81
  41. package/dist/types/overlay/voice-panel.d.ts +0 -13
  42. package/dist/types/replay/index.d.ts +0 -65
  43. package/dist/types/session/index.d.ts +0 -49
  44. package/dist/types/session/resume.d.ts +0 -13
@@ -1,4 +1,3 @@
1
- import type { QueuedScore } from './contracts/index.js';
2
1
  import type { JsonValue, RoomStatus } from './server/index.js';
3
2
  export type PercorsoDiff = Array<string | number>;
4
3
  export type OperazioneDiff = {
@@ -36,14 +35,13 @@ export interface RoomConfiguration {
36
35
  min: number;
37
36
  max: number;
38
37
  };
39
- lobby: boolean;
40
38
  persistent: boolean;
41
39
  requestRole: boolean;
42
40
  }
43
41
  export interface StanzaProtocollo {
42
+ origin: 'player' | 'matchmaking';
44
43
  rematch?: {
45
44
  keepSetup: boolean;
46
- autoStart: boolean;
47
45
  } | null;
48
46
  result?: JsonValue;
49
47
  countdownAt?: number | null;
@@ -55,8 +53,8 @@ export interface StanzaProtocollo {
55
53
  tick: number;
56
54
  tickRate: number;
57
55
  serverTime: number;
58
- host: string | null;
59
56
  }
57
+ /** Istantanea di sola lettura della stanza: stato, giocatori e metadati in un colpo. */
60
58
  export interface FotografiaStanza {
61
59
  room: StanzaProtocollo;
62
60
  players: GiocatoreProtocollo[];
@@ -190,8 +188,6 @@ export type MessaggioClientStanza = MessaggioClientVoce | {
190
188
  } | {
191
189
  t: 'team';
192
190
  team: number;
193
- } | {
194
- t: 'start';
195
191
  } | {
196
192
  t: 'restart';
197
193
  } | {
@@ -207,9 +203,6 @@ export type MessaggioClientStanza = MessaggioClientVoce | {
207
203
  t: 'leave';
208
204
  };
209
205
  export type MessaggioServerStanza = {
210
- t: 'replay-ready';
211
- id: string;
212
- } | {
213
206
  t: 'welcome';
214
207
  you: string;
215
208
  room: StanzaProtocollo;
@@ -218,26 +211,20 @@ export type MessaggioServerStanza = {
218
211
  } | {
219
212
  t: 'players';
220
213
  players: GiocatoreProtocollo[];
221
- host?: string | null;
222
214
  } | {
223
215
  t: 'role-result';
224
216
  r: number;
225
217
  ok: boolean;
226
218
  code: string | null;
227
- } | {
228
- t: 'score-queued';
229
- score: QueuedScore;
230
219
  } | {
231
220
  t: 'status';
232
221
  rematch?: {
233
222
  keepSetup: boolean;
234
- autoStart: boolean;
235
223
  } | null;
236
224
  status: RoomStatus;
237
225
  at: number;
238
226
  result: JsonValue;
239
227
  countdownAt?: number | null;
240
- host?: string | null;
241
228
  } | {
242
229
  t: 'state';
243
230
  tickRate?: number;
@@ -265,9 +252,3 @@ export type MessaggioServerStanza = {
265
252
  } | {
266
253
  t: 'flush';
267
254
  } | MessaggioServerVoce;
268
- export type MessaggioServerSpettatore = ({
269
- t: 'watching';
270
- delayMs: number;
271
- } & FotografiaStanza) | Extract<MessaggioServerStanza, {
272
- t: 'replay-ready' | 'players' | 'status' | 'state' | 'snapshot' | 'msg' | 'error' | 'pong';
273
- }>;
@@ -1,3 +1,4 @@
1
+ export { measureNetwork } from './network-probe.js';
1
2
  import type { FotografiaStanza } from '../protocollo.js';
2
3
  import type { GameDefinition, JsonValue, RoomStatus } from '../server/index.js';
3
4
  export interface RoomManifest {
@@ -6,9 +7,7 @@ export interface RoomManifest {
6
7
  min: number;
7
8
  max: number;
8
9
  };
9
- lobby: boolean;
10
10
  persistent?: boolean;
11
- replays?: boolean;
12
11
  roles: Array<{
13
12
  id: string;
14
13
  min: number;
@@ -20,12 +19,10 @@ export interface RoomManifest {
20
19
  } | null;
21
20
  modes: Array<{
22
21
  id: string;
23
- execution?: 'local' | 'room';
24
22
  players?: {
25
23
  min: number;
26
24
  max: number;
27
25
  };
28
- lobby?: boolean;
29
26
  }>;
30
27
  voice?: 'none' | 'room' | 'team' | 'proximity';
31
28
  }
@@ -39,7 +36,6 @@ export interface Esito {
39
36
  connessione: string;
40
37
  testo: string;
41
38
  }>;
42
- pubblici: string[];
43
39
  chiusure: Array<{
44
40
  connessione: string;
45
41
  codice: number;
@@ -52,6 +48,7 @@ export interface Esito {
52
48
  voceRivedi: boolean;
53
49
  }
54
50
  export interface InfoStanza {
51
+ origin: 'player' | 'matchmaking';
55
52
  roomId: string;
56
53
  status: RoomStatus;
57
54
  players: number;
@@ -72,14 +69,6 @@ export type EsitoAscolto = {
72
69
  reason: 'mode' | 'unknown' | 'team' | 'gain';
73
70
  };
74
71
  export interface EsitoFlush {
75
- scores: Array<{
76
- playerId: string;
77
- board: string;
78
- score: number;
79
- daily: boolean;
80
- day?: string | null;
81
- submittedAt?: number;
82
- }>;
83
72
  ended: {
84
73
  result: JsonValue;
85
74
  at: number;
@@ -89,6 +78,7 @@ export interface FacetStanza {
89
78
  crea(input: {
90
79
  mode: string | null;
91
80
  creator: IdentitaGiocatore;
81
+ origin?: 'player' | 'matchmaking';
92
82
  }): Promise<Esito & {
93
83
  ok: boolean;
94
84
  }>;
@@ -0,0 +1,4 @@
1
+ import { type NetworkProbeResult } from '../contracts/index.js';
2
+ import type { GameDefinition } from '../server/index.js';
3
+ import type { ManifestStanza } from '../stanza/tipi.js';
4
+ export declare function measureNetwork(definition: GameDefinition, manifest: ManifestStanza): Promise<NetworkProbeResult>;
@@ -4,18 +4,10 @@ export type JsonValue = null | boolean | number | string | JsonValue[] | {
4
4
  };
5
5
  export type RematchOptions = boolean | {
6
6
  keepSetup?: boolean;
7
- autoStart?: boolean;
8
7
  };
9
- export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
8
+ export type RoomStatus = 'waiting' | 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
10
9
  export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
11
10
  export type LeaveReason = 'left' | 'timeout' | 'kicked';
12
- export interface SharedGameStore {
13
- get(key: string): Promise<JsonValue | null>;
14
- set(key: string, value: JsonValue): Promise<void>;
15
- delete(key: string): Promise<void>;
16
- list(prefix?: string): Promise<string[]>;
17
- increment(key: string, amount?: number): Promise<number>;
18
- }
19
11
  export interface Player {
20
12
  readonly id: string;
21
13
  readonly name: string;
@@ -34,7 +26,6 @@ export interface Room<State extends JsonValue = JsonValue> {
34
26
  readonly result: JsonValue | null;
35
27
  state: State;
36
28
  readonly players: readonly Player[];
37
- readonly host: Player | null;
38
29
  broadcast(message: JsonValue): void;
39
30
  send(player: Player | string, message: JsonValue): void;
40
31
  kick(player: Player | string): void;
@@ -45,7 +36,6 @@ export interface Room<State extends JsonValue = JsonValue> {
45
36
  }): void;
46
37
  save(key: string, value: JsonValue): Promise<void>;
47
38
  load(key: string): Promise<JsonValue | null>;
48
- readonly shared: SharedGameStore;
49
39
  schedule(milliseconds: number, handler: string, payload: JsonValue): void;
50
40
  readonly daily: {
51
41
  readonly day: string;
@@ -1,6 +1,6 @@
1
1
  import { type Player } from '../server/index.js';
2
2
  import type { FotografiaStanza } from '../protocollo.js';
3
- import type { AdattatoreStanza, EsitoAscolto, EsitoFlush, EsitoIngresso, IdentitaGiocatore, InfoStanza, ManifestStanza } from './tipi.js';
3
+ import type { AdattatoreStanza, EsitoAscolto, EsitoFlush, EsitoIngresso, IdentitaGiocatore, InfoStanza, ManifestStanza, StatoPersistito } from './tipi.js';
4
4
  export declare class NucleoStanza {
5
5
  private readonly definizione;
6
6
  private readonly manifest;
@@ -8,7 +8,6 @@ export declare class NucleoStanza {
8
8
  private dati;
9
9
  private readonly room;
10
10
  private readonly frequenza;
11
- private frequenzaDeposito;
12
11
  private readonly kickRichiesti;
13
12
  private readonly voceGuadagniCambiati;
14
13
  private fineRichiesta;
@@ -22,7 +21,7 @@ export declare class NucleoStanza {
22
21
  private richiediDati;
23
22
  private stanzaTerminata;
24
23
  get esiste(): boolean;
25
- crea(id: string, mode: string | null, _creator: IdentitaGiocatore): Promise<boolean>;
24
+ crea(id: string, mode: string | null, _creator: IdentitaGiocatore, origin?: StatoPersistito['origin']): Promise<boolean>;
26
25
  private get configurazione();
27
26
  info(playerId?: string): InfoStanza | null;
28
27
  fotografia(): FotografiaStanza | null;
@@ -52,12 +51,15 @@ export declare class NucleoStanza {
52
51
  private rivincita;
53
52
  private prontiRivincita;
54
53
  private avviaRivincita;
55
- private avviaCountdown;
56
- private verificaCountdown;
54
+ /**
55
+ * Nessuno ospita e nessuno preme "inizia": appena tutti i connessi sono pronti e i
56
+ * minimi di giocatori, ruoli e squadre sono rispettati parte il countdown; se la
57
+ * condizione cade durante il countdown si torna in lobby.
58
+ */
59
+ private rivalutaAvvio;
57
60
  private messaggioErrato;
58
61
  private chiudiConnessione;
59
62
  private rimuoviGiocatore;
60
- private assegnaHost;
61
63
  private eseguiTimer;
62
64
  private pianifica;
63
65
  private giornata;
@@ -65,15 +67,6 @@ export declare class NucleoStanza {
65
67
  private richiediFine;
66
68
  private salva;
67
69
  private caricaSave;
68
- private verificaChiaveDeposito;
69
- private verificaPrefissoDeposito;
70
- private contaOperazioneDeposito;
71
- private usaDeposito;
72
- private leggiDeposito;
73
- private scriviDeposito;
74
- private eliminaDeposito;
75
- private elencaDeposito;
76
- private incrementaDeposito;
77
70
  private messaggioCreatore;
78
71
  private broadcastCreatore;
79
72
  private inviaCreatore;
@@ -85,7 +78,6 @@ export declare class NucleoStanza {
85
78
  private inviaGiocatori;
86
79
  private inviaStatus;
87
80
  private inviaDiff;
88
- private iniziaReplay;
89
81
  private inviaSnapshotTutti;
90
82
  private chiama;
91
83
  private applicaAzioni;
@@ -1,4 +1,4 @@
1
- import type { JsonValue, RoomStatus, SharedGameStore } from '../server/index.js';
1
+ import type { JsonValue, RoomStatus } from '../server/index.js';
2
2
  import type { MessaggioServerStanza } from '../protocollo.js';
3
3
  export interface ManifestStanza {
4
4
  id: string;
@@ -6,9 +6,7 @@ export interface ManifestStanza {
6
6
  min: number;
7
7
  max: number;
8
8
  };
9
- lobby: boolean;
10
9
  persistent?: boolean;
11
- replays?: boolean;
12
10
  roles: Array<{
13
11
  id: string;
14
12
  min: number;
@@ -20,12 +18,10 @@ export interface ManifestStanza {
20
18
  } | null;
21
19
  modes: Array<{
22
20
  id: string;
23
- execution?: 'local' | 'room';
24
21
  players?: {
25
22
  min: number;
26
23
  max: number;
27
24
  };
28
- lobby?: boolean;
29
25
  }>;
30
26
  voice?: 'none' | 'room' | 'team' | 'proximity';
31
27
  }
@@ -35,13 +31,9 @@ export interface ArchivioStanza {
35
31
  delete(key: string): Promise<void>;
36
32
  list(prefix?: string): Promise<Map<string, unknown>>;
37
33
  }
38
- export type DepositoCondiviso = SharedGameStore;
39
34
  export interface AdattatoreStanza {
40
35
  readonly storage: ArchivioStanza;
41
- readonly deposito: DepositoCondiviso | null;
42
36
  invia(connessione: string, messaggio: MessaggioServerStanza): void;
43
- inizioReplay?(fotografia: import('../protocollo.js').FotografiaStanza): void;
44
- pubblica(messaggio: MessaggioServerStanza): void;
45
37
  chiudi(connessione: string, codice: number, motivo: string): void;
46
38
  connessioniAttive(): readonly string[];
47
39
  ora(): number;
@@ -72,20 +64,13 @@ export interface TimerPersistito {
72
64
  handler: string;
73
65
  payload: JsonValue;
74
66
  }
75
- export interface PunteggioPersistito {
76
- playerId: string;
77
- board: string;
78
- score: number;
79
- daily: boolean;
80
- day?: string | null;
81
- submittedAt?: number;
82
- }
83
67
  export interface FinePersistita {
84
68
  result: JsonValue;
85
69
  at: number;
86
70
  }
87
71
  export interface StatoPersistito {
88
72
  versione: 1;
73
+ origin: 'player' | 'matchmaking';
89
74
  id: string;
90
75
  mode: string | null;
91
76
  status: RoomStatus;
@@ -95,13 +80,11 @@ export interface StatoPersistito {
95
80
  ultimoCambioStatoAt: number;
96
81
  state: JsonValue;
97
82
  giocatori: GiocatorePersistito[];
98
- hostId: string | null;
99
83
  result: JsonValue | null;
100
84
  resultAt: number | null;
101
85
  daily?: import('../daily.js').DailyContext;
102
86
  rivincita?: {
103
87
  keepSetup: boolean;
104
- autoStart: boolean;
105
88
  } | null;
106
89
  prontiPrecedenti?: string[];
107
90
  countdownRivincita?: boolean;
@@ -109,7 +92,6 @@ export interface StatoPersistito {
109
92
  countdownAt: number | null;
110
93
  timer: TimerPersistito[];
111
94
  prossimoTimerId: number;
112
- punteggi: PunteggioPersistito[];
113
95
  fineInCoda: FinePersistita | null;
114
96
  flushInAttesa?: EsitoFlush & {
115
97
  id: string;
@@ -135,6 +117,7 @@ export type EsitoAscolto = {
135
117
  reason: 'mode' | 'unknown' | 'team' | 'gain';
136
118
  };
137
119
  export interface InfoStanza {
120
+ origin: 'player' | 'matchmaking';
138
121
  roomId: string;
139
122
  status: RoomStatus;
140
123
  players: number;
@@ -143,6 +126,5 @@ export interface InfoStanza {
143
126
  member: boolean;
144
127
  }
145
128
  export interface EsitoFlush {
146
- scores: PunteggioPersistito[];
147
129
  ended: FinePersistita | null;
148
130
  }
@@ -82,7 +82,6 @@ export declare class VoceClient implements Voice {
82
82
  socketDisconnesso(): void;
83
83
  socketRiconnesso(): void;
84
84
  termina(): void;
85
- private scegliMic;
86
85
  private verificaIngresso;
87
86
  private entra;
88
87
  private entraSfu;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caisual/kit",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "Client and server kit for Caisual games",
5
5
  "license": "MIT",
6
6
  "homepage": "https://caisual.com",
@@ -24,9 +24,8 @@
24
24
  "dist/runtime.d.ts",
25
25
  "dist/node.js",
26
26
  "dist/node.d.ts",
27
- "dist/overlay.js",
28
- "dist/overlay.js.map",
29
- "dist/overlay.d.ts",
27
+ "dist/host.js",
28
+ "dist/host.d.ts",
30
29
  "dist/types"
31
30
  ],
32
31
  "exports": {
@@ -50,25 +49,24 @@
50
49
  "import": "./dist/node.js",
51
50
  "default": "./dist/node.js"
52
51
  },
53
- "./overlay": {
54
- "types": "./dist/overlay.d.ts",
55
- "import": "./dist/overlay.js",
56
- "default": "./dist/overlay.js"
52
+ "./host": {
53
+ "types": "./dist/host.d.ts",
54
+ "import": "./dist/host.js",
55
+ "default": "./dist/host.js"
57
56
  }
58
57
  },
59
58
  "types": "./dist/kit.d.ts",
60
- "scripts": {
61
- "build": "node build.mjs",
62
- "prepack": "pnpm build",
63
- "typecheck": "tsc --noEmit && tsc -p tsconfig.node.json --noEmit",
64
- "test": "node verifica-dist.mjs && vitest run && WRANGLER_LOG_PATH=/tmp/caisual-kit-wrangler.log vitest run --config vitest.workers.config.ts"
65
- },
66
59
  "devDependencies": {
67
- "@caisual/contracts": "workspace:*",
68
60
  "@cloudflare/vitest-pool-workers": "^0.20.3",
69
61
  "@types/node": "^26.2.0",
70
62
  "esbuild": "^0.28.1",
71
63
  "typescript": "^7.0.2",
72
- "vitest": "^4.1.10"
64
+ "vitest": "^4.1.10",
65
+ "@caisual/contracts": "0.0.0"
66
+ },
67
+ "scripts": {
68
+ "build": "node build.mjs",
69
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.node.json --noEmit",
70
+ "test": "node verifica-dist.mjs && vitest run && WRANGLER_LOG_PATH=/tmp/caisual-kit-wrangler.log vitest run --config vitest.workers.config.ts"
73
71
  }
74
- }
72
+ }
package/dist/overlay.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './types/overlay/index.js';