diff --git a/types/custom-functions-runtime/custom-functions-runtime-tests.ts b/types/custom-functions-runtime/custom-functions-runtime-tests.ts new file mode 100644 index 0000000000..335e5a1f95 --- /dev/null +++ b/types/custom-functions-runtime/custom-functions-runtime-tests.ts @@ -0,0 +1,33 @@ +/* Note that this is a sample function for the purpose of running the below CustomFunctionsMappings test */ +function ADD10(n: number) { + return n + 10; +} + +CustomFunctionMappings = { + addTen: ADD10 +}; + +async function getStockValues(ticker: string, handler: CustomFunctions.StreamingHandler) { + const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json(); + handler.setResult(dollars); +} + +async function getStockValuesOneTime(ticker: string, handler: CustomFunctions.CancelableHandler) { + let shouldStop = false; + handler.onCanceled = () => shouldStop = true; + await pause(1000); + + if (shouldStop) { + return null; + } + + const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json(); + return dollars; +} + +async function getStockValuesNowWithNoCancelling(ticker: string) { + const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json(); + return dollars; +} + +declare function pause(ms: number): Promise; diff --git a/types/custom-functions-runtime/index.d.ts b/types/custom-functions-runtime/index.d.ts new file mode 100644 index 0000000000..b031862efb --- /dev/null +++ b/types/custom-functions-runtime/index.d.ts @@ -0,0 +1,43 @@ +// Type definitions for Custom Functions 1.4 +// Project: http://dev.office.com +// Definitions by: OfficeDev , Michael Zlatkovsky , Michelle Scharlock +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/* +office-js +Copyright (c) Microsoft Corporation +*/ + + +//////////////////////////////////////////////////////////////// +//////////////////// Begin custom-functions-runtime //////////// +//////////////////////////////////////////////////////////////// + +/* +* Enables you to map your own name that uses lowercase letters to a function. +*/ +declare let CustomFunctionMappings: { [key: string]: Function }; + +declare namespace CustomFunctions { + interface StreamingHandler extends CancelableHandler { + /* + * Sets the returned result for a streaming custom function. + * @beta + */ + setResult: (value: T) => void; + } + + interface CancelableHandler { + /* + * Handles what should occur when a custom function is canceled. + * @beta + */ + onCanceled: () => void; + } +} + + +//////////////////////////////////////////////////////////////// +//////////////////// End custom-functions-runtime //////////// +//////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/types/office-runtime/tsconfig.json b/types/custom-functions-runtime/tsconfig.json similarity index 91% rename from types/office-runtime/tsconfig.json rename to types/custom-functions-runtime/tsconfig.json index f8559f2ebd..c42a495281 100644 --- a/types/office-runtime/tsconfig.json +++ b/types/custom-functions-runtime/tsconfig.json @@ -18,6 +18,6 @@ }, "files": [ "index.d.ts", - "office-runtime-tests.ts" + "custom-functions-runtime-tests.ts" ] } diff --git a/types/custom-functions-runtime/tslint.json b/types/custom-functions-runtime/tslint.json new file mode 100644 index 0000000000..a62d0d4e68 --- /dev/null +++ b/types/custom-functions-runtime/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "ban-types": false + } +} diff --git a/types/office-runtime/index.d.ts b/types/office-runtime/index.d.ts deleted file mode 100644 index 3f57014bc9..0000000000 --- a/types/office-runtime/index.d.ts +++ /dev/null @@ -1,117 +0,0 @@ -// Type definitions for office-runtime 1.0 -// Project: http://dev.office.com/ -// Definitions by: Michael Zlatskovsky , Michelle Scharlock -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Typescript Version: 2.4 - -/* -office-runtime -Copyright (c) Microsoft Corporation -*/ - -declare namespace OfficeRuntime { - function displayWebDialog(url: string, options: DisplayWebDialogOptions): Promise; - const AsyncStorage: AsyncStorage; - - // tslint:disable-next-line:interface-name - /* - * Asynchronous, global, and persistent key-value storage that can be used by Excel Custom Functions. - * @beta - * - * @remarks - * Each add-in instance has its own storage partition, unique to a user and their device. - * - * The default amount of total storage allowed per add-in is 5MB. - * - * Each method listed below returns a Promise object. - * - */ - interface AsyncStorage { - /* - * @beta - * Retrieves an object based on a key and invokes a callback when finished. Returns a Promise. - */ - getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise; - /* - * @beta - * Assigns the value for a key-value pair and invokes a callback when finished. Returns a Promise. - */ - setItem(key: string, value: string, callback?: (error?: Error) => void): Promise; - /* - * @beta - * Removes an item for specified key and invokes a callback when finished. Returns a Promise. - */ - removeItem(key: string, callback?: (error?: Error) => void): Promise; - /* - * @beta - * Erases all AsyncStorage. Returns a Promise. - */ - clear(callback?: (error?: Error) => void): Promise; - /* - * @beta - * Returns a Promise with all keys. - */ - getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise; - /* - * @beta - * Stores multiple key-value pairs in one batch. Returns a Promise. When a key doesn't exist, returns null. - */ - multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; - /* - * @beta - * Deletes a batch of keys, specified in the `keys` array. - */ - multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise; - /* - * @beta - * Fetches a batch of keys, specified in the `keys` array. When a key doesn't exist, returns null. - */ - multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise; - } - /* - * @beta - * Object representing the dialog box. - */ - interface Dialog { - /* - * @beta - * Method that closes a dialog box. - */ - close(): Promise; - } - /* - * Provides options for how a dialog is displayed. - */ - interface DisplayWebDialogOptions { - /* - * @beta - * Determines whether the dialog box displays as a popup (false) or within an IFrame (true). This setting is only applicable to custom functions running on Excel Online. - */ - displayInIFrame?: boolean; - /* - * @beta - * Defines the height of the dialog box as a percentage of the current display. - */ - height?: string; - /* - * @beta - * Defines the width of the dialog box as a percentage of the current display. - */ - width?: string; - /* - * @beta - * True if title is hidden from the dialog box. - */ - hideTitle?: boolean; - /* - * @beta - * Callback that is run when the dialog box is closed. - */ - onClose?: () => void; - /* - * @beta - * Callback that is run when the dialog box sends an error. - */ - onMessage?(message: string, dialog?: Dialog): void; - } - } diff --git a/types/office-runtime/office-runtime-tests.ts b/types/office-runtime/office-runtime-tests.ts deleted file mode 100644 index 889665b3df..0000000000 --- a/types/office-runtime/office-runtime-tests.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* -office-runtime -Copyright (c) Microsoft Corporation -*/ - -OfficeRuntime.AsyncStorage.getItem("foo", () => { - // perform an action -}); -OfficeRuntime.AsyncStorage.getItem("foo").then(value => console.log(value)); - -OfficeRuntime.AsyncStorage.setItem("foo", "bar"); -OfficeRuntime.AsyncStorage.setItem("foo", "bar").then(error => console.log(error)); - -OfficeRuntime.AsyncStorage.removeItem("foo"); -OfficeRuntime.AsyncStorage.removeItem("foo", () => { - // perform an action -}); - -OfficeRuntime.AsyncStorage.clear(); -OfficeRuntime.AsyncStorage.clear(() => { - // perform an action -}); - -OfficeRuntime.AsyncStorage.getAllKeys().then(keys => { - keys.forEach(item => console.log(item)); -}); - -OfficeRuntime.AsyncStorage.getAllKeys((error, keys) => { - if (error) { - console.error(error); - } else { - keys.forEach(item => console.log(item)); - } -}); - -OfficeRuntime.AsyncStorage.multiSet( - [["username", "foo"], ["yearOfBirth", "2001"]], - errors => { - errors.filter(error => error != null).forEach(error => console.log(error)); - } -); - -OfficeRuntime.AsyncStorage.multiRemove(["foo", "bar"]); -OfficeRuntime.AsyncStorage.multiRemove(["foo", "bar"]).then(value => console.log(value)); - -OfficeRuntime.AsyncStorage.multiGet(["username", "yearOfBirth"]).then( - values => { - console.log(values[0][1]); - console.log(values[1][1]); - } -); - -OfficeRuntime.displayWebDialog("https://localhost:3000", { - displayInIFrame: false -}); - -OfficeRuntime.displayWebDialog("https://localhost:3000", { - onClose: () => { - console.log("closed"); - } -}); diff --git a/types/office-runtime/tslint.json b/types/office-runtime/tslint.json deleted file mode 100644 index f93cf8562a..0000000000 --- a/types/office-runtime/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "dtslint/dt.json" -}