@4players/odin-common 1.1.0 → 1.2.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/CHANGELOG.md +12 -0
- package/lib/cjs/utility/rpc.js +187 -1
- package/lib/cjs/utility/selector.js +5 -5
- package/lib/cjs/utility/strand.js +7 -7
- package/lib/esm/utility/rpc.js +184 -1
- package/lib/esm/utility/selector.js +5 -5
- package/lib/esm/utility/strand.js +7 -7
- package/lib/rpc/commands.d.ts +217 -2
- package/lib/rpc/notifications.d.ts +779 -2
- package/lib/utility/json.spec.d.ts +1 -1
- package/lib/utility/result.spec.d.ts +4 -0
- package/lib/utility/rpc.d.ts +40 -1
- package/lib/utility/rpc.spec.d.ts +7 -0
- package/lib/utility/selector.d.ts +3 -3
- package/lib/utility/selector.spec.d.ts +4 -0
- package/lib/utility/strand.d.ts +2 -2
- package/lib/utility/strand.spec.d.ts +4 -0
- package/lib/utility/url.spec.d.ts +4 -0
- package/lib/utility/validation.spec.d.ts +3 -0
- package/package.json +1 -1
- package/testy.json +0 -4
package/lib/utility/rpc.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
import { WebSocket } from 'ws';
|
|
2
3
|
import { MessagePackRpc } from '../schema/serialization';
|
|
3
|
-
import { Result } from './result';
|
|
4
|
+
import { Accept, Result } from './result';
|
|
5
|
+
import { Commands } from '../rpc/commands';
|
|
4
6
|
import { Notifications } from '../rpc/notifications';
|
|
5
7
|
export declare function msgpackEncode(value: unknown): ArrayBuffer;
|
|
6
8
|
export declare function msgpackDecode(buffer: ArrayBuffer): unknown;
|
|
@@ -8,6 +10,33 @@ export interface RpcMessage {
|
|
|
8
10
|
name: string;
|
|
9
11
|
properties: unknown;
|
|
10
12
|
}
|
|
13
|
+
export interface RpcRequest {
|
|
14
|
+
resolve: Accept<Result<unknown> | 'closed' | 'timeout'>;
|
|
15
|
+
timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare class RpcConnection {
|
|
18
|
+
readonly webSocket: WebSocket;
|
|
19
|
+
private readonly _SendQueue;
|
|
20
|
+
private readonly _RecvQueue;
|
|
21
|
+
private readonly _Requests;
|
|
22
|
+
private readonly _Close;
|
|
23
|
+
private _NextId;
|
|
24
|
+
get closed(): boolean;
|
|
25
|
+
get closeSignal(): AbortSignal;
|
|
26
|
+
constructor(webSocket: WebSocket);
|
|
27
|
+
request(name: string, properties: unknown): Promise<Result<unknown> | 'closed'>;
|
|
28
|
+
request(name: string, properties: unknown, timeout: number): Promise<Result<unknown> | 'closed' | 'timeout'>;
|
|
29
|
+
notify(name: string, properties: unknown): void;
|
|
30
|
+
recv(): Promise<RpcMessage | 'closed'>;
|
|
31
|
+
close(): void;
|
|
32
|
+
private _TimeoutRequest;
|
|
33
|
+
private _Send;
|
|
34
|
+
private _OnWebSocketOpen;
|
|
35
|
+
private _OnWebSocketMessage;
|
|
36
|
+
private _OnResponse;
|
|
37
|
+
private _OnEvent;
|
|
38
|
+
private _Cleanup;
|
|
39
|
+
}
|
|
11
40
|
export interface TypedRpcMessage<Name extends string, Properties> extends RpcMessage {
|
|
12
41
|
name: Name;
|
|
13
42
|
properties: Properties;
|
|
@@ -15,5 +44,15 @@ export interface TypedRpcMessage<Name extends string, Properties> extends RpcMes
|
|
|
15
44
|
export type RealizedEvents<E extends Notifications> = {
|
|
16
45
|
[Name in Extract<keyof E, string>]: TypedRpcMessage<Name, z.infer<E[Name]>>;
|
|
17
46
|
}[Extract<keyof E, string>];
|
|
47
|
+
export declare class TypedRpcConnection<C extends Commands, E extends Notifications> extends RpcConnection {
|
|
48
|
+
readonly _Commands: C;
|
|
49
|
+
readonly _Events: E;
|
|
50
|
+
constructor(webSocket: WebSocket, _Commands: C, _Events: E);
|
|
51
|
+
request<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>): Promise<Result<z.infer<C[Name]['response']>> | 'closed'>;
|
|
52
|
+
request<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>, timeout: number): Promise<Result<z.infer<C[Name]['response']>> | 'closed' | 'timeout'>;
|
|
53
|
+
notify<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>): void;
|
|
54
|
+
recv(): Promise<RealizedEvents<E> | 'closed'>;
|
|
55
|
+
}
|
|
18
56
|
export declare function parseRpc(buffer: ArrayBuffer): Result<MessagePackRpc>;
|
|
19
57
|
export declare function parseRpcMessage<E extends Notifications>(events: E, rpc: RpcMessage): RealizedEvents<E> | undefined;
|
|
58
|
+
export declare function isKnownRpcMessage<E extends Notifications>(events: E, name: string): name is Extract<keyof E, string>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class Selector<T extends Array<() => PromiseLike<unknown>>> {
|
|
2
|
-
private readonly
|
|
3
|
-
private readonly
|
|
4
|
-
constructor(
|
|
2
|
+
private readonly _Generators;
|
|
3
|
+
private readonly _Futures;
|
|
4
|
+
constructor(_Generators: T);
|
|
5
5
|
next(): Promise<Awaited<ReturnType<T[number]>>>;
|
|
6
6
|
static addIndex(generator: () => PromiseLike<unknown>, index: number): Promise<[unknown, number]>;
|
|
7
7
|
}
|
package/lib/utility/strand.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4players/odin-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A collection of commonly used type definitions and utility functions across ODIN web projects",
|
|
5
5
|
"author": "Josho Bleicker <josho.bleicker@4players.io> (https://www.4players.io)",
|
|
6
6
|
"homepage": "https://www.4players.io",
|
package/testy.json
DELETED