@aeriajs/common 0.0.53 → 0.0.55

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/error.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { EndpointError, EndpointErrorContent, RouteContext } from '@aeriajs/types';
2
- export declare const error: <TEndpointErrorContent extends EndpointErrorContent>(error: TEndpointErrorContent, context: Pick<RouteContext, 'response'>) => {
3
- readonly _tag: "Error";
4
- readonly error: TEndpointErrorContent;
1
+ import type { EndpointError, EndpointErrorContent } from '@aeriajs/types';
2
+ export declare const error: <const TEndpointErrorContent extends EndpointErrorContent>(value: TEndpointErrorContent) => EndpointError & {
3
+ value: TEndpointErrorContent;
5
4
  };
6
- export declare const isError: (object: any) => object is EndpointError<any>;
5
+ export declare const isError: <TEndpointErrorContent extends EndpointErrorContent>(object: EndpointError<TEndpointErrorContent> | any) => object is EndpointError<TEndpointErrorContent>;
6
+ export declare const unwrapError: <TEndpointErrorContent extends EndpointErrorContent>(error: EndpointError<TEndpointErrorContent>) => TEndpointErrorContent;
package/dist/error.js CHANGED
@@ -1,18 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isError = exports.error = void 0;
4
- const error = (error, context) => {
5
- const { httpStatus = 500 } = error;
6
- context.response.writeHead(httpStatus, {
7
- 'content-type': 'application/json',
8
- });
9
- return {
3
+ exports.unwrapError = exports.isError = exports.error = void 0;
4
+ const types_1 = require("@aeriajs/types");
5
+ const error = (value) => {
6
+ const wrappedError = {
7
+ [types_1.ERROR_SYMBOL]: true,
10
8
  _tag: 'Error',
11
- error,
9
+ value,
12
10
  };
11
+ return wrappedError;
13
12
  };
14
13
  exports.error = error;
15
14
  const isError = (object) => {
16
- return object._tag === 'Error';
15
+ return object
16
+ && typeof object === 'object'
17
+ && (types_1.ERROR_SYMBOL in object || types_1.ERROR_SYMBOL_DESCRIPTION in object);
17
18
  };
18
19
  exports.isError = isError;
20
+ const unwrapError = (error) => {
21
+ return error.value;
22
+ };
23
+ exports.unwrapError = unwrapError;
package/dist/error.mjs CHANGED
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
- export const error = (error2, context) => {
3
- const { httpStatus = 500 } = error2;
4
- context.response.writeHead(httpStatus, {
5
- "content-type": "application/json"
6
- });
7
- return {
2
+ import { ERROR_SYMBOL, ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
3
+ export const error = (value) => {
4
+ const wrappedError = {
5
+ [ERROR_SYMBOL]: true,
8
6
  _tag: "Error",
9
- error: error2
7
+ value
10
8
  };
9
+ return wrappedError;
11
10
  };
12
11
  export const isError = (object) => {
13
- return object._tag === "Error";
12
+ return object && typeof object === "object" && (ERROR_SYMBOL in object || ERROR_SYMBOL_DESCRIPTION in object);
13
+ };
14
+ export const unwrapError = (error2) => {
15
+ return error2.value;
14
16
  };
package/dist/pipe.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export type PipeOptions = {
2
- returnFirst?: boolean | ((value: any) => boolean);
2
+ returnFirst?: boolean | ((value: any) => any);
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<true | ReturnType<TFunction>>;
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<any>;
package/dist/pipe.js CHANGED
@@ -11,7 +11,7 @@ const pipe = (functions, options) => {
11
11
  switch (typeof returnFirst) {
12
12
  case 'function': {
13
13
  const result = returnFirst(ret);
14
- if (result) {
14
+ if (result !== undefined) {
15
15
  return result;
16
16
  }
17
17
  break;
package/dist/pipe.mjs CHANGED
@@ -9,7 +9,7 @@ export const pipe = (functions, options) => {
9
9
  switch (typeof returnFirst) {
10
10
  case "function": {
11
11
  const result = returnFirst(ret);
12
- if (result) {
12
+ if (result !== void 0) {
13
13
  return result;
14
14
  }
15
15
  break;
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Property, ObjectToSchema, EndpointErrorContent } from '@aeriajs/types';
1
+ import type { Property, ObjectToSchema, HTTPStatus } from '@aeriajs/types';
2
2
  export declare const fromLiteral: <const TObject, TRequired extends (keyof TObject & string)[]>(object: TObject, required?: TRequired) => ObjectToSchema<TObject, TRequired>;
3
3
  export declare const leftSchema: <const TObject extends Property>(object: TObject) => {
4
4
  readonly type: "object";
@@ -18,17 +18,30 @@ export declare const rightSchema: <const TObject extends Property>(object: TObje
18
18
  readonly value: Property;
19
19
  };
20
20
  };
21
- export declare const endpointErrorSchema: (error: EndpointErrorContent) => {
21
+ export declare const endpointErrorSchema: <THTTPStatus extends HTTPStatus[], TCode extends string[]>(error: {
22
+ httpStatus: THTTPStatus;
23
+ code: TCode;
24
+ }) => {
22
25
  readonly type: "object";
23
26
  readonly properties: {
24
- readonly httpCode: {
25
- readonly const: string;
26
- };
27
- readonly code: {
28
- readonly const: string;
29
- };
30
- readonly message: {
31
- readonly const: string;
27
+ readonly value: {
28
+ readonly type: "object";
29
+ readonly required: readonly ["httpStatus", "code"];
30
+ readonly properties: {
31
+ readonly httpStatus: {
32
+ readonly enum: THTTPStatus;
33
+ };
34
+ readonly code: {
35
+ readonly enum: TCode;
36
+ };
37
+ readonly message: {
38
+ readonly type: "string";
39
+ };
40
+ readonly details: {
41
+ readonly type: "object";
42
+ readonly variable: true;
43
+ };
44
+ };
32
45
  };
33
46
  };
34
47
  };
package/dist/schema.js CHANGED
@@ -76,14 +76,27 @@ const endpointErrorSchema = (error) => {
76
76
  return {
77
77
  type: 'object',
78
78
  properties: {
79
- httpCode: {
80
- const: error.code,
81
- },
82
- code: {
83
- const: error.code,
84
- },
85
- message: {
86
- const: error.message,
79
+ value: {
80
+ type: 'object',
81
+ required: [
82
+ 'httpStatus',
83
+ 'code',
84
+ ],
85
+ properties: {
86
+ httpStatus: {
87
+ enum: error.httpStatus,
88
+ },
89
+ code: {
90
+ enum: error.code,
91
+ },
92
+ message: {
93
+ type: 'string',
94
+ },
95
+ details: {
96
+ type: 'object',
97
+ variable: true,
98
+ },
99
+ },
87
100
  },
88
101
  },
89
102
  };
package/dist/schema.mjs CHANGED
@@ -71,14 +71,27 @@ export const endpointErrorSchema = (error) => {
71
71
  return {
72
72
  type: "object",
73
73
  properties: {
74
- httpCode: {
75
- const: error.code
76
- },
77
- code: {
78
- const: error.code
79
- },
80
- message: {
81
- const: error.message
74
+ value: {
75
+ type: "object",
76
+ required: [
77
+ "httpStatus",
78
+ "code"
79
+ ],
80
+ properties: {
81
+ httpStatus: {
82
+ enum: error.httpStatus
83
+ },
84
+ code: {
85
+ enum: error.code
86
+ },
87
+ message: {
88
+ type: "string"
89
+ },
90
+ details: {
91
+ type: "object",
92
+ variable: true
93
+ }
94
+ }
82
95
  }
83
96
  }
84
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/common",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
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.50",
34
+ "@aeriajs/types": "^0.0.52",
35
35
  "bson": "^6.5.0"
36
36
  },
37
37
  "scripts": {