@kaspernj/api-maker 1.0.123 → 1.0.127

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 +6 -5
  10. package/src/api.cjs +15 -15
  11. package/src/base-model.cjs +85 -80
  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 +45 -15
  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
package/src/api.cjs CHANGED
@@ -3,23 +3,23 @@ const FormDataObjectizer = require("form-data-objectizer")
3
3
  const qs = require("qs")
4
4
 
5
5
  module.exports = class Api {
6
- static get(path, pathParams = null) {
6
+ static get (path, pathParams = null) {
7
7
  return this.requestLocal({path, pathParams, method: "GET"})
8
8
  }
9
9
 
10
- static delete(path, pathParams = null) {
10
+ static delete (path, pathParams = null) {
11
11
  return this.requestLocal({path, pathParams, method: "DELETE"})
12
12
  }
13
13
 
14
- static patch(path, data = {}) {
14
+ static patch (path, data = {}) {
15
15
  return this.requestLocal({path, data, method: "PATCH"})
16
16
  }
17
17
 
18
- static post(path, data = {}) {
18
+ static post (path, data = {}) {
19
19
  return this.requestLocal({path, data, method: "POST"})
20
20
  }
21
21
 
22
- static request(args) {
22
+ static request (args) {
23
23
  let path = args.path
24
24
 
25
25
  if (args.pathParams) {
@@ -32,7 +32,7 @@ module.exports = class Api {
32
32
  xhr.open(args.method, path, true)
33
33
 
34
34
  if (args.headers) {
35
- for(const headerName in args.headers) {
35
+ for (const headerName in args.headers) {
36
36
  xhr.setRequestHeader(headerName, args.headers[headerName])
37
37
  }
38
38
  }
@@ -59,41 +59,41 @@ module.exports = class Api {
59
59
  })
60
60
  }
61
61
 
62
- static requestLocal(args) {
62
+ static requestLocal (args) {
63
63
  if (!args.headers) {
64
- args["headers"] = {}
64
+ args.headers = {}
65
65
  }
66
66
 
67
67
  const token = this._token()
68
68
 
69
69
  if (token) {
70
- args["headers"]["X-CSRF-Token"] = token
70
+ args.headers["X-CSRF-Token"] = token
71
71
  }
72
72
 
73
73
  if (args.data) {
74
- args["headers"]["Content-Type"] = "application/json"
75
- args["data"] = JSON.stringify(args.data)
74
+ args.headers["Content-Type"] = "application/json"
75
+ args.data = JSON.stringify(args.data)
76
76
  }
77
77
 
78
78
  if (args.rawData) {
79
- args["data"] = args.rawData
79
+ args.data = args.rawData
80
80
  }
81
81
 
82
82
  return this.request(args)
83
83
  }
84
84
 
85
- static put(path, data = {}) {
85
+ static put (path, data = {}) {
86
86
  return this.requestLocal({path, data, method: "PUT"})
87
87
  }
88
88
 
89
- static _token() {
89
+ static _token () {
90
90
  const tokenElement = document.querySelector("meta[name='csrf-token']")
91
91
 
92
92
  if (tokenElement)
93
93
  return tokenElement.getAttribute("content")
94
94
  }
95
95
 
96
- static _parseResponse(xhr) {
96
+ static _parseResponse (xhr) {
97
97
  const responseType = xhr.getResponseHeader("content-type")
98
98
 
99
99
  if (responseType && responseType.startsWith("application/json")) {
@@ -16,11 +16,11 @@ const {ValidationErrors} = require("./validation-errors.cjs")
16
16
  const shared = {}
17
17
 
18
18
  module.exports = class BaseModel {
19
- static modelClassData() {
19
+ static modelClassData () {
20
20
  throw new Error("modelClassData should be overriden by child")
21
21
  }
22
22
 
23
- static async find(id) {
23
+ static async find (id) {
24
24
  const primaryKeyName = this.modelClassData().primaryKey
25
25
  const query = {}
26
26
  query[`${primaryKeyName}_eq`] = id
@@ -34,30 +34,30 @@ module.exports = class BaseModel {
34
34
  }
35
35
  }
36
36
 
37
- static async findOrCreateBy(findOrCreateByArgs, args = {}) {
37
+ static async findOrCreateBy (findOrCreateByArgs, args = {}) {
38
38
  const result = await Services.current().sendRequest("Models::FindOrCreateBy", {
39
39
  additional_data: args.additionalData,
40
40
  find_or_create_by_args: findOrCreateByArgs,
41
- resource_name: digg(this.modelClassData(), "name"),
41
+ resource_name: digg(this.modelClassData(), "name")
42
42
  })
43
43
  const model = digg(result, "model")
44
44
 
45
45
  return model
46
46
  }
47
47
 
48
- static modelName() {
48
+ static modelName () {
49
49
  return new ModelName({i18n: shared.i18n, modelClassData: this.modelClassData()})
50
50
  }
51
51
 
52
- static ransack(query = {}) {
52
+ static ransack (query = {}) {
53
53
  return new Collection({modelClass: this}, {ransack: query})
54
54
  }
55
55
 
56
- static setI18n(i18n) {
56
+ static setI18n (i18n) {
57
57
  shared.i18n = i18n
58
58
  }
59
59
 
60
- constructor(args = {}) {
60
+ constructor (args = {}) {
61
61
  this.changes = {}
62
62
  this.newRecord = args.isNewRecord
63
63
  this.relationshipsCache = {}
@@ -76,8 +76,8 @@ module.exports = class BaseModel {
76
76
  }
77
77
  }
78
78
 
79
- assignAttributes(newAttributes) {
80
- for(const key in newAttributes) {
79
+ assignAttributes (newAttributes) {
80
+ for (const key in newAttributes) {
81
81
  const newValue = newAttributes[key]
82
82
 
83
83
  let applyChange = true
@@ -103,11 +103,11 @@ module.exports = class BaseModel {
103
103
  }
104
104
  }
105
105
 
106
- attributes() {
106
+ attributes () {
107
107
  return digg(this, "modelData")
108
108
  }
109
109
 
110
- can(givenAbilityName) {
110
+ can (givenAbilityName) {
111
111
  const abilityName = inflection.underscore(givenAbilityName)
112
112
 
113
113
  if (!(abilityName in this.abilities)) {
@@ -117,17 +117,17 @@ module.exports = class BaseModel {
117
117
  return this.abilities[abilityName]
118
118
  }
119
119
 
120
- clone() {
121
- const clone = new this.constructor
120
+ clone () {
121
+ const clone = new this.constructor()
122
122
 
123
- clone.abilities = Object.assign({}, this.abilities)
124
- clone.modelData = Object.assign({}, this.modelData)
125
- clone.relationshipsCache = Object.assign({}, this.relationshipsCache)
123
+ clone.abilities = {...this.abilities}
124
+ clone.modelData = {...this.modelData}
125
+ clone.relationshipsCache = {...this.relationshipsCache}
126
126
 
127
127
  return clone
128
128
  }
129
129
 
130
- cacheKey() {
130
+ cacheKey () {
131
131
  if (this.isPersisted()) {
132
132
  const keyParts = [
133
133
  this.modelClassData().paramKey,
@@ -152,7 +152,11 @@ module.exports = class BaseModel {
152
152
  }
153
153
  }
154
154
 
155
- async create(attributes, options) {
155
+ static all () {
156
+ return this.ransack()
157
+ }
158
+
159
+ async create (attributes, options) {
156
160
  if (attributes) this.assignAttributes(attributes)
157
161
  const paramKey = this.modelClassData().paramKey
158
162
  const modelData = this.getAttributes()
@@ -186,7 +190,7 @@ module.exports = class BaseModel {
186
190
  return {model: this, response}
187
191
  }
188
192
 
189
- async createRaw(rawData, options = {}) {
193
+ async createRaw (rawData, options = {}) {
190
194
  const objectData = this._objectDataFromGivenRawData(rawData, options)
191
195
 
192
196
  let response
@@ -200,7 +204,8 @@ module.exports = class BaseModel {
200
204
  command: `${this.modelClassData().collectionName}-create`,
201
205
  collectionName: this.modelClassData().collectionName,
202
206
  primaryKey: this.primaryKey(),
203
- type: "create"},
207
+ type: "create"
208
+ },
204
209
  {}
205
210
  )
206
211
  } catch (error) {
@@ -216,7 +221,7 @@ module.exports = class BaseModel {
216
221
  return {model: this, response}
217
222
  }
218
223
 
219
- async destroy() {
224
+ async destroy () {
220
225
  const response = await CommandsPool.addCommand(
221
226
  {
222
227
  args: {query_params: this.collection && this.collection.params()},
@@ -236,11 +241,11 @@ module.exports = class BaseModel {
236
241
 
237
242
  return {model: this, response}
238
243
  } else {
239
- handleResponseError(response)
244
+ this.handleResponseError(response)
240
245
  }
241
246
  }
242
247
 
243
- async ensureAbilities(listOfAbilities) {
248
+ async ensureAbilities (listOfAbilities) {
244
249
  // Populate an array with a list of abilities currently not loaded
245
250
  const abilitiesToLoad = []
246
251
 
@@ -275,27 +280,27 @@ module.exports = class BaseModel {
275
280
  }
276
281
  }
277
282
 
278
- getAttributes() {
283
+ getAttributes () {
279
284
  return Object.assign(this.modelData, this.changes)
280
285
  }
281
286
 
282
- handleResponseError(response) {
287
+ handleResponseError (response) {
283
288
  this.parseValidationErrors(response)
284
289
  throw new new CustomError("Response wasn't successful", {model: this, response})
285
290
  }
286
291
 
287
- identifierKey() {
292
+ identifierKey () {
288
293
  if (!this._identifierKey) this._identifierKey = this.isPersisted() ? this.primaryKey() : this.uniqueKey()
289
294
 
290
295
  return this._identifierKey
291
296
  }
292
297
 
293
- isAssociationLoaded(associationName) {
298
+ isAssociationLoaded (associationName) {
294
299
  if (associationName in this.relationshipsCache) return true
295
300
  return false
296
301
  }
297
302
 
298
- parseValidationErrors(error, options) {
303
+ parseValidationErrors (error, options) {
299
304
  if (!(error instanceof CustomError)) return
300
305
  if (!error.args.response.validation_errors) return
301
306
 
@@ -311,24 +316,24 @@ module.exports = class BaseModel {
311
316
  }
312
317
  }
313
318
 
314
- sendValidationErrorsEvent(validationErrors, options) {
319
+ sendValidationErrorsEvent (validationErrors, options) {
315
320
  if (options && options.form) {
316
321
  const event = this.newCustomEvent(validationErrors)
317
322
  options.form.dispatchEvent(event)
318
323
  }
319
324
  }
320
325
 
321
- newCustomEvent(validationErrors) {
326
+ newCustomEvent (validationErrors) {
322
327
  return new CustomEvent("validation-errors", {detail: validationErrors})
323
328
  }
324
329
 
325
- static humanAttributeName(attributeName) {
330
+ static humanAttributeName (attributeName) {
326
331
  const keyName = digg(this.modelClassData(), "i18nKey")
327
332
 
328
333
  return shared.i18n.t(`activerecord.attributes.${keyName}.${BaseModel.snakeCase(attributeName)}`, {defaultValue: attributeName})
329
334
  }
330
335
 
331
- isAttributeChanged(attributeName) {
336
+ isAttributeChanged (attributeName) {
332
337
  const attributeNameUnderscore = inflection.underscore(attributeName)
333
338
  const attributeData = this.modelClassData().attributes.find((attribute) => digg(attribute, "name") == attributeNameUnderscore)
334
339
 
@@ -351,7 +356,7 @@ module.exports = class BaseModel {
351
356
  return changedMethod(oldValue, newValue)
352
357
  }
353
358
 
354
- isChanged() {
359
+ isChanged () {
355
360
  const keys = Object.keys(this.changes)
356
361
 
357
362
  if (keys.length > 0) {
@@ -361,7 +366,7 @@ module.exports = class BaseModel {
361
366
  }
362
367
  }
363
368
 
364
- isNewRecord() {
369
+ isNewRecord () {
365
370
  if (this.newRecord === false) {
366
371
  return false
367
372
  } else if ("id" in this.modelData && this.modelData.id) {
@@ -371,23 +376,23 @@ module.exports = class BaseModel {
371
376
  }
372
377
  }
373
378
 
374
- isPersisted() {
379
+ isPersisted () {
375
380
  return !this.isNewRecord()
376
381
  }
377
382
 
378
- static snakeCase(string) {
383
+ static snakeCase (string) {
379
384
  return inflection.underscore(string)
380
385
  }
381
386
 
382
- savedChangeToAttribute(attributeName) {
387
+ savedChangeToAttribute (attributeName) {
383
388
  if (!this.previousModelData)
384
389
  return false
385
390
 
386
391
  const attributeNameUnderscore = inflection.underscore(attributeName)
387
- const attributeData = this.modelClassData().attributes.find(attribute => attribute.name == attributeNameUnderscore)
392
+ const attributeData = this.modelClassData().attributes.find((attribute) => attribute.name == attributeNameUnderscore)
388
393
 
389
394
  if (!attributeData) {
390
- const attributeNames = this.modelClassData().attributes.map(attribute => attribute.name)
395
+ const attributeNames = this.modelClassData().attributes.map((attribute) => attribute.name)
391
396
  throw new Error(`Couldn't find an attribute by that name: "${attributeName}" in: ${attributeNames.join(", ")}`)
392
397
  }
393
398
 
@@ -405,27 +410,27 @@ module.exports = class BaseModel {
405
410
  return changedMethod(oldValue, newValue)
406
411
  }
407
412
 
408
- setNewModel(model) {
413
+ setNewModel (model) {
409
414
  this.setNewModelData(model)
410
415
  this.relationshipsCache = digg(model, "relationshipsCache")
411
416
  }
412
417
 
413
- setNewModelData(model) {
418
+ setNewModelData (model) {
414
419
  this.previousModelData = digg(this, "modelData")
415
420
  this.modelData = digg(model, "modelData")
416
421
  }
417
422
 
418
- _isDateChanged(oldValue, newValue) {
423
+ _isDateChanged (oldValue, newValue) {
419
424
  if (Date.parse(oldValue) != Date.parse(newValue))
420
425
  return true
421
426
  }
422
427
 
423
- _isIntegerChanged(oldValue, newValue) {
424
- if (parseInt(oldValue) != parseInt(newValue))
428
+ _isIntegerChanged (oldValue, newValue) {
429
+ if (parseInt(oldValue, 10) != parseInt(newValue, 10))
425
430
  return true
426
431
  }
427
432
 
428
- _isStringChanged(oldValue, newValue) {
433
+ _isStringChanged (oldValue, newValue) {
429
434
  const oldConvertedValue = `${oldValue}`
430
435
  const newConvertedValue = `${newValue}`
431
436
 
@@ -433,11 +438,11 @@ module.exports = class BaseModel {
433
438
  return true
434
439
  }
435
440
 
436
- modelClassData() {
441
+ modelClassData () {
437
442
  return this.constructor.modelClassData()
438
443
  }
439
444
 
440
- async reload() {
445
+ async reload () {
441
446
  const params = this.collection && this.collection.params()
442
447
  const primaryKeyName = this.modelClassData().primaryKey
443
448
  const ransackParams = {}
@@ -464,7 +469,7 @@ module.exports = class BaseModel {
464
469
  this.changes = {}
465
470
  }
466
471
 
467
- save() {
472
+ save () {
468
473
  if (this.isNewRecord()) {
469
474
  return this.create()
470
475
  } else {
@@ -472,7 +477,7 @@ module.exports = class BaseModel {
472
477
  }
473
478
  }
474
479
 
475
- saveRaw(rawData, options = {}) {
480
+ saveRaw (rawData, options = {}) {
476
481
  if (this.isNewRecord()) {
477
482
  return this.createRaw(rawData, options)
478
483
  } else {
@@ -480,7 +485,7 @@ module.exports = class BaseModel {
480
485
  }
481
486
  }
482
487
 
483
- async update(newAttributes, options) {
488
+ async update (newAttributes, options) {
484
489
  if (newAttributes)
485
490
  this.assignAttributes(newAttributes)
486
491
 
@@ -521,21 +526,21 @@ module.exports = class BaseModel {
521
526
 
522
527
  return {response, model: this}
523
528
  } else {
524
- handleResponseError(response)
529
+ this.handleResponseError(response)
525
530
  }
526
531
  }
527
532
 
528
- _refreshModelFromResponse(response) {
533
+ _refreshModelFromResponse (response) {
529
534
  const newModel = ModelsResponseReader.first(digg(response, "model"))
530
535
  this.setNewModel(newModel)
531
536
  }
532
537
 
533
- _refreshModelDataFromResponse(response) {
538
+ _refreshModelDataFromResponse (response) {
534
539
  const newModel = ModelsResponseReader.first(digg(response, "model"))
535
540
  this.setNewModelData(newModel)
536
541
  }
537
542
 
538
- _objectDataFromGivenRawData(rawData, options) {
543
+ _objectDataFromGivenRawData (rawData, options) {
539
544
  if (rawData instanceof FormData || rawData.nodeName == "FORM") {
540
545
  const formData = FormDataObjectizer.formDataFromObject(rawData, options)
541
546
 
@@ -545,7 +550,7 @@ module.exports = class BaseModel {
545
550
  return rawData
546
551
  }
547
552
 
548
- async updateRaw(rawData, options = {}) {
553
+ async updateRaw (rawData, options = {}) {
549
554
  const objectData = this._objectDataFromGivenRawData(rawData, options)
550
555
 
551
556
  let response
@@ -577,11 +582,11 @@ module.exports = class BaseModel {
577
582
  return {response, model: this}
578
583
  }
579
584
 
580
- isValid() {
585
+ isValid () {
581
586
  throw new Error("Not implemented yet")
582
587
  }
583
588
 
584
- async isValidOnServer() {
589
+ async isValidOnServer () {
585
590
  const modelData = this.getAttributes()
586
591
  const paramKey = this.modelClassData().paramKey
587
592
  const dataToUse = {}
@@ -603,18 +608,18 @@ module.exports = class BaseModel {
603
608
  return {valid: response.valid, errors: response.errors}
604
609
  }
605
610
 
606
- modelClass() {
611
+ modelClass () {
607
612
  return this.constructor
608
613
  }
609
614
 
610
- preloadRelationship(relationshipName, model) {
615
+ preloadRelationship (relationshipName, model) {
611
616
  this.relationshipsCache[BaseModel.snakeCase(relationshipName)] = model
612
617
  }
613
618
 
614
- uniqueKey() {
619
+ uniqueKey () {
615
620
  if (!this.uniqueKeyValue) {
616
- const min = 500000000000000000
617
- const max = 999999999999999999
621
+ const min = 5000000000000000
622
+ const max = 9007199254740991
618
623
  const randomBetween = Math.floor(Math.random() * (max - min + 1) + min)
619
624
  this.uniqueKeyValue = randomBetween
620
625
  }
@@ -622,15 +627,15 @@ module.exports = class BaseModel {
622
627
  return this.uniqueKeyValue
623
628
  }
624
629
 
625
- static _callCollectionCommand(args, commandArgs) {
630
+ static _callCollectionCommand (args, commandArgs) {
626
631
  return CommandsPool.addCommand(args, commandArgs)
627
632
  }
628
633
 
629
- _callMemberCommand(args, commandArgs) {
634
+ _callMemberCommand (args, commandArgs) {
630
635
  return CommandsPool.addCommand(args, commandArgs)
631
636
  }
632
637
 
633
- static _postDataFromArgs(args) {
638
+ static _postDataFromArgs (args) {
634
639
  let postData
635
640
 
636
641
  if (args) {
@@ -646,13 +651,13 @@ module.exports = class BaseModel {
646
651
  return postData
647
652
  }
648
653
 
649
- readAttribute(attributeName) {
654
+ readAttribute (attributeName) {
650
655
  const attributeNameUnderscore = inflection.underscore(attributeName)
651
656
 
652
657
  return this.readAttributeUnderscore(attributeNameUnderscore)
653
658
  }
654
659
 
655
- readAttributeUnderscore(attributeName) {
660
+ readAttributeUnderscore (attributeName) {
656
661
  if (attributeName in this.changes) {
657
662
  return this.changes[attributeName]
658
663
  } else if (attributeName in this.modelData) {
@@ -667,7 +672,7 @@ module.exports = class BaseModel {
667
672
  throw new AttributeNotLoadedError(`No such attribute: ${digg(this.modelClassData(), "name")}#${attributeName}`)
668
673
  }
669
674
 
670
- isAttributeLoaded(attributeName) {
675
+ isAttributeLoaded (attributeName) {
671
676
  const attributeNameUnderscore = inflection.underscore(attributeName)
672
677
 
673
678
  if (attributeNameUnderscore in this.changes) return true
@@ -675,7 +680,7 @@ module.exports = class BaseModel {
675
680
  return false
676
681
  }
677
682
 
678
- _isPresent(value) {
683
+ _isPresent (value) {
679
684
  if (!value) {
680
685
  return false
681
686
  } else if (typeof value == "string" && value.match(/^\s*$/)) {
@@ -685,7 +690,7 @@ module.exports = class BaseModel {
685
690
  return true
686
691
  }
687
692
 
688
- async _loadBelongsToReflection(args, queryArgs = {}) {
693
+ async _loadBelongsToReflection (args, queryArgs = {}) {
689
694
  if (args.reflectionName in this.relationshipsCache) {
690
695
  return this.relationshipsCache[args.reflectionName]
691
696
  } else {
@@ -696,7 +701,7 @@ module.exports = class BaseModel {
696
701
  }
697
702
  }
698
703
 
699
- _readBelongsToReflection({reflectionName}) {
704
+ _readBelongsToReflection ({reflectionName}) {
700
705
  if (!(reflectionName in this.relationshipsCache)) {
701
706
  if (this.isNewRecord())
702
707
  return null
@@ -710,7 +715,7 @@ module.exports = class BaseModel {
710
715
  return this.relationshipsCache[reflectionName]
711
716
  }
712
717
 
713
- async _loadHasManyReflection(args, queryArgs = {}) {
718
+ async _loadHasManyReflection (args, queryArgs = {}) {
714
719
  if (args.reflectionName in this.relationshipsCache) {
715
720
  return this.relationshipsCache[args.reflectionName]
716
721
  }
@@ -723,7 +728,7 @@ module.exports = class BaseModel {
723
728
  return models
724
729
  }
725
730
 
726
- async _loadHasOneReflection(args, queryArgs = {}) {
731
+ async _loadHasOneReflection (args, queryArgs = {}) {
727
732
  if (args.reflectionName in this.relationshipsCache) {
728
733
  return this.relationshipsCache[args.reflectionName]
729
734
  } else {
@@ -736,7 +741,7 @@ module.exports = class BaseModel {
736
741
  }
737
742
  }
738
743
 
739
- _readHasOneReflection({reflectionName}) {
744
+ _readHasOneReflection ({reflectionName}) {
740
745
  if (!(reflectionName in this.relationshipsCache)) {
741
746
  if (this.isNewRecord())
742
747
  return null
@@ -750,14 +755,14 @@ module.exports = class BaseModel {
750
755
  return this.relationshipsCache[reflectionName]
751
756
  }
752
757
 
753
- _readModelDataFromArgs(args) {
758
+ _readModelDataFromArgs (args) {
754
759
  this.abilities = args.data.b || {}
755
760
  this.collection = args.collection
756
761
  this.modelData = args.data.a
757
762
  this.preloadedRelationships = args.data.r
758
763
  }
759
764
 
760
- _readPreloadedRelationships(preloaded) {
765
+ _readPreloadedRelationships (preloaded) {
761
766
  if (!this.preloadedRelationships) {
762
767
  return
763
768
  }
@@ -787,7 +792,7 @@ module.exports = class BaseModel {
787
792
  } else if (Array.isArray(relationshipData)) {
788
793
  const result = []
789
794
 
790
- for(const relationshipId of relationshipData) {
795
+ for (const relationshipId of relationshipData) {
791
796
  const model = preloaded.getModel(relationshipType, relationshipId)
792
797
 
793
798
  result.push(model)
@@ -801,11 +806,11 @@ module.exports = class BaseModel {
801
806
  }
802
807
  }
803
808
 
804
- primaryKey() {
809
+ primaryKey () {
805
810
  return this.readAttributeUnderscore(digg(this.modelClassData(), "primaryKey"))
806
811
  }
807
812
 
808
- static _token() {
813
+ static _token () {
809
814
  const csrfTokenElement = document.querySelector("meta[name='csrf-token']")
810
815
 
811
816
  if (csrfTokenElement) {
@@ -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