@twin.org/api-models 0.0.2-next.1 → 0.0.2-next.3

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.
@@ -15,6 +15,8 @@ export * from "./models/protocol/IHttpRequestPathParams";
15
15
  export * from "./models/protocol/IHttpRequestQuery";
16
16
  export * from "./models/protocol/IHttpResponse";
17
17
  export * from "./models/protocol/IHttpServerRequest";
18
+ export * from "./models/protocol/ISocketRequestContext";
19
+ export * from "./models/protocol/ISocketServerRequest";
18
20
  export * from "./models/requests/INoContentRequest";
19
21
  export * from "./models/responses/errors/IBadRequestResponse";
20
22
  export * from "./models/responses/errors/IConflictResponse";
@@ -0,0 +1,10 @@
1
+ import type { IHttpRequestContext } from "./IHttpRequestContext";
2
+ /**
3
+ * Context data from the socket request.
4
+ */
5
+ export interface ISocketRequestContext extends IHttpRequestContext {
6
+ /**
7
+ * The id of the socket.
8
+ */
9
+ socketId: string;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { IHttpServerRequest } from "./IHttpServerRequest";
2
+ /**
3
+ * Model for the standard parameters for an http request.
4
+ */
5
+ export interface ISocketServerRequest<T = any> extends IHttpServerRequest<T> {
6
+ /**
7
+ * The socket id.
8
+ */
9
+ socketId: string;
10
+ }
@@ -1,7 +1,7 @@
1
1
  import type { IBaseRoute } from "./IBaseRoute";
2
2
  import type { IHttpRequest } from "../protocol/IHttpRequest";
3
- import type { IHttpRequestContext } from "../protocol/IHttpRequestContext";
4
3
  import type { IHttpResponse } from "../protocol/IHttpResponse";
4
+ import type { ISocketRequestContext } from "../protocol/ISocketRequestContext";
5
5
  /**
6
6
  * Interface which defines a socket route.
7
7
  */
@@ -13,7 +13,7 @@ export interface ISocketRoute<T extends IHttpRequest = any, U extends IHttpRespo
13
13
  /**
14
14
  * The request context.
15
15
  */
16
- httpRequestContext: IHttpRequestContext,
16
+ socketRequestContext: ISocketRequestContext,
17
17
  /**
18
18
  * The request object.
19
19
  */
@@ -22,4 +22,20 @@ export interface ISocketRoute<T extends IHttpRequest = any, U extends IHttpRespo
22
22
  * The function to emit an event.
23
23
  */
24
24
  emit: (event: string, response: U) => Promise<void>) => void;
25
+ /**
26
+ * The connected handler.
27
+ */
28
+ connected?: (
29
+ /**
30
+ * The request context.
31
+ */
32
+ socketRequestContext: ISocketRequestContext) => void;
33
+ /**
34
+ * The disconnected handler.
35
+ */
36
+ disconnected?: (
37
+ /**
38
+ * The request context.
39
+ */
40
+ socketRequestContext: ISocketRequestContext) => void;
25
41
  }
@@ -6,7 +6,7 @@ import type { IBaseRoute } from "../routes/IBaseRoute";
6
6
  /**
7
7
  * The definition for a base processor for handling REST routes.
8
8
  */
9
- export interface IBaseRouteProcessor<T = IBaseRoute> extends IComponent {
9
+ export interface IBaseRouteProcessor<T = IBaseRoute, R = IHttpServerRequest> extends IComponent {
10
10
  /**
11
11
  * Pre process the REST request for the specified route.
12
12
  * @param request The request to handle.
@@ -16,7 +16,7 @@ export interface IBaseRouteProcessor<T = IBaseRoute> extends IComponent {
16
16
  * @param processorState The state handed through the processors.
17
17
  * @returns Promise that resolves when the request is processed.
18
18
  */
19
- pre?(request: IHttpServerRequest, response: IHttpResponse, route: T | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
19
+ pre?(request: R, response: IHttpResponse, route: T | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
20
20
  [id: string]: unknown;
21
21
  }): Promise<void>;
22
22
  /**
@@ -28,7 +28,7 @@ export interface IBaseRouteProcessor<T = IBaseRoute> extends IComponent {
28
28
  * @param processorState The state handed through the processors.
29
29
  * @returns Promise that resolves when the request is processed.
30
30
  */
31
- post?(request: IHttpServerRequest, response: IHttpResponse, route: T | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
31
+ post?(request: R, response: IHttpResponse, route: T | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
32
32
  [id: string]: unknown;
33
33
  }): Promise<void>;
34
34
  }
@@ -1,35 +1,29 @@
1
1
  import type { IBaseRouteProcessor } from "./IBaseRouteProcessor";
2
2
  import type { IHttpRequestIdentity } from "../protocol/IHttpRequestIdentity";
3
3
  import type { IHttpResponse } from "../protocol/IHttpResponse";
4
- import type { IHttpServerRequest } from "../protocol/IHttpServerRequest";
4
+ import type { ISocketServerRequest } from "../protocol/ISocketServerRequest";
5
5
  import type { ISocketRoute } from "../routes/ISocketRoute";
6
6
  /**
7
7
  * The definition for a processor for handling socket routes.
8
8
  */
9
- export interface ISocketRouteProcessor extends IBaseRouteProcessor<ISocketRoute> {
9
+ export interface ISocketRouteProcessor extends IBaseRouteProcessor<ISocketRoute, ISocketServerRequest> {
10
10
  /**
11
11
  * Process the connected event.
12
- * @param request The request to handle.
12
+ * @param request The server request object containing the socket id and other parameters.
13
13
  * @param route The route being requested, if a matching one was found.
14
- * @param processorState The state handed through the processors.
15
14
  * @returns Promise that resolves when the request is processed.
16
15
  */
17
- connected?(request: IHttpServerRequest, route: ISocketRoute | undefined, processorState: {
18
- [id: string]: unknown;
19
- }): Promise<void>;
16
+ connected?(request: ISocketServerRequest, route: ISocketRoute | undefined): Promise<void>;
20
17
  /**
21
18
  * Process the disconnected event.
22
- * @param request The request to handle.
19
+ * @param request The server request object containing the socket id and other parameters.
23
20
  * @param route The route being requested, if a matching one was found.
24
- * @param processorState The state handed through the processors.
25
21
  * @returns Promise that resolves when the request is processed.
26
22
  */
27
- disconnected?(request: IHttpServerRequest, route: ISocketRoute | undefined, processorState: {
28
- [id: string]: unknown;
29
- }): Promise<void>;
23
+ disconnected?(request: ISocketServerRequest, route: ISocketRoute | undefined): Promise<void>;
30
24
  /**
31
25
  * Process the REST request for the specified route.
32
- * @param request The request to handle.
26
+ * @param request The server request object containing the socket id and other parameters.
33
27
  * @param response The response data to send if any.
34
28
  * @param route The route being requested, if a matching one was found.
35
29
  * @param requestIdentity The identity context for the request.
@@ -37,7 +31,7 @@ export interface ISocketRouteProcessor extends IBaseRouteProcessor<ISocketRoute>
37
31
  * @param responseEmitter The function to emit a response.
38
32
  * @returns Promise that resolves when the request is processed.
39
33
  */
40
- process?(request: IHttpServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
34
+ process?(request: ISocketServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
41
35
  [id: string]: unknown;
42
36
  }, responseEmitter: (topic: string, response: IHttpResponse) => Promise<void>): Promise<void>;
43
37
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @twin.org/api-models - Changelog
2
2
 
3
+ ## [0.0.2-next.3](https://github.com/twinfoundation/api/compare/api-models-v0.0.2-next.2...api-models-v0.0.2-next.3) (2025-07-24)
4
+
5
+
6
+ ### Features
7
+
8
+ * add socket id, connect and disconnect ([20b0d0e](https://github.com/twinfoundation/api/commit/20b0d0ec279cab46141fee09de2c4a7087cdce16))
9
+
10
+ ## [0.0.2-next.2](https://github.com/twinfoundation/api/compare/api-models-v0.0.2-next.1...api-models-v0.0.2-next.2) (2025-07-17)
11
+
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * **api-models:** Synchronize repo versions
16
+
3
17
  ## [0.0.2-next.1](https://github.com/twinfoundation/api/compare/api-models-v0.0.2-next.0...api-models-v0.0.2-next.1) (2025-07-08)
4
18
 
5
19
 
@@ -19,6 +19,8 @@
19
19
  - [IHttpRequestQuery](interfaces/IHttpRequestQuery.md)
20
20
  - [IHttpResponse](interfaces/IHttpResponse.md)
21
21
  - [IHttpServerRequest](interfaces/IHttpServerRequest.md)
22
+ - [ISocketRequestContext](interfaces/ISocketRequestContext.md)
23
+ - [ISocketServerRequest](interfaces/ISocketServerRequest.md)
22
24
  - [INoContentRequest](interfaces/INoContentRequest.md)
23
25
  - [IBadRequestResponse](interfaces/IBadRequestResponse.md)
24
26
  - [IConflictResponse](interfaces/IConflictResponse.md)
@@ -1,4 +1,4 @@
1
- # Interface: IBaseRouteProcessor\<T\>
1
+ # Interface: IBaseRouteProcessor\<T, R\>
2
2
 
3
3
  The definition for a base processor for handling REST routes.
4
4
 
@@ -17,6 +17,10 @@ The definition for a base processor for handling REST routes.
17
17
 
18
18
  `T` = [`IBaseRoute`](IBaseRoute.md)
19
19
 
20
+ ### R
21
+
22
+ `R` = [`IHttpServerRequest`](IHttpServerRequest.md)
23
+
20
24
  ## Methods
21
25
 
22
26
  ### pre()?
@@ -29,7 +33,7 @@ Pre process the REST request for the specified route.
29
33
 
30
34
  ##### request
31
35
 
32
- [`IHttpServerRequest`](IHttpServerRequest.md)
36
+ `R`
33
37
 
34
38
  The request to handle.
35
39
 
@@ -73,7 +77,7 @@ Post process the REST request for the specified route.
73
77
 
74
78
  ##### request
75
79
 
76
- [`IHttpServerRequest`](IHttpServerRequest.md)
80
+ `R`
77
81
 
78
82
  The request to handle.
79
83
 
@@ -6,6 +6,10 @@ Context data from the HTTP request.
6
6
 
7
7
  - [`IHttpRequestIdentity`](IHttpRequestIdentity.md)
8
8
 
9
+ ## Extended by
10
+
11
+ - [`ISocketRequestContext`](ISocketRequestContext.md)
12
+
9
13
  ## Properties
10
14
 
11
15
  ### serverRequest
@@ -6,6 +6,10 @@ Model for the standard parameters for an http request.
6
6
 
7
7
  - [`IHttpRequest`](IHttpRequest.md)\<`T`\>
8
8
 
9
+ ## Extended by
10
+
11
+ - [`ISocketServerRequest`](ISocketServerRequest.md)
12
+
9
13
  ## Type Parameters
10
14
 
11
15
  ### T
@@ -0,0 +1,67 @@
1
+ # Interface: ISocketRequestContext
2
+
3
+ Context data from the socket request.
4
+
5
+ ## Extends
6
+
7
+ - [`IHttpRequestContext`](IHttpRequestContext.md)
8
+
9
+ ## Properties
10
+
11
+ ### serverRequest
12
+
13
+ > **serverRequest**: [`IHttpServerRequest`](IHttpServerRequest.md)
14
+
15
+ The raw HTTP request.
16
+
17
+ #### Inherited from
18
+
19
+ [`IHttpRequestContext`](IHttpRequestContext.md).[`serverRequest`](IHttpRequestContext.md#serverrequest)
20
+
21
+ ***
22
+
23
+ ### processorState
24
+
25
+ > **processorState**: `object`
26
+
27
+ The state handed through the processors.
28
+
29
+ #### Index Signature
30
+
31
+ \[`id`: `string`\]: `unknown`
32
+
33
+ #### Inherited from
34
+
35
+ [`IHttpRequestContext`](IHttpRequestContext.md).[`processorState`](IHttpRequestContext.md#processorstate)
36
+
37
+ ***
38
+
39
+ ### nodeIdentity?
40
+
41
+ > `optional` **nodeIdentity**: `string`
42
+
43
+ The identity of the node the request is being performed on.
44
+
45
+ #### Inherited from
46
+
47
+ [`IHttpRequestContext`](IHttpRequestContext.md).[`nodeIdentity`](IHttpRequestContext.md#nodeidentity)
48
+
49
+ ***
50
+
51
+ ### userIdentity?
52
+
53
+ > `optional` **userIdentity**: `string`
54
+
55
+ The identity of the requestor if there is an authenticated user.
56
+
57
+ #### Inherited from
58
+
59
+ [`IHttpRequestContext`](IHttpRequestContext.md).[`userIdentity`](IHttpRequestContext.md#useridentity)
60
+
61
+ ***
62
+
63
+ ### socketId
64
+
65
+ > **socketId**: `string`
66
+
67
+ The id of the socket.
@@ -56,15 +56,15 @@ Skips the authentication for this route.
56
56
 
57
57
  ### handler()
58
58
 
59
- > **handler**: (`httpRequestContext`, `request`, `emit`) => `void`
59
+ > **handler**: (`socketRequestContext`, `request`, `emit`) => `void`
60
60
 
61
61
  The handler module.
62
62
 
63
63
  #### Parameters
64
64
 
65
- ##### httpRequestContext
65
+ ##### socketRequestContext
66
66
 
67
- [`IHttpRequestContext`](IHttpRequestContext.md)
67
+ [`ISocketRequestContext`](ISocketRequestContext.md)
68
68
 
69
69
  The request context.
70
70
 
@@ -83,3 +83,43 @@ The function to emit an event.
83
83
  #### Returns
84
84
 
85
85
  `void`
86
+
87
+ ***
88
+
89
+ ### connected()?
90
+
91
+ > `optional` **connected**: (`socketRequestContext`) => `void`
92
+
93
+ The connected handler.
94
+
95
+ #### Parameters
96
+
97
+ ##### socketRequestContext
98
+
99
+ [`ISocketRequestContext`](ISocketRequestContext.md)
100
+
101
+ The request context.
102
+
103
+ #### Returns
104
+
105
+ `void`
106
+
107
+ ***
108
+
109
+ ### disconnected()?
110
+
111
+ > `optional` **disconnected**: (`socketRequestContext`) => `void`
112
+
113
+ The disconnected handler.
114
+
115
+ #### Parameters
116
+
117
+ ##### socketRequestContext
118
+
119
+ [`ISocketRequestContext`](ISocketRequestContext.md)
120
+
121
+ The request context.
122
+
123
+ #### Returns
124
+
125
+ `void`
@@ -4,7 +4,7 @@ The definition for a processor for handling socket routes.
4
4
 
5
5
  ## Extends
6
6
 
7
- - [`IBaseRouteProcessor`](IBaseRouteProcessor.md)\<[`ISocketRoute`](ISocketRoute.md)\>
7
+ - [`IBaseRouteProcessor`](IBaseRouteProcessor.md)\<[`ISocketRoute`](ISocketRoute.md), [`ISocketServerRequest`](ISocketServerRequest.md)\>
8
8
 
9
9
  ## Methods
10
10
 
@@ -18,7 +18,7 @@ Pre process the REST request for the specified route.
18
18
 
19
19
  ##### request
20
20
 
21
- [`IHttpServerRequest`](IHttpServerRequest.md)
21
+ [`ISocketServerRequest`](ISocketServerRequest.md)
22
22
 
23
23
  The request to handle.
24
24
 
@@ -66,7 +66,7 @@ Post process the REST request for the specified route.
66
66
 
67
67
  ##### request
68
68
 
69
- [`IHttpServerRequest`](IHttpServerRequest.md)
69
+ [`ISocketServerRequest`](ISocketServerRequest.md)
70
70
 
71
71
  The request to handle.
72
72
 
@@ -106,7 +106,7 @@ Promise that resolves when the request is processed.
106
106
 
107
107
  ### connected()?
108
108
 
109
- > `optional` **connected**(`request`, `route`, `processorState`): `Promise`\<`void`\>
109
+ > `optional` **connected**(`request`, `route`): `Promise`\<`void`\>
110
110
 
111
111
  Process the connected event.
112
112
 
@@ -114,9 +114,9 @@ Process the connected event.
114
114
 
115
115
  ##### request
116
116
 
117
- [`IHttpServerRequest`](IHttpServerRequest.md)
117
+ [`ISocketServerRequest`](ISocketServerRequest.md)
118
118
 
119
- The request to handle.
119
+ The server request object containing the socket id and other parameters.
120
120
 
121
121
  ##### route
122
122
 
@@ -124,10 +124,6 @@ The route being requested, if a matching one was found.
124
124
 
125
125
  `undefined` | [`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\>
126
126
 
127
- ##### processorState
128
-
129
- The state handed through the processors.
130
-
131
127
  #### Returns
132
128
 
133
129
  `Promise`\<`void`\>
@@ -138,7 +134,7 @@ Promise that resolves when the request is processed.
138
134
 
139
135
  ### disconnected()?
140
136
 
141
- > `optional` **disconnected**(`request`, `route`, `processorState`): `Promise`\<`void`\>
137
+ > `optional` **disconnected**(`request`, `route`): `Promise`\<`void`\>
142
138
 
143
139
  Process the disconnected event.
144
140
 
@@ -146,9 +142,9 @@ Process the disconnected event.
146
142
 
147
143
  ##### request
148
144
 
149
- [`IHttpServerRequest`](IHttpServerRequest.md)
145
+ [`ISocketServerRequest`](ISocketServerRequest.md)
150
146
 
151
- The request to handle.
147
+ The server request object containing the socket id and other parameters.
152
148
 
153
149
  ##### route
154
150
 
@@ -156,10 +152,6 @@ The route being requested, if a matching one was found.
156
152
 
157
153
  `undefined` | [`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\>
158
154
 
159
- ##### processorState
160
-
161
- The state handed through the processors.
162
-
163
155
  #### Returns
164
156
 
165
157
  `Promise`\<`void`\>
@@ -178,9 +170,9 @@ Process the REST request for the specified route.
178
170
 
179
171
  ##### request
180
172
 
181
- [`IHttpServerRequest`](IHttpServerRequest.md)
173
+ [`ISocketServerRequest`](ISocketServerRequest.md)
182
174
 
183
- The request to handle.
175
+ The server request object containing the socket id and other parameters.
184
176
 
185
177
  ##### response
186
178
 
@@ -0,0 +1,93 @@
1
+ # Interface: ISocketServerRequest\<T\>
2
+
3
+ Model for the standard parameters for an http request.
4
+
5
+ ## Extends
6
+
7
+ - [`IHttpServerRequest`](IHttpServerRequest.md)\<`T`\>
8
+
9
+ ## Type Parameters
10
+
11
+ ### T
12
+
13
+ `T` = `any`
14
+
15
+ ## Properties
16
+
17
+ ### headers?
18
+
19
+ > `optional` **headers**: `IHttpHeaders`
20
+
21
+ Incoming Http Headers.
22
+
23
+ #### Inherited from
24
+
25
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`headers`](IHttpServerRequest.md#headers)
26
+
27
+ ***
28
+
29
+ ### pathParams?
30
+
31
+ > `optional` **pathParams**: [`IHttpRequestPathParams`](IHttpRequestPathParams.md)
32
+
33
+ The path parameters.
34
+
35
+ #### Inherited from
36
+
37
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`pathParams`](IHttpServerRequest.md#pathparams)
38
+
39
+ ***
40
+
41
+ ### query?
42
+
43
+ > `optional` **query**: [`IHttpRequestQuery`](IHttpRequestQuery.md)
44
+
45
+ The query parameters.
46
+
47
+ #### Inherited from
48
+
49
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`query`](IHttpServerRequest.md#query)
50
+
51
+ ***
52
+
53
+ ### body?
54
+
55
+ > `optional` **body**: `T`
56
+
57
+ Data to return send as the body.
58
+
59
+ #### Inherited from
60
+
61
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`body`](IHttpServerRequest.md#body)
62
+
63
+ ***
64
+
65
+ ### method?
66
+
67
+ > `optional` **method**: `HttpMethod`
68
+
69
+ The request method.
70
+
71
+ #### Inherited from
72
+
73
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`method`](IHttpServerRequest.md#method)
74
+
75
+ ***
76
+
77
+ ### url?
78
+
79
+ > `optional` **url**: `string`
80
+
81
+ The request url.
82
+
83
+ #### Inherited from
84
+
85
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`url`](IHttpServerRequest.md#url)
86
+
87
+ ***
88
+
89
+ ### socketId
90
+
91
+ > **socketId**: `string`
92
+
93
+ The socket id.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-models",
3
- "version": "0.0.2-next.1",
3
+ "version": "0.0.2-next.3",
4
4
  "description": "Contains models and classes for use with APIs",
5
5
  "repository": {
6
6
  "type": "git",