first commit

This commit is contained in:
2026-06-02 20:24:26 -03:00
commit 7b8a8d722d
3354 changed files with 627959 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type { AwaitableIterable } from '../common/types.js';
/**
* @internal
*/
export declare class AsyncIterableUtil {
static map<T, U>(iterable: AwaitableIterable<T>, map: (item: T) => Promise<U>): AsyncIterable<U>;
static flatMap<T, U>(iterable: AwaitableIterable<T>, map: (item: T) => AwaitableIterable<U>): AsyncIterable<U>;
static collect<T>(iterable: AwaitableIterable<T>): Promise<T[]>;
static first<T>(iterable: AwaitableIterable<T>): Promise<T | undefined>;
}
//# sourceMappingURL=AsyncIterableUtil.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AsyncIterableUtil.d.ts","sourceRoot":"","sources":["../../../src/util/AsyncIterableUtil.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AAE1D;;GAEG;AACH,qBAAa,iBAAiB;WACd,GAAG,CAAC,CAAC,EAAE,CAAC,EACpB,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3B,aAAa,CAAC,CAAC,CAAC;WAML,OAAO,CAAC,CAAC,EAAE,CAAC,EACxB,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,GACrC,aAAa,CAAC,CAAC,CAAC;WAMN,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;WAQxD,KAAK,CAAC,CAAC,EAClB,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAM1B"}

View File

@@ -0,0 +1,29 @@
/**
* @internal
*/
export class AsyncIterableUtil {
static async *map(iterable, map) {
for await (const value of iterable) {
yield await map(value);
}
}
static async *flatMap(iterable, map) {
for await (const value of iterable) {
yield* map(value);
}
}
static async collect(iterable) {
const result = [];
for await (const value of iterable) {
result.push(value);
}
return result;
}
static async first(iterable) {
for await (const value of iterable) {
return value;
}
return;
}
}
//# sourceMappingURL=AsyncIterableUtil.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AsyncIterableUtil.js","sourceRoot":"","sources":["../../../src/util/AsyncIterableUtil.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CACf,QAA8B,EAC9B,GAA4B;QAE5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CACnB,QAA8B,EAC9B,GAAsC;QAEtC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YACnC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,QAA8B;QACpD,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,QAA8B;QAE9B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YACnC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO;IACT,CAAC;CACF"}

View File

@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { TimeoutError } from '../common/Errors.js';
/**
* @internal
*/
export interface DeferredOptions {
message: string;
timeout: number;
}
/**
* Creates and returns a deferred object along with the resolve/reject functions.
*
* If the deferred has not been resolved/rejected within the `timeout` period,
* the deferred gets resolves with a timeout error. `timeout` has to be greater than 0 or
* it is ignored.
*
* @internal
*/
export declare class Deferred<T, V extends Error = Error> {
#private;
static create<R, X extends Error = Error>(opts?: DeferredOptions): Deferred<R, X>;
static race<R>(awaitables: Array<Promise<R> | Deferred<R>>): Promise<R>;
constructor(opts?: DeferredOptions);
resolve(value: T): void;
reject(error: V | TimeoutError): void;
resolved(): boolean;
finished(): boolean;
value(): T | V | TimeoutError | undefined;
valueOrThrow(): Promise<T>;
}
//# sourceMappingURL=Deferred.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Deferred.d.ts","sourceRoot":"","sources":["../../../src/util/Deferred.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,GAAG,KAAK;;IAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,GAAG,KAAK,EACtC,IAAI,CAAC,EAAE,eAAe,GACrB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;WAIJ,IAAI,CAAC,CAAC,EACjB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC;gBAsCD,IAAI,CAAC,EAAE,eAAe;IAelC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAQvB,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,YAAY,GAAG,IAAI;IAQrC,QAAQ,IAAI,OAAO;IAInB,QAAQ,IAAI,OAAO;IAInB,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,YAAY,GAAG,SAAS;IAKzC,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC;CAY3B"}

View File

