@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,130 @@
1
+ import * as _ from 'lodash';
2
+
3
+ function funEval(funStr) {
4
+ try {
5
+ return eval(funStr)
6
+ } catch (e) {
7
+ console.error(e, funStr);
8
+ }
9
+ };
10
+
11
+ export function jsonToObject(objectMetadata) {
12
+ _.forEach(objectMetadata.fields, (field, key) => {
13
+ const _reference_to = field._reference_to;
14
+ if (_reference_to && _.isString(_reference_to)) {
15
+ field.reference_to = funEval(`(${_reference_to})`);
16
+ }
17
+ })
18
+ }
19
+
20
+ export function objectToJson(objectConfig) {
21
+ _.forEach(objectConfig.actions, (action, key) => {
22
+ const _todo = action?.todo
23
+ if (_todo && _.isFunction(_todo)) {
24
+ action.todo = _todo.toString()
25
+ }
26
+ const _visible = action?.visible
27
+ if (_visible && _.isFunction(_visible)) {
28
+ action._visible = _visible.toString()
29
+ }
30
+ })
31
+
32
+ _.forEach(objectConfig.fields, (field, key) => {
33
+
34
+ const options = field.options
35
+ if (options && _.isFunction(options)) {
36
+ field._options = field.options.toString()
37
+ }
38
+
39
+ if (field.regEx) {
40
+ field._regEx = field.regEx.toString();
41
+ }
42
+ if (_.isFunction(field.min)) {
43
+ field._min = field.min.toString();
44
+ }
45
+ if (_.isFunction(field.max)) {
46
+ field._max = field.max.toString();
47
+ }
48
+ if (field.autoform) {
49
+ const _type = field.autoform.type;
50
+ if (_type && _.isFunction(_type) && _type != Object && _type != String && _type != Number && _type != Boolean && !_.isArray(_type)) {
51
+ field.autoform._type = _type.toString();
52
+ }
53
+ }
54
+ const optionsFunction = field.optionsFunction;
55
+ const reference_to = field.reference_to;
56
+ const createFunction = field.createFunction;
57
+ const beforeOpenFunction = field.beforeOpenFunction;
58
+ const filtersFunction = field.filtersFunction;
59
+ if (optionsFunction && _.isFunction(optionsFunction)) {
60
+ field._optionsFunction = optionsFunction.toString()
61
+ }
62
+ if (reference_to && _.isFunction(reference_to)) {
63
+ field._reference_to = reference_to.toString()
64
+ }
65
+ if (createFunction && _.isFunction(createFunction)) {
66
+ field._createFunction = createFunction.toString()
67
+ }
68
+ if (beforeOpenFunction && _.isFunction(beforeOpenFunction)) {
69
+ field._beforeOpenFunction = beforeOpenFunction.toString()
70
+ }
71
+ if (filtersFunction && _.isFunction(filtersFunction)) {
72
+ field._filtersFunction = filtersFunction.toString()
73
+ }
74
+
75
+
76
+ const defaultValue = field.defaultValue
77
+ if (defaultValue && _.isFunction(defaultValue)) {
78
+ field._defaultValue = field.defaultValue.toString()
79
+ }
80
+
81
+ const is_company_limited = field.is_company_limited;
82
+ if (is_company_limited && _.isFunction(is_company_limited)) {
83
+ field._is_company_limited = field.is_company_limited.toString()
84
+ }
85
+ })
86
+
87
+ _.forEach(objectConfig.list_views, (list_view, key) => {
88
+ if (_.isFunction(list_view.filters)) {
89
+ list_view._filters = list_view.filters.toString()
90
+ } else if (_.isArray(list_view.filters)) {
91
+ _.forEach(list_view.filters, (filter: any, _index) => {
92
+ if (_.isArray(filter)) {
93
+ if (filter.length == 3 && _.isFunction(filter[2])) {
94
+ filter[2] = filter[2].toString()
95
+ filter[3] = "FUNCTION"
96
+ } else if (filter.length == 3 && _.isDate(filter[2])) {
97
+ filter[3] = "DATE"
98
+ }
99
+ } else if (_.isObject(filter)) {
100
+ if (_.isFunction((filter as any)?.value)) {
101
+ (filter as any)._value = (filter as any).value.toString()
102
+ } else if (_.isDate((filter as any)?.value)) {
103
+ (filter as any)._is_date = true
104
+ }
105
+ }
106
+ })
107
+ }
108
+ })
109
+
110
+ if (objectConfig.form && !_.isString(objectConfig.form)) {
111
+ objectConfig.form = JSON.stringify(objectConfig.form, (key, val) => {
112
+ if (_.isFunction(val))
113
+ return val + '';
114
+ else
115
+ return val;
116
+ })
117
+ }
118
+
119
+ _.forEach(objectConfig.relatedList, (relatedObjInfo) => {
120
+ if (_.isObject(relatedObjInfo)) {
121
+ _.forEach(relatedObjInfo, (val: any, key) => {
122
+ if (key == 'filters' && _.isFunction(val)) {
123
+ relatedObjInfo[key] = val.toString();
124
+ }
125
+ })
126
+ }
127
+ })
128
+
129
+ return objectConfig;
130
+ }
package/src/util/index.ts CHANGED
@@ -28,6 +28,7 @@ export * from './suffix'
28
28
  export * from './locale'
