UNPKG

wa-chat-server

Version:

Watson Assistant powered chat server

64 lines (63 loc) 2.44 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionStorageFactoryMock = void 0; const SessionDoesNotExistError_1 = require("../../exception/SessionDoesNotExistError"); class SessionStorageMock { constructor(config) { this.config = config; this.storage = {}; } init() { return __awaiter(this, void 0, void 0, function* () { // console.log('SessionStorageMock.init()'); return this; }); } create(sessionId) { return __awaiter(this, void 0, void 0, function* () { var _a; // console.log('SessionStorageMock.create()'); const id = `ID_${Date.now()}`; if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.allowForeignSessionIds)) { return id; } return sessionId || id; }); } read(sessionId) { return __awaiter(this, void 0, void 0, function* () { // console.log('SessionStorageMock.read()'); const value = this.storage[sessionId]; if (!value) throw new SessionDoesNotExistError_1.SessionDoesNotExistError(); return value; }); } write(sessionId, data) { return __awaiter(this, void 0, void 0, function* () { // console.log('SessionStorageMock.write()'); this.storage[sessionId] = data; }); } } class SessionStorageFactoryMock { constructor(config) { this.config = {}; if (config) { this.config = config; } } createStorage(config) { return new SessionStorageMock(); } } exports.SessionStorageFactoryMock = SessionStorageFactoryMock;