Skip to content

Commit

Permalink
Merge pull request #51 from contentstack/next
Browse files Browse the repository at this point in the history
Added array of values in includereference method
  • Loading branch information
cs-raj authored Sep 12, 2024
2 parents da154ce + 18c0e83 commit 13e23f2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change log

### Version: 4.3.0
#### Date: Septmber-09-2024
Feat: Include refernce accepts array of values

### Version: 4.2.0
#### Date: Septmber-04-2024
Feat: Variants support added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.2.0",
"version": "4.3.0",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/types/src/index.d.ts",
Expand Down
14 changes: 11 additions & 3 deletions src/lib/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ export class Entries extends EntryQueryable {
* @param {string} referenceFieldUid - UID of the reference field to include.
* @returns {Entries} - Returns the Entries instance for chaining.
*/
includeReference(referenceFieldUid: string): Entries {
this._queryParams['include[]'] = referenceFieldUid;

includeReference(...referenceFieldUid: (string | string[])[]): Entries {
if (referenceFieldUid.length) {
referenceFieldUid.forEach(value => {
if (!Array.isArray(this._queryParams['include[]'])) {
this._queryParams['include[]'] = [];
}
(this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value]));
});
} else {
console.error("Argument should be a String or an Array.");
}
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Entry {
private _contentTypeUid: string;
private _entryUid: string;
private _urlPath: string;
_queryParams: { [key: string]: string | number } = {};
_queryParams: { [key: string]: string | number | string[] } = {};

constructor(client: AxiosInstance, contentTypeUid: string, entryUid: string) {
this._client = client;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/internal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export type params = {
}

export type queryParams = {
[key: string]: string | boolean | number
[key: string]: string | boolean | number | string[]
}
4 changes: 2 additions & 2 deletions test/unit/entries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ describe('Entries class', () => {
it('should set the include parameter to the given reference field UID', () => {
const referenceFieldUid = 'referenceFieldUid';
entry.includeReference(referenceFieldUid);
expect(entry._queryParams['include[]']).toContain(referenceFieldUid);
});

expect(entry._queryParams['include[]']).toBe(referenceFieldUid);
});

it('should add "include_fallback" in _queryParams when includeFallback method is called', () => {
const returnedValue = entry.includeFallback();
Expand Down
38 changes: 19 additions & 19 deletions test/utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const assetQueryFindResponseDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
},
{
Expand Down Expand Up @@ -122,7 +122,7 @@ const assetQueryFindResponseDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
},
{
Expand Down Expand Up @@ -163,7 +163,7 @@ const assetQueryFindResponseDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
},
{
Expand Down Expand Up @@ -204,7 +204,7 @@ const assetQueryFindResponseDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
},
{
Expand Down Expand Up @@ -245,7 +245,7 @@ const assetQueryFindResponseDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
},
{
Expand Down Expand Up @@ -286,7 +286,7 @@ const assetQueryFindResponseDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
},
]
Expand Down Expand Up @@ -1077,7 +1077,7 @@ const assetFetchDataMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}

}
Expand Down Expand Up @@ -1226,7 +1226,7 @@ const entryFindMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:56.964Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
}
],
Expand Down Expand Up @@ -1291,7 +1291,7 @@ const entryFindMock = {
"ACL": {},
"uid": "blt4f1fd991ec80e52f",
"created_by": "bltcd82b2c6bf913241",
"updated_by": "***REMOVED***",
"updated_by": "blt42e55757d70d5f81026a2b9f",
"created_at": "2019-08-16T08:19:25.397Z",
"updated_at": "2019-08-23T13:02:21.457Z",
"_version": 4,
Expand All @@ -1300,7 +1300,7 @@ const entryFindMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-23T13:02:25.439Z",
"user": "***REMOVED***"
"user": "blt42e55757d70d5f81026a2b9f"
}
},
{
Expand Down Expand Up @@ -1328,7 +1328,7 @@ const entryFindMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
}
],
Expand Down Expand Up @@ -1387,7 +1387,7 @@ const entryFindMock = {
"ACL": {},
"uid": "blta278bb5672180c94",
"created_by": "bltcd82b2c6bf913241",
"updated_by": "***REMOVED***",
"updated_by": "blt42e55757d70d5f81026a2b9f",
"created_at": "2019-08-16T08:19:27.182Z",
"updated_at": "2019-08-23T13:01:19.866Z",
"_version": 4,
Expand All @@ -1396,7 +1396,7 @@ const entryFindMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-23T13:01:23.290Z",
"user": "***REMOVED***"
"user": "blt42e55757d70d5f81026a2b9f"
}
},
{
Expand Down Expand Up @@ -1424,7 +1424,7 @@ const entryFindMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:56.964Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
}
],
Expand Down Expand Up @@ -1476,7 +1476,7 @@ const entryFindMock = {
"ACL": {},
"uid": "bltbd92ac498e3d5f96",
"created_by": "bltcd82b2c6bf913241",
"updated_by": "***REMOVED***",
"updated_by": "blt42e55757d70d5f81026a2b9f",
"created_at": "2019-08-16T08:19:20.072Z",
"updated_at": "2019-08-23T12:50:53.424Z",
"_version": 13,
Expand All @@ -1485,7 +1485,7 @@ const entryFindMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-23T12:50:56.727Z",
"user": "***REMOVED***"
"user": "blt42e55757d70d5f81026a2b9f"
}
}
]
Expand Down Expand Up @@ -1517,7 +1517,7 @@ const entryFetchMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-19T12:28:47.432Z",
"user": "***REMOVED***"
"user": "blt587a89fc7883c56700a95bfe"
}
}
],
Expand Down Expand Up @@ -1576,7 +1576,7 @@ const entryFetchMock = {
"ACL": {},
"uid": "blta278bb5672180c94",
"created_by": "bltcd82b2c6bf913241",
"updated_by": "***REMOVED***",
"updated_by": "blt42e55757d70d5f81026a2b9f",
"created_at": "2019-08-16T08:19:27.182Z",
"updated_at": "2019-08-23T13:01:19.866Z",
"_version": 4,
Expand All @@ -1585,7 +1585,7 @@ const entryFetchMock = {
"environment": "blta39a4441696e35e0",
"locale": "en-us",
"time": "2019-08-23T13:01:23.290Z",
"user": "***REMOVED***"
"user": "blt42e55757d70d5f81026a2b9f"
}
}
}
Expand Down

0 comments on commit 13e23f2

Please sign in to comment.