@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,66 +1,66 @@
|
|
|
1
|
-
import Registry from './Registry'
|
|
2
|
-
import { parameters } from '@/decorators'
|
|
3
|
-
|
|
1
|
+
import Registry from './Registry.js'
|
|
4
2
|
export const QueryFilters = new Registry()
|
|
5
3
|
|
|
6
4
|
QueryFilters.register({
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
'text': {
|
|
6
|
+
parameters: {
|
|
7
|
+
operator: {
|
|
8
|
+
type: 'string'
|
|
9
|
+
},
|
|
10
|
+
text: {
|
|
11
|
+
type: 'string'
|
|
12
|
+
}
|
|
11
13
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (query.isPostgreSQL()) {
|
|
32
|
-
query.where(property, 'ILIKE', operand)
|
|
33
|
-
} else {
|
|
34
|
-
query.whereRaw(
|
|
14
|
+
|
|
15
|
+
handler(query, property, { operator, text }) {
|
|
16
|
+
if (text === undefined) {
|
|
17
|
+
text = operator
|
|
18
|
+
operator = 'contains'
|
|
19
|
+
}
|
|
20
|
+
const templates = {
|
|
21
|
+
'equals': text => text,
|
|
22
|
+
'contains': text => `%${text}%`,
|
|
23
|
+
'starts-with': text => `${text}%`,
|
|
24
|
+
'ends-with': text => `%${text}`
|
|
25
|
+
}
|
|
26
|
+
if (text) {
|
|
27
|
+
const operand = templates[operator]?.(text)
|
|
28
|
+
if (operand) {
|
|
29
|
+
if (query.isPostgreSQL()) {
|
|
30
|
+
query.where(property, 'ILIKE', operand)
|
|
31
|
+
} else {
|
|
32
|
+
query.whereRaw(
|
|
35
33
|
`LOWER(??) LIKE ?`,
|
|
36
34
|
[property, operand.toLowerCase()]
|
|
37
|
-
|
|
35
|
+
)
|
|
36
|
+
}
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
},
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
'date-range': {
|
|
43
|
+
parameters: {
|
|
44
|
+
from: {
|
|
45
|
+
type: 'datetime',
|
|
46
|
+
nullable: true
|
|
47
|
+
},
|
|
48
|
+
to: {
|
|
49
|
+
type: 'datetime',
|
|
50
|
+
nullable: true
|
|
51
|
+
}
|
|
48
52
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} else if (from) {
|
|
59
|
-
query.where(property, '>=', new Date(from))
|
|
60
|
-
} else if (to) {
|
|
61
|
-
query.where(property, '<=', new Date(to))
|
|
62
|
-
} else {
|
|
53
|
+
|
|
54
|
+
handler(query, property, { from, to }) {
|
|
55
|
+
if (from && to) {
|
|
56
|
+
query.whereBetween(property, [new Date(from), new Date(to)])
|
|
57
|
+
} else if (from) {
|
|
58
|
+
query.where(property, '>=', new Date(from))
|
|
59
|
+
} else if (to) {
|
|
60
|
+
query.where(property, '<=', new Date(to))
|
|
61
|
+
} else {
|
|
63
62
|
// TODO: Can we get validation to catch the case where both are empty?
|
|
63
|
+
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ResponseError, QueryBuilderError } from '@/errors'
|
|
2
1
|
import { isString, asArray } from '@ditojs/utils'
|
|
3
|
-
import Registry from './Registry'
|
|
2
|
+
import Registry from './Registry.js'
|
|
3
|
+
import { ResponseError, QueryBuilderError } from '../errors/index.js'
|
|
4
4
|
|
|
5
5
|
export const QueryParameters = new Registry()
|
|
6
6
|
|
package/src/query/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './QueryBuilder'
|
|
2
|
-
export * from './QueryFilters'
|
|
3
|
-
export * from './QueryParameters'
|
|
1
|
+
export * from './QueryBuilder.js'
|
|
2
|
+
export * from './QueryFilters.js'
|
|
3
|
+
export * from './QueryParameters.js'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './_empty'
|
|
2
|
-
export * from './_required'
|
|
1
|
+
export * from './_empty.js'
|
|
2
|
+
export * from './_required.js'
|
package/src/schema/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * as keywords from './keywords'
|
|
2
|
-
export * as formats from './formats'
|
|
3
|
-
export * from './properties'
|
|
4
|
-
export * from './relations'
|
|
1
|
+
export * as keywords from './keywords/index.js'
|
|
2
|
+
export * as formats from './formats/index.js'
|
|
3
|
+
export * from './properties.js'
|
|
4
|
+
export * from './relations.js'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from './_specificType'
|
|
2
|
-
export * from './_primary'
|
|
3
|
-
export * from './_foreign'
|
|
4
|
-
export * from './_unique'
|
|
5
|
-
export * from './_index'
|
|
6
|
-
export * from './_computed'
|
|
7
|
-
export * from './_hidden'
|
|
8
|
-
export * from './_unsigned'
|
|
9
|
-
export * from './_instanceof'
|
|
10
|
-
export * from './_validate'
|
|
11
|
-
export * from './_relate'
|
|
12
|
-
export * from './_range'
|
|
1
|
+
export * from './_specificType.js'
|
|
2
|
+
export * from './_primary.js'
|
|
3
|
+
export * from './_foreign.js'
|
|
4
|
+
export * from './_unique.js'
|
|
5
|
+
export * from './_index.js'
|
|
6
|
+
export * from './_computed.js'
|
|
7
|
+
export * from './_hidden.js'
|
|
8
|
+
export * from './_unsigned.js'
|
|
9
|
+
export * from './_instanceof.js'
|
|
10
|
+
export * from './_validate.js'
|
|
11
|
+
export * from './_relate.js'
|
|
12
|
+
export * from './_range.js'
|
package/src/schema/relations.js
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
HasManyRelation,
|
|
7
7
|
ManyToManyRelation
|
|
8
8
|
} from 'objection'
|
|
9
|
-
import { RelationError } from '@/errors'
|
|
10
9
|
import {
|
|
11
10
|
isObject, isArray, isString, asArray, capitalize, camelize
|
|
12
11
|
} from '@ditojs/utils'
|
|
12
|
+
import { RelationError } from '../errors/index.js'
|
|
13
13
|
|
|
14
14
|
const relationLookup = {
|
|
15
15
|
// one:
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
HasManyRelation,
|
|
6
6
|
ManyToManyRelation
|
|
7
7
|
} from 'objection'
|
|
8
|
-
import { Model } from '
|
|
8
|
+
import { Model } from '../models.js'
|
|
9
9
|
import {
|
|
10
10
|
getRelationClass, convertRelation, addRelationSchemas
|
|
11
|
-
} from './relations'
|
|
11
|
+
} from './relations.js'
|
|
12
12
|
|
|
13
13
|
describe('getRelationClass()', () => {
|
|
14
14
|
it('returns the corresponding relation classes', () => {
|
package/src/services/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Service'
|
|
1
|
+
export * from './Service.js'
|
package/src/storage/S3Storage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import aws from 'aws-sdk'
|
|
2
2
|
import multerS3 from 'multer-s3'
|
|
3
|
-
import
|
|
3
|
+
import { fileTypeFromBuffer } from 'file-type'
|
|
4
4
|
import isSvg from 'is-svg'
|
|
5
|
-
import { Storage } from './Storage'
|
|
5
|
+
import { Storage } from './Storage.js'
|
|
6
6
|
import { PassThrough } from 'stream'
|
|
7
7
|
|
|
8
8
|
export class S3Storage extends Storage {
|
|
@@ -49,7 +49,7 @@ export class S3Storage extends Storage {
|
|
|
49
49
|
const onData = chunk => {
|
|
50
50
|
if (!data) {
|
|
51
51
|
// 2. Try reading the mimetype from the first chunk.
|
|
52
|
-
const type =
|
|
52
|
+
const type = fileTypeFromBuffer(chunk)?.mime
|
|
53
53
|
if (type) {
|
|
54
54
|
stream.off('data', onData)
|
|
55
55
|
done(type)
|
|
@@ -58,7 +58,7 @@ export class S3Storage extends Storage {
|
|
|
58
58
|
// the mimetype using the full data.
|
|
59
59
|
stream.once('end', () => {
|
|
60
60
|
const type = (
|
|
61
|
-
|
|
61
|
+
fileTypeFromBuffer(data)?.mime ||
|
|
62
62
|
(isSvg(data) ? 'image/svg+xml' : 'application/octet-stream')
|
|
63
63
|
)
|
|
64
64
|
done(type)
|
package/src/storage/Storage.js
CHANGED
|
@@ -4,7 +4,7 @@ import imageSize from 'image-size'
|
|
|
4
4
|
import { PassThrough } from 'stream'
|
|
5
5
|
import { URL } from 'url'
|
|
6
6
|
import { hyphenate, toPromiseCallback } from '@ditojs/utils'
|
|
7
|
-
import { AssetFile } from './AssetFile'
|
|
7
|
+
import { AssetFile } from './AssetFile.js'
|
|
8
8
|
|
|
9
9
|
const storageClasses = {}
|
|
10
10
|
|
package/src/storage/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Storage } from './Storage'
|
|
2
|
-
import { DiskStorage } from './DiskStorage'
|
|
3
|
-
import { S3Storage } from './S3Storage'
|
|
1
|
+
import { Storage } from './Storage.js'
|
|
2
|
+
import { DiskStorage } from './DiskStorage.js'
|
|
3
|
+
import { S3Storage } from './S3Storage.js'
|
|
4
4
|
|
|
5
5
|
Storage.register(DiskStorage)
|
|
6
6
|
Storage.register(S3Storage)
|
|
7
7
|
|
|
8
|
-
export * from './AssetFile'
|
|
8
|
+
export * from './AssetFile.js'
|
|
9
9
|
export { Storage }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { asArray } from '@ditojs/utils'
|
|
2
|
+
|
|
3
|
+
export function processHandlerParameters(handler, name, value) {
|
|
4
|
+
if (value) {
|
|
5
|
+
const [schema, options] = asArray(value)
|
|
6
|
+
handler[name] = schema
|
|
7
|
+
|
|
8
|
+
// If validation options are provided, expose them through
|
|
9
|
+
// `handler.options[name]`, see `ControllerAction`.
|
|
10
|
+
if (options) {
|
|
11
|
+
handler.options = {
|
|
12
|
+
...handler.options,
|
|
13
|
+
[name]: options
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/utils/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export * from './decorator'
|
|
2
|
-
export * from './deprecate'
|
|
3
|
-
export * from './emitter'
|
|
4
|
-
export * from './function'
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
1
|
+
export * from './decorator.js'
|
|
2
|
+
export * from './deprecate.js'
|
|
3
|
+
export * from './emitter.js'
|
|
4
|
+
export * from './function.js'
|
|
5
|
+
export * from './handler.js'
|
|
6
|
+
export * from './json.js'
|
|
7
|
+
export * from './object.js'
|
|
8
|
+
export * from './scope.js'
|