@thisisagile/easy 18.12.0 → 18.13.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.
- package/dist/{chunk-BODG3KPC.mjs → chunk-23ZFESSO.mjs} +3 -3
- package/dist/{chunk-HN3HW22I.mjs → chunk-3HEPK3TC.mjs} +2 -2
- package/dist/{chunk-WLTKHBFQ.mjs → chunk-3JALCI3D.mjs} +3 -3
- package/dist/{chunk-ZO6LH5HU.mjs → chunk-4SO7UI5S.mjs} +2 -2
- package/dist/{chunk-DODBPVV5.mjs → chunk-5LVVM522.mjs} +7 -7
- package/dist/{chunk-NQYUWVJT.mjs → chunk-6I4ZNNVM.mjs} +2 -2
- package/dist/{chunk-RF23BV6J.mjs → chunk-7VJ3E3GP.mjs} +2 -2
- package/dist/{chunk-EGGEJRWA.mjs → chunk-AHSUQCHS.mjs} +4 -4
- package/dist/{chunk-I2VWZJ2K.mjs → chunk-BS5KUNX2.mjs} +784 -784
- package/dist/chunk-BS5KUNX2.mjs.map +1 -0
- package/dist/{chunk-YDYQTX4H.mjs → chunk-CB3LF3XW.mjs} +5 -5
- package/dist/{chunk-EHVMIXKR.mjs → chunk-D5U4D63E.mjs} +4 -4
- package/dist/{chunk-M7OD5QSB.mjs → chunk-DMOWSGD3.mjs} +2 -2
- package/dist/{chunk-HAGNDCSR.mjs → chunk-EPCIQ4J3.mjs} +2 -2
- package/dist/{chunk-M7MW5CXO.mjs → chunk-F2W64HKC.mjs} +2 -2
- package/dist/{chunk-3VDUMU5P.mjs → chunk-HI4ZNU6Z.mjs} +2 -2
- package/dist/chunk-HI4ZNU6Z.mjs.map +1 -0
- package/dist/{chunk-EOHHPAAY.mjs → chunk-HWR7EEVI.mjs} +3 -3
- package/dist/{chunk-4AEHKWWI.mjs → chunk-M6I5JHJC.mjs} +2 -2
- package/dist/{chunk-YRVCY3KC.mjs → chunk-MH4VLBIT.mjs} +4 -4
- package/dist/{chunk-4FXDIYQT.mjs → chunk-NL464DQQ.mjs} +3 -3
- package/dist/{chunk-YYXHD3PC.mjs → chunk-NOZLL54Z.mjs} +2 -2
- package/dist/{chunk-TMVZSMUA.mjs → chunk-NTK2UCHO.mjs} +5 -5
- package/dist/{chunk-KXYGCS7S.mjs → chunk-NWUALPMB.mjs} +2 -2
- package/dist/{chunk-UG3NG43J.mjs → chunk-OLL5B5NN.mjs} +3 -3
- package/dist/{chunk-PNSMLGOA.mjs → chunk-P2ZMGAQP.mjs} +2 -2
- package/dist/{chunk-4UKOKM72.mjs → chunk-PFLWEHXS.mjs} +2 -2
- package/dist/{chunk-P4XVLBXB.mjs → chunk-QMIBOIAF.mjs} +2 -2
- package/dist/{chunk-52VT3UEM.mjs → chunk-S5J3TYAZ.mjs} +3 -3
- package/dist/{chunk-KMEBQTNE.mjs → chunk-SATFIUWH.mjs} +2 -2
- package/dist/{chunk-TNLJ45P5.mjs → chunk-T773NDGK.mjs} +2 -2
- package/dist/{chunk-EFFUHXDK.mjs → chunk-T7YVWWJF.mjs} +4 -4
- package/dist/{chunk-XVZYKKLD.mjs → chunk-TN6LYAFX.mjs} +2 -2
- package/dist/{chunk-J2RU23YZ.mjs → chunk-UIL3XRCV.mjs} +3 -3
- package/dist/{chunk-V5TW476J.mjs → chunk-W3LNVDFV.mjs} +2 -2
- package/dist/{chunk-BSN5WGZ6.mjs → chunk-WJGWSFCJ.mjs} +3 -3
- package/dist/{chunk-4NRVIWNE.mjs → chunk-Z37TBPTK.mjs} +2 -2
- package/dist/data/Condition.mjs +4 -4
- package/dist/data/Database.mjs +3 -3
- package/dist/data/Field.mjs +4 -4
- package/dist/data/InMemoryGateway.mjs +4 -4
- package/dist/domain/Audit.mjs +8 -8
- package/dist/domain/Child.mjs +5 -5
- package/dist/domain/DateTime.mjs +4 -4
- package/dist/domain/Entity.mjs +10 -10
- package/dist/domain/Repo.mjs +4 -4
- package/dist/domain/Struct.mjs +4 -4
- package/dist/domain/Typo.mjs +4 -4
- package/dist/http/CacheControl.mjs +4 -4
- package/dist/http/ContentType.mjs +3 -3
- package/dist/http/HttpStatus.mjs +3 -3
- package/dist/http/HttpVerb.mjs +3 -3
- package/dist/http/LocalRequestStore.mjs +2 -2
- package/dist/http/RequestOptions.mjs +4 -4
- package/dist/http/RestResult.mjs +4 -4
- package/dist/http/toResponse.mjs +5 -5
- package/dist/index.js.map +1 -1
- package/dist/process/App.mjs +3 -3
- package/dist/process/Manage.mjs +4 -4
- package/dist/process/Scope.mjs +3 -3
- package/dist/process/Search.mjs +4 -4
- package/dist/process/UseCase.mjs +2 -2
- package/dist/resources/Req.mjs +3 -3
- package/dist/services/Api.mjs +12 -12
- package/dist/services/ApiGateway.mjs +15 -15
- package/dist/services/AxiosProvider.mjs +10 -10
- package/dist/services/MappedRouteGateway.mjs +19 -19
- package/dist/services/RouteGateway.mjs +16 -16
- package/dist/services/ViewRouteGateway.mjs +18 -18
- package/dist/sql/Column.mjs +3 -3
- package/dist/sql/Count.mjs +5 -5
- package/dist/sql/Delete.mjs +4 -4
- package/dist/sql/Insert.mjs +4 -4
- package/dist/sql/Select.mjs +4 -4
- package/dist/sql/SqlQuery.mjs +3 -3
- package/dist/sql/Table.mjs +15 -15
- package/dist/sql/TableGateway.mjs +4 -4
- package/dist/sql/Update.mjs +4 -4
- package/dist/types/Cache.mjs +2 -2
- package/dist/types/CacheAge.mjs +4 -4
- package/dist/types/Case.mjs +2 -2
- package/dist/types/Context.mjs +2 -2
- package/dist/types/Enum.mjs +2 -2
- package/dist/types/Environment.mjs +2 -2
- package/dist/types/ErrorOrigin.mjs +2 -2
- package/dist/types/Exception.mjs +2 -2
- package/dist/types/Gateway.mjs +3 -3
- package/dist/types/IsEqual.mjs +2 -2
- package/dist/types/Json.mjs +3 -3
- package/dist/types/List.d.ts +1 -1
- package/dist/types/List.mjs +2 -2
- package/dist/types/Meta.mjs +2 -2
- package/dist/types/Number.mjs +3 -3
- package/dist/types/Object.mjs +2 -2
- package/dist/types/PageList.d.ts +1 -1
- package/dist/types/PageList.mjs +3 -3
- package/dist/types/Parser.mjs +2 -2
- package/dist/types/Repository.mjs +3 -3
- package/dist/types/Result.mjs +2 -2
- package/dist/types/Results.mjs +2 -2
- package/dist/types/Tag.mjs +2 -2
- package/dist/types/Template.mjs +2 -2
- package/dist/types/ToText.mjs +2 -2
- package/dist/types/Try.mjs +2 -2
- package/dist/types/Uri.mjs +2 -2
- package/dist/utils/If.mjs +2 -2
- package/dist/utils/Mapper.mjs +4 -4
- package/dist/utils/Period.mjs +4 -4
- package/dist/utils/Promise.mjs +2 -2
- package/dist/utils/Seconds.mjs +3 -3
- package/dist/utils/Sentence.mjs +2 -2
- package/dist/utils/View.mjs +5 -5
- package/dist/validation/Contraints.mjs +3 -3
- package/dist/validation/Validate.mjs +2 -2
- package/dist/validation/When.mjs +2 -2
- package/package.json +1 -1
- package/src/types/List.ts +2 -2
- package/src/types/PageList.ts +1 -1
- package/dist/chunk-3VDUMU5P.mjs.map +0 -1
- package/dist/chunk-I2VWZJ2K.mjs.map +0 -1
- /package/dist/{chunk-BODG3KPC.mjs.map → chunk-23ZFESSO.mjs.map} +0 -0
- /package/dist/{chunk-HN3HW22I.mjs.map → chunk-3HEPK3TC.mjs.map} +0 -0
- /package/dist/{chunk-WLTKHBFQ.mjs.map → chunk-3JALCI3D.mjs.map} +0 -0
- /package/dist/{chunk-ZO6LH5HU.mjs.map → chunk-4SO7UI5S.mjs.map} +0 -0
- /package/dist/{chunk-DODBPVV5.mjs.map → chunk-5LVVM522.mjs.map} +0 -0
- /package/dist/{chunk-NQYUWVJT.mjs.map → chunk-6I4ZNNVM.mjs.map} +0 -0
- /package/dist/{chunk-RF23BV6J.mjs.map → chunk-7VJ3E3GP.mjs.map} +0 -0
- /package/dist/{chunk-EGGEJRWA.mjs.map → chunk-AHSUQCHS.mjs.map} +0 -0
- /package/dist/{chunk-YDYQTX4H.mjs.map → chunk-CB3LF3XW.mjs.map} +0 -0
- /package/dist/{chunk-EHVMIXKR.mjs.map → chunk-D5U4D63E.mjs.map} +0 -0
- /package/dist/{chunk-M7OD5QSB.mjs.map → chunk-DMOWSGD3.mjs.map} +0 -0
- /package/dist/{chunk-HAGNDCSR.mjs.map → chunk-EPCIQ4J3.mjs.map} +0 -0
- /package/dist/{chunk-M7MW5CXO.mjs.map → chunk-F2W64HKC.mjs.map} +0 -0
- /package/dist/{chunk-EOHHPAAY.mjs.map → chunk-HWR7EEVI.mjs.map} +0 -0
- /package/dist/{chunk-4AEHKWWI.mjs.map → chunk-M6I5JHJC.mjs.map} +0 -0
- /package/dist/{chunk-YRVCY3KC.mjs.map → chunk-MH4VLBIT.mjs.map} +0 -0
- /package/dist/{chunk-4FXDIYQT.mjs.map → chunk-NL464DQQ.mjs.map} +0 -0
- /package/dist/{chunk-YYXHD3PC.mjs.map → chunk-NOZLL54Z.mjs.map} +0 -0
- /package/dist/{chunk-TMVZSMUA.mjs.map → chunk-NTK2UCHO.mjs.map} +0 -0
- /package/dist/{chunk-KXYGCS7S.mjs.map → chunk-NWUALPMB.mjs.map} +0 -0
- /package/dist/{chunk-UG3NG43J.mjs.map → chunk-OLL5B5NN.mjs.map} +0 -0
- /package/dist/{chunk-PNSMLGOA.mjs.map → chunk-P2ZMGAQP.mjs.map} +0 -0
- /package/dist/{chunk-4UKOKM72.mjs.map → chunk-PFLWEHXS.mjs.map} +0 -0
- /package/dist/{chunk-P4XVLBXB.mjs.map → chunk-QMIBOIAF.mjs.map} +0 -0
- /package/dist/{chunk-52VT3UEM.mjs.map → chunk-S5J3TYAZ.mjs.map} +0 -0
- /package/dist/{chunk-KMEBQTNE.mjs.map → chunk-SATFIUWH.mjs.map} +0 -0
- /package/dist/{chunk-TNLJ45P5.mjs.map → chunk-T773NDGK.mjs.map} +0 -0
- /package/dist/{chunk-EFFUHXDK.mjs.map → chunk-T7YVWWJF.mjs.map} +0 -0
- /package/dist/{chunk-XVZYKKLD.mjs.map → chunk-TN6LYAFX.mjs.map} +0 -0
- /package/dist/{chunk-J2RU23YZ.mjs.map → chunk-UIL3XRCV.mjs.map} +0 -0
- /package/dist/{chunk-V5TW476J.mjs.map → chunk-W3LNVDFV.mjs.map} +0 -0
- /package/dist/{chunk-BSN5WGZ6.mjs.map → chunk-WJGWSFCJ.mjs.map} +0 -0
- /package/dist/{chunk-4NRVIWNE.mjs.map → chunk-Z37TBPTK.mjs.map} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
traverse
|
|
3
|
-
} from "./chunk-SSROJBD5.mjs";
|
|
4
1
|
import {
|
|
5
2
|
isValidatable
|
|
6
3
|
} from "./chunk-EBIF6AMC.mjs";
|
|
7
4
|
import {
|
|
8
5
|
toArray
|
|
9
6
|
} from "./chunk-KCY4RPFR.mjs";
|
|
7
|
+
import {
|
|
8
|
+
traverse
|
|
9
|
+
} from "./chunk-SSROJBD5.mjs";
|
|
10
10
|
import {
|
|
11
11
|
isValue
|
|
12
12
|
} from "./chunk-S3NSPQ7M.mjs";
|
|
@@ -42,949 +42,959 @@ import {
|
|
|
42
42
|
isTrue
|
|
43
43
|
} from "./chunk-AAND4MKF.mjs";
|
|
44
44
|
|
|
45
|
-
// src/types/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
() => toList([...Object.entries(subject), ...Object.entries(Object.getPrototypeOf(subject) ?? {})]),
|
|
50
|
-
() => toList()
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
function values(subject) {
|
|
54
|
-
return toList([...Object.values(subject), ...Object.values(Object.getPrototypeOf(subject) ?? {})]);
|
|
55
|
-
}
|
|
56
|
-
function keys(subject) {
|
|
57
|
-
return toList([...Object.keys(subject), ...Object.keys(Object.getPrototypeOf(subject) ?? {})]);
|
|
58
|
-
}
|
|
59
|
-
function extractKeys(obj, keys2) {
|
|
60
|
-
return keys2.filter((k) => k in obj).reduce(
|
|
61
|
-
(acc, key) => {
|
|
62
|
-
acc.keys[key] = obj[key];
|
|
63
|
-
delete acc[key];
|
|
64
|
-
return acc;
|
|
65
|
-
},
|
|
66
|
-
{ keys: {}, ...obj }
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/utils/Promise.ts
|
|
71
|
-
var resolve = (subject) => Promise.resolve(subject);
|
|
72
|
-
var reject = (e) => Promise.reject(e);
|
|
73
|
-
var tuple = {
|
|
74
|
-
2: (first, second) => Promise.all([first, second]),
|
|
75
|
-
3: (first, second, third) => Promise.all([first, second, third]),
|
|
76
|
-
4: (first, second, third, forth) => Promise.all([first, second, third, forth]),
|
|
77
|
-
5: (first, second, third, forth, fifth) => Promise.all([first, second, third, forth, fifth]),
|
|
78
|
-
all: (first, second) => Promise.all([first, Promise.all(second)]),
|
|
79
|
-
spread: (first, ...second) => Promise.all([first, Promise.all(toArray(second))]),
|
|
80
|
-
list: (list) => Promise.all([...list]).then(toList),
|
|
81
|
-
settled: (list) => Promise.allSettled([...list]).then((rs) => ({
|
|
82
|
-
fulfilled: toList(...rs.filter((r) => r.status === "fulfilled").map((r) => r.value)),
|
|
83
|
-
rejected: toList(...rs.filter((r) => r.status === "rejected").map((r) => asString(r.reason)))
|
|
84
|
-
})),
|
|
85
|
-
object: (obj) => use(keys(obj), (ks) => tuple.list(values(obj)).then((vs) => vs.reduce((acc, v, i) => on(acc, (a) => a[ks[i]] = v), {})))
|
|
86
|
-
};
|
|
87
|
-
var tuple2 = tuple[2];
|
|
88
|
-
var tuple3 = tuple[3];
|
|
89
|
-
var tuple4 = tuple[4];
|
|
90
|
-
var tuple5 = tuple[5];
|
|
91
|
-
var tupleO = tuple.object;
|
|
92
|
-
var settled = tuple.settled;
|
|
93
|
-
|
|
94
|
-
// src/types/Meta.ts
|
|
95
|
-
import "reflect-metadata";
|
|
96
|
-
var ClassMeta = class {
|
|
97
|
-
constructor(subject, data = (subject.prototype ?? subject).constructor) {
|
|
98
|
-
this.subject = subject;
|
|
99
|
-
this.data = data;
|
|
100
|
-
}
|
|
101
|
-
get = (key) => Reflect.getMetadata(key, this.data);
|
|
102
|
-
set = (key, value) => {
|
|
103
|
-
Reflect.defineMetadata(key, value, this.data);
|
|
104
|
-
return value;
|
|
105
|
-
};
|
|
106
|
-
entries = () => entries(this.subject);
|
|
107
|
-
parse = (f, options = {}) => {
|
|
108
|
-
const { initial = {}, skipUndefined = false } = options;
|
|
109
|
-
return this.entries().reduce((a, [k, val]) => use(f(val), (v) => isDefined(v) || !skipUndefined ? on(a, (a2) => a2[k] = v) : a), initial);
|
|
110
|
-
};
|
|
111
|
-
properties = (key) => toList([...Object.getOwnPropertyNames(this.subject), ...Object.getOwnPropertyNames(Object.getPrototypeOf(this.subject))]).map((p) => this.property(p)).filter((p) => key ? p.get(key) : p);
|
|
112
|
-
keys = (key) => this.properties().map((p) => p.get(key)).reduce((list, u) => u ? list.add(u) : list, toList());
|
|
113
|
-
values = () => values(this.subject);
|
|
114
|
-
property = (property) => new PropertyMeta(this.subject, property);
|
|
115
|
-
};
|
|
116
|
-
var PropertyMeta = class {
|
|
117
|
-
constructor(subject, property, data = Reflect.getMetadata(property, subject)) {
|
|
118
|
-
this.subject = subject;
|
|
119
|
-
this.property = property;
|
|
120
|
-
this.data = data;
|
|
121
|
-
}
|
|
122
|
-
get value() {
|
|
123
|
-
return this.subject[this.property];
|
|
45
|
+
// src/types/Case.ts
|
|
46
|
+
var CaseBuilder = class {
|
|
47
|
+
constructor(v) {
|
|
48
|
+
this.v = v;
|
|
124
49
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
}
|
|
129
71
|
};
|
|
130
|
-
|
|
131
|
-
|
|
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));
|
|
72
|
+
if = this.is;
|
|
73
|
+
case(pred, out) {
|
|
74
|
+
return new Case(this.v).case(pred, out);
|
|
168
75
|
}
|
|
169
|
-
|
|
170
|
-
return this.
|
|
76
|
+
type(guard, out) {
|
|
77
|
+
return new Case(this.v).type(guard, out);
|
|
171
78
|
}
|
|
172
|
-
|
|
173
|
-
return this.
|
|
79
|
+
equals(value, out) {
|
|
80
|
+
return new Case(this.v).equals(value, out);
|
|
174
81
|
}
|
|
175
82
|
};
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
83
|
+
var Case = class {
|
|
84
|
+
constructor(value, outcome) {
|
|
85
|
+
this.value = value;
|
|
86
|
+
this.outcome = outcome;
|
|
87
|
+
}
|
|
180
88
|
is = {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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),
|
|
186
98
|
not: {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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)
|
|
190
108
|
}
|
|
191
109
|
};
|
|
192
110
|
if = this.is;
|
|
193
|
-
|
|
194
|
-
|
|
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;
|
|
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);
|
|
206
113
|
}
|
|
207
|
-
|
|
208
|
-
|
|
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);
|
|
209
116
|
}
|
|
210
|
-
|
|
211
|
-
return
|
|
117
|
+
equals(value, out) {
|
|
118
|
+
return this.case(this.value === value, out);
|
|
212
119
|
}
|
|
213
|
-
|
|
214
|
-
return
|
|
120
|
+
else(alt) {
|
|
121
|
+
return ofGet(alt, this.value);
|
|
215
122
|
}
|
|
216
|
-
|
|
217
|
-
|
|
123
|
+
};
|
|
124
|
+
var Found = class extends Case {
|
|
125
|
+
constructor(value, outcome) {
|
|
126
|
+
super(value, outcome);
|
|
127
|
+
this.value = value;
|
|
128
|
+
this.outcome = outcome;
|
|
218
129
|
}
|
|
219
|
-
|
|
130
|
+
case(pred, out) {
|
|
220
131
|
return this;
|
|
221
132
|
}
|
|
222
|
-
|
|
223
|
-
return
|
|
224
|
-
f(this.value);
|
|
225
|
-
return this;
|
|
226
|
-
});
|
|
133
|
+
type(guard, out) {
|
|
134
|
+
return this;
|
|
227
135
|
}
|
|
228
|
-
|
|
229
|
-
return
|
|
230
|
-
if (predicate(this.value))
|
|
231
|
-
return this;
|
|
232
|
-
throw new Error(`Applying filter(${predicate.toString()}) failed.`);
|
|
233
|
-
});
|
|
136
|
+
equals(value, out) {
|
|
137
|
+
return this;
|
|
234
138
|
}
|
|
235
|
-
|
|
236
|
-
return this.
|
|
139
|
+
else(alt) {
|
|
140
|
+
return this.outcome;
|
|
237
141
|
}
|
|
238
|
-
|
|
239
|
-
|
|
142
|
+
};
|
|
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);
|
|
240
183
|
}
|
|
241
|
-
|
|
242
|
-
return this.
|
|
184
|
+
get indexed() {
|
|
185
|
+
return this.map((v, index) => ({ ...v, index }));
|
|
243
186
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
constructor(error) {
|
|
247
|
-
super();
|
|
248
|
-
this.error = error;
|
|
187
|
+
isSubSetOf(...items) {
|
|
188
|
+
return this.diff(items).length === 0;
|
|
249
189
|
}
|
|
250
|
-
|
|
251
|
-
|
|
190
|
+
isSuperSetOf(...items) {
|
|
191
|
+
return this.length > items.length && toList(...items).isSubSetOf(...this);
|
|
252
192
|
}
|
|
253
|
-
|
|
254
|
-
return
|
|
193
|
+
isIntersectingWith(...items) {
|
|
194
|
+
return this.intersect(items).length > 0;
|
|
255
195
|
}
|
|
256
|
-
|
|
257
|
-
return
|
|
196
|
+
isDisjointWith(...items) {
|
|
197
|
+
return !this.isIntersectingWith(...items);
|
|
258
198
|
}
|
|
259
|
-
|
|
260
|
-
return
|
|
199
|
+
areEqual(...items) {
|
|
200
|
+
return this.isSubSetOf(...items) && toList(...items).isSubSetOf(...this);
|
|
261
201
|
}
|
|
262
|
-
|
|
263
|
-
return
|
|
202
|
+
asc(p) {
|
|
203
|
+
return toList(...this).sort((e1, e2) => ofProperty(e1, p) > ofProperty(e2, p) ? 1 : -1);
|
|
264
204
|
}
|
|
265
|
-
|
|
266
|
-
return this;
|
|
205
|
+
desc(p) {
|
|
206
|
+
return toList(...this).sort((e1, e2) => ofProperty(e1, p) < ofProperty(e2, p) ? 1 : -1);
|
|
267
207
|
}
|
|
268
|
-
|
|
269
|
-
return this;
|
|
208
|
+
first(p, params) {
|
|
209
|
+
return p ? this.find(p, params) : this[0];
|
|
270
210
|
}
|
|
271
|
-
|
|
272
|
-
return
|
|
211
|
+
firstValue(f, alt) {
|
|
212
|
+
return ifDefined(
|
|
213
|
+
this.first((t) => !!f(t)),
|
|
214
|
+
f,
|
|
215
|
+
(v) => ofGet(alt, v)
|
|
216
|
+
);
|
|
273
217
|
}
|
|
274
|
-
|
|
275
|
-
return
|
|
218
|
+
isFirst(value) {
|
|
219
|
+
return value === this.first();
|
|
276
220
|
}
|
|
277
|
-
|
|
278
|
-
|
|
221
|
+
next(p, params) {
|
|
222
|
+
return p ? this[this.findIndex(p, params) + 1] : this[0];
|
|
279
223
|
}
|
|
280
|
-
|
|
281
|
-
|
|
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;
|
|
224
|
+
prev(p, params) {
|
|
225
|
+
return p ? this[this.findIndex(p, params) - 1] : this[0];
|
|
289
226
|
}
|
|
290
|
-
|
|
291
|
-
|
|
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;
|
|
227
|
+
last(p, params) {
|
|
228
|
+
return p ? this.filter(p, params).last() : this[this.length - 1];
|
|
319
229
|
}
|
|
320
|
-
|
|
321
|
-
return this.
|
|
230
|
+
isLast(value) {
|
|
231
|
+
return value === this.last();
|
|
322
232
|
}
|
|
323
|
-
|
|
324
|
-
return
|
|
233
|
+
overlaps(...items) {
|
|
234
|
+
return toList(...items).some((i) => this.some((t) => i === t));
|
|
325
235
|
}
|
|
326
|
-
|
|
327
|
-
return this.
|
|
328
|
-
(s) => s.split(" ").map((w) => text(w).cap).join(" ")
|
|
329
|
-
);
|
|
236
|
+
diff(others) {
|
|
237
|
+
return this.filter((i) => !others.includes(i));
|
|
330
238
|
}
|
|
331
|
-
|
|
332
|
-
return this.
|
|
239
|
+
diffByKey(others, key) {
|
|
240
|
+
return this.filter((i) => !others.some((o) => o[key] === i[key]));
|
|
333
241
|
}
|
|
334
|
-
|
|
335
|
-
return this.
|
|
242
|
+
symmetricDiff(others) {
|
|
243
|
+
return this.diff(others).concat(toList(...others).diff(this));
|
|
336
244
|
}
|
|
337
|
-
|
|
338
|
-
return this.
|
|
245
|
+
symmetricDiffByKey(others, key) {
|
|
246
|
+
return this.diffByKey(others, key).concat(toList(...others).diffByKey(this, key));
|
|
339
247
|
}
|
|
340
|
-
|
|
341
|
-
return this.
|
|
248
|
+
intersect(others) {
|
|
249
|
+
return this.filter((i) => others.includes(i));
|
|
342
250
|
}
|
|
343
|
-
|
|
344
|
-
return this.
|
|
251
|
+
intersectByKey(others, key) {
|
|
252
|
+
return this.filter((i) => others.some((o) => o[key] === i[key]));
|
|
345
253
|
}
|
|
346
|
-
|
|
347
|
-
return this.
|
|
254
|
+
intersectBy(others, f) {
|
|
255
|
+
return this.filter((i) => others.some((o) => f(i, o)));
|
|
348
256
|
}
|
|
349
|
-
|
|
350
|
-
return this.map(
|
|
351
|
-
|
|
352
|
-
|
|
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
|
+
});
|
|
353
266
|
}
|
|
354
|
-
|
|
355
|
-
return this.
|
|
267
|
+
toJSON() {
|
|
268
|
+
return this.reduce((a, i) => {
|
|
269
|
+
a.push(JSON.parse(JSON.stringify(i ?? {})));
|
|
270
|
+
return a;
|
|
271
|
+
}, new Array());
|
|
356
272
|
}
|
|
357
|
-
|
|
358
|
-
return
|
|
273
|
+
map(f, params) {
|
|
274
|
+
return toList(super.map(f, params));
|
|
359
275
|
}
|
|
360
|
-
|
|
361
|
-
return
|
|
276
|
+
flatMap(f, params) {
|
|
277
|
+
return toList(super.flatMap(f, params));
|
|
362
278
|
}
|
|
363
|
-
|
|
364
|
-
return this.
|
|
279
|
+
mapDefined(f, params) {
|
|
280
|
+
return this.map(f, params).defined();
|
|
365
281
|
}
|
|
366
|
-
|
|
367
|
-
return
|
|
368
|
-
(s) => s.split(" ").map((w) => w[0]).join("")
|
|
369
|
-
);
|
|
282
|
+
mapAsync(f) {
|
|
283
|
+
return Promise.all(super.map((e) => f(e))).then((a) => toList(a));
|
|
370
284
|
}
|
|
371
|
-
|
|
372
|
-
return
|
|
285
|
+
mapSerial(f) {
|
|
286
|
+
return super.reduce((p, item) => p.then((results) => on(results, async (r) => r.push(await f(item)))), Promise.resolve(toList()));
|
|
373
287
|
}
|
|
374
|
-
|
|
375
|
-
return this.
|
|
376
|
-
(s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
|
|
377
|
-
);
|
|
288
|
+
distinct() {
|
|
289
|
+
return this.filter((i, index) => this.indexOf(i) === index);
|
|
378
290
|
}
|
|
379
|
-
|
|
380
|
-
|
|
291
|
+
distinctByKey(key) {
|
|
292
|
+
const seen = /* @__PURE__ */ new Set();
|
|
293
|
+
return this.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
|
|
381
294
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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;
|
|
295
|
+
distinctByValue() {
|
|
296
|
+
const seen = /* @__PURE__ */ new Set();
|
|
297
|
+
return this.filter((item) => !seen.has(JSON.stringify(item)) && seen.add(JSON.stringify(item)));
|
|
401
298
|
}
|
|
402
|
-
|
|
403
|
-
return
|
|
299
|
+
filter(p, params) {
|
|
300
|
+
return toList(super.filter(p, params));
|
|
404
301
|
}
|
|
405
|
-
|
|
406
|
-
|
|
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;
|
|
302
|
+
sum(p) {
|
|
303
|
+
return this.reduce((sum, i) => sum + p(i), 0);
|
|
423
304
|
}
|
|
424
|
-
|
|
425
|
-
|
|
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;
|
|
305
|
+
max(p) {
|
|
306
|
+
return this.desc(p).first();
|
|
444
307
|
}
|
|
445
|
-
|
|
446
|
-
return this.
|
|
308
|
+
min(p) {
|
|
309
|
+
return this.asc(p).first();
|
|
447
310
|
}
|
|
448
|
-
|
|
449
|
-
return this.
|
|
311
|
+
byId(id) {
|
|
312
|
+
return this.first((i) => equals(i.id, id));
|
|
450
313
|
}
|
|
451
|
-
|
|
452
|
-
return this.
|
|
314
|
+
byKey(key, value) {
|
|
315
|
+
return this.first((i) => i[key] == value);
|
|
453
316
|
}
|
|
454
|
-
|
|
455
|
-
|
|
317
|
+
add(...items) {
|
|
318
|
+
super.push(...toArray(...items));
|
|
319
|
+
return this;
|
|
456
320
|
}
|
|
457
|
-
|
|
458
|
-
return
|
|
321
|
+
concat(...items) {
|
|
322
|
+
return toList(super.concat(...items));
|
|
459
323
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return this.clone(this.valid === this.results.isValid);
|
|
324
|
+
reverse() {
|
|
325
|
+
return toList(super.reverse());
|
|
463
326
|
}
|
|
464
|
-
|
|
465
|
-
|
|
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");
|
|
327
|
+
splice(start, deleteCount, ...items) {
|
|
328
|
+
return toList(super.splice(start, deleteCount, ...items));
|
|
491
329
|
}
|
|
492
|
-
|
|
493
|
-
this.
|
|
330
|
+
remove(item) {
|
|
331
|
+
const index = this.indexOf(item);
|
|
332
|
+
if (index > -1) {
|
|
333
|
+
this.splice(index, 1);
|
|
334
|
+
}
|
|
335
|
+
return this;
|
|
494
336
|
}
|
|
495
|
-
|
|
496
|
-
return this.
|
|
337
|
+
move(sourceId, destinationId) {
|
|
338
|
+
return this.moveOn("id", sourceId, destinationId);
|
|
497
339
|
}
|
|
498
|
-
|
|
499
|
-
|
|
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)));
|
|
500
344
|
}
|
|
501
|
-
|
|
502
|
-
this.
|
|
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;
|
|
503
349
|
}
|
|
504
|
-
|
|
505
|
-
return this.
|
|
350
|
+
switch(item) {
|
|
351
|
+
return this.includes(item) ? this.remove(item) : this.add(item);
|
|
506
352
|
}
|
|
507
|
-
|
|
508
|
-
|
|
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
|
+
);
|
|
509
358
|
}
|
|
510
|
-
|
|
511
|
-
return this.
|
|
359
|
+
defined() {
|
|
360
|
+
return this.reduce((l, v) => isDefined(v) ? l.add(v) : l, toList());
|
|
512
361
|
}
|
|
513
|
-
|
|
514
|
-
this.
|
|
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
|
+
}, {});
|
|
515
369
|
}
|
|
516
|
-
|
|
517
|
-
return this.
|
|
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
|
+
);
|
|
518
380
|
}
|
|
519
|
-
|
|
520
|
-
return this
|
|
381
|
+
orElse(...alt) {
|
|
382
|
+
return !isEmpty(this) ? this : !isEmpty(...alt) ? toList(...alt) : void 0;
|
|
521
383
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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
|
-
};
|
|
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;
|
|
538
389
|
}
|
|
539
|
-
|
|
540
|
-
return
|
|
390
|
+
slice(start, end) {
|
|
391
|
+
return toList(super.slice(start, end));
|
|
541
392
|
}
|
|
542
|
-
|
|
543
|
-
this.
|
|
393
|
+
none(p) {
|
|
394
|
+
return !this.some(p);
|
|
544
395
|
}
|
|
545
|
-
|
|
546
|
-
return this.
|
|
396
|
+
chunk(chunkSize) {
|
|
397
|
+
return this.reduce((acc, _, index) => index % chunkSize === 0 ? on(acc, (a) => a.push(this.slice(index, index + chunkSize))) : acc, toList());
|
|
547
398
|
}
|
|
548
|
-
|
|
549
|
-
|
|
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);
|
|
550
402
|
}
|
|
551
|
-
|
|
552
|
-
|
|
403
|
+
updateFirst(p, val) {
|
|
404
|
+
const index = this.findIndex(p);
|
|
405
|
+
return this.update((t, i) => p(t, i, this) && i == index, val);
|
|
553
406
|
}
|
|
554
|
-
|
|
555
|
-
|
|
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);
|
|
407
|
+
updateFirstById(id, val) {
|
|
408
|
+
return this.updateFirst((i) => equals(i?.id, id), val);
|
|
571
409
|
}
|
|
572
|
-
|
|
573
|
-
return this.
|
|
410
|
+
updateById(id, val) {
|
|
411
|
+
return this.update((i) => equals(i?.id, id), val);
|
|
574
412
|
}
|
|
575
|
-
|
|
576
|
-
return
|
|
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
|
+
);
|
|
577
417
|
}
|
|
578
|
-
add = (...rs) => toResults(...this.results, ...parse(...rs));
|
|
579
418
|
};
|
|
580
|
-
var
|
|
581
|
-
var
|
|
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];
|
|
582
424
|
|
|
583
|
-
// src/
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
+
}
|
|
605
449
|
|
|
606
|
-
// src/
|
|
607
|
-
var
|
|
608
|
-
|
|
609
|
-
|
|
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;
|
|
610
480
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
}
|
|
481
|
+
get = (key) => Reflect.getMetadata(key, this.data);
|
|
482
|
+
set = (key, value) => {
|
|
483
|
+
Reflect.defineMetadata(key, value, this.data);
|
|
484
|
+
return value;
|
|
632
485
|
};
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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);
|
|
495
|
+
};
|
|
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;
|
|
639
501
|
}
|
|
640
|
-
|
|
641
|
-
return
|
|
502
|
+
get value() {
|
|
503
|
+
return this.subject[this.property];
|
|
642
504
|
}
|
|
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
|
+
};
|
|
643
510
|
};
|
|
644
|
-
var
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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;
|
|
648
520
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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)
|
|
669
|
-
}
|
|
670
|
-
};
|
|
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);
|
|
521
|
+
static isEnum = true;
|
|
522
|
+
get isValid() {
|
|
523
|
+
return isDefined(this.id);
|
|
674
524
|
}
|
|
675
|
-
|
|
676
|
-
return
|
|
525
|
+
static all() {
|
|
526
|
+
return meta(this.allTuple()).values();
|
|
677
527
|
}
|
|
678
|
-
|
|
679
|
-
return this.
|
|
528
|
+
static filter(p, params) {
|
|
529
|
+
return this.all().filter(p, params);
|
|
680
530
|
}
|
|
681
|
-
|
|
682
|
-
return
|
|
531
|
+
static first(p, params) {
|
|
532
|
+
return this.all().first(p, params);
|
|
683
533
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
constructor(value, outcome) {
|
|
687
|
-
super(value, outcome);
|
|
688
|
-
this.value = value;
|
|
689
|
-
this.outcome = outcome;
|
|
534
|
+
static byIds(ids = []) {
|
|
535
|
+
return toList(ids).mapDefined((id) => this.byId(id)).distinct();
|
|
690
536
|
}
|
|
691
|
-
|
|
692
|
-
return this;
|
|
537
|
+
static byId(id, alt) {
|
|
538
|
+
return this.allTuple()[id] ?? ofGet(alt);
|
|
693
539
|
}
|
|
694
|
-
|
|
695
|
-
return this;
|
|
540
|
+
static allTuple() {
|
|
541
|
+
return meta(this).get(`all-${this.name}`) ?? meta(this).set(`all-${this.name}`, meta(this).values().filter(isEnum).toObject("id"));
|
|
696
542
|
}
|
|
697
|
-
equals(
|
|
698
|
-
return this;
|
|
543
|
+
equals(other) {
|
|
544
|
+
return this.id === (isEnum(other) ? other.id : other);
|
|
699
545
|
}
|
|
700
|
-
|
|
701
|
-
return this.
|
|
546
|
+
isIn(...items) {
|
|
547
|
+
return items.some((i) => this.equals(i));
|
|
548
|
+
}
|
|
549
|
+
toJSON() {
|
|
550
|
+
return this.id;
|
|
551
|
+
}
|
|
552
|
+
toString() {
|
|
553
|
+
return this.id.toString();
|
|
702
554
|
}
|
|
703
555
|
};
|
|
704
|
-
var
|
|
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));
|
|
556
|
+
var isEnum = (e) => isDefined(e) && e instanceof Enum && isAn(e, "name", "id", "code");
|
|
716
557
|
|
|
717
|
-
// src/
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
)
|
|
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;
|
|
564
|
+
}
|
|
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;
|
|
573
|
+
}
|
|
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
|
+
};
|
|
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
|
+
});
|
|
738
588
|
}
|
|
739
589
|
|
|
740
|
-
// src/types/
|
|
741
|
-
var
|
|
742
|
-
|
|
743
|
-
|
|
590
|
+
// src/types/ToText.ts
|
|
591
|
+
var ToText = class {
|
|
592
|
+
constructor(subject) {
|
|
593
|
+
this.subject = subject;
|
|
594
|
+
}
|
|
595
|
+
get cap() {
|
|
596
|
+
return this.map((s) => capitalize(s?.toLowerCase()));
|
|
597
|
+
}
|
|
598
|
+
get capFirst() {
|
|
599
|
+
return this.map((s) => capitalize(s));
|
|
744
600
|
}
|
|
745
|
-
get
|
|
746
|
-
return this.map(
|
|
601
|
+
get title() {
|
|
602
|
+
return this.map(
|
|
603
|
+
(s) => s.split(" ").map((w) => text(w).cap).join(" ")
|
|
604
|
+
);
|
|
747
605
|
}
|
|
748
|
-
|
|
749
|
-
return this.
|
|
606
|
+
get pascal() {
|
|
607
|
+
return this.title.replace(" ", "");
|
|
750
608
|
}
|
|
751
|
-
|
|
752
|
-
return this.
|
|
609
|
+
get lower() {
|
|
610
|
+
return this.map((s) => s.toLowerCase());
|
|
753
611
|
}
|
|
754
|
-
|
|
755
|
-
return this.
|
|
612
|
+
get upper() {
|
|
613
|
+
return this.map((s) => s.toUpperCase());
|
|
756
614
|
}
|
|
757
|
-
|
|
758
|
-
return
|
|
615
|
+
get camel() {
|
|
616
|
+
return this.title.trim.map((s) => `${s.charAt(0).toLowerCase()}${s.slice(1)}`);
|
|
759
617
|
}
|
|
760
|
-
|
|
761
|
-
return this.
|
|
618
|
+
get kebab() {
|
|
619
|
+
return this.lower.replace(" ", "-");
|
|
762
620
|
}
|
|
763
|
-
|
|
764
|
-
return
|
|
621
|
+
get strictKebab() {
|
|
622
|
+
return this.map((s) => s.replace(/[^a-z\d]+/gi, " ").trim()).kebab;
|
|
765
623
|
}
|
|
766
|
-
|
|
767
|
-
return
|
|
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
|
+
);
|
|
768
628
|
}
|
|
769
|
-
|
|
770
|
-
return
|
|
629
|
+
get snake() {
|
|
630
|
+
return this.upper.replace(" ", "_");
|
|
771
631
|
}
|
|
772
|
-
|
|
773
|
-
return
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
632
|
+
get plural() {
|
|
633
|
+
return this.ifLike("") ?? this.add("s");
|
|
634
|
+
}
|
|
635
|
+
get space() {
|
|
636
|
+
return this.map((s) => s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]/g, " "));
|
|
637
|
+
}
|
|
638
|
+
get sentence() {
|
|
639
|
+
return this.isEmpty ? this : this.map((s) => `${s.charAt(0).toUpperCase()}${s.slice(1)}.`);
|
|
640
|
+
}
|
|
641
|
+
get initials() {
|
|
642
|
+
return this.map(
|
|
643
|
+
(s) => s.split(" ").map((w) => w[0]).join("")
|
|
777
644
|
);
|
|
778
645
|
}
|
|
779
|
-
|
|
780
|
-
return
|
|
646
|
+
get trim() {
|
|
647
|
+
return this.map((s) => s.replace(/[- ,_#]/g, ""));
|
|
781
648
|
}
|
|
782
|
-
|
|
783
|
-
return
|
|
649
|
+
get trimSentence() {
|
|
650
|
+
return this.map(
|
|
651
|
+
(s) => s.replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/[\s\u00A0]+/g, " ").replace(/\s+([.,;:!?])/g, "$1").trim()
|
|
652
|
+
);
|
|
784
653
|
}
|
|
785
|
-
|
|
786
|
-
return
|
|
654
|
+
get isEmpty() {
|
|
655
|
+
return isEmpty(this.toString());
|
|
787
656
|
}
|
|
788
|
-
|
|
789
|
-
|
|
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;
|
|
790
676
|
}
|
|
791
|
-
|
|
792
|
-
return
|
|
677
|
+
toJSON() {
|
|
678
|
+
return this.subject;
|
|
793
679
|
}
|
|
794
|
-
|
|
795
|
-
|
|
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;
|
|
796
698
|
}
|
|
797
|
-
|
|
798
|
-
|
|
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;
|
|
799
719
|
}
|
|
800
|
-
|
|
801
|
-
return this.
|
|
720
|
+
get not() {
|
|
721
|
+
return this.clone(!this.valid);
|
|
802
722
|
}
|
|
803
|
-
|
|
804
|
-
return this.
|
|
723
|
+
get and() {
|
|
724
|
+
return this.clone(this.valid);
|
|
805
725
|
}
|
|
806
|
-
|
|
807
|
-
return this.
|
|
726
|
+
get isDefined() {
|
|
727
|
+
return this.clone(this.valid === isDefined(this.subject));
|
|
808
728
|
}
|
|
809
|
-
|
|
810
|
-
return this.
|
|
729
|
+
get isEmpty() {
|
|
730
|
+
return this.clone(this.valid === isEmpty(this.subject));
|
|
811
731
|
}
|
|
812
|
-
|
|
813
|
-
return this.
|
|
732
|
+
get isTrue() {
|
|
733
|
+
return this.clone(this.valid === !!this.subject);
|
|
814
734
|
}
|
|
815
|
-
|
|
816
|
-
|
|
735
|
+
get isValid() {
|
|
736
|
+
this.results = validate(this.subject);
|
|
737
|
+
return this.clone(this.valid === this.results.isValid);
|
|
817
738
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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");
|
|
827
766
|
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
a.push(JSON.parse(JSON.stringify(i ?? {})));
|
|
831
|
-
return a;
|
|
832
|
-
}, new Array());
|
|
767
|
+
set token(token) {
|
|
768
|
+
this.set("token", token);
|
|
833
769
|
}
|
|
834
|
-
|
|
835
|
-
return
|
|
770
|
+
get identity() {
|
|
771
|
+
return this.token;
|
|
836
772
|
}
|
|
837
|
-
|
|
838
|
-
return
|
|
773
|
+
get jwt() {
|
|
774
|
+
return this.get("jwt");
|
|
839
775
|
}
|
|
840
|
-
|
|
841
|
-
|
|
776
|
+
set jwt(jwt) {
|
|
777
|
+
this.set("jwt", jwt);
|
|
842
778
|
}
|
|
843
|
-
|
|
844
|
-
return
|
|
779
|
+
get correlationId() {
|
|
780
|
+
return this.get("correlationId");
|
|
845
781
|
}
|
|
846
|
-
|
|
847
|
-
|
|
782
|
+
set correlationId(id) {
|
|
783
|
+
this.set("correlationId", id);
|
|
848
784
|
}
|
|
849
|
-
|
|
850
|
-
return this.
|
|
785
|
+
get lastError() {
|
|
786
|
+
return this.get("lastError");
|
|
851
787
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
788
|
+
set lastError(error) {
|
|
789
|
+
this.set("lastError", error);
|
|
790
|
+
}
|
|
791
|
+
get(key) {
|
|
792
|
+
return this.state[key];
|
|
793
|
+
}
|
|
794
|
+
set(key, value) {
|
|
795
|
+
return this.state[key] = value;
|
|
796
|
+
}
|
|
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
|
+
};
|
|
855
813
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
return this.filter((item) => !seen.has(JSON.stringify(item)) && seen.add(JSON.stringify(item)));
|
|
814
|
+
get env() {
|
|
815
|
+
return this.state.env;
|
|
859
816
|
}
|
|
860
|
-
|
|
861
|
-
|
|
817
|
+
set env(env) {
|
|
818
|
+
this.state.env = env;
|
|
862
819
|
}
|
|
863
|
-
|
|
864
|
-
return this.
|
|
820
|
+
get request() {
|
|
821
|
+
return this.state.request;
|
|
865
822
|
}
|
|
866
|
-
|
|
867
|
-
|
|
823
|
+
set request(request) {
|
|
824
|
+
this.state.request = request;
|
|
868
825
|
}
|
|
869
|
-
|
|
870
|
-
return this.
|
|
826
|
+
get other() {
|
|
827
|
+
return this.state.other;
|
|
871
828
|
}
|
|
872
|
-
|
|
873
|
-
|
|
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);
|
|
874
846
|
}
|
|
875
|
-
|
|
876
|
-
return this.
|
|
847
|
+
get length() {
|
|
848
|
+
return this.results.length;
|
|
877
849
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
return this;
|
|
850
|
+
get isValid() {
|
|
851
|
+
return this.results.length === 0;
|
|
881
852
|
}
|
|
882
|
-
|
|
883
|
-
|
|
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));
|
|
884
871
|
}
|
|
885
|
-
|
|
886
|
-
|
|
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;
|
|
887
909
|
}
|
|
888
|
-
|
|
889
|
-
|
|
910
|
+
get error() {
|
|
911
|
+
throw new Error("No error found");
|
|
890
912
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
if (index > -1) {
|
|
894
|
-
this.splice(index, 1);
|
|
895
|
-
}
|
|
896
|
-
return this;
|
|
913
|
+
get isValid() {
|
|
914
|
+
return true;
|
|
897
915
|
}
|
|
898
|
-
|
|
899
|
-
return
|
|
916
|
+
map(f) {
|
|
917
|
+
return tryTo(f, this.value);
|
|
900
918
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
const dest = this.findIndex((i) => equals(i[key], destinationId));
|
|
904
|
-
return on(toList(...this), (r) => r.splice(dest, 0, ...r.splice(source, 1)));
|
|
919
|
+
recover(f) {
|
|
920
|
+
return this;
|
|
905
921
|
}
|
|
906
|
-
|
|
907
|
-
const index = this.findIndex((i) => i[key] === item?.[key]);
|
|
908
|
-
ifTrue(index != -1, () => this.splice(index, 1, item));
|
|
922
|
+
recoverFrom(type, f) {
|
|
909
923
|
return this;
|
|
910
924
|
}
|
|
911
|
-
|
|
912
|
-
return
|
|
925
|
+
accept(f) {
|
|
926
|
+
return tryTo(() => {
|
|
927
|
+
f(this.value);
|
|
928
|
+
return this;
|
|
929
|
+
});
|
|
913
930
|
}
|
|
914
|
-
|
|
915
|
-
return
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
931
|
+
filter(predicate) {
|
|
932
|
+
return tryTo(() => {
|
|
933
|
+
if (predicate(this.value))
|
|
934
|
+
return this;
|
|
935
|
+
throw new Error(`Applying filter(${predicate.toString()}) failed.`);
|
|
936
|
+
});
|
|
919
937
|
}
|
|
920
|
-
|
|
921
|
-
return this.
|
|
938
|
+
or(value) {
|
|
939
|
+
return this.value;
|
|
922
940
|
}
|
|
923
|
-
|
|
924
|
-
return this.
|
|
925
|
-
o[i[key]] = i;
|
|
926
|
-
if (options.deleteKey)
|
|
927
|
-
delete o[i[key]][key];
|
|
928
|
-
return o;
|
|
929
|
-
}, {});
|
|
941
|
+
orElse(value) {
|
|
942
|
+
return this.value;
|
|
930
943
|
}
|
|
931
|
-
|
|
932
|
-
return this.
|
|
933
|
-
(a, t) => {
|
|
934
|
-
const k = t[key];
|
|
935
|
-
a[k] = a[k] ?? toList();
|
|
936
|
-
a[k].push(t);
|
|
937
|
-
return a;
|
|
938
|
-
},
|
|
939
|
-
{}
|
|
940
|
-
);
|
|
944
|
+
orThrow(_error) {
|
|
945
|
+
return this.value;
|
|
941
946
|
}
|
|
942
|
-
|
|
943
|
-
|
|
947
|
+
};
|
|
948
|
+
var Failure = class _Failure extends Try {
|
|
949
|
+
constructor(error) {
|
|
950
|
+
super();
|
|
951
|
+
this.error = error;
|
|
944
952
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
this.splice(i, 0, insertFrom[n++]);
|
|
948
|
-
}
|
|
949
|
-
return this;
|
|
953
|
+
get value() {
|
|
954
|
+
throw this.error;
|
|
950
955
|
}
|
|
951
|
-
|
|
952
|
-
return
|
|
956
|
+
get isValid() {
|
|
957
|
+
return false;
|
|
953
958
|
}
|
|
954
|
-
|
|
955
|
-
return
|
|
959
|
+
map(f) {
|
|
960
|
+
return new _Failure(this.error);
|
|
956
961
|
}
|
|
957
|
-
|
|
958
|
-
return
|
|
962
|
+
recover(f) {
|
|
963
|
+
return tryTo(f, this.error);
|
|
959
964
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
return this.map((v, i, a) => p(v, i, a) ? ofGet(val, v, i, a) : v);
|
|
965
|
+
recoverFrom(type, f) {
|
|
966
|
+
return tryTo(() => this.error instanceof type ? this.recover(f) : this);
|
|
963
967
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
return this.update((t, i) => p(t, i, this) && i == index, val);
|
|
968
|
+
accept(f) {
|
|
969
|
+
return this;
|
|
967
970
|
}
|
|
968
|
-
|
|
969
|
-
return this
|
|
971
|
+
filter(predicate) {
|
|
972
|
+
return this;
|
|
970
973
|
}
|
|
971
|
-
|
|
972
|
-
return
|
|
974
|
+
or(value) {
|
|
975
|
+
return ofGet(value);
|
|
973
976
|
}
|
|
974
|
-
|
|
975
|
-
return
|
|
976
|
-
|
|
977
|
-
|
|
977
|
+
orElse(value) {
|
|
978
|
+
return ofGet(value);
|
|
979
|
+
}
|
|
980
|
+
orThrow(error) {
|
|
981
|
+
throw ofConstruct(error);
|
|
978
982
|
}
|
|
979
983
|
};
|
|
980
|
-
var
|
|
981
|
-
var isList = (l) => isDefined(l) && isArray(l) && isA(l, "first", "last", "asc", "desc");
|
|
982
|
-
var asList = (c, items = []) => toList(toArray(items).map((i) => new c(i)));
|
|
983
|
-
var maxValue = (l, key) => l.desc(key).first()?.[key];
|
|
984
|
-
var minValue = (l, key) => l.asc(key).first()?.[key];
|
|
984
|
+
var tryTo = (c, ...args) => Try.of(c, ...args);
|
|
985
985
|
|
|
986
986
|
export {
|
|
987
|
-
|
|
987
|
+
Try,
|
|
988
|
+
tryTo,
|
|
989
|
+
choose,
|
|
990
|
+
isEqual,
|
|
991
|
+
ifTrue,
|
|
992
|
+
ifFalse,
|
|
993
|
+
ifDefined,
|
|
994
|
+
ifNotEmpty,
|
|
995
|
+
ifEqual,
|
|
996
|
+
ifEither,
|
|
997
|
+
List,
|
|
988
998
|
toList,
|
|
989
999
|
isList,
|
|
990
1000
|
asList,
|
|
@@ -1007,8 +1017,6 @@ export {
|
|
|
1007
1017
|
isEnumConstructor,
|
|
1008
1018
|
Enum,
|
|
1009
1019
|
isEnum,
|
|
1010
|
-
Try,
|
|
1011
|
-
tryTo,
|
|
1012
1020
|
Template,
|
|
1013
1021
|
template,
|
|
1014
1022
|
ToText,
|
|
@@ -1032,14 +1040,6 @@ export {
|
|
|
1032
1040
|
asResults,
|
|
1033
1041
|
validate,
|
|
1034
1042
|
validateReject,
|
|
1035
|
-
isValid
|
|
1036
|
-
choose,
|
|
1037
|
-
isEqual,
|
|
1038
|
-
ifTrue,
|
|
1039
|
-
ifFalse,
|
|
1040
|
-
ifDefined,
|
|
1041
|
-
ifNotEmpty,
|
|
1042
|
-
ifEqual,
|
|
1043
|
-
ifEither
|
|
1043
|
+
isValid
|
|
1044
1044
|
};
|
|
1045
|
-
//# sourceMappingURL=chunk-
|
|
1045
|
+
//# sourceMappingURL=chunk-BS5KUNX2.mjs.map
|