@inversifyjs/http-sse 1.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +6 -0
  4. package/lib/cjs/index.d.ts +5 -0
  5. package/lib/cjs/index.d.ts.map +1 -0
  6. package/lib/cjs/index.js +8 -0
  7. package/lib/cjs/index.js.map +1 -0
  8. package/lib/cjs/package.json +3 -0
  9. package/lib/cjs/sse/actions/Publisher.int.spec.d.ts +2 -0
  10. package/lib/cjs/sse/actions/Publisher.int.spec.d.ts.map +1 -0
  11. package/lib/cjs/sse/actions/SsePublisher.d.ts +4 -0
  12. package/lib/cjs/sse/actions/SsePublisher.d.ts.map +1 -0
  13. package/lib/cjs/sse/actions/SsePublisher.js +33 -0
  14. package/lib/cjs/sse/actions/SsePublisher.js.map +1 -0
  15. package/lib/cjs/sse/calculations/stringifyMessageEvent.d.ts +3 -0
  16. package/lib/cjs/sse/calculations/stringifyMessageEvent.d.ts.map +1 -0
  17. package/lib/cjs/sse/calculations/stringifyMessageEvent.js +23 -0
  18. package/lib/cjs/sse/calculations/stringifyMessageEvent.js.map +1 -0
  19. package/lib/cjs/sse/calculations/stringifyMessageEvent.spec.d.ts +2 -0
  20. package/lib/cjs/sse/calculations/stringifyMessageEvent.spec.d.ts.map +1 -0
  21. package/lib/cjs/sse/models/MessageEvent.d.ts +7 -0
  22. package/lib/cjs/sse/models/MessageEvent.d.ts.map +1 -0
  23. package/lib/cjs/sse/models/MessageEvent.js +3 -0
  24. package/lib/cjs/sse/models/MessageEvent.js.map +1 -0
  25. package/lib/cjs/sse/models/SsePublisherOptions.d.ts +8 -0
  26. package/lib/cjs/sse/models/SsePublisherOptions.d.ts.map +1 -0
  27. package/lib/cjs/sse/models/SsePublisherOptions.js +3 -0
  28. package/lib/cjs/sse/models/SsePublisherOptions.js.map +1 -0
  29. package/lib/cjs/stream/models/SseStream.d.ts +13 -0
  30. package/lib/cjs/stream/models/SseStream.d.ts.map +1 -0
  31. package/lib/cjs/stream/models/SseStream.js +43 -0
  32. package/lib/cjs/stream/models/SseStream.js.map +1 -0
  33. package/lib/cjs/stream/models/SseStream.spec.d.ts +2 -0
  34. package/lib/cjs/stream/models/SseStream.spec.d.ts.map +1 -0
  35. package/lib/esm/index.d.ts +31 -0
  36. package/lib/esm/index.d.ts.map +1 -0
  37. package/lib/esm/index.js +2 -0
  38. package/lib/esm/index.js.map +1 -0
  39. package/lib/esm/package.json +3 -0
  40. package/package.json +86 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @inversifyjs/http-sse
