@apifuse/provider-sdk 2.1.0-beta.15 → 2.1.0-beta.17
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/CHANGELOG.md +12 -0
- package/dist/cli/create.js +0 -1
- package/dist/cli/templates/provider/README.md.tpl +1 -0
- package/dist/runtime/http.js +4 -1
- package/dist/testing/run.js +5 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/cli/create.ts +0 -1
- package/src/cli/templates/provider/README.md.tpl +1 -0
- package/src/runtime/http.ts +8 -1
- package/src/testing/run.ts +9 -1
- package/src/types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @apifuse/provider-sdk Changelog
|
|
2
2
|
|
|
3
|
+
## 2.1.0-beta.17
|
|
4
|
+
|
|
5
|
+
- Release candidate for main commit c4466ffc8a30cb99740b50687a62b92cec9ba10e.
|
|
6
|
+
|
|
7
|
+
## 2.1.0-beta.16
|
|
8
|
+
|
|
9
|
+
- Release candidate for main commit c0d8a1c4be519e1c1abc59e0304efc64f371634d.
|
|
10
|
+
|
|
11
|
+
## Unreleased
|
|
12
|
+
|
|
13
|
+
- Add `arrayBuffer()` and `bytes()` to `HttpResponse` so `ctx.http` consumers can read binary-safe upstream bodies; internal response handling is now byte-first.
|
|
14
|
+
|
|
3
15
|
## 2.1.0-beta.15
|
|
4
16
|
|
|
5
17
|
- Release candidate for main commit 4f51232d87828082f117dcc9f0c257a46f37c040.
|
package/dist/cli/create.js
CHANGED
|
@@ -461,7 +461,6 @@ function renderPackageJson(input) {
|
|
|
461
461
|
"submit-check": "apifuse submit-check . --markdown submission-report.md",
|
|
462
462
|
test: "apifuse test .",
|
|
463
463
|
record: "apifuse record .",
|
|
464
|
-
"perf:sample": "apifuse perf . --operation ping --runs 3",
|
|
465
464
|
start: "bun start.ts",
|
|
466
465
|
},
|
|
467
466
|
dependencies: {
|
package/dist/runtime/http.js
CHANGED
|
@@ -396,7 +396,8 @@ function toHttpTransportError(error) {
|
|
|
396
396
|
}
|
|
397
397
|
async function toNativeHttpResponse(response) {
|
|
398
398
|
const headers = Object.fromEntries(response.headers.entries());
|
|
399
|
-
const
|
|
399
|
+
const bodyBytes = new Uint8Array(await response.arrayBuffer());
|
|
400
|
+
const rawText = new TextDecoder().decode(bodyBytes);
|
|
400
401
|
const data = parseHttpData(rawText, headers);
|
|
401
402
|
return {
|
|
402
403
|
data,
|
|
@@ -412,6 +413,8 @@ async function toNativeHttpResponse(response) {
|
|
|
412
413
|
ok: response.status >= 200 && response.status < 300,
|
|
413
414
|
status: response.status,
|
|
414
415
|
text: async () => rawText,
|
|
416
|
+
arrayBuffer: async () => bodyBytes.buffer.slice(bodyBytes.byteOffset, bodyBytes.byteOffset + bodyBytes.byteLength),
|
|
417
|
+
bytes: async () => bodyBytes.slice(0),
|
|
415
418
|
};
|
|
416
419
|
}
|
|
417
420
|
async function drainNativeResponseBody(response) {
|
package/dist/testing/run.js
CHANGED
|
@@ -68,13 +68,17 @@ function inferFixtureDir(providerId) {
|
|
|
68
68
|
return `providers/${providerId}/__fixtures__`;
|
|
69
69
|
}
|
|
70
70
|
function jsonResponse(data) {
|
|
71
|
+
const body = JSON.stringify(data);
|
|
72
|
+
const bodyBytes = new TextEncoder().encode(body);
|
|
71
73
|
return {
|
|
72
74
|
status: 200,
|
|
73
75
|
ok: true,
|
|
74
76
|
headers: {},
|
|
75
77
|
data,
|
|
76
78
|
json: async () => JSON.parse(JSON.stringify(data)),
|
|
77
|
-
text: async () =>
|
|
79
|
+
text: async () => body,
|
|
80
|
+
arrayBuffer: async () => bodyBytes.buffer.slice(bodyBytes.byteOffset, bodyBytes.byteOffset + bodyBytes.byteLength),
|
|
81
|
+
bytes: async () => bodyBytes.slice(0),
|
|
78
82
|
};
|
|
79
83
|
}
|
|
80
84
|
function unsupported(name) {
|
package/dist/types.d.ts
CHANGED
|
@@ -917,6 +917,8 @@ export interface HttpResponse<T = unknown> {
|
|
|
917
917
|
data: T;
|
|
918
918
|
json<U = T>(): Promise<U>;
|
|
919
919
|
text(): Promise<string>;
|
|
920
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
921
|
+
bytes(): Promise<Uint8Array>;
|
|
920
922
|
}
|
|
921
923
|
export interface HttpStreamResponse {
|
|
922
924
|
status: number;
|
package/package.json
CHANGED
package/src/cli/create.ts
CHANGED
|
@@ -629,7 +629,6 @@ function renderPackageJson(input: {
|
|
|
629
629
|
"apifuse submit-check . --markdown submission-report.md",
|
|
630
630
|
test: "apifuse test .",
|
|
631
631
|
record: "apifuse record .",
|
|
632
|
-
"perf:sample": "apifuse perf . --operation ping --runs 3",
|
|
633
632
|
start: "bun start.ts",
|
|
634
633
|
},
|
|
635
634
|
dependencies: {
|
package/src/runtime/http.ts
CHANGED
|
@@ -582,7 +582,8 @@ function toHttpTransportError(error: unknown): TransportError {
|
|
|
582
582
|
|
|
583
583
|
async function toNativeHttpResponse(response: Response): Promise<HttpResponse> {
|
|
584
584
|
const headers = Object.fromEntries(response.headers.entries());
|
|
585
|
-
const
|
|
585
|
+
const bodyBytes = new Uint8Array(await response.arrayBuffer());
|
|
586
|
+
const rawText = new TextDecoder().decode(bodyBytes);
|
|
586
587
|
const data = parseHttpData(rawText, headers);
|
|
587
588
|
|
|
588
589
|
return {
|
|
@@ -602,6 +603,12 @@ async function toNativeHttpResponse(response: Response): Promise<HttpResponse> {
|
|
|
602
603
|
ok: response.status >= 200 && response.status < 300,
|
|
603
604
|
status: response.status,
|
|
604
605
|
text: async () => rawText,
|
|
606
|
+
arrayBuffer: async () =>
|
|
607
|
+
bodyBytes.buffer.slice(
|
|
608
|
+
bodyBytes.byteOffset,
|
|
609
|
+
bodyBytes.byteOffset + bodyBytes.byteLength,
|
|
610
|
+
),
|
|
611
|
+
bytes: async () => bodyBytes.slice(0),
|
|
605
612
|
};
|
|
606
613
|
}
|
|
607
614
|
|
package/src/testing/run.ts
CHANGED
|
@@ -128,13 +128,21 @@ function inferFixtureDir(providerId: string): string {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
function jsonResponse(data: unknown): HttpResponse {
|
|
131
|
+
const body = JSON.stringify(data);
|
|
132
|
+
const bodyBytes = new TextEncoder().encode(body);
|
|
131
133
|
return {
|
|
132
134
|
status: 200,
|
|
133
135
|
ok: true,
|
|
134
136
|
headers: {},
|
|
135
137
|
data,
|
|
136
138
|
json: async <_T = unknown>() => JSON.parse(JSON.stringify(data)),
|
|
137
|
-
text: async () =>
|
|
139
|
+
text: async () => body,
|
|
140
|
+
arrayBuffer: async () =>
|
|
141
|
+
bodyBytes.buffer.slice(
|
|
142
|
+
bodyBytes.byteOffset,
|
|
143
|
+
bodyBytes.byteOffset + bodyBytes.byteLength,
|
|
144
|
+
),
|
|
145
|
+
bytes: async () => bodyBytes.slice(0),
|
|
138
146
|
};
|
|
139
147
|
}
|
|
140
148
|
|
package/src/types.ts
CHANGED
|
@@ -1102,6 +1102,8 @@ export interface HttpResponse<T = unknown> {
|
|
|
1102
1102
|
data: T;
|
|
1103
1103
|
json<U = T>(): Promise<U>;
|
|
1104
1104
|
text(): Promise<string>;
|
|
1105
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1106
|
+
bytes(): Promise<Uint8Array>;
|
|
1105
1107
|
}
|
|
1106
1108
|
|
|
1107
1109
|
export interface HttpStreamResponse {
|