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