@aeriajs/common 0.0.157 → 0.0.158
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/arraysIntersect.js +1 -5
- package/dist/checkForEmptiness.js +1 -5
- package/dist/convertConditionToQuery.js +6 -10
- package/dist/deepClone.js +1 -5
- package/dist/deepMerge.js +2 -6
- package/dist/endpointError.js +8 -13
- package/dist/evaluateCondition.js +3 -7
- package/dist/freshItem.js +4 -9
- package/dist/getMissingProperties.js +6 -10
- package/dist/getReferenceProperty.js +1 -5
- package/dist/getValueFromPath.js +1 -5
- package/dist/http.js +7 -13
- package/dist/index.d.ts +0 -1
- package/dist/index.js +19 -36
- package/dist/isGranted.js +3 -7
- package/dist/isReference.js +1 -5
- package/dist/isRequired.js +3 -7
- package/dist/isValidCollection.js +3 -8
- package/dist/pipe.js +1 -5
- package/dist/result.js +6 -13
- package/dist/serialize.js +3 -8
- package/package.json +6 -11
- package/dist/arraysIntersect.mjs +0 -7
- package/dist/checkForEmptiness.mjs +0 -7
- package/dist/convertConditionToQuery.mjs +0 -69
- package/dist/deepClone.mjs +0 -4
- package/dist/deepMerge.mjs +0 -34
- package/dist/dynamicImport.d.ts +0 -1
- package/dist/dynamicImport.js +0 -16
- package/dist/dynamicImport.mjs +0 -12
- package/dist/endpointError.mjs +0 -11
- package/dist/evaluateCondition.mjs +0 -72
- package/dist/freshItem.mjs +0 -40
- package/dist/getMissingProperties.mjs +0 -38
- package/dist/getReferenceProperty.mjs +0 -10
- package/dist/getValueFromPath.mjs +0 -7
- package/dist/http.mjs +0 -63
- package/dist/index.mjs +0 -21
- package/dist/isGranted.mjs +0 -18
- package/dist/isReference.mjs +0 -4
- package/dist/isRequired.mjs +0 -15
- package/dist/isValidCollection.mjs +0 -7
- package/dist/pipe.mjs +0 -25
- package/dist/result.mjs +0 -19
- package/dist/serialize.mjs +0 -6
package/dist/arraysIntersect.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arraysIntersect = void 0;
|
|
4
|
-
const arraysIntersect = (subject, arr) => {
|
|
1
|
+
export const arraysIntersect = (subject, arr) => {
|
|
5
2
|
if (!arr) {
|
|
6
3
|
return false;
|
|
7
4
|
}
|
|
@@ -9,4 +6,3 @@ const arraysIntersect = (subject, arr) => {
|
|
|
9
6
|
? subject.some((e) => arr.includes(e))
|
|
10
7
|
: arr.includes(subject);
|
|
11
8
|
};
|
|
12
|
-
exports.arraysIntersect = arraysIntersect;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkForEmptiness = void 0;
|
|
4
|
-
const checkForEmptiness = (property, propName, what) => {
|
|
1
|
+
export const checkForEmptiness = (property, propName, what) => {
|
|
5
2
|
if (property.readOnly || property.isTimestamp) {
|
|
6
3
|
return false;
|
|
7
4
|
}
|
|
@@ -9,4 +6,3 @@ const checkForEmptiness = (property, propName, what) => {
|
|
|
9
6
|
|| what[propName] === undefined
|
|
10
7
|
|| what[propName] === '';
|
|
11
8
|
};
|
|
12
|
-
exports.checkForEmptiness = checkForEmptiness;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertConditionToQuery = void 0;
|
|
4
|
-
const getValueFromPath_js_1 = require("./getValueFromPath.js");
|
|
1
|
+
import { getValueFromPath } from './getValueFromPath.js';
|
|
5
2
|
const convertExpression = (condition, subject) => {
|
|
6
3
|
let term2 = null;
|
|
7
4
|
if ('term2' in condition) {
|
|
8
5
|
if (condition.fromState) {
|
|
9
6
|
term2 = subject && typeof condition.term2 === 'string'
|
|
10
|
-
?
|
|
7
|
+
? getValueFromPath(subject, condition.term2)
|
|
11
8
|
: null;
|
|
12
9
|
}
|
|
13
10
|
else {
|
|
@@ -47,24 +44,23 @@ const convertExpression = (condition, subject) => {
|
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
};
|
|
50
|
-
const convertConditionToQuery = (condition, subject) => {
|
|
47
|
+
export const convertConditionToQuery = (condition, subject) => {
|
|
51
48
|
if ('or' in condition) {
|
|
52
49
|
return {
|
|
53
|
-
$or: condition.or.map((sub) =>
|
|
50
|
+
$or: condition.or.map((sub) => convertConditionToQuery(sub, subject)),
|
|
54
51
|
};
|
|
55
52
|
}
|
|
56
53
|
if ('and' in condition) {
|
|
57
54
|
return {
|
|
58
|
-
$and: condition.and.map((sub) =>
|
|
55
|
+
$and: condition.and.map((sub) => convertConditionToQuery(sub, subject)),
|
|
59
56
|
};
|
|
60
57
|
}
|
|
61
58
|
if ('not' in condition) {
|
|
62
59
|
return {
|
|
63
|
-
$not:
|
|
60
|
+
$not: convertConditionToQuery(condition.not, subject),
|
|
64
61
|
};
|
|
65
62
|
}
|
|
66
63
|
return {
|
|
67
64
|
[condition.term1]: convertExpression(condition, subject),
|
|
68
65
|
};
|
|
69
66
|
};
|
|
70
|
-
exports.convertConditionToQuery = convertConditionToQuery;
|
package/dist/deepClone.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepClone = void 0;
|
|
4
|
-
const deepClone = (obj) => {
|
|
1
|
+
export const deepClone = (obj) => {
|
|
5
2
|
return typeof structuredClone === 'function' && typeof window === 'undefined'
|
|
6
3
|
? structuredClone(obj)
|
|
7
4
|
: JSON.parse(JSON.stringify(obj));
|
|
8
5
|
};
|
|
9
|
-
exports.deepClone = deepClone;
|
package/dist/deepMerge.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepMerge = void 0;
|
|
4
|
-
const deepMerge = (left, right, options) => {
|
|
1
|
+
export const deepMerge = (left, right, options) => {
|
|
5
2
|
const result = Object.assign({}, left);
|
|
6
3
|
const { arrays = true } = options || {};
|
|
7
4
|
for (const key in right) {
|
|
@@ -29,11 +26,10 @@ const deepMerge = (left, right, options) => {
|
|
|
29
26
|
result[key] = rightVal;
|
|
30
27
|
continue;
|
|
31
28
|
}
|
|
32
|
-
result[key] =
|
|
29
|
+
result[key] = deepMerge(leftVal, rightVal, options);
|
|
33
30
|
continue;
|
|
34
31
|
}
|
|
35
32
|
result[key] = rightVal;
|
|
36
33
|
}
|
|
37
34
|
return result;
|
|
38
35
|
};
|
|
39
|
-
exports.deepMerge = deepMerge;
|
package/dist/endpointError.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const endpointError = (value) => {
|
|
7
|
-
return types_1.Result.error(Object.assign({
|
|
8
|
-
[types_1.ERROR_SYMBOL]: true,
|
|
1
|
+
import { Result, ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from '@aeriajs/types';
|
|
2
|
+
import { isError } from './result.js';
|
|
3
|
+
export const endpointError = (value) => {
|
|
4
|
+
return Result.error(Object.assign({
|
|
5
|
+
[ERROR_SYMBOL]: true,
|
|
9
6
|
}, value));
|
|
10
7
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return !!((0, result_js_1.isError)(object)
|
|
8
|
+
export const isEndpointError = (object) => {
|
|
9
|
+
return !!(isError(object)
|
|
14
10
|
&& object.error
|
|
15
11
|
&& typeof object.error === 'object'
|
|
16
|
-
&& (
|
|
12
|
+
&& (ERROR_SYMBOL in object.error || ERROR_SYMBOL_DESCRIPTION in object.error));
|
|
17
13
|
};
|
|
18
|
-
exports.isEndpointError = isEndpointError;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateCondition = void 0;
|
|
4
|
-
const arraysIntersect_js_1 = require("./arraysIntersect.js");
|
|
1
|
+
import { arraysIntersect } from './arraysIntersect.js';
|
|
5
2
|
const isCondition = (subject) => {
|
|
6
3
|
if (!subject || typeof subject !== 'object') {
|
|
7
4
|
return false;
|
|
@@ -13,7 +10,7 @@ const isCondition = (subject) => {
|
|
|
13
10
|
};
|
|
14
11
|
const equalOrContains = (term1, term2) => {
|
|
15
12
|
if (Array.isArray(term1) && Array.isArray(term2)) {
|
|
16
|
-
return
|
|
13
|
+
return arraysIntersect(term1, term2);
|
|
17
14
|
}
|
|
18
15
|
if (Array.isArray(term1)) {
|
|
19
16
|
return term1.includes(term2);
|
|
@@ -57,7 +54,7 @@ const evaluateExpression = (subject, expression) => {
|
|
|
57
54
|
}
|
|
58
55
|
return false;
|
|
59
56
|
};
|
|
60
|
-
const evaluateCondition = (subject, condition) => {
|
|
57
|
+
export const evaluateCondition = (subject, condition) => {
|
|
61
58
|
const result = {
|
|
62
59
|
satisfied: false,
|
|
63
60
|
else: null,
|
|
@@ -68,4 +65,3 @@ const evaluateCondition = (subject, condition) => {
|
|
|
68
65
|
}
|
|
69
66
|
return result;
|
|
70
67
|
};
|
|
71
|
-
exports.evaluateCondition = evaluateCondition;
|
package/dist/freshItem.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.freshItem = exports.freshProperty = void 0;
|
|
4
|
-
const freshProperty = (property) => {
|
|
1
|
+
export const freshProperty = (property) => {
|
|
5
2
|
const value = (() => {
|
|
6
3
|
if ('$ref' in property && property.inline) {
|
|
7
4
|
return {};
|
|
@@ -9,7 +6,7 @@ const freshProperty = (property) => {
|
|
|
9
6
|
if ('properties' in property) {
|
|
10
7
|
const obj = {};
|
|
11
8
|
for (const propName in property.properties) {
|
|
12
|
-
obj[propName] =
|
|
9
|
+
obj[propName] = freshProperty(property.properties[propName]);
|
|
13
10
|
}
|
|
14
11
|
return obj;
|
|
15
12
|
}
|
|
@@ -24,11 +21,10 @@ const freshProperty = (property) => {
|
|
|
24
21
|
})();
|
|
25
22
|
return value;
|
|
26
23
|
};
|
|
27
|
-
|
|
28
|
-
const freshItem = (description) => {
|
|
24
|
+
export const freshItem = (description) => {
|
|
29
25
|
const item = {};
|
|
30
26
|
for (const propName in description.properties) {
|
|
31
|
-
const value =
|
|
27
|
+
const value = freshProperty(description.properties[propName]);
|
|
32
28
|
if (value !== null) {
|
|
33
29
|
item[propName] = value;
|
|
34
30
|
}
|
|
@@ -38,4 +34,3 @@ const freshItem = (description) => {
|
|
|
38
34
|
}
|
|
39
35
|
return item;
|
|
40
36
|
};
|
|
41
|
-
exports.freshItem = freshItem;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const checkForEmptiness_js_1 = require("./checkForEmptiness.js");
|
|
5
|
-
const evaluateCondition_js_1 = require("./evaluateCondition.js");
|
|
6
|
-
const getMissingProperties = (what, schema, required) => {
|
|
1
|
+
import { checkForEmptiness } from './checkForEmptiness.js';
|
|
2
|
+
import { evaluateCondition } from './evaluateCondition.js';
|
|
3
|
+
export const getMissingProperties = (what, schema, required) => {
|
|
7
4
|
const missingProps = [];
|
|
8
5
|
if (Array.isArray(required)) {
|
|
9
6
|
for (const propName of required) {
|
|
10
|
-
const isMissing =
|
|
7
|
+
const isMissing = checkForEmptiness(schema.properties[propName], propName, what);
|
|
11
8
|
if (isMissing) {
|
|
12
9
|
missingProps.push(propName);
|
|
13
10
|
}
|
|
@@ -22,12 +19,12 @@ const getMissingProperties = (what, schema, required) => {
|
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
if (typeof requiredProp === 'object') {
|
|
25
|
-
const result =
|
|
22
|
+
const result = evaluateCondition(what, requiredProp);
|
|
26
23
|
if (!result.satisfied) {
|
|
27
24
|
continue;
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
const isMissing =
|
|
27
|
+
const isMissing = checkForEmptiness(schema.properties[propName], propName, what);
|
|
31
28
|
if (isMissing) {
|
|
32
29
|
missingProps.push(propName);
|
|
33
30
|
}
|
|
@@ -35,4 +32,3 @@ const getMissingProperties = (what, schema, required) => {
|
|
|
35
32
|
}
|
|
36
33
|
return missingProps;
|
|
37
34
|
};
|
|
38
|
-
exports.getMissingProperties = getMissingProperties;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReferenceProperty = void 0;
|
|
4
|
-
const getReferenceProperty = (property) => {
|
|
1
|
+
export const getReferenceProperty = (property) => {
|
|
5
2
|
const search = [
|
|
6
3
|
'items' in property
|
|
7
4
|
? property.items
|
|
@@ -16,4 +13,3 @@ const getReferenceProperty = (property) => {
|
|
|
16
13
|
? reference
|
|
17
14
|
: null;
|
|
18
15
|
};
|
|
19
|
-
exports.getReferenceProperty = getReferenceProperty;
|
package/dist/getValueFromPath.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValueFromPath = void 0;
|
|
4
|
-
const getValueFromPath = (object, path) => {
|
|
1
|
+
export const getValueFromPath = (object, path) => {
|
|
5
2
|
const fragments = path.split('.');
|
|
6
3
|
return fragments.reduce((a, fragment) => {
|
|
7
4
|
return a && a[fragment];
|
|
8
5
|
}, object);
|
|
9
6
|
};
|
|
10
|
-
exports.getValueFromPath = getValueFromPath;
|
package/dist/http.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.request = exports.defaultResponseTransformer = exports.defaultRequestTransformer = void 0;
|
|
4
|
-
const defaultRequestTransformer = async (context) => {
|
|
1
|
+
export const defaultRequestTransformer = async (context) => {
|
|
5
2
|
if (context.payload) {
|
|
6
3
|
if (context.params.method === 'GET' || context.params.method === 'HEAD') {
|
|
7
4
|
context.url += `?${new URLSearchParams(context.payload)}`;
|
|
@@ -14,8 +11,7 @@ const defaultRequestTransformer = async (context) => {
|
|
|
14
11
|
}
|
|
15
12
|
return context;
|
|
16
13
|
};
|
|
17
|
-
|
|
18
|
-
const defaultResponseTransformer = async (context) => {
|
|
14
|
+
export const defaultResponseTransformer = async (context) => {
|
|
19
15
|
const result = context.response;
|
|
20
16
|
result.data = await context.response.text();
|
|
21
17
|
if (context.response.headers.get('content-type')?.startsWith('application/json')) {
|
|
@@ -24,8 +20,7 @@ const defaultResponseTransformer = async (context) => {
|
|
|
24
20
|
context.response = result;
|
|
25
21
|
return context;
|
|
26
22
|
};
|
|
27
|
-
|
|
28
|
-
const request = async (url, payload, config = {}) => {
|
|
23
|
+
export const request = async (url, payload, config = {}) => {
|
|
29
24
|
const { requestTransformer, responseTransformer, } = config;
|
|
30
25
|
let params;
|
|
31
26
|
if (config.params) {
|
|
@@ -52,21 +47,20 @@ const request = async (url, payload, config = {}) => {
|
|
|
52
47
|
params,
|
|
53
48
|
};
|
|
54
49
|
if (requestTransformer) {
|
|
55
|
-
transformedRequest = await requestTransformer(transformedRequest,
|
|
50
|
+
transformedRequest = await requestTransformer(transformedRequest, defaultRequestTransformer);
|
|
56
51
|
}
|
|
57
52
|
else {
|
|
58
|
-
transformedRequest = await
|
|
53
|
+
transformedRequest = await defaultRequestTransformer(transformedRequest);
|
|
59
54
|
}
|
|
60
55
|
const response = await fetch(transformedRequest.url, transformedRequest.params);
|
|
61
56
|
let transformedResponse = {
|
|
62
57
|
response,
|
|
63
58
|
};
|
|
64
59
|
if (responseTransformer) {
|
|
65
|
-
transformedResponse = await responseTransformer(transformedResponse,
|
|
60
|
+
transformedResponse = await responseTransformer(transformedResponse, defaultResponseTransformer);
|
|
66
61
|
}
|
|
67
62
|
else {
|
|
68
|
-
transformedResponse = await
|
|
63
|
+
transformedResponse = await defaultResponseTransformer(transformedResponse);
|
|
69
64
|
}
|
|
70
65
|
return transformedResponse.response;
|
|
71
66
|
};
|
|
72
|
-
exports.request = request;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './arraysIntersect.js';
|
|
|
2
2
|
export * from './checkForEmptiness.js';
|
|
3
3
|
export * from './deepClone.js';
|
|
4
4
|
export * from './deepMerge.js';
|
|
5
|
-
export * from './dynamicImport.js';
|
|
6
5
|
export * from './result.js';
|
|
7
6
|
export * from './endpointError.js';
|
|
8
7
|
export * from './evaluateCondition.js';
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
__exportStar(require("./deepMerge.js"), exports);
|
|
21
|
-
__exportStar(require("./dynamicImport.js"), exports);
|
|
22
|
-
__exportStar(require("./result.js"), exports);
|
|
23
|
-
__exportStar(require("./endpointError.js"), exports);
|
|
24
|
-
__exportStar(require("./evaluateCondition.js"), exports);
|
|
25
|
-
__exportStar(require("./freshItem.js"), exports);
|
|
26
|
-
__exportStar(require("./getMissingProperties.js"), exports);
|
|
27
|
-
__exportStar(require("./getReferenceProperty.js"), exports);
|
|
28
|
-
__exportStar(require("./getValueFromPath.js"), exports);
|
|
29
|
-
__exportStar(require("./http.js"), exports);
|
|
30
|
-
__exportStar(require("./isGranted.js"), exports);
|
|
31
|
-
__exportStar(require("./isReference.js"), exports);
|
|
32
|
-
__exportStar(require("./isRequired.js"), exports);
|
|
33
|
-
__exportStar(require("./isValidCollection.js"), exports);
|
|
34
|
-
__exportStar(require("./convertConditionToQuery.js"), exports);
|
|
35
|
-
__exportStar(require("./pipe.js"), exports);
|
|
36
|
-
__exportStar(require("./serialize.js"), exports);
|
|
1
|
+
export * from './arraysIntersect.js';
|
|
2
|
+
export * from './checkForEmptiness.js';
|
|
3
|
+
export * from './deepClone.js';
|
|
4
|
+
export * from './deepMerge.js';
|
|
5
|
+
export * from './result.js';
|
|
6
|
+
export * from './endpointError.js';
|
|
7
|
+
export * from './evaluateCondition.js';
|
|
8
|
+
export * from './freshItem.js';
|
|
9
|
+
export * from './getMissingProperties.js';
|
|
10
|
+
export * from './getReferenceProperty.js';
|
|
11
|
+
export * from './getValueFromPath.js';
|
|
12
|
+
export * from './http.js';
|
|
13
|
+
export * from './isGranted.js';
|
|
14
|
+
export * from './isReference.js';
|
|
15
|
+
export * from './isRequired.js';
|
|
16
|
+
export * from './isValidCollection.js';
|
|
17
|
+
export * from './convertConditionToQuery.js';
|
|
18
|
+
export * from './pipe.js';
|
|
19
|
+
export * from './serialize.js';
|
package/dist/isGranted.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isGranted = void 0;
|
|
4
|
-
const arraysIntersect_js_1 = require("./arraysIntersect.js");
|
|
5
|
-
const isGranted = (condition, token) => {
|
|
1
|
+
import { arraysIntersect } from './arraysIntersect.js';
|
|
2
|
+
export const isGranted = (condition, token) => {
|
|
6
3
|
if (Array.isArray(condition)) {
|
|
7
4
|
return token.authenticated
|
|
8
|
-
?
|
|
5
|
+
? arraysIntersect(token.roles, condition)
|
|
9
6
|
: condition.includes('unauthenticated');
|
|
10
7
|
}
|
|
11
8
|
switch (condition) {
|
|
@@ -19,4 +16,3 @@ const isGranted = (condition, token) => {
|
|
|
19
16
|
return !token.authenticated;
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
|
-
exports.isGranted = isGranted;
|
package/dist/isReference.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isReference = void 0;
|
|
4
|
-
const isReference = (property) => {
|
|
1
|
+
export const isReference = (property) => {
|
|
5
2
|
return 'items' in property
|
|
6
3
|
? '$ref' in property.items
|
|
7
4
|
: '$ref' in property;
|
|
8
5
|
};
|
|
9
|
-
exports.isReference = isReference;
|
package/dist/isRequired.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isRequired = void 0;
|
|
4
|
-
const evaluateCondition_js_1 = require("./evaluateCondition.js");
|
|
5
|
-
const isRequired = (propName, required, subject) => {
|
|
1
|
+
import { evaluateCondition } from './evaluateCondition.js';
|
|
2
|
+
export const isRequired = (propName, required, subject) => {
|
|
6
3
|
if (Array.isArray(required)) {
|
|
7
4
|
return required.includes(propName);
|
|
8
5
|
}
|
|
@@ -13,6 +10,5 @@ const isRequired = (propName, required, subject) => {
|
|
|
13
10
|
if (typeof requiredProp !== 'object') {
|
|
14
11
|
return requiredProp;
|
|
15
12
|
}
|
|
16
|
-
return
|
|
13
|
+
return evaluateCondition(subject, requiredProp).satisfied;
|
|
17
14
|
};
|
|
18
|
-
exports.isRequired = isRequired;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidCollection = exports.isValidDescription = void 0;
|
|
4
|
-
const isValidDescription = (value) => {
|
|
1
|
+
export const isValidDescription = (value) => {
|
|
5
2
|
return !!(value
|
|
6
3
|
&& typeof value === 'object'
|
|
7
4
|
&& '$id' in value
|
|
@@ -10,11 +7,9 @@ const isValidDescription = (value) => {
|
|
|
10
7
|
&& typeof value.$id === 'string'
|
|
11
8
|
&& typeof value.properties === 'object');
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const isValidCollection = (value) => {
|
|
10
|
+
export const isValidCollection = (value) => {
|
|
15
11
|
return !!(value
|
|
16
12
|
&& typeof value === 'object'
|
|
17
13
|
&& 'description' in value
|
|
18
|
-
&&
|
|
14
|
+
&& isValidDescription(value.description));
|
|
19
15
|
};
|
|
20
|
-
exports.isValidCollection = isValidCollection;
|
package/dist/pipe.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pipe = void 0;
|
|
4
|
-
const pipe = (functions, options) => {
|
|
1
|
+
export const pipe = (functions, options) => {
|
|
5
2
|
const { returnFirst } = options || {};
|
|
6
3
|
return async (value, ...args) => {
|
|
7
4
|
let ret = value;
|
|
@@ -25,4 +22,3 @@ const pipe = (functions, options) => {
|
|
|
25
22
|
return ret;
|
|
26
23
|
};
|
|
27
24
|
};
|
|
28
|
-
exports.pipe = pipe;
|
package/dist/result.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfError = exports.isError = exports.isResult = exports.isEither = void 0;
|
|
4
|
-
const isEither = (value) => {
|
|
1
|
+
export const isEither = (value) => {
|
|
5
2
|
return !!(value
|
|
6
3
|
&& typeof value === 'object'
|
|
7
4
|
&& '_tag' in value
|
|
8
5
|
&& (value._tag === 'Error' || value._tag === 'Result'));
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return !!((0, exports.isEither)(value) && value.result);
|
|
7
|
+
export const isResult = (value) => {
|
|
8
|
+
return !!(isEither(value) && value.result);
|
|
13
9
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return !!((0, exports.isEither)(value) && value.error);
|
|
10
|
+
export const isError = (value) => {
|
|
11
|
+
return !!(isEither(value) && value.error);
|
|
17
12
|
};
|
|
18
|
-
|
|
19
|
-
const throwIfError = (either, message) => {
|
|
13
|
+
export const throwIfError = (either, message) => {
|
|
20
14
|
if (either.error) {
|
|
21
15
|
if (process.env.NODE_ENV !== 'production') {
|
|
22
16
|
console.trace(JSON.stringify(either.error, null, 2));
|
|
@@ -27,4 +21,3 @@ const throwIfError = (either, message) => {
|
|
|
27
21
|
}
|
|
28
22
|
return either.result;
|
|
29
23
|
};
|
|
30
|
-
exports.throwIfError = throwIfError;
|
package/dist/serialize.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const BSON = require("bson");
|
|
5
|
-
const serialize = (...args) => Buffer.from(BSON.serialize(...args)).toString('latin1');
|
|
6
|
-
exports.serialize = serialize;
|
|
7
|
-
const deserialize = (buffer) => {
|
|
1
|
+
import * as BSON from 'bson';
|
|
2
|
+
export const serialize = (...args) => Buffer.from(BSON.serialize(...args)).toString('latin1');
|
|
3
|
+
export const deserialize = (buffer) => {
|
|
8
4
|
return BSON.deserialize(new Uint8Array(Array.from(buffer).map((c) => c.charCodeAt(0))));
|
|
9
5
|
};
|
|
10
|
-
exports.deserialize = deserialize;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.158",
|
|
4
5
|
"description": "",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -17,13 +17,11 @@
|
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
|
-
"
|
|
21
|
-
"require": "./dist/index.js"
|
|
20
|
+
"default": "./dist/index.js"
|
|
22
21
|
},
|
|
23
22
|
"./either": {
|
|
24
23
|
"types": "./dist/either.d.ts",
|
|
25
|
-
"
|
|
26
|
-
"require": "./dist/either.js"
|
|
24
|
+
"default": "./dist/either.js"
|
|
27
25
|
}
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
@@ -31,7 +29,7 @@
|
|
|
31
29
|
"bson": "^6.10.4"
|
|
32
30
|
},
|
|
33
31
|
"peerDependencies": {
|
|
34
|
-
"@aeriajs/types": "^0.0.
|
|
32
|
+
"@aeriajs/types": "^0.0.136",
|
|
35
33
|
"bson": "^6.10.4"
|
|
36
34
|
},
|
|
37
35
|
"scripts": {
|
|
@@ -39,9 +37,6 @@
|
|
|
39
37
|
"test:typecheck": "tsc -p tsconfig.test.json",
|
|
40
38
|
"lint": "eslint .",
|
|
41
39
|
"lint:fix": "eslint . --fix",
|
|
42
|
-
"build": "
|
|
43
|
-
"build:cjs": "tsc",
|
|
44
|
-
"build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
|
|
45
|
-
"build:esm-transform": "pnpm -w esm-transform $PWD/dist"
|
|
40
|
+
"build": "tsc"
|
|
46
41
|
}
|
|
47
42
|
}
|
package/dist/arraysIntersect.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { getValueFromPath } from "./getValueFromPath.mjs";
|
|
3
|
-
const convertExpression = (condition, subject) => {
|
|
4
|
-
let term2 = null;
|
|
5
|
-
if ("term2" in condition) {
|
|
6
|
-
if (condition.fromState) {
|
|
7
|
-
term2 = subject && typeof condition.term2 === "string" ? getValueFromPath(subject, condition.term2) : null;
|
|
8
|
-
} else {
|
|
9
|
-
term2 = condition.term2;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
switch (condition.operator) {
|
|
13
|
-
case "truthy":
|
|
14
|
-
return {
|
|
15
|
-
$ne: [
|
|
16
|
-
null,
|
|
17
|
-
void 0
|
|
18
|
-
]
|
|
19
|
-
};
|
|
20
|
-
case "equal":
|
|
21
|
-
return term2;
|
|
22
|
-
case "gt":
|
|
23
|
-
return {
|
|
24
|
-
$gt: term2
|
|
25
|
-
};
|
|
26
|
-
case "lt":
|
|
27
|
-
return {
|
|
28
|
-
$lt: term2
|
|
29
|
-
};
|
|
30
|
-
case "gte":
|
|
31
|
-
return {
|
|
32
|
-
$gte: term2
|
|
33
|
-
};
|
|
34
|
-
case "lte":
|
|
35
|
-
return {
|
|
36
|
-
$lte: term2
|
|
37
|
-
};
|
|
38
|
-
case "regex":
|
|
39
|
-
return {
|
|
40
|
-
$regex: term2,
|
|
41
|
-
$options: condition.regexOptions
|
|
42
|
-
};
|
|
43
|
-
case "in": {
|
|
44
|
-
return Array.isArray(term2) ? {
|
|
45
|
-
$in: term2
|
|
46
|
-
} : term2;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
export const convertConditionToQuery = (condition, subject) => {
|
|
51
|
-
if ("or" in condition) {
|
|
52
|
-
return {
|
|
53
|
-
$or: condition.or.map((sub) => convertConditionToQuery(sub, subject))
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if ("and" in condition) {
|
|
57
|
-
return {
|
|
58
|
-
$and: condition.and.map((sub) => convertConditionToQuery(sub, subject))
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if ("not" in condition) {
|
|
62
|
-
return {
|
|
63
|
-
$not: convertConditionToQuery(condition.not, subject)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
[condition.term1]: convertExpression(condition, subject)
|
|
68
|
-
};
|
|
69
|
-
};
|
package/dist/deepClone.mjs
DELETED
package/dist/deepMerge.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const deepMerge = (left, right, options) => {
|
|
3
|
-
const result = Object.assign({}, left);
|
|
4
|
-
const { arrays = true } = options || {};
|
|
5
|
-
for (const key in right) {
|
|
6
|
-
const leftVal = result[key];
|
|
7
|
-
const rightVal = right[key];
|
|
8
|
-
if (options?.callback) {
|
|
9
|
-
const res = options.callback(key, leftVal, rightVal);
|
|
10
|
-
if (res !== void 0) {
|
|
11
|
-
result[key] = res;
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (Array.isArray(result[key]) && Array.isArray(rightVal)) {
|
|
16
|
-
result[key] = arrays ? result[key].concat(...rightVal) : rightVal;
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
if (rightVal instanceof Function) {
|
|
20
|
-
result[key] = rightVal;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if (leftVal instanceof Object && rightVal instanceof Object) {
|
|
24
|
-
if (rightVal.constructor !== Object) {
|
|
25
|
-
result[key] = rightVal;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
result[key] = deepMerge(leftVal, rightVal, options);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
result[key] = rightVal;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
package/dist/dynamicImport.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const dynamicImport: (path: string) => Promise<any>;
|
package/dist/dynamicImport.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dynamicImport = void 0;
|
|
4
|
-
const dynamicImport = async (path) => {
|
|
5
|
-
try {
|
|
6
|
-
return require(path);
|
|
7
|
-
}
|
|
8
|
-
catch (err) {
|
|
9
|
-
}
|
|
10
|
-
const fn = new Function(`return (async () => {
|
|
11
|
-
const { pathToFileURL } = await import('url')
|
|
12
|
-
return import(pathToFileURL('${path.replace(/\\/g, '\\\\')}'))
|
|
13
|
-
})()`);
|
|
14
|
-
return fn();
|
|
15
|
-
};
|
|
16
|
-
exports.dynamicImport = dynamicImport;
|
package/dist/dynamicImport.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const dynamicImport = async (path) => {
|
|
3
|
-
try {
|
|
4
|
-
return require(path);
|
|
5
|
-
} catch (err) {
|
|
6
|
-
}
|
|
7
|
-
const fn = new Function(`return (async () => {
|
|
8
|
-
const { pathToFileURL } = await import('url')
|
|
9
|
-
return import(pathToFileURL('${path.replace(/\\/g, "\\\\")}'))
|
|
10
|
-
})()`);
|
|
11
|
-
return fn();
|
|
12
|
-
};
|
package/dist/endpointError.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result, ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
|
|
3
|
-
import { isError } from "./result.mjs";
|
|
4
|
-
export const endpointError = (value) => {
|
|
5
|
-
return Result.error(Object.assign({
|
|
6
|
-
[ERROR_SYMBOL]: true
|
|
7
|
-
}, value));
|
|
8
|
-
};
|
|
9
|
-
export const isEndpointError = (object) => {
|
|
10
|
-
return !!(isError(object) && object.error && typeof object.error === "object" && (ERROR_SYMBOL in object.error || ERROR_SYMBOL_DESCRIPTION in object.error));
|
|
11
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { arraysIntersect } from "./arraysIntersect.mjs";
|
|
3
|
-
const isCondition = (subject) => {
|
|
4
|
-
if (!subject || typeof subject !== "object") {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
return "and" in subject || "or" in subject || "not" in subject || "operator" in subject && "term1" in subject;
|
|
8
|
-
};
|
|
9
|
-
const equalOrContains = (term1, term2) => {
|
|
10
|
-
if (Array.isArray(term1) && Array.isArray(term2)) {
|
|
11
|
-
return arraysIntersect(term1, term2);
|
|
12
|
-
}
|
|
13
|
-
if (Array.isArray(term1)) {
|
|
14
|
-
return term1.includes(term2);
|
|
15
|
-
}
|
|
16
|
-
if (Array.isArray(term2)) {
|
|
17
|
-
return term2.includes(term1);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const evaluateExpression = (subject, expression) => {
|
|
21
|
-
if (!isCondition(expression)) {
|
|
22
|
-
return expression;
|
|
23
|
-
}
|
|
24
|
-
if ("term1" in expression) {
|
|
25
|
-
if (!subject || typeof subject !== "object") {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const term1 = subject[expression.term1];
|
|
29
|
-
if (expression.operator === "truthy") {
|
|
30
|
-
return !!term1;
|
|
31
|
-
}
|
|
32
|
-
const { operator, term2 } = expression;
|
|
33
|
-
const right = evaluateExpression(subject, term2);
|
|
34
|
-
switch (operator) {
|
|
35
|
-
case "equal":
|
|
36
|
-
return term1 === right;
|
|
37
|
-
case "in":
|
|
38
|
-
return !!equalOrContains(term1, right);
|
|
39
|
-
case "gt":
|
|
40
|
-
return term1 > Number(right);
|
|
41
|
-
case "lt":
|
|
42
|
-
return term1 < Number(right);
|
|
43
|
-
case "gte":
|
|
44
|
-
return term1 >= Number(right);
|
|
45
|
-
case "lte":
|
|
46
|
-
return term1 <= Number(right);
|
|
47
|
-
case "regex":
|
|
48
|
-
return new RegExp(right).test(term1);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if ("and" in expression) {
|
|
52
|
-
return expression.and.every((expression2) => evaluateExpression(subject, expression2));
|
|
53
|
-
}
|
|
54
|
-
if ("or" in expression) {
|
|
55
|
-
return expression.or.some((expression2) => evaluateExpression(subject, expression2));
|
|
56
|
-
}
|
|
57
|
-
if ("not" in expression) {
|
|
58
|
-
return !evaluateExpression(subject, expression.not);
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
};
|
|
62
|
-
export const evaluateCondition = (subject, condition) => {
|
|
63
|
-
const result = {
|
|
64
|
-
satisfied: false,
|
|
65
|
-
else: null
|
|
66
|
-
};
|
|
67
|
-
const satisfied = result.satisfied = !!evaluateExpression(subject, condition);
|
|
68
|
-
if (!satisfied && "else" in condition) {
|
|
69
|
-
result.else = condition.else;
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
};
|
package/dist/freshItem.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const freshProperty = (property) => {
|
|
3
|
-
const value = (() => {
|
|
4
|
-
if ("$ref" in property && property.inline) {
|
|
5
|
-
return {};
|
|
6
|
-
}
|
|
7
|
-
if ("properties" in property) {
|
|
8
|
-
const obj = {};
|
|
9
|
-
for (const propName in property.properties) {
|
|
10
|
-
obj[propName] = freshProperty(property.properties[propName]);
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
if ("type" in property) {
|
|
15
|
-
switch (property.type) {
|
|
16
|
-
case "boolean":
|
|
17
|
-
return false;
|
|
18
|
-
case "array":
|
|
19
|
-
return [];
|
|
20
|
-
case "object":
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
})();
|
|
26
|
-
return value;
|
|
27
|
-
};
|
|
28
|
-
export const freshItem = (description) => {
|
|
29
|
-
const item = {};
|
|
30
|
-
for (const propName in description.properties) {
|
|
31
|
-
const value = freshProperty(description.properties[propName]);
|
|
32
|
-
if (value !== null) {
|
|
33
|
-
item[propName] = value;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (description.freshItem) {
|
|
37
|
-
Object.assign(item, description.freshItem);
|
|
38
|
-
}
|
|
39
|
-
return item;
|
|
40
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { checkForEmptiness } from "./checkForEmptiness.mjs";
|
|
3
|
-
import { evaluateCondition } from "./evaluateCondition.mjs";
|
|
4
|
-
export const getMissingProperties = (what, schema, required) => {
|
|
5
|
-
const missingProps = [];
|
|
6
|
-
if (Array.isArray(required)) {
|
|
7
|
-
for (const propName of required) {
|
|
8
|
-
const isMissing = checkForEmptiness(schema.properties[propName], propName, what);
|
|
9
|
-
if (isMissing) {
|
|
10
|
-
missingProps.push(propName);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
for (const propName in required) {
|
|
15
|
-
const requiredProp = required[propName];
|
|
16
|
-
if (typeof requiredProp === "boolean") {
|
|
17
|
-
if (!requiredProp) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (typeof requiredProp === "object") {
|
|
22
|
-
const result = evaluateCondition(what, requiredProp);
|
|
23
|
-
if (!result.satisfied) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const isMissing = checkForEmptiness(
|
|
28
|
-
schema.properties[propName],
|
|
29
|
-
propName,
|
|
30
|
-
what
|
|
31
|
-
);
|
|
32
|
-
if (isMissing) {
|
|
33
|
-
missingProps.push(propName);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return missingProps;
|
|
38
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const getReferenceProperty = (property) => {
|
|
3
|
-
const search = [
|
|
4
|
-
"items" in property ? property.items : null,
|
|
5
|
-
"additionalProperties" in property && typeof property.additionalProperties === "object" ? property.additionalProperties : null,
|
|
6
|
-
property
|
|
7
|
-
];
|
|
8
|
-
const reference = search.find((_) => !!_);
|
|
9
|
-
return reference && "$ref" in reference ? reference : null;
|
|
10
|
-
};
|
package/dist/http.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const defaultRequestTransformer = async (context) => {
|
|
3
|
-
if (context.payload) {
|
|
4
|
-
if (context.params.method === "GET" || context.params.method === "HEAD") {
|
|
5
|
-
context.url += `?${new URLSearchParams(context.payload)}`;
|
|
6
|
-
} else {
|
|
7
|
-
context.params.body = context.params.headers?.["content-type"]?.startsWith("application/json") ? JSON.stringify(context.payload) : context.payload;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return context;
|
|
11
|
-
};
|
|
12
|
-
export const defaultResponseTransformer = async (context) => {
|
|
13
|
-
const result = context.response;
|
|
14
|
-
result.data = await context.response.text();
|
|
15
|
-
if (context.response.headers.get("content-type")?.startsWith("application/json")) {
|
|
16
|
-
result.data = JSON.parse(String(result.data));
|
|
17
|
-
}
|
|
18
|
-
context.response = result;
|
|
19
|
-
return context;
|
|
20
|
-
};
|
|
21
|
-
export const request = async (url, payload, config = {}) => {
|
|
22
|
-
const {
|
|
23
|
-
requestTransformer,
|
|
24
|
-
responseTransformer
|
|
25
|
-
} = config;
|
|
26
|
-
let params;
|
|
27
|
-
if (config.params) {
|
|
28
|
-
params = config.params;
|
|
29
|
-
} else {
|
|
30
|
-
if (payload) {
|
|
31
|
-
params = {
|
|
32
|
-
method: "POST",
|
|
33
|
-
headers: {
|
|
34
|
-
"content-type": "application/json"
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
} else {
|
|
38
|
-
params = {
|
|
39
|
-
method: "GET"
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
let transformedRequest = {
|
|
44
|
-
url,
|
|
45
|
-
payload,
|
|
46
|
-
params
|
|
47
|
-
};
|
|
48
|
-
if (requestTransformer) {
|
|
49
|
-
transformedRequest = await requestTransformer(transformedRequest, defaultRequestTransformer);
|
|
50
|
-
} else {
|
|
51
|
-
transformedRequest = await defaultRequestTransformer(transformedRequest);
|
|
52
|
-
}
|
|
53
|
-
const response = await fetch(transformedRequest.url, transformedRequest.params);
|
|
54
|
-
let transformedResponse = {
|
|
55
|
-
response
|
|
56
|
-
};
|
|
57
|
-
if (responseTransformer) {
|
|
58
|
-
transformedResponse = await responseTransformer(transformedResponse, defaultResponseTransformer);
|
|
59
|
-
} else {
|
|
60
|
-
transformedResponse = await defaultResponseTransformer(transformedResponse);
|
|
61
|
-
}
|
|
62
|
-
return transformedResponse.response;
|
|
63
|
-
};
|
package/dist/index.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export * from "./arraysIntersect.mjs";
|
|
3
|
-
export * from "./checkForEmptiness.mjs";
|
|
4
|
-
export * from "./deepClone.mjs";
|
|
5
|
-
export * from "./deepMerge.mjs";
|
|
6
|
-
export * from "./dynamicImport.mjs";
|
|
7
|
-
export * from "./result.mjs";
|
|
8
|
-
export * from "./endpointError.mjs";
|
|
9
|
-
export * from "./evaluateCondition.mjs";
|
|
10
|
-
export * from "./freshItem.mjs";
|
|
11
|
-
export * from "./getMissingProperties.mjs";
|
|
12
|
-
export * from "./getReferenceProperty.mjs";
|
|
13
|
-
export * from "./getValueFromPath.mjs";
|
|
14
|
-
export * from "./http.mjs";
|
|
15
|
-
export * from "./isGranted.mjs";
|
|
16
|
-
export * from "./isReference.mjs";
|
|
17
|
-
export * from "./isRequired.mjs";
|
|
18
|
-
export * from "./isValidCollection.mjs";
|
|
19
|
-
export * from "./convertConditionToQuery.mjs";
|
|
20
|
-
export * from "./pipe.mjs";
|
|
21
|
-
export * from "./serialize.mjs";
|
package/dist/isGranted.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { arraysIntersect } from "./arraysIntersect.mjs";
|
|
3
|
-
export const isGranted = (condition, token) => {
|
|
4
|
-
if (Array.isArray(condition)) {
|
|
5
|
-
return token.authenticated ? arraysIntersect(token.roles, condition) : condition.includes("unauthenticated");
|
|
6
|
-
}
|
|
7
|
-
switch (condition) {
|
|
8
|
-
case false:
|
|
9
|
-
case void 0:
|
|
10
|
-
return false;
|
|
11
|
-
case true:
|
|
12
|
-
return token.authenticated;
|
|
13
|
-
case "unauthenticated":
|
|
14
|
-
return true;
|
|
15
|
-
case "unauthenticated-only":
|
|
16
|
-
return !token.authenticated;
|
|
17
|
-
}
|
|
18
|
-
};
|
package/dist/isReference.mjs
DELETED
package/dist/isRequired.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { evaluateCondition } from "./evaluateCondition.mjs";
|
|
3
|
-
export const isRequired = (propName, required, subject) => {
|
|
4
|
-
if (Array.isArray(required)) {
|
|
5
|
-
return required.includes(propName);
|
|
6
|
-
}
|
|
7
|
-
if (!(propName in required)) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const requiredProp = required[propName];
|
|
11
|
-
if (typeof requiredProp !== "object") {
|
|
12
|
-
return requiredProp;
|
|
13
|
-
}
|
|
14
|
-
return evaluateCondition(subject, requiredProp).satisfied;
|
|
15
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const isValidDescription = (value) => {
|
|
3
|
-
return !!(value && typeof value === "object" && "$id" in value && "properties" in value && value.properties && typeof value.$id === "string" && typeof value.properties === "object");
|
|
4
|
-
};
|
|
5
|
-
export const isValidCollection = (value) => {
|
|
6
|
-
return !!(value && typeof value === "object" && "description" in value && isValidDescription(value.description));
|
|
7
|
-
};
|
package/dist/pipe.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const pipe = (functions, options) => {
|
|
3
|
-
const { returnFirst } = options || {};
|
|
4
|
-
return async (value, ...args) => {
|
|
5
|
-
let ret = value;
|
|
6
|
-
for (const fn of functions) {
|
|
7
|
-
ret = await fn(ret, ...args);
|
|
8
|
-
if (returnFirst && ret !== void 0) {
|
|
9
|
-
switch (typeof returnFirst) {
|
|
10
|
-
case "function": {
|
|
11
|
-
const result = returnFirst(ret);
|
|
12
|
-
if (result !== void 0) {
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
default: {
|
|
18
|
-
return ret;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return ret;
|
|
24
|
-
};
|
|
25
|
-
};
|
package/dist/result.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const isEither = (value) => {
|
|
3
|
-
return !!(value && typeof value === "object" && "_tag" in value && (value._tag === "Error" || value._tag === "Result"));
|
|
4
|
-
};
|
|
5
|
-
export const isResult = (value) => {
|
|
6
|
-
return !!(isEither(value) && value.result);
|
|
7
|
-
};
|
|
8
|
-
export const isError = (value) => {
|
|
9
|
-
return !!(isEither(value) && value.error);
|
|
10
|
-
};
|
|
11
|
-
export const throwIfError = (either, message) => {
|
|
12
|
-
if (either.error) {
|
|
13
|
-
if (true) {
|
|
14
|
-
console.trace(JSON.stringify(either.error, null, 2));
|
|
15
|
-
}
|
|
16
|
-
throw new Error(`throwIfError threw: ${either.error} ${message ? `(${message})` : ""}`);
|
|
17
|
-
}
|
|
18
|
-
return either.result;
|
|
19
|
-
};
|
package/dist/serialize.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import * as BSON from "bson";
|
|
3
|
-
export const serialize = (...args) => Buffer.from(BSON.serialize(...args)).toString("latin1");
|
|
4
|
-
export const deserialize = (buffer) => {
|
|
5
|
-
return BSON.deserialize(new Uint8Array(Array.from(buffer).map((c) => c.charCodeAt(0))));
|
|
6
|
-
};
|