@ditojs/server 2.51.1 → 2.52.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 +6 -6
- package/src/app/Application.js +3 -2
- package/src/cli/db/createMigration.js +1 -2
- package/src/cli/db/seed.js +1 -1
- package/src/controllers/AdminController.js +2 -3
- package/src/controllers/ControllerAction.js +5 -11
- package/src/storage/Storage.js +1 -1
- package/src/utils/model.js +35 -0
- package/types/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.52.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.52.0",
|
|
30
|
+
"@ditojs/build": "^2.52.0",
|
|
31
|
+
"@ditojs/router": "^2.52.0",
|
|
32
|
+
"@ditojs/utils": "^2.52.0",
|
|
33
33
|
"@koa/cors": "^5.0.0",
|
|
34
34
|
"@koa/multer": "^3.1.0",
|
|
35
35
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"objection": "^3.1.5",
|
|
91
91
|
"typescript": "^5.8.3"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "dbfde6b475d824a88fbbbc1e007fd264e80d46fb"
|
|
94
94
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -64,6 +64,7 @@ export class Application extends Koa {
|
|
|
64
64
|
#logger
|
|
65
65
|
|
|
66
66
|
constructor({
|
|
67
|
+
basePath = process.cwd(),
|
|
67
68
|
config = {},
|
|
68
69
|
validator,
|
|
69
70
|
router,
|
|
@@ -74,6 +75,7 @@ export class Application extends Koa {
|
|
|
74
75
|
controllers
|
|
75
76
|
} = {}) {
|
|
76
77
|
super()
|
|
78
|
+
this.basePath = basePath
|
|
77
79
|
this._configureEmitter(events)
|
|
78
80
|
const {
|
|
79
81
|
// Pluck keys out of `config.app` to keep them secret
|
|
@@ -430,9 +432,8 @@ export class Application extends Koa {
|
|
|
430
432
|
}
|
|
431
433
|
|
|
432
434
|
async loadAdminViteConfig() {
|
|
433
|
-
const cwd = process.cwd()
|
|
434
435
|
for (const extension of ['js', 'mjs', 'cjs', 'ts']) {
|
|
435
|
-
const file = path.join(
|
|
436
|
+
const file = path.join(this.basePath, `admin.vite.config.${extension}`)
|
|
436
437
|
try {
|
|
437
438
|
await fs.access(file)
|
|
438
439
|
return (await import(file)).default
|
|
@@ -21,9 +21,8 @@ const defaultValues = {
|
|
|
21
21
|
'now()': `knex.raw('CURRENT_TIMESTAMP')`
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const migrationDir = path.join(process.cwd(), 'migrations')
|
|
25
|
-
|
|
26
24
|
export async function createMigration(app, name, ...modelNames) {
|
|
25
|
+
const migrationDir = path.join(app.basePath, 'migrations')
|
|
27
26
|
const models = modelNames.map(modelName => {
|
|
28
27
|
const modelClass = app.models[modelName]
|
|
29
28
|
if (!modelClass) {
|
package/src/cli/db/seed.js
CHANGED
|
@@ -6,7 +6,7 @@ import pluralize from 'pluralize'
|
|
|
6
6
|
import { isFunction, isArray, camelize } from '@ditojs/utils'
|
|
7
7
|
|
|
8
8
|
export async function seed(app) {
|
|
9
|
-
const seedDir = path.join(
|
|
9
|
+
const seedDir = path.join(app.basePath, 'seeds')
|
|
10
10
|
const files = await fs.readdir(seedDir)
|
|
11
11
|
const seeds = []
|
|
12
12
|
// Create a lookup table with sort indices per model name.
|
|
@@ -164,7 +164,6 @@ export class AdminController extends Controller {
|
|
|
164
164
|
defineViteConfig(config = {}) {
|
|
165
165
|
const isDevelopment = this.mode === 'development'
|
|
166
166
|
|
|
167
|
-
const cwd = process.cwd()
|
|
168
167
|
const root = this.getPath('root')
|
|
169
168
|
const base = `${this.url}/`
|
|
170
169
|
const views = path.join(root, 'views')
|
|
@@ -205,10 +204,10 @@ export class AdminController extends Controller {
|
|
|
205
204
|
chunkSizeWarningLimit: 1000,
|
|
206
205
|
rollupOptions: {
|
|
207
206
|
output: {
|
|
208
|
-
manualChunks
|
|
207
|
+
manualChunks: id => {
|
|
209
208
|
if (id.startsWith(views)) {
|
|
210
209
|
return 'views'
|
|
211
|
-
} else if (id.startsWith(
|
|
210
|
+
} else if (id.startsWith(this.app.basePath)) {
|
|
212
211
|
return 'common'
|
|
213
212
|
} else {
|
|
214
213
|
const module = id.match(
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
isObject,
|
|
4
|
-
asArray,
|
|
5
|
-
clone,
|
|
6
|
-
convertToJson,
|
|
7
|
-
deprecate
|
|
8
|
-
} from '@ditojs/utils'
|
|
1
|
+
import { isString, isObject, asArray, clone, deprecate } from '@ditojs/utils'
|
|
2
|
+
import { convertModelsToJson } from '../utils/model.js'
|
|
9
3
|
|
|
10
4
|
export default class ControllerAction {
|
|
11
5
|
constructor(
|
|
@@ -126,11 +120,11 @@ export default class ControllerAction {
|
|
|
126
120
|
await this.controller.emitHook(`before:${identifier}`, false, ctx, ...args)
|
|
127
121
|
const response = await this.callHandler(ctx, ...args)
|
|
128
122
|
const result =
|
|
129
|
-
// Don't convert response to JSON if it isn't being validated
|
|
130
|
-
//
|
|
123
|
+
// Don't convert response to JSON if it isn't being validated, or if the
|
|
124
|
+
// response validation schema contains model references.
|
|
131
125
|
!this.response.validate || this.response.hasModelRefs
|
|
132
126
|
? response
|
|
133
|
-
:
|
|
127
|
+
: convertModelsToJson(response)
|
|
134
128
|
return this.validateResponse(
|
|
135
129
|
await this.controller.emitHook(`after:${identifier}`, true, ctx, result)
|
|
136
130
|
)
|
package/src/storage/Storage.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isPlainObject, isPlainArray } from '@ditojs/utils'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts Models to their external representation by calling the `$toJson()`
|
|
5
|
+
* method. It does not create a JSON string, but a plain object. It is necessary
|
|
6
|
+
* to do this before the validation is performed, otherwise different properties
|
|
7
|
+
* might end up in the Json response. This is done recursively, so that nested
|
|
8
|
+
* models are also converted. Streams, Buffers and other non plain objects are
|
|
9
|
+
* left as-is, so this can directly be used on any results.
|
|
10
|
+
*/
|
|
11
|
+
export function convertModelsToJson(value) {
|
|
12
|
+
return value?.$isObjectionModel
|
|
13
|
+
? value.$toJson()
|
|
14
|
+
: isPlainObject(value)
|
|
15
|
+
? convertToJsonObject(value)
|
|
16
|
+
: isPlainArray(value)
|
|
17
|
+
? convertToJsonArray(value)
|
|
18
|
+
: value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function convertToJsonObject(value) {
|
|
22
|
+
const object = {}
|
|
23
|
+
for (const key of Object.keys(value)) {
|
|
24
|
+
object[key] = convertModelsToJson(value[key])
|
|
25
|
+
}
|
|
26
|
+
return object
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function convertToJsonArray(value) {
|
|
30
|
+
const array = new Array(value.length)
|
|
31
|
+
for (let i = 0, l = value.length; i < l; ++i) {
|
|
32
|
+
array[i] = convertModelsToJson(value[i])
|
|
33
|
+
}
|
|
34
|
+
return array
|
|
35
|
+
}
|
package/types/index.d.ts
CHANGED