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.
- package/.github/workflows/nodejs.yml +4 -4
- package/.github/workflows/publish.yml +5 -5
- package/.github/workflows/rc.yml +5 -5
- package/dist/engine/chaos_monkey.js +12 -51
- package/dist/engine/event_stream.js +9 -10
- package/dist/engine/index.d.ts +1 -0
- package/dist/engine/index.js +2 -0
- package/dist/engine/memcached_state_store.js +53 -165
- package/dist/engine/memory_state_store.js +52 -129
- package/dist/engine/playhead_state.js +53 -156
- package/dist/engine/preflight.js +13 -52
- package/dist/engine/redis_state_store.js +162 -332
- package/dist/engine/server.js +799 -1287
- package/dist/engine/session.js +1793 -2543
- package/dist/engine/session_live.js +1759 -2254
- package/dist/engine/session_live_state.js +84 -206
- package/dist/engine/session_state.js +178 -356
- package/dist/engine/shared_state_store.js +69 -206
- package/dist/engine/stream_switcher.js +675 -902
- package/dist/engine/subtitle_slicer.js +135 -200
- package/dist/engine/util.js +133 -200
- package/dist/examples/autocreate.js +34 -35
- package/dist/examples/default.js +32 -32
- package/dist/examples/demux.js +29 -32
- package/dist/examples/drm.js +25 -28
- package/dist/examples/livemix-demux.js +79 -80
- package/dist/examples/livemix.js +71 -72
- package/dist/examples/multicodec.js +26 -29
- package/dist/examples/truncate.js +31 -32
- package/dist/package.json +16 -14
- package/engine/server.ts +1 -1
- package/package.json +16 -14
- package/tsconfig.json +3 -1
- package/dist/engine/ad_request.d.ts +0 -14
- package/dist/engine/ad_request.js +0 -121
- 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: [
|
|
12
|
+
node-version: [20.x, 22.x]
|
|
13
13
|
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
16
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
17
|
-
uses: actions/setup-node@
|
|
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@
|
|
13
|
-
- uses: actions/setup-node@
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
14
|
with:
|
|
15
|
-
node-version:
|
|
15
|
+
node-version: 20
|
|
16
16
|
registry-url: https://registry.npmjs.org/
|
|
17
17
|
- run: |
|
|
18
|
-
npm
|
|
18
|
+
npm ci
|
|
19
19
|
npm run build
|
|
20
20
|
npm publish
|
|
21
21
|
env:
|
package/.github/workflows/rc.yml
CHANGED
|
@@ -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@
|
|
13
|
-
- uses: actions/setup-node@
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
14
|
with:
|
|
15
|
-
node-version:
|
|
15
|
+
node-version: 20
|
|
16
16
|
registry-url: https://registry.npmjs.org/
|
|
17
17
|
- run: |
|
|
18
|
-
npm
|
|
18
|
+
npm ci
|
|
19
19
|
npm run build
|
|
20
20
|
npm publish --tag rc
|
|
21
21
|
env:
|
|
@@ -1,55 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
15
|
+
loadVod
|
|
55
16
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
class EventStream {
|
|
3
|
+
constructor(session) {
|
|
3
4
|
this._session = session;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
19
|
-
}());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
20
19
|
module.exports = EventStream;
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/engine/index.js
CHANGED
|
@@ -1,172 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
+
const prependPrefix = opts.version.replace(/\./g, "X");
|
|
44
9
|
this.keyPrefix = prependPrefix + this.keyPrefix;
|
|
45
|
-
debug(
|
|
10
|
+
debug(`Prepending keyprefix with ${prependPrefix} => ${this.keyPrefix}`);
|
|
46
11
|
}
|
|
47
12
|
this.client = new MemcacheClient({ server: opts.memcachedUrl, cmdTimeout: 10000 });
|
|
48
13
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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;
|