@clipboard-health/util-ts 2.2.8 → 2.4.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.
Files changed (41) hide show
  1. package/package.json +1 -1
  2. package/src/lib/cbh-error.d.ts +7 -2
  3. package/src/lib/cbh-error.d.ts.map +1 -1
  4. package/src/lib/cbh-error.js +13 -5
  5. package/src/lib/cbh-error.js.map +1 -1
  6. package/src/lib/defined-utils.d.ts +0 -8
  7. package/src/lib/defined-utils.d.ts.map +1 -1
  8. package/src/lib/defined-utils.js +0 -4
  9. package/src/lib/defined-utils.js.map +1 -1
  10. package/src/lib/delay.d.ts +3 -0
  11. package/src/lib/delay.d.ts.map +1 -1
  12. package/src/lib/delay.js +3 -0
  13. package/src/lib/delay.js.map +1 -1
  14. package/src/lib/force-cast.d.ts +3 -1
  15. package/src/lib/force-cast.d.ts.map +1 -1
  16. package/src/lib/force-cast.js +3 -1
  17. package/src/lib/force-cast.js.map +1 -1
  18. package/src/lib/head.d.ts +6 -0
  19. package/src/lib/head.d.ts.map +1 -1
  20. package/src/lib/head.js +3 -0
  21. package/src/lib/head.js.map +1 -1
  22. package/src/lib/identity.d.ts +1 -6
  23. package/src/lib/identity.d.ts.map +1 -1
  24. package/src/lib/identity.js +1 -6
  25. package/src/lib/identity.js.map +1 -1
  26. package/src/lib/non-empty-array.d.ts +9 -0
  27. package/src/lib/non-empty-array.d.ts.map +1 -1
  28. package/src/lib/non-empty-array.js +3 -0
  29. package/src/lib/non-empty-array.js.map +1 -1
  30. package/src/lib/null-to-undefined.d.ts +2 -5
  31. package/src/lib/null-to-undefined.d.ts.map +1 -1
  32. package/src/lib/null-to-undefined.js +2 -5
  33. package/src/lib/null-to-undefined.js.map +1 -1
  34. package/src/lib/stringify.d.ts +3 -0
  35. package/src/lib/stringify.d.ts.map +1 -1
  36. package/src/lib/stringify.js +3 -0
  37. package/src/lib/stringify.js.map +1 -1
  38. package/src/lib/to-error.d.ts +9 -0
  39. package/src/lib/to-error.d.ts.map +1 -1
  40. package/src/lib/to-error.js +9 -0
  41. package/src/lib/to-error.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipboard-health/util-ts",
3
- "version": "2.2.8",
3
+ "version": "2.4.0",
4
4
  "main": "./src/index.js",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
@@ -1,4 +1,9 @@
1
- import { type OneOrNonEmptyArray } from "./non-empty-array";
1
+ import { type OneOrArray } from "./head";
2
+ /**
3
+ * Error status codes in our service APIs.
4
+ *
5
+ * @see {@link https://www.notion.so/BP-REST-API-f769b7fe745c4cf38f6eca2e9ad8a843?pvs=4#e0b4e9ea30f041409ce39505650098ea}
6
+ */
2
7
  declare const ERROR_STATUS_CODES: readonly [400, 401, 403, 404, 409, 422, 429, 500];
3
8
  export type ErrorStatusCode = (typeof ERROR_STATUS_CODES)[number];
