@ditojs/server 0.275.0 → 1.0.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.
Files changed (216) hide show
  1. package/package.json +25 -43
  2. package/src/app/Application.js +105 -111
  3. package/src/app/Validator.js +6 -3
  4. package/src/app/index.js +2 -2
  5. package/src/cli/db/createMigration.js +1 -1
  6. package/src/cli/db/index.js +7 -7
  7. package/src/cli/db/listAssetConfig.js +1 -1
  8. package/src/cli/db/reset.js +1 -1
  9. package/src/cli/index.js +14 -5
  10. package/src/controllers/AdminController.js +181 -158
  11. package/src/controllers/CollectionController.js +8 -29
  12. package/src/controllers/Controller.js +71 -76
  13. package/src/controllers/ControllerAction.js +39 -17
  14. package/src/controllers/MemberAction.js +2 -2
  15. package/src/controllers/ModelController.js +4 -4
  16. package/src/controllers/RelationController.js +3 -3
  17. package/src/controllers/{UserController.js → UsersController.js} +8 -13
  18. package/src/controllers/index.js +5 -5
  19. package/src/decorators/action.js +3 -3
  20. package/src/decorators/authorize.js +1 -1
  21. package/src/decorators/index.js +6 -6
  22. package/src/decorators/parameters.js +1 -1
  23. package/src/decorators/returns.js +1 -1
  24. package/src/decorators/scope.js +1 -1
  25. package/src/decorators/transacted.js +1 -1
  26. package/src/errors/AssetError.js +1 -1
  27. package/src/errors/AuthenticationError.js +1 -1
  28. package/src/errors/AuthorizationError.js +1 -1
  29. package/src/errors/ControllerError.js +1 -1
  30. package/src/errors/DatabaseError.js +12 -3
  31. package/src/errors/GraphError.js +1 -1
  32. package/src/errors/ModelError.js +1 -1
  33. package/src/errors/NotFoundError.js +1 -1
  34. package/src/errors/NotImplementedError.js +1 -1
  35. package/src/errors/QueryBuilderError.js +1 -1
  36. package/src/errors/RelationError.js +1 -1
  37. package/src/errors/ValidationError.js +1 -1
  38. package/src/errors/WrappedError.js +1 -1
  39. package/src/errors/index.js +14 -14
  40. package/src/graph/DitoGraphProcessor.js +2 -1
  41. package/src/graph/graph.js +1 -1
  42. package/src/graph/index.js +3 -3
  43. package/src/index.js +11 -9
  44. package/src/lib/index.js +2 -2
  45. package/src/middleware/createTransaction.js +1 -1
  46. package/src/middleware/findRoute.js +3 -2
  47. package/src/middleware/handleConnectMiddleware.js +88 -0
  48. package/src/middleware/handleError.js +1 -1
  49. package/src/middleware/handleRoute.js +3 -3
  50. package/src/middleware/index.js +8 -7
  51. package/src/mixins/AssetMixin.js +1 -1
  52. package/src/mixins/UserMixin.js +1 -1
  53. package/src/mixins/index.js +4 -4
  54. package/src/models/AssetModel.js +2 -2
  55. package/src/models/Model.js +16 -12
  56. package/src/models/RelationAccessor.js +1 -1
  57. package/src/models/SessionModel.js +2 -2
  58. package/src/models/TimeStampedModel.js +2 -2
  59. package/src/models/UserModel.js +2 -2
  60. package/src/models/definitions/assets.js +1 -1
  61. package/src/models/definitions/filters.js +57 -44
  62. package/src/models/definitions/hooks.js +1 -1
  63. package/src/models/definitions/index.js +9 -9
  64. package/src/models/definitions/modifiers.js +1 -1
  65. package/src/models/definitions/options.js +1 -1
  66. package/src/models/definitions/properties.js +2 -2
  67. package/src/models/definitions/relations.js +1 -1
  68. package/src/models/definitions/schema.js +1 -1
  69. package/src/models/definitions/scopes.js +2 -2
  70. package/src/models/index.js +5 -5
  71. package/src/query/QueryBuilder.js +5 -5
  72. package/src/query/QueryFilters.js +50 -50
  73. package/src/query/QueryParameters.js +2 -2
  74. package/src/query/index.js +3 -3
  75. package/src/schema/formats/index.js +2 -2
  76. package/src/schema/index.js +4 -4
  77. package/src/schema/keywords/_relate.js +1 -1
  78. package/src/schema/keywords/index.js +12 -12
  79. package/src/schema/properties.test.js +1 -1
  80. package/src/schema/relations.js +1 -1
  81. package/src/schema/relations.test.js +2 -2
  82. package/src/services/index.js +1 -1
  83. package/src/storage/DiskStorage.js +1 -1
  84. package/src/storage/S3Storage.js +4 -4
  85. package/src/storage/Storage.js +1 -1
  86. package/src/storage/index.js +4 -4
  87. package/src/utils/function.test.js +1 -1
  88. package/src/utils/handler.js +17 -0
  89. package/src/utils/index.js +8 -7
  90. package/src/utils/object.test.js +1 -1
  91. package/lib/app/Application.js +0 -961
  92. package/lib/app/SessionStore.js +0 -40
  93. package/lib/app/Validator.js +0 -355
  94. package/lib/app/index.js +0 -26
  95. package/lib/cli/console.js +0 -175
  96. package/lib/cli/db/createMigration.js +0 -237
  97. package/lib/cli/db/index.js +0 -66
  98. package/lib/cli/db/listAssetConfig.js +0 -16
  99. package/lib/cli/db/migrate.js +0 -15
  100. package/lib/cli/db/reset.js +0 -27
  101. package/lib/cli/db/rollback.js +0 -15
  102. package/lib/cli/db/seed.js +0 -104
  103. package/lib/cli/db/unlock.js +0 -15
  104. package/lib/cli/index.js +0 -90
  105. package/lib/controllers/AdminController.js +0 -258
  106. package/lib/controllers/CollectionController.js +0 -263
  107. package/lib/controllers/Controller.js +0 -462
  108. package/lib/controllers/ControllerAction.js +0 -276
  109. package/lib/controllers/MemberAction.js +0 -22
  110. package/lib/controllers/ModelController.js +0 -64
  111. package/lib/controllers/RelationController.js +0 -82
  112. package/lib/controllers/UserController.js +0 -98
  113. package/lib/controllers/index.js +0 -50
  114. package/lib/decorators/action.js +0 -14
  115. package/lib/decorators/authorize.js +0 -13
  116. package/lib/decorators/index.js +0 -58
  117. package/lib/decorators/parameters.js +0 -35
  118. package/lib/decorators/returns.js +0 -26
  119. package/lib/decorators/scope.js +0 -14
  120. package/lib/decorators/transacted.js +0 -12
  121. package/lib/errors/AssetError.js +0 -19
  122. package/lib/errors/AuthenticationError.js +0 -19
  123. package/lib/errors/AuthorizationError.js +0 -19
  124. package/lib/errors/ControllerError.js +0 -24
  125. package/lib/errors/DatabaseError.js +0 -27
  126. package/lib/errors/GraphError.js +0 -19
  127. package/lib/errors/ModelError.js +0 -24
  128. package/lib/errors/NotFoundError.js +0 -19
  129. package/lib/errors/NotImplementedError.js +0 -19
  130. package/lib/errors/QueryBuilderError.js +0 -19
  131. package/lib/errors/RelationError.js +0 -36
  132. package/lib/errors/ResponseError.js +0 -46
  133. package/lib/errors/ValidationError.js +0 -19
  134. package/lib/errors/WrappedError.js +0 -24
  135. package/lib/errors/index.js +0 -122
  136. package/lib/graph/DitoGraphProcessor.js +0 -185
  137. package/lib/graph/expression.js +0 -76
  138. package/lib/graph/graph.js +0 -300
  139. package/lib/graph/index.js +0 -34
  140. package/lib/index.js +0 -82
  141. package/lib/lib/EventEmitter.js +0 -76
  142. package/lib/lib/KnexHelper.js +0 -40
  143. package/lib/lib/index.js +0 -26
  144. package/lib/middleware/attachLogger.js +0 -16
  145. package/lib/middleware/createTransaction.js +0 -36
  146. package/lib/middleware/findRoute.js +0 -35
  147. package/lib/middleware/handleError.js +0 -26
  148. package/lib/middleware/handleRoute.js +0 -29
  149. package/lib/middleware/handleUser.js +0 -36
  150. package/lib/middleware/index.js +0 -66
  151. package/lib/middleware/logRequests.js +0 -122
  152. package/lib/mixins/AssetMixin.js +0 -81
  153. package/lib/mixins/SessionMixin.js +0 -22
  154. package/lib/mixins/TimeStampedMixin.js +0 -47
  155. package/lib/mixins/UserMixin.js +0 -151
  156. package/lib/mixins/index.js +0 -42
  157. package/lib/models/AssetModel.js +0 -12
  158. package/lib/models/Model.js +0 -953
  159. package/lib/models/RelationAccessor.js +0 -41
  160. package/lib/models/SessionModel.js +0 -12
  161. package/lib/models/TimeStampedModel.js +0 -12
  162. package/lib/models/UserModel.js +0 -12
  163. package/lib/models/definitions/assets.js +0 -11
  164. package/lib/models/definitions/filters.js +0 -101
  165. package/lib/models/definitions/hooks.js +0 -11
  166. package/lib/models/definitions/index.js +0 -38
  167. package/lib/models/definitions/modifiers.js +0 -11
  168. package/lib/models/definitions/options.js +0 -11
  169. package/lib/models/definitions/properties.js +0 -87
  170. package/lib/models/definitions/relations.js +0 -11
  171. package/lib/models/definitions/schema.js +0 -11
  172. package/lib/models/definitions/scopes.js +0 -51
  173. package/lib/models/index.js +0 -50
  174. package/lib/query/QueryBuilder.js +0 -745
  175. package/lib/query/QueryFilters.js +0 -82
  176. package/lib/query/QueryParameters.js +0 -77
  177. package/lib/query/Registry.js +0 -40
  178. package/lib/query/index.js +0 -34
  179. package/lib/schema/formats/_empty.js +0 -10
  180. package/lib/schema/formats/_required.js +0 -10
  181. package/lib/schema/formats/index.js +0 -26
  182. package/lib/schema/index.js +0 -49
  183. package/lib/schema/keywords/_computed.js +0 -11
  184. package/lib/schema/keywords/_foreign.js +0 -11
  185. package/lib/schema/keywords/_hidden.js +0 -11
  186. package/lib/schema/keywords/_index.js +0 -11
  187. package/lib/schema/keywords/_instanceof.js +0 -49
  188. package/lib/schema/keywords/_primary.js +0 -11
  189. package/lib/schema/keywords/_range.js +0 -26
  190. package/lib/schema/keywords/_relate.js +0 -19
  191. package/lib/schema/keywords/_specificType.js +0 -11
  192. package/lib/schema/keywords/_unique.js +0 -11
  193. package/lib/schema/keywords/_unsigned.js +0 -11
  194. package/lib/schema/keywords/_validate.js +0 -80
  195. package/lib/schema/keywords/index.js +0 -106
  196. package/lib/schema/properties.js +0 -227
  197. package/lib/schema/properties.test.js +0 -573
  198. package/lib/schema/relations.js +0 -274
  199. package/lib/schema/relations.test.js +0 -155
  200. package/lib/services/Service.js +0 -34
  201. package/lib/services/index.js +0 -18
  202. package/lib/storage/AssetFile.js +0 -97
  203. package/lib/storage/DiskStorage.js +0 -125
  204. package/lib/storage/S3Storage.js +0 -171
  205. package/lib/storage/Storage.js +0 -209
  206. package/lib/storage/index.js +0 -34
  207. package/lib/utils/decorator.js +0 -16
  208. package/lib/utils/deprecate.js +0 -46
  209. package/lib/utils/emitter.js +0 -13
  210. package/lib/utils/function.js +0 -14
  211. package/lib/utils/function.test.js +0 -49
  212. package/lib/utils/index.js +0 -66
  213. package/lib/utils/json.js +0 -9
  214. package/lib/utils/object.js +0 -92
  215. package/lib/utils/object.test.js +0 -65
  216. package/lib/utils/scope.js +0 -14
