@aeriajs/common 0.0.100 → 0.0.102
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.d.ts +1 -1
- package/dist/{checkForUndefined.d.ts → checkForEmptiness.d.ts} +1 -1
- package/dist/{checkForUndefined.js → checkForEmptiness.js} +3 -3
- package/dist/{checkForUndefined.mjs → checkForEmptiness.mjs} +1 -1
- package/dist/deepMerge.js +1 -1
- package/dist/deepMerge.mjs +1 -1
- package/dist/endpointError.d.ts +1 -1
- package/dist/endpointError.js +3 -2
- package/dist/endpointError.mjs +2 -1
- package/dist/evaluateCondition.d.ts +2 -2
- package/dist/evaluateCondition.js +5 -5
- package/dist/evaluateCondition.mjs +5 -5
- package/dist/getMissingProperties.js +3 -3
- package/dist/getMissingProperties.mjs +3 -3
- package/dist/getValueFromPath.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/http.js +1 -1
- package/dist/http.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/isRequired.d.ts +9 -2
- package/dist/isRequired.js +1 -1
- package/dist/isRequired.mjs +1 -1
- package/dist/pipe.d.ts +3 -3
- package/dist/pipe.js +1 -0
- package/dist/result.d.ts +4 -3
- package/dist/result.js +11 -8
- package/dist/result.mjs +6 -3
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const arraysIntersect: <T extends
|
|
1
|
+
export declare const arraysIntersect: <T extends unknown[] | readonly unknown[]>(subject: T | string, arr: T | undefined) => boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Property } from '@aeriajs/types';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const checkForEmptiness: (property: Property, propName: string, what: Record<string, unknown>) => boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.checkForEmptiness = void 0;
|
|
4
|
+
const checkForEmptiness = (property, propName, what) => {
|
|
5
5
|
if (property.readOnly || property.isTimestamp) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
@@ -9,4 +9,4 @@ const checkForUndefined = (property, propName, what) => {
|
|
|
9
9
|
|| what[propName] === undefined
|
|
10
10
|
|| what[propName] === '';
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
12
|
+
exports.checkForEmptiness = checkForEmptiness;
|
package/dist/deepMerge.js
CHANGED
|
@@ -14,7 +14,7 @@ const deepMerge = (left, right, options) => {
|
|
|
14
14
|
continue;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
if (Array.isArray(
|
|
17
|
+
if (Array.isArray(result[key]) && Array.isArray(rightVal)) {
|
|
18
18
|
result[key] = arrays
|
|
19
19
|
? result[key].concat(...rightVal)
|
|
20
20
|
: rightVal;
|
package/dist/deepMerge.mjs
CHANGED
|
@@ -12,7 +12,7 @@ export const deepMerge = (left, right, options) => {
|
|
|
12
12
|
continue;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
if (Array.isArray(
|
|
15
|
+
if (Array.isArray(result[key]) && Array.isArray(rightVal)) {
|
|
16
16
|
result[key] = arrays ? result[key].concat(...rightVal) : rightVal;
|
|
17
17
|
continue;
|
|
18
18
|
}
|
package/dist/endpointError.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare const endpointError: <const TEndpointError extends EndpointError>
|
|
|
5
5
|
readonly error: TEndpointError;
|
|
6
6
|
readonly result: undefined;
|
|
7
7
|
};
|
|
8
|
-
export declare const isEndpointError: (object: EndpointError |
|
|
8
|
+
export declare const isEndpointError: (object: EndpointError | unknown) => object is Result.Error<EndpointError>;
|
package/dist/endpointError.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isEndpointError = exports.endpointError = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
|
+
const result_js_1 = require("./result.js");
|
|
5
6
|
const endpointError = (value) => {
|
|
6
7
|
return types_1.Result.error(Object.assign({
|
|
7
8
|
[types_1.ERROR_SYMBOL]: true,
|
|
@@ -9,9 +10,9 @@ const endpointError = (value) => {
|
|
|
9
10
|
};
|
|
10
11
|
exports.endpointError = endpointError;
|
|
11
12
|
const isEndpointError = (object) => {
|
|
12
|
-
return object
|
|
13
|
+
return !!((0, result_js_1.isError)(object)
|
|
13
14
|
&& object.error
|
|
14
15
|
&& typeof object.error === 'object'
|
|
15
|
-
&& (types_1.ERROR_SYMBOL in object.error || types_1.ERROR_SYMBOL_DESCRIPTION in object.error);
|
|
16
|
+
&& (types_1.ERROR_SYMBOL in object.error || types_1.ERROR_SYMBOL_DESCRIPTION in object.error));
|
|
16
17
|
};
|
|
17
18
|
exports.isEndpointError = isEndpointError;
|
package/dist/endpointError.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Result, ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
|
|
3
|
+
import { isError } from "./result.mjs";
|
|
3
4
|
export const endpointError = (value) => {
|
|
4
5
|
return Result.error(Object.assign({
|
|
5
6
|
[ERROR_SYMBOL]: true
|
|
6
7
|
}, value));
|
|
7
8
|
};
|
|
8
9
|
export const isEndpointError = (object) => {
|
|
9
|
-
return object && object.error && typeof object.error === "object" && (ERROR_SYMBOL in object.error || ERROR_SYMBOL_DESCRIPTION in object.error);
|
|
10
|
+
return !!(isError(object) && object.error && typeof object.error === "object" && (ERROR_SYMBOL in object.error || ERROR_SYMBOL_DESCRIPTION in object.error));
|
|
10
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Condition } from '@aeriajs/types';
|
|
2
|
-
export declare const evaluateCondition: (subject:
|
|
2
|
+
export declare const evaluateCondition: (subject: unknown, condition: Condition) => {
|
|
3
3
|
satisfied: boolean;
|
|
4
|
-
else:
|
|
4
|
+
else: unknown;
|
|
5
5
|
};
|
|
@@ -15,7 +15,7 @@ const equalOrContains = (term1, term2) => {
|
|
|
15
15
|
};
|
|
16
16
|
const evaluatesToTrue = (subject, condition) => {
|
|
17
17
|
if ('term1' in condition) {
|
|
18
|
-
if (!subject) {
|
|
18
|
+
if (!subject || typeof subject !== 'object') {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
const term1 = subject[condition.term1];
|
|
@@ -26,10 +26,10 @@ const evaluatesToTrue = (subject, condition) => {
|
|
|
26
26
|
switch (operator) {
|
|
27
27
|
case 'equal': return term1 === term2;
|
|
28
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;
|
|
29
|
+
case 'gt': return term1 > Number(term2);
|
|
30
|
+
case 'lt': return term1 < Number(term2);
|
|
31
|
+
case 'gte': return term1 >= Number(term2);
|
|
32
|
+
case 'lte': return term1 <= Number(term2);
|
|
33
33
|
case 'regex': return new RegExp(term2).test(term1);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -13,7 +13,7 @@ const equalOrContains = (term1, term2) => {
|
|
|
13
13
|
};
|
|
14
14
|
const evaluatesToTrue = (subject, condition) => {
|
|
15
15
|
if ("term1" in condition) {
|
|
16
|
-
if (!subject) {
|
|
16
|
+
if (!subject || typeof subject !== "object") {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
const term1 = subject[condition.term1];
|
|
@@ -27,13 +27,13 @@ const evaluatesToTrue = (subject, condition) => {
|
|
|
27
27
|
case "in":
|
|
28
28
|
return !!equalOrContains(term1, term2);
|
|
29
29
|
case "gt":
|
|
30
|
-
return term1 > term2;
|
|
30
|
+
return term1 > Number(term2);
|
|
31
31
|
case "lt":
|
|
32
|
-
return term1 < term2;
|
|
32
|
+
return term1 < Number(term2);
|
|
33
33
|
case "gte":
|
|
34
|
-
return term1 >= term2;
|
|
34
|
+
return term1 >= Number(term2);
|
|
35
35
|
case "lte":
|
|
36
|
-
return term1 <= term2;
|
|
36
|
+
return term1 <= Number(term2);
|
|
37
37
|
case "regex":
|
|
38
38
|
return new RegExp(term2).test(term1);
|
|
39
39
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMissingProperties = void 0;
|
|
4
|
-
const
|
|
4
|
+
const checkForEmptiness_js_1 = require("./checkForEmptiness.js");
|
|
5
5
|
const evaluateCondition_js_1 = require("./evaluateCondition.js");
|
|
6
6
|
const getMissingProperties = (what, schema, required) => {
|
|
7
7
|
const missingProps = [];
|
|
8
8
|
if (Array.isArray(required)) {
|
|
9
9
|
for (const propName of required) {
|
|
10
|
-
const isMissing = (0,
|
|
10
|
+
const isMissing = (0, checkForEmptiness_js_1.checkForEmptiness)(schema.properties[propName], propName, what);
|
|
11
11
|
if (isMissing) {
|
|
12
12
|
missingProps.push(propName);
|
|
13
13
|
}
|
|
@@ -27,7 +27,7 @@ const getMissingProperties = (what, schema, required) => {
|
|
|
27
27
|
continue;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
const isMissing = (0,
|
|
30
|
+
const isMissing = (0, checkForEmptiness_js_1.checkForEmptiness)(schema.properties[propName], propName, what);
|
|
31
31
|
if (isMissing) {
|
|
32
32
|
missingProps.push(propName);
|
|
33
33
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { checkForEmptiness } from "./checkForEmptiness.mjs";
|
|
3
3
|
import { evaluateCondition } from "./evaluateCondition.mjs";
|
|
4
4
|
export const getMissingProperties = (what, schema, required) => {
|
|
5
5
|
const missingProps = [];
|
|
6
6
|
if (Array.isArray(required)) {
|
|
7
7
|
for (const propName of required) {
|
|
8
|
-
const isMissing =
|
|
8
|
+
const isMissing = checkForEmptiness(
|
|
9
9
|
schema.properties[propName],
|
|
10
10
|
propName,
|
|
11
11
|
what
|
|
@@ -28,7 +28,7 @@ export const getMissingProperties = (what, schema, required) => {
|
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
const isMissing =
|
|
31
|
+
const isMissing = checkForEmptiness(
|
|
32
32
|
schema.properties[propName],
|
|
33
33
|
propName,
|
|
34
34
|
what
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getValueFromPath: (object:
|
|
1
|
+
export declare const getValueFromPath: <TValue>(object: Record<string, unknown>, path: string) => TValue;
|
package/dist/http.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type RequestConfig = {
|
|
|
9
9
|
}>;
|
|
10
10
|
responseTransformer?: typeof defaultResponseTransformer;
|
|
11
11
|
};
|
|
12
|
-
export declare const defaultRequestTransformer: (url: string, payload:
|
|
12
|
+
export declare const defaultRequestTransformer: (url: string, payload: unknown, params: RequestParams) => Promise<{
|
|
13
13
|
url: string;
|
|
14
14
|
params: RequestParams;
|
|
15
15
|
}>;
|
package/dist/http.js
CHANGED
|
@@ -13,7 +13,7 @@ const defaultRequestTransformer = async (url, payload, params) => {
|
|
|
13
13
|
else {
|
|
14
14
|
request.params.body = params.headers?.['content-type']?.startsWith('application/json')
|
|
15
15
|
? JSON.stringify(payload)
|
|
16
|
-
: payload;
|
|
16
|
+
: Buffer.from(String(payload));
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
return request;
|
package/dist/http.mjs
CHANGED
|
@@ -8,7 +8,7 @@ export const defaultRequestTransformer = async (url, payload, params) => {
|
|
|
8
8
|
if (params.method === "GET" || params.method === "HEAD") {
|
|
9
9
|
request2.url += `?${new URLSearchParams(payload)}`;
|
|
10
10
|
} else {
|
|
11
|
-
request2.params.body = params.headers?.["content-type"]?.startsWith("application/json") ? JSON.stringify(payload) : payload;
|
|
11
|
+
request2.params.body = params.headers?.["content-type"]?.startsWith("application/json") ? JSON.stringify(payload) : Buffer.from(String(payload));
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
return request2;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./arraysIntersect.js"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./checkForEmptiness.js"), exports);
|
|
19
19
|
__exportStar(require("./deepClone.js"), exports);
|
|
20
20
|
__exportStar(require("./deepMerge.js"), exports);
|
|
21
21
|
__exportStar(require("./dynamicImport.js"), exports);
|
package/dist/index.mjs
CHANGED
package/dist/isRequired.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const isRequired: (propName: string, required: NonNullable<
|
|
1
|
+
import type { JsonSchema } from '@aeriajs/types';
|
|
2
|
+
export declare const isRequired: (propName: string, required: NonNullable<JsonSchema["required"]>, subject: unknown) => number | boolean | {
|
|
3
|
+
(...items: ConcatArray<string>[]): string[];
|
|
4
|
+
(...items: (string | ConcatArray<string>)[]): string[];
|
|
5
|
+
} | ((separator?: string) => string) | ((start?: number, end?: number) => string[]) | ((searchElement: string, fromIndex?: number) => number) | ((callbackfn: (value: string, index: number, array: readonly string[]) => void, thisArg?: any) => void) | {
|
|
6
|
+
(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: readonly string[]) => string): string;
|
|
7
|
+
(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: readonly string[]) => string, initialValue: string): string;
|
|
8
|
+
<U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: readonly string[]) => U, initialValue: U): U;
|
|
9
|
+
} | ((searchElement: string, fromIndex?: number) => boolean) | (<A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]) | ((index: number) => string | undefined) | ((compareFn?: ((a: string, b: string) => number) | undefined) => string[]) | ((index: number, value: string) => string[]) | undefined;
|
package/dist/isRequired.js
CHANGED
|
@@ -10,7 +10,7 @@ const isRequired = (propName, required, subject) => {
|
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
const requiredProp = required[propName];
|
|
13
|
-
if (typeof requiredProp
|
|
13
|
+
if (typeof requiredProp !== 'object') {
|
|
14
14
|
return requiredProp;
|
|
15
15
|
}
|
|
16
16
|
return (0, evaluateCondition_js_1.evaluateCondition)(subject, requiredProp).satisfied;
|
package/dist/isRequired.mjs
CHANGED
|
@@ -8,7 +8,7 @@ export const isRequired = (propName, required, subject) => {
|
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
const requiredProp = required[propName];
|
|
11
|
-
if (typeof requiredProp
|
|
11
|
+
if (typeof requiredProp !== "object") {
|
|
12
12
|
return requiredProp;
|
|
13
13
|
}
|
|
14
14
|
return evaluateCondition(subject, requiredProp).satisfied;
|
package/dist/pipe.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type PipeOptions = {
|
|
2
|
-
returnFirst?: boolean | ((value: unknown) =>
|
|
1
|
+
export type PipeOptions<TReturn> = {
|
|
2
|
+
returnFirst?: boolean | ((value: unknown) => Awaited<TReturn> | undefined);
|
|
3
3
|
};
|
|
4
|
-
export declare const pipe: <
|
|
4
|
+
export declare const pipe: <TArgs extends unknown[], TReturn>(functions: ((p1: TReturn, ...args: TArgs) => TReturn)[], options?: PipeOptions<TReturn>) => (value: Awaited<TReturn>, ...args: TArgs) => Promise<TReturn>;
|
package/dist/pipe.js
CHANGED
package/dist/result.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Result } from '@aeriajs/types';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
2
|
+
export declare const isEither: (value: unknown) => value is Result.Either<unknown, unknown>;
|
|
3
|
+
export declare const isResult: (value: unknown) => value is Result.Result<unknown>;
|
|
4
|
+
export declare const isError: (value: unknown) => value is Result.Error<unknown>;
|
|
5
|
+
export declare const throwIfError: <TValue>(either: Result.Either<unknown, TValue>, message?: unknown) => NonNullable<TValue>;
|
package/dist/result.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfError = exports.isError = exports.isResult = void 0;
|
|
3
|
+
exports.throwIfError = exports.isError = exports.isResult = exports.isEither = void 0;
|
|
4
|
+
const isEither = (value) => {
|
|
5
|
+
return !!(value
|
|
6
|
+
&& typeof value === 'object'
|
|
7
|
+
&& '_tag' in value
|
|
8
|
+
&& (value._tag === 'Error' || value._tag === 'Result'));
|
|
9
|
+
};
|
|
10
|
+
exports.isEither = isEither;
|
|
4
11
|
const isResult = (value) => {
|
|
5
|
-
return value
|
|
6
|
-
&& value.constructor === Object
|
|
7
|
-
&& (value._tag === 'Error' || value._tag === 'Result');
|
|
12
|
+
return !!((0, exports.isEither)(value) && value.result);
|
|
8
13
|
};
|
|
9
14
|
exports.isResult = isResult;
|
|
10
|
-
const isError = (
|
|
11
|
-
return
|
|
12
|
-
&& object._tag === 'Error'
|
|
13
|
-
&& 'error' in object;
|
|
15
|
+
const isError = (value) => {
|
|
16
|
+
return !!((0, exports.isEither)(value) && value.error);
|
|
14
17
|
};
|
|
15
18
|
exports.isError = isError;
|
|
16
19
|
const throwIfError = (either, message) => {
|
package/dist/result.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
export const isEither = (value) => {
|
|
3
|
+
return !!(value && typeof value === "object" && "_tag" in value && (value._tag === "Error" || value._tag === "Result"));
|
|
4
|
+
};
|
|
2
5
|
export const isResult = (value) => {
|
|
3
|
-
return value && value.
|
|
6
|
+
return !!(isEither(value) && value.result);
|
|
4
7
|
};
|
|
5
|
-
export const isError = (
|
|
6
|
-
return
|
|
8
|
+
export const isError = (value) => {
|
|
9
|
+
return !!(isEither(value) && value.error);
|
|
7
10
|
};
|
|
8
11
|
export const throwIfError = (either, message) => {
|
|
9
12
|
if (either.error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.102",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bson": "^6.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
+
"@aeriajs/types": "^0.0.87",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|