@orkestrel/pool 0.0.10 → 0.0.11
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/README.md +9 -12
- package/dist/src/core/index.cjs +8 -6
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +41 -18
- package/dist/src/core/index.d.ts +41 -18
- package/dist/src/core/index.js +8 -6
- package/dist/src/core/index.js.map +1 -1
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
# @orkestrel/pool
|
|
2
2
|
|
|
3
|
-
A typed
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`release` / `destroy`) and deliberately de-bloated — no warm-floor, no
|
|
13
|
-
eviction timers. Environment-agnostic — no I/O, no browser or server
|
|
14
|
-
assumptions. Part of the `@orkestrel` line.
|
|
3
|
+
> A typed resource pool with optional bounded capacity, unique ownership, FIFO settlement,
|
|
4
|
+
> validated reuse, caller-owned cancellation, explicit cleanup failures, and a stable
|
|
5
|
+
> event-driven teardown barrier.
|
|
6
|
+
|
|
7
|
+
Create a pool with the `createPool` function, hand it the hooks that make, check, and tear
|
|
8
|
+
down one resource, and `await pool.acquire()` wherever the work needs one. Release the token
|
|
9
|
+
in a `finally` block, and `await pool.destroy()` when the process is done with the pool.
|
|
10
|
+
Environment-agnostic — no I/O, no browser or server assumptions. Part of the `@orkestrel`
|
|
11
|
+
line.
|
|
15
12
|
|
|
16
13
|
## Install
|
|
17
14
|
|
package/dist/src/core/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let _orkestrel_emitter = require("@orkestrel/emitter");
|
|
3
3
|
//#region src/core/errors.ts
|
|
4
4
|
/**
|
|
5
|
-
* Represents a stable, machine-readable pool failure
|
|
6
|
-
* context.
|
|
5
|
+
* Represents a stable, machine-readable pool failure that retains the original thrown value as
|
|
6
|
+
* its cause without unsafe coercion, alongside structured context.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
@@ -62,7 +62,7 @@ function isPoolError(value) {
|
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/core/validators.ts
|
|
64
64
|
/**
|
|
65
|
-
* Tests whether a value is a valid
|
|
65
|
+
* Tests whether a value is a positive safe integer, the only valid explicit pool maximum.
|
|
66
66
|
*
|
|
67
67
|
* @param value - The unknown maximum candidate
|
|
68
68
|
* @returns True if the value is a positive safe integer; false otherwise
|
|
@@ -77,7 +77,8 @@ function isPoolMax(value) {
|
|
|
77
77
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Tests whether a value is a native `AbortSignal
|
|
80
|
+
* Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`
|
|
81
|
+
* for hostile proxies.
|
|
81
82
|
*
|
|
82
83
|
* @param value - The unknown signal candidate
|
|
83
84
|
* @returns True if the value is a native `AbortSignal`; false otherwise
|
|
@@ -623,7 +624,8 @@ var Pool = class {
|
|
|
623
624
|
//#endregion
|
|
624
625
|
//#region src/core/factories.ts
|
|
625
626
|
/**
|
|
626
|
-
* Creates a
|
|
627
|
+
* Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
|
|
628
|
+
* capacity, unique ownership, and FIFO settlement.
|
|
627
629
|
*
|
|
628
630
|
* @remarks
|
|
629
631
|
* Concurrent create and validation hooks may overlap, while acquire promises settle in
|
|
@@ -637,7 +639,7 @@ var Pool = class {
|
|
|
637
639
|
* @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe
|
|
638
640
|
* integer, with `code: 'invalid'`. Construction validates it synchronously, before the pool exists.
|
|
639
641
|
*
|
|
640
|
-
* @example
|
|
642
|
+
* @example Create a pool
|
|
641
643
|
* ```ts
|
|
642
644
|
* import { createPool } from '@orkestrel/pool'
|
|
643
645
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#create","#destroy","#validate","#max","#emitter","#resources","#available","#validating","#leased","#destroying","#waiters","#assigned","#reservations","#signals","#ready","#operations","#owned","#failures","#ending","#state","#createAbort","#abort","#pump","#dispose","#settleClear","#detach","#own","#finish","#release","#createRelease","#recycle","#commit","#pumping","#repump","#startValidation","#startCreate","#createResource","#completeOperation","#failOperation","#prepare","#validateResource","#token","#record","#clean","#cleanupError","#completeCleanup","#failCleanup"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\n\n/**\n * Represents a stable, machine-readable pool failure with the original cause and structured\n * 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\ttry {\n\t\t\tif (\n\t\t\t\toptions.cause instanceof Error &&\n\t\t\t\ttypeof options.cause.message === 'string' &&\n\t\t\t\toptions.cause.message.length > 0\n\t\t\t) {\n\t\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t\t}\n\t\t} catch {}\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\ttry {\n\t\treturn value instanceof PoolError\n\t} catch {\n\t\treturn false\n\t}\n}\n","/**\n * Tests whether a value is a valid finite pool maximum.\n *\n * @param value - The unknown maximum candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolMax(8) // true\n * isPoolMax(Infinity) // false\n * ```\n */\nexport function isPoolMax(value: unknown): value is number {\n\treturn typeof value === 'number' && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal`, returning `false` 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\ttry {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (getter === undefined) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type { EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { PoolError } from './errors.js'\nimport { isPoolMax, isPoolSignal } from './validators.js'\n\n/**\n * Represents a capacity-aware resource pool whose opaque ownership records preserve FIFO\n * settlement, cancellation, exact lease release, and deterministic teardown under concurrent\n * 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 #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new 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\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, and optional positive safe `max`\n\t * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n\t * integer, with `code: 'invalid'`.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tif (max !== undefined && !isPoolMax(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\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\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 or destroying. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts the records immediately available without validation work. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts the records represented by unsettled released-once lease tokens. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Queues and leases one resource in FIFO settlement order.\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, with `code: 'create'` and the hook's thrown\n\t * value as `cause`; and when an invalid record's cleanup fails, with `code: 'cleanup'`. A\n\t * `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.\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 failed 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\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#createRelease(record: object): () => void {\n\t\tlet released = false\n\t\treturn (): void => {\n\t\t\tif (released) return\n\t\t\treleased = true\n\t\t\tthis.#release(record)\n\t\t}\n\t}\n\n\t#token(record: object, value: T): PoolToken<T> {\n\t\treturn { value, release: this.#createRelease(record) }\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.#available.shift()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#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.#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} while (this.#repump)\n\t\tthis.#pumping = false\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.#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 = {}\n\t\tthis.#resources.set(record, value)\n\t\tthis.#emitter.emit('create')\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),\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\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\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),\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\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\tthis.#leased.add(result.record)\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): void {\n\t\tif (!this.#leased.delete(record)) return\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tthis.#available.push(record)\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\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\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 attempt: Promise<void>\n\t\ttry {\n\t\t\tattempt = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tattempt = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait attempt\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tthis.#resources.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\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 (this.#validating.has(record) || this.#destroying.has(record)) continue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > 0 || 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 resource pool with optional bounded capacity, unique ownership, 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 *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, optional positive safe `max`, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n * integer, with `code: 'invalid'`. Construction validates it synchronously, before the pool exists.\n *\n * @example\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":";;;;;;;;;;;;;;;;;;AAiBA,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,IAAI;GACH,IACC,QAAQ,iBAAiB,SACzB,OAAO,QAAQ,MAAM,YAAY,YACjC,QAAQ,MAAM,QAAQ,SAAS,GAE/B,UAAU,GAAG,QAAQ,IAAI,QAAQ,MAAM;EAEzC,QAAQ,CAAC;EACT,MAAM,SAAS,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EACjF,KAAK,OAAO;EACZ,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ;CACxB;AACD;;;;;;;;;;;;;AAcA,SAAgB,YAAY,OAAoC;CAC/D,IAAI;EACH,OAAO,iBAAiB;CACzB,QAAQ;EACP,OAAO;CACR;AACD;;;;;;;;;;;;;;;ACvDA,SAAgB,UAAU,OAAiC;CAC1D,OAAO,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,QAAQ;AAC5E;;;;;;;;;;;;;AAcA,SAAgB,aAAa,OAAsC;CAClE,IAAI;EACH,MAAM,SAAS,OAAO,yBAAyB,YAAY,WAA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O;AACxB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","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'\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\ttry {\n\t\t\tif (\n\t\t\t\toptions.cause instanceof Error &&\n\t\t\t\ttypeof options.cause.message === 'string' &&\n\t\t\t\toptions.cause.message.length > 0\n\t\t\t) {\n\t\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t\t}\n\t\t} catch {}\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\ttry {\n\t\treturn value instanceof PoolError\n\t} catch {\n\t\treturn false\n\t}\n}\n","/**\n * Tests whether a value is a positive safe integer, the only valid explicit pool maximum.\n *\n * @param value - The unknown maximum candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolMax(8) // true\n * isPoolMax(Infinity) // false\n * ```\n */\nexport function isPoolMax(value: unknown): value is number {\n\treturn typeof value === 'number' && 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\ttry {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (getter === undefined) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type { EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { PoolError } from './errors.js'\nimport { isPoolMax, isPoolSignal } from './validators.js'\n\n/**\n * Represents a capacity-aware resource pool whose opaque ownership records preserve FIFO\n * settlement, cancellation, exact lease release, and deterministic teardown under concurrent\n * 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 #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new 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\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, and optional positive safe `max`\n\t * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n\t * integer, with `code: 'invalid'`.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tif (max !== undefined && !isPoolMax(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\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\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 or destroying. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts the records immediately available without validation work. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts the records represented by unsettled released-once lease tokens. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Queues and leases one resource in FIFO settlement order.\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, with `code: 'create'` and the hook's thrown\n\t * value as `cause`; and when an invalid record's cleanup fails, with `code: 'cleanup'`. A\n\t * `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.\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 failed 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\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#createRelease(record: object): () => void {\n\t\tlet released = false\n\t\treturn (): void => {\n\t\t\tif (released) return\n\t\t\treleased = true\n\t\t\tthis.#release(record)\n\t\t}\n\t}\n\n\t#token(record: object, value: T): PoolToken<T> {\n\t\treturn { value, release: this.#createRelease(record) }\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.#available.shift()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#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.#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} while (this.#repump)\n\t\tthis.#pumping = false\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.#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 = {}\n\t\tthis.#resources.set(record, value)\n\t\tthis.#emitter.emit('create')\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),\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\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\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),\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\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\tthis.#leased.add(result.record)\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): void {\n\t\tif (!this.#leased.delete(record)) return\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tthis.#available.push(record)\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\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\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 attempt: Promise<void>\n\t\ttry {\n\t\t\tattempt = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tattempt = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait attempt\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tthis.#resources.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\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 (this.#validating.has(record) || this.#destroying.has(record)) continue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > 0 || 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, unique ownership, 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 *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, optional positive safe `max`, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n * integer, with `code: 'invalid'`. Construction validates it 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":";;;;;;;;;;;;;;;;;;AAiBA,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,IAAI;GACH,IACC,QAAQ,iBAAiB,SACzB,OAAO,QAAQ,MAAM,YAAY,YACjC,QAAQ,MAAM,QAAQ,SAAS,GAE/B,UAAU,GAAG,QAAQ,IAAI,QAAQ,MAAM;EAEzC,QAAQ,CAAC;EACT,MAAM,SAAS,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EACjF,KAAK,OAAO;EACZ,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ;CACxB;AACD;;;;;;;;;;;;;AAcA,SAAgB,YAAY,OAAoC;CAC/D,IAAI;EACH,OAAO,iBAAiB;CACzB,QAAQ;EACP,OAAO;CACR;AACD;;;;;;;;;;;;;;;ACvDA,SAAgB,UAAU,OAAiC;CAC1D,OAAO,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,QAAQ;AAC5E;;;;;;;;;;;;;;AAeA,SAAgB,aAAa,OAAsC;CAClE,IAAI;EACH,MAAM,SAAS,OAAO,yBAAyB,YAAY,WAAW,SAAS,CAAC,EAAE;EAClF,IAAI,WAAW,KAAA,GAAW,OAAO;EACjC,QAAQ,MAAM,QAAQ,OAAO,CAAC,CAAC;EAC/B,OAAO;CACR,QAAQ;EACP,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;;;;;;ACXA,IAAa,OAAb,MAAiD;CAChD;CACA;CACA;CACA;CACA;CACA,6BAAsB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AAU,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;EAC/E,IAAI,UAAU;EACd,KAAK,MAAM,UAAU,KAAK,WAAW,KAAK,GAAG;GAC5C,IAAI,KAAK,YAAY,IAAI,MAAM,KAAK,KAAK,YAAY,IAAI,MAAM,GAAG;GAClE,UAAU;GACV,KAAK,KAAK,KAAK,SAAS,MAAM,CAAC;EAChC;EACA,IAAI,WAAW,KAAK,WAAW,OAAO,KAAK,KAAK,YAAY,OAAO,GAAG;EACtE,KAAK,SAAS,QAAQ;EACtB,IAAI,KAAK,UAAU,SAAS,GAAG,OAAO,OAAO,KAAK,cAAc,KAAK,SAAS,CAAC;OAC1E,OAAO,QAAQ;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACriBA,SAAgB,WAAc,SAA2C;CACxE,OAAO,IAAI,KAAK,OAAO;AACxB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
1
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates a
|
|
6
|
+
* Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
|
|
7
|
+
* capacity, unique ownership, and FIFO settlement.
|
|
7
8
|
*
|
|
8
9
|
* @remarks
|
|
9
10
|
* Concurrent create and validation hooks may overlap, while acquire promises settle in
|
|
@@ -17,7 +18,7 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
17
18
|
* @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe
|
|
18
19
|
* integer, with `code: 'invalid'`. Construction validates it synchronously, before the pool exists.
|
|
19
20
|
*
|
|
20
|
-
* @example
|
|
21
|
+
* @example Create a pool
|
|
21
22
|
* ```ts
|
|
22
23
|
* import { createPool } from '@orkestrel/pool'
|
|
23
24
|
*
|
|
@@ -53,7 +54,7 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
53
54
|
export declare function isPoolError(value: unknown): value is PoolError;
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* Tests whether a value is a valid
|
|
57
|
+
* Tests whether a value is a positive safe integer, the only valid explicit pool maximum.
|
|
57
58
|
*
|
|
58
59
|
* @param value - The unknown maximum candidate
|
|
59
60
|
* @returns True if the value is a positive safe integer; false otherwise
|
|
@@ -67,7 +68,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
67
68
|
export declare function isPoolMax(value: unknown): value is number;
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
|
-
* Tests whether a value is a native `AbortSignal
|
|
71
|
+
* Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`
|
|
72
|
+
* for hostile proxies.
|
|
71
73
|
*
|
|
72
74
|
* @param value - The unknown signal candidate
|
|
73
75
|
* @returns True if the value is a native `AbortSignal`; false otherwise
|
|
@@ -154,10 +156,15 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
154
156
|
destroy(): Promise<void>;
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Names the machine-readable failure codes produced by {@link PoolError}.
|
|
161
|
+
*/
|
|
158
162
|
export declare type PoolCode = 'invalid' | 'destroyed' | 'create' | 'cleanup';
|
|
159
163
|
|
|
160
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Represents the structured context attached to a {@link PoolError}: the rejected input, or the
|
|
166
|
+
* distinct destroy-hook failures an aggregate cleanup collected.
|
|
167
|
+
*/
|
|
161
168
|
export declare interface PoolContext {
|
|
162
169
|
/** Holds the rejected public input, when the failure is an input-validation error. */
|
|
163
170
|
readonly value?: unknown;
|
|
@@ -166,8 +173,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
/**
|
|
169
|
-
* Represents a stable, machine-readable pool failure
|
|
170
|
-
* context.
|
|
176
|
+
* Represents a stable, machine-readable pool failure that retains the original thrown value as
|
|
177
|
+
* its cause without unsafe coercion, alongside structured context.
|
|
171
178
|
*
|
|
172
179
|
* @example
|
|
173
180
|
* ```ts
|
|
@@ -193,7 +200,10 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
193
200
|
constructor(options: PoolErrorOptions);
|
|
194
201
|
}
|
|
195
202
|
|
|
196
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* Represents the construction options for {@link PoolError}: the stable code, an optional cause,
|
|
205
|
+
* and optional structured context.
|
|
206
|
+
*/
|
|
197
207
|
export declare interface PoolErrorOptions {
|
|
198
208
|
/** Holds the stable machine-readable failure category. */
|
|
199
209
|
readonly code: PoolCode;
|
|
@@ -203,7 +213,9 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
203
213
|
readonly context?: PoolContext;
|
|
204
214
|
}
|
|
205
215
|
|
|
206
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Represents the observable resource lifecycle events emitted by a {@link PoolInterface}.
|
|
218
|
+
*/
|
|
207
219
|
export declare type PoolEventMap = {
|
|
208
220
|
/** Signals that a created resource entered pool ownership. */
|
|
209
221
|
readonly create: readonly [];
|
|
@@ -215,7 +227,10 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
215
227
|
readonly destroy: readonly [];
|
|
216
228
|
};
|
|
217
229
|
|
|
218
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Represents a FIFO resource pool with optional bounded capacity and deterministic teardown,
|
|
232
|
+
* exposing its record counts and a typed lifecycle emitter.
|
|
233
|
+
*/
|
|
219
234
|
export declare interface PoolInterface<T> {
|
|
220
235
|
/** Holds the typed synchronous lifecycle observation surface. */
|
|
221
236
|
readonly emitter: EmitterInterface<PoolEventMap>;
|
|
@@ -226,7 +241,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
226
241
|
/** Counts the records represented by unsettled released-once lease tokens. */
|
|
227
242
|
readonly active: number;
|
|
228
243
|
/**
|
|
229
|
-
* Queues
|
|
244
|
+
* Queues the caller in FIFO order, validates an idle record or creates one, and settles queued
|
|
245
|
+
* acquires in that same order.
|
|
230
246
|
*
|
|
231
247
|
* @param signal - Optional native cancellation signal
|
|
232
248
|
* @returns A promise for the unique resource lease
|
|
@@ -261,7 +277,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
261
277
|
}
|
|
262
278
|
|
|
263
279
|
/**
|
|
264
|
-
* Represents the resource lifecycle options for {@link Pool} and `createPool
|
|
280
|
+
* Represents the resource lifecycle options for {@link Pool} and `createPool`: creation,
|
|
281
|
+
* destruction, validation, capacity, and observation.
|
|
265
282
|
*
|
|
266
283
|
* @remarks
|
|
267
284
|
* `create` lazily produces resources. `destroy` tears down a claimed resource.
|
|
@@ -278,11 +295,17 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
278
295
|
readonly max?: number;
|
|
279
296
|
}
|
|
280
297
|
|
|
281
|
-
/**
|
|
298
|
+
/**
|
|
299
|
+
* Represents a unique lease over one pool-owned resource record, exposing that record as a readonly
|
|
300
|
+
* `value` and returning it through an idempotent `release`.
|
|
301
|
+
*/
|
|
282
302
|
export declare interface PoolToken<T> {
|
|
283
303
|
/** Holds the leased value. Duplicate values still belong to independent records. */
|
|
284
304
|
readonly value: T;
|
|
285
|
-
/**
|
|
305
|
+
/**
|
|
306
|
+
* Gives this exact record back to the pool once; a repeat call, and a call after teardown took
|
|
307
|
+
* ownership, are no-ops.
|
|
308
|
+
*/
|
|
286
309
|
release(): void;
|
|
287
310
|
}
|
|
288
311
|
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
1
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates a
|
|
6
|
+
* Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
|
|
7
|
+
* capacity, unique ownership, and FIFO settlement.
|
|
7
8
|
*
|
|
8
9
|
* @remarks
|
|
9
10
|
* Concurrent create and validation hooks may overlap, while acquire promises settle in
|
|
@@ -17,7 +18,7 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
17
18
|
* @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe
|
|
18
19
|
* integer, with `code: 'invalid'`. Construction validates it synchronously, before the pool exists.
|
|
19
20
|
*
|
|
20
|
-
* @example
|
|
21
|
+
* @example Create a pool
|
|
21
22
|
* ```ts
|
|
22
23
|
* import { createPool } from '@orkestrel/pool'
|
|
23
24
|
*
|
|
@@ -53,7 +54,7 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
53
54
|
export declare function isPoolError(value: unknown): value is PoolError;
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* Tests whether a value is a valid
|
|
57
|
+
* Tests whether a value is a positive safe integer, the only valid explicit pool maximum.
|
|
57
58
|
*
|
|
58
59
|
* @param value - The unknown maximum candidate
|
|
59
60
|
* @returns True if the value is a positive safe integer; false otherwise
|
|
@@ -67,7 +68,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
67
68
|
export declare function isPoolMax(value: unknown): value is number;
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
|
-
* Tests whether a value is a native `AbortSignal
|
|
71
|
+
* Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`
|
|
72
|
+
* for hostile proxies.
|
|
71
73
|
*
|
|
72
74
|
* @param value - The unknown signal candidate
|
|
73
75
|
* @returns True if the value is a native `AbortSignal`; false otherwise
|
|
@@ -154,10 +156,15 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
154
156
|
destroy(): Promise<void>;
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Names the machine-readable failure codes produced by {@link PoolError}.
|
|
161
|
+
*/
|
|
158
162
|
export declare type PoolCode = 'invalid' | 'destroyed' | 'create' | 'cleanup';
|
|
159
163
|
|
|
160
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Represents the structured context attached to a {@link PoolError}: the rejected input, or the
|
|
166
|
+
* distinct destroy-hook failures an aggregate cleanup collected.
|
|
167
|
+
*/
|
|
161
168
|
export declare interface PoolContext {
|
|
162
169
|
/** Holds the rejected public input, when the failure is an input-validation error. */
|
|
163
170
|
readonly value?: unknown;
|
|
@@ -166,8 +173,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
/**
|
|
169
|
-
* Represents a stable, machine-readable pool failure
|
|
170
|
-
* context.
|
|
176
|
+
* Represents a stable, machine-readable pool failure that retains the original thrown value as
|
|
177
|
+
* its cause without unsafe coercion, alongside structured context.
|
|
171
178
|
*
|
|
172
179
|
* @example
|
|
173
180
|
* ```ts
|
|
@@ -193,7 +200,10 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
193
200
|
constructor(options: PoolErrorOptions);
|
|
194
201
|
}
|
|
195
202
|
|
|
196
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* Represents the construction options for {@link PoolError}: the stable code, an optional cause,
|
|
205
|
+
* and optional structured context.
|
|
206
|
+
*/
|
|
197
207
|
export declare interface PoolErrorOptions {
|
|
198
208
|
/** Holds the stable machine-readable failure category. */
|
|
199
209
|
readonly code: PoolCode;
|
|
@@ -203,7 +213,9 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
203
213
|
readonly context?: PoolContext;
|
|
204
214
|
}
|
|
205
215
|
|
|
206
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Represents the observable resource lifecycle events emitted by a {@link PoolInterface}.
|
|
218
|
+
*/
|
|
207
219
|
export declare type PoolEventMap = {
|
|
208
220
|
/** Signals that a created resource entered pool ownership. */
|
|
209
221
|
readonly create: readonly [];
|
|
@@ -215,7 +227,10 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
215
227
|
readonly destroy: readonly [];
|
|
216
228
|
};
|
|
217
229
|
|
|
218
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Represents a FIFO resource pool with optional bounded capacity and deterministic teardown,
|
|
232
|
+
* exposing its record counts and a typed lifecycle emitter.
|
|
233
|
+
*/
|
|
219
234
|
export declare interface PoolInterface<T> {
|
|
220
235
|
/** Holds the typed synchronous lifecycle observation surface. */
|
|
221
236
|
readonly emitter: EmitterInterface<PoolEventMap>;
|
|
@@ -226,7 +241,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
226
241
|
/** Counts the records represented by unsettled released-once lease tokens. */
|
|
227
242
|
readonly active: number;
|
|
228
243
|
/**
|
|
229
|
-
* Queues
|
|
244
|
+
* Queues the caller in FIFO order, validates an idle record or creates one, and settles queued
|
|
245
|
+
* acquires in that same order.
|
|
230
246
|
*
|
|
231
247
|
* @param signal - Optional native cancellation signal
|
|
232
248
|
* @returns A promise for the unique resource lease
|
|
@@ -261,7 +277,8 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
261
277
|
}
|
|
262
278
|
|
|
263
279
|
/**
|
|
264
|
-
* Represents the resource lifecycle options for {@link Pool} and `createPool
|
|
280
|
+
* Represents the resource lifecycle options for {@link Pool} and `createPool`: creation,
|
|
281
|
+
* destruction, validation, capacity, and observation.
|
|
265
282
|
*
|
|
266
283
|
* @remarks
|
|
267
284
|
* `create` lazily produces resources. `destroy` tears down a claimed resource.
|
|
@@ -278,11 +295,17 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
278
295
|
readonly max?: number;
|
|
279
296
|
}
|
|
280
297
|
|
|
281
|
-
/**
|
|
298
|
+
/**
|
|
299
|
+
* Represents a unique lease over one pool-owned resource record, exposing that record as a readonly
|
|
300
|
+
* `value` and returning it through an idempotent `release`.
|
|
301
|
+
*/
|
|
282
302
|
export declare interface PoolToken<T> {
|
|
283
303
|
/** Holds the leased value. Duplicate values still belong to independent records. */
|
|
284
304
|
readonly value: T;
|
|
285
|
-
/**
|
|
305
|
+
/**
|
|
306
|
+
* Gives this exact record back to the pool once; a repeat call, and a call after teardown took
|
|
307
|
+
* ownership, are no-ops.
|
|
308
|
+
*/
|
|
286
309
|
release(): void;
|
|
287
310
|
}
|
|
288
311
|
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Emitter } from "@orkestrel/emitter";
|
|
2
2
|
//#region src/core/errors.ts
|
|
3
3
|
/**
|
|
4
|
-
* Represents a stable, machine-readable pool failure
|
|
5
|
-
* context.
|
|
4
|
+
* Represents a stable, machine-readable pool failure that retains the original thrown value as
|
|
5
|
+
* its cause without unsafe coercion, alongside structured context.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
@@ -61,7 +61,7 @@ function isPoolError(value) {
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/core/validators.ts
|
|
63
63
|
/**
|
|
64
|
-
* Tests whether a value is a valid
|
|
64
|
+
* Tests whether a value is a positive safe integer, the only valid explicit pool maximum.
|
|
65
65
|
*
|
|
66
66
|
* @param value - The unknown maximum candidate
|
|
67
67
|
* @returns True if the value is a positive safe integer; false otherwise
|
|
@@ -76,7 +76,8 @@ function isPoolMax(value) {
|
|
|
76
76
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
* Tests whether a value is a native `AbortSignal
|
|
79
|
+
* Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`
|
|
80
|
+
* for hostile proxies.
|
|
80
81
|
*
|
|
81
82
|
* @param value - The unknown signal candidate
|
|
82
83
|
* @returns True if the value is a native `AbortSignal`; false otherwise
|
|
@@ -622,7 +623,8 @@ var Pool = class {
|
|
|
622
623
|
//#endregion
|
|
623
624
|
//#region src/core/factories.ts
|
|
624
625
|
/**
|
|
625
|
-
* Creates a
|
|
626
|
+
* Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
|
|
627
|
+
* capacity, unique ownership, and FIFO settlement.
|
|
626
628
|
*
|
|
627
629
|
* @remarks
|
|
628
630
|
* Concurrent create and validation hooks may overlap, while acquire promises settle in
|
|
@@ -636,7 +638,7 @@ var Pool = class {
|
|
|
636
638
|
* @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe
|
|
637
639
|
* integer, with `code: 'invalid'`. Construction validates it synchronously, before the pool exists.
|
|
638
640
|
*
|
|
639
|
-
* @example
|
|
641
|
+
* @example Create a pool
|
|
640
642
|
* ```ts
|
|
641
643
|
* import { createPool } from '@orkestrel/pool'
|
|
642
644
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#create","#destroy","#validate","#max","#emitter","#resources","#available","#validating","#leased","#destroying","#waiters","#assigned","#reservations","#signals","#ready","#operations","#owned","#failures","#ending","#state","#createAbort","#abort","#pump","#dispose","#settleClear","#detach","#own","#finish","#release","#createRelease","#recycle","#commit","#pumping","#repump","#startValidation","#startCreate","#createResource","#completeOperation","#failOperation","#prepare","#validateResource","#token","#record","#clean","#cleanupError","#completeCleanup","#failCleanup"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\n\n/**\n * Represents a stable, machine-readable pool failure with the original cause and structured\n * 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\ttry {\n\t\t\tif (\n\t\t\t\toptions.cause instanceof Error &&\n\t\t\t\ttypeof options.cause.message === 'string' &&\n\t\t\t\toptions.cause.message.length > 0\n\t\t\t) {\n\t\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t\t}\n\t\t} catch {}\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\ttry {\n\t\treturn value instanceof PoolError\n\t} catch {\n\t\treturn false\n\t}\n}\n","/**\n * Tests whether a value is a valid finite pool maximum.\n *\n * @param value - The unknown maximum candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolMax(8) // true\n * isPoolMax(Infinity) // false\n * ```\n */\nexport function isPoolMax(value: unknown): value is number {\n\treturn typeof value === 'number' && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal`, returning `false` 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\ttry {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (getter === undefined) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type { EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { PoolError } from './errors.js'\nimport { isPoolMax, isPoolSignal } from './validators.js'\n\n/**\n * Represents a capacity-aware resource pool whose opaque ownership records preserve FIFO\n * settlement, cancellation, exact lease release, and deterministic teardown under concurrent\n * 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 #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new 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\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, and optional positive safe `max`\n\t * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n\t * integer, with `code: 'invalid'`.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tif (max !== undefined && !isPoolMax(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\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\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 or destroying. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts the records immediately available without validation work. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts the records represented by unsettled released-once lease tokens. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Queues and leases one resource in FIFO settlement order.\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, with `code: 'create'` and the hook's thrown\n\t * value as `cause`; and when an invalid record's cleanup fails, with `code: 'cleanup'`. A\n\t * `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.\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 failed 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\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#createRelease(record: object): () => void {\n\t\tlet released = false\n\t\treturn (): void => {\n\t\t\tif (released) return\n\t\t\treleased = true\n\t\t\tthis.#release(record)\n\t\t}\n\t}\n\n\t#token(record: object, value: T): PoolToken<T> {\n\t\treturn { value, release: this.#createRelease(record) }\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.#available.shift()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#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.#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} while (this.#repump)\n\t\tthis.#pumping = false\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.#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 = {}\n\t\tthis.#resources.set(record, value)\n\t\tthis.#emitter.emit('create')\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),\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\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\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),\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\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\tthis.#leased.add(result.record)\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): void {\n\t\tif (!this.#leased.delete(record)) return\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tthis.#available.push(record)\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\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\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 attempt: Promise<void>\n\t\ttry {\n\t\t\tattempt = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tattempt = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait attempt\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tthis.#resources.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\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 (this.#validating.has(record) || this.#destroying.has(record)) continue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > 0 || 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 resource pool with optional bounded capacity, unique ownership, 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 *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, optional positive safe `max`, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n * integer, with `code: 'invalid'`. Construction validates it synchronously, before the pool exists.\n *\n * @example\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":";;;;;;;;;;;;;;;;;AAiBA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;;;;;CAOA,YAAY,SAA2B;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ACN,GAAI,SAAS,OAAO,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,SAAS,GAAG;GAC1D,SAAS,EAAE,UAAU,CAAC,GAAG,QAAQ,EAAE;EACpC,CAAC;CACF;CAEA,UAAgB;EACf,MAAM,SAAS,KAAKC;EACpB,IAAI,WAAW,KAAA,KAAa,KAAKH,YAAY,OAAO,KAAK,KAAKC,OAAO,OAAO,GAAG;EAC/E,IAAI,UAAU;EACd,KAAK,MAAM,UAAU,KAAKX,WAAW,KAAK,GAAG;GAC5C,IAAI,KAAKE,YAAY,IAAI,MAAM,KAAK,KAAKE,YAAY,IAAI,MAAM,GAAG;GAClE,UAAU;GACV,KAAKiB,KAAK,KAAKH,SAAS,MAAM,CAAC;EAChC;EACA,IAAI,WAAW,KAAKlB,WAAW,OAAO,KAAK,KAAKI,YAAY,OAAO,GAAG;EACtE,KAAKL,SAAS,QAAQ;EACtB,IAAI,KAAKa,UAAU,SAAS,GAAG,OAAO,OAAO,KAAK2B,cAAc,KAAK3B,SAAS,CAAC;OAC1E,OAAO,QAAQ;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtiBA,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'\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\ttry {\n\t\t\tif (\n\t\t\t\toptions.cause instanceof Error &&\n\t\t\t\ttypeof options.cause.message === 'string' &&\n\t\t\t\toptions.cause.message.length > 0\n\t\t\t) {\n\t\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t\t}\n\t\t} catch {}\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\ttry {\n\t\treturn value instanceof PoolError\n\t} catch {\n\t\treturn false\n\t}\n}\n","/**\n * Tests whether a value is a positive safe integer, the only valid explicit pool maximum.\n *\n * @param value - The unknown maximum candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolMax(8) // true\n * isPoolMax(Infinity) // false\n * ```\n */\nexport function isPoolMax(value: unknown): value is number {\n\treturn typeof value === 'number' && 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\ttry {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (getter === undefined) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n","import type { EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { PoolError } from './errors.js'\nimport { isPoolMax, isPoolSignal } from './validators.js'\n\n/**\n * Represents a capacity-aware resource pool whose opaque ownership records preserve FIFO\n * settlement, cancellation, exact lease release, and deterministic teardown under concurrent\n * 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 #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new 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\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, and optional positive safe `max`\n\t * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n\t * integer, with `code: 'invalid'`.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tif (max !== undefined && !isPoolMax(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\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\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 or destroying. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts the records immediately available without validation work. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts the records represented by unsettled released-once lease tokens. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Queues and leases one resource in FIFO settlement order.\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, with `code: 'create'` and the hook's thrown\n\t * value as `cause`; and when an invalid record's cleanup fails, with `code: 'cleanup'`. A\n\t * `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.\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 failed 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\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#createRelease(record: object): () => void {\n\t\tlet released = false\n\t\treturn (): void => {\n\t\t\tif (released) return\n\t\t\treleased = true\n\t\t\tthis.#release(record)\n\t\t}\n\t}\n\n\t#token(record: object, value: T): PoolToken<T> {\n\t\treturn { value, release: this.#createRelease(record) }\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.#available.shift()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#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.#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} while (this.#repump)\n\t\tthis.#pumping = false\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.#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 = {}\n\t\tthis.#resources.set(record, value)\n\t\tthis.#emitter.emit('create')\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),\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\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\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),\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\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\tthis.#leased.add(result.record)\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): void {\n\t\tif (!this.#leased.delete(record)) return\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tthis.#available.push(record)\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\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\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 attempt: Promise<void>\n\t\ttry {\n\t\t\tattempt = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tattempt = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait attempt\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tthis.#resources.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\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 (this.#validating.has(record) || this.#destroying.has(record)) continue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > 0 || 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, unique ownership, 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 *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, optional positive safe `max`, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown when `options.max` is present and is not a positive safe\n * integer, with `code: 'invalid'`. Construction validates it 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":";;;;;;;;;;;;;;;;;AAiBA,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,IAAI;GACH,IACC,QAAQ,iBAAiB,SACzB,OAAO,QAAQ,MAAM,YAAY,YACjC,QAAQ,MAAM,QAAQ,SAAS,GAE/B,UAAU,GAA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U,SAAS,GAAG,OAAO,OAAO,KAAK,cAAc,KAAK,SAAS,CAAC;OAC1E,OAAO,QAAQ;CACrB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACriBA,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.11",
|
|
4
4
|
"description": "A typed resource pool with optional bounded capacity, FIFO abort-cancellable waiting, validated idle reuse, and an observable lifecycle. Part of the @orkestrel line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"connection-pool",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
46
46
|
"copy": "node -e \"const fs=require('node:fs'),p=require('node:path'),a=process.argv[1],b=process.argv[2];fs.mkdirSync(p.dirname(b),{recursive:true});fs.cpSync(a,b,{force:true});console.log('Copied: '+a+' to '+b)\"",
|
|
47
47
|
"scaffold": "scaffold",
|
|
48
|
-
"lint": "oxlint --config .oxlintrc.json --fix
|
|
48
|
+
"lint": "oxlint --config .oxlintrc.json --fix .",
|
|
49
49
|
"check": "tsc --noEmit --project tsconfig.json && npm run check:src",
|
|
50
50
|
"check:src": "npm run check:src:core",
|
|
51
51
|
"check:src:core": "tsc --noEmit -p configs/src/tsconfig.core.json",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"test:src:core": "vitest run --config vite.config.ts --no-cache --reporter=dot --project src:core",
|
|
58
58
|
"test:policy": "vitest run --config vite.config.ts --no-cache --reporter=dot --project policy",
|
|
59
59
|
"test:config": "vitest run --config vite.config.ts --no-cache --reporter=dot --project config",
|
|
60
|
-
"test:guides": "
|
|
60
|
+
"test:guides": "node --experimental-strip-types tests/guides.test.ts",
|
|
61
61
|
"build": "npm run clean && npm run build:src",
|
|
62
62
|
"build:src": "npm run build:src:core",
|
|
63
63
|
"build:src:core": "vite build --config configs/src/vite.core.config.ts && npm run copy dist/src/core/index.d.ts dist/src/core/index.d.cts",
|
|
@@ -69,20 +69,19 @@
|
|
|
69
69
|
"test:setup": "vitest run --config vite.config.ts --no-cache --reporter=dot --project setup"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@orkestrel/emitter": "^0.0.
|
|
72
|
+
"@orkestrel/emitter": "^0.0.10"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@microsoft/api-extractor": "^7.59.0",
|
|
76
|
-
"@orkestrel/guide": "^0.0.
|
|
77
|
-
"@orkestrel/probe": "^0.0.
|
|
78
|
-
"@orkestrel/scaffold": "^0.0.
|
|
79
|
-
"@orkestrel/test": "^0.0.
|
|
76
|
+
"@orkestrel/guide": "^0.0.17",
|
|
77
|
+
"@orkestrel/probe": "^0.0.12",
|
|
78
|
+
"@orkestrel/scaffold": "^0.0.63",
|
|
79
|
+
"@orkestrel/test": "^0.0.14",
|
|
80
80
|
"@types/node": "^26.4.1",
|
|
81
81
|
"oxfmt": "^0.66.0",
|
|
82
82
|
"oxlint": "^1.81.0",
|
|
83
83
|
"typescript": "^6.0.3",
|
|
84
84
|
"vite": "^8.2.2",
|
|
85
|
-
"vite-plugin-dts": "^5.1.0",
|
|
86
85
|
"vitest": "^4.1.11"
|
|
87
86
|
},
|
|
88
87
|
"engines": {
|