@ez4/gateway 0.35.0 → 0.36.0

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.
Files changed (145) hide show
  1. package/README.md +121 -2
  2. package/dist/client/authorization.d.ts +1 -1
  3. package/dist/client/operations.d.ts +1 -2
  4. package/dist/errors/auth/authorizer.d.ts +4 -0
  5. package/dist/errors/{identity.d.ts → auth/identity.d.ts} +4 -2
  6. package/dist/errors/{authorization.d.ts → http/authorization.d.ts} +4 -2
  7. package/dist/errors/{cache.d.ts → http/cache.d.ts} +4 -2
  8. package/dist/errors/{cors.d.ts → http/cors.d.ts} +5 -3
  9. package/dist/errors/{body.d.ts → web/body.d.ts} +4 -2
  10. package/dist/errors/{defaults.d.ts → web/defaults.d.ts} +4 -2
  11. package/dist/errors/{headers.d.ts → web/headers.d.ts} +4 -2
  12. package/dist/errors/web/parameters.d.ts +14 -0
  13. package/dist/errors/{preferences.d.ts → web/preferences.d.ts} +4 -2
  14. package/dist/errors/{query.d.ts → web/query.d.ts} +4 -2
  15. package/dist/errors/ws/event.d.ts +10 -0
  16. package/dist/errors/{authorizer.d.ts → ws/target.d.ts} +1 -1
  17. package/dist/library.cjs +460 -311
  18. package/dist/library.d.ts +26 -23
  19. package/dist/library.mjs +436 -293
  20. package/dist/main.cjs +17 -17
  21. package/dist/main.d.ts +5 -3
  22. package/dist/main.mjs +8 -8
  23. package/dist/metadata/auth/handler.d.ts +4 -0
  24. package/dist/metadata/auth/identity.d.ts +6 -0
  25. package/dist/metadata/auth/request.d.ts +4 -0
  26. package/dist/metadata/auth/response.d.ts +4 -0
  27. package/dist/metadata/auth/types.d.ts +17 -0
  28. package/dist/metadata/http/access.d.ts +4 -0
  29. package/dist/metadata/http/authorization.d.ts +4 -0
  30. package/dist/metadata/http/cache.d.ts +4 -0
  31. package/dist/metadata/http/cors.d.ts +4 -0
  32. package/dist/metadata/http/defaults.d.ts +4 -0
  33. package/dist/metadata/{errors.d.ts → http/errors.d.ts} +2 -2
  34. package/dist/metadata/http/handler.d.ts +4 -0
  35. package/dist/metadata/http/import.d.ts +7 -0
  36. package/dist/metadata/http/provider.d.ts +4 -0
  37. package/dist/metadata/http/request.d.ts +4 -0
  38. package/dist/metadata/http/response.d.ts +4 -0
  39. package/dist/metadata/{route.d.ts → http/routes.d.ts} +3 -2
  40. package/dist/metadata/http/service.d.ts +7 -0
  41. package/dist/{types/common.d.ts → metadata/http/types.d.ts} +33 -22
  42. package/dist/metadata/utils/path.d.ts +2 -0
  43. package/dist/metadata/utils/type.d.ts +1 -0
  44. package/dist/metadata/web/body.d.ts +6 -0
  45. package/dist/metadata/web/headers.d.ts +5 -0
  46. package/dist/metadata/web/parameters.d.ts +5 -0
  47. package/dist/metadata/web/preferences.d.ts +4 -0
  48. package/dist/metadata/web/query.d.ts +5 -0
  49. package/dist/metadata/web/types.d.ts +4 -0
  50. package/dist/metadata/ws/connection.d.ts +4 -0
  51. package/dist/metadata/ws/defaults.d.ts +5 -0
  52. package/dist/metadata/ws/event.d.ts +4 -0
  53. package/dist/metadata/ws/handlers.d.ts +5 -0
  54. package/dist/metadata/ws/message.d.ts +4 -0
  55. package/dist/metadata/ws/request.d.ts +4 -0
  56. package/dist/metadata/ws/response.d.ts +4 -0
  57. package/dist/metadata/ws/service.d.ts +7 -0
  58. package/dist/metadata/ws/types.d.ts +72 -0
  59. package/dist/services/auth/cache.d.ts +9 -0
  60. package/dist/services/auth/handler.d.ts +9 -0
  61. package/dist/services/auth/identity.d.ts +5 -0
  62. package/dist/services/auth/incoming.d.ts +22 -0
  63. package/dist/services/auth/provider.d.ts +11 -0
  64. package/dist/services/auth/request.d.ts +20 -0
  65. package/dist/services/auth/response.d.ts +10 -0
  66. package/dist/services/{client.d.ts → http/client.d.ts} +3 -3
  67. package/dist/services/{contract.d.ts → http/contract.d.ts} +42 -30
  68. package/dist/services/http/defaults.d.ts +17 -0
  69. package/dist/services/http/errors.d.ts +6 -0
  70. package/dist/services/http/handler.d.ts +10 -0
  71. package/dist/services/http/incoming.d.ts +30 -0
  72. package/dist/services/http/listener.d.ts +9 -0
  73. package/dist/services/http/path.d.ts +2 -0
  74. package/dist/services/http/request.d.ts +30 -0
  75. package/dist/services/http/response.d.ts +19 -0
  76. package/dist/services/http/route.d.ts +45 -0
  77. package/dist/services/{utils.d.ts → http/utils.d.ts} +13 -5
  78. package/dist/services/web/body.d.ts +13 -0
  79. package/dist/services/web/defaults.d.ts +22 -0
  80. package/dist/services/web/headers.d.ts +10 -0
  81. package/dist/services/web/parameters.d.ts +5 -0
  82. package/dist/services/{preferences.d.ts → web/preferences.d.ts} +2 -2
  83. package/dist/services/web/query.d.ts +5 -0
  84. package/dist/services/web/target.d.ts +27 -0
  85. package/dist/services/ws/client.d.ts +19 -0
  86. package/dist/services/ws/connect.d.ts +23 -0
  87. package/dist/services/ws/contract.d.ts +108 -0
  88. package/dist/services/ws/defaults.d.ts +13 -0
  89. package/dist/services/ws/disconnect.d.ts +17 -0
  90. package/dist/services/ws/event.d.ts +20 -0
  91. package/dist/services/ws/handler.d.ts +10 -0
  92. package/dist/services/ws/incoming.d.ts +19 -0
  93. package/dist/services/ws/listener.d.ts +9 -0
  94. package/dist/services/ws/message.d.ts +17 -0
  95. package/dist/services/ws/request.d.ts +15 -0
  96. package/dist/services/ws/response.d.ts +10 -0
  97. package/dist/services/ws/utils.d.ts +11 -0
  98. package/dist/utils/body.d.ts +1 -1
  99. package/dist/utils/client.d.ts +4 -4
  100. package/dist/utils/errors.d.ts +1 -0
  101. package/dist/utils/headers.d.ts +1 -1
  102. package/dist/utils/identity.d.ts +1 -1
  103. package/dist/utils/parameters.d.ts +1 -1
  104. package/dist/utils/query.d.ts +1 -1
  105. package/dist/utils.cjs +2 -2
  106. package/dist/utils.mjs +5 -5
  107. package/package.json +8 -8
  108. package/dist/errors/parameters.d.ts +0 -8
  109. package/dist/metadata/access.d.ts +0 -3
  110. package/dist/metadata/authorization.d.ts +0 -3
  111. package/dist/metadata/authorizer.d.ts +0 -3
  112. package/dist/metadata/body.d.ts +0 -5
  113. package/dist/metadata/cache.d.ts +0 -3
  114. package/dist/metadata/cors.d.ts +0 -3
  115. package/dist/metadata/defaults.d.ts +0 -3
  116. package/dist/metadata/handler.d.ts +0 -3
  117. package/dist/metadata/headers.d.ts +0 -4
  118. package/dist/metadata/identity.d.ts +0 -5
  119. package/dist/metadata/import.d.ts +0 -6
  120. package/dist/metadata/parameters.d.ts +0 -4
  121. package/dist/metadata/preferences.d.ts +0 -3
  122. package/dist/metadata/provider.d.ts +0 -3
  123. package/dist/metadata/query.d.ts +0 -4
  124. package/dist/metadata/request.d.ts +0 -4
  125. package/dist/metadata/response.d.ts +0 -4
  126. package/dist/metadata/service.d.ts +0 -6
  127. package/dist/metadata/utils.d.ts +0 -24
  128. package/dist/services/cache.d.ts +0 -9
  129. package/dist/services/common.d.ts +0 -143
  130. package/dist/services/defaults.d.ts +0 -31
  131. package/dist/services/route.d.ts +0 -56
  132. package/dist/types/import.d.ts +0 -14
  133. package/dist/types/service.d.ts +0 -14
  134. /package/dist/errors/{access.d.ts → http/access.d.ts} +0 -0
  135. /package/dist/errors/{provider.d.ts → http/provider.d.ts} +0 -0
  136. /package/dist/errors/{route.d.ts → http/route.d.ts} +0 -0
  137. /package/dist/errors/{handler.d.ts → web/handler.d.ts} +0 -0
  138. /package/dist/errors/{request.d.ts → web/request.d.ts} +0 -0
  139. /package/dist/errors/{response.d.ts → web/response.d.ts} +0 -0
  140. /package/dist/errors/{service.d.ts → web/service.d.ts} +0 -0
  141. /package/dist/metadata/{schema.d.ts → utils/schema.d.ts} +0 -0
  142. /package/dist/services/{access.d.ts → http/access.d.ts} +0 -0
  143. /package/dist/services/{authorization.d.ts → http/authorization.d.ts} +0 -0
  144. /package/dist/services/{cors.d.ts → http/cors.d.ts} +0 -0
  145. /package/dist/services/{provider.d.ts → http/provider.d.ts} +0 -0
