@clipboard-health/util-ts 2.0.1 → 2.1.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/.eslintrc.json +12 -0
- package/jest.config.ts +18 -0
- package/package.json +5 -3
- package/project.json +33 -0
- package/src/{index.d.ts → index.ts} +1 -1
- package/src/lib/{attributes.d.ts → attributes.ts} +1 -1
- package/src/lib/cbh-error.spec.ts +30 -0
- package/src/lib/cbh-error.ts +26 -0
- package/src/lib/cbh-response.spec.ts +25 -0
- package/src/lib/cbh-response.ts +15 -0
- package/src/lib/defined-utils.spec.ts +35 -0
- package/src/lib/{defined-utils.d.ts → defined-utils.ts} +9 -4
- package/src/lib/delay.spec.ts +11 -0
- package/src/lib/delay.ts +5 -0
- package/src/lib/force-cast.spec.ts +8 -0
- package/src/lib/force-cast.ts +4 -0
- package/src/lib/head.spec.ts +21 -0
- package/src/lib/head.ts +5 -0
- package/src/lib/identity.spec.ts +17 -0
- package/src/lib/{identity.d.ts → identity.ts} +3 -2
- package/src/lib/is-string.spec.ts +11 -0
- package/src/lib/is-string.ts +3 -0
- package/src/lib/non-empty-array.ts +7 -0
- package/src/lib/null-to-undefined.spec.ts +33 -0
- package/src/lib/{null-to-undefined.d.ts → null-to-undefined.ts} +4 -2
- package/src/lib/stringify.spec.ts +11 -0
- package/src/lib/stringify.ts +5 -0
- package/src/lib/to-error.spec.ts +28 -0
- package/src/lib/to-error.ts +20 -0
- package/tsconfig.json +19 -0
- package/tsconfig.lib.json +8 -0
- package/tsconfig.lint.json +7 -0
- package/tsconfig.spec.json +13 -0
- package/typedoc.json +4 -0
- package/CHANGELOG.md +0 -208
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -16
- package/src/index.js.map +0 -1
- package/src/lib/attributes.d.ts.map +0 -1
- package/src/lib/attributes.js +0 -3
- package/src/lib/attributes.js.map +0 -1
- package/src/lib/cbh-error.d.ts +0 -15
- package/src/lib/cbh-error.d.ts.map +0 -1
- package/src/lib/cbh-error.js +0 -19
- package/src/lib/cbh-error.js.map +0 -1
- package/src/lib/cbh-response.d.ts +0 -18
- package/src/lib/cbh-response.d.ts.map +0 -1
- package/src/lib/cbh-response.js +0 -13
- package/src/lib/cbh-response.js.map +0 -1
- package/src/lib/defined-utils.d.ts.map +0 -1
- package/src/lib/defined-utils.js +0 -22
- package/src/lib/defined-utils.js.map +0 -1
- package/src/lib/force-cast.d.ts +0 -3
- package/src/lib/force-cast.d.ts.map +0 -1
- package/src/lib/force-cast.js +0 -9
- package/src/lib/force-cast.js.map +0 -1
- package/src/lib/head.d.ts +0 -3
- package/src/lib/head.d.ts.map +0 -1
- package/src/lib/head.js +0 -8
- package/src/lib/head.js.map +0 -1
- package/src/lib/identity.d.ts.map +0 -1
- package/src/lib/identity.js +0 -18
- package/src/lib/identity.js.map +0 -1
- package/src/lib/is-string.d.ts +0 -2
- package/src/lib/is-string.d.ts.map +0 -1
- package/src/lib/is-string.js +0 -8
- package/src/lib/is-string.js.map +0 -1
- package/src/lib/non-empty-array.d.ts +0 -4
- package/src/lib/non-empty-array.d.ts.map +0 -1
- package/src/lib/non-empty-array.js +0 -8
- package/src/lib/non-empty-array.js.map +0 -1
- package/src/lib/null-to-undefined.d.ts.map +0 -1
- package/src/lib/null-to-undefined.js +0 -18
- package/src/lib/null-to-undefined.js.map +0 -1
- package/src/lib/stringify.d.ts +0 -2
- package/src/lib/stringify.d.ts.map +0 -1
- package/src/lib/stringify.js +0 -8
- package/src/lib/stringify.js.map +0 -1
- package/src/lib/to-error.d.ts +0 -4
- package/src/lib/to-error.d.ts.map +0 -1
- package/src/lib/to-error.js +0 -25
- package/src/lib/to-error.js.map +0 -1
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../../.eslintrc.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"parserOptions": {
|
|
5
|
+
"project": "tsconfig.lint.json",
|
|
6
|
+
"tsconfigRootDir": "packages/util-ts"
|
|
7
|
+
},
|
|
8
|
+
"rules": {
|
|
9
|
+
// Block node dependencies so this library is usable in the browser.
|
|
10
|
+
"no-restricted-imports": ["error", { "patterns": ["node:*"] }]
|
|
11
|
+
}
|
|
12
|
+
}
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
coveragePathIgnorePatterns: [],
|
|
3
|
+
coverageThreshold: {
|
|
4
|
+
global: {
|
|
5
|
+
branches: 100,
|
|
6
|
+
functions: 100,
|
|
7
|
+
lines: 100,
|
|
8
|
+
statements: 100,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
displayName: "util-ts",
|
|
12
|
+
moduleFileExtensions: ["ts", "js"],
|
|
13
|
+
preset: "../../jest.preset.js",
|
|
14
|
+
setupFiles: ["../../jest.setup.js"],
|
|
15
|
+
transform: {
|
|
16
|
+
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
|
|
17
|
+
},
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/util-ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
7
|
+
},
|
|
5
8
|
"scripts": {
|
|
6
9
|
"build": "nx build util-ts",
|
|
7
10
|
"lint": "nx lint util-ts",
|
|
8
11
|
"test": "nx test util-ts"
|
|
9
|
-
}
|
|
10
|
-
"type": "commonjs"
|
|
12
|
+
}
|
|
11
13
|
}
|
package/project.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "util-ts",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"sourceRoot": "packages/util-ts/src",
|
|
6
|
+
"tags": ["scope:no-external-imports"],
|
|
7
|
+
"targets": {
|
|
8
|
+
"build": {
|
|
9
|
+
"executor": "@nx/js:tsc",
|
|
10
|
+
"options": {
|
|
11
|
+
"assets": ["packages/util-ts/*.md"],
|
|
12
|
+
"main": "packages/util-ts/src/index.js",
|
|
13
|
+
"outputPath": "dist/packages/util-ts",
|
|
14
|
+
"tsConfig": "packages/util-ts/tsconfig.lib.json"
|
|
15
|
+
},
|
|
16
|
+
"outputs": ["{options.outputPath}"]
|
|
17
|
+
},
|
|
18
|
+
"lint": {
|
|
19
|
+
"executor": "@nx/eslint:lint",
|
|
20
|
+
"options": {
|
|
21
|
+
"maxWarnings": 0
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"test": {
|
|
25
|
+
"executor": "@nx/jest:jest",
|
|
26
|
+
"options": {
|
|
27
|
+
"jestConfig": "packages/util-ts/jest.config.ts",
|
|
28
|
+
"passWithNoTests": false
|
|
29
|
+
},
|
|
30
|
+
"outputs": ["{projectRoot}/coverage"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -2,6 +2,7 @@ export * from "./lib/attributes";
|
|
|
2
2
|
export * from "./lib/cbh-error";
|
|
3
3
|
export * from "./lib/cbh-response";
|
|
4
4
|
export * from "./lib/defined-utils";
|
|
5
|
+
export * from "./lib/delay";
|
|
5
6
|
export * from "./lib/force-cast";
|
|
6
7
|
export * from "./lib/head";
|
|
7
8
|
export * from "./lib/identity";
|
|
@@ -10,4 +11,3 @@ export * from "./lib/non-empty-array";
|
|
|
10
11
|
export * from "./lib/null-to-undefined";
|
|
11
12
|
export * from "./lib/stringify";
|
|
12
13
|
export * from "./lib/to-error";
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CbhError } from "./cbh-error";
|
|
2
|
+
|
|
3
|
+
describe("CbhError", () => {
|
|
4
|
+
it("returns proper defaults", () => {
|
|
5
|
+
const message = "boom";
|
|
6
|
+
const statusCode = 500;
|
|
7
|
+
|
|
8
|
+
const error = new CbhError({ message, statusCode });
|
|
9
|
+
|
|
10
|
+
expect(error.name).toBe("CbhError");
|
|
11
|
+
expect(error.message).toBe(message);
|
|
12
|
+
expect(error.issues[0]?.statusCode).toBe(statusCode);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("sets the cause", () => {
|
|
16
|
+
const cause = new Error("cause");
|
|
17
|
+
|
|
18
|
+
const error = new CbhError({ message: "boom", cause });
|
|
19
|
+
|
|
20
|
+
expect(error.cause).toBe(cause);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("accpets an array", () => {
|
|
24
|
+
const message = "boom";
|
|
25
|
+
|
|
26
|
+
const error = new CbhError([{ message }]);
|
|
27
|
+
|
|
28
|
+
expect(error.message).toBe(message);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type OneOrNonEmptyArray, toNonEmptyArray } from "./non-empty-array";
|
|
2
|
+
|
|
3
|
+
const ERROR_STATUS_CODES = [400, 401, 403, 404, 409, 422, 429, 500] as const;
|
|
4
|
+
export type ErrorStatusCode = (typeof ERROR_STATUS_CODES)[number];
|
|
5
|
+
|
|
6
|
+
export interface CbhIssue {
|
|
7
|
+
cause?: Error;
|
|
8
|
+
id?: string;
|
|
9
|
+
message: string;
|
|
10
|
+
statusCode?: ErrorStatusCode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class CbhError extends Error {
|
|
14
|
+
public readonly issues: CbhIssue[];
|
|
15
|
+
|
|
16
|
+
constructor(issues: OneOrNonEmptyArray<CbhIssue>) {
|
|
17
|
+
const is = toNonEmptyArray(issues);
|
|
18
|
+
const first = is[0];
|
|
19
|
+
super(first?.message, { cause: first?.cause });
|
|
20
|
+
// See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
|
|
21
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
22
|
+
|
|
23
|
+
this.issues = is;
|
|
24
|
+
this.name = "CbhError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CbhError } from "./cbh-error";
|
|
2
|
+
import { toErrorCbhResponse, toSuccessCbhResponse } from "./cbh-response";
|
|
3
|
+
|
|
4
|
+
describe("toErrorCbhResponse", () => {
|
|
5
|
+
it("returns error", () => {
|
|
6
|
+
const message = "boom";
|
|
7
|
+
|
|
8
|
+
const response = toErrorCbhResponse({ message });
|
|
9
|
+
|
|
10
|
+
expect(response).toEqual({
|
|
11
|
+
success: false,
|
|
12
|
+
error: new CbhError({ message }),
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe("toSuccessCbhResponse", () => {
|
|
18
|
+
it("returns success", () => {
|
|
19
|
+
const message = "success";
|
|
20
|
+
|
|
21
|
+
const response = toSuccessCbhResponse({ message });
|
|
22
|
+
|
|
23
|
+
expect(response).toEqual({ success: true, data: { message } });
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CbhError, type CbhIssue } from "./cbh-error";
|
|
2
|
+
import type { OneOrNonEmptyArray } from "./non-empty-array";
|
|
3
|
+
|
|
4
|
+
export type CbhResponse<T> = { success: true; data: T } | { success: false; error: CbhError };
|
|
5
|
+
|
|
6
|
+
export function toErrorCbhResponse(issues: OneOrNonEmptyArray<CbhIssue>): {
|
|
7
|
+
success: false;
|
|
8
|
+
error: CbhError;
|
|
9
|
+
} {
|
|
10
|
+
return { success: false, error: new CbhError(issues) };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function toSuccessCbhResponse<T>(data: T): { success: true; data: T } {
|
|
14
|
+
return { success: true, data };
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isDefined, isNullOrUndefined } from "./defined-utils";
|
|
2
|
+
|
|
3
|
+
const DEFINED_TEST_CASES = ["gandalf", " ", "", 42, 0, -0];
|
|
4
|
+
|
|
5
|
+
describe("isNullOrUndefined", () => {
|
|
6
|
+
it.each(DEFINED_TEST_CASES)("returns false for (%s)", (value) => {
|
|
7
|
+
expect(isNullOrUndefined(value)).toBe(false);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("returns true if null", () => {
|
|
11
|
+
// eslint-disable-next-line unicorn/no-null
|
|
12
|
+
expect(isNullOrUndefined(null)).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("returns true if undefined", () => {
|
|
16
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
17
|
+
expect(isNullOrUndefined(undefined)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("isDefined", () => {
|
|
22
|
+
it.each(DEFINED_TEST_CASES)("returns true for (%s)", (value) => {
|
|
23
|
+
expect(isDefined(value)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("returns false if undefined", () => {
|
|
27
|
+
// eslint-disable-next-line unicorn/no-null
|
|
28
|
+
expect(isDefined(null)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("returns false if null", () => {
|
|
32
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
33
|
+
expect(isDefined(undefined)).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -2,18 +2,23 @@
|
|
|
2
2
|
* We specifically want to guard against both `null` and `undefined`
|
|
3
3
|
* In this one case, we need to define `null` as an expected argument type.
|
|
4
4
|
*/
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
6
|
type NullOrUndefined = null | undefined;
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Checks whether a value is null or undefined. If it is not defined, the return type ensures type safety.
|
|
8
10
|
* @param value any value or null or undefined
|
|
9
11
|
* @returns true if `value` is null or undefined, false otherwise.
|
|
10
12
|
*/
|
|
11
|
-
export
|
|
13
|
+
export function isNullOrUndefined<T>(value: T | NullOrUndefined): value is NullOrUndefined {
|
|
14
|
+
return value === null || value === undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Checks whether a value is defined. If it is defined, the return type ensures type safety.
|
|
14
19
|
* @param value any value or null or undefined
|
|
15
20
|
* @returns true if `value` is defined (not null and not undefined), false otherwise.
|
|
16
21
|
*/
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
export function isDefined<T>(value: T | NullOrUndefined): value is T {
|
|
23
|
+
return !isNullOrUndefined(value);
|
|
24
|
+
}
|
package/src/lib/delay.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { head } from "./head";
|
|
2
|
+
|
|
3
|
+
describe("head", () => {
|
|
4
|
+
it("returns head of list", () => {
|
|
5
|
+
expect(head([1, 2])).toBe(1);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns undefined if empty list", () => {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
10
|
+
expect(head([])).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("returns undefined if passed", () => {
|
|
14
|
+
expect(head()).toBeUndefined();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns value if not an array", () => {
|
|
18
|
+
const value = { hi: "there" };
|
|
19
|
+
expect(head(value)).toEqual(value);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/lib/head.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { identity } from "./identity";
|
|
2
|
+
|
|
3
|
+
describe("identity", () => {
|
|
4
|
+
it("returns the provided input", () => {
|
|
5
|
+
expect(identity(1)).toBe(1);
|
|
6
|
+
expect(identity("text")).toBe("text");
|
|
7
|
+
expect(identity({})).toStrictEqual({});
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should correctly infer the type", () => {
|
|
11
|
+
const a = 1;
|
|
12
|
+
expect(typeof a).toBe("number");
|
|
13
|
+
|
|
14
|
+
const b = identity(a);
|
|
15
|
+
expect(typeof b).toBe("number");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -8,5 +8,6 @@
|
|
|
8
8
|
* @param {T} value - The value to return unchanged.
|
|
9
9
|
* @returns {T} The input value, unchanged.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
11
|
+
export function identity<T>(value: T): T {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { nullToUndefined } from "./null-to-undefined";
|
|
2
|
+
|
|
3
|
+
describe("nullToUndefined", () => {
|
|
4
|
+
it("returns undefined", async () => {
|
|
5
|
+
// eslint-disable-next-line unicorn/no-null
|
|
6
|
+
expect(await nullToUndefined(Promise.resolve(null))).toBeUndefined();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("returns value", async () => {
|
|
10
|
+
const expected = "hi";
|
|
11
|
+
|
|
12
|
+
expect(await nullToUndefined(Promise.resolve(expected))).toBe(expected);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("supports PromiseLike objects", async () => {
|
|
16
|
+
const expected = "hello";
|
|
17
|
+
|
|
18
|
+
const promiseLike: PromiseLike<string> = {
|
|
19
|
+
// eslint-disable-next-line unicorn/no-thenable
|
|
20
|
+
then: function <TResult1, TResult2>(
|
|
21
|
+
onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | undefined,
|
|
22
|
+
): PromiseLike<TResult1 | TResult2> {
|
|
23
|
+
if (onfulfilled) {
|
|
24
|
+
return Promise.resolve(onfulfilled(expected));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return Promise.reject();
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
expect(await nullToUndefined(promiseLike)).toBe(expected);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -7,5 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @param value A promise or a promise-like object.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
11
|
+
export async function nullToUndefined<T>(value: PromiseLike<T | null>): Promise<T | undefined> {
|
|
12
|
+
return (await value) ?? undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { stringify } from "./stringify";
|
|
2
|
+
|
|
3
|
+
describe("stringify", () => {
|
|
4
|
+
test.each([
|
|
5
|
+
[1n, '"1"'],
|
|
6
|
+
[{ a: 1 }, '{"a":1}'],
|
|
7
|
+
[{ a: 1n }, '{"a":"1"}'],
|
|
8
|
+
])("stringify(%i, %i)", (value, expected) => {
|
|
9
|
+
expect(stringify(value)).toBe(expected);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { stringify } from "./stringify";
|
|
2
|
+
import { toErrorMessage } from "./to-error";
|
|
3
|
+
|
|
4
|
+
const MESSAGE = "hi";
|
|
5
|
+
|
|
6
|
+
describe("toErrorMessage", () => {
|
|
7
|
+
it("returns message", () => {
|
|
8
|
+
expect(toErrorMessage(new Error(MESSAGE))).toEqual(MESSAGE);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("returns message if non-error object", () => {
|
|
12
|
+
const error = { hello: MESSAGE };
|
|
13
|
+
|
|
14
|
+
expect(toErrorMessage(error)).toEqual(stringify(error));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns message if unable to stringify", () => {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
const circularReference = { a: { b: "c" }, d: {} } as any;
|
|
20
|
+
circularReference.a.d = circularReference.a;
|
|
21
|
+
|
|
22
|
+
expect(toErrorMessage(circularReference)).toBe("[object Object]");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("returns message if string", () => {
|
|
26
|
+
expect(toErrorMessage(MESSAGE)).toEqual(MESSAGE);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isString } from "./is-string";
|
|
2
|
+
import { stringify } from "./stringify";
|
|
3
|
+
|
|
4
|
+
export function isError(error: unknown): error is Error {
|
|
5
|
+
return error instanceof Error;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function toError(error: unknown): Error {
|
|
9
|
+
if (isError(error)) return error;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
return new Error(isString(error) ? error : stringify(error));
|
|
13
|
+
} catch {
|
|
14
|
+
return new Error(String(error));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function toErrorMessage(error: unknown): string {
|
|
19
|
+
return toError(error).message;
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc"
|
|
5
|
+
},
|
|
6
|
+
"files": [],
|
|
7
|
+
"include": [],
|
|
8
|
+
"references": [
|
|
9
|
+
{
|
|
10
|
+
"path": "./tsconfig.lib.json"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"path": "./tsconfig.lint.json"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"path": "./tsconfig.spec.json"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
package/typedoc.json
ADDED
package/CHANGELOG.md
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
-
|
|
5
|
-
## [2.0.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-2.0.0...util-ts-2.0.1) (2024-07-18)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* add build postTarget ([#692](https://github.com/ClipboardHealth/cbh-core/issues/692)) ([3b42efb](https://github.com/ClipboardHealth/cbh-core/commit/3b42efb603572c7a273c8eedd554773c6a364acf))
|
|
11
|
-
|
|
12
|
-
## [2.0.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.2.1...util-ts-2.0.0) (2024-07-18)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### ⚠ BREAKING CHANGES
|
|
16
|
-
|
|
17
|
-
* upgrade Nx to v18 (#690)
|
|
18
|
-
|
|
19
|
-
### Code Refactoring
|
|
20
|
-
|
|
21
|
-
* upgrade Nx to v18 ([#690](https://github.com/ClipboardHealth/cbh-core/issues/690)) ([e6dd982](https://github.com/ClipboardHealth/cbh-core/commit/e6dd982db39022a72dfbf888f707768bae834ccb))
|
|
22
|
-
|
|
23
|
-
## [1.2.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.2.0...util-ts-1.2.1) (2024-07-12)
|
|
24
|
-
|
|
25
|
-
## [1.2.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.2.0...util-ts-1.2.1) (2024-07-11)
|
|
26
|
-
|
|
27
|
-
## [1.2.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.2.0...util-ts-1.2.1) (2024-07-11)
|
|
28
|
-
|
|
29
|
-
## [1.2.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.2.0...util-ts-1.2.1) (2024-07-11)
|
|
30
|
-
|
|
31
|
-
## [1.2.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.1.0...util-ts-1.2.0) (2024-05-08)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### Features
|
|
35
|
-
|
|
36
|
-
* add more utils ([#624](https://github.com/ClipboardHealth/cbh-core/issues/624)) ([282ec68](https://github.com/ClipboardHealth/cbh-core/commit/282ec68d285ac0007032eb57d5e16177ef380e30))
|
|
37
|
-
|
|
38
|
-
## [1.1.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-1.0.0...util-ts-1.1.0) (2024-01-24)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Features
|
|
42
|
-
|
|
43
|
-
* **money:** add clamp operation ([#515](https://github.com/ClipboardHealth/cbh-core/issues/515)) ([1e92217](https://github.com/ClipboardHealth/cbh-core/commit/1e92217cc5d44762ddaffbe5467398f3b6653744))
|
|
44
|
-
|
|
45
|
-
## [1.0.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.7...util-ts-1.0.0) (2024-01-10)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### ⚠ BREAKING CHANGES
|
|
49
|
-
|
|
50
|
-
* Add 422 response code to CbhError (#497)
|
|
51
|
-
|
|
52
|
-
### Features
|
|
53
|
-
|
|
54
|
-
* Add 422 response code to CbhError ([#497](https://github.com/ClipboardHealth/cbh-core/issues/497)) ([e1695bb](https://github.com/ClipboardHealth/cbh-core/commit/e1695bbcd31ec6db50ac4c07f3d49588999bc436)), closes [4#f184ccb3923a4af4bbb6ee82914a4ff5](https://github.com/ClipboardHealth/4/issues/f184ccb3923a4af4bbb6ee82914a4ff5)
|
|
55
|
-
|
|
56
|
-
## [0.11.7](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.6...util-ts-0.11.7) (2023-12-07)
|
|
57
|
-
|
|
58
|
-
## [0.11.6](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.5...util-ts-0.11.6) (2023-12-07)
|
|
59
|
-
|
|
60
|
-
## [0.11.5](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.4...util-ts-0.11.5) (2023-12-04)
|
|
61
|
-
|
|
62
|
-
## [0.11.4](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.3...util-ts-0.11.4) (2023-11-06)
|
|
63
|
-
|
|
64
|
-
## [0.11.3](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.2...util-ts-0.11.3) (2023-11-06)
|
|
65
|
-
|
|
66
|
-
## [0.11.2](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.1...util-ts-0.11.2) (2023-11-06)
|
|
67
|
-
|
|
68
|
-
## [0.11.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.11.0...util-ts-0.11.1) (2023-09-29)
|
|
69
|
-
|
|
70
|
-
## [0.11.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.10.0...util-ts-0.11.0) (2023-09-24)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
### Features
|
|
74
|
-
|
|
75
|
-
* add api-nestjs ([8e6a1bb](https://github.com/ClipboardHealth/cbh-core/commit/8e6a1bbc2cf24d876ae098f4977f96a70a815b5b))
|
|
76
|
-
|
|
77
|
-
## [0.10.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.9.1...util-ts-0.10.0) (2023-09-14)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
### Features
|
|
81
|
-
|
|
82
|
-
* add identity function to util-ts ([#314](https://github.com/ClipboardHealth/cbh-core/issues/314)) ([7ba2f98](https://github.com/ClipboardHealth/cbh-core/commit/7ba2f98db8550cef89cd9b1e8631ec6902f46058))
|
|
83
|
-
|
|
84
|
-
## [0.9.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.9.0...util-ts-0.9.1) (2023-08-18)
|
|
85
|
-
|
|
86
|
-
## [0.9.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.8.0...util-ts-0.9.0) (2023-08-14)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
### Features
|
|
90
|
-
|
|
91
|
-
* add typed API relationships, add pagination and API error examples ([#256](https://github.com/ClipboardHealth/cbh-core/issues/256)) ([81377e3](https://github.com/ClipboardHealth/cbh-core/commit/81377e357af447c764ed668196a5c025e35aff35))
|
|
92
|
-
|
|
93
|
-
## [0.8.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.7.4...util-ts-0.8.0) (2023-08-10)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
### Features
|
|
97
|
-
|
|
98
|
-
* add API errors with helpers to create them from CbhError ([#252](https://github.com/ClipboardHealth/cbh-core/issues/252)) ([0efb42a](https://github.com/ClipboardHealth/cbh-core/commit/0efb42a9ef44831bf08b05a6ae19a55cfc38742a))
|
|
99
|
-
|
|
100
|
-
## [0.7.4](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.7.3...util-ts-0.7.4) (2023-07-12)
|
|
101
|
-
|
|
102
|
-
## [0.7.3](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.7.2...util-ts-0.7.3) (2023-07-10)
|
|
103
|
-
|
|
104
|
-
## [0.7.2](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.7.1...util-ts-0.7.2) (2023-07-07)
|
|
105
|
-
|
|
106
|
-
## [0.7.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.7.0...util-ts-0.7.1) (2023-07-05)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
### Bug Fixes
|
|
110
|
-
|
|
111
|
-
* export to-error, is-string, and stringify ([#191](https://github.com/ClipboardHealth/cbh-core/issues/191)) ([b89fd79](https://github.com/ClipboardHealth/cbh-core/commit/b89fd79b954c70b4469506ce96982cce9cf40137))
|
|
112
|
-
|
|
113
|
-
## [0.7.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.6.1...util-ts-0.7.0) (2023-07-05)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
### Features
|
|
117
|
-
|
|
118
|
-
* Add `isDefined` utility function ([#183](https://github.com/ClipboardHealth/cbh-core/issues/183)) ([335e94b](https://github.com/ClipboardHealth/cbh-core/commit/335e94ba37eb969a5c325e012afa86188b3bce59))
|
|
119
|
-
|
|
120
|
-
## [0.6.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.6.0...util-ts-0.6.1) (2023-07-05)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Bug Fixes
|
|
124
|
-
|
|
125
|
-
* sonarcloud code smells, reduce duplication ([#182](https://github.com/ClipboardHealth/cbh-core/issues/182)) ([5fd9bb6](https://github.com/ClipboardHealth/cbh-core/commit/5fd9bb6c2f79033ac0adaa8168a24835e24abc8b))
|
|
126
|
-
|
|
127
|
-
## [0.6.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.9...util-ts-0.6.0) (2023-07-05)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
### Features
|
|
131
|
-
|
|
132
|
-
* add toError, toErrorMessage, stringify, and isString to util-ts ([#181](https://github.com/ClipboardHealth/cbh-core/issues/181)) ([149390a](https://github.com/ClipboardHealth/cbh-core/commit/149390ab5e35852accbcf38245eb69e25a1f5323))
|
|
133
|
-
|
|
134
|
-
## [0.5.9](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.8...util-ts-0.5.9) (2023-06-23)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
### Bug Fixes
|
|
138
|
-
|
|
139
|
-
* Prevent NX from modifying package.json ([#158](https://github.com/ClipboardHealth/cbh-core/issues/158)) ([9744a00](https://github.com/ClipboardHealth/cbh-core/commit/9744a0028942aa4cfb61646af9153ab1ef8594a2))
|
|
140
|
-
|
|
141
|
-
## [0.5.8](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.7...util-ts-0.5.8) (2023-06-01)
|
|
142
|
-
|
|
143
|
-
## [0.5.7](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.6...util-ts-0.5.7) (2023-05-25)
|
|
144
|
-
|
|
145
|
-
## [0.5.6](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.5...util-ts-0.5.6) (2023-05-24)
|
|
146
|
-
|
|
147
|
-
## [0.5.5](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.4...util-ts-0.5.5) (2023-05-19)
|
|
148
|
-
|
|
149
|
-
## [0.5.4](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.3...util-ts-0.5.4) (2023-05-17)
|
|
150
|
-
|
|
151
|
-
## [0.5.3](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.2...util-ts-0.5.3) (2023-05-16)
|
|
152
|
-
|
|
153
|
-
## [0.5.2](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.1...util-ts-0.5.2) (2023-05-15)
|
|
154
|
-
|
|
155
|
-
## [0.5.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.5.0...util-ts-0.5.1) (2023-05-14)
|
|
156
|
-
|
|
157
|
-
## [0.5.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.4.0...util-ts-0.5.0) (2023-05-09)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
### Features
|
|
161
|
-
|
|
162
|
-
* add TypeDoc ([#44](https://github.com/ClipboardHealth/cbh-core/issues/44)) ([fd3d1ba](https://github.com/ClipboardHealth/cbh-core/commit/fd3d1ba8f38ef61a47ff8163bd1b21e034016484))
|
|
163
|
-
|
|
164
|
-
## [0.4.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.3.4...util-ts-0.4.0) (2023-05-09)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
### Features
|
|
168
|
-
|
|
169
|
-
* allow `message-producer` clients to pass arbitrary message attributes ([#43](https://github.com/ClipboardHealth/cbh-core/issues/43)) ([2e94876](https://github.com/ClipboardHealth/cbh-core/commit/2e94876e286da9bcf08b0345bd36316538843178))
|
|
170
|
-
|
|
171
|
-
## [0.3.4](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.3.3...util-ts-0.3.4) (2023-04-28)
|
|
172
|
-
|
|
173
|
-
## [0.3.3](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.3.2...util-ts-0.3.3) (2023-04-26)
|
|
174
|
-
|
|
175
|
-
## [0.3.2](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.3.1...util-ts-0.3.2) (2023-04-26)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
### Bug Fixes
|
|
179
|
-
|
|
180
|
-
* allow empty array in ConsumeRequest ([2271707](https://github.com/ClipboardHealth/cbh-core/commit/22717070aa8b3ca7158adf6f26afef0b37212fb6))
|
|
181
|
-
|
|
182
|
-
## [0.3.1](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.3.0...util-ts-0.3.1) (2023-04-24)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
### Bug Fixes
|
|
186
|
-
|
|
187
|
-
* export types ([565f3a1](https://github.com/ClipboardHealth/cbh-core/commit/565f3a175c96836719a23c5597abec54eeb07362))
|
|
188
|
-
|
|
189
|
-
## [0.3.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.2.0...util-ts-0.3.0) (2023-04-24)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
### Features
|
|
193
|
-
|
|
194
|
-
* use XO ESLint config ([#26](https://github.com/ClipboardHealth/cbh-core/issues/26) ([ae385eb](https://github.com/ClipboardHealth/cbh-core/commit/ae385eb06d02a79f894e2f229731f2cf0aedffbd))
|
|
195
|
-
|
|
196
|
-
## [0.2.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.1.0...util-ts-0.2.0) (2023-04-24)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
### Features
|
|
200
|
-
|
|
201
|
-
* Add `MessageProducer` class ([#24](https://github.com/ClipboardHealth/cbh-core/issues/24)) ([6b9ca48](https://github.com/ClipboardHealth/cbh-core/commit/6b9ca4814a7e4e6e9dd876c3a74dc10f018b023b))
|
|
202
|
-
|
|
203
|
-
## 0.1.0 (2023-04-19)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
### Features
|
|
207
|
-
|
|
208
|
-
* **DEV-19:** implement `crypto-kms` lib ([#22](https://github.com/ClipboardHealth/cbh-core/issues/22)) ([79a19d3](https://github.com/ClipboardHealth/cbh-core/commit/79a19d30b340b39e792cb5bb7ee01fe178d6bd27))
|
package/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
package/src/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/attributes"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./lib/cbh-error"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./lib/cbh-response"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./lib/defined-utils"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./lib/force-cast"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./lib/head"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./lib/identity"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./lib/is-string"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./lib/non-empty-array"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./lib/null-to-undefined"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./lib/stringify"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./lib/to-error"), exports);
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,0DAAgC;AAChC,6DAAmC;AACnC,8DAAoC;AACpC,2DAAiC;AACjC,qDAA2B;AAC3B,yDAA+B;AAC/B,0DAAgC;AAChC,gEAAsC;AACtC,kEAAwC;AACxC,0DAAgC;AAChC,yDAA+B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/attributes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;AAEvF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC"}
|
package/src/lib/attributes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/attributes.ts"],"names":[],"mappings":""}
|
package/src/lib/cbh-error.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type OneOrNonEmptyArray } from "./non-empty-array";
|
|
2
|
-
declare const ERROR_STATUS_CODES: readonly [400, 401, 403, 404, 409, 422, 429, 500];
|
|
3
|
-
export type ErrorStatusCode = (typeof ERROR_STATUS_CODES)[number];
|
|
4
|
-
export interface CbhIssue {
|
|
5
|
-
cause?: Error;
|
|
6
|
-
id?: string;
|
|
7
|
-
message: string;
|
|
8
|
-
statusCode?: ErrorStatusCode;
|
|
9
|
-
}
|
|
10
|
-
export declare class CbhError extends Error {
|
|
11
|
-
readonly issues: CbhIssue[];
|
|
12
|
-
constructor(issues: OneOrNonEmptyArray<CbhIssue>);
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=cbh-error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cbh-error.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AAE7E,QAAA,MAAM,kBAAkB,mDAAoD,CAAC;AAC7E,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,MAAM,EAAE,QAAQ,EAAE,CAAC;gBAEvB,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC;CAUjD"}
|
package/src/lib/cbh-error.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CbhError = void 0;
|
|
4
|
-
const non_empty_array_1 = require("./non-empty-array");
|
|
5
|
-
const ERROR_STATUS_CODES = [400, 401, 403, 404, 409, 422, 429, 500];
|
|
6
|
-
class CbhError extends Error {
|
|
7
|
-
issues;
|
|
8
|
-
constructor(issues) {
|
|
9
|
-
const is = (0, non_empty_array_1.toNonEmptyArray)(issues);
|
|
10
|
-
const first = is[0];
|
|
11
|
-
super(first?.message, { cause: first?.cause });
|
|
12
|
-
// See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
|
|
13
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
14
|
-
this.issues = is;
|
|
15
|
-
this.name = "CbhError";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.CbhError = CbhError;
|
|
19
|
-
//# sourceMappingURL=cbh-error.js.map
|
package/src/lib/cbh-error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cbh-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":";;;AAAA,uDAA6E;AAE7E,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAU7E,MAAa,QAAS,SAAQ,KAAK;IACjB,MAAM,CAAa;IAEnC,YAAY,MAAoC;QAC9C,MAAM,EAAE,GAAG,IAAA,iCAAe,EAAC,MAAM,CAAC,CAAC;QACnC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACpB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/C,6FAA6F;QAC7F,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAbD,4BAaC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { CbhError, type CbhIssue } from "./cbh-error";
|
|
2
|
-
import type { OneOrNonEmptyArray } from "./non-empty-array";
|
|
3
|
-
export type CbhResponse<T> = {
|
|
4
|
-
success: true;
|
|
5
|
-
data: T;
|
|
6
|
-
} | {
|
|
7
|
-
success: false;
|
|
8
|
-
error: CbhError;
|
|
9
|
-
};
|
|
10
|
-
export declare function toErrorCbhResponse(issues: OneOrNonEmptyArray<CbhIssue>): {
|
|
11
|
-
success: false;
|
|
12
|
-
error: CbhError;
|
|
13
|
-
};
|
|
14
|
-
export declare function toSuccessCbhResponse<T>(data: T): {
|
|
15
|
-
success: true;
|
|
16
|
-
data: T;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=cbh-response.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cbh-response.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE9F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG;IACxE,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACjB,CAEA;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAE3E"}
|
package/src/lib/cbh-response.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toSuccessCbhResponse = exports.toErrorCbhResponse = void 0;
|
|
4
|
-
const cbh_error_1 = require("./cbh-error");
|
|
5
|
-
function toErrorCbhResponse(issues) {
|
|
6
|
-
return { success: false, error: new cbh_error_1.CbhError(issues) };
|
|
7
|
-
}
|
|
8
|
-
exports.toErrorCbhResponse = toErrorCbhResponse;
|
|
9
|
-
function toSuccessCbhResponse(data) {
|
|
10
|
-
return { success: true, data };
|
|
11
|
-
}
|
|
12
|
-
exports.toSuccessCbhResponse = toSuccessCbhResponse;
|
|
13
|
-
//# sourceMappingURL=cbh-response.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cbh-response.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-response.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAKtD,SAAgB,kBAAkB,CAAC,MAAoC;IAIrE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,oBAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;AACzD,CAAC;AALD,gDAKC;AAED,SAAgB,oBAAoB,CAAI,IAAO;IAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAFD,oDAEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defined-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/defined-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,KAAK,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,eAAe,GAAG,KAAK,IAAI,eAAe,CAEzF;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,eAAe,GAAG,KAAK,IAAI,CAAC,CAEnE"}
|
package/src/lib/defined-utils.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDefined = exports.isNullOrUndefined = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Checks whether a value is null or undefined. If it is not defined, the return type ensures type safety.
|
|
6
|
-
* @param value any value or null or undefined
|
|
7
|
-
* @returns true if `value` is null or undefined, false otherwise.
|
|
8
|
-
*/
|
|
9
|
-
function isNullOrUndefined(value) {
|
|
10
|
-
return value === null || value === undefined;
|
|
11
|
-
}
|
|
12
|
-
exports.isNullOrUndefined = isNullOrUndefined;
|
|
13
|
-
/**
|
|
14
|
-
* Checks whether a value is defined. If it is defined, the return type ensures type safety.
|
|
15
|
-
* @param value any value or null or undefined
|
|
16
|
-
* @returns true if `value` is defined (not null and not undefined), false otherwise.
|
|
17
|
-
*/
|
|
18
|
-
function isDefined(value) {
|
|
19
|
-
return !isNullOrUndefined(value);
|
|
20
|
-
}
|
|
21
|
-
exports.isDefined = isDefined;
|
|
22
|
-
//# sourceMappingURL=defined-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defined-utils.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/defined-utils.ts"],"names":[],"mappings":";;;AAOA;;;;GAIG;AACH,SAAgB,iBAAiB,CAAI,KAA0B;IAC7D,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC;AAFD,8CAEC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAI,KAA0B;IACrD,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAFD,8BAEC"}
|
package/src/lib/force-cast.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"force-cast.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAE9C"}
|
package/src/lib/force-cast.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.forceCast = void 0;
|
|
4
|
-
/** Force cast to the provided type. */
|
|
5
|
-
function forceCast(value) {
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
exports.forceCast = forceCast;
|
|
9
|
-
//# sourceMappingURL=force-cast.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"force-cast.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,SAAgB,SAAS,CAAI,KAAc;IACzC,OAAO,KAAU,CAAC;AACpB,CAAC;AAFD,8BAEC"}
|
package/src/lib/head.d.ts
DELETED
package/src/lib/head.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/head.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAEpC,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAE5D"}
|
package/src/lib/head.js
DELETED
package/src/lib/head.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"head.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/head.ts"],"names":[],"mappings":";;;AAEA,SAAgB,IAAI,CAAI,KAAqB;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC;AAC9D,CAAC;AAFD,oBAEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEvC"}
|
package/src/lib/identity.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.identity = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* A generic function that returns its input unchanged.
|
|
6
|
-
* This function is useful in various functional programming scenarios, such as:
|
|
7
|
-
* - Creating higher-order functions like map, filter, and reduce.
|
|
8
|
-
* - Composing functions by providing an "identity element" in function composition.
|
|
9
|
-
*
|
|
10
|
-
* @template T - The type of the input value.
|
|
11
|
-
* @param {T} value - The value to return unchanged.
|
|
12
|
-
* @returns {T} The input value, unchanged.
|
|
13
|
-
*/
|
|
14
|
-
function identity(value) {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
exports.identity = identity;
|
|
18
|
-
//# sourceMappingURL=identity.js.map
|
package/src/lib/identity.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/identity.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAI,KAAQ;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,4BAEC"}
|
package/src/lib/is-string.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-string.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/is-string.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD"}
|
package/src/lib/is-string.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isString = void 0;
|
|
4
|
-
function isString(value) {
|
|
5
|
-
return typeof value === "string" || value instanceof String;
|
|
6
|
-
}
|
|
7
|
-
exports.isString = isString;
|
|
8
|
-
//# sourceMappingURL=is-string.js.map
|
package/src/lib/is-string.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-string.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/is-string.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC;AAC9D,CAAC;AAFD,4BAEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"non-empty-array.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/non-empty-array.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAE3C,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAEzD,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAEjF"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toNonEmptyArray = void 0;
|
|
4
|
-
function toNonEmptyArray(value) {
|
|
5
|
-
return Array.isArray(value) ? value : [value];
|
|
6
|
-
}
|
|
7
|
-
exports.toNonEmptyArray = toNonEmptyArray;
|
|
8
|
-
//# sourceMappingURL=non-empty-array.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"non-empty-array.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/non-empty-array.ts"],"names":[],"mappings":";;;AAIA,SAAgB,eAAe,CAAI,KAA4B;IAC7D,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAFD,0CAEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"null-to-undefined.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/null-to-undefined.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wBAAsB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAE7F"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nullToUndefined = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Turns a null-returning promise into a promise returning undefined.
|
|
6
|
-
*
|
|
7
|
-
* Some of the database packages that we use return promises (Prisma)
|
|
8
|
-
* or promise-like objects (mongoose) that can resolve to null.
|
|
9
|
-
* This function is useful for getting rid of nulls which are banned by our linter rules.
|
|
10
|
-
*
|
|
11
|
-
* @param value A promise or a promise-like object.
|
|
12
|
-
*/
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
14
|
-
async function nullToUndefined(value) {
|
|
15
|
-
return (await value) ?? undefined;
|
|
16
|
-
}
|
|
17
|
-
exports.nullToUndefined = nullToUndefined;
|
|
18
|
-
//# sourceMappingURL=null-to-undefined.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"null-to-undefined.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/null-to-undefined.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,wDAAwD;AACjD,KAAK,UAAU,eAAe,CAAI,KAA4B;IACnE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC;AACpC,CAAC;AAFD,0CAEC"}
|
package/src/lib/stringify.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/stringify.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAIhD"}
|
package/src/lib/stringify.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringify = void 0;
|
|
4
|
-
function stringify(value) {
|
|
5
|
-
return JSON.stringify(value, (_, value) => typeof value === "bigint" ? String(value) : value);
|
|
6
|
-
}
|
|
7
|
-
exports.stringify = stringify;
|
|
8
|
-
//# sourceMappingURL=stringify.js.map
|
package/src/lib/stringify.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/stringify.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,KAAc,EAAE,EAAE,CACjD,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAClD,CAAC;AACJ,CAAC;AAJD,8BAIC"}
|
package/src/lib/to-error.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-error.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/to-error.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAEtD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQ7C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD"}
|
package/src/lib/to-error.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toErrorMessage = exports.toError = exports.isError = void 0;
|
|
4
|
-
const is_string_1 = require("./is-string");
|
|
5
|
-
const stringify_1 = require("./stringify");
|
|
6
|
-
function isError(error) {
|
|
7
|
-
return error instanceof Error;
|
|
8
|
-
}
|
|
9
|
-
exports.isError = isError;
|
|
10
|
-
function toError(error) {
|
|
11
|
-
if (isError(error))
|
|
12
|
-
return error;
|
|
13
|
-
try {
|
|
14
|
-
return new Error((0, is_string_1.isString)(error) ? error : (0, stringify_1.stringify)(error));
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return new Error(String(error));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.toError = toError;
|
|
21
|
-
function toErrorMessage(error) {
|
|
22
|
-
return toError(error).message;
|
|
23
|
-
}
|
|
24
|
-
exports.toErrorMessage = toErrorMessage;
|
|
25
|
-
//# sourceMappingURL=to-error.js.map
|
package/src/lib/to-error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/to-error.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,2CAAwC;AAExC,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,KAAK,CAAC;AAChC,CAAC;AAFD,0BAEC;AAED,SAAgB,OAAO,CAAC,KAAc;IACpC,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEjC,IAAI,CAAC;QACH,OAAO,IAAI,KAAK,CAAC,IAAA,oBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AARD,0BAQC;AAED,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChC,CAAC;AAFD,wCAEC"}
|