@thisisagile/easy 18.13.0 → 18.14.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 (151) hide show
  1. package/dist/{chunk-NWUALPMB.mjs → chunk-255VBKTY.mjs} +2 -2
  2. package/dist/{chunk-3HEPK3TC.mjs → chunk-2A2VVRKY.mjs} +2 -2
  3. package/dist/{chunk-HWR7EEVI.mjs → chunk-2YLKDL3N.mjs} +3 -3
  4. package/dist/{chunk-WJGWSFCJ.mjs → chunk-3MEMRALH.mjs} +3 -3
  5. package/dist/{chunk-SATFIUWH.mjs → chunk-3ZE2G4HB.mjs} +2 -2
  6. package/dist/{chunk-MH4VLBIT.mjs → chunk-5MBUYLFK.mjs} +4 -4
  7. package/dist/{chunk-AHSUQCHS.mjs → chunk-62BBBQYU.mjs} +4 -4
  8. package/dist/{chunk-CB3LF3XW.mjs → chunk-7SFPVYRU.mjs} +5 -5
  9. package/dist/{chunk-5LVVM522.mjs → chunk-CF4JGPMH.mjs} +7 -7
  10. package/dist/{chunk-DMOWSGD3.mjs → chunk-CJSI5MAE.mjs} +2 -2
  11. package/dist/{chunk-4SO7UI5S.mjs → chunk-CMLKFSSN.mjs} +2 -2
  12. package/dist/{chunk-UIL3XRCV.mjs → chunk-F2Q6WJQX.mjs} +3 -3
  13. package/dist/{chunk-F2W64HKC.mjs → chunk-FBCVFM4R.mjs} +2 -2
  14. package/dist/{chunk-M6I5JHJC.mjs → chunk-FL6A4QWU.mjs} +2 -2
  15. package/dist/{chunk-PFLWEHXS.mjs → chunk-FLNCIKYW.mjs} +2 -2
  16. package/dist/{chunk-NTK2UCHO.mjs → chunk-HLOV3PMY.mjs} +5 -5
  17. package/dist/{chunk-HI4ZNU6Z.mjs → chunk-IDWBCCDW.mjs} +2 -2
  18. package/dist/{chunk-NOZLL54Z.mjs → chunk-IN65OZB4.mjs} +2 -2
  19. package/dist/{chunk-W3LNVDFV.mjs → chunk-IRNBNWCM.mjs} +2 -2
  20. package/dist/{chunk-P2ZMGAQP.mjs → chunk-K2HJJNJP.mjs} +2 -2
  21. package/dist/{chunk-6I4ZNNVM.mjs → chunk-KLGORPEU.mjs} +2 -2
  22. package/dist/{chunk-D5U4D63E.mjs → chunk-L3VPYEDN.mjs} +4 -4
  23. package/dist/{chunk-7VJ3E3GP.mjs → chunk-MCRJNXS2.mjs} +2 -2
  24. package/dist/{chunk-Z37TBPTK.mjs → chunk-NPXVRI7V.mjs} +2 -2
  25. package/dist/{chunk-OLL5B5NN.mjs → chunk-NS5U2ZJ2.mjs} +3 -3
  26. package/dist/{chunk-T773NDGK.mjs → chunk-OLRXTHEG.mjs} +2 -2
  27. package/dist/{chunk-23ZFESSO.mjs → chunk-QX4UPTRI.mjs} +3 -3
  28. package/dist/{chunk-BS5KUNX2.mjs → chunk-ROXEHSW3.mjs} +791 -787
  29. package/dist/chunk-ROXEHSW3.mjs.map +1 -0
  30. package/dist/{chunk-T7YVWWJF.mjs → chunk-SW5UXAUU.mjs} +4 -4
  31. package/dist/{chunk-S5J3TYAZ.mjs → chunk-U7LVNVLH.mjs} +3 -3
  32. package/dist/{chunk-EPCIQ4J3.mjs → chunk-UIGXOZBD.mjs} +2 -2
  33. package/dist/{chunk-QMIBOIAF.mjs → chunk-VEHGATCM.mjs} +2 -2
  34. package/dist/{chunk-3JALCI3D.mjs → chunk-VIBUGFSC.mjs} +3 -3
  35. package/dist/{chunk-NL464DQQ.mjs → chunk-VNGHCDPU.mjs} +3 -3
  36. package/dist/{chunk-TN6LYAFX.mjs → chunk-ZWLHFGMK.mjs} +2 -2
  37. package/dist/data/Condition.mjs +3 -3
  38. package/dist/data/Database.mjs +2 -2
  39. package/dist/data/Field.mjs +3 -3
  40. package/dist/data/InMemoryGateway.mjs +3 -3
  41. package/dist/domain/Audit.mjs +7 -7
  42. package/dist/domain/Child.mjs +4 -4
  43. package/dist/domain/DateTime.mjs +3 -3
  44. package/dist/domain/Entity.mjs +9 -9
  45. package/dist/domain/Repo.mjs +3 -3
  46. package/dist/domain/Struct.mjs +3 -3
  47. package/dist/domain/Typo.mjs +3 -3
  48. package/dist/http/CacheControl.mjs +3 -3
  49. package/dist/http/ContentType.mjs +2 -2
  50. package/dist/http/HttpStatus.mjs +2 -2
  51. package/dist/http/HttpVerb.mjs +2 -2
  52. package/dist/http/LocalRequestStore.mjs +1 -1
  53. package/dist/http/RequestOptions.mjs +3 -3
  54. package/dist/http/RestResult.mjs +3 -3
  55. package/dist/http/toResponse.mjs +4 -4
  56. package/dist/index.js +5 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/process/App.mjs +2 -2
  59. package/dist/process/Manage.mjs +3 -3
  60. package/dist/process/Scope.mjs +2 -2
  61. package/dist/process/Search.mjs +3 -3
  62. package/dist/process/UseCase.mjs +1 -1
  63. package/dist/resources/Req.mjs +2 -2
  64. package/dist/services/Api.mjs +11 -11
  65. package/dist/services/ApiGateway.mjs +14 -14
  66. package/dist/services/AxiosProvider.mjs +9 -9
  67. package/dist/services/MappedRouteGateway.mjs +18 -18
  68. package/dist/services/RouteGateway.mjs +15 -15
  69. package/dist/services/ViewRouteGateway.mjs +17 -17
  70. package/dist/sql/Column.mjs +2 -2
  71. package/dist/sql/Count.mjs +4 -4
  72. package/dist/sql/Delete.mjs +3 -3
  73. package/dist/sql/Insert.mjs +3 -3
  74. package/dist/sql/Select.mjs +3 -3
  75. package/dist/sql/SqlQuery.mjs +2 -2
  76. package/dist/sql/Table.mjs +14 -14
  77. package/dist/sql/TableGateway.mjs +3 -3
  78. package/dist/sql/Update.mjs +3 -3
  79. package/dist/types/Cache.mjs +1 -1
  80. package/dist/types/CacheAge.mjs +3 -3
  81. package/dist/types/Case.mjs +1 -1
  82. package/dist/types/Context.mjs +1 -1
  83. package/dist/types/Enum.mjs +1 -1
  84. package/dist/types/Environment.mjs +1 -1
  85. package/dist/types/ErrorOrigin.mjs +1 -1
  86. package/dist/types/Exception.mjs +1 -1
  87. package/dist/types/Gateway.mjs +2 -2
  88. package/dist/types/IsEqual.mjs +1 -1
  89. package/dist/types/Json.mjs +2 -2
  90. package/dist/types/List.mjs +1 -1
  91. package/dist/types/Meta.mjs +1 -1
  92. package/dist/types/Number.mjs +2 -2
  93. package/dist/types/Object.mjs +1 -1
  94. package/dist/types/PageList.mjs +2 -2
  95. package/dist/types/Parser.mjs +1 -1
  96. package/dist/types/Repository.mjs +2 -2
  97. package/dist/types/Result.mjs +1 -1
  98. package/dist/types/Results.mjs +1 -1
  99. package/dist/types/Tag.mjs +1 -1
  100. package/dist/types/Template.mjs +1 -1
  101. package/dist/types/ToText.mjs +1 -1
  102. package/dist/types/Try.mjs +1 -1
  103. package/dist/types/Uri.mjs +1 -1
  104. package/dist/utils/If.d.ts +3 -0
  105. package/dist/utils/If.mjs +3 -1
  106. package/dist/utils/Mapper.mjs +3 -3
  107. package/dist/utils/Period.mjs +3 -3
  108. package/dist/utils/Promise.mjs +1 -1
  109. package/dist/utils/Seconds.mjs +2 -2
  110. package/dist/utils/Sentence.mjs +1 -1
  111. package/dist/utils/View.mjs +4 -4
  112. package/dist/validation/Contraints.mjs +2 -2
  113. package/dist/validation/Validate.mjs +1 -1
  114. package/dist/validation/When.mjs +1 -1
  115. package/package.json +1 -1
  116. package/src/utils/If.ts +8 -1
  117. package/dist/chunk-BS5KUNX2.mjs.map +0 -1
  118. /package/dist/{chunk-NWUALPMB.mjs.map → chunk-255VBKTY.mjs.map} +0 -0
  119. /package/dist/{chunk-3HEPK3TC.mjs.map → chunk-2A2VVRKY.mjs.map} +0 -0
  120. /package/dist/{chunk-HWR7EEVI.mjs.map → chunk-2YLKDL3N.mjs.map} +0 -0
  121. /package/dist/{chunk-WJGWSFCJ.mjs.map → chunk-3MEMRALH.mjs.map} +0 -0
  122. /package/dist/{chunk-SATFIUWH.mjs.map → chunk-3ZE2G4HB.mjs.map} +0 -0
  123. /package/dist/{chunk-MH4VLBIT.mjs.map → chunk-5MBUYLFK.mjs.map} +0 -0
  124. /package/dist/{chunk-AHSUQCHS.mjs.map → chunk-62BBBQYU.mjs.map} +0 -0
  125. /package/dist/{chunk-CB3LF3XW.mjs.map → chunk-7SFPVYRU.mjs.map} +0 -0
  126. /package/dist/{chunk-5LVVM522.mjs.map → chunk-CF4JGPMH.mjs.map} +0 -0
  127. /package/dist/{chunk-DMOWSGD3.mjs.map → chunk-CJSI5MAE.mjs.map} +0 -0
  128. /package/dist/{chunk-4SO7UI5S.mjs.map → chunk-CMLKFSSN.mjs.map} +0 -0
  129. /package/dist/{chunk-UIL3XRCV.mjs.map → chunk-F2Q6WJQX.mjs.map} +0 -0
  130. /package/dist/{chunk-F2W64HKC.mjs.map → chunk-FBCVFM4R.mjs.map} +0 -0
  131. /package/dist/{chunk-M6I5JHJC.mjs.map → chunk-FL6A4QWU.mjs.map} +0 -0
  132. /package/dist/{chunk-PFLWEHXS.mjs.map → chunk-FLNCIKYW.mjs.map} +0 -0
  133. /package/dist/{chunk-NTK2UCHO.mjs.map → chunk-HLOV3PMY.mjs.map} +0 -0
  134. /package/dist/{chunk-HI4ZNU6Z.mjs.map → chunk-IDWBCCDW.mjs.map} +0 -0
  135. /package/dist/{chunk-NOZLL54Z.mjs.map → chunk-IN65OZB4.mjs.map} +0 -0
  136. /package/dist/{chunk-W3LNVDFV.mjs.map → chunk-IRNBNWCM.mjs.map} +0 -0
  137. /package/dist/{chunk-P2ZMGAQP.mjs.map → chunk-K2HJJNJP.mjs.map} +0 -0
  138. /package/dist/{chunk-6I4ZNNVM.mjs.map → chunk-KLGORPEU.mjs.map} +0 -0
  139. /package/dist/{chunk-D5U4D63E.mjs.map → chunk-L3VPYEDN.mjs.map} +0 -0
  140. /package/dist/{chunk-7VJ3E3GP.mjs.map → chunk-MCRJNXS2.mjs.map} +0 -0
  141. /package/dist/{chunk-Z37TBPTK.mjs.map → chunk-NPXVRI7V.mjs.map} +0 -0
  142. /package/dist/{chunk-OLL5B5NN.mjs.map → chunk-NS5U2ZJ2.mjs.map} +0 -0
  143. /package/dist/{chunk-T773NDGK.mjs.map → chunk-OLRXTHEG.mjs.map} +0 -0
  144. /package/dist/{chunk-23ZFESSO.mjs.map → chunk-QX4UPTRI.mjs.map} +0 -0
  145. /package/dist/{chunk-T7YVWWJF.mjs.map → chunk-SW5UXAUU.mjs.map} +0 -0
  146. /package/dist/{chunk-S5J3TYAZ.mjs.map → chunk-U7LVNVLH.mjs.map} +0 -0
  147. /package/dist/{chunk-EPCIQ4J3.mjs.map → chunk-UIGXOZBD.mjs.map} +0 -0
  148. /package/dist/{chunk-QMIBOIAF.mjs.map → chunk-VEHGATCM.mjs.map} +0 -0
  149. /package/dist/{chunk-3JALCI3D.mjs.map → chunk-VIBUGFSC.mjs.map} +0 -0
  150. /package/dist/{chunk-NL464DQQ.mjs.map → chunk-VNGHCDPU.mjs.map} +0 -0
  151. /package/dist/{chunk-TN6LYAFX.mjs.map → chunk-ZWLHFGMK.mjs.map} +0 -0
