@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
|
@@ -30,13 +30,13 @@ export interface ConstraintHandler<GenericName extends string = string, GenericP
|
|
|
30
30
|
* const result = Between1And10.create(5);
|
|
31
31
|
*
|
|
32
32
|
* if (E.isRight(result)) {
|
|
33
|
-
* // result : E.
|
|
33
|
+
* // result : E.Right<"createConstrainedType", C.ConstrainedType<"between-1-10", 5>>
|
|
34
34
|
* }
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
|
-
create<GenericData extends GenericPrimitiveValue>(data: GenericData): (DEither.
|
|
39
|
-
create<GenericPrimitive extends Primitive<GenericPrimitiveValue>>(data: GenericPrimitive): (DEither.
|
|
38
|
+
create<GenericData extends GenericPrimitiveValue>(data: GenericData): (DEither.Right<"createConstrainedType", ConstrainedType<GenericName, GenericData>> | DEither.Left<"createConstrainedTypeError", DDataParser.DataParserError>);
|
|
39
|
+
create<GenericPrimitive extends Primitive<GenericPrimitiveValue>>(data: GenericPrimitive): (DEither.Right<"createConstrainedType", (GenericPrimitive & ConstrainedType<GenericName, Unwrap<GenericPrimitive>>)> | DEither.Left<"createConstrainedTypeError", DDataParser.DataParserError>);
|
|
40
40
|
/**
|
|
41
41
|
* Creates a constrained value and throws on error.
|
|
42
42
|
*
|
|
@@ -57,7 +57,7 @@ export interface ConstraintHandler<GenericName extends string = string, GenericP
|
|
|
57
57
|
* ```
|
|
58
58
|
*
|
|
59
59
|
*/
|
|
60
|
-
createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.
|
|
60
|
+
createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.Right<"createConstrainedType", ConstrainedType<GenericName, GenericPrimitiveValue>> | DEither.Left<"createConstrainedTypeError", DDataParser.DataParserError>);
|
|
61
61
|
/**
|
|
62
62
|
* Creates a constrained value from an unknown input and throws on error.
|
|
63
63
|
*
|
|
@@ -107,7 +107,7 @@ export declare class CreateConstrainedTypeError extends CreateConstrainedTypeErr
|
|
|
107
107
|
* const result = Between1And10.create(5);
|
|
108
108
|
*
|
|
109
109
|
* if (E.isRight(result)) {
|
|
110
|
-
* // result : E.
|
|
110
|
+
* // result : E.Right<"createConstrainedType", C.ConstrainedType<"between-1-10", 5>>
|
|
111
111
|
* }
|
|
112
112
|
*
|
|
113
113
|
* const value = Between1And10.createOrThrow(7);
|
|
@@ -12,7 +12,7 @@ import * as DDataParser from "../../../dataParser";
|
|
|
12
12
|
* const result = C.Int.create(12);
|
|
13
13
|
*
|
|
14
14
|
* if (E.isRight(result)) {
|
|
15
|
-
* // result: E.
|
|
15
|
+
* // result: E.Right<"createConstrainedType", C.ConstrainedType<"int", 12>>
|
|
16
16
|
* }
|
|
17
17
|
*
|
|
18
18
|
* const value = C.Int.createOrThrow(7);
|
|
@@ -41,7 +41,7 @@ export type Int = GetConstraint<typeof Int>;
|
|
|
41
41
|
* const result = C.Positive.create(4);
|
|
42
42
|
*
|
|
43
43
|
* if (E.isRight(result)) {
|
|
44
|
-
* // result: E.
|
|
44
|
+
* // result: E.Right<"createConstrainedType", C.ConstrainedType<"positive", 4>>
|
|
45
45
|
* }
|
|
46
46
|
*
|
|
47
47
|
* const value = C.Positive.createOrThrow(10);
|
|
@@ -70,7 +70,7 @@ export type Positive = GetConstraint<typeof Positive>;
|
|
|
70
70
|
* const result = C.Negative.create(-4);
|
|
71
71
|
*
|
|
72
72
|
* if (E.isRight(result)) {
|
|
73
|
-
* // result: E.
|
|
73
|
+
* // result: E.Right<"createConstrainedType", C.ConstrainedType<"negative", -4>>
|
|
74
74
|
* }
|
|
75
75
|
*
|
|
76
76
|
* const value = C.Negative.createOrThrow(-10);
|
|
@@ -12,7 +12,7 @@ import * as DDataParser from "../../../dataParser";
|
|
|
12
12
|
* const result = C.Email.create("hello@duplojs.dev");
|
|
13
13
|
*
|
|
14
14
|
* if (E.isRight(result)) {
|
|
15
|
-
* // result: E.
|
|
15
|
+
* // result: E.Right<"createConstrainedType", C.ConstrainedType<"email", "hello@duplojs.dev">>
|
|
16
16
|
* }
|
|
17
17
|
*
|
|
18
18
|
* const email = C.Email.createOrThrow("a@b.com");
|
|
@@ -41,7 +41,7 @@ export type Email = GetConstraint<typeof Email>;
|
|
|
41
41
|
* const result = C.Url.create("https://duplojs.dev");
|
|
42
42
|
*
|
|
43
43
|
* if (E.isRight(result)) {
|
|
44
|
-
* // result: E.
|
|
44
|
+
* // result: E.Right<"createConstrainedType", C.ConstrainedType<"url", "https://duplojs.dev">>
|
|
45
45
|
* }
|
|
46
46
|
*
|
|
47
47
|
* const url = C.Url.createOrThrow("https://example.com");
|
package/dist/clean/entity.cjs
CHANGED
|
@@ -116,6 +116,15 @@ function createEntity(name, getPropertiesDefinition) {
|
|
|
116
116
|
function is$1(input) {
|
|
117
117
|
return entityKind.has(input) && entityKind.getValue(input) === name;
|
|
118
118
|
}
|
|
119
|
+
function update(entity, newProperties) {
|
|
120
|
+
const updatedEntity = {};
|
|
121
|
+
for (const key in propertiesDefinition) {
|
|
122
|
+
updatedEntity[key] = newProperties[key] !== undefined
|
|
123
|
+
? newProperties[key]
|
|
124
|
+
: entity[key];
|
|
125
|
+
}
|
|
126
|
+
return entityKind.setTo(updatedEntity, name);
|
|
127
|
+
}
|
|
119
128
|
return entityHandlerKind.setTo({
|
|
120
129
|
name,
|
|
121
130
|
propertiesDefinition,
|
|
@@ -124,6 +133,7 @@ function createEntity(name, getPropertiesDefinition) {
|
|
|
124
133
|
map: map$1,
|
|
125
134
|
mapOrThrow,
|
|
126
135
|
is: is$1,
|
|
136
|
+
update,
|
|
127
137
|
});
|
|
128
138
|
}
|
|
129
139
|
|
package/dist/clean/entity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SimplifyTopLevel, type Kind, type Unwrap, type IsEqual, type IsExtends, type Or, type NeverCoalescing } from "../common";
|
|
1
|
+
import { type SimplifyTopLevel, type Kind, type Unwrap, type IsEqual, type IsExtends, type Or, type NeverCoalescing, type RemoveKind } from "../common";
|
|
2
2
|
import { type GetNewType, type NewTypeHandler } from "./newType";
|
|
3
3
|
import * as DEither from "../either";
|
|
4
4
|
import * as DDataParser from "../dataParser";
|
|
@@ -85,7 +85,7 @@ export interface EntityHandler<GenericName extends string = string, GenericPrope
|
|
|
85
85
|
* ```
|
|
86
86
|
*
|
|
87
87
|
*/
|
|
88
|
-
map(rawProperties: EntityRawProperties<GenericPropertiesDefinition>): (DEither.
|
|
88
|
+
map(rawProperties: EntityRawProperties<GenericPropertiesDefinition>): (DEither.Right<"createEntity", Entity<GenericName> & EntityProperties<GenericPropertiesDefinition>> | DEither.Left<"createEntityError", DDataParser.DataParserError>);
|
|
89
89
|
/**
|
|
90
90
|
* Validates raw properties and throws on error.
|
|
91
91
|
*
|
|
@@ -112,6 +112,18 @@ export interface EntityHandler<GenericName extends string = string, GenericPrope
|
|
|
112
112
|
*
|
|
113
113
|
*/
|
|
114
114
|
is<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput, Entity<GenericName>>;
|
|
115
|
+
/**
|
|
116
|
+
* Updates an entity by merging typed properties into an existing entity.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* const updated = User.Entity.update(mapped, {
|
|
120
|
+
* name: User.Name.createOrThrow("Bobby"),
|
|
121
|
+
* nick: null,
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
126
|
+
update<const GenericEntity extends Entity<GenericName>, const GenericProperties extends Partial<EntityProperties<GenericPropertiesDefinition>>>(entity: GenericEntity, properties: GenericProperties): Entity<GenericName> & DObject.AssignObjects<RemoveKind<GenericEntity>, GenericProperties>;
|
|
115
127
|
}
|
|
116
128
|
declare const CreateEntityError_base: new (params: {
|
|
117
129
|
"@DuplojsUtilsError/create-entity-error"?: unknown;
|
|
@@ -197,7 +209,7 @@ export interface PropertiesDefinitionParams {
|
|
|
197
209
|
* });
|
|
198
210
|
*
|
|
199
211
|
* if (E.isRight(mappedResult)) {
|
|
200
|
-
* // mappedResult: E.
|
|
212
|
+
* // mappedResult: E.Right<"createEntity", C.Entity<"User">>
|
|
201
213
|
* }
|
|
202
214
|
*
|
|
203
215
|
* ```
|
package/dist/clean/entity.mjs
CHANGED
|
@@ -114,6 +114,15 @@ function createEntity(name, getPropertiesDefinition) {
|
|
|
114
114
|
function is(input) {
|
|
115
115
|
return entityKind.has(input) && entityKind.getValue(input) === name;
|
|
116
116
|
}
|
|
117
|
+
function update(entity, newProperties) {
|
|
118
|
+
const updatedEntity = {};
|
|
119
|
+
for (const key in propertiesDefinition) {
|
|
120
|
+
updatedEntity[key] = newProperties[key] !== undefined
|
|
121
|
+
? newProperties[key]
|
|
122
|
+
: entity[key];
|
|
123
|
+
}
|
|
124
|
+
return entityKind.setTo(updatedEntity, name);
|
|
125
|
+
}
|
|
117
126
|
return entityHandlerKind.setTo({
|
|
118
127
|
name,
|
|
119
128
|
propertiesDefinition,
|
|
@@ -122,6 +131,7 @@ function createEntity(name, getPropertiesDefinition) {
|
|
|
122
131
|
map: map$1,
|
|
123
132
|
mapOrThrow,
|
|
124
133
|
is,
|
|
134
|
+
update,
|
|
125
135
|
});
|
|
126
136
|
}
|
|
127
137
|
|
package/dist/clean/flag.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ export interface Flag<GenericName extends string = string, GenericValue extends
|
|
|
91
91
|
* drinkAlcohol,
|
|
92
92
|
* ),
|
|
93
93
|
* );
|
|
94
|
-
* // E.
|
|
94
|
+
* // E.Left<"not-major", undefined> | E.Right<"not-thirsty-anymore", undefined>
|
|
95
95
|
*
|
|
96
96
|
* const flagged = User.MajorFlag.append(user, user.age);
|
|
97
97
|
* const value = User.MajorFlag.getValue(flagged);
|
package/dist/clean/newType.d.ts
CHANGED
|
@@ -34,8 +34,8 @@ export interface NewTypeHandler<GenericName extends string = string, GenericValu
|
|
|
34
34
|
* ```
|
|
35
35
|
*
|
|
36
36
|
*/
|
|
37
|
-
create<const GenericData extends GenericValue>(data: GenericData): (DEither.
|
|
38
|
-
create<GenericPrimitive extends Primitive<Extract<GenericValue, EligiblePrimitive>>>(data: GenericPrimitive): (DEither.
|
|
37
|
+
create<const GenericData extends GenericValue>(data: GenericData): (DEither.Right<"createNewType", NewType<GenericName, GenericData, GenericConstrainHandler[number]["name"]>> | DEither.Left<"createNewTypeError", DDataParser.DataParserError>);
|
|
38
|
+
create<GenericPrimitive extends Primitive<Extract<GenericValue, EligiblePrimitive>>>(data: GenericPrimitive): (DEither.Right<"createNewType", (GenericPrimitive & NewType<GenericName, Unwrap<GenericPrimitive>, GenericConstrainHandler[number]["name"]>)> | DEither.Left<"createNewTypeError", DDataParser.DataParserError>);
|
|
39
39
|
/**
|
|
40
40
|
* Creates a NewType value and throws on error. Works with raw values or primitives.
|
|
41
41
|
*
|
|
@@ -60,12 +60,12 @@ export interface NewTypeHandler<GenericName extends string = string, GenericValu
|
|
|
60
60
|
* const maybe = UserId.createWithUnknown(unknownValue);
|
|
61
61
|
*
|
|
62
62
|
* if (E.isRight(maybe)) {
|
|
63
|
-
* // maybe: E.
|
|
63
|
+
* // maybe: E.Right<"createNewType", UserId>
|
|
64
64
|
* }
|
|
65
65
|
* ```
|
|
66
66
|
*
|
|
67
67
|
*/
|
|
68
|
-
createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.
|
|
68
|
+
createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.Right<"createNewType", NewType<GenericName, GenericValue, GenericConstrainHandler[number]["name"]>> | DEither.Left<"createNewTypeError", DDataParser.DataParserError>);
|
|
69
69
|
/**
|
|
70
70
|
* Creates a NewType value from an unknown input and throws on error.
|
|
71
71
|
*
|
|
@@ -125,7 +125,7 @@ export declare class CreateNewTypeError extends CreateNewTypeError_base {
|
|
|
125
125
|
* const maybe = UserId.createWithUnknown(unknownValue);
|
|
126
126
|
*
|
|
127
127
|
* if (E.isRight(maybe)) {
|
|
128
|
-
* // maybe: E.
|
|
128
|
+
* // maybe: E.Right<"createNewType", UserId>
|
|
129
129
|
* }
|
|
130
130
|
*
|
|
131
131
|
* const strictValue = UserId.createWithUnknownOrThrow(unknownValue);
|
|
@@ -14,12 +14,12 @@ export interface PrimitiveHandler<GenericValue extends EligiblePrimitive = Eligi
|
|
|
14
14
|
* const result = C.String.create("hello");
|
|
15
15
|
*
|
|
16
16
|
* if (E.isRight(result)) {
|
|
17
|
-
* // result: E.
|
|
17
|
+
* // result: E.Right<"createNewType", C.Primitive<"hello">>
|
|
18
18
|
* }
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
create<GenericData extends GenericValue>(data: GenericData): (DEither.
|
|
22
|
+
create<GenericData extends GenericValue>(data: GenericData): (DEither.Right<"createNewType", Primitive<GenericData>> | DEither.Left<"createNewTypeError", DDataParser.DataParserError>);
|
|
23
23
|
/**
|
|
24
24
|
* Creates a primitive value and throws on error.
|
|
25
25
|
*
|
|
@@ -36,11 +36,11 @@ export interface PrimitiveHandler<GenericValue extends EligiblePrimitive = Eligi
|
|
|
36
36
|
* ```ts
|
|
37
37
|
* const unknownValue: unknown = "world";
|
|
38
38
|
* const maybe = C.String.createWithUnknown(unknownValue);
|
|
39
|
-
* // E.
|
|
39
|
+
* // E.Left<"createNewTypeError", DataParserError> | E.Right<"createNewType", C.Primitive<string>>
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
*/
|
|
43
|
-
createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.
|
|
43
|
+
createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.Right<"createNewType", Primitive<GenericValue>> | DEither.Left<"createNewTypeError", DDataParser.DataParserError>);
|
|
44
44
|
/**
|
|
45
45
|
* Creates a primitive value from an unknown input and throws on error.
|
|
46
46
|
*
|
|
@@ -89,7 +89,7 @@ export declare class CreatePrimitiveError extends CreatePrimitiveError_base {
|
|
|
89
89
|
* const result = C.String.create("hello");
|
|
90
90
|
*
|
|
91
91
|
* if (E.isRight(result)) {
|
|
92
|
-
* // result: E.
|
|
92
|
+
* // result: E.Right<"createNewType", C.Primitive<"hello">>
|
|
93
93
|
* }
|
|
94
94
|
*
|
|
95
95
|
* const value = C.String.createOrThrow("world");
|
|
@@ -122,7 +122,7 @@ export type String = ReturnType<typeof String["createWithUnknownOrThrow"]>;
|
|
|
122
122
|
* const result = C.Number.create(42);
|
|
123
123
|
*
|
|
124
124
|
* if (E.isRight(result)) {
|
|
125
|
-
* // result: E.
|
|
125
|
+
* // result: E.Right<"createNewType", C.Primitive<42>>
|
|
126
126
|
* }
|
|
127
127
|
*
|
|
128
128
|
* const value = C.Number.createOrThrow(7);
|
|
@@ -155,7 +155,7 @@ export type Number = ReturnType<typeof Number["createWithUnknownOrThrow"]>;
|
|
|
155
155
|
* const result = C.BigInt.create(10n);
|
|
156
156
|
*
|
|
157
157
|
* if (E.isRight(result)) {
|
|
158
|
-
* // result: E.
|
|
158
|
+
* // result: E.Right<"createNewType", C.Primitive<10n>>
|
|
159
159
|
* }
|
|
160
160
|
*
|
|
161
161
|
* const value = C.BigInt.createOrThrow(99n);
|
|
@@ -188,7 +188,7 @@ export type BigInt = ReturnType<typeof BigInt["createWithUnknownOrThrow"]>;
|
|
|
188
188
|
* const result = C.Boolean.create(true);
|
|
189
189
|
*
|
|
190
190
|
* if (E.isRight(result)) {
|
|
191
|
-
* // result: E.
|
|
191
|
+
* // result: E.Right<"createNewType", C.Primitive<true>>
|
|
192
192
|
* }
|
|
193
193
|
*
|
|
194
194
|
* const value = C.Boolean.createOrThrow(false);
|
|
@@ -223,7 +223,7 @@ export type Boolean = ReturnType<typeof Boolean["createWithUnknownOrThrow"]>;
|
|
|
223
223
|
* const result = C.Date.create(date);
|
|
224
224
|
*
|
|
225
225
|
* if (E.isRight(result)) {
|
|
226
|
-
* // result: E.
|
|
226
|
+
* // result: E.Right<"createNewType", C.Primitive<D.TheDate>>
|
|
227
227
|
* }
|
|
228
228
|
*
|
|
229
229
|
* const value = C.Date.createOrThrow(date);
|
|
@@ -258,7 +258,7 @@ export type Date = ReturnType<typeof Date["createWithUnknownOrThrow"]>;
|
|
|
258
258
|
* const result = C.Time.create(theTime);
|
|
259
259
|
*
|
|
260
260
|
* if (E.isRight(result)) {
|
|
261
|
-
* // result: E.
|
|
261
|
+
* // result: E.Right<"createNewType", C.Primitive<D.TheTime>>
|
|
262
262
|
* }
|
|
263
263
|
*
|
|
264
264
|
* const value = C.Time.createOrThrow(theTime);
|
|
@@ -55,7 +55,7 @@ export interface RepositoryHandler<GenericRepository extends object = object> ex
|
|
|
55
55
|
*
|
|
56
56
|
* // Application Layer
|
|
57
57
|
* interface UserRepository {
|
|
58
|
-
* findById(id: User.Id): Promise<E.
|
|
58
|
+
* findById(id: User.Id): Promise<E.Success<User.Entity> | E.Fail>;
|
|
59
59
|
* }
|
|
60
60
|
*
|
|
61
61
|
* const UserRepository = C.createRepository<UserRepository>();
|
package/dist/clean/useCase.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export interface UseCaseHandler<GenericDependencies extends UseCaseDependencies
|
|
|
60
60
|
*
|
|
61
61
|
* // Application Layer
|
|
62
62
|
* interface UserRepository {
|
|
63
|
-
* findById(id: User.Id): Promise<E.
|
|
63
|
+
* findById(id: User.Id): Promise<E.Success<User.Entity> | E.Fail>;
|
|
64
64
|
* }
|
|
65
65
|
*
|
|
66
66
|
* const UserRepository = C.createRepository<UserRepository>();
|
|
@@ -12,13 +12,13 @@ import { type AnyTuple, type UnionToIntersection } from "./types";
|
|
|
12
12
|
* Predicate overloads (type guards) narrow the output type.
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
|
-
* const input = E.ok() as E.
|
|
15
|
+
* const input = E.ok() as E.Ok | E.Error;
|
|
16
16
|
*
|
|
17
17
|
* if (hasKinds(input, [
|
|
18
18
|
* E.eitherOkKind,
|
|
19
19
|
* E.eitherRightKind,
|
|
20
20
|
* ])) {
|
|
21
|
-
* // type: E.
|
|
21
|
+
* // type: E.Ok
|
|
22
22
|
* }
|
|
23
23
|
*
|
|
24
24
|
* const result = pipe(
|
|
@@ -31,7 +31,7 @@ import { type AnyTuple, type UnionToIntersection } from "./types";
|
|
|
31
31
|
* () => "ok",
|
|
32
32
|
* ),
|
|
33
33
|
* );
|
|
34
|
-
* // result: "ok" | E.
|
|
34
|
+
* // result: "ok" | E.Error<unknown>
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
37
|
* @see https://utils.duplojs.dev/en/v1/api/common/hasKinds
|
|
@@ -12,13 +12,13 @@ import { type AnyTuple } from "./types";
|
|
|
12
12
|
* Predicate overloads (type guards) narrow the output type.
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
|
-
* const input = E.ok() as E.
|
|
15
|
+
* const input = E.ok() as E.Ok | E.Error;
|
|
16
16
|
*
|
|
17
17
|
* if (hasSomeKinds(input, [
|
|
18
18
|
* E.eitherOkKind,
|
|
19
19
|
* E.eitherErrorKind,
|
|
20
20
|
* ])) {
|
|
21
|
-
* // type: E.
|
|
21
|
+
* // type: E.Ok | E.Error
|
|
22
22
|
* }
|
|
23
23
|
*
|
|
24
24
|
* const result = pipe(
|
|
@@ -31,7 +31,7 @@ import { type AnyTuple } from "./types";
|
|
|
31
31
|
* () => "known",
|
|
32
32
|
* ),
|
|
33
33
|
* );
|
|
34
|
-
* // result: "known" | E.
|
|
34
|
+
* // result: "known" | E.Error<unknown>
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
37
|
* @see https://utils.duplojs.dev/en/v1/api/common/hasSomeKinds
|
|
@@ -24,4 +24,4 @@ import type { AnyTuple } from "../types";
|
|
|
24
24
|
* @see https://utils.duplojs.dev/en/v1/api/common/path/resolveFrom
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
|
-
export declare function resolveFrom<GenericSegment extends string>(origin: string, segments: AnyTuple<GenericSegment>): DEither.
|
|
27
|
+
export declare function resolveFrom<GenericSegment extends string>(origin: string, segments: AnyTuple<GenericSegment>): DEither.Fail | DEither.Success<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type MaybeArray<GenericValue extends unknown> = GenericValue | GenericValue[];
|
|
1
|
+
export type MaybeArray<GenericValue extends unknown> = GenericValue | readonly GenericValue[];
|
|
@@ -67,7 +67,7 @@ export interface DataParser<GenericDefinition extends DataParserDefinition = Dat
|
|
|
67
67
|
* @namespace DP
|
|
68
68
|
*
|
|
69
69
|
*/
|
|
70
|
-
parse(data: unknown): DEither.
|
|
70
|
+
parse(data: unknown): DEither.Success<GenericOutput> | DEither.Error<DataParserError>;
|
|
71
71
|
/**
|
|
72
72
|
* The asyncParse() method runs a data parser asynchronously and resolves to an Either with the parsed value or a DataParserError.
|
|
73
73
|
*
|
|
@@ -79,7 +79,7 @@ export interface DataParser<GenericDefinition extends DataParserDefinition = Dat
|
|
|
79
79
|
* @namespace DP
|
|
80
80
|
*
|
|
81
81
|
*/
|
|
82
|
-
asyncParse(data: unknown): Promise<DEither.
|
|
82
|
+
asyncParse(data: unknown): Promise<DEither.Success<GenericOutput> | DEither.Error<DataParserError>>;
|
|
83
83
|
/**
|
|
84
84
|
* The addChecker() method returns a new data parser with one or more additional checkers appended.
|
|
85
85
|
*
|
|
@@ -45,7 +45,7 @@ export interface DataParserExtended<GenericDefinition extends DataParserDefiniti
|
|
|
45
45
|
* @namespace DPE
|
|
46
46
|
*
|
|
47
47
|
*/
|
|
48
|
-
parse(data: unknown): DEither.
|
|
48
|
+
parse(data: unknown): DEither.Success<GenericOutput> | DEither.Error<DataParserError>;
|
|
49
49
|
/**
|
|
50
50
|
* The asyncParse() method runs an extended data parser asynchronously and resolves to an Either with the parsed value or a DataParserError.
|
|
51
51
|
*
|
|
@@ -57,7 +57,7 @@ export interface DataParserExtended<GenericDefinition extends DataParserDefiniti
|
|
|
57
57
|
* @namespace DPE
|
|
58
58
|
*
|
|
59
59
|
*/
|
|
60
|
-
asyncParse(data: unknown): Promise<DEither.
|
|
60
|
+
asyncParse(data: unknown): Promise<DEither.Success<GenericOutput> | DEither.Error<DataParserError>>;
|
|
61
61
|
/**
|
|
62
62
|
* The parseOrThrow() method runs an extended data parser synchronously and returns the parsed value or throws a DataParserThrowError.
|
|
63
63
|
*
|
|
@@ -26,7 +26,7 @@ export interface DataParserEmptyExtended<GenericDefinition extends dataParsers.D
|
|
|
26
26
|
* const parser = DPE.empty();
|
|
27
27
|
* const result = parser.parse(undefined);
|
|
28
28
|
* if (E.isRight(result)) {
|
|
29
|
-
* // E.
|
|
29
|
+
* // E.Success<undefined>
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
32
32
|
* const coerceParser = DPE.coerce.empty();
|
|
@@ -33,7 +33,7 @@ export interface DataParserEmpty<GenericDefinition extends DataParserDefinitionE
|
|
|
33
33
|
* const parser = DP.empty();
|
|
34
34
|
* const result = parser.parse(undefined);
|
|
35
35
|
* if (E.isRight(result)) {
|
|
36
|
-
* // E.
|
|
36
|
+
* // E.Success<undefined>
|
|
37
37
|
* }
|
|
38
38
|
*
|
|
39
39
|
* const withCheckers = DP.empty({
|
package/dist/date/create.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Hour, IsLeapYear, IsSafeYear, Millisecond, Minute, Second, TheDate
|
|
|
2
2
|
import * as DEither from "../either";
|
|
3
3
|
import type * as DString from "../string";
|
|
4
4
|
import { type And, type IsEqual, type Not, type IsExtends } from "../common";
|
|
5
|
-
export type MayBe = DEither.
|
|
5
|
+
export type MayBe = DEither.Right<"date-created", TheDate> | DEither.Left<"date-created-error", null>;
|
|
6
6
|
type SafeDate = `${number}-${MonthWithDay}`;
|
|
7
7
|
declare const SymbolForbiddenDate: unique symbol;
|
|
8
8
|
type ForbiddenDate<GenericDate extends string> = And<[
|
|
@@ -3,7 +3,7 @@ import { type maxTimeValue, type minTimeValue } from "./constants";
|
|
|
3
3
|
import { type TheTime, type SpoolingTime } from "./types";
|
|
4
4
|
import * as DEither from "../either";
|
|
5
5
|
import { type IsGreater, type IsLess } from "../number";
|
|
6
|
-
export type MayBeTime = DEither.
|
|
6
|
+
export type MayBeTime = DEither.Right<"time-created", TheTime> | DEither.Left<"time-created-error", null>;
|
|
7
7
|
type Units = "week" | "day" | "hour" | "minute" | "second" | "millisecond";
|
|
8
8
|
declare const SymbolForbiddenTime: unique symbol;
|
|
9
9
|
type ForbiddenTime<GenericInput extends number, GenericUnit extends Units> = IsEqual<GenericInput, number> extends true ? {
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var kind = require('../kind.cjs');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const boolKind = kind.createEitherKind("bool");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use boolKind
|
|
8
|
+
*/
|
|
9
|
+
const eitherBoolKind = boolKind;
|
|
6
10
|
|
|
11
|
+
exports.boolKind = boolKind;
|
|
7
12
|
exports.eitherBoolKind = eitherBoolKind;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
export declare const boolKind: import("../..").KindHandler<import("../..").KindDefinition<"@DuplojsUtilsEither/bool", unknown>>;
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use boolKind
|
|
4
|
+
*/
|
|
1
5
|
export declare const eitherBoolKind: import("../..").KindHandler<import("../..").KindDefinition<"@DuplojsUtilsEither/bool", unknown>>;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { createEitherKind } from '../kind.mjs';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const boolKind = createEitherKind("bool");
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use boolKind
|
|
6
|
+
*/
|
|
7
|
+
const eitherBoolKind = boolKind;
|
|
4
8
|
|
|
5
|
-
export { eitherBoolKind };
|
|
9
|
+
export { boolKind, eitherBoolKind };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type FalsyValue, type IsEqual } from "../../common";
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
2
|
+
import { type BoolFalsy } from "./falsy";
|
|
3
|
+
import { type BoolTruthy } from "./truthy";
|
|
4
4
|
/**
|
|
5
|
-
* Converts any value into a boolean monad (
|
|
5
|
+
* Converts any value into a boolean monad (BoolTruthy or BoolFalsy). Handy to keep track of the test while benefiting from the whenIsBoolTruthy/whenIsBoolFalsy helpers.
|
|
6
6
|
*
|
|
7
7
|
* Signature: `bool(value)` → returns a value
|
|
8
8
|
*
|
|
@@ -15,7 +15,7 @@ import { type EitherBoolTruthy } from "./truthy";
|
|
|
15
15
|
* E.bool,
|
|
16
16
|
* );
|
|
17
17
|
*
|
|
18
|
-
* // type: E.
|
|
18
|
+
* // type: E.BoolFalsy<undefined> | E.BoolTruthy<"nest">
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
21
|
* @see https://utils.duplojs.dev/en/v1/api/either/bool
|
|
@@ -23,5 +23,5 @@ import { type EitherBoolTruthy } from "./truthy";
|
|
|
23
23
|
* @namespace E
|
|
24
24
|
*
|
|
25
25
|
*/
|
|
26
|
-
export declare function bool<const GenericValue extends unknown = undefined>(value: GenericValue): GenericValue extends FalsyValue ?
|
|
27
|
-
export type Bool<GenericValue extends unknown> =
|
|
26
|
+
export declare function bool<const GenericValue extends unknown = undefined>(value: GenericValue): GenericValue extends FalsyValue ? BoolFalsy<GenericValue> : IsEqual<GenericValue, number> extends true ? BoolTruthy<GenericValue> | BoolFalsy<0> : IsEqual<GenericValue, bigint> extends true ? BoolTruthy<GenericValue> | BoolFalsy<0n> : IsEqual<GenericValue, string> extends true ? BoolTruthy<GenericValue> | BoolFalsy<""> : BoolTruthy<GenericValue>;
|
|
27
|
+
export type Bool<GenericValue extends unknown> = BoolTruthy<GenericValue> | BoolFalsy;
|
|
@@ -8,7 +8,11 @@ var is = require('../left/is.cjs');
|
|
|
8
8
|
var is$1 = require('../right/is.cjs');
|
|
9
9
|
var unwrap = require('../../common/unwrap.cjs');
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const boolFalsyKind = kind.createEitherKind("bool-falsy");
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use boolFalsyKind
|
|
14
|
+
*/
|
|
15
|
+
const eitherBoolFalsyKind = boolFalsyKind;
|
|
12
16
|
/**
|
|
13
17
|
* {@include either/boolFalsy/index.md}
|
|
14
18
|
*/
|
|
@@ -19,12 +23,12 @@ const eitherBoolFalsyKind = kind.createEitherKind("bool-falsy");
|
|
|
19
23
|
* {@include either/whenIsBoolFalsy/index.md}
|
|
20
24
|
*/
|
|
21
25
|
function boolFalsy(value = undefined) {
|
|
22
|
-
return base.
|
|
26
|
+
return base.boolKind.setTo(boolFalsyKind.setTo(create.left("bool", value)));
|
|
23
27
|
}
|
|
24
28
|
function isBoolFalsy(input) {
|
|
25
29
|
return is.isLeft(input)
|
|
26
|
-
&& base.
|
|
27
|
-
&&
|
|
30
|
+
&& base.boolKind.has(input)
|
|
31
|
+
&& boolFalsyKind.has(input);
|
|
28
32
|
}
|
|
29
33
|
function whenIsBoolFalsy(...args) {
|
|
30
34
|
if (args.length === 1) {
|
|
@@ -48,6 +52,7 @@ function whenIsBoolFalsy(...args) {
|
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
exports.boolFalsy = boolFalsy;
|
|
55
|
+
exports.boolFalsyKind = boolFalsyKind;
|
|
51
56
|
exports.eitherBoolFalsyKind = eitherBoolFalsyKind;
|
|
52
57
|
exports.isBoolFalsy = isBoolFalsy;
|
|
53
58
|
exports.whenIsBoolFalsy = whenIsBoolFalsy;
|