mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Fixed some type issues with the api framework
- fixes a bunch of red squiggly lines due to type issues - this in turn makes it slightly easier to read the API pipeline code
This commit is contained in:
parent
4cd210c29c
commit
0695f74a65
@ -19,6 +19,8 @@ class Frame {
|
|||||||
* file: Uploaded file
|
* file: Uploaded file
|
||||||
* files: Uploaded files
|
* files: Uploaded files
|
||||||
* apiType: Content or admin api access
|
* apiType: Content or admin api access
|
||||||
|
* docName: The endpoint name, e.g. "posts"
|
||||||
|
* method: The method name, e.g. "browse"
|
||||||
*/
|
*/
|
||||||
this.options = {};
|
this.options = {};
|
||||||
this.data = {};
|
this.data = {};
|
||||||
@ -26,6 +28,9 @@ class Frame {
|
|||||||
this.file = {};
|
this.file = {};
|
||||||
this.files = [];
|
this.files = [];
|
||||||
this.apiType = null;
|
this.apiType = null;
|
||||||
|
this.docName = null;
|
||||||
|
this.method = null;
|
||||||
|
this.response = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,23 +174,21 @@ const STAGES = {
|
|||||||
* 4. Controller - Execute the controller implementation & receive model response.
|
* 4. Controller - Execute the controller implementation & receive model response.
|
||||||
* 5. Output Serialisation - Output formatting, Deprecations, Extra attributes etc...
|
* 5. Output Serialisation - Output formatting, Deprecations, Extra attributes etc...
|
||||||
*
|
*
|
||||||
* @param {Function} apiController
|
* @param {Object} apiController
|
||||||
* @param {Object} apiUtils - Local utils (validation & serialisation) from target API version
|
* @param {Object} apiUtils - Local utils (validation & serialisation) from target API version
|
||||||
* @param {String} [apiType] - Content or Admin API access
|
* @param {String} [apiType] - Content or Admin API access
|
||||||
* @return {Function}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
const pipeline = (apiController, apiUtils, apiType) => {
|
const pipeline = (apiController, apiUtils, apiType) => {
|
||||||
const keys = Object.keys(apiController);
|
const keys = Object.keys(apiController);
|
||||||
|
const docName = apiController.docName;
|
||||||
|
|
||||||
// CASE: api controllers are objects with configuration.
|
// CASE: api controllers are objects with configuration.
|
||||||
// We have to ensure that we expose a functional interface e.g. `api.posts.add` has to be available.
|
// We have to ensure that we expose a functional interface e.g. `api.posts.add` has to be available.
|
||||||
return keys.reduce((obj, key) => {
|
return keys.reduce((obj, method) => {
|
||||||
const docName = apiController.docName;
|
const apiImpl = _.cloneDeep(apiController)[method];
|
||||||
const method = key;
|
|
||||||
|
|
||||||
const apiImpl = _.cloneDeep(apiController)[key];
|
obj[method] = function wrapper() {
|
||||||
|
|
||||||
obj[key] = function wrapper() {
|
|
||||||
const apiConfig = {docName, method};
|
const apiConfig = {docName, method};
|
||||||
let options;
|
let options;
|
||||||
let data;
|
let data;
|
||||||
@ -253,7 +251,7 @@ const pipeline = (apiController, apiUtils, apiType) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(obj[key], apiImpl);
|
Object.assign(obj[method], apiImpl);
|
||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,10 @@ describe('Frame', function () {
|
|||||||
'user',
|
'user',
|
||||||
'file',
|
'file',
|
||||||
'files',
|
'files',
|
||||||
'apiType'
|
'apiType',
|
||||||
|
'docName',
|
||||||
|
'method',
|
||||||
|
'response'
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,7 +45,10 @@ describe('HTTP', function () {
|
|||||||
'user',
|
'user',
|
||||||
'file',
|
'file',
|
||||||
'files',
|
'files',
|
||||||
'apiType'
|
'apiType',
|
||||||
|
'docName',
|
||||||
|
'method',
|
||||||
|
'response'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
apiImpl.args[0][0].data.should.eql({a: 'a'});
|
apiImpl.args[0][0].data.should.eql({a: 'a'});
|
||||||
|
Loading…
Reference in New Issue
Block a user