@contello/store 2.0.1 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -114,7 +114,8 @@ type SourceAt<TSchema, TKey> = TSchema extends {
114
114
  } ? TKey extends keyof TSources ? TSources[TKey] : never : never;
115
115
  /**
116
116
  * For `define*(arg, options?)` — accepts either a string key (looked up in `schema.sources`) or a SourceDef directly.
117
- * `ResolveSource` projects the argument to the underlying SourceDef so `ExtractSourceResult` can extract the fragment type.
117
+ * `ResolveSource` projects the argument to the underlying SourceDef so `ExtractSourceResult`
118
+ * can extract the fragment type.
118
119
  */
119
120
  type ResolveSource<TSchema, T> = T extends string ? SourceAt<TSchema, T> : T extends SourceDef<any, any, any> ? T : never;
120
121
  type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
@@ -128,10 +129,30 @@ type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
128
129
  onError?: ((error: unknown) => void) | undefined;
129
130
  connectionEvents?: ConnectionEvents | undefined;
130
131
  };
132
+ /**
133
+ * What triggered a refresh:
134
+ * - `'upstream-update'` — watcher event from the server (partial refresh on collection,
135
+ * full on singleton / i18n, cache eviction on lazy stores).
136
+ * - `'ttl'` — periodic safety-net timer fired.
137
+ * - `'on-demand'` — consumer called `instance.refresh()`.
138
+ */
139
+ type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand';
140
+ /** Refresh event shape for stores keyed by id (collection, lazy-collection, routes, assets, i18n). */
141
+ type RefreshEvent = {
142
+ ids: string[];
143
+ kind: RefreshKind;
144
+ };
145
+ /** Refresh event shape for stores with no id concept (singleton). */
146
+ type SingletonRefreshEvent = {
147
+ kind: RefreshKind;
148
+ };
131
149
  /** Cache options for non-lazy collections and singletons. */
132
150
  type CacheOptions = {
133
- /** If set, the cache is refreshed automatically this many ms after each completed fetch. */
134
- ttl?: number | undefined;
151
+ /**
152
+ * Periodic full refresh — guards against stale data from missed update events.
153
+ * Defaults to 3 hours; set `0` or `false` to disable.
154
+ */
155
+ ttl?: number | false | undefined;
135
156
  /**
136
157
  * Controls how the cache responds to Contello update events.
137
158
  * `'refresh'` (default) serves stale data while a partial fetch runs in the background (SWR);
@@ -141,45 +162,54 @@ type CacheOptions = {
141
162
  */
142
163
  eviction?: 'refresh' | 'clear' | undefined;
143
164
  };
144
- /** Cache options for sync collections and singletons. `eviction` is omitted — clearing the cache would break the sync guarantee. */
165
+ /**
166
+ * Cache options for sync collections and singletons. `eviction` is omitted — clearing
167
+ * the cache would break the sync guarantee.
168
+ */
145
169
  type SyncCacheOptions = {
146
- /** If set, the cache is refreshed automatically this many ms after each completed fetch. */
147
- ttl?: number | undefined;
170
+ /**
171
+ * Periodic full refresh — guards against stale data from missed update events.
172
+ * Defaults to 3 hours; set `0` or `false` to disable.
173
+ */
174
+ ttl?: number | false | undefined;
148
175
  };
149
176
  /** Cache options for lazy collections. */
150
177
  type LazyCacheOptions = {
151
178
  /** Maximum number of items kept in the LRU cache. Defaults to 1000. */
152
179
  max?: number | undefined;
153
- /** Items are evicted from the LRU cache after this many ms. */
154
- ttl?: number | undefined;
180
+ /**
181
+ * Per-item LRU eviction — expired items are dropped on next access and
182
+ * re-fetched lazily. Defaults to 3 hours; set `0` or `false` to disable.
183
+ */
184
+ ttl?: number | false | undefined;
155
185
  };