@@ -1,15 +1,19 @@
1
1
  import path from 'path'
2
+ import fs from 'fs'
2
3
  import Koa from 'koa'
3
- import mount from 'koa-mount'
4
4
  import serve from 'koa-static'
5
- import koaWebpack from 'koa-webpack'
6
- import historyApiFallback from 'koa-connect-history-api-fallback'
7
- import VueService from '@vue/cli-service'
8
- import HtmlWebpackTagsPlugin from 'html-webpack-tags-plugin'
9
- import { Controller } from './Controller'
10
- import { ControllerError } from '@/errors'
11
- import { formatJson } from '@/utils'
12
- import { isString, isObject } from '@ditojs/utils'
5
+ import { defineConfig, createServer } from 'vite'
6
+ import { createVuePlugin } from 'vite-plugin-vue2'
7
+ import {
8
+ viteCommonjs as createCommonJsPlugin
9
+ } from '@originjs/vite-plugin-commonjs'
10
+ import picomatch from 'picomatch'
11
+ import { findUpSync } from 'find-up'
12
+ import { merge } from '@ditojs/utils'
13
+ import { Controller } from './Controller.js'
14
+ import { handleConnectMiddleware } from '../middleware/index.js'
15
+ import { ControllerError } from '../errors/index.js'
16
+ import { formatJson } from '../utils/index.js'
13
17
 
