eternal-timer 2.2.0 → 2.3.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.
Files changed (40) hide show
  1. package/README.md +75 -44
  2. package/dist/cjs/JSONLTimersManager.cjs +31 -25
  3. package/dist/cjs/JSONLTimersManager.cjs.map +1 -0
  4. package/dist/cjs/JSONLTimersManager.d.ts +7 -7
  5. package/dist/cjs/JSONLTimersManager.d.ts.map +1 -1
  6. package/dist/cjs/Log.cjs +0 -21
  7. package/dist/cjs/{Log.js.map → Log.cjs.map} +1 -1
  8. package/dist/cjs/PlainTextTimersManager.cjs +33 -25
  9. package/dist/cjs/PlainTextTimersManager.cjs.map +1 -0
  10. package/dist/cjs/PlainTextTimersManager.d.ts +7 -7
  11. package/dist/cjs/PlainTextTimersManager.d.ts.map +1 -1
  12. package/dist/cjs/TimersManager.d.ts +6 -6
  13. package/dist/cjs/TimersManager.d.ts.map +1 -1
  14. package/dist/cjs/index.d.ts +3 -3
  15. package/dist/cjs/index.d.ts.map +1 -1
  16. package/dist/cjs/types.d.ts +9 -2
  17. package/dist/cjs/types.d.ts.map +1 -1
  18. package/dist/esm/JSONLTimersManager.d.ts +6 -6
  19. package/dist/esm/JSONLTimersManager.d.ts.map +1 -1
  20. package/dist/esm/JSONLTimersManager.js +31 -25
  21. package/dist/esm/JSONLTimersManager.js.map +1 -1
  22. package/dist/esm/Log.js +0 -21
  23. package/dist/esm/Log.js.map +1 -1
  24. package/dist/esm/PlainTextTimersManager.d.ts +6 -6
  25. package/dist/esm/PlainTextTimersManager.d.ts.map +1 -1
  26. package/dist/esm/PlainTextTimersManager.js +33 -25
  27. package/dist/esm/PlainTextTimersManager.js.map +1 -1
  28. package/dist/esm/TimersManager.d.ts +6 -6
  29. package/dist/esm/TimersManager.d.ts.map +1 -1
  30. package/dist/esm/index.d.ts +1 -1
  31. package/dist/esm/index.d.ts.map +1 -1
  32. package/dist/esm/types.d.ts +9 -2
  33. package/dist/esm/types.d.ts.map +1 -1
  34. package/package.json +7 -4
  35. package/dist/cjs/JSONLTimersManager.js.map +0 -1
  36. package/dist/cjs/PlainTextTimersManager.js.map +0 -1
  37. /package/dist/cjs/{TimersManager.js.map → TimersManager.cjs.map} +0 -0
  38. /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
  39. /package/dist/cjs/{searchRoot.js.map → searchRoot.cjs.map} +0 -0
  40. /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
package/README.md CHANGED
@@ -33,20 +33,25 @@ async function main() {
33
33
  const manager = new JSONLTimersManager();
34
34
 
35
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.');
36
+ const timerId = await manager.createTimer({length: 5000, title: 'My Timer', description: 'This is a test timer.'});
37
37
  console.log('Timer created:', timerId);
38
38
 
39
39
  // Monitor timers (executes when timer expires)
40
40
  const interval = manager.checkTimers(async (timer) => {
41
41
  console.log('Timer expired:', timer.id, timer.title);
42
+ // Once the timer expires, you can remove it
43
+ await manager.removeTimer(timer.id);
42
44
  });
43
45
 
44
46
  // Display all timers
45
47
  const timers = await manager.showTimers();
46
48
  console.log('Active timers:', timers);
47
49
 
48
- // Remove a timer
49
- await manager.removeTimer(timerId);
50
+ // To stop monitoring, for example after 10 seconds
51
+ setTimeout(() => {
52
+ clearInterval(interval);
53
+ console.log('Stopped monitoring timers.');
54
+ }, 10000);
50
55
  }
51
56
 
52
57
  main();
