mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-28 23: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'
|
'use strict'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
OPEN: 'open',
|
OPEN: /** @type {'open'} */('open'),
|
||||||
CLOSING: 'closing',
|
CLOSING: /** @type {'closing'} */('closing'),
|
||||||
CLOSED: 'closed'
|
CLOSED: /** @type {'closed'} */('closed')
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ exports.SignaturePolicy = {
|
|||||||
* * Enforce the fields to be present, reject otherwise.
|
* * Enforce the fields to be present, reject otherwise.
|
||||||
* * Propagate only if the fields are valid and signature can be verified, 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:
|
* On the producing side:
|
||||||
* * Build messages without the signature, key, from and seqno fields.
|
* * 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.
|
* * 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.
|
* * 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.
|
* Make everything an array.
|
||||||
*
|
*
|
||||||
* @param {any} maybeArray
|
* @template T
|
||||||
* @returns {Array}
|
* @param {T|T[]} maybeArray
|
||||||
|
* @returns {T[]}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
exports.ensureArray = (maybeArray) => {
|
exports.ensureArray = (maybeArray) => {
|
||||||
@ -85,9 +86,11 @@ exports.ensureArray = (maybeArray) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures `message.from` is base58 encoded
|
* Ensures `message.from` is base58 encoded
|
||||||
* @param {object} message
|
*
|
||||||
* @param {String} peerId
|
* @template {Object} T
|
||||||
* @return {object}
|
* @param {T} message
|
||||||
|
* @param {string} [peerId]
|
||||||
|
* @return {T & {from?: string, peerId?: string }}
|
||||||
*/
|
*/
|
||||||
exports.normalizeInRpcMessage = (message, peerId) => {
|
exports.normalizeInRpcMessage = (message, peerId) => {
|
||||||
const m = Object.assign({}, message)
|
const m = Object.assign({}, message)
|
||||||
@ -101,8 +104,10 @@ exports.normalizeInRpcMessage = (message, peerId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} message
|
* @template {Object} T
|
||||||
* @return {object}
|
*
|
||||||
|
* @param {T} message
|
||||||
|
* @return {T & {from?: Uint8Array, data?: Uint8Array}}
|
||||||
*/
|
*/
|
||||||
exports.normalizeOutRpcMessage = (message) => {
|
exports.normalizeOutRpcMessage = (message) => {
|
||||||
const m = Object.assign({}, message)
|
const m = Object.assign({}, message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user