@webiny/handler 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.9bd236cf5e

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 (82) hide show
  1. package/Context.d.ts +4 -5
  2. package/Context.js +6 -12
  3. package/Context.js.map +1 -1
  4. package/PreHandler/IPreHandler.d.ts +9 -0
  5. package/PreHandler/IPreHandler.js +13 -0
  6. package/PreHandler/IPreHandler.js.map +1 -0
  7. package/PreHandler/IfNotOptionsRequest.d.ts +9 -0
  8. package/PreHandler/IfNotOptionsRequest.js +28 -0
  9. package/PreHandler/IfNotOptionsRequest.js.map +1 -0
  10. package/PreHandler/IfOptionsRequest.d.ts +9 -0
  11. package/PreHandler/IfOptionsRequest.js +28 -0
  12. package/PreHandler/IfOptionsRequest.js.map +1 -0
  13. package/PreHandler/PreHandler.d.ts +9 -0
  14. package/PreHandler/PreHandler.js +24 -0
  15. package/PreHandler/PreHandler.js.map +1 -0
  16. package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +10 -0
  17. package/PreHandler/ProcessBeforeHandlerPlugins.js +31 -0
  18. package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -0
  19. package/PreHandler/ProcessContextPlugins.d.ts +10 -0
  20. package/PreHandler/ProcessContextPlugins.js +31 -0
  21. package/PreHandler/ProcessContextPlugins.js.map +1 -0
  22. package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +10 -0
  23. package/PreHandler/ProcessHandlerOnRequestPlugins.js +33 -0
  24. package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -0
  25. package/PreHandler/SendEarlyOptionsResponse.d.ts +9 -0
  26. package/PreHandler/SendEarlyOptionsResponse.js +38 -0
  27. package/PreHandler/SendEarlyOptionsResponse.js.map +1 -0
  28. package/PreHandler/SetDefaultHeaders.d.ts +9 -0
  29. package/PreHandler/SetDefaultHeaders.js +64 -0
  30. package/PreHandler/SetDefaultHeaders.js.map +1 -0
  31. package/ResponseHeaders.d.ts +25 -0
  32. package/ResponseHeaders.js +46 -0
  33. package/ResponseHeaders.js.map +1 -0
  34. package/fastify.d.ts +6 -4
  35. package/fastify.js +159 -185
  36. package/fastify.js.map +1 -1
  37. package/index.d.ts +6 -0
  38. package/index.js +48 -1
  39. package/index.js.map +1 -1
  40. package/package.json +15 -23
  41. package/plugins/BeforeHandlerPlugin.d.ts +1 -1
  42. package/plugins/BeforeHandlerPlugin.js +4 -5
  43. package/plugins/BeforeHandlerPlugin.js.map +1 -1
  44. package/plugins/EventPlugin.d.ts +1 -1
  45. package/plugins/EventPlugin.js +4 -5
  46. package/plugins/EventPlugin.js.map +1 -1
  47. package/plugins/HandlerErrorPlugin.d.ts +6 -3
  48. package/plugins/HandlerErrorPlugin.js +4 -5
  49. package/plugins/HandlerErrorPlugin.js.map +1 -1
  50. package/plugins/HandlerOnRequestPlugin.d.ts +9 -8
  51. package/plugins/HandlerOnRequestPlugin.js +13 -7
  52. package/plugins/HandlerOnRequestPlugin.js.map +1 -1
  53. package/plugins/HandlerResultPlugin.d.ts +1 -1
  54. package/plugins/HandlerResultPlugin.js +4 -5
  55. package/plugins/HandlerResultPlugin.js.map +1 -1
  56. package/plugins/ModifyFastifyPlugin.d.ts +1 -1
  57. package/plugins/ModifyFastifyPlugin.js +4 -5
  58. package/plugins/ModifyFastifyPlugin.js.map +1 -1
  59. package/plugins/ModifyResponseHeadersPlugin.d.ts +14 -0
  60. package/plugins/ModifyResponseHeadersPlugin.js +24 -0
  61. package/plugins/ModifyResponseHeadersPlugin.js.map +1 -0
  62. package/plugins/OnRequestResponseSendPlugin.d.ts +26 -0
  63. package/plugins/OnRequestResponseSendPlugin.js +40 -0
  64. package/plugins/OnRequestResponseSendPlugin.js.map +1 -0
  65. package/plugins/OnRequestTimeoutPlugin.d.ts +12 -0
  66. package/plugins/OnRequestTimeoutPlugin.js +24 -0
  67. package/plugins/OnRequestTimeoutPlugin.js.map +1 -0
  68. package/plugins/RoutePlugin.d.ts +1 -1
  69. package/plugins/RoutePlugin.js +4 -5
  70. package/plugins/RoutePlugin.js.map +1 -1
  71. package/stringifyError.d.ts +5 -0
  72. package/stringifyError.js +27 -0
  73. package/stringifyError.js.map +1 -0
  74. package/suppressPunycodeWarnings.d.ts +4 -0
  75. package/suppressPunycodeWarnings.js +11 -0
  76. package/suppressPunycodeWarnings.js.map +1 -0
  77. package/types.d.ts +10 -13
  78. package/types.js +4 -7
  79. package/types.js.map +1 -1
  80. package/middleware.d.ts +0 -4
  81. package/middleware.js +0 -45
  82. package/middleware.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_plugins","require","OnRequestResponseSendPlugin","Plugin","type","constructor","cb","exec","request","reply","payload","exports","createOnRequestResponseSend"],"sources":["OnRequestResponseSendPlugin.ts"],"sourcesContent":["/**\n * !!!!!!!!!!!!!!\n * !!! DANGER !!!\n * !!!!!!!!!!!!!!\n *\n * Using this plugin can cause slowdowns in your application response times.\n * Also, if you do not return payload from the plugin callback, there will be nothing to send in the response.\n */\nimport { Plugin } from \"@webiny/plugins\";\nimport type { Reply as FastifyReply, Request as FastifyRequest } from \"~/types.js\";\n\nexport interface IOnResponseSendPluginCallable {\n <T = unknown>(request: FastifyRequest, reply: FastifyReply, payload: T): Promise<T>;\n}\n\n/**\n * @description Read info in the class file.\n */\nexport class OnRequestResponseSendPlugin extends Plugin {\n public static override type: string = \"handler.onRequestResponseSend\";\n\n private readonly cb: IOnResponseSendPluginCallable;\n\n public constructor(cb: IOnResponseSendPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public async exec<T = unknown>(\n request: FastifyRequest,\n reply: FastifyReply,\n payload: T\n ): Promise<unknown> {\n return await this.cb<T>(request, reply, payload);\n }\n}\n\n/**\n * @description Read info in the class file.\n */\nexport const createOnRequestResponseSend = (cb: IOnResponseSendPluginCallable) => {\n return new OnRequestResponseSendPlugin(cb);\n};\n"],"mappings":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACO,MAAMC,2BAA2B,SAASC,eAAM,CAAC;EACpD,OAAuBC,IAAI,GAAW,+BAA+B;EAI9DC,WAAWA,CAACC,EAAiC,EAAE;IAClD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAaC,IAAIA,CACbC,OAAuB,EACvBC,KAAmB,EACnBC,OAAU,EACM;IAChB,OAAO,MAAM,IAAI,CAACJ,EAAE,CAAIE,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;EACpD;AACJ;;AAEA;AACA;AACA;AAFAC,OAAA,CAAAT,2BAAA,GAAAA,2BAAA;AAGO,MAAMU,2BAA2B,GAAIN,EAAiC,IAAK;EAC9E,OAAO,IAAIJ,2BAA2B,CAACI,EAAE,CAAC;AAC9C,CAAC;AAACK,OAAA,CAAAC,2BAAA,GAAAA,2BAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import type { Reply as FastifyReply, Request as FastifyRequest } from "../types.js";
