@thisisagile/easy 18.6.0 → 18.8.0

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 (185) hide show
  1. package/dist/{chunk-34COXZ5A.mjs → chunk-5N6Q7OXJ.mjs} +3 -3
  2. package/dist/{chunk-ZBVKM7WT.mjs → chunk-63DTRTSC.mjs} +4 -8
  3. package/dist/{chunk-ZBVKM7WT.mjs.map → chunk-63DTRTSC.mjs.map} +1 -1
  4. package/dist/{chunk-U3NVU37K.mjs → chunk-6PMTGQVO.mjs} +3 -3
  5. package/dist/{chunk-ISRJB7Z4.mjs → chunk-6YTIRHPN.mjs} +4 -6
  6. package/dist/{chunk-ISRJB7Z4.mjs.map → chunk-6YTIRHPN.mjs.map} +1 -1
  7. package/dist/{chunk-GOZMSSH5.mjs → chunk-AYR4US3Z.mjs} +2 -2
  8. package/dist/{chunk-6MBDCDGA.mjs → chunk-B37NZCNW.mjs} +2 -2
  9. package/dist/{chunk-H73MZAGT.mjs → chunk-FF3BNZ4H.mjs} +3 -5
  10. package/dist/{chunk-H73MZAGT.mjs.map → chunk-FF3BNZ4H.mjs.map} +1 -1
  11. package/dist/{chunk-WWYPWYFC.mjs → chunk-FFD2T6YV.mjs} +2 -2
  12. package/dist/{chunk-GV6NUD6R.mjs → chunk-FSWASMJZ.mjs} +2 -2
  13. package/dist/{chunk-TRR2LTWJ.mjs → chunk-GF7JYGJU.mjs} +4 -8
  14. package/dist/{chunk-TRR2LTWJ.mjs.map → chunk-GF7JYGJU.mjs.map} +1 -1
  15. package/dist/{chunk-LPT6LW5N.mjs → chunk-GKQMIKIY.mjs} +2 -2
  16. package/dist/{chunk-C6VQGKDB.mjs → chunk-IESVFCB3.mjs} +3 -3
  17. package/dist/{chunk-JZCNZKGP.mjs → chunk-IYUYA5OX.mjs} +5 -5
  18. package/dist/{chunk-SW73SKB2.mjs → chunk-J5PB7ZVO.mjs} +4 -6
  19. package/dist/{chunk-SW73SKB2.mjs.map → chunk-J5PB7ZVO.mjs.map} +1 -1
  20. package/dist/{chunk-V6TMXDF7.mjs → chunk-JI7MC5EA.mjs} +2 -2
  21. package/dist/{chunk-GMFUUU3V.mjs → chunk-JM6NAJQ3.mjs} +4 -6
  22. package/dist/{chunk-GMFUUU3V.mjs.map → chunk-JM6NAJQ3.mjs.map} +1 -1
  23. package/dist/{chunk-2SE4U4T2.mjs → chunk-JNZUGKMO.mjs} +2 -2
  24. package/dist/{chunk-MLYUI7R7.mjs → chunk-KPXOQFEB.mjs} +4 -6
  25. package/dist/{chunk-MLYUI7R7.mjs.map → chunk-KPXOQFEB.mjs.map} +1 -1
  26. package/dist/{chunk-FAFNTQIS.mjs → chunk-LHDTOERW.mjs} +3 -5
  27. package/dist/{chunk-FAFNTQIS.mjs.map → chunk-LHDTOERW.mjs.map} +1 -1
  28. package/dist/{chunk-CFJJ2C6C.mjs → chunk-M2S4OLVZ.mjs} +2 -2
  29. package/dist/{chunk-SW5NBVHL.mjs → chunk-O4RWZGFC.mjs} +4 -6
  30. package/dist/{chunk-SW5NBVHL.mjs.map → chunk-O4RWZGFC.mjs.map} +1 -1
  31. package/dist/{chunk-ZEIIFJDX.mjs → chunk-QBPSI5NM.mjs} +4 -4
  32. package/dist/{chunk-HBDIZSIE.mjs → chunk-QLEGIYVU.mjs} +3 -5
  33. package/dist/{chunk-HBDIZSIE.mjs.map → chunk-QLEGIYVU.mjs.map} +1 -1
  34. package/dist/{chunk-DUYHH6LC.mjs → chunk-QZPBFVZL.mjs} +2 -2
  35. package/dist/{chunk-YXLGHJ5Q.mjs → chunk-RBJBAJOK.mjs} +2 -2
  36. package/dist/{chunk-5C5OHGRW.mjs → chunk-RW4AKBCN.mjs} +3 -3
  37. package/dist/{chunk-5FD5G442.mjs → chunk-SBT3WGBP.mjs} +7 -7
  38. package/dist/{chunk-USR4ETA7.mjs → chunk-TNIG6FU2.mjs} +2 -2
  39. package/dist/{chunk-5BGTUK7G.mjs → chunk-TUO7ZPSP.mjs} +540 -104
  40. package/dist/chunk-TUO7ZPSP.mjs.map +1 -0
  41. package/dist/{chunk-UATZAAX2.mjs → chunk-WOUH6UVC.mjs} +3 -5
  42. package/dist/{chunk-UATZAAX2.mjs.map → chunk-WOUH6UVC.mjs.map} +1 -1
  43. package/dist/{chunk-KXNGKB2N.mjs → chunk-XQ4F3L4F.mjs} +22 -16
  44. package/dist/{chunk-KXNGKB2N.mjs.map → chunk-XQ4F3L4F.mjs.map} +1 -1
  45. package/dist/{chunk-5MCJXABA.mjs → chunk-XQJ5LQEQ.mjs} +2 -2
  46. package/dist/{chunk-5JE4QW4E.mjs → chunk-ZBOGLMG2.mjs} +4 -4
  47. package/dist/{chunk-UGNNHNYX.mjs → chunk-ZRH6FGUK.mjs} +4 -4
  48. package/dist/{chunk-LCJEJ3LU.mjs → chunk-ZZ73Z5CU.mjs} +2 -2
  49. package/dist/data/Condition.mjs +5 -4
  50. package/dist/data/Database.mjs +4 -5
  51. package/dist/data/Field.mjs +5 -4
  52. package/dist/data/Field.mjs.map +1 -1
  53. package/dist/data/InMemoryGateway.mjs +4 -9
  54. package/dist/data/InMemoryGateway.mjs.map +1 -1
  55. package/dist/domain/Audit.mjs +8 -13
  56. package/dist/domain/Child.mjs +5 -10
  57. package/dist/domain/Child.mjs.map +1 -1
  58. package/dist/domain/DateTime.mjs +4 -9
  59. package/dist/domain/Entity.mjs +8 -13
  60. package/dist/domain/Entity.mjs.map +1 -1
  61. package/dist/domain/Repo.mjs +7 -14
  62. package/dist/domain/Repo.mjs.map +1 -1
  63. package/dist/domain/Struct.mjs +4 -9
  64. package/dist/domain/Typo.mjs +4 -9
  65. package/dist/domain/Typo.mjs.map +1 -1
  66. package/dist/http/CacheControl.mjs +6 -12
  67. package/dist/http/CacheControl.mjs.map +1 -1
  68. package/dist/http/ContentType.mjs +4 -5
  69. package/dist/http/HttpStatus.mjs +4 -5
  70. package/dist/http/HttpVerb.mjs +4 -5
  71. package/dist/http/LocalRequestStore.mjs +2 -7
  72. package/dist/http/LocalRequestStore.mjs.map +1 -1
  73. package/dist/http/RequestOptions.mjs +4 -9
  74. package/dist/http/RestResult.mjs +4 -9
  75. package/dist/http/toResponse.mjs +5 -10
  76. package/dist/index.js +540 -521
  77. package/dist/index.js.map +1 -1
  78. package/dist/process/App.mjs +3 -8
  79. package/dist/process/App.mjs.map +1 -1
  80. package/dist/process/Manage.mjs +4 -9
  81. package/dist/process/Manage.mjs.map +1 -1
  82. package/dist/process/Scope.mjs +3 -8
  83. package/dist/process/Search.mjs +4 -9
  84. package/dist/process/UseCase.mjs +5 -12
  85. package/dist/process/UseCase.mjs.map +1 -1
  86. package/dist/resources/Req.mjs +4 -9
  87. package/dist/resources/Req.mjs.map +1 -1
  88. package/dist/services/Api.mjs +12 -17
  89. package/dist/services/ApiGateway.mjs +15 -20
  90. package/dist/services/AxiosProvider.mjs +10 -15
  91. package/dist/services/MappedRouteGateway.mjs +18 -23
  92. package/dist/services/MappedRouteGateway.mjs.map +1 -1
  93. package/dist/services/RouteGateway.mjs +16 -21
  94. package/dist/services/ViewRouteGateway.mjs +18 -24
  95. package/dist/services/ViewRouteGateway.mjs.map +1 -1
  96. package/dist/sql/Column.mjs +3 -8
  97. package/dist/sql/Count.mjs +6 -4
  98. package/dist/sql/Delete.mjs +5 -3
  99. package/dist/sql/Insert.mjs +5 -3
  100. package/dist/sql/Select.mjs +5 -3
  101. package/dist/sql/SqlQuery.mjs +4 -2
  102. package/dist/sql/Table.mjs +13 -18
  103. package/dist/sql/Table.mjs.map +1 -1
  104. package/dist/sql/TableGateway.mjs +5 -11
  105. package/dist/sql/TableGateway.mjs.map +1 -1
  106. package/dist/sql/Update.mjs +5 -3
  107. package/dist/types/Cache.mjs +3 -3
  108. package/dist/types/CacheAge.mjs +4 -9
  109. package/dist/types/Case.mjs +2 -7
  110. package/dist/types/Context.mjs +2 -7
  111. package/dist/types/Enum.mjs +3 -4
  112. package/dist/types/Environment.mjs +3 -4
  113. package/dist/types/Environment.mjs.map +1 -1
  114. package/dist/types/Exception.mjs +2 -7
  115. package/dist/types/Gateway.mjs +3 -8
  116. package/dist/types/IsEqual.mjs +2 -8
  117. package/dist/types/Json.mjs +4 -3
  118. package/dist/types/List.mjs +3 -1
  119. package/dist/types/Meta.mjs +3 -3
  120. package/dist/types/Number.mjs +3 -8
  121. package/dist/types/Object.mjs +3 -2
  122. package/dist/types/PageList.mjs +3 -8
  123. package/dist/types/Parser.mjs +2 -7
  124. package/dist/types/Parser.mjs.map +1 -1
  125. package/dist/types/Repository.mjs +3 -8
  126. package/dist/types/Result.mjs +2 -7
  127. package/dist/types/Results.mjs +2 -7
  128. package/dist/types/Tag.mjs +3 -3
  129. package/dist/types/Template.mjs +2 -7
  130. package/dist/types/ToText.mjs +2 -7
  131. package/dist/types/Try.mjs +2 -7
  132. package/dist/types/Uri.mjs +5 -13
  133. package/dist/types/Uri.mjs.map +1 -1
  134. package/dist/utils/If.d.ts +2 -0
  135. package/dist/utils/If.mjs +5 -1
  136. package/dist/utils/Mapper.mjs +5 -5
  137. package/dist/utils/Period.mjs +4 -9
  138. package/dist/utils/Period.mjs.map +1 -1
  139. package/dist/utils/Promise.mjs +3 -3
  140. package/dist/utils/Seconds.mjs +4 -2
  141. package/dist/utils/Sentence.mjs +2 -7
  142. package/dist/utils/Sentence.mjs.map +1 -1
  143. package/dist/utils/View.d.ts +7 -0
  144. package/dist/utils/View.mjs +5 -11
  145. package/dist/validation/Contraints.mjs +3 -8
  146. package/dist/validation/Validate.mjs +2 -7
  147. package/dist/validation/When.mjs +2 -7
  148. package/package.json +1 -1
  149. package/src/utils/If.ts +7 -0
  150. package/src/utils/View.ts +14 -0
  151. package/dist/chunk-2PL5VUHT.mjs +0 -37
  152. package/dist/chunk-2PL5VUHT.mjs.map +0 -1
  153. package/dist/chunk-5BGTUK7G.mjs.map +0 -1
  154. package/dist/chunk-5FAZA55F.mjs +0 -58
  155. package/dist/chunk-5FAZA55F.mjs.map +0 -1
  156. package/dist/chunk-7A3RM67L.mjs +0 -68
  157. package/dist/chunk-7A3RM67L.mjs.map +0 -1
  158. package/dist/chunk-AJZIKJEC.mjs +0 -54
  159. package/dist/chunk-AJZIKJEC.mjs.map +0 -1
  160. package/dist/chunk-AQXV7L65.mjs +0 -310
  161. package/dist/chunk-AQXV7L65.mjs.map +0 -1
  162. package/dist/chunk-DC5HIBQG.mjs +0 -23
  163. package/dist/chunk-DC5HIBQG.mjs.map +0 -1
  164. /package/dist/{chunk-34COXZ5A.mjs.map → chunk-5N6Q7OXJ.mjs.map} +0 -0
  165. /package/dist/{chunk-U3NVU37K.mjs.map → chunk-6PMTGQVO.mjs.map} +0 -0
  166. /package/dist/{chunk-GOZMSSH5.mjs.map → chunk-AYR4US3Z.mjs.map} +0 -0
  167. /package/dist/{chunk-6MBDCDGA.mjs.map → chunk-B37NZCNW.mjs.map} +0 -0
  168. /package/dist/{chunk-WWYPWYFC.mjs.map → chunk-FFD2T6YV.mjs.map} +0 -0
  169. /package/dist/{chunk-GV6NUD6R.mjs.map → chunk-FSWASMJZ.mjs.map} +0 -0
  170. /package/dist/{chunk-LPT6LW5N.mjs.map → chunk-GKQMIKIY.mjs.map} +0 -0
  171. /package/dist/{chunk-C6VQGKDB.mjs.map → chunk-IESVFCB3.mjs.map} +0 -0
  172. /package/dist/{chunk-JZCNZKGP.mjs.map → chunk-IYUYA5OX.mjs.map} +0 -0
  173. /package/dist/{chunk-V6TMXDF7.mjs.map → chunk-JI7MC5EA.mjs.map} +0 -0
  174. /package/dist/{chunk-2SE4U4T2.mjs.map → chunk-JNZUGKMO.mjs.map} +0 -0
  175. /package/dist/{chunk-CFJJ2C6C.mjs.map → chunk-M2S4OLVZ.mjs.map} +0 -0
  176. /package/dist/{chunk-ZEIIFJDX.mjs.map → chunk-QBPSI5NM.mjs.map} +0 -0
  177. /package/dist/{chunk-DUYHH6LC.mjs.map → chunk-QZPBFVZL.mjs.map} +0 -0
  178. /package/dist/{chunk-YXLGHJ5Q.mjs.map → chunk-RBJBAJOK.mjs.map} +0 -0
  179. /package/dist/{chunk-5C5OHGRW.mjs.map → chunk-RW4AKBCN.mjs.map} +0 -0
  180. /package/dist/{chunk-5FD5G442.mjs.map → chunk-SBT3WGBP.mjs.map} +0 -0
  181. /package/dist/{chunk-USR4ETA7.mjs.map → chunk-TNIG6FU2.mjs.map} +0 -0
  182. /package/dist/{chunk-5MCJXABA.mjs.map → chunk-XQJ5LQEQ.mjs.map} +0 -0
  183. /package/dist/{chunk-5JE4QW4E.mjs.map → chunk-ZBOGLMG2.mjs.map} +0 -0
  184. /package/dist/{chunk-UGNNHNYX.mjs.map → chunk-ZRH6FGUK.mjs.map} +0 -0
  185. /package/dist/{chunk-LCJEJ3LU.mjs.map → chunk-ZZ73Z5CU.mjs.map} +0 -0
