@ditojs/server 1.2.0 → 1.4.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": "1.
|
|
3
|
+
"version": "1.4.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",
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
"dito": "./src/cli/index.js"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">= 16.0.0",
|
|
18
18
|
"yarn": ">= 1.0.0"
|
|
19
19
|
},
|
|
20
20
|
"browserslist": [
|
|
21
|
-
"node >=
|
|
21
|
+
"node >= 16"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@ditojs/admin": "^1.
|
|
25
|
-
"@ditojs/router": "^1.
|
|
26
|
-
"@ditojs/utils": "^1.
|
|
24
|
+
"@ditojs/admin": "^1.4.0",
|
|
25
|
+
"@ditojs/router": "^1.4.0",
|
|
26
|
+
"@ditojs/utils": "^1.4.0",
|
|
27
27
|
"@koa/cors": "^3.2.0",
|
|
28
28
|
"@koa/multer": "^3.0.0",
|
|
29
29
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"koa-session": "^6.2.0",
|
|
54
54
|
"koa-static": "^5.0.0",
|
|
55
55
|
"mime-types": "^2.1.35",
|
|
56
|
-
"minimatch": "^5.0.1",
|
|
57
56
|
"multer": "^1.4.4",
|
|
58
57
|
"multer-s3": "^2.10.0",
|
|
59
58
|
"nanoid": "^3.3.1",
|
|
@@ -82,5 +81,5 @@
|
|
|
82
81
|
"pg": "^8.7.3",
|
|
83
82
|
"sqlite3": "^5.0.2"
|
|
84
83
|
},
|
|
85
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "0b308cb3bd1513d78894c7ccdc0c8716339f55a1"
|
|
86
85
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -171,7 +171,7 @@ export class Application extends Koa {
|
|
|
171
171
|
}
|
|
172
172
|
if (Object.keys(data).length > 0) {
|
|
173
173
|
console.info(
|
|
174
|
-
pico.yellow.bold(`\n${modelClass.name}:\n`),
|
|
174
|
+
pico.yellow(pico.bold(`\n${modelClass.name}:\n`)),
|
|
175
175
|
util.inspect(data, {
|
|
176
176
|
colors: true,
|
|
177
177
|
depth: null,
|
package/src/app/Validator.js
CHANGED
|
@@ -195,12 +195,12 @@ export class Validator extends objection.Validator {
|
|
|
195
195
|
// NOTE: As of Ajv 8, `error.dataPath` is now called `error.instancePath`,
|
|
196
196
|
// but we stick to `error.dataPath` in Dito.js, and support both in errors
|
|
197
197
|
// passed in here.
|
|
198
|
-
const instancePath = error.instancePath
|
|
198
|
+
const instancePath = (error.instancePath ?? error.dataPath) || ''
|
|
199
199
|
const dataPath = `${options?.dataPath || ''}${instancePath}`
|
|
200
200
|
// Unknown properties are reported in `['propertyName']` notation,
|
|
201
201
|
// so replace those with dot-notation, see:
|
|
202
202
|
// https://github.com/epoberezkin/ajv/issues/671
|
|
203
|
-
const key = dataPath.replace(/\['([^']*)'\]/g, '
|
|
203
|
+
const key = dataPath.replace(/\['([^']*)'\]/g, '/$1').slice(1)
|
|
204
204
|
const { message, keyword, params } = error
|
|
205
205
|
const definition = keyword === 'format'
|
|
206
206
|
? this.getFormat(params.format)
|
|
@@ -13,7 +13,7 @@ import { merge } from '@ditojs/utils'
|
|
|
13
13
|
import { Controller } from './Controller.js'
|
|
14
14
|
import { handleConnectMiddleware } from '../middleware/index.js'
|
|
15
15
|
import { ControllerError } from '../errors/index.js'
|
|
16
|
-
import { formatJson } from '../utils/index.js'
|
|
16
|
+
import { formatJson, deprecate } from '../utils/index.js'
|
|
17
17
|
|
|
18
18
|
export class AdminController extends Controller {
|
|
19
19
|
// @override
|
|
@@ -34,11 +34,19 @@ export class AdminController extends Controller {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
getPath(name) {
|
|
37
|
-
const
|
|
37
|
+
const { config } = this
|
|
38
|
+
let str = config[name]
|
|
39
|
+
if (config.build?.path || config.dist?.path) {
|
|
40
|
+
deprecate(`config.admin.build.path and config.admin.dist.path are deprecated. Use config.admin.root and config.admin.dist instead.`)
|
|
41
|
+
|
|
42
|
+
str = name === 'root' ? config.build?.path
|
|
43
|
+
: name === 'dist' ? config.dist?.path
|
|
44
|
+
: null
|
|
45
|
+
}
|
|
38
46
|
if (!str) {
|
|
39
47
|
throw new ControllerError(
|
|
40
48
|
this,
|
|
41
|
-
`Missing admin.${name}
|
|
49
|
+
`Missing \`config.admin.${name}\` configuration.`
|
|
42
50
|
)
|
|
43
51
|
}
|
|
44
52
|
return path.resolve(str)
|
|
@@ -85,8 +93,8 @@ export class AdminController extends Controller {
|
|
|
85
93
|
this.koa = new Koa()
|
|
86
94
|
this.koa.use(this.middleware())
|
|
87
95
|
if (this.mode === 'development') {
|
|
88
|
-
// Calling getPath() throws exception if admin.
|
|
89
|
-
if (this.getPath('
|
|
96
|
+
// Calling getPath() throws exception if config.admin.root is not defined:
|
|
97
|
+
if (this.getPath('root')) {
|
|
90
98
|
this.app.once('after:start', () => this.setupViteServer())
|
|
91
99
|
}
|
|
92
100
|
} else {
|
|
@@ -128,14 +136,14 @@ export class AdminController extends Controller {
|
|
|
128
136
|
const development = this.mode === 'development'
|
|
129
137
|
|
|
130
138
|
const cwd = path.resolve('.')
|
|
131
|
-
const root = this.getPath('
|
|
139
|
+
const root = this.getPath('root')
|
|
132
140
|
const base = `${this.url}/`
|
|
133
141
|
const views = path.join(root, 'views')
|
|
134
142
|
|
|
135
143
|
// Read `package.json` from the closest package.json, so we can emulate
|
|
136
144
|
// ESM-style imports mappings in rollup / vite.
|
|
137
145
|
const pkg = findUpSync('package.json', { cwd: root })
|
|
138
|
-
const { imports } = JSON.parse(fs.readFileSync(pkg, 'utf8'))
|
|
146
|
+
const { imports = {} } = JSON.parse(fs.readFileSync(pkg, 'utf8'))
|
|
139
147
|
|
|
140
148
|
return defineConfig(merge({
|
|
141
149
|
root,
|
|
@@ -209,7 +217,7 @@ export class AdminController extends Controller {
|
|
|
209
217
|
replacement: '#',
|
|
210
218
|
customResolver(id) {
|
|
211
219
|
for (const [find, replacement] of Object.entries(imports)) {
|
|
212
|
-
picomatch.isMatch(id, find, {
|
|
220
|
+
picomatch.isMatch(id, find.replace('*', '**'), {
|
|
213
221
|
capture: true,
|
|
214
222
|
onMatch({ input, regex }) {
|
|
215
223
|
const replacementPath = path.resolve(replacement)
|
|
@@ -120,6 +120,15 @@ export class Controller {
|
|
|
120
120
|
type, actions, name, action, authorize[name]
|
|
121
121
|
)
|
|
122
122
|
}
|
|
123
|
+
// Expose a direct reference to the controller on the action object, but
|
|
124
|
+
// also make it inherit from the controller so that all its public fields
|
|
125
|
+
// and functions (`app`, `query()`, `execute()`, etc.) can be accessed
|
|
126
|
+
// directly through `this` from actions.
|
|
127
|
+
// NOTE: Inheritance is also set up by `inheritValues()` so that from inside
|
|
128
|
+
// the handlers, `super` points to the parent controller's actions object,
|
|
129
|
+
// so that calling `super.patch()` from a patch handler magically works.
|
|
130
|
+
actions.controller = this
|
|
131
|
+
Object.setPrototypeOf(actions, this)
|
|
123
132
|
return actions
|
|
124
133
|
}
|
|
125
134
|
|
|
@@ -139,7 +148,9 @@ export class Controller {
|
|
|
139
148
|
this.setupActionRoute(
|
|
140
149
|
type,
|
|
141
150
|
// eslint-disable-next-line new-cap
|
|
142
|
-
new actionClass(
|
|
151
|
+
new actionClass(
|
|
152
|
+
this, actions, handler, type, name, method, path, authorize
|
|
153
|
+
)
|
|
143
154
|
)
|
|
144
155
|
return handler
|
|
145
156
|
}
|
|
@@ -559,5 +570,5 @@ function isMethodAction(name) {
|
|
|
559
570
|
options: true,
|
|
560
571
|
trace: true,
|
|
561
572
|
connect: true
|
|
562
|
-
}[name]
|
|
573
|
+
}[name] || false
|
|
563
574
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isString, isObject, asArray, clone } from '@ditojs/utils'
|
|
2
2
|
|
|
3
3
|
export default class ControllerAction {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(
|
|
5
|
+
controller, actions, handler, type, name, _method, _path, _authorize
|
|
6
|
+
) {
|
|
5
7
|
const {
|
|
6
8
|
core = false,
|
|
7
9
|
// Allow decorators on actions to override the predetermined defaults for
|
|
@@ -20,6 +22,7 @@ export default class ControllerAction {
|
|
|
20
22
|
} = handler
|
|
21
23
|
|
|
22
24
|
this.controller = controller
|
|
25
|
+
this.actions = actions
|
|
23
26
|
this.handler = handler
|
|
24
27
|
this.type = type
|
|
25
28
|
this.name = name
|
|
@@ -96,7 +99,7 @@ export default class ControllerAction {
|
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
async callHandler(ctx, ...args) {
|
|
99
|
-
return this.handler.call(this.
|
|
102
|
+
return this.handler.call(this.actions, ctx, ...args)
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
createValidationError(options) {
|