Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for pagination, GCP support and package bump #113

Merged
merged 9 commits into from
Jan 18, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ You can use advanced sync queries to fetch custom results while performing initi

### The MIT License (MIT)

Copyright © 2012-2021 [Contentstack](https://www.contentstack.com). All Rights Reserved
Copyright © 2012-2024 [Contentstack](https://www.contentstack.com). All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
1,170 changes: 496 additions & 674 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
},
"dependencies": {
"@contentstack/core": "^1.0.1",
"@contentstack/utils": "^1.1.3",
"@types/humps": "^2.0.2",
"@contentstack/utils": "^1.3.1",
"@types/humps": "^2.0.6",

"dotenv": "^16.3.1",
"humps": "^2.0.1"
},
Expand All @@ -31,17 +32,17 @@
"README.md"
],
"devDependencies": {
"@nrwl/jest": "^16.8.1",
"@types/jest": "^29.5.5",
"axios-mock-adapter": "^1.21.2",
"@nrwl/jest": "^17.2.8",
"@types/jest": "^29.5.11",
"axios-mock-adapter": "^1.22.0",
"babel-jest": "^29.7.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-html-reporters": "^3.1.4",
"jest-html-reporters": "^3.1.7",
"jest-junit": "^16.0.0",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "10.9.1",
"ts-loader": "^9.5.1",
"ts-node": "10.9.2",
"webpack-cli": "^5.1.4"
}
}
14 changes: 7 additions & 7 deletions src/lib/asset-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AssetQuery extends BaseQuery {
* @description Retrieve a specific version of an asset in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().version(1).find();
Expand All @@ -30,7 +30,7 @@ export class AssetQuery extends BaseQuery {
* @description Includes the dimensions (height and width) of the image in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeDimension().find();
Expand All @@ -47,7 +47,7 @@ export class AssetQuery extends BaseQuery {
* @description Includes the branch in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeBranch().find();
Expand All @@ -64,7 +64,7 @@ export class AssetQuery extends BaseQuery {
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeMetadata().fetch();
Expand All @@ -81,7 +81,7 @@ export class AssetQuery extends BaseQuery {
* @description Includes the relative URLs of the assets in result
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().relativeUrls().find();
Expand All @@ -98,7 +98,7 @@ export class AssetQuery extends BaseQuery {
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().includeFallback().find();
Expand All @@ -115,7 +115,7 @@ export class AssetQuery extends BaseQuery {
* @description The assets published in the locale will be fetched
* @returns {AssetQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().locale('en-us').find();
Expand Down
16 changes: 8 additions & 8 deletions src/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Asset {
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeFallback().fetch();
Expand All @@ -33,7 +33,7 @@ export class Asset {
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeMetadata().fetch();
Expand All @@ -50,7 +50,7 @@ export class Asset {
* @description Includes the dimensions (height and width) of the image in result
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeDimension().fetch();
Expand All @@ -67,7 +67,7 @@ export class Asset {
* @description Includes the branch in result
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').includeBranch().fetch();
Expand All @@ -84,7 +84,7 @@ export class Asset {
* @description Includes the relative URLs of the asset in result
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').relativeUrls().fetch();
Expand All @@ -101,7 +101,7 @@ export class Asset {
* @description Retrieve a specific version of an asset in result
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').version(1).fetch();
Expand All @@ -118,7 +118,7 @@ export class Asset {
* @description The assets published in the locale will be fetched
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').locale('en-us').fetch();
Expand All @@ -135,7 +135,7 @@ export class Asset {
* @description Fetches the asset data on the basis of the asset uid
* @returns {Asset}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset('asset_uid').fetch();
Expand Down
62 changes: 53 additions & 9 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class BaseQuery extends Pagination {
* @memberof BaseQuery
* @description Retrieve count and data of objects in result
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
Expand All @@ -33,7 +33,7 @@ export class BaseQuery extends Pagination {
* @memberof BaseQuery
* @description Sorts the results in ascending order based on the specified field UID.
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
Expand All @@ -54,7 +54,7 @@ export class BaseQuery extends Pagination {
* @memberof BaseQuery
* @description Sorts the results in descending order based on the specified key.
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
Expand All @@ -70,12 +70,56 @@ export class BaseQuery extends Pagination {
return this;
}

/**
* @method limit
* @memberof BaseQuery
* @description Returns a specific number of entries based on the set limit
* @example
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.limit("limit_value").find()
* // OR
* const asset = await stack.asset().limit(5).find()
*
* @returns {BaseQuery}
*/
limit(key: number): BaseQuery {
this._queryParams.limit = key;

return this;
}

/**
* @method skip
* @memberof BaseQuery
* @description Skips at specific number of entries.
* @example
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
* const result = await query.skip("skip_value").find()
* // OR
* const asset = await stack.asset().skip(5).find()
*
* @returns {BaseQuery}
*/
skip(key: number): BaseQuery {
this._queryParams.skip = key;

return this;
}



/**
* @method param
* @memberof BaseQuery
* @description Adds query parameters to the URL.
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
Expand All @@ -96,7 +140,7 @@ export class BaseQuery extends Pagination {
* @memberof BaseQuery
* @description Adds a query parameter to the query.
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
Expand All @@ -117,7 +161,7 @@ export class BaseQuery extends Pagination {
* @memberof BaseQuery
* @description Removes a query parameter from the query.
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const query = stack.contentType("contentTypeUid").entry().query();
Expand All @@ -139,17 +183,17 @@ export class BaseQuery extends Pagination {
* @description The assets of the stack will be fetched
* @returns {Collection}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset().find();
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentType1Uid").entry().query().find();
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.asset(asset_uid).fetch();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ContentType {
* @description Creates entry object of the passed entry uid.
* @returns {Entry}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entry = stack.contentType("contentTypeUid").entry("entryUid");
Expand All @@ -43,7 +43,7 @@ export class ContentType {
* @description Fetches the contentType data on the basis of the contentType uid
* @returns {ContentType}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(asset_uid).fetch();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export * as Utils from '@contentstack/utils';
* @param {StackConfig} config - config object for stack with apiKey, deliveryToken and environment as required fields
*
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
* const stack = contentstack.Stack({
* apiKey: "apiKey",
* deliveryToken: "deliveryToken",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/contenttype-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ContentTypeQuery {
* @description The assets published in the locale will be fetched
* @returns {ContentTypeQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const contentTypeQuery = stack.contentType();
Expand All @@ -33,7 +33,7 @@ export class ContentTypeQuery {
* @description Fetches all contentTypes of the stack
* @returns {ContentTypeQuery}
* @example
* import contentstack from '@contentstack/typescript'
* import contentstack from '@contentstack/delivery'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const contentTypeQuery = stack.contentType();
Expand Down
Loading
Loading