@twin.org/api-models 0.0.1-next.1 → 0.0.1-next.10

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.
@@ -65,6 +65,46 @@ class HttpErrorHelper {
65
65
  }
66
66
  }
67
67
 
68
+ // Copyright 2024 IOTA Stiftung.
69
+ // SPDX-License-Identifier: Apache-2.0.
70
+ /**
71
+ * Class to help with handling http parameters.
72
+ */
73
+ class HttpParameterHelper {
74
+ /**
75
+ * Convert list query to array.
76
+ * @param values The values query string.
77
+ * @returns The array of values.
78
+ */
79
+ static arrayFromString(values) {
80
+ return values?.split(",");
81
+ }
82
+ /**
83
+ * Convert array of values to query string.
84
+ * @param values The values to combine string.
85
+ * @returns The combined.
86
+ */
87
+ static arrayToString(values) {
88
+ return values?.join(",");
89
+ }
90
+ /**
91
+ * Convert object string to object.
92
+ * @param value The value query string.
93
+ * @returns The object.
94
+ */
95
+ static objectFromString(value) {
96
+ return core.Is.json(value) ? JSON.parse(value) : undefined;
97
+ }
98
+ /**
99
+ * Convert object to query string.
100
+ * @param value The value to convert to a string.
101
+ * @returns The converted object.
102
+ */
103
+ static objectToString(value) {
104
+ return core.Is.empty(value) ? undefined : JSON.stringify(value);
105
+ }
106
+ }
107
+
68
108
  // Copyright 2024 IOTA Stiftung.
69
109
  // SPDX-License-Identifier: Apache-2.0.
70
110
  /**
@@ -88,3 +128,4 @@ const HealthStatus = {
88
128
 
89
129
  exports.HealthStatus = HealthStatus;
90
130
  exports.HttpErrorHelper = HttpErrorHelper;
131
+ exports.HttpParameterHelper = HttpParameterHelper;
@@ -1,4 +1,4 @@
1
- import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError } from '@twin.org/core';
1
+ import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
2
2
  import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
3
3
 
4
4
  // Copyright 2024 IOTA Stiftung.
@@ -63,6 +63,46 @@ class HttpErrorHelper {
63
63
  }
64
64
  }
65
65
 
66
+ // Copyright 2024 IOTA Stiftung.
67
+ // SPDX-License-Identifier: Apache-2.0.
68
+ /**
69
+ * Class to help with handling http parameters.
70
+ */
71
+ class HttpParameterHelper {
72
+ /**
73
+ * Convert list query to array.
74
+ * @param values The values query string.
75
+ * @returns The array of values.
76
+ */
77
+ static arrayFromString(values) {
78
+ return values?.split(",");
79
+ }
80
+ /**
81
+ * Convert array of values to query string.
82
+ * @param values The values to combine string.
83
+ * @returns The combined.
84
+ */
85
+ static arrayToString(values) {
86
+ return values?.join(",");
87
+ }
88
+ /**
89
+ * Convert object string to object.
90
+ * @param value The value query string.
91
+ * @returns The object.
92
+ */
93
+ static objectFromString(value) {
94
+ return Is.json(value) ? JSON.parse(value) : undefined;
95
+ }
96
+ /**
97
+ * Convert object to query string.
98
+ * @param value The value to convert to a string.
99
+ * @returns The converted object.
100
+ */
101
+ static objectToString(value) {
102
+ return Is.empty(value) ? undefined : JSON.stringify(value);
103
+ }
104
+ }
105
+
66
106
  // Copyright 2024 IOTA Stiftung.
67
107
  // SPDX-License-Identifier: Apache-2.0.