29
29
  export * from './field'
30
30
  export * from './function_expression'
31
+ export * from './convert'
31
32
 
32
33
  exports.loadJSONFile = (filePath: string)=>{
33
34
  return JSON.parse(fs.readFileSync(filePath, 'utf8').normalize('NFC'));
@@ -571,7 +572,7 @@ export function extend(destination: JsonMap, ...sources: JsonMap[]){
571
572
  }else if(isJsonMap(v)){
572
573
  let _d = getJsonMap(destination, k);
573
574
  if(isJsonMap(_d)){
574
- destination[k] = this.extend(clone(_d), v)
575
+ destination[k] = extend(clone(_d), v)
575
576
  }else{
576
577
  destination[k] = v
577
578
  }
@@ -682,7 +683,7 @@ export function getSteedosConfig(){
682
683
  let config: any;
683
684
  let configPath = path.join(getBaseDirectory(), configName)
684
685
  if (fs.existsSync(configPath) && !fs.statSync(configPath).isDirectory()) {
685
- config = this.loadFile(configPath)
686
+ config = loadFile(configPath)
686
687
  if (config.env){
687
688
  _.each(config.env, function(item, key){
688
689
  process.env[key] = calcString(item)
@@ -951,128 +952,13 @@ export function absoluteUrl (path, options?) {
951
952
  return url;
952
953
  }
953
954
 
954
- /**
955
- * 对objectConfig中的function属性做toString()处理
956
- * This method mutates objectConfig.
957
- * @param objectConfig
958
- * @returns objectConfig
959
- */
960
- export function objectToJson(objectConfig){
961
- _.forEach(objectConfig.actions, (action, key)=>{
962
- const _todo = action?.todo
963
- if(_todo && _.isFunction(_todo)){
964
- action.todo = _todo.toString()
965
- }
966
- const _visible = action?.visible
967
- if(_visible && _.isFunction(_visible)){
968
- action._visible = _visible.toString()
969
- }
970
- })
971
-
972
- _.forEach(objectConfig.fields, (field, key)=>{
973
-
974
- const options = field.options
975
- if(options && _.isFunction(options)){
976
- field._options = field.options.toString()
977
- }
978
-
979
- if(field.regEx){
980
- field._regEx = field.regEx.toString();
981
- }
982
- if(_.isFunction(field.min)){
983
- field._min = field.min.toString();
984
- }
985
- if(_.isFunction(field.max)){
986
- field._max = field.max.toString();
987
- }
988
- if(field.autoform){
989
- const _type = field.autoform.type;
990
- if(_type && _.isFunction(_type) && _type != Object && _type != String && _type != Number && _type != Boolean && !_.isArray(_type)){
991
- field.autoform._type = _type.toString();
992
- }
993
- }
994
- const optionsFunction = field.optionsFunction;
995
- const reference_to = field.reference_to;
996
- const createFunction = field.createFunction;
997
- const beforeOpenFunction = field.beforeOpenFunction;
998
- const filtersFunction = field.filtersFunction;
999
- if(optionsFunction && _.isFunction(optionsFunction)){
1000
- field._optionsFunction = optionsFunction.toString()
1001
- }
1002
- if(reference_to && _.isFunction(reference_to)){
1003
- field._reference_to = reference_to.toString()
1004
- }
1005
- if(createFunction && _.isFunction(createFunction)){
1006
- field._createFunction = createFunction.toString()
1007
- }
1008
- if(beforeOpenFunction && _.isFunction(beforeOpenFunction)){
1009
- field._beforeOpenFunction = beforeOpenFunction.toString()
1010
- }
1011
- if(filtersFunction && _.isFunction(filtersFunction)){
1012
- field._filtersFunction = filtersFunction.toString()
1013
- }
1014
-
1015
-
1016
- const defaultValue = field.defaultValue
1017
- if(defaultValue && _.isFunction(defaultValue)){
1018
- field._defaultValue = field.defaultValue.toString()
1019
- }
1020
-
1021
- const is_company_limited = field.is_company_limited;
1022
- if(is_company_limited && _.isFunction(is_company_limited)){
1023
- field._is_company_limited = field.is_company_limited.toString()
1024
- }
1025
- })
1026
-
1027
- _.forEach(objectConfig.list_views, (list_view, key)=>{
1028
- if(_.isFunction(list_view.filters)){
1029
- list_view._filters = list_view.filters.toString()
1030
- }else if(_.isArray(list_view.filters)){
1031
- _.forEach(list_view.filters, (filter, _index)=>{
1032
- if(_.isArray(filter)){
1033
- if(filter.length == 3 && _.isFunction(filter[2])){
1034
- filter[2] = filter[2].toString()
1035
- filter[3] = "FUNCTION"
1036
- }else if(filter.length == 3 && _.isDate(filter[2])){
1037
- filter[3] = "DATE"
1038
- }
1039
- }else if(_.isObject(filter)){
1040
- if(_.isFunction(filter?.value)){
1041
- filter._value = filter.value.toString()
1042
- }else if(_.isDate(filter?.value)){
1043
- filter._is_date = true
1044
- }
1045
- }
1046
- })
1047
- }
1048
- })
1049
-
1050
- if(objectConfig.form && !_.isString(objectConfig.form)){
1051
- objectConfig.form = JSON.stringify(objectConfig.form, (key, val)=>{
1052
- if(_.isFunction(val))
1053
- return val + '';
1054
- else
1055
- return val;
1056
- })
1057
- }
1058
-
1059
- _.forEach(objectConfig.relatedList, (relatedObjInfo)=>{
1060
- if(_.isObject(relatedObjInfo)){
1061
- _.forEach(relatedObjInfo, (val, key)=>{
1062
- if(key == 'filters' && _.isFunction(val)){
1063
- relatedObjInfo[key] = val.toString();
1064
- }
1065
- })
1066
- }
1067
- })
1068
-
1069
- return objectConfig;
1070
- }
1071
-
1072
955
  export function validateFilters(filters: [], objectFields: any) {
1073
956
  processFilters(clone(filters), objectFields);
1074
957
  }
1075
958
 
959
+ export async function sleep(ms) {
960
+ return new Promise(resolve => setTimeout(resolve, ms));
961
+ }
1076
962
 
1077
963
  export function parserFilters(filters){
1078
964
  if(_.isString(filters)){
@@ -1,3 +0,0 @@
1
- import { SteedosSchema, SteedosDataSourceType } from "../types";
2
- import { GraphQLSchema } from 'graphql';
3
- export declare function buildGraphQLSchema(steedosSchema: SteedosSchema, datasource?: SteedosDataSourceType): GraphQLSchema;
@@ -1,374 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildGraphQLSchema = void 0;
4
- var tslib_1 = require("tslib");
5
- var graphql_1 = require("graphql");
6
- var _ = require("underscore");
7
- var mongodb_1 = require("mongodb");
8
- var GraphQLJSON = require('graphql-type-json');
9
- var utils_1 = require("./utils");
10
- var graphql_iso_date_1 = require("graphql-iso-date");
11
- /** Maps basic creator field types to basic GraphQL types */
12
- var BASIC_TYPE_MAPPING = {
13
- 'text': graphql_1.GraphQLString,
14
- 'textarea': graphql_1.GraphQLString,
15
- 'html': graphql_1.GraphQLString,
16
- 'select': graphql_1.GraphQLString,
17
- 'url': graphql_1.GraphQLString,
18
- 'email': graphql_1.GraphQLString,
19
- 'date': graphql_iso_date_1.GraphQLDate,
20
- 'datetime': graphql_iso_date_1.GraphQLDateTime,
21
- 'number': graphql_1.GraphQLFloat,
22
- 'currency': graphql_1.GraphQLFloat,
23
- 'boolean': graphql_1.GraphQLBoolean
24
- };
25
- var knownTypes = {};
26
- var relatedObjects = {};
27
- var RELATEDPREFIX = 'related__';
28
- var LABELSUFFIX = '__label';
29
- function convertFields(steedosSchema, fields, knownTypes) {
30
- var objTypeFields = {};
31
- objTypeFields["_id"] = {
32
- type: graphql_1.GraphQLString
33
- };
34
- _.each(fields, function (v, k) {
35
- if (k.indexOf('.') > -1) {
36
- return;
37
- }
38
- if (!v.type) {
39
- console.error("The field " + k + " has no type property.");
40
- return;
41
- }
42
- if (BASIC_TYPE_MAPPING[v.type]) {
43
- objTypeFields[k] = { type: BASIC_TYPE_MAPPING[v.type] };
44
- }
45
- else if ((v.type == 'lookup' || v.type == 'master_detail') && v.reference_to && _.isString(v.reference_to)) {
46
- var objectName_1 = v.reference_to;
47
- var corName = correctName(objectName_1);
48
- if (!knownTypes[corName]) {
49
- try {
50
- var object = steedosSchema.getObject(objectName_1);
51
- if (object) {
52
- knownTypes[corName] = buildGraphQLObjectType(object, steedosSchema, knownTypes);
53
- }
54
- }
55
- catch (error) {
56
- console.error(error);
57
- return;
58
- }
59
- }
60
- objTypeFields[k] = {
61
- type: knownTypes[corName],
62
- args: {},
63
- resolve: function (source, args, context, info) {
64
- return tslib_1.__awaiter(this, void 0, void 0, function () {
65
- var object, userSession, record;
66
- return tslib_1.__generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0:
69
- object = steedosSchema.getObject(objectName_1);
70
- userSession = context ? context.user : null;
71
- if (object.name == 'users') {
72
- userSession = null;
73
- }
74
- return [4 /*yield*/, object.findOne(source[info.fieldName], {}, userSession)];
75
- case 1:
76
- record = _a.sent();
77
- return [2 /*return*/, record];
78
- }
79
- });
80
- });
81
- }
82
- };
83
- if (v.type == 'lookup' && v.multiple) {
84
- objTypeFields[k].type = new graphql_1.GraphQLList(knownTypes[corName]);
85
- objTypeFields[k].resolve = function (source, args, context, info) {
86
- return tslib_1.__awaiter(this, void 0, void 0, function () {
87
- var object, filters, userSession;
88
- return tslib_1.__generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0:
91
- object = steedosSchema.getObject(objectName_1);
92
- filters = [];
93
- _.each(source[info.fieldName], function (f) {
94
- filters.push("(_id eq '" + f + "')");
95
- });
96
- if (filters.length === 0) {
97
- return [2 /*return*/, null];
98
- }
99
- userSession = context ? context.user : null;
100
- if (object.name == 'users') {
101
- userSession = null;
102
- }
103
- return [4 /*yield*/, object.find({
104
- filters: filters.join(' or ')
105
- }, userSession)];
106
- case 1: return [2 /*return*/, _a.sent()];
107
- }
108
- });
109
- });
110
- };
111
- }
112
- }
113
- else if (v.type == RELATEDPREFIX) {
114
- var corName_1 = v.reference_to;
115
- var objName = v.objectName;
116
- if (!knownTypes[objName]) {
117
- var object = steedosSchema.getObject(objName);
118
- if (object) {
119
- knownTypes[objName] = buildGraphQLObjectType(object, steedosSchema, knownTypes);
120
- }
121
- }
122
- objTypeFields[k] = {
123
- type: new graphql_1.GraphQLList(knownTypes[objName]),
124
- args: { 'fields': { type: new graphql_1.GraphQLList(graphql_1.GraphQLString) || graphql_1.GraphQLString }, 'filters': { type: GraphQLJSON }, 'top': { type: graphql_1.GraphQLInt }, 'skip': { type: graphql_1.GraphQLInt }, 'sort': { type: graphql_1.GraphQLString } },
125
- resolve: function (source, args, context, info) {
126
- return tslib_1.__awaiter(this, void 0, void 0, function () {
127
- var field, referenceToField, relatedObjName, object, userSession, filters, _idValue;
128
- return tslib_1.__generator(this, function (_a) {
129
- field = relatedObjects[corName_1].fields[info.fieldName];
130
- referenceToField = field.reference_to_field;
131
- relatedObjName = field.objectName;
132
- object = steedosSchema.getObject(relatedObjName);
133
- userSession = context ? context.user : null;
134
- filters = [];
135
- _idValue = source._id;
136
- if (referenceToField) {
137
- _idValue = source[referenceToField];
138
- }
139
- if (field.by_enabled) {
140
- filters = [[field.name + ".o", "=", corName_1], [field.name + ".ids", "=", source._id]];
141
- }
142
- else {
143
- filters = [[field.name, "=", _idValue]];
144
- }
145
- if (args && args.filters) {
146
- filters.push(args.filters);
147
- }
148
- args.filters = filters;
149
- return [2 /*return*/, object.find(args, userSession)];
150
- });
151
- });
152
- }
153
- };
154
- }
155
- else if (v.type == LABELSUFFIX) {
156
- objTypeFields[k] = {
157
- type: GraphQLJSON,
158
- resolve: function (source, args, context, info) {
159
- // let field = relatedObjects[info.parentType.name].fields[info.fieldName];
160
- // return getFieldLabel(field, source[field.name], userSession);
161
- var userSession = context ? context.user : null;
162
- var objectName = info.parentType.name;
163
- var fieldName = info.fieldName;
164
- var field = relatedObjects[objectName].fields[fieldName];
165
- var fieldValue = source[field.name];
166
- var relatedFields = relatedObjects[objectName].fields;
167
- var object = steedosSchema.getObject(objectName);
168
- return utils_1.getFieldLabel(fieldName, fieldValue, relatedFields, object, userSession);
169
- }
170
- };
171
- }
172
- else {
173
- objTypeFields[k] = {
174
- type: GraphQLJSON
175
- };
176
- }
177
- });
178
- return objTypeFields;
179
- }
180
- function correctName(name) {
181
- return name.replace(/\./g, '_');
182
- }
183
- function buildGraphQLObjectType(obj, steedosSchema, knownTypes) {
184
- var corName = correctName(obj.name);
185
- var relatedFields = relatedObjects[corName].fields;
186
- return new graphql_1.GraphQLObjectType({
187
- name: corName, fields: function () {
188
- return convertFields(steedosSchema, _.extend({}, obj.fields, relatedFields), knownTypes);
189
- }
190
- });
191
- }
192
- function collectRelatedObjects(steedosSchema) {
193
- _.each(steedosSchema.getDataSources(), function (datasource) {
194
- _.each(datasource.getObjects(), function (obj, object_name) {
195
- if (!obj.name || !obj.fields) {
196
- return;
197
- }
198
- var objName = correctName(obj.name);
199
- if (!relatedObjects[objName]) {
200
- relatedObjects[objName] = { fields: {} };
201
- }
202
- _.each(obj.fields, function (v, k) {
203
- if (v.type == 'master_detail' && v.reference_to && _.isString(v.reference_to)) {
204
- var refName = correctName(v.reference_to);
205
- if (!relatedObjects[refName]) {
206
- relatedObjects[refName] = { fields: {} };
207
- }
208
- relatedObjects[refName].fields["" + RELATEDPREFIX + objName] = {
209
- type: RELATEDPREFIX,
210
- reference_to: refName,
211
- reference_to_field: v.reference_to_field,
212
- name: k,
213
- objectName: objName
214
- };
215
- }
216
- else if (['boolean', 'date', 'datetime', 'select', 'percent'].includes(v.type)) {
217
- relatedObjects[objName].fields["" + k + LABELSUFFIX] = {
218
- type: LABELSUFFIX,
219
- name: k,
220
- dataType: v.type,
221
- options: v.options,
222
- multiple: v.multiple
223
- };
224
- }
225
- });
226
- var enabledRefNames = [];
227
- if (obj.enable_files) {
228
- enabledRefNames.push('cms_files');
229
- }
230
- if (obj.enable_tasks) {
231
- enabledRefNames.push('tasks');
232
- }
233
- if (obj.enable_events) {
234
- enabledRefNames.push('events');
235
- }
236
- if (obj.enable_audit) {
237
- enabledRefNames.push('audit_records');
238
- }
239
- _.forEach(enabledRefNames, function (refName) {
240
- relatedObjects[objName].fields["" + RELATEDPREFIX + refName] = {
241
- type: RELATEDPREFIX,
242
- reference_to: objName,
243
- name: refName == 'cms_files' ? 'parent' : 'related_to',
244
- objectName: refName,
245
- by_enabled: true // 通过enable方式关联的子表打上标记供查询时判断
246
- };
247
- });
248
- });
249
- });
250
- }
251
- function buildGraphQLSchema(steedosSchema, datasource) {
252
- collectRelatedObjects(steedosSchema);
253
- var rootQueryfields = {};
254
- _.each(steedosSchema.getDataSources(), function (datasource) {
255
- _.each(datasource.getObjects(), function (obj, object_name) {
256
- if (!obj.name) {
257
- return;
258
- }
259
- var corName = correctName(obj.name);
260
- var objName = correctName(obj.name);
261
- knownTypes[objName] = buildGraphQLObjectType(obj, steedosSchema, knownTypes);
262
- rootQueryfields[corName] = {
263
- type: new graphql_1.GraphQLList(knownTypes[objName]),
264
- args: { 'fields': { type: new graphql_1.GraphQLList(graphql_1.GraphQLString) || graphql_1.GraphQLString }, 'filters': { type: GraphQLJSON }, 'top': { type: graphql_1.GraphQLInt }, 'skip': { type: graphql_1.GraphQLInt }, 'sort': { type: graphql_1.GraphQLString } },
265
- resolve: function (source, args, context, info) {
266
- return tslib_1.__awaiter(this, void 0, void 0, function () {
267
- var object, userSession;
268
- return tslib_1.__generator(this, function (_a) {
269
- object = steedosSchema.getObject("" + obj.name);
270
- userSession = context ? context.user : null;
271
- return [2 /*return*/, object.find(args, userSession)];
272
- });
273
- });
274
- }
275
- };
276
- });
277
- });
278
- var rootMutationfields = {};
279
- _.each(rootQueryfields, function (type, objName) {
280
- rootMutationfields[objName + '__insert'] = {
281
- type: knownTypes[objName],
282
- args: { 'data': { type: new graphql_1.GraphQLNonNull(GraphQLJSON) || new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } },
283
- resolve: function (source, args, context, info) {
284
- return tslib_1.__awaiter(this, void 0, void 0, function () {
285
- var data, object, userSession;
286
- return tslib_1.__generator(this, function (_a) {
287
- data = '';
288
- if (_.isString(args['data'])) {
289
- data = JSON.parse(args['data']);
290
- }
291
- else {
292
- data = JSON.parse(JSON.stringify(args['data']));
293
- }
294
- data._id = data._id || new mongodb_1.ObjectId().toHexString();
295
- object = steedosSchema.getObject("" + type.type.ofType.name);
296
- userSession = context ? context.user : null;
297
- if (userSession && object.getField('space')) {
298
- data.space = userSession.spaceId;
299
- }
300
- return [2 /*return*/, object.insert(data, userSession)];
301
- });
302
- });
303
- }
304
- };
305
- rootMutationfields[objName + '__update'] = {
306
- type: knownTypes[objName],
307
- args: { '_id': { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, 'selector': { type: GraphQLJSON }, 'data': { type: new graphql_1.GraphQLNonNull(GraphQLJSON) || new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } },
308
- resolve: function (source, args, context, info) {
309
- return tslib_1.__awaiter(this, void 0, void 0, function () {
310
- var data, _id, object, userSession;
311
- return tslib_1.__generator(this, function (_a) {
312
- data = '';
313
- if (_.isString(args['data'])) {
314
- data = JSON.parse(args['data']);
315
- }
316
- else {
317
- data = JSON.parse(JSON.stringify(args['data']));
318
- }
319
- _id = args['_id'];
320
- object = steedosSchema.getObject("" + type.type.ofType.name);
321
- userSession = context ? context.user : null;
322
- delete data.space;
323
- return [2 /*return*/, object.update(_id, data, userSession)];
324
- });
325
- });
326
- }
327
- };
328
- rootMutationfields[objName + '__delete'] = {
329
- type: GraphQLJSON,
330
- args: { '_id': { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, 'selector': { type: GraphQLJSON } },
331
- resolve: function (source, args, context, info) {
332
- return tslib_1.__awaiter(this, void 0, void 0, function () {
333
- var _id, object, userSession;
334
- return tslib_1.__generator(this, function (_a) {
335
- _id = args['_id'];
336
- object = steedosSchema.getObject("" + type.type.ofType.name);
337
- userSession = context ? context.user : null;
338
- return [2 /*return*/, object.delete(_id, userSession)];
339
- });
340
- });
341
- }
342
- };
343
- });
344
- rootQueryfields['count'] = {
345
- type: graphql_1.GraphQLInt,
346
- args: { 'objectName': { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, 'filters': { type: GraphQLJSON } },
347
- resolve: function (source, args, context, info) {
348
- return tslib_1.__awaiter(this, void 0, void 0, function () {
349
- var object, userSession;
350
- return tslib_1.__generator(this, function (_a) {
351
- if (!args.objectName) {
352
- throw new Error('objectName is required!');
353
- }
354
- object = steedosSchema.getObject(args.objectName);
355
- userSession = context ? context.user : null;
356
- return [2 /*return*/, object.count({ filters: args.filters }, userSession)];
357
- });
358
- });
359
- }
360
- };
361
- var schemaConfig = {
362
- query: new graphql_1.GraphQLObjectType({
363
- name: 'RootQueryType',
364
- fields: rootQueryfields
365
- }),
366
- mutation: new graphql_1.GraphQLObjectType({
367
- name: 'MutationRootType',
368
- fields: rootMutationfields
369
- })
370
- };
371
- return new graphql_1.GraphQLSchema(schemaConfig);
372
- }
373
- exports.buildGraphQLSchema = buildGraphQLSchema;
374
- //# sourceMappingURL=index.js.map