spice-js 2.6.85 → 2.7.1
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/, +0 -0
- package/build/models/SpiceModel.js +9 -68
- package/package.json +1 -1
- package/src/models/SpiceModel.js +9 -69
package/,
ADDED
|
File without changes
|
|
@@ -1924,84 +1924,25 @@ class SpiceModel {
|
|
|
1924
1924
|
var requestedColumns = _this18.parseRequestedColumns(args == null ? void 0 : args.columns); // Cache the modifiers lookup for the specified type.
|
|
1925
1925
|
|
|
1926
1926
|
|
|
1927
|
-
var modifiers = ((_this18$_serializers = _this18[_serializers]) == null ? void 0 : (_this18$_serializers$ = _this18$_serializers[type]) == null ? void 0 : _this18$_serializers$.modifiers) || []; //
|
|
1928
|
-
|
|
1929
|
-
var fieldModifiers = [];
|
|
1930
|
-
var genericModifiers = [];
|
|
1927
|
+
var modifiers = ((_this18$_serializers = _this18[_serializers]) == null ? void 0 : (_this18$_serializers$ = _this18$_serializers[type]) == null ? void 0 : _this18$_serializers$.modifiers) || []; // Run modifiers serially
|
|
1931
1928
|
|
|
1932
1929
|
for (var modifier of modifiers) {
|
|
1933
|
-
// Skip field-specific modifiers if columns specified and
|
|
1930
|
+
// Skip field-specific modifiers if columns specified and field is not requested
|
|
1934
1931
|
if (requestedColumns && modifier.field && !requestedColumns.has(modifier.field) && !(modifier.sourceField && requestedColumns.has(modifier.sourceField))) {
|
|
1935
1932
|
continue;
|
|
1936
|
-
} // Field modifiers have a .field property and .execute function - they can run in parallel
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
if (modifier.field && typeof modifier.execute === "function") {
|
|
1940
|
-
fieldModifiers.push(modifier);
|
|
1941
|
-
} else {
|
|
1942
|
-
genericModifiers.push(modifier);
|
|
1943
1933
|
}
|
|
1944
|
-
} // Run generic modifiers serially first (they may transform the data structure)
|
|
1945
1934
|
|
|
1946
|
-
|
|
1947
|
-
for (var _modifier of genericModifiers) {
|
|
1948
1935
|
try {
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
console.error("Modifier error in do_serialize (generic):", error.stack);
|
|
1953
|
-
}
|
|
1954
|
-
} // ⚡ OPTIMIZED: Run field-specific modifiers in PARALLEL - each populates a different field
|
|
1955
|
-
|
|
1936
|
+
// Handle both function modifiers and object modifiers with .execute
|
|
1937
|
+
var executeFn = typeof modifier === "function" ? modifier : modifier.execute;
|
|
1938
|
+
var result = yield executeFn(data, old_data, _this18[_ctx], _this18.type); // Only assign if modifier returned a value to prevent data corruption
|
|
1956
1939
|
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
var dataArray = _originalIsArray ? data : [data]; // Run all field modifiers in parallel
|
|
1961
|
-
|
|
1962
|
-
var fieldResults = yield Promise.allSettled(fieldModifiers.map(
|
|
1963
|
-
/*#__PURE__*/
|
|
1964
|
-
function () {
|
|
1965
|
-
var _ref17 = _asyncToGenerator(function* (modifier) {
|
|
1966
|
-
try {
|
|
1967
|
-
// Each modifier gets a copy of data and returns its field mappings
|
|
1968
|
-
var result = yield modifier.execute(_originalIsArray ? [...dataArray] : dataArray[0], old_data, _this18[_ctx], _this18.type);
|
|
1969
|
-
return {
|
|
1970
|
-
field: modifier.field,
|
|
1971
|
-
result
|
|
1972
|
-
};
|
|
1973
|
-
} catch (error) {
|
|
1974
|
-
console.error("Modifier error for field " + modifier.field + ":", error.stack);
|
|
1975
|
-
return {
|
|
1976
|
-
field: modifier.field,
|
|
1977
|
-
result: null,
|
|
1978
|
-
error
|
|
1979
|
-
};
|
|
1980
|
-
}
|
|
1981
|
-
});
|
|
1982
|
-
|
|
1983
|
-
return function (_x3) {
|
|
1984
|
-
return _ref17.apply(this, arguments);
|
|
1985
|
-
};
|
|
1986
|
-
}())); // Merge results - each field modifier added its field to the data items
|
|
1987
|
-
|
|
1988
|
-
for (var outcome of fieldResults) {
|
|
1989
|
-
if (outcome.status === "fulfilled" && outcome.value.result) {
|
|
1990
|
-
var {
|
|
1991
|
-
field,
|
|
1992
|
-
result
|
|
1993
|
-
} = outcome.value;
|
|
1994
|
-
var resultArray = Array.isArray(result) ? result : [result]; // Copy the mapped field from each result item to the corresponding data item
|
|
1995
|
-
|
|
1996
|
-
for (var i = 0; i < dataArray.length && i < resultArray.length; i++) {
|
|
1997
|
-
if (resultArray[i] && resultArray[i][field] !== undefined) {
|
|
1998
|
-
dataArray[i][field] = resultArray[i][field];
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
1940
|
+
if (result !== undefined) {
|
|
1941
|
+
data = result;
|
|
2001
1942
|
}
|
|
1943
|
+
} catch (error) {
|
|
1944
|
+
console.error("Modifier error in do_serialize:", error.stack);
|
|
2002
1945
|
}
|
|
2003
|
-
|
|
2004
|
-
data = _originalIsArray ? dataArray : dataArray[0];
|
|
2005
1946
|
} // Ensure data is always an array for consistent processing.
|
|
2006
1947
|
|
|
2007
1948
|
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -1727,12 +1727,9 @@ export default class SpiceModel {
|
|
|
1727
1727
|
// Cache the modifiers lookup for the specified type.
|
|
1728
1728
|
const modifiers = this[_serializers]?.[type]?.modifiers || [];
|
|
1729
1729
|
|
|
1730
|
-
//
|
|
1731
|
-
const fieldModifiers = [];
|
|
1732
|
-
const genericModifiers = [];
|
|
1733
|
-
|
|
1730
|
+
// Run modifiers serially
|
|
1734
1731
|
for (const modifier of modifiers) {
|
|
1735
|
-
// Skip field-specific modifiers if columns specified and
|
|
1732
|
+
// Skip field-specific modifiers if columns specified and field is not requested
|
|
1736
1733
|
if (
|
|
1737
1734
|
requestedColumns &&
|
|
1738
1735
|
modifier.field &&
|
|
@@ -1742,75 +1739,18 @@ export default class SpiceModel {
|
|
|
1742
1739
|
continue;
|
|
1743
1740
|
}
|
|
1744
1741
|
|
|
1745
|
-
// Field modifiers have a .field property and .execute function - they can run in parallel
|
|
1746
|
-
if (modifier.field && typeof modifier.execute === "function") {
|
|
1747
|
-
fieldModifiers.push(modifier);
|
|
1748
|
-
} else {
|
|
1749
|
-
genericModifiers.push(modifier);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
// Run generic modifiers serially first (they may transform the data structure)
|
|
1754
|
-
for (const modifier of genericModifiers) {
|
|
1755
1742
|
try {
|
|
1743
|
+
// Handle both function modifiers and object modifiers with .execute
|
|
1756
1744
|
const executeFn =
|
|
1757
1745
|
typeof modifier === "function" ? modifier : modifier.execute;
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
error.stack
|
|
1763
|
-
);
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
// ⚡ OPTIMIZED: Run field-specific modifiers in PARALLEL - each populates a different field
|
|
1768
|
-
if (fieldModifiers.length > 0) {
|
|
1769
|
-
const originalIsArray = Array.isArray(data);
|
|
1770
|
-
const dataArray = originalIsArray ? data : [data];
|
|
1771
|
-
|
|
1772
|
-
// Run all field modifiers in parallel
|
|
1773
|
-
const fieldResults = await Promise.allSettled(
|
|
1774
|
-
fieldModifiers.map(async (modifier) => {
|
|
1775
|
-
try {
|
|
1776
|
-
// Each modifier gets a copy of data and returns its field mappings
|
|
1777
|
-
const result = await modifier.execute(
|
|
1778
|
-
originalIsArray ? [...dataArray] : dataArray[0],
|
|
1779
|
-
old_data,
|
|
1780
|
-
this[_ctx],
|
|
1781
|
-
this.type
|
|
1782
|
-
);
|
|
1783
|
-
return { field: modifier.field, result };
|
|
1784
|
-
} catch (error) {
|
|
1785
|
-
console.error(
|
|
1786
|
-
`Modifier error for field ${modifier.field}:`,
|
|
1787
|
-
error.stack
|
|
1788
|
-
);
|
|
1789
|
-
return { field: modifier.field, result: null, error };
|
|
1790
|
-
}
|
|
1791
|
-
})
|
|
1792
|
-
);
|
|
1793
|
-
|
|
1794
|
-
// Merge results - each field modifier added its field to the data items
|
|
1795
|
-
for (const outcome of fieldResults) {
|
|
1796
|
-
if (outcome.status === "fulfilled" && outcome.value.result) {
|
|
1797
|
-
const { field, result } = outcome.value;
|
|
1798
|
-
const resultArray = Array.isArray(result) ? result : [result];
|
|
1799
|
-
|
|
1800
|
-
// Copy the mapped field from each result item to the corresponding data item
|
|
1801
|
-
for (
|
|
1802
|
-
let i = 0;
|
|
1803
|
-
i < dataArray.length && i < resultArray.length;
|
|
1804
|
-
i++
|
|
1805
|
-
) {
|
|
1806
|
-
if (resultArray[i] && resultArray[i][field] !== undefined) {
|
|
1807
|
-
dataArray[i][field] = resultArray[i][field];
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1746
|
+
const result = await executeFn(data, old_data, this[_ctx], this.type);
|
|
1747
|
+
// Only assign if modifier returned a value to prevent data corruption
|
|
1748
|
+
if (result !== undefined) {
|
|
1749
|
+
data = result;
|
|
1810
1750
|
}
|
|
1751
|
+
} catch (error) {
|
|
1752
|
+
console.error("Modifier error in do_serialize:", error.stack);
|
|
1811
1753
|
}
|
|
1812
|
-
|
|
1813
|
-
data = originalIsArray ? dataArray : dataArray[0];
|
|
1814
1754
|
}
|
|
1815
1755
|
|
|
1816
1756
|
// Ensure data is always an array for consistent processing.
|