@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 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.
@@ -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: {
@@ -9,6 +9,7 @@ bun run dev
9
9
  bun run check
10
10
  bun run test
11
11
  bun run submit-check
12
+ bunx apifuse perf . --operation <operation-id> --runs 3
12
13
  ```
13
14
 
14
15
 
@@ -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 rawText = await response.text();
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) {
@@ -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 () => JSON.stringify(data),
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.1.0-beta.15",
2
+ "version": "2.1.0-beta.17",
3
3
  "name": "@apifuse/provider-sdk",
4
4
  "private": false,
5
5
  "type": "module",
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: {
@@ -9,6 +9,7 @@ bun run dev
9
9
  bun run check
10
10
  bun run test
11
11
  bun run submit-check
12
+ bunx apifuse perf . --operation <operation-id> --runs 3
12
13
  ```
13
14
 
14
15
 
@@ -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 rawText = await response.text();
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
 
@@ -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 () => JSON.stringify(data),
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 {