extension-port-stream
Advanced tools
Comparing version 2.0.1 to 2.1.1
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
@@ -10,20 +9,35 @@ | ||
## [2.0.1] - 2021-04-29 | ||
## [2.1.1] | ||
### Changed | ||
- deps: replace webextension-polyfill-ts with webextension-polyfill ([#43](https://github.com/MetaMask/extension-port-stream/pull/43)) | ||
## [2.1.0] - 2023-06-15 | ||
### Added | ||
- `_setLogger` method can be used to inject custom logger for incoming/outgoing messages ([#46](https://github.com/MetaMask/extension-port-stream/pull/46)) | ||
### Changed | ||
- deps: webextension-polyfill-ts@0.22.0->0.26.0 ([#37](https://github.com/MetaMask/extension-port-stream/pull/37)) | ||
- Updates webextension-polyfill from 0.7.0 to 0.8.0 | ||
### Fixed | ||
- Fix exporting of types ([#24](https://github.com/MetaMask/extension-port-stream/pull/24)) | ||
- deps: webextension-polyfill-ts@0.22.0->0.26.0 ([#37](https://github.com/MetaMask/extension-port-stream/pull/37)) | ||
- Updates webextension-polyfill from 0.7.0 to 0.8.0 | ||
## [2.0.1] - 2021-04-29 | ||
### Changed | ||
- Move `webextension-polyfill-ts` from `devDependencies` to `dependencies` ([#11](https://github.com/MetaMask/extension-port-stream/pull/11)) | ||
## [2.0.0] - 2020-11-23 | ||
### Added | ||
- TypeScript typings ([#4](https://github.com/MetaMask/extension-port-stream/pull/4)) | ||
### Removed | ||
- **(BREAKING)** Remove `readable-stream` dependency ([#4](https://github.com/MetaMask/extension-port-stream/pull/4)) | ||
- Consumers using this package in browser environments will have to bring their own Node.js stream polyfill. | ||
[Unreleased]:https://github.com/MetaMask/extension-port-stream/compare/v2.0.0...HEAD | ||
[2.0.0]:https://github.com/MetaMask/extension-port-stream/compare/v1.0.0...v2.0.0 | ||
[Unreleased]: https://github.com/MetaMask/extension-port-stream/compare/v2.1.1...HEAD | ||
[2.1.1]: https://github.com/MetaMask/extension-port-stream/compare/v2.1.0...v2.1.1 | ||
[2.1.0]: https://github.com/MetaMask/extension-port-stream/compare/v2.0.1...v2.1.0 | ||
[2.0.1]: https://github.com/MetaMask/extension-port-stream/compare/v2.0.0...v2.0.1 | ||
[2.0.0]: https://github.com/MetaMask/extension-port-stream/releases/tag/v2.0.0 |
/// <reference types="node" /> | ||
import { Duplex } from 'stream'; | ||
import { Runtime } from 'webextension-polyfill-ts'; | ||
declare const _default: { | ||
new (port: Runtime.Port): { | ||
_port: Runtime.Port; | ||
/** | ||
* Callback triggered when a message is received from | ||
* the remote Port associated with this Stream. | ||
* | ||
* @param msg - Payload from the onMessage listener of the port | ||
*/ | ||
_onMessage(msg: unknown): void; | ||
/** | ||
* Callback triggered when the remote Port associated with this Stream | ||
* disconnects. | ||
*/ | ||
_onDisconnect(): void; | ||
/** | ||
* Explicitly sets read operations to a no-op. | ||
*/ | ||
_read(): void; | ||
/** | ||
* Called internally when data should be written to this writable stream. | ||
* | ||
* @param msg - Arbitrary object to write | ||
* @param encoding - Encoding to use when writing payload | ||
* @param cb - Called when writing is complete or an error occurs | ||
*/ | ||
_write(msg: unknown, _encoding: BufferEncoding, cb: (error?: Error | null | undefined) => void): void; | ||
readonly writable: boolean; | ||
readonly writableEnded: boolean; | ||
readonly writableFinished: boolean; | ||
readonly writableHighWaterMark: number; | ||
readonly writableLength: number; | ||
readonly writableObjectMode: boolean; | ||
readonly writableCorked: number; | ||
_writev?(chunks: { | ||
chunk: any; | ||
encoding: BufferEncoding; | ||
}[], callback: (error?: Error | null | undefined) => void): void; | ||
_destroy(error: Error | null, callback: (error: Error | null) => void): void; | ||
_final(callback: (error?: Error | null | undefined) => void): void; | ||
write(chunk: any, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined, cb?: ((error: Error | null | undefined) => void) | undefined): boolean; | ||
write(chunk: any, cb?: ((error: Error | null | undefined) => void) | undefined): boolean; | ||
setDefaultEncoding(encoding: BufferEncoding): any; | ||
end(cb?: (() => void) | undefined): void; | ||
end(chunk: any, cb?: (() => void) | undefined): void; | ||
end(chunk: any, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined, cb?: (() => void) | undefined): void; | ||
cork(): void; | ||
uncork(): void; | ||
readable: boolean; | ||
readonly readableEncoding: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | null; | ||
readonly readableEnded: boolean; | ||
readonly readableFlowing: boolean | null; | ||
readonly readableHighWaterMark: number; | ||
readonly readableLength: number; | ||
readonly readableObjectMode: boolean; | ||
destroyed: boolean; | ||
read(size?: number | undefined): any; | ||
setEncoding(encoding: BufferEncoding): any; | ||
pause(): any; | ||
resume(): any; | ||
isPaused(): boolean; | ||
unpipe(destination?: NodeJS.WritableStream | undefined): any; | ||
unshift(chunk: any, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): void; | ||
wrap(oldStream: NodeJS.ReadableStream): any; | ||
push(chunk: any, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): boolean; | ||
destroy(error?: Error | undefined): void; | ||
addListener(event: "close", listener: () => void): any; | ||
addListener(event: "data", listener: (chunk: any) => void): any; | ||
addListener(event: "end", listener: () => void): any; | ||
addListener(event: "error", listener: (err: Error) => void): any; | ||
addListener(event: "pause", listener: () => void): any; | ||
addListener(event: "readable", listener: () => void): any; | ||
addListener(event: "resume", listener: () => void): any; | ||
addListener(event: string | symbol, listener: (...args: any[]) => void): any; | ||
emit(event: "close"): boolean; | ||
emit(event: "data", chunk: any): boolean; | ||
emit(event: "end"): boolean; | ||
emit(event: "error", err: Error): boolean; | ||
emit(event: "pause"): boolean; | ||
emit(event: "readable"): boolean; | ||
emit(event: "resume"): boolean; | ||
emit(event: string | symbol, ...args: any[]): boolean; | ||
on(event: "close", listener: () => void): any; | ||
on(event: "data", listener: (chunk: any) => void): any; | ||
on(event: "end", listener: () => void): any; | ||
on(event: "error", listener: (err: Error) => void): any; | ||
on(event: "pause", listener: () => void): any; | ||
on(event: "readable", listener: () => void): any; | ||
on(event: "resume", listener: () => void): any; | ||
on(event: string | symbol, listener: (...args: any[]) => void): any; | ||
once(event: "close", listener: () => void): any; | ||
once(event: "data", listener: (chunk: any) => void): any; | ||
once(event: "end", listener: () => void): any; | ||
once(event: "error", listener: (err: Error) => void): any; | ||
once(event: "pause", listener: () => void): any; | ||
once(event: "readable", listener: () => void): any; | ||
once(event: "resume", listener: () => void): any; | ||
once(event: string | symbol, listener: (...args: any[]) => void): any; | ||
prependListener(event: "close", listener: () => void): any; | ||
prependListener(event: "data", listener: (chunk: any) => void): any; | ||
prependListener(event: "end", listener: () => void): any; | ||
prependListener(event: "error", listener: (err: Error) => void): any; | ||
prependListener(event: "pause", listener: () => void): any; | ||
prependListener(event: "readable", listener: () => void): any; | ||
prependListener(event: "resume", listener: () => void): any; | ||
prependListener(event: string | symbol, listener: (...args: any[]) => void): any; | ||
prependOnceListener(event: "close", listener: () => void): any; | ||
prependOnceListener(event: "data", listener: (chunk: any) => void): any; | ||
prependOnceListener(event: "end", listener: () => void): any; | ||
prependOnceListener(event: "error", listener: (err: Error) => void): any; | ||
prependOnceListener(event: "pause", listener: () => void): any; | ||
prependOnceListener(event: "readable", listener: () => void): any; | ||
prependOnceListener(event: "resume", listener: () => void): any; | ||
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): any; | ||
removeListener(event: "close", listener: () => void): any; | ||
removeListener(event: "data", listener: (chunk: any) => void): any; | ||
removeListener(event: "end", listener: () => void): any; | ||
removeListener(event: "error", listener: (err: Error) => void): any; | ||
removeListener(event: "pause", listener: () => void): any; | ||
removeListener(event: "readable", listener: () => void): any; | ||
removeListener(event: "resume", listener: () => void): any; | ||
removeListener(event: string | symbol, listener: (...args: any[]) => void): any; | ||
[Symbol.asyncIterator](): AsyncIterableIterator<any>; | ||
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { | ||
end?: boolean | undefined; | ||
} | undefined): T; | ||
off(event: string | symbol, listener: (...args: any[]) => void): any; | ||
removeAllListeners(event?: string | symbol | undefined): any; | ||
setMaxListeners(n: number): any; | ||
getMaxListeners(): number; | ||
listeners(event: string | symbol): Function[]; | ||
rawListeners(event: string | symbol): Function[]; | ||
listenerCount(event: string | symbol): number; | ||
eventNames(): (string | symbol)[]; | ||
}; | ||
from(iterable: Iterable<any> | AsyncIterable<any>, options?: import("stream").ReadableOptions | undefined): import("stream").Readable; | ||
finished: typeof import("stream").finished; | ||
pipeline: typeof import("stream").pipeline; | ||
Stream: typeof import("stream").Stream; | ||
Readable: typeof import("stream").Readable; | ||
Writable: typeof import("stream").Writable; | ||
Duplex: typeof Duplex; | ||
Transform: typeof import("stream").Transform; | ||
PassThrough: typeof import("stream").PassThrough; | ||
listenerCount(emitter: import("events").EventEmitter, event: string | symbol): number; | ||
defaultMaxListeners: number; | ||
readonly errorMonitor: unique symbol; | ||
}; | ||
export = _default; | ||
import { Runtime } from 'webextension-polyfill'; | ||
declare type Log = (data: unknown, out: boolean) => void; | ||
export default class PortDuplexStream extends Duplex { | ||
private _port; | ||
private _log; | ||
/** | ||
* @param port - An instance of WebExtensions Runtime.Port. See: | ||
* {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port} | ||
*/ | ||
constructor(port: Runtime.Port); | ||
/** | ||
* Callback triggered when a message is received from | ||
* the remote Port associated with this Stream. | ||
* | ||
* @param msg - Payload from the onMessage listener of the port | ||
*/ | ||
private _onMessage; | ||
/** | ||
* Callback triggered when the remote Port associated with this Stream | ||
* disconnects. | ||
*/ | ||
private _onDisconnect; | ||
/** | ||
* Explicitly sets read operations to a no-op. | ||
*/ | ||
_read(): void; | ||
/** | ||
* Called internally when data should be written to this writable stream. | ||
* | ||
* @param msg - Arbitrary object to write | ||
* @param encoding - Encoding to use when writing payload | ||
* @param cb - Called when writing is complete or an error occurs | ||
*/ | ||
_write(msg: unknown, _encoding: BufferEncoding, cb: (error?: Error | null) => void): void; | ||
/** | ||
* Call to set a custom logger for incoming/outgoing messages | ||
* | ||
* @param log - the logger function | ||
*/ | ||
_setLogger(log: Log): void; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const stream_1 = require("stream"); | ||
module.exports = class PortDuplexStream extends stream_1.Duplex { | ||
class PortDuplexStream extends stream_1.Duplex { | ||
/** | ||
@@ -13,2 +14,3 @@ * @param port - An instance of WebExtensions Runtime.Port. See: | ||
this._port.onDisconnect.addListener(() => this._onDisconnect()); | ||
this._log = () => null; | ||
} | ||
@@ -24,5 +26,7 @@ /** | ||
const data = Buffer.from(msg); | ||
this._log(data, false); | ||
this.push(data); | ||
} | ||
else { | ||
this._log(msg, false); | ||
this.push(msg); | ||
@@ -56,5 +60,7 @@ } | ||
data._isBuffer = true; | ||
this._log(data, true); | ||
this._port.postMessage(data); | ||
} | ||
else { | ||
this._log(msg, true); | ||
this._port.postMessage(msg); | ||
@@ -68,3 +74,12 @@ } | ||
} | ||
}; | ||
/** | ||
* Call to set a custom logger for incoming/outgoing messages | ||
* | ||
* @param log - the logger function | ||
*/ | ||
_setLogger(log) { | ||
this._log = log; | ||
} | ||
} | ||
exports.default = PortDuplexStream; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "extension-port-stream", | ||
"version": "2.0.1", | ||
"version": "2.1.1", | ||
"description": "A module for creating a node style stream over a WebExtension port object.", | ||
@@ -13,3 +13,4 @@ "main": "dist/index.js", | ||
"lint:fix": "yarn lint --fix", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"prepublishOnly": "yarn build && yarn lint" | ||
}, | ||
@@ -21,3 +22,3 @@ "files": [ | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/MetaMask/extension-port-stream.git" | ||
"url": "https://git@github.com/MetaMask/extension-port-stream" | ||
}, | ||
@@ -35,6 +36,7 @@ "keywords": [ | ||
"dependencies": { | ||
"webextension-polyfill-ts": "^0.22.0" | ||
"webextension-polyfill": ">=0.10.0 <1.0" | ||
}, | ||
"devDependencies": { | ||
"@metamask/eslint-config": "^4.1.0", | ||
"@types/webextension-polyfill": ">=0.10.0 <1.0", | ||
"@types/node": "14.14.7", | ||
@@ -41,0 +43,0 @@ "@typescript-eslint/eslint-plugin": "^4.8.1", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10114
10
124
1
+ Addedwebextension-polyfill@0.12.0(transitive)
- Removedwebextension-polyfill-ts@^0.22.0
- Removedwebextension-polyfill@0.7.0(transitive)
- Removedwebextension-polyfill-ts@0.22.0(transitive)