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

convert module/classes names to lower case #177

Merged
merged 3 commits into from
Apr 22, 2024
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
6 changes: 3 additions & 3 deletions src/lib/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class ContentType {
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const entry = stack.contentType("contentTypeUid").entry("entryUid");
*/
Entry(uid: string): Entry;
Entry(): Entries;
Entry(uid?: string): Entry | Entries {
entry(uid: string): Entry;
entry(): Entries;
entry(uid?: string): Entry | Entries {
if (uid) return new Entry(this._client, this._contentTypeUid, uid);

return new Entries(this._client, this._contentTypeUid);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export * as Utils from '@contentstack/utils';
* }
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function Stack(config: StackConfig): StackClass {
export function stack(config: StackConfig): StackClass {
let defaultConfig = {
defaultHostname: 'cdn.contentstack.io',
headers: {} as AxiosRequestHeaders,
Expand Down
20 changes: 10 additions & 10 deletions src/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class Stack {
* const asset = stack.asset('assetUid') // For a single asset with uid 'assetUid'
*
*/
Asset(uid: string): Asset;
Asset(): AssetQuery;
Asset(uid?: string): Asset | AssetQuery {
asset(uid: string): Asset;
asset(): AssetQuery;
asset(uid?: string): Asset | AssetQuery {
if (uid) return new Asset(this._client, uid);

return new AssetQuery(this._client);
Expand All @@ -56,9 +56,9 @@ export class Stack {
* // OR
* const contentType = stack.contentType('contentTypeUid') // For a single contentType with uid 'contentTypeUid'
*/
ContentType(): ContentTypeQuery;
ContentType(uid: string): ContentType;
ContentType(uid?: string): ContentType | ContentTypeQuery {
contentType(): ContentTypeQuery;
contentType(uid: string): ContentType;
contentType(uid?: string): ContentType | ContentTypeQuery {
if (uid) return new ContentType(this._client, uid);

return new ContentTypeQuery(this._client);
Expand All @@ -76,7 +76,7 @@ export class Stack {

* const taxonomy = stack.Taxonomy() // For taxonomy query object
*/
Taxonomy(): TaxonomyQuery {
taxonomy(): TaxonomyQuery {
return new TaxonomyQuery(this._client)
};

Expand All @@ -91,9 +91,9 @@ export class Stack {
* // OR
* const contentType = stack.contentType('contentTypeUid') // For a single contentType with uid 'contentTypeUid'
*/
GlobalField(): GlobalFieldQuery;
GlobalField(uid: string): GlobalField;
GlobalField(uid?: string): GlobalField | GlobalFieldQuery {
globalField(): GlobalFieldQuery;
globalField(uid: string): GlobalField;
globalField(uid?: string): GlobalField | GlobalFieldQuery {
if (uid) return new GlobalField(this._client, uid);

return new GlobalFieldQuery(this._client);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/string-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ImageTransform } from './image-transform';
import { ImageTransform } from './image-transform';

declare global {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -7,7 +7,7 @@ declare global {
}
}

String.prototype.transform = function (imageTransform: ImageTransform): string {
String.prototype.transform = function (imageTransform:ImageTransform): string {
let result = this.toString();
const queryString = Object.entries(Object.assign({}, imageTransform.obj))
.map(([key, value]) => `${key}=${value}`)
Expand Down
2 changes: 1 addition & 1 deletion test/api/asset-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('AssetQuery API tests', () => {
});
});
function makeAssetQuery(): AssetQuery {
const asset = stack.Asset();
const asset = stack.asset();

return asset;
}
2 changes: 1 addition & 1 deletion test/api/asset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('Asset API tests', () => {
});
});
function makeAsset(uid = ''): Asset {
const asset = stack.Asset(uid);
const asset = stack.asset(uid);

return asset;
}
2 changes: 1 addition & 1 deletion test/api/contenttype-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ContentTypeQuery API test cases', () => {
});
});
function makeContentTypeQuery(): ContentTypeQuery {
const contentTypeQuery = stack.ContentType();
const contentTypeQuery = stack.contentType();

return contentTypeQuery;
}
4 changes: 2 additions & 2 deletions test/api/contenttype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dotenv.config()
const stack = stackInstance();
describe('ContentType API test cases', () => {
it('should give Entry instance when entry method is called with entryUid', async () => {
const result = await makeContentType('author').Entry(process.env.ENTRY_UID as string).fetch<TEntry>();
const result = await makeContentType('author').entry(process.env.ENTRY_UID as string).fetch<TEntry>();
expect(result).toBeDefined();
});
it('should check for content_types of the given contentTypeUid', async () => {
Expand All @@ -27,7 +27,7 @@ describe('ContentType API test cases', () => {
});

function makeContentType(uid = ''): ContentType {
const contentType = stack.ContentType(uid);
const contentType = stack.contentType(uid);

return contentType;
}
2 changes: 1 addition & 1 deletion test/api/entries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Entries API test cases', () => {
})
});
function makeEntries(contentTypeUid = ''): Entries {
const entries = stack.ContentType(contentTypeUid).Entry();
const entries = stack.contentType(contentTypeUid).entry();

return entries;
}
17 changes: 16 additions & 1 deletion test/api/entry-queryables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,24 @@ describe('Query Operators API test cases', () => {
expect(query.entries[0].created_at).toBeDefined();
}
});

it('should check for include reference', async () => {
const query = makeEntries('contenttype_uid2').includeReference('reference')
const result = await query.find<TEntry>()
if (result.entries) {
expect(result.entries.length).toBeGreaterThan(0);
expect(result.entries[0].reference).toBeDefined();
expect(result.entries[0].reference[0].title).toBeDefined();
expect(result.entries[0]._version).toBeDefined();
expect(result.entries[0].title).toBeDefined();
expect(result.entries[0].uid).toBeDefined();
expect(result.entries[0].created_at).toBeDefined();

}
});
});

function makeEntries(contentTypeUid = ''): Entries {
const entries = stack.ContentType(contentTypeUid).Entry();
const entries = stack.contentType(contentTypeUid).entry();
return entries;
}
2 changes: 1 addition & 1 deletion test/api/entry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Entry API tests', () => {
});
});
function makeEntry(uid = ''): Entry {
const entry = stack.ContentType('author').Entry(uid);
const entry = stack.contentType('author').entry(uid);

return entry;
}
22 changes: 11 additions & 11 deletions test/api/live-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const environment = process.env.ENVIRONMENT as string

describe('Live preview tests', () => {
test('should check for values initialized', () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
Expand All @@ -21,7 +21,7 @@ describe('Live preview tests', () => {
});

test('should check host when live preview is enabled and management token is provided', () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
Expand All @@ -39,7 +39,7 @@ describe('Live preview tests', () => {
});

test('should check host when live preview is disabled and management token is provided', () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
Expand All @@ -57,7 +57,7 @@ describe('Live preview tests', () => {
});

test('should check host when live preview is enabled and preview token is provided', () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
Expand All @@ -75,7 +75,7 @@ describe('Live preview tests', () => {
});

test('should check host when live preview is disabled and preview token is provided', () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
Expand All @@ -95,7 +95,7 @@ describe('Live preview tests', () => {

describe('Live preview query Entry API tests', () => {
it('should check for entry is when live preview is enabled with managemenet token', async () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
Expand All @@ -108,7 +108,7 @@ describe('Live preview query Entry API tests', () => {
contentTypeUid: 'contentTypeUid',
live_preview: 'ser',
})
const result = await stack.ContentType('contentTypeUid').Entry('entryUid').fetch<TEntry>();
const result = await stack.contentType('contentTypeUid').entry('entryUid').fetch<TEntry>();
expect(result).toBeDefined();
expect(result._version).toBeDefined();
expect(result.locale).toEqual('en-us');
Expand All @@ -118,7 +118,7 @@ describe('Live preview query Entry API tests', () => {
});

it('should check for entry is when live preview is disabled with managemenet token', async () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
Expand All @@ -131,7 +131,7 @@ describe('Live preview query Entry API tests', () => {
contentTypeUid: 'contentTypeUid',
live_preview: 'ser',
})
const result = await stack.ContentType('contentTypeUid').Entry('entryUid').fetch<TEntry>();
const result = await stack.contentType('contentTypeUid').entry('entryUid').fetch<TEntry>();
expect(result).toBeDefined();
expect(result._version).toBeDefined();
expect(result.locale).toEqual('en-us');
Expand All @@ -141,7 +141,7 @@ describe('Live preview query Entry API tests', () => {
});

it('should check for entry is when live preview is disabled with preview token', async () => {
const stack = contentstack.Stack({
const stack = contentstack.stack({
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
Expand All @@ -154,7 +154,7 @@ describe('Live preview query Entry API tests', () => {
contentTypeUid: 'contentTypeUid',
live_preview: 'ser',
})
const result = await stack.ContentType('contentTypeUid').Entry('entryUid').fetch<TEntry>();
const result = await stack.contentType('contentTypeUid').entry('entryUid').fetch<TEntry>();
expect(result).toBeDefined();
expect(result._version).toBeDefined();
expect(result.locale).toEqual('en-us');
Expand Down
2 changes: 1 addition & 1 deletion test/api/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Pagination API tests', () => {
});
});
function makePagination(uid = '', pageObj = {}) {
const query = stack.ContentType(uid).Entry().paginate(pageObj);
const query = stack.contentType(uid).entry().paginate(pageObj);

return query;
}
2 changes: 1 addition & 1 deletion test/api/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Query API tests', () => {
});
});
function makeQuery(ctUid: string, queryObj?: { [key: string]: any }) {
const entryInstance = stack.ContentType(ctUid).Entry();
const entryInstance = stack.contentType(ctUid).entry();

if (queryObj) return entryInstance.query(queryObj);
return entryInstance.query();
Expand Down
26 changes: 13 additions & 13 deletions test/api/taxonomy-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,59 @@ const stack = stackInstance();

describe('Taxonomy API test cases', () => {
it('Taxonomies Endpoint: Get Entries With One Term', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one')
let taxonomy = stack.taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one')
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
});

it('Taxonomies Endpoint: Get Entries With Any Term ($in)', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', QueryOperation.INCLUDES, ['term_one', 'term_two']);
let taxonomy = stack.taxonomy().where('taxonomies.one', QueryOperation.INCLUDES, ['term_one', 'term_two']);
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With Any Term ($or)', async () => {
let taxonomyQuery1 = stack.Taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one');
let taxonomyQuery2 = stack.Taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two');
let taxonomyQuery = stack.Taxonomy().queryOperator(QueryOperator.OR, taxonomyQuery1, taxonomyQuery2);
let taxonomyQuery1 = stack.taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one');
let taxonomyQuery2 = stack.taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two');
let taxonomyQuery = stack.taxonomy().queryOperator(QueryOperator.OR, taxonomyQuery1, taxonomyQuery2);
const data = await taxonomyQuery.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With All Terms ($and)', async () => {
let taxonomyQuery1 = stack.Taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one');
let taxonomyQuery2 = stack.Taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two');
let taxonomyQuery = stack.Taxonomy().queryOperator(QueryOperator.AND, taxonomyQuery1, taxonomyQuery2);
let taxonomyQuery1 = stack.taxonomy().where('taxonomies.one', QueryOperation.EQUALS, 'term_one');
let taxonomyQuery2 = stack.taxonomy().where('taxonomies.two', QueryOperation.EQUALS, 'term_two');
let taxonomyQuery = stack.taxonomy().queryOperator(QueryOperator.AND, taxonomyQuery1, taxonomyQuery2);
const data = await taxonomyQuery.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With Any Taxonomy Terms ($exists)', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', QueryOperation.EXISTS, true)
let taxonomy = stack.taxonomy().where('taxonomies.one', QueryOperation.EXISTS, true)
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_BELOW, 'term_one', {"levels": 1})
let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_BELOW, 'term_one', {"levels": 1})
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.BELOW, 'term_one', {"levels": 1})
let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.BELOW, 'term_one', {"levels": 1})
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_ABOVE, 'term_one', {"levels": 1})
let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.EQ_ABOVE, 'term_one', {"levels": 1})
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', async () => {
let taxonomy = stack.Taxonomy().where('taxonomies.one', TaxonomyQueryOperation.ABOVE, 'term_one_child', {"levels": 1})
let taxonomy = stack.taxonomy().where('taxonomies.one', TaxonomyQueryOperation.ABOVE, 'term_one_child', {"levels": 1})
const data = await taxonomy.find<TEntries>();
return expect(data.entries.length).toBeGreaterThan(0);
})
Expand Down
6 changes: 6 additions & 0 deletions test/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface TEntry {
publish_details: PublishDetails;
author: Author[];
url: string;
reference?: any;
}


Expand All @@ -29,6 +30,11 @@ interface Author {
_content_type_uid: string;
}

interface Reference {
uid: string;
_content_type_uid: string;
}

export interface TAsset {
_version: number;
uid: string;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/contentstack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Contentstack', () => {
createHttpClientMock.mockReset();
});

const createStackInstance = (config: StackConfig) => Contentstack.Stack(config);
const createStackInstance = (config: StackConfig) => Contentstack.stack(config);

it('should throw error when api key is empty', (done) => {
const config = {
Expand Down
Loading