Comparing version 2.2.17 to 2.2.18
@@ -10,2 +10,10 @@ export declare enum HttpStatusCode { | ||
} | ||
export declare enum RequestMethod { | ||
GET = "GET", | ||
POST = "POST", | ||
PATCH = "PATCH", | ||
DELETE = "DELETE", | ||
PUT = "PUT", | ||
ALL = "ALL" | ||
} | ||
export declare enum APiType { | ||
@@ -12,0 +20,0 @@ error = "ERROR", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextCodes = exports.APiError = exports.APiSuccess = exports.APiResponse = exports.APiType = exports.HttpStatusCode = void 0; | ||
var HttpStatusCode; | ||
@@ -14,2 +13,11 @@ (function (HttpStatusCode) { | ||
})(HttpStatusCode = exports.HttpStatusCode || (exports.HttpStatusCode = {})); | ||
var RequestMethod; | ||
(function (RequestMethod) { | ||
RequestMethod["GET"] = "GET"; | ||
RequestMethod["POST"] = "POST"; | ||
RequestMethod["PATCH"] = "PATCH"; | ||
RequestMethod["DELETE"] = "DELETE"; | ||
RequestMethod["PUT"] = "PUT"; | ||
RequestMethod["ALL"] = "ALL"; | ||
})(RequestMethod = exports.RequestMethod || (exports.RequestMethod = {})); | ||
var APiType; | ||
@@ -16,0 +24,0 @@ (function (APiType) { |
@@ -12,3 +12,3 @@ /** | ||
import Router from "./Router"; | ||
import { MiddleWareInterface, CorsInterface } from "./interfaces/index"; | ||
import { MiddleWareInterface, CorsInterface, MiddleWareOptions } from './interfaces/index'; | ||
declare const GET: (options?: { | ||
@@ -40,2 +40,3 @@ url: string; | ||
declare const MiddleWare: (target: Router, key: string) => void; | ||
export { MiddleWare, GET, PUT, POST, PATCH, DELETE }; | ||
declare const RouteMiddleWare: (options: MiddleWareOptions) => (target: Router, key: string) => void; | ||
export { MiddleWare, GET, PUT, POST, PATCH, DELETE, RouteMiddleWare }; |
@@ -13,3 +13,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DELETE = exports.PATCH = exports.POST = exports.PUT = exports.GET = exports.MiddleWare = void 0; | ||
// GET Decorator | ||
@@ -65,1 +64,11 @@ const decorator = (options, routersType, methodType) => { | ||
exports.MiddleWare = MiddleWare; | ||
const RouteMiddleWare = (options) => { | ||
return (target, key) => { | ||
target.tempMiddleWares = target.tempMiddleWares || []; | ||
target.tempMiddleWares.push({ | ||
middleWare: target[key], | ||
options: options | ||
}); | ||
}; | ||
}; | ||
exports.RouteMiddleWare = RouteMiddleWare; |
@@ -17,5 +17,5 @@ /** | ||
import FileUpload from './fileupload'; | ||
import { GET, POST, PUT, PATCH, DELETE, MiddleWare } from "./decorators"; | ||
import { IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, TextCodes } from "./common"; | ||
import { Constructable } from "interfaces"; | ||
import { GET, POST, PUT, PATCH, DELETE, MiddleWare, RouteMiddleWare } from "./decorators"; | ||
import { IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, TextCodes, RequestMethod } from "./common"; | ||
import { Constructable, MiddleWareOptions } from "interfaces"; | ||
declare const validation: { | ||
@@ -36,2 +36,2 @@ strip_html_tags: (str: string) => string | false; | ||
}; | ||
export { Server, Router, View, Request, Response, validation, Cipher, FileUpload, GET, POST, PUT, PATCH, DELETE, MiddleWare, IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, Constructable, TextCodes }; | ||
export { Server, Router, View, Request, Response, validation, Cipher, FileUpload, GET, POST, PUT, PATCH, DELETE, MiddleWare, RouteMiddleWare, IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, Constructable, TextCodes, RequestMethod, MiddleWareOptions }; |
@@ -6,3 +6,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextCodes = exports.APiType = exports.HttpStatusCode = exports.APiResponse = exports.APiSuccess = exports.APiError = exports.MiddleWare = exports.DELETE = exports.PATCH = exports.PUT = exports.POST = exports.GET = exports.FileUpload = exports.Cipher = exports.validation = exports.Response = exports.Request = exports.View = exports.Router = exports.Server = void 0; | ||
/** | ||
@@ -19,7 +18,7 @@ * @package @Grandjs | ||
const Server_1 = require("./Server"); | ||
Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } }); | ||
exports.Server = Server_1.Server; | ||
const Router_1 = __importDefault(require("./Router")); | ||
exports.Router = Router_1.default; | ||
const View_1 = require("./View"); | ||
Object.defineProperty(exports, "View", { enumerable: true, get: function () { return View_1.View; } }); | ||
exports.View = View_1.View; | ||
const Request_1 = __importDefault(require("./Request")); | ||
@@ -33,15 +32,17 @@ exports.Request = Request_1.default; | ||
const decorators_1 = require("./decorators"); | ||
Object.defineProperty(exports, "GET", { enumerable: true, get: function () { return decorators_1.GET; } }); | ||
Object.defineProperty(exports, "POST", { enumerable: true, get: function () { return decorators_1.POST; } }); | ||
Object.defineProperty(exports, "PUT", { enumerable: true, get: function () { return decorators_1.PUT; } }); | ||
Object.defineProperty(exports, "PATCH", { enumerable: true, get: function () { return decorators_1.PATCH; } }); | ||
Object.defineProperty(exports, "DELETE", { enumerable: true, get: function () { return decorators_1.DELETE; } }); | ||
Object.defineProperty(exports, "MiddleWare", { enumerable: true, get: function () { return decorators_1.MiddleWare; } }); | ||
exports.GET = decorators_1.GET; | ||
exports.POST = decorators_1.POST; | ||
exports.PUT = decorators_1.PUT; | ||
exports.PATCH = decorators_1.PATCH; | ||
exports.DELETE = decorators_1.DELETE; | ||
exports.MiddleWare = decorators_1.MiddleWare; | ||
exports.RouteMiddleWare = decorators_1.RouteMiddleWare; | ||
const common_1 = require("./common"); | ||
Object.defineProperty(exports, "APiError", { enumerable: true, get: function () { return common_1.APiError; } }); | ||
Object.defineProperty(exports, "APiSuccess", { enumerable: true, get: function () { return common_1.APiSuccess; } }); | ||
Object.defineProperty(exports, "APiResponse", { enumerable: true, get: function () { return common_1.APiResponse; } }); | ||
Object.defineProperty(exports, "HttpStatusCode", { enumerable: true, get: function () { return common_1.HttpStatusCode; } }); | ||
Object.defineProperty(exports, "APiType", { enumerable: true, get: function () { return common_1.APiType; } }); | ||
Object.defineProperty(exports, "TextCodes", { enumerable: true, get: function () { return common_1.TextCodes; } }); | ||
exports.APiError = common_1.APiError; | ||
exports.APiSuccess = common_1.APiSuccess; | ||
exports.APiResponse = common_1.APiResponse; | ||
exports.HttpStatusCode = common_1.HttpStatusCode; | ||
exports.APiType = common_1.APiType; | ||
exports.TextCodes = common_1.TextCodes; | ||
exports.RequestMethod = common_1.RequestMethod; | ||
const validation = helpers_1.default.validation; | ||
@@ -48,0 +49,0 @@ exports.validation = validation; |
@@ -19,2 +19,3 @@ /// <reference types="node" /> | ||
import RequestParser from "../requestParser"; | ||
import { RequestMethod } from '../common'; | ||
export interface OptionalObject { | ||
@@ -78,2 +79,6 @@ [key: string]: any; | ||
} | ||
export interface MiddleWareOptions { | ||
method: RequestMethod; | ||
url: string; | ||
} | ||
export interface StaticFolderInterface { | ||
@@ -83,2 +88,6 @@ path: string; | ||
} | ||
export interface TempMiddleWares { | ||
middleWare: MiddleWareInterface; | ||
options: MiddleWareOptions; | ||
} | ||
export interface RouterInterface { | ||
@@ -125,2 +134,4 @@ [key: string]: any; | ||
assignChildRouterRoutes(childRouter: Router): this; | ||
tempMiddleWares: TempMiddleWares[]; | ||
parseTempMiddleWares(): any; | ||
} | ||
@@ -127,0 +138,0 @@ export interface ServerConfigurations { |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
import { RouterInterface, CorsInterface, MiddleWareInterface, StaticFolderInterface, ServerConfigurations } from './interfaces/index'; | ||
import { RouterInterface, CorsInterface, MiddleWareInterface, StaticFolderInterface, ServerConfigurations, TempMiddleWares } from './interfaces/index'; | ||
import Request from "./Request"; | ||
@@ -37,2 +37,3 @@ import Response from "./Response"; | ||
child: boolean; | ||
tempMiddleWares: TempMiddleWares[]; | ||
constructor(options?: { | ||
@@ -44,2 +45,3 @@ base?: string; | ||
build(): this; | ||
parseTempMiddleWares(): void; | ||
init(): this; | ||
@@ -46,0 +48,0 @@ chooseRoute(req: Request, res: Response): any; |
@@ -23,2 +23,3 @@ "use strict"; | ||
const helpers_1 = __importDefault(require("./helpers")); | ||
const common_1 = require("./common"); | ||
class Router { | ||
@@ -49,2 +50,3 @@ constructor(options) { | ||
}; | ||
this.tempMiddleWares = this.tempMiddleWares || []; | ||
this.options = options || {}; | ||
@@ -63,2 +65,3 @@ this.setBase(); | ||
this.staticFolder = this.options.staticFolder || this.staticFolder; | ||
this.parseTempMiddleWares(); | ||
} | ||
@@ -80,2 +83,83 @@ use(func) { | ||
} | ||
// parsee temp middleWares | ||
parseTempMiddleWares() { | ||
this.tempMiddleWares.forEach((obj, i) => { | ||
const { options: { method, url } } = obj; | ||
let getRouters = []; | ||
let postRouters = []; | ||
let putRouters = []; | ||
let patchRouters = []; | ||
let deleteRouters = []; | ||
if (method === common_1.RequestMethod.ALL) { | ||
if (url === "*") { | ||
this.globalMiddleWares.push(obj.middleWare); | ||
} | ||
else { | ||
getRouters = this.getRouters.filter(route => route.url === url ? route : null); | ||
postRouters = this.postRouters.filter(route => route.url === url ? route : null); | ||
putRouters = this.putRouters.filter(route => route.url === url ? route : null); | ||
patchRouters = this.patchRouters.filter(route => route.url === url ? route : null); | ||
deleteRouters = this.deleteRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
else { | ||
if (method === common_1.RequestMethod.GET) { | ||
if (url === "*") { | ||
getRouters = this.getRouters; | ||
} | ||
else { | ||
getRouters = this.getRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
else if (method === common_1.RequestMethod.POST) { | ||
if (url === "*") { | ||
postRouters = this.postRouters; | ||
} | ||
else { | ||
postRouters = this.postRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
else if (method === common_1.RequestMethod.PUT) { | ||
if (url === "*") { | ||
putRouters = this.putRouters; | ||
} | ||
else { | ||
putRouters = this.putRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
else if (method === common_1.RequestMethod.PATCH) { | ||
if (url === "*") { | ||
patchRouters = this.patchRouters; | ||
} | ||
else { | ||
patchRouters = this.patchRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
else if (method === common_1.RequestMethod.DELETE) { | ||
if (url === "*") { | ||
deleteRouters = this.deleteRouters; | ||
} | ||
else { | ||
deleteRouters = this.deleteRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
} | ||
getRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
postRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
patchRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
putRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
deleteRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
}); | ||
this.tempMiddleWares = []; | ||
} | ||
init() { | ||
@@ -82,0 +166,0 @@ this.chooseRoute(this.req, this.res); |
@@ -6,3 +6,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseServer = exports.Server = void 0; | ||
/** | ||
@@ -9,0 +8,0 @@ * @package @Grandjs |
@@ -6,3 +6,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.View = void 0; | ||
/** | ||
@@ -9,0 +8,0 @@ * @package @Grandjs |
{ | ||
"name": "grandjs", | ||
"version": "2.2.17", | ||
"version": "2.2.18", | ||
"description": "A backend framework for solid web apps based on node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -10,3 +10,10 @@ export enum HttpStatusCode { | ||
} | ||
export enum RequestMethod { | ||
GET = 'GET', | ||
POST = 'POST', | ||
PATCH = 'PATCH', | ||
DELETE = 'DELETE', | ||
PUT = 'PUT', | ||
ALL = 'ALL' | ||
} | ||
export enum APiType{ | ||
@@ -13,0 +20,0 @@ error = "ERROR", |
@@ -14,3 +14,4 @@ /** | ||
import Router from "./Router"; | ||
import {MiddleWareInterface, CorsInterface} from "./interfaces/index"; | ||
import { MiddleWareInterface, CorsInterface, TempMiddleWares, MiddleWareOptions } from './interfaces/index'; | ||
import { RequestMethod } from './common'; | ||
// GET Decorator | ||
@@ -62,3 +63,11 @@ | ||
} | ||
export {MiddleWare, GET, PUT, POST, PATCH, DELETE} | ||
const RouteMiddleWare = (options: MiddleWareOptions) => { | ||
return (target: Router, key: string) => { | ||
target.tempMiddleWares = target.tempMiddleWares || []; | ||
target.tempMiddleWares.push({ | ||
middleWare: target[key], | ||
options: options | ||
}) | ||
} | ||
} | ||
export {MiddleWare, GET, PUT, POST, PATCH, DELETE, RouteMiddleWare} |
@@ -18,9 +18,9 @@ /** | ||
import FileUpload from './fileupload'; | ||
import {GET, POST, PUT, PATCH, DELETE, MiddleWare} from "./decorators"; | ||
import {IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, TextCodes} from "./common" | ||
import {Constructable} from "interfaces" | ||
import {GET, POST, PUT, PATCH, DELETE, MiddleWare, RouteMiddleWare} from "./decorators"; | ||
import {IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, TextCodes, RequestMethod} from "./common" | ||
import {Constructable, MiddleWareOptions} from "interfaces" | ||
const validation = helpers.validation; | ||
const Cipher = helpers.Cipher; | ||
export {Server, Router, View, Request, Response, validation, Cipher, FileUpload, GET, POST, PUT, PATCH, DELETE, MiddleWare, IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, Constructable, TextCodes}; | ||
export {Server, Router, View, Request, Response, validation, Cipher, FileUpload, GET, POST, PUT, PATCH, DELETE, MiddleWare, RouteMiddleWare, IResponse, APiError, APiSuccess, APiResponse, APiResponseInterface, HttpStatusCode, APiType, Constructable, TextCodes, RequestMethod, MiddleWareOptions}; | ||
@@ -19,2 +19,3 @@ /** | ||
import RequestParser from "../requestParser"; | ||
import { RequestMethod } from '../common'; | ||
export interface OptionalObject { | ||
@@ -74,2 +75,3 @@ [key:string]:any | ||
} | ||
export interface MiddleWareOptions {method: RequestMethod, url: string} | ||
export interface StaticFolderInterface{ | ||
@@ -79,2 +81,6 @@ path: string, | ||
} | ||
export interface TempMiddleWares{ | ||
middleWare: MiddleWareInterface | ||
options: MiddleWareOptions | ||
} | ||
export interface RouterInterface { | ||
@@ -115,3 +121,5 @@ [key:string]:any | ||
static(options:{url:string, path:string, absolute?:boolean, middleWares:[]}):any | ||
assignChildRouterRoutes(childRouter:Router):this | ||
assignChildRouterRoutes(childRouter: Router): this | ||
tempMiddleWares: TempMiddleWares[] | ||
parseTempMiddleWares():any | ||
} | ||
@@ -118,0 +126,0 @@ export interface ServerConfigurations{ |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
import { RouterInterface, CorsInterface, MiddleWareInterface, RequestInterface, ResponseInterface, RouteInterface, StaticFolderInterface, ServerConfigurations} from './interfaces/index'; | ||
import { RouterInterface, CorsInterface, MiddleWareInterface, RequestInterface, ResponseInterface, RouteInterface, StaticFolderInterface, ServerConfigurations, TempMiddleWares } from './interfaces/index'; | ||
import path from "path"; | ||
@@ -23,4 +23,4 @@ import cors from "cors"; | ||
import Route from "./Route"; | ||
import UrlPattern from 'url-pattern'; | ||
import helpers from './helpers'; | ||
import { RequestMethod } from './common'; | ||
class Router implements RouterInterface { | ||
@@ -46,4 +46,6 @@ [key:string]:any | ||
statics: Route[] | ||
child:boolean = false; | ||
child: boolean = false; | ||
tempMiddleWares: TempMiddleWares[] | ||
constructor(options?: { base?: string, staticFolder?: StaticFolderInterface }) { | ||
this.tempMiddleWares = this.tempMiddleWares || []; | ||
this.options = options || {}; | ||
@@ -62,2 +64,3 @@ this.setBase(); | ||
this.staticFolder = this.options.staticFolder || this.staticFolder; | ||
this.parseTempMiddleWares(); | ||
} | ||
@@ -79,2 +82,72 @@ use(func: MiddleWareInterface): this { | ||
} | ||
// parsee temp middleWares | ||
parseTempMiddleWares() { | ||
this.tempMiddleWares.forEach((obj, i) => { | ||
const { options: { method, url } } = obj; | ||
let getRouters:Route[] = []; | ||
let postRouters:Route[] = []; | ||
let putRouters:Route[] = []; | ||
let patchRouters:Route[] = []; | ||
let deleteRouters:Route[] = []; | ||
if (method === RequestMethod.ALL) { | ||
if (url === "*") { | ||
this.globalMiddleWares.push(obj.middleWare); | ||
} else { | ||
getRouters = this.getRouters.filter(route => route.url === url ? route : null); | ||
postRouters = this.postRouters.filter(route => route.url === url ? route : null); | ||
putRouters = this.putRouters.filter(route => route.url === url ? route : null); | ||
patchRouters = this.patchRouters.filter(route => route.url === url ? route : null); | ||
deleteRouters = this.deleteRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} else { | ||
if (method === RequestMethod.GET) { | ||
if (url === "*") { | ||
getRouters = this.getRouters; | ||
} else { | ||
getRouters = this.getRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} else if (method === RequestMethod.POST) { | ||
if (url === "*") { | ||
postRouters = this.postRouters; | ||
} else { | ||
postRouters = this.postRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} else if (method === RequestMethod.PUT) { | ||
if (url === "*") { | ||
putRouters = this.putRouters; | ||
} else { | ||
putRouters = this.putRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} else if (method === RequestMethod.PATCH) { | ||
if (url === "*") { | ||
patchRouters = this.patchRouters; | ||
} else { | ||
patchRouters = this.patchRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} else if (method === RequestMethod.DELETE) { | ||
if (url === "*") { | ||
deleteRouters = this.deleteRouters; | ||
} else { | ||
deleteRouters = this.deleteRouters.filter(route => route.url === url ? route : null); | ||
} | ||
} | ||
} | ||
getRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
postRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
patchRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
putRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
deleteRouters.forEach((route) => { | ||
route.middleWares.push(obj.middleWare); | ||
}); | ||
}) | ||
this.tempMiddleWares = []; | ||
} | ||
public init(): this { | ||
@@ -81,0 +154,0 @@ this.chooseRoute(this.req, this.res); |
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
256530
5573