@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
@@ -1,37 +1,37 @@
1
1
  const {digg} = require("diggerize")
2
2
  const ModelEvents = require("./model-events.cjs")
3
3
  const PropTypes = require("prop-types")
4
- const PropTypesExact = require("prop-types-exact")
4
+ const propTypesExact = require("prop-types-exact")
5
5
  const React = require("react")
6
6
 
7
7
  export default class ApiMakerUpdatedAttribute extends React.PureComponent {
8
- static propTypes = PropTypesExact({
8
+ static propTypes = propTypesExact({
9
9
  attribute: PropTypes.string,
10
10
  model: PropTypes.object.isRequired,
11
11
  onValue: PropTypes.func
12
12
  })
13
13
 
14
- constructor(props) {
14
+ constructor (props) {
15
15
  super(props)
16
16
  this.state = {
17
17
  model: this.props.model
18
18
  }
19
19
  }
20
20
 
21
- componentDidMount() {
21
+ componentDidMount () {
22
22
  this.setAttribute()
23
23
  this.connect()
24
24
  }
25
25
 
26
- componentWillUnmount() {
26
+ componentWillUnmount () {
27
27
  // Apparently 'componentWillUnmount' can be called without 'componentDidMount' was called. Several bug reports on this.
28
28
  if (this.connectUpdated) {
29
29
  this.connectUpdated.unsubscribe()
30
30
  }
31
31
  }
32
32
 
33
- connect() {
34
- this.connectUpdated = ModelEvents.connectUpdated(this.props.model, args => {
33
+ connect () {
34
+ this.connectUpdated = ModelEvents.connectUpdated(this.props.model, (args) => {
35
35
  if (!this.props.attribute || args.model.isAttributeLoaded(this.props.attribute)) {
36
36
  this.setState(
37
37
  {model: args.model},
@@ -44,7 +44,7 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
44
44
  }
45
45
 
46
46
  // This loads the model from the backend with the primary key and the attribute and calls setAttribute
47
- async loadModelWithAttribute() {
47
+ async loadModelWithAttribute () {
48
48
  const id = this.props.model.primaryKey()
49
49
  const modelClass = this.props.model.modelClass()
50
50
  const modelName = digg(modelClass.modelClassData(), "name")
@@ -56,7 +56,10 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
56
56
  const select = {}
57
57
  select[modelName] = [primaryKey, this.props.attribute]
58
58
 
59
- const model = await modelClass.ransack(args).select(select).first()
59
+ const model = await modelClass
60
+ .ransack(args)
61
+ .select(select)
62
+ .first()
60
63
 
61
64
  this.setState(
62
65
  {model},
@@ -64,14 +67,15 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
64
67
  )
65
68
  }
66
69
 
67
- setAttribute() {
70
+ setAttribute () {
68
71
  let newValue
69
72
 
70
73
  if (this.props.onValue) {
71
74
  newValue = this.props.onValue.apply(null, [{model: this.state.model}])
72
75
  } else {
73
- if (!this.state.model[this.props.attribute])
76
+ if (!this.state.model[this.props.attribute]) {
74
77
  throw new Error(`No such method: ${digg(this.state.model.modelClassData(), "name")}#${this.props.attribute}()`)
78
+ }
75
79
 
76
80
  newValue = this.state.model[this.props.attribute].apply(this.state.model)
77
81
  }
@@ -81,9 +85,8 @@ export default class ApiMakerUpdatedAttribute extends React.PureComponent {
81
85
  })
82
86
  }
83
87
 
84
- render() {
85
- if (this.state.value === undefined)
86
- return null
88
+ render () {
89
+ if (this.state.value === undefined) return null
87
90
 
88
91
  return this.state.value
89
92
  }
@@ -1,25 +1,22 @@
1
1
  const CustomError = require("./custom-error.cjs")
2
- const {digg} = require("diggerize")
3
2
  const inflection = require("inflection")
4
3
 
5
4
  module.exports = class ValidationError extends CustomError {
6
- constructor(validationErrors, args) {
5
+ constructor (validationErrors, args) {
7
6
  super(validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage(), args)
8
7
  this.validationErrors = validationErrors
9
8
  }
10
9
 
11
- hasUnhandledErrors() {
12
- const unhandledError = this.validationErrors.getValidationErrors().find(validationError => !validationError.getHandled())
10
+ hasUnhandledErrors () {
11
+ const unhandledError = this.validationErrors.getValidationErrors().find((validationError) => !validationError.getHandled())
13
12
  return Boolean(unhandledError)
14
13
  }
15
14
 
16
- hasValidationErrorForAttribute(attributeName) {
15
+ hasValidationErrorForAttribute (attributeName) {
17
16
  const underscoredAttributeName = inflection.underscore(attributeName)
18
17
  const foundAttribute = this.validationErrors.getValidationErrors().find((validationError) => validationError.getAttributeName() == underscoredAttributeName)
19
18
 
20
- if (foundAttribute) {
21
- return true
22
- }
19
+ if (foundAttribute) return true
23
20
 
24
21
  return false
25
22
  }
@@ -2,7 +2,7 @@ const {digg, digs} = require("diggerize")
2
2
  const inflection = require("inflection")
3
3
 
4
4
  class ValidationError {
5
- constructor(args) {
5
+ constructor (args) {
6
6
  this.attributeName = digg(args, "attribute_name")
7
7
  this.attributeType = digg(args, "attribute_type")
8
8
  this.errorMessages = digg(args, "error_messages")
@@ -12,7 +12,7 @@ class ValidationError {
12
12
  this.modelName = digg(args, "model_name")
13
13
  }
14
14
 
15
- matchesAttributeAndInputName(attributeName, inputName) {
15
+ matchesAttributeAndInputName (attributeName, inputName) {
16
16
  if (this.getInputName() == inputName) return true
17
17
  if (!attributeName) return false
18
18
 
@@ -29,15 +29,15 @@ class ValidationError {
29
29
  return false
30
30
  }
31
31
 
32
- getAttributeName() {
32
+ getAttributeName () {
33
33
  return digg(this, "attributeName")
34
34
  }
35
35
 
36
- getErrorMessages() {
36
+ getErrorMessages () {
37
37
  return digg(this, "errorMessages")
38
38
  }
39
39
 
40
- getFullErrorMessages() {
40
+ getFullErrorMessages () {
41
41
  const {attributeType} = digs(this, "attributeType")
42
42
 
43
43
  if (attributeType == "base") {
@@ -54,32 +54,32 @@ class ValidationError {
54
54
  }
55
55
  }
56
56
 
57
- getHandled() {
57
+ getHandled () {
58
58
  return digg(this, "handled")
59
59
  }
60
60
 
61
- getInputName() {
61
+ getInputName () {
62
62
  return digg(this, "inputName")
63
63
  }
64
64
 
65
- getModelClass() {
65
+ getModelClass () {
66
66
  const modelName = inflection.classify(digg(this, "modelName"))
67
67
 
68
68
  return digg(require("@kaspernj/api-maker/src/models"), modelName)
69
69
  }
70
70
 
71
- setHandled() {
71
+ setHandled () {
72
72
  this.handled = true
73
73
  }
74
74
  }
75
75
 
76
76
  class ValidationErrors {
77
- constructor(args) {
77
+ constructor (args) {
78
78
  this.rootModel = digg(args, "model")
79
- this.validationErrors = digg(args, "validationErrors").map(validationError => new ValidationError(validationError))
79
+ this.validationErrors = digg(args, "validationErrors").map((validationError) => new ValidationError(validationError))
80
80
  }
81
81
 
82
- getErrorMessage() {
82
+ getErrorMessage () {
83
83
  const fullErrorMessages = []
84
84
 
85
85
  for (const validationError of this.validationErrors) {
@@ -91,11 +91,11 @@ class ValidationErrors {
91
91
  return fullErrorMessages.join(". ")
92
92
  }
93
93
 
94
- getValidationErrors() {
94
+ getValidationErrors () {
95
95
  return this.validationErrors
96
96
  }
97
97
 
98
- getValidationErrorsForInput(args) {
98
+ getValidationErrorsForInput (args) {
99
99
  const {attribute, inputName, onMatchValidationError} = args
100
100
  const validationErrors = this.validationErrors.filter((validationError) => {
101
101
  if (onMatchValidationError) {
@@ -110,8 +110,8 @@ class ValidationErrors {
110
110
  return validationErrors
111
111
  }
112
112
 
113
- getUnhandledErrorMessage() {
114
- const unhandledValidationErrors = this.validationErrors.filter(validationError => !validationError.getHandled())
113
+ getUnhandledErrorMessage () {
114
+ const unhandledValidationErrors = this.validationErrors.filter((validationError) => !validationError.getHandled())
115
115
 
116
116
  if (unhandledValidationErrors.length > 0) {
117
117
  const unhandledValidationErrorMessages = []
@@ -1,21 +0,0 @@
1
- import PropTypes from "prop-types"
2
- import React from "react"
3
-
4
- export default class EventLocationChanged extends React.PureComponent {
5
- static propTypes = {
6
- history: PropTypes.object.isRequired,
7
- onChanged: PropTypes.func.isRequired
8
- }
9
-
10
- componentDidMount() {
11
- this.appHistoryUnlisten = this.props.history.listen(this.props.onChanged)
12
- }
13
-
14
- componentWillUnmount() {
15
- this.appHistoryUnlisten()
16
- }
17
-
18
- render() {
19
- return null
20
- }
21
- }
@@ -1,20 +0,0 @@
1
- const PropTypes = require("prop-types")
2
- const PropTypesExact = require("prop-types-exact")
3
-
4
- export default class ApiMakerHistoryListener extends React.PureComponent {
5
- static propTypes = PropTypesExact({
6
- onChanged: PropTypes.func.isRequired
7
- })
8
-
9
- componentDidMount() {
10
- this.unlisten = AppHistory.listen((location, action) => this.props.onChanged({location, action}))
11
- }
12
-
13
- componentWillUnmount() {
14
- this.unlisten()
15
- }
16
-
17
- render() {
18
- return null
19
- }
20
- }