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