@aeriajs/common 0.0.24 → 0.0.26
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/arraysIntersects.mjs +6 -7
- package/dist/checkForUndefined.mjs +6 -5
- package/dist/convertConditionToQuery.mjs +53 -68
- package/dist/date.mjs +31 -96
- package/dist/deepClone.mjs +3 -2
- package/dist/deepMerge.mjs +30 -62
- package/dist/dynamicImport.mjs +12 -145
- package/dist/either.mjs +24 -27
- package/dist/evaluateCondition.mjs +56 -59
- package/dist/formatValue.mjs +46 -55
- package/dist/freshItem.mjs +32 -129
- package/dist/getMissingProperties.mjs +36 -44
- package/dist/getReferenceProperty.mjs +9 -10
- package/dist/getValueFromPath.mjs +6 -5
- package/dist/http.mjs +39 -220
- package/dist/index.mjs +1 -0
- package/dist/isReference.mjs +3 -2
- package/dist/isRequired.mjs +13 -12
- package/dist/pipe.mjs +21 -255
- package/dist/schema.mjs +61 -64
- package/dist/serialize.mjs +4 -36
- package/package.json +3 -3
|
@@ -1,63 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { arraysIntersects } from "./arraysIntersects.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const equalOrContains = (term1, term2) => {
|
|
4
|
+
if (Array.isArray(term1) && Array.isArray(term2)) {
|
|
5
|
+
return arraysIntersects(term1, term2);
|
|
6
|
+
}
|
|
7
|
+
if (Array.isArray(term1)) {
|
|
8
|
+
return term1.includes(term2);
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(term2)) {
|
|
11
|
+
return term2.includes(term1);
|
|
12
|
+
}
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if ("not" in condition) {
|
|
49
|
-
return !evaluatesToTrue(subject, condition.not);
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
14
|
+
const evaluatesToTrue = (subject, condition) => {
|
|
15
|
+
if ("term1" in condition) {
|
|
16
|
+
if (!subject) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const term1 = subject[condition.term1];
|
|
20
|
+
if (condition.operator === "truthy") {
|
|
21
|
+
return !!term1;
|
|
22
|
+
}
|
|
23
|
+
const { operator, term2 } = condition;
|
|
24
|
+
switch (operator) {
|
|
25
|
+
case "equal":
|
|
26
|
+
return term1 === term2;
|
|
27
|
+
case "in":
|
|
28
|
+
return !!equalOrContains(term1, term2);
|
|
29
|
+
case "gt":
|
|
30
|
+
return term1 > term2;
|
|
31
|
+
case "lt":
|
|
32
|
+
return term1 < term2;
|
|
33
|
+
case "gte":
|
|
34
|
+
return term1 >= term2;
|
|
35
|
+
case "lte":
|
|
36
|
+
return term1 <= term2;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if ("and" in condition) {
|
|
40
|
+
return condition.and.every((condition2) => evaluatesToTrue(subject, condition2));
|
|
41
|
+
}
|
|
42
|
+
if ("or" in condition) {
|
|
43
|
+
return condition.or.some((condition2) => evaluatesToTrue(subject, condition2));
|
|
44
|
+
}
|
|
45
|
+
if ("not" in condition) {
|
|
46
|
+
return !evaluatesToTrue(subject, condition.not);
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
52
49
|
};
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
export const evaluateCondition = (subject, condition) => {
|
|
51
|
+
const result = {
|
|
52
|
+
satisfied: false,
|
|
53
|
+
else: null
|
|
54
|
+
};
|
|
55
|
+
const satisfied = result.satisfied = evaluatesToTrue(subject, condition);
|
|
56
|
+
if (!satisfied && "else" in condition) {
|
|
57
|
+
result.else = condition.else;
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
63
60
|
};
|
package/dist/formatValue.mjs
CHANGED
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
3
|
-
return !!right[Symbol.hasInstance](left);
|
|
4
|
-
} else {
|
|
5
|
-
return left instanceof right;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
"use strict";
|
|
8
2
|
import { formatDateTime } from "./date.mjs";
|
|
9
3
|
import { getReferenceProperty } from "./getReferenceProperty.mjs";
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export const formatValue = (value, key, property, index) => {
|
|
5
|
+
if (Array.isArray(value)) {
|
|
6
|
+
return value.map((v) => formatValue(v, key, property, index)).join(", ");
|
|
7
|
+
}
|
|
8
|
+
const firstValue = (() => {
|
|
9
|
+
if (!property) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
const refProperty = getReferenceProperty(property);
|
|
13
|
+
if (refProperty) {
|
|
14
|
+
const firstIndex = index || refProperty.indexes?.[0];
|
|
15
|
+
return firstIndex && value?.[firstIndex];
|
|
16
|
+
}
|
|
17
|
+
if (value instanceof Object) {
|
|
18
|
+
return Object.values(value)[0];
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
})();
|
|
22
|
+
const formatted = (() => {
|
|
23
|
+
if (!property) {
|
|
24
|
+
return firstValue;
|
|
25
|
+
}
|
|
26
|
+
if ("type" in property) {
|
|
27
|
+
if (property.type === "boolean") {
|
|
28
|
+
return firstValue ? "true" : false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if ("format" in property && property.format) {
|
|
32
|
+
if ([
|
|
33
|
+
"date",
|
|
34
|
+
"date-time"
|
|
35
|
+
].includes(property.format)) {
|
|
36
|
+
return formatDateTime(String(value), {
|
|
37
|
+
hours: property.format === "date-time"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if ([
|
|
42
|
+
void 0,
|
|
43
|
+
null
|
|
44
|
+
].includes(firstValue)) {
|
|
45
|
+
return "-";
|
|
15
46
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
var refProperty = getReferenceProperty(property);
|
|
21
|
-
if (refProperty) {
|
|
22
|
-
var _refProperty_indexes;
|
|
23
|
-
var firstIndex = index || ((_refProperty_indexes = refProperty.indexes) === null || _refProperty_indexes === void 0 ? void 0 : _refProperty_indexes[0]);
|
|
24
|
-
return firstIndex && (value === null || value === void 0 ? void 0 : value[firstIndex]);
|
|
25
|
-
}
|
|
26
|
-
if (_instanceof(value, Object)) {
|
|
27
|
-
return Object.values(value)[0];
|
|
28
|
-
}
|
|
29
|
-
return value;
|
|
30
|
-
}();
|
|
31
|
-
var formatted = function() {
|
|
32
|
-
if (!property) {
|
|
33
|
-
return firstValue;
|
|
34
|
-
}
|
|
35
|
-
if ("type" in property) {
|
|
36
|
-
if (property.type === "boolean") {
|
|
37
|
-
return firstValue ? "true" : false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if ("format" in property && property.format) {
|
|
41
|
-
if ([
|
|
42
|
-
"date",
|
|
43
|
-
"date-time"
|
|
44
|
-
].includes(property.format)) {
|
|
45
|
-
return formatDateTime(String(value), {
|
|
46
|
-
hours: property.format === "date-time"
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if ([
|
|
51
|
-
undefined,
|
|
52
|
-
null
|
|
53
|
-
].includes(firstValue)) {
|
|
54
|
-
return "-";
|
|
55
|
-
}
|
|
56
|
-
return firstValue;
|
|
57
|
-
}();
|
|
58
|
-
return String(formatted);
|
|
47
|
+
return firstValue;
|
|
48
|
+
})();
|
|
49
|
+
return String(formatted);
|
|
59
50
|
};
|
package/dist/freshItem.mjs
CHANGED
|
@@ -1,133 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
function _array_with_holes(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return arr;
|
|
8
|
-
}
|
|
9
|
-
function _define_property(obj, key, value) {
|
|
10
|
-
if (key in obj) {
|
|
11
|
-
Object.defineProperty(obj, key, {
|
|
12
|
-
value: value,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true
|
|
16
|
-
});
|
|
17
|
-
} else {
|
|
18
|
-
obj[key] = value;
|
|
1
|
+
"use strict";
|
|
2
|
+
const freshProperties = (properties) => Object.entries(properties).reduce((a, [key, property]) => {
|
|
3
|
+
const value = (() => {
|
|
4
|
+
if ("$ref" in property) {
|
|
5
|
+
return {};
|
|
19
6
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function _iterable_to_array_limit(arr, i) {
|
|
23
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
24
|
-
if (_i == null) return;
|
|
25
|
-
var _arr = [];
|
|
26
|
-
var _n = true;
|
|
27
|
-
var _d = false;
|
|
28
|
-
var _s, _e;
|
|
29
|
-
try {
|
|
30
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
31
|
-
_arr.push(_s.value);
|
|
32
|
-
if (i && _arr.length === i) break;
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
35
|
-
_d = true;
|
|
36
|
-
_e = err;
|
|
37
|
-
} finally{
|
|
38
|
-
try {
|
|
39
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
-
} finally{
|
|
41
|
-
if (_d) throw _e;
|
|
42
|
-
}
|
|
7
|
+
if ("properties" in property) {
|
|
8
|
+
return freshProperties(property.properties);
|
|
43
9
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
54
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
55
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
ownKeys.forEach(function(key) {
|
|
59
|
-
_define_property(target, key, source[key]);
|
|
60
|
-
});
|
|
10
|
+
if ("type" in property) {
|
|
11
|
+
switch (property.type) {
|
|
12
|
+
case "boolean":
|
|
13
|
+
return false;
|
|
14
|
+
case "array":
|
|
15
|
+
return [];
|
|
16
|
+
case "object":
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
61
19
|
}
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
source = source != null ? source : {};
|
|
79
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
80
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
81
|
-
} else {
|
|
82
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
83
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return target;
|
|
87
|
-
}
|
|
88
|
-
function _sliced_to_array(arr, i) {
|
|
89
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
90
|
-
}
|
|
91
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
92
|
-
if (!o) return;
|
|
93
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
94
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
95
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
96
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
97
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
98
|
-
}
|
|
99
|
-
var freshProperties = function(properties) {
|
|
100
|
-
return Object.entries(properties).reduce(function(a, param) {
|
|
101
|
-
var _param = _sliced_to_array(param, 2), key = _param[0], property = _param[1];
|
|
102
|
-
var value = function() {
|
|
103
|
-
if ("$ref" in property) {
|
|
104
|
-
return {};
|
|
105
|
-
}
|
|
106
|
-
if ("properties" in property) {
|
|
107
|
-
return freshProperties(property.properties);
|
|
108
|
-
}
|
|
109
|
-
if ("type" in property) {
|
|
110
|
-
switch(property.type){
|
|
111
|
-
case "boolean":
|
|
112
|
-
return false;
|
|
113
|
-
case "array":
|
|
114
|
-
return [];
|
|
115
|
-
case "object":
|
|
116
|
-
return {};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}();
|
|
121
|
-
if (value === null) {
|
|
122
|
-
return a;
|
|
123
|
-
}
|
|
124
|
-
return _object_spread_props(_object_spread({}, a), _define_property({}, key, value));
|
|
125
|
-
}, {});
|
|
126
|
-
};
|
|
127
|
-
export var freshItem = function(description) {
|
|
128
|
-
var item = freshProperties(description.properties);
|
|
129
|
-
if (description.freshItem) {
|
|
130
|
-
Object.assign(item, description.freshItem);
|
|
131
|
-
}
|
|
132
|
-
return item;
|
|
20
|
+
return null;
|
|
21
|
+
})();
|
|
22
|
+
if (value === null) {
|
|
23
|
+
return a;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...a,
|
|
27
|
+
[key]: value
|
|
28
|
+
};
|
|
29
|
+
}, {});
|
|
30
|
+
export const freshItem = (description) => {
|
|
31
|
+
const item = freshProperties(description.properties);
|
|
32
|
+
if (description.freshItem) {
|
|
33
|
+
Object.assign(item, description.freshItem);
|
|
34
|
+
}
|
|
35
|
+
return item;
|
|
133
36
|
};
|
|
@@ -1,50 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { checkForUndefined } from "./checkForUndefined.mjs";
|
|
2
3
|
import { evaluateCondition } from "./evaluateCondition.mjs";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
} finally{
|
|
24
|
-
if (_didIteratorError) {
|
|
25
|
-
throw _iteratorError;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
4
|
+
export const getMissingProperties = (what, schema, required) => {
|
|
5
|
+
const missingProps = [];
|
|
6
|
+
if (Array.isArray(required)) {
|
|
7
|
+
for (const propName of required) {
|
|
8
|
+
const isMissing = checkForUndefined(
|
|
9
|
+
schema.properties[propName],
|
|
10
|
+
propName,
|
|
11
|
+
what
|
|
12
|
+
);
|
|
13
|
+
if (isMissing) {
|
|
14
|
+
missingProps.push(propName);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
for (const propName in required) {
|
|
19
|
+
const requiredProp = required[propName];
|
|
20
|
+
if (typeof requiredProp === "boolean") {
|
|
21
|
+
if (!requiredProp) {
|
|
22
|
+
continue;
|
|
28
23
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (typeof requiredProp === "object") {
|
|
38
|
-
var result = evaluateCondition(what, requiredProp);
|
|
39
|
-
if (!result.satisfied) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
var isMissing1 = checkForUndefined(schema.properties[propName1], propName1, what);
|
|
44
|
-
if (isMissing1) {
|
|
45
|
-
missingProps.push(propName1);
|
|
46
|
-
}
|
|
24
|
+
}
|
|
25
|
+
if (typeof requiredProp === "object") {
|
|
26
|
+
const result = evaluateCondition(what, requiredProp);
|
|
27
|
+
if (!result.satisfied) {
|
|
28
|
+
continue;
|
|
47
29
|
}
|
|
30
|
+
}
|
|
31
|
+
const isMissing = checkForUndefined(
|
|
32
|
+
schema.properties[propName],
|
|
33
|
+
propName,
|
|
34
|
+
what
|
|
35
|
+
);
|
|
36
|
+
if (isMissing) {
|
|
37
|
+
missingProps.push(propName);
|
|
38
|
+
}
|
|
48
39
|
}
|
|
49
|
-
|
|
40
|
+
}
|
|
41
|
+
return missingProps;
|
|
50
42
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return reference && "$ref" in reference ? reference : null;
|
|
1
|
+
"use strict";
|
|
2
|
+
export const getReferenceProperty = (property) => {
|
|
3
|
+
const search = [
|
|
4
|
+
"items" in property ? property.items : null,
|
|
5
|
+
"additionalProperties" in property ? property.additionalProperties : null,
|
|
6
|
+
property
|
|
7
|
+
];
|
|
8
|
+
const reference = search.find((_) => !!_);
|
|
9
|
+
return reference && "$ref" in reference ? reference : null;
|
|
11
10
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
export const getValueFromPath = (object, path) => {
|
|
3
|
+
const fragments = path.split(".");
|
|
4
|
+
return fragments.reduce((a, fragment) => {
|
|
5
|
+
return a && a[fragment];
|
|
6
|
+
}, object);
|
|
6
7
|
};
|