From f8e37b2dfb84fd68bf06ab816604469a02e16f8e Mon Sep 17 00:00:00 2001 From: Dominic Wroblewski Date: Mon, 27 Jan 2020 18:58:45 +0000 Subject: [PATCH] [contentstack] Add ContentStack type definitions for 3.8.1 (#41888) * Add initial ContentStack definitions for 3.8(.1) * Add additional configuration constructor --- types/contentstack/contentstack-tests.ts | 169 +++++++++++++++++++++++ types/contentstack/index.d.ts | 83 +++++++++++ types/contentstack/tsconfig.json | 23 +++ types/contentstack/tslint.json | 1 + 4 files changed, 276 insertions(+) create mode 100644 types/contentstack/contentstack-tests.ts create mode 100644 types/contentstack/index.d.ts create mode 100644 types/contentstack/tsconfig.json create mode 100644 types/contentstack/tslint.json diff --git a/types/contentstack/contentstack-tests.ts b/types/contentstack/contentstack-tests.ts new file mode 100644 index 0000000000..a39d8f0b0e --- /dev/null +++ b/types/contentstack/contentstack-tests.ts @@ -0,0 +1,169 @@ +import contentstack = require('contentstack'); + +contentstack.Stack({ api_key: '', access_token: '', environment: ''}); +const stack = contentstack.Stack('api_key', 'access_token', 'environment_name'); +stack.ContentType('content_type'); + +const query = stack.ContentType('content_type').Query(); +stack + .ContentType('content_type') + .Query() + .find(); +stack + .ContentType('content_type') + .Query() + .setCacheProvider({}) + .find(); +stack + .ContentType('content_type') + .Query() + .setCachePolicy(1) + .find(); +stack + .ContentType('content_type') + .Query() + .language('en-US') + .find(); +stack + .ContentType('content_type') + .Query() + .addQuery('query', 'foo') + .find(); +stack + .ContentType('content_type') + .Query() + .includeReference('query') + .find(); +stack + .ContentType('content_type') + .Query() + .includeReference('query', 'foo') + .find(); +stack + .ContentType('content_type') + .Query() + .includeReference(['query']) + .find(); +stack + .ContentType('content_type') + .Query() + .includeReference(['query', 'foo']) + .find(); +stack + .ContentType('content_type') + .Query() + .includeReferenceContentTypeUID() + .find(); +stack + .ContentType('content_type') + .Query() + .includeSchema() + .find(); +stack + .ContentType('content_type') + .Query() + .includeContentType() + .find(); +stack + .ContentType('content_type') + .Query() + .includeOwner() + .find(); +stack + .ContentType('content_type') + .Query() + .toJSON() + .find(); +stack + .ContentType('content_type') + .Query() + .addParam('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .fetch(); +stack + .ContentType('content_type') + .Query() + .equalTo('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .where('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .count() + .find(); +stack + .ContentType('content_type') + .Query() + .referenceIn('key', query) + .find(); +stack + .ContentType('content_type') + .Query() + .referenceNotIn('key', query) + .find(); +stack + .ContentType('content_type') + .Query() + .tags(['some', 'tag']) + .find(); +stack + .ContentType('content_type') + .Query() + .includeCount() + .find(); +stack + .ContentType('content_type') + .Query() + .getQuery() + .find(); +stack + .ContentType('content_type') + .Query() + .regex('key', 'value', 'options') + .find(); +stack + .ContentType('content_type') + .Query() + .search('search_value') + .find(); +stack + .ContentType('content_type') + .Query() + .findOne(); +stack + .ContentType('content_type') + .Query() + .greaterThan('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .greaterThanOrEqualTo('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .lessThan('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .lessThanOrEqualTo('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .notEqualTo('key', 'value') + .find(); +stack + .ContentType('content_type') + .Query() + .containedIn('key', 'value') + .find(); diff --git a/types/contentstack/index.d.ts b/types/contentstack/index.d.ts new file mode 100644 index 0000000000..d8aa8b83ee --- /dev/null +++ b/types/contentstack/index.d.ts @@ -0,0 +1,83 @@ +// Type definitions for contentstack 3.8 +// Project: https://github.com/contentstack/contentstack-javascript +// Definitions by: Dominic Wroblewski +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.6 + +export function Stack(api_key: string, access_token: string, environment_name: string): Stack; +export function Stack(config: Config): Stack; + +export interface Config { + api_key: string; + access_token: string; + environment: string; +} + +export class Stack { + constructor(config: Config); + constructor(api_key: string, access_token: string, environment_name: string); + + ContentType(uid: string): ContentType; +} + +export class ContentType { + constructor(); + + Query(): Query; +} + +export class Entry { + constructor(); + + setCacheProvider(provider: object): Entry; + setCachePolicy(policy: number): Entry; + includeReference(val: string[]): Entry; + includeReference(...val: string[]): Entry; + language(language_code: string): Entry; + addQuery(key: string, value: string): Entry; + includeSchema(): Entry; + includeReferenceContentTypeUID(): Entry; + includeContentType(): Entry; + includeOwner(): Entry; + toJSON(): Entry; + addParam(key: string, value: any): Entry; + fetch(): Promise; +} + +export class Query extends Entry { + constructor(); + + setCacheProvider(provider: object): Query; + setCachePolicy(policy: number): Query; + language(language_code: string): Query; + addQuery(key: string, value: string): Query; + includeReference(val: string[]): Query; + includeReference(...val: string[]): Query; + includeReferenceContentTypeUID(): Query; + includeSchema(): Query; + includeContentType(): Query; + includeOwner(): Query; + toJSON(): Query; + addParam(key: string, value: any): Query; + fetch(): Promise; + + equalTo(key: string, value: any): Query; + where(key: string, value: any): Query; + count(): Query; + query(query: any): Query; + referenceIn(key: string, query: Query): Query; + referenceNotIn(key: string, query: Query): Query; + tags(value: any[]): Query; + includeCount(): Query; + getQuery(): Query; + regex(key: string, value: any, options: string): Query; + search(value: string): Query; + find(): Promise; + findOne(): Promise; + greaterThan(key: string, value: any): Query; + greaterThanOrEqualTo(key: string, value: any): Query; + lessThan(key: string, value: any): Query; + lessThanOrEqualTo(key: string, value: any): Query; + notEqualTo(key: string, value: any): Query; + containedIn(key: string, value: any): Query; +} diff --git a/types/contentstack/tsconfig.json b/types/contentstack/tsconfig.json new file mode 100644 index 0000000000..0cf3aed498 --- /dev/null +++ b/types/contentstack/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "contentstack-tests.ts" + ] +} diff --git a/types/contentstack/tslint.json b/types/contentstack/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/contentstack/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }