@kaspernj/api-maker 1.0.125 → 1.0.128

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 (58) hide show
  1. package/.eslintrc.js +39 -33
  2. package/__tests__/cable-connection-pool.test.js +4 -4
  3. package/__tests__/custom-error.test.js +13 -0
  4. package/__tests__/model-name.test.js +16 -10
  5. package/__tests__/routes-native.test.js +15 -33
  6. package/__tests__/support/task.js +5 -5
  7. package/__tests__/support/user.js +5 -5
  8. package/index.js +0 -4
  9. package/package.json +7 -6
  10. package/src/api.cjs +15 -15
  11. package/src/base-model.cjs +82 -81
  12. package/src/cable-connection-pool.cjs +11 -11
  13. package/src/cable-subscription-pool.cjs +34 -34
  14. package/src/cable-subscription.cjs +2 -2
  15. package/src/can-can-loader.jsx +7 -7
  16. package/src/can-can.cjs +17 -16
  17. package/src/collection.cjs +36 -36
  18. package/src/command-submit-data.cjs +10 -11
  19. package/src/commands-pool.cjs +13 -13
  20. package/src/custom-error.cjs +20 -14
  21. package/src/deserializer.cjs +7 -7
  22. package/src/devise.cjs +15 -15
  23. package/src/error-logger.cjs +9 -9
  24. package/src/event-connection.jsx +6 -6
  25. package/src/event-created.jsx +8 -8
  26. package/src/event-destroyed.jsx +6 -6
  27. package/src/event-emitter-listener.jsx +6 -6
  28. package/src/event-listener.jsx +8 -8
  29. package/src/event-model-class.jsx +6 -6
  30. package/src/event-updated.jsx +10 -10
  31. package/src/instance-of-class-name.cjs +5 -7
  32. package/src/key-value-store.cjs +21 -18
  33. package/src/logger.cjs +4 -4
  34. package/src/merge.cjs +4 -4
  35. package/src/model-events.cjs +6 -5
  36. package/src/model-name.cjs +6 -5
  37. package/src/model-prop-type.cjs +11 -13
  38. package/src/model-recipes-loader.cjs +4 -4
  39. package/src/model-recipes-model-loader.cjs +39 -14
  40. package/src/models-response-reader.cjs +10 -10
  41. package/src/money-formatter.cjs +11 -11
  42. package/src/params.cjs +7 -7
  43. package/src/preloaded.cjs +6 -6
  44. package/src/resource-route.cjs +14 -12
  45. package/src/resource-routes.jsx +9 -4
  46. package/src/result.cjs +7 -7
  47. package/src/routes-native.cjs +6 -6
  48. package/src/routes.cjs +1 -1
  49. package/src/serializer.cjs +9 -9
  50. package/src/services.cjs +3 -3
  51. package/src/session-status-updater.cjs +14 -14
  52. package/src/source-maps-loader.cjs +11 -11
  53. package/src/translated-collections.cjs +2 -1
  54. package/src/updated-attribute.jsx +17 -14
  55. package/src/validation-error.cjs +5 -8
  56. package/src/validation-errors.cjs +16 -16
  57. package/src/event-location-changed.jsx +0 -21
  58. package/src/history-listener.jsx +0 -20
@@ -3,21 +3,21 @@ const CableSubscription = require("./cable-subscription.cjs")
3
3
  const {dig} = require("diggerize")
4
4
 
