@webiny/handler 0.0.0-ee-vpcs.549378cf03
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 +13 -0
- package/Context.js +29 -0
- package/Context.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/fastify.d.ts +8 -0
- package/fastify.js +407 -0
- package/fastify.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +135 -0
- package/index.js.map +1 -0
- package/middleware.d.ts +4 -0
- package/middleware.js +51 -0
- package/middleware.js.map +1 -0
- package/package.json +47 -0
- package/plugins/BeforeHandlerPlugin.d.ts +12 -0
- package/plugins/BeforeHandlerPlugin.js +38 -0
- package/plugins/BeforeHandlerPlugin.js.map +1 -0
- package/plugins/EventPlugin.d.ts +25 -0
- package/plugins/EventPlugin.js +38 -0
- package/plugins/EventPlugin.js.map +1 -0
- package/plugins/HandlerErrorPlugin.d.ts +12 -0
- package/plugins/HandlerErrorPlugin.js +34 -0
- package/plugins/HandlerErrorPlugin.js.map +1 -0
- package/plugins/HandlerOnRequestPlugin.d.ts +20 -0
- package/plugins/HandlerOnRequestPlugin.js +34 -0
- package/plugins/HandlerOnRequestPlugin.js.map +1 -0
- package/plugins/HandlerResultPlugin.d.ts +12 -0
- package/plugins/HandlerResultPlugin.js +34 -0
- package/plugins/HandlerResultPlugin.js.map +1 -0
- package/plugins/ModifyFastifyPlugin.d.ts +13 -0
- package/plugins/ModifyFastifyPlugin.js +34 -0
- package/plugins/ModifyFastifyPlugin.js.map +1 -0
- package/plugins/RoutePlugin.d.ts +23 -0
- package/plugins/RoutePlugin.js +30 -0
- package/plugins/RoutePlugin.js.map +1 -0
- package/types.d.ts +45 -0
- package/types.js +19 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createRoute = exports.RoutePlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
+
|
|
14
|
+
class RoutePlugin extends _Plugin.Plugin {
|
|
15
|
+
constructor(cb) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
|
+
this.cb = cb;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.RoutePlugin = RoutePlugin;
|
|
24
|
+
(0, _defineProperty2.default)(RoutePlugin, "type", "handler.fastify.route");
|
|
25
|
+
|
|
26
|
+
const createRoute = cb => {
|
|
27
|
+
return new RoutePlugin(cb);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.createRoute = createRoute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RoutePlugin","Plugin","constructor","cb","createRoute"],"sources":["RoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, RouteMethod } from \"~/types\";\n\ninterface RoutePluginCbParams<T extends Context> {\n context: T;\n onGet: RouteMethod;\n onPost: RouteMethod;\n onPut: RouteMethod;\n onPatch: RouteMethod;\n onDelete: RouteMethod;\n onOptions: RouteMethod;\n onAll: RouteMethod;\n onHead: RouteMethod;\n}\nexport interface RoutePluginCb<T extends Context> {\n (params: RoutePluginCbParams<T>): void;\n}\n\nexport class RoutePlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.fastify.route\";\n\n public readonly cb: RoutePluginCb<T>;\n\n public constructor(cb: RoutePluginCb<T>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createRoute = <T extends Context = Context>(cb: RoutePluginCb<T>): RoutePlugin<T> => {\n return new RoutePlugin<T>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAkBO,MAAMA,WAAN,SAAuDC,cAAvD,CAA8D;EAK1DC,WAAW,CAACC,EAAD,EAAuB;IACrC;IADqC;IAErC,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARgE;;;8BAAxDH,W,UACsC,uB;;AAU5C,MAAMI,WAAW,GAAiCD,EAA9B,IAAuE;EAC9F,OAAO,IAAIH,WAAJ,CAAmBG,EAAnB,CAAP;AACH,CAFM"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
|
|
2
|
+
export { FastifyInstance, HTTPMethods } from "fastify";
|
|
3
|
+
import { ClientContext } from "@webiny/handler-client/types";
|
|
4
|
+
export interface RouteMethodOptions {
|
|
5
|
+
override?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare type RouteMethodPath = `/${string}` | "*";
|
|
8
|
+
export interface RouteMethod {
|
|
9
|
+
(path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;
|
|
10
|
+
}
|
|
11
|
+
export declare type Request = FastifyRequest;
|
|
12
|
+
export declare type Reply = FastifyReply;
|
|
13
|
+
export declare type DefinedContextRoutes = Record<HTTPMethods, string[]>;
|
|
14
|
+
export interface ContextRoutes {
|
|
15
|
+
defined: DefinedContextRoutes;
|
|
16
|
+
onGet: RouteMethod;
|
|
17
|
+
onPost: RouteMethod;
|
|
18
|
+
onPut: RouteMethod;
|
|
19
|
+
onPatch: RouteMethod;
|
|
20
|
+
onDelete: RouteMethod;
|
|
21
|
+
onOptions: RouteMethod;
|
|
22
|
+
onAll: RouteMethod;
|
|
23
|
+
onHead: RouteMethod;
|
|
24
|
+
}
|
|
25
|
+
export interface Context extends ClientContext {
|
|
26
|
+
/**
|
|
27
|
+
* An instance of fastify server.
|
|
28
|
+
* Use at your own risk.
|
|
29
|
+
* @instance
|
|
30
|
+
*/
|
|
31
|
+
server: FastifyInstance;
|
|
32
|
+
/**
|
|
33
|
+
* Current request. Must be set only once!
|
|
34
|
+
*/
|
|
35
|
+
request: FastifyRequest;
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
routes: ContextRoutes;
|
|
40
|
+
}
|
|
41
|
+
declare module "fastify" {
|
|
42
|
+
interface FastifyInstance {
|
|
43
|
+
webiny: Context;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FastifyInstance", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _fastify.FastifyInstance;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "HTTPMethods", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _fastify.HTTPMethods;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _fastify = require("fastify");
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n FastifyInstance,\n FastifyRequest,\n FastifyReply,\n HTTPMethods,\n RouteHandlerMethod\n} from \"fastify\";\n\nexport { FastifyInstance, HTTPMethods } from \"fastify\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\n\nexport interface RouteMethodOptions {\n override?: boolean;\n}\n\nexport type RouteMethodPath = `/${string}` | \"*\";\nexport interface RouteMethod {\n (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;\n}\n\nexport type Request = FastifyRequest;\nexport type Reply = FastifyReply;\n\nexport type DefinedContextRoutes = Record<HTTPMethods, string[]>;\nexport interface ContextRoutes {\n defined: DefinedContextRoutes;\n onGet: RouteMethod;\n onPost: RouteMethod;\n onPut: RouteMethod;\n onPatch: RouteMethod;\n onDelete: RouteMethod;\n onOptions: RouteMethod;\n onAll: RouteMethod;\n onHead: RouteMethod;\n}\n\nexport interface Context extends ClientContext {\n /**\n * An instance of fastify server.\n * Use at your own risk.\n * @instance\n */\n server: FastifyInstance;\n /**\n * Current request. Must be set only once!\n */\n request: FastifyRequest;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA"}
|