@webiny/handler 0.0.0-unstable.8c4d9f045a → 0.0.0-unstable.9609e4e0c9

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.
Files changed (49) hide show
  1. package/README.md +10 -14
  2. package/ResponseHeaders.d.ts +24 -0
  3. package/ResponseHeaders.js +36 -0
  4. package/ResponseHeaders.js.map +1 -0
  5. package/abstractions/Reply.d.ts +5 -0
  6. package/abstractions/Reply.js +5 -0
  7. package/abstractions/Reply.js.map +1 -0
  8. package/abstractions/Request.d.ts +5 -0
  9. package/abstractions/Request.js +5 -0
  10. package/abstractions/Request.js.map +1 -0
  11. package/exports/api.d.ts +0 -0
  12. package/exports/api.js +0 -0
  13. package/index.d.ts +6 -8
  14. package/index.js +5 -109
  15. package/package.json +18 -28
  16. package/plugins/RegisterExtensionPlugin.d.ts +36 -0
  17. package/plugins/RegisterExtensionPlugin.js +38 -0
  18. package/plugins/RegisterExtensionPlugin.js.map +1 -0
  19. package/stringifyError.d.ts +5 -0
  20. package/stringifyError.js +15 -0
  21. package/stringifyError.js.map +1 -0
  22. package/types.d.ts +21 -43
  23. package/types.js +0 -19
  24. package/Context.d.ts +0 -13
  25. package/Context.js +0 -29
  26. package/Context.js.map +0 -1
  27. package/fastify.d.ts +0 -8
  28. package/fastify.js +0 -315
  29. package/fastify.js.map +0 -1
  30. package/index.js.map +0 -1
  31. package/middleware.d.ts +0 -4
  32. package/middleware.js +0 -51
  33. package/middleware.js.map +0 -1
  34. package/plugins/BeforeHandlerPlugin.d.ts +0 -12
  35. package/plugins/BeforeHandlerPlugin.js +0 -38
  36. package/plugins/BeforeHandlerPlugin.js.map +0 -1
  37. package/plugins/EventPlugin.d.ts +0 -25
  38. package/plugins/EventPlugin.js +0 -38
  39. package/plugins/EventPlugin.js.map +0 -1
  40. package/plugins/HandlerErrorPlugin.d.ts +0 -12
  41. package/plugins/HandlerErrorPlugin.js +0 -34
  42. package/plugins/HandlerErrorPlugin.js.map +0 -1
  43. package/plugins/HandlerResultPlugin.d.ts +0 -12
  44. package/plugins/HandlerResultPlugin.js +0 -34
  45. package/plugins/HandlerResultPlugin.js.map +0 -1
  46. package/plugins/RoutePlugin.d.ts +0 -23
  47. package/plugins/RoutePlugin.js +0 -30
  48. package/plugins/RoutePlugin.js.map +0 -1
  49. package/types.js.map +0 -1
