-
Notifications
You must be signed in to change notification settings - Fork 450
/
types.ts
137 lines (114 loc) · 3.52 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import LegacyFormData from 'form-data'
// TODO shared with other packages
export type StorageErrorPayload = {
error: string
status: number
message: string
}
// TODO shared with other packages
export interface StorageActionErrorState {
/**
* @return `true` if an error occurred
* @depreacted use `!isSuccess` or `!!error` instead
* */
isError: boolean
/** Provides details about the error */
error: StorageErrorPayload | null
}
// * Avoid circular references and broken links in docusaurus generated docs
export interface FileUploadConfig {
accessToken?: string
url: string
adminSecret?: string
}
export interface StorageHeadersParam {
headers?: Record<string, string>
}
// works only in browser. Used for for hooks
export interface StorageUploadFileParams extends StorageHeadersParam {
file: File
id?: string
name?: string
bucketId?: string
}
// works in browser and server
export interface StorageUploadFormDataParams extends StorageHeadersParam {
formData: FormData | LegacyFormData
bucketId?: string
}
// works in browser and server
export type StorageUploadParams = StorageUploadFileParams | StorageUploadFormDataParams
export type StorageUploadFileResponse =
| { fileMetadata: FileResponse; error: null }
| { fileMetadata: null; error: StorageErrorPayload }
export type StorageUploadFormDataResponse =
| { fileMetadata: { processedFiles: FileResponse[] }; error: null }
| { fileMetadata: null; error: StorageErrorPayload }
export type StorageUploadResponse = StorageUploadFileResponse | StorageUploadFormDataResponse
export interface StorageDownloadFileParams
extends StorageImageTransformationParams,
StorageHeadersParam {
fileId: string
}
export type StorageDownloadFileResponse = { file: Blob; error: null } | { file: null; error: Error }
export interface StorageImageTransformationParams {
/** Image width, in pixels */
width?: number
/** Image height, in pixels */
height?: number
/** Image quality, between 1 and 100, 100 being the best quality */
quality?: number
/** Image blur, between 0 and 100 */
blur?: number
// TODO not implemented yet in hasura-storage
/** Image radius */
// radius?: number
}
export interface StorageGetUrlParams extends StorageImageTransformationParams {
fileId: string
}
export interface StorageGetPresignedUrlParams
extends StorageImageTransformationParams,
StorageHeadersParam {
fileId: string
}
export type StorageGetPresignedUrlResponse =
| { presignedUrl: { url: string; expiration: number }; error: null }
| { presignedUrl: null; error: Error }
export interface StorageDeleteParams {
fileId: string
}
export interface StorageDeleteResponse {
error: Error | null
}
export interface FileResponse {
id: string
name: string
size: number
mimeType: string
etag: string
createdAt: string
bucketId: string
isUploaded: true
updatedAt: string
uploadedByUserId: string
}
// TODO not implemented yet in hasura-storage
// export interface ApiGetPresignedUrlParams extends StorageImageTransformationParams {
export interface ApiGetPresignedUrlParams extends StorageHeadersParam {
fileId: string
}
export type ApiGetPresignedUrlResponse =
| { presignedUrl: { url: string; expiration: number }; error: null }
| { presignedUrl: null; error: Error }
export interface ApiDeleteParams extends StorageHeadersParam {
fileId: string
}
export interface ApiDeleteResponse {
error: Error | null
}
export type UploadHeaders = HeadersInit & {
'x-nhost-bucket-id'?: string
'x-nhost-file-id'?: string
'x-nhost-file-name'?: string
}