@twin.org/api-models 0.0.1-next.32 → 0.0.1-next.34

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.
@@ -45,18 +45,17 @@ class HttpErrorHelper {
45
45
  // types then set the http response code accordingly
46
46
  const flattened = core.BaseError.flatten(error);
47
47
  let httpStatusCode = web.HttpStatusCode.internalServerError;
48
- if (flattened.some(e => core.BaseError.isErrorName(e, core.GuardError.CLASS_NAME))) {
48
+ if (flattened.some(e => core.BaseError.isErrorName(e, core.GuardError.CLASS_NAME)) ||
49
+ flattened.some(e => core.BaseError.isErrorName(e, core.ValidationError.CLASS_NAME))) {
49
50
  httpStatusCode = web.HttpStatusCode.badRequest;
50
51
  }
51
- else if (flattened.some(e => core.BaseError.isErrorName(e, core.ConflictError.CLASS_NAME))) {
52
+ else if (flattened.some(e => core.BaseError.isErrorName(e, core.ConflictError.CLASS_NAME)) ||
53
+ flattened.some(e => core.BaseError.isErrorName(e, core.AlreadyExistsError.CLASS_NAME))) {
52
54
  httpStatusCode = web.HttpStatusCode.conflict;
53
55
  }
54
56
  else if (flattened.some(e => core.BaseError.isErrorName(e, core.NotFoundError.CLASS_NAME))) {
55
57
  httpStatusCode = web.HttpStatusCode.notFound;
56
58
  }
57
- else if (flattened.some(e => core.BaseError.isErrorName(e, core.AlreadyExistsError.CLASS_NAME))) {
58
- httpStatusCode = web.HttpStatusCode.conflict;
59
- }
60
59
  else if (flattened.some(e => core.BaseError.isErrorName(e, core.UnauthorizedError.CLASS_NAME))) {
61
60
  httpStatusCode = web.HttpStatusCode.unauthorized;
62
61
  }
@@ -1,4 +1,4 @@
1
- import { Factory, BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
1
+ import { Factory, BaseError, GuardError, ValidationError, ConflictError, AlreadyExistsError, NotFoundError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
2
2
  import { HttpStatusCode, MimeTypes, HeaderTypes } from '@twin.org/web';
3
3
 
4
4
  // Copyright 2024 IOTA Stiftung.
@@ -43,18 +43,17 @@ class HttpErrorHelper {
43
43
  // types then set the http response code accordingly
44
44
  const flattened = BaseError.flatten(error);
45
45
  let httpStatusCode = HttpStatusCode.internalServerError;
46
- if (flattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME))) {
46
+ if (flattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME)) ||
47
+ flattened.some(e => BaseError.isErrorName(e, ValidationError.CLASS_NAME))) {
47
48
  httpStatusCode = HttpStatusCode.badRequest;
48
49
  }
49
- else if (flattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME))) {
50
+ else if (flattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME)) ||
51
+ flattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))) {
50
52
  httpStatusCode = HttpStatusCode.conflict;
51
53
  }
52
54
  else if (flattened.some(e => BaseError.isErrorName(e, NotFoundError.CLASS_NAME))) {
53
55
  httpStatusCode = HttpStatusCode.notFound;
54
56
  }
