@kaspernj/api-maker 1.0.203 → 1.0.204

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.203",
19
+ "version": "1.0.204",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -1,6 +1,7 @@
1
1
  const AttributeNotLoadedError = require("./attribute-not-loaded-error.cjs")
2
2
  const Collection = require("./collection.cjs")
3
3
  const CommandsPool = require("./commands-pool.cjs")
4
+ const Config = require("@kaspernj/api-maker/src/config").default
4
5
  const CustomError = require("./custom-error.cjs")
5
6
  const {digg} = require("diggerize")
6
7
  const FormDataObjectizer = require("form-data-objectizer")
@@ -12,8 +13,6 @@ const Services = require("./services.cjs")
12
13
  const ValidationError = require("./validation-error.cjs")
13
14
  const {ValidationErrors} = require("./validation-errors.cjs")
14
15
 
15
- const shared = {}
16
-
17
16
  const newCustomEvent = (validationErrors) => {
18
17
  return new CustomEvent("validation-errors", {detail: validationErrors})
19
18
  }
@@ -56,17 +55,13 @@ class BaseModel {
56
55
  }
57
56
 
58
57
  static modelName () {
59
- return new ModelName({i18n: shared.i18n, modelClassData: this.modelClassData()})
58
+ return new ModelName({modelClassData: this.modelClassData()})
60
59
  }
61
60
 
62
61
  static ransack (query = {}) {
63
62
  return new Collection({modelClass: this}, {ransack: query})
64
63
  }
65
64
 
66
- static setI18n (i18n) {
67
- shared.i18n = i18n
68
- }
69
-
70
65
  constructor (args = {}) {
71
66
  this.changes = {}
72
67
  this.newRecord = args.isNewRecord
@@ -328,8 +323,9 @@ class BaseModel {
328
323
 
329
324
  static humanAttributeName (attributeName) {
330
325
  const keyName = digg(this.modelClassData(), "i18nKey")
326
+ const i18n = Config.getI18n()
331
327
 
332
- if (shared.i18n) return shared.i18n.t(`activerecord.attributes.${keyName}.${BaseModel.snakeCase(attributeName)}`, {defaultValue: attributeName})
328
+ if (i18n) return i18n.t(`activerecord.attributes.${keyName}.${BaseModel.snakeCase(attributeName)}`, {defaultValue: attributeName})
333
329
 
334
330
  return inflection.humanize(attributeName)
335
331
  }
package/src/config.js CHANGED
@@ -15,6 +15,7 @@ const accessors = {
15
15
  currenciesCollection: {required: true},
16
16
  history: {required: false},
17
17
  host: {required: false},
18
+ i18n: {required: false},
18
19
  routes: {required: false},
19
20
  routeDefinitions: {required: false}
20
21
  }
@@ -1,3 +1,5 @@
1
+ const Config = require("@kaspernj/api-maker/src/config").default
2
+
1
3
  module.exports = class ModelName {
2
4
  constructor (data) {
3
5
  this.data = data
@@ -22,7 +24,7 @@ module.exports = class ModelName {
22
24
 
23
25
  const key = `activerecord.models.${this.data.modelClassData.i18nKey}.${countKey}`
24
26
 
25
- return this.data.i18n.t(key)
27
+ return Config.getI18n().t(key)
26
28
  }
27
29
 
28
30
  paramKey() {