@caisual/kit 0.20.0 → 0.22.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 (46) hide show
  1. package/README.md +6 -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 +182 -457
  7. package/dist/runtime.js +236 -299
  8. package/dist/types/api.d.ts +2 -9
  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 -3
  12. package/dist/types/contracts/manifest.d.ts +6 -40
  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 -38
  18. package/dist/types/index.d.ts +64 -90
  19. package/dist/types/node/index.d.ts +6 -27
  20. package/dist/types/protocollo.d.ts +1 -20
  21. package/dist/types/runtime/index.d.ts +8 -15
  22. package/dist/types/runtime/network-probe.d.ts +4 -0
  23. package/dist/types/server/index.d.ts +0 -20
  24. package/dist/types/stanza/nucleo.d.ts +12 -17
  25. package/dist/types/stanza/tipi.d.ts +7 -23
  26. package/dist/types/voce/index.d.ts +0 -1
  27. package/package.json +16 -19
  28. package/dist/overlay.d.ts +0 -1
  29. package/dist/overlay.js +0 -2326
  30. package/dist/overlay.js.map +0 -7
  31. package/dist/types/contracts/overlay-boards.d.ts +0 -3
  32. package/dist/types/contracts/overlay.d.ts +0 -240
  33. package/dist/types/contracts/replay.d.ts +0 -83
  34. package/dist/types/overlay/boards.d.ts +0 -48
  35. package/dist/types/overlay/bridge.d.ts +0 -3
  36. package/dist/types/overlay/i18n.d.ts +0 -146
  37. package/dist/types/overlay/index.d.ts +0 -10
  38. package/dist/types/overlay/locale.d.ts +0 -4
  39. package/dist/types/overlay/shortcut.d.ts +0 -4
  40. package/dist/types/overlay/styles.d.ts +0 -1
  41. package/dist/types/overlay/ui-model.d.ts +0 -53
  42. package/dist/types/overlay/ui.d.ts +0 -83
  43. package/dist/types/overlay/voice-panel.d.ts +0 -13
  44. package/dist/types/replay/index.d.ts +0 -65
  45. package/dist/types/session/index.d.ts +0 -50
  46. 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 = {
@@ -43,7 +42,6 @@ export interface RoomConfiguration {
43
42
  export interface StanzaProtocollo {
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,10 +1,7 @@
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 {
4
- boards?: Record<string, {
5
- source: 'client' | 'server';
6
- day?: 'submit' | 'start';
7
- }>;
8
5
  id: string;
9
6
  players: {
10
7
  min: number;
@@ -12,7 +9,6 @@ export interface RoomManifest {
12
9
  };
13
10
  lobby: boolean;
14
11
  persistent?: boolean;
15
- replays?: boolean;
16
12
  roles: Array<{
17
13
  id: string;
18
14
  min: number;
@@ -24,7 +20,6 @@ export interface RoomManifest {
24
20
  } | null;
25
21
  modes: Array<{
26
22
  id: string;
27
- execution?: 'local' | 'room';
28
23
  players?: {
29
24
  min: number;
30
25
  max: number;
@@ -43,7 +38,6 @@ export interface Esito {
43
38
  connessione: string;
44
39
  testo: string;
45
40
  }>;
46
- pubblici: string[];
47
41
  chiusure: Array<{
48
42
  connessione: string;
49
43
  codice: number;
@@ -56,6 +50,8 @@ export interface Esito {
56
50
  voceRivedi: boolean;
57
51
  }
58
52
  export interface InfoStanza {
53
+ origin: 'player' | 'matchmaking';
54
+ lobby: boolean;
59
55
  roomId: string;
60
56
  status: RoomStatus;
61
57
  players: number;
@@ -76,14 +72,6 @@ export type EsitoAscolto = {
76
72
  reason: 'mode' | 'unknown' | 'team' | 'gain';
77
73
  };
78
74
  export interface EsitoFlush {
79
- scores: Array<{
80
- playerId: string;
81
- board: string;
82
- score: number;
83
- daily: boolean;
84
- day?: string | null;
85
- submittedAt?: number;
86
- }>;
87
75
  ended: {
88
76
  result: JsonValue;
89
77
  at: number;
@@ -93,6 +81,7 @@ export interface FacetStanza {
93
81
  crea(input: {
94
82
  mode: string | null;
95
83
  creator: IdentitaGiocatore;
84
+ origin?: 'player' | 'matchmaking';
96
85
  }): Promise<Esito & {
97
86
  ok: boolean;
98
87
  }>;
@@ -107,6 +96,10 @@ export interface FacetStanza {
107
96
  tick(): Promise<Esito>;
108
97
  sveglia(): Promise<Esito>;
109
98
  flush(): Promise<EsitoFlush>;
99
+ preparaFlush(): Promise<(EsitoFlush & {
100
+ id: string;
101
+ }) | null>;
102
+ confermaFlush(id: string): Promise<void>;
110
103
  }
111
104
  export interface StorageFacet {
112
105
  get<T>(chiave: string): Promise<T | undefined>;
@@ -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
8
  export type RoomStatus = '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,18 +36,7 @@ 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
- readonly board: {
51
- submit(board: string, score: number, options?: {
52
- daily?: boolean;
53
- day?: string;
54
- }): void;
55
- submit(player: Player | string, board: string, score: number, options?: {
56
- daily?: boolean;
57
- day?: string;
58
- }): void;
59
- };
60
40
  readonly daily: {
61
41
  readonly day: string;
62
42
  readonly seed: number;
@@ -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;
@@ -34,6 +33,10 @@ export declare class NucleoStanza {
34
33
  ricevi(connessione: string, frame: string, limiteVerificato?: boolean): Promise<void>;
35
34
  eseguiTick(): Promise<void>;
36
35
  sveglia(): Promise<void>;
36
+ preparaFlush(): Promise<(EsitoFlush & {
37
+ id: string;
38
+ }) | null>;
39
+ confermaFlush(id: string): Promise<void>;
37
40
  flush(): Promise<EsitoFlush>;
38
41
  riconciliaConnessioni(): Promise<void>;
39
42
  private ruoloAutomatico;
@@ -48,29 +51,22 @@ export declare class NucleoStanza {
48
51
  private rivincita;
49
52
  private prontiRivincita;
50
53
  private avviaRivincita;
51
- private avviaCountdown;
52
- 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;
53
60
  private messaggioErrato;
54
61
  private chiudiConnessione;
55
62
  private rimuoviGiocatore;
56
- private assegnaHost;
57
63
  private eseguiTimer;
58
64
  private pianifica;
59
65
  private giornata;
60
66
  private contestoGiornaliero;
61
- private accodaPunteggio;
62
67
  private richiediFine;
63
68
  private salva;
64
69
  private caricaSave;
65
- private verificaChiaveDeposito;
66
- private verificaPrefissoDeposito;
67
- private contaOperazioneDeposito;
68
- private usaDeposito;
69
- private leggiDeposito;
70
- private scriviDeposito;
71
- private eliminaDeposito;
72
- private elencaDeposito;
73
- private incrementaDeposito;
74
70
  private messaggioCreatore;
75
71
  private broadcastCreatore;
76
72
  private inviaCreatore;
@@ -82,7 +78,6 @@ export declare class NucleoStanza {
82
78
  private inviaGiocatori;
83
79
  private inviaStatus;
84
80
  private inviaDiff;
85
- private iniziaReplay;
86
81
  private inviaSnapshotTutti;
87
82
  private chiama;
88
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;
@@ -8,11 +8,6 @@ export interface ManifestStanza {
8
8
  };
9
9
  lobby: boolean;
10
10
  persistent?: boolean;
11
- replays?: boolean;
12
- boards?: Record<string, {
13
- source: 'client' | 'server';
14
- day?: 'submit' | 'start';
15
- }>;
16
11
  roles: Array<{
17
12
  id: string;
18
13
  min: number;
@@ -24,7 +19,6 @@ export interface ManifestStanza {
24
19
  } | null;
25
20
  modes: Array<{
26
21
  id: string;
27
- execution?: 'local' | 'room';
28
22
  players?: {
29
23
  min: number;
30
24
  max: number;
@@ -39,13 +33,9 @@ export interface ArchivioStanza {
39
33
  delete(key: string): Promise<void>;
40
34
  list(prefix?: string): Promise<Map<string, unknown>>;
41
35
  }
42
- export type DepositoCondiviso = SharedGameStore;
43
36
  export interface AdattatoreStanza {
44
37
  readonly storage: ArchivioStanza;
45
- readonly deposito: DepositoCondiviso | null;
46
38
  invia(connessione: string, messaggio: MessaggioServerStanza): void;
47
- inizioReplay?(fotografia: import('../protocollo.js').FotografiaStanza): void;
48
- pubblica(messaggio: MessaggioServerStanza): void;
49
39
  chiudi(connessione: string, codice: number, motivo: string): void;
50
40
  connessioniAttive(): readonly string[];
51
41
  ora(): number;
@@ -76,20 +66,13 @@ export interface TimerPersistito {
76
66
  handler: string;
77
67
  payload: JsonValue;
78
68
  }
79
- export interface PunteggioPersistito {
80
- playerId: string;
81
- board: string;
82
- score: number;
83
- daily: boolean;
84
- day?: string | null;
85
- submittedAt?: number;
86
- }
87
69
  export interface FinePersistita {
88
70
  result: JsonValue;
89
71
  at: number;
90
72
  }
91
73
  export interface StatoPersistito {
92
74
  versione: 1;
75
+ origin: 'player' | 'matchmaking';
93
76
  id: string;
94
77
  mode: string | null;
95
78
  status: RoomStatus;
@@ -99,13 +82,11 @@ export interface StatoPersistito {
99
82
  ultimoCambioStatoAt: number;
100
83
  state: JsonValue;
101
84
  giocatori: GiocatorePersistito[];
102
- hostId: string | null;
103
85
  result: JsonValue | null;
104
86
  resultAt: number | null;
105
87
  daily?: import('../daily.js').DailyContext;
106
88
  rivincita?: {
107
89
  keepSetup: boolean;
108
- autoStart: boolean;
109
90
  } | null;
110
91
  prontiPrecedenti?: string[];
111
92
  countdownRivincita?: boolean;
@@ -113,8 +94,10 @@ export interface StatoPersistito {
113
94
  countdownAt: number | null;
114
95
  timer: TimerPersistito[];
115
96
  prossimoTimerId: number;
116
- punteggi: PunteggioPersistito[];
117
97
  fineInCoda: FinePersistita | null;
98
+ flushInAttesa?: EsitoFlush & {
99
+ id: string;
100
+ };
118
101
  vuotaDa: number | null;
119
102
  cancellaDopoFlush: boolean;
120
103
  tickSincronizzato: number;
@@ -136,6 +119,8 @@ export type EsitoAscolto = {
136
119
  reason: 'mode' | 'unknown' | 'team' | 'gain';
137
120
  };
138
121
  export interface InfoStanza {
122
+ origin: 'player' | 'matchmaking';
123
+ lobby: boolean;
139
124
  roomId: string;
140
125
  status: RoomStatus;
141
126
  players: number;
@@ -144,6 +129,5 @@ export interface InfoStanza {
144
129
  member: boolean;
145
130
  }
146
131
  export interface EsitoFlush {
147
- scores: PunteggioPersistito[];
148
132
  ended: FinePersistita | null;
149
133
  }
@@ -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.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Client and server kit for Caisual games",
5
5
  "license": "MIT",
6
6
  "homepage": "https://caisual.com",
@@ -10,8 +10,7 @@
10
10
  "multiplayer",
11
11
  "game-kit",
12
12
  "websocket",
13
- "rooms",
14
- "leaderboards"
13
+ "rooms"
15
14
  ],
16
15
  "author": "Damiano Rodriguez",
17
16
  "type": "module",
@@ -25,9 +24,8 @@
25
24
  "dist/runtime.d.ts",
26
25
  "dist/node.js",
27
26
  "dist/node.d.ts",
28
- "dist/overlay.js",
29
- "dist/overlay.js.map",
30
- "dist/overlay.d.ts",
27
+ "dist/host.js",
28
+ "dist/host.d.ts",
31
29
  "dist/types"
32
30
  ],
33
31
  "exports": {
@@ -51,25 +49,24 @@
51
49
  "import": "./dist/node.js",
52
50
  "default": "./dist/node.js"
53
51
  },
54
- "./overlay": {
55
- "types": "./dist/overlay.d.ts",
56
- "import": "./dist/overlay.js",
57
- "default": "./dist/overlay.js"
52
+ "./host": {
53
+ "types": "./dist/host.d.ts",
54
+ "import": "./dist/host.js",
55
+ "default": "./dist/host.js"
58
56
  }
59
57
  },
60
58
  "types": "./dist/kit.d.ts",
61
- "scripts": {
62
- "build": "node build.mjs",
63
- "prepack": "pnpm build",
64
- "typecheck": "tsc --noEmit && tsc -p tsconfig.node.json --noEmit",
65
- "test": "node verifica-dist.mjs && vitest run && WRANGLER_LOG_PATH=/tmp/caisual-kit-wrangler.log vitest run --config vitest.workers.config.ts"
66
- },
67
59
  "devDependencies": {
68
- "@caisual/contracts": "workspace:*",
69
60
  "@cloudflare/vitest-pool-workers": "^0.20.3",
70
61
  "@types/node": "^26.2.0",
71
62
  "esbuild": "^0.28.1",
72
63
  "typescript": "^7.0.2",
73
- "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"
74
71
  }
75
- }
72
+ }
package/dist/overlay.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './types/overlay/index.js';