chore: Upgrade Flow to v0.104.0

This commit is contained in:
Tom Moor
2020-08-08 16:26:20 -07:00
parent e9387db895
commit c6d2467fae
131 changed files with 9151 additions and 3089 deletions

View File

@@ -24,7 +24,6 @@ import { NotFoundError } from "../errors";
import errorHandling from "../middlewares/errorHandling";
import validation from "../middlewares/validation";
import methodOverride from "../middlewares/methodOverride";
import cache from "./middlewares/cache";
import apiWrapper from "./middlewares/apiWrapper";
import editor from "./middlewares/editor";
@@ -35,7 +34,6 @@ const router = new Router();
api.use(errorHandling());
api.use(bodyParser());
api.use(methodOverride());
api.use(cache());
api.use(validation());
api.use(apiWrapper());
api.use(editor());

View File

@@ -17,6 +17,7 @@ export default function apiWrapper() {
) {
// $FlowFixMe
ctx.body = {
// $FlowFixMe
...ctx.body,
status: ctx.status,
ok,

View File

@@ -1,26 +0,0 @@
// @flow
import debug from "debug";
import { type Context } from "koa";
const log = debug("cache");
export default function cache() {
return async function cacheMiddleware(ctx: Context, next: () => Promise<*>) {
ctx.cache = {};
ctx.cache.set = async (id, value) => {
ctx.cache[id] = value;
};
ctx.cache.get = async (id, def) => {
if (ctx.cache[id]) {
log(`hit: ${id}`);
} else {
log(`miss: ${id}`);
ctx.cache.set(id, await def());
}
return ctx.cache[id];
};
return next();
};
}

View File

@@ -16,9 +16,8 @@ export default function pagination(options?: Object) {
};
let query = ctx.request.query;
// $FlowFixMe
let body = ctx.request.body;
// $FlowFixMe
let limit = query.limit || body.limit;
// $FlowFixMe
@@ -48,15 +47,20 @@ export default function pagination(options?: Object) {
);
}
/* $FlowFixMeNowPlease This comment suppresses an error found when upgrading
* flow-bin@0.104.0. To view the error, delete this comment and run Flow. */
ctx.state.pagination = {
limit: limit,
offset: offset,
limit,
offset,
};
// $FlowFixMe
query.limit = ctx.state.pagination.limit;
// $FlowFixMe
query.offset = ctx.state.pagination.offset + query.limit;
/* $FlowFixMeNowPlease This comment suppresses an error found when upgrading
* flow-bin@0.104.0. To view the error, delete this comment and run Flow. */
ctx.state.pagination.nextPath = `/api${
ctx.request.path
}?${querystring.stringify(query)}`;