@ditojs/server 2.26.1 → 2.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/server",
3
- "version": "2.26.1",
3
+ "version": "2.27.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js Server – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/server",
@@ -22,10 +22,10 @@
22
22
  "node >= 18"
23
23
  ],
24
24
  "dependencies": {
25
- "@ditojs/admin": "^2.26.1",
26
- "@ditojs/build": "^2.26.1",
27
- "@ditojs/router": "^2.26.1",
28
- "@ditojs/utils": "^2.26.1",
25
+ "@ditojs/admin": "^2.27.0",
26
+ "@ditojs/build": "^2.27.0",
27
+ "@ditojs/router": "^2.27.0",
28
+ "@ditojs/utils": "^2.27.0",
29
29
  "@koa/cors": "^5.0.0",
30
30
  "@koa/multer": "^3.0.2",
31
31
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -90,7 +90,7 @@
90
90
  "typescript": "^5.4.5"
91
91
  },
92
92
  "types": "types",
93
- "gitHead": "8f2e07e3774d0e03b24ee78cffe60c5edacb93ae",
93
+ "gitHead": "e80d56a1887faa60f61f4c642502687d50ead333",
94
94
  "scripts": {
95
95
  "types": "tsc --noEmit --esModuleInterop ./types/index.d.ts"
96
96
  },
@@ -25,9 +25,12 @@ export class CollectionController extends Controller {
25
25
  // @override
26
26
  setup() {
27
27
  this.logController()
28
- this.collection = this.setupActions('collection')
29
- this.member = this.isOneToOne ? {} : this.setupActions('member')
30
- this.assets = this.setupAssets()
28
+ this.setProperty('collection', this.setupActions('collection'))
29
+ this.setProperty(
30
+ 'member',
31
+ this.isOneToOne ? {} : this.setupActions('member')
32
+ )
33
+ this.setProperty('assets', this.setupAssets())
31
34
  }
32
35
 
33
36
  // @override
@@ -70,26 +70,22 @@ export class Controller {
70
70
  // If the class name ends in 'Controller', remove it from controller name.
71
71
  this.name ||= this.constructor.name.match(/^(.*?)(?:Controller|)$/)[1]
72
72
  this.path ??= this.app.normalizePath(this.name)
73
- if (!this.url) {
74
- // NOTE: `RelationController.configure()` sets the `url` before calling
75
- // `super.configure()` and has its own handling of logging.
76
- const { path, namespace } = this
77
- // TODO: The distinction between `url` and `path` is a bit tricky, since
78
- // what we call `url` here is called `path` in Router, and may contain
79
- // mapped parameters or wildcards. Consider `path` / `route` instead?
80
- const url = path ? `/${path}` : ''
81
- this.url = namespace ? `/${namespace}${url}` : url
82
- }
73
+ const { path, namespace } = this
74
+ // TODO: The distinction between `url` and `path` is a bit tricky, since
75
+ // what we call `url` here is called `path` in Router, and may contain
76
+ // mapped parameters or wildcards. Consider `path` / `route` instead?
77
+ const url = path ? `/${path}` : ''
78
+ this.url = namespace ? `/${namespace}${url}` : url
83
79
  }
84
80
 
85
81
  // @overridable
86
82
  setup() {
87
83
  this.logController()
88
- this.actions ||= this.reflectActionsObject()
84
+ this.setProperty('actions', this.actions || this.reflectActionsObject())
89
85
  // Now that the instance fields are reflected in the `controller` object
90
86
  // we can use the normal inheritance mechanism through `setupActions()`:
91
- this.actions = this.setupActions('actions')
92
- this.assets = this.setupAssets()
87
+ this.setProperty('actions', this.setupActions('actions'))
88
+ this.setProperty('assets', this.setupAssets())
93
89
  }
94
90
 
95
91
  // @overridable
@@ -119,6 +115,15 @@ export class Controller {
119
115
  )
120
116
  }
121
117
 
118
+ setProperty(key, value) {
119
+ Object.defineProperty(this, key, {
120
+ value,
121
+ writable: false,
122
+ enumerable: true,
123
+ configurable: true
124
+ })
125
+ }
126
+
122
127
  logRoute(str, indent = 0) {
123
128
  if (this.logRoutes) {
124
129
  console.info(`${' '.repeat(indent)}${str}`)
@@ -14,7 +14,7 @@ export class ModelController extends CollectionController {
14
14
 
15
15
  setup() {
16
16
  super.setup()
17
- this.relations = this.setupRelations()
17
+ this.setProperty('relations', this.setupRelations())
18
18
  }
19
19
 
20
20
  setupRelations() {
@@ -1,4 +1,3 @@
1
- import pico from 'picocolors'
2
1
  import { asArray } from '@ditojs/utils'
3
2
  import { CollectionController } from './CollectionController.js'
4
3
  import { ControllerError } from '../errors/index.js'
@@ -32,28 +31,18 @@ export class RelationController extends CollectionController {
32
31
  // relations:
33
32
  this.scope = asArray(parent.scope).filter(scope => getScope(scope).graph)
34
33
  }
35
- // Copy over all fields in the relation object except the ones that are
36
- // going to be inherited in `setup()` (relation, member, allow), for
37
- // settings like scope, etc.
38
- for (const key in this.object) {
39
- if (!['relation', 'member', 'allow'].includes(key)) {
40
- this[key] = this.object[key]
41
- }
34
+ // Copy over all fields in the relation object.
35
+ for (const key in object) {
36
+ // On the relation objects, the `collection` actions are stored in a
37
+ // `relation` object, to make sense both for one- and many-relations:
38
+ this.setProperty(key === 'relation' ? 'collection' : key, object[key])
42
39
  }
43
40
  }
44
41
 
45
42
  // @override
46
43
  configure() {
47
- // Setup the `url` before calling `super.configure()` to override its
48
- // default behavior for `RelationController`:
49
- this.url = `${this.parent.url}/${this.parent.getPath('member', this.path)}`
50
- this.log(`${pico.blue(this.path)}${pico.white(':')}`, this.level)
51
44
  super.configure()
52
- }
53
-
54
- // @override
55
- logController() {
56
- // The parent controller logs itself already, that's enough.
45
+ this.url = `${this.parent.url}/${this.parent.getPath('member', this.path)}`
57
46
  }
58
47
 
59
48
  // @override
@@ -98,7 +87,7 @@ export class RelationController extends CollectionController {
98
87
  })
99
88
  }
100
89
 
101
- collection = this.toCoreActions({})
90
+ collection = this.convertToCoreActions({})
102
91
 
103
- member = this.toCoreActions({})
92
+ member = this.convertToCoreActions({})
104
93
  }