@ditojs/server 2.30.1 → 2.30.3

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.30.1",
3
+ "version": "2.30.3",
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",
@@ -90,7 +90,7 @@
90
90
  "typescript": "^5.4.5"
91
91
  },
92
92
  "types": "types",
93
- "gitHead": "39fbb6da77e7d90265fce7cd7cd7e92b3b034803",
93
+ "gitHead": "7ea9e5bd85295f299825a8560dc25caee1cc94d2",
94
94
  "scripts": {
95
95
  "types": "tsc --noEmit --esModuleInterop ./types/index.d.ts"
96
96
  },
@@ -748,7 +748,12 @@ export class Model extends objection.Model {
748
748
  static modifierNotFound(query, modifier) {
749
749
  if (isString(modifier)) {
750
750
  if (query.modelClass().hasScope(modifier)) {
751
- return query.applyScope(modifier)
751
+ return query.applyScope(
752
+ modifier,
753
+ // Pass `false` for `checkAllowedScopes`, to always allow scopes
754
+ // that are defined on relations to be applied.
755
+ false
756
+ )
752
757
  }
753
758
  // Now check possible scope prefixes and handle them:
754
759
  switch (modifier[0]) {
@@ -756,7 +761,12 @@ export class Model extends objection.Model {
756
761
  // Always apply eager-scopes, even if the model itself doesn't know
757
762
  // it. The scope may still be known in eager-loaded relations.
758
763
  // Note: `applyScope()` will handle the '^' sign.
759
- return query.applyScope(modifier)
764
+ return query.applyScope(
765
+ modifier,
766
+ // Pass `false` for `checkAllowedScopes`, to always allow scopes
767
+ // that are defined on relations to be applied.
768
+ false
769
+ )
760
770
  case '-': // Ignore scope:
761
771
  return query.ignoreScope(modifier.slice(1))
762
772
  case '#': // Select column:
@@ -88,7 +88,7 @@ export class QueryBuilder extends objection.QueryBuilder {
88
88
  return super.toFindQuery().clear('runAfter')
89
89
  }
90
90
 
91
- withScope(...args) {
91
+ #withScope(...args) {
92
92
  const { checkAllowedScopes, scopes } = getScopes(args)
93
93
  for (const expr of scopes) {
94
94
  if (expr) {
@@ -105,6 +105,11 @@ export class QueryBuilder extends objection.QueryBuilder {
105
105
  this.#scopes[scope] ||= graph
106
106
  }
107
107
  }
108
+ return scopes
109
+ }
110
+
111
+ withScope(...args) {
112
+ this.#withScope(...args)
108
113
  return this
109
114
  }
110
115
 
@@ -131,11 +136,10 @@ export class QueryBuilder extends objection.QueryBuilder {
131
136
  }
132
137
 
133
138
  applyScope(...args) {
134
- // When directly applying a scope, still merge it into `this.#scopes`,
135
- // so it can still be passed on to forked child queries. This also handles
136
- // the checks against `_allowScopes`.
137
- this.withScope(...args)
138
- for (const expr of getScopes(args).scopes) {
139
+ // When directly applying a scope, still use `#withScope() to merge it into
140
+ // `this.#scopes`, so it can still be passed on to forked child queries.
141
+ // This also handles the checks against `#allowScopes`.
142
+ for (const expr of this.#withScope(...args)) {
139
143
  if (expr) {
140
144
  const { scope, graph } = getScope(expr)
141
145
  this.#applyScope(scope, graph)
@@ -171,7 +175,7 @@ export class QueryBuilder extends objection.QueryBuilder {
171
175
 
172
176
  #copyScopes(query, isChildQuery = false) {
173
177
  const isSameModelClass = this.modelClass() === query.modelClass()
174
- // Only copy `_allowScopes` and `_ignoreScopes` if it's for the same model.
178
+ // Only copy `#allowScopes` and `_ignoreScopes` if it's for the same model.
175
179
  if (isSameModelClass) {
176
180
  this.#allowScopes = query.#allowScopes ? { ...query.#allowScopes } : null
177
181
  this.#ignoreScopes = { ...query.#ignoreScopes }
@@ -205,9 +209,9 @@ export class QueryBuilder extends objection.QueryBuilder {
205
209
  // If this isn't a normal find query, ignore all graph operations,
206
210
  // to not mess with special selects such as `count`, etc:
207
211
  this.#ignoreGraph = !isNormalFind
208
- // All scopes in `_scopes` were already checked against `_allowScopes`.
212
+ // All scopes in `_scopes` were already checked against `#allowScopes`.
209
213
  // They themselves are allowed to apply / request other scopes that
210
- // aren't listed, so clear `_allowScopes` and restore again after:
214
+ // aren't listed, so clear `#allowScopes` and restore again after:
211
215
  const allowScopes = this.#allowScopes
212
216
  this.#allowScopes = null
213
217
  const collectedScopes = {}
@@ -263,7 +267,12 @@ export class QueryBuilder extends objection.QueryBuilder {
263
267
  const name = `^${scope}`
264
268
  const modifiers = {
265
269
  [name]: query => {
266
- query.withScope(name)
270
+ query.withScope(
271
+ name,
272
+ // Pass `false` for `checkAllowedScopes` as when `#applyScope()`
273
+ // was called, no further checks are required.
274
+ false
275
+ )
267
276
  if (query.#isJoinChildQuery) {
268
277
  // Join child queries are never executed, and need to apply
269
278
  // their scopes manually. Note that it's OK to call this
@@ -852,15 +861,14 @@ for (const key of [
852
861
  }
853
862
  }
854
863
 
855
- function getScopes(args) {
856
- const last = args.at(-1)
857
- let scopes = args
864
+ function getScopes(scopes) {
858
865
  let checkAllowedScopes = true
866
+ const last = scopes.at(-1)
859
867
  if (isBoolean(last)) {
860
868
  checkAllowedScopes = last
861
- scopes = args.slice(0, -1)
869
+ scopes = scopes.slice(0, -1)
862
870
  }
863
- return { scopes, checkAllowedScopes }
871
+ return { checkAllowedScopes, scopes }
864
872
  }
865
873
 
866
874
  function filterScopes(scopes, callback) {