@steedos/objectql 2.1.73 → 2.1.78

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 (45) hide show
  1. package/lib/index.d.ts +0 -1
  2. package/lib/index.js +0 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/services/objectService.d.ts +1 -1
  5. package/lib/services/objectService.js +5 -4
  6. package/lib/services/objectService.js.map +1 -1
  7. package/lib/services/objectServiceDispatcher.js +12 -2
  8. package/lib/services/objectServiceDispatcher.js.map +1 -1
  9. package/lib/types/datasource.d.ts +0 -2
  10. package/lib/types/datasource.js +0 -6
  11. package/lib/types/datasource.js.map +1 -1
  12. package/lib/types/field_permission.d.ts +1 -0
  13. package/lib/types/field_permission.js +24 -0
  14. package/lib/types/field_permission.js.map +1 -1
  15. package/lib/types/index.d.ts +1 -0
  16. package/lib/types/index.js +1 -0
  17. package/lib/types/index.js.map +1 -1
  18. package/lib/types/object.d.ts +6 -2
  19. package/lib/types/object.js +70 -36
  20. package/lib/types/object.js.map +1 -1
  21. package/lib/types/object_dynamic_load.d.ts +1 -0
  22. package/lib/types/object_dynamic_load.js +33 -18
  23. package/lib/types/object_dynamic_load.js.map +1 -1
  24. package/lib/types/schema.d.ts +0 -3
  25. package/lib/types/schema.js +0 -11
  26. package/lib/types/schema.js.map +1 -1
  27. package/package.json +8 -8
  28. package/server.js +0 -7
  29. package/src/index.ts +0 -1
  30. package/src/services/objectService.ts +4 -3
  31. package/src/services/objectServiceDispatcher.ts +6 -2
  32. package/src/types/datasource.ts +0 -8
  33. package/src/types/field_permission.ts +16 -0
  34. package/src/types/index.ts +1 -0
  35. package/src/types/object.ts +60 -26
  36. package/src/types/object_dynamic_load.ts +9 -1
  37. package/src/types/schema.ts +0 -13
  38. package/lib/graphql/index.d.ts +0 -3
  39. package/lib/graphql/index.js +0 -374
  40. package/lib/graphql/index.js.map +0 -1
  41. package/lib/graphql/utils.d.ts +0 -7
  42. package/lib/graphql/utils.js +0 -67
  43. package/lib/graphql/utils.js.map +0 -1
  44. package/src/graphql/index.ts +0 -361
  45. package/src/graphql/utils.ts +0 -61
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"
@@ -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: {
@@ -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){
@@ -436,14 +436,6 @@ export class SteedosDataSourceType implements Dictionary {
436
436
  return this._schema;
437
437
  }
438
438
 
439
- buildGraphQLSchema() {
440
- return this._schema.buildGraphQLSchema();
441
- }
442
-
443
- getGraphQLSchema() {
444
- return this._schema.getGraphQLSchema();
445
- }
446
-
447
439
  async dropEntities() {
448
440
  if (this._adapter.dropEntities) {
449
441
  return await this._adapter.dropEntities();
@@ -23,4 +23,20 @@ export class FieldPermission {
23
23
  })
24
24
  return result;
25
25
  }
26
+
27
+ static async getObjectsFieldsPermissionGroupRole() {
28
+ const permissions = await this.getObjectFieldsPermission('*', '*');
29
+ const result = {};
30
+ _.each(permissions, (permission) => {
31
+ if (!result[permission.object_name]) {
32
+ result[permission.object_name] = {};
33
+ }
34
+ const { permission_set_id, field, editable, readable } = permission.metadata;
35
+ if (!result[permission.object_name][permission_set_id]) {
36
+ result[permission.object_name][permission_set_id] = [];
37
+ }
38
+ result[permission.object_name][permission_set_id].push({ field: field, read: readable, edit: editable })
39
+ })
40
+ return result;
41
+ }
26
42
  }
@@ -7,6 +7,7 @@ export * from "./dashboard";
7
7
  export * from "./object";
8
8
  export * from "./connection";
9
9
  export * from "./object_layouts";
10
+ export * from "./field_permission";
10
11
  export { SteedosFieldType, SteedosFieldTypeConfig } from "./field";
11
12
  export { SteedosListenerConfig } from './listeners'
12
13
  export { SteedosTriggerType } from './trigger'
@@ -609,7 +609,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
609
609
  return globalPermission
610
610
  }
611
611
 
612
- async getUserObjectPermission(userSession: SteedosUserSession) {
612
+ async getUserObjectPermission(userSession: SteedosUserSession, rolesFieldsPermission?: any) {
613
613
 
614
614
  if (!userSession) {
615
615
  throw new Error('userSession is required')
@@ -649,7 +649,9 @@ export class SteedosObjectType extends SteedosObjectProperties {
649
649
  throw new Error('not find user permission');
650
650
  }
651
651
 
652
- const rolesFieldsPermission = await FieldPermission.getObjectFieldsPermissionGroupRole(this.name);
652
+ if (!rolesFieldsPermission) {
653
+ rolesFieldsPermission = await FieldPermission.getObjectFieldsPermissionGroupRole(this.name);
654
+ }
653
655
 
654
656
  roles.forEach((role) => {
655
657
  let rolePermission = objectRolesPermission[role];
@@ -926,6 +928,13 @@ export class SteedosObjectType extends SteedosObjectProperties {
926
928
  return await this.callMetadataObjectServiceAction(`getLookupDetailsInfo`, {objectApiName: this.name});
927
929
  }
928
930
 
931
+ /**
932
+ * 此函数返回getDetailsInfo、getMastersInfo、getLookupDetailsInfo 3个请求的结果,用于优化访问速度
933
+ */
934
+ async getRelationsInfo() {
935
+ return await this.callMetadataObjectServiceAction(`getRelationsInfo`, { objectApiName: this.name });
936
+ }
937
+
929
938
  async getRecordPermissions(record, userSession){
930
939
  const permissions = await this.getUserObjectPermission(userSession);
931
940
  const { userId, company_ids: user_company_ids } = userSession;
@@ -985,22 +994,39 @@ export class SteedosObjectType extends SteedosObjectProperties {
985
994
  return permissions
986
995
  }
987
996
 
988
- async getRecordView(userSession){
997
+ async getRecordView(userSession, context?: any) {
998
+ let objectConfig;
999
+ let layouts;
1000
+ let spaceProcessDefinition;
1001
+ let dbListViews;
1002
+ let rolesFieldsPermission;
1003
+
1004
+ if (context) {
1005
+ objectConfig = context.objectConfig;
1006
+ layouts = context.layouts;
1007
+ spaceProcessDefinition = context.spaceProcessDefinition;
1008
+ dbListViews = context.dbListViews;
1009
+ rolesFieldsPermission = context.rolesFieldsPermission;
1010
+ }
1011
+
989
1012
  const lng = userSession.language;
990
- const objectMetadataConfig: any = await this.callMetadataObjectServiceAction('get', {objectApiName: this.name});
991
- let objectConfig = objectMetadataConfig.metadata;
1013
+ if (!objectConfig) {
1014
+ const objectMetadataConfig: any = await this.callMetadataObjectServiceAction('get', { objectApiName: this.name });
1015
+ objectConfig = objectMetadataConfig.metadata;
1016
+ }
992
1017
  objectConfig.name = this.name
993
1018
  objectConfig.datasource = this.datasource.name;
994
- objectConfig.permissions = await this.getUserObjectPermission(userSession);
995
- objectConfig.details = await this.getDetailsInfo();
996
- objectConfig.masters = await this.getMastersInfo();
997
- objectConfig.lookup_details = await this.getLookupDetailsInfo();
998
-
1019
+ objectConfig.permissions = await this.getUserObjectPermission(userSession, rolesFieldsPermission);
1020
+ const relationsInfo = await this.getRelationsInfo();
1021
+ objectConfig.details = relationsInfo.details;
1022
+ objectConfig.masters = relationsInfo.masters;
1023
+ objectConfig.lookup_details = relationsInfo.lookup_details;
999
1024
  delete objectConfig.db
1000
1025
 
1001
1026
  translationObject(lng, objectConfig.name, objectConfig, true);
1002
-
1003
- const layouts = await getObjectLayouts(userSession.profile, userSession.spaceId, this.name);
1027
+ if (!layouts) {
1028
+ layouts = await getObjectLayouts(userSession.profile, userSession.spaceId, this.name);
1029
+ }
1004
1030
  if(layouts && layouts.length > 0){
1005
1031
  const layout = layouts[0];
1006
1032
  let _fields = {};
@@ -1084,24 +1110,31 @@ export class SteedosObjectType extends SteedosObjectProperties {
1084
1110
  const userObjectFields = objectConfig.fields;
1085
1111
  _.each(objectConfig.permissions.field_permissions, (field_permission, field) => {
1086
1112
  const { read, edit } = field_permission;
1087
- if (read) {
1088
- userObjectFields[field].omit = true;
1089
- }
1090
- if (edit) {
1091
- userObjectFields[field].omit = false;
1092
- userObjectFields[field].hidden = false;
1093
- userObjectFields[field].readonly = false;
1094
- userObjectFields[field].disabled = false;
1095
- }
1096
- if (!read && !edit) {
1097
- delete userObjectFields[field]
1113
+ if (userObjectFields[field]) {
1114
+ if (read) {
1115
+ userObjectFields[field].hidden = false;
1116
+ userObjectFields[field].omit = true;
1117
+ userObjectFields[field].readonly = true;
1118
+ userObjectFields[field].disabled = true;
1119
+ }
1120
+ if (edit) {
1121
+ userObjectFields[field].omit = false;
1122
+ userObjectFields[field].hidden = false;
1123
+ userObjectFields[field].readonly = false;
1124
+ userObjectFields[field].disabled = false;
1125
+ }
1126
+ if (!read && !edit) {
1127
+ delete userObjectFields[field]
1128
+ }
1098
1129
  }
1099
1130
  })
1100
1131
 
1101
1132
  objectConfig.fields = userObjectFields
1102
1133
 
1103
1134
  // TODO object layout 是否需要控制审批记录显示?
1104
- let spaceProcessDefinition = await getObject("process_definition").directFind({ filters: [['space', '=', userSession.spaceId], ['object_name', '=', this.name], ['active', '=', true]] })
1135
+ if (!spaceProcessDefinition) {
1136
+ spaceProcessDefinition = await getObject("process_definition").directFind({ filters: [['space', '=', userSession.spaceId], ['object_name', '=', this.name], ['active', '=', true]] })
1137
+ }
1105
1138
  if (spaceProcessDefinition.length > 0) {
1106
1139
  objectConfig.enable_process = true
1107
1140
  }
@@ -1113,8 +1146,9 @@ export class SteedosObjectType extends SteedosObjectProperties {
1113
1146
  delete objectConfig.triggers[key];
1114
1147
  }
1115
1148
  })
1116
-
1117
- const dbListViews = await getObject("object_listviews").find({ filters: [['space', '=', userSession.spaceId], ['object_name', '=', this.name], [['owner', '=', userSession.userId], 'or', ['shared', '=', true]]] })
1149
+ if (!dbListViews) {
1150
+ dbListViews = await getObject("object_listviews").directFind({ filters: [['space', '=', userSession.spaceId], ['object_name', '=', this.name], [['owner', '=', userSession.userId], 'or', ['shared', '=', true]]] })
1151
+ }
1118
1152
  objectConfig.list_views = Object.assign({}, objectConfig.list_views)
1119
1153
  _.each(dbListViews, function(dbListView){
1120
1154
  delete dbListView.created;
@@ -24,6 +24,7 @@ const _routers: Array<any> = [];
24
24
  const _objectsData: Dictionary<any> = {};
25
25
  const delayLoadExtendObjectConfigQueue: Dictionary<any> = {};
26
26
  let standardObjectsLoaded: boolean = false;
27
+ let dbMetadataLoaing: boolean = false;
27
28
 
28
29
  const addDelayLoadExtendObjectConfig = function (extend: string, config: SteedosObjectTypeConfig){
29
30
  if(!delayLoadExtendObjectConfigQueue[extend]){
@@ -323,10 +324,17 @@ export const removeObjectListenerConfig = (_id, listenTo, when)=>{
323
324
  }
324
325
  }
325
326
 
326
- export const loadStandardMetadata = async (serviceName: string, datasourceApiName: string) =>{
327
+ export const loadStandardMetadata = async (serviceName: string, datasourceApiName: string) => {
327
328
  await loadStandardProfiles(serviceName);
328
329
  await loadStandardPermissionsets(serviceName);
329
330
  await loadStandardBaseObjects(serviceName);
331
+ if (dbMetadataLoaing != true) {
332
+ dbMetadataLoaing = true;
333
+ await loadDbMetadatas(datasourceApiName);
334
+ }
335
+ }
336
+
337
+ export const loadDbMetadatas = async (datasourceApiName: string) => {
330
338
  if(datasourceApiName === 'default' || datasourceApiName === 'meteor'){
331
339
  const datasource = getDataSource(datasourceApiName)
332
340
  if(datasource && datasourceApiName === 'default'){
@@ -7,7 +7,6 @@ import { getFromContainer } from 'typeorm';
7
7
  // import { loadCoreValidators } from '../validators';
8
8
  // import { loadStandardBaseObjects } from './object_dynamic_load';
9
9
  // import { preloadDBObjectFields, preloadDBObjectButtons } from '../dynamic-load';
10
- import { buildGraphQLSchema } from '../graphql';
11
10
  import { MetadataRegister } from '../metadata-register';
12
11
  import { MetadataDriver } from '../driver/metadata';
13
12
 
@@ -22,7 +21,6 @@ export type SteedosSchemaConfig = {
22
21
  export class SteedosSchema {
23
22
  private _datasources: Dictionary<SteedosDataSourceType> = {};
24
23
  private _objectsMap: Dictionary<{ datasourceName: string, filePath?: string }> = {};
25
- private graphQLSchema: any = null;
26
24
  private _broker: any = null;
27
25
  private _metadataBroker: any = null;
28
26
  metadataRegister: MetadataRegister = null;
@@ -230,17 +228,6 @@ export class SteedosSchema {
230
228
  return this._datasources
231
229
  }
232
230
 
233
- buildGraphQLSchema() {
234
- this.graphQLSchema = buildGraphQLSchema(this);
235
- }
236
-
237
- getGraphQLSchema() {
238
- if (!this.graphQLSchema) {
239
- this.buildGraphQLSchema();
240
- }
241
- return this.graphQLSchema;
242
- }
243
-
244
231
  async getAllObject() {
245
232
  return await this.metadataBroker.call("objects.getAll");
246
233
  }
@@ -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;