@webiny/handler 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.de38392959
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/Context.d.ts +17 -10
- package/Context.js +20 -17
- package/Context.js.map +1 -1
- package/ResponseHeaders.d.ts +25 -0
- package/ResponseHeaders.js +46 -0
- package/ResponseHeaders.js.map +1 -0
- package/fastify.d.ts +3 -2
- package/fastify.js +125 -149
- package/fastify.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +25 -32
- package/index.js.map +1 -1
- package/middleware.d.ts +4 -1
- package/middleware.js +4 -8
- package/middleware.js.map +1 -1
- package/package.json +16 -18
- package/plugins/BeforeHandlerPlugin.js +3 -14
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/EventPlugin.js +4 -12
- package/plugins/EventPlugin.js.map +1 -1
- package/plugins/HandlerErrorPlugin.d.ts +5 -2
- package/plugins/HandlerErrorPlugin.js +3 -13
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerOnRequestPlugin.js +9 -12
- package/plugins/HandlerOnRequestPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.js +3 -13
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/plugins/ModifyFastifyPlugin.js +3 -13
- package/plugins/ModifyFastifyPlugin.js.map +1 -1
- package/plugins/ModifyResponseHeadersPlugin.d.ts +14 -0
- package/plugins/ModifyResponseHeadersPlugin.js +24 -0
- package/plugins/ModifyResponseHeadersPlugin.js.map +1 -0
- package/plugins/RoutePlugin.js +3 -12
- package/plugins/RoutePlugin.js.map +1 -1
- package/types.d.ts +2 -7
- package/types.js +3 -1
- package/types.js.map +1 -1
package/Context.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import { Context as BaseContext, ContextParams as BaseContextParams } from "@webiny/api";
|
|
2
|
-
import { Context as
|
|
1
|
+
import { Context as BaseContext, ContextParams as BaseContextParams, ContextPlugin as BaseContextPlugin, ContextPluginCallable as BaseContextPluginCallable } from "@webiny/api";
|
|
2
|
+
import { Context as ContextInterface } from "./types";
|
|
3
3
|
export interface ContextParams extends BaseContextParams {
|
|
4
|
-
|
|
5
|
-
routes: BaseContextType["routes"];
|
|
4
|
+
routes: ContextInterface["routes"];
|
|
6
5
|
}
|
|
7
|
-
export declare class Context extends BaseContext implements
|
|
8
|
-
readonly
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
reply: BaseContextType["reply"];
|
|
6
|
+
export declare class Context extends BaseContext implements ContextInterface {
|
|
7
|
+
readonly routes: ContextInterface["routes"];
|
|
8
|
+
handlerClient: ContextInterface["handlerClient"];
|
|
9
|
+
request: ContextInterface["request"];
|
|
10
|
+
reply: ContextInterface["reply"];
|
|
13
11
|
constructor(params: ContextParams);
|
|
14
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
|
|
15
|
+
*
|
|
16
|
+
* This can be removed when we introduce the type augmentation.
|
|
17
|
+
*/
|
|
18
|
+
export declare type ContextPluginCallable<T extends ContextInterface = ContextInterface> = BaseContextPluginCallable<T>;
|
|
19
|
+
export declare class ContextPlugin<T extends ContextInterface = ContextInterface> extends BaseContextPlugin<T> {
|
|
20
|
+
}
|
|
21
|
+
export declare const createContextPlugin: <T extends ContextInterface = ContextInterface>(callable: ContextPluginCallable<T>) => BaseContextPlugin<T>;
|
package/Context.js
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports.Context = void 0;
|
|
6
|
+
exports.createContextPlugin = exports.ContextPlugin = exports.Context = void 0;
|
|
7
|
+
var _api = require("@webiny/api");
|
|
8
|
+
class Context extends _api.Context {
|
|
9
|
+
// @ts-expect-error
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
// @ts-expect-error
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
// @ts-expect-error
|
|
13
14
|
|
|
14
|
-
class Context extends _api.Context {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
// @ts-ignore
|
|
18
15
|
constructor(params) {
|
|
19
16
|
super(params);
|
|
20
|
-
(0, _defineProperty2.default)(this, "server", void 0);
|
|
21
|
-
(0, _defineProperty2.default)(this, "routes", void 0);
|
|
22
|
-
(0, _defineProperty2.default)(this, "handlerClient", void 0);
|
|
23
|
-
(0, _defineProperty2.default)(this, "request", void 0);
|
|
24
|
-
(0, _defineProperty2.default)(this, "reply", void 0);
|
|
25
|
-
this.server = params.server;
|
|
26
17
|
this.routes = params.routes;
|
|
27
18
|
}
|
|
28
|
-
|
|
29
19
|
}
|
|
30
20
|
|
|
31
|
-
|
|
21
|
+
/**
|
|
22
|
+
* We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
|
|
23
|
+
*
|
|
24
|
+
* This can be removed when we introduce the type augmentation.
|
|
25
|
+
*/
|
|
26
|
+
exports.Context = Context;
|
|
27
|
+
class ContextPlugin extends _api.ContextPlugin {}
|
|
28
|
+
exports.ContextPlugin = ContextPlugin;
|
|
29
|
+
const createContextPlugin = callable => {
|
|
30
|
+
return (0, _api.createContextPlugin)(callable);
|
|
31
|
+
};
|
|
32
|
+
exports.createContextPlugin = createContextPlugin;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=Context.js.map
|
package/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Context","BaseContext","constructor","params","
|
|
1
|
+
{"version":3,"names":["_api","require","Context","BaseContext","constructor","params","routes","exports","ContextPlugin","BaseContextPlugin","createContextPlugin","callable","baseCreateContextPlugin"],"sources":["Context.ts"],"sourcesContent":["import {\n Context as BaseContext,\n ContextParams as BaseContextParams,\n ContextPlugin as BaseContextPlugin,\n ContextPluginCallable as BaseContextPluginCallable,\n createContextPlugin as baseCreateContextPlugin\n} from \"@webiny/api\";\nimport { Context as ContextInterface } from \"~/types\";\n\nexport interface ContextParams extends BaseContextParams {\n routes: ContextInterface[\"routes\"];\n}\n\nexport class Context extends BaseContext implements ContextInterface {\n public readonly routes: ContextInterface[\"routes\"];\n // @ts-expect-error\n public handlerClient: ContextInterface[\"handlerClient\"];\n // @ts-expect-error\n public request: ContextInterface[\"request\"];\n // @ts-expect-error\n public reply: ContextInterface[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.routes = params.routes;\n }\n}\n\n/**\n * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.\n *\n * This can be removed when we introduce the type augmentation.\n */\nexport type ContextPluginCallable<T extends ContextInterface = ContextInterface> =\n BaseContextPluginCallable<T>;\n\nexport class ContextPlugin<\n T extends ContextInterface = ContextInterface\n> extends BaseContextPlugin<T> {}\n\nexport const createContextPlugin = <T extends ContextInterface = ContextInterface>(\n callable: ContextPluginCallable<T>\n) => {\n return baseCreateContextPlugin<T>(callable);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAaO,MAAMC,OAAO,SAASC,YAAW,CAA6B;EAEjE;;EAEA;;EAEA;;EAGOC,WAAWA,CAACC,MAAqB,EAAE;IACtC,KAAK,CAACA,MAAM,CAAC;IACb,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;AACJ;;AAEA;AACA;AACA;AACA;AACA;AAJAC,OAAA,CAAAL,OAAA,GAAAA,OAAA;AAQO,MAAMM,aAAa,SAEhBC,kBAAiB,CAAI;AAAEF,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAE1B,MAAME,mBAAmB,GAC5BC,QAAkC,IACjC;EACD,OAAO,IAAAC,wBAAuB,EAAID,QAAQ,CAAC;AAC/C,CAAC;AAACJ,OAAA,CAAAG,mBAAA,GAAAA,mBAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as http from "http";
|
|
3
|
+
declare type ExtraHeaders = {
|
|
4
|
+
"content-type"?: string | undefined;
|
|
5
|
+
"x-webiny-version"?: http.OutgoingHttpHeader | undefined;
|
|
6
|
+
};
|
|
7
|
+
declare type AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;
|
|
8
|
+
export declare type StandardHeaderValue = http.OutgoingHttpHeader | boolean | undefined;
|
|
9
|
+
export declare type StandardHeaders = {
|
|
10
|
+
[K in keyof AllHeaders as string extends K ? never : number extends K ? never : K]: http.OutgoingHttpHeaders[K];
|
|
11
|
+
} & {
|
|
12
|
+
[name: string]: StandardHeaderValue;
|
|
13
|
+
};
|
|
14
|
+
declare type Setter<T> = ((value: T) => T) | T;
|
|
15
|
+
export declare class ResponseHeaders {
|
|
16
|
+
private readonly headers;
|
|
17
|
+
private constructor();
|
|
18
|
+
set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>): this;
|
|
19
|
+
merge(headers: ResponseHeaders): ResponseHeaders;
|
|
20
|
+
getHeaders(): {
|
|
21
|
+
[k: string]: StandardHeaderValue;
|
|
22
|
+
};
|
|
23
|
+
static create(initialHeaders?: StandardHeaders): ResponseHeaders;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ResponseHeaders = void 0;
|
|
7
|
+
// Extract known standard headers, and remove all non-string keys.
|
|
8
|
+
|
|
9
|
+
function isFunction(setter) {
|
|
10
|
+
return typeof setter === "function";
|
|
11
|
+
}
|
|
12
|
+
class ResponseHeaders {
|
|
13
|
+
headers = new Map();
|
|
14
|
+
constructor(initialHeaders) {
|
|
15
|
+
if (initialHeaders) {
|
|
16
|
+
Object.keys(initialHeaders).forEach(key => {
|
|
17
|
+
this.headers.set(key, initialHeaders[key]);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
set(header, setter) {
|
|
22
|
+
if (isFunction(setter)) {
|
|
23
|
+
const previousValue = this.headers.get(header);
|
|
24
|
+
const newValue = setter(previousValue);
|
|
25
|
+
this.headers.set(header, newValue);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
this.headers.set(header, setter);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
merge(headers) {
|
|
32
|
+
return ResponseHeaders.create({
|
|
33
|
+
...this.getHeaders(),
|
|
34
|
+
...headers.getHeaders()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getHeaders() {
|
|
38
|
+
return Object.fromEntries(this.headers);
|
|
39
|
+
}
|
|
40
|
+
static create(initialHeaders) {
|
|
41
|
+
return new ResponseHeaders(initialHeaders);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ResponseHeaders = ResponseHeaders;
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=ResponseHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isFunction","setter","ResponseHeaders","headers","Map","constructor","initialHeaders","Object","keys","forEach","key","set","header","previousValue","get","newValue","merge","create","getHeaders","fromEntries","exports"],"sources":["ResponseHeaders.ts"],"sourcesContent":["import * as http from \"http\";\n\ntype ExtraHeaders = {\n \"content-type\"?: string | undefined;\n \"x-webiny-version\"?: http.OutgoingHttpHeader | undefined;\n};\n\ntype AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;\n\nexport type StandardHeaderValue = http.OutgoingHttpHeader | boolean | undefined;\n\n// Extract known standard headers, and remove all non-string keys.\nexport type StandardHeaders = {\n [K in keyof AllHeaders as string extends K\n ? never\n : number extends K\n ? never\n : K]: http.OutgoingHttpHeaders[K];\n} & {\n [name: string]: StandardHeaderValue;\n};\n\nfunction isFunction<T>(setter: unknown): setter is (value: T) => T {\n return typeof setter === \"function\";\n}\n\ntype Setter<T> = ((value: T) => T) | T;\n\nexport class ResponseHeaders {\n private readonly headers = new Map<keyof StandardHeaders, StandardHeaderValue>();\n\n private constructor(initialHeaders?: StandardHeaders) {\n if (initialHeaders) {\n (Object.keys(initialHeaders) as Array<keyof StandardHeaders>).forEach(key => {\n this.headers.set(key, initialHeaders[key]);\n });\n }\n }\n\n set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>) {\n if (isFunction<StandardHeaders[T]>(setter)) {\n const previousValue = this.headers.get(header) as StandardHeaders[T];\n const newValue = setter(previousValue);\n this.headers.set(header, newValue);\n return this;\n }\n\n this.headers.set(header, setter);\n\n return this;\n }\n\n merge(headers: ResponseHeaders) {\n return ResponseHeaders.create({ ...this.getHeaders(), ...headers.getHeaders() });\n }\n\n getHeaders() {\n return Object.fromEntries(this.headers);\n }\n\n static create(initialHeaders?: StandardHeaders) {\n return new ResponseHeaders(initialHeaders);\n }\n}\n"],"mappings":";;;;;;AAWA;;AAWA,SAASA,UAAUA,CAAIC,MAAe,EAA6B;EAC/D,OAAO,OAAOA,MAAM,KAAK,UAAU;AACvC;AAIO,MAAMC,eAAe,CAAC;EACRC,OAAO,GAAG,IAAIC,GAAG,CAA6C,CAAC;EAExEC,WAAWA,CAACC,cAAgC,EAAE;IAClD,IAAIA,cAAc,EAAE;MACfC,MAAM,CAACC,IAAI,CAACF,cAAc,CAAC,CAAkCG,OAAO,CAACC,GAAG,IAAI;QACzE,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACD,GAAG,EAAEJ,cAAc,CAACI,GAAG,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;EAEAC,GAAGA,CAAkCC,MAAS,EAAEX,MAAkC,EAAE;IAChF,IAAID,UAAU,CAAqBC,MAAM,CAAC,EAAE;MACxC,MAAMY,aAAa,GAAG,IAAI,CAACV,OAAO,CAACW,GAAG,CAACF,MAAM,CAAuB;MACpE,MAAMG,QAAQ,GAAGd,MAAM,CAACY,aAAa,CAAC;MACtC,IAAI,CAACV,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEG,QAAQ,CAAC;MAClC,OAAO,IAAI;IACf;IAEA,IAAI,CAACZ,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEX,MAAM,CAAC;IAEhC,OAAO,IAAI;EACf;EAEAe,KAAKA,CAACb,OAAwB,EAAE;IAC5B,OAAOD,eAAe,CAACe,MAAM,CAAC;MAAE,GAAG,IAAI,CAACC,UAAU,CAAC,CAAC;MAAE,GAAGf,OAAO,CAACe,UAAU,CAAC;IAAE,CAAC,CAAC;EACpF;EAEAA,UAAUA,CAAA,EAAG;IACT,OAAOX,MAAM,CAACY,WAAW,CAAC,IAAI,CAAChB,OAAO,CAAC;EAC3C;EAEA,OAAOc,MAAMA,CAACX,cAAgC,EAAE;IAC5C,OAAO,IAAIJ,eAAe,CAACI,cAAc,CAAC;EAC9C;AACJ;AAACc,OAAA,CAAAlB,eAAA,GAAAA,eAAA"}
|
package/fastify.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PluginCollection } from "@webiny/plugins/types";
|
|
2
|
+
import { PluginCollection, PluginsContainer } from "@webiny/plugins/types";
|
|
3
3
|
import { FastifyServerOptions as ServerOptions } from "fastify";
|
|
4
4
|
export interface CreateHandlerParams {
|
|
5
|
-
plugins: PluginCollection;
|
|
5
|
+
plugins: PluginCollection | PluginsContainer;
|
|
6
6
|
options?: ServerOptions;
|
|
7
|
+
debug?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const createHandler: (params: CreateHandlerParams) => import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
|