diff --git a/src/codecs/codec.js b/src/codecs/codec.js index c1bd94aa..ae3059e4 100644 --- a/src/codecs/codec.js +++ b/src/codecs/codec.js @@ -1,16 +1,31 @@ // @ts-check +/** + * @template {number} Code + * @template T + * @typedef {import('./interface').BlockCodec} BlockCodec + */ +/** + * @template {number} Code + * @template T + * @typedef {import('./interface').BlockEncoder} BlockEncoder + */ +/** + * @template {number} Code + * @template T + * @typedef {import('./interface').BlockDecoder} BlockDecoder + */ + /** * @template {string} Name * @template {number} Code * @template T - * * @param {Object} options * @param {Name} options.name * @param {Code} options.code * @param {(data:T) => Uint8Array} options.encode * @param {(bytes:Uint8Array) => T} options.decode - * @returns {import('./interface').BlockCodec} + * @returns {BlockCodec & { encoder: BlockEncoder, decoder: BlockDecoder }} */ export const codec = ({ name, code, decode, encode }) => { const decoder = new Decoder(name, code, decode) @@ -19,12 +34,6 @@ export const codec = ({ name, code, decode, encode }) => { return { name, code, decode, encode, decoder, encoder } } -/** - * @template {number} Code - * @template T - * @typedef {import('./interface').BlockEncoder} BlockEncoder - */ - /** * @class * @template T @@ -45,12 +54,6 @@ export class Encoder { } } -/** - * @template {number} Code - * @template T - * @typedef {import('./interface').BlockDecoder} BlockDecoder - */ - /** * @class * @template {number} Code diff --git a/src/codecs/interface.ts b/src/codecs/interface.ts index e7a98b52..e6cb6564 100644 --- a/src/codecs/interface.ts +++ b/src/codecs/interface.ts @@ -20,14 +20,11 @@ export interface BlockDecoder { * separate those capabilties as sender requires encoder and receiver * requires decoder. */ -export interface BlockCodec extends BlockEncoder, BlockDecoder { - encoder: BlockEncoder, - decoder: BlockDecoder -} +export interface BlockCodec extends BlockEncoder, BlockDecoder {} -// This just a hack to retain type information abouth the data that -// is incoded `T` Because it's a union `data` field is never going +// This just a hack to retain type information about the data that +// is encoded `T` Because it's a union `data` field is never going // to be usable anyway. export type ByteView = | Uint8Array