@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/server",
3
- "version": "2.47.0",
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.47.0",
29
- "@ditojs/build": "^2.47.0",
30
- "@ditojs/router": "^2.47.0",
31
- "@ditojs/utils": "^2.47.0",
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": "^2.1.1",
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": "9ce26a1dc412e67304e823c0206593ee4a9c8ae4"
93
+ "gitHead": "bacff1f9a6b314fad4f01b4a83d5cf4778d344e1"
94
94
  }
@@ -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) {
@@ -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 (e) {
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
- convertToCoreActions(actions) {
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.convertToCoreActions({
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
- reflectActionsObject() {
146
- // On base controllers, the actions can be defined directly in the class
147
- // instead of inside an actions object, as is done with model and relation
148
- // controllers. But in order to use the same structure for inheritance as
149
- // these other controllers, we reflect these instance fields in a separate
150
- // `actions` object.
151
- const { allow } = this
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
- // Use `Object.getOwnPropertyNames()` to get the fields, in order to
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
- for (const [name, action] of Object.entries(actions)) {
194
- // Replace the action object with the converted action handler, so they
195
- // too can benefit from prototypal inheritance:
196
- actions[name] = this.setupAction(
197
- type,
198
- actions,
199
- name,
200
- action,
201
- authorize[name]
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
- _method,
11
- _path,
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'
@@ -87,7 +87,7 @@ export class RelationController extends CollectionController {
87
87
  })
88
88
  }
89
89
 
90
- collection = this.convertToCoreActions({})
90
+ collection = this.markAsCoreActions({})
91
91
 
92
- member = this.convertToCoreActions({})
92
+ member = this.markAsCoreActions({})
93
93
  }
package/src/index.js CHANGED
@@ -6,5 +6,4 @@ export * from './mixins/index.js'
6
6
  export * from './models/index.js'
7
7
  export * from './controllers/index.js'
8
8
  export * from './services/index.js'
9
- export * from './decorators/index.js'
10
9
  export * from './storage/index.js'
@@ -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
  ]
@@ -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 })
@@ -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 (err) {}
167
+ } catch {}
168
168
  return null
169
169
  }
@@ -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, deprecate } from '@ditojs/utils'
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)
@@ -1,5 +1,4 @@
1
1
  import { isNumber } from '@ditojs/utils'
2
- // eslint-disable-next-line import/default
3
2
  import parseDuration from 'parse-duration'
4
3
 
5
4
  export function getDuration(duration) {
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
 
@@ -1,8 +0,0 @@
1
- import { createDecorator } from '../utils/decorator.js'
2
-
3
- export function action(method, path) {
4
- return createDecorator(value => {
5
- value.method = method
6
- value.path = path
7
- })
8
- }
@@ -1,7 +0,0 @@
1
- import { createDecorator } from '../utils/decorator.js'
2
-
3
- export function authorize(authorize) {
4
- return createDecorator(value => {
5
- value.authorize = authorize
6
- })
7
- }
@@ -1,6 +0,0 @@
1
- export * from './action.js'
2
- export * from './authorize.js'
3
- export * from './parameters.js'
4
- export * from './returns.js'
5
- export * from './scope.js'
6
- export * from './transacted.js'
@@ -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
- }
@@ -1,8 +0,0 @@
1
- import { createDecorator } from '../utils/decorator.js'
2
-
3
- export function scope(...scopes) {
4
- return createDecorator(value => {
5
- const scope = (value.scope ||= [])
6
- scope.push(...scopes)
7
- })
8
- }
@@ -1,5 +0,0 @@
1
- import { createDecorator } from '../utils/decorator.js'
2
-
3
- export const transacted = createDecorator(value => {
4
- value.transacted = true
5
- })