@anmiles/queue 4.0.1 → 5.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/.nycrc.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "all": true,
3
+ "check-coverage" : true,
4
+
5
+ "statements" : 100,
6
+ "branches" : 100,
7
+ "lines" : 100,
8
+ "functions" : 100,
9
+
10
+ "report-dir" : "./coverage",
11
+ "temp-dir" : "./coverage",
12
+
13
+ "reporter" : [
14
+ "text",
15
+ "html"
16
+ ],
17
+ "extension": [
18
+ ".js",
19
+ ".mjs",
20
+ ".cjs",
21
+ ".jsx",
22
+ ".ts",
23
+ ".cts",
24
+ ".mts",
25
+ ".tsx"
26
+ ]
27
+ }
package/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.0.0](../../tags/v5.0.0) - 2025-05-18
9
+ __(BREAKING) Dropped support for NodeJS 18 (EOL). Minimum required version is now NodeJS 20.__
10
+
11
+ ### Changed
12
+ - Migrated to NodeJS 20.19
13
+ - Migrated to ESLint V9 flat configs
14
+ - Updated dependencies
15
+
8
16
  ## [4.0.1](../../tags/v4.0.1) - 2024-03-20
9
17
  ### Changed
10
18
  - Update dependencies
package/cspell.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "version": "0.2",
3
+ "enabled": true,
4
+ "language": "en",
5
+ "minWordLength": 4,
6
+ "enableGlobDot": true,
7
+ "useGitignore": true,
8
+ "ignorePaths": [
9
+ ".git",
10
+ "package-lock.json"
11
+ ],
12
+ "words": [
13
+ "anmiles",
14
+ "anatoliy",
15
+ "emittery",
16
+ "oblaukhov"
17
+ ],
18
+ "flagWords": []
19
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"queue.d.ts","sourceR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M,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;IACnH,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,IAAI,GAAE,KAAK,EAAO,EAAE,EAAE,QAAY,EAAE,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;IAO5E,OAAO,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI;IAU1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,KAAK,IAAI,MAAM;CAGf;AAED,eAAe,KAAK,CAAC"}
package/dist/lib/queue.js CHANGED
@@ -25,7 +25,7 @@ class Queue extends emittery_1.default {
25
25
  this.done = false;
26
26
  if (this.data.length > 0) {
27
27
  const now = performance.now();
28
- await this.emit('item', this.data.shift());
28
+ await this.emit('item', this.data.shift()); // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
29
29
  setTimeout(() => {
30
30
  void this.dequeue();
31
31
  }, Math.max(0, this.interval - (performance.now() - now)));
@@ -1 +1 @@
1
- {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/lib/queue.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAOhC,MAAM,KAAa,SAAQ,kBAAyF;IAC3G,IAAI,CAAwB;IACnB,IAAI,CAAe;IACnB,QAAQ,CAAU;IAEnC,YAAY,OAAgB,EAAE,EAAE,EAAE,QAAQ,GAAG,CAAC,KAA6B,EAAE;QAC5E,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAO,KAAK,CAAC;QACtB,IAAI,CAAC,IAAI,GAAO,IAAI,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,OAAO,CAAC,GAAG,KAAc;QACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAEzB,I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AI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,OAAO,CAAC,GAAG,KAAc;QACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAEzB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAElB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAW,CAAC,CAAC,CAAC,kEAAkE;YACvH,UAAU,CAAC,GAAG,EAAE;gBACf,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACF,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;CACD;AAED,kBAAe,KAAK,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { configs } from '@anmiles/eslint-config';
2
+ import type { Linter } from 'eslint';
3
+
4
+ export default [
5
+ ...configs.base,
6
+ ...configs.ts,
7
+ ...configs.jest,
8
+
9
+ {
10
+ ignores: [
11
+ 'coverage/*',
12
+ 'dist/*',
13
+ ],
14
+ },
15
+ ] as Linter.Config[];
package/jest.config.js CHANGED
@@ -1,16 +1,19 @@
1
1
  module.exports = {
2
- preset : 'ts-jest',
3
- transform : {
4
- '^.+\\.tsx?$' : 'ts-jest',
2
+ preset : 'ts-jest',
3
+ transform: {
4
+ '^.+\\.tsx?$': [ 'ts-jest', {
5
+ tsconfig: './tsconfig.test.json',
6
+ } ],
5
7
  },
6
8
 
7
- clearMocks : true,
9
+ clearMocks: true,
8
10
 
9
- roots : [ '<rootDir>/src' ],
10
- testMatch : [ '<rootDir>/src/**/__tests__/*.test.{ts,tsx}' ],
11
+ roots : [ '<rootDir>/src' ],
12
+ testMatch: [ '<rootDir>/src/**/__tests__/*.test.{ts,tsx}' ],
11
13
 
12
- collectCoverageFrom : [
14
+ collectCoverageFrom: [
13
15
  '<rootDir>/src/**/*.{ts,tsx}',
14
16
  '!<rootDir>/src/**/__tests__/**',
17
+ '!<rootDir>/src/**/__mocks__/**',
15
18
  ],
16
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anmiles/queue",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "Queue dispatcher that sequentially processes incoming items",
5
5
  "keywords": [
6
6
  "queue",
@@ -12,43 +12,52 @@
12
12
  "repository": "github:anmiles/queue",
13
13
  "license": "MIT",
14
14
  "engines": {
15
- "node": ">=18.18.0"
15
+ "node": ">=20.19.0"
16
16
  },
17
17
  "main": "dist/index.js",
18
18
  "scripts": {
19
- "build": "rimraf dist && tsc -p ./tsconfig.build.json",
20
- "lint": "eslint .",
21
- "lint:fix": "npm run lint -- --fix",
19
+ "spellcheck": "cspell .",
20
+ "prebuild": "rimraf dist",
21
+ "build": "tsc -p ./tsconfig.build.json",
22
+ "lint": "eslint",
23
+ "lint:fix": "eslint --fix",
22
24
  "test": "jest --verbose",
23
25
  "test:coverage": "npm test -- --coverage",
24
26
  "test:ci": "npm test -- --ci --coverage",
25
27
  "test:watch": "npm test -- --watch",
26
28
  "test:watch:coverage": "npm test -- --watch --coverage",
27
- "test:report:coverage": "nyc report --nycrc-path ./coverage.config.js -t ./coverage --report-dir ./coverage"
29
+ "test:report:coverage": "nyc report"
28
30
  },
29
31
  "dependencies": {
30
32
  "emittery": "^0.13.1"
31
33
  },
32
34
  "devDependencies": {
33
- "@anmiles/eslint-config": "^7.1.1",
34
- "@anmiles/sleep": "^4.0.1",
35
- "@anmiles/tsconfig": "^3.0.1",
36
- "@stylistic/eslint-plugin": "^1.7.0",
37
- "@types/jest": "^29.5.12",
38
- "@typescript-eslint/eslint-plugin": "^7.3.1",
39
- "@typescript-eslint/parser": "^7.3.1",
40
- "eslint": "^8.57.0",
41
- "eslint-import-resolver-typescript": "^3.6.1",
35
+ "@anmiles/eslint-config": "^9.0.0",
36
+ "@anmiles/sleep": "^5.0.0",
37
+ "@anmiles/tsconfig": "^4.0.0",
38
+ "@eslint/compat": "^1.2.9",
39
+ "@eslint/css": "^0.8.1",
40
+ "@eslint/js": "^9.27.0",
41
+ "@eslint/json": "^0.12.0",
42
+ "@eslint/markdown": "^6.4.0",
43
+ "@stylistic/eslint-plugin": "^4.2.0",
44
+ "@types/jest": "^29.5.14",
45
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
46
+ "@typescript-eslint/parser": "^8.32.1",
47
+ "cspell": "^9.0.1",
48
+ "eslint": "^9.27.0",
49
+ "eslint-import-resolver-typescript": "^4.3.5",
42
50
  "eslint-plugin-align-assignments": "^1.1.2",
43
- "eslint-plugin-import": "^2.29.1",
44
- "eslint-plugin-jest": "^27.9.0",
45
- "eslint-plugin-jsonc": "^2.14.1",
46
- "eslint-plugin-n": "^16.6.2",
47
- "eslint-plugin-promise": "^6.1.1",
51
+ "eslint-plugin-i18next": "^6.1.1",
52
+ "eslint-plugin-import": "^2.31.0",
53
+ "eslint-plugin-jest": "^28.11.0",
54
+ "eslint-plugin-n": "^17.18.0",
55
+ "eslint-plugin-promise": "^7.2.1",
48
56
  "jest": "^29.7.0",
49
- "nyc": "^15.1.0",
50
- "rimraf": "^5.0.5",
51
- "ts-jest": "^29.1.2",
52
- "typescript": "^5.4.2"
57
+ "jiti": "^2.4.2",
58
+ "nyc": "^17.1.0",
59
+ "rimraf": "^6.0.1",
60
+ "ts-jest": "^29.3.4",
61
+ "typescript": "^5.8.3"
53
62
  }
54
63
  }
@@ -1,4 +1,5 @@
1
1
  import sleep from '@anmiles/sleep';
2
+
2
3
  import Queue from '../queue';
3
4
 
4
5
  describe('src/lib/queue', () => {
@@ -16,7 +17,7 @@ describe('src/lib/queue', () => {
16
17
  setTimeoutSpy.mockImplementation((func, timeout) => {
17
18
  log.push(`timeout(${Math.floor(timeout ?? 0)})`);
18
19
  func();
19
- return 0 as unknown as ReturnType<typeof setTimeout>;
20
+ return 0 as unknown as ReturnType<typeof setTimeout>; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
20
21
  });
21
22
  });
22
23
 
@@ -41,7 +42,7 @@ describe('src/lib/queue', () => {
41
42
  });
42
43
 
43
44
  it('should be set if specified', () => {
44
- expect(new Queue([], { interval : 10 })['interval']).toEqual(10);
45
+ expect(new Queue([], { interval: 10 })['interval']).toEqual(10);
45
46
  });
46
47
  });
47
48
  });
package/src/lib/queue.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import Emittery from 'emittery';
2
2
 
3
3
  interface Listeners<T> {
4
- item : (item: T) => Promise<void>;
5
- done : () => void;
4
+ item: (item: T)=> Promise<void>;
5
+ done: ()=> void;
6
6
  }
7
7
 
8
8
  class Queue<TItem> extends Emittery<{ [TEvent in keyof Listeners<TItem>]: Parameters<Listeners<TItem>[TEvent]>[0] }> {
9
- private done : boolean;
10
- private readonly data : TItem[];
11
- private readonly interval : number;
9
+ private done: boolean;
10
+ private readonly data: TItem[];
11
+ private readonly interval: number;
12
12
 
13
- constructor(data: TItem[] = [], { interval = 0 }: { interval? : number } = {}) {
13
+ constructor(data: TItem[] = [], { interval = 0 }: { interval?: number } = {}) {
14
14
  super();
15
15
  this.done = false;
16
16
  this.data = data;
@@ -32,7 +32,7 @@ class Queue<TItem> extends Emittery<{ [TEvent in keyof Listeners<TItem>]: Parame
32
32
 
33
33
  if (this.data.length > 0) {
34
34
  const now = performance.now();
35
- await this.emit('item', this.data.shift() as TItem);
35
+ await this.emit('item', this.data.shift() as TItem); // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
36
36
  setTimeout(() => {
37
37
  void this.dequeue();
38
38
  }, Math.max(0, this.interval - (performance.now() - now)));
@@ -3,5 +3,11 @@
3
3
 
4
4
  "exclude" : [
5
5
  "**/__tests__/",
6
+ "**/__mocks__/",
6
7
  ],
8
+
9
+ "compilerOptions" : {
10
+ "rootDir" : "./src",
11
+ "outDir" : "./dist",
12
+ },
7
13
  }
package/tsconfig.json CHANGED
@@ -1,11 +1,6 @@
1
1
  {
2
2
  "extends" : "./node_modules/@anmiles/tsconfig/tsconfig.json",
3
3
 
4
- "compilerOptions" : {
5
- "rootDir" : "./src",
6
- "outDir" : "./dist",
7
- },
8
-
9
4
  "include" : [
10
5
  "src",
11
6
  ],
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends" : "./tsconfig.json",
3
+
4
+ "compilerOptions" : {
5
+ "isolatedModules" : true,
6
+ },
7
+ }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- coverage
2
- dist
package/.eslintrc.js DELETED
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- root : true,
3
-
4
- extends : [
5
- './node_modules/@anmiles/eslint-config/src/base.preset.js',
6
- './node_modules/@anmiles/eslint-config/src/ts.preset.js',
7
- './node_modules/@anmiles/eslint-config/src/jest.preset.js',
8
- ],
9
- };
@@ -1,7 +0,0 @@
1
- {
2
- "cSpell.words": [
3
- "anmiles",
4
- "emittery",
5
- "nycrc"
6
- ]
7
- }
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- 'check-coverage' : true,
3
- 'statements' : 100,
4
- 'branches' : 100,
5
- 'lines' : 100,
6
- 'functions' : 100,
7
- 'reporter' : [ 'html', 'text' ],
8
- };