spice-js 2.7.5 → 2.7.8
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 +28 -5
- package/package.json +1 -1
- package/src/models/SpiceModel.js +25 -2
|
@@ -13,12 +13,12 @@ var _fix = require("../utility/fix");
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
-
|
|
18
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
17
|
|
|
20
18
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
19
|
|
|
20
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
21
|
+
|
|
22
22
|
var co = require("co");
|
|
23
23
|
|
|
24
24
|
var regeneratorRuntime = require("regenerator-runtime");
|
|
@@ -170,12 +170,25 @@ class SpiceModel {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
args.props = applySchemaOverrides(removeDynamicProps(args.props), args.collection);
|
|
173
|
-
this[_props] = args.props;
|
|
173
|
+
this[_props] = args.props; // Get dynamic schema for zero-downtime field updates
|
|
174
|
+
// Merge with static props to ensure new fields are also copied to instance
|
|
175
|
+
|
|
176
|
+
var effectiveProps = args.props;
|
|
177
|
+
|
|
178
|
+
if (typeof spice !== "undefined" && spice.schemas && args.collection) {
|
|
179
|
+
var dynamicSchema = spice.schemas[args.collection] || spice.schemas[args.collection.toLowerCase()];
|
|
180
|
+
|
|
181
|
+
if (dynamicSchema) {
|
|
182
|
+
effectiveProps = _extends({}, args.props, dynamicSchema);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
174
185
|
|
|
175
|
-
for (var i in
|
|
186
|
+
for (var i in effectiveProps) {
|
|
176
187
|
if (args.args != undefined) {
|
|
177
188
|
if (args.args[i] != undefined) {
|
|
178
|
-
|
|
189
|
+
var propDef = effectiveProps[i] || {};
|
|
190
|
+
|
|
191
|
+
switch (propDef.type) {
|
|
179
192
|
case String:
|
|
180
193
|
case "string":
|
|
181
194
|
{
|
|
@@ -244,6 +257,16 @@ class SpiceModel {
|
|
|
244
257
|
}
|
|
245
258
|
|
|
246
259
|
get props() {
|
|
260
|
+
// Dynamically look up schema from spice.schemas for zero-downtime updates
|
|
261
|
+
// Fall back to stored props for backward compatibility
|
|
262
|
+
if (this.type && typeof spice !== "undefined" && spice.schemas) {
|
|
263
|
+
var dynamicSchema = spice.schemas[this.type] || spice.schemas[this.type.toLowerCase()];
|
|
264
|
+
|
|
265
|
+
if (dynamicSchema) {
|
|
266
|
+
return dynamicSchema;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
247
270
|
return this[_props];
|
|
248
271
|
}
|
|
249
272
|
|
package/package.json
CHANGED
package/src/models/SpiceModel.js
CHANGED
|
@@ -158,10 +158,24 @@ export default class SpiceModel {
|
|
|
158
158
|
args.collection
|
|
159
159
|
);
|
|
160
160
|
this[_props] = args.props;
|
|
161
|
-
|
|
161
|
+
|
|
162
|
+
// Get dynamic schema for zero-downtime field updates
|
|
163
|
+
// Merge with static props to ensure new fields are also copied to instance
|
|
164
|
+
let effectiveProps = args.props;
|
|
165
|
+
if (typeof spice !== "undefined" && spice.schemas && args.collection) {
|
|
166
|
+
const dynamicSchema =
|
|
167
|
+
spice.schemas[args.collection] ||
|
|
168
|
+
spice.schemas[args.collection.toLowerCase()];
|
|
169
|
+
if (dynamicSchema) {
|
|
170
|
+
effectiveProps = { ...args.props, ...dynamicSchema };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (let i in effectiveProps) {
|
|
162
175
|
if (args.args != undefined) {
|
|
163
176
|
if (args.args[i] != undefined) {
|
|
164
|
-
|
|
177
|
+
const propDef = effectiveProps[i] || {};
|
|
178
|
+
switch (propDef.type) {
|
|
165
179
|
case String:
|
|
166
180
|
case "string": {
|
|
167
181
|
this[i] = args.args[i];
|
|
@@ -229,6 +243,15 @@ export default class SpiceModel {
|
|
|
229
243
|
}
|
|
230
244
|
|
|
231
245
|
get props() {
|
|
246
|
+
// Dynamically look up schema from spice.schemas for zero-downtime updates
|
|
247
|
+
// Fall back to stored props for backward compatibility
|
|
248
|
+
if (this.type && typeof spice !== "undefined" && spice.schemas) {
|
|
249
|
+
const dynamicSchema =
|
|
250
|
+
spice.schemas[this.type] || spice.schemas[this.type.toLowerCase()];
|
|
251
|
+
if (dynamicSchema) {
|
|
252
|
+
return dynamicSchema;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
232
255
|
return this[_props];
|
|
233
256
|
}
|
|
234
257
|
|