velocious 1.0.103 → 1.0.105
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/record/create-spec.js +7 -0
- package/spec/dummy/dummy-directory.js +2 -0
- package/spec/dummy/index.js +5 -1
- package/spec/dummy/src/model-bases/project.js +18 -0
- package/src/application.js +1 -0
- package/src/configuration-types.js +6 -0
- package/src/controller.js +44 -24
- package/src/database/drivers/base-foreign-key.js +1 -1
- package/src/database/drivers/base.js +2 -2
- package/src/database/drivers/mssql/column.js +6 -0
- package/src/database/drivers/mssql/columns-index.js +2 -5
- package/src/database/drivers/mssql/foreign-key.js +2 -0
- package/src/database/drivers/mssql/options.js +25 -0
- package/src/database/drivers/mssql/query-parser.js +2 -0
- package/src/database/drivers/mysql/options.js +9 -0
- package/src/database/drivers/mysql/sql/alter-table.js +2 -0
- package/src/database/drivers/mysql/sql/create-database.js +2 -0
- package/src/database/drivers/mysql/sql/create-index.js +2 -0
- package/src/database/drivers/mysql/sql/create-table.js +2 -0
- package/src/database/drivers/mysql/sql/delete.js +2 -0
- package/src/database/drivers/mysql/sql/drop-table.js +2 -0
- package/src/database/drivers/mysql/sql/insert.js +2 -0
- package/src/database/drivers/mysql/sql/update.js +2 -0
- package/src/database/drivers/pgsql/column.js +6 -0
- package/src/database/drivers/pgsql/columns-index.js +2 -0
- package/src/database/drivers/pgsql/foreign-key.js +2 -0
- package/src/database/drivers/pgsql/options.js +9 -0
- package/src/database/drivers/pgsql/query-parser.js +2 -0
- package/src/database/drivers/pgsql/sql/alter-table.js +2 -0
- package/src/database/drivers/pgsql/sql/create-database.js +5 -4
- package/src/database/drivers/pgsql/sql/create-index.js +2 -0
- package/src/database/drivers/pgsql/sql/create-table.js +2 -0
- package/src/database/drivers/pgsql/sql/delete.js +2 -0
- package/src/database/drivers/pgsql/sql/drop-table.js +2 -0
- package/src/database/drivers/pgsql/sql/insert.js +2 -0
- package/src/database/drivers/pgsql/sql/update.js +2 -0
- package/src/database/drivers/pgsql/table.js +6 -0
- package/src/database/drivers/sqlite/columns-index.js +2 -6
- package/src/database/drivers/sqlite/connection-remote.js +7 -0
- package/src/database/drivers/sqlite/connection-sql-js.js +12 -2
- package/src/database/drivers/sqlite/foreign-key.js +7 -0
- package/src/database/drivers/sqlite/index.js +7 -1
- package/src/database/drivers/sqlite/index.web.js +12 -3
- package/src/database/drivers/sqlite/options.js +9 -0
- package/src/database/drivers/sqlite/query-parser.js +2 -0
- package/src/database/drivers/sqlite/query.js +19 -6
- package/src/database/drivers/sqlite/query.web.js +13 -1
- package/src/database/initializer-from-require-context.js +11 -1
- package/src/database/migrator/types.js +2 -0
- package/src/database/pool/base-methods-forward.js +7 -0
- package/src/database/query/delete-base.js +8 -0
- package/src/database/query/preloader/belongs-to.js +16 -1
- package/src/database/query/preloader/has-many.js +19 -1
- package/src/database/query/preloader/has-one.js +20 -2
- package/src/database/query/preloader.js +19 -4
- package/src/database/query/update-base.js +9 -0
- package/src/database/query-parser/limit-parser.js +7 -2
- package/src/database/query-parser/options.js +47 -6
- package/src/database/query-parser/order-parser.js +11 -6
- package/src/database/query-parser/select-parser.js +8 -5
- package/src/database/query-parser/where-parser.js +11 -5
- package/src/database/record/index.js +28 -24
- package/src/database/record/instance-relationships/base.js +10 -1
- package/src/database/record/record-not-found-error.js +2 -0
- package/src/database/record/user-module.js +13 -0
- package/src/database/record/validators/uniqueness.js +13 -2
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +19 -0
- package/src/error-logger.js +17 -3
- package/src/http-client/index.js +34 -2
- package/src/http-client/request.js +1 -1
- package/src/http-server/client/params-to-object.js +28 -0
- package/src/initializer.js +2 -0
- package/src/routes/app-routes.js +3 -1
- package/src/routes/base-route.js +67 -58
- package/src/routes/basic-route.js +76 -0
- package/src/routes/get-route.js +21 -5
- package/src/routes/index.js +10 -0
- package/src/routes/namespace-route.js +21 -5
- package/src/routes/post-route.js +20 -5
- package/src/routes/resolver.js +15 -2
- package/src/routes/resource-route.js +21 -5
- package/src/routes/root-route.js +3 -3
- package/src/testing/request-client.js +19 -14
- package/src/testing/test-runner.js +16 -10
- package/src/testing/test.js +70 -22
- package/src/utils/with-tracked-stack-async-hooks.js +22 -4
- package/src/utils/with-tracked-stack.js +9 -0
package/src/testing/test.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import {anythingDifferent} from "set-state-compare/src/diff-utils.js"
|
|
2
4
|
import restArgsError from "../utils/rest-args-error.js"
|
|
3
5
|
|
|
6
|
+
/** @type {import("./test-runner.js").TestsArgument} */
|
|
4
7
|
const tests = {
|
|
8
|
+
/** @type {import("./test-runner.js").AfterBeforeEachCallbackObjectType[]} */
|
|
5
9
|
afterEaches: [],
|
|
6
10
|
args: {},
|
|
11
|
+
|
|
12
|
+
/** @type {import("./test-runner.js").AfterBeforeEachCallbackObjectType[]} */
|
|
7
13
|
beforeEaches: [],
|
|
8
14
|
subs: {},
|
|
9
15
|
tests: {}
|
|
@@ -12,7 +18,7 @@ const tests = {
|
|
|
12
18
|
let currentPath = [tests]
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
|
-
* @param {
|
|
21
|
+
* @param {import("./test-runner.js").AfterBeforeEachCallbackType} callback
|
|
16
22
|
* @returns {void}
|
|
17
23
|
*/
|
|
18
24
|
function beforeEach(callback) {
|
|
@@ -22,7 +28,7 @@ function beforeEach(callback) {
|
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
|
-
* @param {
|
|
31
|
+
* @param {import("./test-runner.js").AfterBeforeEachCallbackType} callback
|
|
26
32
|
* @returns {void}
|
|
27
33
|
*/
|
|
28
34
|
function afterEach(callback) {
|
|
@@ -31,8 +37,28 @@ function afterEach(callback) {
|
|
|
31
37
|
currentTest.afterEaches.push({callback})
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
class
|
|
40
|
+
class BaseExpect {
|
|
41
|
+
/**
|
|
42
|
+
* @abstract
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
*/
|
|
45
|
+
async runBefore() { /* do nothing */ }
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @abstract
|
|
49
|
+
* @returns {Promise<void>}
|
|
50
|
+
*/
|
|
51
|
+
async runAfter() { /* do nothing */ }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class ExpectToChange extends BaseExpect {
|
|
55
|
+
/**
|
|
56
|
+
* @param {object} args
|
|
57
|
+
* @param {function(): Promise<number>} args.changeCallback
|
|
58
|
+
* @param {Expect} args.expect
|
|
59
|
+
*/
|
|
35
60
|
constructor({changeCallback, expect, ...restArgs}) {
|
|
61
|
+
super()
|
|
36
62
|
restArgsError(restArgs)
|
|
37
63
|
|
|
38
64
|
this.expect = expect
|
|
@@ -58,9 +84,13 @@ class ExpectToChange {
|
|
|
58
84
|
}
|
|
59
85
|
|
|
60
86
|
/**
|
|
61
|
-
* @returns {void}
|
|
87
|
+
* @returns {Promise<void>}
|
|
62
88
|
*/
|
|
63
89
|
async execute() {
|
|
90
|
+
if (this.newCount === undefined || this.oldCount === undefined) {
|
|
91
|
+
throw new Error("ExpectToChange not executed properly")
|
|
92
|
+
}
|
|
93
|
+
|
|
64
94
|
const difference = this.newCount - this.oldCount
|
|
65
95
|
|
|
66
96
|
if (difference != this.count) {
|
|
@@ -69,20 +99,24 @@ class ExpectToChange {
|
|
|
69
99
|
}
|
|
70
100
|
}
|
|
71
101
|
|
|
72
|
-
class Expect {
|
|
102
|
+
class Expect extends BaseExpect {
|
|
73
103
|
/**
|
|
74
104
|
* @param {any} object
|
|
75
105
|
*/
|
|
76
106
|
constructor(object) {
|
|
107
|
+
super()
|
|
77
108
|
this._object = object
|
|
109
|
+
|
|
110
|
+
/** @type {Array<Expect | ExpectToChange>} */
|
|
78
111
|
this.expectations = []
|
|
79
112
|
}
|
|
80
113
|
|
|
81
114
|
/**
|
|
115
|
+
* @param {function(): Promise<number>} changeCallback
|
|
82
116
|
* @returns {ExpectToChange}
|
|
83
117
|
*/
|
|
84
|
-
andChange(
|
|
85
|
-
return this.toChange(
|
|
118
|
+
andChange(changeCallback) {
|
|
119
|
+
return this.toChange(changeCallback)
|
|
86
120
|
}
|
|
87
121
|
|
|
88
122
|
/**
|
|
@@ -126,6 +160,7 @@ class Expect {
|
|
|
126
160
|
}
|
|
127
161
|
|
|
128
162
|
/**
|
|
163
|
+
* @param {Function} klass
|
|
129
164
|
* @returns {void}
|
|
130
165
|
*/
|
|
131
166
|
toBeInstanceOf(klass) {
|
|
@@ -156,7 +191,7 @@ class Expect {
|
|
|
156
191
|
}
|
|
157
192
|
|
|
158
193
|
/**
|
|
159
|
-
* @param {function():
|
|
194
|
+
* @param {function(): Promise<number>} changeCallback
|
|
160
195
|
* @returns {ExpectToChange}
|
|
161
196
|
*/
|
|
162
197
|
toChange(changeCallback) {
|
|
@@ -230,7 +265,7 @@ class Expect {
|
|
|
230
265
|
/**
|
|
231
266
|
* @template T extends Error
|
|
232
267
|
* @param {string|T} expectedError
|
|
233
|
-
* @returns {void}
|
|
268
|
+
* @returns {Promise<void>}
|
|
234
269
|
*/
|
|
235
270
|
async toThrowError(expectedError) {
|
|
236
271
|
if (this._not) throw new Error("not stub")
|
|
@@ -249,14 +284,18 @@ class Expect {
|
|
|
249
284
|
|
|
250
285
|
if (typeof failedError == "string") {
|
|
251
286
|
failedErrorMessage = failedError
|
|
252
|
-
} else {
|
|
287
|
+
} else if (failedError instanceof Error) {
|
|
253
288
|
failedErrorMessage = failedError.message
|
|
289
|
+
} else {
|
|
290
|
+
failedErrorMessage = String(failedError)
|
|
254
291
|
}
|
|
255
292
|
|
|
256
293
|
if (typeof expectedError == "string") {
|
|
257
294
|
expectedErrorMessage = expectedError
|
|
258
|
-
} else {
|
|
295
|
+
} else if (expectedError instanceof Error) {
|
|
259
296
|
expectedErrorMessage = expectedError.message
|
|
297
|
+
} else {
|
|
298
|
+
expectedErrorMessage = String(expectedError)
|
|
260
299
|
}
|
|
261
300
|
|
|
262
301
|
if (failedErrorMessage != expectedErrorMessage) {
|
|
@@ -265,7 +304,7 @@ class Expect {
|
|
|
265
304
|
}
|
|
266
305
|
|
|
267
306
|
/**
|
|
268
|
-
* @returns {any}
|
|
307
|
+
* @returns {Promise<any>}
|
|
269
308
|
*/
|
|
270
309
|
async execute() {
|
|
271
310
|
for (const expectation of this.expectations) {
|
|
@@ -286,12 +325,13 @@ class Expect {
|
|
|
286
325
|
}
|
|
287
326
|
|
|
288
327
|
/**
|
|
289
|
-
* @param {
|
|
328
|
+
* @param {Record<string, any>} result
|
|
290
329
|
* @returns {void}
|
|
291
330
|
*/
|
|
292
331
|
toHaveAttributes(result) {
|
|
293
332
|
if (this._not) throw new Error("not stub")
|
|
294
333
|
|
|
334
|
+
/** @type {Record<string, any[]>} */
|
|
295
335
|
const differences = {}
|
|
296
336
|
|
|
297
337
|
for (const key in result) {
|
|
@@ -314,9 +354,9 @@ class Expect {
|
|
|
314
354
|
|
|
315
355
|
/**
|
|
316
356
|
* @param {string} description
|
|
317
|
-
* @param {object|() => Promise<void>} arg1
|
|
318
|
-
* @param {undefined|() => Promise<void>} [arg2]
|
|
319
|
-
* @returns {void}
|
|
357
|
+
* @param {object|(() => Promise<void>)} arg1
|
|
358
|
+
* @param {undefined|(() => Promise<void>)} [arg2]
|
|
359
|
+
* @returns {Promise<void>}
|
|
320
360
|
*/
|
|
321
361
|
async function describe(description, arg1, arg2) {
|
|
322
362
|
let testArgs, testFunction
|
|
@@ -360,15 +400,19 @@ function expect(arg) {
|
|
|
360
400
|
|
|
361
401
|
/**
|
|
362
402
|
* @param {string} description
|
|
363
|
-
* @param {object|() => Promise<void>} arg1
|
|
364
|
-
* @param {undefined|() => Promise<void>} [arg2]
|
|
403
|
+
* @param {object|(() => Promise<void>)} arg1
|
|
404
|
+
* @param {undefined|(() => Promise<void>)} [arg2]
|
|
365
405
|
* @returns {void}
|
|
366
406
|
*/
|
|
367
407
|
function it(description, arg1, arg2) {
|
|
368
408
|
const currentTest = currentPath[currentPath.length - 1]
|
|
369
|
-
let testArgs
|
|
409
|
+
let testArgs
|
|
410
|
+
|
|
411
|
+
/** @type {() => Promise<void>} */
|
|
412
|
+
let testFunction
|
|
370
413
|
|
|
371
414
|
if (typeof arg1 == "function") {
|
|
415
|
+
// @ts-expect-error
|
|
372
416
|
testFunction = arg1
|
|
373
417
|
testArgs = {}
|
|
374
418
|
} else if (typeof arg2 == "function") {
|
|
@@ -385,14 +429,18 @@ function it(description, arg1, arg2) {
|
|
|
385
429
|
|
|
386
430
|
/**
|
|
387
431
|
* @param {string} description
|
|
388
|
-
* @param {object|() => Promise<void>} arg1
|
|
389
|
-
* @param {undefined|() => Promise<void>} [arg2]
|
|
432
|
+
* @param {object|(() => Promise<void>)} arg1
|
|
433
|
+
* @param {undefined|(() => Promise<void>)} [arg2]
|
|
390
434
|
* @returns {void}
|
|
391
435
|
*/
|
|
392
436
|
function fit(description, arg1, arg2) {
|
|
393
|
-
let testArgs
|
|
437
|
+
let testArgs
|
|
438
|
+
|
|
439
|
+
/** @type {() => Promise<void>} */
|
|
440
|
+
let testFunction
|
|
394
441
|
|
|
395
442
|
if (typeof arg1 == "function") {
|
|
443
|
+
// @ts-expect-error
|
|
396
444
|
testFunction = arg1
|
|
397
445
|
testArgs = {focus: true}
|
|
398
446
|
} else if (typeof arg2 == "function") {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import {AsyncLocalStorage} from "async_hooks"
|
|
2
4
|
|
|
5
|
+
/** @type {AsyncLocalStorage<Array<string[]>> | undefined} */
|
|
3
6
|
let asyncLocalStorage
|
|
4
7
|
|
|
5
8
|
if (AsyncLocalStorage) {
|
|
6
9
|
asyncLocalStorage = new AsyncLocalStorage()
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/** @param {Error} error */
|
|
9
13
|
function addTrackedStackToError(error) {
|
|
10
14
|
// Not supported
|
|
11
15
|
if (!asyncLocalStorage) return
|
|
@@ -23,15 +27,27 @@ function addTrackedStackToError(error) {
|
|
|
23
27
|
error.stack += "\n" + additionalStackLines.join("\n")
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {() => Promise<void> | string} arg1
|
|
33
|
+
* @param {() => Promise<void> | Error} [arg2]
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
*/
|
|
26
36
|
async function withTrackedStack(arg1, arg2) {
|
|
27
|
-
|
|
37
|
+
/** @type {() => Promise<void>} */
|
|
38
|
+
let callback
|
|
39
|
+
|
|
40
|
+
/** @type {string} */
|
|
41
|
+
let stack
|
|
28
42
|
|
|
29
|
-
if (arg2) {
|
|
43
|
+
if (typeof arg2 == "function" && typeof arg1 == "string") {
|
|
44
|
+
// @ts-expect-error
|
|
30
45
|
callback = arg2
|
|
31
46
|
stack = arg1
|
|
32
47
|
} else {
|
|
48
|
+
// @ts-expect-error
|
|
33
49
|
callback = arg1
|
|
34
|
-
stack = Error().stack
|
|
50
|
+
stack = Error().stack || ""
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
// Not supported
|
|
@@ -56,13 +72,15 @@ async function withTrackedStack(arg1, arg2) {
|
|
|
56
72
|
const newStacks = [additionalStackLines, ...parentStacks]
|
|
57
73
|
|
|
58
74
|
await asyncLocalStorage.run(newStacks, async () => {
|
|
59
|
-
|
|
75
|
+
await callback()
|
|
60
76
|
})
|
|
61
77
|
}
|
|
62
78
|
|
|
79
|
+
// @ts-expect-error
|
|
63
80
|
if (globalThis.withTrackedStack) {
|
|
64
81
|
console.warn("globalThis.withTrackedStack was already defined")
|
|
65
82
|
} else {
|
|
83
|
+
// @ts-expect-error
|
|
66
84
|
globalThis.withTrackedStack = {addTrackedStackToError, withTrackedStack}
|
|
67
85
|
}
|
|
68
86
|
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** @param {Error} error */
|
|
1
4
|
function addTrackedStackToError(error) {
|
|
5
|
+
// @ts-expect-error
|
|
2
6
|
globalThis.withTrackedStack?.addTrackedStackToError(error)
|
|
3
7
|
}
|
|
4
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @param {...any} args
|
|
11
|
+
* @returns {Promise<any>}
|
|
12
|
+
*/
|
|
5
13
|
async function withTrackedStack(...args) {
|
|
14
|
+
// @ts-expect-error
|
|
6
15
|
const withTrackedStack = globalThis.withTrackedStack?.withTrackedStack
|
|
7
16
|
|
|
8
17
|
let callback
|