@@ -0,0 +1,105 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { TimeoutError } from '../common/Errors.js';
/**
* Creates and returns a deferred object along with the resolve/reject functions.
*
* If the deferred has not been resolved/rejected within the `timeout` period,
* the deferred gets resolves with a timeout error. `timeout` has to be greater than 0 or
* it is ignored.
*
* @internal
*/
export class Deferred {
static create(opts) {
return new Deferred(opts);
}
static async race(awaitables) {
const deferredWithTimeout = new Set();
try {
const promises = awaitables.map(value => {
if (value instanceof Deferred) {
if (value.#timeoutId) {
deferredWithTimeout.add(value);
}
return value.valueOrThrow();
}
return value;
});
// eslint-disable-next-line no-restricted-syntax
return await Promise.race(promises);
}
finally {
for (const deferred of deferredWithTimeout) {
// We need to stop the timeout else
// Node.JS will keep running the event loop till the
// timer executes
deferred.reject(new Error('Timeout cleared'));
}
}
}
#isResolved = false;
#isRejected = false;
#value;
// SAFETY: This is ensured by #taskPromise.
#resolve;
// TODO: Switch to Promise.withResolvers with Node 22
#taskPromise = new Promise(resolve => {
this.#resolve = resolve;
});
#timeoutId;
#timeoutError;
constructor(opts) {
if (opts && opts.timeout > 0) {
this.#timeoutError = new TimeoutError(opts.message);
this.#timeoutId = setTimeout(() => {
this.reject(this.#timeoutError);
}, opts.timeout);
}
}
#finish(value) {
clearTimeout(this.#timeoutId);
this.#value = value;
this.#resolve();
}
resolve(value) {
if (this.#isRejected || this.#isResolved) {
return;
}
this.#isResolved = true;
this.#finish(value);
}
reject(error) {
if (this.#isRejected || this.#isResolved) {
return;
}
this.#isRejected = true;
this.#finish(error);
}
resolved() {
return this.#isResolved;
}
finished() {
return this.#isResolved || this.#isRejected;
}
value() {
return this.#value;
}
#promise;
valueOrThrow() {
if (!this.#promise) {
this.#promise = (async () => {
await this.#taskPromise;
if (this.#isRejected) {
throw this.#value;
}
return this.#value;
})();
}
return this.#promise;
}
}
//# sourceMappingURL=Deferred.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Deferred.js","sourceRoot":"","sources":["../../../src/util/Deferred.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAUjD;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAQ;IACnB,MAAM,CAAC,MAAM,CACX,IAAsB;QAEtB,OAAO,IAAI,QAAQ,CAAO,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,UAA2C;QAE3C,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAe,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;gBACtC,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;oBAC9B,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;wBACrB,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACjC,CAAC;oBAED,OAAO,KAAK,CAAC,YAAY,EAAE,CAAC;gBAC9B,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;YACH,gDAAgD;YAChD,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;gBAAS,CAAC;YACT,KAAK,MAAM,QAAQ,IAAI,mBAAmB,EAAE,CAAC;gBAC3C,mCAAmC;gBACnC,oDAAoD;gBACpD,iBAAiB;gB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T,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;IAC9C,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ,CAAyB;IACjC,YAAY;QACV,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,CAAC,KAAK,IAAI,EAAE;gBAC1B,MAAM,IAAI,CAAC,YAAY,CAAC;gBACxB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;oBACrB,MAAM,IAAI,CAAC,MAAM,CAAC;gBACpB,CAAC;gBACD,OAAO,IAAI,CAAC,MAAW,CAAC;YAC1B,CAAC,CAAC,EAAE,CAAC;QACP,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}

View File

@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type { ProtocolError } from '../common/Errors.js';
/**
* @internal
*/
export interface ErrorLike extends Error {
name: string;
message: string;
}
/**
* @internal
*/
export declare function isErrorLike(obj: unknown): obj is ErrorLike;
/**
* @internal
*/
export declare function isErrnoException(obj: unknown): obj is NodeJS.ErrnoException;
/**
* @internal
*/
export declare function rewriteError(error: ProtocolError, message: string, originalMessage?: string): Error;
/**
* @internal
*/
export declare function createProtocolErrorMessage(object: {
error: {
message: string;
data: any;
code: number;
};
}): string;
//# sourceMappingURL=ErrorLike.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ErrorLike.d.ts","sourceRoot":"","sources":["../../../src/util/ErrorLike.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAI1D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,cAAc,CAK3E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,GACvB,KAAK,CAIP;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,KAAK,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC;CACnD,GAAG,MAAM,CAYT"}

View File

@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @internal
*/
export function isErrorLike(obj) {
return (typeof obj === 'object' && obj !== null && 'name' in obj && 'message' in obj);
}
/**
* @internal
*/
export function isErrnoException(obj) {
return (isErrorLike(obj) &&
('errno' in obj || 'code' in obj || 'path' in obj || 'syscall' in obj));
}
/**
* @internal
*/
export function rewriteError(error, message, originalMessage) {
error.message = message;
error.originalMessage = originalMessage ?? error.originalMessage;
return error;
}
/**
* @internal
*/
export function createProtocolErrorMessage(object) {
let message = object.error.message;
// TODO: remove the type checks when we stop connecting to BiDi with a CDP
// client.
if (object.error &&
typeof object.error === 'object' &&
'data' in object.error) {
message += ` ${object.error.data}`;
}
return message;
}
//# sourceMappingURL=ErrorLike.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ErrorLike.js","sourceRoot":"","sources":["../../../src/util/ErrorLike.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,MAAM,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,CAC7E,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,OAAO,CACL,WAAW,CAAC,GAAG,CAAC;QAChB,CAAC,OAAO,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC,CACvE,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAoB,EACpB,OAAe,EACf,eAAwB;IAExB,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,KAAK,CAAC,eAAe,GAAG,eAAe,IAAI,KAAK,CAAC,eAAe,CAAC;IACjE,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAE1C;IACC,IAAI,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;IACnC,0EAA0E;IAC1E,UAAU;IACV,IACE,MAAM,CAAC,KAAK;QACZ,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAChC,MAAM,IAAI,MAAM,CAAC,KAAK,EACtB,CAAC;QACD,OAAO,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}

View File

@@ -0,0 +1,34 @@
/**
* Creates a function from a string.
*
* @internal
*/
export declare const createFunction: (functionValue: string) => ((...args: unknown[]) => unknown);
/**
* @internal
*/
export declare function stringifyFunction(fn: (...args: never) => unknown): string;
/**
* Replaces `PLACEHOLDER`s with the given replacements.
*
* All replacements must be valid JS code.
*
* @example
*
* ```ts
* interpolateFunction(() => PLACEHOLDER('test'), {test: 'void 0'});
* // Equivalent to () => void 0
* ```
*
* @internal
*/
export declare const interpolateFunction: <T extends (...args: never[]) => unknown>(fn: T, replacements: Record<string, string>) => T;
declare global {
/**
* Used for interpolation with {@link interpolateFunction}.
*
* @internal
*/
function PLACEHOLDER<T>(name: string): T;
}
//# sourceMappingURL=Function.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Function.d.ts","sourceRoot":"","sources":["../../../src/util/Function.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,eAAe,MAAM,KACpB,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAUlC,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAAG,MAAM,CAyBzE;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EACzE,IAAI,CAAC,EACL,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACnC,CAYF,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;CAC1C"}

View File

