-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle >2 union members in links #669
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6750956
Handle >2 union members in links
scotttrinh 3d8318a
Add 2.x back in but continue on error
scotttrinh cdc9662
wip: Attempt to find the macOS test failure
scotttrinh 30a158c
Revert allowing 2.x to fail
scotttrinh 42b4595
Run tests on all pull requests
scotttrinh 2c91512
Commit the migration
scotttrinh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ on: | |
- master | ||
- ci | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CREATE MIGRATION m1bffqrfcj7ols7s3v27kgbxhtsetpvwvqpxrogvhsq2crwwlnbbya | ||
ONTO m1sxhoqfjqn7vtpmatzanmwydtxndf3jlf33npkblmya42fx3bcdoa | ||
{ | ||
CREATE TYPE default::W { | ||
CREATE PROPERTY a -> std::str; | ||
CREATE PROPERTY d -> std::float64; | ||
}; | ||
ALTER TYPE default::Z { | ||
ALTER LINK xy { | ||
SET TYPE ((default::Y | default::X) | default::W) USING (SELECT | ||
default::X | ||
LIMIT | ||
1 | ||
); | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { CodeFragment, dts, r, t, ts } from "../builders"; | ||
import { type CodeFragment, dts, r, t, ts } from "../builders"; | ||
import type { GeneratorParams } from "../genutil"; | ||
import type { $ } from "../genutil"; | ||
import { | ||
|
@@ -158,93 +158,15 @@ export const getStringRepresentation: ( | |
export const generateObjectTypes = (params: GeneratorParams) => { | ||
const { dir, types } = params; | ||
|
||
// const plainTypesCode = dir.getPath("types"); | ||
// plainTypesCode.addImportStar("edgedb", "edgedb", { | ||
// typeOnly: true | ||
// }); | ||
// const plainTypeModules = new Map< | ||
// string, | ||
// {internalName: string; buf: CodeBuffer; types: Map<string, string>} | ||
// >(); | ||
|
||
// const getPlainTypeModule = ( | ||
// typeName: string | ||
// ): { | ||
// tMod: string; | ||
// tName: string; | ||
// module: { | ||
// internalName: string; | ||
// buf: CodeBuffer; | ||
// types: Map<string, string>; | ||
// }; | ||
// } => { | ||
// const {mod: tMod, name: tName} = splitName(typeName); | ||
// if (!plainTypeModules.has(tMod)) { | ||
// plainTypeModules.set(tMod, { | ||
// internalName: makePlainIdent(tMod), | ||
// buf: new CodeBuffer(), | ||
// types: new Map() | ||
// }); | ||
// } | ||
// return {tMod, tName, module: plainTypeModules.get(tMod)!}; | ||
// }; | ||
|
||
// const _getTypeName = | ||
// (mod: string) => | ||
// (typeName: string, withModule: boolean = false): string => { | ||
// const {tMod, tName, module} = getPlainTypeModule(typeName); | ||
// return ( | ||
// ((mod !== tMod || withModule) && tMod !== "default" | ||
// ? `${module.internalName}.` | ||
// : "") + `${makePlainIdent(tName)}` | ||
// ); | ||
// }; | ||
|
||
for (const type of types.values()) { | ||
if (type.kind !== "object") { | ||
// if (type.kind === "scalar" && type.enum_values?.length) { | ||
// // generate plain enum type | ||
// const {mod: enumMod, name: enumName} = splitName(type.name); | ||
// const getEnumTypeName = _getTypeName(enumMod); | ||
|
||
// const {module} = getPlainTypeModule(type.name); | ||
// module.types.set(enumName, getEnumTypeName(type.name, true)); | ||
// module.buf.writeln( | ||
// [t`export enum ${getEnumTypeName(type.name)} {`], | ||
// ...type.enum_values.map(val => [ | ||
// t` ${makePlainIdent(val)} = ${quote(val)},` | ||
// ]), | ||
// [t`}`] | ||
// ); | ||
|
||
// if (enumMod === "default") { | ||
// module.buf.writeln( | ||
// [js`const ${getEnumTypeName(type.name)} = {`], | ||
// ...type.enum_values.map(val => [ | ||
// js` ${makePlainIdent(val)}: ${quote(val)},` | ||
// ]), | ||
// [js`}`] | ||
// ); | ||
// plainTypesCode.addExport(getEnumTypeName(type.name), { | ||
// modes: ["js"] | ||
// }); | ||
// } else { | ||
// module.buf.writeln( | ||
// [js`"${getEnumTypeName(type.name)}": {`], | ||
// ...type.enum_values.map(val => [ | ||
// js` ${makePlainIdent(val)}: ${quote(val)},` | ||
// ]), | ||
// [js`},`] | ||
// ); | ||
// } | ||
// } | ||
continue; | ||
} | ||
|
||
const isUnionType = Boolean(type.union_of?.length); | ||
const isIntersectionType = Boolean(type.intersection_of?.length); | ||
|
||
if (isIntersectionType) { | ||
if (isIntersectionType || isUnionType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the actual fix: we just skip generating any type if it's actually a union instead of a separate type. |
||
continue; | ||
} | ||
|
||
|
@@ -256,65 +178,6 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
|
||
const ref = getRef(type.name); | ||
|
||
///////// | ||
// generate plain type | ||
///////// | ||
|
||
// const getTypeName = _getTypeName(mod); | ||
|
||
// const getTSType = (pointer: $.introspect.Pointer): string => { | ||
// const targetType = types.get(pointer.target_id); | ||
// if (pointer.kind === "link") { | ||
// return getTypeName(targetType.name); | ||
// } else { | ||
// return toTSScalarType( | ||
// targetType as $.introspect.PrimitiveType, | ||
// types, | ||
// { | ||
// getEnumRef: enumType => getTypeName(enumType.name), | ||
// edgedbDatatypePrefix: "" | ||
// } | ||
// ).join(""); | ||
// } | ||
// }; | ||
|
||
// const {module: plainTypeModule} = getPlainTypeModule(type.name); | ||
|
||
// if (!isUnionType) { | ||
// plainTypeModule.types.set(name, getTypeName(type.name, true)); | ||
// } | ||
// plainTypeModule.buf.writeln([ | ||
// t`${ | ||
// !isUnionType ? "export " : "" | ||
// }interface ${getTypeName(type.name)}${ | ||
// type.bases.length | ||
// ? ` extends ${type.bases | ||
// .map(({id}) => { | ||
// const baseType = types.get(id); | ||
// return getTypeName(baseType.name); | ||
// }) | ||
// .join(", ")}` | ||
// : "" | ||
// } ${ | ||
// type.pointers.length | ||
// ? `{\n${type.pointers | ||
// .map(pointer => { | ||
// const isOptional = | ||
// pointer.real_cardinality === Cardinality.AtMostOne; | ||
// return ` ${quote(pointer.name)}${ | ||
// isOptional ? "?" : "" | ||
// }: ${getTSType(pointer)}${ | ||
// pointer.card === Cardinality.Many || | ||
// pointer.card === Cardinality.AtLeastOne | ||
// ? "[]" | ||
// : "" | ||
// }${isOptional ? " | null" : ""};`; | ||
// }) | ||
// .join("\n")}\n}` | ||
// : "{}" | ||
// }\n`, | ||
// ]); | ||
|
||
///////// | ||
// generate interface | ||
///////// | ||
|
@@ -357,19 +220,6 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
}; | ||
}; | ||
|
||
// unique | ||
// const BaseObject = params.typesByName["std::BaseObject"]; | ||
// const uniqueStubs = [...new Set(type.backlinks.map((bl) => bl.stub))]; | ||
// const stubLines = uniqueStubs.map((stub): $.introspect.Pointer => { | ||
// return { | ||
// card: Cardinality.Many, | ||
// kind: "link", | ||
// name: `<${stub}`, | ||
// target_id: BaseObject.id, | ||
// is_exclusive: false, | ||
// pointers: null, | ||
// }; | ||
// }); | ||
const lines = [ | ||
...type.pointers, | ||
...type.backlinks, | ||
|
@@ -456,7 +306,6 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
} | ||
}); | ||
|
||
// const ref = getRef(type.name); | ||
for (const ex of type.exclusives) { | ||
body.writeln([ | ||
t` {`, | ||
|
@@ -468,7 +317,6 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
}), | ||
t`},`, | ||
]); | ||
// body.writeln([t`\n {${lines.join(", ")}}`]); | ||
} | ||
|
||
body.writeln([t`]>;`]); | ||
|
@@ -480,11 +328,6 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
///////// | ||
// generate runtime type | ||
///////// | ||
if (isUnionType) { | ||
// union types don't need runtime type | ||
continue; | ||
} | ||
|
||
const literal = getRef(type.name, { prefix: "" }); | ||
|
||
body.writeln([ | ||
|
@@ -496,7 +339,6 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
r`(_.spec, ${quote(type.id)}, _.syntax.literal);`, | ||
]); | ||
body.addExport(ref); | ||
// body.addExport(ref, `$${name}`); // dollar | ||
|
||
const typeCard = singletonObjectTypes.has(type.name) ? "One" : "Many"; | ||
|
||
|
@@ -513,28 +355,4 @@ export const generateObjectTypes = (params: GeneratorParams) => { | |
body.addExport(literal); | ||
body.addToDefaultExport(literal, name); | ||
} | ||
|
||
// plain types export | ||
// const plainTypesExportBuf = new CodeBuffer(); | ||
// for (const [moduleName, module] of plainTypeModules) { | ||
// if (moduleName === "default") { | ||
// plainTypesCode.writeBuf(module.buf); | ||
// } else { | ||
// plainTypesCode.writeln([t`export namespace ${module.internalName} {`]); | ||
// plainTypesCode.writeln([js`const ${module.internalName} = {`]); | ||
// plainTypesCode.indented(() => plainTypesCode.writeBuf(module.buf)); | ||
// plainTypesCode.writeln([t`}`]); | ||
// plainTypesCode.writeln([js`}`]); | ||
// plainTypesCode.addExport(module.internalName, {modes: ["js"]}); | ||
// } | ||
|
||
// plainTypesExportBuf.writeln([ | ||
// t` ${quote(moduleName)}: {\n${[...module.types.entries()] | ||
// .map(([name, typeName]) => ` ${quote(name)}: ${typeName};`) | ||
// .join("\n")}\n };` | ||
// ]); | ||
// } | ||
// plainTypesCode.writeln([t`export interface types {`]); | ||
// plainTypesCode.writeBuf(plainTypesExportBuf); | ||
// plainTypesCode.writeln([t`}`]); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm just killing all this commented out code: it's already drifting pretty far, so I don't think it makes much sense to keep it.