@@ -70,7 +75,18 @@ async function main() {
70
75
  // Monitor timers
71
76
  const interval = manager.checkTimers(async (timer) => {
72
77
  console.log('Timer expired:', timer.id);
78
+ await manager.removeTimer(timer.id);
73
79
  });
80
+
81
+ // Display all timers
82
+ const timers = await manager.showTimers();
83
+ console.log('Active timers:', timers);
84
+
85
+ // Stop monitoring after a while
86
+ setTimeout(() => {
87
+ clearInterval(interval);
88
+ console.log('Stopped monitoring timers.');
89
+ }, 10000);
74
90
  }
75
91
 
76
92
  main();
@@ -78,79 +94,94 @@ main();
78
94
 
79
95
  ## API
80
96
 
81
- ### `new JSONLTimersManager(timerfiledir?: string)`
97
+ ### `JSONLTimersManager`
82
98
 
83
- Creates a manager for timers stored in the **JSON Lines** format.
99
+ #### `constructor(timerfiledir?: string)`
100
+ Creates a manager for timers stored in **JSON Lines** format.
84
101
 
85
- **Parameters:**
86
- - `timerfiledir` (string, optional): The path to the timer file. If omitted, the default is `.timers.jsonl` in the project root.
102
+ - **`timerfiledir`** (optional, string): Path to the timer file. Defaults to `.timers.jsonl` in the project root.
87
103
 
88
- ### `new PlainTextTimersManager(timerfiledir?: string)`
104
+ ### `PlainTextTimersManager`
89
105
 
90
- Creates a manager for timers stored in the **plain-text** format.
106
+ #### `constructor(timerfiledir?: string)`
107
+ Creates a manager for timers stored in **plain-text** format.
91
108
 
92
- **Parameters:**
93
- - `timerfiledir` (string, optional): The path to the timer file. If omitted, the default is `.timers` in the project root.
109
+ - **`timerfiledir`** (optional, string): Path to the timer file. Defaults to `.timers` in the project root.
94
110
 
95
111
  ---
96
112
 
97
- ### `createTimer(length: number, title?: string, description?: string): Promise<string>`
113
+ ### `createTimer(options: CreateTimerOptions<T>): Promise<string>`
114
+
115
+ Creates a new timer and saves it to the file.
116
+
117
+ #### Parameters
118
+
119
+ - **`options`**
98
120
 
99
- Creates a new timer.
121
+ When using `"PlainText"` storage:
122
+ - `number` — Timer duration in milliseconds.
100
123
 
