Skip to content

Commit

Permalink
Handle anyobject and re-enable the FTS module
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Oct 12, 2023
1 parent c1579a7 commit 5379b1d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
8 changes: 1 addition & 7 deletions packages/generate/src/edgeql-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,7 @@ export async function generateQueryBuilder(params: {
generateSetImpl(generatorParams);
console.log("Generating globals...");
generateGlobals(generatorParams);

// TODO: Fix 'fts' module generation properly, for now we just disable
// output of this module
dir._modules.delete("fts");
dir._map.delete("modules/fts");
// -----------------

console.log("Generating index...");
generateIndex(generatorParams);

// generate module imports
Expand Down
1 change: 0 additions & 1 deletion packages/generate/src/edgeql-js/generateFunctionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function generateFuncopTypes<F extends FuncopDef>(
const implicitCastableRootTypes = getImplicitCastableRootTypes(casts);

for (const [funcName, _funcDefs] of funcops.entries()) {
console.log("Generating function type for", funcName);
const { mod, name } = splitName(funcName);

const code = dir.getModule(mod);
Expand Down
37 changes: 30 additions & 7 deletions packages/generate/src/funcoputil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ export function expandFuncopAnytypeOverloads<F extends FuncopDef>(

// create an anytype overload for 'range<anypoint>' so 'anypoint'
// gets inferred to the same type in return type
const anypointParams = [
const paramsList = [
...overload.params.positional,
...overload.params.named,
].filter((param) => param.type.name.includes("anypoint"));
];
const anypointParams = paramsList.filter((param) =>
param.type.name.includes("anypoint")
);
if (anypointParams.length) {
return [
{
Expand All @@ -54,6 +57,23 @@ export function expandFuncopAnytypeOverloads<F extends FuncopDef>(
},
];
}
const anyobjectParams = paramsList.filter((param) =>
param.type.name.includes("anyobject")
);
if (anyobjectParams.length) {
return [
{
...overload,
anytypes: {
kind: "noncastable" as const,
type: ["$.ObjectType"],
typeObj: anyobjectParams[0].type,
refName: anyobjectParams[0].typeName,
refPath: findPathOfAnytype(anyobjectParams[0].type.id, types),
},
},
];
}

// Each overload with 'anytype' params is expanded into several overloads:
// - overload for each implicitly castable root type union
Expand All @@ -73,10 +93,9 @@ export function expandFuncopAnytypeOverloads<F extends FuncopDef>(
// other params reference first param type
// - return anytype: references first param type

const anytypeParams = [
...overload.params.positional,
...overload.params.named,
].filter((param) => param.type.name.includes("anytype"));
const anytypeParams = paramsList.filter((param) =>
param.type.name.includes("anytype")
);

if (anytypeParams.length) {
const hasArrayType =
Expand Down Expand Up @@ -204,7 +223,11 @@ function _findPathOfAnytype(
): string | null {
const type = types.get(typeId);

if (type.name === "anytype" || type.name === "anypoint") {
if (
type.name === "anytype" ||
type.name === "anypoint" ||
type.name === "anyobject"
) {
return '["__element__"]';
}
if (type.kind === "array") {
Expand Down

0 comments on commit 5379b1d

Please sign in to comment.