@contello/store 1.0.4 → 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2026 entwico GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -591,7 +591,11 @@ function createCollection(def, client, updates$, resolver) {
591
591
  },
592
592
  () => clearTimeout(timer)
593
593
  );
594
+ let loaded = false;
594
595
  updates$.subscribe((batch) => {
596
+ if (!loaded) {
597
+ return;
598
+ }
595
599
  const hasOwnModel = batch.entity.has(_def.model);
596
600
  const hasAffectedRefs = batch.events.some((event) => dependencyCollector.getAffectedKeys(event).size > 0);
597
601
  if (!hasOwnModel && !hasAffectedRefs) {
@@ -617,8 +621,11 @@ function createCollection(def, client, updates$, resolver) {
617
621
  scheduleRefresh();
618
622
  },
619
623
  async load() {
620
- scheduleRefresh();
621
624
  const items = await projected.getAll();
625
+ loaded = true;
626
+ if (_def.cache.ttl !== void 0) {
627
+ timer = setTimeout(scheduleRefresh, _def.cache.ttl);
628
+ }
622
629
  def.onLoad?.(items.map((item) => item.id));
623
630
  }
624
631
  };
@@ -1037,7 +1044,11 @@ function createSingleton(def, client, updates$, resolver) {
1037
1044
  },
1038
1045
  () => clearTimeout(timer)
1039
1046
  );
1047
+ let loaded = false;
1040
1048
  updates$.subscribe((batch) => {
1049
+ if (!loaded) {
1050
+ return;
1051
+ }
1041
1052
  const hasOwnModel = batch.entity.has(_def.model);
1042
1053
  const hasAffectedRefs = batch.events.some((event) => dependencyCollector.getAffectedKeys(event).size > 0);
1043
1054
  if (!hasOwnModel && !hasAffectedRefs) {
@@ -1060,8 +1071,11 @@ function createSingleton(def, client, updates$, resolver) {
1060
1071
  scheduleRefresh();
1061
1072
  },
1062
1073
  async load() {
1063
- scheduleRefresh();
1064
1074
  await projected.get();
1075
+ loaded = true;
1076
+ if (_def.cache.ttl !== void 0) {
1077
+ timer = setTimeout(scheduleRefresh, _def.cache.ttl);
1078
+ }
1065
1079
  def.onLoad?.();
1066
1080
  }
1067
1081
  };
package/dist/index.d.cts CHANGED
@@ -154,6 +154,9 @@ type SingletonSyncDef<TOps extends OperationMap | undefined, TModel extends stri
154
154
  onLoad?: (() => void) | undefined;
155
155
  onRefresh?: (() => void) | undefined;
156
156
  };
157
+ type Loadable = {
158
+ load(): Promise<void>;
159
+ };
157
160
  type Singleton<T> = {
158
161
  readonly name: string;
159
162
  readonly refresh$: Observable<void>;
@@ -327,4 +330,4 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
327
330
  }
328
331
  declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: CreateStoreOptions<TOps, TModels>): Store<TOps, TModels>;
329
332
 
330
- 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 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 };
333
+ 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
@@ -154,6 +154,9 @@ type SingletonSyncDef<TOps extends OperationMap | undefined, TModel extends stri
154
154
  onLoad?: (() => void) | undefined;
155
155
  onRefresh?: (() => void) | undefined;
156
156
  };
157
+ type Loadable = {
158
+ load(): Promise<void>;
159
+ };
157
160
  type Singleton<T> = {
158
161
  readonly name: string;
159
162
  readonly refresh$: Observable<void>;
@@ -327,4 +330,4 @@ declare class Store<TOps extends OperationMap | undefined = undefined, TModels e
327
330
  }
328
331
  declare function createStore<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: CreateStoreOptions<TOps, TModels>): Store<TOps, TModels>;
329
332
 
330
- 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 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 };
333
+ 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
@@ -554,7 +554,11 @@ function createCollection(def, client, updates$, resolver) {
554
554
  },
555
555
  () => clearTimeout(timer)
556
556
  );
557
+ let loaded = false;
557
558
  updates$.subscribe((batch) => {
559
+ if (!loaded) {
560
+ return;
561
+ }
558
562
  const hasOwnModel = batch.entity.has(_def.model);
559
563
  const hasAffectedRefs = batch.events.some((event) => dependencyCollector.getAffectedKeys(event).size > 0);
560
564
  if (!hasOwnModel && !hasAffectedRefs) {
@@ -580,8 +584,11 @@ function createCollection(def, client, updates$, resolver) {
580
584
  scheduleRefresh();
581
585
  },
582
586
  async load() {
583
- scheduleRefresh();
584
587
  const items = await projected.getAll();
588
+ loaded = true;
589
+ if (_def.cache.ttl !== void 0) {
590
+ timer = setTimeout(scheduleRefresh, _def.cache.ttl);
591
+ }
585
592
  def.onLoad?.(items.map((item) => item.id));
586
593
  }
587
594
  };
@@ -1000,7 +1007,11 @@ function createSingleton(def, client, updates$, resolver) {
1000
1007
  },
1001
1008
  () => clearTimeout(timer)
1002
1009
  );
1010
+ let loaded = false;
1003
1011
  updates$.subscribe((batch) => {
1012
+ if (!loaded) {
1013
+ return;
1014
+ }
1004
1015
  const hasOwnModel = batch.entity.has(_def.model);
1005
1016
  const hasAffectedRefs = batch.events.some((event) => dependencyCollector.getAffectedKeys(event).size > 0);
1006
1017
  if (!hasOwnModel && !hasAffectedRefs) {
@@ -1023,8 +1034,11 @@ function createSingleton(def, client, updates$, resolver) {
1023
1034
  scheduleRefresh();
1024
1035
  },
1025
1036
  async load() {
1026
- scheduleRefresh();
1027
1037
  await projected.get();
1038
+ loaded = true;
1039
+ if (_def.cache.ttl !== void 0) {
1040
+ timer = setTimeout(scheduleRefresh, _def.cache.ttl);
1041
+ }
1028
1042
  def.onLoad?.();
1029
1043
  }
1030
1044
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/store",
3
- "version": "1.0.4",
3
+ "version": "1.1.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",
@@ -10,21 +10,14 @@
10
10
  "url": "https://github.com/entwico/contello-js",
11
11
  "directory": "packages/store"
12
12
  },
13
- "scripts": {
14
- "build": "tsup",
15
- "generate": "node --env-file=../../.env ../client/dist/cli.js generate",
16
- "lint": "eslint .",
17
- "lint:fix": "eslint . --fix",
18
- "typecheck": "tsc --noEmit"
19
- },
20
13
  "peerDependencies": {
21
14
  "projected": "^2.0.0",
22
15
  "rxjs": "^7.0.0"
23
16
  },
24
17
  "dependencies": {
25
- "@contello/client": "workspace:^",
26
18
  "backoff-rxjs": "^7.0.0",
27
- "lru-cache": "^11.2.7"
19
+ "lru-cache": "^11.2.7",
20
+ "@contello/client": "^1.0.2"
28
21
  },
29
22
  "devDependencies": {
30
23
  "projected": "^2.2.0",
@@ -44,5 +37,12 @@
44
37
  "publishConfig": {
45
38
  "access": "public",
46
39
  "registry": "https://registry.npmjs.org"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "generate": "node --env-file=../../.env ../client/dist/cli.js generate",
44
+ "lint": "eslint .",
45
+ "lint:fix": "eslint . --fix",
46
+ "typecheck": "tsc --noEmit"
47
47
  }
48
- }
48
+ }