Skip to content

Commit

Permalink
refactor(action-menu): clearly mark public api (#1163)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra authored Dec 15, 2022
1 parent 0e89e6c commit e4e5ca1
Show file tree
Hide file tree
Showing 27 changed files with 142 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/action-menu/src/ActionMenuApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
} from './handlers'
import { ActionMenuService } from './services'

/**
* @public
*/
@injectable()
export class ActionMenuApi {
private connectionService: ConnectionService
Expand Down
15 changes: 15 additions & 0 deletions packages/action-menu/src/ActionMenuApiOptions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import type { ActionMenuRole } from './ActionMenuRole'
import type { ActionMenu, ActionMenuSelection } from './models'

/**
* @public
*/
export interface FindActiveMenuOptions {
connectionId: string
role: ActionMenuRole
}

/**
* @public
*/
export interface ClearActiveMenuOptions {
connectionId: string
role: ActionMenuRole
}

/**
* @public
*/
export interface RequestMenuOptions {
connectionId: string
}

/**
* @public
*/
export interface SendMenuOptions {
connectionId: string
menu: ActionMenu
}

/**
* @public
*/
export interface PerformActionOptions {
connectionId: string
performedAction: ActionMenuSelection
Expand Down
7 changes: 7 additions & 0 deletions packages/action-menu/src/ActionMenuEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import type { ActionMenuState } from './ActionMenuState'
import type { ActionMenuRecord } from './repository'
import type { BaseEvent } from '@aries-framework/core'

/**
* @public
*/
export enum ActionMenuEventTypes {
ActionMenuStateChanged = 'ActionMenuStateChanged',
}

/**
* @public
*/
export interface ActionMenuStateChangedEvent extends BaseEvent {
type: typeof ActionMenuEventTypes.ActionMenuStateChanged
payload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/action-menu/src/ActionMenuModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { ActionMenuRole } from './ActionMenuRole'
import { ActionMenuRepository } from './repository'
import { ActionMenuService } from './services'

/**
* @public
*/
export class ActionMenuModule implements Module {
public readonly api = ActionMenuApi

Expand Down
1 change: 1 addition & 0 deletions packages/action-menu/src/ActionMenuRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Action Menu roles based on the flow defined in RFC 0509.
*
* @see https://github.com/hyperledger/aries-rfcs/tree/main/features/0509-action-menu#roles
* @public
*/
export enum ActionMenuRole {
Requester = 'requester',
Expand Down
1 change: 1 addition & 0 deletions packages/action-menu/src/ActionMenuState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Action Menu states based on the flow defined in RFC 0509.
*
* @see https://github.com/hyperledger/aries-rfcs/tree/main/features/0509-action-menu#states
* @public
*/
export enum ActionMenuState {
Null = 'null',
Expand Down
12 changes: 5 additions & 7 deletions packages/action-menu/src/__tests__/ActionMenuModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import type { DependencyManager, FeatureRegistry } from '@aries-framework/core'

import { Protocol } from '@aries-framework/core'

import {
ActionMenuApi,
ActionMenuModule,
ActionMenuRepository,
ActionMenuRole,
ActionMenuService,
} from '@aries-framework/action-menu'
import { ActionMenuApi } from '../ActionMenuApi'
import { ActionMenuModule } from '../ActionMenuModule'
import { ActionMenuRole } from '../ActionMenuRole'
import { ActionMenuRepository } from '../repository'
import { ActionMenuService } from '../services'

const dependencyManager = {
registerInstance: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import { ProblemReportError } from '@aries-framework/core'

import { ActionMenuProblemReportMessage } from '../messages'

/**
* @internal
*/
interface ActionMenuProblemReportErrorOptions extends ProblemReportErrorOptions {
problemCode: ActionMenuProblemReportReason
}

/**
* @internal
*/
export class ActionMenuProblemReportError extends ProblemReportError {
public problemReport: ActionMenuProblemReportMessage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Action Menu errors discussed in RFC 0509.
*
* @see https://github.com/hyperledger/aries-rfcs/tree/main/features/0509-action-menu#unresolved-questions
* @internal
*/
export enum ActionMenuProblemReportReason {
Timeout = 'timeout',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { ActionMenuProblemReportMessage } from '../messages'

/**
* @internal
*/
export class ActionMenuProblemReportHandler implements Handler {
private actionMenuService: ActionMenuService
public supportedMessages = [ActionMenuProblemReportMessage]
Expand Down
3 changes: 3 additions & 0 deletions packages/action-menu/src/handlers/MenuMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { MenuMessage } from '../messages'

/**
* @internal
*/
export class MenuMessageHandler implements Handler {
private actionMenuService: ActionMenuService
public supportedMessages = [MenuMessage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { MenuRequestMessage } from '../messages'

/**
* @internal
*/
export class MenuRequestMessageHandler implements Handler {
private actionMenuService: ActionMenuService
public supportedMessages = [MenuRequestMessage]
Expand Down
3 changes: 3 additions & 0 deletions packages/action-menu/src/handlers/PerformMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { Handler, HandlerInboundMessage } from '@aries-framework/core'

import { PerformMessage } from '../messages'

/**
* @internal
*/
export class PerformMessageHandler implements Handler {
private actionMenuService: ActionMenuService
public supportedMessages = [PerformMessage]
Expand Down
4 changes: 1 addition & 3 deletions packages/action-menu/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ export * from './ActionMenuModule'
export * from './ActionMenuEvents'
export * from './ActionMenuRole'
export * from './ActionMenuState'
export * from './messages'
export * from './models'
export * from './repository'
export * from './services'
export * from './repository/ActionMenuRecord'
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ActionMenuProblemReportMessageOptions = ProblemReportMessageOptions

/**
* @see https://github.com/hyperledger/aries-rfcs/blob/main/features/0035-report-problem/README.md
* @internal
*/
export class ActionMenuProblemReportMessage extends ProblemReportMessage {
/**
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/messages/MenuMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { IsInstance, IsOptional, IsString } from 'class-validator'

import { ActionMenuOption } from '../models'

/**
* @internal
*/
export interface MenuMessageOptions {
id?: string
title: string
Expand All @@ -15,6 +18,9 @@ export interface MenuMessageOptions {
threadId?: string
}

/**
* @internal
*/
export class MenuMessage extends AgentMessage {
public constructor(options: MenuMessageOptions) {
super()
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/messages/MenuRequestMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'

/**
* @internal
*/
export interface MenuRequestMessageOptions {
id?: string
}

/**
* @internal
*/
export class MenuRequestMessage extends AgentMessage {
public constructor(options: MenuRequestMessageOptions) {
super()
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/messages/PerformMessage.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { IsOptional, IsString } from 'class-validator'

/**
* @internal
*/
export interface PerformMessageOptions {
id?: string
name: string
params?: Record<string, string>
threadId: string
}

/**
* @internal
*/
export class PerformMessage extends AgentMessage {
public constructor(options: PerformMessageOptions) {
super()
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/models/ActionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { IsInstance, IsString } from 'class-validator'

import { ActionMenuOption } from './ActionMenuOption'

/**
* @public
*/
export interface ActionMenuOptions {
title: string
description: string
options: ActionMenuOptionOptions[]
}

/**
* @public
*/
export class ActionMenu {
public constructor(options: ActionMenuOptions) {
if (options) {
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/models/ActionMenuOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { IsBoolean, IsInstance, IsOptional, IsString } from 'class-validator'

import { ActionMenuForm } from './ActionMenuOptionForm'

/**
* @public
*/
export interface ActionMenuOptionOptions {
name: string
title: string
Expand All @@ -13,6 +16,9 @@ export interface ActionMenuOptionOptions {
form?: ActionMenuFormOptions
}

/**
* @public
*/
export class ActionMenuOption {
public constructor(options: ActionMenuOptionOptions) {
if (options) {
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/models/ActionMenuOptionForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { IsInstance, IsString } from 'class-validator'

import { ActionMenuFormParameter } from './ActionMenuOptionFormParameter'

/**
* @public
*/
export interface ActionMenuFormOptions {
description: string
params: ActionMenuFormParameterOptions[]
submitLabel: string
}

/**
* @public
*/
export class ActionMenuForm {
public constructor(options: ActionMenuFormOptions) {
if (options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator'

/**
* @public
*/
export enum ActionMenuFormInputType {
Text = 'text',
}

/**
* @public
*/
export interface ActionMenuFormParameterOptions {
name: string
title: string
Expand All @@ -13,6 +19,9 @@ export interface ActionMenuFormParameterOptions {
type?: ActionMenuFormInputType
}

/**
* @public
*/
export class ActionMenuFormParameter {
public constructor(options: ActionMenuFormParameterOptions) {
if (options) {
Expand Down
6 changes: 6 additions & 0 deletions packages/action-menu/src/models/ActionMenuSelection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { IsOptional, IsString } from 'class-validator'

/**
* @public
*/
export interface ActionMenuSelectionOptions {
name: string
params?: Record<string, string>
}

/**
* @public
*/
export class ActionMenuSelection {
public constructor(options: ActionMenuSelectionOptions) {
if (options) {
Expand Down
12 changes: 12 additions & 0 deletions packages/action-menu/src/repository/ActionMenuRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { Type } from 'class-transformer'

import { ActionMenuSelection, ActionMenu } from '../models'

/**
* @public
*/
export interface ActionMenuRecordProps {
id?: string
state: ActionMenuState
Expand All @@ -19,14 +22,23 @@ export interface ActionMenuRecordProps {
tags?: CustomActionMenuTags
}

/**
* @public
*/
export type CustomActionMenuTags = TagsBase

/**
* @public
*/
export type DefaultActionMenuTags = {
role: ActionMenuRole
connectionId: string
threadId: string
}

/**
* @public
*/
export class ActionMenuRecord
extends BaseRecord<DefaultActionMenuTags, CustomActionMenuTags>
implements ActionMenuRecordProps
Expand Down
3 changes: 3 additions & 0 deletions packages/action-menu/src/repository/ActionMenuRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { EventEmitter, InjectionSymbols, inject, injectable, Repository, Storage

import { ActionMenuRecord } from './ActionMenuRecord'

/**
* @internal
*/
@injectable()
export class ActionMenuRepository extends Repository<ActionMenuRecord> {
public constructor(
Expand Down
Loading

0 comments on commit e4e5ca1

Please sign in to comment.