New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 0.1.0-alpha.ad52811b to 0.1.0-alpha.b123904d

lib/validator.d.ts

11

lib/application.js

@@ -34,3 +34,14 @@ "use strict";

const controller = config.dependencyResolver.resolve(route.controller.object);
//bind parameters
const parameters = binder_1.bindParameter(request, route.action, config.converters);
//check validation
if (config.validator) {
const param = (i) => route.action.parameters[i];
const validate = (value, i) => config.validator(value, param(i));
const issues = parameters.map((value, index) => ({ parameter: param(index).name, issues: validate(value, index) }))
.filter(x => Boolean(x.issues));
log(`[Action Invocation] Validation result ${framework_1.b(util_1.inspect(issues, false, null))}`);
if (issues.length > 0)
return new framework_1.ActionResult(issues, 400);
}
const result = controller[route.action.name].apply(controller, parameters);

@@ -37,0 +48,0 @@ const status = config.responseStatus && config.responseStatus[route.method] || 200;

4

lib/binder.d.ts
/// <reference types="koa-bodyparser" />
import { Request } from "koa";
import { Class, TypeConverter, ValueConverter } from "./framework";
import { FunctionReflection } from "./libs/reflect";
import { FunctionReflection } from "tinspector";
export declare function booleanConverter(value: any): boolean;

@@ -12,2 +12,2 @@ export declare function dateConverter(value: any): Date;

export declare function convert(value: any, type: Class | undefined, converters: Map<Function, ValueConverter>): any;
export declare function bindParameter(request: Request, action: FunctionReflection, converter?: TypeConverter): (string | object | undefined)[];
export declare function bindParameter(request: Request, action: FunctionReflection, converter?: TypeConverter): any[];

@@ -7,3 +7,3 @@ "use strict";

const framework_1 = require("./framework");
const reflect_1 = require("./libs/reflect");
const tinspector_1 = require("tinspector");
const log = debug_1.default("plum:binder");

@@ -34,3 +34,3 @@ /* ------------------------------------------------------------------------------- */

log(`[Model Converter] converting ${framework_1.b(util_1.inspect(value, false, null))} to ${framework_1.b(type.name)} `);
const reflection = reflect_1.reflect(type);
const reflection = tinspector_1.reflect(type);
log(`[Model Converter] model info ${framework_1.b(util_1.inspect(reflection.ctorParameters))} `);

