@duplojs/utils 1.2.18 → 1.3.19

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 (218) hide show
  1. package/dist/array/every.cjs +6 -3
  2. package/dist/array/every.d.ts +4 -3
  3. package/dist/array/every.mjs +6 -3
  4. package/dist/array/fill/all.d.ts +2 -2
  5. package/dist/array/filter.cjs +6 -3
  6. package/dist/array/filter.d.ts +6 -5
  7. package/dist/array/filter.mjs +6 -3
  8. package/dist/array/flatMap.cjs +6 -3
  9. package/dist/array/flatMap.d.ts +4 -3
  10. package/dist/array/flatMap.mjs +6 -3
  11. package/dist/array/index.cjs +11 -10
  12. package/dist/array/index.d.ts +2 -0
  13. package/dist/array/index.mjs +4 -4
  14. package/dist/array/insert.cjs +12 -0
  15. package/dist/array/insert.d.ts +2 -0
  16. package/dist/array/insert.mjs +10 -0
  17. package/dist/array/isLastIndex.cjs +12 -0
  18. package/dist/array/isLastIndex.d.ts +2 -0
  19. package/dist/array/isLastIndex.mjs +10 -0
  20. package/dist/array/map.cjs +6 -3
  21. package/dist/array/map.d.ts +4 -3
  22. package/dist/array/map.mjs +6 -3
  23. package/dist/array/push.cjs +3 -3
  24. package/dist/array/push.d.ts +2 -2
  25. package/dist/array/push.mjs +3 -3
  26. package/dist/array/reduce.cjs +22 -9
  27. package/dist/array/reduce.d.ts +7 -4
  28. package/dist/array/reduce.mjs +22 -10
  29. package/dist/array/reduceRight.cjs +7 -10
  30. package/dist/array/reduceRight.d.ts +2 -2
  31. package/dist/array/reduceRight.mjs +7 -10
  32. package/dist/array/some.cjs +6 -3
  33. package/dist/array/some.d.ts +4 -3
  34. package/dist/array/some.mjs +6 -3
  35. package/dist/array/types/ArrayCoalescing.d.ts +1 -1
  36. package/dist/clean/constraint/base.cjs +77 -0
  37. package/dist/clean/constraint/base.d.ts +36 -0
  38. package/dist/clean/constraint/base.mjs +72 -0
  39. package/dist/{array/sort → clean/constraint/defaultConstraint}/index.d.ts +0 -1
  40. package/dist/clean/constraint/defaultConstraint/number.cjs +15 -0
  41. package/dist/clean/constraint/defaultConstraint/number.d.ts +8 -0
  42. package/dist/clean/constraint/defaultConstraint/number.mjs +11 -0
  43. package/dist/clean/constraint/defaultConstraint/string.cjs +12 -0
  44. package/dist/clean/constraint/defaultConstraint/string.d.ts +6 -0
  45. package/dist/clean/constraint/defaultConstraint/string.mjs +9 -0
  46. package/dist/clean/constraint/index.d.ts +2 -0
  47. package/dist/clean/entity.cjs +125 -0
  48. package/dist/clean/entity.d.ts +74 -0
  49. package/dist/clean/entity.mjs +121 -0
  50. package/dist/clean/flag.cjs +26 -0
  51. package/dist/clean/flag.d.ts +16 -0
  52. package/dist/clean/flag.mjs +23 -0
  53. package/dist/clean/index.cjs +84 -0
  54. package/dist/clean/index.d.ts +8 -0
  55. package/dist/clean/index.mjs +29 -0
  56. package/dist/clean/kind.cjs +9 -0
  57. package/dist/clean/kind.d.ts +1 -0
  58. package/dist/clean/kind.mjs +7 -0
  59. package/dist/clean/newType.cjs +91 -0
  60. package/dist/clean/newType.d.ts +38 -0
  61. package/dist/clean/newType.mjs +86 -0
  62. package/dist/clean/primitive/base.cjs +72 -0
  63. package/dist/clean/primitive/base.d.ts +36 -0
  64. package/dist/clean/primitive/base.mjs +64 -0
  65. package/dist/clean/primitive/index.d.ts +2 -0
  66. package/dist/clean/primitive/operations/date/dateGreaterThan.cjs +15 -0
  67. package/dist/clean/primitive/operations/date/dateGreaterThan.d.ts +4 -0
  68. package/dist/clean/primitive/operations/date/dateGreaterThan.mjs +13 -0
  69. package/dist/clean/primitive/operations/date/dateLessThan.cjs +15 -0
  70. package/dist/clean/primitive/operations/date/dateLessThan.d.ts +4 -0
  71. package/dist/clean/primitive/operations/date/dateLessThan.mjs +13 -0
  72. package/dist/clean/primitive/operations/date/dateMax.cjs +15 -0
  73. package/dist/clean/primitive/operations/date/dateMax.d.ts +5 -0
  74. package/dist/clean/primitive/operations/date/dateMax.mjs +13 -0
  75. package/dist/clean/primitive/operations/date/dateMin.cjs +15 -0
  76. package/dist/clean/primitive/operations/date/dateMin.d.ts +5 -0
  77. package/dist/clean/primitive/operations/date/dateMin.mjs +13 -0
  78. package/dist/clean/primitive/operations/date/index.d.ts +8 -0
  79. package/dist/clean/primitive/operations/equal.cjs +14 -0
  80. package/dist/clean/primitive/operations/equal.d.ts +4 -0
  81. package/dist/clean/primitive/operations/equal.mjs +12 -0
  82. package/dist/clean/primitive/operations/index.d.ts +5 -0
  83. package/dist/clean/primitive/operations/number/add.cjs +15 -0
  84. package/dist/clean/primitive/operations/number/add.d.ts +3 -0
  85. package/dist/clean/primitive/operations/number/add.mjs +13 -0
  86. package/dist/clean/primitive/operations/number/divide.cjs +15 -0
  87. package/dist/clean/primitive/operations/number/divide.d.ts +3 -0
  88. package/dist/clean/primitive/operations/number/divide.mjs +13 -0
  89. package/dist/clean/primitive/operations/number/greaterThan.cjs +14 -0
  90. package/dist/clean/primitive/operations/number/greaterThan.d.ts +3 -0
  91. package/dist/clean/primitive/operations/number/greaterThan.mjs +12 -0
  92. package/dist/clean/primitive/operations/number/index.d.ts +8 -0
  93. package/dist/clean/primitive/operations/number/lessThan.cjs +14 -0
  94. package/dist/clean/primitive/operations/number/lessThan.d.ts +3 -0
  95. package/dist/clean/primitive/operations/number/lessThan.mjs +12 -0
  96. package/dist/clean/primitive/operations/number/max.cjs +10 -0
  97. package/dist/clean/primitive/operations/number/max.d.ts +3 -0
  98. package/dist/clean/primitive/operations/number/max.mjs +8 -0
  99. package/dist/clean/primitive/operations/number/min.cjs +10 -0
  100. package/dist/clean/primitive/operations/number/min.d.ts +3 -0
  101. package/dist/clean/primitive/operations/number/min.mjs +8 -0
  102. package/dist/clean/primitive/operations/number/multiply.cjs +15 -0
  103. package/dist/clean/primitive/operations/number/multiply.d.ts +3 -0
  104. package/dist/clean/primitive/operations/number/multiply.mjs +13 -0
  105. package/dist/clean/primitive/operations/number/subtract.cjs +15 -0
  106. package/dist/clean/primitive/operations/number/subtract.d.ts +3 -0
  107. package/dist/clean/primitive/operations/number/subtract.mjs +13 -0
  108. package/dist/clean/primitive/operations/sort.cjs +35 -0
  109. package/dist/clean/primitive/operations/sort.d.ts +9 -0
  110. package/dist/clean/primitive/operations/sort.mjs +33 -0
  111. package/dist/clean/primitive/operations/string/concat.cjs +16 -0
  112. package/dist/clean/primitive/operations/string/concat.d.ts +3 -0
  113. package/dist/clean/primitive/operations/string/concat.mjs +14 -0
  114. package/dist/clean/primitive/operations/string/index.d.ts +5 -0
  115. package/dist/clean/primitive/operations/string/length.cjs +10 -0
  116. package/dist/clean/primitive/operations/string/length.d.ts +2 -0
  117. package/dist/clean/primitive/operations/string/length.mjs +8 -0
  118. package/dist/clean/primitive/operations/string/lengthEqual.cjs +14 -0
  119. package/dist/clean/primitive/operations/string/lengthEqual.d.ts +3 -0
  120. package/dist/clean/primitive/operations/string/lengthEqual.mjs +12 -0
  121. package/dist/clean/primitive/operations/string/lengthGreaterThan.cjs +14 -0
  122. package/dist/clean/primitive/operations/string/lengthGreaterThan.d.ts +3 -0
  123. package/dist/clean/primitive/operations/string/lengthGreaterThan.mjs +12 -0
  124. package/dist/clean/primitive/operations/string/lengthLessThan.cjs +14 -0
  125. package/dist/clean/primitive/operations/string/lengthLessThan.d.ts +3 -0
  126. package/dist/clean/primitive/operations/string/lengthLessThan.mjs +12 -0
  127. package/dist/clean/repository.cjs +15 -0
  128. package/dist/clean/repository.d.ts +8 -0
  129. package/dist/clean/repository.mjs +12 -0
  130. package/dist/clean/useCase.cjs +25 -0
  131. package/dist/clean/useCase.d.ts +23 -0
  132. package/dist/clean/useCase.mjs +21 -0
  133. package/dist/common/index.d.ts +0 -1
  134. package/dist/common/kind.d.ts +1 -0
  135. package/dist/common/types/index.d.ts +1 -0
  136. package/dist/common/types/sortType.d.ts +1 -0
  137. package/dist/common/unwrap.d.ts +1 -2
  138. package/dist/dataParser/base.d.ts +5 -4
  139. package/dist/dataParser/baseExtended.d.ts +2 -1
  140. package/dist/dataParser/extended/index.d.ts +1 -0
  141. package/dist/dataParser/extended/number.cjs +3 -0
  142. package/dist/dataParser/extended/number.d.ts +3 -0
  143. package/dist/dataParser/extended/number.mjs +3 -0
  144. package/dist/dataParser/extended/object.cjs +8 -13
  145. package/dist/dataParser/extended/object.d.ts +2 -0
  146. package/dist/dataParser/extended/object.mjs +8 -13
  147. package/dist/dataParser/identifier.d.ts +40 -40
  148. package/dist/dataParser/index.cjs +4 -0
  149. package/dist/dataParser/index.mjs +2 -0
  150. package/dist/dataParser/parsers/array/index.cjs +2 -2
  151. package/dist/dataParser/parsers/array/index.mjs +2 -2
  152. package/dist/dataParser/parsers/literal.d.ts +1 -1
  153. package/dist/dataParser/parsers/object/index.cjs +3 -3
  154. package/dist/dataParser/parsers/object/index.d.ts +2 -0
  155. package/dist/dataParser/parsers/object/index.mjs +3 -3
  156. package/dist/dataParser/parsers/object/partial.cjs +20 -0
  157. package/dist/dataParser/parsers/object/partial.d.ts +14 -0
  158. package/dist/dataParser/parsers/object/partial.mjs +18 -0
  159. package/dist/dataParser/parsers/object/required.cjs +20 -0
  160. package/dist/dataParser/parsers/object/required.d.ts +10 -0
  161. package/dist/dataParser/parsers/object/required.mjs +18 -0
  162. package/dist/dataParser/parsers/record/index.cjs +2 -2
  163. package/dist/dataParser/parsers/record/index.mjs +2 -2
  164. package/dist/dataParser/parsers/recover.d.ts +1 -1
  165. package/dist/dataParser/parsers/refine.d.ts +1 -1
  166. package/dist/dataParser/parsers/tuple.cjs +2 -2
  167. package/dist/dataParser/parsers/tuple.mjs +2 -2
  168. package/dist/date/index.cjs +8 -0
  169. package/dist/date/index.d.ts +4 -0
  170. package/dist/date/index.mjs +4 -0
  171. package/dist/date/is.cjs +9 -0
  172. package/dist/date/is.d.ts +2 -0
  173. package/dist/date/is.mjs +7 -0
  174. package/dist/date/max.cjs +10 -0
  175. package/dist/date/max.d.ts +3 -0
  176. package/dist/date/max.mjs +8 -0
  177. package/dist/date/min.cjs +10 -0
  178. package/dist/date/min.d.ts +3 -0
  179. package/dist/date/min.mjs +8 -0
  180. package/dist/date/sort.cjs +20 -0
  181. package/dist/date/sort.d.ts +4 -0
  182. package/dist/date/sort.mjs +18 -0
  183. package/dist/generator/reduce.cjs +2 -6
  184. package/dist/generator/reduce.d.ts +1 -0
  185. package/dist/generator/reduce.mjs +2 -6
  186. package/dist/index.cjs +3 -2
  187. package/dist/index.d.ts +2 -0
  188. package/dist/index.mjs +3 -1
  189. package/dist/number/index.cjs +2 -0
  190. package/dist/number/index.d.ts +1 -0
  191. package/dist/number/index.mjs +1 -0
  192. package/dist/number/max.cjs +2 -7
  193. package/dist/number/max.d.ts +2 -2
  194. package/dist/number/max.mjs +2 -7
  195. package/dist/number/min.cjs +2 -7
  196. package/dist/number/min.d.ts +2 -2
  197. package/dist/number/min.mjs +2 -7
  198. package/dist/number/sort.cjs +14 -0
  199. package/dist/number/sort.d.ts +3 -0
  200. package/dist/number/sort.mjs +12 -0
  201. package/dist/pattern/when.d.ts +5 -5
  202. package/dist/string/index.cjs +2 -0
  203. package/dist/string/index.d.ts +1 -0
  204. package/dist/string/index.mjs +1 -0
  205. package/dist/{array/sort/string.cjs → string/sort.cjs} +6 -6
  206. package/dist/string/sort.d.ts +3 -0
  207. package/dist/{array/sort/string.mjs → string/sort.mjs} +6 -6
  208. package/package.json +7 -2
  209. package/dist/array/sort/number.cjs +0 -14
  210. package/dist/array/sort/number.d.ts +0 -4
  211. package/dist/array/sort/number.mjs +0 -12
  212. package/dist/array/sort/string.d.ts +0 -4
  213. package/dist/common/not.cjs +0 -12
  214. package/dist/common/not.d.ts +0 -2
  215. package/dist/common/not.mjs +0 -10
  216. /package/dist/array/{sort/default.cjs → sort.cjs} +0 -0
  217. /package/dist/array/{sort/default.d.ts → sort.d.ts} +0 -0
  218. /package/dist/array/{sort/default.mjs → sort.mjs} +0 -0
