homebridge-plugin-utils 1.11.2 → 1.12.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.
@@ -13,14 +13,14 @@
13
13
  "lib": [
14
14
 
15
15
  "DOM",
16
- "ES2022"
16
+ "ES2023"
17
17
  ],
18
18
 
19
19
  "module": "ES2022",
20
20
  "moduleResolution":"node",
21
21
  "sourceMap": true,
22
22
  "strict": true,
23
- "target": "ES2022"
23
+ "target": "ES2023"
24
24
  }
25
25
  }
26
26
  /* When creating your own tsconfig.json, use the following as a starting point to inherit these defaults:
package/dist/util.d.ts CHANGED
@@ -32,6 +32,18 @@ export interface HomebridgePluginLogging {
32
32
  info: (message: string, ...parameters: unknown[]) => void;
33
33
  warn: (message: string, ...parameters: unknown[]) => void;
34
34
  }
35
+ /**
36
+ * A utility method that retries an operation at a specific interval for up to an absolute total number of retries.
37
+ * @param operation - The operation callback to try until successful.
38
+ * @param retryInterval - Interval to retry, in milliseconds.
39
+ * @param totalRetries - Optionally, specify the total number of retries.
40
+ *
41
+ * @returns Returns `true` when the operation is successful, `false` otherwise or if the total number of retries has been exceeded.
42
+ *
43
+ * @remarks `operation` must be an asynchronous function that returns `true` when successful, and `false` otherwise.
44
+ *
45
+ * @category Utilities
46
+ */
35
47
  export declare function retry(operation: () => Promise<boolean>, retryInterval: number, totalRetries?: number): Promise<boolean>;
36
48
  export declare function runWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<Nullable<T>>;
37
49
  export declare function sleep(sleepTimer: number): Promise<NodeJS.Timeout>;
package/dist/util.js CHANGED
@@ -2,16 +2,27 @@
2
2
  *
3
3
  * util.ts: Useful utility functions when writing TypeScript.
4
4
  */
5
- // Retry an operation until we're successful.
5
+ /**
6
+ * A utility method that retries an operation at a specific interval for up to an absolute total number of retries.
7
+ * @param operation - The operation callback to try until successful.
8
+ * @param retryInterval - Interval to retry, in milliseconds.
9
+ * @param totalRetries - Optionally, specify the total number of retries.
10
+ *
11
+ * @returns Returns `true` when the operation is successful, `false` otherwise or if the total number of retries has been exceeded.
12
+ *
13
+ * @remarks `operation` must be an asynchronous function that returns `true` when successful, and `false` otherwise.
14
+ *
15
+ * @category Utilities
16
+ */
6
17
  export async function retry(operation, retryInterval, totalRetries) {
7
- if ((totalRetries !== undefined) && (totalRetries < 0)) {
18
+ if ((totalRetries !== undefined) && (totalRetries <= 0)) {
8
19
  return false;
9
20
  }
10
21
  // Try the operation that was requested.
11
22
  if (!(await operation())) {
12
23
  // If the operation wasn't successful, let's sleep for the requested interval and try again.
13
24
  await sleep(retryInterval);
14
- return retry(operation, retryInterval, (totalRetries === undefined) ? undefined : totalRetries--);
25
+ return retry(operation, retryInterval, (totalRetries === undefined) ? undefined : --totalRetries);
15
26
  }
16
27
  // We were successful - we're done.
17
28
  return true;
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2CH,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,SAAiC,EAAE,aAAqB,EAAE,YAAqB;IAEzG,IAAG,CAAC,YAAY,KAAK,SAAS,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;QAEtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,wCAAwC;IACxC,IAAG,CAAC,CAAC,MAAM,SAAS,EAAE,CAAC,EAAE,CAAC;QAExB,4FAA4F;QAC5F,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;QAE3B,OAAO,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;IACpG,CAAC;IAED,mCAAmC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,O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AAY,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IACpG,CAAC;IAED,mCAAmC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,OAAmB,EAAE,OAAe;IAE1E,MAAM,cAAc,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAEhG,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,4BAA4B;AAC5B,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,UAAkB;IAE5C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,YAAY,CAAC,IAAY;IAEvC,+JAA+J;IAC/J,EAAE;IACF,6DAA6D;IAC7D,2DAA2D;IAC3D,0BAA0B;IAC1B,EAAE;IACF,wFAAwF;IACxF,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-plugin-utils",
3
- "version": "1.11.2",
3
+ "version": "1.12.0",
4
4
  "displayName": "Homebridge Plugin Utilities",
5
5
  "description": "Opinionated utilities to provide common capabilities and create rich configuration webUI experiences for Homebridge plugins.",
6
6
  "author": {
@@ -39,13 +39,13 @@
39
39
  },
40
40
  "main": "dist/index.js",
41
41
  "devDependencies": {
42
- "@stylistic/eslint-plugin": "2.11.0",
43
- "@types/node": "22.10.1",
44
- "eslint": "^9.16.0",
42
+ "@stylistic/eslint-plugin": "2.12.1",
43
+ "@types/node": "22.10.2",
44
+ "eslint": "^9.17.0",
45
45
  "homebridge": "1.8.4",
46
46
  "shx": "0.3.4",
47
47
  "typescript": "5.7.2",
48
- "typescript-eslint": "^8.17.0"
48
+ "typescript-eslint": "^8.18.1"
49
49
  },
50
50
  "dependencies": {
51
51
  "mqtt": "5.10.3"