@ez4/gateway 0.30.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.
- package/dist/client/operations.d.ts +9 -0
- package/dist/library.cjs +267 -240
- package/dist/library.d.ts +2 -0
- package/dist/library.mjs +260 -231
- package/dist/main.cjs +8 -8
- package/dist/main.d.ts +1 -0
- package/dist/main.mjs +4 -4
- package/dist/metadata/access.d.ts +1 -1
- package/dist/metadata/authorizer.d.ts +1 -1
- package/dist/metadata/body.d.ts +1 -1
- package/dist/metadata/cache.d.ts +1 -1
- package/dist/metadata/cors.d.ts +1 -1
- package/dist/metadata/defaults.d.ts +1 -1
- package/dist/metadata/errors.d.ts +1 -1
- package/dist/metadata/handler.d.ts +1 -1
- package/dist/metadata/headers.d.ts +1 -1
- package/dist/metadata/identity.d.ts +1 -1
- package/dist/metadata/import.d.ts +6 -0
- package/dist/metadata/parameters.d.ts +1 -1
- package/dist/metadata/provider.d.ts +1 -1
- package/dist/metadata/query.d.ts +1 -1
- package/dist/metadata/request.d.ts +2 -2
- package/dist/metadata/response.d.ts +2 -3
- package/dist/metadata/route.d.ts +2 -1
- package/dist/metadata/schema.d.ts +1 -1
- package/dist/metadata/utils.d.ts +1 -0
- package/dist/services/client.d.ts +73 -0
- package/dist/services/common.d.ts +6 -1
- package/dist/services/contract.d.ts +43 -1
- package/dist/triggers/service.d.ts +1 -0
- package/dist/types/common.d.ts +26 -24
- package/dist/types/import.d.ts +13 -0
- package/dist/utils/body.d.ts +4 -0
- package/dist/utils/client.d.ts +8 -0
- package/dist/utils/errors.d.ts +10 -1
- package/dist/utils/headers.d.ts +1 -1
- package/dist/utils/identity.d.ts +1 -1
- package/dist/utils/parameters.d.ts +2 -1
- package/dist/utils/query.d.ts +2 -1
- package/dist/utils/request.d.ts +6 -0
- package/dist/utils.cjs +47 -24
- package/dist/utils.d.ts +1 -0
- package/dist/utils.mjs +45 -24
- package/package.json +8 -8
package/dist/main.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var
|
|
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
|
-
c(s,o,{get:()=>e[o],enumerable:!(n=
|
|
4
|
-
HttpInternalServerError:()=>
|
|
5
|
-
HttpUnprocessableEntityError:()=>y,HttpUnsupportedMediaTypeError:()=>
|
|
6
|
-
exports=q
|
|
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
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)}},
|
|
11
|
-
p(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},
|
|
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)}},
|
|
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
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
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
4
|
dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},c=class extends p{static{
|
|
@@ -6,9 +6,9 @@ r(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},u=cl
|
|
|
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)}},
|
|
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{
|
|
12
|
-
|
|
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
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { HttpAccess } from '../types/common';
|
|
3
|
-
export declare const getHttpAccess: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAccess |
|
|
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 |
|
|
3
|
+
export declare const getHttpAuthorizer: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAuthorizer | undefined;
|
package/dist/metadata/body.d.ts
CHANGED
|
@@ -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[]) => ObjectSchema | UnionSchema | ArraySchema | import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema |
|
|
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 {};
|
package/dist/metadata/cache.d.ts
CHANGED
|
@@ -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 |
|
|
3
|
+
export declare const getHttpCache: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpCache | undefined;
|
package/dist/metadata/cors.d.ts
CHANGED
|
@@ -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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
4
|
+
export declare const getHttpIdentity: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => ObjectSchema | UnionSchema | undefined;
|
|
5
5
|
export {};
|
|
@@ -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 |
|
|
3
|
+
export declare const getHttpParameters: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").ObjectSchema | undefined;
|
|
4
4
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { HttpProvider } from '../types/common';
|
|
3
|
-
export declare const getHttpProvider: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpProvider |
|
|
3
|
+
export declare const getHttpProvider: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpProvider | undefined;
|
package/dist/metadata/query.d.ts
CHANGED
|
@@ -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 |
|
|
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) |
|
|
4
|
-
export declare const getHttpHandlerRequest: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => (HttpAuthRequest & HttpRequest) |
|
|
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[]) =>
|
|
5
|
-
export declare const getHttpHandlerResponse: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpResponse |
|
|
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;
|
package/dist/metadata/route.d.ts
CHANGED
|
@@ -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
|
|
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 |
|
|
2
|
+
export declare const getSchemaFromType: (type: TypeObject | TypeModel | TypeIntersection, reflection: SourceMap) => import("@ez4/schema").ObjectSchema | undefined;
|
package/dist/metadata/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ 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;
|
|
5
6
|
export declare const isHttpProvider: (type: AllType) => type is TypeModel;
|
|
6
7
|
export declare const isHttpRoute: (type: AllType) => type is TypeModel;
|
|
7
8
|
export declare const isHttpAuthorizerRequest: (type: TypeModel) => boolean;
|
|
@@ -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 {
|
|
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.
|
|
@@ -167,6 +168,10 @@ export interface HttpResponse {
|
|
|
167
168
|
body?: HttpJsonBody | HttpRawBody;
|
|
168
169
|
}
|
|
169
170
|
export interface HttpProvider {
|
|
171
|
+
/**
|
|
172
|
+
* Variables associated to the provider.
|
|
173
|
+
*/
|
|
174
|
+
variables?: LinkedVariables;
|
|
170
175
|
/**
|
|
171
176
|
* All services associated to the provider.
|
|
172
177
|
*/
|
|
@@ -2,6 +2,7 @@ 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
4
|
import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse } from './utils';
|
|
5
|
+
import type { Client } from './client';
|
|
5
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.
|
|
@@ -34,6 +35,10 @@ export declare namespace Http {
|
|
|
34
35
|
* HTTP route.
|
|
35
36
|
*/
|
|
36
37
|
interface Route<T extends Request = Request, U extends AuthRequest = AuthRequest> {
|
|
38
|
+
/**
|
|
39
|
+
* Route name.
|
|
40
|
+
*/
|
|
41
|
+
name?: string;
|
|
37
42
|
/**
|
|
38
43
|
* Route path.
|
|
39
44
|
*/
|
|
@@ -139,6 +144,43 @@ export declare namespace Http {
|
|
|
139
144
|
/**
|
|
140
145
|
* Service client.
|
|
141
146
|
*/
|
|
142
|
-
client:
|
|
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;
|
|
143
185
|
}
|
|
144
186
|
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -7,24 +7,24 @@ export type HttpPreferences = {
|
|
|
7
7
|
namingStyle?: NamingStyle;
|
|
8
8
|
};
|
|
9
9
|
export type HttpAuthRequest = {
|
|
10
|
-
headers?: ObjectSchema
|
|
11
|
-
parameters?: ObjectSchema
|
|
12
|
-
query?: ObjectSchema
|
|
10
|
+
headers?: ObjectSchema;
|
|
11
|
+
parameters?: ObjectSchema;
|
|
12
|
+
query?: ObjectSchema;
|
|
13
13
|
};
|
|
14
14
|
export type HttpAuthResponse = {
|
|
15
|
-
identity?: ObjectSchema | UnionSchema
|
|
15
|
+
identity?: ObjectSchema | UnionSchema;
|
|
16
16
|
};
|
|
17
17
|
export type HttpRequest = {
|
|
18
|
-
identity?: ObjectSchema | UnionSchema
|
|
19
|
-
headers?: ObjectSchema
|
|
20
|
-
parameters?: ObjectSchema
|
|
21
|
-
query?: ObjectSchema
|
|
22
|
-
body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema
|
|
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
25
|
status: number | number[];
|
|
26
|
-
headers?: ObjectSchema
|
|
27
|
-
body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema
|
|
26
|
+
headers?: ObjectSchema;
|
|
27
|
+
body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
|
|
28
28
|
};
|
|
29
29
|
export type HttpHandler = {
|
|
30
30
|
name: string;
|
|
@@ -47,25 +47,26 @@ export type HttpErrors = {
|
|
|
47
47
|
[name: string]: number;
|
|
48
48
|
};
|
|
49
49
|
export type HttpRoute = {
|
|
50
|
+
name?: string;
|
|
50
51
|
path: HttpPath;
|
|
51
52
|
handler: HttpHandler;
|
|
52
|
-
listener?: ServiceListener
|
|
53
|
-
authorizer?: HttpAuthorizer
|
|
54
|
-
variables?: LinkedVariables
|
|
55
|
-
httpErrors?: HttpErrors
|
|
53
|
+
listener?: ServiceListener;
|
|
54
|
+
authorizer?: HttpAuthorizer;
|
|
55
|
+
variables?: LinkedVariables;
|
|
56
|
+
httpErrors?: HttpErrors;
|
|
56
57
|
preferences?: HttpPreferences;
|
|
57
|
-
logRetention?: number
|
|
58
|
-
timeout?: number
|
|
59
|
-
memory?: number
|
|
60
|
-
cors?: boolean
|
|
58
|
+
logRetention?: number;
|
|
59
|
+
timeout?: number;
|
|
60
|
+
memory?: number;
|
|
61
|
+
cors?: boolean;
|
|
61
62
|
};
|
|
62
63
|
export type HttpDefaults = {
|
|
63
|
-
listener?: ServiceListener
|
|
64
|
-
httpErrors?: HttpErrors
|
|
64
|
+
listener?: ServiceListener;
|
|
65
|
+
httpErrors?: HttpErrors;
|
|
65
66
|
preferences?: HttpPreferences;
|
|
66
|
-
logRetention?: number
|
|
67
|
-
timeout?: number
|
|
68
|
-
memory?: number
|
|
67
|
+
logRetention?: number;
|
|
68
|
+
timeout?: number;
|
|
69
|
+
memory?: number;
|
|
69
70
|
};
|
|
70
71
|
export type HttpCache = {
|
|
71
72
|
authorizerTTL?: number;
|
|
@@ -82,5 +83,6 @@ export type HttpCors = {
|
|
|
82
83
|
maxAge?: number;
|
|
83
84
|
};
|
|
84
85
|
export type HttpProvider = {
|
|
86
|
+
variables?: LinkedVariables;
|
|
85
87
|
services?: LinkedServices;
|
|
86
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;
|
package/dist/utils/body.d.ts
CHANGED
|
@@ -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>;
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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;
|
package/dist/utils/headers.d.ts
CHANGED
package/dist/utils/identity.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ObjectSchema, UnionSchema } from '@ez4/schema';
|
|
2
|
-
import type { Http } from '
|
|
2
|
+
import type { Http } from '../services/contract';
|
|
3
3
|
export declare const getIdentity: <T extends Http.Identity>(input: T, schema: ObjectSchema | UnionSchema) => Promise<T>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { ObjectSchema } from '@ez4/schema';
|
|
2
|
-
import type { Http } from '
|
|
2
|
+
import type { Http } from '../services/contract';
|
|
3
3
|
export declare const getPathParameters: <T extends Http.PathParameters>(input: T, schema: ObjectSchema) => Promise<T>;
|
|
4
|
+
export declare const preparePathParameters: (path: string, parameters: Record<string, string>) => string;
|
package/dist/utils/query.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { ObjectSchema } from '@ez4/schema';
|
|
2
|
-
import type { Http } from '
|
|
2
|
+
import type { Http } from '../services/contract';
|
|
3
3
|
export declare const getQueryStrings: <T extends Http.QueryStrings>(input: T, schema: ObjectSchema, preferences?: Http.Preferences | null) => Promise<T>;
|
|
4
|
+
export declare const prepareQueryStrings: <T extends Http.QueryStrings>(query: T) => string | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ClientRequest } from '../services/client';
|
|
2
|
+
export declare const prepareRequestUrl: (host: string, path: string, request: ClientRequest) => string;
|
|
3
|
+
export declare const sendClientRequest: (url: string, method: string, request: ClientRequest) => Promise<{
|
|
4
|
+
body?: any;
|
|
5
|
+
status: number;
|
|
6
|
+
}>;
|
package/dist/utils.cjs
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
$
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
1
|
+
"use strict";var x=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var s=(e,t)=>x(e,"name",{value:t,configurable:!0});var J=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},k=(e,t,r,o)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let n of Q(t))!V.call(e,n)&&n!==r&&
|
|
3
|
+
x(e,n,{get:()=>t[n],enumerable:!(o=N(t,n))||o.enumerable});return e};var F=e=>k(x({},"__esModule",{value:!0}),e);var et={};J(et,{getClientRequestUrl:()=>W,getHeaders:()=>Z,getHttpException:()=>C,
|
|
4
|
+
getIdentity:()=>tt,getJsonError:()=>D,getPathParameters:()=>_,getQueryStrings:()=>G,
|
|
5
|
+
getRequestBody:()=>K,getResponseBody:()=>L,prepareBodyRequest:()=>E,preparePathParameters:()=>q,
|
|
6
|
+
prepareQueryStrings:()=>R,sendClientRequest:()=>X});module.exports=F(et);var O=require("@ez4/schema"),H=require("@ez4/transform");var a=require("@ez4/gateway");var D=s(({status:e,message:t,details:r})=>({status:e,body:{message:t,details:r}}),
|
|
7
|
+
"getJsonError"),C=s((e,t,r)=>{switch(e){case 400:return new a.HttpBadRequestError(
|
|
8
|
+
t,r);case 401:return new a.HttpUnauthorizedError(t,r);case 403:return new a.HttpForbiddenError(
|
|
9
|
+
t,r);case 404:return new a.HttpNotFoundError(t,r);case 415:return new a.HttpUnsupportedMediaTypeError(
|
|
10
|
+
t,r);case 422:return new a.HttpUnprocessableEntityError(t,r);default:return new a.HttpError(
|
|
11
|
+
e,t,r)}},"getHttpException");var S=require("@ez4/transform"),f=require("@ez4/validator"),j=require("@ez4/gateway");var _=s(async(e,t)=>{let r=(0,S.transform)(e,t,(0,S.createTransformContext)({convert:!1})),
|
|
12
|
+
o=await(0,f.validate)(r,t,(0,f.createValidatorContext)({property:"$path"}));if(o.
|
|
13
|
+
length){let n=(0,f.getUniqueErrorMessages)(o);throw new j.HttpBadRequestError("M\
|
|
14
|
+
alformed path parameters.",n)}return r},"getPathParameters"),q=s((e,t)=>e.replaceAll(
|
|
15
|
+
/\{(\w+)\}/g,(r,o)=>o in t?`${t[o]}`:`{${o}}`),"preparePathParameters");var w=require("@ez4/transform"),u=require("@ez4/validator"),U=require("@ez4/gateway"),
|
|
16
|
+
$=require("@ez4/utils");var G=s(async(e,t,r)=>{let o=r?.namingStyle,n=(0,w.createTransformContext)({convert:!0,
|
|
17
|
+
inputStyle:o}),i=(0,w.transform)(e,t,n),c=(0,u.createValidatorContext)({property:"\
|
|
18
|
+
$query",pathStyle:o}),p=await(0,u.validate)(i,t,c);if(p.length){let m=(0,u.getUniqueErrorMessages)(
|
|
19
|
+
p);throw new U.HttpBadRequestError("Malformed query strings.",m)}return i},"getQ\
|
|
20
|
+
ueryStrings"),R=s(e=>{let t=[];for(let r in e){let o=e[r];if(!(0,$.isNullish)(o)){
|
|
21
|
+
if(o instanceof Date){t.push(`${r}=${encodeURIComponent(o.toISOString())}`);continue}
|
|
22
|
+
if(o instanceof Array){t.push(`${r}=${encodeURIComponent(o.join(","))}`);continue}
|
|
23
|
+
t.push(`${r}=${encodeURIComponent(`${o}`)}`)}}if(t.length)return t.join("&")},"p\
|
|
24
|
+
repareQueryStrings");var y=require("@ez4/transform"),d=require("@ez4/validator"),B=require("@ez4/gateway"),
|
|
25
|
+
M=require("@ez4/utils");var K=s(async(e,t,r)=>{let o=r?.namingStyle,n=(0,d.createValidatorContext)({property:"\
|
|
26
|
+
$body",inputStyle:o}),i=await(0,d.validate)(e,t,n);if(i.length){let m=(0,d.getUniqueErrorMessages)(
|
|
27
|
+
i);throw new B.HttpBadRequestError("Malformed body payload.",m)}let c=(0,y.createTransformContext)(
|
|
28
|
+
{convert:!1,inputStyle:o});return(0,y.transform)(e,t,c)},"getRequestBody"),L=s((e,t,r)=>{
|
|
29
|
+
let o=r?.namingStyle,n=(0,y.createTransformContext)({convert:!1,outputStyle:o});
|
|
30
|
+
return(0,y.transform)(e,t,n)},"getResponseBody"),E=s(e=>(0,M.isAnyString)(e)?{json:!1,
|
|
31
|
+
body:e}:{body:JSON.stringify(e),json:!0},"prepareBodyRequest");var W=s((e,t,r)=>{let{parameters:o,query:n}=r,i=o?q(t,o):t,c=n&&R(n),p=[e];return i&&
|
|
32
|
+
p.push(i),c&&p.push("?",c),p.join("")},"getClientRequestUrl"),X=s(async(e,t,r)=>{
|
|
33
|
+
let{headers:o,body:n,responseSchema:i,namingStyle:c,timeout:p=20}=r,m=n?E(n):void 0,
|
|
34
|
+
v=new AbortController,I=setTimeout(()=>v?.abort("Request timed out"),p),h=await fetch(
|
|
35
|
+
e,{signal:v?.signal,body:m?.body,method:t,headers:{...o,...m?.json&&{"content-ty\
|
|
36
|
+
pe":"application/json"}}});if(clearTimeout(I),!h.ok){let P=await h.json();throw C(
|
|
37
|
+
h.status,P.message,P.details)}let b=await h.text();return{status:h.status,...b&&
|
|
38
|
+
{body:Y(b,i,c)}}},"sendClientRequest"),Y=s((e,t,r)=>{if(!t||(0,O.isScalarSchema)(
|
|
39
|
+
t))return e;let o=JSON.parse(e),n=(0,H.createTransformContext)({inputStyle:r,convert:!1});
|
|
40
|
+
return(0,H.transform)(o,t,n)},"getResponseBody");var T=require("@ez4/transform"),l=require("@ez4/validator"),A=require("@ez4/gateway");var Z=s(async(e,t)=>{let r=(0,T.transform)(e,t,(0,T.createTransformContext)({convert:!1})),
|
|
41
|
+
o=await(0,l.validate)(r,t,(0,l.createValidatorContext)({property:"$header"}));if(o.
|
|
42
|
+
length){let n=(0,l.getUniqueErrorMessages)(o);throw new A.HttpBadRequestError("M\
|
|
43
|
+
alformed request headers.",n)}return r},"getHeaders");var g=require("@ez4/validator"),z=require("@ez4/gateway");var tt=s(async(e,t)=>{let r=await(0,g.validate)(e,t,(0,g.createValidatorContext)(
|
|
44
|
+
{property:"$identity"}));if(r.length){let o=(0,g.getUniqueErrorMessages)(r);throw new z.HttpBadRequestError(
|
|
45
|
+
"Malformed authorizer identity.",o)}return e},"getIdentity");0&&(module.exports={getClientRequestUrl,getHeaders,getHttpException,getIdentity,
|
|
46
|
+
getJsonError,getPathParameters,getQueryStrings,getRequestBody,getResponseBody,prepareBodyRequest,
|
|
47
|
+
preparePathParameters,prepareQueryStrings,sendClientRequest});
|
|
25
48
|
//# sourceMappingURL=utils.cjs.map
|