@reekon-tools/boldr-utils 1.4.8 → 1.4.9

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.
@@ -29,22 +29,16 @@ function normalizeUnitForMathJS(unit) {
29
29
  function normalizeMapping(mapping) {
30
30
  if (typeof mapping === 'string') {
31
31
  // Legacy format: just the ID
32
- console.log('šŸ”§ Converting legacy string mapping:', mapping);
33
32
  return { id: mapping, type: 'measurement' };
34
33
  }
35
34
  // New format: ensure type defaults to 'measurement' and handle 'column' as 'measurement'
36
35
  const normalizedType = mapping.type === 'column' ? 'measurement' : mapping.type || 'measurement';
37
- console.log('šŸ”§ Normalizing mapping:', mapping, '→', {
38
- id: mapping.id,
39
- type: normalizedType,
40
- });
41
36
  return { id: mapping.id, type: normalizedType };
42
37
  }
43
38
  // Unified formula evaluation function
44
39
  export function evaluateFormula({ expression, mappings, valueMap, unit, formulas = [], scope, }) {
45
40
  // Legacy mode: if scope is provided, use it directly
46
41
  if (scope) {
47
- console.log('šŸ“œ Using legacy scope mode');
48
42
  try {
49
43
  const normalizedUnit = normalizeUnitForMathJS(unit);
50
44
  const compiled = compile(expression);
@@ -68,9 +62,6 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
68
62
  const evaluationStack = new Set(); // For circular dependency detection
69
63
  const cache = new Map(); // Local cache for this evaluation session
70
64
  function evaluateNestedFormula(formulaId, currentExpression, currentMappings) {
71
- console.log(`šŸ” Evaluating nested formula: ${formulaId}`);
72
- console.log(`šŸ“ Expression: "${currentExpression}"`);
73
- console.log('šŸ—ŗļø Current mappings:', currentMappings);
74
65
  // Check for circular dependency
75
66
  if (evaluationStack.has(formulaId)) {
76
67
  throw new Error(`Circular dependency detected involving formula: ${formulaId}`);
@@ -78,36 +69,26 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
78
69
  // Check cache first
79
70
  const cacheKey = `${formulaId}_${unit}`;
80
71
  if (cache.has(cacheKey)) {
81
- console.log(`šŸ’¾ Using cached result for ${formulaId}`);
82
72
  return cache.get(cacheKey);
83
73
  }
84
74
  evaluationStack.add(formulaId);
85
75
  try {
86
76
  const scope = {};
87
77
  const normalizedUnit = normalizeUnitForMathJS(unit);
88
- console.log(`šŸ”„ Converting to unit: ${unit} → ${normalizedUnit}`);
89
78
  // Build scope by resolving each variable
90
79
  for (const [variable, rawMapping] of Object.entries(currentMappings)) {
91
- console.log(`\nšŸ”§ Processing variable "${variable}":`, rawMapping);
92
80
  const mapping = normalizeMapping(rawMapping);
93
- console.log(`āœ… Normalized mapping:`, mapping);
94
81
  if (mapping.type === 'measurement') {
95
82
  // Handle measurement/column reference
96
- console.log(`šŸ“Š Looking up measurement ID "${mapping.id}" in valueMap`);
97
83
  const micrometers = valueMap[mapping.id] ?? 0;
98
- console.log(`šŸ“ˆ Found value: ${micrometers} micrometers`);
99
84
  if (micrometers === 0) {
100
85
  console.warn(`āš ļø Zero or missing value for mapping ID "${mapping.id}"`);
101
- console.log('šŸ—‚ļø Available valueMap keys:', Object.keys(valueMap));
102
86
  }
103
87
  const valueInUnit = mathUnit(micrometers, 'um').toNumber(normalizedUnit);
104
- console.log(`šŸ”¢ Converted to ${normalizedUnit}: ${valueInUnit}`);
105
88
  scope[variable] = valueInUnit;
106
- console.log(`āœ… Set scope["${variable}"] = ${valueInUnit}`);
107
89
  }
108
90
  else if (mapping.type === 'formula') {
109
91
  // Handle formula reference - recursively evaluate
110
- console.log(`šŸ”„ Recursively evaluating formula "${mapping.id}"`);
111
92
  const referencedFormula = formulas.find((f) => f.id === mapping.id);
112
93
  if (!referencedFormula) {
113
94
  throw new Error(`Referenced formula not found: ${mapping.id}`);
@@ -116,25 +97,17 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
116
97
  const nestedResult = evaluateNestedFormula(referencedFormula.id, referencedFormula.expression, referencedFormula.variableToColumnMap);
117
98
  // Convert result to current unit
118
99
  const resultInUnit = mathUnit(nestedResult, 'um').toNumber(normalizedUnit);
119
- console.log(`šŸ”¢ Nested formula result in ${normalizedUnit}: ${resultInUnit}`);
120
100
  scope[variable] = resultInUnit;
121
- console.log(`āœ… Set scope["${variable}"] = ${resultInUnit} (from formula)`);
122
101
  }
123
102
  }
124
- console.log('\nšŸŽÆ Final scope built:', scope);
125
103
  // Evaluate the formula expression
126
- console.log(`šŸ“Š Compiling expression: "${currentExpression}"`);
127
104
  const compiled = compile(currentExpression);
128
- console.log('🧮 Evaluating with scope:', scope);
129
105
  const result = compiled.evaluate(scope);
130
- console.log('šŸ“‹ Raw evaluation result:', result, typeof result);
131
106
  const asUnit = mathUnit(result, normalizedUnit);
132
- console.log('šŸ“ As unit object:', asUnit.toString());
133
107
  if (!asUnit.equalBase(mathUnit('1 um'))) {
134
108
  throw new Error(`Incompatible unit: ${asUnit.formatUnits()} is not compatible with ${normalizedUnit}`);
135
109
  }
136
110
  const finalResult = Math.round(asUnit.toNumber('um'));
137
- console.log(`šŸŽÆ Final result: ${finalResult} micrometers`);
138
111
  // Cache the result
139
112
  cache.set(cacheKey, finalResult);
140
113
  return finalResult;
@@ -145,7 +118,6 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
145
118
  }
146
119
  try {
147
120
  const result = evaluateNestedFormula('root', expression, mappings);
148
- console.log(`šŸŽ‰ Formula evaluation completed successfully: ${result}`);
149
121
  return result;
150
122
  }
151
123
  catch (err) {
@@ -92,7 +92,7 @@ export interface Template extends Timestamps {
92
92
  orgName: string;
93
93
  parentFolderId?: string | null;
94
94
  }
95
- export interface SelectedTemplate {
95
+ export interface SelectedTemplate extends FirestoreDoc {
96
96
  count: number;
97
97
  isPublic: boolean;
98
98
  name: string;
@@ -214,6 +214,7 @@ export interface ColumnConfig {
214
214
  withTolerance?: boolean;
215
215
  options?: string[];
216
216
  conversions?: Conversion[];
217
+ size?: number;
217
218
  }
218
219
  export interface Conversion {
219
220
  label: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reekon-tools/boldr-utils",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "description": "Shared utilities for formulas and measurement conversion used in Reekon apps",
5
5
  "author": "REEKON Tools",
6
6
  "license": "MIT",