@ditojs/server 2.30.1 → 2.30.2
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 +2 -2
- package/src/models/Model.js +12 -2
- package/src/query/QueryBuilder.js +17 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "2.30.
|
|
3
|
+
"version": "2.30.2",
|
|
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": "
|
|
93
|
+
"gitHead": "5836afdea0e9d269307af74900e7d43c3bab7e2b",
|
|
94
94
|
"scripts": {
|
|
95
95
|
"types": "tsc --noEmit --esModuleInterop ./types/index.d.ts"
|
|
96
96
|
},
|
package/src/models/Model.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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
|
|
135
|
-
// so it can still be passed on to forked child queries.
|
|
136
|
-
// the checks against
|
|
137
|
-
this
|
|
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 `
|
|
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
|
|
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 `
|
|
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 = {}
|
|
@@ -852,15 +856,14 @@ for (const key of [
|
|
|
852
856
|
}
|
|
853
857
|
}
|
|
854
858
|
|
|
855
|
-
function getScopes(
|
|
856
|
-
const last = args.at(-1)
|
|
857
|
-
let scopes = args
|
|
859
|
+
function getScopes(scopes) {
|
|
858
860
|
let checkAllowedScopes = true
|
|
861
|
+
const last = scopes.at(-1)
|
|
859
862
|
if (isBoolean(last)) {
|
|
860
863
|
checkAllowedScopes = last
|
|
861
|
-
scopes =
|
|
864
|
+
scopes = scopes.slice(0, -1)
|
|
862
865
|
}
|
|
863
|
-
return {
|
|
866
|
+
return { checkAllowedScopes, scopes }
|
|
864
867
|
}
|
|
865
868
|
|
|
866
869
|
function filterScopes(scopes, callback) {
|