@dynamatix/cat-shared 0.0.99 → 0.0.100

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.
@@ -97,18 +97,20 @@ async function resolveDeletionDescription(doc, auditConfig) {
97
97
  return await resolveExpressionDescription(doc, expression, 'direct');
98
98
  }
99
99
 
100
- // Utility to build a fieldName -> dataType map from formConfig.sections
101
- function buildFieldTypeMap(sections) {
100
+ // Utility to build a fieldName -> dataType map from multiple formConfig.sections
101
+ function buildFieldTypeMapFromConfigs(formConfigs) {
102
102
  const map = {};
103
- function extract(sections) {
103
+ function extractFields(sections) {
104
104
  for (const section of sections || []) {
105
105
  if (section.fields) {
106
106
  for (const f of section.fields) map[f.fieldName] = f.dataType;
107
107
  }
108
- if (section.sections) extract(section.sections);
108
+ if (section.sections) extractFields(section.sections);
109
109
  }
110
110
  }
111
- extract(sections);
111
+ for (const config of formConfigs) {
112
+ extractFields(config.sections);
113
+ }
112
114
  return map;
113
115
  }
114
116
 
@@ -118,9 +120,9 @@ function applyAuditMiddleware(schema, collectionName) {
118
120
  const auditConfig = await AuditConfigModel.findOne({ collectionName });
119
121
  if (!auditConfig?.trackCreation) return;
120
122
 
121
- // Fetch form config and build fieldTypeMap once
122
- const formConfig = await FormConfigurationModel.findOne({ collectionName });
123
- const fieldTypeMap = formConfig ? buildFieldTypeMap(formConfig.sections) : {};
123
+ // Fetch all form configs and build fieldTypeMap once
124
+ const formConfigs = await FormConfigurationModel.find({ collectionName });
125
+ const fieldTypeMap = buildFieldTypeMapFromConfigs(formConfigs);
124
126
 
125
127
  const context = getContext();
126
128
  const userId = context?.userId || 'anonymous';
@@ -191,9 +193,9 @@ function applyAuditMiddleware(schema, collectionName) {
191
193
  const auditConfig = await AuditConfigModel.findOne({ collectionName });
192
194
  if (!auditConfig?.fields?.length) return;
193
195
 
194
- // Fetch form config and build fieldTypeMap once
195
- const formConfig = await FormConfigurationModel.findOne({ collectionName });
196
- const fieldTypeMap = formConfig ? buildFieldTypeMap(formConfig.sections) : {};
196
+ // Fetch all form configs and build fieldTypeMap once
197
+ const formConfigs = await FormConfigurationModel.find({ collectionName });
198
+ const fieldTypeMap = buildFieldTypeMapFromConfigs(formConfigs);
197
199
 
198
200
  const update = this.getUpdate();
199
201
  let logs = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/cat-shared",
3
- "version": "0.0.99",
3
+ "version": "0.0.100",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"