@sitecore/sc-contenthub-webclient-sdk 1.2.12 → 1.2.24

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/README.md CHANGED
@@ -1,49 +1,31 @@
1
1
  # Sitecore Content Hub WebClient JS SDK
2
2
 
3
- Sitecore Content Hub WebClient JS SDK, which is a lightweight JS client for Sitecore Content Hub.
3
+ Lightweight JS client for [Sitecore Content Hub](https://doc.sitecore.com/ch/en/developers/cloud-dev/index-en.html).
4
4
 
5
- ## Internal resources
5
+ Environment
6
6
 
7
- - [Backlog](https://stylelabs.atlassian.net/secure/RapidBoard.jspa?rapidView=347&projectKey=ONSJSSDK&view=planning.nodetail&issueLimit=100)
8
- - Slack: #ch-devex-questions
7
+ - Node.js
9
8
 
10
- ## Release process
9
+ Language level
11
10
 
12
- There are currently three build configurations that are specified in `bitbucket-pipelines.yml`
11
+ - ES6
12
+ - ESNext
13
13
 
14
- - A basic build runs each time a pull request is created or updated. This is to ensure that all unit tests are passing before committing any code to `master`.
15
- - Once a pull request has been completed and the code is merged to `master`, an internal build is triggered automatically.
16
- - Public releases can be created by tagging a commit with the following: `release-<major>.<minor>.<patch>` (e.g `release-1.0.0`). Upon a successful build all artifacts are pushed to the public channels.
14
+ Module system
17
15
 
18
- ### To Release
16
+ - CommonJS
17
+ - ESNext
19
18
 
20
- - Add new release tag, `release-<major>.<minor>.<patch>`.
21
- - Trigger a release build to publish final artifacts to the partners feed.
22
- - Cut the release branch, `release\<major>.<minor>.x`.
23
- - Update the Changelog in Documentation repository.
24
- - Update Content Hub repository with new official released version.
25
- - Bump version for the next release.
19
+ ## Installing
26
20
 
27
- ## Documentation
28
-
29
- [Stylelabs.M.Docs reporitory](https://bitbucket.org/stylelabsdev/stylelabs.m.docs/src/master/docfx-website/content/4.0.x/integrations/javascript-sdk/)
30
-
31
- _NOTE: There are multiple paths for various versions that need to be updated independently._
32
-
33
- ## Dev test configuration
21
+ ```bash
22
+ npm install @sitecore/sc-contenthub-webclient-sdk
23
+ ```
34
24
 
35
- Some tests require an instance of ContentHub and a configuration to run.
25
+ ## Documentation
36
26
 
37
- 1. Create a .env file in project root.
38
- 1. Configure an OAuth client in `<path-to-contenthub>/en-us/admin/oauthclients`.
27
+ - [Sitecore Content Hub](https://doc.sitecore.com/ch/en/developers/cloud-dev/index-en.html)
39
28
 
40
- Example .env config:
29
+ - [Sitecore Content Hub SDKs](https://doc.sitecore.com/ch/en/developers/cloud-dev/javascript-sdk.html)
41
30
 
42
- ```
43
- ENDPOINT=https://localhost:5001
44
- OAUTH_CLIENT_ID=jssdk
45
- OAUTH_CLIENT_SECRET=testsecret
46
- USER_NAME=Administrator
47
- USER_PASSWORD=admin
48
- IGNORE_HTTPS_ERRORS=true
49
- ```
31
+ _NOTE: There are multiple paths for various versions._
@@ -203,8 +203,13 @@ 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.isFullyLoaded) {
208
+ return (yield this._relationManager.loadRelationAsync(name, role, true));
209
+ }
210
+ }
211
+ else {
212
+ if (loadOption == member_load_option_1.MemberLoadOption.LazyLoading) {
208
213
  // Scoped to be able to redefine relation as type RelationType does not match IRelation. //TODO generics?
209
214
  const relation = yield this._relationManager.loadRelationAsync(name, role);
210
215
  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.
@@ -73,14 +73,15 @@ class RelationManager {
73
73
  * If the relation does not exist, null will be returned.
74
74
  * @param relationName - The name of the relation
75
75
  * @param role - The role of the relation
76
+ * @param forceLoad - Forces the relation to be loaded even though it has already been loaded before
76
77
  * @returns A promise resolving to the relation or null.
77
78
  */
78
- loadRelationAsync(relationName, role) {
79
+ loadRelationAsync(relationName, role, forceLoad = false) {
79
80
  return __awaiter(this, void 0, void 0, function* () {
80
81
  guard_1.default.stringNotNullOrEmpty(relationName);
81
82
  lazy_loading_manager_1.LazyLoadingManager.ensureLazyLoadingIsPossible(this._entity);
82
83
  let relation = this.getRelation(relationName, role);
83
- if (relation != null) {
84
+ if (relation != null && !forceLoad) {
84
85
  return relation;
85
86
  }
86
87
  relation = yield this.fetchRelationAsync(relationName, role);
@@ -187,6 +188,9 @@ class RelationManager {
187
188
  this._relations[relation.name] = container;
188
189
  }
189
190
  if (container.relationExists(relation.role)) {
191
+ if (container.getRelation(relation.role).isFullyLoaded === false) {
192
+ container.setRelation(relation);
193
+ }
190
194
  return;
191
195
  }
192
196
  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.12",
3
+ "version": "1.2.24",
4
4
  "description": "Sitecore Content Hub WebClient SDK.",
5
5
  "scripts": {
6
6
  "build": "npm run clean && npm run test && tsc && npm run lint",