@cldmv/holdmytask 1.6.1 → 2.0.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/dist/utils.mjs ADDED
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @Project: @cldmv/holdmytask
3
+ * @Filename: /src/utils.mjs
4
+ * @Date: 2025-11-08 17:43:09 -08:00 (1762652589)
5
+ * @Author: Nate Hyson <CLDMV>
6
+ * @Email: <Shinrai@users.noreply.github.com>
7
+ * -----
8
+ * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
+ * @Last modified time: 2025-11-09 16:22:05 -08:00 (1762734125)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+
14
+ /**
15
+ * A min-heap implementation with custom comparison function.
16
+ * Maintains the heap property where parent nodes are smaller than their children.
17
+ */
18
+ export class MinHeap {
19
+ /**
20
+ * Creates a new MinHeap with a custom comparison function.
21
+ * @param {Function} compare - Comparison function that returns negative if a < b, positive if a > b, 0 if equal
22
+ * @example
23
+ * // Priority queue (higher priority = smaller value)
24
+ * const heap = new MinHeap((a, b) => a.priority - b.priority);
25
+ */
26
+ constructor(compare) {
27
+ this.heap = [];
28
+ this.compare = compare;
29
+ }
30
+
31
+ /**
32
+ * Adds an item to the heap, maintaining heap property.
33
+ * @param {*} item - The item to add to the heap
34
+ * @returns {void}
35
+ * @example
36
+ * heap.push({ value: 5, priority: 1 });
37
+ */
38
+ push(item) {
39
+ this.heap.push(item);
40
+ this.bubbleUp(this.heap.length - 1);
41
+ }
42
+
43
+ /**
44
+ * Removes and returns the minimum item from the heap.
45
+ * @returns {*|undefined} The minimum item, or undefined if heap is empty
46
+ * @example
47
+ * const min = heap.pop(); // Returns item with smallest comparison value
48
+ */
49
+ pop() {
50
+ if (this.heap.length === 0) return undefined;
51
+ const root = this.heap[0];
52
+ const last = this.heap.pop();
53
+ if (this.heap.length > 0) {
54
+ this.heap[0] = last;
55
+ this.sinkDown(0);
56
+ }
57
+ return root;
58
+ }
59
+
60
+ /**
61
+ * Returns the minimum item without removing it from the heap.
62
+ * @returns {*|undefined} The minimum item, or undefined if heap is empty
63
+ * @example
64
+ * const min = heap.peek(); // Look at minimum without removing
65
+ */
66
+ peek() {
67
+ return this.heap[0];
68
+ }
69
+
70
+ /**
71
+ * Returns the number of items in the heap.
72
+ * @returns {number} The size of the heap
73
+ * @example
74
+ * const count = heap.size(); // 5
75
+ */
76
+ size() {
77
+ return this.heap.length;
78
+ }
79
+
80
+ /**
81
+ * Moves an item up the heap to maintain heap property after insertion.
82
+ * @param {number} index - Index of the item to bubble up
83
+ * @returns {void}
84
+ * @private
85
+ */
86
+ bubbleUp(index) {
87
+ while (index > 0) {
88
+ const parentIndex = Math.floor((index - 1) / 2);
89
+ if (this.compare(this.heap[index], this.heap[parentIndex]) >= 0) break;
90
+ [this.heap[index], this.heap[parentIndex]] = [this.heap[parentIndex], this.heap[index]];
91
+ index = parentIndex;
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Moves an item down the heap to maintain heap property after removal.
97
+ * @param {number} index - Index of the item to sink down
98
+ * @returns {void}
99
+ * @private
100
+ */
101
+ sinkDown(index) {
102
+ const length = this.heap.length;
103
+ while (true) {
104
+ let left = 2 * index + 1;
105
+ let right = 2 * index + 2;
106
+ let smallest = index;
107
+
108
+ if (left < length && this.compare(this.heap[left], this.heap[smallest]) < 0) {
109
+ smallest = left;
110
+ }
111
+ if (right < length && this.compare(this.heap[right], this.heap[smallest]) < 0) {
112
+ smallest = right;
113
+ }
114
+ if (smallest === index) break;
115
+
116
+ [this.heap[index], this.heap[smallest]] = [this.heap[smallest], this.heap[index]];
117
+ index = smallest;
118
+ }
119
+ }
120
+ }
package/index.mjs CHANGED
@@ -11,7 +11,11 @@
11
11
  * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
12
  */
13
13
 
14
- // Development environment check (must happen before holdmytask imports)
14
+ // Development environment check. NOTE: the static `import` of the core below is
15
+ // hoisted and evaluated before this IIFE body runs, so devcheck does NOT run before
16
+ // the core loads - it's a best-effort, fire-and-forget dev-time warning. (Running it
17
+ // strictly first would require a dynamic import + top-level await, which breaks the
18
+ // index.cjs bridge's synchronous `require` of this module - see PR #11 discussion.)
15
19
  (async () => {
16
20
  try {
17
21
  await import("./devcheck.mjs");
@@ -20,56 +24,51 @@
20
24
  }
21
25
  })();
22
26
 
27
+ import { HoldMyTask } from "@cldmv/holdmytask/main";
28
+
23
29
  /**
24
30
  * Creates a HoldMyTask instance for task queue management
25
31
  * @param {object} [options={}] - Configuration options
26
- * @returns {Promise<object>} HoldMyTask instance
32
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
27
33
  */
28
- export default async function createHoldMyTask(options = {}) {
29
- // Dynamic import after environment check
30
- const mod = await import("@cldmv/holdmytask/main");
31
- const HoldMyTask = mod.HoldMyTask;
34
+ export async function createHoldMyTask(options = {}) {
32
35
  return new HoldMyTask(options);
33
36
  }
34
37
 
35
38
  /**
36
39
  * Create a task queue instance
37
40
  * @param {object} [options={}] - Configuration options
38
- * @returns {Promise<object>} HoldMyTask instance
41
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
39
42
  */
40
43
  export async function createQueue(options = {}) {
41
- const mod = await import("@cldmv/holdmytask/main");
42
- const HoldMyTask = mod.HoldMyTask;
43
44
  return new HoldMyTask(options);
44
45
  }
45
46
 
46
47
  /**
47
48
  * Create a task manager instance
48
49
  * @param {object} [options={}] - Configuration options
49
- * @returns {Promise<object>} HoldMyTask instance
50
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
50
51
  */
51
52
  export async function createTaskManager(options = {}) {
52
- const mod = await import("@cldmv/holdmytask/main");
53
- const HoldMyTask = mod.HoldMyTask;
54
53
  return new HoldMyTask(options);
55
54
  }
56
55
 
57
56
  /**
58
57
  * Create a task processor instance
59
58
  * @param {object} [options={}] - Configuration options
60
- * @returns {Promise<object>} HoldMyTask instance
59
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
61
60
  */
62
61
  export async function createTaskProcessor(options = {}) {
63
- const mod = await import("@cldmv/holdmytask/main");
64
- const HoldMyTask = mod.HoldMyTask;
65
62
  return new HoldMyTask(options);
66
63
  }
67
64
 
68
- // Named export aliases
69
- export { createHoldMyTask as HoldMyTask };
70
- export { createQueue as queue };
71
- export { createQueue as Queue };
72
- export { createTaskManager as TaskManager };
73
- export { createQueue as TaskQueue };
74
- export { createQueue as QueueManager };
75
- export { createTaskProcessor as TaskProcessor };
65
+ // HoldMyTask and its constructor aliases are the real class (see issue #3) - `new
66
+ // HoldMyTask()`, `new QueueManager()`, etc. all construct the same underlying type.
67
+ export { HoldMyTask };
68
+ export default HoldMyTask;
69
+ export { HoldMyTask as queue };
70
+ export { HoldMyTask as Queue };
71
+ export { HoldMyTask as TaskManager };
72
+ export { HoldMyTask as TaskQueue };
73
+ export { HoldMyTask as QueueManager };
74
+ export { HoldMyTask as TaskProcessor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/holdmytask",
3
- "version": "1.6.1",
3
+ "version": "2.0.0",
4
4
  "description": "A tiny task queue that waits until your task is ready",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.mjs",
@@ -11,12 +11,8 @@
11
11
  "import": "./index.mjs",
12
12
  "require": "./index.cjs"
13
13
  },
14
- "./devcheck": {
15
- "types": "./types/devcheck.d.mts",
16
- "import": "./devcheck.mjs"
17
- },
18
14
  "./main": {
19
- "development": {
15
+ "holdmytask-dev": {
20
16
  "types": "./types/src/hold-my-task.d.mts",
21
17
  "import": "./src/hold-my-task.mjs"
22
18
  },
@@ -28,11 +24,17 @@
28
24
  "node": ">=18.12"
29
25
  },
30
26
  "scripts": {
31
- "test": "vitest run --config .configs/vitest.config.mjs",
27
+ "test": "node tests/run-vitest.mjs",
28
+ "test:watch": "vitest --config .configs/vitest.config.mjs",
32
29
  "test:run": "vitest run",
33
30
  "test:coverage": "vitest run --coverage",
34
31
  "test:types": "tsc --noEmit --project .configs/tsconfig.dts.jsonc",
32
+ "coverage": "node tests/run-vitest.mjs --coverage-quiet",
33
+ "ci:coverage": "npm run coverage",
35
34
  "lint": "eslint --config .configs/eslint.config.mjs .",
35
+ "lint:fix": "eslint --config .configs/eslint.config.mjs . --fix",
36
+ "format": "prettier --config .configs/.prettierrc --write .",
37
+ "format:check": "prettier --config .configs/.prettierrc --check .",
36
38
  "build": "node build.mjs",
37
39
  "build:types": "tsc --project .configs/tsconfig.dts.jsonc",
38
40
  "build:ci": "npm run build:types && npm run test:types && npm run build",
@@ -78,19 +80,21 @@
78
80
  },
79
81
  "type": "module",
80
82
  "devDependencies": {
81
- "@eslint/css": "^0.14.1",
82
- "@eslint/js": "^9.39.1",
83
- "@eslint/json": "^0.14.0",
84
- "@eslint/markdown": "^7.5.1",
85
- "@html-eslint/eslint-plugin": "^0.48.0",
86
- "@html-eslint/parser": "^0.48.0",
87
- "@types/node": "^20.0.0",
88
- "@vitest/ui": "^4.0.8",
89
- "eslint": "^9.39.1",
90
- "globals": "^16.5.0",
83
+ "@cldmv/vitest-runner": "^1.2.0",
84
+ "@eslint/css": "^1.4.0",
85
+ "@eslint/js": "^10.0.1",
86
+ "@eslint/json": "^2.0.1",
87
+ "@eslint/markdown": "^8.0.3",
88
+ "@html-eslint/eslint-plugin": "^0.64.0",
89
+ "@html-eslint/parser": "^0.64.0",
90
+ "@types/node": "^26.1.2",
91
+ "@vitest/coverage-v8": "^4.1.10",
92
+ "@vitest/ui": "^4.1.10",
93
+ "eslint": "^10.8.0",
94
+ "globals": "^17.9.0",
91
95
  "prettier": "^3.0.0",
92
- "typescript": "^5.0.0",
93
- "vitest": "^4.0.8"
96
+ "typescript": "^7.0.2",
97
+ "vitest": "^4.1.10"
94
98
  },
95
99
  "repository": {
96
100
  "type": "git",
package/types/index.d.mts CHANGED
@@ -1,3 +1,46 @@
1
- export * from "@cldmv/holdmytask/main";
2
- export { HoldMyTask as default, HoldMyTask as queue, HoldMyTask as Queue, HoldMyTask as TaskManager, HoldMyTask as TaskQueue, HoldMyTask as QueueManager, HoldMyTask as TaskProcessor } from "@cldmv/holdmytask/main";
1
+ /**
2
+ * @Project: @cldmv/holdmytask
3
+ * @Filename: /index.mjs
4
+ * @Date: 2025-11-08 14:04:10 -08:00 (1762639450)
5
+ * @Author: Nate Hyson <CLDMV>
6
+ * @Email: <Shinrai@users.noreply.github.com>
7
+ * -----
8
+ * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
+ * @Last modified time: 2025-11-21 14:47:33 -08:00 (1763765253)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+ import { HoldMyTask } from "@cldmv/holdmytask/main";
14
+ /**
15
+ * Creates a HoldMyTask instance for task queue management
16
+ * @param {object} [options={}] - Configuration options
17
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
18
+ */
19
+ export declare function createHoldMyTask(options?: object): Promise<HoldMyTask>;
20
+ /**
21
+ * Create a task queue instance
22
+ * @param {object} [options={}] - Configuration options
23
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
24
+ */
25
+ export declare function createQueue(options?: object): Promise<HoldMyTask>;
26
+ /**
27
+ * Create a task manager instance
28
+ * @param {object} [options={}] - Configuration options
29
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
30
+ */
31
+ export declare function createTaskManager(options?: object): Promise<HoldMyTask>;
32
+ /**
33
+ * Create a task processor instance
34
+ * @param {object} [options={}] - Configuration options
35
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
36
+ */
37
+ export declare function createTaskProcessor(options?: object): Promise<HoldMyTask>;
38
+ export { HoldMyTask };
39
+ export default HoldMyTask;
40
+ export { HoldMyTask as queue };
41
+ export { HoldMyTask as Queue };
42
+ export { HoldMyTask as TaskManager };
43
+ export { HoldMyTask as TaskQueue };
44
+ export { HoldMyTask as QueueManager };
45
+ export { HoldMyTask as TaskProcessor };
3
46
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAeH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,AAH3C,CACA,EADQ,MAGwC,GAFtC,OAAO,CAAC,UAAU,CAAC,CAI/B;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,OAAO,AAHtC,CACA,EADQ,MAGmC,GAFjC,OAAO,CAAC,UAAU,CAAC,CAI/B;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,AAH5C,CACA,EADQ,MAGyC,GAFvC,OAAO,CAAC,UAAU,CAAC,CAI/B;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,AAH9C,CACA,EADQ,MAG2C,GAFzC,OAAO,CAAC,UAAU,CAAC,CAI/B;AAID,OAAO,EAAE,UAAU,EAAE,CAAC;eACP,UAAU;AACzB,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,CAAC;AAC/B,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,CAAC;AAC/B,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,CAAC;AACrC,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC;AACnC,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,CAAC;AACtC,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,CAAC"}