@push.rocks/smartrust 1.3.2 → 1.4.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.
@@ -0,0 +1,37 @@
1
+ {
2
+ "@git.zone/cli": {
3
+ "projectType": "npm",
4
+ "module": {
5
+ "githost": "code.foss.global",
6
+ "gitscope": "push.rocks",
7
+ "gitrepo": "smartrust",
8
+ "description": "A type-safe bridge between JavaScript engines and Rust binaries.",
9
+ "npmPackagename": "@push.rocks/smartrust",
10
+ "license": "MIT",
11
+ "projectDomain": "push.rocks",
12
+ "keywords": [
13
+ "rust",
14
+ "typescript",
15
+ "ipc",
16
+ "bridge",
17
+ "stdio",
18
+ "socket",
19
+ "binary",
20
+ "transport"
21
+ ]
22
+ },
23
+ "release": {
24
+ "accessLevel": "public",
25
+ "registries": [
26
+ "https://verdaccio.lossless.digital",
27
+ "https://registry.npmjs.org"
28
+ ]
29
+ }
30
+ },
31
+ "@git.zone/tsdoc": {
32
+ "legal": "\n## License and Legal Information\n\nThis repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license) file.\n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.\n\nUse of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.\n\n### Company Information\n\nTask Venture Capital GmbH\nRegistered at District Court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
33
+ },
34
+ "@ship.zone/szci": {
35
+ "npmGlobalTools": []
36
+ }
37
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartrust',
6
- version: '1.3.2',
7
- description: 'a bridge between JS engines and rust'
6
+ version: '1.4.0',
7
+ description: 'A type-safe bridge between JavaScript engines and Rust binaries.'
8
8
  };
9
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx1QkFBdUI7SUFDN0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHNDQUFzQztDQUNwRCxDQUFBIn0=
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx1QkFBdUI7SUFDN0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLGtFQUFrRTtDQUNoRixDQUFBIn0=
package/license ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Task Venture Capital GmbH (hello@task.vc)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@push.rocks/smartrust",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
- "description": "a bridge between JS engines and rust",
5
+ "description": "A type-safe bridge between JavaScript engines and Rust binaries.",
6
6
  "main": "dist_ts/index.js",
7
7
  "typings": "dist_ts/index.d.ts",
8
8
  "type": "module",
@@ -10,16 +10,46 @@
10
10
  "license": "MIT",
11
11
  "scripts": {
12
12
  "test": "(tstest test/ --verbose --logfile --timeout 60)",
13
- "build": "(tsbuild tsfolders --allowimplicitany)",
13
+ "build": "(tsbuild tsfolders)",
14
14
  "buildDocs": "(tsdoc)"
15
15
  },
16
16
  "devDependencies": {
17
- "@git.zone/tsbuild": "^4.1.2",
18
- "@git.zone/tsrun": "^2.0.1",
19
- "@git.zone/tstest": "^3.1.8",
20
- "@types/node": "^25.2.0"
17
+ "@git.zone/tsbuild": "^4.4.0",
18
+ "@git.zone/tsrun": "^2.0.2",
19
+ "@git.zone/tstest": "^3.6.3",
20
+ "@types/node": "^25.6.0"
21
21
  },
22
22
  "dependencies": {
23
23
  "@push.rocks/smartpath": "^6.0.0"
24
- }
24
+ },
25
+ "files": [
26
+ "ts/**/*",
27
+ "dist/**/*",
28
+ "dist_*/**/*",
29
+ "dist_ts/**/*",
30
+ "assets/**/*",
31
+ "cli.js",
32
+ ".smartconfig.json",
33
+ "license",
34
+ "readme.md"
35
+ ],
36
+ "keywords": [
37
+ "rust",
38
+ "typescript",
39
+ "ipc",
40
+ "bridge",
41
+ "stdio",
42
+ "socket",
43
+ "binary",
44
+ "transport"
45
+ ],
46
+ "homepage": "https://code.foss.global/push.rocks/smartrust#readme",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://code.foss.global/push.rocks/smartrust.git"
50
+ },
51
+ "bugs": {
52
+ "url": "https://code.foss.global/push.rocks/smartrust/issues"
53
+ },
54
+ "packageManager": "pnpm@10.28.2"
25
55
  }
package/readme.md CHANGED
@@ -9,9 +9,7 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
9
9
  ## Install 📦
10
10
 
