@contello/store 1.4.0 → 1.4.2

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 CHANGED
@@ -1299,8 +1299,8 @@ var Store = class {
1299
1299
  _client;
1300
1300
  _resolver;
1301
1301
  _watcher;
1302
- _media;
1303
1302
  updates$;
1303
+ media;
1304
1304
  constructor(options) {
1305
1305
  const { url, project, token, operations } = options;
1306
1306
  this._client = (0, import_client.createContelloClient)({
@@ -1317,20 +1317,9 @@ var Store = class {
1317
1317
  this._resolver = new ModelResolver(options.models);
1318
1318
  this._watcher = createInternalWatcher(this._client, this._resolver);
1319
1319
  this.updates$ = this._watcher.updates$;
1320
- this._media = options.media ? (0, import_media.createMediaResolver)(options.media) : void 0;
1320
+ this.media = (0, import_media.createMediaResolver)(options.media ?? {});
1321
1321
  this.ping = () => this._client.ping();
1322
1322
  }
1323
- /**
1324
- * Returns the configured `MediaResolver`. Throws if `createStore` was called
1325
- * without a `media` option. Type-narrows to `never` when `THasMedia` is `false`,
1326
- * so compile-time consumers get an error on access without configuration.
1327
- */
1328
- get media() {
1329
- if (!this._media) {
1330
- throw new Error("store.media requires the `media` option to be configured in createStore()");
1331
- }
1332
- return this._media;
1333
- }
1334
1323
  async init() {
1335
1324
  await wrap("store:init", () => this._client.init());
1336
1325
  this._watcher.start();
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OperationMap, ContelloClient, ConnectionEvents, UploadData, UploadMetadata, UploadOptions, DownloadResult, ProxyResult } from '@contello/client';
2
- import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
2
+ import { MediaResolverOptions, MediaResolver } from '@contello/media';
3
3
  import { Observable } from 'rxjs';
4
4
  import { MaybePromise } from 'projected';
5
5
 
@@ -313,27 +313,13 @@ type Routes = {
313
313
  clear(): void;
314
314
  };
315
315
 
316
- type HasMedia<O> = O extends {
317
- media: MediaResolverOptions;
318
- } ? true : false;
319
- type HasMediaFallback<O> = O extends {
320
- media: {
321
- fallback: ImageDef;
322
- };
323
- } ? true : false;
324
- declare class Store<TOps extends OperationMap | undefined = undefined, TModels extends string = string, THasMedia extends boolean = false, THasMediaFallback extends boolean = false> {
316
+ declare class Store<TOps extends OperationMap | undefined = undefined, TModels extends string = string> {
325
317
  private _client;
326
318
  private _resolver;
327
319
  private _watcher;
328
- private _media;
329
320
  readonly updates$: Observable<UpdateBatch>;
321
+ readonly media: MediaResolver;
330
322
  constructor(options: CreateStoreOptions<TOps, TModels>);
331
- /**
332
- * Returns the configured `MediaResolver`. Throws if `createStore` was called
333
- * without a `media` option. Type-narrows to `never` when `THasMedia` is `false`,
334
- * so compile-time consumers get an error on access without configuration.
335
- */
336
- get media(): THasMedia extends true ? MediaResolver<THasMediaFallback> : never;
337
323
  init(): Promise<void>;
338
324
  destroy(): Promise<void>;
339
325
  defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
@@ -352,6 +338,6 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
352
338
  defineI18nMessages(def: I18nMessageDef): I18nMessages;
353
339
  ping: () => Promise<void>;
354
340
  }
355
- declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string, O extends CreateStoreOptions<TOps, TModels> = CreateStoreOptions<TOps, TModels>>(options: O): Store<TOps, TModels, HasMedia<O>, HasMediaFallback<O>>;
341
+ declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: CreateStoreOptions<TOps, TModels>): Store<TOps, TModels>;
356
342
 
357
343
  export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionDef, type CollectionSync, type CollectionSyncDef, type CreateStoreOptions, type Fetchable, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionDef, type Loadable, type MapperContext, type RouteCollectionOptions, type Routes, type Singleton, type SingletonDef, type SingletonSync, type SingletonSyncDef, 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
@@ -1,5 +1,5 @@
1
1
  import { OperationMap, ContelloClient, ConnectionEvents, UploadData, UploadMetadata, UploadOptions, DownloadResult, ProxyResult } from '@contello/client';
2
- import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
2
+ import { MediaResolverOptions, MediaResolver } from '@contello/media';
3
3
  import { Observable } from 'rxjs';
4
4
  import { MaybePromise } from 'projected';
5
5
 
@@ -313,27 +313,13 @@ type Routes = {
313
313
  clear(): void;
314
314
  };
315
315
 
316
- type HasMedia<O> = O extends {
317
- media: MediaResolverOptions;
318
- } ? true : false;
319
- type HasMediaFallback<O> = O extends {
320
- media: {
321
- fallback: ImageDef;
322
- };
323
- } ? true : false;
324
- declare class Store<TOps extends OperationMap | undefined = undefined, TModels extends string = string, THasMedia extends boolean = false, THasMediaFallback extends boolean = false> {
316
+ declare class Store<TOps extends OperationMap | undefined = undefined, TModels extends string = string> {
325
317
  private _client;
326
318
  private _resolver;
327
319
  private _watcher;
328
- private _media;
329
320
  readonly updates$: Observable<UpdateBatch>;
321
+ readonly media: MediaResolver;
330
322
  constructor(options: CreateStoreOptions<TOps, TModels>);
331
- /**
332
- * Returns the configured `MediaResolver`. Throws if `createStore` was called
333
- * without a `media` option. Type-narrows to `never` when `THasMedia` is `false`,
334
- * so compile-time consumers get an error on access without configuration.
335
- */
336
- get media(): THasMedia extends true ? MediaResolver<THasMediaFallback> : never;
337
323
  init(): Promise<void>;
338
324
  destroy(): Promise<void>;
339
325
  defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
@@ -352,6 +338,6 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
352
338
  defineI18nMessages(def: I18nMessageDef): I18nMessages;
353
339
  ping: () => Promise<void>;
354
340
  }
355
- declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string, O extends CreateStoreOptions<TOps, TModels> = CreateStoreOptions<TOps, TModels>>(options: O): Store<TOps, TModels, HasMedia<O>, HasMediaFallback<O>>;
341
+ declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: CreateStoreOptions<TOps, TModels>): Store<TOps, TModels>;
356
342
 
357
343
  export { type AssetCollectionOptions, type Assets, type CacheOptions, type Collection, type CollectionDef, type CollectionSync, type CollectionSyncDef, type CreateStoreOptions, type Fetchable, type I18nInitialTranslation, type I18nMessage, type I18nMessageDef, type I18nMessageRegistrationDefinition, type I18nMessages, type I18nTranslation, type I18nVariableInput, type LazyCacheOptions, type LazyCollection, type LazyCollectionDef, type Loadable, type MapperContext, type RouteCollectionOptions, type Routes, type Singleton, type SingletonDef, type SingletonSync, type SingletonSyncDef, 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.js CHANGED
@@ -1262,8 +1262,8 @@ var Store = class {
1262
1262
  _client;
1263
1263
  _resolver;
1264
1264
  _watcher;
1265
- _media;
1266
1265
  updates$;
1266
+ media;
1267
1267
  constructor(options) {
1268
1268
  const { url, project, token, operations } = options;
1269
1269
  this._client = createContelloClient({
@@ -1280,20 +1280,9 @@ var Store = class {
1280
1280
  this._resolver = new ModelResolver(options.models);
1281
1281
  this._watcher = createInternalWatcher(this._client, this._resolver);
1282
1282
  this.updates$ = this._watcher.updates$;
1283
- this._media = options.media ? createMediaResolver(options.media) : void 0;
1283
+ this.media = createMediaResolver(options.media ?? {});
1284
1284
  this.ping = () => this._client.ping();
1285
1285
  }
1286
- /**
1287
- * Returns the configured `MediaResolver`. Throws if `createStore` was called
1288
- * without a `media` option. Type-narrows to `never` when `THasMedia` is `false`,
1289
- * so compile-time consumers get an error on access without configuration.
1290
- */
1291
- get media() {
1292
- if (!this._media) {
1293
- throw new Error("store.media requires the `media` option to be configured in createStore()");
1294
- }
1295
- return this._media;
1296
- }
1297
1286
  async init() {
1298
1287
  await wrap("store:init", () => this._client.init());
1299
1288
  this._watcher.start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/store",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Framework-agnostic store for Contello CMS with reactive collections and automatic dependency tracking",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,17 +12,19 @@
12
12
  },
13
13
  "peerDependencies": {
14
14
  "projected": "^2.0.0",
15
- "rxjs": "^7.0.0"
15
+ "rxjs": "^7.0.0",
16
+ "@contello/client": "^1.1.0",
17
+ "@contello/media": "^1.0.0"
16
18
  },
17
19
  "dependencies": {
18
20
  "backoff-rxjs": "^7.0.0",
19
- "lru-cache": "^11.3.5",
20
- "@contello/client": "^1.1.0",
21
- "@contello/media": "^1.0.0"
21
+ "lru-cache": "^11.3.5"
22
22
  },
23
23
  "devDependencies": {
24
24
  "projected": "^2.2.1",
25
- "rxjs": "^7.8.2"
25
+ "rxjs": "^7.8.2",
26
+ "@contello/client": "^1.1.0",
27
+ "@contello/media": "^1.0.0"
26
28
  },
27
29
  "files": [
28
30
  "dist",