From 719959a59ac8877523f36254da71609fd5e222eb Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Fri, 24 Jul 2020 17:48:37 +0300 Subject: [PATCH] fix: DataStoreORM interface --- packages/daf-typeorm/src/data-store-orm.ts | 47 +-- packages/daf-typeorm/src/index.ts | 10 +- report/daf-selective-disclosure.api.md | 83 ++++ report/daf-typeorm.api.md | 469 +++++++++++++++++++++ scripts/generate-docs.ts | 9 +- scripts/generate-schemas.ts | 12 +- 6 files changed, 591 insertions(+), 39 deletions(-) create mode 100644 report/daf-selective-disclosure.api.md create mode 100644 report/daf-typeorm.api.md diff --git a/packages/daf-typeorm/src/data-store-orm.ts b/packages/daf-typeorm/src/data-store-orm.ts index e327c268b..a9d9f607a 100644 --- a/packages/daf-typeorm/src/data-store-orm.ts +++ b/packages/daf-typeorm/src/data-store-orm.ts @@ -41,35 +41,32 @@ interface IContext { authenticatedDid?: string } +export type FindIdentitiesArgs = FindArgs +export type FindMessagesArgs = FindArgs +export type FindClaimsArgs = FindArgs +export type FindCredentialsArgs = FindArgs +export type FindPresentationsArgs = FindArgs + export interface IDataStoreORM extends IPluginMethodMap { - dataStoreORMGetIdentities: (args: FindArgs, context: IContext) => Promise - dataStoreORMGetIdentitiesCount: (args: FindArgs, context: IContext) => Promise - dataStoreORMGetMessages: (args: FindArgs, context: IContext) => Promise - dataStoreORMGetMessagesCount: (args: FindArgs, context: IContext) => Promise - dataStoreORMGetVerifiableCredentialsByClaims: ( - args: FindArgs, - context: IContext, - ) => Promise - dataStoreORMGetVerifiableCredentialsByClaimsCount: ( - args: FindArgs, - context: IContext, - ) => Promise - dataStoreORMGetVerifiableCredentials: ( - args: FindArgs, + dataStoreORMGetIdentities(args: FindIdentitiesArgs, context: IContext): Promise> + dataStoreORMGetIdentitiesCount(args: FindIdentitiesArgs, context: IContext): Promise + dataStoreORMGetMessages(args: FindMessagesArgs, context: IContext): Promise> + dataStoreORMGetMessagesCount(args: FindMessagesArgs, context: IContext): Promise + dataStoreORMGetVerifiableCredentialsByClaims( + args: FindClaimsArgs, context: IContext, - ) => Promise - dataStoreORMGetVerifiableCredentialsCount: ( - args: FindArgs, + ): Promise> + dataStoreORMGetVerifiableCredentialsByClaimsCount(args: FindClaimsArgs, context: IContext): Promise + dataStoreORMGetVerifiableCredentials( + args: FindCredentialsArgs, context: IContext, - ) => Promise - dataStoreORMGetVerifiablePresentations: ( - args: FindArgs, - context: IContext, - ) => Promise - dataStoreORMGetVerifiablePresentationsCount: ( - args: FindArgs, + ): Promise> + dataStoreORMGetVerifiableCredentialsCount(args: FindCredentialsArgs, context: IContext): Promise + dataStoreORMGetVerifiablePresentations( + args: FindPresentationsArgs, context: IContext, - ) => Promise + ): Promise> + dataStoreORMGetVerifiablePresentationsCount(args: FindPresentationsArgs, context: IContext): Promise } export class DataStoreORM implements IAgentPlugin { diff --git a/packages/daf-typeorm/src/index.ts b/packages/daf-typeorm/src/index.ts index cf6e82497..a5e822690 100644 --- a/packages/daf-typeorm/src/index.ts +++ b/packages/daf-typeorm/src/index.ts @@ -1,7 +1,15 @@ export { IdentityStore } from './identity/identity-store' export { KeyStore } from './identity/key-store' export { DataStore } from './data-store' -export { DataStoreORM, IDataStoreORM } from './data-store-orm' +export { + DataStoreORM, + IDataStoreORM, + FindClaimsArgs, + FindCredentialsArgs, + FindIdentitiesArgs, + FindMessagesArgs, + FindPresentationsArgs, +} from './data-store-orm' export * from './types' import { Key, KeyType } from './entities/key' import { Identity } from './entities/identity' diff --git a/report/daf-selective-disclosure.api.md b/report/daf-selective-disclosure.api.md new file mode 100644 index 000000000..bb990eb8d --- /dev/null +++ b/report/daf-selective-disclosure.api.md @@ -0,0 +1,83 @@ +## API Report File for "daf-selective-disclosure" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { AbstractMessageHandler } from 'daf-core' +import { IAgentContext } from 'daf-core' +import { IAgentPlugin } from 'daf-core' +import { IDataStoreORM } from 'daf-typeorm' +import { IHandleMessage } from 'daf-core' +import { IIdentityManager } from 'daf-core' +import { IKeyManager } from 'daf-core' +import { IPluginMethodMap } from 'daf-core' +import { Message } from 'daf-core' +import { VerifiableCredential } from 'daf-core' +import { VerifiablePresentation } from 'daf-core' + +// Warning: (ae-forgotten-export) The symbol "TCreateSelectiveDisclosureRequest" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export const createSelectiveDisclosureRequest: TCreateSelectiveDisclosureRequest + +// Warning: (ae-forgotten-export) The symbol "TGetVerifiableCredentialsForSdr" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export const getVerifiableCredentialsForSdr: TGetVerifiableCredentialsForSdr + +// @public (undocumented) +export interface ICreateSelectiveDisclosureRequest extends IPluginMethodMap { + // Warning: (ae-forgotten-export) The symbol "ICreateSelectiveDisclosureRequestArgs" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts + // + // (undocumented) + createSelectiveDisclosureRequest( + args: ICreateSelectiveDisclosureRequestArgs, + context: IContext_2, + ): Promise +} + +// @public (undocumented) +export interface IGetVerifiableCredentialsForSdr extends IPluginMethodMap { + // (undocumented) + getVerifiableCredentialsForSdr: TGetVerifiableCredentialsForSdr +} + +// @public (undocumented) +export interface ISdr + extends ICreateSelectiveDisclosureRequest, + IGetVerifiableCredentialsForSdr, + IValidatePresentationAgainstSdr {} + +// @public (undocumented) +export interface IValidatePresentationAgainstSdr extends IPluginMethodMap { + // Warning: (ae-forgotten-export) The symbol "TValidatePresentationAgainstSdr" needs to be exported by the entry point index.d.ts + // + // (undocumented) + validatePresentationAgainstSdr: TValidatePresentationAgainstSdr +} + +// @public (undocumented) +export const MessageTypes: { + sdr: string +} + +// @public (undocumented) +export class Sdr implements IAgentPlugin { + // (undocumented) + readonly methods: ISdr +} + +// @public (undocumented) +export class SdrMessageHandler extends AbstractMessageHandler { + // Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts + // + // (undocumented) + handle(message: Message, context: IContext): Promise +} + +// @public (undocumented) +export const validatePresentationAgainstSdr: TValidatePresentationAgainstSdr + +// (No @packageDocumentation comment for this package) +``` diff --git a/report/daf-typeorm.api.md b/report/daf-typeorm.api.md new file mode 100644 index 000000000..815ca9e66 --- /dev/null +++ b/report/daf-typeorm.api.md @@ -0,0 +1,469 @@ +## API Report File for "daf-typeorm" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { AbstractIdentityStore } from 'daf-core' +import { AbstractKeyStore } from 'daf-core' +import { AbstractSecretBox } from 'daf-core' +import { BaseEntity } from 'typeorm' +import { Connection } from 'typeorm' +import { IAgentPlugin } from 'daf-core' +import { IDataStore } from 'daf-core' +import { IIdentity } from 'daf-core' +import { IKey } from 'daf-core' +import { IMessage } from 'daf-core' +import { IPluginMethodMap } from 'daf-core' +import { VerifiableCredential } from 'daf-core' +import { VerifiablePresentation } from 'daf-core' + +// @public (undocumented) +export class Claim extends BaseEntity { + // (undocumented) + context: string[] + // (undocumented) + credential: Credential_2 + // (undocumented) + credentialType: string[] + // (undocumented) + expirationDate?: Date + // (undocumented) + hash: string + // (undocumented) + isObj: boolean + // (undocumented) + issuanceDate: Date + // (undocumented) + issuer: Identity + // (undocumented) + subject?: Identity + // (undocumented) + type: string + // (undocumented) + value: string +} + +// @public (undocumented) +class Credential_2 extends BaseEntity { + // (undocumented) + claims: Claim[] + // (undocumented) + context: string[] + // (undocumented) + expirationDate?: Date + // (undocumented) + hash: string + // (undocumented) + id?: string + // (undocumented) + issuanceDate: Date + // (undocumented) + issuer: Identity + // (undocumented) + messages: Message[] + // (undocumented) + presentations: Presentation[] + set raw(raw: VerifiableCredential) + // (undocumented) + get raw(): VerifiableCredential + // (undocumented) + subject?: Identity + // (undocumented) + type: string[] +} + +export { Credential_2 as Credential } + +// @public (undocumented) +export class DataStore implements IAgentPlugin { + constructor(dbConnection: Promise) + // (undocumented) + dataStoreSaveMessage(args: IMessage): Promise + // (undocumented) + dataStoreSaveVerifiableCredential(args: VerifiableCredential): Promise + // (undocumented) + dataStoreSaveVerifiablePresentation(args: VerifiablePresentation): Promise + // (undocumented) + readonly methods: IDataStore +} + +// @public (undocumented) +export class DataStoreORM implements IAgentPlugin { + constructor(dbConnection: Promise) + // Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts + // + // (undocumented) + dataStoreORMGetIdentities(args: FindArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetIdentitiesCount(args: FindArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetMessages(args: FindArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetMessagesCount(args: FindArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetVerifiableCredentials( + args: FindArgs, + context: IContext, + ): Promise + // (undocumented) + dataStoreORMGetVerifiableCredentialsByClaims( + args: FindArgs, + context: IContext, + ): Promise + // (undocumented) + dataStoreORMGetVerifiableCredentialsByClaimsCount( + args: FindArgs, + context: IContext, + ): Promise + // (undocumented) + dataStoreORMGetVerifiableCredentialsCount( + args: FindArgs, + context: IContext, + ): Promise + // (undocumented) + dataStoreORMGetVerifiablePresentations( + args: FindArgs, + context: IContext, + ): Promise + // (undocumented) + dataStoreORMGetVerifiablePresentationsCount( + args: FindArgs, + context: IContext, + ): Promise + // (undocumented) + readonly methods: IDataStoreORM +} + +// @public (undocumented) +export const Entities: ( + | typeof Identity + | typeof Message + | typeof Claim + | typeof Credential_2 + | typeof Presentation + | typeof Key + | typeof Service +)[] + +// @public (undocumented) +export interface FindArgs { + // (undocumented) + order?: Order[] + // (undocumented) + skip?: number + // (undocumented) + take?: number + // (undocumented) + where?: Where[] +} + +// @public (undocumented) +export type FindClaimsArgs = FindArgs + +// @public (undocumented) +export type FindCredentialsArgs = FindArgs + +// @public (undocumented) +export type FindIdentitiesArgs = FindArgs + +// @public (undocumented) +export type FindMessagesArgs = FindArgs + +// @public (undocumented) +export type FindPresentationsArgs = FindArgs + +// @public (undocumented) +export interface IDataStoreORM extends IPluginMethodMap { + // (undocumented) + dataStoreORMGetIdentities(args: FindIdentitiesArgs, context: IContext): Promise> + // (undocumented) + dataStoreORMGetIdentitiesCount(args: FindIdentitiesArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetMessages(args: FindMessagesArgs, context: IContext): Promise> + // (undocumented) + dataStoreORMGetMessagesCount(args: FindMessagesArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetVerifiableCredentials( + args: FindCredentialsArgs, + context: IContext, + ): Promise> + // (undocumented) + dataStoreORMGetVerifiableCredentialsByClaims( + args: FindClaimsArgs, + context: IContext, + ): Promise> + // (undocumented) + dataStoreORMGetVerifiableCredentialsByClaimsCount(args: FindClaimsArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetVerifiableCredentialsCount(args: FindCredentialsArgs, context: IContext): Promise + // (undocumented) + dataStoreORMGetVerifiablePresentations( + args: FindPresentationsArgs, + context: IContext, + ): Promise> + // (undocumented) + dataStoreORMGetVerifiablePresentationsCount(args: FindPresentationsArgs, context: IContext): Promise +} + +// @public (undocumented) +export class Identity extends BaseEntity { + // (undocumented) + alias?: string + // (undocumented) + controllerKeyId: string + // (undocumented) + did: string + getLatestClaimValue( + dbConnection: Promise, + where: { + type: string + }, + ): Promise + // (undocumented) + issuedClaims: Claim[] + // (undocumented) + issuedCredentials: Credential_2[] + // (undocumented) + issuedPresentations: Presentation[] + // (undocumented) + keys: Key[] + // (undocumented) + provider: string + // (undocumented) + receivedClaims: Claim[] + // (undocumented) + receivedCredentials: Credential_2[] + // (undocumented) + receivedMessages: Message[] + // (undocumented) + receivedPresentations: Presentation[] + // (undocumented) + saveDate: Date + // (undocumented) + sentMessages: Message[] + // (undocumented) + services: Service[] + // (undocumented) + shortDid(): string + // (undocumented) + updateDate: Date +} + +// @public (undocumented) +export class IdentityStore extends AbstractIdentityStore { + constructor(dbConnection: Promise) + // (undocumented) + delete({ did }: { did: string }): Promise + // (undocumented) + get({ did, alias }: { did: string; alias: string }): Promise + // (undocumented) + import(args: IIdentity): Promise + // (undocumented) + list(): Promise +} + +// @public (undocumented) +export class Key extends BaseEntity { + // (undocumented) + identity: Identity + // (undocumented) + kid: string + // (undocumented) + kms: string + // (undocumented) + meta?: Record + // (undocumented) + privateKeyHex?: string + // (undocumented) + publicKeyHex: string + // (undocumented) + type: KeyType_2 +} + +// @public (undocumented) +export class KeyStore extends AbstractKeyStore { + constructor(dbConnection: Promise, secretBox?: AbstractSecretBox | undefined) + // (undocumented) + delete({ kid }: { kid: string }): Promise + // (undocumented) + get({ kid }: { kid: string }): Promise + // (undocumented) + import(args: IKey): Promise +} + +// @public (undocumented) +type KeyType_2 = 'Ed25519' | 'Secp256k1' + +export { KeyType_2 as KeyType } + +// @public (undocumented) +export class Message extends BaseEntity { + // (undocumented) + createdAt?: Date + // (undocumented) + credentials: Credential_2[] + // (undocumented) + data?: any + // (undocumented) + expiresAt?: Date + // (undocumented) + from?: Identity + // (undocumented) + id: string + // (undocumented) + metaData?: MetaData[] + // (undocumented) + presentations: Presentation[] + // (undocumented) + raw?: string + // (undocumented) + replyTo?: string[] + // (undocumented) + replyUrl?: string + // (undocumented) + saveDate: Date + // (undocumented) + setId(): void + // (undocumented) + threadId?: string + // (undocumented) + to?: Identity + // (undocumented) + type: string + // (undocumented) + updateDate: Date +} + +// @public (undocumented) +export interface MetaData { + // (undocumented) + type: string + // (undocumented) + value?: string +} + +// @public (undocumented) +export const migrations: never[] + +// @public (undocumented) +export interface Order { + // (undocumented) + column: TColumns + // (undocumented) + direction: 'ASC' | 'DESC' +} + +// @public (undocumented) +export class Presentation extends BaseEntity { + // (undocumented) + context: string[] + // (undocumented) + credentials: Credential_2[] + // (undocumented) + expirationDate?: Date + // (undocumented) + hash: string + // (undocumented) + holder: Identity + // (undocumented) + id?: String + // (undocumented) + issuanceDate: Date + // (undocumented) + messages: Message[] + set raw(raw: VerifiablePresentation) + // (undocumented) + get raw(): VerifiablePresentation + // (undocumented) + type: string[] + // (undocumented) + verifier?: Identity[] +} + +// @public (undocumented) +export class Service extends BaseEntity { + // (undocumented) + description?: string + // (undocumented) + id: string + // (undocumented) + identity: Identity + // (undocumented) + serviceEndpoint: string + // (undocumented) + type: string +} + +// @public (undocumented) +export type TClaimsColumns = + | 'context' + | 'credentialType' + | 'type' + | 'value' + | 'isObj' + | 'id' + | 'issuer' + | 'subject' + | 'expirationDate' + | 'issuanceDate' + +// @public (undocumented) +export type TCredentialColumns = + | 'context' + | 'type' + | 'id' + | 'issuer' + | 'subject' + | 'expirationDate' + | 'issuanceDate' + +// @public (undocumented) +export type TIdentitiesColumns = 'did' | 'alias' | 'provider' + +// @public (undocumented) +export type TMessageColumns = + | 'from' + | 'to' + | 'id' + | 'createdAt' + | 'expiresAt' + | 'threadId' + | 'type' + | 'raw' + | 'replyTo' + | 'replyUrl' + +// @public (undocumented) +export type TPresentationColumns = + | 'context' + | 'type' + | 'id' + | 'holder' + | 'verifier' + | 'expirationDate' + | 'issuanceDate' + +// @public (undocumented) +export interface Where { + // (undocumented) + column: TColumns + // (undocumented) + not?: boolean + // (undocumented) + op?: + | 'LessThan' + | 'LessThanOrEqual' + | 'MoreThan' + | 'MoreThanOrEqual' + | 'Equal' + | 'Like' + | 'Between' + | 'In' + | 'Any' + | 'IsNull' + // (undocumented) + value?: string[] +} + +// (No @packageDocumentation comment for this package) +``` diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 7ae7816af..59a1ef0cd 100644 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -13,23 +13,16 @@ const configs = [ // '../packages/daf-resolver-universal/api-extractor.json', // '../packages/daf-rest/api-extractor.json', // '../packages/daf-selective-disclosure/api-extractor.json', - // '../packages/daf-typeorm/api-extractor.json', + '../packages/daf-typeorm/api-extractor.json', '../packages/daf-url/api-extractor.json', '../packages/daf-w3c/api-extractor.json', ] for (const config of configs) { const apiExtractorJsonPath: string = path.join(__dirname, config) - - // Load and parse the api-extractor.json file const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath) - - // Invoke API Extractor const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, { - // Equivalent to the "--local" command-line parameter localBuild: true, - - // Equivalent to the "--verbose" command-line parameter showVerboseMessages: true, }) diff --git a/scripts/generate-schemas.ts b/scripts/generate-schemas.ts index 068a77409..89bdaca2a 100644 --- a/scripts/generate-schemas.ts +++ b/scripts/generate-schemas.ts @@ -15,6 +15,8 @@ const apiExtractorConfig = require('../api-extractor-base.json') const agentPlugins: Record> = { 'daf-core': ['IResolveDid', 'IDataStore', 'IKeyManager', 'IIdentityManager', 'IHandleMessage'], + // 'daf-selective-disclosure': ['ISdr'], + 'daf-typeorm': ['IDataStoreORM'], 'daf-w3c': ['IW3c'], } @@ -46,9 +48,6 @@ function createSchema(generator: TJS.JsonSchemaGenerator, symbol: string) { fixedSymbol = fixedSymbol.replace('Array<', '').replace('>', '') const schema = generator.getSchemaForSymbol(fixedSymbol) - if (fixedSymbol === 'TIdentityManagerGetIdentitiesResult') { - console.log(schema) - } const newSchema = { components: { @@ -87,12 +86,13 @@ function getResponseSchema(response: string) { for (const packageName of Object.keys(agentPlugins)) { const program = TJS.getProgramFromFiles([resolve('packages/' + packageName + '/src/index.ts')]) - const generator = TJS.buildGenerator(program, { required: true, topRef: true }) + const generator = TJS.buildGenerator(program, { required: true, topRef: true, excludePrivate: false }) const apiModel: ApiModel = new ApiModel() const apiPackage = apiModel.loadPackage( (apiExtractorConfig.docModel.apiJsonFilePath as string).replace('', packageName), ) + const entry = apiPackage.entryPoints[0] for (const pluginInterfaceName of agentPlugins[packageName]) { @@ -129,6 +129,7 @@ for (const packageName of Object.keys(agentPlugins)) { } for (const method of methods) { + console.log(`${method.operationId}(args: ${method.parameters}) => Promise<${method.response}>`) //@ts-ignore openApi.paths['/' + method.operationId] = { post: { @@ -151,4 +152,5 @@ for (const packageName of Object.keys(agentPlugins)) { } } -console.dir(openApi, { depth: 10 }) +console.log('Writing ./openApi.json') +writeFileSync('./openApi.json', JSON.stringify(openApi, null, 2))