@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
package/dist/index.js CHANGED
@@ -895,162 +895,6 @@ var Enum = class {
895
895
  };
896
896
  var isEnum = (e) => isDefined(e) && e instanceof Enum && isAn(e, "name", "id", "code");
897
897
 
898
- // src/types/Template.ts
899
- var Template = class {
900
- constructor(template2, subject = {}, options = {}) {
901
- this.template = template2;
902
- this.subject = subject;
903
- this.options = options;
904
- }
905
- toString = () => {
906
- return entries(this.options).reduce((t, [k]) => this.option(t, k), this.object()).replace(" ", " ");
907
- };
908
- props = (tmpl, key, result = toList()) => {
909
- const i1 = tmpl.indexOf(`{${key}`);
910
- if (i1 < 0) {
911
- return result;
912
- }
913
- const i2 = tmpl.indexOf("}", i1);
914
- return this.props(tmpl.slice(i2 + 1), key, result.add(tmpl.substring(i1 + 1, i2)));
915
- };
916
- object = () => {
917
- return this.props(this.template, "this").reduce((t, p) => t.replace(`{${p}}`, textValue(this.subject, p.replace("this.", ""))), this.template);
918
- };
919
- option = (tmpl, prop) => {
920
- return this.props(tmpl, prop).reduce((t, p) => t.replace(`{${p}}`, textValue(this.options, p)), tmpl);
921
- };
922
- };
923
- function template(tmpl, subject, options = {}) {
924
- return new Template(asString(tmpl), subject, {
925
- type: toName(subject),
926
- subject: text(JSON.stringify(subject)),
927
- ...options
928
- });
929
- }
930
-
931
- // src/types/ToText.ts
932
- var ToText = class {
933
- constructor(subject) {
934
- this.subject = subject;
935
- }
936
- get cap() {
937
- return this.map((s) => capitalize(s?.toLowerCase()));
938
- }
939
- get capFirst() {
940
- return this.map((s) => capitalize(s));
941
- }
942
- get title() {
943
- return this.map(
944
- (s) => s.split(" ").map((w) => text(w).cap).join(" ")
945
- );
946
- }
947
- get pascal() {
948
- return this.title.replace(" ", "");
949
- }
950
- get lower() {
951
- return this.map((s) => s.toLowerCase());
952
- }
953
- get upper() {
954
- return this.map((s) => s.toUpperCase());
955
- }
956
- get camel() {
957
- return this.title.trim.map((s) => `${s.charAt(0).toLowerCase()}${s.slice(1)}`);
958
- }
959
- get kebab() {
960
- return this.lower.replace(" ", "-");
961
- }
962
- get strictKebab() {
963
- return this.map((s) => s.replace(/[^a-z\d]+/gi, " ").trim()).kebab;
964
- }
965
- get slug() {
966
- return this.map(
967
- (s) => s.replace(/ß/g, "ss").normalize("NFKD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z\d]+/g, "-").replace(/(^-)|(-$)/g, "")
968
- );
969
- }
970
- get snake() {
971
- return this.upper.replace(" ", "_");
972
- }
973
- get plural() {
974
- return this.ifLike("") ?? this.add("s");
975
- }
976
- get space() {
977
- return this.map((s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]/g, " "));
978
- }
979
- get sentence() {
980
- return this.isEmpty ? this : this.map((s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}.`);
981
- }
982
- get initials() {
983
- return this.map(
984
- (s) => s.split(" ").map((w) => w[0]).join("")
985
- );
986
- }
987
- get trim() {
988
- return this.map((s) => s.replace(/[- ,_#]/g, ""));
989
- }
990
- get trimSentence() {
991
- return this.map(
992
- (s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
993
- );
994
- }
995
- get isEmpty() {
996
- return isEmpty(this.toString());
997
- }
998
- parse = (subject, options = {}) => text(template(this.subject, subject, { type: toName(subject), ...options }));
999
- is = (...others) => others.some((o) => this.toString() === text(o).toString());
1000
- equals = this.is;
1001
- like = (...others) => others.some((o) => this.trim.lower.toString().includes(text(o).trim.lower.toString()));
1002
- isLike = (...others) => others.some((o) => this.trim.lower.is(text(o).trim.lower));
1003
- ifLike = (...others) => this.isLike(...others) ? this : void 0;
1004
- endsWith = (end) => this.subject.endsWith(asString(end));
1005
- startsWith = (end) => this.subject.startsWith(asString(end));
1006
- first = (n) => this.map((s) => s.substring(0, n));
1007
- last = (n) => this.map((s) => s.substring(s.length - n));
1008
- map = (func) => text(ofGet(func, this.subject));
1009
- replace = (search, replace) => this.map((s) => replaceAll(s, search, replace));
1010
- add = (add, separator = "") => this.map((s) => isNotEmpty(add) ? `${s}${separator}${text(add)}` : s);
1011
- with = (separator, ...other) => this.map(
1012
- (s) => toList(s).add(...other.map((u) => text(u).toString())).filter((s2) => isNotEmpty(s2)).join(separator)
1013
- );
1014
- split = (separator = " ") => toList(this.subject.split(separator));
1015
- toString() {
1016
- return this.subject;
1017
- }
1018
- toJSON() {
1019
- return this.subject;
1020
- }
1021
- };
1022
- function text(subject, alt = "") {
1023
- const sub = subject ? asString(subject) : alt;
1024
- return new ToText(sub !== "[object Object]" ? sub : "");
1025
- }
1026
- function textValue(subject, prop) {
1027
- const p = prop.split(".");
1028
- const root = subject?.[p[0]];
1029
- const initial = typeof root === "object" && root !== null ? root : text(root);
1030
- return p.splice(1).reduce((t, s) => t?.[s], initial)?.toString() ?? "";
1031
- }
1032
-
1033
- // src/types/Exception.ts
1034
- var Exception = class _Exception extends Enum {
1035
- constructor(message, id, reason) {
1036
- super(message, id ?? text(message).pascal.toString());
1037
- this.message = message;
1038
- this.reason = reason;
1039
- }
1040
- static AlreadyExists = new _Exception("Subject already exists");
1041
- static DoesNotExist = new _Exception("Does not exist");
1042
- static IsMissingId = new _Exception("Subject is missing an id");
1043
- static IsNotImplemented = new _Exception("Is not implemented");
1044
- static IsNotValid = new _Exception("Is not valid");
1045
- static Unknown = new _Exception("Unknown error");
1046
- static CouldNotExecute = (target) => new _Exception(`Could not execute ${target}.`, "CouldNotExecute");
1047
- static CouldNotValidate = (target) => new _Exception(`Could not validate ${target}.`, "CouldNotValidate");
1048
- static EnvironmentVariableNotFound = (variable) => new _Exception(`Environment variable ${text(variable).upper} could not be found.`, "EnvironmentVariableNotFound");
1049
- because = (reason) => new _Exception(this.message, this.id, reason);
1050
- };
1051
- var isException = (e, t) => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);
1052
- var isDoesNotExist = (e) => e instanceof Exception && Exception.DoesNotExist.equals(e);
1053
-
1054
898
  // src/utils/Promise.ts
1055
899
  var resolve = (subject) => Promise.resolve(subject);
1056
900
  var reject = (e) => Promise.reject(e);
@@ -1075,40 +919,6 @@ var tuple5 = tuple[5];
1075
919
  var tupleO = tuple.object;
1076
920
  var settled = tuple.settled;
1077
921
 
1078
- // src/types/Gateway.ts
1079
- var Gateway = class {
1080
- all(options) {
1081
- return reject(Exception.IsNotImplemented);
1082
- }
1083
- byId(id, options) {
1084
- return reject(Exception.IsNotImplemented);
1085
- }
1086
- by(_key, _value, _options) {
1087
- return reject(Exception.IsNotImplemented);
1088
- }
1089
- byIds(..._ids) {
1090
- return reject(Exception.IsNotImplemented);
1091
- }
1092
- search(q, options) {
1093
- return reject(Exception.IsNotImplemented);
1094
- }
1095
- filter(options) {
1096
- return reject(Exception.IsNotImplemented);
1097
- }
1098
- exists(id, options) {
1099
- return reject(Exception.IsNotImplemented);
1100
- }
1101
- add(item, options) {
1102
- return reject(Exception.IsNotImplemented);
1103
- }
1104
- update(item, options) {
1105
- return reject(Exception.IsNotImplemented);
1106
- }
1107
- remove(id, options) {
1108
- return reject(Exception.IsNotImplemented);
1109
- }
1110
- };
1111
-
1112
922
  // src/validation/When.ts
1113
923
  var When = class _When {
1114
924
  constructor(subject, valid2 = true, results) {
@@ -1254,55 +1064,160 @@ var Results = class {
1254
1064
  var toResults = (...r) => new Results(...r);
1255
1065
  var isResults = (r) => isDefined(r) && r instanceof Results;
1256
1066
 
1257
- // src/types/Value.ts
1258
- var Value = class {
1259
- constructor(value) {
1260
- this.value = value;
1261
- this.value = value;
1067
+ // src/types/Case.ts
1068
+ var CaseBuilder = class {
1069
+ constructor(v) {
1070
+ this.v = v;
1262
1071
  }
1263
- get isValid() {
1264
- return isDefined(this.value);
1072
+ is = {
1073
+ true: (pred, out) => new Case(this.v).case(pred, out),
1074
+ false: (pred, out) => new Case(this.v).case(!ofGet(pred, this.v), out),
1075
+ defined: (prop, out) => new Case(this.v).case(isDefined(prop(this.v)), out),
1076
+ empty: (prop, out) => new Case(this.v).case(isEmpty(prop(this.v)), out),
1077
+ valid: (prop, out) => new Case(this.v).case(validate(prop(this.v)).isValid, out),
1078
+ in: (prop, out) => new Case(this.v).case(ofGet(prop, this.v).includes(this.v), out),
1079
+ not: {
1080
+ true: (pred, out) => new Case(this.v).case(!ofGet(pred, this.v), out),
1081
+ false: (pred, out) => new Case(this.v).case(pred, out),
1082
+ defined: (prop, out) => new Case(this.v).case(!isDefined(prop(this.v)), out),
1083
+ empty: (prop, out) => new Case(this.v).case(!isEmpty(prop(this.v)), out),
1084
+ valid: (prop, out) => new Case(this.v).case(!validate(prop(this.v)).isValid, out),
1085
+ in: (prop, out) => new Case(this.v).case(!ofGet(prop, this.v).includes(this.v), out)
1086
+ }
1087
+ };
1088
+ if = this.is;
1089
+ case(pred, out) {
1090
+ return new Case(this.v).case(pred, out);
1265
1091
  }
1266
- toJSON() {
1267
- return this.value;
1092
+ type(guard, out) {
1093
+ return new Case(this.v).type(guard, out);
1268
1094
  }
1269
- toString() {
1270
- return asString(this.value);
1095
+ equals(value, out) {
1096
+ return new Case(this.v).equals(value, out);
1271
1097
  }
1272
1098
  };
1273
- var isValue = (v) => v instanceof Value;
1274
-
1275
- // src/types/Validatable.ts
1276
- var isValidatable = (v) => isA(v, "isValid");
1277
-
1278
- // src/validation/Validate.ts
1279
- var asResults = (subject, template2, options = {}) => toResults(toResult(text(template2).parse(subject, options), toName(subject)));
1280
- var validators = (subject) => meta(subject).keys("constraint").reduce((list, vs) => list.add(vs), toList());
1281
- var runValidator = (v, subject) => {
1282
- try {
1283
- const actual = isFunction(subject[v.property]) ? subject[v.property]() : subject[v.property];
1284
- const constraint2 = v.constraint(actual);
1285
- return isResults(constraint2) ? constraint2 : !constraint2 ? asResults(subject, v.text, {
1286
- ...v,
1287
- actual
1288
- }) : toResults();
1289
- } catch (e) {
1290
- return asResults(subject, asString(e));
1099
+ var Case = class _Case {
1100
+ constructor(value, outcome) {
1101
+ this.value = value;
1102
+ this.outcome = outcome;
1291
1103
  }
1292
- };
1293
- var constraints = (subject) => validators(subject).map((vs) => runValidator(vs, subject)).reduce((rs, r) => rs.add(...r.results), toResults());
1294
- var validate = (subject) => choose(subject).is.not.defined(
1295
- (s) => s,
1296
- () => toResults("Subject is not defined.")
1297
- ).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());
1298
- var validateReject = (subject) => when(subject).not.isValid.reject();
1299
- var isValid = (t) => validate(t).isValid;
1300
-
1301
- // src/types/Try.ts
1302
- var Try = class _Try {
1303
1104
  is = {
1304
- defined: (prop) => this.filter((v) => isDefined(prop ? prop(v) : v)),
1305
- empty: (prop) => this.filter((v) => isEmpty(prop ? prop(v) : v)),
1105
+ true: (pred, out) => new _Case(this.value).case(pred, out),
1106
+ false: (pred, out) => new _Case(this.value).case(!ofGet(pred, this.value), out),
1107
+ defined: (prop, out) => new _Case(this.value).case(isDefined(prop(this.value)), out),
1108
+ empty: (prop, out) => new _Case(this.value).case(isEmpty(prop(this.value)), out),
1109
+ valid: (prop, out) => new _Case(this.value).case(validate(prop(this.value)).isValid, out),
1110
+ in: (prop, out) => new _Case(this.value).case(ofGet(prop, this.value).includes(this.value), out),
1111
+ not: {
1112
+ true: (pred, out) => new _Case(this.value).case(!ofGet(pred, this.value), out),
1113
+ false: (pred, out) => new _Case(this.value).case(pred, out),
1114
+ defined: (prop, out) => new _Case(this.value).case(!isDefined(prop(this.value)), out),
1115
+ empty: (prop, out) => new _Case(this.value).case(!isEmpty(prop(this.value)), out),
1116
+ valid: (prop, out) => new _Case(this.value).case(!validate(prop(this.value)).isValid, out),
1117
+ in: (prop, out) => new _Case(this.value).case(!ofGet(prop, this.value).includes(this.value), out)
1118
+ }
1119
+ };
1120
+ if = this.is;
1121
+ case(pred, out) {
1122
+ return tryTo(pred, this.value).is.true().map(() => ofGet(out, this.value)).map((res) => new Found(this.value, res)).or(this);
1123
+ }
1124
+ type(guard, out) {
1125
+ return tryTo(guard, this.value).is.true().map(() => out(this.value)).map((res) => new Found(this.value, res)).or(this);
1126
+ }
1127
+ equals(value, out) {
1128
+ return this.case(this.value === value, out);
1129
+ }
1130
+ else(alt) {
1131
+ return ofGet(alt, this.value);
1132
+ }
1133
+ };
1134
+ var Found = class extends Case {
1135
+ constructor(value, outcome) {
1136
+ super(value, outcome);
1137
+ this.value = value;
1138
+ this.outcome = outcome;
1139
+ }
1140
+ is = {
1141
+ true: (_pred, _out) => this,
1142
+ false: (_pred, _out) => this,
1143
+ defined: (_prop, _out) => this,
1144
+ empty: (_prop, _out) => this,
1145
+ valid: (_prop, _out) => this,
1146
+ in: (_prop, _out) => this,
1147
+ not: {
1148
+ true: (_pred, _out) => this,
1149
+ false: (_pred, _out) => this,
1150
+ defined: (_prop, _out) => this,
1151
+ empty: (_prop, _out) => this,
1152
+ valid: (_prop, _out) => this,
1153
+ in: (_prop, _out) => this
1154
+ }
1155
+ };
1156
+ if = this.is;
1157
+ case(pred, out) {
1158
+ return this;
1159
+ }
1160
+ type(guard, out) {
1161
+ return this;
1162
+ }
1163
+ equals(value, out) {
1164
+ return this;
1165
+ }
1166
+ else(alt) {
1167
+ return this.outcome;
1168
+ }
1169
+ };
1170
+ var choose = (value) => new CaseBuilder(value);
1171
+
1172
+ // src/types/Value.ts
1173
+ var Value = class {
1174
+ constructor(value) {
1175
+ this.value = value;
1176
+ this.value = value;
1177
+ }
1178
+ get isValid() {
1179
+ return isDefined(this.value);
1180
+ }
1181
+ toJSON() {
1182
+ return this.value;
1183
+ }
1184
+ toString() {
1185
+ return asString(this.value);
1186
+ }
1187
+ };
1188
+ var isValue = (v) => v instanceof Value;
1189
+
1190
+ // src/types/Validatable.ts
1191
+ var isValidatable = (v) => isA(v, "isValid");
1192
+
1193
+ // src/validation/Validate.ts
1194
+ var asResults = (subject, template2, options = {}) => toResults(toResult(text(template2).parse(subject, options), toName(subject)));
1195
+ var validators = (subject) => meta(subject).keys("constraint").reduce((list, vs) => list.add(vs), toList());
1196
+ var runValidator = (v, subject) => {
1197
+ try {
1198
+ const actual = isFunction(subject[v.property]) ? subject[v.property]() : subject[v.property];
1199
+ const constraint2 = v.constraint(actual);
1200
+ return isResults(constraint2) ? constraint2 : !constraint2 ? asResults(subject, v.text, {
1201
+ ...v,
1202
+ actual
1203
+ }) : toResults();
1204
+ } catch (e) {
1205
+ return asResults(subject, asString(e));
1206
+ }
1207
+ };
1208
+ var constraints = (subject) => validators(subject).map((vs) => runValidator(vs, subject)).reduce((rs, r) => rs.add(...r.results), toResults());
1209
+ var validate = (subject) => choose(subject).is.not.defined(
1210
+ (s) => s,
1211
+ () => toResults("Subject is not defined.")
1212
+ ).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());
1213
+ var validateReject = (subject) => when(subject).not.isValid.reject();
1214
+ var isValid = (t) => validate(t).isValid;
1215
+
1216
+ // src/types/Try.ts
1217
+ var Try = class _Try {
1218
+ is = {
1219
+ defined: (prop) => this.filter((v) => isDefined(prop ? prop(v) : v)),
1220
+ empty: (prop) => this.filter((v) => isEmpty(prop ? prop(v) : v)),
1306
1221
  valid: (prop) => this.filter((v) => validate(prop ? prop(v) : v).isValid),
1307
1222
  true: (prop) => this.filter((v) => isTrue(prop ? prop(v) : v)),
1308
1223
  false: (prop) => this.filter((v) => !isTrue(prop ? prop(v) : v)),
@@ -1403,98 +1318,194 @@ var Failure = class _Failure extends Try {
1403
1318
  };
1404
1319
  var tryTo = (c, ...args) => Try.of(c, ...args);
1405
1320
 
1406
- // src/types/Case.ts
1407
- var CaseBuilder = class {
1408
- constructor(v) {
1409
- this.v = v;
1321
+ // src/types/Template.ts
1322
+ var Template = class {
1323
+ constructor(template2, subject = {}, options = {}) {
1324
+ this.template = template2;
1325
+ this.subject = subject;
1326
+ this.options = options;
1410
1327
  }
1411
- is = {
1412
- defined: (prop, out) => new Case(this.v).case(isDefined(prop(this.v)), out),
1413
- empty: (prop, out) => new Case(this.v).case(isEmpty(prop(this.v)), out),
1414
- valid: (prop, out) => new Case(this.v).case(validate(prop(this.v)).isValid, out),
1415
- in: (prop, out) => new Case(this.v).case(ofGet(prop, this.v).includes(this.v), out),
1416
- not: {
1417
- defined: (prop, out) => new Case(this.v).case(!isDefined(prop(this.v)), out),
1418
- empty: (prop, out) => new Case(this.v).case(!isEmpty(prop(this.v)), out),
1419
- valid: (prop, out) => new Case(this.v).case(!validate(prop(this.v)).isValid, out),
1420
- in: (prop, out) => new Case(this.v).case(!ofGet(prop, this.v).includes(this.v), out)
1328
+ knownPrefixes = /* @__PURE__ */ new Set(["type", "property", "actual", "subject"]);
1329
+ toString = () => {
1330
+ return entries(this.options).reduce((t, [k]) => this.option(t, k), this.object()).replace(" ", " ");
1331
+ };
1332
+ props = (tmpl, key, result = toList()) => {
1333
+ const i1 = tmpl.indexOf(`{${key}`);
1334
+ if (i1 < 0) {
1335
+ return result;
1421
1336
  }
1337
+ const i2 = tmpl.indexOf("}", i1);
1338
+ return this.props(tmpl.slice(i2 + 1), key, result.add(tmpl.substring(i1 + 1, i2)));
1422
1339
  };
1423
- if = this.is;
1424
- case(pred, out) {
1425
- return new Case(this.v).case(pred, out);
1340
+ 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("");
1341
+ option = (tmpl, prop) => {
1342
+ return this.props(tmpl, prop).reduce((t, p) => t.replace(`{${p}}`, textValue(this.options, p)), tmpl);
1343
+ };
1344
+ };
1345
+ function template(tmpl, subject, options = {}) {
1346
+ return new Template(asString(tmpl), subject, {
1347
+ type: toName(subject),
1348
+ subject: text(JSON.stringify(subject)),
1349
+ ...options
1350
+ });
1351
+ }
1352
+
1353
+ // src/types/ToText.ts
1354
+ var ToText = class {
1355
+ constructor(subject) {
1356
+ this.subject = subject;
1426
1357
  }
1427
- type(guard, out) {
1428
- return new Case(this.v).type(guard, out);
1358
+ get cap() {
1359
+ return this.map((s) => capitalize(s?.toLowerCase()));
1429
1360
  }
1430
- equals(value, out) {
1431
- return new Case(this.v).equals(value, out);
1361
+ get capFirst() {
1362
+ return this.map((s) => capitalize(s));
1432
1363
  }
1433
- };
1434
- var Case = class _Case {
1435
- constructor(value, outcome) {
1436
- this.value = value;
1437
- this.outcome = outcome;
1364
+ get title() {
1365
+ return this.map(
1366
+ (s) => s.split(" ").map((w) => text(w).cap).join(" ")
1367
+ );
1438
1368
  }
1439
- is = {
1440
- defined: (prop, out) => new _Case(this.value).case(isDefined(prop(this.value)), out),
1441
- empty: (prop, out) => new _Case(this.value).case(isEmpty(prop(this.value)), out),
1442
- valid: (prop, out) => new _Case(this.value).case(validate(prop(this.value)).isValid, out),
1443
- in: (prop, out) => new _Case(this.value).case(ofGet(prop, this.value).includes(this.value), out),
1444
- not: {
1445
- defined: (prop, out) => new _Case(this.value).case(!isDefined(prop(this.value)), out),
1446
- empty: (prop, out) => new _Case(this.value).case(!isEmpty(prop(this.value)), out),
1447
- valid: (prop, out) => new _Case(this.value).case(!validate(prop(this.value)).isValid, out),
1448
- in: (prop, out) => new _Case(this.value).case(!ofGet(prop, this.value).includes(this.value), out)
1449
- }
1450
- };
1451
- if = this.is;
1452
- case(pred, out) {
1453
- return tryTo(pred, this.value).is.true().map(() => ofGet(out, this.value)).map((res) => new Found(this.value, res)).or(this);
1369
+ get pascal() {
1370
+ return this.title.replace(" ", "");
1454
1371
  }
1455
- type(guard, out) {
1456
- return tryTo(guard, this.value).is.true().map(() => out(this.value)).map((res) => new Found(this.value, res)).or(this);
1372
+ get lower() {
1373
+ return this.map((s) => s.toLowerCase());
1457
1374
  }
1458
- equals(value, out) {
1459
- return this.case(this.value === value, out);
1375
+ get upper() {
1376
+ return this.map((s) => s.toUpperCase());
1460
1377
  }
1461
- else(alt) {
1462
- return ofGet(alt, this.value);
1378
+ get camel() {
1379
+ return this.title.trim.map((s) => `${s.charAt(0).toLowerCase()}${s.slice(1)}`);
1380
+ }
1381
+ get kebab() {
1382
+ return this.lower.replace(" ", "-");
1383
+ }
1384
+ get strictKebab() {
1385
+ return this.map((s) => s.replace(/[^a-z\d]+/gi, " ").trim()).kebab;
1386
+ }
1387
+ get slug() {
1388
+ return this.map(
1389
+ (s) => s.replace(/ß/g, "ss").normalize("NFKD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z\d]+/g, "-").replace(/(^-)|(-$)/g, "")
1390
+ );
1391
+ }
1392
+ get snake() {
1393
+ return this.upper.replace(" ", "_");
1394
+ }
1395
+ get plural() {
1396
+ return this.ifLike("") ?? this.add("s");
1397
+ }
1398
+ get space() {
1399
+ return this.map((s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]/g, " "));
1400
+ }
1401
+ get sentence() {
1402
+ return this.isEmpty ? this : this.map((s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}.`);
1403
+ }
1404
+ get initials() {
1405
+ return this.map(
1406
+ (s) => s.split(" ").map((w) => w[0]).join("")
1407
+ );
1408
+ }
1409
+ get trim() {
1410
+ return this.map((s) => s.replace(/[- ,_#]/g, ""));
1411
+ }
1412
+ get trimSentence() {
1413
+ return this.map(
1414
+ (s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
1415
+ );
1416
+ }
1417
+ get isEmpty() {
1418
+ return isEmpty(this.toString());
1419
+ }
1420
+ parse = (subject, options = {}) => text(template(this.subject, subject, { type: toName(subject), ...options }));
1421
+ is = (...others) => others.some((o) => this.toString() === text(o).toString());
1422
+ equals = this.is;
1423
+ like = (...others) => others.some((o) => this.trim.lower.toString().includes(text(o).trim.lower.toString()));
1424
+ isLike = (...others) => others.some((o) => this.trim.lower.is(text(o).trim.lower));
1425
+ ifLike = (...others) => this.isLike(...others) ? this : void 0;
1426
+ endsWith = (end) => this.subject.endsWith(asString(end));
1427
+ startsWith = (end) => this.subject.startsWith(asString(end));
1428
+ first = (n) => this.map((s) => s.substring(0, n));
1429
+ last = (n) => this.map((s) => s.substring(s.length - n));
1430
+ map = (func) => text(ofGet(func, this.subject));
1431
+ replace = (search, replace) => this.map((s) => replaceAll(s, search, replace));
1432
+ add = (add, separator = "") => this.map((s) => isNotEmpty(add) ? `${s}${separator}${text(add)}` : s);
1433
+ with = (separator, ...other) => this.map(
1434
+ (s) => toList(s).add(...other.map((u) => text(u).toString())).filter((s2) => isNotEmpty(s2)).join(separator)
1435
+ );
1436
+ split = (separator = " ") => toList(this.subject.split(separator));
1437
+ toString() {
1438
+ return this.subject;
1439
+ }
1440
+ toJSON() {
1441
+ return this.subject;
1463
1442
  }
1464
1443
  };
1465
- var Found = class extends Case {
1466
- constructor(value, outcome) {
1467
- super(value, outcome);
1468
- this.value = value;
1469
- this.outcome = outcome;
1444
+ function text(subject, alt = "") {
1445
+ const sub = subject ? asString(subject) : alt;
1446
+ return new ToText(sub !== "[object Object]" ? sub : "");
1447
+ }
1448
+ function textValue(subject, prop) {
1449
+ const p = prop.split(".");
1450
+ const root = subject?.[p[0]];
1451
+ const initial = typeof root === "object" && root !== null ? root : text(root);
1452
+ return p.splice(1).reduce((t, s) => (typeof t === "object" && t !== null ? t : text(t))?.[s], initial)?.toString() ?? "";
1453
+ }
1454
+
1455
+ // src/types/Exception.ts
1456
+ var Exception = class _Exception extends Enum {
1457
+ constructor(message, id, reason) {
1458
+ super(message, id ?? text(message).pascal.toString());
1459
+ this.message = message;
1460
+ this.reason = reason;
1470
1461
  }
1471
- is = {
1472
- defined: (_prop, _out) => this,
1473
- empty: (_prop, _out) => this,
1474
- valid: (_prop, _out) => this,
1475
- in: (_prop, _out) => this,
1476
- not: {
1477
- defined: (_prop, _out) => this,
1478
- empty: (_prop, _out) => this,
1479
- valid: (_prop, _out) => this,
1480
- in: (_prop, _out) => this
1481
- }
1482
- };
1483
- if = this.is;
1484
- case(pred, out) {
1485
- return this;
1462
+ static AlreadyExists = new _Exception("Subject already exists");
1463
+ static DoesNotExist = new _Exception("Does not exist");
1464
+ static IsMissingId = new _Exception("Subject is missing an id");
1465
+ static IsNotImplemented = new _Exception("Is not implemented");
1466
+ static IsNotValid = new _Exception("Is not valid");
1467
+ static Unknown = new _Exception("Unknown error");
1468
+ static CouldNotExecute = (target) => new _Exception(`Could not execute ${target}.`, "CouldNotExecute");
1469
+ static CouldNotValidate = (target) => new _Exception(`Could not validate ${target}.`, "CouldNotValidate");
1470
+ static EnvironmentVariableNotFound = (variable) => new _Exception(`Environment variable ${text(variable).upper} could not be found.`, "EnvironmentVariableNotFound");
1471
+ because = (reason) => new _Exception(this.message, this.id, reason);
1472
+ };
1473
+ var isException = (e, t) => e instanceof Exception && (isDefined(t) ? e.equals(asString(t)) : true);
1474
+ var isDoesNotExist = (e) => e instanceof Exception && Exception.DoesNotExist.equals(e);
1475
+
1476
+ // src/types/Gateway.ts
1477
+ var Gateway = class {
1478
+ all(options) {
1479
+ return reject(Exception.IsNotImplemented);
1486
1480
  }
1487
- type(guard, out) {
1488
- return this;
1481
+ byId(id, options) {
1482
+ return reject(Exception.IsNotImplemented);
1489
1483
  }
1490
- equals(value, out) {
1491
- return this;
1484
+ by(_key, _value, _options) {
1485
+ return reject(Exception.IsNotImplemented);
1492
1486
  }
1493
- else(alt) {
1494
- return this.outcome;
1487
+ byIds(..._ids) {
1488
+ return reject(Exception.IsNotImplemented);
1489
+ }
1490
+ search(q, options) {
1491
+ return reject(Exception.IsNotImplemented);
1492
+ }
1493
+ filter(options) {
1494
+ return reject(Exception.IsNotImplemented);
1495
+ }
1496
+ exists(id, options) {
1497
+ return reject(Exception.IsNotImplemented);
1498
+ }
1499
+ add(item, options) {
1500
+ return reject(Exception.IsNotImplemented);
1501
+ }
1502
+ update(item, options) {
1503
+ return reject(Exception.IsNotImplemented);
1504
+ }
1505
+ remove(id, options) {
1506
+ return reject(Exception.IsNotImplemented);
1495
1507
  }
1496
1508
  };
1497
- var choose = (value) => new CaseBuilder(value);
1498
1509
 
1499
1510
  // src/types/PageList.ts
1500
1511
  var toFilter = (field, value) => toShortFilter(field, field, value);