Closed
Description
Given #213 #212 #208 and #211 I would like to propose trimming down Link
interface to bare minimum where it acts like Model and introduce another interface e.g. LinkView
(can call whatever) that extends Link
with bunch of methods:
export interface Link<
Data extends unknown = unknown,
Format extends number = number,
Alg extends number = number,
V extends Version = 1
> extends Phantom<Data> {
readonly version: V
readonly code: Format
readonly multihash: MultihashDigest<Alg>
readonly bytes: ByteView<Link<Data, Format, Alg, V>>
readonly ['/']: this['bytes']
}
export interface LinkView<
Data extends unknown = unknown,
Format extends number = number,
Alg extends number = number,
V extends Version = 1
> extends Link<Data, Format, Alg> {
equals: (other: unknown) => other is Link<Data, Format, Alg, Version>
toString: <Prefix extends string>(base?: MultibaseEncoder<Prefix>) => ToString<Link<Data, Format, Alg, Version>, Prefix>
toJSON: () => { version: V, code: Format, hash: Uint8Array }
link: () => Link<Data, Format, Alg, V>
toV1: () => Link<Data, Format, Alg, 1>
}
Note I have removed following entirely
js-multiformats/src/link/interface.ts
Lines 31 to 32 in 0ec751a
Idea here would be that CID
class will implement both interfaces, but all the stuff on LinkView
will be implemented using CID.prototype
which should ensure that value equality will hold.
This also would imply that isLink
would become something like this:
const isLink = (value:unknown): value is Link => value && value['/'] === value.bytes
Metadata
Metadata
Assignees
Labels
No labels