@d-mok/quasar-app-extension-quasar-axe 2.1.8 → 2.1.9
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
|
@@ -3,23 +3,15 @@ import {
|
|
|
3
3
|
HANDLE_ERROR,
|
|
4
4
|
PostgrestFilterBuilder,
|
|
5
5
|
PostgrestSingleResponse,
|
|
6
|
-
} from '../../
|
|
6
|
+
} from '../../supabase'
|
|
7
7
|
import { Filter } from '../type'
|
|
8
8
|
|
|
9
9
|
type FilterBuilder = PostgrestFilterBuilder<any, any, any, any>
|
|
10
10
|
|
|
11
|
-
async function send(q:
|
|
11
|
+
async function send(q: any): Promise<any[]> {
|
|
12
12
|
let { data, error } = await q
|
|
13
13
|
HANDLE_ERROR(data, error)
|
|
14
|
-
return data
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function sendSingle(
|
|
18
|
-
q: PromiseLike<PostgrestSingleResponse<any>>
|
|
19
|
-
): Promise<any[]> {
|
|
20
|
-
let { data, error } = await q
|
|
21
|
-
HANDLE_ERROR(data, error)
|
|
22
|
-
return [data]
|
|
14
|
+
return Array.isArray(data) ? data : [data]
|
|
23
15
|
}
|
|
24
16
|
|
|
25
17
|
function parseFilters(q: FilterBuilder, filters: Filter[]): FilterBuilder {
|
|
@@ -78,7 +70,7 @@ class DB {
|
|
|
78
70
|
}
|
|
79
71
|
|
|
80
72
|
async insert(table: string, rows: any[]): Promise<any[]> {
|
|
81
|
-
let q = supabase.from(table).insert(rows)
|
|
73
|
+
let q = supabase.from(table).insert(rows).select('*')
|
|
82
74
|
return send(q)
|
|
83
75
|
}
|
|
84
76
|
|
|
@@ -88,13 +80,23 @@ class DB {
|
|
|
88
80
|
idVal: any,
|
|
89
81
|
row: any
|
|
90
82
|
): Promise<any[]> {
|
|
91
|
-
let q = supabase
|
|
92
|
-
|
|
83
|
+
let q = supabase
|
|
84
|
+
.from(table)
|
|
85
|
+
.update(row)
|
|
86
|
+
.eq(idKey, idVal)
|
|
87
|
+
.select('*')
|
|
88
|
+
.single()
|
|
89
|
+
return send(q)
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
async delete(table: string, idKey: string, idVal: any): Promise<any[]> {
|
|
96
|
-
let q = supabase
|
|
97
|
-
|
|
93
|
+
let q = supabase
|
|
94
|
+
.from(table)
|
|
95
|
+
.delete()
|
|
96
|
+
.eq(idKey, idVal)
|
|
97
|
+
.select('*')
|
|
98
|
+
.single()
|
|
99
|
+
return send(q)
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
async upsert(
|
|
@@ -1,130 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
createClient,
|
|
3
|
+
PostgrestError,
|
|
4
|
+
SupabaseClient,
|
|
5
|
+
Session,
|
|
6
|
+
} from '@supabase/supabase-js'
|
|
7
|
+
import { qDialog } from './dialog'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export type {
|
|
10
|
+
PostgrestFilterBuilder,
|
|
11
|
+
PostgrestSingleResponse,
|
|
12
|
+
} from '@supabase/postgrest-js'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// signIn: () => void
|
|
16
|
-
// accessTokenLife: () => number
|
|
17
|
-
// waitForSignin: () => Promise<void>
|
|
18
|
-
// email: () => string
|
|
19
|
-
// call: <T>(fn: string, params?: object | undefined) => Promise<T[]>
|
|
20
|
-
// callSingle: <T>(fn: string, params?: object | undefined) => Promise<T>
|
|
21
|
-
// }
|
|
22
|
-
// }
|
|
14
|
+
let SUPABASE_URL = process.env.SUPABASE_URL ?? ''
|
|
15
|
+
let SUPABASE_KEY = process.env.SUPABASE_KEY ?? ''
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
export class MySupabaseClient extends SupabaseClient {
|
|
18
|
+
email: string = 'unauthenticated'
|
|
19
|
+
session: Session | null = null
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
constructor() {
|
|
22
|
+
super(SUPABASE_URL, SUPABASE_KEY, {
|
|
23
|
+
auth: {
|
|
24
|
+
autoRefreshToken: true,
|
|
25
|
+
persistSession: true,
|
|
26
|
+
detectSessionInUrl: true,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
this.auth.onAuthStateChange((event, session) => {
|
|
30
|
+
console.log('[SUPABASE AUTH]', event, session?.user?.email)
|
|
31
|
+
this.session = session
|
|
32
|
+
this.email = session?.user?.email ?? 'unauthenticated'
|
|
33
|
+
})
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
async signIn() {
|
|
37
|
+
await this.auth.signOut()
|
|
38
|
+
await this.auth.signInWithOAuth({
|
|
39
|
+
provider: 'google',
|
|
40
|
+
options: {
|
|
41
|
+
redirectTo: window.location.href,
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
}
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// return Math.round(ms / 1000)
|
|
47
|
-
// }
|
|
46
|
+
async call<T>(fn: string, params?: object | undefined): Promise<T[]> {
|
|
47
|
+
let { data, error } = await this.rpc<string, any>(fn, params)
|
|
48
|
+
HANDLE_ERROR(data, error)
|
|
49
|
+
return data
|
|
50
|
+
}
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
async callSingle<T>(fn: string, params?: object | undefined): Promise<T> {
|
|
53
|
+
let { data, error } = await this.rpc<string, any>(fn, params).single()
|
|
54
|
+
HANDLE_ERROR(data, error)
|
|
55
|
+
return data as T
|
|
56
|
+
}
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
async waitForSignin(): Promise<void> {
|
|
59
|
+
setInterval(() => {
|
|
60
|
+
if (this.session === null) this.signIn()
|
|
61
|
+
}, 1000)
|
|
62
|
+
waitFor(
|
|
63
|
+
() => this.session !== null,
|
|
64
|
+
'[Wait for SignIn] waiting...',
|
|
65
|
+
'[Wait for SignIn] DONE!'
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
// fn: string,
|
|
66
|
-
// params?: object | undefined
|
|
67
|
-
// ): Promise<T[]> {
|
|
68
|
-
// let { data, error } = await supabase.rpc<T>(fn, params)
|
|
69
|
-
// HANDLE_ERROR(data, error)
|
|
70
|
-
// return data
|
|
71
|
-
// }
|
|
70
|
+
export let supabase = new MySupabaseClient()
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
export function HANDLE_ERROR<T>(
|
|
73
|
+
data: T[] | T | null,
|
|
74
|
+
error: PostgrestError | null
|
|
75
|
+
): asserts data {
|
|
76
|
+
if (error) {
|
|
77
|
+
if (error.message === 'JWSError JWSInvalidSignature') {
|
|
78
|
+
localStorage.removeItem('supabase.auth.token')
|
|
79
|
+
qDialog.error(
|
|
80
|
+
'Database Error!',
|
|
81
|
+
'Your login session has expired. Please try refreshing the website.'
|
|
82
|
+
)
|
|
83
|
+
throw error
|
|
84
|
+
}
|
|
85
|
+
let msg = ''
|
|
86
|
+
msg += error.details ?? '' + '<br/>'
|
|
87
|
+
msg += error.message ?? '' + '<br/>'
|
|
88
|
+
msg += error.hint ?? ''
|
|
89
|
+
qDialog.error('Database Error!', msg)
|
|
90
|
+
throw error
|
|
91
|
+
}
|
|
92
|
+
if (data === null) {
|
|
93
|
+
qDialog.error('Supabase Error!', 'Returned data is null')
|
|
94
|
+
throw 'supabase return data is null!'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
81
97
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// let msg = ''
|
|
101
|
-
// msg += error.details ?? '' + '<br/>'
|
|
102
|
-
// msg += error.message ?? '' + '<br/>'
|
|
103
|
-
// msg += error.hint ?? ''
|
|
104
|
-
// qDialog.error('Database Error!', msg)
|
|
105
|
-
// throw error
|
|
106
|
-
// }
|
|
107
|
-
// if (data === null) {
|
|
108
|
-
// qDialog.error('Supabase Error!', 'Returned data is null')
|
|
109
|
-
// throw 'supabase return data is null!'
|
|
110
|
-
// }
|
|
111
|
-
// }
|
|
112
|
-
|
|
113
|
-
// async function waitFor(
|
|
114
|
-
// predicate: () => boolean,
|
|
115
|
-
// waitingMsg: string,
|
|
116
|
-
// doneMsg: string
|
|
117
|
-
// ) {
|
|
118
|
-
// return new Promise(resolve => {
|
|
119
|
-
// function checker() {
|
|
120
|
-
// if (predicate()) {
|
|
121
|
-
// console.log(doneMsg)
|
|
122
|
-
// resolve(true)
|
|
123
|
-
// } else {
|
|
124
|
-
// console.log(waitingMsg)
|
|
125
|
-
// setTimeout(() => checker(), 50)
|
|
126
|
-
// }
|
|
127
|
-
// }
|
|
128
|
-
// checker()
|
|
129
|
-
// })
|
|
130
|
-
// }
|
|
98
|
+
async function waitFor(
|
|
99
|
+
predicate: () => boolean,
|
|
100
|
+
waitingMsg: string,
|
|
101
|
+
doneMsg: string
|
|
102
|
+
) {
|
|
103
|
+
return new Promise(resolve => {
|
|
104
|
+
async function checker() {
|
|
105
|
+
if (predicate()) {
|
|
106
|
+
console.log(doneMsg)
|
|
107
|
+
resolve(true)
|
|
108
|
+
} else {
|
|
109
|
+
console.log(waitingMsg)
|
|
110
|
+
setTimeout(checker, 50)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
checker()
|
|
114
|
+
})
|
|
115
|
+
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClient,
|
|
3
|
-
PostgrestError,
|
|
4
|
-
SupabaseClient,
|
|
5
|
-
Session,
|
|
6
|
-
SupabaseClientOptions,
|
|
7
|
-
} from '@supabase/supabase-js'
|
|
8
|
-
import { qDialog } from './dialog'
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
PostgrestFilterBuilder,
|
|
12
|
-
PostgrestSingleResponse,
|
|
13
|
-
} from '@supabase/postgrest-js'
|
|
14
|
-
|
|
15
|
-
let SUPABASE_URL = process.env.SUPABASE_URL ?? ''
|
|
16
|
-
let SUPABASE_KEY = process.env.SUPABASE_KEY ?? ''
|
|
17
|
-
|
|
18
|
-
export class MySupabaseClient extends SupabaseClient {
|
|
19
|
-
email: string = 'unauthenticated'
|
|
20
|
-
session: Session | null = null
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
super(SUPABASE_URL, SUPABASE_KEY, {
|
|
24
|
-
auth: {
|
|
25
|
-
autoRefreshToken: true,
|
|
26
|
-
persistSession: true,
|
|
27
|
-
detectSessionInUrl: true,
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
this.auth.onAuthStateChange((event, session) => {
|
|
31
|
-
console.log('[SUPABASE AUTH]', event, session?.user?.email)
|
|
32
|
-
this.session = session
|
|
33
|
-
this.email = session?.user?.email ?? 'unauthenticated'
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async signIn() {
|
|
38
|
-
await this.auth.signOut()
|
|
39
|
-
await this.auth.signInWithOAuth({
|
|
40
|
-
provider: 'google',
|
|
41
|
-
options: {
|
|
42
|
-
redirectTo: window.location.href,
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async call<T>(fn: string, params?: object | undefined): Promise<T[]> {
|
|
48
|
-
let { data, error } = await this.rpc<string, any>(fn, params)
|
|
49
|
-
HANDLE_ERROR(data, error)
|
|
50
|
-
return data
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async callSingle<T>(fn: string, params?: object | undefined): Promise<T> {
|
|
54
|
-
let { data, error } = await this.rpc<string, any>(fn, params).single()
|
|
55
|
-
HANDLE_ERROR(data, error)
|
|
56
|
-
return data as T
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async waitForSignin(): Promise<void> {
|
|
60
|
-
setInterval(() => {
|
|
61
|
-
if (this.session === null) this.signIn()
|
|
62
|
-
}, 1000)
|
|
63
|
-
waitFor(
|
|
64
|
-
() => this.session !== null,
|
|
65
|
-
'[Wait for SignIn] waiting...',
|
|
66
|
-
'[Wait for SignIn] DONE!'
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export let supabase = new MySupabaseClient()
|
|
72
|
-
|
|
73
|
-
export function HANDLE_ERROR<T>(
|
|
74
|
-
data: T[] | T | null,
|
|
75
|
-
error: PostgrestError | null
|
|
76
|
-
): asserts data {
|
|
77
|
-
if (error) {
|
|
78
|
-
if (error.message === 'JWSError JWSInvalidSignature') {
|
|
79
|
-
localStorage.removeItem('supabase.auth.token')
|
|
80
|
-
qDialog.error(
|
|
81
|
-
'Database Error!',
|
|
82
|
-
'Your login session has expired. Please try refreshing the website.'
|
|
83
|
-
)
|
|
84
|
-
throw error
|
|
85
|
-
}
|
|
86
|
-
let msg = ''
|
|
87
|
-
msg += error.details ?? '' + '<br/>'
|
|
88
|
-
msg += error.message ?? '' + '<br/>'
|
|
89
|
-
msg += error.hint ?? ''
|
|
90
|
-
qDialog.error('Database Error!', msg)
|
|
91
|
-
throw error
|
|
92
|
-
}
|
|
93
|
-
if (data === null) {
|
|
94
|
-
qDialog.error('Supabase Error!', 'Returned data is null')
|
|
95
|
-
throw 'supabase return data is null!'
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function waitFor(
|
|
100
|
-
predicate: () => boolean,
|
|
101
|
-
waitingMsg: string,
|
|
102
|
-
doneMsg: string
|
|
103
|
-
) {
|
|
104
|
-
return new Promise(resolve => {
|
|
105
|
-
async function checker() {
|
|
106
|
-
if (predicate()) {
|
|
107
|
-
console.log(doneMsg)
|
|
108
|
-
resolve(true)
|
|
109
|
-
} else {
|
|
110
|
-
console.log(waitingMsg)
|
|
111
|
-
setTimeout(checker, 50)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
checker()
|
|
115
|
-
})
|
|
116
|
-
}
|