Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ag-timemachine

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ag-timemachine - npm Package Compare versions

Comparing version 1.0.15 to 1.0.16

2

package.json
{
"name": "ag-timemachine",
"version": "1.0.15",
"version": "1.0.16",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -138,3 +138,3 @@ import { TmData, TmFrequence } from "./AgTypes";

private buffer;
private autoFlush;
private pollhandle?;
private lastSnapshotTime?;

@@ -147,2 +147,3 @@ private diff?;

unbind(): Promise<void>;
flushBuffer(retry?: number): Promise<void>;
}

@@ -53,2 +53,3 @@ "use strict";

var AgVueWrap_1 = require("ag-utilities/AgVueWrap");
var AgPoll_1 = require("ag-utilities/AgPoll");
var minBufferSpan = 60;

@@ -66,3 +67,2 @@ var snapshotSpan = 60;

this.buffer = [];
this.autoFlush = false;
}

@@ -123,46 +123,19 @@ AgTmObject.prototype.loadLatest = function () {

return __awaiter(this, void 0, void 0, function () {
var datas, _a;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
this.diff = (0, AgVueWrap_1.diffComputed)(dataSource);
this.diff.onPatched = function (delta) {
var _a;
var time = _this.updateDeltas({ time: new Date(), value: _this.diff.value });
_this.updateLifeTime(time);
_this.updateFrequence(time);
var record = { time: time, delta: delta };
if (!_this.lastSnapshotTime || (new Date().getTime() - _this.lastSnapshotTime.getTime()) > snapshotSpan * 1000) {
record.snapshot = { value: (_a = _this.diff) === null || _a === void 0 ? void 0 : _a.value };
_this.lastSnapshotTime = new Date();
}
_this.buffer.push(__assign(__assign({}, record), { _id: AgHelper_1.AgHelper.uuid() }));
};
this.autoFlush = true;
_b.label = 1;
case 1:
if (!this.autoFlush) return [3 /*break*/, 8];
if (!this.buffer.length) return [3 /*break*/, 6];
datas = this.buffer.splice(0);
_b.label = 2;
case 2:
_a = this.autoFlush;
if (!_a) return [3 /*break*/, 4];
return [4 /*yield*/, this.table.flush(datas)];
case 3:
_a = !(_b.sent());
_b.label = 4;
case 4:
if (!_a) return [3 /*break*/, 6];
return [4 /*yield*/, AgHelper_1.AgHelper.sleep(1000)];
case 5:
_b.sent();
return [3 /*break*/, 2];
case 6: return [4 /*yield*/, AgHelper_1.AgHelper.sleep(1000)];
case 7:
_b.sent();
return [3 /*break*/, 1];
case 8: return [2 /*return*/];
}
return __generator(this, function (_a) {
this.diff = (0, AgVueWrap_1.diffComputed)(dataSource);
this.diff.onPatched = function (delta) {
var _a;
var time = _this.updateDeltas({ time: new Date(), value: _this.diff.value });
_this.updateLifeTime(time);
_this.updateFrequence(time);
var record = { time: time, delta: delta };
if (!_this.lastSnapshotTime || (new Date().getTime() - _this.lastSnapshotTime.getTime()) > snapshotSpan * 1000) {
record.snapshot = { value: (_a = _this.diff) === null || _a === void 0 ? void 0 : _a.value };
_this.lastSnapshotTime = new Date();
}
_this.buffer.push(__assign(__assign({}, record), { _id: AgHelper_1.AgHelper.uuid() }));
};
this.pollhandle = AgPoll_1.AgPoll.poll(1000, this.flushBuffer);
return [2 /*return*/];
});

@@ -172,5 +145,4 @@ });

AgTmObject.prototype.unbind = function () {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var datas, retry, _b;
return __generator(this, function (_c) {

@@ -180,24 +152,32 @@ switch (_c.label) {

(_a = this.diff) === null || _a === void 0 ? void 0 : _a.stop();
this.autoFlush = false;
(_b = this.pollhandle) === null || _b === void 0 ? void 0 : _b.stop();
return [4 /*yield*/, this.flushBuffer(3)];
case 1:
_c.sent();
return [2 /*return*/];
}
});
});
};
AgTmObject.prototype.flushBuffer = function (retry) {
if (retry === void 0) { retry = -1; }
return __awaiter(this, void 0, void 0, function () {
var datas;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.buffer.length) return [3 /*break*/, 6];
datas = this.buffer.splice(0);
retry = 0;
_c.label = 1;
case 1:
_b = retry++ < 3;
if (!_b) return [3 /*break*/, 3];
return [4 /*yield*/, this.table.flush(datas)];
datas = this.buffer.splice(0, 100);
_a.label = 1;
case 1: return [4 /*yield*/, this.table.flush(datas)];
case 2:
_b = !(_c.sent());
_c.label = 3;
if (!(!(_a.sent()) && (retry < 0 || --retry >= 0))) return [3 /*break*/, 4];
return [4 /*yield*/, AgHelper_1.AgHelper.sleep(1000)];
case 3:
if (!_b) return [3 /*break*/, 5];
return [4 /*yield*/, AgHelper_1.AgHelper.sleep(1000)];
case 4:
_c.sent();
_a.sent();
return [3 /*break*/, 1];
case 4: return [4 /*yield*/, AgHelper_1.AgHelper.sleep(10)];
case 5:
if (retry == 3)
console.log("[TIME MACHINE - DATA] failed to flush buffer: ", datas);
_c.label = 6;
_a.sent();
return [3 /*break*/, 0];
case 6: return [2 /*return*/];

@@ -204,0 +184,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc