Преглед на файлове

feat(api): finalize `export type` usage (#1847)

Lucas Fernandes Nogueira преди 4 години
родител
ревизия
612cd8ecb8

+ 1 - 1
.changes/api-export-type.md

@@ -2,4 +2,4 @@
 "api": patch
 ---
 
-Use `export type` to export TS types.
+Use `export type` to export TS types, enums and interfaces.

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
core/tauri/scripts/bundle.js


+ 5 - 3
tooling/api/src/cli.ts

@@ -9,7 +9,7 @@
 
 import { invokeTauriCommand } from './helpers/tauri'
 
-export interface ArgMatch {
+interface ArgMatch {
   /**
    * string if takes value
    * boolean if flag
@@ -22,12 +22,12 @@ export interface ArgMatch {
   occurrences: number
 }
 
-export interface SubcommandMatch {
+interface SubcommandMatch {
   name: string
   matches: CliMatches
 }
 
-export interface CliMatches {
+interface CliMatches {
   args: { [name: string]: ArgMatch }
   subcommand: SubcommandMatch | null
 }
@@ -46,4 +46,6 @@ async function getMatches(): Promise<CliMatches> {
   })
 }
 
+export type { ArgMatch, SubcommandMatch, CliMatches }
+
 export { getMatches }

+ 5 - 3
tooling/api/src/dialog.ts

@@ -10,7 +10,7 @@
 import { invokeTauriCommand } from './helpers/tauri'
 
 /** Extension filters for the file dialog. */
-export interface DialogFilter {
+interface DialogFilter {
   /** Filter name. */
   name: string
   /**
@@ -24,7 +24,7 @@ export interface DialogFilter {
 }
 
 /** Options for the open dialog. */
-export interface OpenDialogOptions {
+interface OpenDialogOptions {
   /** The filters of the dialog. */
   filters?: DialogFilter[]
   /** Initial directory or file path. It must exist. */
@@ -36,7 +36,7 @@ export interface OpenDialogOptions {
 }
 
 /** Options for the save dialog. */
-export interface SaveDialogOptions {
+interface SaveDialogOptions {
   /** The filters of the dialog. */
   filters?: DialogFilter[]
   /** Initial directory or file path. It must exist. */
@@ -83,4 +83,6 @@ async function save(options: SaveDialogOptions = {}): Promise<string> {
   })
 }
 
+export type { DialogFilter, OpenDialogOptions, SaveDialogOptions }
+
 export { open, save }

+ 5 - 3
tooling/api/src/event.ts

@@ -11,7 +11,7 @@ import { invokeTauriCommand } from './helpers/tauri'
 import { emit as emitEvent } from './helpers/event'
 import { transformCallback } from './tauri'
 
-export interface Event<T> {
+interface Event<T> {
   /** Event name */
   event: string
   /** Event identifier used to unlisten */
@@ -20,9 +20,9 @@ export interface Event<T> {
   payload: T
 }
 
-export type EventCallback<T> = (event: Event<T>) => void
+type EventCallback<T> = (event: Event<T>) => void
 
-export type UnlistenFn = () => void
+type UnlistenFn = () => void
 
 /**
  * Unregister the event listener associated with the given id.
@@ -92,4 +92,6 @@ async function emit(event: string, payload?: string): Promise<void> {
   return emitEvent(event, undefined, payload)
 }
 
+export type { Event, EventCallback, UnlistenFn }
+
 export { listen, once, emit }

+ 13 - 5
tooling/api/src/fs.ts

@@ -31,26 +31,26 @@ export enum BaseDirectory {
   Current
 }
 
-export interface FsOptions {
+interface FsOptions {
   dir?: BaseDirectory
 }
 
-export interface FsDirOptions {
+interface FsDirOptions {
   dir?: BaseDirectory
   recursive?: boolean
 }
 
-export interface FsTextFileOption {
+interface FsTextFileOption {
   path: string
   contents: string
 }
 
-export interface FsBinaryFileOption {
+interface FsBinaryFileOption {
   path: string
   contents: ArrayBuffer
 }
 
-export interface FileEntry {
+interface FileEntry {
   path: string
   /**
    * Name of the directory/file
@@ -332,6 +332,14 @@ async function renameFile(
   })
 }
 
+export type {
+  FsOptions,
+  FsDirOptions,
+  FsTextFileOption,
+  FsBinaryFileOption,
+  FileEntry
+}
+
 export {
   BaseDirectory as Dir,
   readTextFile,

+ 7 - 3
tooling/api/src/helpers/tauri.ts

@@ -6,7 +6,7 @@
 
 import { invoke } from '../tauri'
 
-export type TauriModule =
+type TauriModule =
   | 'App'
   | 'Fs'
   | 'Window'
@@ -20,11 +20,15 @@ export type TauriModule =
   | 'GlobalShortcut'
   | 'Process'
 
-export interface TauriCommand {
+interface TauriCommand {
   __tauriModule: TauriModule
   [key: string]: unknown
 }
 
-export async function invokeTauriCommand<T>(command: TauriCommand): Promise<T> {
+async function invokeTauriCommand<T>(command: TauriCommand): Promise<T> {
   return invoke('tauri', command)
 }
+
+export type { TauriModule, TauriCommand }
+
+export { invokeTauriCommand }

+ 23 - 12
tooling/api/src/http.ts

@@ -9,26 +9,26 @@
 
 import { invokeTauriCommand } from './helpers/tauri'
 
-export interface ClientOptions {
+interface ClientOptions {
   maxRedirections: number
   connectTimeout: number
 }
 
-export enum ResponseType {
+enum ResponseType {
   JSON = 1,
   Text = 2,
   Binary = 3
 }
 
-export type Part = 'string' | number[]
+type Part = 'string' | number[]
 
 /** The body object to be used on POST and PUT requests. */
-export class Body {
+class Body {
   type: string
   payload: unknown
 
   /** @ignore */
-  constructor(type: string, payload: unknown) {
+  private constructor(type: string, payload: unknown) {
     this.type = type
     this.payload = payload
   }
@@ -79,7 +79,7 @@ export class Body {
 }
 
 /** The request HTTP verb. */
-export type HttpVerb =
+type HttpVerb =
   | 'GET'
   | 'POST'
   | 'PUT'
@@ -91,7 +91,7 @@ export type HttpVerb =
   | 'TRACE'
 
 /** Options object sent to the backend. */
-export interface HttpOptions {
+interface HttpOptions {
   method: HttpVerb
   url: string
   headers?: Record<string, any>
@@ -102,12 +102,12 @@ export interface HttpOptions {
 }
 
 /** Request options. */
-export type RequestOptions = Omit<HttpOptions, 'method' | 'url'>
+type RequestOptions = Omit<HttpOptions, 'method' | 'url'>
 /** Options for the `fetch` API. */
-export type FetchOptions = Omit<HttpOptions, 'url'>
+type FetchOptions = Omit<HttpOptions, 'url'>
 
 /** Response object. */
-export interface Response<T> {
+interface Response<T> {
   /** The request URL. */
   url: string
   /** The response status code. */
@@ -118,7 +118,7 @@ export interface Response<T> {
   data: T
 }
 
-export class Client {
+class Client {
   id: number
   /** @ignore */
   constructor(id: number) {
@@ -286,4 +286,15 @@ async function fetch<T>(
   })
 }
 
-export { getClient, fetch }
+export type {
+  ClientOptions,
+  ResponseType,
+  Part,
+  HttpVerb,
+  HttpOptions,
+  RequestOptions,
+  FetchOptions,
+  Response
+}
+
+export { getClient, fetch, Body, Client }

+ 4 - 2
tooling/api/src/notification.ts

@@ -12,7 +12,7 @@ import { invokeTauriCommand } from './helpers/tauri'
 /**
  * Options to send a notification.
  */
-export interface Options {
+interface Options {
   /** Notification title. */
   title: string
   /** Optional notification body. */
@@ -22,7 +22,7 @@ export interface Options {
 }
 
 /** Possible permission values. */
-export type Permission = 'granted' | 'denied' | 'default'
+type Permission = 'granted' | 'denied' | 'default'
 
 /**
  * Checks if the permission to send notifications is granted.
@@ -65,4 +65,6 @@ function sendNotification(options: Options | string): void {
   }
 }
 
+export type { Options, Permission }
+
 export { sendNotification, requestPermission, isPermissionGranted }

+ 3 - 1
tooling/api/src/tauri.ts

@@ -54,7 +54,7 @@ function transformCallback(
 }
 
 /** Command arguments. */
-export interface InvokeArgs {
+interface InvokeArgs {
   [key: string]: unknown
 }
 
@@ -84,4 +84,6 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
   })
 }
 
+export type { InvokeArgs }
+
 export { transformCallback, invoke }

+ 10 - 6
tooling/api/src/updater.ts

@@ -9,20 +9,20 @@
 
 import { once, listen, emit, UnlistenFn } from './event'
 
-export type UpdateStatus = 'PENDING' | 'ERROR' | 'DONE' | 'UPTODATE'
+type UpdateStatus = 'PENDING' | 'ERROR' | 'DONE' | 'UPTODATE'
 
-export interface UpdateStatusResult {
+interface UpdateStatusResult {
   error?: string
   status: UpdateStatus
 }
 
-export interface UpdateManifest {
+interface UpdateManifest {
   version: string
   date: string
   body: string
 }
 
-export interface UpdateResult {
+interface UpdateResult {
   manifest?: UpdateManifest
   shouldUpdate: boolean
 }
@@ -32,7 +32,7 @@ export interface UpdateResult {
  *
  * @return A promise indicating the success or failure of the operation.
  */
-export async function installUpdate(): Promise<void> {
+async function installUpdate(): Promise<void> {
   let unlistenerFn: UnlistenFn | undefined
 
   function cleanListener(): void {
@@ -84,7 +84,7 @@ export async function installUpdate(): Promise<void> {
  *
  * @return Promise resolving to the update status.
  */
-export async function checkUpdate(): Promise<UpdateResult> {
+async function checkUpdate(): Promise<UpdateResult> {
   let unlistenerFn: UnlistenFn | undefined
 
   function cleanListener(): void {
@@ -147,3 +147,7 @@ export async function checkUpdate(): Promise<UpdateResult> {
     })
   })
 }
+
+export type { UpdateStatus, UpdateStatusResult, UpdateManifest, UpdateResult }
+
+export { installUpdate, checkUpdate }

+ 4 - 3
tooling/api/src/window.ts

@@ -267,7 +267,7 @@ class WebviewWindow extends WebviewWindowHandle {
 /**
  * Manage the current window object.
  */
-export class WindowManager {
+class WindowManager {
   // Getters
   /** The scale factor that can be used to map physical pixels to logical pixels. */
   async scaleFactor(): Promise<number> {
@@ -703,7 +703,7 @@ export class WindowManager {
 const appWindow = new WindowManager()
 
 /** Configuration for the window to create. */
-export interface WindowOptions {
+interface WindowOptions {
   /**
    * Remote URL or local file path to open, e.g. `https://github.com/tauri-apps` or `path/to/page.html`.
    */
@@ -781,6 +781,7 @@ async function availableMonitors(): Promise<Monitor[]> {
 export {
   WebviewWindow,
   WebviewWindowHandle,
+  WindowManager,
   getCurrent,
   getAll,
   appWindow,
@@ -793,4 +794,4 @@ export {
   availableMonitors
 }
 
-export type { Monitor }
+export type { Monitor, WindowOptions }

Някои файлове не бяха показани, защото твърде много файлове са промени