realm-object-server
Version:
300 lines • 9.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function addPathAndMethod(target, httpMethod, path, functionName, allowAnonymous) {
const routes = Object.assign([], target.routes || []);
routes.push({
httpMethod,
path,
functionName,
allowAnonymous,
});
target.routes = routes;
}
function Get(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "get", path, propertyKey, config.allowAnonymous);
};
}
exports.Get = Get;
function Post(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "post", path, propertyKey, config.allowAnonymous);
};
}
exports.Post = Post;
function Put(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "put", path, propertyKey, config.allowAnonymous);
};
}
exports.Put = Put;
function Delete(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "delete", path, propertyKey, config.allowAnonymous);
};
}
exports.Delete = Delete;
function Options(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "options", path, propertyKey, config.allowAnonymous);
};
}
exports.Options = Options;
function Head(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "head", path, propertyKey, config.allowAnonymous);
};
}
exports.Head = Head;
function Trace(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "trace", path, propertyKey, config.allowAnonymous);
};
}
exports.Trace = Trace;
function Patch(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "patch", path, propertyKey, config.allowAnonymous);
};
}
exports.Patch = Patch;
function All(path, config = {}) {
return function (target, propertyKey, descriptor) {
addPathAndMethod(target, "all", path, propertyKey, config.allowAnonymous);
};
}
exports.All = All;
function Upgrade(path) {
return function (target, propertyKey, descriptor) {
const upgradeRoutes = target.upgradeRoutes || [];
upgradeRoutes.push({
functionName: propertyKey,
path: path
});
target.upgradeRoutes = upgradeRoutes;
};
}
exports.Upgrade = Upgrade;
function MiddlewaresBefore(...middlewares) {
return function (target, propertyKey, descriptor) {
if (!propertyKey) {
const middlewaresBeforeService = target.middlewaresBeforeService || [];
target.middlewaresBeforeService = middlewaresBeforeService.concat(middlewares);
}
else {
const middlewaresBeforeFunction = target.middlewaresBeforeFunction || [];
middlewaresBeforeFunction.push({
functionName: propertyKey,
middlewares: middlewares
});
target.middlewaresBeforeFunction = middlewaresBeforeFunction;
}
};
}
exports.MiddlewaresBefore = MiddlewaresBefore;
function BaseRoute(path, config = { allowAnonymous: true }) {
return function (target) {
target.baseRoute = path;
target.allowAnonymous = config.allowAnonymous;
};
}
exports.BaseRoute = BaseRoute;
function ServiceName(name) {
return function (target) {
target.serviceName = name;
};
}
exports.ServiceName = ServiceName;
function Tags(tags) {
return function (target) {
target.tags = tags;
};
}
exports.Tags = Tags;
function ServeStatic(route, staticRoot) {
return function (target) {
const original = target;
const f = function (...args) {
const instance = new original(...args);
const serveStaticRoutes = [];
serveStaticRoutes.push({
path: route,
staticRoot: staticRoot
});
instance.serveStaticRoutes = serveStaticRoutes;
return instance;
};
f.prototype = original.prototype;
return f;
};
}
exports.ServeStatic = ServeStatic;
function Cors(path, options = null) {
return function (target) {
if (!target.corsPaths) {
target.corsPaths = {};
}
target.corsPaths[path] = options;
};
}
exports.Cors = Cors;
function Body(keyPath) {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "body",
keyPath: keyPath
});
target.parameterArguments = bodyParams;
};
}
exports.Body = Body;
function Headers(keyPath) {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "headers",
keyPath: keyPath
});
target.parameterArguments = bodyParams;
};
}
exports.Headers = Headers;
function Params(keyPath) {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "params",
keyPath: keyPath
});
target.parameterArguments = bodyParams;
};
}
exports.Params = Params;
function Query(keyPath) {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "query",
keyPath: keyPath
});
target.parameterArguments = bodyParams;
};
}
exports.Query = Query;
function Request() {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "request"
});
target.parameterArguments = bodyParams;
};
}
exports.Request = Request;
function Response() {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "response"
});
target.parameterArguments = bodyParams;
};
}
exports.Response = Response;
function Socket() {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "socket"
});
target.parameterArguments = bodyParams;
};
}
exports.Socket = Socket;
function HeadBuffer() {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "headBuffer"
});
target.parameterArguments = bodyParams;
};
}
exports.HeadBuffer = HeadBuffer;
function Next() {
return function (target, functionName, argumentIndex) {
const bodyParams = target.parameterArguments || [];
bodyParams.push({
functionName: functionName,
argumentIndex: argumentIndex,
type: "next"
});
target.parameterArguments = bodyParams;
};
}
exports.Next = Next;
function Start() {
return function (target, propertyKey, descriptor) {
target.startFunctionName = propertyKey;
};
}
exports.Start = Start;
function Stop() {
return function (target, propertyKey, descriptor) {
target.stopFunctionName = propertyKey;
};
}
exports.Stop = Stop;
function Stopping() {
return function (target, propertyKey, descriptor) {
target.stoppingFunctionName = propertyKey;
};
}
exports.Stopping = Stopping;
function ServerStarted() {
return function (target, propertyKey, descriptor) {
target.serverStartedFunctionName = propertyKey;
};
}
exports.ServerStarted = ServerStarted;
function Address() {
return function (target, propertyKey, descriptor) {
target.addressFunctionName = propertyKey;
};
}
exports.Address = Address;
function Unmute(contextual = true) {
return function (target, propertyKey, descriptor) {
if (contextual) {
target.unmuteContextualFunctionName = propertyKey;
}
else {
target.unmuteFunctionName = propertyKey;
}
};
}
exports.Unmute = Unmute;
function EnhanceLog() {
return function (target, propertyKey, descriptor) {
target.enhanceLogFunctionName = propertyKey;
};
}
exports.EnhanceLog = EnhanceLog;
//# sourceMappingURL=decorators.js.map