@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/index.js ADDED
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _ContextPlugin = require("@webiny/api/plugins/ContextPlugin");
8
+
9
+ Object.keys(_ContextPlugin).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _ContextPlugin[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _ContextPlugin[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _fastify = require("./fastify");
21
+
22
+ Object.keys(_fastify).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _fastify[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _fastify[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _Context = require("./Context");
34
+
35
+ Object.keys(_Context).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _Context[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _Context[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _EventPlugin = require("./plugins/EventPlugin");
47
+
48
+ Object.keys(_EventPlugin).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _EventPlugin[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _EventPlugin[key];
55
+ }
56
+ });
57
+ });
58
+
59
+ var _RoutePlugin = require("./plugins/RoutePlugin");
60
+
61
+ Object.keys(_RoutePlugin).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (key in exports && exports[key] === _RoutePlugin[key]) return;
64
+ Object.defineProperty(exports, key, {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _RoutePlugin[key];
68
+ }
69
+ });
70
+ });
71
+
72
+ var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
73
+
74
+ Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
75
+ if (key === "default" || key === "__esModule") return;
76
+ if (key in exports && exports[key] === _BeforeHandlerPlugin[key]) return;
77
+ Object.defineProperty(exports, key, {
78
+ enumerable: true,
79
+ get: function () {
80
+ return _BeforeHandlerPlugin[key];
81
+ }
82
+ });
83
+ });
84
+
85
+ var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
86
+
87
+ Object.keys(_HandlerErrorPlugin).forEach(function (key) {
88
+ if (key === "default" || key === "__esModule") return;
89
+ if (key in exports && exports[key] === _HandlerErrorPlugin[key]) return;
90
+ Object.defineProperty(exports, key, {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _HandlerErrorPlugin[key];
94
+ }
95
+ });
96
+ });
97
+
98
+ var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
99
+
100
+ Object.keys(_HandlerResultPlugin).forEach(function (key) {
101
+ if (key === "default" || key === "__esModule") return;
102
+ if (key in exports && exports[key] === _HandlerResultPlugin[key]) return;
103
+ Object.defineProperty(exports, key, {
104
+ enumerable: true,
105
+ get: function () {
106
+ return _HandlerResultPlugin[key];
107
+ }
108
+ });
109
+ });
110
+
111
+ var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
112
+
113
+ Object.keys(_HandlerOnRequestPlugin).forEach(function (key) {
114
+ if (key === "default" || key === "__esModule") return;
115
+ if (key in exports && exports[key] === _HandlerOnRequestPlugin[key]) return;
116
+ Object.defineProperty(exports, key, {
117
+ enumerable: true,
118
+ get: function () {
119
+ return _HandlerOnRequestPlugin[key];
120
+ }
121
+ });
122
+ });
123
+
124
+ var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
125
+
126
+ Object.keys(_ModifyFastifyPlugin).forEach(function (key) {
127
+ if (key === "default" || key === "__esModule") return;
128
+ if (key in exports && exports[key] === _ModifyFastifyPlugin[key]) return;
129
+ Object.defineProperty(exports, key, {
130
+ enumerable: true,
131
+ get: function () {
132
+ return _ModifyFastifyPlugin[key];
133
+ }
134
+ });
135
+ });
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"@webiny/api/plugins/ContextPlugin\";\nexport * from \"~/fastify\";\nexport * from \"~/Context\";\nexport * from \"~/plugins/EventPlugin\";\nexport * from \"~/plugins/RoutePlugin\";\nexport * from \"~/plugins/BeforeHandlerPlugin\";\nexport * from \"~/plugins/HandlerErrorPlugin\";\nexport * from \"~/plugins/HandlerResultPlugin\";\nexport * from \"~/plugins/HandlerOnRequestPlugin\";\nexport * from \"~/plugins/ModifyFastifyPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Compose a single middleware from the array of middleware functions
3
+ */
4
+ export declare const middleware: (functions?: Function[]) => Function;
package/middleware.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.middleware = void 0;
7
+
8
+ /**
9
+ * Compose a single middleware from the array of middleware functions
10
+ */
11
+ const middleware = (functions = []) => {
12
+ return (...args) => {
13
+ if (!functions.length) {
14
+ return Promise.resolve();
15
+ } // Create a clone of function chain to prevent modifying the original array with `shift()`
16
+
17
+
18
+ const chain = [...functions];
19
+ return new Promise((parentResolve, parentReject) => {
20
+ const next = async () => {
21
+ const fn = chain.shift();
22
+
23
+ if (!fn) {
24
+ return Promise.resolve();
25
+ }
26
+
27
+ return new Promise(async (resolve, reject) => {
28
+ try {
29
+ const result = await fn(...args, resolve);
30
+
31
+ if (typeof result !== "undefined") {
32
+ return parentResolve(result);
33
+ }
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ }).then(() => {
38
+ return next();
39
+ }).then(() => {
40
+ parentResolve(...args);
41
+ }).catch(e => {
42
+ parentReject(e);
43
+ });
44
+ };
45
+
46
+ return next();
47
+ });
48
+ };
49
+ };
50
+
51
+ exports.middleware = middleware;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["middleware","functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"sources":["middleware.ts"],"sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport const middleware = (functions: Function[] = []): Function => {\n return (...args: string[]): Promise<any> => {\n if (!functions.length) {\n return Promise.resolve();\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n const chain = [...functions];\n return new Promise((parentResolve: any, parentReject) => {\n const next = async (): Promise<any> => {\n const fn = chain.shift();\n if (!fn) {\n return Promise.resolve();\n }\n\n return new Promise(async (resolve, reject) => {\n try {\n const result = await fn(...args, resolve);\n if (typeof result !== \"undefined\") {\n return parentResolve(result);\n }\n } catch (e) {\n reject(e);\n }\n })\n .then(() => {\n return next();\n })\n .then(() => {\n parentResolve(...args);\n })\n .catch(e => {\n parentReject(e);\n });\n };\n\n return next();\n });\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,CAACC,SAAqB,GAAG,EAAzB,KAA0C;EAChE,OAAO,CAAC,GAAGC,IAAJ,KAAqC;IACxC,IAAI,CAACD,SAAS,CAACE,MAAf,EAAuB;MACnB,OAAOC,OAAO,CAACC,OAAR,EAAP;IACH,CAHuC,CAKxC;;;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAJ,CAAd;IACA,OAAO,IAAIG,OAAJ,CAAY,CAACG,aAAD,EAAqBC,YAArB,KAAsC;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAN,EAAX;;QACA,IAAI,CAACD,EAAL,EAAS;UACL,OAAON,OAAO,CAACC,OAAR,EAAP;QACH;;QAED,OAAO,IAAID,OAAJ,CAAY,OAAOC,OAAP,EAAgBO,MAAhB,KAA2B;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAJ,EAAUG,OAAV,CAAvB;;YACA,IAAI,OAAOQ,MAAP,KAAkB,WAAtB,EAAmC;cAC/B,OAAON,aAAa,CAACM,MAAD,CAApB;YACH;UACJ,CALD,CAKE,OAAOC,CAAP,EAAU;YACRF,MAAM,CAACE,CAAD,CAAN;UACH;QACJ,CATM,EAUFC,IAVE,CAUG,MAAM;UACR,OAAON,IAAI,EAAX;QACH,CAZE,EAaFM,IAbE,CAaG,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAJ,CAAb;QACH,CAfE,EAgBFc,KAhBE,CAgBIF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAD,CAAZ;QACH,CAlBE,CAAP;MAmBH,CAzBD;;MA2BA,OAAOL,IAAI,EAAX;IACH,CA7BM,CAAP;EA8BH,CArCD;AAsCH,CAvCM"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@webiny/handler",
3
+ "version": "0.0.0-ee-vpcs.549378cf03",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "description": "Our small wrapper around fastify to ease handling of http requests for the system.",
10
+ "contributors": [
11
+ "Bruno Zorić <bruno@webiny.com>"
12
+ ],
13
+ "license": "MIT",
14
+ "dependencies": {
15
+ "@babel/runtime": "7.19.0",
16
+ "@fastify/compress": "6.2.0",
17
+ "@fastify/cookie": "8.3.0",
18
+ "@webiny/api": "0.0.0-ee-vpcs.549378cf03",
19
+ "@webiny/error": "0.0.0-ee-vpcs.549378cf03",
20
+ "@webiny/handler-client": "0.0.0-ee-vpcs.549378cf03",
21
+ "@webiny/plugins": "0.0.0-ee-vpcs.549378cf03",
22
+ "@webiny/utils": "0.0.0-ee-vpcs.549378cf03",
23
+ "fastify": "4.11.0"
24
+ },
25
+ "devDependencies": {
26
+ "@babel/cli": "^7.19.3",
27
+ "@babel/core": "^7.19.3",
28
+ "@babel/preset-env": "^7.19.4",
29
+ "@babel/preset-typescript": "^7.18.6",
30
+ "@webiny/cli": "^0.0.0-ee-vpcs.549378cf03",
31
+ "@webiny/project-utils": "^0.0.0-ee-vpcs.549378cf03",
32
+ "babel-plugin-lodash": "^3.3.4",
33
+ "merge": "^1.2.1",
34
+ "rimraf": "^3.0.2",
35
+ "ttypescript": "^1.5.13",
36
+ "typescript": "4.7.4"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "directory": "dist"
41
+ },
42
+ "scripts": {
43
+ "build": "yarn webiny run build",
44
+ "watch": "yarn webiny run watch"
45
+ },
46
+ "gitHead": "549378cf03fcd27845fc3fa23d1dc6b32896f630"
47
+ }
@@ -0,0 +1,12 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { Context } from "../types";
3
+ export interface BeforeHandlerCallable<T extends Context = Context> {
4
+ (context: T): void | Promise<void>;
5
+ }
6
+ export declare class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {
7
+ static readonly type: string;
8
+ private readonly _callable;
9
+ constructor(callable: BeforeHandlerCallable<T>);
10
+ apply(context: T): Promise<void>;
11
+ }
12
+ export declare const createBeforeHandlerPlugin: <T extends Context = Context>(callable: BeforeHandlerCallable<T>) => BeforeHandlerPlugin<T>;
@@ -0,0 +1,38 @@
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.createBeforeHandlerPlugin = exports.BeforeHandlerPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ class BeforeHandlerPlugin extends _plugins.Plugin {
15
+ constructor(callable) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "_callable", void 0);
18
+ this._callable = callable;
19
+ }
20
+
21
+ async apply(context) {
22
+ if (typeof this._callable !== "function") {
23
+ throw Error(`Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
24
+ }
25
+
26
+ return this._callable(context);
27
+ }
28
+
29
+ }
30
+
31
+ exports.BeforeHandlerPlugin = BeforeHandlerPlugin;
32
+ (0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
33
+
34
+ const createBeforeHandlerPlugin = callable => {
35
+ return new BeforeHandlerPlugin(callable);
36
+ };
37
+
38
+ exports.createBeforeHandlerPlugin = createBeforeHandlerPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createBeforeHandlerPlugin"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\nexport const createBeforeHandlerPlugin = <T extends Context = Context>(\n callable: BeforeHandlerCallable<T>\n): BeforeHandlerPlugin<T> => {\n return new BeforeHandlerPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAIzEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,6IADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB;;AAmB5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * EventPlugin must be handled in the package which implements fastify for certain cloud.
3
+ * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
4
+ * to be sorted out in the implementation package.
5
+ *
6
+ * Note that only one EventPlugin can be defined per fastify initialisation.
7
+ * If more is needed, check ~/fastify.ts and implement that possibility.
8
+ */
9
+ import { Plugin } from "@webiny/plugins/Plugin";
10
+ import { Request, Context as BaseContext, Reply } from "../types";
11
+ export interface EventPluginCallableParams<Payload, Context extends BaseContext> {
12
+ context: Context;
13
+ payload: Payload;
14
+ request: Request;
15
+ reply: Reply;
16
+ }
17
+ export interface EventPluginCallable<Payload, Context extends BaseContext, Response> {
18
+ (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;
19
+ }
20
+ export declare class EventPlugin<Payload = any, Context extends BaseContext = BaseContext, Response = any> extends Plugin {
21
+ static type: string;
22
+ readonly cb: EventPluginCallable<Payload, Context, Response>;
23
+ constructor(cb: EventPluginCallable<Payload, Context, Response>);
24
+ }
25
+ export declare const createEvent: <Payload = any, Context extends BaseContext = BaseContext, Response_1 = any>(cb: EventPluginCallable<Payload, Context, Response_1>) => EventPlugin<Payload, Context, Response_1>;
@@ -0,0 +1,38 @@
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.createEvent = exports.EventPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _Plugin = require("@webiny/plugins/Plugin");
13
+
14
+ /**
15
+ * EventPlugin must be handled in the package which implements fastify for certain cloud.
16
+ * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
17
+ * to be sorted out in the implementation package.
18
+ *
19
+ * Note that only one EventPlugin can be defined per fastify initialisation.
20
+ * If more is needed, check ~/fastify.ts and implement that possibility.
21
+ */
22
+ class EventPlugin extends _Plugin.Plugin {
23
+ constructor(cb) {
24
+ super();
25
+ (0, _defineProperty2.default)(this, "cb", void 0);
26
+ this.cb = cb;
27
+ }
28
+
29
+ }
30
+
31
+ exports.EventPlugin = EventPlugin;
32
+ (0, _defineProperty2.default)(EventPlugin, "type", "handler.fastify.event");
33
+
34
+ const createEvent = cb => {
35
+ return new EventPlugin(cb);
36
+ };
37
+
38
+ exports.createEvent = createEvent;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["EventPlugin","Plugin","constructor","cb","createEvent"],"sources":["EventPlugin.ts"],"sourcesContent":["/**\n * EventPlugin must be handled in the package which implements fastify for certain cloud.\n * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that\n * to be sorted out in the implementation package.\n *\n * Note that only one EventPlugin can be defined per fastify initialisation.\n * If more is needed, check ~/fastify.ts and implement that possibility.\n */\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Context as BaseContext, Reply } from \"~/types\";\n\nexport interface EventPluginCallableParams<Payload, Context extends BaseContext> {\n context: Context;\n payload: Payload;\n request: Request;\n reply: Reply;\n}\n\nexport interface EventPluginCallable<Payload, Context extends BaseContext, Response> {\n (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;\n}\n\nexport class EventPlugin<\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.event\";\n\n public readonly cb: EventPluginCallable<Payload, Context, Response>;\n\n public constructor(cb: EventPluginCallable<Payload, Context, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEvent = <\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: EventPluginCallable<Payload, Context, Response>\n) => {\n return new EventPlugin<Payload, Context, Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeO,MAAMA,WAAN,SAIGC,cAJH,CAIU;EAKNC,WAAW,CAACC,EAAD,EAAsD;IACpE;IADoE;IAEpE,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARY;;;8BAJJH,W,UAKqB,uB;;AAU3B,MAAMI,WAAW,GAKpBD,EALuB,IAMtB;EACD,OAAO,IAAIH,WAAJ,CAA4CG,EAA5C,CAAP;AACH,CARM"}
@@ -0,0 +1,12 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { Context } from "../types";
3
+ export interface HandlerErrorCallable<T extends Context = Context> {
4
+ (context: T, error: Error, next: Function): Promise<any>;
5
+ }
6
+ export declare class HandlerErrorPlugin<T extends Context = Context> extends Plugin {
7
+ static readonly type: string;
8
+ private readonly _callable;
9
+ constructor(callable: HandlerErrorCallable<T>);
10
+ handle(context: T, error: Error, next: Function): Promise<any>;
11
+ }
12
+ export declare const createHandlerErrorPlugin: <T extends Context = Context>(callable: HandlerErrorCallable<T>) => HandlerErrorPlugin<T>;
@@ -0,0 +1,34 @@
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.createHandlerErrorPlugin = exports.HandlerErrorPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ class HandlerErrorPlugin extends _plugins.Plugin {
15
+ constructor(callable) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "_callable", void 0);
18
+ this._callable = callable;
19
+ }
20
+
21
+ async handle(context, error, next) {
22
+ return this._callable(context, error, next);
23
+ }
24
+
25
+ }
26
+
27
+ exports.HandlerErrorPlugin = HandlerErrorPlugin;
28
+ (0, _defineProperty2.default)(HandlerErrorPlugin, "type", "handler-error");
29
+
30
+ const createHandlerErrorPlugin = callable => {
31
+ return new HandlerErrorPlugin(callable);
32
+ };
33
+
34
+ exports.createHandlerErrorPlugin = createHandlerErrorPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next","createHandlerErrorPlugin"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n\nexport const createHandlerErrorPlugin = <T extends Context = Context>(\n callable: HandlerErrorCallable<T>\n): HandlerErrorPlugin<T> => {\n return new HandlerErrorPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;EAKjEC,WAAW,CAACC,QAAD,EAAoC;IAClD;IADkD;IAElD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;IACxE,OAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;EACH;;AAZuE;;;8BAA/DR,kB,UACsC,e;;AAc5C,MAAMS,wBAAwB,GACjCN,QADoC,IAEZ;EACxB,OAAO,IAAIH,kBAAJ,CAA0BG,QAA1B,CAAP;AACH,CAJM"}
@@ -0,0 +1,20 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { FastifyReply, FastifyRequest } from "fastify";
3
+ /**
4
+ * If the execution of the callable returns false, no more plugins will be executed after the given one.
5
+ * Nor it will execute our default OPTIONS code.
6
+ *
7
+ * This way users can prevent stopping of the request on our built-in OPTIONS request.
8
+ */
9
+ export declare type HandlerOnRequestPluginCallableResponse = false | undefined | null | void;
10
+ interface HandlerOnRequestPluginCallable {
11
+ (request: FastifyRequest, reply: FastifyReply): Promise<HandlerOnRequestPluginCallableResponse>;
12
+ }
13
+ export declare class HandlerOnRequestPlugin extends Plugin {
14
+ static type: string;
15
+ private readonly cb;
16
+ constructor(cb: HandlerOnRequestPluginCallable);
17
+ exec(request: FastifyRequest, reply: FastifyReply): Promise<HandlerOnRequestPluginCallableResponse>;
18
+ }
19
+ export declare const createHandlerOnRequest: (cb: HandlerOnRequestPluginCallable) => HandlerOnRequestPlugin;
20
+ export {};
@@ -0,0 +1,34 @@
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.createHandlerOnRequest = exports.HandlerOnRequestPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ class HandlerOnRequestPlugin extends _plugins.Plugin {
15
+ constructor(cb) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "cb", void 0);
18
+ this.cb = cb;
19
+ }
20
+
21
+ async exec(request, reply) {
22
+ return this.cb(request, reply);
23
+ }
24
+
25
+ }
26
+
27
+ exports.HandlerOnRequestPlugin = HandlerOnRequestPlugin;
28
+ (0, _defineProperty2.default)(HandlerOnRequestPlugin, "type", "handler.event.onRequest");
29
+
30
+ const createHandlerOnRequest = cb => {
31
+ return new HandlerOnRequestPlugin(cb);
32
+ };
33
+
34
+ exports.createHandlerOnRequest = createHandlerOnRequest;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["HandlerOnRequestPlugin","Plugin","constructor","cb","exec","request","reply","createHandlerOnRequest"],"sources":["HandlerOnRequestPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FastifyReply, FastifyRequest } from \"fastify\";\n\n/**\n * If the execution of the callable returns false, no more plugins will be executed after the given one.\n * Nor it will execute our default OPTIONS code.\n *\n * This way users can prevent stopping of the request on our built-in OPTIONS request.\n */\nexport type HandlerOnRequestPluginCallableResponse = false | undefined | null | void;\ninterface HandlerOnRequestPluginCallable {\n (request: FastifyRequest, reply: FastifyReply): Promise<HandlerOnRequestPluginCallableResponse>;\n}\n\nexport class HandlerOnRequestPlugin extends Plugin {\n public static override type = \"handler.event.onRequest\";\n\n private readonly cb: HandlerOnRequestPluginCallable;\n\n public constructor(cb: HandlerOnRequestPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public async exec(\n request: FastifyRequest,\n reply: FastifyReply\n ): Promise<HandlerOnRequestPluginCallableResponse> {\n return this.cb(request, reply);\n }\n}\n\nexport const createHandlerOnRequest = (cb: HandlerOnRequestPluginCallable) => {\n return new HandlerOnRequestPlugin(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAcO,MAAMA,sBAAN,SAAqCC,eAArC,CAA4C;EAKxCC,WAAW,CAACC,EAAD,EAAqC;IACnD;IADmD;IAEnD,KAAKA,EAAL,GAAUA,EAAV;EACH;;EAEgB,MAAJC,IAAI,CACbC,OADa,EAEbC,KAFa,EAGkC;IAC/C,OAAO,KAAKH,EAAL,CAAQE,OAAR,EAAiBC,KAAjB,CAAP;EACH;;AAf8C;;;8BAAtCN,sB,UACqB,yB;;AAiB3B,MAAMO,sBAAsB,GAAIJ,EAAD,IAAwC;EAC1E,OAAO,IAAIH,sBAAJ,CAA2BG,EAA3B,CAAP;AACH,CAFM"}
@@ -0,0 +1,12 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { Context } from "../types";
3
+ export interface HandlerResultCallable<T extends Context = Context> {
4
+ (context: T, result: any): Promise<any>;
5
+ }
6
+ export declare class HandlerResultPlugin<T extends Context = Context> extends Plugin {
7
+ static readonly type: string;
8
+ private readonly _callable;
9
+ constructor(callable: HandlerResultCallable<T>);
10
+ handle(context: T, result: any): Promise<any>;
11
+ }
12
+ export declare const createHandlerResultPlugin: <T extends Context = Context>(callable: HandlerResultCallable<T>) => HandlerResultPlugin<T>;
@@ -0,0 +1,34 @@
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.createHandlerResultPlugin = exports.HandlerResultPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ class HandlerResultPlugin extends _plugins.Plugin {
15
+ constructor(callable) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "_callable", void 0);
18
+ this._callable = callable;
19
+ }
20
+
21
+ async handle(context, result) {
22
+ return this._callable(context, result);
23
+ }
24
+
25
+ }
26
+
27
+ exports.HandlerResultPlugin = HandlerResultPlugin;
28
+ (0, _defineProperty2.default)(HandlerResultPlugin, "type", "handler-result");
29
+
30
+ const createHandlerResultPlugin = callable => {
31
+ return new HandlerResultPlugin(callable);
32
+ };
33
+
34
+ exports.createHandlerResultPlugin = createHandlerResultPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result","createHandlerResultPlugin"],"sources":["HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerResultCallable<T extends Context = Context> {\n (context: T, result: any): Promise<any>;\n}\n\nexport class HandlerResultPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-result\";\n\n private readonly _callable: HandlerResultCallable<T>;\n\n public constructor(callable: HandlerResultCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, result: any): Promise<any> {\n return this._callable(context, result);\n }\n}\n\nexport const createHandlerResultPlugin = <T extends Context = Context>(\n callable: HandlerResultCallable<T>\n): HandlerResultPlugin<T> => {\n return new HandlerResultPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAKlEC,WAAW,CAACC,QAAD,EAAqC;IACnD;IADmD;IAEnD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,MAAb,EAAwC;IACvD,OAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,MAAxB,CAAP;EACH;;AAZwE;;;8BAAhEP,mB,UACsC,gB;;AAc5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
@@ -0,0 +1,13 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin";
2
+ import { FastifyInstance } from "fastify";
3
+ interface ModifyFastifyPluginCallable {
4
+ (app: FastifyInstance): void;
5
+ }
6
+ export declare class ModifyFastifyPlugin extends Plugin {
7
+ static type: string;
8
+ private readonly cb;
9
+ constructor(cb: ModifyFastifyPluginCallable);
10
+ modify(app: FastifyInstance): void;
11
+ }
12
+ export declare const createModifyFastifyPlugin: (cb: ModifyFastifyPluginCallable) => ModifyFastifyPlugin;
13
+ export {};
@@ -0,0 +1,34 @@
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.createModifyFastifyPlugin = exports.ModifyFastifyPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _Plugin = require("@webiny/plugins/Plugin");
13
+
14
+ class ModifyFastifyPlugin extends _Plugin.Plugin {
15
+ constructor(cb) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "cb", void 0);
18
+ this.cb = cb;
19
+ }
20
+
21
+ modify(app) {
22
+ this.cb(app);
23
+ }
24
+
25
+ }
26
+
27
+ exports.ModifyFastifyPlugin = ModifyFastifyPlugin;
28
+ (0, _defineProperty2.default)(ModifyFastifyPlugin, "type", "handler.fastify.modify");
29
+
30
+ const createModifyFastifyPlugin = cb => {
31
+ return new ModifyFastifyPlugin(cb);
32
+ };
33
+
34
+ exports.createModifyFastifyPlugin = createModifyFastifyPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ModifyFastifyPlugin","Plugin","constructor","cb","modify","app","createModifyFastifyPlugin"],"sources":["ModifyFastifyPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { FastifyInstance } from \"fastify\";\n\ninterface ModifyFastifyPluginCallable {\n (app: FastifyInstance): void;\n}\n\nexport class ModifyFastifyPlugin extends Plugin {\n public static override type = \"handler.fastify.modify\";\n\n private readonly cb: ModifyFastifyPluginCallable;\n\n public constructor(cb: ModifyFastifyPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public modify(app: FastifyInstance): void {\n this.cb(app);\n }\n}\n\nexport const createModifyFastifyPlugin = (cb: ModifyFastifyPluginCallable) => {\n return new ModifyFastifyPlugin(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAAkCC,cAAlC,CAAyC;EAKrCC,WAAW,CAACC,EAAD,EAAkC;IAChD;IADgD;IAEhD,KAAKA,EAAL,GAAUA,EAAV;EACH;;EAEMC,MAAM,CAACC,GAAD,EAA6B;IACtC,KAAKF,EAAL,CAAQE,GAAR;EACH;;AAZ2C;;;8BAAnCL,mB,UACqB,wB;;AAc3B,MAAMM,yBAAyB,GAAIH,EAAD,IAAqC;EAC1E,OAAO,IAAIH,mBAAJ,CAAwBG,EAAxB,CAAP;AACH,CAFM"}
@@ -0,0 +1,23 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin";
2
+ import { Context, RouteMethod } from "../types";
3
+ interface RoutePluginCbParams<T extends Context> {
4
+ context: T;
5
+ onGet: RouteMethod;
6
+ onPost: RouteMethod;
7
+ onPut: RouteMethod;
8
+ onPatch: RouteMethod;
9
+ onDelete: RouteMethod;
10
+ onOptions: RouteMethod;
11
+ onAll: RouteMethod;
12
+ onHead: RouteMethod;
13
+ }
14
+ export interface RoutePluginCb<T extends Context> {
15
+ (params: RoutePluginCbParams<T>): void;
16
+ }
17
+ export declare class RoutePlugin<T extends Context = Context> extends Plugin {
18
+ static readonly type: string;
19
+ readonly cb: RoutePluginCb<T>;
20
+ constructor(cb: RoutePluginCb<T>);
21
+ }
22
+ export declare const createRoute: <T extends Context = Context>(cb: RoutePluginCb<T>) => RoutePlugin<T>;
23
+ export {};