156
186
  type SingletonOptions<TRaw, TMapped, TModels extends string = string> = {
157
187
  name?: string | undefined;
158
188
  map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
159
189
  cache?: CacheOptions | undefined;
160
190
  onLoad?: (() => void) | undefined;
161
- onRefresh?: (() => void) | undefined;
191
+ onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
162
192
  };
163
193
  type SingletonSyncOptions<TRaw, TMapped, TModels extends string = string> = {
164
194
  name?: string | undefined;
165
195
  map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
166
196
  cache?: SyncCacheOptions | undefined;
167
197
  onLoad?: (() => void) | undefined;
168
- onRefresh?: (() => void) | undefined;
198
+ onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
169
199
  };
170
200
  type Loadable = {
171
201
  load(): Promise<void>;
172
202
  };
173
203
  type Singleton<T> = {
174
204
  readonly name: string;
175
- readonly refresh$: AsyncIterable<void>;
205
+ readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
176
206
  load(): Promise<void>;
177
207
  get(): MaybePromise<ReadonlyDeep<T>>;
178
208
  refresh(): void;
179
209
  };
180
210
  type SingletonSync<T> = {
181
211
  readonly name: string;
182
- readonly refresh$: AsyncIterable<void>;
212
+ readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
183
213
  load(): Promise<void>;
184
214
  get(): ReadonlyDeep<T>;
185
215
  refresh(): void;
@@ -192,7 +222,7 @@ type CollectionOptions<TRaw, TMapped extends {
192
222
  sort?: ((a: TMapped, b: TMapped) => number) | undefined;
193
223
  cache?: CacheOptions | undefined;
194
224
  onLoad?: ((ids: string[]) => void) | undefined;
195
- onRefresh?: ((ids: string[]) => void) | undefined;
225
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
196
226
  };
197
227
  type CollectionSyncOptions<TRaw, TMapped extends {
198
228
  id: string;
@@ -202,23 +232,23 @@ type CollectionSyncOptions<TRaw, TMapped extends {
202
232
  sort?: ((a: TMapped, b: TMapped) => number) | undefined;
203
233
  cache?: SyncCacheOptions | undefined;
204
234
  onLoad?: ((ids: string[]) => void) | undefined;
205
- onRefresh?: ((ids: string[]) => void) | undefined;
235
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
206
236
  };
207
237
  type Collection<T> = {
208
238
  readonly name: string;
209
- readonly refresh$: AsyncIterable<string[]>;
239
+ readonly refresh$: AsyncIterable<RefreshEvent>;
210
240
  load(): Promise<void>;
211
241
  get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
212
- get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
242
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
213
243
  getAll(): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
214
244
  refresh(): void;
215
245
  };
216
246
  type CollectionSync<T> = {
217
247
  readonly name: string;
218
- readonly refresh$: AsyncIterable<string[]>;
248
+ readonly refresh$: AsyncIterable<RefreshEvent>;
219
249
  load(): Promise<void>;
220
250
  get(id: string): ReadonlyDeep<T> | undefined;
221
- get(ids: string[]): ReadonlyArray<ReadonlyDeep<T>>;
251
+ get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<T>>;
222
252
  getAll(): ReadonlyArray<ReadonlyDeep<T>>;
223
253
  refresh(): void;
224
254
  };
@@ -228,13 +258,13 @@ type LazyCollectionOptions<TRaw, TMapped extends {
228
258
  name?: string | undefined;
229
259
  cache?: LazyCacheOptions | undefined;
230
260
  map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
231
- onRefresh?: ((ids: string[]) => void) | undefined;
261
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
232
262
  };
233
263
  type LazyCollection<T> = {
234
264
  readonly name: string;
235
- readonly refresh$: AsyncIterable<string[]>;
265
+ readonly refresh$: AsyncIterable<RefreshEvent>;
236
266
  get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
237
- get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
267
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
238
268
  refresh(): void;
239
269
  clear(): void;
240
270
  };
@@ -254,13 +284,14 @@ type StoreAsset = {
254
284
  preview: StoreFile | undefined;
255
285
  optimized: StoreFile[];
256
286
  };
257
- type AssetCollectionOptions = {
287
+ type LazyAssetsOptions = {
258
288
  cache?: LazyCacheOptions | undefined;
289
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
259
290
  };
260
- type Assets = {
261
- readonly refresh$: AsyncIterable<string[]>;
291
+ type LazyAssets = {
292
+ readonly refresh$: AsyncIterable<RefreshEvent>;
262
293
  get(id: string): Promise<ReadonlyDeep<StoreAsset> | undefined>;
263
- get(ids: string[]): Promise<ReadonlyDeep<StoreAsset[]>>;
294
+ get(ids: readonly string[]): Promise<ReadonlyDeep<StoreAsset[]>>;
264
295
  upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
265
296
  download(fileId: string): Promise<DownloadResult>;
266
297
  proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
@@ -268,6 +299,37 @@ type Assets = {
268
299
  clear(): void;
269
300
  };
270
301
 
302
+ type AssetsOptions = {
303
+ cache?: CacheOptions | undefined;
304
+ onLoad?: ((ids: string[]) => void) | undefined;
305
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
306
+ };
307
+ type AssetsSyncOptions = {
308
+ cache?: SyncCacheOptions | undefined;
309
+ onLoad?: ((ids: string[]) => void) | undefined;
310
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
311
+ };
312
+ type Assets = {
313
+ readonly refresh$: AsyncIterable<RefreshEvent>;
314
+ load(): Promise<void>;
315
+ get(id: string): MaybePromise<ReadonlyDeep<StoreAsset> | undefined>;
316
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreAsset>>>;
317
+ upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
318
+ download(fileId: string): Promise<DownloadResult>;
319
+ proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
320
+ refresh(): void;
321
+ };
322
+ type AssetsSync = {
323
+ readonly refresh$: AsyncIterable<RefreshEvent>;
324
+ load(): Promise<void>;
325
+ get(id: string): ReadonlyDeep<StoreAsset> | undefined;
326
+ get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreAsset>>;
327
+ upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
328
+ download(fileId: string): Promise<DownloadResult>;
329
+ proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
330
+ refresh(): void;
331
+ };
332
+
271
333
  type I18nTranslation = {
272
334
  language: string;
273
335
  value: string;
@@ -293,6 +355,8 @@ type I18nMessageRegistrationDefinition = {
293
355
  };
294
356
  type I18nMessageDef = {
295
357
  collection: string;
358
+ cache?: SyncCacheOptions | undefined;
359
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
296
360
  };
297
361
  type I18nMessage = {
298
362
  id: string;
@@ -300,28 +364,59 @@ type I18nMessage = {
300
364
  translations: Map<string, string>;
301
365
  };
302
366
  type I18nMessages = {
303
- readonly refresh$: AsyncIterable<string[]>;
367
+ readonly refresh$: AsyncIterable<RefreshEvent>;
304
368
  get(id: string): MaybePromise<ReadonlyDeep<I18nMessage> | undefined>;
305
- get(ids: string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
369
+ get(ids: readonly string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
306
370
  getAll(): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
307
371
  register(messages: I18nMessageRegistrationDefinition[]): Promise<void>;
372
+ refresh(): void;
308
373
  /** Completes refresh$ and detaches from the watcher — called by `Store.destroy()`. */
309
374
  destroy(): void;
310
375
  };
311
376
 
312
- type RouteCollectionOptions = {
377
+ type LazyRoutesOptions = {
313
378
  cache?: LazyCacheOptions | undefined;
379
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
314
380
  };
315
- type Routes = {
316
- readonly refresh$: AsyncIterable<string[]>;
381
+ type LazyRoutes = {
382
+ readonly refresh$: AsyncIterable<RefreshEvent>;
317
383
  get(id: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
318
- get(ids: string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
384
+ get(ids: readonly string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
319
385
  getByPath(path: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
320
- getByPath(paths: string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
386
+ getByPath(paths: readonly string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
321
387
  refresh(): void;
322
388
  clear(): void;
323
389
  };
324
390
 
391
+ type RoutesOptions = {
392
+ cache?: CacheOptions | undefined;
393
+ onLoad?: ((ids: string[]) => void) | undefined;
394
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
395
+ };
396
+ type RoutesSyncOptions = {
397
+ cache?: SyncCacheOptions | undefined;
398
+ onLoad?: ((ids: string[]) => void) | undefined;
399
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
400
+ };
401
+ type Routes = {
402
+ readonly refresh$: AsyncIterable<RefreshEvent>;
403
+ load(): Promise<void>;
404
+ get(id: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
405
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
406
+ getByPath(path: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
407
+ getByPath(paths: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
408
+ refresh(): void;
409
+ };
410
+ type RoutesSync = {
411
+ readonly refresh$: AsyncIterable<RefreshEvent>;
412
+ load(): Promise<void>;
413
+ get(id: string): ReadonlyDeep<StoreRoute> | undefined;
414
+ get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
415
+ getByPath(path: string): ReadonlyDeep<StoreRoute> | undefined;
416
+ getByPath(paths: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
417
+ refresh(): void;
418
+ };
419
+
325
420
  /** Project the model-reference-name union out of a Schema generic, falling back to `string`. */
326
421
  type ModelsOf<TSchema> = TSchema extends {
327
422
  models: infer M;
@@ -336,6 +431,7 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
336
431
  private _watcher;
337
432
  private _schema;
338
433
  private _cleanups;
434
+ private _refreshByTtl;
339
435
  /**
340
436
  * Multicast update-batch stream from the watcher. Consume with `for await (const batch of updates$)`;
341
437
  * each iteration starts an independent fan-out from the shared source.
@@ -364,11 +460,15 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
364
460
  } = CollectionRaw<TSchema, TArg> & {
365
461
  id: string;
366
462
  }>(sourceOrKey: TArg, options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): LazyCollection<TMapped>;
367
- defineAssets(options?: AssetCollectionOptions | undefined): Assets;
368
- defineRoutes(options?: RouteCollectionOptions | undefined): Routes;
463
+ defineAssets(options?: AssetsOptions | undefined): Assets;
464
+ defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync;
465
+ defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets;
466
+ defineRoutes(options?: RoutesOptions | undefined): Routes;
467
+ defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync;
468
+ defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes;
369
469
  defineI18nMessages(def: I18nMessageDef): I18nMessages;
370
470
  ping: () => Promise<void>;
371
471
  }
372
472
  declare function createStore<TSchema extends Schema | undefined = undefined>(options: CreateStoreOptions<TSchema>): Store<TSchema>;
373
473
 
374
- export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionOptions, type CollectionSync, type CollectionSyncOptions, type CreateStoreOptions, type ExtractSourceResult, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionOptions, type Loadable, type MapperContext, type ResolveSource, type RouteCollectionOptions, type Routes, type Singleton, type SingletonOptions, type SingletonSync, type SingletonSyncOptions, type SourceAt, type SourceKeysOf, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
474
+ export { type Assets, type AssetsOptions, type AssetsSync, type AssetsSyncOptions, type CacheOptions, type Collection, type CollectionOptions, type CollectionSync, type CollectionSyncOptions, type CreateStoreOptions, type ExtractSourceResult, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyAssets, type LazyAssetsOptions, type LazyCacheOptions, type LazyCollection, type LazyCollectionOptions, type LazyRoutes, type LazyRoutesOptions, type Loadable, type MapperContext, type ResolveSource, type Routes, type RoutesOptions, type RoutesSync, type RoutesSyncOptions, type Singleton, type SingletonOptions, type SingletonSync, type SingletonSyncOptions, type SourceAt, type SourceKeysOf, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
package/dist/index.d.ts CHANGED
@@ -114,7 +114,8 @@ type SourceAt<TSchema, TKey> = TSchema extends {
114
114
  } ? TKey extends keyof TSources ? TSources[TKey] : never : never;
115
115
  /**
116
116
  * For `define*(arg, options?)` — accepts either a string key (looked up in `schema.sources`) or a SourceDef directly.
117
- * `ResolveSource` projects the argument to the underlying SourceDef so `ExtractSourceResult` can extract the fragment type.
117
+ * `ResolveSource` projects the argument to the underlying SourceDef so `ExtractSourceResult`
118
+ * can extract the fragment type.
118
119
  */
119
120
  type ResolveSource<TSchema, T> = T extends string ? SourceAt<TSchema, T> : T extends SourceDef<any, any, any> ? T : never;
120
121
  type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
@@ -128,10 +129,30 @@ type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
128
129
  onError?: ((error: unknown) => void) | undefined;
129
130
  connectionEvents?: ConnectionEvents | undefined;
130
131
  };
132
+ /**
133
+ * What triggered a refresh:
134
+ * - `'upstream-update'` — watcher event from the server (partial refresh on collection,
135
+ * full on singleton / i18n, cache eviction on lazy stores).
136
+ * - `'ttl'` — periodic safety-net timer fired.
137
+ * - `'on-demand'` — consumer called `instance.refresh()`.
138
+ */
139
+ type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand';
140
+ /** Refresh event shape for stores keyed by id (collection, lazy-collection, routes, assets, i18n). */
141
+ type RefreshEvent = {
142
+ ids: string[];
143
+ kind: RefreshKind;
144
+ };
145
+ /** Refresh event shape for stores with no id concept (singleton). */
146
+ type SingletonRefreshEvent = {
147
+ kind: RefreshKind;
148
+ };
131
149
  /** Cache options for non-lazy collections and singletons. */
132
150
  type CacheOptions = {
133
- /** If set, the cache is refreshed automatically this many ms after each completed fetch. */
134
- ttl?: number | undefined;
151
+ /**
152
+ * Periodic full refresh — guards against stale data from missed update events.
153
+ * Defaults to 3 hours; set `0` or `false` to disable.
154
+ */
155
+ ttl?: number | false | undefined;
135
156
  /**
136
157
  * Controls how the cache responds to Contello update events.
137
158
  * `'refresh'` (default) serves stale data while a partial fetch runs in the background (SWR);
@@ -141,45 +162,54 @@ type CacheOptions = {
141
162
  */
142
163
  eviction?: 'refresh' | 'clear' | undefined;
143
164
  };
144
- /** Cache options for sync collections and singletons. `eviction` is omitted — clearing the cache would break the sync guarantee. */
165
+ /**
166
+ * Cache options for sync collections and singletons. `eviction` is omitted — clearing
167
+ * the cache would break the sync guarantee.
168
+ */
145
169
  type SyncCacheOptions = {
146
- /** If set, the cache is refreshed automatically this many ms after each completed fetch. */
147
- ttl?: number | undefined;
170
+ /**
171
+ * Periodic full refresh — guards against stale data from missed update events.
172
+ * Defaults to 3 hours; set `0` or `false` to disable.
173
+ */
174
+ ttl?: number | false | undefined;
148
175
  };
149
176
  /** Cache options for lazy collections. */
150
177
  type LazyCacheOptions = {
151
178
  /** Maximum number of items kept in the LRU cache. Defaults to 1000. */
152
179
  max?: number | undefined;
153
- /** Items are evicted from the LRU cache after this many ms. */
154
- ttl?: number | undefined;
180
+ /**
181
+ * Per-item LRU eviction — expired items are dropped on next access and
182
+ * re-fetched lazily. Defaults to 3 hours; set `0` or `false` to disable.
183
+ */
184
+ ttl?: number | false | undefined;
155
185
  };
156
186
  type SingletonOptions<TRaw, TMapped, TModels extends string = string> = {
157
187
  name?: string | undefined;
158
188
  map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
159
189
  cache?: CacheOptions | undefined;
160
190
  onLoad?: (() => void) | undefined;
161
- onRefresh?: (() => void) | undefined;
191
+ onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
162
192
  };
163
193
  type SingletonSyncOptions<TRaw, TMapped, TModels extends string = string> = {
164
194
  name?: string | undefined;
165
195
  map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
166
196
  cache?: SyncCacheOptions | undefined;
167
197
  onLoad?: (() => void) | undefined;
168
- onRefresh?: (() => void) | undefined;
198
+ onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
169
199
  };
170
200
  type Loadable = {
171
201
  load(): Promise<void>;
172
202
  };
173
203
  type Singleton<T> = {
174
204
  readonly name: string;
175
- readonly refresh$: AsyncIterable<void>;
205
+ readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
176
206
  load(): Promise<void>;
177
207
  get(): MaybePromise<ReadonlyDeep<T>>;
178
208
  refresh(): void;
179
209
  };
180
210
  type SingletonSync<T> = {
181
211
  readonly name: string;
182
- readonly refresh$: AsyncIterable<void>;
212
+ readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
183
213
  load(): Promise<void>;
184
214
  get(): ReadonlyDeep<T>;
185
215
  refresh(): void;
@@ -192,7 +222,7 @@ type CollectionOptions<TRaw, TMapped extends {
192
222
  sort?: ((a: TMapped, b: TMapped) => number) | undefined;
193
223
  cache?: CacheOptions | undefined;
194
224
  onLoad?: ((ids: string[]) => void) | undefined;
195
- onRefresh?: ((ids: string[]) => void) | undefined;
225
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
196
226
  };
197
227
  type CollectionSyncOptions<TRaw, TMapped extends {
198
228
  id: string;
@@ -202,23 +232,23 @@ type CollectionSyncOptions<TRaw, TMapped extends {
202
232
  sort?: ((a: TMapped, b: TMapped) => number) | undefined;
203
233
  cache?: SyncCacheOptions | undefined;
204
234
  onLoad?: ((ids: string[]) => void) | undefined;
205
- onRefresh?: ((ids: string[]) => void) | undefined;
235
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
206
236
  };
207
237
  type Collection<T> = {
208
238
  readonly name: string;
209
- readonly refresh$: AsyncIterable<string[]>;
239
+ readonly refresh$: AsyncIterable<RefreshEvent>;
210
240
  load(): Promise<void>;
211
241
  get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
212
- get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
242
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
213
243
  getAll(): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
214
244
  refresh(): void;
215
245
  };
216
246
  type CollectionSync<T> = {
217
247
  readonly name: string;
218
- readonly refresh$: AsyncIterable<string[]>;
248
+ readonly refresh$: AsyncIterable<RefreshEvent>;
219
249
  load(): Promise<void>;
220
250
  get(id: string): ReadonlyDeep<T> | undefined;
221
- get(ids: string[]): ReadonlyArray<ReadonlyDeep<T>>;
251
+ get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<T>>;
222
252
  getAll(): ReadonlyArray<ReadonlyDeep<T>>;
223
253
  refresh(): void;
224
254
  };
@@ -228,13 +258,13 @@ type LazyCollectionOptions<TRaw, TMapped extends {
228
258
  name?: string | undefined;
229
259
  cache?: LazyCacheOptions | undefined;
230
260
  map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
231
- onRefresh?: ((ids: string[]) => void) | undefined;
261
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
232
262
  };
233
263
  type LazyCollection<T> = {
234
264
  readonly name: string;
235
- readonly refresh$: AsyncIterable<string[]>;
265
+ readonly refresh$: AsyncIterable<RefreshEvent>;
236
266
  get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
237
- get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
267
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
238
268
  refresh(): void;
239
269
  clear(): void;
240
270
  };
@@ -254,13 +284,14 @@ type StoreAsset = {
254
284
  preview: StoreFile | undefined;
255
285
  optimized: StoreFile[];
256
286
  };
257
- type AssetCollectionOptions = {
287
+ type LazyAssetsOptions = {
258
288
  cache?: LazyCacheOptions | undefined;
289
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
259
290
  };
260
- type Assets = {
261
- readonly refresh$: AsyncIterable<string[]>;
291
+ type LazyAssets = {
292
+ readonly refresh$: AsyncIterable<RefreshEvent>;
262
293
  get(id: string): Promise<ReadonlyDeep<StoreAsset> | undefined>;
263
- get(ids: string[]): Promise<ReadonlyDeep<StoreAsset[]>>;
294
+ get(ids: readonly string[]): Promise<ReadonlyDeep<StoreAsset[]>>;
264
295
  upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
265
296
  download(fileId: string): Promise<DownloadResult>;
266
297
  proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
@@ -268,6 +299,37 @@ type Assets = {
268
299
  clear(): void;
269
300
  };
270
301
 
302
+ type AssetsOptions = {
303
+ cache?: CacheOptions | undefined;
304
+ onLoad?: ((ids: string[]) => void) | undefined;
305
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
306
+ };
307
+ type AssetsSyncOptions = {
308
+ cache?: SyncCacheOptions | undefined;
309
+ onLoad?: ((ids: string[]) => void) | undefined;
310
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
311
+ };
312
+ type Assets = {
313
+ readonly refresh$: AsyncIterable<RefreshEvent>;
314
+ load(): Promise<void>;
315
+ get(id: string): MaybePromise<ReadonlyDeep<StoreAsset> | undefined>;
316
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreAsset>>>;
317
+ upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
318
+ download(fileId: string): Promise<DownloadResult>;
319
+ proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
320
+ refresh(): void;
321
+ };
322
+ type AssetsSync = {
323
+ readonly refresh$: AsyncIterable<RefreshEvent>;
324
+ load(): Promise<void>;
325
+ get(id: string): ReadonlyDeep<StoreAsset> | undefined;
326
+ get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreAsset>>;
327
+ upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
328
+ download(fileId: string): Promise<DownloadResult>;
329
+ proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
330
+ refresh(): void;
331
+ };
332
+
271
333
  type I18nTranslation = {
272
334
  language: string;
273
335
  value: string;
@@ -293,6 +355,8 @@ type I18nMessageRegistrationDefinition = {
293
355
  };
294
356
  type I18nMessageDef = {
295
357
  collection: string;
358
+ cache?: SyncCacheOptions | undefined;
359
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
296
360
  };
297
361
  type I18nMessage = {
298
362
  id: string;
@@ -300,28 +364,59 @@ type I18nMessage = {
300
364
  translations: Map<string, string>;
301
365
  };
302
366
  type I18nMessages = {
303
- readonly refresh$: AsyncIterable<string[]>;
367
+ readonly refresh$: AsyncIterable<RefreshEvent>;
304
368
  get(id: string): MaybePromise<ReadonlyDeep<I18nMessage> | undefined>;
305
- get(ids: string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
369
+ get(ids: readonly string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
306
370
  getAll(): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
307
371
  register(messages: I18nMessageRegistrationDefinition[]): Promise<void>;
372
+ refresh(): void;
308
373
  /** Completes refresh$ and detaches from the watcher — called by `Store.destroy()`. */
309
374
  destroy(): void;
310
375
  };
311
376
 
312
- type RouteCollectionOptions = {
377
+ type LazyRoutesOptions = {
313
378
  cache?: LazyCacheOptions | undefined;
379
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
314
380
  };
315
- type Routes = {
316
- readonly refresh$: AsyncIterable<string[]>;
381
+ type LazyRoutes = {
382
+ readonly refresh$: AsyncIterable<RefreshEvent>;
317
383
  get(id: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
318
- get(ids: string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
384
+ get(ids: readonly string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
319
385
  getByPath(path: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
320
- getByPath(paths: string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
386
+ getByPath(paths: readonly string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
321
387
  refresh(): void;
322
388
  clear(): void;
323
389
  };
324
390
 
391
+ type RoutesOptions = {
392
+ cache?: CacheOptions | undefined;
393
+ onLoad?: ((ids: string[]) => void) | undefined;
394
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
395
+ };
396
+ type RoutesSyncOptions = {
397
+ cache?: SyncCacheOptions | undefined;
398
+ onLoad?: ((ids: string[]) => void) | undefined;
399
+ onRefresh?: ((event: RefreshEvent) => void) | undefined;
400
+ };
401
+ type Routes = {
402
+ readonly refresh$: AsyncIterable<RefreshEvent>;
403
+ load(): Promise<void>;
404
+ get(id: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
405
+ get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
406
+ getByPath(path: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
407
+ getByPath(paths: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
408
+ refresh(): void;
409
+ };
410
+ type RoutesSync = {
411
+ readonly refresh$: AsyncIterable<RefreshEvent>;
412
+ load(): Promise<void>;
413
+ get(id: string): ReadonlyDeep<StoreRoute> | undefined;
414
+ get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
415
+ getByPath(path: string): ReadonlyDeep<StoreRoute> | undefined;
416
+ getByPath(paths: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
417
+ refresh(): void;
418
+ };
419
+
325
420
  /** Project the model-reference-name union out of a Schema generic, falling back to `string`. */
326
421
  type ModelsOf<TSchema> = TSchema extends {
327
422
  models: infer M;
@@ -336,6 +431,7 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
336
431
  private _watcher;
337
432
  private _schema;
338
433
  private _cleanups;
434
+ private _refreshByTtl;
339
435
  /**
340
436
  * Multicast update-batch stream from the watcher. Consume with `for await (const batch of updates$)`;
341
437
  * each iteration starts an independent fan-out from the shared source.
@@ -364,11 +460,15 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
364
460
  } = CollectionRaw<TSchema, TArg> & {
365
461
  id: string;
366
462
  }>(sourceOrKey: TArg, options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): LazyCollection<TMapped>;
367
- defineAssets(options?: AssetCollectionOptions | undefined): Assets;
368
- defineRoutes(options?: RouteCollectionOptions | undefined): Routes;
463
+ defineAssets(options?: AssetsOptions | undefined): Assets;
464
+ defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync;
465
+ defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets;
466
+ defineRoutes(options?: RoutesOptions | undefined): Routes;
467
+ defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync;
468
+ defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes;
369
469
  defineI18nMessages(def: I18nMessageDef): I18nMessages;
370
470
  ping: () => Promise<void>;
371
471
  }
372
472
  declare function createStore<TSchema extends Schema | undefined = undefined>(options: CreateStoreOptions<TSchema>): Store<TSchema>;
373
473
 
374
- export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionOptions, type CollectionSync, type CollectionSyncOptions, type CreateStoreOptions, type ExtractSourceResult, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionOptions, type Loadable, type MapperContext, type ResolveSource, type RouteCollectionOptions, type Routes, type Singleton, type SingletonOptions, type SingletonSync, type SingletonSyncOptions, type SourceAt, type SourceKeysOf, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };
474
+ export { type Assets, type AssetsOptions, type AssetsSync, type AssetsSyncOptions, type CacheOptions, type Collection, type CollectionOptions, type CollectionSync, type CollectionSyncOptions, type CreateStoreOptions, type ExtractSourceResult, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyAssets, type LazyAssetsOptions, type LazyCacheOptions, type LazyCollection, type LazyCollectionOptions, type LazyRoutes, type LazyRoutesOptions, type Loadable, type MapperContext, type ResolveSource, type Routes, type RoutesOptions, type RoutesSync, type RoutesSyncOptions, type Singleton, type SingletonOptions, type SingletonSync, type SingletonSyncOptions, type SourceAt, type SourceKeysOf, Store, type StoreAsset, type StoreFile, type StoreFileMetadata, type StoreRoute, type StoreRouteCustomHeader, type SyncCacheOptions, type UpdateBatch, type UpdateEvent, type UpdateEventFor, type UpdateMutationType, createStore };