-
Notifications
You must be signed in to change notification settings - Fork 103
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
#244 - add a createLevelDatabase
to allow customizing the Level
used by BlockstoreLevel
#249
Conversation
4ea2a57
to
fad51ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested some minor changes but @mistermoe and @shamilovtim probably are best people to actually know if the abstraction is sufficient for them to instantiate a different level implementation.
70bb6e5
to
03fcdaa
Compare
createStore
to allow customizing the Level
used by BlockstoreLevel
createDatabase
to allow customizing the Level
used by BlockstoreLevel
I am going to try my best to review but one difficulty I'm going to have is that I can't actually pull this due to the (unrelated to PR) presence of |
d38fc19
to
f652e56
Compare
f652e56
to
e50a995
Compare
createDatabase
to allow customizing the Level
used by BlockstoreLevel
createLevelDatabase
to allow customizing the Level
used by BlockstoreLevel
tried it out using import type { LevelDatabase, LevelDatabaseOptions } from '../src/store/create-level';
import { MemoryLevel } from 'memory-level';
import { MessageStoreLevel } from '../src/store/message-store-level.js';
import { DataStream, DidKeyResolver, Dwn, RecordsQuery, RecordsWrite } from '../src/index.js';
const messageStore = new MessageStoreLevel({
createLevelDatabase<K, V>(_, options?: LevelDatabaseOptions<K, V>): LevelDatabase<K, V> {
return new MemoryLevel(options);
},
});
(async (): Promise<any> => {
const { did, keyPair } = await DidKeyResolver.generate();
const data = new TextEncoder().encode('data1');
const record = await RecordsWrite.create({
schema : 'test',
data : data,
dataFormat : 'application/json',
authorizationSignatureInput : {
privateJwk : keyPair.privateJwk,
protectedHeader : { alg: 'EdDSA', kid: DidKeyResolver.getKeyId(did) }
}
});
console.log(record.toJSON());
const dwn = await Dwn.create({ messageStore });
let result = await dwn.processMessage(did, record.toJSON(), DataStream.fromBytes(data));
console.log(result);
const query = await RecordsQuery.create({
filter: {
schema: 'test'
},
authorizationSignatureInput: {
privateJwk : keyPair.privateJwk,
protectedHeader : { alg: 'EdDSA', kid: DidKeyResolver.getKeyId(did) }
}
});
result = await dwn.processMessage(did, query.toJSON());
console.log(JSON.stringify(result, null, 2));
})(); |
…sed by `BlockstoreLevel` this will also be passed down when creating a `MessageStoreLevel` and `DataStoreLevel`
e50a995
to
7a93e18
Compare
i.e. if a developer provides their own `createLevelDatabase` then we will use that instead of `'level'` in order to support this for both node and browser, we need to switch to using dynamic `import` (instead of `require`, as that's not defined for node when `"type": "module"`) most of this commit is changing sync logic to `async` for that purpose
i.e. if a developer provides their own `createLevelDatabase` then we will use that instead of `'level'` in order to support this for both node and browser, we need to switch to using dynamic `import` (instead of `require`, as that's not defined for node when `"type": "module"`) most of this commit is changing sync logic to `async` for that purpose (though it also allows for more flexibility when providing a custom `createLevelDatabase`)
i.e. if a developer provides their own `createLevelDatabase` then we will use that instead of `'level'` in order to support this for both node and browser, we need to switch to using dynamic `import` (instead of `require`, as that's not defined for node when `"type": "module"`) most of this commit is changing sync logic to `async` for that purpose (though it also allows for more flexibility when providing a custom `createLevelDatabase`)
i.e. if a developer provides their own `createLevelDatabase` then we will use that instead of `'level'` in order to support this for both node and browser, we need to switch to using dynamic `import` (instead of `require`, as that's not defined for node when `"type": "module"`) most of this commit is changing sync logic to `async` for that purpose (though it also allows for more flexibility when providing a custom `createLevelDatabase`)
this will also be passed down when creating a
Dwn
,MessageStoreLevel
, andDataStoreLevel