101
- **Parameters:**
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`**.
124
+ When using `"JSONL"` storage:
125
+ - `{ length: number; title?: string; description?: string }`
126
+ - `length` (number): Timer duration in milliseconds.
127
+ - `title` (optional, string): A title for the timer.
128
+ - `description` (optional, string): A description for the timer.
105
129
 
106
- **Returns:** Promise that resolves to the timer ID (UUID)
130
+ - `number` Timer duration in milliseconds.
131
+ ⚠ Not recommended. See [Storage Formats](#storage-formats).
107
132
 
108
- **Throws:** If length is invalid(e.g. length < 0) or file operation fails
133
+ **Returns** A `Promise<string>` that resolves to the timer's unique ID (UUID).
134
+
135
+ **Throws** An error if: `length` is invalid (e.g., negative) or a file operation fails
109
136
 
110
137
  ### `removeTimer(id: string): Promise<void>`
111
138
 
112
- Removes a timer by ID.
139
+ Removes a timer by its ID.
113
140
 
114
- **Parameters:**
115
- - `id` (string): ID of the timer to remove
141
+ - **`id`**: The ID of the timer to remove.
116
142
 
117
- **Returns:** void
143
+ **Returns:** A `Promise` that resolves when the timer is removed.
118
144
 
119
- **Throws:** If the timer with the specified ID is not found or if a file operation fails.
145
+ **Throws:** An error if the timer with the specified ID is not found or if a file operation fails.
120
146
 
121
- ### `checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): Promise<NodeJS.Timeout>`
147
+ ### `checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout`
122
148
 
123
- Starts monitoring expired timers and returns immediately.
149
+ Starts monitoring for expired timers at a specified interval. This function runs asynchronously and will not block execution.
124
150
 
125
- The callback is invoked when a timer expires during periodic checks.
126
- The callback is awaited before the next timer check continues.
151
+ When an expired timer is found, the provided `callback` function is invoked with the `timer` object. The function waits for the `callback`'s `Promise` to resolve before proceeding to the next check, preventing race conditions. Error handling has been added within the `callback` to prevent the application from crashing if an error occurs during timer processing.
127
152
 
128
- **Parameters:**
129
- - `callback`: Function invoked when an expired timer is detected (called during periodic checks and awaited)
130
- - `interval` (number, optional): Check interval in milliseconds (default: 50ms)
153
+ - **`callback`**: An async function that is called with the expired `timer` object.
154
+ - **`interval`** (optional, number): The interval in milliseconds to check for expired timers. Defaults to `200ms`.
131
155
 
132
- **Returns:** interval id of checkTimers
156
+ **Returns:** A `NodeJS.Timeout` object that can be used with `clearInterval()` to stop monitoring.
133
157
 
134
- **Throws:** If file operation fails
158
+ **Throws:** An error if a file operation fails during monitoring.
135
159
 
136
160
  ### `showTimers(): Promise<Timer[]>`
137
161
 
138
162
  Retrieves all active timers.
139
163
 
140
- **Returns:** Array of `Timer` objects
164
+ **Returns:** A `Promise` that resolves to an array of `Timer` objects.
141
165
 
142
- **Throws:** If file operation fails
166
+ **Throws:** An error if a file operation fails.
143
167
 
144
168
  ## Type Definition
145
169
 
170
+ The `StorageType` has the following structure:
146
171
  ```typescript
