velocious 1.0.106 → 1.0.108
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 +3 -1
- package/peak_flow.yml +1 -0
- package/spec/cli/commands/db/migrate-spec.js +7 -2
- package/spec/cli/commands/test/test-files-finder-spec.js +2 -0
- package/spec/database/connection/drivers/mysql/query-parser-spec.js +3 -1
- package/spec/database/drivers/mysql/connection-spec.js +1 -1
- package/spec/database/record/find-or-create-spec.js +3 -3
- package/spec/database/record/find-spec.js +1 -1
- package/spec/database/record/instance-relationships/belongs-to-relationship-spec.js +1 -1
- package/spec/database/record/instance-relationships/has-many-relationship-spec.js +3 -3
- package/spec/database/record/instance-relationships/has-one-relationship-spec.js +1 -1
- package/spec/database/record/last-spec.js +2 -2
- package/spec/database/record/preloader/belongs-to-spec.js +1 -1
- package/spec/database/record/preloader/has-many-spec.js +4 -4
- package/spec/database/record/preloader/has-one-spec.js +1 -1
- package/spec/database/record/query-spec.js +8 -6
- package/spec/database/record/translation-fallbacks-spec.js +1 -1
- package/spec/dummy/src/config/configuration.example.js +1 -0
- package/spec/dummy/src/config/routes.js +4 -0
- package/spec/dummy/src/model-bases/account.js +2 -2
- package/spec/dummy/src/model-bases/authentication-token.js +3 -3
- package/spec/dummy/src/model-bases/project-detail.js +3 -3
- package/spec/dummy/src/model-bases/project-translation.js +3 -3
- package/spec/dummy/src/model-bases/project.js +12 -12
- package/spec/dummy/src/model-bases/task.js +3 -3
- package/spec/dummy/src/model-bases/user.js +9 -9
- package/spec/dummy/src/routes/api/controller.js +9 -0
- package/spec/dummy/src/routes/projects/controller.js +1 -1
- package/spec/dummy/src/routes/tasks/controller.js +1 -3
- package/spec/http-server/client-spec.js +1 -1
- package/spec/http-server/get-spec.js +1 -1
- package/spec/http-server/namespace-spec.js +17 -0
- package/spec/http-server/post-spec.js +9 -9
- package/spec/http-server/root-get-spec.js +2 -1
- package/src/application.js +1 -0
- package/src/cli/base-command.js +1 -1
- package/src/cli/commands/db/create.js +1 -1
- package/src/cli/use-browser-cli.js +2 -0
- package/src/configuration-types.js +11 -6
- package/src/controller.js +1 -2
- package/src/database/drivers/base.js +9 -9
- package/src/database/drivers/mssql/index.js +11 -11
- package/src/database/drivers/mssql/options.js +10 -6
- package/src/database/drivers/mysql/index.js +8 -8
- package/src/database/drivers/mysql/options.js +10 -6
- package/src/database/drivers/pgsql/index.js +10 -10
- package/src/database/drivers/pgsql/options.js +9 -6
- package/src/database/drivers/sqlite/base.js +10 -10
- package/src/database/drivers/sqlite/connection-sql-js.js +2 -0
- package/src/database/drivers/sqlite/index.js +8 -2
- package/src/database/drivers/sqlite/index.native.js +5 -1
- package/src/database/drivers/sqlite/index.web.js +2 -1
- package/src/database/drivers/sqlite/options.js +10 -7
- package/src/database/drivers/sqlite/sql/alter-table.js +3 -3
- package/src/database/migration/index.js +16 -5
- package/src/database/migrator.js +5 -1
- package/src/database/pool/base-methods-forward.js +0 -4
- package/src/database/query/alter-table-base.js +2 -2
- package/src/database/query/base.js +2 -2
- package/src/database/query/create-index-base.js +2 -2
- package/src/database/query/create-table-base.js +4 -4
- package/src/database/query/drop-table-base.js +2 -2
- package/src/database/query/index.js +2 -2
- package/src/database/record/index.js +11 -44
- package/src/database/record/instance-relationships/base.js +2 -2
- package/src/database/record/instance-relationships/has-many.js +1 -1
- package/src/database/use-database.js +1 -0
- package/src/environment-handlers/base.js +2 -2
- package/src/environment-handlers/browser.js +40 -18
- package/src/environment-handlers/node/cli/commands/destroy/migration.js +5 -1
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +20 -9
- package/src/environment-handlers/node/cli/commands/generate/migration.js +5 -1
- package/src/environment-handlers/node/cli/commands/generate/model.js +5 -1
- package/src/environment-handlers/node/cli/commands/init.js +5 -1
- package/src/environment-handlers/node.js +1 -1
- package/src/http-server/client/index.js +2 -1
- package/src/http-server/client/params-to-object.js +0 -8
- package/src/http-server/client/request-buffer/index.js +1 -0
- package/src/routes/basic-route.js +1 -1
- package/src/routes/namespace-route.js +1 -1
- package/src/testing/test-files-finder.js +1 -1
- package/src/testing/test-runner.js +3 -0
- package/src/testing/test.js +0 -2
- package/src/utils/with-tracked-stack-async-hooks.js +0 -2
- package/src/utils/with-tracked-stack.js +0 -2
- package/tsconfig.json +15 -0
|
@@ -23,7 +23,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* @returns {string[]}
|
|
26
|
+
* @returns {Promise<string[]>}
|
|
27
27
|
*/
|
|
28
28
|
async toSQLs() {
|
|
29
29
|
const {tableData} = this
|
|
@@ -108,7 +108,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
|
|
|
108
108
|
tableDataColumn.setForeignKey(foreignKey)
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
const createNewTableSQL = this.getDriver().createTableSql(newTableData)
|
|
111
|
+
const createNewTableSQL = await this.getDriver().createTableSql(newTableData)
|
|
112
112
|
const insertSQL = `INSERT INTO ${options.quoteTableName(tempTableName)} (${newColumnsSQL}) SELECT ${oldColumnsSQL} FROM ${options.quoteTableName(tableName)}`
|
|
113
113
|
const dropTableSQLs = `DROP TABLE ${options.quoteTableName(tableName)}`
|
|
114
114
|
const renameTableSQL = `ALTER TABLE ${options.quoteTableName(tempTableName)} RENAME TO ${options.quoteTableName(tableName)}`
|
|
@@ -141,7 +141,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
|
|
|
141
141
|
tableName,
|
|
142
142
|
unique: actualTableIndex.getUnique()
|
|
143
143
|
}
|
|
144
|
-
const createIndexSQLs = new CreateIndexBase(createIndexArgs).toSQLs()
|
|
144
|
+
const createIndexSQLs = await new CreateIndexBase(createIndexArgs).toSQLs()
|
|
145
145
|
|
|
146
146
|
for (const createIndexSQL of createIndexSQLs) {
|
|
147
147
|
sqls.push(createIndexSQL)
|
|
@@ -135,7 +135,7 @@ export default class VelociousDatabaseMigration {
|
|
|
135
135
|
},
|
|
136
136
|
args
|
|
137
137
|
)
|
|
138
|
-
const sqls = this.getDriver().createIndexSQLs(createIndexArgs)
|
|
138
|
+
const sqls = await this.getDriver().createIndexSQLs(createIndexArgs)
|
|
139
139
|
|
|
140
140
|
for (const sql of sqls) {
|
|
141
141
|
await this.getDriver().query(sql)
|
|
@@ -246,14 +246,25 @@ export default class VelociousDatabaseMigration {
|
|
|
246
246
|
* @property {CreateTableIdArgsType | false} [id]
|
|
247
247
|
*/
|
|
248
248
|
/**
|
|
249
|
+
* @typedef {(TableData) => void} CreateTableCallbackType
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* @overload
|
|
253
|
+
* @param {string} tableName
|
|
254
|
+
* @param {CreateTableCallbackType} callback
|
|
255
|
+
* @returns {Promise<void>}
|
|
256
|
+
*/
|
|
257
|
+
/**
|
|
258
|
+
* @overload
|
|
249
259
|
* @param {string} tableName
|
|
250
|
-
* @param {
|
|
260
|
+
* @param {CreateTableArgsType} args
|
|
261
|
+
* @param {CreateTableCallbackType} callback
|
|
251
262
|
* @returns {Promise<void>}
|
|
252
263
|
*/
|
|
253
264
|
/**
|
|
254
265
|
* @param {string} tableName
|
|
255
|
-
* @param {CreateTableArgsType} arg1
|
|
256
|
-
* @param {
|
|
266
|
+
* @param {CreateTableArgsType | CreateTableCallbackType} arg1
|
|
267
|
+
* @param {CreateTableCallbackType | undefined} [arg2]
|
|
257
268
|
* @returns {Promise<void>}
|
|
258
269
|
*/
|
|
259
270
|
async createTable(tableName, arg1, arg2) {
|
|
@@ -297,7 +308,7 @@ export default class VelociousDatabaseMigration {
|
|
|
297
308
|
callback(tableData)
|
|
298
309
|
}
|
|
299
310
|
|
|
300
|
-
const sqls = this.getDriver().createTableSql(tableData)
|
|
311
|
+
const sqls = await this.getDriver().createTableSql(tableData)
|
|
301
312
|
|
|
302
313
|
for (const sql of sqls) {
|
|
303
314
|
await this._db.query(sql)
|
package/src/database/migrator.js
CHANGED
|
@@ -56,7 +56,7 @@ export default class VelociousDatabaseMigrator {
|
|
|
56
56
|
|
|
57
57
|
schemaMigrationsTable.string("version", {null: false, primaryKey: true})
|
|
58
58
|
|
|
59
|
-
const createSchemaMigrationsTableSqls = db.createTableSql(schemaMigrationsTable)
|
|
59
|
+
const createSchemaMigrationsTableSqls = await db.createTableSql(schemaMigrationsTable)
|
|
60
60
|
|
|
61
61
|
for (const createSchemaMigrationsTableSql of createSchemaMigrationsTableSqls) {
|
|
62
62
|
await db.query(createSchemaMigrationsTableSql)
|
|
@@ -64,6 +64,10 @@ export default class VelociousDatabaseMigrator {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
async dropDatabase() {
|
|
68
|
+
throw new Error("Not implemented yet")
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
/**
|
|
68
72
|
* @param {string} dbIdentifier
|
|
69
73
|
* @param {number} version
|
|
@@ -28,16 +28,12 @@ export default function baseMethodsForward(PoolBase) {
|
|
|
28
28
|
]
|
|
29
29
|
|
|
30
30
|
for (const forwardMethod of forwardMethods) {
|
|
31
|
-
// @ts-expect-error
|
|
32
31
|
PoolBase.prototype[forwardMethod] = function(...args) {
|
|
33
32
|
const connection = this.getCurrentConnection()
|
|
34
|
-
|
|
35
|
-
// @ts-expect-error
|
|
36
33
|
const connectionMethod = connection[forwardMethod]
|
|
37
34
|
|
|
38
35
|
if (!connectionMethod) throw new Error(`${forwardMethod} isn't defined on driver`)
|
|
39
36
|
|
|
40
|
-
// @ts-expect-error
|
|
41
37
|
return connection[forwardMethod](...args)
|
|
42
38
|
}
|
|
43
39
|
}
|
|
@@ -20,9 +20,9 @@ export default class VelociousDatabaseQueryAlterTableBase extends QueryBase {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* @returns {string[]}
|
|
23
|
+
* @returns {Promise<string[]>}
|
|
24
24
|
*/
|
|
25
|
-
toSQLs() {
|
|
25
|
+
async toSQLs() {
|
|
26
26
|
const databaseType = this.getDriver().getType()
|
|
27
27
|
const sqls = []
|
|
28
28
|
const {tableData} = this
|
|
@@ -52,9 +52,9 @@ export default class VelociousDatabaseQueryCreateIndexBase extends QueryBase {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @returns {string[]}
|
|
55
|
+
* @returns {Promise<string[]>}
|
|
56
56
|
*/
|
|
57
|
-
toSQLs() {
|
|
57
|
+
async toSQLs() {
|
|
58
58
|
const databaseType = this.getDriver().getType()
|
|
59
59
|
const indexName = this.name || this.generateIndexName()
|
|
60
60
|
const options = this.getOptions()
|
|
@@ -24,9 +24,9 @@ export default class VelociousDatabaseQueryCreateTableBase extends QueryBase {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* @returns {string[]}
|
|
27
|
+
* @returns {Promise<string[]>}
|
|
28
28
|
*/
|
|
29
|
-
toSql() {
|
|
29
|
+
async toSql() {
|
|
30
30
|
const databaseType = this.getDatabaseType()
|
|
31
31
|
const driver = this.getDriver()
|
|
32
32
|
const options = this.getOptions()
|
|
@@ -128,7 +128,7 @@ export default class VelociousDatabaseQueryCreateTableBase extends QueryBase {
|
|
|
128
128
|
tableName: tableData.getName(),
|
|
129
129
|
unique: index.getUnique()
|
|
130
130
|
}
|
|
131
|
-
const createIndexSQLs = new CreateIndexBase(createIndexArgs).toSQLs()
|
|
131
|
+
const createIndexSQLs = await new CreateIndexBase(createIndexArgs).toSQLs()
|
|
132
132
|
|
|
133
133
|
for (const createIndexSQL of createIndexSQLs) {
|
|
134
134
|
sqls.push(createIndexSQL)
|
|
@@ -156,7 +156,7 @@ export default class VelociousDatabaseQueryCreateTableBase extends QueryBase {
|
|
|
156
156
|
tableName: tableData.getName(),
|
|
157
157
|
unique
|
|
158
158
|
}
|
|
159
|
-
const createIndexSQLs = new CreateIndexBase(createIndexArgs).toSQLs()
|
|
159
|
+
const createIndexSQLs = await new CreateIndexBase(createIndexArgs).toSQLs()
|
|
160
160
|
|
|
161
161
|
for (const createIndexSQL of createIndexSQLs) {
|
|
162
162
|
sqls.push(createIndexSQL)
|
|
@@ -22,9 +22,9 @@ export default class VelociousDatabaseQueryDropTableBase extends QueryBase {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @returns {string[]}
|
|
25
|
+
* @returns {Promise<string[]>}
|
|
26
26
|
*/
|
|
27
|
-
toSQLs() {
|
|
27
|
+
async toSQLs() {
|
|
28
28
|
const databaseType = this.getDatabaseType()
|
|
29
29
|
const options = this.getOptions()
|
|
30
30
|
const {cascade, ifExists, tableName} = this
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
|
|
5
|
-
* @typedef {string|
|
|
6
|
-
* @typedef {object|string} WhereArgumentType
|
|
5
|
+
* @typedef {string | string[] | import("./select-base.js").default | import("./select-base.js").default[]} SelectArgumentType
|
|
6
|
+
* @typedef {object | string} WhereArgumentType
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import FromPlain from "./from-plain.js"
|
|
@@ -181,29 +181,20 @@ class VelociousDatabaseRecord {
|
|
|
181
181
|
actualData.className = inflection.camelize(inflection.singularize(relationshipName))
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
/** @type {Record<string, (this: VelociousDatabaseRecord) => unknown>} */
|
|
185
|
-
const proto = /** @type {any} */ (this.prototype);
|
|
186
|
-
|
|
187
184
|
let relationship
|
|
188
185
|
|
|
189
186
|
if (actualData.type == "belongsTo") {
|
|
190
187
|
relationship = new BelongsToRelationship(actualData)
|
|
191
188
|
|
|
192
|
-
|
|
189
|
+
this.prototype[relationshipName] = function() {
|
|
193
190
|
const relationship = this.getRelationshipByName(relationshipName)
|
|
194
191
|
|
|
195
192
|
return relationship.loaded()
|
|
196
193
|
}
|
|
197
194
|
|
|
198
|
-
|
|
199
|
-
proto[`build${inflection.camelize(relationshipName)}`] = function(attributes) {
|
|
200
|
-
// @ts-expect-error
|
|
195
|
+
this.prototype[`build${inflection.camelize(relationshipName)}`] = function(attributes) {
|
|
201
196
|
const instanceRelationship = this.getRelationshipByName(relationshipName)
|
|
202
|
-
|
|
203
|
-
// @ts-expect-error
|
|
204
197
|
const record = instanceRelationship.build(attributes)
|
|
205
|
-
|
|
206
|
-
// @ts-expect-error
|
|
207
198
|
const inverseOf = instanceRelationship.getRelationship().getInverseOf()
|
|
208
199
|
|
|
209
200
|
if (inverseOf) {
|
|
@@ -223,51 +214,40 @@ class VelociousDatabaseRecord {
|
|
|
223
214
|
return record
|
|
224
215
|
}
|
|
225
216
|
|
|
226
|
-
|
|
217
|
+
this.prototype[`load${inflection.camelize(relationshipName)}`] = async function() {
|
|
227
218
|
await this.getRelationshipByName(relationshipName).load()
|
|
228
219
|
}
|
|
229
220
|
|
|
230
|
-
|
|
231
|
-
proto[`set${inflection.camelize(relationshipName)}`] = function(model) {
|
|
232
|
-
// @ts-expect-error
|
|
221
|
+
this.prototype[`set${inflection.camelize(relationshipName)}`] = function(model) {
|
|
233
222
|
const relationship = this.getRelationshipByName(relationshipName)
|
|
234
223
|
|
|
235
|
-
// @ts-expect-error
|
|
236
224
|
relationship.setLoaded(model)
|
|
237
|
-
|
|
238
|
-
// @ts-expect-error
|
|
239
225
|
relationship.setDirty(true)
|
|
240
226
|
}
|
|
241
227
|
} else if (actualData.type == "hasMany") {
|
|
242
228
|
relationship = new HasManyRelationship(actualData)
|
|
243
229
|
|
|
244
|
-
|
|
245
|
-
return this.getRelationshipByName(relationshipName)
|
|
230
|
+
this.prototype[relationshipName] = function() {
|
|
231
|
+
return /** @type {import("./instance-relationships/has-many.js").default} */ (this.getRelationshipByName(relationshipName))
|
|
246
232
|
}
|
|
247
233
|
|
|
248
|
-
|
|
234
|
+
this.prototype[`${relationshipName}Loaded`] = function() {
|
|
249
235
|
return this.getRelationshipByName(relationshipName).loaded()
|
|
250
236
|
}
|
|
251
237
|
|
|
252
|
-
|
|
238
|
+
this.prototype[`load${inflection.camelize(relationshipName)}`] = async function() {
|
|
253
239
|
await this.getRelationshipByName(relationshipName).load()
|
|
254
240
|
}
|
|
255
241
|
} else if (actualData.type == "hasOne") {
|
|
256
242
|
relationship = new HasOneRelationship(actualData)
|
|
257
243
|
|
|
258
|
-
|
|
244
|
+
this.prototype[relationshipName] = function() {
|
|
259
245
|
return this.getRelationshipByName(relationshipName).loaded()
|
|
260
246
|
}
|
|
261
247
|
|
|
262
|
-
|
|
263
|
-
proto[`build${inflection.camelize(relationshipName)}`] = function(attributes) {
|
|
264
|
-
// @ts-expect-error
|
|
248
|
+
this.prototype[`build${inflection.camelize(relationshipName)}`] = function(attributes) {
|
|
265
249
|
const instanceRelationship = this.getRelationshipByName(relationshipName)
|
|
266
|
-
|
|
267
|
-
// @ts-expect-error
|
|
268
250
|
const record = instanceRelationship.build(attributes)
|
|
269
|
-
|
|
270
|
-
// @ts-expect-error
|
|
271
251
|
const inverseOf = instanceRelationship.getRelationship().getInverseOf()
|
|
272
252
|
|
|
273
253
|
if (inverseOf) {
|
|
@@ -280,7 +260,7 @@ class VelociousDatabaseRecord {
|
|
|
280
260
|
return record
|
|
281
261
|
}
|
|
282
262
|
|
|
283
|
-
|
|
263
|
+
this.prototype[`load${inflection.camelize(relationshipName)}`] = async function() {
|
|
284
264
|
await this.getRelationshipByName(relationshipName).load()
|
|
285
265
|
}
|
|
286
266
|
} else {
|
|
@@ -477,19 +457,15 @@ class VelociousDatabaseRecord {
|
|
|
477
457
|
attributeNameToColumnName[camelizedColumnName] = column.getName()
|
|
478
458
|
columnNameToAttributeName[column.getName()] = camelizedColumnName
|
|
479
459
|
|
|
480
|
-
// @ts-expect-error
|
|
481
460
|
this.prototype[camelizedColumnName] = function() {
|
|
482
461
|
return this.readAttribute(camelizedColumnName)
|
|
483
462
|
}
|
|
484
463
|
|
|
485
|
-
// @ts-expect-error
|
|
486
464
|
this.prototype[`set${camelizedColumnNameBigFirst}`] = function(newValue) {
|
|
487
465
|
return this._setColumnAttribute(camelizedColumnName, newValue)
|
|
488
466
|
}
|
|
489
467
|
|
|
490
|
-
// @ts-expect-error
|
|
491
468
|
this.prototype[`has${camelizedColumnNameBigFirst}`] = function() {
|
|
492
|
-
// @ts-expect-error
|
|
493
469
|
let value = this[camelizedColumnName]()
|
|
494
470
|
|
|
495
471
|
return this._hasAttribute(value)
|
|
@@ -537,16 +513,13 @@ class VelociousDatabaseRecord {
|
|
|
537
513
|
const nameCamelized = inflection.camelize(name)
|
|
538
514
|
const setterMethodName = `set${nameCamelized}`
|
|
539
515
|
|
|
540
|
-
// @ts-expect-error
|
|
541
516
|
this.prototype[name] = function getTranslatedAttribute() {
|
|
542
517
|
const locale = this._getConfiguration().getLocale()
|
|
543
518
|
|
|
544
519
|
return this._getTranslatedAttributeWithFallback(name, locale)
|
|
545
520
|
}
|
|
546
521
|
|
|
547
|
-
// @ts-expect-error
|
|
548
522
|
this.prototype[`has${nameCamelized}`] = function hasTranslatedAttribute() {
|
|
549
|
-
// @ts-expect-error
|
|
550
523
|
const candidate = this[name]
|
|
551
524
|
|
|
552
525
|
if (typeof candidate == "function") {
|
|
@@ -558,7 +531,6 @@ class VelociousDatabaseRecord {
|
|
|
558
531
|
}
|
|
559
532
|
}
|
|
560
533
|
|
|
561
|
-
// @ts-expect-error
|
|
562
534
|
this.prototype[setterMethodName] = function setTranslatedAttribute(newValue) {
|
|
563
535
|
const locale = this._getConfiguration().getLocale()
|
|
564
536
|
|
|
@@ -571,19 +543,15 @@ class VelociousDatabaseRecord {
|
|
|
571
543
|
const setterMethodNameLocalized = `${setterMethodName}${localeCamelized}`
|
|
572
544
|
const hasMethodNameLocalized = `has${inflection.camelize(name)}${localeCamelized}`
|
|
573
545
|
|
|
574
|
-
// @ts-expect-error
|
|
575
546
|
this.prototype[getterMethodNameLocalized] = function getTranslatedAttributeWithLocale() {
|
|
576
547
|
return this._getTranslatedAttribute(name, locale)
|
|
577
548
|
}
|
|
578
549
|
|
|
579
|
-
// @ts-expect-error
|
|
580
550
|
this.prototype[setterMethodNameLocalized] = function setTranslatedAttributeWithLocale(newValue) {
|
|
581
551
|
return this._setTranslatedAttribute(name, locale, newValue)
|
|
582
552
|
}
|
|
583
553
|
|
|
584
|
-
// @ts-expect-error
|
|
585
554
|
this.prototype[hasMethodNameLocalized] = function hasTranslatedAttribute() {
|
|
586
|
-
// @ts-expect-error
|
|
587
555
|
const candidate = this[getterMethodNameLocalized]
|
|
588
556
|
|
|
589
557
|
if (typeof candidate == "function") {
|
|
@@ -646,7 +614,6 @@ class VelociousDatabaseRecord {
|
|
|
646
614
|
if (!this.getModelClass().isInitialized()) throw new Error(`${this.constructor.name} model isn't initialized yet`)
|
|
647
615
|
if (!(setterName in this)) throw new Error(`No such setter method: ${this.constructor.name}#${setterName}`)
|
|
648
616
|
|
|
649
|
-
// @ts-expect-error
|
|
650
617
|
this[setterName](newValue)
|
|
651
618
|
}
|
|
652
619
|
|
|
@@ -17,10 +17,10 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @abstract
|
|
20
|
-
* @param {import("../index.js").default[]}
|
|
20
|
+
* @param {import("../index.js").default[] | import("../index.js").default} models
|
|
21
21
|
* @returns {void}
|
|
22
22
|
*/
|
|
23
|
-
addToLoaded(
|
|
23
|
+
addToLoaded(models) { // eslint-disable-line no-unused-vars
|
|
24
24
|
throw new Error("addToLoaded not implemented")
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -78,7 +78,7 @@ export default class VelociousDatabaseRecordHasManyInstanceRelationship extends
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* @param {import("../index.js").default[]} models
|
|
81
|
+
* @param {import("../index.js").default[] | import("../index.js").default} models
|
|
82
82
|
* @returns {void}
|
|
83
83
|
*/
|
|
84
84
|
addToLoaded(models) {
|
|
@@ -122,10 +122,10 @@ export default class VelociousEnvironmentHandlerBase {
|
|
|
122
122
|
importTestingConfigPath() { throw new Error(`'importTestingConfigPath' not implemented`) }
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
+
* @abstract
|
|
125
126
|
* @param {object} args
|
|
126
127
|
* @param {string[]} args.commandParts
|
|
127
|
-
* @returns {Promise<import ("../cli/base-command.js").default>}
|
|
128
|
-
* @abstract
|
|
128
|
+
* @returns {Promise<typeof import ("../cli/base-command.js").default>}
|
|
129
129
|
*/
|
|
130
130
|
async requireCommand({commandParts}) { throw new Error("'requireCommand' not implemented") } // eslint-disable-line no-unused-vars
|
|
131
131
|
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
import Base from "./base.js"
|
|
2
|
-
import {digg} from "diggerize"
|
|
3
2
|
import * as inflection from "inflection"
|
|
4
3
|
import restArgsError from "../utils/rest-args-error.js"
|
|
5
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {(id: string) => {default: typeof import("../database/migration/index.js").default}} MigrationsRequireContextIDFunctionType
|
|
7
|
+
* @typedef {MigrationsRequireContextIDFunctionType & {
|
|
8
|
+
* keys: () => string[],
|
|
9
|
+
* id: string
|
|
10
|
+
* }} MigrationsRequireContextType
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {(id: string) => {default: typeof import("../cli/base-command.js").default}} CommandsRequireContextIDFunctionType
|
|
15
|
+
* @typedef {CommandsRequireContextIDFunctionType & {
|
|
16
|
+
* keys: () => string[],
|
|
17
|
+
* id: string
|
|
18
|
+
* }} CommandsRequireContextType
|
|
19
|
+
*/
|
|
20
|
+
|
|
6
21
|
export default class VelociousEnvironmentsHandlerBrowser extends Base {
|
|
22
|
+
/** @type {CommandsRequireContextType | undefined} */
|
|
23
|
+
findCommandsRequireContextResult = undefined
|
|
24
|
+
|
|
25
|
+
/** @type {MigrationsRequireContextType | undefined} */
|
|
26
|
+
_migrationsRequireContextResult = undefined
|
|
27
|
+
|
|
7
28
|
/**
|
|
8
29
|
* @param {object} args
|
|
9
|
-
* @param {
|
|
30
|
+
* @param {() => Promise<MigrationsRequireContextType>} [args.migrationsRequireContextCallback]
|
|
10
31
|
*/
|
|
11
32
|
constructor({migrationsRequireContextCallback, ...restArgs} = {}) {
|
|
12
33
|
super()
|
|
@@ -16,29 +37,33 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
|
|
|
16
37
|
}
|
|
17
38
|
|
|
18
39
|
/**
|
|
19
|
-
* @returns {
|
|
40
|
+
* @returns {Promise<MigrationsRequireContextType>}
|
|
20
41
|
*/
|
|
21
|
-
migrationsRequireContext() {
|
|
22
|
-
const migrationsRequireContextCallback =
|
|
42
|
+
async migrationsRequireContext() {
|
|
43
|
+
const {migrationsRequireContextCallback} = this
|
|
23
44
|
|
|
24
45
|
if (!migrationsRequireContextCallback) throw new Error("migrationsRequireContextCallback is required")
|
|
25
46
|
|
|
26
|
-
this._migrationsRequireContextResult ||= migrationsRequireContextCallback()
|
|
47
|
+
this._migrationsRequireContextResult ||= await migrationsRequireContextCallback()
|
|
27
48
|
|
|
28
49
|
return this._migrationsRequireContextResult
|
|
29
50
|
}
|
|
30
51
|
|
|
31
52
|
/**
|
|
32
|
-
* @returns {Promise<Array<
|
|
53
|
+
* @returns {Promise<Array<import("./base.js").CommandFileObjectType>>}
|
|
33
54
|
*/
|
|
34
|
-
findCommands() {
|
|
55
|
+
async findCommands() {
|
|
35
56
|
this._findCommandsResult = this._actualFindCommands()
|
|
36
57
|
|
|
37
58
|
return this._findCommandsResult
|
|
38
59
|
}
|
|
39
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @returns {CommandsRequireContextType}
|
|
63
|
+
*/
|
|
40
64
|
_findCommandsRequireContext() {
|
|
41
|
-
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
this.findCommandsRequireContextResult ||= /** @type {CommandsRequireContextType} */ (require.context("../cli/commands", true, /\.js$/))
|
|
42
67
|
|
|
43
68
|
return this.findCommandsRequireContextResult
|
|
44
69
|
}
|
|
@@ -65,13 +90,11 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
|
|
|
65
90
|
}
|
|
66
91
|
|
|
67
92
|
/**
|
|
68
|
-
* @param {
|
|
69
|
-
* @
|
|
70
|
-
* @returns {Promise<
|
|
93
|
+
* @param {object} args
|
|
94
|
+
* @param {Array<string>} args.commandParts
|
|
95
|
+
* @returns {Promise<typeof import("../cli/base-command.js").default>}
|
|
71
96
|
*/
|
|
72
|
-
async requireCommand({commandParts
|
|
73
|
-
restArgsError(restArgs)
|
|
74
|
-
|
|
97
|
+
async requireCommand({commandParts}) {
|
|
75
98
|
let filePath = "."
|
|
76
99
|
|
|
77
100
|
for (let commandPart of commandParts) {
|
|
@@ -109,7 +132,7 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
|
|
|
109
132
|
}
|
|
110
133
|
|
|
111
134
|
/**
|
|
112
|
-
* @returns {Promise<Array<
|
|
135
|
+
* @returns {Promise<Array<import("./base.js").MigrationObjectType>>}
|
|
113
136
|
*/
|
|
114
137
|
async findMigrations() {
|
|
115
138
|
const migrationsRequireContext = await this.migrationsRequireContext()
|
|
@@ -150,8 +173,7 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
|
|
|
150
173
|
|
|
151
174
|
/**
|
|
152
175
|
* @param {string} filePath
|
|
153
|
-
* @
|
|
154
|
-
* @returns {Promise<T>}
|
|
176
|
+
* @returns {Promise<typeof import("../database/migration/index.js").default>}
|
|
155
177
|
*/
|
|
156
178
|
requireMigration = async (filePath) => {
|
|
157
179
|
if (!filePath) throw new Error("filePath is required")
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import BaseCommand from "../../../../../cli/base-command.js"
|
|
2
2
|
import fs from "fs/promises"
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{destroyed: string[]}} DestroyMigrationResult
|
|
6
|
+
*/
|
|
7
|
+
|
|
4
8
|
export default class DbDestroyMigration extends BaseCommand {
|
|
5
9
|
/**
|
|
6
|
-
* @returns {Promise<void>}
|
|
10
|
+
* @returns {Promise<void | DestroyMigrationResult>}
|
|
7
11
|
*/
|
|
8
12
|
async execute() {
|
|
9
13
|
const migrationName = this.processArgs[1]
|
|
@@ -29,14 +29,19 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
29
29
|
console.log(`create src/model-bases/${modelBaseFileName}`)
|
|
30
30
|
|
|
31
31
|
let fileContent = ""
|
|
32
|
+
let velociousPath = "velocious"
|
|
32
33
|
|
|
33
34
|
if (devMode) {
|
|
34
|
-
|
|
35
|
+
velociousPath = "../../../.."
|
|
36
|
+
fileContent += `import DatabaseRecord from "../../../../src/database/record/index.js"\n\n`
|
|
37
|
+
// /** @type {import("./instance-relationships/has-many.js").default} */
|
|
35
38
|
} else {
|
|
36
|
-
fileContent += `import
|
|
39
|
+
fileContent += `import DatabaseRecord from "velocious/src/database/record/index.js"\n\n`
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
const hasManyRelationFilePath = `${velociousPath}/src/database/record/instance-relationships/has-many.js`
|
|
43
|
+
|
|
44
|
+
fileContent += `export default class ${modelNameCamelized}Base extends DatabaseRecord {\n`
|
|
40
45
|
|
|
41
46
|
const columns = await modelClass._getTable().getColumns()
|
|
42
47
|
let methodsCount = 0
|
|
@@ -135,13 +140,15 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
for (const relationship of modelClass.getRelationships()) {
|
|
138
|
-
let fileName, fullFilePath
|
|
143
|
+
let baseFilePath, baseFullFilePath, fileName, fullFilePath
|
|
139
144
|
|
|
140
145
|
if (relationship.getPolymorphic()) {
|
|
141
146
|
fileName = "velocious/src/database/record/index.js"
|
|
142
147
|
} else {
|
|
143
148
|
fileName = inflection.dasherize(inflection.underscore(relationship.getTargetModelClass().name))
|
|
144
149
|
fullFilePath = `src/models/${fileName}.js`
|
|
150
|
+
baseFilePath = `../model-bases/${fileName}.js`
|
|
151
|
+
baseFullFilePath = `src/model-bases/${fileName}.js`
|
|
145
152
|
}
|
|
146
153
|
|
|
147
154
|
if (methodsCount > 0) {
|
|
@@ -153,6 +160,8 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
153
160
|
|
|
154
161
|
if (fullFilePath && await fileExists(fullFilePath)) {
|
|
155
162
|
modelFilePath = `../models/${fileName}.js`
|
|
163
|
+
} else if (baseFullFilePath && await fileExists(baseFullFilePath)) {
|
|
164
|
+
modelFilePath = baseFilePath
|
|
156
165
|
} else {
|
|
157
166
|
modelFilePath = "velocious/src/database/record/index.js"
|
|
158
167
|
}
|
|
@@ -160,7 +169,7 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
160
169
|
fileContent += " /**\n"
|
|
161
170
|
fileContent += ` * @returns {import("${modelFilePath}").default}\n`
|
|
162
171
|
fileContent += " */\n"
|
|
163
|
-
fileContent += ` ${relationship.getRelationshipName()}() { return this.getRelationshipByName("${relationship.getRelationshipName()}").loaded() }\n`
|
|
172
|
+
fileContent += ` ${relationship.getRelationshipName()}() { return /** @type {import("${modelFilePath}").default} */ (this.getRelationshipByName("${relationship.getRelationshipName()}").loaded()) }\n`
|
|
164
173
|
|
|
165
174
|
fileContent += "\n"
|
|
166
175
|
fileContent += " /**\n"
|
|
@@ -189,20 +198,22 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
189
198
|
|
|
190
199
|
if (fullFilePath && await fileExists(fullFilePath)) {
|
|
191
200
|
recordImport = `../models/${fileName}.js`
|
|
201
|
+
} else if (baseFullFilePath && await fileExists(baseFullFilePath)) {
|
|
202
|
+
recordImport = `../model-bases/${fileName}.js`
|
|
192
203
|
} else {
|
|
193
|
-
recordImport =
|
|
204
|
+
recordImport = `${velociousPath}/src/database/record/index.js`
|
|
194
205
|
}
|
|
195
206
|
|
|
196
207
|
fileContent += " /**\n"
|
|
197
|
-
fileContent += ` * @returns {import("
|
|
208
|
+
fileContent += ` * @returns {import("${hasManyRelationFilePath}").default}\n`
|
|
198
209
|
fileContent += " */\n"
|
|
199
|
-
fileContent += ` ${relationship.getRelationshipName()}() { return this.getRelationshipByName("${relationship.getRelationshipName()}") }\n`
|
|
210
|
+
fileContent += ` ${relationship.getRelationshipName()}() { return /** @type {import("${hasManyRelationFilePath}").default} */ (this.getRelationshipByName("${relationship.getRelationshipName()}")) }\n`
|
|
200
211
|
|
|
201
212
|
fileContent += "\n"
|
|
202
213
|
fileContent += " /**\n"
|
|
203
214
|
fileContent += ` * @returns {Array<import("${recordImport}").default>}\n`
|
|
204
215
|
fileContent += " */\n"
|
|
205
|
-
fileContent += ` ${relationship.getRelationshipName()}Loaded() { return this.getRelationshipByName("${relationship.getRelationshipName()}").loaded() }\n`
|
|
216
|
+
fileContent += ` ${relationship.getRelationshipName()}Loaded() { return /** @type {Array<import("${recordImport}").default>} */ (this.getRelationshipByName("${relationship.getRelationshipName()}").loaded()) }\n`
|
|
206
217
|
|
|
207
218
|
fileContent += "\n"
|
|
208
219
|
fileContent += " /**\n"
|
|
@@ -4,9 +4,13 @@ import fs from "fs/promises"
|
|
|
4
4
|
import * as inflection from "inflection"
|
|
5
5
|
import strftime from "strftime"
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{date: Date, migrationContent: string, migrationName: string, migrationNameCamelized: string, migrationNumber: string, migrationPath: string}} DbGenerateMigrationReturnType
|
|
9
|
+
*/
|
|
10
|
+
|
|
7
11
|
export default class DbGenerateMigration extends BaseCommand {
|
|
8
12
|
/**
|
|
9
|
-
* @returns {Promise<void>}
|
|
13
|
+
* @returns {Promise<void | DbGenerateMigrationReturnType>}
|
|
10
14
|
*/
|
|
11
15
|
async execute() {
|
|
12
16
|
const migrationName = this.processArgs[1]
|