@creejs/commons-retrier 1.0.6 → 1.0.8

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 CHANGED
@@ -51,8 +51,7 @@ npm intall @creejs/commons-retrier
51
51
  1. retry(task)
52
52
 
53
53
  ```javascript
54
- 'use strict'
55
- const { Retrier } = require('@creejs/commons-retrier')
54
+ const { Retrier } = require('@creejs/commons-retrier')
56
55
 
57
56
  // Chainable API to create and initialize Retrier
58
57
  const retrier = Retrier.infinite() // no retry limit
@@ -84,8 +83,7 @@ npm intall @creejs/commons-retrier
84
83
  2. always(task)
85
84
 
86
85
  ```javas
87
- 'use strict'
88
-
86
+
89
87
  const { Retrier } = require('@creejs/commons-retrier')
90
88
 
91
89
  // Chainable API to create and initialize Retrier
package/index.js CHANGED
@@ -1,3 +1,2 @@
1
- 'use strict'
2
-
3
- module.exports = require('./lib')
1
+ export { default } from './lib/index.js'
2
+ export * from './lib/index.js'
package/lib/alway-task.js CHANGED
@@ -1,11 +1,11 @@
1
- 'use strict'
2
-
3
1
  // owned
4
- // eslint-disable-next-line no-unused-vars
5
- const Retrier = require('./retrier')
6
- const Task = require('./task')
2
+ import Task from './task.js'
3
+
4
+ /**
5
+ * @typedef {import('./retrier.js').default} Retrier
6
+ */
7
7
 
