diff --git a/qb/playground.ts b/qb/playground.ts index fe6a0d922..06ca07352 100644 --- a/qb/playground.ts +++ b/qb/playground.ts @@ -1,7 +1,8 @@ // tslint:disable:no-console import {setupTests} from "./test/setupTeardown"; -import e, {Genre} from "./dbschema/edgeql-js"; +import e from "./dbschema/edgeql-js"; import {createClient, Duration, IsolationLevel} from "edgedb"; +import type {typeutil} from "edgedb/dist/reflection"; async function run() { await setupTests(); @@ -30,10 +31,7 @@ async function run() { readonly: false, }); - const query = e.select(e.Movie, m => ({ - release_year: true, - filter: e.op(m.title, "=", "The Avengers"), - })); + const query = e.datetime(new Date()); console.log(query.toEdgeQL()); const result = await query.run(client); diff --git a/qb/test/collections.test.ts b/qb/test/collections.test.ts index ff47c07f5..e9846b6e8 100644 --- a/qb/test/collections.test.ts +++ b/qb/test/collections.test.ts @@ -1,6 +1,6 @@ import {Client, $} from "edgedb"; -import e, {$infer} from "../dbschema/edgeql-js"; -import type {$VersionStageλEnum} from "../dbschema/edgeql-js/modules/sys"; +import e, {$infer, sys} from "../dbschema/edgeql-js"; +// import type {$VersionStageλEnum} from "../dbschema/edgeql-js/modules/sys"; import {tc} from "./setupTeardown"; import {setupTests, teardownTests, TestData} from "./setupTeardown"; @@ -390,12 +390,12 @@ test("non literal tuples", async () => { ver: { major: number; minor: number; - stage: `${$VersionStageλEnum}`; + stage: `${sys.VersionStage}`; stage_no: number; local: string[]; }; verMajor: number; - verStage: `${$VersionStageλEnum}`; + verStage: `${sys.VersionStage}`; verLocal: string[]; verLocal0: string; } diff --git a/src/reflection/generators/generateScalars.ts b/src/reflection/generators/generateScalars.ts index 5577a83ed..3b6b42824 100644 --- a/src/reflection/generators/generateScalars.ts +++ b/src/reflection/generators/generateScalars.ts @@ -8,7 +8,7 @@ import { toTSScalarType, scalarToLiteralMapping, } from "../util/genutil"; -import {dts, js, r, t, ts} from "../builders"; +import {dts, r, t, ts} from "../builders"; import type {GeneratorParams} from "../generate"; import {typeMapping} from "../queries/getTypes"; @@ -88,22 +88,6 @@ export const generateScalars = (params: GeneratorParams) => { // generate enum if (type.enum_values && type.enum_values.length) { - sc.writeln([ - dts`declare `, - t`enum `, - js`const `, - ...frag`${ref}λEnum `, - js`= `, - `{`, - ]); - sc.indented(() => { - for (const val of type.enum_values!) { - sc.writeln([toIdent(val), t` = `, js`: `, quote(val), `,`]); - } - }); - sc.writeln([`}`]); - sc.addExport(frag`${ref}λEnum`); - sc.writeln([ t`export `, dts`declare `, @@ -112,7 +96,9 @@ export const generateScalars = (params: GeneratorParams) => { val => t` ${toIdent(val)}: $.$expr_Literal<${ref}>;\n` ), t`} & `, - t`$.EnumType<${quote(type.name)}, \`\${${ref}λEnum}\`>;`, + t`$.EnumType<${quote(type.name)}, [${type.enum_values + .map(val => quote(val)) + .join(", ")}]>;`, ]); sc.writeln([ dts`declare `, diff --git a/src/reflection/typesystem.ts b/src/reflection/typesystem.ts index cbf795b93..754bc1f08 100644 --- a/src/reflection/typesystem.ts +++ b/src/reflection/typesystem.ts @@ -182,13 +182,12 @@ export type ExpressionMethods = { ////////////////// export interface EnumType< Name extends string = string, - TsType extends any = any + Values extends [string, ...string[]] = [string, ...string[]] > extends BaseType { __kind__: TypeKind.enum; - __tstype__: TsType; + __tstype__: Values[number]; __name__: Name; - __values__: string[]; - // (val: TsType | Vals): $expr_Literal; + __values__: Values; } ////////////////// @@ -663,13 +662,13 @@ export type BaseTypeToTsType = Type extends ScalarType : Type extends EnumType ? Type["__tstype__"] : Type extends ArrayType - ? ArrayTypeToTsType + ? typeutil.flatten> : Type extends RangeType ? Range : Type extends TupleType ? TupleItemsToTsType : Type extends NamedTupleType - ? NamedTupleTypeToTsType + ? typeutil.flatten> : Type extends ObjectType ? typeutil.flatten< computeObjectShape