@d-mok/quasar-app-extension-quasar-axe 3.1.2 → 3.1.4
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 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
DeleteBuilder,
|
|
3
|
+
InsertBuilder,
|
|
4
|
+
SelectBuilder,
|
|
5
|
+
SelectInBuilder,
|
|
6
|
+
SelectRPCBuilder,
|
|
7
|
+
UpdateBuilder,
|
|
8
|
+
UpsertBuilder,
|
|
9
|
+
} from './builder'
|
|
10
|
+
import { Constructor, Key, BooleanKeys } from './type'
|
|
11
|
+
import { Core } from './core'
|
|
12
|
+
import { reactive } from 'vue'
|
|
13
|
+
|
|
14
|
+
export function ORM<
|
|
15
|
+
RBase extends Constructor,
|
|
16
|
+
K extends Key<InstanceType<RBase>>
|
|
17
|
+
>(RClass: RBase, tableName: string, idKey: K) {
|
|
18
|
+
type R = InstanceType<RBase>
|
|
19
|
+
|
|
20
|
+
class E extends RClass {
|
|
21
|
+
private _hostTable: InstanceType<ReturnType<typeof getTable>>
|
|
22
|
+
|
|
23
|
+
constructor(...args: any[]) {
|
|
24
|
+
super()
|
|
25
|
+
let [row, hostTable] = args
|
|
26
|
+
Object.assign(this, row)
|
|
27
|
+
this._hostTable = hostTable
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
update(this: E & R, row: Partial<R>) {
|
|
31
|
+
return this._hostTable.update(this[idKey], row)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
delete(this: E & R) {
|
|
35
|
+
return this._hostTable.delete(this[idKey])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toggle(this: E & R, key: BooleanKeys<R>) {
|
|
39
|
+
let val = !this[key]
|
|
40
|
+
let obj = { [key]: val } as Partial<R>
|
|
41
|
+
return this._hostTable.update(this[idKey], obj)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getTable<EBase extends RBase>(EClass: EBase) {
|
|
46
|
+
type T = InstanceType<EBase>
|
|
47
|
+
|
|
48
|
+
function convertor(host: TableClass) {
|
|
49
|
+
return ($: R) => new EClass($, host) as T
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function core(host: TableClass) {
|
|
53
|
+
return new Core<T, R>(
|
|
54
|
+
tableName,
|
|
55
|
+
idKey,
|
|
56
|
+
Object.keys(new RClass()) as Key<R>[],
|
|
57
|
+
convertor(host)
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class TableClass extends Array<InstanceType<EBase>> {
|
|
62
|
+
/** make reactive */
|
|
63
|
+
reactive(): this {
|
|
64
|
+
const rec = reactive(this) as this
|
|
65
|
+
if (process.env.DEBUGGING) {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
globalThis.TABLES.push(rec)
|
|
68
|
+
}
|
|
69
|
+
return rec
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
protected onChange(): void {}
|
|
73
|
+
protected onEdit(): void {}
|
|
74
|
+
protected onSanitize(row: Partial<R>): Partial<R> {
|
|
75
|
+
return row
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
select() {
|
|
79
|
+
let callback = ($: T[]) => {
|
|
80
|
+
this.set($)
|
|
81
|
+
this.onChange()
|
|
82
|
+
}
|
|
83
|
+
return new SelectBuilder(core(this), callback)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
patch() {
|
|
87
|
+
let callback = ($: T[]) => {
|
|
88
|
+
this.absorb($, idKey)
|
|
89
|
+
this.onChange()
|
|
90
|
+
}
|
|
91
|
+
return new SelectBuilder(core(this), callback)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
selectIn<K extends Key<R>>(key: K, vals: R[K][]) {
|
|
95
|
+
let callback = ($: T[]) => {
|
|
96
|
+
this.set($)
|
|
97
|
+
this.sortBy($ => vals.indexOf($[key]))
|
|
98
|
+
this.onChange()
|
|
99
|
+
}
|
|
100
|
+
return new SelectInBuilder(key, vals, core(this), callback)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
patchIn<K extends Key<R>>(key: K, vals: R[K][]) {
|
|
104
|
+
let callback = ($: T[]) => {
|
|
105
|
+
this.absorb($, idKey)
|
|
106
|
+
this.sortBy($ => vals.indexOf($[key]))
|
|
107
|
+
this.onChange()
|
|
108
|
+
}
|
|
109
|
+
return new SelectInBuilder(key, vals, core(this), callback)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
selectRPC(param: object = {}) {
|
|
113
|
+
let callback = ($: T[]) => {
|
|
114
|
+
this.set($)
|
|
115
|
+
this.onChange()
|
|
116
|
+
}
|
|
117
|
+
return new SelectRPCBuilder(param, core(this), callback)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
patchRPC(param: object = {}) {
|
|
121
|
+
let callback = ($: T[]) => {
|
|
122
|
+
this.absorb($, idKey)
|
|
123
|
+
this.onChange()
|
|
124
|
+
}
|
|
125
|
+
return new SelectRPCBuilder(param, core(this), callback)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
selectCustom(rows: R[]) {
|
|
129
|
+
let convert = core(this).convertor
|
|
130
|
+
let entities = rows.map(convert)
|
|
131
|
+
this.set(entities)
|
|
132
|
+
this.onChange()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
insert(row: Partial<R>) {
|
|
136
|
+
row = this.onSanitize(row)
|
|
137
|
+
let callback = ($: T[]) => {
|
|
138
|
+
this.push(...$)
|
|
139
|
+
this.onChange()
|
|
140
|
+
this.onEdit()
|
|
141
|
+
}
|
|
142
|
+
return new InsertBuilder([row], core(this), callback).notify(
|
|
143
|
+
'Created!'
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
insertMany(rows: Partial<R>[]) {
|
|
148
|
+
rows = rows.map(this.onSanitize)
|
|
149
|
+
let callback = ($: T[]) => {
|
|
150
|
+
this.push(...$)
|
|
151
|
+
this.onChange()
|
|
152
|
+
this.onEdit()
|
|
153
|
+
}
|
|
154
|
+
return new InsertBuilder(rows, core(this), callback).notify(
|
|
155
|
+
'Created!'
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
update(idVal: R[K], row: Partial<R>) {
|
|
160
|
+
row = this.onSanitize(row)
|
|
161
|
+
let callback = ($: T[]) => {
|
|
162
|
+
this.merge($, idKey)
|
|
163
|
+
this.onChange()
|
|
164
|
+
this.onEdit()
|
|
165
|
+
}
|
|
166
|
+
return new UpdateBuilder(
|
|
167
|
+
idVal,
|
|
168
|
+
row,
|
|
169
|
+
core(this),
|
|
170
|
+
callback
|
|
171
|
+
).notify('Updated!')
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
delete(idVal: R[K]) {
|
|
175
|
+
let callback = ($: T[]) => {
|
|
176
|
+
this.remove($ => $[idKey] === idVal)
|
|
177
|
+
this.onChange()
|
|
178
|
+
this.onEdit()
|
|
179
|
+
}
|
|
180
|
+
return new DeleteBuilder(idVal, core(this), callback).notify(
|
|
181
|
+
'Deleted!'
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
upsert(row: Partial<R>, conflictKeys: Key<R>[]) {
|
|
186
|
+
row = this.onSanitize(row)
|
|
187
|
+
let callback = ($: T[]) => {
|
|
188
|
+
this.absorb($, idKey)
|
|
189
|
+
this.onChange()
|
|
190
|
+
this.onEdit()
|
|
191
|
+
}
|
|
192
|
+
return new UpsertBuilder(
|
|
193
|
+
row,
|
|
194
|
+
conflictKeys,
|
|
195
|
+
core(this),
|
|
196
|
+
callback
|
|
197
|
+
).notify('Updated!')
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return TableClass
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
console.dev(
|
|
205
|
+
`Create Table [${tableName}] idKey [${idKey}] entity [${E.name}]`
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
return { Entity: E, Table: getTable }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (process.env.DEBUGGING) {
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
globalThis.TABLES = []
|
|
214
|
+
}
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DeleteBuilder,
|
|
3
|
-
InsertBuilder,
|
|
4
|
-
SelectBuilder,
|
|
5
|
-
SelectInBuilder,
|
|
6
|
-
SelectRPCBuilder,
|
|
7
|
-
UpdateBuilder,
|
|
8
|
-
UpsertBuilder,
|
|
9
|
-
} from './builder'
|
|
10
|
-
import { Constructor, Key, BooleanKeys } from './type'
|
|
11
|
-
import { Core } from './core'
|
|
12
|
-
import { reactive } from 'vue'
|
|
13
|
-
|
|
14
|
-
export function ORM<
|
|
15
|
-
RBase extends Constructor,
|
|
16
|
-
K extends Key<InstanceType<RBase>>
|
|
17
|
-
>(RClass: RBase, tableName: string, idKey: K) {
|
|
18
|
-
type R = InstanceType<RBase>
|
|
19
|
-
|
|
20
|
-
class E extends RClass {
|
|
21
|
-
private _hostTable: InstanceType<ReturnType<typeof getTable>>
|
|
22
|
-
|
|
23
|
-
constructor(...args: any[]) {
|
|
24
|
-
super()
|
|
25
|
-
let [row, hostTable] = args
|
|
26
|
-
Object.assign(this, row)
|
|
27
|
-
this._hostTable = hostTable
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
update(this: E & R, row: Partial<R>) {
|
|
31
|
-
return this._hostTable.update(this[idKey], row)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
delete(this: E & R) {
|
|
35
|
-
return this._hostTable.delete(this[idKey])
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
toggle(this: E & R, key: BooleanKeys<R>) {
|
|
39
|
-
let val = !this[key]
|
|
40
|
-
let obj = { [key]: val } as Partial<R>
|
|
41
|
-
return this._hostTable.update(this[idKey], obj)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getTable<EBase extends RBase>(EClass: EBase) {
|
|
46
|
-
type T = InstanceType<EBase>
|
|
47
|
-
|
|
48
|
-
function convertor(host: TableClass) {
|
|
49
|
-
return ($: R) => new EClass($, host) as T
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function core(host: TableClass) {
|
|
53
|
-
return new Core<T, R>(
|
|
54
|
-
tableName,
|
|
55
|
-
idKey,
|
|
56
|
-
Object.keys(new RClass()) as Key<R>[],
|
|
57
|
-
convertor(host)
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
class TableClass extends Array<InstanceType<EBase>> {
|
|
62
|
-
/** make reactive */
|
|
63
|
-
reactive(): this {
|
|
64
|
-
const rec = reactive(this) as this
|
|
65
|
-
if (process.env.DEBUGGING) {
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
globalThis.TABLES.push(rec)
|
|
68
|
-
}
|
|
69
|
-
return rec
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
protected onChange(): void {}
|
|
73
|
-
protected onEdit(): void {}
|
|
74
|
-
protected onSanitize(row: Partial<R>): Partial<R> {
|
|
75
|
-
return row
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
select() {
|
|
79
|
-
let callback = ($: T[]) => {
|
|
80
|
-
this.set($)
|
|
81
|
-
this.onChange()
|
|
82
|
-
}
|
|
83
|
-
return new SelectBuilder(core(this), callback)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
patch() {
|
|
87
|
-
let callback = ($: T[]) => {
|
|
88
|
-
this.absorb($, idKey)
|
|
89
|
-
this.onChange()
|
|
90
|
-
}
|
|
91
|
-
return new SelectBuilder(core(this), callback)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
selectIn<K extends Key<R>>(key: K, vals: R[K][]) {
|
|
95
|
-
let callback = ($: T[]) => {
|
|
96
|
-
this.set($)
|
|
97
|
-
this.sortBy($ => vals.indexOf($[key]))
|
|
98
|
-
this.onChange()
|
|
99
|
-
}
|
|
100
|
-
return new SelectInBuilder(key, vals, core(this), callback)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
patchIn<K extends Key<R>>(key: K, vals: R[K][]) {
|
|
104
|
-
let callback = ($: T[]) => {
|
|
105
|
-
this.absorb($, idKey)
|
|
106
|
-
this.sortBy($ => vals.indexOf($[key]))
|
|
107
|
-
this.onChange()
|
|
108
|
-
}
|
|
109
|
-
return new SelectInBuilder(key, vals, core(this), callback)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
selectRPC(param: object = {}) {
|
|
113
|
-
let callback = ($: T[]) => {
|
|
114
|
-
this.set($)
|
|
115
|
-
this.onChange()
|
|
116
|
-
}
|
|
117
|
-
return new SelectRPCBuilder(param, core(this), callback)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
patchRPC(param: object = {}) {
|
|
121
|
-
let callback = ($: T[]) => {
|
|
122
|
-
this.absorb($, idKey)
|
|
123
|
-
this.onChange()
|
|
124
|
-
}
|
|
125
|
-
return new SelectRPCBuilder(param, core(this), callback)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
selectCustom(rows: R[]) {
|
|
129
|
-
let convert = core(this).convertor
|
|
130
|
-
let entities = rows.map(convert)
|
|
131
|
-
this.set(entities)
|
|
132
|
-
this.onChange()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
insert(row: Partial<R>) {
|
|
136
|
-
row = this.onSanitize(row)
|
|
137
|
-
let callback = ($: T[]) => {
|
|
138
|
-
this.push(...$)
|
|
139
|
-
this.onChange()
|
|
140
|
-
this.onEdit()
|
|
141
|
-
}
|
|
142
|
-
return new InsertBuilder([row], core(this), callback).notify(
|
|
143
|
-
'Created!'
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
insertMany(rows: Partial<R>[]) {
|
|
148
|
-
rows = rows.map(this.onSanitize)
|
|
149
|
-
let callback = ($: T[]) => {
|
|
150
|
-
this.push(...$)
|
|
151
|
-
this.onChange()
|
|
152
|
-
this.onEdit()
|
|
153
|
-
}
|
|
154
|
-
return new InsertBuilder(rows, core(this), callback).notify(
|
|
155
|
-
'Created!'
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
update(idVal: R[K], row: Partial<R>) {
|
|
160
|
-
row = this.onSanitize(row)
|
|
161
|
-
let callback = ($: T[]) => {
|
|
162
|
-
this.merge($, idKey)
|
|
163
|
-
this.onChange()
|
|
164
|
-
this.onEdit()
|
|
165
|
-
}
|
|
166
|
-
return new UpdateBuilder(
|
|
167
|
-
idVal,
|
|
168
|
-
row,
|
|
169
|
-
core(this),
|
|
170
|
-
callback
|
|
171
|
-
).notify('Updated!')
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
delete(idVal: R[K]) {
|
|
175
|
-
let callback = ($: T[]) => {
|
|
176
|
-
this.remove($ => $[idKey] === idVal)
|
|
177
|
-
this.onChange()
|
|
178
|
-
this.onEdit()
|
|
179
|
-
}
|
|
180
|
-
return new DeleteBuilder(idVal, core(this), callback).notify(
|
|
181
|
-
'Deleted!'
|
|
182
|
-
)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
upsert(row: Partial<R>, conflictKeys: Key<R>[]) {
|
|
186
|
-
row = this.onSanitize(row)
|
|
187
|
-
let callback = ($: T[]) => {
|
|
188
|
-
this.absorb($, idKey)
|
|
189
|
-
this.onChange()
|
|
190
|
-
this.onEdit()
|
|
191
|
-
}
|
|
192
|
-
return new UpsertBuilder(
|
|
193
|
-
row,
|
|
194
|
-
conflictKeys,
|
|
195
|
-
core(this),
|
|
196
|
-
callback
|
|
197
|
-
).notify('Updated!')
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return TableClass
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
console.dev(
|
|
205
|
-
`Create Table [${tableName}] idKey [${idKey}] entity [${E.name}]`
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
return { Entity: E, Table: getTable }
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (process.env.DEBUGGING) {
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
globalThis.TABLES = []
|
|
214
|
-
}
|