@ditojs/server 2.38.0 → 2.40.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.38.0",
3
+ "version": "2.40.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",
@@ -25,10 +25,10 @@
25
25
  "node >= 18"
26
26
  ],
27
27
  "dependencies": {
28
- "@ditojs/admin": "^2.38.0",
29
- "@ditojs/build": "^2.38.0",
30
- "@ditojs/router": "^2.38.0",
31
- "@ditojs/utils": "^2.38.0",
28
+ "@ditojs/admin": "^2.40.0",
29
+ "@ditojs/build": "^2.40.0",
30
+ "@ditojs/router": "^2.40.0",
31
+ "@ditojs/utils": "^2.40.0",
32
32
  "@koa/cors": "^5.0.0",
33
33
  "@koa/multer": "^3.0.2",
34
34
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -46,7 +46,7 @@
46
46
  "koa-compress": "^5.1.1",
47
47
  "koa-conditional-get": "^3.0.0",
48
48
  "koa-etag": "^4.0.0",
49
- "koa-helmet": "^7.1.0",
49
+ "koa-helmet": "^8.0.1",
50
50
  "koa-mount": "^4.0.0",
51
51
  "koa-passport": "^6.0.0",
52
52
  "koa-response-time": "^2.1.0",
@@ -56,8 +56,8 @@
56
56
  "mime-types": "^2.1.35",
57
57
  "multer": "^1.4.5-lts.1",
58
58
  "multer-s3": "https://github.com/ditojs/multer-s3#dito",
59
- "nanoid": "^5.0.8",
60
- "parse-duration": "^1.1.0",
59
+ "nanoid": "^5.0.9",
60
+ "parse-duration": "^1.1.1",
61
61
  "passport-local": "^1.0.0",
62
62
  "passthrough-counter": "^1.0.0",
63
63
  "picocolors": "^1.1.1",
@@ -66,7 +66,7 @@
66
66
  "pino-pretty": "^13.0.0",
67
67
  "pluralize": "^8.0.0",
68
68
  "repl": "^0.1.3",
69
- "type-fest": "^4.28.0",
69
+ "type-fest": "^4.30.0",
70
70
  "uuid": "^11.0.3"
71
71
  },
72
72
  "peerDependencies": {
@@ -76,19 +76,19 @@
76
76
  "objection": "^3.0.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@aws-sdk/client-s3": "^3.699.0",
80
- "@aws-sdk/lib-storage": "^3.699.0",
79
+ "@aws-sdk/client-s3": "^3.701.0",
80
+ "@aws-sdk/lib-storage": "^3.701.0",
81
81
  "@types/koa-bodyparser": "^4.3.12",
82
82
  "@types/koa-compress": "^4.0.6",
83
83
  "@types/koa-response-time": "^2.1.5",
84
84
  "@types/koa-session": "^6.4.5",
85
85
  "@types/koa-static": "^4.0.4",
86
86
  "@types/koa__cors": "^5.0.0",
87
- "@types/node": "^22.9.3",
87
+ "@types/node": "^22.10.1",
88
88
  "knex": "^3.1.0",
89
89
  "objection": "^3.1.5",
90
90
  "typescript": "^5.7.2"
91
91
  },
92
92
  "types": "types",
93
- "gitHead": "5e64e0bf42e2a526e58c10710ddb2ae14288ffae"
93
+ "gitHead": "bc2ebaea27229f1fce8597bd62f00644fb0925d4"
94
94
  }
@@ -164,6 +164,23 @@ export class Application extends Koa {
164
164
  this.router[method](path, route)
165
165
  }
166
166
 
167
+ fixModuleClassNames(modules) {
168
+ // Naming fix for a weird vite 6 bug where the model classes are sometimes
169
+ // prefixed with `_`, but only when imported in `vite.config.js`.
170
+ if (isPlainObject(modules)) {
171
+ for (const [key, module] of Object.entries(modules)) {
172
+ if (module?.name?.match(/^_(.*)$/)?.[1] === key) {
173
+ Object.defineProperty(module, 'name', {
174
+ value: key,
175
+ writable: false,
176
+ enumerable: false,
177
+ configurable: true
178
+ })
179
+ }
180
+ }
181
+ }
182
+ }
183
+
167
184
  getStorage(name) {
168
185
  return this.storages[name] || null
169
186
  }
@@ -190,8 +207,9 @@ export class Application extends Koa {
190
207
  }
191
208
 
