@kaspernj/api-maker 1.0.136 → 1.0.139

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 CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.136",
19
+ "version": "1.0.139",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -34,6 +34,24 @@
34
34
  "eslint-find-rules": "eslint-find-rules",
35
35
  "test": "jest"
36
36
  },
37
+ "dependencies": {
38
+ "@rails/actioncable": ">= 6.1.0",
39
+ "clone-deep": ">= 4.0.1",
40
+ "debounce": ">= 1.2.1",
41
+ "diggerize": ">= 1.0.4",
42
+ "epic-locks": ">= 1.0.1",
43
+ "form-data-objectizer": ">= 1.0.0",
44
+ "form-serialize": ">= 0.7.2",
45
+ "format-number": ">= 3.0.0",
46
+ "inflection": ">= 1.12.0",
47
+ "js-money": ">= 0.6.3",
48
+ "numberable": ">= 1.0.0",
49
+ "object-to-formdata": ">= 4.1.0",
50
+ "qs": ">= 6.9.3",
51
+ "replaceall": ">= 0.1.6",
52
+ "strftime": ">= 0.10.0",
53
+ "wake-event": ">= 0.0.1"
54
+ },
37
55
  "peerDependencies": {
38
56
  "prop-types": "^15.7.2",
39
57
  "prop-types-exact": ">= 1.2.0",
@@ -55,23 +73,5 @@
55
73
  "i18n-on-steroids": "^1.0.2",
56
74
  "jest": "^27.0.6",
57
75
  "jsdom": "^19.0.0"
58
- },
59
- "dependencies": {
60
- "@rails/actioncable": ">= 6.1.0",
61
- "clone-deep": ">= 4.0.1",
62
- "debounce": ">= 1.2.1",
63
- "diggerize": ">= 1.0.4",
64
- "epic-locks": ">= 1.0.1",
65
- "form-data-objectizer": ">= 1.0.0",
66
- "form-serialize": ">= 0.7.2",
67
- "format-number": ">= 3.0.0",
68
- "inflection": ">= 1.12.0",
69
- "js-money": ">= 0.6.3",
70
- "numberable": ">= 1.0.0",
71
- "object-to-formdata": ">= 4.1.0",
72
- "qs": ">= 6.9.3",
73
- "replaceall": ">= 0.1.6",
74
- "strftime": ">= 0.10.0",
75
- "wake-event": ">= 0.0.1"
76
76
  }
77
77
  }
@@ -126,7 +126,7 @@ module.exports = class ApiMakerCommandsPool {
126
126
  const commandData = currentPool[parseInt(commandId, 10)]
127
127
  const responseType = commandResponse.type
128
128
 
129
- if (commandResponseData) {
129
+ if (commandResponseData && typeof commandResponseData == "object") {
130
130
  const bugReportUrl = dig(commandResponseData, "bug_report_url")
131
131
 
132
132
  if (bugReportUrl) {
package/src/config.js ADDED
@@ -0,0 +1,15 @@
1
+ class ApiMakerConfig {
2
+ getCurrenciesCollection() {
3
+ if (!this._currenciesCollection) throw new Error("Currencies collection hasn't been set")
4
+
5
+ return this._currenciesCollection
6
+ }
7
+
8
+ setCurrenciesCollection(newCurrenciesCollection) {
9
+ this._currenciesCollection = newCurrenciesCollection
10
+ }
11
+ }
12
+
13
+ const apiMakerConfig = new ApiMakerConfig()
14
+
15
+ export default apiMakerConfig
@@ -20,11 +20,6 @@ export default class ApiMakerEventUpdated extends React.PureComponent {
20
20
  onUpdated: PropTypes.func.isRequired
21
21
  })
22
22
 
23
- constructor (props) {
24
- super(props)
25
- this.onConnected = this.onConnected.bind(this)
26
- }
27
-
28
23
  componentDidMount () {
29
24
  this.connect()
30
25
  }
@@ -35,17 +30,17 @@ export default class ApiMakerEventUpdated extends React.PureComponent {
35
30
  }
36
31
 
37
32
  if (this.onConnectedListener) {
38
- this.connectUpdated.events.removeListener("connected", this.onConnected)
33
+ this.connectUpdated.events.removeListener("connected", this.props.onConnected)
39
34
  }
40
35
  }
41
36
 
42
37
  connect () {
43
38
  const {model, onConnected} = this.props
44
39
 
45
- this.connectUpdated = ModelEvents.connectUpdated(model, (...args) => this.onUpdated(...args))
40
+ this.connectUpdated = ModelEvents.connectUpdated(model, this.onUpdated)
46
41
 
47
42
  if (onConnected) {
48
- this.connectUpdated.events.addListener("connected", this.onConnected)
43
+ this.onConnectedListener = this.connectUpdated.events.addListener("connected", this.props.onConnected)
49
44
  }
50
45
  }
51
46
 
@@ -61,11 +56,7 @@ export default class ApiMakerEventUpdated extends React.PureComponent {
61
56
  return this.debounceInstance
62
57
  }
63
58
 
64
- onConnected () {
65
- this.props.onConnected()
66
- }
67
-
68
- onUpdated (...args) {
59
+ onUpdated = (...args) => {
69
60
  if (!this.props.active) {
70
61
  return
71
62
  }
@@ -1,3 +1,4 @@
1
+ import EventUpdated from "./event-updated"
1
2
  import Params from "./params.cjs"
2
3
  import React from "react"
3
4
 
@@ -26,6 +27,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
26
27
  const {modelId} = digs(this.state, "modelId")
27
28
  const query = await ModelClass.ransack({id_eq: modelId})
28
29
 
30
+ if (args.abilities) query.abilities(args.abilities)
29
31
  if (args.preload) query.preload(args.preload)
30
32
  if (args.select) query.select(args.select)
31
33
 
@@ -52,7 +54,14 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
52
54
  wrappedComponentProps[`${this.camelizedLower}Id`] = modelId
53
55
 
54
56
  return (
55
- <WrappedComponent {...wrappedComponentProps} {...this.props} />
57
+ <>
58
+ {model && args.eventUpdated &&
59
+ <EventUpdated model={model} onUpdated={digg(this, "onUpdated")} />
60
+ }
61
+ <WrappedComponent {...wrappedComponentProps} {...this.props} />
62
+ </>
56
63
  )
57
64
  }
65
+
66
+ onUpdated = () => this.loadExistingModel()
58
67
  }
package/src/routes.cjs CHANGED
@@ -3,6 +3,8 @@ const inflection = require("inflection")
3
3
 
4
4
  module.exports = class ApiMakerRoutes {
5
5
  constructor ({jsRoutes, locale, routeDefinitions}) {
6
+ if (!jsRoutes) throw new Error("'jsRoutes' wasn't given")
7
+
6
8
  this.jsRoutes = jsRoutes
7
9
  this.routeDefinitions = routeDefinitions
8
10
 
@@ -16,7 +16,13 @@ module.exports = class Serializer {
16
16
  }
17
17
 
18
18
  serializeArgument (arg) {
19
- if (typeof arg == "function" && arg.apiMakerType == "BaseModel") {
19
+ if (typeof arg == "object" && arg.constructor.apiMakerType == "BaseModel") {
20
+ return {
21
+ api_maker_type: "model",
22
+ model_class_name: digg(arg.modelClassData(), "name"),
23
+ model_id: arg.id()
24
+ }
25
+ } else if (typeof arg == "function" && arg.apiMakerType == "BaseModel") {
20
26
  return {
21
27
  api_maker_type: "resource",
22
28
  name: digg(arg.modelClassData(), "name")