@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.
@@ -1,63 +1,60 @@
1
+ "use strict";
1
2
  import { arraysIntersects } from "./arraysIntersects.mjs";
2
- var equalOrContains = function(term1, term2) {
3
- if (Array.isArray(term1) && Array.isArray(term2)) {
4
- return arraysIntersects(term1, term2);
5
- }
6
- if (Array.isArray(term1)) {
7
- return term1.includes(term2);
8
- }
9
- if (Array.isArray(term2)) {
10
- return term2.includes(term1);
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
- var evaluatesToTrue = function(subject, condition) {
14
- if ("term1" in condition) {
15
- if (!subject) {
16
- return false;
17
- }
18
- var term1 = subject[condition.term1];
19
- if (condition.operator === "truthy") {
20
- return !!term1;
21
- }
22
- var operator = condition.operator, term2 = condition.term2;
23
- switch(operator){
24
- case "equal":
25
- return term1 === term2;
26
- case "in":
27
- return !!equalOrContains(term1, term2);
28
- case "gt":
29
- return term1 > term2;
30
- case "lt":
31
- return term1 < term2;
32
- case "gte":
33
- return term1 >= term2;
34
- case "lte":
35
- return term1 <= term2;
36
- }
37
- }
38
- if ("and" in condition) {
39
- return condition.and.every(function(condition) {
40
- return evaluatesToTrue(subject, condition);
41
- });
42
- }
43
- if ("or" in condition) {
44
- return condition.or.some(function(condition) {
45
- return evaluatesToTrue(subject, condition);
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 var evaluateCondition = function(subject, condition) {
54
- var result = {
55
- satisfied: false,
56
- else: null
57
- };
58
- var satisfied = result.satisfied = evaluatesToTrue(subject, condition);
59
- if (!satisfied && "else" in condition) {
60
- result.else = condition.else;
61
- }
62
- return result;
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
  };
@@ -1,59 +1,50 @@
1
- function _instanceof(left, right) {
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 var formatValue = function(value, key, property, index) {
11
- if (Array.isArray(value)) {
12
- return value.map(function(v) {
13
- return formatValue(v, key, property, index);
14
- }).join(", ");
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
- var firstValue = function() {
17
- if (!property) {
18
- return value;
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
  };
@@ -1,133 +1,36 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
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
- return obj;
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
- return _arr;
45
- }
46
- function _non_iterable_rest() {
47
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
48
- }
49
- function _object_spread(target) {
50
- for(var i = 1; i < arguments.length; i++){
51
- var source = arguments[i] != null ? arguments[i] : {};
52
- var ownKeys = Object.keys(source);
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 target;
63
- }
64
- function ownKeys(object, enumerableOnly) {
65
- var keys = Object.keys(object);
66
- if (Object.getOwnPropertySymbols) {
67
- var symbols = Object.getOwnPropertySymbols(object);
68
- if (enumerableOnly) {
69
- symbols = symbols.filter(function(sym) {
70
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
71
- });
72
- }
73
- keys.push.apply(keys, symbols);
74
- }
75
- return keys;
76
- }
77
- function _object_spread_props(target, source) {
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 var getMissingProperties = function(what, schema, required) {
4
- var missingProps = [];
5
- if (Array.isArray(required)) {
6
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
7
- try {
8
- for(var _iterator = required[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
9
- var propName = _step.value;
10
- var isMissing = checkForUndefined(schema.properties[propName], propName, what);
11
- if (isMissing) {
12
- missingProps.push(propName);
13
- }
14
- }
15
- } catch (err) {
16
- _didIteratorError = true;
17
- _iteratorError = err;
18
- } finally{
19
- try {
20
- if (!_iteratorNormalCompletion && _iterator.return != null) {
21
- _iterator.return();
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
- } else {
30
- for(var propName1 in required){
31
- var requiredProp = required[propName1];
32
- if (typeof requiredProp === "boolean") {
33
- if (!requiredProp) {
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
- return missingProps;
40
+ }
41
+ return missingProps;
50
42
  };
@@ -1,11 +1,10 @@
1
- export var getReferenceProperty = function(property) {
2
- var search = [
3
- "items" in property ? property.items : null,
4
- "additionalProperties" in property ? property.additionalProperties : null,
5
- property
6
- ];
7
- var reference = search.find(function(_) {
8
- return !!_;
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
- export var getValueFromPath = function(object, path) {
2
- var fragments = path.split(".");
3
- return fragments.reduce(function(a, fragment) {
4
- return a && a[fragment];
5
- }, object);
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
  };