@@ -42,959 +42,952 @@ import {
42
42
  isTrue
43
43
  } from "./chunk-AAND4MKF.mjs";
44
44
 
45
- // src/types/Case.ts
46
- var CaseBuilder = class {
47
- constructor(v) {
48
- this.v = v;
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;
49
100
  }
50
- is = {
51
- true: (pred, out) => this.case(pred, out),
52
- false: (pred, out) => this.case(!ofGet(pred, this.v), out),
53
- truthy: (prop, out) => this.case(!!prop(this.v), out),
54
- falsy: (prop, out) => this.case(!prop(this.v), out),
55
- defined: (prop, out) => this.case(isDefined(prop(this.v)), out),
56
- empty: (prop, out) => this.case(isEmpty(prop(this.v)), out),
57
- valid: (prop, out) => this.case(validate(prop(this.v)).isValid, out),
58
- in: (prop, out) => this.case(ofGet(prop, this.v).includes(this.v), out),
59
- type: (guard, out) => this.type(guard, out),
60
- not: {
61
- true: (pred, out) => this.case(!ofGet(pred, this.v), out),
62
- false: (pred, out) => this.case(pred, out),
63
- truthy: (prop, out) => this.case(!prop(this.v), out),
64
- falsy: (prop, out) => this.case(!!prop(this.v), out),
65
- defined: (prop, out) => this.case(!isDefined(prop(this.v)), out),
66
- empty: (prop, out) => this.case(!isEmpty(prop(this.v)), out),
67
- valid: (prop, out) => this.case(!validate(prop(this.v)).isValid, out),
68
- in: (prop, out) => this.case(!ofGet(prop, this.v).includes(this.v), out),
69
- type: (guard, out) => this.case((v) => !guard(v), out)
70
- }
101
+ get = (key) => Reflect.getMetadata(key, this.data);
102
+ set = (key, value) => {
103
+ Reflect.defineMetadata(key, value, this.data);
104
+ return value;
71
105
  };
72
- if = this.is;
73
- case(pred, out) {
74
- return new Case(this.v).case(pred, out);
75
- }
76
- type(guard, out) {
77
- return new Case(this.v).type(guard, out);
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;
78
121
  }
79
- equals(value, out) {
80
- return new Case(this.v).equals(value, out);
122
+ get value() {
123
+ return this.subject[this.property];
81
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
+ };
82
130
  };
83
- var Case = class {
84
- constructor(value, outcome) {
85
- this.value = value;
86
- this.outcome = outcome;
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();
87
174
  }
175
+ };
176
+ var isEnum = (e) => isDefined(e) && e instanceof Enum && isAn(e, "name", "id", "code");
177
+
178
+ // src/types/Try.ts
179
+ var Try = class _Try {
88
180
  is = {
89
- true: (pred, out) => this.case(pred, out),
90
- false: (pred, out) => this.case(!ofGet(pred, this.value), out),
91
- truthy: (prop, out) => this.case(!!prop(this.value), out),
92
- falsy: (prop, out) => this.case(!prop(this.value), out),
93
- defined: (prop, out) => this.case(isDefined(prop(this.value)), out),
94
- empty: (prop, out) => this.case(isEmpty(prop(this.value)), out),
95
- valid: (prop, out) => this.case(validate(prop(this.value)).isValid, out),
96
- in: (prop, out) => this.case(ofGet(prop, this.value).includes(this.value), out),
97
- type: (guard, out) => this.type(guard, out),
181
+ defined: (prop) => this.filter((v) => isDefined(prop ? prop(v) : v)),
182
+ empty: (prop) => this.filter((v) => isEmpty(prop ? prop(v) : v)),
183
+ valid: (prop) => this.filter((v) => validate(prop ? prop(v) : v).isValid),
184
+ true: (prop) => this.filter((v) => isTrue(prop ? prop(v) : v)),
185
+ false: (prop) => this.filter((v) => !isTrue(prop ? prop(v) : v)),
98
186
  not: {
99
- true: (pred, out) => this.case(!ofGet(pred, this.value), out),
100
- false: (pred, out) => this.case(pred, out),
101
- truthy: (prop, out) => this.case(!prop(this.value), out),
102
- falsy: (prop, out) => this.case(!!prop(this.value), out),
103
- defined: (prop, out) => this.case(!isDefined(prop(this.value)), out),
104
- empty: (prop, out) => this.case(!isEmpty(prop(this.value)), out),
105
- valid: (prop, out) => this.case(!validate(prop(this.value)).isValid, out),
106
- in: (prop, out) => this.case(!ofGet(prop, this.value).includes(this.value), out),
107
- type: (guard, out) => this.case((v) => !guard(v), out)
187
+ defined: (prop) => this.filter((v) => !isDefined(prop ? prop(v) : v)),
188
+ empty: (prop) => this.filter((v) => !isEmpty(prop ? prop(v) : v)),
189
+ valid: (prop) => this.filter((v) => !validate(prop ? prop(v) : v).isValid)
108
190
  }
109
191
  };
110
192
  if = this.is;
111
- case(pred, out) {
112
- return tryTo(pred, this.value).is.true().map(() => ofGet(out, this.value)).map((res) => new Found(this.value, res)).or(this);
113
- }
114
- type(guard, out) {
115
- return tryTo(guard, this.value).is.true().map(() => out(this.value)).map((res) => new Found(this.value, res)).or(this);
193
+ static of = (c, ...args) => {
194
+ try {
195
+ const out = ofGet(c, ...args);
196
+ return new Success(out instanceof _Try ? out.value : out);
197
+ } catch (e) {
198
+ return new Failure(e);
199
+ }
200
+ };
201
+ };
202
+ var Success = class extends Try {
203
+ constructor(value) {
204
+ super();
205
+ this.value = value;
116
206
  }
117
- equals(value, out) {
118
- return this.case(this.value === value, out);
207
+ get error() {
208
+ throw new Error("No error found");
119
209
  }
120
- else(alt) {
121
- return ofGet(alt, this.value);
210
+ get isValid() {
211
+ return true;
122
212
  }
123
- };
124
- var Found = class extends Case {
125
- constructor(value, outcome) {
126
- super(value, outcome);
127
- this.value = value;
128
- this.outcome = outcome;
213
+ map(f) {
214
+ return tryTo(f, this.value);
129
215
  }
130
- case(pred, out) {
216
+ recover(f) {
131
217
  return this;
132
218
  }
133
- type(guard, out) {
219
+ recoverFrom(type, f) {
134
220
  return this;
135
221
  }
136
- equals(value, out) {
137
- return this;
222
+ accept(f) {
223
+ return tryTo(() => {
224
+ f(this.value);
225
+ return this;
226
+ });
138
227
  }
139
- else(alt) {
140
- return this.outcome;
228
+ filter(predicate) {
229
+ return tryTo(() => {
230
+ if (predicate(this.value))
231
+ return this;
232
+ throw new Error(`Applying filter(${predicate.toString()}) failed.`);
233
+ });
234
+ }
235
+ or(value) {
236
+ return this.value;
237
+ }
238
+ orElse(value) {
239
+ return this.value;
240
+ }
241
+ orThrow(_error) {
242
+ return this.value;
141
243
  }
142
244
  };
143
- var choose = (value) => new CaseBuilder(value);
144
-
145
- // src/types/IsEqual.ts
146
- 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])));
147
- 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);
148
- var isEqual = (one, another) => choose([one, another]).case(([o, a]) => o === a, true).case(
149
- ([o, a]) => isArray(o) || isArray(a),
150
- ([o, a]) => isEqualArray(o, a)
151
- ).case(
152
- ([o, a]) => o == null || a == null || !isObject(o) && !isObject(a),
153
- ([o, a]) => o !== o && a !== a
154
- ).else(([o, a]) => isEqualObject(o, a));
155
-
156
- // src/utils/If.ts
157
- function ifTrue(o, f, alt) {
158
- return isTrue(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
159
- }
160
- function ifFalse(o, f, alt) {
161
- return !isTrue(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
162
- }
163
- function ifDefined(o, f, alt) {
164
- return isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt);
165
- }
166
- function ifNotEmpty(o, f = (o2) => o2, alt) {
167
- return isNotEmpty(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
168
- }
169
- function ifEqual(one, another, f, alt) {
170
- return isEqual(one, another) ? ofConstruct(f) : ofConstruct(alt);
171
- }
172
- function ifEither(os, f = (o) => o, alt) {
173
- return use(
174
- toList(os).first((o) => isPresent(o)),
175
- (o) => isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt, o)
176
- );
177
- }
178
-
179
- // src/types/List.ts
180
- var List = class extends Array {
181
- get ids() {
182
- return this.mapDefined((i) => i.id);
183
- }
184
- get indexed() {
185
- return this.map((v, index) => ({ ...v, index }));
186
- }
187
- isSubSetOf(...items) {
188
- return this.diff(items).length === 0;
189
- }
190
- isSuperSetOf(...items) {
191
- return this.length > items.length && toList(...items).isSubSetOf(...this);
192
- }
193
- isIntersectingWith(...items) {
194
- return this.intersect(items).length > 0;
245
+ var Failure = class _Failure extends Try {
246
+ constructor(error) {
247
+ super();
248
+ this.error = error;
195
249
  }
196
- isDisjointWith(...items) {
197
- return !this.isIntersectingWith(...items);
250
+ get value() {
251
+ throw this.error;
198
252
  }
199
- areEqual(...items) {
200
- return this.isSubSetOf(...items) && toList(...items).isSubSetOf(...this);
253
+ get isValid() {
254
+ return false;
201
255
  }
202
- asc(p) {
203
- return toList(...this).sort((e1, e2) => ofProperty(e1, p) > ofProperty(e2, p) ? 1 : -1);
256
+ map(f) {
257
+ return new _Failure(this.error);
204
258
  }
205
- desc(p) {
206
- return toList(...this).sort((e1, e2) => ofProperty(e1, p) < ofProperty(e2, p) ? 1 : -1);
259
+ recover(f) {
260
+ return tryTo(f, this.error);
207
261
  }
208
- first(p, params) {
209
- return p ? this.find(p, params) : this[0];
262
+ recoverFrom(type, f) {
263
+ return tryTo(() => this.error instanceof type ? this.recover(f) : this);
210
264
  }
211
- firstValue(f, alt) {
212
- return ifDefined(
213
- this.first((t) => !!f(t)),
214
- f,
215
- (v) => ofGet(alt, v)
216
- );
265
+ accept(f) {
266
+ return this;
217
267
  }
218
- isFirst(value) {
219
- return value === this.first();
268
+ filter(predicate) {
269
+ return this;
220
270
  }
221
- next(p, params) {
222
- return p ? this[this.findIndex(p, params) + 1] : this[0];
271
+ or(value) {
272
+ return ofGet(value);
223
273
  }
224
- prev(p, params) {
225
- return p ? this[this.findIndex(p, params) - 1] : this[0];
274
+ orElse(value) {
275
+ return ofGet(value);
226
276
  }
227
- last(p, params) {
228
- return p ? this.filter(p, params).last() : this[this.length - 1];
277
+ orThrow(error) {
278
+ throw ofConstruct(error);
229
279
  }
230
- isLast(value) {
231
- return value === this.last();
280
+ };
281
+ var tryTo = (c, ...args) => Try.of(c, ...args);
282
+
283
+ // src/types/Template.ts
284
+ var Template = class {
285
+ constructor(template2, subject = {}, options = {}) {
286
+ this.template = template2;
287
+ this.subject = subject;
288
+ this.options = options;
232
289
  }
233
- overlaps(...items) {
234
- return toList(...items).some((i) => this.some((t) => i === t));
290
+ knownPrefixes = /* @__PURE__ */ new Set(["typeof", "property", "actual", "subject"]);
291
+ toString = () => {
292
+ return entries(this.options).reduce((t, [k]) => this.option(t, k), this.object()).replace(" ", " ");
293
+ };
294
+ props = (tmpl, key, result = toList()) => {
295
+ const i1 = tmpl.indexOf(`{${key}`);
296
+ if (i1 < 0) {
297
+ return result;
298
+ }
299
+ const i2 = tmpl.indexOf("}", i1);
300
+ return this.props(tmpl.slice(i2 + 1), key, result.add(tmpl.substring(i1 + 1, i2)));
301
+ };
302
+ object = () => tryTo(() => this.template.replace(/\{this\./g, "{")).map((t) => t.replace(/\{([^{}]+)}/g, (match, p) => this.knownPrefixes.has(p.split(".")[0]) ? match : textValue(this.subject, p))).or("");
303
+ option = (tmpl, prop) => {
304
+ return this.props(tmpl, prop).reduce((t, p) => t.replace(`{${p}}`, textValue(this.options, p)), tmpl);
305
+ };
306
+ };
307
+ function template(tmpl, subject, options = {}) {
308
+ return new Template(asString(tmpl), subject, {
309
+ typeof: toName(subject),
310
+ subject: text(JSON.stringify(subject)),
311
+ ...options
312
+ });
313
+ }
314
+
315
+ // src/types/ToText.ts
316
+ var ToText = class {
317
+ constructor(subject) {
318
+ this.subject = subject;
235
319
  }
236
- diff(others) {
237
- return this.filter((i) => !others.includes(i));
320
+ get cap() {
321
+ return this.map((s) => capitalize(s?.toLowerCase()));
238
322
  }
239
- diffByKey(others, key) {
240
- return this.filter((i) => !others.some((o) => o[key] === i[key]));
323
+ get capFirst() {
324
+ return this.map((s) => capitalize(s));
241
325
  }
242
- symmetricDiff(others) {
243
- return this.diff(others).concat(toList(...others).diff(this));
326
+ get title() {
327
+ return this.map(
328
+ (s) => s.split(" ").map((w) => text(w).cap).join(" ")
329
+ );
244
330
  }
245
- symmetricDiffByKey(others, key) {
246
- return this.diffByKey(others, key).concat(toList(...others).diffByKey(this, key));
331
+ get pascal() {
332
+ return this.title.replace(" ", "");
247
333
  }
248
- intersect(others) {
249
- return this.filter((i) => others.includes(i));
334
+ get lower() {
335
+ return this.map((s) => s.toLowerCase());
250
336
  }
251
- intersectByKey(others, key) {
252
- return this.filter((i) => others.some((o) => o[key] === i[key]));
337
+ get upper() {
338
+ return this.map((s) => s.toUpperCase());
253
339
  }
254
- intersectBy(others, f) {
255
- return this.filter((i) => others.some((o) => f(i, o)));
340
+ get camel() {
341
+ return this.title.trim.map((s) => `${s.charAt(0).toLowerCase()}${s.slice(1)}`);
256
342
  }
257
- accumulate(...keys2) {
258
- return this.map((d, i, arr) => {
259
- const acc = keys2.reduce((acc2, v) => {
260
- acc2[v] = i === 0 ? d[v] : arr[i - 1][v] + d[v];
261
- return acc2;
262
- }, d);
263
- arr[i] = acc;
264
- return acc;
265
- });
343
+ get kebab() {
344
+ return this.lower.replace(" ", "-");
266
345
  }
267
- toJSON() {
268
- return this.reduce((a, i) => {
269
- a.push(JSON.parse(JSON.stringify(i ?? {})));
270
- return a;
271
- }, new Array());
346
+ get strictKebab() {
347
+ return this.map((s) => s.replace(/[^a-z\d]+/gi, " ").trim()).kebab;
272
348
  }
273
- map(f, params) {
274
- return toList(super.map(f, params));
349
+ get slug() {
350
+ return this.map(
351
+ (s) => s.replace(/ß/g, "ss").normalize("NFKD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z\d]+/g, "-").replace(/(^-)|(-$)/g, "")
352
+ );
275
353
  }
276
- flatMap(f, params) {
277
- return toList(super.flatMap(f, params));
354
+ get snake() {
355
+ return this.upper.replace(" ", "_");
278
356
  }
279
- mapDefined(f, params) {
280
- return this.map(f, params).defined();
357
+ get plural() {
358
+ return this.ifLike("") ?? this.add("s");
281
359
  }
282
- mapAsync(f) {
283
- return Promise.all(super.map((e) => f(e))).then((a) => toList(a));
360
+ get space() {
361
+ return this.map((s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]/g, " "));
284
362
  }
285
- mapSerial(f) {
286
- return super.reduce((p, item) => p.then((results) => on(results, async (r) => r.push(await f(item)))), Promise.resolve(toList()));
363
+ get sentence() {
364
+ return this.isEmpty ? this : this.map((s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}.`);
287
365
  }
288
- distinct() {
289
- return this.filter((i, index) => this.indexOf(i) === index);
366
+ get initials() {
367
+ return this.map(
368
+ (s) => s.split(" ").map((w) => w[0]).join("")
369
+ );
290
370
  }
291
- distinctByKey(key) {
292
- const seen = /* @__PURE__ */ new Set();
293
- return this.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
371
+ get trim() {
372
+ return this.map((s) => s.replace(/[- ,_#]/g, ""));
294
373
  }
295
- distinctByValue() {
296
- const seen = /* @__PURE__ */ new Set();
297
- return this.filter((item) => !seen.has(JSON.stringify(item)) && seen.add(JSON.stringify(item)));
374
+ get trimSentence() {
375
+ return this.map(
376
+ (s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
377
+ );
298
378
  }
299
- filter(p, params) {
300
- return toList(super.filter(p, params));
379
+ get isEmpty() {
380
+ return isEmpty(this.toString());
301
381
  }
302
- sum(p) {
303
- return this.reduce((sum, i) => sum + p(i), 0);
382
+ parse = (subject, options = {}) => text(template(this.subject, subject, { typeof: toName(subject), ...options }));
383
+ is = (...others) => others.some((o) => this.toString() === text(o).toString());
384
+ equals = this.is;
385
+ like = (...others) => others.some((o) => this.trim.lower.toString().includes(text(o).trim.lower.toString()));
386
+ isLike = (...others) => others.some((o) => this.trim.lower.is(text(o).trim.lower));
387
+ ifLike = (...others) => this.isLike(...others) ? this : void 0;
388
+ endsWith = (end) => this.subject.endsWith(asString(end));
389
+ startsWith = (end) => this.subject.startsWith(asString(end));
390
+ first = (n) => this.map((s) => s.substring(0, n));
391
+ last = (n) => this.map((s) => s.substring(s.length - n));
392
+ map = (func) => text(ofGet(func, this.subject));
393
+ replace = (search, replace) => this.map((s) => replaceAll(s, search, replace));
394
+ add = (add, separator = "") => this.map((s) => isNotEmpty(add) ? `${s}${separator}${text(add)}` : s);
395
+ with = (separator, ...other) => this.map(
396
+ (s) => toList(s).add(...other.map((u) => text(u).toString())).filter((s2) => isNotEmpty(s2)).join(separator)
397
+ );
398
+ split = (separator = " ") => toList(this.subject.split(separator));
399
+ toString() {
400
+ return this.subject;
304
401
  }
305
- max(p) {
306
- return this.desc(p).first();
402
+ toJSON() {
403
+ return this.subject;
307
404
  }
308
- min(p) {
309
- return this.asc(p).first();
310
- }
311
- byId(id) {
312
- return this.first((i) => equals(i.id, id));
313
- }
314
- byKey(key, value) {
315
- return this.first((i) => i[key] == value);
316
- }
317
- add(...items) {
318
- super.push(...toArray(...items));
319
- return this;
320
- }
321
- concat(...items) {
322
- return toList(super.concat(...items));
323
- }
324
- reverse() {
325
- return toList(super.reverse());
326
- }
327
- splice(start, deleteCount, ...items) {
328
- return toList(super.splice(start, deleteCount, ...items));
329
- }
330
- remove(item) {
331
- const index = this.indexOf(item);
332
- if (index > -1) {
333
- this.splice(index, 1);
334
- }
335
- return this;
405
+ };
406
+ function text(subject, alt = "") {
407
+ const sub = subject ? asString(subject) : alt;
408
+ return new ToText(sub !== "[object Object]" ? sub : "");
409
+ }
410
+ function textValue(subject, prop) {
411
+ const p = prop.split(".");
412
+ const root = subject?.[p[0]];
413
+ const initial = typeof root === "object" && root !== null ? root : text(root);
414
+ return p.splice(1).reduce((t, s) => (typeof t === "object" && t !== null ? t : text(t))?.[s], initial)?.toString() ?? "";
415
+ }
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;
336
423
  }
337
- move(sourceId, destinationId) {
338
- return this.moveOn("id", sourceId, destinationId);
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;
339
444
  }
340
- moveOn(key, sourceId, destinationId) {
341
- const source = this.findIndex((i) => equals(i[key], sourceId));
342
- const dest = this.findIndex((i) => equals(i[key], destinationId));
343
- return on(toList(...this), (r) => r.splice(dest, 0, ...r.splice(source, 1)));
445
+ get not() {
446
+ return this.clone(!this.valid);
344
447
  }
345
- replace(key, item) {
346
- const index = this.findIndex((i) => i[key] === item?.[key]);
347
- ifTrue(index != -1, () => this.splice(index, 1, item));
348
- return this;
448
+ get and() {
449
+ return this.clone(this.valid);
349
450
  }
350
- switch(item) {
351
- return this.includes(item) ? this.remove(item) : this.add(item);
451
+ get isDefined() {
452
+ return this.clone(this.valid === isDefined(this.subject));
352
453
  }
353
- switchOn(item, on2) {
354
- return use(
355
- typeof on2 === "function" ? this.find(on2) : use(traverse(item, on2), (v) => this.find((i) => traverse(i, on2) === v)),
356
- (i) => i ? this.remove(i) : this.add(item)
357
- );
454
+ get isEmpty() {
455
+ return this.clone(this.valid === isEmpty(this.subject));
358
456
  }
359
- defined() {
360
- return this.reduce((l, v) => isDefined(v) ? l.add(v) : l, toList());
457
+ get isTrue() {
458
+ return this.clone(this.valid === !!this.subject);
361
459
  }
362
- toObject(key, options = {}) {
363
- return this.reduce((o, i) => {
364
- o[i[key]] = i;
365
- if (options.deleteKey)
366
- delete o[i[key]][key];
367
- return o;
368
- }, {});
460
+ get isValid() {
461
+ this.results = validate(this.subject);
462
+ return this.clone(this.valid === this.results.isValid);
369
463
  }
370
- toObjectList(key) {
371
- return this.reduce(
372
- (a, t) => {
373
- const k = t[key];
374
- a[k] = a[k] ?? toList();
375
- a[k].push(t);
376
- return a;
377
- },
378
- {}
379
- );
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
+
475
+ // src/types/Context.ts
476
+ var DotEnvContext = class {
477
+ domain = process.env.DOMAIN ?? "easy";
478
+ name = process.env.ENVIRONMENT_NAME ?? "";
479
+ host = process.env.HOST ?? "";
480
+ port = Number.parseInt(process.env.PORT ?? "8080");
481
+ app = process.env.APP ?? "";
482
+ get = (key, alt) => {
483
+ const k = text(key).map((k2) => k2.replace(/([a-z])([A-Z])/g, "$1 $2")).snake.toString();
484
+ return process.env[k] ?? alt;
485
+ };
486
+ };
487
+ var BaseRequestContext = class {
488
+ state = {};
489
+ get token() {
490
+ return this.get("token");
380
491
  }
381
- orElse(...alt) {
382
- return !isEmpty(this) ? this : !isEmpty(...alt) ? toList(...alt) : void 0;
492
+ set token(token) {
493
+ this.set("token", token);
383
494
  }
384
- weave(insertFrom, interval) {
385
- for (let i = interval, n = 0; i <= this.length && n < insertFrom.length; i += interval + 1) {
386
- this.splice(i, 0, insertFrom[n++]);
387
- }
388
- return this;
495
+ get identity() {
496
+ return this.token;
389
497
  }
390
- slice(start, end) {
391
- return toList(super.slice(start, end));
498
+ get jwt() {
499
+ return this.get("jwt");
392
500
  }
393
- none(p) {
394
- return !this.some(p);
501
+ set jwt(jwt) {
502
+ this.set("jwt", jwt);
395
503
  }
396
- chunk(chunkSize) {
397
- return this.reduce((acc, _, index) => index % chunkSize === 0 ? on(acc, (a) => a.push(this.slice(index, index + chunkSize))) : acc, toList());
504
+ get correlationId() {
505
+ return this.get("correlationId");
398
506
  }
399
- //we needed to add U because of a Typescript issue with generics
400
- update(p, val) {
401
- return this.map((v, i, a) => p(v, i, a) ? ofGet(val, v, i, a) : v);
507
+ set correlationId(id) {
508
+ this.set("correlationId", id);
402
509
  }
403
- updateFirst(p, val) {
404
- const index = this.findIndex(p);
405
- return this.update((t, i) => p(t, i, this) && i == index, val);
510
+ get lastError() {
511
+ return this.get("lastError");
406
512
  }
407
- updateFirstById(id, val) {
408
- return this.updateFirst((i) => equals(i?.id, id), val);
513
+ set lastError(error) {
514
+ this.set("lastError", error);
409
515
  }
410
- updateById(id, val) {
411
- return this.update((i) => equals(i?.id, id), val);
516
+ get(key) {
517
+ return this.state[key];
412
518
  }
413
- groupBy(by) {
414
- return toList(
415
- 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())
416
- );
519
+ set(key, value) {
520
+ return this.state[key] = value;
417
521
  }
522
+ create = (f) => f();
523
+ wrap = (f) => f();
418
524
  };
419
- var toList = (...items) => new List().add(...items);
420
- var isList = (l) => isDefined(l) && isArray(l) && isA(l, "first", "last", "asc", "desc");
421
- var asList = (c, items = []) => toList(toArray(items).map((i) => new c(i)));
422
- var maxValue = (l, key) => l.desc(key).first()?.[key];
423
- var minValue = (l, key) => l.asc(key).first()?.[key];
424
-
425
- // src/types/Object.ts
426
- function entries(subject) {
427
- return ifDefined(
428
- subject,
429
- () => toList([...Object.entries(subject), ...Object.entries(Object.getPrototypeOf(subject) ?? {})]),
430
- () => toList()
431
- );
432
- }
433
- function values(subject) {
434
- return toList([...Object.values(subject), ...Object.values(Object.getPrototypeOf(subject) ?? {})]);
435
- }
436
- function keys(subject) {
437
- return toList([...Object.keys(subject), ...Object.keys(Object.getPrototypeOf(subject) ?? {})]);
438
- }
439
- function extractKeys(obj, keys2) {
440
- return keys2.filter((k) => k in obj).reduce(
441
- (acc, key) => {
442
- acc.keys[key] = obj[key];
443
- delete acc[key];
444
- return acc;
445
- },
446
- { keys: {}, ...obj }
447
- );
448
- }
449
-
450
- // src/utils/Promise.ts
451
- var resolve = (subject) => Promise.resolve(subject);
452
- var reject = (e) => Promise.reject(e);
453
- var tuple = {
454
- 2: (first, second) => Promise.all([first, second]),
455
- 3: (first, second, third) => Promise.all([first, second, third]),
456
- 4: (first, second, third, forth) => Promise.all([first, second, third, forth]),
457
- 5: (first, second, third, forth, fifth) => Promise.all([first, second, third, forth, fifth]),
458
- all: (first, second) => Promise.all([first, Promise.all(second)]),
459
- spread: (first, ...second) => Promise.all([first, Promise.all(toArray(second))]),
460
- list: (list) => Promise.all([...list]).then(toList),
461
- settled: (list) => Promise.allSettled([...list]).then((rs) => ({
462
- fulfilled: toList(...rs.filter((r) => r.status === "fulfilled").map((r) => r.value)),
463
- rejected: toList(...rs.filter((r) => r.status === "rejected").map((r) => asString(r.reason)))
464
- })),
465
- object: (obj) => use(keys(obj), (ks) => tuple.list(values(obj)).then((vs) => vs.reduce((acc, v, i) => on(acc, (a) => a[ks[i]] = v), {})))
466
- };
467
- var tuple2 = tuple[2];
468
- var tuple3 = tuple[3];
469
- var tuple4 = tuple[4];
470
- var tuple5 = tuple[5];
471
- var tupleO = tuple.object;
472
- var settled = tuple.settled;
473
-
474
- // src/types/Meta.ts
475
- import "reflect-metadata";
476
- var ClassMeta = class {
477
- constructor(subject, data = (subject.prototype ?? subject).constructor) {
478
- this.subject = subject;
479
- this.data = data;
480
- }
481
- get = (key) => Reflect.getMetadata(key, this.data);
482
- set = (key, value) => {
483
- Reflect.defineMetadata(key, value, this.data);
484
- return value;
485
- };
486
- entries = () => entries(this.subject);
487
- parse = (f, options = {}) => {
488
- const { initial = {}, skipUndefined = false } = options;
489
- return this.entries().reduce((a, [k, val]) => use(f(val), (v) => isDefined(v) || !skipUndefined ? on(a, (a2) => a2[k] = v) : a), initial);
490
- };
491
- 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);
492
- keys = (key) => this.properties().map((p) => p.get(key)).reduce((list, u) => u ? list.add(u) : list, toList());
493
- values = () => values(this.subject);
494
- property = (property) => new PropertyMeta(this.subject, property);
525
+ var BaseContext = class extends BaseRequestContext {
495
526
  };
496
- var PropertyMeta = class {
497
- constructor(subject, property, data = Reflect.getMetadata(property, subject)) {
498
- this.subject = subject;
499
- this.property = property;
500
- this.data = data;
527
+ var Context = class {
528
+ constructor(state = {}) {
529
+ this.state = state;
530
+ this.state = {
531
+ ...{
532
+ env: new DotEnvContext(),
533
+ request: new BaseRequestContext(),
534
+ other: {}
535
+ },
536
+ ...this.state
537
+ };
501
538
  }
502
- get value() {
503
- return this.subject[this.property];
539
+ get env() {
540
+ return this.state.env;
504
541
  }
505
- get = (key) => isDefined(this.data) && isDefined(this.data[key]) ? this.data[key] : void 0;
506
- set = (key, value) => {
507
- Reflect.defineMetadata(this.property, { ...this.data, [key]: value }, this.subject);
508
- return value;
509
- };
510
- };
511
- var meta = (subject) => new ClassMeta(subject ?? {});
512
-
513
- // src/types/Enum.ts
514
- var isEnumConstructor = (c) => isFunction(c) && c.isEnum;
515
- var Enum = class {
516
- constructor(name, id = name.toLowerCase(), code = id.toString()) {
517
- this.name = name;
518
- this.id = id;
519
- this.code = code;
542
+ set env(env) {
543
+ this.state.env = env;
520
544
  }
521
- static isEnum = true;
522
- get isValid() {
523
- return isDefined(this.id);
545
+ get request() {
546
+ return this.state.request;
524
547
  }
525
- static all() {
526
- return meta(this.allTuple()).values();
548
+ set request(request) {
549
+ this.state.request = request;
527
550
  }
528
- static filter(p, params) {
529
- return this.all().filter(p, params);
551
+ get other() {
552
+ return this.state.other;
530
553
  }
531
- static first(p, params) {
532
- return this.all().first(p, params);
554
+ };
555
+ var ctx = new Context();
556
+
557
+ // src/types/Result.ts
558
+ var toResult = (message, location, domain = ctx.env.domain) => ({
559
+ message: message.toString(),
560
+ location: location?.toString(),
561
+ domain: domain?.toString()
562
+ });
563
+ var isResult = (r) => isA(r, "message");
564
+
565
+ // src/types/Results.ts
566
+ var parse = (...rs) => toArray(...rs).map((r) => isResult(r) ? r : toResult(r));
567
+ var Results = class {
568
+ results;
569
+ constructor(...rs) {
570
+ this.results = parse(...rs);
533
571
  }
534
- static byIds(ids = []) {
535
- return toList(ids).mapDefined((id) => this.byId(id)).distinct();
572
+ get length() {
573
+ return this.results.length;
536
574
  }
537
- static byId(id, alt) {
538
- return this.allTuple()[id] ?? ofGet(alt);
575
+ get isValid() {
576
+ return this.results.length === 0;
539
577
  }
540
- static allTuple() {
541
- return meta(this).get(`all-${this.name}`) ?? meta(this).set(`all-${this.name}`, meta(this).values().filter(isEnum).toObject("id"));
578
+ add = (...rs) => toResults(...this.results, ...parse(...rs));
579
+ };
580
+ var toResults = (...r) => new Results(...r);
581
+ var isResults = (r) => isDefined(r) && r instanceof Results;
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));
542
596
  }
543
- equals(other) {
544
- return this.id === (isEnum(other) ? other.id : other);
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
+
606
+ // src/types/Case.ts
607
+ var CaseBuilder = class {
608
+ constructor(v) {
609
+ this.v = v;
545
610
  }
546
- isIn(...items) {
547
- return items.some((i) => this.equals(i));
611
+ is = {
612
+ true: (pred, out) => this.case(pred, out),
613
+ false: (pred, out) => this.case(!ofGet(pred, this.v), out),
614
+ truthy: (prop, out) => this.case(!!prop(this.v), out),
615
+ falsy: (prop, out) => this.case(!prop(this.v), out),
616
+ defined: (prop, out) => this.case(isDefined(prop(this.v)), out),
617
+ empty: (prop, out) => this.case(isEmpty(prop(this.v)), out),
618
+ valid: (prop, out) => this.case(validate(prop(this.v)).isValid, out),
619
+ in: (prop, out) => this.case(ofGet(prop, this.v).includes(this.v), out),
620
+ type: (guard, out) => this.type(guard, out),
621
+ not: {
622
+ true: (pred, out) => this.case(!ofGet(pred, this.v), out),
623
+ false: (pred, out) => this.case(pred, out),
624
+ truthy: (prop, out) => this.case(!prop(this.v), out),
625
+ falsy: (prop, out) => this.case(!!prop(this.v), out),
626
+ defined: (prop, out) => this.case(!isDefined(prop(this.v)), out),
627
+ empty: (prop, out) => this.case(!isEmpty(prop(this.v)), out),
628
+ valid: (prop, out) => this.case(!validate(prop(this.v)).isValid, out),
629
+ in: (prop, out) => this.case(!ofGet(prop, this.v).includes(this.v), out),
630
+ type: (guard, out) => this.case((v) => !guard(v), out)
631
+ }
632
+ };
633
+ if = this.is;
634
+ case(pred, out) {
635
+ return new Case(this.v).case(pred, out);
548
636
  }
549
- toJSON() {
550
- return this.id;
637
+ type(guard, out) {
638
+ return new Case(this.v).type(guard, out);
551
639
  }
552
- toString() {
553
- return this.id.toString();
640
+ equals(value, out) {
641
+ return new Case(this.v).equals(value, out);
554
642
  }
555
643
  };
556
- var isEnum = (e) => isDefined(e) && e instanceof Enum && isAn(e, "name", "id", "code");
557
-
558
- // src/types/Template.ts
559
- var Template = class {
560
- constructor(template2, subject = {}, options = {}) {
561
- this.template = template2;
562
- this.subject = subject;
563
- this.options = options;
644
+ var Case = class {
645
+ constructor(value, outcome) {
646
+ this.value = value;
647
+ this.outcome = outcome;
564
648
  }
565
- knownPrefixes = /* @__PURE__ */ new Set(["typeof", "property", "actual", "subject"]);
566
- toString = () => {
567
- return entries(this.options).reduce((t, [k]) => this.option(t, k), this.object()).replace(" ", " ");
568
- };
569
- props = (tmpl, key, result = toList()) => {
570
- const i1 = tmpl.indexOf(`{${key}`);
571
- if (i1 < 0) {
572
- return result;
649
+ is = {
650
+ true: (pred, out) => this.case(pred, out),
651
+ false: (pred, out) => this.case(!ofGet(pred, this.value), out),
652
+ truthy: (prop, out) => this.case(!!prop(this.value), out),
653
+ falsy: (prop, out) => this.case(!prop(this.value), out),
654
+ defined: (prop, out) => this.case(isDefined(prop(this.value)), out),
655
+ empty: (prop, out) => this.case(isEmpty(prop(this.value)), out),
656
+ valid: (prop, out) => this.case(validate(prop(this.value)).isValid, out),
657
+ in: (prop, out) => this.case(ofGet(prop, this.value).includes(this.value), out),
658
+ type: (guard, out) => this.type(guard, out),
659
+ not: {
660
+ true: (pred, out) => this.case(!ofGet(pred, this.value), out),
661
+ false: (pred, out) => this.case(pred, out),
662
+ truthy: (prop, out) => this.case(!prop(this.value), out),
663
+ falsy: (prop, out) => this.case(!!prop(this.value), out),
664
+ defined: (prop, out) => this.case(!isDefined(prop(this.value)), out),
665
+ empty: (prop, out) => this.case(!isEmpty(prop(this.value)), out),
666
+ valid: (prop, out) => this.case(!validate(prop(this.value)).isValid, out),
667
+ in: (prop, out) => this.case(!ofGet(prop, this.value).includes(this.value), out),
668
+ type: (guard, out) => this.case((v) => !guard(v), out)
573
669
  }
574
- const i2 = tmpl.indexOf("}", i1);
575
- return this.props(tmpl.slice(i2 + 1), key, result.add(tmpl.substring(i1 + 1, i2)));
576
- };
577
- object = () => tryTo(() => this.template.replace(/\{this\./g, "{")).map((t) => t.replace(/\{([^{}]+)}/g, (match, p) => this.knownPrefixes.has(p.split(".")[0]) ? match : textValue(this.subject, p))).or("");
578
- option = (tmpl, prop) => {
579
- return this.props(tmpl, prop).reduce((t, p) => t.replace(`{${p}}`, textValue(this.options, p)), tmpl);
580
670
  };
581
- };
582
- function template(tmpl, subject, options = {}) {
583
- return new Template(asString(tmpl), subject, {
584
- typeof: toName(subject),
585
- subject: text(JSON.stringify(subject)),
586
- ...options
587
- });
588
- }
589
-
590
- // src/types/ToText.ts
591
- var ToText = class {
592
- constructor(subject) {
593
- this.subject = subject;
671
+ if = this.is;
672
+ case(pred, out) {
673
+ return tryTo(pred, this.value).is.true().map(() => ofGet(out, this.value)).map((res) => new Found(this.value, res)).or(this);
594
674
  }
595
- get cap() {
596
- return this.map((s) => capitalize(s?.toLowerCase()));
675
+ type(guard, out) {
676
+ return tryTo(guard, this.value).is.true().map(() => out(this.value)).map((res) => new Found(this.value, res)).or(this);
597
677
  }
598
- get capFirst() {
599
- return this.map((s) => capitalize(s));
678
+ equals(value, out) {
679
+ return this.case(this.value === value, out);
600
680
  }
601
- get title() {
602
- return this.map(
603
- (s) => s.split(" ").map((w) => text(w).cap).join(" ")
604
- );
681
+ else(alt) {
682
+ return ofGet(alt, this.value);
605
683
  }
606
- get pascal() {
607
- return this.title.replace(" ", "");
684
+ };
685
+ var Found = class extends Case {
686
+ constructor(value, outcome) {
687
+ super(value, outcome);
688
+ this.value = value;
689
+ this.outcome = outcome;
608
690
  }
609
- get lower() {
610
- return this.map((s) => s.toLowerCase());
691
+ case(pred, out) {
692
+ return this;
611
693
  }
612
- get upper() {
613
- return this.map((s) => s.toUpperCase());
694
+ type(guard, out) {
695
+ return this;
614
696
  }
615
- get camel() {
616
- return this.title.trim.map((s) => `${s.charAt(0).toLowerCase()}${s.slice(1)}`);
697
+ equals(value, out) {
698
+ return this;
699
+ }
700
+ else(alt) {
701
+ return this.outcome;
702
+ }
703
+ };
704
+ var choose = (value) => new CaseBuilder(value);
705
+
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));
716
+
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 ifEmpty(o, f = (o2) => o2, alt) {
731
+ return isEmpty(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
732
+ }
733
+ function ifEqual(one, another, f, alt) {
734
+ return isEqual(one, another) ? ofConstruct(f) : ofConstruct(alt);
735
+ }
736
+ function ifEither(os, f = (o) => o, alt) {
737
+ return use(
738
+ toList(os).first((o) => isPresent(o)),
739
+ (o) => isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt, o)
740
+ );
741
+ }
742
+
743
+ // src/types/List.ts
744
+ var List8 = class extends Array {
745
+ get ids() {
746
+ return this.mapDefined((i) => i.id);
617
747
  }
618
- get kebab() {
619
- return this.lower.replace(" ", "-");
748
+ get indexed() {
749
+ return this.map((v, index) => ({ ...v, index }));
620
750
  }
621
- get strictKebab() {
622
- return this.map((s) => s.replace(/[^a-z\d]+/gi, " ").trim()).kebab;
751
+ isSubSetOf(...items) {
752
+ return this.diff(items).length === 0;
623
753
  }
624
- get slug() {
625
- return this.map(
626
- (s) => s.replace(/ß/g, "ss").normalize("NFKD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z\d]+/g, "-").replace(/(^-)|(-$)/g, "")
627
- );
754
+ isSuperSetOf(...items) {
755
+ return this.length > items.length && toList(...items).isSubSetOf(...this);
628
756
  }
629
- get snake() {
630
- return this.upper.replace(" ", "_");
757
+ isIntersectingWith(...items) {
758
+ return this.intersect(items).length > 0;
631
759
  }
632
- get plural() {
633
- return this.ifLike("") ?? this.add("s");
760
+ isDisjointWith(...items) {
761
+ return !this.isIntersectingWith(...items);
634
762
  }
635
- get space() {
636
- return this.map((s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]/g, " "));
763
+ areEqual(...items) {
764
+ return this.isSubSetOf(...items) && toList(...items).isSubSetOf(...this);
637
765
  }
638
- get sentence() {
639
- return this.isEmpty ? this : this.map((s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}.`);
766
+ asc(p) {
767
+ return toList(...this).sort((e1, e2) => ofProperty(e1, p) > ofProperty(e2, p) ? 1 : -1);
640
768
  }
641
- get initials() {
642
- return this.map(
643
- (s) => s.split(" ").map((w) => w[0]).join("")
644
- );
769
+ desc(p) {
770
+ return toList(...this).sort((e1, e2) => ofProperty(e1, p) < ofProperty(e2, p) ? 1 : -1);
645
771
  }
646
- get trim() {
647
- return this.map((s) => s.replace(/[- ,_#]/g, ""));
772
+ first(p, params) {
773
+ return p ? this.find(p, params) : this[0];
648
774
  }
649
- get trimSentence() {
650
- return this.map(
651
- (s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
775
+ firstValue(f, alt) {
776
+ return ifDefined(
777
+ this.first((t) => !!f(t)),
778
+ f,
779
+ (v) => ofGet(alt, v)
652
780
  );
653
781
  }
654
- get isEmpty() {
655
- return isEmpty(this.toString());
656
- }
657
- parse = (subject, options = {}) => text(template(this.subject, subject, { typeof: toName(subject), ...options }));
658
- is = (...others) => others.some((o) => this.toString() === text(o).toString());
659
- equals = this.is;
660
- like = (...others) => others.some((o) => this.trim.lower.toString().includes(text(o).trim.lower.toString()));
661
- isLike = (...others) => others.some((o) => this.trim.lower.is(text(o).trim.lower));
662
- ifLike = (...others) => this.isLike(...others) ? this : void 0;
663
- endsWith = (end) => this.subject.endsWith(asString(end));
664
- startsWith = (end) => this.subject.startsWith(asString(end));
665
- first = (n) => this.map((s) => s.substring(0, n));
666
- last = (n) => this.map((s) => s.substring(s.length - n));
667
- map = (func) => text(ofGet(func, this.subject));
668
- replace = (search, replace) => this.map((s) => replaceAll(s, search, replace));
669
- add = (add, separator = "") => this.map((s) => isNotEmpty(add) ? `${s}${separator}${text(add)}` : s);
670
- with = (separator, ...other) => this.map(
671
- (s) => toList(s).add(...other.map((u) => text(u).toString())).filter((s2) => isNotEmpty(s2)).join(separator)
672
- );
673
- split = (separator = " ") => toList(this.subject.split(separator));
674
- toString() {
675
- return this.subject;
676
- }
677
- toJSON() {
678
- return this.subject;
679
- }
680
- };
681
- function text(subject, alt = "") {
682
- const sub = subject ? asString(subject) : alt;
683
- return new ToText(sub !== "[object Object]" ? sub : "");
684
- }
685
- function textValue(subject, prop) {
686
- const p = prop.split(".");
687
- const root = subject?.[p[0]];
688
- const initial = typeof root === "object" && root !== null ? root : text(root);
689
- return p.splice(1).reduce((t, s) => (typeof t === "object" && t !== null ? t : text(t))?.[s], initial)?.toString() ?? "";
690
- }
691
-
692
- // src/types/Exception.ts
693
- var Exception = class _Exception extends Enum {
694
- constructor(message, id, reason) {
695
- super(message, id ?? text(message).pascal.toString());
696
- this.message = message;
697
- this.reason = reason;
782
+ isFirst(value) {
783
+ return value === this.first();
698
784
  }
699
- static AlreadyExists = new _Exception("Subject already exists");
700
- static DoesNotExist = new _Exception("Does not exist");
701
- static IsMissingId = new _Exception("Subject is missing an id");
702
- static IsNotImplemented = new _Exception("Is not implemented");
703
- static IsNotValid = new _Exception("Is not valid");
704
- static Unknown = new _Exception("Unknown error");
705
- static CouldNotExecute = (target) => new _Exception(`Could not execute ${target}.`, "CouldNotExecute");
706
- static CouldNotValidate = (target) => new _Exception(`Could not validate ${target}.`, "CouldNotValidate");
707
- static EnvironmentVariableNotFound = (variable) => new _Exception(`Environment variable ${text(variable).upper} could not be found.`, "EnvironmentVariableNotFound");
708
- because = (reason) => new _Exception(this.message, this.id, reason);
709
- };
710
- var isException = (e, t) => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);
711
- var isDoesNotExist = (e) => e instanceof Exception && Exception.DoesNotExist.equals(e);
712
-
713
- // src/validation/When.ts
714
- var When = class _When {
715
- constructor(subject, valid = true, results) {
716
- this.subject = subject;
717
- this.valid = valid;
718
- this.results = results;
785
+ next(p, params) {
786
+ return p ? this[this.findIndex(p, params) + 1] : this[0];
719
787
  }
720
- get not() {
721
- return this.clone(!this.valid);
788
+ prev(p, params) {
789
+ return p ? this[this.findIndex(p, params) - 1] : this[0];
722
790
  }
723
- get and() {
724
- return this.clone(this.valid);
791
+ last(p, params) {
792
+ return p ? this.filter(p, params).last() : this[this.length - 1];
725
793
  }
726
- get isDefined() {
727
- return this.clone(this.valid === isDefined(this.subject));
794
+ isLast(value) {
795
+ return value === this.last();
728
796
  }
729
- get isEmpty() {
730
- return this.clone(this.valid === isEmpty(this.subject));
797
+ overlaps(...items) {
798
+ return toList(...items).some((i) => this.some((t) => i === t));
731
799
  }
732
- get isTrue() {
733
- return this.clone(this.valid === !!this.subject);
800
+ diff(others) {
801
+ return this.filter((i) => !others.includes(i));
734
802
  }
735
- get isValid() {
736
- this.results = validate(this.subject);
737
- return this.clone(this.valid === this.results.isValid);
803
+ diffByKey(others, key) {
804
+ return this.filter((i) => !others.some((o) => o[key] === i[key]));
738
805
  }
739
- isInstance = (c) => this.clone(this.valid === this.subject instanceof c);
740
- with = (pred) => this.clone(this.valid === ofGet(pred, this.subject));
741
- contains = (property) => this.clone(this.valid === isDefined(ofGet(property, this.subject)));
742
- in = (...items) => this.clone(this.valid === isIn(this.subject, toArray(...items)));
743
- is = (item) => this.clone(this.valid === (this.subject === item));
744
- reject = (error) => !this.valid ? resolve(this.subject) : reject(ofGet(error, this.subject) ?? this.results ?? Exception.Unknown);
745
- recover = (f) => resolve(!this.valid ? this.subject : f(this.subject));
746
- clone = (result = true) => new _When(this.subject, result, this.results);
747
- };
748
- var when = (subject) => new When(subject);
749
-
750
- // src/types/Context.ts
751
- var DotEnvContext = class {
752
- domain = process.env.DOMAIN ?? "easy";
753
- name = process.env.ENVIRONMENT_NAME ?? "";
754
- host = process.env.HOST ?? "";
755
- port = Number.parseInt(process.env.PORT ?? "8080");
756
- app = process.env.APP ?? "";
757
- get = (key, alt) => {
758
- const k = text(key).map((k2) => k2.replace(/([a-z])([A-Z])/g, "$1 $2")).snake.toString();
759
- return process.env[k] ?? alt;
760
- };
761
- };
762
- var BaseRequestContext = class {
763
- state = {};
764
- get token() {
765
- return this.get("token");
806
+ symmetricDiff(others) {
807
+ return this.diff(others).concat(toList(...others).diff(this));
766
808
  }
767
- set token(token) {
768
- this.set("token", token);
809
+ symmetricDiffByKey(others, key) {
810
+ return this.diffByKey(others, key).concat(toList(...others).diffByKey(this, key));
769
811
  }
770
- get identity() {
771
- return this.token;
812
+ intersect(others) {
813
+ return this.filter((i) => others.includes(i));
772
814
  }
773
- get jwt() {
774
- return this.get("jwt");
815
+ intersectByKey(others, key) {
816
+ return this.filter((i) => others.some((o) => o[key] === i[key]));
775
817
  }
776
- set jwt(jwt) {
777
- this.set("jwt", jwt);
818
+ intersectBy(others, f) {
819
+ return this.filter((i) => others.some((o) => f(i, o)));
778
820
  }
779
- get correlationId() {
780
- return this.get("correlationId");
821
+ accumulate(...keys2) {
822
+ return this.map((d, i, arr) => {
823
+ const acc = keys2.reduce((acc2, v) => {
824
+ acc2[v] = i === 0 ? d[v] : arr[i - 1][v] + d[v];
825
+ return acc2;
826
+ }, d);
827
+ arr[i] = acc;
828
+ return acc;
829
+ });
781
830
  }
782
- set correlationId(id) {
783
- this.set("correlationId", id);
831
+ toJSON() {
832
+ return this.reduce((a, i) => {
833
+ a.push(JSON.parse(JSON.stringify(i ?? {})));
834
+ return a;
835
+ }, new Array());
784
836
  }
785
- get lastError() {
786
- return this.get("lastError");
837
+ map(f, params) {
838
+ return toList(super.map(f, params));
787
839
  }
788
- set lastError(error) {
789
- this.set("lastError", error);
840
+ flatMap(f, params) {
841
+ return toList(super.flatMap(f, params));
790
842
  }
791
- get(key) {
792
- return this.state[key];
843
+ mapDefined(f, params) {
844
+ return this.map(f, params).defined();
793
845
  }
794
- set(key, value) {
795
- return this.state[key] = value;
846
+ mapAsync(f) {
847
+ return Promise.all(super.map((e) => f(e))).then((a) => toList(a));
796
848
  }
797
- create = (f) => f();
798
- wrap = (f) => f();
799
- };
800
- var BaseContext = class extends BaseRequestContext {
801
- };
802
- var Context = class {
803
- constructor(state = {}) {
804
- this.state = state;
805
- this.state = {
806
- ...{
807
- env: new DotEnvContext(),
808
- request: new BaseRequestContext(),
809
- other: {}
810
- },
811
- ...this.state
812
- };
849
+ mapSerial(f) {
850
+ return super.reduce((p, item) => p.then((results) => on(results, async (r) => r.push(await f(item)))), Promise.resolve(toList()));
813
851
  }
814
- get env() {
815
- return this.state.env;
852
+ distinct() {
853
+ return this.filter((i, index) => this.indexOf(i) === index);
816
854
  }
817
- set env(env) {
818
- this.state.env = env;
855
+ distinctByKey(key) {
856
+ const seen = /* @__PURE__ */ new Set();
857
+ return this.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
819
858
  }
820
- get request() {
821
- return this.state.request;
859
+ distinctByValue() {
860
+ const seen = /* @__PURE__ */ new Set();
861
+ return this.filter((item) => !seen.has(JSON.stringify(item)) && seen.add(JSON.stringify(item)));
822
862
  }
823
- set request(request) {
824
- this.state.request = request;
863
+ filter(p, params) {
864
+ return toList(super.filter(p, params));
825
865
  }
826
- get other() {
827
- return this.state.other;
866
+ sum(p) {
867
+ return this.reduce((sum, i) => sum + p(i), 0);
828
868
  }
829
- };
830
- var ctx = new Context();
831
-
832
- // src/types/Result.ts
833
- var toResult = (message, location, domain = ctx.env.domain) => ({
834
- message: message.toString(),
835
- location: location?.toString(),
836
- domain: domain?.toString()
837
- });
838
- var isResult = (r) => isA(r, "message");
839
-
840
- // src/types/Results.ts
841
- var parse = (...rs) => toArray(...rs).map((r) => isResult(r) ? r : toResult(r));
842
- var Results = class {
843
- results;
844
- constructor(...rs) {
845
- this.results = parse(...rs);
869
+ max(p) {
870
+ return this.desc(p).first();
846
871
  }
847
- get length() {
848
- return this.results.length;
872
+ min(p) {
873
+ return this.asc(p).first();
849
874
  }
850
- get isValid() {
851
- return this.results.length === 0;
875
+ byId(id) {
876
+ return this.first((i) => equals(i.id, id));
852
877
  }
853
- add = (...rs) => toResults(...this.results, ...parse(...rs));
854
- };
855
- var toResults = (...r) => new Results(...r);
856
- var isResults = (r) => isDefined(r) && r instanceof Results;
857
-
858
- // src/validation/Validate.ts
859
- var asResults = (subject, template2, options = {}) => toResults(toResult(text(template2).parse(subject, options), toName(subject)));
860
- var validators = (subject) => meta(subject).keys("constraint").reduce((list, vs) => list.add(vs), toList());
861
- var runValidator = (v, subject) => {
862
- try {
863
- const actual = isFunction(subject[v.property]) ? subject[v.property]() : subject[v.property];
864
- const constraint = v.constraint(actual);
865
- return isResults(constraint) ? constraint : !constraint ? asResults(subject, v.text, {
866
- ...v,
867
- actual
868
- }) : toResults();
869
- } catch (e) {
870
- return asResults(subject, asString(e));
878
+ byKey(key, value) {
879
+ return this.first((i) => i[key] == value);
871
880
  }
872
- };
873
- var constraints = (subject) => validators(subject).map((vs) => runValidator(vs, subject)).reduce((rs, r) => rs.add(...r.results), toResults());
874
- var validate = (subject) => choose(subject).is.not.defined(
875
- (s) => s,
876
- () => toResults("Subject is not defined.")
877
- ).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());
878
- var validateReject = (subject) => when(subject).not.isValid.reject();
879
- var isValid = (t) => validate(t).isValid;
880
-
881
- // src/types/Try.ts
882
- var Try = class _Try {
883
- is = {
884
- defined: (prop) => this.filter((v) => isDefined(prop ? prop(v) : v)),
885
- empty: (prop) => this.filter((v) => isEmpty(prop ? prop(v) : v)),
886
- valid: (prop) => this.filter((v) => validate(prop ? prop(v) : v).isValid),
887
- true: (prop) => this.filter((v) => isTrue(prop ? prop(v) : v)),
888
- false: (prop) => this.filter((v) => !isTrue(prop ? prop(v) : v)),
889
- not: {
890
- defined: (prop) => this.filter((v) => !isDefined(prop ? prop(v) : v)),
891
- empty: (prop) => this.filter((v) => !isEmpty(prop ? prop(v) : v)),
892
- valid: (prop) => this.filter((v) => !validate(prop ? prop(v) : v).isValid)
893
- }
894
- };
895
- if = this.is;
896
- static of = (c, ...args) => {
897
- try {
898
- const out = ofGet(c, ...args);
899
- return new Success(out instanceof _Try ? out.value : out);
900
- } catch (e) {
901
- return new Failure(e);
902
- }
903
- };
904
- };
905
- var Success = class extends Try {
906
- constructor(value) {
907
- super();
908
- this.value = value;
881
+ add(...items) {
882
+ super.push(...toArray(...items));
883
+ return this;
909
884
  }
910
- get error() {
911
- throw new Error("No error found");
885
+ concat(...items) {
886
+ return toList(super.concat(...items));
912
887
  }
913
- get isValid() {
914
- return true;
888
+ reverse() {
889
+ return toList(super.reverse());
915
890
  }
916
- map(f) {
917
- return tryTo(f, this.value);
891
+ splice(start, deleteCount, ...items) {
892
+ return toList(super.splice(start, deleteCount, ...items));
918
893
  }
919
- recover(f) {
894
+ remove(item) {
895
+ const index = this.indexOf(item);
896
+ if (index > -1) {
897
+ this.splice(index, 1);
898
+ }
920
899
  return this;
921
900
  }
922
- recoverFrom(type, f) {
923
- return this;
901
+ move(sourceId, destinationId) {
902
+ return this.moveOn("id", sourceId, destinationId);
924
903
  }
925
- accept(f) {
926
- return tryTo(() => {
927
- f(this.value);
928
- return this;
929
- });
904
+ moveOn(key, sourceId, destinationId) {
905
+ const source = this.findIndex((i) => equals(i[key], sourceId));
906
+ const dest = this.findIndex((i) => equals(i[key], destinationId));
907
+ return on(toList(...this), (r) => r.splice(dest, 0, ...r.splice(source, 1)));
930
908
  }
931
- filter(predicate) {
932
- return tryTo(() => {
933
- if (predicate(this.value))
934
- return this;
935
- throw new Error(`Applying filter(${predicate.toString()}) failed.`);
936
- });
909
+ replace(key, item) {
910
+ const index = this.findIndex((i) => i[key] === item?.[key]);
911
+ ifTrue(index != -1, () => this.splice(index, 1, item));
912
+ return this;
937
913
  }
938
- or(value) {
939
- return this.value;
914
+ switch(item) {
915
+ return this.includes(item) ? this.remove(item) : this.add(item);
940
916
  }
941
- orElse(value) {
942
- return this.value;
917
+ switchOn(item, on2) {
918
+ return use(
919
+ typeof on2 === "function" ? this.find(on2) : use(traverse(item, on2), (v) => this.find((i) => traverse(i, on2) === v)),
920
+ (i) => i ? this.remove(i) : this.add(item)
921
+ );
943
922
  }
944
- orThrow(_error) {
945
- return this.value;
923
+ defined() {
924
+ return this.reduce((l, v) => isDefined(v) ? l.add(v) : l, toList());
946
925
  }
947
- };
948
- var Failure = class _Failure extends Try {
949
- constructor(error) {
950
- super();
951
- this.error = error;
926
+ toObject(key, options = {}) {
927
+ return this.reduce((o, i) => {
928
+ o[i[key]] = i;
929
+ if (options.deleteKey)
930
+ delete o[i[key]][key];
931
+ return o;
932
+ }, {});
952
933
  }
953
- get value() {
954
- throw this.error;
934
+ toObjectList(key) {
935
+ return this.reduce(
936
+ (a, t) => {
937
+ const k = t[key];
938
+ a[k] = a[k] ?? toList();
939
+ a[k].push(t);
940
+ return a;
941
+ },
942
+ {}
943
+ );
955
944
  }
956
- get isValid() {
957
- return false;
945
+ orElse(...alt) {
946
+ return !isEmpty(this) ? this : !isEmpty(...alt) ? toList(...alt) : void 0;
958
947
  }
959
- map(f) {
960
- return new _Failure(this.error);
948
+ weave(insertFrom, interval) {
949
+ for (let i = interval, n = 0; i <= this.length && n < insertFrom.length; i += interval + 1) {
950
+ this.splice(i, 0, insertFrom[n++]);
951
+ }
952
+ return this;
961
953
  }
962
- recover(f) {
963
- return tryTo(f, this.error);
954
+ slice(start, end) {
955
+ return toList(super.slice(start, end));
964
956
  }
965
- recoverFrom(type, f) {
966
- return tryTo(() => this.error instanceof type ? this.recover(f) : this);
957
+ none(p) {
958
+ return !this.some(p);
967
959
  }
968
- accept(f) {
969
- return this;
960
+ chunk(chunkSize) {
961
+ return this.reduce((acc, _, index) => index % chunkSize === 0 ? on(acc, (a) => a.push(this.slice(index, index + chunkSize))) : acc, toList());
970
962
  }
971
- filter(predicate) {
972
- return this;
963
+ //we needed to add U because of a Typescript issue with generics
964
+ update(p, val) {
965
+ return this.map((v, i, a) => p(v, i, a) ? ofGet(val, v, i, a) : v);
973
966
  }
974
- or(value) {
975
- return ofGet(value);
967
+ updateFirst(p, val) {
968
+ const index = this.findIndex(p);
969
+ return this.update((t, i) => p(t, i, this) && i == index, val);
976
970
  }
977
- orElse(value) {
978
- return ofGet(value);
971
+ updateFirstById(id, val) {
972
+ return this.updateFirst((i) => equals(i?.id, id), val);
979
973
  }
980
- orThrow(error) {
981
- throw ofConstruct(error);
974
+ updateById(id, val) {
975
+ return this.update((i) => equals(i?.id, id), val);
976
+ }
977
+ groupBy(by) {
978
+ return toList(
979
+ 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())
980
+ );
982
981
  }
983
982
  };
984
- var tryTo = (c, ...args) => Try.of(c, ...args);
983
+ var toList = (...items) => new List8().add(...items);
984
+ var isList = (l) => isDefined(l) && isArray(l) && isA(l, "first", "last", "asc", "desc");
985
+ var asList = (c, items = []) => toList(toArray(items).map((i) => new c(i)));
986
+ var maxValue = (l, key) => l.desc(key).first()?.[key];
987
+ var minValue = (l, key) => l.asc(key).first()?.[key];
985
988
 
986
989
  export {
987
- Try,
988
- tryTo,
989
- choose,
990
- isEqual,
991
- ifTrue,
992
- ifFalse,
993
- ifDefined,
994
- ifNotEmpty,
995
- ifEqual,
996
- ifEither,
997
- List,
990
+ List8 as List,
998
991
  toList,
999
992
  isList,
1000
993
  asList,
@@ -1017,6 +1010,8 @@ export {
1017
1010
  isEnumConstructor,
1018
1011
  Enum,
1019
1012
  isEnum,
1013
+ Try,
1014
+ tryTo,
1020
1015
  Template,
1021
1016
  template,
1022
1017
  ToText,
@@ -1040,6 +1035,15 @@ export {
1040
1035
  asResults,
1041
1036
  validate,
1042
1037
  validateReject,
1043
- isValid
1038
+ isValid,
1039
+ choose,
1040
+ isEqual,
1041
+ ifTrue,
1042
+ ifFalse,
1043
+ ifDefined,
1044
+ ifNotEmpty,
1045
+ ifEmpty,
1046
+ ifEqual,
1047
+ ifEither
1044
1048
  };
1045
- //# sourceMappingURL=chunk-BS5KUNX2.mjs.map
1049
+ //# sourceMappingURL=chunk-ROXEHSW3.mjs.map