@aeriajs/common 0.0.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/LICENSE +19 -0
- package/README.md +13 -0
- package/dist/arraysIntersects.d.ts +1 -0
- package/dist/arraysIntersects.js +12 -0
- package/dist/arraysIntersects.mjs +8 -0
- package/dist/checkForUndefined.d.ts +2 -0
- package/dist/checkForUndefined.js +12 -0
- package/dist/checkForUndefined.mjs +6 -0
- package/dist/convertConditionToQuery.d.ts +2 -0
- package/dist/convertConditionToQuery.js +60 -0
- package/dist/convertConditionToQuery.mjs +72 -0
- package/dist/date.d.ts +7 -0
- package/dist/date.js +42 -0
- package/dist/date.mjs +101 -0
- package/dist/deepClone.d.ts +1 -0
- package/dist/deepClone.js +9 -0
- package/dist/deepClone.mjs +3 -0
- package/dist/deepMerge.d.ts +5 -0
- package/dist/deepMerge.js +39 -0
- package/dist/deepMerge.mjs +66 -0
- package/dist/dynamicImport.d.ts +1 -0
- package/dist/dynamicImport.js +16 -0
- package/dist/dynamicImport.mjs +145 -0
- package/dist/either.d.ts +9 -0
- package/dist/either.js +37 -0
- package/dist/either.mjs +32 -0
- package/dist/evaluateCondition.d.ts +5 -0
- package/dist/evaluateCondition.js +57 -0
- package/dist/evaluateCondition.mjs +63 -0
- package/dist/formatValue.d.ts +2 -0
- package/dist/formatValue.js +55 -0
- package/dist/formatValue.mjs +59 -0
- package/dist/freshItem.d.ts +2 -0
- package/dist/freshItem.js +36 -0
- package/dist/freshItem.mjs +133 -0
- package/dist/getMissingProperties.d.ts +2 -0
- package/dist/getMissingProperties.js +38 -0
- package/dist/getMissingProperties.mjs +50 -0
- package/dist/getReferenceProperty.d.ts +2 -0
- package/dist/getReferenceProperty.js +19 -0
- package/dist/getReferenceProperty.mjs +11 -0
- package/dist/getValueFromPath.d.ts +1 -0
- package/dist/getValueFromPath.js +10 -0
- package/dist/getValueFromPath.mjs +6 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.js +51 -0
- package/dist/http.mjs +224 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +36 -0
- package/dist/index.mjs +20 -0
- package/dist/isReference.d.ts +2 -0
- package/dist/isReference.js +9 -0
- package/dist/isReference.mjs +3 -0
- package/dist/isRequired.d.ts +2 -0
- package/dist/isRequired.js +18 -0
- package/dist/isRequired.mjs +14 -0
- package/dist/pipe.d.ts +4 -0
- package/dist/pipe.js +28 -0
- package/dist/pipe.mjs +259 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.js +74 -0
- package/dist/schema.mjs +72 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/serialize.js +33 -0
- package/dist/serialize.mjs +38 -0
- package/package.json +37 -0
package/dist/either.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Either, Left, Right } from '@aeriajs/types';
|
|
2
|
+
export declare const left: <const T>(value: T) => Left<T>;
|
|
3
|
+
export declare const right: <const T>(value: T) => Right<T>;
|
|
4
|
+
export declare const isLeft: <L>(either: Either<L, any>) => either is Left<L>;
|
|
5
|
+
export declare const isRight: <R>(either: Either<any, R>) => either is Right<R>;
|
|
6
|
+
export declare const unwrapEither: <L, R>(either: Either<L, R>) => L | R;
|
|
7
|
+
export declare const error: <const T>(value: T) => Left<T>;
|
|
8
|
+
export declare const ok: <const T>(value: T) => Right<T>;
|
|
9
|
+
export declare const unsafe: <L, R>(either: Either<L, R>, message?: any) => R;
|
package/dist/either.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unsafe = exports.ok = exports.error = exports.unwrapEither = exports.isRight = exports.isLeft = exports.right = exports.left = void 0;
|
|
4
|
+
const left = (value) => ({
|
|
5
|
+
_tag: 'Left',
|
|
6
|
+
value,
|
|
7
|
+
});
|
|
8
|
+
exports.left = left;
|
|
9
|
+
const right = (value) => ({
|
|
10
|
+
_tag: 'Right',
|
|
11
|
+
value,
|
|
12
|
+
});
|
|
13
|
+
exports.right = right;
|
|
14
|
+
const isLeft = (either) => {
|
|
15
|
+
return either._tag === 'Left';
|
|
16
|
+
};
|
|
17
|
+
exports.isLeft = isLeft;
|
|
18
|
+
const isRight = (either) => {
|
|
19
|
+
return either._tag === 'Right';
|
|
20
|
+
};
|
|
21
|
+
exports.isRight = isRight;
|
|
22
|
+
const unwrapEither = (either) => {
|
|
23
|
+
return either.value;
|
|
24
|
+
};
|
|
25
|
+
exports.unwrapEither = unwrapEither;
|
|
26
|
+
exports.error = exports.left;
|
|
27
|
+
exports.ok = exports.right;
|
|
28
|
+
const unsafe = (either, message) => {
|
|
29
|
+
if (either._tag !== 'Right') {
|
|
30
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
+
console.trace(JSON.stringify(either.value, null, 2));
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`unsafe threw: ${either.value} (${message || '-'})`);
|
|
34
|
+
}
|
|
35
|
+
return either.value;
|
|
36
|
+
};
|
|
37
|
+
exports.unsafe = unsafe;
|
package/dist/either.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export var left = function(value) {
|
|
2
|
+
return {
|
|
3
|
+
_tag: "Left",
|
|
4
|
+
value: value
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export var right = function(value) {
|
|
8
|
+
return {
|
|
9
|
+
_tag: "Right",
|
|
10
|
+
value: value
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export var isLeft = function(either) {
|
|
14
|
+
return either._tag === "Left";
|
|
15
|
+
};
|
|
16
|
+
export var isRight = function(either) {
|
|
17
|
+
return either._tag === "Right";
|
|
18
|
+
};
|
|
19
|
+
export var unwrapEither = function(either) {
|
|
20
|
+
return either.value;
|
|
21
|
+
};
|
|
22
|
+
export var error = left;
|
|
23
|
+
export var ok = right;
|
|
24
|
+
export var unsafe = function(either, message) {
|
|
25
|
+
if (either._tag !== "Right") {
|
|
26
|
+
if (process.env.NODE_ENV !== "production") {
|
|
27
|
+
console.trace(JSON.stringify(either.value, null, 2));
|
|
28
|
+
}
|
|
29
|
+
throw new Error("unsafe threw: ".concat(either.value, " (").concat(message || "-", ")"));
|
|
30
|
+
}
|
|
31
|
+
return either.value;
|
|
32
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateCondition = void 0;
|
|
4
|
+
const arraysIntersects_js_1 = require("./arraysIntersects.js");
|
|
5
|
+
const equalOrContains = (term1, term2) => {
|
|
6
|
+
if (Array.isArray(term1) && Array.isArray(term2)) {
|
|
7
|
+
return (0, arraysIntersects_js_1.arraysIntersects)(term1, term2);
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(term1)) {
|
|
10
|
+
return term1.includes(term2);
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(term2)) {
|
|
13
|
+
return term2.includes(term1);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const evaluatesToTrue = (subject, condition) => {
|
|
17
|
+
if ('term1' in condition) {
|
|
18
|
+
if (!subject) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const term1 = subject[condition.term1];
|
|
22
|
+
if (condition.operator === 'truthy') {
|
|
23
|
+
return !!term1;
|
|
24
|
+
}
|
|
25
|
+
const { operator, term2 } = condition;
|
|
26
|
+
switch (operator) {
|
|
27
|
+
case 'equal': return term1 === term2;
|
|
28
|
+
case 'in': return !!equalOrContains(term1, term2);
|
|
29
|
+
case 'gt': return term1 > term2;
|
|
30
|
+
case 'lt': return term1 < term2;
|
|
31
|
+
case 'gte': return term1 >= term2;
|
|
32
|
+
case 'lte': return term1 <= term2;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if ('and' in condition) {
|
|
36
|
+
return condition.and.every((condition) => evaluatesToTrue(subject, condition));
|
|
37
|
+
}
|
|
38
|
+
if ('or' in condition) {
|
|
39
|
+
return condition.or.some((condition) => evaluatesToTrue(subject, condition));
|
|
40
|
+
}
|
|
41
|
+
if ('not' in condition) {
|
|
42
|
+
return !evaluatesToTrue(subject, condition.not);
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
const evaluateCondition = (subject, condition) => {
|
|
47
|
+
const result = {
|
|
48
|
+
satisfied: false,
|
|
49
|
+
else: null,
|
|
50
|
+
};
|
|
51
|
+
const satisfied = result.satisfied = evaluatesToTrue(subject, condition);
|
|
52
|
+
if (!satisfied && 'else' in condition) {
|
|
53
|
+
result.else = condition.else;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
exports.evaluateCondition = evaluateCondition;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
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
|
+
}
|
|
12
|
+
};
|
|
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;
|
|
52
|
+
};
|
|
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;
|
|
63
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatValue = void 0;
|
|
4
|
+
const date_js_1 = require("./date.js");
|
|
5
|
+
const getReferenceProperty_js_1 = require("./getReferenceProperty.js");
|
|
6
|
+
const formatValue = (value, key, property, index) => {
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
return value.map((v) => (0, exports.formatValue)(v, key, property, index)).join(', ');
|
|
9
|
+
}
|
|
10
|
+
const firstValue = (() => {
|
|
11
|
+
if (!property) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
const refProperty = (0, getReferenceProperty_js_1.getReferenceProperty)(property);
|
|
15
|
+
if (refProperty) {
|
|
16
|
+
const firstIndex = index || refProperty.indexes?.[0];
|
|
17
|
+
return firstIndex && value?.[firstIndex];
|
|
18
|
+
}
|
|
19
|
+
if (value instanceof Object) {
|
|
20
|
+
return Object.values(value)[0];
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
})();
|
|
24
|
+
const formatted = (() => {
|
|
25
|
+
if (!property) {
|
|
26
|
+
return firstValue;
|
|
27
|
+
}
|
|
28
|
+
if ('type' in property) {
|
|
29
|
+
if (property.type === 'boolean') {
|
|
30
|
+
return firstValue
|
|
31
|
+
? 'true'
|
|
32
|
+
: false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if ('format' in property && property.format) {
|
|
36
|
+
if ([
|
|
37
|
+
'date',
|
|
38
|
+
'date-time',
|
|
39
|
+
].includes(property.format)) {
|
|
40
|
+
return (0, date_js_1.formatDateTime)(String(value), {
|
|
41
|
+
hours: property.format === 'date-time',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if ([
|
|
46
|
+
undefined,
|
|
47
|
+
null,
|
|
48
|
+
].includes(firstValue)) {
|
|
49
|
+
return '-';
|
|
50
|
+
}
|
|
51
|
+
return firstValue;
|
|
52
|
+
})();
|
|
53
|
+
return String(formatted);
|
|
54
|
+
};
|
|
55
|
+
exports.formatValue = formatValue;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
|
8
|
+
import { formatDateTime } from "./date.mjs";
|
|
9
|
+
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(", ");
|
|
15
|
+
}
|
|
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);
|
|
59
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.freshItem = void 0;
|
|
4
|
+
const freshProperties = (properties) => Object.entries(properties).reduce((a, [key, property]) => {
|
|
5
|
+
const value = (() => {
|
|
6
|
+
if ('$ref' in property) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
if ('properties' in property) {
|
|
10
|
+
return freshProperties(property.properties);
|
|
11
|
+
}
|
|
12
|
+
if ('type' in property) {
|
|
13
|
+
switch (property.type) {
|
|
14
|
+
case 'boolean': return false;
|
|
15
|
+
case 'array': return [];
|
|
16
|
+
case 'object': return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
})();
|
|
21
|
+
if (value === null) {
|
|
22
|
+
return a;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...a,
|
|
26
|
+
[key]: value,
|
|
27
|
+
};
|
|
28
|
+
}, {});
|
|
29
|
+
const freshItem = (description) => {
|
|
30
|
+
const item = freshProperties(description.properties);
|
|
31
|
+
if (description.freshItem) {
|
|
32
|
+
Object.assign(item, description.freshItem);
|
|
33
|
+
}
|
|
34
|
+
return item;
|
|
35
|
+
};
|
|
36
|
+
exports.freshItem = freshItem;
|
|
@@ -0,0 +1,133 @@
|
|
|
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;
|
|
19
|
+
}
|
|
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
|
+
}
|
|
43
|
+
}
|
|
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
|
+
});
|
|
61
|
+
}
|
|
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;
|
|
133
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMissingProperties = void 0;
|
|
4
|
+
const checkForUndefined_js_1 = require("./checkForUndefined.js");
|
|
5
|
+
const evaluateCondition_js_1 = require("./evaluateCondition.js");
|
|
6
|
+
const getMissingProperties = (what, schema, required) => {
|
|
7
|
+
const missingProps = [];
|
|
8
|
+
if (Array.isArray(required)) {
|
|
9
|
+
for (const propName of required) {
|
|
10
|
+
const isMissing = (0, checkForUndefined_js_1.checkForUndefined)(schema.properties[propName], propName, what);
|
|
11
|
+
if (isMissing) {
|
|
12
|
+
missingProps.push(propName);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
for (const propName in required) {
|
|
18
|
+
const requiredProp = required[propName];
|
|
19
|
+
if (typeof requiredProp === 'boolean') {
|
|
20
|
+
if (!requiredProp) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (typeof requiredProp === 'object') {
|
|
25
|
+
const result = (0, evaluateCondition_js_1.evaluateCondition)(what, requiredProp);
|
|
26
|
+
if (!result.satisfied) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const isMissing = (0, checkForUndefined_js_1.checkForUndefined)(schema.properties[propName], propName, what);
|
|
31
|
+
if (isMissing) {
|
|
32
|
+
missingProps.push(propName);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return missingProps;
|
|
37
|
+
};
|
|
38
|
+
exports.getMissingProperties = getMissingProperties;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { checkForUndefined } from "./checkForUndefined.mjs";
|
|
2
|
+
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
|
+
}
|
|
28
|
+
}
|
|
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
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return missingProps;
|
|
50
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReferenceProperty = void 0;
|
|
4
|
+
const getReferenceProperty = (property) => {
|
|
5
|
+
const search = [
|
|
6
|
+
'items' in property
|
|
7
|
+
? property.items
|
|
8
|
+
: null,
|
|
9
|
+
'additionalProperties' in property
|
|
10
|
+
? property.additionalProperties
|
|
11
|
+
: null,
|
|
12
|
+
property,
|
|
13
|
+
];
|
|
14
|
+
const reference = search.find((_) => !!_);
|
|
15
|
+
return reference && '$ref' in reference
|
|
16
|
+
? reference
|
|
17
|
+
: null;
|
|
18
|
+
};
|
|
19
|
+
exports.getReferenceProperty = getReferenceProperty;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getValueFromPath: (object: any, path: string) => any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValueFromPath = void 0;
|
|
4
|
+
const getValueFromPath = (object, path) => {
|
|
5
|
+
const fragments = path.split('.');
|
|
6
|
+
return fragments.reduce((a, fragment) => {
|
|
7
|
+
return a && a[fragment];
|
|
8
|
+
}, object);
|
|
9
|
+
};
|
|
10
|
+
exports.getValueFromPath = getValueFromPath;
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequestMethod } from '@aeriajs/types';
|
|
2
|
+
export type RequestParams = Omit<RequestInit, 'headers'> & {
|
|
3
|
+
method: RequestMethod;
|
|
4
|
+
headers?: Partial<Record<string, string>>;
|
|
5
|
+
};
|
|
6
|
+
export type RequestConfig<Return = any> = {
|
|
7
|
+
params?: RequestParams;
|
|
8
|
+
requestTransformer?: (...args: Parameters<typeof defaultRequestTransformer>) => Promise<Return>;
|
|
9
|
+
responseTransformer?: typeof defaultResponseTransformer;
|
|
10
|
+
};
|
|
11
|
+
export declare const defaultRequestTransformer: (url: string, payload: any, params: RequestParams) => Promise<{
|
|
12
|
+
url: string;
|
|
13
|
+
params: RequestParams;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const defaultResponseTransformer: (response: Awaited<ReturnType<typeof fetch>>) => Promise<Response & {
|
|
16
|
+
data: any;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const request: <Return = any>(url: string, payload?: any, config?: RequestConfig<Return> | undefined) => Promise<Response & {
|
|
19
|
+
data: any;
|
|
20
|
+
}>;
|