@@ -2,42 +2,33 @@ import {
2
2
  isValidatable
3
3
  } from "./chunk-GPNPXSOF.mjs";
4
4
  import {
5
- reject,
6
- resolve
7
- } from "./chunk-AJZIKJEC.mjs";
5
+ toArray
6
+ } from "./chunk-QCPWEAAJ.mjs";
7
+ import {
8
+ traverse
9
+ } from "./chunk-SSROJBD5.mjs";
8
10
  import {
9
11
  isValue
10
12
  } from "./chunk-AMS2ELWR.mjs";
11
- import {
12
- Enum,
13
- isEnum
14
- } from "./chunk-7A3RM67L.mjs";
15
- import {
16
- meta
17
- } from "./chunk-5FAZA55F.mjs";
18
- import {
19
- entries
20
- } from "./chunk-2PL5VUHT.mjs";
21
- import {
22
- toList
23
- } from "./chunk-AQXV7L65.mjs";
24
- import {
25
- toArray
26
- } from "./chunk-QCPWEAAJ.mjs";
27
13
  import {
28
14
  asString,
29
15
  capitalize,
16
+ equals,
30
17
  replaceAll
31
18
  } from "./chunk-4Q6IHSAU.mjs";
32
19
  import {
33
- ofGet
20
+ ofGet,
21
+ ofProperty
34
22
  } from "./chunk-SJGQU3OG.mjs";
