@d-mok/quasar-app-extension-quasar-axe 2.0.5 → 2.0.6
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
|
@@ -19,12 +19,12 @@ const props = withDefaults(
|
|
|
19
19
|
defineProps<{
|
|
20
20
|
options: any[]
|
|
21
21
|
modelValue: any
|
|
22
|
-
optionLabel
|
|
22
|
+
optionLabel?: string | ((_: any) => string)
|
|
23
23
|
ticker?: number
|
|
24
24
|
}>(),
|
|
25
25
|
{
|
|
26
|
-
ticker: 0,
|
|
27
26
|
optionLabel: $ => String($),
|
|
27
|
+
ticker: 0,
|
|
28
28
|
}
|
|
29
29
|
)
|
|
30
30
|
const emits = defineEmits(['update:modelValue'])
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
supabase,
|
|
3
|
+
HANDLE_ERROR,
|
|
4
|
+
PostgrestFilterBuilder,
|
|
5
|
+
PostgrestSingleResponse,
|
|
6
|
+
} from '../../supabase'
|
|
2
7
|
import { Filter } from '../type'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function chunk<T>(arr: T[], size: number): T[][] {
|
|
8
|
-
if (size <= 0) return []
|
|
9
|
-
let newArr = []
|
|
10
|
-
for (let i = 0; i < arr.length; i += size) {
|
|
11
|
-
newArr.push(arr.slice(i, i + size))
|
|
12
|
-
}
|
|
13
|
-
return newArr
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
import _ from 'lodash'
|
|
17
9
|
|
|
18
10
|
async function send<R>(q: PostgrestFilterBuilder<R>): Promise<R[]> {
|
|
19
11
|
let { data, error } = await q
|
|
@@ -21,73 +13,67 @@ async function send<R>(q: PostgrestFilterBuilder<R>): Promise<R[]> {
|
|
|
21
13
|
return data
|
|
22
14
|
}
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
async function sendSingle<R>(
|
|
17
|
+
q: PromiseLike<PostgrestSingleResponse<R>>
|
|
18
|
+
): Promise<R[]> {
|
|
26
19
|
let { data, error } = await q
|
|
27
20
|
HANDLE_ERROR(data, error)
|
|
28
21
|
return [data]
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
function parseFilter<R>(
|
|
25
|
+
q: PostgrestFilterBuilder<R>,
|
|
26
|
+
filter: Filter<R>
|
|
27
|
+
): PostgrestFilterBuilder<R> {
|
|
35
28
|
if (filter.type === 'eq') q = q.eq(filter.payload.key, filter.payload.val)
|
|
36
29
|
if (filter.type === 'in') q = q.in(filter.payload.key, filter.payload.vals)
|
|
37
|
-
if (filter.type === 'like')
|
|
30
|
+
if (filter.type === 'like')
|
|
31
|
+
q = q.like(filter.payload.key, filter.payload.pattern)
|
|
38
32
|
return q
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
function parseLimit<R>(
|
|
36
|
+
q: PostgrestFilterBuilder<R>,
|
|
37
|
+
filter: Filter<R>
|
|
38
|
+
): PostgrestFilterBuilder<R> {
|
|
39
|
+
if (filter.type === 'limit') q = q.limit(filter.payload)
|
|
45
40
|
return q
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
function parseOrder<R>(
|
|
44
|
+
q: PostgrestFilterBuilder<R>,
|
|
45
|
+
filter: Filter<R>
|
|
46
|
+
): PostgrestFilterBuilder<R> {
|
|
50
47
|
if (filter.type === 'order')
|
|
51
48
|
q = q.order(filter.payload.key, { ascending: filter.payload.asc })
|
|
52
49
|
return q
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
|
|
56
52
|
function parseFilters<R>(
|
|
57
53
|
q: PostgrestFilterBuilder<R>,
|
|
58
54
|
filters: Filter<R>[]
|
|
59
55
|
): PostgrestFilterBuilder<R> {
|
|
60
|
-
for (const filter of filters)
|
|
61
|
-
|
|
62
|
-
for (const filter of filters)
|
|
63
|
-
q = parseOrder(q, filter)
|
|
64
|
-
for (const filter of filters)
|
|
65
|
-
q = parseLimit(q, filter)
|
|
56
|
+
for (const filter of filters) q = parseFilter(q, filter)
|
|
57
|
+
for (const filter of filters) q = parseOrder(q, filter)
|
|
58
|
+
for (const filter of filters) q = parseLimit(q, filter)
|
|
66
59
|
return q
|
|
67
60
|
}
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
62
|
/**
|
|
73
63
|
* I am responsible for providing database operation.
|
|
74
64
|
* Purely functional.
|
|
75
65
|
*/
|
|
76
66
|
class DB {
|
|
77
|
-
|
|
78
67
|
async select<R>(
|
|
79
68
|
table: string,
|
|
80
69
|
fields: (keyof R)[],
|
|
81
70
|
filters: Filter<R>[]
|
|
82
71
|
): Promise<R[]> {
|
|
83
|
-
let q = supabase
|
|
84
|
-
.from<R>(table)
|
|
85
|
-
.select(fields.join(','))
|
|
72
|
+
let q = supabase.from<R>(table).select(fields.join(','))
|
|
86
73
|
q = parseFilters(q, filters)
|
|
87
74
|
return send(q)
|
|
88
75
|
}
|
|
89
76
|
|
|
90
|
-
|
|
91
77
|
async selectIn<R, K extends keyof R>(
|
|
92
78
|
table: string,
|
|
93
79
|
fields: (keyof R)[],
|
|
@@ -103,78 +89,57 @@ class DB {
|
|
|
103
89
|
q = parseFilters(q, filters)
|
|
104
90
|
return send(q)
|
|
105
91
|
}
|
|
106
|
-
let promises = chunk(vals, 100).map(getRows)
|
|
92
|
+
let promises = _.chunk(vals, 100).map(getRows)
|
|
107
93
|
let result = await Promise.all(promises)
|
|
108
94
|
return result.flat()
|
|
109
95
|
}
|
|
110
96
|
|
|
111
|
-
|
|
112
97
|
async rpc<R>(
|
|
113
98
|
fn: string,
|
|
114
99
|
param: object,
|
|
115
100
|
filters: Filter<R>[]
|
|
116
101
|
): Promise<R[]> {
|
|
117
|
-
let q = supabase
|
|
118
|
-
.rpc<R>(fn, param)
|
|
102
|
+
let q = supabase.rpc<R>(fn, param)
|
|
119
103
|
q = parseFilters(q, filters)
|
|
120
104
|
return send(q)
|
|
121
105
|
}
|
|
122
106
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
async insert<R>(
|
|
126
|
-
table: string,
|
|
127
|
-
rows: Partial<R>[]
|
|
128
|
-
): Promise<R[]> {
|
|
129
|
-
let q = supabase
|
|
130
|
-
.from<R>(table)
|
|
131
|
-
.insert(rows)
|
|
107
|
+
async insert<R>(table: string, rows: Partial<R>[]): Promise<R[]> {
|
|
108
|
+
let q = supabase.from<R>(table).insert(rows)
|
|
132
109
|
return send(q)
|
|
133
110
|
}
|
|
134
111
|
|
|
135
|
-
|
|
136
112
|
async update<R, K extends keyof R>(
|
|
137
113
|
table: string,
|
|
138
114
|
idKey: K,
|
|
139
115
|
idVal: R[K],
|
|
140
116
|
row: Partial<R>
|
|
141
117
|
): Promise<R[]> {
|
|
142
|
-
let q = supabase
|
|
143
|
-
.from<R>(table)
|
|
144
|
-
.update(row)
|
|
145
|
-
.eq(idKey, idVal)
|
|
146
|
-
.single()
|
|
118
|
+
let q = supabase.from<R>(table).update(row).eq(idKey, idVal).single()
|
|
147
119
|
return sendSingle(q)
|
|
148
120
|
}
|
|
149
121
|
|
|
150
|
-
|
|
151
122
|
async delete<R, K extends keyof R>(
|
|
152
123
|
table: string,
|
|
153
124
|
idKey: K,
|
|
154
125
|
idVal: R[K]
|
|
155
126
|
): Promise<R[]> {
|
|
156
|
-
let q = supabase
|
|
157
|
-
.from<R>(table)
|
|
158
|
-
.delete()
|
|
159
|
-
.eq(idKey, idVal)
|
|
160
|
-
.single()
|
|
127
|
+
let q = supabase.from<R>(table).delete().eq(idKey, idVal).single()
|
|
161
128
|
return sendSingle(q)
|
|
162
129
|
}
|
|
163
130
|
|
|
164
|
-
|
|
165
131
|
async upsert<R, K extends keyof R>(
|
|
166
132
|
table: string,
|
|
167
133
|
idKey: K,
|
|
168
134
|
row: Partial<R>,
|
|
169
135
|
conflictKeys: (keyof R)[]
|
|
170
136
|
): Promise<R[]> {
|
|
171
|
-
|
|
172
137
|
let conflict: any = {}
|
|
173
138
|
for (let f of conflictKeys) {
|
|
174
139
|
conflict[f] = row[f]
|
|
175
140
|
}
|
|
176
141
|
|
|
177
|
-
let q = supabase.from<R>(table).select(
|
|
142
|
+
let q = supabase.from<R>(table).select('*').match(conflict)
|
|
178
143
|
let data = await send(q)
|
|
179
144
|
|
|
180
145
|
if (data.length > 1)
|
|
@@ -186,11 +151,7 @@ class DB {
|
|
|
186
151
|
} else {
|
|
187
152
|
return await this.insert(table, [row])
|
|
188
153
|
}
|
|
189
|
-
|
|
190
154
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
155
|
}
|
|
194
156
|
|
|
195
|
-
|
|
196
|
-
export const db = new DB()
|
|
157
|
+
export const db = new DB()
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<q-select
|
|
3
|
-
v-model="selected"
|
|
4
|
-
:options="options"
|
|
5
|
-
v-bind="$attrs"
|
|
6
|
-
/>
|
|
7
|
-
</template>
|
|
8
|
-
|
|
9
|
-
<script
|
|
10
|
-
lang="ts"
|
|
11
|
-
setup
|
|
12
|
-
>
|
|
13
|
-
import { watch } from 'vue'
|
|
14
|
-
import { useVModel } from '@vueuse/core'
|
|
15
|
-
|
|
16
|
-
const props = defineProps<{
|
|
17
|
-
options: string[]
|
|
18
|
-
modelValue: string
|
|
19
|
-
}>()
|
|
20
|
-
|
|
21
|
-
const emits = defineEmits(['update:modelValue'])
|
|
22
|
-
|
|
23
|
-
const selected = useVModel(props, 'modelValue', emits)
|
|
24
|
-
|
|
25
|
-
function rePick() {
|
|
26
|
-
if (props.options.length === 0) return
|
|
27
|
-
|
|
28
|
-
if (!props.options.includes(selected.value))
|
|
29
|
-
selected.value = props.options[0]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
rePick()
|
|
33
|
-
watch(() => props.options, rePick)
|
|
34
|
-
</script>
|