Skip to content

Commit 612cd8e

Browse files
authored
feat(api): finalize export type usage (#1847)
1 parent 7616e6c commit 612cd8e

File tree

12 files changed

+81
-43
lines changed

12 files changed

+81
-43
lines changed

.changes/api-export-type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"api": patch
33
---
44

5-
Use `export type` to export TS types.
5+
Use `export type` to export TS types, enums and interfaces.

core/tauri/scripts/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/api/src/cli.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { invokeTauriCommand } from './helpers/tauri'
1111

12-
export interface ArgMatch {
12+
interface ArgMatch {
1313
/**
1414
* string if takes value
1515
* boolean if flag
@@ -22,12 +22,12 @@ export interface ArgMatch {
2222
occurrences: number
2323
}
2424

25-
export interface SubcommandMatch {
25+
interface SubcommandMatch {
2626
name: string
2727
matches: CliMatches
2828
}
2929

30-
export interface CliMatches {
30+
interface CliMatches {
3131
args: { [name: string]: ArgMatch }
3232
subcommand: SubcommandMatch | null
3333
}
@@ -46,4 +46,6 @@ async function getMatches(): Promise<CliMatches> {
4646
})
4747
}
4848

49+
export type { ArgMatch, SubcommandMatch, CliMatches }
50+
4951
export { getMatches }

tooling/api/src/dialog.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { invokeTauriCommand } from './helpers/tauri'
1111

1212
/** Extension filters for the file dialog. */
13-
export interface DialogFilter {
13+
interface DialogFilter {
1414
/** Filter name. */
1515
name: string
1616
/**
@@ -24,7 +24,7 @@ export interface DialogFilter {
2424
}
2525

2626
/** Options for the open dialog. */
27-
export interface OpenDialogOptions {
27+
interface OpenDialogOptions {
2828
/** The filters of the dialog. */
2929
filters?: DialogFilter[]
3030
/** Initial directory or file path. It must exist. */
@@ -36,7 +36,7 @@ export interface OpenDialogOptions {
3636
}
3737

3838
/** Options for the save dialog. */
39-
export interface SaveDialogOptions {
39+
interface SaveDialogOptions {
4040
/** The filters of the dialog. */
4141
filters?: DialogFilter[]
4242
/** Initial directory or file path. It must exist. */
@@ -83,4 +83,6 @@ async function save(options: SaveDialogOptions = {}): Promise<string> {
8383
})
8484
}
8585

86+
export type { DialogFilter, OpenDialogOptions, SaveDialogOptions }
87+
8688
export { open, save }

tooling/api/src/event.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { invokeTauriCommand } from './helpers/tauri'
1111
import { emit as emitEvent } from './helpers/event'
1212
import { transformCallback } from './tauri'
1313

14-
export interface Event<T> {
14+
interface Event<T> {
1515
/** Event name */
1616
event: string
1717
/** Event identifier used to unlisten */
@@ -20,9 +20,9 @@ export interface Event<T> {
2020
payload: T
2121
}
2222

23-
export type EventCallback<T> = (event: Event<T>) => void
23+
type EventCallback<T> = (event: Event<T>) => void
2424

25-
export type UnlistenFn = () => void
25+
type UnlistenFn = () => void
2626

2727
/**
2828
* Unregister the event listener associated with the given id.
@@ -92,4 +92,6 @@ async function emit(event: string, payload?: string): Promise<void> {
9292
return emitEvent(event, undefined, payload)
9393
}
9494

95+
export type { Event, EventCallback, UnlistenFn }
96+
9597
export { listen, once, emit }

tooling/api/src/fs.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ export enum BaseDirectory {
3131
Current
3232
}
3333

34-
export interface FsOptions {
34+
interface FsOptions {
3535
dir?: BaseDirectory
3636
}
3737

38-
export interface FsDirOptions {
38+
interface FsDirOptions {
3939
dir?: BaseDirectory
4040
recursive?: boolean
4141
}
4242

43-
export interface FsTextFileOption {
43+
interface FsTextFileOption {
4444
path: string
4545
contents: string
4646
}
4747

48-
export interface FsBinaryFileOption {
48+
interface FsBinaryFileOption {
4949
path: string
5050
contents: ArrayBuffer
5151
}
5252

53-
export interface FileEntry {
53+
interface FileEntry {
5454
path: string
5555
/**
5656
* Name of the directory/file
@@ -332,6 +332,14 @@ async function renameFile(
332332
})
333333
}
334334

335+
export type {
336+
FsOptions,
337+
FsDirOptions,
338+
FsTextFileOption,
339+
FsBinaryFileOption,
340+
FileEntry
341+
}
342+
335343
export {
336344
BaseDirectory as Dir,
337345
readTextFile,

tooling/api/src/helpers/tauri.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { invoke } from '../tauri'
88

9-
export type TauriModule =
9+
type TauriModule =
1010
| 'App'
1111
| 'Fs'
1212
| 'Window'
@@ -20,11 +20,15 @@ export type TauriModule =
2020
| 'GlobalShortcut'
2121
| 'Process'
2222

23-
export interface TauriCommand {
23+
interface TauriCommand {
2424
__tauriModule: TauriModule
2525
[key: string]: unknown
2626
}
2727

28-
export async function invokeTauriCommand<T>(command: TauriCommand): Promise<T> {
28+
async function invokeTauriCommand<T>(command: TauriCommand): Promise<T> {
2929
return invoke('tauri', command)
3030
}
31+
32+
export type { TauriModule, TauriCommand }
33+
34+
export { invokeTauriCommand }

tooling/api/src/http.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99

1010
import { invokeTauriCommand } from './helpers/tauri'
1111

12-
export interface ClientOptions {
12+
interface ClientOptions {
1313
maxRedirections: number
1414
connectTimeout: number
1515
}
1616

17-
export enum ResponseType {
17+
enum ResponseType {
1818
JSON = 1,
1919
Text = 2,
2020
Binary = 3
2121
}
2222

23-
export type Part = 'string' | number[]
23+
type Part = 'string' | number[]
2424

2525
/** The body object to be used on POST and PUT requests. */
26-
export class Body {
26+
class Body {
2727
type: string
2828
payload: unknown
2929

3030
/** @ignore */
31-
constructor(type: string, payload: unknown) {
31+
private constructor(type: string, payload: unknown) {
3232
this.type = type
3333
this.payload = payload
3434
}
@@ -79,7 +79,7 @@ export class Body {
7979
}
8080

8181
/** The request HTTP verb. */
82-
export type HttpVerb =
82+
type HttpVerb =
8383
| 'GET'
8484
| 'POST'
8585
| 'PUT'
@@ -91,7 +91,7 @@ export type HttpVerb =
9191
| 'TRACE'
9292

9393
/** Options object sent to the backend. */
94-
export interface HttpOptions {
94+
interface HttpOptions {
9595
method: HttpVerb
9696
url: string
9797
headers?: Record<string, any>
@@ -102,12 +102,12 @@ export interface HttpOptions {
102102
}
103103

104104
/** Request options. */
105-
export type RequestOptions = Omit<HttpOptions, 'method' | 'url'>
105+
type RequestOptions = Omit<HttpOptions, 'method' | 'url'>
106106
/** Options for the `fetch` API. */
107-
export type FetchOptions = Omit<HttpOptions, 'url'>
107+
type FetchOptions = Omit<HttpOptions, 'url'>
108108

109109
/** Response object. */
110-
export interface Response<T> {
110+
interface Response<T> {
111111
/** The request URL. */
112112
url: string
113113
/** The response status code. */
@@ -118,7 +118,7 @@ export interface Response<T> {
118118
data: T
119119
}
120120

121-
export class Client {
121+
class Client {
122122
id: number
123123
/** @ignore */
124124
constructor(id: number) {
@@ -286,4 +286,15 @@ async function fetch<T>(
286286
})
287287
}
288288

289-
export { getClient, fetch }
289+
export type {
290+
ClientOptions,
291+
ResponseType,
292+
Part,
293+
HttpVerb,
294+
HttpOptions,
295+
RequestOptions,
296+
FetchOptions,
297+
Response
298+
}
299+
300+
export { getClient, fetch, Body, Client }

tooling/api/src/notification.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { invokeTauriCommand } from './helpers/tauri'
1212
/**
1313
* Options to send a notification.
1414
*/
15-
export interface Options {
15+
interface Options {
1616
/** Notification title. */
1717
title: string
1818
/** Optional notification body. */
@@ -22,7 +22,7 @@ export interface Options {
2222
}
2323

2424
/** Possible permission values. */
25-
export type Permission = 'granted' | 'denied' | 'default'
25+
type Permission = 'granted' | 'denied' | 'default'
2626

2727
/**
2828
* Checks if the permission to send notifications is granted.
@@ -65,4 +65,6 @@ function sendNotification(options: Options | string): void {
6565
}
6666
}
6767

68+
export type { Options, Permission }
69+
6870
export { sendNotification, requestPermission, isPermissionGranted }

tooling/api/src/tauri.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function transformCallback(
5454
}
5555

5656
/** Command arguments. */
57-
export interface InvokeArgs {
57+
interface InvokeArgs {
5858
[key: string]: unknown
5959
}
6060

@@ -84,4 +84,6 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
8484
})
8585
}
8686

87+
export type { InvokeArgs }
88+
8789
export { transformCallback, invoke }

0 commit comments

Comments
 (0)