@ditojs/server 0.271.0 → 0.274.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.
Files changed (86) hide show
  1. package/lib/app/Application.js +68 -25
  2. package/lib/app/SessionStore.js +3 -1
  3. package/lib/app/Validator.js +16 -2
  4. package/lib/app/index.js +7 -1
  5. package/lib/cli/console.js +14 -4
  6. package/lib/cli/db/createMigration.js +16 -4
  7. package/lib/cli/db/index.js +7 -1
  8. package/lib/cli/db/listAssetConfig.js +4 -2
  9. package/lib/cli/db/migrate.js +3 -3
  10. package/lib/cli/db/reset.js +3 -3
  11. package/lib/cli/db/rollback.js +3 -3
  12. package/lib/cli/db/seed.js +14 -6
  13. package/lib/cli/db/unlock.js +3 -3
  14. package/lib/cli/index.js +9 -5
  15. package/lib/controllers/AdminController.js +18 -6
  16. package/lib/controllers/CollectionController.js +15 -1
  17. package/lib/controllers/Controller.js +28 -4
  18. package/lib/controllers/ControllerAction.js +18 -6
  19. package/lib/controllers/RelationController.js +9 -3
  20. package/lib/controllers/UserController.js +15 -1
  21. package/lib/controllers/index.js +7 -1
  22. package/lib/decorators/index.js +7 -1
  23. package/lib/decorators/parameters.js +4 -2
  24. package/lib/decorators/returns.js +4 -2
  25. package/lib/errors/DatabaseError.js +5 -19
  26. package/lib/errors/ResponseError.js +4 -14
  27. package/lib/errors/index.js +7 -1
  28. package/lib/graph/DitoGraphProcessor.js +5 -1
  29. package/lib/graph/expression.js +5 -1
  30. package/lib/graph/graph.js +18 -2
  31. package/lib/graph/index.js +7 -1
  32. package/lib/index.js +7 -1
  33. package/lib/lib/index.js +7 -1
  34. package/lib/middleware/findRoute.js +7 -1
  35. package/lib/middleware/index.js +7 -1
  36. package/lib/middleware/logRequests.js +4 -4
  37. package/lib/mixins/AssetMixin.js +4 -4
  38. package/lib/mixins/SessionMixin.js +4 -4
  39. package/lib/mixins/TimeStampedMixin.js +4 -4
  40. package/lib/mixins/UserMixin.js +10 -4
  41. package/lib/mixins/index.js +7 -1
  42. package/lib/models/Model.js +41 -22
  43. package/lib/models/definitions/filters.js +9 -1
  44. package/lib/models/definitions/properties.js +7 -1
  45. package/lib/models/definitions/scopes.js +9 -1
  46. package/lib/models/index.js +7 -1
  47. package/lib/query/QueryBuilder.js +11 -1
  48. package/lib/query/QueryFilters.js +11 -1
  49. package/lib/query/index.js +7 -1
  50. package/lib/schema/formats/index.js +7 -1
  51. package/lib/schema/index.js +10 -2
  52. package/lib/schema/keywords/index.js +7 -1
  53. package/lib/schema/properties.js +11 -1
  54. package/lib/schema/relations.js +18 -4
  55. package/lib/services/index.js +7 -1
  56. package/lib/storage/DiskStorage.js +7 -1
  57. package/lib/storage/Storage.js +5 -1
  58. package/lib/storage/index.js +7 -1
  59. package/lib/utils/emitter.js +5 -1
  60. package/lib/utils/index.js +15 -1
  61. package/lib/utils/json.js +9 -0
  62. package/lib/utils/object.js +9 -3
  63. package/package.json +31 -31
  64. package/src/app/Application.js +40 -11
  65. package/src/app/Validator.js +2 -1
  66. package/src/cli/console.js +3 -3
  67. package/src/cli/db/createMigration.js +3 -3
  68. package/src/cli/db/listAssetConfig.js +3 -1
  69. package/src/cli/db/migrate.js +4 -4
  70. package/src/cli/db/reset.js +4 -4
  71. package/src/cli/db/rollback.js +4 -4
  72. package/src/cli/db/seed.js +6 -6
  73. package/src/cli/db/unlock.js +2 -2
  74. package/src/cli/index.js +3 -3
  75. package/src/controllers/AdminController.js +3 -2
  76. package/src/controllers/Controller.js +8 -8
  77. package/src/controllers/ControllerAction.js +7 -5
  78. package/src/controllers/RelationController.js +2 -2
  79. package/src/decorators/parameters.js +2 -2
  80. package/src/decorators/returns.js +2 -2
  81. package/src/errors/DatabaseError.js +2 -23
  82. package/src/errors/ResponseError.js +1 -8
  83. package/src/middleware/logRequests.js +9 -9
  84. package/src/models/Model.js +13 -8
  85. package/src/utils/index.js +1 -0
  86. package/src/utils/json.js +3 -0
@@ -3,9 +3,13 @@ import { QueryBuilder } from '@/query'
3
3
  import { EventEmitter, KnexHelper } from '@/lib'
4
4
  import { convertSchema, addRelationSchemas, convertRelations } from '@/schema'
5
5
  import { populateGraph, filterGraph } from '@/graph'
6
+ import { formatJson } from '@/utils'
6
7
  import {
7
- ResponseError, DatabaseError, GraphError, ModelError, NotFoundError,
8
- RelationError, WrappedError
8
+ ResponseError,
9
+ GraphError, ModelError,
10
+ NotFoundError,
11
+ RelationError,
12
+ WrappedError
9
13
  } from '@/errors'
10
14
  import {
11
15
  isString, isObject, isArray, isFunction, isPromise, asArray, merge, flatten,
@@ -222,7 +226,7 @@ export class Model extends objection.Model {
222
226
  return super.query(trx).onError(err => {
223
227
  // TODO: Shouldn't this wrapping happen on the Controller level?
224
228
  err = err instanceof ResponseError ? err
225
- : err instanceof objection.DBError ? new DatabaseError(err)
229
+ : err instanceof objection.DBError ? this.app.createDatabaseError(err)
226
230
  : new WrappedError(err)
227
231
  return Promise.reject(err)
228
232
  })
@@ -279,9 +283,9 @@ export class Model extends objection.Model {
279
283
  throw new ModelError(
280
284
  this,
281
285
  `Invalid amount of id values provided for reference: Unable to map ${
282
- JSON.stringify(modelOrId)
286
+ formatJson(modelOrId, false)
283
287
  } to ${
284
- JSON.stringify(idProperties)
288
+ formatJson(idProperties, false)
285
289
  }.`
286
290
  )
287
291
  }
@@ -729,10 +733,11 @@ export class Model extends objection.Model {
729
733
  case 'ModelValidation':
730
734
  return this.app.createValidationError({
731
735
  type,
732
- message: message ||
733
- `The provided data for the ${this.name} model is not valid: ${JSON.stringify(json)}`,
736
+ message:
737
+ message || `The provided data for the ${this.name} model is not valid`,
734
738
  errors,
735
- options
739
+ options,
740
+ json
736
741
  })
737
742
  case 'RelationExpression':
738
743
  case 'UnallowedRelation':
@@ -2,5 +2,6 @@ export * from './decorator'
2
2
  export * from './deprecate'
3
3
  export * from './emitter'
4
4
  export * from './function'
5
+ export * from './json'
5
6
  export * from './object'
6
7
  export * from './scope'
@@ -0,0 +1,3 @@
1
+ export function formatJson(json, indented = true) {
2
+ return JSON.stringify(json, null, indented ? 2 : 0)
3
+ }