@contello/store 4.2.0 → 4.4.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/fragments.d.ts.map +1 -1
- package/dist/fragments.js.map +1 -1
- package/dist/index.cjs +294 -11
- package/dist/index.d.cts +99 -27
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +99 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +295 -12
- package/dist/index.js.map +1 -1
- package/fragments/route.gql +3 -0
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConnectionEvents, ContelloClient, DownloadResult, ProxyResult, Schema, SourceCardinality, SourceDef, UploadData, UploadMetadata, UploadOptions } from "@contello/client";
|
|
2
2
|
import { MaybePromise, ReadonlyDeep } from "@entwico/dash";
|
|
3
|
+
import "@entwico/dash/async";
|
|
3
4
|
//#region src/routes-mapping.d.ts
|
|
4
5
|
type StoreRouteCustomHeader = {
|
|
5
6
|
name: string;
|
|
@@ -28,6 +29,9 @@ type StoreRoute = {
|
|
|
28
29
|
model: string;
|
|
29
30
|
entityType: string;
|
|
30
31
|
entityId: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'sitemap';
|
|
34
|
+
sitemapId: string;
|
|
31
35
|
});
|
|
32
36
|
//#endregion
|
|
33
37
|
//#region src/watcher.d.ts
|
|
@@ -69,8 +73,10 @@ type UpdateBatch = {
|
|
|
69
73
|
readonly events: UpdateEvent[];
|
|
70
74
|
readonly route: UpdateEventFor<'route'>[];
|
|
71
75
|
readonly asset: UpdateEventFor<'asset'>[];
|
|
72
|
-
readonly i18nMessage: UpdateEventFor<'i18nMessage'>[];
|
|
73
|
-
|
|
76
|
+
readonly i18nMessage: UpdateEventFor<'i18nMessage'>[];
|
|
77
|
+
/** entity events grouped by model typename */
|
|
78
|
+
readonly entity: Map<string, UpdateEventFor<'entity'>[]>;
|
|
79
|
+
/** route events grouped by target entity model (both after and before targets for updates) */
|
|
74
80
|
readonly routeByEntityModel: Map<string, UpdateEventFor<'route'>[]>;
|
|
75
81
|
};
|
|
76
82
|
//#endregion
|
|
@@ -105,7 +111,7 @@ type ExtractSourceResult<S extends SourceDef<string, 'entity' | 'singleton'>> =
|
|
|
105
111
|
/** Keys of `schema.sources` whose entries match the given cardinality. */
|
|
106
112
|
type SourceKeysOf<TSchema, TCardinality extends SourceCardinality> = TSchema extends {
|
|
107
113
|
sources: infer TSources;
|
|
108
|
-
} ? { [K in keyof TSources]: TSources[K] extends SourceDef<any, TCardinality, any> ? K : never }[keyof TSources] : never;
|
|
114
|
+
} ? { [K in keyof TSources]: TSources[K] extends SourceDef<any, TCardinality, any> ? K : never; }[keyof TSources] : never;
|
|
109
115
|
/** The SourceDef at `schema.sources[TKey]`. */
|
|
110
116
|
type SourceAt<TSchema, TKey> = TSchema extends {
|
|
111
117
|
sources: infer TSources;
|
|
@@ -133,8 +139,10 @@ type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
|
|
|
133
139
|
* full on singleton / i18n, cache eviction on lazy stores).
|
|
134
140
|
* - `'ttl'` — periodic safety-net timer fired.
|
|
135
141
|
* - `'on-demand'` — consumer called `instance.refresh()`.
|
|
142
|
+
* - `'write'` — a `create` / `update` / `delete` on the collection itself; the watcher event
|
|
143
|
+
* for the same change still arrives afterwards and refreshes again.
|
|
136
144
|
*/
|
|
137
|
-
type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand';
|
|
145
|
+
type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand' | 'write';
|
|
138
146
|
/** Refresh event shape for stores keyed by id (collection, lazy-collection, routes, assets, i18n). */
|
|
139
147
|
type RefreshEvent = {
|
|
140
148
|
ids: string[];
|
|
@@ -173,7 +181,8 @@ type SyncCacheOptions = {
|
|
|
173
181
|
};
|
|
174
182
|
/** Cache options for lazy collections. */
|
|
175
183
|
type LazyCacheOptions = {
|
|
176
|
-
/** Maximum number of items kept in the LRU cache. Defaults to 1000. */
|
|
184
|
+
/** Maximum number of items kept in the LRU cache. Defaults to 1000. */
|
|
185
|
+
max?: number | undefined;
|
|
177
186
|
/**
|
|
178
187
|
* Per-item LRU eviction — expired items are dropped on next access and
|
|
179
188
|
* re-fetched lazily. Defaults to 3 hours; set `0` or `false` to disable.
|
|
@@ -231,24 +240,68 @@ type CollectionSyncOptions<TRaw, TMapped extends {
|
|
|
231
240
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
232
241
|
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
233
242
|
};
|
|
234
|
-
type Collection<T> = {
|
|
243
|
+
type Collection<T, TWrites = unknown> = {
|
|
235
244
|
readonly name: string;
|
|
236
245
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
237
246
|
load(): Promise<void>;
|
|
238
247
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
248
|
+
/**
|
|
249
|
+
* Resolves the given ids in the given order; ids that are unknown to the collection are skipped,
|
|
250
|
+
* so the result may be shorter than the input.
|
|
251
|
+
*/
|
|
239
252
|
get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
240
253
|
getAll(): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
241
254
|
refresh(): void;
|
|
242
|
-
}
|
|
243
|
-
type CollectionSync<T> = {
|
|
255
|
+
} & CollectionWrites<T, TWrites>;
|
|
256
|
+
type CollectionSync<T, TWrites = unknown> = {
|
|
244
257
|
readonly name: string;
|
|
245
258
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
246
259
|
load(): Promise<void>;
|
|
247
260
|
get(id: string): ReadonlyDeep<T> | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* Resolves the given ids in the given order; ids that are unknown to the collection are skipped,
|
|
263
|
+
* so the result may be shorter than the input.
|
|
264
|
+
*/
|
|
248
265
|
get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<T>>;
|
|
249
266
|
getAll(): ReadonlyArray<ReadonlyDeep<T>>;
|
|
250
267
|
refresh(): void;
|
|
251
|
-
}
|
|
268
|
+
} & CollectionWrites<T, TWrites>;
|
|
269
|
+
/** The phantom write-input shape a SourceDef carries, or `unknown` when it carries none. */
|
|
270
|
+
type ExtractSourceWrites<S> = S extends SourceDef<string, SourceCardinality, any, infer TWrites> ? TWrites : unknown;
|
|
271
|
+
/** Everything the model's delete mutation accepts besides the id (e.g. `force`). */
|
|
272
|
+
type DeleteOptions<TDelete> = Omit<TDelete, 'id'>;
|
|
273
|
+
/**
|
|
274
|
+
* The write-input shape of the schema's built-in source of a given cardinality — `unknown` when
|
|
275
|
+
* the app's documents carry no fragment for it, which is also when its writes cannot be typed.
|
|
276
|
+
*/
|
|
277
|
+
type BuiltInWrites<TSchema, TCardinality extends SourceCardinality> = [SourceKeysOf<TSchema, TCardinality>] extends [never] ? unknown : ExtractSourceWrites<SourceAt<TSchema, SourceKeysOf<TSchema, TCardinality>>>;
|
|
278
|
+
/**
|
|
279
|
+
* The write half of a source-backed store — collections, routes, assets: one method per mutation
|
|
280
|
+
* the schema defines for it, so a model without a `createX` has no `create` here, and an asset
|
|
281
|
+
* (which comes into being through `client.upload()`) has no `create` at all. Whether the token
|
|
282
|
+
* may run them is the server's call — it answers a write it does not allow with an error, like
|
|
283
|
+
* any other request.
|
|
284
|
+
*
|
|
285
|
+
* Writes are expressed in the model's raw input types, not in the mapped shape: `map()` is
|
|
286
|
+
* one-way, so there is no way back from `T` to what the server accepts. What comes back is
|
|
287
|
+
* mapped — `create` and `update` answer with the entity as the collection sees it.
|
|
288
|
+
*
|
|
289
|
+
* `update` is a patch: attributes left out keep their stored value, per property and, for
|
|
290
|
+
* translatable ones, per locale.
|
|
291
|
+
*/
|
|
292
|
+
type CollectionWrites<TMapped, TWrites> = (TWrites extends {
|
|
293
|
+
create: infer TCreate;
|
|
294
|
+
} ? {
|
|
295
|
+
create(input: TCreate): Promise<ReadonlyDeep<TMapped>>;
|
|
296
|
+
} : Record<never, never>) & (TWrites extends {
|
|
297
|
+
update: infer TUpdate;
|
|
298
|
+
} ? {
|
|
299
|
+
update(input: TUpdate): Promise<ReadonlyDeep<TMapped>>;
|
|
300
|
+
} : Record<never, never>) & (TWrites extends {
|
|
301
|
+
delete: infer TDelete;
|
|
302
|
+
} ? {
|
|
303
|
+
delete(id: string, options?: DeleteOptions<TDelete> | undefined): Promise<void>;
|
|
304
|
+
} : Record<never, never>);
|
|
252
305
|
type LazyCollectionOptions<TRaw, TMapped extends {
|
|
253
306
|
id: string;
|
|
254
307
|
}, TModels extends string = string> = {
|
|
@@ -261,6 +314,10 @@ type LazyCollection<T> = {
|
|
|
261
314
|
readonly name: string;
|
|
262
315
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
263
316
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
317
|
+
/**
|
|
318
|
+
* Resolves the given ids in the given order; ids that are unknown to the collection are skipped,
|
|
319
|
+
* so the result may be shorter than the input.
|
|
320
|
+
*/
|
|
264
321
|
get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
265
322
|
refresh(): void;
|
|
266
323
|
clear(): void;
|
|
@@ -308,7 +365,11 @@ type AssetsSyncOptions = {
|
|
|
308
365
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
309
366
|
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
310
367
|
};
|
|
311
|
-
|
|
368
|
+
/**
|
|
369
|
+
* There is no `create`: an asset comes into being through `upload()`, which is the transport, not
|
|
370
|
+
* a mutation. `update` patches the mutable metadata — fields left out keep their value.
|
|
371
|
+
*/
|
|
372
|
+
type Assets<TWrites = unknown> = {
|
|
312
373
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
313
374
|
load(): Promise<void>;
|
|
314
375
|
get(id: string): MaybePromise<ReadonlyDeep<StoreAsset> | undefined>;
|
|
@@ -317,8 +378,8 @@ type Assets = {
|
|
|
317
378
|
download(fileId: string): Promise<DownloadResult>;
|
|
318
379
|
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
319
380
|
refresh(): void;
|
|
320
|
-
}
|
|
321
|
-
type AssetsSync = {
|
|
381
|
+
} & CollectionWrites<StoreAsset, TWrites>;
|
|
382
|
+
type AssetsSync<TWrites = unknown> = {
|
|
322
383
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
323
384
|
load(): Promise<void>;
|
|
324
385
|
get(id: string): ReadonlyDeep<StoreAsset> | undefined;
|
|
@@ -327,7 +388,7 @@ type AssetsSync = {
|
|
|
327
388
|
download(fileId: string): Promise<DownloadResult>;
|
|
328
389
|
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
329
390
|
refresh(): void;
|
|
330
|
-
}
|
|
391
|
+
} & CollectionWrites<StoreAsset, TWrites>;
|
|
331
392
|
//#endregion
|
|
332
393
|
//#region src/i18n.d.ts
|
|
333
394
|
type I18nTranslation = {
|
|
@@ -347,8 +408,10 @@ type I18nMessageRegistrationDefinition = {
|
|
|
347
408
|
token: string;
|
|
348
409
|
example?: string | undefined;
|
|
349
410
|
description?: string | undefined;
|
|
350
|
-
variables?: I18nVariableInput[] | undefined;
|
|
351
|
-
|
|
411
|
+
variables?: I18nVariableInput[] | undefined;
|
|
412
|
+
/** always overwrites existing translations for this token */
|
|
413
|
+
translations?: I18nInitialTranslation[] | undefined;
|
|
414
|
+
/** only applied when the token is newly registered (existing translations are preserved) */
|
|
352
415
|
initialTranslations?: I18nInitialTranslation[] | undefined;
|
|
353
416
|
};
|
|
354
417
|
type I18nMessageDef = {
|
|
@@ -367,7 +430,8 @@ type I18nMessages = {
|
|
|
367
430
|
get(ids: readonly string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
368
431
|
getAll(): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
369
432
|
register(messages: I18nMessageRegistrationDefinition[]): Promise<void>;
|
|
370
|
-
refresh(): void;
|
|
433
|
+
refresh(): void;
|
|
434
|
+
/** Completes refresh$ and detaches from the watcher — called by `Store.destroy()`. */
|
|
371
435
|
destroy(): void;
|
|
372
436
|
};
|
|
373
437
|
//#endregion
|
|
@@ -397,7 +461,11 @@ type RoutesSyncOptions = {
|
|
|
397
461
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
398
462
|
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
399
463
|
};
|
|
400
|
-
|
|
464
|
+
/**
|
|
465
|
+
* `update` is not the patch a collection's is: `updateContelloRoute` is keyed by the `path` in its
|
|
466
|
+
* input — there is no id — and it replaces the route, so a field left out is cleared, not kept.
|
|
467
|
+
*/
|
|
468
|
+
type Routes<TWrites = unknown> = {
|
|
401
469
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
402
470
|
load(): Promise<void>;
|
|
403
471
|
get(id: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
@@ -405,8 +473,8 @@ type Routes = {
|
|
|
405
473
|
getByPath(path: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
406
474
|
getByPath(paths: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
|
|
407
475
|
refresh(): void;
|
|
408
|
-
}
|
|
409
|
-
type RoutesSync = {
|
|
476
|
+
} & CollectionWrites<StoreRoute, TWrites>;
|
|
477
|
+
type RoutesSync<TWrites = unknown> = {
|
|
410
478
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
411
479
|
load(): Promise<void>;
|
|
412
480
|
get(id: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
@@ -414,7 +482,7 @@ type RoutesSync = {
|
|
|
414
482
|
getByPath(path: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
415
483
|
getByPath(paths: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
|
|
416
484
|
refresh(): void;
|
|
417
|
-
}
|
|
485
|
+
} & CollectionWrites<StoreRoute, TWrites>;
|
|
418
486
|
//#endregion
|
|
419
487
|
//#region src/store.d.ts
|
|
420
488
|
/** Project the model-reference-name union out of a Schema generic, falling back to `string`. */
|
|
@@ -424,6 +492,10 @@ type ModelsOf<TSchema> = TSchema extends {
|
|
|
424
492
|
type CollectionArg<TSchema> = SourceKeysOf<TSchema, 'entity'> | SourceDef<ModelsOf<TSchema>, 'entity'>;
|
|
425
493
|
type SingletonArg<TSchema> = SourceKeysOf<TSchema, 'singleton'> | SourceDef<ModelsOf<TSchema>, 'singleton'>;
|
|
426
494
|
type CollectionRaw<TSchema, TArg> = ExtractSourceResult<Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>>;
|
|
495
|
+
/** The write-input shape the source carries — `unknown` for sources the generator bound no mutations to. */
|
|
496
|
+
type CollectionWritesOf<TSchema, TArg> = ExtractSourceWrites<Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>>;
|
|
497
|
+
type RouteWrites<TSchema> = BuiltInWrites<TSchema, 'route'>;
|
|
498
|
+
type AssetWrites<TSchema> = BuiltInWrites<TSchema, 'asset'>;
|
|
427
499
|
type SingletonRaw<TSchema, TArg> = ExtractSourceResult<Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'singleton'>>>;
|
|
428
500
|
declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
429
501
|
private _client;
|
|
@@ -450,26 +522,26 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
|
450
522
|
id: string;
|
|
451
523
|
} = CollectionRaw<TSchema, TArg> & {
|
|
452
524
|
id: string;
|
|
453
|
-
}>(sourceOrKey: TArg, options?: CollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): Collection<TMapped
|
|
525
|
+
}>(sourceOrKey: TArg, options?: CollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): Collection<TMapped, CollectionWritesOf<TSchema, TArg>>;
|
|
454
526
|
defineCollectionSync<TArg extends CollectionArg<TSchema>, TMapped extends {
|
|
455
527
|
id: string;
|
|
456
528
|
} = CollectionRaw<TSchema, TArg> & {
|
|
457
529
|
id: string;
|
|
458
|
-
}>(sourceOrKey: TArg, options?: CollectionSyncOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): CollectionSync<TMapped
|
|
530
|
+
}>(sourceOrKey: TArg, options?: CollectionSyncOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): CollectionSync<TMapped, CollectionWritesOf<TSchema, TArg>>;
|
|
459
531
|
defineLazyCollection<TArg extends CollectionArg<TSchema>, TMapped extends {
|
|
460
532
|
id: string;
|
|
461
533
|
} = CollectionRaw<TSchema, TArg> & {
|
|
462
534
|
id: string;
|
|
463
535
|
}>(sourceOrKey: TArg, options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): LazyCollection<TMapped>;
|
|
464
|
-
defineAssets(options?: AssetsOptions | undefined): Assets
|
|
465
|
-
defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync
|
|
536
|
+
defineAssets(options?: AssetsOptions | undefined): Assets<AssetWrites<TSchema>>;
|
|
537
|
+
defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync<AssetWrites<TSchema>>;
|
|
466
538
|
defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets;
|
|
467
|
-
defineRoutes(options?: RoutesOptions | undefined): Routes
|
|
468
|
-
defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync
|
|
539
|
+
defineRoutes(options?: RoutesOptions | undefined): Routes<RouteWrites<TSchema>>;
|
|
540
|
+
defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync<RouteWrites<TSchema>>;
|
|
469
541
|
defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes;
|
|
470
542
|
defineI18nMessages(def: I18nMessageDef): I18nMessages;
|
|
471
543
|
}
|
|
472
544
|
declare function createStore<TSchema extends Schema | undefined = undefined>(options: CreateStoreOptions<TSchema>): Store<TSchema>;
|
|
473
545
|
//#endregion
|
|
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 };
|
|
546
|
+
export { type Assets, type AssetsOptions, type AssetsSync, type AssetsSyncOptions, type BuiltInWrites, type CacheOptions, type Collection, type CollectionOptions, type CollectionSync, type CollectionSyncOptions, type CollectionWrites, type CreateStoreOptions, type DeleteOptions, type ExtractSourceResult, type ExtractSourceWrites, 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 };
|
|
475
547
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/routes-mapping.ts","../src/watcher.ts","../src/dependency-collector.ts","../src/types.ts","../src/lazy-assets.ts","../src/assets.ts","../src/i18n.ts","../src/lazy-routes.ts","../src/routes.ts","../src/store.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/routes-mapping.ts","../src/watcher.ts","../src/dependency-collector.ts","../src/types.ts","../src/lazy-assets.ts","../src/assets.ts","../src/i18n.ts","../src/lazy-routes.ts","../src/routes.ts","../src/store.ts"],"mappings":";;;;KAGY;EACV;EACA;;KAGU;EACV;EACA;EACA,eAAe;;EAEX;EAAkB;EAAkB;;EACpC;EAAc;EAAiB;;EAC/B;EAAe;EAAiB;EAAgB;EAA6C;;EAC7F;EAAgB;EAAe;EAAoB;;EACnD;EAAiB;;;;KCJX,YAAY;EAClB;EAAY;EAAoB;EAAiB,OAAO;;EACxD;EAAY;EAAoB;EAAiB,OAAO;EAAY,QAAQ;;EAC5E;EAAY;EAAoB;;EAChC;EAAY;EAA0C;;EACtD;EAAY;EAA0C;EAAuB;;EAC7E;EAAY;EAA0C;EAAkB,OAAO;;KAEzE,qBAAqB;KAErB,eAAe,UAAU,yBAAyB,QAAQ;EAAe,QAAQ;;KAEjF;WACD,QAAQ;WACR,OAAO;WACP,OAAO;WACP,aAAa;;WAEb,QAAQ,YAAY;;WAEpB,oBAAoB,YAAY;;;;;;;;;;;;;;;;;;KCd/B,cAAc;EACxB,MAAM;IAAO;IAAoB;;EACjC,YAAY,UAAU,SAAS;EAC/B,WAAW;EACX,WAAW;;;;;KClBD,oBAAoB,UAAU,6CAA6C,YAAY;;KAMvF,aAAa,SAAS,qBAAqB,qBAAqB;EAC1E,eAAe;OAGV,WAAW,WAAW,SAAS,WAAW,eAAe,qBAAqB,mBACzE;;KAIA,S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AAU;KAElE,aAAa,MACb,UAAU,kBAAkB,cAAc,SAAS,OAAO,SAAS,SAAS,YAC3E,WAAW,SAAS,mBAAmB,SAAS;EAgB5C,qBACL,aAAa,cAAc,UAC3B;IAAkB;MAAe,cAAc,SAAS;IAAU;KAElE,aAAa,MACb,UAAU,sBAAsB,cAAc,SAAS,OAAO,SAAS,SAAS,YAC/E,eAAe,SAAS,mBAAmB,SAAS;EAkBhD,qBACL,aAAa,cAAc,UAC3B;IAAkB;MAAe,cAAc,SAAS;IAAU;KAElE,aAAa,MACb,UAAU,sBAAsB,cAAc,SAAS,OAAO,SAAS,SAAS,YAC/E,eAAe;EAmBX,aAAa,UAAU,4BAA4B,OAAO,YAAY;EAatE,iBAAiB,UAAU,gCAAgC,WAAW,YAAY;EAalF,iBAAiB,UAAU,gCAAgC;EAU3D,aAAa,UAAU,4BAA4B,OAAO,YAAY;EActE,iBAAiB,UAAU,gCAAgC,WAAW,YAAY;EAclF,iBAAiB,UAAU,gCAAgC;EAa3D,mBAAmB,KAAK,iBAAiB;;iBASlC,YAAY,gBAAgB,gCAC1C,SAAS,mBAAmB,WAC3B,MAAM"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConnectionEvents, ContelloClient, DownloadResult, ProxyResult, Schema, SourceCardinality, SourceDef, UploadData, UploadMetadata, UploadOptions } from "@contello/client";
|
|
2
|
+
import "@entwico/dash/async";
|
|
2
3
|
import { MaybePromise, ReadonlyDeep } from "@entwico/dash";
|
|
3
|
-
|
|
4
4
|
//#region src/routes-mapping.d.ts
|
|
5
5
|
type StoreRouteCustomHeader = {
|
|
6
6
|
name: string;
|
|
@@ -29,6 +29,9 @@ type StoreRoute = {
|
|
|
29
29
|
model: string;
|
|
30
30
|
entityType: string;
|
|
31
31
|
entityId: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'sitemap';
|
|
34
|
+
sitemapId: string;
|
|
32
35
|
});
|
|
33
36
|
//#endregion
|
|
34
37
|
//#region src/watcher.d.ts
|
|
@@ -70,8 +73,10 @@ type UpdateBatch = {
|
|
|
70
73
|
readonly events: UpdateEvent[];
|
|
71
74
|
readonly route: UpdateEventFor<'route'>[];
|
|
72
75
|
readonly asset: UpdateEventFor<'asset'>[];
|
|
73
|
-
readonly i18nMessage: UpdateEventFor<'i18nMessage'>[];
|
|
74
|
-
|
|
76
|
+
readonly i18nMessage: UpdateEventFor<'i18nMessage'>[];
|
|
77
|
+
/** entity events grouped by model typename */
|
|
78
|
+
readonly entity: Map<string, UpdateEventFor<'entity'>[]>;
|
|
79
|
+
/** route events grouped by target entity model (both after and before targets for updates) */
|
|
75
80
|
readonly routeByEntityModel: Map<string, UpdateEventFor<'route'>[]>;
|
|
76
81
|
};
|
|
77
82
|
//#endregion
|
|
@@ -106,7 +111,7 @@ type ExtractSourceResult<S extends SourceDef<string, 'entity' | 'singleton'>> =
|
|
|
106
111
|
/** Keys of `schema.sources` whose entries match the given cardinality. */
|
|
107
112
|
type SourceKeysOf<TSchema, TCardinality extends SourceCardinality> = TSchema extends {
|
|
108
113
|
sources: infer TSources;
|
|
109
|
-
} ? { [K in keyof TSources]: TSources[K] extends SourceDef<any, TCardinality, any> ? K : never }[keyof TSources] : never;
|
|
114
|
+
} ? { [K in keyof TSources]: TSources[K] extends SourceDef<any, TCardinality, any> ? K : never; }[keyof TSources] : never;
|
|
110
115
|
/** The SourceDef at `schema.sources[TKey]`. */
|
|
111
116
|
type SourceAt<TSchema, TKey> = TSchema extends {
|
|
112
117
|
sources: infer TSources;
|
|
@@ -134,8 +139,10 @@ type CreateStoreOptions<TSchema extends Schema | undefined = undefined> = {
|
|
|
134
139
|
* full on singleton / i18n, cache eviction on lazy stores).
|
|
135
140
|
* - `'ttl'` — periodic safety-net timer fired.
|
|
136
141
|
* - `'on-demand'` — consumer called `instance.refresh()`.
|
|
142
|
+
* - `'write'` — a `create` / `update` / `delete` on the collection itself; the watcher event
|
|
143
|
+
* for the same change still arrives afterwards and refreshes again.
|
|
137
144
|
*/
|
|
138
|
-
type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand';
|
|
145
|
+
type RefreshKind = 'upstream-update' | 'ttl' | 'on-demand' | 'write';
|
|
139
146
|
/** Refresh event shape for stores keyed by id (collection, lazy-collection, routes, assets, i18n). */
|
|
140
147
|
type RefreshEvent = {
|
|
141
148
|
ids: string[];
|
|
@@ -174,7 +181,8 @@ type SyncCacheOptions = {
|
|
|
174
181
|
};
|
|
175
182
|
/** Cache options for lazy collections. */
|
|
176
183
|
type LazyCacheOptions = {
|
|
177
|
-
/** Maximum number of items kept in the LRU cache. Defaults to 1000. */
|
|
184
|
+
/** Maximum number of items kept in the LRU cache. Defaults to 1000. */
|
|
185
|
+
max?: number | undefined;
|
|
178
186
|
/**
|
|
179
187
|
* Per-item LRU eviction — expired items are dropped on next access and
|
|
180
188
|
* re-fetched lazily. Defaults to 3 hours; set `0` or `false` to disable.
|
|
@@ -232,24 +240,68 @@ type CollectionSyncOptions<TRaw, TMapped extends {
|
|
|
232
240
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
233
241
|
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
234
242
|
};
|
|
235
|
-
type Collection<T> = {
|
|
243
|
+
type Collection<T, TWrites = unknown> = {
|
|
236
244
|
readonly name: string;
|
|
237
245
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
238
246
|
load(): Promise<void>;
|
|
239
247
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
248
|
+
/**
|
|
249
|
+
* Resolves the given ids in the given order; ids that are unknown to the collection are skipped,
|
|
250
|
+
* so the result may be shorter than the input.
|
|
251
|
+
*/
|
|
240
252
|
get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
241
253
|
getAll(): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
242
254
|
refresh(): void;
|
|
243
|
-
}
|
|
244
|
-
type CollectionSync<T> = {
|
|
255
|
+
} & CollectionWrites<T, TWrites>;
|
|
256
|
+
type CollectionSync<T, TWrites = unknown> = {
|
|
245
257
|
readonly name: string;
|
|
246
258
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
247
259
|
load(): Promise<void>;
|
|
248
260
|
get(id: string): ReadonlyDeep<T> | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* Resolves the given ids in the given order; ids that are unknown to the collection are skipped,
|
|
263
|
+
* so the result may be shorter than the input.
|
|
264
|
+
*/
|
|
249
265
|
get(ids: readonly string[]): ReadonlyArray<ReadonlyDeep<T>>;
|
|
250
266
|
getAll(): ReadonlyArray<ReadonlyDeep<T>>;
|
|
251
267
|
refresh(): void;
|
|
252
|
-
}
|
|
268
|
+
} & CollectionWrites<T, TWrites>;
|
|
269
|
+
/** The phantom write-input shape a SourceDef carries, or `unknown` when it carries none. */
|
|
270
|
+
type ExtractSourceWrites<S> = S extends SourceDef<string, SourceCardinality, any, infer TWrites> ? TWrites : unknown;
|
|
271
|
+
/** Everything the model's delete mutation accepts besides the id (e.g. `force`). */
|
|
272
|
+
type DeleteOptions<TDelete> = Omit<TDelete, 'id'>;
|
|
273
|
+
/**
|
|
274
|
+
* The write-input shape of the schema's built-in source of a given cardinality — `unknown` when
|
|
275
|
+
* the app's documents carry no fragment for it, which is also when its writes cannot be typed.
|
|
276
|
+
*/
|
|
277
|
+
type BuiltInWrites<TSchema, TCardinality extends SourceCardinality> = [SourceKeysOf<TSchema, TCardinality>] extends [never] ? unknown : ExtractSourceWrites<SourceAt<TSchema, SourceKeysOf<TSchema, TCardinality>>>;
|
|
278
|
+
/**
|
|
279
|
+
* The write half of a source-backed store — collections, routes, assets: one method per mutation
|
|
280
|
+
* the schema defines for it, so a model without a `createX` has no `create` here, and an asset
|
|
281
|
+
* (which comes into being through `client.upload()`) has no `create` at all. Whether the token
|
|
282
|
+
* may run them is the server's call — it answers a write it does not allow with an error, like
|
|
283
|
+
* any other request.
|
|
284
|
+
*
|
|
285
|
+
* Writes are expressed in the model's raw input types, not in the mapped shape: `map()` is
|
|
286
|
+
* one-way, so there is no way back from `T` to what the server accepts. What comes back is
|
|
287
|
+
* mapped — `create` and `update` answer with the entity as the collection sees it.
|
|
288
|
+
*
|
|
289
|
+
* `update` is a patch: attributes left out keep their stored value, per property and, for
|
|
290
|
+
* translatable ones, per locale.
|
|
291
|
+
*/
|
|
292
|
+
type CollectionWrites<TMapped, TWrites> = (TWrites extends {
|
|
293
|
+
create: infer TCreate;
|
|
294
|
+
} ? {
|
|
295
|
+
create(input: TCreate): Promise<ReadonlyDeep<TMapped>>;
|
|
296
|
+
} : Record<never, never>) & (TWrites extends {
|
|
297
|
+
update: infer TUpdate;
|
|
298
|
+
} ? {
|
|
299
|
+
update(input: TUpdate): Promise<ReadonlyDeep<TMapped>>;
|
|
300
|
+
} : Record<never, never>) & (TWrites extends {
|
|
301
|
+
delete: infer TDelete;
|
|
302
|
+
} ? {
|
|
303
|
+
delete(id: string, options?: DeleteOptions<TDelete> | undefined): Promise<void>;
|
|
304
|
+
} : Record<never, never>);
|
|
253
305
|
type LazyCollectionOptions<TRaw, TMapped extends {
|
|
254
306
|
id: string;
|
|
255
307
|
}, TModels extends string = string> = {
|
|
@@ -262,6 +314,10 @@ type LazyCollection<T> = {
|
|
|
262
314
|
readonly name: string;
|
|
263
315
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
264
316
|
get(id: string): MaybePromise<ReadonlyDeep<T> | undefined>;
|
|
317
|
+
/**
|
|
318
|
+
* Resolves the given ids in the given order; ids that are unknown to the collection are skipped,
|
|
319
|
+
* so the result may be shorter than the input.
|
|
320
|
+
*/
|
|
265
321
|
get(ids: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<T>>>;
|
|
266
322
|
refresh(): void;
|
|
267
323
|
clear(): void;
|
|
@@ -309,7 +365,11 @@ type AssetsSyncOptions = {
|
|
|
309
365
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
310
366
|
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
311
367
|
};
|
|
312
|
-
|
|
368
|
+
/**
|
|
369
|
+
* There is no `create`: an asset comes into being through `upload()`, which is the transport, not
|
|
370
|
+
* a mutation. `update` patches the mutable metadata — fields left out keep their value.
|
|
371
|
+
*/
|
|
372
|
+
type Assets<TWrites = unknown> = {
|
|
313
373
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
314
374
|
load(): Promise<void>;
|
|
315
375
|
get(id: string): MaybePromise<ReadonlyDeep<StoreAsset> | undefined>;
|
|
@@ -318,8 +378,8 @@ type Assets = {
|
|
|
318
378
|
download(fileId: string): Promise<DownloadResult>;
|
|
319
379
|
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
320
380
|
refresh(): void;
|
|
321
|
-
}
|
|
322
|
-
type AssetsSync = {
|
|
381
|
+
} & CollectionWrites<StoreAsset, TWrites>;
|
|
382
|
+
type AssetsSync<TWrites = unknown> = {
|
|
323
383
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
324
384
|
load(): Promise<void>;
|
|
325
385
|
get(id: string): ReadonlyDeep<StoreAsset> | undefined;
|
|
@@ -328,7 +388,7 @@ type AssetsSync = {
|
|
|
328
388
|
download(fileId: string): Promise<DownloadResult>;
|
|
329
389
|
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
330
390
|
refresh(): void;
|
|
331
|
-
}
|
|
391
|
+
} & CollectionWrites<StoreAsset, TWrites>;
|
|
332
392
|
//#endregion
|
|
333
393
|
//#region src/i18n.d.ts
|
|
334
394
|
type I18nTranslation = {
|
|
@@ -348,8 +408,10 @@ type I18nMessageRegistrationDefinition = {
|
|
|
348
408
|
token: string;
|
|
349
409
|
example?: string | undefined;
|
|
350
410
|
description?: string | undefined;
|
|
351
|
-
variables?: I18nVariableInput[] | undefined;
|
|
352
|
-
|
|
411
|
+
variables?: I18nVariableInput[] | undefined;
|
|
412
|
+
/** always overwrites existing translations for this token */
|
|
413
|
+
translations?: I18nInitialTranslation[] | undefined;
|
|
414
|
+
/** only applied when the token is newly registered (existing translations are preserved) */
|
|
353
415
|
initialTranslations?: I18nInitialTranslation[] | undefined;
|
|
354
416
|
};
|
|
355
417
|
type I18nMessageDef = {
|
|
@@ -368,7 +430,8 @@ type I18nMessages = {
|
|
|
368
430
|
get(ids: readonly string[]): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
369
431
|
getAll(): MaybePromise<ReadonlyDeep<I18nMessage[]>>;
|
|
370
432
|
register(messages: I18nMessageRegistrationDefinition[]): Promise<void>;
|
|
371
|
-
refresh(): void;
|
|
433
|
+
refresh(): void;
|
|
434
|
+
/** Completes refresh$ and detaches from the watcher — called by `Store.destroy()`. */
|
|
372
435
|
destroy(): void;
|
|
373
436
|
};
|
|
374
437
|
//#endregion
|
|
@@ -398,7 +461,11 @@ type RoutesSyncOptions = {
|
|
|
398
461
|
onLoad?: ((ids: string[]) => void) | undefined;
|
|
399
462
|
onRefresh?: ((event: RefreshEvent) => void) | undefined;
|
|
400
463
|
};
|
|
401
|
-
|
|
464
|
+
/**
|
|
465
|
+
* `update` is not the patch a collection's is: `updateContelloRoute` is keyed by the `path` in its
|
|
466
|
+
* input — there is no id — and it replaces the route, so a field left out is cleared, not kept.
|
|
467
|
+
*/
|
|
468
|
+
type Routes<TWrites = unknown> = {
|
|
402
469
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
403
470
|
load(): Promise<void>;
|
|
404
471
|
get(id: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
@@ -406,8 +473,8 @@ type Routes = {
|
|
|
406
473
|
getByPath(path: string): MaybePromise<ReadonlyDeep<StoreRoute> | undefined>;
|
|
407
474
|
getByPath(paths: readonly string[]): MaybePromise<ReadonlyArray<ReadonlyDeep<StoreRoute>>>;
|
|
408
475
|
refresh(): void;
|
|
409
|
-
}
|
|
410
|
-
type RoutesSync = {
|
|
476
|
+
} & CollectionWrites<StoreRoute, TWrites>;
|
|
477
|
+
type RoutesSync<TWrites = unknown> = {
|
|
411
478
|
readonly refresh$: AsyncIterable<RefreshEvent>;
|
|
412
479
|
load(): Promise<void>;
|
|
413
480
|
get(id: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
@@ -415,7 +482,7 @@ type RoutesSync = {
|
|
|
415
482
|
getByPath(path: string): ReadonlyDeep<StoreRoute> | undefined;
|
|
416
483
|
getByPath(paths: readonly string[]): ReadonlyArray<ReadonlyDeep<StoreRoute>>;
|
|
417
484
|
refresh(): void;
|
|
418
|
-
}
|
|
485
|
+
} & CollectionWrites<StoreRoute, TWrites>;
|
|
419
486
|
//#endregion
|
|
420
487
|
//#region src/store.d.ts
|
|
421
488
|
/** Project the model-reference-name union out of a Schema generic, falling back to `string`. */
|
|
@@ -425,6 +492,10 @@ type ModelsOf<TSchema> = TSchema extends {
|
|
|
425
492
|
type CollectionArg<TSchema> = SourceKeysOf<TSchema, 'entity'> | SourceDef<ModelsOf<TSchema>, 'entity'>;
|
|
426
493
|
type SingletonArg<TSchema> = SourceKeysOf<TSchema, 'singleton'> | SourceDef<ModelsOf<TSchema>, 'singleton'>;
|
|
427
494
|
type CollectionRaw<TSchema, TArg> = ExtractSourceResult<Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>>;
|
|
495
|
+
/** The write-input shape the source carries — `unknown` for sources the generator bound no mutations to. */
|
|
496
|
+
type CollectionWritesOf<TSchema, TArg> = ExtractSourceWrites<Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>>;
|
|
497
|
+
type RouteWrites<TSchema> = BuiltInWrites<TSchema, 'route'>;
|
|
498
|
+
type AssetWrites<TSchema> = BuiltInWrites<TSchema, 'asset'>;
|
|
428
499
|
type SingletonRaw<TSchema, TArg> = ExtractSourceResult<Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'singleton'>>>;
|
|
429
500
|
declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
430
501
|
private _client;
|
|
@@ -451,26 +522,26 @@ declare class Store<TSchema extends Schema | undefined = undefined> {
|
|
|
451
522
|
id: string;
|
|
452
523
|
} = CollectionRaw<TSchema, TArg> & {
|
|
453
524
|
id: string;
|
|
454
|
-
}>(sourceOrKey: TArg, options?: CollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): Collection<TMapped
|
|
525
|
+
}>(sourceOrKey: TArg, options?: CollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): Collection<TMapped, CollectionWritesOf<TSchema, TArg>>;
|
|
455
526
|
defineCollectionSync<TArg extends CollectionArg<TSchema>, TMapped extends {
|
|
456
527
|
id: string;
|
|
457
528
|
} = CollectionRaw<TSchema, TArg> & {
|
|
458
529
|
id: string;
|
|
459
|
-
}>(sourceOrKey: TArg, options?: CollectionSyncOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): CollectionSync<TMapped
|
|
530
|
+
}>(sourceOrKey: TArg, options?: CollectionSyncOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): CollectionSync<TMapped, CollectionWritesOf<TSchema, TArg>>;
|
|
460
531
|
defineLazyCollection<TArg extends CollectionArg<TSchema>, TMapped extends {
|
|
461
532
|
id: string;
|
|
462
533
|
} = CollectionRaw<TSchema, TArg> & {
|
|
463
534
|
id: string;
|
|
464
535
|
}>(sourceOrKey: TArg, options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>): LazyCollection<TMapped>;
|
|
465
|
-
defineAssets(options?: AssetsOptions | undefined): Assets
|
|
466
|
-
defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync
|
|
536
|
+
defineAssets(options?: AssetsOptions | undefined): Assets<AssetWrites<TSchema>>;
|
|
537
|
+
defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync<AssetWrites<TSchema>>;
|
|
467
538
|
defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets;
|
|
468
|
-
defineRoutes(options?: RoutesOptions | undefined): Routes
|
|
469
|
-
defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync
|
|
539
|
+
defineRoutes(options?: RoutesOptions | undefined): Routes<RouteWrites<TSchema>>;
|
|
540
|
+
defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync<RouteWrites<TSchema>>;
|
|
470
541
|
defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes;
|
|
471
542
|
defineI18nMessages(def: I18nMessageDef): I18nMessages;
|
|
472
543
|
}
|
|
473
544
|
declare function createStore<TSchema extends Schema | undefined = undefined>(options: CreateStoreOptions<TSchema>): Store<TSchema>;
|
|
474
545
|
//#endregion
|
|
475
|
-
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 };
|
|
546
|
+
export { type Assets, type AssetsOptions, type AssetsSync, type AssetsSyncOptions, type BuiltInWrites, type CacheOptions, type Collection, type CollectionOptions, type CollectionSync, type CollectionSyncOptions, type CollectionWrites, type CreateStoreOptions, type DeleteOptions, type ExtractSourceResult, type ExtractSourceWrites, 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 };
|
|
476
547
|
//# sourceMappingURL=index.d.ts.map
|