@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.
- package/package.json +25 -43
- package/src/app/Application.js +105 -111
- package/src/app/Validator.js +6 -3
- package/src/app/index.js +2 -2
- package/src/cli/db/createMigration.js +1 -1
- package/src/cli/db/index.js +7 -7
- package/src/cli/db/listAssetConfig.js +1 -1
- package/src/cli/db/reset.js +1 -1
- package/src/cli/index.js +14 -5
- package/src/controllers/AdminController.js +181 -158
- package/src/controllers/CollectionController.js +8 -29
- package/src/controllers/Controller.js +71 -76
- package/src/controllers/ControllerAction.js +39 -17
- package/src/controllers/MemberAction.js +2 -2
- package/src/controllers/ModelController.js +4 -4
- package/src/controllers/RelationController.js +3 -3
- package/src/controllers/{UserController.js → UsersController.js} +8 -13
- package/src/controllers/index.js +5 -5
- package/src/decorators/action.js +3 -3
- package/src/decorators/authorize.js +1 -1
- package/src/decorators/index.js +6 -6
- package/src/decorators/parameters.js +1 -1
- package/src/decorators/returns.js +1 -1
- package/src/decorators/scope.js +1 -1
- package/src/decorators/transacted.js +1 -1
- package/src/errors/AssetError.js +1 -1
- package/src/errors/AuthenticationError.js +1 -1
- package/src/errors/AuthorizationError.js +1 -1
- package/src/errors/ControllerError.js +1 -1
- package/src/errors/DatabaseError.js +12 -3
- package/src/errors/GraphError.js +1 -1
- package/src/errors/ModelError.js +1 -1
- package/src/errors/NotFoundError.js +1 -1
- package/src/errors/NotImplementedError.js +1 -1
- package/src/errors/QueryBuilderError.js +1 -1
- package/src/errors/RelationError.js +1 -1
- package/src/errors/ValidationError.js +1 -1
- package/src/errors/WrappedError.js +1 -1
- package/src/errors/index.js +14 -14
- package/src/graph/DitoGraphProcessor.js +2 -1
- package/src/graph/graph.js +1 -1
- package/src/graph/index.js +3 -3
- package/src/index.js +11 -9
- package/src/lib/index.js +2 -2
- package/src/middleware/createTransaction.js +1 -1
- package/src/middleware/findRoute.js +3 -2
- package/src/middleware/handleConnectMiddleware.js +88 -0
- package/src/middleware/handleError.js +1 -1
- package/src/middleware/handleRoute.js +3 -3
- package/src/middleware/index.js +8 -7
- package/src/mixins/AssetMixin.js +1 -1
- package/src/mixins/UserMixin.js +1 -1
- package/src/mixins/index.js +4 -4
- package/src/models/AssetModel.js +2 -2
- package/src/models/Model.js +16 -12
- package/src/models/RelationAccessor.js +1 -1
- package/src/models/SessionModel.js +2 -2
- package/src/models/TimeStampedModel.js +2 -2
- package/src/models/UserModel.js +2 -2
- package/src/models/definitions/assets.js +1 -1
- package/src/models/definitions/filters.js +57 -44
- package/src/models/definitions/hooks.js +1 -1
- package/src/models/definitions/index.js +9 -9
- package/src/models/definitions/modifiers.js +1 -1
- package/src/models/definitions/options.js +1 -1
- package/src/models/definitions/properties.js +2 -2
- package/src/models/definitions/relations.js +1 -1
- package/src/models/definitions/schema.js +1 -1
- package/src/models/definitions/scopes.js +2 -2
- package/src/models/index.js +5 -5
- package/src/query/QueryBuilder.js +5 -5
- package/src/query/QueryFilters.js +50 -50
- package/src/query/QueryParameters.js +2 -2
- package/src/query/index.js +3 -3
- package/src/schema/formats/index.js +2 -2
- package/src/schema/index.js +4 -4
- package/src/schema/keywords/_relate.js +1 -1
- package/src/schema/keywords/index.js +12 -12
- package/src/schema/properties.test.js +1 -1
- package/src/schema/relations.js +1 -1
- package/src/schema/relations.test.js +2 -2
- package/src/services/index.js +1 -1
- package/src/storage/DiskStorage.js +1 -1
- package/src/storage/S3Storage.js +4 -4
- package/src/storage/Storage.js +1 -1
- package/src/storage/index.js +4 -4
- package/src/utils/function.test.js +1 -1
- package/src/utils/handler.js +17 -0
- package/src/utils/index.js +8 -7
- package/src/utils/object.test.js +1 -1
- package/lib/app/Application.js +0 -961
- package/lib/app/SessionStore.js +0 -40
- package/lib/app/Validator.js +0 -355
- package/lib/app/index.js +0 -26
- package/lib/cli/console.js +0 -175
- package/lib/cli/db/createMigration.js +0 -237
- package/lib/cli/db/index.js +0 -66
- package/lib/cli/db/listAssetConfig.js +0 -16
- package/lib/cli/db/migrate.js +0 -15
- package/lib/cli/db/reset.js +0 -27
- package/lib/cli/db/rollback.js +0 -15
- package/lib/cli/db/seed.js +0 -104
- package/lib/cli/db/unlock.js +0 -15
- package/lib/cli/index.js +0 -90
- package/lib/controllers/AdminController.js +0 -258
- package/lib/controllers/CollectionController.js +0 -263
- package/lib/controllers/Controller.js +0 -462
- package/lib/controllers/ControllerAction.js +0 -276
- package/lib/controllers/MemberAction.js +0 -22
- package/lib/controllers/ModelController.js +0 -64
- package/lib/controllers/RelationController.js +0 -82
- package/lib/controllers/UserController.js +0 -98
- package/lib/controllers/index.js +0 -50
- package/lib/decorators/action.js +0 -14
- package/lib/decorators/authorize.js +0 -13
- package/lib/decorators/index.js +0 -58
- package/lib/decorators/parameters.js +0 -35
- package/lib/decorators/returns.js +0 -26
- package/lib/decorators/scope.js +0 -14
- package/lib/decorators/transacted.js +0 -12
- package/lib/errors/AssetError.js +0 -19
- package/lib/errors/AuthenticationError.js +0 -19
- package/lib/errors/AuthorizationError.js +0 -19
- package/lib/errors/ControllerError.js +0 -24
- package/lib/errors/DatabaseError.js +0 -27
- package/lib/errors/GraphError.js +0 -19
- package/lib/errors/ModelError.js +0 -24
- package/lib/errors/NotFoundError.js +0 -19
- package/lib/errors/NotImplementedError.js +0 -19
- package/lib/errors/QueryBuilderError.js +0 -19
- package/lib/errors/RelationError.js +0 -36
- package/lib/errors/ResponseError.js +0 -46
- package/lib/errors/ValidationError.js +0 -19
- package/lib/errors/WrappedError.js +0 -24
- package/lib/errors/index.js +0 -122
- package/lib/graph/DitoGraphProcessor.js +0 -185
- package/lib/graph/expression.js +0 -76
- package/lib/graph/graph.js +0 -300
- package/lib/graph/index.js +0 -34
- package/lib/index.js +0 -82
- package/lib/lib/EventEmitter.js +0 -76
- package/lib/lib/KnexHelper.js +0 -40
- package/lib/lib/index.js +0 -26
- package/lib/middleware/attachLogger.js +0 -16
- package/lib/middleware/createTransaction.js +0 -36
- package/lib/middleware/findRoute.js +0 -35
- package/lib/middleware/handleError.js +0 -26
- package/lib/middleware/handleRoute.js +0 -29
- package/lib/middleware/handleUser.js +0 -36
- package/lib/middleware/index.js +0 -66
- package/lib/middleware/logRequests.js +0 -122
- package/lib/mixins/AssetMixin.js +0 -81
- package/lib/mixins/SessionMixin.js +0 -22
- package/lib/mixins/TimeStampedMixin.js +0 -47
- package/lib/mixins/UserMixin.js +0 -151
- package/lib/mixins/index.js +0 -42
- package/lib/models/AssetModel.js +0 -12
- package/lib/models/Model.js +0 -953
- package/lib/models/RelationAccessor.js +0 -41
- package/lib/models/SessionModel.js +0 -12
- package/lib/models/TimeStampedModel.js +0 -12
- package/lib/models/UserModel.js +0 -12
- package/lib/models/definitions/assets.js +0 -11
- package/lib/models/definitions/filters.js +0 -101
- package/lib/models/definitions/hooks.js +0 -11
- package/lib/models/definitions/index.js +0 -38
- package/lib/models/definitions/modifiers.js +0 -11
- package/lib/models/definitions/options.js +0 -11
- package/lib/models/definitions/properties.js +0 -87
- package/lib/models/definitions/relations.js +0 -11
- package/lib/models/definitions/schema.js +0 -11
- package/lib/models/definitions/scopes.js +0 -51
- package/lib/models/index.js +0 -50
- package/lib/query/QueryBuilder.js +0 -745
- package/lib/query/QueryFilters.js +0 -82
- package/lib/query/QueryParameters.js +0 -77
- package/lib/query/Registry.js +0 -40
- package/lib/query/index.js +0 -34
- package/lib/schema/formats/_empty.js +0 -10
- package/lib/schema/formats/_required.js +0 -10
- package/lib/schema/formats/index.js +0 -26
- package/lib/schema/index.js +0 -49
- package/lib/schema/keywords/_computed.js +0 -11
- package/lib/schema/keywords/_foreign.js +0 -11
- package/lib/schema/keywords/_hidden.js +0 -11
- package/lib/schema/keywords/_index.js +0 -11
- package/lib/schema/keywords/_instanceof.js +0 -49
- package/lib/schema/keywords/_primary.js +0 -11
- package/lib/schema/keywords/_range.js +0 -26
- package/lib/schema/keywords/_relate.js +0 -19
- package/lib/schema/keywords/_specificType.js +0 -11
- package/lib/schema/keywords/_unique.js +0 -11
- package/lib/schema/keywords/_unsigned.js +0 -11
- package/lib/schema/keywords/_validate.js +0 -80
- package/lib/schema/keywords/index.js +0 -106
- package/lib/schema/properties.js +0 -227
- package/lib/schema/properties.test.js +0 -573
- package/lib/schema/relations.js +0 -274
- package/lib/schema/relations.test.js +0 -155
- package/lib/services/Service.js +0 -34
- package/lib/services/index.js +0 -18
- package/lib/storage/AssetFile.js +0 -97
- package/lib/storage/DiskStorage.js +0 -125
- package/lib/storage/S3Storage.js +0 -171
- package/lib/storage/Storage.js +0 -209
- package/lib/storage/index.js +0 -34
- package/lib/utils/decorator.js +0 -16
- package/lib/utils/deprecate.js +0 -46
- package/lib/utils/emitter.js +0 -13
- package/lib/utils/function.js +0 -14
- package/lib/utils/function.test.js +0 -49
- package/lib/utils/index.js +0 -66
- package/lib/utils/json.js +0 -9
- package/lib/utils/object.js +0 -92
- package/lib/utils/object.test.js +0 -65
- 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
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
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 (
|
|
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.
|
|
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
|
|
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
|
|
93
|
-
if (!ctx.url.match(
|
|
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
|
|
105
|
+
return this.koa
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
async
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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(
|
|
126
|
-
|
|
122
|
+
this.koa.use(handleConnectMiddleware(server.middlewares, {
|
|
123
|
+
expandMountPath: true
|
|
124
|
+
}))
|
|
127
125
|
}
|
|
128
126
|
|
|
129
|
-
|
|
127
|
+
getViteConfig(config = {}) {
|
|
130
128
|
const development = this.mode === 'development'
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
}
|