From b628aca0c6d776d8adbf0dd7f303ef8d1cb609a7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 31 Jul 2024 05:43:32 +0530 Subject: [PATCH] chore(core): lint --- mx-interpreter/interpret.ts | 82 ++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/mx-interpreter/interpret.ts b/mx-interpreter/interpret.ts index d465312f..9ac32b0e 100644 --- a/mx-interpreter/interpret.ts +++ b/mx-interpreter/interpret.ts @@ -39,11 +39,11 @@ export default class Interpreter extends EventEmitter { private options: InterpreterOptions; - private concurrency : Concurrency; + private concurrency: Concurrency; - private stopper : Function | null = null; + private stopper: Function | null = null; - private log : typeof log; + private log: typeof log; constructor(workflow: WorkflowFile, options?: Partial) { super(); @@ -87,7 +87,7 @@ export default class Interpreter extends EventEmitter { * @param workflow Current **initialized** workflow (array of where-what pairs). * @returns {PageState} State of the current page. */ - private async getState(page: Page, workflow: Workflow) : Promise { + private async getState(page: Page, workflow: Workflow): Promise { /** * All the selectors present in the current Workflow */ @@ -98,7 +98,7 @@ export default class Interpreter extends EventEmitter { * @param selector Selector to be queried * @returns True if the targetted element is actionable, false otherwise. */ - const actionable = async (selector: string) : Promise => { + const actionable = async (selector: string): Promise => { try { const proms = [ page.isEnabled(selector, { timeout: 500 }), @@ -115,7 +115,7 @@ export default class Interpreter extends EventEmitter { /** * Object of selectors present in the current page. */ - const presentSelectors : SelectorArray = await Promise.all( + const presentSelectors: SelectorArray = await Promise.all( selectors.map(async (selector) => { if (await actionable(selector)) { return [selector]; @@ -142,7 +142,7 @@ export default class Interpreter extends EventEmitter { * @param context Current browser context. * @returns True if `where` is applicable in the given context, false otherwise */ - private applicable(where: Where, context: PageState, usedActions : string[] = []) : boolean { + private applicable(where: Where, context: PageState, usedActions: string[] = []): boolean { /** * Given two arbitrary objects, determines whether `subset` is a subset of `superset`.\ * \ @@ -153,7 +153,7 @@ export default class Interpreter extends EventEmitter { * @returns `true` if `subset <= superset`, `false` otherwise. */ const inclusive = (subset: Record, superset: Record) - : boolean => ( + : boolean => ( Object.entries(subset).every( ([key, value]) => { /** @@ -161,7 +161,7 @@ export default class Interpreter extends EventEmitter { */ const parsedValue = Array.isArray(value) ? arrayToObject(value) : value; - const parsedSuperset : Record = {}; + const parsedSuperset: Record = {}; parsedSuperset[key] = Array.isArray(superset[key]) ? arrayToObject(superset[key]) : superset[key]; @@ -169,14 +169,14 @@ export default class Interpreter extends EventEmitter { // Every `subset` key must exist in the `superset` and // have the same value (strict equality), or subset[key] <= superset[key] return parsedSuperset[key] - && ( - (parsedSuperset[key] === parsedValue) - || ((parsedValue).constructor.name === 'RegExp' && (parsedValue).test(parsedSuperset[key])) - || ( - (parsedValue).constructor.name !== 'RegExp' - && typeof parsedValue === 'object' && inclusive(parsedValue, parsedSuperset[key]) - ) - ); + && ( + (parsedSuperset[key] === parsedValue) + || ((parsedValue).constructor.name === 'RegExp' && (parsedValue).test(parsedSuperset[key])) + || ( + (parsedValue).constructor.name !== 'RegExp' + && typeof parsedValue === 'object' && inclusive(parsedValue, parsedSuperset[key]) + ) + ); }, ) ); @@ -188,7 +188,7 @@ export default class Interpreter extends EventEmitter { const array = Array.isArray(value) ? value as Where[] : Object.entries(value).map((a) => Object.fromEntries([a])); - // every condition is treated as a single context + // every condition is treated as a single context switch (key as keyof typeof operators) { case '$and': @@ -234,24 +234,24 @@ export default class Interpreter extends EventEmitter { * @param page Playwright Page object * @param steps Array of actions. */ - private async carryOutSteps(page: Page, steps: What[]) : Promise { - /** - * Defines overloaded (or added) methods/actions usable in the workflow. - * If a method overloads any existing method of the Page class, it accepts the same set - * of parameters *(but can override some!)*\ - * \ - * Also, following piece of code defines functions to be run in the browser's context. - * Beware of false linter errors - here, we know better! - */ - const wawActions : Record void> = { + private async carryOutSteps(page: Page, steps: What[]): Promise { + /** + * Defines overloaded (or added) methods/actions usable in the workflow. + * If a method overloads any existing method of the Page class, it accepts the same set + * of parameters *(but can override some!)*\ + * \ + * Also, following piece of code defines functions to be run in the browser's context. + * Beware of false linter errors - here, we know better! + */ + const wawActions: Record void> = { screenshot: async (params: PageScreenshotOptions) => { const screenshotBuffer = await page.screenshot({ ...params, path: undefined, }); await this.options.binaryCallback(screenshotBuffer, 'image/png'); }, - enqueueLinks: async (selector : string) => { - const links : string[] = await page.locator(selector) + enqueueLinks: async (selector: string) => { + const links: string[] = await page.locator(selector) .evaluateAll( // @ts-ignore (elements) => elements.map((a) => a.href).filter((x) => x), @@ -277,7 +277,7 @@ export default class Interpreter extends EventEmitter { await page.close(); }, scrape: async (selector?: string) => { - const scrapeResults : Record[] = await page + const scrapeResults: Record[] = await page // eslint-disable-next-line // @ts-ignore .evaluate((s) => scrape(s ?? null), selector); @@ -296,7 +296,7 @@ export default class Interpreter extends EventEmitter { this.options.serializableCallback(scrapeResult); }, - scroll: async (pages? : number) => { + scroll: async (pages?: number) => { await page.evaluate(async (pagesInternal) => { for (let i = 1; i <= (pagesInternal ?? 1); i += 1) { // @ts-ignore @@ -304,9 +304,9 @@ export default class Interpreter extends EventEmitter { } }, pages ?? 1); }, - script: async (code : string) => { - const AsyncFunction : FunctionConstructor = Object.getPrototypeOf( - async () => {}, + script: async (code: string) => { + const AsyncFunction: FunctionConstructor = Object.getPrototypeOf( + async () => { }, ).constructor; const x = new AsyncFunction('page', 'log', code); await x(page, this.log); @@ -324,11 +324,11 @@ export default class Interpreter extends EventEmitter { const params = !step.args || Array.isArray(step.args) ? step.args : [step.args]; await wawActions[step.action as CustomFunctions](...(params ?? [])); } else { - // Implements the dot notation for the "method name" in the workflow + // Implements the dot notation for the "method name" in the workflow const levels = step.action.split('.'); const methodName = levels[levels.length - 1]; - let invokee : any = page; + let invokee: any = page; for (const level of levels.splice(0, levels.length - 1)) { invokee = invokee[level]; } @@ -344,8 +344,8 @@ export default class Interpreter extends EventEmitter { } } - private async runLoop(p : Page, workflow: Workflow) { - const usedActions : string[] = []; + private async runLoop(p: Page, workflow: Workflow) { + const usedActions: string[] = []; let lastAction = null; let repeatCount = 0; @@ -423,7 +423,7 @@ export default class Interpreter extends EventEmitter { * @param {ParamType} params Workflow specific, set of parameters * for the `{$param: nameofparam}` fields. */ - public async run(page: Page, params? : ParamType) : Promise { + public async run(page: Page, params?: ParamType): Promise { if (this.stopper) { throw new Error('This Interpreter is already running a workflow. To run another workflow, please, spawn another Interpreter.'); } @@ -448,7 +448,7 @@ export default class Interpreter extends EventEmitter { this.stopper = null; } - public async stop() : Promise { + public async stop(): Promise { if (this.stopper) { await this.stopper(); this.stopper = null;