@ditojs/server 1.3.0 → 1.4.2
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.2",
|
|
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,22 +14,22 @@
|
|
|
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.2",
|
|
25
|
+
"@ditojs/router": "^1.4.1",
|
|
26
|
+
"@ditojs/utils": "^1.4.1",
|
|
27
27
|
"@koa/cors": "^3.2.0",
|
|
28
28
|
"@koa/multer": "^3.0.0",
|
|
29
29
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
30
|
-
"ajv": "^8.
|
|
30
|
+
"ajv": "^8.11.0",
|
|
31
31
|
"ajv-formats": "^2.1.1",
|
|
32
|
-
"aws-sdk": "^2.
|
|
32
|
+
"aws-sdk": "^2.1098.0",
|
|
33
33
|
"axios": "^0.26.1",
|
|
34
34
|
"bcryptjs": "^2.4.3",
|
|
35
35
|
"bytes": "^3.1.2",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"passthrough-counter": "^1.0.0",
|
|
62
62
|
"picocolors": "^1.0.0",
|
|
63
63
|
"picomatch": "^2.3.1",
|
|
64
|
-
"pino": "^7.9.
|
|
64
|
+
"pino": "^7.9.2",
|
|
65
65
|
"pino-pretty": "^7.5.4",
|
|
66
66
|
"pluralize": "^8.0.0",
|
|
67
67
|
"repl": "^0.1.3",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"pg": "^8.7.3",
|
|
82
82
|
"sqlite3": "^5.0.2"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "1790e50f979322b47a53421e9facddb86f6eff86"
|
|
85
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,
|
|
@@ -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) {
|
|
@@ -216,38 +216,39 @@ export class QueryBuilder extends objection.QueryBuilder {
|
|
|
216
216
|
this._allowScopes = query._allowScopes ? { ...query._allowScopes } : null
|
|
217
217
|
this._ignoreScopes = { ...query._ignoreScopes }
|
|
218
218
|
}
|
|
219
|
-
// If
|
|
219
|
+
// If the target is a child query of a graph query, copy all scopes, graph
|
|
220
220
|
// and non-graph. If it is a child query of a related or eager query,
|
|
221
221
|
// copy only the graph scopes.
|
|
222
222
|
const copyAllScopes =
|
|
223
223
|
isSameModelClass && isChildQuery && query.has(/GraphAndFetch$/)
|
|
224
|
-
|
|
224
|
+
// When copying scopes for child-queries, we also need to take the already
|
|
225
|
+
// applied scopes into account and copy those too.
|
|
226
|
+
const scopes = isChildQuery
|
|
227
|
+
? { ...query._appliedScopes, ...query._scopes }
|
|
228
|
+
: query._scopes
|
|
229
|
+
this._scopes = this._filterScopes(scopes, (scope, graph) =>
|
|
225
230
|
copyAllScopes || graph)
|
|
226
231
|
}
|
|
227
232
|
|
|
228
233
|
_filterScopes(scopes, callback) {
|
|
229
|
-
return Object.entries(scopes).
|
|
230
|
-
(
|
|
231
|
-
|
|
232
|
-
scopes[scope] = graph
|
|
233
|
-
}
|
|
234
|
-
return scopes
|
|
235
|
-
},
|
|
236
|
-
{}
|
|
237
|
-
)
|
|
234
|
+
return Object.fromEntries(Object.entries(scopes).filter(
|
|
235
|
+
([scope, graph]) => callback(scope, graph)
|
|
236
|
+
))
|
|
238
237
|
}
|
|
239
238
|
|
|
240
239
|
_applyScope(scope, graph) {
|
|
241
240
|
if (!this._ignoreScopes[SYMBOL_ALL] && !this._ignoreScopes[scope]) {
|
|
242
241
|
// Prevent multiple application of scopes. This can easily occur
|
|
243
242
|
// with the nesting and eager-application of graph-scopes, see below.
|
|
244
|
-
|
|
243
|
+
// NOTE: The boolean values indicate the `graph` settings, not whether the
|
|
244
|
+
// scopes were applied or not.
|
|
245
|
+
if (!(scope in this._appliedScopes)) {
|
|
245
246
|
// Only apply graph-scopes that are actually defined on the model:
|
|
246
247
|
const func = this.modelClass().getScope(scope)
|
|
247
248
|
if (func) {
|
|
248
249
|
func.call(this, this)
|
|
249
250
|
}
|
|
250
|
-
this._appliedScopes[scope] =
|
|
251
|
+
this._appliedScopes[scope] = graph
|
|
251
252
|
}
|
|
252
253
|
if (graph) {
|
|
253
254
|
// Also bake the scope into any graph expression that may have been
|
|
@@ -255,12 +256,12 @@ export class QueryBuilder extends objection.QueryBuilder {
|
|
|
255
256
|
const expr = this.graphExpressionObject()
|
|
256
257
|
if (expr) {
|
|
257
258
|
// Add a new modifier to the existing graph expression that
|
|
258
|
-
// recursively
|
|
259
|
-
//
|
|
260
|
-
//
|
|
259
|
+
// recursively adds the graph-scope to the resulting queries. This
|
|
260
|
+
// even works if nested scopes expand the graph expression, because it
|
|
261
|
+
// re-applies itself to the result.
|
|
261
262
|
const name = `^${scope}`
|
|
262
263
|
const modifiers = {
|
|
263
|
-
[name]: query => query.
|
|
264
|
+
[name]: query => query.withScope(name)
|
|
264
265
|
}
|
|
265
266
|
this.withGraph(
|
|
266
267
|
addGraphScope(this.modelClass(), expr, [name], modifiers, true)
|