From 660a2d87d6acf0abf6be70c01e6402cb5aba96c7 Mon Sep 17 00:00:00 2001 From: chip Date: Sun, 12 Jul 2020 15:34:44 -0700 Subject: [PATCH] feat(tauri.js) move exported api types into api modules (fix #807) (#809) --- .changes/taurijs_move_api_types_into_api.md | 7 ++++ cli/tauri.js/api-src/cli.ts | 24 ++++++++++- cli/tauri.js/api-src/dialog.ts | 10 ++++- cli/tauri.js/api-src/event.ts | 8 +++- cli/tauri.js/api-src/fs.ts | 45 ++++++++++++++++++++- cli/tauri.js/api-src/http.ts | 35 +++++++++++++++- cli/tauri.js/api-src/notification.ts | 10 ++++- cli/tauri.js/api-src/types/cli.ts | 22 ---------- cli/tauri.js/api-src/types/dialog.ts | 8 ---- cli/tauri.js/api-src/types/event.ts | 6 --- cli/tauri.js/api-src/types/fs.ts | 43 -------------------- cli/tauri.js/api-src/types/http.ts | 33 --------------- cli/tauri.js/api-src/types/notification.ts | 8 ---- 13 files changed, 133 insertions(+), 126 deletions(-) create mode 100644 .changes/taurijs_move_api_types_into_api.md delete mode 100644 cli/tauri.js/api-src/types/cli.ts delete mode 100644 cli/tauri.js/api-src/types/dialog.ts delete mode 100644 cli/tauri.js/api-src/types/event.ts delete mode 100644 cli/tauri.js/api-src/types/fs.ts delete mode 100644 cli/tauri.js/api-src/types/http.ts delete mode 100644 cli/tauri.js/api-src/types/notification.ts diff --git a/.changes/taurijs_move_api_types_into_api.md b/.changes/taurijs_move_api_types_into_api.md new file mode 100644 index 000000000..3f4255e26 --- /dev/null +++ b/.changes/taurijs_move_api_types_into_api.md @@ -0,0 +1,7 @@ +--- +"tauri.js": minor +--- + +Move types exported in the `tauri` js api into the modules that use them. For +example, `Event` is now available from `tauri/api/event` instead of +`tauri/api/types/event`. diff --git a/cli/tauri.js/api-src/cli.ts b/cli/tauri.js/api-src/cli.ts index 39011db9e..b513f1ff1 100644 --- a/cli/tauri.js/api-src/cli.ts +++ b/cli/tauri.js/api-src/cli.ts @@ -1,6 +1,28 @@ -import { CliMatches } from './types/cli' import { promisified } from './tauri' +export interface ArgMatch { + /** + * string if takes value + * boolean if flag + * string[] or null if takes multiple values + */ + value: string | boolean | string[] | null + /** + * number of occurrences + */ + occurrences: number +} + +export interface SubcommandMatch { + name: string + matches: CliMatches +} + +export interface CliMatches { + args: { [name: string]: ArgMatch } + subcommand: SubcommandMatch | null +} + /** * gets the CLI matches */ diff --git a/cli/tauri.js/api-src/dialog.ts b/cli/tauri.js/api-src/dialog.ts index a9e9e4a07..6f223b0d6 100644 --- a/cli/tauri.js/api-src/dialog.ts +++ b/cli/tauri.js/api-src/dialog.ts @@ -1,6 +1,14 @@ -import { OpenDialogOptions, SaveDialogOptions } from './types/dialog' import { promisified } from './tauri' +export interface OpenDialogOptions { + filter?: string + defaultPath?: string + multiple?: boolean + directory?: boolean +} + +export type SaveDialogOptions = Pick + /** * @name openDialog * @description Open a file/directory selection dialog diff --git a/cli/tauri.js/api-src/event.ts b/cli/tauri.js/api-src/event.ts index 11ee63cf3..d9a3a1a8c 100644 --- a/cli/tauri.js/api-src/event.ts +++ b/cli/tauri.js/api-src/event.ts @@ -1,5 +1,11 @@ import { invoke, transformCallback } from './tauri' -import { EventCallback } from './types/event' + +export interface Event { + type: string + payload: T +} + +export type EventCallback = (event: Event) => void /** * listen to an event from the backend diff --git a/cli/tauri.js/api-src/fs.ts b/cli/tauri.js/api-src/fs.ts index 966681892..439743799 100644 --- a/cli/tauri.js/api-src/fs.ts +++ b/cli/tauri.js/api-src/fs.ts @@ -1,5 +1,48 @@ import { promisified } from './tauri' -import { BaseDirectory, FsOptions, FsTextFileOption, FsBinaryFileOption, FileEntry } from './types/fs' + +export enum BaseDirectory { + Audio = 1, + Cache, + Config, + Data, + LocalData, + Desktop, + Document, + Download, + Executable, + Font, + Home, + Picture, + Public, + Runtime, + Template, + Video, + Resource, + App, +} + +export interface FsOptions { + dir?: BaseDirectory +} + +export interface FsTextFileOption { + path: string + contents: string +} + +export interface FsBinaryFileOption { + path: string + contents: ArrayBuffer +} + +export interface FileEntry { + path: string + // name of the directory/file + // can be null if the path terminates with `..` + name?: string + // children of this entry if it's a directory; null otherwise + children?: FileEntry[] +} /** * reads a file as text diff --git a/cli/tauri.js/api-src/http.ts b/cli/tauri.js/api-src/http.ts index c88e4f965..9527f1491 100644 --- a/cli/tauri.js/api-src/http.ts +++ b/cli/tauri.js/api-src/http.ts @@ -1,5 +1,38 @@ import { promisified } from './tauri' -import { HttpOptions, Body, BodyType, ResponseType, PartialOptions } from './types/http' + +export enum ResponseType { + JSON = 1, + Text = 2, + Binary = 3 +} + +export enum BodyType { + Form = 1, + File = 2, + Auto = 3 +} + +export type Body = object | string | BinaryType + +export type HttpVerb = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' + +export interface HttpOptions { + method: HttpVerb + url: string + headers?: Record + params?: Record + body?: Body + followRedirects: boolean + maxRedirections: boolean + connectTimeout: number + readTimeout: number + timeout: number + allowCompression: boolean + responseType?: ResponseType + bodyType: BodyType +} + +export type PartialOptions = Omit /** * makes a HTTP request diff --git a/cli/tauri.js/api-src/notification.ts b/cli/tauri.js/api-src/notification.ts index 8d0a97f18..517f55083 100644 --- a/cli/tauri.js/api-src/notification.ts +++ b/cli/tauri.js/api-src/notification.ts @@ -1,6 +1,14 @@ -import { Options, Permission } from './types/notification' import { promisified } from './tauri' +export interface Options { + title: string + body?: string + icon?: string +} + +export type PartialOptions = Omit +export type Permission = 'granted' | 'denied' | 'default' + async function isPermissionGranted(): Promise { if (window.Notification.permission !== 'default') { return await Promise.resolve(window.Notification.permission === 'granted') diff --git a/cli/tauri.js/api-src/types/cli.ts b/cli/tauri.js/api-src/types/cli.ts deleted file mode 100644 index 483e75089..000000000 --- a/cli/tauri.js/api-src/types/cli.ts +++ /dev/null @@ -1,22 +0,0 @@ -export interface ArgMatch { - /** - * string if takes value - * boolean if flag - * string[] or null if takes multiple values - */ - value: string | boolean | string[] | null - /** - * number of occurrences - */ - occurrences: number -} - -export interface SubcommandMatch { - name: string - matches: CliMatches -} - -export interface CliMatches { - args: { [name: string]: ArgMatch } - subcommand: SubcommandMatch | null -} diff --git a/cli/tauri.js/api-src/types/dialog.ts b/cli/tauri.js/api-src/types/dialog.ts deleted file mode 100644 index 6a45e3add..000000000 --- a/cli/tauri.js/api-src/types/dialog.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface OpenDialogOptions { - filter?: string - defaultPath?: string - multiple?: boolean - directory?: boolean -} - -export type SaveDialogOptions = Pick diff --git a/cli/tauri.js/api-src/types/event.ts b/cli/tauri.js/api-src/types/event.ts deleted file mode 100644 index 624cd6b6b..000000000 --- a/cli/tauri.js/api-src/types/event.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Event { - type: string - payload: T -} - -export type EventCallback = (event: Event) => void diff --git a/cli/tauri.js/api-src/types/fs.ts b/cli/tauri.js/api-src/types/fs.ts deleted file mode 100644 index 391015317..000000000 --- a/cli/tauri.js/api-src/types/fs.ts +++ /dev/null @@ -1,43 +0,0 @@ -export enum BaseDirectory { - Audio = 1, - Cache, - Config, - Data, - LocalData, - Desktop, - Document, - Download, - Executable, - Font, - Home, - Picture, - Public, - Runtime, - Template, - Video, - Resource, - App, -} - -export interface FsOptions { - dir?: BaseDirectory -} - -export interface FsTextFileOption { - path: string - contents: string -} - -export interface FsBinaryFileOption { - path: string - contents: ArrayBuffer -} - -export interface FileEntry { - path: string - // name of the directory/file - // can be null if the path terminates with `..` - name?: string - // children of this entry if it's a directory; null otherwise - children?: FileEntry[] -} diff --git a/cli/tauri.js/api-src/types/http.ts b/cli/tauri.js/api-src/types/http.ts deleted file mode 100644 index c814aa782..000000000 --- a/cli/tauri.js/api-src/types/http.ts +++ /dev/null @@ -1,33 +0,0 @@ -export enum ResponseType { - JSON = 1, - Text = 2, - Binary = 3 -} - -export enum BodyType { - Form = 1, - File = 2, - Auto = 3 -} - -export type Body = object | string | BinaryType - -export type HttpVerb = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' - -export interface HttpOptions { - method: HttpVerb - url: string - headers?: Record - params?: Record - body?: Body - followRedirects: boolean - maxRedirections: boolean - connectTimeout: number - readTimeout: number - timeout: number - allowCompression: boolean - responseType?: ResponseType - bodyType: BodyType -} - -export type PartialOptions = Omit diff --git a/cli/tauri.js/api-src/types/notification.ts b/cli/tauri.js/api-src/types/notification.ts deleted file mode 100644 index 309b8bf84..000000000 --- a/cli/tauri.js/api-src/types/notification.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface Options { - title: string - body?: string - icon?: string -} - -export type PartialOptions = Omit -export type Permission = 'granted' | 'denied' | 'default'