From fcdd468a4dd180ceee771b8f4a06efee162ee892 Mon Sep 17 00:00:00 2001 From: Florent Date: Mon, 12 Jul 2021 16:12:34 +0200 Subject: [PATCH] add prepack script --- .gitignore | 3 +- build/index.d.ts | 2 + build/index.d.ts.map | 1 + build/index.js | 5 + build/listener-rss-aggregator.d.ts | 38 +++ build/listener-rss-aggregator.d.ts.map | 1 + build/listener-rss-aggregator.js | 346 +++++++++++++++++++++++++ build/sqlite-tools.d.ts | 13 + build/sqlite-tools.d.ts.map | 1 + build/sqlite-tools.js | 265 +++++++++++++++++++ package.json | 7 +- 11 files changed, 677 insertions(+), 5 deletions(-) create mode 100644 build/index.d.ts create mode 100644 build/index.d.ts.map create mode 100644 build/index.js create mode 100644 build/listener-rss-aggregator.d.ts create mode 100644 build/listener-rss-aggregator.d.ts.map create mode 100644 build/listener-rss-aggregator.js create mode 100644 build/sqlite-tools.d.ts create mode 100644 build/sqlite-tools.d.ts.map create mode 100644 build/sqlite-tools.js diff --git a/.gitignore b/.gitignore index 2d7336e..78f2710 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -build/ node_modules/ -.idea/ \ No newline at end of file +.idea/ diff --git a/build/index.d.ts b/build/index.d.ts new file mode 100644 index 0000000..8eee94e --- /dev/null +++ b/build/index.d.ts @@ -0,0 +1,2 @@ +export { ListenerRssAggregator } from "./listener-rss-aggregator"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/build/index.d.ts.map b/build/index.d.ts.map new file mode 100644 index 0000000..ec8fe1f --- /dev/null +++ b/build/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"} \ No newline at end of file diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..641762f --- /dev/null +++ b/build/index.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ListenerRssAggregator = void 0; +var listener_rss_aggregator_1 = require("./listener-rss-aggregator"); +Object.defineProperty(exports, "ListenerRssAggregator", { enumerable: true, get: function () { return listener_rss_aggregator_1.ListenerRssAggregator; } }); diff --git a/build/listener-rss-aggregator.d.ts b/build/listener-rss-aggregator.d.ts new file mode 100644 index 0000000..441bf21 --- /dev/null +++ b/build/listener-rss-aggregator.d.ts @@ -0,0 +1,38 @@ +/// +import EventEmitter from "events"; +import { ListenerRss } from "listener-rss"; +import { SqliteTools } from "./sqlite-tools"; +/** + * Permit to manage a ListenerRSS array, data storage and event aggregation + */ +export declare class ListenerRssAggregator extends EventEmitter { + private listenerMap; + private looprunning; + private sqliteDb; + constructor(args: { + sqliteDB: SqliteTools; + configInstantiated: Map; + }); + static instantiateAggregator(path: string): Promise<{ + sqliteDB: SqliteTools; + configInstantiated: Map; + }>; + /** + * @brief [private don't use it] create a sqlite instance for the specified path and load the data + */ + private static loadDb; + /** + * @brief [private don't use it] load the actual config inside the sqliteTools instance specified + */ + private static extractConfig; + getAllConfigs(): Promise; + editConfig(callback: (config: ListenerRss.Config[]) => ListenerRss.Config[]): Promise; + private addNewListener; + private removeOldListener; + registerListener(info: ListenerRss.Config): Promise; + unregisterListener(addr: string): Promise; + saveOverride(expectedConfig: ListenerRss.Config[]): Promise; + startAll(): void; + stopAll(): void; +} +//# sourceMappingURL=listener-rss-aggregator.d.ts.map \ No newline at end of file diff --git a/build/listener-rss-aggregator.d.ts.map b/build/listener-rss-aggregator.d.ts.map new file mode 100644 index 0000000..3c09608 --- /dev/null +++ b/build/listener-rss-aggregator.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"listener-rss-aggregator.d.ts","sourceRoot":"","sources":["../src/listener-rss-aggregator.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,WAAW,CAAkB;IAErC,OAAO,CAAC,QAAQ,CAAc;gBAElB,IAAI,EAAE;QAChB,QAAQ,EAAE,WAAW,CAAC;QACtB,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;KAC9C;WAOY,qBAAqB,CAChC,IAAI,EAAE,MAAM,GACX,OAAO,CAAC;QACT,QAAQ,EAAE,WAAW,CAAC;QACtB,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;KAC9C,CAAC;IAMF;;OAEG;mBACkB,MAAM;IAa3B;;OAEG;mBACkB,aAAa;IAO5B,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAI9C,UAAU,CACd,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,WAAW,CAAC,MAAM,EAAE,GAC/D,OAAO,CAAC,IAAI,CAAC;IAOhB,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,iBAAiB;IAanB,gBAAgB,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM;IAOzC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO/C,YAAY,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE;IAgBvD,QAAQ,IAAI,IAAI;IAOhB,OAAO,IAAI,IAAI;CAMhB"} \ No newline at end of file diff --git a/build/listener-rss-aggregator.js b/build/listener-rss-aggregator.js new file mode 100644 index 0000000..ea6192f --- /dev/null +++ b/build/listener-rss-aggregator.js @@ -0,0 +1,346 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +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()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + 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; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __values = (this && this.__values) || function(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ListenerRssAggregator = void 0; +var events_1 = __importDefault(require("events")); +var listener_rss_1 = require("listener-rss"); +var sqlite_tools_1 = require("./sqlite-tools"); +/** + * Permit to manage a ListenerRSS array, data storage and event aggregation + */ +var ListenerRssAggregator = /** @class */ (function (_super) { + __extends(ListenerRssAggregator, _super); + function ListenerRssAggregator(args) { + var _this = _super.call(this) || this; + _this.looprunning = false; + _this.sqliteDb = args.sqliteDB; + _this.listenerMap = args.configInstantiated; + return _this; + } + ListenerRssAggregator.instantiateAggregator = function (path) { + return __awaiter(this, void 0, void 0, function () { + var sqliteDB, configInstantiated; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + sqliteDB = new sqlite_tools_1.SqliteTools(path); + return [4 /*yield*/, this.loadDb(sqliteDB)]; + case 1: + configInstantiated = _a.sent(); + return [2 /*return*/, { sqliteDB: sqliteDB, configInstantiated: configInstantiated }]; + } + }); + }); + }; + /** + * @brief [private don't use it] create a sqlite instance for the specified path and load the data + */ + ListenerRssAggregator.loadDb = function (sqliteDb) { + return __awaiter(this, void 0, void 0, function () { + var config, configInstantiated, config_1, config_1_1, obj; + var e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, this.extractConfig(sqliteDb)]; + case 1: + config = _b.sent(); + configInstantiated = new Map(); + try { + for (config_1 = __values(config), config_1_1 = config_1.next(); !config_1_1.done; config_1_1 = config_1.next()) { + obj = config_1_1.value; + configInstantiated.set(obj.address, new listener_rss_1.ListenerRss(obj)); + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (config_1_1 && !config_1_1.done && (_a = config_1.return)) _a.call(config_1); + } + finally { if (e_1) throw e_1.error; } + } + return [2 /*return*/, configInstantiated]; + } + }); + }); + }; + /** + * @brief [private don't use it] load the actual config inside the sqliteTools instance specified + */ + ListenerRssAggregator.extractConfig = function (sqliteDb) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, sqliteDb.ensureTableExists()]; + case 1: + _a.sent(); + return [4 /*yield*/, sqliteDb.fetchAll()]; + case 2: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + ListenerRssAggregator.prototype.getAllConfigs = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, ListenerRssAggregator.extractConfig(this.sqliteDb)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + ListenerRssAggregator.prototype.editConfig = function (callback) { + return __awaiter(this, void 0, void 0, function () { + var actualConfig; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.stopAll(); + return [4 /*yield*/, this.getAllConfigs()]; + case 1: + actualConfig = _a.sent(); + this.saveOverride(callback(actualConfig)); + this.startAll(); + return [2 /*return*/]; + } + }); + }); + }; + ListenerRssAggregator.prototype.addNewListener = function (info) { + var _this = this; + var newListener = new listener_rss_1.ListenerRss(info); + this.listenerMap.set(newListener.address, newListener); + newListener.on("update", function (obj) { + return _this.emit("update", { + items: obj, + addressListener: newListener.address, + }); + }); + newListener.on("newEntries", function (obj) { + return _this.emit("newEntries", { + items: obj, + addressListener: newListener.address, + }); + }); + newListener.on("error", function (err) { + return _this.emit("error", { + error: err, + addressListener: newListener.address, + }); + }); + return newListener; + }; + ListenerRssAggregator.prototype.removeOldListener = function (addr) { + var oldListener = this.listenerMap.get(addr); + if (!oldListener) + return; + oldListener.stop(); + oldListener + .removeAllListeners("update") + .removeAllListeners("newEntries") + .removeAllListeners("error"); + this.listenerMap.delete(addr); + }; + ListenerRssAggregator.prototype.registerListener = function (info) { + return __awaiter(this, void 0, void 0, function () { + var listener; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (this.listenerMap.has(info.address)) + return [2 /*return*/]; + listener = this.addNewListener(info); + return [4 /*yield*/, this.sqliteDb.insertListener(listener)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + ListenerRssAggregator.prototype.unregisterListener = function (addr) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.listenerMap.has(addr)) + return [2 /*return*/]; + this.removeOldListener(addr); + return [4 /*yield*/, this.sqliteDb.deleteListener(addr)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + ListenerRssAggregator.prototype.saveOverride = function (expectedConfig) { + return __awaiter(this, void 0, void 0, function () { + var actualConfig, _a, _b, newItem, e_2_1, _c, _d, oldItem, e_3_1; + var e_2, _e, e_3, _f; + return __generator(this, function (_g) { + switch (_g.label) { + case 0: return [4 /*yield*/, this.getAllConfigs()]; + case 1: + actualConfig = _g.sent(); + _g.label = 2; + case 2: + _g.trys.push([2, 7, 8, 9]); + _a = __values(expectedConfig.filter(function (item) { return !actualConfig.includes(item); })), _b = _a.next(); + _g.label = 3; + case 3: + if (!!_b.done) return [3 /*break*/, 6]; + newItem = _b.value; + return [4 /*yield*/, this.registerListener(newItem)]; + case 4: + _g.sent(); + _g.label = 5; + case 5: + _b = _a.next(); + return [3 /*break*/, 3]; + case 6: return [3 /*break*/, 9]; + case 7: + e_2_1 = _g.sent(); + e_2 = { error: e_2_1 }; + return [3 /*break*/, 9]; + case 8: + try { + if (_b && !_b.done && (_e = _a.return)) _e.call(_a); + } + finally { if (e_2) throw e_2.error; } + return [7 /*endfinally*/]; + case 9: + _g.trys.push([9, 14, 15, 16]); + _c = __values(actualConfig.filter(function (item) { return !expectedConfig.includes(item); })), _d = _c.next(); + _g.label = 10; + case 10: + if (!!_d.done) return [3 /*break*/, 13]; + oldItem = _d.value; + return [4 /*yield*/, this.unregisterListener(oldItem.address)]; + case 11: + _g.sent(); + _g.label = 12; + case 12: + _d = _c.next(); + return [3 /*break*/, 10]; + case 13: return [3 /*break*/, 16]; + case 14: + e_3_1 = _g.sent(); + e_3 = { error: e_3_1 }; + return [3 /*break*/, 16]; + case 15: + try { + if (_d && !_d.done && (_f = _c.return)) _f.call(_c); + } + finally { if (e_3) throw e_3.error; } + return [7 /*endfinally*/]; + case 16: return [2 /*return*/]; + } + }); + }); + }; + ListenerRssAggregator.prototype.startAll = function () { + var e_4, _a; + if (this.looprunning) + return; + this.looprunning = true; + try { + for (var _b = __values(this.listenerMap.values()), _c = _b.next(); !_c.done; _c = _b.next()) { + var item = _c.value; + item.start(); + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + }; + ListenerRssAggregator.prototype.stopAll = function () { + var e_5, _a; + if (!this.looprunning) + return; + this.looprunning = false; + try { + for (var _b = __values(this.listenerMap.values()), _c = _b.next(); !_c.done; _c = _b.next()) { + var item = _c.value; + item.stop(); + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } + }; + return ListenerRssAggregator; +}(events_1.default)); +exports.ListenerRssAggregator = ListenerRssAggregator; diff --git a/build/sqlite-tools.d.ts b/build/sqlite-tools.d.ts new file mode 100644 index 0000000..d4ff528 --- /dev/null +++ b/build/sqlite-tools.d.ts @@ -0,0 +1,13 @@ +import { ListenerRss } from "listener-rss"; +import { DatabaseConnection } from "@databases/sqlite"; +export declare class SqliteTools { + path?: string; + constructor(path?: string); + withDB(callback: (db: DatabaseConnection) => Promise): Promise; + ensureTableExists(): Promise; + fetchAll(): Promise; + insertListener(listener: ListenerRss.Config): Promise; + deleteListener(adr: string): Promise; + updateAll(listeners: ListenerRss.Config[]): Promise; +} +//# sourceMappingURL=sqlite-tools.d.ts.map \ No newline at end of file diff --git a/build/sqlite-tools.d.ts.map b/build/sqlite-tools.d.ts.map new file mode 100644 index 0000000..5cb0efd --- /dev/null +++ b/build/sqlite-tools.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sqlite-tools.d.ts","sourceRoot":"","sources":["../src/sqlite-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAgB,EAAE,kBAAkB,EAAO,MAAM,mBAAmB,CAAC;AAErE,qBAAa,WAAW;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEF,IAAI,CAAC,EAAE,MAAM;IAInB,MAAM,CAAC,IAAI,EACf,QAAQ,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GAClD,OAAO,CAAC,IAAI,CAAC;IASV,iBAAiB;IAgBjB,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAezC,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM;IAW3C,cAAc,CAAC,GAAG,EAAE,MAAM;IAQ1B,SAAS,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE;CAchD"} \ No newline at end of file diff --git a/build/sqlite-tools.js b/build/sqlite-tools.js new file mode 100644 index 0000000..b220b49 --- /dev/null +++ b/build/sqlite-tools.js @@ -0,0 +1,265 @@ +"use strict"; +var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { + if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } + return cooked; +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + 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; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __values = (this && this.__values) || function(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SqliteTools = void 0; +var sqlite_1 = __importStar(require("@databases/sqlite")); +var SqliteTools = /** @class */ (function () { + function SqliteTools(path) { + this.path = path; + } + SqliteTools.prototype.withDB = function (callback) { + return __awaiter(this, void 0, void 0, function () { + var db; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + db = sqlite_1.default(this.path); + _a.label = 1; + case 1: + _a.trys.push([1, , 2, 4]); + return [2 /*return*/, callback(db)]; + case 2: return [4 /*yield*/, db.dispose()]; + case 3: + _a.sent(); + return [7 /*endfinally*/]; + case 4: return [2 /*return*/]; + } + }); + }); + }; + SqliteTools.prototype.ensureTableExists = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.withDB(function (db) { return __awaiter(_this, void 0, void 0, function () { + var req; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + req = sqlite_1.sql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["CREATE TABLE IF NOT EXISTS listeners\n (\n address TEXT NOT NULL,\n customfields TEXT DEFAULT '[]' NOT NULL,\n timeloop INTEGER DEFAULT 300 NOT NULL,\n last_entries_links TEXT DEFAULT '[]' NOT NULL,\n PRIMARY KEY (address),\n CHECK(timeloop >= 0)\n );"], ["CREATE TABLE IF NOT EXISTS listeners\n (\n address TEXT NOT NULL,\n customfields TEXT DEFAULT '[]' NOT NULL,\n timeloop INTEGER DEFAULT 300 NOT NULL,\n last_entries_links TEXT DEFAULT '[]' NOT NULL,\n PRIMARY KEY (address),\n CHECK(timeloop >= 0)\n );"]))); + return [4 /*yield*/, db.query(req)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + SqliteTools.prototype.fetchAll = function () { + return __awaiter(this, void 0, void 0, function () { + var rows; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.withDB(function (db) { return __awaiter(_this, void 0, void 0, function () { + var req; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + req = sqlite_1.sql(templateObject_2 || (templateObject_2 = __makeTemplateObject(["SELECT *\n FROM listeners"], ["SELECT *\n FROM listeners"]))); + return [4 /*yield*/, db.query(req)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); })]; + case 1: + rows = _a.sent(); + return [2 /*return*/, rows.map(function (row) { return ({ + address: row["address"], + customfields: JSON.parse(row["customfields"]), + timeloop: row["timeloop"], + lastEntriesLinks: JSON.parse(row["last_entries_links"]), + }); })]; + } + }); + }); + }; + SqliteTools.prototype.insertListener = function (listener) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.withDB(function (db) { return __awaiter(_this, void 0, void 0, function () { + var req; + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + req = sqlite_1.sql(templateObject_3 || (templateObject_3 = __makeTemplateObject(["INSERT INTO listeners (address, timeloop, customfields, last_entries_links)\n VALUES (", ",\n ", ",\n ", ",\n ", ")"], ["INSERT INTO listeners (address, timeloop, customfields, last_entries_links)\n VALUES (", ",\n ", ",\n ", ",\n ", ")"])), listener.address, listener.timeloop, JSON.stringify((_a = listener.customfields) !== null && _a !== void 0 ? _a : []), JSON.stringify((_b = listener.lastEntriesLinks) !== null && _b !== void 0 ? _b : [])); + return [4 /*yield*/, db.query(req)]; + case 1: + _c.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + SqliteTools.prototype.deleteListener = function (adr) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.withDB(function (db) { return __awaiter(_this, void 0, void 0, function () { + var req; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + req = sqlite_1.sql(templateObject_4 || (templateObject_4 = __makeTemplateObject(["DELETE FROM listeners\n WHERE address = ", ""], ["DELETE FROM listeners\n WHERE address = ", ""])), adr); + return [4 /*yield*/, db.query(req)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + SqliteTools.prototype.updateAll = function (listeners) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.withDB(function (db) { return __awaiter(_this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, db.tx(function (transaction) { return __awaiter(_this, void 0, void 0, function () { + var listeners_1, listeners_1_1, listener, req, e_1_1; + var e_1, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 5, 6, 7]); + listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); + _b.label = 1; + case 1: + if (!!listeners_1_1.done) return [3 /*break*/, 4]; + listener = listeners_1_1.value; + req = sqlite_1.sql(templateObject_5 || (templateObject_5 = __makeTemplateObject(["UPDATE listeners\n SET last_entries_links = ", "\n WHERE address = ", ""], ["UPDATE listeners\n SET last_entries_links = ", + "\n WHERE address = ", ""])), JSON.stringify(listener.lastEntriesLinks), listener.address); + return [4 /*yield*/, transaction.query(req)]; + case 2: + _b.sent(); + _b.label = 3; + case 3: + listeners_1_1 = listeners_1.next(); + return [3 /*break*/, 1]; + case 4: return [3 /*break*/, 7]; + case 5: + e_1_1 = _b.sent(); + e_1 = { error: e_1_1 }; + return [3 /*break*/, 7]; + case 6: + try { + if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1); + } + finally { if (e_1) throw e_1.error; } + return [7 /*endfinally*/]; + case 7: return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + return SqliteTools; +}()); +exports.SqliteTools = SqliteTools; +var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5; diff --git a/package.json b/package.json index 69d299b..b2953ac 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,13 @@ "url": "https://zeteo.me/gitea/Outils-PeerTube/listener-rss-agregators/issues" }, "files": [ - "build/" + "build/", + "README.md", + "package.json" ], "scripts": { "test": "cross-env TS_NODE_PROJECT='./tests/tsconfig.json' mocha --require ts-node/register ./tests/**/*-spec.ts", - "build": "tsc", - "postinstall": "npm run build" + "build": "ls . && tsc -p ." }, "keywords": [ "RSS",