@steedos/objectql 2.2.39 → 2.2.42

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.
@@ -2,7 +2,8 @@ import { SteedosObjectType } from '../types/object';
2
2
  import { getDataSource, SteedosDatabaseDriverType } from '../types/datasource';
3
3
  import { getObjectConfig } from '../types/object_dynamic_load';
4
4
  import _ = require('underscore');
5
- import { generateActionRestProp, generateActionGraphqlProp, generateSettingsGraphql, RELATED_PREFIX, _getRelatedType, correctName, getGraphqlActions, getRelatedResolver, dealWithRelatedFields, getLocalService } from './helpers';
5
+ import { generateActionGraphqlProp, generateSettingsGraphql, RELATED_PREFIX, _getRelatedType, correctName, getGraphqlActions, getRelatedResolver, dealWithRelatedFields, getLocalService } from './helpers';
6
+ // generateActionRestProp,
6
7
  import { getObjectServiceName } from '.';
7
8
  import { jsonToObject } from '../util/convert';
8
9
  import { extend } from '../util';
@@ -154,14 +155,14 @@ function getObjectServiceMethodsSchema() {
154
155
  return await this.object.getRecordView(userSession, context);
155
156
  }
156
157
  },
157
- createDefaulRecordView: {
158
+ createDefaultRecordView: {
158
159
  async handler(userSession) {
159
- return await this.object.createDefaulRecordView(userSession);
160
+ return await this.object.createDefaultRecordView(userSession);
160
161
  }
161
162
  },
162
- getDefaulRecordView: {
163
+ getDefaultRecordView: {
163
164
  async handler(userSession) {
164
- return await this.object.getDefaulRecordView(userSession);
165
+ return await this.object.getDefaultRecordView(userSession);
165
166
  }
166
167
  },
167
168
  getRelateds: {
@@ -173,6 +174,26 @@ function getObjectServiceMethodsSchema() {
173
174
  async handler() {
174
175
  return await this.object.refreshIndexes();
175
176
  }
177
+ },
178
+ allowRead:{
179
+ async handler(userSession) {
180
+ return await this.object.allowRead(userSession);
181
+ }
182
+ },
183
+ allowInsert:{
184
+ async handler(userSession) {
185
+ return await this.object.allowInsert(userSession);
186
+ }
187
+ },
188
+ allowUpdate:{
189
+ async handler(userSession) {
190
+ return await this.object.allowUpdate(userSession);
191
+ }
192
+ },
193
+ allowDelete:{
194
+ async handler(userSession) {
195
+ return await this.object.allowDelete(userSession);
196
+ }
176
197
  }
177
198
  // getPageView: {
178
199
  // //TODO
@@ -437,10 +458,6 @@ function getObjectServiceActionsSchema() {
437
458
  }
438
459
  },
439
460
  count: {
440
- rest: {
441
- method: "GET",
442
- path: "/count"
443
- },
444
461
  params: {
445
462
  fields: { type: 'array', items: "string", optional: true },
446
463
  filters: [{ type: 'array', optional: true }, { type: 'string', optional: true }],
@@ -454,10 +471,6 @@ function getObjectServiceActionsSchema() {
454
471
  }
455
472
  },
456
473
  getField: {
457
- rest: {
458
- method: "GET",
459
- path: "/field"
460
- },
461
474
  params: {
462
475
  fieldApiName: { type: "string" },
463
476
  },
@@ -467,10 +480,10 @@ function getObjectServiceActionsSchema() {
467
480
  }
468
481
  },
469
482
  getFields: {
470
- rest: {
471
- method: "GET",
472
- path: "/fields"
473
- },
483
+ // rest: {
484
+ // method: "GET",
485
+ // path: "/fields"
486
+ // },
474
487
  async handler(ctx) {
475
488
  return this.getFields()
476
489
  }
@@ -486,10 +499,10 @@ function getObjectServiceActionsSchema() {
486
499
  }
487
500
  },
488
501
  getUserObjectPermission: {
489
- rest: {
490
- method: "GET",
491
- path: "/getUserObjectPermission"
492
- },
502
+ // rest: {
503
+ // method: "GET",
504
+ // path: "/getUserObjectPermission"
505
+ // },
493
506
  async handler(ctx) {
494
507
  const userSession = ctx.meta.user;
495
508
  return this.getUserObjectPermission(userSession)
@@ -516,10 +529,10 @@ function getObjectServiceActionsSchema() {
516
529
  }
517
530
  },
518
531
  getRecordPermissionsById: {
519
- rest: {
520
- method: "GET",
521
- path: "/recordPermissions/:recordId"
522
- },
532
+ // rest: {
533
+ // method: "GET",
534
+ // path: "/recordPermissions/:recordId"
535
+ // },
523
536
  async handler(ctx) {
524
537
  const userSession = ctx.meta.user;
525
538
  const { recordId } = ctx.params;
@@ -535,47 +548,47 @@ function getObjectServiceActionsSchema() {
535
548
  }
536
549
  },
537
550
  getRecordView: {
538
- rest: {
539
- method: "GET",
540
- path: "/uiSchema"
541
- },
551
+ // rest: {
552
+ // method: "GET",
553
+ // path: "/uiSchema"
554
+ // },
542
555
  async handler(ctx) {
543
556
  const userSession = ctx.meta.user;
544
557
  const { context } = ctx.params;
545
558
  return await this.getRecordView(userSession, context);
546
559
  }
547
560
  },
548
- createDefaulRecordView: {
549
- rest: {
550
- method: "POST",
551
- path: "/defUiSchema"
552
- },
561
+ createDefaultRecordView: {
562
+ // rest: {
563
+ // method: "POST",
564
+ // path: "/defUiSchema"
565
+ // },
553
566
  async handler(ctx) {
554
567
  const userSession = ctx.meta.user;
555
568
  if(!userSession.is_space_admin){
556
569
  throw new Error('no permission.')
557
570
  }
558
- return await this.createDefaulRecordView(userSession);
571
+ return await this.createDefaultRecordView(userSession);
559
572
  }
560
573
  },
561
- getDefaulRecordView: {
562
- rest: {
563
- method: "GET",
564
- path: "/uiSchemaTemplate"
565
- },
574
+ getDefaultRecordView: {
575
+ // rest: {
576
+ // method: "GET",
577
+ // path: "/uiSchemaTemplate"
578
+ // },
566
579
  async handler(ctx) {
567
580
  const userSession = ctx.meta.user;
568
581
  if(!userSession.is_space_admin){
569
582
  throw new Error('no permission.')
570
583
  }
571
- return await this.getDefaulRecordView(userSession);
584
+ return await this.getDefaultRecordView(userSession);
572
585
  }
573
586
  },
574
587
  getRelateds: {
575
- rest: {
576
- method: "GET",
577
- path: "/relateds"
578
- },
588
+ // rest: {
589
+ // method: "GET",
590
+ // path: "/relateds"
591
+ // },
579
592
  async handler(ctx) {
580
593
  return await this.getRelateds();
581
594
  }
@@ -584,6 +597,30 @@ function getObjectServiceActionsSchema() {
584
597
  async handler(ctx) {
585
598
  return await this.refreshIndexes();
586
599
  }
600
+ },
601
+ allowRead: {
602
+ async handler(ctx) {
603
+ const userSession = ctx.meta.user;
604
+ return await this.allowRead(userSession);
605
+ }
606
+ },
607
+ allowInsert: {
608
+ async handler(ctx) {
609
+ const userSession = ctx.meta.user;
610
+ return await this.allowInsert(userSession);
611
+ }
612
+ },
613
+ allowUpdate: {
614
+ async handler(ctx) {
615
+ const userSession = ctx.meta.user;
616
+ return await this.allowUpdate(userSession);
617
+ }
618
+ },
619
+ allowDelete: {
620
+ async handler(ctx) {
621
+ const userSession = ctx.meta.user;
622
+ return await this.allowDelete(userSession);
623
+ }
587
624
  }
588
625
  };
589
626
  _.each(actions, function(action){
@@ -686,14 +723,15 @@ module.exports = {
686
723
  merged(schema) {
687
724
  let settings = schema.settings;
688
725
  let objectConfig = settings.objectConfig;
689
- if (objectConfig.enable_api) {
690
- _.each(schema.actions, (action, actionName) => {
691
- let rest = generateActionRestProp(actionName);
692
- if (rest.method) {
693
- action.rest = rest;
694
- }
695
- })
696
- }
726
+ // 先关闭对象服务action rest api, 否则会导致 action rest api 过多, 请求速度变慢.
727
+ // if (objectConfig.enable_api) {
728
+ // _.each(schema.actions, (action, actionName) => {
729
+ // let rest = generateActionRestProp(actionName);
730
+ // if (rest.method) {
731
+ // action.rest = rest;
732
+ // }
733
+ // })
734
+ // }
697
735
  if (objectConfig.enable_graphql || true) { // TODO object.yml添加enable_graphql属性
698
736
  _.each(schema.actions, (action, actionName) => {
699
737
  let gpObj = generateActionGraphqlProp(actionName, objectConfig);
@@ -187,12 +187,12 @@ class ObjectServiceDispatcher {
187
187
  return await this.callAction(`getRecordView`, { userSession, context });
188
188
  }
189
189
 
190
- async createDefaulRecordView(userSession){
191
- return await this.callAction(`createDefaulRecordView`, {userSession});
190
+ async createDefaultRecordView(userSession){
191
+ return await this.callAction(`createDefaultRecordView`, {userSession});
192
192
  }
193
193
 
194
- async getDefaulRecordView(userSession){
195
- return await this.callAction(`getDefaulRecordView`, {userSession});
194
+ async getDefaultRecordView(userSession){
195
+ return await this.callAction(`getDefaultRecordView`, {userSession});
196
196
  }
197
197
 
198
198
  async getRelateds(){
@@ -123,11 +123,14 @@ export class SteedosDataSourceType implements Dictionary {
123
123
  return this._driver;
124
124
  }
125
125
 
126
- async getObjects() {
126
+ async getObjects(useCache = true) {
127
127
  // if(!this.schema.metadataRegister){
128
128
  // return this._objects
129
129
  // }
130
130
  // return await this.schema.metadataRegister.getObjectsConfig(this.name);
131
+ if(useCache === false){
132
+ await this.flushCacheObjects();
133
+ }
131
134
  return this.getCacheObjects();
132
135
  }
133
136