@bedrockio/model 0.1.20 → 0.1.22

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.
@@ -121,6 +121,8 @@ function attributesToMongoose(attributes) {
121
121
  } else if (key === 'attributes' && type === 'object') {
122
122
  val = attributesToMongoose(val);
123
123
  }
124
+ } else if (Array.isArray(val)) {
125
+ val = val.map(attributesToMongoose);
124
126
  } else if ((0, _lodash.isPlainObject)(val)) {
125
127
  if (isScopeExtension(val)) {
126
128
  applyScopeExtension(val, definition);
@@ -178,6 +180,7 @@ function applyExtensions(typedef) {
178
180
  applySyntaxExtensions(typedef);
179
181
  applyUniqueExtension(typedef);
180
182
  applyTupleExtension(typedef);
183
+ applyDateExtension(typedef);
181
184
  }
182
185
  function applySyntaxExtensions(typedef) {
183
186
  const {
@@ -240,6 +243,15 @@ function applyTupleExtension(typedef) {
240
243
  typedef.validate = (0, _validation.getTupleValidator)(type);
241
244
  }
242
245
  }
246
+ function applyDateExtension(typedef) {
247
+ const {
248
+ type,
249
+ default: defaultValue
250
+ } = typedef;
251
+ if (type === 'Date' && defaultValue === 'now') {
252
+ typedef.default = Date.now;
253
+ }
254
+ }
243
255
 
244
256
  // Intercepts "unique" options and changes to "softUnique".
245
257
  function applyUniqueExtension(typedef) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/schema.js CHANGED
@@ -131,6 +131,8 @@ function attributesToMongoose(attributes) {
131
131
  } else if (key === 'attributes' && type === 'object') {
132
132
  val = attributesToMongoose(val);
133
133
  }
134
+ } else if (Array.isArray(val)) {
135
+ val = val.map(attributesToMongoose);
134
136
  } else if (isPlainObject(val)) {
135
137
  if (isScopeExtension(val)) {
136
138
  applyScopeExtension(val, definition);
@@ -193,6 +195,7 @@ function applyExtensions(typedef) {
193
195
  applySyntaxExtensions(typedef);
194
196
  applyUniqueExtension(typedef);
195
197
  applyTupleExtension(typedef);
198
+ applyDateExtension(typedef);
196
199
  }
197
200
 
198
201
  function applySyntaxExtensions(typedef) {
@@ -248,6 +251,13 @@ function applyTupleExtension(typedef) {
248
251
  }
249
252
  }
250
253
 
254
+ function applyDateExtension(typedef) {
255
+ const { type, default: defaultValue } = typedef;
256
+ if (type === 'Date' && defaultValue === 'now') {
257
+ typedef.default = Date.now;
258
+ }
259
+ }
260
+
251
261
  // Intercepts "unique" options and changes to "softUnique".
252
262
  function applyUniqueExtension(typedef) {
253
263
  if (typedef.unique === true) {