@@ -1,52 +1,64 @@
1
1
  import type { Service as CommonService } from '@ez4/common';
2
2
  import type { LinkedVariables } from '@ez4/project/library';
3
- import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse } from './utils';
3
+ import type { AuthResponse as HttpAuthResponse } from '../auth/response';
4
+ import type { AuthRequest as HttpAuthRequest } from '../auth/request';
5
+ import type { WebJsonBody, WebRawBody } from '../web/body';
6
+ import type { WebPathParameters } from '../web/parameters';
7
+ import type { WebPreferences } from '../web/preferences';
8
+ import type { AuthIdentity } from '../auth/identity';
9
+ import type { WebQueryStrings } from '../web/query';
10
+ import type { WebHeaders } from '../web/headers';
11
+ import type { AuthCache } from '../auth/cache';
12
+ import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse, HttpEmptyRequest } from './utils';
4
13
  import type { HttpAuthorization } from './authorization';
5
- import type { HttpPreferences } from './preferences';
6
14
  import type { HttpDefaults } from './defaults';
7
15
  import type { HttpProvider } from './provider';
16
+ import type { HttpListener } from './listener';
17
+ import type { HttpIncoming } from './incoming';
18
+ import type { HttpResponse } from './response';
19
+ import type { HttpRequest } from './request';
20
+ import type { HttpHandler } from './handler';
21
+ import type { HttpClient } from './client';
8
22
  import type { HttpAccess } from './access';
