@kaspernj/api-maker 1.0.281 → 1.0.283
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/package.json +1 -1
- package/src/base-model.mjs +18 -5
- package/src/collection.mjs +3 -1
package/package.json
CHANGED
package/src/base-model.mjs
CHANGED
|
@@ -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 = {}
|
|
@@ -408,8 +420,9 @@ export default class BaseModel {
|
|
|
408
420
|
return this._identifierKey
|
|
409
421
|
}
|
|
410
422
|
|
|
411
|
-
isAssociationLoaded (associationName)
|
|
412
|
-
|
|
423
|
+
isAssociationLoaded = (associationName) => this.isAssociationLoadedUnderscore(inflection.underscore(associationName))
|
|
424
|
+
isAssociationLoadedUnderscore (associationNameUnderscore) {
|
|
425
|
+
if (associationNameUnderscore in this.relationshipsCache) return true
|
|
413
426
|
return false
|
|
414
427
|
}
|
|
415
428
|
|
|
@@ -908,7 +921,7 @@ export default class BaseModel {
|
|
|
908
921
|
_readModelDataFromArgs (args) {
|
|
909
922
|
this.abilities = args.data.b || {}
|
|
910
923
|
this.collection = args.collection
|
|
911
|
-
this.modelData = args.data.a
|
|
924
|
+
this.modelData = objectToUnderscore(args.data.a)
|
|
912
925
|
this.preloadedRelationships = args.data.r
|
|
913
926
|
}
|
|
914
927
|
|
package/src/collection.mjs
CHANGED
|
@@ -110,7 +110,9 @@ export default class ApiMakerCollection {
|
|
|
110
110
|
|
|
111
111
|
return digg(model.relationships, reflectionNameUnderscore)
|
|
112
112
|
} else {
|
|
113
|
-
|
|
113
|
+
const relationshipsLoaded = uniqunize(Object.keys(model.relationships).concat(Object.keys(model.relationshipsCache)))
|
|
114
|
+
|
|
115
|
+
throw new Error(`${reflectionName} hasnt been loaded yet on ${model.modelClassData().name}. Loaded was: ${relationshipsLoaded.join(", ")}`)
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|