Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-jb committed Dec 6, 2023
1 parent 745e949 commit 0900678
Show file tree
Hide file tree
Showing 69 changed files with 438 additions and 508 deletions.
11 changes: 5 additions & 6 deletions src/access/interface.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import type { Startable } from '@libp2p/interfaces/startable'

import type { EntryInstance } from '@/entry/interface.js'
import { HLDB_PREFIX } from '@/utils/constants.js'
import type { ComponentProtocol } from '@/interface.js'
import type { Manifest } from '@/manifest/index'
import type { Startable } from '@libp2p/interfaces/startable'
import { HLDB_PREFIX } from '@/utils/constants.js'

export interface AccessInstance extends Startable {
canAppend: (entry: EntryInstance<any>) => Promise<boolean>
close: () => Promise<void>
canAppend(entry: EntryInstance<any>): Promise<boolean>
close(): Promise<void>
}

export interface Open {
manifest: Manifest
}

export interface AccessComponent<T extends AccessInstance = AccessInstance, P extends string = string> extends ComponentProtocol<P> {
create: (config: Open) => T
create(config: Open): T
}

export const wildcard = '*'
Expand Down
8 changes: 3 additions & 5 deletions src/access/static/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { base32 } from 'multiformats/bases/base32'

import { Playable } from '@/utils/playable.js'
import { type Open, type AccessInstance, type AccessComponent, wildcard } from '../interface.js'
import protocol, { type Config } from './protocol.js'
import type { EntryInstance } from '@/entry/interface.js'
import type { Manifest } from '@/manifest/index.js'

import protocol, { type Config } from './protocol.js'
import { type Open, type AccessInstance, type AccessComponent, wildcard } from '../interface.js'
import { Playable } from '@/utils/playable.js'

// the Static in StaticAccess means the ACL is immutable and does not change
export class StaticAccess extends Playable implements AccessInstance {
Expand Down
3 changes: 1 addition & 2 deletions src/access/static/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Protocol } from '@/manifest/interface.js'

import { prefix } from '../interface.js'
import type { Protocol } from '@/manifest/interface.js'

const protocol = `${prefix}static` as const

Expand Down
22 changes: 10 additions & 12 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
import { start, stop } from '@libp2p/interfaces/startable'
import { NamespaceDatastore } from 'datastore-core'
import { Key } from 'interface-datastore'
import type { CID } from 'multiformats/cid'
import type { Datastore } from 'interface-datastore'

import { Playable } from '@/utils/playable.js'
import { Replica } from '@/replica/index.js'
import type { DbConfig, DbOpen, DbEvents, ClosedEmit, DbComponents } from './interface.js'
import type { AccessInstance } from '@/access/interface.js'
import type { IdentityInstance } from '@/identity/interface.js'
import type { Address } from '@/manifest/address.js'
import type { Manifest } from '@/manifest/index.js'
import type { AccessInstance } from '@/access/interface.js'
import type { Creator, Selector, StoreInstance } from '@/store/interface.js'
import type { Replicator } from '@/replicator/interface.js'
import type { Creator, Selector, StoreInstance } from '@/store/interface.js'
import type { Datastore } from 'interface-datastore'
import type { CID } from 'multiformats/cid'
import { Replica } from '@/replica/index.js'
import { STORE_NAMESPACE, REPLICA_NAMESPACE } from '@/utils/constants.js'

import type { DbConfig, DbOpen, DbEvents, ClosedEmit, DbComponents } from './interface.js'
import { Playable } from '@/utils/playable.js'