@@ -0,0 +1,70 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
const createdFunctions = new Map();
/**
* Creates a function from a string.
*
* @internal
*/
export const createFunction = (functionValue) => {
let fn = createdFunctions.get(functionValue);
if (fn) {
return fn;
}
fn = new Function(`return ${functionValue}`)();
createdFunctions.set(functionValue, fn);
return fn;
};
/**
* @internal
*/
export function stringifyFunction(fn) {
let value = fn.toString();
if (value.match(/^(async )*function(\(|\s)/) ||
value.match(/^(async )*function\s*\*\s*/)) {
return value;
}
const isArrow = value.startsWith('(') ||
value.match(/^async\s*\(/) ||
value.match(/^(async)*\s*(?:[$_\p{ID_Start}])(?:[$\u200C\u200D\p{ID_Continue}])*\s*=>/u);
if (isArrow) {
return value;
}
// This means we might have a function shorthand (e.g. `test(){}`). Let's
// try prefixing.
let prefix = 'function ';
if (value.startsWith('async ')) {
prefix = `async ${prefix}`;
value = value.substring('async '.length);
}
return `${prefix}${value}`;
}
/**
* Replaces `PLACEHOLDER`s with the given replacements.
*
* All replacements must be valid JS code.
*
* @example
*
* ```ts
* interpolateFunction(() => PLACEHOLDER('test'), {test: 'void 0'});
* // Equivalent to () => void 0
* ```
*
* @internal
*/
export const interpolateFunction = (fn, replacements) => {
let value = stringifyFunction(fn);
for (const [name, jsValue] of Object.entries(replacements)) {
value = value.replace(new RegExp(`PLACEHOLDER\\(\\s*(?:'${name}'|"${name}")\\s*\\)`, 'g'),
// Wrapping this ensures tersers that accidentally inline PLACEHOLDER calls
// are still valid. Without, we may get calls like ()=>{...}() which is
// not valid.
`(${jsValue})`);
}
return createFunction(value);
};
//# sourceMappingURL=Function.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Function.js","sourceRoot":"","sources":["../../../src/util/Function.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA2C,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,aAAqB,EACc,EAAE;IACrC,IAAI,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC7C,IAAI,EAAE,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,EAAE,GAAG,IAAI,QAAQ,CAAC,UAAU,aAAa,EAAE,CAAC,EAEhC,CAAC;IACb,gBAAgB,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE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uE;QACvE,aAAa;QACb,IAAI,OAAO,GAAG,CACf,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC,KAAK,CAAiB,CAAC;AAC/C,CAAC,CAAC"}

View File

@@ -0,0 +1,17 @@
import { disposeSymbol } from './disposable.js';
/**
* @internal
*/
export declare class Mutex {
#private;
static Guard: {
new (mutex: Mutex, onRelease?: () => void): {
"__#200@#mutex": Mutex;
"__#200@#onRelease"?: () => void;
[Symbol.dispose](): void;
};
};
acquire(onRelease?: () => void): Promise<InstanceType<typeof Mutex.Guard>>;
release(): void;
}
//# sourceMappingURL=Mutex.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Mutex.d.ts","sourceRoot":"","sources":["../../../src/util/Mutex.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,qBAAa,KAAK;;IAChB,MAAM,CAAC,KAAK;oBAGS,KAAK,cAAc,MAAM,IAAI;6BAFxC,KAAK;kCACA,MAAM,IAAI;gCAKJ,IAAI;;MAIvB;IAMI,OAAO,CACX,SAAS,CAAC,EAAE,MAAM,IAAI,GACrB,OAAO,CAAC,YAAY,CAAC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IAW5C,OAAO,IAAI,IAAI;CAQhB"}

View File

@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { Deferred } from './Deferred.js';
import { disposeSymbol } from './disposable.js';
/**
* @internal
*/
export class Mutex {
static Guard = class Guard {
#mutex;
#onRelease;
constructor(mutex, onRelease) {
this.#mutex = mutex;
this.#onRelease = onRelease;
}
[disposeSymbol]() {
this.#onRelease?.();
return this.#mutex.release();
}
};
#locked = false;
#acquirers = [];
// This is FIFO.
async acquire(onRelease) {
if (!this.#locked) {
this.#locked = true;
return new Mutex.Guard(this, onRelease);
}
const deferred = Deferred.create();
this.#acquirers.push(deferred.resolve.bind(deferred));
await deferred.valueOrThrow();
return new Mutex.Guard(this, onRelease);
}
release() {
const resolve = this.#acquirers.shift();
if (!resolve) {
this.#locked = false;
return;
}
resolve();
}
}
//# sourceMappingURL=Mutex.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Mutex.js","sourceRoot":"","sources":["../../../src/util/Mutex.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,KAAK;IAChB,MAAM,CAAC,KAAK,GAAG,MAAM,KAAK;QACxB,MAAM,CAAQ;QACd,UAAU,CAAc;QACxB,YAAY,KAAY,EAAE,SAAsB;YAC9C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC9B,CAAC;QACD,CAAC,aAAa,CAAC;YACb,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC;KACF,CAAC;IAEF,OAAO,GAAG,KAAK,CAAC;IAChB,UAAU,GAAsB,EAAE,CAAC;IAEnC,gBAAgB;IAChB,KAAK,CAAC,OAAO,CACX,SAAsB;QAEtB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,EAAQ,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtD,MAAM,QAAQ,CAAC,YAAY,EAAE,CAAC;QAC9B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,OAAO;QACT,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC"}

View File

@@ -0,0 +1,14 @@
/**
* @license
* Copyright 2020 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Asserts that the given value is truthy.
* @param value - some conditional statement
* @param message - the error message to throw if the value is not truthy.
*
* @internal
*/
export declare const assert: (value: unknown, message?: string) => asserts value;
//# sourceMappingURL=assert.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/util/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,KAOlE,CAAC"}

View File

@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2020 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Asserts that the given value is truthy.
* @param value - some conditional statement
* @param message - the error message to throw if the value is not truthy.
*
* @internal
*/
export const assert = (value, message) => {
if (!value) {
throw new Error(message);
}
};
//# sourceMappingURL=assert.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../../src/util/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GAAwD,CACzE,KAAK,EACL,OAAO,EACP,EAAE;IACF,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC,CAAC"}

View File

@@ -0,0 +1,27 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type { EventType } from '../common/EventEmitter.js';
import type { EventEmitter } from '../common/EventEmitter.js';
import type { Disposed, Moveable } from '../common/types.js';
export declare function moveable<Class extends abstract new (...args: never[]) => Moveable>(Class: Class, _: ClassDecoratorContext<Class>): Class;
export declare function throwIfDisposed<This extends Disposed>(message?: (value: This) => string): (target: (this: This, ...args: any[]) => any, _: unknown) => (this: This, ...args: any[]) => any;
export declare function inertIfDisposed<This extends Disposed>(target: (this: This, ...args: any[]) => any, _: unknown): (this: This, ...args: any[]) => any;
/**
* The decorator only invokes the target if the target has not been invoked with
* the same arguments before. The decorated method throws an error if it's
* invoked with a different number of elements: if you decorate a method, it
* should have the same number of arguments
*
* @internal
*/
export declare function invokeAtMostOnceForArguments(target: (this: unknown, ...args: any[]) => any, _: unknown): typeof target;
export declare function guarded<T extends object>(getKey?: (this: T) => object): (target: (this: T, ...args: any[]) => Promise<any>, _: ClassMethodDecoratorContext<T>) => typeof target;
/**
* Event emitter fields marked with `bubble` will have their events bubble up
* the field owner.
*/
export declare function bubble<T extends EventType[]>(events?: T): <This extends EventEmitter<any>, Value extends EventEmitter<any>>({ set, get }: ClassAccessorDecoratorTarget<This, Value>, context: ClassAccessorDecoratorContext<This, Value>) => ClassAccessorDecoratorResult<This, Value>;
//# sourceMappingURL=decorators.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/util/decorators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAO3D,wBAAgB,QAAQ,CACtB,KAAK,SAAS,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AAS,YAAY,CAAC,GAAG,CAAC,EACrE,cAAY,4BAA4B,CAAC,IAAI,EAAE,KAAK,CAAC,EACrD,SAAS,6BAA6B,CAAC,IAAI,EAAE,KAAK,CAAC,KAClD,4BAA4B,CAAC,IAAI,EAAE,KAAK,CAAC,CAiC7C"}

View File

@@ -0,0 +1,232 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
if (value !== null && value !== void 0) {
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
var dispose, inner;
if (async) {
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
dispose = value[Symbol.asyncDispose];
}
if (dispose === void 0) {
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
dispose = value[Symbol.dispose];
if (async) inner = dispose;
}
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
env.stack.push({ value: value, dispose: dispose, async: async });
}
else if (async) {
env.stack.push({ async: true });
}
return value;
};
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
return function (env) {
function fail(e) {
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
env.hasError = true;
}
var r, s = 0;
function next() {
while (r = env.stack.pop()) {
try {
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
if (r.dispose) {
var result = r.dispose.call(r.value);
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
}
else s |= 1;
}
catch (e) {
fail(e);
}
}
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
if (env.hasError) throw env.error;
}
return next();
};
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
});
import { asyncDisposeSymbol, disposeSymbol } from './disposable.js';
import { Mutex } from './Mutex.js';
const instances = new WeakSet();
export function moveable(Class, _) {
let hasDispose = false;
if (Class.prototype[disposeSymbol]) {
const dispose = Class.prototype[disposeSymbol];
Class.prototype[disposeSymbol] = function () {
if (instances.has(this)) {
instances.delete(this);
return;
}
return dispose.call(this);
};
hasDispose = true;
}
if (Class.prototype[asyncDisposeSymbol]) {
const asyncDispose = Class.prototype[asyncDisposeSymbol];
Class.prototype[asyncDisposeSymbol] = function () {
if (instances.has(this)) {
instances.delete(this);
return;
}
return asyncDispose.call(this);
};
hasDispose = true;
}
if (hasDispose) {
Class.prototype.move = function () {
instances.add(this);
return this;
};
}
return Class;
}
export function throwIfDisposed(message = value => {
return `Attempted to use disposed ${value.constructor.name}.`;
}) {
return (target, _) => {
return function (...args) {
if (this.disposed) {
throw new Error(message(this));
}
return target.call(this, ...args);
};
};
}
export function inertIfDisposed(target, _) {
return function (...args) {
if (this.disposed) {
return;
}
return target.call(this, ...args);
};
}
/**
* The decorator only invokes the target if the target has not been invoked with
* the same arguments before. The decorated method throws an error if it's
* invoked with a different number of elements: if you decorate a method, it
* should have the same number of arguments
*
* @internal
*/
export function invokeAtMostOnceForArguments(target, _) {
const cache = new WeakMap();
let cacheDepth = -1;
return function (...args) {
if (cacheDepth === -1) {
cacheDepth = args.length;
}
if (cacheDepth !== args.length) {
throw new Error('Memoized method was called with the wrong number of arguments');
}
let freshArguments = false;
let cacheIterator = cache;
for (const arg of args) {
if (cacheIterator.has(arg)) {
cacheIterator = cacheIterator.get(arg);
}
else {
freshArguments = true;
cacheIterator.set(arg, new WeakMap());
cacheIterator = cacheIterator.get(arg);
}
}
if (!freshArguments) {
return;
}
return target.call(this, ...args);
};
}
export function guarded(getKey = function () {
return this;
}) {
return (target, _) => {
const mutexes = new WeakMap();
return async function (...args) {
const env_1 = { stack: [], error: void 0, hasError: false };
try {
const key = getKey.call(this);
let mutex = mutexes.get(key);
if (!mutex) {
mutex = new Mutex();
mutexes.set(key, mutex);
}
const _ = __addDisposableResource(env_1, await mutex.acquire(), true);
return await target.call(this, ...args);
}
catch (e_1) {
env_1.error = e_1;
env_1.hasError = true;
}
finally {
const result_1 = __disposeResources(env_1);
if (result_1)
await result_1;
}
};
};
}
const bubbleHandlers = new WeakMap();
const bubbleInitializer = function (events) {
const handlers = bubbleHandlers.get(this) ?? new Map();
if (handlers.has(events)) {
return;
}
const handler = events !== undefined
? (type, event) => {
if (events.includes(type)) {
this.emit(type, event);
}
}
: (type, event) => {
this.emit(type, event);
};
handlers.set(events, handler);
bubbleHandlers.set(this, handlers);
};
/**
* Event emitter fields marked with `bubble` will have their events bubble up
* the field owner.
*/
// The type is too complicated to type.
export function bubble(events) {
return ({ set, get }, context) => {
context.addInitializer(function () {
return bubbleInitializer.apply(this, [events]);
});
return {
set(emitter) {
const handler = bubbleHandlers.get(this).get(events);
// In case we are re-setting.
const oldEmitter = get.call(this);
if (oldEmitter !== undefined) {
oldEmitter.off('*', handler);
}
if (emitter === undefined) {
return;
}
emitter.on('*', handler);
set.call(this, emitter);
},
init(emitter) {
if (emitter === undefined) {
return emitter;
}
bubbleInitializer.apply(this, [events]);
const handler = bubbleHandlers.get(this).get(events);
emitter.on('*', handler);
return emitter;
},
};
};
}
//# sourceMappingURL=decorators.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,218 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
declare global {
interface SymbolConstructor {
/**
* A method that is used to release resources held by an object. Called by
* the semantics of the `using` statement.
*/
readonly dispose: unique symbol;
/**
* A method that is used to asynchronously release resources held by an
* object. Called by the semantics of the `await using` statement.
*/
readonly asyncDispose: unique symbol;
}
interface Disposable {
[Symbol.dispose](): void;
}
interface AsyncDisposable {
[Symbol.asyncDispose](): PromiseLike<void>;
}
}
/**
* @internal
*/
export declare const disposeSymbol: typeof Symbol.dispose;
/**
* @internal
*/
export declare const asyncDisposeSymbol: typeof Symbol.asyncDispose;
/**
* @internal
*/
export declare class DisposableStackPolyfill {
#private;
/**
* Returns a value indicating whether the stack has been disposed.
*/
get disposed(): boolean;
/**
* Alias for `[Symbol.dispose]()`.
*/
dispose(): void;
/**
* Adds a disposable resource to the top of stack, returning the resource.
* Has no effect if provided `null` or `undefined`.
*
* @param value - A `Disposable` object, `null`, or `undefined`.
* `null` and `undefined` will not be added, but will be returned.
* @returns The provided `value`.
*/
use<T extends Disposable | null | undefined>(value: T): T;
/**
* Adds a non-disposable resource and a disposal callback to the top of the stack.
*
* @param value - A resource to be disposed.
* @param onDispose - A callback invoked to dispose the provided value.
* Will be invoked with `value` as the first parameter.
* @returns The provided `value`.
*/
adopt<T>(value: T, onDispose: (value: T) => void): T;
/**
* Add a disposal callback to the top of the stack to be invoked when stack is disposed.
* @param onDispose - A callback to invoke when this object is disposed.
*/
defer(onDispose: () => void): void;
/**
* Move all resources out of this stack and into a new `DisposableStack`, and
* marks this stack as disposed.
* @returns The new `DisposableStack`.
*
* @example
*
* ```ts
* class C {
* #res1: Disposable;
* #res2: Disposable;
* #disposables: DisposableStack;
* constructor() {
* // stack will be disposed when exiting constructor for any reason
* using stack = new DisposableStack();
*
* // get first resource
* this.#res1 = stack.use(getResource1());
*
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
* this.#res2 = stack.use(getResource2());
*
* // all operations succeeded, move resources out of `stack` so that
* // they aren't disposed when constructor exits
* this.#disposables = stack.move();
* }
*
* [disposeSymbol]() {
* this.#disposables.dispose();
* }
* }
* ```
*/
move(): DisposableStackPolyfill;
/**
* Disposes each resource in the stack in last-in-first-out (LIFO) manner.
*/
[disposeSymbol](): void;
readonly [Symbol.toStringTag] = "DisposableStack";
}
/**
* @internal
*/
export declare const DisposableStack: typeof DisposableStackPolyfill;
/**
* @internal
*/
export declare class AsyncDisposableStackPolyfill {
#private;
/**
* Returns a value indicating whether the stack has been disposed.
*/
get disposed(): boolean;
/**
* Alias for `[Symbol.asyncDispose]()`.
*/
disposeAsync(): Promise<void>;
/**
* Adds a AsyncDisposable resource to the top of stack, returning the resource.
* Has no effect if provided `null` or `undefined`.
*
* @param value - A `AsyncDisposable` object, `null`, or `undefined`.
* `null` and `undefined` will not be added, but will be returned.
* @returns The provided `value`.
*/
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
/**
* Adds a non-disposable resource and a disposal callback to the top of the stack.
*
* @param value - A resource to be disposed.
* @param onDispose - A callback invoked to dispose the provided value.
* Will be invoked with `value` as the first parameter.
* @returns The provided `value`.
*/
adopt<T>(value: T, onDispose: (value: T) => Promise<void>): T;
/**
* Add a disposal callback to the top of the stack to be invoked when stack is disposed.
* @param onDispose - A callback to invoke when this object is disposed.
*/
defer(onDispose: () => Promise<void>): void;
/**
* Move all resources out of this stack and into a new `DisposableStack`, and
* marks this stack as disposed.
* @returns The new `AsyncDisposableStack`.
*
* @example
*
* ```ts
* class C {
* #res1: Disposable;
* #res2: Disposable;
* #disposables: DisposableStack;
* constructor() {
* // stack will be disposed when exiting constructor for any reason
* using stack = new DisposableStack();
*
* // get first resource
* this.#res1 = stack.use(getResource1());
*
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
* this.#res2 = stack.use(getResource2());
*
* // all operations succeeded, move resources out of `stack` so that
* // they aren't disposed when constructor exits
* this.#disposables = stack.move();
* }
*
* [disposeSymbol]() {
* this.#disposables.dispose();
* }
* }
* ```
*/
move(): AsyncDisposableStackPolyfill;
/**
* Disposes each resource in the stack in last-in-first-out (LIFO) manner.
*/
[asyncDisposeSymbol](): Promise<void>;
readonly [Symbol.toStringTag] = "AsyncDisposableStack";
}
/**
* @internal
*/
export declare const AsyncDisposableStack: typeof AsyncDisposableStackPolyfill;
/**
* @internal
* Represents an error that occurs when multiple errors are thrown during
* the disposal of resources. This class encapsulates the primary error and
* any suppressed errors that occurred subsequently.
*/
declare class SuppressedErrorPolyfill extends Error {
#private;
constructor(error: unknown, suppressed: unknown, message?: string);
/**
* The primary error that occurred during disposal.
*/
get error(): unknown;
/**
* The suppressed error i.e. the error that was suppressed
* because it occurred later in the flow after the original error.
*/
get suppressed(): unknown;
}
/**
* @internal
*/
export declare const SuppressedError: typeof SuppressedErrorPolyfill;
export {};
//# sourceMappingURL=disposable.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../src/util/disposable.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB;;;WAGG;QACH,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAC;QAEhC;;;WAGG;QACH,QAAQ,CAAC,YAAY,EAAE,OAAO,MAAM,CAAC;KACtC;IAED,UAAU,UAAU;QAClB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;KAC1B;IAED,UAAU,eAAe;QACvB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;KAC5C;CACF;AAKD;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC,OAAwB,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAAO,MAAM,CAAC,YAC1B,CAAC;AAEtB;;GAEG;AACH,qBAAa,uBAAuB;;IAIlC;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;OAEG;IACH,OAAO,IAAI,IAAI;IAIf;;;;;;;OAOG;IACH,GAAG,CAAC,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAOzD;;;;;;;OAOG;IACH,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC;IASpD;;;OAGG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG,IAAI;IAQlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;O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eAAO,MAAM,eAAe,EAAE,OAAO,uBAC2B,CAAC"}

