fix(compiler): route the generated api object through the real buildApiRequest
Root-cause fix for the fix-round-1 review: the inlined query/body assembly in __wrnexusCallApi was a third, unguarded copy of buildApiRequest's rules. Restore the import of buildApiRequest from @wrnexus/core in the generated module and delete the inline copy. The four api-block-ssr.test.ts tests (and three in compiler.test.ts) that dynamically import a generated module from an OS tmpdir were failing against a stale globally-installed @wrnexus/core (v0.8.8, predates buildApiRequest) because that tmpdir has no node_modules of its own and bare-specifier resolution walked out of the workspace. Fixed at the source: symlink the workspace @wrnexus/core into each tmpdir root before the dynamic import, the same way every in-repo package already resolves it.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
// Generated by scripts/build-editor-compiler.mjs. Do not edit directly.
|
||||
// WRN editor compiler source hash: 03f56cb1555bb66c503f2ec4caf75aa149dd7142637593a07c78d1f1baab8e2b
|
||||
// WRN editor compiler source hash: 843d73711698bc31e874370cb28bf0cb6940d3d4a6c761d00921b5f35806ab98
|
||||
// WRN editor compiler generator hash: a54ca847c758bc98d8e353ad6d70088df31de1820f6cf9d1c3462505f563e6b8
|
||||
// Generated with TypeScript: 6.0.3
|
||||
const __nodeRequire = require;
|
||||
@@ -1691,28 +1691,15 @@ async function __wrnexusCallApi(
|
||||
return await ctx.__wrnexusCallApi(path, method, input);
|
||||
}
|
||||
|
||||
const verb = String(method || "GET").toUpperCase();
|
||||
const values = (input ?? {}) as Record<string, unknown>;
|
||||
const built = __wrnexusBuildApiRequest(path, method, input as Record<string, unknown> | undefined);
|
||||
const url = new URL(built.url, ctx.req.url);
|
||||
const headers = new Headers(ctx.req.headers);
|
||||
let requestPath = path;
|
||||
let body: string | undefined;
|
||||
if (verb === "GET" || verb === "HEAD") {
|
||||
const query: string[] = [];
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (value === undefined || value === null || value === "") continue;
|
||||
query.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`);
|
||||
}
|
||||
if (query.length) requestPath = \`\${path}?\${query.join("&")}\`;
|
||||
} else {
|
||||
body = JSON.stringify(values);
|
||||
headers.set("content-type", "application/json");
|
||||
}
|
||||
const url = new URL(requestPath, ctx.req.url);
|
||||
if (built.contentType) headers.set("content-type", built.contentType);
|
||||
const res = await fetch(
|
||||
new Request(url, {
|
||||
method,
|
||||
headers,
|
||||
...(body === undefined ? {} : { body }),
|
||||
...(built.body === undefined ? {} : { body: built.body }),
|
||||
}),
|
||||
);
|
||||
const type = res.headers.get("content-type") || "";
|
||||
@@ -2203,6 +2190,7 @@ function generateInner(ast) {
|
||||
const needsSsrRuntime = ssrBindings.length > 0 || loops.length > 0 || runtimeStateNames.size > 0;
|
||||
const needsRuntimeHelpers = needsSsrRuntime || hasServerApis;
|
||||
if (needsRuntimeHelpers) {
|
||||
out.push(`import { buildApiRequest as __wrnexusBuildApiRequest } from "@wrnexus/core";`);
|
||||
out.push(ssrRuntimeSource());
|
||||
out.push(`const __wrnexusSsrBindings: __WrnexusSsrBinding[] = ${JSON.stringify(ssrBindings, null, 2)};`);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// WRN editor extension source hash: ae7dab4aff1ce30f0d01fa0b9172651e526408916351862e2644a85c25df03ac
|
||||
// WRN editor extension source hash: 52dfa294ba556cb26807ce112cc6826a690aa4a80721520d0c39bd7cfd8aa33e
|
||||
// WRN editor extension generator hash: 456d1d614e44e5fb1f19b784176c09cf2ade9b64ef73a17934c2698150b62728
|
||||
"use strict";
|
||||
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
||||
|
||||
Reference in New Issue
Block a user