amphora 8.0.0 → 8.3.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/.circleci/config.yml +0 -1
- package/lib/render.js +6 -2
- package/lib/render.test.js +3 -0
- package/lib/services/db-operations.js +28 -2
- package/lib/services/layouts.js +9 -4
- package/lib/services/pages.js +8 -4
- package/package.json +1 -1
package/.circleci/config.yml
CHANGED
package/lib/render.js
CHANGED
|
@@ -87,8 +87,12 @@ function renderComponent(req, res, hrStart) {
|
|
|
87
87
|
return components.get(_ref, locals)
|
|
88
88
|
.then(cmptData => formDataForRenderer(cmptData, { _ref }, locals))
|
|
89
89
|
.tap(logTime(hrStart, _ref))
|
|
90
|
-
.then(({data, options}) => renderer.render(data, options, res))
|
|
91
|
-
.catch(err =>
|
|
90
|
+
.then(({ data, options }) => renderer.render(data, options, res))
|
|
91
|
+
.catch(err => {
|
|
92
|
+
log('error', err, { url: _.get(res, 'locals.url') });
|
|
93
|
+
|
|
94
|
+
return responses.handleError(res)(err);
|
|
95
|
+
});
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
/**
|
package/lib/render.test.js
CHANGED
|
@@ -7,6 +7,7 @@ const _ = require('lodash'),
|
|
|
7
7
|
expect = require('chai').expect,
|
|
8
8
|
sinon = require('sinon'),
|
|
9
9
|
schema = require('./schema'),
|
|
10
|
+
responses = require('./responses'),
|
|
10
11
|
components = require('./services/components'),
|
|
11
12
|
composer = require('./services/composer'),
|
|
12
13
|
createMockReq = require('../test/fixtures/mocks/req'),
|
|
@@ -81,6 +82,7 @@ describe(_.startCase(filename), function () {
|
|
|
81
82
|
sandbox.stub(components);
|
|
82
83
|
sandbox.stub(composer);
|
|
83
84
|
sandbox.stub(schema);
|
|
85
|
+
sandbox.stub(responses, 'handleError').returns(() => {});
|
|
84
86
|
lib.setLog(mockLog);
|
|
85
87
|
lib.resetUriRouteHandlers();
|
|
86
88
|
lib.registerRenderers({
|
|
@@ -177,6 +179,7 @@ describe(_.startCase(filename), function () {
|
|
|
177
179
|
return fn(req, getMockRes())
|
|
178
180
|
.then(() => {
|
|
179
181
|
sinon.assert.calledWith(mockLog, 'error', error);
|
|
182
|
+
sinon.assert.calledOnce(responses.handleError);
|
|
180
183
|
lib.registerRenderers(undefined);
|
|
181
184
|
});
|
|
182
185
|
});
|
|
@@ -80,6 +80,30 @@ function splitCascadingData(uri, data) {
|
|
|
80
80
|
return ops;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Adds user info onto each op object
|
|
85
|
+
*
|
|
86
|
+
* @param {Object} locals
|
|
87
|
+
* @param {Object} locals.user
|
|
88
|
+
* @returns {Function}
|
|
89
|
+
*/
|
|
90
|
+
function addUserInfoToOp(locals) {
|
|
91
|
+
if (!locals) {
|
|
92
|
+
return _.identity;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { user } = locals;
|
|
96
|
+
|
|
97
|
+
function addUserProp(op) {
|
|
98
|
+
op.user = user;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return (opsList) => {
|
|
102
|
+
opsList.forEach(addUserProp);
|
|
103
|
+
return opsList;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
83
107
|
/**
|
|
84
108
|
* Get a list of all the put operations needed to complete a cascading PUT
|
|
85
109
|
*
|
|
@@ -105,8 +129,10 @@ function getPutOperations(putFn, uri, data, locals) {
|
|
|
105
129
|
}
|
|
106
130
|
|
|
107
131
|
// run each through the normal put, which may or may not hit custom component logic
|
|
108
|
-
return bluebird
|
|
109
|
-
.
|
|
132
|
+
return bluebird
|
|
133
|
+
.map(cmptOrLayout, ({ key, value }) => putFn(key, value, locals))
|
|
134
|
+
.then(ops => _.filter(_.flattenDeep(ops), _.identity))
|
|
135
|
+
.then(addUserInfoToOp(locals));
|
|
110
136
|
}
|
|
111
137
|
|
|
112
138
|
/**
|
package/lib/services/layouts.js
CHANGED
|
@@ -6,8 +6,9 @@ const _ = require('lodash'),
|
|
|
6
6
|
uid = require('../uid'),
|
|
7
7
|
files = require('../files'),
|
|
8
8
|
models = require('./models'),
|
|
9
|
+
components = require('./components'),
|
|
9
10
|
meta = require('./metadata'),
|
|
10
|
-
{ getLayoutName, replaceVersion } = require('clayutils'),
|
|
11
|
+
{ getLayoutName, replaceVersion, isComponent } = require('clayutils'),
|
|
11
12
|
bus = require('./bus');
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -39,9 +40,13 @@ function get(uri, locals) {
|
|
|
39
40
|
* @returns {Promise}
|
|
40
41
|
*/
|
|
41
42
|
function put(uri, data, locals) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// layout-level components are published the same as page-level components
|
|
44
|
+
if (isComponent(uri)) return components.cmptPut(uri, data, locals);
|
|
45
|
+
|
|
46
|
+
// else try to apply a layout model to the layout instance
|
|
47
|
+
const model = files.getLayoutModules(getLayoutName(uri)),
|
|
48
|
+
callHooks = _.get(locals, 'hooks') !== 'false';
|
|
49
|
+
let result;
|
|
45
50
|
|
|
46
51
|
if (model && _.isFunction(model.save) && callHooks) {
|
|
47
52
|
result = models.put(model, uri, data, locals);
|
package/lib/services/pages.js
CHANGED
|
@@ -27,13 +27,17 @@ const _ = require('lodash'),
|
|
|
27
27
|
* @param {string} uri
|
|
28
28
|
* @param {{}} data
|
|
29
29
|
* @param {[]} ops
|
|
30
|
+
* @param {{}} locals
|
|
30
31
|
* @returns {array}
|
|
31
32
|
*/
|
|
32
|
-
function addOp(uri, data, ops) {
|
|
33
|
+
function addOp(uri, data, ops, locals = {}) {
|
|
34
|
+
const { user } = locals;
|
|
35
|
+
|
|
33
36
|
ops.push({
|
|
34
37
|
type: 'put',
|
|
35
38
|
key: uri,
|
|
36
|
-
value: JSON.stringify(data)
|
|
39
|
+
value: JSON.stringify(data),
|
|
40
|
+
user
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
return ops;
|
|
@@ -257,7 +261,7 @@ function publish(uri, data, locals) {
|
|
|
257
261
|
publishedMeta = meta;
|
|
258
262
|
|
|
259
263
|
// add page PUT operation last
|
|
260
|
-
return addOp(replaceVersion(uri, published), pageData, ops);
|
|
264
|
+
return addOp(replaceVersion(uri, published), pageData, ops, locals);
|
|
261
265
|
});
|
|
262
266
|
})
|
|
263
267
|
.then(applyBatch)
|
|
@@ -306,7 +310,7 @@ function create(uri, data, locals) {
|
|
|
306
310
|
return getPageClonePutOperations(pageData, locals)
|
|
307
311
|
.then(ops => {
|
|
308
312
|
pageData.layout = layoutReference;
|
|
309
|
-
return addOp(pageReference, pageData, ops);
|
|
313
|
+
return addOp(pageReference, pageData, ops, locals);
|
|
310
314
|
});
|
|
311
315
|
})
|
|
312
316
|
.then(applyBatch)
|