@duplojs/utils 1.4.43 → 1.4.45

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 (116) hide show
  1. package/dist/clean/constraint/base.d.ts +5 -5
  2. package/dist/clean/constraint/defaultConstraint/number.d.ts +3 -3
  3. package/dist/clean/constraint/defaultConstraint/string.d.ts +2 -2
  4. package/dist/clean/entity.cjs +10 -0
  5. package/dist/clean/entity.d.ts +15 -3
  6. package/dist/clean/entity.mjs +10 -0
  7. package/dist/clean/flag.d.ts +1 -1
  8. package/dist/clean/newType.d.ts +5 -5
  9. package/dist/clean/primitive/base.d.ts +10 -10
  10. package/dist/clean/repository.d.ts +1 -1
  11. package/dist/clean/useCase.d.ts +1 -1
  12. package/dist/common/hasKinds.d.ts +3 -3
  13. package/dist/common/hasSomeKinds.d.ts +3 -3
  14. package/dist/common/path/resolveFrom.d.ts +1 -1
  15. package/dist/common/types/maybeArray.d.ts +1 -1
  16. package/dist/dataParser/base.d.ts +2 -2
  17. package/dist/dataParser/baseExtended.d.ts +2 -2
  18. package/dist/dataParser/extended/empty.d.ts +1 -1
  19. package/dist/dataParser/parsers/empty.d.ts +1 -1
  20. package/dist/date/create.d.ts +1 -1
  21. package/dist/date/createTime.d.ts +1 -1
  22. package/dist/either/bool/base.cjs +6 -1
  23. package/dist/either/bool/base.d.ts +4 -0
  24. package/dist/either/bool/base.mjs +6 -2
  25. package/dist/either/bool/create.d.ts +6 -6
  26. package/dist/either/bool/falsy.cjs +9 -4
  27. package/dist/either/bool/falsy.d.ts +23 -15
  28. package/dist/either/bool/falsy.mjs +10 -6
  29. package/dist/either/bool/truthy.cjs +9 -4
  30. package/dist/either/bool/truthy.d.ts +23 -15
  31. package/dist/either/bool/truthy.mjs +10 -6
  32. package/dist/either/future/base.cjs +6 -1
  33. package/dist/either/future/base.d.ts +4 -0
  34. package/dist/either/future/base.mjs +6 -2
  35. package/dist/either/future/create.d.ts +8 -8
  36. package/dist/either/future/error.cjs +7 -2
  37. package/dist/either/future/error.d.ts +15 -7
  38. package/dist/either/future/error.mjs +8 -4
  39. package/dist/either/future/success.cjs +7 -2
  40. package/dist/either/future/success.d.ts +15 -7
  41. package/dist/either/future/success.mjs +8 -4
  42. package/dist/either/hasInformation.cjs +2 -2
  43. package/dist/either/hasInformation.d.ts +8 -8
  44. package/dist/either/hasInformation.mjs +3 -3
  45. package/dist/either/index.cjs +24 -0
  46. package/dist/either/index.mjs +23 -23
  47. package/dist/either/kind.cjs +6 -1
  48. package/dist/either/kind.d.ts +4 -0
  49. package/dist/either/kind.mjs +6 -2
  50. package/dist/either/left/create.cjs +7 -2
  51. package/dist/either/left/create.d.ts +14 -6
  52. package/dist/either/left/create.mjs +8 -4
  53. package/dist/either/left/error.cjs +7 -2
  54. package/dist/either/left/error.d.ts +14 -6
  55. package/dist/either/left/error.mjs +7 -3
  56. package/dist/either/left/fail.cjs +7 -2
  57. package/dist/either/left/fail.d.ts +14 -6
  58. package/dist/either/left/fail.mjs +7 -3
  59. package/dist/either/left/is.cjs +2 -2
  60. package/dist/either/left/is.d.ts +4 -4
  61. package/dist/either/left/is.mjs +4 -4
  62. package/dist/either/left/when.d.ts +4 -4
  63. package/dist/either/nullable/base.cjs +6 -1
  64. package/dist/either/nullable/base.d.ts +4 -0
  65. package/dist/either/nullable/base.mjs +6 -2
  66. package/dist/either/nullable/create.d.ts +5 -5
  67. package/dist/either/nullable/empty.cjs +9 -4
  68. package/dist/either/nullable/empty.d.ts +23 -15
  69. package/dist/either/nullable/empty.mjs +10 -6
  70. package/dist/either/nullable/filled.cjs +9 -4
  71. package/dist/either/nullable/filled.d.ts +22 -14
  72. package/dist/either/nullable/filled.mjs +10 -6
  73. package/dist/either/nullish/base.cjs +6 -1
  74. package/dist/either/nullish/base.d.ts +4 -0
  75. package/dist/either/nullish/base.mjs +6 -2
  76. package/dist/either/nullish/create.d.ts +5 -5
  77. package/dist/either/nullish/empty.cjs +9 -4
  78. package/dist/either/nullish/empty.d.ts +23 -15
  79. package/dist/either/nullish/empty.mjs +10 -6
  80. package/dist/either/nullish/filled.cjs +9 -4
  81. package/dist/either/nullish/filled.d.ts +23 -15
  82. package/dist/either/nullish/filled.mjs +10 -6
  83. package/dist/either/optional/base.cjs +6 -1
  84. package/dist/either/optional/base.d.ts +4 -0
  85. package/dist/either/optional/base.mjs +6 -2
  86. package/dist/either/optional/create.d.ts +5 -5
  87. package/dist/either/optional/empty.cjs +9 -4
  88. package/dist/either/optional/empty.d.ts +23 -15
  89. package/dist/either/optional/empty.mjs +10 -6
  90. package/dist/either/optional/filled.cjs +9 -4
  91. package/dist/either/optional/filled.d.ts +22 -14
  92. package/dist/either/optional/filled.mjs +10 -6
  93. package/dist/either/right/asyncGroup.d.ts +7 -7
  94. package/dist/either/right/asyncPipe.d.ts +33 -25
  95. package/dist/either/right/create.cjs +7 -2
  96. package/dist/either/right/create.d.ts +15 -7
  97. package/dist/either/right/create.mjs +8 -4
  98. package/dist/either/right/group.d.ts +8 -8
  99. package/dist/either/right/is.cjs +2 -2
  100. package/dist/either/right/is.d.ts +4 -4
  101. package/dist/either/right/is.mjs +4 -4
  102. package/dist/either/right/ok.cjs +7 -2
  103. package/dist/either/right/ok.d.ts +14 -6
  104. package/dist/either/right/ok.mjs +7 -3
  105. package/dist/either/right/pipe.d.ts +32 -24
  106. package/dist/either/right/success.cjs +7 -2
  107. package/dist/either/right/success.d.ts +14 -6
  108. package/dist/either/right/success.mjs +7 -3
  109. package/dist/either/right/when.d.ts +4 -4
  110. package/dist/either/safeCallback.cjs +14 -4
  111. package/dist/either/safeCallback.d.ts +33 -17
  112. package/dist/either/safeCallback.mjs +13 -5
  113. package/dist/either/whenHasInformation.cjs +1 -1
  114. package/dist/either/whenHasInformation.d.ts +7 -7
  115. package/dist/either/whenHasInformation.mjs +2 -2
  116. package/package.json +1 -1
