@duplojs/utils 1.3.19 → 1.3.20

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 (108) hide show
  1. package/dist/array/group.d.ts +5 -5
  2. package/dist/common/types/index.d.ts +1 -0
  3. package/dist/common/types/maybeGetter.d.ts +1 -0
  4. package/dist/dataParser/base.cjs +7 -9
  5. package/dist/dataParser/base.d.ts +2 -1
  6. package/dist/dataParser/base.mjs +7 -9
  7. package/dist/dataParser/baseExtended.cjs +3 -0
  8. package/dist/dataParser/baseExtended.d.ts +1 -0
  9. package/dist/dataParser/baseExtended.mjs +3 -0
  10. package/dist/dataParser/extended/array.d.ts +1 -0
  11. package/dist/dataParser/extended/bigint.d.ts +1 -0
  12. package/dist/dataParser/extended/boolean.d.ts +1 -0
  13. package/dist/dataParser/extended/date.d.ts +1 -0
  14. package/dist/dataParser/extended/empty.d.ts +1 -0
  15. package/dist/dataParser/extended/lazy.d.ts +1 -0
  16. package/dist/dataParser/extended/literal.d.ts +1 -0
  17. package/dist/dataParser/extended/nil.d.ts +1 -0
  18. package/dist/dataParser/extended/nullable.d.ts +1 -0
  19. package/dist/dataParser/extended/number.d.ts +1 -0
  20. package/dist/dataParser/extended/object.d.ts +1 -0
  21. package/dist/dataParser/extended/optional.d.ts +1 -0
  22. package/dist/dataParser/extended/pipe.d.ts +1 -0
  23. package/dist/dataParser/extended/record.d.ts +1 -0
  24. package/dist/dataParser/extended/recover.d.ts +1 -0
  25. package/dist/dataParser/extended/string.d.ts +1 -0
  26. package/dist/dataParser/extended/templateLiteral.d.ts +1 -0
  27. package/dist/dataParser/extended/transform.d.ts +1 -0
  28. package/dist/dataParser/extended/tuple.d.ts +1 -0
  29. package/dist/dataParser/extended/union.d.ts +1 -0
  30. package/dist/dataParser/extended/unknown.d.ts +1 -0
  31. package/dist/dataParser/parsers/array/index.cjs +3 -5
  32. package/dist/dataParser/parsers/array/index.d.ts +1 -0
  33. package/dist/dataParser/parsers/array/index.mjs +3 -5
  34. package/dist/dataParser/parsers/bigint/index.cjs +3 -5
  35. package/dist/dataParser/parsers/bigint/index.d.ts +1 -0
  36. package/dist/dataParser/parsers/bigint/index.mjs +3 -5
  37. package/dist/dataParser/parsers/boolean.cjs +3 -5
  38. package/dist/dataParser/parsers/boolean.d.ts +1 -0
  39. package/dist/dataParser/parsers/boolean.mjs +3 -5
  40. package/dist/dataParser/parsers/date.cjs +3 -5
  41. package/dist/dataParser/parsers/date.d.ts +1 -0
  42. package/dist/dataParser/parsers/date.mjs +3 -5
  43. package/dist/dataParser/parsers/empty.cjs +3 -5
  44. package/dist/dataParser/parsers/empty.d.ts +1 -0
  45. package/dist/dataParser/parsers/empty.mjs +3 -5
  46. package/dist/dataParser/parsers/lazy.cjs +3 -5
  47. package/dist/dataParser/parsers/lazy.d.ts +1 -0
  48. package/dist/dataParser/parsers/lazy.mjs +3 -5
  49. package/dist/dataParser/parsers/literal.cjs +3 -5
  50. package/dist/dataParser/parsers/literal.d.ts +1 -0
  51. package/dist/dataParser/parsers/literal.mjs +3 -5
  52. package/dist/dataParser/parsers/nil.cjs +3 -5
  53. package/dist/dataParser/parsers/nil.d.ts +1 -0
  54. package/dist/dataParser/parsers/nil.mjs +3 -5
  55. package/dist/dataParser/parsers/nullable.cjs +4 -6
  56. package/dist/dataParser/parsers/nullable.d.ts +1 -0
  57. package/dist/dataParser/parsers/nullable.mjs +4 -6
  58. package/dist/dataParser/parsers/number/index.cjs +3 -5
  59. package/dist/dataParser/parsers/number/index.d.ts +1 -0
  60. package/dist/dataParser/parsers/number/index.mjs +3 -5
  61. package/dist/dataParser/parsers/object/index.cjs +7 -9
  62. package/dist/dataParser/parsers/object/index.d.ts +1 -0
  63. package/dist/dataParser/parsers/object/index.mjs +7 -9
  64. package/dist/dataParser/parsers/optional.cjs +4 -6
  65. package/dist/dataParser/parsers/optional.d.ts +1 -0
  66. package/dist/dataParser/parsers/optional.mjs +4 -6
  67. package/dist/dataParser/parsers/pipe.cjs +4 -6
  68. package/dist/dataParser/parsers/pipe.d.ts +1 -0
  69. package/dist/dataParser/parsers/pipe.mjs +4 -6
  70. package/dist/dataParser/parsers/record/index.cjs +5 -7
  71. package/dist/dataParser/parsers/record/index.d.ts +1 -0
  72. package/dist/dataParser/parsers/record/index.mjs +5 -7
  73. package/dist/dataParser/parsers/recover.cjs +4 -6
  74. package/dist/dataParser/parsers/recover.d.ts +1 -0
  75. package/dist/dataParser/parsers/recover.mjs +4 -6
  76. package/dist/dataParser/parsers/string/index.cjs +3 -5
  77. package/dist/dataParser/parsers/string/index.d.ts +1 -0
  78. package/dist/dataParser/parsers/string/index.mjs +3 -5
  79. package/dist/dataParser/parsers/templateLiteral/createTemplateLiteralPattern.cjs +2 -2
  80. package/dist/dataParser/parsers/templateLiteral/createTemplateLiteralPattern.mjs +2 -2
  81. package/dist/dataParser/parsers/templateLiteral/index.cjs +4 -6
  82. package/dist/dataParser/parsers/templateLiteral/index.d.ts +1 -0
  83. package/dist/dataParser/parsers/templateLiteral/index.mjs +4 -6
  84. package/dist/dataParser/parsers/transform.cjs +4 -6
  85. package/dist/dataParser/parsers/transform.d.ts +1 -0
  86. package/dist/dataParser/parsers/transform.mjs +4 -6
  87. package/dist/dataParser/parsers/tuple.cjs +4 -6
  88. package/dist/dataParser/parsers/tuple.d.ts +1 -0
  89. package/dist/dataParser/parsers/tuple.mjs +4 -6
  90. package/dist/dataParser/parsers/union.cjs +3 -5
  91. package/dist/dataParser/parsers/union.d.ts +1 -0
  92. package/dist/dataParser/parsers/union.mjs +3 -5
  93. package/dist/dataParser/parsers/unknown.cjs +2 -4
  94. package/dist/dataParser/parsers/unknown.d.ts +1 -0
  95. package/dist/dataParser/parsers/unknown.mjs +2 -4
  96. package/dist/either/future/create.cjs +4 -4
  97. package/dist/either/future/create.d.ts +4 -5
  98. package/dist/either/future/create.mjs +4 -4
  99. package/dist/either/index.cjs +4 -0
  100. package/dist/either/index.mjs +2 -0
  101. package/dist/either/right/asyncGroup.cjs +18 -0
  102. package/dist/either/right/asyncGroup.d.ts +12 -0
  103. package/dist/either/right/asyncGroup.mjs +16 -0
  104. package/dist/either/right/group.cjs +17 -0
  105. package/dist/either/right/group.d.ts +12 -0
  106. package/dist/either/right/group.mjs +15 -0
  107. package/dist/either/right/index.d.ts +2 -0
  108. package/package.json +1 -1
