@steedos/service-metadata-objects 2.1.52 → 2.1.56

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.
@@ -18,6 +18,9 @@ export class LookupActionHandler {
18
18
 
19
19
  async deleteAll(objectConfig){
20
20
  try {
21
+ if (!objectConfig) {
22
+ return;
23
+ }
21
24
  await this.deleteAllLookups(objectConfig);
22
25
  return true
23
26
  } catch (error) {
@@ -63,14 +66,14 @@ export class LookupActionHandler {
63
66
  }
64
67
  }
65
68
 
66
- getDetailKey(objectApiName) {
67
- return `$steedos.$lookup.#${objectApiName}.detail`
69
+ getDetailKey(objectApiName, detailApiName) {
70
+ return `$steedos.$lookup.#${objectApiName}.$detail.${detailApiName}`
68
71
  }
69
72
 
70
73
  async getDetails(objectApiName: string) {
71
- let { metadata } = (await this.broker.call('metadata.get', { key: this.getDetailKey(objectApiName) }, { meta: {} })) || {};
72
74
  let detailName = [];
73
- _.each(metadata, function(item){
75
+ const detailsInfo = await this.getDetailsInfo(objectApiName);
76
+ _.each(detailsInfo, function(item){
74
77
  if(item && _.isString(item)){
75
78
  const foo = item.split('.');
76
79
  if(foo.length > 0){
@@ -81,39 +84,28 @@ export class LookupActionHandler {
81
84
  return _.uniq(detailName);
82
85
  }
83
86
  async getDetailsInfo(objectApiName: string){
84
- let { metadata } = (await this.broker.call('metadata.get', { key: this.getDetailKey(objectApiName) }, { meta: {} })) || {};
85
- return metadata || [];
87
+ const detailsInfo = [];
88
+ let records = (await this.broker.call('metadata.filter', { key: this.getDetailKey(objectApiName, "*") }, { meta: {} })) || {};
89
+ for await (const item of records) {
90
+ const metadata = item?.metadata;
91
+ if(metadata){
92
+ detailsInfo.push(metadata);
93
+ }
94
+ }
95
+ return detailsInfo;
86
96
  }
87
97
 
88
98
  async removeDetail(objectApiName: any, detailObjectApiName: string, detailField: any) {
89
- let detail = await this.getDetailsInfo(objectApiName);
90
- let maps = [];
91
- if (detail) {
92
- maps = detail;
93
- }
94
99
  const detailFullName = `${detailObjectApiName}.${detailField.name}`
95
- maps = _.difference(maps, [detailFullName]);
96
- await this.broker.call('metadata.add', { key: this.getDetailKey(objectApiName), data: maps }, { meta: {} })
97
- // this.broker.emit(`@${objectApiName}.detailsChanged`, { objectApiName, detailObjectApiName, detailFieldName: detailField.name, detailFieldReferenceToFieldName: detailField.reference_to_field });
100
+ await this.broker.call('metadata.delete', { key: this.getDetailKey(objectApiName, detailFullName) }, { meta: {} });
98
101
  return true;
99
102
  }
100
103
 
101
104
  async addDetail(objectApiName: any, detailObjectApiName: string, detailField: any) {
102
- let detail = await this.getDetailsInfo(objectApiName);
103
- let maps = [];
104
- if (detail) {
105
- maps = detail;
106
- }
107
105
  const detailFullName = `${detailObjectApiName}.${detailField.name}`
108
- let count = _.filter(maps, function(o) { return o.startsWith(`${detailObjectApiName}.`) && o != detailFullName});
109
- if (count.length < 1) {
110
- maps.push(detailFullName);
111
- maps = _.uniq(maps);
112
- await this.broker.call('metadata.add', { key: this.getDetailKey(objectApiName), data: maps }, { meta: {} })
113
- this.broker.emit(`@${objectApiName}.detailsChanged`, { objectApiName, detailObjectApiName, detailFieldName: detailField.name, detailFieldReferenceToFieldName: detailField.reference_to_field });
114
- return true;
115
- }
116
- return false;
106
+ await this.broker.call('metadata.add', { key: this.getDetailKey(objectApiName, detailFullName), data: detailFullName }, { meta: {} })
107
+ this.broker.broadcast(`@${objectApiName}.detailsChanged`, { objectApiName, detailObjectApiName, detailFieldName: detailField.name, detailFieldReferenceToFieldName: detailField.reference_to_field });
108
+ return true;
117
109
  }
118
110
 
119
111
  // async removeDetail(objectApiName: any, detailObjectApiName: string) {
@@ -126,7 +118,7 @@ export class LookupActionHandler {
126
118
  // }
127
119
 
128
120
  async deleteObjectLookups(objectApiName: string) {
129
- await this.broker.call('metadata.delete', { key: this.getDetailKey(objectApiName) }, { meta: {} });
121
+ await this.broker.call('metadata.fuzzyDelete', { key: this.getDetailKey(objectApiName, '*') }, { meta: {} });
130
122
  return true;
131
123
  }
132
124
  }
@@ -79,7 +79,21 @@ export class MasterDetailActionHandler{
79
79
  }
80
80
  return false
81
81
  }
82
-
82
+
83
+ async deleteAll(objectConfig) {
84
+ try {
85
+ if (!objectConfig) {
86
+ return;
87
+ }
88
+ await this.deleteObjectMasterDetails(objectConfig.name);
89
+ await this.broker.call('metadata.fuzzyDelete', {key: this.getDetailKey('*', objectConfig.name, '*')}, {meta: {}});
90
+ return true;
91
+ } catch (error) {
92
+ this.broker.logger.error(error);
93
+ }
94
+ return false;
95
+ }
96
+
83
97
  async remove(objectConfig){
84
98
  try {
85
99
  await this.removeObjectMasterDetails(objectConfig);
@@ -183,15 +197,14 @@ export class MasterDetailActionHandler{
183
197
  await this.checkMasterDetails(objectApiName);
184
198
  }
185
199
 
186
-
187
- getMasterKey(objectApiName){
188
- return `$steedos.$masterDetail.#${objectApiName}.master`
200
+ getMasterKey(objectApiName, masterApiName){
201
+ return `$steedos.$masterDetail.#${objectApiName}.$master.${masterApiName}`
189
202
  }
190
203
 
191
204
  async getMasters(objectApiName: string){
192
- let { metadata } = (await this.broker.call('metadata.get', {key: this.getMasterKey(objectApiName)}, {meta: {}})) || {};
205
+ let mastersInfo = await this.getMastersInfo(objectApiName);
193
206
  let mastersName = [];
194
- _.each(metadata, function(item){
207
+ _.each(mastersInfo, function(item){
195
208
  if(item && _.isString(item)){
196
209
  const foo = item.split('.');
197
210
  if(foo.length > 0){
@@ -203,48 +216,37 @@ export class MasterDetailActionHandler{
203
216
  }
204
217
 
205
218
  async getMastersInfo(objectApiName: string){
206
- let { metadata } = (await this.broker.call('metadata.get', {key: this.getMasterKey(objectApiName)}, {meta: {}})) || {};
207
- return metadata || [];
219
+ const mastersInfo = [];
220
+ let records = (await this.broker.call('metadata.filter', { key: this.getMasterKey(objectApiName, "*") }, { meta: {} })) || {};
221
+ for await (const item of records) {
222
+ const metadata = item?.metadata;
223
+ if(metadata){
224
+ mastersInfo.push(metadata);
225
+ }
226
+ }
227
+ return mastersInfo;
208
228
  }
209
229
 
210
230
  async addMaster(objectApiName: any, masterObjectApiName: string, field: any){
211
- let master = await this.getMastersInfo(objectApiName);
212
- let maps = [];
213
- if(master){
214
- maps = master;
215
- }
216
231
  const masterFullName = `${masterObjectApiName}.${field.name}`
217
- let count = _.filter(maps, function(o) { return o.startsWith(`${masterObjectApiName}.`) && o != masterFullName});
218
- if (count.length < 1) {
219
- maps.push(masterFullName);
220
- maps = _.uniq(maps);
221
- await this.broker.call('metadata.add', {key: this.getMasterKey(objectApiName), data: maps}, {meta: {}})
222
- return true;
223
- }
224
- console.log(`maps`, maps, masterFullName)
225
- return false;
232
+ await this.broker.call('metadata.add', {key: this.getMasterKey(objectApiName, masterFullName), data: masterFullName}, {meta: {}})
233
+ return true;
226
234
  }
227
235
 
228
236
  async removeMaster(objectApiName: any, masterObjectApiName: string, masterFieldName: any){
229
- let master = await this.getMastersInfo(objectApiName);
230
- let maps = [];
231
- if (master) {
232
- maps = master;
233
- }
234
237
  const masterFullName = `${masterObjectApiName}.${masterFieldName}`
235
- maps = _.difference(maps, [masterFullName]);
236
- await this.broker.call('metadata.add', { key: this.getMasterKey(objectApiName), data: maps }, { meta: {} })
238
+ await this.broker.call('metadata.delete', { key: this.getMasterKey(objectApiName, masterFullName) }, { meta: {} })
237
239
  return true;
238
240
  }
239
241
 
240
- getDetailKey(objectApiName){
241
- return `$steedos.$masterDetail.#${objectApiName}.detail`
242
+ getDetailKey(objectApiName, detailObjectApiName, detailFieldName){
243
+ return `$steedos.$masterDetail.#${objectApiName}.$detail.${detailObjectApiName}.${detailFieldName}`
242
244
  }
243
245
 
244
246
  async getDetails(objectApiName: string){
245
- let { metadata } = (await this.broker.call('metadata.get', {key: this.getDetailKey(objectApiName)}, {meta: {}})) || {};
247
+ let detailsInfo = await this.getDetailsInfo(objectApiName);
246
248
  let detailsName = [];
247
- _.each(metadata, function(item){
249
+ _.each(detailsInfo, function(item){
248
250
  if(item && _.isString(item)){
249
251
  const foo = item.split('.');
250
252
  if(foo.length > 0){
@@ -256,38 +258,26 @@ export class MasterDetailActionHandler{
256
258
  }
257
259
 
258
260
  async getDetailsInfo(objectApiName: string){
259
- let { metadata } = (await this.broker.call('metadata.get', {key: this.getDetailKey(objectApiName)}, {meta: {}})) || {};
260
- return metadata || [];
261
+ const detailsInfo = [];
262
+ let records = (await this.broker.call('metadata.filter', { key: this.getDetailKey(objectApiName, "*", "*") }, { meta: {} })) || {};
263
+ for await (const item of records) {
264
+ const metadata = item?.metadata;
265
+ if(metadata){
266
+ detailsInfo.push(metadata);
267
+ }
268
+ }
269
+ return detailsInfo;
261
270
  }
262
271
 
263
272
  async addDetail(objectApiName: any, detailObjectApiName: string, detailField: any){
264
- let detail = await this.getDetailsInfo(objectApiName);
265
- let maps = [];
266
- if(detail){
267
- maps = detail;
268
- }
269
273
  const detailFullName = `${detailObjectApiName}.${detailField.name}`
270
- let count = _.filter(maps, function(o) { return o.startsWith(`${detailObjectApiName}.`) && o != detailFullName});
271
- if (count.length < 1) {
272
- maps.push(detailFullName);
273
- maps = _.uniq(maps);
274
- await this.broker.call('metadata.add', {key: this.getDetailKey(objectApiName), data: maps}, {meta: {}})
275
- this.broker.emit(`@${objectApiName}.detailsChanged`, { objectApiName, detailObjectApiName, detailFieldName: detailField.name, detailFieldReferenceToFieldName: detailField.reference_to_field });
276
- return true;
277
- }
278
- return false;
274
+ await this.broker.call('metadata.add', {key: this.getDetailKey(objectApiName, detailObjectApiName, detailField.name), data: detailFullName}, {meta: {}})
275
+ this.broker.broadcast(`@${objectApiName}.detailsChanged`, { objectApiName, detailObjectApiName, detailFieldName: detailField.name, detailFieldReferenceToFieldName: detailField.reference_to_field });
276
+ return true;
279
277
  }
280
-
281
278
 
282
279
  async removeDetail(objectApiName: any, detailObjectApiName: string, detailFieldName: any){
283
- let detail = await this.getDetailsInfo(objectApiName);
284
- let maps = [];
285
- if (detail) {
286
- maps = detail;
287
- }
288
- const detailFullName = `${detailObjectApiName}.${detailFieldName}`
289
- maps = _.difference(maps, [detailFullName]);
290
- await this.broker.call('metadata.add', { key: this.getDetailKey(objectApiName), data: maps }, { meta: {} })
280
+ await this.broker.call('metadata.delete', { key: this.getDetailKey(objectApiName, detailObjectApiName, detailFieldName)}, { meta: {} })
291
281
  return true;
292
282
  }
293
283
 
@@ -357,8 +347,8 @@ export class MasterDetailActionHandler{
357
347
  }
358
348
 
359
349
  async deleteObjectMasterDetails(objectApiName: string){
360
- await this.broker.call('metadata.delete', {key: this.getMasterKey(objectApiName)}, {meta: {}});
361
- await this.broker.call('metadata.delete', {key: this.getDetailKey(objectApiName)}, {meta: {}});
350
+ await this.broker.call('metadata.fuzzyDelete', {key: this.getMasterKey(objectApiName, '*')}, {meta: {}});
351
+ await this.broker.call('metadata.fuzzyDelete', {key: this.getDetailKey(objectApiName, '*', '*')}, {meta: {}});
362
352
  return true;
363
353
  }
364
354
  }
@@ -22,7 +22,7 @@ async function getBaseObjectConfig(ctx, datasourceName) {
22
22
  serviceName,
23
23
  metadataType,
24
24
  metadataApiName: metadataApiName,
25
- });
25
+ }, {meta: ctx.meta});
26
26
  return configs && configs.length > 0 ? configs[0]?.metadata : null;
27
27
  }
28
28
 
@@ -35,8 +35,9 @@ async function getObjectConfigs(ctx, objectApiName) {
35
35
  serviceName,
36
36
  metadataType,
37
37
  metadataApiName: objectApiName,
38
- }
38
+ }, {meta: ctx.meta}
39
39
  );
40
+ // console.log(`getObjectConfigs ==== `, getObjectConfigs.length);
40
41
  return _.compact(_.map(objectConfigs, "metadata"));
41
42
  }
42
43
 
@@ -105,8 +106,8 @@ export async function refreshObject(ctx, objectApiName) {
105
106
  let objectConfig: any = {};
106
107
 
107
108
  const objectConfigs = await getObjectConfigs(ctx, objectApiName);
108
-
109
109
  if (objectConfigs.length == 0) {
110
+ // console.log(`refreshObject objectConfigs`, objectConfigs.length)
110
111
  return null;
111
112
  }
112
113
 
@@ -232,7 +233,9 @@ export async function refreshObject(ctx, objectApiName) {
232
233
  if (maxSortNoField) {
233
234
  objectConfig.fields_serial_number = maxSortNoField.sort_no;
234
235
  }
235
- } catch (error) {}
236
+ } catch (error) {
237
+ console.log(`refreshObject error`, error)
238
+ }
236
239
 
237
240
  return objectConfig;
238
241
  }
@@ -20,6 +20,12 @@ module.exports = {
20
20
  dependencies: ['metadata'],
21
21
 
22
22
  events: {
23
+ [`delete.metadata.${METADATA_TYPE}`]: {
24
+ async handler(ctx) {
25
+ const { objectApiName } = ctx.params;
26
+ return await this.objetActionHandlers.handleDeleteObject(ctx, objectApiName);
27
+ }
28
+ },
23
29
  [`$METADATA.${METADATA_TYPE}.*`]: {
24
30
  async handler(ctx) {
25
31
  return await this.objetActionHandlers.refresh(ctx);
@@ -209,6 +215,9 @@ module.exports = {
209
215
  await this.summaryActionHandler.add(objectConfig);
210
216
  }, async (objectConfig)=>{
211
217
  await this.lookupActionHandler.deleteAll(objectConfig);
218
+ await this.masterDetailActionHandler.deleteAll(objectConfig);
219
+ await this.formulaActionHandler.deleteAll(objectConfig);
220
+ await this.summaryActionHandler.deleteAll(objectConfig);
212
221
  }, async (objectConfig)=>{
213
222
  /**
214
223
  * 重算公式关系链时,可能存在待重算的对象还未进入缓存(但已经过了公式关系链计算过程)。所以进行延时
@@ -16,6 +16,20 @@ export class SummaryActionHandler {
16
16
  this.broker = broker;
17
17
  }
18
18
 
19
+ async deleteAll(objectConfig){
20
+ try {
21
+ if (!objectConfig) {
22
+ return;
23
+ }
24
+ // console.log(`deleteAll summary`, this.cacherKey(objectConfig.name, '*'))
25
+ await this.broker.call('metadata.fuzzyDelete', {key: this.cacherKey(objectConfig.name, '*')}, {meta: {}})
26
+ return true
27
+ } catch (error) {
28
+ this.broker.logger.error(error);
29
+ }
30
+ return false
31
+ }
32
+
19
33
  async getObjectConfig(objectApiName: string) {
20
34
  const data = await this.broker.call('objects.get', { objectApiName: objectApiName })
21
35
  return data ? data.metadata : null;