@d-mok/quasar-app-extension-quasar-axe 3.1.67 → 3.1.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
supabase,
|
|
3
|
-
HANDLE_ERROR,
|
|
4
|
-
PostgrestFilterBuilder,
|
|
5
|
-
} from '../../supabase'
|
|
1
|
+
import { supabase, handleError, PostgrestFilterBuilder } from '../../supabase'
|
|
6
2
|
import { Filter } from '../type'
|
|
7
3
|
|
|
8
4
|
type FilterBuilder = PostgrestFilterBuilder<any, any, any, any>
|
|
9
5
|
|
|
10
6
|
async function send(q: any): Promise<any[]> {
|
|
11
|
-
let
|
|
12
|
-
HANDLE_ERROR(data, error)
|
|
7
|
+
let data = await q.then(handleError)
|
|
13
8
|
return Array.isArray(data) ? data : [data]
|
|
14
9
|
}
|
|
15
10
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { supabase,
|
|
1
|
+
import { supabase, handleError } from '.'
|
|
2
2
|
import { reactive } from 'vue'
|
|
3
3
|
import { FileOptions } from '@supabase/storage-js'
|
|
4
|
-
import { exportFile } from 'quasar'
|
|
5
4
|
import { mimeTypesToExt } from './mimeTypesToExt'
|
|
6
5
|
|
|
7
6
|
export class SupabaseBucket extends Map<string, string> {
|
|
@@ -11,28 +10,28 @@ export class SupabaseBucket extends Map<string, string> {
|
|
|
11
10
|
|
|
12
11
|
private async listPaths(): Promise<string[]> {
|
|
13
12
|
// can only list file in root folder
|
|
14
|
-
const
|
|
13
|
+
const data = await supabase.storage
|
|
15
14
|
.from(this.bucketName)
|
|
16
15
|
.list(undefined, { limit: 10000 })
|
|
17
|
-
|
|
16
|
+
.then(handleError)
|
|
18
17
|
return data.pluck('name')
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
private async getUrl(path: string): Promise<string> {
|
|
22
|
-
const
|
|
21
|
+
const data = await supabase.storage
|
|
23
22
|
.from(this.bucketName)
|
|
24
23
|
.createSignedUrl(path, 60 * 60 * 24)
|
|
25
|
-
|
|
24
|
+
.then(handleError)
|
|
26
25
|
return data.signedUrl
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
private async getUrls(
|
|
30
29
|
paths: string[]
|
|
31
30
|
): Promise<{ path: string | null; signedUrl: string }[]> {
|
|
32
|
-
const
|
|
31
|
+
const data = await supabase.storage
|
|
33
32
|
.from(this.bucketName)
|
|
34
33
|
.createSignedUrls(paths, 60 * 60 * 24)
|
|
35
|
-
|
|
34
|
+
.then(handleError)
|
|
36
35
|
return data
|
|
37
36
|
}
|
|
38
37
|
|
|
@@ -56,10 +55,10 @@ export class SupabaseBucket extends Map<string, string> {
|
|
|
56
55
|
file: File | Blob,
|
|
57
56
|
fileOptions?: FileOptions
|
|
58
57
|
): Promise<void> {
|
|
59
|
-
const
|
|
58
|
+
const data = await supabase.storage
|
|
60
59
|
.from(this.bucketName)
|
|
61
60
|
.upload(path, file, fileOptions)
|
|
62
|
-
|
|
61
|
+
.then(handleError)
|
|
63
62
|
await this.load(path)
|
|
64
63
|
}
|
|
65
64
|
|
|
@@ -68,10 +67,10 @@ export class SupabaseBucket extends Map<string, string> {
|
|
|
68
67
|
file: File | Blob,
|
|
69
68
|
fileOptions?: FileOptions
|
|
70
69
|
): Promise<void> {
|
|
71
|
-
const
|
|
70
|
+
const data = await supabase.storage
|
|
72
71
|
.from(this.bucketName)
|
|
73
72
|
.update(path, file, fileOptions)
|
|
74
|
-
|
|
73
|
+
.then(handleError)
|
|
75
74
|
await this.load(path)
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -80,34 +79,34 @@ export class SupabaseBucket extends Map<string, string> {
|
|
|
80
79
|
file: File | Blob,
|
|
81
80
|
fileOptions?: FileOptions
|
|
82
81
|
): Promise<void> {
|
|
83
|
-
const
|
|
82
|
+
const data = await supabase.storage
|
|
84
83
|
.from(this.bucketName)
|
|
85
84
|
.upload(path, file, { ...fileOptions, upsert: true })
|
|
86
|
-
|
|
85
|
+
.then(handleError)
|
|
87
86
|
await this.load(path)
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
async remove(path: string): Promise<void> {
|
|
91
|
-
const
|
|
90
|
+
const data = await supabase.storage
|
|
92
91
|
.from(this.bucketName)
|
|
93
92
|
.remove([path])
|
|
94
|
-
|
|
93
|
+
.then(handleError)
|
|
95
94
|
this.delete(path)
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
async copy(fromPath: string, toPath: string): Promise<void> {
|
|
99
|
-
const
|
|
98
|
+
const data = await supabase.storage
|
|
100
99
|
.from(this.bucketName)
|
|
101
100
|
.copy(fromPath, toPath)
|
|
102
|
-
|
|
101
|
+
.then(handleError)
|
|
103
102
|
await this.load(toPath)
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
async move(fromPath: string, toPath: string): Promise<void> {
|
|
107
|
-
const
|
|
106
|
+
const data = await supabase.storage
|
|
108
107
|
.from(this.bucketName)
|
|
109
108
|
.move(fromPath, toPath)
|
|
110
|
-
|
|
109
|
+
.then(handleError)
|
|
111
110
|
await this.load(toPath)
|
|
112
111
|
this.delete(fromPath)
|
|
113
112
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClient,
|
|
3
|
-
PostgrestError,
|
|
4
|
-
SupabaseClient,
|
|
5
|
-
Session,
|
|
6
|
-
} from '@supabase/supabase-js'
|
|
1
|
+
import { PostgrestError, SupabaseClient } from '@supabase/supabase-js'
|
|
7
2
|
import { qDialog } from './dialog'
|
|
8
3
|
|
|
9
4
|
export type {
|
|
@@ -16,7 +11,6 @@ let SUPABASE_KEY = process.env.SUPABASE_KEY ?? ''
|
|
|
16
11
|
|
|
17
12
|
export class MySupabaseClient extends SupabaseClient {
|
|
18
13
|
email: string = 'unauthenticated'
|
|
19
|
-
// session: Session | null = null
|
|
20
14
|
|
|
21
15
|
constructor() {
|
|
22
16
|
super(SUPABASE_URL, SUPABASE_KEY, {
|
|
@@ -24,15 +18,9 @@ export class MySupabaseClient extends SupabaseClient {
|
|
|
24
18
|
// @ts-ignore
|
|
25
19
|
schema: process.env.SUPABASE_SCHEMA ?? 'public',
|
|
26
20
|
},
|
|
27
|
-
// auth: {
|
|
28
|
-
// autoRefreshToken: true,
|
|
29
|
-
// persistSession: true,
|
|
30
|
-
// detectSessionInUrl: true,
|
|
31
|
-
// },
|
|
32
21
|
})
|
|
33
22
|
this.auth.onAuthStateChange((event, session) => {
|
|
34
23
|
console.log('[SUPABASE AUTH]', event, session?.user?.email)
|
|
35
|
-
// this.session = session
|
|
36
24
|
this.email = session?.user?.email ?? 'unauthenticated'
|
|
37
25
|
})
|
|
38
26
|
}
|
|
@@ -52,42 +40,19 @@ export class MySupabaseClient extends SupabaseClient {
|
|
|
52
40
|
}
|
|
53
41
|
|
|
54
42
|
async call<T>(fn: string, params?: object | undefined): Promise<T[]> {
|
|
55
|
-
|
|
56
|
-
HANDLE_ERROR(data, error)
|
|
57
|
-
return data
|
|
43
|
+
return await this.rpc<string, any>(fn, params).then(handleError)
|
|
58
44
|
}
|
|
59
45
|
|
|
60
46
|
async callSingle<T>(fn: string, params?: object | undefined): Promise<T> {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
return (await this.rpc<string, any>(fn, params)
|
|
48
|
+
.single()
|
|
49
|
+
.then(handleError)) as T
|
|
64
50
|
}
|
|
65
51
|
|
|
66
|
-
// private async tryRefreshSession() {
|
|
67
|
-
// try {
|
|
68
|
-
// await this.auth.refreshSession()
|
|
69
|
-
// } catch (e) {
|
|
70
|
-
// console.error('[Supabase] Refresh session failed', e)
|
|
71
|
-
// }
|
|
72
|
-
// }
|
|
73
|
-
|
|
74
52
|
async waitForSignin(): Promise<void> {
|
|
75
|
-
// await this.tryRefreshSession()
|
|
76
53
|
await this.auth.initialize()
|
|
77
54
|
const { data } = await this.auth.getClaims()
|
|
78
55
|
if (data === null) this.signIn()
|
|
79
|
-
// setInterval(async () => {
|
|
80
|
-
// if (this.session === null) await this.tryRefreshSession()
|
|
81
|
-
// if (this.session === null) this.signIn()
|
|
82
|
-
// }, 1000)
|
|
83
|
-
// setInterval(async () => {
|
|
84
|
-
// await this.auth.refreshSession()
|
|
85
|
-
// }, 1000 * 60 * 30 * 0.99)
|
|
86
|
-
// await waitFor(
|
|
87
|
-
// () => this.session !== null,
|
|
88
|
-
// '[Wait for SignIn] waiting...',
|
|
89
|
-
// '[Wait for SignIn] DONE!'
|
|
90
|
-
// )
|
|
91
56
|
}
|
|
92
57
|
}
|
|
93
58
|
|
|
@@ -95,7 +60,7 @@ export let supabase: MySupabaseClient
|
|
|
95
60
|
if (SUPABASE_URL !== '' && SUPABASE_KEY !== '')
|
|
96
61
|
supabase = new MySupabaseClient()
|
|
97
62
|
|
|
98
|
-
|
|
63
|
+
function HANDLE_ERROR<T>(
|
|
99
64
|
data: T[] | T | null,
|
|
100
65
|
error: PostgrestError | Error | null
|
|
101
66
|
): asserts data {
|
|
@@ -121,21 +86,13 @@ export function HANDLE_ERROR<T>(
|
|
|
121
86
|
}
|
|
122
87
|
}
|
|
123
88
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// } else {
|
|
135
|
-
// console.log(waitingMsg)
|
|
136
|
-
// setTimeout(checker, 50)
|
|
137
|
-
// }
|
|
138
|
-
// }
|
|
139
|
-
// checker()
|
|
140
|
-
// })
|
|
141
|
-
// }
|
|
89
|
+
export function handleError<D>({
|
|
90
|
+
data,
|
|
91
|
+
error,
|
|
92
|
+
}: {
|
|
93
|
+
data: D
|
|
94
|
+
error: PostgrestError | Error | null
|
|
95
|
+
}): NonNullable<D> {
|
|
96
|
+
HANDLE_ERROR(data, error)
|
|
97
|
+
return data
|
|
98
|
+
}
|