diff --git a/package-lock.json b/package-lock.json index d95acbd..09e0a63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.4.2", + "version": "4.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.4.2", + "version": "4.4.3", "license": "MIT", "dependencies": { "@contentstack/core": "^1.1.3", diff --git a/package.json b/package.json index 216971b..883f718 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.4.2", + "version": "4.4.3", "type": "module", "license": "MIT", "main": "./dist/legacy/index.cjs", diff --git a/src/lib/base-query.ts b/src/lib/base-query.ts index 91b77ce..cb99594 100644 --- a/src/lib/base-query.ts +++ b/src/lib/base-query.ts @@ -217,7 +217,6 @@ export class BaseQuery extends Pagination { 'x-cs-variant-uid': this._variants }; } - const response = await getData(this._client, this._urlPath, getRequestOptions); return response as FindResponse; diff --git a/src/lib/entry-queryable.ts b/src/lib/entry-queryable.ts index 9a25de0..57c1edd 100644 --- a/src/lib/entry-queryable.ts +++ b/src/lib/entry-queryable.ts @@ -15,9 +15,16 @@ export class EntryQueryable extends BaseQuery { * @param {string} fieldUid - field uid to select * @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls */ - only(fieldUid: string): EntryQueryable { - this._queryParams['only[BASE][]'] = fieldUid; - + only(fieldUid: string|string[]): EntryQueryable { + if (Array.isArray(fieldUid)) { + let i = 0; + for (const uid of fieldUid) { + this._queryParams[`only[BASE][${i}]`] = uid; + i++; + } + } else { + this._queryParams["only[BASE][]"] = fieldUid; + } return this; } @@ -34,8 +41,16 @@ export class EntryQueryable extends BaseQuery { * @param {string} fieldUid - field uid to exclude * @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls */ - except(fieldUid: string): EntryQueryable { - this._queryParams['except[BASE][]'] = fieldUid; + except(fieldUid: string|string[]): EntryQueryable { + if (Array.isArray(fieldUid)) { + let i = 0; + for (const uid of fieldUid) { + this._queryParams[`except[BASE][${i}]`] = uid; + i++; + } + } else { + this._queryParams["except[BASE][]"] = fieldUid; + } return this; } diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index 8763f14..a57c6f1 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -258,6 +258,28 @@ describe('Query Operators API test cases', () => { } }); + + it('should check for projected fields after only filter is applied', async () => { + const query = makeEntries('contenttype_uid2').only(['title', 'reference']) + const result = await query.find(); + if (result.entries) { + expect(result.entries.length).toBeGreaterThan(0); + expect(result.entries[0].reference).toBeDefined(); + expect(result.entries[0].title).toBeDefined(); + expect(result.entries[0]._version).toBeUndefined(); + } + }); + + it('should ignore fields after except filter is applied', async () => { + const query = makeEntries('contenttype_uid2').except(['title', 'reference']) + const result = await query.find(); + if (result.entries) { + expect(result.entries.length).toBeGreaterThan(0); + expect(result.entries[0].reference).toBeUndefined(); + expect(result.entries[0].title).toBeUndefined(); + expect(result.entries[0]._version).toBeDefined(); + } + }); }); function makeEntries(contentTypeUid = ''): Entries {