Skip to content

Commit

Permalink
Added support for pagination, GCP support and package bump
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil-lakshman committed Jan 10, 2024
1 parent b407e5c commit dcd2ab6
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 993 deletions.
1,357 changes: 374 additions & 983 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json"
},
"dependencies": {
"@contentstack/core": "file:contentstack-core-0.0.1.tgz",
"@contentstack/utils": "^1.1.3",
"@types/humps": "^2.0.2",
"@contentstack/core": "^1.0.0",
"@contentstack/utils": "^1.3.1",
"@types/humps": "^2.0.6",
"dotenv": "^16.3.1",
"humps": "^2.0.1"
},
Expand All @@ -31,16 +31,16 @@
"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"
}
}
44 changes: 44 additions & 0 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ 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/typescript'
*
* 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/typescript'
*
* 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
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum Region {
EU = 'eu',
AZURE_NA = 'azure-na',
AZURE_EU = 'azure-eu',
GCP_NA= "gcp-na",
}
export interface StackConfig extends HttpClientParams {
host?: string;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/base-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ describe('BaseQuery class', () => {
expect(baseQuery._queryParams.desc).toBe('date');
});

it("should add 'limit' parameter with the specified key to the query parameters", () => {
baseQuery.limit(5);

expect(baseQuery._queryParams.limit).toBe(5);
});

it("should add 'skip' parameter with the specified key to the query parameters", () => {
baseQuery.skip(5);

expect(baseQuery._queryParams.skip).toBe(5);
});

it('should add the specified key-value pair to the query parameters', () => {
baseQuery.param('category', 'books');

Expand Down
6 changes: 5 additions & 1 deletion test/unit/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Region } from '../../src/lib/types';
import { getHost } from '../../src/lib/utils';
import { DUMMY_URL, HOST_EU_REGION, HOST_URL, MOCK_CLIENT_OPTIONS } from '../utils/constant';
import { DUMMY_URL, HOST_EU_REGION, HOST_GCP_NA_REGION, HOST_URL, MOCK_CLIENT_OPTIONS } from '../utils/constant';
import { httpClient, AxiosInstance } from '@contentstack/core';
import MockAdapter from 'axios-mock-adapter';
import { assetQueryFindResponseDataMock } from '../utils/mocks';
Expand All @@ -18,6 +18,10 @@ describe('Utils', () => {
const url = getHost(Region.EU);
expect(url).toEqual(HOST_EU_REGION);
});
it('should return host when region or host is passed', () => {
const url = getHost(Region.GCP_NA);
expect(url).toEqual(HOST_GCP_NA_REGION);
});
it('should return proper US region when nothing is passed', () => {
const url = getHost();
expect(url).toEqual(HOST_URL);
Expand Down
1 change: 1 addition & 0 deletions test/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const HOST_URL = 'cdn.contentstack.io';
export const LOCALE = 'en-155';
export const HOST_EU_REGION = 'eu-cdn.contentstack.com';
export const HOST_AZURE_NA_REGION = 'azure-na-cdn.contentstack.com';
export const HOST_GCP_NA_REGION = 'gcp-na-cdn.contentstack.com';
export const DUMMY_URL = 'www.example.com';
export const MOCK_CLIENT_OPTIONS = { defaultHostname: HOST_URL, params: { environment: 'env' } };

0 comments on commit dcd2ab6

Please sign in to comment.