Skip to content

Commit 2a8021b

Browse files
committed
Improve types for Libp2p services
1 parent 74305be commit 2a8021b

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/index.d.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
declare module "@orbitdb/core" {
2-
import type { DefaultLibp2pServices, HeliaLibp2p } from "helia";
3-
import type { Libp2p } from "@libp2p/interface";
4-
import type { PeerId } from "@libp2p/interface";
2+
import type { HeliaLibp2p } from "helia";
3+
import type { Libp2p, PeerId, PrivateKey, ServiceMap } from "@libp2p/interface";
54
import type { TypedEmitter } from "tiny-typed-emitter";
6-
import type { PrivateKey } from "@libp2p/interface";
75
import type { ByteView, CID } from "multiformats";
86

97
export function createOrbitDB<
10-
T extends Libp2p = Libp2p<DefaultLibp2pServices>,
8+
T extends ServiceMap = ServiceMap,
119
>(args: {
12-
ipfs: HeliaLibp2p<T>;
10+
ipfs: HeliaLibp2p<Libp2p<T>>;
1311
id?: string;
1412
identity?: Identity;
1513
identities?: IdentitiesType;
@@ -38,9 +36,9 @@ declare module "@orbitdb/core" {
3836
referencesCount: number;
3937
}>;
4038

41-
type CreateDatabaseOptions<T extends Libp2p = Libp2p<DefaultLibp2pServices>> =
39+
type CreateDatabaseOptions<T extends ServiceMap = ServiceMap> =
4240
{
43-
ipfs: HeliaLibp2p<T>;
41+
ipfs: HeliaLibp2p<Libp2p<T>>;
4442
identity?: Identity;
4543
address: string;
4644
name?: string;
@@ -142,14 +140,14 @@ declare module "@orbitdb/core" {
142140
) => Promise<boolean>;
143141
};
144142

145-
export type OrbitDB<T extends Libp2p = Libp2p<DefaultLibp2pServices>> = {
143+
export type OrbitDB<T extends ServiceMap = ServiceMap> = {
146144
id: string;
147145
open: (
148146
address: string,
149147
options?: OpenDatabaseOptions,
150148
) => ReturnType<typeof Database>;
151149
stop: () => Promise<void>;
152-
ipfs: HeliaLibp2p<T>;
150+
ipfs: HeliaLibp2p<Libp2p<T>>;
153151
directory: string;
154152
keystore: KeyStoreType;
155153
identities: IdentitiesType;
@@ -255,12 +253,12 @@ declare module "@orbitdb/core" {
255253
>;
256254

257255
export function Identities<
258-
T extends Libp2p = Libp2p<DefaultLibp2pServices>,
256+
T extends ServiceMap = ServiceMap,
259257
>(args: {
260258
keystore?: KeyStoreType;
261259
path?: string;
262260
storage?: Storage;
263-
ipfs?: HeliaLibp2p<T>;
261+
ipfs?: HeliaLibp2p<Libp2p<T>>;
264262
}): Promise<{
265263
createIdentity: (options: object) => Promise<Identity>;
266264
getIdentity: (hash: string) => Promise<Identity>;
@@ -299,9 +297,9 @@ declare module "@orbitdb/core" {
299297
get: (hash: string) => Promise<ByteView<unknown>>;
300298
};
301299
export function IPFSBlockStorage<
302-
T extends Libp2p = Libp2p<DefaultLibp2pServices>,
300+
T extends ServiceMap = ServiceMap,
303301
>(args: {
304-
ipfs: HeliaLibp2p<T>;
302+
ipfs: HeliaLibp2p<Libp2p<T>>;
305303
pin?: boolean;
306304
timeout?: number;
307305
}): Promise<Storage>;

0 commit comments

Comments
 (0)