Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix syncmanager typedefs to use abstractlevel #309

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/agent/src/sync-manager.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thiink the desired convention for imports from top to bottom in this repo (though i'm sure there's evidence of the contrary in a few places bc of time constraints) is:

  • all import types first
  • then all imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably run a formatter that does this in the future. Although past experience has been that import sorting is always a fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
Loading