From dd7a7918c6ae4e4d7b98135dace7e33b33594661 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 15 Jul 2024 22:32:37 +0530 Subject: [PATCH] feat: types for workflow & actions --- mx-interpreter/types/workflow.ts | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 mx-interpreter/types/workflow.ts diff --git a/mx-interpreter/types/workflow.ts b/mx-interpreter/types/workflow.ts new file mode 100644 index 00000000..ac9fda22 --- /dev/null +++ b/mx-interpreter/types/workflow.ts @@ -0,0 +1,58 @@ +import { Page } from 'playwright'; +import { + naryOperators, unaryOperators, operators, meta, +} from './logic'; + +export type Operator = typeof operators[number]; +export type UnaryOperator = typeof unaryOperators[number]; +export type NAryOperator = typeof naryOperators[number]; + +export type Meta = typeof meta[number]; + +export type SelectorArray = string[]; + +type RegexableString = string | { '$regex':string }; + +type BaseConditions = { + 'url': RegexableString, + 'cookies': Record, + 'selectors': SelectorArray, // (CSS/Playwright) selectors use their own logic, there is no reason (and several technical difficulties) to allow regular expression notation +} & Record; + +export type Where = +Partial<{ [key in NAryOperator]: Where[] }> & // either a logic operator (arity N) +Partial<{ [key in UnaryOperator]: Where }> & // or an unary operator +Partial; // or one of the base conditions + +type MethodNames = { + [K in keyof T]: T[K] extends Function ? K : never; +}[keyof T]; + +export type CustomFunctions = 'scrape' | 'scrapeSchema' | 'scroll' | 'screenshot' | 'script' | 'enqueueLinks' | 'flag'; + +export type What = { + action: MethodNames | CustomFunctions, + args?: any[] +}; + +export type PageState = Partial; + +export type ParamType = Record; + +export type MetaData = { + name?: string, + desc?: string, +}; + +export interface WhereWhatPair { + id?: string + where: Where + what: What[] +} + +export type Workflow = WhereWhatPair[]; + +export type WorkflowFile = { + meta?: MetaData, + workflow: Workflow +}; \ No newline at end of file