@ts-pf/message-client 0.1.5 → 0.2.1
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 +21 -0
- package/README.md +48 -2
- package/dist/call.d.ts +59 -0
- package/dist/call.d.ts.map +1 -0
- package/dist/call.js +269 -0
- package/dist/call.js.map +1 -0
- package/dist/duplex.d.ts +30 -0
- package/dist/duplex.d.ts.map +1 -0
- package/dist/duplex.js +108 -0
- package/dist/duplex.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/port.d.ts +3 -2
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +9 -18
- package/dist/port.js.map +1 -1
- package/dist/shared.d.ts +19 -9
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +33 -323
- package/dist/shared.js.map +1 -1
- package/dist/stdio.d.ts +3 -2
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +10 -18
- package/dist/stdio.js.map +1 -1
- package/dist/ws.d.ts +8 -2
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +33 -60
- package/dist/ws.js.map +1 -1
- package/package.json +12 -7
- package/skills/ts-pf-message-client/SKILL.md +32 -3
- package/dist/is-async-iterable.d.ts +0 -2
- package/dist/is-async-iterable.d.ts.map +0 -1
- package/dist/is-async-iterable.js +0 -12
- package/dist/is-async-iterable.js.map +0 -1
- package/dist/push-queue.d.ts +0 -7
- package/dist/push-queue.d.ts.map +0 -1
- package/dist/push-queue.js +0 -74
- package/dist/push-queue.js.map +0 -1
package/dist/port.js
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import { createPortDuplex } from '@ts-pf/message';
|
|
2
|
-
import {
|
|
2
|
+
import { DuplexLink } from './duplex.js';
|
|
3
|
+
/** `DuplexLink` over `createPortDuplex`; `close()` also closes the port. */
|
|
3
4
|
export class PortLink {
|
|
4
|
-
|
|
5
|
+
link;
|
|
5
6
|
port;
|
|
6
7
|
closed = false;
|
|
7
8
|
constructor(opts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
attach.meta = opts.meta;
|
|
13
|
-
}
|
|
14
|
-
if (opts.maxFrameBytes !== undefined) {
|
|
15
|
-
attach.maxFrameBytes = opts.maxFrameBytes;
|
|
16
|
-
}
|
|
17
|
-
if (opts.helloTimeoutMs !== undefined) {
|
|
18
|
-
attach.helloTimeoutMs = opts.helloTimeoutMs;
|
|
19
|
-
}
|
|
20
|
-
this.attached = attachClient(attach);
|
|
21
|
-
opts.port.start();
|
|
9
|
+
const { port, ...options } = opts;
|
|
10
|
+
this.port = port;
|
|
11
|
+
this.link = new DuplexLink({ duplex: createPortDuplex(port), ...options });
|
|
12
|
+
port.start();
|
|
22
13
|
}
|
|
23
14
|
call(path, input, signal) {
|
|
24
|
-
return this.
|
|
15
|
+
return this.link.call(path, input, signal);
|
|
25
16
|
}
|
|
26
17
|
close() {
|
|
27
18
|
if (this.closed) {
|
|
28
19
|
return;
|
|
29
20
|
}
|
|
30
21
|
this.closed = true;
|
|
31
|
-
this.
|
|
22
|
+
this.link.close();
|
|
32
23
|
try {
|
|
33
24
|
this.port.close();
|
|
34
25
|
}
|
package/dist/port.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"port.js","sourceRoot":"","sources":["../src/port.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"port.js","sourceRoot":"","sources":["../src/port.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,4EAA4E;AAC5E,MAAM,OAAO,QAAQ;IACF,IAAI,CAAY;IAChB,IAAI,CAAa;IAC1B,MAAM,GAAG,KAAK,CAAA;IAEtB,YAAY,IAAyC;QACnD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAA;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC1E,IAAI,CAAC,KAAK,EAAE,CAAA;IACd,CAAC;IAED,IAAI,CACF,IAAc,EACd,KAAc,EACd,MAAoB;QAEpB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAM;QACR,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;QACjB,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,uBAAuB;QACzB,CAAC;IACH,CAAC;CACF"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type
|
|
1
|
+
import type { BackpressureOptions } from '@ts-pf/message';
|
|
2
|
+
import { type PFError } from '@ts-pf/protocol';
|
|
3
|
+
export type { BackpressureOptions, StallInfo } from '@ts-pf/message';
|
|
3
4
|
export type LinkOptions = {
|
|
4
5
|
meta?: unknown;
|
|
5
6
|
maxFrameBytes?: number;
|
|
6
7
|
helloTimeoutMs?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Slow-peer protection for input streams this client pushes and output
|
|
10
|
+
* streams it reads, on by default (1 MiB `highWaterMark`, 30 s
|
|
11
|
+
* `drainTimeout`, one `console.warn` per stall). A bad value throws a
|
|
12
|
+
* `TypeError` from the constructor.
|
|
13
|
+
*/
|
|
14
|
+
backpressure?: BackpressureOptions;
|
|
7
15
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
/** Envelope items only: a `ReadableStream` is bytes, not items; it is sent as a plain JSON value. */
|
|
17
|
+
export declare function isItemStream(value: unknown): value is AsyncIterable<unknown>;
|
|
18
|
+
export declare function abortedFailure(signal: AbortSignal): PFError;
|
|
19
|
+
/**
|
|
20
|
+
* `promise`, or a local `Request aborted` as soon as `signal` fires. An
|
|
21
|
+
* abort that lands before the promise settles wins even if both are
|
|
22
|
+
* observed in the same turn. Without a signal this is `promise` itself.
|
|
23
|
+
*/
|
|
24
|
+
export declare function awaitWithAbort<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
15
25
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE7E,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEpE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAA;CACnC,CAAA;AAED,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAK5E;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAI3D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAgCZ"}
|
package/dist/shared.js
CHANGED
|
@@ -1,337 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { isAsyncIterable, localFailure } from '@ts-pf/protocol';
|
|
2
|
+
/** Envelope items only: a `ReadableStream` is bytes, not items; it is sent as a plain JSON value. */
|
|
3
|
+
export function isItemStream(value) {
|
|
4
|
+
return (isAsyncIterable(value) &&
|
|
5
|
+
!(typeof ReadableStream !== 'undefined' && value instanceof ReadableStream));
|
|
6
|
+
}
|
|
7
|
+
export function abortedFailure(signal) {
|
|
5
8
|
return signal.reason !== undefined
|
|
6
9
|
? localFailure('Request aborted', signal.reason)
|
|
7
10
|
: localFailure('Request aborted');
|
|
8
11
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (reason === 'stringify') {
|
|
28
|
-
return errorFromEnvelope({
|
|
29
|
-
code: 'INTERNAL',
|
|
30
|
-
message: 'Internal server error',
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return localFailure('Connection closed');
|
|
34
|
-
}
|
|
35
|
-
export function attachClient(options) {
|
|
36
|
-
let next = 1;
|
|
37
|
-
let closed = false;
|
|
38
|
-
const inflight = new Map();
|
|
39
|
-
const session = new MessageSession({
|
|
40
|
-
duplex: options.duplex,
|
|
41
|
-
role: 'client',
|
|
42
|
-
...(options.maxFrameBytes !== undefined
|
|
43
|
-
? { maxFrameBytes: options.maxFrameBytes }
|
|
44
|
-
: {}),
|
|
45
|
-
...(options.helloTimeoutMs !== undefined
|
|
46
|
-
? { helloTimeoutMs: options.helloTimeoutMs }
|
|
47
|
-
: {}),
|
|
48
|
-
...(options.meta !== undefined ? { helloMeta: options.meta } : {}),
|
|
49
|
-
onFrame: (frame) => {
|
|
50
|
-
handleFrame(frame);
|
|
51
|
-
},
|
|
52
|
-
// decode failures never settle a call, in-flight or not
|
|
53
|
-
onInvalidFrame: () => { },
|
|
54
|
-
onClose: (reason) => {
|
|
55
|
-
closed = true;
|
|
56
|
-
const error = reason === undefined
|
|
57
|
-
? localFailure('Connection closed')
|
|
58
|
-
: localFailure('Connection closed', reason);
|
|
59
|
-
for (const [id, rec] of [...inflight]) {
|
|
60
|
-
const mode = rec.mode;
|
|
61
|
-
finish(id, rec, () => {
|
|
62
|
-
if (mode === 'pending-first') {
|
|
63
|
-
rec.reject(error);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
rec.output?.fail(error);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
void session.ready.catch(() => {
|
|
72
|
-
// handshake / close rejects ready; call() re-awaits the same promise
|
|
73
|
-
});
|
|
74
|
-
function finish(id, rec, action) {
|
|
75
|
-
if (rec.mode === 'done') {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
rec.mode = 'done';
|
|
79
|
-
rec.sendingInput = false;
|
|
80
|
-
inflight.delete(id);
|
|
81
|
-
rec.unsubAbort?.();
|
|
82
|
-
void Promise.resolve(rec.inputIterator?.return?.()).then(() => { }, () => { });
|
|
83
|
-
action();
|
|
84
|
-
}
|
|
85
|
-
function wrapOutput(id, rec, queue) {
|
|
86
|
-
return {
|
|
87
|
-
[Symbol.asyncIterator]() {
|
|
88
|
-
const inner = queue[Symbol.asyncIterator]();
|
|
89
|
-
return {
|
|
90
|
-
next: () => inner.next(),
|
|
91
|
-
async return() {
|
|
92
|
-
if (rec.mode !== 'done') {
|
|
93
|
-
finish(id, rec, () => {
|
|
94
|
-
session.send({ type: 'cancel', id });
|
|
95
|
-
rec.output?.end();
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return { done: true, value: undefined };
|
|
99
|
-
},
|
|
100
|
-
async throw(error) {
|
|
101
|
-
if (rec.mode !== 'done') {
|
|
102
|
-
finish(id, rec, () => {
|
|
103
|
-
session.send({ type: 'cancel', id });
|
|
104
|
-
rec.output?.fail(error);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
throw error;
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
},
|
|
12
|
+
/**
|
|
13
|
+
* `promise`, or a local `Request aborted` as soon as `signal` fires. An
|
|
14
|
+
* abort that lands before the promise settles wins even if both are
|
|
15
|
+
* observed in the same turn. Without a signal this is `promise` itself.
|
|
16
|
+
*/
|
|
17
|
+
export function awaitWithAbort(promise, signal) {
|
|
18
|
+
if (signal === undefined) {
|
|
19
|
+
return promise;
|
|
20
|
+
}
|
|
21
|
+
if (signal.aborted) {
|
|
22
|
+
return Promise.reject(abortedFailure(signal));
|
|
23
|
+
}
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const onAbort = () => {
|
|
26
|
+
signal.removeEventListener('abort', onAbort);
|
|
27
|
+
reject(abortedFailure(signal));
|
|
111
28
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (frame.type === 'done') {
|
|
119
|
-
finish(frame.id, rec, () => {
|
|
120
|
-
rec.output?.end();
|
|
121
|
-
});
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (frame.type === 'result' && !frame.ok) {
|
|
125
|
-
finish(frame.id, rec, () => {
|
|
126
|
-
rec.output?.fail(errorFromEnvelope(frame.error));
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function handleFrame(frame) {
|
|
131
|
-
if (frame.type === 'hello' ||
|
|
132
|
-
frame.type === 'hello-ok' ||
|
|
133
|
-
frame.type === 'hello-error') {
|
|
134
|
-
session.close();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const rec = inflight.get(frame.id);
|
|
138
|
-
if (rec === undefined || rec.mode === 'done') {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (rec.mode === 'streaming-out') {
|
|
142
|
-
handleStreamingOut(frame, rec);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (frame.type === 'result') {
|
|
146
|
-
finish(frame.id, rec, () => {
|
|
147
|
-
if (frame.ok) {
|
|
148
|
-
rec.resolve(frame.output);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
rec.reject(errorFromEnvelope(frame.error));
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (frame.type === 'item') {
|
|
157
|
-
rec.mode = 'streaming-out';
|
|
158
|
-
const queue = createPushQueue();
|
|
159
|
-
rec.output = queue;
|
|
160
|
-
queue.push(frame.output);
|
|
161
|
-
rec.resolve(wrapOutput(frame.id, rec, queue));
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
if (frame.type === 'done') {
|
|
165
|
-
const queue = createPushQueue();
|
|
166
|
-
rec.output = queue;
|
|
167
|
-
queue.end();
|
|
168
|
-
rec.resolve(wrapOutput(frame.id, rec, queue));
|
|
169
|
-
finish(frame.id, rec, () => { });
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
finish(frame.id, rec, () => {
|
|
173
|
-
rec.reject(localFailure('Invalid response'));
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
function waitForReady(signal) {
|
|
177
|
-
if (signal === undefined) {
|
|
178
|
-
return session.ready;
|
|
179
|
-
}
|
|
180
|
-
if (signal.aborted) {
|
|
181
|
-
return Promise.reject(abortedFailure(signal));
|
|
182
|
-
}
|
|
183
|
-
return new Promise((resolve, reject) => {
|
|
184
|
-
const onAbort = () => {
|
|
185
|
-
signal.removeEventListener('abort', onAbort);
|
|
29
|
+
signal.addEventListener('abort', onAbort);
|
|
30
|
+
promise.then((value) => {
|
|
31
|
+
signal.removeEventListener('abort', onAbort);
|
|
32
|
+
if (signal.aborted) {
|
|
186
33
|
reject(abortedFailure(signal));
|
|
187
|
-
};
|
|
188
|
-
signal.addEventListener('abort', onAbort);
|
|
189
|
-
session.ready.then(() => {
|
|
190
|
-
signal.removeEventListener('abort', onAbort);
|
|
191
|
-
if (signal.aborted) {
|
|
192
|
-
reject(abortedFailure(signal));
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
resolve();
|
|
196
|
-
}, (error) => {
|
|
197
|
-
signal.removeEventListener('abort', onAbort);
|
|
198
|
-
if (signal.aborted) {
|
|
199
|
-
reject(abortedFailure(signal));
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
reject(error);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
async function pumpInput(id, rec) {
|
|
207
|
-
const iterator = rec.inputIterator;
|
|
208
|
-
if (iterator === undefined) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
while (rec.sendingInput) {
|
|
213
|
-
const nextValue = await iterator.next();
|
|
214
|
-
const mode = rec.mode;
|
|
215
|
-
if (!rec.sendingInput || mode === 'done') {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if (nextValue.done) {
|
|
219
|
-
rec.sendingInput = false;
|
|
220
|
-
session.send({ type: 'in-done', id });
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const item = { type: 'in-item', id };
|
|
224
|
-
if (nextValue.value !== undefined) {
|
|
225
|
-
item.input = nextValue.value;
|
|
226
|
-
}
|
|
227
|
-
const sent = session.send(item);
|
|
228
|
-
if (!sent.ok) {
|
|
229
|
-
const mode = rec.mode;
|
|
230
|
-
finish(id, rec, () => {
|
|
231
|
-
if (sent.reason !== 'closed') {
|
|
232
|
-
session.send({ type: 'cancel', id });
|
|
233
|
-
}
|
|
234
|
-
const error = sendFailure(sent.reason);
|
|
235
|
-
if (mode === 'pending-first') {
|
|
236
|
-
rec.reject(error);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
rec.output?.fail(error);
|
|
240
|
-
});
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
if (rec.mode === 'done') {
|
|
247
34
|
return;
|
|
248
35
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (mode === 'pending-first') {
|
|
254
|
-
rec.reject(mapped);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
rec.output?.fail(mapped);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async function callInner(path, input, signal) {
|
|
262
|
-
const streamingInput = isAsyncIterable(input);
|
|
263
|
-
await waitForReady(signal);
|
|
264
|
-
if (closed) {
|
|
265
|
-
throw localFailure('Connection closed');
|
|
266
|
-
}
|
|
267
|
-
if (signal?.aborted) {
|
|
268
|
-
throw abortedFailure(signal);
|
|
269
|
-
}
|
|
270
|
-
const id = String(next);
|
|
271
|
-
next += 1;
|
|
272
|
-
return new Promise((resolve, reject) => {
|
|
273
|
-
const rec = {
|
|
274
|
-
resolve,
|
|
275
|
-
reject,
|
|
276
|
-
mode: 'pending-first',
|
|
277
|
-
sendingInput: false,
|
|
278
|
-
};
|
|
279
|
-
if (signal?.aborted) {
|
|
36
|
+
resolve(value);
|
|
37
|
+
}, (error) => {
|
|
38
|
+
signal.removeEventListener('abort', onAbort);
|
|
39
|
+
if (signal.aborted) {
|
|
280
40
|
reject(abortedFailure(signal));
|
|
281
41
|
return;
|
|
282
42
|
}
|
|
283
|
-
|
|
284
|
-
const frame = { type: 'call', id, path };
|
|
285
|
-
if (streamingInput) {
|
|
286
|
-
frame.stream = true;
|
|
287
|
-
}
|
|
288
|
-
else if (input !== undefined) {
|
|
289
|
-
frame.input = input;
|
|
290
|
-
}
|
|
291
|
-
const sent = session.send(frame);
|
|
292
|
-
if (!sent.ok) {
|
|
293
|
-
finish(id, rec, () => {
|
|
294
|
-
rec.reject(sendFailure(sent.reason));
|
|
295
|
-
});
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
if (signal !== undefined) {
|
|
299
|
-
const abortSignal = signal;
|
|
300
|
-
const onAbort = () => {
|
|
301
|
-
const mode = rec.mode;
|
|
302
|
-
finish(id, rec, () => {
|
|
303
|
-
session.send({ type: 'cancel', id });
|
|
304
|
-
const error = abortedFailure(abortSignal);
|
|
305
|
-
if (mode === 'pending-first') {
|
|
306
|
-
rec.reject(error);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
rec.output?.fail(error);
|
|
310
|
-
});
|
|
311
|
-
};
|
|
312
|
-
abortSignal.addEventListener('abort', onAbort);
|
|
313
|
-
rec.unsubAbort = () => {
|
|
314
|
-
abortSignal.removeEventListener('abort', onAbort);
|
|
315
|
-
};
|
|
316
|
-
if (abortSignal.aborted) {
|
|
317
|
-
onAbort();
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
if (streamingInput) {
|
|
322
|
-
rec.sendingInput = true;
|
|
323
|
-
rec.inputIterator = input[Symbol.asyncIterator]();
|
|
324
|
-
void pumpInput(id, rec);
|
|
325
|
-
}
|
|
43
|
+
reject(error);
|
|
326
44
|
});
|
|
327
|
-
}
|
|
328
|
-
return {
|
|
329
|
-
call(path, input, signal) {
|
|
330
|
-
return callInner(path, input, signal);
|
|
331
|
-
},
|
|
332
|
-
close() {
|
|
333
|
-
session.close();
|
|
334
|
-
},
|
|
335
|
-
};
|
|
45
|
+
});
|
|
336
46
|
}
|
|
337
47
|
//# sourceMappingURL=shared.js.map
|
package/dist/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,iBAAiB,EAEjB,YAAY,EAEZ,cAAc,GACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAkB,MAAM,iBAAiB,CAAA;AAwBjE,SAAS,cAAc,CAAC,MAAmB;IACzC,OAAO,MAAM,CAAC,MAAM,KAAK,SAAS;QAChC,CAAC,CAAC,YAAY,CAAC,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC;QAChD,CAAC,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAA;AACrC,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IACE,KAAK,YAAY,KAAK;QACtB,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,QAAQ,IAAI,KAAK,EACjB,CAAC;QACD,OAAO,KAAkB,CAAA;IAC3B,CAAC;IACD,OAAO,KAAK,YAAY,KAAK;QAC3B,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC;QACpC,CAAC,CAAC,YAAY,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;AAChD,CAAC;AAED,SAAS,WAAW,CAAC,MAA2C;IAC9D,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,iBAAiB,CAAC;YACvB,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,WAAW,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@@
|
|
|
1
1
|
import type { Readable, Writable } from 'node:stream';
|
|
2
2
|
import type { Link } from '@ts-pf/client';
|
|
3
|
-
import {
|
|
3
|
+
import type { LinkOptions } from './shared.js';
|
|
4
|
+
/** `DuplexLink` over `createStdioDuplex`. */
|
|
4
5
|
export declare class StdioLink implements Link {
|
|
5
|
-
private readonly
|
|
6
|
+
private readonly link;
|
|
6
7
|
private closed;
|
|
7
8
|
constructor(opts: {
|
|
8
9
|
input: Readable;
|
package/dist/stdio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAQ9C,6CAA6C;AAC7C,qBAAa,SAAU,YAAW,IAAI;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,MAAM,CAAQ;gBAEV,IAAI,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,QAAQ,CAAA;KAAE,GAAG,WAAW;IAUrE,IAAI,CACF,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAI3B,KAAK,IAAI,IAAI;CAOd"}
|
package/dist/stdio.js
CHANGED
|
@@ -1,40 +1,32 @@
|
|
|
1
1
|
import { createStdioDuplex } from '@ts-pf/message/stdio';
|
|
2
|
-
import {
|
|
2
|
+
import { DuplexLink } from './duplex.js';
|
|
3
3
|
// child (handler)
|
|
4
4
|
// new StdioHandler(app).bind({ input: process.stdin, output: process.stdout }, { context })
|
|
5
5
|
// parent (link)
|
|
6
6
|
// const child = spawn(cmd, { stdio: ['pipe', 'pipe', 'inherit'] })
|
|
7
7
|
// new StdioLink({ input: child.stdout, output: child.stdin })
|
|
8
|
+
/** `DuplexLink` over `createStdioDuplex`. */
|
|
8
9
|
export class StdioLink {
|
|
9
|
-
|
|
10
|
+
link;
|
|
10
11
|
closed = false;
|
|
11
12
|
constructor(opts) {
|
|
13
|
+
const { input, output, ...options } = opts;
|
|
12
14
|
const duplexOpts = {};
|
|
13
|
-
if (
|
|
14
|
-
duplexOpts.maxFrameBytes =
|
|
15
|
+
if (options.maxFrameBytes !== undefined) {
|
|
16
|
+
duplexOpts.maxFrameBytes = options.maxFrameBytes;
|
|
15
17
|
}
|
|
16
|
-
const duplex = createStdioDuplex({ input
|
|
17
|
-
|
|
18
|
-
if (opts.meta !== undefined) {
|
|
19
|
-
attach.meta = opts.meta;
|
|
20
|
-
}
|
|
21
|
-
if (opts.maxFrameBytes !== undefined) {
|
|
22
|
-
attach.maxFrameBytes = opts.maxFrameBytes;
|
|
23
|
-
}
|
|
24
|
-
if (opts.helloTimeoutMs !== undefined) {
|
|
25
|
-
attach.helloTimeoutMs = opts.helloTimeoutMs;
|
|
26
|
-
}
|
|
27
|
-
this.attached = attachClient(attach);
|
|
18
|
+
const duplex = createStdioDuplex({ input, output }, duplexOpts);
|
|
19
|
+
this.link = new DuplexLink({ duplex, ...options });
|
|
28
20
|
}
|
|
29
21
|
call(path, input, signal) {
|
|
30
|
-
return this.
|
|
22
|
+
return this.link.call(path, input, signal);
|
|
31
23
|
}
|
|
32
24
|
close() {
|
|
33
25
|
if (this.closed) {
|
|
34
26
|
return;
|
|
35
27
|
}
|
|
36
28
|
this.closed = true;
|
|
37
|
-
this.
|
|
29
|
+
this.link.close();
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
32
|
//# sourceMappingURL=stdio.js.map
|
package/dist/stdio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,kBAAkB;AAClB,4FAA4F;AAC5F,gBAAgB;AAChB,mEAAmE;AACnE,8DAA8D;AAE9D,6CAA6C;AAC7C,MAAM,OAAO,SAAS;IACH,IAAI,CAAY;IACzB,MAAM,GAAG,KAAK,CAAA;IAEtB,YAAY,IAAyD;QACnE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAA;QAC1C,MAAM,UAAU,GAA+B,EAAE,CAAA;QACjD,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACxC,UAAU,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;QAClD,CAAC;QACD,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC,CAAA;QAC/D,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,CACF,IAAc,EACd,KAAc,EACd,MAAoB;QAEpB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAM;QACR,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC;CACF"}
|
package/dist/ws.d.ts
CHANGED
|
@@ -14,9 +14,16 @@ type WsLinkOpts = ({
|
|
|
14
14
|
socket?: never;
|
|
15
15
|
WebSocket?: WebSocketCtor;
|
|
16
16
|
} & LinkOptions);
|
|
17
|
+
/**
|
|
18
|
+
* `DuplexLink` over `createWsDuplex`, started once the socket is open.
|
|
19
|
+
* Calls made before that wait for the connect; `close()` also closes the
|
|
20
|
+
* socket. `backpressure.highWaterMark` is the `bufferedAmount` the socket may
|
|
21
|
+
* hold before an input stream's producer pauses.
|
|
22
|
+
*/
|
|
17
23
|
export declare class WsLink implements Link {
|
|
18
24
|
private readonly socket;
|
|
19
|
-
private
|
|
25
|
+
private readonly highWaterMark;
|
|
26
|
+
private link;
|
|
20
27
|
private readonly connected;
|
|
21
28
|
private closed;
|
|
22
29
|
private settleConnect;
|
|
@@ -28,6 +35,5 @@ export declare class WsLink implements Link {
|
|
|
28
35
|
private start;
|
|
29
36
|
private failConnect;
|
|
30
37
|
private callInner;
|
|
31
|
-
private waitConnected;
|
|
32
38
|
}
|
|
33
39
|
//# sourceMappingURL=ws.d.ts.map
|
package/dist/ws.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EA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