Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.13
@@ -1,67 +0,3 @@ | ||
/// <reference types="koa__cors" /> | ||
import Cors from "@koa/cors"; | ||
import { ActionResult, Application, Class, Configuration, DefaultFacility, Facility, Invocation, KoaMiddleware, Middleware, PlumierApplication, PlumierConfiguration, RouteInfo, ValidatorFunction } from "@plumier/core"; | ||
import Koa, { Context } from "koa"; | ||
export interface RouteContext extends Koa.Context { | ||
route: Readonly<RouteInfo>; | ||
parameters: any[]; | ||
} | ||
export interface BodyParserOption { | ||
enableTypes?: string[]; | ||
encode?: string; | ||
formLimit?: string; | ||
jsonLimit?: string; | ||
strict?: boolean; | ||
detectJSON?: (ctx: Koa.Context) => boolean; | ||
extendTypes?: { | ||
json?: string[]; | ||
form?: string[]; | ||
text?: string[]; | ||
}; | ||
onerror?: (err: Error, ctx: Koa.Context) => void; | ||
} | ||
export declare class MiddlewareInvocation implements Invocation { | ||
private middleware; | ||
context: Context; | ||
private next; | ||
constructor(middleware: Middleware, context: Context, next: Invocation); | ||
proceed(): Promise<ActionResult>; | ||
} | ||
export declare class ActionInvocation implements Invocation { | ||
context: RouteContext; | ||
constructor(context: RouteContext); | ||
proceed(): Promise<ActionResult>; | ||
} | ||
export declare function pipe(middleware: Middleware[], context: Context, invocation: Invocation): Invocation; | ||
/** | ||
* Preset configuration for building web api. This facility contains: | ||
* | ||
* body parser: koa-bodyparser | ||
* | ||
* cors: @koa/cors | ||
*/ | ||
export declare class WebApiFacility extends DefaultFacility { | ||
private opt?; | ||
constructor(opt?: { | ||
controller?: string | Class | Class[] | undefined; | ||
bodyParser?: BodyParserOption | undefined; | ||
cors?: Cors.Options | undefined; | ||
validators?: { | ||
[key: string]: ValidatorFunction; | ||
} | undefined; | ||
} | undefined); | ||
setup(app: Readonly<PlumierApplication>): void; | ||
} | ||
/** | ||
* Preset configuration for building restful style api. This facility contains: | ||
* | ||
* body parser: koa-bodyparser | ||
* | ||
* cors: @koa/cors | ||
* | ||
* default response status: { get: 200, post: 201, put: 204, delete: 204 } | ||
*/ | ||
export declare class RestfulApiFacility extends WebApiFacility { | ||
setup(app: Readonly<PlumierApplication>): void; | ||
} | ||
import { Application, Configuration, Facility, KoaMiddleware, Middleware, PlumierApplication, PlumierConfiguration } from "@plumier/core"; | ||
import Koa from "koa"; | ||
export declare class Plumier implements PlumierApplication { | ||
@@ -76,4 +12,3 @@ readonly config: Readonly<PlumierConfiguration>; | ||
set(config: Partial<Configuration>): Application; | ||
private createRoutes; | ||
initialize(): Promise<Koa>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const cors_1 = tslib_1.__importDefault(require("@koa/cors")); | ||
const core_1 = require("@plumier/core"); | ||
const kernel_1 = require("@plumier/kernel"); | ||
const validator_1 = require("@plumier/validator"); | ||
const fs_1 = require("fs"); | ||
const koa_1 = tslib_1.__importDefault(require("koa")); | ||
const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser")); | ||
const path_1 = require("path"); | ||
const router_1 = require("./router"); | ||
/* ------------------------------------------------------------------------------- */ | ||
/* ------------------------------- INVOCATIONS ----------------------------------- */ | ||
/* ------------------------------------------------------------------------------- */ | ||
class MiddlewareInvocation { | ||
constructor(middleware, context, next) { | ||
this.middleware = middleware; | ||
this.context = context; | ||
this.next = next; | ||
} | ||
proceed() { | ||
return this.middleware.execute(this.next); | ||
} | ||
} | ||
exports.MiddlewareInvocation = MiddlewareInvocation; | ||
class NotFoundActionInvocation { | ||
constructor(context) { | ||
this.context = context; | ||
} | ||
proceed() { | ||
throw new core_1.HttpStatusError(404); | ||
} | ||
} | ||
class ActionInvocation { | ||
constructor(context) { | ||
this.context = context; | ||
} | ||
async proceed() { | ||
const { route, config } = this.context; | ||
const controller = config.dependencyResolver.resolve(route.controller.type); | ||
//check validation | ||
if (config.validator) { | ||
const param = (i) => route.action.parameters[i]; | ||
const validate = (value, i) => config.validator(value, param(i), this.context, this.context.config.validators); | ||
const result = await Promise.all(this.context.parameters.map((value, index) => validate(value, index))); | ||
const issues = result.flatten(); | ||
if (issues.length > 0) | ||
throw new core_1.ValidationError(issues); | ||
} | ||
const result = controller[route.action.name].apply(controller, this.context.parameters); | ||
const awaitedResult = await Promise.resolve(result); | ||
const status = config.responseStatus && config.responseStatus[route.method] || 200; | ||
//if instance of action result, return immediately | ||
if (awaitedResult && awaitedResult.execute) { | ||
awaitedResult.status = awaitedResult.status || status; | ||
return awaitedResult; | ||
} | ||
else { | ||
return new core_1.ActionResult(awaitedResult, status); | ||
} | ||
} | ||
} | ||
exports.ActionInvocation = ActionInvocation; | ||
function pipe(middleware, context, invocation) { | ||
return middleware.reverse().reduce((prev, cur) => new MiddlewareInvocation(cur, context, prev), invocation); | ||
} | ||
exports.pipe = pipe; | ||
/* ------------------------------------------------------------------------------- */ | ||
/* -------------------------------- FACILITIES ----------------------------------- */ | ||
/* ------------------------------------------------------------------------------- */ | ||
/** | ||
* Preset configuration for building web api. This facility contains: | ||
* | ||
* body parser: koa-bodyparser | ||
* | ||
* cors: @koa/cors | ||
*/ | ||
class WebApiFacility extends core_1.DefaultFacility { | ||
constructor(opt) { | ||
super(); | ||
this.opt = opt; | ||
} | ||
setup(app) { | ||
app.koa.use(async (ctx, next) => { | ||
try { | ||
await next(); | ||
} | ||
catch (e) { | ||
if (e instanceof core_1.ValidationError) { | ||
ctx.body = e.issues; | ||
ctx.status = e.status; | ||
} | ||
else if (e instanceof core_1.ConversionError) { | ||
ctx.body = [e.issues]; | ||
ctx.status = e.status; | ||
} | ||
else if (e instanceof core_1.HttpStatusError) | ||
ctx.throw(e.status, e); | ||
else | ||
ctx.throw(500, e); | ||
} | ||
}); | ||
app.koa.use(koa_bodyparser_1.default(this.opt && this.opt.bodyParser)); | ||
app.koa.use(cors_1.default(this.opt && this.opt.cors)); | ||
if (this.opt && this.opt.controller) | ||
app.set({ controller: this.opt.controller }); | ||
if (this.opt && this.opt.validators) | ||
app.set({ validators: this.opt.validators }); | ||
app.set({ | ||
validator: (value, meta, ctx, validators) => validator_1.validate(value, meta.decorators, [meta.name], ctx, validators) | ||
}); | ||
} | ||
} | ||
exports.WebApiFacility = WebApiFacility; | ||
/** | ||
* Preset configuration for building restful style api. This facility contains: | ||
* | ||
* body parser: koa-bodyparser | ||
* | ||
* cors: @koa/cors | ||
* | ||
* default response status: { get: 200, post: 201, put: 204, delete: 204 } | ||
*/ | ||
class RestfulApiFacility extends WebApiFacility { | ||
setup(app) { | ||
super.setup(app); | ||
app.set({ responseStatus: { post: 201, put: 204, delete: 204 } }); | ||
} | ||
} | ||
exports.RestfulApiFacility = RestfulApiFacility; | ||
/* ------------------------------------------------------------------------------- */ | ||
/* --------------------------- MAIN APPLICATION ---------------------------------- */ | ||
/* ------------------------------------------------------------------------------- */ | ||
class Plumier { | ||
@@ -151,3 +23,3 @@ constructor() { | ||
set(config) { | ||
if (kernel_1.hasKeyOf(config, "setup")) { | ||
if (core_1.hasKeyOf(config, "setup")) { | ||
config.setup(this); | ||
@@ -160,20 +32,2 @@ this.config.facilities.push(config); | ||
} | ||
createRoutes(executionPath) { | ||
let routes = []; | ||
if (typeof this.config.controller === "string") { | ||
const path = path_1.isAbsolute(this.config.controller) ? this.config.controller : | ||
path_1.join(executionPath, this.config.controller); | ||
if (!fs_1.existsSync(path)) | ||
throw new Error(core_1.errorMessage.ControllerPathNotFound.format(path)); | ||
routes = kernel_1.RouteGenerator.transformModule(path); | ||
} | ||
else if (Array.isArray(this.config.controller)) { | ||
routes = this.config.controller.map(x => kernel_1.RouteGenerator.transformController(x)) | ||
.flatten(); | ||
} | ||
else { | ||
routes = kernel_1.RouteGenerator.transformController(this.config.controller); | ||
} | ||
return routes; | ||
} | ||
async initialize() { | ||
@@ -185,3 +39,3 @@ try { | ||
//module.parent.parent.filename -> because Plumier app also exported in plumier/src/index.ts | ||
let routes = this.createRoutes(path_1.dirname(module.parent.parent.filename)); | ||
let routes = core_1.generateRoutes(path_1.dirname(module.parent.parent.filename), this.config.controller); | ||
for (const facility of this.config.facilities) { | ||
@@ -191,15 +45,4 @@ await facility.initialize(this, routes); | ||
if (this.config.mode === "debug") | ||
kernel_1.RouteGenerator.printAnalysis(kernel_1.RouteGenerator.analyzeRoutes(routes)); | ||
const decorators = {}; | ||
this.koa.use(router_1.router(routes, this.config, ctx => { | ||
if (ctx.route && ctx.parameters) { | ||
//execute global middleware and controller | ||
const middleware = decorators[ctx.route.url] || (decorators[ctx.route.url] = this.globalMiddleware.concat(core_1.middleware.extractDecorators(ctx.route))); | ||
return pipe(middleware, ctx, new ActionInvocation(ctx)); | ||
} | ||
else { | ||
//execute global middleware only | ||
return pipe(this.globalMiddleware.slice(0), ctx, new NotFoundActionInvocation(ctx)); | ||
} | ||
})); | ||
core_1.printAnalysis(core_1.analyzeRoutes(routes)); | ||
this.koa.use(core_1.router(routes, this.config, this.globalMiddleware)); | ||
return this.koa; | ||
@@ -206,0 +49,0 @@ } |
@@ -1,6 +0,4 @@ | ||
export { authorize, ActionResult, Application, bind, Configuration, Class, DependencyResolver, Facility, FileUploadInfo, FileParser, HeaderPart, HttpMethod, HttpStatusError, Invocation, KoaMiddleware, middleware, Middleware, domain, PlumierApplication, PlumierConfiguration, RequestPart, route, RouteInfo, ConversionError, ValidationError, ValidationIssue, ValidatorStore, ValidatorFunction, ValidatorId, DefaultFacility, response } from "@plumier/core"; | ||
export { Converter, Binder, RouteGenerator, Security } from "@plumier/kernel"; | ||
export { WebApiFacility, RestfulApiFacility } from "./application"; | ||
export { val } from "@plumier/validator"; | ||
export { authorize, ActionResult, Application, bind, Configuration, Class, DependencyResolver, Facility, FileUploadInfo, FileParser, HeaderPart, HttpMethod, HttpStatusError, Invocation, KoaMiddleware, middleware, Middleware, domain, PlumierApplication, PlumierConfiguration, RequestPart, route, RouteInfo, ValidationIssue, ValidatorStore, ValidatorFunction, ValidatorId, DefaultFacility, response, val } from "@plumier/core"; | ||
export * from "./facility"; | ||
import { Plumier } from "./application"; | ||
export default Plumier; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
var core_1 = require("@plumier/core"); | ||
@@ -11,18 +12,8 @@ exports.authorize = core_1.authorize; | ||
exports.route = core_1.route; | ||
exports.ConversionError = core_1.ConversionError; | ||
exports.ValidationError = core_1.ValidationError; | ||
exports.ValidatorId = core_1.ValidatorId; | ||
exports.DefaultFacility = core_1.DefaultFacility; | ||
exports.response = core_1.response; | ||
var kernel_1 = require("@plumier/kernel"); | ||
exports.Converter = kernel_1.Converter; | ||
exports.Binder = kernel_1.Binder; | ||
exports.RouteGenerator = kernel_1.RouteGenerator; | ||
exports.Security = kernel_1.Security; | ||
var application_1 = require("./application"); | ||
exports.WebApiFacility = application_1.WebApiFacility; | ||
exports.RestfulApiFacility = application_1.RestfulApiFacility; | ||
var validator_1 = require("@plumier/validator"); | ||
exports.val = validator_1.val; | ||
const application_2 = require("./application"); | ||
exports.default = application_2.Plumier; | ||
exports.val = core_1.val; | ||
tslib_1.__exportStar(require("./facility"), exports); | ||
const application_1 = require("./application"); | ||
exports.default = application_1.Plumier; |
{ | ||
"name": "plumier", | ||
"version": "1.0.0-alpha.9+aa8e63b", | ||
"version": "1.0.0-alpha.13+9278020", | ||
"description": "Delightful Node.js Rest API Framework powered by Koa and TypeScript", | ||
@@ -10,4 +10,2 @@ "main": "lib/index.js", | ||
"Koa", | ||
"IoC", | ||
"Dependency Injection", | ||
"Web API", | ||
@@ -25,22 +23,15 @@ "JSON Service", | ||
"@koa/cors": "^3.0.0", | ||
"@plumier/core": "1.0.0-alpha.9+aa8e63b", | ||
"@plumier/kernel": "1.0.0-alpha.9+aa8e63b", | ||
"@plumier/validator": "1.0.0-alpha.9+aa8e63b", | ||
"@types/glob": "^7.1.1", | ||
"@plumier/core": "1.0.0-alpha.13+9278020", | ||
"@types/koa": "^2.0.48", | ||
"@types/koa-bodyparser": "^5.0.0", | ||
"@types/koa__cors": "^2.2.3", | ||
"@types/validator": "^10.9.0", | ||
"chalk": "^2.4.2", | ||
"glob": "^7.1.3", | ||
"koa": "^2.7.0", | ||
"koa-bodyparser": "^4.2.1", | ||
"path-to-regexp": "^3.0.0", | ||
"tinspector": "^2.2.0", | ||
"tslib": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"@plumier/jwt": "1.0.0-alpha.9+aa8e63b", | ||
"@plumier/multipart": "1.0.0-alpha.9+aa8e63b", | ||
"@plumier/serve-static": "1.0.0-alpha.9+aa8e63b", | ||
"@plumier/jwt": "1.0.0-alpha.13+9278020", | ||
"@plumier/mongoose": "1.0.0-alpha.13+9278020", | ||
"@plumier/multipart": "1.0.0-alpha.13+9278020", | ||
"@plumier/serve-static": "1.0.0-alpha.13+9278020", | ||
"@types/body-parser": "^1.17.0", | ||
@@ -81,3 +72,3 @@ "@types/cors": "^2.8.4", | ||
}, | ||
"gitHead": "aa8e63b628454c06e6cc0da3c8ebfbfb7e39d20e" | ||
"gitHead": "9278020291d4a96d9657d1b223d5654c8cbed0d0" | ||
} |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
8
10
2
25219
28
197
3
- Removed@types/glob@^7.1.1
- Removed@types/validator@^10.9.0
- Removedchalk@^2.4.2
- Removedglob@^7.1.3
- Removedpath-to-regexp@^3.0.0
- Removedtinspector@^2.2.0
- Removed@types/acorn@4.0.5(transitive)
- Removed@types/estree@1.0.6(transitive)
- Removed@types/glob@7.2.0(transitive)
- Removed@types/minimatch@5.1.2(transitive)
- Removed@types/validator@10.11.3(transitive)
- Removedacorn@7.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-to-regexp@3.3.0(transitive)
- Removedreflect-metadata@0.1.14(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtinspector@2.3.1(transitive)
- Removedwrappy@1.0.2(transitive)