Skip to content

Commit 47f1bad

Browse files
authored
Merge pull request #182 from contentstack/fix/DX-3010
fix: method chaining for entry queryable class methods
2 parents cfcbe19 + 9943b00 commit 47f1bad

File tree

10 files changed

+1116
-1000
lines changed

10 files changed

+1116
-1000
lines changed

.talismanrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ fileignoreconfig:
88
- filename: src/lib/query.ts
99
checksum: c4529069bc974d15c104303c5ae573c9341185a869c612ab07f0ee7f42e8b149
1010
- filename: package-lock.json
11-
checksum: 815fd2251550d87a0f113dd2e14266879be37af3a264041e871436a1cc84ae1c
11+
checksum: f9c5af529a2c4c6576d67bd6c25dc6c3088ddedf2482757d382953f2d4521995
12+
- filename: src/lib/entries.ts
13+
checksum: 1c9a58570f26d3e53526e89b404581a523d3f035234bc099fda96d144dee40f6
14+
- filename: src/lib/entry.ts
15+
checksum: 8826fe3147a2c640b0780dae02345611ed24e562562e7df7b3785cb0fa6f1f14
1216
- filename: .husky/pre-commit
1317
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
1418
version: ""

package-lock.json

Lines changed: 854 additions & 810 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/entries.ts

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AxiosInstance, getData } from '@contentstack/core';
2-
import { EntryQueryable } from './entry-queryable';
32
import { Query } from './query';
3+
import { BaseQuery } from './base-query';
44

