eyevinn-channel-engine 5.0.6 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.github/workflows/nodejs.yml +4 -4
  2. package/.github/workflows/publish.yml +5 -5
  3. package/.github/workflows/rc.yml +5 -5
  4. package/dist/engine/chaos_monkey.js +12 -51
  5. package/dist/engine/event_stream.js +9 -10
  6. package/dist/engine/index.d.ts +1 -0
  7. package/dist/engine/index.js +2 -0
  8. package/dist/engine/memcached_state_store.js +53 -165
  9. package/dist/engine/memory_state_store.js +52 -129
  10. package/dist/engine/playhead_state.js +53 -156
  11. package/dist/engine/preflight.js +13 -52
  12. package/dist/engine/redis_state_store.js +162 -332
  13. package/dist/engine/server.js +799 -1287
  14. package/dist/engine/session.js +1793 -2543
  15. package/dist/engine/session_live.js +1759 -2254
  16. package/dist/engine/session_live_state.js +84 -206
  17. package/dist/engine/session_state.js +178 -356
  18. package/dist/engine/shared_state_store.js +69 -206
  19. package/dist/engine/stream_switcher.js +675 -902
  20. package/dist/engine/subtitle_slicer.js +135 -200
  21. package/dist/engine/util.js +133 -200
  22. package/dist/examples/autocreate.js +34 -35
  23. package/dist/examples/default.js +32 -32
  24. package/dist/examples/demux.js +29 -32
  25. package/dist/examples/drm.js +25 -28
  26. package/dist/examples/livemix-demux.js +79 -80
  27. package/dist/examples/livemix.js +71 -72
  28. package/dist/examples/multicodec.js +26 -29
  29. package/dist/examples/truncate.js +31 -32
  30. package/dist/package.json +16 -14
  31. package/engine/server.ts +1 -1
  32. package/package.json +16 -14
  33. package/tsconfig.json +3 -1
  34. package/dist/engine/ad_request.d.ts +0 -14
  35. package/dist/engine/ad_request.js +0 -121
  36. package/engine/ad_request.js +0 -188
@@ -1,5 +1,5 @@
1
1
  name: Node CI
2
-
2
+
3
3
  on: [push]
4
4
 
5
5
  jobs:
@@ -9,12 +9,12 @@ jobs:
9
9
 
10
10
  strategy:
11
11
  matrix:
12
- node-version: [14.x, 16.x, 18.x]
12
+ node-version: [20.x, 22.x]
13
13
 
14
14
  steps:
15
- - uses: actions/checkout@v3
15
+ - uses: actions/checkout@v4
16
16
  - name: Use Node.js ${{ matrix.node-version }}
17
- uses: actions/setup-node@v3
17
+ uses: actions/setup-node@v4
18
18
  with:
19
19
  node-version: ${{ matrix.node-version }}
20
20
  - name: npm install, build, and test
@@ -1,5 +1,5 @@
1
1
  name: Publish
2
-
2
+
3
3
  on:
4
4
  release:
5
5
  types: [released]
@@ -9,13 +9,13 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
 
11
11
  steps:
12
- - uses: actions/checkout@v1
13
- - uses: actions/setup-node@v1
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-node@v4
14
14
  with:
15
- node-version: 16
15
+ node-version: 20
16
16
  registry-url: https://registry.npmjs.org/
17
17
  - run: |
18
- npm install
18
+ npm ci
19
19
  npm run build
20
20
  npm publish
21
21
  env:
@@ -1,5 +1,5 @@
1
1
  name: Publish release candidate
2
-
2
+
3
3
  on:
4
4
  release:
5
5
  types: [prereleased]
@@ -9,13 +9,13 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
 
11
11
  steps:
12
- - uses: actions/checkout@v1
13
- - uses: actions/setup-node@v1
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-node@v4
14
14
  with:
15
- node-version: 16
15
+ node-version: 20
16
16
  registry-url: https://registry.npmjs.org/
