@irpclib/irpc 1.0.0-beta.19 → 1.0.0-beta.20
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/dist/call.d.ts +21 -3
- package/dist/call.js +25 -0
- package/dist/enum.d.ts +34 -0
- package/dist/enum.js +35 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/module.js +13 -9
- package/dist/state.d.ts +19 -0
- package/dist/state.js +41 -0
- package/dist/transport.js +11 -3
- package/dist/types.d.ts +43 -17
- package/package.json +7 -4
package/dist/call.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRPCPayload } from "./types.js";
|
|
1
|
+
import { IRPCPayload, IRPCStatus } from "./types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/call.d.ts
|
|
4
4
|
|
|
@@ -8,23 +8,41 @@ import { IRPCPayload } from "./types.js";
|
|
|
8
8
|
*/
|
|
9
9
|
declare class IRPCCall {
|
|
10
10
|
payload: IRPCPayload;
|
|
11
|
-
resolver
|
|
12
|
-
rejector
|
|
11
|
+
private resolver;
|
|
12
|
+
private rejector;
|
|
13
13
|
timeout?: number | undefined;
|
|
14
14
|
/**
|
|
15
15
|
* Unique identifier for this RPC call, generated using shortId().
|
|
16
16
|
*/
|
|
17
17
|
id: string;
|
|
18
|
+
/**
|
|
19
|
+
* The status of the RPC call, indicating whether it is pending, resolved, or rejected.
|
|
20
|
+
*/
|
|
21
|
+
status: IRPCStatus;
|
|
18
22
|
/**
|
|
19
23
|
* Flag indicating whether this call has been resolved or rejected.
|
|
20
24
|
* Prevents multiple resolutions of the same call.
|
|
21
25
|
*/
|
|
22
26
|
resolved: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The timestamp when the RPC call was started.
|
|
29
|
+
*/
|
|
30
|
+
startedAt: number;
|
|
31
|
+
/**
|
|
32
|
+
* The timestamp when the RPC call was finished.
|
|
33
|
+
*/
|
|
34
|
+
finishedAt?: number;
|
|
35
|
+
/**
|
|
36
|
+
* The value returned by the RPC call.
|
|
37
|
+
*/
|
|
38
|
+
value?: unknown;
|
|
39
|
+
error?: Error;
|
|
23
40
|
/**
|
|
24
41
|
* Creates a new IRPCCall instance.
|
|
25
42
|
* @param payload - The RPC payload containing method and parameters
|
|
26
43
|
* @param resolver - Function to resolve the associated promise with a value
|
|
27
44
|
* @param rejector - Function to reject the associated promise with an error
|
|
45
|
+
* @param timeout - Optional timeout value in milliseconds
|
|
28
46
|
*/
|
|
29
47
|
constructor(payload: IRPCPayload, resolver: (value: unknown) => void, rejector: (reason?: Error) => void, timeout?: number | undefined);
|
|
30
48
|
/**
|
package/dist/call.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRPC_STATUS } from "./enum.js";
|
|
1
2
|
import { uuid } from "./uuid.js";
|
|
2
3
|
|
|
3
4
|
//#region src/call.ts
|
|
@@ -11,15 +12,33 @@ var IRPCCall = class {
|
|
|
11
12
|
*/
|
|
12
13
|
id = uuid();
|
|
13
14
|
/**
|
|
15
|
+
* The status of the RPC call, indicating whether it is pending, resolved, or rejected.
|
|
16
|
+
*/
|
|
17
|
+
status = IRPC_STATUS.PENDING;
|
|
18
|
+
/**
|
|
14
19
|
* Flag indicating whether this call has been resolved or rejected.
|
|
15
20
|
* Prevents multiple resolutions of the same call.
|
|
16
21
|
*/
|
|
17
22
|
resolved = false;
|
|
18
23
|
/**
|
|
24
|
+
* The timestamp when the RPC call was started.
|
|
25
|
+
*/
|
|
26
|
+
startedAt = Date.now();
|
|
27
|
+
/**
|
|
28
|
+
* The timestamp when the RPC call was finished.
|
|
29
|
+
*/
|
|
30
|
+
finishedAt;
|
|
31
|
+
/**
|
|
32
|
+
* The value returned by the RPC call.
|
|
33
|
+
*/
|
|
34
|
+
value;
|
|
35
|
+
error;
|
|
36
|
+
/**
|
|
19
37
|
* Creates a new IRPCCall instance.
|
|
20
38
|
* @param payload - The RPC payload containing method and parameters
|
|
21
39
|
* @param resolver - Function to resolve the associated promise with a value
|
|
22
40
|
* @param rejector - Function to reject the associated promise with an error
|
|
41
|
+
* @param timeout - Optional timeout value in milliseconds
|
|
23
42
|
*/
|
|
24
43
|
constructor(payload, resolver, rejector, timeout) {
|
|
25
44
|
this.payload = payload;
|
|
@@ -34,7 +53,10 @@ var IRPCCall = class {
|
|
|
34
53
|
*/
|
|
35
54
|
resolve(value) {
|
|
36
55
|
if (this.resolved) return;
|
|
56
|
+
this.value = value;
|
|
57
|
+
this.status = IRPC_STATUS.SUCCESS;
|
|
37
58
|
this.resolved = true;
|
|
59
|
+
this.finishedAt = Date.now();
|
|
38
60
|
this.resolver(value);
|
|
39
61
|
}
|
|
40
62
|
/**
|
|
@@ -44,7 +66,10 @@ var IRPCCall = class {
|
|
|
44
66
|
*/
|
|
45
67
|
reject(reason) {
|
|
46
68
|
if (this.resolved) return;
|
|
69
|
+
this.error = reason;
|
|
70
|
+
this.status = IRPC_STATUS.ERROR;
|
|
47
71
|
this.resolved = true;
|
|
72
|
+
this.finishedAt = Date.now();
|
|
48
73
|
this.rejector(reason);
|
|
49
74
|
}
|
|
50
75
|
};
|
package/dist/enum.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/enum.d.ts
|
|
2
|
+
declare const IRPC_PACKET_TYPE: {
|
|
3
|
+
readonly CALL: "call";
|
|
4
|
+
readonly EVENT: "event";
|
|
5
|
+
readonly ANSWER: "answer";
|
|
6
|
+
readonly REQUEST: "request";
|
|
7
|
+
readonly RESPONSE: "response";
|
|
8
|
+
};
|
|
9
|
+
declare const IRPC_DATA_TYPE: {
|
|
10
|
+
readonly ARRAY: "array";
|
|
11
|
+
readonly OBJECT: "object";
|
|
12
|
+
readonly READABLE: "readable";
|
|
13
|
+
readonly WRITABLE: "writable";
|
|
14
|
+
readonly PRIMITIVE: "primitive";
|
|
15
|
+
};
|
|
16
|
+
declare const IRPC_EVENT_TYPE: {
|
|
17
|
+
readonly OBJECT_SET: "set";
|
|
18
|
+
readonly OBJECT_DELETE: "delete";
|
|
19
|
+
readonly ARRAY_PUSH: "push";
|
|
20
|
+
readonly ARRAY_POP: "pop";
|
|
21
|
+
readonly ARRAY_SHIFT: "shift";
|
|
22
|
+
readonly ARRAY_UNSHIFT: "unshift";
|
|
23
|
+
readonly ARRAY_SPLICE: "splice";
|
|
24
|
+
readonly ARRAY_REVERSE: "reverse";
|
|
25
|
+
readonly ARRAY_COPY_WITHIN: "copyWithin";
|
|
26
|
+
};
|
|
27
|
+
declare const IRPC_STATUS: {
|
|
28
|
+
readonly IDLE: "idle";
|
|
29
|
+
readonly ERROR: "error";
|
|
30
|
+
readonly PENDING: "pending";
|
|
31
|
+
readonly SUCCESS: "success";
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS };
|
package/dist/enum.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/enum.ts
|
|
2
|
+
const IRPC_PACKET_TYPE = {
|
|
3
|
+
CALL: "call",
|
|
4
|
+
EVENT: "event",
|
|
5
|
+
ANSWER: "answer",
|
|
6
|
+
REQUEST: "request",
|
|
7
|
+
RESPONSE: "response"
|
|
8
|
+
};
|
|
9
|
+
const IRPC_DATA_TYPE = {
|
|
10
|
+
ARRAY: "array",
|
|
11
|
+
OBJECT: "object",
|
|
12
|
+
READABLE: "readable",
|
|
13
|
+
WRITABLE: "writable",
|
|
14
|
+
PRIMITIVE: "primitive"
|
|
15
|
+
};
|
|
16
|
+
const IRPC_EVENT_TYPE = {
|
|
17
|
+
OBJECT_SET: "set",
|
|
18
|
+
OBJECT_DELETE: "delete",
|
|
19
|
+
ARRAY_PUSH: "push",
|
|
20
|
+
ARRAY_POP: "pop",
|
|
21
|
+
ARRAY_SHIFT: "shift",
|
|
22
|
+
ARRAY_UNSHIFT: "unshift",
|
|
23
|
+
ARRAY_SPLICE: "splice",
|
|
24
|
+
ARRAY_REVERSE: "reverse",
|
|
25
|
+
ARRAY_COPY_WITHIN: "copyWithin"
|
|
26
|
+
};
|
|
27
|
+
const IRPC_STATUS = {
|
|
28
|
+
IDLE: "idle",
|
|
29
|
+
ERROR: "error",
|
|
30
|
+
PENDING: "pending",
|
|
31
|
+
SUCCESS: "success"
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IRPCCacheEntry, IRPCCacher } from "./cache.js";
|
|
2
|
+
import { IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
|
|
2
3
|
import { ERROR_CODE, ERROR_MESSAGE, ErrorCode } from "./error.js";
|
|
3
4
|
import { IRPCTransport } from "./transport.js";
|
|
4
|
-
import { IRPCArraySchema, IRPCCache,
|
|
5
|
+
import { IRPCArraySchema, IRPCCache, IRPCContext, IRPCContextProvider, IRPCData, IRPCDataSchema, IRPCDataType, IRPCError, IRPCEventType, IRPCHandler, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacket, IRPCPacketAnswer, IRPCPacketCall, IRPCPacketData, IRPCPacketEvent, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStubStore, TransportConfig } from "./types.js";
|
|
5
6
|
import { IRPCCall } from "./call.js";
|
|
6
7
|
import { createContext, getContext, setContext, setContextProvider, withContext } from "./context.js";
|
|
7
8
|
import { IRPCPackage, createPackage } from "./module.js";
|
|
8
9
|
import { IRPCResolver } from "./resolver.js";
|
|
9
|
-
export { ERROR_CODE, ERROR_MESSAGE, ErrorCode, IRPCArraySchema, IRPCCache, IRPCCacheEntry, IRPCCacher,
|
|
10
|
+
export { ERROR_CODE, ERROR_MESSAGE, ErrorCode, IRPCArraySchema, IRPCCache, IRPCCacheEntry, IRPCCacher, IRPCCall, IRPCContext, IRPCContextProvider, IRPCData, IRPCDataSchema, IRPCDataType, IRPCError, IRPCEventType, IRPCHandler, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackage, IRPCPackageConfig, IRPCPackageInfo, IRPCPacket, IRPCPacketAnswer, IRPCPacketCall, IRPCPacketData, IRPCPacketEvent, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCResolver, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStubStore, IRPCTransport, IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS, TransportConfig, createContext, createPackage, getContext, setContext, setContextProvider, withContext };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IRPCCacher } from "./cache.js";
|
|
2
|
+
import { IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
|
|
2
3
|
import { IRPCCall } from "./call.js";
|
|
3
4
|
import { createContext, getContext, setContext, setContextProvider, withContext } from "./context.js";
|
|
4
5
|
import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
|
|
@@ -6,4 +7,4 @@ import { IRPCTransport } from "./transport.js";
|
|
|
6
7
|
import { IRPCPackage, createPackage } from "./module.js";
|
|
7
8
|
import { IRPCResolver } from "./resolver.js";
|
|
8
9
|
|
|
9
|
-
export { ERROR_CODE, ERROR_MESSAGE, IRPCCacher, IRPCCall, IRPCPackage, IRPCResolver, IRPCTransport, createContext, createPackage, getContext, setContext, setContextProvider, withContext };
|
|
10
|
+
export { ERROR_CODE, ERROR_MESSAGE, IRPCCacher, IRPCCall, IRPCPackage, IRPCResolver, IRPCTransport, IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS, createContext, createPackage, getContext, setContext, setContextProvider, withContext };
|
package/dist/module.js
CHANGED
|
@@ -72,20 +72,24 @@ var IRPCPackage = class {
|
|
|
72
72
|
declare(init) {
|
|
73
73
|
if (this.specs.has(init.name)) throw new Error(`IRPC ${init.name} already exists.`);
|
|
74
74
|
const spec = { ...init };
|
|
75
|
+
const calls = /* @__PURE__ */ new Map();
|
|
75
76
|
const caches = new IRPCCacher();
|
|
76
77
|
const timeout = spec.timeout ?? this.config.timeout;
|
|
77
78
|
const stub = (async (...args) => {
|
|
78
|
-
if (typeof spec.handler
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
if (!this.transport && typeof spec.handler !== "function") throw new Error(ERROR_MESSAGE[ERROR_CODE.TRANSPORT_MISSING]);
|
|
80
|
+
const callKey = JSON.stringify(args);
|
|
81
|
+
const cached = caches.get(callKey);
|
|
82
|
+
if (cached) return cached.value;
|
|
83
|
+
if (spec.coalesce !== false && calls.has(callKey)) return calls.get(callKey);
|
|
84
|
+
const call = typeof spec.handler === "function" ? spec.handler(...args) : this.transport.call(spec, args, timeout);
|
|
85
|
+
calls.set(callKey, call);
|
|
86
|
+
try {
|
|
87
|
+
const data = await call;
|
|
88
|
+
if (spec.maxAge) caches.set(callKey, data, spec.maxAge);
|
|
86
89
|
return data;
|
|
90
|
+
} finally {
|
|
91
|
+
calls.delete(callKey);
|
|
87
92
|
}
|
|
88
|
-
return await this.transport.call(spec, args, timeout);
|
|
89
93
|
});
|
|
90
94
|
this.specs.set(init.name, spec);
|
|
91
95
|
this.stubs.set(stub, spec);
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IRPCReadable, IRPCStatus } from "./types.js";
|
|
2
|
+
import * as _anchorlib_core0 from "@anchorlib/core";
|
|
3
|
+
import { StateSubscriber } from "@anchorlib/core";
|
|
4
|
+
|
|
5
|
+
//#region src/state.d.ts
|
|
6
|
+
declare class RemoteState<T> {
|
|
7
|
+
#private;
|
|
8
|
+
get data(): T;
|
|
9
|
+
set data(data: T);
|
|
10
|
+
get error(): Error | undefined;
|
|
11
|
+
set error(error: Error | undefined);
|
|
12
|
+
get status(): IRPCStatus;
|
|
13
|
+
set status(status: IRPCStatus);
|
|
14
|
+
constructor(init: T);
|
|
15
|
+
subscribe(handler: StateSubscriber<IRPCReadable<T>>): _anchorlib_core0.StateUnsubscribe;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { RemoteState };
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IRPC_STATUS } from "./enum.js";
|
|
2
|
+
import { anchor, mutable, subscribe } from "@anchorlib/core";
|
|
3
|
+
|
|
4
|
+
//#region src/state.ts
|
|
5
|
+
var RemoteState = class {
|
|
6
|
+
#state;
|
|
7
|
+
get data() {
|
|
8
|
+
return this.#state.data;
|
|
9
|
+
}
|
|
10
|
+
set data(data) {
|
|
11
|
+
this.#state.data = data;
|
|
12
|
+
}
|
|
13
|
+
get error() {
|
|
14
|
+
return this.#state.error;
|
|
15
|
+
}
|
|
16
|
+
set error(error) {
|
|
17
|
+
this.#state.error = error;
|
|
18
|
+
}
|
|
19
|
+
get status() {
|
|
20
|
+
return this.#state.status;
|
|
21
|
+
}
|
|
22
|
+
set status(status) {
|
|
23
|
+
this.#state.status = status;
|
|
24
|
+
}
|
|
25
|
+
constructor(init) {
|
|
26
|
+
this.#state = mutable({
|
|
27
|
+
data: mutable(init),
|
|
28
|
+
error: void 0,
|
|
29
|
+
status: IRPC_STATUS.IDLE
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
subscribe(handler) {
|
|
33
|
+
return subscribe(this.#state, handler);
|
|
34
|
+
}
|
|
35
|
+
destroy() {
|
|
36
|
+
anchor.destroy(this.#state);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { RemoteState };
|
package/dist/transport.js
CHANGED
|
@@ -50,10 +50,18 @@ var IRPCTransport = class {
|
|
|
50
50
|
* @param call - The RPC call to schedule.
|
|
51
51
|
*/
|
|
52
52
|
schedule(call) {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const { debounce } = this.config ?? {};
|
|
54
|
+
if (debounce === false) {
|
|
55
|
+
this.dispatch([call]).finally(() => {});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const timeout = typeof debounce === "number" && !Number.isNaN(debounce) ? debounce : 0;
|
|
59
|
+
const dispatch = () => {
|
|
60
|
+
this.dispatch(Array.from(this.queue)).finally(() => {});
|
|
55
61
|
this.queue.clear();
|
|
56
|
-
}
|
|
62
|
+
};
|
|
63
|
+
if (!this.queue.size) if (timeout === 0) queueMicrotask(dispatch);
|
|
64
|
+
else setTimeout(dispatch, timeout);
|
|
57
65
|
this.queue.add(call);
|
|
58
66
|
}
|
|
59
67
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRPC_DATA_TYPE, IRPC_EVENT_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
|
|
1
2
|
import { ErrorCode } from "./error.js";
|
|
2
3
|
import { IRPCTransport } from "./transport.js";
|
|
3
4
|
import { ZodArray, ZodBoolean, ZodNull, ZodNumber, ZodObject, ZodSafeParseResult, ZodString, ZodUndefined } from "zod/v4";
|
|
@@ -14,6 +15,37 @@ type IRPCStubStore = WeakMap<IRPCHandler, IRPCSpec<IRPCInputs, IRPCOutput>>;
|
|
|
14
15
|
* Used to keep track of available RPC hosts by their names.
|
|
15
16
|
*/
|
|
16
17
|
type IRPCSpecStore = Map<string, IRPCSpec<IRPCInputs, IRPCOutput>>;
|
|
18
|
+
type IRPCStatus = (typeof IRPC_STATUS)[keyof typeof IRPC_STATUS];
|
|
19
|
+
type IRPCDataType = (typeof IRPC_DATA_TYPE)[keyof typeof IRPC_DATA_TYPE];
|
|
20
|
+
type IRPCPacketType = (typeof IRPC_PACKET_TYPE)[keyof typeof IRPC_PACKET_TYPE];
|
|
21
|
+
type IRPCEventType = (typeof IRPC_EVENT_TYPE)[keyof typeof IRPC_EVENT_TYPE];
|
|
22
|
+
type IRPCPacket = {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
type: IRPCPacketType;
|
|
26
|
+
dispatchAt?: number;
|
|
27
|
+
receivedAt?: number;
|
|
28
|
+
};
|
|
29
|
+
type IRPCPacketData = {
|
|
30
|
+
type: IRPCDataType;
|
|
31
|
+
value: IRPCData;
|
|
32
|
+
};
|
|
33
|
+
type IRPCPacketCall = IRPCPacket & {
|
|
34
|
+
args: IRPCData[];
|
|
35
|
+
};
|
|
36
|
+
type IRPCPacketAnswer = IRPCPacket & {
|
|
37
|
+
data?: IRPCPacketData;
|
|
38
|
+
error?: IRPCError;
|
|
39
|
+
};
|
|
40
|
+
type IRPCPacketEvent = IRPCPacket & {
|
|
41
|
+
data: IRPCPacketData;
|
|
42
|
+
event: IRPCEventType;
|
|
43
|
+
};
|
|
44
|
+
interface IRPCReadable<T> {
|
|
45
|
+
data: T;
|
|
46
|
+
error: Error | undefined;
|
|
47
|
+
status: IRPCStatus;
|
|
48
|
+
}
|
|
17
49
|
/**
|
|
18
50
|
* Represents primitive data types that can be used in IRPC communications.
|
|
19
51
|
* Includes string, number, boolean, null, and undefined.
|
|
@@ -74,15 +106,6 @@ type IRPCPackageConfig = IRPCPackageInfo & {
|
|
|
74
106
|
timeout?: number;
|
|
75
107
|
transport?: IRPCTransport;
|
|
76
108
|
};
|
|
77
|
-
/**
|
|
78
|
-
* Defines an RPC module which extends a namespace with execution capabilities.
|
|
79
|
-
*/
|
|
80
|
-
type IRPCModule = IRPCPackageInfo & {
|
|
81
|
-
/** Optional timeout for RPC calls */
|
|
82
|
-
timeout?: number;
|
|
83
|
-
/** Optional transport mechanism for RPC communications */
|
|
84
|
-
transport?: IRPCTransport;
|
|
85
|
-
};
|
|
86
109
|
/**
|
|
87
110
|
* Represents the payload of an RPC call with its name and arguments.
|
|
88
111
|
*/
|
|
@@ -116,14 +139,21 @@ type IRPCHandler = Function;
|
|
|
116
139
|
type IRPCInit<I extends IRPCInputs, O extends IRPCOutput> = {
|
|
117
140
|
/** The name of the RPC function */
|
|
118
141
|
name: string;
|
|
119
|
-
/** Optional schema for input/output validation */
|
|
120
|
-
schema?: IRPCSchema<I, O>;
|
|
121
142
|
/** Optional description of the RPC function */
|
|
122
143
|
description?: string;
|
|
144
|
+
/** Optional schema for input/output validation */
|
|
145
|
+
schema?: IRPCSchema<I, O>;
|
|
123
146
|
/** Optional maximum age of a call in milliseconds */
|
|
124
147
|
maxAge?: number;
|
|
125
148
|
/** Optional timeout for RPC calls */
|
|
126
149
|
timeout?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Whether to coalesce multiple calls to the same RPC function within a short time period.
|
|
152
|
+
* If true, multiple calls with the same parameters will be combined into a single call,
|
|
153
|
+
* with subsequent calls waiting for the result of the first call.
|
|
154
|
+
* This can help reduce the number of actual function executions.
|
|
155
|
+
*/
|
|
156
|
+
coalesce?: boolean;
|
|
127
157
|
};
|
|
128
158
|
/**
|
|
129
159
|
* Complete specification for an RPC function including its implementation.
|
|
@@ -169,10 +199,6 @@ type IRPCCache = {
|
|
|
169
199
|
expiresAt: number;
|
|
170
200
|
timestamp: number;
|
|
171
201
|
};
|
|
172
|
-
/**
|
|
173
|
-
* Represents a cache for RPC responses.
|
|
174
|
-
*/
|
|
175
|
-
type IRPCCaches = Map<string, IRPCCache>;
|
|
176
202
|
/**
|
|
177
203
|
* Context storage mechanism for RPC operations.
|
|
178
204
|
*/
|
|
@@ -192,7 +218,7 @@ type IRPCContextProvider = {
|
|
|
192
218
|
};
|
|
193
219
|
type TransportConfig = {
|
|
194
220
|
timeout?: number;
|
|
195
|
-
debounce?: number;
|
|
221
|
+
debounce?: number | boolean;
|
|
196
222
|
};
|
|
197
223
|
//#endregion
|
|
198
|
-
export { IRPCArraySchema, IRPCCache,
|
|
224
|
+
export { IRPCArraySchema, IRPCCache, IRPCContext, IRPCContextProvider, IRPCData, IRPCDataSchema, IRPCDataType, IRPCError, IRPCEventType, IRPCHandler, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacket, IRPCPacketAnswer, IRPCPacketCall, IRPCPacketData, IRPCPacketEvent, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStubStore, TransportConfig };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@irpclib/irpc",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.20",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -36,13 +36,16 @@
|
|
|
36
36
|
"zod": "^4.1.5"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"dev": "tsdown --watch",
|
|
39
|
+
"dev": "rimraf dist && tsdown --watch ./src",
|
|
40
40
|
"clean": "rimraf dist",
|
|
41
|
-
"build": "tsdown && publint",
|
|
41
|
+
"build": "rimraf dist && tsdown && publint",
|
|
42
42
|
"format": "biome format --write",
|
|
43
43
|
"test": "rimraf coverage && vitest --run",
|
|
44
44
|
"test:preview": "rimraf coverage && vitest --run && vite preview --outDir coverage",
|
|
45
45
|
"prepublish": "bun run format && bun run clean && tsdown && publint"
|
|
46
46
|
},
|
|
47
|
-
"license": "MIT"
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@anchorlib/core": "1.0.0-beta.19"
|
|
50
|
+
}
|
|
48
51
|
}
|