@pluv/client 3.0.0 → 3.1.1
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +44 -0
- package/dist/index.d.mts +14 -11
- package/dist/index.d.ts +14 -11
- package/package.json +5 -5
- package/src/PluvClient.ts +11 -15
- package/src/PluvRoom.ts +2 -2
- package/src/createClient.ts +3 -4
- package/src/infer.ts +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/client@3.
|
|
2
|
+
> @pluv/client@3.1.1 build /home/runner/work/pluv/pluv/packages/client
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m63.03 KB[39m
|
|
12
|
-
[32mESM[39m ⚡️ Build success in 137ms
|
|
13
11
|
[32mCJS[39m [1mdist/index.js [22m[32m64.77 KB[39m
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 108ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m63.03 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 108ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5064ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m19.16 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m19.16 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @pluv/client
|
|
2
2
|
|
|
3
|
+
## 3.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/crdt@3.1.1
|
|
8
|
+
- @pluv/types@3.1.1
|
|
9
|
+
|
|
10
|
+
## 3.1.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 022857d: TypeScript will now emit an error if `initialStorage` was provided to `createClient` while `createIO` was not provided a `crdt`.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createClient, infer } from "@pluv/client";
|
|
18
|
+
import { yjs } from "@pluv/crdt-yjs";
|
|
19
|
+
import { createIO } from "@pluv/io";
|
|
20
|
+
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
21
|
+
|
|
22
|
+
const io = createIO(
|
|
23
|
+
// Assume no crdt was provided here
|
|
24
|
+
platformCloudflare({
|
|
25
|
+
/* ... */
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const ioServer = io.server();
|
|
30
|
+
|
|
31
|
+
const types = infer((i) => ({ io: i<typeof ioServer> }));
|
|
32
|
+
const client = createClient({
|
|
33
|
+
types,
|
|
34
|
+
// This will now emit a TypeScript error, because `crdt` was not provided to
|
|
35
|
+
// `createIO` above
|
|
36
|
+
initialStorage: yjs.doc((t) => ({
|
|
37
|
+
groceries: t.array<string>("groceries"),
|
|
38
|
+
})),
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- @pluv/crdt@3.1.0
|
|
45
|
+
- @pluv/types@3.1.0
|
|
46
|
+
|
|
3
47
|
## 3.0.0
|
|
4
48
|
|
|
5
49
|
### 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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "3.1.1",
|
|
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.
|
|
22
|
-
"@pluv/types": "^3.
|
|
21
|
+
"@pluv/crdt": "^3.1.1",
|
|
22
|
+
"@pluv/types": "^3.1.1"
|
|
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.
|
|
29
|
-
"eslint-config-pluv": "^3.
|
|
28
|
+
"@pluv/tsconfig": "^3.1.1",
|
|
29
|
+
"eslint-config-pluv": "^3.1.1"
|
|
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
|
-
|
|
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
|
|
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
|
|
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,
|
package/src/createClient.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
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;
|