17
17
  - run: |
18
- npm install
18
+ npm ci
19
19
  npm run build
20
20
  npm publish --tag rc
21
21
  env:
@@ -1,55 +1,16 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1
+ "use strict";
2
+ const debug = require('debug')('chaos-monkey');
3
+ const CHAOS_MONKEY_PROBABILITY = process.env.CHAOS_MONKEY_PROBABILITY || 0.5;
4
+ const doChaos = () => process.env.CHAOS_MONKEY === "true" && Math.random() < CHAOS_MONKEY_PROBABILITY;
5
+ const loadVod = async (p) => {
6
+ if (doChaos()) {
7
+ debug("Chaos Monkey is doing stuff");
8
+ throw new Error("Chaos monkey prevented you from loading a VOD");
9
+ }
10
+ else {
11
+ return await p;
35
12
  }
36
13
  };
37
- var _this = this;
38
- var debug = require('debug')('chaos-monkey');
39
- var CHAOS_MONKEY_PROBABILITY = process.env.CHAOS_MONKEY_PROBABILITY || 0.5;
40
- var doChaos = function () { return process.env.CHAOS_MONKEY === "true" && Math.random() < CHAOS_MONKEY_PROBABILITY; };
41
- var loadVod = function (p) { return __awaiter(_this, void 0, void 0, function () {
42
- return __generator(this, function (_a) {
43
- switch (_a.label) {
44
- case 0:
45
- if (!doChaos()) return [3 /*break*/, 1];
46
- debug("Chaos Monkey is doing stuff");
47
- throw new Error("Chaos monkey prevented you from loading a VOD");
48
- case 1: return [4 /*yield*/, p];
49
- case 2: return [2 /*return*/, _a.sent()];
50
- }
51
- });
52
- }); };
53
14
  module.exports = {
54
- loadVod: loadVod
15
+ loadVod
55
16
  };
