@kaspernj/api-maker 1.0.281 → 1.0.282

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/base-model.mjs +15 -3
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.281",
19
+ "version": "1.0.282",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -17,6 +17,18 @@ import Services from "./services.mjs"
17
17
  import ValidationError from "./validation-error.mjs"
18
18
  import {ValidationErrors} from "./validation-errors.mjs"
19
19
 
20
+ const objectToUnderscore = (object) => {
21
+ const newObject = {}
22
+
23
+ for (const key in object) {
24
+ const underscoreKey = inflection.underscore(key)
25
+
26
+ newObject[underscoreKey] = object[key]
27
+ }
28
+
29
+ return newObject
30
+ }
31
+
20
32
  export default class BaseModel {
21
33
  static apiMakerType = "BaseModel"
22
34
 
@@ -171,10 +183,10 @@ export default class BaseModel {
171
183
  this._readModelDataFromArgs(args)
172
184
  } else if (args.a) {
173
185
  this.abilities = args.b || {}
174
- this.modelData = args.a
186
+ this.modelData = objectToUnderscore(args.a)
175
187
  } else if (args) {
176
188
  this.abilities = {}
177
- this.modelData = args
189
+ this.modelData = objectToUnderscore(args)
178
190
  } else {
179
191
  this.abilities = {}
180
192
  this.modelData = {}
@@ -908,7 +920,7 @@ export default class BaseModel {
908
920
  _readModelDataFromArgs (args) {
909
921
  this.abilities = args.data.b || {}
910
922
  this.collection = args.collection
911
- this.modelData = args.data.a
923
+ this.modelData = objectToUnderscore(args.data.a)
912
924
  this.preloadedRelationships = args.data.r
913
925
  }
914
926