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

Fixed crypto import and isNodeStream function #79

Merged
merged 4 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/facade/FileClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface FileClientConfig {
}

function isNodeStream(source: InputSource): source is NodeJS.ReadableStream {
return Object.prototype.hasOwnProperty.call(source, 'pipe');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

amazingly hasOwnProperty returns false for stream altough !!source.pipe returns pipe. HasOwnPropery is for innumerable props (the one that will appear in loop, native methods are not innumerable).

return typeof (source as NodeJS.ReadableStream)?.pipe === 'function';
}

export class FileClient {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/index.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NanoTDFClient, NanoTDFDatasetClient, AuthProviders, version, clientType } from './index';
import fetch from 'node-fetch';
import crypto from 'crypto';
import { webcrypto as crypto } from 'node:crypto';

globalThis.crypto = crypto as unknown as Crypto;
globalThis.fetch = fetch as typeof globalThis.fetch;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/nanotdf-crypto/getCryptoLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default function getCryptoLib(): SubtleCrypto {
return subtleCrypto;
}

return globalThis.crypto.webcrypto.subtle;
return globalThis.crypto.subtle;
}