@dynamatix/cat-shared 0.0.122 → 0.0.124
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.
|
@@ -15,6 +15,8 @@ const customResolvers = {
|
|
|
15
15
|
|
|
16
16
|
// Expression-based description resolver: resolves ${fieldName} in the expression using doc, and via Lookup if needed
|
|
17
17
|
async function resolveExpressionDescription(doc, expression, resolverType) {
|
|
18
|
+
console.log("expression-", expression);
|
|
19
|
+
console.log("resolverType-", resolverType);
|
|
18
20
|
const matches = [...expression.matchAll(/\$\{([^}]+)\}/g)];
|
|
19
21
|
let result = expression;
|
|
20
22
|
for (const match of matches) {
|
|
@@ -33,12 +35,14 @@ async function resolveExpressionDescription(doc, expression, resolverType) {
|
|
|
33
35
|
async function resolveDescription(field, doc) {
|
|
34
36
|
const modelName = doc.constructor.modelName;
|
|
35
37
|
const config = await ValueReferenceMap.findOne({ field, model: modelName });
|
|
38
|
+
console.log("config-", config);
|
|
36
39
|
if (!config) return field;
|
|
37
40
|
|
|
38
41
|
if (config.descriptionField && config.descriptionField.includes('${')) {
|
|
42
|
+
console.log("config.descriptionField", config.descriptionField);
|
|
39
43
|
return await resolveExpressionDescription(doc, config.descriptionField, config.descriptionResolverType);
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
console.log("config.descriptionResolverType", config.descriptionResolverType);
|
|
42
46
|
switch (config.descriptionResolverType) {
|
|
43
47
|
case 'lookup': {
|
|
44
48
|
const lookupId = doc[config.descriptionField];
|
|
@@ -71,7 +75,12 @@ async function resolveEntityDescription(doc, auditConfig) {
|
|
|
71
75
|
const field = auditConfig.descriptionResolutorForExternalData;
|
|
72
76
|
const value = doc[field];
|
|
73
77
|
// Try to resolve via ValueReferenceMap
|
|
78
|
+
console.log("field-", field);
|
|
74
79
|
const map = await ValueReferenceMap.findOne({ field });
|
|
80
|
+
console.log("map-", map);
|
|
81
|
+
if (map?.descriptionResolverType === 'displayFieldReturn') {
|
|
82
|
+
return map.descriptionField;
|
|
83
|
+
}
|
|
75
84
|
if (map && map.descriptionField && map.descriptionField.includes('${')) {
|
|
76
85
|
return await resolveExpressionDescription(doc, map.descriptionField, map.descriptionResolverType);
|
|
77
86
|
}
|
|
@@ -206,9 +215,10 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
206
215
|
const entityDescription = await resolveEntityDescription(result, auditConfig);
|
|
207
216
|
|
|
208
217
|
for (const field of auditConfig.fields) {
|
|
218
|
+
console.log("field", field);
|
|
209
219
|
const hasChanged =
|
|
210
220
|
update?.$set?.hasOwnProperty(field) || update?.hasOwnProperty(field);
|
|
211
|
-
|
|
221
|
+
console.log("hasChanged", hasChanged);
|
|
212
222
|
if (hasChanged) {
|
|
213
223
|
const newValue = update?.$set?.[field] ?? update?.[field];
|
|
214
224
|
const oldValue = this._originalDoc ? this._originalDoc[field] : '';
|
|
@@ -228,10 +238,11 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
228
238
|
lookupOldName = '';
|
|
229
239
|
}
|
|
230
240
|
}
|
|
231
|
-
|
|
232
241
|
// Convert null/undefined to empty string for comparison
|
|
233
242
|
let displayOldValue = lookupOldName ?? oldValue ?? '';
|
|
234
243
|
let displayNewValue = lookupNewName ?? newValue ?? '';
|
|
244
|
+
console.log("displayOldValue", displayOldValue);
|
|
245
|
+
console.log("displayNewValue", displayNewValue);
|
|
235
246
|
// --- Add pound prefix if needed ---
|
|
236
247
|
const dataType = fieldTypeMap[field];
|
|
237
248
|
if (dataType === 'pound') {
|
|
@@ -240,6 +251,7 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
240
251
|
}
|
|
241
252
|
if (displayOldValue !== displayNewValue) {
|
|
242
253
|
const fieldDescription = await resolveDescription(field, result);
|
|
254
|
+
console.log("fieldDescription-", fieldDescription);
|
|
243
255
|
logs.push({
|
|
244
256
|
name: fieldDescription,
|
|
245
257
|
entity: entityDescription,
|
|
@@ -255,13 +267,16 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
255
267
|
}
|
|
256
268
|
}
|
|
257
269
|
}
|
|
270
|
+
console.log("logs", logs);
|
|
258
271
|
logs = logs.filter(log => {
|
|
259
272
|
// Convert null/undefined to empty string for comparison
|
|
260
273
|
const oldVal = log.oldValue ?? '';
|
|
261
274
|
const newVal = log.newValue ?? '';
|
|
262
275
|
return oldVal !== newVal;
|
|
263
276
|
});
|
|
277
|
+
console.log("logs.length", logs.length);
|
|
264
278
|
if (logs.length) {
|
|
279
|
+
console.log("logs.length", logs.length);
|
|
265
280
|
await AuditLog.insertMany(logs);
|
|
266
281
|
await updateContextAuditCount(contextId, logs.length);
|
|
267
282
|
if (onAuditLogCreated) {
|
package/models/index.js
CHANGED
|
@@ -7,4 +7,5 @@ export { default as DocumentModel } from './document.model.js';
|
|
|
7
7
|
export { default as WorkflowAlertModel } from './workflow-alert.model.js';
|
|
8
8
|
export { default as WorkflowConfigModel } from './workflow-config.model.js';
|
|
9
9
|
export { default as DocumentHistoryModel } from './document-history.model.js';
|
|
10
|
-
export { default as MetaModel } from './meta.model.js';
|
|
10
|
+
export { default as MetaModel } from './meta.model.js';
|
|
11
|
+
export { default as PropertyMetaDataModel } from './property-metadata.model.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import applyAuditMiddleware from "../middlewares/audit.middleware";
|
|
3
|
+
|
|
4
|
+
const propertyMetadataSchema = new mongoose.Schema({
|
|
5
|
+
collectionName: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
index: true
|
|
9
|
+
},
|
|
10
|
+
propertyName: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
index: true
|
|
14
|
+
},
|
|
15
|
+
type: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true,
|
|
18
|
+
enum: ['String', 'Number', 'Boolean', 'Date', 'ObjectId', 'Array', 'Object', 'Mixed'],
|
|
19
|
+
index: true
|
|
20
|
+
},
|
|
21
|
+
aliasName: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: false,
|
|
24
|
+
default: ""
|
|
25
|
+
},
|
|
26
|
+
referenceCollection: {
|
|
27
|
+
type: String,
|
|
28
|
+
required: false,
|
|
29
|
+
default: null
|
|
30
|
+
},
|
|
31
|
+
// Additional recommended fields
|
|
32
|
+
description: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: false,
|
|
35
|
+
default: ""
|
|
36
|
+
},
|
|
37
|
+
isRequired: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
required: true,
|
|
40
|
+
default: false,
|
|
41
|
+
index: true
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
timestamps: true
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Compound indexes for efficient querying
|
|
48
|
+
propertyMetadataSchema.index({ collectionName: 1, propertyName: 1 }, { unique: true });
|
|
49
|
+
propertyMetadataSchema.index({ collectionName: 1, isActive: 1 });
|
|
50
|
+
propertyMetadataSchema.index({ type: 1, isActive: 1 });
|
|
51
|
+
propertyMetadataSchema.index({ category: 1, isActive: 1 });
|
|
52
|
+
|
|
53
|
+
// Apply audit middleware
|
|
54
|
+
applyAuditMiddleware(propertyMetadataSchema, "PropertyMetaData");
|
|
55
|
+
|
|
56
|
+
const PropertyMetaDataModel = mongoose.models.PropertyMetaData || mongoose.model('PropertyMetaData', propertyMetadataSchema);
|
|
57
|
+
export default PropertyMetaDataModel;
|