Skip to content

Collection

Defined in: src/main/collection.ts:20

A named group of downloadable items sharing one policy. Get it with library.collection(name). Every method waits for library.ready first.

Type Parameter Default type
M unknown
readonly name: string;

Defined in: src/main/collection.ts:22

Collection name from the config.

get config(): Readonly<ResolvedCollectionConfig>;

Defined in: src/main/collection.ts:32

The resolved policy (defaults filled in).

Readonly<ResolvedCollectionConfig>

arrayBuffer(id, url?): Promise<ArrayBuffer | undefined>;

Defined in: src/main/collection.ts:190

The stored file as an ArrayBuffer (default: the first file), or undefined.

Parameter Type
id string
url? string

Promise<ArrayBuffer | undefined>


blob(id, url?): Promise<Blob | undefined>;

Defined in: src/main/collection.ts:180

The stored file as a Blob (default: the first file), or undefined. For OPFS this is a disk-backed File.

Parameter Type
id string
url? string

Promise<Blob | undefined>


bytes(id, url?): Promise<Uint8Array<ArrayBufferLike> | undefined>;

Defined in: src/main/collection.ts:205

The stored file as a Uint8Array (default: the first file), or undefined. This is the shape model runtimes take: ort.InferenceSession.create(await models.bytes('encoder')).

For items kept in memory (storage: 'memory') this returns the buffer the download filled, without a copy. Treat it as read-only.

Parameter Type
id string
url? string

Promise<Uint8Array<ArrayBufferLike> | undefined>


cancel(id): Promise<void>;

Defined in: src/main/collection.ts:134

Cancel a download in progress (or remove a paused/failed one). The item is removed.

Parameter Type
id string

Promise<void>


clear(): Promise<void>;

Defined in: src/main/collection.ts:159

Delete every item in the collection.

Promise<void>


delete(id): Promise<boolean>;

Defined in: src/main/collection.ts:154

Delete an item and its stored files. Resolves false if it did not exist.

Parameter Type
id string

Promise<boolean>


done(id): Promise<OfflibraryItem<M>>;

Defined in: src/main/collection.ts:105

Resolves with the item when it is completed; rejects with an OfflibraryError when it fails, is cancelled, deleted or evicted.

Parameter Type
id string

Promise<OfflibraryItem<M>>


download(item): Promise<OfflibraryItem<M>>;

Defined in: src/main/collection.ts:51

Start (or continue) downloading an item. Resolves once the download has started, with the item’s current state. Use events or Collection.done to learn when it completes.

  • Already completed with the same version and URLs: no-op (marks it as recently used).
  • Paused or failed: resumes.
  • Different version or URLs: downloads again and replaces the stored copy.

Throws invalid-item, limit-exceeded or quota-exceeded before anything starts.

Parameter Type
item ItemInput<M>

Promise<OfflibraryItem<M>>


downloadAll(items): Promise<PromiseSettledResult<OfflibraryItem<M>>[]>;

Defined in: src/main/collection.ts:56

Download several items. Failing items reject individually; see the returned settled results.

Parameter Type
items ItemInput<M>[]

Promise<PromiseSettledResult<OfflibraryItem<M>>[]>


get(id): Promise<
| OfflibraryItem<M>
| undefined>;

Defined in: src/main/collection.ts:61

Current state of an item, or undefined if it is not in the library.

Parameter Type
id string

Promise< | OfflibraryItem<M> | undefined>


has(id): Promise<boolean>;

Defined in: src/main/collection.ts:97

Whether the item is fully downloaded and available offline.

Parameter Type
id string

Promise<boolean>


list(): Promise<readonly OfflibraryItem<M>[]>;

Defined in: src/main/collection.ts:73

All items in the collection, oldest first.

Promise<readonly OfflibraryItem<M>[]>


match(id, url?): Promise<Response | undefined>;

Defined in: src/main/collection.ts:172

The stored response for one of the item’s files (default: the first), or undefined. Works for every storage kind (cache, opfs, memory).

Parameter Type
id string
url? string

Promise<Response | undefined>


pause(id): Promise<OfflibraryItem<M>>;

Defined in: src/main/collection.ts:139

Pause a fetch-transport download, keeping received bytes. Background Fetch downloads throw not-supported.

Parameter Type
id string

Promise<OfflibraryItem<M>>


peek(id):
| OfflibraryItem<M>
| undefined;

Defined in: src/main/collection.ts:67

Synchronous version of Collection.get (valid after library.ready).

Parameter Type
id string

| OfflibraryItem<M> | undefined


resume(id): Promise<OfflibraryItem<M>>;

Defined in: src/main/collection.ts:144

Resume a paused or failed download.

Parameter Type
id string

Promise<OfflibraryItem<M>>


retry(id): Promise<OfflibraryItem<M>>;

Defined in: src/main/collection.ts:149

Retry a failed download (same as Collection.resume).

Parameter Type
id string

Promise<OfflibraryItem<M>>


snapshot(): readonly OfflibraryItem<M>[];

Defined in: src/main/collection.ts:82

Synchronous, referentially stable list of items. A new array is created only when something in this collection changes, so it can be used directly as a useSyncExternalStore snapshot.

readonly OfflibraryItem<M>[]


subscribe(listener): () => void;

Defined in: src/main/collection.ts:90

Call listener whenever an item in this collection changes. Returns an unsubscribe function. Pair with Collection.snapshot for useSyncExternalStore, signals or stores.

Parameter Type
listener (detail) => void

() => void


sync(items, options?): Promise<(
| OfflibraryItem<M>
| undefined)[]>;

Defined in: src/main/collection.ts:225

Reconcile with your source of truth (a feed, an API response). Updates titles/meta of known items and, with prune: true, deletes stored items whose id is not in items (pinned items are kept). Returns the current state for each input (or undefined when it isn’t downloaded).

Parameter Type
items Pick<ItemInput<M>, "id" | "title" | "meta">[]
options? { prune?: boolean; }
options.prune? boolean

Promise<( | OfflibraryItem<M> | undefined)[]>


touch(id): Promise<OfflibraryItem<M>>;

Defined in: src/main/collection.ts:164

Mark an item as recently used (protects it from LRU eviction). Done automatically when the SW serves it.

Parameter Type
id string

Promise<OfflibraryItem<M>>


usage(): Promise<CollectionUsage>;

Defined in: src/main/collection.ts:215

Completed items and their bytes.

Promise<CollectionUsage>