@telorun/http-client 0.1.7 → 0.2.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.
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { Readable } from "stream";
|
|
1
|
+
import { Stream, type ResourceContext, type ResourceInstance } from "@telorun/sdk";
|
|
3
2
|
interface TeloResponse {
|
|
4
3
|
status: number;
|
|
5
4
|
headers: Record<string, string>;
|
|
@@ -24,7 +23,9 @@ declare class HttpRequestResource implements ResourceInstance {
|
|
|
24
23
|
private readonly manifest;
|
|
25
24
|
private readonly ctx;
|
|
26
25
|
constructor(manifest: HttpRequestManifest, ctx: ResourceContext);
|
|
27
|
-
invoke(input: any): Promise<TeloResponse |
|
|
26
|
+
invoke(input: any): Promise<TeloResponse | {
|
|
27
|
+
output: Stream<Uint8Array>;
|
|
28
|
+
}>;
|
|
28
29
|
}
|
|
29
30
|
export declare function register(): void;
|
|
30
31
|
export declare function create(resource: HttpRequestManifest, ctx: ResourceContext): Promise<HttpRequestResource>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Stream } from "@telorun/sdk";
|
|
1
2
|
import { PassThrough } from "stream";
|
|
2
3
|
const MAX_REDIRECTS = 5;
|
|
3
4
|
const DEFAULT_TIMEOUT = 10000;
|
|
@@ -219,7 +220,12 @@ class HttpRequestResource {
|
|
|
219
220
|
throw new Error(`HTTP ${response.status} error from ${fullUrl}`);
|
|
220
221
|
}
|
|
221
222
|
if (m.mode === "stream") {
|
|
222
|
-
|
|
223
|
+
// Wrap the upstream Readable in a Stream so the value's constructor is
|
|
224
|
+
// recognized by CEL and the result fits the streaming-Invocable
|
|
225
|
+
// convention ({output: Stream<...>}). HTTP server consumers pipe through
|
|
226
|
+
// a format-codec encoder (Octet.Encoder for raw bytes) to write to the
|
|
227
|
+
// response.
|
|
228
|
+
return { output: new Stream(response.body) };
|
|
223
229
|
}
|
|
224
230
|
return response;
|
|
225
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Telo HTTP Client module - HTTP client resource kinds for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"src/**"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@telorun/sdk": "0.
|
|
38
|
+
"@telorun/sdk": "0.7.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^20.0.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { Stream, type ResourceContext, type ResourceInstance } from "@telorun/sdk";
|
|
2
2
|
import { PassThrough, Readable } from "stream";
|
|
3
3
|
|
|
4
4
|
const MAX_REDIRECTS = 5;
|
|
@@ -195,7 +195,7 @@ class HttpRequestResource implements ResourceInstance {
|
|
|
195
195
|
private readonly ctx: ResourceContext,
|
|
196
196
|
) {}
|
|
197
197
|
|
|
198
|
-
async invoke(input: any): Promise<TeloResponse |
|
|
198
|
+
async invoke(input: any): Promise<TeloResponse | { output: Stream<Uint8Array> }> {
|
|
199
199
|
const ctx = this.ctx;
|
|
200
200
|
const m = this.manifest;
|
|
201
201
|
|
|
@@ -297,7 +297,12 @@ class HttpRequestResource implements ResourceInstance {
|
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
if (m.mode === "stream") {
|
|
300
|
-
|
|
300
|
+
// Wrap the upstream Readable in a Stream so the value's constructor is
|
|
301
|
+
// recognized by CEL and the result fits the streaming-Invocable
|
|
302
|
+
// convention ({output: Stream<...>}). HTTP server consumers pipe through
|
|
303
|
+
// a format-codec encoder (Octet.Encoder for raw bytes) to write to the
|
|
304
|
+
// response.
|
|
305
|
+
return { output: new Stream(response.body as Readable) };
|
|
301
306
|
}
|
|
302
307
|
|
|
303
308
|
return response;
|