@ez4/gateway 0.29.0 → 0.31.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 (51) hide show
  1. package/dist/client/operations.d.ts +9 -0
  2. package/dist/errors/access.d.ts +11 -0
  3. package/dist/errors/context.d.ts +8 -0
  4. package/dist/errors/provider.d.ts +8 -0
  5. package/dist/errors/service.d.ts +4 -1
  6. package/dist/library.cjs +291 -228
  7. package/dist/library.d.ts +5 -1
  8. package/dist/library.mjs +262 -200
  9. package/dist/main.cjs +9 -9
  10. package/dist/main.d.ts +1 -0
  11. package/dist/main.mjs +6 -6
  12. package/dist/metadata/access.d.ts +3 -0
  13. package/dist/metadata/authorizer.d.ts +1 -1
  14. package/dist/metadata/body.d.ts +1 -1
  15. package/dist/metadata/cache.d.ts +1 -1
  16. package/dist/metadata/context.d.ts +3 -0
  17. package/dist/metadata/cors.d.ts +1 -1
  18. package/dist/metadata/defaults.d.ts +1 -1
  19. package/dist/metadata/errors.d.ts +1 -1
  20. package/dist/metadata/handler.d.ts +1 -1
  21. package/dist/metadata/headers.d.ts +1 -1
  22. package/dist/metadata/identity.d.ts +1 -1
  23. package/dist/metadata/import.d.ts +6 -0
  24. package/dist/metadata/parameters.d.ts +1 -1
  25. package/dist/metadata/provider.d.ts +3 -0
  26. package/dist/metadata/query.d.ts +1 -1
  27. package/dist/metadata/request.d.ts +2 -2
  28. package/dist/metadata/response.d.ts +2 -3
  29. package/dist/metadata/route.d.ts +2 -1
  30. package/dist/metadata/schema.d.ts +1 -1
  31. package/dist/metadata/utils.d.ts +4 -1
  32. package/dist/services/client.d.ts +73 -0
  33. package/dist/services/common.d.ts +16 -2
  34. package/dist/services/contract.d.ts +51 -4
  35. package/dist/services/utils.d.ts +1 -1
  36. package/dist/triggers/service.d.ts +3 -0
  37. package/dist/types/common.d.ts +37 -28
  38. package/dist/types/import.d.ts +13 -0
  39. package/dist/types/service.d.ts +3 -2
  40. package/dist/utils/body.d.ts +4 -0
  41. package/dist/utils/client.d.ts +8 -0
  42. package/dist/utils/errors.d.ts +10 -1
  43. package/dist/utils/headers.d.ts +1 -1
  44. package/dist/utils/identity.d.ts +1 -1
  45. package/dist/utils/parameters.d.ts +2 -1
  46. package/dist/utils/query.d.ts +2 -1
  47. package/dist/utils/request.d.ts +6 -0
  48. package/dist/utils.cjs +47 -24
  49. package/dist/utils.d.ts +1 -0
  50. package/dist/utils.mjs +45 -24
  51. package/package.json +12 -8