35
23
  import {
36
- isA
24
+ isA,
25
+ isAn
37
26
  } from "./chunk-MDIO6K2O.mjs";
38
27
  import {
39
28
  ofConstruct,
40
- toName
29
+ on,
30
+ toName,
31
+ use
41
32
  } from "./chunk-QK5XGRSM.mjs";
42
33
  import {
43
34
  isArray,
@@ -46,9 +37,144 @@ import {
46
37
  isFunction,
47
38
  isIn,
48
39
  isNotEmpty,
40
+ isObject,
41
+ isPresent,
49
42
  isTrue
50
43
  } from "./chunk-YYWOQNZQ.mjs";
51
44
 
45
+ // src/types/Object.ts
46
+ function entries(subject) {
47
+ return ifDefined(
48
+ subject,
49
+ () => toList([...Object.entries(subject), ...Object.entries(Object.getPrototypeOf(subject) ?? {})]),
50
+ () => toList()
51
+ );
52
+ }
53
+ function values(subject) {
54
+ return toList([...Object.values(subject), ...Object.values(Object.getPrototypeOf(subject) ?? {})]);
55
+ }
56
+ function keys(subject) {
57
+ return toList([...Object.keys(subject), ...Object.keys(Object.getPrototypeOf(subject) ?? {})]);
58
+ }
59
+ function extractKeys(obj, keys2) {
60
+ return keys2.filter((k) => k in obj).reduce(
61
+ (acc, key) => {
62
+ acc.keys[key] = obj[key];
63
+ delete acc[key];
64
+ return acc;
65
+ },
66
+ { keys: {}, ...obj }
67
+ );
68
+ }
69
+
70
+ // src/utils/Promise.ts
71
+ var resolve = (subject) => Promise.resolve(subject);
72
+ var reject = (e) => Promise.reject(e);
73
+ var tuple = {
74
+ 2: (first, second) => Promise.all([first, second]),
75
+ 3: (first, second, third) => Promise.all([first, second, third]),
76
+ 4: (first, second, third, forth) => Promise.all([first, second, third, forth]),
77
+ 5: (first, second, third, forth, fifth) => Promise.all([first, second, third, forth, fifth]),
78
+ all: (first, second) => Promise.all([first, Promise.all(second)]),
79
+ spread: (first, ...second) => Promise.all([first, Promise.all(toArray(second))]),
80
+ list: (list) => Promise.all([...list]).then(toList),
81
+ settled: (list) => Promise.allSettled([...list]).then((rs) => ({
82
+ fulfilled: toList(...rs.filter((r) => r.status === "fulfilled").map((r) => r.value)),
83
+ rejected: toList(...rs.filter((r) => r.status === "rejected").map((r) => asString(r.reason)))
84
+ })),
85
+ object: (obj) => use(keys(obj), (ks) => tuple.list(values(obj)).then((vs) => vs.reduce((acc, v, i) => on(acc, (a) => a[ks[i]] = v), {})))
86
+ };
87
+ var tuple2 = tuple[2];
88
+ var tuple3 = tuple[3];
89
+ var tuple4 = tuple[4];
90
+ var tuple5 = tuple[5];
91
+ var tupleO = tuple.object;
92
+ var settled = tuple.settled;
93
+
94
+ // src/types/Meta.ts
95
+ import "reflect-metadata";
96
+ var ClassMeta = class {
97
+ constructor(subject, data = (subject.prototype ?? subject).constructor) {
98
+ this.subject = subject;
99
+ this.data = data;
100
+ }
101
+ get = (key) => Reflect.getMetadata(key, this.data);
102
+ set = (key, value) => {
103
+ Reflect.defineMetadata(key, value, this.data);
104
+ return value;
105
+ };
106
+ entries = () => entries(this.subject);
107
+ parse = (f, options = {}) => {
108
+ const { initial = {}, skipUndefined = false } = options;
109
+ return this.entries().reduce((a, [k, val]) => use(f(val), (v) => isDefined(v) || !skipUndefined ? on(a, (a2) => a2[k] = v) : a), initial);
110
+ };
111
+ properties = (key) => toList([...Object.getOwnPropertyNames(this.subject), ...Object.getOwnPropertyNames(Object.getPrototypeOf(this.subject))]).map((p) => this.property(p)).filter((p) => key ? p.get(key) : p);
112
+ keys = (key) => this.properties().map((p) => p.get(key)).reduce((list, u) => u ? list.add(u) : list, toList());
113
+ values = () => values(this.subject);
114
+ property = (property) => new PropertyMeta(this.subject, property);
115
+ };
116
+ var PropertyMeta = class {
117
+ constructor(subject, property, data = Reflect.getMetadata(property, subject)) {
118
+ this.subject = subject;
119
+ this.property = property;
120
+ this.data = data;
121
+ }
122
+ get value() {
123
+ return this.subject[this.property];
124
+ }
125
+ get = (key) => isDefined(this.data) && isDefined(this.data[key]) ? this.data[key] : void 0;
126
+ set = (key, value) => {
127
+ Reflect.defineMetadata(this.property, { ...this.data, [key]: value }, this.subject);
128
+ return value;
129
+ };
130
+ };
131
+ var meta = (subject) => new ClassMeta(subject ?? {});
132
+
133
+ // src/types/Enum.ts
134
+ var isEnumConstructor = (c) => isFunction(c) && c.isEnum;
135
+ var Enum = class {
136
+ constructor(name, id = name.toLowerCase(), code = id.toString()) {
137
+ this.name = name;
138
+ this.id = id;
139
+ this.code = code;
140
+ }
141
+ static isEnum = true;
142
+ get isValid() {
143
+ return isDefined(this.id);
144
+ }
145
+ static all() {
146
+ return meta(this.allTuple()).values();
147
+ }
148
+ static filter(p, params) {
149
+ return this.all().filter(p, params);
150
+ }
151
+ static first(p, params) {
152
+ return this.all().first(p, params);
153
+ }
154
+ static byIds(ids = []) {
155
+ return toList(ids).mapDefined((id) => this.byId(id)).distinct();
156
+ }
157
+ static byId(id, alt) {
158
+ return this.allTuple()[id] ?? ofGet(alt);
159
+ }
160
+ static allTuple() {
161
+ return meta(this).get(`all-${this.name}`) ?? meta(this).set(`all-${this.name}`, meta(this).values().filter(isEnum).toObject("id"));
162
+ }
163
+ equals(other) {
164
+ return this.id === (isEnum(other) ? other.id : other);
165
+ }
166
+ isIn(...items) {
167
+ return items.some((i) => this.equals(i));
168
+ }
169
+ toJSON() {
170
+ return this.id;
171
+ }
172
+ toString() {
173
+ return this.id.toString();
174
+ }
175
+ };
176
+ var isEnum = (e) => isDefined(e) && e instanceof Enum && isAn(e, "name", "id", "code");
177
+
52
178
  // src/types/Try.ts
53
179
  var Try = class _Try {
54
180
  is = {
@@ -288,6 +414,64 @@ function textValue(subject, prop) {
288
414
  return p.splice(1).reduce((t, s) => (typeof t === "object" && t !== null ? t : text(t))?.[s], initial)?.toString() ?? "";
289
415
  }
290
416
 
417
+ // src/types/Exception.ts
418
+ var Exception = class _Exception extends Enum {
419
+ constructor(message, id, reason) {
420
+ super(message, id ?? text(message).pascal.toString());
421
+ this.message = message;
422
+ this.reason = reason;
423
+ }
424
+ static AlreadyExists = new _Exception("Subject already exists");
425
+ static DoesNotExist = new _Exception("Does not exist");
426
+ static IsMissingId = new _Exception("Subject is missing an id");
427
+ static IsNotImplemented = new _Exception("Is not implemented");
428
+ static IsNotValid = new _Exception("Is not valid");
429
+ static Unknown = new _Exception("Unknown error");
430
+ static CouldNotExecute = (target) => new _Exception(`Could not execute ${target}.`, "CouldNotExecute");
431
+ static CouldNotValidate = (target) => new _Exception(`Could not validate ${target}.`, "CouldNotValidate");
432
+ static EnvironmentVariableNotFound = (variable) => new _Exception(`Environment variable ${text(variable).upper} could not be found.`, "EnvironmentVariableNotFound");
433
+ because = (reason) => new _Exception(this.message, this.id, reason);
434
+ };
435
+ var isException = (e, t) => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);
436
+ var isDoesNotExist = (e) => e instanceof Exception && Exception.DoesNotExist.equals(e);
437
+
438
+ // src/validation/When.ts
439
+ var When = class _When {
440
+ constructor(subject, valid = true, results) {
441
+ this.subject = subject;
442
+ this.valid = valid;
443
+ this.results = results;
444
+ }
445
+ get not() {
446
+ return this.clone(!this.valid);
447
+ }
448
+ get and() {
449
+ return this.clone(this.valid);
450
+ }
451
+ get isDefined() {
452
+ return this.clone(this.valid === isDefined(this.subject));
453
+ }
454
+ get isEmpty() {
455
+ return this.clone(this.valid === isEmpty(this.subject));
456
+ }
457
+ get isTrue() {
458
+ return this.clone(this.valid === !!this.subject);
459
+ }
460
+ get isValid() {
461
+ this.results = validate(this.subject);
462
+ return this.clone(this.valid === this.results.isValid);
463
+ }
464
+ isInstance = (c) => this.clone(this.valid === this.subject instanceof c);
465
+ with = (pred) => this.clone(this.valid === ofGet(pred, this.subject));
466
+ contains = (property) => this.clone(this.valid === isDefined(ofGet(property, this.subject)));
467
+ in = (...items) => this.clone(this.valid === isIn(this.subject, toArray(...items)));
468
+ is = (item) => this.clone(this.valid === (this.subject === item));
469
+ reject = (error) => !this.valid ? resolve(this.subject) : reject(ofGet(error, this.subject) ?? this.results ?? Exception.Unknown);
470
+ recover = (f) => resolve(!this.valid ? this.subject : f(this.subject));
471
+ clone = (result = true) => new _When(this.subject, result, this.results);
472
+ };
473
+ var when = (subject) => new When(subject);
474
+
291
475
  // src/types/Context.ts
292
476
  var DotEnvContext = class {
293
477
  domain = process.env.DOMAIN ?? "easy";
@@ -396,6 +580,29 @@ var Results = class {
396
580
  var toResults = (...r) => new Results(...r);
397
581
  var isResults = (r) => isDefined(r) && r instanceof Results;
398
582
 
583
+ // src/validation/Validate.ts
584
+ var asResults = (subject, template2, options = {}) => toResults(toResult(text(template2).parse(subject, options), toName(subject)));
585
+ var validators = (subject) => meta(subject).keys("constraint").reduce((list, vs) => list.add(vs), toList());
586
+ var runValidator = (v, subject) => {
587
+ try {
588
+ const actual = isFunction(subject[v.property]) ? subject[v.property]() : subject[v.property];
589
+ const constraint = v.constraint(actual);
590
+ return isResults(constraint) ? constraint : !constraint ? asResults(subject, v.text, {
591
+ ...v,
592
+ actual
593
+ }) : toResults();
594
+ } catch (e) {
595
+ return asResults(subject, asString(e));
596
+ }
597
+ };
598
+ var constraints = (subject) => validators(subject).map((vs) => runValidator(vs, subject)).reduce((rs, r) => rs.add(...r.results), toResults());
599
+ var validate = (subject) => choose(subject).is.not.defined(
600
+ (s) => s,
601
+ () => toResults("Subject is not defined.")
602
+ ).type(isEnum, (e) => e.isValid ? toResults() : asResults(e, "This is not a valid {typeof}.")).type(isValue, (v) => v.isValid ? toResults() : asResults(v, "This is not a valid {typeof}.")).type(isArray, (a) => a.map((i) => validate(i)).reduce((rs, r) => rs.add(...r.results), toResults())).type(isValidatable, (v) => constraints(v)).else(toResults());
603
+ var validateReject = (subject) => when(subject).not.isValid.reject();
604
+ var isValid = (t) => validate(t).isValid;
605
+
399
606
  // src/types/Case.ts
400
607
  var CaseBuilder = class {
401
608
  constructor(v) {
@@ -496,88 +703,320 @@ var Found = class extends Case {
496
703
  };
497
704
  var choose = (value) => new CaseBuilder(value);
498
705
 
499
- // src/validation/Validate.ts
500
- var asResults = (subject, template2, options = {}) => toResults(toResult(text(template2).parse(subject, options), toName(subject)));
501
- var validators = (subject) => meta(subject).keys("constraint").reduce((list, vs) => list.add(vs), toList());
502
- var runValidator = (v, subject) => {
503
- try {
504
- const actual = isFunction(subject[v.property]) ? subject[v.property]() : subject[v.property];
505
- const constraint = v.constraint(actual);
506
- return isResults(constraint) ? constraint : !constraint ? asResults(subject, v.text, {
507
- ...v,
508
- actual
509
- }) : toResults();
510
- } catch (e) {
511
- return asResults(subject, asString(e));
512
- }
513
- };
514
- var constraints = (subject) => validators(subject).map((vs) => runValidator(vs, subject)).reduce((rs, r) => rs.add(...r.results), toResults());
515
- var validate = (subject) => choose(subject).is.not.defined(
516
- (s) => s,
517
- () => toResults("Subject is not defined.")
518
- ).type(isEnum, (e) => e.isValid ? toResults() : asResults(e, "This is not a valid {typeof}.")).type(isValue, (v) => v.isValid ? toResults() : asResults(v, "This is not a valid {typeof}.")).type(isArray, (a) => a.map((i) => validate(i)).reduce((rs, r) => rs.add(...r.results), toResults())).type(isValidatable, (v) => constraints(v)).else(toResults());
519
- var validateReject = (subject) => when(subject).not.isValid.reject();
520
- var isValid = (t) => validate(t).isValid;
706
+ // src/types/IsEqual.ts
707
+ var isEqualArray = (one, another) => choose([one, another]).case(([o, a]) => !isArray(o) || !isArray(a), false).case(([o, a]) => o?.length !== a?.length, false).else(([o, a]) => !o.some((v, i) => !isEqual(v, a[i])));
708
+ var isEqualObject = (one, another) => choose([Object.keys(one), Object.keys(another)]).case(([keysO, keysA]) => keysO.length !== keysA.length, false).case(([keysO, keysA]) => keysO.some((k) => !keysA.includes(k)), false).case(([keysO]) => keysO.some((k) => !isEqual(one[k], another[k])), false).else(true);
709
+ var isEqual = (one, another) => choose([one, another]).case(([o, a]) => o === a, true).case(
710
+ ([o, a]) => isArray(o) || isArray(a),
711
+ ([o, a]) => isEqualArray(o, a)
712
+ ).case(
713
+ ([o, a]) => o == null || a == null || !isObject(o) && !isObject(a),
714
+ ([o, a]) => o !== o && a !== a
715
+ ).else(([o, a]) => isEqualObject(o, a));
521
716
 
522
- // src/types/Exception.ts
523
- var Exception = class _Exception extends Enum {
524
- constructor(message, id, reason) {
525
- super(message, id ?? text(message).pascal.toString());
526
- this.message = message;
527
- this.reason = reason;
528
- }
529
- static AlreadyExists = new _Exception("Subject already exists");
530
- static DoesNotExist = new _Exception("Does not exist");
531
- static IsMissingId = new _Exception("Subject is missing an id");
532
- static IsNotImplemented = new _Exception("Is not implemented");
533
- static IsNotValid = new _Exception("Is not valid");
534
- static Unknown = new _Exception("Unknown error");
535
- static CouldNotExecute = (target) => new _Exception(`Could not execute ${target}.`, "CouldNotExecute");
536
- static CouldNotValidate = (target) => new _Exception(`Could not validate ${target}.`, "CouldNotValidate");
537
- static EnvironmentVariableNotFound = (variable) => new _Exception(`Environment variable ${text(variable).upper} could not be found.`, "EnvironmentVariableNotFound");
538
- because = (reason) => new _Exception(this.message, this.id, reason);
539
- };
540
- var isException = (e, t) => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);
541
- var isDoesNotExist = (e) => e instanceof Exception && Exception.DoesNotExist.equals(e);
717
+ // src/utils/If.ts
718
+ function ifTrue(o, f, alt) {
719
+ return isTrue(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
720
+ }
721
+ function ifFalse(o, f, alt) {
722
+ return !isTrue(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
723
+ }
724
+ function ifDefined(o, f, alt) {
725
+ return isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt);
726
+ }
727
+ function ifNotEmpty(o, f = (o2) => o2, alt) {
728
+ return isNotEmpty(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
729
+ }
730
+ function ifEqual(one, another, f, alt) {
731
+ return isEqual(one, another) ? ofConstruct(f) : ofConstruct(alt);
732
+ }
733
+ function ifEither(os, f = (o) => o, alt) {
734
+ return use(
735
+ toList(os).first((o) => isPresent(o)),
736
+ (o) => isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt, o)
737
+ );
738
+ }
542
739
 
543
- // src/validation/When.ts
544
- var When = class _When {
545
- constructor(subject, valid = true, results) {
546
- this.subject = subject;
547
- this.valid = valid;
548
- this.results = results;
740
+ // src/types/List.ts
741
+ var List8 = class extends Array {
742
+ get ids() {
743
+ return this.mapDefined((i) => i.id);
549
744
  }
550
- get not() {
551
- return this.clone(!this.valid);
745
+ get indexed() {
746
+ return this.map((v, index) => ({ ...v, index }));
552
747
  }
553
- get and() {
554
- return this.clone(this.valid);
748
+ isSubSetOf(...items) {
749
+ return this.diff(items).length === 0;
555
750
  }
556
- get isDefined() {
557
- return this.clone(this.valid === isDefined(this.subject));
751
+ isSuperSetOf(...items) {
752
+ return this.length > items.length && toList(...items).isSubSetOf(...this);
558
753
  }
559
- get isEmpty() {
560
- return this.clone(this.valid === isEmpty(this.subject));
754
+ isIntersectingWith(...items) {
755
+ return this.intersect(items).length > 0;
561
756
  }
562
- get isTrue() {
563
- return this.clone(this.valid === !!this.subject);
757
+ isDisjointWith(...items) {
758
+ return !this.isIntersectingWith(...items);
564
759
  }
565
- get isValid() {
566
- this.results = validate(this.subject);
567
- return this.clone(this.valid === this.results.isValid);
760
+ areEqual(...items) {
761
+ return this.isSubSetOf(...items) && toList(...items).isSubSetOf(...this);
762
+ }
763
+ asc(p) {
764
+ return toList(...this).sort((e1, e2) => ofProperty(e1, p) > ofProperty(e2, p) ? 1 : -1);
765
+ }
766
+ desc(p) {
767
+ return toList(...this).sort((e1, e2) => ofProperty(e1, p) < ofProperty(e2, p) ? 1 : -1);
768
+ }
769
+ first(p, params) {
770
+ return p ? this.find(p, params) : this[0];
771
+ }
772
+ firstValue(f, alt) {
773
+ return ifDefined(
774
+ this.first((t) => !!f(t)),
775
+ f,
776
+ (v) => ofGet(alt, v)
777
+ );
778
+ }
779
+ isFirst(value) {
780
+ return value === this.first();
781
+ }
782
+ next(p, params) {
783
+ return p ? this[this.findIndex(p, params) + 1] : this[0];
784
+ }
785
+ prev(p, params) {
786
+ return p ? this[this.findIndex(p, params) - 1] : this[0];
787
+ }
788
+ last(p, params) {
789
+ return p ? this.filter(p, params).last() : this[this.length - 1];
790
+ }
791
+ isLast(value) {
792
+ return value === this.last();
793
+ }
794
+ overlaps(...items) {
795
+ return toList(...items).some((i) => this.some((t) => i === t));
796
+ }
797
+ diff(others) {
798
+ return this.filter((i) => !others.includes(i));
799
+ }
800
+ diffByKey(others, key) {
801
+ return this.filter((i) => !others.some((o) => o[key] === i[key]));
802
+ }
803
+ symmetricDiff(others) {
804
+ return this.diff(others).concat(toList(...others).diff(this));
805
+ }
806
+ symmetricDiffByKey(others, key) {
807
+ return this.diffByKey(others, key).concat(toList(...others).diffByKey(this, key));
808
+ }
809
+ intersect(others) {
810
+ return this.filter((i) => others.includes(i));
811
+ }
812
+ intersectByKey(others, key) {
813
+ return this.filter((i) => others.some((o) => o[key] === i[key]));
814
+ }
815
+ intersectBy(others, f) {
816
+ return this.filter((i) => others.some((o) => f(i, o)));
817
+ }
818
+ accumulate(...keys2) {
819
+ return this.map((d, i, arr) => {
820
+ const acc = keys2.reduce((acc2, v) => {
821
+ acc2[v] = i === 0 ? d[v] : arr[i - 1][v] + d[v];
822
+ return acc2;
823
+ }, d);
824
+ arr[i] = acc;
825
+ return acc;
826
+ });
827
+ }
828
+ toJSON() {
829
+ return this.reduce((a, i) => {
830
+ a.push(JSON.parse(JSON.stringify(i ?? {})));
831
+ return a;
832
+ }, new Array());
833
+ }
834
+ map(f, params) {
835
+ return toList(super.map(f, params));
836
+ }
837
+ flatMap(f, params) {
838
+ return toList(super.flatMap(f, params));
839
+ }
840
+ mapDefined(f, params) {
841
+ return this.map(f, params).defined();
842
+ }
843
+ mapAsync(f) {
844
+ return Promise.all(super.map((e) => f(e))).then((a) => toList(a));
845
+ }
846
+ mapSerial(f) {
847
+ return super.reduce((p, item) => p.then((results) => on(results, async (r) => r.push(await f(item)))), Promise.resolve(toList()));
848
+ }
849
+ distinct() {
850
+ return this.filter((i, index) => this.indexOf(i) === index);
851
+ }
852
+ distinctByKey(key) {
853
+ const seen = /* @__PURE__ */ new Set();
854
+ return this.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
855
+ }
856
+ distinctByValue() {
857
+ const seen = /* @__PURE__ */ new Set();
858
+ return this.filter((item) => !seen.has(JSON.stringify(item)) && seen.add(JSON.stringify(item)));
859
+ }
860
+ filter(p, params) {
861
+ return toList(super.filter(p, params));
862
+ }
863
+ sum(p) {
864
+ return this.reduce((sum, i) => sum + p(i), 0);
865
+ }
866
+ max(p) {
867
+ return this.desc(p).first();
868
+ }
869
+ min(p) {
870
+ return this.asc(p).first();
871
+ }
872
+ byId(id) {
873
+ return this.first((i) => equals(i.id, id));
874
+ }
875
+ byKey(key, value) {
876
+ return this.first((i) => i[key] == value);
877
+ }
878
+ add(...items) {
879
+ super.push(...toArray(...items));
880
+ return this;
881
+ }
882
+ concat(...items) {
883
+ return toList(super.concat(...items));
884
+ }
885
+ reverse() {
886
+ return toList(super.reverse());
887
+ }
888
+ splice(start, deleteCount, ...items) {
889
+ return toList(super.splice(start, deleteCount, ...items));
890
+ }
891
+ remove(item) {
892
+ const index = this.indexOf(item);
893
+ if (index > -1) {
894
+ this.splice(index, 1);
895
+ }
896
+ return this;
897
+ }
898
+ move(sourceId, destinationId) {
899
+ return this.moveOn("id", sourceId, destinationId);
900
+ }
901
+ moveOn(key, sourceId, destinationId) {
902
+ const source = this.findIndex((i) => equals(i[key], sourceId));
903
+ const dest = this.findIndex((i) => equals(i[key], destinationId));
904
+ return on(toList(...this), (r) => r.splice(dest, 0, ...r.splice(source, 1)));
905
+ }
906
+ replace(key, item) {
907
+ const index = this.findIndex((i) => i[key] === item?.[key]);
908
+ ifTrue(index != -1, () => this.splice(index, 1, item));
909
+ return this;
910
+ }
911
+ switch(item) {
912
+ return this.includes(item) ? this.remove(item) : this.add(item);
913
+ }
914
+ switchOn(item, on2) {
915
+ return use(
916
+ typeof on2 === "function" ? this.find(on2) : use(traverse(item, on2), (v) => this.find((i) => traverse(i, on2) === v)),
917
+ (i) => i ? this.remove(i) : this.add(item)
918
+ );
919
+ }
920
+ defined() {
921
+ return this.reduce((l, v) => isDefined(v) ? l.add(v) : l, toList());
922
+ }
923
+ toObject(key, options = {}) {
924
+ return this.reduce((o, i) => {
925
+ o[i[key]] = i;
926
+ if (options.deleteKey)
927
+ delete o[i[key]][key];
928
+ return o;
929
+ }, {});
930
+ }
931
+ toObjectList(key) {
932
+ return this.reduce(
933
+ (a, t) => {
934
+ const k = t[key];
935
+ a[k] = a[k] ?? toList();
936
+ a[k].push(t);
937
+ return a;
938
+ },
939
+ {}
940
+ );
941
+ }
942
+ orElse(...alt) {
943
+ return !isEmpty(this) ? this : !isEmpty(...alt) ? toList(...alt) : void 0;
944
+ }
945
+ weave(insertFrom, interval) {
946
+ for (let i = interval, n = 0; i <= this.length && n < insertFrom.length; i += interval + 1) {
947
+ this.splice(i, 0, insertFrom[n++]);
948
+ }
949
+ return this;
950
+ }
951
+ slice(start, end) {
952
+ return toList(super.slice(start, end));
953
+ }
954
+ none(p) {
955
+ return !this.some(p);
956
+ }
957
+ chunk(chunkSize) {
958
+ return this.reduce((acc, _, index) => index % chunkSize === 0 ? on(acc, (a) => a.push(this.slice(index, index + chunkSize))) : acc, toList());
959
+ }
960
+ //we needed to add U because of a Typescript issue with generics
961
+ update(p, val) {
962
+ return this.map((v, i, a) => p(v, i, a) ? ofGet(val, v, i, a) : v);
963
+ }
964
+ updateFirst(p, val) {
965
+ const index = this.findIndex(p);
966
+ return this.update((t, i) => p(t, i, this) && i == index, val);
967
+ }
968
+ updateFirstById(id, val) {
969
+ return this.updateFirst((i) => equals(i?.id, id), val);
970
+ }
971
+ updateById(id, val) {
972
+ return this.update((i) => equals(i?.id, id), val);
973
+ }
974
+ groupBy(by) {
975
+ return toList(
976
+ Array.from(this.reduce((m, v, i, a) => use(by(v, i, a), (key) => m.set(key, (m.get(key) ?? toList()).add(v))), /* @__PURE__ */ new Map()).values())
977
+ );
568
978
  }
569
- isInstance = (c) => this.clone(this.valid === this.subject instanceof c);
570
- with = (pred) => this.clone(this.valid === ofGet(pred, this.subject));
571
- contains = (property) => this.clone(this.valid === isDefined(ofGet(property, this.subject)));
572
- in = (...items) => this.clone(this.valid === isIn(this.subject, toArray(...items)));
573
- is = (item) => this.clone(this.valid === (this.subject === item));
574
- reject = (error) => !this.valid ? resolve(this.subject) : reject(ofGet(error, this.subject) ?? this.results ?? Exception.Unknown);
575
- recover = (f) => resolve(!this.valid ? this.subject : f(this.subject));
576
- clone = (result = true) => new _When(this.subject, result, this.results);
577
979
  };
578
- var when = (subject) => new When(subject);
980
+ var toList = (...items) => new List8().add(...items);
981
+ var isList = (l) => isDefined(l) && isArray(l) && isA(l, "first", "last", "asc", "desc");
982
+ var asList = (c, items = []) => toList(toArray(items).map((i) => new c(i)));
983
+ var maxValue = (l, key) => l.desc(key).first()?.[key];
984
+ var minValue = (l, key) => l.asc(key).first()?.[key];
579
985
 
580
986
  export {
987
+ List8 as List,
988
+ toList,
989
+ isList,
990
+ asList,
991
+ maxValue,
992
+ minValue,
993
+ entries,
994
+ values,
995
+ keys,
996
+ extractKeys,
997
+ resolve,
998
+ reject,
999
+ tuple,
1000
+ tuple2,
1001
+ tuple3,
1002
+ tuple4,
1003
+ tuple5,
1004
+ tupleO,
1005
+ settled,
1006
+ meta,
1007
+ isEnumConstructor,
1008
+ Enum,
1009
+ isEnum,
1010
+ Try,
1011
+ tryTo,
1012
+ Template,
1013
+ template,
1014
+ ToText,
1015
+ text,
1016
+ textValue,
1017
+ Exception,
1018
+ isException,
1019
+ isDoesNotExist,
581
1020
  When,
582
1021
  when,
583
1022
  DotEnvContext,
@@ -590,20 +1029,17 @@ export {
590
1029
  Results,
591
1030
  toResults,
592
1031
  isResults,
593
- choose,
594
1032
  asResults,
595
1033
  validate,
596
1034
  validateReject,
597
1035
  isValid,
598
- Try,
599
- tryTo,
600
- Template,
601
- template,
602
- ToText,
603
- text,
604
- textValue,
605
- Exception,
606
- isException,
607
- isDoesNotExist
1036
+ choose,
1037
+ isEqual,
1038
+ ifTrue,
1039
+ ifFalse,
1040
+ ifDefined,
1041
+ ifNotEmpty,
1042
+ ifEqual,
1043
+ ifEither
608
1044
  };
609
- //# sourceMappingURL=chunk-5BGTUK7G.mjs.map
1045
+ //# sourceMappingURL=chunk-TUO7ZPSP.mjs.map