Socket
Socket
Sign inDemoInstall

socket-controllers

Package Overview
Dependencies
39
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.1.0-alpha

CurrentUserChecker.d.ts

18

index.d.ts

@@ -16,4 +16,20 @@ import { MetadataArgsStorage } from "./metadata-builder/MetadataArgsStorage";

export * from "./container";
export * from "./decorators";
export * from "./SocketControllersOptions";
export * from "./MiddlewareInterface";
export * from "./decorator/SocketController";
export * from "./decorator/SocketIO";
export * from "./decorator/SocketId";
export * from "./decorator/SocketRequest";
export * from "./decorator/SocketRooms";
export * from "./decorator/SocketQueryParam";
export * from "./decorator/ConnectedSocket";
export * from "./decorator/OnConnect";
export * from "./decorator/OnDisconnect";
export * from "./decorator/OnMessage";
export * from "./decorator/EmitOnSuccess";
export * from "./decorator/EmitOnFail";
export * from "./decorator/SkipEmitOnEmptyResult";
export * from "./decorator/Middleware";
export * from "./decorator/MessageBody";
export * from "./decorator/NspParams";
export * from "./decorator/NspParam";

@@ -54,2 +54,3 @@ "use strict";

executor.plainToClassTransformOptions = options.plainToClassTransformOptions;
executor.currentUserChecker = options.currentUserChecker;
// run socket controller register and other operations

@@ -74,4 +75,21 @@ executor.execute(controllerClasses, middlewareClasses);

__export(require("./container"));
__export(require("./decorators"));
// decorators
__export(require("./decorator/SocketController"));
__export(require("./decorator/SocketIO"));
__export(require("./decorator/SocketId"));
__export(require("./decorator/SocketRequest"));
__export(require("./decorator/SocketRooms"));
__export(require("./decorator/SocketQueryParam"));
__export(require("./decorator/ConnectedSocket"));
__export(require("./decorator/OnConnect"));
__export(require("./decorator/OnDisconnect"));
__export(require("./decorator/OnMessage"));
__export(require("./decorator/EmitOnSuccess"));
__export(require("./decorator/EmitOnFail"));
__export(require("./decorator/SkipEmitOnEmptyResult"));
__export(require("./decorator/Middleware"));
__export(require("./decorator/MessageBody"));
__export(require("./decorator/NspParams"));
__export(require("./decorator/NspParam"));
//# sourceMappingURL=index.js.map

@@ -6,2 +6,3 @@ import { SocketControllerMetadataArgs } from "../metadata/args/SocketControllerMetadataArgs";

import { ResultMetadataArgs } from "../metadata/args/ResultMetadataArgs";
import { UseMetadataArgs } from "../metadata/args/UseMetadataArgs";
/**

@@ -13,2 +14,3 @@ * Storage all metadatas read from decorators.

middlewares: MiddlewareMetadataArgs[];
uses: UseMetadataArgs[];
actions: ActionMetadataArgs[];

@@ -20,2 +22,3 @@ results: ResultMetadataArgs[];

findActionsWithTarget(target: Function): ActionMetadataArgs[];
filterUsesWithTarget(target: Function): UseMetadataArgs[];
findResutlsWithTargetAndMethod(target: Function, methodName: string): ResultMetadataArgs[];

@@ -22,0 +25,0 @@ findParamsWithTargetAndMethod(target: Function, methodName: string): ParamMetadataArgs[];

@@ -13,2 +13,3 @@ "use strict";

this.middlewares = [];
this.uses = [];
this.actions = [];

@@ -34,2 +35,7 @@ this.results = [];

};
MetadataArgsStorage.prototype.filterUsesWithTarget = function (target) {
return this.uses.filter(function (use) {
return use.target === target;
});
};
MetadataArgsStorage.prototype.findResutlsWithTargetAndMethod = function (target, methodName) {

@@ -36,0 +42,0 @@ return this.results.filter(function (result) {

import { ControllerMetadata } from "../metadata/ControllerMetadata";
import { MiddlewareMetadata } from "../metadata/MiddlewareMetadata";
import { UseMetadata } from "../metadata/UseMetadata";
/**

@@ -12,4 +13,8 @@ * Builds metadata from the given metadata arguments.

private createActions;
/**
* Creates use metadatas for controllers.
*/
protected createControllerUses(controller: ControllerMetadata): UseMetadata[];
private createParams;
private createResults;
}

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

