@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.
- package/dist/clean/constraint/base.d.ts +5 -5
- package/dist/clean/constraint/defaultConstraint/number.d.ts +3 -3
- package/dist/clean/constraint/defaultConstraint/string.d.ts +2 -2
- package/dist/clean/entity.cjs +10 -0
- package/dist/clean/entity.d.ts +15 -3
- package/dist/clean/entity.mjs +10 -0
- package/dist/clean/flag.d.ts +1 -1
- package/dist/clean/newType.d.ts +5 -5
- package/dist/clean/primitive/base.d.ts +10 -10
- package/dist/clean/repository.d.ts +1 -1
- package/dist/clean/useCase.d.ts +1 -1
- package/dist/common/hasKinds.d.ts +3 -3
- package/dist/common/hasSomeKinds.d.ts +3 -3
- package/dist/common/path/resolveFrom.d.ts +1 -1
- package/dist/common/types/maybeArray.d.ts +1 -1
- package/dist/dataParser/base.d.ts +2 -2
- package/dist/dataParser/baseExtended.d.ts +2 -2
- package/dist/dataParser/extended/empty.d.ts +1 -1
- package/dist/dataParser/parsers/empty.d.ts +1 -1
- package/dist/date/create.d.ts +1 -1
- package/dist/date/createTime.d.ts +1 -1
- package/dist/either/bool/base.cjs +6 -1
- package/dist/either/bool/base.d.ts +4 -0
- package/dist/either/bool/base.mjs +6 -2
- package/dist/either/bool/create.d.ts +6 -6
- package/dist/either/bool/falsy.cjs +9 -4
- package/dist/either/bool/falsy.d.ts +23 -15
- package/dist/either/bool/falsy.mjs +10 -6
- package/dist/either/bool/truthy.cjs +9 -4
- package/dist/either/bool/truthy.d.ts +23 -15
- package/dist/either/bool/truthy.mjs +10 -6
- package/dist/either/future/base.cjs +6 -1
- package/dist/either/future/base.d.ts +4 -0
- package/dist/either/future/base.mjs +6 -2
- package/dist/either/future/create.d.ts +8 -8
- package/dist/either/future/error.cjs +7 -2
- package/dist/either/future/error.d.ts +15 -7
- package/dist/either/future/error.mjs +8 -4
- package/dist/either/future/success.cjs +7 -2
- package/dist/either/future/success.d.ts +15 -7
- package/dist/either/future/success.mjs +8 -4
- package/dist/either/hasInformation.cjs +2 -2
- package/dist/either/hasInformation.d.ts +8 -8
- package/dist/either/hasInformation.mjs +3 -3
- package/dist/either/index.cjs +24 -0
- package/dist/either/index.mjs +23 -23
- package/dist/either/kind.cjs +6 -1
- package/dist/either/kind.d.ts +4 -0
- package/dist/either/kind.mjs +6 -2
- package/dist/either/left/create.cjs +7 -2
- package/dist/either/left/create.d.ts +14 -6
- package/dist/either/left/create.mjs +8 -4
- package/dist/either/left/error.cjs +7 -2
- package/dist/either/left/error.d.ts +14 -6
- package/dist/either/left/error.mjs +7 -3
- package/dist/either/left/fail.cjs +7 -2
- package/dist/either/left/fail.d.ts +14 -6
- package/dist/either/left/fail.mjs +7 -3
- package/dist/either/left/is.cjs +2 -2
- package/dist/either/left/is.d.ts +4 -4
- package/dist/either/left/is.mjs +4 -4
- package/dist/either/left/when.d.ts +4 -4
- package/dist/either/nullable/base.cjs +6 -1
- package/dist/either/nullable/base.d.ts +4 -0
- package/dist/either/nullable/base.mjs +6 -2
- package/dist/either/nullable/create.d.ts +5 -5
- package/dist/either/nullable/empty.cjs +9 -4
- package/dist/either/nullable/empty.d.ts +23 -15
- package/dist/either/nullable/empty.mjs +10 -6
- package/dist/either/nullable/filled.cjs +9 -4
- package/dist/either/nullable/filled.d.ts +22 -14
- package/dist/either/nullable/filled.mjs +10 -6
- package/dist/either/nullish/base.cjs +6 -1
- package/dist/either/nullish/base.d.ts +4 -0
- package/dist/either/nullish/base.mjs +6 -2
- package/dist/either/nullish/create.d.ts +5 -5
- package/dist/either/nullish/empty.cjs +9 -4
- package/dist/either/nullish/empty.d.ts +23 -15
- package/dist/either/nullish/empty.mjs +10 -6
- package/dist/either/nullish/filled.cjs +9 -4
- package/dist/either/nullish/filled.d.ts +23 -15
- package/dist/either/nullish/filled.mjs +10 -6
- package/dist/either/optional/base.cjs +6 -1
- package/dist/either/optional/base.d.ts +4 -0
- package/dist/either/optional/base.mjs +6 -2
- package/dist/either/optional/create.d.ts +5 -5
- package/dist/either/optional/empty.cjs +9 -4
- package/dist/either/optional/empty.d.ts +23 -15
- package/dist/either/optional/empty.mjs +10 -6
- package/dist/either/optional/filled.cjs +9 -4
- package/dist/either/optional/filled.d.ts +22 -14
- package/dist/either/optional/filled.mjs +10 -6
- package/dist/either/right/asyncGroup.d.ts +7 -7
- package/dist/either/right/asyncPipe.d.ts +33 -25
- package/dist/either/right/create.cjs +7 -2
- package/dist/either/right/create.d.ts +15 -7
- package/dist/either/right/create.mjs +8 -4
- package/dist/either/right/group.d.ts +8 -8
- package/dist/either/right/is.cjs +2 -2
- package/dist/either/right/is.d.ts +4 -4
- package/dist/either/right/is.mjs +4 -4
- package/dist/either/right/ok.cjs +7 -2
- package/dist/either/right/ok.d.ts +14 -6
- package/dist/either/right/ok.mjs +7 -3
- package/dist/either/right/pipe.d.ts +32 -24
- package/dist/either/right/success.cjs +7 -2
- package/dist/either/right/success.d.ts +14 -6
- package/dist/either/right/success.mjs +7 -3
- package/dist/either/right/when.d.ts +4 -4
- package/dist/either/safeCallback.cjs +14 -4
- package/dist/either/safeCallback.d.ts +33 -17
- package/dist/either/safeCallback.mjs +13 -5
- package/dist/either/whenHasInformation.cjs +1 -1
- package/dist/either/whenHasInformation.d.ts +7 -7
- package/dist/either/whenHasInformation.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import type { Kind, EscapeVoid } from "../common";
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
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
|
|
7
|
-
type
|
|
8
|
-
export interface
|
|
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
|
|
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
|
-
*
|
|
18
|
-
|
|
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.
|
|
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
|
|
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 `
|
|
43
|
-
* - Keeps an `
|
|
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> |
|
|
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
|
|
8
|
-
|
|
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
|
|
18
|
+
return callbackErrorKind.setTo(left("callback", value));
|
|
11
19
|
}
|
|
12
20
|
function callbackSuccess(value) {
|
|
13
|
-
return
|
|
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.
|
|
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
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
type Either =
|
|
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.
|
|
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
|
|
43
|
-
export declare function whenHasInformation<const GenericInput extends unknown, GenericInformation extends (GenericInput extends Either ? ReturnType<typeof
|
|
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 {
|
|
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(
|
|
16
|
+
|| isRight(input)) && formattedInformation.includes(informationKind.getValue(input))) {
|
|
17
17
|
return theFunction(unwrap(input));
|
|
18
18
|
}
|
|
19
19
|
return input;
|