@irpclib/irpc 1.0.0-beta.24 → 1.0.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/dist/adapter.d.ts +76 -0
- package/dist/adapter.js +109 -0
- package/dist/call.d.ts +6 -2
- package/dist/call.js +5 -8
- package/dist/enum.d.ts +1 -10
- package/dist/enum.js +2 -11
- package/dist/error.d.ts +124 -58
- package/dist/error.js +224 -55
- package/dist/index.d.ts +8 -7
- package/dist/index.js +5 -3
- package/dist/module.d.ts +53 -12
- package/dist/module.js +91 -41
- package/dist/reader.js +3 -2
- package/dist/resolver.d.ts +1 -1
- package/dist/resolver.js +7 -25
- package/dist/router.d.ts +3 -6
- package/dist/router.js +3 -6
- package/dist/state.d.ts +37 -5
- package/dist/state.js +44 -7
- package/dist/store.d.ts +2 -2
- package/dist/stream.d.ts +3 -3
- package/dist/stream.js +4 -13
- package/dist/transport.d.ts +3 -3
- package/dist/transport.js +2 -5
- package/dist/types.d.ts +101 -17
- package/dist/types.js +8 -1
- package/package.json +6 -4
package/dist/error.js
CHANGED
|
@@ -1,61 +1,230 @@
|
|
|
1
1
|
//#region src/error.ts
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const IRPC_ERROR_TYPE = {
|
|
3
|
+
STUB: "stub",
|
|
4
|
+
HOOK: "hook",
|
|
5
|
+
CALL: "call",
|
|
6
|
+
CRUD: "crud",
|
|
7
|
+
HANDLER: "handler",
|
|
8
|
+
RESOLVE: "resolve",
|
|
9
|
+
TRANSPORT: "transport"
|
|
10
|
+
};
|
|
11
|
+
const STUB_ERROR = {
|
|
12
|
+
DUPLICATE: "duplicate",
|
|
13
|
+
INVALID: "invalid",
|
|
5
14
|
NOT_FOUND: "not_found",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
INVALID_NAME: "invalid_name",
|
|
16
|
+
INVALID_VERSION: "invalid_version"
|
|
17
|
+
};
|
|
18
|
+
const HANDLER_ERROR = {
|
|
19
|
+
INVALID: "invalid",
|
|
20
|
+
MISSING: "missing",
|
|
21
|
+
ERROR: "error"
|
|
22
|
+
};
|
|
23
|
+
const TRANSPORT_ERROR = {
|
|
24
|
+
INVALID: "invalid",
|
|
25
|
+
MISSING: "missing",
|
|
12
26
|
NOT_IMPLEMENTED: "not_implemented",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
NOT_CONNECTED: "not_connected",
|
|
28
|
+
CLOSED: "closed",
|
|
29
|
+
INVALID_BODY: "invalid_body",
|
|
30
|
+
STREAM_TERMINATED: "stream_terminated",
|
|
31
|
+
ERROR: "error"
|
|
32
|
+
};
|
|
33
|
+
const RESOLVE_ERROR = {
|
|
34
|
+
NOT_FOUND: "not_found",
|
|
35
|
+
INVALID_INPUT: "invalid_input",
|
|
36
|
+
INVALID_OUTPUT: "invalid_output",
|
|
37
|
+
ERROR: "error"
|
|
38
|
+
};
|
|
39
|
+
const HOOK_ERROR = {
|
|
40
|
+
INVALID: "invalid",
|
|
41
|
+
ERROR: "error"
|
|
42
|
+
};
|
|
43
|
+
const CALL_ERROR = {
|
|
44
|
+
TIMEOUT: "timeout",
|
|
45
|
+
MAX_RETRIES: "max_retries",
|
|
46
|
+
STREAM_ERROR: "stream_error"
|
|
47
|
+
};
|
|
48
|
+
const CRUD_ERROR = {
|
|
49
|
+
NOT_FOUND: "not_found",
|
|
50
|
+
NOT_IMPLEMENTED: "not_implemented"
|
|
51
|
+
};
|
|
52
|
+
function unwrap(input) {
|
|
53
|
+
if (input instanceof Error) return {
|
|
54
|
+
message: input.message,
|
|
55
|
+
cause: input
|
|
56
|
+
};
|
|
57
|
+
return { message: input };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Base error class for all IRPC errors.
|
|
61
|
+
*
|
|
62
|
+
* @property type - The domain category of the error (stub, handler, transport, etc.)
|
|
63
|
+
* @property code - A stable, machine-readable code for translation or programmatic matching.
|
|
64
|
+
*/
|
|
65
|
+
var IRPCError = class IRPCError extends Error {
|
|
66
|
+
constructor(type, code, message, cause) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.type = type;
|
|
69
|
+
this.code = code;
|
|
70
|
+
this.cause = cause;
|
|
71
|
+
}
|
|
72
|
+
/** Serialize to the wire format used in IRPC packets. */
|
|
73
|
+
json() {
|
|
74
|
+
return {
|
|
75
|
+
type: this.type,
|
|
76
|
+
code: this.code,
|
|
77
|
+
message: this.message
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Reconstruct an IRPCError from a wire packet error. */
|
|
81
|
+
static from(obj) {
|
|
82
|
+
const ErrorClass = IRPC_ERROR_CLASS[obj.type];
|
|
83
|
+
if (ErrorClass) return new ErrorClass(obj.code, obj.message);
|
|
84
|
+
return new IRPCError(obj.type, obj.code, obj.message);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
/** Errors related to stub declaration, registration, and lookup. */
|
|
88
|
+
var StubError = class StubError extends IRPCError {
|
|
89
|
+
constructor(code, message, cause) {
|
|
90
|
+
super(IRPC_ERROR_TYPE.STUB, code, message, cause);
|
|
91
|
+
}
|
|
92
|
+
static duplicate(name) {
|
|
93
|
+
return new StubError(STUB_ERROR.DUPLICATE, `IRPC "${name}" already exists.`);
|
|
94
|
+
}
|
|
95
|
+
static invalid() {
|
|
96
|
+
return new StubError(STUB_ERROR.INVALID, "Invalid stub.");
|
|
97
|
+
}
|
|
98
|
+
static notFound() {
|
|
99
|
+
return new StubError(STUB_ERROR.NOT_FOUND, "No spec found for stub.");
|
|
100
|
+
}
|
|
101
|
+
static invalidName(name) {
|
|
102
|
+
return new StubError(STUB_ERROR.INVALID_NAME, `Invalid name: ${name}`);
|
|
103
|
+
}
|
|
104
|
+
static invalidVersion(version) {
|
|
105
|
+
return new StubError(STUB_ERROR.INVALID_VERSION, `Invalid version: ${version}`);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/** Errors related to handler registration and execution. */
|
|
109
|
+
var HandlerError = class HandlerError extends IRPCError {
|
|
110
|
+
constructor(code, message, cause) {
|
|
111
|
+
super(IRPC_ERROR_TYPE.HANDLER, code, message, cause);
|
|
112
|
+
}
|
|
113
|
+
static invalid() {
|
|
114
|
+
return new HandlerError(HANDLER_ERROR.INVALID, "Handler must be a function.");
|
|
115
|
+
}
|
|
116
|
+
static missing(name) {
|
|
117
|
+
return new HandlerError(HANDLER_ERROR.MISSING, `IRPC "${name}" has no implementation.`);
|
|
118
|
+
}
|
|
119
|
+
static failed(input) {
|
|
120
|
+
const { message, cause } = unwrap(input);
|
|
121
|
+
return new HandlerError(HANDLER_ERROR.ERROR, message, cause);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/** Errors related to the transport layer. */
|
|
125
|
+
var TransportError = class TransportError extends IRPCError {
|
|
126
|
+
constructor(code, message, cause) {
|
|
127
|
+
super(IRPC_ERROR_TYPE.TRANSPORT, code, message, cause);
|
|
128
|
+
}
|
|
129
|
+
static missing() {
|
|
130
|
+
return new TransportError(TRANSPORT_ERROR.MISSING, "No transport configured.");
|
|
131
|
+
}
|
|
132
|
+
static invalid() {
|
|
133
|
+
return new TransportError(TRANSPORT_ERROR.INVALID, "Invalid transport.");
|
|
134
|
+
}
|
|
135
|
+
static notImplemented() {
|
|
136
|
+
return new TransportError(TRANSPORT_ERROR.NOT_IMPLEMENTED, "Transport dispatch not implemented.");
|
|
137
|
+
}
|
|
138
|
+
static notConnected(name) {
|
|
139
|
+
return new TransportError(TRANSPORT_ERROR.NOT_CONNECTED, `${name} is not connected.`);
|
|
140
|
+
}
|
|
141
|
+
static closed(name) {
|
|
142
|
+
return new TransportError(TRANSPORT_ERROR.CLOSED, `${name} connection closed.`);
|
|
143
|
+
}
|
|
144
|
+
static invalidBody() {
|
|
145
|
+
return new TransportError(TRANSPORT_ERROR.INVALID_BODY, "Invalid response body.");
|
|
146
|
+
}
|
|
147
|
+
static streamTerminated() {
|
|
148
|
+
return new TransportError(TRANSPORT_ERROR.STREAM_TERMINATED, "Response stream terminated.");
|
|
149
|
+
}
|
|
150
|
+
static failed(input) {
|
|
151
|
+
const { message, cause } = unwrap(input);
|
|
152
|
+
return new TransportError(TRANSPORT_ERROR.ERROR, message, cause);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
/** Errors related to server-side request resolution. */
|
|
156
|
+
var ResolveError = class ResolveError extends IRPCError {
|
|
157
|
+
constructor(code, message, cause) {
|
|
158
|
+
super(IRPC_ERROR_TYPE.RESOLVE, code, message, cause);
|
|
159
|
+
}
|
|
160
|
+
static notFound(name) {
|
|
161
|
+
return new ResolveError(RESOLVE_ERROR.NOT_FOUND, `IRPC "${name}" does not exist.`);
|
|
162
|
+
}
|
|
163
|
+
static invalidInput(input) {
|
|
164
|
+
const { message, cause } = unwrap(input);
|
|
165
|
+
return new ResolveError(RESOLVE_ERROR.INVALID_INPUT, message, cause);
|
|
166
|
+
}
|
|
167
|
+
static invalidOutput(input) {
|
|
168
|
+
if (!input) return new ResolveError(RESOLVE_ERROR.INVALID_OUTPUT, "Invalid output.");
|
|
169
|
+
const { message, cause } = unwrap(input);
|
|
170
|
+
return new ResolveError(RESOLVE_ERROR.INVALID_OUTPUT, message, cause);
|
|
171
|
+
}
|
|
172
|
+
static failed(input) {
|
|
173
|
+
const { message, cause } = unwrap(input);
|
|
174
|
+
return new ResolveError(RESOLVE_ERROR.ERROR, message, cause);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
/** Errors related to hook registration and execution. */
|
|
178
|
+
var HookError = class HookError extends IRPCError {
|
|
179
|
+
constructor(code, message, cause) {
|
|
180
|
+
super(IRPC_ERROR_TYPE.HOOK, code, message, cause);
|
|
181
|
+
}
|
|
182
|
+
static invalid() {
|
|
183
|
+
return new HookError(HOOK_ERROR.INVALID, "Hook must be a function.");
|
|
184
|
+
}
|
|
185
|
+
static failed(input) {
|
|
186
|
+
const { message, cause } = unwrap(input);
|
|
187
|
+
return new HookError(HOOK_ERROR.ERROR, message, cause);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/** Errors related to call execution lifecycle. */
|
|
191
|
+
var CallError = class CallError extends IRPCError {
|
|
192
|
+
constructor(code, message, cause) {
|
|
193
|
+
super(IRPC_ERROR_TYPE.CALL, code, message, cause);
|
|
194
|
+
}
|
|
195
|
+
static timeout() {
|
|
196
|
+
return new CallError(CALL_ERROR.TIMEOUT, "Call timed out.");
|
|
197
|
+
}
|
|
198
|
+
static maxRetries(reasons) {
|
|
199
|
+
const detail = Array.from(reasons).map((r) => r.message).join(", ");
|
|
200
|
+
return new CallError(CALL_ERROR.MAX_RETRIES, `Max retries reached: ${detail}`);
|
|
201
|
+
}
|
|
202
|
+
static streamError(input) {
|
|
203
|
+
const { message, cause } = unwrap(input);
|
|
204
|
+
return new CallError(CALL_ERROR.STREAM_ERROR, message, cause);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
/** Errors related to CRUD adapter operations. */
|
|
208
|
+
var CrudError = class CrudError extends IRPCError {
|
|
209
|
+
constructor(code, message, cause) {
|
|
210
|
+
super(IRPC_ERROR_TYPE.CRUD, code, message, cause);
|
|
211
|
+
}
|
|
212
|
+
static notFound() {
|
|
213
|
+
return new CrudError(CRUD_ERROR.NOT_FOUND, "Unknown CRUD instance — was it created with pkg.crud()?");
|
|
214
|
+
}
|
|
215
|
+
static notImplemented(method) {
|
|
216
|
+
return new CrudError(CRUD_ERROR.NOT_IMPLEMENTED, `CRUD method "${method}" not implemented.`);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
const IRPC_ERROR_CLASS = {
|
|
220
|
+
[IRPC_ERROR_TYPE.STUB]: StubError,
|
|
221
|
+
[IRPC_ERROR_TYPE.HANDLER]: HandlerError,
|
|
222
|
+
[IRPC_ERROR_TYPE.TRANSPORT]: TransportError,
|
|
223
|
+
[IRPC_ERROR_TYPE.RESOLVE]: ResolveError,
|
|
224
|
+
[IRPC_ERROR_TYPE.HOOK]: HookError,
|
|
225
|
+
[IRPC_ERROR_TYPE.CALL]: CallError,
|
|
226
|
+
[IRPC_ERROR_TYPE.CRUD]: CrudError
|
|
58
227
|
};
|
|
59
228
|
|
|
60
229
|
//#endregion
|
|
61
|
-
export {
|
|
230
|
+
export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, 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,20 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
1
|
+
import { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
|
|
4
2
|
import { IRPCFile, IRPCFileMeta, IRPCFilePipe, IRPCFileState, IRPCFileStatus, IRPCFileStream, IRPCFileUnpipe } from "./file.js";
|
|
5
3
|
import { IRPCFilePointer, IRPCFileQueue, IRPCPacketJson, IRPCPacketQueues, IRPC_FILE_IDENTIFIER, PacketStream, decode, encode, isFilePointer } from "./packet.js";
|
|
6
|
-
import {
|
|
4
|
+
import { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, IRPCCall } from "./call.js";
|
|
7
5
|
import { IRPCTransport } from "./transport.js";
|
|
8
|
-
import { IRPCArraySchema,
|
|
6
|
+
import { IRPCArraySchema, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCCrudField, IRPCCrudMeta, IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDataSchema, IRPCDeclareConfig, IRPCDeclareInit, IRPCDefined, IRPCDriver, IRPCEntityId, 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, IRPCReturnOf, IRPCSchema, IRPCSpec, IRPCSpecStore, IRPCStatus, IRPCStreamInit, IRPCStub, IRPCStubStore, StreamCleanup, StreamConstructor, TransportConfig } from "./types.js";
|
|
9
7
|
import { RemoteState, stream } from "./state.js";
|
|
10
8
|
import { IRPCReader } from "./reader.js";
|
|
11
|
-
import {
|
|
9
|
+
import { IRPCHookArgs, IRPCPackage, IRPCSpecHook, createPackage, intercept } from "./module.js";
|
|
10
|
+
import { IRPCAdapter } from "./adapter.js";
|
|
11
|
+
import { IRPCCacheEntry, IRPCCacher } from "./cache.js";
|
|
12
12
|
import { createContext, createContextStore, getAbortController, getAbortSignal, getContext, setContext, setContextProvider, withContext } from "./context.js";
|
|
13
13
|
import { createCredentials, credential, getCredentials } from "./credential.js";
|
|
14
|
+
import { CALL_ERROR, CRUD_ERROR, CallError, CrudError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPCErrorType, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
|
|
14
15
|
import { IRPCResolver } from "./resolver.js";
|
|
15
16
|
import { IRPCHook, IRPCRouter } from "./router.js";
|
|
16
17
|
import { IRPCStream } from "./stream.js";
|
|
17
18
|
import { IRPCStore, IRPCStoreEvent, IRPCStoreSubscriber, IRPC_STORE } from "./store.js";
|
|
18
19
|
import { plan } from "@anchorlib/core";
|
|
19
|
-
export { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE,
|
|
20
|
+
export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCAdapter, IRPCArraySchema, IRPCCacheEntry, IRPCCacher, IRPCCall, IRPCCallConfig, IRPCContext, IRPCContextProvider, IRPCCredentials, IRPCCredentialsFactory, IRPCCrudField, IRPCCrudMeta, IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDataSchema, IRPCDeclareConfig, IRPCDeclareInit, IRPCDefined, IRPCDriver, IRPCEntityId, 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, IRPCReturnOf, 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,7 @@
|
|
|
1
|
+
import { CALL_ERROR, CRUD_ERROR, CallError, CrudError, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCError, IRPC_ERROR_TYPE, RESOLVE_ERROR, ResolveError, STUB_ERROR, StubError, TRANSPORT_ERROR, TransportError } from "./error.js";
|
|
2
|
+
import { IRPCAdapter } from "./adapter.js";
|
|
1
3
|
import { IRPCCacher } from "./cache.js";
|
|
2
|
-
import { IRPC_BASE_CONTEXT,
|
|
3
|
-
import { ERROR_CODE, ERROR_MESSAGE } from "./error.js";
|
|
4
|
+
import { IRPC_BASE_CONTEXT, IRPC_FILE_STATUS, IRPC_PACKET_TYPE, IRPC_STATUS, IRPC_STORE_EVENT } from "./enum.js";
|
|
4
5
|
import { createContext, createContextStore, getAbortController, getAbortSignal, getContext, setContext, setContextProvider, withContext } from "./context.js";
|
|
5
6
|
import { RemoteState, stream } from "./state.js";
|
|
6
7
|
import { IRPCReader } from "./reader.js";
|
|
@@ -14,6 +15,7 @@ import { createCredentials, credential, getCredentials } from "./credential.js";
|
|
|
14
15
|
import { IRPCFile, IRPCFileStream } from "./file.js";
|
|
15
16
|
import { IRPC_FILE_IDENTIFIER, decode, encode, isFilePointer } from "./packet.js";
|
|
16
17
|
import { IRPCResolver } from "./resolver.js";
|
|
18
|
+
import { IRPCDriver } from "./types.js";
|
|
17
19
|
import { plan } from "@anchorlib/core";
|
|
18
20
|
|
|
19
|
-
export { DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE,
|
|
21
|
+
export { CALL_ERROR, CRUD_ERROR, CallError, CrudError, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_MODE, HANDLER_ERROR, HOOK_ERROR, HandlerError, HookError, IRPCAdapter, IRPCCacher, IRPCCall, IRPCDriver, 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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IRPCTransport } from "./transport.js";
|
|
2
|
-
import { IRPCData, IRPCDeclareInit, IRPCFunction, IRPCHandler, IRPCInputs, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCRequest, IRPCSpec, IRPCStub } from "./types.js";
|
|
2
|
+
import { IRPCCrudMethod, IRPCCrudOptions, IRPCCrudStubs, IRPCData, IRPCDeclareConfig, IRPCDeclareInit, IRPCFunction, IRPCHandler, IRPCInferInit, IRPCInputs, IRPCObject, IRPCOutput, IRPCPackageConfig, IRPCPackageInfo, IRPCRequest, IRPCReturnOf, IRPCSpec, IRPCStub } from "./types.js";
|
|
3
3
|
import { RemoteState } from "./state.js";
|
|
4
4
|
import { IRPCReader } from "./reader.js";
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ type IRPCSpecHook<F$1> = (req: IRPCHookArgs<F$1>) => void | Promise<void>;
|
|
|
17
17
|
* and their corresponding stubs. It manages the configuration, transport, and execution
|
|
18
18
|
* of remote procedure calls.
|
|
19
19
|
*/
|
|
20
|
-
declare class IRPCPackage {
|
|
20
|
+
declare class IRPCPackage<K extends string = 'id'> {
|
|
21
21
|
/**
|
|
22
22
|
* A map storing all IRPC specifications by their names
|
|
23
23
|
*/
|
|
@@ -54,12 +54,47 @@ declare class IRPCPackage {
|
|
|
54
54
|
*/
|
|
55
55
|
constructor(config?: Partial<IRPCPackageConfig>);
|
|
56
56
|
/**
|
|
57
|
-
* Declares a new IRPC specification and
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
* @
|
|
57
|
+
* Declares a new IRPC specification and returns a callable stub.
|
|
58
|
+
*
|
|
59
|
+
* @param name - The unique name for the IRPC specification.
|
|
60
|
+
* @param seed - Factory function returning the initial data value.
|
|
61
|
+
* @param config - Optional configuration (description, schema, caching, etc).
|
|
62
|
+
* @returns A stub function that can be used to call the IRPC.
|
|
63
|
+
* @throws Error if an IRPC with the same name already exists.
|
|
64
|
+
*/
|
|
65
|
+
declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(name: string, seed: () => IRPCReturnOf<F>, config?: IRPCDeclareConfig<I, O>): IRPCFunction<F>;
|
|
66
|
+
/**
|
|
67
|
+
* Declares a new IRPC specification and returns a callable stub.
|
|
68
|
+
*
|
|
69
|
+
* @param name - The unique name for the IRPC specification.
|
|
70
|
+
* @param config - Configuration object including seed and optional fields.
|
|
71
|
+
* @returns A stub function that can be used to call the IRPC.
|
|
72
|
+
* @throws Error if an IRPC with the same name already exists.
|
|
73
|
+
*/
|
|
74
|
+
declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(name: string, config: IRPCDeclareConfig<I, O> & IRPCInferInit<IRPCReturnOf<F>>): IRPCFunction<F>;
|
|
75
|
+
/**
|
|
76
|
+
* Declares a new IRPC specification and returns a callable stub.
|
|
77
|
+
*
|
|
78
|
+
* @param options - The initialization object containing name, seed, and configuration.
|
|
79
|
+
* @returns A stub function that can be used to call the IRPC.
|
|
80
|
+
* @throws Error if an IRPC with the same name already exists.
|
|
61
81
|
*/
|
|
62
82
|
declare<F, I extends IRPCInputs = IRPCInputs, O extends IRPCOutput = IRPCOutput>(options: IRPCDeclareInit<F, I, O>): IRPCFunction<F>;
|
|
83
|
+
/**
|
|
84
|
+
* Declares CRUD stubs (get, create, update, delete) for an entity
|
|
85
|
+
* @param name - The entity name used as prefix for stub names
|
|
86
|
+
* @param seed - Factory function returning a default entity instance
|
|
87
|
+
* @param options - Optional configuration for caching, schemas, and call behavior
|
|
88
|
+
* @returns An object containing the four CRUD stub functions
|
|
89
|
+
*/
|
|
90
|
+
crud<T extends IRPCObject, I extends IRPCObject = T, U extends IRPCObject = T, CK extends string = K>(name: string, seed: () => T, options?: IRPCCrudOptions): IRPCCrudStubs<T, CK, I, U>;
|
|
91
|
+
/**
|
|
92
|
+
* Removes CRUD methods from a stubs object and unregisters their specs
|
|
93
|
+
* @param stubs - The CRUD stubs object to modify
|
|
94
|
+
* @param keys - The method names to remove
|
|
95
|
+
* @returns The stubs object without the excluded methods
|
|
96
|
+
*/
|
|
97
|
+
exclude<S extends object, E extends IRPCCrudMethod>(stubs: S, keys: E[]): Omit<S, E>;
|
|
63
98
|
/**
|
|
64
99
|
* Resolves and executes an IRPC call based on a request object
|
|
65
100
|
* @param req - The request containing the IRPC name and arguments
|
|
@@ -76,13 +111,17 @@ declare class IRPCPackage {
|
|
|
76
111
|
*/
|
|
77
112
|
construct<F, A extends unknown[], R extends IRPCData>(stub: IRPCStub<F, A, R>, handler: F): this;
|
|
78
113
|
/**
|
|
79
|
-
* Registers a hook
|
|
80
|
-
* @param stub - The stub function created by declare()
|
|
81
|
-
* @param handler - The hook function to register
|
|
82
|
-
* @returns This IRPCPackage instance for chaining
|
|
83
|
-
* @throws Error if the stub is invalid or if no IRPC exists for the stub
|
|
114
|
+
* Registers a hook for a specific stub.
|
|
115
|
+
* @param stub - The stub function created by declare().
|
|
116
|
+
* @param handler - The hook function to register.
|
|
84
117
|
*/
|
|
85
118
|
hook<F extends IRPCHandler>(stub: F, handler: IRPCSpecHook<F>): this;
|
|
119
|
+
/**
|
|
120
|
+
* Registers a hook for all stubs in a group (e.g., CRUD).
|
|
121
|
+
* @param stubs - An object whose values are stub functions.
|
|
122
|
+
* @param handler - The hook function to register.
|
|
123
|
+
*/
|
|
124
|
+
hook(stubs: Record<string, IRPCHandler>, handler: IRPCSpecHook<IRPCHandler>): this;
|
|
86
125
|
/**
|
|
87
126
|
* Resolves and executes all registered hooks for a given request
|
|
88
127
|
* @param req - The request containing the IRPC name and arguments
|
|
@@ -122,7 +161,9 @@ declare class IRPCPackage {
|
|
|
122
161
|
* @param config - Optional partial configuration for the package
|
|
123
162
|
* @returns A new IRPCPackage instance
|
|
124
163
|
*/
|
|
125
|
-
declare function createPackage(config?: Partial<IRPCPackageConfig>
|
|
164
|
+
declare function createPackage<K extends string = 'id'>(config?: Partial<IRPCPackageConfig> & {
|
|
165
|
+
key?: K;
|
|
166
|
+
}): IRPCPackage<K>;
|
|
126
167
|
/**
|
|
127
168
|
* Intercepts local function call to get an instant response without remote execution.
|
|
128
169
|
*
|