eternal-timer 2.0.4 → 2.2.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 +78 -19
- package/dist/cjs/JSONLTimersManager.cjs +193 -0
- package/dist/cjs/JSONLTimersManager.d.ts +63 -0
- package/dist/cjs/JSONLTimersManager.d.ts.map +1 -0
- package/dist/cjs/JSONLTimersManager.js.map +1 -0
- package/dist/cjs/Log.cjs +82 -0
- package/dist/cjs/Log.d.ts +8 -0
- package/dist/cjs/Log.d.ts.map +1 -0
- package/dist/cjs/Log.js.map +1 -0
- package/dist/cjs/PlainTextTimersManager.cjs +192 -0
- package/dist/cjs/PlainTextTimersManager.d.ts +60 -0
- package/dist/cjs/PlainTextTimersManager.d.ts.map +1 -0
- package/dist/cjs/PlainTextTimersManager.js.map +1 -0
- package/dist/cjs/TimersManager.cjs +39 -0
- package/dist/cjs/TimersManager.d.ts +75 -0
- package/dist/cjs/TimersManager.d.ts.map +1 -0
- package/dist/cjs/TimersManager.js.map +1 -0
- package/dist/cjs/index.cjs +5 -192
- package/dist/cjs/index.d.ts +3 -68
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.cjs +3 -0
- package/dist/cjs/types.d.ts +8 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/JSONLTimersManager.d.ts +63 -0
- package/dist/esm/JSONLTimersManager.d.ts.map +1 -0
- package/dist/esm/JSONLTimersManager.js +186 -0
- package/dist/esm/JSONLTimersManager.js.map +1 -0
- package/dist/esm/Log.d.ts +8 -0
- package/dist/esm/Log.d.ts.map +1 -0
- package/dist/esm/Log.js +45 -0
- package/dist/esm/Log.js.map +1 -0
- package/dist/esm/PlainTextTimersManager.d.ts +60 -0
- package/dist/esm/PlainTextTimersManager.d.ts.map +1 -0
- package/dist/esm/PlainTextTimersManager.js +185 -0
- package/dist/esm/PlainTextTimersManager.js.map +1 -0
- package/dist/esm/TimersManager.d.ts +75 -0
- package/dist/esm/TimersManager.d.ts.map +1 -0
- package/dist/esm/TimersManager.js +32 -0
- package/dist/esm/TimersManager.js.map +1 -0
- package/dist/esm/index.d.ts +3 -68
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -187
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +8 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +12 -4
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# eternal-timer
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|