@@ -3,10 +3,13 @@
3
3
  function some(...args) {
4
4
  if (args.length === 1) {
5
5
  const [predicate] = args;
6
- return (array) => some(array, predicate);
6
+ return (input) => some(input, predicate);
7
7
  }
8
- const [array, predicate] = args;
9
- return array.some((element, index) => predicate(element, { index }));
8
+ const [input, predicate] = args;
9
+ return input.some((element, index) => predicate(element, {
10
+ index,
11
+ self: input,
12
+ }));
10
13
  }
11
14
 
12
15
  exports.some = some;
@@ -1,6 +1,7 @@
1
- interface ArraySomeParams {
1
+ interface ArraySomeParams<GenericInputArray extends readonly unknown[]> {
2
2
  index: number;
3
+ self: GenericInputArray;
3
4
  }
4
- export declare function some<GenericArray extends readonly unknown[]>(predicate: (element: GenericArray[number], params: ArraySomeParams) => boolean): (array: GenericArray) => boolean;
5
- export declare function some<GenericElement extends unknown>(array: readonly GenericElement[], predicate: (element: GenericElement, params: ArraySomeParams) => boolean): boolean;
5
+ export declare function some<GenericInput extends readonly unknown[]>(predicate: (element: GenericInput[number], params: ArraySomeParams<GenericInput>) => boolean): (input: GenericInput) => boolean;
6
+ export declare function some<GenericInput extends readonly unknown[]>(input: GenericInput, predicate: (element: GenericInput[number], params: ArraySomeParams<GenericInput>) => boolean): boolean;
6
7
  export {};
@@ -1,10 +1,13 @@
1
1
  function some(...args) {
2
2
  if (args.length === 1) {
3
3
  const [predicate] = args;
4
- return (array) => some(array, predicate);
4
+ return (input) => some(input, predicate);
5
5
  }
6
- const [array, predicate] = args;
7
- return array.some((element, index) => predicate(element, { index }));
6
+ const [input, predicate] = args;
7
+ return input.some((element, index) => predicate(element, {
8
+ index,
9
+ self: input,
10
+ }));
8
11
  }
9
12
 
10
13
  export { some };
@@ -1 +1 @@
1
- export type ArrayCoalescing<GenericValue extends unknown> = GenericValue extends readonly any[] ? GenericValue : [GenericValue];
1
+ export type ArrayCoalescing<GenericValue extends unknown> = GenericValue extends readonly any[] ? GenericValue : readonly [GenericValue];
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var kind = require('../kind.cjs');
4
+ var kind$1 = require('../../common/kind.cjs');
5
+ var coalescing = require('../../array/coalescing.cjs');
6
+ var errorKindNamespace = require('../../common/errorKindNamespace.cjs');
7
+ var is = require('../../either/left/is.cjs');
8
+ var unwrap = require('../../common/unwrap.cjs');
9
+ var create = require('../../either/left/create.cjs');
10
+ var create$1 = require('../../either/right/create.cjs');
11
+ var wrapValue = require('../../common/wrapValue.cjs');
12
+
13
+ const constrainedTypeKind = kind.createCleanKind("constrained-type");
14
+ const constraintHandlerKind = kind.createCleanKind("constraint-handler");
15
+ class CreateConstrainedTypeError extends kind$1.kindHeritage("create-constrained-type-error", errorKindNamespace.createErrorKind("create-constrained-type-error"), Error) {
16
+ constrainedTypeName;
17
+ data;
18
+ dataParserError;
19
+ constructor(constrainedTypeName, data, dataParserError) {
20
+ super({}, [`Error when create constrained type ${constrainedTypeName}.`]);
21
+ this.constrainedTypeName = constrainedTypeName;
22
+ this.data = data;
23
+ this.dataParserError = dataParserError;
24
+ }
25
+ }
26
+ function createConstraint(name, primitiveHandler, checker) {
27
+ const checkers = coalescing.coalescing(checker);
28
+ const dataParserWithCheckers = primitiveHandler
29
+ .dataParser
30
+ .addChecker(...checkers);
31
+ function create$2(data) {
32
+ const result = dataParserWithCheckers.parse(unwrap.unwrap(data));
33
+ if (is.isLeft(result)) {
34
+ return create.left("createConstrainedTypeError", unwrap.unwrap(result));
35
+ }
36
+ else if (constrainedTypeKind.has(data)) {
37
+ return create$1.right("createConstrainedType", constrainedTypeKind.addTo(data, {
38
+ ...constrainedTypeKind.getValue(data),
39
+ [name]: null,
40
+ }));
41
+ }
42
+ else {
43
+ return create$1.right("createConstrainedType", constrainedTypeKind.setTo(wrapValue.wrapValue(unwrap.unwrap(result)), { [name]: null }));
44
+ }
45
+ }
46
+ function createOrThrow(data) {
47
+ const result = create$2(data);
48
+ if (is.isLeft(result)) {
49
+ throw new CreateConstrainedTypeError(name, data, unwrap.unwrap(result));
50
+ }
51
+ else {
52
+ return unwrap.unwrap(result);
53
+ }
54
+ }
55
+ function is$1(input) {
56
+ if (constrainedTypeKind.has(input)
57
+ && constrainedTypeKind.getValue(input)[name] === null) {
58
+ return true;
59
+ }
60
+ return false;
61
+ }
62
+ return constraintHandlerKind.setTo({
63
+ name,
64
+ primitiveHandler,
65
+ checkers,
66
+ create: create$2,
67
+ createOrThrow,
68
+ createWithUnknown: create$2,
69
+ createWithUnknownOrThrow: createOrThrow,
70
+ is: is$1,
71
+ });
72
+ }
73
+
74
+ exports.CreateConstrainedTypeError = CreateConstrainedTypeError;
75
+ exports.constrainedTypeKind = constrainedTypeKind;
76
+ exports.constraintHandlerKind = constraintHandlerKind;
77
+ exports.createConstraint = createConstraint;
@@ -0,0 +1,36 @@
1
+ import { type Unwrap, type Kind, type WrappedValue } from "../..";
2
+ import { type Primitive, type EligiblePrimitive, type PrimitiveHandler } from "../primitive";
3
+ import * as DArray from "../../array";
4
+ import * as DEither from "../../either";
5
+ import type * as DDataParser from "../../dataParser";
6
+ export declare const constrainedTypeKind: import("../..").KindHandler<import("../..").KindDefinition<"@DuplojsUtilsClean/constrained-type", Record<string, unknown>>>;
7
+ export interface ConstrainedType<GenericName extends string, GenericValue extends unknown> extends Kind<typeof constrainedTypeKind.definition, Record<GenericName, unknown>>, WrappedValue<GenericValue> {
8
+ }
9
+ export declare const constraintHandlerKind: import("../..").KindHandler<import("../..").KindDefinition<"@DuplojsUtilsClean/constraint-handler", unknown>>;
10
+ export interface ConstraintHandler<GenericName extends string = string, GenericPrimitiveValue extends EligiblePrimitive = EligiblePrimitive, GenericCheckers extends readonly DDataParser.DataParserChecker[] = readonly DDataParser.DataParserChecker[]> extends Kind<typeof constraintHandlerKind.definition> {
11
+ readonly name: GenericName;
12
+ readonly checkers: GenericCheckers;
13
+ readonly primitiveHandler: PrimitiveHandler<GenericPrimitiveValue>;
14
+ create<GenericData extends GenericPrimitiveValue>(data: GenericData): (DEither.EitherRight<"createConstrainedType", ConstrainedType<GenericName, GenericData>> | DEither.EitherLeft<"createConstrainedTypeError", DDataParser.DataParserError>);
15
+ create<GenericPrimitive extends Primitive<GenericPrimitiveValue>>(data: GenericPrimitive): (DEither.EitherRight<"createConstrainedType", (GenericPrimitive & ConstrainedType<GenericName, Unwrap<GenericPrimitive>>)> | DEither.EitherLeft<"createConstrainedTypeError", DDataParser.DataParserError>);
16
+ createOrThrow<GenericData extends GenericPrimitiveValue>(data: GenericData): ConstrainedType<GenericName, GenericData>;
17
+ createOrThrow<GenericPrimitive extends Primitive<GenericPrimitiveValue>>(data: GenericPrimitive): (GenericPrimitive & ConstrainedType<GenericName, Unwrap<GenericPrimitive>>);
18
+ createWithUnknown<GenericData extends unknown>(data: GenericData): (DEither.EitherRight<"createConstrainedType", ConstrainedType<GenericName, GenericPrimitiveValue>> | DEither.EitherLeft<"createConstrainedTypeError", DDataParser.DataParserError>);
19
+ createWithUnknownOrThrow<GenericData extends unknown>(data: GenericData): ConstrainedType<GenericName, GenericPrimitiveValue>;
20
+ is<GenericInput extends WrappedValue>(input: GenericInput): input is Extract<GenericInput, ConstrainedType<GenericName, GenericPrimitiveValue>>;
21
+ }
22
+ declare const CreateConstrainedTypeError_base: new (params: {
23
+ "@DuplojsUtilsError/create-constrained-type-error"?: unknown;
24
+ }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../..").KindDefinition<"create-constrained-type-error", unknown>, unknown> & Kind<import("../..").KindDefinition<"@DuplojsUtilsError/create-constrained-type-error", unknown>, unknown>;
25
+ export declare class CreateConstrainedTypeError extends CreateConstrainedTypeError_base {
26
+ constrainedTypeName: string;
27
+ data: unknown;
28
+ dataParserError: DDataParser.DataParserError;
29
+ constructor(constrainedTypeName: string, data: unknown, dataParserError: DDataParser.DataParserError);
30
+ }
31
+ export declare function createConstraint<GenericName extends string, GenericPrimitiveValue extends EligiblePrimitive, const GenericChecker extends (DDataParser.DataParserChecker<DDataParser.DataParserCheckerDefinition, GenericPrimitiveValue> | readonly [
32
+ DDataParser.DataParserChecker<DDataParser.DataParserCheckerDefinition, GenericPrimitiveValue>,
33
+ ...DDataParser.DataParserChecker<DDataParser.DataParserCheckerDefinition, GenericPrimitiveValue>[]
34
+ ]) = never>(name: GenericName, primitiveHandler: PrimitiveHandler<GenericPrimitiveValue>, checker: GenericChecker): ConstraintHandler<GenericName, GenericPrimitiveValue, DArray.ArrayCoalescing<GenericChecker>>;
35
+ export type Constraint<GenericConstrainHandler extends ConstraintHandler, GenericValue extends DDataParser.InputChecker<GenericConstrainHandler["checkers"][number]> = DDataParser.InputChecker<GenericConstrainHandler["checkers"][number]>> = Extract<ConstrainedType<GenericConstrainHandler["name"], GenericValue>, any>;
36
+ export {};
@@ -0,0 +1,72 @@
1
+ import { createCleanKind } from '../kind.mjs';
2
+ import { kindHeritage } from '../../common/kind.mjs';
3
+ import { coalescing } from '../../array/coalescing.mjs';
4
+ import { createErrorKind } from '../../common/errorKindNamespace.mjs';
5
+ import { isLeft } from '../../either/left/is.mjs';
6
+ import { unwrap } from '../../common/unwrap.mjs';
7
+ import { left } from '../../either/left/create.mjs';
8
+ import { right } from '../../either/right/create.mjs';
9
+ import { wrapValue } from '../../common/wrapValue.mjs';
10
+
11
+ const constrainedTypeKind = createCleanKind("constrained-type");
12
+ const constraintHandlerKind = createCleanKind("constraint-handler");
13
+ class CreateConstrainedTypeError extends kindHeritage("create-constrained-type-error", createErrorKind("create-constrained-type-error"), Error) {
14
+ constrainedTypeName;
15
+ data;
16
+ dataParserError;
17
+ constructor(constrainedTypeName, data, dataParserError) {
18
+ super({}, [`Error when create constrained type ${constrainedTypeName}.`]);
19
+ this.constrainedTypeName = constrainedTypeName;
20
+ this.data = data;
21
+ this.dataParserError = dataParserError;
22
+ }
23
+ }
24
+ function createConstraint(name, primitiveHandler, checker) {
25
+ const checkers = coalescing(checker);
26
+ const dataParserWithCheckers = primitiveHandler
27
+ .dataParser
28
+ .addChecker(...checkers);
29
+ function create(data) {
30
+ const result = dataParserWithCheckers.parse(unwrap(data));
31
+ if (isLeft(result)) {
32
+ return left("createConstrainedTypeError", unwrap(result));
33
+ }
34
+ else if (constrainedTypeKind.has(data)) {
35
+ return right("createConstrainedType", constrainedTypeKind.addTo(data, {
36
+ ...constrainedTypeKind.getValue(data),
37
+ [name]: null,
38
+ }));
39
+ }
40
+ else {
41
+ return right("createConstrainedType", constrainedTypeKind.setTo(wrapValue(unwrap(result)), { [name]: null }));
42
+ }
43
+ }
44
+ function createOrThrow(data) {
45
+ const result = create(data);
46
+ if (isLeft(result)) {
47
+ throw new CreateConstrainedTypeError(name, data, unwrap(result));
48
+ }
49
+ else {
50
+ return unwrap(result);
51
+ }
52
+ }
53
+ function is(input) {
54
+ if (constrainedTypeKind.has(input)
55
+ && constrainedTypeKind.getValue(input)[name] === null) {
56
+ return true;
57
+ }
58
+ return false;
59
+ }
60
+ return constraintHandlerKind.setTo({
61
+ name,
62
+ primitiveHandler,
63
+ checkers,
64
+ create,
65
+ createOrThrow,
66
+ createWithUnknown: create,
67
+ createWithUnknownOrThrow: createOrThrow,
68
+ is,
69
+ });
70
+ }
71
+
72
+ export { CreateConstrainedTypeError, constrainedTypeKind, constraintHandlerKind, createConstraint };
@@ -1,3 +1,2 @@
1
- export * from "./default";
2
1
  export * from "./number";
3
2
  export * from "./string";
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var base = require('../base.cjs');
4
+ var base$1 = require('../../primitive/base.cjs');
5
+ var int = require('../../../dataParser/parsers/number/checkers/int.cjs');
6
+ var min = require('../../../dataParser/parsers/number/checkers/min.cjs');
7
+ var max = require('../../../dataParser/parsers/number/checkers/max.cjs');
8
+
9
+ const Int = base.createConstraint("int", base$1.Number, int.checkerInt());
10
+ const Positive = base.createConstraint("positive", base$1.Number, min.checkerNumberMin(1));
11
+ const Negative = base.createConstraint("negative", base$1.Number, max.checkerNumberMax(-1));
12
+
13
+ exports.Int = Int;
14
+ exports.Negative = Negative;
15
+ exports.Positive = Positive;
@@ -0,0 +1,8 @@
1
+ import { type Constraint } from "../base";
2
+ import * as DDataParser from "../../../dataParser";
3
+ export declare const Int: import("..").ConstraintHandler<"int", number, readonly [DDataParser.DataParserCheckerInt]>;
4
+ export type Int = Constraint<typeof Int>;
5
+ export declare const Positive: import("..").ConstraintHandler<"positive", number, readonly [DDataParser.DataParserCheckerNumberMin]>;
6
+ export type Positive = Constraint<typeof Positive>;
7
+ export declare const Negative: import("..").ConstraintHandler<"negative", number, readonly [DDataParser.DataParserCheckerNumberMax]>;
8
+ export type Negative = Constraint<typeof Negative>;
@@ -0,0 +1,11 @@
1
+ import { createConstraint } from '../base.mjs';
2
+ import { Number } from '../../primitive/base.mjs';
3
+ import { checkerInt } from '../../../dataParser/parsers/number/checkers/int.mjs';
4
+ import { checkerNumberMin } from '../../../dataParser/parsers/number/checkers/min.mjs';
5
+ import { checkerNumberMax } from '../../../dataParser/parsers/number/checkers/max.mjs';
6
+
7
+ const Int = createConstraint("int", Number, checkerInt());
8
+ const Positive = createConstraint("positive", Number, checkerNumberMin(1));
9
+ const Negative = createConstraint("negative", Number, checkerNumberMax(-1));
10
+
11
+ export { Int, Negative, Positive };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var base = require('../base.cjs');
4
+ var base$1 = require('../../primitive/base.cjs');
5
+ var email = require('../../../dataParser/parsers/string/checkers/email.cjs');
6
+ var url = require('../../../dataParser/parsers/string/checkers/url.cjs');
7
+
8
+ const Email = base.createConstraint("email", base$1.String, email.checkerEmail());
9
+ const Url = base.createConstraint("url", base$1.String, url.checkerUrl());
10
+
11
+ exports.Email = Email;
12
+ exports.Url = Url;
@@ -0,0 +1,6 @@
1
+ import { type Constraint } from "../base";
2
+ import * as DDataParser from "../../../dataParser";
3
+ export declare const Email: import("..").ConstraintHandler<"email", string, readonly [DDataParser.DataParserCheckerEmail]>;
4
+ export type Email = Constraint<typeof Email>;
5
+ export declare const Url: import("..").ConstraintHandler<"url", string, readonly [DDataParser.DataParserCheckerUrl]>;
6
+ export type Url = Constraint<typeof Url>;
@@ -0,0 +1,9 @@
1
+ import { createConstraint } from '../base.mjs';
2
+ import { String } from '../../primitive/base.mjs';
3
+ import { checkerEmail } from '../../../dataParser/parsers/string/checkers/email.mjs';
4
+ import { checkerUrl } from '../../../dataParser/parsers/string/checkers/url.mjs';
5
+
6
+ const Email = createConstraint("email", String, checkerEmail());
7
+ const Url = createConstraint("url", String, checkerUrl());
8
+
9
+ export { Email, Url };
@@ -0,0 +1,2 @@
1
+ export * from "./base";
2
+ export * from "./defaultConstraint";
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ var kind = require('./kind.cjs');
4
+ var newType = require('./newType.cjs');
5
+ var kind$1 = require('../common/kind.cjs');
6
+ var pipe = require('../common/pipe.cjs');
7
+ var filter = require('../array/filter.cjs');
8
+ var isType = require('../common/isType.cjs');
9
+ var map = require('../array/map.cjs');
10
+ var entry = require('../object/entry.cjs');
11
+ var toTuple = require('../array/toTuple.cjs');
12
+ var first = require('../array/at/first.cjs');
13
+ var innerPipe = require('../common/innerPipe.cjs');
14
+ var when = require('../pattern/when.cjs');
15
+ var exhaustive = require('../pattern/exhaustive.cjs');
16
+ var when$1 = require('../common/when.cjs');
17
+ var index = require('../dataParser/parsers/array/index.cjs');
18
+ var min = require('../dataParser/parsers/array/checkers/min.cjs');
19
+ var max = require('../dataParser/parsers/array/checkers/max.cjs');
20
+ var nullable = require('../dataParser/parsers/nullable.cjs');
21
+ var base = require('../dataParser/base.cjs');
22
+ var last = require('../array/at/last.cjs');
23
+ var entries = require('../object/entries.cjs');
24
+ var forward = require('../common/forward.cjs');
25
+ var errorKindNamespace = require('../common/errorKindNamespace.cjs');
26
+ var fromEntries = require('../object/fromEntries.cjs');
27
+ var transform = require('../dataParser/parsers/transform.cjs');
28
+ var base$1 = require('./constraint/base.cjs');
29
+ var wrapValue = require('../common/wrapValue.cjs');
30
+ var otherwise = require('../pattern/otherwise.cjs');
31
+ var justReturn = require('../common/justReturn.cjs');
32
+ var union = require('../dataParser/parsers/union.cjs');
33
+ var minElements = require('../array/minElements.cjs');
34
+ var is = require('../either/left/is.cjs');
35
+ var unwrap = require('../common/unwrap.cjs');
36
+ var create = require('../either/left/create.cjs');
37
+ var create$1 = require('../either/right/create.cjs');
38
+ var index$1 = require('../dataParser/parsers/object/index.cjs');
39
+
40
+ const entityKind = kind.createCleanKind("entity");
41
+ const entityHandlerKind = kind.createCleanKind("entity-handler");
42
+ class CreateEntityError extends kind$1.kindHeritage("create-entity-error", errorKindNamespace.createErrorKind("create-entity-error"), Error) {
43
+ rawProperties;
44
+ dataParserError;
45
+ constructor(rawProperties, dataParserError) {
46
+ super({}, ["Error when create entity."]);
47
+ this.rawProperties = rawProperties;
48
+ this.dataParserError = dataParserError;
49
+ }
50
+ }
51
+ function createEntity(name, getPropertiesDefinition) {
52
+ function theNew(properties) {
53
+ return entityKind.addTo(properties, name);
54
+ }
55
+ function simplePropertyDefinitionToDataParser(simplePropertyDefinition) {
56
+ const constraintKindValue = pipe.pipe(simplePropertyDefinition.constrains, map.map(({ name }) => entry.entry(name, null)), fromEntries.fromEntries);
57
+ return transform.transform(simplePropertyDefinition.dataParser, (value) => base$1.constrainedTypeKind.setTo(newType.newTypeKind.setTo(wrapValue.wrapValue(value), simplePropertyDefinition.name), constraintKindValue));
58
+ }
59
+ function unionPropertyDefinitionToDataParser(unionPropertyDefinition) {
60
+ return pipe.pipe(unionPropertyDefinition, map.map(simplePropertyDefinitionToDataParser), when.when(minElements.minElements(1), union.union), otherwise.otherwise(justReturn.justReturn(null)));
61
+ }
62
+ const params = {
63
+ union: (...type) => ({ type }),
64
+ array: (definition, params) => (newType.newTypeHandlerKind.has(definition) || definition instanceof Array
65
+ ? {
66
+ type: definition,
67
+ inArray: params ?? true,
68
+ }
69
+ : {
70
+ ...definition,
71
+ inArray: params ?? true,
72
+ }),
73
+ nullable: (definition) => (newType.newTypeHandlerKind.has(definition) || definition instanceof Array
74
+ ? {
75
+ type: definition,
76
+ nullable: true,
77
+ }
78
+ : {
79
+ ...definition,
80
+ nullable: true,
81
+ }),
82
+ };
83
+ const propertiesDefinition = getPropertiesDefinition(params);
84
+ const mapDataParser = pipe.pipe(forward.forward(propertiesDefinition), entries.entries, map.map(toTuple.toTuple([
85
+ first.first,
86
+ innerPipe.innerPipe(last.last, when.when(newType.newTypeHandlerKind.has, simplePropertyDefinitionToDataParser), when.when(isType.isType("array"), unionPropertyDefinitionToDataParser), when.when(isType.isType("object"), (definition) => pipe.pipe(definition.type, when.when(newType.newTypeHandlerKind.has, simplePropertyDefinitionToDataParser), when.when(isType.isType("array"), unionPropertyDefinitionToDataParser), exhaustive.exhaustive, when$1.when(base.dataParserKind.has, innerPipe.innerPipe((dataParser) => {
87
+ if (definition.inArray) {
88
+ return pipe.pipe(index.array(dataParser), (dataParser) => typeof definition.inArray === "object"
89
+ && definition.inArray.min !== undefined
90
+ ? dataParser.addChecker(min.checkerArrayMin(definition.inArray.min))
91
+ : dataParser, (dataParser) => typeof definition.inArray === "object"
92
+ && definition.inArray.max !== undefined
93
+ ? dataParser.addChecker(max.checkerArrayMax(definition.inArray.max))
94
+ : dataParser);
95
+ }
96
+ return dataParser;
97
+ }, when$1.when(() => definition.nullable === true, nullable.nullable))))), exhaustive.exhaustive),
98
+ ])), map.map(([key, value]) => value !== null && entry.entry(key, value)), filter.filter(isType.isType("array")), fromEntries.fromEntries, index$1.object, (dataParser) => transform.transform(dataParser, (value) => entityKind.setTo(value, name)));
99
+ function map$1(rawProperties) {
100
+ const result = mapDataParser.parse(rawProperties);
101
+ if (is.isLeft(result)) {
102
+ return create.left("createEntityError", unwrap.unwrap(result));
103
+ }
104
+ return create$1.right("createEntity", unwrap.unwrap(result));
105
+ }
106
+ function mapOrThrow(rawProperties) {
107
+ const result = mapDataParser.parse(rawProperties);
108
+ if (is.isLeft(result)) {
109
+ throw new CreateEntityError(rawProperties, unwrap.unwrap(result));
110
+ }
111
+ return unwrap.unwrap(result);
112
+ }
113
+ return entityHandlerKind.setTo({
114
+ name,
115
+ propertiesDefinition,
116
+ mapDataParser,
117
+ new: theNew,
118
+ map: map$1,
119
+ mapOrThrow,
120
+ });
121
+ }
122
+
123
+ exports.CreateEntityError = CreateEntityError;
124
+ exports.createEntity = createEntity;
125
+ exports.entityKind = entityKind;
@@ -0,0 +1,74 @@
1
+ import { type SimplifyTopLevel, type Kind, type Unwrap, type IsEqual, type IsExtends, type Or, type NeverCoalescing } from "../common";
2
+ import { type GetNewType, type NewTypeHandler } from "./newType";
3
+ import * as DEither from "../either";
4
+ import * as DDataParser from "../dataParser";
5
+ import * as DObject from "../object";
6
+ import * as DArray from "../array";
7
+ export type EntitySimplePropertyDefinition = NewTypeHandler<string, unknown, readonly any[]>;
8
+ export type EntityUnionPropertyDefinition = readonly [
9
+ EntitySimplePropertyDefinition,
10
+ ...EntitySimplePropertyDefinition[]
11
+ ];
12
+ export interface EntityAdvancedArrayPropertyDefinition {
13
+ min?: number;
14
+ max?: number;
15
+ }
16
+ export interface EntityAdvancedPropertyDefinition {
17
+ type: (EntitySimplePropertyDefinition | EntityUnionPropertyDefinition);
18
+ nullable?: true;
19
+ inArray?: true | EntityAdvancedArrayPropertyDefinition;
20
+ }
21
+ export type EntityPropertyDefinition = (EntitySimplePropertyDefinition | EntityUnionPropertyDefinition | EntityAdvancedPropertyDefinition);
22
+ export type EntityPropertiesDefinition = Readonly<Record<string, EntityPropertyDefinition>>;
23
+ export type EntityProperties<GenericPropertiesDefinition extends EntityPropertiesDefinition = EntityPropertiesDefinition> = SimplifyTopLevel<{
24
+ readonly [Prop in keyof GenericPropertiesDefinition]: (GenericPropertiesDefinition[Prop] extends EntitySimplePropertyDefinition ? GetNewType<GenericPropertiesDefinition[Prop]> : GenericPropertiesDefinition[Prop] extends EntityUnionPropertyDefinition ? GetNewType<GenericPropertiesDefinition[Prop][number]> : GenericPropertiesDefinition[Prop] extends EntityAdvancedPropertyDefinition ? GetNewType<GenericPropertiesDefinition[Prop]["type"] extends EntityUnionPropertyDefinition ? GenericPropertiesDefinition[Prop]["type"][number] : GenericPropertiesDefinition[Prop]["type"] extends EntitySimplePropertyDefinition ? GenericPropertiesDefinition[Prop]["type"] : never> extends infer InferredValue ? (IsEqual<GenericPropertiesDefinition[Prop]["inArray"], true> extends true ? readonly InferredValue[] : GenericPropertiesDefinition[Prop]["inArray"] extends object ? GenericPropertiesDefinition[Prop]["inArray"]["min"] extends number ? readonly [
25
+ ...DArray.CreateTuple<InferredValue, GenericPropertiesDefinition[Prop]["inArray"]["min"]>,
26
+ ...InferredValue[]
27
+ ] : readonly InferredValue[] : InferredValue) extends infer InferredValueWithArray ? IsEqual<GenericPropertiesDefinition[Prop]["nullable"], true> extends true ? InferredValueWithArray | null : InferredValueWithArray : never : never : unknown);
28
+ }>;
29
+ export type EntityRawProperties<GenericPropertiesDefinition extends EntityPropertiesDefinition = EntityPropertiesDefinition> = SimplifyTopLevel<{
30
+ readonly [Prop in keyof GenericPropertiesDefinition]: (GenericPropertiesDefinition[Prop] extends EntitySimplePropertyDefinition ? Unwrap<GetNewType<GenericPropertiesDefinition[Prop]>> : GenericPropertiesDefinition[Prop] extends EntityUnionPropertyDefinition ? Unwrap<GetNewType<GenericPropertiesDefinition[Prop][number]>> : GenericPropertiesDefinition[Prop] extends EntityAdvancedPropertyDefinition ? Unwrap<GetNewType<GenericPropertiesDefinition[Prop]["type"] extends EntityUnionPropertyDefinition ? GenericPropertiesDefinition[Prop]["type"][number] : GenericPropertiesDefinition[Prop]["type"] extends EntitySimplePropertyDefinition ? GenericPropertiesDefinition[Prop]["type"] : never>> extends infer InferredValue ? (Or<[
31
+ IsEqual<GenericPropertiesDefinition[Prop]["inArray"], true>,
32
+ IsExtends<GenericPropertiesDefinition[Prop]["inArray"], object>
33
+ ]> extends true ? readonly InferredValue[] : InferredValue) extends infer InferredValueWithArray ? IsEqual<GenericPropertiesDefinition[Prop]["nullable"], true> extends true ? InferredValueWithArray | null : InferredValueWithArray : never : never : never);
34
+ }>;
35
+ export declare const entityKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsClean/entity", string>>;
36
+ export interface Entity<GenericName extends string = string> extends Kind<typeof entityKind.definition, GenericName> {
37
+ }
38
+ declare const entityHandlerKind: import("../common").KindHandler<import("../common").KindDefinition<"@DuplojsUtilsClean/entity-handler", unknown>>;
39
+ export interface EntityHandler<GenericName extends string = string, GenericPropertiesDefinition extends EntityPropertiesDefinition = EntityPropertiesDefinition> extends Kind<typeof entityHandlerKind.definition> {
40
+ readonly name: GenericName;
41
+ readonly propertiesDefinition: GenericPropertiesDefinition;
42
+ readonly mapDataParser: DDataParser.Contract<EntityProperties<GenericPropertiesDefinition>, EntityRawProperties<GenericPropertiesDefinition>>;
43
+ "new"<GenericProperties extends EntityProperties<GenericPropertiesDefinition>>(properties: GenericProperties): Entity<GenericName> & GenericProperties;
44
+ map(rawProperties: EntityRawProperties<GenericPropertiesDefinition>): (DEither.EitherRight<"createEntity", Entity<GenericName> & EntityProperties<GenericPropertiesDefinition>> | DEither.EitherLeft<"createEntityError", DDataParser.DataParserError>);
45
+ mapOrThrow(rawProperties: EntityRawProperties<GenericPropertiesDefinition>): Entity<GenericName> & EntityProperties<GenericPropertiesDefinition>;
46
+ }
47
+ declare const CreateEntityError_base: new (params: {
48
+ "@DuplojsUtilsError/create-entity-error"?: unknown;
49
+ }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../common").KindDefinition<"create-entity-error", unknown>, unknown> & Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-entity-error", unknown>, unknown>;
50
+ export declare class CreateEntityError extends CreateEntityError_base {
51
+ rawProperties: EntityRawProperties;
52
+ dataParserError: DDataParser.DataParserError;
53
+ constructor(rawProperties: EntityRawProperties, dataParserError: DDataParser.DataParserError);
54
+ }
55
+ export interface PropertiesDefinitionParams {
56
+ union<const GenericUnionPropertyDefinition extends EntityUnionPropertyDefinition>(...type: GenericUnionPropertyDefinition): {
57
+ type: GenericUnionPropertyDefinition;
58
+ };
59
+ nullable<const GenericPropertyDefinition extends EntityPropertyDefinition>(definition: GenericPropertyDefinition): GenericPropertyDefinition extends EntityAdvancedPropertyDefinition ? DObject.AssignObjects<GenericPropertyDefinition, {
60
+ nullable: true;
61
+ }> : {
62
+ type: GenericPropertyDefinition;
63
+ nullable: true;
64
+ };
65
+ array<const GenericPropertyDefinition extends EntityPropertyDefinition, const GenericAdvancedArrayPropertyDefinition extends EntityAdvancedArrayPropertyDefinition = never>(definition: GenericPropertyDefinition, params?: GenericAdvancedArrayPropertyDefinition): GenericPropertyDefinition extends EntityAdvancedPropertyDefinition ? DObject.AssignObjects<GenericPropertyDefinition, {
66
+ inArray: NeverCoalescing<GenericAdvancedArrayPropertyDefinition, true>;
67
+ }> : {
68
+ type: GenericPropertyDefinition;
69
+ inArray: NeverCoalescing<GenericAdvancedArrayPropertyDefinition, true>;
70
+ };
71
+ }
72
+ export declare function createEntity<GenericName extends string, const GenericPropertiesDefinition extends EntityPropertiesDefinition>(name: GenericName, getPropertiesDefinition: (params: PropertiesDefinitionParams) => GenericPropertiesDefinition): EntityHandler<GenericName, GenericPropertiesDefinition>;
73
+ export type GetEntity<GenericEntityHandler extends EntityHandler<string, any>> = Extract<ReturnType<GenericEntityHandler["new"]>, any>;
74
+ export {};