@openmrs/esm-utils 4.0.0-pre.0 → 4.0.0-pre.1
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/.turbo/turbo-build.log +18 -18
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +10 -10
- package/.turbo/turbo-typescript.log +2 -2
- package/dist/age-helpers.d.ts +20 -0
- package/dist/index.d.ts +5 -0
- package/dist/omrs-dates.d.ts +110 -0
- package/dist/omrs-dates.test.d.ts +1 -0
- package/dist/openmrs-esm-utils.js +0 -0
- package/dist/openmrs-esm-utils.js.map +1 -1
- package/dist/retry.d.ts +38 -0
- package/dist/translate.d.ts +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.test.d.ts +1 -0
- package/package.json +2 -2
- package/src/omrs-dates.ts +2 -0
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @module @category Utility */
|
|
2
|
+
/**
|
|
3
|
+
* Options for configuring the behavior of the {@link retry} function.
|
|
4
|
+
*/
|
|
5
|
+
export interface RetryOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Determines whether the retry function should retry executing the function after it failed
|
|
8
|
+
* with an error on the current attempt.
|
|
9
|
+
* @param attempt The current (zero-based) retry attempt. `0` indicates the initial attempt.
|
|
10
|
+
*/
|
|
11
|
+
shouldRetry?(attempt: number): any;
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the next delay (in milliseconds) before a retry attempt.
|
|
14
|
+
* Returning a value for the inital attempt (`0`) delays the initial function invocation.
|
|
15
|
+
* @param attempt The current (zero-based) retry attempt. `0` indicates the initial attempt.
|
|
16
|
+
*/
|
|
17
|
+
getDelay?(attempt: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Called when invoking the function resulted in an error.
|
|
20
|
+
* Allows running side-effects on errors, e.g. logging.
|
|
21
|
+
* @param e The error thrown by the function.
|
|
22
|
+
* @param attempt The current (zero-based) retry attempt. `0` indicates the initial attempt.
|
|
23
|
+
*/
|
|
24
|
+
onError?(e: any, attempt: number): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Executes the specified function and retries executing on failure with a custom backoff strategy
|
|
28
|
+
* defined by the options.
|
|
29
|
+
*
|
|
30
|
+
* If not configured otherwise, this function uses the following default options:
|
|
31
|
+
* * Retries 5 times beyond the initial attempt.
|
|
32
|
+
* * Uses an exponential backoff starting with an initial delay of 1000ms.
|
|
33
|
+
* @param fn The function to be executed and retried on failure.
|
|
34
|
+
* @param options Additional options which configure the retry behavior.
|
|
35
|
+
* @returns The result of successfully executing `fn`.
|
|
36
|
+
* @throws Rethrows the final error of running `fn` when the function stops retrying.
|
|
37
|
+
*/
|
|
38
|
+
export declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function translateFrom(moduleName: string, key: string, fallback?: string, options?: object): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isVersionSatisfied(requiredVersion: string, installedVersion: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-utils",
|
|
3
|
-
"version": "4.0.0-pre.
|
|
3
|
+
"version": "4.0.0-pre.1",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Helper utilities for OpenMRS",
|
|
6
6
|
"browser": "dist/openmrs-esm-utils.js",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"semver": "^7.3.2"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "9f58b801f07526083a9edc1cc5a1e58660d71eb0"
|
|
53
53
|
}
|
package/src/omrs-dates.ts
CHANGED
|
@@ -178,6 +178,8 @@ const defaultOptions: FormatDateOptions = {
|
|
|
178
178
|
* When time is included, it is appended with a comma and a space. This
|
|
179
179
|
* agrees with the output of `Date.prototype.toLocaleString` for *most*
|
|
180
180
|
* locales.
|
|
181
|
+
*
|
|
182
|
+
* TODO: Shouldn't throw on null input
|
|
181
183
|
*/
|
|
182
184
|
export function formatDate(date: Date, options?: Partial<FormatDateOptions>) {
|
|
183
185
|
const { mode, time, day, year }: FormatDateOptions = {
|