@nomux-sh/extension 0.0.0-stage → 0.1.2

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-APACHE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/LICENSE-MIT ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The nomux Authors
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.
22
+
package/README.md CHANGED
@@ -1,3 +1,137 @@
1
- # Temporary Holding Version
1
+ # @nomux-sh/extension
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The nomux extension SDK for TypeScript: the daemon part of a [nomux](https://github.com/nomux-sh) extension.
4
+
5
+ The daemon part of an extension is a separate process. The nomux daemon (the host) starts it when a client needs it and stops it when it is idle. The host and the extension exchange protobuf messages on the standard input and the standard output of the process. The [extension protocol](https://github.com/nomux-sh/extension-api/blob/main/spec/extension-protocol.md) specifies the messages.
6
+
7
+ The package has the same parts as the Rust crate [`nomux-extension`](https://crates.io/crates/nomux-extension): the framing with the size limit, the handshake with the version rule, methods, calls of host services, events, cancellation and the shutdown. The [conformance suite](https://github.com/nomux-sh/extension-api/tree/main/conformance) examines each SDK with the same cases.
8
+
9
+ Versions earlier than 1.0.0 are pre-releases: interfaces can change between minor versions.
10
+
11
+ ## Requirements
12
+
13
+ - Node.js 22 or later. Node.js 22 is the oldest LTS line that has support. The package uses only Node.js APIs (`node:process`, `node:stream`), thus it also runs on Bun and Deno where they are compatible with Node.js.
14
+ - The package is ESM only.
15
+ - The one runtime dependency is [`@bufbuild/protobuf`](https://www.npmjs.com/package/@bufbuild/protobuf). The code reads and writes protobuf with its `wire` module only. No reflection runtime loads at the start.
16
+
17
+ ## Write an extension
18
+
19
+ ```sh
20
+ npm install @nomux-sh/extension @bufbuild/protobuf
21
+ ```
22
+
23
+ `src/main.ts`:
24
+
25
+ ```ts
26
+ import { BinaryReader, BinaryWriter, WireType } from "@bufbuild/protobuf/wire";
27
+ import { CallError, Extension } from "@nomux-sh/extension";
28
+ import type { Call, Codec } from "@nomux-sh/extension";
29
+
30
+ interface Text {
31
+ text: string;
32
+ }
33
+
34
+ // The codec of `message Text { string text = 1; }`.
35
+ const Text: Codec<Text> = {
36
+ encode: ({ text }) => new BinaryWriter().tag(1, WireType.LengthDelimited).string(text).finish(),
37
+ decode: (bytes) => {
38
+ const reader = new BinaryReader(bytes);
39
+ const message: Text = { text: "" };
40
+ while (reader.pos < reader.len) {
41
+ const [field, wireType] = reader.tag();
42
+ if (field === 1 && wireType === WireType.LengthDelimited) {
43
+ message.text = reader.string();
44
+ } else {
45
+ reader.skip(wireType);
46
+ }
47
+ }
48
+ return message;
49
+ },
50
+ };
51
+
52
+ function echo(input: Text, call: Call): Text {
53
+ if (input.text === "") {
54
+ throw CallError.failed("the text is empty");
55
+ }
56
+ call.host.emit("echoed", Text, input);
57
+ return input;
58
+ }
59
+
60
+ await new Extension("nomux.echo", "0.1.0")
61
+ .method("echo", { input: Text, output: Text }, echo)
62
+ .run();
63
+ ```
64
+
65
+ 1. `new Extension(id, version)` takes the `id` and the `version` of `extension.toml`. The host stops an extension whose `id` is different from its manifest.
66
+ 2. `method(name, { input, output }, method)` adds a method. A `Codec` encodes and decodes a payload. If the payload of a call is not valid, the host gets `ErrorCode.INVALID_ARGUMENT` and the method does not run. The codec `bytes` gives the payload as a `Uint8Array`.
67
+ 3. `run()` does the handshake and serves the host on the standard input and the standard output. The promise resolves after the host sends a shutdown request. It rejects with a `RunError` when the extension must stop for a different reason, and then the process exits with a status that is not 0.
68
+
69
+ The standard output carries the protocol. Do not write to it: write logs to the standard error (`console.error`).
70
+
71
+ ### Methods
72
+
73
+ A method gets the argument and a `Call`, and returns the result or a promise of the result.
74
+
75
+ - Throw a `CallError` to fail the call with a code: `new CallError(ErrorCode.NOT_FOUND, "no such session")`, or `CallError.failed(message)`. A different thrown value fails the call with `ErrorCode.FAILED` and its message.
76
+ - The methods run one at a time, in the sequence in which the calls arrive. Thus a method does not need a lock for the state of the extension. While a method waits for a promise, the extension answers health requests and records cancellations. A method that blocks the event loop for a long time stops the health answers: the host then stops the extension.
77
+ - `onInitialize(host => ...)` sets a function that runs one time, before the first call. If it throws, the host gets the error and no method runs.
78
+
79
+ ### Cancellation
80
+
81
+ `call.signal` is an `AbortSignal`. The SDK aborts it when the host cancels the call. Give it to the functions that the method calls, for example `fetch(url, { signal: call.signal })`, or examine `call.signal.aborted` between the steps. If a method throws a value that is not a `CallError` after the signal aborted, the call fails with `ErrorCode.CANCELLED`. `CallError.cancelled()` makes the same error.
82
+
83
+ ### Host services and events
84
+
85
+ - `await call.host.call("sessions.list", { input, output }, value)` calls a method of a host service. The host fails the call with `ErrorCode.PERMISSION_DENIED` if the extension does not have the scope of the service.
86
+ - `call.host.emit(name, codec, value)` sends an event. The host adds the identifier of the extension to the name.
87
+ - `call.host.permissions` has the permissions that the user approved: `fs`, `process`, `network` and `scopes`.
88
+
89
+ A `Host` stays valid until the extension stops. Code outside a method can keep it, for example to emit events when a file changes.
90
+
91
+ ### Tests
92
+
93
+ `extension.serve(input, output)` serves a host on two Node.js streams. Use it to test an extension in the process of the test.
94
+
95
+ ## Package and run
96
+
97
+ The daemon part starts lazily, on the first call. Thus the start time is important. Bundle the extension into one file: Node.js then loads one module, not the module graph of each package. On a computer with 8 cores, the measured time from the process start to a completed handshake was 35 ms without a bundle and 25 ms with a bundle. An empty `node` process takes 17 ms.
98
+
99
+ 1. Build one file with a bundler, for example [esbuild](https://esbuild.github.io):
100
+
101
+ ```sh
102
+ esbuild src/main.ts --bundle --platform=node --target=node22 --format=esm --outfile=dist/main.js
103
+ ```
104
+
105
+ 2. Write a launcher, `bin/nomux-echo`, and make it executable (`chmod +x`):
106
+
107
+ ```sh
108
+ #!/bin/sh
109
+ exec node "$(dirname "$0")/../dist/main.js"
110
+ ```
111
+
112
+ 3. Write `extension.toml`. The `command` is the launcher:
113
+
114
+ ```toml
115
+ [extension]
116
+ id = "nomux.echo"
117
+ name = "Echo"
118
+ version = "0.1.0"
119
+ api = "^0.1"
120
+
121
+ [daemon]
122
+ command = "bin/nomux-echo"
123
+ ```
124
+
125
+ The package is the directory with `extension.toml`, `bin/` and `dist/`. The host refuses a package with a symbolic link. Thus do not put a `node_modules` directory from `npm install` in the package: its `.bin` directory has symbolic links. With a bundle, the package needs no `node_modules`.
126
+
127
+ The user must have Node.js 22 or later on the `PATH` of the nomux daemon.
128
+
129
+ To examine a package before the installation, run `nomux ext validate <directory>`.
130
+
131
+ ## Version rule
132
+
133
+ The version of this package is equal to the extension API version that it implements, as for the Rust crate. `API_VERSION` has the value. Thus `@nomux-sh/extension` 0.1.2 implements the extension API 0.1.2, and an extension built with it has the requirement `^0.1.2`. The [version rule](https://github.com/nomux-sh/extension-api/blob/main/spec/extension-protocol.md#version-rule) of the protocol applies.
134
+
135
+ ## License
136
+
137
+ MIT or Apache-2.0, at your choice.
@@ -0,0 +1,15 @@
1
+ import type { ApiVersion } from "./generated/nomux/extension/v1/handshake.js";
2
+ export type { ApiVersion };
3
+ /**
4
+ * The extension API version that this package implements. It is equal to the
5
+ * version of the package.
6
+ */
7
+ export declare const API_VERSION: Readonly<ApiVersion>;
8
+ /** Formats a version as `major.minor.patch`. */
9
+ export declare function formatVersion(version: ApiVersion): string;
10
+ /**
11
+ * Returns `true` if an extension that was built for `builtFor` can use a host
12
+ * that supplies `host`. This is the caret rule of the specification: the
13
+ * first part of `builtFor` that is not 0 sets the limit.
14
+ */
15
+ export declare function isCompatible(builtFor: ApiVersion, host: ApiVersion): boolean;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The extension API version that this package implements. It is equal to the
3
+ * version of the package.
4
+ */
5
+ export const API_VERSION = Object.freeze({
6
+ major: 0,
7
+ minor: 1,
8
+ patch: 2,
9
+ });
10
+ /** Formats a version as `major.minor.patch`. */
11
+ export function formatVersion(version) {
12
+ return `${version.major}.${version.minor}.${version.patch}`;
13
+ }
14
+ /**
15
+ * Returns `true` if an extension that was built for `builtFor` can use a host
16
+ * that supplies `host`. This is the caret rule of the specification: the
17
+ * first part of `builtFor` that is not 0 sets the limit.
18
+ */
19
+ export function isCompatible(builtFor, host) {
20
+ const limit = builtFor.major > 0
21
+ ? [builtFor.major + 1, 0, 0]
22
+ : builtFor.minor > 0
23
+ ? [0, builtFor.minor + 1, 0]
24
+ : [0, 0, builtFor.patch + 1];
25
+ const version = [host.major, host.minor, host.patch];
26
+ const minimum = [builtFor.major, builtFor.minor, builtFor.patch];
27
+ return compare(minimum, version) <= 0 && compare(version, limit) < 0;
28
+ }
29
+ function compare(left, right) {
30
+ for (let index = 0; index < left.length; index += 1) {
31
+ const difference = (left[index] ?? 0) - (right[index] ?? 0);
32
+ if (difference !== 0) {
33
+ return difference;
34
+ }
35
+ }
36
+ return 0;
37
+ }
package/dist/call.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { Host } from "./host.js";
2
+ /** The context of one call. Each method gets it as its second argument. */
3
+ export interface Call {
4
+ /** The host that sent the call. */
5
+ readonly host: Host;
6
+ /**
7
+ * Aborted when the host cancels the call. A method that can run for a long
8
+ * time gives it to the functions that it calls, or examines
9
+ * `signal.aborted` between its steps.
10
+ */
11
+ readonly signal: AbortSignal;
12
+ }
package/dist/call.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The encoding of a payload: the argument or the result of a method, or the
3
+ * data of an event.
4
+ *
5
+ * The method specifies the encoding. An encoded protobuf message is the
6
+ * usual choice. `decode` throws if the bytes are not valid.
7
+ */
8
+ export interface Codec<Value> {
9
+ /** Encodes a value. */
10
+ encode(value: Value): Uint8Array;
11
+ /** Decodes bytes. Throws if the bytes are not a valid value. */
12
+ decode(bytes: Uint8Array): Value;
13
+ }
14
+ /** The codec of a payload that the method reads as bytes. */
15
+ export declare const bytes: Codec<Uint8Array>;
16
+ /** The codecs of the argument and the result of a method. */
17
+ export interface MethodCodecs<Input, Output> {
18
+ /** The codec of the argument. */
19
+ readonly input: Codec<Input>;
20
+ /** The codec of the result. */
21
+ readonly output: Codec<Output>;
22
+ }
package/dist/codec.js ADDED
@@ -0,0 +1,5 @@
1
+ /** The codec of a payload that the method reads as bytes. */
2
+ export const bytes = {
3
+ encode: (value) => value,
4
+ decode: (value) => value,
5
+ };
@@ -0,0 +1,57 @@
1
+ import type { Readable, Writable } from "node:stream";
2
+ import type { Call } from "./call.js";
3
+ import type { CallRequest } from "./generated/nomux/extension/v1/call.js";
4
+ import type { Response } from "./generated/nomux/extension/v1/envelope.js";
5
+ import type { Identity } from "./handshake.js";
6
+ /** The work of a request that runs in the queue of the extension. */
7
+ export type Work = {
8
+ readonly $case: "initialize";
9
+ } | {
10
+ readonly $case: "shutdown";
11
+ } | {
12
+ readonly $case: "call";
13
+ readonly value: CallRequest;
14
+ };
15
+ /** The result of a request. */
16
+ export type Result = NonNullable<Response["result"]>;
17
+ /** Does the work of one request. The promise does not reject. */
18
+ export type Answer = (work: Work, call: Call) => Promise<Result>;
19
+ /**
20
+ * One connection to the host, from `Hello` to the end.
21
+ *
22
+ * The connection reads the frames as they arrive. It answers health
23
+ * requests, records cancellations and gives the responses of host services
24
+ * to the calls that wait for them at once. The work of the other requests
25
+ * runs in a queue, one request at a time, in the sequence of arrival.
26
+ */
27
+ export declare class Connection {
28
+ private readonly input;
29
+ private readonly identity;
30
+ private readonly answer;
31
+ private readonly reader;
32
+ private readonly outbound;
33
+ private readonly pending;
34
+ private readonly cancellations;
35
+ private readonly queue;
36
+ private host;
37
+ private isWorking;
38
+ private isStopped;
39
+ private resolve;
40
+ private reject;
41
+ private readonly onData;
42
+ private readonly onEnd;
43
+ private readonly onError;
44
+ constructor(input: Readable, output: Writable, identity: Identity, answer: Answer);
45
+ /** Serves the host until a shutdown request or a failure. */
46
+ run(): Promise<void>;
47
+ private receive;
48
+ private receiveEnd;
49
+ private route;
50
+ private handshake;
51
+ private routeRequest;
52
+ private enqueue;
53
+ private work;
54
+ private respond;
55
+ /** Stops the connection. `error` is `undefined` after a shutdown request. */
56
+ private stop;
57
+ }