@synode/adapter-stream 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 ADDED
@@ -0,0 +1,35 @@
1
+ Synode Proprietary License
2
+
3
+ Copyright (c) 2026 Digitl Cloud GmbH. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person or organization
6
+ obtaining a copy of this software and associated documentation files (the
7
+ "Software"), to use the Software for personal, internal, and commercial
8
+ purposes, subject to the following conditions:
9
+
10
+ 1. PERMITTED USE. You may use, copy, and modify the Software for your own
11
+ personal, internal, or commercial purposes.
12
+
13
+ 2. NO REDISTRIBUTION. You may not distribute, publish, sublicense, or
14
+ otherwise make the Software or any derivative works available to third
15
+ parties, whether in source code or compiled form, free of charge or for
16
+ a fee.
17
+
18
+ 3. NO RESALE. You may not sell, rent, lease, or otherwise commercially
19
+ exploit the Software itself as a standalone product or as part of a
20
+ software distribution.
21
+
22
+ 4. NO HOSTING AS A SERVICE. You may not offer the Software to third parties
23
+ as a hosted, managed, or software-as-a-service product where the primary
24
+ value derives from the Software.
25
+
26
+ 5. ATTRIBUTION. You must retain this license notice and copyright notice in
27
+ all copies or substantial portions of the Software.
28
+
29
+ 6. NO WARRANTY. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
30
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES
33
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35
+ OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,66 @@
1
+
2
+ //#region src/index.ts
3
+ /**
4
+ * Adapter that writes events to a Node.js {@link Writable} stream.
5
+ *
6
+ * Supports two formats:
7
+ * - **jsonl** (default): each event is written as a single JSON line immediately
8
+ * - **json**: events are buffered in memory and flushed as a pretty-printed
9
+ * JSON array when {@link close} is called
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { createWriteStream } from 'node:fs';
14
+ *
15
+ * const stream = createWriteStream('./events.jsonl');
16
+ * const adapter = new StreamAdapter(stream);
17
+ * await generate(journey, { users: 10, adapter });
18
+ * await adapter.close();
19
+ * ```
20
+ */
21
+ var StreamAdapter = class {
22
+ stream;
23
+ format;
24
+ buffer;
25
+ /**
26
+ * @param stream - The writable stream to write events to
27
+ * @param options - Configuration options
28
+ */
29
+ constructor(stream, options) {
30
+ this.stream = stream;
31
+ this.format = options?.format ?? "jsonl";
32
+ this.buffer = [];
33
+ }
34
+ /**
35
+ * Writes a single event to the stream.
36
+ *
37
+ * In jsonl mode the event is serialized and written immediately.
38
+ * In json mode the event is added to an internal buffer.
39
+ *
40
+ * @param event - The generated event to write
41
+ */
42
+ write(event) {
43
+ if (this.format === "jsonl") this.stream.write(JSON.stringify(event) + "\n");
44
+ else this.buffer.push(event);
45
+ }
46
+ /**
47
+ * Flushes any buffered data and ends the underlying stream.
48
+ *
49
+ * In json mode this writes the full buffered array before ending.
50
+ *
51
+ * @returns A promise that resolves when the stream has finished
52
+ */
53
+ close() {
54
+ return new Promise((resolve, reject) => {
55
+ if (this.format === "json") this.stream.write(JSON.stringify(this.buffer, null, 2));
56
+ this.stream.end(() => {
57
+ resolve();
58
+ });
59
+ this.stream.on("error", reject);
60
+ });
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ exports.StreamAdapter = StreamAdapter;
66
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { Writable } from 'node:stream';\nimport type { Event, OutputAdapter } from '@synode/core';\n\n/**\n * Configuration options for {@link StreamAdapter}.\n *\n * @param format - Serialization format: 'jsonl' writes one JSON object per line\n * as events arrive, 'json' buffers all events and writes a single JSON array\n * on close. Defaults to 'jsonl'.\n */\nexport interface StreamAdapterOptions {\n format?: 'json' | 'jsonl';\n}\n\n/**\n * Adapter that writes events to a Node.js {@link Writable} stream.\n *\n * Supports two formats:\n * - **jsonl** (default): each event is written as a single JSON line immediately\n * - **json**: events are buffered in memory and flushed as a pretty-printed\n * JSON array when {@link close} is called\n *\n * @example\n * ```ts\n * import { createWriteStream } from 'node:fs';\n *\n * const stream = createWriteStream('./events.jsonl');\n * const adapter = new StreamAdapter(stream);\n * await generate(journey, { users: 10, adapter });\n * await adapter.close();\n * ```\n */\nexport class StreamAdapter implements OutputAdapter {\n private stream: Writable;\n private format: 'json' | 'jsonl';\n private buffer: Event[];\n\n /**\n * @param stream - The writable stream to write events to\n * @param options - Configuration options\n */\n constructor(stream: Writable, options?: StreamAdapterOptions) {\n this.stream = stream;\n this.format = options?.format ?? 'jsonl';\n this.buffer = [];\n }\n\n /**\n * Writes a single event to the stream.\n *\n * In jsonl mode the event is serialized and written immediately.\n * In json mode the event is added to an internal buffer.\n *\n * @param event - The generated event to write\n */\n write(event: Event): void {\n if (this.format === 'jsonl') {\n this.stream.write(JSON.stringify(event) + '\\n');\n } else {\n this.buffer.push(event);\n }\n }\n\n /**\n * Flushes any buffered data and ends the underlying stream.\n *\n * In json mode this writes the full buffered array before ending.\n *\n * @returns A promise that resolves when the stream has finished\n */\n close(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.format === 'json') {\n this.stream.write(JSON.stringify(this.buffer, null, 2));\n }\n this.stream.end(() => {\n resolve();\n });\n this.stream.on('error', reject);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,gBAAb,MAAoD;CAClD,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;CAMR,YAAY,QAAkB,SAAgC;AAC5D,OAAK,SAAS;AACd,OAAK,SAAS,SAAS,UAAU;AACjC,OAAK,SAAS,EAAE;;;;;;;;;;CAWlB,MAAM,OAAoB;AACxB,MAAI,KAAK,WAAW,QAClB,MAAK,OAAO,MAAM,KAAK,UAAU,MAAM,GAAG,KAAK;MAE/C,MAAK,OAAO,KAAK,MAAM;;;;;;;;;CAW3B,QAAuB;AACrB,SAAO,IAAI,SAAS,SAAS,WAAW;AACtC,OAAI,KAAK,WAAW,OAClB,MAAK,OAAO,MAAM,KAAK,UAAU,KAAK,QAAQ,MAAM,EAAE,CAAC;AAEzD,QAAK,OAAO,UAAU;AACpB,aAAS;KACT;AACF,QAAK,OAAO,GAAG,SAAS,OAAO;IAC/B"}
@@ -0,0 +1,63 @@
1
+ import { Writable } from "node:stream";
2
+ import { Event, OutputAdapter } from "@synode/core";
3
+
4
+ //#region src/index.d.ts
5
+
6
+ /**
7
+ * Configuration options for {@link StreamAdapter}.
8
+ *
9
+ * @param format - Serialization format: 'jsonl' writes one JSON object per line
10
+ * as events arrive, 'json' buffers all events and writes a single JSON array
11
+ * on close. Defaults to 'jsonl'.
12
+ */
13
+ interface StreamAdapterOptions {
14
+ format?: 'json' | 'jsonl';
15
+ }
16
+ /**
17
+ * Adapter that writes events to a Node.js {@link Writable} stream.
18
+ *
19
+ * Supports two formats:
20
+ * - **jsonl** (default): each event is written as a single JSON line immediately
21
+ * - **json**: events are buffered in memory and flushed as a pretty-printed
22
+ * JSON array when {@link close} is called
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { createWriteStream } from 'node:fs';
27
+ *
28
+ * const stream = createWriteStream('./events.jsonl');
29
+ * const adapter = new StreamAdapter(stream);
30
+ * await generate(journey, { users: 10, adapter });
31
+ * await adapter.close();
32
+ * ```
33
+ */
34
+ declare class StreamAdapter implements OutputAdapter {
35
+ private stream;
36
+ private format;
37
+ private buffer;
38
+ /**
39
+ * @param stream - The writable stream to write events to
40
+ * @param options - Configuration options
41
+ */
42
+ constructor(stream: Writable, options?: StreamAdapterOptions);
43
+ /**
44
+ * Writes a single event to the stream.
45
+ *
46
+ * In jsonl mode the event is serialized and written immediately.
47
+ * In json mode the event is added to an internal buffer.
48
+ *
49
+ * @param event - The generated event to write
50
+ */
51
+ write(event: Event): void;
52
+ /**
53
+ * Flushes any buffered data and ends the underlying stream.
54
+ *
55
+ * In json mode this writes the full buffered array before ending.
56
+ *
57
+ * @returns A promise that resolves when the stream has finished
58
+ */
59
+ close(): Promise<void>;
60
+ }
61
+ //#endregion
62
+ export { StreamAdapter, StreamAdapterOptions };
63
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,63 @@
1
+ import { Writable } from "node:stream";
2
+ import { Event, OutputAdapter } from "@synode/core";
3
+
4
+ //#region src/index.d.ts
5
+
6
+ /**
7
+ * Configuration options for {@link StreamAdapter}.
8
+ *
9
+ * @param format - Serialization format: 'jsonl' writes one JSON object per line
10
+ * as events arrive, 'json' buffers all events and writes a single JSON array
11
+ * on close. Defaults to 'jsonl'.
12
+ */
13
+ interface StreamAdapterOptions {
14
+ format?: 'json' | 'jsonl';
15
+ }
16
+ /**
17
+ * Adapter that writes events to a Node.js {@link Writable} stream.
18
+ *
19
+ * Supports two formats:
20
+ * - **jsonl** (default): each event is written as a single JSON line immediately
21
+ * - **json**: events are buffered in memory and flushed as a pretty-printed
22
+ * JSON array when {@link close} is called
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { createWriteStream } from 'node:fs';
27
+ *
28
+ * const stream = createWriteStream('./events.jsonl');
29
+ * const adapter = new StreamAdapter(stream);
30
+ * await generate(journey, { users: 10, adapter });
31
+ * await adapter.close();
32
+ * ```
33
+ */
34
+ declare class StreamAdapter implements OutputAdapter {
35
+ private stream;
36
+ private format;
37
+ private buffer;
38
+ /**
39
+ * @param stream - The writable stream to write events to
40
+ * @param options - Configuration options
41
+ */
42
+ constructor(stream: Writable, options?: StreamAdapterOptions);
43
+ /**
44
+ * Writes a single event to the stream.
45
+ *
46
+ * In jsonl mode the event is serialized and written immediately.
47
+ * In json mode the event is added to an internal buffer.
48
+ *
49
+ * @param event - The generated event to write
50
+ */
51
+ write(event: Event): void;
52
+ /**
53
+ * Flushes any buffered data and ends the underlying stream.
54
+ *
55
+ * In json mode this writes the full buffered array before ending.
56
+ *
57
+ * @returns A promise that resolves when the stream has finished
58
+ */
59
+ close(): Promise<void>;
60
+ }
61
+ //#endregion
62
+ export { StreamAdapter, StreamAdapterOptions };
63
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,65 @@
1
+ //#region src/index.ts
2
+ /**
3
+ * Adapter that writes events to a Node.js {@link Writable} stream.
4
+ *
5
+ * Supports two formats:
6
+ * - **jsonl** (default): each event is written as a single JSON line immediately
7
+ * - **json**: events are buffered in memory and flushed as a pretty-printed
8
+ * JSON array when {@link close} is called
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createWriteStream } from 'node:fs';
13
+ *
14
+ * const stream = createWriteStream('./events.jsonl');
15
+ * const adapter = new StreamAdapter(stream);
16
+ * await generate(journey, { users: 10, adapter });
17
+ * await adapter.close();
18
+ * ```
19
+ */
20
+ var StreamAdapter = class {
21
+ stream;
22
+ format;
23
+ buffer;
24
+ /**
25
+ * @param stream - The writable stream to write events to
26
+ * @param options - Configuration options
27
+ */
28
+ constructor(stream, options) {
29
+ this.stream = stream;
30
+ this.format = options?.format ?? "jsonl";
31
+ this.buffer = [];
32
+ }
33
+ /**
34
+ * Writes a single event to the stream.
35
+ *
36
+ * In jsonl mode the event is serialized and written immediately.
37
+ * In json mode the event is added to an internal buffer.
38
+ *
39
+ * @param event - The generated event to write
40
+ */
41
+ write(event) {
42
+ if (this.format === "jsonl") this.stream.write(JSON.stringify(event) + "\n");
43
+ else this.buffer.push(event);
44
+ }
45
+ /**
46
+ * Flushes any buffered data and ends the underlying stream.
47
+ *
48
+ * In json mode this writes the full buffered array before ending.
49
+ *
50
+ * @returns A promise that resolves when the stream has finished
51
+ */
52
+ close() {
53
+ return new Promise((resolve, reject) => {
54
+ if (this.format === "json") this.stream.write(JSON.stringify(this.buffer, null, 2));
55
+ this.stream.end(() => {
56
+ resolve();
57
+ });
58
+ this.stream.on("error", reject);
59
+ });
60
+ }
61
+ };
62
+
63
+ //#endregion
64
+ export { StreamAdapter };
65
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { Writable } from 'node:stream';\nimport type { Event, OutputAdapter } from '@synode/core';\n\n/**\n * Configuration options for {@link StreamAdapter}.\n *\n * @param format - Serialization format: 'jsonl' writes one JSON object per line\n * as events arrive, 'json' buffers all events and writes a single JSON array\n * on close. Defaults to 'jsonl'.\n */\nexport interface StreamAdapterOptions {\n format?: 'json' | 'jsonl';\n}\n\n/**\n * Adapter that writes events to a Node.js {@link Writable} stream.\n *\n * Supports two formats:\n * - **jsonl** (default): each event is written as a single JSON line immediately\n * - **json**: events are buffered in memory and flushed as a pretty-printed\n * JSON array when {@link close} is called\n *\n * @example\n * ```ts\n * import { createWriteStream } from 'node:fs';\n *\n * const stream = createWriteStream('./events.jsonl');\n * const adapter = new StreamAdapter(stream);\n * await generate(journey, { users: 10, adapter });\n * await adapter.close();\n * ```\n */\nexport class StreamAdapter implements OutputAdapter {\n private stream: Writable;\n private format: 'json' | 'jsonl';\n private buffer: Event[];\n\n /**\n * @param stream - The writable stream to write events to\n * @param options - Configuration options\n */\n constructor(stream: Writable, options?: StreamAdapterOptions) {\n this.stream = stream;\n this.format = options?.format ?? 'jsonl';\n this.buffer = [];\n }\n\n /**\n * Writes a single event to the stream.\n *\n * In jsonl mode the event is serialized and written immediately.\n * In json mode the event is added to an internal buffer.\n *\n * @param event - The generated event to write\n */\n write(event: Event): void {\n if (this.format === 'jsonl') {\n this.stream.write(JSON.stringify(event) + '\\n');\n } else {\n this.buffer.push(event);\n }\n }\n\n /**\n * Flushes any buffered data and ends the underlying stream.\n *\n * In json mode this writes the full buffered array before ending.\n *\n * @returns A promise that resolves when the stream has finished\n */\n close(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.format === 'json') {\n this.stream.write(JSON.stringify(this.buffer, null, 2));\n }\n this.stream.end(() => {\n resolve();\n });\n this.stream.on('error', reject);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,IAAa,gBAAb,MAAoD;CAClD,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;CAMR,YAAY,QAAkB,SAAgC;AAC5D,OAAK,SAAS;AACd,OAAK,SAAS,SAAS,UAAU;AACjC,OAAK,SAAS,EAAE;;;;;;;;;;CAWlB,MAAM,OAAoB;AACxB,MAAI,KAAK,WAAW,QAClB,MAAK,OAAO,MAAM,KAAK,UAAU,MAAM,GAAG,KAAK;MAE/C,MAAK,OAAO,KAAK,MAAM;;;;;;;;;CAW3B,QAAuB;AACrB,SAAO,IAAI,SAAS,SAAS,WAAW;AACtC,OAAI,KAAK,WAAW,OAClB,MAAK,OAAO,MAAM,KAAK,UAAU,KAAK,QAAQ,MAAM,EAAE,CAAC;AAEzD,QAAK,OAAO,UAAU;AACpB,aAAS;KACT;AACF,QAAK,OAAO,GAAG,SAAS,OAAO;IAC/B"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@synode/adapter-stream",
3
+ "version": "1.0.0",
4
+ "description": "Stream adapter for Synode",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.mts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "author": "Digitl Cloud GmbH",
20
+ "license": "SEE LICENSE IN LICENSE",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/digitl-cloud/synode",
24
+ "directory": "packages/adapter-stream"
25
+ },
26
+ "peerDependencies": {
27
+ "@synode/core": "^1.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^24.12.0",
31
+ "eslint": "^9.39.4",
32
+ "eslint-config-prettier": "^10.1.8",
33
+ "typescript-eslint": "^8.58.0",
34
+ "tsdown": "^0.16.8",
35
+ "typescript": "^5.9.3",
36
+ "vitest": "^4.1.2",
37
+ "@synode/core": "1.0.0"
38
+ },
39
+ "scripts": {
40
+ "build": "tsdown",
41
+ "test": "vitest run",
42
+ "lint": "eslint src tests"
43
+ }
44
+ }