eternal-timer 2.2.1 → 2.4.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.md +89 -46
- package/dist/cjs/Log.cjs +0 -21
- package/dist/cjs/{Log.js.map → Log.cjs.map} +1 -1
- package/dist/cjs/TimersManager/JSONLTimersManager.cjs +25 -0
- package/dist/cjs/TimersManager/JSONLTimersManager.cjs.map +1 -0
- package/dist/cjs/TimersManager/JSONLTimersManager.d.ts +18 -0
- package/dist/cjs/TimersManager/JSONLTimersManager.d.ts.map +1 -0
- package/dist/cjs/TimersManager/PlainTextTimersManager.cjs +25 -0
- package/dist/cjs/TimersManager/PlainTextTimersManager.cjs.map +1 -0
- package/dist/cjs/TimersManager/PlainTextTimersManager.d.ts +18 -0
- package/dist/cjs/TimersManager/PlainTextTimersManager.d.ts.map +1 -0
- package/dist/cjs/TimersManager/TimersManager.cjs +211 -0
- package/dist/cjs/TimersManager/TimersManager.cjs.map +1 -0
- package/dist/cjs/TimersManager/TimersManager.d.ts +87 -0
- package/dist/cjs/TimersManager/TimersManager.d.ts.map +1 -0
- package/dist/cjs/TimersStore/JSONLTimersStore.cjs +50 -0
- package/dist/cjs/TimersStore/JSONLTimersStore.cjs.map +1 -0
- package/dist/cjs/TimersStore/JSONLTimersStore.d.ts +16 -0
- package/dist/cjs/TimersStore/JSONLTimersStore.d.ts.map +1 -0
- package/dist/cjs/TimersStore/PlainTextTimersStore.cjs +56 -0
- package/dist/cjs/TimersStore/PlainTextTimersStore.cjs.map +1 -0
- package/dist/cjs/TimersStore/PlainTextTimersStore.d.ts +16 -0
- package/dist/cjs/TimersStore/PlainTextTimersStore.d.ts.map +1 -0
- package/dist/cjs/TimersStore/TimersStore.cjs +44 -0
- package/dist/cjs/TimersStore/TimersStore.cjs.map +1 -0
- package/dist/cjs/TimersStore/TimersStore.d.ts +12 -0
- package/dist/cjs/TimersStore/TimersStore.d.ts.map +1 -0
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/types.d.ts +11 -1
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/Log.js +0 -21
- package/dist/esm/Log.js.map +1 -1
- package/dist/esm/TimersManager/JSONLTimersManager.d.ts +18 -0
- package/dist/esm/TimersManager/JSONLTimersManager.d.ts.map +1 -0
- package/dist/esm/TimersManager/JSONLTimersManager.js +21 -0
- package/dist/esm/TimersManager/JSONLTimersManager.js.map +1 -0
- package/dist/esm/TimersManager/PlainTextTimersManager.d.ts +18 -0
- package/dist/esm/TimersManager/PlainTextTimersManager.d.ts.map +1 -0
- package/dist/esm/TimersManager/PlainTextTimersManager.js +21 -0
- package/dist/esm/TimersManager/PlainTextTimersManager.js.map +1 -0
- package/dist/esm/TimersManager/TimersManager.d.ts +87 -0
- package/dist/esm/TimersManager/TimersManager.d.ts.map +1 -0
- package/dist/esm/TimersManager/TimersManager.js +205 -0
- package/dist/esm/TimersManager/TimersManager.js.map +1 -0
- package/dist/esm/TimersStore/JSONLTimersStore.d.ts +16 -0
- package/dist/esm/TimersStore/JSONLTimersStore.d.ts.map +1 -0
- package/dist/esm/TimersStore/JSONLTimersStore.js +46 -0
- package/dist/esm/TimersStore/JSONLTimersStore.js.map +1 -0
- package/dist/esm/TimersStore/PlainTextTimersStore.d.ts +16 -0
- package/dist/esm/TimersStore/PlainTextTimersStore.d.ts.map +1 -0
- package/dist/esm/TimersStore/PlainTextTimersStore.js +52 -0
- package/dist/esm/TimersStore/PlainTextTimersStore.js.map +1 -0
- package/dist/esm/TimersStore/TimersStore.d.ts +12 -0
- package/dist/esm/TimersStore/TimersStore.d.ts.map +1 -0
- package/dist/esm/TimersStore/TimersStore.js +37 -0
- package/dist/esm/TimersStore/TimersStore.js.map +1 -0
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +11 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +7 -4
- package/dist/cjs/JSONLTimersManager.cjs +0 -198
- package/dist/cjs/JSONLTimersManager.d.ts +0 -63
- package/dist/cjs/JSONLTimersManager.d.ts.map +0 -1
- package/dist/cjs/JSONLTimersManager.js.map +0 -1
- package/dist/cjs/PlainTextTimersManager.cjs +0 -200
- package/dist/cjs/PlainTextTimersManager.d.ts +0 -60
- package/dist/cjs/PlainTextTimersManager.d.ts.map +0 -1
- package/dist/cjs/PlainTextTimersManager.js.map +0 -1
- package/dist/cjs/TimersManager.cjs +0 -39
- package/dist/cjs/TimersManager.d.ts +0 -75
- package/dist/cjs/TimersManager.d.ts.map +0 -1
- package/dist/cjs/TimersManager.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/JSONLTimersManager.d.ts +0 -63
- package/dist/esm/JSONLTimersManager.d.ts.map +0 -1
- package/dist/esm/JSONLTimersManager.js +0 -191
- package/dist/esm/JSONLTimersManager.js.map +0 -1
- package/dist/esm/PlainTextTimersManager.d.ts +0 -60
- package/dist/esm/PlainTextTimersManager.d.ts.map +0 -1
- package/dist/esm/PlainTextTimersManager.js +0 -193
- package/dist/esm/PlainTextTimersManager.js.map +0 -1
- package/dist/esm/TimersManager.d.ts +0 -75
- package/dist/esm/TimersManager.d.ts.map +0 -1
- package/dist/esm/TimersManager.js +0 -32
- package/dist/esm/TimersManager.js.map +0 -1
- /package/dist/cjs/{searchRoot.js.map → searchRoot.cjs.map} +0 -0
- /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JSONLTimersManager = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const uuid_1 = require("uuid");
|
|
9
|
-
const readline_1 = __importDefault(require("readline"));
|
|
10
|
-
const TimersManager_js_1 = require("./TimersManager.cjs");
|
|
11
|
-
const Log_js_1 = require("./Log.cjs");
|
|
12
|
-
/**
|
|
13
|
-
* JSONLTimersManager
|
|
14
|
-
* @description
|
|
15
|
-
* Manages timers stored in a JSONL file.
|
|
16
|
-
* (This is a abstract class)
|
|
17
|
-
*
|
|
18
|
-
* - Timers are persisted in a file
|
|
19
|
-
* - Expired timers are detected by polling
|
|
20
|
-
*/
|
|
21
|
-
class JSONLTimersManager extends TimersManager_js_1.TimersManager {
|
|
22
|
-
getDefaultFilename() {
|
|
23
|
-
return ".timers.jsonl";
|
|
24
|
-
}
|
|
25
|
-
async checkTimerfileSyntax(fileData) {
|
|
26
|
-
const throwing = () => {
|
|
27
|
-
throw new Error(`Timer file's syntax is wrong`);
|
|
28
|
-
};
|
|
29
|
-
const timersData = fileData
|
|
30
|
-
.split('\n')
|
|
31
|
-
.map(l => l.trim())
|
|
32
|
-
.filter(l => l !== "");
|
|
33
|
-
for (const timerData of timersData) {
|
|
34
|
-
const parsed = JSON.parse(timerData);
|
|
35
|
-
if (!parsed.id || typeof parsed.id !== "string" || parsed.id.length !== 36)
|
|
36
|
-
throwing();
|
|
37
|
-
if (!parsed.start || typeof parsed.start !== "number" || parsed.start.toString().trim() === "")
|
|
38
|
-
throwing();
|
|
39
|
-
if (!parsed.stop || typeof parsed.stop !== "number" || parsed.stop.toString().trim() === "")
|
|
40
|
-
throwing();
|
|
41
|
-
if (parsed.title && typeof parsed.title !== "string")
|
|
42
|
-
throwing();
|
|
43
|
-
if (parsed.description && typeof parsed.description !== "string")
|
|
44
|
-
throwing();
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* createTimer
|
|
50
|
-
* @description Creates a new timer.
|
|
51
|
-
* @param length Timer duration in milliseconds
|
|
52
|
-
* @param title(string, optional) Title of the timer(only for JSONLTimersManager)
|
|
53
|
-
* @param description(string, optional) Description of the timer(only for JSONLTimersManager)
|
|
54
|
-
* @returns Promise that resolves to the timer ID (UUID)
|
|
55
|
-
* @throws If length is invalid(e.g. length < 0) or file operation fails
|
|
56
|
-
* @example
|
|
57
|
-
* const manager = new JSONLTimersManager();
|
|
58
|
-
* const newTimer = await manager.createTimer(5000);
|
|
59
|
-
* // newTimer will be id of the timer
|
|
60
|
-
*/
|
|
61
|
-
async createTimer(length, title, description) {
|
|
62
|
-
try {
|
|
63
|
-
if (length < 0) {
|
|
64
|
-
throw new Error(`Invailed length: ${length}`);
|
|
65
|
-
}
|
|
66
|
-
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
67
|
-
await this.checkTimerfileSyntax(timersRaw);
|
|
68
|
-
length = Math.trunc(length);
|
|
69
|
-
// uuid, start, end
|
|
70
|
-
const id = (0, uuid_1.v4)();
|
|
71
|
-
const now = Date.now();
|
|
72
|
-
const newTimerData = JSON.stringify({
|
|
73
|
-
id,
|
|
74
|
-
start: now,
|
|
75
|
-
stop: (now + length),
|
|
76
|
-
...(title !== undefined && { title }),
|
|
77
|
-
...(description !== undefined && { description }),
|
|
78
|
-
});
|
|
79
|
-
await fs_1.default.promises.appendFile(this.timerfiledir, newTimerData + "\n");
|
|
80
|
-
return id;
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
throw new Error(`Error when creating timer: ${e}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* removeTimer
|
|
88
|
-
* @description Removes a timer by ID.
|
|
89
|
-
* @param id ID of the timer to remove
|
|
90
|
-
* @returns void
|
|
91
|
-
* @throws If file operation fails
|
|
92
|
-
* @example
|
|
93
|
-
* await manager.removeTimer(id);
|
|
94
|
-
*/
|
|
95
|
-
async removeTimer(id) {
|
|
96
|
-
try {
|
|
97
|
-
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
98
|
-
await this.checkTimerfileSyntax(timersRaw);
|
|
99
|
-
const rl = readline_1.default.createInterface({
|
|
100
|
-
input: fs_1.default.createReadStream(this.timerfiledir),
|
|
101
|
-
crlfDelay: Infinity,
|
|
102
|
-
});
|
|
103
|
-
let newTimersData = "";
|
|
104
|
-
let found = false;
|
|
105
|
-
for await (const line of rl) {
|
|
106
|
-
if (!line.trim())
|
|
107
|
-
continue;
|
|
108
|
-
const timerData = JSON.parse(line);
|
|
109
|
-
if (timerData.id === id) {
|
|
110
|
-
found = true;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
newTimersData += `${JSON.stringify(timerData, null, 0)}\n`;
|
|
114
|
-
}
|
|
115
|
-
if (!found) {
|
|
116
|
-
throw new Error(`Timer with id ${id} not found`);
|
|
117
|
-
}
|
|
118
|
-
await fs_1.default.promises.writeFile(this.timerfiledir, newTimersData, "utf-8");
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
throw new Error(`Error when removing timer: ${e}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
|
|
127
|
-
* The callback is awaited before continuing.
|
|
128
|
-
* @param callback Function invoked when an expired timer is detected (called asynchronously)
|
|
129
|
-
* @param interval (number, optional): Check interval in milliseconds (default: 200ms)
|
|
130
|
-
* @throws If file operation fails
|
|
131
|
-
* @returns (NodeJS.Timeout) intervalId interval id of checkTimers
|
|
132
|
-
* @example
|
|
133
|
-
* const interval = manager.checkTimers((timer) => {
|
|
134
|
-
* console.log(`A timer was stopped: ${timer.id}`);
|
|
135
|
-
* });
|
|
136
|
-
*/
|
|
137
|
-
checkTimers(callback, interval = 200) {
|
|
138
|
-
return setInterval(async () => {
|
|
139
|
-
if (this.checkLock)
|
|
140
|
-
return;
|
|
141
|
-
this.checkLock = true;
|
|
142
|
-
try {
|
|
143
|
-
const rl = readline_1.default.createInterface({
|
|
144
|
-
input: fs_1.default.createReadStream(this.timerfiledir),
|
|
145
|
-
crlfDelay: Infinity,
|
|
146
|
-
});
|
|
147
|
-
for await (const line of rl) {
|
|
148
|
-
if (!line.trim())
|
|
149
|
-
continue;
|
|
150
|
-
const timerData = JSON.parse(line);
|
|
151
|
-
const now = Date.now();
|
|
152
|
-
if (Number(timerData.stop) <= now) {
|
|
153
|
-
await this.removeTimer(timerData.id);
|
|
154
|
-
callback(timerData).catch(async (e) => {
|
|
155
|
-
await Log_js_1.Log.ensureLogger();
|
|
156
|
-
if (Log_js_1.Log.loggerInstance) {
|
|
157
|
-
Log_js_1.Log.loggerInstance.error(`Error in callback of checkTimers: ${e}`);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
await Log_js_1.Log.ensureLogger();
|
|
165
|
-
if (Log_js_1.Log.loggerInstance) {
|
|
166
|
-
Log_js_1.Log.loggerInstance.error(`Error when checking alarm: ${e}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
finally {
|
|
170
|
-
this.checkLock = false;
|
|
171
|
-
}
|
|
172
|
-
}, interval);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* showTimers
|
|
176
|
-
* @description Retrieves all active timers.
|
|
177
|
-
* @returns Array of `Timer` objects
|
|
178
|
-
* @throws If file operation fails
|
|
179
|
-
* @example
|
|
180
|
-
* const timers = await manager.showTimers();
|
|
181
|
-
* console.log(JSON.stringify(timers))
|
|
182
|
-
*/
|
|
183
|
-
async showTimers() {
|
|
184
|
-
try {
|
|
185
|
-
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
186
|
-
const timersData = timersRaw
|
|
187
|
-
.split(/\r?\n/)
|
|
188
|
-
.filter(t => t.trim())
|
|
189
|
-
.map(line => JSON.parse(line));
|
|
190
|
-
return timersData;
|
|
191
|
-
}
|
|
192
|
-
catch (e) {
|
|
193
|
-
throw new Error(`Error when showing timers: ${e}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.JSONLTimersManager = JSONLTimersManager;
|
|
198
|
-
//# sourceMappingURL=JSONLTimersManager.js.map
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { Timer } from "./types.cjs";
|
|
2
|
-
import { TimersManager } from "./TimersManager.cjs";
|
|
3
|
-
/**
|
|
4
|
-
* JSONLTimersManager
|
|
5
|
-
* @description
|
|
6
|
-
* Manages timers stored in a JSONL file.
|
|
7
|
-
* (This is a abstract class)
|
|
8
|
-
*
|
|
9
|
-
* - Timers are persisted in a file
|
|
10
|
-
* - Expired timers are detected by polling
|
|
11
|
-
*/
|
|
12
|
-
export declare class JSONLTimersManager extends TimersManager {
|
|
13
|
-
protected getDefaultFilename(): string;
|
|
14
|
-
protected checkTimerfileSyntax(fileData: string): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* createTimer
|
|
17
|
-
* @description Creates a new timer.
|
|
18
|
-
* @param length Timer duration in milliseconds
|
|
19
|
-
* @param title(string, optional) Title of the timer(only for JSONLTimersManager)
|
|
20
|
-
* @param description(string, optional) Description of the timer(only for JSONLTimersManager)
|
|
21
|
-
* @returns Promise that resolves to the timer ID (UUID)
|
|
22
|
-
* @throws If length is invalid(e.g. length < 0) or file operation fails
|
|
23
|
-
* @example
|
|
24
|
-
* const manager = new JSONLTimersManager();
|
|
25
|
-
* const newTimer = await manager.createTimer(5000);
|
|
26
|
-
* // newTimer will be id of the timer
|
|
27
|
-
*/
|
|
28
|
-
createTimer(length: number, title?: string, description?: string): Promise<string>;
|
|
29
|
-
/**
|
|
30
|
-
* removeTimer
|
|
31
|
-
* @description Removes a timer by ID.
|
|
32
|
-
* @param id ID of the timer to remove
|
|
33
|
-
* @returns void
|
|
34
|
-
* @throws If file operation fails
|
|
35
|
-
* @example
|
|
36
|
-
* await manager.removeTimer(id);
|
|
37
|
-
*/
|
|
38
|
-
removeTimer(id: string): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
|
|
41
|
-
* The callback is awaited before continuing.
|
|
42
|
-
* @param callback Function invoked when an expired timer is detected (called asynchronously)
|
|
43
|
-
* @param interval (number, optional): Check interval in milliseconds (default: 200ms)
|
|
44
|
-
* @throws If file operation fails
|
|
45
|
-
* @returns (NodeJS.Timeout) intervalId interval id of checkTimers
|
|
46
|
-
* @example
|
|
47
|
-
* const interval = manager.checkTimers((timer) => {
|
|
48
|
-
* console.log(`A timer was stopped: ${timer.id}`);
|
|
49
|
-
* });
|
|
50
|
-
*/
|
|
51
|
-
checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout;
|
|
52
|
-
/**
|
|
53
|
-
* showTimers
|
|
54
|
-
* @description Retrieves all active timers.
|
|
55
|
-
* @returns Array of `Timer` objects
|
|
56
|
-
* @throws If file operation fails
|
|
57
|
-
* @example
|
|
58
|
-
* const timers = await manager.showTimers();
|
|
59
|
-
* console.log(JSON.stringify(timers))
|
|
60
|
-
*/
|
|
61
|
-
showTimers(): Promise<Timer[]>;
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=JSONLTimersManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONLTimersManager.d.ts","sourceRoot":"","sources":["../../src/JSONLTimersManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;IACpD,SAAS,CAAC,kBAAkB,IAAI,MAAM;cAItB,oBAAoB,CAAC,QAAQ,EA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K,CAAC,IAAI,CAAU,CAAC,CAAC;YAEzC,OAAO,UAAU,CAAC;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC;QACpD,CAAC;IACF,CAAC;CACD;AAjLD,gDAiLC"}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PlainTextTimersManager = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const uuid_1 = require("uuid");
|
|
9
|
-
const readline_1 = __importDefault(require("readline"));
|
|
10
|
-
const TimersManager_js_1 = require("./TimersManager.cjs");
|
|
11
|
-
const Log_js_1 = require("./Log.cjs");
|
|
12
|
-
class PlainTextTimersManager extends TimersManager_js_1.TimersManager {
|
|
13
|
-
getDefaultFilename() {
|
|
14
|
-
return ".timers";
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* checkTimerfileSyntax
|
|
18
|
-
* @description Checks the syntax of the timer file.
|
|
19
|
-
* @param fileData
|
|
20
|
-
* @returns void
|
|
21
|
-
* @throws If syntax is invalid
|
|
22
|
-
*/
|
|
23
|
-
async checkTimerfileSyntax(fileData) {
|
|
24
|
-
const throwing = () => {
|
|
25
|
-
throw new Error(`Timer file's syntax is wrong`);
|
|
26
|
-
};
|
|
27
|
-
const timersData = fileData
|
|
28
|
-
.split('\n')
|
|
29
|
-
.map(l => l.trim())
|
|
30
|
-
.filter(l => l !== "");
|
|
31
|
-
for (const timerData of timersData) {
|
|
32
|
-
const timerArray = timerData.split(/\s+/);
|
|
33
|
-
if (timerArray.length !== 3)
|
|
34
|
-
throwing();
|
|
35
|
-
if (timerArray[0]?.length !== 36)
|
|
36
|
-
throwing();
|
|
37
|
-
if (timerArray[1].trim() === "")
|
|
38
|
-
throwing();
|
|
39
|
-
if (timerArray[2].trim() === "")
|
|
40
|
-
throwing();
|
|
41
|
-
}
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* createTimer
|
|
46
|
-
* @description Creates a new timer.
|
|
47
|
-
* @param length
|
|
48
|
-
* @returns Promise that resolves to the timer ID (UUID)
|
|
49
|
-
* @throws If length is invalid(e.g. length < 0) or file operation fails
|
|
50
|
-
* @example
|
|
51
|
-
* const manager = new PlainTextTimersManager();
|
|
52
|
-
* const newTimer = await manager.createTimer(5000);
|
|
53
|
-
* // newTimer will be id of the timer
|
|
54
|
-
*/
|
|
55
|
-
async createTimer(length) {
|
|
56
|
-
try {
|
|
57
|
-
if (length < 0) {
|
|
58
|
-
throw new Error(`Invailed length: ${length}`);
|
|
59
|
-
}
|
|
60
|
-
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
61
|
-
await this.checkTimerfileSyntax(timersRaw);
|
|
62
|
-
length = Math.trunc(length);
|
|
63
|
-
// uuid, start, end
|
|
64
|
-
const id = (0, uuid_1.v4)();
|
|
65
|
-
const now = Date.now();
|
|
66
|
-
const newTimerData = `${id} ${now.toString()} ${(now + length).toString()}`;
|
|
67
|
-
await fs_1.default.promises.appendFile(this.timerfiledir, newTimerData + "\n");
|
|
68
|
-
return id;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
throw new Error(`Error when creating timer: ${e}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* removeTimer
|
|
76
|
-
* @description Removes a timer by ID.
|
|
77
|
-
* @param id ID of the timer to remove
|
|
78
|
-
* @returns void
|
|
79
|
-
* @throws If file operation fails
|
|
80
|
-
* @example
|
|
81
|
-
* await manager.removeTimer(id);
|
|
82
|
-
*/
|
|
83
|
-
async removeTimer(id) {
|
|
84
|
-
try {
|
|
85
|
-
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
86
|
-
await this.checkTimerfileSyntax(timersRaw);
|
|
87
|
-
const rl = readline_1.default.createInterface({
|
|
88
|
-
input: fs_1.default.createReadStream(this.timerfiledir),
|
|
89
|
-
crlfDelay: Infinity,
|
|
90
|
-
});
|
|
91
|
-
const newTimersDataLines = [];
|
|
92
|
-
let found = false;
|
|
93
|
-
for await (const line of rl) {
|
|
94
|
-
if (!line.trim())
|
|
95
|
-
continue;
|
|
96
|
-
const [timerId] = line.split(" ");
|
|
97
|
-
if (timerId === id) {
|
|
98
|
-
found = true;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
newTimersDataLines.push(line);
|
|
102
|
-
}
|
|
103
|
-
if (!found) {
|
|
104
|
-
throw new Error(`Timer with id ${id} not found`);
|
|
105
|
-
}
|
|
106
|
-
await fs_1.default.promises.writeFile(this.timerfiledir, newTimersDataLines.join("\n"), "utf-8");
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
throw new Error(`Error when removing timer: ${e}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* checkTimers
|
|
115
|
-
* @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
|
|
116
|
-
* The callback is awaited before continuing.
|
|
117
|
-
* @param callback Function invoked when an expired timer is detected (called asynchronously)
|
|
118
|
-
* @param interval (number, optional): Check interval in milliseconds (default: 200ms)
|
|
119
|
-
* @throws If file operation fails
|
|
120
|
-
* @returns (NodeJS.Timeout) intervalId interval id of checkTimers
|
|
121
|
-
* @example
|
|
122
|
-
* const interval = manager.checkTimers((timer) => {
|
|
123
|
-
* console.log(`A timer was stopped: ${timer.id}`);
|
|
124
|
-
* });
|
|
125
|
-
*/
|
|
126
|
-
checkTimers(callback, interval = 200) {
|
|
127
|
-
return setInterval(async () => {
|
|
128
|
-
if (this.checkLock)
|
|
129
|
-
return;
|
|
130
|
-
this.checkLock = true;
|
|
131
|
-
try {
|
|
132
|
-
const rl = readline_1.default.createInterface({
|
|
133
|
-
input: fs_1.default.createReadStream(this.timerfiledir),
|
|
134
|
-
crlfDelay: Infinity,
|
|
135
|
-
});
|
|
136
|
-
for await (const line of rl) {
|
|
137
|
-
if (!line.trim())
|
|
138
|
-
continue;
|
|
139
|
-
const [id, startStr, stopStr] = line.split(" ");
|
|
140
|
-
const timer = {
|
|
141
|
-
id: id,
|
|
142
|
-
start: Number(startStr),
|
|
143
|
-
stop: Number(stopStr),
|
|
144
|
-
};
|
|
145
|
-
const now = Date.now();
|
|
146
|
-
if (Number(timer.stop) <= now) {
|
|
147
|
-
await this.removeTimer(timer.id);
|
|
148
|
-
callback(timer).catch(async (e) => {
|
|
149
|
-
await Log_js_1.Log.ensureLogger();
|
|
150
|
-
if (Log_js_1.Log.loggerInstance) {
|
|
151
|
-
Log_js_1.Log.loggerInstance.error(`Error in timer callback: ${e}`);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
158
|
-
await Log_js_1.Log.ensureLogger();
|
|
159
|
-
if (Log_js_1.Log.loggerInstance) {
|
|
160
|
-
Log_js_1.Log.loggerInstance.error(`Error when checking alarm: ${e}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
this.checkLock = false;
|
|
165
|
-
}
|
|
166
|
-
}, interval);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* showTimers
|
|
170
|
-
* @description Retrieves all active timers.
|
|
171
|
-
* @returns Array of `Timer` objects
|
|
172
|
-
* @throws If file operation fails
|
|
173
|
-
* @example
|
|
174
|
-
* const timers = await manager.showTimers();
|
|
175
|
-
* console.log(JSON.stringify(timers))
|
|
176
|
-
*/
|
|
177
|
-
async showTimers() {
|
|
178
|
-
try {
|
|
179
|
-
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
180
|
-
const timersData = timersRaw.split(/\r?\n/);
|
|
181
|
-
const timersJSON = [];
|
|
182
|
-
for (const timerData of timersData) {
|
|
183
|
-
const splitedTimerData = timerData.split(" ");
|
|
184
|
-
if (!timerData.trim())
|
|
185
|
-
continue;
|
|
186
|
-
timersJSON.push({
|
|
187
|
-
id: splitedTimerData[0],
|
|
188
|
-
start: Number(splitedTimerData[1]),
|
|
189
|
-
stop: Number(splitedTimerData[2]),
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
return timersJSON;
|
|
193
|
-
}
|
|
194
|
-
catch (e) {
|
|
195
|
-
throw new Error(`Error when showing timers: ${e}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
exports.PlainTextTimersManager = PlainTextTimersManager;
|
|
200
|
-
//# sourceMappingURL=PlainTextTimersManager.js.map
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Timer } from "./types.cjs";
|
|
2
|
-
import { TimersManager } from "./TimersManager.cjs";
|
|
3
|
-
export declare class PlainTextTimersManager extends TimersManager {
|
|
4
|
-
protected getDefaultFilename(): string;
|
|
5
|
-
/**
|
|
6
|
-
* checkTimerfileSyntax
|
|
7
|
-
* @description Checks the syntax of the timer file.
|
|
8
|
-
* @param fileData
|
|
9
|
-
* @returns void
|
|
10
|
-
* @throws If syntax is invalid
|
|
11
|
-
*/
|
|
12
|
-
protected checkTimerfileSyntax(fileData: string): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* createTimer
|
|
15
|
-
* @description Creates a new timer.
|
|
16
|
-
* @param length
|
|
17
|
-
* @returns Promise that resolves to the timer ID (UUID)
|
|
18
|
-
* @throws If length is invalid(e.g. length < 0) or file operation fails
|
|
19
|
-
* @example
|
|
20
|
-
* const manager = new PlainTextTimersManager();
|
|
21
|
-
* const newTimer = await manager.createTimer(5000);
|
|
22
|
-
* // newTimer will be id of the timer
|
|
23
|
-
*/
|
|
24
|
-
createTimer(length: number): Promise<string>;
|
|
25
|
-
/**
|
|
26
|
-
* removeTimer
|
|
27
|
-
* @description Removes a timer by ID.
|
|
28
|
-
* @param id ID of the timer to remove
|
|
29
|
-
* @returns void
|
|
30
|
-
* @throws If file operation fails
|
|
31
|
-
* @example
|
|
32
|
-
* await manager.removeTimer(id);
|
|
33
|
-
*/
|
|
34
|
-
removeTimer(id: string): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* checkTimers
|
|
37
|
-
* @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
|
|
38
|
-
* The callback is awaited before continuing.
|
|
39
|
-
* @param callback Function invoked when an expired timer is detected (called asynchronously)
|
|
40
|
-
* @param interval (number, optional): Check interval in milliseconds (default: 200ms)
|
|
41
|
-
* @throws If file operation fails
|
|
42
|
-
* @returns (NodeJS.Timeout) intervalId interval id of checkTimers
|
|
43
|
-
* @example
|
|
44
|
-
* const interval = manager.checkTimers((timer) => {
|
|
45
|
-
* console.log(`A timer was stopped: ${timer.id}`);
|
|
46
|
-
* });
|
|
47
|
-
*/
|
|
48
|
-
checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout;
|
|
49
|
-
/**
|
|
50
|
-
* showTimers
|
|
51
|
-
* @description Retrieves all active timers.
|
|
52
|
-
* @returns Array of `Timer` objects
|
|
53
|
-
* @throws If file operation fails
|
|
54
|
-
* @example
|
|
55
|
-
* const timers = await manager.showTimers();
|
|
56
|
-
* console.log(JSON.stringify(timers))
|
|
57
|
-
*/
|
|
58
|
-
showTimers(): Promise<Timer[]>;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=PlainTextTimersManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlainTextTimersManager.d.ts","sourceRoot":"","sources":["../../src/PlainTextTimersManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE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,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAE,CAAC;iBAClC,CAAC,CAAC;YACJ,CAAC;YACD,OAAO,UAAU,CAAC;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC;QACpD,CAAC;IACF,CAAC;CACD;AAzLD,wDAyLC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TimersManager = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const searchRoot_js_1 = __importDefault(require("./searchRoot.cjs"));
|
|
10
|
-
/**
|
|
11
|
-
* TimersManager
|
|
12
|
-
* @description
|
|
13
|
-
* Manages timers stored in a file.
|
|
14
|
-
* (This is a abstract class)
|
|
15
|
-
*
|
|
16
|
-
* - Timers are persisted in a file
|
|
17
|
-
* - Expired timers are detected by polling
|
|
18
|
-
*/
|
|
19
|
-
class TimersManager {
|
|
20
|
-
timerfiledir;
|
|
21
|
-
checkLock = false;
|
|
22
|
-
/**
|
|
23
|
-
* constructor
|
|
24
|
-
* @param timerfiledir(string, optional)
|
|
25
|
-
* If omitted, `.timers.jsonl` under the project root is used.
|
|
26
|
-
*/
|
|
27
|
-
constructor(timerfiledir) {
|
|
28
|
-
this.timerfiledir =
|
|
29
|
-
timerfiledir ?? path_1.default.join((0, searchRoot_js_1.default)(), this.getDefaultFilename());
|
|
30
|
-
try {
|
|
31
|
-
fs_1.default.accessSync(this.timerfiledir);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
fs_1.default.writeFileSync(this.timerfiledir, "");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.TimersManager = TimersManager;
|
|
39
|
-
//# sourceMappingURL=TimersManager.js.map
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { Timer } from "./types.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* TimersManager
|
|
4
|
-
* @description
|
|
5
|
-
* Manages timers stored in a file.
|
|
6
|
-
* (This is a abstract class)
|
|
7
|
-
*
|
|
8
|
-
* - Timers are persisted in a file
|
|
9
|
-
* - Expired timers are detected by polling
|
|
10
|
-
*/
|
|
11
|
-
export declare abstract class TimersManager {
|
|
12
|
-
protected readonly timerfiledir: string;
|
|
13
|
-
protected checkLock: boolean;
|
|
14
|
-
protected abstract getDefaultFilename(): string;
|
|
15
|
-
/**
|
|
16
|
-
* constructor
|
|
17
|
-
* @param timerfiledir(string, optional)
|
|
18
|
-
* If omitted, `.timers.jsonl` under the project root is used.
|
|
19
|
-
*/
|
|
20
|
-
constructor(timerfiledir?: string);
|
|
21
|
-
/**
|
|
22
|
-
* checkTimerfileSyntax
|
|
23
|
-
* @description Checks the syntax of the timer file.
|
|
24
|
-
* @param fileData
|
|
25
|
-
* @returns void
|
|
26
|
-
* @throws If syntax is invalid
|
|
27
|
-
*/
|
|
28
|
-
protected abstract checkTimerfileSyntax(fileData: string): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* createTimer
|
|
31
|
-
* @description Creates a new timer.
|
|
32
|
-
* @param length Timer duration in milliseconds
|
|
33
|
-
* @returns Promise that resolves to the timer ID (UUID)
|
|
34
|
-
* @throws If length is invalid(e.g. length < 0) or file operation fails
|
|
35
|
-
* @example
|
|
36
|
-
* const manager = new TimersManager();
|
|
37
|
-
* const newTimer = await manager.createTimer(5000);
|
|
38
|
-
* // newTimer will be id of the timer
|
|
39
|
-
*/
|
|
40
|
-
abstract createTimer(length: number, title?: string, description?: string): Promise<string>;
|
|
41
|
-
/**
|
|
42
|
-
* removeTimer
|
|
43
|
-
* @description Removes a timer by ID.
|
|
44
|
-
* @param id ID of the timer to remove
|
|
45
|
-
* @returns void
|
|
46
|
-
* @throws If file operation fails
|
|
47
|
-
* @example
|
|
48
|
-
* await manager.removeTimer(id);
|
|
49
|
-
*/
|
|
50
|
-
abstract removeTimer(id: string): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
|
|
53
|
-
* The callback is awaited before continuing.
|
|
54
|
-
* @param callback Function invoked when an expired timer is detected (called asynchronously)
|
|
55
|
-
* @param interval (number, optional): Check interval in milliseconds (default: 200ms)
|
|
56
|
-
* @throws If file operation fails
|
|
57
|
-
* @returns (NodeJS.Timeout) intervalId interval id of checkTimers
|
|
58
|
-
* @example
|
|
59
|
-
* const interval = manager.checkTimers((timer) => {
|
|
60
|
-
* console.log(`A timer was stopped: ${timer.id}`);
|
|
61
|
-
* });
|
|
62
|
-
*/
|
|
63
|
-
abstract checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout;
|
|
64
|
-
/**
|
|
65
|
-
* showTimers
|
|
66
|
-
* @description Retrieves all active timers.
|
|
67
|
-
* @returns Array of `Timer` objects
|
|
68
|
-
* @throws If file operation fails
|
|
69
|
-
* @example
|
|
70
|
-
* const timers = await manager.showTimers();
|
|
71
|
-
* console.log(JSON.stringify(timers))
|
|
72
|
-
*/
|
|
73
|
-
abstract showTimers(): Promise<Timer[]>;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=TimersManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TimersManager.d.ts","sourceRoot":"","sources":["../../src/TimersManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;GAQG;AACH,8BAAsB,aAAa;IAClC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IACxC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAS;IAErC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,IAAI,MAAM;IAE/C;;;;OAIM;gBAEL,YAAY,CAAC,EAAE,MAAM;IAYtB;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAExE;;;;;;;;;;OAUM;aACU,WAAW,CAAC,MAAM,EAAC,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAEjG;;;;;;;;OAQM;aACU,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEtD;;;;;;;;;;;OAWM;aACU,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO;IAEzG;;;;;;;;OAQM;aACU,UAAU,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;CAC9C"}
|