Skip to content

Commit

Permalink
chore: add typescript pr types
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Aug 2, 2023
1 parent 4a8470d commit 0ead76d
Show file tree
Hide file tree
Showing 27 changed files with 329 additions and 611 deletions.
19 changes: 11 additions & 8 deletions diff-types1/base-x.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

export interface BaseConverter {
encode(buffer: Uint8Array | number[]): string;
decodeUnsafe(string: string): Uint8Array | undefined;
decode(string: string): Uint8Array;
}

export default function base(ALPHABET: string, name: string): BaseConverter
export default _brrp__multiformats_scope_baseX;
/**
* @param {string} ALPHABET
* @param {any} name
*/
declare function _brrp__multiformats_scope_baseX(ALPHABET: string, name: any): {
encode: (source: any[] | Iterable<number>) => string;
decodeUnsafe: (source: string | string[]) => Uint8Array | undefined;
decode: (string: string | string[]) => Uint8Array;
};
//# sourceMappingURL=base-x.d.ts.map
188 changes: 57 additions & 131 deletions diff-types1/base.d.ts
Original file line number Diff line number Diff line change
@@ -1,148 +1,74 @@
export function or<L extends string, R extends string>(left: API.UnibaseDecoder<L> | API.CombobaseDecoder<L>, right: API.UnibaseDecoder<R> | API.CombobaseDecoder<R>): ComposedDecoder<L | R>;
/**
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseCodec<Prefix>}
* @implements {API.MultibaseEncoder<Prefix>}
* @implements {API.MultibaseDecoder<Prefix>}
* @implements {API.BaseCodec}
* @implements {API.BaseEncoder}
* @implements {API.BaseDecoder}
*/
export class Codec<Base extends string, Prefix extends string> implements API.MultibaseCodec<Prefix>, API.MultibaseEncoder<Prefix>, API.MultibaseDecoder<Prefix>, API.BaseCodec, API.BaseEncoder, API.BaseDecoder {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(bytes:Uint8Array) => string} baseEncode
* @param {(text:string) => Uint8Array} baseDecode
*/
constructor(name: Base, prefix: Prefix, baseEncode: (bytes: Uint8Array) => string, baseDecode: (text: string) => Uint8Array);
name: Base;
prefix: Prefix;
baseEncode: (bytes: Uint8Array) => string;
baseDecode: (text: string) => Uint8Array;
encoder: Encoder<Base, Prefix>;
decoder: Decoder<Base, Prefix>;
/**
* @param {Uint8Array} input
*/
encode(input: Uint8Array): API.Multibase<Prefix>;
/**
* @param {string} input
*/
decode(input: string): Uint8Array;
import type { BaseCodec, BaseDecoder, BaseEncoder, CombobaseDecoder, Multibase, MultibaseCodec, MultibaseDecoder, MultibaseEncoder, UnibaseDecoder } from './interface.js';
interface EncodeFn {
(bytes: Uint8Array): string;
}
export function from<Base extends string, Prefix extends string>({ name, prefix, encode, decode }: {
name: Base;
prefix: Prefix;
encode: (bytes: Uint8Array) => string;
decode: (input: string) => Uint8Array;
}): Codec<Base, Prefix>;
export function baseX<Base extends string, Prefix extends string>({ prefix, name, alphabet }: {
name: Base;
prefix: Prefix;
alphabet: string;
}): Codec<Base, Prefix>;
export function rfc4648<Base extends string, Prefix extends string>({ name, prefix, bitsPerChar, alphabet }: {
name: Base;
prefix: Prefix;
alphabet: string;
bitsPerChar: number;
}): Codec<Base, Prefix>;
export type Decoders<Prefix extends string> = Record<Prefix, API.UnibaseDecoder<Prefix>>;
import * as API from "./interface.js";
/**
* @template {string} Prefix
* @typedef {Record<Prefix, API.UnibaseDecoder<Prefix>>} Decoders
*/
/**
* @template {string} Prefix
* @implements {API.MultibaseDecoder<Prefix>}
* @implements {API.CombobaseDecoder<Prefix>}
*/
declare class ComposedDecoder<Prefix extends string> implements API.MultibaseDecoder<Prefix>, API.CombobaseDecoder<Prefix> {
/**
* @param {Decoders<Prefix>} decoders
*/
constructor(decoders: Decoders<Prefix>);
decoders: Decoders<Prefix>;
/**
* @template {string} OtherPrefix
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
*/
or<OtherPrefix extends string>(decoder: API.UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
/**
* @param {string} input
* @returns {Uint8Array}
*/
decode(input: string): Uint8Array;
interface DecodeFn {
(text: string): Uint8Array;
}
/**
* Class represents both BaseEncoder and MultibaseEncoder meaning it
* can be used to encode to multibase or base encode without multibase
* prefix.
*
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseEncoder<Prefix>}
* @implements {API.BaseEncoder}
*/
declare class Encoder<Base extends string, Prefix extends string> implements API.MultibaseEncoder<Prefix>, API.BaseEncoder {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(bytes:Uint8Array) => string} baseEncode
*/
constructor(name: Base, prefix: Prefix, baseEncode: (bytes: Uint8Array) => string);
name: Base;
prefix: Prefix;
baseEncode: (bytes: Uint8Array) => string;
/**
* @param {Uint8Array} bytes
* @returns {API.Multibase<Prefix>}
*/
encode(bytes: Uint8Array): API.Multibase<Prefix>;
declare class Encoder<Base extends string, Prefix extends string> implements MultibaseEncoder<Prefix>, BaseEncoder {
readonly name: Base;
readonly prefix: Prefix;
readonly baseEncode: EncodeFn;
constructor(name: Base, prefix: Prefix, baseEncode: EncodeFn);
encode(bytes: Uint8Array): Multibase<Prefix>;
}
/**
* @template {string} Prefix
*/
/**
* Class represents both BaseDecoder and MultibaseDecoder so it could be used
* to decode multibases (with matching prefix) or just base decode strings
* with corresponding base encoding.
*
* @class
* @template {string} Base
* @template {string} Prefix
* @implements {API.MultibaseDecoder<Prefix>}
* @implements {API.UnibaseDecoder<Prefix>}
* @implements {API.BaseDecoder}
*/
declare class Decoder<Base extends string, Prefix extends string> implements API.MultibaseDecoder<Prefix>, API.UnibaseDecoder<Prefix>, API.BaseDecoder {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(text:string) => Uint8Array} baseDecode
*/
constructor(name: Base, prefix: Prefix, baseDecode: (text: string) => Uint8Array);
name: Base;
prefix: Prefix;
/** @private */
private prefixCodePoint;
baseDecode: (text: string) => Uint8Array;
/**
* @param {string} text
*/
declare class Decoder<Base extends string, Prefix extends string> implements MultibaseDecoder<Prefix>, UnibaseDecoder<Prefix>, BaseDecoder {
readonly name: Base;
readonly prefix: Prefix;
readonly baseDecode: DecodeFn;
private readonly prefixCodePoint;
constructor(name: Base, prefix: Prefix, baseDecode: DecodeFn);
decode(text: string): Uint8Array;
/**
* @template {string} OtherPrefix
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
*/
or<OtherPrefix extends string>(decoder: API.UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
or<OtherPrefix extends string>(decoder: UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
}
type Decoders<Prefix extends string> = Record<Prefix, UnibaseDecoder<Prefix>>;
declare class ComposedDecoder<Prefix extends string> implements MultibaseDecoder<Prefix>, CombobaseDecoder<Prefix> {
readonly decoders: Decoders<Prefix>;
constructor(decoders: Decoders<Prefix>);
or<OtherPrefix extends string>(decoder: UnibaseDecoder<OtherPrefix> | ComposedDecoder<OtherPrefix>): ComposedDecoder<Prefix | OtherPrefix>;
decode(input: string): Uint8Array;
}
export declare function or<L extends string, R extends string>(left: UnibaseDecoder<L> | CombobaseDecoder<L>, right: UnibaseDecoder<R> | CombobaseDecoder<R>): ComposedDecoder<L | R>;
export declare class Codec<Base extends string, Prefix extends string> implements MultibaseCodec<Prefix>, MultibaseEncoder<Prefix>, MultibaseDecoder<Prefix>, BaseCodec, BaseEncoder, BaseDecoder {
readonly name: Base;
readonly prefix: Prefix;
readonly baseEncode: EncodeFn;
readonly baseDecode: DecodeFn;
readonly encoder: Encoder<Base, Prefix>;
readonly decoder: Decoder<Base, Prefix>;
constructor(name: Base, prefix: Prefix, baseEncode: EncodeFn, baseDecode: DecodeFn);
encode(input: Uint8Array): string;
decode(input: string): Uint8Array;
}
export declare function from<Base extends string, Prefix extends string>({ name, prefix, encode, decode }: {
name: Base;
prefix: Prefix;
encode: EncodeFn;
decode: DecodeFn;
}): Codec<Base, Prefix>;
export declare function baseX<Base extends string, Prefix extends string>({ name, prefix, alphabet }: {
name: Base;
prefix: Prefix;
alphabet: string;
}): Codec<Base, Prefix>;
/**
* RFC4648 Factory
*/
export declare function rfc4648<Base extends string, Prefix extends string>({ name, prefix, bitsPerChar, alphabet }: {
name: Base;
prefix: Prefix;
bitsPerChar: number;
alphabet: string;
}): Codec<Base, Prefix>;
export {};
//# sourceMappingURL=base.d.ts.map
2 changes: 1 addition & 1 deletion diff-types1/base10.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const base10: import("./base.js").Codec<"base10", "9">;
export declare const base10: import("./base.js").Codec<"base10", "9">;
//# sourceMappingURL=base10.d.ts.map
4 changes: 2 additions & 2 deletions diff-types1/base16.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const base16: import("./base.js").Codec<"base16", "f">;
export const base16upper: import("./base.js").Codec<"base16upper", "F">;
export declare const base16: import("./base.js").Codec<"base16", "f">;
export declare const base16upper: import("./base.js").Codec<"base16upper", "F">;
//# sourceMappingURL=base16.d.ts.map
2 changes: 1 addition & 1 deletion diff-types1/base2.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const base2: import("./base.js").Codec<"base2", "0">;
export declare const base2: import("./base.js").Codec<"base2", "0">;
//# sourceMappingURL=base2.d.ts.map
2 changes: 1 addition & 1 deletion diff-types1/base256emoji.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const base256emoji: import("./base.js").Codec<"base256emoji", "🚀">;
export declare const base256emoji: import("./base.js").Codec<"base256emoji", "🚀">;
//# sourceMappingURL=base256emoji.d.ts.map
18 changes: 9 additions & 9 deletions diff-types1/base32.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const base32: import("./base.js").Codec<"base32", "b">;
export const base32upper: import("./base.js").Codec<"base32upper", "B">;
export const base32pad: import("./base.js").Codec<"base32pad", "c">;
export const base32padupper: import("./base.js").Codec<"base32padupper", "C">;
export const base32hex: import("./base.js").Codec<"base32hex", "v">;
export const base32hexupper: import("./base.js").Codec<"base32hexupper", "V">;
export const base32hexpad: import("./base.js").Codec<"base32hexpad", "t">;
export const base32hexpadupper: import("./base.js").Codec<"base32hexpadupper", "T">;
export const base32z: import("./base.js").Codec<"base32z", "h">;
export declare const base32: import("./base.js").Codec<"base32", "b">;
export declare const base32upper: import("./base.js").Codec<"base32upper", "B">;
export declare const base32pad: import("./base.js").Codec<"base32pad", "c">;
export declare const base32padupper: import("./base.js").Codec<"base32padupper", "C">;
export declare const base32hex: import("./base.js").Codec<"base32hex", "v">;
export declare const base32hexupper: import("./base.js").Codec<"base32hexupper", "V">;
export declare const base32hexpad: import("./base.js").Codec<"base32hexpad", "t">;
export declare const base32hexpadupper: import("./base.js").Codec<"base32hexpadupper", "T">;
export declare const base32z: import("./base.js").Codec<"base32z", "h">;
//# sourceMappingURL=base32.d.ts.map
4 changes: 2 additions & 2 deletions diff-types1/base36.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const base36: import("./base.js").Codec<"base36", "k">;
export const base36upper: import("./base.js").Codec<"base36upper", "K">;
export declare const base36: import("./base.js").Codec<"base36", "k">;
export declare const base36upper: import("./base.js").Codec<"base36upper", "K">;
//# sourceMappingURL=base36.d.ts.map
4 changes: 2 additions & 2 deletions diff-types1/base58.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const base58btc: import("./base.js").Codec<"base58btc", "z">;
export const base58flickr: import("./base.js").Codec<"base58flickr", "Z">;
export declare const base58btc: import("./base.js").Codec<"base58btc", "z">;
export declare const base58flickr: import("./base.js").Codec<"base58flickr", "Z">;
//# sourceMappingURL=base58.d.ts.map
8 changes: 4 additions & 4 deletions diff-types1/base64.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const base64: import("./base.js").Codec<"base64", "m">;
export const base64pad: import("./base.js").Codec<"base64pad", "M">;
export const base64url: import("./base.js").Codec<"base64url", "u">;
export const base64urlpad: import("./base.js").Codec<"base64urlpad", "U">;
export declare const base64: import("./base.js").Codec<"base64", "m">;
export declare const base64pad: import("./base.js").Codec<"base64pad", "M">;
export declare const base64url: import("./base.js").Codec<"base64url", "u">;
export declare const base64urlpad: import("./base.js").Codec<"base64urlpad", "U">;
//# sourceMappingURL=base64.d.ts.map
2 changes: 1 addition & 1 deletion diff-types1/base8.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const base8: import("./base.js").Codec<"base8", "7">;
export declare const base8: import("./base.js").Codec<"base8", "7">;
//# sourceMappingURL=base8.d.ts.map
42 changes: 19 additions & 23 deletions diff-types1/basics.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { CID } from "./index.js";
import { hasher } from "./index.js";
import { digest } from "./index.js";
import { varint } from "./index.js";
import { bytes } from "./index.js";
export const hashes: {
identity: {
code: number;
name: string;
encode: (input: Uint8Array) => Uint8Array;
digest: (input: Uint8Array) => digest.Digest<0, number>;
};
sha256: hasher.Hasher<"sha2-256", 18>;
sha512: hasher.Hasher<"sha2-512", 19>;
};
export const bases: {
import * as raw from './codecs/raw.js';
import * as json from './codecs/json.js';
import { CID, hasher, digest, varint, bytes } from './index.js';
declare const bases: {
base256emoji: import("./bases/base.js").Codec<"base256emoji", "🚀">;
base64: import("./bases/base.js").Codec<"base64", "m">;
base64pad: import("./bases/base.js").Codec<"base64pad", "M">;
Expand All @@ -39,11 +27,19 @@ export const bases: {
base2: import("./bases/base.js").Codec<"base2", "0">;
identity: import("./bases/base.js").Codec<"identity", "\0">;
};
export namespace codecs {
export { raw };
export { json };
}
import * as raw from "./codecs/raw.js";
import * as json from "./codecs/json.js";
export { CID, hasher, digest, varint, bytes };
declare const hashes: {
identity: {
code: number;
name: string;
encode: (input: Uint8Array) => Uint8Array;
digest: (input: Uint8Array) => digest.Digest<0, number>;
};
sha256: hasher.Hasher<"sha2-256", 18>;
sha512: hasher.Hasher<"sha2-512", 19>;
};
declare const codecs: {
raw: typeof raw;
json: typeof json;
};
export { CID, hasher, digest, varint, bytes, hashes, bases, codecs };
//# sourceMappingURL=basics.d.ts.map
Loading

0 comments on commit 0ead76d

Please sign in to comment.