@irpclib/irpc 1.0.0-beta.24 → 1.0.0-beta.25

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 CHANGED
@@ -12,7 +12,9 @@ declare const DEFAULT_RETRY_DELAY = 1000;
12
12
  declare class IRPCCall {
13
13
  transport: IRPCTransport;
14
14
  payload: IRPCPayload;
15
- options: IRPCCallConfig;
15
+ options: IRPCCallConfig & {
16
+ seed?: () => IRPCData;
17
+ };
16
18
  /**
17
19
  * Unique identifier for this RPC call, generated using shortId().
18
20
  */
@@ -51,7 +53,9 @@ declare class IRPCCall {
51
53
  * @param payload - The RPC payload containing method and parameters
52
54
  * @param options - Options for the call, such as timeout, maxRetries, etc.
53
55
  */
54
- constructor(transport: IRPCTransport, payload: IRPCPayload, options: IRPCCallConfig, reader?: IRPCReader<IRPCData>);
56
+ constructor(transport: IRPCTransport, payload: IRPCPayload, options: IRPCCallConfig & {
57
+ seed?: () => IRPCData;
58
+ }, reader?: IRPCReader<IRPCData>);
55
59
  enqueue(packet: IRPCPacketStream<IRPCData>): void;
56
60
  /**
57
61
  * Resolves the RPC call with the provided value.
package/dist/call.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
- import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
2
+ import { CallError } from "./error.js";
3
3
  import { IRPCReader } from "./reader.js";
4
4
  import { IRPC_STORE } from "./store.js";
5
5
  import { uuid } from "@anchorlib/core";
@@ -60,16 +60,13 @@ var IRPCCall = class {
60
60
  name: this.payload.name,
61
61
  type: IRPC_PACKET_TYPE.CLOSE,
62
62
  status: IRPC_STATUS.ERROR,
63
- error: {
64
- code: ERROR_CODE.TIMEOUT,
65
- message: ERROR_MESSAGE[ERROR_CODE.TIMEOUT]
66
- },
63
+ error: CallError.timeout().json(),
67
64
  createdAt: Date.now()
68
65
  });
69
66
  clearTimeout(this.retryId);
70
- this.reject(new Error(ERROR_MESSAGE[ERROR_CODE.TIMEOUT]), false);
67
+ this.reject(CallError.timeout(), false);
71
68
  }, options.timeout);
72
- this.reader = reader ?? new IRPCReader(uuid(), options?.init?.());
69
+ this.reader = reader ?? new IRPCReader(uuid(), options?.seed?.());
73
70
  this.reader.onClose = () => this.close();
74
71
  this.id = this.reader.id;
75
72
  }
@@ -105,7 +102,7 @@ var IRPCCall = class {
105
102
  if (maxRetries && retriable) {
106
103
  if (reason) this.retryReasons.add(reason);
107
104
  if (this.retries >= maxRetries) {
108
- IRPC_STORE.error(/* @__PURE__ */ new Error(`${ERROR_MESSAGE[ERROR_CODE.CALL_MAX_RETRIES_REACHED]}: ${Array.from(this.retryReasons).map((r) => r.message).join(", ")}`), [{
105
+ IRPC_STORE.error(CallError.maxRetries(this.retryReasons), [{
109
106
  id: this.id,
110
107
  name: this.payload.name
111
108
  }]);
package/dist/enum.d.ts CHANGED
@@ -4,15 +4,6 @@ declare const IRPC_PACKET_TYPE: {
4
4
  readonly EVENT: "event";
5
5
  readonly CLOSE: "close";
6
6
  readonly ANSWER: "answer";
7
- readonly REQUEST: "request";
8
- readonly RESPONSE: "response";
9
- };
10
- declare const IRPC_DATA_TYPE: {
11
- readonly ARRAY: "array";
12
- readonly OBJECT: "object";
13
- readonly READABLE: "readable";
14
- readonly WRITABLE: "writable";
15
- readonly PRIMITIVE: "primitive";
16
7
  };
17
8
  declare const IRPC_STATUS: {
18
9
  readonly IDLE: "idle";
@@ -40,4 +31,4 @@ declare const IRPC_FILE_STATUS: {
40
31
  readonly ERROR: "error";
41
32
  };
42
33
  //#endregion
43
- export { IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT };
34
+ export { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT };
package/dist/enum.js CHANGED
@@ -3,16 +3,7 @@ const IRPC_PACKET_TYPE = {
3
3
  CALL: "call",
4
4
  EVENT: "event",
5
5
  CLOSE: "close",
6
- ANSWER: "answer",
7
- REQUEST: "request",
8
- RESPONSE: "response"
9
- };
10
- const IRPC_DATA_TYPE = {
11
- ARRAY: "array",
12
- OBJECT: "object",
13
- READABLE: "readable",
14
- WRITABLE: "writable",
15
- PRIMITIVE: "primitive"
6
+ ANSWER: "answer"
16
7
  };
17
8
  const IRPC_STATUS = {
18
9
  IDLE: "idle",
@@ -41,4 +32,4 @@ const IRPC_FILE_STATUS = {
41
32
  };
42
33
 
43
34
  //#endregion
44
- export { IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT };
35
+ export { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT };
package/dist/error.d.ts CHANGED
@@ -1,61 +1,116 @@
1
+ import { IRPCPacketError } from "./types.js";
2
+
1
3
  //#region src/error.d.ts
2
- declare const ERROR_CODE: {
3
- UNKNOWN: string;
4
- TIMEOUT: string;
5
- NOT_FOUND: string;
6
- NOT_SUPPORTED: string;
7
- INVALID_TYPE: string;
8
- INVALID_STATE: string;
9
- INVALID_VALUE: string;
10
- INVALID_INPUT: string;
11
- INVALID_OUTPUT: string;
12
- NOT_IMPLEMENTED: string;
13
- INVALID_HANDLER: string;
14
- INVALID_OPERATION: string;
15
- INVALID_HOOK: string;
16
- TRANSPORT_MISSING: string;
17
- TRANSPORT_INVALID: string;
18
- TRANSPORT_NOT_IMPLEMENTED: string;
19
- STUB_MISSING: string;
20
- STUB_INVALID: string;
21
- STUB_NOT_IMPLEMENTED: string;
22
- RESOLVER_MISSING: string;
23
- RESOLVER_NOT_IMPLEMENTED: string;
24
- RESOLVER_NOT_FOUND: string;
25
- RESOLVER_NOT_SUPPORTED: string;
26
- STREAM_ERROR: string;
27
- HANDLER_ERROR: string;
28
- RESOLVE_ERROR: string;
29
- CALL_MAX_RETRIES_REACHED: string;
4
+ declare const IRPC_ERROR_TYPE: {
5
+ readonly STUB: "stub";
6
+ readonly HOOK: "hook";
7
+ readonly CALL: "call";
8
+ readonly HANDLER: "handler";
9
+ readonly RESOLVE: "resolve";
10
+ readonly TRANSPORT: "transport";
30
11
  };
31
- type ErrorCode = (typeof ERROR_CODE)[keyof typeof ERROR_CODE];
32
- declare const ERROR_MESSAGE: {
33
- [ERROR_CODE.UNKNOWN]: string;
34
- [ERROR_CODE.TIMEOUT]: string;
35
- [ERROR_CODE.NOT_FOUND]: string;
36
- [ERROR_CODE.NOT_SUPPORTED]: string;
37
- [ERROR_CODE.INVALID_TYPE]: string;
38
- [ERROR_CODE.INVALID_STATE]: string;
39
- [ERROR_CODE.INVALID_VALUE]: string;
40
- [ERROR_CODE.INVALID_INPUT]: string;
41
- [ERROR_CODE.INVALID_OUTPUT]: string;
42
- [ERROR_CODE.NOT_IMPLEMENTED]: string;
43
- [ERROR_CODE.INVALID_HANDLER]: string;
44
- [ERROR_CODE.INVALID_OPERATION]: string;
45
- [ERROR_CODE.INVALID_HOOK]: string;
46
- [ERROR_CODE.TRANSPORT_MISSING]: string;
47
- [ERROR_CODE.TRANSPORT_INVALID]: string;
48
- [ERROR_CODE.TRANSPORT_NOT_IMPLEMENTED]: string;
49
- [ERROR_CODE.STUB_INVALID]: string;
50
- [ERROR_CODE.STREAM_ERROR]: string;
51
- [ERROR_CODE.HANDLER_ERROR]: string;
52
- [ERROR_CODE.RESOLVE_ERROR]: string;
53
- [ERROR_CODE.STUB_NOT_IMPLEMENTED]: string;
54
- [ERROR_CODE.RESOLVER_MISSING]: string;
55
- [ERROR_CODE.RESOLVER_NOT_IMPLEMENTED]: string;
56
- [ERROR_CODE.RESOLVER_NOT_FOUND]: string;
57
- [ERROR_CODE.RESOLVER_NOT_SUPPORTED]: string;
58
- [ERROR_CODE.CALL_MAX_RETRIES_REACHED]: string;
12
+ type IRPCErrorType = (typeof IRPC_ERROR_TYPE)[keyof typeof IRPC_ERROR_TYPE];
13
+ declare const STUB_ERROR: {
14
+ readonly DUPLICATE: "duplicate";
15
+ readonly INVALID: "invalid";
16
+ readonly NOT_FOUND: "not_found";
17
+ readonly INVALID_NAME: "invalid_name";
18
+ readonly INVALID_VERSION: "invalid_version";
59
19
  };
20
+ declare const HANDLER_ERROR: {
21
+ readonly INVALID: "invalid";
22
+ readonly MISSING: "missing";
23
+ readonly ERROR: "error";
24
+ };
25
+ declare const TRANSPORT_ERROR: {
26
+ readonly INVALID: "invalid";
27
+ readonly MISSING: "missing";
28
+ readonly NOT_IMPLEMENTED: "not_implemented";
29
+ readonly NOT_CONNECTED: "not_connected";
30
+ readonly CLOSED: "closed";
31
+ readonly INVALID_BODY: "invalid_body";
32
+ readonly STREAM_TERMINATED: "stream_terminated";
33
+ readonly ERROR: "error";
34
+ };
35
+ declare const RESOLVE_ERROR: {
36
+ readonly NOT_FOUND: "not_found";
37
+ readonly INVALID_INPUT: "invalid_input";
38
+ readonly INVALID_OUTPUT: "invalid_output";
39
+ readonly ERROR: "error";
40
+ };
41
+ declare const HOOK_ERROR: {
42
+ readonly INVALID: "invalid";
43
+ readonly ERROR: "error";
44
+ };
45
+ declare const CALL_ERROR: {
46
+ readonly TIMEOUT: "timeout";
47
+ readonly MAX_RETRIES: "max_retries";
48
+ readonly STREAM_ERROR: "stream_error";
49
+ };
50
+ /**
51
+ * Base error class for all IRPC errors.
52
+ *
53
+ * @property type - The domain category of the error (stub, handler, transport, etc.)
54
+ * @property code - A stable, machine-readable code for translation or programmatic matching.
55
+ */
56
+ declare class IRPCError extends Error {
57
+ type: IRPCErrorType;
58
+ code: string;
59
+ cause?: Error | undefined;
60
+ constructor(type: IRPCErrorType, code: string, message: string, cause?: Error | undefined);
61
+ /** Serialize to the wire format used in IRPC packets. */
62
+ json(): IRPCPacketError;
63
+ /** Reconstruct an IRPCError from a wire packet error. */
64
+ static from(obj: IRPCPacketError): IRPCError;
65
+ }
66
+ /** Errors related to stub declaration, registration, and lookup. */
67
+ declare class StubError extends IRPCError {
68
+ constructor(code: string, message: string, cause?: Error);
69
+ static duplicate(name: string): StubError;
70
+ static invalid(): StubError;
71
+ static notFound(): StubError;
72
+ static invalidName(name: string): StubError;
73
+ static invalidVersion(version: string): StubError;
74
+ }
75
+ /** Errors related to handler registration and execution. */
76
+ declare class HandlerError extends IRPCError {
77
+ constructor(code: string, message: string, cause?: Error);
78
+ static invalid(): HandlerError;
79
+ static missing(name: string): HandlerError;
80
+ static failed(input: Error | string): HandlerError;
81
+ }
82
+ /** Errors related to the transport layer. */
83
+ declare class TransportError extends IRPCError {
84
+ constructor(code: string, message: string, cause?: Error);
85
+ static missing(): TransportError;
86
+ static invalid(): TransportError;
87
+ static notImplemented(): TransportError;
88
+ static notConnected(name: string): TransportError;
89
+ static closed(name: string): TransportError;
90
+ static invalidBody(): TransportError;
91
+ static streamTerminated(): TransportError;
92
+ static failed(input: Error | string): TransportError;
93
+ }
94
+ /** Errors related to server-side request resolution. */
95
+ declare class ResolveError extends IRPCError {
96
+ constructor(code: string, message: string, cause?: Error);
97
+ static notFound(name: string): ResolveError;
98
+ static invalidInput(input: Error | string): ResolveError;
99
+ static invalidOutput(input?: Error | string): ResolveError;
100
+ static failed(input: Error | string): ResolveError;
101
+ }
102
+ /** Errors related to hook registration and execution. */
103
+ declare class HookError extends IRPCError {
104
+ constructor(code: string, message: string, cause?: Error);
105
+ static invalid(): HookError;
106
+ static failed(input: Error | string): HookError;
107
+ }
108
+ /** Errors related to call execution lifecycle. */
109
+ declare class CallError extends IRPCError {
110
+ constructor(code: string, message: string, cause?: Error);
111
+ static timeout(): CallError;
112
+ static maxRetries(reasons: Set<Error>): CallError;
113
+ static streamError(input: Error | string): CallError;
114
+ }
60
115
  //#endregion
61
- export { ERROR_CODE, ERROR_MESSAGE, ErrorCode };
116
+ export { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError };
package/dist/error.js CHANGED
@@ -1,61 +1,212 @@
1
1
  //#region src/error.ts
2
- const ERROR_CODE = {
3
- UNKNOWN: "unknown",
4
- TIMEOUT: "timeout",
2
+ const IRPC_ERROR_TYPE = {
3
+ STUB: "stub",
4
+ HOOK: "hook",
5
+ CALL: "call",
6
+ HANDLER: "handler",
7
+ RESOLVE: "resolve",
8
+ TRANSPORT: "transport"
9
+ };
10
+ const STUB_ERROR = {
11
+ DUPLICATE: "duplicate",
12
+ INVALID: "invalid",
5
13
  NOT_FOUND: "not_found",
6
- NOT_SUPPORTED: "not_supported",
7
- INVALID_TYPE: "invalid_type",
8
- INVALID_STATE: "invalid_state",
9
- INVALID_VALUE: "invalid_value",
10
- INVALID_INPUT: "invalid_argument",
11
- INVALID_OUTPUT: "invalid_argument",
14
+ INVALID_NAME: "invalid_name",
15
+ INVALID_VERSION: "invalid_version"
16
+ };
17
+ const HANDLER_ERROR = {
18
+ INVALID: "invalid",
19
+ MISSING: "missing",
20
+ ERROR: "error"
21
+ };
22
+ const TRANSPORT_ERROR = {
23
+ INVALID: "invalid",
24
+ MISSING: "missing",
12
25
  NOT_IMPLEMENTED: "not_implemented",
13
- INVALID_HANDLER: "invalid_handler",
14
- INVALID_OPERATION: "invalid_operation",
15
- INVALID_HOOK: "invalid_middleware",
16
- TRANSPORT_MISSING: "transport_missing",
17
- TRANSPORT_INVALID: "transport_invalid",
18
- TRANSPORT_NOT_IMPLEMENTED: "transport_not_implemented",
19
- STUB_MISSING: "stub_missing",
20
- STUB_INVALID: "stub_invalid",
21
- STUB_NOT_IMPLEMENTED: "stub_not_implemented",
22
- RESOLVER_MISSING: "resolver_missing",
23
- RESOLVER_NOT_IMPLEMENTED: "resolver_not_implemented",
24
- RESOLVER_NOT_FOUND: "resolver_not_found",
25
- RESOLVER_NOT_SUPPORTED: "resolver_not_supported",
26
- STREAM_ERROR: "stream_error",
27
- HANDLER_ERROR: "handler_error",
28
- RESOLVE_ERROR: "resolve_error",
29
- CALL_MAX_RETRIES_REACHED: "call_max_retries_reached"
30
- };
31
- const ERROR_MESSAGE = {
32
- [ERROR_CODE.UNKNOWN]: "IRPC: Unknown error",
33
- [ERROR_CODE.TIMEOUT]: "IRPC: Timeout error",
34
- [ERROR_CODE.NOT_FOUND]: "IRPC: Not found error",
35
- [ERROR_CODE.NOT_SUPPORTED]: "IRPC: Not supported error",
36
- [ERROR_CODE.INVALID_TYPE]: "IRPC: Invalid type error",
37
- [ERROR_CODE.INVALID_STATE]: "IRPC: Invalid state error",
38
- [ERROR_CODE.INVALID_VALUE]: "IRPC: Invalid value error",
39
- [ERROR_CODE.INVALID_INPUT]: "IRPC: Invalid input error",
40
- [ERROR_CODE.INVALID_OUTPUT]: "IRPC: Invalid output error",
41
- [ERROR_CODE.NOT_IMPLEMENTED]: "IRPC: Not implemented error",
42
- [ERROR_CODE.INVALID_HANDLER]: "IRPC: Invalid handler error",
43
- [ERROR_CODE.INVALID_OPERATION]: "IRPC: Invalid operation error",
44
- [ERROR_CODE.INVALID_HOOK]: "IRPC: Invalid hook error",
45
- [ERROR_CODE.TRANSPORT_MISSING]: "IRPC: Transport missing error",
46
- [ERROR_CODE.TRANSPORT_INVALID]: "IRPC: Transport invalid error",
47
- [ERROR_CODE.TRANSPORT_NOT_IMPLEMENTED]: "IRPC: Transport not implemented error",
48
- [ERROR_CODE.STUB_INVALID]: "IRPC: Stub invalid error",
49
- [ERROR_CODE.STREAM_ERROR]: "IRPC: Stream error",
50
- [ERROR_CODE.HANDLER_ERROR]: "IRPC: Handler error",
51
- [ERROR_CODE.RESOLVE_ERROR]: "IRPC: Resolve error",
52
- [ERROR_CODE.STUB_NOT_IMPLEMENTED]: "IRPC: Stub not implemented error",
53
- [ERROR_CODE.RESOLVER_MISSING]: "IRPC: Resolver missing error",
54
- [ERROR_CODE.RESOLVER_NOT_IMPLEMENTED]: "IRPC: Resolver not implemented error",
55
- [ERROR_CODE.RESOLVER_NOT_FOUND]: "IRPC: Resolver not found error",
56
- [ERROR_CODE.RESOLVER_NOT_SUPPORTED]: "IRPC: Resolver not supported error",
57
- [ERROR_CODE.CALL_MAX_RETRIES_REACHED]: "IRPC: Call max retries reached error"
26
+ NOT_CONNECTED: "not_connected",
27
+ CLOSED: "closed",
28
+ INVALID_BODY: "invalid_body",
29
+ STREAM_TERMINATED: "stream_terminated",
30
+ ERROR: "error"
31
+ };
32
+ const RESOLVE_ERROR = {
33
+ NOT_FOUND: "not_found",
34
+ INVALID_INPUT: "invalid_input",
35
+ INVALID_OUTPUT: "invalid_output",
36
+ ERROR: "error"
37
+ };
38
+ const HOOK_ERROR = {
39
+ INVALID: "invalid",
40
+ ERROR: "error"
41
+ };
42
+ const CALL_ERROR = {
43
+ TIMEOUT: "timeout",
44
+ MAX_RETRIES: "max_retries",
45
+ STREAM_ERROR: "stream_error"
46
+ };
47
+ function unwrap(input) {
48
+ if (input instanceof Error) return {
49
+ message: input.message,
50
+ cause: input
51
+ };
52
+ return { message: input };
53
+ }
54
+ /**
55
+ * Base error class for all IRPC errors.
56
+ *
57
+ * @property type - The domain category of the error (stub, handler, transport, etc.)
58
+ * @property code - A stable, machine-readable code for translation or programmatic matching.
59
+ */
60
+ var IRPCError = class IRPCError extends Error {
61
+ constructor(type, code, message, cause) {
62
+ super(message);
63
+ this.type = type;
64
+ this.code = code;
65
+ this.cause = cause;
66
+ }
67
+ /** Serialize to the wire format used in IRPC packets. */
68
+ json() {
69
+ return {
70
+ type: this.type,
71
+ code: this.code,
72
+ message: this.message
73
+ };
74
+ }
75
+ /** Reconstruct an IRPCError from a wire packet error. */
76
+ static from(obj) {
77
+ const ErrorClass = IRPC_ERROR_CLASS[obj.type];
78
+ if (ErrorClass) return new ErrorClass(obj.code, obj.message);
79
+ return new IRPCError(obj.type, obj.code, obj.message);
80
+ }
81
+ };
82
+ /** Errors related to stub declaration, registration, and lookup. */
83
+ var StubError = class StubError extends IRPCError {
84
+ constructor(code, message, cause) {
85
+ super(IRPC_ERROR_TYPE.STUB, code, message, cause);
86
+ }
87
+ static duplicate(name) {
88
+ return new StubError(STUB_ERROR.DUPLICATE, `IRPC "${name}" already exists.`);
89
+ }
90
+ static invalid() {
91
+ return new StubError(STUB_ERROR.INVALID, "Invalid stub.");
92
+ }
93
+ static notFound() {
94
+ return new StubError(STUB_ERROR.NOT_FOUND, "No spec found for stub.");
95
+ }
96
+ static invalidName(name) {
97
+ return new StubError(STUB_ERROR.INVALID_NAME, `Invalid name: ${name}`);
98
+ }
99
+ static invalidVersion(version) {
100
+ return new StubError(STUB_ERROR.INVALID_VERSION, `Invalid version: ${version}`);
101
+ }
102
+ };
103
+ /** Errors related to handler registration and execution. */
104
+ var HandlerError = class HandlerError extends IRPCError {
105
+ constructor(code, message, cause) {
106
+ super(IRPC_ERROR_TYPE.HANDLER, code, message, cause);
107
+ }
108
+ static invalid() {
109
+ return new HandlerError(HANDLER_ERROR.INVALID, "Handler must be a function.");
110
+ }
111
+ static missing(name) {
112
+ return new HandlerError(HANDLER_ERROR.MISSING, `IRPC "${name}" has no implementation.`);
113
+ }
114
+ static failed(input) {
115
+ const { message, cause } = unwrap(input);
116
+ return new HandlerError(HANDLER_ERROR.ERROR, message, cause);
117
+ }
118
+ };
119
+ /** Errors related to the transport layer. */
120
+ var TransportError = class TransportError extends IRPCError {
121
+ constructor(code, message, cause) {
122
+ super(IRPC_ERROR_TYPE.TRANSPORT, code, message, cause);
123
+ }
124
+ static missing() {
125
+ return new TransportError(TRANSPORT_ERROR.MISSING, "No transport configured.");
126
+ }
127
+ static invalid() {
128
+ return new TransportError(TRANSPORT_ERROR.INVALID, "Invalid transport.");
129
+ }
130
+ static notImplemented() {
131
+ return new TransportError(TRANSPORT_ERROR.NOT_IMPLEMENTED, "Transport dispatch not implemented.");
132
+ }
133
+ static notConnected(name) {
134
+ return new TransportError(TRANSPORT_ERROR.NOT_CONNECTED, `${name} is not connected.`);
135
+ }
136
+ static closed(name) {
137
+ return new TransportError(TRANSPORT_ERROR.CLOSED, `${name} connection closed.`);
138
+ }
139
+ static invalidBody() {
140
+ return new TransportError(TRANSPORT_ERROR.INVALID_BODY, "Invalid response body.");
141
+ }
142
+ static streamTerminated() {
143
+ return new TransportError(TRANSPORT_ERROR.STREAM_TERMINATED, "Response stream terminated.");
144
+ }
145
+ static failed(input) {
146
+ const { message, cause } = unwrap(input);
147
+ return new TransportError(TRANSPORT_ERROR.ERROR, message, cause);
148
+ }
149
+ };
150
+ /** Errors related to server-side request resolution. */
151
+ var ResolveError = class ResolveError extends IRPCError {
152
+ constructor(code, message, cause) {
153
+ super(IRPC_ERROR_TYPE.RESOLVE, code, message, cause);
154
+ }
155
+ static notFound(name) {
156
+ return new ResolveError(RESOLVE_ERROR.NOT_FOUND, `IRPC "${name}" does not exist.`);
157
+ }
158
+ static invalidInput(input) {
159
+ const { message, cause } = unwrap(input);
160
+ return new ResolveError(RESOLVE_ERROR.INVALID_INPUT, message, cause);
161
+ }
162
+ static invalidOutput(input) {
163
+ if (!input) return new ResolveError(RESOLVE_ERROR.INVALID_OUTPUT, "Invalid output.");
164
+ const { message, cause } = unwrap(input);
165
+ return new ResolveError(RESOLVE_ERROR.INVALID_OUTPUT, message, cause);
166
+ }
167
+ static failed(input) {
168
+ const { message, cause } = unwrap(input);
169
+ return new ResolveError(RESOLVE_ERROR.ERROR, message, cause);
170
+ }
171
+ };
172
+ /** Errors related to hook registration and execution. */
173
+ var HookError = class HookError extends IRPCError {
174
+ constructor(code, message, cause) {
175
+ super(IRPC_ERROR_TYPE.HOOK, code, message, cause);
176
+ }
177
+ static invalid() {
178
+ return new HookError(HOOK_ERROR.INVALID, "Hook must be a function.");
179
+ }
180
+ static failed(input) {
181
+ const { message, cause } = unwrap(input);
182
+ return new HookError(HOOK_ERROR.ERROR, message, cause);
183
+ }
184
+ };
185
+ /** Errors related to call execution lifecycle. */
186
+ var CallError = class CallError extends IRPCError {
187
+ constructor(code, message, cause) {
188
+ super(IRPC_ERROR_TYPE.CALL, code, message, cause);
189
+ }
190
+ static timeout() {
191
+ return new CallError(CALL_ERROR.TIMEOUT, "Call timed out.");
192
+ }
193
+ static maxRetries(reasons) {
194
+ const detail = Array.from(reasons).map((r) => r.message).join(", ");
195
+ return new CallError(CALL_ERROR.MAX_RETRIES, `Max retries reached: ${detail}`);
196
+ }
197
+ static streamError(input) {
198
+ const { message, cause } = unwrap(input);
199
+ return new CallError(CALL_ERROR.STREAM_ERROR, message, cause);
200
+ }
201
+ };
202
+ const IRPC_ERROR_CLASS = {
203
+ [IRPC_ERROR_TYPE.STUB]: StubError,
204
+ [IRPC_ERROR_TYPE.HANDLER]: HandlerError,
205
+ [IRPC_ERROR_TYPE.TRANSPORT]: TransportError,
206
+ [IRPC_ERROR_TYPE.RESOLVE]: ResolveError,
207
+ [IRPC_ERROR_TYPE.HOOK]: HookError,
208
+ [IRPC_ERROR_TYPE.CALL]: CallError
58
209
  };
59
210
 
60
211
  //#endregion
61
- export { ERROR_CODE, ERROR_MESSAGE };
212
+ export { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { IRPCCacheEntry, IRPCCacher } from "./cache.js";
2
- import { IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
3
- import { ERROR_CODE, ERROR_MESSAGE, ErrorCode } from "./error.js";
2
+ import { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
4
3
  import { IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe } from "./file.js";
5
4
  import { IRPCFilePointer, IRPCFileQueue, IRPCPacketJson, IRPCPacketQueues, IRPC_FILE_IDENTIFIER, PacketStream, decode, encode, isFilePointer } from "./packet.js";
6
5
  import { IRPCHookArgs, IRPCPackage, IRPCSpecHook, createPackage, intercept } from "./module.js";
7
6
  import { IRPCTransport } from "./transport.js";
8
- import { IRPCArraySchema, IRPCBaseContext, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDataType, IRPCDeclareInit, IRPCError, IRPCFunction, IRPCHandler, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig } from "./types.js";
7
+ import { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDeclareInit, IRPCDefined, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig } from "./types.js";
9
8
  import { RemoteState, stream } from "./state.js";
10
9
  import { IRPCReader } from "./reader.js";
11
10
  import { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, IRPCCall } from "./call.js";
12
11
  import { createContext, createContextStore, getAbortController, getAbortSignal, getContext, setContext, setContextProvider, withContext } from "./context.js";
13
12
  import { createCredentials, credential, getCredentials } from "./credential.js";
13
+ import { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
14
14
  import { IRPCResolver } from "./resolver.js";
15
15
  import { IRPCHook, IRPCRouter } from "./router.js";
16
16
  import { IRPCStream } from "./stream.js";
17
17
  import { IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPC_STORE } from "./store.js";
18
18
  import { plan } from "@anchorlib/core";
19
- export { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, ERROR_CODE, ERROR_MESSAGE, ErrorCode, IRPCArraySchema, IRPCBaseContext, IRPCCacheEntry, IRPCCacher, IRPCCall, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDataType, IRPCDeclareInit, IRPCError, IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFilePointer, IRPCFileQueue, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe, IRPCFunction, IRPCHandler, IRPCHook, IRPCHookArgs, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackage, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketEvent, IRPCPacketJson, IRPCPacketQueues, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCReader, IRPCRequest, IRPCRequests, IRPCResolver, IRPCResponse, IRPCRouter, IRPCSchema, IRPCSpec, IRPCSpecHook, IRPCSpecStore, IRPCStatus, IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPCStream, IRPCStreamInit, IRPCStub, IRPCStubStore, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, PacketStream, RemoteState, StreamCleanup, StreamConstructor, TransportConfig, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
19
+ export { CALL_ERROR, CallError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCArraySchema, IRPCCacheEntry, IRPCCacher, IRPCCall, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDeclareInit, IRPCDefined, IRPCError, IRPCErrorType, IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFilePointer, IRPCFileQueue, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe, IRPCFunction, IRPCHandler, IRPCHook, IRPCHookArgs, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackage, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketJson, IRPCPacketQueues, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCReader, IRPCRequest, IRPCRequests, IRPCResolver, IRPCResponse, IRPCRouter, IRPCSchema, IRPCSpec, IRPCSpecHook, IRPCSpecStore, IRPCStatus, IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPCStream, IRPCStreamInit, IRPCStub, IRPCStubStore, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_ERROR_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, PacketStream, RESOLVE_ERROR, RemoteState, ResolveError, STUB_ERROR, StreamCleanup, StreamConstructor, StubError, TRANSPORT_ERROR, TransportConfig, TransportError, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IRPCCacher } from "./cache.js";
2
- import { IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
3
- import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
2
+ import { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
3
+ import { CALL_ERROR, CallError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
4
4
  import { createContext, createContextStore, getAbortController, getAbortSignal, getContext, setContext, setContextProvider, withContext } from "./context.js";
5
5
  import { RemoteState, stream } from "./state.js";
6
6
  import { IRPCReader } from "./reader.js";
@@ -16,4 +16,4 @@ import { IRPC_FILE_IDENTIFIER, decode, encode, isFilePointer } from "./packet.js
16
16
  import { IRPCResolver } from "./resolver.js";
17
17
  import { plan } from "@anchorlib/core";
18
18
 
19
- export { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, ERROR_CODE, ERROR_MESSAGE, IRPCCacher, IRPCCall, IRPCFile, IRPCFileStream, IRPCPackage, IRPCReader, IRPCResolver, IRPCRouter, IRPCStore, IRPCStream, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, RemoteState, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
19
+ export { CALL_ERROR, CallError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCCacher, IRPCCall, IRPCError, IRPCFile, IRPCFileStream, IRPCPackage, IRPCReader, IRPCResolver, IRPCRouter, IRPCStore, IRPCStream, IRPCTransport, IRPC_BASE_CONTEXT, IRPC_ERROR_TYPE, IRPC_FILE_IDENTIFIER, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE, IRPC_STORE_EVENT, RESOLVE_ERROR, RemoteState, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError, createContext, createContextStore, createCredentials, createPackage, credential, decode, encode, getAbortController, getAbortSignal, getContext, getCredentials, intercept, isFilePointer, plan, setContext, setContextProvider, stream, withContext };
package/dist/module.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IRPCCacher } from "./cache.js";
2
2
  import { IRPC_STATUS } from "./enum.js";
3
- import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
3
+ import { HandlerError, ResolveError, StubError, TransportError } from "./error.js";
4
4
  import { getAbortSignal } from "./context.js";
5
5
  import { RemoteState } from "./state.js";
6
6
  import { IRPCReader } from "./reader.js";
@@ -79,15 +79,16 @@ var IRPCPackage = class {
79
79
  */
80
80
  declare(options) {
81
81
  const $options = options;
82
- if (this.specs.has($options.name)) throw new Error(`IRPC ${$options.name} already exists.`);
82
+ if (this.specs.has($options.name)) throw StubError.duplicate($options.name);
83
+ if ($options.init && !$options.seed) $options.seed = $options.init;
83
84
  const spec = {
84
- init: () => void 0,
85
+ seed: () => void 0,
85
86
  ...$options
86
87
  };
87
88
  const calls = /* @__PURE__ */ new Map();
88
89
  const caches = new IRPCCacher();
89
90
  const stub = ((...args) => {
90
- return execute(args, new IRPCReader(uuid(), spec.init()));
91
+ return execute(args, new IRPCReader(uuid(), spec.seed()));
91
92
  });
92
93
  /** Browser only stub for single immediate execution **/
93
94
  stub.once = (...args) => {
@@ -100,7 +101,7 @@ var IRPCPackage = class {
100
101
  return prepare(typeof getArgs === "function" ? getArgs : () => getArgs, true, debounce);
101
102
  };
102
103
  stub.later = (debounce) => {
103
- const reader = new IRPCReader(uuid(), spec.init(), IRPC_STATUS.IDLE, true);
104
+ const reader = new IRPCReader(uuid(), spec.seed(), IRPC_STATUS.IDLE, true);
104
105
  if (debounce) {
105
106
  const [schedule, cancel] = microtask(debounce);
106
107
  reader.dispatch = (...args) => schedule(() => {
@@ -125,7 +126,7 @@ var IRPCPackage = class {
125
126
  * @returns {IRPCReader<IRPCData>} - The reader for the call.
126
127
  */
127
128
  function prepare(getArgs, deferred, debounce = 0) {
128
- const reader = new IRPCReader(uuid(), spec.init(), deferred ? IRPC_STATUS.IDLE : IRPC_STATUS.PENDING);
129
+ const reader = new IRPCReader(uuid(), spec.seed(), deferred ? IRPC_STATUS.IDLE : IRPC_STATUS.PENDING);
129
130
  if (isBrowser()) {
130
131
  const observer = createObserver(() => {
131
132
  observer.reset();
@@ -149,13 +150,13 @@ var IRPCPackage = class {
149
150
  return reader;
150
151
  }
151
152
  const execute = (args, reader) => {
152
- if (!this.transport && typeof spec.handler !== "function") return Promise.reject(new Error(ERROR_MESSAGE[ERROR_CODE.TRANSPORT_MISSING]));
153
+ if (!this.transport && typeof spec.handler !== "function") return Promise.reject(TransportError.missing());
153
154
  reader.status = IRPC_STATUS.PENDING;
154
155
  const callKey = JSON.stringify(args);
155
156
  const cached = caches.get(callKey);
156
157
  if (cached) return cached.value;
157
158
  if (spec.coalesce !== false && calls.has(callKey)) return calls.get(callKey);
158
- const { timeout, maxRetries, retryDelay, retryMode, init } = {
159
+ const { timeout, maxRetries, retryDelay, retryMode } = {
159
160
  ...this.config,
160
161
  ...spec
161
162
  };
@@ -163,8 +164,7 @@ var IRPCPackage = class {
163
164
  timeout,
164
165
  maxRetries,
165
166
  retryDelay,
166
- retryMode,
167
- init
167
+ retryMode
168
168
  };
169
169
  const hooks = this.hooks.get(spec);
170
170
  if (hooks) hooks.forEach((hook) => hook({
@@ -192,8 +192,8 @@ var IRPCPackage = class {
192
192
  */
193
193
  resolve(req) {
194
194
  const spec = this.specs.get(req.name);
195
- if (!spec) return Promise.reject(/* @__PURE__ */ new Error(`IRPC ${req.name} does not exist.`));
196
- if (typeof spec.handler !== "function") return Promise.reject(/* @__PURE__ */ new Error(`IRPC ${req.name} does not have an implementation.`));
195
+ if (!spec) return Promise.reject(ResolveError.notFound(req.name));
196
+ if (typeof spec.handler !== "function") return Promise.reject(HandlerError.missing(req.name));
197
197
  return spec.handler(...req.args);
198
198
  }
199
199
  /**
@@ -204,10 +204,10 @@ var IRPCPackage = class {
204
204
  * @throws Error if the stub or handler is invalid, or if no IRPC exists for the stub
205
205
  */
206
206
  construct(stub, handler) {
207
- if (typeof stub !== "function") throw new Error(ERROR_MESSAGE[ERROR_CODE.STUB_INVALID]);
208
- if (typeof handler !== "function") throw new Error(ERROR_MESSAGE[ERROR_CODE.INVALID_HANDLER]);
207
+ if (typeof stub !== "function") throw StubError.invalid();
208
+ if (typeof handler !== "function") throw HandlerError.invalid();
209
209
  const spec = this.stubs.get(stub);
210
- if (!spec?.name) throw new Error(ERROR_MESSAGE[ERROR_CODE.NOT_FOUND]);
210
+ if (!spec?.name) throw StubError.notFound();
211
211
  spec.handler = handler;
212
212
  return this;
213
213
  }
@@ -220,7 +220,7 @@ var IRPCPackage = class {
220
220
  */
221
221
  hook(stub, handler) {
222
222
  if (!this.stubs.has(stub)) {
223
- const error = new Error(ERROR_MESSAGE[ERROR_CODE.NOT_FOUND]);
223
+ const error = StubError.notFound();
224
224
  IRPC_STORE.error(error);
225
225
  return this;
226
226
  }
@@ -236,7 +236,7 @@ var IRPCPackage = class {
236
236
  */
237
237
  async resolveHooks(req) {
238
238
  const spec = this.specs.get(req.name);
239
- if (!spec || !this.hooks.has(spec)) throw new Error(ERROR_MESSAGE[ERROR_CODE.NOT_FOUND]);
239
+ if (!spec || !this.hooks.has(spec)) throw StubError.notFound();
240
240
  const hooks = this.hooks.get(spec);
241
241
  for (const hook of hooks) await hook(req);
242
242
  }
@@ -247,7 +247,7 @@ var IRPCPackage = class {
247
247
  * @throws Error if the transport is not a valid Transport instance
248
248
  */
249
249
  use(transport) {
250
- if (!(transport instanceof IRPCTransport)) throw new Error(ERROR_MESSAGE[ERROR_CODE.TRANSPORT_INVALID]);
250
+ if (!(transport instanceof IRPCTransport)) throw TransportError.invalid();
251
251
  if (this.transport) this.transport.modules.delete(this);
252
252
  transport.modules.add(this);
253
253
  this.config.transport = transport;
@@ -269,8 +269,8 @@ var IRPCPackage = class {
269
269
  * @throws Error if the provided name or version is invalid
270
270
  */
271
271
  configure(config) {
272
- if (config.name && !NAME_CONSTRAINT.test(config.name)) throw new Error(`Invalid IRPC name: ${config.name}`);
273
- if (config.version && !VERSION_CONSTRAINT.test(config.version)) throw new Error(`Invalid IRPC version: ${config.version}`);
272
+ if (config.name && !NAME_CONSTRAINT.test(config.name)) throw StubError.invalidName(config.name);
273
+ if (config.version && !VERSION_CONSTRAINT.test(config.version)) throw StubError.invalidVersion(config.version);
274
274
  Object.assign(this.config, config);
275
275
  return this;
276
276
  }
package/dist/reader.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
+ import { IRPCError } from "./error.js";
2
3
  import { RemoteState } from "./state.js";
3
4
  import { replay } from "@anchorlib/core";
4
5
 
@@ -30,11 +31,11 @@ var IRPCReader = class extends RemoteState {
30
31
  */
31
32
  push(packet) {
32
33
  packet.arrivedAt = Date.now();
33
- if (packet.type === IRPC_PACKET_TYPE.ANSWER) if (packet.status === IRPC_STATUS.ERROR) this.error = new Error(packet.error.message);
34
+ if (packet.type === IRPC_PACKET_TYPE.ANSWER) if (packet.status === IRPC_STATUS.ERROR) this.error = IRPCError.from(packet.error);
34
35
  else this.data = packet.data;
35
36
  else if (packet.type === IRPC_PACKET_TYPE.EVENT) replay(this.state, packet.data);
36
37
  else if (packet.type === IRPC_PACKET_TYPE.CLOSE) {
37
- if (packet.error) this.error = new Error(packet.error.message);
38
+ if (packet.error) this.error = IRPCError.from(packet.error);
38
39
  }
39
40
  this.status = packet.status;
40
41
  }
package/dist/resolver.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ERROR_CODE } from "./error.js";
1
+ import { HandlerError, ResolveError } from "./error.js";
2
2
  import { RemoteState } from "./state.js";
3
3
 
4
4
  //#region src/resolver.ts
@@ -40,20 +40,14 @@ var IRPCResolver = class {
40
40
  if (!this.spec) return {
41
41
  id,
42
42
  name,
43
- error: {
44
- code: ERROR_CODE.NOT_FOUND,
45
- message: `IRPC "${name}" does not exist.`
46
- }
43
+ error: ResolveError.notFound(name).json()
47
44
  };
48
45
  const { schema } = this.spec;
49
46
  const inputs = parseInput(args, schema?.input);
50
47
  if (!inputs.success) return {
51
48
  id,
52
49
  name,
53
- error: {
54
- code: ERROR_CODE.INVALID_INPUT,
55
- message: inputs.error
56
- }
50
+ error: ResolveError.invalidInput(inputs.error).json()
57
51
  };
58
52
  return this.forward({
59
53
  id,
@@ -85,10 +79,7 @@ var IRPCResolver = class {
85
79
  if (!output$1.success) return {
86
80
  id,
87
81
  name,
88
- error: {
89
- code: ERROR_CODE.INVALID_OUTPUT,
90
- message: output$1.error?.message
91
- }
82
+ error: ResolveError.invalidOutput(output$1.error).json()
92
83
  };
93
84
  return {
94
85
  id,
@@ -103,10 +94,7 @@ var IRPCResolver = class {
103
94
  if (!output$1.success) return {
104
95
  id,
105
96
  name,
106
- error: {
107
- code: ERROR_CODE.INVALID_OUTPUT,
108
- message: output$1.error?.message
109
- }
97
+ error: ResolveError.invalidOutput(output$1.error).json()
110
98
  };
111
99
  return {
112
100
  id,
@@ -123,19 +111,13 @@ var IRPCResolver = class {
123
111
  else return {
124
112
  id,
125
113
  name,
126
- error: {
127
- code: ERROR_CODE.INVALID_OUTPUT,
128
- message: output.error?.message
129
- }
114
+ error: ResolveError.invalidOutput(output.error).json()
130
115
  };
131
116
  } catch (error) {
132
117
  return {
133
118
  id,
134
119
  name,
135
- error: {
136
- code: ERROR_CODE.HANDLER_ERROR,
137
- message: error.message
138
- }
120
+ error: HandlerError.failed(error).json()
139
121
  };
140
122
  }
141
123
  }
package/dist/router.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IRPCPackage } from "./module.js";
2
2
  import { IRPCTransport } from "./transport.js";
3
- import { IRPCRequest } from "./types.js";
3
+ import { IRPCPacketError, IRPCRequest } from "./types.js";
4
4
 
5
5
  //#region src/router.d.ts
6
6
  type IRPCHook = () => void | Promise<void>;
@@ -42,10 +42,7 @@ declare class IRPCRouter {
42
42
  name: string;
43
43
  type: "close";
44
44
  status: "error";
45
- error: {
46
- code: string;
47
- message: string;
48
- };
45
+ error: IRPCPacketError;
49
46
  createdAt: number;
50
47
  } | undefined>;
51
48
  }
package/dist/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IRPC_BASE_CONTEXT, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
- import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
2
+ import { HookError } from "./error.js";
3
3
  import { createContextStore, withContext } from "./context.js";
4
4
  import { IRPC_STORE } from "./store.js";
5
5
 
@@ -24,7 +24,7 @@ var IRPCRouter = class {
24
24
  */
25
25
  use(hook) {
26
26
  if (typeof hook !== "function") {
27
- const error = new Error(ERROR_MESSAGE[ERROR_CODE.INVALID_HOOK]);
27
+ const error = HookError.invalid();
28
28
  IRPC_STORE.error(error);
29
29
  return this;
30
30
  }
@@ -67,10 +67,7 @@ var IRPCRouter = class {
67
67
  name: req.name,
68
68
  type: IRPC_PACKET_TYPE.CLOSE,
69
69
  status: IRPC_STATUS.ERROR,
70
- error: {
71
- code: ERROR_CODE.UNKNOWN,
72
- message: ERROR_MESSAGE[ERROR_CODE.UNKNOWN]
73
- },
70
+ error: HookError.failed(error).json(),
74
71
  createdAt: Date.now()
75
72
  };
76
73
  }
package/dist/state.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { IRPCReadable, IRPCStatus, StreamConstructor } from "./types.js";
2
- import * as _anchorlib_core0 from "@anchorlib/core";
3
- import { StateSubscriber } from "@anchorlib/core";
2
+ import { StateSubscriber, StateUnsubscribe } from "@anchorlib/core";
4
3
 
5
4
  //#region src/state.d.ts
6
5
 
@@ -41,8 +40,21 @@ declare class RemoteState<T> extends Promise<T> {
41
40
  * @param resumable - Whether the state should be resumable after being closed.
42
41
  */
43
42
  constructor(init?: T, status?: IRPCStatus, resumable?: boolean | undefined);
43
+ /**
44
+ * Transitions the state to SUCCESS and resolves the underlying Promise.
45
+ *
46
+ * @param value - Optional final value to resolve with.
47
+ */
44
48
  accept(value?: T): void;
49
+ /**
50
+ * Transitions the state to ERROR and rejects the underlying Promise.
51
+ *
52
+ * @param error - Optional error to reject with.
53
+ */
45
54
  reject(error?: Error): void;
55
+ /**
56
+ * Aborts the current execution, transitioning the status to ABORTED.
57
+ */
46
58
  abort(): void;
47
59
  /**
48
60
  * Subscribes to changes emitted by the internal state.
@@ -50,14 +62,34 @@ declare class RemoteState<T> extends Promise<T> {
50
62
  * @param handler - A callback function invoked whenever the state mutates.
51
63
  * @returns An unsubscribe function to terminate the listener.
52
64
  */
53
- subscribe(handler: StateSubscriber<IRPCReadable<T>>): _anchorlib_core0.StateUnsubscribe;
65
+ subscribe(handler: StateSubscriber<IRPCReadable<T>>): StateUnsubscribe;
54
66
  /**
55
67
  * Closes the reactive state and terminates the underlying Promise.
56
68
  */
57
69
  close(): void;
70
+ /**
71
+ * Resumes a closed state if it was marked as resumable.
72
+ */
58
73
  protected resume(): void;
74
+ /**
75
+ * Temporarily disables the `.then()` method to prevent automatic Promise chaining.
76
+ *
77
+ * @returns The current instance for chaining.
78
+ */
59
79
  pipe(): this;
80
+ /**
81
+ * Restores the `.then()` method if it was previously locked via `.pipe()`.
82
+ *
83
+ * @returns The current instance for chaining.
84
+ */
60
85
  unpipe(): this;
86
+ /**
87
+ * Pipes all state mutations from this instance to a target RemoteState.
88
+ *
89
+ * @param target - The destination RemoteState to receive the updates.
90
+ * @returns The current instance for chaining.
91
+ */
92
+ pipeTo(target: RemoteState<T>): this;
61
93
  /**
62
94
  * Destroys the reactive state bindings.
63
95
  */
@@ -75,9 +107,9 @@ declare class RemoteState<T> extends Promise<T> {
75
107
  *
76
108
  * @template T - The type of the streamed payload data.
77
109
  * @param construct - The isolated stream constructor callback that natively operates the pipeline.
78
- * @param init - An optional initial value to prime the state payload inherently.
110
+ * @param seed - An optional initial value to prime the state payload inherently.
79
111
  * @returns A fully active RemoteState inherently bound to the callbacks executing natively.
80
112
  */
81
- declare function stream<T>(construct: StreamConstructor<T>, init?: T): RemoteState<T>;
113
+ declare function stream<T>(construct: StreamConstructor<T>, seed?: T): RemoteState<T>;
82
114
  //#endregion
83
115
  export { RemoteState, stream };
package/dist/state.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IRPC_STATUS } from "./enum.js";
2
- import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
2
+ import { IRPCError, IRPC_ERROR_TYPE } from "./error.js";
3
3
  import { getAbortSignal } from "./context.js";
4
- import { $do, anchor, mutable, onCleanup, subscribe } from "@anchorlib/core";
4
+ import { $do, anchor, mutable, onCleanup, replay, subscribe } from "@anchorlib/core";
5
5
 
6
6
  //#region src/state.ts
7
7
  /**
@@ -17,6 +17,7 @@ var RemoteState = class extends Promise {
17
17
  #state;
18
18
  #accept;
19
19
  #reject;
20
+ #pipes = /* @__PURE__ */ new Set();
20
21
  #closed = false;
21
22
  #locked;
22
23
  get state() {
@@ -97,10 +98,13 @@ var RemoteState = class extends Promise {
97
98
  if (args.length) this.#state.error = args[0];
98
99
  this.#closed = true;
99
100
  this.#state.status = IRPC_STATUS.ERROR;
100
- this.#reject(this.error ?? new Error(ERROR_MESSAGE[ERROR_CODE.UNKNOWN]));
101
+ this.#reject(this.error ?? new IRPCError(IRPC_ERROR_TYPE.CALL, "unknown", "Unknown error."));
101
102
  this.destroy();
102
103
  });
103
104
  }
105
+ /**
106
+ * Aborts the current execution, transitioning the status to ABORTED.
107
+ */
104
108
  abort() {
105
109
  $do(() => {
106
110
  this.#closed = true;
@@ -116,7 +120,9 @@ var RemoteState = class extends Promise {
116
120
  * @returns An unsubscribe function to terminate the listener.
117
121
  */
118
122
  subscribe(handler) {
119
- return subscribe(this.state, handler);
123
+ const unsubscribe = subscribe(this.state, handler);
124
+ this.#pipes.add(unsubscribe);
125
+ return unsubscribe;
120
126
  }
121
127
  /**
122
128
  * Closes the reactive state and terminates the underlying Promise.
@@ -127,14 +133,27 @@ var RemoteState = class extends Promise {
127
133
  this.#accept(this.data);
128
134
  this.destroy();
129
135
  }
136
+ /**
137
+ * Resumes a closed state if it was marked as resumable.
138
+ */
130
139
  resume() {
131
140
  this.#closed = false;
132
141
  }
142
+ /**
143
+ * Temporarily disables the `.then()` method to prevent automatic Promise chaining.
144
+ *
145
+ * @returns The current instance for chaining.
146
+ */
133
147
  pipe() {
134
148
  this.#locked = this.then;
135
149
  this.then = void 0;
136
150
  return this;
137
151
  }
152
+ /**
153
+ * Restores the `.then()` method if it was previously locked via `.pipe()`.
154
+ *
155
+ * @returns The current instance for chaining.
156
+ */
138
157
  unpipe() {
139
158
  if (!this.#locked) return this;
140
159
  this.then = this.#locked;
@@ -142,10 +161,28 @@ var RemoteState = class extends Promise {
142
161
  return this;
143
162
  }
144
163
  /**
164
+ * Pipes all state mutations from this instance to a target RemoteState.
165
+ *
166
+ * @param target - The destination RemoteState to receive the updates.
167
+ * @returns The current instance for chaining.
168
+ */
169
+ pipeTo(target) {
170
+ this.subscribe((_, event) => {
171
+ if (event.type === "init") {
172
+ anchor.assign(target.state, this.state);
173
+ return;
174
+ }
175
+ replay(target.state, event);
176
+ });
177
+ return this;
178
+ }
179
+ /**
145
180
  * Destroys the reactive state bindings.
146
181
  */
147
182
  destroy() {
148
183
  if (this.resumable) return;
184
+ for (const unsubscribe of this.#pipes) unsubscribe();
185
+ this.#pipes.clear();
149
186
  anchor.destroy(this.state);
150
187
  }
151
188
  /**
@@ -163,11 +200,11 @@ var RemoteState = class extends Promise {
163
200
  *
164
201
  * @template T - The type of the streamed payload data.
165
202
  * @param construct - The isolated stream constructor callback that natively operates the pipeline.
166
- * @param init - An optional initial value to prime the state payload inherently.
203
+ * @param seed - An optional initial value to prime the state payload inherently.
167
204
  * @returns A fully active RemoteState inherently bound to the callbacks executing natively.
168
205
  */
169
- function stream(construct, init) {
170
- const state = new RemoteState(init);
206
+ function stream(construct, seed) {
207
+ const state = new RemoteState(seed);
171
208
  const abortSignal = getAbortSignal();
172
209
  const accept = ((...values) => {
173
210
  if (values.length > 0) state.data = values[0];
package/dist/stream.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IRPCData, IRPCDataSchema, IRPCError, IRPCInputs, IRPCPacketStream, IRPCResponse, IRPCSpec, IRPCStatus } from "./types.js";
1
+ import { IRPCData, IRPCDataSchema, IRPCInputs, IRPCPacketError, IRPCPacketStream, IRPCResponse, IRPCSpec, IRPCStatus } from "./types.js";
2
2
  import { IRPCRouter } from "./router.js";
3
3
 
4
4
  //#region src/stream.d.ts
@@ -21,7 +21,7 @@ declare class IRPCStream<T extends IRPCData> {
21
21
  private closeHandlers;
22
22
  private errorHandlers;
23
23
  value?: T;
24
- error?: IRPCError;
24
+ error?: IRPCPacketError;
25
25
  status: IRPCStatus;
26
26
  closed: boolean;
27
27
  createdAt: number;
@@ -55,7 +55,7 @@ declare class IRPCStream<T extends IRPCData> {
55
55
  *
56
56
  * @param handler - A callback function to receive stream errors.
57
57
  */
58
- catch(handler: (error: IRPCError) => void): void;
58
+ catch(handler: (error: IRPCPacketError) => void): void;
59
59
  /**
60
60
  * Binds a handler triggered upon terminal completion of the stream process (success or error).
61
61
  *
package/dist/stream.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
- import { ERROR_CODE } from "./error.js";
2
+ import { CallError, HandlerError, ResolveError } from "./error.js";
3
3
  import { getAbortController, getAbortSignal } from "./context.js";
4
4
  import { RemoteState } from "./state.js";
5
5
  import { IRPC_STORE } from "./store.js";
@@ -68,10 +68,7 @@ var IRPCStream = class {
68
68
  this.value = result.data;
69
69
  if (result.status === IRPC_STATUS.SUCCESS || result.status === IRPC_STATUS.ERROR) {
70
70
  if (result.status === IRPC_STATUS.ERROR) {
71
- this.error = {
72
- code: ERROR_CODE.HANDLER_ERROR,
73
- message: result.error.message
74
- };
71
+ this.error = HandlerError.failed(result.error).json();
75
72
  this.status = IRPC_STATUS.ERROR;
76
73
  } else this.status = IRPC_STATUS.SUCCESS;
77
74
  const packet = {
@@ -119,10 +116,7 @@ var IRPCStream = class {
119
116
  if (state.status !== IRPC_STATUS.SUCCESS && state.status !== IRPC_STATUS.ERROR) return;
120
117
  this.status = state.status;
121
118
  if (state.status === IRPC_STATUS.ERROR) {
122
- this.error = {
123
- code: ERROR_CODE.STREAM_ERROR,
124
- message: state.error.message
125
- };
119
+ this.error = CallError.streamError(state.error).json();
126
120
  this.errorHandlers.forEach((handler) => handler(this.error));
127
121
  }
128
122
  this.pipeHandlers.forEach((handler) => {
@@ -169,10 +163,7 @@ var IRPCStream = class {
169
163
  id: this.id,
170
164
  name: this.name
171
165
  }]);
172
- this.error = {
173
- code: ERROR_CODE.RESOLVE_ERROR,
174
- message: error.message
175
- };
166
+ this.error = ResolveError.failed(error).json();
176
167
  this.status = IRPC_STATUS.ERROR;
177
168
  this.pipeHandlers.forEach((handler) => {
178
169
  handler({
package/dist/transport.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
- import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
2
+ import { TransportError } from "./error.js";
3
3
  import { IRPCReader } from "./reader.js";
4
4
  import { IRPC_STORE } from "./store.js";
5
5
  import { IRPCCall } from "./call.js";
@@ -119,10 +119,7 @@ var IRPCTransport = class {
119
119
  name: call.payload.name,
120
120
  type: IRPC_PACKET_TYPE.CLOSE,
121
121
  status: IRPC_STATUS.ERROR,
122
- error: {
123
- code: ERROR_CODE.TRANSPORT_NOT_IMPLEMENTED,
124
- message: ERROR_MESSAGE[ERROR_CODE.TRANSPORT_NOT_IMPLEMENTED]
125
- },
122
+ error: TransportError.notImplemented().json(),
126
123
  createdAt: Date.now()
127
124
  });
128
125
  });
package/dist/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { IRPC_BASE_CONTEXT, IRPC_DATA_TYPE, IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
2
- import { ErrorCode } from "./error.js";
1
+ import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
3
2
  import { IRPCFile } from "./file.js";
4
3
  import { IRPCFilePointer } from "./packet.js";
5
4
  import { IRPCTransport } from "./transport.js";
@@ -21,9 +20,7 @@ type IRPCStubStore = WeakMap<IRPCHandler, IRPCSpec<IRPCInputs, IRPCOutput>>;
21
20
  */
22
21
  type IRPCSpecStore = Map<string, IRPCSpec<IRPCInputs, IRPCOutput>>;
23
22
  type IRPCStatus = (typeof IRPC_STATUS)[keyof typeof IRPC_STATUS];
24
- type IRPCDataType = (typeof IRPC_DATA_TYPE)[keyof typeof IRPC_DATA_TYPE];
25
23
  type IRPCPacketType = (typeof IRPC_PACKET_TYPE)[keyof typeof IRPC_PACKET_TYPE];
26
- type IRPCBaseContext = (typeof IRPC_BASE_CONTEXT)[keyof typeof IRPC_BASE_CONTEXT];
27
24
  type IRPCPacketBase = {
28
25
  id: string;
29
26
  name: string;
@@ -37,13 +34,13 @@ type IRPCPacketCall = IRPCPacketBase & {
37
34
  };
38
35
  type IRPCPacketAnswer<T extends IRPCData> = IRPCPacketBase & {
39
36
  data?: T;
40
- error?: IRPCError;
37
+ error?: IRPCPacketError;
41
38
  };
42
39
  type IRPCPacketEvent = IRPCPacketBase & {
43
40
  data: StateChange;
44
41
  };
45
42
  type IRPCPacketClose = IRPCPacketBase & {
46
- error?: IRPCError;
43
+ error?: IRPCPacketError;
47
44
  };
48
45
  type IRPCPacketStream<T extends IRPCData> = IRPCPacketAnswer<T> | IRPCPacketEvent | IRPCPacketClose;
49
46
  interface IRPCReadable<T> {
@@ -118,6 +115,11 @@ type IRPCObject = {
118
115
  * This is a recursive type that allows nested structures.
119
116
  */
120
117
  type IRPCData = IRPCPrimitive | IRPCObject | IRPCFile | IRPCData[];
118
+ /**
119
+ * Represents all possible defined data types in IRPC, including primitives, objects, and arrays.
120
+ * This is a recursive type that allows nested structures.
121
+ */
122
+ type IRPCDefined = string | number | boolean | IRPCObject | IRPCFile | IRPCDefined[];
121
123
  /**
122
124
  * Union type of all primitive Zod schema types used for validation.
123
125
  */
@@ -206,9 +208,12 @@ type IRPCInit<R$1, I extends IRPCInputs, O$1 extends IRPCOutput> = {
206
208
  * This can help reduce the number of actual function executions.
207
209
  */
208
210
  coalesce?: boolean;
209
- /** Optional initialization function to seed the data */
210
- init?: () => R$1;
211
- } & IRPCCallConfig;
211
+ } & IRPCCallConfig & IRPCInferInit<R$1>;
212
+ type IRPCInferInit<R$1> = R$1 extends IRPCDefined ? {
213
+ seed: () => R$1;
214
+ } : {
215
+ seed?: () => R$1;
216
+ };
212
217
  /**
213
218
  * Configuration options for initializing an RPC stream function.
214
219
  * Contains metadata and constraints for the RPC stream function.
@@ -228,7 +233,7 @@ type IRPCStreamInit<I extends IRPCInputs, O$1 extends IRPCOutput, R$1> = IRPCIni
228
233
  * @template I - Tuple of input validation schemas
229
234
  * @template O - Output validation schema
230
235
  */
231
- type IRPCDeclareInit<F, I extends IRPCInputs, O$1 extends IRPCOutput> = F extends ((...args: IRPCData[]) => infer R) ? R extends RemoteState<infer S> ? S extends IRPCData ? IRPCStreamInit<I, O$1, S> : IRPCInit<IRPCData, IRPCInputs, IRPCOutput> : R extends Promise<infer D> ? D extends IRPCData ? IRPCInit<D, I, O$1> : IRPCInit<IRPCData, IRPCInputs, IRPCOutput> : R extends IRPCData ? IRPCInit<R, I, O$1> : IRPCInit<IRPCData, IRPCInputs, IRPCOutput> : IRPCInit<IRPCData, IRPCInputs, IRPCOutput>;
236
+ type IRPCDeclareInit<F, I extends IRPCInputs, O$1 extends IRPCOutput> = F extends ((...args: infer _A) => infer R) ? R extends RemoteState<infer S> ? S extends IRPCData ? IRPCStreamInit<I, O$1, S> : IRPCInit<S, IRPCInputs, IRPCOutput> : R extends Promise<infer D> ? D extends IRPCData ? IRPCInit<D, I, O$1> : IRPCInit<D, IRPCInputs, IRPCOutput> : R extends IRPCData ? IRPCInit<R, I, O$1> : IRPCInit<R, IRPCInputs, IRPCOutput> : IRPCInit<IRPCData, IRPCInputs, IRPCOutput>;
232
237
  /**
233
238
  * Complete specification for an RPC function including its implementation.
234
239
  * Extends IRPCInit with the actual handler function.
@@ -243,8 +248,6 @@ type IRPCSpec<I extends IRPCInputs, O$1 extends IRPCOutput> = IRPCInit<IRPCData,
243
248
  stream?: boolean;
244
249
  /** The actual handler function that implements the RPC */
245
250
  handler: IRPCHandler;
246
- /** Optional initialization function for a stream RPC */
247
- init?: () => unknown;
248
251
  };
249
252
  /**
250
253
  * Represents an incoming RPC request.
@@ -264,8 +267,9 @@ type IRPCRequests = {
264
267
  calls: IRPCRequest[];
265
268
  credentials?: IRPCCredentials;
266
269
  };
267
- type IRPCError = {
268
- code: ErrorCode;
270
+ type IRPCPacketError = {
271
+ type: string;
272
+ code: string;
269
273
  message: string;
270
274
  };
271
275
  /**
@@ -277,7 +281,7 @@ type IRPCResponse = {
277
281
  /** Name of the RPC function that was called */
278
282
  name: string;
279
283
  /** Error message if the call failed */
280
- error?: IRPCError;
284
+ error?: IRPCPacketError;
281
285
  /** Result of the RPC call if successful */
282
286
  result?: unknown;
283
287
  };
@@ -310,8 +314,6 @@ type IRPCCallConfig = {
310
314
  retryMode?: 'linear' | 'exponential';
311
315
  /** Base delay between retries in milliseconds */
312
316
  retryDelay?: number;
313
- /** Optional initialization function for a stream RPC */
314
- init?: () => unknown;
315
317
  };
316
318
  /**
317
319
  * Configuration for transport layer, extending call configuration with debounce settings.
@@ -333,4 +335,4 @@ type StreamCleanup = () => void;
333
335
  */
334
336
  type StreamConstructor<T> = (state: IRPCReadable<T>, resolve: (value?: T) => void, reject: (error: Error) => void) => StreamCleanup | void | Promise<StreamCleanup | void>;
335
337
  //#endregion
336
- export { IRPCArraySchema, IRPCBaseContext, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDataType, IRPCDeclareInit, IRPCError, IRPCFunction, IRPCHandler, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig };
338
+ export { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCDataSchema, IRPCDeclareInit, IRPCDefined, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInit, IRPCInputs, IRPCObject, IRPCObjectSchema, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCPacketAnswer, IRPCPacketBase, IRPCPacketCall, IRPCPacketClose, IRPCPacketError, IRPCPacketEvent, IRPCPacketStream, IRPCPacketType, IRPCParseResult, IRPCPayload, IRPCPrimitive, IRPCPrimitiveSchema, IRPCReadable, IRPCRequest, IRPCRequests, IRPCResponse, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, 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.24",
4
+ "version": "1.0.0-beta.25",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
7
7
  "exports": {
@@ -14,7 +14,9 @@
14
14
  "import": "./dist/server/index.js"
15
15
  }
16
16
  },
17
- "files": ["dist"],
17
+ "files": [
18
+ "dist"
19
+ ],
18
20
  "directories": {
19
21
  "dist": "./dist"
20
22
  },
@@ -50,6 +52,6 @@
50
52
  },
51
53
  "license": "MIT",
52
54
  "dependencies": {
53
- "@anchorlib/core": "^1.0.0-beta.24"
55
+ "@anchorlib/core": "^1.0.0-beta.25"
54
56
  }
55
- }
57
+ }