chore: rename internal query handler (#8955)

This commit is contained in:
jrandolf 2022-09-15 08:48:59 +02:00 committed by GitHub
parent 7c4f41fadc
commit 64763e973b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -20,7 +20,7 @@ import {CDPSession} from './Connection.js';
import {ElementHandle} from './ElementHandle.js'; import {ElementHandle} from './ElementHandle.js';
import {Frame} from './Frame.js'; import {Frame} from './Frame.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js'; import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js';
import {InternalQueryHandler} from './QueryHandler.js'; import {PuppeteerQueryHandler} from './QueryHandler.js';
async function queryAXTree( async function queryAXTree(
client: CDPSession, client: CDPSession,
@ -95,7 +95,7 @@ const queryOneId = async (element: ElementHandle<Node>, selector: string) => {
return res[0].backendDOMNodeId; return res[0].backendDOMNodeId;
}; };
const queryOne: InternalQueryHandler['queryOne'] = async ( const queryOne: PuppeteerQueryHandler['queryOne'] = async (
element, element,
selector selector
) => { ) => {
@ -108,7 +108,7 @@ const queryOne: InternalQueryHandler['queryOne'] = async (
)) as ElementHandle<Node>; )) as ElementHandle<Node>;
}; };
const waitFor: InternalQueryHandler['waitFor'] = async ( const waitFor: PuppeteerQueryHandler['waitFor'] = async (
elementOrFrame, elementOrFrame,
selector, selector,
options options
@ -158,7 +158,7 @@ const waitFor: InternalQueryHandler['waitFor'] = async (
return result.frame.worlds[MAIN_WORLD].transferHandle(result); return result.frame.worlds[MAIN_WORLD].transferHandle(result);
}; };
const queryAll: InternalQueryHandler['queryAll'] = async ( const queryAll: PuppeteerQueryHandler['queryAll'] = async (
element, element,
selector selector
) => { ) => {
@ -178,7 +178,7 @@ const queryAll: InternalQueryHandler['queryAll'] = async (
/** /**
* @internal * @internal
*/ */
export const ariaHandler: InternalQueryHandler = { export const ariaHandler: PuppeteerQueryHandler = {
queryOne, queryOne,
waitFor, waitFor,
queryAll, queryAll,

View File

@ -40,7 +40,7 @@ export interface CustomQueryHandler {
/** /**
* @internal * @internal
*/ */
export interface InternalQueryHandler { export interface PuppeteerQueryHandler {
/** /**
* Queries for a single node given a selector and {@link ElementHandle}. * Queries for a single node given a selector and {@link ElementHandle}.
* *
@ -71,10 +71,10 @@ export interface InternalQueryHandler {
) => Promise<ElementHandle<Node> | null>; ) => Promise<ElementHandle<Node> | null>;
} }
function internalizeCustomQueryHandler( function createPuppeteerQueryHandler(
handler: CustomQueryHandler handler: CustomQueryHandler
): InternalQueryHandler { ): PuppeteerQueryHandler {
const internalHandler: InternalQueryHandler = {}; const internalHandler: PuppeteerQueryHandler = {};
if (handler.queryOne) { if (handler.queryOne) {
const queryOne = handler.queryOne; const queryOne = handler.queryOne;
@ -138,7 +138,7 @@ function internalizeCustomQueryHandler(
return internalHandler; return internalHandler;
} }
const defaultHandler = internalizeCustomQueryHandler({ const defaultHandler = createPuppeteerQueryHandler({
queryOne: (element, selector) => { queryOne: (element, selector) => {
if (!('querySelector' in element)) { if (!('querySelector' in element)) {
throw new Error( throw new Error(
@ -165,7 +165,7 @@ const defaultHandler = internalizeCustomQueryHandler({
}, },
}); });
const pierceHandler = internalizeCustomQueryHandler({ const pierceHandler = createPuppeteerQueryHandler({
queryOne: (element, selector) => { queryOne: (element, selector) => {
let found: Node | null = null; let found: Node | null = null;
const search = (root: Node) => { const search = (root: Node) => {
@ -215,7 +215,7 @@ const pierceHandler = internalizeCustomQueryHandler({
}, },
}); });
const xpathHandler = internalizeCustomQueryHandler({ const xpathHandler = createPuppeteerQueryHandler({
queryOne: (element, selector) => { queryOne: (element, selector) => {
const doc = element.ownerDocument || document; const doc = element.ownerDocument || document;
const result = doc.evaluate( const result = doc.evaluate(
@ -245,7 +245,7 @@ const xpathHandler = internalizeCustomQueryHandler({
}); });
interface RegisteredQueryHandler { interface RegisteredQueryHandler {
handler: InternalQueryHandler; handler: PuppeteerQueryHandler;
transformSelector?: (selector: string) => string; transformSelector?: (selector: string) => string;
} }
@ -294,7 +294,7 @@ export function registerCustomQueryHandler(
throw new Error(`Custom query handler names may only contain [a-zA-Z]`); 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): { export function getQueryHandlerAndSelector(selector: string): {
updatedSelector: string; updatedSelector: string;
queryHandler: InternalQueryHandler; queryHandler: PuppeteerQueryHandler;
} { } {
for (const handlerMap of [QUERY_HANDLERS, INTERNAL_QUERY_HANDLERS]) { for (const handlerMap of [QUERY_HANDLERS, INTERNAL_QUERY_HANDLERS]) {
for (const [ for (const [