@@ -1,12 +1,12 @@
1
- var EventStream = /** @class */ (function () {
2
- function EventStream(session) {
1
+ "use strict";
2
+ class EventStream {
3
+ constructor(session) {
3
4
  this._session = session;
4
5
  }
5
- EventStream.prototype.poll = function () {
6
- var _this = this;
7
- return new Promise(function (resolve, reject) {
8
- var event = {};
9
- event = _this._session.consumeEvent();
6
+ poll() {
7
+ return new Promise((resolve, reject) => {
8
+ let event = {};
9
+ event = this._session.consumeEvent();
10
10
  if (event) {
11
11
  resolve(JSON.stringify(event));
12
12
  }
@@ -14,7 +14,6 @@ var EventStream = /** @class */ (function () {
14
14
  resolve(JSON.stringify({}));
15
15
  }
16
16
  });
17
- };
18
- return EventStream;
19
- }());
17
+ }
18
+ }
20
19
  module.exports = EventStream;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,172 +1,60 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var MemcacheClient = require("memcache-client");
38
- var debug = require("debug")("memcached-state-store");
39
- var MemcachedStateStore = /** @class */ (function () {
40
- function MemcachedStateStore(keyPrefix, opts) {
1
+ "use strict";
2
+ const MemcacheClient = require("memcache-client");
3
+ const debug = require("debug")("memcached-state-store");
4
+ class MemcachedStateStore {
5
+ constructor(keyPrefix, opts) {
41
6
  this.keyPrefix = keyPrefix;
42
7
  if (opts.version) {
43
- var prependPrefix = opts.version.replace(/\./g, "X");
8
+ const prependPrefix = opts.version.replace(/\./g, "X");
44
9
  this.keyPrefix = prependPrefix + this.keyPrefix;
45
- debug("Prepending keyprefix with ".concat(prependPrefix, " => ").concat(this.keyPrefix));
10
+ debug(`Prepending keyprefix with ${prependPrefix} => ${this.keyPrefix}`);
46
11
  }
47
12
  this.client = new MemcacheClient({ server: opts.memcachedUrl, cmdTimeout: 10000 });
48
13
  }
49
- MemcachedStateStore.prototype.initAsync = function (id, initData) {
50
- return __awaiter(this, void 0, void 0, function () {
51
- var isInitiated, data, _i, _a, key, _b, _c, _d, _e, key, _f, _g;
52
- return __generator(this, function (_h) {
53
- switch (_h.label) {
54
- case 0: return [4 /*yield*/, this.getAsync(id, "_initiated")];
55
- case 1:
56
- isInitiated = _h.sent();
57
- data = {};
58
- if (!!isInitiated) return [3 /*break*/, 7];
59
- _i = 0, _a = Object.keys(initData);
60
- _h.label = 2;
61
- case 2:
62
- if (!(_i < _a.length)) return [3 /*break*/, 5];
63
- key = _a[_i];
64
- debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating key ").concat(key, " with init data"));
65
- _b = data;
66
- _c = key;
67
- return [4 /*yield*/, this.setAsync(id, key, initData[key])];
68
- case 3:
69
- _b[_c] = _h.sent();
70
- _h.label = 4;
71
- case 4:
72
- _i++;
73
- return [3 /*break*/, 2];
74
- case 5: return [4 /*yield*/, this.setAsync(id, "_initiated", true)];
75
- case 6:
76
- _h.sent();
77
- return [3 /*break*/, 11];
78
- case 7:
79
- debug("".concat(this.keyPrefix, ":").concat(id, ": Already initiated, not initiating with init data"));
80
- _d = 0, _e = Object.keys(initData);
81
- _h.label = 8;
82
- case 8:
83
- if (!(_d < _e.length)) return [3 /*break*/, 11];
84
- key = _e[_d];
85
- debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating key ").concat(key, " with data from store"));
86
- _f = data;
87
- _g = key;
88
- return [4 /*yield*/, this.getAsync(id, key)];
89
- case 9:
90
- _f[_g] = _h.sent();
91
- _h.label = 10;
92
- case 10:
93
- _d++;
94
- return [3 /*break*/, 8];
95
- case 11: return [2 /*return*/, data];
96
- }
97
- });
98
- });
99
- };
100
- MemcachedStateStore.prototype.resetAsync = function (id, initData) {
101
- return __awaiter(this, void 0, void 0, function () {
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0: return [4 /*yield*/, this.setAsync(id, "_initiated", false)];
105
- case 1:
106
- _a.sent();
107
- return [4 /*yield*/, this.initAsync(id, initData)];
108
- case 2:
109
- _a.sent();
110
- return [2 /*return*/];
111
- }
112
- });
113
- });
114
- };
115
- MemcachedStateStore.prototype.resetAllAsync = function () {
116
- return __awaiter(this, void 0, void 0, function () {
117
- return __generator(this, function (_a) {
118
- console.error("Shared Storage Reset Failed.\nMemcache-client: Flush All Command Not Implemented Yet");
119
- return [2 /*return*/];
120
- });
121
- });
122
- };
123
- MemcachedStateStore.prototype.getAsync = function (id, key) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- var storeKey, data;
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0:
129
- storeKey = "" + this.keyPrefix + id + key;
130
- return [4 /*yield*/, this.client.get(storeKey)];
131
- case 1:
132
- data = _a.sent();
133
- if (data) {
134
- return [2 /*return*/, JSON.parse(data.value)];
135
- }
136
- return [2 /*return*/, null];
137
- }
138
- });
139
- });
140
- };
141
- MemcachedStateStore.prototype.setAsync = function (id, key, value) {
142
- return __awaiter(this, void 0, void 0, function () {
143
- var storeKey;
144
- return __generator(this, function (_a) {
145
- switch (_a.label) {
146
- case 0:
147
- storeKey = "" + this.keyPrefix + id + key;
148
- return [4 /*yield*/, this.client.set(storeKey, JSON.stringify(value))];
149
- case 1:
150
- _a.sent();
151
- return [2 /*return*/, value];
152
- }
153
- });
154
- });
155
- };
156
- MemcachedStateStore.prototype.setVolatileAsync = function (id, key, value) {
157
- return __awaiter(this, void 0, void 0, function () {
158
- return __generator(this, function (_a) {
159
- throw new Error("memcached: setVolatileAsync not implemented yet");
160
- });
161
- });
162
- };
163
- MemcachedStateStore.prototype.removeAsync = function (id, key) {
164
- return __awaiter(this, void 0, void 0, function () {
165
- return __generator(this, function (_a) {
166
- throw new Error("memcached: removeAsync not implemented yet");
167
- });
168
- });
169
- };
170
- return MemcachedStateStore;
171
- }());
14
+ async initAsync(id, initData) {
15
+ const isInitiated = await this.getAsync(id, "_initiated");
16
+ let data = {};
17
+ if (!isInitiated) {
18
+ for (const key of Object.keys(initData)) {
19
+ debug(`${this.keyPrefix}:${id}: Initiating key ${key} with init data`);
20
+ data[key] = await this.setAsync(id, key, initData[key]);
21
+ }
22
+ await this.setAsync(id, "_initiated", true);
23
+ }
24
+ else {
25
+ debug(`${this.keyPrefix}:${id}: Already initiated, not initiating with init data`);
26
+ for (const key of Object.keys(initData)) {
27
+ debug(`${this.keyPrefix}:${id}: Initiating key ${key} with data from store`);
28
+ data[key] = await this.getAsync(id, key);
29
+ }
30
+ }
31
+ return data;
32
+ }
33
+ async resetAsync(id, initData) {
34
+ await this.setAsync(id, "_initiated", false);
35
+ await this.initAsync(id, initData);
36
+ }
37
+ async resetAllAsync() {
38
+ console.error("Shared Storage Reset Failed.\nMemcache-client: Flush All Command Not Implemented Yet");
39
+ }
40
+ async getAsync(id, key) {
41
+ const storeKey = "" + this.keyPrefix + id + key;
42
+ const data = await this.client.get(storeKey);
43
+ if (data) {
44
+ return JSON.parse(data.value);
45
+ }
46
+ return null;
47
+ }
48
+ async setAsync(id, key, value) {
49
+ const storeKey = "" + this.keyPrefix + id + key;
50
+ await this.client.set(storeKey, JSON.stringify(value));
51
+ return value;
52
+ }
53
+ async setVolatileAsync(id, key, value) {
54
+ throw new Error("memcached: setVolatileAsync not implemented yet");
55
+ }
56
+ async removeAsync(id, key) {
57
+ throw new Error("memcached: removeAsync not implemented yet");
58
+ }
59
+ }
172
60
  module.exports = MemcachedStateStore;
