Skip to content

Commit

Permalink
Add assertion that querybuilder is built by same edgedb-js version as…
Browse files Browse the repository at this point in the history
… currently installed (#300)
  • Loading branch information
jaclarke committed Mar 16, 2022
1 parent b505c59 commit 01dc45c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/index.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export type _ICodec = codecs.ICodec;

import {plugJSBI} from "./primitives/bigint";
export const _plugJSBI = plugJSBI;

export const _edgedbJsVersion = "0.0.0";
14 changes: 12 additions & 2 deletions src/reflection/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {fs, path, exists, readFileUtf8} from "../adapter.node";

import {DirBuilder, dts, r, t} from "./builders";
import {createClient, Client} from "../index.node";
import {createClient, Client, _edgedbJsVersion} from "../index.node";

import {ConnectConfig} from "../conUtils";

Expand Down Expand Up @@ -114,11 +114,21 @@ export async function generateQB(params: {
// index.addExportStarFrom(null, "./castMaps", true);
index.addExportStarFrom(null, "./syntax/external", true);
index.addExportStarFrom(null, "./types", true, ["ts", "dts"]);
index.addImport({$: true}, "edgedb");
index.addImport({$: true, _edgedbJsVersion: true}, "edgedb");
index.addExportFrom({createClient: true}, "edgedb");
index.addStarImport("$syntax", "./syntax/syntax", true);
index.addStarImport("$op", "./operators", true);

index.writeln([
r`\nif (_edgedbJsVersion !== "${_edgedbJsVersion}") {
throw new Error(
\`The query builder was generated by a different version of edgedb-js (v${_edgedbJsVersion})\` +
\` than the one currently installed (v\${_edgedbJsVersion}).\\n\` +
\`Run 'npx edgeql-js' to re-generate a compatible version.\\n\`
);
}`,
]);

const spreadModules = [
{
name: "$op",
Expand Down
2 changes: 2 additions & 0 deletions tools/copySyntaxToDist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ mv dist/__esm/syntax/*.mjs dist/syntax
rm -r dist/__esm
cp src/syntax/*.ts dist/syntax/
rm -rf dist/syntax/genMock
sed -i.bak -e "s/\"0.0.0\"/\"$npm_package_version\"/" dist/index.shared*
rm dist/index.shared*.bak

0 comments on commit 01dc45c

Please sign in to comment.