5-
export class Entries extends EntryQueryable {
5+
export class Entries extends BaseQuery {
66
private _contentTypeUid: string;
77

88
constructor(client: AxiosInstance, contentTypeUid: string) {
@@ -14,35 +14,62 @@ export class Entries extends EntryQueryable {
1414
}
1515

1616
/**
17-
* @method includeFallback
17+
* @method except
1818
* @memberof Entries
19-
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
19+
* @description Excludes specific field/fields of an entry
20+
* @example
21+
* import contentstack from '@contentstack/delivery-sdk'
22+
*
23+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
24+
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
25+
*
26+
* @param {string} fieldUid - field uid to exclude
27+
* @returns {Entries} - returns Entries object for chaining method calls
28+
*/
29+
except(fieldUid: string|string[]): this {
30+
if (Array.isArray(fieldUid)) {
31+
let i = 0;
32+
for (const uid of fieldUid) {
33+
this._queryParams[`except[BASE][${i}]`] = uid;
34+
i++;
35+
}
36+
} else {
37+
this._queryParams["except[BASE][]"] = fieldUid;
38+
}
39+
40+
return this;
41+
}
42+
43+
/**
44+
* @method includeBranch
45+
* @memberof Entries
46+
* @description Includes the branch in result
2047
* @returns {Entries}
2148
* @example
2249
* import contentstack from '@contentstack/delivery-sdk'
2350
*
2451
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
25-
* const result = await stack.contentType(contentType_uid).entry().includeFallback().find();
52+
* const result = await stack.contentType(contentType_uid).entry().includeBranch().find();
2653
*/
27-
includeFallback(): Entries {
28-
this._queryParams.include_fallback = 'true';
54+
includeBranch(): Entries {
55+
this._queryParams.include_branch = 'true';
2956

3057
return this;
3158
}
3259

3360
/**
34-
* @method includeMetadata
61+
* @method includeContentType
3562
* @memberof Entries
36-
* @description Include the metadata for getting metadata content for the entry.
63+
* @description IInclude the details of the content type along with the entries details
3764
* @returns {Entries}
3865
* @example
3966
* import contentstack from '@contentstack/delivery-sdk'
4067
*
4168
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
42-
* const result = await stack.contentType(contentType_uid).entry().includeMetadata().find();
69+
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
4370
*/
44-
includeMetadata(): Entries {
45-
this._queryParams.include_metadata = 'true';
71+
includeContentType(): Entries {
72+
this._queryParams.include_content_type = 'true';
4673

4774
return this;
4875
}
@@ -65,35 +92,35 @@ export class Entries extends EntryQueryable {
6592
}
6693

6794
/**
68-
* @method includeContentType
95+
* @method includeFallback
6996
* @memberof Entries
70-
* @description IInclude the details of the content type along with the entries details
97+
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
7198
* @returns {Entries}
7299
* @example
73100
* import contentstack from '@contentstack/delivery-sdk'
74101
*
75102
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
76-
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
103+
* const result = await stack.contentType(contentType_uid).entry().includeFallback().find();
77104
*/
78-
includeContentType(): Entries {
79-
this._queryParams.include_content_type = 'true';
105+
includeFallback(): Entries {
106+
this._queryParams.include_fallback = 'true';
80107

81108
return this;
82109
}
83110

84111
/**
85-
* @method includeBranch
112+
* @method includeMetadata
86113
* @memberof Entries
87-
* @description Includes the branch in result
114+
* @description Include the metadata for getting metadata content for the entry.
88115
* @returns {Entries}
89116
* @example
90117
* import contentstack from '@contentstack/delivery-sdk'
91118
*
92119
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
93-
* const result = await stack.contentType(contentType_uid).entry().includeBranch().find();
120+
* const result = await stack.contentType(contentType_uid).entry().includeMetadata().find();
94121
*/
95-
includeBranch(): Entries {
96-
this._queryParams.include_branch = 'true';
122+
includeMetadata(): Entries {
123+
this._queryParams.include_metadata = 'true';
97124

98125
return this;
99126
}
@@ -177,6 +204,32 @@ export class Entries extends EntryQueryable {
177204
return this;
178205
}
179206

207+
/**
208+
* @method only
209+
* @memberof Entries
210+
* @description Selects specific field/fields of an entry
211+
* @example
212+
* import contentstack from '@contentstack/delivery-sdk'
213+
*
214+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
215+
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
216+
*
217+
* @param {string} fieldUid - field uid to select
218+
* @returns {Entries} - returns Entries object for chaining method calls
219+
*/
220+
only(fieldUid: string|string[]): this {
221+
if (Array.isArray(fieldUid)) {
222+
let i = 0;
223+
for (const uid of fieldUid) {
224+
this._queryParams[`only[BASE][${i}]`] = uid;
225+
i++;
226+
}
227+
} else {
228+
this._queryParams["only[BASE][]"] = fieldUid;
229+
}
230+
return this;
231+
}
232+
180233
/**
181234
* @method query
182235
* @memberof Entries

src/lib/entry-queryable.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,5 @@ import { BaseQuery } from './base-query';
22

33
/* eslint-disable @cspell/spellchecker */
44
export class EntryQueryable extends BaseQuery {
5-
/**
6-
* @method only
7-
* @memberof EntryQueryable
8-
* @description Selects specific field/fields of an entry
9-
* @example
10-
* import contentstack from '@contentstack/delivery-sdk'
11-
*
12-
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
13-
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
14-
*
15-
* @param {string} fieldUid - field uid to select
16-
* @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls
17-
*/
18-
only(fieldUid: string|string[]): this {
19-
if (Array.isArray(fieldUid)) {
20-
let i = 0;
21-
for (const uid of fieldUid) {
22-
this._queryParams[`only[BASE][${i}]`] = uid;
23-
i++;
24-
}
25-
} else {
26-
this._queryParams["only[BASE][]"] = fieldUid;
27-
}
28-
return this;
29-
}
30-
31-
/**
32-
* @method except
33-
* @memberof EntryQueryable
34-
* @description Excludes specific field/fields of an entry
35-
* @example
36-
* import contentstack from '@contentstack/delivery-sdk'
37-
*
38-
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
39-
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
40-
*
41-
* @param {string} fieldUid - field uid to exclude
42-
* @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls
43-
*/
44-
except(fieldUid: string|string[]): this {
45-
if (Array.isArray(fieldUid)) {
46-
let i = 0;
47-
for (const uid of fieldUid) {
48-
this._queryParams[`except[BASE][${i}]`] = uid;
49-
i++;
50-
}
51-
} else {
52-
this._queryParams["except[BASE][]"] = fieldUid;
53-
}
54-
55-
return this;
56-
}
5+
576
}

src/lib/entry.ts

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Entry {
2929
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
3030
* const result = await stack.contentType(contentType_uid).entry(entry_uid).includeFallback().fetch();
3131
*/
32-
includeFallback(): Entry {
32+
includeFallback(): this {
3333
this._queryParams.include_fallback = 'true';
3434

3535
return this;
@@ -46,7 +46,7 @@ export class Entry {
4646
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
4747
* const result = await stack.contentType('abc').entry('entry_uid').variants('xyz').fetch();
4848
*/
49-
variants(variants: string | string[]): Entry {
49+
variants(variants: string | string[]): this {
5050
if (Array.isArray(variants) && variants.length > 0) {
5151
this._variants = variants.join(',');
5252
} else if (typeof variants == 'string' && variants.length > 0) {
@@ -67,7 +67,7 @@ export class Entry {
6767
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
6868
* const result = await stack.contentType(contentType_uid).entry(entry_uid).includeMetadata().fetch();
6969
*/
70-
includeMetadata(): Entry {
70+
includeMetadata(): this {
7171
this._queryParams.include_metadata = 'true';
7272

7373
return this;
@@ -84,7 +84,7 @@ export class Entry {
8484
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
8585
* const result = await stack.contentType(contentType_uid).entry(entry_uid).includeEmbeddedItems().fetch();
8686
*/
87-
includeEmbeddedItems(): Entry {
87+
includeEmbeddedItems(): this {
8888
this._queryParams['include_embedded_items[]'] = 'BASE';
8989

9090
return this;
@@ -103,7 +103,7 @@ export class Entry {
103103
* @param {string} referenceFieldUid - UID of the reference field to include.
104104
* @returns {Entry} - Returns the Entry instance for chaining.
105105
*/
106-
includeReference(...referenceFieldUid: (string | string[])[]): Entry {
106+
includeReference(...referenceFieldUid: (string | string[])[]): this {
107107
if (referenceFieldUid.length) {
108108
referenceFieldUid.forEach(value => {
109109
if (!Array.isArray(this._queryParams['include[]'])) {
@@ -128,7 +128,7 @@ export class Entry {
128128
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
129129
* const result = await stack.contentType(contentType_uid).entry(entry_uid).includeContentType().fetch();
130130
*/
131-
includeContentType(): Entry {
131+
includeContentType(): this {
132132
this._queryParams.include_content_type = 'true';
133133

134134
return this;
@@ -145,7 +145,7 @@ export class Entry {
145145
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
146146
* const result = await stack.contentType(contentType_uid).entry(entry_uid).includeBranch().fetch();
147147
*/
148-
includeBranch(): Entry {
148+
includeBranch(): this {
149149
this._queryParams.include_branch = 'true';
150150

151151
return this;
@@ -162,7 +162,7 @@ export class Entry {
162162
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
163163
* const result = await stack.assetQuery().locale('en-us').fetch();
164164
*/
165-
locale(locale: string): Entry {
165+
locale(locale: string): this {
166166
this._queryParams.locale = locale;
167167

168168
return this;
@@ -195,7 +195,7 @@ export class Entry {
195195
return response;
196196
}
197197

198-
/**
198+
/**
199199
* @method addParams
200200
* @memberof Entry
201201
* @description Adds a query parameter to the query.
@@ -207,9 +207,62 @@ export class Entry {
207207
*
208208
* @returns {Entry}
209209
*/
210-
addParams(paramObj: { [key: string]: string | number | string[] }): Entry {
210+
addParams(paramObj: { [key: string]: string | number | string[] }): this {
211211
this._queryParams = { ...this._queryParams, ...paramObj };
212212

213213
return this;
214214
}
215+
216+
/**
217+
* @method except
218+
* @memberof Entry
219+
* @description Excludes specific field/fields of an entry
220+
* @example
221+
* import contentstack from '@contentstack/delivery-sdk'
222+
*
223+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
224+
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
225+
*
226+
* @param {string} fieldUid - field uid to exclude
227+
* @returns {Entry} - returns Entry object for chaining method calls
228+
*/
229+
except(fieldUid: string|string[]): this {
230+
if (Array.isArray(fieldUid)) {
231+
let i = 0;
232+
for (const uid of fieldUid) {
233+
this._queryParams[`except[BASE][${i}]`] = uid;
234+
i++;
235+
}
236+
} else {
237+
this._queryParams["except[BASE][]"] = fieldUid;
238+
}
239+
240+
return this;
241+
}
242+
243+
/**
244+
* @method only
245+
* @memberof Entry
246+
* @description Selects specific field/fields of an entry
247+
* @example
248+
* import contentstack from '@contentstack/delivery-sdk'
249+
*
250+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
251+
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
252+
*
253+
* @param {string} fieldUid - field uid to select
254+
* @returns {Entry} - returns Entry object for chaining method calls
255+
*/
256+
only(fieldUid: string|string[]): this {
257+
if (Array.isArray(fieldUid)) {
258+
let i = 0;
259+
for (const uid of fieldUid) {
260+
this._queryParams[`only[BASE][${i}]`] = uid;
261+
i++;
262+
}
263+
} else {
264+
this._queryParams["only[BASE][]"] = fieldUid;
265+
}
266+
return this;
267+
}
215268
}

0 commit comments

Comments
 (0)