@pogodisco/response 0.0.1 → 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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./types/response";
2
- export * from "./utils/response";
1
+ export * from "./types/response.js";
2
+ export * from "./utils/response.js";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./types/response";
2
- export * from "./utils/response";
1
+ export * from "./types/response.js";
2
+ export * from "./utils/response.js";
@@ -1,7 +1,8 @@
1
- import { type BaseResponse, type FailureResponse, type SuccessResponse, TResponse } from "../types/response";
1
+ import { type BaseResponse, type FailureResponse, type SuccessResponse, TResponse } from "../types/response.js";
2
2
  export declare function newSuccessResponse<T>(data: T, opts?: Partial<Pick<BaseResponse, "message" | "status">>): SuccessResponse<T>;
3
3
  export declare function newFailureResponse(error: string, opts?: Partial<Pick<FailureResponse, "message" | "status" | "level" | "errors">>): FailureResponse;
4
4
  export declare function isFailure<T>(resp: TResponse<T>): resp is FailureResponse;
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>>;
@@ -1,4 +1,4 @@
1
- import { ResponseLevel, } from "../types/response";
1
+ import { ResponseLevel, } from "../types/response.js";
2
2
  export function newSuccessResponse(data, opts) {
3
3
  const { message = "", status = 200 } = opts ?? {};
4
4
  return { ok: true, data, message, status, level: ResponseLevel.SUCCESS };
@@ -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.1",
3
+ "version": "0.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },