@aeriajs/common 0.0.55 → 0.0.57

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/either.d.ts CHANGED
@@ -1,7 +1,7 @@
1
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>;
2
+ export declare const left: <const TValue>(value: TValue) => Left<TValue>;
3
+ export declare const right: <const TValue>(value: TValue) => Right<TValue>;
4
+ export declare const isLeft: <TValue>(either: Either<TValue, any>) => either is Left<TValue>;
5
+ export declare const isRight: <TValue>(either: Either<any, TValue>) => either is Right<TValue>;
6
6
  export declare const unwrapEither: <L, R>(either: Either<L, R>) => L | R;
7
- export declare const unsafe: <L, R>(either: Either<L, R>, message?: any) => R;
7
+ export declare const throwIfLeft: <L, R>(either: Either<L, R>, message?: any) => R;
package/dist/either.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unsafe = exports.unwrapEither = exports.isRight = exports.isLeft = exports.right = exports.left = void 0;
3
+ exports.throwIfLeft = exports.unwrapEither = exports.isRight = exports.isLeft = exports.right = exports.left = void 0;
4
4
  const left = (value) => ({
5
5
  _tag: 'Left',
6
6
  value,
@@ -23,13 +23,13 @@ const unwrapEither = (either) => {
23
23
  return either.value;
24
24
  };
25
25
  exports.unwrapEither = unwrapEither;
26
- const unsafe = (either, message) => {
26
+ const throwIfLeft = (either, message) => {
27
27
  if (either._tag !== 'Right') {
28
28
  if (process.env.NODE_ENV !== 'production') {
29
29
  console.trace(JSON.stringify(either.value, null, 2));
30
30
  }
31
- throw new Error(`unsafe threw: ${either.value} (${message || '-'})`);
31
+ throw new Error(`throwIfLeft threw: ${either.value} (${message || '-'})`);
32
32
  }
33
33
  return either.value;
34
34
  };
35
- exports.unsafe = unsafe;
35
+ exports.throwIfLeft = throwIfLeft;
package/dist/either.mjs CHANGED
@@ -16,12 +16,12 @@ export const isRight = (either) => {
16
16
  export const unwrapEither = (either) => {
17
17
  return either.value;
18
18
  };
19
- export const unsafe = (either, message) => {
19
+ export const throwIfLeft = (either, message) => {
20
20
  if (either._tag !== "Right") {
21
21
  if (true) {
22
22
  console.trace(JSON.stringify(either.value, null, 2));
23
23
  }
24
- throw new Error(`unsafe threw: ${either.value} (${message || "-"})`);
24
+ throw new Error(`throwIfLeft threw: ${either.value} (${message || "-"})`);
25
25
  }
26
26
  return either.value;
27
27
  };
package/dist/error.d.ts CHANGED
@@ -2,5 +2,6 @@ import type { EndpointError, EndpointErrorContent } from '@aeriajs/types';
2
2
  export declare const error: <const TEndpointErrorContent extends EndpointErrorContent>(value: TEndpointErrorContent) => EndpointError & {
3
3
  value: TEndpointErrorContent;
4
4
  };
5
- export declare const isError: <TEndpointErrorContent extends EndpointErrorContent>(object: EndpointError<TEndpointErrorContent> | any) => object is EndpointError<TEndpointErrorContent>;
5
+ export declare const isError: (object: EndpointError | any) => object is EndpointError<any>;
6
6
  export declare const unwrapError: <TEndpointErrorContent extends EndpointErrorContent>(error: EndpointError<TEndpointErrorContent>) => TEndpointErrorContent;
7
+ export declare const throwIfError: <TValue>(value: TValue, message?: any) => Exclude<TValue, EndpointError<any>>;
package/dist/error.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unwrapError = exports.isError = exports.error = void 0;
3
+ exports.throwIfError = exports.unwrapError = exports.isError = exports.error = void 0;
4
4
  const types_1 = require("@aeriajs/types");
5
5
  const error = (value) => {
6
6
  const wrappedError = {
@@ -21,3 +21,14 @@ const unwrapError = (error) => {
21
21
  return error.value;
22
22
  };
23
23
  exports.unwrapError = unwrapError;
24
+ const throwIfError = (value, message) => {
25
+ if ((0, exports.isError)(value)) {
26
+ const error = (0, exports.unwrapError)(value);
27
+ if (process.env.NODE_ENV !== 'production') {
28
+ console.trace(JSON.stringify(error, null, 2));
29
+ }
30
+ throw new Error(`throwIfLeft threw: ${error.code} (${message || '-'})`);
31
+ }
32
+ return value;
33
+ };
34
+ exports.throwIfError = throwIfError;
package/dist/error.mjs CHANGED
@@ -14,3 +14,13 @@ export const isError = (object) => {
14
14
  export const unwrapError = (error2) => {
15
15
  return error2.value;
16
16
  };
17
+ export const throwIfError = (value, message) => {
18
+ if (isError(value)) {
19
+ const error2 = unwrapError(value);
20
+ if (true) {
21
+ console.trace(JSON.stringify(error2, null, 2));
22
+ }
23
+ throw new Error(`throwIfLeft threw: ${error2.code} (${message || "-"})`);
24
+ }
25
+ return value;
26
+ };
package/dist/schema.d.ts CHANGED
@@ -18,12 +18,15 @@ export declare const rightSchema: <const TObject extends Property>(object: TObje
18
18
  readonly value: Property;
19
19
  };
20
20
  };
21
- export declare const endpointErrorSchema: <THTTPStatus extends HTTPStatus[], TCode extends string[]>(error: {
21
+ export declare const endpointErrorSchema: <const THTTPStatus extends HTTPStatus[], const TCode extends string[]>(error: {
22
22
  httpStatus: THTTPStatus;
23
23
  code: TCode;
24
24
  }) => {
25
25
  readonly type: "object";
26
26
  readonly properties: {
27
+ readonly _tag: {
28
+ readonly const: "Error";
29
+ };
27
30
  readonly value: {
28
31
  readonly type: "object";
29
32
  readonly required: readonly ["httpStatus", "code"];
package/dist/schema.js CHANGED
@@ -76,6 +76,9 @@ const endpointErrorSchema = (error) => {
76
76
  return {
77
77
  type: 'object',
78
78
  properties: {
79
+ _tag: {
80
+ const: 'Error',
81
+ },
79
82
  value: {
80
83
  type: 'object',
81
84
  required: [
package/dist/schema.mjs CHANGED
@@ -71,6 +71,9 @@ export const endpointErrorSchema = (error) => {
71
71
  return {
72
72
  type: "object",
73
73
  properties: {
74
+ _tag: {
75
+ const: "Error"
76
+ },
74
77
  value: {
75
78
  type: "object",
76
79
  required: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/common",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
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.52",
34
+ "@aeriajs/types": "^0.0.54",
35
35
  "bson": "^6.5.0"
36
36
  },
37
37
  "scripts": {