23
+ import type { HttpErrors } from './errors';
9
24
  import type { HttpRoute } from './route';
10
- import type { HttpCache } from './cache';
11
25
  import type { HttpCors } from './cors';
12
- import type { Client } from './client';
13
- import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler } from './common';
14
26
  /**
15
27
  * Provide all contracts for a self-managed HTTP service.
16
28
  */
17
29
  export declare namespace Http {
18
- type Headers = HttpHeaders;
19
- type Identity = HttpIdentity;
20
- type PathParameters = HttpPathParameters;
21
- type QueryStrings = HttpQueryStrings;
22
- type JsonBody = HttpJsonBody;
23
- type RawBody = HttpRawBody;
30
+ type Headers = WebHeaders;
31
+ type Identity = AuthIdentity;
32
+ type PathParameters = WebPathParameters;
33
+ type QueryStrings = WebQueryStrings;
34
+ type JsonBody = WebJsonBody;
35
+ type RawBody = WebRawBody;
24
36
  type Authorization = HttpAuthorization;
25
- type Preferences = HttpPreferences;
26
- type AuthRequest = HttpAuthRequest;
37
+ type Access = HttpAccess;
38
+ type Preferences = WebPreferences;
39
+ type Cache = AuthCache;
27
40
  type Request = HttpRequest;
28
- type AuthResponse = HttpAuthResponse;
29
41
  type Response = HttpResponse;
42
+ type AuthRequest = HttpAuthRequest;
43
+ type AuthResponse = HttpAuthResponse;
30
44
  type Errors = HttpErrors;
31
45
  type Provider = HttpProvider;
32
- type Cache = HttpCache;
33
- type Access = HttpAccess;
34
46
  type Cors = HttpCors;
35
- type Incoming<T extends Request | AuthRequest> = HttpIncoming<T>;
36
- type Listener<T extends Request | AuthRequest> = HttpListener<T>;
37
- type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
47
+ type Incoming<T extends Request> = HttpIncoming<T>;
48
+ type Listener<T extends Request> = HttpListener<T>;
38
49
  type Handler<T extends Request> = HttpHandler<T>;
39
50
  type Route<T extends Request = Request, U extends AuthRequest = AuthRequest> = HttpRoute<T, U>;
40
- type Defaults<T extends HttpRequest | HttpAuthRequest = any> = HttpDefaults<T>;
41
- type ServiceEvent<T extends Request | AuthRequest = Request> = CommonService.AnyEvent<Incoming<T>>;
51
+ type Defaults<T extends Request = Request> = HttpDefaults<T>;
52
+ type ServiceEvent<T extends Request = Request> = CommonService.AnyEvent<Incoming<T>>;
42
53
  type SuccessEmptyResponse<S extends HttpSuccessStatuses = 204> = HttpSuccessEmptyResponse<S>;
43
- type SuccessResponse<S extends HttpSuccessStatuses, T extends HttpRawBody | HttpJsonBody> = HttpSuccessResponse<S, T>;
54
+ type SuccessResponse<S extends HttpSuccessStatuses, T extends JsonBody | RawBody> = HttpSuccessResponse<S, T>;
55
+ type EmptyRequest = HttpEmptyRequest;
44
56
  /**
45
57
  * HTTP Route definition.
46
58
  */
47
59
  type UseRoute<T extends Route<any, any>> = T;
48
60
  /**
49
- * HTTP Service definition.
61
+ * HTTP Defaults definition.
50
62
  */
51
63
  type UseDefaults<T extends Defaults<any>> = T;
52
64
  /**
@@ -74,7 +86,7 @@ export declare namespace Http {
74
86
  */
75
87
  abstract class Service implements CommonService.Provider {
76
88
  /**
77
- * All expected routes.
89
+ * All routes associated to the gateway.
78
90
  */
79
91
  abstract readonly routes: Route<any, any>[];
80
92
  /**
@@ -82,19 +94,19 @@ export declare namespace Http {
82
94
  */
83
95
  readonly name?: string;
84
96
  /**
85
- * Default parameters.
97
+ * Default gateway parameters.
86
98
  */
87
99
  readonly defaults?: Defaults<any>;
88
100
  /**
89
- * CORS configuration.
101
+ * CORS configuration for all routes.
90
102
  */
91
103
  readonly cors?: Cors;
92
104
  /**
93
- * Cache configuration.
105
+ * Cache configuration for authorizers.
94
106
  */
95
107
  readonly cache?: Cache;
96
108
  /**
97
- * Access configuration.
109
+ * Access configuration for logs.
98
110
  */
99
111
  readonly access?: Access;
100
112
  /**
@@ -104,7 +116,7 @@ export declare namespace Http {
104
116
  /**
105
117
  * Service client.
106
118
  */
107
- readonly client: Client<Service>;
119
+ readonly client: HttpClient<Service>;
108
120
  }
109
121
  /**
110
122
  * Imported HTTP service.
@@ -137,7 +149,7 @@ export declare namespace Http {
137
149
  /**
138
150
  * Imported service client (do not replace).
139
151
  */
140
- readonly client: Client<T>;
152
+ readonly client: HttpClient<T>;
141
153
  /**
142
154
  * Variables are not allowed.
143
155
  */
@@ -0,0 +1,17 @@
1
+ import type { WebDefaults } from '../web/defaults';
2
+ import type { HttpListener } from './listener';
3
+ import type { HttpRequest } from './request';
4
+ import type { HttpErrors } from './errors';
5
+ /**
6
+ * Default HTTP service parameters.
7
+ */
8
+ export interface HttpDefaults<T extends HttpRequest> extends WebDefaults {
9
+ /**
10
+ * Default listener.
11
+ */
12
+ readonly listener?: HttpListener<T>;
13
+ /**
14
+ * Status codes for all known exceptions.
15
+ */
16
+ readonly httpErrors?: HttpErrors;
17
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * HTTP errors.
3
+ */
4
+ export type HttpErrors = {
5
+ [code: number]: readonly Error[];
6
+ };
@@ -0,0 +1,10 @@
1
+ import type { Service } from '@ez4/common';
2
+ import type { HttpProvider } from './provider';
3
+ import type { HttpIncoming } from './incoming';
4
+ import type { HttpResponse } from './response';
5
+ import type { HttpRequest } from './request';
6
+ import type { Http } from './contract';
7
+ /**
8
+ * HTTP request handler.
9
+ */
10
+ export type HttpHandler<T extends HttpRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service | HttpProvider>) => Promise<HttpResponse> | HttpResponse;
@@ -0,0 +1,30 @@
1
+ import type { HttpRequest } from './request';
2
+ /**
3
+ * Incoming request.
4
+ */
5
+ export type HttpIncoming<T extends HttpRequest> = T & {
6
+ /**
7
+ * Request tracking Id.
8
+ */
9
+ readonly requestId: string;
10
+ /**
11
+ * Determines whether request is base64 encoded or not.
12
+ */
13
+ readonly encoded?: boolean;
14
+ /**
15
+ * Request timestamp.
16
+ */
17
+ readonly timestamp: Date;
18
+ /**
19
+ * Request method.
20
+ */
21
+ readonly method: string;
22
+ /**
23
+ * Request path.
24
+ */
25
+ readonly path: string;
26
+ /**
27
+ * Raw body data (when provided in the request).
28
+ */
29
+ readonly data?: string;
30
+ };
@@ -0,0 +1,9 @@
1
+ import type { Service } from '@ez4/common';
2
+ import type { HttpProvider } from './provider';
3
+ import type { HttpIncoming } from './incoming';
4
+ import type { HttpRequest } from './request';
5
+ import type { Http } from './contract';
6
+ /**
7
+ * HTTP request listener.
8
+ */
9
+ export type HttpListener<T extends HttpRequest> = (event: Service.AnyEvent<HttpIncoming<T>>, context: Service.Context<Http.Service | HttpProvider>) => Promise<void> | void;
@@ -0,0 +1,2 @@
1
+ export type HttpVerb = 'ANY' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
2
+ export type HttpPath = `${HttpVerb} /${string}`;
@@ -0,0 +1,30 @@
1
+ import type { AuthIdentity } from '../auth/identity';
2
+ import type { WebPathParameters } from '../web/parameters';
3
+ import type { WebQueryStrings } from '../web/query';
4
+ import type { WebHeaders } from '../web/headers';
5
+ import type { WebBody } from '../web/body';
6
+ /**
7
+ * HTTP request.
8
+ */
9
+ export interface HttpRequest {
10
+ /**
11
+ * Expected identity.
12
+ */
13
+ readonly identity?: AuthIdentity;
14
+ /**
15
+ * Expected HTTP headers.
16
+ */
17
+ readonly headers?: WebHeaders;
18
+ /**
19
+ * Expected HTTP path parameters.
20
+ */
21
+ readonly parameters?: WebPathParameters;
22
+ /**
23
+ * Expected HTTP query strings.
24
+ */
25
+ readonly query?: WebQueryStrings;
26
+ /**
27
+ * Expected HTTP body payload.
28
+ */
29
+ readonly body?: WebBody;
30
+ }
@@ -0,0 +1,19 @@
1
+ import type { WebHeaders } from '../web/headers';
2
+ import type { WebBody } from '../web/body';
3
+ /**
4
+ * HTTP response.
5
+ */
6
+ export interface HttpResponse {
7
+ /**
8
+ * HTTP status code.
9
+ */
10
+ readonly status: number;
11
+ /**
12
+ * HTTP headers.
13
+ */
14
+ readonly headers?: WebHeaders;
15
+ /**
16
+ * HTTP body payload.
17
+ */
18
+ readonly body?: WebBody;
19
+ }
@@ -0,0 +1,45 @@
1
+ import type { AuthHandler } from '../auth/handler';
2
+ import type { AuthRequest } from '../auth/request';
3
+ import type { WebTarget } from '../web/target';
4
+ import type { HttpListener } from './listener';
5
+ import type { HttpRequest } from './request';
6
+ import type { HttpHandler } from './handler';
7
+ import type { HttpErrors } from './errors';
8
+ import type { HttpPath } from './path';
9
+ /**
10
+ * HTTP route.
11
+ */
12
+ export interface HttpRoute<T extends HttpRequest, U extends AuthRequest> extends WebTarget {
13
+ /**
14
+ * Route operation name.
15
+ */
16
+ readonly name?: string;
17
+ /**
18
+ * Route path including the HTTP verb.
19
+ */
20
+ readonly path: HttpPath;
21
+ /**
22
+ * Life-cycle listener function for the route.
23
+ */
24
+ readonly listener?: HttpListener<T>;
25
+ /**
26
+ * Entry-point authorizer handler function for the route.
27
+ */
28
+ readonly authorizer?: AuthHandler<U>;
29
+ /**
30
+ * Entry-point handler function for the route.
31
+ */
32
+ readonly handler: HttpHandler<T>;
33
+ /**
34
+ * Map status codes and errors for all known exceptions.
35
+ */
36
+ readonly httpErrors?: HttpErrors;
37
+ /**
38
+ * Determines whether or not the route is disabled.
39
+ */
40
+ readonly disabled?: boolean;
41
+ /**
42
+ * Determines whether or not CORS is enabled for the route.
43
+ */
44
+ readonly cors?: boolean;
45
+ }
@@ -1,18 +1,26 @@
1
- import type { HttpResponse, HttpJsonBody, HttpRawBody } from './common';
1
+ import type { Http } from './contract';
2
+ /**
3
+ * HTTP success status codes.
4
+ */
2
5
  export type HttpSuccessStatuses = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208;
3
6
  /**
4
- * Common HTTP success response without a response body.
7
+ * HTTP empty request.
8
+ */
9
+ export declare class HttpEmptyRequest implements Http.Request {
10
+ }
11
+ /**
12
+ * HTTP success response without a response body.
5
13
  */
6
- export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> implements HttpResponse {
14
+ export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> implements Http.Response {
7
15
  /**
8
16
  * HTTP status code.
9
17
  */
10
18
  readonly status: S;
11
19
  }
12
20
  /**
13
- * Common HTTP success response.
21
+ * HTTP success response.
14
22
  */
15
- export declare class HttpSuccessResponse<S extends HttpSuccessStatuses, T extends HttpJsonBody | HttpRawBody> implements HttpResponse {
23
+ export declare class HttpSuccessResponse<S extends HttpSuccessStatuses, T extends Http.JsonBody | Http.RawBody> implements Http.Response {
16
24
  /**
17
25
  * HTTP status code.
18
26
  */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Json body payload.
3
+ */
4
+ export interface WebJsonBody {
5
+ }
6
+ /**
7
+ * Raw body payload.
8
+ */
9
+ export type WebRawBody = string;
10
+ /**
11
+ * Body payload.
12
+ */
13
+ export type WebBody = WebJsonBody | WebRawBody;
@@ -0,0 +1,22 @@
1
+ import type { WebPreferences } from './preferences';
2
+ /**
3
+ * Default service parameters.
4
+ */
5
+ export interface WebDefaults {
6
+ /**
7
+ * Default preferences for all handlers.
8
+ */
9
+ readonly preferences?: WebPreferences;
10
+ /**
11
+ * Default log retention (in days) for the handlers.
12
+ */
13
+ readonly logRetention?: number;
14
+ /**
15
+ * Default execution time (in seconds) for handlers.
16
+ */
17
+ readonly timeout?: number;
18
+ /**
19
+ * Default amount of memory available (in megabytes) for handlers.
20
+ */
21
+ readonly memory?: number;
22
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Request headers.
3
+ */
4
+ export interface WebHeaders {
5
+ }
6
+ /**
7
+ * Request path parameters.
8
+ */
9
+ export interface WebPathParameters {
10
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Request path parameters.
3
+ */
4
+ export interface WebPathParameters {
5
+ }
@@ -1,8 +1,8 @@
1
1
  import type { NamingStyle } from '@ez4/schema';
2
2
  /**
3
- * HTTP preferences configuration.
3
+ * Preferences configuration.
4
4
  */
5
- export interface HttpPreferences {
5
+ export interface WebPreferences {
6
6
  /**
7
7
  * Determines the naming style for the query strings and body payloads.
8
8
  */
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Request query strings.
3
+ */
4
+ export interface WebQueryStrings {
5
+ }
@@ -0,0 +1,27 @@
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
+ import type { WebPreferences } from './preferences';
3
+ /**
4
+ * Target configuration.
5
+ */
6
+ export interface WebTarget {
7
+ /**
8
+ * Target preference options.
9
+ */
10
+ readonly preferences?: WebPreferences;
11
+ /**
12
+ * Default log retention (in days) for the handlers.
13
+ */
14
+ readonly logRetention?: number;
15
+ /**
16
+ * Variables associated to the event.
17
+ */
18
+ readonly variables?: LinkedVariables;
19
+ /**
20
+ * Max execution time (in seconds) for the event.
21
+ */
22
+ readonly timeout?: number;
23
+ /**
24
+ * Amount of memory available (in megabytes) for the handler.
25
+ */
26
+ readonly memory?: number;
27
+ }
@@ -0,0 +1,19 @@
1
+ import type { Ws } from './contract';
2
+ /**
3
+ * WS client.
4
+ */
5
+ export interface WsClient<T extends Ws.JsonBody> {
6
+ /**
7
+ * Send a new JSON message to the connection.
8
+ *
9
+ * @param connectionId Connection identifier.
10
+ * @param message Message object.
11
+ */
12
+ sendMessage(connectionId: string, message: T): Promise<void>;
13
+ /**
14
+ * Terminate an active connection.
15
+ *
16
+ * @param connectionId Connection identifier.
17
+ */
18
+ disconnect(connectionId: string): Promise<void>;
19
+ }
@@ -0,0 +1,23 @@
1
+ import type { AuthHandler } from '../auth/handler';
2
+ import type { AuthRequest } from '../auth/request';
3
+ import type { WebTarget } from '../web/target';
4
+ import type { WsListener } from './listener';
5
+ import type { WsHandler } from './handler';
6
+ import type { WsEvent } from './event';
7
+ /**
8
+ * WS connect event.
9
+ */
10
+ export interface WsConnect<T extends WsEvent, U extends AuthRequest> extends WebTarget {
11
+ /**
12
+ * Life-cycle listener function for the event.
13
+ */
14
+ readonly listener?: WsListener<T>;
15
+ /**
16
+ * Entry-point authorizer handler function for the event.
17
+ */
18
+ readonly authorizer?: AuthHandler<U>;
19
+ /**
20
+ * Entry-point handler function for the event.
21
+ */
22
+ readonly handler: WsHandler<T>;
23
+ }
@@ -0,0 +1,108 @@
1
+ import type { Service as CommonService } from '@ez4/common';
2
+ import type { LinkedVariables } from '@ez4/project/library';
3
+ import type { AuthResponse as WsAuthResponse } from '../auth/response';
4
+ import type { AuthRequest as WsAuthRequest } from '../auth/request';
5
+ import type { WebJsonBody, WebRawBody } from '../web/body';
6
+ import type { WebPreferences } from '../web/preferences';
7
+ import type { AuthIdentity } from '../auth/identity';
8
+ import type { WebQueryStrings } from '../web/query';
9
+ import type { WebHeaders } from '../web/headers';
10
+ import type { WsEmptyEvent, WsEmptyRequest } from './utils';
11
+ import type { WsDisconnect } from './disconnect';
12
+ import type { WsDefaults } from './defaults';
13
+ import type { WsIncoming } from './incoming';
14
+ import type { WsListener } from './listener';
15
+ import type { WsResponse } from './response';
16
+ import type { WsRequest } from './request';
17
+ import type { WsHandler } from './handler';
18
+ import type { WsMessage } from './message';
19
+ import type { WsConnect } from './connect';
20
+ import type { WsClient } from './client';
21
+ import type { WsEvent } from './event';
22
+ /**
23
+ * Provide all contracts for a self-managed WS service.
24
+ */
25
+ export declare namespace Ws {
26
+ type Headers = WebHeaders;
27
+ type Identity = AuthIdentity;
28
+ type QueryStrings = WebQueryStrings;
29
+ type JsonBody = WebJsonBody;
30
+ type RawBody = WebRawBody;
31
+ type Preferences = WebPreferences;
32
+ type Request = WsRequest;
33
+ type Response = WsResponse;
34
+ type Event = WsEvent;
35
+ type AuthRequest = WsAuthRequest;
36
+ type AuthResponse = WsAuthResponse;
37
+ type Incoming<T extends Request | Event> = WsIncoming<T>;
38
+ type Listener<T extends Request | Event> = WsListener<T>;
39
+ type Handler<T extends Request | Event> = WsHandler<T>;
40
+ type Connect<T extends Event = Event, U extends AuthRequest = AuthRequest> = WsConnect<T, U>;
41
+ type Disconnect<T extends Event = Event> = WsDisconnect<T>;
42
+ type Message<T extends Request = Request> = WsMessage<T>;
43
+ type Defaults<T extends Request | Event = any> = WsDefaults<T>;
44
+ type ServiceEvent<T extends Request | Event = Event> = CommonService.AnyEvent<Incoming<T>>;
45
+ type EmptyRequest = WsEmptyRequest;
46
+ type EmptyEvent = WsEmptyEvent;
47
+ /**
48
+ * WS Defaults definition.
49
+ */
50
+ type UseDefaults<T extends Defaults<any>> = T;
51
+ /**
52
+ * WS Preferences definition.
53
+ */
54
+ type UsePreferences<T extends Preferences> = T;
55
+ /**
56
+ * WS Connect event definition.
57
+ */
58
+ type UseConnect<T extends Connect<any, any>> = T;
59
+ /**
60
+ * WS Disconnect event definition.
61
+ */
62
+ type UseDisconnect<T extends Disconnect<any>> = T;
63
+ /**
64
+ * WS Message event definition.
65
+ */
66
+ type UseMessage<T extends Message<any>> = T;
67
+ /**
68
+ * WS service.
69
+ */
70
+ abstract class Service<T extends JsonBody> implements CommonService.Provider {
71
+ /**
72
+ * All connection events.
73
+ */
74
+ abstract readonly connect: Connect<any, any>;
75
+ /**
76
+ * All disconnection events.
77
+ */
78
+ abstract readonly disconnect: Disconnect<any>;
79
+ /**
80
+ * All message events.
81
+ */
82
+ abstract readonly message: Message<any>;
83
+ /**
84
+ * Default gateway parameters.
85
+ */
86
+ readonly defaults?: Defaults<any>;
87
+ /**
88
+ * Display name for the service.
89
+ */
90
+ readonly name?: string;
91
+ /**
92
+ * Service stage name.
93
+ */
94
+ readonly stage?: string;
95
+ /**
96
+ * Service schema.
97
+ */
98
+ readonly schema: T;
99
+ /**
100
+ * Variables associated to all routes.
101
+ */
102
+ readonly variables?: LinkedVariables;
103
+ /**
104
+ * Service client.
105
+ */
106
+ readonly client: WsClient<T>;
107
+ }
108
+ }
@@ -0,0 +1,13 @@
1
+ import type { WebDefaults } from '../web/defaults';
2
+ import type { WsRequest } from './request';
3
+ import type { WsListener } from './listener';
4
+ import type { WsEvent } from './event';
5
+ /**
6
+ * Default WS service parameters.
7
+ */
8
+ export interface WsDefaults<T extends WsRequest | WsEvent> extends WebDefaults {
9
+ /**
10
+ * Default listener.
11
+ */
12
+ readonly listener?: WsListener<T>;
13
+ }
@@ -0,0 +1,17 @@
1
+ import type { WebTarget } from '../web/target';
2
+ import type { WsListener } from './listener';
3
+ import type { WsHandler } from './handler';
4
+ import type { WsEvent } from './event';
5
+ /**
6
+ * WS disconnect event.
7
+ */
8
+ export interface WsDisconnect<T extends WsEvent> extends WebTarget {
9
+ /**
10
+ * Life-cycle listener function for the event.
11
+ */
12
+ readonly listener?: WsListener<T>;
13
+ /**
14
+ * Entry-point handler function for the event.
15
+ */
16
+ readonly handler: WsHandler<T>;
17
+ }
@@ -0,0 +1,20 @@
1
+ import type { AuthIdentity } from '../auth/identity';
2
+ import type { WebQueryStrings } from '../web/query';
3
+ import type { WebHeaders } from '../web/headers';
4
+ /**
5
+ * WS event.
6
+ */
7
+ export interface WsEvent {
8
+ /**
9
+ * Expected HTTP headers.
10
+ */
11
+ readonly headers?: WebHeaders;
12
+ /**
13
+ * Expected HTTP query strings.
14
+ */
15
+ readonly query?: WebQueryStrings;
16
+ /**
17
+ * Expected identity.
18
+ */
19
+ readonly identity?: AuthIdentity;
20
+ }