kamboja-core
Advanced tools
Comparing version 0.4.0 to 0.5.0-alpha.40636165
@@ -1,80 +0,35 @@ | ||
/// <reference types="node" /> | ||
export { Application, BaseController, Engine, Facility, Invocation, KambojaOption, LogType, MethodDecorator, Middleware, MiddlewaresType, Response, MiddlewareFunction, InvocationBase } from "./framework"; | ||
export { Cookie, CookieOptions, HttpError, HttpMethod, HttpRequest } from "./http"; | ||
export { DependencyResolver, IdentifierResolver, PathResolver } from "./resolver"; | ||
export { AnalysisMessage, ControllerInfo, MetaDataLoaderCategory, MetaDataStorage, OverrideRequest, QualifiedClassMetaData, RouteAnalysisCode, TransformerName, TransformStatus } from "./router"; | ||
export { AuthUser, AuthUserStore } from "./security"; | ||
export { Handshake, SocketEvent, SocketRegistry } from "./socket"; | ||
export { FieldValidatorArg, ValidationTypesAccepted, Validator } from "./validator"; | ||
import { Cookie, CookieOptions, HttpRequest, HttpMethod } from "./http"; | ||
import { Handshake, SocketEvent } from "./socket"; | ||
import { Response, Facility, MiddlewaresType } from "./framework"; | ||
import { TransformerName, OverrideRequest, MetaDataStorage, TransformStatus } from "./router"; | ||
import { MethodMetaData, ClassMetaData } from "kecubung"; | ||
import * as Kecubung from "kecubung"; | ||
import * as Url from "url"; | ||
import "reflect-metadata"; | ||
export declare type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "EVENT"; | ||
export declare type TransformStatus = "ExitWithResult" | "Next" | "Exit"; | ||
export declare type TransformerName = "DefaultAction" | "IndexAction" | "HttpMethodDecorator" | "ApiConvention" | "InternalDecorator" | "Controller" | "ControllerWithDecorator" | "Module"; | ||
export declare type MetaDataLoaderCategory = "Controller" | "Model"; | ||
export declare const ValidationTypesAccepted: string[]; | ||
export declare type LogType = "Info" | "Warning" | "Error" | "None"; | ||
export declare type MiddlewaresType = string | string[] | Middleware | Middleware[]; | ||
export declare type MiddlewareFactory = (opt: KambojaOption) => MiddlewaresType; | ||
export declare const MethodDecorator: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
export declare class Decorator { | ||
/** | ||
* Add type metadata information | ||
* @param typ Qualified name of the type | ||
*/ | ||
type(typ: string): (...target: any[]) => void; | ||
import { DependencyResolver, IdentifierResolver, PathResolver } from "./resolver"; | ||
import { ValidatorCommand, FieldValidatorArg } from "./validator"; | ||
import { AuthUserStore } from "./security"; | ||
export declare class ActionResult { | ||
body: any; | ||
status: number | undefined; | ||
type: string | undefined; | ||
engine: "Express" | "General"; | ||
header: { | ||
[key: string]: string | string[]; | ||
}; | ||
cookies?: Cookie[]; | ||
events?: SocketEvent[]; | ||
constructor(body: any, status?: number | undefined, type?: string | undefined); | ||
setHeader(key: string, value: string | string[]): this; | ||
setCookie(key: string, value: string, options?: CookieOptions): this; | ||
setStatus(status: number): this; | ||
setType(type: string): this; | ||
broadcast(event: string, data?: any): this; | ||
emit(event: string, id: string | string[], data?: any): this; | ||
execute(context: HttpRequest | Handshake, response: Response, routeInfo?: RouteInfo): void; | ||
} | ||
export declare class HttpDecorator { | ||
ignore(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
root(route: string): (constructor: Function) => void; | ||
get(route?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
post(route?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
put(route?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
patch(route?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
delete(route?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
on(event: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
} | ||
export declare class BinderDecorator { | ||
body(): (target: any, propertyKey: string, index: number) => void; | ||
cookie(name?: string): (target: any, propertyKey: string, index: number) => void; | ||
} | ||
export declare type DecoratorType = keyof Decorator | keyof HttpDecorator; | ||
export declare namespace RouteAnalysisCode { | ||
/** | ||
* Issue when route parameters doesn't have association | ||
* with action parameters | ||
*/ | ||
const UnAssociatedParameters = 1; | ||
/** | ||
* Only applied on GET method, issue when action contains parameter | ||
* but route doesn't have any | ||
*/ | ||
const MissingRouteParameters = 2; | ||
/** | ||
* Issue when router contains parameter, but action doesn't have any | ||
*/ | ||
const MissingActionParameters = 3; | ||
/** | ||
* Issue when @internal decorator combined with other http method decorator | ||
*/ | ||
const ConflictDecorators = 4; | ||
/** | ||
* API Convention fail because appropriate method name is match with | ||
* method naming convention but the method doesn't have parameters | ||
*/ | ||
const ConventionFail = 5; | ||
const ClassNotInheritedFromController = 6; | ||
const ClassNotExported = 7; | ||
const DuplicateRoutes = 8; | ||
const DuplicateParameterName = 9; | ||
const QueryParameterNotAllowed = 10; | ||
const DecoratorNotAllowed = 11; | ||
} | ||
export interface AnalysisMessage { | ||
code: number; | ||
type: "Error" | "Warning"; | ||
message: string; | ||
} | ||
/** | ||
* ask the next transformer to override each of field if possible | ||
*/ | ||
export declare enum OverrideRequest { | ||
Route = 1, | ||
HttpMethod = 2, | ||
} | ||
export interface RouteInfo { | ||
@@ -102,16 +57,2 @@ /** | ||
} | ||
export interface TransformResult { | ||
status: TransformStatus; | ||
info?: RouteInfo[]; | ||
} | ||
export interface FieldValidatorArg { | ||
value: any; | ||
field: string; | ||
parentField?: string; | ||
decoratorArgs: Kecubung.ValueMetaData[]; | ||
classInfo: Kecubung.ClassMetaData; | ||
} | ||
export interface ValidatorCommand { | ||
validate(args: FieldValidatorArg): ValidationError[] | undefined; | ||
} | ||
export interface Facade { | ||
@@ -123,3 +64,3 @@ dependencyResolver?: DependencyResolver; | ||
metaDataStorage?: MetaDataStorage; | ||
middlewares?: (Middleware | string)[]; | ||
middlewares?: (MiddlewaresType)[]; | ||
autoValidation?: boolean; | ||
@@ -130,21 +71,9 @@ authUserStore?: AuthUserStore; | ||
} | ||
export interface KambojaOption extends Facade { | ||
skipAnalysis?: boolean; | ||
controllerPaths?: string[]; | ||
modelPath?: string; | ||
rootPath: string; | ||
showLog?: LogType; | ||
socketEngine?: Engine; | ||
socketApp?: any; | ||
httpApp?: any; | ||
export interface TransformResult { | ||
status: TransformStatus; | ||
info?: RouteInfo[]; | ||
} | ||
export interface MetaDataStorage { | ||
pathResolver: PathResolver; | ||
get(classId: string): QualifiedClassMetaData | undefined; | ||
getFiles(category: MetaDataLoaderCategory): Kecubung.ParentMetaData[]; | ||
getClasses(category: MetaDataLoaderCategory): QualifiedClassMetaData[]; | ||
export interface ValidatorCommand { | ||
validate(args: FieldValidatorArg): ValidationError[] | undefined; | ||
} | ||
export interface Engine { | ||
init(routes: RouteInfo[], option: KambojaOption): any; | ||
} | ||
export interface ValidationError { | ||
@@ -154,160 +83,1 @@ field: string; | ||
} | ||
export interface Validator { | ||
isValid(): boolean; | ||
getValidationErrors(): ValidationError[] | undefined; | ||
} | ||
export interface SocketRegistry { | ||
register(id: string, alias: string): Promise<void>; | ||
lookup(alias: string): Promise<string>; | ||
} | ||
export interface BaseController { | ||
context: HttpRequest | Handshake; | ||
validator: Validator; | ||
} | ||
export interface AuthUserStore { | ||
save(user: AuthUser): Promise<void>; | ||
get(id: string): Promise<AuthUser>; | ||
} | ||
export interface AuthUser { | ||
readonly id: string; | ||
} | ||
export interface Handshake { | ||
contextType: "Handshake"; | ||
headers: any; | ||
id: string; | ||
rooms: string[]; | ||
user: AuthUser; | ||
params: { | ||
[key: string]: string; | ||
}; | ||
getHeader(key: string): string | undefined; | ||
getParam(key: string): string | undefined; | ||
} | ||
export interface HttpRequest { | ||
contextType: "HttpRequest"; | ||
httpVersion: string; | ||
httpMethod: HttpMethod; | ||
headers: { | ||
[key: string]: string; | ||
}; | ||
cookies: { | ||
[key: string]: string; | ||
}; | ||
params: { | ||
[key: string]: string; | ||
}; | ||
user: AuthUser; | ||
body: any; | ||
referrer: string; | ||
url: Url.Url; | ||
getHeader(key: string): string | undefined; | ||
getCookie(key: string): string | undefined; | ||
getParam(key: string): string | undefined; | ||
getAccepts(key: string | string[]): string | boolean; | ||
isAuthenticated(): boolean; | ||
getUserRole(): string; | ||
route: string; | ||
} | ||
export interface ControllerInfo { | ||
methodMetaData?: MethodMetaData; | ||
classMetaData?: ClassMetaData; | ||
qualifiedClassName?: string; | ||
classId?: any; | ||
} | ||
export interface Cookie { | ||
key: string; | ||
value: string; | ||
options?: CookieOptions; | ||
} | ||
export interface CookieOptions { | ||
maxAge?: number; | ||
signed?: boolean; | ||
expires?: Date | boolean; | ||
httpOnly?: boolean; | ||
path?: string; | ||
domain?: string; | ||
secure?: boolean | "auto"; | ||
} | ||
export interface Response { | ||
send(result: ResponseResult): void; | ||
} | ||
export interface ResponseResult { | ||
body: any; | ||
status?: number; | ||
type?: string; | ||
header?: { | ||
[key: string]: string | string[]; | ||
}; | ||
cookies?: Cookie[]; | ||
events?: SocketEvent[]; | ||
} | ||
export declare class HttpError { | ||
status: number; | ||
error: any; | ||
request: HttpRequest; | ||
response: Response; | ||
constructor(status: number, error: any, request: HttpRequest, response: Response); | ||
} | ||
export declare abstract class Invocation { | ||
abstract proceed(): Promise<ActionResult>; | ||
parameters: any[]; | ||
controllerInfo?: RouteInfo; | ||
middlewares?: Middleware[]; | ||
} | ||
export interface Middleware { | ||
execute(context: Handshake | HttpRequest, next: Invocation): Promise<ActionResult>; | ||
} | ||
export interface Facility { | ||
apply(app: Application): void; | ||
} | ||
export interface Application { | ||
use(middleware: MiddlewaresType): Application; | ||
set(key: keyof KambojaOption, value: any): Application; | ||
get(key: keyof KambojaOption): any; | ||
} | ||
export interface DependencyResolver { | ||
resolve<T>(qualifiedClassName: string): T; | ||
} | ||
export interface IdentifierResolver { | ||
getClassId(qualifiedClassName: string): string; | ||
getClassName(classId: string): string; | ||
} | ||
export interface PathResolver { | ||
resolve(path: string): string; | ||
relative(absolute: string): string; | ||
normalize(path: string): string; | ||
} | ||
export interface SocketEvent { | ||
type: "Broadcast" | "Private"; | ||
name: string; | ||
id?: string | string[]; | ||
payload?: any; | ||
} | ||
export declare class ActionResult implements ResponseResult { | ||
body: any; | ||
status: number | undefined; | ||
type: string | undefined; | ||
engine: "Express" | "General"; | ||
header: { | ||
[key: string]: string | string[]; | ||
}; | ||
cookies?: Cookie[]; | ||
events?: SocketEvent[]; | ||
constructor(body: any, status?: number | undefined, type?: string | undefined); | ||
setHeader(key: string, value: string | string[]): this; | ||
setCookie(key: string, value: string, options?: CookieOptions): this; | ||
setStatus(status: number): this; | ||
setType(type: string): this; | ||
broadcast(event: string, data?: any): this; | ||
emit(event: string, id: string | string[], data?: any): this; | ||
execute(context: HttpRequest | Handshake, response: Response, routeInfo?: RouteInfo): void; | ||
} | ||
export declare function getRouteDetail(info: RouteInfo): string; | ||
export interface QualifiedClassMetaData extends Kecubung.ClassMetaData { | ||
qualifiedClassName: string; | ||
} | ||
export declare namespace MetaDataHelper { | ||
function save(key: string, value: any, args: any[]): void; | ||
function get<T>(key: string, target: any, methodName?: string): T[]; | ||
} | ||
export declare function reflect(obj: any): string[]; |
152
lib/index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("reflect-metadata"); | ||
exports.ValidationTypesAccepted = ["string", "string[]", "number", "number[]", "boolean", "boolean[]", "date", "date[]"]; | ||
exports.MethodDecorator = function (target, propertyKey, descriptor) { }; | ||
var Decorator = (function () { | ||
function Decorator() { | ||
} | ||
/** | ||
* Add type metadata information | ||
* @param typ Qualified name of the type | ||
*/ | ||
Decorator.prototype.type = function (typ) { return function () { | ||
var target = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
target[_i] = arguments[_i]; | ||
} | ||
}; }; | ||
return Decorator; | ||
}()); | ||
exports.Decorator = Decorator; | ||
var HttpDecorator = (function () { | ||
function HttpDecorator() { | ||
} | ||
HttpDecorator.prototype.ignore = function () { return exports.MethodDecorator; }; | ||
HttpDecorator.prototype.root = function (route) { return function (constructor) { }; }; | ||
HttpDecorator.prototype.get = function (route) { return exports.MethodDecorator; }; | ||
HttpDecorator.prototype.post = function (route) { return exports.MethodDecorator; }; | ||
HttpDecorator.prototype.put = function (route) { return exports.MethodDecorator; }; | ||
HttpDecorator.prototype.patch = function (route) { return exports.MethodDecorator; }; | ||
HttpDecorator.prototype.delete = function (route) { return exports.MethodDecorator; }; | ||
HttpDecorator.prototype.on = function (event) { return exports.MethodDecorator; }; | ||
return HttpDecorator; | ||
}()); | ||
exports.HttpDecorator = HttpDecorator; | ||
var BinderDecorator = (function () { | ||
function BinderDecorator() { | ||
} | ||
BinderDecorator.prototype.body = function () { return function (target, propertyKey, index) { }; }; | ||
BinderDecorator.prototype.cookie = function (name) { return function (target, propertyKey, index) { }; }; | ||
return BinderDecorator; | ||
}()); | ||
exports.BinderDecorator = BinderDecorator; | ||
var RouteAnalysisCode; | ||
(function (RouteAnalysisCode) { | ||
/** | ||
* Issue when route parameters doesn't have association | ||
* with action parameters | ||
*/ | ||
RouteAnalysisCode.UnAssociatedParameters = 1; | ||
/** | ||
* Only applied on GET method, issue when action contains parameter | ||
* but route doesn't have any | ||
*/ | ||
RouteAnalysisCode.MissingRouteParameters = 2; | ||
/** | ||
* Issue when router contains parameter, but action doesn't have any | ||
*/ | ||
RouteAnalysisCode.MissingActionParameters = 3; | ||
/** | ||
* Issue when @internal decorator combined with other http method decorator | ||
*/ | ||
RouteAnalysisCode.ConflictDecorators = 4; | ||
/** | ||
* API Convention fail because appropriate method name is match with | ||
* method naming convention but the method doesn't have parameters | ||
*/ | ||
RouteAnalysisCode.ConventionFail = 5; | ||
RouteAnalysisCode.ClassNotInheritedFromController = 6; | ||
RouteAnalysisCode.ClassNotExported = 7; | ||
RouteAnalysisCode.DuplicateRoutes = 8; | ||
RouteAnalysisCode.DuplicateParameterName = 9; | ||
RouteAnalysisCode.QueryParameterNotAllowed = 10; | ||
RouteAnalysisCode.DecoratorNotAllowed = 11; | ||
})(RouteAnalysisCode = exports.RouteAnalysisCode || (exports.RouteAnalysisCode = {})); | ||
/** | ||
* ask the next transformer to override each of field if possible | ||
*/ | ||
var OverrideRequest; | ||
(function (OverrideRequest) { | ||
OverrideRequest[OverrideRequest["Route"] = 1] = "Route"; | ||
OverrideRequest[OverrideRequest["HttpMethod"] = 2] = "HttpMethod"; | ||
})(OverrideRequest = exports.OverrideRequest || (exports.OverrideRequest = {})); | ||
var HttpError = (function () { | ||
function HttpError(status, error, request, response) { | ||
this.status = status; | ||
this.error = error; | ||
this.request = request; | ||
this.response = response; | ||
} | ||
return HttpError; | ||
}()); | ||
exports.HttpError = HttpError; | ||
var Invocation = (function () { | ||
function Invocation() { | ||
} | ||
return Invocation; | ||
}()); | ||
exports.Invocation = Invocation; | ||
var ActionResult = (function () { | ||
var framework_1 = require("./framework"); | ||
exports.Invocation = framework_1.Invocation; | ||
exports.MethodDecorator = framework_1.MethodDecorator; | ||
var http_1 = require("./http"); | ||
exports.HttpError = http_1.HttpError; | ||
var router_1 = require("./router"); | ||
exports.OverrideRequest = router_1.OverrideRequest; | ||
exports.RouteAnalysisCode = router_1.RouteAnalysisCode; | ||
var validator_1 = require("./validator"); | ||
exports.ValidationTypesAccepted = validator_1.ValidationTypesAccepted; | ||
var ActionResult = /** @class */ (function () { | ||
function ActionResult(body, status, type) { | ||
@@ -144,44 +57,1 @@ this.body = body; | ||
exports.ActionResult = ActionResult; | ||
function getRouteDetail(info) { | ||
var tokens = info.qualifiedClassName.split(","); | ||
var method = tokens[0].trim() + "." + info.methodMetaData.name; | ||
var file = tokens[1].trim(); | ||
return "[" + method + " " + file + "]"; | ||
} | ||
exports.getRouteDetail = getRouteDetail; | ||
var MetaDataHelper; | ||
(function (MetaDataHelper) { | ||
function save(key, value, args) { | ||
if (args.length == 1) { | ||
var collections = Reflect.getMetadata(key, args[0]) || []; | ||
collections.push(value); | ||
Reflect.defineMetadata(key, collections, args[0]); | ||
} | ||
else { | ||
var collections = Reflect.getMetadata(key, args[0], args[1]) || []; | ||
collections.push(value); | ||
Reflect.defineMetadata(key, collections, args[0], args[1]); | ||
} | ||
} | ||
MetaDataHelper.save = save; | ||
function get(key, target, methodName) { | ||
if (!target) | ||
return []; | ||
if (!methodName) { | ||
var collections = Reflect.getMetadata(key, target.constructor); | ||
return collections; | ||
} | ||
else { | ||
var collections = Reflect.getMetadata(key, target, methodName); | ||
return collections; | ||
} | ||
} | ||
MetaDataHelper.get = get; | ||
})(MetaDataHelper = exports.MetaDataHelper || (exports.MetaDataHelper = {})); | ||
function reflect(obj) { | ||
//dynamic | ||
var dynamicProperties = Object.getOwnPropertyNames(obj); | ||
var staticProperties = Object.getOwnPropertyNames(Object.getPrototypeOf(obj)); | ||
return dynamicProperties.concat(staticProperties.filter(function (x) { return x != "constructor"; })); | ||
} | ||
exports.reflect = reflect; |
{ | ||
"name": "kamboja-core", | ||
"version": "0.4.0", | ||
"version": "0.5.0-alpha.40636165", | ||
"description": "Core library of KambojaJS", | ||
@@ -22,5 +22,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@types/lodash": "^4.14.71", | ||
"@types/node": "^8.0.19", | ||
"kecubung": "^0.4.0", | ||
"@types/lodash": "^4.14.74", | ||
"@types/node": "^8.0.28", | ||
"kecubung": "0.5.0-alpha.40636165", | ||
"lodash": "^4.17.4", | ||
@@ -31,6 +31,6 @@ "reflect-metadata": "^0.1.10", | ||
"devDependencies": { | ||
"@types/chai": "^4.0.2", | ||
"@types/mocha": "^2.2.41", | ||
"@types/sinon": "^2.3.3", | ||
"chai": "^4.1.0", | ||
"@types/chai": "^4.0.4", | ||
"@types/mocha": "^2.2.43", | ||
"@types/sinon": "^2.3.4", | ||
"chai": "^4.1.2", | ||
"coveralls": "^2.13.1", | ||
@@ -41,9 +41,9 @@ "del": "^3.0.0", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-sourcemaps": "^2.6.0", | ||
"gulp-typescript": "^3.2.1", | ||
"mocha": "^3.5.0", | ||
"gulp-sourcemaps": "^2.6.1", | ||
"gulp-typescript": "^3.2.2", | ||
"mocha": "^3.5.3", | ||
"run-sequence": "^2.1.0", | ||
"sinon": "^3.0.0", | ||
"typescript": "^2.4.2" | ||
"sinon": "^3.2.1", | ||
"typescript": "^2.5.2" | ||
} | ||
} |
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
29994
96
704
1
+ Addedkecubung@0.5.0-alpha.40636165(transitive)
- Removedkecubung@0.4.0(transitive)
Updated@types/lodash@^4.14.74
Updated@types/node@^8.0.28