11
11
  ```bash
12
- npm install @push.rocks/smartrust
13
- # or
14
- pnpm install @push.rocks/smartrust
12
+ pnpm add @push.rocks/smartrust
15
13
  ```
16
14
 
17
15
  ## Overview 🔭
@@ -556,7 +554,7 @@ fn main() {
556
554
 
557
555
  ## License and Legal Information
558
556
 
559
- This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
557
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license) file.
560
558
 
561
559
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
562
560
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartrust',
6
- version: '1.3.2',
7
- description: 'a bridge between JS engines and rust'
6
+ version: '1.4.0',
7
+ description: 'A type-safe bridge between JavaScript engines and Rust binaries.'
8
8
  }
@@ -1,66 +0,0 @@
1
- name: Default (not tags)
2
-
3
- on:
4
- push:
5
- tags-ignore:
6
- - '**'
7
-
8
- env:
9
- IMAGE: code.foss.global/host.today/ht-docker-node:npmci
10
- NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@code.foss.global/${{gitea.repository}}.git
11
- NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
12
- NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
13
- NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
14
- NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
15
-
16
- jobs:
17
- security:
18
- runs-on: ubuntu-latest
19
- continue-on-error: true
20
- container:
21
- image: ${{ env.IMAGE }}
22
-
23
- steps:
24
- - uses: actions/checkout@v3
25
-
26
- - name: Install pnpm and npmci
27
- run: |
28
- pnpm install -g pnpm
29
- pnpm install -g @ship.zone/npmci
30
-
31
- - name: Run npm prepare
32
- run: npmci npm prepare
33
-
34
- - name: Audit production dependencies
35
- run: |
36
- npmci command npm config set registry https://registry.npmjs.org
37
- npmci command pnpm audit --audit-level=high --prod
38
- continue-on-error: true
39
-
40
- - name: Audit development dependencies
41
- run: |
42
- npmci command npm config set registry https://registry.npmjs.org
43
- npmci command pnpm audit --audit-level=high --dev
44
- continue-on-error: true
45
-
46
- test:
47
- if: ${{ always() }}
48
- needs: security
49
- runs-on: ubuntu-latest
50
- container:
51
- image: ${{ env.IMAGE }}
52
-
53
- steps:
54
- - uses: actions/checkout@v3
55
-
56
- - name: Test stable
57
- run: |
58
- npmci node install stable
59
- npmci npm install
60
- npmci npm test
61
-
62
- - name: Test build
63
- run: |
64
- npmci node install stable
65
- npmci npm install
66
- npmci npm build
@@ -1,124 +0,0 @@
1
- name: Default (tags)
2
-
3
- on:
4
- push:
5
- tags:
6
- - '*'
7
-
8
- env:
9
- IMAGE: code.foss.global/host.today/ht-docker-node:npmci
10
- NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@code.foss.global/${{gitea.repository}}.git
11
- NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
12
- NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
13
- NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
14
- NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
15
-
16
- jobs:
17
- security:
18
- runs-on: ubuntu-latest
19
- continue-on-error: true
20
- container:
21
- image: ${{ env.IMAGE }}
22
-
23
- steps:
24
- - uses: actions/checkout@v3
25
-
26
- - name: Prepare
27
- run: |
28
- pnpm install -g pnpm
29
- pnpm install -g @ship.zone/npmci
30
- npmci npm prepare
31
-
32
- - name: Audit production dependencies
33
- run: |
34
- npmci command npm config set registry https://registry.npmjs.org
35
- npmci command pnpm audit --audit-level=high --prod
36
- continue-on-error: true
37
-
38
- - name: Audit development dependencies
39
- run: |
40
- npmci command npm config set registry https://registry.npmjs.org
41
- npmci command pnpm audit --audit-level=high --dev
42
- continue-on-error: true
43
-
44
- test:
45
- if: ${{ always() }}
46
- needs: security
47
- runs-on: ubuntu-latest
48
- container:
49
- image: ${{ env.IMAGE }}
50
-
51
- steps:
52
- - uses: actions/checkout@v3
53
-
54
- - name: Prepare
55
- run: |
56
- pnpm install -g pnpm
57
- pnpm install -g @ship.zone/npmci
58
- npmci npm prepare
59
-
60
- - name: Test stable
61
- run: |
62
- npmci node install stable
63
- npmci npm install
64
- npmci npm test
65
-
66
- - name: Test build
67
- run: |
68
- npmci node install stable
69
- npmci npm install
70
- npmci npm build
71
-
72
- release:
73
- needs: test
74
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
75
- runs-on: ubuntu-latest
76
- container:
77
- image: ${{ env.IMAGE }}
78
-
79
- steps:
80
- - uses: actions/checkout@v3
81
-
82
- - name: Prepare
83
- run: |
84
- pnpm install -g pnpm
85
- pnpm install -g @ship.zone/npmci
86
- npmci npm prepare
87
-
88
- - name: Release
89
- run: |
90
- npmci node install stable
91
- npmci npm publish
92
-
93
- metadata:
94
- needs: test
95
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
96
- runs-on: ubuntu-latest
97
- container:
98
- image: ${{ env.IMAGE }}
99
- continue-on-error: true
100
-
101
- steps:
102
- - uses: actions/checkout@v3
103
-
104
- - name: Prepare
105
- run: |
106
- pnpm install -g pnpm
107
- pnpm install -g @ship.zone/npmci
108
- npmci npm prepare
109
-
110
- - name: Code quality
111
- run: |
112
- npmci command npm install -g typescript
113
- npmci npm install
114
-
115
- - name: Trigger
116
- run: npmci trigger
117
-
118
- - name: Build docs and upload artifacts
119
- run: |
120
- npmci node install stable
121
- npmci npm install
122
- pnpm install -g @git.zone/tsdoc
123
- npmci command tsdoc
124
- continue-on-error: true
@@ -1,11 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "command": "npm test",
6
- "name": "Run npm test",
7
- "request": "launch",
8
- "type": "node-terminal"
9
- }
10
- ]
11
- }
@@ -1,26 +0,0 @@
1
- {
2
- "json.schemas": [
3
- {
4
- "fileMatch": ["/npmextra.json"],
5
- "schema": {
6
- "type": "object",
7
- "properties": {
8
- "npmci": {
9
- "type": "object",
10
- "description": "settings for npmci"
11
- },
12
- "gitzone": {
13
- "type": "object",
14
- "description": "settings for gitzone",
15
- "properties": {
16
- "projectType": {
17
- "type": "string",
18
- "enum": ["website", "element", "service", "npm", "wcc"]
19
- }
20
- }
21
- }
22
- }
23
- }
24
- }
25
- ]
26
- }
package/changelog.md DELETED
@@ -1,84 +0,0 @@
1
- # Changelog
2
-
3
- ## 2026-03-14 - 1.3.2 - fix(rustbinarylocator)
4
- support resolving platform-suffixed local Rust binaries
5
-
6
- - Checks local Rust build paths for binaries with platform suffixes such as _linux_amd64 in addition to unsuffixed names
7
- - Adds platform and architecture suffix mapping for linux, darwin, windows, x64, and arm64
8
-
9
- ## 2026-02-26 - 1.3.1 - fix(readme)
10
- document socket transport and clarify stdio/socket differences in README
11
-
12
- - Add 'Two Transport Modes' section documenting stdio (spawn) and socket (connect) modes
13
- - Add examples for connect(), socket usage, and auto-reconnect with exponential backoff
14
- - Clarify protocol is transport-agnostic and update ready/stream/event descriptions
15
- - Update event docs: mark stderr as stdio-only and add 'reconnected' event for socket transports
16
- - Clarify kill() behavior for both stdio and socket transports
17
- - Add API reference entries for SocketTransport, StdioTransport, ISocketConnectOptions, IRustTransport, and LineScanner
18
- - Add platform notes, architecture diagram, and minimal Rust/socket usage guidance
19
-
20
- ## 2026-02-26 - 1.3.0 - feat(transport)
21
- introduce transport abstraction and socket-mode support for RustBridge
22
-
23
- - Add IRustTransport interface and two transport implementations: StdioTransport (spawns child process and uses stdin/stdout) and SocketTransport (connects to Unix socket / Windows named pipe).
24
- - Refactor RustBridge to use a transport abstraction (connectWithTransport) and add connect(socketPath) to attach to an existing daemon via socket.
25
- - Introduce LineScanner: a buffer-based newline scanner used by both transports to handle large/newline-delimited messages and avoid OOMs.
26
- - Add socket connection options (autoReconnect, reconnectBaseDelayMs, reconnectMaxDelayMs, maxReconnectAttempts) and implement auto-reconnect/backoff behavior in SocketTransport.
27
- - Implement backpressure-aware write semantics and proper disconnect/cleanup for both transports; RustBridge.kill() now disconnects the transport instead of directly managing processes.
28
- - Add tests and tooling: socket transport tests, line scanner tests, and a mock-socket-server.mjs helper script for testing socket mode.
29
- - Export new symbols (StdioTransport, SocketTransport, LineScanner) and update plugins to expose net; update interfaces to export transport types.
30
-
31
- ## 2026-02-12 - 1.2.1 - fix(rust-binary-locator)
32
- auto-fix missing execute permission for located Rust binaries
33
-
34
- - If a located binary exists but lacks the execute bit, attempt to chmod it to 0o755 and treat it as executable.
35
- - Logs an info message when the auto-fix is applied: 'Auto-fixed missing execute permission on: <filePath>'.
36
- - Addresses cases where npm/pnpm installs remove the execute permission from bundled binaries.
37
-
38
- ## 2026-02-11 - 1.2.0 - feat(rustbridge)
39
- add streaming responses and robust large-payload/backpressure handling to RustBridge
40
-
41
- - Introduce StreamingResponse type and export it (for-await-of iterator + .result promise)
42
- - Add sendCommandStreaming API to send streaming commands and receive chunks + final result
43
- - Implement buffer-based stdout newline scanner to handle large messages and avoid readline limits
44
- - Add backpressure-aware writeToStdin to wait for drain when writing large outbound payloads
45
- - Add maxPayloadSize option and enforce outbound/inbound size checks to prevent OOMs
46
- - Add streamTimeoutMs (inactivity timeout) and reset timeout on each received chunk
47
- - Improve stderr handling (cross-chunk buffering and trimmed emits)
48
- - Update mock test binary and extensive tests for streaming, large payloads, concurrency, and error cases
49
- - Add TypeScript types for streaming commands (TStreamingCommandKeys, TExtractChunk, IManagementStreamChunk)
50
-
51
- ## 2026-02-10 - 1.1.2 - fix(rust-binary-locator)
52
- use import.meta.resolve and url.fileURLToPath to locate bundled Rust binary in ESM environments
53
-
54
- - Replace require.resolve with import.meta.resolve to support ESM module resolution
55
- - Convert resolved file URL to a filesystem path using url.fileURLToPath
56
- - Export the url module from ts/plugins to provide fileURLToPath
57
-
58
- ## 2026-02-10 - 1.1.1 - fix(readme)
59
- update README with comprehensive documentation, usage examples, API reference, installation instructions, and legal/company information
60
-
61
- - Rewrote readme.md (≈ +298 −3 lines) to add detailed install, overview, IPC protocol, command definition examples, usage, API reference, issue reporting & security guidance, and legal/trademark/company information.
62
- - Documentation-only change — no source code modified.
63
- - Current package version is 1.1.0; recommend a patch release
64
-
65
- ## 2026-02-10 - 1.1.0 - feat(rustbridge)
66
- add RustBridge and RustBinaryLocator with typed IPC interfaces, plugins, tests and mock runner; export from index; add npm registries
67
-
68
- - Introduce RustBridge: spawn and manage a child binary, JSON-over-stdin/stdout request/response handling, events, timeouts, pending request tracking, kill/cleanup logic.
69
- - Introduce RustBinaryLocator: multi-strategy binary discovery (explicit path, env var, platform-specific package, local build paths, system PATH) with caching and logger hooks.
70
- - Add IPC and config TypeScript interfaces (IManagementRequest/Response/Event, ICommandDefinition, IBinaryLocatorOptions, IRustBridgeOptions) and re-export via interfaces/index.ts.
71
- - Update ts/plugins.ts to export fs, child_process, readline and events for easier native integration.
72
- - Add tests for RustBridge and RustBinaryLocator plus a test helper mock-rust-binary.mjs to simulate the IPC protocol and exercise commands, events, timeouts and locator behaviors.
73
- - Update ts/index.ts to export RustBridge and RustBinaryLocator and export interfaces; update npmextra.json to include internal Verdaccio registry alongside npmjs.org.
74
-
75
- ## 2026-02-08 - 1.0.2 - fix()
76
- no changes
77
-
78
- - No changes detected in git diff; no release necessary.
79
-
80
- ## 2026-02-08 - 1.0.1 - initial release
81
- Initial release of the project.
82
-
83
- - Initial commit creating the project repository and baseline files.
84
- - Tagged as version 1.0.1.
package/npmextra.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "@git.zone/cli": {
3
- "projectType": "npm",
4
- "module": {
5
- "githost": "code.foss.global",
6
- "gitscope": "push.rocks",
7
- "gitrepo": "smartrust",
8
- "description": "a bridge between JS engines and rust",
9
- "npmPackagename": "@push.rocks/smartrust",
10
- "license": "MIT",
11
- "projectDomain": "push.rocks"
12
- },
13
- "release": {
14
- "accessLevel": "public",
15
- "registries": [
16
- "https://verdaccio.lossless.digital",
17
- "https://registry.npmjs.org"
18
- ]
19
- }
20
- },
21
- "@ship.zone/szci": {
22
- "npmGlobalTools": []
23
- }
24
- }
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Mock "Rust binary" for testing the RustBridge IPC protocol.
5
- * Reads JSON lines from stdin via Buffer-based scanner, writes JSON lines to stdout.
6
- * Emits a ready event on startup.
7
- */
8
-
9
- // Emit ready event
10
- const readyEvent = JSON.stringify({ event: 'ready', data: { version: '1.0.0' } });
11
- process.stdout.write(readyEvent + '\n');
12
-
13
- // Buffer-based newline scanner for stdin (mirrors the RustBridge approach)
14
- let stdinBuffer = Buffer.alloc(0);
15
-
16
- process.stdin.on('data', (chunk) => {
17
- stdinBuffer = Buffer.concat([stdinBuffer, chunk]);
18
-
19
- let newlineIndex;
20
- while ((newlineIndex = stdinBuffer.indexOf(0x0A)) !== -1) {
21
- const lineBuffer = stdinBuffer.subarray(0, newlineIndex);
22
- stdinBuffer = stdinBuffer.subarray(newlineIndex + 1);
23
- const line = lineBuffer.toString('utf8').trim();
24
- if (line) {
25
- handleLine(line);
26
- }
27
- }
28
- });
29
-
30
- /**
31
- * Backpressure-aware write to stdout.
32
- */
33
- function writeResponse(data) {
34
- const json = JSON.stringify(data) + '\n';
35
- if (!process.stdout.write(json)) {
36
- // Wait for drain before continuing
37
- process.stdout.once('drain', () => {});
38
- }
39
- }
40
-
41
- function handleLine(line) {
42
- let request;
43
- try {
44
- request = JSON.parse(line);
45
- } catch {
46
- return;
47
- }
48
-
49
- const { id, method, params } = request;
50
-
51
- if (method === 'echo') {
52
- // Echo back the params as result
53
- writeResponse({ id, success: true, result: params });
54
- } else if (method === 'largeEcho') {
55
- // Echo back params (same as echo, named distinctly for large payload tests)
56
- writeResponse({ id, success: true, result: params });
57
- } else if (method === 'error') {
58
- // Return an error
59
- writeResponse({ id, success: false, error: 'Test error message' });
60
- } else if (method === 'emitEvent') {
61
- // Emit a custom event, then respond with success
62
- writeResponse({ event: params.eventName, data: params.eventData });
63
- writeResponse({ id, success: true, result: null });
64
- } else if (method === 'slow') {
65
- // Respond after a delay
66
- setTimeout(() => {
67
- writeResponse({ id, success: true, result: { delayed: true } });
68
- }, 100);
69
- } else if (method === 'streamEcho') {
70
- // Send params.count stream chunks, then final response
71
- const count = params.count || 0;
72
- let sent = 0;
73
- const interval = setInterval(() => {
74
- if (sent < count) {
75
- writeResponse({ id, stream: true, data: { index: sent, value: `chunk_${sent}` } });
76
- sent++;
77
- } else {
78
- clearInterval(interval);
79
- writeResponse({ id, success: true, result: { totalChunks: count } });
80
- }
81
- }, 10);
82
- } else if (method === 'streamError') {
83
- // Send 1 chunk, then error
84
- writeResponse({ id, stream: true, data: { index: 0, value: 'before_error' } });
85
- setTimeout(() => {
86
- writeResponse({ id, success: false, error: 'Stream error after chunk' });
87
- }, 20);
88
- } else if (method === 'streamEmpty') {
89
- // Zero chunks, immediate final response
90
- writeResponse({ id, success: true, result: { totalChunks: 0 } });
91
- } else if (method === 'exit') {
92
- // Graceful exit
93
- writeResponse({ id, success: true, result: null });
94
- process.exit(0);
95
- } else {
96
- // Unknown command
97
- writeResponse({ id, success: false, error: `Unknown method: ${method}` });
98
- }
99
- }
100
-
101
- // Handle SIGTERM gracefully
102
- process.on('SIGTERM', () => {
103
- process.exit(0);
104
- });