3
+ export interface IOnRequestTimeoutPluginCallable {
4
+ (request: FastifyRequest, reply: FastifyReply): Promise<unknown>;
5
+ }
6
+ export declare class OnRequestTimeoutPlugin extends Plugin {
7
+ static type: string;
8
+ private readonly cb;
9
+ constructor(cb: IOnRequestTimeoutPluginCallable);
10
+ exec(request: FastifyRequest, reply: FastifyReply): Promise<unknown>;
11
+ }
12
+ export declare const createOnRequestTimeout: (cb: IOnRequestTimeoutPluginCallable) => OnRequestTimeoutPlugin;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createOnRequestTimeout = exports.OnRequestTimeoutPlugin = void 0;
7
+ var _plugins = require("@webiny/plugins");
8
+ class OnRequestTimeoutPlugin extends _plugins.Plugin {
9
+ static type = "handler.onRequestTimeout";
10
+ constructor(cb) {
11
+ super();
12
+ this.cb = cb;
13
+ }
14
+ async exec(request, reply) {
15
+ return await this.cb(request, reply);
16
+ }
17
+ }
18
+ exports.OnRequestTimeoutPlugin = OnRequestTimeoutPlugin;
19
+ const createOnRequestTimeout = cb => {
20
+ return new OnRequestTimeoutPlugin(cb);
21
+ };
22
+ exports.createOnRequestTimeout = createOnRequestTimeout;
23
+
24
+ //# sourceMappingURL=OnRequestTimeoutPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_plugins","require","OnRequestTimeoutPlugin","Plugin","type","constructor","cb","exec","request","reply","exports","createOnRequestTimeout"],"sources":["OnRequestTimeoutPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Reply as FastifyReply, Request as FastifyRequest } from \"~/types.js\";\n\nexport interface IOnRequestTimeoutPluginCallable {\n (request: FastifyRequest, reply: FastifyReply): Promise<unknown>;\n}\n\nexport class OnRequestTimeoutPlugin extends Plugin {\n public static override type: string = \"handler.onRequestTimeout\";\n\n private readonly cb: IOnRequestTimeoutPluginCallable;\n\n public constructor(cb: IOnRequestTimeoutPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public async exec(request: FastifyRequest, reply: FastifyReply): Promise<unknown> {\n return await this.cb(request, reply);\n }\n}\n\nexport const createOnRequestTimeout = (cb: IOnRequestTimeoutPluginCallable) => {\n return new OnRequestTimeoutPlugin(cb);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAOO,MAAMC,sBAAsB,SAASC,eAAM,CAAC;EAC/C,OAAuBC,IAAI,GAAW,0BAA0B;EAIzDC,WAAWA,CAACC,EAAmC,EAAE;IACpD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAaC,IAAIA,CAACC,OAAuB,EAAEC,KAAmB,EAAoB;IAC9E,OAAO,MAAM,IAAI,CAACH,EAAE,CAACE,OAAO,EAAEC,KAAK,CAAC;EACxC;AACJ;AAACC,OAAA,CAAAR,sBAAA,GAAAA,sBAAA;AAEM,MAAMS,sBAAsB,GAAIL,EAAmC,IAAK;EAC3E,OAAO,IAAIJ,sBAAsB,CAACI,EAAE,CAAC;AACzC,CAAC;AAACI,OAAA,CAAAC,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from "@webiny/plugins/Plugin";
2
- import { Context, RouteMethod } from "../types";
2
+ import type { Context, RouteMethod } from "../types";
3
3
  interface RoutePluginCbParams<T extends Context> {
4
4
  context: T;
5
5
  onGet: RouteMethod;
@@ -1,22 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createRoute = exports.RoutePlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _Plugin = require("@webiny/plugins/Plugin");
10
8
  class RoutePlugin extends _Plugin.Plugin {
9
+ static type = "handler.fastify.route";
11
10
  constructor(cb) {
12
11
  super();
13
- (0, _defineProperty2.default)(this, "cb", void 0);
14
12
  this.cb = cb;
15
13
  }
16
14
  }
17
15
  exports.RoutePlugin = RoutePlugin;
18
- (0, _defineProperty2.default)(RoutePlugin, "type", "handler.fastify.route");
19
16
  const createRoute = cb => {
20
17
  return new RoutePlugin(cb);
21
18
  };
22
- exports.createRoute = createRoute;
19
+ exports.createRoute = createRoute;
20
+
21
+ //# sourceMappingURL=RoutePlugin.js.map
@@ -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":";;;;;;;;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"}
1
+ {"version":3,"names":["_Plugin","require","RoutePlugin","Plugin","type","constructor","cb","exports","createRoute"],"sources":["RoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { 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,IAAAA,OAAA,GAAAC,OAAA;AAkBO,MAAMC,WAAW,SAAsCC,cAAM,CAAC;EACjE,OAAgCC,IAAI,GAAW,uBAAuB;EAI/DC,WAAWA,CAACC,EAAoB,EAAE;IACrC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,WAAA,GAAAA,WAAA;AAEM,MAAMM,WAAW,GAAiCF,EAAoB,IAAqB;EAC9F,OAAO,IAAIJ,WAAW,CAAII,EAAE,CAAC;AACjC,CAAC;AAACC,OAAA,CAAAC,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export interface CustomError extends Error {
2
+ code?: string;
3
+ data?: Record<string, any>;
4
+ }
5
+ export declare const stringifyError: (error: CustomError) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stringifyError = void 0;
7
+ const stringifyError = error => {
8
+ const {
9
+ name,
10
+ message,
11
+ code,
12
+ stack,
13
+ data
14
+ } = error;
15
+ return JSON.stringify({
16
+ ...error,
17
+ constructorName: error.constructor?.name || "UnknownError",
18
+ name: name || "No error name",
19
+ message: message || "No error message",
20
+ code: code || "NO_CODE",
21
+ data,
22
+ stack: process.env.DEBUG === "true" ? stack : "Turn on the debug flag to see the stack."
23
+ });
24
+ };
25
+ exports.stringifyError = stringifyError;
26
+
27
+ //# sourceMappingURL=stringifyError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["stringifyError","error","name","message","code","stack","data","JSON","stringify","constructorName","constructor","process","env","DEBUG","exports"],"sources":["stringifyError.ts"],"sourcesContent":["export interface CustomError extends Error {\n code?: string;\n data?: Record<string, any>;\n}\n\nexport const stringifyError = (error: CustomError) => {\n const { name, message, code, stack, data } = error;\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"],"mappings":";;;;;;AAKO,MAAMA,cAAc,GAAIC,KAAkB,IAAK;EAClD,MAAM;IAAEC,IAAI;IAAEC,OAAO;IAAEC,IAAI;IAAEC,KAAK;IAAEC;EAAK,CAAC,GAAGL,KAAK;EAClD,OAAOM,IAAI,CAACC,SAAS,CAAC;IAClB,GAAGP,KAAK;IACRQ,eAAe,EAAER,KAAK,CAACS,WAAW,EAAER,IAAI,IAAI,cAAc;IAC1DA,IAAI,EAAEA,IAAI,IAAI,eAAe;IAC7BC,OAAO,EAAEA,OAAO,IAAI,kBAAkB;IACtCC,IAAI,EAAEA,IAAI,IAAI,SAAS;IACvBE,IAAI;IACJD,KAAK,EAAEM,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,MAAM,GAAGR,KAAK,GAAG;EAClD,CAAC,CAAC;AACN,CAAC;AAACS,OAAA,CAAAd,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ declare const originalConsoleError: {
2
+ (...data: any[]): void;
3
+ (message?: any, ...optionalParams: any[]): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const originalConsoleError = console.error;
4
+ console.error = (message, ...args) => {
5
+ if (typeof message === "string" && message.includes("punycode")) {
6
+ return;
7
+ }
8
+ originalConsoleError.call(console, message, ...args);
9
+ };
10
+
11
+ //# sourceMappingURL=suppressPunycodeWarnings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["originalConsoleError","console","error","message","args","includes","call"],"sources":["suppressPunycodeWarnings.ts"],"sourcesContent":["const originalConsoleError = console.error;\nconsole.error = (message, ...args) => {\n if (typeof message === \"string\" && message.includes(\"punycode\")) {\n return;\n }\n originalConsoleError.call(console, message, ...args);\n};\n"],"mappings":";;AAAA,MAAMA,oBAAoB,GAAGC,OAAO,CAACC,KAAK;AAC1CD,OAAO,CAACC,KAAK,GAAG,CAACC,OAAO,EAAE,GAAGC,IAAI,KAAK;EAClC,IAAI,OAAOD,OAAO,KAAK,QAAQ,IAAIA,OAAO,CAACE,QAAQ,CAAC,UAAU,CAAC,EAAE;IAC7D;EACJ;EACAL,oBAAoB,CAACM,IAAI,CAACL,OAAO,EAAEE,OAAO,EAAE,GAAGC,IAAI,CAAC;AACxD,CAAC","ignoreList":[]}
package/types.d.ts CHANGED
@@ -1,16 +1,18 @@
1
- import { FastifyInstance, FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
2
- export { FastifyInstance, HTTPMethods } from "fastify";
3
- import { ClientContext } from "@webiny/handler-client/types";
1
+ import "@fastify/cookie";
2
+ import type { FastifyRequest, FastifyReply, HTTPMethods as BaseHttpMethods, RouteHandlerMethod } from "fastify";
3
+ export { FastifyInstance } from "fastify";
4
+ import type { ClientContext } from "@webiny/handler-client/types";
4
5
  export interface RouteMethodOptions {
5
6
  override?: boolean;
6
7
  }
7
- export declare type RouteMethodPath = `/${string}` | "*";
8
+ export type RouteMethodPath = `/${string}` | "*";
8
9
  export interface RouteMethod {
9
10
  (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;
10
11
  }
11
- export declare type Request = FastifyRequest;
12
- export declare type Reply = FastifyReply;
13
- export declare type DefinedContextRoutes = Record<HTTPMethods, string[]>;
12
+ export type Request = FastifyRequest;
13
+ export type Reply = FastifyReply;
14
+ export type HTTPMethods = Uppercase<BaseHttpMethods>;
15
+ export type DefinedContextRoutes = Record<HTTPMethods, string[]>;
14
16
  export interface ContextRoutes {
15
17
  defined: DefinedContextRoutes;
16
18
  onGet: RouteMethod;
@@ -23,12 +25,6 @@ export interface ContextRoutes {
23
25
  onHead: RouteMethod;
24
26
  }
25
27
  export interface Context extends ClientContext {
26
- /**
27
- * An instance of fastify server.
28
- * Use at your own risk.
29
- * @instance
30
- */
31
- server: FastifyInstance;
32
28
  /**
33
29
  * Current request. Must be set only once!
34
30
  */
@@ -45,5 +41,6 @@ export interface Context extends ClientContext {
45
41
  declare module "fastify" {
46
42
  interface FastifyInstance {
47
43
  webiny: Context;
44
+ __webiny_raw_result: any;
48
45
  }
49
46
  }
package/types.js CHANGED
@@ -9,10 +9,7 @@ Object.defineProperty(exports, "FastifyInstance", {
9
9
  return _fastify.FastifyInstance;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "HTTPMethods", {
13
- enumerable: true,
14
- get: function () {
15
- return _fastify.HTTPMethods;
16
- }
17
- });
18
- var _fastify = require("fastify");
12
+ require("@fastify/cookie");
13
+ var _fastify = require("fastify");
14
+
15
+ //# sourceMappingURL=types.js.map
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":";;;;;;;;;;;;;;;;;AAAA"}
1
+ {"version":3,"names":["require","_fastify"],"sources":["types.ts"],"sourcesContent":["import \"@fastify/cookie\";\nimport type {\n FastifyRequest,\n FastifyReply,\n HTTPMethods as BaseHttpMethods,\n RouteHandlerMethod\n} from \"fastify\";\nexport { FastifyInstance } from \"fastify\";\nimport type { 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 HTTPMethods = Uppercase<BaseHttpMethods>;\n\nexport type DefinedContextRoutes = Record<HTTPMethods, string[]>;\n\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 * 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 __webiny_raw_result: any;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAAA,OAAA;AAOA,IAAAC,QAAA,GAAAD,OAAA","ignoreList":[]}
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,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.middleware = void 0;
7
- /**
8
- * Compose a single middleware from the array of middleware functions
9
- */
10
- const middleware = (functions = []) => {
11
- return (...args) => {
12
- if (!functions.length) {
13
- return Promise.resolve();
14
- }
15
-
16
- // Create a clone of function chain to prevent modifying the original array with `shift()`
17
- const chain = [...functions];
18
- return new Promise((parentResolve, parentReject) => {
19
- const next = async () => {
20
- const fn = chain.shift();
21
- if (!fn) {
22
- return Promise.resolve();
23
- }
24
- return new Promise(async (resolve, reject) => {
25
- try {
26
- const result = await fn(...args, resolve);
27
- if (typeof result !== "undefined") {
28
- return parentResolve(result);
29
- }
30
- } catch (e) {
31
- reject(e);
32
- }
33
- }).then(() => {
34
- return next();
35
- }).then(() => {
36
- parentResolve(...args);
37
- }).catch(e => {
38
- parentReject(e);
39
- });
40
- };
41
- return next();
42
- });
43
- };
44
- };
45
- 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,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"}