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