@nomux-sh/extension 0.0.0-stage → 0.1.3
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 +202 -0
- package/LICENSE-MIT +22 -0
- package/README.md +144 -2
- package/dist/api-version.d.ts +22 -0
- package/dist/api-version.js +48 -0
- package/dist/call.d.ts +12 -0
- package/dist/call.js +1 -0
- package/dist/codec.d.ts +22 -0
- package/dist/codec.js +5 -0
- package/dist/connection.d.ts +57 -0
- package/dist/connection.js +183 -0
- package/dist/error.d.ts +41 -0
- package/dist/error.js +61 -0
- package/dist/extension.d.ts +90 -0
- package/dist/extension.js +153 -0
- package/dist/frame.d.ts +32 -0
- package/dist/frame.js +99 -0
- package/dist/generated/nomux/extension/v1/call.d.ts +29 -0
- package/dist/generated/nomux/extension/v1/call.js +103 -0
- package/dist/generated/nomux/extension/v1/envelope.d.ts +176 -0
- package/dist/generated/nomux/extension/v1/envelope.js +476 -0
- package/dist/generated/nomux/extension/v1/handshake.d.ts +66 -0
- package/dist/generated/nomux/extension/v1/handshake.js +269 -0
- package/dist/generated/nomux/extension/v1/lifecycle.d.ts +36 -0
- package/dist/generated/nomux/extension/v1/lifecycle.js +205 -0
- package/dist/handshake.d.ts +21 -0
- package/dist/handshake.js +36 -0
- package/dist/host.d.ts +37 -0
- package/dist/host.js +73 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +16 -0
- package/dist/outbound.d.ts +16 -0
- package/dist/outbound.js +30 -0
- package/dist/pending-calls.d.ts +20 -0
- package/dist/pending-calls.js +43 -0
- package/package.json +53 -4
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-ts_proto v2.18.5
|
|
4
|
+
// protoc unknown
|
|
5
|
+
// source: nomux/extension/v1/handshake.proto
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
8
|
+
function createBaseApiVersion() {
|
|
9
|
+
return { major: 0, minor: 0, patch: 0 };
|
|
10
|
+
}
|
|
11
|
+
export const ApiVersion = {
|
|
12
|
+
encode(message, writer = new BinaryWriter()) {
|
|
13
|
+
if (message.major !== 0) {
|
|
14
|
+
writer.uint32(8).uint32(message.major);
|
|
15
|
+
}
|
|
16
|
+
if (message.minor !== 0) {
|
|
17
|
+
writer.uint32(16).uint32(message.minor);
|
|
18
|
+
}
|
|
19
|
+
if (message.patch !== 0) {
|
|
20
|
+
writer.uint32(24).uint32(message.patch);
|
|
21
|
+
}
|
|
22
|
+
return writer;
|
|
23
|
+
},
|
|
24
|
+
decode(input, length) {
|
|
25
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
26
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
27
|
+
if (previousRecursionDepth >= 100) {
|
|
28
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
29
|
+
}
|
|
30
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
31
|
+
try {
|
|
32
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
33
|
+
const message = createBaseApiVersion();
|
|
34
|
+
while (reader.pos < end) {
|
|
35
|
+
const tag = reader.uint32();
|
|
36
|
+
switch (tag >>> 3) {
|
|
37
|
+
case 1: {
|
|
38
|
+
if (tag !== 8) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
message.major = reader.uint32();
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
case 2: {
|
|
45
|
+
if (tag !== 16) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
message.minor = reader.uint32();
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
case 3: {
|
|
52
|
+
if (tag !== 24) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
message.patch = reader.uint32();
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
reader.skip(tag & 7);
|
|
63
|
+
}
|
|
64
|
+
return message;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
function createBasePermissions() {
|
|
72
|
+
return { fs: [], process: [], network: false, scopes: [] };
|
|
73
|
+
}
|
|
74
|
+
export const Permissions = {
|
|
75
|
+
encode(message, writer = new BinaryWriter()) {
|
|
76
|
+
for (const v of message.fs) {
|
|
77
|
+
writer.uint32(10).string(v);
|
|
78
|
+
}
|
|
79
|
+
for (const v of message.process) {
|
|
80
|
+
writer.uint32(18).string(v);
|
|
81
|
+
}
|
|
82
|
+
if (message.network !== false) {
|
|
83
|
+
writer.uint32(24).bool(message.network);
|
|
84
|
+
}
|
|
85
|
+
for (const v of message.scopes) {
|
|
86
|
+
writer.uint32(34).string(v);
|
|
87
|
+
}
|
|
88
|
+
return writer;
|
|
89
|
+
},
|
|
90
|
+
decode(input, length) {
|
|
91
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
92
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
93
|
+
if (previousRecursionDepth >= 100) {
|
|
94
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
95
|
+
}
|
|
96
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
97
|
+
try {
|
|
98
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
99
|
+
const message = createBasePermissions();
|
|
100
|
+
while (reader.pos < end) {
|
|
101
|
+
const tag = reader.uint32();
|
|
102
|
+
switch (tag >>> 3) {
|
|
103
|
+
case 1: {
|
|
104
|
+
if (tag !== 10) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
message.fs.push(reader.string());
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
case 2: {
|
|
111
|
+
if (tag !== 18) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
message.process.push(reader.string());
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
case 3: {
|
|
118
|
+
if (tag !== 24) {
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
message.network = reader.bool();
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
case 4: {
|
|
125
|
+
if (tag !== 34) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
message.scopes.push(reader.string());
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
reader.skip(tag & 7);
|
|
136
|
+
}
|
|
137
|
+
return message;
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
function createBaseHello() {
|
|
145
|
+
return { apiVersion: undefined, extensionId: "", permissions: undefined };
|
|
146
|
+
}
|
|
147
|
+
export const Hello = {
|
|
148
|
+
encode(message, writer = new BinaryWriter()) {
|
|
149
|
+
if (message.apiVersion !== undefined) {
|
|
150
|
+
ApiVersion.encode(message.apiVersion, writer.uint32(10).fork()).join();
|
|
151
|
+
}
|
|
152
|
+
if (message.extensionId !== "") {
|
|
153
|
+
writer.uint32(18).string(message.extensionId);
|
|
154
|
+
}
|
|
155
|
+
if (message.permissions !== undefined) {
|
|
156
|
+
Permissions.encode(message.permissions, writer.uint32(26).fork()).join();
|
|
157
|
+
}
|
|
158
|
+
return writer;
|
|
159
|
+
},
|
|
160
|
+
decode(input, length) {
|
|
161
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
162
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
163
|
+
if (previousRecursionDepth >= 100) {
|
|
164
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
165
|
+
}
|
|
166
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
167
|
+
try {
|
|
168
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
169
|
+
const message = createBaseHello();
|
|
170
|
+
while (reader.pos < end) {
|
|
171
|
+
const tag = reader.uint32();
|
|
172
|
+
switch (tag >>> 3) {
|
|
173
|
+
case 1: {
|
|
174
|
+
if (tag !== 10) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
message.apiVersion = ApiVersion.decode(reader, reader.uint32());
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
case 2: {
|
|
181
|
+
if (tag !== 18) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
message.extensionId = reader.string();
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
case 3: {
|
|
188
|
+
if (tag !== 26) {
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
message.permissions = Permissions.decode(reader, reader.uint32());
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
reader.skip(tag & 7);
|
|
199
|
+
}
|
|
200
|
+
return message;
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
function createBaseWelcome() {
|
|
208
|
+
return { apiVersion: undefined, extensionId: "", extensionVersion: "" };
|
|
209
|
+
}
|
|
210
|
+
export const Welcome = {
|
|
211
|
+
encode(message, writer = new BinaryWriter()) {
|
|
212
|
+
if (message.apiVersion !== undefined) {
|
|
213
|
+
ApiVersion.encode(message.apiVersion, writer.uint32(10).fork()).join();
|
|
214
|
+
}
|
|
215
|
+
if (message.extensionId !== "") {
|
|
216
|
+
writer.uint32(18).string(message.extensionId);
|
|
217
|
+
}
|
|
218
|
+
if (message.extensionVersion !== "") {
|
|
219
|
+
writer.uint32(26).string(message.extensionVersion);
|
|
220
|
+
}
|
|
221
|
+
return writer;
|
|
222
|
+
},
|
|
223
|
+
decode(input, length) {
|
|
224
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
225
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
226
|
+
if (previousRecursionDepth >= 100) {
|
|
227
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
228
|
+
}
|
|
229
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
230
|
+
try {
|
|
231
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
232
|
+
const message = createBaseWelcome();
|
|
233
|
+
while (reader.pos < end) {
|
|
234
|
+
const tag = reader.uint32();
|
|
235
|
+
switch (tag >>> 3) {
|
|
236
|
+
case 1: {
|
|
237
|
+
if (tag !== 10) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
message.apiVersion = ApiVersion.decode(reader, reader.uint32());
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
case 2: {
|
|
244
|
+
if (tag !== 18) {
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
message.extensionId = reader.string();
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
case 3: {
|
|
251
|
+
if (tag !== 26) {
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
message.extensionVersion = reader.string();
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
reader.skip(tag & 7);
|
|
262
|
+
}
|
|
263
|
+
return message;
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
2
|
+
/**
|
|
3
|
+
* Tells the extension to prepare for calls. The host sends it one time, after
|
|
4
|
+
* the handshake and before the first call.
|
|
5
|
+
*/
|
|
6
|
+
export interface InitializeRequest {
|
|
7
|
+
}
|
|
8
|
+
/** The reply to `InitializeRequest`. After it, the extension accepts calls. */
|
|
9
|
+
export interface InitializeResponse {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Tells the extension to stop. The host sends it when the extension is idle
|
|
13
|
+
* or when the daemon stops.
|
|
14
|
+
*/
|
|
15
|
+
export interface ShutdownRequest {
|
|
16
|
+
}
|
|
17
|
+
/** The reply to `ShutdownRequest`. The extension sends it and then exits. */
|
|
18
|
+
export interface ShutdownResponse {
|
|
19
|
+
}
|
|
20
|
+
/** Asks the extension if it can still read and write messages. */
|
|
21
|
+
export interface HealthRequest {
|
|
22
|
+
}
|
|
23
|
+
/** The reply to `HealthRequest`. An extension answers also while a call runs. */
|
|
24
|
+
export interface HealthResponse {
|
|
25
|
+
}
|
|
26
|
+
export declare const InitializeRequest: MessageFns<InitializeRequest>;
|
|
27
|
+
export declare const InitializeResponse: MessageFns<InitializeResponse>;
|
|
28
|
+
export declare const ShutdownRequest: MessageFns<ShutdownRequest>;
|
|
29
|
+
export declare const ShutdownResponse: MessageFns<ShutdownResponse>;
|
|
30
|
+
export declare const HealthRequest: MessageFns<HealthRequest>;
|
|
31
|
+
export declare const HealthResponse: MessageFns<HealthResponse>;
|
|
32
|
+
interface MessageFns<T> {
|
|
33
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
34
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-ts_proto v2.18.5
|
|
4
|
+
// protoc unknown
|
|
5
|
+
// source: nomux/extension/v1/lifecycle.proto
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
8
|
+
function createBaseInitializeRequest() {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
export const InitializeRequest = {
|
|
12
|
+
encode(_, writer = new BinaryWriter()) {
|
|
13
|
+
return writer;
|
|
14
|
+
},
|
|
15
|
+
decode(input, length) {
|
|
16
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
17
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
18
|
+
if (previousRecursionDepth >= 100) {
|
|
19
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
20
|
+
}
|
|
21
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
22
|
+
try {
|
|
23
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
24
|
+
const message = createBaseInitializeRequest();
|
|
25
|
+
while (reader.pos < end) {
|
|
26
|
+
const tag = reader.uint32();
|
|
27
|
+
switch (tag >>> 3) {
|
|
28
|
+
}
|
|
29
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
reader.skip(tag & 7);
|
|
33
|
+
}
|
|
34
|
+
return message;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
function createBaseInitializeResponse() {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
export const InitializeResponse = {
|
|
45
|
+
encode(_, writer = new BinaryWriter()) {
|
|
46
|
+
return writer;
|
|
47
|
+
},
|
|
48
|
+
decode(input, length) {
|
|
49
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
50
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
51
|
+
if (previousRecursionDepth >= 100) {
|
|
52
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
53
|
+
}
|
|
54
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
55
|
+
try {
|
|
56
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
57
|
+
const message = createBaseInitializeResponse();
|
|
58
|
+
while (reader.pos < end) {
|
|
59
|
+
const tag = reader.uint32();
|
|
60
|
+
switch (tag >>> 3) {
|
|
61
|
+
}
|
|
62
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
reader.skip(tag & 7);
|
|
66
|
+
}
|
|
67
|
+
return message;
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
function createBaseShutdownRequest() {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
export const ShutdownRequest = {
|
|
78
|
+
encode(_, writer = new BinaryWriter()) {
|
|
79
|
+
return writer;
|
|
80
|
+
},
|
|
81
|
+
decode(input, length) {
|
|
82
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
83
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
84
|
+
if (previousRecursionDepth >= 100) {
|
|
85
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
86
|
+
}
|
|
87
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
88
|
+
try {
|
|
89
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
90
|
+
const message = createBaseShutdownRequest();
|
|
91
|
+
while (reader.pos < end) {
|
|
92
|
+
const tag = reader.uint32();
|
|
93
|
+
switch (tag >>> 3) {
|
|
94
|
+
}
|
|
95
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
reader.skip(tag & 7);
|
|
99
|
+
}
|
|
100
|
+
return message;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
function createBaseShutdownResponse() {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
export const ShutdownResponse = {
|
|
111
|
+
encode(_, writer = new BinaryWriter()) {
|
|
112
|
+
return writer;
|
|
113
|
+
},
|
|
114
|
+
decode(input, length) {
|
|
115
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
116
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
117
|
+
if (previousRecursionDepth >= 100) {
|
|
118
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
119
|
+
}
|
|
120
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
121
|
+
try {
|
|
122
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
123
|
+
const message = createBaseShutdownResponse();
|
|
124
|
+
while (reader.pos < end) {
|
|
125
|
+
const tag = reader.uint32();
|
|
126
|
+
switch (tag >>> 3) {
|
|
127
|
+
}
|
|
128
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
reader.skip(tag & 7);
|
|
132
|
+
}
|
|
133
|
+
return message;
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
function createBaseHealthRequest() {
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
export const HealthRequest = {
|
|
144
|
+
encode(_, writer = new BinaryWriter()) {
|
|
145
|
+
return writer;
|
|
146
|
+
},
|
|
147
|
+
decode(input, length) {
|
|
148
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
149
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
150
|
+
if (previousRecursionDepth >= 100) {
|
|
151
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
152
|
+
}
|
|
153
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
154
|
+
try {
|
|
155
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
156
|
+
const message = createBaseHealthRequest();
|
|
157
|
+
while (reader.pos < end) {
|
|
158
|
+
const tag = reader.uint32();
|
|
159
|
+
switch (tag >>> 3) {
|
|
160
|
+
}
|
|
161
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
reader.skip(tag & 7);
|
|
165
|
+
}
|
|
166
|
+
return message;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
function createBaseHealthResponse() {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
export const HealthResponse = {
|
|
177
|
+
encode(_, writer = new BinaryWriter()) {
|
|
178
|
+
return writer;
|
|
179
|
+
},
|
|
180
|
+
decode(input, length) {
|
|
181
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
182
|
+
const previousRecursionDepth = reader.__tsProtoDecodeDepth ?? 0;
|
|
183
|
+
if (previousRecursionDepth >= 100) {
|
|
184
|
+
throw new globalThis.Error("protobuf decode recursion limit exceeded");
|
|
185
|
+
}
|
|
186
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
|
|
187
|
+
try {
|
|
188
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
189
|
+
const message = createBaseHealthResponse();
|
|
190
|
+
while (reader.pos < end) {
|
|
191
|
+
const tag = reader.uint32();
|
|
192
|
+
switch (tag >>> 3) {
|
|
193
|
+
}
|
|
194
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
reader.skip(tag & 7);
|
|
198
|
+
}
|
|
199
|
+
return message;
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
reader.__tsProtoDecodeDepth = previousRecursionDepth;
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RunError } from "./error.js";
|
|
2
|
+
import type { Envelope, Response } from "./generated/nomux/extension/v1/envelope.js";
|
|
3
|
+
import type { ApiVersion, Permissions } from "./generated/nomux/extension/v1/handshake.js";
|
|
4
|
+
/**
|
|
5
|
+
* The identifier and the version of the extension, and the lowest extension
|
|
6
|
+
* API version that it needs.
|
|
7
|
+
*/
|
|
8
|
+
export interface Identity {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly version: string;
|
|
11
|
+
readonly api: ApiVersion;
|
|
12
|
+
}
|
|
13
|
+
/** The answer to the first message of the host. */
|
|
14
|
+
export interface HandshakeAnswer {
|
|
15
|
+
/** The response to send. `undefined` if the first message is not `Hello`. */
|
|
16
|
+
readonly response: Response | undefined;
|
|
17
|
+
/** The permissions, or the reason why the extension stops. */
|
|
18
|
+
readonly outcome: Permissions | RunError;
|
|
19
|
+
}
|
|
20
|
+
/** Reads `Hello`, applies the version rule and makes the answer. */
|
|
21
|
+
export declare function answerHello(envelope: Envelope, identity: Identity): HandshakeAnswer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { API_VERSION, formatVersion, isCompatible } from "./api-version.js";
|
|
2
|
+
import { ErrorCode, RunError } from "./error.js";
|
|
3
|
+
/** Reads `Hello`, applies the version rule and makes the answer. */
|
|
4
|
+
export function answerHello(envelope, identity) {
|
|
5
|
+
const request = envelope.kind?.$case === "request" ? envelope.kind.value : undefined;
|
|
6
|
+
if (request?.body?.$case !== "hello") {
|
|
7
|
+
return {
|
|
8
|
+
response: undefined,
|
|
9
|
+
outcome: new RunError("no-hello", "the first message from the host was not `Hello`"),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const hello = request.body.value;
|
|
13
|
+
const host = hello.apiVersion ?? { major: 0, minor: 0, patch: 0 };
|
|
14
|
+
if (!isCompatible(identity.api, host)) {
|
|
15
|
+
const message = `the extension needs the extension API version ^${formatVersion(identity.api)}, but the host supplies ${formatVersion(host)}`;
|
|
16
|
+
return {
|
|
17
|
+
response: {
|
|
18
|
+
id: request.id,
|
|
19
|
+
result: {
|
|
20
|
+
$case: "error",
|
|
21
|
+
value: { code: ErrorCode.VERSION_INCOMPATIBLE, message },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
outcome: new RunError("incompatible-api", message),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const welcome = {
|
|
28
|
+
apiVersion: { ...API_VERSION },
|
|
29
|
+
extensionId: identity.id,
|
|
30
|
+
extensionVersion: identity.version,
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
response: { id: request.id, result: { $case: "welcome", value: welcome } },
|
|
34
|
+
outcome: hello.permissions ?? { fs: [], process: [], network: false, scopes: [] },
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Codec, MethodCodecs } from "./codec.js";
|
|
2
|
+
import type { Permissions } from "./generated/nomux/extension/v1/handshake.js";
|
|
3
|
+
import type { Outbound } from "./outbound.js";
|
|
4
|
+
import type { PendingCalls } from "./pending-calls.js";
|
|
5
|
+
export type { Permissions };
|
|
6
|
+
/**
|
|
7
|
+
* The nomux daemon that started the extension.
|
|
8
|
+
*
|
|
9
|
+
* A method gets the host from `call.host`. The host stays valid until the
|
|
10
|
+
* extension stops, thus code outside a method can keep it, for example to
|
|
11
|
+
* emit events when a file changes.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Host {
|
|
14
|
+
/** The permissions that the user approved for the extension. */
|
|
15
|
+
readonly permissions: Readonly<Permissions>;
|
|
16
|
+
private readonly outbound;
|
|
17
|
+
private readonly pending;
|
|
18
|
+
/** The SDK makes the host. An extension does not call this constructor. */
|
|
19
|
+
constructor(outbound: Outbound, pending: PendingCalls, permissions: Permissions);
|
|
20
|
+
/**
|
|
21
|
+
* Calls a method of a host service and waits for the result.
|
|
22
|
+
*
|
|
23
|
+
* `method` has the form `<service>.<method>`, for example `sessions.list`.
|
|
24
|
+
* The host fails the call with {@link ErrorCode.PERMISSION_DENIED} if the
|
|
25
|
+
* extension does not have the scope of the service. The promise rejects
|
|
26
|
+
* with a {@link CallError}.
|
|
27
|
+
*/
|
|
28
|
+
call<Input, Output>(method: string, codecs: MethodCodecs<Input, Output>, input: Input): Promise<Output>;
|
|
29
|
+
/**
|
|
30
|
+
* Sends an event to the host. The host adds the identifier of the
|
|
31
|
+
* extension to the name. Throws a {@link CallError} if the event was not
|
|
32
|
+
* sent.
|
|
33
|
+
*/
|
|
34
|
+
emit<Value>(name: string, codec: Codec<Value>, value: Value): void;
|
|
35
|
+
}
|
|
36
|
+
/** Decodes a payload. A payload that is not valid is an invalid argument. */
|
|
37
|
+
export declare function decode<Value>(codec: Codec<Value>, payload: Uint8Array, what: string): Value;
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CallError, ErrorCode, describe } from "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* The nomux daemon that started the extension.
|
|
4
|
+
*
|
|
5
|
+
* A method gets the host from `call.host`. The host stays valid until the
|
|
6
|
+
* extension stops, thus code outside a method can keep it, for example to
|
|
7
|
+
* emit events when a file changes.
|
|
8
|
+
*/
|
|
9
|
+
export class Host {
|
|
10
|
+
/** The permissions that the user approved for the extension. */
|
|
11
|
+
permissions;
|
|
12
|
+
outbound;
|
|
13
|
+
pending;
|
|
14
|
+
/** The SDK makes the host. An extension does not call this constructor. */
|
|
15
|
+
constructor(outbound, pending, permissions) {
|
|
16
|
+
this.outbound = outbound;
|
|
17
|
+
this.pending = pending;
|
|
18
|
+
this.permissions = Object.freeze(permissions);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calls a method of a host service and waits for the result.
|
|
22
|
+
*
|
|
23
|
+
* `method` has the form `<service>.<method>`, for example `sessions.list`.
|
|
24
|
+
* The host fails the call with {@link ErrorCode.PERMISSION_DENIED} if the
|
|
25
|
+
* extension does not have the scope of the service. The promise rejects
|
|
26
|
+
* with a {@link CallError}.
|
|
27
|
+
*/
|
|
28
|
+
async call(method, codecs, input) {
|
|
29
|
+
const { id, response } = this.pending.register();
|
|
30
|
+
try {
|
|
31
|
+
const payload = codecs.input.encode(input);
|
|
32
|
+
this.outbound.send({
|
|
33
|
+
$case: "request",
|
|
34
|
+
value: { id, body: { $case: "call", value: { method, payload } } },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
this.pending.forget(id);
|
|
39
|
+
throw CallError.failed(`the call of \`${method}\` was not sent: ${describe(error)}`);
|
|
40
|
+
}
|
|
41
|
+
const { result } = await response;
|
|
42
|
+
switch (result?.$case) {
|
|
43
|
+
case "call":
|
|
44
|
+
return decode(codecs.output, result.value.payload, `the result of \`${method}\``);
|
|
45
|
+
case "error":
|
|
46
|
+
throw CallError.fromWire(result.value);
|
|
47
|
+
default:
|
|
48
|
+
throw CallError.failed(`the host did not answer \`${method}\` with a call result`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sends an event to the host. The host adds the identifier of the
|
|
53
|
+
* extension to the name. Throws a {@link CallError} if the event was not
|
|
54
|
+
* sent.
|
|
55
|
+
*/
|
|
56
|
+
emit(name, codec, value) {
|
|
57
|
+
try {
|
|
58
|
+
this.outbound.send({ $case: "event", value: { name, payload: codec.encode(value) } });
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw CallError.failed(`the event \`${name}\` was not sent: ${describe(error)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Decodes a payload. A payload that is not valid is an invalid argument. */
|
|
66
|
+
export function decode(codec, payload, what) {
|
|
67
|
+
try {
|
|
68
|
+
return codec.decode(payload);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new CallError(ErrorCode.INVALID_ARGUMENT, `${what} is not valid: ${describe(error)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|