mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(javascript): recover RPC link URLs declared with template literals (#2963)
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
644cb8243d
commit
bba3a3f0d9
3 files changed
+24
-4
No files matched your search
@@ -629,7 +629,11 @@ export const semanticFinalObjectStringProperty = (
|
||||
key: string,
|
||||
): string | undefined => {
|
||||
const value = semanticFinalObjectProperty(node, key);
|
||||
return t.isStringLiteral(value) ? value.value : undefined;
|
||||
if (value === undefined) return undefined;
|
||||
const literal = readExactJavaScriptLiteral(value);
|
||||
return literal.found && typeof literal.value === "string"
|
||||
? literal.value
|
||||
: undefined;
|
||||
};
|
||||
|
||||
/** Read exact consumed object-pattern keys, leaving dynamic keys unknown. */
|
||||
|
||||
@@ -35,6 +35,9 @@ describe("RPC object property ownership", () => {
|
||||
['url: "/trpc/live", [0x1n]: {}', "/trpc/live"],
|
||||
['url: "/trpc/live", [0b1n]: {}', "/trpc/live"],
|
||||
['url: "/trpc/live", [-1n]: {}', "/trpc/live"],
|
||||
["url: `/trpc/\\u006cive`", "/trpc/live"],
|
||||
['url: "/trpc/old", url: `/trpc/live`', "/trpc/live"],
|
||||
['url: "/trpc/old", url: `/trpc/${runtimeUrl}`', null],
|
||||
] as const)(
|
||||
"reads only the final known link URL from {%s}",
|
||||
(options, value) => {
|
||||
@@ -48,6 +51,11 @@ describe("RPC object property ownership", () => {
|
||||
|
||||
it.each([
|
||||
['operation: "mutation"', "Old", "graphql:mutation"],
|
||||
[
|
||||
"kind: `OperationDefinition`, operation: `mutation`, name: { kind: `Name`, value: `Current` }",
|
||||
"Current",
|
||||
"graphql:mutation",
|
||||
],
|
||||
['name: { kind: "Name", value: "Current" }', "Current", "graphql:query"],
|
||||
['kind: "FragmentDefinition"', null, null],
|
||||
["name: runtimeName", null, null],
|
||||
@@ -317,7 +325,7 @@ describe("tRPC binding identity and bundled syntax", () => {
|
||||
c.users.query();
|
||||
const p = (t.createTRPCProxyClient as any)({});
|
||||
p.posts.query();
|
||||
(0, t.httpLink)({ url: "/api/other" });
|
||||
(0, t.httpLink)({ url: \`/api/other\` });
|
||||
`),
|
||||
).toEqual([
|
||||
{
|
||||
|
||||
@@ -120,6 +120,7 @@ cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
httpBatchLink({ url: "/trpc/spread-old", ...options }),
|
||||
httpBatchLink({ url: "/trpc/computed-old", [key]: options.url }),
|
||||
httpBatchLink({ ...options, url: "/trpc/final", headers: {} }),
|
||||
httpBatchLink({ url: \`/trpc/template\` }),
|
||||
];
|
||||
const doc = {
|
||||
kind: "OperationDefinition", operation: "query", operation: "mutation",
|
||||
@@ -131,7 +132,13 @@ cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
});
|
||||
// This control checks JavaScript object semantics, not a live tRPC client.
|
||||
expect(await runNodeJsonControl(root, "entry.mjs")).toEqual([
|
||||
["/trpc/live", "/trpc/runtime", "/trpc/runtime", "/trpc/final"],
|
||||
[
|
||||
"/trpc/live",
|
||||
"/trpc/runtime",
|
||||
"/trpc/runtime",
|
||||
"/trpc/final",
|
||||
"/trpc/template",
|
||||
],
|
||||
"mutation",
|
||||
"Current",
|
||||
]);
|
||||
@@ -147,9 +154,10 @@ cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
expect.arrayContaining([
|
||||
["/trpc/live", "trpc:link:httpBatchLink"],
|
||||
["/trpc/final", "trpc:link:httpBatchLink"],
|
||||
["/trpc/template", "trpc:link:httpBatchLink"],
|
||||
["Current", "graphql:mutation"],
|
||||
]),
|
||||
);
|
||||
expect(endpoints).toHaveLength(3);
|
||||
expect(endpoints).toHaveLength(4);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user