@ditojs/server 2.47.0 → 2.48.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 +7 -7
- package/src/app/Application.js +1 -7
- package/src/cli/console.js +1 -1
- package/src/controllers/CollectionController.js +2 -14
- package/src/controllers/Controller.js +30 -44
- package/src/controllers/ControllerAction.js +5 -9
- package/src/controllers/RelationController.js +2 -2
- package/src/index.js +0 -1
- package/src/middleware/handleSession.js +0 -1
- package/src/query/QueryBuilder.js +1 -15
- package/src/services/Service.js +0 -5
- package/src/storage/S3Storage.js +1 -1
- package/src/storage/Storage.js +2 -12
- package/src/utils/duration.js +0 -1
- package/types/index.d.ts +0 -2
- package/src/decorators/action.js +0 -8
- package/src/decorators/authorize.js +0 -7
- package/src/decorators/index.js +0 -6
- package/src/decorators/parameters.js +0 -20
- package/src/decorators/returns.js +0 -23
- package/src/decorators/scope.js +0 -8
- package/src/decorators/transacted.js +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.48.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",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"node >= 18"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ditojs/admin": "^2.
|
|
29
|
-
"@ditojs/build": "^2.
|
|
30
|
-
"@ditojs/router": "^2.
|
|
31
|
-
"@ditojs/utils": "^2.
|
|
28
|
+
"@ditojs/admin": "^2.48.0",
|
|
29
|
+
"@ditojs/build": "^2.48.0",
|
|
30
|
+
"@ditojs/router": "^2.48.0",
|
|
31
|
+
"@ditojs/utils": "^2.48.0",
|
|
32
32
|
"@koa/cors": "^5.0.0",
|
|
33
33
|
"@koa/multer": "^3.1.0",
|
|
34
34
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
35
35
|
"ajv": "^8.17.1",
|
|
36
|
-
"ajv-formats": "^
|
|
36
|
+
"ajv-formats": "^3.0.1",
|
|
37
37
|
"bcryptjs": "^3.0.2",
|
|
38
38
|
"bytes": "^3.1.2",
|
|
39
39
|
"data-uri-to-buffer": "^6.0.2",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"typescript": "^5.8.3"
|
|
91
91
|
},
|
|
92
92
|
"types": "types",
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "bacff1f9a6b314fad4f01b4a83d5cf4778d344e1"
|
|
94
94
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -31,8 +31,7 @@ import {
|
|
|
31
31
|
parseDataPath,
|
|
32
32
|
normalizeDataPath,
|
|
33
33
|
toPromiseCallback,
|
|
34
|
-
mapConcurrently
|
|
35
|
-
deprecate
|
|
34
|
+
mapConcurrently
|
|
36
35
|
} from '@ditojs/utils'
|
|
37
36
|
import { Validator } from './Validator.js'
|
|
38
37
|
import { EventEmitter } from '../lib/index.js'
|
|
@@ -879,11 +878,6 @@ export class Application extends Koa {
|
|
|
879
878
|
}
|
|
880
879
|
}
|
|
881
880
|
|
|
882
|
-
startOrExit() {
|
|
883
|
-
deprecate(`app.startOrExit() is deprecated. Use app.execute() instead.`)
|
|
884
|
-
return this.execute()
|
|
885
|
-
}
|
|
886
|
-
|
|
887
881
|
// Assets handling
|
|
888
882
|
|
|
889
883
|
async createAssets(storage, files, count = 0, transaction = null) {
|
package/src/cli/console.js
CHANGED
|
@@ -59,7 +59,7 @@ export default async function startConsole(app, config) {
|
|
|
59
59
|
.slice(0, config.historySize)
|
|
60
60
|
.filter(line => line.trim())
|
|
61
61
|
.map(line => server.history.push(line))
|
|
62
|
-
} catch
|
|
62
|
+
} catch {
|
|
63
63
|
console.info(deindent`
|
|
64
64
|
Unable to REPL history file at ${historyFile}.
|
|
65
65
|
A history file will be created on shutdown
|
|
@@ -182,19 +182,7 @@ export class CollectionController extends Controller {
|
|
|
182
182
|
)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
// Mark action object and methods as core, so `Controller.processValues()`
|
|
187
|
-
// can filter correctly.
|
|
188
|
-
for (const action of Object.values(actions)) {
|
|
189
|
-
// Mark action functions also, so ControllerAction can use it to determine
|
|
190
|
-
// value for `transacted`.
|
|
191
|
-
action.core = true
|
|
192
|
-
}
|
|
193
|
-
actions.$core = true
|
|
194
|
-
return actions
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
collection = this.convertToCoreActions({
|
|
185
|
+
collection = this.markAsCoreActions({
|
|
198
186
|
async get(ctx, modify) {
|
|
199
187
|
const result = await this.execute(ctx, (query, trx) => {
|
|
200
188
|
query
|
|
@@ -245,7 +233,7 @@ export class CollectionController extends Controller {
|
|
|
245
233
|
}
|
|
246
234
|
})
|
|
247
235
|
|
|
248
|
-
member = this.
|
|
236
|
+
member = this.markAsCoreActions({
|
|
249
237
|
async get(ctx, modify) {
|
|
250
238
|
return this.execute(ctx, (query, trx) =>
|
|
251
239
|
query
|
|
@@ -32,8 +32,8 @@ export class Controller {
|
|
|
32
32
|
name = null
|
|
33
33
|
path = null
|
|
34
34
|
url = null
|
|
35
|
-
actions = null
|
|
36
35
|
assets = null
|
|
36
|
+
actions = null
|
|
37
37
|
transacted = null
|
|
38
38
|
initialized = false
|
|
39
39
|
|
|
@@ -80,7 +80,6 @@ export class Controller {
|
|
|
80
80
|
// @overridable
|
|
81
81
|
setup() {
|
|
82
82
|
this.logController()
|
|
83
|
-
this.setProperty('actions', this.actions || this.reflectActionsObject())
|
|
84
83
|
// Now that the instance fields are reflected in the `controller` object
|
|
85
84
|
// we can use the normal inheritance mechanism through `setupActions()`:
|
|
86
85
|
this.setProperty('actions', this.setupActions('actions'))
|
|
@@ -142,30 +141,15 @@ export class Controller {
|
|
|
142
141
|
return value
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const actions = allow ? { allow } : {}
|
|
153
|
-
|
|
154
|
-
const addAction = key => {
|
|
155
|
-
const value = this[key]
|
|
156
|
-
// NOTE: Only add instance methods that have a @action() decorator, which
|
|
157
|
-
// in turn sets the `method` property on the method, as well as action
|
|
158
|
-
// objects which provide the `method` property:
|
|
159
|
-
if (value?.method) {
|
|
160
|
-
actions[key] = value
|
|
161
|
-
}
|
|
144
|
+
markAsCoreActions(actions) {
|
|
145
|
+
// Mark action object and methods as core, so `Controller.processValues()`
|
|
146
|
+
// can filter correctly.
|
|
147
|
+
for (const action of Object.values(actions)) {
|
|
148
|
+
// Mark action functions also, so ControllerAction can use it to determine
|
|
149
|
+
// value for `transacted`.
|
|
150
|
+
action.core = true
|
|
162
151
|
}
|
|
163
|
-
|
|
164
|
-
// not also receive values from parents (those are fetched later in
|
|
165
|
-
// `inheritValues()`, see `getParentValues()`).
|
|
166
|
-
const proto = Object.getPrototypeOf(this)
|
|
167
|
-
Object.getOwnPropertyNames(proto).forEach(addAction)
|
|
168
|
-
Object.getOwnPropertyNames(this).forEach(addAction)
|
|
152
|
+
actions.$core = true
|
|
169
153
|
return actions
|
|
170
154
|
}
|
|
171
155
|
|
|
@@ -190,26 +174,28 @@ export class Controller {
|
|
|
190
174
|
values: actions,
|
|
191
175
|
authorize
|
|
192
176
|
} = this.processValues(this.inheritValues(type))
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
177
|
+
if (actions) {
|
|
178
|
+
for (const [name, action] of Object.entries(actions)) {
|
|
179
|
+
// Replace the action object with the converted action handler, so they
|
|
180
|
+
// too can benefit from prototypal inheritance:
|
|
181
|
+
actions[name] = this.setupAction(
|
|
182
|
+
type,
|
|
183
|
+
actions,
|
|
184
|
+
name,
|
|
185
|
+
action,
|
|
186
|
+
authorize[name]
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
// Expose a direct reference to the controller on the action object, but
|
|
190
|
+
// also make it inherit from the controller so that all its public fields
|
|
191
|
+
// and functions (`app`, `query()`, `execute()`, etc.) can be accessed
|
|
192
|
+
// directly through `this` from actions.
|
|
193
|
+
// NOTE: Inheritance is also set up by `inheritValues()` so that from the
|
|
194
|
+
// handlers, `super` points to the parent controller's actions object, so
|
|
195
|
+
// that calling `super.patch()` from a patch handler magically works.
|
|
196
|
+
actions.controller = this
|
|
197
|
+
Object.setPrototypeOf(actions, this)
|
|
203
198
|
}
|
|
204
|
-
// Expose a direct reference to the controller on the action object, but
|
|
205
|
-
// also make it inherit from the controller so that all its public fields
|
|
206
|
-
// and functions (`app`, `query()`, `execute()`, etc.) can be accessed
|
|
207
|
-
// directly through `this` from actions.
|
|
208
|
-
// NOTE: Inheritance is also set up by `inheritValues()` so that from inside
|
|
209
|
-
// the handlers, `super` points to the parent controller's actions object,
|
|
210
|
-
// so that calling `super.patch()` from a patch handler magically works.
|
|
211
|
-
actions.controller = this
|
|
212
|
-
Object.setPrototypeOf(actions, this)
|
|
213
199
|
return actions
|
|
214
200
|
}
|
|
215
201
|
|
|
@@ -7,18 +7,12 @@ export default class ControllerAction {
|
|
|
7
7
|
handler,
|
|
8
8
|
type,
|
|
9
9
|
name,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
method,
|
|
11
|
+
path,
|
|
12
12
|
_authorize
|
|
13
13
|
) {
|
|
14
14
|
const {
|
|
15
15
|
core = false,
|
|
16
|
-
// Allow decorators on actions to override the predetermined defaults for
|
|
17
|
-
// `method`, `path` and `authorize`:
|
|
18
|
-
// TODO: `handler.method` and `handler.path` were deprecated in March
|
|
19
|
-
// 2022, remove later and only set the valued passed to constructor then.
|
|
20
|
-
method = _method,
|
|
21
|
-
path = _path,
|
|
22
16
|
scope,
|
|
23
17
|
authorize,
|
|
24
18
|
transacted,
|
|
@@ -28,6 +22,7 @@ export default class ControllerAction {
|
|
|
28
22
|
...additional
|
|
29
23
|
} = handler
|
|
30
24
|
|
|
25
|
+
this.app = controller.app
|
|
31
26
|
this.controller = controller
|
|
32
27
|
this.actions = actions
|
|
33
28
|
this.handler = handler
|
|
@@ -37,6 +32,8 @@ export default class ControllerAction {
|
|
|
37
32
|
this.method = method
|
|
38
33
|
this.path = path
|
|
39
34
|
this.scope = scope
|
|
35
|
+
// Allow action handlers to override the predetermined defaults for
|
|
36
|
+
// `authorize`:
|
|
40
37
|
this.authorize = authorize || _authorize
|
|
41
38
|
this.transacted = !!(
|
|
42
39
|
transacted ??
|
|
@@ -52,7 +49,6 @@ export default class ControllerAction {
|
|
|
52
49
|
)
|
|
53
50
|
)
|
|
54
51
|
this.authorization = controller.processAuthorize(this.authorize)
|
|
55
|
-
this.app = controller.app
|
|
56
52
|
this.paramsName = ['post', 'put', 'patch'].includes(this.method)
|
|
57
53
|
? 'body'
|
|
58
54
|
: 'query'
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,6 @@ export function handleSession(app, {
|
|
|
11
11
|
// Create a ContextStore that resolved the specified model class,
|
|
12
12
|
// uses it to persist and retrieve the session, and automatically
|
|
13
13
|
// binds all db operations to `ctx.transaction`, if it is set.
|
|
14
|
-
// eslint-disable-next-line new-cap
|
|
15
14
|
options.ContextStore = createSessionStore(modelClass)
|
|
16
15
|
}
|
|
17
16
|
options.autoCommit = false
|
|
@@ -1065,19 +1065,5 @@ const mixinMethods = [
|
|
|
1065
1065
|
'havingBetween',
|
|
1066
1066
|
'havingNotBetween',
|
|
1067
1067
|
'havingRaw',
|
|
1068
|
-
'havingWrapped'
|
|
1069
|
-
|
|
1070
|
-
// deprecated methods that are still supported at the moment.
|
|
1071
|
-
// TODO: Remove once we move to Objection 3.0
|
|
1072
|
-
'eager',
|
|
1073
|
-
'joinEager',
|
|
1074
|
-
'naiveEager',
|
|
1075
|
-
'mergeEager',
|
|
1076
|
-
'mergeJoinEager',
|
|
1077
|
-
'mergeNaiveEager',
|
|
1078
|
-
'clearEager',
|
|
1079
|
-
|
|
1080
|
-
'scope',
|
|
1081
|
-
'mergeScope',
|
|
1082
|
-
'clearScope'
|
|
1068
|
+
'havingWrapped'
|
|
1083
1069
|
]
|
package/src/services/Service.js
CHANGED
|
@@ -28,11 +28,6 @@ export class Service {
|
|
|
28
28
|
// @overridable
|
|
29
29
|
async stop() {}
|
|
30
30
|
|
|
31
|
-
/** @deprecated Use `instance.logger` instead. */
|
|
32
|
-
getLogger() {
|
|
33
|
-
return this.logger
|
|
34
|
-
}
|
|
35
|
-
|
|
36
31
|
get logger() {
|
|
37
32
|
const logger = this.app.requestLocals.logger ?? this.app.logger
|
|
38
33
|
return logger.child({ name: this.#loggerName })
|
package/src/storage/S3Storage.js
CHANGED
|
@@ -164,6 +164,6 @@ function getFileTypeFromBuffer(buffer) {
|
|
|
164
164
|
try {
|
|
165
165
|
// Use leather as fall-back for better media file mime type detection.
|
|
166
166
|
return fileTypeFromBuffer(buffer)?.mime || readMediaAttributes(buffer)?.mime
|
|
167
|
-
} catch
|
|
167
|
+
} catch {}
|
|
168
168
|
return null
|
|
169
169
|
}
|
package/src/storage/Storage.js
CHANGED
|
@@ -4,7 +4,7 @@ import multer from '@koa/multer'
|
|
|
4
4
|
import picomatch from 'picomatch'
|
|
5
5
|
import { PassThrough } from 'stream'
|
|
6
6
|
import { readMediaAttributes } from 'leather'
|
|
7
|
-
import { hyphenate, toPromiseCallback
|
|
7
|
+
import { hyphenate, toPromiseCallback } from '@ditojs/utils'
|
|
8
8
|
import { AssetFile } from './AssetFile.js'
|
|
9
9
|
|
|
10
10
|
const storageClasses = {}
|
|
@@ -158,18 +158,8 @@ export class Storage {
|
|
|
158
158
|
async _listKeys() {}
|
|
159
159
|
|
|
160
160
|
async _handleUpload(req, file, config) {
|
|
161
|
-
if (config.readImageSize) {
|
|
162
|
-
deprecate(
|
|
163
|
-
`config.readImageSize is deprecated in favour of config.readDimensions`
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
161
|
if (
|
|
167
|
-
|
|
168
|
-
config.readDimensions ||
|
|
169
|
-
// TODO: `config.readImageSize` was deprecated in favour of
|
|
170
|
-
// `config.readDimensions` in March 2023. Remove in 1 year.
|
|
171
|
-
config.readImageSize
|
|
172
|
-
) &&
|
|
162
|
+
config.readDimensions &&
|
|
173
163
|
/^(image|video)\//.test(file.mimetype)
|
|
174
164
|
) {
|
|
175
165
|
return this._handleMediaFile(req, file)
|
package/src/utils/duration.js
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1442,8 +1442,6 @@ export class Service {
|
|
|
1442
1442
|
/** @overridable */
|
|
1443
1443
|
stop(): Promise<void>
|
|
1444
1444
|
get logger(): PinoLogger
|
|
1445
|
-
/** @deprecated Use `instance.logger` instead. */
|
|
1446
|
-
getLogger(ctx: KoaContext): PinoLogger
|
|
1447
1445
|
}
|
|
1448
1446
|
export type Services = Record<string, Class<Service> | Service>
|
|
1449
1447
|
|
package/src/decorators/action.js
DELETED
package/src/decorators/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isArray, isObject } from '@ditojs/utils'
|
|
2
|
-
import { createDecorator } from '../utils/decorator.js'
|
|
3
|
-
|
|
4
|
-
export function parameters(parameters, options) {
|
|
5
|
-
if (!isArray(parameters) && !isObject(parameters)) {
|
|
6
|
-
throw new Error(
|
|
7
|
-
`@parameters() need to be defined using array or object definitions`
|
|
8
|
-
)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return createDecorator(value => {
|
|
12
|
-
value.parameters = parameters
|
|
13
|
-
// If validation options are provided, expose them through
|
|
14
|
-
// `handler.options.parameters`, see ControllerAction
|
|
15
|
-
if (options) {
|
|
16
|
-
value.options ||= {}
|
|
17
|
-
value.options.parameters = options
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isObject } from '@ditojs/utils'
|
|
2
|
-
import { createDecorator } from '../utils/decorator.js'
|
|
3
|
-
import { formatJson } from '../utils/json.js'
|
|
4
|
-
|
|
5
|
-
export function returns(returns, options) {
|
|
6
|
-
if (!isObject(returns)) {
|
|
7
|
-
throw new Error(
|
|
8
|
-
`@returns(${
|
|
9
|
-
formatJson(returns, false)
|
|
10
|
-
}) needs to be defined using an object parameter definition`
|
|
11
|
-
)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return createDecorator(value => {
|
|
15
|
-
value.returns = returns
|
|
16
|
-
// If validation options are provided, expose them through
|
|
17
|
-
// `handler.options.returns`, see ControllerAction
|
|
18
|
-
if (options) {
|
|
19
|
-
value.options ||= {}
|
|
20
|
-
value.options.returns = options
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
}
|
package/src/decorators/scope.js
DELETED