Skip to content

Commit

Permalink
Fix sequence operator bug (#322)
Browse files Browse the repository at this point in the history
* Fix sequence bug

* Fix seq

* 0.20.3
  • Loading branch information
colinhacks committed Apr 1, 2022
1 parent 7445eb7 commit f044e26
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edgedb",
"version": "0.20.2",
"version": "0.20.3",
"description": "The official Node.js client library for EdgeDB",
"homepage": "https://edgedb.com/docs",
"author": "EdgeDB <info@edgedb.com>",
Expand Down
14 changes: 1 addition & 13 deletions qb/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@ import e, * as types from "./dbschema/edgeql-js/index";

async function run() {
const {client} = await setupTests();
const query = e.select(e.Villain, () => ({
id: true,
name: true,
nemesis: nemesis => {
const nameLen = e.len(nemesis.name);
return {
name: true,
nameLen,
nameLen2: nameLen,
};
},
}));

const query = e.select("Hello world!");
console.log(query.toEdgeQL());
const result = await query.run(client);
console.log(result);
Expand Down
4 changes: 4 additions & 0 deletions qb/test/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,10 @@ test("select with enums", async () => {
expect(result.length).toEqual(2);
});

test("filter by sequence", async () => {
await e.op(e.Bag.seqField, "=", 1).run(client);
});

// Modifier methods removed for now, until we can fix typescript inference
// problems / excessively deep errors

Expand Down
1 change: 0 additions & 1 deletion src/reflection/generators/generateOperatorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function generateOperators({
}: GeneratorParams) {
const typeSpecificities = getTypesSpecificity(types, casts);
const implicitCastableRootTypes = getImplicitCastableRootTypes(casts);

const code = dir.getPath("operators");

code.addImport({$: true}, "edgedb");
Expand Down
18 changes: 10 additions & 8 deletions src/reflection/queries/getTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {StrictMap} from "../strictMap";
export type UUID = string;

export type Pointer = {
// cardinality: "One" | "Many";
real_cardinality: Cardinality;
kind: "link" | "property";
name: string;
Expand All @@ -14,7 +13,6 @@ export type Pointer = {
is_computed: boolean;
is_readonly: boolean;
has_default: boolean;
is_seq: boolean;
pointers: ReadonlyArray<Pointer> | null;
};

Expand All @@ -38,6 +36,7 @@ export type TypeProperties<T extends TypeKind> = {

export type ScalarType = TypeProperties<"scalar"> & {
is_abstract: boolean;
is_seq: boolean;
bases: ReadonlyArray<{id: UUID}>;
// ancestors: ReadonlyArray<{id: UUID}>;
enum_values: ReadonlyArray<string> | null;
Expand Down Expand Up @@ -75,20 +74,20 @@ export type Type = PrimitiveType | ObjectType;

export type Types = StrictMap<UUID, Type>;

export const nonCastableTypes = new Set<string>([
// numberType.id
]);

const numberType: ScalarType = {
id: "00000000-0000-0000-0000-0000000001ff",
name: "std::number",
is_abstract: false,
is_seq: false,
kind: "scalar",
enum_values: null,
material_id: null,
bases: [],
};

export const nonCastableTypes = new Set<string>([
// numberType.id
]);

export const typeMapping = new Map([
[
"00000000-0000-0000-0000-000000000103", // int16
Expand Down Expand Up @@ -139,7 +138,7 @@ export async function getTypes(
'unknown',
[IS ScalarType].enum_values,
is_seq := 'std::sequence' in [IS ScalarType].ancestors.name,
# for sequence (abstract type that has non-abstract ancestor)
single material_id := (
SELECT x := Type[IS ScalarType].ancestors
Expand Down Expand Up @@ -221,6 +220,9 @@ export async function getTypes(
if (typeMapping.has(type.id)) {
type.castOnlyType = typeMapping.get(type.id)!.id;
}
if (type.is_seq) {
type.castOnlyType = numberType.id;
}
// if (type.material_id) {
// type.material_id =
// typeMapping.get(type.material_id)?.id ?? type.material_id;
Expand Down

0 comments on commit f044e26

Please sign in to comment.