@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.
- package/lib/actionsHandler.d.ts +1 -0
- package/lib/actionsHandler.js +12 -3
- package/lib/actionsHandler.js.map +1 -1
- package/lib/formula/formulaActionHandler.d.ts +1 -0
- package/lib/formula/formulaActionHandler.js +30 -0
- package/lib/formula/formulaActionHandler.js.map +1 -1
- package/lib/formula/type.d.ts +1 -0
- package/lib/formula/type.js.map +1 -1
- package/lib/lookup/LookupActionHandler.d.ts +2 -2
- package/lib/lookup/LookupActionHandler.js +32 -29
- package/lib/lookup/LookupActionHandler.js.map +1 -1
- package/lib/master-detail/masterDetailActionHandler.d.ts +5 -4
- package/lib/master-detail/masterDetailActionHandler.js +79 -63
- package/lib/master-detail/masterDetailActionHandler.js.map +1 -1
- package/lib/objects/index.js +7 -3
- package/lib/objects/index.js.map +1 -1
- package/lib/objects.service.js +11 -0
- package/lib/objects.service.js.map +1 -1
- package/lib/summary/summaryActionHandler.d.ts +1 -0
- package/lib/summary/summaryActionHandler.js +16 -0
- package/lib/summary/summaryActionHandler.js.map +1 -1
- package/package.json +2 -2
- package/src/actionsHandler.ts +10 -3
- package/src/formula/formulaActionHandler.ts +28 -0
- package/src/formula/type.ts +2 -1
- package/src/lookup/LookupActionHandler.ts +21 -29
- package/src/master-detail/masterDetailActionHandler.ts +50 -60
- package/src/objects/index.ts +7 -4
- package/src/objects.service.ts +9 -0
- package/src/summary/summaryActionHandler.ts +14 -0
|
@@ -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}
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
205
|
+
let mastersInfo = await this.getMastersInfo(objectApiName);
|
|
193
206
|
let mastersName = [];
|
|
194
|
-
_.each(
|
|
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
|
-
|
|
207
|
-
|
|
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
|
-
|
|
218
|
-
|
|
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
|
-
|
|
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}
|
|
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
|
|
247
|
+
let detailsInfo = await this.getDetailsInfo(objectApiName);
|
|
246
248
|
let detailsName = [];
|
|
247
|
-
_.each(
|
|
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
|
-
|
|
260
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
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.
|
|
361
|
-
await this.broker.call('metadata.
|
|
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
|
}
|
package/src/objects/index.ts
CHANGED
|
@@ -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
|
}
|
package/src/objects.service.ts
CHANGED
|
@@ -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;
|