@enkaku/server 0.6.3 → 0.7.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/lib/handlers/channel.d.ts +3 -3
- package/lib/handlers/channel.d.ts.map +1 -1
- package/lib/handlers/channel.js +3 -0
- package/lib/handlers/event.d.ts +3 -3
- package/lib/handlers/event.d.ts.map +1 -1
- package/lib/handlers/request.d.ts +3 -3
- package/lib/handlers/request.d.ts.map +1 -1
- package/lib/handlers/request.js +1 -0
- package/lib/handlers/stream.d.ts +3 -3
- package/lib/handlers/stream.d.ts.map +1 -1
- package/lib/handlers/stream.js +3 -0
- package/lib/index.d.ts +13 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +12 -1
- package/lib/server.d.ts +38 -24
- package/lib/server.d.ts.map +1 -1
- package/lib/server.js +158 -70
- package/lib/types.d.ts +30 -30
- package/lib/types.d.ts.map +1 -1
- package/lib/utils.d.ts +3 -3
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +1 -0
- package/package.json +21 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChannelPayloadOf, ClientMessage, ProtocolDefinition } from '@enkaku/protocol';
|
|
2
2
|
import { ErrorRejection } from '../rejections.js';
|
|
3
3
|
import type { HandlerContext } from '../types.js';
|
|
4
|
-
export type ChannelMessageOf<
|
|
5
|
-
export declare function handleChannel<
|
|
4
|
+
export type ChannelMessageOf<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string = keyof Protocol & string> = ClientMessage<ChannelPayloadOf<Command, Protocol[Command]>>;
|
|
5
|
+
export declare function handleChannel<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string>(ctx: HandlerContext<Protocol>, msg: ChannelMessageOf<Protocol, Command>): ErrorRejection | Promise<void>;
|
|
6
6
|
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/handlers/channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/handlers/channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,EAGV,cAAc,EAGf,MAAM,aAAa,CAAA;AAGpB,MAAM,MAAM,gBAAgB,CAC1B,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,QAAQ,GAAG,MAAM,IAC/D,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAE/D,wBAAgB,aAAa,CAC3B,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,EAEvC,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC7B,GAAG,EAAE,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,GACvC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAwChC"}
|
package/lib/handlers/channel.js
CHANGED
|
@@ -17,7 +17,9 @@ export function handleChannel(ctx, msg) {
|
|
|
17
17
|
});
|
|
18
18
|
ctx.controllers[msg.payload.rid] = controller;
|
|
19
19
|
const receiveStream = createPipe();
|
|
20
|
+
// @ts-ignore type instantiation too deep
|
|
20
21
|
consumeReader({
|
|
22
|
+
// @ts-ignore type instantiation too deep
|
|
21
23
|
onValue: async (val)=>{
|
|
22
24
|
await ctx.send({
|
|
23
25
|
typ: 'receive',
|
|
@@ -35,5 +37,6 @@ export function handleChannel(ctx, msg) {
|
|
|
35
37
|
signal: controller.signal,
|
|
36
38
|
writable: receiveStream.writable
|
|
37
39
|
};
|
|
40
|
+
// @ts-ignore context and handler types
|
|
38
41
|
return executeHandler(ctx, msg.payload, ()=>handler(handlerContext));
|
|
39
42
|
}
|
package/lib/handlers/event.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClientMessage, EventPayloadOf, ProtocolDefinition } from '@enkaku/protocol';
|
|
2
2
|
import { ErrorRejection } from '../rejections.js';
|
|
3
3
|
import type { HandlerContext } from '../types.js';
|
|
4
|
-
export type EventMessageOf<
|
|
5
|
-
export declare function handleEvent<
|
|
4
|
+
export type EventMessageOf<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string = keyof Protocol & string> = ClientMessage<EventPayloadOf<Command, Protocol[Command]>>;
|
|
5
|
+
export declare function handleEvent<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string>(ctx: HandlerContext<Protocol>, msg: EventMessageOf<Protocol, Command>): ErrorRejection | Promise<void>;
|
|
6
6
|
//# sourceMappingURL=event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/handlers/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/handlers/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAGzF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,EAAqC,cAAc,EAAE,MAAM,aAAa,CAAA;AAEpF,MAAM,MAAM,cAAc,CACxB,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,QAAQ,GAAG,MAAM,IAC/D,aAAa,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAE7D,wBAAgB,WAAW,CACzB,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,EAEvC,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC7B,GAAG,EAAE,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,GACrC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBhC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClientMessage, ProtocolDefinition, RequestPayloadOf } from '@enkaku/protocol';
|
|
2
2
|
import { ErrorRejection } from '../rejections.js';
|
|
3
3
|
import type { HandlerContext } from '../types.js';
|
|
4
|
-
export type RequestMessageOf<
|
|
5
|
-
export declare function handleRequest<
|
|
4
|
+
export type RequestMessageOf<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string = keyof Protocol & string> = ClientMessage<RequestPayloadOf<Command, Protocol[Command]>>;
|
|
5
|
+
export declare function handleRequest<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string>(ctx: HandlerContext<Protocol>, msg: RequestMessageOf<Protocol, Command>): ErrorRejection | Promise<void>;
|
|
6
6
|
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/handlers/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/handlers/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAE3F,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAA;AAGjE,MAAM,MAAM,gBAAgB,CAC1B,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,QAAQ,GAAG,MAAM,IAC/D,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAE/D,wBAAgB,aAAa,CAC3B,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,EAEvC,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC7B,GAAG,EAAE,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,GACvC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhC"}
|
package/lib/handlers/request.js
CHANGED
package/lib/handlers/stream.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClientMessage, ProtocolDefinition, StreamPayloadOf } from '@enkaku/protocol';
|
|
2
2
|
import { ErrorRejection } from '../rejections.js';
|
|
3
3
|
import type { HandlerContext } from '../types.js';
|
|
4
|
-
export type StreamMessageOf<
|
|
5
|
-
export declare function handleStream<
|
|
4
|
+
export type StreamMessageOf<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string = keyof Protocol & string> = ClientMessage<StreamPayloadOf<Command, Protocol[Command]>>;
|
|
5
|
+
export declare function handleStream<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string>(ctx: HandlerContext<Protocol>, msg: StreamMessageOf<Protocol, Command>): ErrorRejection | Promise<void>;
|
|
6
6
|
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/handlers/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/handlers/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACb,kBAAkB,EAClB,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAA8B,MAAM,aAAa,CAAA;AAG7E,MAAM,MAAM,eAAe,CACzB,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,QAAQ,GAAG,MAAM,IAC/D,aAAa,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAE9D,wBAAgB,YAAY,CAC1B,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,EAEvC,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC7B,GAAG,EAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,GACtC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAgChC"}
|
package/lib/handlers/stream.js
CHANGED
|
@@ -11,7 +11,9 @@ export function handleStream(ctx, msg) {
|
|
|
11
11
|
const controller = new AbortController();
|
|
12
12
|
ctx.controllers[msg.payload.rid] = controller;
|
|
13
13
|
const receiveStream = createPipe();
|
|
14
|
+
// @ts-ignore type instantiation too deep
|
|
14
15
|
consumeReader({
|
|
16
|
+
// @ts-ignore type instantiation too deep
|
|
15
17
|
onValue: async (val)=>{
|
|
16
18
|
await ctx.send({
|
|
17
19
|
typ: 'receive',
|
|
@@ -28,5 +30,6 @@ export function handleStream(ctx, msg) {
|
|
|
28
30
|
signal: controller.signal,
|
|
29
31
|
writable: receiveStream.writable
|
|
30
32
|
};
|
|
33
|
+
// @ts-ignore context and handler types
|
|
31
34
|
return executeHandler(ctx, msg.payload, ()=>handler(handlerContext));
|
|
32
35
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server logic for Enkaku RPC.
|
|
3
|
+
*
|
|
4
|
+
* ## Installation
|
|
5
|
+
*
|
|
6
|
+
* ```sh
|
|
7
|
+
* npm install @enkaku/server
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @module server
|
|
11
|
+
*/
|
|
1
12
|
export type { CommandAccessRecord } from './access-control.js';
|
|
2
|
-
export type
|
|
3
|
-
export { type ServeParams, type
|
|
13
|
+
export { AbortRejection, ErrorRejection, type RejectionType } from './rejections.js';
|
|
14
|
+
export { type ServeParams, Server, type ServerParams, serve } from './server.js';
|
|
4
15
|
export type { ChannelHandler, ChannelHandlerContext, CommandHandlers, EventHandler, EventHandlerContext, HandlerReturn, RequestHandler, RequestHandlerContext, StreamHandler, StreamHandlerContext, } from './types.js';
|
|
5
16
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpF,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAChF,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Server logic for Enkaku RPC.
|
|
3
|
+
*
|
|
4
|
+
* ## Installation
|
|
5
|
+
*
|
|
6
|
+
* ```sh
|
|
7
|
+
* npm install @enkaku/server
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @module server
|
|
11
|
+
*/ export { AbortRejection, ErrorRejection } from './rejections.js';
|
|
12
|
+
export { Server, serve } from './server.js';
|
package/lib/server.d.ts
CHANGED
|
@@ -1,34 +1,48 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyClientMessageOf, type ProtocolDefinition, type ServerTransportOf } from '@enkaku/protocol';
|
|
2
|
+
import { type Validator } from '@enkaku/schema';
|
|
2
3
|
import { type Disposer } from '@enkaku/util';
|
|
3
4
|
import { type CommandAccessRecord } from './access-control.js';
|
|
4
5
|
import { type RejectionType } from './rejections.js';
|
|
5
|
-
import type { CommandHandlers
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
signal: AbortSignal;
|
|
11
|
-
transport: ServerTransportOf<Definitions>;
|
|
12
|
-
} & ({
|
|
13
|
-
insecure: true;
|
|
6
|
+
import type { CommandHandlers } from './types.js';
|
|
7
|
+
export type AccessControlParams = {
|
|
8
|
+
public: true;
|
|
9
|
+
serverID?: string;
|
|
10
|
+
access?: CommandAccessRecord;
|
|
14
11
|
} | {
|
|
15
|
-
|
|
12
|
+
public: false;
|
|
16
13
|
serverID: string;
|
|
17
14
|
access: CommandAccessRecord;
|
|
18
|
-
}
|
|
19
|
-
export type
|
|
20
|
-
handlers: CommandHandlers<
|
|
15
|
+
};
|
|
16
|
+
export type HandleMessagesParams<Protocol extends ProtocolDefinition> = AccessControlParams & {
|
|
17
|
+
handlers: CommandHandlers<Protocol>;
|
|
18
|
+
reject: (rejection: RejectionType) => void;
|
|
19
|
+
signal: AbortSignal;
|
|
20
|
+
transport: ServerTransportOf<Protocol>;
|
|
21
|
+
validator?: Validator<AnyClientMessageOf<Protocol>>;
|
|
22
|
+
};
|
|
23
|
+
export type ServerParams<Protocol extends ProtocolDefinition> = {
|
|
24
|
+
access?: CommandAccessRecord;
|
|
25
|
+
handlers: CommandHandlers<Protocol>;
|
|
26
|
+
id?: string;
|
|
27
|
+
protocol?: Protocol;
|
|
28
|
+
public?: boolean;
|
|
21
29
|
signal?: AbortSignal;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
insecure?: false;
|
|
27
|
-
id: string;
|
|
30
|
+
transports?: Array<ServerTransportOf<Protocol>>;
|
|
31
|
+
};
|
|
32
|
+
export type HandleOptions = {
|
|
33
|
+
public?: boolean;
|
|
28
34
|
access?: CommandAccessRecord;
|
|
29
|
-
});
|
|
30
|
-
export type Server = Disposer & {
|
|
31
|
-
rejections: ReadableStream<RejectionType>;
|
|
32
35
|
};
|
|
33
|
-
export declare
|
|
36
|
+
export declare class Server<Protocol extends ProtocolDefinition> implements Disposer {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(params: ServerParams<Protocol>);
|
|
39
|
+
get disposed(): Promise<void>;
|
|
40
|
+
get rejections(): ReadableStream<RejectionType>;
|
|
41
|
+
dispose(): Promise<void>;
|
|
42
|
+
handle(transport: ServerTransportOf<Protocol>, options?: HandleOptions): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export type ServeParams<Protocol extends ProtocolDefinition> = Omit<ServerParams<Protocol>, 'transports'> & {
|
|
45
|
+
transport: ServerTransportOf<Protocol>;
|
|
46
|
+
};
|
|
47
|
+
export declare function serve<Protocol extends ProtocolDefinition>(params: ServeParams<Protocol>): Server<Protocol>;
|
|
34
48
|
//# sourceMappingURL=server.d.ts.map
|
package/lib/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAEvB,KAAK,kBAAkB,EAC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EAAE,WAAW,CAAA;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAA;CAChD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAE9E,qBAAa,MAAM,CAAC,QAAQ,SAAS,kBAAkB,CAAE,YAAW,QAAQ;;gBAU9D,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC;IAqD1C,IAAI,QAAQ,kBAEX;IAED,IAAI,UAAU,kCAEb;IAEK,OAAO;IAIb,MAAM,CAAC,SAAS,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B3F;AAED,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,kBAAkB,IAAI,IAAI,CACjE,YAAY,CAAC,QAAQ,CAAC,EACtB,YAAY,CACb,GAAG;IACF,SAAS,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAA;CACvC,CAAA;AAED,wBAAgB,KAAK,CAAC,QAAQ,SAAS,kBAAkB,EACvD,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,GAC5B,MAAM,CAAC,QAAQ,CAAC,CAGlB"}
|
package/lib/server.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createClientMessageSchema } from '@enkaku/protocol';
|
|
2
|
+
import { createValidator } from '@enkaku/schema';
|
|
1
3
|
import { createPipe } from '@enkaku/stream';
|
|
2
4
|
import { createUnsignedToken, isSignedToken } from '@enkaku/token';
|
|
3
5
|
import { createDisposer } from '@enkaku/util';
|
|
@@ -8,7 +10,8 @@ import { handleRequest } from './handlers/request.js';
|
|
|
8
10
|
import { handleStream } from './handlers/stream.js';
|
|
9
11
|
import { ErrorRejection } from './rejections.js';
|
|
10
12
|
async function handleMessages(params) {
|
|
11
|
-
const {
|
|
13
|
+
const { handlers, reject, signal, transport, validator } = params;
|
|
14
|
+
const controllers = Object.create(null);
|
|
12
15
|
const context = {
|
|
13
16
|
controllers,
|
|
14
17
|
handlers,
|
|
@@ -24,6 +27,18 @@ async function handleMessages(params) {
|
|
|
24
27
|
// Wait until all running handlers are done
|
|
25
28
|
await Promise.all(Object.values(running));
|
|
26
29
|
}, signal);
|
|
30
|
+
const processMessage = validator ? (message)=>{
|
|
31
|
+
const result = validator(message);
|
|
32
|
+
if (result.isError()) {
|
|
33
|
+
reject(new ErrorRejection('Invalid protocol message', {
|
|
34
|
+
cause: result.error,
|
|
35
|
+
info: {
|
|
36
|
+
message
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
return result.value;
|
|
41
|
+
} : (message)=>message;
|
|
27
42
|
function processHandler(message, handle) {
|
|
28
43
|
const returned = handle();
|
|
29
44
|
if (returned instanceof ErrorRejection) {
|
|
@@ -36,9 +51,9 @@ async function handleMessages(params) {
|
|
|
36
51
|
});
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
|
-
const process = params.
|
|
54
|
+
const process = params.public ? processHandler : async (message, handle)=>{
|
|
40
55
|
try {
|
|
41
|
-
if (!params.
|
|
56
|
+
if (!params.public) {
|
|
42
57
|
if (!isSignedToken(message)) {
|
|
43
58
|
throw new Error('Message is not signed');
|
|
44
59
|
}
|
|
@@ -69,81 +84,154 @@ async function handleMessages(params) {
|
|
|
69
84
|
await disposer.dispose();
|
|
70
85
|
return;
|
|
71
86
|
}
|
|
72
|
-
const msg = next.value;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
case 'channel':
|
|
78
|
-
{
|
|
79
|
-
const message = msg;
|
|
80
|
-
process(message, ()=>handleChannel(context, message));
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case 'event':
|
|
84
|
-
{
|
|
85
|
-
const message = msg;
|
|
86
|
-
process(message, ()=>handleEvent(context, message));
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case 'request':
|
|
90
|
-
{
|
|
91
|
-
const message = msg;
|
|
92
|
-
process(message, ()=>handleRequest(context, message));
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
case 'send':
|
|
96
|
-
{
|
|
97
|
-
const controller = controllers[msg.payload.rid];
|
|
98
|
-
controller?.writer.write(msg.payload.val);
|
|
87
|
+
const msg = processMessage(next.value);
|
|
88
|
+
if (msg != null) {
|
|
89
|
+
switch(msg.payload.typ){
|
|
90
|
+
case 'abort':
|
|
91
|
+
controllers[msg.payload.rid]?.abort();
|
|
99
92
|
break;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
case 'channel':
|
|
94
|
+
{
|
|
95
|
+
const message = msg;
|
|
96
|
+
// @ts-ignore type instantiation too deep
|
|
97
|
+
process(message, ()=>handleChannel(context, message));
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'event':
|
|
101
|
+
{
|
|
102
|
+
const message = msg;
|
|
103
|
+
process(message, ()=>handleEvent(context, message));
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'request':
|
|
107
|
+
{
|
|
108
|
+
const message = msg;
|
|
109
|
+
process(message, ()=>handleRequest(context, message));
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 'send':
|
|
113
|
+
{
|
|
114
|
+
const controller = controllers[msg.payload.rid];
|
|
115
|
+
controller?.writer.write(msg.payload.val);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'stream':
|
|
119
|
+
{
|
|
120
|
+
const message = msg;
|
|
121
|
+
process(message, ()=>handleStream(context, message));
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
107
125
|
}
|
|
108
126
|
handleNext();
|
|
109
127
|
}
|
|
110
128
|
handleNext();
|
|
111
129
|
return disposer.disposed;
|
|
112
130
|
}
|
|
113
|
-
export
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
export class Server {
|
|
132
|
+
#abortController;
|
|
133
|
+
#accessControl;
|
|
134
|
+
#disposer;
|
|
135
|
+
#handlers;
|
|
136
|
+
#handling = [];
|
|
137
|
+
#reject;
|
|
138
|
+
#rejections;
|
|
139
|
+
#validator;
|
|
140
|
+
constructor(params){
|
|
141
|
+
this.#abortController = new AbortController();
|
|
142
|
+
this.#handlers = params.handlers;
|
|
143
|
+
if (params.id == null) {
|
|
144
|
+
if (params.public) {
|
|
145
|
+
this.#accessControl = {
|
|
146
|
+
public: true,
|
|
147
|
+
access: params.access
|
|
148
|
+
};
|
|
149
|
+
} else {
|
|
150
|
+
throw new Error('Invalid server parameters: either the server "id" must be provided or the "public" parameter must be set to true');
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
this.#accessControl = {
|
|
154
|
+
public: !!params.public,
|
|
155
|
+
serverID: params.id,
|
|
156
|
+
access: params.access ?? {}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
this.#disposer = createDisposer(async ()=>{
|
|
160
|
+
// Signal messages handler to stop execution and run cleanup logic
|
|
161
|
+
this.#abortController.abort();
|
|
162
|
+
// Dispose of all handling transports
|
|
163
|
+
await Promise.all(// @ts-ignore type instantiation too deep
|
|
164
|
+
this.#handling.map(async (handling)=>{
|
|
165
|
+
// Wait until all handlers are done - they might still need to flush messages to the transport
|
|
166
|
+
await handling.done;
|
|
167
|
+
// Dispose transport
|
|
168
|
+
await handling.transport.dispose();
|
|
169
|
+
}));
|
|
170
|
+
// Cleanup rejections writer
|
|
171
|
+
await rejectionsWriter.close();
|
|
172
|
+
}, params.signal);
|
|
173
|
+
const rejections = createPipe();
|
|
174
|
+
this.#rejections = rejections.readable;
|
|
175
|
+
const rejectionsWriter = rejections.writable.getWriter();
|
|
176
|
+
this.#reject = (rejection)=>{
|
|
177
|
+
void rejectionsWriter.write(rejection);
|
|
178
|
+
};
|
|
179
|
+
if (params.protocol != null) {
|
|
180
|
+
this.#validator = createValidator(createClientMessageSchema(params.protocol));
|
|
181
|
+
}
|
|
182
|
+
for (const transport of params.transports ?? []){
|
|
183
|
+
this.handle(transport);
|
|
184
|
+
}
|
|
120
185
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
186
|
+
get disposed() {
|
|
187
|
+
return this.#disposer.disposed;
|
|
188
|
+
}
|
|
189
|
+
get rejections() {
|
|
190
|
+
return this.#rejections;
|
|
191
|
+
}
|
|
192
|
+
async dispose() {
|
|
193
|
+
return await this.#disposer.dispose();
|
|
194
|
+
}
|
|
195
|
+
handle(transport, options = {}) {
|
|
196
|
+
const publicAccess = options.public ?? this.#accessControl.public;
|
|
197
|
+
let accessControl;
|
|
198
|
+
if (publicAccess) {
|
|
199
|
+
accessControl = {
|
|
200
|
+
public: true,
|
|
201
|
+
access: {}
|
|
202
|
+
};
|
|
203
|
+
} else {
|
|
204
|
+
const serverID = this.#accessControl.serverID;
|
|
205
|
+
if (serverID == null) {
|
|
206
|
+
return Promise.reject(new Error('Server ID is required to enable access control'));
|
|
207
|
+
}
|
|
208
|
+
accessControl = {
|
|
209
|
+
public: false,
|
|
210
|
+
serverID,
|
|
211
|
+
access: options.access ?? this.#accessControl.access ?? {}
|
|
212
|
+
};
|
|
133
213
|
}
|
|
214
|
+
const done = handleMessages({
|
|
215
|
+
handlers: this.#handlers,
|
|
216
|
+
reject: this.#reject,
|
|
217
|
+
signal: this.#abortController.signal,
|
|
218
|
+
transport,
|
|
219
|
+
validator: this.#validator,
|
|
220
|
+
...accessControl
|
|
221
|
+
});
|
|
222
|
+
this.#handling.push({
|
|
223
|
+
done,
|
|
224
|
+
transport
|
|
225
|
+
});
|
|
226
|
+
return done;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
export function serve(params) {
|
|
230
|
+
const { transport, ...rest } = params;
|
|
231
|
+
return new Server({
|
|
232
|
+
...rest,
|
|
233
|
+
transports: [
|
|
234
|
+
transport
|
|
235
|
+
]
|
|
134
236
|
});
|
|
135
|
-
const disposer = createDisposer(async ()=>{
|
|
136
|
-
// Signal messages handler to stop execution and run cleanup logic
|
|
137
|
-
abortController.abort();
|
|
138
|
-
// Wait until all handlers are done - they might still need to flush messages to the transport
|
|
139
|
-
await handlersDone;
|
|
140
|
-
// Dispose transport
|
|
141
|
-
await params.transport.dispose();
|
|
142
|
-
// Cleanup rejections writer
|
|
143
|
-
await rejectionsWriter.close();
|
|
144
|
-
}, params.signal);
|
|
145
|
-
return {
|
|
146
|
-
...disposer,
|
|
147
|
-
rejections: rejections.readable
|
|
148
|
-
};
|
|
149
237
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyRequestCommandDefinition, AnyServerPayloadOf, ChannelCommandDefinition, DataOf, EventCallPayload, EventCommandDefinition, Message, ProtocolDefinition, RequestCallPayload, RequestCommandDefinition, StreamCommandDefinition } from '@enkaku/protocol';
|
|
2
2
|
import type { RejectionType } from './rejections.js';
|
|
3
3
|
export type RequestController = AbortController;
|
|
4
4
|
export type ChannelController<Send = unknown> = AbortController & {
|
|
5
5
|
writer: WritableStreamDefaultWriter<Send>;
|
|
6
6
|
};
|
|
7
7
|
export type HandlerController<Send = unknown> = RequestController | ChannelController<Send>;
|
|
8
|
-
export type EventHandlerContext<
|
|
9
|
-
message: Message<EventCallPayload<Command,
|
|
10
|
-
data:
|
|
11
|
-
};
|
|
12
|
-
export type EventHandler<
|
|
13
|
-
export type RequestHandlerContext<
|
|
14
|
-
message: Message<RequestCallPayload<
|
|
15
|
-
params:
|
|
8
|
+
export type EventHandlerContext<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends EventCommandDefinition ? {
|
|
9
|
+
message: Message<EventCallPayload<Command, DataOf<Protocol[Command]['data']>>>;
|
|
10
|
+
data: DataOf<Protocol[Command]['data']>;
|
|
11
|
+
} : never;
|
|
12
|
+
export type EventHandler<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = (context: EventHandlerContext<Protocol, Command>) => void | Promise<void>;
|
|
13
|
+
export type RequestHandlerContext<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends AnyRequestCommandDefinition ? {
|
|
14
|
+
message: Message<RequestCallPayload<Protocol[Command]['type'], Command, DataOf<Protocol[Command]['params']>>>;
|
|
15
|
+
params: DataOf<Protocol[Command]['params']>;
|
|
16
16
|
signal: AbortSignal;
|
|
17
|
+
} : never;
|
|
18
|
+
export type HandlerReturn<ResultSchema, Data = DataOf<ResultSchema>> = Data | Promise<Data>;
|
|
19
|
+
export type RequestHandler<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends AnyRequestCommandDefinition ? (context: RequestHandlerContext<Protocol, Command>) => HandlerReturn<Protocol[Command]['result']> : never;
|
|
20
|
+
export type StreamHandlerContext<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends StreamCommandDefinition | ChannelCommandDefinition ? RequestHandlerContext<Protocol, Command> & {
|
|
21
|
+
writable: WritableStream<DataOf<Protocol[Command]['receive']>>;
|
|
22
|
+
} : never;
|
|
23
|
+
export type StreamHandler<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends StreamCommandDefinition | ChannelCommandDefinition ? (context: StreamHandlerContext<Protocol, Command>) => HandlerReturn<Protocol[Command]['result']> : never;
|
|
24
|
+
export type ChannelHandlerContext<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends ChannelCommandDefinition ? StreamHandlerContext<Protocol, Command> & {
|
|
25
|
+
readable: ReadableStream<DataOf<Protocol[Command]['send']>>;
|
|
26
|
+
} : never;
|
|
27
|
+
export type ChannelHandler<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends ChannelCommandDefinition ? (context: ChannelHandlerContext<Protocol, Command>) => HandlerReturn<Protocol[Command]['result']> : never;
|
|
28
|
+
export type CommandHandlers<Protocol extends ProtocolDefinition> = {
|
|
29
|
+
[Command in keyof Protocol & string]: Protocol[Command] extends EventCommandDefinition ? (context: EventHandlerContext<Protocol, Command>) => void : Protocol[Command] extends RequestCommandDefinition ? (context: RequestHandlerContext<Protocol, Command>) => HandlerReturn<Protocol[Command]['result']> : Protocol[Command] extends StreamCommandDefinition ? (context: StreamHandlerContext<Protocol, Command>) => HandlerReturn<Protocol[Command]['result']> : Protocol[Command] extends ChannelCommandDefinition ? (context: ChannelHandlerContext<Protocol, Command>) => HandlerReturn<Protocol[Command]['result']> : never;
|
|
17
30
|
};
|
|
18
|
-
export type
|
|
19
|
-
export type
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export type
|
|
24
|
-
export type ChannelHandlerContext<Command extends string, Params, Sent, Receive> = StreamHandlerContext<'channel', Command, Params, Receive> & {
|
|
25
|
-
readable: ReadableStream<Sent>;
|
|
26
|
-
};
|
|
27
|
-
export type ChannelHandler<Command extends string, Params, Sent, Receive, Result> = (context: ChannelHandlerContext<Command, Params, Sent, Receive>) => HandlerReturn<Result>;
|
|
28
|
-
export type CommandHandlers<Definitions extends AnyDefinitions> = {
|
|
29
|
-
[Command in keyof Definitions & string]: Definitions[Command] extends EventDefinition<infer Data> ? (context: EventHandlerContext<Command, Data>) => void : Definitions[Command] extends RequestDefinition<infer Params, infer Result> ? (context: RequestHandlerContext<'request', Command, Params>) => HandlerReturn<Result> : Definitions[Command] extends StreamDefinition<infer Params, infer Receive, infer Result> ? (context: StreamHandlerContext<'stream', Command, Params, Receive>) => HandlerReturn<Result> : Definitions[Command] extends ChannelDefinition<infer Params, infer Send, infer Receive, infer Result> ? (context: ChannelHandlerContext<Command, Params, Send, Receive>) => HandlerReturn<Result> : never;
|
|
30
|
-
};
|
|
31
|
-
export type EventDataType<Definitions extends AnyDefinitions, Command extends keyof Definitions & string> = Definitions[Command] extends EventDefinition<infer Data> ? Data : never;
|
|
32
|
-
export type ParamsType<Definitions extends AnyDefinitions, Command extends keyof Definitions & string> = Definitions[Command] extends RequestDefinition<infer Params> ? Params : Definitions[Command] extends StreamDefinition<infer Params> ? Params : Definitions[Command] extends ChannelDefinition<infer Params> ? Params : never;
|
|
33
|
-
export type ReceiveType<Definitions extends AnyDefinitions, Command extends keyof Definitions & string> = Definitions[Command] extends StreamDefinition<infer Params, infer Receive> ? Receive : Definitions[Command] extends ChannelDefinition<infer Params, infer Send, infer Receive> ? Receive : never;
|
|
34
|
-
export type ResultType<Definitions extends AnyDefinitions, Command extends keyof Definitions & string> = Definitions[Command] extends RequestDefinition<infer Params, infer Result> ? Result : Definitions[Command] extends StreamDefinition<infer Params, infer Receive, infer Result> ? Result : Definitions[Command] extends ChannelDefinition<infer Params, infer Send, infer Receive, infer Result> ? Result : never;
|
|
35
|
-
export type SendType<Definitions extends AnyDefinitions, Command extends keyof Definitions & string> = Definitions[Command] extends ChannelDefinition<infer Params, infer Send> ? Send : never;
|
|
36
|
-
export type HandlerContext<Definitions extends AnyDefinitions> = {
|
|
31
|
+
export type EventDataType<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends EventCommandDefinition ? DataOf<Protocol[Command]['data']> : never;
|
|
32
|
+
export type ParamsType<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends AnyRequestCommandDefinition ? DataOf<Protocol[Command]['params']> : never;
|
|
33
|
+
export type ReceiveType<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends StreamCommandDefinition ? DataOf<Protocol[Command]['receive']> : Protocol[Command] extends ChannelCommandDefinition ? DataOf<Protocol[Command]['receive']> : never;
|
|
34
|
+
export type ResultType<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends AnyRequestCommandDefinition ? DataOf<Protocol[Command]['result']> : never;
|
|
35
|
+
export type SendType<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string> = Protocol[Command] extends ChannelCommandDefinition ? DataOf<Protocol[Command]['send']> : never;
|
|
36
|
+
export type HandlerContext<Protocol extends ProtocolDefinition> = {
|
|
37
37
|
controllers: Record<string, HandlerController>;
|
|
38
|
-
handlers: CommandHandlers<
|
|
38
|
+
handlers: CommandHandlers<Protocol>;
|
|
39
39
|
reject: (rejection: RejectionType) => void;
|
|
40
|
-
send: (payload: AnyServerPayloadOf<
|
|
40
|
+
send: (payload: AnyServerPayloadOf<Protocol>) => Promise<void>;
|
|
41
41
|
};
|
|
42
42
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,kBAAkB,EAClB,wBAAwB,EACxB,MAAM,EACN,gBAAgB,EAChB,sBAAsB,EACtB,OAAO,EACP,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAA;AAE/C,MAAM,MAAM,iBAAiB,CAAC,IAAI,GAAG,OAAO,IAAI,eAAe,GAAG;IAChE,MAAM,EAAE,2BAA2B,CAAC,IAAI,CAAC,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,IAAI,GAAG,OAAO,IAAI,iBAAiB,GAAG,iBAAi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AAA;IAC9C,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;IACnC,MAAM,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAA;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/D,CAAA"}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { HandlerContext,
|
|
1
|
+
import type { ProtocolDefinition, RequestPayloadOf } from '@enkaku/protocol';
|
|
2
|
+
import type { HandlerContext, ResultType } from './types.js';
|
|
3
3
|
export type ConsumeReaderParams<T> = {
|
|
4
4
|
onDone?: () => void;
|
|
5
5
|
onValue: (value: T) => Promise<void>;
|
|
@@ -7,5 +7,5 @@ export type ConsumeReaderParams<T> = {
|
|
|
7
7
|
signal: AbortSignal;
|
|
8
8
|
};
|
|
9
9
|
export declare function consumeReader<T>(params: ConsumeReaderParams<T>): Promise<void>;
|
|
10
|
-
export declare function executeHandler<
|
|
10
|
+
export declare function executeHandler<Protocol extends ProtocolDefinition, Command extends keyof Protocol & string, Result extends ResultType<Protocol, Command> = ResultType<Protocol, Command>>(context: HandlerContext<Protocol>, payload: RequestPayloadOf<Command, Protocol[Command]>, execute: () => Result | Promise<Result>): Promise<void>;
|
|
11
11
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAKhG,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;IACnC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,MAAM,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAA;IACtC,MAAM,EAAE,WAAW,CAAA;CACpB,CAAA;AAED,wBAAsB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBpF;AAGD,wBAAsB,cAAc,CAClC,QAAQ,SAAS,kBAAkB,EACnC,OAAO,SAAS,MAAM,QAAQ,GAAG,MAAM,EACvC,MAAM,SAAS,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,EAE5E,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,EACjC,OAAO,EAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,EACrD,OAAO,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GACtC,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enkaku/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"
|
|
5
|
+
"homepage": "https://enkaku.dev",
|
|
6
|
+
"description": "Server logic for Enkaku RPC",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"json",
|
|
9
|
+
"rpc",
|
|
10
|
+
"server"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/TairuFramework/enkaku",
|
|
15
|
+
"directory": "packages/server"
|
|
16
|
+
},
|
|
6
17
|
"type": "module",
|
|
7
18
|
"main": "lib/index.js",
|
|
8
19
|
"types": "lib/index.d.ts",
|
|
@@ -14,20 +25,21 @@
|
|
|
14
25
|
],
|
|
15
26
|
"sideEffects": false,
|
|
16
27
|
"dependencies": {
|
|
17
|
-
"@enkaku/capability": "^0.
|
|
18
|
-
"@enkaku/
|
|
19
|
-
"@enkaku/stream": "^0.
|
|
20
|
-
"@enkaku/
|
|
28
|
+
"@enkaku/capability": "^0.7.0",
|
|
29
|
+
"@enkaku/schema": "^0.7.0",
|
|
30
|
+
"@enkaku/stream": "^0.7.0",
|
|
31
|
+
"@enkaku/protocol": "^0.7.0",
|
|
32
|
+
"@enkaku/token": "^0.7.0",
|
|
33
|
+
"@enkaku/util": "^0.7.0"
|
|
21
34
|
},
|
|
22
35
|
"devDependencies": {
|
|
23
|
-
"@enkaku/
|
|
24
|
-
"@enkaku/transport": "^0.6.0"
|
|
36
|
+
"@enkaku/transport": "^0.7.0"
|
|
25
37
|
},
|
|
26
38
|
"scripts": {
|
|
27
39
|
"build:clean": "del lib",
|
|
28
40
|
"build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
|
|
29
41
|
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
30
|
-
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
42
|
+
"build:types:ci": "tsc --emitDeclarationOnly --skipLibCheck --declarationMap false",
|
|
31
43
|
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
32
44
|
"test:types": "tsc --noEmit --skipLibCheck",
|
|
33
45
|
"test:unit": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
|