evaengine 0.11.1 → 1.0.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.
Files changed (105) hide show
  1. package/.ai/analysis.md +657 -0
  2. package/.ai/architecture/runtime.md +504 -0
  3. package/.ai/contracts/public-api.md +447 -0
  4. package/.ai/external-project-guide.md +248 -0
  5. package/.ai/vision.md +314 -0
  6. package/README.md +51 -62
  7. package/bin/engine +15 -21
  8. package/index.js +2 -18
  9. package/package.json +60 -64
  10. package/src/index.js +57 -0
  11. package/bin/engine-babel +0 -38
  12. package/lib/commands/index.js +0 -25
  13. package/lib/commands/index.js.map +0 -1
  14. package/lib/commands/interface.js +0 -51
  15. package/lib/commands/interface.js.map +0 -1
  16. package/lib/commands/make_entity.js +0 -549
  17. package/lib/commands/make_entity.js.map +0 -1
  18. package/lib/commands/tramp.js +0 -53
  19. package/lib/commands/tramp.js.map +0 -1
  20. package/lib/config/index.js +0 -98
  21. package/lib/config/index.js.map +0 -1
  22. package/lib/di.js +0 -99
  23. package/lib/di.js.map +0 -1
  24. package/lib/engine.js +0 -558
  25. package/lib/engine.js.map +0 -1
  26. package/lib/entities/index.js +0 -283
  27. package/lib/entities/index.js.map +0 -1
  28. package/lib/exceptions/index.js +0 -522
  29. package/lib/exceptions/index.js.map +0 -1
  30. package/lib/index.js +0 -105
  31. package/lib/index.js.map +0 -1
  32. package/lib/middlewares/auth.js +0 -97
  33. package/lib/middlewares/auth.js.map +0 -1
  34. package/lib/middlewares/auth_kong.js +0 -48
  35. package/lib/middlewares/auth_kong.js.map +0 -1
  36. package/lib/middlewares/debug.js +0 -68
  37. package/lib/middlewares/debug.js.map +0 -1
  38. package/lib/middlewares/index.js +0 -45
  39. package/lib/middlewares/index.js.map +0 -1
  40. package/lib/middlewares/providers.js +0 -102
  41. package/lib/middlewares/providers.js.map +0 -1
  42. package/lib/middlewares/session.js +0 -76
  43. package/lib/middlewares/session.js.map +0 -1
  44. package/lib/middlewares/trace.js +0 -241
  45. package/lib/middlewares/trace.js.map +0 -1
  46. package/lib/middlewares/validator.js +0 -71
  47. package/lib/middlewares/validator.js.map +0 -1
  48. package/lib/middlewares/view_cache.js +0 -160
  49. package/lib/middlewares/view_cache.js.map +0 -1
  50. package/lib/services/cache.js +0 -234
  51. package/lib/services/cache.js.map +0 -1
  52. package/lib/services/config.js +0 -140
  53. package/lib/services/config.js.map +0 -1
  54. package/lib/services/env.js +0 -40
  55. package/lib/services/env.js.map +0 -1
  56. package/lib/services/event_manager.js +0 -110
  57. package/lib/services/event_manager.js.map +0 -1
  58. package/lib/services/http_client.js +0 -178
  59. package/lib/services/http_client.js.map +0 -1
  60. package/lib/services/index.js +0 -70
  61. package/lib/services/index.js.map +0 -1
  62. package/lib/services/interface.js +0 -12
  63. package/lib/services/interface.js.map +0 -1
  64. package/lib/services/joi.js +0 -28
  65. package/lib/services/joi.js.map +0 -1
  66. package/lib/services/jwt_token.js +0 -120
  67. package/lib/services/jwt_token.js.map +0 -1
  68. package/lib/services/jwt_token_kong.js +0 -111
  69. package/lib/services/jwt_token_kong.js.map +0 -1
  70. package/lib/services/logger.js +0 -172
  71. package/lib/services/logger.js.map +0 -1
  72. package/lib/services/namespace.js +0 -188
  73. package/lib/services/namespace.js.map +0 -1
  74. package/lib/services/now.js +0 -69
  75. package/lib/services/now.js.map +0 -1
  76. package/lib/services/providers.js +0 -195
  77. package/lib/services/providers.js.map +0 -1
  78. package/lib/services/redis.js +0 -77
  79. package/lib/services/redis.js.map +0 -1
  80. package/lib/services/rest_client.js +0 -136
  81. package/lib/services/rest_client.js.map +0 -1
  82. package/lib/swagger/index.js +0 -684
  83. package/lib/swagger/index.js.map +0 -1
  84. package/lib/utils/api_scaffold.js +0 -253
  85. package/lib/utils/api_scaffold.js.map +0 -1
  86. package/lib/utils/case_converter.js +0 -48
  87. package/lib/utils/case_converter.js.map +0 -1
  88. package/lib/utils/crc32.js +0 -22
  89. package/lib/utils/crc32.js.map +0 -1
  90. package/lib/utils/datetime.js +0 -21
  91. package/lib/utils/datetime.js.map +0 -1
  92. package/lib/utils/host.js +0 -48
  93. package/lib/utils/host.js.map +0 -1
  94. package/lib/utils/index.js +0 -61
  95. package/lib/utils/index.js.map +0 -1
  96. package/lib/utils/pagination.js +0 -269
  97. package/lib/utils/pagination.js.map +0 -1
  98. package/lib/utils/random.js +0 -33
  99. package/lib/utils/random.js.map +0 -1
  100. package/lib/utils/smart_query.js +0 -342
  101. package/lib/utils/smart_query.js.map +0 -1
  102. package/lib/utils/test.js +0 -62
  103. package/lib/utils/test.js.map +0 -1
  104. package/lib/utils/wrapper.js +0 -9
  105. package/lib/utils/wrapper.js.map +0 -1
