@ditojs/server 1.8.1 → 1.10.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 +20 -20
- package/src/controllers/AdminController.js +7 -2
- package/src/mixins/AssetMixin.js +1 -2
- package/src/models/Model.js +1 -13
- package/src/storage/S3Storage.js +11 -10
- package/src/utils/index.js +1 -0
- package/src/utils/net.js +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.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",
|
|
@@ -21,24 +21,24 @@
|
|
|
21
21
|
"node >= 16"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@ditojs/
|
|
26
|
-
"@ditojs/
|
|
27
|
-
"@ditojs/
|
|
24
|
+
"@aws-sdk/client-s3": "^3.135.0",
|
|
25
|
+
"@ditojs/admin": "^1.10.0",
|
|
26
|
+
"@ditojs/build": "^1.10.0",
|
|
27
|
+
"@ditojs/router": "^1.10.0",
|
|
28
|
+
"@ditojs/utils": "^1.10.0",
|
|
28
29
|
"@koa/cors": "^3.3.0",
|
|
29
30
|
"@koa/multer": "^3.0.0",
|
|
30
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
31
32
|
"ajv": "^8.11.0",
|
|
32
33
|
"ajv-formats": "^2.1.1",
|
|
33
|
-
"aws-sdk": "^2.1141.0",
|
|
34
34
|
"axios": "^0.27.2",
|
|
35
35
|
"bcryptjs": "^2.4.3",
|
|
36
36
|
"bytes": "^3.1.2",
|
|
37
37
|
"data-uri-to-buffer": "^4.0.0",
|
|
38
|
-
"eventemitter2": "^6.4.
|
|
39
|
-
"file-type": "^17.1.
|
|
38
|
+
"eventemitter2": "^6.4.6",
|
|
39
|
+
"file-type": "^17.1.3",
|
|
40
40
|
"fs-extra": "^10.1.0",
|
|
41
|
-
"image-size": "^1.0.
|
|
41
|
+
"image-size": "^1.0.2",
|
|
42
42
|
"is-svg": "^4.3.2",
|
|
43
43
|
"koa": "^2.13.4",
|
|
44
44
|
"koa-bodyparser": "^4.3.0",
|
|
@@ -53,31 +53,31 @@
|
|
|
53
53
|
"koa-session": "^6.2.0",
|
|
54
54
|
"koa-static": "^5.0.0",
|
|
55
55
|
"mime-types": "^2.1.35",
|
|
56
|
-
"multer": "^1.4.
|
|
57
|
-
"multer-s3": "^
|
|
58
|
-
"nanoid": "^
|
|
56
|
+
"multer": "^1.4.5-lts.1",
|
|
57
|
+
"multer-s3": "^3.0.1",
|
|
58
|
+
"nanoid": "^4.0.0",
|
|
59
59
|
"parse-duration": "^1.0.2",
|
|
60
60
|
"passport-local": "^1.0.0",
|
|
61
61
|
"passthrough-counter": "^1.0.0",
|
|
62
62
|
"picocolors": "^1.0.0",
|
|
63
63
|
"picomatch": "^2.3.1",
|
|
64
|
-
"pino": "^
|
|
65
|
-
"pino-pretty": "^
|
|
64
|
+
"pino": "^8.3.0",
|
|
65
|
+
"pino-pretty": "^8.1.0",
|
|
66
66
|
"pluralize": "^8.0.0",
|
|
67
67
|
"repl": "^0.1.3",
|
|
68
68
|
"uuid": "^8.3.2",
|
|
69
|
-
"vite": "^
|
|
70
|
-
"vite-plugin-vue2": "^2.0.
|
|
71
|
-
"vue": "^2.
|
|
72
|
-
"vue-template-compiler": "^2.
|
|
69
|
+
"vite": "^3.0.2",
|
|
70
|
+
"vite-plugin-vue2": "^2.0.2",
|
|
71
|
+
"vue": "^2.7.8",
|
|
72
|
+
"vue-template-compiler": "^2.7.8"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"knex": "^1.0.5",
|
|
76
76
|
"objection": "^3.0.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"knex": "^2.
|
|
79
|
+
"knex": "^2.2.0",
|
|
80
80
|
"objection": "^3.0.1"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "0b044d649e0fe1bcbcd3603bcdc9c6168058fb6d"
|
|
83
83
|
}
|
|
@@ -15,7 +15,7 @@ import { merge } from '@ditojs/utils'
|
|
|
15
15
|
import { Controller } from './Controller.js'
|
|
16
16
|
import { handleConnectMiddleware } from '../middleware/index.js'
|
|
17
17
|
import { ControllerError } from '../errors/index.js'
|
|
18
|
-
import { formatJson, deprecate } from '../utils/index.js'
|
|
18
|
+
import { formatJson, getRandomFreePort, deprecate } from '../utils/index.js'
|
|
19
19
|
|
|
20
20
|
export class AdminController extends Controller {
|
|
21
21
|
// @override
|
|
@@ -130,7 +130,12 @@ export class AdminController extends Controller {
|
|
|
130
130
|
const server = await createServer({
|
|
131
131
|
...config,
|
|
132
132
|
server: {
|
|
133
|
-
middlewareMode:
|
|
133
|
+
middlewareMode: true,
|
|
134
|
+
hmr: {
|
|
135
|
+
// Use a random free port instead of vite's default 24678, since we
|
|
136
|
+
// may be running multiple servers in parallel (e.g. e2e and dev).
|
|
137
|
+
port: await getRandomFreePort()
|
|
138
|
+
},
|
|
134
139
|
watch: {
|
|
135
140
|
// Watch the @ditojs packages while in dev mode, although they are
|
|
136
141
|
// inside the node_modules folder.
|
package/src/mixins/AssetMixin.js
CHANGED
|
@@ -64,11 +64,10 @@ export const AssetMixin = mixin(Model => class extends TimeStampedMixin(Model) {
|
|
|
64
64
|
|
|
65
65
|
// @override
|
|
66
66
|
$parseJson(json) {
|
|
67
|
-
const { constructor } = this
|
|
68
67
|
const { file, storage } = json
|
|
69
68
|
// Convert `AssetMixin#file` to an `AssetFile` instance:
|
|
70
69
|
if (file && storage) {
|
|
71
|
-
constructor.app.getStorage(storage)?.convertAssetFile(file)
|
|
70
|
+
this.constructor.app.getStorage(storage)?.convertAssetFile(file)
|
|
72
71
|
}
|
|
73
72
|
return json
|
|
74
73
|
}
|
package/src/models/Model.js
CHANGED
|
@@ -579,20 +579,8 @@ export class Model extends objection.Model {
|
|
|
579
579
|
|
|
580
580
|
// @override
|
|
581
581
|
$formatJson(json) {
|
|
582
|
-
const { constructor } = this
|
|
583
|
-
// Calculate and set the computed properties.
|
|
584
|
-
for (const key of constructor.computedAttributes) {
|
|
585
|
-
// Perhaps the computed property is produced in the SQL statement,
|
|
586
|
-
// in which case we don't have to do anything anymore here.
|
|
587
|
-
if (!(key in json)) {
|
|
588
|
-
const value = this[key]
|
|
589
|
-
if (value !== undefined) {
|
|
590
|
-
json[key] = value
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
582
|
// Remove hidden attributes.
|
|
595
|
-
for (const key of constructor.hiddenAttributes) {
|
|
583
|
+
for (const key of this.constructor.hiddenAttributes) {
|
|
596
584
|
delete json[key]
|
|
597
585
|
}
|
|
598
586
|
return json
|
package/src/storage/S3Storage.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { S3 } from '@aws-sdk/client-s3'
|
|
2
2
|
import multerS3 from 'multer-s3'
|
|
3
3
|
import { fileTypeFromBuffer } from 'file-type'
|
|
4
4
|
import isSvg from 'is-svg'
|
|
5
5
|
import { Storage } from './Storage.js'
|
|
6
6
|
import { PassThrough } from 'stream'
|
|
7
|
+
import consumers from 'stream/consumers'
|
|
7
8
|
|
|
8
9
|
export class S3Storage extends Storage {
|
|
9
10
|
static type = 's3'
|
|
@@ -17,7 +18,7 @@ export class S3Storage extends Storage {
|
|
|
17
18
|
bucket,
|
|
18
19
|
...options
|
|
19
20
|
} = config
|
|
20
|
-
this.s3 = new
|
|
21
|
+
this.s3 = new S3(s3)
|
|
21
22
|
this.acl = acl
|
|
22
23
|
this.bucket = bucket
|
|
23
24
|
|
|
@@ -101,13 +102,13 @@ export class S3Storage extends Storage {
|
|
|
101
102
|
|
|
102
103
|
// @override
|
|
103
104
|
async _addFile(file, buffer) {
|
|
104
|
-
const data = await this.s3.
|
|
105
|
+
const data = await this.s3.putObject({
|
|
105
106
|
Bucket: this.bucket,
|
|
106
107
|
ACL: this.acl,
|
|
107
108
|
Key: file.key,
|
|
108
109
|
ContentType: file.type,
|
|
109
110
|
Body: buffer
|
|
110
|
-
})
|
|
111
|
+
})
|
|
111
112
|
// "Convert" `file` to something looking more like a S3 `storageFile`.
|
|
112
113
|
// For now, only the `location` property is of interest:
|
|
113
114
|
return {
|
|
@@ -121,7 +122,7 @@ export class S3Storage extends Storage {
|
|
|
121
122
|
await this.s3.deleteObject({
|
|
122
123
|
Bucket: this.bucket,
|
|
123
124
|
Key: file.key
|
|
124
|
-
})
|
|
125
|
+
})
|
|
125
126
|
// TODO: Check for errors and throw?
|
|
126
127
|
}
|
|
127
128
|
|
|
@@ -129,12 +130,12 @@ export class S3Storage extends Storage {
|
|
|
129
130
|
async _readFile(file) {
|
|
130
131
|
const {
|
|
131
132
|
ContentType: type,
|
|
132
|
-
Body:
|
|
133
|
+
Body: stream
|
|
133
134
|
} = await this.s3.getObject({
|
|
134
135
|
Bucket: this.bucket,
|
|
135
136
|
Key: file.key
|
|
136
|
-
})
|
|
137
|
-
const buffer =
|
|
137
|
+
})
|
|
138
|
+
const buffer = await consumers.buffer(stream)
|
|
138
139
|
// See `AssetFile.data` setter:
|
|
139
140
|
buffer.type = type
|
|
140
141
|
return buffer
|
|
@@ -146,8 +147,8 @@ export class S3Storage extends Storage {
|
|
|
146
147
|
const params = { Bucket: this.bucket }
|
|
147
148
|
let result
|
|
148
149
|
do {
|
|
149
|
-
result = await this.s3.listObjectsV2(params)
|
|
150
|
-
for (const { Key: key } of result.Contents) {
|
|
150
|
+
result = await this.s3.listObjectsV2(params)
|
|
151
|
+
for (const { Key: key } of result.Contents ?? []) {
|
|
151
152
|
files.push(key)
|
|
152
153
|
}
|
|
153
154
|
// Continue it if results are truncated.
|
package/src/utils/index.js
CHANGED
package/src/utils/net.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import net from 'net'
|
|
2
|
+
|
|
3
|
+
export async function getRandomFreePort() {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const srv = net.createServer()
|
|
6
|
+
srv.listen(0, () => {
|
|
7
|
+
const port = srv.address().port
|
|
8
|
+
srv.close(err => {
|
|
9
|
+
if (err) {
|
|
10
|
+
reject(err)
|
|
11
|
+
} else {
|
|
12
|
+
resolve(port)
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
}
|