Skip to content

Commit

Permalink
Merge pull request #163 from contentstack/v4-beta/next
Browse files Browse the repository at this point in the history
V4 beta/next
  • Loading branch information
abhinav-from-contentstack authored Mar 28, 2024
2 parents 4fd162e + 233f750 commit cd1f750
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
47 changes: 24 additions & 23 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions 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.4",
"version": "4.0.0-beta.5",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/types/src/index.d.ts",
Expand All @@ -24,8 +24,9 @@
},
"dependencies": {
"@contentstack/core": "^1.0.1",
"@contentstack/utils": "^1.3.1",
"@contentstack/utils": "^1.3.3",
"@types/humps": "^2.0.6",
"axios": "^1.6.8",
"dotenv": "^16.3.1",
"humps": "^2.0.1"
},
Expand Down
150 changes: 147 additions & 3 deletions src/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -291,12 +309,138 @@ 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<TEntry>();
* const entryQuery = await stack.contentType('contenttype_uid').query().referenceIn('reference_uid', query).find();
*
* @returns {Query}
*/
referenceIn(key: string, query: Query) {
referenceIn(key: string, query: Query): Query {
this._parameters[key] = { '$in_query': query._parameters }
return this;
}
}

/**
* @method referenceNotIn
* @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): Query {
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;
}

/**
* @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
}

/**
* @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;
}
}
Loading

0 comments on commit cd1f750

Please sign in to comment.