From fc326e85d5b5f7614a35ca1ef0c38d3c8f158d7d Mon Sep 17 00:00:00 2001 From: Frank Lemanschik Date: Sat, 21 Mar 2020 12:46:08 +0100 Subject: [PATCH] Forgotten 2 files sorry --- docs/README.md | 35 ++++++++++++++++++++++ src/models/UserSession.js | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 docs/README.md create mode 100644 src/models/UserSession.js diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..e5b12d2 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,35 @@ +# TypeScript none standard JSDOC Import syntax +```js +// 1.Normal Case +/** + * @param {import('./user').User} user + */ + + + +// typescript +// 1. normal +/** + * @param p { import("./a").Pet } + */ +function walk(p) { + console.log(`Walking ${p.name}...`); +} + +// 2.Alias Type +/** + * @typedef { import("./a").Pet } Pet + */ + +/** + * @type {Pet} + */ +var myPet; +myPet.name; + +// 3.Refer Inferred Type +/** + * @type {typeof import("./a").x } + */ +var x = require("./a").x; +``` \ No newline at end of file diff --git a/src/models/UserSession.js b/src/models/UserSession.js new file mode 100644 index 0000000..7aac4fb --- /dev/null +++ b/src/models/UserSession.js @@ -0,0 +1,61 @@ +/** + * User session model + * @type {Object} Session Object. + * @property {string} _sessionId The session identifier + * @property {string} _websiteKey The website id for session + */ +export class UserSession { + /** + * Set session ID + * @param {string} id + */ + set sessionId(id) { + this._sessionId = id; + } + + /** + * Get the session ID + * @type {string} + */ + get sessionId() { + return this._sessionId; + } + + /** + * Set session ID + * @param {string} id + */ + set websiteKey(id) { + this._websiteKey = id; + } + + /** + * Get the session ID + * @type {string} + */ + get websiteKey() { + return this._websiteKey; + } + + /** + * Serialize the session into a JSON object + * @return {Array} + */ + serialize() { + const {sessionId, websiteKey} = this; + if (!sessionId || !websiteKey) { + throw Error(); + } + return [sessionId, websiteKey]; + } + + /** + * Deserialize session data from JSON object + * @param {Array} payload + */ + deserialize([sessionId, websiteKey]) { + Object.assign(this, {sessionId, websiteKey}); + } +}; + +export default UserSession;