@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.
Files changed (143) hide show
  1. package/lib/services/helpers/graphql/consts.d.ts +17 -0
  2. package/lib/services/helpers/graphql/consts.js +28 -0
  3. package/lib/services/helpers/graphql/consts.js.map +1 -0
  4. package/lib/services/helpers/graphql/getQueryFields.js +17 -2
  5. package/lib/services/helpers/graphql/getQueryFields.js.map +1 -1
  6. package/lib/services/helpers/graphql/index.d.ts +1 -1
  7. package/lib/services/helpers/graphql/index.js +31 -46
  8. package/lib/services/helpers/graphql/index.js.map +1 -1
  9. package/lib/util/index.js +7 -0
  10. package/lib/util/index.js.map +1 -1
  11. package/package.json +11 -12
  12. package/src/actions/field_updates.ts +0 -118
  13. package/src/actions/index.ts +0 -3
  14. package/src/actions/types/field_update_target.ts +0 -7
  15. package/src/actions/types/workflow_notification.ts +0 -9
  16. package/src/actions/types/workflow_rule.ts +0 -11
  17. package/src/actions/workflow_notifications.ts +0 -81
  18. package/src/actions/workflow_rule.ts +0 -136
  19. package/src/driver/driver.ts +0 -102
  20. package/src/driver/field-encrytion/index.ts +0 -8
  21. package/src/driver/field-encrytion/sharedconst.ts +0 -34
  22. package/src/driver/fieldDBType.ts +0 -14
  23. package/src/driver/format.ts +0 -36
  24. package/src/driver/index.ts +0 -20
  25. package/src/driver/metadata.ts +0 -226
  26. package/src/driver/meteorMongo.ts +0 -639
  27. package/src/driver/mongo.ts +0 -416
  28. package/src/driver/mysql.ts +0 -47
  29. package/src/driver/oracle.ts +0 -60
  30. package/src/driver/postgres.ts +0 -46
  31. package/src/driver/sqlite3.ts +0 -40
  32. package/src/driver/sqlserver.ts +0 -52
  33. package/src/dynamic-load/actions.ts +0 -146
  34. package/src/dynamic-load/approval_process.ts +0 -73
  35. package/src/dynamic-load/button.ts +0 -75
  36. package/src/dynamic-load/chart.ts +0 -22
  37. package/src/dynamic-load/client_script.ts +0 -65
  38. package/src/dynamic-load/field.ts +0 -77
  39. package/src/dynamic-load/flow_role.ts +0 -46
  40. package/src/dynamic-load/index.ts +0 -21
  41. package/src/dynamic-load/layout.ts +0 -53
  42. package/src/dynamic-load/listview.ts +0 -57
  43. package/src/dynamic-load/method.ts +0 -63
  44. package/src/dynamic-load/object_translations.ts +0 -61
  45. package/src/dynamic-load/originalObject.ts +0 -8
  46. package/src/dynamic-load/package.ts +0 -312
  47. package/src/dynamic-load/page.ts +0 -23
  48. package/src/dynamic-load/permission.ts +0 -71
  49. package/src/dynamic-load/permissionset.ts +0 -78
  50. package/src/dynamic-load/preload_data.ts +0 -104
  51. package/src/dynamic-load/profile.ts +0 -90
  52. package/src/dynamic-load/query.ts +0 -22
  53. package/src/dynamic-load/restrictionRules.ts +0 -23
  54. package/src/dynamic-load/role.ts +0 -46
  55. package/src/dynamic-load/shareRules.ts +0 -23
  56. package/src/dynamic-load/tab.ts +0 -17
  57. package/src/dynamic-load/tabs.ts +0 -13
  58. package/src/dynamic-load/translations.ts +0 -54
  59. package/src/dynamic-load/trigger.ts +0 -236
  60. package/src/dynamic-load/validation_rule.ts +0 -77
  61. package/src/dynamic-load/workflow.ts +0 -114
  62. package/src/errors/index.ts +0 -111
  63. package/src/formula/core.ts +0 -490
  64. package/src/formula/field_formula.ts +0 -107
  65. package/src/formula/index.ts +0 -81
  66. package/src/formula/params.ts +0 -197
  67. package/src/formula/recompute.ts +0 -65
  68. package/src/formula/simple_params.ts +0 -92
  69. package/src/formula/type.ts +0 -107
  70. package/src/formula/util.ts +0 -207
  71. package/src/index.ts +0 -24
  72. package/src/metadata-register/_base.ts +0 -85
  73. package/src/metadata-register/app.ts +0 -30
  74. package/src/metadata-register/chart.ts +0 -9
  75. package/src/metadata-register/index.ts +0 -123
  76. package/src/metadata-register/layout.ts +0 -38
  77. package/src/metadata-register/object.ts +0 -68
  78. package/src/metadata-register/page.ts +0 -9
  79. package/src/metadata-register/permissionFields.ts +0 -13
  80. package/src/metadata-register/permissionset.ts +0 -25
  81. package/src/metadata-register/process.ts +0 -16
  82. package/src/metadata-register/processTrigger.ts +0 -24
  83. package/src/metadata-register/profile.ts +0 -25
  84. package/src/metadata-register/query.ts +0 -9
  85. package/src/metadata-register/restrictionRules.ts +0 -12
  86. package/src/metadata-register/shareRules.ts +0 -13
  87. package/src/metadata-register/tab.ts +0 -9
  88. package/src/metadata-register/tabs.ts +0 -43
  89. package/src/services/datasourceServiceFactory.ts +0 -55
  90. package/src/services/helpers/graphql/getPrimaryFieldType.ts +0 -48
  91. package/src/services/helpers/graphql/getQueryFields.ts +0 -36
  92. package/src/services/helpers/graphql/index.ts +0 -681
  93. package/src/services/helpers/rest.ts +0 -57
  94. package/src/services/index.ts +0 -13
  95. package/src/services/objectService.ts +0 -846
  96. package/src/services/objectServiceDispatcher.ts +0 -209
  97. package/src/services/objectServiceFactory.ts +0 -29
  98. package/src/summary/core.ts +0 -263
  99. package/src/summary/field_summary.ts +0 -71
  100. package/src/summary/index.ts +0 -96
  101. package/src/summary/recompute.ts +0 -31
  102. package/src/summary/type.ts +0 -60
  103. package/src/ts-types/index.ts +0 -3
  104. package/src/ts-types/permissionset.ts +0 -8
  105. package/src/ts-types/profile.ts +0 -11
  106. package/src/ts-types/triggerActionParams.ts +0 -22
  107. package/src/typeorm/driver.ts +0 -379
  108. package/src/typeorm/index.ts +0 -3
  109. package/src/typeorm/util.ts +0 -147
  110. package/src/types/action.ts +0 -52
  111. package/src/types/app.ts +0 -280
  112. package/src/types/config.ts +0 -152
  113. package/src/types/connection.ts +0 -87
  114. package/src/types/dashboard.ts +0 -91
  115. package/src/types/datasource.ts +0 -570
  116. package/src/types/field.ts +0 -370
  117. package/src/types/field_permission.ts +0 -42
  118. package/src/types/field_types.ts +0 -1
  119. package/src/types/index.ts +0 -21
  120. package/src/types/list_view.ts +0 -56
  121. package/src/types/listeners.ts +0 -18
  122. package/src/types/object.ts +0 -2076
  123. package/src/types/object_dynamic_load.ts +0 -426
  124. package/src/types/object_events.ts +0 -43
  125. package/src/types/object_layouts.ts +0 -20
  126. package/src/types/object_permission.ts +0 -134
  127. package/src/types/query.ts +0 -28
  128. package/src/types/report.ts +0 -128
  129. package/src/types/restrictionRule.ts +0 -57
  130. package/src/types/schema.ts +0 -273
  131. package/src/types/shareRule.ts +0 -57
  132. package/src/types/trigger.ts +0 -88
  133. package/src/types/userSession.ts +0 -45
  134. package/src/types/validation_rules.ts +0 -29
  135. package/src/util/convert.ts +0 -131
  136. package/src/util/field.ts +0 -93
  137. package/src/util/function_expression.ts +0 -63
  138. package/src/util/index.ts +0 -1058
  139. package/src/util/locale.ts +0 -24
  140. package/src/util/permission_shares.ts +0 -25
  141. package/src/util/suffix.ts +0 -78
  142. package/src/util/transform.ts +0 -239
  143. package/src/validators/index.ts +0 -36