147
- type Timer = {
148
- id: string; // Unique timer identifier (UUID)
149
- start: number; // Timer start timestamp
150
- stop: number; // Timer end timestamp
151
- title?: string;
152
- description?: string;
153
- }
172
+ type StorageType = "JSONL" | "PlainText"
173
+ ```
174
+
175
+ The `Timer` object has the following structure:
176
+
177
+ ```typescript
178
+ type Timer<T extends StorageType> = {
179
+ id: string;
180
+ start: number;
181
+ stop: number;
182
+ } & (T extends "JSONL"
183
+ ? { title?: string; description?: string }
184
+ : object);
154
185
  ```
155
186
 
156
187
  ## Scripts
@@ -168,7 +199,7 @@ You can choose between two storage formats by selecting the appropriate manager
168
199
  ### 1. JSON Lines (via `JSONLTimersManager`)
169
200
  This is the recommended format for storing rich metadata.
170
201
 
171
- - **Pros**: Allows for storing `title` and `description`.
202
+ - **Pros**: Allows for storing `title` and `description`. Improved memory efficiency due to line-by-line file reading.
172
203
  - **Cons**: Involves JSON parsing, which may have a minor performance overhead.
173
204
  - **Default File**: `.timers.jsonl`
174
205
  - **Format**:
@@ -179,7 +210,7 @@ This is the recommended format for storing rich metadata.
179
210
  ### 2. Plain Text (via `PlainTextTimersManager`)
180
211
  This format is more lightweight and slightly faster.
181
212
 
182
- - **Pros**: Simple and efficient.
213
+ - **Pros**: Simple and efficient. Improved memory efficiency due to line-by-line file reading.
183
214
  - **Cons**: Cannot store additional data like `title` or `description`.
184
215
  - **Default File**: `.timers`
185
216
  - **Format**:
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.JSONLTimersManager = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const uuid_1 = require("uuid");
9
+ const readline_1 = __importDefault(require("readline"));
9
10
  const TimersManager_js_1 = require("./TimersManager.cjs");
10
11
  const Log_js_1 = require("./Log.cjs");
11
12
  /**
@@ -57,8 +58,9 @@ class JSONLTimersManager extends TimersManager_js_1.TimersManager {
57
58
  * const newTimer = await manager.createTimer(5000);
58
59
  * // newTimer will be id of the timer
59
60
  */
60
- async createTimer(length, title, description) {
61
+ async createTimer(options) {
61
62
  try {
63
+ let length = typeof options === "object" ? options.length : options;
62
64
  if (length < 0) {
63
65
  throw new Error(`Invailed length: ${length}`);
64
66
  }
@@ -72,8 +74,8 @@ class JSONLTimersManager extends TimersManager_js_1.TimersManager {
72
74
  id,
73
75
  start: now,
74
76
  stop: (now + length),
75
- ...(title !== undefined && { title }),
76
- ...(description !== undefined && { description }),
77
+ ...(typeof options === "object" && options.title !== undefined && { title: options.title }),
78
+ ...(typeof options === "object" && options.description !== undefined && { description: options.description }),
77
79
  });
78
80
  await fs_1.default.promises.appendFile(this.timerfiledir, newTimerData + "\n");
79
81
  return id;
@@ -95,15 +97,16 @@ class JSONLTimersManager extends TimersManager_js_1.TimersManager {
95
97
  try {
96
98
  const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
97
99
  await this.checkTimerfileSyntax(timersRaw);
100
+ const rl = readline_1.default.createInterface({
101
+ input: fs_1.default.createReadStream(this.timerfiledir),
102
+ crlfDelay: Infinity,
103
+ });
98
104
  let newTimersData = "";
99
- const timersData = timersRaw
100
- .split(/\r?\n/)
101
- .filter(t => t.trim())
102
- .map(line => JSON.parse(line));
103
105
  let found = false;
104
- for (const timerData of timersData) {
105
- if (!timerData)
106
+ for await (const line of rl) {
107
+ if (!line.trim())
106
108
  continue;
109
+ const timerData = JSON.parse(line);
107
110
  if (timerData.id === id) {
108
111
  found = true;
109
112
  continue;
@@ -124,7 +127,7 @@ class JSONLTimersManager extends TimersManager_js_1.TimersManager {
124
127
  * @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
125
128
  * The callback is awaited before continuing.
126
129
  * @param callback Function invoked when an expired timer is detected (called asynchronously)
127
- * @param interval (number, optional): Check interval in milliseconds (default: 50ms)
130
+ * @param interval (number, optional): Check interval in milliseconds (default: 200ms)
128
131
  * @throws If file operation fails
129
132
  * @returns (NodeJS.Timeout) intervalId interval id of checkTimers
130
133
  * @example
@@ -132,26 +135,29 @@ class JSONLTimersManager extends TimersManager_js_1.TimersManager {
132
135
  * console.log(`A timer was stopped: ${timer.id}`);
133
136
  * });
134
137
  */
135
- checkTimers(callback, interval = 50) {
138
+ checkTimers(callback, interval = 200) {
136
139
  return setInterval(async () => {
137
140
  if (this.checkLock)
138
141
  return;
139
142
  this.checkLock = true;
140
143
  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);
144
+ const rl = readline_1.default.createInterface({
145
+ input: fs_1.default.createReadStream(this.timerfiledir),
146
+ crlfDelay: Infinity,
147
+ });
148
+ for await (const line of rl) {
149
+ if (!line.trim())
150
+ continue;
151
+ const timerData = JSON.parse(line);
152
+ const now = Date.now();
153
+ if (Number(timerData.stop) <= now) {
154
+ await this.removeTimer(timerData.id);
155
+ callback(timerData).catch(async (e) => {
156
+ await Log_js_1.Log.ensureLogger();
157
+ if (Log_js_1.Log.loggerInstance) {
158
+ Log_js_1.Log.loggerInstance.error(`Error in callback of checkTimers: ${e}`);
159
+ }
160
+ });
155
161
  }
156
162
  }
157
163
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JSONLTimersManager.js","sourceRoot":"","sources":["../../src/JSONLTimersManager.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA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AK,CAAC,qCAAqC,CAAC,EAAE,CAAC,CAAC;4BACpE,CAAC;wBACF,CAAC,CAAC,CAAC;oBACJ,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;IACU,KAAK,CAAC,UAAU;QAC/B,IAAI,CAAC;YACJ,MAAM,SAAS,GAAW,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YACjF,MAAM,UAAU,GAAqB,SAAS;iBAC5C,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,CAAmB,CAAC,CAAC;YAElD,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;AAlLD,gDAkLC"}
@@ -1,5 +1,5 @@
1
- import type { Timer } from "./types.cjs";
2
- import { TimersManager } from "./TimersManager.cjs";
1
+ import type { Timer, CreateTimerOptions } from "./types.js";
2
+ import { TimersManager } from "./TimersManager.js";
3
3
  /**
4
4
  * JSONLTimersManager
5
5
  * @description
@@ -9,7 +9,7 @@ import { TimersManager } from "./TimersManager.cjs";
9
9
  * - Timers are persisted in a file
10
10
  * - Expired timers are detected by polling
11
11
  */
12
- export declare class JSONLTimersManager extends TimersManager {
12
+ export declare class JSONLTimersManager extends TimersManager<"JSONL"> {
13
13
  protected getDefaultFilename(): string;
14
14
  protected checkTimerfileSyntax(fileData: string): Promise<void>;
15
15
  /**
@@ -25,7 +25,7 @@ export declare class JSONLTimersManager extends TimersManager {
25
25
  * const newTimer = await manager.createTimer(5000);
26
26
  * // newTimer will be id of the timer
27
27
  */
28
- createTimer(length: number, title?: string, description?: string): Promise<string>;
28
+ createTimer(options: CreateTimerOptions<"JSONL">): Promise<string>;
29
29
  /**
30
30
  * removeTimer
31
31
  * @description Removes a timer by ID.
@@ -40,7 +40,7 @@ export declare class JSONLTimersManager extends TimersManager {
40
40
  * @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
41
41
  * The callback is awaited before continuing.
42
42
  * @param callback Function invoked when an expired timer is detected (called asynchronously)
43
- * @param interval (number, optional): Check interval in milliseconds (default: 50ms)
43
+ * @param interval (number, optional): Check interval in milliseconds (default: 200ms)
44
44
  * @throws If file operation fails
45
45
  * @returns (NodeJS.Timeout) intervalId interval id of checkTimers
46
46
  * @example
@@ -48,7 +48,7 @@ export declare class JSONLTimersManager extends TimersManager {
48
48
  * console.log(`A timer was stopped: ${timer.id}`);
49
49
  * });
50
50
  */
51
- checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout;
51
+ checkTimers(callback: (timer: Timer<"JSONL">) => Promise<void>, interval?: number): NodeJS.Timeout;
52
52
  /**
53
53
  * showTimers
54
54
  * @description Retrieves all active timers.
@@ -58,6 +58,6 @@ export declare class JSONLTimersManager extends TimersManager {
58
58
  * const timers = await manager.showTimers();
59
59
  * console.log(JSON.stringify(timers))
60
60
  */
61
- showTimers(): Promise<Timer[]>;
61
+ showTimers(): Promise<Timer<"JSONL">[]>;
62
62
  }
63
63
  //# sourceMappingURL=JSONLTimersManager.d.ts.map
@@ -1 +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,MAAW,GAAG,MAAM,CAAC,OAAO;IAoCpG;;;;;;;;OAQM;IACO,UAAU,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;CAa3C"}
1
+ {"version":3,"file":"JSONLTimersManager.d.ts","sourceRoot":"","sources":["../../src/JSONLTimersManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,SAAQ,aAAa,CAAC,OAAO,CAAC;cAC1C,kBAAkB,IAAI,MAAM;cAI/B,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBrE;;;;;;;;;;;;OAYM;IACgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BxF;;;;;;;;OAQM;IACgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC5D;;;;;;;;;;;OAWM;IACU,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAE,MAAY,GAAG,MAAM,CAAC,OAAO;IAoCvH;;;;;;;;OAQM;IACgB,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;CAa7D"}
package/dist/cjs/Log.cjs CHANGED
@@ -58,25 +58,4 @@ class Log {
58
58
  }
59
59
  }
60
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
61
  //# sourceMappingURL=Log.js.map
@@ -1 +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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AAG,CAAC,WAAW,CAAC;IACvB,CAAC;IAEM,MAAM,KAAK,cAAc;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC;IACnB,CAAC;;AAvBF,kBAwBC"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PlainTextTimersManager = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const uuid_1 = require("uuid");
9
+ const readline_1 = __importDefault(require("readline"));
9
10
  const TimersManager_js_1 = require("./TimersManager.cjs");
10
11
  const Log_js_1 = require("./Log.cjs");
11
12
  class PlainTextTimersManager extends TimersManager_js_1.TimersManager {
@@ -51,14 +52,14 @@ class PlainTextTimersManager extends TimersManager_js_1.TimersManager {
51
52
  * const newTimer = await manager.createTimer(5000);
52
53
  * // newTimer will be id of the timer
53
54
  */
54
- async createTimer(length) {
55
+ async createTimer(options) {
55
56
  try {
56
- if (length < 0) {
57
- throw new Error(`Invailed length: ${length}`);
57
+ if (options < 0) {
58
+ throw new Error(`Invailed length: ${options}`);
58
59
  }
59
60
  const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
60
61
  await this.checkTimerfileSyntax(timersRaw);
61
- length = Math.trunc(length);
62
+ const length = Math.trunc(options);
62
63
  // uuid, start, end
63
64
  const id = (0, uuid_1.v4)();
64
65
  const now = Date.now();
@@ -83,23 +84,26 @@ class PlainTextTimersManager extends TimersManager_js_1.TimersManager {
83
84
  try {
84
85
  const timersRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
85
86
  await this.checkTimerfileSyntax(timersRaw);
86
- const newTimersData = [];
87
- const timersData = timersRaw.split(/\r?\n/);
87
+ const rl = readline_1.default.createInterface({
88
+ input: fs_1.default.createReadStream(this.timerfiledir),
89
+ crlfDelay: Infinity,
90
+ });
91
+ const newTimersDataLines = [];
88
92
  let found = false;
89
- for (const timerData of timersData) {
90
- if (!timerData.trim())
93
+ for await (const line of rl) {
94
+ if (!line.trim())
91
95
  continue;
92
- const [timerId] = timerData.split(" ");
96
+ const [timerId] = line.split(" ");
93
97
  if (timerId === id) {
94
98
  found = true;
95
99
  continue;
96
100
  }
97
- newTimersData.push(timerData);
101
+ newTimersDataLines.push(line);
98
102
  }
99
103
  if (!found) {
100
104
  throw new Error(`Timer with id ${id} not found`);
101
105
  }
102
- await fs_1.default.promises.writeFile(this.timerfiledir, newTimersData.join("\n"), "utf-8");
106
+ await fs_1.default.promises.writeFile(this.timerfiledir, newTimersDataLines.join("\n"), "utf-8");
103
107
  return;
104
108
  }
105
109
  catch (e) {
@@ -111,7 +115,7 @@ class PlainTextTimersManager extends TimersManager_js_1.TimersManager {
111
115
  * @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
112
116
  * The callback is awaited before continuing.
113
117
  * @param callback Function invoked when an expired timer is detected (called asynchronously)
114
- * @param interval (number, optional): Check interval in milliseconds (default: 50ms)
118
+ * @param interval (number, optional): Check interval in milliseconds (default: 200ms)
115
119
  * @throws If file operation fails
116
120
  * @returns (NodeJS.Timeout) intervalId interval id of checkTimers
117
121
  * @example
@@ -119,30 +123,34 @@ class PlainTextTimersManager extends TimersManager_js_1.TimersManager {
119
123
  * console.log(`A timer was stopped: ${timer.id}`);
120
124
  * });
121
125
  */
122
- checkTimers(callback, interval = 50) {
126
+ checkTimers(callback, interval = 200) {
123
127
  return setInterval(async () => {
124
128
  if (this.checkLock)
125
129
  return;
126
130
  this.checkLock = true;
127
131
  try {
128
- const timersDataRaw = await fs_1.default.promises.readFile(this.timerfiledir, "utf-8");
129
- const timersMap = new Map();
130
- const timersData = timersDataRaw.split(/\r?\n/);
131
- for (const timerData of timersData) {
132
- if (!timerData.trim())
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())
133
138
  continue;
134
- const [id, startStr, stopStr] = timerData.split(" ");
135
- timersMap.set(id, {
139
+ const [id, startStr, stopStr] = line.split(" ");
140
+ const timer = {
136
141
  id: id,
137
142
  start: Number(startStr),
138
143
  stop: Number(stopStr),
139
- });
140
- }
141
- const now = Date.now();
142
- for (const timer of timersMap.values()) {
144
+ };
145
+ const now = Date.now();
143
146
  if (Number(timer.stop) <= now) {
144
147
  await this.removeTimer(timer.id);
145
- await callback(timer);
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
+ });
146
154
  }
147
155
  }
148
156
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlainTextTimersManager.js","sourceRoot":"","sources":["../../src/PlainTextTimersManager.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAAoC;AACpC,wDAAgC;AAGhC,yDAAmD;AACnD,qCAA+B;AAE/B,MAAa,sBAAuB,SAAQ,gCAA0B;IAC3D,kBAAkB;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACgB,KAAK,CAAC,oBAAoB,CAAC,QAAgB;QAC7D,MAAM,QAAQ,GAAG,GAAG,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACjD,CAAC,CAAC;QACF,MAAM,UAAU,GAAG,QAAQ;aACzB,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACxB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACpC,MAAM,UAAU,GAAa,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACpD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;gBAAE,QAAQ,EAAE,CAAC;YACxC,IAAI,U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 -1,6 +1,6 @@
1
- import type { Timer } from "./types.cjs";
2
- import { TimersManager } from "./TimersManager.cjs";
3
- export declare class PlainTextTimersManager extends TimersManager {
1
+ import type { Timer, CreateTimerOptions } from "./types.js";
2
+ import { TimersManager } from "./TimersManager.js";
3
+ export declare class PlainTextTimersManager extends TimersManager<"PlainText"> {
4
4
  protected getDefaultFilename(): string;
5
5
  /**
6
6
  * checkTimerfileSyntax
@@ -21,7 +21,7 @@ export declare class PlainTextTimersManager extends TimersManager {
21
21
  * const newTimer = await manager.createTimer(5000);
22
22
  * // newTimer will be id of the timer
23
23
  */
24
- createTimer(length: number): Promise<string>;
24
+ createTimer(options: CreateTimerOptions<"PlainText">): Promise<string>;
25
25
  /**
26
26
  * removeTimer
27
27
  * @description Removes a timer by ID.
@@ -37,7 +37,7 @@ export declare class PlainTextTimersManager extends TimersManager {
37
37
  * @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
38
38
  * The callback is awaited before continuing.
39
39
  * @param callback Function invoked when an expired timer is detected (called asynchronously)
40
- * @param interval (number, optional): Check interval in milliseconds (default: 50ms)
40
+ * @param interval (number, optional): Check interval in milliseconds (default: 200ms)
41
41
  * @throws If file operation fails
42
42
  * @returns (NodeJS.Timeout) intervalId interval id of checkTimers
43
43
  * @example
@@ -45,7 +45,7 @@ export declare class PlainTextTimersManager extends TimersManager {
45
45
  * console.log(`A timer was stopped: ${timer.id}`);
46
46
  * });
47
47
  */
48
- checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout;
48
+ checkTimers(callback: (timer: Timer<"PlainText">) => Promise<void>, interval?: number): NodeJS.Timeout;
49
49
  /**
50
50
  * showTimers
51
51
  * @description Retrieves all active timers.
@@ -55,6 +55,6 @@ export declare class PlainTextTimersManager extends TimersManager {
55
55
  * const timers = await manager.showTimers();
56
56
  * console.log(JSON.stringify(timers))
57
57
  */
58
- showTimers(): Promise<Timer[]>;
58
+ showTimers(): Promise<Timer<"PlainText">[]>;
59
59
  }
60
60
  //# sourceMappingURL=PlainTextTimersManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlainTextTimersManager.d.ts","sourceRoot":"","sources":["../../src/PlainTextTimersManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,qBAAa,sBAAuB,SAAQ,aAAa;IACxD,SAAS,CAAC,kBAAkB,IAAI,MAAM;IAItC;;;;;;OAMG;cACa,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBrE;;;;;;;;;;OAUG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBzD;;;;;;;;OAQG;IACU,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BnD;;;;;;;;;;;;OAYG;IACI,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM,CAAC,OAAO;IAuCpG;;;;;;;;OAQG;IACU,UAAU,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;CAoB3C"}
1
+ {"version":3,"file":"PlainTextTimersManager.d.ts","sourceRoot":"","sources":["../../src/PlainTextTimersManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,qBAAa,sBAAuB,SAAQ,aAAa,CAAC,WAAW,CAAC;IACrE,SAAS,CAAC,kBAAkB,IAAI,MAAM;IAItC;;;;;;OAMG;cACsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB9E;;;;;;;;;;OAUG;IACmB,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAsB5F;;;;;;;;OAQG;IACmB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B5D;;;;;;;;;;;;OAYG;IACa,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAE,MAAY,GAAG,MAAM,CAAC,OAAO;IAyC3H;;;;;;;;OAQG;IACmB,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;CAoBjE"}
@@ -1,4 +1,4 @@
1
- import type { Timer } from "./types.cjs";
1
+ import type { CreateTimerOptions, StorageType, Timer } from "./types.js";
2
2
  /**
3
3
  * TimersManager
4
4
  * @description
@@ -8,7 +8,7 @@ import type { Timer } from "./types.cjs";
8
8
  * - Timers are persisted in a file
9
9
  * - Expired timers are detected by polling
10
10
  */
11
- export declare abstract class TimersManager {
11
+ export declare abstract class TimersManager<T extends StorageType> {
12
12
  protected readonly timerfiledir: string;
13
13
  protected checkLock: boolean;
14
14
  protected abstract getDefaultFilename(): string;
@@ -37,7 +37,7 @@ export declare abstract class TimersManager {
37
37
  * const newTimer = await manager.createTimer(5000);
38
38
  * // newTimer will be id of the timer
39
39
  */
40
- abstract createTimer(length: number, title?: string, description?: string): Promise<string>;
40
+ abstract createTimer(options: CreateTimerOptions<T>): Promise<string>;
41
41
  /**
42
42
  * removeTimer
43
43
  * @description Removes a timer by ID.
@@ -52,7 +52,7 @@ export declare abstract class TimersManager {
52
52
  * @description Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.
53
53
  * The callback is awaited before continuing.
54
54
  * @param callback Function invoked when an expired timer is detected (called asynchronously)
55
- * @param interval (number, optional): Check interval in milliseconds (default: 50ms)
55
+ * @param interval (number, optional): Check interval in milliseconds (default: 200ms)
56
56
  * @throws If file operation fails
57
57
  * @returns (NodeJS.Timeout) intervalId interval id of checkTimers
58
58
  * @example
@@ -60,7 +60,7 @@ export declare abstract class TimersManager {
60
60
  * console.log(`A timer was stopped: ${timer.id}`);
61
61
  * });
62
62
  */
63
- abstract checkTimers(callback: (timer: Timer) => Promise<void>, interval?: number): NodeJS.Timeout;
63
+ abstract checkTimers(callback: (timer: Timer<T>) => Promise<void>, interval?: number): NodeJS.Timeout;
64
64
  /**
65
65
  * showTimers
66
66
  * @description Retrieves all active timers.
@@ -70,6 +70,6 @@ export declare abstract class TimersManager {
70
70
  * const timers = await manager.showTimers();
71
71
  * console.log(JSON.stringify(timers))
72
72
  */
73
- abstract showTimers(): Promise<Timer[]>;
73
+ abstract showTimers(): Promise<Timer<T>[]>;
74
74
  }
75
75
  //# sourceMappingURL=TimersManager.d.ts.map