@orkestrel/pool 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/index.cjs +95 -75
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +5 -1
- package/dist/src/core/index.d.ts +5 -1
- package/dist/src/core/index.js +96 -76
- package/dist/src/core/index.js.map +1 -1
- package/package.json +15 -15
package/dist/src/core/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _orkestrel_contract = require("@orkestrel/contract");
|
|
3
3
|
let _orkestrel_emitter = require("@orkestrel/emitter");
|
|
4
|
-
|
|
4
|
+
// src/core/errors.ts
|
|
5
5
|
/**
|
|
6
6
|
* Represents a stable, machine-readable pool failure that retains the original thrown value as
|
|
7
7
|
* its cause without unsafe coercion, alongside structured context.
|
|
@@ -28,19 +28,23 @@ var PoolError = class extends Error {
|
|
|
28
28
|
* @param options - Stable code plus optional cause and structured context
|
|
29
29
|
*/
|
|
30
30
|
constructor(options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if ((0, _orkestrel_contract.isError)(options.cause) && (0, _orkestrel_contract.isString)(options.cause.message) && options.cause.message.length > 0) message = `${message}: ${options.cause.message}`;
|
|
31
|
+
const destroyed = options.code === "destroyed" ? "pool is destroyed" : "pool input is invalid";
|
|
32
|
+
const created = options.code === "create" ? "pool create failed" : destroyed;
|
|
33
|
+
const reason = options.code === "cleanup" ? "pool cleanup failed" : created;
|
|
34
|
+
const message = (0, _orkestrel_contract.isError)(options.cause) && (0, _orkestrel_contract.isString)(options.cause.message) && options.cause.message.length > 0 ? `${reason}: ${options.cause.message}` : reason;
|
|
36
35
|
super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
36
|
+
_orkestrel_contract.INTRINSICS.define(this, Symbol.for("@orkestrel/pool.PoolError"), { value: this });
|
|
37
37
|
this.name = "PoolError";
|
|
38
38
|
this.code = options.code;
|
|
39
39
|
this.context = options.context;
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
|
-
* Tests whether an unknown value is a {@link PoolError}
|
|
43
|
+
* Tests whether an unknown value is a branded {@link PoolError} with declared code and context.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* Accepts subclasses and errors from another installed copy without reading `name`. Refuses
|
|
47
|
+
* transparent proxies, unbranded look-alikes, and plain branded objects.
|
|
44
48
|
*
|
|
45
49
|
* @param value - The unknown boundary value
|
|
46
50
|
* @returns True if the value is a real `PoolError` instance; false otherwise
|
|
@@ -52,10 +56,21 @@ var PoolError = class extends Error {
|
|
|
52
56
|
* ```
|
|
53
57
|
*/
|
|
54
58
|
function isPoolError(value) {
|
|
55
|
-
|
|
59
|
+
if (!(0, _orkestrel_contract.isObject)(value)) return false;
|
|
60
|
+
return (0, _orkestrel_contract.holds)(() => {
|
|
61
|
+
if (!(value instanceof _orkestrel_contract.INTRINSICS.error)) return false;
|
|
62
|
+
if (_orkestrel_contract.INTRINSICS.prototype(value) === _orkestrel_contract.INTRINSICS.error.prototype) return false;
|
|
63
|
+
if (_orkestrel_contract.INTRINSICS.describe(value, Symbol.for("@orkestrel/pool.PoolError"))?.value !== value) return false;
|
|
64
|
+
const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
|
|
65
|
+
if (code !== "invalid" && code !== "destroyed" && code !== "create" && code !== "cleanup") return false;
|
|
66
|
+
const context = _orkestrel_contract.INTRINSICS.reflect.read(value, "context");
|
|
67
|
+
if (context === void 0) return true;
|
|
68
|
+
if (!(0, _orkestrel_contract.isObject)(context) && !(0, _orkestrel_contract.isFunction)(context)) return false;
|
|
69
|
+
const failures = _orkestrel_contract.INTRINSICS.reflect.read(context, "failures");
|
|
70
|
+
return failures === void 0 || (0, _orkestrel_contract.isArray)(failures);
|
|
71
|
+
});
|
|
56
72
|
}
|
|
57
|
-
|
|
58
|
-
//#region src/core/validators.ts
|
|
73
|
+
// src/core/validators.ts
|
|
59
74
|
/**
|
|
60
75
|
* Tests whether a value is a positive safe integer for a pool record or lease limit.
|
|
61
76
|
*
|
|
@@ -92,8 +107,7 @@ function isPoolSignal(value) {
|
|
|
92
107
|
return true;
|
|
93
108
|
});
|
|
94
109
|
}
|
|
95
|
-
|
|
96
|
-
//#region src/core/Pool.ts
|
|
110
|
+
// src/core/Pool.ts
|
|
97
111
|
/**
|
|
98
112
|
* Represents a resource pool with optional bounded capacity and a warm floor, whose opaque
|
|
99
113
|
* ownership records preserve FIFO settlement, cancellation, exact lease release, and
|
|
@@ -329,13 +343,8 @@ var Pool = class {
|
|
|
329
343
|
}
|
|
330
344
|
#createAbort(waiter, signal) {
|
|
331
345
|
return () => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
reason = this.#state(signal)[1];
|
|
335
|
-
} catch (error) {
|
|
336
|
-
reason = error;
|
|
337
|
-
}
|
|
338
|
-
this.#abort(waiter, reason);
|
|
346
|
+
const state = (0, _orkestrel_contract.attempt)(() => this.#state(signal));
|
|
347
|
+
this.#abort(waiter, state.success ? state.value[1] : state.error);
|
|
339
348
|
};
|
|
340
349
|
}
|
|
341
350
|
#state(signal) {
|
|
@@ -459,23 +468,22 @@ var Pool = class {
|
|
|
459
468
|
this.#fill();
|
|
460
469
|
}
|
|
461
470
|
#occupancy(record) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
471
|
+
const leased = this.#leased.get(record)?.size ?? 0;
|
|
472
|
+
return this.#ready.values().reduce((count, result) => {
|
|
473
|
+
return count + (result.success && result.record === record ? 1 : 0);
|
|
474
|
+
}, leased);
|
|
465
475
|
}
|
|
466
476
|
#select() {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
for (const record of this.#resources.keys()) {
|
|
470
|
-
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) continue;
|
|
477
|
+
const selected = this.#resources.keys().reduce((candidate, record) => {
|
|
478
|
+
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) return candidate;
|
|
471
479
|
const count = this.#occupancy(record);
|
|
472
|
-
if (count === 0 && !this.#available.includes(record))
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return this.#available[0] ?? selected;
|
|
480
|
+
if (count === 0 && !this.#available.includes(record)) return candidate;
|
|
481
|
+
return count < candidate.count ? {
|
|
482
|
+
record,
|
|
483
|
+
count
|
|
484
|
+
} : candidate;
|
|
485
|
+
}, { count: this.#capacity });
|
|
486
|
+
return this.#available[0] ?? selected.record;
|
|
479
487
|
}
|
|
480
488
|
#spent() {
|
|
481
489
|
return this.#restarts !== void 0 && this.#strikes > this.#restarts;
|
|
@@ -509,16 +517,27 @@ var Pool = class {
|
|
|
509
517
|
}
|
|
510
518
|
async #refill() {
|
|
511
519
|
if (this.#ending !== void 0) return;
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
} catch (error) {
|
|
516
|
-
this.#addStrike(error);
|
|
520
|
+
const creation = await this.#produce();
|
|
521
|
+
if (!creation.success) {
|
|
522
|
+
this.#addStrike(creation.error);
|
|
517
523
|
return;
|
|
518
524
|
}
|
|
519
|
-
const record = this.#insert(value);
|
|
525
|
+
const record = this.#insert(creation.value);
|
|
520
526
|
this.#recycle(record);
|
|
521
527
|
}
|
|
528
|
+
async #produce() {
|
|
529
|
+
try {
|
|
530
|
+
return {
|
|
531
|
+
success: true,
|
|
532
|
+
value: await this.#create()
|
|
533
|
+
};
|
|
534
|
+
} catch (error) {
|
|
535
|
+
return {
|
|
536
|
+
success: false,
|
|
537
|
+
error
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
522
541
|
#insert(value) {
|
|
523
542
|
const record = {};
|
|
524
543
|
this.#births.set(record, this.#epoch);
|
|
@@ -579,22 +598,21 @@ var Pool = class {
|
|
|
579
598
|
this.#repump = true;
|
|
580
599
|
}
|
|
581
600
|
async #createResource(waiter) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
value = await this.#create();
|
|
585
|
-
} catch (error) {
|
|
601
|
+
const creation = await this.#produce();
|
|
602
|
+
if (!creation.success) {
|
|
586
603
|
this.#reservations.delete(waiter);
|
|
587
604
|
if (this.#waiters.includes(waiter)) this.#ready.set(waiter, {
|
|
588
605
|
success: false,
|
|
589
606
|
error: new PoolError({
|
|
590
607
|
code: "create",
|
|
591
|
-
cause: error
|
|
608
|
+
cause: creation.error
|
|
592
609
|
})
|
|
593
610
|
});
|
|
594
611
|
else this.#assigned.delete(waiter);
|
|
595
612
|
this.#commit();
|
|
596
613
|
return;
|
|
597
614
|
}
|
|
615
|
+
const value = creation.value;
|
|
598
616
|
this.#reservations.delete(waiter);
|
|
599
617
|
const record = this.#insert(value);
|
|
600
618
|
if (this.#ending !== void 0) {
|
|
@@ -617,10 +635,7 @@ var Pool = class {
|
|
|
617
635
|
this.#commit();
|
|
618
636
|
}
|
|
619
637
|
async #validateResource(waiter, record, value) {
|
|
620
|
-
|
|
621
|
-
try {
|
|
622
|
-
valid = await this.#validate?.(value) === true;
|
|
623
|
-
} catch {}
|
|
638
|
+
const valid = await this.#check(value);
|
|
624
639
|
this.#validating.delete(record);
|
|
625
640
|
if (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) {
|
|
626
641
|
this.#assigned.delete(waiter);
|
|
@@ -671,6 +686,13 @@ var Pool = class {
|
|
|
671
686
|
this.#assigned.delete(waiter);
|
|
672
687
|
this.#pump();
|
|
673
688
|
}
|
|
689
|
+
async #check(value) {
|
|
690
|
+
try {
|
|
691
|
+
return await this.#validate?.(value) === true;
|
|
692
|
+
} catch {
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
674
696
|
#prepare(waiter, record, value) {
|
|
675
697
|
if (!this.#waiters.includes(waiter) || this.#ending !== void 0) {
|
|
676
698
|
this.#assigned.delete(waiter);
|
|
@@ -771,29 +793,16 @@ var Pool = class {
|
|
|
771
793
|
return Promise.resolve();
|
|
772
794
|
}
|
|
773
795
|
async #clean(record, value, cleanup) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
disposal = Promise.reject(error);
|
|
779
|
-
}
|
|
780
|
-
let failure;
|
|
781
|
-
let failed = false;
|
|
782
|
-
try {
|
|
783
|
-
await disposal;
|
|
784
|
-
} catch (error) {
|
|
785
|
-
failure = error;
|
|
786
|
-
failed = true;
|
|
787
|
-
}
|
|
788
|
-
if (failed && this.#min !== void 0) {
|
|
789
|
-
this.#survivors.set(record, failure);
|
|
790
|
-
this.#record(failure);
|
|
796
|
+
const disposal = await this.#disposeValue(value);
|
|
797
|
+
if (!disposal.success && this.#min !== void 0) {
|
|
798
|
+
this.#survivors.set(record, disposal.error);
|
|
799
|
+
this.#record(disposal.error);
|
|
791
800
|
} else {
|
|
792
801
|
this.#resources.delete(record);
|
|
793
802
|
if (this.#owing.has(record)) this.#owed += 1;
|
|
794
803
|
}
|
|
795
804
|
this.#owing.delete(record);
|
|
796
|
-
if (
|
|
805
|
+
if (!disposal.success) cleanup.reject(disposal.error);
|
|
797
806
|
else cleanup.resolve();
|
|
798
807
|
await Promise.resolve();
|
|
799
808
|
this.#emitter.emit("destroy");
|
|
@@ -801,6 +810,21 @@ var Pool = class {
|
|
|
801
810
|
if (this.#min !== void 0) this.#pump();
|
|
802
811
|
this.#finish();
|
|
803
812
|
}
|
|
813
|
+
async #disposeValue(value) {
|
|
814
|
+
const disposal = (0, _orkestrel_contract.attempt)(() => Promise.resolve(this.#destroy?.(value)));
|
|
815
|
+
try {
|
|
816
|
+
await (disposal.success ? disposal.value : Promise.reject(disposal.error));
|
|
817
|
+
return {
|
|
818
|
+
success: true,
|
|
819
|
+
value: void 0
|
|
820
|
+
};
|
|
821
|
+
} catch (error) {
|
|
822
|
+
return {
|
|
823
|
+
success: false,
|
|
824
|
+
error
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
}
|
|
804
828
|
async #settleClear(cleanups) {
|
|
805
829
|
const settled = await Promise.allSettled(cleanups);
|
|
806
830
|
const failures = [];
|
|
@@ -834,20 +858,17 @@ var Pool = class {
|
|
|
834
858
|
#finish() {
|
|
835
859
|
const ending = this.#ending;
|
|
836
860
|
if (ending === void 0 || this.#operations.size > 0 || this.#owned.size > 0) return;
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) continue;
|
|
840
|
-
claimed = true;
|
|
861
|
+
if (this.#resources.keys().reduce((previous, record) => {
|
|
862
|
+
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) return previous;
|
|
841
863
|
this.#own(this.#dispose(record));
|
|
842
|
-
|
|
843
|
-
|
|
864
|
+
return true;
|
|
865
|
+
}, false) || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return;
|
|
844
866
|
this.#emitter.destroy();
|
|
845
867
|
if (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures));
|
|
846
868
|
else ending.resolve();
|
|
847
869
|
}
|
|
848
870
|
};
|
|
849
|
-
|
|
850
|
-
//#region src/core/factories.ts
|
|
871
|
+
// src/core/factories.ts
|
|
851
872
|
/**
|
|
852
873
|
* Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
|
|
853
874
|
* capacity, exclusive leases by default, and FIFO settlement.
|
|
@@ -889,7 +910,6 @@ var Pool = class {
|
|
|
889
910
|
function createPool(options) {
|
|
890
911
|
return new Pool(options);
|
|
891
912
|
}
|
|
892
|
-
//#endregion
|
|
893
913
|
exports.Pool = Pool;
|
|
894
914
|
exports.PoolError = PoolError;
|
|
895
915
|
exports.createPool = createPool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isError","isString","isInstance","isNumber","holds","isFunction","isNumber","isFunction","Emitter","attempt"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\nimport { isError, isInstance, isString } from '@orkestrel/contract'\n\n/**\n * Represents a stable, machine-readable pool failure that retains the original thrown value as\n * its cause without unsafe coercion, alongside structured context.\n *\n * @example\n * ```ts\n * import { PoolError, isPoolError } from '@orkestrel/pool'\n *\n * try {\n * \tawait pool.acquire()\n * } catch (error: unknown) {\n * \tif (isPoolError(error)) console.error(error.code, error.cause)\n * }\n * ```\n */\nexport class PoolError extends Error {\n\t/** Holds the stable machine-readable failure category. */\n\treadonly code\n\t/** Holds optional structured input or aggregate destroy-hook failure details. */\n\treadonly context\n\n\t/**\n\t * Creates a pool failure without coercing a hostile thrown value.\n\t *\n\t * @param options - Stable code plus optional cause and structured context\n\t */\n\tconstructor(options: PoolErrorOptions) {\n\t\tlet message = 'pool input is invalid'\n\t\tif (options.code === 'destroyed') message = 'pool is destroyed'\n\t\tif (options.code === 'create') message = 'pool create failed'\n\t\tif (options.code === 'cleanup') message = 'pool cleanup failed'\n\t\tif (\n\t\t\tisError(options.cause) &&\n\t\t\tisString(options.cause.message) &&\n\t\t\toptions.cause.message.length > 0\n\t\t) {\n\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t}\n\t\tsuper(message, options.cause === undefined ? undefined : { cause: options.cause })\n\t\tthis.name = 'PoolError'\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Tests whether an unknown value is a {@link PoolError}, returning `false` for hostile proxies.\n *\n * @param value - The unknown boundary value\n * @returns True if the value is a real `PoolError` instance; false otherwise\n *\n * @example\n * ```ts\n * isPoolError(new PoolError({ code: 'destroyed' })) // true\n * isPoolError(new Error('other')) // false\n * ```\n */\nexport function isPoolError(value: unknown): value is PoolError {\n\treturn isInstance(value, PoolError)\n}\n","import { holds, isFunction, isNumber } from '@orkestrel/contract'\n\n/**\n * Tests whether a value is a positive safe integer for a pool record or lease limit.\n *\n * @param value - The unknown record or lease limit candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolLimit(8) // true\n * isPoolLimit(Infinity) // false\n * ```\n */\nexport function isPoolLimit(value: unknown): value is number {\n\treturn isNumber(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`\n * for hostile proxies.\n *\n * @param value - The unknown signal candidate\n * @returns True if the value is a native `AbortSignal`; false otherwise\n *\n * @example\n * ```ts\n * isPoolSignal(new AbortController().signal) // true\n * isPoolSignal({ aborted: false }) // false\n * ```\n */\nexport function isPoolSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (!isFunction(getter)) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n","import type { EmitterErrorHandler, EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { attempt, isFunction, isNumber } from '@orkestrel/contract'\nimport { PoolError } from './errors.js'\nimport { isPoolLimit, isPoolSignal } from './validators.js'\n\n/**\n * Represents a resource pool with optional bounded capacity and a warm floor, whose opaque\n * ownership records preserve FIFO settlement, cancellation, exact lease release, and\n * deterministic teardown under concurrent hooks.\n *\n * @typeParam T - The pooled resource value\n *\n * @example\n * ```ts\n * import { Pool } from '@orkestrel/pool'\n *\n * const pool = new Pool({ create: () => new Uint8Array(64), max: 2 })\n * const token = await pool.acquire()\n * try {\n * \tconsume(token.value)\n * } finally {\n * \ttoken.release()\n * }\n * await pool.destroy()\n * ```\n */\nexport class Pool<T> implements PoolInterface<T> {\n\treadonly #create: () => Promise<T> | T\n\treadonly #destroy: ((value: T) => Promise<void> | void) | undefined\n\treadonly #validate: ((value: T) => Promise<boolean> | boolean) | undefined\n\treadonly #max: number | undefined\n\treadonly #capacity: number\n\treadonly #min: number | undefined\n\treadonly #restarts: number | undefined\n\treadonly #watch: PoolOptions<T>['watch']\n\treadonly #error: EmitterErrorHandler | undefined\n\treadonly #watches = new Map<object, AbortController>()\n\treadonly #births = new WeakMap<object, object>()\n\treadonly #settled = new WeakSet<object>()\n\treadonly #survivors = new Map<object, unknown>()\n\treadonly #owing = new Set<object>()\n\treadonly #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new Map<object, Set<object>>()\n\treadonly #destroying = new Map<object, Promise<void>>()\n\treadonly #waiters: Array<PromiseWithResolvers<PoolToken<T>>> = []\n\treadonly #assigned = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #reservations = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #signals = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t{ readonly signal: AbortSignal; readonly listener: () => void }\n\t>()\n\treadonly #ready = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t| { readonly success: true; readonly record: object; readonly token: PoolToken<T> }\n\t\t| { readonly success: false; readonly error: unknown }\n\t>()\n\treadonly #operations = new Set<Promise<void>>()\n\treadonly #owned = new Set<Promise<void>>()\n\treadonly #failures: unknown[] = []\n\t#ending: PromiseWithResolvers<void> | undefined\n\t#pumping = false\n\t#repump = false\n\t#started = false\n\t#starting: PromiseWithResolvers<void> | undefined\n\t#refilling = false\n\t#strikes = 0\n\t#epoch = {}\n\t#owed = 0\n\t#cause: unknown\n\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor\n\t * @throws {@link PoolError} Thrown with `code: 'invalid'` when `capacity`, `min`, or `max` is not a positive\n\t * safe integer, explicit `min` and `max` differ, `restarts` is absent with `min`, present without\n\t * `min`, or not a non-negative safe integer, or `watch` is not callable.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tconst capacity = options.capacity\n\t\tconst min = options.min\n\t\tconst restarts = options.restarts\n\t\tconst watch = options.watch\n\t\tif (max !== undefined && !isPoolLimit(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\n\t\t}\n\t\tif (capacity !== undefined && !isPoolLimit(capacity)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: capacity } })\n\t\t}\n\t\tif (min !== undefined && (!isPoolLimit(min) || (max !== undefined && min !== max))) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: min } })\n\t\t}\n\t\tif (\n\t\t\t(min !== undefined && restarts === undefined) ||\n\t\t\t(restarts !== undefined &&\n\t\t\t\t(min === undefined ||\n\t\t\t\t\t!isNumber(restarts) ||\n\t\t\t\t\t!Number.isSafeInteger(restarts) ||\n\t\t\t\t\trestarts < 0))\n\t\t) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: restarts } })\n\t\t}\n\t\tif (watch !== undefined && !isFunction(watch)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: watch } })\n\t\t}\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#create = options.create\n\t\tthis.#destroy = options.destroy\n\t\tthis.#validate = options.validate\n\t\tthis.#max = max ?? min\n\t\tthis.#capacity = capacity ?? 1\n\t\tthis.#min = min\n\t\tthis.#restarts = restarts\n\t\tthis.#watch = watch\n\t\tthis.#error = error\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\t/** Holds the typed synchronous lifecycle observation surface. */\n\tget emitter(): EmitterInterface<PoolEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Counts all owned records, including records validating, destroying, or retained after failed cleanup. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts available records with no live lease or pending handout. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts records with live leases, counting a shared record once rather than counting its leases. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Fills the warm floor and resets the strikes of a spent floor; without a floor, resolves immediately.\n\t *\n\t * @returns A promise that resolves when the floor owns `min` live records\n\t * @throws {@link PoolError} Thrown as a rejection with `code: 'create'` and the last cause\n\t * when the bound is spent, `code: 'cleanup'` when retained failed cleanup prevents filling,\n\t * or `code: 'destroyed'` when teardown begins.\n\t */\n\tstart(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (this.#min === undefined) return Promise.resolve()\n\t\tif (this.#starting !== undefined) return this.#starting.promise\n\t\tconst starting = Promise.withResolvers<void>()\n\t\tthis.#starting = starting\n\t\tthis.#started = true\n\t\tif (this.#spent()) this.#strikes = 0\n\t\tthis.#pump()\n\t\treturn starting.promise\n\t}\n\n\t/**\n\t * Queues the caller in FIFO order, shares an occupied record or validates an idle record, and\n\t * waits for a floor refill or creates on demand without a floor.\n\t *\n\t * @param signal - Optional native cancellation signal\n\t * @returns A promise for the unique resource lease\n\t * @throws {@link PoolError} Thrown when `signal` is present and is not a native `AbortSignal`,\n\t * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller\n\t * that handles failures with `.catch()` alone misses it.\n\t * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with\n\t * `code: 'destroyed'`; when the create hook fails or the floor is spent without an eligible record,\n\t * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or\n\t * a floor retains a record, owns `min` records, has nothing eligible, and has no refill or disposal\n\t * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.\n\t * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.\n\t */\n\tacquire(signal?: AbortSignal): Promise<PoolToken<T>> {\n\t\tif (signal !== undefined && !isPoolSignal(signal)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (signal !== undefined) {\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) return Promise.reject(state[1])\n\t\t}\n\n\t\tconst waiter = Promise.withResolvers<PoolToken<T>>()\n\t\tthis.#waiters.push(waiter)\n\t\tif (signal !== undefined) {\n\t\t\tconst listener = this.#createAbort(waiter, signal)\n\t\t\tAbortSignal.prototype.addEventListener.call(signal, 'abort', listener, { once: true })\n\t\t\tthis.#signals.set(waiter, { signal, listener })\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) this.#abort(waiter, state[1])\n\t\t}\n\t\tthis.#pump()\n\t\treturn waiter.promise\n\t}\n\n\t/**\n\t * Destroys the records that are idle at this call's synchronous snapshot and restores a started floor.\n\t *\n\t * @returns A promise that settles after every snapshot cleanup attempt\n\t * @throws {@link PoolError} Thrown when `destroy()` has already begun, with `code: 'destroyed'`.\n\t * @throws {@link PoolError} Thrown when a claimed record's destroy hook fails, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. Each arrives as a rejected\n\t * promise rather than a synchronous throw.\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tconst records = this.#available.splice(0)\n\t\tconst cleanups: Array<Promise<void>> = []\n\t\tfor (const record of records) {\n\t\t\tconst cleanup = this.#dispose(record)\n\t\t\tcleanups.push(cleanup)\n\t\t\tvoid cleanup.then(\n\t\t\t\t() => this.#pump(),\n\t\t\t\t() => this.#pump(),\n\t\t\t)\n\t\t}\n\t\treturn this.#settleClear(cleanups)\n\t}\n\n\t/**\n\t * Tears down the pool permanently and returns its stable completion barrier.\n\t *\n\t * @returns The exact promise shared by every destroy call\n\t * @throws {@link PoolError} Thrown when a destroy hook failure was retained or occurred during teardown, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. The barrier rejects; it\n\t * never throws synchronously, and a repeat call receives the same rejected promise.\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending.promise\n\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending\n\t\tthis.#starting?.reject(new PoolError({ code: 'destroyed' }))\n\t\tthis.#starting = undefined\n\t\tconst waiters = this.#waiters.splice(0)\n\t\tfor (const waiter of waiters) {\n\t\t\tthis.#detach(waiter)\n\t\t\twaiter.reject(new PoolError({ code: 'destroyed' }))\n\t\t}\n\t\tthis.#ready.clear()\n\t\tthis.#assigned.clear()\n\t\tthis.#available.splice(0)\n\t\tfor (const cleanup of this.#destroying.values()) this.#own(cleanup)\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (!this.#validating.has(record)) this.#own(this.#dispose(record))\n\t\t}\n\t\tthis.#finish()\n\t\treturn ending.promise\n\t}\n\n\t#createAbort(waiter: PromiseWithResolvers<PoolToken<T>>, signal: AbortSignal): () => void {\n\t\treturn (): void => {\n\t\t\tlet reason: unknown\n\t\t\ttry {\n\t\t\t\treason = this.#state(signal)[1]\n\t\t\t} catch (error: unknown) {\n\t\t\t\treason = error\n\t\t\t}\n\t\t\tthis.#abort(waiter, reason)\n\t\t}\n\t}\n\n\t#state(signal: AbortSignal): readonly [aborted: boolean, reason: unknown] {\n\t\tconst aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tconst reason = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason')?.get\n\t\tif (aborted === undefined || reason === undefined) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\ttry {\n\t\t\tconst stopped = Reflect.apply(aborted, signal, []) === true\n\t\t\treturn [stopped, stopped ? Reflect.apply(reason, signal, []) : undefined]\n\t\t} catch (error: unknown) {\n\t\t\tthrow new PoolError({ code: 'invalid', cause: error, context: { value: signal } })\n\t\t}\n\t}\n\n\t#token(record: object, value: T, lease: object): PoolToken<T> {\n\t\treturn {\n\t\t\tvalue,\n\t\t\trelease: this.#createRelease(record, lease),\n\t\t\tdestroy: this.#createDestroy(record, lease),\n\t\t}\n\t}\n\n\t#createRelease(record: object, lease: object): () => void {\n\t\treturn (): void => {\n\t\t\tif (this.#settled.has(lease)) return\n\t\t\tthis.#settled.add(lease)\n\t\t\tthis.#release(record, lease)\n\t\t}\n\t}\n\n\t#createDestroy(record: object, lease: object): () => Promise<void> {\n\t\treturn (): Promise<void> => {\n\t\t\tif (this.#settled.has(lease)) return Promise.resolve()\n\t\t\tthis.#settled.add(lease)\n\t\t\treturn (this.#destroying.get(record) ?? this.#lose(record)).catch((error: unknown) => {\n\t\t\t\tthrow new PoolError({ code: 'cleanup', cause: error })\n\t\t\t})\n\t\t}\n\t}\n\n\t#abort(waiter: PromiseWithResolvers<PoolToken<T>>, reason: unknown): void {\n\t\tconst index = this.#waiters.indexOf(waiter)\n\t\tif (index < 0) return\n\t\tthis.#waiters.splice(index, 1)\n\t\tthis.#detach(waiter)\n\t\tconst ready = this.#ready.get(waiter)\n\t\tthis.#ready.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (ready?.success === true) {\n\t\t\tthis.#recycle(ready.record)\n\t\t}\n\t\twaiter.reject(reason)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t}\n\n\t#detach(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst entry = this.#signals.get(waiter)\n\t\tif (entry === undefined) return\n\t\tAbortSignal.prototype.removeEventListener.call(entry.signal, 'abort', entry.listener)\n\t\tthis.#signals.delete(waiter)\n\t}\n\n\t#pump(): void {\n\t\tif (this.#ending !== undefined) return\n\t\tif (this.#pumping) {\n\t\t\tthis.#repump = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.#pumping = true\n\t\tdo {\n\t\t\tthis.#repump = false\n\t\t\tfor (const waiter of this.#waiters) {\n\t\t\t\tif (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue\n\t\t\t\tconst record = this.#select()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tconst index = this.#available.indexOf(record)\n\t\t\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\t\t\tif (this.#occupancy(record) === 0) this.#validating.add(record)\n\t\t\t\t\tthis.#startValidation(waiter, record)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (this.#min !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#resources.size >= this.#min &&\n\t\t\t\t\t\tthis.#survivors.size > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({\n\t\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\t\tcause: this.#survivors.values().next().value,\n\t\t\t\t\t\t\t\tcontext: { failures: [...this.#failures] },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#spent() &&\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#owed === 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({ code: 'create', cause: this.#cause }),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif (this.#max === undefined || this.#resources.size + this.#reservations.size < this.#max) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#reservations.add(waiter)\n\t\t\t\t\tthis.#startCreate(waiter)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t} while (this.#repump)\n\t\tthis.#pumping = false\n\t\tthis.#fill()\n\t}\n\n\t#occupancy(record: object): number {\n\t\tlet count = this.#leased.get(record)?.size ?? 0\n\t\tfor (const result of this.#ready.values()) {\n\t\t\tif (result.success && result.record === record) count += 1\n\t\t}\n\t\treturn count\n\t}\n\n\t#select(): object | undefined {\n\t\tlet selected: object | undefined\n\t\tlet least = this.#capacity\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tconst count = this.#occupancy(record)\n\t\t\tif (count === 0 && !this.#available.includes(record)) continue\n\t\t\tif (count < least) {\n\t\t\t\tselected = record\n\t\t\t\tleast = count\n\t\t\t}\n\t\t}\n\t\treturn this.#available[0] ?? selected\n\t}\n\n\t#spent(): boolean {\n\t\treturn this.#restarts !== undefined && this.#strikes > this.#restarts\n\t}\n\n\t#fill(): void {\n\t\tif (this.#ending !== undefined || !this.#started || this.#min === undefined) return\n\t\tif (this.#refilling) return\n\t\tconst live = this.#resources.size - this.#destroying.size - this.#survivors.size\n\t\tif (live >= this.#min) {\n\t\t\tthis.#starting?.resolve()\n\t\t\tthis.#starting = undefined\n\t\t}\n\t\tif (this.#resources.size < this.#min && (!this.#spent() || this.#owed > 0)) {\n\t\t\tif (this.#owed > 0) this.#owed -= 1\n\t\t\tthis.#refilling = true\n\t\t\tconst operation = Promise.resolve().then(() => this.#refill())\n\t\t\tthis.#operations.add(operation)\n\t\t\t// Refill never rejects: create failures are caught, and watch/emitter callbacks isolate errors.\n\t\t\tvoid operation.then(() => {\n\t\t\t\tthis.#refilling = false\n\t\t\t\tthis.#completeOperation(operation)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tif (this.#destroying.size > 0) return\n\t\tif (this.#spent() || this.#survivors.size > 0) {\n\t\t\tthis.#starting?.reject(\n\t\t\t\tthis.#spent()\n\t\t\t\t\t? new PoolError({ code: 'create', cause: this.#cause })\n\t\t\t\t\t: this.#cleanupError(this.#failures),\n\t\t\t)\n\t\t\tthis.#starting = undefined\n\t\t}\n\t}\n\n\tasync #refill(): Promise<void> {\n\t\tif (this.#ending !== undefined) return\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#addStrike(error)\n\t\t\treturn\n\t\t}\n\t\tconst record = this.#insert(value)\n\t\tthis.#recycle(record)\n\t}\n\n\t#insert(value: T): object {\n\t\tconst record = {}\n\t\tthis.#births.set(record, this.#epoch)\n\t\tthis.#resources.set(record, value)\n\t\tif (this.#watch !== undefined) {\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#watches.set(record, controller)\n\t\t\tconst watching = attempt(() => this.#watch?.(value, controller.signal))\n\t\t\tconst settled = watching.success\n\t\t\t\t? Promise.resolve(watching.value)\n\t\t\t\t: Promise.reject(watching.error)\n\t\t\tvoid settled.then(\n\t\t\t\t() => this.#own(this.#lose(record)),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (controller.signal.aborted) return\n\t\t\t\t\tthis.#own(this.#lose(record, error))\n\t\t\t\t\tattempt(() => this.#error?.(error, 'watch'))\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tthis.#emitter.emit('create')\n\t\treturn record\n\t}\n\n\tasync #lose(record: object, cause?: unknown): Promise<void> {\n\t\tif (\n\t\t\tthis.#ending !== undefined ||\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t)\n\t\t\treturn\n\t\tif (this.#leased.has(record) && this.#min !== undefined) this.#owing.add(record)\n\t\tthis.#strike(record, cause)\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#pump()\n\t\t\tthrow error\n\t\t}\n\t\tthis.#pump()\n\t}\n\n\t#strike(record: object, cause?: unknown): void {\n\t\tif (this.#min !== undefined && !this.#leased.has(record)) {\n\t\t\tthis.#addStrike(cause)\n\t\t}\n\t}\n\n\t#addStrike(cause: unknown): void {\n\t\tthis.#strikes += 1\n\t\tthis.#cause = cause\n\t\tthis.#epoch = {}\n\t}\n\n\t#startCreate(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst operation = Promise.resolve().then(() => this.#createResource(waiter))\n\t\tthis.#operations.add(operation)\n\t\tvoid operation.then(\n\t\t\t() => this.#completeOperation(operation),\n\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'create'),\n\t\t)\n\t}\n\n\t#startValidation(waiter: PromiseWithResolvers<PoolToken<T>>, record: object): void {\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tif (!this.#validating.has(record) || this.#validate === undefined) {\n\t\t\t\tthis.#validating.delete(record)\n\t\t\t\tthis.#prepare(waiter, record, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst operation = Promise.resolve().then(() => this.#validateResource(waiter, record, value))\n\t\t\tthis.#operations.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#completeOperation(operation),\n\t\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'invalid'),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.#validating.delete(record)\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#repump = true\n\t}\n\n\tasync #createResource(waiter: PromiseWithResolvers<PoolToken<T>>): Promise<void> {\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#reservations.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'create', cause: error }),\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t\treturn\n\t\t}\n\n\t\tthis.#reservations.delete(waiter)\n\t\tconst record = this.#insert(value)\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\tasync #validateResource(\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\trecord: object,\n\t\tvalue: T,\n\t): Promise<void> {\n\t\tlet valid = false\n\t\ttry {\n\t\t\tvalid = (await this.#validate?.(value)) === true\n\t\t} catch {}\n\t\tthis.#validating.delete(record)\n\t\tif (\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!valid) this.#strike(record)\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (valid) this.#recycle(record)\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#dispose(record)\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthis.#record(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (valid) {\n\t\t\tthis.#prepare(waiter, record, value)\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'cleanup', cause: error }),\n\t\t\t\t})\n\t\t\t\tthis.#commit()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#record(error)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#pump()\n\t}\n\n\t#prepare(waiter: PromiseWithResolvers<PoolToken<T>>, record: object, value: T): void {\n\t\tif (!this.#waiters.includes(waiter) || this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\t#commit(): void {\n\t\twhile (this.#ending === undefined) {\n\t\t\tconst waiter = this.#waiters[0]\n\t\t\tif (waiter === undefined) return\n\t\t\tconst result = this.#ready.get(waiter)\n\t\t\tif (result === undefined) return\n\t\t\tif (\n\t\t\t\tresult.success &&\n\t\t\t\t(!this.#resources.has(result.record) ||\n\t\t\t\t\tthis.#destroying.has(result.record) ||\n\t\t\t\t\tthis.#survivors.has(result.record))\n\t\t\t) {\n\t\t\t\tthis.#ready.delete(waiter)\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t\tthis.#repump = true\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#waiters.shift()\n\t\t\tthis.#repump = true\n\t\t\tthis.#ready.delete(waiter)\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#detach(waiter)\n\t\t\tif (!result.success) {\n\t\t\t\twaiter.reject(result.error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst leases = this.#leased.get(result.record) ?? new Set<object>()\n\t\t\tleases.add(waiter)\n\t\t\tthis.#leased.set(result.record, leases)\n\t\t\tif (this.#births.get(result.record) === this.#epoch) this.#strikes = 0\n\t\t\twaiter.resolve(result.token)\n\t\t\tthis.#emitter.emit('acquire')\n\t\t}\n\t}\n\n\t#completeOperation(operation: Promise<void>): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#failOperation(\n\t\toperation: Promise<void>,\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\terror: unknown,\n\t\tcode: PoolCode,\n\t): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#reservations.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (this.#waiters.includes(waiter)) {\n\t\t\tthis.#ready.set(waiter, { success: false, error: new PoolError({ code, cause: error }) })\n\t\t}\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#release(record: object, lease: object): void {\n\t\tconst leases = this.#leased.get(record)\n\t\tif (leases === undefined || !leases.delete(lease)) return\n\t\tif (leases.size === 0) this.#leased.delete(record)\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record))\n\t\t\treturn\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tthis.#occupancy(record) === 0 &&\n\t\t\t!this.#validating.has(record) &&\n\t\t\t!this.#available.includes(record)\n\t\t) {\n\t\t\tthis.#available.push(record)\n\t\t}\n\t\tthis.#pump()\n\t\tif (this.#available.includes(record)) this.#emitter.emit('release')\n\t}\n\n\t#dispose(record: object): Promise<void> {\n\t\tif (this.#survivors.has(record)) return Promise.resolve()\n\t\tconst existing = this.#destroying.get(record)\n\t\tif (existing !== undefined) return existing\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tconst cleanup = Promise.withResolvers<void>()\n\t\t\tthis.#destroying.set(record, cleanup.promise)\n\t\t\tconst index = this.#available.indexOf(record)\n\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\tthis.#validating.delete(record)\n\t\t\tthis.#leased.delete(record)\n\t\t\tthis.#watches.get(record)?.abort()\n\t\t\tthis.#watches.delete(record)\n\t\t\tif (this.#ending !== undefined) this.#own(cleanup.promise)\n\t\t\tvoid this.#clean(record, value, cleanup)\n\t\t\treturn cleanup.promise\n\t\t}\n\t\treturn Promise.resolve()\n\t}\n\n\tasync #clean(record: object, value: T, cleanup: PromiseWithResolvers<void>): Promise<void> {\n\t\tlet disposal: Promise<void>\n\t\ttry {\n\t\t\tdisposal = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tdisposal = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait disposal\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tif (failed && this.#min !== undefined) {\n\t\t\tthis.#survivors.set(record, failure)\n\t\t\tthis.#record(failure)\n\t\t} else {\n\t\t\tthis.#resources.delete(record)\n\t\t\tif (this.#owing.has(record)) this.#owed += 1\n\t\t}\n\t\tthis.#owing.delete(record)\n\t\tif (failed) cleanup.reject(failure)\n\t\telse cleanup.resolve()\n\t\t// Cleanup owners must bind outcomes before destroy observers can reenter.\n\t\tawait Promise.resolve()\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#destroying.delete(record)\n\t\tif (this.#min !== undefined) this.#pump()\n\t\tthis.#finish()\n\t}\n\n\tasync #settleClear(cleanups: ReadonlyArray<Promise<void>>): Promise<void> {\n\t\tconst settled = await Promise.allSettled(cleanups)\n\t\tconst failures: unknown[] = []\n\t\tfor (const result of settled) {\n\t\t\tif (\n\t\t\t\tresult.status === 'rejected' &&\n\t\t\t\t!failures.some((failure) => Object.is(failure, result.reason))\n\t\t\t) {\n\t\t\t\tfailures.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (failures.length > 0) throw this.#cleanupError(failures)\n\t}\n\n\t#own(cleanup: Promise<void>): void {\n\t\tif (this.#owned.has(cleanup)) return\n\t\tthis.#owned.add(cleanup)\n\t\tvoid cleanup.then(\n\t\t\t() => this.#completeCleanup(cleanup),\n\t\t\t(error: unknown) => this.#failCleanup(cleanup, error),\n\t\t)\n\t}\n\n\t#completeCleanup(cleanup: Promise<void>): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#finish()\n\t}\n\n\t#failCleanup(cleanup: Promise<void>, error: unknown): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#record(error)\n\t\tthis.#finish()\n\t}\n\n\t#record(error: unknown): void {\n\t\tif (!this.#failures.some((failure) => Object.is(failure, error))) this.#failures.push(error)\n\t}\n\n\t#cleanupError(failures: readonly unknown[]): PoolError {\n\t\treturn new PoolError({\n\t\t\tcode: 'cleanup',\n\t\t\t...(failures[0] === undefined ? {} : { cause: failures[0] }),\n\t\t\tcontext: { failures: [...failures] },\n\t\t})\n\t}\n\n\t#finish(): void {\n\t\tconst ending = this.#ending\n\t\tif (ending === undefined || this.#operations.size > 0 || this.#owned.size > 0) return\n\t\tlet claimed = false\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return\n\t\tthis.#emitter.destroy()\n\t\tif (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures))\n\t\telse ending.resolve()\n\t}\n}\n","import type { PoolInterface, PoolOptions } from './types.js'\nimport { Pool } from './Pool.js'\n\n/**\n * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded\n * capacity, exclusive leases by default, and FIFO settlement.\n *\n * @remarks\n * Concurrent create and validation hooks may overlap, while acquire promises settle in\n * request order. `clear` owns its idle snapshot; `destroy` returns one stable barrier and\n * waits for every in-flight create, validation, and destroy attempt before destroying the\n * emitter last.\n * Set `min` with its required `restarts` bound and call `start()` to warm resources and\n * refill losses independently of queued acquires. `watch` observes loss and its signal\n * aborts at disposal; a token can declare loss through `destroy()`.\n *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, capacity, optional bounded warm floor, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown with `code: 'invalid'` when capacity, restart bounds, or\n * the watch hook are invalid. Construction validates them synchronously, before the pool exists.\n *\n * @example Create a pool\n * ```ts\n * import { createPool } from '@orkestrel/pool'\n *\n * const pool = createPool<Connection>({\n * \tcreate: () => connect(),\n * \tdestroy: (connection) => connection.close(),\n * \tvalidate: (connection) => connection.alive,\n * \tmax: 8,\n * })\n *\n * const token = await pool.acquire()\n * try {\n * \tawait token.value.query('select 1')\n * } finally {\n * \ttoken.release()\n * }\n * ```\n */\nexport function createPool<T>(options: PoolOptions<T>): PoolInterface<T> {\n\treturn new Pool(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;;;;;CAOA,YAAY,SAA2B;EACtC,IAAI,UAAU;EACd,IAAI,QAAQ,SAAS,aAAa,UAAU;EAC5C,IAAI,QAAQ,SAAS,UAAU,UAAU;EACzC,IAAI,QAAQ,SAAS,WAAW,UAAU;EAC1C,KAAA,GACCA,oBAAAA,QAAAA,CAAQ,QAAQ,KAAK,MAAA,GACrBC,oBAAAA,SAAAA,CAAS,QAAQ,MAAM,OAAO,KAC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;;;;;;;;;;;;;;;;;AC70BA,SAAgB,WAAc,SAA2C;CACxE,OAAO,IAAI,KAAK,OAAO;AACxB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isError","isString","isObject","holds","INTRINSICS","isFunction","isArray","isNumber","holds","isFunction","isNumber","isFunction","Emitter","attempt"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\nimport {\n\tholds,\n\tINTRINSICS,\n\tisArray,\n\tisError,\n\tisFunction,\n\tisObject,\n\tisString,\n} from '@orkestrel/contract'\n\n/**\n * Represents a stable, machine-readable pool failure that retains the original thrown value as\n * its cause without unsafe coercion, alongside structured context.\n *\n * @example\n * ```ts\n * import { PoolError, isPoolError } from '@orkestrel/pool'\n *\n * try {\n * \tawait pool.acquire()\n * } catch (error: unknown) {\n * \tif (isPoolError(error)) console.error(error.code, error.cause)\n * }\n * ```\n */\nexport class PoolError extends Error {\n\t/** Holds the stable machine-readable failure category. */\n\treadonly code\n\t/** Holds optional structured input or aggregate destroy-hook failure details. */\n\treadonly context\n\n\t/**\n\t * Creates a pool failure without coercing a hostile thrown value.\n\t *\n\t * @param options - Stable code plus optional cause and structured context\n\t */\n\tconstructor(options: PoolErrorOptions) {\n\t\tconst destroyed = options.code === 'destroyed' ? 'pool is destroyed' : 'pool input is invalid'\n\t\tconst created = options.code === 'create' ? 'pool create failed' : destroyed\n\t\tconst reason = options.code === 'cleanup' ? 'pool cleanup failed' : created\n\t\tconst message =\n\t\t\tisError(options.cause) && isString(options.cause.message) && options.cause.message.length > 0\n\t\t\t\t? `${reason}: ${options.cause.message}`\n\t\t\t\t: reason\n\t\tsuper(message, options.cause === undefined ? undefined : { cause: options.cause })\n\t\tINTRINSICS.define(this, Symbol.for('@orkestrel/pool.PoolError'), { value: this })\n\t\tthis.name = 'PoolError'\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Tests whether an unknown value is a branded {@link PoolError} with declared code and context.\n *\n * @remarks\n * Accepts subclasses and errors from another installed copy without reading `name`. Refuses\n * transparent proxies, unbranded look-alikes, and plain branded objects.\n *\n * @param value - The unknown boundary value\n * @returns True if the value is a real `PoolError` instance; false otherwise\n *\n * @example\n * ```ts\n * isPoolError(new PoolError({ code: 'destroyed' })) // true\n * isPoolError(new Error('other')) // false\n * ```\n */\nexport function isPoolError(value: unknown): value is PoolError {\n\tif (!isObject(value)) return false\n\treturn holds(() => {\n\t\tif (!(value instanceof INTRINSICS.error)) return false\n\t\tif (INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false\n\t\tconst brand = INTRINSICS.describe(value, Symbol.for('@orkestrel/pool.PoolError'))\n\t\tif (brand?.value !== value) return false\n\t\tconst code: unknown = INTRINSICS.reflect.read(value, 'code')\n\t\tif (code !== 'invalid' && code !== 'destroyed' && code !== 'create' && code !== 'cleanup')\n\t\t\treturn false\n\t\tconst context: unknown = INTRINSICS.reflect.read(value, 'context')\n\t\tif (context === undefined) return true\n\t\tif (!isObject(context) && !isFunction(context)) return false\n\t\tconst failures: unknown = INTRINSICS.reflect.read(context, 'failures')\n\t\treturn failures === undefined || isArray(failures)\n\t})\n}\n","import { holds, isFunction, isNumber } from '@orkestrel/contract'\n\n/**\n * Tests whether a value is a positive safe integer for a pool record or lease limit.\n *\n * @param value - The unknown record or lease limit candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolLimit(8) // true\n * isPoolLimit(Infinity) // false\n * ```\n */\nexport function isPoolLimit(value: unknown): value is number {\n\treturn isNumber(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`\n * for hostile proxies.\n *\n * @param value - The unknown signal candidate\n * @returns True if the value is a native `AbortSignal`; false otherwise\n *\n * @example\n * ```ts\n * isPoolSignal(new AbortController().signal) // true\n * isPoolSignal({ aborted: false }) // false\n * ```\n */\nexport function isPoolSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (!isFunction(getter)) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n","import type { EmitterErrorHandler, EmitterInterface } from '@orkestrel/emitter'\nimport type { Result } from '@orkestrel/contract'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { attempt, isFunction, isNumber } from '@orkestrel/contract'\nimport { PoolError } from './errors.js'\nimport { isPoolLimit, isPoolSignal } from './validators.js'\n\n/**\n * Represents a resource pool with optional bounded capacity and a warm floor, whose opaque\n * ownership records preserve FIFO settlement, cancellation, exact lease release, and\n * deterministic teardown under concurrent hooks.\n *\n * @typeParam T - The pooled resource value\n *\n * @example\n * ```ts\n * import { Pool } from '@orkestrel/pool'\n *\n * const pool = new Pool({ create: () => new Uint8Array(64), max: 2 })\n * const token = await pool.acquire()\n * try {\n * \tconsume(token.value)\n * } finally {\n * \ttoken.release()\n * }\n * await pool.destroy()\n * ```\n */\nexport class Pool<T> implements PoolInterface<T> {\n\treadonly #create: () => Promise<T> | T\n\treadonly #destroy: ((value: T) => Promise<void> | void) | undefined\n\treadonly #validate: ((value: T) => Promise<boolean> | boolean) | undefined\n\treadonly #max: number | undefined\n\treadonly #capacity: number\n\treadonly #min: number | undefined\n\treadonly #restarts: number | undefined\n\treadonly #watch: PoolOptions<T>['watch']\n\treadonly #error: EmitterErrorHandler | undefined\n\treadonly #watches = new Map<object, AbortController>()\n\treadonly #births = new WeakMap<object, object>()\n\treadonly #settled = new WeakSet<object>()\n\treadonly #survivors = new Map<object, unknown>()\n\treadonly #owing = new Set<object>()\n\treadonly #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new Map<object, Set<object>>()\n\treadonly #destroying = new Map<object, Promise<void>>()\n\treadonly #waiters: Array<PromiseWithResolvers<PoolToken<T>>> = []\n\treadonly #assigned = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #reservations = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #signals = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t{ readonly signal: AbortSignal; readonly listener: () => void }\n\t>()\n\treadonly #ready = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t| { readonly success: true; readonly record: object; readonly token: PoolToken<T> }\n\t\t| { readonly success: false; readonly error: unknown }\n\t>()\n\treadonly #operations = new Set<Promise<void>>()\n\treadonly #owned = new Set<Promise<void>>()\n\treadonly #failures: unknown[] = []\n\t#ending: PromiseWithResolvers<void> | undefined\n\t#pumping = false\n\t#repump = false\n\t#started = false\n\t#starting: PromiseWithResolvers<void> | undefined\n\t#refilling = false\n\t#strikes = 0\n\t#epoch = {}\n\t#owed = 0\n\t#cause: unknown\n\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor\n\t * @throws {@link PoolError} Thrown with `code: 'invalid'` when `capacity`, `min`, or `max` is not a positive\n\t * safe integer, explicit `min` and `max` differ, `restarts` is absent with `min`, present without\n\t * `min`, or not a non-negative safe integer, or `watch` is not callable.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tconst capacity = options.capacity\n\t\tconst min = options.min\n\t\tconst restarts = options.restarts\n\t\tconst watch = options.watch\n\t\tif (max !== undefined && !isPoolLimit(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\n\t\t}\n\t\tif (capacity !== undefined && !isPoolLimit(capacity)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: capacity } })\n\t\t}\n\t\tif (min !== undefined && (!isPoolLimit(min) || (max !== undefined && min !== max))) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: min } })\n\t\t}\n\t\tif (\n\t\t\t(min !== undefined && restarts === undefined) ||\n\t\t\t(restarts !== undefined &&\n\t\t\t\t(min === undefined ||\n\t\t\t\t\t!isNumber(restarts) ||\n\t\t\t\t\t!Number.isSafeInteger(restarts) ||\n\t\t\t\t\trestarts < 0))\n\t\t) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: restarts } })\n\t\t}\n\t\tif (watch !== undefined && !isFunction(watch)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: watch } })\n\t\t}\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#create = options.create\n\t\tthis.#destroy = options.destroy\n\t\tthis.#validate = options.validate\n\t\tthis.#max = max ?? min\n\t\tthis.#capacity = capacity ?? 1\n\t\tthis.#min = min\n\t\tthis.#restarts = restarts\n\t\tthis.#watch = watch\n\t\tthis.#error = error\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\t/** Holds the typed synchronous lifecycle observation surface. */\n\tget emitter(): EmitterInterface<PoolEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Counts all owned records, including records validating, destroying, or retained after failed cleanup. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts available records with no live lease or pending handout. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts records with live leases, counting a shared record once rather than counting its leases. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Fills the warm floor and resets the strikes of a spent floor; without a floor, resolves immediately.\n\t *\n\t * @returns A promise that resolves when the floor owns `min` live records\n\t * @throws {@link PoolError} Thrown as a rejection with `code: 'create'` and the last cause\n\t * when the bound is spent, `code: 'cleanup'` when retained failed cleanup prevents filling,\n\t * or `code: 'destroyed'` when teardown begins.\n\t */\n\tstart(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (this.#min === undefined) return Promise.resolve()\n\t\tif (this.#starting !== undefined) return this.#starting.promise\n\t\tconst starting = Promise.withResolvers<void>()\n\t\tthis.#starting = starting\n\t\tthis.#started = true\n\t\tif (this.#spent()) this.#strikes = 0\n\t\tthis.#pump()\n\t\treturn starting.promise\n\t}\n\n\t/**\n\t * Queues the caller in FIFO order, shares an occupied record or validates an idle record, and\n\t * waits for a floor refill or creates on demand without a floor.\n\t *\n\t * @param signal - Optional native cancellation signal\n\t * @returns A promise for the unique resource lease\n\t * @throws {@link PoolError} Thrown when `signal` is present and is not a native `AbortSignal`,\n\t * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller\n\t * that handles failures with `.catch()` alone misses it.\n\t * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with\n\t * `code: 'destroyed'`; when the create hook fails or the floor is spent without an eligible record,\n\t * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or\n\t * a floor retains a record, owns `min` records, has nothing eligible, and has no refill or disposal\n\t * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.\n\t * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.\n\t */\n\tacquire(signal?: AbortSignal): Promise<PoolToken<T>> {\n\t\tif (signal !== undefined && !isPoolSignal(signal)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (signal !== undefined) {\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) return Promise.reject(state[1])\n\t\t}\n\n\t\tconst waiter = Promise.withResolvers<PoolToken<T>>()\n\t\tthis.#waiters.push(waiter)\n\t\tif (signal !== undefined) {\n\t\t\tconst listener = this.#createAbort(waiter, signal)\n\t\t\tAbortSignal.prototype.addEventListener.call(signal, 'abort', listener, { once: true })\n\t\t\tthis.#signals.set(waiter, { signal, listener })\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) this.#abort(waiter, state[1])\n\t\t}\n\t\tthis.#pump()\n\t\treturn waiter.promise\n\t}\n\n\t/**\n\t * Destroys the records that are idle at this call's synchronous snapshot and restores a started floor.\n\t *\n\t * @returns A promise that settles after every snapshot cleanup attempt\n\t * @throws {@link PoolError} Thrown when `destroy()` has already begun, with `code: 'destroyed'`.\n\t * @throws {@link PoolError} Thrown when a claimed record's destroy hook fails, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. Each arrives as a rejected\n\t * promise rather than a synchronous throw.\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tconst records = this.#available.splice(0)\n\t\tconst cleanups: Array<Promise<void>> = []\n\t\tfor (const record of records) {\n\t\t\tconst cleanup = this.#dispose(record)\n\t\t\tcleanups.push(cleanup)\n\t\t\tvoid cleanup.then(\n\t\t\t\t() => this.#pump(),\n\t\t\t\t() => this.#pump(),\n\t\t\t)\n\t\t}\n\t\treturn this.#settleClear(cleanups)\n\t}\n\n\t/**\n\t * Tears down the pool permanently and returns its stable completion barrier.\n\t *\n\t * @returns The exact promise shared by every destroy call\n\t * @throws {@link PoolError} Thrown when a destroy hook failure was retained or occurred during teardown, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. The barrier rejects; it\n\t * never throws synchronously, and a repeat call receives the same rejected promise.\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending.promise\n\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending\n\t\tthis.#starting?.reject(new PoolError({ code: 'destroyed' }))\n\t\tthis.#starting = undefined\n\t\tconst waiters = this.#waiters.splice(0)\n\t\tfor (const waiter of waiters) {\n\t\t\tthis.#detach(waiter)\n\t\t\twaiter.reject(new PoolError({ code: 'destroyed' }))\n\t\t}\n\t\tthis.#ready.clear()\n\t\tthis.#assigned.clear()\n\t\tthis.#available.splice(0)\n\t\tfor (const cleanup of this.#destroying.values()) this.#own(cleanup)\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (!this.#validating.has(record)) this.#own(this.#dispose(record))\n\t\t}\n\t\tthis.#finish()\n\t\treturn ending.promise\n\t}\n\n\t#createAbort(waiter: PromiseWithResolvers<PoolToken<T>>, signal: AbortSignal): () => void {\n\t\treturn (): void => {\n\t\t\tconst state = attempt(() => this.#state(signal))\n\t\t\tthis.#abort(waiter, state.success ? state.value[1] : state.error)\n\t\t}\n\t}\n\n\t#state(signal: AbortSignal): readonly [aborted: boolean, reason: unknown] {\n\t\tconst aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tconst reason = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason')?.get\n\t\tif (aborted === undefined || reason === undefined) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\ttry {\n\t\t\tconst stopped = Reflect.apply(aborted, signal, []) === true\n\t\t\treturn [stopped, stopped ? Reflect.apply(reason, signal, []) : undefined]\n\t\t} catch (error: unknown) {\n\t\t\tthrow new PoolError({ code: 'invalid', cause: error, context: { value: signal } })\n\t\t}\n\t}\n\n\t#token(record: object, value: T, lease: object): PoolToken<T> {\n\t\treturn {\n\t\t\tvalue,\n\t\t\trelease: this.#createRelease(record, lease),\n\t\t\tdestroy: this.#createDestroy(record, lease),\n\t\t}\n\t}\n\n\t#createRelease(record: object, lease: object): () => void {\n\t\treturn (): void => {\n\t\t\tif (this.#settled.has(lease)) return\n\t\t\tthis.#settled.add(lease)\n\t\t\tthis.#release(record, lease)\n\t\t}\n\t}\n\n\t#createDestroy(record: object, lease: object): () => Promise<void> {\n\t\treturn (): Promise<void> => {\n\t\t\tif (this.#settled.has(lease)) return Promise.resolve()\n\t\t\tthis.#settled.add(lease)\n\t\t\treturn (this.#destroying.get(record) ?? this.#lose(record)).catch((error: unknown) => {\n\t\t\t\tthrow new PoolError({ code: 'cleanup', cause: error })\n\t\t\t})\n\t\t}\n\t}\n\n\t#abort(waiter: PromiseWithResolvers<PoolToken<T>>, reason: unknown): void {\n\t\tconst index = this.#waiters.indexOf(waiter)\n\t\tif (index < 0) return\n\t\tthis.#waiters.splice(index, 1)\n\t\tthis.#detach(waiter)\n\t\tconst ready = this.#ready.get(waiter)\n\t\tthis.#ready.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (ready?.success === true) {\n\t\t\tthis.#recycle(ready.record)\n\t\t}\n\t\twaiter.reject(reason)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t}\n\n\t#detach(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst entry = this.#signals.get(waiter)\n\t\tif (entry === undefined) return\n\t\tAbortSignal.prototype.removeEventListener.call(entry.signal, 'abort', entry.listener)\n\t\tthis.#signals.delete(waiter)\n\t}\n\n\t#pump(): void {\n\t\tif (this.#ending !== undefined) return\n\t\tif (this.#pumping) {\n\t\t\tthis.#repump = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.#pumping = true\n\t\tdo {\n\t\t\tthis.#repump = false\n\t\t\tfor (const waiter of this.#waiters) {\n\t\t\t\tif (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue\n\t\t\t\tconst record = this.#select()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tconst index = this.#available.indexOf(record)\n\t\t\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\t\t\tif (this.#occupancy(record) === 0) this.#validating.add(record)\n\t\t\t\t\tthis.#startValidation(waiter, record)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (this.#min !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#resources.size >= this.#min &&\n\t\t\t\t\t\tthis.#survivors.size > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({\n\t\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\t\tcause: this.#survivors.values().next().value,\n\t\t\t\t\t\t\t\tcontext: { failures: [...this.#failures] },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#spent() &&\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#owed === 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({ code: 'create', cause: this.#cause }),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif (this.#max === undefined || this.#resources.size + this.#reservations.size < this.#max) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#reservations.add(waiter)\n\t\t\t\t\tthis.#startCreate(waiter)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t} while (this.#repump)\n\t\tthis.#pumping = false\n\t\tthis.#fill()\n\t}\n\n\t#occupancy(record: object): number {\n\t\tconst leased = this.#leased.get(record)?.size ?? 0\n\t\treturn this.#ready.values().reduce((count, result) => {\n\t\t\treturn count + (result.success && result.record === record ? 1 : 0)\n\t\t}, leased)\n\t}\n\n\t#select(): object | undefined {\n\t\tconst selected = this.#resources.keys().reduce<{\n\t\t\treadonly record?: object\n\t\t\treadonly count: number\n\t\t}>(\n\t\t\t(candidate, record) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\t\tthis.#survivors.has(record)\n\t\t\t\t)\n\t\t\t\t\treturn candidate\n\t\t\t\tconst count = this.#occupancy(record)\n\t\t\t\tif (count === 0 && !this.#available.includes(record)) return candidate\n\t\t\t\treturn count < candidate.count ? { record, count } : candidate\n\t\t\t},\n\t\t\t{ count: this.#capacity },\n\t\t)\n\t\treturn this.#available[0] ?? selected.record\n\t}\n\n\t#spent(): boolean {\n\t\treturn this.#restarts !== undefined && this.#strikes > this.#restarts\n\t}\n\n\t#fill(): void {\n\t\tif (this.#ending !== undefined || !this.#started || this.#min === undefined) return\n\t\tif (this.#refilling) return\n\t\tconst live = this.#resources.size - this.#destroying.size - this.#survivors.size\n\t\tif (live >= this.#min) {\n\t\t\tthis.#starting?.resolve()\n\t\t\tthis.#starting = undefined\n\t\t}\n\t\tif (this.#resources.size < this.#min && (!this.#spent() || this.#owed > 0)) {\n\t\t\tif (this.#owed > 0) this.#owed -= 1\n\t\t\tthis.#refilling = true\n\t\t\tconst operation = Promise.resolve().then(() => this.#refill())\n\t\t\tthis.#operations.add(operation)\n\t\t\t// Refill never rejects: create failures are caught, and watch/emitter callbacks isolate errors.\n\t\t\tvoid operation.then(() => {\n\t\t\t\tthis.#refilling = false\n\t\t\t\tthis.#completeOperation(operation)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tif (this.#destroying.size > 0) return\n\t\tif (this.#spent() || this.#survivors.size > 0) {\n\t\t\tthis.#starting?.reject(\n\t\t\t\tthis.#spent()\n\t\t\t\t\t? new PoolError({ code: 'create', cause: this.#cause })\n\t\t\t\t\t: this.#cleanupError(this.#failures),\n\t\t\t)\n\t\t\tthis.#starting = undefined\n\t\t}\n\t}\n\n\tasync #refill(): Promise<void> {\n\t\tif (this.#ending !== undefined) return\n\t\tconst creation = await this.#produce()\n\t\tif (!creation.success) {\n\t\t\tthis.#addStrike(creation.error)\n\t\t\treturn\n\t\t}\n\t\tconst record = this.#insert(creation.value)\n\t\tthis.#recycle(record)\n\t}\n\n\tasync #produce(): Promise<Result<T>> {\n\t\ttry {\n\t\t\treturn { success: true, value: await this.#create() }\n\t\t} catch (error: unknown) {\n\t\t\treturn { success: false, error }\n\t\t}\n\t}\n\n\t#insert(value: T): object {\n\t\tconst record = {}\n\t\tthis.#births.set(record, this.#epoch)\n\t\tthis.#resources.set(record, value)\n\t\tif (this.#watch !== undefined) {\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#watches.set(record, controller)\n\t\t\tconst watching = attempt(() => this.#watch?.(value, controller.signal))\n\t\t\tconst settled = watching.success\n\t\t\t\t? Promise.resolve(watching.value)\n\t\t\t\t: Promise.reject(watching.error)\n\t\t\tvoid settled.then(\n\t\t\t\t() => this.#own(this.#lose(record)),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (controller.signal.aborted) return\n\t\t\t\t\tthis.#own(this.#lose(record, error))\n\t\t\t\t\tattempt(() => this.#error?.(error, 'watch'))\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tthis.#emitter.emit('create')\n\t\treturn record\n\t}\n\n\tasync #lose(record: object, cause?: unknown): Promise<void> {\n\t\tif (\n\t\t\tthis.#ending !== undefined ||\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t)\n\t\t\treturn\n\t\tif (this.#leased.has(record) && this.#min !== undefined) this.#owing.add(record)\n\t\tthis.#strike(record, cause)\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#pump()\n\t\t\tthrow error\n\t\t}\n\t\tthis.#pump()\n\t}\n\n\t#strike(record: object, cause?: unknown): void {\n\t\tif (this.#min !== undefined && !this.#leased.has(record)) {\n\t\t\tthis.#addStrike(cause)\n\t\t}\n\t}\n\n\t#addStrike(cause: unknown): void {\n\t\tthis.#strikes += 1\n\t\tthis.#cause = cause\n\t\tthis.#epoch = {}\n\t}\n\n\t#startCreate(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst operation = Promise.resolve().then(() => this.#createResource(waiter))\n\t\tthis.#operations.add(operation)\n\t\tvoid operation.then(\n\t\t\t() => this.#completeOperation(operation),\n\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'create'),\n\t\t)\n\t}\n\n\t#startValidation(waiter: PromiseWithResolvers<PoolToken<T>>, record: object): void {\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tif (!this.#validating.has(record) || this.#validate === undefined) {\n\t\t\t\tthis.#validating.delete(record)\n\t\t\t\tthis.#prepare(waiter, record, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst operation = Promise.resolve().then(() => this.#validateResource(waiter, record, value))\n\t\t\tthis.#operations.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#completeOperation(operation),\n\t\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'invalid'),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.#validating.delete(record)\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#repump = true\n\t}\n\n\tasync #createResource(waiter: PromiseWithResolvers<PoolToken<T>>): Promise<void> {\n\t\tconst creation = await this.#produce()\n\t\tif (!creation.success) {\n\t\t\tthis.#reservations.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'create', cause: creation.error }),\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t\treturn\n\t\t}\n\n\t\tconst value = creation.value\n\t\tthis.#reservations.delete(waiter)\n\t\tconst record = this.#insert(value)\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\tasync #validateResource(\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\trecord: object,\n\t\tvalue: T,\n\t): Promise<void> {\n\t\tconst valid = await this.#check(value)\n\t\tthis.#validating.delete(record)\n\t\tif (\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!valid) this.#strike(record)\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (valid) this.#recycle(record)\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#dispose(record)\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthis.#record(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (valid) {\n\t\t\tthis.#prepare(waiter, record, value)\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'cleanup', cause: error }),\n\t\t\t\t})\n\t\t\t\tthis.#commit()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#record(error)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#pump()\n\t}\n\n\tasync #check(value: T): Promise<boolean> {\n\t\ttry {\n\t\t\treturn (await this.#validate?.(value)) === true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\n\t#prepare(waiter: PromiseWithResolvers<PoolToken<T>>, record: object, value: T): void {\n\t\tif (!this.#waiters.includes(waiter) || this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\t#commit(): void {\n\t\twhile (this.#ending === undefined) {\n\t\t\tconst waiter = this.#waiters[0]\n\t\t\tif (waiter === undefined) return\n\t\t\tconst result = this.#ready.get(waiter)\n\t\t\tif (result === undefined) return\n\t\t\tif (\n\t\t\t\tresult.success &&\n\t\t\t\t(!this.#resources.has(result.record) ||\n\t\t\t\t\tthis.#destroying.has(result.record) ||\n\t\t\t\t\tthis.#survivors.has(result.record))\n\t\t\t) {\n\t\t\t\tthis.#ready.delete(waiter)\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t\tthis.#repump = true\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#waiters.shift()\n\t\t\tthis.#repump = true\n\t\t\tthis.#ready.delete(waiter)\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#detach(waiter)\n\t\t\tif (!result.success) {\n\t\t\t\twaiter.reject(result.error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst leases = this.#leased.get(result.record) ?? new Set<object>()\n\t\t\tleases.add(waiter)\n\t\t\tthis.#leased.set(result.record, leases)\n\t\t\tif (this.#births.get(result.record) === this.#epoch) this.#strikes = 0\n\t\t\twaiter.resolve(result.token)\n\t\t\tthis.#emitter.emit('acquire')\n\t\t}\n\t}\n\n\t#completeOperation(operation: Promise<void>): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#failOperation(\n\t\toperation: Promise<void>,\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\terror: unknown,\n\t\tcode: PoolCode,\n\t): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#reservations.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (this.#waiters.includes(waiter)) {\n\t\t\tthis.#ready.set(waiter, { success: false, error: new PoolError({ code, cause: error }) })\n\t\t}\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#release(record: object, lease: object): void {\n\t\tconst leases = this.#leased.get(record)\n\t\tif (leases === undefined || !leases.delete(lease)) return\n\t\tif (leases.size === 0) this.#leased.delete(record)\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record))\n\t\t\treturn\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tthis.#occupancy(record) === 0 &&\n\t\t\t!this.#validating.has(record) &&\n\t\t\t!this.#available.includes(record)\n\t\t) {\n\t\t\tthis.#available.push(record)\n\t\t}\n\t\tthis.#pump()\n\t\tif (this.#available.includes(record)) this.#emitter.emit('release')\n\t}\n\n\t#dispose(record: object): Promise<void> {\n\t\tif (this.#survivors.has(record)) return Promise.resolve()\n\t\tconst existing = this.#destroying.get(record)\n\t\tif (existing !== undefined) return existing\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tconst cleanup = Promise.withResolvers<void>()\n\t\t\tthis.#destroying.set(record, cleanup.promise)\n\t\t\tconst index = this.#available.indexOf(record)\n\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\tthis.#validating.delete(record)\n\t\t\tthis.#leased.delete(record)\n\t\t\tthis.#watches.get(record)?.abort()\n\t\t\tthis.#watches.delete(record)\n\t\t\tif (this.#ending !== undefined) this.#own(cleanup.promise)\n\t\t\tvoid this.#clean(record, value, cleanup)\n\t\t\treturn cleanup.promise\n\t\t}\n\t\treturn Promise.resolve()\n\t}\n\n\tasync #clean(record: object, value: T, cleanup: PromiseWithResolvers<void>): Promise<void> {\n\t\tconst disposal = await this.#disposeValue(value)\n\t\tif (!disposal.success && this.#min !== undefined) {\n\t\t\tthis.#survivors.set(record, disposal.error)\n\t\t\tthis.#record(disposal.error)\n\t\t} else {\n\t\t\tthis.#resources.delete(record)\n\t\t\tif (this.#owing.has(record)) this.#owed += 1\n\t\t}\n\t\tthis.#owing.delete(record)\n\t\tif (!disposal.success) cleanup.reject(disposal.error)\n\t\telse cleanup.resolve()\n\t\t// Cleanup owners must bind outcomes before destroy observers can reenter.\n\t\tawait Promise.resolve()\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#destroying.delete(record)\n\t\tif (this.#min !== undefined) this.#pump()\n\t\tthis.#finish()\n\t}\n\n\tasync #disposeValue(value: T): Promise<Result<void>> {\n\t\tconst disposal = attempt(() => Promise.resolve(this.#destroy?.(value)))\n\t\ttry {\n\t\t\tawait (disposal.success ? disposal.value : Promise.reject(disposal.error))\n\t\t\treturn { success: true, value: undefined }\n\t\t} catch (error: unknown) {\n\t\t\treturn { success: false, error }\n\t\t}\n\t}\n\n\tasync #settleClear(cleanups: ReadonlyArray<Promise<void>>): Promise<void> {\n\t\tconst settled = await Promise.allSettled(cleanups)\n\t\tconst failures: unknown[] = []\n\t\tfor (const result of settled) {\n\t\t\tif (\n\t\t\t\tresult.status === 'rejected' &&\n\t\t\t\t!failures.some((failure) => Object.is(failure, result.reason))\n\t\t\t) {\n\t\t\t\tfailures.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (failures.length > 0) throw this.#cleanupError(failures)\n\t}\n\n\t#own(cleanup: Promise<void>): void {\n\t\tif (this.#owned.has(cleanup)) return\n\t\tthis.#owned.add(cleanup)\n\t\tvoid cleanup.then(\n\t\t\t() => this.#completeCleanup(cleanup),\n\t\t\t(error: unknown) => this.#failCleanup(cleanup, error),\n\t\t)\n\t}\n\n\t#completeCleanup(cleanup: Promise<void>): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#finish()\n\t}\n\n\t#failCleanup(cleanup: Promise<void>, error: unknown): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#record(error)\n\t\tthis.#finish()\n\t}\n\n\t#record(error: unknown): void {\n\t\tif (!this.#failures.some((failure) => Object.is(failure, error))) this.#failures.push(error)\n\t}\n\n\t#cleanupError(failures: readonly unknown[]): PoolError {\n\t\treturn new PoolError({\n\t\t\tcode: 'cleanup',\n\t\t\t...(failures[0] === undefined ? {} : { cause: failures[0] }),\n\t\t\tcontext: { failures: [...failures] },\n\t\t})\n\t}\n\n\t#finish(): void {\n\t\tconst ending = this.#ending\n\t\tif (ending === undefined || this.#operations.size > 0 || this.#owned.size > 0) return\n\t\tconst claimed = this.#resources.keys().reduce((previous, record) => {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\treturn previous\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn true\n\t\t}, false)\n\t\tif (claimed || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return\n\t\tthis.#emitter.destroy()\n\t\tif (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures))\n\t\telse ending.resolve()\n\t}\n}\n","import type { PoolInterface, PoolOptions } from './types.js'\nimport { Pool } from './Pool.js'\n\n/**\n * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded\n * capacity, exclusive leases by default, and FIFO settlement.\n *\n * @remarks\n * Concurrent create and validation hooks may overlap, while acquire promises settle in\n * request order. `clear` owns its idle snapshot; `destroy` returns one stable barrier and\n * waits for every in-flight create, validation, and destroy attempt before destroying the\n * emitter last.\n * Set `min` with its required `restarts` bound and call `start()` to warm resources and\n * refill losses independently of queued acquires. `watch` observes loss and its signal\n * aborts at disposal; a token can declare loss through `destroy()`.\n *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, capacity, optional bounded warm floor, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown with `code: 'invalid'` when capacity, restart bounds, or\n * the watch hook are invalid. Construction validates them synchronously, before the pool exists.\n *\n * @example Create a pool\n * ```ts\n * import { createPool } from '@orkestrel/pool'\n *\n * const pool = createPool<Connection>({\n * \tcreate: () => connect(),\n * \tdestroy: (connection) => connection.close(),\n * \tvalidate: (connection) => connection.alive,\n * \tmax: 8,\n * })\n *\n * const token = await pool.acquire()\n * try {\n * \tawait token.value.query('select 1')\n * } finally {\n * \ttoken.release()\n * }\n * ```\n */\nexport function createPool<T>(options: PoolOptions<T>): PoolInterface<T> {\n\treturn new Pool(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;;;;;CAOA,YAAY,SAA2B;EACtC,MAAM,YAAY,QAAQ,SAAS,cAAc,sBAAsB;EACvE,MAAM,UAAU,QAAQ,SAAS,WAAW,uBAAuB;EACnE,MAAM,SAAS,QAAQ,SAAS,YAAY,wBAAwB;EACpE,MAAM,WAAA,GACLA,oBAAAA,QAAAA,CAAQ,QAAQ,KAAK,MAAA,GAAKC,oBAAAA,SAAAA,CAAS,QAAQ,MAAM,OAAO,KAAK,QAAQ,MAAM,QAAQ,SAAS,IACzF,GAAG,OAAO,IAAI,QAAQ,MAAM,YAC5B;EACJ,MAAM,SAAS,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EACjF,oBAAA,WAAW,OAAO,MA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|
|
@@ -43,7 +43,11 @@ import type { EmitterInterface } from '@orkestrel/emitter';
|
|
|
43
43
|
export declare function createPool<T>(options: PoolOptions<T>): PoolInterface<T>;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Tests whether an unknown value is a {@link PoolError}
|
|
46
|
+
* Tests whether an unknown value is a branded {@link PoolError} with declared code and context.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Accepts subclasses and errors from another installed copy without reading `name`. Refuses
|
|
50
|
+
* transparent proxies, unbranded look-alikes, and plain branded objects.
|
|
47
51
|
*
|
|
48
52
|
* @param value - The unknown boundary value
|
|
49
53
|
* @returns True if the value is a real `PoolError` instance; false otherwise
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -43,7 +43,11 @@ import type { EmitterInterface } from '@orkestrel/emitter';
|
|
|
43
43
|
export declare function createPool<T>(options: PoolOptions<T>): PoolInterface<T>;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Tests whether an unknown value is a {@link PoolError}
|
|
46
|
+
* Tests whether an unknown value is a branded {@link PoolError} with declared code and context.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Accepts subclasses and errors from another installed copy without reading `name`. Refuses
|
|
50
|
+
* transparent proxies, unbranded look-alikes, and plain branded objects.
|
|
47
51
|
*
|
|
48
52
|
* @param value - The unknown boundary value
|
|
49
53
|
* @returns True if the value is a real `PoolError` instance; false otherwise
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { attempt, holds, isError, isFunction,
|
|
1
|
+
import { INTRINSICS, attempt, holds, isArray, isError, isFunction, isNumber, isObject, isString } from "@orkestrel/contract";
|
|
2
2
|
import { Emitter } from "@orkestrel/emitter";
|
|
3
|
-
|
|
3
|
+
// src/core/errors.ts
|
|
4
4
|
/**
|
|
5
5
|
* Represents a stable, machine-readable pool failure that retains the original thrown value as
|
|
6
6
|
* its cause without unsafe coercion, alongside structured context.
|
|
@@ -27,19 +27,23 @@ var PoolError = class extends Error {
|
|
|
27
27
|
* @param options - Stable code plus optional cause and structured context
|
|
28
28
|
*/
|
|
29
29
|
constructor(options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (isError(options.cause) && isString(options.cause.message) && options.cause.message.length > 0) message = `${message}: ${options.cause.message}`;
|
|
30
|
+
const destroyed = options.code === "destroyed" ? "pool is destroyed" : "pool input is invalid";
|
|
31
|
+
const created = options.code === "create" ? "pool create failed" : destroyed;
|
|
32
|
+
const reason = options.code === "cleanup" ? "pool cleanup failed" : created;
|
|
33
|
+
const message = isError(options.cause) && isString(options.cause.message) && options.cause.message.length > 0 ? `${reason}: ${options.cause.message}` : reason;
|
|
35
34
|
super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
35
|
+
INTRINSICS.define(this, Symbol.for("@orkestrel/pool.PoolError"), { value: this });
|
|
36
36
|
this.name = "PoolError";
|
|
37
37
|
this.code = options.code;
|
|
38
38
|
this.context = options.context;
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
* Tests whether an unknown value is a {@link PoolError}
|
|
42
|
+
* Tests whether an unknown value is a branded {@link PoolError} with declared code and context.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Accepts subclasses and errors from another installed copy without reading `name`. Refuses
|
|
46
|
+
* transparent proxies, unbranded look-alikes, and plain branded objects.
|
|
43
47
|
*
|
|
44
48
|
* @param value - The unknown boundary value
|
|
45
49
|
* @returns True if the value is a real `PoolError` instance; false otherwise
|
|
@@ -51,10 +55,21 @@ var PoolError = class extends Error {
|
|
|
51
55
|
* ```
|
|
52
56
|
*/
|
|
53
57
|
function isPoolError(value) {
|
|
54
|
-
|
|
58
|
+
if (!isObject(value)) return false;
|
|
59
|
+
return holds(() => {
|
|
60
|
+
if (!(value instanceof INTRINSICS.error)) return false;
|
|
61
|
+
if (INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false;
|
|
62
|
+
if (INTRINSICS.describe(value, Symbol.for("@orkestrel/pool.PoolError"))?.value !== value) return false;
|
|
63
|
+
const code = INTRINSICS.reflect.read(value, "code");
|
|
64
|
+
if (code !== "invalid" && code !== "destroyed" && code !== "create" && code !== "cleanup") return false;
|
|
65
|
+
const context = INTRINSICS.reflect.read(value, "context");
|
|
66
|
+
if (context === void 0) return true;
|
|
67
|
+
if (!isObject(context) && !isFunction(context)) return false;
|
|
68
|
+
const failures = INTRINSICS.reflect.read(context, "failures");
|
|
69
|
+
return failures === void 0 || isArray(failures);
|
|
70
|
+
});
|
|
55
71
|
}
|
|
56
|
-
|
|
57
|
-
//#region src/core/validators.ts
|
|
72
|
+
// src/core/validators.ts
|
|
58
73
|
/**
|
|
59
74
|
* Tests whether a value is a positive safe integer for a pool record or lease limit.
|
|
60
75
|
*
|
|
@@ -91,8 +106,7 @@ function isPoolSignal(value) {
|
|
|
91
106
|
return true;
|
|
92
107
|
});
|
|
93
108
|
}
|
|
94
|
-
|
|
95
|
-
//#region src/core/Pool.ts
|
|
109
|
+
// src/core/Pool.ts
|
|
96
110
|
/**
|
|
97
111
|
* Represents a resource pool with optional bounded capacity and a warm floor, whose opaque
|
|
98
112
|
* ownership records preserve FIFO settlement, cancellation, exact lease release, and
|
|
@@ -328,13 +342,8 @@ var Pool = class {
|
|
|
328
342
|
}
|
|
329
343
|
#createAbort(waiter, signal) {
|
|
330
344
|
return () => {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
reason = this.#state(signal)[1];
|
|
334
|
-
} catch (error) {
|
|
335
|
-
reason = error;
|
|
336
|
-
}
|
|
337
|
-
this.#abort(waiter, reason);
|
|
345
|
+
const state = attempt(() => this.#state(signal));
|
|
346
|
+
this.#abort(waiter, state.success ? state.value[1] : state.error);
|
|
338
347
|
};
|
|
339
348
|
}
|
|
340
349
|
#state(signal) {
|
|
@@ -458,23 +467,22 @@ var Pool = class {
|
|
|
458
467
|
this.#fill();
|
|
459
468
|
}
|
|
460
469
|
#occupancy(record) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
470
|
+
const leased = this.#leased.get(record)?.size ?? 0;
|
|
471
|
+
return this.#ready.values().reduce((count, result) => {
|
|
472
|
+
return count + (result.success && result.record === record ? 1 : 0);
|
|
473
|
+
}, leased);
|
|
464
474
|
}
|
|
465
475
|
#select() {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
for (const record of this.#resources.keys()) {
|
|
469
|
-
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) continue;
|
|
476
|
+
const selected = this.#resources.keys().reduce((candidate, record) => {
|
|
477
|
+
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) return candidate;
|
|
470
478
|
const count = this.#occupancy(record);
|
|
471
|
-
if (count === 0 && !this.#available.includes(record))
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
return this.#available[0] ?? selected;
|
|
479
|
+
if (count === 0 && !this.#available.includes(record)) return candidate;
|
|
480
|
+
return count < candidate.count ? {
|
|
481
|
+
record,
|
|
482
|
+
count
|
|
483
|
+
} : candidate;
|
|
484
|
+
}, { count: this.#capacity });
|
|
485
|
+
return this.#available[0] ?? selected.record;
|
|
478
486
|
}
|
|
479
487
|
#spent() {
|
|
480
488
|
return this.#restarts !== void 0 && this.#strikes > this.#restarts;
|
|
@@ -508,16 +516,27 @@ var Pool = class {
|
|
|
508
516
|
}
|
|
509
517
|
async #refill() {
|
|
510
518
|
if (this.#ending !== void 0) return;
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
} catch (error) {
|
|
515
|
-
this.#addStrike(error);
|
|
519
|
+
const creation = await this.#produce();
|
|
520
|
+
if (!creation.success) {
|
|
521
|
+
this.#addStrike(creation.error);
|
|
516
522
|
return;
|
|
517
523
|
}
|
|
518
|
-
const record = this.#insert(value);
|
|
524
|
+
const record = this.#insert(creation.value);
|
|
519
525
|
this.#recycle(record);
|
|
520
526
|
}
|
|
527
|
+
async #produce() {
|
|
528
|
+
try {
|
|
529
|
+
return {
|
|
530
|
+
success: true,
|
|
531
|
+
value: await this.#create()
|
|
532
|
+
};
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return {
|
|
535
|
+
success: false,
|
|
536
|
+
error
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
521
540
|
#insert(value) {
|
|
522
541
|
const record = {};
|
|
523
542
|
this.#births.set(record, this.#epoch);
|
|
@@ -578,22 +597,21 @@ var Pool = class {
|
|
|
578
597
|
this.#repump = true;
|
|
579
598
|
}
|
|
580
599
|
async #createResource(waiter) {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
value = await this.#create();
|
|
584
|
-
} catch (error) {
|
|
600
|
+
const creation = await this.#produce();
|
|
601
|
+
if (!creation.success) {
|
|
585
602
|
this.#reservations.delete(waiter);
|
|
586
603
|
if (this.#waiters.includes(waiter)) this.#ready.set(waiter, {
|
|
587
604
|
success: false,
|
|
588
605
|
error: new PoolError({
|
|
589
606
|
code: "create",
|
|
590
|
-
cause: error
|
|
607
|
+
cause: creation.error
|
|
591
608
|
})
|
|
592
609
|
});
|
|
593
610
|
else this.#assigned.delete(waiter);
|
|
594
611
|
this.#commit();
|
|
595
612
|
return;
|
|
596
613
|
}
|
|
614
|
+
const value = creation.value;
|
|
597
615
|
this.#reservations.delete(waiter);
|
|
598
616
|
const record = this.#insert(value);
|
|
599
617
|
if (this.#ending !== void 0) {
|
|
@@ -616,10 +634,7 @@ var Pool = class {
|
|
|
616
634
|
this.#commit();
|
|
617
635
|
}
|
|
618
636
|
async #validateResource(waiter, record, value) {
|
|
619
|
-
|
|
620
|
-
try {
|
|
621
|
-
valid = await this.#validate?.(value) === true;
|
|
622
|
-
} catch {}
|
|
637
|
+
const valid = await this.#check(value);
|
|
623
638
|
this.#validating.delete(record);
|
|
624
639
|
if (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) {
|
|
625
640
|
this.#assigned.delete(waiter);
|
|
@@ -670,6 +685,13 @@ var Pool = class {
|
|
|
670
685
|
this.#assigned.delete(waiter);
|
|
671
686
|
this.#pump();
|
|
672
687
|
}
|
|
688
|
+
async #check(value) {
|
|
689
|
+
try {
|
|
690
|
+
return await this.#validate?.(value) === true;
|
|
691
|
+
} catch {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
673
695
|
#prepare(waiter, record, value) {
|
|
674
696
|
if (!this.#waiters.includes(waiter) || this.#ending !== void 0) {
|
|
675
697
|
this.#assigned.delete(waiter);
|
|
@@ -770,29 +792,16 @@ var Pool = class {
|
|
|
770
792
|
return Promise.resolve();
|
|
771
793
|
}
|
|
772
794
|
async #clean(record, value, cleanup) {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
disposal = Promise.reject(error);
|
|
778
|
-
}
|
|
779
|
-
let failure;
|
|
780
|
-
let failed = false;
|
|
781
|
-
try {
|
|
782
|
-
await disposal;
|
|
783
|
-
} catch (error) {
|
|
784
|
-
failure = error;
|
|
785
|
-
failed = true;
|
|
786
|
-
}
|
|
787
|
-
if (failed && this.#min !== void 0) {
|
|
788
|
-
this.#survivors.set(record, failure);
|
|
789
|
-
this.#record(failure);
|
|
795
|
+
const disposal = await this.#disposeValue(value);
|
|
796
|
+
if (!disposal.success && this.#min !== void 0) {
|
|
797
|
+
this.#survivors.set(record, disposal.error);
|
|
798
|
+
this.#record(disposal.error);
|
|
790
799
|
} else {
|
|
791
800
|
this.#resources.delete(record);
|
|
792
801
|
if (this.#owing.has(record)) this.#owed += 1;
|
|
793
802
|
}
|
|
794
803
|
this.#owing.delete(record);
|
|
795
|
-
if (
|
|
804
|
+
if (!disposal.success) cleanup.reject(disposal.error);
|
|
796
805
|
else cleanup.resolve();
|
|
797
806
|
await Promise.resolve();
|
|
798
807
|
this.#emitter.emit("destroy");
|
|
@@ -800,6 +809,21 @@ var Pool = class {
|
|
|
800
809
|
if (this.#min !== void 0) this.#pump();
|
|
801
810
|
this.#finish();
|
|
802
811
|
}
|
|
812
|
+
async #disposeValue(value) {
|
|
813
|
+
const disposal = attempt(() => Promise.resolve(this.#destroy?.(value)));
|
|
814
|
+
try {
|
|
815
|
+
await (disposal.success ? disposal.value : Promise.reject(disposal.error));
|
|
816
|
+
return {
|
|
817
|
+
success: true,
|
|
818
|
+
value: void 0
|
|
819
|
+
};
|
|
820
|
+
} catch (error) {
|
|
821
|
+
return {
|
|
822
|
+
success: false,
|
|
823
|
+
error
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
}
|
|
803
827
|
async #settleClear(cleanups) {
|
|
804
828
|
const settled = await Promise.allSettled(cleanups);
|
|
805
829
|
const failures = [];
|
|
@@ -833,20 +857,17 @@ var Pool = class {
|
|
|
833
857
|
#finish() {
|
|
834
858
|
const ending = this.#ending;
|
|
835
859
|
if (ending === void 0 || this.#operations.size > 0 || this.#owned.size > 0) return;
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) continue;
|
|
839
|
-
claimed = true;
|
|
860
|
+
if (this.#resources.keys().reduce((previous, record) => {
|
|
861
|
+
if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) return previous;
|
|
840
862
|
this.#own(this.#dispose(record));
|
|
841
|
-
|
|
842
|
-
|
|
863
|
+
return true;
|
|
864
|
+
}, false) || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return;
|
|
843
865
|
this.#emitter.destroy();
|
|
844
866
|
if (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures));
|
|
845
867
|
else ending.resolve();
|
|
846
868
|
}
|
|
847
869
|
};
|
|
848
|
-
|
|
849
|
-
//#region src/core/factories.ts
|
|
870
|
+
// src/core/factories.ts
|
|
850
871
|
/**
|
|
851
872
|
* Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
|
|
852
873
|
* capacity, exclusive leases by default, and FIFO settlement.
|
|
@@ -888,7 +909,6 @@ var Pool = class {
|
|
|
888
909
|
function createPool(options) {
|
|
889
910
|
return new Pool(options);
|
|
890
911
|
}
|
|
891
|
-
//#endregion
|
|
892
912
|
export { Pool, PoolError, createPool, isPoolError, isPoolLimit, isPoolSignal };
|
|
893
913
|
|
|
894
914
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\nimport { isError, isInstance, isString } from '@orkestrel/contract'\n\n/**\n * Represents a stable, machine-readable pool failure that retains the original thrown value as\n * its cause without unsafe coercion, alongside structured context.\n *\n * @example\n * ```ts\n * import { PoolError, isPoolError } from '@orkestrel/pool'\n *\n * try {\n * \tawait pool.acquire()\n * } catch (error: unknown) {\n * \tif (isPoolError(error)) console.error(error.code, error.cause)\n * }\n * ```\n */\nexport class PoolError extends Error {\n\t/** Holds the stable machine-readable failure category. */\n\treadonly code\n\t/** Holds optional structured input or aggregate destroy-hook failure details. */\n\treadonly context\n\n\t/**\n\t * Creates a pool failure without coercing a hostile thrown value.\n\t *\n\t * @param options - Stable code plus optional cause and structured context\n\t */\n\tconstructor(options: PoolErrorOptions) {\n\t\tlet message = 'pool input is invalid'\n\t\tif (options.code === 'destroyed') message = 'pool is destroyed'\n\t\tif (options.code === 'create') message = 'pool create failed'\n\t\tif (options.code === 'cleanup') message = 'pool cleanup failed'\n\t\tif (\n\t\t\tisError(options.cause) &&\n\t\t\tisString(options.cause.message) &&\n\t\t\toptions.cause.message.length > 0\n\t\t) {\n\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t}\n\t\tsuper(message, options.cause === undefined ? undefined : { cause: options.cause })\n\t\tthis.name = 'PoolError'\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Tests whether an unknown value is a {@link PoolError}, returning `false` for hostile proxies.\n *\n * @param value - The unknown boundary value\n * @returns True if the value is a real `PoolError` instance; false otherwise\n *\n * @example\n * ```ts\n * isPoolError(new PoolError({ code: 'destroyed' })) // true\n * isPoolError(new Error('other')) // false\n * ```\n */\nexport function isPoolError(value: unknown): value is PoolError {\n\treturn isInstance(value, PoolError)\n}\n","import { holds, isFunction, isNumber } from '@orkestrel/contract'\n\n/**\n * Tests whether a value is a positive safe integer for a pool record or lease limit.\n *\n * @param value - The unknown record or lease limit candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolLimit(8) // true\n * isPoolLimit(Infinity) // false\n * ```\n */\nexport function isPoolLimit(value: unknown): value is number {\n\treturn isNumber(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`\n * for hostile proxies.\n *\n * @param value - The unknown signal candidate\n * @returns True if the value is a native `AbortSignal`; false otherwise\n *\n * @example\n * ```ts\n * isPoolSignal(new AbortController().signal) // true\n * isPoolSignal({ aborted: false }) // false\n * ```\n */\nexport function isPoolSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (!isFunction(getter)) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n","import type { EmitterErrorHandler, EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { attempt, isFunction, isNumber } from '@orkestrel/contract'\nimport { PoolError } from './errors.js'\nimport { isPoolLimit, isPoolSignal } from './validators.js'\n\n/**\n * Represents a resource pool with optional bounded capacity and a warm floor, whose opaque\n * ownership records preserve FIFO settlement, cancellation, exact lease release, and\n * deterministic teardown under concurrent hooks.\n *\n * @typeParam T - The pooled resource value\n *\n * @example\n * ```ts\n * import { Pool } from '@orkestrel/pool'\n *\n * const pool = new Pool({ create: () => new Uint8Array(64), max: 2 })\n * const token = await pool.acquire()\n * try {\n * \tconsume(token.value)\n * } finally {\n * \ttoken.release()\n * }\n * await pool.destroy()\n * ```\n */\nexport class Pool<T> implements PoolInterface<T> {\n\treadonly #create: () => Promise<T> | T\n\treadonly #destroy: ((value: T) => Promise<void> | void) | undefined\n\treadonly #validate: ((value: T) => Promise<boolean> | boolean) | undefined\n\treadonly #max: number | undefined\n\treadonly #capacity: number\n\treadonly #min: number | undefined\n\treadonly #restarts: number | undefined\n\treadonly #watch: PoolOptions<T>['watch']\n\treadonly #error: EmitterErrorHandler | undefined\n\treadonly #watches = new Map<object, AbortController>()\n\treadonly #births = new WeakMap<object, object>()\n\treadonly #settled = new WeakSet<object>()\n\treadonly #survivors = new Map<object, unknown>()\n\treadonly #owing = new Set<object>()\n\treadonly #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new Map<object, Set<object>>()\n\treadonly #destroying = new Map<object, Promise<void>>()\n\treadonly #waiters: Array<PromiseWithResolvers<PoolToken<T>>> = []\n\treadonly #assigned = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #reservations = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #signals = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t{ readonly signal: AbortSignal; readonly listener: () => void }\n\t>()\n\treadonly #ready = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t| { readonly success: true; readonly record: object; readonly token: PoolToken<T> }\n\t\t| { readonly success: false; readonly error: unknown }\n\t>()\n\treadonly #operations = new Set<Promise<void>>()\n\treadonly #owned = new Set<Promise<void>>()\n\treadonly #failures: unknown[] = []\n\t#ending: PromiseWithResolvers<void> | undefined\n\t#pumping = false\n\t#repump = false\n\t#started = false\n\t#starting: PromiseWithResolvers<void> | undefined\n\t#refilling = false\n\t#strikes = 0\n\t#epoch = {}\n\t#owed = 0\n\t#cause: unknown\n\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor\n\t * @throws {@link PoolError} Thrown with `code: 'invalid'` when `capacity`, `min`, or `max` is not a positive\n\t * safe integer, explicit `min` and `max` differ, `restarts` is absent with `min`, present without\n\t * `min`, or not a non-negative safe integer, or `watch` is not callable.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tconst capacity = options.capacity\n\t\tconst min = options.min\n\t\tconst restarts = options.restarts\n\t\tconst watch = options.watch\n\t\tif (max !== undefined && !isPoolLimit(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\n\t\t}\n\t\tif (capacity !== undefined && !isPoolLimit(capacity)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: capacity } })\n\t\t}\n\t\tif (min !== undefined && (!isPoolLimit(min) || (max !== undefined && min !== max))) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: min } })\n\t\t}\n\t\tif (\n\t\t\t(min !== undefined && restarts === undefined) ||\n\t\t\t(restarts !== undefined &&\n\t\t\t\t(min === undefined ||\n\t\t\t\t\t!isNumber(restarts) ||\n\t\t\t\t\t!Number.isSafeInteger(restarts) ||\n\t\t\t\t\trestarts < 0))\n\t\t) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: restarts } })\n\t\t}\n\t\tif (watch !== undefined && !isFunction(watch)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: watch } })\n\t\t}\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#create = options.create\n\t\tthis.#destroy = options.destroy\n\t\tthis.#validate = options.validate\n\t\tthis.#max = max ?? min\n\t\tthis.#capacity = capacity ?? 1\n\t\tthis.#min = min\n\t\tthis.#restarts = restarts\n\t\tthis.#watch = watch\n\t\tthis.#error = error\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\t/** Holds the typed synchronous lifecycle observation surface. */\n\tget emitter(): EmitterInterface<PoolEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Counts all owned records, including records validating, destroying, or retained after failed cleanup. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts available records with no live lease or pending handout. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts records with live leases, counting a shared record once rather than counting its leases. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Fills the warm floor and resets the strikes of a spent floor; without a floor, resolves immediately.\n\t *\n\t * @returns A promise that resolves when the floor owns `min` live records\n\t * @throws {@link PoolError} Thrown as a rejection with `code: 'create'` and the last cause\n\t * when the bound is spent, `code: 'cleanup'` when retained failed cleanup prevents filling,\n\t * or `code: 'destroyed'` when teardown begins.\n\t */\n\tstart(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (this.#min === undefined) return Promise.resolve()\n\t\tif (this.#starting !== undefined) return this.#starting.promise\n\t\tconst starting = Promise.withResolvers<void>()\n\t\tthis.#starting = starting\n\t\tthis.#started = true\n\t\tif (this.#spent()) this.#strikes = 0\n\t\tthis.#pump()\n\t\treturn starting.promise\n\t}\n\n\t/**\n\t * Queues the caller in FIFO order, shares an occupied record or validates an idle record, and\n\t * waits for a floor refill or creates on demand without a floor.\n\t *\n\t * @param signal - Optional native cancellation signal\n\t * @returns A promise for the unique resource lease\n\t * @throws {@link PoolError} Thrown when `signal` is present and is not a native `AbortSignal`,\n\t * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller\n\t * that handles failures with `.catch()` alone misses it.\n\t * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with\n\t * `code: 'destroyed'`; when the create hook fails or the floor is spent without an eligible record,\n\t * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or\n\t * a floor retains a record, owns `min` records, has nothing eligible, and has no refill or disposal\n\t * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.\n\t * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.\n\t */\n\tacquire(signal?: AbortSignal): Promise<PoolToken<T>> {\n\t\tif (signal !== undefined && !isPoolSignal(signal)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (signal !== undefined) {\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) return Promise.reject(state[1])\n\t\t}\n\n\t\tconst waiter = Promise.withResolvers<PoolToken<T>>()\n\t\tthis.#waiters.push(waiter)\n\t\tif (signal !== undefined) {\n\t\t\tconst listener = this.#createAbort(waiter, signal)\n\t\t\tAbortSignal.prototype.addEventListener.call(signal, 'abort', listener, { once: true })\n\t\t\tthis.#signals.set(waiter, { signal, listener })\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) this.#abort(waiter, state[1])\n\t\t}\n\t\tthis.#pump()\n\t\treturn waiter.promise\n\t}\n\n\t/**\n\t * Destroys the records that are idle at this call's synchronous snapshot and restores a started floor.\n\t *\n\t * @returns A promise that settles after every snapshot cleanup attempt\n\t * @throws {@link PoolError} Thrown when `destroy()` has already begun, with `code: 'destroyed'`.\n\t * @throws {@link PoolError} Thrown when a claimed record's destroy hook fails, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. Each arrives as a rejected\n\t * promise rather than a synchronous throw.\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tconst records = this.#available.splice(0)\n\t\tconst cleanups: Array<Promise<void>> = []\n\t\tfor (const record of records) {\n\t\t\tconst cleanup = this.#dispose(record)\n\t\t\tcleanups.push(cleanup)\n\t\t\tvoid cleanup.then(\n\t\t\t\t() => this.#pump(),\n\t\t\t\t() => this.#pump(),\n\t\t\t)\n\t\t}\n\t\treturn this.#settleClear(cleanups)\n\t}\n\n\t/**\n\t * Tears down the pool permanently and returns its stable completion barrier.\n\t *\n\t * @returns The exact promise shared by every destroy call\n\t * @throws {@link PoolError} Thrown when a destroy hook failure was retained or occurred during teardown, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. The barrier rejects; it\n\t * never throws synchronously, and a repeat call receives the same rejected promise.\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending.promise\n\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending\n\t\tthis.#starting?.reject(new PoolError({ code: 'destroyed' }))\n\t\tthis.#starting = undefined\n\t\tconst waiters = this.#waiters.splice(0)\n\t\tfor (const waiter of waiters) {\n\t\t\tthis.#detach(waiter)\n\t\t\twaiter.reject(new PoolError({ code: 'destroyed' }))\n\t\t}\n\t\tthis.#ready.clear()\n\t\tthis.#assigned.clear()\n\t\tthis.#available.splice(0)\n\t\tfor (const cleanup of this.#destroying.values()) this.#own(cleanup)\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (!this.#validating.has(record)) this.#own(this.#dispose(record))\n\t\t}\n\t\tthis.#finish()\n\t\treturn ending.promise\n\t}\n\n\t#createAbort(waiter: PromiseWithResolvers<PoolToken<T>>, signal: AbortSignal): () => void {\n\t\treturn (): void => {\n\t\t\tlet reason: unknown\n\t\t\ttry {\n\t\t\t\treason = this.#state(signal)[1]\n\t\t\t} catch (error: unknown) {\n\t\t\t\treason = error\n\t\t\t}\n\t\t\tthis.#abort(waiter, reason)\n\t\t}\n\t}\n\n\t#state(signal: AbortSignal): readonly [aborted: boolean, reason: unknown] {\n\t\tconst aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tconst reason = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason')?.get\n\t\tif (aborted === undefined || reason === undefined) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\ttry {\n\t\t\tconst stopped = Reflect.apply(aborted, signal, []) === true\n\t\t\treturn [stopped, stopped ? Reflect.apply(reason, signal, []) : undefined]\n\t\t} catch (error: unknown) {\n\t\t\tthrow new PoolError({ code: 'invalid', cause: error, context: { value: signal } })\n\t\t}\n\t}\n\n\t#token(record: object, value: T, lease: object): PoolToken<T> {\n\t\treturn {\n\t\t\tvalue,\n\t\t\trelease: this.#createRelease(record, lease),\n\t\t\tdestroy: this.#createDestroy(record, lease),\n\t\t}\n\t}\n\n\t#createRelease(record: object, lease: object): () => void {\n\t\treturn (): void => {\n\t\t\tif (this.#settled.has(lease)) return\n\t\t\tthis.#settled.add(lease)\n\t\t\tthis.#release(record, lease)\n\t\t}\n\t}\n\n\t#createDestroy(record: object, lease: object): () => Promise<void> {\n\t\treturn (): Promise<void> => {\n\t\t\tif (this.#settled.has(lease)) return Promise.resolve()\n\t\t\tthis.#settled.add(lease)\n\t\t\treturn (this.#destroying.get(record) ?? this.#lose(record)).catch((error: unknown) => {\n\t\t\t\tthrow new PoolError({ code: 'cleanup', cause: error })\n\t\t\t})\n\t\t}\n\t}\n\n\t#abort(waiter: PromiseWithResolvers<PoolToken<T>>, reason: unknown): void {\n\t\tconst index = this.#waiters.indexOf(waiter)\n\t\tif (index < 0) return\n\t\tthis.#waiters.splice(index, 1)\n\t\tthis.#detach(waiter)\n\t\tconst ready = this.#ready.get(waiter)\n\t\tthis.#ready.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (ready?.success === true) {\n\t\t\tthis.#recycle(ready.record)\n\t\t}\n\t\twaiter.reject(reason)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t}\n\n\t#detach(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst entry = this.#signals.get(waiter)\n\t\tif (entry === undefined) return\n\t\tAbortSignal.prototype.removeEventListener.call(entry.signal, 'abort', entry.listener)\n\t\tthis.#signals.delete(waiter)\n\t}\n\n\t#pump(): void {\n\t\tif (this.#ending !== undefined) return\n\t\tif (this.#pumping) {\n\t\t\tthis.#repump = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.#pumping = true\n\t\tdo {\n\t\t\tthis.#repump = false\n\t\t\tfor (const waiter of this.#waiters) {\n\t\t\t\tif (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue\n\t\t\t\tconst record = this.#select()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tconst index = this.#available.indexOf(record)\n\t\t\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\t\t\tif (this.#occupancy(record) === 0) this.#validating.add(record)\n\t\t\t\t\tthis.#startValidation(waiter, record)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (this.#min !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#resources.size >= this.#min &&\n\t\t\t\t\t\tthis.#survivors.size > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({\n\t\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\t\tcause: this.#survivors.values().next().value,\n\t\t\t\t\t\t\t\tcontext: { failures: [...this.#failures] },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#spent() &&\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#owed === 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({ code: 'create', cause: this.#cause }),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif (this.#max === undefined || this.#resources.size + this.#reservations.size < this.#max) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#reservations.add(waiter)\n\t\t\t\t\tthis.#startCreate(waiter)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t} while (this.#repump)\n\t\tthis.#pumping = false\n\t\tthis.#fill()\n\t}\n\n\t#occupancy(record: object): number {\n\t\tlet count = this.#leased.get(record)?.size ?? 0\n\t\tfor (const result of this.#ready.values()) {\n\t\t\tif (result.success && result.record === record) count += 1\n\t\t}\n\t\treturn count\n\t}\n\n\t#select(): object | undefined {\n\t\tlet selected: object | undefined\n\t\tlet least = this.#capacity\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tconst count = this.#occupancy(record)\n\t\t\tif (count === 0 && !this.#available.includes(record)) continue\n\t\t\tif (count < least) {\n\t\t\t\tselected = record\n\t\t\t\tleast = count\n\t\t\t}\n\t\t}\n\t\treturn this.#available[0] ?? selected\n\t}\n\n\t#spent(): boolean {\n\t\treturn this.#restarts !== undefined && this.#strikes > this.#restarts\n\t}\n\n\t#fill(): void {\n\t\tif (this.#ending !== undefined || !this.#started || this.#min === undefined) return\n\t\tif (this.#refilling) return\n\t\tconst live = this.#resources.size - this.#destroying.size - this.#survivors.size\n\t\tif (live >= this.#min) {\n\t\t\tthis.#starting?.resolve()\n\t\t\tthis.#starting = undefined\n\t\t}\n\t\tif (this.#resources.size < this.#min && (!this.#spent() || this.#owed > 0)) {\n\t\t\tif (this.#owed > 0) this.#owed -= 1\n\t\t\tthis.#refilling = true\n\t\t\tconst operation = Promise.resolve().then(() => this.#refill())\n\t\t\tthis.#operations.add(operation)\n\t\t\t// Refill never rejects: create failures are caught, and watch/emitter callbacks isolate errors.\n\t\t\tvoid operation.then(() => {\n\t\t\t\tthis.#refilling = false\n\t\t\t\tthis.#completeOperation(operation)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tif (this.#destroying.size > 0) return\n\t\tif (this.#spent() || this.#survivors.size > 0) {\n\t\t\tthis.#starting?.reject(\n\t\t\t\tthis.#spent()\n\t\t\t\t\t? new PoolError({ code: 'create', cause: this.#cause })\n\t\t\t\t\t: this.#cleanupError(this.#failures),\n\t\t\t)\n\t\t\tthis.#starting = undefined\n\t\t}\n\t}\n\n\tasync #refill(): Promise<void> {\n\t\tif (this.#ending !== undefined) return\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#addStrike(error)\n\t\t\treturn\n\t\t}\n\t\tconst record = this.#insert(value)\n\t\tthis.#recycle(record)\n\t}\n\n\t#insert(value: T): object {\n\t\tconst record = {}\n\t\tthis.#births.set(record, this.#epoch)\n\t\tthis.#resources.set(record, value)\n\t\tif (this.#watch !== undefined) {\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#watches.set(record, controller)\n\t\t\tconst watching = attempt(() => this.#watch?.(value, controller.signal))\n\t\t\tconst settled = watching.success\n\t\t\t\t? Promise.resolve(watching.value)\n\t\t\t\t: Promise.reject(watching.error)\n\t\t\tvoid settled.then(\n\t\t\t\t() => this.#own(this.#lose(record)),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (controller.signal.aborted) return\n\t\t\t\t\tthis.#own(this.#lose(record, error))\n\t\t\t\t\tattempt(() => this.#error?.(error, 'watch'))\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tthis.#emitter.emit('create')\n\t\treturn record\n\t}\n\n\tasync #lose(record: object, cause?: unknown): Promise<void> {\n\t\tif (\n\t\t\tthis.#ending !== undefined ||\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t)\n\t\t\treturn\n\t\tif (this.#leased.has(record) && this.#min !== undefined) this.#owing.add(record)\n\t\tthis.#strike(record, cause)\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#pump()\n\t\t\tthrow error\n\t\t}\n\t\tthis.#pump()\n\t}\n\n\t#strike(record: object, cause?: unknown): void {\n\t\tif (this.#min !== undefined && !this.#leased.has(record)) {\n\t\t\tthis.#addStrike(cause)\n\t\t}\n\t}\n\n\t#addStrike(cause: unknown): void {\n\t\tthis.#strikes += 1\n\t\tthis.#cause = cause\n\t\tthis.#epoch = {}\n\t}\n\n\t#startCreate(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst operation = Promise.resolve().then(() => this.#createResource(waiter))\n\t\tthis.#operations.add(operation)\n\t\tvoid operation.then(\n\t\t\t() => this.#completeOperation(operation),\n\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'create'),\n\t\t)\n\t}\n\n\t#startValidation(waiter: PromiseWithResolvers<PoolToken<T>>, record: object): void {\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tif (!this.#validating.has(record) || this.#validate === undefined) {\n\t\t\t\tthis.#validating.delete(record)\n\t\t\t\tthis.#prepare(waiter, record, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst operation = Promise.resolve().then(() => this.#validateResource(waiter, record, value))\n\t\t\tthis.#operations.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#completeOperation(operation),\n\t\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'invalid'),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.#validating.delete(record)\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#repump = true\n\t}\n\n\tasync #createResource(waiter: PromiseWithResolvers<PoolToken<T>>): Promise<void> {\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#reservations.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'create', cause: error }),\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t\treturn\n\t\t}\n\n\t\tthis.#reservations.delete(waiter)\n\t\tconst record = this.#insert(value)\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\tasync #validateResource(\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\trecord: object,\n\t\tvalue: T,\n\t): Promise<void> {\n\t\tlet valid = false\n\t\ttry {\n\t\t\tvalid = (await this.#validate?.(value)) === true\n\t\t} catch {}\n\t\tthis.#validating.delete(record)\n\t\tif (\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!valid) this.#strike(record)\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (valid) this.#recycle(record)\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#dispose(record)\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthis.#record(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (valid) {\n\t\t\tthis.#prepare(waiter, record, value)\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'cleanup', cause: error }),\n\t\t\t\t})\n\t\t\t\tthis.#commit()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#record(error)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#pump()\n\t}\n\n\t#prepare(waiter: PromiseWithResolvers<PoolToken<T>>, record: object, value: T): void {\n\t\tif (!this.#waiters.includes(waiter) || this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\t#commit(): void {\n\t\twhile (this.#ending === undefined) {\n\t\t\tconst waiter = this.#waiters[0]\n\t\t\tif (waiter === undefined) return\n\t\t\tconst result = this.#ready.get(waiter)\n\t\t\tif (result === undefined) return\n\t\t\tif (\n\t\t\t\tresult.success &&\n\t\t\t\t(!this.#resources.has(result.record) ||\n\t\t\t\t\tthis.#destroying.has(result.record) ||\n\t\t\t\t\tthis.#survivors.has(result.record))\n\t\t\t) {\n\t\t\t\tthis.#ready.delete(waiter)\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t\tthis.#repump = true\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#waiters.shift()\n\t\t\tthis.#repump = true\n\t\t\tthis.#ready.delete(waiter)\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#detach(waiter)\n\t\t\tif (!result.success) {\n\t\t\t\twaiter.reject(result.error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst leases = this.#leased.get(result.record) ?? new Set<object>()\n\t\t\tleases.add(waiter)\n\t\t\tthis.#leased.set(result.record, leases)\n\t\t\tif (this.#births.get(result.record) === this.#epoch) this.#strikes = 0\n\t\t\twaiter.resolve(result.token)\n\t\t\tthis.#emitter.emit('acquire')\n\t\t}\n\t}\n\n\t#completeOperation(operation: Promise<void>): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#failOperation(\n\t\toperation: Promise<void>,\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\terror: unknown,\n\t\tcode: PoolCode,\n\t): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#reservations.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (this.#waiters.includes(waiter)) {\n\t\t\tthis.#ready.set(waiter, { success: false, error: new PoolError({ code, cause: error }) })\n\t\t}\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#release(record: object, lease: object): void {\n\t\tconst leases = this.#leased.get(record)\n\t\tif (leases === undefined || !leases.delete(lease)) return\n\t\tif (leases.size === 0) this.#leased.delete(record)\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record))\n\t\t\treturn\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tthis.#occupancy(record) === 0 &&\n\t\t\t!this.#validating.has(record) &&\n\t\t\t!this.#available.includes(record)\n\t\t) {\n\t\t\tthis.#available.push(record)\n\t\t}\n\t\tthis.#pump()\n\t\tif (this.#available.includes(record)) this.#emitter.emit('release')\n\t}\n\n\t#dispose(record: object): Promise<void> {\n\t\tif (this.#survivors.has(record)) return Promise.resolve()\n\t\tconst existing = this.#destroying.get(record)\n\t\tif (existing !== undefined) return existing\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tconst cleanup = Promise.withResolvers<void>()\n\t\t\tthis.#destroying.set(record, cleanup.promise)\n\t\t\tconst index = this.#available.indexOf(record)\n\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\tthis.#validating.delete(record)\n\t\t\tthis.#leased.delete(record)\n\t\t\tthis.#watches.get(record)?.abort()\n\t\t\tthis.#watches.delete(record)\n\t\t\tif (this.#ending !== undefined) this.#own(cleanup.promise)\n\t\t\tvoid this.#clean(record, value, cleanup)\n\t\t\treturn cleanup.promise\n\t\t}\n\t\treturn Promise.resolve()\n\t}\n\n\tasync #clean(record: object, value: T, cleanup: PromiseWithResolvers<void>): Promise<void> {\n\t\tlet disposal: Promise<void>\n\t\ttry {\n\t\t\tdisposal = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tdisposal = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait disposal\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tif (failed && this.#min !== undefined) {\n\t\t\tthis.#survivors.set(record, failure)\n\t\t\tthis.#record(failure)\n\t\t} else {\n\t\t\tthis.#resources.delete(record)\n\t\t\tif (this.#owing.has(record)) this.#owed += 1\n\t\t}\n\t\tthis.#owing.delete(record)\n\t\tif (failed) cleanup.reject(failure)\n\t\telse cleanup.resolve()\n\t\t// Cleanup owners must bind outcomes before destroy observers can reenter.\n\t\tawait Promise.resolve()\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#destroying.delete(record)\n\t\tif (this.#min !== undefined) this.#pump()\n\t\tthis.#finish()\n\t}\n\n\tasync #settleClear(cleanups: ReadonlyArray<Promise<void>>): Promise<void> {\n\t\tconst settled = await Promise.allSettled(cleanups)\n\t\tconst failures: unknown[] = []\n\t\tfor (const result of settled) {\n\t\t\tif (\n\t\t\t\tresult.status === 'rejected' &&\n\t\t\t\t!failures.some((failure) => Object.is(failure, result.reason))\n\t\t\t) {\n\t\t\t\tfailures.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (failures.length > 0) throw this.#cleanupError(failures)\n\t}\n\n\t#own(cleanup: Promise<void>): void {\n\t\tif (this.#owned.has(cleanup)) return\n\t\tthis.#owned.add(cleanup)\n\t\tvoid cleanup.then(\n\t\t\t() => this.#completeCleanup(cleanup),\n\t\t\t(error: unknown) => this.#failCleanup(cleanup, error),\n\t\t)\n\t}\n\n\t#completeCleanup(cleanup: Promise<void>): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#finish()\n\t}\n\n\t#failCleanup(cleanup: Promise<void>, error: unknown): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#record(error)\n\t\tthis.#finish()\n\t}\n\n\t#record(error: unknown): void {\n\t\tif (!this.#failures.some((failure) => Object.is(failure, error))) this.#failures.push(error)\n\t}\n\n\t#cleanupError(failures: readonly unknown[]): PoolError {\n\t\treturn new PoolError({\n\t\t\tcode: 'cleanup',\n\t\t\t...(failures[0] === undefined ? {} : { cause: failures[0] }),\n\t\t\tcontext: { failures: [...failures] },\n\t\t})\n\t}\n\n\t#finish(): void {\n\t\tconst ending = this.#ending\n\t\tif (ending === undefined || this.#operations.size > 0 || this.#owned.size > 0) return\n\t\tlet claimed = false\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return\n\t\tthis.#emitter.destroy()\n\t\tif (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures))\n\t\telse ending.resolve()\n\t}\n}\n","import type { PoolInterface, PoolOptions } from './types.js'\nimport { Pool } from './Pool.js'\n\n/**\n * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded\n * capacity, exclusive leases by default, and FIFO settlement.\n *\n * @remarks\n * Concurrent create and validation hooks may overlap, while acquire promises settle in\n * request order. `clear` owns its idle snapshot; `destroy` returns one stable barrier and\n * waits for every in-flight create, validation, and destroy attempt before destroying the\n * emitter last.\n * Set `min` with its required `restarts` bound and call `start()` to warm resources and\n * refill losses independently of queued acquires. `watch` observes loss and its signal\n * aborts at disposal; a token can declare loss through `destroy()`.\n *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, capacity, optional bounded warm floor, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown with `code: 'invalid'` when capacity, restart bounds, or\n * the watch hook are invalid. Construction validates them synchronously, before the pool exists.\n *\n * @example Create a pool\n * ```ts\n * import { createPool } from '@orkestrel/pool'\n *\n * const pool = createPool<Connection>({\n * \tcreate: () => connect(),\n * \tdestroy: (connection) => connection.close(),\n * \tvalidate: (connection) => connection.alive,\n * \tmax: 8,\n * })\n *\n * const token = await pool.acquire()\n * try {\n * \tawait token.value.query('select 1')\n * } finally {\n * \ttoken.release()\n * }\n * ```\n */\nexport function createPool<T>(options: PoolOptions<T>): PoolInterface<T> {\n\treturn new Pool(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;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AAc,KAAK,SAAS,CAAC;OAC1E,OAAO,QAAQ;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC70BA,SAAgB,WAAc,SAA2C;CACxE,OAAO,IAAI,KAAK,OAAO;AACxB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\nimport {\n\tholds,\n\tINTRINSICS,\n\tisArray,\n\tisError,\n\tisFunction,\n\tisObject,\n\tisString,\n} from '@orkestrel/contract'\n\n/**\n * Represents a stable, machine-readable pool failure that retains the original thrown value as\n * its cause without unsafe coercion, alongside structured context.\n *\n * @example\n * ```ts\n * import { PoolError, isPoolError } from '@orkestrel/pool'\n *\n * try {\n * \tawait pool.acquire()\n * } catch (error: unknown) {\n * \tif (isPoolError(error)) console.error(error.code, error.cause)\n * }\n * ```\n */\nexport class PoolError extends Error {\n\t/** Holds the stable machine-readable failure category. */\n\treadonly code\n\t/** Holds optional structured input or aggregate destroy-hook failure details. */\n\treadonly context\n\n\t/**\n\t * Creates a pool failure without coercing a hostile thrown value.\n\t *\n\t * @param options - Stable code plus optional cause and structured context\n\t */\n\tconstructor(options: PoolErrorOptions) {\n\t\tconst destroyed = options.code === 'destroyed' ? 'pool is destroyed' : 'pool input is invalid'\n\t\tconst created = options.code === 'create' ? 'pool create failed' : destroyed\n\t\tconst reason = options.code === 'cleanup' ? 'pool cleanup failed' : created\n\t\tconst message =\n\t\t\tisError(options.cause) && isString(options.cause.message) && options.cause.message.length > 0\n\t\t\t\t? `${reason}: ${options.cause.message}`\n\t\t\t\t: reason\n\t\tsuper(message, options.cause === undefined ? undefined : { cause: options.cause })\n\t\tINTRINSICS.define(this, Symbol.for('@orkestrel/pool.PoolError'), { value: this })\n\t\tthis.name = 'PoolError'\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Tests whether an unknown value is a branded {@link PoolError} with declared code and context.\n *\n * @remarks\n * Accepts subclasses and errors from another installed copy without reading `name`. Refuses\n * transparent proxies, unbranded look-alikes, and plain branded objects.\n *\n * @param value - The unknown boundary value\n * @returns True if the value is a real `PoolError` instance; false otherwise\n *\n * @example\n * ```ts\n * isPoolError(new PoolError({ code: 'destroyed' })) // true\n * isPoolError(new Error('other')) // false\n * ```\n */\nexport function isPoolError(value: unknown): value is PoolError {\n\tif (!isObject(value)) return false\n\treturn holds(() => {\n\t\tif (!(value instanceof INTRINSICS.error)) return false\n\t\tif (INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false\n\t\tconst brand = INTRINSICS.describe(value, Symbol.for('@orkestrel/pool.PoolError'))\n\t\tif (brand?.value !== value) return false\n\t\tconst code: unknown = INTRINSICS.reflect.read(value, 'code')\n\t\tif (code !== 'invalid' && code !== 'destroyed' && code !== 'create' && code !== 'cleanup')\n\t\t\treturn false\n\t\tconst context: unknown = INTRINSICS.reflect.read(value, 'context')\n\t\tif (context === undefined) return true\n\t\tif (!isObject(context) && !isFunction(context)) return false\n\t\tconst failures: unknown = INTRINSICS.reflect.read(context, 'failures')\n\t\treturn failures === undefined || isArray(failures)\n\t})\n}\n","import { holds, isFunction, isNumber } from '@orkestrel/contract'\n\n/**\n * Tests whether a value is a positive safe integer for a pool record or lease limit.\n *\n * @param value - The unknown record or lease limit candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolLimit(8) // true\n * isPoolLimit(Infinity) // false\n * ```\n */\nexport function isPoolLimit(value: unknown): value is number {\n\treturn isNumber(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`\n * for hostile proxies.\n *\n * @param value - The unknown signal candidate\n * @returns True if the value is a native `AbortSignal`; false otherwise\n *\n * @example\n * ```ts\n * isPoolSignal(new AbortController().signal) // true\n * isPoolSignal({ aborted: false }) // false\n * ```\n */\nexport function isPoolSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (!isFunction(getter)) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n","import type { EmitterErrorHandler, EmitterInterface } from '@orkestrel/emitter'\nimport type { Result } from '@orkestrel/contract'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { attempt, isFunction, isNumber } from '@orkestrel/contract'\nimport { PoolError } from './errors.js'\nimport { isPoolLimit, isPoolSignal } from './validators.js'\n\n/**\n * Represents a resource pool with optional bounded capacity and a warm floor, whose opaque\n * ownership records preserve FIFO settlement, cancellation, exact lease release, and\n * deterministic teardown under concurrent hooks.\n *\n * @typeParam T - The pooled resource value\n *\n * @example\n * ```ts\n * import { Pool } from '@orkestrel/pool'\n *\n * const pool = new Pool({ create: () => new Uint8Array(64), max: 2 })\n * const token = await pool.acquire()\n * try {\n * \tconsume(token.value)\n * } finally {\n * \ttoken.release()\n * }\n * await pool.destroy()\n * ```\n */\nexport class Pool<T> implements PoolInterface<T> {\n\treadonly #create: () => Promise<T> | T\n\treadonly #destroy: ((value: T) => Promise<void> | void) | undefined\n\treadonly #validate: ((value: T) => Promise<boolean> | boolean) | undefined\n\treadonly #max: number | undefined\n\treadonly #capacity: number\n\treadonly #min: number | undefined\n\treadonly #restarts: number | undefined\n\treadonly #watch: PoolOptions<T>['watch']\n\treadonly #error: EmitterErrorHandler | undefined\n\treadonly #watches = new Map<object, AbortController>()\n\treadonly #births = new WeakMap<object, object>()\n\treadonly #settled = new WeakSet<object>()\n\treadonly #survivors = new Map<object, unknown>()\n\treadonly #owing = new Set<object>()\n\treadonly #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new Map<object, Set<object>>()\n\treadonly #destroying = new Map<object, Promise<void>>()\n\treadonly #waiters: Array<PromiseWithResolvers<PoolToken<T>>> = []\n\treadonly #assigned = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #reservations = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #signals = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t{ readonly signal: AbortSignal; readonly listener: () => void }\n\t>()\n\treadonly #ready = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t| { readonly success: true; readonly record: object; readonly token: PoolToken<T> }\n\t\t| { readonly success: false; readonly error: unknown }\n\t>()\n\treadonly #operations = new Set<Promise<void>>()\n\treadonly #owned = new Set<Promise<void>>()\n\treadonly #failures: unknown[] = []\n\t#ending: PromiseWithResolvers<void> | undefined\n\t#pumping = false\n\t#repump = false\n\t#started = false\n\t#starting: PromiseWithResolvers<void> | undefined\n\t#refilling = false\n\t#strikes = 0\n\t#epoch = {}\n\t#owed = 0\n\t#cause: unknown\n\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor\n\t * @throws {@link PoolError} Thrown with `code: 'invalid'` when `capacity`, `min`, or `max` is not a positive\n\t * safe integer, explicit `min` and `max` differ, `restarts` is absent with `min`, present without\n\t * `min`, or not a non-negative safe integer, or `watch` is not callable.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tconst capacity = options.capacity\n\t\tconst min = options.min\n\t\tconst restarts = options.restarts\n\t\tconst watch = options.watch\n\t\tif (max !== undefined && !isPoolLimit(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\n\t\t}\n\t\tif (capacity !== undefined && !isPoolLimit(capacity)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: capacity } })\n\t\t}\n\t\tif (min !== undefined && (!isPoolLimit(min) || (max !== undefined && min !== max))) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: min } })\n\t\t}\n\t\tif (\n\t\t\t(min !== undefined && restarts === undefined) ||\n\t\t\t(restarts !== undefined &&\n\t\t\t\t(min === undefined ||\n\t\t\t\t\t!isNumber(restarts) ||\n\t\t\t\t\t!Number.isSafeInteger(restarts) ||\n\t\t\t\t\trestarts < 0))\n\t\t) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: restarts } })\n\t\t}\n\t\tif (watch !== undefined && !isFunction(watch)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: watch } })\n\t\t}\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#create = options.create\n\t\tthis.#destroy = options.destroy\n\t\tthis.#validate = options.validate\n\t\tthis.#max = max ?? min\n\t\tthis.#capacity = capacity ?? 1\n\t\tthis.#min = min\n\t\tthis.#restarts = restarts\n\t\tthis.#watch = watch\n\t\tthis.#error = error\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\t/** Holds the typed synchronous lifecycle observation surface. */\n\tget emitter(): EmitterInterface<PoolEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Counts all owned records, including records validating, destroying, or retained after failed cleanup. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts available records with no live lease or pending handout. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts records with live leases, counting a shared record once rather than counting its leases. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Fills the warm floor and resets the strikes of a spent floor; without a floor, resolves immediately.\n\t *\n\t * @returns A promise that resolves when the floor owns `min` live records\n\t * @throws {@link PoolError} Thrown as a rejection with `code: 'create'` and the last cause\n\t * when the bound is spent, `code: 'cleanup'` when retained failed cleanup prevents filling,\n\t * or `code: 'destroyed'` when teardown begins.\n\t */\n\tstart(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (this.#min === undefined) return Promise.resolve()\n\t\tif (this.#starting !== undefined) return this.#starting.promise\n\t\tconst starting = Promise.withResolvers<void>()\n\t\tthis.#starting = starting\n\t\tthis.#started = true\n\t\tif (this.#spent()) this.#strikes = 0\n\t\tthis.#pump()\n\t\treturn starting.promise\n\t}\n\n\t/**\n\t * Queues the caller in FIFO order, shares an occupied record or validates an idle record, and\n\t * waits for a floor refill or creates on demand without a floor.\n\t *\n\t * @param signal - Optional native cancellation signal\n\t * @returns A promise for the unique resource lease\n\t * @throws {@link PoolError} Thrown when `signal` is present and is not a native `AbortSignal`,\n\t * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller\n\t * that handles failures with `.catch()` alone misses it.\n\t * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with\n\t * `code: 'destroyed'`; when the create hook fails or the floor is spent without an eligible record,\n\t * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or\n\t * a floor retains a record, owns `min` records, has nothing eligible, and has no refill or disposal\n\t * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.\n\t * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.\n\t */\n\tacquire(signal?: AbortSignal): Promise<PoolToken<T>> {\n\t\tif (signal !== undefined && !isPoolSignal(signal)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (signal !== undefined) {\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) return Promise.reject(state[1])\n\t\t}\n\n\t\tconst waiter = Promise.withResolvers<PoolToken<T>>()\n\t\tthis.#waiters.push(waiter)\n\t\tif (signal !== undefined) {\n\t\t\tconst listener = this.#createAbort(waiter, signal)\n\t\t\tAbortSignal.prototype.addEventListener.call(signal, 'abort', listener, { once: true })\n\t\t\tthis.#signals.set(waiter, { signal, listener })\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) this.#abort(waiter, state[1])\n\t\t}\n\t\tthis.#pump()\n\t\treturn waiter.promise\n\t}\n\n\t/**\n\t * Destroys the records that are idle at this call's synchronous snapshot and restores a started floor.\n\t *\n\t * @returns A promise that settles after every snapshot cleanup attempt\n\t * @throws {@link PoolError} Thrown when `destroy()` has already begun, with `code: 'destroyed'`.\n\t * @throws {@link PoolError} Thrown when a claimed record's destroy hook fails, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. Each arrives as a rejected\n\t * promise rather than a synchronous throw.\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tconst records = this.#available.splice(0)\n\t\tconst cleanups: Array<Promise<void>> = []\n\t\tfor (const record of records) {\n\t\t\tconst cleanup = this.#dispose(record)\n\t\t\tcleanups.push(cleanup)\n\t\t\tvoid cleanup.then(\n\t\t\t\t() => this.#pump(),\n\t\t\t\t() => this.#pump(),\n\t\t\t)\n\t\t}\n\t\treturn this.#settleClear(cleanups)\n\t}\n\n\t/**\n\t * Tears down the pool permanently and returns its stable completion barrier.\n\t *\n\t * @returns The exact promise shared by every destroy call\n\t * @throws {@link PoolError} Thrown when a destroy hook failure was retained or occurred during teardown, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. The barrier rejects; it\n\t * never throws synchronously, and a repeat call receives the same rejected promise.\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending.promise\n\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending\n\t\tthis.#starting?.reject(new PoolError({ code: 'destroyed' }))\n\t\tthis.#starting = undefined\n\t\tconst waiters = this.#waiters.splice(0)\n\t\tfor (const waiter of waiters) {\n\t\t\tthis.#detach(waiter)\n\t\t\twaiter.reject(new PoolError({ code: 'destroyed' }))\n\t\t}\n\t\tthis.#ready.clear()\n\t\tthis.#assigned.clear()\n\t\tthis.#available.splice(0)\n\t\tfor (const cleanup of this.#destroying.values()) this.#own(cleanup)\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (!this.#validating.has(record)) this.#own(this.#dispose(record))\n\t\t}\n\t\tthis.#finish()\n\t\treturn ending.promise\n\t}\n\n\t#createAbort(waiter: PromiseWithResolvers<PoolToken<T>>, signal: AbortSignal): () => void {\n\t\treturn (): void => {\n\t\t\tconst state = attempt(() => this.#state(signal))\n\t\t\tthis.#abort(waiter, state.success ? state.value[1] : state.error)\n\t\t}\n\t}\n\n\t#state(signal: AbortSignal): readonly [aborted: boolean, reason: unknown] {\n\t\tconst aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tconst reason = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason')?.get\n\t\tif (aborted === undefined || reason === undefined) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\ttry {\n\t\t\tconst stopped = Reflect.apply(aborted, signal, []) === true\n\t\t\treturn [stopped, stopped ? Reflect.apply(reason, signal, []) : undefined]\n\t\t} catch (error: unknown) {\n\t\t\tthrow new PoolError({ code: 'invalid', cause: error, context: { value: signal } })\n\t\t}\n\t}\n\n\t#token(record: object, value: T, lease: object): PoolToken<T> {\n\t\treturn {\n\t\t\tvalue,\n\t\t\trelease: this.#createRelease(record, lease),\n\t\t\tdestroy: this.#createDestroy(record, lease),\n\t\t}\n\t}\n\n\t#createRelease(record: object, lease: object): () => void {\n\t\treturn (): void => {\n\t\t\tif (this.#settled.has(lease)) return\n\t\t\tthis.#settled.add(lease)\n\t\t\tthis.#release(record, lease)\n\t\t}\n\t}\n\n\t#createDestroy(record: object, lease: object): () => Promise<void> {\n\t\treturn (): Promise<void> => {\n\t\t\tif (this.#settled.has(lease)) return Promise.resolve()\n\t\t\tthis.#settled.add(lease)\n\t\t\treturn (this.#destroying.get(record) ?? this.#lose(record)).catch((error: unknown) => {\n\t\t\t\tthrow new PoolError({ code: 'cleanup', cause: error })\n\t\t\t})\n\t\t}\n\t}\n\n\t#abort(waiter: PromiseWithResolvers<PoolToken<T>>, reason: unknown): void {\n\t\tconst index = this.#waiters.indexOf(waiter)\n\t\tif (index < 0) return\n\t\tthis.#waiters.splice(index, 1)\n\t\tthis.#detach(waiter)\n\t\tconst ready = this.#ready.get(waiter)\n\t\tthis.#ready.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (ready?.success === true) {\n\t\t\tthis.#recycle(ready.record)\n\t\t}\n\t\twaiter.reject(reason)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t}\n\n\t#detach(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst entry = this.#signals.get(waiter)\n\t\tif (entry === undefined) return\n\t\tAbortSignal.prototype.removeEventListener.call(entry.signal, 'abort', entry.listener)\n\t\tthis.#signals.delete(waiter)\n\t}\n\n\t#pump(): void {\n\t\tif (this.#ending !== undefined) return\n\t\tif (this.#pumping) {\n\t\t\tthis.#repump = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.#pumping = true\n\t\tdo {\n\t\t\tthis.#repump = false\n\t\t\tfor (const waiter of this.#waiters) {\n\t\t\t\tif (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue\n\t\t\t\tconst record = this.#select()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tconst index = this.#available.indexOf(record)\n\t\t\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\t\t\tif (this.#occupancy(record) === 0) this.#validating.add(record)\n\t\t\t\t\tthis.#startValidation(waiter, record)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (this.#min !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#resources.size >= this.#min &&\n\t\t\t\t\t\tthis.#survivors.size > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({\n\t\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\t\tcause: this.#survivors.values().next().value,\n\t\t\t\t\t\t\t\tcontext: { failures: [...this.#failures] },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#spent() &&\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#owed === 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({ code: 'create', cause: this.#cause }),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif (this.#max === undefined || this.#resources.size + this.#reservations.size < this.#max) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#reservations.add(waiter)\n\t\t\t\t\tthis.#startCreate(waiter)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t} while (this.#repump)\n\t\tthis.#pumping = false\n\t\tthis.#fill()\n\t}\n\n\t#occupancy(record: object): number {\n\t\tconst leased = this.#leased.get(record)?.size ?? 0\n\t\treturn this.#ready.values().reduce((count, result) => {\n\t\t\treturn count + (result.success && result.record === record ? 1 : 0)\n\t\t}, leased)\n\t}\n\n\t#select(): object | undefined {\n\t\tconst selected = this.#resources.keys().reduce<{\n\t\t\treadonly record?: object\n\t\t\treadonly count: number\n\t\t}>(\n\t\t\t(candidate, record) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\t\tthis.#survivors.has(record)\n\t\t\t\t)\n\t\t\t\t\treturn candidate\n\t\t\t\tconst count = this.#occupancy(record)\n\t\t\t\tif (count === 0 && !this.#available.includes(record)) return candidate\n\t\t\t\treturn count < candidate.count ? { record, count } : candidate\n\t\t\t},\n\t\t\t{ count: this.#capacity },\n\t\t)\n\t\treturn this.#available[0] ?? selected.record\n\t}\n\n\t#spent(): boolean {\n\t\treturn this.#restarts !== undefined && this.#strikes > this.#restarts\n\t}\n\n\t#fill(): void {\n\t\tif (this.#ending !== undefined || !this.#started || this.#min === undefined) return\n\t\tif (this.#refilling) return\n\t\tconst live = this.#resources.size - this.#destroying.size - this.#survivors.size\n\t\tif (live >= this.#min) {\n\t\t\tthis.#starting?.resolve()\n\t\t\tthis.#starting = undefined\n\t\t}\n\t\tif (this.#resources.size < this.#min && (!this.#spent() || this.#owed > 0)) {\n\t\t\tif (this.#owed > 0) this.#owed -= 1\n\t\t\tthis.#refilling = true\n\t\t\tconst operation = Promise.resolve().then(() => this.#refill())\n\t\t\tthis.#operations.add(operation)\n\t\t\t// Refill never rejects: create failures are caught, and watch/emitter callbacks isolate errors.\n\t\t\tvoid operation.then(() => {\n\t\t\t\tthis.#refilling = false\n\t\t\t\tthis.#completeOperation(operation)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tif (this.#destroying.size > 0) return\n\t\tif (this.#spent() || this.#survivors.size > 0) {\n\t\t\tthis.#starting?.reject(\n\t\t\t\tthis.#spent()\n\t\t\t\t\t? new PoolError({ code: 'create', cause: this.#cause })\n\t\t\t\t\t: this.#cleanupError(this.#failures),\n\t\t\t)\n\t\t\tthis.#starting = undefined\n\t\t}\n\t}\n\n\tasync #refill(): Promise<void> {\n\t\tif (this.#ending !== undefined) return\n\t\tconst creation = await this.#produce()\n\t\tif (!creation.success) {\n\t\t\tthis.#addStrike(creation.error)\n\t\t\treturn\n\t\t}\n\t\tconst record = this.#insert(creation.value)\n\t\tthis.#recycle(record)\n\t}\n\n\tasync #produce(): Promise<Result<T>> {\n\t\ttry {\n\t\t\treturn { success: true, value: await this.#create() }\n\t\t} catch (error: unknown) {\n\t\t\treturn { success: false, error }\n\t\t}\n\t}\n\n\t#insert(value: T): object {\n\t\tconst record = {}\n\t\tthis.#births.set(record, this.#epoch)\n\t\tthis.#resources.set(record, value)\n\t\tif (this.#watch !== undefined) {\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#watches.set(record, controller)\n\t\t\tconst watching = attempt(() => this.#watch?.(value, controller.signal))\n\t\t\tconst settled = watching.success\n\t\t\t\t? Promise.resolve(watching.value)\n\t\t\t\t: Promise.reject(watching.error)\n\t\t\tvoid settled.then(\n\t\t\t\t() => this.#own(this.#lose(record)),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (controller.signal.aborted) return\n\t\t\t\t\tthis.#own(this.#lose(record, error))\n\t\t\t\t\tattempt(() => this.#error?.(error, 'watch'))\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tthis.#emitter.emit('create')\n\t\treturn record\n\t}\n\n\tasync #lose(record: object, cause?: unknown): Promise<void> {\n\t\tif (\n\t\t\tthis.#ending !== undefined ||\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t)\n\t\t\treturn\n\t\tif (this.#leased.has(record) && this.#min !== undefined) this.#owing.add(record)\n\t\tthis.#strike(record, cause)\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#pump()\n\t\t\tthrow error\n\t\t}\n\t\tthis.#pump()\n\t}\n\n\t#strike(record: object, cause?: unknown): void {\n\t\tif (this.#min !== undefined && !this.#leased.has(record)) {\n\t\t\tthis.#addStrike(cause)\n\t\t}\n\t}\n\n\t#addStrike(cause: unknown): void {\n\t\tthis.#strikes += 1\n\t\tthis.#cause = cause\n\t\tthis.#epoch = {}\n\t}\n\n\t#startCreate(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst operation = Promise.resolve().then(() => this.#createResource(waiter))\n\t\tthis.#operations.add(operation)\n\t\tvoid operation.then(\n\t\t\t() => this.#completeOperation(operation),\n\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'create'),\n\t\t)\n\t}\n\n\t#startValidation(waiter: PromiseWithResolvers<PoolToken<T>>, record: object): void {\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tif (!this.#validating.has(record) || this.#validate === undefined) {\n\t\t\t\tthis.#validating.delete(record)\n\t\t\t\tthis.#prepare(waiter, record, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst operation = Promise.resolve().then(() => this.#validateResource(waiter, record, value))\n\t\t\tthis.#operations.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#completeOperation(operation),\n\t\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'invalid'),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.#validating.delete(record)\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#repump = true\n\t}\n\n\tasync #createResource(waiter: PromiseWithResolvers<PoolToken<T>>): Promise<void> {\n\t\tconst creation = await this.#produce()\n\t\tif (!creation.success) {\n\t\t\tthis.#reservations.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'create', cause: creation.error }),\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t\treturn\n\t\t}\n\n\t\tconst value = creation.value\n\t\tthis.#reservations.delete(waiter)\n\t\tconst record = this.#insert(value)\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\tasync #validateResource(\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\trecord: object,\n\t\tvalue: T,\n\t): Promise<void> {\n\t\tconst valid = await this.#check(value)\n\t\tthis.#validating.delete(record)\n\t\tif (\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!valid) this.#strike(record)\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (valid) this.#recycle(record)\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#dispose(record)\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthis.#record(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (valid) {\n\t\t\tthis.#prepare(waiter, record, value)\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'cleanup', cause: error }),\n\t\t\t\t})\n\t\t\t\tthis.#commit()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#record(error)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#pump()\n\t}\n\n\tasync #check(value: T): Promise<boolean> {\n\t\ttry {\n\t\t\treturn (await this.#validate?.(value)) === true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\n\t#prepare(waiter: PromiseWithResolvers<PoolToken<T>>, record: object, value: T): void {\n\t\tif (!this.#waiters.includes(waiter) || this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\t#commit(): void {\n\t\twhile (this.#ending === undefined) {\n\t\t\tconst waiter = this.#waiters[0]\n\t\t\tif (waiter === undefined) return\n\t\t\tconst result = this.#ready.get(waiter)\n\t\t\tif (result === undefined) return\n\t\t\tif (\n\t\t\t\tresult.success &&\n\t\t\t\t(!this.#resources.has(result.record) ||\n\t\t\t\t\tthis.#destroying.has(result.record) ||\n\t\t\t\t\tthis.#survivors.has(result.record))\n\t\t\t) {\n\t\t\t\tthis.#ready.delete(waiter)\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t\tthis.#repump = true\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#waiters.shift()\n\t\t\tthis.#repump = true\n\t\t\tthis.#ready.delete(waiter)\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#detach(waiter)\n\t\t\tif (!result.success) {\n\t\t\t\twaiter.reject(result.error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst leases = this.#leased.get(result.record) ?? new Set<object>()\n\t\t\tleases.add(waiter)\n\t\t\tthis.#leased.set(result.record, leases)\n\t\t\tif (this.#births.get(result.record) === this.#epoch) this.#strikes = 0\n\t\t\twaiter.resolve(result.token)\n\t\t\tthis.#emitter.emit('acquire')\n\t\t}\n\t}\n\n\t#completeOperation(operation: Promise<void>): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#failOperation(\n\t\toperation: Promise<void>,\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\terror: unknown,\n\t\tcode: PoolCode,\n\t): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#reservations.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (this.#waiters.includes(waiter)) {\n\t\t\tthis.#ready.set(waiter, { success: false, error: new PoolError({ code, cause: error }) })\n\t\t}\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#release(record: object, lease: object): void {\n\t\tconst leases = this.#leased.get(record)\n\t\tif (leases === undefined || !leases.delete(lease)) return\n\t\tif (leases.size === 0) this.#leased.delete(record)\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record))\n\t\t\treturn\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tthis.#occupancy(record) === 0 &&\n\t\t\t!this.#validating.has(record) &&\n\t\t\t!this.#available.includes(record)\n\t\t) {\n\t\t\tthis.#available.push(record)\n\t\t}\n\t\tthis.#pump()\n\t\tif (this.#available.includes(record)) this.#emitter.emit('release')\n\t}\n\n\t#dispose(record: object): Promise<void> {\n\t\tif (this.#survivors.has(record)) return Promise.resolve()\n\t\tconst existing = this.#destroying.get(record)\n\t\tif (existing !== undefined) return existing\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tconst cleanup = Promise.withResolvers<void>()\n\t\t\tthis.#destroying.set(record, cleanup.promise)\n\t\t\tconst index = this.#available.indexOf(record)\n\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\tthis.#validating.delete(record)\n\t\t\tthis.#leased.delete(record)\n\t\t\tthis.#watches.get(record)?.abort()\n\t\t\tthis.#watches.delete(record)\n\t\t\tif (this.#ending !== undefined) this.#own(cleanup.promise)\n\t\t\tvoid this.#clean(record, value, cleanup)\n\t\t\treturn cleanup.promise\n\t\t}\n\t\treturn Promise.resolve()\n\t}\n\n\tasync #clean(record: object, value: T, cleanup: PromiseWithResolvers<void>): Promise<void> {\n\t\tconst disposal = await this.#disposeValue(value)\n\t\tif (!disposal.success && this.#min !== undefined) {\n\t\t\tthis.#survivors.set(record, disposal.error)\n\t\t\tthis.#record(disposal.error)\n\t\t} else {\n\t\t\tthis.#resources.delete(record)\n\t\t\tif (this.#owing.has(record)) this.#owed += 1\n\t\t}\n\t\tthis.#owing.delete(record)\n\t\tif (!disposal.success) cleanup.reject(disposal.error)\n\t\telse cleanup.resolve()\n\t\t// Cleanup owners must bind outcomes before destroy observers can reenter.\n\t\tawait Promise.resolve()\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#destroying.delete(record)\n\t\tif (this.#min !== undefined) this.#pump()\n\t\tthis.#finish()\n\t}\n\n\tasync #disposeValue(value: T): Promise<Result<void>> {\n\t\tconst disposal = attempt(() => Promise.resolve(this.#destroy?.(value)))\n\t\ttry {\n\t\t\tawait (disposal.success ? disposal.value : Promise.reject(disposal.error))\n\t\t\treturn { success: true, value: undefined }\n\t\t} catch (error: unknown) {\n\t\t\treturn { success: false, error }\n\t\t}\n\t}\n\n\tasync #settleClear(cleanups: ReadonlyArray<Promise<void>>): Promise<void> {\n\t\tconst settled = await Promise.allSettled(cleanups)\n\t\tconst failures: unknown[] = []\n\t\tfor (const result of settled) {\n\t\t\tif (\n\t\t\t\tresult.status === 'rejected' &&\n\t\t\t\t!failures.some((failure) => Object.is(failure, result.reason))\n\t\t\t) {\n\t\t\t\tfailures.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (failures.length > 0) throw this.#cleanupError(failures)\n\t}\n\n\t#own(cleanup: Promise<void>): void {\n\t\tif (this.#owned.has(cleanup)) return\n\t\tthis.#owned.add(cleanup)\n\t\tvoid cleanup.then(\n\t\t\t() => this.#completeCleanup(cleanup),\n\t\t\t(error: unknown) => this.#failCleanup(cleanup, error),\n\t\t)\n\t}\n\n\t#completeCleanup(cleanup: Promise<void>): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#finish()\n\t}\n\n\t#failCleanup(cleanup: Promise<void>, error: unknown): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#record(error)\n\t\tthis.#finish()\n\t}\n\n\t#record(error: unknown): void {\n\t\tif (!this.#failures.some((failure) => Object.is(failure, error))) this.#failures.push(error)\n\t}\n\n\t#cleanupError(failures: readonly unknown[]): PoolError {\n\t\treturn new PoolError({\n\t\t\tcode: 'cleanup',\n\t\t\t...(failures[0] === undefined ? {} : { cause: failures[0] }),\n\t\t\tcontext: { failures: [...failures] },\n\t\t})\n\t}\n\n\t#finish(): void {\n\t\tconst ending = this.#ending\n\t\tif (ending === undefined || this.#operations.size > 0 || this.#owned.size > 0) return\n\t\tconst claimed = this.#resources.keys().reduce((previous, record) => {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\treturn previous\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn true\n\t\t}, false)\n\t\tif (claimed || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return\n\t\tthis.#emitter.destroy()\n\t\tif (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures))\n\t\telse ending.resolve()\n\t}\n}\n","import type { PoolInterface, PoolOptions } from './types.js'\nimport { Pool } from './Pool.js'\n\n/**\n * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded\n * capacity, exclusive leases by default, and FIFO settlement.\n *\n * @remarks\n * Concurrent create and validation hooks may overlap, while acquire promises settle in\n * request order. `clear` owns its idle snapshot; `destroy` returns one stable barrier and\n * waits for every in-flight create, validation, and destroy attempt before destroying the\n * emitter last.\n * Set `min` with its required `restarts` bound and call `start()` to warm resources and\n * refill losses independently of queued acquires. `watch` observes loss and its signal\n * aborts at disposal; a token can declare loss through `destroy()`.\n *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, capacity, optional bounded warm floor, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown with `code: 'invalid'` when capacity, restart bounds, or\n * the watch hook are invalid. Construction validates them synchronously, before the pool exists.\n *\n * @example Create a pool\n * ```ts\n * import { createPool } from '@orkestrel/pool'\n *\n * const pool = createPool<Connection>({\n * \tcreate: () => connect(),\n * \tdestroy: (connection) => connection.close(),\n * \tvalidate: (connection) => connection.alive,\n * \tmax: 8,\n * })\n *\n * const token = await pool.acquire()\n * try {\n * \tawait token.value.query('select 1')\n * } finally {\n * \ttoken.release()\n * }\n * ```\n */\nexport function createPool<T>(options: PoolOptions<T>): PoolInterface<T> {\n\treturn new Pool(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0BA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;;;;;CAOA,YAAY,SAA2B;EACtC,MAAM,YAAY,QAAQ,SAAS,cAAc,sBAAsB;EACvE,MAAM,UAAU,QAAQ,SAAS,WAAW,uBAAuB;EACnE,MAAM,SAAS,QAAQ,SAAS,YAAY,wBAAwB;EACpE,MAAM,UACL,QAAQ,QAAQ,KAAK,KAAK,SAAS,QAAQ,MAAM,OAAO,KAAK,QAAQ,MAAM,QAAQ,SAAS,IACzF,GAAG,OAAO,IAAI,QAAQ,MAAM,YAC5B;EACJ,MAAM,SAAS,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EACjF,WAAW,OAAO,MAAM,OAAO,IAAI,2BAA2B,GAAG,EAAE,OAAO,KAAK,C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,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,SAAS,GAAG;GAC1D,SAAS,EAAE,UAAU,CAAC,GAAG,QAAQ,EAAE;EACpC,CAAC;CACF;CAEA,UAAgB;EACf,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,KAAA,KAAa,KAAK,YAAY,OAAO,KAAK,KAAK,OAAO,OAAO,GAAG;EAW/E,IAVgB,KAAK,WAAW,KAAK,CAAC,CAAC,QAAQ,UAAU,WAAW;GACnE,IACC,KAAK,YAAY,IAAI,MAAM,KAC3B,KAAK,YAAY,IAAI,MAAM,KAC3B,KAAK,WAAW,IAAI,MAAM,GAE1B,OAAO;GACR,KAAK,KAAK,KAAK,SAAS,MAAM,CAAC;GAC/B,OAAO;EACR,GAAG,KACC,KAAW,KAAK,WAAW,OAAO,KAAK,WAAW,QAAQ,KAAK,YAAY,OAAO,GAAG;EACzF,KAAK,SAAS,QAAQ;EACtB,IAAI,KAAK,UAAU,SAAS,GAAG,OAAO,OAAO,KAAK,cAAc,KAAK,SAAS,CAAC;OAC1E,OAAO,QAAQ;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC/0BA,SAAgB,WAAc,SAA2C;CACxE,OAAO,IAAI,KAAK,OAAO;AACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orkestrel/pool",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "A typed resource pool with optional bounded capacity, a warm floor, bounded loss recovery, FIFO abort-cancellable waiting, validated idle reuse, and an observable lifecycle. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"connection-pool",
|
|
@@ -64,26 +64,26 @@
|
|
|
64
64
|
"prepublishOnly": "npm run format:check && npm run lint:check && npm run check && npm run build && npm test && npm run test:distribution -- --mode release",
|
|
65
65
|
"test:distribution": "vitest run --config vite.config.ts --no-cache --reporter=dot --project distribution",
|
|
66
66
|
"test:probe": "vitest run --config vite.config.ts --no-cache --reporter=verbose --project probe",
|
|
67
|
-
"test:bench": "vitest bench --config vite.config.ts --no-cache --project probe",
|
|
67
|
+
"test:bench": "vitest bench --config vite.config.ts --no-cache --project \"probe (bench)\" --mode benchmark",
|
|
68
68
|
"prepack": "npm run build",
|
|
69
69
|
"test:setup": "vitest run --config vite.config.ts --no-cache --reporter=dot --project setup"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@orkestrel/contract": "^0.0.
|
|
73
|
-
"@orkestrel/emitter": "^0.0.
|
|
72
|
+
"@orkestrel/contract": "^0.0.20",
|
|
73
|
+
"@orkestrel/emitter": "^0.0.13"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@microsoft/api-extractor": "^7.
|
|
77
|
-
"@orkestrel/guide": "^0.0.
|
|
78
|
-
"@orkestrel/probe": "^0.0.
|
|
79
|
-
"@orkestrel/scaffold": "^0.0.
|
|
80
|
-
"@orkestrel/test": "^0.0.
|
|
81
|
-
"@types/node": "^26.6.
|
|
82
|
-
"oxfmt": "^0.
|
|
83
|
-
"oxlint": "^1.
|
|
84
|
-
"typescript": "^
|
|
85
|
-
"vite": "^8.3.
|
|
86
|
-
"vitest": "^
|
|
76
|
+
"@microsoft/api-extractor": "^7.60.0",
|
|
77
|
+
"@orkestrel/guide": "^0.0.25",
|
|
78
|
+
"@orkestrel/probe": "^0.0.25",
|
|
79
|
+
"@orkestrel/scaffold": "^0.0.113",
|
|
80
|
+
"@orkestrel/test": "^0.0.31",
|
|
81
|
+
"@types/node": "^26.6.6",
|
|
82
|
+
"oxfmt": "^0.75.0",
|
|
83
|
+
"oxlint": "^1.90.0",
|
|
84
|
+
"typescript": "^7.0.2",
|
|
85
|
+
"vite": "^8.3.5",
|
|
86
|
+
"vitest": "^5.0.5"
|
|
87
87
|
},
|
|
88
88
|
"engines": {
|
|
89
89
|
"node": ">=22.12.0"
|