@ditojs/server 1.4.0 → 1.4.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": "1.4.0",
3
+ "version": "1.4.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",
@@ -21,15 +21,15 @@
21
21
  "node >= 16"
22
22
  ],
23
23
  "dependencies": {
24
- "@ditojs/admin": "^1.4.0",
25
- "@ditojs/router": "^1.4.0",
26
- "@ditojs/utils": "^1.4.0",
24
+ "@ditojs/admin": "^1.4.3",
25
+ "@ditojs/router": "^1.4.3",
26
+ "@ditojs/utils": "^1.4.3",
27
27
  "@koa/cors": "^3.2.0",
28
28
  "@koa/multer": "^3.0.0",
29
29
  "@originjs/vite-plugin-commonjs": "^1.0.3",
30
- "ajv": "^8.10.0",
30
+ "ajv": "^8.11.0",
31
31
  "ajv-formats": "^2.1.1",
32
- "aws-sdk": "^2.1095.0",
32
+ "aws-sdk": "^2.1098.0",
33
33
  "axios": "^0.26.1",
34
34
  "bcryptjs": "^2.4.3",
35
35
  "bytes": "^3.1.2",
@@ -61,7 +61,7 @@
61
61
  "passthrough-counter": "^1.0.0",
62
62
  "picocolors": "^1.0.0",
63
63
  "picomatch": "^2.3.1",
64
- "pino": "^7.9.1",
64
+ "pino": "^7.9.2",
65
65
  "pino-pretty": "^7.5.4",
66
66
  "pluralize": "^8.0.0",
67
67
  "repl": "^0.1.3",
@@ -81,5 +81,5 @@
81
81
  "pg": "^8.7.3",
82
82
  "sqlite3": "^5.0.2"
83
83
  },
84
- "gitHead": "0b308cb3bd1513d78894c7ccdc0c8716339f55a1"
84
+ "gitHead": "f2a544aef8ab0a12c7019650cd86558f8365b007"
85
85
  }
@@ -17,6 +17,10 @@ export function handleUser() {
17
17
  const { user } = ctx.state
18
18
  await user?.$emit('before:logout', options)
19
19
  await logout.call(this) // No options in passport's logout()
20
+ // Clear the session after logout, apparently koa-passport doesn't take
21
+ // care of this itself:
22
+ // https://stackoverflow.com/questions/55818887/koa-passport-logout-is-not-clearing-session
23
+ ctx.session = null
20
24
  await user?.$emit('after:logout', options)
21
25
  }
22
26
 
@@ -216,38 +216,34 @@ export class QueryBuilder extends objection.QueryBuilder {
216
216
  this._allowScopes = query._allowScopes ? { ...query._allowScopes } : null
217
217
  this._ignoreScopes = { ...query._ignoreScopes }
218
218
  }
219
- // If he target is a child query of a graph query, copy all scopes, graph
219
+ const scopes = isChildQuery
220
+ // When copying scopes for child-queries, we also need to take the already
221
+ // applied scopes into account and copy those too.
222
+ ? { ...query._appliedScopes, ...query._scopes }
223
+ : { ...query._scopes }
224
+ // If the target is a child query of a graph query, copy all scopes, graph
220
225
  // and non-graph. If it is a child query of a related or eager query,
221
226
  // copy only the graph scopes.
222
227
  const copyAllScopes =
223
228
  isSameModelClass && isChildQuery && query.has(/GraphAndFetch$/)
224
- this._scopes = this._filterScopes(query._scopes, (scope, graph) =>
225
- copyAllScopes || graph)
226
- }
227
-
228
- _filterScopes(scopes, callback) {
229
- return Object.entries(scopes).reduce(
230
- (scopes, [scope, graph]) => {
231
- if (callback(scope, graph)) {
232
- scopes[scope] = graph
233
- }
234
- return scopes
235
- },
236
- {}
237
- )
229
+ this._scopes = copyAllScopes
230
+ ? scopes
231
+ : filterScopes(scopes, (scope, graph) => graph) // copy graph-scopes only.
238
232
  }
239
233
 
240
234
  _applyScope(scope, graph) {
241
235
  if (!this._ignoreScopes[SYMBOL_ALL] && !this._ignoreScopes[scope]) {
242
236
  // Prevent multiple application of scopes. This can easily occur
243
237
  // with the nesting and eager-application of graph-scopes, see below.
244
- if (!this._appliedScopes[scope]) {
238
+ // NOTE: The boolean values indicate the `graph` settings, not whether the
239
+ // scopes were applied or not.
240
+ if (!(scope in this._appliedScopes)) {
245
241
  // Only apply graph-scopes that are actually defined on the model:
246
242
  const func = this.modelClass().getScope(scope)
247
243
  if (func) {
248
244
  func.call(this, this)
249
245
  }
250
- this._appliedScopes[scope] = true
246
+ this._appliedScopes[scope] = graph
251
247
  }
252
248
  if (graph) {
253
249
  // Also bake the scope into any graph expression that may have been
@@ -255,12 +251,12 @@ export class QueryBuilder extends objection.QueryBuilder {
255
251
  const expr = this.graphExpressionObject()
256
252
  if (expr) {
257
253
  // Add a new modifier to the existing graph expression that
258
- // recursively applies the graph-scope to the resulting queries.
259
- // This even works if nested scopes expand the graph expression,
260
- // because it re-applies itself to the result.
254
+ // recursively adds the graph-scope to the resulting queries. This
255
+ // even works if nested scopes expand the graph expression, because it
256
+ // re-applies itself to the result.
261
257
  const name = `^${scope}`
262
258
  const modifiers = {
263
- [name]: query => query._applyScope(scope, graph)
259
+ [name]: query => query.withScope(name)
264
260
  }
265
261
  this.withGraph(
266
262
  addGraphScope(this.modelClass(), expr, [name], modifiers, true)
@@ -796,6 +792,12 @@ for (const key of [
796
792
  }
797
793
  }
798
794
 
795
+ function filterScopes(scopes, callback) {
796
+ return Object.fromEntries(Object.entries(scopes).filter(
797
+ ([scope, graph]) => callback(scope, graph)
798
+ ))
799
+ }
800
+
799
801
  // The default options for insertDitoGraph(), upsertDitoGraph(),
800
802
  // updateDitoGraph() and patchDitoGraph()
801
803
  const insertDitoGraphOptions = {