first commit

This commit is contained in:
Frank John Begornia
2025-12-23 01:51:15 +08:00
commit c926590e1d
4137 changed files with 613038 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/**
* Copyright 2022 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { BidiPlusChannel } from '../../../protocol/chromium-bidi.js';
import { ChromiumBidi, type BrowsingContext } from '../../../protocol/protocol.js';
import { EventEmitter } from '../../../utils/EventEmitter.js';
import type { Result } from '../../../utils/result.js';
import { OutgoingMessage } from '../../OutgoingMessage.js';
import type { BrowsingContextStorage } from '../context/BrowsingContextStorage.js';
export declare const enum EventManagerEvents {
Event = "event"
}
type EventManagerEventsMap = {
[EventManagerEvents.Event]: {
message: Promise<Result<OutgoingMessage>>;
event: string;
};
};
export declare class EventManager extends EventEmitter<EventManagerEventsMap> {
#private;
constructor(browsingContextStorage: BrowsingContextStorage);
registerEvent(event: ChromiumBidi.Event, contextId: BrowsingContext.BrowsingContext | null): void;
registerPromiseEvent(event: Promise<Result<ChromiumBidi.Event>>, contextId: BrowsingContext.BrowsingContext | null, eventName: ChromiumBidi.EventNames): void;
subscribe(eventNames: ChromiumBidi.EventNames[], contextIds: (BrowsingContext.BrowsingContext | null)[], channel: BidiPlusChannel): void;
unsubscribe(eventNames: ChromiumBidi.EventNames[], contextIds: (BrowsingContext.BrowsingContext | null)[], channel: BidiPlusChannel): void;
}
export {};

View File

@@ -0,0 +1,184 @@
"use strict";
/**
* Copyright 2022 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventManager = void 0;
const protocol_js_1 = require("../../../protocol/protocol.js");
const Buffer_js_1 = require("../../../utils/Buffer.js");
const DefaultMap_js_1 = require("../../../utils/DefaultMap.js");
const EventEmitter_js_1 = require("../../../utils/EventEmitter.js");
const IdWrapper_js_1 = require("../../../utils/IdWrapper.js");
const OutgoingMessage_js_1 = require("../../OutgoingMessage.js");
const events_js_1 = require("./events.js");
const SubscriptionManager_js_1 = require("./SubscriptionManager.js");
class EventWrapper {
#idWrapper = new IdWrapper_js_1.IdWrapper();
#contextId;
#event;
constructor(event, contextId) {
this.#event = event;
this.#contextId = contextId;
}
get id() {
return this.#idWrapper.id;
}
get contextId() {
return this.#contextId;
}
get event() {
return this.#event;
}
}
/**
* Maps event name to a desired buffer length.
*/
const eventBufferLength = new Map([[protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded, 100]]);
class EventManager extends EventEmitter_js_1.EventEmitter {
/**
* Maps event name to a set of contexts where this event already happened.
* Needed for getting buffered events from all the contexts in case of
* subscripting to all contexts.
*/
#eventToContextsMap = new DefaultMap_js_1.DefaultMap(() => new Set());
/**
* Maps `eventName` + `browsingContext` to buffer. Used to get buffered events
* during subscription. Channel-agnostic.
*/
#eventBuffers = new Map();
/**
* Maps `eventName` + `browsingContext` + `channel` to last sent event id.
* Used to avoid sending duplicated events when user
* subscribes -> unsubscribes -> subscribes.
*/
#lastMessageSent = new Map();
#subscriptionManager;
#browsingContextStorage;
constructor(browsingContextStorage) {
super();
this.#browsingContextStorage = browsingContextStorage;
this.#subscriptionManager = new SubscriptionManager_js_1.SubscriptionManager(browsingContextStorage);
}
/**
* Returns consistent key to be used to access value maps.
*/
static #getMapKey(eventName, browsingContext, channel) {
return JSON.stringify({ eventName, browsingContext, channel });
}
registerEvent(event, contextId) {
this.registerPromiseEvent(Promise.resolve({
kind: 'success',
value: event,
}), contextId, event.method);
}
registerPromiseEvent(event, contextId, eventName) {
const eventWrapper = new EventWrapper(event, contextId);
const sortedChannels = this.#subscriptionManager.getChannelsSubscribedToEvent(eventName, contextId);
this.#bufferEvent(eventWrapper, eventName);
// Send events to channels in the subscription priority.
for (const channel of sortedChannels) {
this.emit("event" /* EventManagerEvents.Event */, {
message: OutgoingMessage_js_1.OutgoingMessage.createFromPromise(event, channel),
event: eventName,
});
this.#markEventSent(eventWrapper, channel, eventName);
}
}
subscribe(eventNames, contextIds, channel) {
for (const name of eventNames) {
(0, events_js_1.assertSupportedEvent)(name);
}
// First check if all the contexts are known.
for (const contextId of contextIds) {
if (contextId !== null) {
// Assert the context is known. Throw exception otherwise.
this.#browsingContextStorage.getContext(contextId);
}
}
for (const eventName of eventNames) {
for (const contextId of contextIds) {
this.#subscriptionManager.subscribe(eventName, contextId, channel);
for (const eventWrapper of this.#getBufferedEvents(eventName, contextId, channel)) {
// The order of the events is important.
this.emit("event" /* EventManagerEvents.Event */, {
message: OutgoingMessage_js_1.OutgoingMessage.createFromPromise(eventWrapper.event, channel),
event: eventName,
});
this.#markEventSent(eventWrapper, channel, eventName);
}
}
}
}
unsubscribe(eventNames, contextIds, channel) {
for (const name of eventNames) {
(0, events_js_1.assertSupportedEvent)(name);
}
this.#subscriptionManager.unsubscribeAll(eventNames, contextIds, channel);
}
/**
* If the event is buffer-able, put it in the buffer.
*/
#bufferEvent(eventWrapper, eventName) {
if (!eventBufferLength.has(eventName)) {
// Do nothing if the event is no buffer-able.
return;
}
const bufferMapKey = EventManager.#getMapKey(eventName, eventWrapper.contextId);
if (!this.#eventBuffers.has(bufferMapKey)) {
this.#eventBuffers.set(bufferMapKey, new Buffer_js_1.Buffer(eventBufferLength.get(eventName)));
}
this.#eventBuffers.get(bufferMapKey).add(eventWrapper);
// Add the context to the list of contexts having `eventName` events.
this.#eventToContextsMap.get(eventName).add(eventWrapper.contextId);
}
/**
* If the event is buffer-able, mark it as sent to the given contextId and channel.
*/
#markEventSent(eventWrapper, channel, eventName) {
if (!eventBufferLength.has(eventName)) {
// Do nothing if the event is no buffer-able.
return;
}
const lastSentMapKey = EventManager.#getMapKey(eventName, eventWrapper.contextId, channel);
this.#lastMessageSent.set(lastSentMapKey, Math.max(this.#lastMessageSent.get(lastSentMapKey) ?? 0, eventWrapper.id));
}
/**
* Returns events which are buffered and not yet sent to the given channel events.
*/
#getBufferedEvents(eventName, contextId, channel) {
const bufferMapKey = EventManager.#getMapKey(eventName, contextId);
const lastSentMapKey = EventManager.#getMapKey(eventName, contextId, channel);
const lastSentMessageId = this.#lastMessageSent.get(lastSentMapKey) ?? -Infinity;
const result = this.#eventBuffers
.get(bufferMapKey)
?.get()
.filter((wrapper) => wrapper.id > lastSentMessageId) ?? [];
if (contextId === null) {
// For global subscriptions, events buffered in each context should be sent back.
Array.from(this.#eventToContextsMap.get(eventName).keys())
.filter((_contextId) =>
// Events without context are already in the result.
_contextId !== null &&
// Events from deleted contexts should not be sent.
this.#browsingContextStorage.hasContext(_contextId))
.map((_contextId) => this.#getBufferedEvents(eventName, _contextId, channel))
.forEach((events) => result.push(...events));
}
return result.sort((e1, e2) => e1.id - e2.id);
}
}
exports.EventManager = EventManager;
//# sourceMappingURL=EventManager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
/**
* Copyright 2023 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { BidiPlusChannel } from '../../../protocol/chromium-bidi.js';
import type { EmptyResult, Session } from '../../../protocol/protocol.js';
import type { EventManager } from './EventManager.js';
export declare class SessionProcessor {
#private;
constructor(eventManager: EventManager);
status(): Session.StatusResult;
subscribe(params: Session.SubscriptionRequest, channel?: BidiPlusChannel): EmptyResult;
unsubscribe(params: Session.SubscriptionRequest, channel?: BidiPlusChannel): EmptyResult;
}

View File

@@ -0,0 +1,38 @@
"use strict";
/**
* Copyright 2023 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionProcessor = void 0;
class SessionProcessor {
#eventManager;
constructor(eventManager) {
this.#eventManager = eventManager;
}
status() {
return { ready: false, message: 'already connected' };
}
subscribe(params, channel = null) {
this.#eventManager.subscribe(params.events, params.contexts ?? [null], channel);
return {};
}
unsubscribe(params, channel = null) {
this.#eventManager.unsubscribe(params.events, params.contexts ?? [null], channel);
return {};
}
}
exports.SessionProcessor = SessionProcessor;
//# sourceMappingURL=SessionProcessor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SessionProcessor.js","sourceRoot":"","sources":["../../../../../src/bidiMapper/domains/session/SessionProcessor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAWH,MAAa,gBAAgB;IAC3B,aAAa,CAAe;IAE5B,YAAY,YAA0B;QACpC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,MAAM;QACJ,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAC,CAAC;IACtD,CAAC;IAED,SAAS,CACP,MAAmC,EACnC,UAA2B,IAAI;QAE/B,IAAI,CAAC,aAAa,CAAC,SAAS,CAC1B,MAAM,CAAC,MAAmC,EAC1C,MAAM,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,EACzB,OAAO,CACR,CAAC;QACF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,WAAW,CACT,MAAmC,EACnC,UAA2B,IAAI;QAE/B,IAAI,CAAC,aAAa,CAAC,WAAW,CAC5B,MAAM,CAAC,MAAmC,EAC1C,MAAM,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,EACzB,OAAO,CACR,CAAC;QACF,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAlCD,4CAkCC"}

View File

@@ -0,0 +1,43 @@
/**
* Copyright 2022 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { BidiPlusChannel } from '../../../protocol/chromium-bidi.js';
import { ChromiumBidi, type BrowsingContext } from '../../../protocol/protocol.js';
import type { BrowsingContextStorage } from '../context/BrowsingContextStorage.js';
/**
* Returns the cartesian product of the given arrays.
*
* Example:
* cartesian([1, 2], ['a', 'b']); => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
*/
export declare function cartesianProduct(...a: any[][]): any[];
/** Expands "AllEvents" events into atomic events. */
export declare function unrollEvents(events: ChromiumBidi.EventNames[]): ChromiumBidi.EventNames[];
export declare class SubscriptionManager {
#private;
constructor(browsingContextStorage: BrowsingContextStorage);
getChannelsSubscribedToEvent(eventMethod: ChromiumBidi.EventNames, contextId: BrowsingContext.BrowsingContext | null): BidiPlusChannel[];
subscribe(event: ChromiumBidi.EventNames, contextId: BrowsingContext.BrowsingContext | null, channel: BidiPlusChannel): void;
/**
* Unsubscribes atomically from all events in the given contexts and channel.
*/
unsubscribeAll(events: ChromiumBidi.EventNames[], contextIds: (BrowsingContext.BrowsingContext | null)[], channel: BidiPlusChannel): void;
/**
* Unsubscribes from the event in the given context and channel.
* Syntactic sugar for "unsubscribeAll".
*/
unsubscribe(eventName: ChromiumBidi.EventNames, contextId: BrowsingContext.BrowsingContext | null, channel: BidiPlusChannel): void;
}

View File

@@ -0,0 +1,206 @@
"use strict";
/**
* Copyright 2022 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionManager = exports.unrollEvents = exports.cartesianProduct = void 0;
const protocol_js_1 = require("../../../protocol/protocol.js");
const events_js_1 = require("./events.js");
/**
* Returns the cartesian product of the given arrays.
*
* Example:
* cartesian([1, 2], ['a', 'b']); => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
*/
function cartesianProduct(...a) {
return a.reduce((a, b) => a.flatMap((d) => b.map((e) => [d, e].flat())));
}
exports.cartesianProduct = cartesianProduct;
/** Expands "AllEvents" events into atomic events. */
function unrollEvents(events) {
const allEvents = new Set();
function addEvents(events) {
for (const event of events) {
allEvents.add(event);
}
}
for (const event of events) {
switch (event) {
case protocol_js_1.ChromiumBidi.BiDiModule.BrowsingContext:
addEvents(Object.values(protocol_js_1.ChromiumBidi.BrowsingContext.EventNames));
break;
case protocol_js_1.ChromiumBidi.BiDiModule.Log:
addEvents(Object.values(protocol_js_1.ChromiumBidi.Log.EventNames));
break;
case protocol_js_1.ChromiumBidi.BiDiModule.Network:
addEvents(Object.values(protocol_js_1.ChromiumBidi.Network.EventNames));
break;
case protocol_js_1.ChromiumBidi.BiDiModule.Script:
addEvents(Object.values(protocol_js_1.ChromiumBidi.Script.EventNames));
break;
default:
allEvents.add(event);
}
}
return [...allEvents.values()];
}
exports.unrollEvents = unrollEvents;
class SubscriptionManager {
#subscriptionPriority = 0;
// BrowsingContext `null` means the event has subscription across all the
// browsing contexts.
// Channel `null` means no `channel` should be added.
#channelToContextToEventMap = new Map();
#browsingContextStorage;
constructor(browsingContextStorage) {
this.#browsingContextStorage = browsingContextStorage;
}
getChannelsSubscribedToEvent(eventMethod, contextId) {
const prioritiesAndChannels = Array.from(this.#channelToContextToEventMap.keys())
.map((channel) => ({
priority: this.#getEventSubscriptionPriorityForChannel(eventMethod, contextId, channel),
channel,
}))
.filter(({ priority }) => priority !== null);
// Sort channels by priority.
return prioritiesAndChannels
.sort((a, b) => a.priority - b.priority)
.map(({ channel }) => channel);
}
#getEventSubscriptionPriorityForChannel(eventMethod, contextId, channel) {
const contextToEventMap = this.#channelToContextToEventMap.get(channel);
if (contextToEventMap === undefined) {
return null;
}
const maybeTopLevelContextId = this.#browsingContextStorage.findTopLevelContextId(contextId);
// `null` covers global subscription.
const relevantContexts = [...new Set([null, maybeTopLevelContextId])];
// Get all the subscription priorities.
const priorities = relevantContexts
.map((context) => {
// Get the priority for exact event name
const priority = contextToEventMap.get(context)?.get(eventMethod);
// For CDP we can't provide specific event name when subscribing
// to the module directly.
// Because of that we need to see event `cdp` exits in the map.
if ((0, events_js_1.isCdpEvent)(eventMethod)) {
const cdpPriority = contextToEventMap
.get(context)
?.get(protocol_js_1.ChromiumBidi.BiDiModule.Cdp);
// If we subscribe to the event directly and `cdp` module as well
// priority will be different we take minimal priority
return priority && cdpPriority
? Math.min(priority, cdpPriority)
: // At this point we know that we have subscribed
// to only one of the two
priority ?? cdpPriority;
}
return priority;
})
.filter((p) => p !== undefined);
if (priorities.length === 0) {
// Not subscribed, return null.
return null;
}
// Return minimal priority.
return Math.min(...priorities);
}
subscribe(event, contextId, channel) {
// All the subscriptions are handled on the top-level contexts.
contextId = this.#browsingContextStorage.findTopLevelContextId(contextId);
// Check if subscribed event is a whole module
switch (event) {
case protocol_js_1.ChromiumBidi.BiDiModule.BrowsingContext:
Object.values(protocol_js_1.ChromiumBidi.BrowsingContext.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
return;
case protocol_js_1.ChromiumBidi.BiDiModule.Log:
Object.values(protocol_js_1.ChromiumBidi.Log.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
return;
case protocol_js_1.ChromiumBidi.BiDiModule.Network:
Object.values(protocol_js_1.ChromiumBidi.Network.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
return;
case protocol_js_1.ChromiumBidi.BiDiModule.Script:
Object.values(protocol_js_1.ChromiumBidi.Script.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
return;
default:
// Intentionally left empty.
}
if (!this.#channelToContextToEventMap.has(channel)) {
this.#channelToContextToEventMap.set(channel, new Map());
}
const contextToEventMap = this.#channelToContextToEventMap.get(channel);
if (!contextToEventMap.has(contextId)) {
contextToEventMap.set(contextId, new Map());
}
const eventMap = contextToEventMap.get(contextId);
// Do not re-subscribe to events to keep the priority.
if (eventMap.has(event)) {
return;
}
eventMap.set(event, this.#subscriptionPriority++);
}
/**
* Unsubscribes atomically from all events in the given contexts and channel.
*/
unsubscribeAll(events, contextIds, channel) {
// Assert all contexts are known.
for (const contextId of contextIds) {
if (contextId !== null) {
this.#browsingContextStorage.getContext(contextId);
}
}
const eventContextPairs = cartesianProduct(unrollEvents(events), contextIds);
// Assert all unsubscriptions are valid.
// If any of the unsubscriptions are invalid, do not unsubscribe from anything.
eventContextPairs
.map(([event, contextId]) => this.#checkUnsubscribe(event, contextId, channel))
.forEach((unsubscribe) => unsubscribe());
}
/**
* Unsubscribes from the event in the given context and channel.
* Syntactic sugar for "unsubscribeAll".
*/
unsubscribe(eventName, contextId, channel) {
this.unsubscribeAll([eventName], [contextId], channel);
}
#checkUnsubscribe(event, contextId, channel) {
// All the subscriptions are handled on the top-level contexts.
contextId = this.#browsingContextStorage.findTopLevelContextId(contextId);
if (!this.#channelToContextToEventMap.has(channel)) {
throw new protocol_js_1.InvalidArgumentException(`Cannot unsubscribe from ${event}, ${contextId === null ? 'null' : contextId}. No subscription found.`);
}
const contextToEventMap = this.#channelToContextToEventMap.get(channel);
if (!contextToEventMap.has(contextId)) {
throw new protocol_js_1.InvalidArgumentException(`Cannot unsubscribe from ${event}, ${contextId === null ? 'null' : contextId}. No subscription found.`);
}
const eventMap = contextToEventMap.get(contextId);
if (!eventMap.has(event)) {
throw new protocol_js_1.InvalidArgumentException(`Cannot unsubscribe from ${event}, ${contextId === null ? 'null' : contextId}. No subscription found.`);
}
return () => {
eventMap.delete(event);
// Clean up maps if empty.
if (eventMap.size === 0) {
contextToEventMap.delete(event);
}
if (contextToEventMap.size === 0) {
this.#channelToContextToEventMap.delete(channel);
}
};
}
}
exports.SubscriptionManager = SubscriptionManager;
//# sourceMappingURL=SubscriptionManager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
/**
* Copyright 2023 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ChromiumBidi } from '../../../protocol/protocol.js';
/**
* Returns true if the given event is a CDP event.
* @see https://chromedevtools.github.io/devtools-protocol/
*/
export declare function isCdpEvent(name: string): boolean;
/**
* Asserts that the given event is known to BiDi or BiDi+, or throws otherwise.
*/
export declare function assertSupportedEvent(name: string): asserts name is ChromiumBidi.EventNames;

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertSupportedEvent = exports.isCdpEvent = void 0;
/**
* Copyright 2023 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const protocol_js_1 = require("../../../protocol/protocol.js");
/**
* Returns true if the given event is a CDP event.
* @see https://chromedevtools.github.io/devtools-protocol/
*/
function isCdpEvent(name) {
return (name.split('.').at(0)?.startsWith(protocol_js_1.ChromiumBidi.BiDiModule.Cdp) ?? false);
}
exports.isCdpEvent = isCdpEvent;
/**
* Asserts that the given event is known to BiDi or BiDi+, or throws otherwise.
*/
function assertSupportedEvent(name) {
if (!protocol_js_1.ChromiumBidi.EVENT_NAMES.has(name) && !isCdpEvent(name)) {
throw new protocol_js_1.InvalidArgumentException(`Unknown event: ${name}`);
}
}
exports.assertSupportedEvent = assertSupportedEvent;
//# sourceMappingURL=events.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../../src/bidiMapper/domains/session/events.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,+DAGuC;AAEvC;;;GAGG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,CACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,0BAAY,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CACxE,CAAC;AACJ,CAAC;AAJD,gCAIC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,IAAY;IAEZ,IAAI,CAAC,0BAAY,CAAC,WAAW,CAAC,GAAG,CAAC,IAAa,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,sCAAwB,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAND,oDAMC"}