192
209
  addStorages(storages) {
193
- for (const [name, config] of Object.entries(storages)) {
194
- this.addStorage(config, name)
210
+ this.fixModuleClassNames(storages)
211
+ for (const [key, config] of Object.entries(storages)) {
212
+ this.addStorage(config, key)
195
213
  }
196
214
  }
197
215
 
@@ -230,8 +248,9 @@ export class Application extends Koa {
230
248
  }
231
249
 
232
250
  addServices(services) {
233
- for (const [name, service] of Object.entries(services)) {
234
- this.addService(service, name)
251
+ this.fixModuleClassNames(services)
252
+ for (const [key, service] of Object.entries(services)) {
253
+ this.addService(service, key)
235
254
  }
236
255
  }
237
256
 
@@ -275,6 +294,7 @@ export class Application extends Koa {
275
294
  }
276
295
 
277
296
  addModels(models) {
297
+ this.fixModuleClassNames(models)
278
298
  models = Object.values(models)
279
299
  // First, add all models to the application, so that they can be referenced
280
300
  // by other models, e.g. in `jsonSchema` and `relationMappings`:
@@ -365,6 +385,7 @@ export class Application extends Koa {
365
385
  }
366
386
 
367
387
  addControllers(controllers, namespace) {
388
+ this.fixModuleClassNames(controllers)
368
389
  for (const [key, value] of Object.entries(controllers)) {
369
390
  if (isModule(value) || isPlainObject(value)) {
370
391
  this.addControllers(value, namespace ? `${namespace}/${key}` : key)
@@ -115,22 +115,10 @@ export class AdminController extends Controller {
115
115
  }
116
116
 
117
117
  async setupViteServer() {
118
- const config = (
119
- (await this.app.loadAdminViteConfig()) ||
120
- this.defineViteConfig()
121
- )
122
-
123
- const development = this.mode === 'development'
124
- const server = await createServer({
125
- ...config,
118
+ const defaultConfig = {
126
119
  server: {
127
120
  middlewareMode: true,
128
- hmr: {
129
- // Use a random free port instead of vite's default 24678, since we
130
- // may be running multiple servers in parallel (e.g. e2e and dev).
131
- port: await getRandomFreePort()
132
- },
133
- ...(development && {
121
+ ...(this.mode === 'development' && {
134
122
  watch: {
135
123
  // Watch the @ditojs packages while in dev mode, although they are
136
124
  // inside the node_modules folder.
@@ -138,7 +126,22 @@ export class AdminController extends Controller {
138
126
  }
139
127
  })
140
128
  }
141
- })
129
+ }
130
+
131
+ const viteConfig = (
132
+ (await this.app.loadAdminViteConfig()) ||
133
+ this.defineViteConfig()
134
+ )
135
+
136
+ const config = assignDeeply(defaultConfig, viteConfig)
137
+
138
+ if (config.server?.hmr?.port === 0) {
139
+ // Setting the port to 0 means use a random free port instead of vite's
140
+ // default 24678, since we may be running multiple servers in parallel.
141
+ config.server.hmr.port = await getRandomFreePort()
142
+ }
143
+
144
+ const server = await createServer(config)
142
145
 
143
146
  this.closed = false
144
147
 
@@ -159,7 +162,7 @@ export class AdminController extends Controller {
159
162
  }
160
163
 
161
164
  defineViteConfig(config = {}) {
162
- const development = this.mode === 'development'
165
+ const isDevelopment = this.mode === 'development'
163
166
 
164
167
  const cwd = process.cwd()
165
168
  const root = this.getPath('root')
@@ -193,7 +196,7 @@ export class AdminController extends Controller {
193
196
  }
194
197
  }
195
198
  ],
196
- build: development
199
+ build: isDevelopment
197
200
  ? {}
198
201
  : {
199
202
  outDir: this.getPath('dist'),
@@ -226,7 +229,7 @@ export class AdminController extends Controller {
226
229
  },
227
230
  css: {
228
231
  postcss: getPostCssConfig(),
229
- devSourcemap: development,
232
+ devSourcemap: isDevelopment,
230
233
  preprocessorOptions: {
231
234
  scss: {
232
235
  // https://sass-lang.com/documentation/breaking-changes/legacy-js-api/
@@ -236,10 +239,10 @@ export class AdminController extends Controller {
236
239
  }
237
240
  },
238
241
  optimizeDeps: {
239
- exclude: development ? ditoPackages : [],
242
+ exclude: isDevelopment ? ditoPackages : [],
240
243
  include: [
241
244
  ...(
242
- development
245
+ isDevelopment
243
246
  ? // https://discuss.prosemirror.net/t/rangeerror-adding-different-instances-of-a-keyed-plugin-plugin/4242/13
244
247
  [
245
248
  'prosemirror-state',