@@ -1,21 +1,37 @@
1
1
  import type { Kind, EscapeVoid } from "../common";
2
- import { type EitherLeft } from "./left";
3
- import { type EitherRight } from "./right";
2
+ import { type Left } from "./left";
3
+ import { type Right } from "./right";
4
+ export declare const callbackErrorKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-error", unknown>>;
5
+ /**
6
+ * @deprecated use callbackErrorKind
7
+ */
4
8
  export declare const eitherCallbackErrorKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-error", unknown>>;
9
+ export declare const callbackSuccessKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-success", unknown>>;
10
+ /**
11
+ * @deprecated use callbackSuccessKind
12
+ */
5
13
  export declare const eitherCallbackSuccessKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsEither/callback-success", unknown>>;
6
- type _EitherCallbackError = (EitherLeft<"callback", unknown> & Kind<typeof eitherCallbackErrorKind.definition>);
7
- type _EitherCallbackSuccess<GenericValue extends unknown> = (EitherRight<"callback", GenericValue> & Kind<typeof eitherCallbackSuccessKind.definition>);
8
- export interface EitherCallbackError extends _EitherCallbackError {
14
+ type _CallbackError = (Left<"callback", unknown> & Kind<typeof callbackErrorKind.definition>);
15
+ type _CallbackSuccess<GenericValue extends unknown> = (Right<"callback", GenericValue> & Kind<typeof callbackSuccessKind.definition>);
16
+ export interface CallbackError extends _CallbackError {
9
17
  }
10
- export interface EitherCallbackSuccess<GenericValue extends unknown> extends _EitherCallbackSuccess<GenericValue> {
18
+ export interface CallbackSuccess<GenericValue extends unknown> extends _CallbackSuccess<GenericValue> {
11
19
  }
12
- export declare function callbackError(value: unknown): EitherCallbackError;
13
- export declare function callbackSuccess<GenericValue extends unknown>(value: GenericValue): EitherCallbackSuccess<GenericValue>;
14
- type Either = EitherRight | EitherLeft;
15
- type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput extends Either ? GenericOutput : GenericOutput extends EscapeVoid ? EitherCallbackSuccess<undefined> : EitherCallbackSuccess<GenericOutput>;
16
20
  /**
17
- * Runs a callback in a safe block. If the callback throws, the function returns a "callback" typed EitherLeft instead of propagating the exception.
18
- * If the callback returns an Either, it is returned as-is; otherwise the value is wrapped in an EitherRight.
21
+ * @deprecated use CallbackError
22
+ */
23
+ export type EitherCallbackError = CallbackError;
24
+ /**
25
+ * @deprecated use CallbackSuccess
26
+ */
27
+ export type EitherCallbackSuccess<GenericValue extends unknown> = CallbackSuccess<GenericValue>;
28
+ export declare function callbackError(value: unknown): CallbackError;
29
+ export declare function callbackSuccess<GenericValue extends unknown>(value: GenericValue): CallbackSuccess<GenericValue>;
30
+ type Either = Right | Left;
31
+ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput extends Either ? GenericOutput : GenericOutput extends EscapeVoid ? CallbackSuccess<undefined> : CallbackSuccess<GenericOutput>;
32
+ /**
33
+ * Runs a callback in a safe block. If the callback throws, the function returns a "callback" typed Left instead of propagating the exception.
34
+ * If the callback returns an Either, it is returned as-is; otherwise the value is wrapped in an Right.
19
35
  *
20
36
  * Signature: `safeCallback(theFunction)` → returns a value
21
37
  *
@@ -23,7 +39,7 @@ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput ex
23
39
  *
24
40
  * ```ts
25
41
  * const success = E.safeCallback(() => 42);
26
- * // E.EitherCallbackError | E.EitherCallbackSuccess<number>
42
+ * // E.CallbackError | E.CallbackSuccess<number>
27
43
  *
28
44
  * const failure = E.safeCallback(() => {
29
45
  * throw new Error("boom");
@@ -35,12 +51,12 @@ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput ex
35
51
  * () => E.left("example", "already"),
36
52
  * );
37
53
  *
38
- * const isEitherLeft = E.isLeft(eitherResult);
54
+ * const isLeft = E.isLeft(eitherResult);
39
55
  * ```
40
56
  *
41
57
  * @remarks
42
- * - Catches exceptions thrown by the callback and wraps them in an `EitherLeft<"callback">`
43
- * - Keeps an `EitherLeft` or `EitherRight` returned by the callback untouched
58
+ * - Catches exceptions thrown by the callback and wraps them in an `Left<"callback">`
59
+ * - Keeps an `Left` or `Right` returned by the callback untouched
44
60
  * - Useful for working in an unsafe environment (3rd party libraries, user code, etc.)
45
61
  *
46
62
  * @see https://utils.duplojs.dev/en/v1/api/either/safeCallback
@@ -48,5 +64,5 @@ type ComputeSafeCallbackResult<GenericOutput extends unknown> = GenericOutput ex
48
64
  * @namespace E
49
65
  *
50
66
  */
51
- export declare function safeCallback<GenericOutput extends unknown>(theFunction: () => GenericOutput): ComputeSafeCallbackResult<GenericOutput> | EitherCallbackError;
67
+ export declare function safeCallback<GenericOutput extends unknown>(theFunction: () => GenericOutput): ComputeSafeCallbackResult<GenericOutput> | CallbackError;
52
68
  export {};
@@ -4,13 +4,21 @@ import { right } from './right/create.mjs';
4
4
  import { isRight } from './right/is.mjs';
5
5
  import { isLeft } from './left/is.mjs';
6
6
 
7
- const eitherCallbackErrorKind = createEitherKind("callback-error");
8
- const eitherCallbackSuccessKind = createEitherKind("callback-success");
7
+ const callbackErrorKind = createEitherKind("callback-error");
8
+ /**
9
+ * @deprecated use callbackErrorKind
10
+ */
11
+ const eitherCallbackErrorKind = callbackErrorKind;
12
+ const callbackSuccessKind = createEitherKind("callback-success");
13
+ /**
14
+ * @deprecated use callbackSuccessKind
15
+ */
16
+ const eitherCallbackSuccessKind = callbackSuccessKind;
9
17
  function callbackError(value) {
10
- return eitherCallbackErrorKind.setTo(left("callback", value));
18
+ return callbackErrorKind.setTo(left("callback", value));
11
19
  }
12
20
  function callbackSuccess(value) {
13
- return eitherCallbackSuccessKind.setTo(right("callback", value));
21
+ return callbackSuccessKind.setTo(right("callback", value));
14
22
  }
15
23
  /**
16
24
  * {@include either/safeCallback/index.md}
@@ -28,4 +36,4 @@ function safeCallback(theFunction) {
28
36
  }
29
37
  }
30
38
 
31
- export { callbackError, callbackSuccess, eitherCallbackErrorKind, eitherCallbackSuccessKind, safeCallback };
39
+ export { callbackError, callbackErrorKind, callbackSuccess, callbackSuccessKind, eitherCallbackErrorKind, eitherCallbackSuccessKind, safeCallback };
@@ -15,7 +15,7 @@ function whenHasInformation(...args) {
15
15
  ? information
16
16
  : [information];
17
17
  if ((is.isLeft(input)
18
- || is$1.isRight(input)) && formattedInformation.includes(kind.eitherInformationKind.getValue(input))) {
18
+ || is$1.isRight(input)) && formattedInformation.includes(kind.informationKind.getValue(input))) {
19
19
  return theFunction(unwrap.unwrap(input));
20
20
  }
21
21
  return input;
@@ -1,8 +1,8 @@
1
1
  import { type Kind, type WrappedValue, type AnyValue, type Unwrap, type BreakGenericLink } from "../common";
2
- import { type EitherRight } from "./right";
3
- import { type EitherLeft } from "./left";
4
- import { eitherInformationKind } from "./kind";
5
- type Either = EitherRight | EitherLeft;
2
+ import { type Right } from "./right";
3
+ import { type Left } from "./left";
4
+ import { informationKind } from "./kind";
5
+ type Either = Right | Left;
6
6
  /**
7
7
  * Functional pattern matching based on the literal information of an Either. The function is executed only when the information (or one of the informations) matches.
8
8
  *
@@ -31,7 +31,7 @@ type Either = EitherRight | EitherLeft;
31
31
  * }),
32
32
  * );
33
33
  *
34
- * // type: 1 | 2 | E.EitherLeft<"left-3", 3>
34
+ * // type: 1 | 2 | E.Left<"left-3", 3>
35
35
  * ```
36
36
  *
37
37
  * @see https://utils.duplojs.dev/en/v1/api/either/whenHasInformation
@@ -39,6 +39,6 @@ type Either = EitherRight | EitherLeft;
39
39
  * @namespace E
40
40
  *
41
41
  */
42
- export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof eitherInformationKind.getValue<GenericInput>> : never), const GenericOutput extends AnyValue>(information: GenericInformation | GenericInformation[], theFunction: (value: Unwrap<Extract<BreakGenericLink<GenericInput>, Kind<typeof eitherInformationKind.definition, GenericInformation> & WrappedValue>>) => GenericOutput): (input: GenericInput) => GenericOutput | Exclude<BreakGenericLink<GenericInput>, Kind<typeof eitherInformationKind.definition, GenericInformation>>;
43
- export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof eitherInformationKind.getValue<GenericInput>> : never), const GenericOutput extends AnyValue>(input: GenericInput, information: GenericInformation | GenericInformation[], theFunction: (value: Unwrap<Extract<BreakGenericLink<GenericInput>, Kind<typeof eitherInformationKind.definition, GenericInformation> & WrappedValue>>) => GenericOutput): GenericOutput | Exclude<GenericInput, Kind<typeof eitherInformationKind.definition, GenericInformation>>;
42
+ export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof informationKind.getValue<GenericInput>> : never), const GenericOutput extends AnyValue>(information: GenericInformation | GenericInformation[], theFunction: (value: Unwrap<Extract<BreakGenericLink<GenericInput>, Kind<typeof informationKind.definition, GenericInformation> & WrappedValue>>) => GenericOutput): (input: GenericInput) => GenericOutput | Exclude<BreakGenericLink<GenericInput>, Kind<typeof informationKind.definition, GenericInformation>>;
43
+ export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof informationKind.getValue<GenericInput>> : never), const GenericOutput extends AnyValue>(input: GenericInput, information: GenericInformation | GenericInformation[], theFunction: (value: Unwrap<Extract<BreakGenericLink<GenericInput>, Kind<typeof informationKind.definition, GenericInformation> & WrappedValue>>) => GenericOutput): GenericOutput | Exclude<GenericInput, Kind<typeof informationKind.definition, GenericInformation>>;
44
44
  export {};
@@ -1,4 +1,4 @@
1
- import { eitherInformationKind } from './kind.mjs';
1
+ import { informationKind } from './kind.mjs';
2
2
  import { isLeft } from './left/is.mjs';
3
3
  import { isRight } from './right/is.mjs';
4
4
  import { unwrap } from '../common/unwrap.mjs';
@@ -13,7 +13,7 @@ function whenHasInformation(...args) {
13
13
  ? information
14
14
  : [information];
15
15
  if ((isLeft(input)
16
- || isRight(input)) && formattedInformation.includes(eitherInformationKind.getValue(input))) {
16
+ || isRight(input)) && formattedInformation.includes(informationKind.getValue(input))) {
17
17
  return theFunction(unwrap(input));
18
18
  }
19
19
  return input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.4.43",
3
+ "version": "1.4.45",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"