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

plumier

Package Overview
Dependencies
Maintainers
1
Versions
652
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plumier - npm Package Compare versions

Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.13

.DS_Store

69

lib/application.d.ts

@@ -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"
}
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