This commit is contained in:
2026-03-03 15:23:00 +00:00
parent 5e3726de39
commit 8e223bfbec
3689 changed files with 955330 additions and 1011 deletions

95
node_modules/@hapi/teamwork/lib/index.d.ts generated vendored Executable file
View File

@@ -0,0 +1,95 @@
/**
* Team bridges between callbacks and promises. Used to convert callback-based
* interfaces to a promise-based result including support for collecting multiple
* callback events into a single promise.
*/
export class Team<Results extends any | any[] = void> {
/**
* Start a new team work.
*
* @param options Configuration of the team work.
*/
constructor(options?: Team.Options);
/**
* Resulting work when all the meetings are done.
*/
work: Promise<Results>;
/**
* Attend a single meeting.
*
* @param note An optional note that will be included in the work's results. If an error is provided, the work will be immediately rejected with that error.
*/
attend(note?: Error | Team.ElementOf<Results>): void;
/**
* Wait for the current work to be done and start another team work.
*
* @param options New configuration of the team work.
*
* @returns a promise that resolves when the current work is done.
*/
regroup(options?: Team.Options) : Promise<void>;
}
export namespace Team {
/**
* Configuration of the team work.
*/
export interface Options {
/**
* Number of meetings this team should attend before delivering work.
*
* @default 1
*/
readonly meetings?: number | undefined;
/**
* Throws when the team attends more than the expected number of `meetings`,
* or if scheduling an empty meeting.
*
* @default false
*/
readonly strict?: boolean | undefined;
}
type ElementOf<T> = T extends (infer E)[] ? E : T;
}
/**
* Events emitter via an async iterator interface.
*/
export class Events<T> {
/**
* Returns a standard async iterator interface object.
*
* @returns async iterator interface object.
*/
iterator(): Events.Iterator<T>;
/**
* Emits an event to be consumed via the iterator.
*
* @param value
*/
emit(value: T): void;
/**
* Informs the iterator that no new events will be emitted.
*/
end(): void;
}
export namespace Events {
class Iterator<T> implements AsyncIterator<T> {
constructor(events: Events<T>);
[Symbol.asyncIterator](): AsyncIterator<T>;
next(): Promise<IteratorResult<T>>;
}
}

203
node_modules/@hapi/teamwork/lib/index.js generated vendored Executable file
View File

@@ -0,0 +1,203 @@
'use strict';
const internals = {};
exports.Team = class {
#meetings = null;
#count = null;
#notes = null;
#done = false;
#strict = false;
constructor(options) {
this._init(options);
}
static _notes(instance) {
return instance.#notes;
}
_init(options = {}) {
this.work = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
const meetings = options.meetings ?? 1;
const strict = !!options.strict;
if (!Number.isInteger(meetings) || meetings <= 0) {
if (meetings === 0 && !strict) {
return this._finalize(null, null);
}
throw new Error('Invalid meetings value');
}
this.#meetings = meetings;
this.#count = meetings;
this.#notes = [];
this.#done = false;
this.#strict = strict;
}
_finalize(err, note) {
this.#done = true;
this.#notes = null;
if (err) {
this._reject(err);
}
else {
this._resolve(note);
}
}
attend(note) {
if (this.#done) {
if (this.#strict) {
throw new Error('Unscheduled meeting');
}
// else ignore
return;
}
if (note instanceof Error) {
return this._finalize(note);
}
this.#notes.push(note);
if (--this.#count) {
return;
}
this._finalize(null, this.#meetings === 1 ? this.#notes[0] : this.#notes);
}
async regroup(options) {
try {
await this.work;
}
catch {}
this._init(options);
}
};
exports.Events = class {
#iterators = new Set();
static _iterators(instance) {
return instance.#iterators;
}
static isIterator(iterator) {
return iterator instanceof internals.EventsIterator;
}
iterator() {
const iterator = new internals.EventsIterator(this);
this.#iterators.add(iterator);
return iterator;
}
emit(value) {
for (const iterator of this.#iterators) {
iterator._queue({ value, done: false });
}
}
end() {
for (const iterator of this.#iterators) {
iterator._queue({ done: true });
}
}
_remove(iterator) {
this.#iterators.delete(iterator);
}
};
internals.EventsIterator = class {
#events;
#pending = null;
#queue = [];
constructor(events) {
this.#events = events;
}
[Symbol.asyncIterator]() {
return this;
}
next() {
if (this.#queue.length) {
return Promise.resolve(this.#queue.shift());
}
if (!this.#events) {
return { done: true };
}
this.#pending = new exports.Team();
return this.#pending.work;
}
return() {
this._cleanup();
return { done: true };
}
_cleanup() {
this.#events?._remove(this);
this.#events = null;
}
_queue(item) {
if (item.done) {
this._cleanup();
}
if (this.#pending) {
this.#pending.attend(item);
this.#pending = null;
}
else {
this.#queue.push(item);
}
}
};