koa-route-schema
Advanced tools
Comparing version 0.0.1 to 0.0.2-0
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20476
8
327
11
12
+ Added@types/koa@^2.11.3
+ Added@types/accepts@1.3.7(transitive)
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/content-disposition@0.5.8(transitive)
+ Added@types/cookies@0.9.0(transitive)
+ Added@types/express@5.0.0(transitive)
+ Added@types/express-serve-static-core@5.0.2(transitive)
+ Added@types/formidable@1.2.8(transitive)
+ Added@types/http-assert@1.5.6(transitive)
+ Added@types/http-errors@2.0.4(transitive)
+ Added@types/keygrip@1.0.6(transitive)
+ Added@types/koa@2.15.0(transitive)
+ Added@types/koa-compose@3.2.8(transitive)
+ Added@types/mime@1.3.5(transitive)
+ Added@types/node@22.10.2(transitive)
+ Added@types/qs@6.9.17(transitive)
+ Added@types/range-parser@1.2.7(transitive)
+ Added@types/send@0.17.4(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedco-body@5.2.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedformidable@1.2.6(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinflation@2.1.0(transitive)
+ Addedkoa-body@4.2.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addedunpipe@1.0.0(transitive)