@ditojs/server 2.28.2 → 2.29.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.28.2",
3
+ "version": "2.29.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",
@@ -22,10 +22,10 @@
22
22
  "node >= 18"
23
23
  ],
24
24
  "dependencies": {
25
- "@ditojs/admin": "^2.28.2",
26
- "@ditojs/build": "^2.28.0",
27
- "@ditojs/router": "^2.28.1",
28
- "@ditojs/utils": "^2.28.0",
25
+ "@ditojs/admin": "^2.29.0",
26
+ "@ditojs/build": "^2.29.0",
27
+ "@ditojs/router": "^2.29.0",
28
+ "@ditojs/utils": "^2.29.0",
29
29
  "@koa/cors": "^5.0.0",
30
30
  "@koa/multer": "^3.0.2",
31
31
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -90,7 +90,7 @@
90
90
  "typescript": "^5.4.5"
91
91
  },
92
92
  "types": "types",
93
- "gitHead": "a9db3666df01cb3ee66a0ec7525d9221e15c5655",
93
+ "gitHead": "bdf4f66c3d6232f2322dacb088a0611f1e07dc7b",
94
94
  "scripts": {
95
95
  "types": "tsc --noEmit --esModuleInterop ./types/index.d.ts"
96
96
  },
@@ -402,14 +402,6 @@ export class Application extends Koa {
402
402
  return this.getAdminController()?.defineViteConfig(config) || null
403
403
  }
404
404
 
405
- getAdminViteConfig(config) {
406
- deprecate(
407
- `app.getAdminViteConfig() is deprecated. Use app.defineAdminViteConfig() instead.`
408
- )
409
-
410
- return this.defineAdminViteConfig(config)
411
- }
412
-
413
405
  async loadAdminViteConfig() {
414
406
  const cwd = process.cwd()
415
407
  for (const extension of ['js', 'mjs', 'cjs', 'ts']) {
@@ -5,7 +5,7 @@ import { defineConfig, createServer } from 'vite'
5
5
  import createVuePlugin from '@vitejs/plugin-vue'
6
6
  import { viteCommonjs as createCommonJsPlugin } from '@originjs/vite-plugin-commonjs'
7
7
  import { testModuleIdentifier, getPostCssConfig } from '@ditojs/build'
8
- import { assignDeeply, deprecate } from '@ditojs/utils'
8
+ import { assignDeeply } from '@ditojs/utils'
9
9
  import { Controller } from './Controller.js'
10
10
  import { handleConnectMiddleware } from '../middleware/index.js'
11
11
  import { ControllerError } from '../errors/index.js'
@@ -34,19 +34,7 @@ export class AdminController extends Controller {
34
34
 
35
35
  getPath(name) {
36
36
  const { config } = this
37
- let str = config[name]
38
- if (config.build?.path || config.dist?.path) {
39
- deprecate(
40
- `config.admin.build.path and config.admin.dist.path are deprecated. Use config.admin.root and config.admin.dist instead.`
41
- )
42
-
43
- str =
44
- name === 'root'
45
- ? config.build?.path
46
- : name === 'dist'
47
- ? config.dist?.path
48
- : null
49
- }
37
+ const str = config[name]
50
38
  if (!str) {
51
39
  throw new ControllerError(
52
40
  this,
@@ -25,8 +25,7 @@ import {
25
25
  asArray,
26
26
  equals,
27
27
  parseDataPath,
28
- normalizeDataPath,
29
- deprecate
28
+ normalizeDataPath
30
29
  } from '@ditojs/utils'
31
30
 
32
31
  export class Controller {
@@ -625,15 +624,6 @@ function convertActionObject(name, object, actions) {
625
624
  // notation, deploy this crazy JS sorcery:
626
625
  Object.setPrototypeOf(object, Object.getPrototypeOf(actions))
627
626
 
628
- if (action) {
629
- deprecate(
630
- `action.action is deprecated. Use action.method and action.path instead.`
631
- )
632
- const [method, path] = asArray(action)
633
- handler.method = method
634
- handler.path = path
635
- }
636
-
637
627
  if (!handler) {
638
628
  throw new Error(
639
629
  `Missing handler in '${name}' action: ${formatJson(object)}`
@@ -1,19 +1,7 @@
1
- import { isArray, isObject, deprecate } from '@ditojs/utils'
1
+ import { isArray, isObject } from '@ditojs/utils'
2
2
  import { createDecorator } from '../utils/decorator.js'
3
- import { formatJson } from '../utils/json.js'
4
3
 
5
4
  export function parameters(parameters, options) {
6
- if (isObject(parameters)) {
7
- const first = parameters[Object.keys(parameters)[0]]
8
- if (!isObject(first)) {
9
- deprecate(
10
- `@parameters(${
11
- formatJson(parameters, false)
12
- }) with parameter schema object is deprecated: Schema object should be passed nested inside an array or object definition.`
13
- )
14
- parameters = [...arguments]
15
- }
16
- }
17
5
  if (!isArray(parameters) && !isObject(parameters)) {
18
6
  throw new Error(
19
7
  `@parameters() need to be defined using array or object definitions`
@@ -762,7 +762,7 @@ export class Model extends objection.Model {
762
762
  case '#': // Select column:
763
763
  return query.select(modifier.slice(1))
764
764
  case '*': // Select all columns:
765
- if (modifier.length === 1) {
765
+ if (modifier === '*') {
766
766
  return query.select('*')
767
767
  }
768
768
  }
@@ -1,16 +1,16 @@
1
1
  import objection from 'objection'
2
2
  import {
3
+ isArray,
4
+ isString,
5
+ isBoolean,
3
6
  isObject,
4
7
  isPlainObject,
5
- isString,
6
- isArray,
7
8
  clone,
8
9
  mapKeys,
9
10
  getValueAtDataPath,
10
11
  setValueAtDataPath,
11
12
  normalizeDataPath,
12
- parseDataPath,
13
- deprecate
13
+ parseDataPath
14
14
  } from '@ditojs/utils'
15
15
  import { QueryParameters } from './QueryParameters.js'
16
16
  import { KnexHelper } from '../lib/index.js'
@@ -88,11 +88,16 @@ export class QueryBuilder extends objection.QueryBuilder {
88
88
  return super.toFindQuery().clear('runAfter')
89
89
  }
90
90
 
91
- withScope(...scopes) {
91
+ withScope(...args) {
92
+ const { checkAllowedScopes, scopes } = getScopes(args)
92
93
  for (const expr of scopes) {
93
94
  if (expr) {
94
95
  const { scope, graph } = getScope(expr)
95
- if (this.#allowScopes && !this.#allowScopes[scope]) {
96
+ if (
97
+ checkAllowedScopes &&
98
+ this.#allowScopes &&
99
+ !this.#allowScopes[scope]
100
+ ) {
96
101
  throw new QueryBuilderError(
97
102
  `Query scope '${scope}' is not allowed.`
98
103
  )
@@ -125,12 +130,12 @@ export class QueryBuilder extends objection.QueryBuilder {
125
130
  return this
126
131
  }
127
132
 
128
- applyScope(...scopes) {
133
+ applyScope(...args) {
129
134
  // When directly applying a scope, still merge it into `this.#scopes`,
130
135
  // so it can still be passed on to forked child queries. This also handles
131
136
  // the checks against `_allowScopes`.
132
- this.withScope(...scopes)
133
- for (const expr of scopes) {
137
+ this.withScope(...args)
138
+ for (const expr of getScopes(args).scopes) {
134
139
  if (expr) {
135
140
  const { scope, graph } = getScope(expr)
136
141
  this.#applyScope(scope, graph)
@@ -155,28 +160,6 @@ export class QueryBuilder extends objection.QueryBuilder {
155
160
  this.#allowScopes = null
156
161
  }
157
162
 
158
- scope(...scopes) {
159
- deprecate(`QueryBuilder#scope() is deprecated. Use #withScope() instead.`)
160
-
161
- return this.clearWithScope().withScope(...scopes)
162
- }
163
-
164
- mergeScope(...scopes) {
165
- deprecate(
166
- `QueryBuilder#mergeScope() is deprecated. Use #withScope() instead.`
167
- )
168
-
169
- return this.withScope(...scopes)
170
- }
171
-
172
- clearScope() {
173
- deprecate(
174
- `QueryBuilder#clearScope() is deprecated. Use #clearWithScope() or #ignoreScope() instead.`
175
- )
176
-
177
- return this.clearWithScope()
178
- }
179
-
180
163
  #clearScopes(addDefault) {
181
164
  // `_scopes` is an object where the keys are the scopes and the values
182
165
  // indicate if the scope should be eager-applied or not:
@@ -869,6 +852,17 @@ for (const key of [
869
852
  }
870
853
  }
871
854
 
855
+ function getScopes(args) {
856
+ const last = args.at(-1)
857
+ let scopes = args
858
+ let checkAllowedScopes = true
859
+ if (isBoolean(last)) {
860
+ checkAllowedScopes = last
861
+ scopes = args.slice(0, -1)
862
+ }
863
+ return { scopes, checkAllowedScopes }
864
+ }
865
+
872
866
  function filterScopes(scopes, callback) {
873
867
  return Object.fromEntries(
874
868
  Object.entries(scopes).filter(
@@ -223,7 +223,12 @@ export function convertRelation(schema, models) {
223
223
  // Create a new modify function that merges scope and modify them:
224
224
  const origModify = modify
225
225
  modify = query => {
226
- query.applyScope(scope)
226
+ query.applyScope(
227
+ scope,
228
+ // Pass `false` for `checkAllowedScopes`, to always allow scopes
229
+ // that are defined on relations to be applied.
230
+ false
231
+ )
227
232
  if (origModify) {
228
233
  query.modify(origModify)
229
234
  }