@aeriajs/common 0.0.101 → 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.
@@ -1 +1 @@
1
- export declare const arraysIntersect: <T extends any[] | readonly any[]>(subject: T | string, arr: T | undefined) => boolean;
1
+ export declare const arraysIntersect: <T extends unknown[] | readonly unknown[]>(subject: T | string, arr: T | undefined) => boolean;
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(leftVal) && Array.isArray(rightVal)) {
17
+ if (Array.isArray(result[key]) && Array.isArray(rightVal)) {
18
18
  result[key] = arrays
19
19
  ? result[key].concat(...rightVal)
20
20
  : rightVal;
@@ -12,7 +12,7 @@ export const deepMerge = (left, right, options) => {
12
12
  continue;
13
13
  }
14
14
  }
15
- if (Array.isArray(leftVal) && Array.isArray(rightVal)) {
15
+ if (Array.isArray(result[key]) && Array.isArray(rightVal)) {
16
16
  result[key] = arrays ? result[key].concat(...rightVal) : rightVal;
17
17
  continue;
18
18
  }
@@ -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 | any) => object is Result.Error<EndpointError<any>>;
8
+ export declare const isEndpointError: (object: EndpointError | unknown) => object is Result.Error<EndpointError>;
@@ -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;
@@ -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: any, condition: Condition) => {
2
+ export declare const evaluateCondition: (subject: unknown, condition: Condition) => {
3
3
  satisfied: boolean;
4
- else: null;
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 +1 @@
1
- export declare const getValueFromPath: (object: any, path: string) => any;
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: any, params: RequestParams) => Promise<{
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;
@@ -1,2 +1,9 @@
1
- import type { Description } from '@aeriajs/types';
2
- export declare const isRequired: (propName: string, required: NonNullable<Description["required"]>, subject: any) => boolean;
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;
@@ -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 === 'boolean') {
13
+ if (typeof requiredProp !== 'object') {
14
14
  return requiredProp;
15
15
  }
16
16
  return (0, evaluateCondition_js_1.evaluateCondition)(subject, requiredProp).satisfied;
@@ -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 === "boolean") {
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) => unknown);
1
+ export type PipeOptions<TReturn> = {
2
+ returnFirst?: boolean | ((value: unknown) => Awaited<TReturn> | undefined);
3
3
  };
4
- export declare const pipe: <TFunction extends (...args: any) => any>(functions: TFunction[], options?: PipeOptions) => (value: Parameters<TFunction>[0], ...args: Parameters<TFunction> extends [unknown, ...infer Tail] ? Tail : []) => Promise<{} | ReturnType<TFunction> | null>;
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
@@ -7,6 +7,7 @@ const pipe = (functions, options) => {
7
7
  let ret = value;
8
8
  for (const fn of functions) {
9
9
  ret = await fn(ret, ...args);
10
+ // eslint-disable-next-line
10
11
  if (returnFirst && ret !== undefined) {
11
12
  switch (typeof returnFirst) {
12
13
  case 'function': {
package/dist/result.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Result } from '@aeriajs/types';
2
- export declare const isResult: (value: any) => value is Result.Either<unknown, unknown>;
3
- export declare const isError: (object: any) => object is Result.Error<unknown>;
4
- export declare const throwIfError: <TValue>(either: Result.Either<unknown, TValue>, message?: any) => NonNullable<TValue>;
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 = (object) => {
11
- return object
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.constructor === Object && (value._tag === "Error" || value._tag === "Result");
6
+ return !!(isEither(value) && value.result);
4
7
  };
5
- export const isError = (object) => {
6
- return object && object._tag === "Error" && "error" in object;
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.101",
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.86",
34
+ "@aeriajs/types": "^0.0.87",
35
35
  "bson": "^6.5.0"
36
36
  },
37
37
  "scripts": {