@webiny/handler 5.34.8 → 5.35.0-beta.1
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 +19 -10
- package/Context.js +16 -7
- package/Context.js.map +1 -1
- package/fastify.js +15 -71
- package/fastify.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +0 -31
- package/index.js.map +1 -1
- package/middleware.js +2 -8
- package/middleware.js.map +1 -1
- package/package.json +10 -10
- package/plugins/BeforeHandlerPlugin.js +0 -10
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/EventPlugin.js +1 -8
- package/plugins/EventPlugin.js.map +1 -1
- package/plugins/HandlerErrorPlugin.js +0 -9
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerOnRequestPlugin.js +0 -9
- package/plugins/HandlerOnRequestPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.js +0 -9
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/plugins/ModifyFastifyPlugin.js +0 -9
- package/plugins/ModifyFastifyPlugin.js.map +1 -1
- package/plugins/RoutePlugin.js +0 -8
- package/plugins/RoutePlugin.js.map +1 -1
- package/types.js +0 -1
- package/types.js.map +1 -1
package/Context.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
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
|
-
server:
|
|
5
|
-
routes:
|
|
4
|
+
server: ContextInterface["server"];
|
|
5
|
+
routes: ContextInterface["routes"];
|
|
6
6
|
}
|
|
7
|
-
export declare class Context extends BaseContext implements
|
|
8
|
-
readonly server:
|
|
9
|
-
readonly routes:
|
|
10
|
-
handlerClient:
|
|
11
|
-
request:
|
|
12
|
-
reply:
|
|
7
|
+
export declare class Context extends BaseContext implements ContextInterface {
|
|
8
|
+
readonly server: ContextInterface["server"];
|
|
9
|
+
readonly routes: ContextInterface["routes"];
|
|
10
|
+
handlerClient: ContextInterface["handlerClient"];
|
|
11
|
+
request: ContextInterface["request"];
|
|
12
|
+
reply: ContextInterface["reply"];
|
|
13
13
|
constructor(params: ContextParams);
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
|
|
17
|
+
*
|
|
18
|
+
* This can be removed when we introduce the type augmentation.
|
|
19
|
+
*/
|
|
20
|
+
export declare type ContextPluginCallable<T extends ContextInterface = ContextInterface> = BaseContextPluginCallable<T>;
|
|
21
|
+
export declare class ContextPlugin<T extends ContextInterface = ContextInterface> extends BaseContextPlugin<T> {
|
|
22
|
+
}
|
|
23
|
+
export declare const createContextPlugin: <T extends ContextInterface = ContextInterface>(callable: ContextPluginCallable<T>) => BaseContextPlugin<T>;
|
package/Context.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.Context = void 0;
|
|
9
|
-
|
|
7
|
+
exports.createContextPlugin = exports.ContextPlugin = exports.Context = void 0;
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _api = require("@webiny/api");
|
|
13
|
-
|
|
14
10
|
class Context extends _api.Context {
|
|
15
11
|
// @ts-ignore
|
|
12
|
+
|
|
16
13
|
// @ts-ignore
|
|
14
|
+
|
|
17
15
|
// @ts-ignore
|
|
16
|
+
|
|
18
17
|
constructor(params) {
|
|
19
18
|
super(params);
|
|
20
19
|
(0, _defineProperty2.default)(this, "server", void 0);
|
|
@@ -25,7 +24,17 @@ class Context extends _api.Context {
|
|
|
25
24
|
this.server = params.server;
|
|
26
25
|
this.routes = params.routes;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
/**
|
|
30
|
+
* We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
|
|
31
|
+
*
|
|
32
|
+
* This can be removed when we introduce the type augmentation.
|
|
33
|
+
*/
|
|
34
|
+
exports.Context = Context;
|
|
35
|
+
class ContextPlugin extends _api.ContextPlugin {}
|
|
36
|
+
exports.ContextPlugin = ContextPlugin;
|
|
37
|
+
const createContextPlugin = callable => {
|
|
38
|
+
return (0, _api.createContextPlugin)(callable);
|
|
39
|
+
};
|
|
40
|
+
exports.createContextPlugin = createContextPlugin;
|
package/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Context","BaseContext","constructor","params","server","routes"],"sources":["Context.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["Context","BaseContext","constructor","params","server","routes","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 server: ContextInterface[\"server\"];\n routes: ContextInterface[\"routes\"];\n}\n\nexport class Context extends BaseContext implements ContextInterface {\n public readonly server: ContextInterface[\"server\"];\n public readonly routes: ContextInterface[\"routes\"];\n // @ts-ignore\n public handlerClient: ContextInterface[\"handlerClient\"];\n // @ts-ignore\n public request: ContextInterface[\"request\"];\n // @ts-ignore\n public reply: ContextInterface[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.server = params.server;\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;AAcO,MAAMA,OAAO,SAASC,YAAW,CAA6B;EAGjE;;EAEA;;EAEA;;EAGOC,WAAW,CAACC,MAAqB,EAAE;IACtC,KAAK,CAACA,MAAM,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IACd,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC3B,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC/B;AACJ;;AAEA;AACA;AACA;AACA;AACA;AAJA;AAQO,MAAMC,aAAa,SAEhBC,kBAAiB,CAAI;AAAE;AAE1B,MAAMC,mBAAmB,GAC5BC,QAAkC,IACjC;EACD,OAAO,IAAAC,wBAAuB,EAAID,QAAQ,CAAC;AAC/C,CAAC;AAAC"}
|
package/fastify.js
CHANGED
|
@@ -1,44 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createHandler = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _fastify = _interopRequireDefault(require("fastify"));
|
|
13
|
-
|
|
14
10
|
var _utils = require("@webiny/utils");
|
|
15
|
-
|
|
16
11
|
var _Context = require("./Context");
|
|
17
|
-
|
|
18
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
13
|
var _RoutePlugin = require("./plugins/RoutePlugin");
|
|
21
|
-
|
|
22
14
|
var _handlerClient = require("@webiny/handler-client");
|
|
23
|
-
|
|
24
15
|
var _cookie = _interopRequireDefault(require("@fastify/cookie"));
|
|
25
|
-
|
|
26
16
|
var _compress = _interopRequireDefault(require("@fastify/compress"));
|
|
27
|
-
|
|
28
17
|
var _middleware = require("./middleware");
|
|
29
|
-
|
|
30
18
|
var _api = require("@webiny/api");
|
|
31
|
-
|
|
32
19
|
var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
|
|
33
|
-
|
|
34
20
|
var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
|
|
35
|
-
|
|
36
21
|
var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
|
|
37
|
-
|
|
38
22
|
var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
|
|
39
|
-
|
|
40
23
|
var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
|
|
41
|
-
|
|
42
24
|
const DEFAULT_HEADERS = (0, _objectSpread2.default)({
|
|
43
25
|
"Cache-Control": "no-store",
|
|
44
26
|
"Content-Type": "application/json; charset=utf-8",
|
|
@@ -46,34 +28,28 @@ const DEFAULT_HEADERS = (0, _objectSpread2.default)({
|
|
|
46
28
|
"Access-Control-Allow-Headers": "*",
|
|
47
29
|
"Access-Control-Allow-Methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH"
|
|
48
30
|
}, (0, _utils.getWebinyVersionHeaders)());
|
|
49
|
-
|
|
50
31
|
const getDefaultHeaders = routes => {
|
|
51
32
|
/**
|
|
52
33
|
* If we are accepting all headers, just output that one.
|
|
53
34
|
*/
|
|
54
35
|
const keys = Object.keys(routes);
|
|
55
36
|
const all = keys.every(key => routes[key].length > 0);
|
|
56
|
-
|
|
57
37
|
if (all) {
|
|
58
38
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
|
|
59
39
|
"Access-Control-Allow-Methods": "*"
|
|
60
40
|
});
|
|
61
41
|
}
|
|
62
|
-
|
|
63
42
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
|
|
64
43
|
"Access-Control-Allow-Methods": keys.filter(type => {
|
|
65
44
|
if (!routes[type] || Array.isArray(routes[type]) === false) {
|
|
66
45
|
return false;
|
|
67
46
|
}
|
|
68
|
-
|
|
69
47
|
return routes[type].length > 0;
|
|
70
48
|
}).sort().join(",")
|
|
71
49
|
});
|
|
72
50
|
};
|
|
73
|
-
|
|
74
51
|
const stringifyError = error => {
|
|
75
52
|
var _error$constructor;
|
|
76
|
-
|
|
77
53
|
const {
|
|
78
54
|
name,
|
|
79
55
|
message,
|
|
@@ -90,12 +66,10 @@ const stringifyError = error => {
|
|
|
90
66
|
stack: process.env.DEBUG === "true" ? stack : "Turn on the debug flag to see the stack."
|
|
91
67
|
}));
|
|
92
68
|
};
|
|
93
|
-
|
|
94
69
|
const OPTIONS_HEADERS = {
|
|
95
70
|
"Access-Control-Max-Age": "86400",
|
|
96
71
|
"Cache-Control": "public, max-age=86400"
|
|
97
72
|
};
|
|
98
|
-
|
|
99
73
|
const createHandler = params => {
|
|
100
74
|
const definedRoutes = {
|
|
101
75
|
POST: [],
|
|
@@ -115,18 +89,15 @@ const createHandler = params => {
|
|
|
115
89
|
TRACE: [],
|
|
116
90
|
UNLOCK: []
|
|
117
91
|
};
|
|
118
|
-
|
|
119
92
|
const throwOnDefinedRoute = (type, path, options) => {
|
|
120
93
|
if (type === "ALL") {
|
|
121
94
|
const all = Object.keys(definedRoutes).find(key => {
|
|
122
95
|
const routes = definedRoutes[key];
|
|
123
96
|
return routes.includes(path);
|
|
124
97
|
});
|
|
125
|
-
|
|
126
98
|
if (!all) {
|
|
127
99
|
return;
|
|
128
100
|
}
|
|
129
|
-
|
|
130
101
|
console.error(`Error while registering onAll route. One of the routes is already defined.`);
|
|
131
102
|
console.error(JSON.stringify(all));
|
|
132
103
|
throw new _error.default(`You cannot override a route with onAll() method, please remove unnecessary route from the system.`, "OVERRIDE_ROUTE_ERROR", {
|
|
@@ -138,67 +109,54 @@ const createHandler = params => {
|
|
|
138
109
|
} else if ((options === null || options === void 0 ? void 0 : options.override) === true) {
|
|
139
110
|
return;
|
|
140
111
|
}
|
|
141
|
-
|
|
142
112
|
console.error(`Error while trying to override route: [${type}] ${path}`);
|
|
143
113
|
throw new _error.default(`When you are trying to override existing route, you must send "override" parameter when adding that route.`, "OVERRIDE_ROUTE_ERROR", {
|
|
144
114
|
type,
|
|
145
115
|
path
|
|
146
116
|
});
|
|
147
117
|
};
|
|
148
|
-
|
|
149
118
|
const addDefinedRoute = (type, path) => {
|
|
150
119
|
if (!definedRoutes[type]) {
|
|
151
120
|
return;
|
|
152
121
|
} else if (definedRoutes[type].includes(path)) {
|
|
153
122
|
return;
|
|
154
123
|
}
|
|
155
|
-
|
|
156
124
|
definedRoutes[type].push(path);
|
|
157
125
|
};
|
|
158
126
|
/**
|
|
159
127
|
* We must attach the server to our internal context if we want to have it accessible.
|
|
160
128
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
129
|
const app = (0, _fastify.default)((0, _objectSpread2.default)({}, params.options || {}));
|
|
164
130
|
/**
|
|
165
131
|
* We need to register routes in our system so we can output headers later on and dissallow overriding routes.
|
|
166
132
|
*/
|
|
167
|
-
|
|
168
133
|
app.addHook("onRoute", route => {
|
|
169
134
|
const method = route.method;
|
|
170
|
-
|
|
171
135
|
if (Array.isArray(method)) {
|
|
172
136
|
for (const m of method) {
|
|
173
137
|
addDefinedRoute(m, route.path);
|
|
174
138
|
}
|
|
175
|
-
|
|
176
139
|
return;
|
|
177
140
|
}
|
|
178
|
-
|
|
179
141
|
addDefinedRoute(method, route.path);
|
|
180
142
|
});
|
|
181
143
|
/**
|
|
182
144
|
* ############################
|
|
183
145
|
* Register the Fastify plugins.
|
|
184
146
|
*/
|
|
185
|
-
|
|
186
147
|
/**
|
|
187
148
|
* Package @fastify/cookie
|
|
188
149
|
*
|
|
189
150
|
* https://github.com/fastify/fastify-cookie
|
|
190
151
|
*/
|
|
191
|
-
|
|
192
152
|
app.register(_cookie.default, {
|
|
193
153
|
parseOptions: {} // options for parsing cookies
|
|
194
|
-
|
|
195
154
|
});
|
|
196
155
|
/**
|
|
197
156
|
* Package @fastify/compress
|
|
198
157
|
*
|
|
199
158
|
* https://github.com/fastify/fastify-compress
|
|
200
159
|
*/
|
|
201
|
-
|
|
202
160
|
app.register(_compress.default, {
|
|
203
161
|
global: true,
|
|
204
162
|
threshold: 1024,
|
|
@@ -211,7 +169,6 @@ const createHandler = params => {
|
|
|
211
169
|
/**
|
|
212
170
|
* Route helpers - mostly for users.
|
|
213
171
|
*/
|
|
214
|
-
|
|
215
172
|
const routes = {
|
|
216
173
|
defined: definedRoutes,
|
|
217
174
|
onPost: (path, handler, options) => {
|
|
@@ -248,7 +205,6 @@ const createHandler = params => {
|
|
|
248
205
|
}
|
|
249
206
|
};
|
|
250
207
|
let context;
|
|
251
|
-
|
|
252
208
|
try {
|
|
253
209
|
context = new _Context.Context({
|
|
254
210
|
plugins: [
|
|
@@ -257,7 +213,6 @@ const createHandler = params => {
|
|
|
257
213
|
* And it must be one of the first context plugins applied.
|
|
258
214
|
*/
|
|
259
215
|
(0, _handlerClient.createHandlerClient)(), ...(params.plugins || [])],
|
|
260
|
-
|
|
261
216
|
/**
|
|
262
217
|
* Inserted via webpack on build time.
|
|
263
218
|
*/
|
|
@@ -270,12 +225,12 @@ const createHandler = params => {
|
|
|
270
225
|
console.error(stringifyError(ex));
|
|
271
226
|
throw ex;
|
|
272
227
|
}
|
|
228
|
+
|
|
273
229
|
/**
|
|
274
230
|
* We are attaching our custom context to webiny variable on the fastify app, so it is accessible everywhere.
|
|
275
231
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
232
|
app.decorate("webiny", context);
|
|
233
|
+
|
|
279
234
|
/**
|
|
280
235
|
* We have few types of triggers:
|
|
281
236
|
* * Events - EventPlugin
|
|
@@ -283,14 +238,12 @@ const createHandler = params => {
|
|
|
283
238
|
*
|
|
284
239
|
* Routes are registered in fastify but events must be handled in package which implements cloud specific methods.
|
|
285
240
|
*/
|
|
286
|
-
|
|
287
241
|
const routePlugins = app.webiny.plugins.byType(_RoutePlugin.RoutePlugin.type);
|
|
242
|
+
|
|
288
243
|
/**
|
|
289
244
|
* Add routes to the system.
|
|
290
245
|
*/
|
|
291
|
-
|
|
292
246
|
let routePluginName;
|
|
293
|
-
|
|
294
247
|
try {
|
|
295
248
|
for (const plugin of routePlugins) {
|
|
296
249
|
routePluginName = plugin.name;
|
|
@@ -303,12 +256,11 @@ const createHandler = params => {
|
|
|
303
256
|
console.error(stringifyError(ex));
|
|
304
257
|
throw ex;
|
|
305
258
|
}
|
|
259
|
+
|
|
306
260
|
/**
|
|
307
261
|
* On every request we add default headers, which can be changed later.
|
|
308
262
|
* Also, if it is an options request, we skip everything after this hook and output options headers.
|
|
309
263
|
*/
|
|
310
|
-
|
|
311
|
-
|
|
312
264
|
app.addHook("onRequest", async (request, reply) => {
|
|
313
265
|
/**
|
|
314
266
|
* Our default headers are always set. Users can override them.
|
|
@@ -318,15 +270,12 @@ const createHandler = params => {
|
|
|
318
270
|
/**
|
|
319
271
|
* Users can define their own custom handlers for the onRequest event - so let's run them first.
|
|
320
272
|
*/
|
|
321
|
-
|
|
322
273
|
const plugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
|
|
323
274
|
let name;
|
|
324
|
-
|
|
325
275
|
try {
|
|
326
276
|
for (const plugin of plugins) {
|
|
327
277
|
name = plugin.name;
|
|
328
278
|
const result = await plugin.exec(request, reply);
|
|
329
|
-
|
|
330
279
|
if (result === false) {
|
|
331
280
|
return;
|
|
332
281
|
}
|
|
@@ -341,12 +290,9 @@ const createHandler = params => {
|
|
|
341
290
|
*
|
|
342
291
|
* Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.
|
|
343
292
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
346
293
|
if (request.method !== "OPTIONS") {
|
|
347
294
|
return;
|
|
348
295
|
}
|
|
349
|
-
|
|
350
296
|
if (reply.sent) {
|
|
351
297
|
/**
|
|
352
298
|
* At this point throwing an exception will not do anything with the response. So just log it.
|
|
@@ -357,7 +303,6 @@ const createHandler = params => {
|
|
|
357
303
|
}));
|
|
358
304
|
return;
|
|
359
305
|
}
|
|
360
|
-
|
|
361
306
|
reply.headers((0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultHeaders), OPTIONS_HEADERS)).code(204).send("").hijack();
|
|
362
307
|
});
|
|
363
308
|
app.addHook("preParsing", async (request, reply) => {
|
|
@@ -365,7 +310,6 @@ const createHandler = params => {
|
|
|
365
310
|
app.webiny.reply = reply;
|
|
366
311
|
const plugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
|
|
367
312
|
let name;
|
|
368
|
-
|
|
369
313
|
try {
|
|
370
314
|
for (const plugin of plugins) {
|
|
371
315
|
name = plugin.name;
|
|
@@ -380,11 +324,9 @@ const createHandler = params => {
|
|
|
380
324
|
/**
|
|
381
325
|
*
|
|
382
326
|
*/
|
|
383
|
-
|
|
384
327
|
app.addHook("preHandler", async () => {
|
|
385
328
|
const plugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
|
|
386
329
|
let name;
|
|
387
|
-
|
|
388
330
|
try {
|
|
389
331
|
for (const plugin of plugins) {
|
|
390
332
|
name = plugin.name;
|
|
@@ -396,14 +338,13 @@ const createHandler = params => {
|
|
|
396
338
|
throw ex;
|
|
397
339
|
}
|
|
398
340
|
});
|
|
341
|
+
|
|
399
342
|
/**
|
|
400
343
|
*
|
|
401
344
|
*/
|
|
402
|
-
|
|
403
345
|
const preSerialization = async (_, __, payload) => {
|
|
404
346
|
const plugins = app.webiny.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
|
|
405
347
|
let name;
|
|
406
|
-
|
|
407
348
|
try {
|
|
408
349
|
for (const plugin of plugins) {
|
|
409
350
|
name = plugin.name;
|
|
@@ -414,10 +355,8 @@ const createHandler = params => {
|
|
|
414
355
|
console.error(stringifyError(ex));
|
|
415
356
|
throw ex;
|
|
416
357
|
}
|
|
417
|
-
|
|
418
358
|
return payload;
|
|
419
359
|
};
|
|
420
|
-
|
|
421
360
|
app.addHook("preSerialization", preSerialization);
|
|
422
361
|
app.setErrorHandler(async (error, request, reply) => {
|
|
423
362
|
return reply.status(500).headers({
|
|
@@ -437,7 +376,6 @@ const createHandler = params => {
|
|
|
437
376
|
/**
|
|
438
377
|
* Log error to cloud, as these can be extremely annoying to debug!
|
|
439
378
|
*/
|
|
440
|
-
|
|
441
379
|
console.error("@webiny/handler");
|
|
442
380
|
console.error(stringifyError(error));
|
|
443
381
|
reply.status(500).headers({
|
|
@@ -460,12 +398,20 @@ const createHandler = params => {
|
|
|
460
398
|
return reply;
|
|
461
399
|
});
|
|
462
400
|
/**
|
|
463
|
-
*
|
|
401
|
+
* We need to output the benchmark results at the end of the request in both response and timeout cases
|
|
464
402
|
*/
|
|
403
|
+
app.addHook("onResponse", async () => {
|
|
404
|
+
await context.benchmark.output();
|
|
405
|
+
});
|
|
406
|
+
app.addHook("onTimeout", async () => {
|
|
407
|
+
await context.benchmark.output();
|
|
408
|
+
});
|
|
465
409
|
|
|
410
|
+
/**
|
|
411
|
+
* With these plugins we give users possibility to do anything they want on our fastify instance.
|
|
412
|
+
*/
|
|
466
413
|
const modifyPlugins = app.webiny.plugins.byType(_ModifyFastifyPlugin.ModifyFastifyPlugin.type);
|
|
467
414
|
let modifyFastifyPluginName;
|
|
468
|
-
|
|
469
415
|
try {
|
|
470
416
|
for (const plugin of modifyPlugins) {
|
|
471
417
|
modifyFastifyPluginName = plugin.name;
|
|
@@ -476,8 +422,6 @@ const createHandler = params => {
|
|
|
476
422
|
console.error(stringifyError(ex));
|
|
477
423
|
throw ex;
|
|
478
424
|
}
|
|
479
|
-
|
|
480
425
|
return app;
|
|
481
426
|
};
|
|
482
|
-
|
|
483
427
|
exports.createHandler = createHandler;
|
package/fastify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","getDefaultHeaders","routes","keys","Object","all","every","key","length","filter","type","Array","isArray","sort","join","stringifyError","error","name","message","code","stack","data","JSON","stringify","constructorName","constructor","process","env","DEBUG","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","find","includes","console","WebinyError","override","addDefinedRoute","push","app","fastify","addHook","route","method","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","reply","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","server","ex","decorate","routePlugins","webiny","byType","RoutePlugin","routePluginName","plugin","cb","request","defaultHeaders","headers","HandlerOnRequestPlugin","result","exec","sent","explanation","send","hijack","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","__","payload","HandlerResultPlugin","handle","setErrorHandler","status","HandlerErrorPlugin","middleware","map","pl","next","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","modify"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection } from \"@webiny/plugins/types\";\nimport fastify, {\n FastifyServerOptions as ServerOptions,\n preSerializationAsyncHookHandler\n} from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ContextRoutes, DefinedContextRoutes, RouteMethodOptions, HTTPMethods } from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { middleware } from \"~/middleware\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin\";\n\nconst DEFAULT_HEADERS: Record<string, string> = {\n \"Cache-Control\": \"no-store\",\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"*\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET,DELETE,PUT,PATCH\",\n ...getWebinyVersionHeaders()\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): Record<string, string> => {\n /**\n * If we are accepting all headers, just output that one.\n */\n const keys = Object.keys(routes) as HTTPMethods[];\n const all = keys.every(key => routes[key].length > 0);\n if (all) {\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": \"*\"\n };\n }\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": keys\n .filter(type => {\n if (!routes[type] || Array.isArray(routes[type]) === false) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\")\n };\n};\n\nconst stringifyError = (error: Error) => {\n const { name, message, code, stack, data } = error as any;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n\nconst OPTIONS_HEADERS: Record<string, string> = {\n \"Access-Control-Max-Age\": \"86400\",\n \"Cache-Control\": \"public, max-age=86400\"\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection;\n options?: ServerOptions;\n}\n\nexport const createHandler = (params: CreateHandlerParams) => {\n const definedRoutes: DefinedContextRoutes = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: [],\n COPY: [],\n LOCK: [],\n MKCOL: [],\n MOVE: [],\n PROPFIND: [],\n PROPPATCH: [],\n SEARCH: [],\n TRACE: [],\n UNLOCK: []\n };\n\n const throwOnDefinedRoute = (\n type: HTTPMethods | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).find(key => {\n const routes = definedRoutes[key as HTTPMethods];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n console.error(\n `Error while registering onAll route. One of the routes is already defined.`\n );\n console.error(JSON.stringify(all));\n throw new WebinyError(\n `You cannot override a route with onAll() method, please remove unnecessary route from the system.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n } else if (definedRoutes[type].includes(path) === false) {\n return;\n } else if (options?.override === true) {\n return;\n }\n console.error(`Error while trying to override route: [${type}] ${path}`);\n throw new WebinyError(\n `When you are trying to override existing route, you must send \"override\" parameter when adding that route.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n };\n\n const addDefinedRoute = (type: HTTPMethods, path: string): void => {\n if (!definedRoutes[type]) {\n return;\n } else if (definedRoutes[type].includes(path)) {\n return;\n }\n definedRoutes[type].push(path);\n };\n /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n ...(params.options || {})\n });\n /**\n * We need to register routes in our system so we can output headers later on and dissallow overriding routes.\n */\n app.addHook(\"onRoute\", route => {\n const method = route.method;\n if (Array.isArray(method)) {\n for (const m of method) {\n addDefinedRoute(m, route.path);\n }\n return;\n }\n addDefinedRoute(method, route.path);\n });\n /**\n * ############################\n * Register the Fastify plugins.\n */\n /**\n * Package @fastify/cookie\n *\n * https://github.com/fastify/fastify-cookie\n */\n app.register(fastifyCookie, {\n parseOptions: {} // options for parsing cookies\n });\n /**\n * Package @fastify/compress\n *\n * https://github.com/fastify/fastify-compress\n */\n app.register(fastifyCompress, {\n global: true,\n threshold: 1024,\n onUnsupportedEncoding: (encoding, _, reply) => {\n reply.code(406);\n return `We do not support the ${encoding} encoding.`;\n },\n inflateIfDeflated: true\n });\n /**\n * Route helpers - mostly for users.\n */\n const routes: ContextRoutes = {\n defined: definedRoutes,\n onPost: (path, handler, options) => {\n throwOnDefinedRoute(\"POST\", path, options);\n app.post(path, handler);\n },\n onGet: (path, handler, options) => {\n throwOnDefinedRoute(\"GET\", path, options);\n app.get(path, handler);\n },\n onOptions: (path, handler, options) => {\n throwOnDefinedRoute(\"OPTIONS\", path, options);\n app.options(path, handler);\n },\n onDelete: (path, handler, options) => {\n throwOnDefinedRoute(\"DELETE\", path, options);\n app.delete(path, handler);\n },\n onPatch: (path, handler, options) => {\n throwOnDefinedRoute(\"PATCH\", path, options);\n app.patch(path, handler);\n },\n onPut: (path, handler, options) => {\n throwOnDefinedRoute(\"PUT\", path, options);\n app.put(path, handler);\n },\n onAll: (path, handler, options) => {\n throwOnDefinedRoute(\"ALL\", path, options);\n app.all(path, handler);\n },\n onHead: (path, handler, options) => {\n throwOnDefinedRoute(\"HEAD\", path, options);\n app.head(path, handler);\n }\n };\n let context: Context;\n try {\n context = new Context({\n plugins: [\n /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient(),\n ...(params.plugins || [])\n ],\n /**\n * Inserted via webpack on build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n server: app,\n routes\n });\n } catch (ex) {\n console.error(`Error while constructing the Context.`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We are attaching our custom context to webiny variable on the fastify app, so it is accessible everywhere.\n */\n app.decorate(\"webiny\", context);\n\n /**\n * We have few types of triggers:\n * * Events - EventPlugin\n * * Routes - RoutePlugin\n *\n * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.\n */\n const routePlugins = app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type);\n\n /**\n * Add routes to the system.\n */\n let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * On every request we add default headers, which can be changed later.\n * Also, if it is an options request, we skip everything after this hook and output options headers.\n */\n app.addHook(\"onRequest\", async (request, reply) => {\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n /**\n * Users can define their own custom handlers for the onRequest event - so let's run them first.\n */\n const plugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply);\n if (result === false) {\n return;\n }\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerOnRequestPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the onRequest hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n /**\n * When we receive the OPTIONS request, we end it before it goes any further as there is no need for anything to run after this - at least for our use cases.\n *\n * Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.\n */\n if (request.method !== \"OPTIONS\") {\n return;\n }\n\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.error(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return;\n }\n\n reply\n .headers({ ...defaultHeaders, ...OPTIONS_HEADERS })\n .code(204)\n .send(\"\")\n .hijack();\n });\n\n app.addHook(\"preParsing\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ContextPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preParsing hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"BeforeHandlerPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preHandler hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.handle(app.webiny, payload);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerResultPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preSerialization hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n return payload;\n };\n\n app.addHook(\"preSerialization\", preSerialization);\n\n app.setErrorHandler<WebinyError>(async (error, request, reply) => {\n return reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n });\n\n app.addHook(\"onError\", async (_, reply, error: any) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n /**\n * Log error to cloud, as these can be extremely annoying to debug!\n */\n console.error(\"@webiny/handler\");\n console.error(stringifyError(error));\n\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: Function) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n\n /**\n * With these plugins we give users possibility to do anything they want on our fastify instance.\n */\n const modifyPlugins = app.webiny.plugins.byType<ModifyFastifyPlugin>(ModifyFastifyPlugin.type);\n\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,eAAuC;EACzC,iBAAiB,UADwB;EAEzC,gBAAgB,iCAFyB;EAGzC,+BAA+B,GAHU;EAIzC,gCAAgC,GAJS;EAKzC,gCAAgC;AALS,GAMtC,IAAAC,8BAAA,GANsC,CAA7C;;AASA,MAAMC,iB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AMQ;AAChB;AACA;IACgB7F,IAAI,CAACC,SAAL,CAAe;MACXL,OAAO,EAAEF,KAAK,CAACE,OADJ;MAEXC,IAAI,EAAEH,KAAK,CAACG,IAFD;MAGXE,IAAI,EAAEL,KAAK,CAACK;IAHD,CAAf,CATR;IAgBA,MAAMyD,OAAO,GAAG,IAAAkD,sBAAA,EACZlC,OAAO,CAACmC,GAAR,CAAYC,EAAE,IAAI;MACd,OAAO,CAACtC,OAAD,EAAmB5E,KAAnB,EAAiCmH,IAAjC,KAAoD;QACvD,OAAOD,EAAE,CAACN,MAAH,CAAUhC,OAAV,EAAmB5E,KAAnB,EAA0BmH,IAA1B,CAAP;MACH,CAFD;IAGH,CAJD,CADY,CAAhB;IAOA,MAAMrD,OAAO,CAACnB,GAAG,CAAC0C,MAAL,EAAarF,KAAb,CAAb;IAEA,OAAO0D,KAAP;EACH,CAlCD;EAoCA;AACJ;AACA;;EACI,MAAM0D,aAAa,GAAGzE,GAAG,CAAC0C,MAAJ,CAAWP,OAAX,CAAmBQ,MAAnB,CAA+C+B,wCAAA,CAAoB3H,IAAnE,CAAtB;EAEA,IAAI4H,uBAAJ;;EACA,IAAI;IACA,KAAK,MAAM7B,MAAX,IAAqB2B,aAArB,EAAoC;MAChCE,uBAAuB,GAAG7B,MAAM,CAACxF,IAAjC;MACAwF,MAAM,CAAC8B,MAAP,CAAc5E,GAAd;IACH;EACJ,CALD,CAKE,OAAOuC,EAAP,EAAW;IACT5C,OAAO,CAACtC,KAAR,CACK,iDACGsH,uBAAuB,GAAI,IAAGA,uBAAwB,GAA/B,GAAoC,EAC9D,qDAHL;IAKAhF,OAAO,CAACtC,KAAR,CAAcD,cAAc,CAACmF,EAAD,CAA5B;IACA,MAAMA,EAAN;EACH;;EAED,OAAOvC,GAAP;AACH,CApaM"}
|
|
1
|
+
{"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","getDefaultHeaders","routes","keys","Object","all","every","key","length","filter","type","Array","isArray","sort","join","stringifyError","error","name","message","code","stack","data","JSON","stringify","constructorName","constructor","process","env","DEBUG","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","find","includes","console","WebinyError","override","addDefinedRoute","push","app","fastify","addHook","route","method","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","reply","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","server","ex","decorate","routePlugins","webiny","byType","RoutePlugin","routePluginName","plugin","cb","request","defaultHeaders","headers","HandlerOnRequestPlugin","result","exec","sent","explanation","send","hijack","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","__","payload","HandlerResultPlugin","handle","setErrorHandler","status","HandlerErrorPlugin","middleware","map","pl","next","benchmark","output","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","modify"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection } from \"@webiny/plugins/types\";\nimport fastify, {\n FastifyServerOptions as ServerOptions,\n preSerializationAsyncHookHandler\n} from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ContextRoutes, DefinedContextRoutes, RouteMethodOptions, HTTPMethods } from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { middleware } from \"~/middleware\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin\";\n\nconst DEFAULT_HEADERS: Record<string, string> = {\n \"Cache-Control\": \"no-store\",\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"*\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET,DELETE,PUT,PATCH\",\n ...getWebinyVersionHeaders()\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): Record<string, string> => {\n /**\n * If we are accepting all headers, just output that one.\n */\n const keys = Object.keys(routes) as HTTPMethods[];\n const all = keys.every(key => routes[key].length > 0);\n if (all) {\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": \"*\"\n };\n }\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": keys\n .filter(type => {\n if (!routes[type] || Array.isArray(routes[type]) === false) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\")\n };\n};\n\nconst stringifyError = (error: Error) => {\n const { name, message, code, stack, data } = error as any;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n\nconst OPTIONS_HEADERS: Record<string, string> = {\n \"Access-Control-Max-Age\": \"86400\",\n \"Cache-Control\": \"public, max-age=86400\"\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection;\n options?: ServerOptions;\n}\n\nexport const createHandler = (params: CreateHandlerParams) => {\n const definedRoutes: DefinedContextRoutes = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: [],\n COPY: [],\n LOCK: [],\n MKCOL: [],\n MOVE: [],\n PROPFIND: [],\n PROPPATCH: [],\n SEARCH: [],\n TRACE: [],\n UNLOCK: []\n };\n\n const throwOnDefinedRoute = (\n type: HTTPMethods | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).find(key => {\n const routes = definedRoutes[key as HTTPMethods];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n console.error(\n `Error while registering onAll route. One of the routes is already defined.`\n );\n console.error(JSON.stringify(all));\n throw new WebinyError(\n `You cannot override a route with onAll() method, please remove unnecessary route from the system.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n } else if (definedRoutes[type].includes(path) === false) {\n return;\n } else if (options?.override === true) {\n return;\n }\n console.error(`Error while trying to override route: [${type}] ${path}`);\n throw new WebinyError(\n `When you are trying to override existing route, you must send \"override\" parameter when adding that route.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n };\n\n const addDefinedRoute = (type: HTTPMethods, path: string): void => {\n if (!definedRoutes[type]) {\n return;\n } else if (definedRoutes[type].includes(path)) {\n return;\n }\n definedRoutes[type].push(path);\n };\n /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n ...(params.options || {})\n });\n /**\n * We need to register routes in our system so we can output headers later on and dissallow overriding routes.\n */\n app.addHook(\"onRoute\", route => {\n const method = route.method;\n if (Array.isArray(method)) {\n for (const m of method) {\n addDefinedRoute(m, route.path);\n }\n return;\n }\n addDefinedRoute(method, route.path);\n });\n /**\n * ############################\n * Register the Fastify plugins.\n */\n /**\n * Package @fastify/cookie\n *\n * https://github.com/fastify/fastify-cookie\n */\n app.register(fastifyCookie, {\n parseOptions: {} // options for parsing cookies\n });\n /**\n * Package @fastify/compress\n *\n * https://github.com/fastify/fastify-compress\n */\n app.register(fastifyCompress, {\n global: true,\n threshold: 1024,\n onUnsupportedEncoding: (encoding, _, reply) => {\n reply.code(406);\n return `We do not support the ${encoding} encoding.`;\n },\n inflateIfDeflated: true\n });\n /**\n * Route helpers - mostly for users.\n */\n const routes: ContextRoutes = {\n defined: definedRoutes,\n onPost: (path, handler, options) => {\n throwOnDefinedRoute(\"POST\", path, options);\n app.post(path, handler);\n },\n onGet: (path, handler, options) => {\n throwOnDefinedRoute(\"GET\", path, options);\n app.get(path, handler);\n },\n onOptions: (path, handler, options) => {\n throwOnDefinedRoute(\"OPTIONS\", path, options);\n app.options(path, handler);\n },\n onDelete: (path, handler, options) => {\n throwOnDefinedRoute(\"DELETE\", path, options);\n app.delete(path, handler);\n },\n onPatch: (path, handler, options) => {\n throwOnDefinedRoute(\"PATCH\", path, options);\n app.patch(path, handler);\n },\n onPut: (path, handler, options) => {\n throwOnDefinedRoute(\"PUT\", path, options);\n app.put(path, handler);\n },\n onAll: (path, handler, options) => {\n throwOnDefinedRoute(\"ALL\", path, options);\n app.all(path, handler);\n },\n onHead: (path, handler, options) => {\n throwOnDefinedRoute(\"HEAD\", path, options);\n app.head(path, handler);\n }\n };\n let context: Context;\n try {\n context = new Context({\n plugins: [\n /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient(),\n ...(params.plugins || [])\n ],\n /**\n * Inserted via webpack on build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n server: app,\n routes\n });\n } catch (ex) {\n console.error(`Error while constructing the Context.`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We are attaching our custom context to webiny variable on the fastify app, so it is accessible everywhere.\n */\n app.decorate(\"webiny\", context);\n\n /**\n * We have few types of triggers:\n * * Events - EventPlugin\n * * Routes - RoutePlugin\n *\n * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.\n */\n const routePlugins = app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type);\n\n /**\n * Add routes to the system.\n */\n let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * On every request we add default headers, which can be changed later.\n * Also, if it is an options request, we skip everything after this hook and output options headers.\n */\n app.addHook(\"onRequest\", async (request, reply) => {\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n /**\n * Users can define their own custom handlers for the onRequest event - so let's run them first.\n */\n const plugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply);\n if (result === false) {\n return;\n }\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerOnRequestPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the onRequest hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n /**\n * When we receive the OPTIONS request, we end it before it goes any further as there is no need for anything to run after this - at least for our use cases.\n *\n * Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.\n */\n if (request.method !== \"OPTIONS\") {\n return;\n }\n\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.error(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return;\n }\n\n reply\n .headers({ ...defaultHeaders, ...OPTIONS_HEADERS })\n .code(204)\n .send(\"\")\n .hijack();\n });\n\n app.addHook(\"preParsing\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ContextPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preParsing hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"BeforeHandlerPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preHandler hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.handle(app.webiny, payload);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerResultPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preSerialization hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n return payload;\n };\n\n app.addHook(\"preSerialization\", preSerialization);\n\n app.setErrorHandler<WebinyError>(async (error, request, reply) => {\n return reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n });\n\n app.addHook(\"onError\", async (_, reply, error: any) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n /**\n * Log error to cloud, as these can be extremely annoying to debug!\n */\n console.error(\"@webiny/handler\");\n console.error(stringifyError(error));\n\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: Function) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n /**\n * We need to output the benchmark results at the end of the request in both response and timeout cases\n */\n app.addHook(\"onResponse\", async () => {\n await context.benchmark.output();\n });\n app.addHook(\"onTimeout\", async () => {\n await context.benchmark.output();\n });\n\n /**\n * With these plugins we give users possibility to do anything they want on our fastify instance.\n */\n const modifyPlugins = app.webiny.plugins.byType<ModifyFastifyPlugin>(ModifyFastifyPlugin.type);\n\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"mappings":";;;;;;;;AACA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,eAAuC;EACzC,eAAe,EAAE,UAAU;EAC3B,cAAc,EAAE,iCAAiC;EACjD,6BAA6B,EAAE,GAAG;EAClC,8BAA8B,EAAE,GAAG;EACnC,8BAA8B,EAAE;AAAmC,GAChE,IAAAC,8BAAuB,GAAE,CAC/B;AAED,MAAMC,iBAAiB,GAAIC,MAA4B,IAA6B;EAChF;AACJ;AACA;EACI,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACD,MAAM,CAAkB;EACjD,MAAMG,GAAG,GAAGF,IAAI,CAACG,KAAK,CAACC,GAAG,IAAIL,MAAM,CAACK,GAAG,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;EACrD,IAAIH,GAAG,EAA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d,OAAO,CAACtC,OAAgB,EAAE5E,KAAY,EAAEmH,IAAc,KAAK;QACvD,OAAOD,EAAE,CAACN,MAAM,CAAChC,OAAO,EAAE5E,KAAK,EAAEmH,IAAI,CAAC;MAC1C,CAAC;IACL,CAAC,CAAC,CACL;IACD,MAAMrD,OAAO,CAACnB,GAAG,CAAC0C,MAAM,EAAErF,KAAK,CAAC;IAEhC,OAAO0D,KAAK;EAChB,CAAC,CAAC;EACF;AACJ;AACA;EACIf,GAAG,CAACE,OAAO,CAAC,YAAY,EAAE,YAAY;IAClC,MAAM+B,OAAO,CAACwC,SAAS,CAACC,MAAM,EAAE;EACpC,CAAC,CAAC;EACF1E,GAAG,CAACE,OAAO,CAAC,WAAW,EAAE,YAAY;IACjC,MAAM+B,OAAO,CAACwC,SAAS,CAACC,MAAM,EAAE;EACpC,CAAC,CAAC;;EAEF;AACJ;AACA;EACI,MAAMC,aAAa,GAAG3E,GAAG,CAAC0C,MAAM,CAACP,OAAO,CAACQ,MAAM,CAAsBiC,wCAAmB,CAAC7H,IAAI,CAAC;EAE9F,IAAI8H,uBAA2C;EAC/C,IAAI;IACA,KAAK,MAAM/B,MAAM,IAAI6B,aAAa,EAAE;MAChCE,uBAAuB,GAAG/B,MAAM,CAACxF,IAAI;MACrCwF,MAAM,CAACgC,MAAM,CAAC9E,GAAG,CAAC;IACtB;EACJ,CAAC,CAAC,OAAOuC,EAAE,EAAE;IACT5C,OAAO,CAACtC,KAAK,CACR,iDACGwH,uBAAuB,GAAI,IAAGA,uBAAwB,GAAE,GAAG,EAC9D,qDAAoD,CACxD;IACDlF,OAAO,CAACtC,KAAK,CAACD,cAAc,CAACmF,EAAE,CAAC,CAAC;IACjC,MAAMA,EAAE;EACZ;EAEA,OAAOvC,GAAG;AACd,CAAC;AAAC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3,22 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
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
6
|
var _fastify = require("./fastify");
|
|
21
|
-
|
|
22
7
|
Object.keys(_fastify).forEach(function (key) {
|
|
23
8
|
if (key === "default" || key === "__esModule") return;
|
|
24
9
|
if (key in exports && exports[key] === _fastify[key]) return;
|
|
@@ -29,9 +14,7 @@ Object.keys(_fastify).forEach(function (key) {
|
|
|
29
14
|
}
|
|
30
15
|
});
|
|
31
16
|
});
|
|
32
|
-
|
|
33
17
|
var _Context = require("./Context");
|
|
34
|
-
|
|
35
18
|
Object.keys(_Context).forEach(function (key) {
|
|
36
19
|
if (key === "default" || key === "__esModule") return;
|
|
37
20
|
if (key in exports && exports[key] === _Context[key]) return;
|
|
@@ -42,9 +25,7 @@ Object.keys(_Context).forEach(function (key) {
|
|
|
42
25
|
}
|
|
43
26
|
});
|
|
44
27
|
});
|
|
45
|
-
|
|
46
28
|
var _EventPlugin = require("./plugins/EventPlugin");
|
|
47
|
-
|
|
48
29
|
Object.keys(_EventPlugin).forEach(function (key) {
|
|
49
30
|
if (key === "default" || key === "__esModule") return;
|
|
50
31
|
if (key in exports && exports[key] === _EventPlugin[key]) return;
|
|
@@ -55,9 +36,7 @@ Object.keys(_EventPlugin).forEach(function (key) {
|
|
|
55
36
|
}
|
|
56
37
|
});
|
|
57
38
|
});
|
|
58
|
-
|
|
59
39
|
var _RoutePlugin = require("./plugins/RoutePlugin");
|
|
60
|
-
|
|
61
40
|
Object.keys(_RoutePlugin).forEach(function (key) {
|
|
62
41
|
if (key === "default" || key === "__esModule") return;
|
|
63
42
|
if (key in exports && exports[key] === _RoutePlugin[key]) return;
|
|
@@ -68,9 +47,7 @@ Object.keys(_RoutePlugin).forEach(function (key) {
|
|
|
68
47
|
}
|
|
69
48
|
});
|
|
70
49
|
});
|
|
71
|
-
|
|
72
50
|
var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
|
|
73
|
-
|
|
74
51
|
Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
|
|
75
52
|
if (key === "default" || key === "__esModule") return;
|
|
76
53
|
if (key in exports && exports[key] === _BeforeHandlerPlugin[key]) return;
|
|
@@ -81,9 +58,7 @@ Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
|
|
|
81
58
|
}
|
|
82
59
|
});
|
|
83
60
|
});
|
|
84
|
-
|
|
85
61
|
var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
|
|
86
|
-
|
|
87
62
|
Object.keys(_HandlerErrorPlugin).forEach(function (key) {
|
|
88
63
|
if (key === "default" || key === "__esModule") return;
|
|
89
64
|
if (key in exports && exports[key] === _HandlerErrorPlugin[key]) return;
|
|
@@ -94,9 +69,7 @@ Object.keys(_HandlerErrorPlugin).forEach(function (key) {
|
|
|
94
69
|
}
|
|
95
70
|
});
|
|
96
71
|
});
|
|
97
|
-
|
|
98
72
|
var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
|
|
99
|
-
|
|
100
73
|
Object.keys(_HandlerResultPlugin).forEach(function (key) {
|
|
101
74
|
if (key === "default" || key === "__esModule") return;
|
|
102
75
|
if (key in exports && exports[key] === _HandlerResultPlugin[key]) return;
|
|
@@ -107,9 +80,7 @@ Object.keys(_HandlerResultPlugin).forEach(function (key) {
|
|
|
107
80
|
}
|
|
108
81
|
});
|
|
109
82
|
});
|
|
110
|
-
|
|
111
83
|
var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
|
|
112
|
-
|
|
113
84
|
Object.keys(_HandlerOnRequestPlugin).forEach(function (key) {
|
|
114
85
|
if (key === "default" || key === "__esModule") return;
|
|
115
86
|
if (key in exports && exports[key] === _HandlerOnRequestPlugin[key]) return;
|
|
@@ -120,9 +91,7 @@ Object.keys(_HandlerOnRequestPlugin).forEach(function (key) {
|
|
|
120
91
|
}
|
|
121
92
|
});
|
|
122
93
|
});
|
|
123
|
-
|
|
124
94
|
var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
|
|
125
|
-
|
|
126
95
|
Object.keys(_ModifyFastifyPlugin).forEach(function (key) {
|
|
127
96
|
if (key === "default" || key === "__esModule") return;
|
|
128
97
|
if (key in exports && exports[key] === _ModifyFastifyPlugin[key]) return;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * 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"}
|
package/middleware.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.middleware = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Compose a single middleware from the array of middleware functions
|
|
10
9
|
*/
|
|
@@ -12,22 +11,19 @@ const middleware = (functions = []) => {
|
|
|
12
11
|
return (...args) => {
|
|
13
12
|
if (!functions.length) {
|
|
14
13
|
return Promise.resolve();
|
|
15
|
-
}
|
|
16
|
-
|
|
14
|
+
}
|
|
17
15
|
|
|
16
|
+
// Create a clone of function chain to prevent modifying the original array with `shift()`
|
|
18
17
|
const chain = [...functions];
|
|
19
18
|
return new Promise((parentResolve, parentReject) => {
|
|
20
19
|
const next = async () => {
|
|
21
20
|
const fn = chain.shift();
|
|
22
|
-
|
|
23
21
|
if (!fn) {
|
|
24
22
|
return Promise.resolve();
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
return new Promise(async (resolve, reject) => {
|
|
28
25
|
try {
|
|
29
26
|
const result = await fn(...args, resolve);
|
|
30
|
-
|
|
31
27
|
if (typeof result !== "undefined") {
|
|
32
28
|
return parentResolve(result);
|
|
33
29
|
}
|
|
@@ -42,10 +38,8 @@ const middleware = (functions = []) => {
|
|
|
42
38
|
parentReject(e);
|
|
43
39
|
});
|
|
44
40
|
};
|
|
45
|
-
|
|
46
41
|
return next();
|
|
47
42
|
});
|
|
48
43
|
};
|
|
49
44
|
};
|
|
50
|
-
|
|
51
45
|
exports.middleware = middleware;
|
package/middleware.js.map
CHANGED
|
@@ -1 +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":"
|
|
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,EAAE,KAAe;EAChE,OAAO,CAAC,GAAGC,IAAc,KAAmB;IACxC,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOC,OAAO,CAACC,OAAO,EAAE;IAC5B;;IAEA;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAS,CAAC;IAC5B,OAAO,IAAIG,OAAO,CAAC,CAACG,aAAkB,EAAEC,YAAY,KAAK;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAK,EAAE;QACxB,IAAI,CAACD,EAAE,EAAE;UACL,OAAON,OAAO,CAACC,OAAO,EAAE;QAC5B;QAEA,OAAO,IAAID,OAAO,CAAC,OAAOC,OAAO,EAAEO,MAAM,KAAK;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAI,EAAEG,OAAO,CAAC;YACzC,IAAI,OAAOQ,MAAM,KAAK,WAAW,EAAE;cAC/B,OAAON,aAAa,CAACM,MAAM,CAAC;YAChC;UACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;YACRF,MAAM,CAACE,CAAC,CAAC;UACb;QACJ,CAAC,CAAC,CACGC,IAAI,CAAC,MAAM;UACR,OAAON,IAAI,EAAE;QACjB,CAAC,CAAC,CACDM,IAAI,CAAC,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAI,CAAC;QAC1B,CAAC,CAAC,CACDc,KAAK,CAACF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAC,CAAC;QACnB,CAAC,CAAC;MACV,CAAC;MAED,OAAOL,IAAI,EAAE;IACjB,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.35.0-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/runtime": "7.
|
|
15
|
+
"@babel/runtime": "7.20.13",
|
|
16
16
|
"@fastify/compress": "6.2.0",
|
|
17
17
|
"@fastify/cookie": "8.3.0",
|
|
18
|
-
"@webiny/api": "5.
|
|
19
|
-
"@webiny/error": "5.
|
|
20
|
-
"@webiny/handler-client": "5.
|
|
21
|
-
"@webiny/plugins": "5.
|
|
22
|
-
"@webiny/utils": "5.
|
|
18
|
+
"@webiny/api": "5.35.0-beta.1",
|
|
19
|
+
"@webiny/error": "5.35.0-beta.1",
|
|
20
|
+
"@webiny/handler-client": "5.35.0-beta.1",
|
|
21
|
+
"@webiny/plugins": "5.35.0-beta.1",
|
|
22
|
+
"@webiny/utils": "5.35.0-beta.1",
|
|
23
23
|
"fastify": "4.11.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@babel/core": "^7.19.3",
|
|
28
28
|
"@babel/preset-env": "^7.19.4",
|
|
29
29
|
"@babel/preset-typescript": "^7.18.6",
|
|
30
|
-
"@webiny/cli": "^5.
|
|
31
|
-
"@webiny/project-utils": "^5.
|
|
30
|
+
"@webiny/cli": "^5.35.0-beta.1",
|
|
31
|
+
"@webiny/project-utils": "^5.35.0-beta.1",
|
|
32
32
|
"babel-plugin-lodash": "^3.3.4",
|
|
33
33
|
"merge": "^1.2.1",
|
|
34
34
|
"rimraf": "^3.0.2",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"build": "yarn webiny run build",
|
|
44
44
|
"watch": "yarn webiny run watch"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "6b376faedf02e056efbbf1e4d46d537850773ce0"
|
|
47
47
|
}
|
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createBeforeHandlerPlugin = exports.BeforeHandlerPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _plugins = require("@webiny/plugins");
|
|
13
|
-
|
|
14
10
|
class BeforeHandlerPlugin extends _plugins.Plugin {
|
|
15
11
|
constructor(callable) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "_callable", void 0);
|
|
18
14
|
this._callable = callable;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
async apply(context) {
|
|
22
17
|
if (typeof this._callable !== "function") {
|
|
23
18
|
throw Error(`Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
return this._callable(context);
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
}
|
|
30
|
-
|
|
31
23
|
exports.BeforeHandlerPlugin = BeforeHandlerPlugin;
|
|
32
24
|
(0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
|
|
33
|
-
|
|
34
25
|
const createBeforeHandlerPlugin = callable => {
|
|
35
26
|
return new BeforeHandlerPlugin(callable);
|
|
36
27
|
};
|
|
37
|
-
|
|
38
28
|
exports.createBeforeHandlerPlugin = createBeforeHandlerPlugin;
|
|
@@ -1 +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":"
|
|
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,mBAAmB,SAAsCC,eAAM,CAAC;EAIzEC,WAAW,CAACC,QAAkC,EAAE;IAC5C,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,KAAK,CAACC,OAAU,EAAiB;IAC1C,IAAI,OAAO,IAAI,CAACF,SAAS,KAAK,UAAU,EAAE;MACtC,MAAMG,KAAK,CACN,6IAA4I,CAChJ;IACL;IAEA,OAAO,IAAI,CAACH,SAAS,CAACE,OAAO,CAAC;EAClC;AACJ;AAAC;AAAA,8BAlBYN,mBAAmB,UACmB,gBAAgB;AAmB5D,MAAMQ,yBAAyB,GAClCL,QAAkC,IACT;EACzB,OAAO,IAAIH,mBAAmB,CAAIG,QAAQ,CAAC;AAC/C,CAAC;AAAC"}
|
package/plugins/EventPlugin.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createEvent = exports.EventPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* EventPlugin must be handled in the package which implements fastify for certain cloud.
|
|
16
12
|
* There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
|
|
@@ -19,20 +15,17 @@ var _Plugin = require("@webiny/plugins/Plugin");
|
|
|
19
15
|
* Note that only one EventPlugin can be defined per fastify initialisation.
|
|
20
16
|
* If more is needed, check ~/fastify.ts and implement that possibility.
|
|
21
17
|
*/
|
|
18
|
+
|
|
22
19
|
class EventPlugin extends _Plugin.Plugin {
|
|
23
20
|
constructor(cb) {
|
|
24
21
|
super();
|
|
25
22
|
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
26
23
|
this.cb = cb;
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
exports.EventPlugin = EventPlugin;
|
|
32
27
|
(0, _defineProperty2.default)(EventPlugin, "type", "handler.fastify.event");
|
|
33
|
-
|
|
34
28
|
const createEvent = cb => {
|
|
35
29
|
return new EventPlugin(cb);
|
|
36
30
|
};
|
|
37
|
-
|
|
38
31
|
exports.createEvent = createEvent;
|
|
@@ -1 +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":"
|
|
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,WAAW,SAIdC,cAAM,CAAC;EAKNC,WAAW,CAACC,EAAmD,EAAE;IACpE,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BAbYH,WAAW,UAKU,uBAAuB;AAUlD,MAAMI,WAAW,GAKpBD,EAAmD,IAClD;EACD,OAAO,IAAIH,WAAW,CAA6BG,EAAE,CAAC;AAC1D,CAAC;AAAC"}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createHandlerErrorPlugin = exports.HandlerErrorPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _plugins = require("@webiny/plugins");
|
|
13
|
-
|
|
14
10
|
class HandlerErrorPlugin extends _plugins.Plugin {
|
|
15
11
|
constructor(callable) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "_callable", void 0);
|
|
18
14
|
this._callable = callable;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
async handle(context, error, next) {
|
|
22
17
|
return this._callable(context, error, next);
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
exports.HandlerErrorPlugin = HandlerErrorPlugin;
|
|
28
21
|
(0, _defineProperty2.default)(HandlerErrorPlugin, "type", "handler-error");
|
|
29
|
-
|
|
30
22
|
const createHandlerErrorPlugin = callable => {
|
|
31
23
|
return new HandlerErrorPlugin(callable);
|
|
32
24
|
};
|
|
33
|
-
|
|
34
25
|
exports.createHandlerErrorPlugin = createHandlerErrorPlugin;
|
|
@@ -1 +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":"
|
|
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,kBAAkB,SAAsCC,eAAM,CAAC;EAKjEC,WAAW,CAACC,QAAiC,EAAE;IAClD,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,MAAM,CAACC,OAAU,EAAEC,KAAY,EAAEC,IAAc,EAAgB;IACxE,OAAO,IAAI,CAACJ,SAAS,CAACE,OAAO,EAAEC,KAAK,EAAEC,IAAI,CAAC;EAC/C;AACJ;AAAC;AAAA,8BAbYR,kBAAkB,UACoB,eAAe;AAc3D,MAAMS,wBAAwB,GACjCN,QAAiC,IACT;EACxB,OAAO,IAAIH,kBAAkB,CAAIG,QAAQ,CAAC;AAC9C,CAAC;AAAC"}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createHandlerOnRequest = exports.HandlerOnRequestPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _plugins = require("@webiny/plugins");
|
|
13
|
-
|
|
14
10
|
class HandlerOnRequestPlugin extends _plugins.Plugin {
|
|
15
11
|
constructor(cb) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
14
|
this.cb = cb;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
async exec(request, reply) {
|
|
22
17
|
return this.cb(request, reply);
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
exports.HandlerOnRequestPlugin = HandlerOnRequestPlugin;
|
|
28
21
|
(0, _defineProperty2.default)(HandlerOnRequestPlugin, "type", "handler.event.onRequest");
|
|
29
|
-
|
|
30
22
|
const createHandlerOnRequest = cb => {
|
|
31
23
|
return new HandlerOnRequestPlugin(cb);
|
|
32
24
|
};
|
|
33
|
-
|
|
34
25
|
exports.createHandlerOnRequest = createHandlerOnRequest;
|
|
@@ -1 +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":"
|
|
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,sBAAsB,SAASC,eAAM,CAAC;EAKxCC,WAAW,CAACC,EAAkC,EAAE;IACnD,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAaC,IAAI,CACbC,OAAuB,EACvBC,KAAmB,EAC4B;IAC/C,OAAO,IAAI,CAACH,EAAE,CAACE,OAAO,EAAEC,KAAK,CAAC;EAClC;AACJ;AAAC;AAAA,8BAhBYN,sBAAsB,UACD,yBAAyB;AAiBpD,MAAMO,sBAAsB,GAAIJ,EAAkC,IAAK;EAC1E,OAAO,IAAIH,sBAAsB,CAACG,EAAE,CAAC;AACzC,CAAC;AAAC"}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createHandlerResultPlugin = exports.HandlerResultPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _plugins = require("@webiny/plugins");
|
|
13
|
-
|
|
14
10
|
class HandlerResultPlugin extends _plugins.Plugin {
|
|
15
11
|
constructor(callable) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "_callable", void 0);
|
|
18
14
|
this._callable = callable;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
async handle(context, result) {
|
|
22
17
|
return this._callable(context, result);
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
exports.HandlerResultPlugin = HandlerResultPlugin;
|
|
28
21
|
(0, _defineProperty2.default)(HandlerResultPlugin, "type", "handler-result");
|
|
29
|
-
|
|
30
22
|
const createHandlerResultPlugin = callable => {
|
|
31
23
|
return new HandlerResultPlugin(callable);
|
|
32
24
|
};
|
|
33
|
-
|
|
34
25
|
exports.createHandlerResultPlugin = createHandlerResultPlugin;
|
|
@@ -1 +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":"
|
|
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,mBAAmB,SAAsCC,eAAM,CAAC;EAKlEC,WAAW,CAACC,QAAkC,EAAE;IACnD,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,MAAM,CAACC,OAAU,EAAEC,MAAW,EAAgB;IACvD,OAAO,IAAI,CAACH,SAAS,CAACE,OAAO,EAAEC,MAAM,CAAC;EAC1C;AACJ;AAAC;AAAA,8BAbYP,mBAAmB,UACmB,gBAAgB;AAc5D,MAAMQ,yBAAyB,GAClCL,QAAkC,IACT;EACzB,OAAO,IAAIH,mBAAmB,CAAIG,QAAQ,CAAC;AAC/C,CAAC;AAAC"}
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createModifyFastifyPlugin = exports.ModifyFastifyPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
10
|
class ModifyFastifyPlugin extends _Plugin.Plugin {
|
|
15
11
|
constructor(cb) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
14
|
this.cb = cb;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
modify(app) {
|
|
22
17
|
this.cb(app);
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
exports.ModifyFastifyPlugin = ModifyFastifyPlugin;
|
|
28
21
|
(0, _defineProperty2.default)(ModifyFastifyPlugin, "type", "handler.fastify.modify");
|
|
29
|
-
|
|
30
22
|
const createModifyFastifyPlugin = cb => {
|
|
31
23
|
return new ModifyFastifyPlugin(cb);
|
|
32
24
|
};
|
|
33
|
-
|
|
34
25
|
exports.createModifyFastifyPlugin = createModifyFastifyPlugin;
|
|
@@ -1 +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":"
|
|
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,mBAAmB,SAASC,cAAM,CAAC;EAKrCC,WAAW,CAACC,EAA+B,EAAE;IAChD,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEOC,MAAM,CAACC,GAAoB,EAAQ;IACtC,IAAI,CAACF,EAAE,CAACE,GAAG,CAAC;EAChB;AACJ;AAAC;AAAA,8BAbYL,mBAAmB,UACE,wBAAwB;AAcnD,MAAMM,yBAAyB,GAAIH,EAA+B,IAAK;EAC1E,OAAO,IAAIH,mBAAmB,CAACG,EAAE,CAAC;AACtC,CAAC;AAAC"}
|
package/plugins/RoutePlugin.js
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createRoute = exports.RoutePlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
10
|
class RoutePlugin extends _Plugin.Plugin {
|
|
15
11
|
constructor(cb) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
14
|
this.cb = cb;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
exports.RoutePlugin = RoutePlugin;
|
|
24
18
|
(0, _defineProperty2.default)(RoutePlugin, "type", "handler.fastify.route");
|
|
25
|
-
|
|
26
19
|
const createRoute = cb => {
|
|
27
20
|
return new RoutePlugin(cb);
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
exports.createRoute = createRoute;
|
|
@@ -1 +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":"
|
|
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,WAAW,SAAsCC,cAAM,CAAC;EAK1DC,WAAW,CAACC,EAAoB,EAAE;IACrC,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BATYH,WAAW,UAC2B,uBAAuB;AAUnE,MAAMI,WAAW,GAAiCD,EAAoB,IAAqB;EAC9F,OAAO,IAAIH,WAAW,CAAIG,EAAE,CAAC;AACjC,CAAC;AAAC"}
|
package/types.js
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +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 * Current reply. Must be set only once!\n */\n reply: FastifyReply;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":"
|
|
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 * Current reply. Must be set only once!\n */\n reply: FastifyReply;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA"}
|