@kaspernj/api-maker 1.0.201 → 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 +1 -1
- package/src/base-model.cjs +4 -8
- package/src/config.js +1 -0
- package/src/model-name.cjs +3 -1
package/package.json
CHANGED
package/src/base-model.cjs
CHANGED
|
@@ -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({
|
|
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 (
|
|
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
package/src/model-name.cjs
CHANGED
|
@@ -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
|
|
27
|
+
return Config.getI18n().t(key)
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
paramKey() {
|