14
18
  export class AdminController extends Controller {
15
19
  // @override
@@ -67,7 +71,7 @@ export class AdminController extends Controller {
67
71
  // Shield admin views against unauthorized access.
68
72
  const authorization = this.processAuthorize(this.authorize)
69
73
  return async (ctx, next) => {
70
- if (/^\/dito\b/.test(ctx.url)) {
74
+ if (ctx.url === '/dito.js') {
71
75
  // Return without calling `next()`
72
76
  return this.sendDitoObject(ctx)
73
77
  } else if (/\/views\b/.test(ctx.url)) {
@@ -83,178 +87,197 @@ export class AdminController extends Controller {
83
87
  if (this.mode === 'development') {
84
88
  // Calling getPath() throws exception if admin.build.path is not defined:
85
89
  if (this.getPath('build')) {
86
- this.app.once('after:start', () => this.setupKoaWebpack())
90
+ this.app.once('after:start', () => this.setupViteServer())
87
91
  }
88
92
  } else {
89
93
  // Statically serve the pre-built admin SPA. But in order for vue-router
90
- // routes inside the SPA to work, use a tiny rewriting middleware:
94
+ // routes inside the SPA to work for sub-routes, use a tiny rewriting
95
+ // middleware that serves up the `index.html` fur sub-routes:
91
96
  this.koa.use(async (ctx, next) => {
92
- // // Exclude asset requests (css, js, app)
93
- if (!ctx.url.match(/^\/(app\.|css\/|js\/)/)) {
97
+ // // Exclude asset requests (css, js)
98
+ if (!ctx.url.match(/\.(?:css|js)$/)) {
94
99
  ctx.url = '/'
95
100
  }
96
101
  await next()
97
102
  })
98
103
  this.koa.use(serve(this.getPath('dist')))
99
104
  }
100
- return mount(this.url, this.koa)
105
+ return this.koa
101
106
  }
102
107
 
103
- async setupKoaWebpack() {
104
- // https://webpack.js.org/configuration/stats/#stats
105
- const stats = {
106
- all: false,
107
- errors: true,
108
- errorDetails: true
109
- }
110
-
111
- const middleware = await koaWebpack({
112
- config: this.getWebpackConfig(),
113
- devMiddleware: {
114
- publicPath: '/',
115
- stats
116
- },
117
- hotClient: this.config.hotReload !== false && {
118
- // The only way to not log `Failed to parse source map` warnings is
119
- // sadly to ignore all warnings:
120
- // https://github.com/webpack-contrib/webpack-hot-client/issues/94
121
- logLevel: 'error',
122
- stats
108
+ async setupViteServer() {
109
+ const config = this.getViteConfig()
110
+ const server = await createServer({
111
+ ...config,
112
+ server: {
113
+ middlewareMode: 'html',
114
+ watch: {
115
+ // Watch the @ditojs packages while in dev mode, although they are
116
+ // inside the node_modules folder.
117
+ // TODO: This should only really be done if they are symlinked.
118
+ ignored: ['!**/node_modules/@ditojs/**']
119
+ }
123
120
  }
124
121
  })
125
- this.koa.use(historyApiFallback())
126
- this.koa.use(middleware)
122
+ this.koa.use(handleConnectMiddleware(server.middlewares, {
123
+ expandMountPath: true
124
+ }))
127
125
  }
128
126
 
129
- getVueConfig() {
127
+ getViteConfig(config = {}) {
130
128
  const development = this.mode === 'development'
131
- const {
132
- build = {},
133
- devtool = development ? 'source-map' : false
134
- } = this.config
135
- return {
136
- runtimeCompiler: true,
137
- publicPath: `${this.url}/`,
138
- configureWebpack: {
139
- devtool,
140
- // We always need the source build path as entry, even for production,
141
- // for things like .babelrc to work when building for dist:
142
- entry: [this.getPath('build')],
143
- resolve: {
144
- alias: {
145
- // See https://github.com/webpack-contrib/webpack-hot-client/pull/62
146
- 'webpack-hot-client/client':
147
- require.resolve('webpack-hot-client/client')
148
- }
149
- },
150
- output: {
151
- filename: '[name].[hash].js'
152
- },
153
- optimization: {
154
- splitChunks: {
155
- // Split dependencies into two chunks, one for all common libraries,
156
- // and one for all views, so they can be loaded separately, and only
157
- // once authentication was successful.
158
- cacheGroups: {
159
- common: {
160
- name: 'common',
161
- test: /\/node_modules\//,
162
- chunks: 'all'
163
- },
164
- views: {
165
- name: 'views',
166
- test: /\/views\//,
167
- chunks: 'all'
168
- }
129
+
130
+ const cwd = path.resolve('.')
131
+ const root = this.getPath('build')
132
+ const base = `${this.url}/`
133
+ const views = path.join(root, 'views')
134
+
135
+ // Read `package.json` from the closest package.json, so we can emulate
136
+ // ESM-style imports mappings in rollup / vite.
137
+ const pkg = findUpSync('package.json', { cwd: root })
138
+ const { imports } = JSON.parse(fs.readFileSync(pkg, 'utf8'))
139
+
140
+ return defineConfig(merge({
141
+ root,
142
+ base,
143
+ mode: this.mode,
144
+ envFile: false,
145
+ configFile: false,
146
+ plugins: [
147
+ createVuePlugin(),
148
+ createCommonJsPlugin(),
149
+ {
150
+ // Private plugin to inject script tag above main module that loads
151
+ // the `dito` object through its own end-point, see `sendDitoObject()`
152
+ name: 'inject-dito-object',
153
+ transformIndexHtml: {
154
+ enforce: 'post',
155
+ transform(html) {
156
+ return html.replace(
157
+ /(\s*)(<script type="module"[^>]*?><\/script>)/,
158
+ `$1<script src="${base}dito.js"></script>$1$2`
159
+ )
169
160
  }
170
161
  }
171
- },
172
- module: development
173
- // Preserve source-maps in third party dependencies, but do not log
174
- // warnings about dependencies that don't come with source-maps.
175
- // https://webpack.js.org/loaders/source-map-loader/#ignoring-warnings
176
- ? {
177
- rules: [
178
- {
179
- test: /\.(js|css)$/,
180
- enforce: 'pre',
181
- // Use `require.resolve()` here too, to avoid issues similar to
182
- // 'webpack-hot-client/client' above.
183
- use: [require.resolve('source-map-loader')]
162
+ }],
163
+ build: {
164
+ ...(development
165
+ ? {}
166
+ : {
167
+ outDir: this.getPath('dist'),
168
+ assetsDir: '.',
169
+ emptyOutDir: true,
170
+ chunkSizeWarningLimit: 1000,
171
+ rollupOptions: {
172
+ output: {
173
+ manualChunks(id) {
174
+ if (id.startsWith(views)) {
175
+ return 'views'
176
+ } else if (id.startsWith(cwd)) {
177
+ return 'common'
178
+ } else {
179
+ const module = id.match(/node_modules\/([^/$]*)/)?.[1] || ''
180
+ return picomatch.isMatch(module, CORE_DEPENDENCIES)
181
+ ? 'core'
182
+ : 'vendor'
183
+ }
184
+ }
184
185
  }
185
- ]
186
+ }
186
187
  }
187
- : {},
188
- plugins: [
189
- // Use `HtmlWebpackTagsPlugin` plugin to inject a script tag that
190
- // load the dito object from the controller, including `dito.settings`
191
- new HtmlWebpackTagsPlugin({
192
- scripts: ['dito.js'],
193
- useHash: true,
194
- addHash: (path, hash) => path.replace(/\.js$/, `.${hash}.js`),
195
- append: false
196
- })
197
- ],
198
- stats: {
199
- warningsFilter: /Failed to parse source map/
200
- }
188
+ )
201
189
  },
202
-
203
- chainWebpack: conf => {
204
- // Change the location of the HTML template:
205
- const { template = 'index.html' } = build
206
- conf.plugin('html').tap(args => {
207
- args[0].template = /^[./]/.test(template)
208
- ? path.resolve(template)
209
- : path.join(this.getPath('build'), template)
210
- return args
211
- })
212
- if (development) {
213
- // Disable the 'compact' option in babel-loader during development to
214
- // prevent complaints when working with the `yarn watch` versions of
215
- // dito-admin.umd.min.js and dito-ui.umd.min.js
216
- const jsRule = conf.module.rule('js')
217
- const hasBabel = jsRule.toConfig().use?.some(
218
- ({ loader }) => /\bbabel-loader\b/.test(loader)
219
- )
220
- if (hasBabel) {
221
- jsRule.use('babel-loader').options({ compact: false })
190
+ optimizeDeps: {
191
+ exclude: development ? DITO_PACKAGES : [],
192
+ include: [
193
+ ...(development ? [] : DITO_PACKAGES),
194
+ ...NON_ESM_DEPENDENCIES
195
+ ]
196
+ },
197
+ resolve: {
198
+ extensions: ['.js', '.json', '.vue'],
199
+ preserveSymlinks: true,
200
+ alias: [
201
+ {
202
+ find: '@',
203
+ replacement: root
204
+ },
205
+ {
206
+ // Use a custom rollup resolver to emulate ESM-style imports
207
+ // mappings in vite, as read from `package.json` above:
208
+ find: /^#/,
209
+ replacement: '#',
210
+ customResolver(id) {
211
+ for (const [find, replacement] of Object.entries(imports)) {
212
+ picomatch.isMatch(id, find, {
213
+ capture: true,
214
+ onMatch({ input, regex }) {
215
+ const replacementPath = path.resolve(replacement)
216
+ const match = input.match(regex)?.[1]
217
+ id = match
218
+ ? replacementPath.replace('*', match)
219
+ : replacementPath
220
+ }
221
+ })
222
+ }
223
+ return id
224
+ }
222
225
  }
223
- // Make `stats.warningsFilter` work, see:
224
- // https://forum.vuejs.org/t/sppress-warnings-in-vue-cli-3/45905/4
225
- conf.plugins.delete('friendly-errors')
226
- }
226
+ ]
227
227
  }
228
- }
228
+ }, config))
229
229
  }
230
+ }
230
231
 
231
- getVuePlugins() {
232
- return this.config.plugins?.map(definition => {
233
- const plugin = isString(definition)
234
- ? { id: definition }
235
- : isObject(definition)
236
- ? definition
237
- : {}
238
- const {
239
- id,
240
- apply = require(id)
241
- } = plugin
242
- if (!id) {
243
- throw new ControllerError(
244
- this,
245
- `Invalid plugin definition: ${definition}`
246
- )
247
- }
248
- return { id, apply }
249
- })
250
- }
232
+ const DITO_PACKAGES = [
233
+ '@ditojs/admin',
234
+ '@ditojs/ui',
235
+ '@ditojs/utils'
236
+ ]
251
237
 
252
- getWebpackConfig() {
253
- const service = new VueService(this.getPath('build'), {
254
- inlineOptions: this.getVueConfig(),
255
- plugins: this.getVuePlugins()
256
- })
257
- service.init(this.mode)
258
- return service.resolveWebpackConfig()
259
- }
260
- }
238
+ const NON_ESM_DEPENDENCIES = [
239
+ // All non-es modules need to be explicitly included here, and some of
240
+ // them only work due to the use of `createCommonJsPlugin()`.
241
+ 'vue-color',
242
+ 'vue-js-modal',
243
+ 'vue-multiselect',
244
+ 'vue-notification',
245
+ 'lowlight'
246
+ ]
247
+
248
+ const CORE_DEPENDENCIES = [
249
+ ...DITO_PACKAGES,
250
+
251
+ // TODO: Figure out a way to generate this automatically for the current
252
+ // dito-admin dependencies, e.g. similar to
253
+ // `getRollupExternalsFromDependencies()`, perhaps as a script to persist to
254
+ // a json file?
255
+
256
+ 'vue',
257
+ 'vue-color',
258
+ 'vue-js-modal',
259
+ 'vue-multiselect',
260
+ 'vue-notification',
261
+ 'vue-router',
262
+ 'vue-upload-component',
263
+ 'vuedraggable',
264
+
265
+ 'axios',
266
+ 'core-js',
267
+ 'lowlight',
268
+ 'sortablejs',
269
+ 'tiptap',
270
+ 'tiptap-*',
271
+ 'tslib',
272
+ 'prosemirror-*',
273
+ 'codeflask',
274
+ 'rope-sequence',
275
+ 'tinycolor2',
276
+ 'fault',
277
+ 'filesize',
278
+ 'filesize-parser',
279
+ 'format',
280
+ 'highlight.js',
281
+ 'orderedmap',
282
+ 'w3c-keyname'
283
+ ]
@@ -1,6 +1,6 @@
1
- import { Controller } from './Controller'
2
- import { ControllerError } from '@/errors'
3
1
  import { isObject, isArray, asArray } from '@ditojs/utils'
2
+ import { Controller } from './Controller.js'
3
+ import { ControllerError } from '../errors/index.js'
4
4
 
5
5
  // Abstract base class for ModelController and RelationController
6
6
  export class CollectionController extends Controller {
@@ -25,19 +25,6 @@ export class CollectionController extends Controller {
25
25
  this.idValidator = new this.modelClass()
26
26
  }
27
27
 
28
- // @override
29
- setupAction(type, actions, name, handler, authorize, verb, path) {
30
- // These default actions happen directly on the collection / member route
31
- // and are distinguished by their verbs, not by nested paths.
32
- if (name in actionToVerb) {
33
- verb = actionToVerb[name]
34
- path = ''
35
- }
36
- return super.setupAction(
37
- type, actions, name, handler, authorize, verb, path
38
- )
39
- }
40
-
41
28
  // @override
42
29
  setupAssets() {
43
30
  const { modelClass } = this
@@ -120,7 +107,7 @@ export class CollectionController extends Controller {
120
107
  base = this,
121
108
  { query = {}, modify = null, forUpdate = false } = {}
122
109
  ) {
123
- return this.member.find.call(
110
+ return this.member.get.call(
124
111
  this,
125
112
  // Extend `ctx` with a new `query` object, while inheriting the route
126
113
  // params in `ctx.params`, so fining the member by id still works.
@@ -202,7 +189,7 @@ export class CollectionController extends Controller {
202
189
  }
203
190
 
204
191
  collection = this.toCoreActions({
205
- async find(ctx, modify) {
192
+ async get(ctx, modify) {
206
193
  const result = await this.execute(ctx, (query, trx) => {
207
194
  query.find(ctx.query, this.allowParam).modify(getModify(modify, trx))
208
195
  return this.isOneToOne ? query.first() : query
@@ -224,7 +211,7 @@ export class CollectionController extends Controller {
224
211
  return { count }
225
212
  },
226
213
 
227
- async insert(ctx, modify) {
214
+ async post(ctx, modify) {
228
215
  const result = this.relate
229
216
  // Use patchDitoGraphAndFetch() to handle relates for us.
230
217
  ? await this.execute(ctx, (query, trx) => query
@@ -239,7 +226,7 @@ export class CollectionController extends Controller {
239
226
  return result
240
227
  },
241
228
 
242
- async update(ctx, modify) {
229
+ async put(ctx, modify) {
243
230
  return this.executeAndFetch('update', ctx, modify)
244
231
  },
245
232
 
@@ -249,7 +236,7 @@ export class CollectionController extends Controller {
249
236
  })
250
237
 
251
238
  member = this.toCoreActions({
252
- async find(ctx, modify) {
239
+ async get(ctx, modify) {
253
240
  return this.execute(ctx, (query, trx) => query
254
241
  .findById(ctx.memberId)
255
242
  .find(ctx.query, this.allowParam)
@@ -270,7 +257,7 @@ export class CollectionController extends Controller {
270
257
  return { count }
271
258
  },
272
259
 
273
- async update(ctx, modify) {
260
+ async put(ctx, modify) {
274
261
  return this.executeAndFetchById('update', ctx, modify)
275
262
  },
276
263
 
@@ -285,11 +272,3 @@ function getModify(modify, trx) {
285
272
  ? query => modify(query, trx)
286
273
  : null
287
274
  }
288
-
289
- const actionToVerb = {
290
- find: 'get',
291
- delete: 'delete',
292
- insert: 'post',
293
- update: 'put',
294
- patch: 'patch'
295
- }