Skip to content

Commit 53ddc0e

Browse files
authored
Properly escape nested module names for globals (#755)
1 parent cde60b6 commit 53ddc0e

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
// Svelte doesn't correctly compile if imports of the generated /modules
1414
// aren't imported as 'import type' in other parts of the generated
1515
// querybuilder, so set this option to ensure we always do that
16-
"@typescript-eslint/consistent-type-imports": "error"
16+
"@typescript-eslint/consistent-type-imports": "error",
17+
"@typescript-eslint/no-namespace": "off"
1718
}
1819
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Client } from "edgedb";
2+
import e, { type $infer } from "./dbschema/edgeql-js";
3+
import { setupTests, tc, teardownTests } from "./setupTeardown";
4+
5+
describe("auth", () => {
6+
let client: Client;
7+
beforeAll(async () => {
8+
const setup = await setupTests();
9+
({ client } = setup);
10+
});
11+
12+
afterAll(async () => {
13+
await teardownTests(client);
14+
}, 10_000);
15+
16+
test("check generated globals", () => {
17+
const clientTokenIdentity = e.select(
18+
e.ext.auth.global.ClientTokenIdentity,
19+
(i) => ({
20+
...i["*"],
21+
})
22+
);
23+
tc.assert<
24+
tc.IsExact<
25+
$infer<typeof clientTokenIdentity>,
26+
{
27+
id: string;
28+
created_at: Date;
29+
modified_at: Date;
30+
issuer: string;
31+
subject: string;
32+
}[]
33+
>
34+
>(true);
35+
});
36+
37+
const clientToken = e.select(e.ext.auth.global.client_token);
38+
tc.assert<tc.IsExact<$infer<typeof clientToken>, string | null>>(true);
39+
});

integration-tests/nightly/dbschema/default.esdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using extension auth;
2+
13
module default {
24
type WithMultiRange {
35
required ranges: multirange<std::int32>;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE MIGRATION m1sxd3hbdfjetkgd5okfnkylxf32szrksxs4wctldele4gbaaleoha
2+
ONTO m1rlwpc5ikrkb7cvylhbcntglvnanm524yb6si5xlcjk6gd2lczugq
3+
{
4+
CREATE EXTENSION pgcrypto VERSION '1.3';
5+
CREATE EXTENSION auth VERSION '1.0';
6+
};

packages/generate/src/edgeql-js/generateGlobals.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export const generateGlobals = ({ dir, globals, types }: GeneratorParams) => {
1515

1616
for (const [mod, gs] of Object.entries(globalsByMod)) {
1717
const code = dir.getModule(mod);
18+
const modName = mod.split("::").join("_");
1819
code.writeln([
1920
dts`declare `,
20-
...frag`const $${mod}__globals`,
21+
...frag`const $${modName}__globals`,
2122
t`: {`,
2223
...gs
2324
.flatMap((g) => {
@@ -53,9 +54,9 @@ export const generateGlobals = ({ dir, globals, types }: GeneratorParams) => {
5354
]);
5455

5556
code.nl();
56-
code.registerRef(`$${mod}__globals`);
57+
code.registerRef(`$${modName}__globals`);
5758
code.addToDefaultExport(
58-
getRef(`$${mod}__globals`, { prefix: "" }),
59+
getRef(`$${modName}__globals`, { prefix: "" }),
5960
"global"
6061
);
6162
}

0 commit comments

Comments
 (0)