CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
context.js96 linesDownload Raw Back to lib
1'use strict'2 3const {4  kFourOhFourContext,5  kReplySerializerDefault,6  kSchemaErrorFormatter,7  kErrorHandler,8  kChildLoggerFactory,9  kOptions,10  kReply,11  kRequest,12  kBodyLimit,13  kLogLevel,14  kContentTypeParser,15  kRouteByFastify,16  kRequestCacheValidateFns,17  kReplyCacheSerializeFns18} = require('./symbols.js')19 20// Object that holds the context of every request21// Every route holds an instance of this object.22function Context ({23  schema,24  handler,25  config,26  requestIdLogLabel,27  childLoggerFactory,28  errorHandler,29  bodyLimit,30  logLevel,31  logSerializers,32  attachValidation,33  validatorCompiler,34  serializerCompiler,35  replySerializer,36  schemaErrorFormatter,37  exposeHeadRoute,38  prefixTrailingSlash,39  server,40  isFastify41}) {42  this.schema = schema43  this.handler = handler44  this.Reply = server[kReply]45  this.Request = server[kRequest]46  this.contentTypeParser = server[kContentTypeParser]47  this.onRequest = null48  this.onSend = null49  this.onError = null50  this.onTimeout = null51  this.preHandler = null52  this.onResponse = null53  this.preSerialization = null54  this.onRequestAbort = null55  this.config = config56  this.errorHandler = errorHandler || server[kErrorHandler]57  this.requestIdLogLabel = requestIdLogLabel || server[kOptions].requestIdLogLabel58  this.childLoggerFactory = childLoggerFactory || server[kChildLoggerFactory]59  this._middie = null60  this._parserOptions = {61    limit: bodyLimit || server[kBodyLimit]62  }63  this.exposeHeadRoute = exposeHeadRoute64  this.prefixTrailingSlash = prefixTrailingSlash65  this.logLevel = logLevel || server[kLogLevel]66  this.logSerializers = logSerializers67  this[kFourOhFourContext] = null68  this.attachValidation = attachValidation69  this[kReplySerializerDefault] = replySerializer70  this.schemaErrorFormatter =71    schemaErrorFormatter ||72    server[kSchemaErrorFormatter] ||73    defaultSchemaErrorFormatter74  this[kRouteByFastify] = isFastify75 76  this[kRequestCacheValidateFns] = null77  this[kReplyCacheSerializeFns] = null78  this.validatorCompiler = validatorCompiler || null79  this.serializerCompiler = serializerCompiler || null80 81  this.server = server82}83 84function defaultSchemaErrorFormatter (errors, dataVar) {85  let text = ''86  const separator = ', '87 88  for (let i = 0; i !== errors.length; ++i) {89    const e = errors[i]90    text += dataVar + (e.instancePath || '') + ' ' + e.message + separator91  }92  return new Error(text.slice(0, -separator.length))93}94 95module.exports = Context96