@@ -107,3 +107,3 @@ const sanitized = reflection.ctorParameters.map(x => ({

/* ------------------------------------------------------------------------------- */
function arrayDecorator(action, request, par, converter) {
function bindArrayDecorator(action, request, par, converter) {
const decorator = par.decorators.find((x) => x.type == "ParameterBinding" && x.name == "Array");

@@ -129,3 +129,3 @@ if (!decorator)

const converter = (result, type) => convert(result, type || x.typeAnnotation, mergedConverters);
return arrayDecorator(action, request, x, converter) ||
return bindArrayDecorator(action, request, x, converter) ||
bindDecorator(action, request, x, converter) ||

@@ -132,0 +132,0 @@ bindModel(action, request, x, converter) ||

@@ -5,3 +5,3 @@ /// <reference types="koa-bodyparser" />

import Koa, { Context, Request } from "koa";
import { ClassReflection, FunctionReflection } from "./libs/reflect";
import { ClassReflection, FunctionReflection, ParameterReflection } from "tinspector";
export declare type HttpMethod = "post" | "get" | "put" | "delete";

@@ -87,2 +87,6 @@ export declare type KoaMiddleware = (ctx: Context, next: () => Promise<void>) => Promise<any>;

converters?: TypeConverter;
/**
* Set custom validator
*/
validator?: (value: any, metadata: ParameterReflection) => string[] | undefined;
}

@@ -89,0 +93,0 @@ export interface PlumierConfiguration extends Configuration {

@@ -7,3 +7,3 @@ "use strict";

const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
const reflect_1 = require("./libs/reflect");
const tinspector_1 = require("tinspector");
/* ------------------------------------------------------------------------------- */

@@ -185,3 +185,3 @@ /* -------------------------------- HELPERS -------------------------------------- */

function request(part) {
return reflect_1.decorateParameter({ type: "ParameterBinding", name: "Request", part });
return tinspector_1.decorateParameter({ type: "ParameterBinding", name: "Request", part });
}

@@ -200,3 +200,3 @@ bind.request = request;

function body(part) {
return reflect_1.decorateParameter({ type: "ParameterBinding", name: "Body", part });
return tinspector_1.decorateParameter({ type: "ParameterBinding", name: "Body", part });
}

@@ -215,3 +215,3 @@ bind.body = body;

function header(key) {
return reflect_1.decorateParameter({ type: "ParameterBinding", name: "Header", part: key });
return tinspector_1.decorateParameter({ type: "ParameterBinding", name: "Header", part: key });
}

@@ -230,3 +230,3 @@ bind.header = header;

function query(name) {
return reflect_1.decorateParameter({ type: "ParameterBinding", name: "Query", part: name });
return tinspector_1.decorateParameter({ type: "ParameterBinding", name: "Query", part: name });
}

@@ -241,3 +241,3 @@ bind.query = query;

function array(type) {
return reflect_1.decorateParameter({ type: "ParameterBinding", name: "Array", typeAnnotation: type });
return tinspector_1.decorateParameter({ type: "ParameterBinding", name: "Array", typeAnnotation: type });
}

@@ -247,3 +247,3 @@ bind.array = array;

class RouteDecoratorImpl {
decorateRoute(method, url) { return reflect_1.decorateMethod({ name: "Route", method, url }); }
decorateRoute(method, url) { return tinspector_1.decorateMethod({ name: "Route", method, url }); }
/**

@@ -382,3 +382,3 @@ * Mark method as POST method http handler

*/
root(url) { return reflect_1.decorateClass({ name: "Root", url }); }
root(url) { return tinspector_1.decorateClass({ name: "Root", url }); }
/**

@@ -397,3 +397,3 @@ * Ignore method from route generation

*/
ignore() { return reflect_1.decorateMethod({ name: "Ignore" }); }
ignore() { return tinspector_1.decorateMethod({ name: "Ignore" }); }
}

@@ -409,6 +409,6 @@ exports.RouteDecoratorImpl = RouteDecoratorImpl;

if (args.length == 1) {
reflect_1.decorateClass(value)(args[0]);
tinspector_1.decorateClass(value)(args[0]);
}
else {
reflect_1.decorateMethod(value)(args[0], args[1]);
tinspector_1.decorateMethod(value)(args[0], args[1]);
}

@@ -419,3 +419,3 @@ };

})(middleware = exports.middleware || (exports.middleware = {}));
function model() { return reflect_1.decorateClass({}); }
function model() { return tinspector_1.decorateClass({}); }
exports.model = model;

@@ -422,0 +422,0 @@ /* ------------------------------------------------------------------------------- */

import { Context } from "koa";
import { RouteInfo, Class, Configuration, Middleware } from "./framework";
import { ClassReflection } from "./libs/reflect";
import { ClassReflection } from "tinspector";
interface Issue {

@@ -16,3 +16,3 @@ type: "error" | "warning" | "success";

export declare function transformController(object: ClassReflection | Class): RouteInfo[];
export declare function transformModule(path: string): Promise<RouteInfo[]>;
export declare function transformModule(path: string, extensions?: string[]): Promise<RouteInfo[]>;
export declare function router(infos: RouteInfo[], config: Configuration, handler: (ctx: Context) => Promise<void>): (ctx: Context, next: () => Promise<void>) => Promise<void>;

@@ -19,0 +19,0 @@ export declare function analyzeRoutes(routes: RouteInfo[]): TestResult[];

@@ -9,3 +9,3 @@ "use strict";

const framework_1 = require("./framework");
const reflect_1 = require("./libs/reflect");
const tinspector_1 = require("tinspector");
const util_1 = require("util");

@@ -38,10 +38,15 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));

}
function resolvePath(path) {
function resolvePath(path, extensions) {
const ext = extensions || [".js"];
//resolve provided path directory or file
if (Fs.lstatSync(path).isDirectory())
return Fs.readdirSync(path)
//take only *.js
.filter(x => Path.extname(x) === ".js")
if (Fs.lstatSync(path).isDirectory()) {
const files = Fs.readdirSync(path)
//take only file in extension list
.filter(x => ext.some(ex => Path.extname(x) === ex))
//add root path + file name
.map(x => Path.join(path, x));
log(`[Router] Resolve files with ${ext.join("|")}`);
log(`${files.join("\n")}`);
return files;
}
else

@@ -80,3 +85,3 @@ return [path];

function transformController(object) {
const controller = typeof object === "function" ? reflect_1.reflect(object) : object;
const controller = typeof object === "function" ? tinspector_1.reflect(object) : object;
if (!controller.name.toLowerCase().endsWith("controller"))

@@ -95,7 +100,7 @@ return [];

exports.transformController = transformController;
async function transformModule(path) {
async function transformModule(path, extensions) {
//read all files and get module reflection
const modules = await Promise.all(resolvePath(path)
const modules = await Promise.all(resolvePath(path, extensions)
//reflect the file
.map(x => reflect_1.reflect(x)));
.map(x => tinspector_1.reflect(x)));
//get all module.members and combine into one array

@@ -150,3 +155,3 @@ return modules.reduce((a, b) => a.concat(b.members), [])

return par.filter(x => x.typeAnnotation && framework_1.isCustomClass(x.typeAnnotation))
.map(x => reflect_1.reflect(x.typeAnnotation));
.map(x => tinspector_1.reflect(x.typeAnnotation));
}

@@ -160,11 +165,10 @@ function traverseModel(par) {

}
// function getArrayInParameters(par:ParameterReflection[]){
// return par.filter((x) => x.typeAnnotation == Array)
// function getArrayInParameter(par:ParameterReflection){
// return Boolean(par.typeAnnotation == Array && par.decorators
// .find((x):x is ArrayBindingDecorator => x.type == "ParameterBinding" && x.name == "Array" ))
// }
// function traverseArray(par: ParameterReflection) {
// const array = par.decorators.find((x): x is ArrayBindingDecorator => x.type == "ParameterBinding" && x.name == "Array")
// if(array){
// const reflection = reflect(array.typeAnnotation)
// return traverseModel(reflection.ctorParameters)
// }
// function traverseArray(par: ParameterReflection[]) {
// const parameterArray = par.filter(x => getArrayInParameter(x))
// const models = getModelsInParameters(parameterArray)
// const modelContained =
// }

@@ -171,0 +175,0 @@ //-----

{
"name": "plumier",
"version": "0.1.0-alpha.ad52811b",
"description": "A testing friendly Web API framework",
"main": "index.js",
"version": "0.1.0-alpha.b123904d",
"description": "Pleasant TypeScript Web Api Framework",
"main": "lib/index.js",
"keywords": [

@@ -16,3 +16,5 @@ "MVC",

"scripts": {
"compile": "tsc -p tsconfig.build.json"
"compile": "tsc -p tsconfig.build.json",
"package-prod": "node ../../.script/modify-package.js production",
"package-dev": "node ../../.script/modify-package.js"
},

@@ -28,2 +30,3 @@ "author": "Ketut Sandiarsa",

"@types/koa__cors": "^2.2.2",
"@types/validator": "^9.4.1",
"chalk": "^2.4.1",

@@ -34,4 +37,5 @@ "debug": "^3.1.0",

"path-to-regexp": "^2.2.1",
"reflect-metadata": "^0.1.12",
"tslib": "^1.9.2"
"tinspector": "1.4.0-alpha.b123904d",
"tslib": "^1.9.2",
"validator": "^10.4.0"
},

@@ -41,4 +45,6 @@ "devDependencies": {

"benalu": "^2.0.0-beta-1",
"edit-json-file": "^1.0.8",
"supertest": "^3.1.0"
}
},
"types": "lib/index.d.ts"
}
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