q-koa 13.2.8 → 13.2.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/core/app.js
CHANGED
|
@@ -55,6 +55,15 @@ const runVm = (_str) => {
|
|
|
55
55
|
return nodeVm.runInNewContext(_str)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
const getLiteral = (str) => {
|
|
59
|
+
const reg = /literal\((.+)\)/
|
|
60
|
+
const result = str.match(reg)
|
|
61
|
+
if (result) {
|
|
62
|
+
return result[1] // 返回第一个捕获组
|
|
63
|
+
}
|
|
64
|
+
return ''
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
const memRunVm = _.memoize(runVm)
|
|
59
68
|
const connectDatabase = (database) => (config) => {
|
|
60
69
|
if (!database) throw new Error('请配置数据库名称')
|
|
@@ -504,7 +513,15 @@ class APP {
|
|
|
504
513
|
) {
|
|
505
514
|
try {
|
|
506
515
|
this.app[appName].appConfig.router(router)(this.app[appName])
|
|
507
|
-
} catch (e) {
|
|
516
|
+
} catch (e) {
|
|
517
|
+
this.app[appName].service.log &&
|
|
518
|
+
this.app[appName].service.log.push({
|
|
519
|
+
app: this.app[appName],
|
|
520
|
+
appName,
|
|
521
|
+
message: e.message,
|
|
522
|
+
})
|
|
523
|
+
console.log(e.message)
|
|
524
|
+
}
|
|
508
525
|
}
|
|
509
526
|
|
|
510
527
|
if (this.config.defaultRouter) {
|
|
@@ -1053,7 +1070,7 @@ class APP {
|
|
|
1053
1070
|
}
|
|
1054
1071
|
}
|
|
1055
1072
|
|
|
1056
|
-
if (
|
|
1073
|
+
if (['findAll', 'findAndCountAll'].includes(fn)) {
|
|
1057
1074
|
const disabledFindAllList = _.get(
|
|
1058
1075
|
app[appName],
|
|
1059
1076
|
'appConfig.disabledFindAllList',
|
|
@@ -1067,7 +1084,7 @@ class APP {
|
|
|
1067
1084
|
(where && !_.isEmpty(where))
|
|
1068
1085
|
)
|
|
1069
1086
|
) {
|
|
1070
|
-
throw new Error(
|
|
1087
|
+
throw new Error('请使用条件')
|
|
1071
1088
|
}
|
|
1072
1089
|
}
|
|
1073
1090
|
|
|
@@ -1229,20 +1246,21 @@ class APP {
|
|
|
1229
1246
|
if (
|
|
1230
1247
|
fn === 'findOne' &&
|
|
1231
1248
|
attributes &&
|
|
1249
|
+
Array.isArray(attributes) &&
|
|
1232
1250
|
attributes.length > 0 &&
|
|
1233
1251
|
attributes.every(
|
|
1234
1252
|
(attribute) =>
|
|
1235
1253
|
Array.isArray(attribute) &&
|
|
1236
1254
|
attribute.length === 2 &&
|
|
1237
|
-
attribute.some((o) => o.
|
|
1255
|
+
attribute.some((o) => o.startsWith('literal'))
|
|
1238
1256
|
)
|
|
1239
1257
|
) {
|
|
1240
1258
|
const target = await app[appName].model[controller][fn]({
|
|
1241
1259
|
attributes: attributes.map((attribute) => {
|
|
1242
1260
|
if (Array.isArray(attribute)) {
|
|
1243
1261
|
return attribute.map((att) => {
|
|
1244
|
-
if (att.startsWith('
|
|
1245
|
-
return Sequelize.literal(att)
|
|
1262
|
+
if (att.startsWith('literal')) {
|
|
1263
|
+
return Sequelize.literal(getLiteral(att))
|
|
1246
1264
|
}
|
|
1247
1265
|
return att
|
|
1248
1266
|
})
|
|
@@ -39,9 +39,13 @@ const compareIndex = (tableIndexList, modelIndexList = [], model) => {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const flag =
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const flag =
|
|
43
|
+
tableIndexList.every((i) => {
|
|
44
|
+
return modelIndexList.some((m) => isSameArray(m.fields, i.fields, true))
|
|
45
|
+
}) &&
|
|
46
|
+
modelIndexList.every((i) => {
|
|
47
|
+
return tableIndexList.some((m) => isSameArray(m.fields, i.fields, true))
|
|
48
|
+
})
|
|
45
49
|
|
|
46
50
|
const intersection = lodash.intersectionWith(
|
|
47
51
|
tableIndexList,
|
|
@@ -8,7 +8,14 @@ const runVm = (_str) => {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const memRunVm = lodash.memoize(runVm)
|
|
11
|
-
|
|
11
|
+
const getLiteral = (str) => {
|
|
12
|
+
const reg = /literal\((.+)\)/
|
|
13
|
+
const result = str.match(reg)
|
|
14
|
+
if (result) {
|
|
15
|
+
return result[1] // 返回第一个捕获组
|
|
16
|
+
}
|
|
17
|
+
return ''
|
|
18
|
+
}
|
|
12
19
|
exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
13
20
|
const appConfig = getConfig(app)
|
|
14
21
|
const { version: cacheVersion } = await appConfig.getObject('base')
|
|
@@ -211,6 +218,40 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
|
|
|
211
218
|
}
|
|
212
219
|
})
|
|
213
220
|
} else {
|
|
221
|
+
if (data && lodash.isObject(data)) {
|
|
222
|
+
if (
|
|
223
|
+
fn === 'findOne' &&
|
|
224
|
+
'attributes' in data &&
|
|
225
|
+
Array.isArray(data.attributes) &&
|
|
226
|
+
data.attributes.every((attribute) =>
|
|
227
|
+
Array.isArray(attribute)
|
|
228
|
+
) &&
|
|
229
|
+
data.attributes.some(
|
|
230
|
+
(attribute) =>
|
|
231
|
+
Array.isArray(attribute) &&
|
|
232
|
+
attribute.some((att) => att.startsWith('literal'))
|
|
233
|
+
)
|
|
234
|
+
) {
|
|
235
|
+
return app.model[model][fn]({
|
|
236
|
+
where: data.where,
|
|
237
|
+
attributes: data.attributes.map((attribute) => {
|
|
238
|
+
if (Array.isArray(attribute)) {
|
|
239
|
+
return attribute.map((att) => {
|
|
240
|
+
if (att.startsWith('literal')) {
|
|
241
|
+
return Sequelize.literal(getLiteral(att))
|
|
242
|
+
}
|
|
243
|
+
return att
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
return attribute
|
|
247
|
+
}),
|
|
248
|
+
}).then((res) => {
|
|
249
|
+
return {
|
|
250
|
+
[item]: res,
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
}
|
|
214
255
|
const formatData =
|
|
215
256
|
fn === 'findAll' &&
|
|
216
257
|
data &&
|
|
@@ -145,9 +145,10 @@ module.exports = class Singleton {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
async getPrintList(
|
|
148
|
+
async getPrintList(_machineCode, pageIndex = 1, pageSize = 10) {
|
|
149
149
|
const app = this.config.app
|
|
150
150
|
const accessToken = await this.getAccessToken()
|
|
151
|
+
const machineCode = _machineCode || this.config.machine_code
|
|
151
152
|
try {
|
|
152
153
|
const RpcClient = new yly.RpcClient(accessToken, this.oauthConfig)
|
|
153
154
|
const Print = new yly.Printer(RpcClient)
|
package/core/file/utils/index.js
CHANGED
|
@@ -214,14 +214,45 @@ const isDateTime = (str) => {
|
|
|
214
214
|
/^(\d{4}-\d{2}-\d{2})([T\s](\d{2}:\d{2}(:\d{2}(\.\d+)?)?)([+-]\d{2}:\d{2}|Z)?)?$/
|
|
215
215
|
return dateRegex.test(str)
|
|
216
216
|
}
|
|
217
|
+
|
|
218
|
+
const getCol = (str) => {
|
|
219
|
+
const reg = /col\((.+)\)/
|
|
220
|
+
const result = str.match(reg)
|
|
221
|
+
if (result) {
|
|
222
|
+
return result[1] // 返回第一个捕获组
|
|
223
|
+
}
|
|
224
|
+
return ''
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const getLiteral = (str) => {
|
|
228
|
+
const reg = /literal\((.+)\)/
|
|
229
|
+
const result = str.match(reg)
|
|
230
|
+
if (result) {
|
|
231
|
+
return result[1] // 返回第一个捕获组
|
|
232
|
+
}
|
|
233
|
+
return ''
|
|
234
|
+
}
|
|
217
235
|
const $lt = {
|
|
218
236
|
check: (param) => typeof param === 'string',
|
|
219
237
|
result: (param, key) => {
|
|
238
|
+
if (getCol(param[key])) {
|
|
239
|
+
return {
|
|
240
|
+
[key]: Sequelize.col(getCol(param[key])),
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (getLiteral(param[key])) {
|
|
245
|
+
return {
|
|
246
|
+
[key]: Sequelize.literal(getLiteral(param[key])),
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
220
250
|
if (isDateTime(param[key])) {
|
|
221
251
|
return {
|
|
222
252
|
[key]: param[key],
|
|
223
253
|
}
|
|
224
254
|
}
|
|
255
|
+
|
|
225
256
|
return {
|
|
226
257
|
[key]: Sequelize.literal(param[key]),
|
|
227
258
|
}
|
|
@@ -230,6 +261,17 @@ const $lt = {
|
|
|
230
261
|
const $in = {
|
|
231
262
|
check: (param) => typeof param === 'string',
|
|
232
263
|
result: (param, key) => {
|
|
264
|
+
if (getCol(param[key])) {
|
|
265
|
+
return {
|
|
266
|
+
[key]: Sequelize.col(getCol(param[key])),
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (getLiteral(param[key])) {
|
|
271
|
+
return {
|
|
272
|
+
[key]: Sequelize.literal(getLiteral(param[key])),
|
|
273
|
+
}
|
|
274
|
+
}
|
|
233
275
|
return {
|
|
234
276
|
[key]: [Sequelize.literal(param[key])],
|
|
235
277
|
}
|
|
@@ -239,6 +281,11 @@ const $between = {
|
|
|
239
281
|
check: (param) =>
|
|
240
282
|
Array.isArray(param) && param.every((p) => typeof param === 'string'),
|
|
241
283
|
result: (param, key) => {
|
|
284
|
+
if (param[key].every((i) => getLiteral(i))) {
|
|
285
|
+
return {
|
|
286
|
+
[key]: param[key].map((item) => Sequelize.literal(getLiteral(item))),
|
|
287
|
+
}
|
|
288
|
+
}
|
|
242
289
|
if (param[key].every((i) => isDateTime(i))) {
|
|
243
290
|
return {
|
|
244
291
|
[key]: param[key],
|