@steedos/objectql 2.2.51-beta.1 → 2.2.51-beta.2

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 (134) hide show
  1. package/package.json +10 -10
  2. package/src/actions/field_updates.ts +0 -118
  3. package/src/actions/index.ts +0 -3
  4. package/src/actions/types/field_update_target.ts +0 -7
  5. package/src/actions/types/workflow_notification.ts +0 -9
  6. package/src/actions/types/workflow_rule.ts +0 -11
  7. package/src/actions/workflow_notifications.ts +0 -81
  8. package/src/actions/workflow_rule.ts +0 -136
  9. package/src/driver/driver.ts +0 -102
  10. package/src/driver/field-encrytion/index.ts +0 -8
  11. package/src/driver/field-encrytion/sharedconst.ts +0 -34
  12. package/src/driver/fieldDBType.ts +0 -14
  13. package/src/driver/format.ts +0 -36
  14. package/src/driver/index.ts +0 -20
  15. package/src/driver/metadata.ts +0 -226
  16. package/src/driver/meteorMongo.ts +0 -639
  17. package/src/driver/mongo.ts +0 -416
  18. package/src/driver/mysql.ts +0 -47
  19. package/src/driver/oracle.ts +0 -60
  20. package/src/driver/postgres.ts +0 -46
  21. package/src/driver/sqlite3.ts +0 -40
  22. package/src/driver/sqlserver.ts +0 -52
  23. package/src/dynamic-load/actions.ts +0 -146
  24. package/src/dynamic-load/approval_process.ts +0 -73
  25. package/src/dynamic-load/button.ts +0 -75
  26. package/src/dynamic-load/chart.ts +0 -22
  27. package/src/dynamic-load/client_script.ts +0 -65
  28. package/src/dynamic-load/field.ts +0 -77
  29. package/src/dynamic-load/flow_role.ts +0 -46
  30. package/src/dynamic-load/index.ts +0 -21
  31. package/src/dynamic-load/layout.ts +0 -53
  32. package/src/dynamic-load/listview.ts +0 -57
  33. package/src/dynamic-load/method.ts +0 -63
  34. package/src/dynamic-load/object_translations.ts +0 -61
  35. package/src/dynamic-load/originalObject.ts +0 -8
  36. package/src/dynamic-load/package.ts +0 -312
  37. package/src/dynamic-load/page.ts +0 -23
  38. package/src/dynamic-load/permission.ts +0 -71
  39. package/src/dynamic-load/permissionset.ts +0 -78
  40. package/src/dynamic-load/preload_data.ts +0 -104
  41. package/src/dynamic-load/profile.ts +0 -90
  42. package/src/dynamic-load/query.ts +0 -22
  43. package/src/dynamic-load/restrictionRules.ts +0 -23
  44. package/src/dynamic-load/role.ts +0 -46
  45. package/src/dynamic-load/shareRules.ts +0 -23
  46. package/src/dynamic-load/tab.ts +0 -17
  47. package/src/dynamic-load/tabs.ts +0 -13
  48. package/src/dynamic-load/translations.ts +0 -54
  49. package/src/dynamic-load/trigger.ts +0 -236
  50. package/src/dynamic-load/validation_rule.ts +0 -77
  51. package/src/dynamic-load/workflow.ts +0 -114
  52. package/src/errors/index.ts +0 -111
  53. package/src/formula/core.ts +0 -490
  54. package/src/formula/field_formula.ts +0 -107
  55. package/src/formula/index.ts +0 -81
  56. package/src/formula/params.ts +0 -197
  57. package/src/formula/recompute.ts +0 -65
  58. package/src/formula/simple_params.ts +0 -92
  59. package/src/formula/type.ts +0 -107
  60. package/src/formula/util.ts +0 -207
  61. package/src/index.ts +0 -24
  62. package/src/metadata-register/_base.ts +0 -85
  63. package/src/metadata-register/app.ts +0 -30
  64. package/src/metadata-register/chart.ts +0 -9
  65. package/src/metadata-register/index.ts +0 -123
  66. package/src/metadata-register/layout.ts +0 -38
  67. package/src/metadata-register/object.ts +0 -68
  68. package/src/metadata-register/page.ts +0 -9
  69. package/src/metadata-register/permissionFields.ts +0 -13
  70. package/src/metadata-register/permissionset.ts +0 -25
  71. package/src/metadata-register/process.ts +0 -16
  72. package/src/metadata-register/processTrigger.ts +0 -24
  73. package/src/metadata-register/profile.ts +0 -25
  74. package/src/metadata-register/query.ts +0 -9
  75. package/src/metadata-register/restrictionRules.ts +0 -12
  76. package/src/metadata-register/shareRules.ts +0 -13
  77. package/src/metadata-register/tab.ts +0 -9
  78. package/src/metadata-register/tabs.ts +0 -43
  79. package/src/services/datasourceServiceFactory.ts +0 -55
  80. package/src/services/helpers/graphql/consts.ts +0 -25
  81. package/src/services/helpers/graphql/getPrimaryFieldType.ts +0 -48
  82. package/src/services/helpers/graphql/getQueryFields.ts +0 -51
  83. package/src/services/helpers/graphql/index.ts +0 -666
  84. package/src/services/helpers/rest.ts +0 -57
  85. package/src/services/index.ts +0 -13
  86. package/src/services/objectService.ts +0 -846
  87. package/src/services/objectServiceDispatcher.ts +0 -209
  88. package/src/services/objectServiceFactory.ts +0 -29
  89. package/src/summary/core.ts +0 -263
  90. package/src/summary/field_summary.ts +0 -71
  91. package/src/summary/index.ts +0 -96
  92. package/src/summary/recompute.ts +0 -31
  93. package/src/summary/type.ts +0 -60
  94. package/src/ts-types/index.ts +0 -3
  95. package/src/ts-types/permissionset.ts +0 -8
  96. package/src/ts-types/profile.ts +0 -11
  97. package/src/ts-types/triggerActionParams.ts +0 -22
  98. package/src/typeorm/driver.ts +0 -379
  99. package/src/typeorm/index.ts +0 -3
  100. package/src/typeorm/util.ts +0 -147
  101. package/src/types/action.ts +0 -52
  102. package/src/types/app.ts +0 -280
  103. package/src/types/config.ts +0 -152
  104. package/src/types/connection.ts +0 -87
  105. package/src/types/dashboard.ts +0 -91
  106. package/src/types/datasource.ts +0 -570
  107. package/src/types/field.ts +0 -370
  108. package/src/types/field_permission.ts +0 -42
  109. package/src/types/field_types.ts +0 -1
  110. package/src/types/index.ts +0 -21
  111. package/src/types/list_view.ts +0 -56
  112. package/src/types/listeners.ts +0 -18
  113. package/src/types/object.ts +0 -2076
  114. package/src/types/object_dynamic_load.ts +0 -426
  115. package/src/types/object_events.ts +0 -43
  116. package/src/types/object_layouts.ts +0 -20
  117. package/src/types/object_permission.ts +0 -134
  118. package/src/types/query.ts +0 -28
  119. package/src/types/report.ts +0 -128
  120. package/src/types/restrictionRule.ts +0 -57
  121. package/src/types/schema.ts +0 -273
  122. package/src/types/shareRule.ts +0 -57
  123. package/src/types/trigger.ts +0 -88
  124. package/src/types/userSession.ts +0 -45
  125. package/src/types/validation_rules.ts +0 -29
  126. package/src/util/convert.ts +0 -131
  127. package/src/util/field.ts +0 -93
  128. package/src/util/function_expression.ts +0 -63
  129. package/src/util/index.ts +0 -1066
  130. package/src/util/locale.ts +0 -24
  131. package/src/util/permission_shares.ts +0 -25
  132. package/src/util/suffix.ts +0 -78
  133. package/src/util/transform.ts +0 -239
  134. package/src/validators/index.ts +0 -36
