@kaspernj/api-maker 1.0.141 → 1.0.144

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/.eslintrc.js CHANGED
@@ -68,15 +68,20 @@ module.exports = {
68
68
  "init-declarations": "off",
69
69
  "jest/max-nested-describe": "error",
70
70
  "jest/no-alias-methods": "error",
71
+ "jest/no-conditional-in-test": "error",
71
72
  "jest/no-duplicate-hooks": "error",
72
73
  "jest/no-hooks": "off",
73
74
  "jest/no-if": "error",
74
75
  "jest/no-large-snapshots": "error",
75
76
  "jest/no-restricted-matchers": "error",
76
77
  "jest/no-test-return-statement": "error",
78
+ "jest/prefer-comparison-matcher": "error",
79
+ "jest/prefer-equality-matcher": "error",
77
80
  "jest/prefer-expect-resolves": "off", // Needs configuration and no documentation could be found?
78
81
  "jest/prefer-hooks-on-top": "error",
79
82
  "jest/prefer-lowercase-title": "off",
83
+ "prefer-object-has-own": "error",
84
+ "jest/prefer-snapshot-hint": "error",
80
85
  "jest/prefer-to-be": "off", // Needs configuration and no documentation could be found?
81
86
  "jest/prefer-spy-on": "error",
82
87
  "jest/prefer-to-contain": "error",
@@ -212,6 +217,8 @@ module.exports = {
212
217
  "react/forbid-foreign-prop-types": "error",
213
218
  "react/forbid-prop-types": "off",
214
219
  "react/function-component-definition": "error",
220
+ "react/hook-use-state": "error",
221
+ "react/iframe-missing-sandbox": "error",
215
222
  "react/jsx-boolean-value": "error",
216
223
  "react/jsx-child-element-spacing": "error",
217
224
  "react/jsx-closing-bracket-location": "error",
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.141",
19
+ "version": "1.0.144",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -65,13 +65,13 @@
65
65
  "@babel/eslint-parser": "^7.16.3",
66
66
  "@babel/preset-env": "^7.12.11",
67
67
  "@babel/preset-react": "^7.12.10",
68
- "babel-jest": "^27.0.6",
68
+ "babel-jest": "^28.0.3",
69
69
  "eslint": "^8.2.0",
70
70
  "eslint-find-rules": "^4.0.0",
71
71
  "eslint-plugin-jest": "^26.0.0",
72
72
  "eslint-plugin-react": "^7.23.2",
73
73
  "i18n-on-steroids": "^1.0.2",
74
- "jest": "^27.0.6",
74
+ "jest": "^28.0.3",
75
75
  "jsdom": "^19.0.0"
76
76
  }
77
77
  }
package/src/config.js CHANGED
@@ -1,12 +1,18 @@
1
1
  class ApiMakerConfig {
2
+ constructor() {
3
+ if (!global.apiMakerConfigGlobal) global.apiMakerConfigGlobal = {}
4
+
5
+ this.global = global.apiMakerConfigGlobal
6
+ }
7
+
2
8
  getCurrenciesCollection() {
3
- if (!this._currenciesCollection) throw new Error("Currencies collection hasn't been set")
9
+ if (!this.global.currenciesCollection) throw new Error("Currencies collection hasn't been set")
4
10
 
5
- return this._currenciesCollection
11
+ return this.global.currenciesCollection
6
12
  }
7
13
 
8
14
  setCurrenciesCollection(newCurrenciesCollection) {
9
- this._currenciesCollection = newCurrenciesCollection
15
+ this.global.currenciesCollection = newCurrenciesCollection
10
16
  }
11
17
  }
12
18
 
@@ -36,11 +36,18 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
36
36
  this.setState({model})
37
37
  }
38
38
 
39
- loadNewModel() {
39
+ async loadNewModel() {
40
40
  const params = Params.parse()
41
41
  const paramKey = ModelClass.modelName().paramKey()
42
42
  const modelDataFromParams = params[paramKey] || {}
43
- const modelData = Object.assign({}, args.newAttributes, modelDataFromParams)
43
+
44
+ let defaults = {}
45
+
46
+ if (args.newIfNoId?.defaults) {
47
+ defaults = await args.newIfNoId.defaults()
48
+ }
49
+
50
+ const modelData = Object.assign(defaults, args.newAttributes, modelDataFromParams)
44
51
  const model = new ModelClass(modelData)
45
52
 
46
53
  this.setState({model})
@@ -1 +1,3 @@
1
+ /* rails-erb-loader-dependencies api_maker/resources/ models/ */
2
+
1
3
  module.exports = <%= ApiMaker::ModelClassesJavaScriptGeneratorService.execute!.to_json %>
package/src/models.cjs CHANGED
@@ -1,5 +1,3 @@
1
- /* rails-erb-loader-dependencies api_maker/resources/ */
2
-
3
1
  const modelRecipes = require("./model-recipes.cjs.erb")
4
2
  const ModelRecipesLoader = require("./model-recipes-loader.cjs")
5
3
 
@@ -57,7 +57,7 @@ module.exports = class MoneyFormatter {
57
57
  static isMoney(value) {
58
58
  if (value instanceof Money) return true
59
59
 
60
- if (typeof value == "object" && value && Object.keys(value).length == 2 && value.amount && value.currency)
60
+ if (typeof value == "object" && value && Object.keys(value).length == 2 && "amount" in value && "currency" in value)
61
61
  return true
62
62
 
63
63
  return false