Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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.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",
Expand Down
24 changes: 21 additions & 3 deletions src/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,13 +173,31 @@ 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] = value;
this._parameters[key] = { '$in': value };
return this;
}

/**
* @method NoContainedIn
* @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 = notContainedIn('fieldUid', ['value1', 'value2']).find()
*
* @returns {Query}
*/
notContainedIn(key: string, value: (string | number | boolean)[]): Query {
this._parameters[key] = { '$nin': value };
return this;
}
}
14 changes: 12 additions & 2 deletions test/api/contenttype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<TEntry>()
if (query.entries) {
expect(query.entries[0]._version).toBeDefined();
Expand All @@ -36,6 +36,16 @@ describe('ContentType Query API test cases', () => {
expect(query.entries[0].created_at).toBeDefined();
}
});

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<TEntry>()
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);
Expand Down
8 changes: 6 additions & 2 deletions test/unit/contenttype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ 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': ['value']});
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']);
expect(query._queryParams).toStrictEqual({'fieldUID': {'$nin': ['value', 'value2']}});
});
});