velocious 1.0.99 → 1.0.101
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/spec/database/migration/column-exists-spec.js +28 -0
- package/spec/database/record/create-spec.js +14 -7
- package/spec/database/transactions-spec.js +8 -1
- package/spec/dummy/src/model-bases/account.js +67 -0
- package/spec/dummy/src/model-bases/authentication-token.js +108 -0
- package/spec/dummy/src/model-bases/project-detail.js +101 -0
- package/spec/dummy/src/model-bases/project-translation.js +124 -0
- package/spec/dummy/src/model-bases/project.js +178 -0
- package/spec/dummy/src/model-bases/task.js +117 -0
- package/spec/dummy/src/model-bases/user.js +170 -0
- package/spec/dummy/src/models/account.js +2 -2
- package/spec/dummy/src/models/authentication-token.js +2 -2
- package/spec/dummy/src/models/project-detail.js +2 -2
- package/spec/dummy/src/models/project.js +2 -2
- package/spec/dummy/src/models/task.js +2 -2
- package/spec/dummy/src/models/user.js +2 -2
- package/src/cli/base-command.js +1 -1
- package/src/configuration.js +6 -2
- package/src/database/drivers/base-column.js +8 -7
- package/src/database/drivers/base-columns-index.js +1 -1
- package/src/database/drivers/base-foreign-key.js +5 -5
- package/src/database/drivers/base-table.js +4 -4
- package/src/database/drivers/base.js +18 -19
- package/src/database/drivers/mysql/column.js +8 -0
- package/src/database/migration/index.js +7 -5
- package/src/database/pool/base.js +5 -5
- package/src/database/query/base.js +1 -1
- package/src/database/query/from-base.js +2 -4
- package/src/database/query/order-base.js +1 -1
- package/src/database/query/select-base.js +1 -1
- package/src/database/query/where-base.js +1 -1
- package/src/database/record/index.js +5 -2
- package/src/database/record/relationships/base.js +2 -2
- package/src/database/record/validators/base.js +1 -1
- package/src/environment-handlers/base.js +7 -7
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +79 -24
- package/src/initializer.js +1 -1
- package/src/routes/base-route.js +1 -1
- package/src/testing/test.js +3 -3
|
@@ -91,7 +91,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* @
|
|
94
|
+
* @abstract
|
|
95
95
|
* @param {import("../table-data/index.js").default} _tableData
|
|
96
96
|
* @returns {Promise<string[]>}
|
|
97
97
|
*/
|
|
@@ -100,7 +100,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
* @
|
|
103
|
+
* @abstract
|
|
104
104
|
* @returns {Promise<void>}
|
|
105
105
|
*/
|
|
106
106
|
connect() {
|
|
@@ -108,7 +108,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* @
|
|
111
|
+
* @abstract
|
|
112
112
|
* @param {CreateIndexSqlArgs} indexData
|
|
113
113
|
* @returns {string}
|
|
114
114
|
*/
|
|
@@ -129,7 +129,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* @
|
|
132
|
+
* @abstract
|
|
133
133
|
* @param {import("../table-data/index.js").default} tableData
|
|
134
134
|
* @returns {string[]}
|
|
135
135
|
*/
|
|
@@ -148,7 +148,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
|
-
* @
|
|
151
|
+
* @abstract
|
|
152
152
|
* @param {DeleteSqlArgsType} args
|
|
153
153
|
* @returns {string}
|
|
154
154
|
*/
|
|
@@ -170,7 +170,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
|
-
* @
|
|
173
|
+
* @abstract
|
|
174
174
|
* @param {string} tableName
|
|
175
175
|
* @param {DropTableSqlArgsType} [args]
|
|
176
176
|
* @returns {string}
|
|
@@ -180,7 +180,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* @
|
|
183
|
+
* @abstract
|
|
184
184
|
* @param {any} value
|
|
185
185
|
* @returns {any}
|
|
186
186
|
*/
|
|
@@ -212,7 +212,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
-
* @
|
|
215
|
+
* @abstract
|
|
216
216
|
* @returns {Array<import("./base-table.js").default>}
|
|
217
217
|
*/
|
|
218
218
|
getTables() {
|
|
@@ -235,7 +235,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
|
-
* @
|
|
238
|
+
* @abstract
|
|
239
239
|
* @returns {string}
|
|
240
240
|
*/
|
|
241
241
|
getType() {
|
|
@@ -253,7 +253,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
|
-
* @
|
|
256
|
+
* @abstract
|
|
257
257
|
* @param {InsertSqlArgsType} args
|
|
258
258
|
* @returns {string}
|
|
259
259
|
*/
|
|
@@ -262,7 +262,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
/**
|
|
265
|
-
* @
|
|
265
|
+
* @abstract
|
|
266
266
|
* @returns {Promise<number>}
|
|
267
267
|
*/
|
|
268
268
|
lastInsertID() {
|
|
@@ -282,7 +282,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
/**
|
|
285
|
-
* @
|
|
285
|
+
* @abstract
|
|
286
286
|
* @returns {import("../query-parser/options.js").default}
|
|
287
287
|
*/
|
|
288
288
|
options() {
|
|
@@ -361,7 +361,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
/**
|
|
364
|
-
* @
|
|
364
|
+
* @abstract
|
|
365
365
|
* @returns {boolean}
|
|
366
366
|
*/
|
|
367
367
|
shouldSetAutoIncrementWhenPrimaryKey() {
|
|
@@ -498,7 +498,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
/**
|
|
501
|
-
* @
|
|
501
|
+
* @abstract
|
|
502
502
|
* @param {string} sql
|
|
503
503
|
* @returns {Promise<QueryResultType>}
|
|
504
504
|
*/
|
|
@@ -507,14 +507,13 @@ export default class VelociousDatabaseDriversBase {
|
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
/**
|
|
510
|
-
* @
|
|
510
|
+
* @abstract
|
|
511
511
|
* @param {Query} _query
|
|
512
512
|
* @returns {string}
|
|
513
513
|
*/
|
|
514
514
|
queryToSql(_query) { throw new Error("queryToSql not implemented") } // eslint-disable-line no-unused-vars
|
|
515
515
|
|
|
516
516
|
/**
|
|
517
|
-
* @interface
|
|
518
517
|
* @param {Error} _error
|
|
519
518
|
* @returns {boolean}
|
|
520
519
|
*/
|
|
@@ -674,7 +673,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
674
673
|
}
|
|
675
674
|
|
|
676
675
|
/**
|
|
677
|
-
* @
|
|
676
|
+
* @abstract
|
|
678
677
|
* @param {UpdateSqlArgsType} args
|
|
679
678
|
* @returns {string}
|
|
680
679
|
*/
|
|
@@ -683,7 +682,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
683
682
|
}
|
|
684
683
|
|
|
685
684
|
/**
|
|
686
|
-
* @
|
|
685
|
+
* @abstract
|
|
687
686
|
* @returns {Promise<void>}
|
|
688
687
|
*/
|
|
689
688
|
disableForeignKeys() {
|
|
@@ -691,7 +690,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
691
690
|
}
|
|
692
691
|
|
|
693
692
|
/**
|
|
694
|
-
* @
|
|
693
|
+
* @abstract
|
|
695
694
|
* @returns {Promise<void>}
|
|
696
695
|
*/
|
|
697
696
|
enableForeignKeys() {
|
|
@@ -83,7 +83,15 @@ export default class VelociousDatabaseDriversMysqlColumn extends BaseColumn {
|
|
|
83
83
|
|
|
84
84
|
getType() {
|
|
85
85
|
const type = digg(this, "data", "Type")
|
|
86
|
+
|
|
87
|
+
if (type.match(/^[a-z]+$/)) {
|
|
88
|
+
return type
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
const match = type.match(/^(.+)\((\d+)\)$/)
|
|
92
|
+
|
|
93
|
+
if (!match) throw new Error(`Couldn't match column type from: ${type}`)
|
|
94
|
+
|
|
87
95
|
const columnType = match[1]
|
|
88
96
|
|
|
89
97
|
return columnType
|
|
@@ -223,13 +223,15 @@ export default class VelociousDatabaseMigration {
|
|
|
223
223
|
async columnExists(tableName, columnName) {
|
|
224
224
|
const table = await this.getDriver().getTableByName(tableName)
|
|
225
225
|
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
const column = await table.getColumnByName(columnName)
|
|
226
|
+
if (table) {
|
|
227
|
+
const column = await table.getColumnByName(columnName)
|
|
229
228
|
|
|
230
|
-
|
|
229
|
+
if (column) {
|
|
230
|
+
return true
|
|
231
|
+
}
|
|
232
|
+
}
|
|
231
233
|
|
|
232
|
-
return Boolean(
|
|
234
|
+
return Boolean(false)
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
/**
|
|
@@ -36,7 +36,7 @@ class VelociousDatabasePoolBase {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @
|
|
39
|
+
* @abstract
|
|
40
40
|
* @param {import("../drivers/base.js").default} _connection
|
|
41
41
|
*/
|
|
42
42
|
checkin(_connection) { // eslint-disable-line no-unused-vars
|
|
@@ -44,7 +44,7 @@ class VelociousDatabasePoolBase {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* @
|
|
47
|
+
* @abstract
|
|
48
48
|
* @returns {Promise<import("../drivers/base.js").default>}
|
|
49
49
|
*/
|
|
50
50
|
checkout() {
|
|
@@ -52,7 +52,7 @@ class VelociousDatabasePoolBase {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @
|
|
55
|
+
* @abstract
|
|
56
56
|
* @returns {import("../drivers/base.js").default}
|
|
57
57
|
*/
|
|
58
58
|
getCurrentConnection() {
|
|
@@ -67,7 +67,7 @@ class VelociousDatabasePoolBase {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* @
|
|
70
|
+
* @abstract
|
|
71
71
|
* @returns {string}
|
|
72
72
|
*/
|
|
73
73
|
primaryKeyType() {
|
|
@@ -119,7 +119,7 @@ class VelociousDatabasePoolBase {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* @
|
|
122
|
+
* @abstract
|
|
123
123
|
* @param {function(import("../drivers/base.js").default) : void} _callback
|
|
124
124
|
* @returns {Promise<void>}
|
|
125
125
|
*/
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import Query from "./index.js"
|
|
4
|
-
|
|
5
3
|
export default class VelociousDatabaseQueryFromBase {
|
|
6
|
-
/** @type {
|
|
4
|
+
/** @type {import("./index.js").default | null} */
|
|
7
5
|
query = null
|
|
8
6
|
|
|
9
7
|
/**
|
|
@@ -24,7 +22,7 @@ export default class VelociousDatabaseQueryFromBase {
|
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
|
-
* @
|
|
25
|
+
* @abstract
|
|
28
26
|
* @returns {string[]}
|
|
29
27
|
*/
|
|
30
28
|
toSql() {
|
|
@@ -269,7 +269,7 @@ class VelociousDatabaseRecord {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
|
-
* @param {Record<string, any>} attributes
|
|
272
|
+
* @param {Record<string, any>} [attributes]
|
|
273
273
|
* @returns {Promise<InstanceType<typeof this>>}
|
|
274
274
|
*/
|
|
275
275
|
static async create(attributes) {
|
|
@@ -511,6 +511,9 @@ class VelociousDatabaseRecord {
|
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
/**
|
|
515
|
+
* @returns {import("../drivers/base-column.js").default[]}
|
|
516
|
+
*/
|
|
514
517
|
static getColumns() {
|
|
515
518
|
if (!this._columns) throw new Error(`${this.name} hasn't been initialized yet`)
|
|
516
519
|
|
|
@@ -763,7 +766,7 @@ class VelociousDatabaseRecord {
|
|
|
763
766
|
}
|
|
764
767
|
|
|
765
768
|
/**
|
|
766
|
-
* @returns {VelociousDatabaseRecord}
|
|
769
|
+
* @returns {typeof VelociousDatabaseRecord}
|
|
767
770
|
*/
|
|
768
771
|
static getTranslationClass() {
|
|
769
772
|
if (this._translationClass) return this._translationClass
|
|
@@ -42,7 +42,7 @@ export default class VelociousDatabaseRecordBaseRelationship {
|
|
|
42
42
|
getDependent() { return this._dependent }
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* @
|
|
45
|
+
* @abstract
|
|
46
46
|
* @returns {string} The name of the foreign key, e.g. "user_id", "post_id" etc.
|
|
47
47
|
*/
|
|
48
48
|
getForeignKey() {
|
|
@@ -50,7 +50,7 @@ export default class VelociousDatabaseRecordBaseRelationship {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* @
|
|
53
|
+
* @abstract
|
|
54
54
|
* @returns {string} The name of the inverse relationship, e.g. "posts", "comments" etc.
|
|
55
55
|
*/
|
|
56
56
|
getInverseOf() {
|
|
@@ -72,13 +72,13 @@ export default class VelociousEnvironmentHandlerBase {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* @
|
|
75
|
+
* @abstract
|
|
76
76
|
* @returns {Promise<CommandFileObjectType[]>}
|
|
77
77
|
*/
|
|
78
78
|
async findCommands() { throw new Error("findCommands not implemented") }
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* @
|
|
81
|
+
* @abstract
|
|
82
82
|
* @returns {Promise<Array<MigrationObjectType>>}
|
|
83
83
|
*/
|
|
84
84
|
async findMigrations() { throw new Error("findMigrations not implemneted") }
|
|
@@ -97,26 +97,26 @@ export default class VelociousEnvironmentHandlerBase {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* @
|
|
100
|
+
* @abstract
|
|
101
101
|
* @returns {Promise<string>}
|
|
102
102
|
*/
|
|
103
103
|
getVelociousPath() { throw new Error("getVelociousPath not implemented") }
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* @
|
|
106
|
+
* @abstract
|
|
107
107
|
* @returns {Promise<import("../routes/index.js").default>}
|
|
108
108
|
*/
|
|
109
109
|
async importApplicationRoutes() { throw new Error("importApplicationRoutes not implemented") }
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* @
|
|
112
|
+
* @abstract
|
|
113
113
|
* @param {string[]} _testFiles
|
|
114
114
|
* @returns {Promise<void>}
|
|
115
115
|
*/
|
|
116
116
|
importTestFiles(_testFiles) { throw new Error("'importTestFiles' not implemented") } // eslint-disable-line no-unused-vars
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* @
|
|
119
|
+
* @abstract
|
|
120
120
|
* @returns {Promise<void>}
|
|
121
121
|
*/
|
|
122
122
|
importTestingConfigPath() { throw new Error(`'importTestingConfigPath' not implemented`) }
|
|
@@ -125,7 +125,7 @@ export default class VelociousEnvironmentHandlerBase {
|
|
|
125
125
|
* @param {object} args
|
|
126
126
|
* @param {string[]} args.commandParts
|
|
127
127
|
* @returns {Promise<import ("../cli/base-command.js").default>}
|
|
128
|
-
* @
|
|
128
|
+
* @abstract
|
|
129
129
|
*/
|
|
130
130
|
async requireCommand({commandParts}) { throw new Error("'requireCommand' not implemented") } // eslint-disable-line no-unused-vars
|
|
131
131
|
|
|
@@ -9,6 +9,11 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
9
9
|
|
|
10
10
|
const modelsDir = `${process.cwd()}/src/model-bases`
|
|
11
11
|
const modelClasses = this.getConfiguration().getModelClasses()
|
|
12
|
+
let devMode = false
|
|
13
|
+
|
|
14
|
+
if (modelsDir.endsWith("velocious/spec/dummy/src/model-bases")) {
|
|
15
|
+
devMode = true
|
|
16
|
+
}
|
|
12
17
|
|
|
13
18
|
if (!await fileExists(modelsDir)) {
|
|
14
19
|
await fs.mkdir(modelsDir, {recursive: true})
|
|
@@ -23,7 +28,13 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
23
28
|
|
|
24
29
|
console.log(`create src/model-bases/${modelBaseFileName}`)
|
|
25
30
|
|
|
26
|
-
let fileContent =
|
|
31
|
+
let fileContent = ""
|
|
32
|
+
|
|
33
|
+
if (devMode) {
|
|
34
|
+
fileContent += `import Record from "../../../../src/database/record/index.js"\n\n`
|
|
35
|
+
} else {
|
|
36
|
+
fileContent += `import Record from "velocious/src/database/record/index.js"\n\n`
|
|
37
|
+
}
|
|
27
38
|
|
|
28
39
|
fileContent += `export default class ${modelNameCamelized}Base extends Record {\n`
|
|
29
40
|
|
|
@@ -33,15 +44,7 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
33
44
|
for (const column of columns) {
|
|
34
45
|
const camelizedColumnName = inflection.camelize(column.getName(), true)
|
|
35
46
|
const camelizedColumnNameBigFirst = inflection.camelize(column.getName())
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (column.getType() == "varchar") {
|
|
39
|
-
jsdocType = "string"
|
|
40
|
-
} else if (["bigint", "int", "integer", "smallint"].includes(column.getType())) {
|
|
41
|
-
jsdocType = "number"
|
|
42
|
-
} else if (["date", "datetime"].includes(column.getType())) {
|
|
43
|
-
jsdocType = "Date"
|
|
44
|
-
}
|
|
47
|
+
const jsdocType = this.jsDocTypeFromColumn(column)
|
|
45
48
|
|
|
46
49
|
if (methodsCount > 0) {
|
|
47
50
|
fileContent += "\n"
|
|
@@ -49,7 +52,7 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
49
52
|
|
|
50
53
|
if (jsdocType) {
|
|
51
54
|
fileContent += " /**\n"
|
|
52
|
-
fileContent += ` * @returns {${jsdocType}}\n`
|
|
55
|
+
fileContent += ` * @returns {${jsdocType}${column.getNull() ? " | null" : ""}}\n`
|
|
53
56
|
fileContent += " */\n"
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -57,7 +60,7 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
57
60
|
|
|
58
61
|
if (jsdocType) {
|
|
59
62
|
fileContent += " /**\n"
|
|
60
|
-
fileContent += ` * @param {${jsdocType}} newValue\n`
|
|
63
|
+
fileContent += ` * @param {${jsdocType}${column.getNull() ? " | null" : ""}} newValue\n`
|
|
61
64
|
fileContent += " * @returns {void}\n"
|
|
62
65
|
fileContent += " */\n"
|
|
63
66
|
}
|
|
@@ -72,6 +75,46 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
72
75
|
methodsCount++
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
if (modelClass._translations) {
|
|
79
|
+
const TranslationClass = modelClass.getTranslationClass()
|
|
80
|
+
const translationColumns = TranslationClass.getColumns()
|
|
81
|
+
|
|
82
|
+
for (const name in modelClass._translations) {
|
|
83
|
+
const nameUnderscore = inflection.underscore(name)
|
|
84
|
+
const column = translationColumns.find((translationColumn) => translationColumn.getName() === nameUnderscore)
|
|
85
|
+
let translationJsdocType
|
|
86
|
+
|
|
87
|
+
if (column) {
|
|
88
|
+
translationJsdocType = this.jsDocTypeFromColumn(column)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (translationJsdocType) {
|
|
92
|
+
fileContent += `\n`
|
|
93
|
+
fileContent += " /**\n"
|
|
94
|
+
fileContent += ` * @returns {${translationJsdocType}${column.getNull() ? " | null" : ""}}\n`
|
|
95
|
+
fileContent += " */\n"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fileContent += ` ${name}() { return this._getTranslatedAttributeWithFallback("${name}", this._getConfiguration().getLocale()) }\n`
|
|
99
|
+
methodsCount++
|
|
100
|
+
|
|
101
|
+
for (const locale of this.getConfiguration().getLocales()) {
|
|
102
|
+
const localeMethodName = `${name}${inflection.camelize(locale)}`
|
|
103
|
+
|
|
104
|
+
if (translationJsdocType) {
|
|
105
|
+
fileContent += `\n`
|
|
106
|
+
fileContent += " /**\n"
|
|
107
|
+
fileContent += ` * @returns {${translationJsdocType}${column.getNull() ? " | null" : ""}}\n`
|
|
108
|
+
fileContent += " */\n"
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fileContent += ` ${localeMethodName}() { return this._getTranslatedAttributeWithFallback("${name}", "${locale}") }\n`
|
|
112
|
+
|
|
113
|
+
methodsCount++
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
75
118
|
for (const relationship of modelClass.getRelationships()) {
|
|
76
119
|
let fileName, fullFilePath
|
|
77
120
|
|
|
@@ -96,32 +139,32 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
96
139
|
}
|
|
97
140
|
|
|
98
141
|
fileContent += " /**\n"
|
|
99
|
-
fileContent += " * @interface\n"
|
|
100
142
|
fileContent += ` * @returns {import("${modelFilePath}").default}\n`
|
|
101
143
|
fileContent += " */\n"
|
|
102
144
|
fileContent += ` ${relationship.getRelationshipName()}() { return this.getRelationshipByName("${relationship.getRelationshipName()}").loaded() }\n`
|
|
103
145
|
|
|
104
146
|
fileContent += "\n"
|
|
105
147
|
fileContent += " /**\n"
|
|
106
|
-
fileContent += " * @
|
|
148
|
+
fileContent += " * @abstract\n"
|
|
149
|
+
fileContent += " * @param {Record<string, any>} attributes\n"
|
|
107
150
|
fileContent += ` * @returns {import("${modelFilePath}").default}\n`
|
|
108
151
|
fileContent += " */\n"
|
|
109
|
-
fileContent += ` build${inflection.camelize(relationship.getRelationshipName())}() { throw new Error("Not implemented") }\n`
|
|
152
|
+
fileContent += ` build${inflection.camelize(relationship.getRelationshipName())}(attributes) { throw new Error("Not implemented") } // eslint-disable-line no-unused-vars\n`
|
|
110
153
|
|
|
111
154
|
fileContent += "\n"
|
|
112
155
|
fileContent += " /**\n"
|
|
113
|
-
fileContent += " * @
|
|
156
|
+
fileContent += " * @abstract\n"
|
|
114
157
|
fileContent += " * @returns {Promise<void>}\n"
|
|
115
158
|
fileContent += " */\n"
|
|
116
159
|
fileContent += ` load${inflection.camelize(relationship.getRelationshipName())}() { throw new Error("Not implemented") }\n`
|
|
117
160
|
|
|
118
161
|
fileContent += "\n"
|
|
119
162
|
fileContent += " /**\n"
|
|
120
|
-
fileContent += " * @
|
|
163
|
+
fileContent += " * @abstract\n"
|
|
121
164
|
fileContent += ` * @param {import("${modelFilePath}").default} newModel\n`
|
|
122
165
|
fileContent += ` * @returns {void}\n`
|
|
123
166
|
fileContent += " */\n"
|
|
124
|
-
fileContent += ` set${inflection.camelize(relationship.getRelationshipName())}() { throw new Error("Not implemented") }\n`
|
|
167
|
+
fileContent += ` set${inflection.camelize(relationship.getRelationshipName())}(newModel) { throw new Error("Not implemented") } // eslint-disable-line no-unused-vars\n`
|
|
125
168
|
} else if (relationship.getType() == "hasMany") {
|
|
126
169
|
let recordImport
|
|
127
170
|
|
|
@@ -132,32 +175,30 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
132
175
|
}
|
|
133
176
|
|
|
134
177
|
fileContent += " /**\n"
|
|
135
|
-
fileContent += " * @interface\n"
|
|
136
178
|
fileContent += ` * @returns {import("velocious/src/database/query/index.js").default<import("${recordImport}").default>}\n`
|
|
137
179
|
fileContent += " */\n"
|
|
138
180
|
fileContent += ` ${relationship.getRelationshipName()}() { return this.getRelationshipByName("${relationship.getRelationshipName()}") }\n`
|
|
139
181
|
|
|
140
182
|
fileContent += "\n"
|
|
141
183
|
fileContent += " /**\n"
|
|
142
|
-
fileContent += " * @interface\n"
|
|
143
184
|
fileContent += ` * @returns {Array<import("${recordImport}").default>}\n`
|
|
144
185
|
fileContent += " */\n"
|
|
145
186
|
fileContent += ` ${relationship.getRelationshipName()}Loaded() { return this.getRelationshipByName("${relationship.getRelationshipName()}").loaded() }\n`
|
|
146
187
|
|
|
147
188
|
fileContent += "\n"
|
|
148
189
|
fileContent += " /**\n"
|
|
149
|
-
fileContent += " * @
|
|
190
|
+
fileContent += " * @abstract\n"
|
|
150
191
|
fileContent += " * @returns {Promise<void>}\n"
|
|
151
192
|
fileContent += " */\n"
|
|
152
193
|
fileContent += ` load${inflection.camelize(relationship.getRelationshipName())}() { throw new Error("Not implemented") }\n`
|
|
153
194
|
|
|
154
195
|
fileContent += "\n"
|
|
155
196
|
fileContent += " /**\n"
|
|
156
|
-
fileContent += " * @
|
|
197
|
+
fileContent += " * @abstract\n"
|
|
157
198
|
fileContent += ` * @param {Array<import("${recordImport}").default>} newModels\n`
|
|
158
|
-
fileContent += " * @returns {void
|
|
199
|
+
fileContent += " * @returns {void}\n"
|
|
159
200
|
fileContent += " */\n"
|
|
160
|
-
fileContent += ` set${inflection.camelize(relationship.getRelationshipName())}() { throw new Error("Not implemented") }\n`
|
|
201
|
+
fileContent += ` set${inflection.camelize(relationship.getRelationshipName())}(newModels) { throw new Error("Not implemented") } // eslint-disable-line no-unused-vars\n`
|
|
161
202
|
} else {
|
|
162
203
|
throw new Error(`Unknown relationship type: ${relationship.getType()}`)
|
|
163
204
|
}
|
|
@@ -170,4 +211,18 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
170
211
|
await fs.writeFile(modelPath, fileContent)
|
|
171
212
|
}
|
|
172
213
|
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {import("../../../../../database/drivers/base-column.js").default} column
|
|
217
|
+
* @returns {string | undefined}
|
|
218
|
+
*/
|
|
219
|
+
jsDocTypeFromColumn(column) {
|
|
220
|
+
if (column.getType() == "varchar") {
|
|
221
|
+
return "string"
|
|
222
|
+
} else if (["bigint", "int", "integer", "smallint"].includes(column.getType())) {
|
|
223
|
+
return "number"
|
|
224
|
+
} else if (["date", "datetime"].includes(column.getType())) {
|
|
225
|
+
return "Date"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
173
228
|
}
|
package/src/initializer.js
CHANGED
package/src/routes/base-route.js
CHANGED
package/src/testing/test.js
CHANGED
|
@@ -315,7 +315,7 @@ class Expect {
|
|
|
315
315
|
/**
|
|
316
316
|
* @param {string} description
|
|
317
317
|
* @param {object|() => Promise<void>} arg1
|
|
318
|
-
* @param {undefined|() => Promise<void>} arg2
|
|
318
|
+
* @param {undefined|() => Promise<void>} [arg2]
|
|
319
319
|
* @returns {void}
|
|
320
320
|
*/
|
|
321
321
|
async function describe(description, arg1, arg2) {
|
|
@@ -361,7 +361,7 @@ function expect(arg) {
|
|
|
361
361
|
/**
|
|
362
362
|
* @param {string} description
|
|
363
363
|
* @param {object|() => Promise<void>} arg1
|
|
364
|
-
* @param {undefined|() => Promise<void>} arg2
|
|
364
|
+
* @param {undefined|() => Promise<void>} [arg2]
|
|
365
365
|
* @returns {void}
|
|
366
366
|
*/
|
|
367
367
|
function it(description, arg1, arg2) {
|
|
@@ -386,7 +386,7 @@ function it(description, arg1, arg2) {
|
|
|
386
386
|
/**
|
|
387
387
|
* @param {string} description
|
|
388
388
|
* @param {object|() => Promise<void>} arg1
|
|
389
|
-
* @param {undefined|() => Promise<void>} arg2
|
|
389
|
+
* @param {undefined|() => Promise<void>} [arg2]
|
|
390
390
|
* @returns {void}
|
|
391
391
|
*/
|
|
392
392
|
function fit(description, arg1, arg2) {
|