Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-route-schema

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-route-schema - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2-0

.eslintrc.js

45

index.js

@@ -54,3 +54,7 @@ 'use strict'

onError: function(err, ctx) {
ctx.throw(400, ctx.routeSchemaErrors.map(e => e.message).join(', '))
if (err.message === 'RouteSchemaErrors') {
ctx.throw(400, ctx.routeSchemaErrors.map(function(e) { return e.message }).join(', '))
} else {
throw err
}
}

@@ -83,3 +87,3 @@ }

* generate schema validate middleware
*
*
* handle errors Example

@@ -100,3 +104,3 @@ * ```js

return async function(ctx, next) {
return function(ctx, next) {
function callValidate(validate, type) {

@@ -132,3 +136,3 @@ if (!validate) {

/**
* load schema
* load schema
* ```

@@ -141,3 +145,3 @@ * schema.loadSchemaOptions([{

* ```
*
*
* @param {Object} schemaOptions

@@ -190,7 +194,7 @@ */

/**
/**
* ######################################
* mode one: standalone middleware
* low performance
*
*
*/

@@ -222,13 +226,13 @@ KoaRouteSchema.prototype.middleware = function middleware() {

// ensure calling next middleware which is after the router
return typeof _this.options.notFound === 'function' ?
_this.options.notFound(ctx, next) :
next()
return typeof _this.options.notFound === 'function'
? _this.options.notFound(ctx, next)
: next()
}
}
/**
/**
* ######################################
* mode tow: attach to other router middleware
* high performance, need `route in attached router` be same with `route in schemaOptions` exactly
*
*
*/

@@ -263,2 +267,17 @@

module.exports = KoaRouteSchema
/**
* #################################################################################
* middleware for each route
* #################################################################################
*/
KoaRouteSchema.prototype.routeMiddleware = function routeMiddleware(bodySchema, querySchema) {
return this.genMiddlewareFromSchema(bodySchema, querySchema)
}
KoaRouteSchema.prototype.routeBodyMiddleware = function routeMiddleware(schema) {
return this.routeMiddleware(schema, null)
}
KoaRouteSchema.prototype.routeQueryMiddleware = function routeMiddleware(schema) {
return this.routeMiddleware(null, schema)
}
module.exports = KoaRouteSchema
{
"name": "koa-route-schema",
"version": "0.0.1",
"version": "0.0.2-0",
"description": "koa middleware to apply jsonschema with route",
"main": "index.js",
"types": "index.d.ts",
"repository": "https://github.com/keepgoingwm/koa-route-schema.git",

@@ -10,6 +11,8 @@ "author": "Awam Wang <@keepgoingwm> (https://keepgoingwm.github.io/)",

"scripts": {
"lint": "eslint index.js utils.js",
"lint": "eslint index.js utils.js ./examples",
"lint:fix": "eslint index.js utils.js ./examples --fix",
"test": "echo 'test'"
},
"dependencies": {
"@types/koa": "^2.11.3",
"ajv": "^6.12.2",

@@ -34,10 +37,19 @@ "ajv-errors": "^1.0.1",

"peerDependencies": {
"koa": "^2.12.0"
"koa": "^2.12.0",
"koa-body": "^4.1.3"
},
"devDependencies": {
"@types/koa-convert": "^1.2.3",
"babel-eslint": "^10.1.0",
"eslint": "^7.1.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-standard": "^4.0.1"
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"koa": "^2.12.0",
"koa-better-router": "^2.1.1",
"koa-body": "^4.1.3",
"koa-route-schema-yapi": "^0.0.1"
}
}

@@ -39,2 +39,2 @@ 'use strict'

module.exports = utils
module.exports = utils
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc