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

RS-394: Add query support for browser #90

Merged
merged 8 commits into from
Aug 7, 2024

Conversation

AnthonyCvn
Copy link
Contributor

@AnthonyCvn AnthonyCvn commented Aug 5, 2024

Closes #

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • CHANGELOG.md has been updated (for bug fixes / features / docs)

What kind of change does this PR introduce?

Bug fix

What was changed?

  • Detect if the module is running in the browser
  • Request ArrayBuffer instead of Stream when running in the browser
  • Only fetch single records in the browser (not batch)
  • Convert ArrayBuffer to Node.js Buffer (the read() method always gives a Node.js Buffer)

Related issues

No

Does this PR introduce a breaking change?

No

Other information:

Because the read function gives a Node.js Buffer object, applications running in the browser must install stream-browserify.

@AnthonyCvn AnthonyCvn requested a review from atimin August 5, 2024 09:23
src/Record.ts Outdated
@@ -12,7 +13,7 @@ export class ReadableRecord {
public readonly time: bigint;
public readonly size: bigint;
public readonly last: boolean;
public readonly stream: Stream;
public readonly stream: Stream | ArrayBuffer;
Copy link
Member

Choose a reason for hiding this comment

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

I think you break the compatibility here, because in the client code the TS compiler will rise an error to force type check.
I think it is better to use two fields. We can even make it private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atimin good point! I have added another private field for ArrayBuffer. The twist is to give a dummy stream to the stream field in the browser to avoid having an optional stream field that would break compatibility. Let me know if the new update makes sense.

@AnthonyCvn AnthonyCvn requested a review from atimin August 7, 2024 07:58
Copy link
Member

@atimin atimin left a comment

Choose a reason for hiding this comment

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

Perfect!

@atimin atimin merged commit 399c9e5 into main Aug 7, 2024
13 of 19 checks passed
@atimin atimin deleted the RS-394-Add-query-support-for-browser-reduct-js branch August 7, 2024 08:20
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