package/fastify.js DELETED
@@ -1,315 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _fastify = _interopRequireDefault(require("fastify"));
13
-
14
- var _utils = require("@webiny/utils");
15
-
16
- var _Context = require("./Context");
17
-
18
- var _error = _interopRequireDefault(require("@webiny/error"));
19
-
20
- var _RoutePlugin = require("./plugins/RoutePlugin");
21
-
22
- var _handlerClient = require("@webiny/handler-client");
23
-
24
- var _cookie = _interopRequireDefault(require("@fastify/cookie"));
25
-
26
- var _middleware = require("./middleware");
27
-
28
- var _api = require("@webiny/api");
29
-
30
- var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
31
-
32
- var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
33
-
34
- var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
35
-
36
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
37
-
38
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
39
-
40
- const DEFAULT_HEADERS = _objectSpread({
41
- "Cache-Control": "no-store",
42
- "Content-Type": "application/json; charset=utf-8",
43
- "Access-Control-Allow-Origin": "*",
44
- "Access-Control-Allow-Headers": "*",
45
- "Access-Control-Allow-Methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH"
46
- }, (0, _utils.getWebinyVersionHeaders)());
47
-
48
- const getDefaultHeaders = routes => {
49
- /**
50
- * If we are accepting all headers, just output that one.
51
- */
52
- const keys = Object.keys(routes);
53
- const all = keys.every(key => routes[key].length > 0);
54
-
55
- if (all) {
56
- return _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
57
- "Access-Control-Allow-Methods": "*"
58
- });
59
- }
60
-
61
- return _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
62
- "Access-Control-Allow-Methods": keys.filter(key => {
63
- const type = key;
64
-
65
- if (!routes[type] || Array.isArray(routes[type]) === false) {
66
- return false;
67
- }
68
-
69
- return routes[type].length > 0;
70
- }).sort().join(",")
71
- });
72
- };
73
-
74
- const OPTIONS_HEADERS = {
75
- "Access-Control-Max-Age": "86400",
76
- "Cache-Control": "public, max-age=86400"
77
- };
78
-
79
- const createHandler = params => {
80
- const definedRoutes = {
81
- POST: [],
82
- GET: [],
83
- OPTIONS: [],
84
- DELETE: [],
85
- PATCH: [],
86
- PUT: [],
87
- HEAD: []
88
- };
89
-
90
- const throwOnDefinedRoute = (type, path, options) => {
91
- if (type === "ALL") {
92
- const all = Object.keys(definedRoutes).some(key => {
93
- const routes = definedRoutes[key];
94
- return routes.includes(path);
95
- });
96
-
97
- if (!all) {
98
- return;
99
- }
100
-
101
- throw new _error.default(`You cannot override a route with onAll() method, please remove unnecessary route from the system.`, "OVERRIDE_ROUTE_ERROR", {
102
- type,
103
- path
104
- });
105
- } else if (definedRoutes[type].includes(path) === false) {
106
- return;
107
- } else if ((options === null || options === void 0 ? void 0 : options.override) === true) {
108
- return;
109
- }
110
-
111
- throw new _error.default(`When you are trying to override existing route, you must send "override" parameter when adding that route.`, "OVERRIDE_ROUTE_ERROR", {
112
- type,
113
- path
114
- });
115
- };
116
-
117
- const addDefinedRoute = (inputType, path) => {
118
- const type = inputType.toUpperCase();
119
-
120
- if (!definedRoutes[type]) {
121
- return;
122
- } else if (definedRoutes[type].includes(path)) {
123
- return;
124
- }
125
-
126
- definedRoutes[type].push(path);
127
- };
128
- /**
129
- * We must attach the server to our internal context if we want to have it accessible.
130
- */
131
-
132
-
133
- const app = (0, _fastify.default)(_objectSpread({}, params.options || {}));
134
- /**
135
- * We need to register routes in our system so we can output headers later on and dissallow overriding routes.
136
- */
137
-
138
- app.addHook("onRoute", route => {
139
- const method = route.method;
140
-
141
- if (Array.isArray(method)) {
142
- for (const m of method) {
143
- addDefinedRoute(m, route.path);
144
- }
145
-
146
- return;
147
- }
148
-
149
- addDefinedRoute(method, route.path);
150
- });
151
- /**
152
- *
153
- */
154
-
155
- app.register(_cookie.default, {
156
- parseOptions: {} // options for parsing cookies
157
-
158
- });
159
- /**
160
- * Route helpers - mostly for users.
161
- */
162
-
163
- const routes = {
164
- defined: definedRoutes,
165
- onPost: (path, handler, options) => {
166
- throwOnDefinedRoute("POST", path, options);
167
- app.post(path, handler);
168
- },
169
- onGet: (path, handler, options) => {
170
- throwOnDefinedRoute("GET", path, options);
171
- app.get(path, handler);
172
- },
173
- onOptions: (path, handler, options) => {
174
- throwOnDefinedRoute("OPTIONS", path, options);
175
- app.options(path, handler);
176
- },
177
- onDelete: (path, handler, options) => {
178
- throwOnDefinedRoute("DELETE", path, options);
179
- app.delete(path, handler);
180
- },
181
- onPatch: (path, handler, options) => {
182
- throwOnDefinedRoute("PATCH", path, options);
183
- app.patch(path, handler);
184
- },
185
- onPut: (path, handler, options) => {
186
- throwOnDefinedRoute("PUT", path, options);
187
- app.put(path, handler);
188
- },
189
- onAll: (path, handler, options) => {
190
- throwOnDefinedRoute("ALL", path, options);
191
- app.all(path, handler);
192
- },
193
- onHead: (path, handler, options) => {
194
- throwOnDefinedRoute("HEAD", path, options);
195
- app.head(path, handler);
196
- }
197
- };
198
- const context = new _Context.Context({
199
- plugins: [
200
- /**
201
- * We must have handlerClient by default.
202
- * And it must be one of the first context plugins applied.
203
- */
204
- (0, _handlerClient.createHandlerClient)(), ...(params.plugins || [])],
205
-
206
- /**
207
- * Inserted via webpack on build time.
208
- */
209
- WEBINY_VERSION: process.env.WEBINY_VERSION,
210
- server: app,
211
- routes
212
- });
213
- /**
214
- * We are attaching our custom context to webiny variable on the fastify app so it is accessible everywhere
215
- */
216
-
217
- app.decorate("webiny", context);
218
- /**
219
- * We have few types of triggers:
220
- * * Events - EventPlugin
221
- * * Routes - RoutePlugin
222
- *
223
- * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.
224
- */
225
-
226
- const routePlugins = app.webiny.plugins.byType(_RoutePlugin.RoutePlugin.type);
227
- /**
228
- * Add routes to the system.
229
- */
230
-
231
- for (const plugin of routePlugins) {
232
- plugin.cb(_objectSpread(_objectSpread({}, app.webiny.routes), {}, {
233
- context: app.webiny
234
- }));
235
- }
236
- /**
237
- * On every request we add default headers, which can be changed later.
238
- * Also, if it is an options request, we skip everything after this hook and output options headers.
239
- */
240
-
241
-
242
- app.addHook("onRequest", async (request, reply) => {
243
- const defaultHeaders = getDefaultHeaders(definedRoutes);
244
- reply.headers(defaultHeaders);
245
-
246
- if (request.method !== "OPTIONS") {
247
- return;
248
- }
249
-
250
- const raw = reply.code(204).hijack().raw;
251
-
252
- const headers = _objectSpread(_objectSpread({}, defaultHeaders), OPTIONS_HEADERS);
253
-
254
- for (const key in headers) {
255
- raw.setHeader(key, headers[key]);
256
- }
257
-
258
- raw.end("");
259
- });
260
- app.addHook("preParsing", async request => {
261
- app.webiny.request = request;
262
- const plugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
263
-
264
- for (const plugin of plugins) {
265
- await plugin.apply(app.webiny);
266
- }
267
- });
268
- /**
269
- *
270
- */
271
-
272
- app.addHook("preHandler", async () => {
273
- const plugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
274
-
275
- for (const plugin of plugins) {
276
- await plugin.apply(app.webiny);
277
- }
278
- });
279
- /**
280
- *
281
- */
282
-
283
- const preSerialization = async (_, __, payload) => {
284
- const plugins = app.webiny.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
285
-
286
- for (const plugin of plugins) {
287
- await plugin.handle(app.webiny, payload);
288
- }
289
-
290
- return payload;
291
- };
292
-
293
- app.addHook("preSerialization", preSerialization);
294
- app.addHook("onError", async (_, reply, error) => {
295
- const plugins = app.webiny.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type); // Log error to cloud, as these can be extremely annoying to debug!
296
-
297
- console.log("@webiny/handler");
298
- console.log(JSON.stringify(_objectSpread(_objectSpread({}, error || {}), {}, {
299
- message: error === null || error === void 0 ? void 0 : error.message,
300
- code: error === null || error === void 0 ? void 0 : error.code
301
- })));
302
- const handler = (0, _middleware.middleware)(plugins.map(pl => {
303
- return (context, error, next) => {
304
- return pl.handle(context, error, next);
305
- };
306
- }));
307
- await handler(app.webiny, error);
308
- return reply.headers({
309
- "Cache-Control": "no-store"
310
- }).status(500);
311
- });
312
- return app;
313
- };
314
-
315
- exports.createHandler = createHandler;
package/fastify.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","getDefaultHeaders","routes","keys","Object","all","every","key","length","filter","type","Array","isArray","sort","join","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","throwOnDefinedRoute","path","options","some","includes","WebinyError","override","addDefinedRoute","inputType","toUpperCase","push","app","fastify","addHook","route","method","m","register","fastifyCookies","parseOptions","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","process","env","server","decorate","routePlugins","webiny","byType","RoutePlugin","plugin","cb","request","reply","defaultHeaders","headers","raw","code","hijack","setHeader","end","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","_","__","payload","HandlerResultPlugin","handle","error","HandlerErrorPlugin","console","log","JSON","stringify","message","middleware","map","pl","next","status"],"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, RouteTypes } from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookies from \"@fastify/cookie\";\nimport { middleware } from \"~/middleware\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\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);\n const all = keys.every(key => routes[key as RouteTypes].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(key => {\n const type = key as unknown as RouteTypes;\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 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: ContextRoutes[\"defined\"] = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: []\n };\n\n const throwOnDefinedRoute = (\n type: RouteTypes | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).some(key => {\n const routes = definedRoutes[key as RouteTypes];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\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 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 = (inputType: RouteTypes, path: string): void => {\n const type = (inputType as string).toUpperCase() as RouteTypes;\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 */\n app.register(fastifyCookies, {\n parseOptions: {} // options for parsing cookies\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 const 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 /**\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 for (const plugin of routePlugins) {\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\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 const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n if (request.method !== \"OPTIONS\") {\n return;\n }\n const raw = reply.code(204).hijack().raw;\n const headers = { ...defaultHeaders, ...OPTIONS_HEADERS };\n for (const key in headers) {\n raw.setHeader(key, headers[key]);\n }\n\n raw.end(\"\");\n });\n\n app.addHook(\"preParsing\", async request => {\n app.webiny.request = request;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n for (const plugin of plugins) {\n await plugin.handle(app.webiny, payload);\n }\n return payload;\n };\n\n app.addHook(\"preSerialization\", preSerialization);\n\n app.addHook(\"onError\", async (_, reply, error) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n // Log error to cloud, as these can be extremely annoying to debug!\n console.log(\"@webiny/handler\");\n console.log(\n JSON.stringify({\n ...(error || {}),\n message: error?.message,\n code: error?.code\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 .headers({\n \"Cache-Control\": \"no-store\"\n })\n .status(500);\n });\n\n return app;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,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AD,OAAO,CAACC,GAAR,CACIC,IAAI,CAACC,SAAL,iCACQL,KAAK,IAAI,EADjB;MAEIM,OAAO,EAAEN,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAEM,OAFpB;MAGInB,IAAI,EAAEa,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAEb;IAHjB,GADJ;IAOA,MAAMlC,OAAO,GAAG,IAAAsD,sBAAA,EACZtC,OAAO,CAACuC,GAAR,CAAYC,EAAE,IAAI;MACd,OAAO,CAAC1C,OAAD,EAAmBiC,KAAnB,EAAiCU,IAAjC,KAAoD;QACvD,OAAOD,EAAE,CAACV,MAAH,CAAUhC,OAAV,EAAmBiC,KAAnB,EAA0BU,IAA1B,CAAP;MACH,CAFD;IAGH,CAJD,CADY,CAAhB;IAOA,MAAMzD,OAAO,CAACX,GAAG,CAACmC,MAAL,EAAauB,KAAb,CAAb;IAEA,OAAOjB,KAAK,CACPE,OADE,CACM;MACL,iBAAiB;IADZ,CADN,EAIF0B,MAJE,CAIK,GAJL,CAAP;EAKH,CAzBD;EA2BA,OAAOrE,GAAP;AACH,CA5OM"}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/fastify\";\nexport * from \"@webiny/api/plugins/ContextPlugin\";\nexport * from \"~/Context\";\nexport * from \"~/plugins/EventPlugin\";\nexport * from \"~/plugins/RoutePlugin\";\nexport * from \"~/plugins/BeforeHandlerPlugin\";\nexport * from \"~/plugins/HandlerErrorPlugin\";\nexport * from \"~/plugins/HandlerResultPlugin\";\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"}
package/middleware.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Compose a single middleware from the array of middleware functions
3
- */
4
- export declare const middleware: (functions?: Function[]) => Function;
package/middleware.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.middleware = void 0;
7
-
8
- /**
9
- * Compose a single middleware from the array of middleware functions
10
- */
11
- const middleware = (functions = []) => {
12
- return (...args) => {
13
- if (!functions.length) {
14
- return Promise.resolve();
15
- } // Create a clone of function chain to prevent modifying the original array with `shift()`
16
-
17
-
18
- const chain = [...functions];
19
- return new Promise((parentResolve, parentReject) => {
20
- const next = async () => {
21
- const fn = chain.shift();
22
-
23
- if (!fn) {
24
- return Promise.resolve();
25
- }
26
-
27
- return new Promise(async (resolve, reject) => {
28
- try {
29
- const result = await fn(...args, resolve);
30
-
31
- if (typeof result !== "undefined") {
32
- return parentResolve(result);
33
- }
34
- } catch (e) {
35
- reject(e);
36
- }
37
- }).then(() => {
38
- return next();
39
- }).then(() => {
40
- parentResolve(...args);
41
- }).catch(e => {
42
- parentReject(e);
43
- });
44
- };
45
-
46
- return next();
47
- });
48
- };
49
- };
50
-
51
- exports.middleware = middleware;
package/middleware.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["middleware","functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"sources":["middleware.ts"],"sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport const middleware = (functions: Function[] = []): Function => {\n return (...args: string[]): Promise<any> => {\n if (!functions.length) {\n return Promise.resolve();\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n const chain = [...functions];\n return new Promise((parentResolve: any, parentReject) => {\n const next = async (): Promise<any> => {\n const fn = chain.shift();\n if (!fn) {\n return Promise.resolve();\n }\n\n return new Promise(async (resolve, reject) => {\n try {\n const result = await fn(...args, resolve);\n if (typeof result !== \"undefined\") {\n return parentResolve(result);\n }\n } catch (e) {\n reject(e);\n }\n })\n .then(() => {\n return next();\n })\n .then(() => {\n parentResolve(...args);\n })\n .catch(e => {\n parentReject(e);\n });\n };\n\n return next();\n });\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,CAACC,SAAqB,GAAG,EAAzB,KAA0C;EAChE,OAAO,CAAC,GAAGC,IAAJ,KAAqC;IACxC,IAAI,CAACD,SAAS,CAACE,MAAf,EAAuB;MACnB,OAAOC,OAAO,CAACC,OAAR,EAAP;IACH,CAHuC,CAKxC;;;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAJ,CAAd;IACA,OAAO,IAAIG,OAAJ,CAAY,CAACG,aAAD,EAAqBC,YAArB,KAAsC;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAN,EAAX;;QACA,IAAI,CAACD,EAAL,EAAS;UACL,OAAON,OAAO,CAACC,OAAR,EAAP;QACH;;QAED,OAAO,IAAID,OAAJ,CAAY,OAAOC,OAAP,EAAgBO,MAAhB,KAA2B;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAJ,EAAUG,OAAV,CAAvB;;YACA,IAAI,OAAOQ,MAAP,KAAkB,WAAtB,EAAmC;cAC/B,OAAON,aAAa,CAACM,MAAD,CAApB;YACH;UACJ,CALD,CAKE,OAAOC,CAAP,EAAU;YACRF,MAAM,CAACE,CAAD,CAAN;UACH;QACJ,CATM,EAUFC,IAVE,CAUG,MAAM;UACR,OAAON,IAAI,EAAX;QACH,CAZE,EAaFM,IAbE,CAaG,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAJ,CAAb;QACH,CAfE,EAgBFc,KAhBE,CAgBIF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAD,CAAZ;QACH,CAlBE,CAAP;MAmBH,CAzBD;;MA2BA,OAAOL,IAAI,EAAX;IACH,CA7BM,CAAP;EA8BH,CArCD;AAsCH,CAvCM"}
@@ -1,12 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import { Context } from "../types";
3
- export interface BeforeHandlerCallable<T extends Context = Context> {
4
- (context: T): void | Promise<void>;
5
- }
6
- export declare class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {
7
- static readonly type: string;
8
- private readonly _callable;
9
- constructor(callable: BeforeHandlerCallable<T>);
10
- apply(context: T): Promise<void>;
11
- }
12
- export declare const createBeforeHandlerPlugin: <T extends Context = Context>(callable: BeforeHandlerCallable<T>) => BeforeHandlerPlugin<T>;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createBeforeHandlerPlugin = exports.BeforeHandlerPlugin = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _plugins = require("@webiny/plugins");
13
-
14
- class BeforeHandlerPlugin extends _plugins.Plugin {
15
- constructor(callable) {
16
- super();
17
- (0, _defineProperty2.default)(this, "_callable", void 0);
18
- this._callable = callable;
19
- }
20
-
21
- async apply(context) {
22
- if (typeof this._callable !== "function") {
23
- throw Error(`Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
24
- }
25
-
26
- return this._callable(context);
27
- }
28
-
29
- }
30
-
31
- exports.BeforeHandlerPlugin = BeforeHandlerPlugin;
32
- (0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
33
-
34
- const createBeforeHandlerPlugin = callable => {
35
- return new BeforeHandlerPlugin(callable);
36
- };
37
-
38
- exports.createBeforeHandlerPlugin = createBeforeHandlerPlugin;
@@ -1 +0,0 @@
1
- {"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createBeforeHandlerPlugin"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\nexport const createBeforeHandlerPlugin = <T extends Context = Context>(\n callable: BeforeHandlerCallable<T>\n): BeforeHandlerPlugin<T> => {\n return new BeforeHandlerPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAIzEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,6IADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB;;AAmB5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
@@ -1,25 +0,0 @@
1
- /**
2
- * EventPlugin must be handled in the package which implements fastify for certain cloud.
3
- * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
4
- * to be sorted out in the implementation package.
5
- *
6
- * Note that only one EventPlugin can be defined per fastify initialisation.
7
- * If more is needed, check ~/fastify.ts and implement that possibility.
8
- */
9
- import { Plugin } from "@webiny/plugins/Plugin";
10
- import { Request, Context as BaseContext, Reply } from "../types";
11
- export interface EventPluginCallableParams<Payload, Context extends BaseContext> {
12
- context: Context;
13
- payload: Payload;
14
- request: Request;
15
- reply: Reply;
16
- }
17
- export interface EventPluginCallable<Payload, Context extends BaseContext, Response> {
18
- (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;
19
- }
20
- export declare class EventPlugin<Payload = any, Context extends BaseContext = BaseContext, Response = any> extends Plugin {
21
- static type: string;
22
- readonly cb: EventPluginCallable<Payload, Context, Response>;
23
- constructor(cb: EventPluginCallable<Payload, Context, Response>);
24
- }
25
- export declare const createEvent: <Payload = any, Context extends BaseContext = BaseContext, Response_1 = any>(cb: EventPluginCallable<Payload, Context, Response_1>) => EventPlugin<Payload, Context, Response_1>;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createEvent = exports.EventPlugin = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
- /**
15
- * EventPlugin must be handled in the package which implements fastify for certain cloud.
16
- * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
17
- * to be sorted out in the implementation package.
18
- *
19
- * Note that only one EventPlugin can be defined per fastify initialisation.
20
- * If more is needed, check ~/fastify.ts and implement that possibility.
21
- */
22
- class EventPlugin extends _Plugin.Plugin {
23
- constructor(cb) {
24
- super();
25
- (0, _defineProperty2.default)(this, "cb", void 0);
26
- this.cb = cb;
27
- }
28
-
29
- }
30
-
31
- exports.EventPlugin = EventPlugin;
32
- (0, _defineProperty2.default)(EventPlugin, "type", "handler.fastify.event");
33
-
34
- const createEvent = cb => {
35
- return new EventPlugin(cb);
36
- };
37
-
38
- exports.createEvent = createEvent;
@@ -1 +0,0 @@
1
- {"version":3,"names":["EventPlugin","Plugin","constructor","cb","createEvent"],"sources":["EventPlugin.ts"],"sourcesContent":["/**\n * EventPlugin must be handled in the package which implements fastify for certain cloud.\n * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that\n * to be sorted out in the implementation package.\n *\n * Note that only one EventPlugin can be defined per fastify initialisation.\n * If more is needed, check ~/fastify.ts and implement that possibility.\n */\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Context as BaseContext, Reply } from \"~/types\";\n\nexport interface EventPluginCallableParams<Payload, Context extends BaseContext> {\n context: Context;\n payload: Payload;\n request: Request;\n reply: Reply;\n}\n\nexport interface EventPluginCallable<Payload, Context extends BaseContext, Response> {\n (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;\n}\n\nexport class EventPlugin<\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.event\";\n\n public readonly cb: EventPluginCallable<Payload, Context, Response>;\n\n public constructor(cb: EventPluginCallable<Payload, Context, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEvent = <\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: EventPluginCallable<Payload, Context, Response>\n) => {\n return new EventPlugin<Payload, Context, Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeO,MAAMA,WAAN,SAIGC,cAJH,CAIU;EAKNC,WAAW,CAACC,EAAD,EAAsD;IACpE;IADoE;IAEpE,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARY;;;8BAJJH,W,UAKqB,uB;;AAU3B,MAAMI,WAAW,GAKpBD,EALuB,IAMtB;EACD,OAAO,IAAIH,WAAJ,CAA4CG,EAA5C,CAAP;AACH,CARM"}
@@ -1,12 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import { Context } from "../types";
3
- export interface HandlerErrorCallable<T extends Context = Context> {
4
- (context: T, error: Error, next: Function): Promise<any>;
5
- }
6
- export declare class HandlerErrorPlugin<T extends Context = Context> extends Plugin {
7
- static readonly type: string;
8
- private readonly _callable;
9
- constructor(callable: HandlerErrorCallable<T>);
10
- handle(context: T, error: Error, next: Function): Promise<any>;
11
- }
12
- export declare const createHandlerErrorPlugin: <T extends Context = Context>(callable: HandlerErrorCallable<T>) => HandlerErrorPlugin<T>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createHandlerErrorPlugin = exports.HandlerErrorPlugin = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _plugins = require("@webiny/plugins");
13
-
14
- class HandlerErrorPlugin extends _plugins.Plugin {
15
- constructor(callable) {
16
- super();
17
- (0, _defineProperty2.default)(this, "_callable", void 0);
18
- this._callable = callable;
19
- }
20
-
21
- async handle(context, error, next) {
22
- return this._callable(context, error, next);
23
- }
24
-
25
- }
26
-
27
- exports.HandlerErrorPlugin = HandlerErrorPlugin;
28
- (0, _defineProperty2.default)(HandlerErrorPlugin, "type", "handler-error");
29
-
30
- const createHandlerErrorPlugin = callable => {
31
- return new HandlerErrorPlugin(callable);
32
- };
33
-
34
- exports.createHandlerErrorPlugin = createHandlerErrorPlugin;
@@ -1 +0,0 @@
1
- {"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next","createHandlerErrorPlugin"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n\nexport const createHandlerErrorPlugin = <T extends Context = Context>(\n callable: HandlerErrorCallable<T>\n): HandlerErrorPlugin<T> => {\n return new HandlerErrorPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;EAKjEC,WAAW,CAACC,QAAD,EAAoC;IAClD;IADkD;IAElD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;IACxE,OAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;EACH;;AAZuE;;;8BAA/DR,kB,UACsC,e;;AAc5C,MAAMS,wBAAwB,GACjCN,QADoC,IAEZ;EACxB,OAAO,IAAIH,kBAAJ,CAA0BG,QAA1B,CAAP;AACH,CAJM"}
@@ -1,12 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import { Context } from "../types";
3
- export interface HandlerResultCallable<T extends Context = Context> {
4
- (context: T, result: any): Promise<any>;
5
- }
6
- export declare class HandlerResultPlugin<T extends Context = Context> extends Plugin {
7
- static readonly type: string;
8
- private readonly _callable;
9
- constructor(callable: HandlerResultCallable<T>);
10
- handle(context: T, result: any): Promise<any>;
11
- }
12
- export declare const createHandlerResultPlugin: <T extends Context = Context>(callable: HandlerResultCallable<T>) => HandlerResultPlugin<T>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createHandlerResultPlugin = exports.HandlerResultPlugin = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _plugins = require("@webiny/plugins");
13
-
14
- class HandlerResultPlugin extends _plugins.Plugin {
15
- constructor(callable) {
16
- super();
17
- (0, _defineProperty2.default)(this, "_callable", void 0);
18
- this._callable = callable;
19
- }
20
-
21
- async handle(context, result) {
22
- return this._callable(context, result);
23
- }
24
-
25
- }
26
-
27
- exports.HandlerResultPlugin = HandlerResultPlugin;
28
- (0, _defineProperty2.default)(HandlerResultPlugin, "type", "handler-result");
29
-
30
- const createHandlerResultPlugin = callable => {
31
- return new HandlerResultPlugin(callable);
32
- };
33
-
34
- exports.createHandlerResultPlugin = createHandlerResultPlugin;