stream-protocol-toolkit 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/LICENSE +21 -0
- package/README.md +6 -0
- package/dist/Application/Application.d.ts +39 -0
- package/dist/Application/Application.js +156 -0
- package/dist/Application/ApplicationEventEnum.d.ts +6 -0
- package/dist/Application/ApplicationEventEnum.js +10 -0
- package/dist/Application/ApplicationEventMap.d.ts +15 -0
- package/dist/Application/ApplicationEventMap.js +2 -0
- package/dist/Application/ApplicationOptions.d.ts +12 -0
- package/dist/Application/ApplicationOptions.js +2 -0
- package/dist/Application/ApplicationState.d.ts +1 -0
- package/dist/Application/ApplicationState.js +2 -0
- package/dist/Application/ApplicationUnknownProtocolHandler.d.ts +5 -0
- package/dist/Application/ApplicationUnknownProtocolHandler.js +2 -0
- package/dist/Application/create-stream-context/CreateStreamContextInputDTO.d.ts +3 -0
- package/dist/Application/create-stream-context/CreateStreamContextInputDTO.js +2 -0
- package/dist/Application/create-stream-context/CreateStreamContextOutputDTO.d.ts +5 -0
- package/dist/Application/create-stream-context/CreateStreamContextOutputDTO.js +2 -0
- package/dist/Application/create-stream-context/index.d.ts +2 -0
- package/dist/Application/create-stream-context/index.js +2 -0
- package/dist/Application/factories/application-state-factory/ApplicationStateFactory.d.ts +5 -0
- package/dist/Application/factories/application-state-factory/ApplicationStateFactory.js +2 -0
- package/dist/Application/factories/application-state-factory/ApplicationStateFactoryInputDTO.d.ts +2 -0
- package/dist/Application/factories/application-state-factory/ApplicationStateFactoryInputDTO.js +2 -0
- package/dist/Application/factories/application-state-factory/ApplicationStateFactoryOutputDTO.d.ts +4 -0
- package/dist/Application/factories/application-state-factory/ApplicationStateFactoryOutputDTO.js +2 -0
- package/dist/Application/factories/application-state-factory/application-state-factory.d.ts +5 -0
- package/dist/Application/factories/application-state-factory/application-state-factory.js +8 -0
- package/dist/Application/factories/application-state-factory/index.d.ts +4 -0
- package/dist/Application/factories/application-state-factory/index.js +5 -0
- package/dist/Application/factories/index.d.ts +6 -0
- package/dist/Application/factories/index.js +22 -0
- package/dist/Application/factories/stream-buffer-factory/StreamBufferFactory.d.ts +5 -0
- package/dist/Application/factories/stream-buffer-factory/StreamBufferFactory.js +2 -0
- package/dist/Application/factories/stream-buffer-factory/StreamBufferFactoryInputDTO.d.ts +5 -0
- package/dist/Application/factories/stream-buffer-factory/StreamBufferFactoryInputDTO.js +2 -0
- package/dist/Application/factories/stream-buffer-factory/StreamBufferFactoryOutputDTO.d.ts +5 -0
- package/dist/Application/factories/stream-buffer-factory/StreamBufferFactoryOutputDTO.js +2 -0
- package/dist/Application/factories/stream-buffer-factory/index.d.ts +4 -0
- package/dist/Application/factories/stream-buffer-factory/index.js +5 -0
- package/dist/Application/factories/stream-buffer-factory/stream-buffer-factory.d.ts +5 -0
- package/dist/Application/factories/stream-buffer-factory/stream-buffer-factory.js +10 -0
- package/dist/Application/factories/stream-context-factory/StreamContextFactory.d.ts +5 -0
- package/dist/Application/factories/stream-context-factory/StreamContextFactory.js +2 -0
- package/dist/Application/factories/stream-context-factory/StreamContextFactoryInputDTO.d.ts +3 -0
- package/dist/Application/factories/stream-context-factory/StreamContextFactoryInputDTO.js +2 -0
- package/dist/Application/factories/stream-context-factory/StreamContextFactoryOutputDTO.d.ts +5 -0
- package/dist/Application/factories/stream-context-factory/StreamContextFactoryOutputDTO.js +2 -0
- package/dist/Application/factories/stream-context-factory/index.d.ts +4 -0
- package/dist/Application/factories/stream-context-factory/index.js +5 -0
- package/dist/Application/factories/stream-context-factory/stream-context-factory.d.ts +5 -0
- package/dist/Application/factories/stream-context-factory/stream-context-factory.js +12 -0
- package/dist/Application/factories/stream-context-state-factory/StreamContextStateFactory.d.ts +5 -0
- package/dist/Application/factories/stream-context-state-factory/StreamContextStateFactory.js +2 -0
- package/dist/Application/factories/stream-context-state-factory/StreamContextStateFactoryInputDTO.d.ts +2 -0
- package/dist/Application/factories/stream-context-state-factory/StreamContextStateFactoryInputDTO.js +2 -0
- package/dist/Application/factories/stream-context-state-factory/StreamContextStateFactoryOutputDTO.d.ts +4 -0
- package/dist/Application/factories/stream-context-state-factory/StreamContextStateFactoryOutputDTO.js +2 -0
- package/dist/Application/factories/stream-context-state-factory/index.d.ts +4 -0
- package/dist/Application/factories/stream-context-state-factory/index.js +5 -0
- package/dist/Application/factories/stream-context-state-factory/stream-context-state-factory.d.ts +5 -0
- package/dist/Application/factories/stream-context-state-factory/stream-context-state-factory.js +8 -0
- package/dist/Application/factories/stream-protocol-processor-factory/StreamProtocolProcessorFactory.d.ts +5 -0
- package/dist/Application/factories/stream-protocol-processor-factory/StreamProtocolProcessorFactory.js +2 -0
- package/dist/Application/factories/stream-protocol-processor-factory/StreamProtocolProcessorFactoryInputDTO.d.ts +2 -0
- package/dist/Application/factories/stream-protocol-processor-factory/StreamProtocolProcessorFactoryInputDTO.js +2 -0
- package/dist/Application/factories/stream-protocol-processor-factory/StreamProtocolProcessorFactoryOutputDTO.d.ts +5 -0
- package/dist/Application/factories/stream-protocol-processor-factory/StreamProtocolProcessorFactoryOutputDTO.js +2 -0
- package/dist/Application/factories/stream-protocol-processor-factory/index.d.ts +4 -0
- package/dist/Application/factories/stream-protocol-processor-factory/index.js +5 -0
- package/dist/Application/factories/stream-protocol-processor-factory/stream-protocol-processor-factory.d.ts +5 -0
- package/dist/Application/factories/stream-protocol-processor-factory/stream-protocol-processor-factory.js +13 -0
- package/dist/Application/factories/transform-stream-handler-factory/TransformStreamHandlerFactory.d.ts +5 -0
- package/dist/Application/factories/transform-stream-handler-factory/TransformStreamHandlerFactory.js +2 -0
- package/dist/Application/factories/transform-stream-handler-factory/TransformStreamHandlerFactoryInputDTO.d.ts +5 -0
- package/dist/Application/factories/transform-stream-handler-factory/TransformStreamHandlerFactoryInputDTO.js +2 -0
- package/dist/Application/factories/transform-stream-handler-factory/TransformStreamHandlerFactoryOutputDTO.d.ts +4 -0
- package/dist/Application/factories/transform-stream-handler-factory/TransformStreamHandlerFactoryOutputDTO.js +2 -0
- package/dist/Application/factories/transform-stream-handler-factory/index.d.ts +4 -0
- package/dist/Application/factories/transform-stream-handler-factory/index.js +5 -0
- package/dist/Application/factories/transform-stream-handler-factory/transform-stream-handler-factory.d.ts +5 -0
- package/dist/Application/factories/transform-stream-handler-factory/transform-stream-handler-factory.js +65 -0
- package/dist/Application/index.d.ts +9 -0
- package/dist/Application/index.js +24 -0
- package/dist/Application/start-stream/StartStreamInputDTO.d.ts +5 -0
- package/dist/Application/start-stream/StartStreamInputDTO.js +2 -0
- package/dist/Application/start-stream/StartStreamOutputDTO.d.ts +2 -0
- package/dist/Application/start-stream/StartStreamOutputDTO.js +2 -0
- package/dist/Application/start-stream/index.d.ts +2 -0
- package/dist/Application/start-stream/index.js +2 -0
- package/dist/Protocol/Protocol.d.ts +12 -0
- package/dist/Protocol/Protocol.js +84 -0
- package/dist/Protocol/ProtocolInitValue.d.ts +4 -0
- package/dist/Protocol/ProtocolInitValue.js +2 -0
- package/dist/Protocol/ProtocolOptions.d.ts +1 -0
- package/dist/Protocol/ProtocolOptions.js +2 -0
- package/dist/Protocol/index.d.ts +3 -0
- package/dist/Protocol/index.js +5 -0
- package/dist/ProtocolHandler/ProtocolHandler.d.ts +6 -0
- package/dist/ProtocolHandler/ProtocolHandler.js +6 -0
- package/dist/ProtocolHandler/ProtocolHandlerOptions.d.ts +1 -0
- package/dist/ProtocolHandler/ProtocolHandlerOptions.js +2 -0
- package/dist/ProtocolHandler/handle/HandleInputDTO.d.ts +7 -0
- package/dist/ProtocolHandler/handle/HandleInputDTO.js +2 -0
- package/dist/ProtocolHandler/handle/HandleOutputDTO.d.ts +3 -0
- package/dist/ProtocolHandler/handle/HandleOutputDTO.js +2 -0
- package/dist/ProtocolHandler/handle/index.d.ts +2 -0
- package/dist/ProtocolHandler/handle/index.js +2 -0
- package/dist/ProtocolHandler/index.d.ts +3 -0
- package/dist/ProtocolHandler/index.js +20 -0
- package/dist/RawPacket/RawPacket.d.ts +5 -0
- package/dist/RawPacket/RawPacket.js +2 -0
- package/dist/RawPacket/RawPacketHeader.d.ts +4 -0
- package/dist/RawPacket/RawPacketHeader.js +2 -0
- package/dist/RawPacket/index.d.ts +2 -0
- package/dist/RawPacket/index.js +2 -0
- package/dist/StreamBuffer/StreamBuffer.d.ts +14 -0
- package/dist/StreamBuffer/StreamBuffer.js +59 -0
- package/dist/StreamBuffer/StreamBufferOptions.d.ts +5 -0
- package/dist/StreamBuffer/StreamBufferOptions.js +2 -0
- package/dist/StreamBuffer/index.d.ts +2 -0
- package/dist/StreamBuffer/index.js +5 -0
- package/dist/StreamContext/StreamContext.d.ts +17 -0
- package/dist/StreamContext/StreamContext.js +18 -0
- package/dist/StreamContext/StreamContextOptions.d.ts +12 -0
- package/dist/StreamContext/StreamContextOptions.js +2 -0
- package/dist/StreamContext/index.d.ts +2 -0
- package/dist/StreamContext/index.js +5 -0
- package/dist/StreamProtocolProcessor/StreamProtocolProcessor.d.ts +28 -0
- package/dist/StreamProtocolProcessor/StreamProtocolProcessor.js +137 -0
- package/dist/StreamProtocolProcessor/StreamProtocolProcessorOptions.d.ts +10 -0
- package/dist/StreamProtocolProcessor/StreamProtocolProcessorOptions.js +2 -0
- package/dist/StreamProtocolProcessor/index.d.ts +2 -0
- package/dist/StreamProtocolProcessor/index.js +5 -0
- package/dist/errors/StreamProtocolToolkitAlreadyExistsError.d.ts +3 -0
- package/dist/errors/StreamProtocolToolkitAlreadyExistsError.js +7 -0
- package/dist/errors/StreamProtocolToolkitError.d.ts +3 -0
- package/dist/errors/StreamProtocolToolkitError.js +13 -0
- package/dist/errors/StreamProtocolToolkitNotImplementedError.d.ts +3 -0
- package/dist/errors/StreamProtocolToolkitNotImplementedError.js +7 -0
- package/dist/errors/StreamProtocolToolkitTypeError.d.ts +3 -0
- package/dist/errors/StreamProtocolToolkitTypeError.js +7 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +11 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +25 -0
- package/dist/utils/any-signal.d.ts +1 -0
- package/dist/utils/any-signal.js +34 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +13 -0
- package/dist/utils/is-plain-object.d.ts +1 -0
- package/dist/utils/is-plain-object.js +13 -0
- package/dist/utils/is-readable-stream-alive.d.ts +2 -0
- package/dist/utils/is-readable-stream-alive.js +21 -0
- package/dist/utils/is-writable-stream-alive.d.ts +2 -0
- package/dist/utils/is-writable-stream-alive.js +24 -0
- package/dist/utils/read-paused-stream-chunk.d.ts +3 -0
- package/dist/utils/read-paused-stream-chunk.js +51 -0
- package/package.json +48 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { Application } from '../../Application';
|
|
3
|
+
import type { StreamProtocolProcessorFactoryInputDTO } from './StreamProtocolProcessorFactoryInputDTO';
|
|
4
|
+
import type { StreamProtocolProcessorFactoryOutputDTO } from './StreamProtocolProcessorFactoryOutputDTO';
|
|
5
|
+
export type StreamProtocolProcessorFactory<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> = (this: Application<ISTREAM, OSTREAM, AS, SCS>, input: StreamProtocolProcessorFactoryInputDTO<ISTREAM, OSTREAM, AS, SCS>) => StreamProtocolProcessorFactoryOutputDTO<ISTREAM, OSTREAM, AS, SCS>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { StreamProtocolProcessor } from '../../../StreamProtocolProcessor';
|
|
3
|
+
export type StreamProtocolProcessorFactoryOutputDTO<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> = {
|
|
4
|
+
streamProtocolProcessor: StreamProtocolProcessor<ISTREAM, OSTREAM, AS, SCS>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { streamProtocolProcessorFactory } from './stream-protocol-processor-factory';
|
|
2
|
+
export type { StreamProtocolProcessorFactory } from './StreamProtocolProcessorFactory';
|
|
3
|
+
export type { StreamProtocolProcessorFactoryInputDTO } from './StreamProtocolProcessorFactoryInputDTO';
|
|
4
|
+
export type { StreamProtocolProcessorFactoryOutputDTO } from './StreamProtocolProcessorFactoryOutputDTO';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamProtocolProcessorFactory = void 0;
|
|
4
|
+
var stream_protocol_processor_factory_1 = require("./stream-protocol-processor-factory");
|
|
5
|
+
Object.defineProperty(exports, "streamProtocolProcessorFactory", { enumerable: true, get: function () { return stream_protocol_processor_factory_1.streamProtocolProcessorFactory; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { Application } from '../../Application';
|
|
3
|
+
import type { StreamProtocolProcessorFactoryInputDTO } from './StreamProtocolProcessorFactoryInputDTO';
|
|
4
|
+
import type { StreamProtocolProcessorFactoryOutputDTO } from './StreamProtocolProcessorFactoryOutputDTO';
|
|
5
|
+
export declare function streamProtocolProcessorFactory<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object>(this: Application<ISTREAM, OSTREAM, AS, SCS>, input: StreamProtocolProcessorFactoryInputDTO<ISTREAM, OSTREAM, AS, SCS>): StreamProtocolProcessorFactoryOutputDTO<ISTREAM, OSTREAM, AS, SCS>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamProtocolProcessorFactory = streamProtocolProcessorFactory;
|
|
4
|
+
const StreamProtocolProcessor_1 = require("../../../StreamProtocolProcessor");
|
|
5
|
+
function streamProtocolProcessorFactory(input) {
|
|
6
|
+
const { streamBuffer } = this.streamBufferFactory({});
|
|
7
|
+
return {
|
|
8
|
+
streamProtocolProcessor: new StreamProtocolProcessor_1.StreamProtocolProcessor({
|
|
9
|
+
streamBuffer,
|
|
10
|
+
application: this
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { Application } from '../../Application';
|
|
3
|
+
import type { TransformStreamHandlerFactoryInputDTO } from './TransformStreamHandlerFactoryInputDTO';
|
|
4
|
+
import type { TransformStreamHandlerFactoryOutputDTO } from './TransformStreamHandlerFactoryOutputDTO';
|
|
5
|
+
export type TransformStreamHandlerFactory<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> = (this: Application<ISTREAM, OSTREAM, AS, SCS>, input: TransformStreamHandlerFactoryInputDTO<ISTREAM, OSTREAM, AS, SCS>) => TransformStreamHandlerFactoryOutputDTO<ISTREAM, OSTREAM, AS, SCS>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { StreamContext } from '../../../StreamContext';
|
|
3
|
+
export type TransformStreamHandlerFactoryInputDTO<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> = {
|
|
4
|
+
streamContext: StreamContext<ISTREAM, OSTREAM, AS, SCS>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { transformStreamHandlerFactory } from './transform-stream-handler-factory';
|
|
2
|
+
export type { TransformStreamHandlerFactory } from './TransformStreamHandlerFactory';
|
|
3
|
+
export type { TransformStreamHandlerFactoryInputDTO } from './TransformStreamHandlerFactoryInputDTO';
|
|
4
|
+
export type { TransformStreamHandlerFactoryOutputDTO } from './TransformStreamHandlerFactoryOutputDTO';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformStreamHandlerFactory = void 0;
|
|
4
|
+
var transform_stream_handler_factory_1 = require("./transform-stream-handler-factory");
|
|
5
|
+
Object.defineProperty(exports, "transformStreamHandlerFactory", { enumerable: true, get: function () { return transform_stream_handler_factory_1.transformStreamHandlerFactory; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Application } from '../../Application';
|
|
2
|
+
import { Readable, Writable } from 'stream';
|
|
3
|
+
import type { TransformStreamHandlerFactoryInputDTO } from './TransformStreamHandlerFactoryInputDTO';
|
|
4
|
+
import type { TransformStreamHandlerFactoryOutputDTO } from './TransformStreamHandlerFactoryOutputDTO';
|
|
5
|
+
export declare function transformStreamHandlerFactory<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object>(this: Application<ISTREAM, OSTREAM, AS, SCS>, input: TransformStreamHandlerFactoryInputDTO<ISTREAM, OSTREAM, AS, SCS>): TransformStreamHandlerFactoryOutputDTO<ISTREAM, OSTREAM, AS, SCS>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformStreamHandlerFactory = transformStreamHandlerFactory;
|
|
4
|
+
const Protocol_1 = require("../../../Protocol");
|
|
5
|
+
const StreamBuffer_1 = require("../../../StreamBuffer");
|
|
6
|
+
const errors_1 = require("../../../errors");
|
|
7
|
+
const stream_1 = require("stream");
|
|
8
|
+
function transformStreamHandlerFactory(input) {
|
|
9
|
+
const { streamContext } = input;
|
|
10
|
+
const application = streamContext.application;
|
|
11
|
+
const streamProtocolProcessor = streamContext.streamProtocolProcessor;
|
|
12
|
+
const transformStreamHandler = new stream_1.Transform({
|
|
13
|
+
transform: async function (chunk, encoding, callback) {
|
|
14
|
+
try {
|
|
15
|
+
streamProtocolProcessor.pushChunk(chunk).assertState();
|
|
16
|
+
if (streamProtocolProcessor.packetIsReadable(streamProtocolProcessor.streamBuffer)) {
|
|
17
|
+
do {
|
|
18
|
+
const rawPacket = streamProtocolProcessor.readPacket(streamProtocolProcessor.streamBuffer);
|
|
19
|
+
const protocol = application.protocols.get(rawPacket.opcode);
|
|
20
|
+
if (protocol) {
|
|
21
|
+
const protocolPacket = new protocol.protocolClass(rawPacket.payload);
|
|
22
|
+
let result = await protocol.protocolHandler.handle({
|
|
23
|
+
packet: protocolPacket,
|
|
24
|
+
streamContext
|
|
25
|
+
});
|
|
26
|
+
if (result !== undefined) {
|
|
27
|
+
if (result instanceof Protocol_1.Protocol) {
|
|
28
|
+
const protocolBuffer = result._marshal();
|
|
29
|
+
streamProtocolProcessor.writePacketHeader(protocolBuffer, {
|
|
30
|
+
opcode: result._opcode,
|
|
31
|
+
length: protocolBuffer.length
|
|
32
|
+
}, true);
|
|
33
|
+
this.push(protocolBuffer.nativeBufferView);
|
|
34
|
+
}
|
|
35
|
+
else if (result instanceof StreamBuffer_1.StreamBuffer) {
|
|
36
|
+
this.push(result.nativeBufferView);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new errors_1.StreamProtocolToolkitError('PROTOCOL_HANDLER_INVALID_RESULT');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (application.unknownProtocolHandler) {
|
|
44
|
+
const result = await application.unknownProtocolHandler(rawPacket, streamContext);
|
|
45
|
+
if (result) {
|
|
46
|
+
this.push(result);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new errors_1.StreamProtocolToolkitError('UNHANDLED_RAW_PACKET');
|
|
51
|
+
}
|
|
52
|
+
} while (streamProtocolProcessor.packetIsReadable(streamProtocolProcessor.streamBuffer));
|
|
53
|
+
streamProtocolProcessor.streamBuffer.discardReadData();
|
|
54
|
+
}
|
|
55
|
+
callback();
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
callback(e !== null && e !== void 0 ? e : new errors_1.StreamProtocolToolkitError('UNKNOWN_TRANSFORM_STREAM_ERROR'));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
transformStreamHandler
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './factories';
|
|
2
|
+
export * from './start-stream';
|
|
3
|
+
export * from './create-stream-context';
|
|
4
|
+
export { Application } from './Application';
|
|
5
|
+
export type { ApplicationState } from './ApplicationState';
|
|
6
|
+
export { ApplicationEventEnum } from './ApplicationEventEnum';
|
|
7
|
+
export type { ApplicationOptions } from './ApplicationOptions';
|
|
8
|
+
export type { ApplicationEventMap } from './ApplicationEventMap';
|
|
9
|
+
export type { ApplicationUnknownProtocolHandler } from './ApplicationUnknownProtocolHandler';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ApplicationEventEnum = exports.Application = void 0;
|
|
18
|
+
__exportStar(require("./factories"), exports);
|
|
19
|
+
__exportStar(require("./start-stream"), exports);
|
|
20
|
+
__exportStar(require("./create-stream-context"), exports);
|
|
21
|
+
var Application_1 = require("./Application");
|
|
22
|
+
Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return Application_1.Application; } });
|
|
23
|
+
var ApplicationEventEnum_1 = require("./ApplicationEventEnum");
|
|
24
|
+
Object.defineProperty(exports, "ApplicationEventEnum", { enumerable: true, get: function () { return ApplicationEventEnum_1.ApplicationEventEnum; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'stream';
|
|
2
|
+
import type { StreamContext } from '../../StreamContext';
|
|
3
|
+
export type StartStreamInputDTO<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> = {
|
|
4
|
+
streamContext: StreamContext<ISTREAM, OSTREAM, AS, SCS>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProtocolInitValue } from './ProtocolInitValue';
|
|
2
|
+
import { StreamBuffer, StreamBufferOptions } from '../StreamBuffer';
|
|
3
|
+
export declare abstract class Protocol {
|
|
4
|
+
_isInitialized: boolean;
|
|
5
|
+
protected constructor();
|
|
6
|
+
_initialize<T extends Protocol>(initValue: ProtocolInitValue<T>): void;
|
|
7
|
+
_createBuffer(options?: StreamBufferOptions): StreamBuffer;
|
|
8
|
+
get _opcode(): number;
|
|
9
|
+
static get _opcode(): number;
|
|
10
|
+
abstract _marshal(): StreamBuffer;
|
|
11
|
+
abstract _unmarshal(buffer: StreamBuffer): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Protocol = void 0;
|
|
37
|
+
const utils = __importStar(require("../utils"));
|
|
38
|
+
const StreamBuffer_1 = require("../StreamBuffer");
|
|
39
|
+
const errors_1 = require("../errors");
|
|
40
|
+
const reservedPropertyNames = new Set([
|
|
41
|
+
'_opcode', '_isInitialized', '__proto__', 'constructor', 'prototype'
|
|
42
|
+
]);
|
|
43
|
+
class Protocol {
|
|
44
|
+
constructor() {
|
|
45
|
+
this._isInitialized = false;
|
|
46
|
+
}
|
|
47
|
+
_initialize(initValue) {
|
|
48
|
+
if (initValue instanceof StreamBuffer_1.StreamBuffer) {
|
|
49
|
+
this._unmarshal(initValue);
|
|
50
|
+
}
|
|
51
|
+
else if (utils.isPlainObject(initValue)) {
|
|
52
|
+
for (const [key, value] of Object.entries(initValue)) {
|
|
53
|
+
if (reservedPropertyNames.has(key)) {
|
|
54
|
+
throw new errors_1.StreamProtocolToolkitTypeError(`FORBIDDEN_KEY`);
|
|
55
|
+
}
|
|
56
|
+
if (this[key] !== undefined) {
|
|
57
|
+
throw new errors_1.StreamProtocolToolkitTypeError(`FIELD_ALREADY_EXISTS`);
|
|
58
|
+
}
|
|
59
|
+
Object.defineProperty(this, key, {
|
|
60
|
+
value,
|
|
61
|
+
writable: true,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new errors_1.StreamProtocolToolkitTypeError('INVALID_PROTOCOL_INIT_VALUE_TYPE');
|
|
69
|
+
}
|
|
70
|
+
this._isInitialized = true;
|
|
71
|
+
}
|
|
72
|
+
_createBuffer(options) {
|
|
73
|
+
const buffer = new StreamBuffer_1.StreamBuffer(options);
|
|
74
|
+
return buffer.allocEnd(buffer.getWritableSize());
|
|
75
|
+
}
|
|
76
|
+
get _opcode() {
|
|
77
|
+
return this.constructor._opcode;
|
|
78
|
+
}
|
|
79
|
+
static get _opcode() {
|
|
80
|
+
throw new errors_1.StreamProtocolToolkitNotImplementedError('PROTOCOL_OPCODE_NOT_DEFINED');
|
|
81
|
+
}
|
|
82
|
+
;
|
|
83
|
+
}
|
|
84
|
+
exports.Protocol = Protocol;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Protocol } from './Protocol';
|
|
2
|
+
import type { StreamBuffer } from '../StreamBuffer';
|
|
3
|
+
import type { NonFunctionKeys } from 'utility-types';
|
|
4
|
+
export type ProtocolInitValue<T extends Protocol> = StreamBuffer | Omit<Pick<T, NonFunctionKeys<T>>, '_opcode' | '_isInitialized'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ProtocolOptions = void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Protocol } from '../Protocol';
|
|
2
|
+
import type { Readable, Writable } from 'stream';
|
|
3
|
+
import type { HandleInputDTO, HandleOutputDTO } from './handle';
|
|
4
|
+
export declare abstract class ProtocolHandler<PROT extends Protocol, ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> {
|
|
5
|
+
abstract handle(input: HandleInputDTO<PROT, ISTREAM, OSTREAM, AS, SCS>): Promise<HandleOutputDTO>;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ProtocolHandlerOptions = void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Protocol } from '../../Protocol';
|
|
2
|
+
import type { Readable, Writable } from 'stream';
|
|
3
|
+
import type { StreamContext } from '../../StreamContext';
|
|
4
|
+
export type HandleInputDTO<PROT extends Protocol, ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> = {
|
|
5
|
+
packet: PROT;
|
|
6
|
+
streamContext: StreamContext<ISTREAM, OSTREAM, AS, SCS>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ProtocolHandler = void 0;
|
|
18
|
+
__exportStar(require("./handle"), exports);
|
|
19
|
+
var ProtocolHandler_1 = require("./ProtocolHandler");
|
|
20
|
+
Object.defineProperty(exports, "ProtocolHandler", { enumerable: true, get: function () { return ProtocolHandler_1.ProtocolHandler; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ExtendedBuffer } from 'extended-buffer';
|
|
2
|
+
import type { StreamBufferOptions } from './StreamBufferOptions';
|
|
3
|
+
export declare class StreamBuffer<SBO extends StreamBufferOptions = StreamBufferOptions> extends ExtendedBuffer<SBO> {
|
|
4
|
+
readonly packetStringLengthSize: number;
|
|
5
|
+
readonly packetStringEncoding: BufferEncoding;
|
|
6
|
+
constructor(options?: StreamBufferOptions);
|
|
7
|
+
protected createInstanceOptions(options?: StreamBufferOptions): StreamBufferOptions;
|
|
8
|
+
readPacketStringLength(): number;
|
|
9
|
+
writePacketStringLength(value: number, unshift?: boolean): this;
|
|
10
|
+
packetStringLengthIsReadable(): boolean;
|
|
11
|
+
readPacketString(encoding?: BufferEncoding): string;
|
|
12
|
+
writePacketString(string: string, unshift?: boolean, encoding?: BufferEncoding): this;
|
|
13
|
+
packetStringIsReadable(): boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamBuffer = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
const extended_buffer_1 = require("extended-buffer");
|
|
6
|
+
const DEFAULT_PACKET_STRING_PAYLOAD_LENGTH_SIZE = 4;
|
|
7
|
+
const DEFAULT_PACKET_STRING_ENCODING = 'utf8';
|
|
8
|
+
class StreamBuffer extends extended_buffer_1.ExtendedBuffer {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
super(options);
|
|
12
|
+
this.packetStringEncoding = (_a = options === null || options === void 0 ? void 0 : options.packetStringEncoding) !== null && _a !== void 0 ? _a : DEFAULT_PACKET_STRING_ENCODING;
|
|
13
|
+
this.packetStringLengthSize = (_b = options === null || options === void 0 ? void 0 : options.packetStringLengthSize) !== null && _b !== void 0 ? _b : DEFAULT_PACKET_STRING_PAYLOAD_LENGTH_SIZE;
|
|
14
|
+
}
|
|
15
|
+
createInstanceOptions(options) {
|
|
16
|
+
return Object.assign({
|
|
17
|
+
packetStringEncoding: this.packetStringEncoding,
|
|
18
|
+
packetStringLengthSize: this.packetStringLengthSize
|
|
19
|
+
}, super.createInstanceOptions(options));
|
|
20
|
+
}
|
|
21
|
+
readPacketStringLength() {
|
|
22
|
+
return this.readUIntBE(this.packetStringLengthSize);
|
|
23
|
+
}
|
|
24
|
+
writePacketStringLength(value, unshift) {
|
|
25
|
+
return this.writeUIntBE(value, this.packetStringLengthSize, unshift);
|
|
26
|
+
}
|
|
27
|
+
packetStringLengthIsReadable() {
|
|
28
|
+
return this.isReadable(this.packetStringLengthSize);
|
|
29
|
+
}
|
|
30
|
+
readPacketString(encoding) {
|
|
31
|
+
const savedPointer = this.getPointer();
|
|
32
|
+
try {
|
|
33
|
+
const stringLength = this.readPacketStringLength();
|
|
34
|
+
return this.readString(stringLength, encoding !== null && encoding !== void 0 ? encoding : this.packetStringEncoding);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
this.setPointer(savedPointer);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
writePacketString(string, unshift, encoding) {
|
|
42
|
+
const bytes = buffer_1.Buffer.from(string, encoding !== null && encoding !== void 0 ? encoding : this.packetStringEncoding);
|
|
43
|
+
const data = (new StreamBuffer({
|
|
44
|
+
capacity: bytes.length + this.packetStringLengthSize,
|
|
45
|
+
capacityStep: 0
|
|
46
|
+
})).writePacketStringLength(bytes.length).writeNativeBuffer(bytes);
|
|
47
|
+
return this.writeNativeBuffer(data.nativeBufferView, unshift);
|
|
48
|
+
}
|
|
49
|
+
packetStringIsReadable() {
|
|
50
|
+
const savedPointer = this.getPointer();
|
|
51
|
+
try {
|
|
52
|
+
return this.packetStringLengthIsReadable() && this.isReadable(this.readPacketStringLength());
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
this.setPointer(savedPointer);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.StreamBuffer = StreamBuffer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamBuffer = void 0;
|
|
4
|
+
var StreamBuffer_1 = require("./StreamBuffer");
|
|
5
|
+
Object.defineProperty(exports, "StreamBuffer", { enumerable: true, get: function () { return StreamBuffer_1.StreamBuffer; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Application } from '../Application';
|
|
3
|
+
import type { Readable, Transform, Writable } from 'stream';
|
|
4
|
+
import type { StreamContextOptions } from './StreamContextOptions';
|
|
5
|
+
import type { StreamProtocolProcessor } from '../StreamProtocolProcessor';
|
|
6
|
+
export declare class StreamContext<ISTREAM extends Readable, OSTREAM extends Writable, AS extends object, SCS extends object> {
|
|
7
|
+
readonly input: ISTREAM;
|
|
8
|
+
readonly output?: OSTREAM;
|
|
9
|
+
readonly eventBus: EventEmitter;
|
|
10
|
+
readonly streamContextState: SCS;
|
|
11
|
+
readonly inputTransform?: Transform[];
|
|
12
|
+
readonly outputTransform?: Transform[];
|
|
13
|
+
readonly abortController: AbortController;
|
|
14
|
+
readonly application: Application<ISTREAM, OSTREAM, AS, SCS>;
|
|
15
|
+
readonly streamProtocolProcessor: StreamProtocolProcessor<ISTREAM, OSTREAM, AS, SCS>;
|
|
16
|
+
constructor(options: StreamContextOptions<ISTREAM, OSTREAM, AS, SCS>);
|
|
17
|
+
}
|