From 64763e973bc32b2d46efc15f1fcd6cd84412a4f5 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Thu, 15 Sep 2022 08:48:59 +0200 Subject: [PATCH] chore: rename internal query handler (#8955) --- src/common/AriaQueryHandler.ts | 10 +++++----- src/common/QueryHandler.ts | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/common/AriaQueryHandler.ts b/src/common/AriaQueryHandler.ts index 4460c909..97bd9b88 100644 --- a/src/common/AriaQueryHandler.ts +++ b/src/common/AriaQueryHandler.ts @@ -20,7 +20,7 @@ import {CDPSession} from './Connection.js'; import {ElementHandle} from './ElementHandle.js'; import {Frame} from './Frame.js'; import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js'; -import {InternalQueryHandler} from './QueryHandler.js'; +import {PuppeteerQueryHandler} from './QueryHandler.js'; async function queryAXTree( client: CDPSession, @@ -95,7 +95,7 @@ const queryOneId = async (element: ElementHandle, selector: string) => { return res[0].backendDOMNodeId; }; -const queryOne: InternalQueryHandler['queryOne'] = async ( +const queryOne: PuppeteerQueryHandler['queryOne'] = async ( element, selector ) => { @@ -108,7 +108,7 @@ const queryOne: InternalQueryHandler['queryOne'] = async ( )) as ElementHandle; }; -const waitFor: InternalQueryHandler['waitFor'] = async ( +const waitFor: PuppeteerQueryHandler['waitFor'] = async ( elementOrFrame, selector, options @@ -158,7 +158,7 @@ const waitFor: InternalQueryHandler['waitFor'] = async ( return result.frame.worlds[MAIN_WORLD].transferHandle(result); }; -const queryAll: InternalQueryHandler['queryAll'] = async ( +const queryAll: PuppeteerQueryHandler['queryAll'] = async ( element, selector ) => { @@ -178,7 +178,7 @@ const queryAll: InternalQueryHandler['queryAll'] = async ( /** * @internal */ -export const ariaHandler: InternalQueryHandler = { +export const ariaHandler: PuppeteerQueryHandler = { queryOne, waitFor, queryAll, diff --git a/src/common/QueryHandler.ts b/src/common/QueryHandler.ts index 5fd360e0..f89fec91 100644 --- a/src/common/QueryHandler.ts +++ b/src/common/QueryHandler.ts @@ -40,7 +40,7 @@ export interface CustomQueryHandler { /** * @internal */ -export interface InternalQueryHandler { +export interface PuppeteerQueryHandler { /** * Queries for a single node given a selector and {@link ElementHandle}. * @@ -71,10 +71,10 @@ export interface InternalQueryHandler { ) => Promise | null>; } -function internalizeCustomQueryHandler( +function createPuppeteerQueryHandler( handler: CustomQueryHandler -): InternalQueryHandler { - const internalHandler: InternalQueryHandler = {}; +): PuppeteerQueryHandler { + const internalHandler: PuppeteerQueryHandler = {}; if (handler.queryOne) { const queryOne = handler.queryOne; @@ -138,7 +138,7 @@ function internalizeCustomQueryHandler( return internalHandler; } -const defaultHandler = internalizeCustomQueryHandler({ +const defaultHandler = createPuppeteerQueryHandler({ queryOne: (element, selector) => { if (!('querySelector' in element)) { throw new Error( @@ -165,7 +165,7 @@ const defaultHandler = internalizeCustomQueryHandler({ }, }); -const pierceHandler = internalizeCustomQueryHandler({ +const pierceHandler = createPuppeteerQueryHandler({ queryOne: (element, selector) => { let found: Node | null = null; const search = (root: Node) => { @@ -215,7 +215,7 @@ const pierceHandler = internalizeCustomQueryHandler({ }, }); -const xpathHandler = internalizeCustomQueryHandler({ +const xpathHandler = createPuppeteerQueryHandler({ queryOne: (element, selector) => { const doc = element.ownerDocument || document; const result = doc.evaluate( @@ -245,7 +245,7 @@ const xpathHandler = internalizeCustomQueryHandler({ }); interface RegisteredQueryHandler { - handler: InternalQueryHandler; + handler: PuppeteerQueryHandler; transformSelector?: (selector: string) => string; } @@ -294,7 +294,7 @@ export function registerCustomQueryHandler( throw new Error(`Custom query handler names may only contain [a-zA-Z]`); } - QUERY_HANDLERS.set(name, {handler: internalizeCustomQueryHandler(handler)}); + QUERY_HANDLERS.set(name, {handler: createPuppeteerQueryHandler(handler)}); } /** @@ -331,7 +331,7 @@ const CUSTOM_QUERY_SEPARATORS = ['=', '/']; */ export function getQueryHandlerAndSelector(selector: string): { updatedSelector: string; - queryHandler: InternalQueryHandler; + queryHandler: PuppeteerQueryHandler; } { for (const handlerMap of [QUERY_HANDLERS, INTERNAL_QUERY_HANDLERS]) { for (const [