Class: InMemorySpoolStore
Defined in: batteries/storage/in_memory/index.ts:134
In-memory "give bytes, get a reader" persistence layer keyed by callId.
Remarks
Stores each value byte-faithfully as a Uint8Array. string inputs are encoded as UTF-8; Uint8Array inputs are held verbatim (no lossy text round-trip, so binary payloads survive intact); ReadableStream<Uint8Array> inputs are drained fully into a buffer — in-memory storage cannot stream to disk, so the stream form resolves asynchronously and is the documented trade-off for this battery.
Each write() and each read() returns a fresh InMemorySpoolReader — the store owns the bytes, the reader is a view. Mutating the store after handing out a reader does not invalidate the reader.
Implements @nhtio/adk!SpoolStore (i.e. ByteStore<SpoolReader>).
Example
const store = new InMemorySpoolStore();
const bytes = await tool.executor(ctx)(args);
const reader = await store.write(callId, bytes);
const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact;
const artifact = new Ctor(reader);Implements
Constructors
Constructor
new InMemorySpoolStore(): InMemorySpoolStore;Returns
InMemorySpoolStore
Accessors
size
Get Signature
get size(): number;Defined in: batteries/storage/in_memory/index.ts:210
Returns the number of entries currently in the store.
Returns
number
Methods
clear()
clear(): void;Defined in: batteries/storage/in_memory/index.ts:203
Removes every entry from the store.
Returns
void
Remarks
Existing readers handed out by prior write() / read() calls remain valid — they hold their own snapshot.
delete()
delete(callId: string): boolean;Defined in: batteries/storage/in_memory/index.ts:192
Removes the entry under callId.
Parameters
| Parameter | Type | Description |
|---|---|---|
callId | string | Identifier whose entry should be removed. |
Returns
boolean
true if an entry existed and was removed; false otherwise.
Implementation of
SpoolStore.delete;read()
read(callId: string): InMemorySpoolReader | undefined;Defined in: batteries/storage/in_memory/index.ts:180
Returns a reader over the bytes previously written under callId, or undefined if the entry has not been written or has been deleted.
Parameters
| Parameter | Type | Description |
|---|---|---|
callId | string | Identifier supplied to a prior InMemorySpoolStore.write call. |
Returns
InMemorySpoolReader | undefined
A fresh InMemorySpoolReader bound to the stored bytes, or undefined.
Implementation of
SpoolStore.read;write()
Call Signature
write(callId: string, bytes: string): InMemorySpoolReader;Defined in: batteries/storage/in_memory/index.ts:151
Persists bytes under callId and returns a reader over them.
Parameters
| Parameter | Type | Description |
|---|---|---|
callId | string | Identifier used to retrieve the bytes via InMemorySpoolStore.read. |
bytes | string | The bytes to store, as a string, Uint8Array, or ReadableStream<Uint8Array>. |
Returns
A fresh InMemorySpoolReader bound to the stored bytes — a Promise for stream input, synchronous otherwise.
Remarks
string input is encoded as UTF-8; Uint8Array is stored byte-faithfully; ReadableStream<Uint8Array> is drained fully (and write returns a Promise). Re-writing the same callId replaces the prior entry; readers handed out before the rewrite continue to view the old bytes (they hold their own snapshot via the InMemorySpoolReader constructor).
Implementation of
SpoolStore.write;Call Signature
write(callId: string, bytes: Uint8Array): InMemorySpoolReader;Defined in: batteries/storage/in_memory/index.ts:152
Persists bytes under callId and returns a reader over them.
Parameters
| Parameter | Type | Description |
|---|---|---|
callId | string | Identifier used to retrieve the bytes via InMemorySpoolStore.read. |
bytes | Uint8Array | The bytes to store, as a string, Uint8Array, or ReadableStream<Uint8Array>. |
Returns
A fresh InMemorySpoolReader bound to the stored bytes — a Promise for stream input, synchronous otherwise.
Remarks
string input is encoded as UTF-8; Uint8Array is stored byte-faithfully; ReadableStream<Uint8Array> is drained fully (and write returns a Promise). Re-writing the same callId replaces the prior entry; readers handed out before the rewrite continue to view the old bytes (they hold their own snapshot via the InMemorySpoolReader constructor).
Implementation of
SpoolStore.write;Call Signature
write(callId: string, bytes: ReadableStream<Uint8Array<ArrayBufferLike>>): Promise<InMemorySpoolReader>;Defined in: batteries/storage/in_memory/index.ts:153
Persists bytes under callId and returns a reader over them.
Parameters
| Parameter | Type | Description |
|---|---|---|
callId | string | Identifier used to retrieve the bytes via InMemorySpoolStore.read. |
bytes | ReadableStream<Uint8Array<ArrayBufferLike>> | The bytes to store, as a string, Uint8Array, or ReadableStream<Uint8Array>. |
Returns
Promise<InMemorySpoolReader>
A fresh InMemorySpoolReader bound to the stored bytes — a Promise for stream input, synchronous otherwise.
Remarks
string input is encoded as UTF-8; Uint8Array is stored byte-faithfully; ReadableStream<Uint8Array> is drained fully (and write returns a Promise). Re-writing the same callId replaces the prior entry; readers handed out before the rewrite continue to view the old bytes (they hold their own snapshot via the InMemorySpoolReader constructor).
Implementation of
SpoolStore.write;Call Signature
write(callId: string, bytes:
| string
| Uint8Array<ArrayBufferLike>
| ReadableStream<Uint8Array<ArrayBufferLike>>):
| InMemorySpoolReader
| Promise<InMemorySpoolReader>;Defined in: batteries/storage/in_memory/index.ts:154
Persists bytes under callId and returns a reader over them.
Parameters
| Parameter | Type | Description |
|---|---|---|
callId | string | Identifier used to retrieve the bytes via InMemorySpoolStore.read. |
bytes | | string | Uint8Array<ArrayBufferLike> | ReadableStream<Uint8Array<ArrayBufferLike>> | The bytes to store, as a string, Uint8Array, or ReadableStream<Uint8Array>. |
Returns
| InMemorySpoolReader | Promise<InMemorySpoolReader>
A fresh InMemorySpoolReader bound to the stored bytes — a Promise for stream input, synchronous otherwise.
Remarks
string input is encoded as UTF-8; Uint8Array is stored byte-faithfully; ReadableStream<Uint8Array> is drained fully (and write returns a Promise). Re-writing the same callId replaces the prior entry; readers handed out before the rewrite continue to view the old bytes (they hold their own snapshot via the InMemorySpoolReader constructor).
Implementation of
SpoolStore.write;