@@ -1,269 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.paginationFilter = exports.pagination = undefined;
7
-
8
- var _snakeCase = require('lodash/snakeCase');
9
-
10
- var _snakeCase2 = _interopRequireDefault(_snakeCase);
11
-
12
- var _transform = require('lodash/transform');
13
-
14
- var _transform2 = _interopRequireDefault(_transform);
15
-
16
- var _path = require('path');
17
-
18
- var _path2 = _interopRequireDefault(_path);
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const toUrl = (scheme, host, path, query = {}) => {
23
- let queryString = Object.keys(query).map(key => `${key}=${query[key]}`).join('&');
24
- queryString = queryString === '' ? '' : `?${queryString}`;
25
- return `${scheme}://${host}${path}${queryString}`;
26
- };
27
-
28
- const toPaginationUrl = (query, req) => {
29
- const hostInfo = req.get('host').split(':');
30
- let scheme = req.protocol;
31
- let host = hostInfo[0];
32
- let port = hostInfo[1];
33
- if (!port) {
34
- port = req.protocol === 'https' ? 443 : 80;
35
- }
36
- let requestPath = req.baseUrl;
37
- if (req.get('x-forwarded-port')) {
38
- port = req.get('x-forwarded-port');
39
- }
40
- if (req.get('x-forwarded-host')) {
41
- host = req.get('x-forwarded-host');
42
- }
43
- if (req.get('x-forwarded-proto')) {
44
- scheme = req.get('x-forwarded-proto');
45
- }
46
- if (req.get('x-forwarded-prefix')) {
47
- requestPath = _path2.default.join(req.get('x-forwarded-prefix'), requestPath, req.path);
48
- }
49
- if (scheme === 'http' && String(port) !== '80' || scheme === 'https' && String(port) !== '443') {
50
- host = `${host}:${port}`;
51
- }
52
- return toUrl(scheme, host, requestPath, Object.assign(req.query, query));
53
- };
54
-
55
- const toPositiveInteger = number => {
56
- const integer = parseInt(number, 10);
57
- return integer >= 0 ? integer : 0;
58
- };
59
-
60
- const transferProperties = (obj, useSnake = false) => {
61
- if (useSnake === true) {
62
- return (0, _transform2.default)(obj, (result, value, key) => {
63
- result[(0, _snakeCase2.default)(key)] = value; //eslint-disable-line no-param-reassign
64
- });
65
- }
66
- return obj;
67
- };
68
-
69
- //@formatter:off
70
- /**
71
- @swagger
72
- PaginationSnake:
73
- type: object
74
- properties:
75
- total:
76
- type: integer
77
- description: 总数据量
78
- offset:
79
- type: integer
80
- description: 偏移量
81
- limit:
82
- type: integer
83
- description: 单页数据量
84
- prev:
85
- type: integer
86
- description: 上页偏移量
87
- next:
88
- type: integer
89
- description: 下页偏移量
90
- prev_uri:
91
- type: string
92
- description: 上页Uri
93
- next_uri:
94
- type: string
95
- description: 下页Uri
96
- is_first:
97
- type: boolean
98
- description: 是否为首页
99
- is_last:
100
- type: boolean
101
- description: 是否为末页
102
- first_uri:
103
- type: string
104
- description: 首页Uri
105
- last_uri:
106
- type: string
107
- description: 末页Uri
108
- required:
109
- - total
110
- - offset
111
- - limit
112
- - prev
113
- - next
114
- - prev_uri
115
- - next_uri
116
- - is_first
117
- - is_last
118
- - first_uri
119
- - last_uri
120
- example:
121
- total: 100
122
- offset: 30
123
- limit: 15
124
- prev: 15
125
- next: 45
126
- prev_uri: http://localhost/v1/posts?offset=15&limit=15
127
- next_uri: http://localhost/v1/posts?offset=30&limit=15
128
- is_first: false
129
- is_last: false
130
- first_uri: http://localhost/v1/posts?offset=0&limit=15
131
- last_uri: http://localhost/v1/posts?offset=90&limit=15
132
- @swagger
133
- Pagination:
134
- type: object
135
- properties:
136
- total:
137
- type: integer
138
- description: 总数据量
139
- offset:
140
- type: integer
141
- description: 偏移量
142
- limit:
143
- type: integer
144
- description: 单页数据量
145
- prev:
146
- type: integer
147
- description: 上页偏移量
148
- next:
149
- type: integer
150
- description: 下页偏移量
151
- prevUri:
152
- type: string
153
- description: 上页Uri
154
- nextUri:
155
- type: string
156
- description: 下页Uri
157
- isFirst:
158
- type: boolean
159
- description: 是否为首页
160
- isLast:
161
- type: boolean
162
- description: 是否为末页
163
- firstUri:
164
- type: string
165
- description: 首页Uri
166
- lastUri:
167
- type: string
168
- description: 末页Uri
169
- required:
170
- - total
171
- - offset
172
- - limit
173
- - prev
174
- - next
175
- - prevUri
176
- - nextUri
177
- - isFirst
178
- - isLast
179
- - firstUri
180
- - lastUri
181
- example:
182
- total: 100
183
- offset: 30
184
- limit: 15
185
- prev: 15
186
- next: 45
187
- prevUri: http://localhost/v1/posts?offset=15&limit=15
188
- nextUri: http://localhost/v1/posts?offset=30&limit=15
189
- isFirst: false
190
- isLast: false
191
- firstUri: http://localhost/v1/posts?offset=0&limit=15
192
- lastUri: http://localhost/v1/posts?offset=90&limit=15
193
- */
194
- //@formatter:on
195
- const pagination = exports.pagination = ({
196
- total,
197
- limit,
198
- offset,
199
- req,
200
- snakeCase: useSnake
201
- }) => {
202
- const totalNumber = toPositiveInteger(total);
203
- let offsetNumber = parseInt(offset, 10);
204
- offsetNumber = Number.isNaN(offsetNumber) ? 0 : offsetNumber;
205
- let limitNumber = toPositiveInteger(limit);
206
- limitNumber = limitNumber < 1 ? 1 : limitNumber;
207
- const prev = offsetNumber - limitNumber;
208
- const next = offsetNumber + limitNumber;
209
- let prevUri = '';
210
- let nextUri = '';
211
- let firstUri = '';
212
- let lastUri = '';
213
-
214
- if (total < 1) {
215
- return transferProperties({
216
- total: totalNumber,
217
- offset: offsetNumber,
218
- limit: limitNumber,
219
- isFirst: true,
220
- isLast: true,
221
- prev,
222
- next,
223
- prevUri,
224
- nextUri,
225
- firstUri,
226
- lastUri
227
- }, useSnake);
228
- }
229
-
230
- const isFirst = offset <= 0;
231
- const isLast = offset + limit >= total;
232
- const lastOffset = (total - offset) % limit;
233
- const last = lastOffset === 0 ? total - limit : total - lastOffset;
234
- prevUri = isFirst ? prevUri : toPaginationUrl({ offset: prev, limit: limitNumber }, req);
235
- nextUri = isLast ? nextUri : toPaginationUrl({ offset: next, limit: limitNumber }, req);
236
- firstUri = toPaginationUrl({ offset: 0, limit: limitNumber }, req);
237
- lastUri = toPaginationUrl({ offset: last, limit: limitNumber }, req);
238
- return transferProperties({
239
- total: totalNumber,
240
- offset: offsetNumber,
241
- limit: limitNumber,
242
- prev,
243
- next,
244
- isFirst,
245
- isLast,
246
- prevUri,
247
- nextUri,
248
- firstUri,
249
- lastUri
250
- }, useSnake);
251
- };
252
-
253
- const paginationFilter = exports.paginationFilter = ({ offset, limit }, defaultLimit = 15, maxLimit = 100) => {
254
- //Solve offset is negative
255
- let offsetNumber = Number.parseInt(offset, 10);
256
- offsetNumber = Number.isNaN(offsetNumber) ? 0 : offsetNumber;
257
- let limitNumber = toPositiveInteger(limit);
258
- limitNumber = limitNumber < 1 ? defaultLimit : limitNumber;
259
-
260
- if (offsetNumber < 0) {
261
- limitNumber += offsetNumber % limitNumber;
262
- offsetNumber = 0;
263
- }
264
-
265
- limitNumber = maxLimit > 0 && limitNumber > maxLimit ? maxLimit : limitNumber;
266
-
267
- return { offset: offsetNumber, limit: limitNumber };
268
- };
269
- //# sourceMappingURL=pagination.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/pagination.js"],"names":["toUrl","scheme","host","path","query","queryString","Object","keys","map","key","join","toPaginationUrl","req","hostInfo","get","split","protocol","port","requestPath","baseUrl","nodePath","String","assign","toPositiveInteger","number","integer","parseInt","transferProperties","obj","useSnake","result","value","pagination","total","limit","offset","snakeCase","totalNumber","offsetNumber","Number","isNaN","limit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AhB,EAAmD7B,GAAnD,CAAX;AACAmC,YAAUpC,gBAAgB,EAAEwB,QAAQgB,IAAV,EAAgBjB,OAAOO,WAAvB,EAAhB,EAAsD7B,GAAtD,CAAV;AACA,SAAOe,mBAAmB;AACxBM,WAAOI,WADiB;AAExBF,YAAQG,YAFgB;AAGxBJ,WAAOO,WAHiB;AAIxBC,QAJwB;AAKxBC,QALwB;AAMxBK,WANwB;AAOxBC,UAPwB;AAQxBL,WARwB;AASxBC,WATwB;AAUxBC,YAVwB;AAWxBC;AAXwB,GAAnB,EAYJlB,QAZI,CAAP;AAaD,CAxDM;;AA0DA,MAAMuB,8CAAmB,CAAC,EAAEjB,MAAF,EAAUD,KAAV,EAAD,EAAoBmB,eAAe,EAAnC,EAAuCC,WAAW,GAAlD,KAA0D;AACxF;AACA,MAAIhB,eAAeC,OAAOb,QAAP,CAAgBS,MAAhB,EAAwB,EAAxB,CAAnB;AACAG,iBAAeC,OAAOC,KAAP,CAAaF,YAAb,IAA6B,CAA7B,GAAiCA,YAAhD;AACA,MAAIG,cAAclB,kBAAkBW,KAAlB,CAAlB;AACAO,gBAAcA,cAAc,CAAd,GAAkBY,YAAlB,GAAiCZ,WAA/C;;AAEA,MAAIH,eAAe,CAAnB,EAAsB;AACpBG,mBAAgBH,eAAeG,WAA/B;AACAH,mBAAe,CAAf;AACD;;AAEDG,gBAAca,WAAW,CAAX,IAAgBb,cAAca,QAA9B,GAAyCA,QAAzC,GAAoDb,WAAlE;;AAEA,SAAO,EAAEN,QAAQG,YAAV,EAAwBJ,OAAOO,WAA/B,EAAP;AACD,CAfM","file":"pagination.js","sourcesContent":["import snakeCase from 'lodash/snakeCase';\nimport transform from 'lodash/transform';\nimport nodePath from 'path';\n\nconst toUrl = (scheme, host, path, query = {}) => {\n let queryString = Object.keys(query)\n .map(key => `${key}=${query[key]}`)\n .join('&');\n queryString = queryString === '' ? '' : `?${queryString}`;\n return `${scheme}://${host}${path}${queryString}`;\n};\n\nconst toPaginationUrl = (query, req) => {\n const hostInfo = req.get('host').split(':');\n let scheme = req.protocol;\n let host = hostInfo[0];\n let port = hostInfo[1];\n if (!port) {\n port = req.protocol === 'https' ? 443 : 80;\n }\n let requestPath = req.baseUrl;\n if (req.get('x-forwarded-port')) {\n port = req.get('x-forwarded-port');\n }\n if (req.get('x-forwarded-host')) {\n host = req.get('x-forwarded-host');\n }\n if (req.get('x-forwarded-proto')) {\n scheme = req.get('x-forwarded-proto');\n }\n if (req.get('x-forwarded-prefix')) {\n requestPath = nodePath.join(req.get('x-forwarded-prefix'), requestPath, req.path);\n }\n if (\n (scheme === 'http' && String(port) !== '80')\n || (scheme === 'https' && String(port) !== '443')\n ) {\n host = `${host}:${port}`;\n }\n return toUrl(\n scheme, host, requestPath,\n Object.assign(req.query, query)\n );\n};\n\n\nconst toPositiveInteger = (number) => {\n const integer = parseInt(number, 10);\n return integer >= 0 ? integer : 0;\n};\n\nconst transferProperties = (obj, useSnake = false) => {\n if (useSnake === true) {\n return transform(obj, (result, value, key) => {\n result[snakeCase(key)] = value; //eslint-disable-line no-param-reassign\n });\n }\n return obj;\n};\n\n//@formatter:off\n/**\n @swagger\n PaginationSnake:\n type: object\n properties:\n total:\n type: integer\n description: 总数据量\n offset:\n type: integer\n description: 偏移量\n limit:\n type: integer\n description: 单页数据量\n prev:\n type: integer\n description: 上页偏移量\n next:\n type: integer\n description: 下页偏移量\n prev_uri:\n type: string\n description: 上页Uri\n next_uri:\n type: string\n description: 下页Uri\n is_first:\n type: boolean\n description: 是否为首页\n is_last:\n type: boolean\n description: 是否为末页\n first_uri:\n type: string\n description: 首页Uri\n last_uri:\n type: string\n description: 末页Uri\n required:\n - total\n - offset\n - limit\n - prev\n - next\n - prev_uri\n - next_uri\n - is_first\n - is_last\n - first_uri\n - last_uri\n example:\n total: 100\n offset: 30\n limit: 15\n prev: 15\n next: 45\n prev_uri: http://localhost/v1/posts?offset=15&limit=15\n next_uri: http://localhost/v1/posts?offset=30&limit=15\n is_first: false\n is_last: false\n first_uri: http://localhost/v1/posts?offset=0&limit=15\n last_uri: http://localhost/v1/posts?offset=90&limit=15\n @swagger\n Pagination:\n type: object\n properties:\n total:\n type: integer\n description: 总数据量\n offset:\n type: integer\n description: 偏移量\n limit:\n type: integer\n description: 单页数据量\n prev:\n type: integer\n description: 上页偏移量\n next:\n type: integer\n description: 下页偏移量\n prevUri:\n type: string\n description: 上页Uri\n nextUri:\n type: string\n description: 下页Uri\n isFirst:\n type: boolean\n description: 是否为首页\n isLast:\n type: boolean\n description: 是否为末页\n firstUri:\n type: string\n description: 首页Uri\n lastUri:\n type: string\n description: 末页Uri\n required:\n - total\n - offset\n - limit\n - prev\n - next\n - prevUri\n - nextUri\n - isFirst\n - isLast\n - firstUri\n - lastUri\n example:\n total: 100\n offset: 30\n limit: 15\n prev: 15\n next: 45\n prevUri: http://localhost/v1/posts?offset=15&limit=15\n nextUri: http://localhost/v1/posts?offset=30&limit=15\n isFirst: false\n isLast: false\n firstUri: http://localhost/v1/posts?offset=0&limit=15\n lastUri: http://localhost/v1/posts?offset=90&limit=15\n */\n//@formatter:on\nexport const pagination = ({\n total,\n limit,\n offset,\n req,\n snakeCase: useSnake\n}) => {\n const totalNumber = toPositiveInteger(total);\n let offsetNumber = parseInt(offset, 10);\n offsetNumber = Number.isNaN(offsetNumber) ? 0 : offsetNumber;\n let limitNumber = toPositiveInteger(limit);\n limitNumber = limitNumber < 1 ? 1 : limitNumber;\n const prev = offsetNumber - limitNumber;\n const next = offsetNumber + limitNumber;\n let prevUri = '';\n let nextUri = '';\n let firstUri = '';\n let lastUri = '';\n\n if (total < 1) {\n return transferProperties({\n total: totalNumber,\n offset: offsetNumber,\n limit: limitNumber,\n isFirst: true,\n isLast: true,\n prev,\n next,\n prevUri,\n nextUri,\n firstUri,\n lastUri\n }, useSnake);\n }\n\n const isFirst = offset <= 0;\n const isLast = offset + limit >= total;\n const lastOffset = (total - offset) % limit;\n const last = lastOffset === 0 ? total - limit : total - lastOffset;\n prevUri = isFirst ? prevUri : toPaginationUrl({ offset: prev, limit: limitNumber }, req);\n nextUri = isLast ? nextUri : toPaginationUrl({ offset: next, limit: limitNumber }, req);\n firstUri = toPaginationUrl({ offset: 0, limit: limitNumber }, req);\n lastUri = toPaginationUrl({ offset: last, limit: limitNumber }, req);\n return transferProperties({\n total: totalNumber,\n offset: offsetNumber,\n limit: limitNumber,\n prev,\n next,\n isFirst,\n isLast,\n prevUri,\n nextUri,\n firstUri,\n lastUri\n }, useSnake);\n};\n\nexport const paginationFilter = ({ offset, limit }, defaultLimit = 15, maxLimit = 100) => {\n //Solve offset is negative\n let offsetNumber = Number.parseInt(offset, 10);\n offsetNumber = Number.isNaN(offsetNumber) ? 0 : offsetNumber;\n let limitNumber = toPositiveInteger(limit);\n limitNumber = limitNumber < 1 ? defaultLimit : limitNumber;\n\n if (offsetNumber < 0) {\n limitNumber += (offsetNumber % limitNumber);\n offsetNumber = 0;\n }\n\n limitNumber = maxLimit > 0 && limitNumber > maxLimit ? maxLimit : limitNumber;\n\n return { offset: offsetNumber, limit: limitNumber };\n};\n"]}
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.randomString = exports.randomNumber = undefined;
7
-
8
- var _random = require('lodash/random');
9
-
10
- var _random2 = _interopRequireDefault(_random);
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const randomString = (len = 16) => {
15
- const digits = '0123456789abcdefghijklmnopqrstuvwxyz';
16
- let str = '';
17
- for (let i = 0; i < len; i += 1) {
18
- const rand = (0, _random2.default)(0, digits.length - 1);
19
- str += digits[rand];
20
- }
21
- return str;
22
- };
23
-
24
- const randomNumber = (min, max) => {
25
- if (max) {
26
- return parseInt(Math.random() * (max - min + 1) + min, 10);
27
- }
28
- return parseInt(Math.random() * min + 1, 10);
29
- };
30
-
31
- exports.randomNumber = randomNumber;
32
- exports.randomString = randomString;
33
- //# sourceMappingURL=random.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/random.js"],"names":["randomString","len","digits","str","i","rand","length","randomNumber","min","max","parseInt","Math","random"],"mappings":";;;;;;;AAAA;;;;;;AAEA,MAAMA,eAAe,CAACC,MAAM,EAAP,KAAc;AACjC,QAAMC,SAAS,sCAAf;AACA,MAAIC,MAAM,EAAV;AACA,OAAK,IAAIC,IAAI,CAAb,EAAgBA,IAAIH,GAApB,EAAyBG,KAAK,CAA9B,EAAiC;AAC/B,UAAMC,OAAO,sBAAO,CAAP,EAAUH,OAAOI,MAAP,GAAgB,CAA1B,CAAb;AACAH,WAAOD,OAAOG,IAAP,CAAP;AACD;AACD,SAAOF,GAAP;AACD,CARD;;AAUA,MAAMI,eAAe,CAACC,GAAD,EAAMC,GAAN,KAAc;AACjC,MAAIA,GAAJ,EAAS;AACP,WAAOC,SAAUC,KAAKC,MAAL,MAAkBH,MAAMD,GAAP,GAAc,CAA/B,CAAD,GAAsCA,GAA/C,EAAoD,EAApD,CAAP;AACD;AACD,SAAOE,SAAUC,KAAKC,MAAL,KAAgBJ,GAAjB,GAAwB,CAAjC,EAAoC,EAApC,CAAP;AACD,CALD;;QAQED,Y,GAAAA,Y;QACAP,Y,GAAAA,Y","file":"random.js","sourcesContent":["import random from 'lodash/random';\n\nconst randomString = (len = 16) => {\n const digits = '0123456789abcdefghijklmnopqrstuvwxyz';\n let str = '';\n for (let i = 0; i < len; i += 1) {\n const rand = random(0, digits.length - 1);\n str += digits[rand];\n }\n return str;\n};\n\nconst randomNumber = (min, max) => {\n if (max) {\n return parseInt((Math.random() * ((max - min) + 1)) + min, 10);\n }\n return parseInt((Math.random() * min) + 1, 10);\n};\n\nexport {\n randomNumber,\n randomString\n};\n"]}
@@ -1,342 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = undefined;
7
-
8
- var _momentTimezone = require('moment-timezone');
9
-
10
- var _momentTimezone2 = _interopRequireDefault(_momentTimezone);
11
-
12
- var _exceptions = require('../exceptions');
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- /**
17
- * 自动根据 req.query 生成 sequelize 查询条件, 自动判断参数清单中是否有值
18
- */
19
- let SmartQuery = class SmartQuery {
20
- constructor(query) {
21
- this.query = query;
22
- /**
23
- * WHERE 查询条件
24
- * @type {{}}
25
- */
26
- this.where = {};
27
- /**'
28
- * 排序列表
29
- * @type {Array}
30
- */
31
- this.order = [];
32
- }
33
-
34
- /**
35
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加全等查询条件
36
- * @param {String} paramName query 中的参数名称
37
- * @param {String} fieldName 对应的数据库字段名称,默认与 paramName 一致
38
- * @param {String} defaultValue 当 query 中不包含 paramName 或为空时,使用该值
39
- */
40
- equal(paramName, fieldName = paramName, defaultValue = null) {
41
- const value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
42
- if (value != null) {
43
- this.applyWhere(fieldName, '$eq', value);
44
- }
45
-
46
- return this;
47
- }
48
-
49
- /**
50
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 in 查询条件, 值可以为 `delimiter` 分割的字符串或者数组
51
- * @param {String} paramName query 中的参数名称
52
- * @param {String} [fieldName=paramName] 对应的数据库字段名称,默认与 paramName 一致
53
- * @param {String|Array} [defaultValue=null] 当 query 中不包含 paramName 或为空时,使用该值
54
- * @param {String} [delimiter=,] 当值为字符串时的分隔符,默认为 ,
55
- */
56
- in(paramName, fieldName = paramName, defaultValue = null, delimiter = ',') {
57
- return this.applyIn(paramName, fieldName, defaultValue, delimiter, false);
58
- }
59
-
60
- /**
61
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 not in 查询条件, 值可以为 `delimiter` 分割的字符串或者数组
62
- * @param {String} paramName query 中的参数名称
63
- * @param {String} [fieldName=paramName] 对应的数据库字段名称,默认与 paramName 一致
64
- * @param {String|Array} [defaultValue=null] 当 query 中不包含 paramName 或为空时,使用该值
65
- * @param {String} [delimiter=,] 当值为字符串时的分隔符,默认为 ,
66
- */
67
- notIn(paramName, fieldName = paramName, defaultValue = null, delimiter = ',') {
68
- return this.applyIn(paramName, fieldName, defaultValue, delimiter, true);
69
- }
70
-
71
- /**
72
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 LIKE 查询条件,并自动在值的头尾添加 %
73
- * @param {String} paramName query 中的参数名称
74
- * @param {String} fieldName 对应的数据库字段名称,默认与 paramName 一致
75
- * @param {String} defaultValue 当 query 中不包含 paramName 或为空时,使用该值
76
- */
77
- like(paramName, fieldName = paramName, defaultValue = null) {
78
- const value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
79
- if (value != null) {
80
- this.applyWhere(fieldName, '$like', `%${value}%`);
81
- }
82
-
83
- return this;
84
- }
85
-
86
- /**
87
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 LIKE 查询条件,并自动在值的尾部添加 %
88
- * @param {String} paramName query 中的参数名称
89
- * @param {String} fieldName 对应的数据库字段名称,默认与 paramName 一致
90
- * @param {String} defaultValue 当 query 中不包含 paramName 或为空时,使用该值
91
- */
92
- startsWith(paramName, fieldName = paramName, defaultValue = null) {
93
- const value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
94
- if (value != null) {
95
- this.applyWhere(fieldName, '$like', `${value}%`);
96
- }
97
-
98
- return this;
99
- }
100
-
101
- /**
102
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 LIKE 查询条件,并自动在值的头部添加 %
103
- * @param {String} paramName query 中的参数名称
104
- * @param {String} fieldName 对应的数据库字段名称,默认与 paramName 一致
105
- * @param {String} defaultValue 当 query 中不包含 paramName 或为空时,使用该值
106
- */
107
- endsWith(paramName, fieldName = paramName, defaultValue = null) {
108
- const value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
109
- if (value != null) {
110
- this.applyWhere(fieldName, '$like', `%${value}`);
111
- }
112
-
113
- return this;
114
- }
115
-
116
- /**
117
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 >= 查询条件
118
- * @param {String} paramName query 中的参数名称
119
- * @param {String} fieldName 对应的数据库字段名称,默认与 paramName 一致
120
- * @param {String} defaultValue 当 query 中不包含 paramName 或为空时,使用该值
121
- */
122
- gte(paramName, fieldName = paramName, defaultValue = null) {
123
- const value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
124
- if (value != null) {
125
- this.applyWhere(fieldName, '$gte', value);
126
- }
127
-
128
- return this;
129
- }
130
-
131
- /**
132
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 <= 查询条件
133
- * @param {String} paramName query 中的参数名称
134
- * @param {String} fieldName 对应的数据库字段名称,默认与 paramName 一致
135
- * @param {String} defaultValue 当 query 中不包含 paramName 或为空时,使用该值
136
- */
137
- lte(paramName, fieldName = paramName, defaultValue = null) {
138
- const value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
139
- if (value != null) {
140
- this.applyWhere(fieldName, '$lte', value);
141
- }
142
-
143
- return this;
144
- }
145
-
146
- /**
147
- * 当 query 中包含名为 minParamName 的属性时,为 fieldName 添加 >= 查询条件,
148
- * 当 query 中包含名为 maxParamName 的属性时,为 fieldName 添加 <= 查询条件
149
- * @param {String} minParamName query 中的最小值参数名称
150
- * @param {String} maxParamName query 中的最大值参数名称
151
- * @param {String} fieldName 对应的数据库字段名称
152
- * @param {String} minDefault 当 query 中不包含 minParamName 或为空时,使用该值作为默认值
153
- * @param {String} maxDefault 当 query 中不包含 maxParamName 或为空时,使用该值作为默认值
154
- */
155
- range(minParamName, maxParamName, fieldName, minDefault = null, maxDefault = null) {
156
- const min = this.determineParam(minParamName) ? this.query[minParamName] : minDefault;
157
- const max = this.determineParam(maxParamName) ? this.query[maxParamName] : maxDefault;
158
- if (min != null) {
159
- this.applyWhere(fieldName, '$gte', min);
160
- }
161
- if (max != null) {
162
- this.applyWhere(fieldName, '$lte', max);
163
- }
164
- return this;
165
- }
166
-
167
- /**
168
- * 当 query 中包含名为 minParamName 的属性时,为 fieldName 添加 >= 查询条件并将时分秒设为0格式化到 targetFormat ,
169
- * 当 query 中包含名为 maxParamName 的属性时,为 fieldName 添加 <= 查询条件并将时分秒分别设为 23:59:59 后格式化到 targetFormat
170
- * @param {String} minParamName query 中的最小值参数名称
171
- * @param {String} maxParamName query 中的最大值参数名称
172
- * @param {String} fieldName 对应的数据库字段名称
173
- * @param {String} [minDefault=null] 当 query 中不包含 minParamName 或为空时,使用该值作为默认值
174
- * @param {String} [maxDefault=null] 当 query 中不包含 maxParamName 或为空时,使用该值作为默认值
175
- * @param {String} [sourceFormat='YYYY-MM-DD'] 原值时间格式
176
- * @param {String } [targetFormat='X'] 数据库时间格式
177
- */
178
- dateRange(minParamName, maxParamName, fieldName, minDefault = null, maxDefault = null, sourceFormat = 'YYYY-MM-DD', targetFormat = 'X') {
179
- let min = this.determineParam(minParamName) ? this.query[minParamName] : null;
180
- min = min != null && (0, _momentTimezone2.default)(min, sourceFormat).isValid() ? (0, _momentTimezone2.default)(min, sourceFormat) : (0, _momentTimezone2.default)(minDefault, sourceFormat);
181
- let max = this.determineParam(maxParamName) ? this.query[maxParamName] : null;
182
- max = max != null && (0, _momentTimezone2.default)(max, sourceFormat).isValid() ? (0, _momentTimezone2.default)(max, sourceFormat) : (0, _momentTimezone2.default)(maxDefault, sourceFormat);
183
-
184
- if (min.isValid()) {
185
- min = min.hours(0).minutes(0).seconds(0).format(targetFormat);
186
- this.applyWhere(fieldName, '$gte', min);
187
- }
188
- if (max.isValid()) {
189
- max = max.hours(23).minutes(59).seconds(59).format(targetFormat);
190
- this.applyWhere(fieldName, '$lte', max);
191
- }
192
-
193
- return this;
194
- }
195
-
196
- /**
197
- * 当 query 中包含名为 minParamName 的属性时,为 fieldName 添加 >= 查询条件并格式化到 targetFormat ,
198
- * 当 query 中包含名为 maxParamName 的属性时,为 fieldName 添加 <= 查询条件并并格式化到 targetFormat
199
- * @param {String} minParamName query 中的最小值参数名称
200
- * @param {String} maxParamName query 中的最大值参数名称
201
- * @param {String} fieldName 对应的数据库字段名称
202
- * @param {String} [minDefault=null] 当 query 中不包含 minParamName 或为空时,使用该值作为默认值
203
- * @param {String} [maxDefault=null] 当 query 中不包含 maxParamName 或为空时,使用该值作为默认值
204
- * @param {String} [sourceFormat='YYYY-MM-DD'] 原值时间格式
205
- * @param {String } [targetFormat='X'] 数据库时间格式
206
- */
207
- dateTimeRange(minParamName, maxParamName, fieldName, minDefault = null, maxDefault = null, sourceFormat = 'YYYY-MM-DD HH:mm:ss', targetFormat = 'X') {
208
- let min = this.determineParam(minParamName) ? this.query[minParamName] : null;
209
- min = min != null && (0, _momentTimezone2.default)(min, sourceFormat).isValid() ? (0, _momentTimezone2.default)(min, sourceFormat) : (0, _momentTimezone2.default)(minDefault, sourceFormat);
210
- let max = this.determineParam(maxParamName) ? this.query[maxParamName] : null;
211
- max = max != null && (0, _momentTimezone2.default)(max, sourceFormat).isValid() ? (0, _momentTimezone2.default)(max, sourceFormat) : (0, _momentTimezone2.default)(maxDefault, sourceFormat);
212
-
213
- if (min.isValid()) {
214
- min = min.format(targetFormat);
215
- this.applyWhere(fieldName, '$gte', min);
216
- }
217
- if (max.isValid()) {
218
- max = max.format(targetFormat);
219
- this.applyWhere(fieldName, '$lte', max);
220
- }
221
-
222
- return this;
223
- }
224
-
225
- /**
226
- * 处理用户的排序请求
227
- * @param {Array} [autoMapping=[]] 根据字段名自动排序,数组成员为字段名,每个字段名自动生成正反序,
228
- * 如 `created_at` 生成 `created_at` 正序和 `-created_at` 倒序
229
- * @param {Object} [manualMapping={}]
230
- * @param [defaultOrder=null] 默认排序,当 query 中不包含 `paramName` 属性时使用。如不设置则为 `autoMapping` 的第一个字段的倒序
231
- * @param {String} [paramName='sort'] 参数名称
232
- */
233
- orderable(autoMapping = [], manualMapping = {}, defaultOrder = null, paramName = 'order') {
234
- const ordersMapping = {};
235
- let conventionOrder = defaultOrder;
236
- if (autoMapping instanceof Array) {
237
- autoMapping.forEach(field => {
238
- ordersMapping[`-${field}`] = [field, 'DESC'];
239
- ordersMapping[field] = [field, 'ASC'];
240
- });
241
- if (conventionOrder === null) {
242
- conventionOrder = [autoMapping[0], 'DESC'];
243
- }
244
- }
245
-
246
- Object.assign(ordersMapping, manualMapping);
247
-
248
- const order = this.determineParam(paramName) && Object.keys(ordersMapping).includes(this.query[paramName]) ? ordersMapping[this.query[paramName]] : conventionOrder;
249
- if (order != null) {
250
- this.order = [order];
251
- }
252
-
253
- return this;
254
- }
255
-
256
- /**
257
- * 获取完整的有效查询参数
258
- * @returns {{}}
259
- */
260
- getCriteria() {
261
- const criteria = {};
262
- if (this.order instanceof Array && this.order.length > 0) {
263
- criteria.order = this.order;
264
- }
265
-
266
- if (this.where instanceof Object && this.where.length > 0) {
267
- criteria.where = this.where;
268
- }
269
-
270
- return criteria;
271
- }
272
-
273
- /**
274
- * 当 query 中包含名为 paramName 的属性时,为 fieldName 添加 in 或 not in 查询条件, 值可以为 `delimiter` 分割的字符串或者数组
275
- * @protected
276
- * @param {String} paramName query 中的参数名称
277
- * @param {String} fieldName 对应的数据库字段名称
278
- * @param {String|Array} [defaultValue=null] 当 query 中不包含 paramName 或为空时,使用该值
279
- * @param {String} [delimiter=,] 当值为字符串时的分隔符,默认为 ,
280
- * @param {Boolean} [negation=false] 是否取反,为 true 时使用 $notIn
281
- */
282
- applyIn(paramName, fieldName, defaultValue = null, delimiter = ',', negation = false) {
283
- let value = this.determineParam(paramName) ? this.query[paramName] : defaultValue;
284
- if (value === null) {
285
- return this;
286
- }
287
- if (typeof value === 'number') {
288
- value = String(value);
289
- }
290
- if (typeof value === 'string') {
291
- value = value.split(delimiter);
292
- } else if (value instanceof Array === false) {
293
- throw new _exceptions.InvalidArgumentException(`Value for contains must be typeof string or array, but \`${typeof value}\` given`);
294
- }
295
-
296
- this.applyWhere(fieldName, negation ? '$notIn' : '$in', value);
297
- return this;
298
- }
299
-
300
- /**
301
- * 添加 where
302
- *
303
- * @protected
304
- * @param filedName
305
- * @param predicate
306
- * @param value
307
- */
308
- applyWhere(filedName, predicate, value) {
309
- if (!Object.keys(this.where).includes(filedName)) {
310
- this.where[filedName] = {};
311
- }
312
- this.where[filedName][predicate] = value;
313
- }
314
-
315
- /**
316
- * 判定指定名称的参数是否有效
317
- *
318
- * @param paramName
319
- * @returns {boolean}
320
- */
321
- determineParam(paramName) {
322
- if (!Object.keys(this.query).includes(paramName)) {
323
- return false;
324
- }
325
- const value = this.query[paramName];
326
- if (value === null) {
327
- return false;
328
- }
329
- if (typeof value === 'string') {
330
- return value.trim() !== '';
331
- }
332
- if (value instanceof Array) {
333
- return value.length > 0;
334
- }
335
- if (value instanceof Object) {
336
- return Object.keys(value).length > 0;
337
- }
338
- return true;
339
- }
340
- };
341
- exports.default = SmartQuery;
342
- //# sourceMappingURL=smart_query.js.map