From c7ffda1ca635d2132cd7bc82f42e230cdb13d729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20Ribo=CC=81=20Labrador?= Date: Mon, 15 Jan 2024 18:41:47 +0100 Subject: [PATCH] fix: add better documentation on the database project. --- packages/database/README.md | 60 +++++++++++++++++++++++++++++++--- packages/database/src/index.ts | 2 -- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/packages/database/README.md b/packages/database/README.md index a579d2b1..ce030e09 100644 --- a/packages/database/README.md +++ b/packages/database/README.md @@ -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(); @@ -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(); diff --git a/packages/database/src/index.ts b/packages/database/src/index.ts index 09f06b3e..f20fc656 100644 --- a/packages/database/src/index.ts +++ b/packages/database/src/index.ts @@ -97,8 +97,6 @@ export const Database = { }, new Map()); - - const proxy = new Proxy & UnionToIntersection>>(instance as any, {