55
- else if (flattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))) {
56
- httpStatusCode = HttpStatusCode.conflict;
57
- }
58
57
  else if (flattened.some(e => BaseError.isErrorName(e, UnauthorizedError.CLASS_NAME))) {
59
58
  httpStatusCode = HttpStatusCode.unauthorized;
60
59
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @twin.org/api-models - Changelog
2
2
 
3
+ ## [0.0.1-next.34](https://github.com/twinfoundation/api/compare/api-models-v0.0.1-next.33...api-models-v0.0.1-next.34) (2025-05-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * validationError mapped to http status badrequest ([adc5eb1](https://github.com/twinfoundation/api/commit/adc5eb11d987abb0ab9f7e0dc8e1fdae207e436e))
9
+
10
+ ## [0.0.1-next.33](https://github.com/twinfoundation/api/compare/api-models-v0.0.1-next.32...api-models-v0.0.1-next.33) (2025-04-17)
11
+
12
+
13
+ ### Features
14
+
15
+ * use shared store mechanism ([#19](https://github.com/twinfoundation/api/issues/19)) ([32116df](https://github.com/twinfoundation/api/commit/32116df3b4380a30137f5056f242a5c99afa2df9))
16
+
3
17
  ## [0.0.1-next.32](https://github.com/twinfoundation/api/compare/api-models-v0.0.1-next.31...api-models-v0.0.1-next.32) (2025-03-28)
4
18
 
5
19
 
@@ -4,19 +4,19 @@ Class to help with processing http errors.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new HttpErrorHelper()
7
+ ### Constructor
8
8
 
9
- > **new HttpErrorHelper**(): [`HttpErrorHelper`](HttpErrorHelper.md)
9
+ > **new HttpErrorHelper**(): `HttpErrorHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`HttpErrorHelper`](HttpErrorHelper.md)
13
+ `HttpErrorHelper`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### processError()
18
18
 
19
- > `static` **processError**(`err`, `includeStack`?): `object`
19
+ > `static` **processError**(`err`, `includeStack?`): `object`
20
20
 
21
21
  Process the errors from the routes.
22
22
 
@@ -4,25 +4,27 @@ Class to help with handling http parameters.
4
4
 
5
5
  ## Constructors
6
6
 
7
- ### new HttpParameterHelper()
7
+ ### Constructor
8
8
 
9
- > **new HttpParameterHelper**(): [`HttpParameterHelper`](HttpParameterHelper.md)
9
+ > **new HttpParameterHelper**(): `HttpParameterHelper`
10
10
 
11
11
  #### Returns
12
12
 
13
- [`HttpParameterHelper`](HttpParameterHelper.md)
13
+ `HttpParameterHelper`
14
14
 
15
15
  ## Methods
16
16
 
17
17
  ### arrayFromString()
18
18
 
19
- > `static` **arrayFromString**\<`T`\>(`values`?): `undefined` \| `T`[]
19
+ > `static` **arrayFromString**\<`T`\>(`values?`): `undefined` \| `T`[]
20
20
 
21
21
  Convert list query to array.
22
22
 
23
23
  #### Type Parameters
24
24
 
25
- **T** = `string`
25
+ ##### T
26
+
27
+ `T` = `string`
26
28
 
27
29
  #### Parameters
28
30
 
@@ -42,13 +44,15 @@ The array of values.
42
44
 
43
45
  ### arrayToString()
44
46
 
45
- > `static` **arrayToString**\<`T`\>(`values`?): `undefined` \| `string`
47
+ > `static` **arrayToString**\<`T`\>(`values?`): `undefined` \| `string`
46
48
 
47
49
  Convert array of values to query string.
48
50
 
49
51
  #### Type Parameters
50
52
 
51
- **T** = `string`
53
+ ##### T
54
+
55
+ `T` = `string`
52
56
 
53
57
  #### Parameters
54
58
 
@@ -68,13 +72,15 @@ The combined.
68
72
 
69
73
  ### objectFromString()
70
74
 
71
- > `static` **objectFromString**\<`T`\>(`value`?): `undefined` \| `T`
75
+ > `static` **objectFromString**\<`T`\>(`value?`): `undefined` \| `T`
72
76
 
73
77
  Convert object string to object.
74
78
 
75
79
  #### Type Parameters
76
80
 
77
- **T** = `unknown`
81
+ ##### T
82
+
83
+ `T` = `unknown`
78
84
 
79
85
  #### Parameters
80
86
 
@@ -94,13 +100,15 @@ The object.
94
100
 
95
101
  ### objectToString()
96
102
 
97
- > `static` **objectToString**\<`T`\>(`value`?): `undefined` \| `string`
103
+ > `static` **objectToString**\<`T`\>(`value?`): `undefined` \| `string`
98
104
 
99
105
  Convert object to query string.
100
106
 
101
107
  #### Type Parameters
102
108
 
103
- **T** = `unknown`
109
+ ##### T
110
+
111
+ `T` = `unknown`
104
112
 
105
113
  #### Parameters
106
114
 
@@ -4,7 +4,9 @@ Route entry points are used for exposing the routes from a package.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T**
7
+ ### T
8
+
9
+ `T`
8
10
 
9
11
  ## Properties
10
12
 
@@ -13,7 +13,9 @@ The definition for a base processor for handling REST routes.
13
13
 
14
14
  ## Type Parameters
15
15
 
16
- **T** = [`IBaseRoute`](IBaseRoute.md)
16
+ ### T
17
+
18
+ `T` = [`IBaseRoute`](IBaseRoute.md)
17
19
 
18
20
  ## Methods
19
21
 
@@ -9,7 +9,9 @@ Model for the standard parameters for an http request.
9
9
 
10
10
  ## Type Parameters
11
11
 
12
- **T** = `any`
12
+ ### T
13
+
14
+ `T` = `any`
13
15
 
14
16
  ## Properties
15
17
 
@@ -4,7 +4,9 @@ Model for the standard parameters for an http response.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T** = `any`
7
+ ### T
8
+
9
+ `T` = `any`
8
10
 
9
11
  ## Properties
10
12
 
@@ -8,7 +8,9 @@ Model for the standard parameters for an http request.
8
8
 
9
9
  ## Type Parameters
10
10
 
11
- **T** = `any`
11
+ ### T
12
+
13
+ `T` = `any`
12
14
 
13
15
  ## Properties
14
16
 
@@ -52,7 +52,7 @@ The service health.
52
52
 
53
53
  ### setComponentHealth()
54
54
 
55
- > **setComponentHealth**(`name`, `status`, `details`?): `Promise`\<`void`\>
55
+ > **setComponentHealth**(`name`, `status`, `details?`): `Promise`\<`void`\>
56
56
 
57
57
  Set the status of a component.
58
58
 
@@ -8,9 +8,13 @@ Interface which defines a REST route.
8
8
 
9
9
  ## Type Parameters
10
10
 
11
- **T** *extends* [`IHttpRequest`](IHttpRequest.md) = `any`
11
+ ### T
12
12
 
13
- **U** *extends* [`IHttpResponse`](IHttpResponse.md) & [`IRestRouteResponseOptions`](IRestRouteResponseOptions.md) = `any`
13
+ `T` *extends* [`IHttpRequest`](IHttpRequest.md) = `any`
14
+
15
+ ### U
16
+
17
+ `U` *extends* [`IHttpResponse`](IHttpResponse.md) & [`IRestRouteResponseOptions`](IRestRouteResponseOptions.md) = `any`
14
18
 
15
19
  ## Properties
16
20
 
@@ -8,7 +8,9 @@ Interface which defines a REST route request example.
8
8
 
9
9
  ## Type Parameters
10
10
 
11
- **T**
11
+ ### T
12
+
13
+ `T`
12
14
 
13
15
  ## Properties
14
16
 
@@ -8,7 +8,9 @@ Interface which defines a REST route response example.
8
8
 
9
9
  ## Type Parameters
10
10
 
11
- **T**
11
+ ### T
12
+
13
+ `T`
12
14
 
13
15
  ## Properties
14
16
 
@@ -8,9 +8,13 @@ Interface which defines a socket route.
8
8
 
9
9
  ## Type Parameters
10
10
 
11
- **T** *extends* [`IHttpRequest`](IHttpRequest.md) = `any`
11
+ ### T
12
12
 
13
- **U** *extends* [`IHttpResponse`](IHttpResponse.md) = `any`
13
+ `T` *extends* [`IHttpRequest`](IHttpRequest.md) = `any`
14
+
15
+ ### U
16
+
17
+ `U` *extends* [`IHttpResponse`](IHttpResponse.md) = `any`
14
18
 
15
19
  ## Properties
16
20
 
@@ -4,7 +4,9 @@ Interface describing a web server.
4
4
 
5
5
  ## Type Parameters
6
6
 
7
- **T**
7
+ ### T
8
+
9
+ `T`
8
10
 
9
11
  ## Methods
10
12
 
@@ -24,7 +26,7 @@ The web server instance.
24
26
 
25
27
  ### build()
26
28
 
27
- > **build**(`restRouteProcessors`?, `restRoutes`?, `socketRouteProcessors`?, `socketRoutes`?, `options`?): `Promise`\<`void`\>
29
+ > **build**(`restRouteProcessors?`, `restRoutes?`, `socketRouteProcessors?`, `socketRoutes?`, `options?`): `Promise`\<`void`\>
28
30
 
29
31
  Build the server.
30
32
 
@@ -1,5 +1,5 @@
1
1
  # Type Alias: HealthStatus
2
2
 
3
- > **HealthStatus**: *typeof* [`HealthStatus`](../variables/HealthStatus.md)\[keyof *typeof* [`HealthStatus`](../variables/HealthStatus.md)\]
3
+ > **HealthStatus** = *typeof* [`HealthStatus`](../variables/HealthStatus.md)\[keyof *typeof* [`HealthStatus`](../variables/HealthStatus.md)\]
4
4
 
5
5
  The health status of the component.
@@ -1,5 +1,5 @@
1
1
  # Type Alias: IRestRouteEntryPoint
2
2
 
3
- > **IRestRouteEntryPoint**: [`IBaseRouteEntryPoint`](../interfaces/IBaseRouteEntryPoint.md)\<[`IRestRoute`](../interfaces/IRestRoute.md)\>
3
+ > **IRestRouteEntryPoint** = [`IBaseRouteEntryPoint`](../interfaces/IBaseRouteEntryPoint.md)\<[`IRestRoute`](../interfaces/IRestRoute.md)\>
4
4
 
5
5
  Route entry points are used for exposing the REST routes from a package.
@@ -1,5 +1,5 @@
1
1
  # Type Alias: ISocketRouteEntryPoint
2
2
 
3
- > **ISocketRouteEntryPoint**: [`IBaseRouteEntryPoint`](../interfaces/IBaseRouteEntryPoint.md)\<[`ISocketRoute`](../interfaces/ISocketRoute.md)\>
3
+ > **ISocketRouteEntryPoint** = [`IBaseRouteEntryPoint`](../interfaces/IBaseRouteEntryPoint.md)\<[`ISocketRoute`](../interfaces/ISocketRoute.md)\>
4
4
 
5
5
  Route entry points are used for exposing the socket routes from a package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-models",
3
- "version": "0.0.1-next.32",
3
+ "version": "0.0.1-next.34",
4
4
  "description": "Contains models and classes for use with APIs",
5
5
  "repository": {
6
6
  "type": "git",