@planqk/planqk-service-sdk 2.1.1 → 2.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.
- package/.gitlab-ci.yml +8 -39
- package/README-node.md +16 -12
- package/README.md +30 -41
- package/dist/sdk/Client.d.ts +10 -4
- package/dist/sdk/Client.js +46 -4
- package/dist/sdk/api/index.d.ts +2 -3
- package/dist/sdk/api/index.js +2 -3
- package/dist/sdk/api/resources/index.d.ts +2 -2
- package/dist/sdk/api/resources/index.js +2 -2
- package/dist/sdk/api/resources/serviceApi/client/Client.d.ts +41 -55
- package/dist/sdk/api/resources/serviceApi/client/Client.js +131 -227
- package/dist/sdk/api/resources/serviceApi/index.d.ts +2 -2
- package/dist/sdk/api/resources/serviceApi/index.js +2 -2
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponse.d.ts +13 -3
- package/dist/sdk/api/resources/serviceApi/types/index.d.ts +1 -4
- package/dist/sdk/api/resources/serviceApi/types/index.js +1 -4
- package/dist/sdk/api/types/ServiceExecution.d.ts +12 -2
- package/dist/sdk/api/types/ServiceExecution.js +12 -0
- package/dist/sdk/api/types/index.d.ts +2 -6
- package/dist/sdk/api/types/index.js +2 -6
- package/dist/sdk/core/auth/BasicAuth.js +3 -3
- package/dist/sdk/core/auth/index.d.ts +2 -2
- package/dist/sdk/core/auth/index.js +4 -4
- package/dist/sdk/core/base64.d.ts +2 -0
- package/dist/sdk/core/base64.js +26 -0
- package/dist/sdk/core/fetcher/APIResponse.d.ts +10 -0
- package/dist/sdk/core/fetcher/BinaryResponse.d.ts +20 -0
- package/dist/sdk/core/fetcher/BinaryResponse.js +17 -0
- package/dist/sdk/core/fetcher/Fetcher.d.ts +5 -4
- package/dist/sdk/core/fetcher/Fetcher.js +41 -22
- package/dist/sdk/core/fetcher/Headers.d.ts +2 -0
- package/dist/sdk/core/fetcher/Headers.js +85 -0
- package/dist/sdk/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/sdk/core/fetcher/HttpResponsePromise.js +94 -0
- package/dist/sdk/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/sdk/core/fetcher/RawResponse.js +44 -0
- package/dist/sdk/core/fetcher/ResponseWithBody.d.ts +4 -0
- package/dist/sdk/core/fetcher/ResponseWithBody.js +6 -0
- package/dist/sdk/core/fetcher/createRequestUrl.d.ts +1 -1
- package/dist/sdk/core/fetcher/createRequestUrl.js +3 -7
- package/dist/sdk/core/fetcher/getErrorResponseBody.d.ts +1 -0
- package/dist/sdk/core/fetcher/getErrorResponseBody.js +32 -0
- package/dist/sdk/core/fetcher/getFetchFn.d.ts +1 -4
- package/dist/sdk/core/fetcher/getFetchFn.js +1 -52
- package/dist/sdk/core/fetcher/getRequestBody.js +2 -1
- package/dist/sdk/core/fetcher/getResponseBody.js +34 -30
- package/dist/sdk/core/fetcher/index.d.ts +9 -5
- package/dist/sdk/core/fetcher/index.js +13 -7
- package/dist/sdk/core/fetcher/makeRequest.js +3 -3
- package/dist/sdk/core/fetcher/requestWithRetries.js +14 -5
- package/dist/sdk/core/headers.d.ts +3 -0
- package/dist/sdk/core/headers.js +29 -0
- package/dist/sdk/core/index.d.ts +5 -3
- package/dist/sdk/core/index.js +28 -3
- package/dist/sdk/core/json.d.ts +15 -0
- package/dist/sdk/core/json.js +24 -0
- package/dist/sdk/core/runtime/index.d.ts +1 -1
- package/dist/sdk/core/runtime/index.js +2 -2
- package/dist/sdk/core/runtime/runtime.d.ts +1 -1
- package/dist/sdk/core/runtime/runtime.js +49 -40
- package/dist/sdk/core/url/index.d.ts +2 -0
- package/dist/sdk/core/url/index.js +7 -0
- package/dist/sdk/core/url/join.d.ts +1 -0
- package/dist/sdk/core/url/join.js +49 -0
- package/dist/sdk/core/url/qs.d.ts +6 -0
- package/dist/sdk/core/url/qs.js +67 -0
- package/dist/sdk/errors/PlanqkServiceApiError.d.ts +4 -1
- package/dist/sdk/errors/PlanqkServiceApiError.js +7 -8
- package/dist/sdk/errors/PlanqkServiceApiTimeoutError.d.ts +1 -1
- package/dist/sdk/errors/PlanqkServiceApiTimeoutError.js +2 -2
- package/dist/sdk/errors/index.d.ts +2 -2
- package/dist/sdk/errors/index.js +4 -4
- package/dist/sdk/index.d.ts +4 -4
- package/dist/sdk/index.js +9 -9
- package/fern/fern.config.json +1 -1
- package/fern/generators.yml +2 -2
- package/fern/openapi/openapi.yml +41 -131
- package/notebooks/python-sdk.ipynb +1 -1
- package/package.json +2 -3
- package/planqk/service/_version.py +1 -1
- package/pyproject.toml +1 -1
- package/src/index.test.ts +29 -16
- package/src/sdk/Client.ts +27 -7
- package/src/sdk/api/index.ts +2 -3
- package/src/sdk/api/resources/index.ts +2 -2
- package/src/sdk/api/resources/serviceApi/client/Client.ts +223 -250
- package/src/sdk/api/resources/serviceApi/index.ts +2 -2
- package/src/sdk/api/resources/serviceApi/types/GetResultResponse.ts +15 -3
- package/src/sdk/api/resources/serviceApi/types/index.ts +1 -4
- package/src/sdk/api/types/ServiceExecution.ts +13 -3
- package/src/sdk/api/types/index.ts +2 -6
- package/src/sdk/core/auth/BasicAuth.ts +3 -3
- package/src/sdk/core/auth/index.ts +2 -2
- package/src/sdk/core/base64.ts +27 -0
- package/src/sdk/core/fetcher/APIResponse.ts +11 -0
- package/src/sdk/core/fetcher/BinaryResponse.ts +36 -0
- package/src/sdk/core/fetcher/Fetcher.ts +46 -26
- package/src/sdk/core/fetcher/Headers.ts +93 -0
- package/src/sdk/core/fetcher/HttpResponsePromise.ts +116 -0
- package/src/sdk/core/fetcher/RawResponse.ts +61 -0
- package/src/sdk/core/fetcher/ResponseWithBody.ts +7 -0
- package/src/sdk/core/fetcher/createRequestUrl.ts +4 -8
- package/src/sdk/core/fetcher/getErrorResponseBody.ts +32 -0
- package/src/sdk/core/fetcher/getFetchFn.ts +2 -24
- package/src/sdk/core/fetcher/getRequestBody.ts +3 -1
- package/src/sdk/core/fetcher/getResponseBody.ts +38 -27
- package/src/sdk/core/fetcher/index.ts +9 -5
- package/src/sdk/core/fetcher/makeRequest.ts +2 -2
- package/src/sdk/core/fetcher/requestWithRetries.ts +18 -6
- package/src/sdk/core/fetcher/signals.ts +1 -1
- package/src/sdk/core/headers.ts +35 -0
- package/src/sdk/core/index.ts +5 -3
- package/src/sdk/core/json.ts +27 -0
- package/src/sdk/core/runtime/index.ts +1 -1
- package/src/sdk/core/runtime/runtime.ts +60 -53
- package/src/sdk/core/url/index.ts +2 -0
- package/src/sdk/core/url/join.ts +55 -0
- package/src/sdk/core/url/qs.ts +74 -0
- package/src/sdk/errors/PlanqkServiceApiError.ts +21 -11
- package/src/sdk/errors/PlanqkServiceApiTimeoutError.ts +2 -2
- package/src/sdk/errors/index.ts +2 -2
- package/src/sdk/index.ts +4 -4
- package/dist/sdk/api/errors/BadRequestError.d.ts +0 -7
- package/dist/sdk/api/errors/BadRequestError.js +0 -51
- package/dist/sdk/api/errors/ForbiddenError.d.ts +0 -7
- package/dist/sdk/api/errors/ForbiddenError.js +0 -51
- package/dist/sdk/api/errors/InternalServerError.d.ts +0 -7
- package/dist/sdk/api/errors/InternalServerError.js +0 -51
- package/dist/sdk/api/errors/NotFoundError.d.ts +0 -7
- package/dist/sdk/api/errors/NotFoundError.js +0 -51
- package/dist/sdk/api/errors/UnauthorizedError.d.ts +0 -7
- package/dist/sdk/api/errors/UnauthorizedError.js +0 -51
- package/dist/sdk/api/errors/index.d.ts +0 -5
- package/dist/sdk/api/errors/index.js +0 -21
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponseEmbedded.d.ts +0 -7
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponseEmbedded.js +0 -5
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponseLinks.d.ts +0 -7
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponseLinks.js +0 -5
- package/dist/sdk/api/resources/serviceApi/types/HealthCheckResponse.d.ts +0 -7
- package/dist/sdk/api/resources/serviceApi/types/HealthCheckResponse.js +0 -5
- package/dist/sdk/api/types/InputData.d.ts +0 -4
- package/dist/sdk/api/types/InputData.js +0 -5
- package/dist/sdk/api/types/InputDataRef.d.ts +0 -8
- package/dist/sdk/api/types/InputDataRef.js +0 -5
- package/dist/sdk/api/types/InputParams.d.ts +0 -4
- package/dist/sdk/api/types/InputParams.js +0 -5
- package/dist/sdk/api/types/ServiceExecutionStatus.d.ts +0 -12
- package/dist/sdk/api/types/ServiceExecutionStatus.js +0 -14
- package/dist/sdk/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +0 -30
- package/dist/sdk/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +0 -232
- package/dist/sdk/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +0 -21
- package/dist/sdk/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +0 -91
- package/dist/sdk/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +0 -31
- package/dist/sdk/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +0 -214
- package/dist/sdk/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +0 -18
- package/dist/sdk/core/fetcher/stream-wrappers/chooseStreamWrapper.js +0 -48
- package/src/sdk/api/errors/BadRequestError.ts +0 -16
- package/src/sdk/api/errors/ForbiddenError.ts +0 -16
- package/src/sdk/api/errors/InternalServerError.ts +0 -16
- package/src/sdk/api/errors/NotFoundError.ts +0 -16
- package/src/sdk/api/errors/UnauthorizedError.ts +0 -16
- package/src/sdk/api/errors/index.ts +0 -5
- package/src/sdk/api/resources/serviceApi/types/GetResultResponseEmbedded.ts +0 -9
- package/src/sdk/api/resources/serviceApi/types/GetResultResponseLinks.ts +0 -9
- package/src/sdk/api/resources/serviceApi/types/HealthCheckResponse.ts +0 -8
- package/src/sdk/api/types/InputData.ts +0 -5
- package/src/sdk/api/types/InputDataRef.ts +0 -9
- package/src/sdk/api/types/InputParams.ts +0 -5
- package/src/sdk/api/types/ServiceExecutionStatus.ts +0 -14
- package/src/sdk/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts +0 -252
- package/src/sdk/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts +0 -106
- package/src/sdk/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts +0 -239
- package/src/sdk/core/fetcher/stream-wrappers/chooseStreamWrapper.ts +0 -33
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as errors from "../../errors/index";
|
|
6
|
-
|
|
7
|
-
export class InternalServerError extends errors.PlanqkServiceApiError {
|
|
8
|
-
constructor(body?: any) {
|
|
9
|
-
super({
|
|
10
|
-
message: "InternalServerError",
|
|
11
|
-
statusCode: 500,
|
|
12
|
-
body: body,
|
|
13
|
-
});
|
|
14
|
-
Object.setPrototypeOf(this, InternalServerError.prototype);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as errors from "../../errors/index";
|
|
6
|
-
|
|
7
|
-
export class NotFoundError extends errors.PlanqkServiceApiError {
|
|
8
|
-
constructor(body?: any) {
|
|
9
|
-
super({
|
|
10
|
-
message: "NotFoundError",
|
|
11
|
-
statusCode: 404,
|
|
12
|
-
body: body,
|
|
13
|
-
});
|
|
14
|
-
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as errors from "../../errors/index";
|
|
6
|
-
|
|
7
|
-
export class UnauthorizedError extends errors.PlanqkServiceApiError {
|
|
8
|
-
constructor(body?: any) {
|
|
9
|
-
super({
|
|
10
|
-
message: "UnauthorizedError",
|
|
11
|
-
statusCode: 401,
|
|
12
|
-
body: body,
|
|
13
|
-
});
|
|
14
|
-
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export type ServiceExecutionStatus = "UNKNOWN" | "PENDING" | "RUNNING" | "SUCCEEDED" | "CANCELLED" | "FAILED";
|
|
6
|
-
|
|
7
|
-
export const ServiceExecutionStatus = {
|
|
8
|
-
Unknown: "UNKNOWN",
|
|
9
|
-
Pending: "PENDING",
|
|
10
|
-
Running: "RUNNING",
|
|
11
|
-
Succeeded: "SUCCEEDED",
|
|
12
|
-
Cancelled: "CANCELLED",
|
|
13
|
-
Failed: "FAILED",
|
|
14
|
-
} as const;
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import type { Writable } from "stream";
|
|
2
|
-
import { EventCallback, StreamWrapper } from "./chooseStreamWrapper";
|
|
3
|
-
|
|
4
|
-
export class Node18UniversalStreamWrapper<ReadFormat extends Uint8Array | Uint16Array | Uint32Array>
|
|
5
|
-
implements
|
|
6
|
-
StreamWrapper<Node18UniversalStreamWrapper<ReadFormat> | Writable | WritableStream<ReadFormat>, ReadFormat>
|
|
7
|
-
{
|
|
8
|
-
private readableStream: ReadableStream<ReadFormat>;
|
|
9
|
-
private reader: ReadableStreamDefaultReader<ReadFormat>;
|
|
10
|
-
private events: Record<string, EventCallback[] | undefined>;
|
|
11
|
-
private paused: boolean;
|
|
12
|
-
private resumeCallback: ((value?: unknown) => void) | null;
|
|
13
|
-
private encoding: string | null;
|
|
14
|
-
|
|
15
|
-
constructor(readableStream: ReadableStream<ReadFormat>) {
|
|
16
|
-
this.readableStream = readableStream;
|
|
17
|
-
this.reader = this.readableStream.getReader();
|
|
18
|
-
this.events = {
|
|
19
|
-
data: [],
|
|
20
|
-
end: [],
|
|
21
|
-
error: [],
|
|
22
|
-
readable: [],
|
|
23
|
-
close: [],
|
|
24
|
-
pause: [],
|
|
25
|
-
resume: [],
|
|
26
|
-
};
|
|
27
|
-
this.paused = false;
|
|
28
|
-
this.resumeCallback = null;
|
|
29
|
-
this.encoding = null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public on(event: string, callback: EventCallback): void {
|
|
33
|
-
this.events[event]?.push(callback);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public off(event: string, callback: EventCallback): void {
|
|
37
|
-
this.events[event] = this.events[event]?.filter((cb) => cb !== callback);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public pipe(
|
|
41
|
-
dest: Node18UniversalStreamWrapper<ReadFormat> | Writable | WritableStream<ReadFormat>
|
|
42
|
-
): Node18UniversalStreamWrapper<ReadFormat> | Writable | WritableStream<ReadFormat> {
|
|
43
|
-
this.on("data", async (chunk) => {
|
|
44
|
-
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
45
|
-
dest._write(chunk);
|
|
46
|
-
} else if (dest instanceof WritableStream) {
|
|
47
|
-
const writer = dest.getWriter();
|
|
48
|
-
writer.write(chunk).then(() => writer.releaseLock());
|
|
49
|
-
} else {
|
|
50
|
-
dest.write(chunk);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
this.on("end", async () => {
|
|
55
|
-
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
56
|
-
dest._end();
|
|
57
|
-
} else if (dest instanceof WritableStream) {
|
|
58
|
-
const writer = dest.getWriter();
|
|
59
|
-
writer.close();
|
|
60
|
-
} else {
|
|
61
|
-
dest.end();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
this.on("error", async (error) => {
|
|
66
|
-
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
67
|
-
dest._error(error);
|
|
68
|
-
} else if (dest instanceof WritableStream) {
|
|
69
|
-
const writer = dest.getWriter();
|
|
70
|
-
writer.abort(error);
|
|
71
|
-
} else {
|
|
72
|
-
dest.destroy(error);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
this._startReading();
|
|
77
|
-
|
|
78
|
-
return dest;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public pipeTo(
|
|
82
|
-
dest: Node18UniversalStreamWrapper<ReadFormat> | Writable | WritableStream<ReadFormat>
|
|
83
|
-
): Node18UniversalStreamWrapper<ReadFormat> | Writable | WritableStream<ReadFormat> {
|
|
84
|
-
return this.pipe(dest);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public unpipe(dest: Node18UniversalStreamWrapper<ReadFormat> | Writable | WritableStream<ReadFormat>): void {
|
|
88
|
-
this.off("data", async (chunk) => {
|
|
89
|
-
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
90
|
-
dest._write(chunk);
|
|
91
|
-
} else if (dest instanceof WritableStream) {
|
|
92
|
-
const writer = dest.getWriter();
|
|
93
|
-
writer.write(chunk).then(() => writer.releaseLock());
|
|
94
|
-
} else {
|
|
95
|
-
dest.write(chunk);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
this.off("end", async () => {
|
|
100
|
-
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
101
|
-
dest._end();
|
|
102
|
-
} else if (dest instanceof WritableStream) {
|
|
103
|
-
const writer = dest.getWriter();
|
|
104
|
-
writer.close();
|
|
105
|
-
} else {
|
|
106
|
-
dest.end();
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
this.off("error", async (error) => {
|
|
111
|
-
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
112
|
-
dest._error(error);
|
|
113
|
-
} else if (dest instanceof WritableStream) {
|
|
114
|
-
const writer = dest.getWriter();
|
|
115
|
-
writer.abort(error);
|
|
116
|
-
} else {
|
|
117
|
-
dest.destroy(error);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public destroy(error?: Error): void {
|
|
123
|
-
this.reader
|
|
124
|
-
.cancel(error)
|
|
125
|
-
.then(() => {
|
|
126
|
-
this._emit("close");
|
|
127
|
-
})
|
|
128
|
-
.catch((err) => {
|
|
129
|
-
this._emit("error", err);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public pause(): void {
|
|
134
|
-
this.paused = true;
|
|
135
|
-
this._emit("pause");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public resume(): void {
|
|
139
|
-
if (this.paused) {
|
|
140
|
-
this.paused = false;
|
|
141
|
-
this._emit("resume");
|
|
142
|
-
if (this.resumeCallback) {
|
|
143
|
-
this.resumeCallback();
|
|
144
|
-
this.resumeCallback = null;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public get isPaused(): boolean {
|
|
150
|
-
return this.paused;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public async read(): Promise<ReadFormat | undefined> {
|
|
154
|
-
if (this.paused) {
|
|
155
|
-
await new Promise((resolve) => {
|
|
156
|
-
this.resumeCallback = resolve;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
const { done, value } = await this.reader.read();
|
|
160
|
-
|
|
161
|
-
if (done) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
return value;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public setEncoding(encoding: string): void {
|
|
168
|
-
this.encoding = encoding;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public async text(): Promise<string> {
|
|
172
|
-
const chunks: ReadFormat[] = [];
|
|
173
|
-
|
|
174
|
-
while (true) {
|
|
175
|
-
const { done, value } = await this.reader.read();
|
|
176
|
-
if (done) break;
|
|
177
|
-
if (value) chunks.push(value);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
181
|
-
return decoder.decode(await new Blob(chunks).arrayBuffer());
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
public async json<T>(): Promise<T> {
|
|
185
|
-
const text = await this.text();
|
|
186
|
-
return JSON.parse(text);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
private _write(chunk: ReadFormat): void {
|
|
190
|
-
this._emit("data", chunk);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private _end(): void {
|
|
194
|
-
this._emit("end");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
private _error(error: any): void {
|
|
198
|
-
this._emit("error", error);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private _emit(event: string, data?: any): void {
|
|
202
|
-
if (this.events[event]) {
|
|
203
|
-
for (const callback of this.events[event] || []) {
|
|
204
|
-
callback(data);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private async _startReading(): Promise<void> {
|
|
210
|
-
try {
|
|
211
|
-
this._emit("readable");
|
|
212
|
-
while (true) {
|
|
213
|
-
if (this.paused) {
|
|
214
|
-
await new Promise((resolve) => {
|
|
215
|
-
this.resumeCallback = resolve;
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
const { done, value } = await this.reader.read();
|
|
219
|
-
if (done) {
|
|
220
|
-
this._emit("end");
|
|
221
|
-
this._emit("close");
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
if (value) {
|
|
225
|
-
this._emit("data", value);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
} catch (error) {
|
|
229
|
-
this._emit("error", error);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<ReadFormat> {
|
|
234
|
-
return {
|
|
235
|
-
next: async () => {
|
|
236
|
-
if (this.paused) {
|
|
237
|
-
await new Promise((resolve) => {
|
|
238
|
-
this.resumeCallback = resolve;
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
const { done, value } = await this.reader.read();
|
|
242
|
-
if (done) {
|
|
243
|
-
return { done: true, value: undefined };
|
|
244
|
-
}
|
|
245
|
-
return { done: false, value };
|
|
246
|
-
},
|
|
247
|
-
[Symbol.asyncIterator]() {
|
|
248
|
-
return this;
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { Readable, Writable } from "stream";
|
|
2
|
-
import { EventCallback, StreamWrapper } from "./chooseStreamWrapper";
|
|
3
|
-
|
|
4
|
-
export class NodePre18StreamWrapper implements StreamWrapper<Writable, Buffer> {
|
|
5
|
-
private readableStream: Readable;
|
|
6
|
-
private encoding: string | undefined;
|
|
7
|
-
|
|
8
|
-
constructor(readableStream: Readable) {
|
|
9
|
-
this.readableStream = readableStream;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public on(event: string, callback: EventCallback): void {
|
|
13
|
-
this.readableStream.on(event, callback);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public off(event: string, callback: EventCallback): void {
|
|
17
|
-
this.readableStream.off(event, callback);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public pipe(dest: Writable): Writable {
|
|
21
|
-
this.readableStream.pipe(dest);
|
|
22
|
-
return dest;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public pipeTo(dest: Writable): Writable {
|
|
26
|
-
return this.pipe(dest);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public unpipe(dest?: Writable): void {
|
|
30
|
-
if (dest) {
|
|
31
|
-
this.readableStream.unpipe(dest);
|
|
32
|
-
} else {
|
|
33
|
-
this.readableStream.unpipe();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public destroy(error?: Error): void {
|
|
38
|
-
this.readableStream.destroy(error);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public pause(): void {
|
|
42
|
-
this.readableStream.pause();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public resume(): void {
|
|
46
|
-
this.readableStream.resume();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public get isPaused(): boolean {
|
|
50
|
-
return this.readableStream.isPaused();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async read(): Promise<Buffer | undefined> {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
const chunk = this.readableStream.read();
|
|
56
|
-
if (chunk) {
|
|
57
|
-
resolve(chunk);
|
|
58
|
-
} else {
|
|
59
|
-
this.readableStream.once("readable", () => {
|
|
60
|
-
const chunk = this.readableStream.read();
|
|
61
|
-
resolve(chunk);
|
|
62
|
-
});
|
|
63
|
-
this.readableStream.once("error", reject);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public setEncoding(encoding?: string): void {
|
|
69
|
-
this.readableStream.setEncoding(encoding as BufferEncoding);
|
|
70
|
-
this.encoding = encoding;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public async text(): Promise<string> {
|
|
74
|
-
const chunks: Uint8Array[] = [];
|
|
75
|
-
const encoder = new TextEncoder();
|
|
76
|
-
this.readableStream.setEncoding((this.encoding || "utf-8") as BufferEncoding);
|
|
77
|
-
|
|
78
|
-
for await (const chunk of this.readableStream) {
|
|
79
|
-
chunks.push(encoder.encode(chunk));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
83
|
-
return decoder.decode(Buffer.concat(chunks));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public async json<T>(): Promise<T> {
|
|
87
|
-
const text = await this.text();
|
|
88
|
-
return JSON.parse(text);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public [Symbol.asyncIterator](): AsyncIterableIterator<Buffer> {
|
|
92
|
-
const readableStream = this.readableStream;
|
|
93
|
-
const iterator = readableStream[Symbol.asyncIterator]();
|
|
94
|
-
|
|
95
|
-
// Create and return an async iterator that yields buffers
|
|
96
|
-
return {
|
|
97
|
-
async next(): Promise<IteratorResult<Buffer>> {
|
|
98
|
-
const { value, done } = await iterator.next();
|
|
99
|
-
return { value: value as Buffer, done };
|
|
100
|
-
},
|
|
101
|
-
[Symbol.asyncIterator]() {
|
|
102
|
-
return this;
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|