From 1cf9740ca98ee6298bb28babebf19f14e75a623b Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Thu, 4 Apr 2019 12:16:02 -0700 Subject: [PATCH] feat: add flow typedefs Add flow type definitions which would improve workflow for dependent libraries that happen to use flow type-checker. --- .flowconfig | 11 +++++++++++ src/index.js.flow | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .flowconfig create mode 100644 src/index.js.flow diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..1fed445 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,11 @@ +[ignore] + +[include] + +[libs] + +[lints] + +[options] + +[strict] diff --git a/src/index.js.flow b/src/index.js.flow new file mode 100644 index 0000000..4216deb --- /dev/null +++ b/src/index.js.flow @@ -0,0 +1,32 @@ +// @flow strict + +export type Version = 0 | 1 +export type Codec = string +export type Multihash = Buffer +export type BaseEncodedString = string + +declare class CID { + constructor(Version, Codec, Multihash): void; + constructor(BaseEncodedString): void; + constructor(Buffer): void; + + +codec: Codec; + +multihash: Multihash; + +buffer: Buffer; + +prefix: Buffer; + + toV0(): CID; + toV1(): CID; + toBaseEncodedString(base?: string): BaseEncodedString; + toString(): BaseEncodedString; + toJSON(): { codec: Codec, version: Version, hash: Multihash }; + + equals(mixed): boolean; + + static codecs: { [string]: Codec }; + static isCID(mixed): boolean; + static validateCID(mixed): void; +} + +export default CID +export type { CID }