@pluv/io 0.34.0 → 0.34.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 +8 -0
- package/dist/index.d.mts +10 -21
- package/dist/index.d.ts +10 -21
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -5
- package/src/IORoom.ts +5 -6
- package/src/PluvProcedure.ts +12 -11
- package/src/types.ts +9 -14
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.34.
|
|
2
|
+
> @pluv/io@0.34.1 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> pnpm run version && tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @pluv/io@0.34.
|
|
6
|
+
> @pluv/io@0.34.1 version /home/runner/work/pluv/pluv/packages/io
|
|
7
7
|
> genversion ./src/version.generated.ts --esm
|
|
8
8
|
|
|
9
9
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
15
|
[32mCJS[39m [1mdist/index.js [22m[32m45.55 KB[39m
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 157ms
|
|
17
17
|
[32mESM[39m [1mdist/index.mjs [22m[32m43.38 KB[39m
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 158ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 2554ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m29.94 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m29.94 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -83,10 +83,10 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
|
-
broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
86
|
+
broadcast?: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
87
87
|
input?: InputZodLike<TInput>;
|
|
88
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
89
|
-
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
88
|
+
self?: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
89
|
+
sync?: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
90
90
|
}
|
|
91
91
|
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
92
92
|
private _broadcast;
|
|
@@ -95,10 +95,10 @@ declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize
|
|
|
95
95
|
private _sync;
|
|
96
96
|
get config(): ProcedureLike<TInput, TOutput>["config"];
|
|
97
97
|
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
98
|
-
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
98
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
99
99
|
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
100
|
-
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
101
|
-
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
100
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
101
|
+
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
102
102
|
private _resolver;
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -127,24 +127,13 @@ interface CrdtLibraryType {
|
|
|
127
127
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
128
128
|
kind: "loro" | "yjs";
|
|
129
129
|
}
|
|
130
|
-
type
|
|
131
|
-
|
|
130
|
+
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
131
|
+
type EventResolver<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
132
|
+
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
132
133
|
context: TContext;
|
|
133
134
|
doc: AbstractCrdtDoc<any>;
|
|
134
135
|
room: string;
|
|
135
|
-
|
|
136
|
-
* !HACK
|
|
137
|
-
* @description Session should only not exist when invoking the event as a
|
|
138
|
-
* "sync" event on another machine where the session doesn't exist. There must
|
|
139
|
-
* be a better way to handle this, but going to make this nullable for ease
|
|
140
|
-
* for now.
|
|
141
|
-
*
|
|
142
|
-
* `session` should not be referenced most of the time anyhow (outside of
|
|
143
|
-
* internal to this library).
|
|
144
|
-
* @author leedavidcs
|
|
145
|
-
* @date December 25, 2022
|
|
146
|
-
*/
|
|
147
|
-
session: WebSocketSession<TAuthorize> | null;
|
|
136
|
+
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
148
137
|
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
149
138
|
}
|
|
150
139
|
type SendMessageOptions = {
|
package/dist/index.d.ts
CHANGED
|
@@ -83,10 +83,10 @@ declare abstract class AbstractWebSocket<TWebSocket = any> {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
interface PluvProcedureConfig<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> {
|
|
86
|
-
broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
86
|
+
broadcast?: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
87
87
|
input?: InputZodLike<TInput>;
|
|
88
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
89
|
-
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
88
|
+
self?: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
89
|
+
sync?: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
90
90
|
}
|
|
91
91
|
declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>>, TContext extends Record<string, any>, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}, TFilled extends "input" | "broadcast" | "self" | "sync" | "" = ""> {
|
|
92
92
|
private _broadcast;
|
|
@@ -95,10 +95,10 @@ declare class PluvProcedure<TPlatform extends AbstractPlatform<any>, TAuthorize
|
|
|
95
95
|
private _sync;
|
|
96
96
|
get config(): ProcedureLike<TInput, TOutput>["config"];
|
|
97
97
|
constructor(config?: PluvProcedureConfig<TPlatform, TAuthorize, TContext, TInput, TOutput>);
|
|
98
|
-
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
98
|
+
broadcast<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "broadcast">, TFilled | "input" | "broadcast">;
|
|
99
99
|
input<TData extends JsonObject>(input: InputZodLike<TData>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TData, {}, TFilled | "input">, TFilled | "input">;
|
|
100
|
-
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
101
|
-
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
100
|
+
self<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "self">, TFilled | "input" | "self">;
|
|
101
|
+
sync<TResult extends EventRecord<string, any> = {}>(resolver: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, TResult>): Omit<PluvProcedure<TPlatform, TAuthorize, TContext, TInput, MergeEventRecords<[TOutput, TResult]>, TFilled | "input" | "sync">, TFilled | "input" | "sync">;
|
|
102
102
|
private _resolver;
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -127,24 +127,13 @@ interface CrdtLibraryType {
|
|
|
127
127
|
doc: (value: any) => AbstractCrdtDocFactory<any>;
|
|
128
128
|
kind: "loro" | "yjs";
|
|
129
129
|
}
|
|
130
|
-
type
|
|
131
|
-
|
|
130
|
+
type EventResolverKind = "broadcast" | "self" | "sync";
|
|
131
|
+
type EventResolver<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}, TInput extends JsonObject = {}, TOutput extends EventRecord<string, any> = {}> = (data: TInput, context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>) => MaybePromise<TOutput | void>;
|
|
132
|
+
interface EventResolverContext<TKind extends EventResolverKind = EventResolverKind, TPlatform extends AbstractPlatform = AbstractPlatform, TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize, TContext extends Record<string, any> = {}> {
|
|
132
133
|
context: TContext;
|
|
133
134
|
doc: AbstractCrdtDoc<any>;
|
|
134
135
|
room: string;
|
|
135
|
-
|
|
136
|
-
* !HACK
|
|
137
|
-
* @description Session should only not exist when invoking the event as a
|
|
138
|
-
* "sync" event on another machine where the session doesn't exist. There must
|
|
139
|
-
* be a better way to handle this, but going to make this nullable for ease
|
|
140
|
-
* for now.
|
|
141
|
-
*
|
|
142
|
-
* `session` should not be referenced most of the time anyhow (outside of
|
|
143
|
-
* internal to this library).
|
|
144
|
-
* @author leedavidcs
|
|
145
|
-
* @date December 25, 2022
|
|
146
|
-
*/
|
|
147
|
-
session: WebSocketSession<TAuthorize> | null;
|
|
136
|
+
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
148
137
|
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
149
138
|
}
|
|
150
139
|
type SendMessageOptions = {
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.1",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"jose": "^5.9.6",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.4",
|
|
24
|
-
"@pluv/crdt": "^0.34.
|
|
25
|
-
"@pluv/types": "^0.34.
|
|
24
|
+
"@pluv/crdt": "^0.34.1",
|
|
25
|
+
"@pluv/types": "^0.34.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.1",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
30
|
"tsup": "^8.3.5",
|
|
31
31
|
"typescript": "^5.7.2",
|
|
32
|
-
"@pluv/tsconfig": "^0.34.
|
|
33
|
-
"eslint-config-pluv": "^0.34.
|
|
32
|
+
"@pluv/tsconfig": "^0.34.1",
|
|
33
|
+
"eslint-config-pluv": "^0.34.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/IORoom.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { AbstractCrdtDoc, AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
2
|
import { noop } from "@pluv/crdt";
|
|
3
3
|
import type {
|
|
4
|
-
BaseIOAuthorize,
|
|
5
4
|
BaseIOEventRecord,
|
|
6
5
|
EventMessage,
|
|
7
|
-
IOAuthorize,
|
|
8
6
|
IOEventMessage,
|
|
9
7
|
IOLike,
|
|
10
8
|
Id,
|
|
@@ -13,7 +11,6 @@ import type {
|
|
|
13
11
|
InferIOAuthorize,
|
|
14
12
|
InferIOAuthorizeUser,
|
|
15
13
|
InferIOInput,
|
|
16
|
-
InputZodLike,
|
|
17
14
|
JsonObject,
|
|
18
15
|
Maybe,
|
|
19
16
|
} from "@pluv/types";
|
|
@@ -24,12 +21,14 @@ import type {
|
|
|
24
21
|
InferPlatformWebSocketSource,
|
|
25
22
|
InferRoomContextType,
|
|
26
23
|
} from "./AbstractPlatform";
|
|
27
|
-
import { AbstractCloseEvent, AbstractErrorEvent, AbstractMessageEvent
|
|
24
|
+
import type { AbstractCloseEvent, AbstractErrorEvent, AbstractMessageEvent } from "./AbstractWebSocket";
|
|
25
|
+
import { AbstractWebSocket } from "./AbstractWebSocket";
|
|
28
26
|
import type { PluvRouter, PluvRouterEventConfig } from "./PluvRouter";
|
|
29
27
|
import { authorize } from "./authorize";
|
|
30
28
|
import { PING_TIMEOUT_MS } from "./constants";
|
|
31
29
|
import type {
|
|
32
30
|
EventResolverContext,
|
|
31
|
+
EventResolverKind,
|
|
33
32
|
IORoomListenerEvent,
|
|
34
33
|
IORoomMessageEvent,
|
|
35
34
|
IOUserConnectedEvent,
|
|
@@ -646,7 +645,7 @@ export class IORoom<
|
|
|
646
645
|
]);
|
|
647
646
|
|
|
648
647
|
const doc = await this._doc;
|
|
649
|
-
const eventContext: EventResolverContext<TPlatform, TAuthorize, TContext> = {
|
|
648
|
+
const eventContext: EventResolverContext<EventResolverKind, TPlatform, TAuthorize, TContext> = {
|
|
650
649
|
context: this._context,
|
|
651
650
|
doc,
|
|
652
651
|
room: this.id,
|
|
@@ -831,7 +830,7 @@ export class IORoom<
|
|
|
831
830
|
if (!sender) return;
|
|
832
831
|
|
|
833
832
|
const doc = await this._doc;
|
|
834
|
-
const context: EventResolverContext<TPlatform, TAuthorize, TContext> = {
|
|
833
|
+
const context: EventResolverContext<"sync", TPlatform, TAuthorize, TContext> = {
|
|
835
834
|
context: this._context,
|
|
836
835
|
doc,
|
|
837
836
|
room: this.id,
|
package/src/PluvProcedure.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EventRecord, IOAuthorize, InputZodLike, JsonObject, ProcedureLike } from "@pluv/types";
|
|
2
2
|
import type { AbstractPlatform, InferInitContextType } from "./AbstractPlatform";
|
|
3
|
-
import type { EventResolver, MergeEventRecords } from "./types";
|
|
3
|
+
import type { EventResolver, EventResolverKind, MergeEventRecords } from "./types";
|
|
4
4
|
|
|
5
5
|
export interface PluvProcedureConfig<
|
|
6
6
|
TPlatform extends AbstractPlatform<any>,
|
|
@@ -9,10 +9,10 @@ export interface PluvProcedureConfig<
|
|
|
9
9
|
TInput extends JsonObject = {},
|
|
10
10
|
TOutput extends EventRecord<string, any> = {},
|
|
11
11
|
> {
|
|
12
|
-
broadcast?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
12
|
+
broadcast?: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
13
13
|
input?: InputZodLike<TInput>;
|
|
14
|
-
self?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
15
|
-
sync?: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
14
|
+
self?: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
15
|
+
sync?: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class PluvProcedure<
|
|
@@ -23,10 +23,11 @@ export class PluvProcedure<
|
|
|
23
23
|
TOutput extends EventRecord<string, any> = {},
|
|
24
24
|
TFilled extends "input" | "broadcast" | "self" | "sync" | "" = "",
|
|
25
25
|
> {
|
|
26
|
-
private _broadcast: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null =
|
|
26
|
+
private _broadcast: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null =
|
|
27
|
+
null;
|
|
27
28
|
private _input: InputZodLike<TInput> | null = null;
|
|
28
|
-
private _self: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
29
|
-
private _sync: EventResolver<TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
29
|
+
private _self: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
30
|
+
private _sync: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, Partial<TOutput>> | null = null;
|
|
30
31
|
|
|
31
32
|
public get config(): ProcedureLike<TInput, TOutput>["config"] {
|
|
32
33
|
return {
|
|
@@ -48,7 +49,7 @@ export class PluvProcedure<
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
public broadcast<TResult extends EventRecord<string, any> = {}>(
|
|
51
|
-
resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
52
|
+
resolver: EventResolver<"broadcast", TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
52
53
|
): Omit<
|
|
53
54
|
PluvProcedure<
|
|
54
55
|
TPlatform,
|
|
@@ -84,7 +85,7 @@ export class PluvProcedure<
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
public self<TResult extends EventRecord<string, any> = {}>(
|
|
87
|
-
resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
88
|
+
resolver: EventResolver<"self", TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
88
89
|
): Omit<
|
|
89
90
|
PluvProcedure<
|
|
90
91
|
TPlatform,
|
|
@@ -114,7 +115,7 @@ export class PluvProcedure<
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
public sync<TResult extends EventRecord<string, any> = {}>(
|
|
117
|
-
resolver: EventResolver<TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
118
|
+
resolver: EventResolver<"sync", TPlatform, TAuthorize, TContext, TInput, TResult>,
|
|
118
119
|
): Omit<
|
|
119
120
|
PluvProcedure<
|
|
120
121
|
TPlatform,
|
|
@@ -143,7 +144,7 @@ export class PluvProcedure<
|
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
private _resolver(): EventResolver<TPlatform, TAuthorize, TContext, TInput, TOutput> {
|
|
147
|
+
private _resolver(): EventResolver<EventResolverKind, TPlatform, TAuthorize, TContext, TInput, TOutput> {
|
|
147
148
|
return (data, context) => {
|
|
148
149
|
return {
|
|
149
150
|
...this._broadcast?.(data, context),
|
package/src/types.ts
CHANGED
|
@@ -40,15 +40,22 @@ export interface CrdtLibraryType {
|
|
|
40
40
|
kind: "loro" | "yjs";
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
export type EventResolverKind = "broadcast" | "self" | "sync";
|
|
44
|
+
|
|
43
45
|
export type EventResolver<
|
|
46
|
+
TKind extends EventResolverKind = EventResolverKind,
|
|
44
47
|
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
45
48
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
46
49
|
TContext extends Record<string, any> = {},
|
|
47
50
|
TInput extends JsonObject = {},
|
|
48
51
|
TOutput extends EventRecord<string, any> = {},
|
|
49
|
-
> = (
|
|
52
|
+
> = (
|
|
53
|
+
data: TInput,
|
|
54
|
+
context: EventResolverContext<TKind, TPlatform, TAuthorize, TContext>,
|
|
55
|
+
) => MaybePromise<TOutput | void>;
|
|
50
56
|
|
|
51
57
|
export interface EventResolverContext<
|
|
58
|
+
TKind extends EventResolverKind = EventResolverKind,
|
|
52
59
|
TPlatform extends AbstractPlatform = AbstractPlatform,
|
|
53
60
|
TAuthorize extends IOAuthorize<any, any, InferInitContextType<TPlatform>> = BaseIOAuthorize,
|
|
54
61
|
TContext extends Record<string, any> = {},
|
|
@@ -56,19 +63,7 @@ export interface EventResolverContext<
|
|
|
56
63
|
context: TContext;
|
|
57
64
|
doc: AbstractCrdtDoc<any>;
|
|
58
65
|
room: string;
|
|
59
|
-
|
|
60
|
-
* !HACK
|
|
61
|
-
* @description Session should only not exist when invoking the event as a
|
|
62
|
-
* "sync" event on another machine where the session doesn't exist. There must
|
|
63
|
-
* be a better way to handle this, but going to make this nullable for ease
|
|
64
|
-
* for now.
|
|
65
|
-
*
|
|
66
|
-
* `session` should not be referenced most of the time anyhow (outside of
|
|
67
|
-
* internal to this library).
|
|
68
|
-
* @author leedavidcs
|
|
69
|
-
* @date December 25, 2022
|
|
70
|
-
*/
|
|
71
|
-
session: WebSocketSession<TAuthorize> | null;
|
|
66
|
+
session: TKind extends "sync" ? WebSocketSession<TAuthorize> | null : WebSocketSession<TAuthorize>;
|
|
72
67
|
sessions: readonly WebSocketSession<TAuthorize>[];
|
|
73
68
|
}
|
|
74
69
|
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.34.
|
|
2
|
+
export const version = '0.34.1'
|