spice-js 2.7.4 → 2.7.7
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/build/models/SpiceModel.js +22 -4
- package/package.json +1 -1
- package/src/models/SpiceModel.js +31 -4
|
@@ -244,6 +244,16 @@ class SpiceModel {
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
get props() {
|
|
247
|
+
// Dynamically look up schema from spice.schemas for zero-downtime updates
|
|
248
|
+
// Fall back to stored props for backward compatibility
|
|
249
|
+
if (this.type && typeof spice !== 'undefined' && spice.schemas) {
|
|
250
|
+
var dynamicSchema = spice.schemas[this.type] || spice.schemas[this.type.toLowerCase()];
|
|
251
|
+
|
|
252
|
+
if (dynamicSchema) {
|
|
253
|
+
return dynamicSchema;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
247
257
|
return this[_props];
|
|
248
258
|
}
|
|
249
259
|
|
|
@@ -1894,11 +1904,19 @@ class SpiceModel {
|
|
|
1894
1904
|
|
|
1895
1905
|
var modifiers = ((_this18$_serializers = _this18[_serializers]) == null ? void 0 : (_this18$_serializers$ = _this18$_serializers[type]) == null ? void 0 : _this18$_serializers$.modifiers) || [];
|
|
1896
1906
|
|
|
1897
|
-
for (var
|
|
1907
|
+
for (var i = 0; i < modifiers.length; i++) {
|
|
1908
|
+
var modifier = modifiers[i];
|
|
1909
|
+
|
|
1898
1910
|
try {
|
|
1899
|
-
|
|
1911
|
+
var result = yield modifier(data, old_data, _this18[_ctx], _this18.type); // Guard against modifiers that return undefined
|
|
1912
|
+
|
|
1913
|
+
if (result !== undefined) {
|
|
1914
|
+
data = result;
|
|
1915
|
+
} else {
|
|
1916
|
+
console.warn("Modifier #" + i + " for type=" + _this18.type + " returned undefined, keeping previous data");
|
|
1917
|
+
}
|
|
1900
1918
|
} catch (error) {
|
|
1901
|
-
console.error("Modifier error in do_serialize:", error.stack);
|
|
1919
|
+
console.error("Modifier error in do_serialize (type=" + _this18.type + ", modifier #" + i + "):", error instanceof Error ? error.stack : "Non-Error thrown: " + JSON.stringify(error));
|
|
1902
1920
|
}
|
|
1903
1921
|
} // Ensure data is always an array for consistent processing.
|
|
1904
1922
|
|
|
@@ -1957,7 +1975,7 @@ class SpiceModel {
|
|
|
1957
1975
|
|
|
1958
1976
|
return yield doSerialize();
|
|
1959
1977
|
} catch (error) {
|
|
1960
|
-
console.error("Error in do_serialize:", error.stack);
|
|
1978
|
+
console.error("Error in do_serialize:", error instanceof Error ? error.stack : "Non-Error thrown: " + JSON.stringify(error));
|
|
1961
1979
|
throw error;
|
|
1962
1980
|
}
|
|
1963
1981
|
})();
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -229,6 +229,14 @@ export default class SpiceModel {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
get props() {
|
|
232
|
+
// Dynamically look up schema from spice.schemas for zero-downtime updates
|
|
233
|
+
// Fall back to stored props for backward compatibility
|
|
234
|
+
if (this.type && typeof spice !== 'undefined' && spice.schemas) {
|
|
235
|
+
const dynamicSchema = spice.schemas[this.type] || spice.schemas[this.type.toLowerCase()];
|
|
236
|
+
if (dynamicSchema) {
|
|
237
|
+
return dynamicSchema;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
232
240
|
return this[_props];
|
|
233
241
|
}
|
|
234
242
|
|
|
@@ -1678,11 +1686,25 @@ export default class SpiceModel {
|
|
|
1678
1686
|
|
|
1679
1687
|
// Cache the modifiers lookup for the specified type.
|
|
1680
1688
|
const modifiers = this[_serializers]?.[type]?.modifiers || [];
|
|
1681
|
-
for (
|
|
1689
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
1690
|
+
const modifier = modifiers[i];
|
|
1682
1691
|
try {
|
|
1683
|
-
|
|
1692
|
+
const result = await modifier(data, old_data, this[_ctx], this.type);
|
|
1693
|
+
// Guard against modifiers that return undefined
|
|
1694
|
+
if (result !== undefined) {
|
|
1695
|
+
data = result;
|
|
1696
|
+
} else {
|
|
1697
|
+
console.warn(
|
|
1698
|
+
`Modifier #${i} for type=${this.type} returned undefined, keeping previous data`
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1684
1701
|
} catch (error) {
|
|
1685
|
-
console.error(
|
|
1702
|
+
console.error(
|
|
1703
|
+
`Modifier error in do_serialize (type=${this.type}, modifier #${i}):`,
|
|
1704
|
+
error instanceof Error ?
|
|
1705
|
+
error.stack
|
|
1706
|
+
: `Non-Error thrown: ${JSON.stringify(error)}`
|
|
1707
|
+
);
|
|
1686
1708
|
}
|
|
1687
1709
|
}
|
|
1688
1710
|
|
|
@@ -1735,7 +1757,12 @@ export default class SpiceModel {
|
|
|
1735
1757
|
}
|
|
1736
1758
|
return await doSerialize();
|
|
1737
1759
|
} catch (error) {
|
|
1738
|
-
console.error(
|
|
1760
|
+
console.error(
|
|
1761
|
+
"Error in do_serialize:",
|
|
1762
|
+
error instanceof Error ?
|
|
1763
|
+
error.stack
|
|
1764
|
+
: `Non-Error thrown: ${JSON.stringify(error)}`
|
|
1765
|
+
);
|
|
1739
1766
|
throw error;
|
|
1740
1767
|
}
|
|
1741
1768
|
}
|