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 Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
M |
unknown |
Properties
Section titled “Properties”readonly name: string;Defined in: src/main/collection.ts:22
Collection name from the config.
Accessors
Section titled “Accessors”config
Section titled “config”Get Signature
Section titled “Get Signature”get config(): Readonly<ResolvedCollectionConfig>;Defined in: src/main/collection.ts:32
The resolved policy (defaults filled in).
Returns
Section titled “Returns”Readonly<ResolvedCollectionConfig>
Methods
Section titled “Methods”arrayBuffer()
Section titled “arrayBuffer()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
url? |
string |
Returns
Section titled “Returns”Promise<ArrayBuffer | undefined>
blob()
Section titled “blob()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
url? |
string |
Returns
Section titled “Returns”Promise<Blob | undefined>
bytes()
Section titled “bytes()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
url? |
string |
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBufferLike> | undefined>
cancel()
Section titled “cancel()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<void>
clear()
Section titled “clear()”clear(): Promise<void>;Defined in: src/main/collection.ts:159
Delete every item in the collection.
Returns
Section titled “Returns”Promise<void>
delete()
Section titled “delete()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<boolean>
done()
Section titled “done()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<OfflibraryItem<M>>
download()
Section titled “download()”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
versionand URLs: no-op (marks it as recently used). - Paused or failed: resumes.
- Different
versionor URLs: downloads again and replaces the stored copy.
Throws invalid-item, limit-exceeded or quota-exceeded before anything starts.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
item |
ItemInput<M> |
Returns
Section titled “Returns”Promise<OfflibraryItem<M>>
downloadAll()
Section titled “downloadAll()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
items |
ItemInput<M>[] |
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<
| OfflibraryItem<M>
| undefined>
has(id): Promise<boolean>;Defined in: src/main/collection.ts:97
Whether the item is fully downloaded and available offline.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<boolean>
list()
Section titled “list()”list(): Promise<readonly OfflibraryItem<M>[]>;Defined in: src/main/collection.ts:73
All items in the collection, oldest first.
Returns
Section titled “Returns”Promise<readonly OfflibraryItem<M>[]>
match()
Section titled “match()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
url? |
string |
Returns
Section titled “Returns”Promise<Response | undefined>
pause()
Section titled “pause()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<OfflibraryItem<M>>
peek()
Section titled “peek()”peek(id): | OfflibraryItem<M> | undefined;Defined in: src/main/collection.ts:67
Synchronous version of Collection.get (valid after library.ready).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”| OfflibraryItem<M>
| undefined
resume()
Section titled “resume()”resume(id): Promise<OfflibraryItem<M>>;Defined in: src/main/collection.ts:144
Resume a paused or failed download.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<OfflibraryItem<M>>
retry()
Section titled “retry()”retry(id): Promise<OfflibraryItem<M>>;Defined in: src/main/collection.ts:149
Retry a failed download (same as Collection.resume).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<OfflibraryItem<M>>
snapshot()
Section titled “snapshot()”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.
Returns
Section titled “Returns”readonly OfflibraryItem<M>[]
subscribe()
Section titled “subscribe()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
listener |
(detail) => void |
Returns
Section titled “Returns”() => void
sync()
Section titled “sync()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
items |
Pick<ItemInput<M>, "id" | "title" | "meta">[] |
options? |
{ prune?: boolean; } |
options.prune? |
boolean |
Returns
Section titled “Returns”Promise<(
| OfflibraryItem<M>
| undefined)[]>
touch()
Section titled “touch()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Promise<OfflibraryItem<M>>
usage()
Section titled “usage()”usage(): Promise<CollectionUsage>;Defined in: src/main/collection.ts:215
Completed items and their bytes.
Returns
Section titled “Returns”Promise<CollectionUsage>