@ditojs/server 2.78.0 → 2.80.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.78.0",
3
+ "version": "2.80.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",
@@ -26,10 +26,10 @@
26
26
  "node >= 18"
27
27
  ],
28
28
  "dependencies": {
29
- "@ditojs/admin": "^2.78.0",
30
- "@ditojs/build": "^2.78.0",
31
- "@ditojs/router": "^2.78.0",
32
- "@ditojs/utils": "^2.78.0",
29
+ "@ditojs/admin": "^2.80.0",
30
+ "@ditojs/build": "^2.80.0",
31
+ "@ditojs/router": "^2.80.0",
32
+ "@ditojs/utils": "^2.80.0",
33
33
  "@koa/cors": "^5.0.0",
34
34
  "@koa/etag": "^5.0.2",
35
35
  "@koa/multer": "^4.0.0",
@@ -90,5 +90,5 @@
90
90
  "objection": "^3.1.5",
91
91
  "typescript": "^5.9.3"
92
92
  },
93
- "gitHead": "ede4c836e6b2bb5dfcc80e1614a3d85eb80b0efa"
93
+ "gitHead": "fd999439023af0616fa1e8afd51909eff651161d"
94
94
  }
@@ -146,6 +146,7 @@ export function convertRelation(schema, models) {
146
146
  let {
147
147
  relation,
148
148
  // Dito.js-style relation description:
149
+ modelClass,
149
150
  from,
150
151
  to,
151
152
  through,
@@ -224,7 +225,7 @@ export function convertRelation(schema, models) {
224
225
  const origModify = modify
225
226
  modify = query => {
226
227
  query.applyScope(
227
- scope,
228
+ ...asArray(scope),
228
229
  // Pass `false` for `checkAllowedScopes`, to always allow scopes
229
230
  // that are defined on relations to be applied.
230
231
  false
@@ -234,9 +235,18 @@ export function convertRelation(schema, models) {
234
235
  }
235
236
  }
236
237
  }
238
+ if (isString(modelClass)) {
239
+ const modelName = modelClass
240
+ modelClass = models[modelName]
241
+ if (!modelClass) {
242
+ throw new RelationError(
243
+ `Unknown model class: ${modelName}`
244
+ )
245
+ }
246
+ }
237
247
  return {
238
248
  relation: relationClass,
239
- modelClass: to.modelClass,
249
+ modelClass: modelClass ?? to.modelClass,
240
250
  join: {
241
251
  from: from.toValue(),
242
252
  to: to.toValue(),
@@ -29,7 +29,11 @@ export function convertSchema(
29
29
  mergeDefinitions(parentEntry.definitions, definitions)
30
30
  }
31
31
  }
32
- return schema
32
+ // When the schema is null, a circular reference is being processed.
33
+ // Break the chain by cloning the original schema and converting it again:
34
+ return schema === null
35
+ ? convertSchema({ ...original }, options, parentEntry)
36
+ : schema
33
37
  }
34
38
 
35
39
  const entry = {
@@ -103,26 +107,27 @@ export function convertSchema(
103
107
  // TODO: Consider moving to `model` keyword instead that would support
104
108
  // model validation and still could be combined with other keywords.
105
109
  schema.$ref = type
106
- // `$ref` doesn't play with `nullable`, so convert to `oneOf`
107
- if (schema.nullable) {
108
- delete schema.nullable
109
- schema = {
110
- oneOf: [
111
- { type: 'null' },
112
- schema
113
- ]
114
- }
115
- }
116
110
  }
117
111
  }
118
112
  }
119
113
  if (excludeDefaults[schema.default]) {
120
114
  delete schema.default
121
115
  }
122
- // Make nullable work with enum, see the issue for more details:
123
- // https://github.com/ajv-validator/ajv/issues/1471
124
- if (schema.nullable && schema.enum && !schema.enum.includes(null)) {
125
- schema.enum.push(null)
116
+ if (schema.nullable) {
117
+ if (schema.$ref) {
118
+ // `$ref` doesn't play with `nullable`, so convert to `oneOf`
119
+ delete schema.nullable
120
+ schema = {
121
+ oneOf: [
122
+ { type: 'null' },
123
+ schema
124
+ ]
125
+ }
126
+ } else if (schema.enum && !schema.enum.includes(null)) {
127
+ // Make nullable work with enum, see the issue for more details:
128
+ // https://github.com/ajv-validator/ajv/issues/1471
129
+ schema.enum.push(null)
130
+ }
126
131
  }
127
132
 
128
133
  // Convert properties last. This is needed for circular references