@ditojs/server 0.272.0 → 0.273.0
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/lib/app/Application.js +39 -5
- package/lib/app/SessionStore.js +3 -1
- package/lib/app/Validator.js +13 -1
- package/lib/app/index.js +7 -1
- package/lib/cli/console.js +11 -1
- package/lib/cli/db/createMigration.js +13 -1
- package/lib/cli/db/index.js +7 -1
- package/lib/cli/db/seed.js +10 -2
- package/lib/cli/index.js +6 -2
- package/lib/controllers/AdminController.js +12 -2
- package/lib/controllers/CollectionController.js +15 -1
- package/lib/controllers/Controller.js +25 -1
- package/lib/controllers/ControllerAction.js +23 -14
- package/lib/controllers/RelationController.js +7 -1
- package/lib/controllers/UserController.js +15 -1
- package/lib/controllers/index.js +7 -1
- package/lib/decorators/index.js +7 -1
- package/lib/decorators/parameters.js +3 -1
- package/lib/decorators/returns.js +3 -1
- package/lib/errors/DatabaseError.js +5 -19
- package/lib/errors/ResponseError.js +4 -16
- package/lib/errors/index.js +7 -1
- package/lib/graph/DitoGraphProcessor.js +5 -1
- package/lib/graph/expression.js +5 -1
- package/lib/graph/graph.js +18 -2
- package/lib/graph/index.js +7 -1
- package/lib/index.js +7 -1
- package/lib/lib/index.js +7 -1
- package/lib/middleware/findRoute.js +7 -1
- package/lib/middleware/index.js +7 -1
- package/lib/mixins/AssetMixin.js +4 -4
- package/lib/mixins/SessionMixin.js +4 -4
- package/lib/mixins/TimeStampedMixin.js +4 -4
- package/lib/mixins/UserMixin.js +10 -4
- package/lib/mixins/index.js +7 -1
- package/lib/models/Model.js +21 -4
- package/lib/models/definitions/filters.js +9 -1
- package/lib/models/definitions/properties.js +7 -1
- package/lib/models/definitions/scopes.js +9 -1
- package/lib/models/index.js +7 -1
- package/lib/query/QueryBuilder.js +11 -1
- package/lib/query/QueryFilters.js +11 -1
- package/lib/query/index.js +7 -1
- package/lib/schema/formats/index.js +7 -1
- package/lib/schema/index.js +10 -2
- package/lib/schema/keywords/index.js +7 -1
- package/lib/schema/properties.js +11 -1
- package/lib/schema/relations.js +18 -4
- package/lib/services/index.js +7 -1
- package/lib/storage/DiskStorage.js +7 -1
- package/lib/storage/Storage.js +5 -1
- package/lib/storage/index.js +7 -1
- package/lib/utils/emitter.js +5 -1
- package/lib/utils/index.js +7 -1
- package/lib/utils/object.js +9 -3
- package/package.json +29 -29
- package/src/app/Application.js +23 -3
- package/src/controllers/AdminController.js +1 -1
- package/src/controllers/ControllerAction.js +7 -13
- package/src/errors/DatabaseError.js +2 -23
- package/src/errors/ResponseError.js +1 -9
- package/src/models/Model.js +10 -8
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from 'objection'
|
|
9
9
|
|
|
10
10
|
export class DatabaseError extends WrappedError {
|
|
11
|
-
constructor(error) {
|
|
11
|
+
constructor(error, overrides) {
|
|
12
12
|
const status =
|
|
13
13
|
error instanceof CheckViolationError ? 400
|
|
14
14
|
: error instanceof NotNullViolationError ? 400
|
|
@@ -16,28 +16,7 @@ export class DatabaseError extends WrappedError {
|
|
|
16
16
|
: error instanceof DataError ? 400
|
|
17
17
|
: error instanceof DBError ? 500
|
|
18
18
|
: 400
|
|
19
|
-
|
|
20
|
-
// TODO: Fix this properly in Knex / Objection instead, see:
|
|
21
|
-
// https://gitter.im/Vincit/objection.js?at=5a68728f5a9ebe4f75ca40b0
|
|
22
|
-
const [, sql, message] = error.message.match(/^([\s\S]*) - ([\s\S]*?)$/) ||
|
|
23
|
-
[null, null, error.message]
|
|
24
|
-
const overrides = {
|
|
25
|
-
type: error.constructor.name,
|
|
26
|
-
message,
|
|
27
|
-
sql,
|
|
28
|
-
status
|
|
29
|
-
}
|
|
19
|
+
overrides = { type: error.constructor.name, status, ...overrides }
|
|
30
20
|
super(error, overrides, { message: 'Database error', status })
|
|
31
21
|
}
|
|
32
|
-
|
|
33
|
-
toJSON() {
|
|
34
|
-
// Remove SQL query from displayed data in front-end when not in development
|
|
35
|
-
// or test.
|
|
36
|
-
if (process.env.NODE_ENV !== 'development' ||
|
|
37
|
-
process.env.NODE_ENV !== 'test') {
|
|
38
|
-
const { sql, ...data } = this.data
|
|
39
|
-
return data
|
|
40
|
-
}
|
|
41
|
-
return this.data
|
|
42
|
-
}
|
|
43
22
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isPlainObject, isString } from '@ditojs/utils'
|
|
2
|
-
import { formatJson } from '@/utils'
|
|
3
2
|
|
|
4
3
|
export class ResponseError extends Error {
|
|
5
4
|
constructor(error, defaults = { message: 'Response error', status: 400 }) {
|
|
@@ -22,14 +21,7 @@ export class ResponseError extends Error {
|
|
|
22
21
|
? { message: error }
|
|
23
22
|
: error || {}
|
|
24
23
|
const { status, ...data } = { ...defaults, ...object }
|
|
25
|
-
|
|
26
|
-
if (process.env.NODE_ENV === 'test' && error === object) {
|
|
27
|
-
// Include full JSON error in message during tests, for better reporting.
|
|
28
|
-
const { message: _, ...rest } = data
|
|
29
|
-
if (Object.keys(rest).length > 0) {
|
|
30
|
-
message = `${message}\nError Data:\n${formatJson(rest)}`
|
|
31
|
-
}
|
|
32
|
-
}
|
|
24
|
+
const { message, code } = data
|
|
33
25
|
super(message)
|
|
34
26
|
this.name = this.constructor.name
|
|
35
27
|
this.status = status
|
package/src/models/Model.js
CHANGED
|
@@ -5,8 +5,11 @@ import { convertSchema, addRelationSchemas, convertRelations } from '@/schema'
|
|
|
5
5
|
import { populateGraph, filterGraph } from '@/graph'
|
|
6
6
|
import { formatJson } from '@/utils'
|
|
7
7
|
import {
|
|
8
|
-
ResponseError,
|
|
9
|
-
|
|
8
|
+
ResponseError,
|
|
9
|
+
GraphError, ModelError,
|
|
10
|
+
NotFoundError,
|
|
11
|
+
RelationError,
|
|
12
|
+
WrappedError
|
|
10
13
|
} from '@/errors'
|
|
11
14
|
import {
|
|
12
15
|
isString, isObject, isArray, isFunction, isPromise, asArray, merge, flatten,
|
|
@@ -223,7 +226,7 @@ export class Model extends objection.Model {
|
|
|
223
226
|
return super.query(trx).onError(err => {
|
|
224
227
|
// TODO: Shouldn't this wrapping happen on the Controller level?
|
|
225
228
|
err = err instanceof ResponseError ? err
|
|
226
|
-
: err instanceof objection.DBError ?
|
|
229
|
+
: err instanceof objection.DBError ? this.app.createDatabaseError(err)
|
|
227
230
|
: new WrappedError(err)
|
|
228
231
|
return Promise.reject(err)
|
|
229
232
|
})
|
|
@@ -730,12 +733,11 @@ export class Model extends objection.Model {
|
|
|
730
733
|
case 'ModelValidation':
|
|
731
734
|
return this.app.createValidationError({
|
|
732
735
|
type,
|
|
733
|
-
message:
|
|
734
|
-
`The provided data for the ${this.name} model is not valid
|
|
735
|
-
formatJson(json)
|
|
736
|
-
}`,
|
|
736
|
+
message:
|
|
737
|
+
message || `The provided data for the ${this.name} model is not valid`,
|
|
737
738
|
errors,
|
|
738
|
-
options
|
|
739
|
+
options,
|
|
740
|
+
json
|
|
739
741
|
})
|
|
740
742
|
case 'RelationExpression':
|
|
741
743
|
case 'UnallowedRelation':
|