tapeworm_persistence_store_hybrid 1.0.0
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/README +1 -0
- package/dist/HybridPartition.js +128 -0
- package/dist/HybridPartition.js.map +1 -0
- package/dist/HybridPersistence.js +94 -0
- package/dist/HybridPersistence.js.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -0
- package/package.json +38 -0
package/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#tapeworm_persistence_store_hybrid
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
var bluebird_1 = __importDefault(require("bluebird"));
|
|
7
|
+
var slf_1 = require("slf");
|
|
8
|
+
var log = slf_1.LoggerFactory.getLogger('tapeworm-persistence-hybrid:hybrid-partition');
|
|
9
|
+
var DEFAULT_LOAD_SNAPSHOT_MAX_TIME = 10;
|
|
10
|
+
var HybridPartition = (function () {
|
|
11
|
+
function HybridPartition(localPartition, remotePartition, autoCleanLocalPartition, snapshotLifeTime, loggingOptions) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
this.localPartition = localPartition;
|
|
14
|
+
this.remotePartition = remotePartition;
|
|
15
|
+
this.snapshotLifeTime = snapshotLifeTime;
|
|
16
|
+
this.loggingOptions = loggingOptions;
|
|
17
|
+
if (!this.loggingOptions.loadSnapshotMaxTime) {
|
|
18
|
+
this.loggingOptions.loadSnapshotMaxTime = DEFAULT_LOAD_SNAPSHOT_MAX_TIME;
|
|
19
|
+
}
|
|
20
|
+
if (autoCleanLocalPartition) {
|
|
21
|
+
if (!localPartition.querySnapshotsOlderThanMaxDate) {
|
|
22
|
+
throw new Error('Unable to start auto clean of local partition since it does not support it.');
|
|
23
|
+
}
|
|
24
|
+
log.info('Starting auto clean of local partition');
|
|
25
|
+
setInterval(function () {
|
|
26
|
+
_this.cleanPartition();
|
|
27
|
+
}, 1000 * 60 * 30);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
HybridPartition.prototype.cleanPartition = function () {
|
|
31
|
+
var _this = this;
|
|
32
|
+
log.info('Auto cleaning partition');
|
|
33
|
+
var snapshotTTLDate = new Date();
|
|
34
|
+
snapshotTTLDate.setMinutes(snapshotTTLDate.getMinutes() - this.snapshotLifeTime);
|
|
35
|
+
this.localPartition.querySnapshotsOlderThanMaxDate(snapshotTTLDate.toISOString()).then(function (snapshots) {
|
|
36
|
+
log.info('cleaning %s snapshots', snapshots.length);
|
|
37
|
+
var snapshotIdsToRemove = snapshots.map(function (snapshot) { return snapshot.id; });
|
|
38
|
+
_this.localPartition.removeSnapshots(snapshotIdsToRemove);
|
|
39
|
+
snapshotIdsToRemove.forEach(function (snapshotId) { return _this.localPartition.truncateStreamFrom(snapshotId, 0, true); });
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
HybridPartition.prototype.open = function () {
|
|
43
|
+
return bluebird_1["default"].resolve(this);
|
|
44
|
+
};
|
|
45
|
+
HybridPartition.prototype.append = function (commit) {
|
|
46
|
+
return this.localPartition.append(commit);
|
|
47
|
+
};
|
|
48
|
+
HybridPartition.prototype.storeSnapshot = function (streamId, snapshot, version) {
|
|
49
|
+
return this.localPartition.storeSnapshot(streamId, snapshot, version);
|
|
50
|
+
};
|
|
51
|
+
HybridPartition.prototype.checkIsSnapshotToOld = function (snapshot) {
|
|
52
|
+
if (!snapshot) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (snapshot.storedDateTime) {
|
|
56
|
+
var storedDateEpoch = new Date(snapshot.storedDateTime).getTime();
|
|
57
|
+
var nowEpoch = new Date().getTime();
|
|
58
|
+
var elapsedTimeInMilliSeconds = nowEpoch - storedDateEpoch;
|
|
59
|
+
var snapshotLifetimeMilliSeconds = this.snapshotLifeTime * 60 * 1000;
|
|
60
|
+
return elapsedTimeInMilliSeconds > snapshotLifetimeMilliSeconds;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
64
|
+
HybridPartition.prototype.loadSnapshot = function (streamId, callback) {
|
|
65
|
+
var _this = this;
|
|
66
|
+
var startTime = performance.now();
|
|
67
|
+
return new bluebird_1["default"](function (resolve) {
|
|
68
|
+
_this.localPartition.loadSnapshot(streamId).then(function (localSnapshot) {
|
|
69
|
+
var isSnapshotToOld = _this.checkIsSnapshotToOld(localSnapshot);
|
|
70
|
+
if (localSnapshot && !isSnapshotToOld) {
|
|
71
|
+
log.info('loadSnapshot: Using local snapshot');
|
|
72
|
+
callback === null || callback === void 0 ? void 0 : callback(null, localSnapshot);
|
|
73
|
+
resolve(localSnapshot);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
_this.remotePartition
|
|
77
|
+
.loadSnapshot(streamId)
|
|
78
|
+
.then(function (remoteSnapshot) {
|
|
79
|
+
log.info('loadSnapshot: Using remote snapshot');
|
|
80
|
+
if (remoteSnapshot) {
|
|
81
|
+
_this.localPartition.storeSnapshot(remoteSnapshot.id, remoteSnapshot.snapshot, remoteSnapshot.version);
|
|
82
|
+
_this.localPartition.truncateStreamFrom(remoteSnapshot.id, 0, true);
|
|
83
|
+
}
|
|
84
|
+
callback === null || callback === void 0 ? void 0 : callback(null, remoteSnapshot);
|
|
85
|
+
resolve(remoteSnapshot);
|
|
86
|
+
})["catch"](function (error) {
|
|
87
|
+
log.warn('Failed to load snapshot with stream id %s from remote partition', streamId);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
})["finally"](function () {
|
|
91
|
+
var endTime = performance.now();
|
|
92
|
+
var queryTime = (endTime - startTime) / 1000;
|
|
93
|
+
if (_this.loggingOptions.loggingEnabled && queryTime > _this.loggingOptions.loadSnapshotMaxTime) {
|
|
94
|
+
log.error('Loading snapshot with id %s, took longer than allowed max time of %s seconds.', streamId, _this.loggingOptions.loadSnapshotMaxTime);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
HybridPartition.prototype.queryStream = function (streamId, fromEventSequence, callback) {
|
|
99
|
+
var _this = this;
|
|
100
|
+
log.debug('queryStream, streamId %s ,fromEventSequence %s', streamId, fromEventSequence);
|
|
101
|
+
return new bluebird_1["default"](function (resolve) {
|
|
102
|
+
_this.localPartition.loadSnapshot(streamId).then(function (localSnapshot) {
|
|
103
|
+
var currentPartition = _this.localPartition;
|
|
104
|
+
var isSnapshotToOld = _this.checkIsSnapshotToOld(localSnapshot);
|
|
105
|
+
if (!localSnapshot || isSnapshotToOld) {
|
|
106
|
+
currentPartition = _this.remotePartition;
|
|
107
|
+
}
|
|
108
|
+
currentPartition.queryStream(streamId, fromEventSequence).then(function (queryStream) {
|
|
109
|
+
callback === null || callback === void 0 ? void 0 : callback(null, queryStream);
|
|
110
|
+
resolve(queryStream);
|
|
111
|
+
return;
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
HybridPartition.prototype.removeSnapshot = function (streamId) {
|
|
117
|
+
return this.localPartition.removeSnapshot(streamId);
|
|
118
|
+
};
|
|
119
|
+
HybridPartition.prototype.truncateStreamFrom = function (streamId, commit, remove, callback) {
|
|
120
|
+
return this.localPartition.truncateStreamFrom(streamId, commit, remove, callback);
|
|
121
|
+
};
|
|
122
|
+
HybridPartition.prototype.applyCommitHeader = function (streamId, commit, remove, callback) {
|
|
123
|
+
return this.localPartition.applyCommitHeader(streamId, commit, remove, callback);
|
|
124
|
+
};
|
|
125
|
+
return HybridPartition;
|
|
126
|
+
}());
|
|
127
|
+
exports["default"] = HybridPartition;
|
|
128
|
+
//# sourceMappingURL=HybridPartition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HybridPartition.js","sourceRoot":"","sources":["../src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AC;IAED,wCAAc,GAAd,UAAe,QAAgB;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,4CAAkB,GAAlB,UACE,QAAgB,EAChB,MAAmC,EACnC,MAA4C,EAC5C,QAAqC;QAErC,OAAO,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpF,CAAC;IAED,2CAAiB,GAAjB,UAAkB,QAAgB,EAAE,MAAmC,EAAE,MAAW,EAAE,QAAoB;QACxG,OAAO,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnF,CAAC;IACH,sBAAC;AAAD,CAAC,AApJD,IAoJC;AAED,qBAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
exports.__esModule = true;
|
|
42
|
+
var bluebird_1 = __importDefault(require("bluebird"));
|
|
43
|
+
var HybridPartition_1 = __importDefault(require("./HybridPartition"));
|
|
44
|
+
var DEFAULT_PARTITION = 'master';
|
|
45
|
+
var HybridPersistence = (function () {
|
|
46
|
+
function HybridPersistence(localPersistence, remotePersistence, autoCleanLocalPartition, snapshotLifeTime, loggingOptions) {
|
|
47
|
+
this.localPersistence = localPersistence;
|
|
48
|
+
this.remotePersistence = remotePersistence;
|
|
49
|
+
this.autoCleanLocalPartition = autoCleanLocalPartition;
|
|
50
|
+
this.snapshotLifeTime = snapshotLifeTime;
|
|
51
|
+
this.loggingOptions = loggingOptions;
|
|
52
|
+
this.partitions = {};
|
|
53
|
+
}
|
|
54
|
+
HybridPersistence.prototype.openPartition = function (partitionId) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
if (partitionId === void 0) { partitionId = DEFAULT_PARTITION; }
|
|
57
|
+
return new bluebird_1["default"](function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
58
|
+
var partition, localPartition, remotePartition, newPartition_1;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
partition = this.getPartition(partitionId);
|
|
63
|
+
if (!partition) return [3, 1];
|
|
64
|
+
resolve(partition);
|
|
65
|
+
return [3, 4];
|
|
66
|
+
case 1: return [4, this.localPersistence.openPartition(partitionId)];
|
|
67
|
+
case 2:
|
|
68
|
+
localPartition = _a.sent();
|
|
69
|
+
return [4, this.remotePersistence.openPartition(partitionId)];
|
|
70
|
+
case 3:
|
|
71
|
+
remotePartition = _a.sent();
|
|
72
|
+
newPartition_1 = new HybridPartition_1["default"](localPartition, remotePartition, this.autoCleanLocalPartition, this.snapshotLifeTime, this.loggingOptions);
|
|
73
|
+
this.setPartition(partitionId, newPartition_1);
|
|
74
|
+
newPartition_1.open().then(function () {
|
|
75
|
+
resolve(newPartition_1);
|
|
76
|
+
});
|
|
77
|
+
_a.label = 4;
|
|
78
|
+
case 4: return [2];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}); });
|
|
82
|
+
};
|
|
83
|
+
HybridPersistence.prototype.getPartition = function (partitionId) {
|
|
84
|
+
if (partitionId === void 0) { partitionId = DEFAULT_PARTITION; }
|
|
85
|
+
return this.partitions[partitionId];
|
|
86
|
+
};
|
|
87
|
+
HybridPersistence.prototype.setPartition = function (partitionId, partition) {
|
|
88
|
+
this.partitions[partitionId || DEFAULT_PARTITION] = partition;
|
|
89
|
+
return partition;
|
|
90
|
+
};
|
|
91
|
+
return HybridPersistence;
|
|
92
|
+
}());
|
|
93
|
+
exports["default"] = HybridPersistence;
|
|
94
|
+
//# sourceMappingURL=HybridPersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HybridPersistence.js","sourceRoot":"","sources":["../src/HybridPersistence.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAuC;AACvC,sEAAgD;AAwChD,IAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC;IAGE,2BACU,gBAA6B,EAC7B,iBAA8B,EAC9B,uBAAgC,EAChC,gBAAwB,EACxB,cAA8B;QAJ9B,qBAAgB,GAAhB,gBAAgB,CAAa;QAC7B,sBAAiB,GAAjB,iBAAiB,CAAa;QAC9B,4BAAuB,GAAvB,uBAAuB,CAAS;QAChC,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,mBAAc,GAAd,cAAc,CAAgB;QAPhC,eAAU,GAA8B,EAAE,CAAC;IAQhD,CAAC;IAEJ,yCAAa,GAAb,UAAc,WAAuC;QAArD,iBAeC;QAfa,4BAAA,EAAA,+BAAuC;QACnD,OAAO,IAAI,qBAAe,CAAC,UAAO,OAAO;;;;;wBACjC,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;6BAC7C,SAAS,EAAT,cAAS;wBACX,OAAO,CAAC,SAAS,CAAC,CAAC;;4BAEI,WAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,WAAW,CAAC,EAAA;;wBAAvE,cAAc,GAAG,SAAsD;wBACrD,WAAM,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,EAAA;;wBAAzE,eAAe,GAAG,SAAuD;wBACzE,iBAAe,IAAI,4BAAe,CAAC,cAAc,EAAE,eAAe,EAAE,IAAI,CAAC,uBAAuB,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;wBACpJ,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,cAAY,CAAC,CAAC;wBAC7C,cAAY,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC;4BACvB,OAAO,CAAC,cAAY,CAAC,CAAC;wBACxB,CAAC,CAAC,CAAC;;;;;aAEN,CAAC,CAAC;IACL,CAAC;IAEO,wCAAY,GAApB,UAAqB,WAAuC;QAAvC,4BAAA,EAAA,+BAAuC;QAC1D,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAEO,wCAAY,GAApB,UAAqB,WAAoB,EAAE,SAAqB;QAC9D,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,iBAAiB,CAAC,GAAG,SAAS,CAAC;QAC9D,OAAO,SAAS,CAAC;IACnB,CAAC;IACH,wBAAC;AAAD,CAAC,AApCD,IAoCC;AAED,qBAAe,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.HybridPersistence = exports.HybridPartition = void 0;
|
|
7
|
+
var HybridPartition_1 = __importDefault(require("./HybridPartition"));
|
|
8
|
+
exports.HybridPartition = HybridPartition_1["default"];
|
|
9
|
+
var HybridPersistence_1 = __importDefault(require("./HybridPersistence"));
|
|
10
|
+
exports.HybridPersistence = HybridPersistence_1["default"];
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAgD;AAGvC,0BAHF,4BAAe,CAGE;AAFxB,0EAAoD;AAE1B,4BAFnB,8BAAiB,CAEmB"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tapeworm_persistence_store_hybrid",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"prettier": "prettier-config-surikaterna",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"build": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/surikaterna/tapeworm_persistence_store_hybrid.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "Gustav Albertsson",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/surikaterna/tapeworm_persistence_store_hybrid/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/surikaterna/tapeworm_persistence_store_hybrid#readme",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/bluebird": "^3.5.36",
|
|
24
|
+
"@types/jest": "^27.0.1",
|
|
25
|
+
"fake-indexeddb": "^3.1.3",
|
|
26
|
+
"jest": "^27.3.1",
|
|
27
|
+
"prettier": "^2.3.2",
|
|
28
|
+
"prettier-config-surikaterna": "^1.0.1",
|
|
29
|
+
"tapeworm": "^0.3.5",
|
|
30
|
+
"tapeworm_persistence_store_indexeddb": "^0.2.6",
|
|
31
|
+
"ts-jest": "^27.0.5",
|
|
32
|
+
"typescript": "^4.4.2"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"bluebird": "^3.7.2",
|
|
36
|
+
"slf": "^1.0.3"
|
|
37
|
+
}
|
|
38
|
+
}
|