@gabliam/koa
Version:
Gabliam plugin for add koa
135 lines (134 loc) • 4.98 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KoaPluginConfig = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@gabliam/core");
const constants_1 = require("./constants");
const koaBodyFormidableOptions = core_1.Joi.object()
.keys({
/**
* {Integer} Limits the amount of memory all fields together (except files) can allocate in bytes.
* If this value is exceeded, an 'error' event is emitted. The default size is 20MB.
*/
maxFileSize: core_1.Joi.number().integer(),
/**
* {Integer} Limits the number of fields that the querystring parser will decode, default 1000
*/
maxFields: core_1.Joi.number().integer(),
/**
* {Integer} Limits the amount of memory all fields together (except files) can allocate in bytes.
* If this value is exceeded, an 'error' event is emitted, default 2mb (2 * 1024 * 1024)
*/
maxFieldsSize: core_1.Joi.number().integer(),
/**
* {String} Sets the directory for placing file uploads in, default os.tmpDir()
*/
uploadDir: core_1.Joi.string(),
/**
* {Boolean} Files written to uploadDir will include the extensions of the original files, default false
*/
keepExtensions: core_1.Joi.bool(),
/**
* {String} If you want checksums calculated for incoming files, set this to either 'sha1' or 'md5', default false
*/
hash: core_1.Joi.string(),
/**
* {Boolean} Multiple file uploads or no, default true
*/
multiples: core_1.Joi.bool(),
/**
* {Function} Special callback on file begin. The function is executed directly by formidable.
* It can be used to rename files before saving them to disk. See https://github.com/felixge/node-formidable#filebegin
*/
onFileBegin: core_1.Joi.func(),
})
.default({ extended: false });
const koaBodyOptions = core_1.Joi.object().keys({
/**
* {Boolean} Patch request body to Node's ctx.req, default false
*
* Note: You can patch request body to Node or Koa in same time if you want.
*/
patchNode: core_1.Joi.bool(),
/**
* {Boolean} Patch request body to Koa's ctx.request, default true
*
* Note: You can patch request body to Node or Koa in same time if you want.
*/
patchKoa: core_1.Joi.bool(),
/**
* {String|Integer} The byte (if integer) limit of the JSON body, default 1mb
*/
jsonLimit: [core_1.Joi.string(), core_1.Joi.number().integer()],
/**
* {String|Integer} The byte (if integer) limit of the form body, default 56kb
*/
formLimit: [core_1.Joi.string(), core_1.Joi.number().integer()],
/**
* {String|Integer} The byte (if integer) limit of the text body, default 56kb
*/
textLimit: [core_1.Joi.string(), core_1.Joi.number().integer()],
/**
* {String} Sets encoding for incoming form fields, default utf-8
*/
encoding: core_1.Joi.string(),
/**
* {Boolean} Parse multipart bodies, default false
*/
multipart: core_1.Joi.bool(),
/**
* {Boolean} Parse urlencoded bodies, default true
*/
urlencoded: core_1.Joi.bool(),
/**
* {Boolean} Parse text bodies, default true
*/
text: core_1.Joi.bool(),
/**
* {Boolean} Parse json bodies, default true
*/
json: core_1.Joi.bool(),
/**
* Toggles co-body strict mode; if true, only parses arrays or objects, default true
*/
jsonStrict: core_1.Joi.bool(),
/**
* {Object} Options to pass to the formidable multipart parser
*/
formidable: koaBodyFormidableOptions,
/**
* {Function} Custom error handle, if throw an error, you can customize the response - onError(error, context), default will throw
*/
onError: core_1.Joi.func(),
/**
* {Boolean} If enabled, don't parse GET, HEAD, DELETE requests, default true
*
* GET, HEAD, and DELETE requests have no defined semantics for the request body,
* but this doesn't mean they may not be valid in certain use cases.
* koa-body is strict by default
*
* see http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-6.3
*/
strict: core_1.Joi.bool(),
});
let KoaPluginConfig = class KoaPluginConfig {
restConfig() {
return {
koaBodyOptions: this.koaBodyOptions,
};
}
};
tslib_1.__decorate([
(0, core_1.Value)('application.web.koaBodyOptions', koaBodyOptions),
tslib_1.__metadata("design:type", Object)
], KoaPluginConfig.prototype, "koaBodyOptions", void 0);
tslib_1.__decorate([
(0, core_1.Bean)(constants_1.KOA_PLUGIN_CONFIG),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", []),
tslib_1.__metadata("design:returntype", Object)
], KoaPluginConfig.prototype, "restConfig", null);
KoaPluginConfig = tslib_1.__decorate([
(0, core_1.PluginConfig)()
], KoaPluginConfig);
exports.KoaPluginConfig = KoaPluginConfig;