68
108
  /**
@@ -84,4 +124,4 @@ const HealthStatus = {
84
124
  Error: "error"
85
125
  };
86
126
 
87
- export { HealthStatus, HttpErrorHelper };
127
+ export { HealthStatus, HttpErrorHelper, HttpParameterHelper };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Class to help with handling http parameters.
3
+ */
4
+ export declare class HttpParameterHelper {
5
+ /**
6
+ * Convert list query to array.
7
+ * @param values The values query string.
8
+ * @returns The array of values.
9
+ */
10
+ static arrayFromString<T = string>(values?: string): T[] | undefined;
11
+ /**
12
+ * Convert array of values to query string.
13
+ * @param values The values to combine string.
14
+ * @returns The combined.
15
+ */
16
+ static arrayToString<T = string>(values?: T[]): string | undefined;
17
+ /**
18
+ * Convert object string to object.
19
+ * @param value The value query string.
20
+ * @returns The object.
21
+ */
22
+ static objectFromString<T = unknown>(value?: string): T | undefined;
23
+ /**
24
+ * Convert object to query string.
25
+ * @param value The value to convert to a string.
26
+ * @returns The converted object.
27
+ */
28
+ static objectToString<T = unknown>(value?: T): string | undefined;
29
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./helpers/httpErrorHelper";
2
+ export * from "./helpers/httpParameterHelper";
2
3
  export * from "./models/api/IServerHealthResponse";
3
4
  export * from "./models/api/IServerInfoResponse";
4
5
  export * from "./models/api/IServerSpecResponse";
@@ -26,7 +27,10 @@ export * from "./models/responses/success/IOkResponse";
26
27
  export * from "./models/routes/IBaseRoute";
27
28
  export * from "./models/routes/IRestRoute";
28
29
  export * from "./models/routes/IRestRouteEntryPoint";
30
+ export * from "./models/routes/IRestRouteExample";
31
+ export * from "./models/routes/IRestRouteRequestExample";
29
32
  export * from "./models/routes/IRestRouteResponseAttachmentOptions";
33
+ export * from "./models/routes/IRestRouteResponseExample";
30
34
  export * from "./models/routes/IRestRouteResponseOptions";
31
35
  export * from "./models/routes/ISocketRoute";
32
36
  export * from "./models/routes/ITag";
@@ -1,5 +1,7 @@
1
1
  import type { HttpMethod } from "@twin.org/web";
2
2
  import type { IBaseRoute } from "./IBaseRoute";
3
+ import type { IRestRouteRequestExample } from "./IRestRouteRequestExample";
4
+ import type { IRestRouteResponseExample } from "./IRestRouteResponseExample";
3
5
  import type { IRestRouteResponseOptions } from "./IRestRouteResponseOptions";
4
6
  import type { IHttpRequest } from "../protocol/IHttpRequest";
5
7
  import type { IHttpRequestContext } from "../protocol/IHttpRequestContext";
@@ -47,11 +49,7 @@ export interface IRestRoute<T extends IHttpRequest = any, U extends IHttpRespons
47
49
  /**
48
50
  * Example objects for the request.
49
51
  */
50
- examples?: {
51
- id: string;
52
- description?: string;
53
- request: T;
54
- }[];
52
+ examples?: IRestRouteRequestExample<T>[];
55
53
  };
56
54
  /**
57
55
  * The type of the response object.
@@ -68,11 +66,7 @@ export interface IRestRoute<T extends IHttpRequest = any, U extends IHttpRespons
68
66
  /**
69
67
  * Example objects of the response.
70
68
  */
71
- examples?: {
72
- id: string;
73
- description?: string;
74
- response: U;
75
- }[];
69
+ examples?: IRestRouteResponseExample<U>[];
76
70
  }[];
