Skip to content

Commit

Permalink
fix: add better documentation on the database project.
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Jan 15, 2024
1 parent 19a06ae commit c7ffda1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
60 changes: 56 additions & 4 deletions packages/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,33 @@ Password is a 32 bytes buffer.
import { Database } from 'pluto-encrypted';
//You can use IndexDB any other storage that is compatible.
import IndexDB from "@pluto-encrypted/indexdb";
import {
getDefaultCollections,
DIDCollection,
DIDPairCollection,
MediatorCollection,
PrivateKeyColletion,
CredentialCollection,
CredentialRequestMetadataCollection,
LinkSecretColletion,
MessageColletion
} from "@pluto-encrypted/schemas";
const defaultPassword = new Uint8Array(32).fill(1);
const db = await Database.createEncrypted(
const db = await Database.createEncrypted<{
dids: DIDCollection;
didpairs: DIDPairCollection;
mediators: MediatorCollection;
privatekeys: PrivateKeyColletion;
credentials: CredentialCollection;
credentialrequestmetadatas: CredentialRequestMetadataCollection;
linksecrets: LinkSecretColletion;
messages: MessageColletion;
}>(
{
name: `my-db`,
encryptionKey: defaultPassword,
storage: IndexDB,
collections: getDefaultCollections()
}
);
const messages = await db.getAllMessages();
Expand All @@ -35,21 +56,52 @@ Backup database into an unencrypted JSON string and restore from backup.
import { Database } from 'pluto-encrypted';
//You can use IndexDB any other storage that is compatible.
import IndexDB from "@pluto-encrypted/indexdb";
import {
getDefaultCollections,
DIDCollection,
DIDPairCollection,
MediatorCollection,
PrivateKeyColletion,
CredentialCollection,
CredentialRequestMetadataCollection,
LinkSecretColletion,
MessageColletion
} from "@pluto-encrypted/schemas";
const defaultPassword = new Uint8Array(32).fill(1);
const db = await Database.createEncrypted(
const db = await Database.createEncrypted<{
dids: DIDCollection;
didpairs: DIDPairCollection;
mediators: MediatorCollection;
privatekeys: PrivateKeyColletion;
credentials: CredentialCollection;
credentialrequestmetadatas: CredentialRequestMetadataCollection;
linksecrets: LinkSecretColletion;
messages: MessageColletion;
}>(
{
name: "my-db",
encryptionKey: defaultPassword,
storage: IndexDB,
collections: getDefaultCollections()
}
);
const backup = await db.backup();
const restoredDatabase = await Database.createEncrypted(
const restoredDatabase = await Database.createEncrypted<{
dids: DIDCollection;
didpairs: DIDPairCollection;
mediators: MediatorCollection;
privatekeys: PrivateKeyColletion;
credentials: CredentialCollection;
credentialrequestmetadatas: CredentialRequestMetadataCollection;
linksecrets: LinkSecretColletion;
messages: MessageColletion;
}>(
{
name: "my-db",
encryptionKey: defaultPassword,
storage: IndexDB,
importData: backup
importData: backup,
collections: getDefaultCollections()
}
);
const messages = await restoredDatabase.getAllMessages();
Expand Down
2 changes: 0 additions & 2 deletions packages/database/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export const Database = {
}, new Map<string, Function>());




const proxy = new Proxy<DatabaseBase<Collections> & UnionToIntersection<ExtractStaticMethods<
Collections[keyof Collections]
>>>(instance as any, {
Expand Down

0 comments on commit c7ffda1

Please sign in to comment.