@pogodisco/response 0.0.2 → 0.1.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.
@@ -5,3 +5,4 @@ export declare function isFailure<T>(resp: TResponse<T>): resp is FailureRespons
5
5
  export declare function isSuccess<T>(resp: TResponse<T>): resp is SuccessResponse<T>;
6
6
  export declare function assertResponse<T>(res: TResponse<T>, msg?: string): T;
7
7
  export declare function withResponse<Args extends any[], Return>(fn: (...args: Args) => Promise<Return> | Return, validate?: (result: Return) => boolean, failureMessage?: string): (...args: Args) => Promise<TResponse<Return>>;
8
+ export declare function toResponse<T, A extends any[] = []>(fn: (...args: A) => Promise<any>, ...args: A): Promise<TResponse<T>>;
@@ -42,3 +42,9 @@ export function withResponse(fn, validate, failureMessage) {
42
42
  }
43
43
  };
44
44
  }
45
+ export function toResponse(fn, ...args) {
46
+ return withResponse(async () => {
47
+ const result = await fn(...args);
48
+ return result;
49
+ })();
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/response",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },