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.
Files changed (2) hide show
  1. package/listeners.js +64 -59
  2. 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
- data.meta.owner = req.user._id
28
- }
29
- }
30
- })
31
-
32
- api.addCollectionListener('get', 'schemas', function addMetaToSchema (req, collection, data) {
33
- const schema = data.schema
34
- schema.properties.meta = {
35
- type: 'object',
36
- propertyOrder: 2000,
37
- properties: {
38
- created: {
39
- type: 'string'
40
- },
41
- updated: {
42
- type: 'string'
43
- }
44
- }
45
- }
46
- if (data.documentsHaveOwners) {
47
- schema.properties.meta.properties.owner = {
48
- type: 'string',
49
- links: [
50
- {
51
- rel: view owner user',
52
- href: '/admin/#/edit/users/{{self}}',
53
- class: 'comment-link'
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expressa",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "API framework using JSON schemas",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/thomas4019/expressa",