mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 16:32:32 +00:00
fix: add type annotations to improve innference
This commit is contained in:
parent
cba63941b0
commit
4e25c6e51c
@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
OPEN: 'open',
|
||||
CLOSING: 'closing',
|
||||
CLOSED: 'closed'
|
||||
OPEN: /** @type {'open'} */('open'),
|
||||
CLOSING: /** @type {'closing'} */('closing'),
|
||||
CLOSED: /** @type {'closed'} */('closed')
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ exports.SignaturePolicy = {
|
||||
* * Enforce the fields to be present, reject otherwise.
|
||||
* * Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
||||
*/
|
||||
StrictSign: 'StrictSign',
|
||||
StrictSign: /** @type {'StrictSign'} */ ('StrictSign'),
|
||||
/**
|
||||
* On the producing side:
|
||||
* * Build messages without the signature, key, from and seqno fields.
|
||||
@ -24,5 +24,5 @@ exports.SignaturePolicy = {
|
||||
* * Propagate only if the fields are absent, reject otherwise.
|
||||
* * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
|
||||
*/
|
||||
StrictNoSign: 'StrictNoSign'
|
||||
StrictNoSign: /** @type {'StrictNoSign'} */ 'StrictNoSign'
|
||||
}
|
||||
|
@ -71,8 +71,9 @@ exports.anyMatch = (a, b) => {
|
||||
/**
|
||||
* Make everything an array.
|
||||
*
|
||||
* @param {any} maybeArray
|
||||
* @returns {Array}
|
||||
* @template T
|
||||
* @param {T|T[]} maybeArray
|
||||
* @returns {T[]}
|
||||
* @private
|
||||
*/
|
||||
exports.ensureArray = (maybeArray) => {
|
||||
@ -85,9 +86,11 @@ exports.ensureArray = (maybeArray) => {
|
||||
|
||||
/**
|
||||
* Ensures `message.from` is base58 encoded
|
||||
* @param {object} message
|
||||
* @param {String} peerId
|
||||
* @return {object}
|
||||
*
|
||||
* @template {Object} T
|
||||
* @param {T} message
|
||||
* @param {string} [peerId]
|
||||
* @return {T & {from?: string, peerId?: string }}
|
||||
*/
|
||||
exports.normalizeInRpcMessage = (message, peerId) => {
|
||||
const m = Object.assign({}, message)
|
||||
@ -101,8 +104,10 @@ exports.normalizeInRpcMessage = (message, peerId) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} message
|
||||
* @return {object}
|
||||
* @template {Object} T
|
||||
*
|
||||
* @param {T} message
|
||||
* @return {T & {from?: Uint8Array, data?: Uint8Array}}
|
||||
*/
|
||||
exports.normalizeOutRpcMessage = (message) => {
|
||||
const m = Object.assign({}, message)
|
||||
|
Loading…
x
Reference in New Issue
Block a user