@dexyn/common-library 1.1.1 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexyn/common-library",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,6 +1,9 @@
1
1
  type SuccessResult<T> = {
2
2
  success: true;
3
3
  data: T;
4
+ page?: number;
5
+ pageSize?: number;
6
+ totalCount?: number;
4
7
  };
5
8
  export type ErrorResult = {
6
9
  success: false;
@@ -23,9 +26,16 @@ export type Result<T> = SuccessResult<T> | ErrorResult;
23
26
  * @returns A ResultUtils<T, E> representing the outcome of the promise.
24
27
  */
25
28
  export declare function toResult<T>(data: T): Result<T>;
29
+ /**
30
+ * Converts an error into a ResultUtils type, wrapping its error outcome.
31
+ *
32
+ * @param error - Error to be wrapped in ResultUtils type
33
+ * @returns A ResultUtils<T, E> representing the error outcome.
34
+ */
26
35
  export declare function errorToErrorResult(error: Error): ErrorResult;
27
36
  export type ErrorName = "UnhandledError" | "BadRequest" | "NotFound" | "ValidationError" | "NotAuthorized";
28
37
  export declare function toErrorResult(name: ErrorName, message: string, details?: Record<string, unknown>, code?: string, statusCode?: number): ErrorResult;
38
+ export declare function toPagedResult<T>(data: T, page: number, pageSize: number, totalCount: number): Result<T>;
29
39
  declare const ResultUtils: {
30
40
  toResult: typeof toResult;
31
41
  errorToErrorResult: typeof errorToErrorResult;
@@ -5,6 +5,7 @@ exports.ResultUtils = void 0;
5
5
  exports.toResult = toResult;
6
6
  exports.errorToErrorResult = errorToErrorResult;
7
7
  exports.toErrorResult = toErrorResult;
8
+ exports.toPagedResult = toPagedResult;
8
9
  const dateUtils_1 = require("../date/dateUtils");
9
10
  /**
10
11
  * Converts a promise into a ResultUtils type, wrapping its success and error outcomes.
@@ -15,6 +16,12 @@ const dateUtils_1 = require("../date/dateUtils");
15
16
  function toResult(data) {
16
17
  return { success: true, data: data };
17
18
  }
19
+ /**
20
+ * Converts an error into a ResultUtils type, wrapping its error outcome.
21
+ *
22
+ * @param error - Error to be wrapped in ResultUtils type
23
+ * @returns A ResultUtils<T, E> representing the error outcome.
24
+ */
18
25
  function errorToErrorResult(error) {
19
26
  return { success: false, error: error };
20
27
  }
@@ -28,6 +35,9 @@ function toErrorResult(name, message, details, code, statusCode) {
28
35
  timestamp: dateUtils_1.DateUtils.formatDateTime(new Date())
29
36
  } };
30
37
  }
38
+ function toPagedResult(data, page, pageSize, totalCount) {
39
+ return { success: true, data: data, page: page, pageSize: pageSize, totalCount: totalCount };
40
+ }
31
41
  // Export everything as a single constant object
32
42
  const ResultUtils = {
33
43
  toResult,