5
5
  module.exports = class ApiMakerCableConnectionPool {
6
- static current() {
6
+ static current () {
7
7
  if (!global.apiMakerCableConnectionPool)
8
8
  global.apiMakerCableConnectionPool = new ApiMakerCableConnectionPool()
9
9
 
10
10
  return global.apiMakerCableConnectionPool
11
11
  }
12
12
 
13
- constructor() {
13
+ constructor () {
14
14
  this.cableSubscriptionPools = []
15
15
  this.connections = {}
16
16
  this.upcomingSubscriptionData = {}
17
17
  this.upcomingSubscriptions = {}
18
18
  }
19
19
 
20
- connectEventToExistingSubscription({path, subscription, value}) {
20
+ connectEventToExistingSubscription ({path, subscription, value}) {
21
21
  for (const cableSubscriptionPool of this.cableSubscriptionPools) {
22
22
  if (!cableSubscriptionPool.isConnected()) {
23
23
  continue
@@ -46,7 +46,7 @@ module.exports = class ApiMakerCableConnectionPool {
46
46
  return false
47
47
  }
48
48
 
49
- connectModelEvent({callback, path, value}) {
49
+ connectModelEvent ({callback, path, value}) {
50
50
  const subscription = new CableSubscription()
51
51
 
52
52
  subscription.events.addListener("received", callback)
@@ -102,27 +102,27 @@ module.exports = class ApiMakerCableConnectionPool {
102
102
  return subscription
103
103
  }
104
104
 
105
- connectCreated(modelName, callback) {
105
+ connectCreated (modelName, callback) {
106
106
  return this.connectModelEvent({callback, value: true, path: [modelName, "creates"]})
107
107
  }
108
108
 
109
- connectEvent(modelName, modelId, eventName, callback) {
109
+ connectEvent (modelName, modelId, eventName, callback) {
110
110
  return this.connectModelEvent({callback, value: modelId, path: [modelName, "events", eventName]})
111
111
  }
112
112
 
113
- connectDestroyed(modelName, modelId, callback) {
113
+ connectDestroyed (modelName, modelId, callback) {
114
114
  return this.connectModelEvent({callback, value: modelId, path: [modelName, "destroys"]})
115
115
  }
116
116
 
117
- connectModelClassEvent(modelName, eventName, callback) {
117
+ connectModelClassEvent (modelName, eventName, callback) {
118
118
  return this.connectModelEvent({callback, value: eventName, path: [modelName, "model_class_events"]})
119
119
  }
120
120
 
121
- connectUpdate(modelName, modelId, callback) {
121
+ connectUpdate (modelName, modelId, callback) {
122
122
  return this.connectModelEvent({callback, value: modelId, path: [modelName, "updates"]})
123
123
  }
124
124
 
125
- connectUpcoming() {
125
+ connectUpcoming () {
126
126
  const subscriptionData = this.upcomingSubscriptionData
127
127
  const subscriptions = this.upcomingSubscriptions
128
128
 
@@ -137,7 +137,7 @@ module.exports = class ApiMakerCableConnectionPool {
137
137
  this.cableSubscriptionPools.push(cableSubscriptionPool)
138
138
  }
139
139
 
140
- scheduleConnectUpcoming() {
140
+ scheduleConnectUpcoming () {
141
141
  if (this.scheduleConnectUpcomingTimeout)
142
142
  clearTimeout(this.scheduleConnectUpcomingTimeout)
143
143
 
@@ -6,12 +6,12 @@ const inflection = require("inflection")
6
6
  const Logger = require("./logger.cjs")
7
7
 
8
8
  module.exports = class ApiMakerCableSubscriptionPool {
9
- constructor() {
9
+ constructor () {
10
10
  this.activeSubscriptions = 0
11
11
  this.connected = false
12
12
  }
13
13
 
14
- connect(subscriptionData) {
14
+ connect (subscriptionData) {
15
15
  const globalData = CommandsPool.current().globalRequestData
16
16
 
17
17
  this.subscription = ChannelsConsumer.subscriptions.create(
@@ -28,7 +28,7 @@ module.exports = class ApiMakerCableSubscriptionPool {
28
28
  this.connected = true
29
29
  }
30
30
 
31
- forEachSubscription(callback) {
31
+ forEachSubscription (callback) {
32
32
  const modelIdModes = ["destroys", "updates"]
33
33
  const subscriptions = digg(this, "subscriptions")
34
34
 
@@ -43,24 +43,24 @@ module.exports = class ApiMakerCableSubscriptionPool {
43
43
  }
44
44
  }
45
45
 
46
- if (subscriptions[modelName]["creates"]) {
47
- for (const subscription of subscriptions[modelName]["creates"]) {
46
+ if (subscriptions[modelName].creates) {
47
+ for (const subscription of subscriptions[modelName].creates) {
48
48
  callback({mode: "creates", modelName, subscription})
49
49
  }
50
50
  }
51
51
 
52
- if (subscriptions[modelName]["model_class_events"]) {
53
- for (const eventName in subscriptions[modelName]["model_class_events"]) {
54
- for (const subscription of subscriptions[modelName]["model_class_events"][eventName]) {
52
+ if (subscriptions[modelName].model_class_events) {
53
+ for (const eventName in subscriptions[modelName].model_class_events) {
54
+ for (const subscription of subscriptions[modelName].model_class_events[eventName]) {
55
55
  callback({eventName, mode: "model_class_events", modelName, subscription})
56
56
  }
57
57
  }
58
58
  }
59
59
 
60
- if (subscriptions[modelName]["events"]) {
61
- for (const modelId in subscriptions[modelName]["events"]) {
62
- for (const eventName in subscriptions[modelName]["events"][modelId]) {
63
- for (const subscription of subscriptions[modelName]["events"][modelId][eventName]) {
60
+ if (subscriptions[modelName].events) {
61
+ for (const modelId in subscriptions[modelName].events) {
62
+ for (const eventName in subscriptions[modelName].events[modelId]) {
63
+ for (const subscription of subscriptions[modelName].events[modelId][eventName]) {
64
64
  callback({eventName, mode: "updates", modelId, modelName, subscription})
65
65
  }
66
66
  }
@@ -69,17 +69,17 @@ module.exports = class ApiMakerCableSubscriptionPool {
69
69
  }
70
70
  }
71
71
 
72
- isConnected() {
72
+ isConnected () {
73
73
  return digg(this, "connected")
74
74
  }
75
75
 
76
- onConnected() {
76
+ onConnected () {
77
77
  this.forEachSubscription(({subscription}) => {
78
78
  subscription.events.emit("connected")
79
79
  })
80
80
  }
81
81
 
82
- onReceived(rawData) {
82
+ onReceived (rawData) {
83
83
  const data = Deserializer.parse(rawData)
84
84
  const {a: args, e: eventName, m: model, mi: modelId, mt: modelType, t: type} = data
85
85
  const subscriptions = digg(this, "subscriptions")
@@ -94,29 +94,29 @@ module.exports = class ApiMakerCableSubscriptionPool {
94
94
  }
95
95
 
96
96
  if (type == "u") {
97
- for(const subscription of subscriptions[modelName]["updates"][modelId]) {
97
+ for (const subscription of subscriptions[modelName].updates[modelId]) {
98
98
  subscription.events.emit("received", {model})
99
99
  }
100
100
  } else if (type == "c") {
101
- for(const subscription of subscriptions[modelName]["creates"]) {
101
+ for (const subscription of subscriptions[modelName].creates) {
102
102
  subscription.events.emit("received", {model})
103
103
  }
104
104
  } else if (type == "d") {
105
105
  const destroySubscriptions = digg(subscriptions, modelName, "destroys", modelId)
106
106
 
107
- for(const subscription of destroySubscriptions) {
107
+ for (const subscription of destroySubscriptions) {
108
108
  subscription.events.emit("received", {model})
109
109
  }
110
110
  } else if (type == "e") {
111
111
  const eventSubscriptions = digg(subscriptions, modelName, "events", eventName, modelId)
112
112
 
113
- for(const subscription of eventSubscriptions) {
113
+ for (const subscription of eventSubscriptions) {
114
114
  subscription.events.emit("received", {args, eventName, model})
115
115
  }
116
116
  } else if (type == "mce") {
117
117
  const modelClassEventSubscriptions = digg(subscriptions, modelName, "model_class_events", eventName)
118
118
 
119
- for(const subscription of modelClassEventSubscriptions) {
119
+ for (const subscription of modelClassEventSubscriptions) {
120
120
  subscription.events.emit("received", {args, eventName})
121
121
  }
122
122
  } else {
@@ -124,7 +124,7 @@ module.exports = class ApiMakerCableSubscriptionPool {
124
124
  }
125
125
  }
126
126
 
127
- onUnsubscribe() {
127
+ onUnsubscribe () {
128
128
  Logger.log(`activeSubscriptions before unsub: ${this.activeSubscriptions}`)
129
129
  this.activeSubscriptions -= 1
130
130
  Logger.log(`activeSubscriptions after unsub: ${this.activeSubscriptions}`)
@@ -136,32 +136,32 @@ module.exports = class ApiMakerCableSubscriptionPool {
136
136
  }
137
137
  }
138
138
 
139
- registerSubscriptions(subscriptions) {
139
+ registerSubscriptions (subscriptions) {
140
140
  this.subscriptions = subscriptions
141
141
 
142
142
  Logger.log(`registerSubscriptions: ${subscriptions.length}`)
143
143
  Logger.log(subscriptions)
144
144
 
145
- for(const modelName in subscriptions) {
146
- if (subscriptions[modelName]["creates"]) {
147
- for(const subscription of subscriptions[modelName]["creates"]) {
145
+ for (const modelName in subscriptions) {
146
+ if (subscriptions[modelName].creates) {
147
+ for (const subscription of subscriptions[modelName].creates) {
148
148
  this.connectUnsubscriptionForSubscription(subscription)
149
149
  }
150
150
  }
151
151
 
152
- if (subscriptions[modelName]["events"]) {
153
- for(const eventName in subscriptions[modelName]["events"]) {
154
- for(const modelId in subscriptions[modelName]["events"][eventName]) {
155
- for(const subscription of subscriptions[modelName]["events"][eventName][modelId]) {
152
+ if (subscriptions[modelName].events) {
153
+ for (const eventName in subscriptions[modelName].events) {
154
+ for (const modelId in subscriptions[modelName].events[eventName]) {
155
+ for (const subscription of subscriptions[modelName].events[eventName][modelId]) {
156
156
  this.connectUnsubscriptionForSubscription(subscription)
157
157
  }
158
158
  }
159
159
  }
160
160
  }
161
161
 
162
- if (subscriptions[modelName]["updates"]) {
163
- for(const modelId in subscriptions[modelName]["updates"]) {
164
- for(const subscription of subscriptions[modelName]["updates"][modelId]) {
162
+ if (subscriptions[modelName].updates) {
163
+ for (const modelId in subscriptions[modelName].updates) {
164
+ for (const subscription of subscriptions[modelName].updates[modelId]) {
165
165
  this.connectUnsubscriptionForSubscription(subscription)
166
166
  }
167
167
  }
@@ -169,9 +169,9 @@ module.exports = class ApiMakerCableSubscriptionPool {
169
169
  }
170
170
  }
171
171
 
172
- connectUnsubscriptionForSubscription(subscription) {
172
+ connectUnsubscriptionForSubscription (subscription) {
173
173
  Logger.log("Connecting to unsubscribe on subscription")
174
- Logger.log({ subscription })
174
+ Logger.log({subscription})
175
175
 
176
176
  this.activeSubscriptions += 1
177
177
 
@@ -2,12 +2,12 @@ const EventEmitter = require("events")
2
2
  const Logger = require("./logger.cjs")
3
3
 
4
4
  module.exports = class ApiMakerCableSubscription {
5
- constructor() {
5
+ constructor () {
6
6
  this.events = new EventEmitter()
7
7
  this.subscribed = true
8
8
  }
9
9
 
10
- unsubscribe() {
10
+ unsubscribe () {
11
11
  if (!this.subscribed) {
12
12
  Logger.log("Unsubscribed already called")
13
13
  return
@@ -2,20 +2,20 @@ import ApiMakerEventEmitterListener from "./event-emitter-listener"
2
2
  import {digg, digs} from "diggerize"
3
3
  const CanCan = require("./can-can.cjs")
4
4
  const PropTypes = require("prop-types")
5
- const PropTypesExact = require("prop-types-exact")
5
+ const propTypesExact = require("prop-types-exact")
6
6
  const React = require("react")
7
7
 
8
8
  export default class ApiMakerCanCanLoader extends React.PureComponent {
9
- static propTypes = PropTypesExact({
9
+ static propTypes = propTypesExact({
10
10
  abilities: PropTypes.array.isRequired,
11
11
  component: PropTypes.object.isRequired
12
12
  })
13
13
 
14
- componentDidMount() {
14
+ componentDidMount () {
15
15
  this.loadAbilities()
16
16
  }
17
17
 
18
- async loadAbilities() {
18
+ async loadAbilities () {
19
19
  const canCan = CanCan.current()
20
20
  const {abilities} = digs(this.props, "abilities")
21
21
 
@@ -24,14 +24,14 @@ export default class ApiMakerCanCanLoader extends React.PureComponent {
24
24
  this.updateComponent({canCan})
25
25
  }
26
26
 
27
- render() {
27
+ render () {
28
28
  const canCan = CanCan.current()
29
29
  const events = digg(canCan, "events")
30
30
 
31
31
  return (
32
32
  <ApiMakerEventEmitterListener
33
- events={events}
34
33
  event="onResetAbilities"
34
+ events={events}
35
35
  onCalled={this.onResetAbilities}
36
36
  />
37
37
  )
@@ -42,7 +42,7 @@ export default class ApiMakerCanCanLoader extends React.PureComponent {
42
42
  this.loadAbilities()
43
43
  }
44
44
 
45
- updateComponent(updatedState) {
45
+ updateComponent (updatedState) {
46
46
  const {component} = digs(this.props, "component")
47
47
 
48
48
  if (component.shape) {
package/src/can-can.cjs CHANGED
@@ -5,7 +5,7 @@ const {ReadersWriterLock} = require("epic-locks")
5
5
  const Services = require("./services.cjs")
6
6
 
7
7
  module.exports = class ApiMakerCanCan {
8
- static current() {
8
+ static current () {
9
9
  if (!global.currentApiMakerCanCan) {
10
10
  global.currentApiMakerCanCan = new ApiMakerCanCan()
11
11
  }
@@ -13,7 +13,7 @@ module.exports = class ApiMakerCanCan {
13
13
  return global.currentApiMakerCanCan
14
14
  }
15
15
 
16
- constructor() {
16
+ constructor () {
17
17
  this.abilities = []
18
18
  this.abilitiesToLoad = []
19
19
  this.abilitiesToLoadData = []
@@ -21,19 +21,19 @@ module.exports = class ApiMakerCanCan {
21
21
  this.lock = new ReadersWriterLock()
22
22
  }
23
23
 
24
- can(ability, subject) {
25
- ability = inflection.underscore(ability)
26
- const foundAbility = this.findAbility(ability, subject)
24
+ can (ability, subject) {
25
+ let abilityToUse = inflection.underscore(ability)
26
+ const foundAbility = this.findAbility(abilityToUse, subject)
27
27
 
28
28
  if (foundAbility === undefined) {
29
29
  let subjectLabel = subject
30
30
 
31
31
  // Translate resource-models into class name strings
32
- if (typeof subject == "function" && subject["modelClassData"]) {
32
+ if (typeof subject == "function" && subject.modelClassData) {
33
33
  subjectLabel = digg(subject.modelClassData(), "name")
34
34
  }
35
35
 
36
- console.error(`Ability not loaded ${subjectLabel}#${ability}`)
36
+ console.error(`Ability not loaded ${subjectLabel}#${abilityToUse}`)
37
37
 
38
38
  return false
39
39
  } else {
@@ -41,11 +41,11 @@ module.exports = class ApiMakerCanCan {
41
41
  }
42
42
  }
43
43
 
44
- findAbility(ability, subject) {
44
+ findAbility (ability, subject) {
45
45
  return this.abilities.find((abilityData) => digg(abilityData, "subject") == subject && digg(abilityData, "ability") == ability)
46
46
  }
47
47
 
48
- isAbilityLoaded(ability, subject) {
48
+ isAbilityLoaded (ability, subject) {
49
49
  const foundAbility = this.findAbility(ability, subject)
50
50
 
51
51
  if (foundAbility !== undefined) {
@@ -55,8 +55,8 @@ module.exports = class ApiMakerCanCan {
55
55
  return false
56
56
  }
57
57
 
58
- async loadAbilities(abilities) {
59
- await this.lock.read(async() => {
58
+ async loadAbilities (abilities) {
59
+ await this.lock.read(async () => {
60
60
  const promises = []
61
61
 
62
62
  for (const abilityData of abilities) {
@@ -73,12 +73,13 @@ module.exports = class ApiMakerCanCan {
73
73
  })
74
74
  }
75
75
 
76
- loadAbility(ability, subject) {
76
+ loadAbility (ability, subject) {
77
77
  return new Promise((resolve) => {
78
78
  ability = inflection.underscore(ability)
79
79
 
80
80
  if (this.isAbilityLoaded(ability, subject)) {
81
- return resolve()
81
+ resolve()
82
+ return
82
83
  }
83
84
 
84
85
  const foundAbility = this.abilitiesToLoad.find((abilityToLoad) => digg(abilityToLoad, "ability") == ability && digg(abilityToLoad, "subject") == subject)
@@ -94,7 +95,7 @@ module.exports = class ApiMakerCanCan {
94
95
  })
95
96
  }
96
97
 
97
- queueAbilitiesRequest() {
98
+ queueAbilitiesRequest () {
98
99
  if (this.queueAbilitiesRequestTimeout) {
99
100
  clearTimeout(this.queueAbilitiesRequestTimeout)
100
101
  }
@@ -102,14 +103,14 @@ module.exports = class ApiMakerCanCan {
102
103
  this.queueAbilitiesRequestTimeout = setTimeout(() => this.sendAbilitiesRequest(), 0)
103
104
  }
104
105
 
105
- async resetAbilities() {
106
+ async resetAbilities () {
106
107
  await this.lock.write(() => {
107
108
  this.abilities = []
108
109
  })
109
110
  this.events.emit("onResetAbilities")
110
111
  }
111
112
 
112
- async sendAbilitiesRequest() {
113
+ async sendAbilitiesRequest () {
113
114
  const abilitiesToLoad = this.abilitiesToLoad
114
115
  const abilitiesToLoadData = this.abilitiesToLoadData
115
116
 
@@ -7,20 +7,20 @@ const ModelsResponseReader = require("./models-response-reader.cjs")
7
7
  const Result = require("./result.cjs")
8
8
 
9
9
  module.exports = class ApiMakerCollection {
10
- constructor(args, queryArgs = {}) {
10
+ constructor (args, queryArgs = {}) {
11
11
  this.queryArgs = queryArgs
12
12
  this.args = args
13
13
  }
14
14
 
15
- abilities(originalAbilities) {
15
+ abilities (originalAbilities) {
16
16
  const newAbilities = {}
17
17
 
18
- for(const originalAbilityName in originalAbilities) {
18
+ for (const originalAbilityName in originalAbilities) {
19
19
  const newModelName = inflection.underscore(originalAbilityName)
20
20
  const newValues = []
21
21
  const originalValues = originalAbilities[originalAbilityName]
22
22
 
23
- for(const originalAbilityName of originalValues) {
23
+ for (const originalAbilityName of originalValues) {
24
24
  const newAbilityName = inflection.underscore(originalAbilityName)
25
25
  newValues.push(newAbilityName)
26
26
  }
@@ -31,34 +31,34 @@ module.exports = class ApiMakerCollection {
31
31
  return this._merge({abilities: newAbilities})
32
32
  }
33
33
 
34
- accessibleBy(abilityName) {
34
+ accessibleBy (abilityName) {
35
35
  return this._merge({accessibleBy: inflection.underscore(abilityName)})
36
36
  }
37
37
 
38
- async count() {
38
+ async count () {
39
39
  const response = await this.clone()._merge({count: true})._response()
40
40
 
41
41
  return response.count
42
42
  }
43
43
 
44
- distinct() {
44
+ distinct () {
45
45
  return this._merge({distinct: true})
46
46
  }
47
47
 
48
- async each(callback) {
48
+ async each (callback) {
49
49
  const array = await this.toArray()
50
50
 
51
- for(const model in array) {
51
+ for (const model in array) {
52
52
  callback.call(model)
53
53
  }
54
54
  }
55
55
 
56
- async first() {
56
+ async first () {
57
57
  const models = await this.toArray()
58
58
  return models[0]
59
59
  }
60
60
 
61
- groupBy(...arrayOfTablesAndColumns) {
61
+ groupBy (...arrayOfTablesAndColumns) {
62
62
  const arrayOfTablesAndColumnsWithLowercaseColumns = arrayOfTablesAndColumns.map((tableAndColumn) => {
63
63
  if (Array.isArray(tableAndColumn)) {
64
64
  return [tableAndColumn[0], tableAndColumn[1].toLowerCase()]
@@ -74,18 +74,18 @@ module.exports = class ApiMakerCollection {
74
74
  })
75
75
  }
76
76
 
77
- isLoaded() {
77
+ isLoaded () {
78
78
  if (this.args.reflectionName in this.args.model.relationshipsCache)
79
79
  return true
80
80
 
81
81
  return false
82
82
  }
83
83
 
84
- limit(amount) {
84
+ limit (amount) {
85
85
  return this._merge({limit: amount})
86
86
  }
87
87
 
88
- loaded() {
88
+ loaded () {
89
89
  if (!(this.args.reflectionName in this.args.model.relationshipsCache)) {
90
90
  throw new Error(`${this.args.reflectionName} hasnt been loaded yet`)
91
91
  }
@@ -93,22 +93,22 @@ module.exports = class ApiMakerCollection {
93
93
  return this.args.model.relationshipsCache[this.args.reflectionName]
94
94
  }
95
95
 
96
- preload(preloadValue) {
96
+ preload (preloadValue) {
97
97
  return this._merge({preload: preloadValue})
98
98
  }
99
99
 
100
- page(page) {
100
+ page (page) {
101
101
  if (!page)
102
102
  page = 1
103
103
 
104
104
  return this._merge({page})
105
105
  }
106
106
 
107
- pageKey(pageKey) {
107
+ pageKey (pageKey) {
108
108
  return this._merge({pageKey})
109
109
  }
110
110
 
111
- params() {
111
+ params () {
112
112
  let params = {}
113
113
 
114
114
  if (this.queryArgs.params) params = merge(params, this.queryArgs.params)
@@ -128,15 +128,15 @@ module.exports = class ApiMakerCollection {
128
128
  return params
129
129
  }
130
130
 
131
- per(per) {
131
+ per (per) {
132
132
  return this._merge({per})
133
133
  }
134
134
 
135
- perKey(perKey) {
135
+ perKey (perKey) {
136
136
  return this._merge({perKey})
137
137
  }
138
138
 
139
- ransack(params) {
139
+ ransack (params) {
140
140
  if (params) {
141
141
  this._merge({ransack: params})
142
142
  }
@@ -144,26 +144,26 @@ module.exports = class ApiMakerCollection {
144
144
  return this
145
145
  }
146
146
 
147
- async result() {
147
+ async result () {
148
148
  const response = await this._response()
149
149
  const models = this._responseToModels(response)
150
150
  const result = new Result({collection: this, models, response})
151
151
  return result
152
152
  }
153
153
 
154
- searchKey(searchKey) {
155
- return this._merge({searchKey: searchKey})
154
+ searchKey (searchKey) {
155
+ return this._merge({searchKey})
156
156
  }
157
157
 
158
- select(originalSelect) {
158
+ select (originalSelect) {
159
159
  const newSelect = {}
160
160
 
161
- for(const originalModelName in originalSelect) {
161
+ for (const originalModelName in originalSelect) {
162
162
  const newModelName = inflection.underscore(originalModelName)
163
163
  const newValues = []
164
164
  const originalValues = originalSelect[originalModelName]
165
165
 
166
- for(const originalAttributeName of originalValues) {
166
+ for (const originalAttributeName of originalValues) {
167
167
  const newAttributeName = inflection.underscore(originalAttributeName)
168
168
  newValues.push(newAttributeName)
169
169
  }
@@ -174,10 +174,10 @@ module.exports = class ApiMakerCollection {
174
174
  return this._merge({select: newSelect})
175
175
  }
176
176
 
177
- selectColumns(originalSelect) {
177
+ selectColumns (originalSelect) {
178
178
  const newSelect = {}
179
179
 
180
- for(const originalModelName in originalSelect) {
180
+ for (const originalModelName in originalSelect) {
181
181
  const newModelName = inflection.underscore(inflection.underscore(originalModelName))
182
182
  const newValues = []
183
183
  const originalValues = originalSelect[originalModelName]
@@ -193,34 +193,34 @@ module.exports = class ApiMakerCollection {
193
193
  return this._merge({selectColumns: newSelect})
194
194
  }
195
195
 
196
- sort(sortBy) {
196
+ sort (sortBy) {
197
197
  return this._merge({ransack: {s: sortBy}})
198
198
  }
199
199
 
200
- async toArray() {
200
+ async toArray () {
201
201
  const response = await this._response()
202
202
  return this._responseToModels(response)
203
203
  }
204
204
 
205
- modelClass() {
205
+ modelClass () {
206
206
  const modelName = digg(this.args.modelClass.modelClassData(), "name")
207
207
 
208
208
  return digg(require("@kaspernj/api-maker/src/models"), modelName)
209
209
  }
210
210
 
211
- clone() {
211
+ clone () {
212
212
  const clonedQueryArgs = cloneDeep(this.queryArgs)
213
213
 
214
214
  return new ApiMakerCollection(this.args, clonedQueryArgs)
215
215
  }
216
216
 
217
- _merge(newQueryArgs) {
217
+ _merge (newQueryArgs) {
218
218
  merge(this.queryArgs, newQueryArgs)
219
219
 
220
220
  return this
221
221
  }
222
222
 
223
- _response() {
223
+ _response () {
224
224
  const modelClassData = this.args.modelClass.modelClassData()
225
225
 
226
226
  return CommandsPool.addCommand(
@@ -234,7 +234,7 @@ module.exports = class ApiMakerCollection {
234
234
  )
235
235
  }
236
236
 
237
- _responseToModels(response) {
237
+ _responseToModels (response) {
238
238
  const modelsResponseReader = new ModelsResponseReader({
239
239
  collection: this,
240
240
  response