@steedos/objectql 2.1.76 → 2.1.84

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 (279) hide show
  1. package/lib/actions/field_updates.js +15 -15
  2. package/lib/actions/field_updates.js.map +1 -1
  3. package/lib/actions/index.js +3 -3
  4. package/lib/actions/index.js.map +1 -1
  5. package/lib/actions/workflow_notifications.js +10 -10
  6. package/lib/actions/workflow_notifications.js.map +1 -1
  7. package/lib/actions/workflow_rule.js +19 -19
  8. package/lib/actions/workflow_rule.js.map +1 -1
  9. package/lib/driver/index.js +1 -0
  10. package/lib/driver/index.js.map +1 -1
  11. package/lib/driver/metadata.js +3 -3
  12. package/lib/driver/metadata.js.map +1 -1
  13. package/lib/driver/meteorMongo.js +36 -36
  14. package/lib/driver/meteorMongo.js.map +1 -1
  15. package/lib/driver/mongo.js +43 -43
  16. package/lib/driver/mongo.js.map +1 -1
  17. package/lib/driver/mysql.js +2 -2
  18. package/lib/driver/mysql.js.map +1 -1
  19. package/lib/driver/oracle.js +5 -5
  20. package/lib/driver/oracle.js.map +1 -1
  21. package/lib/driver/postgres.js +2 -2
  22. package/lib/driver/postgres.js.map +1 -1
  23. package/lib/driver/sqlite3.js +2 -2
  24. package/lib/driver/sqlite3.js.map +1 -1
  25. package/lib/driver/sqlserver.js +4 -4
  26. package/lib/driver/sqlserver.js.map +1 -1
  27. package/lib/dynamic-load/actions.js +22 -18
  28. package/lib/dynamic-load/actions.js.map +1 -1
  29. package/lib/dynamic-load/approval_process.js +15 -10
  30. package/lib/dynamic-load/approval_process.js.map +1 -1
  31. package/lib/dynamic-load/button.js +25 -18
  32. package/lib/dynamic-load/button.js.map +1 -1
  33. package/lib/dynamic-load/chart.js +20 -23
  34. package/lib/dynamic-load/chart.js.map +1 -1
  35. package/lib/dynamic-load/field.js +21 -16
  36. package/lib/dynamic-load/field.js.map +1 -1
  37. package/lib/dynamic-load/flow_role.js +12 -8
  38. package/lib/dynamic-load/flow_role.js.map +1 -1
  39. package/lib/dynamic-load/index.d.ts +1 -0
  40. package/lib/dynamic-load/index.js +20 -19
  41. package/lib/dynamic-load/index.js.map +1 -1
  42. package/lib/dynamic-load/layout.js +19 -14
  43. package/lib/dynamic-load/layout.js.map +1 -1
  44. package/lib/dynamic-load/listview.js +14 -11
  45. package/lib/dynamic-load/listview.js.map +1 -1
  46. package/lib/dynamic-load/method.js +9 -6
  47. package/lib/dynamic-load/method.js.map +1 -1
  48. package/lib/dynamic-load/object_translations.js +29 -51
  49. package/lib/dynamic-load/object_translations.js.map +1 -1
  50. package/lib/dynamic-load/originalObject.js +1 -1
  51. package/lib/dynamic-load/originalObject.js.map +1 -1
  52. package/lib/dynamic-load/package.d.ts +9 -0
  53. package/lib/dynamic-load/package.js +507 -0
  54. package/lib/dynamic-load/package.js.map +1 -0
  55. package/lib/dynamic-load/page.js +20 -23
  56. package/lib/dynamic-load/page.js.map +1 -1
  57. package/lib/dynamic-load/permission.js +61 -65
  58. package/lib/dynamic-load/permission.js.map +1 -1
  59. package/lib/dynamic-load/permissionset.js +30 -25
  60. package/lib/dynamic-load/permissionset.js.map +1 -1
  61. package/lib/dynamic-load/preload_data.js +55 -74
  62. package/lib/dynamic-load/preload_data.js.map +1 -1
  63. package/lib/dynamic-load/profile.js +33 -28
  64. package/lib/dynamic-load/profile.js.map +1 -1
  65. package/lib/dynamic-load/query.js +20 -23
  66. package/lib/dynamic-load/query.js.map +1 -1
  67. package/lib/dynamic-load/restrictionRules.js +18 -23
  68. package/lib/dynamic-load/restrictionRules.js.map +1 -1
  69. package/lib/dynamic-load/role.js +12 -8
  70. package/lib/dynamic-load/role.js.map +1 -1
  71. package/lib/dynamic-load/shareRules.js +18 -23
  72. package/lib/dynamic-load/shareRules.js.map +1 -1
  73. package/lib/dynamic-load/tab.js +4 -3
  74. package/lib/dynamic-load/tab.js.map +1 -1
  75. package/lib/dynamic-load/tabs.js +9 -7
  76. package/lib/dynamic-load/tabs.js.map +1 -1
  77. package/lib/dynamic-load/translations.js +23 -17
  78. package/lib/dynamic-load/translations.js.map +1 -1
  79. package/lib/dynamic-load/trigger.js +14 -10
  80. package/lib/dynamic-load/trigger.js.map +1 -1
  81. package/lib/dynamic-load/validation_rule.js +13 -8
  82. package/lib/dynamic-load/validation_rule.js.map +1 -1
  83. package/lib/dynamic-load/workflow.js +38 -25
  84. package/lib/dynamic-load/workflow.js.map +1 -1
  85. package/lib/errors/index.js +2 -1
  86. package/lib/errors/index.js.map +1 -1
  87. package/lib/formula/core.js +105 -91
  88. package/lib/formula/core.js.map +1 -1
  89. package/lib/formula/field_formula.js +26 -20
  90. package/lib/formula/field_formula.js.map +1 -1
  91. package/lib/formula/index.js +26 -26
  92. package/lib/formula/index.js.map +1 -1
  93. package/lib/formula/params.js +1 -1
  94. package/lib/formula/params.js.map +1 -1
  95. package/lib/formula/recompute.js +27 -25
  96. package/lib/formula/recompute.js.map +1 -1
  97. package/lib/formula/simple_params.js +2 -2
  98. package/lib/formula/simple_params.js.map +1 -1
  99. package/lib/formula/util.js +33 -23
  100. package/lib/formula/util.js.map +1 -1
  101. package/lib/index.d.ts +0 -1
  102. package/lib/index.js +15 -16
  103. package/lib/index.js.map +1 -1
  104. package/lib/metadata-register/_base.d.ts +1 -0
  105. package/lib/metadata-register/_base.js +45 -15
  106. package/lib/metadata-register/_base.js.map +1 -1
  107. package/lib/metadata-register/app.js +8 -8
  108. package/lib/metadata-register/chart.js +1 -1
  109. package/lib/metadata-register/chart.js.map +1 -1
  110. package/lib/metadata-register/index.js +72 -72
  111. package/lib/metadata-register/index.js.map +1 -1
  112. package/lib/metadata-register/layout.js +18 -16
  113. package/lib/metadata-register/layout.js.map +1 -1
  114. package/lib/metadata-register/object.d.ts +0 -1
  115. package/lib/metadata-register/object.js +17 -35
  116. package/lib/metadata-register/object.js.map +1 -1
  117. package/lib/metadata-register/page.js +1 -1
  118. package/lib/metadata-register/page.js.map +1 -1
  119. package/lib/metadata-register/permissionFields.js +2 -2
  120. package/lib/metadata-register/permissionFields.js.map +1 -1
  121. package/lib/metadata-register/permissionset.js +6 -6
  122. package/lib/metadata-register/profile.js +6 -6
  123. package/lib/metadata-register/query.js +1 -1
  124. package/lib/metadata-register/query.js.map +1 -1
  125. package/lib/metadata-register/restrictionRules.js +2 -2
  126. package/lib/metadata-register/restrictionRules.js.map +1 -1
  127. package/lib/metadata-register/shareRules.js +2 -2
  128. package/lib/metadata-register/shareRules.js.map +1 -1
  129. package/lib/metadata-register/tab.js +1 -1
  130. package/lib/metadata-register/tab.js.map +1 -1
  131. package/lib/metadata-register/tabs.js +18 -16
  132. package/lib/metadata-register/tabs.js.map +1 -1
  133. package/lib/services/datasourceServiceFactory.d.ts +1 -0
  134. package/lib/services/datasourceServiceFactory.js +51 -0
  135. package/lib/services/datasourceServiceFactory.js.map +1 -0
  136. package/lib/services/helpers/graphql.js +86 -87
  137. package/lib/services/helpers/graphql.js.map +1 -1
  138. package/lib/services/helpers/index.js +2 -2
  139. package/lib/services/helpers/index.js.map +1 -1
  140. package/lib/services/helpers/rest.js +1 -1
  141. package/lib/services/helpers/rest.js.map +1 -1
  142. package/lib/services/index.d.ts +3 -0
  143. package/lib/services/index.js +10 -4
  144. package/lib/services/index.js.map +1 -1
  145. package/lib/services/objectService.d.ts +1 -1
  146. package/lib/services/objectService.js +148 -147
  147. package/lib/services/objectService.js.map +1 -1
  148. package/lib/services/objectServiceDispatcher.js +102 -92
  149. package/lib/services/objectServiceDispatcher.js.map +1 -1
  150. package/lib/{metadata-register/objectServiceManager.d.ts → services/objectServiceFactory.d.ts} +0 -0
  151. package/lib/{metadata-register/objectServiceManager.js → services/objectServiceFactory.js} +5 -5
  152. package/lib/services/objectServiceFactory.js.map +1 -0
  153. package/lib/summary/core.js +51 -44
  154. package/lib/summary/core.js.map +1 -1
  155. package/lib/summary/field_summary.js +21 -16
  156. package/lib/summary/field_summary.js.map +1 -1
  157. package/lib/summary/index.js +25 -22
  158. package/lib/summary/index.js.map +1 -1
  159. package/lib/summary/recompute.js +13 -11
  160. package/lib/summary/recompute.js.map +1 -1
  161. package/lib/ts-types/index.js +3 -3
  162. package/lib/ts-types/index.js.map +1 -1
  163. package/lib/typeorm/driver.js +58 -58
  164. package/lib/typeorm/driver.js.map +1 -1
  165. package/lib/typeorm/index.js +2 -1
  166. package/lib/typeorm/index.js.map +1 -1
  167. package/lib/typeorm/util.js +2 -2
  168. package/lib/typeorm/util.js.map +1 -1
  169. package/lib/types/app.js +41 -35
  170. package/lib/types/app.js.map +1 -1
  171. package/lib/types/config.js +52 -45
  172. package/lib/types/config.js.map +1 -1
  173. package/lib/types/connection.js +20 -18
  174. package/lib/types/connection.js.map +1 -1
  175. package/lib/types/dashboard.js +10 -7
  176. package/lib/types/dashboard.js.map +1 -1
  177. package/lib/types/datasource.d.ts +14 -3
  178. package/lib/types/datasource.js +205 -198
  179. package/lib/types/datasource.js.map +1 -1
  180. package/lib/types/field.d.ts +2 -2
  181. package/lib/types/field.js +6 -6
  182. package/lib/types/field.js.map +1 -1
  183. package/lib/types/field_permission.d.ts +1 -0
  184. package/lib/types/field_permission.js +30 -6
  185. package/lib/types/field_permission.js.map +1 -1
  186. package/lib/types/index.d.ts +1 -0
  187. package/lib/types/index.js +11 -9
  188. package/lib/types/index.js.map +1 -1
  189. package/lib/types/list_view.d.ts +1 -1
  190. package/lib/types/list_view.js +1 -1
  191. package/lib/types/list_view.js.map +1 -1
  192. package/lib/types/object.d.ts +17 -13
  193. package/lib/types/object.js +275 -234
  194. package/lib/types/object.js.map +1 -1
  195. package/lib/types/object_dynamic_load.d.ts +1 -0
  196. package/lib/types/object_dynamic_load.js +129 -164
  197. package/lib/types/object_dynamic_load.js.map +1 -1
  198. package/lib/types/object_events.js +5 -5
  199. package/lib/types/object_events.js.map +1 -1
  200. package/lib/types/object_layouts.js +7 -7
  201. package/lib/types/object_layouts.js.map +1 -1
  202. package/lib/types/object_permission.d.ts +1 -1
  203. package/lib/types/object_permission.js +1 -1
  204. package/lib/types/object_permission.js.map +1 -1
  205. package/lib/types/report.js +10 -7
  206. package/lib/types/report.js.map +1 -1
  207. package/lib/types/restrictionRule.js +11 -11
  208. package/lib/types/restrictionRule.js.map +1 -1
  209. package/lib/types/schema.d.ts +1 -4
  210. package/lib/types/schema.js +41 -30
  211. package/lib/types/schema.js.map +1 -1
  212. package/lib/types/shareRule.js +11 -11
  213. package/lib/types/shareRule.js.map +1 -1
  214. package/lib/types/trigger.js +2 -2
  215. package/lib/types/trigger.js.map +1 -1
  216. package/lib/types/validation_rules.js +5 -5
  217. package/lib/types/validation_rules.js.map +1 -1
  218. package/lib/util/convert.d.ts +2 -0
  219. package/lib/util/convert.js +130 -0
  220. package/lib/util/convert.js.map +1 -0
  221. package/lib/util/field.js +5 -3
  222. package/lib/util/field.js.map +1 -1
  223. package/lib/util/function_expression.js +5 -3
  224. package/lib/util/function_expression.js.map +1 -1
  225. package/lib/util/index.d.ts +2 -7
  226. package/lib/util/index.js +86 -166
  227. package/lib/util/index.js.map +1 -1
  228. package/lib/util/locale.js +5 -3
  229. package/lib/util/locale.js.map +1 -1
  230. package/lib/util/permission_shares.js +2 -2
  231. package/lib/util/permission_shares.js.map +1 -1
  232. package/lib/util/suffix.js +22 -16
  233. package/lib/util/suffix.js.map +1 -1
  234. package/lib/util/transform.js +11 -11
  235. package/lib/util/transform.js.map +1 -1
  236. package/lib/validators/index.js +3 -2
  237. package/lib/validators/index.js.map +1 -1
  238. package/package.json +13 -13
  239. package/server.js +0 -7
  240. package/src/dynamic-load/chart.ts +6 -1
  241. package/src/dynamic-load/index.ts +1 -0
  242. package/src/dynamic-load/object_translations.ts +19 -10
  243. package/src/dynamic-load/package.ts +303 -0
  244. package/src/dynamic-load/page.ts +7 -1
  245. package/src/dynamic-load/permission.ts +1 -5
  246. package/src/dynamic-load/preload_data.ts +2 -3
  247. package/src/dynamic-load/query.ts +6 -1
  248. package/src/dynamic-load/restrictionRules.ts +6 -2
  249. package/src/dynamic-load/shareRules.ts +5 -1
  250. package/src/dynamic-load/translations.ts +3 -1
  251. package/src/index.ts +0 -1
  252. package/src/metadata-register/_base.ts +23 -0
  253. package/src/metadata-register/object.ts +1 -20
  254. package/src/services/datasourceServiceFactory.ts +37 -0
  255. package/src/services/helpers/graphql.ts +5 -3
  256. package/src/services/index.ts +7 -0
  257. package/src/services/objectService.ts +9 -7
  258. package/src/services/objectServiceDispatcher.ts +6 -2
  259. package/src/{metadata-register/objectServiceManager.ts → services/objectServiceFactory.ts} +4 -4
  260. package/src/types/datasource.ts +81 -80
  261. package/src/types/field.ts +2 -2
  262. package/src/types/field_permission.ts +16 -0
  263. package/src/types/index.ts +1 -0
  264. package/src/types/list_view.ts +1 -1
  265. package/src/types/object.ts +71 -37
  266. package/src/types/object_dynamic_load.ts +14 -48
  267. package/src/types/object_permission.ts +1 -1
  268. package/src/types/schema.ts +11 -14
  269. package/src/util/convert.ts +130 -0
  270. package/src/util/index.ts +6 -120
  271. package/lib/graphql/index.d.ts +0 -3
  272. package/lib/graphql/index.js +0 -374
  273. package/lib/graphql/index.js.map +0 -1
  274. package/lib/graphql/utils.d.ts +0 -7
  275. package/lib/graphql/utils.js +0 -67
  276. package/lib/graphql/utils.js.map +0 -1
  277. package/lib/metadata-register/objectServiceManager.js.map +0 -1
  278. package/src/graphql/index.ts +0 -361
  279. package/src/graphql/utils.ts +0 -61
