Skip to content
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

Fix calling get_attribute_names on committed datatype #84

Merged
merged 7 commits into from
Sep 5, 2024

Conversation

axelboc
Copy link
Collaborator

@axelboc axelboc commented Sep 2, 2024

Addresses #80 (comment)

Tested locally with:

@axelboc axelboc marked this pull request as draft September 2, 2024 14:08
@bmaranville
Copy link
Member

#83 is merged

@axelboc axelboc marked this pull request as ready for review September 3, 2024 06:36
@bmaranville
Copy link
Member

@axelboc I don't mean to hijack your PR but this seemed like a logical place to also make the changes to the Datatype class, supporting attributes.

Do the types look ok?

Copy link
Collaborator Author

@axelboc axelboc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be my guest! 😊 Looks like I completely missed extending from HasAttrs, thanks.

src/hdf5_hl.ts Outdated
Comment on lines 668 to 669
dereference(ref: Reference | RegionReference): DatasetRegion | getReturnTypes | null {
const is_region = (ref instanceof RegionReference);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cleaner to override this method in the RegionReference class to avoid returning DatasetRegion when invoking this method on other kinds of objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegionReference doesn't extend HasAttrs, so what I suggested was not possible. Instead, I added signature overrides to the dereference method so that if one passes a RegionReference, the return type is DatasetRegion:

dereference(ref: RegionReference): DatasetRegion;
dereference(ref: Reference | RegionReference): DatasetRegion | getReturnTypes | null;

src/hdf5_hl.ts Outdated
@@ -504,6 +504,8 @@ enum OBJECT_TYPE {
REGION_REFERENCE = 'RegionReference',
}

export type getReturnTypes = Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | Reference | RegionReference;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the term Entity would be more suited? In H5Web, Entity is the base interface, and ProvidedEntity is the union of all entity interfaces that extend Entity, but since the bare term "entity" doesn't seem to be used yet in h5wasm, I see no problem using it. Otherwise, maybe ChildEntity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used Entity, but feel free to rename. I ruled out Object since it's already used by TypeScript.

src/hdf5_hl.d.ts Outdated
values(): Generator<BrokenSoftLink | ExternalLink | Datatype | Group | Dataset | null, void, unknown>;
items(): Generator<(string | BrokenSoftLink | ExternalLink | Datatype | Group | Dataset | null)[], void, unknown>;
values(): Generator<getReturnTypes | null, void, unknown>;
items(): Generator<(string | Reference | Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | null)[], void, unknown>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a tuple should work and be more accurate:

Suggested change
items(): Generator<(string | Reference | Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | null)[], void, unknown>;
items(): Generator<[string, getReturnTypes | null], void, unknown>;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is generated by the typescript compiler directly, not by me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, because you changed the return type of Group#get. I think we can "fix" it by defining the return type explicitly on Group#items.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@bmaranville
Copy link
Member

bmaranville commented Sep 4, 2024

When I run npm run build, I get a generated hdf5_hl.d.ts that differs from yours, but only in the line endings - all the source files in h5wasm use lf line endings so far (but your committed hdf5_hl.d.ts uses crlf)

@axelboc
Copy link
Collaborator Author

axelboc commented Sep 5, 2024

Apologies, I was on a Windows machine. I've added an .editorconfig file at the root of the repo to avoid this issue in the future.

@bmaranville bmaranville merged commit b5f5b71 into usnistgov:main Sep 5, 2024
1 check passed
@axelboc axelboc deleted the fix-datatype branch September 6, 2024 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants