@thisisagile/easy 17.31.0 → 17.32.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 (131) hide show
  1. package/dist/{chunk-NIWK2A5T.mjs → chunk-2RHBJLH7.mjs} +8 -12
  2. package/dist/{chunk-NIWK2A5T.mjs.map → chunk-2RHBJLH7.mjs.map} +1 -1
  3. package/dist/{chunk-OOWOFPDC.mjs → chunk-4TGUPVQN.mjs} +2 -2
  4. package/dist/{chunk-GQ7XGATB.mjs → chunk-AMBSWR6J.mjs} +7 -9
  5. package/dist/{chunk-GQ7XGATB.mjs.map → chunk-AMBSWR6J.mjs.map} +1 -1
  6. package/dist/{chunk-DY33LKDP.mjs → chunk-BZNMKX6O.mjs} +2 -2
  7. package/dist/{chunk-6RSZTLCP.mjs → chunk-ESECEXXM.mjs} +4 -4
  8. package/dist/{chunk-PZFHPGDR.mjs → chunk-FCJ4TDW7.mjs} +2 -2
  9. package/dist/{chunk-6PR3OZQP.mjs → chunk-H7NA23T6.mjs} +3 -3
  10. package/dist/{chunk-UNU355PL.mjs → chunk-I5VS3NUO.mjs} +5 -5
  11. package/dist/{chunk-DV7PHOM6.mjs → chunk-JSALAKCR.mjs} +3 -3
  12. package/dist/{chunk-QSB4QYYE.mjs → chunk-KTK2V5FC.mjs} +2 -2
  13. package/dist/{chunk-LKBFD66J.mjs → chunk-KX7RRPEZ.mjs} +3 -5
  14. package/dist/{chunk-LKBFD66J.mjs.map → chunk-KX7RRPEZ.mjs.map} +1 -1
  15. package/dist/{chunk-5O2BGB5V.mjs → chunk-LAY4XDIL.mjs} +3 -3
  16. package/dist/{chunk-PIZ7IORV.mjs → chunk-LP2MEIWU.mjs} +2 -2
  17. package/dist/{chunk-X24AKSPO.mjs → chunk-PCKGK5AF.mjs} +2 -2
  18. package/dist/{chunk-3BJH75JQ.mjs → chunk-PQTYEEZC.mjs} +2 -2
  19. package/dist/{chunk-PKA5XEUC.mjs → chunk-R6UXMGTJ.mjs} +3 -3
  20. package/dist/{chunk-TYH6CVJL.mjs → chunk-RBGF26S7.mjs} +4 -4
  21. package/dist/{chunk-IYFZMJYO.mjs → chunk-TNPMWL7Y.mjs} +7 -11
  22. package/dist/{chunk-IYFZMJYO.mjs.map → chunk-TNPMWL7Y.mjs.map} +1 -1
  23. package/dist/{chunk-GJL7E2EJ.mjs → chunk-TPGAM536.mjs} +4 -4
  24. package/dist/{chunk-2MNT7B4T.mjs → chunk-UYBPL7PM.mjs} +7 -7
  25. package/dist/{chunk-HI2JE5PJ.mjs → chunk-XAIZBTVQ.mjs} +2 -2
  26. package/dist/chunk-ZBS4A3QI.mjs +614 -0
  27. package/dist/chunk-ZBS4A3QI.mjs.map +1 -0
  28. package/dist/data/InMemoryGateway.mjs +5 -11
  29. package/dist/data/InMemoryGateway.mjs.map +1 -1
  30. package/dist/domain/Audit.mjs +6 -11
  31. package/dist/domain/Child.mjs +6 -11
  32. package/dist/domain/Child.mjs.map +1 -1
  33. package/dist/domain/DateTime.mjs +3 -8
  34. package/dist/domain/Entity.mjs +11 -16
  35. package/dist/domain/Entity.mjs.map +1 -1
  36. package/dist/domain/Repo.mjs +5 -11
  37. package/dist/domain/Repo.mjs.map +1 -1
  38. package/dist/domain/Struct.mjs +3 -8
  39. package/dist/domain/Typo.mjs +4 -10
  40. package/dist/domain/Typo.mjs.map +1 -1
  41. package/dist/http/CacheControl.mjs +4 -9
  42. package/dist/http/CacheControl.mjs.map +1 -1
  43. package/dist/http/LocalRequestStore.mjs +6 -2
  44. package/dist/http/LocalRequestStore.mjs.map +1 -1
  45. package/dist/http/RequestOptions.mjs +6 -4
  46. package/dist/http/RestResult.mjs +4 -9
  47. package/dist/http/toResponse.mjs +5 -10
  48. package/dist/index.js +317 -306
  49. package/dist/index.js.map +1 -1
  50. package/dist/process/App.mjs +5 -2
  51. package/dist/process/App.mjs.map +1 -1
  52. package/dist/process/Manage.mjs +4 -9
  53. package/dist/process/Manage.mjs.map +1 -1
  54. package/dist/process/Scope.mjs +5 -2
  55. package/dist/process/Search.mjs +4 -9
  56. package/dist/process/UseCase.mjs +4 -1
  57. package/dist/process/UseCase.mjs.map +1 -1
  58. package/dist/resources/Req.mjs +3 -8
  59. package/dist/resources/Req.mjs.map +1 -1
  60. package/dist/services/Api.mjs +11 -16
  61. package/dist/services/ApiGateway.mjs +14 -19
  62. package/dist/services/AxiosProvider.mjs +10 -15
  63. package/dist/services/MappedRouteGateway.mjs +15 -20
  64. package/dist/services/MappedRouteGateway.mjs.map +1 -1
  65. package/dist/services/RouteGateway.mjs +15 -20
  66. package/dist/services/ViewRouteGateway.mjs +17 -22
  67. package/dist/services/ViewRouteGateway.mjs.map +1 -1
  68. package/dist/sql/Column.mjs +3 -8
  69. package/dist/sql/Table.mjs +3 -8
  70. package/dist/sql/Table.mjs.map +1 -1
  71. package/dist/sql/TableGateway.mjs +4 -9
  72. package/dist/sql/TableGateway.mjs.map +1 -1
  73. package/dist/types/CacheAge.mjs +4 -9
  74. package/dist/types/Case.d.ts +16 -0
  75. package/dist/types/Case.mjs +2 -7
  76. package/dist/types/Context.mjs +6 -2
  77. package/dist/types/Exception.mjs +4 -2
  78. package/dist/types/Gateway.mjs +4 -3
  79. package/dist/types/IsEqual.mjs +3 -8
  80. package/dist/types/Number.mjs +3 -8
  81. package/dist/types/PageList.mjs +3 -8
  82. package/dist/types/Parser.mjs +2 -7
  83. package/dist/types/Parser.mjs.map +1 -1
  84. package/dist/types/Repository.mjs +4 -3
  85. package/dist/types/Result.mjs +6 -3
  86. package/dist/types/Results.mjs +6 -4
  87. package/dist/types/Template.d.ts +1 -0
  88. package/dist/types/Template.mjs +6 -1
  89. package/dist/types/ToText.mjs +6 -1
  90. package/dist/types/Try.mjs +2 -7
  91. package/dist/types/Uri.mjs +3 -9
  92. package/dist/types/Uri.mjs.map +1 -1
  93. package/dist/utils/Sentence.mjs +6 -1
  94. package/dist/utils/Sentence.mjs.map +1 -1
  95. package/dist/utils/View.mjs +5 -10
  96. package/dist/validation/Contraints.mjs +3 -8
  97. package/dist/validation/Validate.mjs +2 -7
  98. package/dist/validation/When.mjs +2 -7
  99. package/package.json +1 -1
  100. package/src/types/Case.ts +12 -0
  101. package/src/types/Template.ts +7 -3
  102. package/src/types/ToText.ts +1 -1
  103. package/dist/chunk-6JA2EI2T.mjs +0 -20
  104. package/dist/chunk-6JA2EI2T.mjs.map +0 -1
  105. package/dist/chunk-HTHNHACU.mjs +0 -94
  106. package/dist/chunk-HTHNHACU.mjs.map +0 -1
  107. package/dist/chunk-MIYBZDW6.mjs +0 -35
  108. package/dist/chunk-MIYBZDW6.mjs.map +0 -1
  109. package/dist/chunk-SOUOSMQ6.mjs +0 -165
  110. package/dist/chunk-SOUOSMQ6.mjs.map +0 -1
  111. package/dist/chunk-VTEGCABM.mjs +0 -40
  112. package/dist/chunk-VTEGCABM.mjs.map +0 -1
  113. package/dist/chunk-WIQKEALP.mjs +0 -324
  114. package/dist/chunk-WIQKEALP.mjs.map +0 -1
  115. /package/dist/{chunk-OOWOFPDC.mjs.map → chunk-4TGUPVQN.mjs.map} +0 -0
  116. /package/dist/{chunk-DY33LKDP.mjs.map → chunk-BZNMKX6O.mjs.map} +0 -0
  117. /package/dist/{chunk-6RSZTLCP.mjs.map → chunk-ESECEXXM.mjs.map} +0 -0
  118. /package/dist/{chunk-PZFHPGDR.mjs.map → chunk-FCJ4TDW7.mjs.map} +0 -0
  119. /package/dist/{chunk-6PR3OZQP.mjs.map → chunk-H7NA23T6.mjs.map} +0 -0
  120. /package/dist/{chunk-UNU355PL.mjs.map → chunk-I5VS3NUO.mjs.map} +0 -0
  121. /package/dist/{chunk-DV7PHOM6.mjs.map → chunk-JSALAKCR.mjs.map} +0 -0
  122. /package/dist/{chunk-QSB4QYYE.mjs.map → chunk-KTK2V5FC.mjs.map} +0 -0
  123. /package/dist/{chunk-5O2BGB5V.mjs.map → chunk-LAY4XDIL.mjs.map} +0 -0
  124. /package/dist/{chunk-PIZ7IORV.mjs.map → chunk-LP2MEIWU.mjs.map} +0 -0
  125. /package/dist/{chunk-X24AKSPO.mjs.map → chunk-PCKGK5AF.mjs.map} +0 -0
  126. /package/dist/{chunk-3BJH75JQ.mjs.map → chunk-PQTYEEZC.mjs.map} +0 -0
  127. /package/dist/{chunk-PKA5XEUC.mjs.map → chunk-R6UXMGTJ.mjs.map} +0 -0
  128. /package/dist/{chunk-TYH6CVJL.mjs.map → chunk-RBGF26S7.mjs.map} +0 -0
  129. /package/dist/{chunk-GJL7E2EJ.mjs.map → chunk-TPGAM536.mjs.map} +0 -0
  130. /package/dist/{chunk-2MNT7B4T.mjs.map → chunk-UYBPL7PM.mjs.map} +0 -0
  131. /package/dist/{chunk-HI2JE5PJ.mjs.map → chunk-XAIZBTVQ.mjs.map} +0 -0
@@ -0,0 +1,614 @@
1
+ import {
2
+ reject,
3
+ resolve
4
+ } from "./chunk-2EJYJ4HI.mjs";
5
+ import {
6
+ isValidatable
7
+ } from "./chunk-OFGI5FLG.mjs";
8
+ import {
9
+ isValue
10
+ } from "./chunk-WSBULPUZ.mjs";
11
+ import {
12
+ Enum,
13
+ isEnum
14
+ } from "./chunk-AG3P2RCU.mjs";
15
+ import {
16
+ meta
17
+ } from "./chunk-MK2UX4IH.mjs";
18
+ import {
19
+ entries
20
+ } from "./chunk-ZKLQJX4N.mjs";
21
+ import {
22
+ toList
23
+ } from "./chunk-HOVTNDHS.mjs";
24
+ import {
25
+ toArray
26
+ } from "./chunk-CO2AFYVD.mjs";
27
+ import {
28
+ asString,
29
+ capitalize,
30
+ replaceAll
31
+ } from "./chunk-BDA5LB4S.mjs";
32
+ import {
33
+ ofGet
34
+ } from "./chunk-SJGQU3OG.mjs";
35
+ import {
36
+ isA
37
+ } from "./chunk-ZHXKBOK2.mjs";
38
+ import {
39
+ ofConstruct,
40
+ toName
41
+ } from "./chunk-ZPNFXK7Y.mjs";
42
+ import {
43
+ isArray,
44
+ isDefined,
45
+ isEmpty,
46
+ isFunction,
47
+ isIn,
48
+ isNotEmpty,
49
+ isTrue
50
+ } from "./chunk-DEJ7A5PY.mjs";
51
+
52
+ // src/types/Try.ts
53
+ var Try = class _Try {
54
+ is = {
55
+ defined: (prop) => this.filter((v) => isDefined(prop ? prop(v) : v)),
56
+ empty: (prop) => this.filter((v) => isEmpty(prop ? prop(v) : v)),
57
+ valid: (prop) => this.filter((v) => validate(prop ? prop(v) : v).isValid),
58
+ true: (prop) => this.filter((v) => isTrue(prop ? prop(v) : v)),
59
+ false: (prop) => this.filter((v) => !isTrue(prop ? prop(v) : v)),
60
+ not: {
61
+ defined: (prop) => this.filter((v) => !isDefined(prop ? prop(v) : v)),
62
+ empty: (prop) => this.filter((v) => !isEmpty(prop ? prop(v) : v)),
63
+ valid: (prop) => this.filter((v) => !validate(prop ? prop(v) : v).isValid)
64
+ }
65
+ };
66
+ if = this.is;
67
+ static of = (c, ...args) => {
68
+ try {
69
+ const out = ofGet(c, ...args);
70
+ return new Success(out instanceof _Try ? out.value : out);
71
+ } catch (e) {
72
+ return new Failure(e);
73
+ }
74
+ };
75
+ };
76
+ var Success = class extends Try {
77
+ constructor(value) {
78
+ super();
79
+ this.value = value;
80
+ }
81
+ get error() {
82
+ throw new Error("No error found");
83
+ }
84
+ get isValid() {
85
+ return true;
86
+ }
87
+ map(f) {
88
+ return tryTo(f, this.value);
89
+ }
90
+ recover(f) {
91
+ return this;
92
+ }
93
+ recoverFrom(type, f) {
94
+ return this;
95
+ }
96
+ accept(f) {
97
+ return tryTo(() => {
98
+ f(this.value);
99
+ return this;
100
+ });
101
+ }
102
+ filter(predicate) {
103
+ return tryTo(() => {
104
+ if (predicate(this.value))
105
+ return this;
106
+ throw new Error(`Applying filter(${predicate.toString()}) failed.`);
107
+ });
108
+ }
109
+ or(value) {
110
+ return this.value;
111
+ }
112
+ orElse(value) {
113
+ return this.value;
114
+ }
115
+ orThrow(_error) {
116
+ return this.value;
117
+ }
118
+ };
119
+ var Failure = class _Failure extends Try {
120
+ constructor(error) {
121
+ super();
122
+ this.error = error;
123
+ }
124
+ get value() {
125
+ throw this.error;
126
+ }
127
+ get isValid() {
128
+ return false;
129
+ }
130
+ map(f) {
131
+ return new _Failure(this.error);
132
+ }
133
+ recover(f) {
134
+ return tryTo(f, this.error);
135
+ }
136
+ recoverFrom(type, f) {
137
+ return tryTo(() => this.error instanceof type ? this.recover(f) : this);
138
+ }
139
+ accept(f) {
140
+ return this;
141
+ }
142
+ filter(predicate) {
143
+ return this;
144
+ }
145
+ or(value) {
146
+ return ofGet(value);
147
+ }
148
+ orElse(value) {
149
+ return ofGet(value);
150
+ }
151
+ orThrow(error) {
152
+ throw ofConstruct(error);
153
+ }
154
+ };
155
+ var tryTo = (c, ...args) => Try.of(c, ...args);
156
+
157
+ // src/types/Template.ts
158
+ var Template = class {
159
+ constructor(template2, subject = {}, options = {}) {
160
+ this.template = template2;
161
+ this.subject = subject;
162
+ this.options = options;
163
+ }
164
+ knownPrefixes = /* @__PURE__ */ new Set(["type", "property", "actual", "subject"]);
165
+ toString = () => {
166
+ return entries(this.options).reduce((t, [k]) => this.option(t, k), this.object()).replace(" ", " ");
167
+ };
168
+ props = (tmpl, key, result = toList()) => {
169
+ const i1 = tmpl.indexOf(`{${key}`);
170
+ if (i1 < 0) {
171
+ return result;
172
+ }
173
+ const i2 = tmpl.indexOf("}", i1);
174
+ return this.props(tmpl.slice(i2 + 1), key, result.add(tmpl.substring(i1 + 1, i2)));
175
+ };
176
+ 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("");
177
+ option = (tmpl, prop) => {
178
+ return this.props(tmpl, prop).reduce((t, p) => t.replace(`{${p}}`, textValue(this.options, p)), tmpl);
179
+ };
180
+ };
181
+ function template(tmpl, subject, options = {}) {
182
+ return new Template(asString(tmpl), subject, {
183
+ type: toName(subject),
184
+ subject: text(JSON.stringify(subject)),
185
+ ...options
186
+ });
187
+ }
188
+
189
+ // src/types/ToText.ts
190
+ var ToText = class {
191
+ constructor(subject) {
192
+ this.subject = subject;
193
+ }
194
+ get cap() {
195
+ return this.map((s) => capitalize(s?.toLowerCase()));
196
+ }
197
+ get capFirst() {
198
+ return this.map((s) => capitalize(s));
199
+ }
200
+ get title() {
201
+ return this.map(
202
+ (s) => s.split(" ").map((w) => text(w).cap).join(" ")
203
+ );
204
+ }
205
+ get pascal() {
206
+ return this.title.replace(" ", "");
207
+ }
208
+ get lower() {
209
+ return this.map((s) => s.toLowerCase());
210
+ }
211
+ get upper() {
212
+ return this.map((s) => s.toUpperCase());
213
+ }
214
+ get camel() {
215
+ return this.title.trim.map((s) => `${s.charAt(0).toLowerCase()}${s.slice(1)}`);
216
+ }
217
+ get kebab() {
218
+ return this.lower.replace(" ", "-");
219
+ }
220
+ get strictKebab() {
221
+ return this.map((s) => s.replace(/[^a-z\d]+/gi, " ").trim()).kebab;
222
+ }
223
+ get slug() {
224
+ return this.map(
225
+ (s) => s.replace(/ß/g, "ss").normalize("NFKD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z\d]+/g, "-").replace(/(^-)|(-$)/g, "")
226
+ );
227
+ }
228
+ get snake() {
229
+ return this.upper.replace(" ", "_");
230
+ }
231
+ get plural() {
232
+ return this.ifLike("") ?? this.add("s");
233
+ }
234
+ get space() {
235
+ return this.map((s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]/g, " "));
236
+ }
237
+ get sentence() {
238
+ return this.isEmpty ? this : this.map((s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}.`);
239
+ }
240
+ get initials() {
241
+ return this.map(
242
+ (s) => s.split(" ").map((w) => w[0]).join("")
243
+ );
244
+ }
245
+ get trim() {
246
+ return this.map((s) => s.replace(/[- ,_#]/g, ""));
247
+ }
248
+ get trimSentence() {
249
+ return this.map(
250
+ (s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
251
+ );
252
+ }
253
+ get isEmpty() {
254
+ return isEmpty(this.toString());
255
+ }
256
+ parse = (subject, options = {}) => text(template(this.subject, subject, { type: toName(subject), ...options }));
257
+ is = (...others) => others.some((o) => this.toString() === text(o).toString());
258
+ equals = this.is;
259
+ like = (...others) => others.some((o) => this.trim.lower.toString().includes(text(o).trim.lower.toString()));
260
+ isLike = (...others) => others.some((o) => this.trim.lower.is(text(o).trim.lower));
261
+ ifLike = (...others) => this.isLike(...others) ? this : void 0;
262
+ endsWith = (end) => this.subject.endsWith(asString(end));
263
+ startsWith = (end) => this.subject.startsWith(asString(end));
264
+ first = (n) => this.map((s) => s.substring(0, n));
265
+ last = (n) => this.map((s) => s.substring(s.length - n));
266
+ map = (func) => text(ofGet(func, this.subject));
267
+ replace = (search, replace) => this.map((s) => replaceAll(s, search, replace));
268
+ add = (add, separator = "") => this.map((s) => isNotEmpty(add) ? `${s}${separator}${text(add)}` : s);
269
+ with = (separator, ...other) => this.map(
270
+ (s) => toList(s).add(...other.map((u) => text(u).toString())).filter((s2) => isNotEmpty(s2)).join(separator)
271
+ );
272
+ split = (separator = " ") => toList(this.subject.split(separator));
273
+ toString() {
274
+ return this.subject;
275
+ }
276
+ toJSON() {
277
+ return this.subject;
278
+ }
279
+ };
280
+ function text(subject, alt = "") {
281
+ const sub = subject ? asString(subject) : alt;
282
+ return new ToText(sub !== "[object Object]" ? sub : "");
283
+ }
284
+ function textValue(subject, prop) {
285
+ const p = prop.split(".");
286
+ const root = subject?.[p[0]];
287
+ const initial = typeof root === "object" && root !== null ? root : text(root);
288
+ return p.splice(1).reduce((t, s) => (typeof t === "object" && t !== null ? t : text(t))?.[s], initial)?.toString() ?? "";
289
+ }
290
+
291
+ // src/types/Context.ts
292
+ var DotEnvContext = class {
293
+ domain = process.env.DOMAIN ?? "easy";
294
+ name = process.env.ENVIRONMENT_NAME ?? "";
295
+ host = process.env.HOST ?? "";
296
+ port = Number.parseInt(process.env.PORT ?? "8080");
297
+ app = process.env.APP ?? "";
298
+ get = (key, alt) => {
299
+ const k = text(key).map((k2) => k2.replace(/([a-z])([A-Z])/g, "$1 $2")).snake.toString();
300
+ return process.env[k] ?? alt;
301
+ };
302
+ };
303
+ var BaseRequestContext = class {
304
+ state = {};
305
+ get token() {
306
+ return this.get("token");
307
+ }
308
+ set token(token) {
309
+ this.set("token", token);
310
+ }
311
+ get identity() {
312
+ return this.token;
313
+ }
314
+ get jwt() {
315
+ return this.get("jwt");
316
+ }
317
+ set jwt(jwt) {
318
+ this.set("jwt", jwt);
319
+ }
320
+ get correlationId() {
321
+ return this.get("correlationId");
322
+ }
323
+ set correlationId(id) {
324
+ this.set("correlationId", id);
325
+ }
326
+ get lastError() {
327
+ return this.get("lastError");
328
+ }
329
+ set lastError(error) {
330
+ this.set("lastError", error);
331
+ }
332
+ get(key) {
333
+ return this.state[key];
334
+ }
335
+ set(key, value) {
336
+ return this.state[key] = value;
337
+ }
338
+ create = (f) => f();
339
+ wrap = (f) => f();
340
+ };
341
+ var BaseContext = class extends BaseRequestContext {
342
+ };
343
+ var Context = class {
344
+ constructor(state = {}) {
345
+ this.state = state;
346
+ this.state = {
347
+ ...{
348
+ env: new DotEnvContext(),
349
+ request: new BaseRequestContext(),
350
+ other: {}
351
+ },
352
+ ...this.state
353
+ };
354
+ }
355
+ get env() {
356
+ return this.state.env;
357
+ }
358
+ set env(env) {
359
+ this.state.env = env;
360
+ }
361
+ get request() {
362
+ return this.state.request;
363
+ }
364
+ set request(request) {
365
+ this.state.request = request;
366
+ }
367
+ get other() {
368
+ return this.state.other;
369
+ }
370
+ };
371
+ var ctx = new Context();
372
+
373
+ // src/types/Result.ts
374
+ var toResult = (message, location, domain = ctx.env.domain) => ({
375
+ message: message.toString(),
376
+ location: location?.toString(),
377
+ domain: domain?.toString()
378
+ });
379
+ var isResult = (r) => isA(r, "message");
380
+
381
+ // src/types/Results.ts
382
+ var parse = (...rs) => toArray(...rs).map((r) => isResult(r) ? r : toResult(r));
383
+ var Results = class {
384
+ results;
385
+ constructor(...rs) {
386
+ this.results = parse(...rs);
387
+ }
388
+ get length() {
389
+ return this.results.length;
390
+ }
391
+ get isValid() {
392
+ return this.results.length === 0;
393
+ }
394
+ add = (...rs) => toResults(...this.results, ...parse(...rs));
395
+ };
396
+ var toResults = (...r) => new Results(...r);
397
+ var isResults = (r) => isDefined(r) && r instanceof Results;
398
+
399
+ // src/types/Case.ts
400
+ var CaseBuilder = class {
401
+ constructor(v) {
402
+ this.v = v;
403
+ }
404
+ is = {
405
+ true: (pred, out) => new Case(this.v).case(pred, out),
406
+ false: (pred, out) => new Case(this.v).case(!ofGet(pred, this.v), out),
407
+ defined: (prop, out) => new Case(this.v).case(isDefined(prop(this.v)), out),
408
+ empty: (prop, out) => new Case(this.v).case(isEmpty(prop(this.v)), out),
409
+ valid: (prop, out) => new Case(this.v).case(validate(prop(this.v)).isValid, out),
410
+ in: (prop, out) => new Case(this.v).case(ofGet(prop, this.v).includes(this.v), out),
411
+ not: {
412
+ true: (pred, out) => new Case(this.v).case(!ofGet(pred, this.v), out),
413
+ false: (pred, out) => new Case(this.v).case(pred, out),
414
+ defined: (prop, out) => new Case(this.v).case(!isDefined(prop(this.v)), out),
415
+ empty: (prop, out) => new Case(this.v).case(!isEmpty(prop(this.v)), out),
416
+ valid: (prop, out) => new Case(this.v).case(!validate(prop(this.v)).isValid, out),
417
+ in: (prop, out) => new Case(this.v).case(!ofGet(prop, this.v).includes(this.v), out)
418
+ }
419
+ };
420
+ if = this.is;
421
+ case(pred, out) {
422
+ return new Case(this.v).case(pred, out);
423
+ }
424
+ type(guard, out) {
425
+ return new Case(this.v).type(guard, out);
426
+ }
427
+ equals(value, out) {
428
+ return new Case(this.v).equals(value, out);
429
+ }
430
+ };
431
+ var Case = class _Case {
432
+ constructor(value, outcome) {
433
+ this.value = value;
434
+ this.outcome = outcome;
435
+ }
436
+ is = {
437
+ true: (pred, out) => new _Case(this.value).case(pred, out),
438
+ false: (pred, out) => new _Case(this.value).case(!ofGet(pred, this.value), out),
439
+ defined: (prop, out) => new _Case(this.value).case(isDefined(prop(this.value)), out),
440
+ empty: (prop, out) => new _Case(this.value).case(isEmpty(prop(this.value)), out),
441
+ valid: (prop, out) => new _Case(this.value).case(validate(prop(this.value)).isValid, out),
442
+ in: (prop, out) => new _Case(this.value).case(ofGet(prop, this.value).includes(this.value), out),
443
+ not: {
444
+ true: (pred, out) => new _Case(this.value).case(!ofGet(pred, this.value), out),
445
+ false: (pred, out) => new _Case(this.value).case(pred, out),
446
+ defined: (prop, out) => new _Case(this.value).case(!isDefined(prop(this.value)), out),
447
+ empty: (prop, out) => new _Case(this.value).case(!isEmpty(prop(this.value)), out),
448
+ valid: (prop, out) => new _Case(this.value).case(!validate(prop(this.value)).isValid, out),
449
+ in: (prop, out) => new _Case(this.value).case(!ofGet(prop, this.value).includes(this.value), out)
450
+ }
451
+ };
452
+ if = this.is;
453
+ case(pred, out) {
454
+ return tryTo(pred, this.value).is.true().map(() => ofGet(out, this.value)).map((res) => new Found(this.value, res)).or(this);
455
+ }
456
+ type(guard, out) {
457
+ return tryTo(guard, this.value).is.true().map(() => out(this.value)).map((res) => new Found(this.value, res)).or(this);
458
+ }
459
+ equals(value, out) {
460
+ return this.case(this.value === value, out);
461
+ }
462
+ else(alt) {
463
+ return ofGet(alt, this.value);
464
+ }
465
+ };
466
+ var Found = class extends Case {
467
+ constructor(value, outcome) {
468
+ super(value, outcome);
469
+ this.value = value;
470
+ this.outcome = outcome;
471
+ }
472
+ is = {
473
+ true: (_pred, _out) => this,
474
+ false: (_pred, _out) => this,
475
+ defined: (_prop, _out) => this,
476
+ empty: (_prop, _out) => this,
477
+ valid: (_prop, _out) => this,
478
+ in: (_prop, _out) => this,
479
+ not: {
480
+ true: (_pred, _out) => this,
481
+ false: (_pred, _out) => this,
482
+ defined: (_prop, _out) => this,
483
+ empty: (_prop, _out) => this,
484
+ valid: (_prop, _out) => this,
485
+ in: (_prop, _out) => this
486
+ }
487
+ };
488
+ if = this.is;
489
+ case(pred, out) {
490
+ return this;
491
+ }
492
+ type(guard, out) {
493
+ return this;
494
+ }
495
+ equals(value, out) {
496
+ return this;
497
+ }
498
+ else(alt) {
499
+ return this.outcome;
500
+ }
501
+ };
502
+ var choose = (value) => new CaseBuilder(value);
503
+
504
+ // src/validation/Validate.ts
505
+ var asResults = (subject, template2, options = {}) => toResults(toResult(text(template2).parse(subject, options), toName(subject)));
506
+ var validators = (subject) => meta(subject).keys("constraint").reduce((list, vs) => list.add(vs), toList());
507
+ var runValidator = (v, subject) => {
508
+ try {
509
+ const actual = isFunction(subject[v.property]) ? subject[v.property]() : subject[v.property];
510
+ const constraint = v.constraint(actual);
511
+ return isResults(constraint) ? constraint : !constraint ? asResults(subject, v.text, {
512
+ ...v,
513
+ actual
514
+ }) : toResults();
515
+ } catch (e) {
516
+ return asResults(subject, asString(e));
517
+ }
518
+ };
519
+ var constraints = (subject) => validators(subject).map((vs) => runValidator(vs, subject)).reduce((rs, r) => rs.add(...r.results), toResults());
520
+ var validate = (subject) => choose(subject).is.not.defined(
521
+ (s) => s,
522
+ () => toResults("Subject is not defined.")
523
+ ).type(isEnum, (e) => e.isValid ? toResults() : asResults(e, "This is not a valid {type}.")).type(isValue, (v) => v.isValid ? toResults() : asResults(v, "This is not a valid {type}.")).type(isArray, (a) => a.map((i) => validate(i)).reduce((rs, r) => rs.add(...r.results), toResults())).type(isValidatable, (v) => constraints(v)).else(toResults());
524
+ var validateReject = (subject) => when(subject).not.isValid.reject();
525
+ var isValid = (t) => validate(t).isValid;
526
+
527
+ // src/types/Exception.ts
528
+ var Exception = class _Exception extends Enum {
529
+ constructor(message, id, reason) {
530
+ super(message, id ?? text(message).pascal.toString());
531
+ this.message = message;
532
+ this.reason = reason;
533
+ }
534
+ static AlreadyExists = new _Exception("Subject already exists");
535
+ static DoesNotExist = new _Exception("Does not exist");
536
+ static IsMissingId = new _Exception("Subject is missing an id");
537
+ static IsNotImplemented = new _Exception("Is not implemented");
538
+ static IsNotValid = new _Exception("Is not valid");
539
+ static Unknown = new _Exception("Unknown error");
540
+ static CouldNotExecute = (target) => new _Exception(`Could not execute ${target}.`, "CouldNotExecute");
541
+ static CouldNotValidate = (target) => new _Exception(`Could not validate ${target}.`, "CouldNotValidate");
542
+ static EnvironmentVariableNotFound = (variable) => new _Exception(`Environment variable ${text(variable).upper} could not be found.`, "EnvironmentVariableNotFound");
543
+ because = (reason) => new _Exception(this.message, this.id, reason);
544
+ };
545
+ var isException = (e, t) => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);
546
+ var isDoesNotExist = (e) => e instanceof Exception && Exception.DoesNotExist.equals(e);
547
+
548
+ // src/validation/When.ts
549
+ var When = class _When {
550
+ constructor(subject, valid = true, results) {
551
+ this.subject = subject;
552
+ this.valid = valid;
553
+ this.results = results;
554
+ }
555
+ get not() {
556
+ return this.clone(!this.valid);
557
+ }
558
+ get and() {
559
+ return this.clone(this.valid);
560
+ }
561
+ get isDefined() {
562
+ return this.clone(this.valid === isDefined(this.subject));
563
+ }
564
+ get isEmpty() {
565
+ return this.clone(this.valid === isEmpty(this.subject));
566
+ }
567
+ get isTrue() {
568
+ return this.clone(this.valid === !!this.subject);
569
+ }
570
+ get isValid() {
571
+ this.results = validate(this.subject);
572
+ return this.clone(this.valid === this.results.isValid);
573
+ }
574
+ isInstance = (c) => this.clone(this.valid === this.subject instanceof c);
575
+ with = (pred) => this.clone(this.valid === ofGet(pred, this.subject));
576
+ contains = (property) => this.clone(this.valid === isDefined(ofGet(property, this.subject)));
577
+ in = (...items) => this.clone(this.valid === isIn(this.subject, toArray(...items)));
578
+ is = (item) => this.clone(this.valid === (this.subject === item));
579
+ reject = (error) => !this.valid ? resolve(this.subject) : reject(ofGet(error, this.subject) ?? this.results ?? Exception.Unknown);
580
+ recover = (f) => resolve(!this.valid ? this.subject : f(this.subject));
581
+ clone = (result = true) => new _When(this.subject, result, this.results);
582
+ };
583
+ var when = (subject) => new When(subject);
584
+
585
+ export {
586
+ When,
587
+ when,
588
+ DotEnvContext,
589
+ BaseRequestContext,
590
+ BaseContext,
591
+ Context,
592
+ ctx,
593
+ toResult,
594
+ isResult,
595
+ Results,
596
+ toResults,
597
+ isResults,
598
+ choose,
599
+ asResults,
600
+ validate,
601
+ validateReject,
602
+ isValid,
603
+ Try,
604
+ tryTo,
605
+ Template,
606
+ template,
607
+ ToText,
608
+ text,
609
+ textValue,
610
+ Exception,
611
+ isException,
612
+ isDoesNotExist
613
+ };
614
+ //# sourceMappingURL=chunk-ZBS4A3QI.mjs.map