@sitecore/sc-contenthub-webclient-sdk 1.2.14 → 1.2.26

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.
@@ -203,8 +203,15 @@ let EntityBase = class EntityBase {
203
203
  return __awaiter(this, void 0, void 0, function* () {
204
204
  guard_1.default.stringNotNullOrEmpty(name);
205
205
  const relation = this.getRelation(name, role, true);
206
- if (relation == null && loadOption == member_load_option_1.MemberLoadOption.LazyLoading) {
207
- {
206
+ if (relation) {
207
+ if ((relation_1.RelationBase.isChildToManyParentsRelation(relation) ||
208
+ relation_1.RelationBase.isParentToManyChildrenRelation(relation)) &&
209
+ !relation.isFullyLoaded) {
210
+ return (yield this._relationManager.loadRelationAsync(name, role, true));
211
+ }
212
+ }
213
+ else {
214
+ if (loadOption == member_load_option_1.MemberLoadOption.LazyLoading) {
208
215
  // Scoped to be able to redefine relation as type RelationType does not match IRelation. //TODO generics?
209
216
  const relation = yield this._relationManager.loadRelationAsync(name, role);
210
217
  if (relation == null) {
@@ -28,9 +28,10 @@ export declare class RelationManager {
28
28
  * If the relation does not exist, null will be returned.
29
29
  * @param relationName - The name of the relation
30
30
  * @param role - The role of the relation
31
+ * @param forceLoad - Forces the relation to be loaded even though it has already been loaded before
31
32
  * @returns A promise resolving to the relation or null.
32
33
  */
33
- loadRelationAsync(relationName: string, role?: RelationRole): NullableResultPromise<IRelation>;
34
+ loadRelationAsync(relationName: string, role?: RelationRole, forceLoad?: boolean): NullableResultPromise<IRelation>;
34
35
  /**
35
36
  * Loads the specified relations.
36
37
  * It will only load if it is actually missing relations and does not overwrite existing relations.
@@ -22,6 +22,7 @@ const property_load_option_1 = require("../querying/property-load-option");
22
22
  const relation_load_option_1 = require("../querying/relation-load-option");
23
23
  const relation_specification_1 = require("../querying/relation-specification");
24
24
  const lazy_loading_manager_1 = require("./lazy-loading-manager");
25
+ const relation_1 = require("./relation");
25
26
  const relation_container_1 = require("./relation-container");
26
27
  class RelationManager {
27
28
  constructor(client, relations, entity) {
@@ -73,14 +74,15 @@ class RelationManager {
73
74
  * If the relation does not exist, null will be returned.
74
75
  * @param relationName - The name of the relation
75
76
  * @param role - The role of the relation
77
+ * @param forceLoad - Forces the relation to be loaded even though it has already been loaded before
76
78
  * @returns A promise resolving to the relation or null.
77
79
  */
78
- loadRelationAsync(relationName, role) {
80
+ loadRelationAsync(relationName, role, forceLoad = false) {
79
81
  return __awaiter(this, void 0, void 0, function* () {
80
82
  guard_1.default.stringNotNullOrEmpty(relationName);
81
83
  lazy_loading_manager_1.LazyLoadingManager.ensureLazyLoadingIsPossible(this._entity);
82
84
  let relation = this.getRelation(relationName, role);
83
- if (relation != null) {
85
+ if (relation != null && !forceLoad) {
84
86
  return relation;
85
87
  }
86
88
  relation = yield this.fetchRelationAsync(relationName, role);
@@ -187,6 +189,12 @@ class RelationManager {
187
189
  this._relations[relation.name] = container;
188
190
  }
189
191
  if (container.relationExists(relation.role)) {
192
+ const relationInRole = container.getRelation(relation.role);
193
+ if ((relation_1.RelationBase.isChildToManyParentsRelation(relationInRole) ||
194
+ relation_1.RelationBase.isParentToManyChildrenRelation(relationInRole)) &&
195
+ !relationInRole.isFullyLoaded) {
196
+ container.setRelation(relation);
197
+ }
190
198
  return;
191
199
  }
192
200
  container.setRelation(relation);
@@ -11,6 +11,11 @@ export interface IChildToManyParentsRelation extends IChildRelation, IToManyRela
11
11
  * The list of parent ids.
12
12
  */
13
13
  readonly parents: Array<number>;
14
+ /**
15
+ * When related items are partially loaded, this value will be set
16
+ * to indicate how many related items there are in total.
17
+ */
18
+ parentTotal?: number;
14
19
  /**
15
20
  * Gets the properties for a parent.
16
21
  *
@@ -22,10 +27,12 @@ export interface IChildToManyParentsRelation extends IChildRelation, IToManyRela
22
27
  export declare class ChildToManyParentsRelation extends ChildRelationBase implements IChildToManyParentsRelation {
23
28
  private _parents;
24
29
  readonly role: RelationRole;
30
+ readonly parentTotal?: number;
25
31
  readonly isMultiValue: boolean;
32
+ get isFullyLoaded(): boolean;
26
33
  get isDirty(): boolean;
27
34
  get parents(): Array<number>;
28
- constructor(name: string, properties?: Nullable<MapNumberTo<MapStringTo<Object_Unknown>>>, client?: IContentHubClient);
35
+ constructor(name: string, properties?: Nullable<MapNumberTo<MapStringTo<Object_Unknown>>>, client?: IContentHubClient, parentTotal?: number);
29
36
  getIds(): Array<number>;
30
37
  setIds(ids: Array<number>): void;
31
38
  clear(): void;
@@ -19,11 +19,15 @@ const entity_load_configuration_1 = require("../../querying/entity-load-configur
19
19
  const relation_1 = require("../relation");
20
20
  const relation_role_1 = require("../relation-role");
21
21
  class ChildToManyParentsRelation extends relation_1.ChildRelationBase {
22
- constructor(name, properties = null, client) {
22
+ constructor(name, properties = null, client, parentTotal) {
23
23
  super(name, properties, client);
24
24
  this._parents = [];
25
25
  this.role = relation_role_1.RelationRole.Child;
26
26
  this.isMultiValue = true;
27
+ this.parentTotal = parentTotal;
28
+ }
29
+ get isFullyLoaded() {
30
+ return this.parentTotal == null || this._parents.length === this.parentTotal;
27
31
  }
28
32
  get isDirty() {
29
33
  if (!this.isTracking) {
@@ -11,6 +11,11 @@ export interface IParentToManyChildrenRelation extends IParentRelation, IToManyR
11
11
  * The list of children ids.
12
12
  */
13
13
  readonly children: Array<number>;
14
+ /**
15
+ * When related items are partially loaded, this value will be set
16
+ * to indicate how many related items there are in total.
17
+ */
18
+ childTotal?: number;
14
19
  /**
15
20
  * Gets the properties for a child.
16
21
  *
@@ -22,10 +27,12 @@ export interface IParentToManyChildrenRelation extends IParentRelation, IToManyR
22
27
  export declare class ParentToManyChildrenRelation extends RelationBase implements IParentToManyChildrenRelation {
23
28
  private _children;
24
29
  readonly role: RelationRole;
30
+ readonly childTotal?: number;
25
31
  readonly isMultiValue: boolean;
32
+ get isFullyLoaded(): boolean;
26
33
  get isDirty(): boolean;
27
34
  get children(): Array<number>;
28
- constructor(name: string, properties?: Nullable<MapNumberTo<MapStringTo<Object_Unknown>>>, client?: IContentHubClient);
35
+ constructor(name: string, properties?: Nullable<MapNumberTo<MapStringTo<Object_Unknown>>>, client?: IContentHubClient, childTotal?: number);
29
36
  getIds(): Array<number>;
30
37
  setIds(ids: Array<number>): void;
31
38
  clear(): void;
@@ -19,11 +19,15 @@ const entity_load_configuration_1 = require("../../querying/entity-load-configur
19
19
  const relation_1 = require("../relation");
20
20
  const relation_role_1 = require("../relation-role");
21
21
  class ParentToManyChildrenRelation extends relation_1.RelationBase {
22
- constructor(name, properties = null, client) {
22
+ constructor(name, properties = null, client, childTotal) {
23
23
  super(name, properties, client);
24
24
  this._children = [];
25
25
  this.role = relation_role_1.RelationRole.Parent;
26
26
  this.isMultiValue = true;
27
+ this.childTotal = childTotal;
28
+ }
29
+ get isFullyLoaded() {
30
+ return this.childTotal == null || this._children.length === this.childTotal;
27
31
  }
28
32
  get isDirty() {
29
33
  if (!this.isTracking) {
@@ -3,6 +3,10 @@ import { IRelation } from "../relation";
3
3
  * Base interface for relation that are associated with many entities.
4
4
  */
5
5
  export interface IToManyRelation extends IRelation {
6
+ /**
7
+ * Indicates whether all the related items are loaded.
8
+ */
9
+ isFullyLoaded: boolean;
6
10
  /**
7
11
  * Adds an id to the relation's values.
8
12
  * @param id - The id to add
@@ -10,6 +10,10 @@ export interface IRelationLoadOption extends ILoadOption {
10
10
  * This is only useful when {@link LoadOption} is {@link LoadOption.Custom}.
11
11
  */
12
12
  relations: Array<IRelationSpecification>;
13
+ /**
14
+ * Can limit the number of related items that are returned.
15
+ */
16
+ maxRelatedItems?: number;
13
17
  /**
14
18
  * Creates a deep clone of this instance.
15
19
  */
@@ -26,6 +30,7 @@ export declare class RelationLoadOption implements IRelationLoadOption {
26
30
  static readonly All: Readonly<IRelationLoadOption>;
27
31
  loadOption: LoadOption;
28
32
  relations: Array<IRelationSpecification>;
33
+ maxRelatedItems?: number;
29
34
  constructor(param?: LoadOption | Array<string> | Array<IRelationSpecification> | RelationLoadOption);
30
35
  deepClone(): IRelationLoadOption;
31
36
  }
@@ -67,6 +67,10 @@ __decorate([
67
67
  (0, ta_json_1.JsonElementType)(relation_specification_1.RelationSpecification),
68
68
  __metadata("design:type", Array)
69
69
  ], RelationLoadOption.prototype, "relations", void 0);
70
+ __decorate([
71
+ (0, ta_json_1.JsonProperty)("max_related_items"),
72
+ __metadata("design:type", Number)
73
+ ], RelationLoadOption.prototype, "maxRelatedItems", void 0);
70
74
  RelationLoadOption = RelationLoadOption_1 = __decorate([
71
75
  (0, ta_json_1.JsonObject)(),
72
76
  __metadata("design:paramtypes", [Object])
@@ -90,11 +90,11 @@ class RelationMapper {
90
90
  ids.push(id);
91
91
  properties[id] = r.properties;
92
92
  }
93
- subRelation = new parent_to_many_children_relation_1.ParentToManyChildrenRelation(name, properties, this._client);
93
+ subRelation = new parent_to_many_children_relation_1.ParentToManyChildrenRelation(name, properties, this._client, relationResource.childTotal);
94
94
  subRelation.setIds(ids);
95
95
  }
96
96
  else {
97
- subRelation = new parent_to_many_children_relation_1.ParentToManyChildrenRelation(name, null, this._client);
97
+ subRelation = new parent_to_many_children_relation_1.ParentToManyChildrenRelation(name, null, this._client, relationResource.childTotal);
98
98
  }
99
99
  result = subRelation;
100
100
  }
@@ -125,11 +125,11 @@ class RelationMapper {
125
125
  ids.push(id);
126
126
  properties[id] = r.properties;
127
127
  }
128
- subRelation = new child_to_many_parents_relation_1.ChildToManyParentsRelation(name, properties, this._client);
128
+ subRelation = new child_to_many_parents_relation_1.ChildToManyParentsRelation(name, properties, this._client, relationResource.parentTotal);
129
129
  subRelation.setIds(ids);
130
130
  }
131
131
  else {
132
- subRelation = new child_to_many_parents_relation_1.ChildToManyParentsRelation(name, null, this._client);
132
+ subRelation = new child_to_many_parents_relation_1.ChildToManyParentsRelation(name, null, this._client, relationResource.parentTotal);
133
133
  }
134
134
  result = subRelation;
135
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore/sc-contenthub-webclient-sdk",
3
- "version": "1.2.14",
3
+ "version": "1.2.26",
4
4
  "description": "Sitecore Content Hub WebClient SDK.",
5
5
  "scripts": {
6
6
  "build": "npm run clean && npm run test && tsc && npm run lint",