|
|
5
5
|
|
|
6
6
|
A simple and persistent timer library for Node.js. Timers are saved to a file and maintain their state even after process restart.
|
|
@@ -9,6 +9,7 @@ A simple and persistent timer library for Node.js. Timers are saved to a file an
|
|
|
9
9
|
|
|
10
10
|
- **Monitor Timers (asynchronous)**: Start monitoring expired timers asynchronously; the function returns immediately and the callback is called when timers expire.
|
|
11
11
|
- **Persistence**: Save timer data to a file that persists across process restarts
|
|
12
|
+
- **Choice of Format**: Choose between JSON Lines for rich data or plain text for lightweight storage.
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
@@ -18,21 +19,26 @@ npm install eternal-timer
|
|
|
18
19
|
|
|
19
20
|
## Usage
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
You can choose between two manager classes depending on the desired storage format.
|
|
23
|
+
|
|
24
|
+
### `JSONLTimersManager` (JSON Lines)
|
|
25
|
+
|
|
26
|
+
Use this manager to store timers in a `.jsonl` file, which allows for storing `title` and `description`.
|
|
22
27
|
|
|
23
28
|
```javascript
|
|
24
|
-
import {
|
|
29
|
+
import { JSONLTimersManager } from 'eternal-timer';
|
|
25
30
|
|
|
26
31
|
async function main() {
|
|
27
|
-
|
|
32
|
+
// By default, timers are stored in '.timers.jsonl' in the project root.
|
|
33
|
+
const manager = new JSONLTimersManager();
|
|
28
34
|
|
|
29
|
-
// Create a timer (5 seconds)
|
|
30
|
-
const timerId = await manager.createTimer(5000);
|
|
35
|
+
// Create a timer (5 seconds) with a title and description
|
|
36
|
+
const timerId = await manager.createTimer(5000, 'My Timer', 'This is a test timer.');
|
|
31
37
|
console.log('Timer created:', timerId);
|
|
32
38
|
|
|
33
39
|
// Monitor timers (executes when timer expires)
|
|
34
|
-
const
|
|
35
|
-
console.log('Timer expired:', timer.id);
|
|
40
|
+
const interval = manager.checkTimers(async (timer) => {
|
|
41
|
+
console.log('Timer expired:', timer.id, timer.title);
|
|
36
42
|
});
|
|
37
43
|
|
|
38
44
|
// Display all timers
|
|
@@ -46,21 +52,56 @@ async function main() {
|
|
|
46
52
|
main();
|
|
47
53
|
```
|
|
48
54
|
|
|
55
|
+
### `PlainTextTimersManager` (Plain Text)
|
|
56
|
+
|
|
57
|
+
Use this manager for a more lightweight plain-text format.
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import { PlainTextTimersManager } from 'eternal-timer';
|
|
61
|
+
|
|
62
|
+
async function main() {
|
|
63
|
+
// By default, timers are stored in '.timers' in the project root.
|
|
64
|
+
const manager = new PlainTextTimersManager();
|
|
65
|
+
|
|
66
|
+
// Create a timer (5 seconds)
|
|
67
|
+
const timerId = await manager.createTimer(5000);
|
|
68
|
+
console.log('Timer created:', timerId);
|
|
69
|
+
|
|
70
|
+
// Monitor timers
|
|
71
|
+
const interval = manager.checkTimers(async (timer) => {
|
|
72
|
+
console.log('Timer expired:', timer.id);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main();
|
|
77
|
+
```
|
|
78
|
+
|
|
49
79
|
## API
|
|
50
80
|
|
|
51
|
-
### `new
|
|
81
|
+
### `new JSONLTimersManager(timerfiledir?: string)`
|
|
82
|
+
|
|
83
|
+
Creates a manager for timers stored in the **JSON Lines** format.
|
|
84
|
+
|
|
85
|
+
**Parameters:**
|
|
86
|
+
- `timerfiledir` (string, optional): The path to the timer file. If omitted, the default is `.timers.jsonl` in the project root.
|
|
87
|
+
|
|
88
|
+
### `new PlainTextTimersManager(timerfiledir?: string)`
|
|
52
89
|
|
|
53
|
-
Creates a
|
|
90
|
+
Creates a manager for timers stored in the **plain-text** format.
|
|
54
91
|
|
|
55
92
|
**Parameters:**
|
|
56
|
-
- `timerfiledir` (string, optional): The path to the
|
|
93
|
+
- `timerfiledir` (string, optional): The path to the timer file. If omitted, the default is `.timers` in the project root.
|
|
57
94
|
|
|
58
|
-
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### `createTimer(length: number, title?: string, description?: string): Promise<string>`
|
|
59
98
|
|
|
60
99
|
Creates a new timer.
|
|
61
100
|
|
|
62
101
|
**Parameters:**
|
|
63
102
|
- `length` (number): Timer duration in milliseconds
|
|
103
|
+
- `title` (string, optional): A title for the timer. **Only available for `JSONLTimersManager`**.
|
|
104
|
+
- `description` (string, optional): A description for the timer. **Only available for `JSONLTimersManager`**.
|
|
64
105
|
|
|
65
106
|
**Returns:** Promise that resolves to the timer ID (UUID)
|
|
66
107
|
|
|
@@ -107,6 +148,8 @@ type Timer = {
|
|
|
107
148
|
id: string; // Unique timer identifier (UUID)
|
|
108
149
|
start: number; // Timer start timestamp
|
|
109
150
|
stop: number; // Timer end timestamp
|
|
151
|
+
title?: string;
|
|
152
|
+
description?: string;
|
|
110
153
|
}
|
|
111
154
|
```
|
|
112
155
|
|
|
@@ -118,13 +161,31 @@ type Timer = {
|
|
|
118
161
|
- `npm run test`: Test the compiled code
|
|
119
162
|
- `npm run lint`: Lint all codes
|
|
120
163
|
|
|
121
|
-
## Storage
|
|
164
|
+
## Storage Formats
|
|
122
165
|
|
|
123
|
-
|
|
166
|
+
You can choose between two storage formats by selecting the appropriate manager class.
|
|
124
167
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
168
|
+
### 1. JSON Lines (via `JSONLTimersManager`)
|
|
169
|
+
This is the recommended format for storing rich metadata.
|
|
170
|
+
|
|
171
|
+
- **Pros**: Allows for storing `title` and `description`.
|
|
172
|
+
- **Cons**: Involves JSON parsing, which may have a minor performance overhead.
|
|
173
|
+
- **Default File**: `.timers.jsonl`
|
|
174
|
+
- **Format**:
|
|
175
|
+
```json
|
|
176
|
+
{"id":"...","start":1678886400000,"stop":1678886405000,"title":"My Timer","description":"..."}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 2. Plain Text (via `PlainTextTimersManager`)
|
|
180
|
+
This format is more lightweight and slightly faster.
|
|
181
|
+
|
|
182
|
+
- **Pros**: Simple and efficient.
|
|
183
|
+
- **Cons**: Cannot store additional data like `title` or `description`.
|
|
184
|
+
- **Default File**: `.timers`
|
|
185
|
+
- **Format**:
|
|
186
|
+
```
|
|
187
|
+
{id} {start_timestamp} {stop_timestamp}
|
|
188
|
+
```
|
|
128
189
|
|
|
129
190
|
## License
|
|
130
191
|
|
|
@@ -135,5 +196,3 @@ Licensed under the Apache License, Version 2.0. See the `LICENSE` file for detai
|
|
|
135
196
|
## Repository
|
|
136
197
|
|
|
137
198
|
https://github.com/SUKEsann2000/eternal-timer
|
|
138
|
-
|
|
139
|
-
|
|
@@ -0,0 +1,193 @@
|
|
|
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 TimersManager_js_1 = require("./TimersManager.cjs");
|
|
10
|
+
const Log_js_1 = require("./Log.cjs");
|
|
11
|
+
/**
|
|
12
|
+
* JSONLTimersManager
|
|
13
|
+
* @description
|
|
14
|
+
* Manages timers stored in a JSONL file.
|
|
15
|
+
* (This is a abstract class)
|
|
16
|
+
*
|
|
17
|
+
* - Timers are persisted in a file
|
|
18
|
+
* - Expired timers are detected by polling
|
|
19
|
+
*/
|
|
20
|
+
class JSONLTimersManager extends TimersManager_js_1.TimersManager {
|
|
21
|
+
getDefaultFilename() {
|
|
22
|
+
return ".timers.jsonl";
|
|
23
|
+
}
|
|
24
|
+
async checkTimerfileSyntax(fileData) {
|
|
25
|
+
const throwing = () => {
|
|
26
|
+
throw new Error(`Timer file's syntax is wrong`);
|
|
27
|
+
};
|
|
28
|
+
const timersData = fileData
|
|
29
|
+
.split('\n')
|
|
30
|
+
.map(l => l.trim())
|
|
31
|
+
.filter(l => l !== "");
|
|
32
|
+
for (const timerData of timersData) {
|
|
33
|
+
const parsed = JSON.parse(timerData);
|
|
34
|
+
if (!parsed.id || typeof parsed.id !== "string" || parsed.id.length !== 36)
|
|
35
|
+
throwing();
|
|
36
|
+
if (!parsed.start || typeof parsed.start !== "number" || parsed.start.toString().trim() === "")
|
|
37
|
+
throwing();
|
|
38
|
+
if (!parsed.stop || typeof parsed.stop !== "number" || parsed.stop.toString().trim() === "")
|
|
39
|
+
throwing();
|
|
40
|
+
if (parsed.title && typeof parsed.title !== "string")
|
|
41
|
+
throwing();
|
|
42
|
+
if (parsed.description && typeof parsed.description !== "string")
|
|
43
|
+
throwing();
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* createTimer
|
|
49
|
+
* @description Creates a new timer.
|
|
50
|
+
* @param length Timer duration in milliseconds
|
|
51
|
+
* @param title(string, optional) Title of the timer(only for JSONLTimersManager)
|
|
52
|
+
* @param description(string, optional) Description of the timer(only for JSONLTimersManager)
|
|
53
|
+
* @returns Promise that resolves to the timer ID (UUID)
|
|
54
|
+
* @throws If length is invalid(e.g. length < 0) or file operation fails
|
|
55
|
+
* @example
|
|
56
|
+
* const manager = new JSONLTimersManager();
|
|
57
|
+
* const newTimer = await manager.createTimer(5000);
|
|
58
|
+
* // newTimer will be id of the timer
|
|
59
|
+
*/
|
|
60
|
+
async createTimer(length, title, description) {
|
|
61
|
+
try {
|
|
62
|
+
if (length < 0) {
|
|
63
|
+
throw new Error(`Invailed length: ${length}`);
|
|
64
|
+
}
|
|
65
|
+
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
66
|
+
await this.checkTimerfileSyntax(timersRaw);
|
|
67
|
+
length = Math.trunc(length);
|
|
68
|
+
// uuid, start, end
|
|
69
|
+
const id = (0, uuid_1.v4)();
|
|
70
|
+
const now = Date.now();
|
|
71
|
+
const newTimerData = JSON.stringify({
|
|
72
|
+
id,
|
|
73
|
+
start: now,
|
|
74
|
+
stop: (now + length),
|
|
75
|
+
...(title !== undefined && { title }),
|
|
76
|
+
...(description !== undefined && { description }),
|
|
77
|
+
});
|
|
78
|
+
await fs_1.default.promises.appendFile(this.timerfiledir, newTimerData + "\n");
|
|
79
|
+
return id;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
throw new Error(`Error when creating timer: ${e}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* removeTimer
|
|
87
|
+
* @description Removes a timer by ID.
|
|
88
|
+
* @param id ID of the timer to remove
|
|
89
|
+
* @returns void
|
|
90
|
+
* @throws If file operation fails
|
|
91
|
+
* @example
|
|
92
|
+
* await manager.removeTimer(id);
|
|
93
|
+
*/
|
|
94
|
+
async removeTimer(id) {
|
|
95
|
+
try {
|
|
96
|
+
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
97
|
+
await this.checkTimerfileSyntax(timersRaw);
|
|
98
|
+
let newTimersData = "";
|
|
99
|
+
const timersData = timersRaw
|
|
100
|
+
.split(/\r?\n/)
|
|
101
|
+
.filter(t => t.trim())
|
|
102
|
+
.map(line => JSON.parse(line));
|
|
103
|
+
let found = false;
|
|
104
|
+
for (const timerData of timersData) {
|
|
105
|
+
if (!timerData)
|
|
106
|
+
continue;
|
|
107
|
+
if (timerData.id === id) {
|
|
108
|
+
found = true;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
newTimersData += `${JSON.stringify(timerData, null, 0)}\n`;
|
|
112
|
+
}
|
|
113
|
+
if (!found) {
|
|
114
|
+
throw new Error(`Timer with id ${id} not found`);
|
|
115
|
+
}
|
|
116
|
+
await fs_1.default.promises.writeFile(this.timerfiledir, newTimersData, "utf-8");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
throw new Error(`Error when removing timer: ${e}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
|
|
125
|
+
* The callback is awaited before continuing.
|
|
126
|
+
* @param callback Function invoked when an expired timer is detected (called asynchronously)
|
|
127
|
+
* @param interval (number, optional): Check interval in milliseconds (default: 50ms)
|
|
128
|
+
* @throws If file operation fails
|
|
129
|
+
* @returns (NodeJS.Timeout) intervalId interval id of checkTimers
|
|
130
|
+
* @example
|
|
131
|
+
* const interval = manager.checkTimers((timer) => {
|
|
132
|
+
* console.log(`A timer was stopped: ${timer.id}`);
|
|
133
|
+
* });
|
|
134
|
+
*/
|
|
135
|
+
checkTimers(callback, interval = 50) {
|
|
136
|
+
return setInterval(async () => {
|
|
137
|
+
if (this.checkLock)
|
|
138
|
+
return;
|
|
139
|
+
this.checkLock = true;
|
|
140
|
+
try {
|
|
141
|
+
const timersDataRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
142
|
+
const timersMap = new Map();
|
|
143
|
+
const timersData = timersDataRaw
|
|
144
|
+
.split(/\r?\n/)
|
|
145
|
+
.filter(line => line.trim())
|
|
146
|
+
.map(line => JSON.parse(line));
|
|
147
|
+
for (const timer of timersData) {
|
|
148
|
+
timersMap.set(timer.id, timer);
|
|
149
|
+
}
|
|
150
|
+
const now = Date.now();
|
|
151
|
+
for (const timer of timersMap.values()) {
|
|
152
|
+
if (Number(timer.stop) <= now) {
|
|
153
|
+
await this.removeTimer(timer.id);
|
|
154
|
+
await callback(timer);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
await Log_js_1.Log.ensureLogger();
|
|
160
|
+
if (Log_js_1.Log.loggerInstance) {
|
|
161
|
+
Log_js_1.Log.loggerInstance.error(`Error when checking alarm: ${e}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
this.checkLock = false;
|
|
166
|
+
}
|
|
167
|
+
}, interval);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* showTimers
|
|
171
|
+
* @description Retrieves all active timers.
|
|
172
|
+
* @returns Array of `Timer` objects
|
|
173
|
+
* @throws If file operation fails
|
|
174
|
+
* @example
|
|
175
|
+
* const timers = await manager.showTimers();
|
|
176
|
+
* console.log(JSON.stringify(timers))
|
|
177
|
+
*/
|
|
178
|
+
async showTimers() {
|
|
179
|
+
try {
|
|
180
|
+
const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
|
|
181
|
+
const timersData = timersRaw
|
|
182
|
+
.split(/\r?\n/)
|
|
183
|
+
.filter(t => t.trim())
|
|
184
|
+
.map(line => JSON.parse(line));
|
|
185
|
+
return timersData;
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
throw new Error(`Error when showing timers: ${e}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.JSONLTimersManager = JSONLTimersManager;
|
|
193
|
+
//# sourceMappingURL=JSONLTimersManager.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
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: 50ms)
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONLTimersManager.d.ts","sourceRoot":"","sources":["../../src/JSONLTimersManager.ts"],"names":[],"mappings":"AAGA,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,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBrE;;;;;;;;;;;;OAYM;IACO,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4B/F;;;;;;;;OAQM;IACO,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BnD;;;;;;;;;;;OAWM;IACC,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAE,MAA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AM,QAAQ,CAAC,KAAK,CAAC,CAAC;oBACvB,CAAC;gBACF,CAAC;YACF,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACZ,MAAM,YAAG,CAAC,YAAY,EAAE,CAAC;gBACzB,IAAI,YAAG,CAAC,cAAc,EAAE,CAAC;oBACxB,YAAG,CAAC,cAAc,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC;gBAC7D,CAAC;YACF,CAAC;oBAAS,CAAC;gBACV,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACxB,CAAC;QACF,CAAC,EAAE,QAAQ,CAAC,CAAC;IACd,CAAC;IAED;;;;;;;;OAQM;IACC,KAAK,CAAC,UAAU;QACtB,IAAI,CAAC;YACJ,MAAM,SAAS,GAAW,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YACjF,MAAM,UAAU,GAAY,SAAS;iBACnC,KAAK,CAAC,OAAO,CAAC;iBACd,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBACrB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,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;AA/KD,gDA+KC"}
|
package/dist/cjs/Log.cjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Log = void 0;
|
|
37
|
+
class Log {
|
|
38
|
+
static logger = null;
|
|
39
|
+
static initPromise = null;
|
|
40
|
+
static async ensureLogger() {
|
|
41
|
+
if (Log.logger)
|
|
42
|
+
return;
|
|
43
|
+
if (!Log.initPromise) {
|
|
44
|
+
Log.initPromise = (async () => {
|
|
45
|
+
try {
|
|
46
|
+
const logtape = await Promise.resolve().then(() => __importStar(require("@logtape/logtape")));
|
|
47
|
+
Log.logger = logtape.getLogger(["eternal-timer"]);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
console.info("Tip: Install the optional package '@logtape/logtape' to customize logging behavior.");
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
}
|
|
54
|
+
await Log.initPromise;
|
|
55
|
+
}
|
|
56
|
+
static get loggerInstance() {
|
|
57
|
+
return Log.logger;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Log = Log;
|
|
61
|
+
/*
|
|
62
|
+
let logger: Logger | null = null;
|
|
63
|
+
let initPromise: Promise<void> | null = null;
|
|
64
|
+
|
|
65
|
+
export async function ensureLogger() {
|
|
66
|
+
if (logger) return;
|
|
67
|
+
if (!initPromise) {
|
|
68
|
+
initPromise = (async () => {
|
|
69
|
+
try {
|
|
70
|
+
const logtape = await import("@logtape/logtape");
|
|
71
|
+
logger = logtape.getLogger(["eternal-timer"]);
|
|
72
|
+
} catch {
|
|
73
|
+
console.info(
|
|
74
|
+
"Tip: Install the optional package '@logtape/logtape' to customize logging behavior.",
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
}
|
|
79
|
+
await initPromise;
|
|
80
|
+
}
|
|
81
|
+
*/
|
|
82
|
+
//# sourceMappingURL=Log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Log.d.ts","sourceRoot":"","sources":["../../src/Log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,GAAG;IACf,OAAO,CAAC,MAAM,CAAC,MAAM,CAAuB;IAC5C,OAAO,CAAC,MAAM,CAAC,WAAW,CAA8B;WAEpC,YAAY;IAiBhC,WAAkB,cAAc,IAAI,MAAM,GAAG,IAAI,CAEhD;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Log.js","sourceRoot":"","sources":["../../src/Log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAa,GAAG;IACP,MAAM,CAAC,MAAM,GAAkB,IAAI,CAAC;IACpC,MAAM,CAAC,WAAW,GAAyB,IAAI,CAAC;IAEjD,MAAM,CAAC,KAAK,CAAC,YAAY;QAC/B,IAAI,GAAG,CAAC,MAAM;YAAE,OAAO;QACvB,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YACtB,GAAG,CAAC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;gBAC7B,IAAI,CAAC;oBACJ,MAAM,OAAO,GAAG,wDAAa,kBAAkB,GAAC,CAAC;oBACjD,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;gBACnD,CAAC;gBAAC,MAAM,CAAC;oBACR,OAAO,CAAC,IAAI,CACX,qFAAqF,CACrF,CAAC;gBACH,CAAC;YACF,CAAC,CAAC,EAAE,CAAC;QACN,CAAC;QACD,MAAM,GAAG,CAAC,WAAW,CAAC;IACvB,CAAC;IAEM,MAAM,KAAK,cAAc;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC;IACnB,CAAC;;AAvBF,kBAwBC;AAED;;;;;;;;;;;;;;;;;;;;EAoBE"}
|