View File

@@ -0,0 +1,342 @@
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
Symbol.dispose ??= Symbol('dispose');
Symbol.asyncDispose ??= Symbol('asyncDispose');
/**
* @internal
*/
export const disposeSymbol = Symbol.dispose;
/**
* @internal
*/
export const asyncDisposeSymbol = Symbol.asyncDispose;
/**
* @internal
*/
export class DisposableStackPolyfill {
#disposed = false;
#stack = [];
/**
* Returns a value indicating whether the stack has been disposed.
*/
get disposed() {
return this.#disposed;
}
/**
* Alias for `[Symbol.dispose]()`.
*/
dispose() {
this[disposeSymbol]();
}
/**
* Adds a disposable resource to the top of stack, returning the resource.
* Has no effect if provided `null` or `undefined`.
*
* @param value - A `Disposable` object, `null`, or `undefined`.
* `null` and `undefined` will not be added, but will be returned.
* @returns The provided `value`.
*/
use(value) {
if (value && typeof value[disposeSymbol] === 'function') {
this.#stack.push(value);
}
return value;
}
/**
* Adds a non-disposable resource and a disposal callback to the top of the stack.
*
* @param value - A resource to be disposed.
* @param onDispose - A callback invoked to dispose the provided value.
* Will be invoked with `value` as the first parameter.
* @returns The provided `value`.
*/
adopt(value, onDispose) {
this.#stack.push({
[disposeSymbol]() {
onDispose(value);
},
});
return value;
}
/**
* Add a disposal callback to the top of the stack to be invoked when stack is disposed.
* @param onDispose - A callback to invoke when this object is disposed.
*/
defer(onDispose) {
this.#stack.push({
[disposeSymbol]() {
onDispose();
},
});
}
/**
* Move all resources out of this stack and into a new `DisposableStack`, and
* marks this stack as disposed.
* @returns The new `DisposableStack`.
*
* @example
*
* ```ts
* class C {
* #res1: Disposable;
* #res2: Disposable;
* #disposables: DisposableStack;
* constructor() {
* // stack will be disposed when exiting constructor for any reason
* using stack = new DisposableStack();
*
* // get first resource
* this.#res1 = stack.use(getResource1());
*
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
* this.#res2 = stack.use(getResource2());
*
* // all operations succeeded, move resources out of `stack` so that
* // they aren't disposed when constructor exits
* this.#disposables = stack.move();
* }
*
* [disposeSymbol]() {
* this.#disposables.dispose();
* }
* }
* ```
*/
move() {
if (this.#disposed) {
throw new ReferenceError('A disposed stack can not use anything new');
}
const stack = new DisposableStackPolyfill();
stack.#stack = this.#stack;
this.#stack = [];
this.#disposed = true;
return stack;
}
/**
* Disposes each resource in the stack in last-in-first-out (LIFO) manner.
*/
[disposeSymbol]() {
if (this.#disposed) {
return;
}
this.#disposed = true;
const errors = [];
for (const resource of this.#stack.reverse()) {
try {
resource[disposeSymbol]();
}
catch (e) {
errors.push(e);
}
}
if (errors.length === 1) {
throw errors[0];
}
else if (errors.length > 1) {
let suppressed = null;
for (const error of errors) {
if (suppressed === null) {
suppressed = error;
}
else {
suppressed = new SuppressedErrorPolyfill(error, suppressed);
}
}
throw suppressed;
}
}
[Symbol.toStringTag] = 'DisposableStack';
}
/**
* @internal
*/
export const DisposableStack = globalThis.DisposableStack ?? DisposableStackPolyfill;
/**
* @internal
*/
export class AsyncDisposableStackPolyfill {
#disposed = false;
#stack = [];
/**
* Returns a value indicating whether the stack has been disposed.
*/
get disposed() {
return this.#disposed;
}
/**
* Alias for `[Symbol.asyncDispose]()`.
*/
async disposeAsync() {
await this[asyncDisposeSymbol]();
}
/**
* Adds a AsyncDisposable resource to the top of stack, returning the resource.
* Has no effect if provided `null` or `undefined`.
*
* @param value - A `AsyncDisposable` object, `null`, or `undefined`.
* `null` and `undefined` will not be added, but will be returned.
* @returns The provided `value`.
*/
use(value) {
if (value) {
const asyncDispose = value[asyncDisposeSymbol];
const dispose = value[disposeSymbol];
if (typeof asyncDispose === 'function') {
this.#stack.push(value);
}
else if (typeof dispose === 'function') {
this.#stack.push({
[asyncDisposeSymbol]: async () => {
value[disposeSymbol]();
},
});
}
}
return value;
}
/**
* Adds a non-disposable resource and a disposal callback to the top of the stack.
*
* @param value - A resource to be disposed.
* @param onDispose - A callback invoked to dispose the provided value.
* Will be invoked with `value` as the first parameter.
* @returns The provided `value`.
*/
adopt(value, onDispose) {
this.#stack.push({
[asyncDisposeSymbol]() {
return onDispose(value);
},
});
return value;
}
/**
* Add a disposal callback to the top of the stack to be invoked when stack is disposed.
* @param onDispose - A callback to invoke when this object is disposed.
*/
defer(onDispose) {
this.#stack.push({
[asyncDisposeSymbol]() {
return onDispose();
},
});
}
/**
* Move all resources out of this stack and into a new `DisposableStack`, and
* marks this stack as disposed.
* @returns The new `AsyncDisposableStack`.
*
* @example
*
* ```ts
* class C {
* #res1: Disposable;
* #res2: Disposable;
* #disposables: DisposableStack;
* constructor() {
* // stack will be disposed when exiting constructor for any reason
* using stack = new DisposableStack();
*
* // get first resource
* this.#res1 = stack.use(getResource1());
*
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
* this.#res2 = stack.use(getResource2());
*
* // all operations succeeded, move resources out of `stack` so that
* // they aren't disposed when constructor exits
* this.#disposables = stack.move();
* }
*
* [disposeSymbol]() {
* this.#disposables.dispose();
* }
* }
* ```
*/
move() {
if (this.#disposed) {
throw new ReferenceError('A disposed stack can not use anything new');
}
const stack = new AsyncDisposableStackPolyfill();
stack.#stack = this.#stack;
this.#stack = [];
this.#disposed = true;
return stack;
}
/**
* Disposes each resource in the stack in last-in-first-out (LIFO) manner.
*/
async [asyncDisposeSymbol]() {
if (this.#disposed) {
return;
}
this.#disposed = true;
const errors = [];
for (const resource of this.#stack.reverse()) {
try {
await resource[asyncDisposeSymbol]();
}
catch (e) {
errors.push(e);
}
}
if (errors.length === 1) {
throw errors[0];
}
else if (errors.length > 1) {
let suppressed = null;
for (const error of errors) {
if (suppressed === null) {
suppressed = error;
}
else {
suppressed = new SuppressedErrorPolyfill(error, suppressed);
}
}
throw suppressed;
}
}
[Symbol.toStringTag] = 'AsyncDisposableStack';
}
/**
* @internal
*/
export const AsyncDisposableStack = globalThis.AsyncDisposableStack ?? AsyncDisposableStackPolyfill;
/**
* @internal
* Represents an error that occurs when multiple errors are thrown during
* the disposal of resources. This class encapsulates the primary error and
* any suppressed errors that occurred subsequently.
*/
class SuppressedErrorPolyfill extends Error {
#error;
#suppressed;
constructor(error, suppressed, message = 'An error was suppressed during disposal') {
super(message);
this.name = 'SuppressedError';
this.#error = error;
this.#suppressed = suppressed;
}
/**
* The primary error that occurred during disposal.
*/
get error() {
return this.#error;
}
/**
* The suppressed error i.e. the error that was suppressed
* because it occurred later in the flow after the original error.
*/
get suppressed() {
return this.#suppressed;
}
}
/**
* @internal
*/
export const SuppressedError = globalThis.SuppressedError ?? SuppressedErrorPolyfill;
//# sourceMappingURL=disposable.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @internal
*/
export declare function stringToTypedArray(string: string, base64Encoded?: boolean): Uint8Array;
/**
* @internal
*/
export declare function stringToBase64(str: string): string;
/**
* @internal
*/
export declare function typedArrayToBase64(typedArray: Uint8Array): string;
/**
* @internal
*/
export declare function mergeUint8Arrays(items: Uint8Array[]): Uint8Array;
//# sourceMappingURL=encoding.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../../src/util/encoding.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,aAAa,UAAQ,GACpB,UAAU,CAeZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAajE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAehE"}

View File

@@ -0,0 +1,63 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @internal
*/
export function stringToTypedArray(string, base64Encoded = false) {
if (base64Encoded) {
if ('fromBase64' in Uint8Array) {
// @ts-expect-error fromBase64 is newer than the types we use.
return Uint8Array.fromBase64(string);
}
// TODO: remove Buffer in v26 when it becomes LTS.
if (typeof Buffer === 'function') {
return Buffer.from(string, 'base64');
}
return Uint8Array.from(atob(string), m => {
return m.codePointAt(0);
});
}
return new TextEncoder().encode(string);
}
/**
* @internal
*/
export function stringToBase64(str) {
return typedArrayToBase64(new TextEncoder().encode(str));
}
/**
* @internal
*/
export function typedArrayToBase64(typedArray) {
// chunkSize should be less V8 limit on number of arguments!
// https://github.com/v8/v8/blob/d3de848bea727518aee94dd2fd42ba0b62037a27/src/objects/code.h#L444
const chunkSize = 65534;
const chunks = [];
for (let i = 0; i < typedArray.length; i += chunkSize) {
const chunk = typedArray.subarray(i, i + chunkSize);
chunks.push(String.fromCodePoint.apply(null, chunk));
}
const binaryString = chunks.join('');
return btoa(binaryString);
}
/**
* @internal
*/
export function mergeUint8Arrays(items) {
let length = 0;
for (const item of items) {
length += item.length;
}
// Create a new array with total length and merge all source arrays.
const result = new Uint8Array(length);
let offset = 0;
for (const item of items) {
result.set(item, offset);
offset += item.length;
}
return result;
}
//# sourceMappingURL=encoding.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../../src/util/encoding.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,aAAa,GAAG,KAAK;IAErB,IAAI,aAAa,EAAE,CAAC;QAClB,IAAI,YAAY,IAAI,UAAU,EAAE,CAAC;YAC/B,8DAA8D;YAC9D,OAAO,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,kDAAkD;QAClD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,UAAU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;IACtC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzB,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}

