Map-like Operations
Methods that make Pool behave like a Map for easy get/set/has/delete operations.
get()
Gets an entry by field value or predicate.
typescript
pool.get(key: keyof T, value: any): T | null
pool.get(predicate: (entry: PoolEntry<T>) => boolean): T | nullParameters:
key- Field name to matchvalue- Value to match for the key- OR
predicate- Function that returns true for the entry to get
Returns: The matching data or null
Example:
typescript
// By field
const user = pool.get('id', 'user123');
// By predicate (with destructuring)
const admin = pool.get(({ data }) => data.role === 'admin');has()
Checks if an entry exists.
typescript
pool.has(key: keyof T, value: any): boolean
pool.has(predicate: (entry: PoolEntry<T>) => boolean): booleanParameters:
key- Field name to matchvalue- Value to match- OR
predicate- Function that returns true for the entry to check
Returns: True if entry exists
Example:
typescript
if (pool.has('id', 'user123')) {
console.log('User exists');
}
// With destructuring
if (pool.has(({ data }) => data.age > 18)) {
console.log('Has adults');
}set()
Sets (updates or adds) an entry in the pool.
typescript
pool.set(key: keyof T, value: any, data: T, meta?: Record<string, any>): PoolEntry<T>Parameters:
key- Field name to use as keyvalue- Value to match for the keydata- New data to setmeta- Optional metadata
Returns: The created or updated pool entry
Example:
typescript
// Update if exists, add if not
pool.set('id', 'user123', { id: 'user123', name: 'Alice' });delete()
Deletes an entry from the pool.
typescript
pool.delete(key: keyof T, value: any): booleanParameters:
key- Field name to use as keyvalue- Value to match for the key
Returns: True if entry was deleted
Example:
typescript
const deleted = pool.delete('id', 'user123');
if (deleted) {
console.log('User deleted');
}