feat(tauri.js) move exported api types into api modules (fix #807) (#809)

This commit is contained in:
chip 2020-07-12 15:34:44 -07:00 committed by GitHub
parent a0a2d86565
commit 660a2d87d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 133 additions and 126 deletions

View File

@ -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`.

View File

@ -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
*/

View File

@ -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<OpenDialogOptions, 'filter' | 'defaultPath'>
/**
* @name openDialog
* @description Open a file/directory selection dialog

View File

@ -1,5 +1,11 @@
import { invoke, transformCallback } from './tauri'
import { EventCallback } from './types/event'
export interface Event<T> {
type: string
payload: T
}
export type EventCallback<T> = (event: Event<T>) => void
/**
* listen to an event from the backend

View File

@ -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

View File

@ -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<string, any>
params?: Record<string, any>
body?: Body
followRedirects: boolean
maxRedirections: boolean
connectTimeout: number
readTimeout: number
timeout: number
allowCompression: boolean
responseType?: ResponseType
bodyType: BodyType
}
export type PartialOptions = Omit<HttpOptions, 'method' | 'url'>
/**
* makes a HTTP request

View File

@ -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<Options, 'title'>
export type Permission = 'granted' | 'denied' | 'default'
async function isPermissionGranted(): Promise<boolean | null> {
if (window.Notification.permission !== 'default') {
return await Promise.resolve(window.Notification.permission === 'granted')

View File

@ -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
}

View File

@ -1,8 +0,0 @@
export interface OpenDialogOptions {
filter?: string
defaultPath?: string
multiple?: boolean
directory?: boolean
}
export type SaveDialogOptions = Pick<OpenDialogOptions, 'filter' | 'defaultPath'>

View File

@ -1,6 +0,0 @@
export interface Event<T> {
type: string
payload: T
}
export type EventCallback<T> = (event: Event<T>) => void

View File

@ -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[]
}

View File

@ -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<string, any>
params?: Record<string, any>
body?: Body
followRedirects: boolean
maxRedirections: boolean
connectTimeout: number
readTimeout: number
timeout: number
allowCompression: boolean
responseType?: ResponseType
bodyType: BodyType
}
export type PartialOptions = Omit<HttpOptions, 'method' | 'url'>

View File

@ -1,8 +0,0 @@
export interface Options {
title: string
body?: string
icon?: string
}
export type PartialOptions = Omit<Options, 'title'>
export type Permission = 'granted' | 'denied' | 'default'