77
71
  /**
78
72
  * Exclude the route from being included in the spec file.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Interface which defines a REST route example.
3
+ */
4
+ export interface IRestRouteExample {
5
+ /**
6
+ * Example objects for the request.
7
+ */
8
+ id: string;
9
+ /**
10
+ * Description of the example.
11
+ */
12
+ description?: string;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { IRestRouteExample } from "./IRestRouteExample";
2
+ /**
3
+ * Interface which defines a REST route request example.
4
+ */
5
+ export interface IRestRouteRequestExample<T> extends IRestRouteExample {
6
+ /**
7
+ * The example request object.
8
+ */
9
+ request: T;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { IRestRouteExample } from "./IRestRouteExample";
2
+ /**
3
+ * Interface which defines a REST route response example.
4
+ */
5
+ export interface IRestRouteResponseExample<T> extends IRestRouteExample {
6
+ /**
7
+ * The example response object.
8
+ */
9
+ response: T;
10
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/api-models - Changelog
2
2
 
3
- ## v0.0.1
3
+ ## v0.0.1-next.10
4
4
 
5
5
  - Initial Release
@@ -0,0 +1,109 @@
1
+ # Class: HttpParameterHelper
2
+
3
+ Class to help with handling http parameters.
4
+
5
+ ## Constructors
6
+
7
+ ### new HttpParameterHelper()
8
+
9
+ > **new HttpParameterHelper**(): [`HttpParameterHelper`](HttpParameterHelper.md)
10
+
11
+ #### Returns
12
+
13
+ [`HttpParameterHelper`](HttpParameterHelper.md)
14
+
15
+ ## Methods
16
+
17
+ ### arrayFromString()
18
+
19
+ > `static` **arrayFromString**\<`T`\>(`values`?): `undefined` \| `T`[]
20
+
21
+ Convert list query to array.
22
+
23
+ #### Type Parameters
24
+
25
+ • **T** = `string`
26
+
27
+ #### Parameters
28
+
29
+ • **values?**: `string`
30
+
31
+ The values query string.
32
+
33
+ #### Returns
34
+
35
+ `undefined` \| `T`[]
36
+
37
+ The array of values.
38
+
39
+ ***
40
+
41
+ ### arrayToString()
42
+
43
+ > `static` **arrayToString**\<`T`\>(`values`?): `undefined` \| `string`
44
+
45
+ Convert array of values to query string.
46
+
47
+ #### Type Parameters
48
+
49
+ • **T** = `string`
50
+
51
+ #### Parameters
52
+
53
+ • **values?**: `T`[]
54
+
55
+ The values to combine string.
56
+
57
+ #### Returns
58
+
59
+ `undefined` \| `string`
60
+
61
+ The combined.
62
+
63
+ ***
64
+
65
+ ### objectFromString()
66
+
67
+ > `static` **objectFromString**\<`T`\>(`value`?): `undefined` \| `T`
68
+
69
+ Convert object string to object.
70
+
71
+ #### Type Parameters
72
+
73
+ • **T** = `unknown`
74
+
75
+ #### Parameters
76
+
77
+ • **value?**: `string`
78
+
79
+ The value query string.
80
+
81
+ #### Returns
82
+
83
+ `undefined` \| `T`
84
+
85
+ The object.
86
+
87
+ ***
88
+
89
+ ### objectToString()
90
+
91
+ > `static` **objectToString**\<`T`\>(`value`?): `undefined` \| `string`
92
+
93
+ Convert object to query string.
94
+
95
+ #### Type Parameters
96
+
97
+ • **T** = `unknown`
98
+
99
+ #### Parameters
100
+
101
+ • **value?**: `T`
102
+
103
+ The value to convert to a string.
104
+
105
+ #### Returns
106
+
107
+ `undefined` \| `string`
108
+
109
+ The converted object.
@@ -3,6 +3,7 @@
3
3
  ## Classes
4
4
 
5
5
  - [HttpErrorHelper](classes/HttpErrorHelper.md)
6
+ - [HttpParameterHelper](classes/HttpParameterHelper.md)
6
7
 
7
8
  ## Interfaces
8
9
 
@@ -33,7 +34,10 @@
33
34
  - [IBaseRoute](interfaces/IBaseRoute.md)
34
35
  - [IRestRoute](interfaces/IRestRoute.md)
35
36
  - [IRestRouteEntryPoint](interfaces/IRestRouteEntryPoint.md)
37
+ - [IRestRouteExample](interfaces/IRestRouteExample.md)
38
+ - [IRestRouteRequestExample](interfaces/IRestRouteRequestExample.md)
36
39
  - [IRestRouteResponseAttachmentOptions](interfaces/IRestRouteResponseAttachmentOptions.md)
40
+ - [IRestRouteResponseExample](interfaces/IRestRouteResponseExample.md)
37
41
  - [IRestRouteResponseOptions](interfaces/IRestRouteResponseOptions.md)
38
42
  - [ISocketRoute](interfaces/ISocketRoute.md)
39
43
  - [ITag](interfaces/ITag.md)
@@ -18,8 +18,8 @@ Response status code.
18
18
 
19
19
  Additional response headers.
20
20
 
21
- #### Location
21
+ #### location
22
22
 
23
- > **Location**: `string`
23
+ > **location**: `string`
24
24
 
25
25
  The location where the resource was created.
@@ -116,7 +116,7 @@ The mime type of the request, defaults to "application/json" if there is a body.
116
116
 
117
117
  #### examples?
118
118
 
119
- > `optional` **examples**: `object`[]
119
+ > `optional` **examples**: [`IRestRouteRequestExample`](IRestRouteRequestExample.md)\<`T`\>[]
120
120
 
121
121
  Example objects for the request.
122
122
 
@@ -0,0 +1,24 @@
1
+ # Interface: IRestRouteExample
2
+
3
+ Interface which defines a REST route example.
4
+
5
+ ## Extended by
6
+
7
+ - [`IRestRouteRequestExample`](IRestRouteRequestExample.md)
8
+ - [`IRestRouteResponseExample`](IRestRouteResponseExample.md)
9
+
10
+ ## Properties
11
+
12
+ ### id
13
+
14
+ > **id**: `string`
15
+
16
+ Example objects for the request.
17
+
18
+ ***
19
+
20
+ ### description?
21
+
22
+ > `optional` **description**: `string`
23
+
24
+ Description of the example.
@@ -0,0 +1,43 @@
1
+ # Interface: IRestRouteRequestExample\<T\>
2
+
3
+ Interface which defines a REST route request example.
4
+
5
+ ## Extends
6
+
7
+ - [`IRestRouteExample`](IRestRouteExample.md)
8
+
9
+ ## Type Parameters
10
+
11
+ • **T**
12
+
13
+ ## Properties
14
+
15
+ ### id
16
+
17
+ > **id**: `string`
18
+
19
+ Example objects for the request.
20
+
21
+ #### Inherited from
22
+
23
+ [`IRestRouteExample`](IRestRouteExample.md).[`id`](IRestRouteExample.md#id)
24
+
25
+ ***
26
+
27
+ ### description?
28
+
29
+ > `optional` **description**: `string`
30
+
31
+ Description of the example.
32
+
33
+ #### Inherited from
34
+
35
+ [`IRestRouteExample`](IRestRouteExample.md).[`description`](IRestRouteExample.md#description)
36
+
37
+ ***
38
+
39
+ ### request
40
+
41
+ > **request**: `T`
42
+
43
+ The example request object.
@@ -0,0 +1,43 @@
1
+ # Interface: IRestRouteResponseExample\<T\>
2
+
3
+ Interface which defines a REST route response example.
4
+
5
+ ## Extends
6
+
7
+ - [`IRestRouteExample`](IRestRouteExample.md)
8
+
9
+ ## Type Parameters
10
+
11
+ • **T**
12
+
13
+ ## Properties
14
+
15
+ ### id
16
+
17
+ > **id**: `string`
18
+
19
+ Example objects for the request.
20
+
21
+ #### Inherited from
22
+
23
+ [`IRestRouteExample`](IRestRouteExample.md).[`id`](IRestRouteExample.md#id)
24
+
25
+ ***
26
+
27
+ ### description?
28
+
29
+ > `optional` **description**: `string`
30
+
31
+ Description of the example.
32
+
33
+ #### Inherited from
34
+
35
+ [`IRestRouteExample`](IRestRouteExample.md).[`description`](IRestRouteExample.md#description)
36
+
37
+ ***
38
+
39
+ ### response
40
+
41
+ > **response**: `T`
42
+
43
+ The example response object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-models",
3
- "version": "0.0.1-next.1",
3
+ "version": "0.0.1-next.10",
4
4
  "description": "Contains models and classes for use with APIs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,38 +13,11 @@
13
13
  "engines": {
14
14
  "node": ">=20.0.0"
15
15
  },
16
- "scripts": {
17
- "clean": "rimraf dist coverage",
18
- "build": "tspc",
19
- "test": "vitest --run --config ./vitest.config.ts --no-cache",
20
- "coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
21
- "bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
22
- "bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
23
- "bundle": "npm run bundle:esm && npm run bundle:cjs",
24
- "docs:clean": "rimraf docs/reference",
25
- "docs:generate": "typedoc",
26
- "docs": "npm run docs:clean && npm run docs:generate",
27
- "dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
28
- },
29
16
  "dependencies": {
30
17
  "@twin.org/core": "next",
31
18
  "@twin.org/nameof": "next",
32
19
  "@twin.org/web": "next"
33
20
  },
34
- "devDependencies": {
35
- "@twin.org/nameof-transformer": "next",
36
- "@vitest/coverage-v8": "2.1.1",
37
- "@types/node": "22.5.5",
38
- "copyfiles": "2.4.1",
39
- "rimraf": "6.0.1",
40
- "rollup": "4.21.3",
41
- "rollup-plugin-typescript2": "0.36.0",
42
- "ts-patch": "3.2.1",
43
- "typedoc": "0.26.7",
44
- "typedoc-plugin-markdown": "4.2.7",
45
- "typescript": "5.6.2",
46
- "vitest": "2.1.1"
47
- },
48
21
  "main": "./dist/cjs/index.cjs",
49
22
  "module": "./dist/esm/index.mjs",
50
23
  "types": "./dist/types/index.d.ts",