@rg-dev/stdlib 1.0.4 → 1.0.6

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.
@@ -113,11 +113,11 @@ function promiseWithTimeout(promise, timeout, errMsg = "The promise timed out.")
113
113
  () => clearTimeout(timeoutID)
114
114
  );
115
115
  }
116
- async function catchInline(promise) {
116
+ async function catchInline(cb) {
117
117
  try {
118
- return { result: await promise, err: null };
118
+ return { error: void 0, result: await cb };
119
119
  } catch (e) {
120
- return { result: null, err: e };
120
+ return { error: e, result: void 0 };
121
121
  }
122
122
  }
123
123
  function doSafe(safe, onError) {
@@ -8,6 +8,7 @@ declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?
8
8
  type MyFn<T extends Record<string, (...args: any[]) => any>> = {
9
9
  [K in keyof T]: (...args: Parameters<T[K]>) => void;
10
10
  };
11
+ type AsyncReturnType<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
11
12
  declare class Optional<T> {
12
13
  private constructor();
13
14
  private value;
@@ -20,12 +21,15 @@ declare class Optional<T> {
20
21
  declare function sleep(ms: number): Promise<unknown>;
21
22
  declare function isNumber(num: any): boolean;
22
23
  declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
23
- declare function catchInline<T>(promise: Promise<T>): Promise<{
24
- err: Error;
24
+ declare function catchInline<T>(cb: Promise<T>): Promise<{
25
+ error: undefined;
25
26
  result: T;
27
+ } | {
28
+ error: Error;
29
+ result: undefined;
26
30
  }>;
27
31
  declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
28
32
  declare function isRunningOnServer(): boolean;
29
33
  declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
30
34
 
31
- export { type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
35
+ export { type AsyncReturnType, type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
@@ -8,6 +8,7 @@ declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?
8
8
  type MyFn<T extends Record<string, (...args: any[]) => any>> = {
9
9
  [K in keyof T]: (...args: Parameters<T[K]>) => void;
10
10
  };
11
+ type AsyncReturnType<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
11
12
  declare class Optional<T> {
12
13
  private constructor();
13
14
  private value;
@@ -20,12 +21,15 @@ declare class Optional<T> {
20
21
  declare function sleep(ms: number): Promise<unknown>;
21
22
  declare function isNumber(num: any): boolean;
22
23
  declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
23
- declare function catchInline<T>(promise: Promise<T>): Promise<{
24
- err: Error;
24
+ declare function catchInline<T>(cb: Promise<T>): Promise<{
25
+ error: undefined;
25
26
  result: T;
27
+ } | {
28
+ error: Error;
29
+ result: undefined;
26
30
  }>;
27
31
  declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
28
32
  declare function isRunningOnServer(): boolean;
29
33
  declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
30
34
 
31
- export { type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
35
+ export { type AsyncReturnType, type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
package/lib/common-env.js CHANGED
@@ -80,11 +80,11 @@ function promiseWithTimeout(promise, timeout, errMsg = "The promise timed out.")
80
80
  () => clearTimeout(timeoutID)
81
81
  );
82
82
  }
83
- async function catchInline(promise) {
83
+ async function catchInline(cb) {
84
84
  try {
85
- return { result: await promise, err: null };
85
+ return { error: void 0, result: await cb };
86
86
  } catch (e) {
87
- return { result: null, err: e };
87
+ return { error: e, result: void 0 };
88
88
  }
89
89
  }
90
90
  function doSafe(safe, onError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/stdlib",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",