From 7e3205f4c5f7c3fcc8fb5d4cf3fcc85d80670f28 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 14 Mar 2024 16:42:54 +0530 Subject: [PATCH 01/12] feat: referenceNotIn operator implementation --- src/lib/query.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/query.ts b/src/lib/query.ts index 066d53e4..13b9a7c3 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -298,5 +298,23 @@ export class Query extends BaseQuery { referenceIn(key: string, query: Query) { this._parameters[key] = { '$in_query': query._parameters } return this; -} + } + + /** + * @method equalTo + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().referenceNotIn('reference_uid', query).find(); + * + * @returns {Query} + */ + referenceNotIn(key: string, query: Query) { + this._parameters[key] = { '$nin_query': query._parameters } + return this; + } } From 81b37efd98e26ae963e9e1fa412416ba79de1382 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 14 Mar 2024 16:44:43 +0530 Subject: [PATCH 02/12] feat: tags query operator implementation --- src/lib/query.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/query.ts b/src/lib/query.ts index 13b9a7c3..a8904084 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -301,7 +301,7 @@ export class Query extends BaseQuery { } /** - * @method equalTo + * @method referenceNotIn * @memberof Query * @description Returns the raw (JSON) query based on the filters applied on Query object. * @example @@ -317,4 +317,22 @@ export class Query extends BaseQuery { this._parameters[key] = { '$nin_query': query._parameters } return this; } + + /** + * @method tags + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().tags(['tag1']).find(); + * + * @returns {Query} + */ + tags(values: (string | number | boolean)[]): Query { + this._parameters['tags'] = values; + return this; + } } From 4e5b9bbbaec8631875b38bd89ab6da71348b74dc Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 15 Mar 2024 14:15:49 +0530 Subject: [PATCH 03/12] test: unit and api tests for tags and referenceNot In operators --- test/api/entry-queryables.spec.ts | 26 ++++++++++++++++++++++++++ test/unit/entry-queryable.spec.ts | 19 ++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index feb15b1f..126ebb29 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -116,6 +116,32 @@ describe('Query Operators API test cases', () => { expect(entryQuery.entries[0].title).toBe('test'); } }); + it('should return entry for referenceNotIn query', async () => { + const query = makeEntries('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + const entryQuery = await makeEntries('contenttype_uid').query().referenceNotIn('reference_uid', query).find(); + + if (entryQuery.entries) { + expect(entryQuery.entries[0]._version).toBeDefined(); + expect(entryQuery.entries[0].locale).toBeDefined(); + expect(entryQuery.entries[0].uid).toBeDefined(); + expect(entryQuery.entries[0].title).not.toBe('test'); + expect(entryQuery.entries[0].title).toBe('value2'); + expect(entryQuery.entries[1]._version).toBeDefined(); + expect(entryQuery.entries[1].locale).toBeDefined(); + expect(entryQuery.entries[1].uid).toBeDefined(); + expect(entryQuery.entries[1].title).toBe('value'); + } + }); + + it('should return entry if tags are matching', async () => { + const query = await makeEntries('contenttype_uid').query().tags(['tag1']).find(); + if (query.entries) { + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].locale).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].title).toBe('value'); + } + }); }); function makeEntries(contentTypeUid = ''): Entries { diff --git a/test/unit/entry-queryable.spec.ts b/test/unit/entry-queryable.spec.ts index 3a97d5da..09ce14cb 100644 --- a/test/unit/entry-queryable.spec.ts +++ b/test/unit/entry-queryable.spec.ts @@ -47,11 +47,24 @@ describe('Query Operators API test cases', () => { const query = contentType.Entry().query().equalTo('fieldUID', 'value'); expect(query._parameters).toStrictEqual({ 'fieldUID': 'value' }); }); - it('should return entry for referencedIn query', async () => { - const query1 = contentType.Entry().query().containedIn('fieldUID', ['value']); + it('should return entry for referenceIn query', async () => { + const query1 = contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value'); const entryQuery = await contentType.Entry().query().referenceIn('reference_uid', query1); if (entryQuery) { - expect(entryQuery._parameters).toEqual({ reference_uid: { '$in_query': { fieldUID: { '$in': [ 'value' ] } } } }); + expect(entryQuery._parameters).toEqual({ reference_uid: { '$in_query': { fieldUID: 'value' } } }); + } + }); + it('should return entry for referenceNotIn query', async () => { + const query1 = contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value'); + const entryQuery = await contentType.Entry().query().referenceNotIn('reference_uid', query1); + if (entryQuery) { + expect(entryQuery._parameters).toEqual({ reference_uid: { '$nin_query': { fieldUID: 'value' } } }); + } + }); + it('should return entry if tags are matching', async () => { + const query = contentType.Entry().query().tags(['tag1']); + if (query) { + expect(query._parameters).toEqual({ tags: ['tag1'] }); } }); }); \ No newline at end of file From 0259d2f53d94a46e4583c7b776cd176bfc07d75b Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 18 Mar 2024 17:04:36 +0530 Subject: [PATCH 04/12] feat: search query operator implementation --- src/lib/query.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/query.ts b/src/lib/query.ts index a8904084..30f5900e 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -295,7 +295,7 @@ export class Query extends BaseQuery { * * @returns {Query} */ - referenceIn(key: string, query: Query) { + referenceIn(key: string, query: Query): Query { this._parameters[key] = { '$in_query': query._parameters } return this; } @@ -313,7 +313,7 @@ export class Query extends BaseQuery { * * @returns {Query} */ - referenceNotIn(key: string, query: Query) { + referenceNotIn(key: string, query: Query): Query { this._parameters[key] = { '$nin_query': query._parameters } return this; } @@ -335,4 +335,8 @@ export class Query extends BaseQuery { this._parameters['tags'] = values; return this; } + search(key: string): Query { + this._queryParams['typeahead'] = key + return this + } } From 20e53f846d285112e5e2a4c77502028174aefaa1 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 18 Mar 2024 17:04:59 +0530 Subject: [PATCH 05/12] test: api and unit test cases for search operator --- test/api/entry-queryables.spec.ts | 10 ++++++++++ test/unit/entry-queryable.spec.ts | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index 126ebb29..7bfa33b8 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -142,6 +142,16 @@ describe('Query Operators API test cases', () => { expect(query.entries[0].title).toBe('value'); } }); + + it('should search for the matching key and return the entry', async () => { + const query = await makeEntries('contenttype_uid').query().search('value2').find(); + if (query.entries) { + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].locale).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].title).toBe('value2'); + } + }); }); function makeEntries(contentTypeUid = ''): Entries { diff --git a/test/unit/entry-queryable.spec.ts b/test/unit/entry-queryable.spec.ts index 09ce14cb..ea7a4a0e 100644 --- a/test/unit/entry-queryable.spec.ts +++ b/test/unit/entry-queryable.spec.ts @@ -67,4 +67,10 @@ describe('Query Operators API test cases', () => { expect(query._parameters).toEqual({ tags: ['tag1'] }); } }); + it('should search for the matching key and return the entry', async () => { + const query = contentType.Entry().query().search('entry'); + if (query) { + expect(query._queryParams).toEqual({ typeahead: 'entry' }); + } + }); }); \ No newline at end of file From 3e6fa5df1858809a704a6fae53f3b4d65772e67a Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 18 Mar 2024 17:09:44 +0530 Subject: [PATCH 06/12] chore: :package: upgraded contentstack utils package --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0f575d3c..ad6b342a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.0.0-beta.4", "dependencies": { "@contentstack/core": "^1.0.1", - "@contentstack/utils": "^1.3.1", + "@contentstack/utils": "^1.3.3", "@types/humps": "^2.0.6", "dotenv": "^16.3.1", "humps": "^2.0.1" @@ -1846,9 +1846,9 @@ } }, "node_modules/@contentstack/utils": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.1.tgz", - "integrity": "sha512-qvhEYAxPzUAC++pA2y6W9uMHAsyeFhRLd/bw/Mw2TblBkOxf62W1ASuRdJZz2bfSYp8aAX4HBC22DvzYvkLgHg==" + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.3.tgz", + "integrity": "sha512-Zj2ejyfbxZlXrF1Wl9lhwK2mCCWo5ooiDnSlNA8nupZ1nDsTfouYERgps8r/uyzm18Vda2wBitxloThxKAyzsA==" }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", @@ -12156,9 +12156,9 @@ } }, "@contentstack/utils": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.1.tgz", - "integrity": "sha512-qvhEYAxPzUAC++pA2y6W9uMHAsyeFhRLd/bw/Mw2TblBkOxf62W1ASuRdJZz2bfSYp8aAX4HBC22DvzYvkLgHg==" + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.3.tgz", + "integrity": "sha512-Zj2ejyfbxZlXrF1Wl9lhwK2mCCWo5ooiDnSlNA8nupZ1nDsTfouYERgps8r/uyzm18Vda2wBitxloThxKAyzsA==" }, "@cspotcode/source-map-support": { "version": "0.8.1", diff --git a/package.json b/package.json index 0ad398b9..5bf4cbc4 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "dependencies": { "@contentstack/core": "^1.0.1", - "@contentstack/utils": "^1.3.1", + "@contentstack/utils": "^1.3.3", "@types/humps": "^2.0.6", "dotenv": "^16.3.1", "humps": "^2.0.1" From 27ef18031be3e2a919bb0ccd775974bc9e958f12 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Tue, 19 Mar 2024 16:22:34 +0530 Subject: [PATCH 07/12] feat: exist query operator implementation --- src/lib/query.ts | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/lib/query.ts b/src/lib/query.ts index 30f5900e..93271497 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -201,6 +201,24 @@ export class Query extends BaseQuery { return this; } + /** + * @method exists + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType("contentTypeUid").entry().query(); + * const result = await query.exists('fieldUid').find() + * + * @returns {Query} + */ + exists(key: string): Query { + this._parameters[key] = { '$exists': true }; + return this; + } + /** * @method notExists * @memberof Query @@ -291,7 +309,7 @@ export class Query extends BaseQuery { * * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().referenceIn('reference_uid', query).find(); + * const entryQuery = await stack.contentType('contenttype_uid').query().referenceIn('reference_uid', query).find(); * * @returns {Query} */ @@ -309,7 +327,7 @@ export class Query extends BaseQuery { * * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().referenceNotIn('reference_uid', query).find(); + * const entryQuery = await stack.contentType('contenttype_uid').query().referenceNotIn('reference_uid', query).find(); * * @returns {Query} */ @@ -327,7 +345,7 @@ export class Query extends BaseQuery { * * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); - * const entryQuery = await stack.contentType('contenttype_uid').query().tags(['tag1']).find(); + * const entryQuery = await stack.contentType('contenttype_uid').query().tags(['tag1']).find(); * * @returns {Query} */ @@ -335,6 +353,20 @@ export class Query extends BaseQuery { this._parameters['tags'] = values; return this; } + + /** + * @method search + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().search('key').find(); + * + * @returns {Query} + */ search(key: string): Query { this._queryParams['typeahead'] = key return this From 17b4e2ef02d0a779893343cbac98e03b4c6ab677 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Tue, 19 Mar 2024 16:24:36 +0530 Subject: [PATCH 08/12] test: unit and api test cases for exists, orderByAscending and orderByDescending --- test/api/entry-queryables.spec.ts | 37 ++++++++++++++++++++++++++++++- test/unit/entry-queryable.spec.ts | 18 +++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index 7bfa33b8..0b1e53ac 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -28,7 +28,7 @@ describe('Query Operators API test cases', () => { }); it('should get entries which does not match the fieldUid - notExists', async () => { - const query = await makeEntries('contenttype_uid').query().notExists('multi_line').find() + const query = await makeEntries('contenttype_uid2').query().notExists('multi_line').find() if (query.entries) { expect(query.entries[0]._version).toBeDefined(); expect(query.entries[0].title).toBeDefined(); @@ -38,6 +38,17 @@ describe('Query Operators API test cases', () => { } }); + it('should get entries which matches the fieldUid - exists', async () => { + const query = await makeEntries('contenttype_uid').query().exists('multi_line').find() + if (query.entries) { + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].title).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].created_at).toBeDefined(); + expect((query.entries[0] as any).multi_line).toBeDefined() + } + }); + it('should return entries matching any of the conditions - or', async () => { const query1: Query = await makeEntries('contenttype_uid').query().containedIn('title', ['value']); const query2: Query = await makeEntries('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value2'); @@ -152,6 +163,30 @@ describe('Query Operators API test cases', () => { expect(query.entries[0].title).toBe('value2'); } }); + + it('should sort entries in ascending order of the given fieldUID', async () => { + const query = await makeEntries('contenttype_uid').query().orderByAscending('title').find(); + if (query.entries) { + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].locale).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].title).toBe('test'); + expect(query.entries[1].title).toBe('test2'); + expect(query.entries[2].title).toBe('value'); + } + }); + + it('should sort entries in descending order of the given fieldUID', async () => { + const query = await makeEntries('contenttype_uid').query().orderByDescending('title').find(); + if (query.entries) { + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].locale).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].title).toBe('value2'); + expect(query.entries[1].title).toBe('value'); + expect(query.entries[2].title).toBe('test2'); + } + }); }); function makeEntries(contentTypeUid = ''): Entries { diff --git a/test/unit/entry-queryable.spec.ts b/test/unit/entry-queryable.spec.ts index ea7a4a0e..3eb8041f 100644 --- a/test/unit/entry-queryable.spec.ts +++ b/test/unit/entry-queryable.spec.ts @@ -31,6 +31,12 @@ describe('Query Operators API test cases', () => { const query = contentType.Entry().query().notExists('fieldUID'); expect(query._parameters).toStrictEqual({'fieldUID': {'$exists': false}}); }); + it('should get entries which matches the fieldUid - exists', async () => { + const query = contentType.Entry().query().exists('fieldUID'); + if (query) { + expect(query._parameters).toEqual({'fieldUID': {'$exists': true}}); + } + }); it('should return entries matching any of the conditions - or', async () => { const query1: Query = await contentType.Entry().query().containedIn('fieldUID', ['value']); const query2: Query = await contentType.Entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2'); @@ -73,4 +79,16 @@ describe('Query Operators API test cases', () => { expect(query._queryParams).toEqual({ typeahead: 'entry' }); } }); + it('should sort entries in ascending order of the given fieldUID', async () => { + const query = contentType.Entry().query().orderByAscending('fieldUid'); + if (query) { + expect(query._queryParams).toEqual({ asc: 'fieldUid' }); + } + }); + it('should sort entries in descending order of the given fieldUID', async () => { + const query = contentType.Entry().query().orderByDescending('fieldUid'); + if (query) { + expect(query._queryParams).toEqual({ desc: 'fieldUid' }); + } + }); }); \ No newline at end of file From cbd85a42413552714c523d61a6f4435d7d6621bd Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 21 Mar 2024 13:07:10 +0530 Subject: [PATCH 09/12] chore: version bump and changeLog update --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c3030b..bd0e10cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change log +### Version: 4.0.0-beta.5 +#### Date: March-26-2024 +##### New Features: +- Query operators implementation-2 + ### Version: 4.0.0-beta.4 #### Date: March-14-2024 ##### New Features: diff --git a/package-lock.json b/package-lock.json index ad6b342a..bb648e47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.0.0-beta.4", + "version": "4.0.0-beta.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.0.0-beta.4", + "version": "4.0.0-beta.5", "dependencies": { "@contentstack/core": "^1.0.1", "@contentstack/utils": "^1.3.3", diff --git a/package.json b/package.json index 5bf4cbc4..cba75e5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.0.0-beta.4", + "version": "4.0.0-beta.5", "type": "commonjs", "main": "./dist/cjs/src/index.js", "types": "./dist/types/src/index.d.ts", From a46561b1f21029974f93186533788f0f38a6109e Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 22 Mar 2024 16:19:55 +0530 Subject: [PATCH 10/12] feat: compare query operators implementation --- src/lib/query.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/lib/query.ts b/src/lib/query.ts index 93271497..1358ce2b 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -371,4 +371,76 @@ export class Query extends BaseQuery { this._queryParams['typeahead'] = key return this } + + /** + * @method lessThan + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().lessThan('fieldUid', 'value').find(); + * + * @returns {Query} + */ + lessThan(key: string, value: (string | number)): Query { + this._parameters[key] = { '$lt': value }; + return this; + } + + /** + * @method lessThanOrEqualTo + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().lessThanOrEqualTo('fieldUid', 'value').find(); + * + * @returns {Query} + */ + lessThanOrEqualTo(key: string, value: (string | number)): Query { + this._parameters[key] = { '$lte': value }; + return this; + } + + /** + * @method greaterThan + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().greaterThan('fieldUid', 'value').find(); + * + * @returns {Query} + */ + greaterThan(key: string, value: (string | number)): Query { + this._parameters[key] = { '$gt': value }; + return this; + } + + /** + * @method greaterThanOrEqualTo + * @memberof Query + * @description Returns the raw (JSON) query based on the filters applied on Query object. + * @example + * import contentstack from '@contentstack/delivery-sdk' + * + * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); + * const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value'); + * const entryQuery = await stack.contentType('contenttype_uid').query().greaterThanOrEqualTo('fieldUid', 'value').find(); + * + * @returns {Query} + */ + greaterThanOrEqualTo(key: string, value: (string | number)): Query { + this._parameters[key] = { '$gte': value }; + return this; + } } From d26614d05d9b948bd6469398f7402afb13bae5a4 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 22 Mar 2024 16:20:27 +0530 Subject: [PATCH 11/12] test: unit and api test cases for compare query operators --- test/api/entry-queryables.spec.ts | 44 +++++++++++++++++++++++++++++++ test/unit/entry-queryable.spec.ts | 16 +++++++++++ 2 files changed, 60 insertions(+) diff --git a/test/api/entry-queryables.spec.ts b/test/api/entry-queryables.spec.ts index 0b1e53ac..8bef8853 100644 --- a/test/api/entry-queryables.spec.ts +++ b/test/api/entry-queryables.spec.ts @@ -187,6 +187,50 @@ describe('Query Operators API test cases', () => { expect(query.entries[2].title).toBe('test2'); } }); + + it('should get entries which is lessThan the fieldUid and values', async () => { + const query = await makeEntries('contenttype_uid').query().lessThan('created_at', '2024-03-01T05:25:30.940Z').find() + if (query.entries) { + expect(query.entries.length).toBeGreaterThan(0); + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].title).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].created_at).toBeDefined(); + } + }); + + it('should get entries which is lessThanOrEqualTo the fieldUid and values', async () => { + const query = await makeEntries('contenttype_uid').query().lessThanOrEqualTo('created_at', '2024-03-01T05:25:30.940Z').find() + if (query.entries) { + expect(query.entries.length).toBeGreaterThan(0); + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].title).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].created_at).toBeDefined(); + } + }); + + it('should get entries which is greaterThan the fieldUid and values', async () => { + const query = await makeEntries('contenttype_uid').query().greaterThan('created_at', '2024-03-01T05:25:30.940Z').find() + if (query.entries) { + expect(query.entries.length).toBeGreaterThan(0); + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].title).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].created_at).toBeDefined(); + } + }); + + it('should get entries which is greaterThanOrEqualTo the fieldUid and values', async () => { + const query = await makeEntries('contenttype_uid').query().greaterThanOrEqualTo('created_at', '2024-03-01T05:25:30.940Z').find() + if (query.entries) { + expect(query.entries.length).toBeGreaterThan(0); + expect(query.entries[0]._version).toBeDefined(); + expect(query.entries[0].title).toBeDefined(); + expect(query.entries[0].uid).toBeDefined(); + expect(query.entries[0].created_at).toBeDefined(); + } + }); }); function makeEntries(contentTypeUid = ''): Entries { diff --git a/test/unit/entry-queryable.spec.ts b/test/unit/entry-queryable.spec.ts index 3eb8041f..03885deb 100644 --- a/test/unit/entry-queryable.spec.ts +++ b/test/unit/entry-queryable.spec.ts @@ -91,4 +91,20 @@ describe('Query Operators API test cases', () => { expect(query._queryParams).toEqual({ desc: 'fieldUid' }); } }); + it('should get entries which is lessThan the fieldUid and values', async () => { + const query = contentType.Entry().query().lessThan('fieldUID', 'value'); + expect(query._parameters).toStrictEqual({'fieldUID': {'$lt': 'value'}}); + }); + it('should get entries which is lessThanOrEqualTo the fieldUid and values', async () => { + const query = contentType.Entry().query().lessThanOrEqualTo('fieldUID', 'value'); + expect(query._parameters).toStrictEqual({'fieldUID': {'$lte': 'value'}}); + }); + it('should get entries which is greaterThan the fieldUid and values', async () => { + const query = contentType.Entry().query().greaterThan('fieldUID', 'value'); + expect(query._parameters).toStrictEqual({'fieldUID': {'$gt': 'value'}}); + }); + it('should get entries which is greaterThanOrEqualTo the fieldUid and values', async () => { + const query = contentType.Entry().query().greaterThanOrEqualTo('fieldUID', 'value'); + expect(query._parameters).toStrictEqual({'fieldUID': {'$gte': 'value'}}); + }); }); \ No newline at end of file From 51df88e3b2f738e655307c7368dc7aca87afd082 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Tue, 26 Mar 2024 15:30:17 +0530 Subject: [PATCH 12/12] chore: :package: axios package update to pass all checks --- package-lock.json | 29 +++++++++++++++-------------- package.json | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb648e47..4396f0a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@contentstack/core": "^1.0.1", "@contentstack/utils": "^1.3.3", "@types/humps": "^2.0.6", + "axios": "^1.6.8", "dotenv": "^16.3.1", "humps": "^2.0.1" }, @@ -3942,11 +3943,11 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", - "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dependencies": { - "follow-redirects": "^1.15.4", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -5389,9 +5390,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -13797,11 +13798,11 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "axios": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.7.tgz", - "integrity": "sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "requires": { - "follow-redirects": "^1.15.4", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -14865,9 +14866,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==" + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==" }, "form-data": { "version": "4.0.0", diff --git a/package.json b/package.json index cba75e5e..a4f297a8 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@contentstack/core": "^1.0.1", "@contentstack/utils": "^1.3.3", "@types/humps": "^2.0.6", + "axios": "^1.6.8", "dotenv": "^16.3.1", "humps": "^2.0.1" },