@godspeedai/cognate-protocol-connect-bun 0.1.2 → 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.
- package/package.json +3 -3
- package/src/index.ts +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@godspeedai/cognate-protocol-connect-bun",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Serves the Connect runtime service on Bun.serve with authentication, payload limits, and deadlines; provides a fetch transport.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
".": "./src/index.ts"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@godspeedai/cognate-protocol-connect": "^0.
|
|
26
|
-
"@godspeedai/cognate-runtime-api": "^0.
|
|
25
|
+
"@godspeedai/cognate-protocol-connect": "^0.2.0",
|
|
26
|
+
"@godspeedai/cognate-runtime-api": "^0.2.0",
|
|
27
27
|
"@connectrpc/connect": "2.2.0",
|
|
28
28
|
"@connectrpc/connect-web": "2.2.0"
|
|
29
29
|
},
|
package/src/index.ts
CHANGED
|
@@ -80,7 +80,12 @@ export function serveRuntime(options: ServeOptions): RuntimeServer {
|
|
|
80
80
|
request = new Request(request.url, { method: request.method, headers, body: request.body ?? undefined, duplex: request.body ? "half" : undefined } as RequestInit);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
const response = await connectFetch(request);
|
|
84
|
+
// Bun's fetch caches repeated identical unary POST responses (DEBT-027); the header protects
|
|
85
|
+
// every client — including hand-rolled createConnectTransport calls without a fetch override.
|
|
86
|
+
const headers = new Headers(response.headers);
|
|
87
|
+
headers.set("cache-control", "no-store");
|
|
88
|
+
return new Response(response.body, { status: response.status, headers });
|
|
84
89
|
},
|
|
85
90
|
});
|
|
86
91
|
|
|
@@ -92,9 +97,15 @@ export function serveRuntime(options: ServeOptions): RuntimeServer {
|
|
|
92
97
|
};
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
/** A fetch-based Connect transport usable from Bun and browsers.
|
|
100
|
+
/** A fetch-based Connect transport usable from Bun and browsers.
|
|
101
|
+
*
|
|
102
|
+
* Bun's fetch caches repeated identical unary POST responses (observed on Bun 1.4.0: a client
|
|
103
|
+
* re-reading a projection kept receiving its first response until the cache entry was bypassed;
|
|
104
|
+
* recorded as DEBT-027), so this helper defaults to `cache: "no-store"` — a Bun runtime has no HTTP
|
|
105
|
+
* cache to benefit from anyway. Pass `fetch` explicitly to override. */
|
|
96
106
|
export function connectTransport(baseUrl: string, options?: { readonly useBinaryFormat?: boolean }): Transport {
|
|
97
|
-
|
|
107
|
+
const fetchNoCache = ((input: RequestInfo | URL, init?: RequestInit) => fetch(input, { ...init, cache: "no-store" })) as typeof globalThis.fetch;
|
|
108
|
+
return createConnectTransport({ baseUrl, useBinaryFormat: options?.useBinaryFormat ?? false, fetch: fetchNoCache });
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
/** Test/dev authenticator: `Bearer <tenant>:<principalId>`. Not for production use. */
|