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:
Hannah Wolfe 2022-08-21 16:31:41 +01:00
parent 4cd210c29c
commit 0695f74a65
4 changed files with 20 additions and 11 deletions

View File

@ -19,6 +19,8 @@ class Frame {
* file: Uploaded file
* files: Uploaded files
* apiType: Content or admin api access
* docName: The endpoint name, e.g. "posts"
* method: The method name, e.g. "browse"
*/
this.options = {};
this.data = {};
@ -26,6 +28,9 @@ class Frame {
this.file = {};
this.files = [];
this.apiType = null;
this.docName = null;
this.method = null;
this.response = null;
}
/**

View File

@ -174,23 +174,21 @@ const STAGES = {
* 4. Controller - Execute the controller implementation & receive model response.
* 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 {String} [apiType] - Content or Admin API access
* @return {Function}
* @return {Object}
*/
const pipeline = (apiController, apiUtils, apiType) => {
const keys = Object.keys(apiController);
const docName = apiController.docName;
// 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.
return keys.reduce((obj, key) => {
const docName = apiController.docName;
const method = key;
return keys.reduce((obj, method) => {
const apiImpl = _.cloneDeep(apiController)[method];
const apiImpl = _.cloneDeep(apiController)[key];
obj[key] = function wrapper() {
obj[method] = function wrapper() {
const apiConfig = {docName, method};
let options;
let data;
@ -253,7 +251,7 @@ const pipeline = (apiController, apiUtils, apiType) => {
});
};
Object.assign(obj[key], apiImpl);
Object.assign(obj[method], apiImpl);
return obj;
}, {});
};

View File

@ -11,7 +11,10 @@ describe('Frame', function () {
'user',
'file',
'files',
'apiType'
'apiType',
'docName',
'method',
'response'
]);
});

View File

@ -45,7 +45,10 @@ describe('HTTP', function () {
'user',
'file',
'files',
'apiType'
'apiType',
'docName',
'method',
'response'
]);
apiImpl.args[0][0].data.should.eql({a: 'a'});