package/dist/main.cjs CHANGED
@@ -1,17 +1,17 @@
1
- "use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(s,e)=>u(s,"name",{value:e,configurable:!0});var S=(s,e)=>{for(var t in e)u(s,t,{get:e[t],enumerable:!0})},q=(s,e,t,n)=>{if(e&&
1
+ "use strict";var c=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var p=(s,e)=>c(s,"name",{value:e,configurable:!0});var S=(s,e)=>{for(var t in e)c(s,t,{get:e[t],enumerable:!0})},f=(s,e,t,n)=>{if(e&&
2
2
  typeof e=="object"||typeof e=="function")for(let o of h(e))!g.call(s,o)&&o!==t&&
3
- u(s,o,{get:()=>e[o],enumerable:!(n=l(e,o))||n.enumerable});return s};var f=s=>q(u({},"__esModule",{value:!0}),s);var A={};S(A,{Http:()=>d,HttpBadRequestError:()=>c,HttpError:()=>r,HttpForbiddenError:()=>a,
4
- HttpInternalServerError:()=>H,HttpNotFoundError:()=>x,HttpUnauthorizedError:()=>i,
5
- HttpUnprocessableEntityError:()=>y,HttpUnsupportedMediaTypeError:()=>m});module.
6
- exports=f(A);var d;(s=>{})(d||={});var R=require("@ez4/common");var r=class extends R.ServiceError{constructor(t,n,o){super(n,o);this.status=t}static{
7
- p(this,"HttpError")}},c=class extends r{static{p(this,"HttpBadRequestError")}constructor(e,t){
3
+ c(s,o,{get:()=>e[o],enumerable:!(n=R(e,o))||n.enumerable});return s};var v=s=>f(c({},"__esModule",{value:!0}),s);var q={};S(q,{Http:()=>H,HttpBadRequestError:()=>u,HttpError:()=>r,HttpForbiddenError:()=>a,
4
+ HttpInternalServerError:()=>d,HttpNotFoundError:()=>m,HttpUnauthorizedError:()=>i,
5
+ HttpUnprocessableEntityError:()=>y,HttpUnsupportedMediaTypeError:()=>x});module.
6
+ exports=v(q);var H;(s=>{})(H||={});var l=require("@ez4/common");var r=class extends l.ServiceError{constructor(t,n,o){super(n,o);this.status=t}static{
7
+ p(this,"HttpError")}},u=class extends r{static{p(this,"HttpBadRequestError")}constructor(e,t){
8
8
  super(400,e||"Bad request",t)}},i=class extends r{static{p(this,"HttpUnauthorize\
9
9
  dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},a=class extends r{static{
10
- p(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},x=class extends r{static{
11
- p(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},m=class extends r{static{
10
+ p(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},m=class extends r{static{
11
+ p(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},x=class extends r{static{
12
12
  p(this,"HttpUnsupportedMediaTypeError")}constructor(e,t){super(415,e||"Unsupport\
13
13
  ed media type",t)}},y=class extends r{static{p(this,"HttpUnprocessableEntityErro\
14
- r")}constructor(e,t){super(422,e||"Unprocessable entity",t)}},H=class extends r{static{
14
+ r")}constructor(e,t){super(422,e||"Unprocessable entity",t)}},d=class extends r{static{
15
15
  p(this,"HttpInternalServerError")}constructor(e,t){super(500,e||"Internal server\
16
16
  error",t)}};0&&(module.exports={Http,HttpBadRequestError,HttpError,HttpForbiddenError,HttpInternalServerError,
17
17
  HttpNotFoundError,HttpUnauthorizedError,HttpUnprocessableEntityError,HttpUnsupportedMediaTypeError});
package/dist/main.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './services/contract';
2
2
  export * from './services/errors';
3
+ export { Client, ClientRequest, ClientResponse } from './services/client';
package/dist/main.mjs CHANGED
@@ -1,14 +1,14 @@
1
- var H=Object.defineProperty;var r=(s,e)=>H(s,"name",{value:e,configurable:!0});var d;(s=>{})(d||={});import{ServiceError as R}from"@ez4/common";var p=class extends R{constructor(t,m,y){super(m,y);this.status=t}static{r(this,
1
+ var d=Object.defineProperty;var r=(s,e)=>d(s,"name",{value:e,configurable:!0});var H;(s=>{})(H||={});import{ServiceError as l}from"@ez4/common";var p=class extends l{constructor(t,x,y){super(x,y);this.status=t}static{r(this,
2
2
  "HttpError")}},o=class extends p{static{r(this,"HttpBadRequestError")}constructor(e,t){
3
3
  super(400,e||"Bad request",t)}},n=class extends p{static{r(this,"HttpUnauthorize\
4
- dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},u=class extends p{static{
5
- r(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},c=class extends p{static{
4
+ dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},c=class extends p{static{
5
+ r(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},u=class extends p{static{
6
6
  r(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},i=class extends p{static{
7
7
  r(this,"HttpUnsupportedMediaTypeError")}constructor(e,t){super(415,e||"Unsupport\
8
8
  ed media type",t)}},a=class extends p{static{r(this,"HttpUnprocessableEntityErro\
9
- r")}constructor(e,t){super(422,e||"Unprocessable entity",t)}},x=class extends p{static{
9
+ r")}constructor(e,t){super(422,e||"Unprocessable entity",t)}},m=class extends p{static{
10
10
  r(this,"HttpInternalServerError")}constructor(e,t){super(500,e||"Internal server\
11
- error",t)}};export{d as Http,o as HttpBadRequestError,p as HttpError,u as HttpForbiddenError,
12
- x as HttpInternalServerError,c as HttpNotFoundError,n as HttpUnauthorizedError,a as HttpUnprocessableEntityError,
11
+ error",t)}};export{H as Http,o as HttpBadRequestError,p as HttpError,c as HttpForbiddenError,
12
+ m as HttpInternalServerError,u as HttpNotFoundError,n as HttpUnauthorizedError,a as HttpUnprocessableEntityError,
13
13
  i as HttpUnsupportedMediaTypeError};
14
14
  //# sourceMappingURL=main.mjs.map
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import type { HttpAccess } from '../types/common';
3
+ export declare const getHttpAccess: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAccess | undefined;
@@ -1,3 +1,3 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpAuthorizer } from '../types/common';
3
- export declare const getHttpAuthorizer: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAuthorizer | null;
3
+ export declare const getHttpAuthorizer: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAuthorizer | undefined;
@@ -1,5 +1,5 @@
1
1
  import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  import type { ArraySchema, ObjectSchema, UnionSchema } from '@ez4/schema/library';
3
3
  type TypeParent = TypeObject | TypeModel | TypeIntersection;
4
- export declare const getHttpBody: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema | ObjectSchema | UnionSchema | ArraySchema | null;
4
+ export declare const getHttpBody: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => ObjectSchema | UnionSchema | ArraySchema | import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema | undefined;
5
5
  export {};
@@ -1,3 +1,3 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpCache } from '../types/common';
3
- export declare const getHttpCache: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpCache | null;
3
+ export declare const getHttpCache: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpCache | undefined;
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import type { HttpContext } from '../types/common';
3
+ export declare const getHttpContext: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpContext | null;
@@ -1,3 +1,3 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpCors } from '../types/common';
3
- export declare const getHttpCors: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpCors | null;
3
+ export declare const getHttpCors: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpCors | undefined;
@@ -1,3 +1,3 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpDefaults } from '../types/common';
3
- export declare const getHttpDefaults: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpDefaults | null;
3
+ export declare const getHttpDefaults: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpDefaults | undefined;
@@ -1,4 +1,4 @@
1
1
  import type { AllType, ModelProperty, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpErrors } from '../types/common';
3
- export declare const getHttpErrors: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpErrors | null;
3
+ export declare const getHttpErrors: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpErrors | undefined;
4
4
  export declare const getErrorClasses: (member: ModelProperty, errorCode: number, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpErrors;
@@ -1,3 +1,3 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpHandler } from '../types/common';
3
- export declare const getHttpHandler: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpHandler | null;
3
+ export declare const getHttpHandler: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[], external: boolean) => HttpHandler | undefined;
@@ -1,4 +1,4 @@
1
1
  import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  type TypeParent = TypeObject | TypeModel | TypeIntersection;
3
- export declare const getHttpHeaders: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | null;
3
+ export declare const getHttpHeaders: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | undefined;
4
4
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  import type { ObjectSchema, UnionSchema } from '@ez4/schema/library';
3
3
  type TypeParent = TypeObject | TypeModel | TypeIntersection;
4
- export declare const getHttpIdentity: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => ObjectSchema | UnionSchema | null;
4
+ export declare const getHttpIdentity: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => ObjectSchema | UnionSchema | undefined;
5
5
  export {};
@@ -0,0 +1,6 @@
1
+ import type { SourceMap } from '@ez4/reflection';
2
+ import type { HttpImport } from '../types/import';
3
+ export declare const getHttpImports: (reflection: SourceMap) => {
4
+ services: Record<string, HttpImport>;
5
+ errors: Error[];
6
+ };
@@ -1,4 +1,4 @@
1
1
  import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  type TypeParent = TypeObject | TypeModel | TypeIntersection;
3
- export declare const getHttpParameters: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | null;
3
+ export declare const getHttpParameters: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | undefined;
4
4
  export {};
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import type { HttpProvider } from '../types/common';
3
+ export declare const getHttpProvider: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpProvider | undefined;
@@ -1,4 +1,4 @@
1
1
  import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  type TypeParent = TypeObject | TypeModel | TypeIntersection;
3
- export declare const getHttpQuery: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | null;
3
+ export declare const getHttpQuery: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | undefined;
4
4
  export {};
@@ -1,4 +1,4 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpAuthRequest, HttpRequest } from '../types/common';
3
- export declare const getHttpAuthRequest: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => (HttpAuthRequest & HttpRequest) | null;
4
- export declare const getHttpHandlerRequest: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => (HttpAuthRequest & HttpRequest) | null;
3
+ export declare const getHttpAuthRequest: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => (HttpAuthRequest & HttpRequest) | undefined;
4
+ export declare const getHttpHandlerRequest: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => (HttpAuthRequest & HttpRequest) | undefined;
@@ -1,5 +1,4 @@
1
1
  import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
- import type { Incomplete } from '@ez4/utils';
3
2
  import type { HttpAuthResponse, HttpResponse } from '../types/common';
4
- export declare const getHttpAuthResponse: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => Incomplete<HttpAuthResponse & HttpResponse> | null;
5
- export declare const getHttpHandlerResponse: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpResponse | null;
3
+ export declare const getHttpAuthResponse: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAuthResponse | undefined;
4
+ export declare const getHttpHandlerResponse: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpResponse | undefined;
@@ -1,3 +1,4 @@
1
1
  import type { ModelProperty, SourceMap, TypeModel } from '@ez4/reflection';
2
2
  import type { HttpRoute } from '../types/common';
3
- export declare const getHttpRoutes: (parent: TypeModel, member: ModelProperty, reflection: SourceMap, errorList: Error[]) => HttpRoute[];
3
+ export declare const getHttpLocalRoutes: (parent: TypeModel, member: ModelProperty, reflection: SourceMap, errorList: Error[]) => HttpRoute[] | undefined;
4
+ export declare const getHttpRemoteRoutes: (parent: TypeModel, member: ModelProperty, reflection: SourceMap, errorList: Error[]) => HttpRoute[] | undefined;
@@ -1,2 +1,2 @@
1
1
  import type { SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
- export declare const getSchemaFromType: (type: TypeObject | TypeModel | TypeIntersection, reflection: SourceMap) => import("@ez4/schema").ObjectSchema | null;
2
+ export declare const getSchemaFromType: (type: TypeObject | TypeModel | TypeIntersection, reflection: SourceMap) => import("@ez4/schema").ObjectSchema | undefined;
@@ -2,6 +2,8 @@ import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '
2
2
  import type { HttpPath } from '../types/common';
3
3
  export declare const isHttpPath: (path: string) => path is HttpPath;
4
4
  export declare const isHttpService: (type: AllType) => type is TypeClass;
5
+ export declare const isHttpImport: (type: AllType) => type is TypeClass;
6
+ export declare const isHttpProvider: (type: AllType) => type is TypeModel;
5
7
  export declare const isHttpRoute: (type: AllType) => type is TypeModel;
6
8
  export declare const isHttpAuthorizerRequest: (type: TypeModel) => boolean;
7
9
  export declare const isHttpHandlerRequest: (type: TypeModel) => boolean;
@@ -14,7 +16,8 @@ export declare const isHttpIdentity: (type: TypeModel) => boolean;
14
16
  export declare const isHttpQuery: (type: TypeModel) => boolean;
15
17
  export declare const isHttpParameters: (type: TypeModel) => boolean;
16
18
  export declare const isJsonBody: (type: TypeModel) => boolean;
17
- export declare const isHttpCors: (type: TypeModel) => boolean;
18
19
  export declare const isHttpCache: (type: TypeModel) => boolean;
20
+ export declare const isHttpAccess: (type: TypeModel) => boolean;
21
+ export declare const isHttpCors: (type: TypeModel) => boolean;
19
22
  export declare const isHttpAuthorizer: (type: AllType) => type is TypeCallback | TypeFunction;
20
23
  export declare const isHttpHandler: (type: AllType) => type is TypeCallback | TypeFunction;
@@ -0,0 +1,73 @@
1
+ import type { AnyObject, Prettify } from '@ez4/utils';
2
+ import type { Http } from './contract';
3
+ /**
4
+ * HTTP client.
5
+ */
6
+ export type Client<T extends Http.Service> = {
7
+ [P in ClientRoutes<T> as P extends {
8
+ name: infer N;
9
+ } ? (N extends string ? N : never) : never]: P extends {
10
+ handler: infer H;
11
+ authorizer: infer A;
12
+ } ? AuthorizedClientOperation<H, A> : P extends {
13
+ handler: infer H;
14
+ } ? ClientOperation<H> : never;
15
+ };
16
+ /**
17
+ * Default HTTP client request.
18
+ */
19
+ export type ClientRequest = RequestOptions & {
20
+ headers?: Record<string, string>;
21
+ parameters?: Record<string, string>;
22
+ query?: Record<string, string>;
23
+ body?: string | AnyObject;
24
+ };
25
+ /**
26
+ * Default HTTP response.
27
+ */
28
+ export type ClientResponse = {
29
+ status: number;
30
+ body?: unknown;
31
+ };
32
+ /**
33
+ * Given a HTTP service `T`, it produces a union type containing all gateway routes.
34
+ */
35
+ type ClientRoutes<T extends Http.Service> = T extends {
36
+ routes: (infer R)[];
37
+ } ? R : never;
38
+ /**
39
+ * Given a handler type `T`, it produces a callback to invoke the operation.
40
+ */
41
+ type ClientOperation<T> = T extends (...args: any) => any ? (request: OperationRequest<T>) => OperationResponse<T> : never;
42
+ /**
43
+ * Given a handler type `T`, it produces a request type.
44
+ */
45
+ type OperationRequest<T extends (...args: any) => any> = Prettify<RequestSchema<Parameters<T>[0]> & RequestOptions>;
46
+ /**
47
+ * Given a handler type `T`, it produces a callback to invoke the operation.
48
+ */
49
+ type AuthorizedClientOperation<T, U> = T extends (...args: any) => any ? U extends (...args: any) => any ? (request: AuthorizedOperationRequest<T, U>) => OperationResponse<T> : never : never;
50
+ /**
51
+ * Given a handler type `T`, it produces a request type.
52
+ */
53
+ type AuthorizedOperationRequest<T extends (...args: any) => any, U extends (...args: any) => any> = Prettify<RequestSchema<Parameters<T>[0]> & RequestSchema<Parameters<U>[0]> & RequestOptions>;
54
+ /**
55
+ * Given a handler type `T`, it produces a response type.
56
+ */
57
+ type OperationResponse<T extends (...args: any) => any> = Promise<Awaited<ReturnType<T>>>;
58
+ /**
59
+ * Given a request type `T`, it produces a request schema containing only valid parameters.
60
+ */
61
+ type RequestSchema<T> = T extends AnyObject ? {
62
+ [P in keyof T as P extends 'parameters' | 'headers' | 'query' | 'body' ? P : never]: T[P];
63
+ } : never;
64
+ /**
65
+ * All request options.
66
+ */
67
+ type RequestOptions = {
68
+ /**
69
+ * Maximum wait time for a response.
70
+ */
71
+ timeout?: number;
72
+ };
73
+ export {};
@@ -1,5 +1,6 @@
1
- import type { Service } from '@ez4/common';
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
2
  import type { NamingStyle } from '@ez4/schema';
3
+ import type { Service } from '@ez4/common';
3
4
  import type { Http } from './contract';
4
5
  /**
5
6
  * Contract for HTTP preferences.
@@ -40,7 +41,7 @@ export interface HttpCors {
40
41
  maxAge?: number;
41
42
  }
42
43
  /**
43
- * HTTP cache.
44
+ * HTTP cache configuration.
44
45
  */
45
46
  export interface HttpCache {
46
47
  /**
@@ -48,6 +49,15 @@ export interface HttpCache {
48
49
  */
49
50
  authorizerTTL: number;
50
51
  }
52
+ /**
53
+ * HTTP access configuration.
54
+ */
55
+ export interface HttpAccess {
56
+ /**
57
+ * Log retention (in days) for the access log.
58
+ */
59
+ logRetention: number;
60
+ }
51
61
  /**
52
62
  * Request headers.
53
63
  */
@@ -158,6 +168,10 @@ export interface HttpResponse {
158
168
  body?: HttpJsonBody | HttpRawBody;
159
169
  }
160
170
  export interface HttpProvider {
171
+ /**
172
+ * Variables associated to the provider.
173
+ */
174
+ variables?: LinkedVariables;
161
175
  /**
162
176
  * All services associated to the provider.
163
177
  */
@@ -1,8 +1,9 @@
1
1
  import type { Service as CommonService } from '@ez4/common';
2
2
  import type { LinkedVariables } from '@ez4/project/library';
3
3
  import type { HttpPath } from '../types/common';
4
- import type { HttpSuccessStatuses, HttpEmptySuccessResponse, HttpSuccessResponse } from './utils';
5
- import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpPreferences, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpCors } from './common';
4
+ import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse } from './utils';
5
+ import type { Client } from './client';
6
+ import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpPreferences, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpAccess, HttpCors } from './common';
6
7
  /**
7
8
  * Provide all contracts for a self-managed HTTP service.
8
9
  */
@@ -21,18 +22,23 @@ export declare namespace Http {
21
22
  type Errors = HttpErrors;
22
23
  type Provider = HttpProvider;
23
24
  type Cache = HttpCache;
25
+ type Access = HttpAccess;
24
26
  type Cors = HttpCors;
25
27
  type Incoming<T extends Request | AuthRequest> = HttpIncoming<T>;
26
28
  type Listener<T extends Request | AuthRequest> = HttpListener<T>;
27
29
  type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
28
30
  type Handler<T extends Request> = HttpHandler<T>;
29
31
  type ServiceEvent<T extends Request | AuthRequest = Request> = CommonService.AnyEvent<Incoming<T>>;
30
- type EmptySuccessResponse<S extends HttpSuccessStatuses = 204> = HttpEmptySuccessResponse<S>;
32
+ type SuccessEmptyResponse<S extends HttpSuccessStatuses = 204> = HttpSuccessEmptyResponse<S>;
31
33
  type SuccessResponse<S extends HttpSuccessStatuses, T extends HttpRawBody | HttpJsonBody> = HttpSuccessResponse<S, T>;
32
34
  /**
33
35
  * HTTP route.
34
36
  */
35
37
  interface Route<T extends Request = Request, U extends AuthRequest = AuthRequest> {
38
+ /**
39
+ * Route name.
40
+ */
41
+ name?: string;
36
42
  /**
37
43
  * Route path.
38
44
  */
@@ -127,6 +133,10 @@ export declare namespace Http {
127
133
  * Cache configuration.
128
134
  */
129
135
  cache?: Cache;
136
+ /**
137
+ * Access configuration.
138
+ */
139
+ access?: Access;
130
140
  /**
131
141
  * Variables associated to all routes.
132
142
  */
@@ -134,6 +144,43 @@ export declare namespace Http {
134
144
  /**
135
145
  * Service client.
136
146
  */
137
- client: never;
147
+ client: Client<Service>;
148
+ }
149
+ /**
150
+ * Imported HTTP service.
151
+ */
152
+ abstract class Import<T extends Service> implements CommonService.Provider {
153
+ /**
154
+ * Name of the imported project defined in the project options file.
155
+ */
156
+ abstract project: string;
157
+ /**
158
+ * Imported service reference.
159
+ */
160
+ reference: T;
161
+ /**
162
+ * All routes attached to the imported service (do not replace).
163
+ */
164
+ routes: T['routes'];
165
+ /**
166
+ * Display name for the service imported service (do not replace).
167
+ */
168
+ name: T['name'];
169
+ /**
170
+ * All default configurations attached to the imported service (do not replace).
171
+ */
172
+ defaults: T['defaults'];
173
+ /**
174
+ * Imported service client (do not replace).
175
+ */
176
+ client: Client<T>;
177
+ /**
178
+ * Variables are not allowed.
179
+ */
180
+ variables: never;
181
+ /**
182
+ * Services are not allowed.
183
+ */
184
+ service: never;
138
185
  }
139
186
  }
@@ -3,7 +3,7 @@ export type HttpSuccessStatuses = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207
3
3
  /**
4
4
  * Common HTTP success response without a response body.
5
5
  */
6
- export declare class HttpEmptySuccessResponse<S extends HttpSuccessStatuses> implements HttpResponse {
6
+ export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> implements HttpResponse {
7
7
  /**
8
8
  * HTTP status code.
9
9
  */
@@ -0,0 +1,3 @@
1
+ import type { TypeClass } from '@ez4/reflection';
2
+ export declare const getLinkedService: (declaration: TypeClass) => string | null;
3
+ export declare const getLinkedImport: (declaration: TypeClass) => string | null;
@@ -1,5 +1,5 @@
1
1
  import type { ArraySchema, NamingStyle, ObjectSchema, ScalarSchema, UnionSchema } from '@ez4/schema';
2
- import type { LinkedVariables } from '@ez4/project/library';
2
+ import type { LinkedServices, LinkedVariables } from '@ez4/project/library';
3
3
  import type { ServiceListener } from '@ez4/common/library';
4
4
  export type HttpVerb = 'ANY' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
5
5
  export type HttpPath = `${HttpVerb} /${string}`;
@@ -7,32 +7,33 @@ export type HttpPreferences = {
7
7
  namingStyle?: NamingStyle;
8
8
  };
9
9
  export type HttpAuthRequest = {
10
- headers?: ObjectSchema | null;
11
- parameters?: ObjectSchema | null;
12
- query?: ObjectSchema | null;
10
+ headers?: ObjectSchema;
11
+ parameters?: ObjectSchema;
12
+ query?: ObjectSchema;
13
13
  };
14
14
  export type HttpAuthResponse = {
15
- identity?: ObjectSchema | UnionSchema | null;
15
+ identity?: ObjectSchema | UnionSchema;
16
16
  };
17
17
  export type HttpRequest = {
18
- identity?: ObjectSchema | UnionSchema | null;
19
- headers?: ObjectSchema | null;
20
- parameters?: ObjectSchema | null;
21
- query?: ObjectSchema | null;
22
- body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema | null;
18
+ identity?: ObjectSchema | UnionSchema;
19
+ headers?: ObjectSchema;
20
+ parameters?: ObjectSchema;
21
+ query?: ObjectSchema;
22
+ body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
23
23
  };
24
24
  export type HttpResponse = {
25
- status: number;
26
- headers?: ObjectSchema | null;
27
- body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema | null;
25
+ status: number | number[];
26
+ headers?: ObjectSchema;
27
+ body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
28
28
  };
29
29
  export type HttpHandler = {
30
30
  name: string;
31
+ file: string;
32
+ module?: string;
31
33
  description?: string;
32
34
  response: HttpResponse;
33
35
  request?: HttpRequest;
34
- file: string;
35
- module?: string;
36
+ provider?: HttpProvider;
36
37
  };
37
38
  export type HttpAuthorizer = {
38
39
  name: string;
@@ -46,29 +47,33 @@ export type HttpErrors = {
46
47
  [name: string]: number;
47
48
  };
48
49
  export type HttpRoute = {
50
+ name?: string;
49
51
  path: HttpPath;
50
52
  handler: HttpHandler;
51
- listener?: ServiceListener | null;
52
- authorizer?: HttpAuthorizer | null;
53
- variables?: LinkedVariables | null;
54
- httpErrors?: HttpErrors | null;
53
+ listener?: ServiceListener;
54
+ authorizer?: HttpAuthorizer;
55
+ variables?: LinkedVariables;
56
+ httpErrors?: HttpErrors;
55
57
  preferences?: HttpPreferences;
56
- logRetention?: number | null;
57
- timeout?: number | null;
58
- memory?: number | null;
59
- cors?: boolean | null;
58
+ logRetention?: number;
59
+ timeout?: number;
60
+ memory?: number;
61
+ cors?: boolean;
60
62
  };
61
63
  export type HttpDefaults = {
62
- listener?: ServiceListener | null;
63
- httpErrors?: HttpErrors | null;
64
+ listener?: ServiceListener;
65
+ httpErrors?: HttpErrors;
64
66
  preferences?: HttpPreferences;
65
- logRetention?: number | null;
66
- timeout?: number | null;
67
- memory?: number | null;
67
+ logRetention?: number;
68
+ timeout?: number;
69
+ memory?: number;
68
70
  };
69
71
  export type HttpCache = {
70
72
  authorizerTTL?: number;
71
73
  };
74
+ export type HttpAccess = {
75
+ logRetention: number;
76
+ };
72
77
  export type HttpCors = {
73
78
  allowOrigins: string[];
74
79
  allowMethods?: string[];
@@ -77,3 +82,7 @@ export type HttpCors = {
77
82
  allowHeaders?: string[];
78
83
  maxAge?: number;
79
84
  };
85
+ export type HttpProvider = {
86
+ variables?: LinkedVariables;
87
+ services?: LinkedServices;
88
+ };
@@ -0,0 +1,13 @@
1
+ import type { ServiceMetadata } from '@ez4/project/library';
2
+ import type { HttpRoute, HttpDefaults } from './common';
3
+ export declare const ImportType = "@ez4/import:http";
4
+ export type HttpImport = ServiceMetadata & {
5
+ type: typeof ImportType;
6
+ reference: string;
7
+ project: string;
8
+ displayName?: string;
9
+ description?: string;
10
+ defaults?: HttpDefaults;
11
+ routes: HttpRoute[];
12
+ };
13
+ export declare const isHttpImport: (service: ServiceMetadata) => service is HttpImport;
@@ -1,5 +1,5 @@
1
1
  import type { ServiceMetadata } from '@ez4/project/library';
2
- import type { HttpRoute, HttpCors, HttpDefaults, HttpCache } from './common';
2
+ import type { HttpRoute, HttpCors, HttpDefaults, HttpCache, HttpAccess } from './common';
3
3
  export declare const ServiceType = "@ez4/http";
4
4
  export type HttpService = ServiceMetadata & {
5
5
  type: typeof ServiceType;
@@ -7,7 +7,8 @@ export type HttpService = ServiceMetadata & {
7
7
  description?: string;
8
8
  defaults?: HttpDefaults;
9
9
  routes: HttpRoute[];
10
- cors?: HttpCors;
11
10
  cache?: HttpCache;
11
+ access?: HttpAccess;
12
+ cors?: HttpCors;
12
13
  };
13
14
  export declare const isHttpService: (service: ServiceMetadata) => service is HttpService;
@@ -2,3 +2,7 @@ import type { AnySchema } from '@ez4/schema';
2
2
  import type { Http } from '../services/contract';
3
3
  export declare const getRequestBody: <T extends Http.JsonBody | Http.RawBody>(input: T | undefined, schema: AnySchema, preferences?: Http.Preferences | null) => Promise<T>;
4
4
  export declare const getResponseBody: (body: unknown, schema: AnySchema, preferences?: Http.Preferences) => unknown;
5
+ export declare const prepareBodyRequest: (body: unknown) => {
6
+ body: string;
7
+ json: boolean;
8
+ };
@@ -0,0 +1,8 @@
1
+ import { type AnySchema, type NamingStyle } from '@ez4/schema';
2
+ import type { ClientRequest, ClientResponse } from '../services/client';
3
+ export declare const getClientRequestUrl: (host: string, path: string, request: ClientRequest) => string;
4
+ export type SendClientRequest = ClientRequest & {
5
+ responseSchema?: AnySchema;
6
+ namingStyle?: NamingStyle;
7
+ };
8
+ export declare const sendClientRequest: (url: string, method: string, request: SendClientRequest) => Promise<ClientResponse>;
@@ -1,4 +1,4 @@
1
- import type { HttpError } from '@ez4/gateway';
1
+ import { HttpError } from '@ez4/gateway';
2
2
  /**
3
3
  * Get a JSON error response for the given HTTP error.
4
4
  *
@@ -11,3 +11,12 @@ export declare const getJsonError: ({ status, message, details }: HttpError) =>
11
11
  details: string[] | undefined;
12
12
  };
13
13
  };
14
+ /**
15
+ * Get a exception based on the given HTTP status code.
16
+ *
17
+ * @param status HTTP status code.
18
+ * @param message Exception message.
19
+ * @param details Exception details.
20
+ * @returns Returns the corresponding exception.
21
+ */
22
+ export declare const getHttpException: (status: number, message: string, details?: string[]) => HttpError;
@@ -1,3 +1,3 @@
1
1
  import type { ObjectSchema } from '@ez4/schema';
2
- import type { Http } from '@ez4/gateway';
2
+ import type { Http } from '../services/contract';
3
3
  export declare const getHeaders: <T extends Http.Headers>(input: T, schema: ObjectSchema) => Promise<T>;
@@ -1,3 +1,3 @@
1
1
  import type { ObjectSchema, UnionSchema } from '@ez4/schema';
2
- import type { Http } from '@ez4/gateway';
2
+ import type { Http } from '../services/contract';
3
3
  export declare const getIdentity: <T extends Http.Identity>(input: T, schema: ObjectSchema | UnionSchema) => Promise<T>;