import { AttachedDoc, Class, Doc, DocumentQuery, DocumentUpdate, Mixin, Ref, Space } from '@hcengineering/core' import { Asset, IntlString, Plugin, plugin } from '@hcengineering/platform' import { ActionCategory, ViewAction } from '@hcengineering/view' /** * @public */ export const automationId = 'automation' as Plugin /** * @public */ export enum CommandType { UpdateDoc = 'UPDATE_DOC' } /** * @public */ export enum TriggerType { Action = 'ACTION', Trigger = 'TRIGGER' } /** * @public */ export interface AttributeAutomationSupport { name: keyof T sort?: { groupBy?: DocumentQuery } } /** * @public */ export interface AttributeAutomationTriggerSupport { name: keyof T } /** * @public */ export interface AutomationTriggerSupport { action?: { mode: ('editor' | 'context')[] } attributes?: AttributeAutomationTriggerSupport[] } /** * @public */ export interface AutomationSortSupport { groupBy?: DocumentQuery } /** * @public */ export interface AutomationSupport extends Class { attributes: AttributeAutomationSupport[] trigger: AutomationTriggerSupport sort?: AutomationSortSupport } /** * @public */ export interface Command { fetch?: DocumentQuery type: CommandType } /** * @public */ export interface UpdateDocCommand extends Command { type: CommandType.UpdateDoc targetClass: Ref> update: DocumentUpdate } /** * @public */ export function isUpdateDocCommand (command: Command): command is UpdateDocCommand { return command.type === CommandType.UpdateDoc } /** * @public */ export interface Automation extends AttachedDoc { name: string description: string | null targetClass: Ref> | null trigger: { type: TriggerType } commands: Command[] } /** * @public */ export interface PerformAutomationProps { automationId: Ref> automationClass: Ref>> } export default plugin(automationId, { class: { Automation: '' as Ref>> }, action: { PerformAutomation: '' as ViewAction }, mixin: { AutomationSupport: '' as Ref>> }, category: { Automation: '' as Ref }, string: { Automation: '' as IntlString, Actions: '' as IntlString, Chat: '' as IntlString, Content: '' as IntlString, Dates: '' as IntlString, Tracker: '' as IntlString, Trigger: '' as IntlString, Set: '' as IntlString, To: '' as IntlString, AddMenu: '' as IntlString, Menu: '' as IntlString, Mode: '' as IntlString, Icon: '' as IntlString, SelectClass: '' as IntlString, In: '' as IntlString, Update: '' as IntlString }, icon: { Automation: '' as Asset }, space: { Automation: '' as Ref } })