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

Event log #290

Merged
merged 24 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ae0eaa
implement `EventLog`
mistermoe Mar 31, 2023
085e0c9
make iterator options optional. this matches levels api for
mistermoe Mar 31, 2023
f57a161
address PR comments
mistermoe Apr 3, 2023
9ad3c30
address PR comments
mistermoe Apr 3, 2023
d76748e
prevent computing message cid twice
mistermoe Apr 3, 2023
66f5623
adjust test based on PR comment
mistermoe Apr 3, 2023
1f9f08a
remove tenant encoding
mistermoe Apr 3, 2023
d0c1e26
improve test based on PR comment
mistermoe Apr 4, 2023
a267bac
add `dump` to `eventLogLevel`
mistermoe Apr 4, 2023
902d7ba
add `deleteEventsByCid`. refactor `getEventsAfter` method signature
mistermoe Apr 5, 2023
513ab06
add missing types to method signature and include method in interface
mistermoe Apr 5, 2023
74a91ab
delete events whenever intermediary `RecordsWrite`s are deleted
mistermoe Apr 5, 2023
eb7f697
fix comment placement
mistermoe Apr 5, 2023
758a47f
Merge branch 'main' into event-log
mistermoe Apr 5, 2023
946b57a
fix merge related issues
mistermoe Apr 5, 2023
8d18971
fix import order
mistermoe Apr 5, 2023
f44f90d
add functional tests
mistermoe Apr 6, 2023
4527355
remove duplicate code
mistermoe Apr 6, 2023
c17f6d5
add jsdoc
mistermoe Apr 6, 2023
e1643a0
delete older ProtocolsConfigure event when one is overwritten
mistermoe Apr 6, 2023
6674e2a
Merge branch 'main' into event-log
mistermoe Apr 6, 2023
6625b71
strict mode :sob:
mistermoe Apr 6, 2023
7b5be72
store events in watermark order and cid order
mistermoe Apr 8, 2023
a17156b
Merge remote-tracking branch 'origin' into event-log
mistermoe Apr 8, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ try.js
# default location for levelDB data storage in a non-browser env
MESSAGESTORE
DATASTORE
EVENTLOG
# location for levelDB data storage for non-browser tests
TEST-DATASTORE
TEST-MESSAGESTORE
TEST-EVENTLOG

# default location for index specific levelDB data storage in a non-browser env
INDEX
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Decentralized Web Node (DWN) SDK

Code Coverage
![Statements](https://img.shields.io/badge/statements-93.84%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-92.39%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-91.01%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-93.84%25-brightgreen.svg?style=flat)
![Statements](https://img.shields.io/badge/statements-93.05%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-92.58%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-90.63%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-93.05%25-brightgreen.svg?style=flat)

## Introduction

Expand Down
99 changes: 65 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@js-temporal/polyfill": "0.4.3",
"@noble/ed25519": "1.7.1",
"@noble/secp256k1": "1.7.1",
"@scure/base": "1.1.1",
"@swc/helpers": "0.3.8",
"@types/eccrypto": "1.1.3",
"@types/ms": "0.7.31",
Expand All @@ -76,6 +77,7 @@
"multiformats": "11.0.2",
"randombytes": "2.1.0",
"readable-stream": "4.3.0",
"ulid": "2.3.0",
"secp256k1": "5.0.0",
"uuid": "8.3.2",
"varint": "6.0.0"
Expand Down
26 changes: 20 additions & 6 deletions src/dwn.ts
diehuxx marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BaseMessage } from './core/types.js';
import type { DataStore } from './store/data-store.js';
import type { EventLog } from './event-log/event-log.js';
import type { MessageStore } from './store/message-store.js';
import type { MethodHandler } from './interfaces/types.js';
import type { Readable } from 'readable-stream';
Expand All @@ -8,6 +9,7 @@ import type { TenantGate } from './core/tenant-gate.js';
import { AllowAllTenantGate } from './core/tenant-gate.js';
import { DataStoreLevel } from './store/data-store-level.js';
import { DidResolver } from './did/did-resolver.js';
import { EventLogLevel } from './event-log/event-log-level.js';
import { MessageReply } from './core/message-reply.js';
import { MessageStoreLevel } from './store/message-store-level.js';
import { PermissionsRequestHandler } from './interfaces/permissions/handlers/permissions-request.js';
Expand All @@ -24,22 +26,26 @@ export class Dwn {
private didResolver: DidResolver;
private messageStore: MessageStore;
private dataStore: DataStore;
private eventLog: EventLog;
private tenantGate: TenantGate;

private constructor(config: DwnConfig) {
this.didResolver = config.didResolver!;
this.messageStore = config.messageStore!;
this.dataStore = config.dataStore!;
this.eventLog = config.eventLog!;
this.tenantGate = config.tenantGate!;

this.methodHandlers = {
[DwnInterfaceName.Permissions + DwnMethodName.Request] : new PermissionsRequestHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Protocols + DwnMethodName.Configure] : new ProtocolsConfigureHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Protocols + DwnMethodName.Query] : new ProtocolsQueryHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Delete] : new RecordsDeleteHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Query] : new RecordsQueryHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Read] : new RecordsReadHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Write] : new RecordsWriteHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Protocols + DwnMethodName.Configure] : new ProtocolsConfigureHandler(
this.didResolver, this.messageStore, this.dataStore, this.eventLog),
[DwnInterfaceName.Protocols + DwnMethodName.Query] : new ProtocolsQueryHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Delete] : new RecordsDeleteHandler(
this.didResolver, this.messageStore, this.dataStore, this.eventLog),
[DwnInterfaceName.Records + DwnMethodName.Query] : new RecordsQueryHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Read] : new RecordsReadHandler(this.didResolver, this.messageStore, this.dataStore),
[DwnInterfaceName.Records + DwnMethodName.Write] : new RecordsWriteHandler(this.didResolver, this.messageStore, this.dataStore, this.eventLog),
};
}

Expand All @@ -52,6 +58,7 @@ export class Dwn {
config.tenantGate ??= new AllowAllTenantGate();
config.messageStore ??= new MessageStoreLevel();
config.dataStore ??= new DataStoreLevel();
config.eventLog ??= new EventLogLevel();

const dwn = new Dwn(config);
await dwn.open();
Expand All @@ -62,11 +69,13 @@ export class Dwn {
private async open(): Promise<void> {
await this.messageStore.open();
await this.dataStore.open();
await this.eventLog.open();
}

public async close(): Promise<void> {
this.messageStore.close();
this.dataStore.close();
this.eventLog.close();
}

/**
Expand Down Expand Up @@ -119,6 +128,10 @@ export class Dwn {
// @ts-ignore
await this.dataStore['dump']?.();
console.groupEnd();

console.group('eventLog');
await this.eventLog['dump']?.();
console.groupEnd();
}
};

Expand All @@ -127,4 +140,5 @@ export type DwnConfig = {
messageStore?: MessageStore;
dataStore?: DataStore;
tenantGate?: TenantGate;
eventLog?: EventLog
};
Loading