@pluv/io 0.30.2 → 0.32.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.
package/src/types.ts CHANGED
@@ -13,6 +13,7 @@ import type {
13
13
  } from "@pluv/types";
14
14
  import type {
15
15
  AbstractPlatform,
16
+ InferInitContextType,
16
17
  InferPlatformWebSocketSource,
17
18
  InferPlatformWebSocketType,
18
19
  InferRoomContextType,
@@ -26,6 +27,10 @@ declare global {
26
27
  };
27
28
  }
28
29
 
30
+ export type PluvContext<TPlatform extends AbstractPlatform, TContext extends Record<string, any>> =
31
+ | TContext
32
+ | ((params: InferRoomContextType<TPlatform>) => TContext);
33
+
29
34
  export interface CrdtLibraryType {
30
35
  doc: (value: any) => AbstractCrdtDocFactory<any>;
31
36
  kind: "loro" | "yjs";
@@ -33,7 +38,7 @@ export interface CrdtLibraryType {
33
38
 
34
39
  export type EventResolver<
35
40
  TPlatform extends AbstractPlatform = AbstractPlatform,
36
- TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize,
41
+ TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
37
42
  TContext extends Record<string, any> = {},
38
43
  TInput extends JsonObject = {},
39
44
  TOutput extends EventRecord<string, any> = {},
@@ -41,7 +46,7 @@ export type EventResolver<
41
46
 
42
47
  export interface EventResolverContext<
43
48
  TPlatform extends AbstractPlatform = AbstractPlatform,
44
- TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>> = BaseIOAuthorize,
49
+ TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
45
50
  TContext extends Record<string, any> = {},
46
51
  > {
47
52
  context: TContext;
@@ -103,7 +108,7 @@ export type MergeEventRecords<
103
108
 
104
109
  type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
105
110
  room: string;
106
- } & InferRoomContextType<TPlatform>;
111
+ };
107
112
 
108
113
  export type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (
109
114
  event: GetInitialStorageEvent<TPlatform>,
@@ -111,8 +116,8 @@ export type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (
111
116
 
112
117
  export interface PluvIOListeners<
113
118
  TPlatform extends AbstractPlatform<any>,
114
- TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>,
115
- TContext extends JsonObject,
119
+ TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
120
+ TContext extends Record<string, any>,
116
121
  TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
117
122
  > {
118
123
  onRoomDeleted: (event: IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents>) => void;
@@ -122,19 +127,19 @@ export interface PluvIOListeners<
122
127
 
123
128
  export type IORoomListenerEvent<
124
129
  TPlatform extends AbstractPlatform<any>,
125
- TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>,
126
- TContext extends JsonObject,
130
+ TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
131
+ TContext extends Record<string, any>,
127
132
  TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
128
133
  > = {
129
- context: TContext & InferRoomContextType<TPlatform>;
134
+ context: TContext;
130
135
  encodedState: string | null;
131
136
  room: string;
132
137
  };
133
138
 
134
139
  export type IORoomMessageEvent<
135
140
  TPlatform extends AbstractPlatform<any>,
136
- TAuthorize extends IOAuthorize<any, any, InferRoomContextType<TPlatform>>,
137
- TContext extends JsonObject,
141
+ TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>,
142
+ TContext extends Record<string, any>,
138
143
  TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext>,
139
144
  > = IORoomListenerEvent<TPlatform, TAuthorize, TContext, TEvents> & {
140
145
  message: InferEventMessage<InferEventsOutput<TEvents>, keyof InferEventsOutput<TEvents>>;
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.30.2'
2
+ export const version = '0.32.0'