Skip to content

Commit

Permalink
Merge pull request #2 from elribonazo/feature/improve-types
Browse files Browse the repository at this point in the history
fix: Improve types.
  • Loading branch information
elribonazo authored Sep 30, 2023
2 parents f6594d5 + ff9f728 commit d9adcd7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 42 deletions.
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Domain } from "@input-output-hk/atala-prism-wallet-sdk";
import type { Domain } from "@input-output-hk/atala-prism-wallet-sdk";
import { getRxStorageDexie } from "rxdb/plugins/storage-dexie";
import { wrappedKeyEncryptionCryptoJsStorage } from "rxdb/plugins/encryption-crypto-js";
import { createRxDatabase } from "rxdb";
Expand All @@ -8,14 +8,15 @@ import { RxDBMigrationPlugin } from "rxdb/plugins/migration";

import MessageSchema from "./schemas/Message";
import DIDSchema from "./schemas/DID";
import { PlutoDatabase } from "./types";
import { PlutoCollections, PlutoDatabase } from "./types";
import CredentialSchema from "./schemas/Credential";
import DIDPairSchema from "./schemas/DIDPair";
import MediatorSchema from "./schemas/Mediator";
import PrivateKeySchema from "./schemas/PrivateKey";

addRxPlugin(RxDBMigrationPlugin);
//New change

export class Database implements Domain.Pluto {
constructor(private db: PlutoDatabase) {}

Expand All @@ -29,14 +30,14 @@ export class Database implements Domain.Pluto {
}),
password: Buffer.from(encryptionKey).toString("hex"),
});
await myDatabase.addCollections({
await myDatabase.addCollections<PlutoCollections>({
messages: {
schema: MessageSchema,
},
dids: {
schema: DIDSchema,
},
credentials: {
verifiableCredentials: {
schema: CredentialSchema,
},
didpairs: {
Expand Down Expand Up @@ -73,7 +74,7 @@ export class Database implements Domain.Pluto {
throw new Error("Method not implemented.");
}

storePrismDID(
async storePrismDID(
did: Domain.DID,
keyPathIndex: number,
privateKey: Domain.PrivateKey,
Expand Down Expand Up @@ -114,6 +115,7 @@ export class Database implements Domain.Pluto {
): Promise<void> {
throw new Error("Method not implemented.");
}

storeCredential(credential: Domain.VerifiableCredential): Promise<void> {
throw new Error("Method not implemented.");
}
Expand Down Expand Up @@ -150,7 +152,6 @@ export class Database implements Domain.Pluto {
getPairByName(name: string): Promise<Domain.DIDPair | null> {
throw new Error("Method not implemented.");
}

getAllMessagesByDID(did: Domain.DID): Promise<Domain.Message[]> {
throw new Error("Method not implemented.");
}
Expand Down
9 changes: 2 additions & 7 deletions src/schemas/Mediator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { GenerateDBSchema } from "../types";
import { GenerateDBSchema, MediarorSchemaType } from "../types";

const MediatorSchema: GenerateDBSchema<{
id: string;
mediatorDID: string;
hostDID: string;
routingDID: string;
}> = {
const MediatorSchema: GenerateDBSchema<MediarorSchemaType> = {
version: 0,
primaryKey: "id",
type: "object",
Expand Down
5 changes: 2 additions & 3 deletions src/schemas/Message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Domain } from "@input-output-hk/atala-prism-wallet-sdk";
import { GenerateDBSchema } from "../types";
import { GenerateDBSchema, MessageSchemaType } from "../types";

const MessageSchema: GenerateDBSchema<Domain.Message> = {
const MessageSchema: GenerateDBSchema<MessageSchemaType> = {
version: 0,
primaryKey: "id",
type: "object",
Expand Down
60 changes: 34 additions & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
import { Domain } from "@input-output-hk/atala-prism-wallet-sdk";
import type { Domain } from "@input-output-hk/atala-prism-wallet-sdk";
import { RxJsonSchema, RxCollection, RxDatabase } from "rxdb";
export type ExcludeKeys<T, K extends keyof T> = Omit<T, K>;

export type ExcludeKeys<T, K extends keyof T> = {
[P in Exclude<keyof T, K>]: T[P];
};

export type GenerateDBSchema<T> = RxJsonSchema<T> & {
encrypted: (keyof T)[];
};
export type MessagesCollection = RxCollection<Domain.Message>;
export type PlutoDatabase = RxDatabase<{
messages: MessagesCollection;
}>;

export type CredentialSchemaType = Domain.VerifiableCredential;
export type DIDSchemaType = ExcludeKeys<
Domain.DID & { readonly alias: string; readonly did: string },
"toString"
>;
export type DIDPairSchemaType = Domain.DIDPair & { readonly id: string };
export type KeySchemaType = ExcludeKeys<
ExcludeKeys<
ExcludeKeys<
ExcludeKeys<
ExcludeKeys<
ExcludeKeys<
ExcludeKeys<
ExcludeKeys<Domain.Key & { readonly id: string }, "isExportable">,
"size"
>,
"getProperty"
>,
"isDerivable"
>,
"isSignable"
>,
"getEncoded"
>,
"canVerify"
>,
"isCurve"
Domain.Key & { readonly id: string },
| "isExportable"
| "size"
| "getProperty"
| "isDerivable"
| "isSignable"
| "getEncoded"
| "canVerify"
| "isCurve"
>;

export type MediarorSchemaType = {
id: string;
mediatorDID: string;
hostDID: string;
routingDID: string;
};
export type MessageSchemaType = Domain.Message;

export type PlutoCollections = {
messages: RxCollection<MessageSchemaType>;
dids: RxCollection<DIDSchemaType>;
verifiableCredentials: RxCollection<CredentialSchemaType>;
didpairs: RxCollection<DIDPairSchemaType>;
mediators: RxCollection<MediarorSchemaType>;
privateKeys: RxCollection<KeySchemaType>;
};
export type PlutoDatabase = RxDatabase<PlutoCollections>;

0 comments on commit d9adcd7

Please sign in to comment.