var ResultMetadata_1 = require("../metadata/ResultMetadata");
var UseMetadata_1 = require("../metadata/UseMetadata");
/**

@@ -42,2 +43,3 @@ * Builds metadata from the given metadata arguments.

controller.actions = _this.createActions(controller);
controller.uses = _this.createControllerUses(controller);
return controller;

@@ -57,2 +59,10 @@ });

};
/**
* Creates use metadatas for controllers.
*/
MetadataBuilder.prototype.createControllerUses = function (controller) {
return index_1.defaultMetadataArgsStorage()
.filterUsesWithTarget(controller.target)
.map(function (useArgs) { return new UseMetadata_1.UseMetadata(useArgs); });
};
MetadataBuilder.prototype.createParams = function (action) {

@@ -59,0 +69,0 @@ return index_1.defaultMetadataArgsStorage()

import { ActionMetadata } from "./ActionMetadata";
import { SocketControllerMetadataArgs } from "./args/SocketControllerMetadataArgs";
import { UseMetadata } from "./UseMetadata";
export declare class ControllerMetadata {

@@ -16,4 +17,8 @@ /**

namespace: string | RegExp;
/**
* Middleware "use"-s applied to a whole controller.
*/
uses: UseMetadata[];
constructor(args: SocketControllerMetadataArgs);
readonly instance: any;
}

3

metadata/types/ParamTypes.d.ts
/**
* Controller action's parameter type.
*/
export declare type ParamType = "custom" | "connected-socket" | "socket-body" | "socket-query-param" | "socket-io" | "socket-id" | "socket-request" | "socket-rooms" | "namespace-params" | "namespace-param";
export declare type ParamType = "custom" | "connected-socket" | "socket-body" | "socket-query-param" | "socket-io" | "socket-id" | "socket-request" | "socket-rooms" | "namespace-params" | "namespace-param" | "current-user";
/**

@@ -19,2 +19,3 @@ * Controller action's parameter type.

static NAMESPACE_PARAM: ParamType;
static CURRENT_USER: ParamType;
}

@@ -19,2 +19,3 @@ "use strict";

ParamTypes.NAMESPACE_PARAM = "namespace-param";
ParamTypes.CURRENT_USER = "current-user";
return ParamTypes;

@@ -21,0 +22,0 @@ }());

{
"name": "socket-controllers",
"private": false,
"version": "0.0.5",
"version": "0.1.0-alpha",
"description": "Use class-based controllers to handle websocket events",

@@ -48,2 +48,3 @@ "license": "MIT",

"@types/node": "^7.0.18",
"@types/socket.io": "^2.1.2",
"del": "^2.2.2",

@@ -50,0 +51,0 @@ "express": "^4.15.2",

import { ClassTransformOptions } from "class-transformer";
import { CurrentUserChecker } from "./CurrentUserChecker";
/**

@@ -22,2 +23,6 @@ * Registers controllers and actions in the given server framework.

plainToClassTransformOptions: ClassTransformOptions;
/**
* Special function used to get currently authorized user.
*/
currentUserChecker: CurrentUserChecker;
private metadataBuilder;

@@ -24,0 +29,0 @@ constructor(io: any);

@@ -68,2 +68,7 @@ "use strict";

controllers.forEach(function (controller) {
controller.uses.forEach(function (middleware) {
socket.use(function (pocket, next) {
middleware.instance.use(pocket, next); // TODO: pass socket instance?
});
});
controller.actions.forEach(function (action) {

@@ -123,2 +128,5 @@ if (action.type === ActionTypes_1.ActionTypes.CONNECT) {

}
else if (param.type === ParamTypes_1.ParamTypes.CURRENT_USER) {
return _this.currentUserChecker(options.socket);
}
else {

@@ -125,0 +133,0 @@ return _this.handleParam(param, options);

import { ClassTransformOptions } from "class-transformer";
import { CurrentUserChecker } from "./CurrentUserChecker";
/**

@@ -29,2 +30,6 @@ * Socket controllers initialization options.

plainToClassTransformOptions?: ClassTransformOptions;
/**
* Special function used to get currently authorized user.
*/
currentUserChecker?: CurrentUserChecker;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc