@contello/store 1.2.0 → 1.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 +9 -0
- package/dist/fragments.js +12 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +17 -0
- package/fragments/asset.gql +2 -22
- package/package.json +7 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* resolved absolute paths to the `.gql` fragment files that store-backed
|
|
3
|
+
* codegen should include. combines media's primitives with store's own
|
|
4
|
+
* `StoreAsset` / `StoreRoute` fragments. intended for use in a project's
|
|
5
|
+
* codegen `documents` config.
|
|
6
|
+
*/
|
|
7
|
+
declare const fragments: string[];
|
|
8
|
+
|
|
9
|
+
export { fragments };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/fragments.ts
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { fragments as mediaFragments } from "@contello/media/fragments";
|
|
4
|
+
var packageRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
5
|
+
var fragments = [
|
|
6
|
+
...mediaFragments,
|
|
7
|
+
`${packageRoot}fragments/asset.gql`,
|
|
8
|
+
`${packageRoot}fragments/route.gql`
|
|
9
|
+
];
|
|
10
|
+
export {
|
|
11
|
+
fragments
|
|
12
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
37
37
|
|
|
38
38
|
// src/store.ts
|
|
39
39
|
var import_client = require("@contello/client");
|
|
40
|
+
var import_media = require("@contello/media");
|
|
40
41
|
|
|
41
42
|
// src/assets.ts
|
|
42
43
|
var import_projected = require("projected");
|
|
@@ -398,6 +399,9 @@ function createAssetsCollection(def, client, updates$) {
|
|
|
398
399
|
download(fileId) {
|
|
399
400
|
return client.download(fileId);
|
|
400
401
|
},
|
|
402
|
+
proxyHls(path, signal) {
|
|
403
|
+
return client.proxyHls(path, signal);
|
|
404
|
+
},
|
|
401
405
|
refresh() {
|
|
402
406
|
scheduleRefresh();
|
|
403
407
|
},
|
|
@@ -1295,6 +1299,7 @@ var Store = class {
|
|
|
1295
1299
|
_client;
|
|
1296
1300
|
_resolver;
|
|
1297
1301
|
_watcher;
|
|
1302
|
+
_media;
|
|
1298
1303
|
updates$;
|
|
1299
1304
|
constructor(options) {
|
|
1300
1305
|
const { url, project, token, operations } = options;
|
|
@@ -1312,8 +1317,20 @@ var Store = class {
|
|
|
1312
1317
|
this._resolver = new ModelResolver(options.models);
|
|
1313
1318
|
this._watcher = createInternalWatcher(this._client, this._resolver);
|
|
1314
1319
|
this.updates$ = this._watcher.updates$;
|
|
1320
|
+
this._media = options.media ? (0, import_media.createMediaResolver)(options.media) : void 0;
|
|
1315
1321
|
this.ping = () => this._client.ping();
|
|
1316
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
|
+
}
|
|
1317
1334
|
async init() {
|
|
1318
1335
|
await wrap("store:init", () => this._client.init());
|
|
1319
1336
|
this._watcher.start();
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { OperationMap, ContelloClient, ConnectionEvents, UploadData, UploadMetadata, UploadOptions, DownloadResult } from '@contello/client';
|
|
1
|
+
import { OperationMap, ContelloClient, ConnectionEvents, UploadData, UploadMetadata, UploadOptions, DownloadResult, ProxyResult } from '@contello/client';
|
|
2
|
+
import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
|
|
2
3
|
import { Observable } from 'rxjs';
|
|
3
4
|
import { MaybePromise } from 'projected';
|
|
4
5
|
|
|
@@ -112,6 +113,7 @@ type CreateStoreOptions<TOps extends OperationMap | undefined = undefined, TMode
|
|
|
112
113
|
onReconnecting?: (() => void) | undefined;
|
|
113
114
|
onError?: ((error: unknown) => void) | undefined;
|
|
114
115
|
connectionEvents?: ConnectionEvents | undefined;
|
|
116
|
+
media?: MediaResolverOptions | undefined;
|
|
115
117
|
};
|
|
116
118
|
/** Cache options for non-lazy collections and singletons. */
|
|
117
119
|
type CacheOptions = {
|
|
@@ -254,6 +256,7 @@ type Assets = {
|
|
|
254
256
|
get(ids: string[]): Promise<StoreAsset[]>;
|
|
255
257
|
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
256
258
|
download(fileId: string): Promise<DownloadResult>;
|
|
259
|
+
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
257
260
|
refresh(): void;
|
|
258
261
|
clear(): void;
|
|
259
262
|
};
|
|
@@ -310,12 +313,27 @@ type Routes = {
|
|
|
310
313
|
clear(): void;
|
|
311
314
|
};
|
|
312
315
|
|
|
313
|
-
|
|
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> {
|
|
314
325
|
private _client;
|
|
315
326
|
private _resolver;
|
|
316
327
|
private _watcher;
|
|
328
|
+
private _media;
|
|
317
329
|
readonly updates$: Observable<UpdateBatch>;
|
|
318
330
|
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;
|
|
319
337
|
init(): Promise<void>;
|
|
320
338
|
destroy(): Promise<void>;
|
|
321
339
|
defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
|
|
@@ -334,6 +352,6 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
|
|
|
334
352
|
defineI18nMessages(def: I18nMessageDef): I18nMessages;
|
|
335
353
|
ping: () => Promise<void>;
|
|
336
354
|
}
|
|
337
|
-
declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>
|
|
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>>;
|
|
338
356
|
|
|
339
357
|
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,4 +1,5 @@
|
|
|
1
|
-
import { OperationMap, ContelloClient, ConnectionEvents, UploadData, UploadMetadata, UploadOptions, DownloadResult } from '@contello/client';
|
|
1
|
+
import { OperationMap, ContelloClient, ConnectionEvents, UploadData, UploadMetadata, UploadOptions, DownloadResult, ProxyResult } from '@contello/client';
|
|
2
|
+
import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
|
|
2
3
|
import { Observable } from 'rxjs';
|
|
3
4
|
import { MaybePromise } from 'projected';
|
|
4
5
|
|
|
@@ -112,6 +113,7 @@ type CreateStoreOptions<TOps extends OperationMap | undefined = undefined, TMode
|
|
|
112
113
|
onReconnecting?: (() => void) | undefined;
|
|
113
114
|
onError?: ((error: unknown) => void) | undefined;
|
|
114
115
|
connectionEvents?: ConnectionEvents | undefined;
|
|
116
|
+
media?: MediaResolverOptions | undefined;
|
|
115
117
|
};
|
|
116
118
|
/** Cache options for non-lazy collections and singletons. */
|
|
117
119
|
type CacheOptions = {
|
|
@@ -254,6 +256,7 @@ type Assets = {
|
|
|
254
256
|
get(ids: string[]): Promise<StoreAsset[]>;
|
|
255
257
|
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
256
258
|
download(fileId: string): Promise<DownloadResult>;
|
|
259
|
+
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
257
260
|
refresh(): void;
|
|
258
261
|
clear(): void;
|
|
259
262
|
};
|
|
@@ -310,12 +313,27 @@ type Routes = {
|
|
|
310
313
|
clear(): void;
|
|
311
314
|
};
|
|
312
315
|
|
|
313
|
-
|
|
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> {
|
|
314
325
|
private _client;
|
|
315
326
|
private _resolver;
|
|
316
327
|
private _watcher;
|
|
328
|
+
private _media;
|
|
317
329
|
readonly updates$: Observable<UpdateBatch>;
|
|
318
330
|
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;
|
|
319
337
|
init(): Promise<void>;
|
|
320
338
|
destroy(): Promise<void>;
|
|
321
339
|
defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
|
|
@@ -334,6 +352,6 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
|
|
|
334
352
|
defineI18nMessages(def: I18nMessageDef): I18nMessages;
|
|
335
353
|
ping: () => Promise<void>;
|
|
336
354
|
}
|
|
337
|
-
declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>
|
|
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>>;
|
|
338
356
|
|
|
339
357
|
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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/store.ts
|
|
2
2
|
import { createContelloClient } from "@contello/client";
|
|
3
|
+
import { createMediaResolver } from "@contello/media";
|
|
3
4
|
|
|
4
5
|
// src/assets.ts
|
|
5
6
|
import { ProjectedLazyMap } from "projected";
|
|
@@ -361,6 +362,9 @@ function createAssetsCollection(def, client, updates$) {
|
|
|
361
362
|
download(fileId) {
|
|
362
363
|
return client.download(fileId);
|
|
363
364
|
},
|
|
365
|
+
proxyHls(path, signal) {
|
|
366
|
+
return client.proxyHls(path, signal);
|
|
367
|
+
},
|
|
364
368
|
refresh() {
|
|
365
369
|
scheduleRefresh();
|
|
366
370
|
},
|
|
@@ -1258,6 +1262,7 @@ var Store = class {
|
|
|
1258
1262
|
_client;
|
|
1259
1263
|
_resolver;
|
|
1260
1264
|
_watcher;
|
|
1265
|
+
_media;
|
|
1261
1266
|
updates$;
|
|
1262
1267
|
constructor(options) {
|
|
1263
1268
|
const { url, project, token, operations } = options;
|
|
@@ -1275,8 +1280,20 @@ var Store = class {
|
|
|
1275
1280
|
this._resolver = new ModelResolver(options.models);
|
|
1276
1281
|
this._watcher = createInternalWatcher(this._client, this._resolver);
|
|
1277
1282
|
this.updates$ = this._watcher.updates$;
|
|
1283
|
+
this._media = options.media ? createMediaResolver(options.media) : void 0;
|
|
1278
1284
|
this.ping = () => this._client.ping();
|
|
1279
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
|
+
}
|
|
1280
1297
|
async init() {
|
|
1281
1298
|
await wrap("store:init", () => this._client.init());
|
|
1282
1299
|
this._watcher.start();
|
package/fragments/asset.gql
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
fragment StoreFile on ContelloFile {
|
|
2
|
-
|
|
3
|
-
mimeType
|
|
4
|
-
metadata {
|
|
5
|
-
... on ContelloImageMetadata {
|
|
6
|
-
width
|
|
7
|
-
height
|
|
8
|
-
}
|
|
9
|
-
... on ContelloVideoMetadata {
|
|
10
|
-
width
|
|
11
|
-
height
|
|
12
|
-
}
|
|
13
|
-
}
|
|
2
|
+
...MediaFile
|
|
14
3
|
}
|
|
15
4
|
|
|
16
5
|
fragment StoreAsset on ContelloAsset {
|
|
17
|
-
|
|
18
|
-
original {
|
|
19
|
-
...StoreFile
|
|
20
|
-
}
|
|
21
|
-
preview {
|
|
22
|
-
...StoreFile
|
|
23
|
-
}
|
|
24
|
-
optimized {
|
|
25
|
-
...StoreFile
|
|
26
|
-
}
|
|
6
|
+
...MediaAsset
|
|
27
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/store",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Framework-agnostic store for Contello CMS with reactive collections and automatic dependency tracking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"backoff-rxjs": "^7.0.0",
|
|
19
19
|
"lru-cache": "^11.3.5",
|
|
20
|
-
"@contello/client": "^1.0
|
|
20
|
+
"@contello/client": "^1.1.0",
|
|
21
|
+
"@contello/media": "^1.0.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"projected": "^2.2.1",
|
|
@@ -32,6 +33,10 @@
|
|
|
32
33
|
".": {
|
|
33
34
|
"import": "./dist/index.js",
|
|
34
35
|
"require": "./dist/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./fragments": {
|
|
38
|
+
"import": "./dist/fragments.js",
|
|
39
|
+
"types": "./dist/fragments.d.ts"
|
|
35
40
|
}
|
|
36
41
|
},
|
|
37
42
|
"publishConfig": {
|