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

@plumier/core

Package Overview
Dependencies
Maintainers
1
Versions
645
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plumier/core - npm Package Compare versions

Comparing version 1.0.1-canary.36 to 1.0.1-canary.40

11

lib/common.d.ts
import glob from "glob";
declare type Class<T = any> = new (...args: any[]) => T;
interface ClassWithRoot {
root: string;
type: Class;
}
declare global {

@@ -19,2 +23,7 @@ interface String {

declare function findFilesRecursive(path: string): Promise<string[]>;
declare function appendRoute(...args: string[]): string;
declare function findClassRecursive(path: string | string[] | Class | Class[], option?: {
directoryAsPath?: boolean;
rootDir?: string;
}): Promise<ClassWithRoot[]>;
interface ColumnMeta {

@@ -57,2 +66,2 @@ align?: "left" | "right";

}
export { ellipsis, toBoolean, getChildValue, Class, hasKeyOf, isCustomClass, entityHelper, findFilesRecursive, memoize, printTable, analyzeModel, AnalysisMessage, globAsync, EntityRelationInfo, OneToManyRelationInfo, ManyToOneRelationInfo };
export { ellipsis, toBoolean, getChildValue, Class, hasKeyOf, isCustomClass, entityHelper, findFilesRecursive, memoize, printTable, analyzeModel, AnalysisMessage, globAsync, EntityRelationInfo, OneToManyRelationInfo, ManyToOneRelationInfo, appendRoute, findClassRecursive, ClassWithRoot };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.globAsync = exports.analyzeModel = exports.printTable = exports.memoize = exports.findFilesRecursive = exports.entityHelper = exports.isCustomClass = exports.hasKeyOf = exports.getChildValue = exports.toBoolean = exports.ellipsis = void 0;
exports.findClassRecursive = exports.appendRoute = exports.globAsync = exports.analyzeModel = exports.printTable = exports.memoize = exports.findFilesRecursive = exports.entityHelper = exports.isCustomClass = exports.hasKeyOf = exports.getChildValue = exports.toBoolean = exports.ellipsis = void 0;
const tslib_1 = require("tslib");

@@ -10,2 +10,3 @@ const fs_1 = require("fs");

const types_1 = require("./types");
const path_1 = require("path");
const lstatAsync = util_1.promisify(fs_1.lstat);

@@ -99,2 +100,48 @@ const existsAsync = util_1.promisify(fs_1.exists);

exports.findFilesRecursive = findFilesRecursive;
function appendRoute(...args) {
return "/" + args
.filter(x => !!x)
.map(x => x.toLowerCase())
.map(x => x.startsWith("/") ? x.slice(1) : x)
.map(x => x.endsWith("/") ? x.slice(0, -1) : x)
.filter(x => !!x)
.join("/");
}
exports.appendRoute = appendRoute;
function getRoot(rootPath, path) {
// directoryAsPath should not working with glob
if (rootPath.indexOf("*") >= 0)
return;
const part = path.slice(rootPath.length).split("/").filter(x => !!x)
.slice(0, -1);
return (part.length === 0) ? undefined : appendRoute(...part);
}
async function findClassRecursive(path, option) {
var _a;
const opt = Object.assign({ rootDir: "", directoryAsPath: false }, option);
if (Array.isArray(path)) {
const result = [];
for (const p of path) {
result.push(...await findClassRecursive(p, opt));
}
return result;
}
if (typeof path === "string") {
const absPath = path_1.isAbsolute(path) ? path : path_1.join(opt.rootDir, path);
//read all files and get module reflection
const files = await findFilesRecursive(absPath);
const result = [];
for (const file of files) {
const root = !!opt.directoryAsPath ? ((_a = getRoot(absPath, file)) !== null && _a !== void 0 ? _a : "") : "";
for (const member of reflect_1.default(file).members) {
if (member.kind === "Class")
result.push({ root, type: member.type });
}
}
return result;
}
else
return [{ root: "", type: path }];
}
exports.findClassRecursive = findClassRecursive;
function printTable(meta, data, option) {

@@ -101,0 +148,0 @@ const getText = (col, row) => {

4

lib/index.d.ts

@@ -9,6 +9,6 @@ import { val } from "@plumier/validator";

export { response } from "./response";
export { generateRoutes, findClassRecursive, appendRoute, IgnoreDecorator, RouteDecorator, transformController, ControllerTransformOption } from "./route-generator";
export { generateRoutes, IgnoreDecorator, RouteDecorator, transformController, ControllerTransformOption } from "./route-generator";
export { analyzeRoutes, printAnalysis } from "./route-analyzer";
export { router } from "./router";
export { Class, findFilesRecursive, getChildValue, hasKeyOf, isCustomClass, printTable, toBoolean, ellipsis, analyzeModel, AnalysisMessage, entityHelper, globAsync, EntityRelationInfo, OneToManyRelationInfo, ManyToOneRelationInfo } from "./common";
export { Class, findFilesRecursive, getChildValue, hasKeyOf, isCustomClass, printTable, toBoolean, ellipsis, analyzeModel, AnalysisMessage, entityHelper, globAsync, EntityRelationInfo, OneToManyRelationInfo, ManyToOneRelationInfo, findClassRecursive, appendRoute, ClassWithRoot } from "./common";
export { AuthDecoratorImpl, authorize } from "./decorator/authorize";

@@ -15,0 +15,0 @@ export { ApiDescriptionDecorator, ApiEnumDecorator, ApiFieldNameDecorator, ApiRequiredDecorator, ApiResponseDecorator, ApiTagDecorator, api, ApiReadOnlyDecorator, ApiWriteOnlyDecorator, ApiHideRelationDecorator } from "./decorator/api";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.entityProvider = exports.middleware = exports.domain = exports.bind = exports.api = exports.authorize = exports.AuthDecoratorImpl = exports.globAsync = exports.entityHelper = exports.analyzeModel = exports.ellipsis = exports.toBoolean = exports.printTable = exports.isCustomClass = exports.hasKeyOf = exports.getChildValue = exports.findFilesRecursive = exports.router = exports.printAnalysis = exports.analyzeRoutes = exports.transformController = exports.appendRoute = exports.findClassRecursive = exports.generateRoutes = exports.response = exports.invoke = exports.ParameterBinderMiddleware = exports.binder = exports.getPolicyInfo = exports.createAuthorizationAnalyzer = exports.analyzeAuthPolicyNameConflict = exports.updateRouteAuthorizationAccess = exports.getRouteAuthorizeDecorators = exports.throwAuthError = exports.createAuthContext = exports.executeAuthorizer = exports.WriteonlyAuthPolicy = exports.ReadonlyAuthPolicy = exports.AuthenticatedAuthPolicy = exports.PublicAuthPolicy = exports.globalPolicies = exports.EntityAuthPolicy = exports.CustomAuthPolicy = exports.Authenticated = exports.Public = exports.PolicyAuthorizer = exports.entityPolicy = exports.authPolicy = exports.checkAuthorize = exports.val = void 0;
exports.entityProvider = exports.middleware = exports.domain = exports.bind = exports.api = exports.authorize = exports.AuthDecoratorImpl = exports.appendRoute = exports.findClassRecursive = exports.globAsync = exports.entityHelper = exports.analyzeModel = exports.ellipsis = exports.toBoolean = exports.printTable = exports.isCustomClass = exports.hasKeyOf = exports.getChildValue = exports.findFilesRecursive = exports.router = exports.printAnalysis = exports.analyzeRoutes = exports.transformController = exports.generateRoutes = exports.response = exports.invoke = exports.ParameterBinderMiddleware = exports.binder = exports.getPolicyInfo = exports.createAuthorizationAnalyzer = exports.analyzeAuthPolicyNameConflict = exports.updateRouteAuthorizationAccess = exports.getRouteAuthorizeDecorators = exports.throwAuthError = exports.createAuthContext = exports.executeAuthorizer = exports.WriteonlyAuthPolicy = exports.ReadonlyAuthPolicy = exports.AuthenticatedAuthPolicy = exports.PublicAuthPolicy = exports.globalPolicies = exports.EntityAuthPolicy = exports.CustomAuthPolicy = exports.Authenticated = exports.Public = exports.PolicyAuthorizer = exports.entityPolicy = exports.authPolicy = exports.checkAuthorize = exports.val = void 0;
exports.MetadataImpl = exports.NestedControllerGeneric = exports.ControllerGeneric = exports.FormFile = exports.DefaultDependencyResolver = exports.errorMessage = exports.ValidationError = exports.RedirectActionResult = exports.MiddlewareUtil = exports.HttpStatusError = exports.DefaultFacility = exports.ActionResult = exports.ValidatorMiddleware = exports.validate = exports.HttpStatus = exports.meta = exports.postSave = exports.preSave = exports.entity = exports.RouteDecoratorImpl = exports.route = exports.responseType = void 0;

@@ -41,4 +41,2 @@ // TypeScript bug https://github.com/microsoft/TypeScript/issues/18877

Object.defineProperty(exports, "generateRoutes", { enumerable: true, get: function () { return route_generator_1.generateRoutes; } });
Object.defineProperty(exports, "findClassRecursive", { enumerable: true, get: function () { return route_generator_1.findClassRecursive; } });
Object.defineProperty(exports, "appendRoute", { enumerable: true, get: function () { return route_generator_1.appendRoute; } });
Object.defineProperty(exports, "transformController", { enumerable: true, get: function () { return route_generator_1.transformController; } });

@@ -61,2 +59,4 @@ var route_analyzer_1 = require("./route-analyzer");

Object.defineProperty(exports, "globAsync", { enumerable: true, get: function () { return common_1.globAsync; } });
Object.defineProperty(exports, "findClassRecursive", { enumerable: true, get: function () { return common_1.findClassRecursive; } });
Object.defineProperty(exports, "appendRoute", { enumerable: true, get: function () { return common_1.appendRoute; } });
var authorize_1 = require("./decorator/authorize");

@@ -63,0 +63,0 @@ Object.defineProperty(exports, "AuthDecoratorImpl", { enumerable: true, get: function () { return authorize_1.AuthDecoratorImpl; } });

@@ -25,10 +25,4 @@ import { Class } from "./common";

}
interface ClassWithRoot {
root: string;
type: Class;
}
declare function appendRoute(...args: string[]): string;
declare function findClassRecursive(path: string): Promise<ClassWithRoot[]>;
declare function transformController(object: Class, opt: ControllerTransformOption): RouteInfo[];
declare function generateRoutes(controller: string | string[] | Class[] | Class, option?: Partial<ControllerTransformOption>): Promise<RouteMetadata[]>;
export { generateRoutes, transformController, RouteDecorator, IgnoreDecorator, RootDecorator, appendRoute, findClassRecursive, ControllerTransformOption };
export { generateRoutes, transformController, RouteDecorator, IgnoreDecorator, RootDecorator, ControllerTransformOption };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findClassRecursive = exports.appendRoute = exports.transformController = exports.generateRoutes = void 0;
exports.transformController = exports.generateRoutes = void 0;
const reflect_1 = require("@plumier/reflect");
const path_1 = require("path");
const common_1 = require("./common");

@@ -10,12 +9,2 @@ /* ------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------- */
function appendRoute(...args) {
return "/" + args
.filter(x => !!x)
.map(x => x.toLowerCase())
.map(x => x.startsWith("/") ? x.slice(1) : x)
.map(x => x.endsWith("/") ? x.slice(0, -1) : x)
.filter(x => !!x)
.join("/");
}
exports.appendRoute = appendRoute;
function striveController(name) {

@@ -36,28 +25,5 @@ return name.replace(/controller$/i, "");

else {
return [{ root: appendRoute(root, striveController(controller.name)), map: {} }];
return [{ root: common_1.appendRoute(root, striveController(controller.name)), map: {} }];
}
}
function getRoot(rootPath, path) {
// directoryAsPath should not working with glob
if (rootPath.indexOf("*") >= 0)
return;
const part = path.slice(rootPath.length).split("/").filter(x => !!x)
.slice(0, -1);
return (part.length === 0) ? undefined : appendRoute(...part);
}
async function findClassRecursive(path) {
var _a;
//read all files and get module reflection
const files = await common_1.findFilesRecursive(path);
const result = [];
for (const file of files) {
const root = (_a = getRoot(path, file)) !== null && _a !== void 0 ? _a : "";
for (const member of reflect_1.reflect(file).members) {
if (member.kind === "Class")
result.push({ root, type: member.type });
}
}
return result;
}
exports.findClassRecursive = findClassRecursive;
class ParamMapper {

@@ -89,3 +55,3 @@ constructor(map) {

else {
return appendRoute(root, actionDecorator.url || actionName.toLowerCase());
return common_1.appendRoute(root, actionDecorator.url || actionName.toLowerCase());
}

@@ -110,3 +76,3 @@ }

group, method: "get",
url: appendRoute(root.root, method.name),
url: common_1.appendRoute(root.root, method.name),
controller,

@@ -142,25 +108,4 @@ action: method,

async function extractController(controller, option) {
if (typeof controller === "string") {
const ctl = path_1.isAbsolute(controller) ? controller : path_1.join(option.rootDir, controller);
const types = await findClassRecursive(ctl);
const result = [];
for (const type of types) {
const ctl = await extractController(type.type, option);
result.push(...ctl.map(x => ({
root: option.directoryAsPath ? type.root : "",
type: x.type
})));
}
return result;
}
else if (Array.isArray(controller)) {
const raw = controller;
const controllers = await Promise.all(raw.map(x => extractController(x, option)));
return controllers.flatten();
}
// common controller
if (isController(controller)) {
return [{ root: "", type: controller }];
}
return [];
const classes = await common_1.findClassRecursive(controller, option);
return classes.filter(x => isController(x.type));
}

@@ -172,3 +117,3 @@ async function generateRoutes(controller, option) {

for (const controller of controllers) {
routes.push(...transformController(controller.type, Object.assign(Object.assign({}, opt), { rootPath: appendRoute(controller.root, opt.rootPath) })));
routes.push(...transformController(controller.type, Object.assign(Object.assign({}, opt), { rootPath: common_1.appendRoute(controller.root, opt.rootPath) })));
}

@@ -175,0 +120,0 @@ return routes;

{
"name": "@plumier/core",
"version": "1.0.1-canary.36+b66ea12",
"version": "1.0.1-canary.40+fb4a744",
"description": "Delightful Node.js Rest Framework",

@@ -23,4 +23,4 @@ "main": "lib/index.js",

"dependencies": {
"@plumier/reflect": "1.0.1-canary.36+b66ea12",
"@plumier/validator": "1.0.1-canary.36+b66ea12",
"@plumier/reflect": "1.0.1-canary.40+fb4a744",
"@plumier/validator": "1.0.1-canary.40+fb4a744",
"@types/debug": "^4.1.5",

@@ -50,3 +50,3 @@ "@types/glob": "^7.1.3",

},
"gitHead": "b66ea12dccb85cd9e4e681a5860092f9dad71082"
"gitHead": "fb4a74482849071075ff3455a612022b7c9c88a3"
}
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