@ditojs/server 2.0.5 → 2.1.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 (53) hide show
  1. package/package.json +11 -13
  2. package/src/app/Application.js +226 -179
  3. package/src/app/Validator.js +53 -43
  4. package/src/cli/console.js +6 -4
  5. package/src/cli/db/createMigration.js +59 -30
  6. package/src/cli/db/migrate.js +6 -4
  7. package/src/cli/db/reset.js +8 -5
  8. package/src/cli/db/rollback.js +6 -4
  9. package/src/cli/db/seed.js +2 -1
  10. package/src/cli/index.js +1 -1
  11. package/src/controllers/AdminController.js +98 -84
  12. package/src/controllers/CollectionController.js +37 -30
  13. package/src/controllers/Controller.js +83 -43
  14. package/src/controllers/ControllerAction.js +27 -15
  15. package/src/controllers/ModelController.js +4 -1
  16. package/src/controllers/RelationController.js +19 -21
  17. package/src/controllers/UsersController.js +3 -4
  18. package/src/decorators/parameters.js +3 -1
  19. package/src/decorators/scope.js +1 -1
  20. package/src/errors/ControllerError.js +2 -1
  21. package/src/errors/DatabaseError.js +20 -11
  22. package/src/graph/DitoGraphProcessor.js +48 -40
  23. package/src/graph/expression.js +6 -8
  24. package/src/graph/graph.js +20 -11
  25. package/src/lib/EventEmitter.js +12 -12
  26. package/src/middleware/handleConnectMiddleware.js +16 -10
  27. package/src/middleware/handleError.js +6 -5
  28. package/src/middleware/handleSession.js +33 -29
  29. package/src/middleware/handleUser.js +2 -2
  30. package/src/middleware/index.js +1 -0
  31. package/src/middleware/logRequests.js +3 -3
  32. package/src/middleware/setupRequestStorage.js +14 -0
  33. package/src/mixins/AssetMixin.js +62 -58
  34. package/src/mixins/SessionMixin.js +13 -10
  35. package/src/mixins/TimeStampedMixin.js +33 -29
  36. package/src/mixins/UserMixin.js +130 -116
  37. package/src/models/Model.js +245 -194
  38. package/src/models/definitions/filters.js +14 -13
  39. package/src/query/QueryBuilder.js +252 -195
  40. package/src/query/QueryFilters.js +3 -3
  41. package/src/query/QueryParameters.js +2 -2
  42. package/src/query/Registry.js +8 -10
  43. package/src/schema/keywords/_validate.js +10 -8
  44. package/src/schema/properties.test.js +247 -206
  45. package/src/schema/relations.js +42 -20
  46. package/src/schema/relations.test.js +36 -19
  47. package/src/services/Service.js +8 -14
  48. package/src/storage/S3Storage.js +5 -3
  49. package/src/storage/Storage.js +16 -14
  50. package/src/utils/function.js +7 -4
  51. package/src/utils/function.test.js +30 -6
  52. package/src/utils/object.test.js +5 -1
  53. package/types/index.d.ts +244 -257
@@ -30,8 +30,8 @@ QueryFilters.register({
30
30
  query.where(property, 'ILIKE', operand)
31
31
  } else {
32
32
  query.whereRaw(
33
- `LOWER(??) LIKE ?`,
34
- [property, operand.toLowerCase()]
33
+ `LOWER(??) LIKE ?`,
34
+ [property, operand.toLowerCase()]
35
35
  )
36
36
  }
37
37
  }
@@ -59,7 +59,7 @@ QueryFilters.register({
59
59
  } else if (to) {
60
60
  query.where(property, '<=', new Date(to))
61
61
  } else {
62
- // TODO: Can we get validation to catch the case where both are empty?
62
+ // TODO: Can we get validation to catch the case where both are empty?
63
63
  }
64
64
  }
65
65
  }
@@ -22,8 +22,8 @@ QueryParameters.register({
22
22
  throw error instanceof ResponseError
23
23
  ? error
24
24
  : new QueryBuilderError(
25
- `Invalid Query filter parameters: ${error.message}.`
26
- )
25
+ `Invalid Query filter parameters: ${error.message}.`
26
+ )
27
27
  }
28
28
  },
29
29
 
@@ -1,17 +1,15 @@
1
1
  import { isObject } from '@ditojs/utils'
2
2
 
3
3
  export default class Registry {
4
- constructor() {
5
- this._registry = Object.create(null)
6
- this._allowed = Object.create(null)
7
- }
4
+ #registry = Object.create(null)
5
+ #allowed = Object.create(null)
8
6
 
9
7
  get(name) {
10
- return this._registry[name]
8
+ return this.#registry[name]
11
9
  }
12
10
 
13
11
  has(name) {
14
- return name in this._registry
12
+ return name in this.#registry
15
13
  }
16
14
 
17
15
  register(name, handler) {
@@ -20,12 +18,12 @@ export default class Registry {
20
18
  this.register(key, name[key])
21
19
  }
22
20
  } else {
23
- this._registry[name] = handler
24
- this._allowed[name] = true
21
+ this.#registry[name] = handler
22
+ this.#allowed[name] = true
25
23
  }
26
24
  }
27
25
 
28
- allowed() {
29
- return this._allowed
26
+ getAllowed() {
27
+ return this.#allowed
30
28
  }
31
29
  }
@@ -58,14 +58,16 @@ function getParams(ctx, data, parentSchema, dataCtx) {
58
58
 
59
59
  function getErrors(error, { validator, instancePath }) {
60
60
  const errors = isArray(error.errors)
61
- // Ajv errors array:
62
- ? error.errors
63
- // Convert string error message to errors array:
64
- : [{
65
- keyword: 'validate',
66
- message: error.message || error.toString(),
67
- params: {}
68
- }]
61
+ ? // Ajv errors array:
62
+ error.errors
63
+ : // Convert string error message to errors array:
64
+ [
65
+ {
66
+ keyword: 'validate',
67
+ message: error.message || error.toString(),
68
+ params: {}
69
+ }
70
+ ]
69
71
  // Return errors prefixed with the current instancePath:
70
72
  return validator.prefixInstancePaths(errors, instancePath)
71
73
  }