Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
fix: relax and correct types (#144)
Browse files Browse the repository at this point in the history
Make signal optional since we guard on it anyway
  • Loading branch information
achingbrain authored Dec 21, 2021
1 parent cd33519 commit 33d2dd5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const log = Object.assign(debug('mss:handle'), {

/**
* @typedef {import('./types').DuplexStream<Uint8Array>} DuplexStream
* @typedef {import('./types').AbortOptions} AbortOptions
*/

/**
* @param {DuplexStream} stream
* @param {string | string[]} protocols
* @param {object} [options]
* @param {AbortSignal} options.signal
* @param {AbortOptions} [options]
*/
module.exports = async function handle (stream, protocols, options) {
protocols = Array.isArray(protocols) ? protocols : [protocols]
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports.PROTOCOL_ID = PROTOCOL_ID

/**
* @typedef {import('./types').DuplexStream<Uint8Array>} DuplexStream
* @typedef {import('./types').AbortOptions} AbortOptions
*/

class MultistreamSelect {
Expand Down Expand Up @@ -63,8 +64,7 @@ exports.Dialer = Dialer
class Listener extends MultistreamSelect {
/**
* @param {string | string[]} protocols
* @param {object} [options]
* @param {AbortSignal} options.signal
* @param {AbortOptions} [options]
*/
handle (protocols, options) {
return handle(this._stream, protocols, options)
Expand Down
4 changes: 2 additions & 2 deletions src/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const log = Object.assign(debug('mss:ls'), {
/**
* @typedef {import('./types').DuplexStream<Uint8Array>} DuplexStream
* @typedef {import('bl/BufferList')} BufferList
* @typedef {import('./types').AbortOptions} AbortOptions
*/

/**
* @param {DuplexStream} stream
* @param {object} [options]
* @param {AbortSignal} options.signal
* @param {AbortOptions} [options]
*/
module.exports = async function ls (stream, options) {
const { reader, writer, rest, stream: shakeStream } = handshake(stream)
Expand Down
4 changes: 2 additions & 2 deletions src/multistream.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { source } = require('abortable-iterator')

/**
* @typedef {import('it-pushable').Pushable<Uint8Array | BufferList>} Pushable
* @typedef {import('./types').AbortOptions} AbortOptions
*/

const NewLine = uint8ArrayFromString('\n')
Expand Down Expand Up @@ -46,8 +47,7 @@ async function writeAll (writer, buffers) {

/**
* @param {AsyncGenerator<Uint8Array | BufferList, void, number>} reader
* @param {object} [options]
* @param {AbortSignal} options.signal
* @param {AbortOptions} [options]
*/
async function read (reader, options) {
let byteLength = 1 // Read single byte chunks until the length is known
Expand Down
4 changes: 2 additions & 2 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const log = Object.assign(debug('mss:select'), {
/**
* @typedef {import('./types').DuplexStream<Uint8Array>} DuplexStream
* @typedef {import('bl/BufferList')} BufferList
* @typedef {import('./types').AbortOptions} AbortOptions
*/

/**
* @param {DuplexStream} stream
* @param {string | string[]} protocols
* @param {string} [protocolId]
* @param {object} [options]
* @param {AbortSignal} options.signal
* @param {AbortOptions} [options]
*/
module.exports = async function select (stream, protocols, protocolId, options) {
protocols = Array.isArray(protocols) ? [...protocols] : [protocols]
Expand Down
11 changes: 9 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

export interface AbortOptions {
signal?: AbortSignal
}

export type Source<T> = AsyncIterable<T>
export interface Sink<T> { (source: AsyncIterable<T>): Promise<void> }

export interface DuplexStream<T> {
source: AsyncIterable<T>
sink: (source: AsyncIterable<T>) => void
source: Source<T>
sink: Sink<T>
}

0 comments on commit 33d2dd5

Please sign in to comment.