UNPKG

pao-aop-server

Version:

基于pao-aop的服务端框架

76 lines (74 loc) 2.3 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* * 版权: Copyright (c) 2018 red * * 文件: session.ts * 创建日期: Thursday October 25th 2018 * 作者: pao * 说明: * 1、 */ /** * Session工具类 */ var Session = /** @class */ (function () { /** Session 工具类 */ function Session(req) { this.req = req; } Session.fromArguments = function (args) { if (args) { var req = (args[args.length - 1]); return new Session(req); } return undefined; }; /** * 设置Session * @param key 关键字 * @param value 值 */ Session.prototype.setValue = function (key, value) { this.req.session[key] = value; this.req.session.save(function (error) { if (error) { console.log('设置Session [${key}] 异常:' + error.stack); throw new Error("\u8BBE\u7F6ESession [" + key + "] \u5F02\u5E38"); } }); }; /** * 获取Session * @param key 关键字 */ Session.prototype.getValue = function (key) { return this.req.session[key]; }; /** * 销毁Session * @param key 关键字 */ Session.prototype.deleteValue = function (key) { this.req.session[key] = undefined; this.req.session.save(function (error) { if (error) { console.log('设置Session [${key}] 异常:' + error.stack); throw new Error("\u8BBE\u7F6ESession [" + key + "] \u5F02\u5E38"); } }); }; return Session; }()); exports.Session = Session; }); //# sourceMappingURL=index.js.map