@twin.org/api-models 0.0.1-next.5 → 0.0.1-next.8

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.
@@ -121,6 +121,39 @@ class HttpParameterHelper {
121
121
  return conditionsList.join(",");
122
122
  }
123
123
  }
124
+ /**
125
+ * Convert the sort string to a list of sort properties.
126
+ * @param sortProperties The sort properties query string.
127
+ * @returns The list of sort properties.
128
+ */
129
+ static sortPropertiesFromString(sortProperties) {
130
+ const sortParts = sortProperties?.split(",") ?? [];
131
+ const sortPropertyList = [];
132
+ for (const conditionPart of sortParts) {
133
+ const parts = conditionPart.split("|");
134
+ if (parts.length === 2) {
135
+ sortPropertyList.push({
136
+ property: parts[0],
137
+ sortDirection: parts[1]
138
+ });
139
+ }
140
+ }
141
+ return sortPropertyList.length === 0 ? undefined : sortPropertyList;
142
+ }
143
+ /**
144
+ * Convert the sort properties to a string parameter.
145
+ * @param sortProperties The sort properties to convert.
146
+ * @returns The string version of the sort properties.
147
+ */
148
+ static sortPropertiesToString(sortProperties) {
149
+ if (core.Is.arrayValue(sortProperties)) {
150
+ const sortPropertyList = [];
151
+ for (const conditionPart of sortProperties) {
152
+ sortPropertyList.push(`${conditionPart.property}|${conditionPart.sortDirection}`);
153
+ }
154
+ return sortPropertyList.join(",");
155
+ }
156
+ }
124
157
  }
125
158
 
126
159
  // Copyright 2024 IOTA Stiftung.
@@ -119,6 +119,39 @@ class HttpParameterHelper {
119
119
  return conditionsList.join(",");
120
120
  }
121
121
  }
122
+ /**
123
+ * Convert the sort string to a list of sort properties.
124
+ * @param sortProperties The sort properties query string.
125
+ * @returns The list of sort properties.
126
+ */
127
+ static sortPropertiesFromString(sortProperties) {
128
+ const sortParts = sortProperties?.split(",") ?? [];
129
+ const sortPropertyList = [];
130
+ for (const conditionPart of sortParts) {
131
+ const parts = conditionPart.split("|");
132
+ if (parts.length === 2) {
133
+ sortPropertyList.push({
134
+ property: parts[0],
135
+ sortDirection: parts[1]
136
+ });
137
+ }
138
+ }
139
+ return sortPropertyList.length === 0 ? undefined : sortPropertyList;
140
+ }
141
+ /**
142
+ * Convert the sort properties to a string parameter.
143
+ * @param sortProperties The sort properties to convert.
144
+ * @returns The string version of the sort properties.
145
+ */
146
+ static sortPropertiesToString(sortProperties) {
147
+ if (Is.arrayValue(sortProperties)) {
148
+ const sortPropertyList = [];
149
+ for (const conditionPart of sortProperties) {
150
+ sortPropertyList.push(`${conditionPart.property}|${conditionPart.sortDirection}`);
151
+ }
152
+ return sortPropertyList.join(",");
153
+ }
154
+ }
122
155
  }
123
156
 
124
157
  // Copyright 2024 IOTA Stiftung.
@@ -1,4 +1,4 @@
1
- import type { IComparator } from "@twin.org/entity";
1
+ import type { IComparator, SortDirection } from "@twin.org/entity";
2
2
  /**
3
3
  * Class to help with handling http parameters.
4
4
  */
@@ -27,4 +27,22 @@ export declare class HttpParameterHelper {
27
27
  * @returns The string version of the comparators.
28
28
  */
29
29
  static conditionsToString(conditions?: IComparator[]): string | undefined;
30
+ /**
31
+ * Convert the sort string to a list of sort properties.
32
+ * @param sortProperties The sort properties query string.
33
+ * @returns The list of sort properties.
34
+ */
35
+ static sortPropertiesFromString<T = unknown>(sortProperties?: string): {
36
+ property: keyof T;
37
+ sortDirection: SortDirection;
38
+ }[] | undefined;
39
+ /**
40
+ * Convert the sort properties to a string parameter.
41
+ * @param sortProperties The sort properties to convert.
42
+ * @returns The string version of the sort properties.
43
+ */
44
+ static sortPropertiesToString<T = unknown>(sortProperties?: {
45
+ property: keyof T;
46
+ sortDirection: SortDirection;
47
+ }[]): string | undefined;
30
48
  }
@@ -27,7 +27,10 @@ export * from "./models/responses/success/IOkResponse";
27
27
  export * from "./models/routes/IBaseRoute";
28
28
  export * from "./models/routes/IRestRoute";
29
29
  export * from "./models/routes/IRestRouteEntryPoint";
30
+ export * from "./models/routes/IRestRouteExample";
31
+ export * from "./models/routes/IRestRouteRequestExample";
30
32
  export * from "./models/routes/IRestRouteResponseAttachmentOptions";
33
+ export * from "./models/routes/IRestRouteResponseExample";
31
34
  export * from "./models/routes/IRestRouteResponseOptions";
32
35
  export * from "./models/routes/ISocketRoute";
33
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-next.5
3
+ ## v0.0.1-next.8
4
4
 
5
5
  - Initial Release
@@ -99,3 +99,51 @@ The conditions to convert.
99
99
  `undefined` \| `string`
100
100
 
101
101
  The string version of the comparators.
102
+
103
+ ***
104
+
105
+ ### sortPropertiesFromString()
106
+
107
+ > `static` **sortPropertiesFromString**\<`T`\>(`sortProperties`?): `undefined` \| `object`[]
108
+
109
+ Convert the sort string to a list of sort properties.
110
+
111
+ #### Type Parameters
112
+
113
+ • **T** = `unknown`
114
+
115
+ #### Parameters
116
+
117
+ • **sortProperties?**: `string`
118
+
119
+ The sort properties query string.
120
+
121
+ #### Returns
122
+
123
+ `undefined` \| `object`[]
124
+
125
+ The list of sort properties.
126
+
127
+ ***
128
+
129
+ ### sortPropertiesToString()
130
+
131
+ > `static` **sortPropertiesToString**\<`T`\>(`sortProperties`?): `undefined` \| `string`
132
+
133
+ Convert the sort properties to a string parameter.
134
+
135
+ #### Type Parameters
136
+
137
+ • **T** = `unknown`
138
+
139
+ #### Parameters
140
+
141
+ • **sortProperties?**: `object`[]
142
+
143
+ The sort properties to convert.
144
+
145
+ #### Returns
146
+
147
+ `undefined` \| `string`
148
+
149
+ The string version of the sort properties.
@@ -34,7 +34,10 @@
34
34
  - [IBaseRoute](interfaces/IBaseRoute.md)
35
35
  - [IRestRoute](interfaces/IRestRoute.md)
36
36
  - [IRestRouteEntryPoint](interfaces/IRestRouteEntryPoint.md)
37
+ - [IRestRouteExample](interfaces/IRestRouteExample.md)
38
+ - [IRestRouteRequestExample](interfaces/IRestRouteRequestExample.md)
37
39
  - [IRestRouteResponseAttachmentOptions](interfaces/IRestRouteResponseAttachmentOptions.md)
40
+ - [IRestRouteResponseExample](interfaces/IRestRouteResponseExample.md)
38
41
  - [IRestRouteResponseOptions](interfaces/IRestRouteResponseOptions.md)
39
42
  - [ISocketRoute](interfaces/ISocketRoute.md)
40
43
  - [ITag](interfaces/ITag.md)
@@ -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.5",
3
+ "version": "0.0.1-next.8",
4
4
  "description": "Contains models and classes for use with APIs",
5
5
  "repository": {
6
6
  "type": "git",