Skip to content
2 min read · 371 words

Class: InMemorySpoolStore

In-memory "give bytes, get a reader" persistence layer keyed by callId.

Remarks

Stores the canonical UTF-8 string form of each value. Uint8Array inputs are decoded via TextDecoder once at write time — subsequent read() calls return a reader over the cached string with no further decoding.

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.

Example

ts
const store = new InMemorySpoolStore();
const bytes = await tool.executor(ctx)(args);
const reader = store.write(callId, bytes);
const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact;
const artifact = new Ctor(reader);

Constructors

Constructor

ts
new InMemorySpoolStore(): InMemorySpoolStore;

Returns

InMemorySpoolStore

Accessors

size

Get Signature

ts
get size(): number;

Returns the number of entries currently in the store.

Returns

number

Methods

clear()

ts
clear(): void;

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()

ts
delete(callId: string): boolean;

Removes the entry under callId.

Parameters

ParameterTypeDescription
callIdstringIdentifier whose entry should be removed.

Returns

boolean

true if an entry existed and was removed; false otherwise.


read()

ts
read(callId: string): InMemorySpoolReader | undefined;

Returns a reader over the bytes previously written under callId, or undefined if the entry has not been written or has been deleted.

Parameters

ParameterTypeDescription
callIdstringIdentifier supplied to a prior InMemorySpoolStore.write call.

Returns

InMemorySpoolReader | undefined

A fresh InMemorySpoolReader bound to the stored bytes, or undefined.


write()

ts
write(callId: string, bytes: string | Uint8Array<ArrayBufferLike>): InMemorySpoolReader;

Persists bytes under callId and returns a reader over them.

Parameters

ParameterTypeDescription
callIdstringIdentifier used to retrieve the bytes via InMemorySpoolStore.read.
bytesstring | Uint8Array<ArrayBufferLike>The bytes to store, as a string or Uint8Array.

Returns

InMemorySpoolReader

A fresh InMemorySpoolReader bound to the stored bytes.

Remarks

Uint8Array inputs are decoded as UTF-8. 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).