@contello/store 2.0.0 → 2.1.0
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.cjs +828 -293
- package/dist/index.d.cts +122 -26
- package/dist/index.d.ts +122 -26
- package/dist/index.js +860 -309
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -128,10 +128,30 @@ type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
|
|
|
128
128
|
onError?: ((error: unknown) => void) | undefined;
|
|
129
129
|
connectionEvents?: ConnectionEvents | undefined;
|
|
130
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* What triggered a refresh:
|
|
133
|
+
* - `'upstream-update'` — watcher event from the server (partial refresh on collection,
|
|
134
|
+
* full on singleton / i18n, cache eviction on lazy stores).
|
|
135
|
+
* - `'ttl'` — periodic safety-net timer fired.
|
|
136
|
+
* - `'on-demand'` — consumer called `instance.refresh()`.
|
|
137
|
+
*/
|
|
138
|
+
type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand';
|
|
139
|
+
/** Refresh event shape for stores keyed by id (collection, lazy-collection, routes, assets, i18n). */
|
|
140
|
+
type RefreshEvent = {
|
|
141
|
+
ids: string[];
|
|
142
|
+
kind: RefreshKind;
|
|
143
|
+
};
|
|
144
|
+
/** Refresh event shape for stores with no id concept (singleton). */
|
|
145
|
+
type SingletonRefreshEvent = {
|
|
146
|
+
kind: RefreshKind;
|
|
147
|
+
};
|
|
131
148
|
/** Cache options for non-lazy collections and singletons. */
|
|
132
149
|
type CacheOptions = {
|
|
133
|
-
/**
|
|
134
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Periodic full refresh — guards against stale data from missed update events.
|
|
152
|
+
* Defaults to 3 hours; set `0` or `false` to disable.
|
|
153
|
+
*/
|
|
154
|
+
ttl?: number | false | undefined;
|
|
135
155
|
/**
|
|
136
156
|
* Controls how the cache responds to Contello update events.
|
|
137
157
|
* `'refresh'` (default) serves stale data while a partial fetch runs in the background (SWR);
|
|
@@ -143,43 +163,49 @@ type CacheOptions = {
|
|
|
143
163
|
};
|
|
144
164
|
/** Cache options for sync collections and singletons. `eviction` is omitted — clearing the cache would break the sync guarantee. */
|
|
145
165
|
type SyncCacheOptions = {
|
|
146
|
-
/**
|
|
147
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Periodic full refresh — guards against stale data from missed update events.
|
|
168
|
+
* Defaults to 3 hours; set `0` or `false` to disable.
|
|
169
|
+
*/
|
|
170
|
+
ttl?: number | false | undefined;
|
|
148
171
|
};
|
|
149
172
|
/** Cache options for lazy collections. */
|
|
150
173
|
type LazyCacheOptions = {
|
|
151
174
|
/** Maximum number of items kept in the LRU cache. Defaults to 1000. */
|
|
152
175
|
max?: number | undefined;
|
|
153
|
-
/**
|
|
154
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Per-item LRU eviction — expired items are dropped on next access and
|
|
178
|
+
* re-fetched lazily. Defaults to 3 hours; set `0` or `false` to disable.
|
|
179
|
+
*/
|
|
180
|
+
ttl?: number | false | undefined;
|
|
155
181
|
};
|
|
156
182
|
type SingletonOptions<TRaw, TMapped, TModels extends string = string> = {
|
|
157
183
|
name?: string | undefined;
|
|
158
184
|
map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
|
|
159
185
|
cache?: CacheOptions | undefined;
|
|
160
186
|
onLoad?: (() => void) | undefined;
|
|
161
|
-
onRefresh?: (() => void) | undefined;
|
|
187
|
+
onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
|
|
162
188
|
};
|
|
163
189
|
type SingletonSyncOptions<TRaw, TMapped, TModels extends string = string> = {
|
|
164
190
|
name?: string | undefined;
|
|
165
191
|
map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
|
|
166
192
|
cache?: SyncCacheOptions | undefined;
|
|
167
193
|
onLoad?: (() => void) | undefined;
|
|
168
|
-
onRefresh?: (() => void) | undefined;
|
|
194
|
+
onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
|
|
169
195
|
};
|
|
170
196
|
type Loadable = {
|
|
171
197
|
load(): Promise<void>;
|
|
172
198
|
};
|
|
173
199
|
type Singleton<T> = {
|
|
174
200
|
readonly name: string;
|
|
175
|
-
readonly refresh$: AsyncIterable<
|
|
201
|
+
readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
|
|
176
202
|
load(): Promise<void>;
|
|
177
203
|
get(): MaybePromise<ReadonlyDeep<T>>;
|
|
178
204
|
refresh(): void;
|
|
179
205
|
};
|
|
180
206
|
type SingletonSync<T> = {
|
|
181
207
|
readonly name: string;
|
|
182
|
-
readonly refresh$: AsyncIterable<
|
|
208
|
+
readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
|
|
183
209
|
load(): Promise<void>;
|
|
184
210
|
get(): ReadonlyDeep<T>;
|
|
185
211
|
refresh(): void;
|
|
@@ -192,7 +218,7 @@ type CollectionOptions<TRaw, TMapped extends {
|
|
|
192
218
|
sort?: ((a: TMapped, b: TMapped) => number) | undefined;
|
|
193
219
|
cache?: CacheOptions | undefined;
|
|
194
220
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
195
|
-
onRefresh?: ((
|
|
221
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
196
222
|
};
|
|
197
223
|
type CollectionSyncOptions<TRaw, TMapped extends {
|
|
198
224
|
id: string;
|
|
@@ -202,11 +228,11 @@ type CollectionSyncOptions<TRaw, TMapped extends {
|
|
|
202
228
|
sort?: ((a: TMapped, b: TMapped) => number) | undefined;
|
|
203
229
|
cache?: SyncCacheOptions | undefined;
|
|
204
230
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
205
|
-
onRefresh?: ((
|
|
231
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
206
232
|
};
|
|
207
233
|
type Collection<T> = {
|
|
208
234
|
readonly name: string;
|
|
209
|
-
readonly refresh$: AsyncIterable<
|
|
235
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
210
236
|
load(): Promise<void>;
|
|
211
237
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
212
238
|
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
@@ -215,7 +241,7 @@ type Collection<T> = {
|
|
|
215
241
|
};
|
|
216
242
|
type CollectionSync<T> = {
|
|
217
243
|
readonly name: string;
|
|
218
|
-
readonly refresh$: AsyncIterable<
|
|
244
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
219
245
|
load(): Promise<void>;
|
|
220
246
|
get(id: string): ReadonlyDeep<T> | undefined;
|
|
221
247
|
get(ids: string[]): ReadonlyArray<ReadonlyDeep<T>>;
|
|
@@ -228,11 +254,11 @@ type LazyCollectionOptions<TRaw, TMapped extends {
|
|
|
228
254
|
name?: string | undefined;
|
|
229
255
|
cache?: LazyCacheOptions | undefined;
|
|
230
256
|
map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
|
|
231
|
-
onRefresh?: ((
|
|
257
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
232
258
|
};
|
|
233
259
|
type LazyCollection<T> = {
|
|
234
260
|
readonly name: string;
|
|
235
|
-
readonly refresh$: AsyncIterable<
|
|
261
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
236
262
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
237
263
|
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
238
264
|
refresh(): void;
|
|
@@ -254,11 +280,12 @@ type StoreAsset = {
|
|
|
254
280
|
preview: StoreFile | undefined;
|
|
255
281
|
optimized: StoreFile[];
|
|
256
282
|
};
|
|
257
|
-
type
|
|
283
|
+
type LazyAssetsOptions = {
|
|
258
284
|
cache?: LazyCacheOptions | undefined;
|
|
285
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
259
286
|
};
|
|
260
|
-
type
|
|
261
|
-
readonly refresh$: AsyncIterable<
|
|
287
|
+
type LazyAssets = {
|
|
288
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
262
289
|
get(id: string): Promise<ReadonlyDeep<StoreAsset> | undefined>;
|
|
263
290
|
get(ids: string[]): Promise<ReadonlyDeep<StoreAsset[]>>;
|
|
264
291
|
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
@@ -268,6 +295,37 @@ type Assets = {
|
|
|
268
295
|
clear(): void;
|
|
269
296
|
};
|
|
270
297
|
|
|
298
|
+
type AssetsOptions = {
|
|
299
|
+
cache?: CacheOptions | undefined;
|
|
300
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
301
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
302
|
+
};
|
|
303
|
+
type AssetsSyncOptions = {
|
|
304
|
+
cache?: SyncCacheOptions | undefined;
|
|
305
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
306
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
307
|
+
};
|
|
308
|
+
type Assets = {
|
|
309
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
310
|
+
load(): Promise<void>;
|
|
311
|
+
get(id: string): MaybePromise<ReadonlyDeep<StoreAsset> | undefined>;
|
|
312
|
+
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreAsset>>>;
|
|
313
|
+
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
314
|
+
download(fileId: string): Promise<DownloadResult>;
|
|
315
|
+
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
316
|
+
refresh(): void;
|
|
317
|
+
};
|
|
318
|
+
type AssetsSync = {
|
|
319
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
320
|
+
load(): Promise<void>;
|
|
321
|
+
get(id: string): ReadonlyDeep<StoreAsset> | undefined;
|
|
322
|
+
get(ids: string[]): ReadonlyArray<ReadonlyDeep<StoreAsset>>;
|
|
323
|
+
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
324
|
+
download(fileId: string): Promise<DownloadResult>;
|
|
325
|
+
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
326
|
+
refresh(): void;
|
|
327
|
+
};
|
|
328
|
+
|
|
271
329
|
type I18nTranslation = {
|
|
272
330
|
language: string;
|
|
273
331
|
value: string;
|
|
@@ -293,6 +351,8 @@ type I18nMessageRegistrationDefinition = {
|
|
|
293
351
|
};
|
|
294
352
|
type I18nMessageDef = {
|
|
295
353
|
collection: string;
|
|
354
|
+
cache?: SyncCacheOptions | undefined;
|
|
355
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
296
356
|
};
|
|
297
357
|
type I18nMessage = {
|
|
298
358
|
id: string;
|
|
@@ -300,20 +360,22 @@ type I18nMessage = {
|
|
|
300
360
|
translations: Map<string, string>;
|
|
301
361
|
};
|
|
302
362
|
type I18nMessages = {
|
|
303
|
-
readonly refresh$: AsyncIterable<
|
|
363
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
304
364
|
get(id: string): MaybePromise<ReadonlyDeep<I18nMessage> | undefined>;
|
|
305
365
|
get(ids: string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
306
366
|
getAll(): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
307
367
|
register(messages: I18nMessageRegistrationDefinition[]): Promise<void>;
|
|
368
|
+
refresh(): void;
|
|
308
369
|
/** Completes refresh$ and detaches from the watcher — called by `Store.destroy()`. */
|
|
309
370
|
destroy(): void;
|
|
310
371
|
};
|
|
311
372
|
|
|
312
|
-
type
|
|
373
|
+
type LazyRoutesOptions = {
|
|
313
374
|
cache?: LazyCacheOptions | undefined;
|
|
375
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
314
376
|
};
|
|
315
|
-
type
|
|
316
|
-
readonly refresh$: AsyncIterable<
|
|
377
|
+
type LazyRoutes = {
|
|
378
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
317
379
|
get(id: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
318
380
|
get(ids: string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
|
|
319
381
|
getByPath(path: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
@@ -322,6 +384,35 @@ type Routes = {
|
|
|
322
384
|
clear(): void;
|
|
323
385
|
};
|
|
324
386
|
|
|
387
|
+
type RoutesOptions = {
|
|
388
|
+
cache?: CacheOptions | undefined;
|
|
389
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
390
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
391
|
+
};
|
|
392
|
+
type RoutesSyncOptions = {
|
|
393
|
+
cache?: SyncCacheOptions | undefined;
|
|
394
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
395
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
396
|
+
};
|
|
397
|
+
type Routes = {
|
|
398
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
399
|
+
load(): Promise<void>;
|
|
400
|
+
get(id: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
401
|
+
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
|
|
402
|
+
getByPath(path: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
403
|
+
getByPath(paths: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
|
|
404
|
+
refresh(): void;
|
|
405
|
+
};
|
|
406
|
+
type RoutesSync = {
|
|
407
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
408
|
+
load(): Promise<void>;
|
|
409
|
+
get(id: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
410
|
+
get(ids: string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
|
|
411
|
+
getByPath(path: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
412
|
+
getByPath(paths: string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
|
|
413
|
+
refresh(): void;
|
|
414
|
+
};
|
|
415
|
+
|
|
325
416
|
/** Project the model-reference-name union out of a Schema generic, falling back to `string`. */
|
|
326
417
|
type ModelsOf<TSchema> = TSchema extends {
|
|
327
418
|
models: infer M;
|
|
@@ -336,6 +427,7 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
|
336
427
|
private _watcher;
|
|
337
428
|
private _schema;
|
|
338
429
|
private _cleanups;
|
|
430
|
+
private _refreshByTtl;
|
|
339
431
|
/**
|
|
340
432
|
* Multicast update-batch stream from the watcher. Consume with `for await (const batch of updates$)`;
|
|
341
433
|
* each iteration starts an independent fan-out from the shared source.
|
|
@@ -364,11 +456,15 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
|
364
456
|
} = CollectionRaw<TSchema, TArg> & {
|
|
365
457
|
id: string;
|
|
366
458
|
}>(sourceOrKey: TArg, options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): LazyCollection<TMapped>;
|
|
367
|
-
defineAssets(options?:
|
|
368
|
-
|
|
459
|
+
defineAssets(options?: AssetsOptions | undefined): Assets;
|
|
460
|
+
defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync;
|
|
461
|
+
defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets;
|
|
462
|
+
defineRoutes(options?: RoutesOptions | undefined): Routes;
|
|
463
|
+
defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync;
|
|
464
|
+
defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes;
|
|
369
465
|
defineI18nMessages(def: I18nMessageDef): I18nMessages;
|
|
370
466
|
ping: () => Promise<void>;
|
|
371
467
|
}
|
|
372
468
|
declare function createStore<TSchema extends Schema | undefined = undefined>(options: CreateStoreOptions<TSchema>): Store<TSchema>;
|
|
373
469
|
|
|
374
|
-
export { type
|
|
470
|
+
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
|
@@ -128,10 +128,30 @@ type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
|
|
|
128
128
|
onError?: ((error: unknown) => void) | undefined;
|
|
129
129
|
connectionEvents?: ConnectionEvents | undefined;
|
|
130
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* What triggered a refresh:
|
|
133
|
+
* - `'upstream-update'` — watcher event from the server (partial refresh on collection,
|
|
134
|
+
* full on singleton / i18n, cache eviction on lazy stores).
|
|
135
|
+
* - `'ttl'` — periodic safety-net timer fired.
|
|
136
|
+
* - `'on-demand'` — consumer called `instance.refresh()`.
|
|
137
|
+
*/
|
|
138
|
+
type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand';
|
|
139
|
+
/** Refresh event shape for stores keyed by id (collection, lazy-collection, routes, assets, i18n). */
|
|
140
|
+
type RefreshEvent = {
|
|
141
|
+
ids: string[];
|
|
142
|
+
kind: RefreshKind;
|
|
143
|
+
};
|
|
144
|
+
/** Refresh event shape for stores with no id concept (singleton). */
|
|
145
|
+
type SingletonRefreshEvent = {
|
|
146
|
+
kind: RefreshKind;
|
|
147
|
+
};
|
|
131
148
|
/** Cache options for non-lazy collections and singletons. */
|
|
132
149
|
type CacheOptions = {
|
|
133
|
-
/**
|
|
134
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Periodic full refresh — guards against stale data from missed update events.
|
|
152
|
+
* Defaults to 3 hours; set `0` or `false` to disable.
|
|
153
|
+
*/
|
|
154
|
+
ttl?: number | false | undefined;
|
|
135
155
|
/**
|
|
136
156
|
* Controls how the cache responds to Contello update events.
|
|
137
157
|
* `'refresh'` (default) serves stale data while a partial fetch runs in the background (SWR);
|
|
@@ -143,43 +163,49 @@ type CacheOptions = {
|
|
|
143
163
|
};
|
|
144
164
|
/** Cache options for sync collections and singletons. `eviction` is omitted — clearing the cache would break the sync guarantee. */
|
|
145
165
|
type SyncCacheOptions = {
|
|
146
|
-
/**
|
|
147
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Periodic full refresh — guards against stale data from missed update events.
|
|
168
|
+
* Defaults to 3 hours; set `0` or `false` to disable.
|
|
169
|
+
*/
|
|
170
|
+
ttl?: number | false | undefined;
|
|
148
171
|
};
|
|
149
172
|
/** Cache options for lazy collections. */
|
|
150
173
|
type LazyCacheOptions = {
|
|
151
174
|
/** Maximum number of items kept in the LRU cache. Defaults to 1000. */
|
|
152
175
|
max?: number | undefined;
|
|
153
|
-
/**
|
|
154
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Per-item LRU eviction — expired items are dropped on next access and
|
|
178
|
+
* re-fetched lazily. Defaults to 3 hours; set `0` or `false` to disable.
|
|
179
|
+
*/
|
|
180
|
+
ttl?: number | false | undefined;
|
|
155
181
|
};
|
|
156
182
|
type SingletonOptions<TRaw, TMapped, TModels extends string = string> = {
|
|
157
183
|
name?: string | undefined;
|
|
158
184
|
map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
|
|
159
185
|
cache?: CacheOptions | undefined;
|
|
160
186
|
onLoad?: (() => void) | undefined;
|
|
161
|
-
onRefresh?: (() => void) | undefined;
|
|
187
|
+
onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
|
|
162
188
|
};
|
|
163
189
|
type SingletonSyncOptions<TRaw, TMapped, TModels extends string = string> = {
|
|
164
190
|
name?: string | undefined;
|
|
165
191
|
map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
|
|
166
192
|
cache?: SyncCacheOptions | undefined;
|
|
167
193
|
onLoad?: (() => void) | undefined;
|
|
168
|
-
onRefresh?: (() => void) | undefined;
|
|
194
|
+
onRefresh?: ((event: SingletonRefreshEvent) => void) | undefined;
|
|
169
195
|
};
|
|
170
196
|
type Loadable = {
|
|
171
197
|
load(): Promise<void>;
|
|
172
198
|
};
|
|
173
199
|
type Singleton<T> = {
|
|
174
200
|
readonly name: string;
|
|
175
|
-
readonly refresh$: AsyncIterable<
|
|
201
|
+
readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
|
|
176
202
|
load(): Promise<void>;
|
|
177
203
|
get(): MaybePromise<ReadonlyDeep<T>>;
|
|
178
204
|
refresh(): void;
|
|
179
205
|
};
|
|
180
206
|
type SingletonSync<T> = {
|
|
181
207
|
readonly name: string;
|
|
182
|
-
readonly refresh$: AsyncIterable<
|
|
208
|
+
readonly refresh$: AsyncIterable<SingletonRefreshEvent>;
|
|
183
209
|
load(): Promise<void>;
|
|
184
210
|
get(): ReadonlyDeep<T>;
|
|
185
211
|
refresh(): void;
|
|
@@ -192,7 +218,7 @@ type CollectionOptions<TRaw, TMapped extends {
|
|
|
192
218
|
sort?: ((a: TMapped, b: TMapped) => number) | undefined;
|
|
193
219
|
cache?: CacheOptions | undefined;
|
|
194
220
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
195
|
-
onRefresh?: ((
|
|
221
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
196
222
|
};
|
|
197
223
|
type CollectionSyncOptions<TRaw, TMapped extends {
|
|
198
224
|
id: string;
|
|
@@ -202,11 +228,11 @@ type CollectionSyncOptions<TRaw, TMapped extends {
|
|
|
202
228
|
sort?: ((a: TMapped, b: TMapped) => number) | undefined;
|
|
203
229
|
cache?: SyncCacheOptions | undefined;
|
|
204
230
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
205
|
-
onRefresh?: ((
|
|
231
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
206
232
|
};
|
|
207
233
|
type Collection<T> = {
|
|
208
234
|
readonly name: string;
|
|
209
|
-
readonly refresh$: AsyncIterable<
|
|
235
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
210
236
|
load(): Promise<void>;
|
|
211
237
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
212
238
|
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
@@ -215,7 +241,7 @@ type Collection<T> = {
|
|
|
215
241
|
};
|
|
216
242
|
type CollectionSync<T> = {
|
|
217
243
|
readonly name: string;
|
|
218
|
-
readonly refresh$: AsyncIterable<
|
|
244
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
219
245
|
load(): Promise<void>;
|
|
220
246
|
get(id: string): ReadonlyDeep<T> | undefined;
|
|
221
247
|
get(ids: string[]): ReadonlyArray<ReadonlyDeep<T>>;
|
|
@@ -228,11 +254,11 @@ type LazyCollectionOptions<TRaw, TMapped extends {
|
|
|
228
254
|
name?: string | undefined;
|
|
229
255
|
cache?: LazyCacheOptions | undefined;
|
|
230
256
|
map?: ((item: TRaw, ref: MapperContext<TModels>) => MaybePromise<TMapped>) | undefined;
|
|
231
|
-
onRefresh?: ((
|
|
257
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
232
258
|
};
|
|
233
259
|
type LazyCollection<T> = {
|
|
234
260
|
readonly name: string;
|
|
235
|
-
readonly refresh$: AsyncIterable<
|
|
261
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
236
262
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
237
263
|
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
238
264
|
refresh(): void;
|
|
@@ -254,11 +280,12 @@ type StoreAsset = {
|
|
|
254
280
|
preview: StoreFile | undefined;
|
|
255
281
|
optimized: StoreFile[];
|
|
256
282
|
};
|
|
257
|
-
type
|
|
283
|
+
type LazyAssetsOptions = {
|
|
258
284
|
cache?: LazyCacheOptions | undefined;
|
|
285
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
259
286
|
};
|
|
260
|
-
type
|
|
261
|
-
readonly refresh$: AsyncIterable<
|
|
287
|
+
type LazyAssets = {
|
|
288
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
262
289
|
get(id: string): Promise<ReadonlyDeep<StoreAsset> | undefined>;
|
|
263
290
|
get(ids: string[]): Promise<ReadonlyDeep<StoreAsset[]>>;
|
|
264
291
|
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
@@ -268,6 +295,37 @@ type Assets = {
|
|
|
268
295
|
clear(): void;
|
|
269
296
|
};
|
|
270
297
|
|
|
298
|
+
type AssetsOptions = {
|
|
299
|
+
cache?: CacheOptions | undefined;
|
|
300
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
301
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
302
|
+
};
|
|
303
|
+
type AssetsSyncOptions = {
|
|
304
|
+
cache?: SyncCacheOptions | undefined;
|
|
305
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
306
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
307
|
+
};
|
|
308
|
+
type Assets = {
|
|
309
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
310
|
+
load(): Promise<void>;
|
|
311
|
+
get(id: string): MaybePromise<ReadonlyDeep<StoreAsset> | undefined>;
|
|
312
|
+
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreAsset>>>;
|
|
313
|
+
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
314
|
+
download(fileId: string): Promise<DownloadResult>;
|
|
315
|
+
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
316
|
+
refresh(): void;
|
|
317
|
+
};
|
|
318
|
+
type AssetsSync = {
|
|
319
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
320
|
+
load(): Promise<void>;
|
|
321
|
+
get(id: string): ReadonlyDeep<StoreAsset> | undefined;
|
|
322
|
+
get(ids: string[]): ReadonlyArray<ReadonlyDeep<StoreAsset>>;
|
|
323
|
+
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
324
|
+
download(fileId: string): Promise<DownloadResult>;
|
|
325
|
+
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
326
|
+
refresh(): void;
|
|
327
|
+
};
|
|
328
|
+
|
|
271
329
|
type I18nTranslation = {
|
|
272
330
|
language: string;
|
|
273
331
|
value: string;
|
|
@@ -293,6 +351,8 @@ type I18nMessageRegistrationDefinition = {
|
|
|
293
351
|
};
|
|
294
352
|
type I18nMessageDef = {
|
|
295
353
|
collection: string;
|
|
354
|
+
cache?: SyncCacheOptions | undefined;
|
|
355
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
296
356
|
};
|
|
297
357
|
type I18nMessage = {
|
|
298
358
|
id: string;
|
|
@@ -300,20 +360,22 @@ type I18nMessage = {
|
|
|
300
360
|
translations: Map<string, string>;
|
|
301
361
|
};
|
|
302
362
|
type I18nMessages = {
|
|
303
|
-
readonly refresh$: AsyncIterable<
|
|
363
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
304
364
|
get(id: string): MaybePromise<ReadonlyDeep<I18nMessage> | undefined>;
|
|
305
365
|
get(ids: string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
306
366
|
getAll(): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
307
367
|
register(messages: I18nMessageRegistrationDefinition[]): Promise<void>;
|
|
368
|
+
refresh(): void;
|
|
308
369
|
/** Completes refresh$ and detaches from the watcher — called by `Store.destroy()`. */
|
|
309
370
|
destroy(): void;
|
|
310
371
|
};
|
|
311
372
|
|
|
312
|
-
type
|
|
373
|
+
type LazyRoutesOptions = {
|
|
313
374
|
cache?: LazyCacheOptions | undefined;
|
|
375
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
314
376
|
};
|
|
315
|
-
type
|
|
316
|
-
readonly refresh$: AsyncIterable<
|
|
377
|
+
type LazyRoutes = {
|
|
378
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
317
379
|
get(id: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
318
380
|
get(ids: string[]): Promise<ReadonlyDeep<StoreRoute[]>>;
|
|
319
381
|
getByPath(path: string): Promise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
@@ -322,6 +384,35 @@ type Routes = {
|
|
|
322
384
|
clear(): void;
|
|
323
385
|
};
|
|
324
386
|
|
|
387
|
+
type RoutesOptions = {
|
|
388
|
+
cache?: CacheOptions | undefined;
|
|
389
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
390
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
391
|
+
};
|
|
392
|
+
type RoutesSyncOptions = {
|
|
393
|
+
cache?: SyncCacheOptions | undefined;
|
|
394
|
+
onLoad?: ((ids: string[]) => void) | undefined;
|
|
395
|
+
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
396
|
+
};
|
|
397
|
+
type Routes = {
|
|
398
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
399
|
+
load(): Promise<void>;
|
|
400
|
+
get(id: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
401
|
+
get(ids: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
|
|
402
|
+
getByPath(path: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
403
|
+
getByPath(paths: string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
|
|
404
|
+
refresh(): void;
|
|
405
|
+
};
|
|
406
|
+
type RoutesSync = {
|
|
407
|
+
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
408
|
+
load(): Promise<void>;
|
|
409
|
+
get(id: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
410
|
+
get(ids: string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
|
|
411
|
+
getByPath(path: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
412
|
+
getByPath(paths: string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
|
|
413
|
+
refresh(): void;
|
|
414
|
+
};
|
|
415
|
+
|
|
325
416
|
/** Project the model-reference-name union out of a Schema generic, falling back to `string`. */
|
|
326
417
|
type ModelsOf<TSchema> = TSchema extends {
|
|
327
418
|
models: infer M;
|
|
@@ -336,6 +427,7 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
|
336
427
|
private _watcher;
|
|
337
428
|
private _schema;
|
|
338
429
|
private _cleanups;
|
|
430
|
+
private _refreshByTtl;
|
|
339
431
|
/**
|
|
340
432
|
* Multicast update-batch stream from the watcher. Consume with `for await (const batch of updates$)`;
|
|
341
433
|
* each iteration starts an independent fan-out from the shared source.
|
|
@@ -364,11 +456,15 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
|
364
456
|
} = CollectionRaw<TSchema, TArg> & {
|
|
365
457
|
id: string;
|
|
366
458
|
}>(sourceOrKey: TArg, options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): LazyCollection<TMapped>;
|
|
367
|
-
defineAssets(options?:
|
|
368
|
-
|
|
459
|
+
defineAssets(options?: AssetsOptions | undefined): Assets;
|
|
460
|
+
defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync;
|
|
461
|
+
defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets;
|
|
462
|
+
defineRoutes(options?: RoutesOptions | undefined): Routes;
|
|
463
|
+
defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync;
|
|
464
|
+
defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes;
|
|
369
465
|
defineI18nMessages(def: I18nMessageDef): I18nMessages;
|
|
370
466
|
ping: () => Promise<void>;
|
|
371
467
|
}
|
|
372
468
|
declare function createStore<TSchema extends Schema | undefined = undefined>(options: CreateStoreOptions<TSchema>): Store<TSchema>;
|
|
373
469
|
|
|
374
|
-
export { type
|
|
470
|
+
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 };
|