velocious 1.0.53 → 1.0.55
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/dummy/src/config/configuration.example.js +6 -3
- package/spec/dummy/src/config/configuration.peakflow.mariadb.js +3 -1
- package/spec/dummy/src/config/configuration.peakflow.mssql.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.pgsql.js +3 -1
- package/spec/dummy/src/config/configuration.peakflow.sqlite.js +3 -1
- package/src/configuration.js +3 -4
- package/src/database/migrator.js +32 -2
- package/src/testing/test-runner.js +3 -3
- package/src/utils/with-tracked-stack-async-hooks.js +69 -0
- package/src/utils/with-tracked-stack.js +12 -52
- package/src/utils/with-tracked-stack.native.js +0 -10
package/package.json
CHANGED
|
@@ -17,7 +17,8 @@ export default new Configuration({
|
|
|
17
17
|
host: "mariadb",
|
|
18
18
|
username: "username",
|
|
19
19
|
password: "password",
|
|
20
|
-
database: "velocious_development"
|
|
20
|
+
database: "velocious_development",
|
|
21
|
+
migrations: true
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
production: {
|
|
@@ -28,7 +29,8 @@ export default new Configuration({
|
|
|
28
29
|
host: "mariadb",
|
|
29
30
|
username: "username",
|
|
30
31
|
password: "password",
|
|
31
|
-
database: "velocious_production"
|
|
32
|
+
database: "velocious_production",
|
|
33
|
+
migrations: true
|
|
32
34
|
}
|
|
33
35
|
},
|
|
34
36
|
test: {
|
|
@@ -39,7 +41,8 @@ export default new Configuration({
|
|
|
39
41
|
host: "mariadb",
|
|
40
42
|
username: "username",
|
|
41
43
|
password: "password",
|
|
42
|
-
database: "velocious_test"
|
|
44
|
+
database: "velocious_test",
|
|
45
|
+
migrations: true
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
},
|
|
@@ -19,7 +19,8 @@ export default new Configuration({
|
|
|
19
19
|
username: "peakflow",
|
|
20
20
|
password: "password",
|
|
21
21
|
database: "velocious_test",
|
|
22
|
-
useDatabase: "velocious_test"
|
|
22
|
+
useDatabase: "velocious_test",
|
|
23
|
+
migrations: true
|
|
23
24
|
},
|
|
24
25
|
mssql: {
|
|
25
26
|
driver: MssqlDriver,
|
|
@@ -27,6 +28,7 @@ export default new Configuration({
|
|
|
27
28
|
type: "mssql",
|
|
28
29
|
database: "velocious_test",
|
|
29
30
|
useDatabase: "default",
|
|
31
|
+
migrations: true,
|
|
30
32
|
sqlConfig: {
|
|
31
33
|
user: "sa",
|
|
32
34
|
password: "Super-Secret-Password",
|
|
@@ -16,6 +16,7 @@ export default new Configuration({
|
|
|
16
16
|
type: "mssql",
|
|
17
17
|
database: "velocious_test",
|
|
18
18
|
useDatabase: "default",
|
|
19
|
+
migrations: true,
|
|
19
20
|
sqlConfig: {
|
|
20
21
|
user: "sa",
|
|
21
22
|
password: "Super-Secret-Password",
|
|
@@ -33,6 +34,7 @@ export default new Configuration({
|
|
|
33
34
|
type: "mssql",
|
|
34
35
|
database: "velocious_test",
|
|
35
36
|
useDatabase: "default",
|
|
37
|
+
migrations: true,
|
|
36
38
|
sqlConfig: {
|
|
37
39
|
user: "sa",
|
|
38
40
|
password: "Super-Secret-Password",
|
|
@@ -19,7 +19,8 @@ export default new Configuration({
|
|
|
19
19
|
username: "peakflow",
|
|
20
20
|
password: "password",
|
|
21
21
|
database: "velocious_test",
|
|
22
|
-
useDatabase: "velocious_test"
|
|
22
|
+
useDatabase: "velocious_test",
|
|
23
|
+
migrations: true
|
|
23
24
|
},
|
|
24
25
|
mssql: {
|
|
25
26
|
driver: MssqlDriver,
|
|
@@ -27,6 +28,7 @@ export default new Configuration({
|
|
|
27
28
|
type: "mssql",
|
|
28
29
|
database: "velocious_test",
|
|
29
30
|
useDatabase: "default",
|
|
31
|
+
migrations: true,
|
|
30
32
|
sqlConfig: {
|
|
31
33
|
user: "sa",
|
|
32
34
|
password: "Super-Secret-Password",
|
|
@@ -16,7 +16,8 @@ export default new Configuration({
|
|
|
16
16
|
driver: SqliteDriver,
|
|
17
17
|
poolType: SingleMultiUsePool,
|
|
18
18
|
type: "sqlite",
|
|
19
|
-
name: "test-db"
|
|
19
|
+
name: "test-db",
|
|
20
|
+
migrations: true
|
|
20
21
|
},
|
|
21
22
|
mssql: {
|
|
22
23
|
driver: MssqlDriver,
|
|
@@ -24,6 +25,7 @@ export default new Configuration({
|
|
|
24
25
|
type: "mssql",
|
|
25
26
|
database: "velocious_test",
|
|
26
27
|
useDatabase: "default",
|
|
28
|
+
migrations: true,
|
|
27
29
|
sqlConfig: {
|
|
28
30
|
user: "sa",
|
|
29
31
|
password: "Super-Secret-Password",
|
package/src/configuration.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
2
|
import restArgsError from "./utils/rest-args-error.js"
|
|
3
|
-
|
|
4
|
-
// import {withTrackedStack} from "./utils/with-tracked-stack.js"
|
|
3
|
+
import {withTrackedStack} from "./utils/with-tracked-stack.js"
|
|
5
4
|
|
|
6
5
|
export default class VelociousConfiguration {
|
|
7
6
|
static current(throwError = true) {
|
|
@@ -159,9 +158,9 @@ export default class VelociousConfiguration {
|
|
|
159
158
|
const dbs = {}
|
|
160
159
|
const stack = Error().stack
|
|
161
160
|
const actualCallback = async () => {
|
|
162
|
-
|
|
161
|
+
await withTrackedStack(stack, async () => {
|
|
163
162
|
return await callback(dbs)
|
|
164
|
-
|
|
163
|
+
})
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
let runRequest = actualCallback
|
package/src/database/migrator.js
CHANGED
|
@@ -17,8 +17,19 @@ export default class VelociousDatabaseMigrator {
|
|
|
17
17
|
async createMigrationsTable() {
|
|
18
18
|
const dbs = await this.configuration.getCurrentConnections()
|
|
19
19
|
|
|
20
|
-
for (const
|
|
21
|
-
|
|
20
|
+
for (const dbIdentifier in dbs) {
|
|
21
|
+
const db = dbs[dbIdentifier]
|
|
22
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
23
|
+
|
|
24
|
+
if (!databaseConfiguration.migrations) {
|
|
25
|
+
this.logger.log(`${dbIdentifier} isn't configured for migrations - skipping creating migrations table for it`)
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (await this.migrationsTableExist(db)) {
|
|
30
|
+
this.logger.log(`${dbIdentifier} migrations table already exists - skipping`)
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
22
33
|
|
|
23
34
|
const schemaMigrationsTable = new TableData("schema_migrations", {ifNotExists: true})
|
|
24
35
|
|
|
@@ -107,6 +118,18 @@ export default class VelociousDatabaseMigrator {
|
|
|
107
118
|
|
|
108
119
|
for (const dbIdentifier in dbs) {
|
|
109
120
|
const db = dbs[dbIdentifier]
|
|
121
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
122
|
+
|
|
123
|
+
if (!databaseConfiguration.migrations) {
|
|
124
|
+
this.logger.debug(`${dbIdentifier} isn't configured for migrations - skipping loading migrations versions for it`)
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!await this.migrationsTableExist(db)) {
|
|
129
|
+
this.logger.log(`Migration table does not exist for ${dbIdentifier} - skipping loading migrations versions for it`)
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
|
|
110
133
|
const rows = await db.select("schema_migrations")
|
|
111
134
|
|
|
112
135
|
this.migrationsVersions[dbIdentifier] = {}
|
|
@@ -204,6 +227,13 @@ export default class VelociousDatabaseMigrator {
|
|
|
204
227
|
const migrationDatabaseIdentifiers = migrationClass.getDatabaseIdentifiers() || ["default"]
|
|
205
228
|
|
|
206
229
|
for (const dbIdentifier in dbs) {
|
|
230
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
231
|
+
|
|
232
|
+
if (!databaseConfiguration.migrations) {
|
|
233
|
+
this.logger.debug(`${dbIdentifier} isn't configured for migrations - skipping migration ${digg(migration, "date")}`)
|
|
234
|
+
continue
|
|
235
|
+
}
|
|
236
|
+
|
|
207
237
|
if (!migrationDatabaseIdentifiers.includes(dbIdentifier)) {
|
|
208
238
|
this.logger.debug(`${dbIdentifier} shouldn't run migration ${migration.file}`, {migrationDatabaseIdentifiers})
|
|
209
239
|
continue
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import {addTrackedStackToError} from "../utils/with-tracked-stack.js"
|
|
2
2
|
import Application from "../../src/application.js"
|
|
3
3
|
import BacktraceCleaner from "../utils/backtrace-cleaner.js"
|
|
4
4
|
import RequestClient from "./request-client.js"
|
|
@@ -145,8 +145,8 @@ export default class TestRunner {
|
|
|
145
145
|
} catch (error) {
|
|
146
146
|
this._failedTests++
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
console.error(`${leftPadding} Test failed: ${error.message}`)
|
|
149
|
+
addTrackedStackToError(error)
|
|
150
150
|
|
|
151
151
|
const backtraceCleaner = new BacktraceCleaner(error)
|
|
152
152
|
const cleanedStack = backtraceCleaner.getCleanedStack()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {AsyncLocalStorage} from "async_hooks"
|
|
2
|
+
|
|
3
|
+
let asyncLocalStorage
|
|
4
|
+
|
|
5
|
+
if (AsyncLocalStorage) {
|
|
6
|
+
asyncLocalStorage = new AsyncLocalStorage()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function addTrackedStackToError(error) {
|
|
10
|
+
// Not supported
|
|
11
|
+
if (!asyncLocalStorage) return
|
|
12
|
+
|
|
13
|
+
const parentStacks = asyncLocalStorage.getStore() || []
|
|
14
|
+
const additionalStackLines = []
|
|
15
|
+
|
|
16
|
+
for (const parentStack of parentStacks) {
|
|
17
|
+
for (const parentStackLine of parentStack) {
|
|
18
|
+
additionalStackLines.push(parentStackLine)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Replace the error message on the first line with this string
|
|
23
|
+
error.stack += "\n" + additionalStackLines.join("\n")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function withTrackedStack(arg1, arg2) {
|
|
27
|
+
let callback, stack
|
|
28
|
+
|
|
29
|
+
if (arg2) {
|
|
30
|
+
callback = arg2
|
|
31
|
+
stack = arg1
|
|
32
|
+
} else {
|
|
33
|
+
callback = arg1
|
|
34
|
+
stack = Error().stack
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Not supported
|
|
38
|
+
if (!asyncLocalStorage) return await callback()
|
|
39
|
+
|
|
40
|
+
const parentStacks = asyncLocalStorage.getStore() || []
|
|
41
|
+
const additionalStackLines = []
|
|
42
|
+
const currentStackLines = stack.split("\n")
|
|
43
|
+
|
|
44
|
+
currentStackLines[0] = " [WITH TRACKED STACK]"
|
|
45
|
+
|
|
46
|
+
for (let i = currentStackLines.length; i >= 0; i--) {
|
|
47
|
+
const stackLine = currentStackLines[i]
|
|
48
|
+
|
|
49
|
+
additionalStackLines.unshift(stackLine)
|
|
50
|
+
|
|
51
|
+
if (stackLine == " [WITH TRACKED STACK]") {
|
|
52
|
+
break
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const newStacks = [additionalStackLines, ...parentStacks]
|
|
57
|
+
|
|
58
|
+
await asyncLocalStorage.run(newStacks, async () => {
|
|
59
|
+
return await callback()
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (globalThis.withTrackedStack) {
|
|
64
|
+
console.warn("globalThis.withTrackedStack was already defined")
|
|
65
|
+
} else {
|
|
66
|
+
globalThis.withTrackedStack = {addTrackedStackToError, withTrackedStack}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {addTrackedStackToError, withTrackedStack}
|
|
@@ -1,63 +1,23 @@
|
|
|
1
|
-
import {AsyncLocalStorage} from "async_hooks"
|
|
2
|
-
|
|
3
|
-
let asyncLocalStorage
|
|
4
|
-
|
|
5
|
-
if (AsyncLocalStorage) {
|
|
6
|
-
asyncLocalStorage = new AsyncLocalStorage()
|
|
7
|
-
}
|
|
8
|
-
|
|
9
1
|
function addTrackedStackToError(error) {
|
|
10
|
-
|
|
11
|
-
if (!asyncLocalStorage) return
|
|
12
|
-
|
|
13
|
-
const parentStacks = asyncLocalStorage.getStore() || []
|
|
14
|
-
const additionalStackLines = []
|
|
15
|
-
|
|
16
|
-
for (const parentStack of parentStacks) {
|
|
17
|
-
for (const parentStackLine of parentStack) {
|
|
18
|
-
additionalStackLines.push(parentStackLine)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Replace the error message on the first line with this string
|
|
23
|
-
error.stack += "\n" + additionalStackLines.join("\n")
|
|
2
|
+
globalThis.withTrackedStack?.addTrackedStackToError(error)
|
|
24
3
|
}
|
|
25
4
|
|
|
26
|
-
async function withTrackedStack(
|
|
27
|
-
|
|
5
|
+
async function withTrackedStack(...args) {
|
|
6
|
+
const withTrackedStack = globalThis.withTrackedStack?.withTrackedStack
|
|
28
7
|
|
|
29
|
-
|
|
30
|
-
callback = arg2
|
|
31
|
-
stack = arg1
|
|
32
|
-
} else {
|
|
33
|
-
callback = arg1
|
|
34
|
-
stack = Error().stack
|
|
35
|
-
}
|
|
8
|
+
let callback
|
|
36
9
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const additionalStackLines = []
|
|
42
|
-
const currentStackLines = stack.split("\n")
|
|
43
|
-
|
|
44
|
-
currentStackLines[0] = " [WITH TRACKED STACK]"
|
|
45
|
-
|
|
46
|
-
for (let i = currentStackLines.length; i >= 0; i--) {
|
|
47
|
-
const stackLine = currentStackLines[i]
|
|
48
|
-
|
|
49
|
-
additionalStackLines.unshift(stackLine)
|
|
50
|
-
|
|
51
|
-
if (stackLine == " [WITH TRACKED STACK]") {
|
|
52
|
-
break
|
|
53
|
-
}
|
|
10
|
+
if (args[1]) {
|
|
11
|
+
callback = args[1]
|
|
12
|
+
} else {
|
|
13
|
+
callback = args[0]
|
|
54
14
|
}
|
|
55
15
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
16
|
+
if (withTrackedStack) {
|
|
17
|
+
return await withTrackedStack(...args)
|
|
18
|
+
} else {
|
|
59
19
|
return await callback()
|
|
60
|
-
}
|
|
20
|
+
}
|
|
61
21
|
}
|
|
62
22
|
|
|
63
23
|
export {addTrackedStackToError, withTrackedStack}
|