2
+
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `MessageEvent`
8
+ - Added `SsePublisher`
9
+ - Added `SsePublisherOptions`
10
+ - Added `SseStream`
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+ - @inversifyjs/http-core@4.7.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 inversify
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ [![Test coverage](https://codecov.io/gh/inversify/monorepo/branch/main/graph/badge.svg?flag=%40inversifyjs%2Fhttp-sse)](https://codecov.io/gh/inversify/monorepo/branch/main/graph/badge.svg?flag=%40inversifyjs%2Fhttp-sse)
2
+ [![npm version](https://img.shields.io/github/package-json/v/inversify/monorepo?filename=packages%2Fframework%2Fhttp%2Flibraries%2Fsse%2Fpackage.json&style=plastic)](https://www.npmjs.com/package/@inversifyjs/http-sse)
3
+
4
+ # @inversifyjs/http-sse
5
+
6
+ Inversify monorepo http sse modules.
@@ -0,0 +1,5 @@
1
+ export type { MessageEvent } from './sse/models/MessageEvent';
2
+ export type { SsePublisherOptions } from './sse/models/SsePublisherOptions';
3
+ export { SseStream } from './stream/models/SseStream';
4
+ export { SsePublisher } from './sse/actions/SsePublisher';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SsePublisher = exports.SseStream = void 0;
4
+ var SseStream_1 = require("./stream/models/SseStream");
5
+ Object.defineProperty(exports, "SseStream", { enumerable: true, get: function () { return SseStream_1.SseStream; } });
6
+ var SsePublisher_1 = require("./sse/actions/SsePublisher");
7
+ Object.defineProperty(exports, "SsePublisher", { enumerable: true, get: function () { return SsePublisher_1.SsePublisher; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAEA,uDAAsD;AAA7C,sGAAA,SAAS,OAAA;AAElB,2DAA0D;AAAjD,4GAAA,YAAY,OAAA"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Publisher.int.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Publisher.int.spec.d.ts","sourceRoot":"","sources":["../../../../src/sse/actions/Publisher.int.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Pipe } from '@inversifyjs/framework-core';
2
+ import { ServiceIdentifier } from 'inversify';
3
+ export declare function SsePublisher<TResult = any>(...parameterPipeList: (ServiceIdentifier<Pipe> | Pipe)[]): ParameterDecorator;
4
+ //# sourceMappingURL=SsePublisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SsePublisher.d.ts","sourceRoot":"","sources":["../../../../src/sse/actions/SsePublisher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAMnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAgB9C,wBAAgB,YAAY,CAAC,OAAO,GAAG,GAAG,EACxC,GAAG,iBAAiB,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,GACvD,kBAAkB,CAoDpB"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SsePublisher = SsePublisher;
4
+ const node_stream_1 = require("node:stream");
5
+ const http_core_1 = require("@inversifyjs/http-core");
6
+ const SseStream_1 = require("../../stream/models/SseStream");
7
+ const stringifyMessageEvent_1 = require("../calculations/stringifyMessageEvent");
8
+ async function* mapMessageEventAsyncIterable(events) {
9
+ for await (const messageEvent of events) {
10
+ yield (0, stringifyMessageEvent_1.stringifyMessageEvent)(messageEvent);
11
+ }
12
+ }
13
+ // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unnecessary-type-parameters, @typescript-eslint/no-explicit-any
14
+ function SsePublisher(...parameterPipeList) {
15
+ return (0, http_core_1.createCustomNativeParameterDecorator)((request, response, options) => {
16
+ return async (sseOptions) => {
17
+ options.setStatus(request, response, sseOptions.statusCode ?? http_core_1.HttpStatusCode.OK);
18
+ options.setHeader(request, response, 'cache-control', 'private, no-cache, no-store, must-revalidate, max-age=0, no-transform');
19
+ options.setHeader(request, response, 'content-type', 'text/event-stream');
20
+ options.setHeader(request, response, 'expires', '0');
21
+ options.setHeader(request, response, 'pragma', 'no-cache');
22
+ options.setHeader(request, response, 'connection', 'keep-alive');
23
+ // NGINX support https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-buffering
24
+ options.setHeader(request, response, 'x-accel-buffering', 'no');
25
+ await options.sendBodySeparator(request, response);
26
+ const stream = SseStream_1.SseStream.is(sseOptions.events)
27
+ ? sseOptions.events
28
+ : node_stream_1.Readable.from(mapMessageEventAsyncIterable(sseOptions.events));
29
+ return options.send(request, response, stream);
30
+ };
31
+ }, ...parameterPipeList);
32
+ }
33
+ //# sourceMappingURL=SsePublisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SsePublisher.js","sourceRoot":"","sources":["../../../../src/sse/actions/SsePublisher.ts"],"names":[],"mappings":";;AAwBA,oCAsDC;AA9ED,6CAAuC;AAGvC,sDAIgC;AAGhC,6DAA0D;AAC1D,iFAA8E;AAI9E,KAAK,SAAS,CAAC,CAAC,4BAA4B,CAC1C,MAAmC;IAEnC,IAAI,KAAK,EAAE,MAAM,YAAY,IAAI,MAAM,EAAE,CAAC;QACxC,MAAM,IAAA,6CAAqB,EAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,uJAAuJ;AACvJ,SAAgB,YAAY,CAC1B,GAAG,iBAAqD;IAExD,OAAO,IAAA,gDAAoC,EAMzC,CACE,OAAgB,EAChB,QAAiB,EACjB,OAIC,EACwD,EAAE;QAC3D,OAAO,KAAK,EAAE,UAA+B,EAAoB,EAAE;YACjE,OAAO,CAAC,SAAS,CACf,OAAO,EACP,QAAQ,EACR,UAAU,CAAC,UAAU,IAAI,0BAAc,CAAC,EAAE,CAC3C,CAAC;YAEF,OAAO,CAAC,SAAS,CACf,OAAO,EACP,QAAQ,EACR,eAAe,EACf,uEAAuE,CACxE,CAAC;YACF,OAAO,CAAC,SAAS,CACf,OAAO,EACP,QAAQ,EACR,cAAc,EACd,mBAAmB,CACpB,CAAC;YACF,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;YACrD,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;YAC3D,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;YACjE,sGAAsG;YACtG,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;YAEhE,MAAM,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAa,qBAAS,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;gBACtD,CAAC,CAAC,UAAU,CAAC,MAAM;gBACnB,CAAC,CAAC,sBAAQ,CAAC,IAAI,CAAC,4BAA4B,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;YAEnE,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC,EACD,GAAG,iBAAiB,CACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { MessageEvent } from '../models/MessageEvent';
2
+ export declare function stringifyMessageEvent(messageEvent: MessageEvent): string;
3
+ //# sourceMappingURL=stringifyMessageEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringifyMessageEvent.d.ts","sourceRoot":"","sources":["../../../../src/sse/calculations/stringifyMessageEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AActD,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAexE"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyMessageEvent = stringifyMessageEvent;
4
+ function stringifyData(data) {
5
+ if (Array.isArray(data)) {
6
+ return data.map((line) => stringifyDataLine(line)).join('');
7
+ }
8
+ return stringifyDataLine(data);
9
+ }
10
+ function stringifyDataLine(line) {
11
+ return `data: ${line}\n`;
12
+ }
13
+ function stringifyMessageEvent(messageEvent) {
14
+ // Consider https://html.spec.whatwg.org/multipage/server-sent-events.html as reference
15
+ const stringifiedType = messageEvent.type === undefined ? '' : `event: ${messageEvent.type}\n`;
16
+ const stringifiedId = messageEvent.id === undefined ? '' : `id: ${messageEvent.id}\n`;
17
+ const stringifiedRetry = messageEvent.retry === undefined
18
+ ? ''
19
+ : `retry: ${messageEvent.retry.toString()}\n`;
20
+ const stringifiedData = stringifyData(messageEvent.data);
21
+ return (stringifiedType + stringifiedId + stringifiedRetry + stringifiedData + '\n');
22
+ }
23
+ //# sourceMappingURL=stringifyMessageEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringifyMessageEvent.js","sourceRoot":"","sources":["../../../../src/sse/calculations/stringifyMessageEvent.ts"],"names":[],"mappings":";;AAcA,sDAeC;AA3BD,SAAS,aAAa,CAAC,IAAuB;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,SAAS,IAAI,IAAI,CAAC;AAC3B,CAAC;AAED,SAAgB,qBAAqB,CAAC,YAA0B;IAC9D,uFAAuF;IACvF,MAAM,eAAe,GACnB,YAAY,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,YAAY,CAAC,IAAI,IAAI,CAAC;IACzE,MAAM,aAAa,GACjB,YAAY,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,YAAY,CAAC,EAAE,IAAI,CAAC;IAClE,MAAM,gBAAgB,GACpB,YAAY,CAAC,KAAK,KAAK,SAAS;QAC9B,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,UAAU,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;IAClD,MAAM,eAAe,GAAW,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjE,OAAO,CACL,eAAe,GAAG,aAAa,GAAG,gBAAgB,GAAG,eAAe,GAAG,IAAI,CAC5E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=stringifyMessageEvent.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringifyMessageEvent.spec.d.ts","sourceRoot":"","sources":["../../../../src/sse/calculations/stringifyMessageEvent.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export interface MessageEvent {
2
+ data: string | string[];
3
+ id?: string;
4
+ retry?: number;
5
+ type?: string;
6
+ }
7
+ //# sourceMappingURL=MessageEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageEvent.d.ts","sourceRoot":"","sources":["../../../../src/sse/models/MessageEvent.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=MessageEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageEvent.js","sourceRoot":"","sources":["../../../../src/sse/models/MessageEvent.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { HttpStatusCode } from '@inversifyjs/http-core';
2
+ import { SseStream } from '../../stream/models/SseStream';
3
+ import { MessageEvent } from './MessageEvent';
4
+ export interface SsePublisherOptions {
5
+ events: AsyncIterable<MessageEvent> | SseStream;
6
+ statusCode?: HttpStatusCode;
7
+ }
8
+ //# sourceMappingURL=SsePublisherOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SsePublisherOptions.d.ts","sourceRoot":"","sources":["../../../../src/sse/models/SsePublisherOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IAChD,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=SsePublisherOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SsePublisherOptions.js","sourceRoot":"","sources":["../../../../src/sse/models/SsePublisherOptions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { Readable } from 'node:stream';
2
+ import { MessageEvent } from '../../sse/models/MessageEvent';
3
+ declare const isSseStreamSymbol: unique symbol;
4
+ export declare class SseStream extends Readable {
5
+ #private;
6
+ readonly [isSseStreamSymbol]: boolean;
7
+ static is(value: unknown): value is SseStream;
8
+ _read(_size: number): void;
9
+ writeMessageEvent(event: MessageEvent): Promise<void>;
10
+ end(): void;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=SseStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SseStream.d.ts","sourceRoot":"","sources":["../../../../src/stream/models/SseStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,QAAA,MAAM,iBAAiB,EAAE,OAAO,MAE/B,CAAC;AAEF,qBAAa,SAAU,SAAQ,QAAQ;;IACrC,SAAgB,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAQ;WAItC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS;IAQpC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQ7B,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB3D,GAAG,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SseStream = void 0;
4
+ const node_stream_1 = require("node:stream");
5
+ const stringifyMessageEvent_1 = require("../../sse/calculations/stringifyMessageEvent");
6
+ const isSseStreamSymbol = Symbol.for('@inversifyjs/http-sse/SseStream');
7
+ class SseStream extends node_stream_1.Readable {
8
+ [isSseStreamSymbol] = true;
9
+ #readyPromise = null;
10
+ #readyResolve = null;
11
+ static is(value) {
12
+ return (typeof value === 'object' &&
13
+ value !== null &&
14
+ value[isSseStreamSymbol] === true);
15
+ }
16
+ _read(_size) {
17
+ if (this.#readyResolve !== null) {
18
+ this.#readyResolve();
19
+ this.#readyResolve = null;
20
+ this.#readyPromise = null;
21
+ }
22
+ }
23
+ async writeMessageEvent(event) {
24
+ // Wait for any existing backpressure to resolve before pushing
25
+ if (this.#readyPromise !== null) {
26
+ await this.#readyPromise;
27
+ }
28
+ const canContinue = this.push((0, stringifyMessageEvent_1.stringifyMessageEvent)(event));
29
+ if (canContinue) {
30
+ return;
31
+ }
32
+ // Buffer is full, wait for _read() to be called
33
+ this.#readyPromise = new Promise((resolve) => {
34
+ this.#readyResolve = resolve;
35
+ });
36
+ return this.#readyPromise;
37
+ }
38
+ end() {
39
+ this.push(null);
40
+ }
41
+ }
42
+ exports.SseStream = SseStream;
43
+ //# sourceMappingURL=SseStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SseStream.js","sourceRoot":"","sources":["../../../../src/stream/models/SseStream.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AAEvC,wFAAqF;AAGrF,MAAM,iBAAiB,GAAkB,MAAM,CAAC,GAAG,CACjD,iCAAiC,CAClC,CAAC;AAEF,MAAa,SAAU,SAAQ,sBAAQ;IACrB,CAAC,iBAAiB,CAAC,GAAY,IAAI,CAAC;IACpD,aAAa,GAAyB,IAAI,CAAC;IAC3C,aAAa,GAAwB,IAAI,CAAC;IAEnC,MAAM,CAAC,EAAE,CAAC,KAAc;QAC7B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACb,KAA4B,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAC1D,CAAC;IACJ,CAAC;IAEe,KAAK,CAAC,KAAa;QACjC,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAAC,KAAmB;QAChD,+DAA+D;QAC/D,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YAChC,MAAM,IAAI,CAAC,aAAa,CAAC;QAC3B,CAAC;QAED,MAAM,WAAW,GAAY,IAAI,CAAC,IAAI,CAAC,IAAA,6CAAqB,EAAC,KAAK,CAAC,CAAC,CAAC;QAErE,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,gDAAgD;QAChD,IAAI,CAAC,aAAa,GAAG,IAAI,OAAO,CAAO,CAAC,OAAmB,EAAE,EAAE;YAC7D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAEM,GAAG;QACR,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;CACF;AA5CD,8BA4CC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SseStream.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SseStream.spec.d.ts","sourceRoot":"","sources":["../../../../src/stream/models/SseStream.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import { HttpStatusCode } from '@inversifyjs/http-core';
2
+ import { Readable } from 'node:stream';
3
+ import { Pipe } from '@inversifyjs/framework-core';
4
+ import { ServiceIdentifier } from 'inversify';
5
+
6
+ interface MessageEvent {
7
+ data: string | string[];
8
+ id?: string;
9
+ retry?: number;
10
+ type?: string;
11
+ }
12
+
13
+ declare const isSseStreamSymbol: unique symbol;
14
+ declare class SseStream extends Readable {
15
+ #private;
16
+ readonly [isSseStreamSymbol]: boolean;
17
+ static is(value: unknown): value is SseStream;
18
+ _read(_size: number): void;
19
+ writeMessageEvent(event: MessageEvent): Promise<void>;
20
+ end(): void;
21
+ }
22
+
23
+ interface SsePublisherOptions {
24
+ events: AsyncIterable<MessageEvent> | SseStream;
25
+ statusCode?: HttpStatusCode;
26
+ }
27
+
28
+ declare function SsePublisher<TResult = any>(...parameterPipeList: (ServiceIdentifier<Pipe> | Pipe)[]): ParameterDecorator;
29
+
30
+ export { SsePublisher, SseStream };
31
+ export type { MessageEvent, SsePublisherOptions };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{Readable as e}from"node:stream";import{createCustomNativeParameterDecorator as t,HttpStatusCode as r}from"@inversifyjs/http-core";function s(e){return`data: ${e}\n`}function n(e){var t;return(void 0===e.type?"":`event: ${e.type}\n`)+(void 0===e.id?"":`id: ${e.id}\n`)+(void 0===e.retry?"":`retry: ${e.retry.toString()}\n`)+(t=e.data,Array.isArray(t)?t.map(e=>s(e)).join(""):s(t))+"\n"}const a=Symbol.for("@inversifyjs/http-sse/SseStream");class o extends e{[a]=!0;#e=null;#t=null;static is(e){return"object"==typeof e&&null!==e&&!0===e[a]}_read(e){null!==this.#t&&(this.#t(),this.#t=null,this.#e=null)}async writeMessageEvent(e){null!==this.#e&&await this.#e;if(!this.push(n(e)))return this.#e=new Promise(e=>{this.#t=e}),this.#e}end(){this.push(null)}}function i(...s){return t((t,s,a)=>async i=>{a.setStatus(t,s,i.statusCode??r.OK),a.setHeader(t,s,"cache-control","private, no-cache, no-store, must-revalidate, max-age=0, no-transform"),a.setHeader(t,s,"content-type","text/event-stream"),a.setHeader(t,s,"expires","0"),a.setHeader(t,s,"pragma","no-cache"),a.setHeader(t,s,"connection","keep-alive"),a.setHeader(t,s,"x-accel-buffering","no"),await a.sendBodySeparator(t,s);const d=o.is(i.events)?i.events:e.from(async function*(e){for await(const t of e)yield n(t)}(i.events));return a.send(t,s,d)},...s)}export{i as SsePublisher,o as SseStream};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/sse/calculations/stringifyMessageEvent.ts","../../src/stream/models/SseStream.ts","../../src/sse/actions/SsePublisher.ts"],"sourcesContent":[null,null,null],"names":["stringifyDataLine","line","stringifyMessageEvent","messageEvent","data","undefined","type","id","retry","toString","Array","isArray","map","join","isSseStreamSymbol","Symbol","for","SseStream","Readable","readyPromise","readyResolve","is","value","_read","_size","this","writeMessageEvent","event","push","Promise","resolve","end","SsePublisher","parameterPipeList","createCustomNativeParameterDecorator","request","response","options","async","sseOptions","setStatus","statusCode","HttpStatusCode","OK","setHeader","sendBodySeparator","stream","events","from","mapMessageEventAsyncIterable","send"],"mappings":"yIAUA,SAASA,EAAkBC,GACzB,MAAO,SAASA,KAClB,CAEM,SAAUC,EAAsBC,GAZtC,IAAuBC,EAwBrB,YATwBC,IAAtBF,EAAaG,KAAqB,GAAK,UAAUH,EAAaG,gBAE1CD,IAApBF,EAAaI,GAAmB,GAAK,OAAOJ,EAAaI,cAElCF,IAAvBF,EAAaK,MACT,GACA,UAAUL,EAAaK,MAAMC,iBArBdL,EAsByBD,EAAaC,KArBvDM,MAAMC,QAAQP,GACTA,EAAKQ,IAAKX,GAAiBD,EAAkBC,IAAOY,KAAK,IAG3Db,EAAkBI,IAoBgD,IAE3E,CCxBA,MAAMU,EAAmCC,OAAOC,IAC9C,mCAGI,MAAOC,UAAkBC,EACbJ,CAACA,IAA8B,EAC/CK,GAAsC,KACtCC,GAAqC,KAE9B,SAAOC,CAAGC,GACf,MACmB,iBAAVA,GACG,OAAVA,IACqD,IAApDA,EAA6BR,EAElC,CAEgB,KAAAS,CAAMC,GACO,OAAvBC,MAAKL,IACPK,MAAKL,IACLK,MAAKL,EAAgB,KACrBK,MAAKN,EAAgB,KAEzB,CAEO,uBAAMO,CAAkBC,GAEF,OAAvBF,MAAKN,SACDM,MAAKN,EAKb,IAF6BM,KAAKG,KAAK1B,EAAsByB,IAW7D,OAJAF,MAAKN,EAAgB,IAAIU,QAAeC,IACtCL,MAAKL,EAAgBU,IAGhBL,MAAKN,CACd,CAEO,GAAAY,GACLN,KAAKG,KAAK,KACZ,EC5BI,SAAUI,KACXC,GAEH,OAAOC,EAML,CACEC,EACAC,EACAC,IAMOC,MAAOC,IACZF,EAAQG,UACNL,EACAC,EACAG,EAAWE,YAAcC,EAAeC,IAG1CN,EAAQO,UACNT,EACAC,EACA,gBACA,yEAEFC,EAAQO,UACNT,EACAC,EACA,eACA,qBAEFC,EAAQO,UAAUT,EAASC,EAAU,UAAW,KAChDC,EAAQO,UAAUT,EAASC,EAAU,SAAU,YAC/CC,EAAQO,UAAUT,EAASC,EAAU,aAAc,cAEnDC,EAAQO,UAAUT,EAASC,EAAU,oBAAqB,YAEpDC,EAAQQ,kBAAkBV,EAASC,GAEzC,MAAMU,EAAmB7B,EAAUI,GAAGkB,EAAWQ,QAC7CR,EAAWQ,OACX7B,EAAS8B,KAxDrBV,gBACES,GAEA,UAAW,MAAM5C,KAAgB4C,QACzB7C,EAAsBC,EAEhC,CAkD0B8C,CAA6BV,EAAWQ,SAE1D,OAAOV,EAAQa,KAAKf,EAASC,EAAUU,OAGxCb,EAEP"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "author": "Roberto Pintos López",
3
+ "bugs": {
4
+ "url": "https://github.com/inversify/monorepo/issues"
5
+ },
6
+ "description": "InversifyJs http sse package",
7
+ "dependencies": {
8
+ "@inversifyjs/http-core": "4.7.0",
9
+ "@inversifyjs/framework-core": "1.0.1"
10
+ },
11
+ "devDependencies": {
12
+ "@hono/node-server": "1.19.6",
13
+ "@stryker-mutator/core": "9.4.0",
14
+ "@stryker-mutator/typescript-checker": "9.4.0",
15
+ "@stryker-mutator/vitest-runner": "9.4.0",
16
+ "@types/express": "5.0.5",
17
+ "@types/express4": "npm:@types/express@4.17.25",
18
+ "@types/node": "24.10.1",
19
+ "@vitest/coverage-v8": "4.0.8",
20
+ "eslint": "9.39.1",
21
+ "express": "5.1.0",
22
+ "express4": "npm:express@4.21.2",
23
+ "fastify": "5.6.2",
24
+ "hono": "4.10.7",
25
+ "inversify": "7.10.4",
26
+ "prettier": "3.7.3",
27
+ "rimraf": "6.1.2",
28
+ "rollup": "4.53.3",
29
+ "ts-loader": "9.5.4",
30
+ "tslib": "2.8.1",
31
+ "typescript": "5.9.3",
32
+ "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.55.0",
33
+ "vitest": "4.0.8",
34
+ "@inversifyjs/http-express": "4.7.0",
35
+ "@inversifyjs/http-express-v4": "4.7.0",
36
+ "@inversifyjs/http-fastify": "4.7.0",
37
+ "@inversifyjs/http-hono": "4.7.0",
38
+ "@inversifyjs/http-uwebsockets": "4.7.0"
39
+ },
40
+ "devEngines": {
41
+ "node": "^24.10.0",
42
+ "pnpm": "^10.13.1"
43
+ },
44
+ "homepage": "https://inversify.io",
45
+ "keywords": [
46
+ "inversify",
47
+ "framework",
48
+ "http",
49
+ "node",
50
+ "sse",
51
+ "typescript"
52
+ ],
53
+ "license": "MIT",
54
+ "main": "lib/cjs/index.js",
55
+ "module": "lib/esm/index.js",
56
+ "exports": {
57
+ ".": {
58
+ "import": "./lib/esm/index.js",
59
+ "require": "./lib/cjs/index.js"
60
+ }
61
+ },
62
+ "name": "@inversifyjs/http-sse",
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/inversify/monorepo.git"
69
+ },
70
+ "version": "1.1.0",
71
+ "scripts": {
72
+ "build": "pnpm run build:cjs && pnpm run build:esm",
73
+ "build:cjs": "tsc --build tsconfig.cjs.json && pnpm exec foundation-ts-package-cjs ./lib/cjs",
74
+ "build:esm": "rollup -c ./rollup.config.mjs && pnpm exec foundation-ts-package-esm ./lib/esm",
75
+ "build:clean": "rimraf lib",
76
+ "format": "prettier --write ./src",
77
+ "lint": "eslint ./src",
78
+ "prebuild": "pnpm run build:clean",
79
+ "test": "vitest run",
80
+ "test:integration": "pnpm run test --project Integration",
81
+ "test:coverage": "pnpm run test:unit --coverage",
82
+ "test:mutation": "stryker run",
83
+ "test:uncommitted": "pnpm run test --changed=HEAD",
84
+ "test:unit": "pnpm run test --project Unit"
85
+ }
86
+ }