@sproutboat/toolchain 0.10.0 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @sproutboat/toolchain
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 6676ead: `env.BUCKET.put(key, request.body)`, `env.KV.put(key, request.body)` and `fetch(url, { body: request.body })` store and send the request body again. Since 0.19.0, `body` is a `ReadableStream`, and these took its string form. Incoming request bodies are also read as the bytes they are, so `arrayBuffer()`, `blob()`, `body` and KV `put` no longer UTF-8 encode a non-ASCII upload twice. R2 `put` accepts bytes as well.
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutboat/toolchain",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -77,8 +77,11 @@ export const REQUEST_CLASS_SOURCE = String.raw`class Request {
77
77
  if (init == null) return null;
78
78
  if (Request._isStream(init)) return init;
79
79
  if (message._bodyStream == null) {
80
- const bytes = Request._bodyBytes(init);
80
+ const bytes = Request._messageBytes(message, init);
81
81
  message._bodyStream = new globalThis.ReadableStream({ start(c) { if (bytes.length) c.enqueue(bytes); c.close(); } });
82
+ // The value the stream was made from, for the bindings that take a body at once
83
+ // (R2 and KV put, outbound fetch): put(key, request.body) is the Workers idiom.
84
+ message._bodyStream._sbBody = message._bodyLatin1 === true ? bytes : init;
82
85
  }
83
86
  return message._bodyStream;
84
87
  }
@@ -120,7 +123,17 @@ export const REQUEST_CLASS_SOURCE = String.raw`class Request {
120
123
  static _read(message, finish) {
121
124
  const body = Request._consume(message);
122
125
  if (Request._isStream(body)) return Request._streamBytes(body).then(finish);
123
- return finish(Request._bodyBytes(body));
126
+ return finish(Request._messageBytes(message, body));
127
+ }
128
+ // A body the native ingress delivered is its raw bytes, one character each
129
+ // (_bodyLatin1): those bytes, not the string UTF-8 encoded again.
130
+ static _messageBytes(message, body) {
131
+ if (message._bodyLatin1 === true && typeof body == 'string') {
132
+ const out = new Uint8Array(body.length);
133
+ for (let i = 0; i < body.length; i++) out[i] = body.charCodeAt(i) & 255;
134
+ return out;
135
+ }
136
+ return Request._bodyBytes(body);
124
137
  }
125
138
 
126
139
  constructor(input, init = undefined) {
@@ -21,7 +21,7 @@ export const PATCH_SOURCES = [
21
21
  * patch.ts as the module patch.ts is everywhere else. Kept current by fingerprint.test.ts
22
22
  * (UPDATE_FINGERPRINT=1 bun test packages/toolchain/src/fingerprint.test.ts).
23
23
  */
24
- export const RELEASED_FINGERPRINT = "405c8f04fb7d";
24
+ export const RELEASED_FINGERPRINT = "9a717433bb3b";
25
25
 
26
26
  /** The fingerprint of the sources in dir, or null where they are not on disk. */
27
27
  export function sourceFingerprint(dir: string): string | null {