@pluv/client 3.0.0 → 3.1.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/client@3.0.0 build /home/runner/work/pluv/pluv/packages/client
2
+ > @pluv/client@3.1.0 build /home/runner/work/pluv/pluv/packages/client
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,10 +9,10 @@
9
9
  ESM Build start
10
10
  CJS Build start
11
11
  ESM dist/index.mjs 63.03 KB
12
- ESM ⚡️ Build success in 137ms
12
+ ESM ⚡️ Build success in 108ms
13
13
  CJS dist/index.js 64.77 KB
14
- CJS ⚡️ Build success in 140ms
14
+ CJS ⚡️ Build success in 109ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 4820ms
17
- DTS dist/index.d.mts 18.99 KB
18
- DTS dist/index.d.ts 18.99 KB
16
+ DTS ⚡️ Build success in 4487ms
17
+ DTS dist/index.d.mts 19.16 KB
18
+ DTS dist/index.d.ts 19.16 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @pluv/client
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 022857d: TypeScript will now emit an error if `initialStorage` was provided to `createClient` while `createIO` was not provided a `crdt`.
8
+
9
+ ```ts
10
+ import { createClient, infer } from "@pluv/client";
11
+ import { yjs } from "@pluv/crdt-yjs";
12
+ import { createIO } from "@pluv/io";
13
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
14
+
15
+ const io = createIO(
16
+ // Assume no crdt was provided here
17
+ platformCloudflare({
18
+ /* ... */
19
+ }),
20
+ );
21
+
22
+ const ioServer = io.server();
23
+
24
+ const types = infer((i) => ({ io: i<typeof ioServer> }));
25
+ const client = createClient({
26
+ types,
27
+ // This will now emit a TypeScript error, because `crdt` was not provided to
28
+ // `createIO` above
29
+ initialStorage: yjs.doc((t) => ({
30
+ groceries: t.array<string>("groceries"),
31
+ })),
32
+ });
33
+ ```
34
+
35
+ ### Patch Changes
36
+
37
+ - @pluv/crdt@3.1.0
38
+ - @pluv/types@3.1.0
39
+
3
40
  ## 3.0.0
4
41
 
5
42
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AbstractCrdtDocFactory, InferDocLike, NoopCrdtDocFactory, InferStorage, InferDoc, InferCrdtJson } from '@pluv/crdt';
2
2
  export { CrdtType, InferCrdtJson } from '@pluv/crdt';
3
- import { IOLike, JsonObject, EventRecord, CrdtDocLike, UserInfo, MaybePromise, Id, ProcedureLike, InputZodLike, IORouterLike, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, RoomLike, InferIOOutput, InferIOInput, RoomEventListenerMap, BroadcastProxy, WebSocketConnection, SubscribeProxy, UpdateMyPresenceAction, MergeEvents } from '@pluv/types';
3
+ import { IOLike, JsonObject, EventRecord, CrdtDocLike, UserInfo, MaybePromise, Id, ProcedureLike, InputZodLike, IORouterLike, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, RoomLike, InferIOOutput, InferIOInput, RoomEventListenerMap, BroadcastProxy, WebSocketConnection, SubscribeProxy, UpdateMyPresenceAction, InferIOCrdtKind, MergeEvents } from '@pluv/types';
4
4
  export { BaseUser, ConnectionState, EventMessage, EventNotifierSubscriptionCallback, EventRecord, IOEventMessage, MergeEvents, RoomLike, UserInfo, WebSocketConnection, WebSocketState } from '@pluv/types';
5
5
 
