From a79ca7ce0bdd9027d27bdabe5e10e262d995c624 Mon Sep 17 00:00:00 2001 From: Timothy Shamilov Date: Tue, 28 Nov 2023 17:38:44 -0500 Subject: [PATCH] types: fix syncmanager typedefs to use abstractlevel (#309) * fix syncmanager to use abstractlevel * fix type * organize imports --- packages/agent/src/sync-manager.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/agent/src/sync-manager.ts b/packages/agent/src/sync-manager.ts index a6f3ea230..4d1e8d8b6 100644 --- a/packages/agent/src/sync-manager.ts +++ b/packages/agent/src/sync-manager.ts @@ -1,20 +1,17 @@ -import type { BatchOperation } from 'level'; +import { DataStream } from '@tbd54566975/dwn-sdk-js'; +import { Convert } from '@web5/common'; +import { utils as didUtils } from '@web5/dids'; +import { Level } from 'level'; +import { webReadableToIsomorphicNodeReadable } from './utils.js'; import type { EventsGetReply, GenericMessage, MessagesGetReply, RecordsWriteMessage, } from '@tbd54566975/dwn-sdk-js'; - -import { Level } from 'level'; -import { Convert } from '@web5/common'; -import { utils as didUtils } from '@web5/dids'; -import { DataStream } from '@tbd54566975/dwn-sdk-js'; - +import type { AbstractBatchOperation, AbstractLevel } from 'abstract-level'; import type { Web5ManagedAgent } from './types/agent.js'; -import { webReadableToIsomorphicNodeReadable } from './utils.js'; - export interface SyncManager { agent: Web5ManagedAgent; registerIdentity(options: { did: string }): Promise; @@ -24,10 +21,12 @@ export interface SyncManager { pull(): Promise; } +type LevelDatabase = AbstractLevel; + export type SyncManagerOptions = { agent?: Web5ManagedAgent; dataPath?: string; - db?: Level; + db?: LevelDatabase; }; type SyncDirection = 'push' | 'pull'; @@ -43,7 +42,7 @@ type DwnMessage = { data?: Blob; } -type DbBatchOperation = BatchOperation; +type DbBatchOperation = AbstractBatchOperation; const is2xx = (code: number) => code >= 200 && code <= 299; const is4xx = (code: number) => code >= 400 && code <= 499; @@ -57,7 +56,7 @@ export class SyncManagerLevel implements SyncManager { * operations within the broader Web5 agent framework. */ private _agent?: Web5ManagedAgent; - private _db: Level; + private _db: LevelDatabase; private _syncIntervalId?: ReturnType; constructor(options?: SyncManagerOptions) {