@labostack/typebridge 0.1.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/README.md +62 -0
- package/dist/adapters/decorators.d.ts +11 -0
- package/dist/adapters/decorators.d.ts.map +1 -0
- package/dist/adapters/decorators.js +20 -0
- package/dist/adapters/decorators.js.map +1 -0
- package/dist/adapters/deepkit-adapter.d.ts +11 -0
- package/dist/adapters/deepkit-adapter.d.ts.map +1 -0
- package/dist/adapters/deepkit-adapter.js +39 -0
- package/dist/adapters/deepkit-adapter.js.map +1 -0
- package/dist/adapters/generic-adapter.d.ts +12 -0
- package/dist/adapters/generic-adapter.d.ts.map +1 -0
- package/dist/adapters/generic-adapter.js +28 -0
- package/dist/adapters/generic-adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +5 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/nest-adapter.d.ts +14 -0
- package/dist/adapters/nest-adapter.d.ts.map +1 -0
- package/dist/adapters/nest-adapter.js +33 -0
- package/dist/adapters/nest-adapter.js.map +1 -0
- package/dist/adapters/tsed-adapter.d.ts +10 -0
- package/dist/adapters/tsed-adapter.d.ts.map +1 -0
- package/dist/adapters/tsed-adapter.js +31 -0
- package/dist/adapters/tsed-adapter.js.map +1 -0
- package/dist/autobarrel/index.d.ts +2 -0
- package/dist/autobarrel/index.d.ts.map +1 -0
- package/dist/autobarrel/index.js +2 -0
- package/dist/autobarrel/index.js.map +1 -0
- package/dist/autobarrel/scanner.d.ts +14 -0
- package/dist/autobarrel/scanner.d.ts.map +1 -0
- package/dist/autobarrel/scanner.js +93 -0
- package/dist/autobarrel/scanner.js.map +1 -0
- package/dist/bridge.d.ts +54 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +151 -0
- package/dist/bridge.js.map +1 -0
- package/dist/discovery/dns.d.ts +10 -0
- package/dist/discovery/dns.d.ts.map +1 -0
- package/dist/discovery/dns.js +19 -0
- package/dist/discovery/dns.js.map +1 -0
- package/dist/discovery/index.d.ts +4 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +4 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/mdns.d.ts +18 -0
- package/dist/discovery/mdns.d.ts.map +1 -0
- package/dist/discovery/mdns.js +49 -0
- package/dist/discovery/mdns.js.map +1 -0
- package/dist/discovery/resolver.d.ts +16 -0
- package/dist/discovery/resolver.d.ts.map +1 -0
- package/dist/discovery/resolver.js +36 -0
- package/dist/discovery/resolver.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mesh/index.d.ts +2 -0
- package/dist/mesh/index.d.ts.map +1 -0
- package/dist/mesh/index.js +2 -0
- package/dist/mesh/index.js.map +1 -0
- package/dist/mesh/mesh-manager.d.ts +55 -0
- package/dist/mesh/mesh-manager.d.ts.map +1 -0
- package/dist/mesh/mesh-manager.js +179 -0
- package/dist/mesh/mesh-manager.js.map +1 -0
- package/dist/proxy/client-proxy.d.ts +20 -0
- package/dist/proxy/client-proxy.d.ts.map +1 -0
- package/dist/proxy/client-proxy.js +69 -0
- package/dist/proxy/client-proxy.js.map +1 -0
- package/dist/proxy/index.d.ts +2 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +2 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/reflection/extractor.d.ts +13 -0
- package/dist/reflection/extractor.d.ts.map +1 -0
- package/dist/reflection/extractor.js +62 -0
- package/dist/reflection/extractor.js.map +1 -0
- package/dist/reflection/index.d.ts +2 -0
- package/dist/reflection/index.d.ts.map +1 -0
- package/dist/reflection/index.js +2 -0
- package/dist/reflection/index.js.map +1 -0
- package/dist/registry/index.d.ts +3 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +2 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/method-registry.d.ts +56 -0
- package/dist/registry/method-registry.d.ts.map +1 -0
- package/dist/registry/method-registry.js +84 -0
- package/dist/registry/method-registry.js.map +1 -0
- package/dist/serialization/error-ext.d.ts +38 -0
- package/dist/serialization/error-ext.d.ts.map +1 -0
- package/dist/serialization/error-ext.js +76 -0
- package/dist/serialization/error-ext.js.map +1 -0
- package/dist/serialization/index.d.ts +4 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/serialization/msgpack.d.ts +30 -0
- package/dist/serialization/msgpack.d.ts.map +1 -0
- package/dist/serialization/msgpack.js +76 -0
- package/dist/serialization/msgpack.js.map +1 -0
- package/dist/serialization/serializer.d.ts +15 -0
- package/dist/serialization/serializer.d.ts.map +1 -0
- package/dist/serialization/serializer.js +2 -0
- package/dist/serialization/serializer.js.map +1 -0
- package/dist/transport/client.d.ts +38 -0
- package/dist/transport/client.d.ts.map +1 -0
- package/dist/transport/client.js +57 -0
- package/dist/transport/client.js.map +1 -0
- package/dist/transport/connection.d.ts +57 -0
- package/dist/transport/connection.d.ts.map +1 -0
- package/dist/transport/connection.js +212 -0
- package/dist/transport/connection.js.map +1 -0
- package/dist/transport/constants.d.ts +2 -0
- package/dist/transport/constants.d.ts.map +1 -0
- package/dist/transport/constants.js +2 -0
- package/dist/transport/constants.js.map +1 -0
- package/dist/transport/framing.d.ts +54 -0
- package/dist/transport/framing.d.ts.map +1 -0
- package/dist/transport/framing.js +107 -0
- package/dist/transport/framing.js.map +1 -0
- package/dist/transport/index.d.ts +7 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +7 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/peer-manager.d.ts +67 -0
- package/dist/transport/peer-manager.d.ts.map +1 -0
- package/dist/transport/peer-manager.js +172 -0
- package/dist/transport/peer-manager.js.map +1 -0
- package/dist/transport/server.d.ts +37 -0
- package/dist/transport/server.d.ts.map +1 -0
- package/dist/transport/server.js +88 -0
- package/dist/transport/server.js.map +1 -0
- package/dist/types/adapter.d.ts +33 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +2 -0
- package/dist/types/adapter.js.map +1 -0
- package/dist/types/descriptor.d.ts +35 -0
- package/dist/types/descriptor.d.ts.map +1 -0
- package/dist/types/descriptor.js +2 -0
- package/dist/types/descriptor.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.ts +55 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +6 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/protocol.d.ts +94 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +43 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/types/type-descriptor.d.ts +64 -0
- package/dist/types/type-descriptor.d.ts.map +1 -0
- package/dist/types/type-descriptor.js +2 -0
- package/dist/types/type-descriptor.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { TypeDescriptor } from "./type-descriptor.js";
|
|
2
|
+
/**
|
|
3
|
+
* Describes a single parameter of a controller method.
|
|
4
|
+
*/
|
|
5
|
+
export interface ParameterDescriptor {
|
|
6
|
+
/** Parameter name (e.g., "id", "data") */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Position index in the parameter list (0-based) */
|
|
9
|
+
index: number;
|
|
10
|
+
/** Full type descriptor */
|
|
11
|
+
type: TypeDescriptor;
|
|
12
|
+
/** Whether the parameter is optional */
|
|
13
|
+
isOptional: boolean;
|
|
14
|
+
/** Default value, if any */
|
|
15
|
+
defaultValue?: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Describes a single method on a controller.
|
|
19
|
+
* This is what gets stored in the MethodRegistry and sent during handshake.
|
|
20
|
+
*/
|
|
21
|
+
export interface MethodDescriptor {
|
|
22
|
+
/** Controller name (e.g., "userController") */
|
|
23
|
+
controllerName: string;
|
|
24
|
+
/** Method name (e.g., "findById") */
|
|
25
|
+
methodName: string;
|
|
26
|
+
/** Ordered list of parameter descriptors */
|
|
27
|
+
parameters: ParameterDescriptor[];
|
|
28
|
+
/** Return type descriptor (may be wrapped in Promise) */
|
|
29
|
+
returnType: TypeDescriptor;
|
|
30
|
+
/** Whether the method is async or returns a Promise */
|
|
31
|
+
isAsync: boolean;
|
|
32
|
+
/** Original framework decorators for context (e.g., ["Get", "Param"]) */
|
|
33
|
+
decorators: string[];
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../../src/types/descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,IAAI,EAAE,cAAc,CAAC;IACrB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,4BAA4B;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,yDAAyD;IACzD,UAAU,EAAE,cAAc,CAAC;IAC3B,uDAAuD;IACvD,OAAO,EAAE,OAAO,CAAC;IACjB,yEAAyE;IACzE,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../../src/types/descriptor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { TypeDescriptor } from "./type-descriptor.js";
|
|
2
|
+
export type { MethodDescriptor, ParameterDescriptor } from "./descriptor.js";
|
|
3
|
+
export type { FrameworkAdapter } from "./adapter.js";
|
|
4
|
+
export type { NodeOptions, TypeBridgeAPI, ControllerInstances, PeerTarget, } from "./options.js";
|
|
5
|
+
export { DEFAULT_PORT } from "./options.js";
|
|
6
|
+
export { FRAME_MAGIC, PROTOCOL_VERSION, FRAME_HEADER_SIZE, MessageType, FrameFlags, } from "./protocol.js";
|
|
7
|
+
export type { HandshakePayload, HandshakeAckPayload, MethodCatalogEntry, RequestPayload, ResponsePayload, ErrorPayload, } from "./protocol.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EACV,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,YAAY,GACb,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the TypeBridge automatic mesh.
|
|
3
|
+
*/
|
|
4
|
+
/** Default port — 0 means auto-assign a free port */
|
|
5
|
+
export declare const DEFAULT_PORT = 0;
|
|
6
|
+
/**
|
|
7
|
+
* Options for TypeBridge.create().
|
|
8
|
+
*/
|
|
9
|
+
export interface NodeOptions<C extends Record<string, unknown> | string = Record<string, unknown>> {
|
|
10
|
+
/**
|
|
11
|
+
* Controllers to expose via RPC.
|
|
12
|
+
* - Object: `{ UserController, OrderController }` — explicit imports
|
|
13
|
+
* - String: `"./src/controllers"` — autobarrel (scans the directory)
|
|
14
|
+
*/
|
|
15
|
+
controllers: C;
|
|
16
|
+
name?: string;
|
|
17
|
+
port?: number;
|
|
18
|
+
host?: string;
|
|
19
|
+
announce?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The API returned by TypeBridge.create().
|
|
23
|
+
*
|
|
24
|
+
* This IS the proxy — access controllers directly:
|
|
25
|
+
* api.userController.findById("abc")
|
|
26
|
+
*
|
|
27
|
+
* Local controllers are called directly.
|
|
28
|
+
* Remote controllers are auto-discovered and routed.
|
|
29
|
+
*/
|
|
30
|
+
export type TypeBridgeAPI<Local extends Record<string, unknown>> = ControllerInstances<Local> & {
|
|
31
|
+
readonly port: number;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
readonly __controllers: ControllerInstances<Local>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Maps a controllers object to its instance types.
|
|
38
|
+
*
|
|
39
|
+
* Given `{ UserController: typeof UserController }`
|
|
40
|
+
* produces `{ userController: UserController }`
|
|
41
|
+
*/
|
|
42
|
+
export type ControllerInstances<C extends Record<string, unknown>> = {
|
|
43
|
+
[K in keyof C as CamelCase<K & string>]: C[K] extends new (...args: any[]) => infer I ? I : C[K];
|
|
44
|
+
};
|
|
45
|
+
/** PascalCase → camelCase */
|
|
46
|
+
type CamelCase<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
47
|
+
/**
|
|
48
|
+
* Explicit peer target (bypass discovery).
|
|
49
|
+
*/
|
|
50
|
+
export interface PeerTarget {
|
|
51
|
+
host: string;
|
|
52
|
+
port: number;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qDAAqD;AACrD,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/F;;;;OAIG;IACH,WAAW,EAAE,CAAC,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC7D,mBAAmB,CAAC,KAAK,CAAC,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAAC,KAAK,CAAC,CAAC;CACpD,CAAC;AAEJ;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAClE,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACjG,CAAC;AAEF,6BAA6B;AAC7B,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAEhG;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qDAAqD;AACrD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol constants and message types.
|
|
3
|
+
*/
|
|
4
|
+
/** Magic bytes identifying a TypeBridge frame (ASCII: "TB") */
|
|
5
|
+
export declare const FRAME_MAGIC = 21570;
|
|
6
|
+
/** Current protocol version */
|
|
7
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
8
|
+
/** Frame header size in bytes: Magic(2) + Version(1) + Flags(1) + PayloadLen(4) + ReqID(4) + MsgType(1) = 13 */
|
|
9
|
+
export declare const FRAME_HEADER_SIZE = 13;
|
|
10
|
+
/**
|
|
11
|
+
* Message types for the wire protocol.
|
|
12
|
+
*/
|
|
13
|
+
export declare enum MessageType {
|
|
14
|
+
/** RPC method call: controller.method(args) */
|
|
15
|
+
Request = 1,
|
|
16
|
+
/** Successful RPC response with return value */
|
|
17
|
+
Response = 2,
|
|
18
|
+
/** RPC error response (serialized Error object) */
|
|
19
|
+
Error = 3,
|
|
20
|
+
/** Stream data chunk (for streaming responses) */
|
|
21
|
+
StreamChunk = 4,
|
|
22
|
+
/** Stream end marker */
|
|
23
|
+
StreamEnd = 5,
|
|
24
|
+
/** Initial handshake: client sends its identity */
|
|
25
|
+
Handshake = 6,
|
|
26
|
+
/** Keepalive ping/pong */
|
|
27
|
+
Heartbeat = 7,
|
|
28
|
+
/** Handshake acknowledgment: server sends type catalog */
|
|
29
|
+
HandshakeAck = 8
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Frame flags (bitfield).
|
|
33
|
+
*/
|
|
34
|
+
export declare enum FrameFlags {
|
|
35
|
+
None = 0,
|
|
36
|
+
/** Payload is compressed (reserved for future use) */
|
|
37
|
+
Compressed = 1,
|
|
38
|
+
/** This is the last frame in a sequence */
|
|
39
|
+
Final = 2
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Handshake payload sent by the client.
|
|
43
|
+
*/
|
|
44
|
+
export interface HandshakePayload {
|
|
45
|
+
/** Client service name */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Protocol version the client supports */
|
|
48
|
+
version: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Handshake acknowledgment payload sent by the server.
|
|
52
|
+
* Contains the full type catalog for compile-time type safety at runtime.
|
|
53
|
+
*/
|
|
54
|
+
export interface HandshakeAckPayload {
|
|
55
|
+
/** Server service name */
|
|
56
|
+
name: string;
|
|
57
|
+
/** Protocol version the server uses */
|
|
58
|
+
version: number;
|
|
59
|
+
/** Full method catalog (controller → method → type descriptors) */
|
|
60
|
+
catalog: Record<string, MethodCatalogEntry[]>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Single method entry in the type catalog.
|
|
64
|
+
*/
|
|
65
|
+
export interface MethodCatalogEntry {
|
|
66
|
+
methodName: string;
|
|
67
|
+
parameterNames: string[];
|
|
68
|
+
parameterCount: number;
|
|
69
|
+
isAsync: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* RPC request payload.
|
|
73
|
+
*/
|
|
74
|
+
export interface RequestPayload {
|
|
75
|
+
/** Dot-separated path: "controllerName.methodName" */
|
|
76
|
+
method: string;
|
|
77
|
+
/** Ordered arguments to the method */
|
|
78
|
+
args: unknown[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* RPC response payload.
|
|
82
|
+
*/
|
|
83
|
+
export interface ResponsePayload {
|
|
84
|
+
/** Return value from the method call */
|
|
85
|
+
result: unknown;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* RPC error payload.
|
|
89
|
+
*/
|
|
90
|
+
export interface ErrorPayload {
|
|
91
|
+
/** Serialized Error object (full passthrough) */
|
|
92
|
+
error: unknown;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/types/protocol.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,+DAA+D;AAC/D,eAAO,MAAM,WAAW,QAAS,CAAC;AAElC,+BAA+B;AAC/B,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,gHAAgH;AAChH,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;GAEG;AACH,oBAAY,WAAW;IACrB,+CAA+C;IAC/C,OAAO,IAAO;IACd,gDAAgD;IAChD,QAAQ,IAAO;IACf,mDAAmD;IACnD,KAAK,IAAO;IACZ,kDAAkD;IAClD,WAAW,IAAO;IAClB,wBAAwB;IACxB,SAAS,IAAO;IAChB,mDAAmD;IACnD,SAAS,IAAO;IAChB,0BAA0B;IAC1B,SAAS,IAAO;IAChB,0DAA0D;IAC1D,YAAY,IAAO;CACpB;AAED;;GAEG;AACH,oBAAY,UAAU;IACpB,IAAI,IAAO;IACX,sDAAsD;IACtD,UAAU,IAAO;IACjB,2CAA2C;IAC3C,KAAK,IAAO;CACb;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,wCAAwC;IACxC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,KAAK,EAAE,OAAO,CAAC;CAChB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol constants and message types.
|
|
3
|
+
*/
|
|
4
|
+
/** Magic bytes identifying a TypeBridge frame (ASCII: "TB") */
|
|
5
|
+
export const FRAME_MAGIC = 0x5442;
|
|
6
|
+
/** Current protocol version */
|
|
7
|
+
export const PROTOCOL_VERSION = 1;
|
|
8
|
+
/** Frame header size in bytes: Magic(2) + Version(1) + Flags(1) + PayloadLen(4) + ReqID(4) + MsgType(1) = 13 */
|
|
9
|
+
export const FRAME_HEADER_SIZE = 13;
|
|
10
|
+
/**
|
|
11
|
+
* Message types for the wire protocol.
|
|
12
|
+
*/
|
|
13
|
+
export var MessageType;
|
|
14
|
+
(function (MessageType) {
|
|
15
|
+
/** RPC method call: controller.method(args) */
|
|
16
|
+
MessageType[MessageType["Request"] = 1] = "Request";
|
|
17
|
+
/** Successful RPC response with return value */
|
|
18
|
+
MessageType[MessageType["Response"] = 2] = "Response";
|
|
19
|
+
/** RPC error response (serialized Error object) */
|
|
20
|
+
MessageType[MessageType["Error"] = 3] = "Error";
|
|
21
|
+
/** Stream data chunk (for streaming responses) */
|
|
22
|
+
MessageType[MessageType["StreamChunk"] = 4] = "StreamChunk";
|
|
23
|
+
/** Stream end marker */
|
|
24
|
+
MessageType[MessageType["StreamEnd"] = 5] = "StreamEnd";
|
|
25
|
+
/** Initial handshake: client sends its identity */
|
|
26
|
+
MessageType[MessageType["Handshake"] = 6] = "Handshake";
|
|
27
|
+
/** Keepalive ping/pong */
|
|
28
|
+
MessageType[MessageType["Heartbeat"] = 7] = "Heartbeat";
|
|
29
|
+
/** Handshake acknowledgment: server sends type catalog */
|
|
30
|
+
MessageType[MessageType["HandshakeAck"] = 8] = "HandshakeAck";
|
|
31
|
+
})(MessageType || (MessageType = {}));
|
|
32
|
+
/**
|
|
33
|
+
* Frame flags (bitfield).
|
|
34
|
+
*/
|
|
35
|
+
export var FrameFlags;
|
|
36
|
+
(function (FrameFlags) {
|
|
37
|
+
FrameFlags[FrameFlags["None"] = 0] = "None";
|
|
38
|
+
/** Payload is compressed (reserved for future use) */
|
|
39
|
+
FrameFlags[FrameFlags["Compressed"] = 1] = "Compressed";
|
|
40
|
+
/** This is the last frame in a sequence */
|
|
41
|
+
FrameFlags[FrameFlags["Final"] = 2] = "Final";
|
|
42
|
+
})(FrameFlags || (FrameFlags = {}));
|
|
43
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/types/protocol.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAElC,+BAA+B;AAC/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,gHAAgH;AAChH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAN,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB,+CAA+C;IAC/C,mDAAc,CAAA;IACd,gDAAgD;IAChD,qDAAe,CAAA;IACf,mDAAmD;IACnD,+CAAY,CAAA;IACZ,kDAAkD;IAClD,2DAAkB,CAAA;IAClB,wBAAwB;IACxB,uDAAgB,CAAA;IAChB,mDAAmD;IACnD,uDAAgB,CAAA;IAChB,0BAA0B;IAC1B,uDAAgB,CAAA;IAChB,0DAA0D;IAC1D,6DAAmB,CAAA;AACrB,CAAC,EAjBW,WAAW,KAAX,WAAW,QAiBtB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,2CAAW,CAAA;IACX,sDAAsD;IACtD,uDAAiB,CAAA;IACjB,2CAA2C;IAC3C,6CAAY,CAAA;AACd,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeDescriptor — Compact type representation for the wire protocol.
|
|
3
|
+
*
|
|
4
|
+
* Describes any TypeScript type as a serializable tree structure.
|
|
5
|
+
* Used in the handshake type catalog so clients know method signatures.
|
|
6
|
+
*/
|
|
7
|
+
export type TypeDescriptor = {
|
|
8
|
+
kind: "primitive";
|
|
9
|
+
type: "string" | "number" | "boolean" | "void" | "null" | "undefined";
|
|
10
|
+
} | {
|
|
11
|
+
kind: "literal";
|
|
12
|
+
value: string | number | boolean;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "object";
|
|
15
|
+
properties: Record<string, {
|
|
16
|
+
type: TypeDescriptor;
|
|
17
|
+
optional: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "array";
|
|
21
|
+
elementType: TypeDescriptor;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "tuple";
|
|
24
|
+
elements: TypeDescriptor[];
|
|
25
|
+
} | {
|
|
26
|
+
kind: "union";
|
|
27
|
+
members: TypeDescriptor[];
|
|
28
|
+
} | {
|
|
29
|
+
kind: "intersection";
|
|
30
|
+
members: TypeDescriptor[];
|
|
31
|
+
} | {
|
|
32
|
+
kind: "promise";
|
|
33
|
+
resolvedType: TypeDescriptor;
|
|
34
|
+
} | {
|
|
35
|
+
kind: "enum";
|
|
36
|
+
name: string;
|
|
37
|
+
members: Record<string, string | number>;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "ref";
|
|
40
|
+
name: string;
|
|
41
|
+
module: string;
|
|
42
|
+
} | {
|
|
43
|
+
kind: "generic";
|
|
44
|
+
base: TypeDescriptor;
|
|
45
|
+
args: TypeDescriptor[];
|
|
46
|
+
} | {
|
|
47
|
+
kind: "map";
|
|
48
|
+
keyType: TypeDescriptor;
|
|
49
|
+
valueType: TypeDescriptor;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "set";
|
|
52
|
+
elementType: TypeDescriptor;
|
|
53
|
+
} | {
|
|
54
|
+
kind: "binary";
|
|
55
|
+
encoding: "buffer" | "uint8array";
|
|
56
|
+
} | {
|
|
57
|
+
kind: "stream";
|
|
58
|
+
chunkType: TypeDescriptor;
|
|
59
|
+
} | {
|
|
60
|
+
kind: "any";
|
|
61
|
+
} | {
|
|
62
|
+
kind: "unknown";
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=type-descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-descriptor.d.ts","sourceRoot":"","sources":["../../src/types/type-descriptor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,CAAA;CAAE,GAC5F;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CAAE,GAC3F;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,cAAc,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,cAAc,EAAE,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,cAAc,EAAE,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,cAAc,EAAE,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,cAAc,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,cAAc,EAAE,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,cAAc,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-descriptor.js","sourceRoot":"","sources":["../../src/types/type-descriptor.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@labostack/typebridge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-ceremony RPC bridge with full auto-typing for TypeScript microservices",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./adapters": {
|
|
14
|
+
"types": "./dist/adapters/index.d.ts",
|
|
15
|
+
"import": "./dist/adapters/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.build.json",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"bonjour-service": "^1.3.0",
|
|
27
|
+
"msgpackr": "^1.11.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^25.9.3",
|
|
31
|
+
"reflect-metadata": "^0.2.0",
|
|
32
|
+
"typescript": "^5.8.3",
|
|
33
|
+
"vitest": "^3.2.1"
|
|
34
|
+
},
|
|
35
|
+
"files": ["dist"],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20.0.0"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"packageManager": "pnpm@9.15.9"
|
|
41
|
+
}
|