@waline/vercel 1.18.9 → 1.19.0

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.
@@ -15,6 +15,7 @@ if (LEAN_ID && LEAN_KEY && LEAN_MASTER_KEY) {
15
15
  module.exports = class extends Base {
16
16
  parseWhere(className, where) {
17
17
  const instance = new AV.Query(className);
18
+
18
19
  if (think.isEmpty(where)) {
19
20
  return instance;
20
21
  }
@@ -36,6 +37,7 @@ module.exports = class extends Base {
36
37
  if (Array.isArray(where[k])) {
37
38
  if (where[k][0]) {
38
39
  const handler = where[k][0].toUpperCase();
40
+
39
41
  switch (handler) {
40
42
  case 'IN':
41
43
  instance.containedIn(k, where[k][1]);
@@ -46,6 +48,7 @@ module.exports = class extends Base {
46
48
  case 'LIKE': {
47
49
  const first = where[k][1][0];
48
50
  const last = where[k][1].slice(-1);
51
+
49
52
  if (first === '%' && last === '%') {
50
53
  instance.contains(k, where[k][1].slice(1, -1));
51
54
  } else if (first === '%') {
@@ -65,6 +68,7 @@ module.exports = class extends Base {
65
68
  }
66
69
  }
67
70
  }
71
+
68
72
  return instance;
69
73
  }
70
74
 
@@ -74,6 +78,7 @@ module.exports = class extends Base {
74
78
  }
75
79
 
76
80
  const filters = [];
81
+
77
82
  for (const k in where._complex) {
78
83
  if (k === '_logic') {
79
84
  continue;
@@ -83,6 +88,7 @@ module.exports = class extends Base {
83
88
  ...where,
84
89
  [k]: where._complex[k],
85
90
  });
91
+
86
92
  filters.push(filter);
87
93
  }
88
94
 
@@ -91,6 +97,7 @@ module.exports = class extends Base {
91
97
 
92
98
  async _select(where, { desc, limit, offset, field } = {}) {
93
99
  const instance = this.where(this.tableName, where);
100
+
94
101
  if (desc) {
95
102
  instance.descending(desc);
96
103
  }
@@ -110,6 +117,7 @@ module.exports = class extends Base {
110
117
  }
111
118
  throw e;
112
119
  });
120
+
113
121
  return data.map((item) => item.toJSON());
114
122
  }
115
123
 
@@ -117,6 +125,7 @@ module.exports = class extends Base {
117
125
  let data = [];
118
126
  let ret = [];
119
127
  let offset = options.offset || 0;
128
+
120
129
  do {
121
130
  options.offset = offset + data.length;
122
131
  ret = await this._select(where, options);
@@ -137,9 +146,12 @@ module.exports = class extends Base {
137
146
 
138
147
  const cacheTableName = `cache_group_count_${key}`;
139
148
  const currentTableName = this.tableName;
149
+
140
150
  this.tableName = cacheTableName;
141
151
  const cacheData = await this.select({ _complex: where._complex });
152
+
142
153
  this.tableName = currentTableName;
154
+
143
155
  return cacheData;
144
156
  }
145
157
 
@@ -154,6 +166,7 @@ module.exports = class extends Base {
154
166
 
155
167
  const cacheTableName = `cache_group_count_${key}`;
156
168
  const currentTableName = this.tableName;
169
+
157
170
  this.tableName = cacheTableName;
158
171
 
159
172
  await think.promiseAllQueue(
@@ -161,6 +174,7 @@ module.exports = class extends Base {
161
174
  if (item.user_id && !think.isString(item.user_id)) {
162
175
  item.user_id = item.user_id.toString();
163
176
  }
177
+
164
178
  return this.add(item);
165
179
  }),
166
180
  1
@@ -190,11 +204,13 @@ module.exports = class extends Base {
190
204
  mail: data.mail,
191
205
  },
192
206
  });
207
+
193
208
  if (think.isEmpty(data)) {
194
209
  return;
195
210
  }
196
211
 
197
212
  let count = cacheData[0].count;
213
+
198
214
  switch (method) {
199
215
  case 'add':
200
216
  if (data.status === 'approved') {
@@ -214,6 +230,7 @@ module.exports = class extends Base {
214
230
  }
215
231
 
216
232
  const currentTableName = this.tableName;
233
+
217
234
  this.tableName = cacheTableName;
218
235
  await this.update({ count }, { objectId: cacheData[0].objectId }).catch(
219
236
  (e) => {
@@ -228,6 +245,7 @@ module.exports = class extends Base {
228
245
 
229
246
  async count(where = {}, options = {}) {
230
247
  const instance = this.where(this.tableName, where);
248
+
231
249
  if (!options.group) {
232
250
  return instance.count(options).catch((e) => {
233
251
  if (e.code === 101) {
@@ -243,22 +261,27 @@ module.exports = class extends Base {
243
261
  where
244
262
  );
245
263
  const cacheDataMap = {};
264
+
246
265
  for (let i = 0; i < cacheData.length; i++) {
247
266
  const key = options.group
248
267
  .map((item) => cacheData[i][item] || undefined)
249
268
  .join('_');
269
+
250
270
  cacheDataMap[key] = cacheData[i];
251
271
  }
252
272
 
253
273
  const counts = [];
254
274
  const countsPromise = [];
275
+
255
276
  for (let i = 0; i < options.group.length; i++) {
256
277
  const groupName = options.group[i];
278
+
257
279
  if (!where._complex || !Array.isArray(where._complex[groupName])) {
258
280
  continue;
259
281
  }
260
282
 
261
283
  const groupFlatValue = {};
284
+
262
285
  options.group.slice(0, i).forEach((group) => {
263
286
  groupFlatValue[group] = undefined;
264
287
  });
@@ -273,6 +296,7 @@ module.exports = class extends Base {
273
296
  }[item] || undefined)
274
297
  )
275
298
  .join('_');
299
+
276
300
  if (cacheDataMap[cacheKey]) {
277
301
  continue;
278
302
  }
@@ -293,6 +317,7 @@ module.exports = class extends Base {
293
317
  count: num,
294
318
  });
295
319
  });
320
+
296
321
  countsPromise.push(countPromise);
297
322
  }
298
323
  }
@@ -300,6 +325,7 @@ module.exports = class extends Base {
300
325
  await think.promiseAllQueue(countsPromise, 1);
301
326
  // cache data
302
327
  await this._setCmtGroupByMailUserIdCache(options.group.join('_'), counts);
328
+
303
329
  return [...cacheData, ...counts];
304
330
  }
305
331
 
@@ -309,15 +335,26 @@ module.exports = class extends Base {
309
335
  ) {
310
336
  const Table = AV.Object.extend(this.tableName);
311
337
  const instance = new Table();
312
- instance.set(data);
338
+
339
+ const REVERSED_KEYS = ['objectId', 'createdAt', 'updatedAt'];
340
+
341
+ for (const k in data) {
342
+ if (REVERSED_KEYS.includes(k)) {
343
+ continue;
344
+ }
345
+ instance.set(k, data[k]);
346
+ }
313
347
 
314
348
  const acl = new AV.ACL();
349
+
315
350
  acl.setPublicReadAccess(read);
316
351
  acl.setPublicWriteAccess(write);
317
352
  instance.setACL(acl);
318
353
 
319
354
  const resp = await instance.save();
355
+
320
356
  await this._updateCmtGroupByMailUserIdCache(data, 'add');
357
+
321
358
  return resp.toJSON();
322
359
  }
323
360
 
@@ -328,17 +365,20 @@ module.exports = class extends Base {
328
365
  return Promise.all(
329
366
  ret.map(async (item) => {
330
367
  const _oldStatus = item.get('status');
368
+
331
369
  if (think.isFunction(data)) {
332
370
  item.set(data(item.toJSON()));
333
371
  } else {
334
372
  item.set(data);
335
373
  }
336
374
  const _newStatus = item.get('status');
375
+
337
376
  if (_newStatus && _oldStatus !== _newStatus) {
338
377
  await this._updateCmtGroupByMailUserIdCache(data, 'update_status');
339
378
  }
340
379
 
341
380
  const resp = await item.save();
381
+
342
382
  return resp.toJSON();
343
383
  })
344
384
  );
@@ -347,6 +387,7 @@ module.exports = class extends Base {
347
387
  async delete(where) {
348
388
  const instance = this.where(this.tableName, where);
349
389
  const data = await instance.find();
390
+
350
391
  await this._updateCmtGroupByMailUserIdCache(data, 'delete');
351
392
 
352
393
  return AV.Object.destroyAll(data);
@@ -9,6 +9,7 @@ module.exports = class extends Base {
9
9
 
10
10
  const filter = {};
11
11
  const parseKey = (k) => (k === 'objectId' ? '_id' : k);
12
+
12
13
  for (let k in where) {
13
14
  if (k === '_complex') {
14
15
  continue;
@@ -25,6 +26,7 @@ module.exports = class extends Base {
25
26
  if (Array.isArray(where[k])) {
26
27
  if (where[k][0]) {
27
28
  const handler = where[k][0].toUpperCase();
29
+
28
30
  switch (handler) {
29
31
  case 'IN':
30
32
  if (k === 'objectId') {
@@ -45,6 +47,7 @@ module.exports = class extends Base {
45
47
  const first = where[k][1][0];
46
48
  const last = where[k][1].slice(-1);
47
49
  let reg;
50
+
48
51
  if (first === '%' && last === '%') {
49
52
  reg = new RegExp(where[k][1].slice(1, -1));
50
53
  } else if (first === '%') {
@@ -68,16 +71,19 @@ module.exports = class extends Base {
68
71
  }
69
72
  }
70
73
  }
74
+
71
75
  return filter;
72
76
  }
73
77
 
74
78
  where(instance, where) {
75
79
  const filter = this.parseWhere(where);
80
+
76
81
  if (!where._complex) {
77
82
  return instance.where(filter);
78
83
  }
79
84
 
80
85
  const filters = [];
86
+
81
87
  for (const k in where._complex) {
82
88
  if (k === '_logic') {
83
89
  continue;
@@ -96,6 +102,7 @@ module.exports = class extends Base {
96
102
 
97
103
  async select(where, { desc, limit, offset, field } = {}) {
98
104
  const instance = this.mongo(this.tableName);
105
+
99
106
  this.where(instance, where);
100
107
  if (desc) {
101
108
  instance.order(`${desc} DESC`);
@@ -108,6 +115,7 @@ module.exports = class extends Base {
108
115
  }
109
116
 
110
117
  const data = await instance.select();
118
+
111
119
  return data.map(({ _id, ...cmt }) => ({
112
120
  ...cmt,
113
121
  objectId: _id.toString(),
@@ -116,14 +124,17 @@ module.exports = class extends Base {
116
124
 
117
125
  async count(where = {}, { group } = {}) {
118
126
  const instance = this.mongo(this.tableName);
127
+
119
128
  this.where(instance, where);
120
129
  if (group) {
121
130
  instance.group(group);
122
131
  }
123
132
  const data = await instance.count({ raw: group });
133
+
124
134
  if (!Array.isArray(data)) {
125
135
  return data;
126
136
  }
137
+
127
138
  return data.map(({ _id, total: count }) => ({ ..._id, count }));
128
139
  }
129
140
 
@@ -135,11 +146,13 @@ module.exports = class extends Base {
135
146
 
136
147
  const instance = this.mongo(this.tableName);
137
148
  const id = await instance.add(data);
149
+
138
150
  return { ...data, objectId: id.toString() };
139
151
  }
140
152
 
141
153
  async update(data, where) {
142
154
  const instance = this.mongo(this.tableName);
155
+
143
156
  this.where(instance, where);
144
157
  const list = await instance.select();
145
158
 
@@ -147,8 +160,10 @@ module.exports = class extends Base {
147
160
  list.map(async (item) => {
148
161
  const updateData = typeof data === 'function' ? data(item) : data;
149
162
  const instance = this.mongo(this.tableName);
163
+
150
164
  this.where(instance, where);
151
165
  await instance.update(updateData);
166
+
152
167
  return { ...item, ...updateData };
153
168
  })
154
169
  );
@@ -156,7 +171,9 @@ module.exports = class extends Base {
156
171
 
157
172
  async delete(where) {
158
173
  const instance = this.mongo(this.tableName);
174
+
159
175
  this.where(instance, where);
176
+
160
177
  return instance.delete();
161
178
  }
162
179
  };
@@ -3,6 +3,7 @@ const Base = require('./base');
3
3
  module.exports = class extends Base {
4
4
  parseWhere(filter) {
5
5
  const where = {};
6
+
6
7
  if (think.isEmpty(filter)) {
7
8
  return where;
8
9
  }
@@ -34,11 +35,13 @@ module.exports = class extends Base {
34
35
 
35
36
  where[k] = filter[k];
36
37
  }
38
+
37
39
  return where;
38
40
  }
39
41
 
40
42
  async select(where, { desc, limit, offset, field } = {}) {
41
43
  const instance = this.model(this.tableName);
44
+
42
45
  instance.where(this.parseWhere(where));
43
46
  if (desc) {
44
47
  instance.order(`${desc} DESC`);
@@ -52,11 +55,13 @@ module.exports = class extends Base {
52
55
  }
53
56
 
54
57
  const data = await instance.select();
58
+
55
59
  return data.map(({ id, ...cmt }) => ({ ...cmt, objectId: id }));
56
60
  }
57
61
 
58
62
  async count(where = {}, { group } = {}) {
59
63
  const instance = this.model(this.tableName);
64
+
60
65
  instance.where(this.parseWhere(where));
61
66
  if (!group) {
62
67
  return instance.count();
@@ -64,6 +69,7 @@ module.exports = class extends Base {
64
69
 
65
70
  instance.field([...group, 'COUNT(*) as count']);
66
71
  instance.group(group);
72
+
67
73
  return instance.select();
68
74
  }
69
75
 
@@ -75,6 +81,7 @@ module.exports = class extends Base {
75
81
 
76
82
  const instance = this.model(this.tableName);
77
83
  const id = await instance.add(data);
84
+
78
85
  return { ...data, objectId: id };
79
86
  }
80
87
 
@@ -82,12 +89,15 @@ module.exports = class extends Base {
82
89
  const list = await this.model(this.tableName)
83
90
  .where(this.parseWhere(where))
84
91
  .select();
92
+
85
93
  return Promise.all(
86
94
  list.map(async (item) => {
87
95
  const updateData = typeof data === 'function' ? data(item) : data;
96
+
88
97
  await this.model(this.tableName)
89
98
  .where({ id: item.id })
90
99
  .update(updateData);
100
+
91
101
  return { ...item, ...updateData };
92
102
  })
93
103
  );
@@ -95,6 +105,7 @@ module.exports = class extends Base {
95
105
 
96
106
  async delete(where) {
97
107
  const instance = this.model(this.tableName);
108
+
98
109
  return instance.where(this.parseWhere(where)).delete();
99
110
  }
100
111
  };
@@ -7,6 +7,7 @@ module.exports = class extends MySQL {
7
7
 
8
8
  async select(where, options = {}) {
9
9
  const lowerWhere = {};
10
+
10
11
  for (const i in where) {
11
12
  lowerWhere[i.toLowerCase()] = where[i];
12
13
  }
@@ -19,19 +20,22 @@ module.exports = class extends MySQL {
19
20
  options.field = options.field.map((field) => field.toLowerCase());
20
21
  }
21
22
 
22
- const data = await super.select(where, options);
23
+ const data = await super.select(lowerWhere, options);
24
+
23
25
  return data.map(({ insertedat, createdat, updatedat, ...item }) => {
24
26
  const mapFields = {
25
27
  insertedAt: insertedat,
26
28
  createdAt: createdat,
27
29
  updatedAt: updatedat,
28
30
  };
31
+
29
32
  for (const field in mapFields) {
30
33
  if (!mapFields[field]) {
31
34
  continue;
32
35
  }
33
36
  item[field] = mapFields[field];
34
37
  }
38
+
35
39
  return item;
36
40
  });
37
41
  }
@@ -41,17 +45,20 @@ module.exports = class extends MySQL {
41
45
  .filter((key) => data[key])
42
46
  .forEach((key) => {
43
47
  const val = data[key];
48
+
44
49
  data[key.toLowerCase()] =
45
50
  val instanceof Date
46
51
  ? think.datetime(val, 'YYYY-MM-DD HH:mm:ss')
47
52
  : val;
48
53
  delete data[key];
49
54
  });
55
+
50
56
  return super.add(data);
51
57
  }
52
58
 
53
59
  async count(...args) {
54
60
  let result = await super.count(...args);
61
+
55
62
  try {
56
63
  if (Array.isArray(result)) {
57
64
  result.forEach((r) => {
@@ -63,6 +70,7 @@ module.exports = class extends MySQL {
63
70
  } catch (e) {
64
71
  console.log(e);
65
72
  }
73
+
66
74
  return result;
67
75
  }
68
76
  };
package/vanilla.js CHANGED
@@ -11,6 +11,7 @@ const instance = new Application({
11
11
  instance.run();
12
12
 
13
13
  let config = {};
14
+
14
15
  try {
15
16
  require('./config.js');
16
17
  } catch (e) {