Skip to content

Commit

Permalink
Properly escape nested module names for globals (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Oct 31, 2023
1 parent cde60b6 commit 53ddc0e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
// Svelte doesn't correctly compile if imports of the generated /modules
// aren't imported as 'import type' in other parts of the generated
// querybuilder, so set this option to ensure we always do that
"@typescript-eslint/consistent-type-imports": "error"
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-namespace": "off"
}
};
39 changes: 39 additions & 0 deletions integration-tests/nightly/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { Client } from "edgedb";
import e, { type $infer } from "./dbschema/edgeql-js";
import { setupTests, tc, teardownTests } from "./setupTeardown";

describe("auth", () => {
let client: Client;
beforeAll(async () => {
const setup = await setupTests();
({ client } = setup);
});

afterAll(async () => {
await teardownTests(client);
}, 10_000);

test("check generated globals", () => {
const clientTokenIdentity = e.select(
e.ext.auth.global.ClientTokenIdentity,
(i) => ({
...i["*"],
})
);
tc.assert<
tc.IsExact<
$infer<typeof clientTokenIdentity>,
{
id: string;
created_at: Date;
modified_at: Date;
issuer: string;
subject: string;
}[]
>
>(true);
});

const clientToken = e.select(e.ext.auth.global.client_token);
tc.assert<tc.IsExact<$infer<typeof clientToken>, string | null>>(true);
});
2 changes: 2 additions & 0 deletions integration-tests/nightly/dbschema/default.esdl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using extension auth;

module default {
type WithMultiRange {
required ranges: multirange<std::int32>;
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/nightly/dbschema/migrations/00002.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE MIGRATION m1sxd3hbdfjetkgd5okfnkylxf32szrksxs4wctldele4gbaaleoha
ONTO m1rlwpc5ikrkb7cvylhbcntglvnanm524yb6si5xlcjk6gd2lczugq
{
CREATE EXTENSION pgcrypto VERSION '1.3';
CREATE EXTENSION auth VERSION '1.0';
};
7 changes: 4 additions & 3 deletions packages/generate/src/edgeql-js/generateGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export const generateGlobals = ({ dir, globals, types }: GeneratorParams) => {

for (const [mod, gs] of Object.entries(globalsByMod)) {
const code = dir.getModule(mod);
const modName = mod.split("::").join("_");
code.writeln([
dts`declare `,
...frag`const $${mod}__globals`,
...frag`const $${modName}__globals`,
t`: {`,
...gs
.flatMap((g) => {
Expand Down Expand Up @@ -53,9 +54,9 @@ export const generateGlobals = ({ dir, globals, types }: GeneratorParams) => {
]);

code.nl();
code.registerRef(`$${mod}__globals`);
code.registerRef(`$${modName}__globals`);
code.addToDefaultExport(
getRef(`$${mod}__globals`, { prefix: "" }),
getRef(`$${modName}__globals`, { prefix: "" }),
"global"
);
}
Expand Down

0 comments on commit 53ddc0e

Please sign in to comment.