Skip to content

Commit

Permalink
types: fix syncmanager typedefs to use abstractlevel (#309)
Browse files Browse the repository at this point in the history
* fix syncmanager to use abstractlevel

* fix type

* organize imports
  • Loading branch information
shamilovtim authored Nov 28, 2023
1 parent 590a5fc commit 34b915d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/agent/src/sync-manager.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
Expand All @@ -24,10 +21,12 @@ export interface SyncManager {
pull(): Promise<void>;
}

type LevelDatabase = AbstractLevel<string | Buffer | Uint8Array, string, string>;

export type SyncManagerOptions = {
agent?: Web5ManagedAgent;
dataPath?: string;
db?: Level;
db?: LevelDatabase;
};

type SyncDirection = 'push' | 'pull';
Expand All @@ -43,7 +42,7 @@ type DwnMessage = {
data?: Blob;
}

type DbBatchOperation = BatchOperation<Level, string, string>;
type DbBatchOperation = AbstractBatchOperation<LevelDatabase, string, string>;

const is2xx = (code: number) => code >= 200 && code <= 299;
const is4xx = (code: number) => code >= 400 && code <= 499;
Expand All @@ -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<typeof setInterval>;

constructor(options?: SyncManagerOptions) {
Expand Down

0 comments on commit 34b915d

Please sign in to comment.