@webiny/handler 6.3.0-beta.4 → 6.4.0-beta.0

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 (65) hide show
  1. package/Context.js +10 -23
  2. package/Context.js.map +1 -1
  3. package/PreHandler/IPreHandler.js +5 -4
  4. package/PreHandler/IPreHandler.js.map +1 -1
  5. package/PreHandler/IfNotOptionsRequest.js +12 -15
  6. package/PreHandler/IfNotOptionsRequest.js.map +1 -1
  7. package/PreHandler/IfOptionsRequest.js +12 -15
  8. package/PreHandler/IfOptionsRequest.js.map +1 -1
  9. package/PreHandler/PreHandler.js +11 -12
  10. package/PreHandler/PreHandler.js.map +1 -1
  11. package/PreHandler/ProcessBeforeHandlerPlugins.js +19 -18
  12. package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -1
  13. package/PreHandler/ProcessContextPlugins.js +19 -18
  14. package/PreHandler/ProcessContextPlugins.js.map +1 -1
  15. package/PreHandler/ProcessHandlerOnRequestPlugins.js +18 -19
  16. package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -1
  17. package/PreHandler/RegisterExtensions.js +8 -9
  18. package/PreHandler/RegisterExtensions.js.map +1 -1
  19. package/PreHandler/SendEarlyOptionsResponse.js +20 -25
  20. package/PreHandler/SendEarlyOptionsResponse.js.map +1 -1
  21. package/PreHandler/SetDefaultHeaders.js +37 -48
  22. package/PreHandler/SetDefaultHeaders.js.map +1 -1
  23. package/ResponseHeaders.js +29 -32
  24. package/ResponseHeaders.js.map +1 -1
  25. package/abstractions/Reply.js +2 -1
  26. package/abstractions/Reply.js.map +1 -1
  27. package/abstractions/Request.js +2 -1
  28. package/abstractions/Request.js.map +1 -1
  29. package/abstractions/Route.js +25 -24
  30. package/abstractions/Route.js.map +1 -1
  31. package/exports/api.js +0 -2
  32. package/fastify.js +277 -398
  33. package/fastify.js.map +1 -1
  34. package/index.js +2 -5
  35. package/package.json +9 -9
  36. package/plugins/BeforeHandlerPlugin.js +13 -14
  37. package/plugins/BeforeHandlerPlugin.js.map +1 -1
  38. package/plugins/EventPlugin.js +10 -17
  39. package/plugins/EventPlugin.js.map +1 -1
  40. package/plugins/HandlerErrorPlugin.js +13 -12
  41. package/plugins/HandlerErrorPlugin.js.map +1 -1
  42. package/plugins/HandlerOnRequestPlugin.js +13 -20
  43. package/plugins/HandlerOnRequestPlugin.js.map +1 -1
  44. package/plugins/HandlerResultPlugin.js +13 -12
  45. package/plugins/HandlerResultPlugin.js.map +1 -1
  46. package/plugins/ModifyFastifyPlugin.js +13 -12
  47. package/plugins/ModifyFastifyPlugin.js.map +1 -1
  48. package/plugins/ModifyResponseHeadersPlugin.js +14 -11
  49. package/plugins/ModifyResponseHeadersPlugin.js.map +1 -1
  50. package/plugins/OnRequestResponseSendPlugin.js +13 -27
  51. package/plugins/OnRequestResponseSendPlugin.js.map +1 -1
  52. package/plugins/OnRequestTimeoutPlugin.js +13 -12
  53. package/plugins/OnRequestTimeoutPlugin.js.map +1 -1
  54. package/plugins/RegisterExtensionPlugin.js +12 -12
  55. package/plugins/RegisterExtensionPlugin.js.map +1 -1
  56. package/plugins/RoutePlugin.js +10 -9
  57. package/plugins/RoutePlugin.js.map +1 -1
  58. package/stringifyError.js +12 -17
  59. package/stringifyError.js.map +1 -1
  60. package/suppressPunycodeWarnings.js +3 -6
  61. package/suppressPunycodeWarnings.js.map +1 -1
  62. package/types.js +0 -2
  63. package/exports/api.js.map +0 -1
  64. package/index.js.map +0 -1
  65. package/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["getWebinyVersionHeaders","ResponseHeaders","Action","createDefaultHeaders","create","getDefaultOptionsHeaders","getDefaultHeaders","routes","headers","keys","Object","all","every","key","length","set","allowedMethods","filter","type","Array","isArray","sort","join","SetDefaultHeaders","constructor","definedRoutes","execute","request","reply","isOptionsRequest","method","defaultHeaders","initialHeaders","merge","getHeaders","CONTINUE"],"sources":["SetDefaultHeaders.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport type { DefinedContextRoutes, HTTPMethods } from \"~/types.js\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\n\nfunction createDefaultHeaders() {\n return ResponseHeaders.create({\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store\",\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}\n\nconst getDefaultOptionsHeaders = () => {\n return ResponseHeaders.create({\n \"access-control-max-age\": \"86400\",\n \"cache-control\": \"public, max-age=86400\"\n });\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): ResponseHeaders => {\n const headers = createDefaultHeaders();\n\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 headers.set(\"access-control-allow-methods\", \"*\");\n } else {\n const allowedMethods = keys\n .filter(type => {\n if (!routes[type] || !Array.isArray(routes[type])) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\");\n\n headers.set(\"access-control-allow-methods\", allowedMethods);\n }\n\n return headers;\n};\n\nexport class SetDefaultHeaders implements IPreHandler {\n private readonly definedRoutes: DefinedContextRoutes;\n\n constructor(definedRoutes: DefinedContextRoutes) {\n this.definedRoutes = definedRoutes;\n }\n\n execute(request: FastifyRequest, reply: FastifyReply) {\n const isOptionsRequest = request.method === \"OPTIONS\";\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(this.definedRoutes);\n\n const initialHeaders = isOptionsRequest\n ? defaultHeaders.merge(getDefaultOptionsHeaders())\n : defaultHeaders;\n\n reply.headers(initialHeaders.getHeaders());\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AACA,SAASA,uBAAuB,QAAQ,eAAe;AACvD,SAASC,eAAe;AAGxB,SAASC,MAAM;AAEf,SAASC,oBAAoBA,CAAA,EAAG;EAC5B,OAAOF,eAAe,CAACG,MAAM,CAAC;IAC1B,cAAc,EAAE,iCAAiC;IACjD,eAAe,EAAE,UAAU;IAC3B,6BAA6B,EAAE,GAAG;IAClC,8BAA8B,EAAE,GAAG;IACnC,8BAA8B,EAAE,mCAAmC;IACnE,GAAGJ,uBAAuB,CAAC;EAC/B,CAAC,CAAC;AACN;AAEA,MAAMK,wBAAwB,GAAGA,CAAA,KAAM;EACnC,OAAOJ,eAAe,CAACG,MAAM,CAAC;IAC1B,wBAAwB,EAAE,OAAO;IACjC,eAAe,EAAE;EACrB,CAAC,CAAC;AACN,CAAC;AAED,MAAME,iBAAiB,GAAIC,MAA4B,IAAsB;EACzE,MAAMC,OAAO,GAAGL,oBAAoB,CAAC,CAAC;;EAEtC;AACJ;AACA;EACI,MAAMM,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,MAAM,CAAkB;EACjD,MAAMI,GAAG,GAAGF,IAAI,CAACG,KAAK,CAACC,GAAG,IAAIN,MAAM,CAACM,GAAG,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;EACrD,IAAIH,GAAG,EAAE;IACLH,OAAO,CAACO,GAAG,CAAC,8BAA8B,EAAE,GAAG,CAAC;EACpD,CAAC,MAAM;IACH,MAAMC,cAAc,GAAGP,IAAI,CACtBQ,MAAM,CAACC,IAAI,IAAI;MACZ,IAAI,CAACX,MAAM,CAACW,IAAI,CAAC,IAAI,CAACC,KAAK,CAACC,OAAO,CAACb,MAAM,CAACW,IAAI,CAAC,CAAC,EAAE;QAC/C,OAAO,KAAK;MAChB;MACA,OAAOX,MAAM,CAACW,IAAI,CAAC,CAACJ,MAAM,GAAG,CAAC;IAClC,CAAC,CAAC,CACDO,IAAI,CAAC,CAAC,CACNC,IAAI,CAAC,GAAG,CAAC;IAEdd,OAAO,CAACO,GAAG,CAAC,8BAA8B,EAAEC,cAAc,CAAC;EAC/D;EAEA,OAAOR,OAAO;AAClB,CAAC;AAED,OAAO,MAAMe,iBAAiB,CAAwB;EAGlDC,WAAWA,CAACC,aAAmC,EAAE;IAC7C,IAAI,CAACA,aAAa,GAAGA,aAAa;EACtC;EAEAC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAE;IAClD,MAAMC,gBAAgB,GAAGF,OAAO,CAACG,MAAM,KAAK,SAAS;IACrD;AACR;AACA;IACQ,MAAMC,cAAc,GAAGzB,iBAAiB,CAAC,IAAI,CAACmB,aAAa,CAAC;IAE5D,MAAMO,cAAc,GAAGH,gBAAgB,GACjCE,cAAc,CAACE,KAAK,CAAC5B,wBAAwB,CAAC,CAAC,CAAC,GAChD0B,cAAc;IAEpBH,KAAK,CAACpB,OAAO,CAACwB,cAAc,CAACE,UAAU,CAAC,CAAC,CAAC;IAE1C,OAAOhC,MAAM,CAACiC,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/SetDefaultHeaders.js","sources":["../../src/PreHandler/SetDefaultHeaders.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport type { DefinedContextRoutes, HTTPMethods } from \"~/types.js\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\n\nfunction createDefaultHeaders() {\n return ResponseHeaders.create({\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store\",\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}\n\nconst getDefaultOptionsHeaders = () => {\n return ResponseHeaders.create({\n \"access-control-max-age\": \"86400\",\n \"cache-control\": \"public, max-age=86400\"\n });\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): ResponseHeaders => {\n const headers = createDefaultHeaders();\n\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 headers.set(\"access-control-allow-methods\", \"*\");\n } else {\n const allowedMethods = keys\n .filter(type => {\n if (!routes[type] || !Array.isArray(routes[type])) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\");\n\n headers.set(\"access-control-allow-methods\", allowedMethods);\n }\n\n return headers;\n};\n\nexport class SetDefaultHeaders implements IPreHandler {\n private readonly definedRoutes: DefinedContextRoutes;\n\n constructor(definedRoutes: DefinedContextRoutes) {\n this.definedRoutes = definedRoutes;\n }\n\n execute(request: FastifyRequest, reply: FastifyReply) {\n const isOptionsRequest = request.method === \"OPTIONS\";\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(this.definedRoutes);\n\n const initialHeaders = isOptionsRequest\n ? defaultHeaders.merge(getDefaultOptionsHeaders())\n : defaultHeaders;\n\n reply.headers(initialHeaders.getHeaders());\n\n return Action.CONTINUE;\n }\n}\n"],"names":["createDefaultHeaders","ResponseHeaders","getWebinyVersionHeaders","getDefaultOptionsHeaders","getDefaultHeaders","routes","headers","keys","Object","all","key","allowedMethods","type","Array","SetDefaultHeaders","definedRoutes","request","reply","isOptionsRequest","defaultHeaders","initialHeaders","Action"],"mappings":";;;AAOA,SAASA;IACL,OAAOC,gBAAgB,MAAM,CAAC;QAC1B,gBAAgB;QAChB,iBAAiB;QACjB,+BAA+B;QAC/B,gCAAgC;QAChC,gCAAgC;QAChC,GAAGC,yBAAyB;IAChC;AACJ;AAEA,MAAMC,2BAA2B,IACtBF,gBAAgB,MAAM,CAAC;QAC1B,0BAA0B;QAC1B,iBAAiB;IACrB;AAGJ,MAAMG,oBAAoB,CAACC;IACvB,MAAMC,UAAUN;IAKhB,MAAMO,OAAOC,OAAO,IAAI,CAACH;IACzB,MAAMI,MAAMF,KAAK,KAAK,CAACG,CAAAA,MAAOL,MAAM,CAACK,IAAI,CAAC,MAAM,GAAG;IACnD,IAAID,KACAH,QAAQ,GAAG,CAAC,gCAAgC;SACzC;QACH,MAAMK,iBAAiBJ,KAClB,MAAM,CAACK,CAAAA;YACJ,IAAI,CAACP,MAAM,CAACO,KAAK,IAAI,CAACC,MAAM,OAAO,CAACR,MAAM,CAACO,KAAK,GAC5C,OAAO;YAEX,OAAOP,MAAM,CAACO,KAAK,CAAC,MAAM,GAAG;QACjC,GACC,IAAI,GACJ,IAAI,CAAC;QAEVN,QAAQ,GAAG,CAAC,gCAAgCK;IAChD;IAEA,OAAOL;AACX;AAEO,MAAMQ;IAGT,YAAYC,aAAmC,CAAE;QAC7C,IAAI,CAAC,aAAa,GAAGA;IACzB;IAEA,QAAQC,OAAuB,EAAEC,KAAmB,EAAE;QAClD,MAAMC,mBAAmBF,AAAmB,cAAnBA,QAAQ,MAAM;QAIvC,MAAMG,iBAAiBf,kBAAkB,IAAI,CAAC,aAAa;QAE3D,MAAMgB,iBAAiBF,mBACjBC,eAAe,KAAK,CAAChB,8BACrBgB;QAENF,MAAM,OAAO,CAACG,eAAe,UAAU;QAEvC,OAAOC,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,39 +1,36 @@
1
- // Extract known standard headers, and remove all non-string keys.
2
-
3
1
  function isFunction(setter) {
4
- return typeof setter === "function";
2
+ return "function" == typeof setter;
5
3
  }
6
- export class ResponseHeaders {
7
- headers = new Map();
8
- constructor(initialHeaders) {
9
- if (initialHeaders) {
10
- Object.keys(initialHeaders).forEach(key => {
11
- this.headers.set(key, initialHeaders[key]);
12
- });
4
+ class ResponseHeaders {
5
+ constructor(initialHeaders){
6
+ this.headers = new Map();
7
+ if (initialHeaders) Object.keys(initialHeaders).forEach((key)=>{
8
+ this.headers.set(key, initialHeaders[key]);
9
+ });
10
+ }
11
+ set(header, setter) {
12
+ if (isFunction(setter)) {
13
+ const previousValue = this.headers.get(header);
14
+ const newValue = setter(previousValue);
15
+ this.headers.set(header, newValue);
16
+ return this;
17
+ }
18
+ this.headers.set(header, setter);
19
+ return this;
20
+ }
21
+ merge(headers) {
22
+ return ResponseHeaders.create({
23
+ ...this.getHeaders(),
24
+ ...headers.getHeaders()
25
+ });
26
+ }
27
+ getHeaders() {
28
+ return Object.fromEntries(this.headers);
13
29
  }
14
- }
15
- set(header, setter) {
16
- if (isFunction(setter)) {
17
- const previousValue = this.headers.get(header);
18
- const newValue = setter(previousValue);
19
- this.headers.set(header, newValue);
20
- return this;
30
+ static create(initialHeaders) {
31
+ return new ResponseHeaders(initialHeaders);
21
32
  }
22
- this.headers.set(header, setter);
23
- return this;
24
- }
25
- merge(headers) {
26
- return ResponseHeaders.create({
27
- ...this.getHeaders(),
28
- ...headers.getHeaders()
29
- });
30
- }
31
- getHeaders() {
32
- return Object.fromEntries(this.headers);
33
- }
34
- static create(initialHeaders) {
35
- return new ResponseHeaders(initialHeaders);
36
- }
37
33
  }
34
+ export { ResponseHeaders };
38
35
 
39
36
  //# sourceMappingURL=ResponseHeaders.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["isFunction","setter","ResponseHeaders","headers","Map","constructor","initialHeaders","Object","keys","forEach","key","set","header","previousValue","get","newValue","merge","create","getHeaders","fromEntries"],"sources":["ResponseHeaders.ts"],"sourcesContent":["import type * as http from \"http\";\n\ntype ExtraHeaders = {\n \"content-type\"?: string | undefined;\n \"x-webiny-version\"?: http.OutgoingHttpHeader | undefined;\n};\n\ntype AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;\n\nexport type StandardHeaderValue = http.OutgoingHttpHeader | undefined;\n\n// Extract known standard headers, and remove all non-string keys.\nexport type StandardHeaders = {\n [K in keyof AllHeaders as string extends K\n ? never\n : number extends K\n ? never\n : K]: http.OutgoingHttpHeaders[K];\n} & {\n [name: string]: StandardHeaderValue;\n};\n\nfunction isFunction<T>(setter: unknown): setter is (value: T) => T {\n return typeof setter === \"function\";\n}\n\ntype Setter<T> = ((value: T) => T) | T;\n\nexport class ResponseHeaders {\n private readonly headers = new Map<keyof StandardHeaders, StandardHeaderValue>();\n\n private constructor(initialHeaders?: StandardHeaders) {\n if (initialHeaders) {\n (Object.keys(initialHeaders) as Array<keyof StandardHeaders>).forEach(key => {\n this.headers.set(key, initialHeaders[key]);\n });\n }\n }\n\n set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>) {\n if (isFunction<StandardHeaders[T]>(setter)) {\n const previousValue = this.headers.get(header) as StandardHeaders[T];\n const newValue = setter(previousValue);\n this.headers.set(header, newValue);\n return this;\n }\n\n this.headers.set(header, setter);\n\n return this;\n }\n\n merge(headers: ResponseHeaders) {\n return ResponseHeaders.create({ ...this.getHeaders(), ...headers.getHeaders() });\n }\n\n getHeaders() {\n return Object.fromEntries(this.headers);\n }\n\n static create(initialHeaders?: StandardHeaders) {\n return new ResponseHeaders(initialHeaders);\n }\n}\n"],"mappings":"AAWA;;AAWA,SAASA,UAAUA,CAAIC,MAAe,EAA6B;EAC/D,OAAO,OAAOA,MAAM,KAAK,UAAU;AACvC;AAIA,OAAO,MAAMC,eAAe,CAAC;EACRC,OAAO,GAAG,IAAIC,GAAG,CAA6C,CAAC;EAExEC,WAAWA,CAACC,cAAgC,EAAE;IAClD,IAAIA,cAAc,EAAE;MACfC,MAAM,CAACC,IAAI,CAACF,cAAc,CAAC,CAAkCG,OAAO,CAACC,GAAG,IAAI;QACzE,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACD,GAAG,EAAEJ,cAAc,CAACI,GAAG,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;EAEAC,GAAGA,CAAkCC,MAAS,EAAEX,MAAkC,EAAE;IAChF,IAAID,UAAU,CAAqBC,MAAM,CAAC,EAAE;MACxC,MAAMY,aAAa,GAAG,IAAI,CAACV,OAAO,CAACW,GAAG,CAACF,MAAM,CAAuB;MACpE,MAAMG,QAAQ,GAAGd,MAAM,CAACY,aAAa,CAAC;MACtC,IAAI,CAACV,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEG,QAAQ,CAAC;MAClC,OAAO,IAAI;IACf;IAEA,IAAI,CAACZ,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEX,MAAM,CAAC;IAEhC,OAAO,IAAI;EACf;EAEAe,KAAKA,CAACb,OAAwB,EAAE;IAC5B,OAAOD,eAAe,CAACe,MAAM,CAAC;MAAE,GAAG,IAAI,CAACC,UAAU,CAAC,CAAC;MAAE,GAAGf,OAAO,CAACe,UAAU,CAAC;IAAE,CAAC,CAAC;EACpF;EAEAA,UAAUA,CAAA,EAAG;IACT,OAAOX,MAAM,CAACY,WAAW,CAAC,IAAI,CAAChB,OAAO,CAAC;EAC3C;EAEA,OAAOc,MAAMA,CAACX,cAAgC,EAAE;IAC5C,OAAO,IAAIJ,eAAe,CAACI,cAAc,CAAC;EAC9C;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"ResponseHeaders.js","sources":["../src/ResponseHeaders.ts"],"sourcesContent":["import type * as http from \"http\";\n\ntype ExtraHeaders = {\n \"content-type\"?: string | undefined;\n \"x-webiny-version\"?: http.OutgoingHttpHeader | undefined;\n};\n\ntype AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;\n\nexport type StandardHeaderValue = http.OutgoingHttpHeader | undefined;\n\n// Extract known standard headers, and remove all non-string keys.\nexport type StandardHeaders = {\n [K in keyof AllHeaders as string extends K\n ? never\n : number extends K\n ? never\n : K]: http.OutgoingHttpHeaders[K];\n} & {\n [name: string]: StandardHeaderValue;\n};\n\nfunction isFunction<T>(setter: unknown): setter is (value: T) => T {\n return typeof setter === \"function\";\n}\n\ntype Setter<T> = ((value: T) => T) | T;\n\nexport class ResponseHeaders {\n private readonly headers = new Map<keyof StandardHeaders, StandardHeaderValue>();\n\n private constructor(initialHeaders?: StandardHeaders) {\n if (initialHeaders) {\n (Object.keys(initialHeaders) as Array<keyof StandardHeaders>).forEach(key => {\n this.headers.set(key, initialHeaders[key]);\n });\n }\n }\n\n set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>) {\n if (isFunction<StandardHeaders[T]>(setter)) {\n const previousValue = this.headers.get(header) as StandardHeaders[T];\n const newValue = setter(previousValue);\n this.headers.set(header, newValue);\n return this;\n }\n\n this.headers.set(header, setter);\n\n return this;\n }\n\n merge(headers: ResponseHeaders) {\n return ResponseHeaders.create({ ...this.getHeaders(), ...headers.getHeaders() });\n }\n\n getHeaders() {\n return Object.fromEntries(this.headers);\n }\n\n static create(initialHeaders?: StandardHeaders) {\n return new ResponseHeaders(initialHeaders);\n }\n}\n"],"names":["isFunction","setter","ResponseHeaders","initialHeaders","Map","Object","key","header","previousValue","newValue","headers"],"mappings":"AAsBA,SAASA,WAAcC,MAAe;IAClC,OAAO,AAAkB,cAAlB,OAAOA;AAClB;AAIO,MAAMC;IAGT,YAAoBC,cAAgC,CAAE;aAFrC,OAAO,GAAG,IAAIC;QAG3B,IAAID,gBACCE,OAAO,IAAI,CAACF,gBAAiD,OAAO,CAACG,CAAAA;YAClE,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,KAAKH,cAAc,CAACG,IAAI;QAC7C;IAER;IAEA,IAAqCC,MAAS,EAAEN,MAAkC,EAAE;QAChF,IAAID,WAA+BC,SAAS;YACxC,MAAMO,gBAAgB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD;YACvC,MAAME,WAAWR,OAAOO;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD,QAAQE;YACzB,OAAO,IAAI;QACf;QAEA,IAAI,CAAC,OAAO,CAAC,GAAG,CAACF,QAAQN;QAEzB,OAAO,IAAI;IACf;IAEA,MAAMS,OAAwB,EAAE;QAC5B,OAAOR,gBAAgB,MAAM,CAAC;YAAE,GAAG,IAAI,CAAC,UAAU,EAAE;YAAE,GAAGQ,QAAQ,UAAU,EAAE;QAAC;IAClF;IAEA,aAAa;QACT,OAAOL,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO;IAC1C;IAEA,OAAO,OAAOF,cAAgC,EAAE;QAC5C,OAAO,IAAID,gBAAgBC;IAC/B;AACJ"}
@@ -1,4 +1,5 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
- export const Reply = createAbstraction("Reply");
2
+ const Reply = createAbstraction("Reply");
3
+ export { Reply };
3
4
 
4
5
  //# sourceMappingURL=Reply.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","Reply"],"sources":["Reply.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Reply as IReply } from \"~/types.js\";\n\nexport const Reply = createAbstraction<IReply>(\"Reply\");\n\nexport namespace Reply {\n export type Interface = IReply;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAGvD,OAAO,MAAMC,KAAK,GAAGD,iBAAiB,CAAS,OAAO,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"abstractions/Reply.js","sources":["../../src/abstractions/Reply.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Reply as IReply } from \"~/types.js\";\n\nexport const Reply = createAbstraction<IReply>(\"Reply\");\n\nexport namespace Reply {\n export type Interface = IReply;\n}\n"],"names":["Reply","createAbstraction"],"mappings":";AAGO,MAAMA,QAAQC,kBAA0B"}
@@ -1,4 +1,5 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
- export const Request = createAbstraction("Request");
2
+ const Request = createAbstraction("Request");
3
+ export { Request };
3
4
 
4
5
  //# sourceMappingURL=Request.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","Request"],"sources":["Request.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Request as IRequest } from \"~/types.js\";\n\nexport const Request = createAbstraction<IRequest>(\"Request\");\n\nexport namespace Request {\n export type Interface = IRequest;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAGvD,OAAO,MAAMC,OAAO,GAAGD,iBAAiB,CAAW,SAAS,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"abstractions/Request.js","sources":["../../src/abstractions/Request.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Request as IRequest } from \"~/types.js\";\n\nexport const Request = createAbstraction<IRequest>(\"Request\");\n\nexport namespace Request {\n export type Interface = IRequest;\n}\n"],"names":["Request","createAbstraction"],"mappings":";AAGO,MAAMA,UAAUC,kBAA4B"}
@@ -1,29 +1,30 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
- export const Route = createAbstraction("Route");
3
- export function toRouteRequest(req) {
4
- return {
5
- body: req.body,
6
- headers: req.headers,
7
- method: req.method,
8
- url: req.url,
9
- params: req.params ?? {},
10
- query: req.query ?? {}
11
- };
2
+ const Route = createAbstraction("Route");
3
+ function toRouteRequest(req) {
4
+ return {
5
+ body: req.body,
6
+ headers: req.headers,
7
+ method: req.method,
8
+ url: req.url,
9
+ params: req.params ?? {},
10
+ query: req.query ?? {}
11
+ };
12
12
  }
13
- export function toRouteReply(reply) {
14
- return {
15
- code(statusCode) {
16
- reply.code(statusCode);
17
- return this;
18
- },
19
- send(data) {
20
- reply.send(data);
21
- },
22
- header(key, value) {
23
- reply.header(key, value);
24
- return this;
25
- }
26
- };
13
+ function toRouteReply(reply) {
14
+ return {
15
+ code (statusCode) {
16
+ reply.code(statusCode);
17
+ return this;
18
+ },
19
+ send (data) {
20
+ reply.send(data);
21
+ },
22
+ header (key, value) {
23
+ reply.header(key, value);
24
+ return this;
25
+ }
26
+ };
27
27
  }
28
+ export { Route, toRouteReply, toRouteRequest };
28
29
 
29
30
  //# sourceMappingURL=Route.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","Route","toRouteRequest","req","body","headers","method","url","params","query","toRouteReply","reply","code","statusCode","send","data","header","key","value"],"sources":["Route.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FastifyRequest, FastifyReply } from \"fastify\";\n\nexport interface IRouteRequest {\n body: unknown;\n headers: Record<string, string | string[] | undefined>;\n method: string;\n url: string;\n params: unknown;\n query: unknown;\n}\n\nexport interface IRouteReply {\n code(statusCode: number): this;\n send(data?: unknown): void;\n header(key: string, value: unknown): this;\n}\n\nexport interface IRoute {\n execute(request: IRouteRequest, reply: IRouteReply): Promise<void>;\n}\n\nexport const Route = createAbstraction<IRoute>(\"Route\");\n\nexport namespace Route {\n export type Interface = IRoute;\n export type Request = IRouteRequest;\n export type Reply = IRouteReply;\n}\n\nexport function toRouteRequest(req: FastifyRequest): IRouteRequest {\n return {\n body: req.body,\n headers: req.headers as Record<string, string | string[] | undefined>,\n method: req.method,\n url: req.url,\n params: (req.params as Record<string, string>) ?? {},\n query: (req.query as Record<string, string | string[]>) ?? {}\n };\n}\n\nexport function toRouteReply(reply: FastifyReply): IRouteReply {\n return {\n code(statusCode) {\n reply.code(statusCode);\n return this;\n },\n send(data) {\n reply.send(data);\n },\n header(key, value) {\n reply.header(key, value as string);\n return this;\n }\n };\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAsBvD,OAAO,MAAMC,KAAK,GAAGD,iBAAiB,CAAS,OAAO,CAAC;AAQvD,OAAO,SAASE,cAAcA,CAACC,GAAmB,EAAiB;EAC/D,OAAO;IACHC,IAAI,EAAED,GAAG,CAACC,IAAI;IACdC,OAAO,EAAEF,GAAG,CAACE,OAAwD;IACrEC,MAAM,EAAEH,GAAG,CAACG,MAAM;IAClBC,GAAG,EAAEJ,GAAG,CAACI,GAAG;IACZC,MAAM,EAAGL,GAAG,CAACK,MAAM,IAA+B,CAAC,CAAC;IACpDC,KAAK,EAAGN,GAAG,CAACM,KAAK,IAA0C,CAAC;EAChE,CAAC;AACL;AAEA,OAAO,SAASC,YAAYA,CAACC,KAAmB,EAAe;EAC3D,OAAO;IACHC,IAAIA,CAACC,UAAU,EAAE;MACbF,KAAK,CAACC,IAAI,CAACC,UAAU,CAAC;MACtB,OAAO,IAAI;IACf,CAAC;IACDC,IAAIA,CAACC,IAAI,EAAE;MACPJ,KAAK,CAACG,IAAI,CAACC,IAAI,CAAC;IACpB,CAAC;IACDC,MAAMA,CAACC,GAAG,EAAEC,KAAK,EAAE;MACfP,KAAK,CAACK,MAAM,CAACC,GAAG,EAAEC,KAAe,CAAC;MAClC,OAAO,IAAI;IACf;EACJ,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"abstractions/Route.js","sources":["../../src/abstractions/Route.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FastifyRequest, FastifyReply } from \"fastify\";\n\nexport interface IRouteRequest {\n body: unknown;\n headers: Record<string, string | string[] | undefined>;\n method: string;\n url: string;\n params: unknown;\n query: unknown;\n}\n\nexport interface IRouteReply {\n code(statusCode: number): this;\n send(data?: unknown): void;\n header(key: string, value: unknown): this;\n}\n\nexport interface IRoute {\n execute(request: IRouteRequest, reply: IRouteReply): Promise<void>;\n}\n\nexport const Route = createAbstraction<IRoute>(\"Route\");\n\nexport namespace Route {\n export type Interface = IRoute;\n export type Request = IRouteRequest;\n export type Reply = IRouteReply;\n}\n\nexport function toRouteRequest(req: FastifyRequest): IRouteRequest {\n return {\n body: req.body,\n headers: req.headers as Record<string, string | string[] | undefined>,\n method: req.method,\n url: req.url,\n params: (req.params as Record<string, string>) ?? {},\n query: (req.query as Record<string, string | string[]>) ?? {}\n };\n}\n\nexport function toRouteReply(reply: FastifyReply): IRouteReply {\n return {\n code(statusCode) {\n reply.code(statusCode);\n return this;\n },\n send(data) {\n reply.send(data);\n },\n header(key, value) {\n reply.header(key, value as string);\n return this;\n }\n };\n}\n"],"names":["Route","createAbstraction","toRouteRequest","req","toRouteReply","reply","statusCode","data","key","value"],"mappings":";AAsBO,MAAMA,QAAQC,kBAA0B;AAQxC,SAASC,eAAeC,GAAmB;IAC9C,OAAO;QACH,MAAMA,IAAI,IAAI;QACd,SAASA,IAAI,OAAO;QACpB,QAAQA,IAAI,MAAM;QAClB,KAAKA,IAAI,GAAG;QACZ,QAASA,IAAI,MAAM,IAA+B,CAAC;QACnD,OAAQA,IAAI,KAAK,IAA0C,CAAC;IAChE;AACJ;AAEO,SAASC,aAAaC,KAAmB;IAC5C,OAAO;QACH,MAAKC,UAAU;YACXD,MAAM,IAAI,CAACC;YACX,OAAO,IAAI;QACf;QACA,MAAKC,IAAI;YACLF,MAAM,IAAI,CAACE;QACf;QACA,QAAOC,GAAG,EAAEC,KAAK;YACbJ,MAAM,MAAM,CAACG,KAAKC;YAClB,OAAO,IAAI;QACf;IACJ;AACJ"}
package/exports/api.js CHANGED
@@ -1,3 +1 @@
1
1
  export { Route } from "../abstractions/Route.js";
2
-
3
- //# sourceMappingURL=api.js.map