@@ -0,0 +1,303 @@
1
+ import _ = require('lodash');
2
+ import { getLazyLoadFields } from './field';
3
+ import { getLazyLoadButtons } from './button';
4
+ import { addObjectConfig } from '../types/object_dynamic_load';
5
+ import { addPermissionConfig, loadObjectMethods, loadObjectTriggers } from '../dynamic-load'
6
+ import { getSteedosSchema } from '../types'
7
+ import { objectToJson } from '../util/convert';
8
+ import { registerPermissionFields } from '..';
9
+ var util = require('../util');
10
+ var clone = require('clone');
11
+ // let Fiber = require('fibers');
12
+ declare var Creator: any;
13
+
14
+ /***
15
+ * 此文件应该迁移到metadata/core中:系统的结构为所有元数据加载都有metadata/core处理,这样metadata的处理就集中了,规则也就一致了,目前metadata core、objectql各自维护一套。
16
+ */
17
+ const getListenTo = function (json) {
18
+ if (!json.listenTo) {
19
+ console.log('json', json);
20
+ throw new Error('missing attribute listenTo');
21
+ }
22
+
23
+ if (!_.isString(json.listenTo) && !_.isFunction(json.listenTo)) {
24
+ throw new Error('listenTo must be a function or string')
25
+ }
26
+
27
+ let listenTo: string = '';
28
+
29
+ if (_.isString(json.listenTo)) {
30
+ listenTo = json.listenTo
31
+ } else if (_.isFunction(json.listenTo)) {
32
+ listenTo = json.listenTo()
33
+ }
34
+ return listenTo;
35
+ }
36
+
37
+ const loadPackageObjects = function (filePath: string) {
38
+ const objectJsons = util.loadObjects(filePath);
39
+ return objectJsons;
40
+ }
41
+
42
+ const loadPackageFields = function (filePath: string) {
43
+ const fieldJsons = util.loadFields(filePath);
44
+ return fieldJsons;
45
+ }
46
+
47
+ const loadPackageListViews = function (filePath: string) {
48
+ let listViewJsons = util.loadListViews(filePath);
49
+ return listViewJsons;
50
+ }
51
+
52
+ const loadPackageButtons = function (filePath: string) {
53
+ let buttonJsons = util.loadButtons(filePath);
54
+ return buttonJsons;
55
+ }
56
+
57
+ const loadPackageActions = function (filePath: string) {
58
+ let actions = util.loadActions(filePath);
59
+ return _.map(actions, actionToMetadata);
60
+ }
61
+
62
+ const loadPackageActionScripts = function (filePath: string) {
63
+ let buttonScripts = util.loadButtonScripts(filePath);
64
+ return _.map(buttonScripts, actionToMetadata);
65
+ }
66
+
67
+ const actionToMetadata = (config) => {
68
+ const actions = {};
69
+ let object_name = getListenTo(config);
70
+ const keys = _.keys(config);
71
+ _.each(keys, (key) => {
72
+ if (key.endsWith('Visible')) {
73
+ if (_.isFunction(config[key])) {
74
+ const _key = key.replace(/(.*)Visible/, '$1');
75
+ if (!actions[_key]) {
76
+ actions[_key] = {};
77
+ }
78
+ actions[_key]._visible = config[key].toString();
79
+ }
80
+ } else {
81
+ if (_.isFunction(config[key])) {
82
+ if (!actions[key]) {
83
+ actions[key] = {};
84
+ }
85
+ actions[key]._todo = config[key].toString();
86
+ }
87
+ }
88
+ })
89
+ return { object_name, actions };
90
+ }
91
+
92
+ const loadPackagePermissions = function (filePath: string) {
93
+ let permissions = util.loadPermissions(filePath);
94
+ return _.map(permissions, (permission) => {
95
+ delete permission.field_permissions;
96
+ return permission;
97
+ });
98
+ }
99
+
100
+ const registerPackageFieldPermissions = async function (filePath: string, broker, serviceName: string) {
101
+ let permissions = util.loadPermissions(filePath);
102
+ permissions.forEach(permission => {
103
+ addPermissionConfig(permission.object_name, permission);
104
+ });
105
+
106
+ const data = [];
107
+
108
+ for (const permission of permissions) {
109
+ const { field_permissions } = permission;
110
+ if (field_permissions && _.isArray(field_permissions) && field_permissions.length > 0) {
111
+ for (const field_permission of field_permissions) {
112
+ data.push({
113
+ "name": `${permission.name}.${permission.object_name}.${field_permission.field}`,
114
+ "permission_set_id": permission.name,
115
+ "permission_object": `${permission.name}_${permission.object_name}`,
116
+ "object_name": permission.object_name,
117
+ "field": field_permission.field,
118
+ "readable": field_permission.readable,
119
+ "editable": field_permission.editable,
120
+ "is_system": true,
121
+ })
122
+ }
123
+ }
124
+ }
125
+ if (data.length > 0) {
126
+ return await registerPermissionFields.mregister(broker, serviceName, data);
127
+ }
128
+ }
129
+
130
+ async function addObjectConfigs(broker, serviceName, objectConfigs) {
131
+ let metadatas = clone(objectConfigs);
132
+ _.map(metadatas, (metadata) => {
133
+ delete metadata.triggers;
134
+ delete metadata.listeners;
135
+ delete metadata.methods;
136
+ objectToJson(metadata);
137
+ })
138
+ const res = await broker.call("objects.addConfigs", { data: metadatas }, {
139
+ meta: {
140
+ metadataServiceName: serviceName,
141
+ caller: {
142
+ nodeID: broker.nodeID
143
+ }
144
+ }
145
+ });
146
+ return res;
147
+ }
148
+
149
+ /**
150
+ * 加载软件包下的所有元数据
151
+ * 1 在内存中合并所有对象元数据并发送: object.yml 、field.yml、.listview.yml、.button.yml、TODO .action.yml
152
+ * 2 TODO 其他元数据发送
153
+ * @param packagePath 软件包路径
154
+ * @param datasource 软件数据源
155
+ * @param serviceName 软件包服务名称
156
+ */
157
+ export const loadPackageMetadatas = async function (packagePath: string, datasource: string, serviceName?: string) {
158
+ let packageObjects = loadPackageObjects(packagePath);
159
+ const packageFields = loadPackageFields(packagePath);
160
+ const packageListviews = loadPackageListViews(packagePath);
161
+ const packageButtons = loadPackageButtons(packagePath);
162
+ const packageActions = loadPackageActions(packagePath);
163
+ const packageActionScripts = loadPackageActionScripts(packagePath);
164
+ const packagePermissions = loadPackagePermissions(packagePath);
165
+
166
+ const packageObjectApiNames = _.map(packageObjects, 'name');
167
+
168
+ packageObjects = _.map(packageObjects, (packageObject) => {
169
+ _.map(packageFields, (field) => {
170
+ if (field && field.object_name == packageObject.name) {
171
+ packageObject = _.defaultsDeep(packageObject, { fields: { [field.name]: field } }, packageObject);
172
+ }
173
+ })
174
+ _.map(packageListviews, (listview) => {
175
+ if (listview && listview.object_name == packageObject.name) {
176
+ packageObject = _.defaultsDeep(packageObject, { list_views: { [listview.name]: listview } }, packageObject);
177
+ }
178
+ })
179
+
180
+ _.map(packageButtons, (button) => {
181
+ if (button && button.object_name == packageObject.name) {
182
+ packageObject = _.defaultsDeep(packageObject, { actions: { [button.name]: button } }, packageObject);
183
+ }
184
+ })
185
+
186
+ _.map(packageActions, (action) => {
187
+ if (action && action.object_name == packageObject.name) {
188
+ packageObject = _.defaultsDeep(packageObject, { actions: action.actions }, packageObject);
189
+ }
190
+ })
191
+
192
+ _.map(packageActionScripts, (actionScript) => {
193
+ if (actionScript && actionScript.object_name == packageObject.name) {
194
+ packageObject = _.defaultsDeep(packageObject, { actions: actionScript.actions }, packageObject);
195
+ }
196
+ })
197
+
198
+ _.map(packagePermissions, (permission) => {
199
+ if (permission && permission.object_name == packageObject.name) {
200
+ packageObject = _.defaultsDeep(packageObject, { permission_set: { [permission.name]: permission } }, packageObject);
201
+ }
202
+ })
203
+ return packageObject;
204
+ })
205
+ for (const element of packageObjects) {
206
+ if (datasource) {
207
+ element.datasource = datasource
208
+ }
209
+ if (!element.extend) {
210
+ element.isMain = true;
211
+ }
212
+ let startNo = 10;
213
+ _.each(element.fields, function (field) {
214
+ if (!_.has(field, 'sort_no')) {
215
+ field.sort_no = startNo;
216
+ startNo = startNo + 10;
217
+ }
218
+ })
219
+ if (!element.fields) {
220
+ element.fields = {}
221
+ }
222
+ _.each(getLazyLoadFields(element.name), function (field) {
223
+ util.extend(element.fields, { [field.name]: field })
224
+ })
225
+ if (!element.actions) {
226
+ element.actions = {}
227
+ }
228
+ _.each(getLazyLoadButtons(element.name), function (action) {
229
+ util.extend(element.actions, { [action.name]: action })
230
+ })
231
+ let _mf = _.maxBy(_.values(element.fields), function (field) { return field.sort_no; });
232
+ if (_mf && element.name) {
233
+ element.fields_serial_number = _mf.sort_no + 10;
234
+ }
235
+ addObjectConfig(element, datasource, null);
236
+ }
237
+
238
+ loadObjectTriggers(packagePath);
239
+ //此功能不支持微服务模式
240
+ loadObjectMethods(packagePath);
241
+
242
+ await addObjectConfigs(getSteedosSchema().metadataBroker, serviceName, packageObjects);
243
+ if (serviceName) {
244
+ for await (const packageField of packageFields) {
245
+ if (packageField && !_.includes(packageObjectApiNames, packageField.object_name)) {
246
+
247
+ await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({ extend: packageField.object_name }, {
248
+ fields: {
249
+ [packageField.name]: packageField
250
+ }
251
+ }));
252
+ }
253
+ }
254
+
255
+ for await (const packageListview of packageListviews) {
256
+ if (packageListview && !_.includes(packageObjectApiNames, packageListview.object_name)) {
257
+ await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({ extend: packageListview.object_name }, {
258
+ list_views: {
259
+ [packageListview.name]: packageListview
260
+ }
261
+ }));
262
+ }
263
+ }
264
+
265
+ for await (const packageButton of packageButtons) {
266
+ if (packageButton && !_.includes(packageObjectApiNames, packageButton.object_name)) {
267
+ await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({ extend: packageButton.object_name }, {
268
+ actions: {
269
+ [packageButton.name]: packageButton
270
+ }
271
+ }));
272
+ }
273
+ }
274
+
275
+ for await (const packageAction of packageActions) {
276
+ if (packageAction && !_.includes(packageObjectApiNames, packageAction.object_name)) {
277
+ await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({ extend: packageAction.object_name }, {
278
+ actions: packageAction.actions
279
+ }));
280
+ }
281
+ }
282
+
283
+ for await (const packageActionScript of packageActionScripts) {
284
+ if (packageActionScript && !_.includes(packageObjectApiNames, packageActionScript.object_name)) {
285
+ await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({ extend: packageActionScript.object_name }, {
286
+ actions: packageActionScript.actions
287
+ }));
288
+ }
289
+ }
290
+
291
+ for await (const permission of packagePermissions) {
292
+ if (permission && !_.includes(packageObjectApiNames, permission.object_name)) {
293
+ await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({ extend: permission.object_name }, {
294
+ permission_set: {
295
+ [permission.name]: permission
296
+ }
297
+ }));
298
+ }
299
+ }
300
+ }
301
+
302
+ await registerPackageFieldPermissions(packagePath, getSteedosSchema().metadataBroker, packagePath)
303
+ }
@@ -6,12 +6,18 @@ const loadPageFile = new LoadPageFile();
6
6
  export const registerPackagePages = async (packagePath: string, packageServiceName: string)=>{
7
7
  const pages = loadPageFile.load(packagePath);
8
8
  const schema = getSteedosSchema();
9
+ const data = [];
9
10
  for (const apiName in pages) {
10
11
  const page = pages[apiName];
11
- await registerPage.register(schema.broker, packageServiceName, Object.assign(page, {is_system:true, record_permissions: {
12
+ data.push(Object.assign(page, {
13
+ is_system: true, record_permissions: {
12
14
  allowEdit: false,
13
15
  allowDelete: false,
14
16
  allowRead: true,
15
17
  }}))
18
+
19
+ }
20
+ if (data.length > 0) {
21
+ await registerPage.mregister(schema.broker, packageServiceName, data)
16
22
  }
17
23
  }
@@ -49,11 +49,7 @@ export const loadObjectPermissions = async function (filePath: string, serviceNa
49
49
  if(serviceName)
50
50
  for await (const permission of permissions) {
51
51
  const { field_permissions } = permission;
52
- delete permission.field_permissions;
53
- await getSteedosSchema().metadataRegister.addObjectConfig(serviceName, Object.assign({extend: permission.object_name}, {permission_set: {
54
- [permission.name]: permission
55
- }}));
56
- if (field_permissions) {
52
+ if (field_permissions && _.isArray(field_permissions) && field_permissions.length > 0) {
57
53
  for await (const field_permission of field_permissions) {
58
54
  await registerPermissionFields.register(getSteedosSchema().broker, serviceName, {
59
55
  "name": `${permission.name}.${permission.object_name}.${field_permission.field}`,
@@ -98,8 +98,7 @@ export const preloadDBPermissionFields = async function (datasource: SteedosData
98
98
  Creator.Collections[tableName] = Creator.createCollection({ name: tableName });
99
99
  }
100
100
  let records: any = await datasource.find(tableName, {});
101
-
102
- for await (const element of records) {
103
- await registerPermissionFields.register(schema.broker, `~database-${tableName}`, element);
101
+ if (records && records.length > 0) {
102
+ await registerPermissionFields.mregister(schema.broker, `~database-${tableName}`, records);
104
103
  }
105
104
  }
@@ -6,12 +6,17 @@ const loadQueryFile = new LoadQueryFile();
6
6
  export const registerPackageQueries = async (packagePath: string, packageServiceName: string)=>{
7
7
  const packageQueries = loadQueryFile.load(packagePath);
8
8
  const schema = getSteedosSchema();
9
+ const data = [];
9
10
  for (const apiName in packageQueries) {
10
11
  const query = packageQueries[apiName];
11
- await registerQuery.register(schema.broker, packageServiceName, Object.assign(query, {is_system:true, record_permissions: {
12
+ data.push(Object.assign(query, {
13
+ is_system: true, record_permissions: {
12
14
  allowEdit: false,
13
15
  allowDelete: false,
14
16
  allowRead: true,
15
17
  }}))
16
18
  }
19
+ if (data.length > 0) {
20
+ await registerQuery.mregister(schema.broker, packageServiceName, data)
21
+ }
17
22
  }
@@ -6,14 +6,18 @@ const loadRestrictionRules = new LoadRestrictionRules();
6
6
  export const registerPackageRestrictionRules = async (packagePath: string, packageServiceName: string) => {
7
7
  const metadata = loadRestrictionRules.load(packagePath);
8
8
  const schema = getSteedosSchema();
9
+ const data = [];
9
10
  for (const apiName in metadata) {
10
11
  const item = metadata[apiName];
11
- await registerRestrictionRules.register(schema.broker, packageServiceName, Object.assign(item, {
12
+ data.push(Object.assign(item, {
12
13
  is_system: true, record_permissions: {
13
14
  allowEdit: false,
14
15
  allowDelete: false,
15
16
  allowRead: true,
16
17
  }
17
- }))
18
+ }));
19
+ }
20
+ if (data.length > 0) {
21
+ await registerRestrictionRules.mregister(schema.broker, packageServiceName, data)
18
22
  }
19
23
  }
@@ -6,9 +6,10 @@ const loadShareRules = new LoadShareRules();
6
6
  export const registerPackageShareRules = async (packagePath: string, packageServiceName: string) => {
7
7
  const metadata = loadShareRules.load(packagePath);
8
8
  const schema = getSteedosSchema();
9
+ const data = [];
9
10
  for (const apiName in metadata) {
10
11
  const item = metadata[apiName];
11
- await registerShareRules.register(schema.broker, packageServiceName, Object.assign(item, {
12
+ data.push(Object.assign(item, {
12
13
  is_system: true, record_permissions: {
13
14
  allowEdit: false,
14
15
  allowDelete: false,
@@ -16,4 +17,7 @@ export const registerPackageShareRules = async (packagePath: string, packageServ
16
17
  }
17
18
  }))
18
19
  }
20
+ if (data.length > 0) {
21
+ await registerShareRules.mregister(schema.broker, packageServiceName, data)
22
+ }
19
23
  }
@@ -43,7 +43,9 @@ export const addTranslationsFiles = async (filePath: string)=>{
43
43
  console.error(`addTranslation error`, error.message)
44
44
  }
45
45
  }
46
- await brokeEmitEvents(filePath)
46
+ if (translations && translations.length > 0) {
47
+ await brokeEmitEvents(filePath)
48
+ }
47
49
  }
48
50
 
49
51
  export const getTranslations = async ()=>{
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './types'
2
2
  export * from "./driver"
3
- export * from "./graphql"
4
3
  export * from "./util"
5
4
  export * from "./formula"
6
5
  export * from "./summary"
@@ -26,6 +26,29 @@ export class RegisterBase{
26
26
  return res;
27
27
  }
28
28
 
29
+ async mregister(broker, packageServiceName, configs) {
30
+ const metadatas = clone(configs);
31
+
32
+ const mdata = {};
33
+
34
+ _.map(metadatas, (metadata) => {
35
+ mdata[this.getApiName(metadata)] = metadata
36
+ })
37
+
38
+ const res = await broker.call(`${this.serviceName}.madd`, { data: mdata }, {
39
+ meta: {
40
+ metadataServiceName: packageServiceName,
41
+ caller: {
42
+ nodeID: broker.nodeID,
43
+ service: {
44
+ name: packageServiceName,
45
+ }
46
+ }
47
+ }
48
+ });
49
+ return res;
50
+ }
51
+
29
52
  async remove(broker, packageServiceName, metadataApiNameOrConfig: string | JsonMap) {
30
53
  let metadataApiName = metadataApiNameOrConfig;
31
54
  if (_.isObject(metadataApiName)) {
@@ -1,7 +1,5 @@
1
- // import { createObjectService } from './objectServiceManager';
2
- // import { getObjectServiceName } from '../services/index';
3
1
  import * as _ from 'underscore';
4
- import { objectToJson } from '../util';
2
+ import { objectToJson, jsonToObject } from '../util/convert';
5
3
  const clone = require('clone');
6
4
 
7
5
  export async function registerObject(broker, serviceName, objectConfig) {
@@ -67,21 +65,4 @@ export async function removeObject(broker, objectApiName) {
67
65
  }
68
66
  }});
69
67
  return res;
70
- }
71
-
72
- function funEval (funStr){
73
- try{
74
- return eval(funStr)
75
- }catch (e){
76
- console.error(e, funStr);
77
- }
78
- };
79
-
80
- export function jsonToObject(objectMetadata){
81
- _.forEach(objectMetadata.fields, (field, key)=>{
82
- const _reference_to = field._reference_to;
83
- if(_reference_to && _.isString(_reference_to)){
84
- field.reference_to = funEval(`(${_reference_to})`);
85
- }
86
- })
87
68
  }
@@ -0,0 +1,37 @@
1
+ import * as _ from 'underscore';
2
+ import { getDataSourceServiceName } from './index';
3
+ import { jsonToObject } from '../util/convert';
4
+ const LocalDataSourceServices = {};
5
+
6
+
7
+ export async function createDataSourceService(broker, dataSource) {
8
+ const dataSourceName = dataSource.name;
9
+ const serviceName = getDataSourceServiceName(dataSourceName);
10
+
11
+ if (LocalDataSourceServices[serviceName]) {
12
+ return;
13
+ }
14
+
15
+ let service = broker.createService({
16
+ name: serviceName,
17
+ events: {
18
+ [`${dataSourceName}.*.metadata.objects.inserted`]: {
19
+ handler(ctx) {
20
+ let objectConfig = ctx.params.data;
21
+ jsonToObject(objectConfig)
22
+ dataSource.initObject(objectConfig)
23
+ /**
24
+ * 每次都需要初始化,TypeORM不适用于微服务模式
25
+ */
26
+ dataSource.initTypeORM();
27
+ }
28
+ }
29
+ }
30
+ })
31
+ if (!broker.started) { //如果broker未启动则手动启动service
32
+ await broker._restartService(service)
33
+ }
34
+ await broker.waitForServices(service.name, null, 10);
35
+ LocalDataSourceServices[serviceName] = true;
36
+ return service
37
+ }
@@ -260,9 +260,11 @@ export async function dealWithRelatedFields(
260
260
  let steedosSchema = getSteedosSchema();
261
261
  let objectName = objectConfig.name;
262
262
  let obj = steedosSchema.getObject(objectName);
263
- // 拆开 使用单独的promise处理
264
- let detailsInfo = await obj.getDetailsInfo();
265
- let lookupsInfo = await obj.getLookupDetailsInfo();
263
+
264
+ const relationsInfo = await obj.getRelationsInfo();
265
+ let detailsInfo = relationsInfo.details || [];
266
+ let lookupsInfo = relationsInfo.lookup_details || [];
267
+
266
268
  let relatedInfos = detailsInfo.concat(lookupsInfo);
267
269
  for (const info of relatedInfos) {
268
270
  if (!info.startsWith("__")) {
@@ -1,6 +1,13 @@
1
1
  export * from './objectServiceDispatcher';
2
2
  export * from './objectService';
3
3
 
4
+ export * from './datasourceServiceFactory';
5
+ export * from './objectServiceFactory';
6
+
4
7
  export function getObjectServiceName(objectApiName: string){
5
8
  return `@${objectApiName}`;
9
+ }
10
+
11
+ export function getDataSourceServiceName(dataSource: string) {
12
+ return `~dataSource-${dataSource}`;
6
13
  }
@@ -4,7 +4,7 @@ import { getObjectConfig } from '../types/object_dynamic_load';
4
4
  import _ = require('underscore');
5
5
  import { generateActionRestProp, generateActionGraphqlProp, generateSettingsGraphql, RELATED_PREFIX, _getRelatedType, correctName, getGraphqlActions, getRelatedResolver, dealWithRelatedFields } from './helpers';
6
6
  import { getObjectServiceName } from '.';
7
- import { jsonToObject } from '../metadata-register/object';
7
+ import { jsonToObject } from '../util/convert';
8
8
  import { extend } from '../util';
9
9
  const Future = require('fibers/future');
10
10
  // import { parse } from '@steedos/formula';
@@ -148,8 +148,8 @@ function getObjectServiceMethodsSchema() {
148
148
  }
149
149
  },
150
150
  getRecordView: {
151
- async handler(userSession) {
152
- return await this.object.getRecordView(userSession);
151
+ async handler(userSession, context?) {
152
+ return await this.object.getRecordView(userSession, context);
153
153
  }
154
154
  },
155
155
  createDefaulRecordView: {
@@ -472,7 +472,8 @@ function getObjectServiceActionsSchema() {
472
472
  },
473
473
  async handler(ctx) {
474
474
  const userSession = ctx.meta.user;
475
- return await this.getRecordView(userSession);
475
+ const { context } = ctx.params;
476
+ return await this.getRecordView(userSession, context);
476
477
  }
477
478
  },
478
479
  createDefaulRecordView: {
@@ -616,9 +617,10 @@ module.exports = {
616
617
  resolvers[objectApiName][relatedFieldName] = getRelatedResolver(objectApiName, detailObjectApiName, detailFieldName, detailFieldReferenceToFieldName);
617
618
  }
618
619
  };
619
- schema.events[`${getObjectServiceName(objectConfig.name)}.metadata.objects.inserted`] = {
620
+ schema.events[`${objectConfig.datasource}.${getObjectServiceName(objectConfig.name)}.metadata.objects.inserted`] = {
620
621
  handler: async function (ctx) {
621
622
  let objectConfig = ctx.params.data;
623
+ // console.log(`${objectConfig.datasource}.${getObjectServiceName(objectConfig.name)}.metadata.objects.inserted`);
622
624
  // 对象发生变化时,重新创建Steedos Object 对象
623
625
  const datasource = getDataSource(objectConfig.datasource);
624
626
  if (datasource) {
@@ -638,13 +640,13 @@ module.exports = {
638
640
  await datasource.init();
639
641
  }
640
642
 
641
- if(datasource.name === 'meteor' && Creator.Objects[objectConfig.name]){
643
+ if (datasource.name === 'meteor' && Creator.Objects[objectConfig.name]) {
642
644
  jsonToObject(objectConfig);
643
645
  const localTriggers = (localObjectConfig as any).triggers;
644
646
  if(localTriggers){
645
647
  objectConfig.triggers = localTriggers;
646
648
  }
647
- extend(objectConfig, {triggers: (localObjectConfig as any)._baseTriggers})
649
+ extend(objectConfig, { triggers: Creator.Objects[objectConfig.name].triggers }, { triggers: (localObjectConfig as any)._baseTriggers })
648
650
  Creator.Objects[objectConfig.name] = objectConfig;
649
651
 
650
652
  await Future.task(() => {
@@ -159,6 +159,10 @@ class ObjectServiceDispatcher {
159
159
  return await this.callMetadataObjectServiceAction(`getLookupDetailsInfo`, {objectApiName: this.objectApiName});
160
160
  }
161
161
 
162
+ async getRelationsInfo() {
163
+ return await this.callMetadataObjectServiceAction(`getRelationsInfo`, { objectApiName: this.objectApiName });
164
+ }
165
+
162
166
  async getDetailPaths(){
163
167
  return await this.callMetadataObjectServiceAction(`getDetailPaths`, {objectApiName: this.objectApiName});
164
168
  }
@@ -179,8 +183,8 @@ class ObjectServiceDispatcher {
179
183
  return await this.callAction(`getRecordPermissions`, {record, userSession});
180
184
  }
181
185
 
182
- async getRecordView(userSession){
183
- return await this.callAction(`getRecordView`, {userSession});
186
+ async getRecordView(userSession, context?) {
187
+ return await this.callAction(`getRecordView`, { userSession, context });
184
188
  }
185
189
 
186
190
  async createDefaulRecordView(userSession){
@@ -1,17 +1,17 @@
1
1
  import * as _ from 'underscore';
2
- import { getObjectServiceName } from '../services/index';
2
+ import { getObjectServiceName } from './index';
3
3
  const objectService = require('../services/objectService');
4
4
 
5
5
  const LocalObjectServices = {};
6
6
 
7
- function onDestroyObjectService(objectApiName){
7
+ function onDestroyObjectService(objectApiName) {
8
8
  const serviceName = getObjectServiceName(objectApiName);
9
9
  delete LocalObjectServices[serviceName]
10
10
  }
11
11
 
12
12
  export async function createObjectService(broker, serviceName, objectConfig) {
13
- if(LocalObjectServices[serviceName]){
14
- return ;
13
+ if (LocalObjectServices[serviceName]) {
14
+ return;
15
15
  }
16
16
  let service = broker.createService({
17
17
  name: serviceName,