8
- class AlwaysTask extends Task {
8
+ export default class AlwaysTask extends Task {
9
9
  /**
10
10
  * Checks if the given task is an instance of AlwaysTask.
11
11
  * @param {*} task - The task to check.
@@ -41,4 +41,4 @@ class AlwaysTask extends Task {
41
41
  }
42
42
  }
43
43
 
44
- module.exports = AlwaysTask
44
+ export { AlwaysTask as AlwaysTaskType }
package/lib/constants.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
2
1
  // module vars
3
- const DefaultMinInterval = 50
4
- const DefaultMaxInterval = 30 * 1000 // 30s
5
-
6
- const DefaultMaxRetries = 3
7
- module.exports = {
2
+ export const DefaultMinInterval = 50
3
+ export const DefaultMaxInterval = 30 * 1000 // 30s
4
+ export const DefaultMaxRetries = 3
5
+ export default {
8
6
  DefaultMinInterval,
9
7
  DefaultMaxInterval,
10
8
  DefaultMaxRetries
package/lib/event.js CHANGED
@@ -1,15 +1,14 @@
1
- 'use strict'
2
- const Start = 'start' // retry started
3
- const Stop = 'stop' // retry stopped
4
- const Retry = 'retry' // one retry began
5
- const Success = 'success' // one task running succeeded
6
- const Failure = 'failure' // one task ran failed
7
- const Timeout = 'timeout' // total timeout
8
- const TaskTimeout = 'task-timeout' // one task timed out
9
- const Completed = 'complete' // all retries completed
10
- const MaxRetries = 'max-retries' // Reach the max retries
1
+ export const Start = 'start' // retry started
2
+ export const Stop = 'stop' // retry stopped
3
+ export const Retry = 'retry' // one retry began
4
+ export const Success = 'success' // one task running succeeded
5
+ export const Failure = 'failure' // one task ran failed
6
+ export const Timeout = 'timeout' // total timeout
7
+ export const TaskTimeout = 'task-timeout' // one task timed out
8
+ export const Completed = 'complete' // all retries completed
9
+ export const MaxRetries = 'max-retries' // Reach the max retries
11
10
 
12
- module.exports = {
11
+ export default {
13
12
  Start,
14
13
  Retry,
15
14
  Success,
package/lib/index.js CHANGED
@@ -1,12 +1,11 @@
1
- 'use strict'
2
1
  // 3rd
3
- const { LangUtils } = require('@creejs/commons-lang')
2
+ import { LangUtils } from '@creejs/commons-lang'
4
3
 
5
4
  // owned
6
- const Policy = require('./policy')
7
- const Retrier = require('./retrier')
8
- const Event = require('./event')
9
- const RetrierFactory = require('./retrier-factory')
5
+ import Policy from './policy.js'
6
+ import Retrier from './retrier.js'
7
+ import Event from './event.js'
8
+ import RetrierFactory from './retrier-factory.js'
10
9
 
11
10
  /**
12
11
  * Add all factory methods to Retrier as static methods.
@@ -19,10 +18,27 @@ const RetrierFactory = require('./retrier-factory')
19
18
  */
20
19
  LangUtils.defaults(Retrier, RetrierFactory)
21
20
 
22
- module.exports = {
21
+ /**
22
+ * default export to support
23
+ * 1. import CommonsRetrier from '@creejs/commons-retrier'
24
+ */
25
+ export default {
23
26
  Policy,
24
27
  Retrier,
25
28
  Event,
26
29
  RetrierFactory,
27
30
  ...RetrierFactory
28
31
  }
32
+
33
+ /**
34
+ * named export to support
35
+ * 1. import { Retrier } from '@creejs/commons-retrier'
36
+ * 2. import * as CommonsRetrier from '@creejs/commons-retrier'
37
+ */
38
+ export {
39
+ Policy,
40
+ Retrier,
41
+ Event,
42
+ RetrierFactory
43
+ }
44
+ export * from './retrier-factory.js'
@@ -1,11 +1,12 @@
1
- 'use strict'
2
1
  // 3rd
3
2
  // internal
4
- const { TypeAssert: { assertPositive } } = require('@creejs/commons-lang')
3
+ import { TypeAssert } from '@creejs/commons-lang'
5
4
  // owned
6
- const Policy = require('../policy')
5
+ import Policy from '../policy.js'
6
+ // module vars
7
+ const { assertPositive } = TypeAssert
7
8
 
8
- class FactoreIncreasePolicy extends Policy {
9
+ export default class FactoreIncreasePolicy extends Policy {
9
10
  /**
10
11
  * each call to _next() increases the interval by lastInterval * factor
11
12
  * @param {number} factor - the increasement factor, >= 1
@@ -42,5 +43,4 @@ class FactoreIncreasePolicy extends Policy {
42
43
  return this._nextInterval * this.factor
43
44
  }
44
45
  }
45
-
46
- module.exports = FactoreIncreasePolicy
46
+ export { FactoreIncreasePolicy as FactoreIncreasePolicyType }
@@ -1,11 +1,11 @@
1
- 'use strict'
2
1
  // 3rd
3
2
  // internal
4
- const { TypeAssert: { assertPositive } } = require('@creejs/commons-lang')
3
+ import { TypeAssert } from '@creejs/commons-lang'
5
4
  // owned
6
- const Policy = require('../policy')
7
-
8
- class FixedIncreasePolicy extends Policy {
5
+ import Policy from '../policy.js'
6
+ // module vars
7
+ const { assertPositive } = TypeAssert
8
+ export default class FixedIncreasePolicy extends Policy {
9
9
  /**
10
10
  * each call to _next() increases the interval by "increasement".
11
11
  * @param {number} increasement - The fixed interval (in milliseconds) between retry attempts.
@@ -36,5 +36,4 @@ class FixedIncreasePolicy extends Policy {
36
36
  return this._nextInterval + this.increasement
37
37
  }
38
38
  }
39
-
40
- module.exports = FixedIncreasePolicy
39
+ export { FixedIncreasePolicy as FixedIncreasePolicyType }
@@ -1,11 +1,11 @@
1
- 'use strict'
2
1
  // 3rd
3
2
  // internal
4
- const { TypeAssert: { assertPositive } } = require('@creejs/commons-lang')
3
+ import { TypeAssert } from '@creejs/commons-lang'
5
4
  // owned
6
- const Policy = require('../policy')
7
-
8
- class FixedIntervalPolicy extends Policy {
5
+ import Policy from '../policy.js'
6
+ // module vars
7
+ const { assertPositive } = TypeAssert
8
+ export default class FixedIntervalPolicy extends Policy {
9
9
  /**
10
10
  * Creates a fixed interval retry policy with the specified interval.
11
11
  * @param {number} interval - The fixed interval (in milliseconds) between retry attempts.
@@ -35,4 +35,4 @@ class FixedIntervalPolicy extends Policy {
35
35
  }
36
36
  }
37
37
 
38
- module.exports = FixedIntervalPolicy
38
+ export { FixedIntervalPolicy as FixedIntervalPolicyType }
@@ -1,12 +1,13 @@
1
- 'use strict'
2
1
  // 3rd
3
2
  // internal
4
- const { TypeAssert: { assertPositive } } = require('@creejs/commons-lang')
3
+ import { TypeAssert } from '@creejs/commons-lang'
5
4
 
6
5
  // owned
7
- const Policy = require('../policy')
6
+ import Policy from '../policy.js'
7
+ // module vars
8
+ const { assertPositive } = TypeAssert
8
9
 
9
- class ShuttlePolicy extends Policy {
10
+ export default class ShuttlePolicy extends Policy {
10
11
  /**
11
12
  * the inteval value shuttles between min and max
12
13
  * @param {number} stepLength - the step length to change
@@ -46,4 +47,4 @@ class ShuttlePolicy extends Policy {
46
47
  }
47
48
  }
48
49
 
49
- module.exports = ShuttlePolicy
50
+ export { ShuttlePolicy as ShuttlePolicyType }
package/lib/policy.js CHANGED
@@ -1,14 +1,13 @@
1
- 'use strict'
2
1
  // internal
3
- const {
4
- TypeAssert: { assertPositive },
5
- TypeUtils: { isNumber }
6
- } = require('@creejs/commons-lang')
2
+ import { TypeAssert, TypeUtils } from '@creejs/commons-lang'
7
3
  // owned
8
- const { DefaultMaxInterval, DefaultMinInterval } = require('./constants')
4
+ import { DefaultMaxInterval, DefaultMinInterval } from './constants.js'
5
+
9
6
  // module vars
7
+ const { assertPositive } = TypeAssert
8
+ const { isNumber } = TypeUtils
10
9
 
11
- class Policy {
10
+ export default class Policy {
12
11
  /**
13
12
  * Creates a new Policy instance with specified retry bounds.
14
13
  */
@@ -128,4 +127,4 @@ class Policy {
128
127
  throw new Error('Not Impled Yet')
129
128
  }
130
129
  }
131
- module.exports = Policy
130
+ export { Policy as PolicyType }
@@ -1,6 +1,5 @@
1
- 'use strict'
2
1
  // owned
3
- const Retrier = require('./retrier')
2
+ import Retrier from './retrier.js'
4
3
  /**
5
4
  * Creates a new Retrier instance with the specified name.
6
5
  * @param {string} name - The name to assign to the retrier.
@@ -155,7 +154,26 @@ function start (task) {
155
154
  return retrier.start()
156
155
  }
157
156
 
158
- module.exports = {
157
+ // default export
158
+ export default {
159
+ name,
160
+ infinite,
161
+ times,
162
+ maxRetries,
163
+ min,
164
+ max,
165
+ range,
166
+ fixedInterval,
167
+ fixedIncrease,
168
+ factorIncrease,
169
+ shuttleInterval,
170
+ timeout,
171
+ taskTimeout,
172
+ start
173
+ }
174
+
175
+ // named export
176
+ export {
159
177
  name,
160
178
  infinite,
161
179
  times,
package/lib/retrier.js CHANGED
@@ -1,32 +1,28 @@
1
- 'use strict'
2
-
3
1
  // internal
4
- const {
5
- TypeAssert: { assertPositive, assertString, assertFunction, assertNumber },
6
- TypeUtils: { isNil },
7
- PromiseUtils
8
- } = require('@creejs/commons-lang')
9
- const { EventEmitter } = require('@creejs/commons-events')
2
+ import { TypeAssert, TypeUtils, PromiseUtils } from '@creejs/commons-lang'
3
+ import { EventEmitter } from '@creejs/commons-events'
10
4
 
11
5
  // owned
12
6
  // eslint-disable-next-line no-unused-vars
13
- const Policy = require('./policy')
14
- const Event = require('./event')
15
- const FixedIntervalPolicy = require('./policy/fixed-interval-policy')
16
- const FixedIncreasePolicy = require('./policy/fixed-increase-policy')
17
- const FactoreIncreasePolicy = require('./policy/factor-increase-policy')
18
- const ShuttlePolicy = require('./policy/shuttle-policy')
19
- const Task = require('./task')
20
- const AlwaysTask = require('./alway-task')
21
- const { DefaultMaxRetries } = require('./constants')
7
+ import Policy from './policy.js'
8
+ import Event from './event.js'
9
+ import FixedIntervalPolicy from './policy/fixed-interval-policy.js'
10
+ import FixedIncreasePolicy from './policy/fixed-increase-policy.js'
11
+ import FactoreIncreasePolicy from './policy/factor-increase-policy.js'
12
+ import ShuttlePolicy from './policy/shuttle-policy.js'
13
+ import Task from './task.js'
14
+ import AlwaysTask from './alway-task.js'
15
+ import { DefaultMaxRetries } from './constants.js'
22
16
 
23
17
  // module vars
18
+ const { assertPositive, assertString, assertFunction, assertNumber } = TypeAssert
19
+ const { isNil } = TypeUtils
24
20
  const TaskTimoutFlag = '!#@%$&^*'
25
21
 
26
22
  /**
27
23
  * @extends EventEmitter
28
24
  */
29
- class Retrier {
25
+ export default class Retrier {
30
26
  /**
31
27
  * Creates a new Retrier instance with a fixed interval policy.
32
28
  * @param {number} [fixedInterval=1000] - The fixed interval in milliseconds between retry attempts. Defaults to 1000ms if not provided.
@@ -531,4 +527,4 @@ function isInfinite (value) {
531
527
  return value <= 0 || value === Infinity
532
528
  }
533
529
 
534
- module.exports = Retrier
530
+ export { Retrier as RetrierType }
package/lib/task.js CHANGED
@@ -1,11 +1,13 @@
1
- 'use strict'
2
-
3
- const { TypeAssert: { assertNotNil, assertFunction } } = require('@creejs/commons-lang')
1
+ import { TypeAssert } from '@creejs/commons-lang'
4
2
  // owned
5
- // eslint-disable-next-line no-unused-vars
6
- const Retrier = require('./retrier')
7
3
 
8
- class Task {
4
+ /**
5
+ * @typedef {import('./retrier.js').default} Retrier
6
+ */
7
+
8
+ // module vars
9
+ const { assertNotNil, assertFunction } = TypeAssert
10
+ export default class Task {
9
11
  /**
10
12
  * Creates a new Task instance.
11
13
  * @param {Retrier} retrier - The retrier instance.
@@ -53,4 +55,4 @@ class Task {
53
55
  }
54
56
  }
55
57
 
56
- module.exports = Task
58
+ export { Task as TaskType }
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@creejs/commons-retrier",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Common Utils About Task Retrying",
5
- "main": "index.js",
5
+ "keywords": [
6
+ "commons",
7
+ "creejs",
8
+ "retrier",
9
+ "retry",
10
+ "always",
11
+ "task",
12
+ "variable delay",
13
+ "variable interval"
14
+ ],
6
15
  "private": false,
16
+ "type": "module",
7
17
  "files": [
8
18
  "index.js",
9
19
  "lib/",
@@ -11,6 +21,26 @@
11
21
  "README.md"
12
22
  ],
13
23
  "types": "types/index.d.ts",
24
+ "main": "./dist/esm/index-min.js",
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "development": "./dist/esm/index-dev.js",
29
+ "production": "./dist/esm/index-min.js",
30
+ "default": "./dist/esm/index-min.js"
31
+ },
32
+ "require": {
33
+ "development": "./dist/cjs/index-dev.cjs",
34
+ "production": "./dist/cjs/index-min.cjs",
35
+ "default": "./dist/cjs/index-min.cjs"
36
+ },
37
+ "browser": {
38
+ "development": "./dist/umd/index-dev.js",
39
+ "production": "./dist/umd/index-min.js",
40
+ "default": "./dist/cjs/index-min.js"
41
+ }
42
+ }
43
+ },
14
44
  "publishConfig": {
15
45
  "access": "public"
16
46
  },
@@ -20,13 +50,17 @@
20
50
  },
21
51
  "scripts": {
22
52
  "dts": "tsc",
23
- "generate-docs": "../../node_modules/.bin/jsdoc -c ./jsdoc.json"
53
+ "generate-docs": "../../node_modules/.bin/jsdoc -c ./jsdoc.json",
54
+ "clean": "rm -rf dist && rm -rf types && rm -rf docs",
55
+ "build": "npm run clean && npm run dts && rollup -c",
56
+ "prepublishOnly": "npm run build",
57
+ "publish": "npm run prepublishOnly && npm publish"
24
58
  },
25
59
  "author": "rodney.vin@gmail.com",
26
60
  "license": "Apache-2.0",
27
61
  "dependencies": {
28
- "@creejs/commons-events": "^1.0.3",
29
- "@creejs/commons-lang": "^1.0.3"
62
+ "@creejs/commons-events": "^1.0.9",
63
+ "@creejs/commons-lang": "^1.0.10"
30
64
  },
31
65
  "devDependencies": {}
32
66
  }
@@ -1,5 +1,7 @@
1
- export = AlwaysTask;
2
- declare class AlwaysTask extends Task {
1
+ /**
2
+ * @typedef {import('./retrier.js').default} Retrier
3
+ */
4
+ export default class AlwaysTask extends Task {
3
5
  /**
4
6
  * Checks if the given task is an instance of AlwaysTask.
5
7
  * @param {*} task - The task to check.
@@ -23,5 +25,6 @@ declare class AlwaysTask extends Task {
23
25
  */
24
26
  execute(retries: number, latence: number, nextInterval: number): Promise<any>;
25
27
  }
26
- import Task = require("./task");
27
- import Retrier = require("./retrier");
28
+ export { AlwaysTask as AlwaysTaskType };
29
+ export type Retrier = import('./retrier.js').default;
30
+ import Task from "./task.js";
@@ -1,3 +1,9 @@
1
1
  export const DefaultMinInterval: 50;
2
2
  export const DefaultMaxInterval: number;
3
3
  export const DefaultMaxRetries: 3;
4
+ declare namespace _default {
5
+ export { DefaultMinInterval };
6
+ export { DefaultMaxInterval };
7
+ export { DefaultMaxRetries };
8
+ }
9
+ export default _default;
package/types/event.d.ts CHANGED
@@ -1,9 +1,21 @@
1
1
  export const Start: "start";
2
+ export const Stop: "stop";
2
3
  export const Retry: "retry";
3
4
  export const Success: "success";
4
5
  export const Failure: "failure";
5
6
  export const Timeout: "timeout";
6
7
  export const TaskTimeout: "task-timeout";
7
- export const Stop: "stop";
8
8
  export const Completed: "complete";
9
9
  export const MaxRetries: "max-retries";
10
+ declare namespace _default {
11
+ export { Start };
12
+ export { Retry };
13
+ export { Success };
14
+ export { Failure };
15
+ export { Timeout };
16
+ export { TaskTimeout };
17
+ export { Stop };
18
+ export { Completed };
19
+ export { MaxRetries };
20
+ }
21
+ export default _default;
package/types/index.d.ts CHANGED
@@ -1,25 +1,52 @@
1
- declare const _exports: {
2
- name: typeof RetrierFactory.name;
3
- infinite: typeof RetrierFactory.infinite;
4
- times: typeof RetrierFactory.times;
5
- maxRetries: typeof RetrierFactory.maxRetries;
6
- min: typeof RetrierFactory.min;
7
- max: typeof RetrierFactory.max;
8
- range: typeof RetrierFactory.range;
9
- fixedInterval: typeof RetrierFactory.fixedInterval;
10
- fixedIncrease: typeof RetrierFactory.fixedIncrease;
11
- factorIncrease: typeof RetrierFactory.factorIncrease;
12
- shuttleInterval: typeof RetrierFactory.shuttleInterval;
13
- timeout: typeof RetrierFactory.timeout;
14
- taskTimeout: typeof RetrierFactory.taskTimeout;
15
- start: typeof RetrierFactory.start;
1
+ declare const _default: {
2
+ name: typeof import("./retrier-factory.js").name;
3
+ infinite: typeof import("./retrier-factory.js").infinite;
4
+ times: typeof import("./retrier-factory.js").times;
5
+ maxRetries: typeof import("./retrier-factory.js").maxRetries;
6
+ min: typeof import("./retrier-factory.js").min;
7
+ max: typeof import("./retrier-factory.js").max;
8
+ range: typeof import("./retrier-factory.js").range;
9
+ fixedInterval: typeof import("./retrier-factory.js").fixedInterval;
10
+ fixedIncrease: typeof import("./retrier-factory.js").fixedIncrease;
11
+ factorIncrease: typeof import("./retrier-factory.js").factorIncrease;
12
+ shuttleInterval: typeof import("./retrier-factory.js").shuttleInterval;
13
+ timeout: typeof import("./retrier-factory.js").timeout;
14
+ taskTimeout: typeof import("./retrier-factory.js").taskTimeout;
15
+ start: typeof import("./retrier-factory.js").start;
16
16
  Policy: typeof Policy;
17
17
  Retrier: typeof Retrier;
18
- Event: typeof Event;
19
- RetrierFactory: typeof RetrierFactory;
18
+ Event: {
19
+ Start: string;
20
+ Retry: string;
21
+ Success: string;
22
+ Failure: string;
23
+ Timeout: string;
24
+ TaskTimeout: string;
25
+ Stop: string;
26
+ Completed: string;
27
+ MaxRetries: string;
28
+ };
29
+ RetrierFactory: {
30
+ name: typeof import("./retrier-factory.js").name;
31
+ infinite: typeof import("./retrier-factory.js").infinite;
32
+ times: typeof import("./retrier-factory.js").times;
33
+ maxRetries: typeof import("./retrier-factory.js").maxRetries;
34
+ min: typeof import("./retrier-factory.js").min;
35
+ max: typeof import("./retrier-factory.js").max;
36
+ range: typeof import("./retrier-factory.js").range;
37
+ fixedInterval: typeof import("./retrier-factory.js").fixedInterval;
38
+ fixedIncrease: typeof import("./retrier-factory.js").fixedIncrease;
39
+ factorIncrease: typeof import("./retrier-factory.js").factorIncrease;
40
+ shuttleInterval: typeof import("./retrier-factory.js").shuttleInterval;
41
+ timeout: typeof import("./retrier-factory.js").timeout;
42
+ taskTimeout: typeof import("./retrier-factory.js").taskTimeout;
43
+ start: typeof import("./retrier-factory.js").start;
44
+ };
20
45
  };
21
- export = _exports;
22
- import RetrierFactory = require("./retrier-factory");
23
- import Policy = require("./policy");
24
- import Retrier = require("./retrier");
25
- import Event = require("./event");
46
+ export default _default;
47
+ export * from "./retrier-factory.js";
48
+ import Policy from "./policy.js";
49
+ import Retrier from "./retrier.js";
50
+ import Event from "./event.js";
51
+ import RetrierFactory from "./retrier-factory.js";
52
+ export { Policy, Retrier, Event, RetrierFactory };
@@ -1,12 +1,12 @@
1
- export = FactoreIncreasePolicy;
2
- declare class FactoreIncreasePolicy extends Policy {
1
+ export default class FactoreIncreasePolicy extends Policy {
3
2
  /**
4
3
  * each call to _next() increases the interval by lastInterval * factor
5
4
  * @param {number} factor - the increasement factor, >= 1
6
5
  */
7
6
  constructor(factor: number);
8
7
  _factor: number;
9
- set factor(factor: number);
8
+ set factor(arg: number);
10
9
  get factor(): number;
11
10
  }
12
- import Policy = require("../policy");
11
+ export { FactoreIncreasePolicy as FactoreIncreasePolicyType };
12
+ import Policy from "../policy.js";
@@ -1,12 +1,12 @@
1
- export = FixedIncreasePolicy;
2
- declare class FixedIncreasePolicy extends Policy {
1
+ export default class FixedIncreasePolicy extends Policy {
3
2
  /**
4
3
  * each call to _next() increases the interval by "increasement".
5
4
  * @param {number} increasement - The fixed interval (in milliseconds) between retry attempts.
6
5
  */
7
6
  constructor(increasement: number);
8
7
  _increasement: number;
9
- set increasement(increasement: number);
8
+ set increasement(arg: number);
10
9
  get increasement(): number;
11
10
  }
12
- import Policy = require("../policy");
11
+ export { FixedIncreasePolicy as FixedIncreasePolicyType };
12
+ import Policy from "../policy.js";
@@ -1,12 +1,12 @@
1
- export = FixedIntervalPolicy;
2
- declare class FixedIntervalPolicy extends Policy {
1
+ export default class FixedIntervalPolicy extends Policy {
3
2
  /**
4
3
  * Creates a fixed interval retry policy with the specified interval.
5
4
  * @param {number} interval - The fixed interval (in milliseconds) between retry attempts.
6
5
  */
7
6
  constructor(interval: number);
8
7
  _interval: number;
9
- set interval(interval: number);
8
+ set interval(arg: number);
10
9
  get interval(): number;
11
10
  }
12
- import Policy = require("../policy");
11
+ export { FixedIntervalPolicy as FixedIntervalPolicyType };
12
+ import Policy from "../policy.js";
@@ -1,5 +1,4 @@
1
- export = ShuttlePolicy;
2
- declare class ShuttlePolicy extends Policy {
1
+ export default class ShuttlePolicy extends Policy {
3
2
  /**
4
3
  * the inteval value shuttles between min and max
5
4
  * @param {number} stepLength - the step length to change
@@ -7,7 +6,8 @@ declare class ShuttlePolicy extends Policy {
7
6
  constructor(stepLength: number);
8
7
  _stepLength: number;
9
8
  increasement: number;
10
- set stepLength(stepLength: number);
9
+ set stepLength(arg: number);
11
10
  get stepLength(): number;
12
11
  }
13
- import Policy = require("../policy");
12
+ export { ShuttlePolicy as ShuttlePolicyType };
13
+ import Policy from "../policy.js";
package/types/policy.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export = Policy;
2
- declare class Policy {
1
+ export default class Policy {
3
2
  _min: number;
4
3
  _max: number;
5
4
  _nextInterval: number;
@@ -35,7 +34,7 @@ declare class Policy {
35
34
  * @returns {this} The retrier instance for chaining.
36
35
  */
37
36
  max(max: number): this;
38
- reset(): this;
37
+ reset(): Policy;
39
38
  /**
40
39
  * Interval ms of next execution
41
40
  * @returns {number}
@@ -50,3 +49,4 @@ declare class Policy {
50
49
  */
51
50
  protected _next(): number;
52
51
  }
52
+ export { Policy as PolicyType };
@@ -1,3 +1,20 @@
1
+ declare namespace _default {
2
+ export { name };
3
+ export { infinite };
4
+ export { times };
5
+ export { maxRetries };
6
+ export { min };
7
+ export { max };
8
+ export { range };
9
+ export { fixedInterval };
10
+ export { fixedIncrease };
11
+ export { factorIncrease };
12
+ export { shuttleInterval };
13
+ export { timeout };
14
+ export { taskTimeout };
15
+ export { start };
16
+ }
17
+ export default _default;
1
18
  /**
2
19
  * Creates a new Retrier instance with the specified name.
3
20
  * @param {string} name - The name to assign to the retrier.
@@ -82,4 +99,4 @@ export function taskTimeout(timeout: number): Retrier;
82
99
  * @returns {Promise<*>} A promise that resolves when the retry process completes.
83
100
  */
84
101
  export function start(task: Function): Promise<any>;
85
- import Retrier = require("./retrier");
102
+ import Retrier from "./retrier.js";
@@ -1,13 +1,12 @@
1
- export = Retrier;
2
1
  /**
3
2
  * @extends EventEmitter
4
3
  */
5
- declare class Retrier {
4
+ export default class Retrier {
6
5
  /**
7
6
  * Creates a new Retrier instance with a fixed interval policy.
8
7
  * @param {number} [fixedInterval=1000] - The fixed interval in milliseconds between retry attempts. Defaults to 1000ms if not provided.
9
8
  */
10
- constructor(fixedInterval?: number);
9
+ constructor(fixedInterval?: number | undefined);
11
10
  /**
12
11
  * @type {Policy}
13
12
  */
@@ -153,7 +152,7 @@ declare class Retrier {
153
152
  * @param {boolean} [resetAfterSuccess=false] - Whether to reset retry counters after success.
154
153
  * @returns {this} The Retrier instance for chaining.
155
154
  */
156
- always(task: Function, resetAfterSuccess?: boolean): this;
155
+ always(task: Function, resetAfterSuccess?: boolean | undefined): this;
157
156
  /**
158
157
  * Starts the retry process.
159
158
  * @returns {Promise<*>}
@@ -164,7 +163,7 @@ declare class Retrier {
164
163
  * @param {Error} [reason] - Optional reason for stopping (defaults to 'Manually Stop' error).
165
164
  * @returns {Promise<void>} A promise that resolves when the retrier has fully stopped.
166
165
  */
167
- stop(reason?: Error): Promise<void>;
166
+ stop(reason?: Error | undefined): Promise<void>;
168
167
  /**
169
168
  * Resets the retry policy to its initial state.
170
169
  */
@@ -209,7 +208,7 @@ declare class Retrier {
209
208
  * Registers a listener for "timeout" events.
210
209
  * @param {Function} listener - The callback function
211
210
  */
212
- onTimeout(listener: Function): this;
211
+ onTimeout(listener: Function): Retrier;
213
212
  /**
214
213
  * Registers a listener for "task-timeout" events.
215
214
  * @param {Function} listener - The callback function
@@ -220,7 +219,7 @@ declare class Retrier {
220
219
  * Registers a listener for "completed" events.
221
220
  * @param {Function} listener - The callback function
222
221
  */
223
- onCompleted(listener: Function): this;
222
+ onCompleted(listener: Function): Retrier;
224
223
  /**
225
224
  * Registers a listener for the 'MaxRetries' event.
226
225
  * @param {Function} listener - The callback function to be executed when max retries are reached.
@@ -228,6 +227,7 @@ declare class Retrier {
228
227
  */
229
228
  onMaxRetries(listener: Function): this;
230
229
  }
231
- import Policy = require("./policy");
232
- import Task = require("./task");
233
- import AlwaysTask = require("./alway-task");
230
+ export { Retrier as RetrierType };
231
+ import Policy from "./policy.js";
232
+ import Task from "./task.js";
233
+ import AlwaysTask from "./alway-task.js";
package/types/task.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- export = Task;
2
- declare class Task {
1
+ export default class Task {
3
2
  /**
4
3
  * Creates a new Task instance.
5
4
  * @param {Retrier} retrier - The retrier instance.
6
5
  * @param {Function} task - The function to be executed as the task.
7
6
  */
8
7
  constructor(retrier: Retrier, task: Function);
9
- retrier: Retrier;
8
+ retrier: import("./retrier.js").default;
10
9
  task: Function;
11
10
  result: any;
12
11
  error: unknown;
@@ -25,4 +24,5 @@ declare class Task {
25
24
  execute(retries: number, latence: number, nextInterval: number): Promise<void>;
26
25
  dispose(): void;
27
26
  }
28
- import Retrier = require("./retrier");
27
+ export { Task as TaskType };
28
+ export type Retrier = import('./retrier.js').default;