/**
* Database Class
Expand Down Expand Up @@ -72,7 +70,7 @@ export class Database extends Playable {
// todo: handle async action creators

interface CreatorProps {
value: (...args: any[]) => Promise<CID>
value(...args: any[]): Promise<CID>
}

const handleCreator = ([key, creator]: [string, Creator]): [
Expand All @@ -82,12 +80,12 @@ export class Database extends Playable {
key,
{
value: async (...args: any[]): Promise<CID> =>
await this.replica.write(creator(...args)).then((entry) => entry.cid)
this.replica.write(creator(...args)).then((entry) => entry.cid)
}
]

interface SelectorProps {
value: (...args: any[]) => Promise<any>
value(...args: any[]): Promise<any>
}

const handleSelector = ([key, selector]: [string, Selector]): [
Expand Down
10 changes: 4 additions & 6 deletions src/entry/basal/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import type { BlockView } from 'multiformats/interface'
import type { CID } from 'multiformats/cid'

import { encodeCbor, decodeCbor } from '@/utils/block.js'
import type { IdentityInstance } from '@/identity/interface.js'

import protocol from './protocol.js'
import type {
EntryData,
Expand All @@ -13,6 +7,10 @@ import type {
Fetch,
AsEntry
} from '../interface.js'
import type { IdentityInstance } from '@/identity/interface.js'
import type { CID } from 'multiformats/cid'
import type { BlockView } from 'multiformats/interface'
import { encodeCbor, decodeCbor } from '@/utils/block.js'

export interface SignedEntry {
auth: CID
Expand Down
2 changes: 1 addition & 1 deletion src/entry/basal/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Protocol } from '@/manifest/interface.js'
import { prefix } from '../interface.js'
import type { Protocol } from '@/manifest/interface.js'

const protocol = `${prefix}basal` as const

Expand Down
17 changes: 8 additions & 9 deletions src/entry/interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { BlockView } from 'multiformats/interface'
import type { CID } from 'multiformats/cid'

import { HLDB_PREFIX } from '@/utils/constants.js'
import type { ComponentProtocol } from '@/interface.js'
import type { IdentityInstance, IdentityComponent } from '@/identity/interface.js'
import type { ComponentProtocol } from '@/interface.js'
import type { Blockstore } from 'interface-blockstore'
import type { CID } from 'multiformats/cid'
import type { BlockView } from 'multiformats/interface'
import { HLDB_PREFIX } from '@/utils/constants.js'

export interface EntryData {
tag: Uint8Array
Expand Down Expand Up @@ -33,10 +32,10 @@ export interface Fetch {
export type AsEntry<Value> = Pick<EntryInstance<Value>, 'block' | 'identity'>

export interface EntryComponent<T extends EntryInstance<unknown> = EntryInstance<unknown>, P extends string = string> extends ComponentProtocol<P> {
create: (create: Create) => Promise<T>
fetch: (fetch: Fetch) => Promise<T>
asEntry: (entry: AsEntry<unknown>) => Promise<T | null>
verify: (entry: AsEntry<unknown>) => Promise<boolean>
create(create: Create): Promise<T>
fetch(fetch: Fetch): Promise<T>
asEntry(entry: AsEntry<unknown>): Promise<T | null>
verify(entry: AsEntry<unknown>): Promise<boolean>
}

export const prefix = `${HLDB_PREFIX}entry/` as const
17 changes: 8 additions & 9 deletions src/identity/basal/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as codec from '@ipld/dag-cbor'
import { keys } from '@libp2p/crypto'
import { Key } from 'interface-datastore'
import * as Block from 'multiformats/block'
import * as codec from '@ipld/dag-cbor'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import type { PrivateKey, PublicKey } from '@libp2p/interface/keys'
import { Key } from 'interface-datastore'
import type { BlockView } from 'multiformats/interface'
import type { CID } from 'multiformats/cid'

import protocol from './protocol.js'
import type {
IdentityInstance,
Expand All @@ -17,6 +13,9 @@ import type {
Get,
Import
} from '../interface.js'
import type { PrivateKey, PublicKey } from '@libp2p/interface/keys'
import type { CID } from 'multiformats/cid'
import type { BlockView } from 'multiformats/interface'
import { decodeCbor, encodeCbor } from '@/utils/block.js'

const secp256k1 = 'secp256k1'
Expand Down Expand Up @@ -83,11 +82,11 @@ export class Identity implements IdentityInstance<IdentityValue> {
}

async sign (data: Uint8Array): Promise<Uint8Array> {
return await sign(this, data)
return sign(this, data)
}

async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> {
return await verify(this, data, sig)
return verify(this, data, sig)
}
}

Expand Down Expand Up @@ -264,7 +263,7 @@ const verify = async (
throw new Error('invalid identity used')
}

return await _identity.pubkey.verify(data, sig)
return _identity.pubkey.verify(data, sig)
}

export const basalIdentity: () => IdentityComponent<Identity, typeof protocol> = () => ({
Expand Down
3 changes: 1 addition & 2 deletions src/identity/basal/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Protocol } from '@/manifest/interface.js'

import { prefix } from '../interface.js'
import type { Protocol } from '@/manifest/interface.js'

const protocol = `${prefix}basal` as const

Expand Down
33 changes: 16 additions & 17 deletions src/identity/interface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { ComponentProtocol } from '@/interface.js'
import type { Keychain } from '@libp2p/keychain'
import type { BlockView } from 'multiformats/interface'
import type { CID } from 'multiformats/cid'
import type { Blockstore } from 'interface-blockstore'
import type { Datastore } from 'interface-datastore'

import type { CID } from 'multiformats/cid'
import type { BlockView } from 'multiformats/interface'
import { HLDB_PREFIX } from '@/utils/constants.js'
import type { ComponentProtocol } from '@/interface.js'
import type { Blockstore } from 'interface-blockstore'

export type Gen = string

Expand Down Expand Up @@ -38,26 +37,26 @@ export interface IdentityInstance<Value> {
block: BlockView<Value>
readonly auth: CID
readonly id: Uint8Array
sign: (data: Uint8Array) => Promise<Uint8Array>
verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>
sign(data: Uint8Array): Promise<Uint8Array>
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>
}

export interface IdentityComponent<T extends IdentityInstance<unknown> = IdentityInstance<unknown>, P extends string = string> extends ComponentProtocol<P> {
gen: (gen: Gen) => Promise<T>
get: (get: Get) => Promise<T>
fetch: (fetch: Fetch) => Promise<T>
asIdentity: (asIdentity: AsIdentity<unknown>) => T | null
import: (imp: Import) => Promise<T>
export: (exp: Export) => Promise<Uint8Array>
sign: (
gen(gen: Gen): Promise<T>
get(get: Get): Promise<T>
fetch(fetch: Fetch): Promise<T>
asIdentity(asIdentity: AsIdentity<unknown>): T | null
import(imp: Import): Promise<T>
export(exp: Export): Promise<Uint8Array>
sign(
identity: AsIdentity<unknown>,
data: Uint8Array
) => Promise<Uint8Array>
verify: (
): Promise<Uint8Array>
verify(
identity: AsIdentity<unknown>,
data: Uint8Array,
sig: Uint8Array
) => Promise<boolean>
): Promise<boolean>
}

export const prefix = `${HLDB_PREFIX}identity/` as const
19 changes: 9 additions & 10 deletions src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import type { Helia } from '@helia/interface'
import type { Libp2p, ServiceMap } from '@libp2p/interface'
import type { PubSub } from '@libp2p/interface/pubsub'
import type { Datastore } from 'interface-datastore'
import type { Keychain } from '@libp2p/keychain'

import type { AccessInstance, AccessComponent } from '@/access/interface.js'
import type { AccessProtocol } from '@/access/static/protocol.js'
import type { EntryProtocol } from '@/entry/basal/protocol.js'
import type { EntryComponent } from '@/entry/interface.js'
import type { IdentityProtocol } from '@/identity/basal/protocol.js'
import type { IdentityInstance, IdentityComponent } from '@/identity/interface.js'
import type { StoreProtocol } from '@/store/keyvalue/protocol.js'
import type { Address, Manifest } from '@/manifest/index.js'
import type { AccessInstance, AccessComponent } from '@/access/interface.js'
import type { EntryComponent } from '@/entry/interface.js'
import type { StoreInstance, StoreComponent } from '@/store/interface'
import type { Replica } from '@/replica/index.js'
import type { Replicator, ReplicatorModule } from '@/replicator/interface'
import type { StoreInstance, StoreComponent } from '@/store/interface'
import type { StoreProtocol } from '@/store/keyvalue/protocol.js'
import type { Helia } from '@helia/interface'
import type { Libp2p, ServiceMap } from '@libp2p/interface'
import type { Ed25519PeerId } from '@libp2p/interface/peer-id'
import type { PubSub } from '@libp2p/interface/pubsub'
import type { Keychain } from '@libp2p/keychain'
import type { Blockstore } from 'interface-blockstore'
import type { Datastore } from 'interface-datastore'

export type GossipServiceMap = ServiceMap & { pubsub: PubSub, keychain: Keychain }
export type GossipLibp2p<T extends GossipServiceMap = GossipServiceMap> = Libp2p<T>
Expand Down
3 changes: 1 addition & 2 deletions src/manifest/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CID } from 'multiformats/cid'
import { base32 } from 'multiformats/bases/base32'

import { CID } from 'multiformats/cid'
import { HLDB_PREFIX as prefix } from '@/utils/constants.js'

const parse = function (address: Address | string): CID {
Expand Down
8 changes: 3 additions & 5 deletions src/manifest/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import type { BlockView } from 'multiformats/interface'

import { decodeCbor, encodeCbor } from '@/utils/block.js'
// import type { FetchOptions } from '@/utils/types.js'

import { Address } from './address.js'
import type {
AsManifest,
Expand All @@ -11,6 +6,9 @@ import type {
ManifestData,
Protocol
} from './interface.js'
import type { BlockView } from 'multiformats/interface'
import { decodeCbor, encodeCbor } from '@/utils/block.js'
// import type { FetchOptions } from '@/utils/types.js'

export { Address }

Expand Down
3 changes: 1 addition & 2 deletions src/manifest/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { BlockView } from 'multiformats/interface'

import type { Address } from './address.js'
import type { Blockstore } from 'interface-blockstore'
import type { BlockView } from 'multiformats/interface'

export interface Protocol<T extends string = string, C extends Record<string, unknown> = Record<string, unknown>> {
readonly protocol: T
Expand Down
6 changes: 2 additions & 4 deletions src/pubsub/direct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
import { getPeers, getTopics } from './util.js'
import type { GossipLibp2p } from '@/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type {
Expand All @@ -8,11 +9,8 @@ import type {
SignedMessage
} from '@libp2p/interface/pubsub'
import type { Startable } from '@libp2p/interfaces/startable'

import { peerIdString } from '@/utils/index.js'

import { getPeers, getTopics } from './util.js'

const prefix = '/dps/1.0.0/'

function sortAlphabetical (a: string, b: string): 1 | 0 | -1 {
Expand Down Expand Up @@ -121,7 +119,7 @@ export class Direct extends EventEmitter<DirectEvents> implements Startable {
throw new Error('direct pubsub not open')
}

return await this.libp2p.services.pubsub.publish(this.topic, bytes)
return this.libp2p.services.pubsub.publish(this.topic, bytes)
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/pubsub/monitor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
import { getPeers } from './util.js'
import type { GossipLibp2p } from '@/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { SubscriptionChangeData } from '@libp2p/interface/pubsub'
import type { Startable } from '@libp2p/interfaces/startable'
import type { PeerId } from '@libp2p/interface/peer-id'

import { parsedPeerId, peerIdString } from '@/utils/index.js'

import { getPeers } from './util.js'

export interface PeerStatusChangeData {
peerId: PeerId
}
Expand Down Expand Up @@ -88,12 +86,12 @@ function refreshPeers (
getPeers(this.libp2p.services.pubsub, this.topic).map(peerIdString)
)

const joins: Set<string> = new Set()
const joins = new Set<string>()
for (const peer of this.peers) {
!_peers.has(peer) && joins.add(peer)
}

const leaves: Set<string> = new Set()
const leaves = new Set<string>()
for (const peer of _peers) {
!this.peers.has(peer) && leaves.add(peer)
}
Expand Down
Loading

0 comments on commit 0900678

Please sign in to comment.