@@ -1,134 +1,57 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var debug = require("debug")("memory-state-store");
38
- var MemoryStateStore = /** @class */ (function () {
39
- function MemoryStateStore(type, opts) {
1
+ "use strict";
2
+ const debug = require("debug")("memory-state-store");
3
+ class MemoryStateStore {
4
+ constructor(type, opts) {
40
5
  this.sharedStates = {};
41
6
  this.globalSharedStates = {};
42
7
  }
43
- MemoryStateStore.prototype.initAsync = function (id, initData) {
44
- return __awaiter(this, void 0, void 0, function () {
45
- var _this = this;
46
- return __generator(this, function (_a) {
47
- if (!this.sharedStates[id]) {
48
- this.sharedStates[id] = {};
49
- Object.keys(initData).forEach(function (key) {
50
- _this.sharedStates[id][key] = initData[key];
51
- });
52
- }
53
- return [2 /*return*/, this.sharedStates[id]];
54
- });
55
- });
56
- };
57
- MemoryStateStore.prototype.resetAsync = function (id, initData) {
58
- return __awaiter(this, void 0, void 0, function () {
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0:
62
- this.sharedStates[id] = null;
63
- return [4 /*yield*/, this.initAsync(id, initData)];
64
- case 1:
65
- _a.sent();
66
- return [2 /*return*/];
67
- }
68
- });
69
- });
70
- };
71
- MemoryStateStore.prototype.resetAllAsync = function () {
72
- return __awaiter(this, void 0, void 0, function () {
73
- return __generator(this, function (_a) {
74
- this.sharedStates = {};
75
- this.globalSharedStates = {};
76
- return [2 /*return*/];
77
- });
78
- });
79
- };
80
- MemoryStateStore.prototype.getAsync = function (id, key) {
81
- return __awaiter(this, void 0, void 0, function () {
82
- var value;
83
- return __generator(this, function (_a) {
84
- if (id === "" || id === null) {
85
- value = this.globalSharedStates[key];
86
- }
87
- else {
88
- if (!this.sharedStates[id]) {
89
- return [2 /*return*/, null];
90
- }
91
- value = this.sharedStates[id][key];
92
- }
93
- return [2 /*return*/, value];
8
+ async initAsync(id, initData) {
9
+ if (!this.sharedStates[id]) {
10
+ this.sharedStates[id] = {};
11
+ Object.keys(initData).forEach((key) => {
12
+ this.sharedStates[id][key] = initData[key];
94
13
  });
95
- });
96
- };
97
- MemoryStateStore.prototype.setAsync = function (id, key, value) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- if (id === "" || id === null) {
101
- this.globalSharedStates[key] = value;
102
- }
103
- else {
104
- if (!this.sharedStates[id]) {
105
- this.sharedStates[id] = {};
106
- }
107
- this.sharedStates[id][key] = value;
108
- return [2 /*return*/, this.sharedStates[id][key]];
109
- }
110
- return [2 /*return*/];
111
- });
112
- });
113
- };
114
- MemoryStateStore.prototype.setVolatileAsync = function (id, key, value) {
115
- return __awaiter(this, void 0, void 0, function () {
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0: return [4 /*yield*/, this.setAsync(id, key, value)];
119
- case 1: return [2 /*return*/, _a.sent()];
120
- }
121
- });
122
- });
123
- };
124
- MemoryStateStore.prototype.removeAsync = function (id, key) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- return __generator(this, function (_a) {
127
- delete this.sharedStates[id][key];
128
- return [2 /*return*/];
129
- });
130
- });
131
- };
132
- return MemoryStateStore;
133
- }());
14
+ }
15
+ return this.sharedStates[id];
16
+ }
17
+ async resetAsync(id, initData) {
18
+ this.sharedStates[id] = null;
19
+ await this.initAsync(id, initData);
20
+ }
21
+ async resetAllAsync() {
22
+ this.sharedStates = {};
23
+ this.globalSharedStates = {};
24
+ }
25
+ async getAsync(id, key) {
26
+ let value;
27
+ if (id === "" || id === null) {
28
+ value = this.globalSharedStates[key];
29
+ }
30
+ else {
31
+ if (!this.sharedStates[id]) {
32
+ return null;
33
+ }
34
+ value = this.sharedStates[id][key];
35
+ }
36
+ return value;
37
+ }
38
+ async setAsync(id, key, value) {
39
+ if (id === "" || id === null) {
40
+ this.globalSharedStates[key] = value;
41
+ }
42
+ else {
43
+ if (!this.sharedStates[id]) {
44
+ this.sharedStates[id] = {};
45
+ }
46
+ this.sharedStates[id][key] = value;
47
+ return this.sharedStates[id][key];
48
+ }
49
+ }
50
+ async setVolatileAsync(id, key, value) {
51
+ return await this.setAsync(id, key, value);
52
+ }
53
+ async removeAsync(id, key) {
54
+ delete this.sharedStates[id][key];
55
+ }
56
+ }
134
57
  module.exports = MemoryStateStore;