4
9
  export interface CbhIssue {
@@ -9,7 +14,7 @@ export interface CbhIssue {
9
14
  }
10
15
  export declare class CbhError extends Error {
11
16
  readonly issues: CbhIssue[];
12
- constructor(issues: OneOrNonEmptyArray<CbhIssue>);
17
+ constructor(messageOrIssues: OneOrArray<CbhIssue> | string);
13
18
  }
14
19
  export {};
15
20
  //# sourceMappingURL=cbh-error.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"cbh-error.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,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,eAAe,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,MAAM;CAgB3D"}
@@ -1,14 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CbhError = void 0;
4
- const non_empty_array_1 = require("./non-empty-array");
4
+ /**
5
+ * Error status codes in our service APIs.
6
+ *
7
+ * @see {@link https://www.notion.so/BP-REST-API-f769b7fe745c4cf38f6eca2e9ad8a843?pvs=4#e0b4e9ea30f041409ce39505650098ea}
8
+ */
5
9
  const ERROR_STATUS_CODES = [400, 401, 403, 404, 409, 422, 429, 500];
6
10
  class CbhError extends Error {
7
11
  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
+ constructor(messageOrIssues) {
13
+ const is = typeof messageOrIssues === "string"
14
+ ? [{ message: messageOrIssues }]
15
+ : Array.isArray(messageOrIssues)
16
+ ? messageOrIssues
17
+ : [messageOrIssues];
18
+ const first = is[0] ?? { message: "Unknown error" };
19
+ super(first?.message, { cause: "cause" in first ? first.cause : undefined });
12
20
  // See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
13
21
  Object.setPrototypeOf(this, new.target.prototype);
14
22
  this.issues = is;
@@ -1 +1 @@
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
+ {"version":3,"file":"cbh-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,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,eAA8C;QACxD,MAAM,EAAE,GACN,OAAO,eAAe,KAAK,QAAQ;YACjC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;YAChC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;gBAC9B,CAAC,CAAC,eAAe;gBACjB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;QAE1B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;QACpD,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7E,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;AAnBD,4BAmBC"}
@@ -1,18 +1,10 @@
1
- /**
2
- * We specifically want to guard against both `null` and `undefined`
3
- * In this one case, we need to define `null` as an expected argument type.
4
- */
5
1
  type NullOrUndefined = null | undefined;
6
2
  /**
7
3
  * Checks whether a value is null or undefined. If it is not defined, the return type ensures type safety.
8
- * @param value any value or null or undefined
9
- * @returns true if `value` is null or undefined, false otherwise.
10
4
  */
11
5
  export declare function isNullOrUndefined<T>(value: T | NullOrUndefined): value is NullOrUndefined;
12
6
  /**
13
7
  * Checks whether a value is defined. If it is defined, the return type ensures type safety.
14
- * @param value any value or null or undefined
15
- * @returns true if `value` is defined (not null and not undefined), false otherwise.
16
8
  */
17
9
  export declare function isDefined<T>(value: T | NullOrUndefined): value is T;
18
10
  export {};
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"defined-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/defined-utils.ts"],"names":[],"mappings":"AACA,KAAK,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;AAExC;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,eAAe,GAAG,KAAK,IAAI,eAAe,CAEzF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,eAAe,GAAG,KAAK,IAAI,CAAC,CAEnE"}
@@ -4,16 +4,12 @@ exports.isNullOrUndefined = isNullOrUndefined;
4
4
  exports.isDefined = isDefined;
5
5
  /**
6
6
  * Checks whether a value is null or undefined. If it is not defined, the return type ensures type safety.
7
- * @param value any value or null or undefined
8
- * @returns true if `value` is null or undefined, false otherwise.
9
7
  */
10
8
  function isNullOrUndefined(value) {
11
9
  return value === null || value === undefined;
12
10
  }
13
11
  /**
14
12
  * 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
13
  */
18
14
  function isDefined(value) {
19
15
  return !isNullOrUndefined(value);
@@ -1 +1 @@
1
- {"version":3,"file":"defined-utils.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/defined-utils.ts"],"names":[],"mappings":";;AAYA,8CAEC;AAOD,8BAEC;AAhBD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAI,KAA0B;IAC7D,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAI,KAA0B;IACrD,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
1
+ {"version":3,"file":"defined-utils.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/defined-utils.ts"],"names":[],"mappings":";;AAMA,8CAEC;AAKD,8BAEC;AAZD;;GAEG;AACH,SAAgB,iBAAiB,CAAI,KAA0B;IAC7D,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAI,KAA0B;IACrD,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Non-blocking delay by the specified number of milliseconds.
3
+ */
1
4
  export declare function delay(milliseconds: number): Promise<void>;
2
5
  //# sourceMappingURL=delay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/delay.ts"],"names":[],"mappings":"AAAA,wBAAsB,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/D"}
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/delay.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAsB,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/D"}
package/src/lib/delay.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.delay = delay;
4
+ /**
5
+ * Non-blocking delay by the specified number of milliseconds.
6
+ */
4
7
  async function delay(milliseconds) {
5
8
  await new Promise((resolve) => {
6
9
  setTimeout(resolve, milliseconds);
@@ -1 +1 @@
1
- {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/delay.ts"],"names":[],"mappings":";;AAAA,sBAIC;AAJM,KAAK,UAAU,KAAK,CAAC,YAAoB;IAC9C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/delay.ts"],"names":[],"mappings":";;AAGA,sBAIC;AAPD;;GAEG;AACI,KAAK,UAAU,KAAK,CAAC,YAAoB;IAC9C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,3 +1,5 @@
1
- /** Force cast to the provided type. */
1
+ /**
2
+ * Force cast to the provided type.
3
+ */
2
4
  export declare function forceCast<T>(value: unknown): T;
3
5
  //# sourceMappingURL=force-cast.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"force-cast.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAE9C"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.forceCast = forceCast;
4
- /** Force cast to the provided type. */
4
+ /**
5
+ * Force cast to the provided type.
6
+ */
5
7
  function forceCast(value) {
6
8
  return value;
7
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"force-cast.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":";;AACA,8BAEC;AAHD,uCAAuC;AACvC,SAAgB,SAAS,CAAI,KAAc;IACzC,OAAO,KAAU,CAAC;AACpB,CAAC"}
1
+ {"version":3,"file":"force-cast.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":";;AAGA,8BAEC;AALD;;GAEG;AACH,SAAgB,SAAS,CAAI,KAAc;IACzC,OAAO,KAAU,CAAC;AACpB,CAAC"}
package/src/lib/head.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Either a single value or an array of values.
3
+ */
1
4
  export type OneOrArray<T> = T | T[];
5
+ /**
6
+ * If the provided value is an array, returns the first element. Otherwise, returns the value itself.
7
+ */
2
8
  export declare function head<T>(value?: OneOrArray<T>): T | undefined;
3
9
  //# sourceMappingURL=head.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/head.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAEpC;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAE5D"}
package/src/lib/head.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.head = head;
4
+ /**
5
+ * If the provided value is an array, returns the first element. Otherwise, returns the value itself.
6
+ */
4
7
  function head(value) {
5
8
  return Array.isArray(value) ? value[0] : (value ?? undefined);
6
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"head.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/head.ts"],"names":[],"mappings":";;AAEA,oBAEC;AAFD,SAAgB,IAAI,CAAI,KAAqB;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC;AAChE,CAAC"}
1
+ {"version":3,"file":"head.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/head.ts"],"names":[],"mappings":";;AAQA,oBAEC;AALD;;GAEG;AACH,SAAgB,IAAI,CAAI,KAAqB;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC;AAChE,CAAC"}
@@ -1,12 +1,7 @@
1
1
  /**
2
- * A generic function that returns its input unchanged.
3
- * This function is useful in various functional programming scenarios, such as:
2
+ * Returns value unchanged, useful in functional programming scenarios such as:
4
3
  * - Creating higher-order functions like map, filter, and reduce.
5
4
  * - Composing functions by providing an "identity element" in function composition.
6
- *
7
- * @template T - The type of the input value.
8
- * @param {T} value - The value to return unchanged.
9
- * @returns {T} The input value, unchanged.
10
5
  */
11
6
  export declare function identity<T>(value: T): T;
12
7
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/identity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEvC"}
@@ -2,14 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.identity = identity;
4
4
  /**
5
- * A generic function that returns its input unchanged.
6
- * This function is useful in various functional programming scenarios, such as:
5
+ * Returns value unchanged, useful in functional programming scenarios such as:
7
6
  * - Creating higher-order functions like map, filter, and reduce.
8
7
  * - 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
8
  */
14
9
  function identity(value) {
15
10
  return value;
@@ -1 +1 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/identity.ts"],"names":[],"mappings":";;AAUA,4BAEC;AAZD;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAI,KAAQ;IAClC,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/identity.ts"],"names":[],"mappings":";;AAKA,4BAEC;AAPD;;;;GAIG;AACH,SAAgB,QAAQ,CAAI,KAAQ;IAClC,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,4 +1,13 @@
1
+ /**
2
+ * @deprecated Use standard Array<T> instead.
3
+ */
1
4
  export type NonEmptyArray<T> = [T, ...T[]];
5
+ /**
6
+ * @deprecated Use @{link OneOrArray} instead.
7
+ */
2
8
  export type OneOrNonEmptyArray<T> = T | NonEmptyArray<T>;
9
+ /**
10
+ * @deprecated Use standard Array<T> instead.
11
+ */
3
12
  export declare function toNonEmptyArray<T>(value: OneOrNonEmptyArray<T>): NonEmptyArray<T>;
4
13
  //# sourceMappingURL=non-empty-array.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"non-empty-array.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/non-empty-array.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAEzD;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAEjF"}
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toNonEmptyArray = toNonEmptyArray;
4
+ /**
5
+ * @deprecated Use standard Array<T> instead.
6
+ */
4
7
  function toNonEmptyArray(value) {
5
8
  return Array.isArray(value) ? value : [value];
6
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"non-empty-array.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/non-empty-array.ts"],"names":[],"mappings":";;AAIA,0CAEC;AAFD,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"}
1
+ {"version":3,"file":"non-empty-array.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/non-empty-array.ts"],"names":[],"mappings":";;AAaA,0CAEC;AALD;;GAEG;AACH,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"}
@@ -1,11 +1,8 @@
1
1
  /**
2
2
  * Turns a null-returning promise into a promise returning undefined.
3
3
  *
4
- * Some of the database packages that we use return promises (Prisma)
5
- * or promise-like objects (mongoose) that can resolve to null.
6
- * This function is useful for getting rid of nulls which are banned by our linter rules.
7
- *
8
- * @param value A promise or a promise-like object.
4
+ * Some libraries we use return promises or promise-like objects that can resolve to null. This
5
+ * function converts them to undefined.
9
6
  */
10
7
  export declare function nullToUndefined<T>(value: PromiseLike<T | null>): Promise<T | undefined>;
11
8
  //# sourceMappingURL=null-to-undefined.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"null-to-undefined.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/null-to-undefined.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAsB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAE7F"}
@@ -4,11 +4,8 @@ exports.nullToUndefined = nullToUndefined;
4
4
  /**
5
5
  * Turns a null-returning promise into a promise returning undefined.
6
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.
7
+ * Some libraries we use return promises or promise-like objects that can resolve to null. This
8
+ * function converts them to undefined.
12
9
  */
13
10
  // eslint-disable-next-line @typescript-eslint/ban-types
14
11
  async function nullToUndefined(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"null-to-undefined.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/null-to-undefined.ts"],"names":[],"mappings":";;AAUA,0CAEC;AAZD;;;;;;;;GAQG;AACH,wDAAwD;AACjD,KAAK,UAAU,eAAe,CAAI,KAA4B;IACnE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC;AACpC,CAAC"}
1
+ {"version":3,"file":"null-to-undefined.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/null-to-undefined.ts"],"names":[],"mappings":";;AAOA,0CAEC;AATD;;;;;GAKG;AACH,wDAAwD;AACjD,KAAK,UAAU,eAAe,CAAI,KAA4B;IACnE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC;AACpC,CAAC"}
@@ -1,2 +1,5 @@
1
+ /**
2
+ * BigInt-safe convertion of values to strings.
3
+ */
1
4
  export declare function stringify(value: unknown): string;
2
5
  //# sourceMappingURL=stringify.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/stringify.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAIhD"}
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringify = stringify;
4
+ /**
5
+ * BigInt-safe convertion of values to strings.
6
+ */
4
7
  function stringify(value) {
5
8
  return JSON.stringify(value, (_, value) => typeof value === "bigint" ? String(value) : value);
6
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/stringify.ts"],"names":[],"mappings":";;AAAA,8BAIC;AAJD,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"}
1
+ {"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/stringify.ts"],"names":[],"mappings":";;AAGA,8BAIC;AAPD;;GAEG;AACH,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"}
@@ -1,4 +1,13 @@
1
+ /**
2
+ * Type guard for `Error` instances.
3
+ */
1
4
  export declare function isError(error: unknown): error is Error;
5
+ /**
6
+ * Convert the provided value to an `Error` instance.
7
+ */
2
8
  export declare function toError(error: unknown): Error;
9
+ /**
10
+ * Converts unknown values error messages. If the value is not an error, it is converted to a string.
11
+ */
3
12
  export declare function toErrorMessage(error: unknown): string;
4
13
  //# sourceMappingURL=to-error.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"to-error.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/to-error.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAEtD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQ7C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD"}
@@ -5,9 +5,15 @@ exports.toError = toError;
5
5
  exports.toErrorMessage = toErrorMessage;
6
6
  const is_string_1 = require("./is-string");
7
7
  const stringify_1 = require("./stringify");
8
+ /**
9
+ * Type guard for `Error` instances.
10
+ */
8
11
  function isError(error) {
9
12
  return error instanceof Error;
10
13
  }
14
+ /**
15
+ * Convert the provided value to an `Error` instance.
16
+ */
11
17
  function toError(error) {
12
18
  if (isError(error))
13
19
  return error;
@@ -18,6 +24,9 @@ function toError(error) {
18
24
  return new Error(String(error));
19
25
  }
20
26
  }
27
+ /**
28
+ * Converts unknown values error messages. If the value is not an error, it is converted to a string.
29
+ */
21
30
  function toErrorMessage(error) {
22
31
  return toError(error).message;
23
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"to-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/to-error.ts"],"names":[],"mappings":";;AAGA,0BAEC;AAED,0BAQC;AAED,wCAEC;AAnBD,2CAAuC;AACvC,2CAAwC;AAExC,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,KAAK,CAAC;AAChC,CAAC;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;AAED,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChC,CAAC"}
1
+ {"version":3,"file":"to-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/to-error.ts"],"names":[],"mappings":";;AAMA,0BAEC;AAKD,0BAQC;AAKD,wCAEC;AA5BD,2CAAuC;AACvC,2CAAwC;AAExC;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,KAAK,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,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;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChC,CAAC"}