View File

@@ -0,0 +1,13 @@
/**
* @license
* Copyright 2025 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Normalizes HTTP header values by handling multiline values.
* Multiline header values are joined with commas according to HTTP/1.1 spec.
*
* @internal
*/
export declare function normalizeHeaderValue(header: string): string;
//# sourceMappingURL=httpUtils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/util/httpUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAY3D"}

View File

@@ -0,0 +1,24 @@
/**
* @license
* Copyright 2025 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Normalizes HTTP header values by handling multiline values.
* Multiline header values are joined with commas according to HTTP/1.1 spec.
*
* @internal
*/
export function normalizeHeaderValue(header) {
if (!header.includes('\n')) {
return header;
}
return header
.split('\n')
.map(v => {
return v.trim();
})
.filter(Boolean)
.join(', ');
}
//# sourceMappingURL=httpUtils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"httpUtils.js","sourceRoot":"","sources":["../../../src/util/httpUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM;SACV,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE;QACP,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAClB,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}

View File

@@ -0,0 +1,14 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @internal
*/
export declare function createIncrementalIdGenerator(): GetIdFn;
/**
* @internal
*/
export type GetIdFn = () => number;
//# sourceMappingURL=incremental-id-generator.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"incremental-id-generator.d.ts","sourceRoot":"","sources":["../../../src/util/incremental-id-generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,OAAO,CAQtD;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC"}

View File

@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @internal
*/
export function createIncrementalIdGenerator() {
let id = 0;
return () => {
if (id === Number.MAX_SAFE_INTEGER) {
id = 0;
}
return ++id;
};
}
//# sourceMappingURL=incremental-id-generator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"incremental-id-generator.js","sourceRoot":"","sources":["../../../src/util/incremental-id-generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,UAAU,4BAA4B;IAC1C,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,OAAO,GAAW,EAAE;QAClB,IAAI,EAAE,KAAK,MAAM,CAAC,gBAAgB,EAAE,CAAC;YACnC,EAAE,GAAG,CAAC,CAAC;QACT,CAAC;QACD,OAAO,EAAE,EAAE,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}

View File

@@ -0,0 +1,14 @@
/**
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
export * from './assert.js';
export * from './Deferred.js';
export * from './Mutex.js';
export * from './ErrorLike.js';
export * from './AsyncIterableUtil.js';
export * from './disposable.js';
export * from './httpUtils.js';
export * from './incremental-id-generator.js';
//# sourceMappingURL=util.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util/util.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC"}

14
node_modules/puppeteer-core/lib/puppeteer/util/util.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
/**
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
export * from './assert.js';
export * from './Deferred.js';
export * from './Mutex.js';
export * from './ErrorLike.js';
export * from './AsyncIterableUtil.js';
export * from './disposable.js';
export * from './httpUtils.js';
export * from './incremental-id-generator.js';
//# sourceMappingURL=util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/util/util.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC"}

View File

@@ -0,0 +1,7 @@
/**
* @license
* Copyright 2025 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
export declare const packageVersion = "25.0.4";
//# sourceMappingURL=version.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/util/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,cAAc,WAAW,CAAC"}

View File

@@ -0,0 +1,10 @@
/**
* @license
* Copyright 2025 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
// If moved update release-please config
// x-release-please-start-version
export const packageVersion = '25.0.4';
// x-release-please-end
//# sourceMappingURL=version.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/util/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wCAAwC;AACxC,iCAAiC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AACvC,uBAAuB"}