6
6
  declare abstract class AbstractStorageStore {
@@ -16,10 +16,10 @@ declare abstract class AbstractStorageStore {
16
16
 
17
17
  declare const identity: <T extends unknown>(x: T) => T;
18
18
 
19
- type InferCallback<TIO extends IOLike<any, any>> = (i: typeof identity) => {
19
+ type InferCallback<TIO extends IOLike<any, any, any>> = (i: typeof identity) => {
20
20
  io: (io: TIO) => TIO;
21
21
  };
22
- declare const infer: <TIO extends IOLike<any, any>>(callback: InferCallback<TIO>) => InferCallback<TIO>;
22
+ declare const infer: <TIO extends IOLike<any, any, any>>(callback: InferCallback<TIO>) => InferCallback<TIO>;
23
23
 
24
24
  type EventResolver<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord<string, any>, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> = (data: TInput, context: EventResolverContext<TIO, TPresence, TDocLike>) => MaybePromise<TOutput | void>;
25
25
  interface EventResolverContext<TIO extends IOLike, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> {
@@ -108,7 +108,7 @@ type FetchOptions = {
108
108
  url: string;
109
109
  options?: RequestInit;
110
110
  };
111
- type RoomEndpoints<TIO extends IOLike<any, any>, TMetadata extends JsonObject> = {
111
+ type RoomEndpoints<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject> = {
112
112
  wsEndpoint?: WsEndpoint<TMetadata>;
113
113
  } & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser ? {
114
114
  authEndpoint: AuthEndpoint<TMetadata>;
@@ -141,7 +141,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject, TPresence exte
141
141
  reconnectTimeoutMs?: ReconnectTimeoutMs;
142
142
  router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
143
143
  } & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TCrdt>, "initialStorage"> & UsersManagerConfig<TPresence>>;
144
- declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObject = {}, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> implements RoomLike<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
144
+ declare class PluvRoom<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject = {}, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> implements RoomLike<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
145
145
  readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
146
146
  readonly id: string;
147
147
  readonly metadata?: InputZodLike<TMetadata>;
@@ -240,9 +240,8 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
240
240
  private _updateState;
241
241
  }
242
242
 
243
- type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject> = RoomEndpoints<TIO, TMetadata> & {
243
+ type PluvClientOptions<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any>, TCrdt extends InferIOCrdtKind<TIO>, TMetadata extends JsonObject> = RoomEndpoints<TIO, TMetadata> & {
244
244
  debug?: boolean;
245
- initialStorage?: TCrdt;
246
245
  /**
247
246
  * @description Configurable limits defined for client-side validation. You should only set
248
247
  * this if you control the server and have changed the limits there.
@@ -252,8 +251,12 @@ type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends Record<st
252
251
  presence?: InputZodLike<TPresence>;
253
252
  publicKey?: PublicKey<TMetadata>;
254
253
  types: InferCallback<TIO>;
255
- };
256
- type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> = {
254
+ } & (InferIOCrdtKind<TIO> extends NoopCrdtDocFactory ? {
255
+ initialStorage?: "[ERROR]: Must provide crdt to createIO to use storage";
256
+ } : {
257
+ initialStorage?: TCrdt;
258
+ });
259
+ type CreateRoomOptions<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> = {
257
260
  addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, InferStorage<TCrdt>>[];
258
261
  debug?: boolean | PluvRoomDebug<TIO>;
259
262
  initialPresence?: TPresence;
@@ -263,7 +266,7 @@ type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends Record<st
263
266
  router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
264
267
  };
265
268
  type EnterRoomParams<TMetadata extends JsonObject = {}> = keyof TMetadata extends never ? [] : [WithMetadata<TMetadata>];
266
- declare class PluvClient<TIO extends IOLike<any, any>, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TMetadata extends JsonObject = {}> {
269
+ declare class PluvClient<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any> = {}, TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>, TMetadata extends JsonObject = {}> {
267
270
  readonly metadata?: InputZodLike<TMetadata>;
268
271
  private readonly _authEndpoint;
269
272
  private readonly _debug;
@@ -287,7 +290,7 @@ declare class PluvClient<TIO extends IOLike<any, any>, TPresence extends Record<
287
290
  private _logDebug;
288
291
  }
289
292
 
290
- declare const createClient: <TIO extends IOLike<any, any>, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TMetadata extends JsonObject = {}>(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>) => PluvClient<TIO, TPresence, TCrdt, TMetadata>;
293
+ declare const createClient: <TIO extends IOLike<any, any, any>, TPresence extends Record<string, any> = {}, TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>, TMetadata extends JsonObject = {}>(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>) => PluvClient<TIO, TPresence, TCrdt, TMetadata>;
291
294
 
292
295
  type MockedRoomEvents<TIO extends IOLike> = Partial<{
293
296
  [P in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>[P]>) => Partial<InferIOOutput<TIO>>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AbstractCrdtDocFactory, InferDocLike, NoopCrdtDocFactory, InferStorage, InferDoc, InferCrdtJson } from '@pluv/crdt';
2
2
  export { CrdtType, InferCrdtJson } from '@pluv/crdt';
3
- import { IOLike, JsonObject, EventRecord, CrdtDocLike, UserInfo, MaybePromise, Id, ProcedureLike, InputZodLike, IORouterLike, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, RoomLike, InferIOOutput, InferIOInput, RoomEventListenerMap, BroadcastProxy, WebSocketConnection, SubscribeProxy, UpdateMyPresenceAction, MergeEvents } from '@pluv/types';
3
+ import { IOLike, JsonObject, EventRecord, CrdtDocLike, UserInfo, MaybePromise, Id, ProcedureLike, InputZodLike, IORouterLike, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, RoomLike, InferIOOutput, InferIOInput, RoomEventListenerMap, BroadcastProxy, WebSocketConnection, SubscribeProxy, UpdateMyPresenceAction, InferIOCrdtKind, MergeEvents } from '@pluv/types';
4
4
  export { BaseUser, ConnectionState, EventMessage, EventNotifierSubscriptionCallback, EventRecord, IOEventMessage, MergeEvents, RoomLike, UserInfo, WebSocketConnection, WebSocketState } from '@pluv/types';
5
5
 
6
6
  declare abstract class AbstractStorageStore {
@@ -16,10 +16,10 @@ declare abstract class AbstractStorageStore {
16
16
 
17
17
  declare const identity: <T extends unknown>(x: T) => T;
18
18
 
19
- type InferCallback<TIO extends IOLike<any, any>> = (i: typeof identity) => {
19
+ type InferCallback<TIO extends IOLike<any, any, any>> = (i: typeof identity) => {
20
20
  io: (io: TIO) => TIO;
21
21
  };
22
- declare const infer: <TIO extends IOLike<any, any>>(callback: InferCallback<TIO>) => InferCallback<TIO>;
22
+ declare const infer: <TIO extends IOLike<any, any, any>>(callback: InferCallback<TIO>) => InferCallback<TIO>;
23
23
 
24
24
  type EventResolver<TIO extends IOLike, TInput extends JsonObject, TOutput extends EventRecord<string, any>, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> = (data: TInput, context: EventResolverContext<TIO, TPresence, TDocLike>) => MaybePromise<TOutput | void>;
25
25
  interface EventResolverContext<TIO extends IOLike, TPresence extends Record<string, any>, TDocLike extends CrdtDocLike<any, any>> {
@@ -108,7 +108,7 @@ type FetchOptions = {
108
108
  url: string;
109
109
  options?: RequestInit;
110
110
  };
111
- type RoomEndpoints<TIO extends IOLike<any, any>, TMetadata extends JsonObject> = {
111
+ type RoomEndpoints<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject> = {
112
112
  wsEndpoint?: WsEndpoint<TMetadata>;
113
113
  } & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser ? {
114
114
  authEndpoint: AuthEndpoint<TMetadata>;
@@ -141,7 +141,7 @@ type RoomConfig<TIO extends IOLike, TMetadata extends JsonObject, TPresence exte
141
141
  reconnectTimeoutMs?: ReconnectTimeoutMs;
142
142
  router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
143
143
  } & RoomEndpoints<TIO, TMetadata> & Pick<CrdtManagerOptions<TCrdt>, "initialStorage"> & UsersManagerConfig<TPresence>>;
144
- declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObject = {}, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> implements RoomLike<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
144
+ declare class PluvRoom<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject = {}, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> implements RoomLike<TIO, InferDoc<TCrdt>, TPresence, InferStorage<TCrdt>> {
145
145
  readonly _endpoints: RoomEndpoints<TIO, TMetadata>;
146
146
  readonly id: string;
147
147
  readonly metadata?: InputZodLike<TMetadata>;
@@ -240,9 +240,8 @@ declare class PluvRoom<TIO extends IOLike<any, any>, TMetadata extends JsonObjec
240
240
  private _updateState;
241
241
  }
242
242
 
243
- type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject> = RoomEndpoints<TIO, TMetadata> & {
243
+ type PluvClientOptions<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any>, TCrdt extends InferIOCrdtKind<TIO>, TMetadata extends JsonObject> = RoomEndpoints<TIO, TMetadata> & {
244
244
  debug?: boolean;
245
- initialStorage?: TCrdt;
246
245
  /**
247
246
  * @description Configurable limits defined for client-side validation. You should only set
248
247
  * this if you control the server and have changed the limits there.
@@ -252,8 +251,12 @@ type PluvClientOptions<TIO extends IOLike<any, any>, TPresence extends Record<st
252
251
  presence?: InputZodLike<TPresence>;
253
252
  publicKey?: PublicKey<TMetadata>;
254
253
  types: InferCallback<TIO>;
255
- };
256
- type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> = {
254
+ } & (InferIOCrdtKind<TIO> extends NoopCrdtDocFactory ? {
255
+ initialStorage?: "[ERROR]: Must provide crdt to createIO to use storage";
256
+ } : {
257
+ initialStorage?: TCrdt;
258
+ });
259
+ type CreateRoomOptions<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>, TMetadata extends JsonObject, TEvents extends PluvRouterEventConfig<TIO, TPresence, InferStorage<TCrdt>> = {}> = {
257
260
  addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, InferStorage<TCrdt>>[];
258
261
  debug?: boolean | PluvRoomDebug<TIO>;
259
262
  initialPresence?: TPresence;
@@ -263,7 +266,7 @@ type CreateRoomOptions<TIO extends IOLike<any, any>, TPresence extends Record<st
263
266
  router?: PluvRouter<TIO, TPresence, InferStorage<TCrdt>, TEvents>;
264
267
  };
265
268
  type EnterRoomParams<TMetadata extends JsonObject = {}> = keyof TMetadata extends never ? [] : [WithMetadata<TMetadata>];
266
- declare class PluvClient<TIO extends IOLike<any, any>, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TMetadata extends JsonObject = {}> {
269
+ declare class PluvClient<TIO extends IOLike<any, any, any>, TPresence extends Record<string, any> = {}, TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>, TMetadata extends JsonObject = {}> {
267
270
  readonly metadata?: InputZodLike<TMetadata>;
268
271
  private readonly _authEndpoint;
269
272
  private readonly _debug;
@@ -287,7 +290,7 @@ declare class PluvClient<TIO extends IOLike<any, any>, TPresence extends Record<
287
290
  private _logDebug;
288
291
  }
289
292
 
290
- declare const createClient: <TIO extends IOLike<any, any>, TPresence extends Record<string, any> = {}, TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory, TMetadata extends JsonObject = {}>(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>) => PluvClient<TIO, TPresence, TCrdt, TMetadata>;
293
+ declare const createClient: <TIO extends IOLike<any, any, any>, TPresence extends Record<string, any> = {}, TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>, TMetadata extends JsonObject = {}>(options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>) => PluvClient<TIO, TPresence, TCrdt, TMetadata>;
291
294
 
292
295
  type MockedRoomEvents<TIO extends IOLike> = Partial<{
293
296
  [P in keyof InferIOInput<TIO>]: (data: Id<InferIOInput<TIO>[P]>) => Partial<InferIOOutput<TIO>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "@pluv/io frontend client",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "wonka": "^6.3.5",
21
- "@pluv/crdt": "^3.0.0",
22
- "@pluv/types": "^3.0.0"
21
+ "@pluv/crdt": "^3.1.0",
22
+ "@pluv/types": "^3.1.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "^9.27.0",
26
26
  "tsup": "^8.5.0",
27
27
  "typescript": "^5.8.3",
28
- "@pluv/tsconfig": "^3.0.0",
29
- "eslint-config-pluv": "^3.0.0"
28
+ "@pluv/tsconfig": "^3.1.0",
29
+ "eslint-config-pluv": "^3.1.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
package/src/PluvClient.ts CHANGED
@@ -1,10 +1,5 @@
1
- import type {
2
- AbstractCrdtDocFactory,
3
- CrdtType,
4
- InferStorage,
5
- NoopCrdtDocFactory,
6
- } from "@pluv/crdt";
7
- import type { InputZodLike, IOLike, JsonObject } from "@pluv/types";
1
+ import type { AbstractCrdtDocFactory, InferStorage, NoopCrdtDocFactory } from "@pluv/crdt";
2
+ import type { InferIOCrdtKind, InputZodLike, IOLike, JsonObject } from "@pluv/types";
8
3
  import { MAX_PRESENCE_SIZE_BYTES } from "./constants";
9
4
  import type { InferCallback } from "./infer";
10
5
  import { PluvProcedure } from "./PluvProcedure";
@@ -23,13 +18,12 @@ import { PluvRouter } from "./PluvRouter";
23
18
  import type { PluvClientLimits, PublicKey, WithMetadata } from "./types";
24
19
 
25
20
  export type PluvClientOptions<
26
- TIO extends IOLike<any, any>,
21
+ TIO extends IOLike<any, any, any>,
27
22
  TPresence extends Record<string, any>,
28
- TCrdt extends AbstractCrdtDocFactory<any, any>,
23
+ TCrdt extends InferIOCrdtKind<TIO>,
29
24
  TMetadata extends JsonObject,
30
25
  > = RoomEndpoints<TIO, TMetadata> & {
31
26
  debug?: boolean;
32
- initialStorage?: TCrdt;
33
27
  /**
34
28
  * @description Configurable limits defined for client-side validation. You should only set
35
29
  * this if you control the server and have changed the limits there.
@@ -39,10 +33,12 @@ export type PluvClientOptions<
39
33
  presence?: InputZodLike<TPresence>;
40
34
  publicKey?: PublicKey<TMetadata>;
41
35
  types: InferCallback<TIO>;
42
- };
36
+ } & (InferIOCrdtKind<TIO> extends NoopCrdtDocFactory
37
+ ? { initialStorage?: "[ERROR]: Must provide crdt to createIO to use storage" }
38
+ : { initialStorage?: TCrdt });
43
39
 
44
40
  export type CreateRoomOptions<
45
- TIO extends IOLike<any, any>,
41
+ TIO extends IOLike<any, any, any>,
46
42
  TPresence extends Record<string, any>,
47
43
  TCrdt extends AbstractCrdtDocFactory<any, any>,
48
44
  TMetadata extends JsonObject,
@@ -62,9 +58,9 @@ export type EnterRoomParams<TMetadata extends JsonObject = {}> = keyof TMetadata
62
58
  : [WithMetadata<TMetadata>];
63
59
 
64
60
  export class PluvClient<
65
- TIO extends IOLike<any, any>,
61
+ TIO extends IOLike<any, any, any>,
66
62
  TPresence extends Record<string, any> = {},
67
- TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory,
63
+ TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>,
68
64
  TMetadata extends JsonObject = {},
69
65
  > {
70
66
  public readonly metadata?: InputZodLike<TMetadata>;
@@ -104,7 +100,7 @@ export class PluvClient<
104
100
 
105
101
  this._authEndpoint = authEndpoint as AuthEndpoint<TMetadata>;
106
102
  this._debug = debug;
107
- this._initialStorage = initialStorage;
103
+ this._initialStorage = initialStorage as TCrdt;
108
104
  this._limits = {
109
105
  presenceMaxSize: MAX_PRESENCE_SIZE_BYTES,
110
106
  ...limits,
package/src/PluvRoom.ts CHANGED
@@ -134,7 +134,7 @@ export type WsEndpoint<TMetadata extends JsonObject> =
134
134
 
135
135
  type FetchOptions = { url: string; options?: RequestInit };
136
136
 
137
- export type RoomEndpoints<TIO extends IOLike<any, any>, TMetadata extends JsonObject> = {
137
+ export type RoomEndpoints<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject> = {
138
138
  wsEndpoint?: WsEndpoint<TMetadata>;
139
139
  } & (InferIOAuthorizeUser<InferIOAuthorize<TIO>> extends BaseUser
140
140
  ? { authEndpoint: AuthEndpoint<TMetadata> }
@@ -204,7 +204,7 @@ export type RoomConfig<
204
204
  >;
205
205
 
206
206
  export class PluvRoom<
207
- TIO extends IOLike<any, any>,
207
+ TIO extends IOLike<any, any, any>,
208
208
  TMetadata extends JsonObject = {},
209
209
  TPresence extends Record<string, any> = {},
210
210
  TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory,
@@ -1,12 +1,11 @@
1
- import type { AbstractCrdtDocFactory, NoopCrdtDocFactory } from "@pluv/crdt";
2
- import type { IOLike, JsonObject } from "@pluv/types";
1
+ import type { InferIOCrdtKind, IOLike, JsonObject } from "@pluv/types";
3
2
  import type { PluvClientOptions } from "./PluvClient";
4
3
  import { PluvClient } from "./PluvClient";
5
4
 
6
5
  export const createClient = <
7
- TIO extends IOLike<any, any>,
6
+ TIO extends IOLike<any, any, any>,
8
7
  TPresence extends Record<string, any> = {},
9
- TCrdt extends AbstractCrdtDocFactory<any, any> = NoopCrdtDocFactory,
8
+ TCrdt extends InferIOCrdtKind<TIO> = InferIOCrdtKind<TIO>,
10
9
  TMetadata extends JsonObject = {},
11
10
  >(
12
11
  options: PluvClientOptions<TIO, TPresence, TCrdt, TMetadata>,
package/src/infer.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { IOLike } from "@pluv/types";
2
2
  import type { identity } from "./utils";
3
3
 
4
- export type InferCallback<TIO extends IOLike<any, any>> = (i: typeof identity) => {
4
+ export type InferCallback<TIO extends IOLike<any, any, any>> = (i: typeof identity) => {
5
5
  io: (io: TIO) => TIO;
6
6
  };
7
7
 
8
- export const infer = <TIO extends IOLike<any, any>>(
8
+ export const infer = <TIO extends IOLike<any, any, any>>(
9
9
  callback: InferCallback<TIO>,
10
10
  ): InferCallback<TIO> => callback;