@@ -6,12 +6,10 @@ import { createOverride } from '../../common/override.mjs';
6
6
  const transformKind = createDataParserKind("transform");
7
7
  function transform(inner, theFunction, definition) {
8
8
  const self = dataParserInit(transformKind, {
9
- definition: {
10
- errorMessage: definition?.errorMessage,
11
- checkers: definition?.checkers ?? [],
12
- inner,
13
- theFunction,
14
- },
9
+ errorMessage: definition?.errorMessage,
10
+ checkers: definition?.checkers ?? [],
11
+ inner,
12
+ theFunction,
15
13
  }, {
16
14
  sync: (data, error, self) => {
17
15
  const innerResult = self.definition.inner.exec(data, error);
@@ -8,12 +8,10 @@ var override = require('../../common/override.cjs');
8
8
  const tupleKind = kind.createDataParserKind("tuple");
9
9
  function tuple(shape, definition) {
10
10
  const self = base.dataParserInit(tupleKind, {
11
- definition: {
12
- errorMessage: definition?.errorMessage,
13
- checkers: definition?.checkers ?? [],
14
- rest: definition?.rest,
15
- shape,
16
- },
11
+ errorMessage: definition?.errorMessage,
12
+ checkers: definition?.checkers ?? [],
13
+ rest: definition?.rest,
14
+ shape,
17
15
  }, {
18
16
  sync: (data, error$1, self) => {
19
17
  if (!(data instanceof Array)) {
@@ -36,6 +36,7 @@ export interface DataParserTuple<GenericDefinition extends DataParserDefinitionT
36
36
  DataParserTupleCheckers<Output<this>>,
37
37
  ...DataParserTupleCheckers<Output<this>>[]
38
38
  ], GenericChecker>): DataParserTuple<AddCheckersToDefinition<GenericDefinition, GenericChecker>>;
39
+ construct<const GenericDefinition extends DataParserDefinitionTuple>(definition: GenericDefinition): DataParserTuple<MergeDefinition<DataParserDefinitionTuple, GenericDefinition>>;
39
40
  }
40
41
  export declare function tuple<GenericShape extends TupleShape, const GenericDefinition extends Partial<Omit<DataParserDefinitionTuple, "shape">> = never>(shape: GenericShape, definition?: GenericDefinition): DataParserTuple<MergeDefinition<DataParserDefinitionTuple, NeverCoalescing<GenericDefinition, {}> & {
41
42
  shape: GenericShape;
@@ -6,12 +6,10 @@ import { createOverride } from '../../common/override.mjs';
6
6
  const tupleKind = createDataParserKind("tuple");
7
7
  function tuple(shape, definition) {
8
8
  const self = dataParserInit(tupleKind, {
9
- definition: {
10
- errorMessage: definition?.errorMessage,
11
- checkers: definition?.checkers ?? [],
12
- rest: definition?.rest,
13
- shape,
14
- },
9
+ errorMessage: definition?.errorMessage,
10
+ checkers: definition?.checkers ?? [],
11
+ rest: definition?.rest,
12
+ shape,
15
13
  }, {
16
14
  sync: (data, error, self) => {
17
15
  if (!(data instanceof Array)) {
@@ -8,11 +8,9 @@ var override = require('../../common/override.cjs');
8
8
  const unionKind = kind.createDataParserKind("union");
9
9
  function union(options, definition) {
10
10
  const self = base.dataParserInit(unionKind, {
11
- definition: {
12
- errorMessage: definition?.errorMessage,
13
- checkers: definition?.checkers ?? [],
14
- options,
15
- },
11
+ errorMessage: definition?.errorMessage,
12
+ checkers: definition?.checkers ?? [],
13
+ options,
16
14
  }, {
17
15
  sync: (data, error$1, self) => {
18
16
  for (const dataParser of self.definition.options) {
@@ -20,6 +20,7 @@ export interface DataParserUnion<GenericDefinition extends DataParserDefinitionU
20
20
  DataParserUnionCheckers<Output<this>>,
21
21
  ...DataParserUnionCheckers<Output<this>>[]
22
22
  ], GenericChecker>): DataParserUnion<AddCheckersToDefinition<GenericDefinition, GenericChecker>>;
23
+ construct<const GenericDefinition extends DataParserDefinitionUnion>(definition: GenericDefinition): DataParserUnion<MergeDefinition<DataParserDefinitionUnion, GenericDefinition>>;
23
24
  }
24
25
  export declare function union<GenericOptions extends UnionOptions, const GenericDefinition extends Partial<Omit<DataParserDefinitionUnion, "options">> = never>(options: GenericOptions, definition?: GenericDefinition): DataParserUnion<MergeDefinition<DataParserDefinitionUnion, NeverCoalescing<GenericDefinition, {}> & {
25
26
  options: GenericOptions;
@@ -6,11 +6,9 @@ import { createOverride } from '../../common/override.mjs';
6
6
  const unionKind = createDataParserKind("union");
7
7
  function union(options, definition) {
8
8
  const self = dataParserInit(unionKind, {
9
- definition: {
10
- errorMessage: definition?.errorMessage,
11
- checkers: definition?.checkers ?? [],
12
- options,
13
- },
9
+ errorMessage: definition?.errorMessage,
10
+ checkers: definition?.checkers ?? [],
11
+ options,
14
12
  }, {
15
13
  sync: (data, error, self) => {
16
14
  for (const dataParser of self.definition.options) {
@@ -7,10 +7,8 @@ var override = require('../../common/override.cjs');
7
7
  const unknownKind = kind.createDataParserKind("unknown");
8
8
  function unknown(definition) {
9
9
  const self = base.dataParserInit(unknownKind, {
10
- definition: {
11
- errorMessage: definition?.errorMessage,
12
- checkers: definition?.checkers ?? [],
13
- },
10
+ errorMessage: definition?.errorMessage,
11
+ checkers: definition?.checkers ?? [],
14
12
  }, (data) => data);
15
13
  return unknown.overrideHandler.apply(self);
16
14
  }
@@ -18,6 +18,7 @@ export interface DataParserUnknown<GenericDefinition extends DataParserDefinitio
18
18
  DataParserUnknownCheckers,
19
19
  ...DataParserUnknownCheckers[]
20
20
  ], GenericChecker>): DataParserUnknown<AddCheckersToDefinition<GenericDefinition, GenericChecker>>;
21
+ construct<const GenericDefinition extends DataParserDefinitionUnknown>(definition: GenericDefinition): DataParserUnknown<MergeDefinition<DataParserDefinitionUnknown, GenericDefinition>>;
21
22
  }
22
23
  export declare function unknown<const GenericDefinition extends Partial<DataParserDefinitionUnknown> = never>(definition?: GenericDefinition): DataParserUnknown<MergeDefinition<DataParserDefinitionUnknown, NeverCoalescing<GenericDefinition, {}>>>;
23
24
  export declare namespace unknown {
@@ -5,10 +5,8 @@ import { createOverride } from '../../common/override.mjs';
5
5
  const unknownKind = createDataParserKind("unknown");
6
6
  function unknown(definition) {
7
7
  const self = dataParserInit(unknownKind, {
8
- definition: {
9
- errorMessage: definition?.errorMessage,
10
- checkers: definition?.checkers ?? [],
11
- },
8
+ errorMessage: definition?.errorMessage,
9
+ checkers: definition?.checkers ?? [],
12
10
  }, (data) => data);
13
11
  return unknown.overrideHandler.apply(self);
14
12
  }
@@ -25,9 +25,9 @@ class Future extends Promise {
25
25
  .catch((error$1) => error.futureError(error$1))));
26
26
  }
27
27
  [kind] = null;
28
- // @ts-expect-error override signature error
29
- then(theFunction) {
30
- return new Future(super.then(theFunction));
28
+ // default declaration
29
+ then(onfulfilled) {
30
+ return super.then(onfulfilled);
31
31
  }
32
32
  static get [Symbol.species]() {
33
33
  return Promise;
@@ -37,7 +37,7 @@ class Future extends Promise {
37
37
  && value?.constructor?.name === "Future"
38
38
  && kind in value;
39
39
  }
40
- static all(values) {
40
+ static rightAll(values) {
41
41
  return new Future(Promise.all(values.map((value) => new Future(value))));
42
42
  }
43
43
  }
@@ -3,12 +3,11 @@ import { type EitherRight } from "../right";
3
3
  import { type EitherFutureSuccess } from "./success";
4
4
  import { type EitherFutureError } from "./error";
5
5
  import { type IsEqual } from "../../common/types/isEqual";
6
- import { type MaybePromise } from "../../common/types/maybePromise";
7
6
  import { type AnyValue } from "../../common";
8
7
  type Either = EitherRight | EitherLeft;
9
8
  type ComputeEitherFutureSuccessResult<GenericValue extends unknown> = IsEqual<never, Exclude<GenericValue, Either>> extends false ? EitherFutureSuccess<Exclude<GenericValue, Either>> : never;
10
- type ComputeEitherFutureErrorResult<GenericValue extends unknown> = GenericValue extends Promise<unknown> ? EitherFutureError : never;
11
- type ComputeFutureEitherResult<GenericValue extends unknown = unknown> = Extract<Awaited<GenericValue>, Either> | ComputeEitherFutureSuccessResult<Awaited<GenericValue>> | ComputeEitherFutureErrorResult<GenericValue>;
9
+ type ComputeEitherFutureErrorResult<GenericValue extends unknown> = GenericValue extends Future<any> ? GenericValue : GenericValue extends Promise<unknown> ? EitherFutureError : never;
10
+ type ComputeFutureEitherResult<GenericValue extends unknown = unknown> = (Extract<Awaited<GenericValue>, Either> | ComputeEitherFutureSuccessResult<Awaited<GenericValue>> | ComputeEitherFutureErrorResult<GenericValue>);
12
11
  export type FutureEitherAllResult<GenericArray extends readonly unknown[] | []> = Future<{
13
12
  -readonly [Prop in keyof GenericArray]: Awaited<Future<GenericArray[Prop]>>;
14
13
  }>;
@@ -16,10 +15,10 @@ declare const kind = "kind-future-either";
16
15
  export declare class Future<const GenericValue extends unknown = unknown> extends Promise<ComputeFutureEitherResult<GenericValue>> {
17
16
  constructor(value: GenericValue);
18
17
  [kind]: unknown;
19
- then<const GenericOutput extends AnyValue>(theFunction: (result: Extract<ComputeFutureEitherResult<GenericValue>, any>) => MaybePromise<GenericOutput>): Future<GenericOutput>;
18
+ then<TResult1 = ComputeFutureEitherResult<GenericValue>, TResult2 = never>(onfulfilled?: ((value: ComputeFutureEitherResult<GenericValue>) => TResult1 | PromiseLike<TResult1>) | null): Promise<TResult1 | TResult2>;
20
19
  static get [Symbol.species](): PromiseConstructor;
21
20
  static instanceof<GenericValue extends unknown>(value: GenericValue): value is Extract<GenericValue, Future<any>>;
22
- static all<const GenericValue extends unknown, GenericArray extends readonly GenericValue[] | []>(values: GenericArray): FutureEitherAllResult<GenericArray>;
21
+ static rightAll<const GenericArray extends readonly unknown[]>(values: GenericArray): FutureEitherAllResult<GenericArray>;
23
22
  }
24
23
  export declare function future<GenericEither extends AnyValue>(value: GenericEither): Future<GenericEither>;
25
24
  export {};
@@ -23,9 +23,9 @@ class Future extends Promise {
23
23
  .catch((error) => futureError(error))));
24
24
  }
25
25
  [kind] = null;
26
- // @ts-expect-error override signature error
27
- then(theFunction) {
28
- return new Future(super.then(theFunction));
26
+ // default declaration
27
+ then(onfulfilled) {
28
+ return super.then(onfulfilled);
29
29
  }
30
30
  static get [Symbol.species]() {
31
31
  return Promise;
@@ -35,7 +35,7 @@ class Future extends Promise {
35
35
  && value?.constructor?.name === "Future"
36
36
  && kind in value;
37
37
  }
38
- static all(values) {
38
+ static rightAll(values) {
39
39
  return new Future(Promise.all(values.map((value) => new Future(value))));
40
40
  }
41
41
  }
@@ -35,6 +35,8 @@ var ok = require('./right/ok.cjs');
35
35
  var pipe = require('./right/pipe.cjs');
36
36
  var success$1 = require('./right/success.cjs');
37
37
  var when$1 = require('./right/when.cjs');
38
+ var group = require('./right/group.cjs');
39
+ var asyncGroup = require('./right/asyncGroup.cjs');
38
40
 
39
41
 
40
42
 
@@ -107,3 +109,5 @@ exports.rightPipe = pipe.rightPipe;
107
109
  exports.eitherSuccessKind = success$1.eitherSuccessKind;
108
110
  exports.success = success$1.success;
109
111
  exports.whenIsRight = when$1.whenIsRight;
112
+ exports.group = group.group;
113
+ exports.asyncGroup = asyncGroup.asyncGroup;
@@ -33,3 +33,5 @@ export { eitherOkKind, ok } from './right/ok.mjs';
33
33
  export { rightPipe } from './right/pipe.mjs';
34
34
  export { eitherSuccessKind, success } from './right/success.mjs';
35
35
  export { whenIsRight } from './right/when.mjs';
36
+ export { group } from './right/group.mjs';
37
+ export { asyncGroup } from './right/asyncGroup.mjs';
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var asyncPipe = require('../../common/asyncPipe.cjs');
4
+ var whenNot = require('../../common/whenNot.cjs');
5
+ var asyncReduce = require('../../generator/asyncReduce.cjs');
6
+ var reduce = require('../../generator/reduce.cjs');
7
+ var entries = require('../../object/entries.cjs');
8
+ var success = require('./success.cjs');
9
+ var is = require('../left/is.cjs');
10
+ var when = require('../../common/when.cjs');
11
+ var isType = require('../../common/isType.cjs');
12
+ var when$1 = require('./when.cjs');
13
+
14
+ function asyncGroup(group) {
15
+ return asyncPipe.asyncPipe(group, entries.entries, asyncReduce.asyncReduce(reduce.reduceFrom({}), ({ element: [key, value], lastValue, nextWithObject, exit }) => asyncPipe.asyncPipe(value, when.when(isType.isType("function"), (getter) => getter()), when.when(is.isLeft, exit), when$1.whenIsRight((data) => nextWithObject(lastValue, { [key]: data })))), whenNot.whenNot(is.isLeft, success.success));
16
+ }
17
+
18
+ exports.asyncGroup = asyncGroup;
@@ -0,0 +1,12 @@
1
+ import { type AnyFunction, type SimplifyTopLevel, type MayBeGetter, type Unwrap, type MaybePromise } from "../../common";
2
+ import { type EitherLeft } from "../left";
3
+ import { type EitherRight } from "./create";
4
+ import * as DEither from "..";
5
+ type Either = MaybePromise<EitherRight | EitherLeft>;
6
+ type ComputeResult<GenericGroup extends Record<string, MayBeGetter<Either>>> = Promise<DEither.EitherSuccess<SimplifyTopLevel<{
7
+ [Prop in keyof GenericGroup]: GenericGroup[Prop] extends AnyFunction ? Unwrap<Extract<Awaited<ReturnType<GenericGroup[Prop]>>, EitherRight>> : Unwrap<Extract<Awaited<GenericGroup[Prop]>, EitherRight>>;
8
+ }>> | {
9
+ [Prop in keyof GenericGroup]: GenericGroup[Prop] extends AnyFunction ? Extract<Awaited<ReturnType<GenericGroup[Prop]>>, EitherLeft> : Extract<Awaited<GenericGroup[Prop]>, EitherLeft>;
10
+ }[keyof GenericGroup]>;
11
+ export declare function asyncGroup<GenericGroup extends Record<string, MayBeGetter<Either>>>(group: GenericGroup): Extract<ComputeResult<GenericGroup>, any>;
12
+ export {};
@@ -0,0 +1,16 @@
1
+ import { asyncPipe } from '../../common/asyncPipe.mjs';
2
+ import { whenNot } from '../../common/whenNot.mjs';
3
+ import { asyncReduce } from '../../generator/asyncReduce.mjs';
4
+ import { reduceFrom } from '../../generator/reduce.mjs';
5
+ import { entries } from '../../object/entries.mjs';
6
+ import { success } from './success.mjs';
7
+ import { isLeft } from '../left/is.mjs';
8
+ import { when } from '../../common/when.mjs';
9
+ import { isType } from '../../common/isType.mjs';
10
+ import { whenIsRight } from './when.mjs';
11
+
12
+ function asyncGroup(group) {
13
+ return asyncPipe(group, entries, asyncReduce(reduceFrom({}), ({ element: [key, value], lastValue, nextWithObject, exit }) => asyncPipe(value, when(isType("function"), (getter) => getter()), when(isLeft, exit), whenIsRight((data) => nextWithObject(lastValue, { [key]: data })))), whenNot(isLeft, success));
14
+ }
15
+
16
+ export { asyncGroup };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var pipe = require('../../common/pipe.cjs');
4
+ var whenNot = require('../../common/whenNot.cjs');
5
+ var when = require('../../common/when.cjs');
6
+ var isType = require('../../common/isType.cjs');
7
+ var reduce = require('../../array/reduce.cjs');
8
+ var when$1 = require('./when.cjs');
9
+ var entries = require('../../object/entries.cjs');
10
+ var success = require('./success.cjs');
11
+ var is = require('../left/is.cjs');
12
+
13
+ function group(group) {
14
+ return pipe.pipe(group, entries.entries, reduce.reduce(reduce.reduceFrom({}), ({ element: [key, value], lastValue, nextWithObject, exit }) => pipe.pipe(value, when.when(isType.isType("function"), (getter) => getter()), when.when(is.isLeft, exit), when$1.whenIsRight((data) => nextWithObject(lastValue, { [key]: data })))), whenNot.whenNot(is.isLeft, success.success));
15
+ }
16
+
17
+ exports.group = group;
@@ -0,0 +1,12 @@
1
+ import { type AnyFunction, type SimplifyTopLevel, type MayBeGetter, type Unwrap } from "../../common";
2
+ import { type EitherLeft } from "../left";
3
+ import { type EitherRight } from "./create";
4
+ import * as DEither from "..";
5
+ type Either = EitherRight | EitherLeft;
6
+ type ComputeResult<GenericGroup extends Record<string, MayBeGetter<Either>>> = (DEither.EitherSuccess<SimplifyTopLevel<{
7
+ [Prop in keyof GenericGroup]: GenericGroup[Prop] extends AnyFunction ? Unwrap<Extract<ReturnType<GenericGroup[Prop]>, EitherRight>> : Unwrap<Extract<GenericGroup[Prop], EitherRight>>;
8
+ }>> | {
9
+ [Prop in keyof GenericGroup]: GenericGroup[Prop] extends AnyFunction ? Extract<ReturnType<GenericGroup[Prop]>, EitherLeft> : Extract<GenericGroup[Prop], EitherLeft>;
10
+ }[keyof GenericGroup]);
11
+ export declare function group<GenericGroup extends Record<string, MayBeGetter<Either>>>(group: GenericGroup): Extract<ComputeResult<GenericGroup>, any>;
12
+ export {};
@@ -0,0 +1,15 @@
1
+ import { pipe } from '../../common/pipe.mjs';
2
+ import { whenNot } from '../../common/whenNot.mjs';
3
+ import { when } from '../../common/when.mjs';
4
+ import { isType } from '../../common/isType.mjs';
5
+ import { reduce, reduceFrom } from '../../array/reduce.mjs';
6
+ import { whenIsRight } from './when.mjs';
7
+ import { entries } from '../../object/entries.mjs';
8
+ import { success } from './success.mjs';
9
+ import { isLeft } from '../left/is.mjs';
10
+
11
+ function group(group) {
12
+ return pipe(group, entries, reduce(reduceFrom({}), ({ element: [key, value], lastValue, nextWithObject, exit }) => pipe(value, when(isType("function"), (getter) => getter()), when(isLeft, exit), whenIsRight((data) => nextWithObject(lastValue, { [key]: data })))), whenNot(isLeft, success));
13
+ }
14
+
15
+ export { group };
@@ -5,3 +5,5 @@ export * from "./ok";
5
5
  export * from "./pipe";
6
6
  export * from "./success";
7
7
  export * from "./when";
8
+ export * from "./group";
9
+ export * from "./asyncGroup";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.3.19",
3
+ "version": "1.3.20",
4
4
  "author": "mathcovax",
5
5
  "license": "MIT",
6
6
  "type": "module",