From 461f60fe409d673633d44ac133bedb2fae91f6ef Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 11:34:34 +0530 Subject: [PATCH 1/7] feat: notContainedIn 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 dd4d0eee..828d88a4 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -179,7 +179,25 @@ export class Query extends BaseQuery { * @returns {Query} */ containedIn(key: string, value: (string | number | boolean)[]): Query { - this._queryParams[key] = value; + this._queryParams[key] = { '$in': value }; + return this; + } + + /** + * @method containedIn + * @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").Query; + * const result = containedIn('fieldUid', ['value1', 'value2']).find() + * + * @returns {Query} + */ + NotContainedIn(key: string, value: (string | number | boolean)[]): Query { + this._queryParams[key] = { '$nin': value }; return this; } } From 88cf0532389f10adf72fd91d502e50c8539434c9 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 11:35:52 +0530 Subject: [PATCH 2/7] test: unit and api test case for not contained in --- test/api/contenttype.spec.ts | 12 +++++++++++- test/unit/contenttype.spec.ts | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/api/contenttype.spec.ts b/test/api/contenttype.spec.ts index 0ecac96a..5391f843 100644 --- a/test/api/contenttype.spec.ts +++ b/test/api/contenttype.spec.ts @@ -3,7 +3,7 @@ import { BaseContentType, BaseEntry, FindResponse } from 'src'; import { ContentType } from '../../src/lib/content-type'; import { stackInstance } from '../utils/stack-instance'; -import { TContentType, TEntry } from './types'; +import { TContentType, TEntries, TEntry } from './types'; import dotenv from 'dotenv'; dotenv.config() @@ -36,6 +36,16 @@ describe('ContentType Query API test cases', () => { expect(query.entries[0].created_at).toBeDefined(); } }); + + it('should test for not Contained In', async () => { + const query = await makeContentType('contenttype_uid').Query().NotContainedIn('title', ['test', 'test2']).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(); + } + }); }); function makeContentType(uid = ''): ContentType { const contentType = stack.ContentType(uid); diff --git a/test/unit/contenttype.spec.ts b/test/unit/contenttype.spec.ts index a97dfb20..d7c69482 100644 --- a/test/unit/contenttype.spec.ts +++ b/test/unit/contenttype.spec.ts @@ -58,6 +58,10 @@ describe('ContentType Query class', () => { }); it('should test for contained In', () => { const query = contentType.Query().containedIn('fieldUID', ['value']); - expect(query._queryParams).toStrictEqual({'fieldUID': ['value']}); + expect(query._queryParams).toStrictEqual({'fieldUID': {'$in': ['value']}}); + }); + it('should test for not contained In', () => { + const query = contentType.Query().NotContainedIn('fieldUID', ['value', 'value2']); + expect(query._queryParams).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}}); }); }); \ No newline at end of file From 9189d1ba66522a67afd5d89aa74809e75a4663a8 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 11:38:56 +0530 Subject: [PATCH 3/7] changed the it statements in test cases --- test/api/contenttype.spec.ts | 4 ++-- test/unit/contenttype.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/api/contenttype.spec.ts b/test/api/contenttype.spec.ts index 5391f843..dc0c3ea5 100644 --- a/test/api/contenttype.spec.ts +++ b/test/api/contenttype.spec.ts @@ -27,7 +27,7 @@ describe('ContentType API test cases', () => { }); }); describe('ContentType Query API test cases', () => { - it('should test for contained In', async () => { + it('should get entries which matches the fieldUid and values', async () => { const query = await makeContentType('contenttype_uid').Query().containedIn('title', ['value']).find() if (query.entries) { expect(query.entries[0]._version).toBeDefined(); @@ -37,7 +37,7 @@ describe('ContentType Query API test cases', () => { } }); - it('should test for not Contained In', async () => { + it('should get entries which does not match the fieldUid and values', async () => { const query = await makeContentType('contenttype_uid').Query().NotContainedIn('title', ['test', 'test2']).find() if (query.entries) { expect(query.entries[0]._version).toBeDefined(); diff --git a/test/unit/contenttype.spec.ts b/test/unit/contenttype.spec.ts index d7c69482..3caa7f80 100644 --- a/test/unit/contenttype.spec.ts +++ b/test/unit/contenttype.spec.ts @@ -56,11 +56,11 @@ describe('ContentType Query class', () => { beforeEach(() => { contentType = new ContentType(client, 'contentTypeUid'); }); - it('should test for contained In', () => { + it('should get entries which matches the fieldUid and values', () => { const query = contentType.Query().containedIn('fieldUID', ['value']); expect(query._queryParams).toStrictEqual({'fieldUID': {'$in': ['value']}}); }); - it('should test for not contained In', () => { + it('should get entries which does not match the fieldUid and values', () => { const query = contentType.Query().NotContainedIn('fieldUID', ['value', 'value2']); expect(query._queryParams).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}}); }); From 1ae922c26f0f06ea6daf558e8bc218cd9fe68fce Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 11:44:16 +0530 Subject: [PATCH 4/7] updated docs and function name --- src/lib/query.ts | 6 +++--- test/api/contenttype.spec.ts | 2 +- test/unit/contenttype.spec.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/query.ts b/src/lib/query.ts index 828d88a4..5ba6413a 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -184,7 +184,7 @@ export class Query extends BaseQuery { } /** - * @method containedIn + * @method NoContainedIn * @memberof Query * @description Returns the raw (JSON) query based on the filters applied on Query object. * @example @@ -192,11 +192,11 @@ export class Query extends BaseQuery { * * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const query = stack.contentType("contentTypeUid").Query; - * const result = containedIn('fieldUid', ['value1', 'value2']).find() + * const result = notContainedIn('fieldUid', ['value1', 'value2']).find() * * @returns {Query} */ - NotContainedIn(key: string, value: (string | number | boolean)[]): Query { + notContainedIn(key: string, value: (string | number | boolean)[]): Query { this._queryParams[key] = { '$nin': value }; return this; } diff --git a/test/api/contenttype.spec.ts b/test/api/contenttype.spec.ts index dc0c3ea5..8409b2fb 100644 --- a/test/api/contenttype.spec.ts +++ b/test/api/contenttype.spec.ts @@ -38,7 +38,7 @@ describe('ContentType Query API test cases', () => { }); it('should get entries which does not match the fieldUid and values', async () => { - const query = await makeContentType('contenttype_uid').Query().NotContainedIn('title', ['test', 'test2']).find() + const query = await makeContentType('contenttype_uid').Query().notContainedIn('title', ['test', 'test2']).find() if (query.entries) { expect(query.entries[0]._version).toBeDefined(); expect(query.entries[0].title).toBeDefined(); diff --git a/test/unit/contenttype.spec.ts b/test/unit/contenttype.spec.ts index 3caa7f80..89700f6f 100644 --- a/test/unit/contenttype.spec.ts +++ b/test/unit/contenttype.spec.ts @@ -61,7 +61,7 @@ describe('ContentType Query class', () => { expect(query._queryParams).toStrictEqual({'fieldUID': {'$in': ['value']}}); }); it('should get entries which does not match the fieldUid and values', () => { - const query = contentType.Query().NotContainedIn('fieldUID', ['value', 'value2']); + const query = contentType.Query().notContainedIn('fieldUID', ['value', 'value2']); expect(query._queryParams).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}}); }); }); \ No newline at end of file From 43487ff3abd2027e15fb8c7c9bbc06f455561bd1 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 15:39:30 +0530 Subject: [PATCH 5/7] updated docs and implementation --- src/lib/query.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/query.ts b/src/lib/query.ts index 5ba6413a..39640a29 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -3,7 +3,7 @@ import { BaseQuery } from './base-query'; import { BaseQueryParameters, QueryOperation, QueryOperator, TaxonomyQueryOperation } from './types'; export class Query extends BaseQuery { private _contentTypeUid?: string; - override _queryParams: { [key: string]: any} = {}; + constructor(client: AxiosInstance, uid: string, queryObj?: { [key: string]: any }) { super(); this._client = client; @@ -173,13 +173,13 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType("contentTypeUid").Query; + * const query = stack.contentType("contentTypeUid").Query(); * const result = containedIn('fieldUid', ['value1', 'value2']).find() * * @returns {Query} */ containedIn(key: string, value: (string | number | boolean)[]): Query { - this._queryParams[key] = { '$in': value }; + this._parameters[key] = { '$in': value }; return this; } @@ -191,13 +191,13 @@ export class Query extends BaseQuery { * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); - * const query = stack.contentType("contentTypeUid").Query; + * const query = stack.contentType("contentTypeUid").Query(); * const result = notContainedIn('fieldUid', ['value1', 'value2']).find() * * @returns {Query} */ notContainedIn(key: string, value: (string | number | boolean)[]): Query { - this._queryParams[key] = { '$nin': value }; + this._parameters[key] = { '$nin': value }; return this; } } From 5f9ad5e80989fa77619b707c29a226fd9653d2fa Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 15:47:20 +0530 Subject: [PATCH 6/7] chore: updated changeLog --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2705b1..3406e67b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ ## Change log +### Version: 4.0.0-beta.4 +#### Date: March-04-2024 +##### New Features: +- Query implementation for containedIn and notContainedIn + +### Version: 4.0.0-beta.3 +#### Date: February-13-2024 + - Live preview support 1.0 and 2.0 + +### Version: v4.0.0-beta.2 +#### Date: February-02-2024 + - Includes adding of prepare script to build package + ### Version: 4.0.0-beta #### Date: January-15-2024 - Beta release of Typescript SDK From 03ebd86a385723fecd9ea6825482f45b5d9e312d Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 1 Mar 2024 16:21:10 +0530 Subject: [PATCH 7/7] chore: :package: updated package files --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9806c357..0f575d3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.0.0-beta.3", + "version": "4.0.0-beta.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.0.0-beta.3", + "version": "4.0.0-beta.4", "dependencies": { "@contentstack/core": "^1.0.1", "@contentstack/utils": "^1.3.1", diff --git a/package.json b/package.json index 4a11640d..0ad398b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.0.0-beta.3", + "version": "4.0.0-beta.4", "type": "commonjs", "main": "./dist/cjs/src/index.js", "types": "./dist/types/src/index.d.ts",