@@ -1,846 +0,0 @@
1
- import { SteedosObjectType } from '../types/object';
2
- import { getDataSource, SteedosDatabaseDriverType } from '../types/datasource';
3
- import { getObjectConfig } from '../types/object_dynamic_load';
4
- import _ = require('underscore');
5
- import {
6
- generateActionGraphqlProp,
7
- generateSettingsGraphql,
8
- RELATED_PREFIX,
9
- _getRelatedType,
10
- correctName,
11
- getGraphqlActions,
12
- getRelatedResolver,
13
- dealWithRelatedFields,
14
- getLocalService,
15
- getQueryFields
16
- } from './helpers/graphql';
17
- // generateActionRestProp,
18
- import { getObjectServiceName } from '.';
19
- import { jsonToObject } from '../util/convert';
20
- import { extend } from '../util';
21
- import { formatFiltersToODataQuery } from "@steedos/filters";
22
- const Future = require('fibers/future');
23
- import { getSteedosSchema } from '../';
24
- // import { parse } from '@steedos/formula';
25
- // mongodb pipeline: https://docs.mongodb.com/manual/core/aggregation-pipeline/
26
- declare var Creator: any;
27
-
28
- type externalPipelineItem = {
29
- [mongodPipeline: string]: any
30
- }
31
- function getObjectServiceMethodsSchema() {
32
- const methods = {
33
- aggregate: {
34
- async handler(query, externalPipeline: Array<externalPipelineItem>, userSession) {
35
- return await this.object.aggregate(query, externalPipeline, userSession)
36
- }
37
- },
38
- find: {
39
- async handler(query, userSession) {
40
- if (this.object.name == 'users') {
41
- return await this.object.find(query)
42
- }
43
- return await this.object.find(query, userSession)
44
- }
45
- },
46
- findOne: {
47
- async handler(id: string, query, userSession) {
48
- if (this.object.name == 'users') {
49
- return await this.object.findOne(id, query)
50
- }
51
- return await this.object.findOne(id, query, userSession)
52
- }
53
- },
54
- insert: {
55
- async handler(doc, userSession) {
56
- return await this.object.insert(doc, userSession)
57
- }
58
- },
59
- update: {
60
- async handler(id, doc, userSession) {
61
- return await this.object.update(id, doc, userSession)
62
- }
63
- },
64
- updateOne: {
65
- async handler(id, doc, userSession) {
66
- return await this.object.updateOne(id, doc, userSession)
67
- }
68
- },
69
- updateMany: {
70
- async handler(queryFilters, doc, userSession) {
71
- return await this.object.updateMany(queryFilters, doc, userSession)
72
- }
73
- },
74
- delete: {
75
- async handler(id, userSession) {
76
- return await this.object.delete(id, userSession)
77
- }
78
- },
79
- directAggregate: {
80
- async handler(query, externalPipeline: Array<externalPipelineItem>, userSession) {
81
- return await this.object.directAggregate(query, externalPipeline, userSession)
82
- }
83
- },
84
- directAggregatePrefixalPipeline: {
85
- async handler(query, externalPipeline: Array<externalPipelineItem>, userSession) {
86
- return await this.object.directAggregatePrefixalPipeline(query, externalPipeline, userSession)
87
- }
88
- },
89
- directFind: {
90
- async handler(query, userSession) {
91
- return await this.object.directFind(query, userSession)
92
- }
93
- },
94
- directInsert: {
95
- async handler(doc, userSession) {
96
- return await this.object.directInsert(doc, userSession)
97
- }
98
- },
99
- directUpdate: {
100
- async handler(id, doc, userSession) {
101
- return await this.object.directUpdate(id, doc, userSession)
102
- }
103
- },
104
- directDelete: {
105
- async handler(id, userSession) {
106
- return await this.object.directDelete(id, userSession)
107
- }
108
- },
109
- count: {
110
- async handler(query, userSession) {
111
- return await this.object.count(query, userSession)
112
- }
113
- },
114
- getField: {
115
- handler(fieldName) {
116
- return this.object.getField(fieldName).toConfig()
117
- }
118
- },
119
- getFields: {
120
- handler() {
121
- return this.object.toConfig().fields;
122
- }
123
- },
124
- getNameFieldKey: {
125
- handler() {
126
- return this.object.getNameFieldKey();
127
- }
128
- },
129
- toConfig: {
130
- handler() {
131
- return this.object.toConfig()
132
- }
133
- },
134
- getUserObjectPermission: {
135
- handler(userSession) {
136
- return this.object.getUserObjectPermission(userSession)
137
- }
138
- },
139
- isEnableAudit: {
140
- handler() {
141
- return this.object.isEnableAudit()
142
- }
143
- },
144
- _makeNewID: {
145
- async handler() {
146
- return await this.object._makeNewID();
147
- }
148
- },
149
- getRecordAbsoluteUrl: {
150
- async handler() {
151
- return this.object.getRecordAbsoluteUrl();
152
- }
153
- },
154
- getGridAbsoluteUrl: {
155
- async handler() {
156
- return this.object.getGridAbsoluteUrl();
157
- }
158
- },
159
- getRecordPermissions: {
160
- async handler(record, userSession) {
161
- return this.object.getRecordPermissions(record, userSession);
162
- }
163
- },
164
- getRecordView: {
165
- async handler(userSession, context?) {
166
- return await this.object.getRecordView(userSession, context);
167
- }
168
- },
169
- createDefaultRecordView: {
170
- async handler(userSession) {
171
- return await this.object.createDefaultRecordView(userSession);
172
- }
173
- },
174
- getDefaultRecordView: {
175
- async handler(userSession) {
176
- return await this.object.getDefaultRecordView(userSession);
177
- }
178
- },
179
- getRelateds: {
180
- async handler() {
181
- return await this.object.getRelateds();
182
- }
183
- },
184
- refreshIndexes: {
185
- async handler() {
186
- return await this.object.refreshIndexes();
187
- }
188
- },
189
- allowRead: {
190
- async handler(userSession) {
191
- return await this.object.allowRead(userSession);
192
- }
193
- },
194
- allowInsert: {
195
- async handler(userSession) {
196
- return await this.object.allowInsert(userSession);
197
- }
198
- },
199
- allowUpdate: {
200
- async handler(userSession) {
201
- return await this.object.allowUpdate(userSession);
202
- }
203
- },
204
- allowDelete: {
205
- async handler(userSession) {
206
- return await this.object.allowDelete(userSession);
207
- }
208
- }
209
- // getPageView: {
210
- // //TODO
211
- // }
212
- };
213
-
214
- return methods;
215
- }
216
-
217
- function getObjectServiceActionsSchema() {
218
- const actions: any = {
219
- aggregate: {
220
- params: {
221
- query: { type: "object" },
222
- externalPipeline: { type: "array", items: "object" }
223
- },
224
- async handler(ctx) {
225
- const userSession = ctx.meta.user;
226
- const { query, externalPipeline } = ctx.params;
227
- return await this.aggregate(query, externalPipeline, userSession)
228
- }
229
- },
230
- // meteor、default database 默认不返回is_deleted = true的数据
231
- graphqlFind: {
232
- params: {
233
- fields: { type: 'array', items: "string", optional: true },
234
- filters: [{ type: 'array', optional: true }, { type: 'string', optional: true }],
235
- top: { type: 'number', optional: true },
236
- skip: { type: 'number', optional: true },
237
- sort: { type: 'string', optional: true }
238
- },
239
- async handler(ctx) {
240
- //TODO filters: 如果filters中没有查询 is_deleted 则自动添加is_deleted != true 条件
241
- if (this.object.datasource.driver === SteedosDatabaseDriverType.MeteorMongo || this.object.datasource.driver === SteedosDatabaseDriverType.Mongo) {
242
- const { filters } = ctx.params;
243
- if (filters) {
244
- if (_.isString(filters)) {
245
- if (filters.indexOf('(is_deleted eq true)') < 0) {
246
- ctx.params.filters = `(${filters}) and (is_deleted ne true)`;
247
- }
248
- }
249
- if (_.isArray(filters)) {
250
- const filtersStr = formatFiltersToODataQuery(filters);
251
- if (filtersStr.indexOf('(is_deleted eq true)') < 0) {
252
- ctx.params.filters = [ctx.params.filters, ['is_deleted', '!=', true]]
253
- }
254
- }
255
- } else {
256
- ctx.params.filters = '(is_deleted ne true)'
257
- }
258
- }
259
- if (_.isEmpty(ctx.params.fields)) {
260
- const { resolveInfo } = ctx.meta;
261
-
262
- const fieldNames = getQueryFields(resolveInfo);
263
-
264
- if (!_.isEmpty(fieldNames)) {
265
- ctx.params.fields = fieldNames;
266
- }
267
- }
268
- const userSession = ctx.meta.user;
269
- return this.find(ctx.params, userSession)
270
- }
271
- },
272
- graphqlCount: {
273
- params: {
274
- fields: { type: 'array', items: "string", optional: true },
275
- filters: [{ type: 'array', optional: true }, { type: 'string', optional: true }],
276
- top: { type: 'number', optional: true },
277
- skip: { type: 'number', optional: true },
278
- sort: { type: 'string', optional: true }
279
- },
280
- async handler(ctx) {
281
- //TODO filters: 如果filters中没有查询 is_deleted 则自动添加is_deleted != true 条件
282
- if (this.object.datasource.driver === SteedosDatabaseDriverType.MeteorMongo || this.object.datasource.driver === SteedosDatabaseDriverType.Mongo) {
283
- const { filters } = ctx.params;
284
- if (filters) {
285
- if (_.isString(filters)) {
286
- if (filters.indexOf('(is_deleted eq true)') < 0) {
287
- ctx.params.filters = `(${filters}) and (is_deleted ne true)`;
288
- }
289
- }
290
- if (_.isArray(filters)) {
291
- const filtersStr = formatFiltersToODataQuery(filters);
292
- if (filtersStr.indexOf('(is_deleted eq true)') < 0) {
293
- ctx.params.filters = [ctx.params.filters, ['is_deleted', '!=', true]]
294
- }
295
- }
296
- } else {
297
- ctx.params.filters = '(is_deleted ne true)'
298
- }
299
- }
300
-
301
- const userSession = ctx.meta.user;
302
- return this.count(ctx.params, userSession)
303
- }
304
- },
305
- find: {
306
- params: {
307
- fields: { type: 'array', items: "string", optional: true },
308
- filters: [{ type: 'array', optional: true }, { type: 'string', optional: true }],
309
- top: { type: 'number', optional: true },
310
- skip: { type: 'number', optional: true },
311
- sort: { type: 'string', optional: true }
312
- },
313
- async handler(ctx) {
314
- const userSession = ctx.meta.user;
315
- return this.find(ctx.params, userSession)
316
- }
317
- },
318
- findOne: {
319
- params: {
320
- id: { type: "any" },
321
- query: { type: "object", optional: true }
322
- },
323
- async handler(ctx) {
324
- const userSession = ctx.meta.user;
325
- const { id, query } = ctx.params;
326
- return this.findOne(id, query, userSession)
327
- }
328
- },
329
- insert: {
330
- params: {
331
- doc: { type: "object" }
332
- },
333
- async handler(ctx) {
334
- const userSession = ctx.meta.user;
335
- const { doc } = ctx.params;
336
- let data: any = '';
337
- if (_.isString(doc)) {
338
- data = JSON.parse(doc);
339
- } else {
340
- data = JSON.parse(JSON.stringify(doc));
341
- }
342
- let object = this.object;
343
- if (userSession && object.getField('space')) {
344
- data.space = userSession.spaceId;
345
- }
346
- return this.insert(data, userSession)
347
- }
348
- },
349
- update: {
350
- params: {
351
- id: { type: "any" },
352
- doc: { type: "object" }
353
- },
354
- async handler(ctx) {
355
- const userSession = ctx.meta.user;
356
- const { id, doc } = ctx.params;
357
- let data: any = '';
358
- if (_.isString(doc)) {
359
- data = JSON.parse(doc);
360
- } else {
361
- data = JSON.parse(JSON.stringify(doc));
362
- }
363
- delete data.space;
364
- return this.update(id, data, userSession)
365
- }
366
- },
367
- updateOne: {
368
- params: {
369
- id: { type: "any" },
370
- doc: { type: "object" }
371
- },
372
- async handler(ctx) {
373
- const userSession = ctx.meta.user;
374
- const { id, doc } = ctx.params;
375
- let data: any = '';
376
- if (_.isString(doc)) {
377
- data = JSON.parse(doc);
378
- } else {
379
- data = JSON.parse(JSON.stringify(doc));
380
- }
381
- delete data.space;
382
- return this.updateOne(id, data, userSession)
383
- }
384
- },
385
- updateMany: {
386
- params: {
387
- queryFilters: { type: "array", items: "any" },
388
- doc: { type: "object" }
389
- },
390
- async handler(ctx) {
391
- const userSession = ctx.meta.user;
392
- const { queryFilters, doc } = ctx.params;
393
- let data: any = '';
394
- if (_.isString(doc)) {
395
- data = JSON.parse(doc);
396
- } else {
397
- data = JSON.parse(JSON.stringify(doc));
398
- }
399
- delete data.space;
400
- return await this.updateMany(queryFilters, data, userSession)
401
- }
402
- },
403
- delete: {
404
- params: {
405
- id: { type: "any" }
406
- },
407
- async handler(ctx) {
408
- const userSession = ctx.meta.user;
409
- const { id } = ctx.params;
410
- return this.delete(id, userSession)
411
- }
412
- },
413
- directAggregate: {
414
- params: {
415
- query: { type: "object" },
416
- externalPipeline: { type: "array", items: "object" }
417
- },
418
- async handler(ctx) {
419
- const userSession = ctx.meta.user;
420
- const { query, externalPipeline } = ctx.params;
421
- return this.directAggregate(query, externalPipeline, userSession)
422
- }
423
- },
424
- directAggregatePrefixalPipeline: {
425
- params: {
426
- query: { type: "object" },
427
- prefixalPipeline: { type: "array", items: "object" }
428
- },
429
- async handler(ctx) {
430
- const userSession = ctx.meta.user;
431
- const { query, prefixalPipeline } = ctx.params;
432
- return this.directAggregatePrefixalPipeline(query, prefixalPipeline, userSession)
433
- }
434
- },
435
- directFind: {
436
- params: {
437
- fields: { type: 'array', items: "string", optional: true },
438
- filters: [{ type: 'array', optional: true }, { type: 'string', optional: true }],
439
- top: { type: 'number', optional: true },
440
- skip: { type: 'number', optional: true },
441
- sort: { type: 'string', optional: true }
442
- },
443
- async handler(ctx) {
444
- const userSession = ctx.meta.user;
445
- return this.directFind(ctx.params, userSession)
446
- }
447
- },
448
- directInsert: {
449
- params: {
450
- doc: { type: "object" }
451
- },
452
- async handler(ctx) {
453
- const userSession = ctx.meta.user;
454
- const { doc } = ctx.params;
455
- return this.directInsert(doc, userSession)
456
- }
457
- },
458
- directUpdate: {
459
- params: {
460
- id: { type: "any" },
461
- doc: { type: "object" }
462
- },
463
- async handler(ctx) {
464
- const userSession = ctx.meta.user;
465
- const { id, doc } = ctx.params;
466
- return this.directUpdate(id, doc, userSession)
467
- }
468
- },
469
- directDelete: {
470
- params: {
471
- id: { type: "any" },
472
- },
473
- async handler(ctx) {
474
- const userSession = ctx.meta.user;
475
- const { id } = ctx.params;
476
- return this.directDelete(id, userSession)
477
- }
478
- },
479
- count: {
480
- params: {
481
- fields: { type: 'array', items: "string", optional: true },
482
- filters: [{ type: 'array', optional: true }, { type: 'string', optional: true }],
483
- top: { type: 'number', optional: true },
484
- skip: { type: 'number', optional: true },
485
- sort: { type: 'string', optional: true }
486
- },
487
- async handler(ctx) {
488
- const userSession = ctx.meta.user;
489
- return this.count(ctx.params, userSession)
490
- }
491
- },
492
- getField: {
493
- params: {
494
- fieldApiName: { type: "string" },
495
- },
496
- async handler(ctx) {
497
- const { fieldApiName } = ctx.params;
498
- return this.getField(fieldApiName)
499
- }
500
- },
501
- getFields: {
502
- // rest: {
503
- // method: "GET",
504
- // path: "/fields"
505
- // },
506
- async handler(ctx) {
507
- return this.getFields()
508
- }
509
- },
510
- getNameFieldKey: {
511
- async handler(ctx) {
512
- return this.getNameFieldKey()
513
- }
514
- },
515
- toConfig: {
516
- async handler(ctx) {
517
- return this.toConfig()
518
- }
519
- },
520
- getUserObjectPermission: {
521
- // rest: {
522
- // method: "GET",
523
- // path: "/getUserObjectPermission"
524
- // },
525
- async handler(ctx) {
526
- const userSession = ctx.meta.user;
527
- return this.getUserObjectPermission(userSession)
528
- }
529
- },
530
- isEnableAudit: {
531
- async handler() {
532
- return this.isEnableAudit();
533
- }
534
- },
535
- _makeNewID: {
536
- async handler() {
537
- return await this._makeNewID();
538
- }
539
- },
540
- getRecordAbsoluteUrl: {
541
- async handler() {
542
- return this.getRecordAbsoluteUrl();
543
- }
544
- },
545
- getGridAbsoluteUrl: {
546
- async handler() {
547
- return this.getGridAbsoluteUrl();
548
- }
549
- },
550
- getRecordPermissionsById: {
551
- // rest: {
552
- // method: "GET",
553
- // path: "/recordPermissions/:recordId"
554
- // },
555
- async handler(ctx) {
556
- const userSession = ctx.meta.user;
557
- const { recordId } = ctx.params;
558
- const record = await this.findOne(recordId)
559
- return this.getRecordPermissions(record, userSession);
560
- }
561
- },
562
- getRecordPermissions: {
563
- async handler(ctx) {
564
- const userSession = ctx.meta.user;
565
- const { record } = ctx.params;
566
- return this.getRecordPermissions(record, userSession);
567
- }
568
- },
569
- getRecordView: {
570
- // rest: {
571
- // method: "GET",
572
- // path: "/uiSchema"
573
- // },
574
- async handler(ctx) {
575
- const userSession = ctx.meta.user;
576
- const { context } = ctx.params;
577
- return await this.getRecordView(userSession, context);
578
- }
579
- },
580
- createDefaultRecordView: {
581
- // rest: {
582
- // method: "POST",
583
- // path: "/defUiSchema"
584
- // },
585
- async handler(ctx) {
586
- const userSession = ctx.meta.user;
587
- if (!userSession.is_space_admin) {
588
- throw new Error('no permission.')
589
- }
590
- return await this.createDefaultRecordView(userSession);
591
- }
592
- },
593
- getDefaultRecordView: {
594
- // rest: {
595
- // method: "GET",
596
- // path: "/uiSchemaTemplate"
597
- // },
598
- async handler(ctx) {
599
- const userSession = ctx.meta.user;
600
- if (!userSession.is_space_admin) {
601
- throw new Error('no permission.')
602
- }
603
- return await this.getDefaultRecordView(userSession);
604
- }
605
- },
606
- getRelateds: {
607
- // rest: {
608
- // method: "GET",
609
- // path: "/relateds"
610
- // },
611
- async handler(ctx) {
612
- return await this.getRelateds();
613
- }
614
- },
615
- refreshIndexes: {
616
- async handler(ctx) {
617
- return await this.refreshIndexes();
618
- }
619
- },
620
- allowRead: {
621
- async handler(ctx) {
622
- const userSession = ctx.meta.user;
623
- return await this.allowRead(userSession);
624
- }
625
- },
626
- allowInsert: {
627
- async handler(ctx) {
628
- const userSession = ctx.meta.user;
629
- return await this.allowInsert(userSession);
630
- }
631
- },
632
- allowUpdate: {
633
- async handler(ctx) {
634
- const userSession = ctx.meta.user;
635
- return await this.allowUpdate(userSession);
636
- }
637
- },
638
- allowDelete: {
639
- async handler(ctx) {
640
- const userSession = ctx.meta.user;
641
- return await this.allowDelete(userSession);
642
- }
643
- }
644
- };
645
- _.each(actions, function (action) {
646
- delete action.params;
647
- });
648
- return actions;
649
- }
650
-
651
- export function getObjectServiceSchema(serviceName, objectConfig) {
652
- return {
653
- name: serviceName,
654
- actions: getObjectServiceActionsSchema(),
655
- methods: getObjectServiceMethodsSchema(),
656
- created() {
657
- this.object = new SteedosObjectType(objectConfig.name, getDataSource(objectConfig.datasource), objectConfig);
658
- }
659
- }
660
- }
661
-
662
- module.exports = {
663
- name: '#_objectBaseService', //TODO
664
- settings: {
665
- // objectApiName: //TODO
666
- // objectConfig
667
- },
668
- actions: getObjectServiceActionsSchema(),
669
- methods: getObjectServiceMethodsSchema(),
670
- created(broker) {
671
- if (!this.settings.objectApiName && !this.settings.objectConfig) {
672
- throw new Error('Please set the settings.objectApiName.')
673
- }
674
- const objectConfig: any = this.settings.objectConfig || getObjectConfig(this.settings.objectApiName);
675
- if (!objectConfig) {
676
- throw new Error('Not found object config by objectApiName.')
677
- }
678
- const datasource = getDataSource(objectConfig.datasource);
679
- if (datasource) {
680
- this.object = datasource.getLocalObject(objectConfig.name);
681
- this.objectApiName = objectConfig.name;
682
- }
683
- },
684
- async started() {
685
- const objectConfig: any = this.settings.objectConfig || getObjectConfig(this.settings.objectApiName);
686
- const objectApiName = objectConfig.name;
687
- // 通知以lookup或master_detail字段关联此对象的对象刷新graphql schema
688
- let steedosSchema = getSteedosSchema();
689
- let obj = steedosSchema.getObject(objectApiName);
690
- const relationsInfo = await obj.getRelationsInfo();
691
- let detailsInfo = relationsInfo.details || [];
692
- let lookupsInfo = relationsInfo.lookup_details || [];
693
- let relatedInfos = detailsInfo.concat(lookupsInfo);
694
- for (const info of relatedInfos) {
695
- if (!info.startsWith("__")) {
696
- let infos = info.split(".");
697
- let detailObjectApiName = infos[0];
698
- this.broker.emit(`${getObjectServiceName(detailObjectApiName)}.refresh`, {});
699
- }
700
- }
701
- },
702
- events: {
703
- "metadata.objects.deleted": {
704
- async handler(ctx) {
705
- const { objectApiName } = ctx.params
706
- const { onDestroyObjectService, objectConfig } = this.settings
707
- if (objectApiName === this.object.name) {
708
- _.each(objectConfig.fields, (field, name) => {
709
- if ((field.type === 'lookup' || field.type === 'master_detail') && (field.reference_to && _.isString(field.reference_to))) {
710
- ctx.broker.emit(`${getObjectServiceName(field.reference_to)}.refresh`, {});
711
- }
712
- })
713
- // console.log(`ctx.broker.destroyService`, this.object.name);
714
- await ctx.broker.destroyService(this);
715
- if (onDestroyObjectService && _.isFunction(onDestroyObjectService)) {
716
- onDestroyObjectService(objectApiName);
717
- }
718
- // 给localservice的settings赋值deleted=true,用于标记服务已删除
719
- let localService = getLocalService(objectApiName);
720
- if (localService) {
721
- localService.settings.deleted = true;
722
- }
723
- // 通知以lookup或master_detail字段关联此对象的对象刷新graphql schema
724
- let steedosSchema = getSteedosSchema();
725
- let obj = steedosSchema.getObject(objectApiName);
726
- const relationsInfo = await obj.getRelationsInfo();
727
- let detailsInfo = relationsInfo.details || [];
728
- let lookupsInfo = relationsInfo.lookup_details || [];
729
- let relatedInfos = detailsInfo.concat(lookupsInfo);
730
- for (const info of relatedInfos) {
731
- if (!info.startsWith("__")) {
732
- let infos = info.split(".");
733
- let detailObjectApiName = infos[0];
734
- ctx.broker.emit(`${getObjectServiceName(detailObjectApiName)}.refresh`, {});
735
- }
736
- }
737
- ctx.emit('$services.changed');
738
- }
739
- }
740
- }
741
- },
742
- merged(schema) {
743
- let settings = schema.settings;
744
- let objectConfig = settings.objectConfig;
745
- // 先关闭对象服务action rest api, 否则会导致 action rest api 过多, 请求速度变慢.
746
- // if (objectConfig.enable_api) {
747
- // _.each(schema.actions, (action, actionName) => {
748
- // let rest = generateActionRestProp(actionName);
749
- // if (rest.method) {
750
- // action.rest = rest;
751
- // }
752
- // })
753
- // }
754
- if (objectConfig.enable_graphql || true) { // TODO object.yml添加enable_graphql属性
755
- _.each(schema.actions, (action, actionName) => {
756
- let gpObj = generateActionGraphqlProp(actionName, objectConfig);
757
- if (!_.isEmpty(gpObj)) {
758
- action.graphql = gpObj;
759
- }
760
- })
761
- settings.graphql = generateSettingsGraphql(objectConfig);
762
- dealWithRelatedFields(objectConfig, settings.graphql);
763
- let graphqlActions = getGraphqlActions(objectConfig);
764
- schema.actions = _.extend({}, graphqlActions, schema.actions);
765
- }
766
- if (!schema.events) {
767
- schema.events = {};
768
- }
769
- schema.events[`${getObjectServiceName(objectConfig.name)}.detailsChanged`] = {
770
- handler: async function (ctx) {
771
- const { objectApiName, detailObjectApiName, detailFieldName, detailFieldReferenceToFieldName } = ctx.params;
772
- let resolvers = this.settings.graphql.resolvers;
773
- let type: string = this.settings.graphql.type;
774
- let relatedFieldName = correctName(`${RELATED_PREFIX}_${detailObjectApiName}_${detailFieldName}`);
775
- let relatedType = _getRelatedType(relatedFieldName, detailObjectApiName);
776
- if (type.indexOf(relatedType) > -1) { // 防止重复定义field
777
- return;
778
- }
779
- this.settings.graphql.type = type.substring(0, type.length - 1) + relatedType + '}';
780
- resolvers[objectApiName][relatedFieldName] = getRelatedResolver(objectApiName, detailObjectApiName, detailFieldName, detailFieldReferenceToFieldName);
781
- }
782
- };
783
- schema.events[`${objectConfig.datasource}.${getObjectServiceName(objectConfig.name)}.metadata.objects.inserted`] = {
784
- handler: async function (ctx) {
785
- let objectConfig = ctx.params.data;
786
- // console.log(`${objectConfig.datasource}.${getObjectServiceName(objectConfig.name)}.metadata.objects.inserted`);
787
- // 对象发生变化时,重新创建Steedos Object 对象
788
- const datasource = getDataSource(objectConfig.datasource);
789
- if (datasource) {
790
- const localObjectConfig = getObjectConfig(objectConfig.name);
791
- if (localObjectConfig) {
792
- objectConfig.listeners = localObjectConfig.listeners;
793
- objectConfig.methods = localObjectConfig.methods;
794
- }
795
- const object = new SteedosObjectType(objectConfig.name, datasource, objectConfig)
796
- datasource.setLocalObject(objectConfig.name, object);
797
- this.object = object;
798
-
799
- if (
800
- datasource.name != "meteor" &&
801
- datasource.name != "default"
802
- ) {
803
- await datasource.init();
804
- }
805
-
806
- if (datasource.name === 'meteor' && Creator.Objects[objectConfig.name]) {
807
- jsonToObject(objectConfig);
808
- const localTriggers = (localObjectConfig as any).triggers;
809
- if (localTriggers) {
810
- objectConfig.triggers = localTriggers;
811
- }
812
- extend(objectConfig, { triggers: Creator.Objects[objectConfig.name].triggers }, { triggers: (localObjectConfig as any)._baseTriggers })
813
- Creator.Objects[objectConfig.name] = objectConfig;
814
-
815
- await Future.task(() => {
816
- try {
817
- Creator.loadObjects(objectConfig, objectConfig.name);
818
- } catch (error) {
819
- this.logger.error('metadata.objects.inserted error', objectConfig.name, error)
820
- }
821
- }).promise();
822
- }
823
- }
824
-
825
- let gobj = generateSettingsGraphql(objectConfig);
826
- this.settings.graphql = gobj;
827
- dealWithRelatedFields(objectConfig, this.settings.graphql);
828
- // TODO 重写 actions
829
- // let graphqlActions = getGraphqlActions(objectConfig);
830
- // schema.actions = _.extend({}, graphqlActions, schema.actions);
831
- ctx.emit('$services.changed');
832
- }
833
- }
834
- schema.events[`${getObjectServiceName(objectConfig.name)}.refresh`] = {
835
- handler: async function (ctx) {
836
- const _objectConfig = getObjectConfig(objectConfig.name);
837
- if (_objectConfig) {
838
- let gobj = generateSettingsGraphql(_objectConfig);
839
- this.settings.graphql = gobj;
840
- dealWithRelatedFields(_objectConfig, this.settings.graphql);
841
- ctx.emit('$services.changed');
842
- }
843
- }
844
- }
845
- },
846
- }