@procwire/transport 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/LICENSE +21 -0
- package/README.md +844 -0
- package/dist/channel/builder.d.ts +68 -0
- package/dist/channel/builder.d.ts.map +1 -0
- package/dist/channel/builder.js +120 -0
- package/dist/channel/builder.js.map +1 -0
- package/dist/channel/index.d.ts +6 -0
- package/dist/channel/index.d.ts.map +1 -0
- package/dist/channel/index.js +6 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/quickstart.d.ts +94 -0
- package/dist/channel/quickstart.d.ts.map +1 -0
- package/dist/channel/quickstart.js +104 -0
- package/dist/channel/quickstart.js.map +1 -0
- package/dist/channel/request-channel.d.ts +119 -0
- package/dist/channel/request-channel.d.ts.map +1 -0
- package/dist/channel/request-channel.js +476 -0
- package/dist/channel/request-channel.js.map +1 -0
- package/dist/channel/types.d.ts +226 -0
- package/dist/channel/types.d.ts.map +1 -0
- package/dist/channel/types.js +2 -0
- package/dist/channel/types.js.map +1 -0
- package/dist/framing/index.d.ts +4 -0
- package/dist/framing/index.d.ts.map +1 -0
- package/dist/framing/index.js +4 -0
- package/dist/framing/index.js.map +1 -0
- package/dist/framing/length-prefixed.d.ts +55 -0
- package/dist/framing/length-prefixed.d.ts.map +1 -0
- package/dist/framing/length-prefixed.js +102 -0
- package/dist/framing/length-prefixed.js.map +1 -0
- package/dist/framing/line-delimited.d.ts +61 -0
- package/dist/framing/line-delimited.d.ts.map +1 -0
- package/dist/framing/line-delimited.js +94 -0
- package/dist/framing/line-delimited.js.map +1 -0
- package/dist/framing/types.d.ts +35 -0
- package/dist/framing/types.d.ts.map +1 -0
- package/dist/framing/types.js +2 -0
- package/dist/framing/types.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/process/handle.d.ts +64 -0
- package/dist/process/handle.d.ts.map +1 -0
- package/dist/process/handle.js +107 -0
- package/dist/process/handle.js.map +1 -0
- package/dist/process/index.d.ts +37 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/process/index.js +37 -0
- package/dist/process/index.js.map +1 -0
- package/dist/process/manager.d.ts +58 -0
- package/dist/process/manager.d.ts.map +1 -0
- package/dist/process/manager.js +360 -0
- package/dist/process/manager.js.map +1 -0
- package/dist/process/types.d.ts +322 -0
- package/dist/process/types.d.ts.map +1 -0
- package/dist/process/types.js +2 -0
- package/dist/process/types.js.map +1 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +6 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/jsonrpc.d.ts +146 -0
- package/dist/protocol/jsonrpc.d.ts.map +1 -0
- package/dist/protocol/jsonrpc.js +288 -0
- package/dist/protocol/jsonrpc.js.map +1 -0
- package/dist/protocol/simple.d.ts +139 -0
- package/dist/protocol/simple.d.ts.map +1 -0
- package/dist/protocol/simple.js +297 -0
- package/dist/protocol/simple.js.map +1 -0
- package/dist/protocol/types.d.ts +117 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +2 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/serialization/index.d.ts +5 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +5 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/serialization/json.d.ts +66 -0
- package/dist/serialization/json.d.ts.map +1 -0
- package/dist/serialization/json.js +66 -0
- package/dist/serialization/json.js.map +1 -0
- package/dist/serialization/raw.d.ts +38 -0
- package/dist/serialization/raw.d.ts.map +1 -0
- package/dist/serialization/raw.js +41 -0
- package/dist/serialization/raw.js.map +1 -0
- package/dist/serialization/registry.d.ts +91 -0
- package/dist/serialization/registry.d.ts.map +1 -0
- package/dist/serialization/registry.js +119 -0
- package/dist/serialization/registry.js.map +1 -0
- package/dist/serialization/types.d.ts +27 -0
- package/dist/serialization/types.d.ts.map +1 -0
- package/dist/serialization/types.js +2 -0
- package/dist/serialization/types.js.map +1 -0
- package/dist/transport/factory.d.ts +139 -0
- package/dist/transport/factory.d.ts.map +1 -0
- package/dist/transport/factory.js +162 -0
- package/dist/transport/factory.js.map +1 -0
- package/dist/transport/index.d.ts +6 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +9 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/socket-server.d.ts +48 -0
- package/dist/transport/socket-server.d.ts.map +1 -0
- package/dist/transport/socket-server.js +215 -0
- package/dist/transport/socket-server.js.map +1 -0
- package/dist/transport/socket-transport.d.ts +67 -0
- package/dist/transport/socket-transport.d.ts.map +1 -0
- package/dist/transport/socket-transport.js +193 -0
- package/dist/transport/socket-transport.js.map +1 -0
- package/dist/transport/stdio-transport.d.ts +94 -0
- package/dist/transport/stdio-transport.d.ts.map +1 -0
- package/dist/transport/stdio-transport.js +234 -0
- package/dist/transport/stdio-transport.js.map +1 -0
- package/dist/transport/types.d.ts +131 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +2 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/utils/assert.d.ts +16 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +31 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/disposables.d.ts +38 -0
- package/dist/utils/disposables.d.ts.map +1 -0
- package/dist/utils/disposables.js +59 -0
- package/dist/utils/disposables.js.map +1 -0
- package/dist/utils/errors.d.ts +43 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +69 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +58 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +95 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pipe-path.d.ts +48 -0
- package/dist/utils/pipe-path.d.ts.map +1 -0
- package/dist/utils/pipe-path.js +89 -0
- package/dist/utils/pipe-path.js.map +1 -0
- package/dist/utils/platform.d.ts +16 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +22 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/time.d.ts +38 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +55 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw.js","sourceRoot":"","sources":["../../src/serialization/raw.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,QAAQ;IACH,IAAI,GAAG,KAAK,CAAC;IACb,WAAW,GAAG,0BAA0B,CAAC;IAEzD;;;;;OAKG;IACH,SAAS,CAAC,KAAa;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,MAAc;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { SerializationCodec } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Global codec registry for serialization codecs.
|
|
4
|
+
*
|
|
5
|
+
* Provides a static registry to register and lookup codecs by name or content type.
|
|
6
|
+
* Thread-safe in Node.js (single-threaded event loop).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { CodecRegistry, JsonCodec } from '@procwire/transport';
|
|
11
|
+
*
|
|
12
|
+
* CodecRegistry.register(new JsonCodec());
|
|
13
|
+
* const codec = CodecRegistry.get('json');
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class CodecRegistry {
|
|
17
|
+
private static readonly byName;
|
|
18
|
+
private static readonly byContentType;
|
|
19
|
+
/**
|
|
20
|
+
* Registers a serialization codec in the global registry.
|
|
21
|
+
*
|
|
22
|
+
* @param codec - Codec to register
|
|
23
|
+
* @throws {SerializationError} if a codec with the same name or content type already exists
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* CodecRegistry.register(new JsonCodec());
|
|
28
|
+
* CodecRegistry.register(new RawCodec());
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
static register(codec: SerializationCodec): void;
|
|
32
|
+
/**
|
|
33
|
+
* Unregisters a codec by name.
|
|
34
|
+
*
|
|
35
|
+
* @param name - Name of the codec to unregister
|
|
36
|
+
* @returns true if codec was found and removed, false otherwise
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* CodecRegistry.unregister('json');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
static unregister(name: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves a codec by name.
|
|
46
|
+
*
|
|
47
|
+
* @param name - Codec name (e.g., 'json', 'raw')
|
|
48
|
+
* @returns Codec instance or undefined if not found
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const codec = CodecRegistry.get('json');
|
|
53
|
+
* if (codec) {
|
|
54
|
+
* const buffer = codec.serialize({ foo: 'bar' });
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static get(name: string): SerializationCodec | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves a codec by content type.
|
|
61
|
+
*
|
|
62
|
+
* @param contentType - Content type (e.g., 'application/json')
|
|
63
|
+
* @returns Codec instance or undefined if not found
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const codec = CodecRegistry.getByContentType('application/json');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
static getByContentType(contentType: string): SerializationCodec | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Lists all registered codec names.
|
|
73
|
+
*
|
|
74
|
+
* @returns Array of codec names
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const names = CodecRegistry.list();
|
|
79
|
+
* console.log(names); // ['json', 'raw']
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static list(): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Clears all registered codecs.
|
|
85
|
+
* Intended for testing purposes only.
|
|
86
|
+
*
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
static resetForTests(): void;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/serialization/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAyC;IACvE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAyC;IAE9E;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI;IAmBhD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAWxC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIxD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI5E;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,IAAI,MAAM,EAAE;IAIvB;;;;;OAKG;IACH,MAAM,CAAC,aAAa,IAAI,IAAI;CAI7B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { SerializationError } from "../utils/errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Global codec registry for serialization codecs.
|
|
4
|
+
*
|
|
5
|
+
* Provides a static registry to register and lookup codecs by name or content type.
|
|
6
|
+
* Thread-safe in Node.js (single-threaded event loop).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { CodecRegistry, JsonCodec } from '@procwire/transport';
|
|
11
|
+
*
|
|
12
|
+
* CodecRegistry.register(new JsonCodec());
|
|
13
|
+
* const codec = CodecRegistry.get('json');
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class CodecRegistry {
|
|
17
|
+
static byName = new Map();
|
|
18
|
+
static byContentType = new Map();
|
|
19
|
+
/**
|
|
20
|
+
* Registers a serialization codec in the global registry.
|
|
21
|
+
*
|
|
22
|
+
* @param codec - Codec to register
|
|
23
|
+
* @throws {SerializationError} if a codec with the same name or content type already exists
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* CodecRegistry.register(new JsonCodec());
|
|
28
|
+
* CodecRegistry.register(new RawCodec());
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
static register(codec) {
|
|
32
|
+
const existingByName = this.byName.get(codec.name);
|
|
33
|
+
if (existingByName) {
|
|
34
|
+
throw new SerializationError(`Codec with name '${codec.name}' is already registered (content type: '${existingByName.contentType}')`);
|
|
35
|
+
}
|
|
36
|
+
const existingByContentType = this.byContentType.get(codec.contentType);
|
|
37
|
+
if (existingByContentType) {
|
|
38
|
+
throw new SerializationError(`Codec with content type '${codec.contentType}' is already registered (name: '${existingByContentType.name}')`);
|
|
39
|
+
}
|
|
40
|
+
this.byName.set(codec.name, codec);
|
|
41
|
+
this.byContentType.set(codec.contentType, codec);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Unregisters a codec by name.
|
|
45
|
+
*
|
|
46
|
+
* @param name - Name of the codec to unregister
|
|
47
|
+
* @returns true if codec was found and removed, false otherwise
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* CodecRegistry.unregister('json');
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
static unregister(name) {
|
|
55
|
+
const codec = this.byName.get(name);
|
|
56
|
+
if (!codec) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
this.byName.delete(name);
|
|
60
|
+
this.byContentType.delete(codec.contentType);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves a codec by name.
|
|
65
|
+
*
|
|
66
|
+
* @param name - Codec name (e.g., 'json', 'raw')
|
|
67
|
+
* @returns Codec instance or undefined if not found
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const codec = CodecRegistry.get('json');
|
|
72
|
+
* if (codec) {
|
|
73
|
+
* const buffer = codec.serialize({ foo: 'bar' });
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
static get(name) {
|
|
78
|
+
return this.byName.get(name);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves a codec by content type.
|
|
82
|
+
*
|
|
83
|
+
* @param contentType - Content type (e.g., 'application/json')
|
|
84
|
+
* @returns Codec instance or undefined if not found
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const codec = CodecRegistry.getByContentType('application/json');
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
static getByContentType(contentType) {
|
|
92
|
+
return this.byContentType.get(contentType);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Lists all registered codec names.
|
|
96
|
+
*
|
|
97
|
+
* @returns Array of codec names
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const names = CodecRegistry.list();
|
|
102
|
+
* console.log(names); // ['json', 'raw']
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
static list() {
|
|
106
|
+
return Array.from(this.byName.keys());
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Clears all registered codecs.
|
|
110
|
+
* Intended for testing purposes only.
|
|
111
|
+
*
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
static resetForTests() {
|
|
115
|
+
this.byName.clear();
|
|
116
|
+
this.byContentType.clear();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/serialization/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAAU,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;IAC/D,MAAM,CAAU,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE9E;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAyB;QACvC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,IAAI,kBAAkB,CAC1B,oBAAoB,KAAK,CAAC,IAAI,2CAA2C,cAAc,CAAC,WAAW,IAAI,CACxG,CAAC;QACJ,CAAC;QAED,MAAM,qBAAqB,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACxE,IAAI,qBAAqB,EAAE,CAAC;YAC1B,MAAM,IAAI,kBAAkB,CAC1B,4BAA4B,KAAK,CAAC,WAAW,mCAAmC,qBAAqB,CAAC,IAAI,IAAI,CAC/G,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,UAAU,CAAC,IAAY;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,GAAG,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAmB;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,aAAa;QAClB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization codec interface for converting between objects and binary data.
|
|
3
|
+
* Implementations: JSON, MessagePack, Protocol Buffers, Apache Arrow.
|
|
4
|
+
*
|
|
5
|
+
* @template T - Type of objects being serialized/deserialized
|
|
6
|
+
*/
|
|
7
|
+
export interface SerializationCodec<T = unknown> {
|
|
8
|
+
/**
|
|
9
|
+
* Codec name (e.g., 'json', 'msgpack', 'protobuf').
|
|
10
|
+
*/
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/**
|
|
13
|
+
* Content type identifier (e.g., 'application/json', 'application/msgpack').
|
|
14
|
+
*/
|
|
15
|
+
readonly contentType: string;
|
|
16
|
+
/**
|
|
17
|
+
* Serializes object to binary buffer.
|
|
18
|
+
* @throws {SerializationError} if serialization fails
|
|
19
|
+
*/
|
|
20
|
+
serialize(data: T): Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Deserializes binary buffer to object.
|
|
23
|
+
* @throws {SerializationError} if deserialization fails
|
|
24
|
+
*/
|
|
25
|
+
deserialize(buffer: Buffer): T;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/serialization/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3B;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/serialization/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { StdioTransport, type StdioTransportOptions } from "./stdio-transport.js";
|
|
2
|
+
import { type SocketTransportOptions } from "./socket-transport.js";
|
|
3
|
+
import { type SocketServerOptions } from "./socket-server.js";
|
|
4
|
+
import type { Transport, TransportServer } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Factory for creating transport instances.
|
|
7
|
+
*
|
|
8
|
+
* Provides convenient methods for creating different types of transports
|
|
9
|
+
* with platform-specific optimizations.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Create stdio transport for child process
|
|
14
|
+
* const transport = TransportFactory.createStdio({
|
|
15
|
+
* executablePath: 'node',
|
|
16
|
+
* args: ['worker.js']
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Create pipe/socket client
|
|
20
|
+
* const client = TransportFactory.createPipeClient({
|
|
21
|
+
* path: '/tmp/my-socket.sock'
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Create pipe/socket server
|
|
25
|
+
* const server = TransportFactory.createPipeServer();
|
|
26
|
+
* await server.listen('/tmp/my-socket.sock');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class TransportFactory {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a stdio transport for child process communication.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Stdio transport options
|
|
34
|
+
* @returns StdioTransport instance
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const transport = TransportFactory.createStdio({
|
|
39
|
+
* executablePath: 'node',
|
|
40
|
+
* args: ['worker.js'],
|
|
41
|
+
* cwd: '/path/to/project'
|
|
42
|
+
* });
|
|
43
|
+
* await transport.connect();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
static createStdio(options: StdioTransportOptions): StdioTransport;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a pipe/socket client transport.
|
|
49
|
+
*
|
|
50
|
+
* Automatically uses the appropriate implementation for the current platform:
|
|
51
|
+
* - Windows: Named Pipes
|
|
52
|
+
* - Unix: Unix Domain Sockets
|
|
53
|
+
*
|
|
54
|
+
* @param options - Socket transport options
|
|
55
|
+
* @returns SocketTransport instance
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const transport = TransportFactory.createPipeClient({
|
|
60
|
+
* path: isWindows() ? '\\\\.\\pipe\\my-pipe' : '/tmp/my-socket.sock',
|
|
61
|
+
* connectionTimeout: 5000
|
|
62
|
+
* });
|
|
63
|
+
* await transport.connect();
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
static createPipeClient(options: SocketTransportOptions): Transport;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a pipe/socket server.
|
|
69
|
+
*
|
|
70
|
+
* Automatically uses the appropriate implementation for the current platform:
|
|
71
|
+
* - Windows: Named Pipe Server
|
|
72
|
+
* - Unix: Unix Domain Socket Server
|
|
73
|
+
*
|
|
74
|
+
* @param options - Socket server options
|
|
75
|
+
* @returns SocketServer instance
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const server = TransportFactory.createPipeServer();
|
|
80
|
+
* await server.listen('/tmp/my-socket.sock');
|
|
81
|
+
*
|
|
82
|
+
* server.onConnection(transport => {
|
|
83
|
+
* console.log('Client connected');
|
|
84
|
+
* transport.onData(data => {
|
|
85
|
+
* transport.write(data); // Echo back
|
|
86
|
+
* });
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
static createPipeServer(options?: SocketServerOptions): TransportServer;
|
|
91
|
+
/**
|
|
92
|
+
* Creates an optimal transport based on options and platform.
|
|
93
|
+
*
|
|
94
|
+
* Automatically selects:
|
|
95
|
+
* - Stdio transport if executablePath is provided
|
|
96
|
+
* - Pipe/socket transport if path is provided
|
|
97
|
+
*
|
|
98
|
+
* @param options - Mixed transport options
|
|
99
|
+
* @returns Transport instance
|
|
100
|
+
* @throws {TransportError} if options are invalid or ambiguous
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Stdio transport
|
|
105
|
+
* const stdio = TransportFactory.createOptimal({
|
|
106
|
+
* executablePath: 'node',
|
|
107
|
+
* args: ['worker.js']
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // Pipe transport
|
|
111
|
+
* const pipe = TransportFactory.createOptimal({
|
|
112
|
+
* path: '/tmp/my-socket.sock'
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
static createOptimal(options: (StdioTransportOptions | SocketTransportOptions) & {
|
|
117
|
+
executablePath?: string;
|
|
118
|
+
path?: string;
|
|
119
|
+
}): Transport;
|
|
120
|
+
/**
|
|
121
|
+
* Validates if a path is valid for the current platform.
|
|
122
|
+
*
|
|
123
|
+
* @param path - Path to validate
|
|
124
|
+
* @returns true if path is valid for current platform
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // Windows
|
|
129
|
+
* TransportFactory.isValidPath('\\\\.\\pipe\\my-pipe'); // true
|
|
130
|
+
* TransportFactory.isValidPath('/tmp/socket.sock'); // false (Unix path on Windows)
|
|
131
|
+
*
|
|
132
|
+
* // Unix
|
|
133
|
+
* TransportFactory.isValidPath('/tmp/socket.sock'); // true
|
|
134
|
+
* TransportFactory.isValidPath('\\\\.\\pipe\\my-pipe'); // false (Windows path on Unix)
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
static isValidPath(path: string): boolean;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/transport/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc;IAIlE;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS;IAInE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,eAAe;IAIvE;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,aAAa,CAClB,OAAO,EAAE,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,GAAG;QAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GACA,SAAS;IAgBZ;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAS1C"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { TransportError } from "../utils/errors.js";
|
|
2
|
+
import { isWindows } from "../utils/platform.js";
|
|
3
|
+
import { StdioTransport } from "./stdio-transport.js";
|
|
4
|
+
import { SocketTransport } from "./socket-transport.js";
|
|
5
|
+
import { SocketServer } from "./socket-server.js";
|
|
6
|
+
/**
|
|
7
|
+
* Factory for creating transport instances.
|
|
8
|
+
*
|
|
9
|
+
* Provides convenient methods for creating different types of transports
|
|
10
|
+
* with platform-specific optimizations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Create stdio transport for child process
|
|
15
|
+
* const transport = TransportFactory.createStdio({
|
|
16
|
+
* executablePath: 'node',
|
|
17
|
+
* args: ['worker.js']
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Create pipe/socket client
|
|
21
|
+
* const client = TransportFactory.createPipeClient({
|
|
22
|
+
* path: '/tmp/my-socket.sock'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Create pipe/socket server
|
|
26
|
+
* const server = TransportFactory.createPipeServer();
|
|
27
|
+
* await server.listen('/tmp/my-socket.sock');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class TransportFactory {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a stdio transport for child process communication.
|
|
33
|
+
*
|
|
34
|
+
* @param options - Stdio transport options
|
|
35
|
+
* @returns StdioTransport instance
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const transport = TransportFactory.createStdio({
|
|
40
|
+
* executablePath: 'node',
|
|
41
|
+
* args: ['worker.js'],
|
|
42
|
+
* cwd: '/path/to/project'
|
|
43
|
+
* });
|
|
44
|
+
* await transport.connect();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
static createStdio(options) {
|
|
48
|
+
return new StdioTransport(options);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a pipe/socket client transport.
|
|
52
|
+
*
|
|
53
|
+
* Automatically uses the appropriate implementation for the current platform:
|
|
54
|
+
* - Windows: Named Pipes
|
|
55
|
+
* - Unix: Unix Domain Sockets
|
|
56
|
+
*
|
|
57
|
+
* @param options - Socket transport options
|
|
58
|
+
* @returns SocketTransport instance
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const transport = TransportFactory.createPipeClient({
|
|
63
|
+
* path: isWindows() ? '\\\\.\\pipe\\my-pipe' : '/tmp/my-socket.sock',
|
|
64
|
+
* connectionTimeout: 5000
|
|
65
|
+
* });
|
|
66
|
+
* await transport.connect();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
static createPipeClient(options) {
|
|
70
|
+
return new SocketTransport(options);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a pipe/socket server.
|
|
74
|
+
*
|
|
75
|
+
* Automatically uses the appropriate implementation for the current platform:
|
|
76
|
+
* - Windows: Named Pipe Server
|
|
77
|
+
* - Unix: Unix Domain Socket Server
|
|
78
|
+
*
|
|
79
|
+
* @param options - Socket server options
|
|
80
|
+
* @returns SocketServer instance
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const server = TransportFactory.createPipeServer();
|
|
85
|
+
* await server.listen('/tmp/my-socket.sock');
|
|
86
|
+
*
|
|
87
|
+
* server.onConnection(transport => {
|
|
88
|
+
* console.log('Client connected');
|
|
89
|
+
* transport.onData(data => {
|
|
90
|
+
* transport.write(data); // Echo back
|
|
91
|
+
* });
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
static createPipeServer(options) {
|
|
96
|
+
return new SocketServer(options);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates an optimal transport based on options and platform.
|
|
100
|
+
*
|
|
101
|
+
* Automatically selects:
|
|
102
|
+
* - Stdio transport if executablePath is provided
|
|
103
|
+
* - Pipe/socket transport if path is provided
|
|
104
|
+
*
|
|
105
|
+
* @param options - Mixed transport options
|
|
106
|
+
* @returns Transport instance
|
|
107
|
+
* @throws {TransportError} if options are invalid or ambiguous
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // Stdio transport
|
|
112
|
+
* const stdio = TransportFactory.createOptimal({
|
|
113
|
+
* executablePath: 'node',
|
|
114
|
+
* args: ['worker.js']
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // Pipe transport
|
|
118
|
+
* const pipe = TransportFactory.createOptimal({
|
|
119
|
+
* path: '/tmp/my-socket.sock'
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
static createOptimal(options) {
|
|
124
|
+
// Check for stdio (has executablePath)
|
|
125
|
+
if ("executablePath" in options && options.executablePath) {
|
|
126
|
+
return this.createStdio(options);
|
|
127
|
+
}
|
|
128
|
+
// Check for pipe/socket (has path)
|
|
129
|
+
if ("path" in options && options.path) {
|
|
130
|
+
return this.createPipeClient(options);
|
|
131
|
+
}
|
|
132
|
+
throw new TransportError("Invalid transport options: must provide either 'executablePath' (stdio) or 'path' (pipe/socket)");
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Validates if a path is valid for the current platform.
|
|
136
|
+
*
|
|
137
|
+
* @param path - Path to validate
|
|
138
|
+
* @returns true if path is valid for current platform
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* // Windows
|
|
143
|
+
* TransportFactory.isValidPath('\\\\.\\pipe\\my-pipe'); // true
|
|
144
|
+
* TransportFactory.isValidPath('/tmp/socket.sock'); // false (Unix path on Windows)
|
|
145
|
+
*
|
|
146
|
+
* // Unix
|
|
147
|
+
* TransportFactory.isValidPath('/tmp/socket.sock'); // true
|
|
148
|
+
* TransportFactory.isValidPath('\\\\.\\pipe\\my-pipe'); // false (Windows path on Unix)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
static isValidPath(path) {
|
|
152
|
+
if (isWindows()) {
|
|
153
|
+
// Windows Named Pipe: must start with \\.\pipe\
|
|
154
|
+
return path.startsWith("\\\\.\\pipe\\");
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// Unix: should be absolute path
|
|
158
|
+
return path.startsWith("/");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/transport/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAA8B,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,eAAe,EAA+B,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,YAAY,EAA4B,MAAM,oBAAoB,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,WAAW,CAAC,OAA8B;QAC/C,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAA+B;QACrD,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAA6B;QACnD,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,aAAa,CAClB,OAGC;QAED,uCAAuC;QACvC,IAAI,gBAAgB,IAAI,OAAO,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,OAAgC,CAAC,CAAC;QAC5D,CAAC;QAED,mCAAmC;QACnC,IAAI,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAiC,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,IAAI,cAAc,CACtB,iGAAiG,CAClG,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,WAAW,CAAC,IAAY;QAC7B,IAAI,SAAS,EAAE,EAAE,CAAC;YAChB,gDAAgD;YAChD,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,gCAAgC;YAChC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAG3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Core types
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
// Transport implementations
|
|
4
|
+
export * from "./stdio-transport.js";
|
|
5
|
+
export * from "./socket-transport.js";
|
|
6
|
+
export * from "./socket-server.js";
|
|
7
|
+
// Factory
|
|
8
|
+
export * from "./factory.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAE3B,4BAA4B;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,UAAU;AACV,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { TransportServer, TransportServerEvents, ServerAddress, Transport } from "./types.js";
|
|
2
|
+
import type { Unsubscribe } from "../utils/disposables.js";
|
|
3
|
+
/**
|
|
4
|
+
* Socket server options.
|
|
5
|
+
*/
|
|
6
|
+
export interface SocketServerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Optional: cleanup stale socket files before listening (Unix only).
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
cleanupBeforeListen?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Socket server implementation for Named Pipes (Windows) and Unix Domain Sockets.
|
|
15
|
+
*
|
|
16
|
+
* Accepts client connections and creates Transport instances for each connection.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const server = new SocketServer();
|
|
21
|
+
* const address = await server.listen('/tmp/my-server.sock');
|
|
22
|
+
*
|
|
23
|
+
* server.onConnection(transport => {
|
|
24
|
+
* console.log('Client connected');
|
|
25
|
+
* transport.onData(data => {
|
|
26
|
+
* console.log('received:', data);
|
|
27
|
+
* transport.write(data); // Echo back
|
|
28
|
+
* });
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class SocketServer implements TransportServer {
|
|
33
|
+
private readonly emitter;
|
|
34
|
+
private readonly options;
|
|
35
|
+
private server;
|
|
36
|
+
private _address;
|
|
37
|
+
private readonly connections;
|
|
38
|
+
constructor(options?: SocketServerOptions);
|
|
39
|
+
get isListening(): boolean;
|
|
40
|
+
get address(): ServerAddress | null;
|
|
41
|
+
listen(address: string | number): Promise<ServerAddress>;
|
|
42
|
+
close(): Promise<void>;
|
|
43
|
+
onConnection(handler: (transport: Transport) => void): Unsubscribe;
|
|
44
|
+
on<K extends keyof TransportServerEvents>(event: K, handler: (data: TransportServerEvents[K]) => void): Unsubscribe;
|
|
45
|
+
private handleConnection;
|
|
46
|
+
private cleanup;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=socket-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-server.d.ts","sourceRoot":"","sources":["../../src/transport/socket-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,aAAa,EAAE,SAAS,EAAmC,MAAM,YAAY,CAAC;AACpI,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,YAAa,YAAW,eAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IACrE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;gBAEvD,OAAO,GAAE,mBAAwB;IAM7C,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,OAAO,IAAI,aAAa,GAAG,IAAI,CAElC;IAEK,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA8CxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B5B,YAAY,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GAAG,WAAW;IAIlE,EAAE,CAAC,CAAC,SAAS,MAAM,qBAAqB,EACtC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,IAAI,GAChD,WAAW;IAId,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,OAAO;CAOhB"}
|