diff --git a/packages/charm-sync/index.d.ts b/packages/charm-sync/index.d.ts index dfd8abf..52ff658 100644 --- a/packages/charm-sync/index.d.ts +++ b/packages/charm-sync/index.d.ts @@ -51,7 +51,9 @@ declare namespace CharmSync { * @param options The atoms to synchronize with the client. * @returns A `ServerSyncer` object. */ - function server(options: ServerOptions): ServerSyncer; + function server( + options: ServerOptions, + ): ServerSyncer; /** * Checks whether a value is `None`. If `true`, the value is scheduled to be @@ -111,27 +113,29 @@ declare namespace CharmSync { * If a value was removed, it is replaced with `None`. This can be checked * using the `sync.isNone` function. */ - type SyncPatch = - | MaybeNone - | (State extends ReadonlyMap | Map - ? ReadonlyMap | None> - : State extends Set | ReadonlySet - ? ReadonlyMap - : State extends readonly (infer T)[] - ? readonly (SyncPatch | None | undefined)[] - : State extends DataType - ? State - : State extends object - ? { readonly [P in keyof State]?: SyncPatch } - : State); + type SyncPatch = MaybeNone | State extends + | ReadonlyMap + | Map + ? ReadonlyMap | None> + : State extends Set | ReadonlySet + ? ReadonlyMap + : State extends readonly (infer T)[] + ? Serialize extends true + ? ReadonlyMap | None> + : readonly (SyncPatch | None | undefined)[] + : State extends DataType + ? State + : State extends object + ? { readonly [P in keyof State]?: SyncPatch } + : State; /** * A payload that can be sent from the server to the client to synchronize * state between the two. */ - type SyncPayload = + type SyncPayload = | { readonly type: "init"; readonly data: StateOfMap } - | { readonly type: "patch"; readonly data: SyncPatch> }; + | { readonly type: "patch"; readonly data: SyncPatch, Serialize> }; interface ClientOptions { /** @@ -145,7 +149,7 @@ declare namespace CharmSync { ignoreUnhydrated?: boolean; } - interface ServerOptions { + interface ServerOptions { /** * The atoms to synchronize with the client. */ @@ -173,7 +177,7 @@ declare namespace CharmSync { * This option should be disabled if your network library uses a custom * serialization method (i.e. Zap, ByteNet) to prevent interference. */ - autoSerialize?: boolean; + autoSerialize?: Serialize; } interface ClientSyncer { @@ -183,10 +187,10 @@ declare namespace CharmSync { * * @param payloads The patches or hydration payloads to apply. */ - sync(...payloads: SyncPayload[]): void; + sync(...payloads: SyncPayload[]): void; } - interface ServerSyncer { + interface ServerSyncer { /** * Sets up a subscription to each atom that schedules a patch to be sent to * the client whenever the state changes. When a change occurs, the `callback` @@ -198,7 +202,7 @@ declare namespace CharmSync { * @param callback The function to call when the state changes. * @returns A cleanup function that unsubscribes all listeners. */ - connect(callback: (player: Player, ...payloads: SyncPayload[]) => void): Cleanup; + connect(callback: (player: Player, ...payloads: SyncPayload[]) => void): Cleanup; /** * Hydrates the client's state with the server's state. This should be * called when a player joins the game and requires the server's state.