velocious 1.0.103 → 1.0.104
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
|
@@ -14,6 +14,13 @@ describe("Record - create", () => {
|
|
|
14
14
|
|
|
15
15
|
project.buildProjectDetail({note: "Test note"})
|
|
16
16
|
|
|
17
|
+
expect(task.hasName()).toBeTrue()
|
|
18
|
+
expect(task.hasCreatedAt()).toBeFalse()
|
|
19
|
+
expect(project.hasName()).toBeTrue()
|
|
20
|
+
expect(project.hasNameEn()).toBeTrue()
|
|
21
|
+
expect(project.hasNameDe()).toBeTrue()
|
|
22
|
+
expect(project.hasUpdatedAt()).toBeFalse()
|
|
23
|
+
|
|
17
24
|
await task.save()
|
|
18
25
|
|
|
19
26
|
expect(task.id()).not.toBeUndefined()
|
|
@@ -70,16 +70,34 @@ export default class ProjectBase extends Record {
|
|
|
70
70
|
*/
|
|
71
71
|
name() { return this._getTranslatedAttributeWithFallback("name", this._getConfiguration().getLocale()) }
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @abstract
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
hasName() { throw new Error("hasName not implemented") }
|
|
78
|
+
|
|
73
79
|
/**
|
|
74
80
|
* @returns {string | null}
|
|
75
81
|
*/
|
|
76
82
|
nameDe() { return this._getTranslatedAttributeWithFallback("name", "de") }
|
|
77
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @abstract
|
|
86
|
+
* @returns {boolean}
|
|
87
|
+
*/
|
|
88
|
+
hasNameDe() { throw new Error("hasNameDe not implemented") }
|
|
89
|
+
|
|
78
90
|
/**
|
|
79
91
|
* @returns {string | null}
|
|
80
92
|
*/
|
|
81
93
|
nameEn() { return this._getTranslatedAttributeWithFallback("name", "en") }
|
|
82
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @abstract
|
|
97
|
+
* @returns {boolean}
|
|
98
|
+
*/
|
|
99
|
+
hasNameEn() { throw new Error("hasNameEn not implemented") }
|
|
100
|
+
|
|
83
101
|
/**
|
|
84
102
|
* @returns {import("../models/user.js").default}
|
|
85
103
|
*/
|
|
@@ -468,9 +468,6 @@ class VelociousDatabaseRecord {
|
|
|
468
468
|
const columnNameToAttributeName = this.getColumnNameToAttributeNameMap()
|
|
469
469
|
const attributeNameToColumnName = this.getAttributeNameToColumnNameMap()
|
|
470
470
|
|
|
471
|
-
/** @type {Record<string, (this: VelociousDatabaseRecord) => unknown>} */
|
|
472
|
-
const proto = /** @type {any} */ (this.prototype);
|
|
473
|
-
|
|
474
471
|
for (const column of this._columns) {
|
|
475
472
|
this._columnsAsHash[column.getName()] = column
|
|
476
473
|
|
|
@@ -480,17 +477,18 @@ class VelociousDatabaseRecord {
|
|
|
480
477
|
attributeNameToColumnName[camelizedColumnName] = column.getName()
|
|
481
478
|
columnNameToAttributeName[column.getName()] = camelizedColumnName
|
|
482
479
|
|
|
483
|
-
|
|
480
|
+
// @ts-expect-error
|
|
481
|
+
this.prototype[camelizedColumnName] = function() {
|
|
484
482
|
return this.readAttribute(camelizedColumnName)
|
|
485
483
|
}
|
|
486
484
|
|
|
487
485
|
// @ts-expect-error
|
|
488
|
-
|
|
489
|
-
// @ts-expect-error
|
|
486
|
+
this.prototype[`set${camelizedColumnNameBigFirst}`] = function(newValue) {
|
|
490
487
|
return this._setColumnAttribute(camelizedColumnName, newValue)
|
|
491
488
|
}
|
|
492
489
|
|
|
493
|
-
|
|
490
|
+
// @ts-expect-error
|
|
491
|
+
this.prototype[`has${camelizedColumnNameBigFirst}`] = function() {
|
|
494
492
|
// @ts-expect-error
|
|
495
493
|
let value = this[camelizedColumnName]()
|
|
496
494
|
|
|
@@ -539,24 +537,20 @@ class VelociousDatabaseRecord {
|
|
|
539
537
|
const nameCamelized = inflection.camelize(name)
|
|
540
538
|
const setterMethodName = `set${nameCamelized}`
|
|
541
539
|
|
|
542
|
-
/** @type {Record<string, unknown>} */
|
|
543
540
|
// @ts-expect-error
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
/** @type {Record<string, (this: VelociousDatabaseRecord) => unknown>} */
|
|
547
|
-
const proto = /** @type {any} */ (this.prototype);
|
|
548
|
-
|
|
549
|
-
proto[name] = function getTranslatedAttribute() {
|
|
541
|
+
this.prototype[name] = function getTranslatedAttribute() {
|
|
550
542
|
const locale = this._getConfiguration().getLocale()
|
|
551
543
|
|
|
552
544
|
return this._getTranslatedAttributeWithFallback(name, locale)
|
|
553
545
|
}
|
|
554
546
|
|
|
555
|
-
|
|
556
|
-
|
|
547
|
+
// @ts-expect-error
|
|
548
|
+
this.prototype[`has${nameCamelized}`] = function hasTranslatedAttribute() {
|
|
549
|
+
// @ts-expect-error
|
|
550
|
+
const candidate = this[name]
|
|
557
551
|
|
|
558
552
|
if (typeof candidate == "function") {
|
|
559
|
-
const value = candidate()
|
|
553
|
+
const value = candidate.bind(this)()
|
|
560
554
|
|
|
561
555
|
return this._hasAttribute(value)
|
|
562
556
|
} else {
|
|
@@ -565,11 +559,9 @@ class VelociousDatabaseRecord {
|
|
|
565
559
|
}
|
|
566
560
|
|
|
567
561
|
// @ts-expect-error
|
|
568
|
-
|
|
569
|
-
// @ts-expect-error
|
|
562
|
+
this.prototype[setterMethodName] = function setTranslatedAttribute(newValue) {
|
|
570
563
|
const locale = this._getConfiguration().getLocale()
|
|
571
564
|
|
|
572
|
-
// @ts-expect-error
|
|
573
565
|
return this._setTranslatedAttribute(name, locale, newValue)
|
|
574
566
|
}
|
|
575
567
|
|
|
@@ -577,6 +569,7 @@ class VelociousDatabaseRecord {
|
|
|
577
569
|
const localeCamelized = inflection.camelize(locale)
|
|
578
570
|
const getterMethodNameLocalized = `${name}${localeCamelized}`
|
|
579
571
|
const setterMethodNameLocalized = `${setterMethodName}${localeCamelized}`
|
|
572
|
+
const hasMethodNameLocalized = `has${inflection.camelize(name)}${localeCamelized}`
|
|
580
573
|
|
|
581
574
|
// @ts-expect-error
|
|
582
575
|
this.prototype[getterMethodNameLocalized] = function getTranslatedAttributeWithLocale() {
|
|
@@ -587,6 +580,20 @@ class VelociousDatabaseRecord {
|
|
|
587
580
|
this.prototype[setterMethodNameLocalized] = function setTranslatedAttributeWithLocale(newValue) {
|
|
588
581
|
return this._setTranslatedAttribute(name, locale, newValue)
|
|
589
582
|
}
|
|
583
|
+
|
|
584
|
+
// @ts-expect-error
|
|
585
|
+
this.prototype[hasMethodNameLocalized] = function hasTranslatedAttribute() {
|
|
586
|
+
// @ts-expect-error
|
|
587
|
+
const candidate = this[getterMethodNameLocalized]
|
|
588
|
+
|
|
589
|
+
if (typeof candidate == "function") {
|
|
590
|
+
const value = candidate.bind(this)()
|
|
591
|
+
|
|
592
|
+
return this._hasAttribute(value)
|
|
593
|
+
} else {
|
|
594
|
+
throw new Error(`Expected candidate to be a function but it was: ${typeof candidate}`)
|
|
595
|
+
}
|
|
596
|
+
}
|
|
590
597
|
}
|
|
591
598
|
}
|
|
592
599
|
}
|
|
@@ -98,6 +98,16 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
98
98
|
fileContent += ` ${name}() { return this._getTranslatedAttributeWithFallback("${name}", this._getConfiguration().getLocale()) }\n`
|
|
99
99
|
methodsCount++
|
|
100
100
|
|
|
101
|
+
const hasName = `has${inflection.camelize(name)}`
|
|
102
|
+
|
|
103
|
+
fileContent += `\n`
|
|
104
|
+
fileContent += " /**\n"
|
|
105
|
+
fileContent += ` * @abstract\n`
|
|
106
|
+
fileContent += ` * @returns {boolean}\n`
|
|
107
|
+
fileContent += " */\n"
|
|
108
|
+
fileContent += ` ${hasName}() { throw new Error("${hasName} not implemented") }\n`
|
|
109
|
+
methodsCount++
|
|
110
|
+
|
|
101
111
|
for (const locale of this.getConfiguration().getLocales()) {
|
|
102
112
|
const localeMethodName = `${name}${inflection.camelize(locale)}`
|
|
103
113
|
|
|
@@ -109,7 +119,16 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
fileContent += ` ${localeMethodName}() { return this._getTranslatedAttributeWithFallback("${name}", "${locale}") }\n`
|
|
122
|
+
methodsCount++
|
|
123
|
+
|
|
124
|
+
const localeHasName = `has${inflection.camelize(localeMethodName)}`
|
|
112
125
|
|
|
126
|
+
fileContent += `\n`
|
|
127
|
+
fileContent += " /**\n"
|
|
128
|
+
fileContent += ` * @abstract\n`
|
|
129
|
+
fileContent += ` * @returns {boolean}\n`
|
|
130
|
+
fileContent += " */\n"
|
|
131
|
+
fileContent += ` ${localeHasName}() { throw new Error("${localeHasName} not implemented") }\n`
|
|
113
132
|
methodsCount++
|
|
114
133
|
}
|
|
115
134
|
}
|