package/src/util/index.ts DELETED
@@ -1,1066 +0,0 @@
1
- /*
2
- * Copyright (c) 2018, salesforce.com, inc.
3
- * All rights reserved.
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
- */
7
-
8
- import { isJsonMap, JsonMap } from '@salesforce/ts-types';
9
- import { Validators, loadCoreValidators } from '../validators';
10
- const odataMongodb = require("odata-v4-mongodb");
11
- const Future = require('fibers/future');
12
- const crypto = require('crypto')
13
- const yaml = require('js-yaml');
14
- const fs = require("fs");
15
- const path = require("path");
16
- const _ = require("underscore");
17
- const globby = require("globby");
18
- var clone = require("clone")
19
- import { has, getJsonMap } from '@salesforce/ts-types';
20
- let STEEDOS_CONFIG:any = {};
21
- const configName = 'steedos-config.yml'
22
- const licenseName = '.license'
23
- import { getObjectConfig } from '../types'
24
- import { defaultsDeep } from 'lodash';
25
- export const StandardObjectsPath = path.dirname(require.resolve("@steedos/standard-objects/package.json"));
26
- export * from './transform'
27
- export * from './permission_shares'
28
- export * from './suffix'
29
- export * from './locale'
30
- export * from './field'
31
- export * from './function_expression'
32
- export * from './convert'
33
-
34
- const validator = require('validator');
35
-
36
- exports.loadJSONFile = (filePath: string)=>{
37
- return JSON.parse(fs.readFileSync(filePath, 'utf8').normalize('NFC'));
38
- }
39
-
40
- exports.loadYmlFile = (filePath: string)=>{
41
- return yaml.load(fs.readFileSync(filePath, 'utf8'));
42
- }
43
-
44
- let loadFile = (filePath: string)=>{
45
- let json:JsonMap = {}
46
- try {
47
- let extname = path.extname(filePath);
48
- if(extname.toLocaleLowerCase() == '.json')
49
- json = JSON.parse(fs.readFileSync(filePath, 'utf8').normalize('NFC'));
50
- else if(extname.toLocaleLowerCase() == '.yml')
51
- json = yaml.load(fs.readFileSync(filePath, 'utf8'));
52
- else if(extname.toLocaleLowerCase() == '.js')
53
- json = clone(require(filePath));
54
- } catch (error) {
55
- console.error('loadFile error', filePath, error);
56
- }
57
- return json;
58
- };
59
- exports.loadFile = loadFile;
60
-
61
- function validateObject(json){
62
- // 校验
63
- let validate = Validators['steedos-schema_object'];
64
- let objectName = json.name;
65
- if (!validate(JSON.parse(JSON.stringify(json)))) {
66
- throw new Error(`对象${objectName}校验不通过: ${JSON.stringify(validate.errors)}`);
67
- }
68
-
69
- return true;
70
- }
71
-
72
- export const loadObjects = (filePath: string) => {
73
- let results = [];
74
- const filePatten = [
75
- path.join(filePath, "*.object.yml"),
76
- path.join(filePath, "*.object.json"),
77
- "!" + path.join(filePath, "node_modules"),
78
- ];
79
- const matchedPaths: [string] = globby.sync(filePatten);
80
- _.each(matchedPaths, (matchedPath: string) => {
81
- let json = loadFile(matchedPath);
82
- try {
83
- if (json) {
84
- json.__filename = matchedPath;
85
- }
86
- } catch (error) {
87
- console.error("loadObjects error", matchedPath, error);
88
- }
89
- if (validateObject(json)) {
90
- results.push(json);
91
- }
92
- });
93
- return results;
94
- };
95
-
96
- function getI18nLng(filePath) {
97
- try {
98
- let pathJson = path.parse(filePath);
99
- let filename = pathJson.base;
100
- if (filename) {
101
- let f = filename.split(".");
102
- if (f.length >= 3) {
103
- return f[f.length - 3];
104
- }
105
- }
106
- console.log(`getI18nLng warn: Invalid file: ${filePath}`);
107
- } catch (error) {
108
- console.error(`getI18nLng error: ${filePath}`, error);
109
- }
110
- }
111
-
112
- function getObjectApiName(filePath) {
113
- try {
114
- let pathJson = path.parse(filePath);
115
- let filename = pathJson.base;
116
- if (filename) {
117
- let f = filename.split(".");
118
- if (f.length >= 3) {
119
- return f[0];
120
- }
121
- }
122
- console.log(`getObjectApiName warn: Invalid file: ${filePath}`);
123
- } catch (error) {
124
- console.error(`getObjectApiName error: ${filePath}`, error);
125
- }
126
- }
127
-
128
- export const loadI18n = (filePath: string) => {
129
- let results = [];
130
- const filePatten = [
131
- path.join(filePath, "*.i18n.yml"),
132
- path.join(filePath, "*.i18n.json"),
133
- "!" + path.join(filePath, "node_modules"),
134
- ];
135
- const matchedPaths: [string] = globby.sync(filePatten);
136
- _.each(matchedPaths, (matchedPath: string) => {
137
- let json = loadFile(matchedPath);
138
- let lng = getI18nLng(matchedPath);
139
- if (lng) {
140
- results.push({ lng: lng, __filename: matchedPath, data: json });
141
- }
142
- });
143
- return results;
144
- };
145
-
146
- export const loadObjectTranslations = (filePath: string) => {
147
- let results = [];
148
- const filePatten = [
149
- path.join(filePath, "*.objectTranslation.yml"),
150
- "!" + path.join(filePath, "node_modules"),
151
- ];
152
- const matchedPaths: [string] = globby.sync(filePatten);
153
- _.each(matchedPaths, (matchedPath: string) => {
154
- let json = loadFile(matchedPath);
155
- let lng = getI18nLng(matchedPath);
156
- let objectApiName = getObjectApiName(matchedPath);
157
- if (lng) {
158
- results.push({
159
- lng: lng,
160
- objectApiName,
161
- __filename: matchedPath,
162
- data: json,
163
- });
164
- }
165
- });
166
- return results;
167
- };
168
-
169
- export const loadTranslations = (filePath: string) => {
170
- let results = [];
171
- const filePatten = [
172
- path.join(filePath, "*.translation.yml"),
173
- "!" + path.join(filePath, "node_modules"),
174
- ];
175
- const matchedPaths: [string] = globby.sync(filePatten);
176
- _.each(matchedPaths, (matchedPath: string) => {
177
- let json = loadFile(matchedPath);
178
- let lng = getI18nLng(matchedPath);
179
- if (lng) {
180
- results.push({ lng: lng, __filename: matchedPath, data: json });
181
- }
182
- });
183
- return results;
184
- };
185
-
186
- const getRouterInfoList = (router, md5) => {
187
- const infoList = [];
188
- if (
189
- router &&
190
- router.default &&
191
- router.default.stack &&
192
- router.default.stack.length > 0
193
- ) {
194
- _.each(router.default.stack, (_route) => {
195
- const info = {
196
- path: "",
197
- methods: "",
198
- md5: md5,
199
- };
200
- if (_route.route) {
201
- info.path = _route.route.path;
202
- info.methods = _route.route.methods;
203
- infoList.push(info);
204
- }
205
- });
206
- }
207
- return infoList;
208
- };
209
-
210
- const getFileMD5 = (filePath) => {
211
- const buffer = fs.readFileSync(filePath);
212
- return getMD5(buffer);
213
- };
214
-
215
- export const loadRouters = (filePath: string) => {
216
- let results = [];
217
- const filePatten = [
218
- path.join(filePath, "*.router.js"),
219
- "!" + path.join(filePath, "node_modules"),
220
- ];
221
- const matchedPaths: [string] = globby.sync(filePatten);
222
- _.each(matchedPaths, (matchedPath: string) => {
223
- delete require.cache[require.resolve(matchedPath)];
224
- let router = loadFile(matchedPath);
225
- let md5 = getFileMD5(matchedPath);
226
- let infoList = getRouterInfoList(router, md5);
227
- results.push({ router: router, infoList: infoList });
228
- });
229
- return results;
230
- };
231
-
232
- export const loadTriggers = (filePath: string) => {
233
- let results = [];
234
- const filePatten = [
235
- path.join(filePath, "*.trigger.js"),
236
- "!" + path.join(filePath, "node_modules"),
237
- ];
238
- const matchedPaths: [string] = globby.sync(filePatten);
239
- _.each(matchedPaths, (matchedPath: string) => {
240
- delete require.cache[require.resolve(matchedPath)];
241
- let json = loadFile(matchedPath);
242
- if (!_.has(json, "listenTo")) {
243
- json.listenTo = path.basename(matchedPath).split(".")[0];
244
- }
245
- results.push(json);
246
- });
247
- return results;
248
- };
249
-
250
- export const loadProcessTriggers = (filePath: string) => {
251
- let results = [];
252
- const filePatten = [
253
- path.join(filePath, "*.processTrigger.js"),
254
- "!" + path.join(filePath, "node_modules"),
255
- ];
256
- const matchedPaths: [string] = globby.sync(filePatten);
257
- _.each(matchedPaths, (matchedPath: string) => {
258
- delete require.cache[require.resolve(matchedPath)];
259
- let json = loadFile(matchedPath);
260
- if (!_.has(json, "listenTo")) {
261
- json.listenTo = path.basename(matchedPath).split(".")[0];
262
- }
263
- results.push(json);
264
- });
265
- return results;
266
- };
267
-
268
- export const loadActions = (filePath: string) => {
269
- let results = [];
270
- const filePatten = [
271
- path.join(filePath, "*.action.js"),
272
- "!" + path.join(filePath, "node_modules"),
273
- ];
274
- const matchedPaths: [string] = globby.sync(filePatten);
275
- _.each(matchedPaths, (matchedPath: string) => {
276
- delete require.cache[require.resolve(matchedPath)];
277
- let json = loadFile(matchedPath);
278
- if (!_.has(json, "listenTo")) {
279
- json.listenTo = path.basename(matchedPath).split(".")[0];
280
- }
281
- results.push(json);
282
- });
283
- return results;
284
- };
285
-
286
- export const loadMethods = (filePath: string) => {
287
- let results = [];
288
- const filePatten = [
289
- path.join(filePath, "*.function.js"),
290
- "!" + path.join(filePath, "node_modules"),
291
- ];
292
- const matchedPaths: [string] = globby.sync(filePatten);
293
- _.each(matchedPaths, (matchedPath: string) => {
294
- delete require.cache[require.resolve(matchedPath)];
295
- let json = loadFile(matchedPath);
296
- if (!_.has(json, "listenTo")) {
297
- json.listenTo = path.basename(matchedPath).split(".")[0];
298
- }
299
- results.push(json);
300
- });
301
- return results;
302
- };
303
-
304
- export const loadFields = (filePath: string) => {
305
- let results = [];
306
- const filePatten = [
307
- path.join(filePath, "*.field.yml"),
308
- "!" + path.join(filePath, "node_modules"),
309
- ];
310
- const matchedPaths: [string] = globby.sync(filePatten);
311
- _.each(matchedPaths, (matchedPath: string) => {
312
- let json = loadFile(matchedPath);
313
- if (!json.name) {
314
- json.name = path.basename(matchedPath).split(".")[0];
315
- }
316
- if (!json.object_name) {
317
- json.object_name = path.parse(
318
- path.dirname(path.dirname(matchedPath))
319
- ).name;
320
- }
321
- results.push(json);
322
- });
323
- return results;
324
- };
325
-
326
- export const loadLayouts = (filePath: string) => {
327
- let results = [];
328
- const filePatten = [
329
- path.join(filePath, "*.layout.yml"),
330
- "!" + path.join(filePath, "node_modules"),
331
- ];
332
- const matchedPaths: [string] = globby.sync(filePatten);
333
- _.each(matchedPaths, (matchedPath: string) => {
334
- let json = loadFile(matchedPath);
335
- let names = path.basename(matchedPath).split(".");
336
-
337
- if (!json.name) {
338
- json.name = names[1];
339
- }
340
- if (!json.object_name) {
341
- json.object_name = names[0];
342
- }
343
- results.push(json);
344
- });
345
- return results;
346
- };
347
-
348
- export const loadValidationRules = (filePath: string)=>{
349
- let results = []
350
- const filePatten = [
351
- path.join(filePath, "*.validationRule.yml"),
352
- "!" + path.join(filePath, "node_modules"),
353
- ]
354
- const matchedPaths:[string] = globby.sync(filePatten);
355
- _.each(matchedPaths, (matchedPath:string)=>{
356
- let json = loadFile(matchedPath);
357
- let names = path.basename(matchedPath).split('.');
358
-
359
- if(!json.name){
360
- json.name = names[1]
361
- }
362
- if(!json.object_name){
363
- json.object_name = path.parse(path.dirname(path.dirname(matchedPath))).name
364
- }
365
- results.push(json)
366
- })
367
- return results
368
- }
369
-
370
- export const loadRoles = (filePath: string)=>{
371
- let results = []
372
- const filePatten = [
373
- path.join(filePath, "*.role.yml"),
374
- "!" + path.join(filePath, "node_modules"),
375
- ]
376
- const matchedPaths:[string] = globby.sync(filePatten);
377
- _.each(matchedPaths, (matchedPath:string)=>{
378
- let json = loadFile(matchedPath);
379
- let names = path.basename(matchedPath).split('.');
380
-
381
- if(!json.name){
382
- json.name = names[1]
383
- }
384
- results.push(json)
385
- })
386
- return results
387
- }
388
-
389
- export const loadFlowRoles = (filePath: string)=>{
390
- let results = []
391
- const filePatten = [
392
- path.join(filePath, "*.flowRole.yml"),
393
- "!" + path.join(filePath, "node_modules"),
394
- ]
395
- const matchedPaths:[string] = globby.sync(filePatten);
396
- _.each(matchedPaths, (matchedPath:string)=>{
397
- let json = loadFile(matchedPath);
398
- let names = path.basename(matchedPath).split('.');
399
-
400
- if(!json.name){
401
- json.name = names[1]
402
- }
403
- results.push(json)
404
- })
405
- return results
406
- }
407
-
408
- export const loadApprovalProcesses = (filePath: string)=>{
409
- let results = []
410
- const filePatten = [
411
- path.join(filePath, "*.approvalProcess.yml"),
412
- "!" + path.join(filePath, "node_modules"),
413
- ]
414
- const matchedPaths:[string] = globby.sync(filePatten);
415
- _.each(matchedPaths, (matchedPath:string)=>{
416
- let json = loadFile(matchedPath);
417
- let names = path.basename(matchedPath).split('.');
418
-
419
- if(!json.name){
420
- json.name = names[1]
421
- }
422
- results.push(json)
423
- })
424
- return results
425
- }
426
-
427
- export const loadWorkflows = (filePath: string)=>{
428
- let results = []
429
- const filePatten = [
430
- path.join(filePath, "*.workflow.yml"),
431
- "!" + path.join(filePath, "node_modules"),
432
- ]
433
- const matchedPaths:[string] = globby.sync(filePatten);
434
- _.each(matchedPaths, (matchedPath:string)=>{
435
- let json = loadFile(matchedPath);
436
- let names = path.basename(matchedPath).split('.');
437
-
438
- if(!json.name){
439
- json.name = names[0]
440
- }
441
- results.push(json)
442
- })
443
- return results
444
- }
445
-
446
- export const loadListViews = (filePath: string)=>{
447
- let results = []
448
- const filePatten = [
449
- path.join(filePath, "*.listview.yml"),
450
- "!" + path.join(filePath, "node_modules"),
451
- ]
452
- const matchedPaths:[string] = globby.sync(filePatten);
453
- _.each(matchedPaths, (matchedPath:string)=>{
454
- let json = loadFile(matchedPath);
455
- if(!json.name){
456
- json.name = path.basename(matchedPath).split('.')[0]
457
- }
458
- if(!json.object_name){
459
- json.object_name = path.parse(path.dirname(path.dirname(matchedPath))).name
460
- }
461
- results.push(json)
462
- })
463
- return results
464
- }
465
-
466
- export const loadButtons = (filePath: string)=>{
467
- let results = []
468
- const filePatten = [
469
- path.join(filePath, "*.button.yml"),
470
- "!" + path.join(filePath, "node_modules"),
471
- ]
472
- const matchedPaths:[string] = globby.sync(filePatten);
473
- _.each(matchedPaths, (matchedPath:string)=>{
474
- let json = loadFile(matchedPath);
475
- if(!json.name){
476
- json.name = path.basename(matchedPath).split('.')[0]
477
- }
478
- if(!json.object_name){
479
- json.object_name = path.parse(path.dirname(path.dirname(matchedPath))).name
480
- }
481
- results.push(json)
482
- })
483
- return results
484
- }
485
-
486
- export const loadButtonScripts = (filePath: string)=>{
487
- let results = []
488
- const filePatten = [
489
- path.join(filePath, "*.button.js"),
490
- "!" + path.join(filePath, "node_modules"),
491
- ]
492
- const matchedPaths:[string] = globby.sync(filePatten);
493
- _.each(matchedPaths, (matchedPath:string)=>{
494
- delete require.cache[require.resolve(matchedPath)]
495
- let json = loadFile(matchedPath);
496
- if(!_.has(json, 'listenTo')){
497
- json.listenTo = path.parse(path.dirname(path.dirname(matchedPath))).name
498
- }
499
- results.push(json)
500
- })
501
- return results
502
- }
503
-
504
- export const loadPermissions = (filePath: string)=>{
505
- let results = []
506
- const filePatten = [
507
- path.join(filePath, "*.permission.yml"),
508
- "!" + path.join(filePath, "node_modules"),
509
- ]
510
- const matchedPaths:[string] = globby.sync(filePatten);
511
- _.each(matchedPaths, (matchedPath:string)=>{
512
- let json = loadFile(matchedPath);
513
- if(!_.has(json, 'object_name')){
514
- json.object_name = path.parse(path.dirname(path.dirname(matchedPath))).name
515
- }
516
- json.name = path.basename(matchedPath).split('.')[0]
517
- results.push(json)
518
- })
519
- return results
520
- }
521
-
522
- export const loadProfiles = (filePath: string)=>{
523
- let results = []
524
- const filePatten = [
525
- path.join(filePath, "*.profile.yml"),
526
- "!" + path.join(filePath, "node_modules"),
527
- ]
528
- const matchedPaths:[string] = globby.sync(filePatten);
529
- _.each(matchedPaths, (matchedPath:string)=>{
530
- let json = loadFile(matchedPath);
531
- json.name = path.basename(matchedPath).split('.')[0];
532
- json._id = json.name;
533
- json.type = 'profile';
534
- results.push(json)
535
- })
536
- return results
537
- }
538
-
539
- export const loadPermissionsets = (filePath: string)=>{
540
- let results = []
541
- const filePatten = [
542
- path.join(filePath, "*.permissionset.yml"),
543
- "!" + path.join(filePath, "node_modules"),
544
- ]
545
- const matchedPaths:[string] = globby.sync(filePatten);
546
- _.each(matchedPaths, (matchedPath:string)=>{
547
- let json = loadFile(matchedPath);
548
- json.name = path.basename(matchedPath).split('.')[0];
549
- json._id = json.name;
550
- json.type = 'permission_set';
551
- results.push(json)
552
- })
553
- return results
554
- }
555
-
556
- export const loadJsonFiles = (filePatten: Array<string>)=>{
557
- let results = []
558
- const matchedPaths:[string] = globby.sync(filePatten);
559
- _.each(matchedPaths, (matchedPath:string)=>{
560
- let json = loadFile(matchedPath);
561
- if(json){
562
- json.__filename = matchedPath
563
- }
564
- results.push({file: matchedPath, data: json})
565
- })
566
- return results
567
- }
568
-
569
- export const loadApps = (filePath: string)=>{
570
- let results = []
571
- if(filePath.indexOf("*") < 0 && isAppFile(filePath)){
572
- results.push(loadFile(filePath))
573
- }else{
574
- const filePatten = [
575
- path.join(filePath, "*.app.yml"),
576
- path.join(filePath, "*.app.js"),
577
- "!" + path.join(filePath, "node_modules"),
578
- ]
579
- const matchedPaths:[string] = globby.sync(filePatten);
580
- _.each(matchedPaths, (matchedPath:string)=>{
581
- let json = loadFile(matchedPath);
582
- results.push(json)
583
- })
584
- }
585
- return results
586
- }
587
-
588
- export function extend(destination: JsonMap, ...sources: JsonMap[]){
589
- _.each(sources, (source: JsonMap)=>{
590
- _.each(source, (v:never, k: string)=>{
591
- if(!has(destination, k)){
592
- destination[k] = v
593
- }else if(isJsonMap(v)){
594
- let _d = getJsonMap(destination, k);
595
- if(isJsonMap(_d)){
596
- destination[k] = extend(clone(_d), v)
597
- }else{
598
- destination[k] = v
599
- }
600
- }else{
601
- destination[k] = v
602
- }
603
- })
604
- })
605
- return destination
606
- }
607
-
608
- exports.isObjectFile = (filePath: string)=>{
609
- return !fs.statSync(filePath).isDirectory() && (filePath.endsWith('.object.yml') || filePath.endsWith('.object.json'))
610
- }
611
- let isAppFile = (filePath: string)=>{
612
- return !fs.statSync(filePath).isDirectory() && (filePath.endsWith('.app.yml') || filePath.endsWith('.app.js'))
613
- }
614
- exports.isAppFile = isAppFile
615
-
616
- exports.isTriggerFile = (filePath: string)=>{
617
- return !fs.statSync(filePath).isDirectory() && filePath.endsWith('.trigger.js')
618
- }
619
-
620
- exports.isActionFile = (filePath: string)=>{
621
- return !fs.statSync(filePath).isDirectory() && filePath.endsWith('.action.js')
622
- }
623
-
624
- exports.isFieldFile = (filePath: string)=>{
625
- return !fs.statSync(filePath).isDirectory() && (filePath.endsWith('.field.yml') || filePath.endsWith('.field.js'))
626
- }
627
-
628
- exports.isReportFile = (filePath: string)=>{
629
- return !fs.statSync(filePath).isDirectory() && (filePath.endsWith('.report.yml') || filePath.endsWith('.report.js'))
630
- }
631
-
632
- export function loadObjectFiles(filePath: string) {
633
- return loadObjects(filePath);
634
- }
635
-
636
- export function loadAppFiles(filePath: string) {
637
- return loadApps(filePath);
638
- }
639
-
640
- export function loadObjectDataFiles(filePath: string){
641
- let results = []
642
- const filePatten = [
643
- path.join(filePath, "*.data.json"),
644
- "!" + path.join(filePath, "node_modules"),
645
- ]
646
- const matchedPaths:[string] = globby.sync(filePatten);
647
- _.each(matchedPaths, (matchedPath:string)=>{
648
- let records = loadFile(matchedPath);
649
- let objectName = path.basename(matchedPath).split('.')[0];
650
- results.push({objectName: objectName, records: records});
651
- })
652
- return results
653
- }
654
-
655
- export function getBaseDirectory(){
656
- //return require('app-root-path').path
657
- let cwd = process.cwd();
658
- if (cwd.indexOf('.meteor') > -1) {
659
- return cwd.split('.meteor')[0];
660
- }
661
- return cwd;
662
- }
663
-
664
- function calcString(str: string, content: any = process.env): string{
665
-
666
- if(!_.isString(str)){
667
- return str;
668
- }
669
-
670
- let calcFun: Function;
671
- var reg = /(\${[^{}]*\})/g;
672
- let rev = str.replace(reg,function(m,$1){
673
- return $1.replace(/\{\s*/,"{args[\"").replace(/\s*\}/,"\"]}");
674
- })
675
- eval(`calcFun = function(args){return \`${rev}\`}`);
676
- let val = calcFun.call({}, content);
677
- if(_.isString(val) && val){
678
- return val.replace(/\\r/g, '\r').replace(/\\n/g, '\n').replace(/undefined/g, '')
679
- }else{
680
- return null;
681
- }
682
- }
683
-
684
- function calcSteedosConfig(config: JsonMap){
685
- _.each(config, (v:never, k: string)=>{
686
- if(isJsonMap(v)){
687
- let _d = getJsonMap(config, k);
688
- if(isJsonMap(_d)){
689
- config[k] = calcSteedosConfig(clone(_d))
690
- }else{
691
- config[k] = calcString(v);
692
- if(k && _.isString(k) && k.startsWith('enable_') && config[k] && _.isString(config[k])){
693
- config[k] = validator.toBoolean(config[k], true);
694
- }
695
- }
696
- }else{
697
- config[k] = calcString(v)
698
- if(k && _.isString(k) && k.startsWith('enable_') && config[k] && _.isString(config[k])){
699
- config[k] = validator.toBoolean(config[k], true);
700
- }
701
- }
702
- });
703
-
704
- if(config){
705
- (config as any).setTenant = (tenant)=>{
706
- config.tenant = defaultsDeep(tenant, config.tenant);
707
- }
708
- }
709
- return config
710
- }
711
-
712
- export function getSteedosConfig(){
713
- if(!_.isEmpty(STEEDOS_CONFIG)){
714
- return STEEDOS_CONFIG;
715
- }
716
- let config: any;
717
- let configPath = path.join(getBaseDirectory(), configName)
718
- if (fs.existsSync(configPath) && !fs.statSync(configPath).isDirectory()) {
719
- config = loadFile(configPath)
720
- if (config.env){
721
- _.each(config.env, function(item, key){
722
- process.env[key] = calcString(item)
723
- })
724
- }
725
- let emailConfig = config.email;
726
- if(emailConfig){
727
- if (!emailConfig.url && emailConfig.host && emailConfig.port && emailConfig.username && emailConfig.password) {
728
- let url = `smtps://${emailConfig.username}:${emailConfig.password}@${emailConfig.host}:${emailConfig.port}/`;
729
- emailConfig.url = url;
730
- }
731
- if(emailConfig.url){
732
- process.env["MAIL_URL"] = calcString(emailConfig.url);
733
- }
734
- if(emailConfig.from){
735
- // 测试下来注册用户时不用MAIL_FROM这个环境变量也是可以的,这里重写是为了保险起见,怕其他地方用到这个环境变量
736
- process.env["MAIL_FROM"] = calcString(emailConfig.from);
737
- }
738
- }
739
- STEEDOS_CONFIG = calcSteedosConfig(config);
740
- // }else{
741
- // throw new Error('Config file not found: ' + configPath);
742
- }
743
- return STEEDOS_CONFIG;
744
- }
745
-
746
- export function getLicense(){
747
- let license = ""
748
- let licensePath = path.join(getBaseDirectory(), licenseName)
749
- if (fs.existsSync(licensePath) && !fs.statSync(licensePath).isDirectory()) {
750
- license = clone(fs.readFileSync(licensePath, 'utf-8'));
751
- }
752
- return license;
753
- }
754
-
755
- export function writeLicense(license){
756
- let licensePath = path.join(getBaseDirectory(), licenseName)
757
- fs.writeFileSync(licensePath, license, "utf8")
758
- }
759
-
760
- export function getRandomString(length) {
761
- var result = '';
762
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
763
- var charactersLength = characters.length;
764
- for ( var i = 0; i < length; i++ ) {
765
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
766
- }
767
- return result;
768
- }
769
-
770
-
771
- declare var Meteor:any;
772
-
773
- export const isMeteor = () => {
774
- return (typeof Meteor != "undefined")
775
- }
776
-
777
- export function wrapAsync(fn, context){
778
- let proxyFn = async function(_cb){
779
- let value = null;
780
- let error = null;
781
- try {
782
- value = await fn.call(context)
783
- } catch (err) {
784
- error = err
785
- }
786
- _cb(error, value)
787
- }
788
- let fut = new Future();
789
- let callback = fut.resolver();
790
- let result = proxyFn.apply(this, [callback]);
791
- return fut ? fut.wait() : result;
792
- }
793
-
794
- export function getTemplateSpaceId(){
795
- let steedosConfig = getSteedosConfig();
796
- if(steedosConfig && steedosConfig.public && steedosConfig.public.templateSpaceId){
797
- return steedosConfig.public.templateSpaceId
798
- }
799
- }
800
-
801
- export function getCloudAdminSpaceId(){
802
- let steedosConfig = getSteedosConfig();
803
- if(steedosConfig && steedosConfig.public && steedosConfig.public.cloudAdminSpaceId){
804
- return steedosConfig.public.cloudAdminSpaceId
805
- }
806
- }
807
-
808
- export function isTemplateSpace(spaceId){
809
- let steedosConfig = getSteedosConfig();
810
-
811
- if(spaceId && steedosConfig && steedosConfig.public && steedosConfig.public.templateSpaceId && spaceId === steedosConfig.public.templateSpaceId){
812
- return true
813
- }
814
-
815
- return false
816
- }
817
-
818
- export function isCloudAdminSpace(spaceId){
819
- let steedosConfig = getSteedosConfig();
820
- if(spaceId && steedosConfig && steedosConfig.public && steedosConfig.public.cloudAdminSpaceId && spaceId === steedosConfig.public.cloudAdminSpaceId){
821
- return true
822
- }
823
- return false
824
- }
825
-
826
- export function getMD5(data){
827
- let md5 = crypto.createHash('md5');
828
- return md5.update(data).digest('hex');
829
- }
830
-
831
- export function JSONStringify(data) {
832
- return JSON.stringify(data, function (key, val) {
833
- if (typeof val === 'function') {
834
- return val + '';
835
- }
836
- return val;
837
- })
838
- }
839
-
840
- //此函数判断不准确
841
- // export function isSystemObject(object_name: string) {
842
- // // 以c结尾的都是零代码上定义的对象
843
- // return !object_name.endsWith("__c")
844
- // }
845
- export function isCodeObject(objectName: string){
846
- let objectConfig = getObjectConfig(objectName);
847
- if(objectConfig && objectConfig.__filename){
848
- return true;
849
- }
850
- }
851
-
852
- /**
853
- * 获取对象字段的基本数据类型,目前支持以下数据类型:
854
- * "text",
855
- * "boolean",
856
- * "date",
857
- * "datetime",
858
- * "number",
859
- * "currency",
860
- * "percent"
861
- * @param objectFields 对象字段集合,即getObjectConfig(object_name)得到的结果
862
- * @param key 字段名
863
- */
864
- export function getFieldDataType(objectFields: any, key: string): string {
865
- var field: any, result: string;
866
- if (objectFields && key) {
867
- field = objectFields[key];
868
- result = field && field.type;
869
- if (["formula", "summary"].indexOf(result) > -1) {
870
- result = field.data_type;
871
- }
872
- return result;
873
- } else {
874
- return "text";
875
- }
876
- }
877
-
878
- export function isValidDate(date: any): boolean {
879
- return date instanceof Date && !isNaN(date.getTime());
880
- }
881
-
882
- export function processFilters(filters: [], objectFields: any) {
883
- if(filters && filters.length){
884
- filters.forEach((filter: any)=>{
885
- if(!(!_.isArray(filter) && _.isObject(filter))){
886
- // 只有{field:xx,operation:xx,value:xx}格式的才支持转换
887
- return;
888
- }
889
- if(!filter.field){
890
- throw new Error("object_fields_error_filter_item_field_required");
891
- }
892
- if(!filter.operation){
893
- throw new Error("object_fields_error_filter_item_operation_required");
894
- }
895
- if(!filter.value){
896
- throw new Error("object_fields_error_filter_item_value_required");
897
- }
898
- // "text","boolean","date","datetime","number","currency","percent"
899
- let dataType = getFieldDataType(objectFields, filter.field);
900
- if(["number", "currency", "percent"].indexOf(dataType) > -1){
901
- if(typeof filter.value === "string"){
902
- filter.value = Number(filter.value);
903
- if(isNaN(filter.value)){
904
- throw new Error("object_fields_error_filter_item_invalid_number");
905
- }
906
- }
907
- }
908
- else if(dataType === "boolean"){
909
- if(typeof filter.value === "string"){
910
- if(["true", "True", "TRUE", "1"].indexOf(filter.value.trim()) > -1){
911
- filter.value = true;
912
- }
913
- else if(["false", "False", "FALSE", "0"].indexOf(filter.value.trim()) > -1){
914
- filter.value = false;
915
- }
916
- else{
917
- throw new Error("object_fields_error_filter_item_invalid_boolean");
918
- }
919
- }
920
- }
921
- else if(dataType === "date"){
922
- if(typeof filter.value === "string"){
923
- // 这里转换为按utc的0点时间值来过滤
924
- // 实测输入2020-02-12,new Date结果为2020-02-12T00:00:00.000Z
925
- filter.value = new Date(filter.value);
926
- if(!isValidDate(filter.value)){
927
- throw new Error("object_fields_error_filter_item_invalid_date");
928
- }
929
- }
930
- }
931
- else if(dataType === "datetime"){
932
- if(typeof filter.value === "string"){
933
- // 这里转换为按utc时间值来过滤
934
- // 实测输入2020-02-12 12:00,new Date结果为2020-02-12T04:00:00.000Z
935
- filter.value = new Date(filter.value);
936
- if(!isValidDate(filter.value)){
937
- throw new Error("object_fields_error_filter_item_invalid_date");
938
- }
939
- }
940
- }
941
- });
942
- }
943
- }
944
-
945
- export function absoluteUrl (path, options?) {
946
- // path is optional
947
- if (!options && typeof path === 'object') {
948
- options = path;
949
- path = undefined;
950
- }
951
- const rootUrl = process.env.ROOT_URL
952
- // merge options with defaults
953
- options = Object.assign({}, {rootUrl: rootUrl}, options || {});
954
-
955
- var url = options.rootUrl;
956
- if (!url)
957
- throw new Error("Must pass options.rootUrl or set ROOT_URL in the server environment");
958
-
959
- if (!/^http[s]?:\/\//i.test(url)) // url starts with 'http://' or 'https://'
960
- url = 'http://' + url; // we will later fix to https if options.secure is set
961
-
962
- if (! url.endsWith("/")) {
963
- url += "/";
964
- }
965
-
966
- if (path) {
967
- // join url and path with a / separator
968
- while (path.startsWith("/")) {
969
- path = path.slice(1);
970
- }
971
- url += path;
972
- }
973
-
974
- // turn http to https if secure option is set, and we're not talking
975
- // to localhost.
976
- if (options.secure &&
977
- /^http:/.test(url) && // url starts with 'http:'
978
- !/http:\/\/localhost[:\/]/.test(url) && // doesn't match localhost
979
- !/http:\/\/127\.0\.0\.1[:\/]/.test(url)) // or 127.0.0.1
980
- url = url.replace(/^http:/, 'https:');
981
-
982
- if (options.replaceLocalhost)
983
- url = url.replace(/^http:\/\/localhost([:\/].*)/, 'http://127.0.0.1$1');
984
-
985
- return url;
986
- }
987
-
988
- export function validateFilters(filters: [], objectFields: any) {
989
- processFilters(clone(filters), objectFields);
990
- }
991
-
992
- export async function sleep(ms) {
993
- return new Promise(resolve => setTimeout(resolve, ms));
994
- }
995
-
996
- export function parserFilters(filters){
997
- if(_.isString(filters)){
998
- filters = odataMongodb.createFilter(filters)
999
- }
1000
- let query: any = {};
1001
- if(_.isArray(filters) && filters.length > 0 && _.isArray(filters[0])){
1002
- _.each(filters,function(filter){
1003
- Object.assign(query, parserFilters(filter))
1004
- })
1005
- }else if(_.isArray(filters) && filters.length > 0){
1006
- if(filters[1] && filters[1] == '='){
1007
- let key = filters[0]
1008
- let value = filters[2]
1009
- Object.assign(query, {[key]: value})
1010
- }else if(filters[1] && (filters[1] == '!=' || filters[1] == '<>')){
1011
- let key = filters[0]
1012
- let value = filters[2]
1013
- Object.assign(query, {[key]: {$ne: value}})
1014
- }else if(filters[1] && filters[1] == 'in'){
1015
- let key = filters[0]
1016
- let value = filters[2]
1017
- Object.assign(query, {[key]: {$in: value}})
1018
- }else{
1019
- _.each(filters,function(filter){
1020
- let parsedFilters = parserFilters(filter);
1021
- if(query._id && query._id.$ne && parsedFilters._id && parsedFilters._id.$ne){
1022
- parsedFilters._id.$ne = [parsedFilters._id.$ne]
1023
- parsedFilters._id.$ne = parsedFilters._id.$ne.concat(query._id.$ne);
1024
- delete query._id;
1025
- }
1026
- Object.assign(query, parsedFilters)
1027
- })
1028
- }
1029
- }else{
1030
- _.each(filters, function (v, k) {
1031
- if(_.isArray(v) && v.length > 0){
1032
- Object.assign(query, parserFilters(v))
1033
- }else{
1034
- if (k === '$and') {
1035
- Object.assign(query, parserFilters(v))
1036
- } else {
1037
- if(_.isArray(filters) && _.isObject(v)){
1038
- Object.assign(query, v)
1039
- }else{
1040
- Object.assign(query, {[k]: v})
1041
- }
1042
- }
1043
- }
1044
-
1045
- })
1046
- }
1047
- return query;
1048
- }
1049
-
1050
-
1051
- export function clearRequireCache(filename) {
1052
- /* istanbul ignore next */
1053
- Object.keys(require.cache).forEach(function (key) {
1054
- if (key == filename) {
1055
- delete require.cache[key];
1056
- }
1057
- });
1058
- };
1059
-
1060
- export function loadService(broker, filename){
1061
- clearRequireCache(filename);
1062
- return broker.loadService(filename);
1063
- }
1064
-
1065
-
1066
- loadCoreValidators();