@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/transport.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IRPCCall } from "./call.js";
|
|
2
2
|
import { IRPCCallConfig, IRPCCredentials, IRPCCredentialsFactory, IRPCData, IRPCInputs, IRPCOutput, IRPCSpec, TransportConfig } from "./types.js";
|
|
3
3
|
import { IRPCReader } from "./reader.js";
|
|
4
|
-
import {
|
|
4
|
+
import { IRPCPackage } from "./module.js";
|
|
5
5
|
|
|
6
6
|
//#region src/transport.d.ts
|
|
7
7
|
|
|
@@ -12,7 +12,7 @@ import { IRPCCall } from "./call.js";
|
|
|
12
12
|
declare class IRPCTransport {
|
|
13
13
|
#private;
|
|
14
14
|
config?: TransportConfig | undefined;
|
|
15
|
-
modules: Set<IRPCPackage
|
|
15
|
+
modules: Set<IRPCPackage<"id">>;
|
|
16
16
|
/**
|
|
17
17
|
* A set of pending RPC calls that are queued for execution.
|
|
18
18
|
*/
|
package/dist/transport.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { TransportError } from "./error.js";
|
|
1
2
|
import { IRPC_PACKET_TYPE, IRPC_STATUS } from "./enum.js";
|
|
2
|
-
import { ERROR_CODE, ERROR_MESSAGE } 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 {
|
|
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?:
|
|
37
|
+
error?: IRPCPacketError;
|
|
41
38
|
};
|
|
42
39
|
type IRPCPacketEvent = IRPCPacketBase & {
|
|
43
40
|
data: StateChange;
|
|
44
41
|
};
|
|
45
42
|
type IRPCPacketClose = IRPCPacketBase & {
|
|
46
|
-
error?:
|
|
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
|
*/
|
|
@@ -158,6 +160,8 @@ type IRPCPackageInfo = {
|
|
|
158
160
|
description?: string;
|
|
159
161
|
};
|
|
160
162
|
type IRPCPackageConfig = IRPCPackageInfo & IRPCCallConfig & {
|
|
163
|
+
/** Primary key field name for CRUD operations. Defaults to 'id'. */
|
|
164
|
+
key?: string;
|
|
161
165
|
transport?: IRPCTransport;
|
|
162
166
|
};
|
|
163
167
|
/**
|
|
@@ -206,8 +210,33 @@ type IRPCInit<R$1, I extends IRPCInputs, O$1 extends IRPCOutput> = {
|
|
|
206
210
|
* This can help reduce the number of actual function executions.
|
|
207
211
|
*/
|
|
208
212
|
coalesce?: boolean;
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
} & IRPCCallConfig & IRPCInferInit<R$1>;
|
|
214
|
+
type IRPCInferInit<R$1> = R$1 extends IRPCDefined ? {
|
|
215
|
+
seed: () => R$1;
|
|
216
|
+
} : {
|
|
217
|
+
seed?: () => R$1;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Extracts the data type from a function's return type by unwrapping
|
|
221
|
+
* RemoteState and Promise wrappers.
|
|
222
|
+
*
|
|
223
|
+
* @template F - The function type to extract from.
|
|
224
|
+
*/
|
|
225
|
+
type IRPCReturnOf<F> = F extends ((...args: infer _A) => infer R) ? R extends RemoteState<infer S> ? S : R extends Promise<infer D> ? D : R : IRPCData;
|
|
226
|
+
/**
|
|
227
|
+
* Configuration options for the shorthand `declare(name, seed, config?)` overload.
|
|
228
|
+
* Contains all IRPCInit fields except `name` and `seed`.
|
|
229
|
+
*
|
|
230
|
+
* @template I - Tuple of input validation schemas
|
|
231
|
+
* @template O - Output validation schema
|
|
232
|
+
*/
|
|
233
|
+
type IRPCDeclareConfig<I extends IRPCInputs = IRPCInputs, O$1 extends IRPCOutput = IRPCOutput> = {
|
|
234
|
+
description?: string;
|
|
235
|
+
schema?: IRPCSchema<I, O$1>;
|
|
236
|
+
maxAge?: number;
|
|
237
|
+
coalesce?: boolean;
|
|
238
|
+
stream?: true;
|
|
239
|
+
ttl?: number;
|
|
211
240
|
} & IRPCCallConfig;
|
|
212
241
|
/**
|
|
213
242
|
* Configuration options for initializing an RPC stream function.
|
|
@@ -228,7 +257,65 @@ type IRPCStreamInit<I extends IRPCInputs, O$1 extends IRPCOutput, R$1> = IRPCIni
|
|
|
228
257
|
* @template I - Tuple of input validation schemas
|
|
229
258
|
* @template O - Output validation schema
|
|
230
259
|
*/
|
|
231
|
-
type IRPCDeclareInit<F, I extends IRPCInputs, O$1 extends IRPCOutput> = F extends ((...args:
|
|
260
|
+
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>;
|
|
261
|
+
type IRPCCrudMethod = 'get' | 'create' | 'update' | 'delete';
|
|
262
|
+
/**
|
|
263
|
+
* Discriminated field — shared value or per-operation values.
|
|
264
|
+
*/
|
|
265
|
+
type IRPCCrudField<T> = T | {
|
|
266
|
+
get?: T;
|
|
267
|
+
create?: T;
|
|
268
|
+
update?: T;
|
|
269
|
+
delete?: T;
|
|
270
|
+
};
|
|
271
|
+
type IRPCCrudOptions = {
|
|
272
|
+
description?: IRPCCrudField<string>;
|
|
273
|
+
schema?: {
|
|
274
|
+
get?: IRPCSchema<IRPCInputs, IRPCOutput>;
|
|
275
|
+
create?: IRPCSchema<IRPCInputs, IRPCOutput>;
|
|
276
|
+
update?: IRPCSchema<IRPCInputs, IRPCOutput>;
|
|
277
|
+
delete?: IRPCSchema<IRPCInputs, IRPCOutput>;
|
|
278
|
+
};
|
|
279
|
+
/** Cache max age — only applied to get. */
|
|
280
|
+
maxAge?: number;
|
|
281
|
+
coalesce?: boolean;
|
|
282
|
+
} & IRPCCallConfig;
|
|
283
|
+
/**
|
|
284
|
+
* ID type extracted from entity using the key field.
|
|
285
|
+
* Falls back to string if the key doesn't exist on the entity.
|
|
286
|
+
*/
|
|
287
|
+
type IRPCEntityId<T, K$1 extends string> = K$1 extends keyof T ? T[K$1] : string;
|
|
288
|
+
type IRPCCrudStubs<T extends IRPCObject, K$1 extends string, I extends IRPCObject = T, U extends IRPCObject = T> = {
|
|
289
|
+
get: IRPCFunction<(id: IRPCEntityId<T, K$1>) => Promise<T> | RemoteState<T>>;
|
|
290
|
+
create: IRPCFunction<(data: I) => Promise<T> | RemoteState<T>>;
|
|
291
|
+
update: IRPCFunction<(id: IRPCEntityId<T, K$1>, data: U) => Promise<T> | RemoteState<T>>;
|
|
292
|
+
delete: IRPCFunction<(id: IRPCEntityId<T, K$1>) => Promise<T> | RemoteState<T>>;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Per-method resolved metadata — discriminated fields flattened,
|
|
296
|
+
* method-specific options applied. Passed to driver on every call.
|
|
297
|
+
*/
|
|
298
|
+
type IRPCCrudMeta = {
|
|
299
|
+
/** Entity/table name. */
|
|
300
|
+
name: string;
|
|
301
|
+
/** Primary key field name. */
|
|
302
|
+
key: string;
|
|
303
|
+
/** Resolved description for this method. */
|
|
304
|
+
description?: string;
|
|
305
|
+
/** Resolved schema for this method. */
|
|
306
|
+
schema?: IRPCSchema<IRPCInputs, IRPCOutput>;
|
|
307
|
+
maxAge?: number;
|
|
308
|
+
coalesce?: boolean;
|
|
309
|
+
} & IRPCCallConfig;
|
|
310
|
+
/**
|
|
311
|
+
* Base class for CRUD drivers that receive per-method resolved metadata on every call
|
|
312
|
+
*/
|
|
313
|
+
declare abstract class IRPCDriver {
|
|
314
|
+
get?(meta: IRPCCrudMeta, id: IRPCData): Promise<IRPCData> | IRPCData;
|
|
315
|
+
create?(meta: IRPCCrudMeta, data: IRPCData): Promise<IRPCData> | IRPCData;
|
|
316
|
+
update?(meta: IRPCCrudMeta, id: IRPCData, data: IRPCData): Promise<IRPCData> | IRPCData;
|
|
317
|
+
delete?(meta: IRPCCrudMeta, id: IRPCData): Promise<IRPCData> | IRPCData;
|
|
318
|
+
}
|
|
232
319
|
/**
|
|
233
320
|
* Complete specification for an RPC function including its implementation.
|
|
234
321
|
* Extends IRPCInit with the actual handler function.
|
|
@@ -243,8 +330,6 @@ type IRPCSpec<I extends IRPCInputs, O$1 extends IRPCOutput> = IRPCInit<IRPCData,
|
|
|
243
330
|
stream?: boolean;
|
|
244
331
|
/** The actual handler function that implements the RPC */
|
|
245
332
|
handler: IRPCHandler;
|
|
246
|
-
/** Optional initialization function for a stream RPC */
|
|
247
|
-
init?: () => unknown;
|
|
248
333
|
};
|
|
249
334
|
/**
|
|
250
335
|
* Represents an incoming RPC request.
|
|
@@ -264,8 +349,9 @@ type IRPCRequests = {
|
|
|
264
349
|
calls: IRPCRequest[];
|
|
265
350
|
credentials?: IRPCCredentials;
|
|
266
351
|
};
|
|
267
|
-
type
|
|
268
|
-
|
|
352
|
+
type IRPCPacketError = {
|
|
353
|
+
type: string;
|
|
354
|
+
code: string;
|
|
269
355
|
message: string;
|
|
270
356
|
};
|
|
271
357
|
/**
|
|
@@ -277,7 +363,7 @@ type IRPCResponse = {
|
|
|
277
363
|
/** Name of the RPC function that was called */
|
|
278
364
|
name: string;
|
|
279
365
|
/** Error message if the call failed */
|
|
280
|
-
error?:
|
|
366
|
+
error?: IRPCPacketError;
|
|
281
367
|
/** Result of the RPC call if successful */
|
|
282
368
|
result?: unknown;
|
|
283
369
|
};
|
|
@@ -310,8 +396,6 @@ type IRPCCallConfig = {
|
|
|
310
396
|
retryMode?: 'linear' | 'exponential';
|
|
311
397
|
/** Base delay between retries in milliseconds */
|
|
312
398
|
retryDelay?: number;
|
|
313
|
-
/** Optional initialization function for a stream RPC */
|
|
314
|
-
init?: () => unknown;
|
|
315
399
|
};
|
|
316
400
|
/**
|
|
317
401
|
* Configuration for transport layer, extending call configuration with debounce settings.
|
|
@@ -333,4 +417,4 @@ type StreamCleanup = () => void;
|
|
|
333
417
|
*/
|
|
334
418
|
type StreamConstructor<T> = (state: IRPCReadable<T>, resolve: (value?: T) => void, reject: (error: Error) => void) => StreamCleanup | void | Promise<StreamCleanup | void>;
|
|
335
419
|
//#endregion
|
|
336
|
-
export { IRPCArraySchema,
|
|
420
|
+
export { 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 };
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@irpclib/irpc",
|
|
4
|
-
"version": "1.0.0
|
|
4
|
+
"version": "1.0.0",
|
|
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": [
|
|
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
|
|
55
|
+
"@anchorlib/core": "^1.0.0"
|
|
54
56
|
}
|
|
55
|
-
}
|
|
57
|
+
}
|