@ditojs/server 2.50.0 → 2.51.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.
|
|
3
|
+
"version": "2.51.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",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"node >= 18"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ditojs/admin": "^2.
|
|
30
|
-
"@ditojs/build": "^2.
|
|
31
|
-
"@ditojs/router": "^2.
|
|
32
|
-
"@ditojs/utils": "^2.
|
|
29
|
+
"@ditojs/admin": "^2.51.0",
|
|
30
|
+
"@ditojs/build": "^2.51.0",
|
|
31
|
+
"@ditojs/router": "^2.51.0",
|
|
32
|
+
"@ditojs/utils": "^2.51.0",
|
|
33
33
|
"@koa/cors": "^5.0.0",
|
|
34
34
|
"@koa/multer": "^3.1.0",
|
|
35
35
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"eventemitter2": "^6.4.9",
|
|
42
42
|
"file-type": "^20.5.0",
|
|
43
43
|
"helmet": "^8.1.0",
|
|
44
|
-
"is-stream": "^4.0.1",
|
|
45
44
|
"koa": "^3.0.0",
|
|
46
45
|
"koa-bodyparser": "^4.4.1",
|
|
47
46
|
"koa-compose": "^4.1.0",
|
|
@@ -86,10 +85,10 @@
|
|
|
86
85
|
"@types/koa-session": "^6.4.5",
|
|
87
86
|
"@types/koa-static": "^4.0.4",
|
|
88
87
|
"@types/koa__cors": "^5.0.0",
|
|
89
|
-
"@types/node": "^22.15.
|
|
88
|
+
"@types/node": "^22.15.18",
|
|
90
89
|
"knex": "^3.1.0",
|
|
91
90
|
"objection": "^3.1.5",
|
|
92
91
|
"typescript": "^5.8.3"
|
|
93
92
|
},
|
|
94
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "0b8f114647510db71c50be9fdc331297b1e726ab"
|
|
95
94
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -534,6 +534,15 @@ export class Application extends Koa {
|
|
|
534
534
|
const schema = properties
|
|
535
535
|
? convertSchema({ type: 'object', properties }, options)
|
|
536
536
|
: null
|
|
537
|
+
|
|
538
|
+
// Method to recursively check the compiled JSON schema and its sub-schemas
|
|
539
|
+
// to see if it has any `$ref` references to model schemas:
|
|
540
|
+
const hasModelRefs = schema => (
|
|
541
|
+
!!this.models[schema?.$ref] ||
|
|
542
|
+
(isArray(schema) || isPlainObject(schema)) &&
|
|
543
|
+
Object.values(schema).some(hasModelRefs)
|
|
544
|
+
)
|
|
545
|
+
|
|
537
546
|
const validate = this.compileValidator(schema, {
|
|
538
547
|
// For parameters, always coerce types, including arrays.
|
|
539
548
|
coerceTypes: 'array',
|
|
@@ -552,7 +561,10 @@ export class Application extends Koa {
|
|
|
552
561
|
validate: validate
|
|
553
562
|
? // Use `call()` to pass ctx as context to Ajv, see passContext:
|
|
554
563
|
data => validate.call(ctx, data)
|
|
555
|
-
: null
|
|
564
|
+
: null,
|
|
565
|
+
get hasModelRefs() {
|
|
566
|
+
return hasModelRefs(schema)
|
|
567
|
+
}
|
|
556
568
|
}
|
|
557
569
|
}
|
|
558
570
|
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isString,
|
|
3
|
+
isObject,
|
|
4
|
+
asArray,
|
|
5
|
+
clone,
|
|
6
|
+
convertToJson,
|
|
7
|
+
deprecate
|
|
8
|
+
} from '@ditojs/utils'
|
|
2
9
|
|
|
3
10
|
export default class ControllerAction {
|
|
4
11
|
constructor(
|
|
@@ -118,8 +125,14 @@ export default class ControllerAction {
|
|
|
118
125
|
const { identifier } = this
|
|
119
126
|
await this.controller.emitHook(`before:${identifier}`, false, ctx, ...args)
|
|
120
127
|
const response = await this.callHandler(ctx, ...args)
|
|
128
|
+
const result =
|
|
129
|
+
// Don't convert response to JSON if it isn't being validated (e.g. useful
|
|
130
|
+
// for streams or buffers), or if the response contains model references.
|
|
131
|
+
!this.response.validate || this.response.hasModelRefs
|
|
132
|
+
? response
|
|
133
|
+
: convertToJson(response)
|
|
121
134
|
return this.validateResponse(
|
|
122
|
-
await this.controller.emitHook(`after:${identifier}`, true, ctx,
|
|
135
|
+
await this.controller.emitHook(`after:${identifier}`, true, ctx, result)
|
|
123
136
|
)
|
|
124
137
|
}
|
|
125
138
|
|
|
@@ -147,7 +147,7 @@ describe('convertSchema()', () => {
|
|
|
147
147
|
})
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
-
it(`expands 'object' schemas with properties to JSON schemas allowing no
|
|
150
|
+
it(`expands 'object' schemas with properties to JSON schemas allowing no unevaluated properties`, () => {
|
|
151
151
|
expect(
|
|
152
152
|
convertSchema({
|
|
153
153
|
type: 'object',
|
|
@@ -171,7 +171,7 @@ describe('convertSchema()', () => {
|
|
|
171
171
|
})
|
|
172
172
|
})
|
|
173
173
|
|
|
174
|
-
it('preserves pre-existing settings for no
|
|
174
|
+
it('preserves pre-existing settings for no unevaluated properties', () => {
|
|
175
175
|
expect(
|
|
176
176
|
convertSchema({
|
|
177
177
|
type: 'object',
|
package/src/utils/koa.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { isString } from '@ditojs/utils'
|
|
2
|
-
import { isStream } from 'is-stream'
|
|
3
|
-
|
|
4
|
-
export function isSupportedKoaBody(body) {
|
|
5
|
-
return (
|
|
6
|
-
Buffer.isBuffer(body) ||
|
|
7
|
-
isString(body) ||
|
|
8
|
-
body instanceof Blob ||
|
|
9
|
-
body instanceof Response ||
|
|
10
|
-
isStream(body)
|
|
11
|
-
)
|
|
12
|
-
}
|