expressa 1.2.4 → 1.2.5
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/listeners.js +64 -59
- package/package.json +1 -1
package/listeners.js
CHANGED
|
@@ -1,59 +1,64 @@
|
|
|
1
|
-
const debug = require('debug')('expressa')
|
|
2
|
-
const util = require('./util')
|
|
3
|
-
|
|
4
|
-
module.exports = function (api) {
|
|
5
|
-
/* Listeners to avoid the need for a server restart */
|
|
6
|
-
api.addCollectionListener('changed', 'collection', async function setupCollectionStorage (req, collection, data) {
|
|
7
|
-
if (!(data.storage === 'memory' && util.getPath(api.db[data._id], 'type') === 'memory')) {
|
|
8
|
-
await api.setupCollectionDb(data)
|
|
9
|
-
}
|
|
10
|
-
debug('updated ' + data._id + ' collection storage')
|
|
11
|
-
})
|
|
12
|
-
api.addCollectionListener('delete', 'collection', function cleanupCollectionStorage (req, collection, data) {
|
|
13
|
-
delete api.db[data._id]
|
|
14
|
-
debug('removed ' + data._id + ' collection storage')
|
|
15
|
-
})
|
|
16
|
-
api.addCollectionListener('changed', 'settings', function updateInMemorySettings (req, collection, data) {
|
|
17
|
-
// TODO: only reload if current environment is updated
|
|
18
|
-
Object.assign(req.settings, data)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
api.addListener(['put', 'post'], function updateMetadata (req, collection, data, { event }) {
|
|
22
|
-
data.meta = data.meta || {}
|
|
23
|
-
data.meta.updated = new Date().toISOString()
|
|
24
|
-
if (event === 'post') {
|
|
25
|
-
data.meta.created = new Date().toISOString()
|
|
26
|
-
if (req.user) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
1
|
+
const debug = require('debug')('expressa')
|
|
2
|
+
const util = require('./util')
|
|
3
|
+
|
|
4
|
+
module.exports = function (api) {
|
|
5
|
+
/* Listeners to avoid the need for a server restart */
|
|
6
|
+
api.addCollectionListener('changed', 'collection', async function setupCollectionStorage (req, collection, data) {
|
|
7
|
+
if (!(data.storage === 'memory' && util.getPath(api.db[data._id], 'type') === 'memory')) {
|
|
8
|
+
await api.setupCollectionDb(data)
|
|
9
|
+
}
|
|
10
|
+
debug('updated ' + data._id + ' collection storage')
|
|
11
|
+
})
|
|
12
|
+
api.addCollectionListener('delete', 'collection', function cleanupCollectionStorage (req, collection, data) {
|
|
13
|
+
delete api.db[data._id]
|
|
14
|
+
debug('removed ' + data._id + ' collection storage')
|
|
15
|
+
})
|
|
16
|
+
api.addCollectionListener('changed', 'settings', function updateInMemorySettings (req, collection, data) {
|
|
17
|
+
// TODO: only reload if current environment is updated
|
|
18
|
+
Object.assign(req.settings, data)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
api.addListener(['put', 'post'], function updateMetadata (req, collection, data, { event }) {
|
|
22
|
+
data.meta = data.meta || {}
|
|
23
|
+
data.meta.updated = new Date().toISOString()
|
|
24
|
+
if (event === 'post') {
|
|
25
|
+
data.meta.created = new Date().toISOString()
|
|
26
|
+
if (req.user) {
|
|
27
|
+
if (req.hasPermission('login to admin')) {
|
|
28
|
+
data.meta.owner = data.meta.owner || req.user._id
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
data.meta.owner = req.user._id
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
api.addCollectionListener('get', 'schemas', function addMetaToSchema (req, collection, data) {
|
|
38
|
+
const schema = data.schema
|
|
39
|
+
schema.properties.meta = {
|
|
40
|
+
type: 'object',
|
|
41
|
+
propertyOrder: 2000,
|
|
42
|
+
properties: {
|
|
43
|
+
created: {
|
|
44
|
+
type: 'string'
|
|
45
|
+
},
|
|
46
|
+
updated: {
|
|
47
|
+
type: 'string'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (data.documentsHaveOwners) {
|
|
52
|
+
schema.properties.meta.properties.owner = {
|
|
53
|
+
type: 'string',
|
|
54
|
+
links: [
|
|
55
|
+
{
|
|
56
|
+
rel: '» view owner user',
|
|
57
|
+
href: '/admin/#/edit/users/{{self}}',
|
|
58
|
+
class: 'comment-link'
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|