From 30dd1a6359998268752cd3d6551aebb4d705b99f Mon Sep 17 00:00:00 2001 From: Jeff Peterson Date: Fri, 23 Aug 2019 14:49:21 -0700 Subject: [PATCH] koji-tools types (#37726) * Add koji-tools type definitions * Prettier * Linted * Add remaining exports * CRLF conversion * Remove namespace --- types/koji-tools/index.d.ts | 55 ++++++++++++++++++++++++++++ types/koji-tools/koji-tools-tests.ts | 11 ++++++ types/koji-tools/tsconfig.json | 23 ++++++++++++ types/koji-tools/tslint.json | 1 + 4 files changed, 90 insertions(+) create mode 100644 types/koji-tools/index.d.ts create mode 100644 types/koji-tools/koji-tools-tests.ts create mode 100644 types/koji-tools/tsconfig.json create mode 100644 types/koji-tools/tslint.json diff --git a/types/koji-tools/index.d.ts b/types/koji-tools/index.d.ts new file mode 100644 index 0000000000..992bc74d57 --- /dev/null +++ b/types/koji-tools/index.d.ts @@ -0,0 +1,55 @@ +// Type definitions for koji-tools 0.5 +// Project: https://github.com/madewithkoji/koji-tools +// Definitions by: Jeff Peterson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +/** + * Server-side function that sets file watchers on all .koji customization + * files and allows for hot reloading of these properties. + */ +export function watch(): void; + +/** + * Sets up Koji.config parameters for each client and handles communication + * between the Koji live preview iframe and your app. + */ +export function pageLoad(options?: object): void; + +/** + * Wrapper for fetch that takes objects from Koji.routes. + */ +export function request(route: object, params?: object): Promise; + +/** + * After the 'pwaPromptReady' event has fired, this function will make a popup + * installation prompt appear. + */ +export function pwaPrompt(): any; + +/** + * An auto-generated list of all of the Koji Customization Controls (VCCs) your + * application has setup. When Koji.watch() is being used this list updates automatically. + */ +export const config: object; + +/** + * A auto-generated list of routes based on koji.json files in your project that are + * used in Koji.request() to request the backend of your app. + */ +export const routes: object; + +export const pwa: any; + +/** + * Registers a callback on a Koji event. + * @param event name of the event being called + * @param callback method to execute when the event occurs + */ +export function on(event: string, callback: () => void): void; + +/** + * Resolve the value of a user's secret from the Koji Keystore. Secrets are used for + * values that are not intended to be read by other users when a project is remixed. + */ +export function resolveSecret(key: string): string | null; diff --git a/types/koji-tools/koji-tools-tests.ts b/types/koji-tools/koji-tools-tests.ts new file mode 100644 index 0000000000..22493783cc --- /dev/null +++ b/types/koji-tools/koji-tools-tests.ts @@ -0,0 +1,11 @@ +import * as Koji from 'koji-tools'; + +Koji.watch(); +Koji.pageLoad(); +Koji.request({ url: 'www.test.org' }); +Koji.pwaPrompt(); +const myConfig = Koji.config; +const myRoutes = Koji.routes; +const myPwaInstaller = Koji.pwa; +Koji.on('test', () => 'Hello, world!'); +const mySecret = Koji.resolveSecret('verySecretKey'); diff --git a/types/koji-tools/tsconfig.json b/types/koji-tools/tsconfig.json new file mode 100644 index 0000000000..03353eef7e --- /dev/null +++ b/types/koji-tools/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "koji-tools-tests.ts" + ] +} diff --git a/types/koji-tools/tslint.json b/types/koji-tools/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/koji-tools/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }