@webiny/handler 0.0.0-unstable.06b2ede40f → 0.0.0-unstable.0d717d18dd

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 (90) hide show
  1. package/README.md +10 -14
  2. package/ResponseHeaders.d.ts +0 -1
  3. package/ResponseHeaders.js +28 -38
  4. package/ResponseHeaders.js.map +1 -1
  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 -15
  14. package/index.js +5 -151
  15. package/package.json +18 -20
  16. package/plugins/RegisterExtensionPlugin.d.ts +22 -0
  17. package/plugins/RegisterExtensionPlugin.js +24 -0
  18. package/plugins/RegisterExtensionPlugin.js.map +1 -0
  19. package/stringifyError.js +12 -24
  20. package/stringifyError.js.map +1 -1
  21. package/types.d.ts +21 -43
  22. package/types.js +0 -15
  23. package/Context.d.ts +0 -22
  24. package/Context.js +0 -34
  25. package/Context.js.map +0 -1
  26. package/PreHandler/IPreHandler.d.ts +0 -9
  27. package/PreHandler/IPreHandler.js +0 -13
  28. package/PreHandler/IPreHandler.js.map +0 -1
  29. package/PreHandler/IfNotOptionsRequest.d.ts +0 -9
  30. package/PreHandler/IfNotOptionsRequest.js +0 -28
  31. package/PreHandler/IfNotOptionsRequest.js.map +0 -1
  32. package/PreHandler/IfOptionsRequest.d.ts +0 -9
  33. package/PreHandler/IfOptionsRequest.js +0 -28
  34. package/PreHandler/IfOptionsRequest.js.map +0 -1
  35. package/PreHandler/PreHandler.d.ts +0 -9
  36. package/PreHandler/PreHandler.js +0 -24
  37. package/PreHandler/PreHandler.js.map +0 -1
  38. package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +0 -10
  39. package/PreHandler/ProcessBeforeHandlerPlugins.js +0 -31
  40. package/PreHandler/ProcessBeforeHandlerPlugins.js.map +0 -1
  41. package/PreHandler/ProcessContextPlugins.d.ts +0 -10
  42. package/PreHandler/ProcessContextPlugins.js +0 -31
  43. package/PreHandler/ProcessContextPlugins.js.map +0 -1
  44. package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +0 -10
  45. package/PreHandler/ProcessHandlerOnRequestPlugins.js +0 -33
  46. package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +0 -1
  47. package/PreHandler/SendEarlyOptionsResponse.d.ts +0 -9
  48. package/PreHandler/SendEarlyOptionsResponse.js +0 -38
  49. package/PreHandler/SendEarlyOptionsResponse.js.map +0 -1
  50. package/PreHandler/SetDefaultHeaders.d.ts +0 -9
  51. package/PreHandler/SetDefaultHeaders.js +0 -64
  52. package/PreHandler/SetDefaultHeaders.js.map +0 -1
  53. package/fastify.d.ts +0 -10
  54. package/fastify.js +0 -401
  55. package/fastify.js.map +0 -1
  56. package/index.js.map +0 -1
  57. package/plugins/BeforeHandlerPlugin.d.ts +0 -12
  58. package/plugins/BeforeHandlerPlugin.js +0 -27
  59. package/plugins/BeforeHandlerPlugin.js.map +0 -1
  60. package/plugins/EventPlugin.d.ts +0 -25
  61. package/plugins/EventPlugin.js +0 -30
  62. package/plugins/EventPlugin.js.map +0 -1
  63. package/plugins/HandlerErrorPlugin.d.ts +0 -15
  64. package/plugins/HandlerErrorPlugin.js +0 -24
  65. package/plugins/HandlerErrorPlugin.js.map +0 -1
  66. package/plugins/HandlerOnRequestPlugin.d.ts +0 -21
  67. package/plugins/HandlerOnRequestPlugin.js +0 -31
  68. package/plugins/HandlerOnRequestPlugin.js.map +0 -1
  69. package/plugins/HandlerResultPlugin.d.ts +0 -12
  70. package/plugins/HandlerResultPlugin.js +0 -24
  71. package/plugins/HandlerResultPlugin.js.map +0 -1
  72. package/plugins/ModifyFastifyPlugin.d.ts +0 -13
  73. package/plugins/ModifyFastifyPlugin.js +0 -24
  74. package/plugins/ModifyFastifyPlugin.js.map +0 -1
  75. package/plugins/ModifyResponseHeadersPlugin.d.ts +0 -14
  76. package/plugins/ModifyResponseHeadersPlugin.js +0 -24
  77. package/plugins/ModifyResponseHeadersPlugin.js.map +0 -1
  78. package/plugins/OnRequestResponseSendPlugin.d.ts +0 -26
  79. package/plugins/OnRequestResponseSendPlugin.js +0 -40
  80. package/plugins/OnRequestResponseSendPlugin.js.map +0 -1
  81. package/plugins/OnRequestTimeoutPlugin.d.ts +0 -12
  82. package/plugins/OnRequestTimeoutPlugin.js +0 -24
  83. package/plugins/OnRequestTimeoutPlugin.js.map +0 -1
  84. package/plugins/RoutePlugin.d.ts +0 -23
  85. package/plugins/RoutePlugin.js +0 -21
  86. package/plugins/RoutePlugin.js.map +0 -1
  87. package/suppressPunycodeWarnings.d.ts +0 -4
  88. package/suppressPunycodeWarnings.js +0 -11
  89. package/suppressPunycodeWarnings.js.map +0 -1
  90. package/types.js.map +0 -1
package/README.md CHANGED
@@ -1,15 +1,11 @@
1
1
  # @webiny/handler
2
- [![](https://img.shields.io/npm/dw/@webiny/handler.svg)](https://www.npmjs.com/package/@webiny/handler)
3
- [![](https://img.shields.io/npm/v/@webiny/handler.svg)](https://www.npmjs.com/package/@webiny/handler)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
-
7
- ## Install
8
- ```
9
- npm install --save @webiny/handler
10
- ```
11
-
12
- Or if you prefer yarn:
13
- ```
14
- yarn add @webiny/handler
15
- ```
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type * as http from "http";
3
2
  type ExtraHeaders = {
4
3
  "content-type"?: string | undefined;
@@ -1,46 +1,36 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ResponseHeaders = void 0;
7
- // Extract known standard headers, and remove all non-string keys.
8
-
9
1
  function isFunction(setter) {
10
- return typeof setter === "function";
2
+ return "function" == typeof setter;
11
3
  }
12
4
  class ResponseHeaders {
13
- headers = new Map();
14
- constructor(initialHeaders) {
15
- if (initialHeaders) {
16
- Object.keys(initialHeaders).forEach(key => {
17
- this.headers.set(key, initialHeaders[key]);
18
- });
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);
19
29
  }
20
- }
21
- set(header, setter) {
22
- if (isFunction(setter)) {
23
- const previousValue = this.headers.get(header);
24
- const newValue = setter(previousValue);
25
- this.headers.set(header, newValue);
26
- return this;
30
+ static create(initialHeaders) {
31
+ return new ResponseHeaders(initialHeaders);
27
32
  }
28
- this.headers.set(header, setter);
29
- return this;
30
- }
31
- merge(headers) {
32
- return ResponseHeaders.create({
33
- ...this.getHeaders(),
34
- ...headers.getHeaders()
35
- });
36
- }
37
- getHeaders() {
38
- return Object.fromEntries(this.headers);
39
- }
40
- static create(initialHeaders) {
41
- return new ResponseHeaders(initialHeaders);
42
- }
43
33
  }
44
- exports.ResponseHeaders = ResponseHeaders;
34
+ export { ResponseHeaders };
45
35
 
46
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","exports"],"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;AAIO,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;AAACc,OAAA,CAAAlB,eAAA,GAAAA,eAAA","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"}
@@ -0,0 +1,5 @@
1
+ import type { Reply as IReply } from "../types.js";
2
+ export declare const Reply: import("@webiny/di").Abstraction<IReply>;
3
+ export declare namespace Reply {
4
+ type Interface = IReply;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const Reply = createAbstraction("Reply");
3
+ export { Reply };
4
+
5
+ //# sourceMappingURL=Reply.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,5 @@
1
+ import type { Request as IRequest } from "../types.js";
2
+ export declare const Request: import("@webiny/di").Abstraction<IRequest>;
3
+ export declare namespace Request {
4
+ type Interface = IRequest;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const Request = createAbstraction("Request");
3
+ export { Request };
4
+
5
+ //# sourceMappingURL=Request.js.map
@@ -0,0 +1 @@
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"}
File without changes
package/exports/api.js ADDED
File without changes
package/index.d.ts CHANGED
@@ -1,15 +1,6 @@
1
- import "./suppressPunycodeWarnings";
2
- export * from "./fastify";
3
- export * from "./Context";
4
- export * from "./ResponseHeaders";
5
- export * from "./plugins/EventPlugin";
6
- export * from "./plugins/RoutePlugin";
7
- export * from "./plugins/BeforeHandlerPlugin";
8
- export * from "./plugins/HandlerErrorPlugin";
9
- export * from "./plugins/HandlerResultPlugin";
10
- export * from "./plugins/HandlerOnRequestPlugin";
11
- export * from "./plugins/ModifyFastifyPlugin";
12
- export * from "./plugins/ModifyResponseHeadersPlugin";
13
- export * from "./plugins/OnRequestResponseSendPlugin.js";
14
- export * from "./plugins/OnRequestTimeoutPlugin.js";
15
- export * from "./ResponseHeaders";
1
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions } from "./plugins/RegisterExtensionPlugin.js";
2
+ export { stringifyError } from "./stringifyError.js";
3
+ export { Request } from "./abstractions/Request.js";
4
+ export { Reply } from "./abstractions/Reply.js";
5
+ export { ResponseHeaders } from "./ResponseHeaders.js";
6
+ export type { StandardHeaders, StandardHeaderValue } from "./ResponseHeaders.js";
package/index.js CHANGED
@@ -1,151 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- require("./suppressPunycodeWarnings");
7
- var _fastify = require("./fastify");
8
- Object.keys(_fastify).forEach(function (key) {
9
- if (key === "default" || key === "__esModule") return;
10
- if (key in exports && exports[key] === _fastify[key]) return;
11
- Object.defineProperty(exports, key, {
12
- enumerable: true,
13
- get: function () {
14
- return _fastify[key];
15
- }
16
- });
17
- });
18
- var _Context = require("./Context");
19
- Object.keys(_Context).forEach(function (key) {
20
- if (key === "default" || key === "__esModule") return;
21
- if (key in exports && exports[key] === _Context[key]) return;
22
- Object.defineProperty(exports, key, {
23
- enumerable: true,
24
- get: function () {
25
- return _Context[key];
26
- }
27
- });
28
- });
29
- var _ResponseHeaders = require("./ResponseHeaders");
30
- Object.keys(_ResponseHeaders).forEach(function (key) {
31
- if (key === "default" || key === "__esModule") return;
32
- if (key in exports && exports[key] === _ResponseHeaders[key]) return;
33
- Object.defineProperty(exports, key, {
34
- enumerable: true,
35
- get: function () {
36
- return _ResponseHeaders[key];
37
- }
38
- });
39
- });
40
- var _EventPlugin = require("./plugins/EventPlugin");
41
- Object.keys(_EventPlugin).forEach(function (key) {
42
- if (key === "default" || key === "__esModule") return;
43
- if (key in exports && exports[key] === _EventPlugin[key]) return;
44
- Object.defineProperty(exports, key, {
45
- enumerable: true,
46
- get: function () {
47
- return _EventPlugin[key];
48
- }
49
- });
50
- });
51
- var _RoutePlugin = require("./plugins/RoutePlugin");
52
- Object.keys(_RoutePlugin).forEach(function (key) {
53
- if (key === "default" || key === "__esModule") return;
54
- if (key in exports && exports[key] === _RoutePlugin[key]) return;
55
- Object.defineProperty(exports, key, {
56
- enumerable: true,
57
- get: function () {
58
- return _RoutePlugin[key];
59
- }
60
- });
61
- });
62
- var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
63
- Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
64
- if (key === "default" || key === "__esModule") return;
65
- if (key in exports && exports[key] === _BeforeHandlerPlugin[key]) return;
66
- Object.defineProperty(exports, key, {
67
- enumerable: true,
68
- get: function () {
69
- return _BeforeHandlerPlugin[key];
70
- }
71
- });
72
- });
73
- var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
74
- Object.keys(_HandlerErrorPlugin).forEach(function (key) {
75
- if (key === "default" || key === "__esModule") return;
76
- if (key in exports && exports[key] === _HandlerErrorPlugin[key]) return;
77
- Object.defineProperty(exports, key, {
78
- enumerable: true,
79
- get: function () {
80
- return _HandlerErrorPlugin[key];
81
- }
82
- });
83
- });
84
- var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
85
- Object.keys(_HandlerResultPlugin).forEach(function (key) {
86
- if (key === "default" || key === "__esModule") return;
87
- if (key in exports && exports[key] === _HandlerResultPlugin[key]) return;
88
- Object.defineProperty(exports, key, {
89
- enumerable: true,
90
- get: function () {
91
- return _HandlerResultPlugin[key];
92
- }
93
- });
94
- });
95
- var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
96
- Object.keys(_HandlerOnRequestPlugin).forEach(function (key) {
97
- if (key === "default" || key === "__esModule") return;
98
- if (key in exports && exports[key] === _HandlerOnRequestPlugin[key]) return;
99
- Object.defineProperty(exports, key, {
100
- enumerable: true,
101
- get: function () {
102
- return _HandlerOnRequestPlugin[key];
103
- }
104
- });
105
- });
106
- var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
107
- Object.keys(_ModifyFastifyPlugin).forEach(function (key) {
108
- if (key === "default" || key === "__esModule") return;
109
- if (key in exports && exports[key] === _ModifyFastifyPlugin[key]) return;
110
- Object.defineProperty(exports, key, {
111
- enumerable: true,
112
- get: function () {
113
- return _ModifyFastifyPlugin[key];
114
- }
115
- });
116
- });
117
- var _ModifyResponseHeadersPlugin = require("./plugins/ModifyResponseHeadersPlugin");
118
- Object.keys(_ModifyResponseHeadersPlugin).forEach(function (key) {
119
- if (key === "default" || key === "__esModule") return;
120
- if (key in exports && exports[key] === _ModifyResponseHeadersPlugin[key]) return;
121
- Object.defineProperty(exports, key, {
122
- enumerable: true,
123
- get: function () {
124
- return _ModifyResponseHeadersPlugin[key];
125
- }
126
- });
127
- });
128
- var _OnRequestResponseSendPlugin = require("./plugins/OnRequestResponseSendPlugin.js");
129
- Object.keys(_OnRequestResponseSendPlugin).forEach(function (key) {
130
- if (key === "default" || key === "__esModule") return;
131
- if (key in exports && exports[key] === _OnRequestResponseSendPlugin[key]) return;
132
- Object.defineProperty(exports, key, {
133
- enumerable: true,
134
- get: function () {
135
- return _OnRequestResponseSendPlugin[key];
136
- }
137
- });
138
- });
139
- var _OnRequestTimeoutPlugin = require("./plugins/OnRequestTimeoutPlugin.js");
140
- Object.keys(_OnRequestTimeoutPlugin).forEach(function (key) {
141
- if (key === "default" || key === "__esModule") return;
142
- if (key in exports && exports[key] === _OnRequestTimeoutPlugin[key]) return;
143
- Object.defineProperty(exports, key, {
144
- enumerable: true,
145
- get: function () {
146
- return _OnRequestTimeoutPlugin[key];
147
- }
148
- });
149
- });
150
-
151
- //# sourceMappingURL=index.js.map
1
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions } from "./plugins/RegisterExtensionPlugin.js";
2
+ export { stringifyError } from "./stringifyError.js";
3
+ export { Request } from "./abstractions/Request.js";
4
+ export { Reply } from "./abstractions/Reply.js";
5
+ export { ResponseHeaders } from "./ResponseHeaders.js";
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/handler",
3
- "version": "0.0.0-unstable.06b2ede40f",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.0d717d18dd",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
5
9
  "repository": {
6
10
  "type": "git",
7
11
  "url": "https://github.com/webiny/webiny-js.git"
@@ -12,27 +16,21 @@
12
16
  ],
13
17
  "license": "MIT",
14
18
  "dependencies": {
15
- "@fastify/compress": "7.0.3",
16
- "@fastify/cookie": "9.4.0",
17
- "@webiny/api": "0.0.0-unstable.06b2ede40f",
18
- "@webiny/error": "0.0.0-unstable.06b2ede40f",
19
- "@webiny/handler-client": "0.0.0-unstable.06b2ede40f",
20
- "@webiny/plugins": "0.0.0-unstable.06b2ede40f",
21
- "@webiny/utils": "0.0.0-unstable.06b2ede40f",
22
- "fastify": "4.29.1"
19
+ "@webiny/di": "1.0.2",
20
+ "@webiny/feature": "0.0.0-unstable.0d717d18dd",
21
+ "@webiny/plugins": "0.0.0-unstable.0d717d18dd"
23
22
  },
24
23
  "devDependencies": {
25
- "@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
26
- "rimraf": "6.0.1",
27
- "typescript": "5.3.3"
24
+ "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
25
+ "rimraf": "6.1.3",
26
+ "typescript": "7.0.2",
27
+ "vitest": "4.1.10"
28
28
  },
29
29
  "publishConfig": {
30
- "access": "public",
31
- "directory": "dist"
32
- },
33
- "scripts": {
34
- "build": "node ../cli/bin.js run build",
35
- "watch": "node ../cli/bin.js run watch"
30
+ "access": "public"
36
31
  },
37
- "gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
32
+ "gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
33
+ "webiny": {
34
+ "publishFrom": "dist"
35
+ }
38
36
  }
@@ -0,0 +1,22 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import type { Container } from "@webiny/di";
3
+ import type { Context } from "../types.js";
4
+ export interface IRegisterExtensionPluginCb<C extends Context = Context> {
5
+ (context: C): Promise<void> | void;
6
+ }
7
+ export declare class RegisterExtensionPlugin<C extends Context = Context> extends Plugin {
8
+ private readonly cb;
9
+ static readonly type: string;
10
+ constructor(cb: IRegisterExtensionPluginCb<C>);
11
+ apply(context: C): Promise<void> | void;
12
+ }
13
+ export declare const createRegisterExtensionPlugin: <C extends Context = Context>(cb: IRegisterExtensionPluginCb<C>) => RegisterExtensionPlugin<C>;
14
+ /**
15
+ * Apply RegisterExtensionPlugins at register() time — synchronously with the request container,
16
+ * BEFORE any RequestContextInitializer runs. Each plugin's callback only does DI registration via
17
+ * registerExtension(ctx.container, ...) (feature/decorator/registration), which is register-time
18
+ * safe. Doing this early is important for code-defined CMS models (ModelFactory): a later
19
+ * initializer (e.g. ACO) lists + caches the model set per request, so any model registered after
20
+ * that — as happened when extensions ran via the post-auth initializer — was silently missing.
21
+ */
22
+ export declare function registerExtensions(container: Container, plugins: unknown | unknown[]): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ class RegisterExtensionPlugin extends Plugin {
3
+ static{
4
+ this.type = "handler.register.extension";
5
+ }
6
+ constructor(cb){
7
+ super(), this.cb = cb;
8
+ }
9
+ apply(context) {
10
+ return this.cb(context);
11
+ }
12
+ }
13
+ const createRegisterExtensionPlugin = (cb)=>new RegisterExtensionPlugin(cb);
14
+ async function registerExtensions(container, plugins) {
15
+ const flat = [
16
+ plugins
17
+ ].flat(1 / 0).filter(Boolean);
18
+ for (const plugin of flat)if (plugin?.type === RegisterExtensionPlugin.type && "function" == typeof plugin.apply) await plugin.apply({
19
+ container
20
+ });
21
+ }
22
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions };
23
+
24
+ //# sourceMappingURL=RegisterExtensionPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins/RegisterExtensionPlugin.js","sources":["../../src/plugins/RegisterExtensionPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Container } from \"@webiny/di\";\nimport type { Context } from \"~/types.js\";\n\nexport interface IRegisterExtensionPluginCb<C extends Context = Context> {\n (context: C): Promise<void> | void;\n}\n\nexport class RegisterExtensionPlugin<C extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.register.extension\";\n\n public constructor(private readonly cb: IRegisterExtensionPluginCb<C>) {\n super();\n }\n\n public apply(context: C): Promise<void> | void {\n return this.cb(context);\n }\n}\n\nexport const createRegisterExtensionPlugin = <C extends Context = Context>(\n cb: IRegisterExtensionPluginCb<C>\n) => {\n return new RegisterExtensionPlugin<C>(cb);\n};\n\n/**\n * Apply RegisterExtensionPlugins at register() time — synchronously with the request container,\n * BEFORE any RequestContextInitializer runs. Each plugin's callback only does DI registration via\n * registerExtension(ctx.container, ...) (feature/decorator/registration), which is register-time\n * safe. Doing this early is important for code-defined CMS models (ModelFactory): a later\n * initializer (e.g. ACO) lists + caches the model set per request, so any model registered after\n * that — as happened when extensions ran via the post-auth initializer — was silently missing.\n */\nexport async function registerExtensions(\n container: Container,\n plugins: unknown | unknown[]\n): Promise<void> {\n const flat = [plugins].flat(Infinity as 1).filter(Boolean) as RegisterExtensionPlugin[];\n for (const plugin of flat) {\n if (plugin?.type === RegisterExtensionPlugin.type && typeof plugin.apply === \"function\") {\n await plugin.apply({ container } as unknown as Context);\n }\n }\n}\n"],"names":["RegisterExtensionPlugin","Plugin","cb","context","createRegisterExtensionPlugin","registerExtensions","container","plugins","flat","Infinity","Boolean","plugin"],"mappings":";AAQO,MAAMA,gCAA6DC;;aACtC,IAAI,GAAW;;IAE/C,YAAoCC,EAAiC,CAAE;QACnE,KAAK,SAD2BA,EAAE,GAAFA;IAEpC;IAEO,MAAMC,OAAU,EAAwB;QAC3C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAEO,MAAMC,gCAAgC,CACzCF,KAEO,IAAIF,wBAA2BE;AAWnC,eAAeG,mBAClBC,SAAoB,EACpBC,OAA4B;IAE5B,MAAMC,OAAO;QAACD;KAAQ,CAAC,IAAI,CAACE,OAAe,MAAM,CAACC;IAClD,KAAK,MAAMC,UAAUH,KACjB,IAAIG,QAAQ,SAASX,wBAAwB,IAAI,IAAI,AAAwB,cAAxB,OAAOW,OAAO,KAAK,EACpE,MAAMA,OAAO,KAAK,CAAC;QAAEL;IAAU;AAG3C"}
package/stringifyError.js CHANGED
@@ -1,27 +1,15 @@
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
- });
1
+ const stringifyError = (error)=>{
2
+ const { name, message, code, stack, data } = error;
3
+ return JSON.stringify({
4
+ ...error,
5
+ constructorName: error.constructor?.name || "UnknownError",
6
+ name: name || "No error name",
7
+ message: message || "No error message",
8
+ code: code || "NO_CODE",
9
+ data,
10
+ stack: "true" === process.env.DEBUG ? stack : "Turn on the debug flag to see the stack."
11
+ });
24
12
  };
25
- exports.stringifyError = stringifyError;
13
+ export { stringifyError };
26
14
 
27
15
  //# sourceMappingURL=stringifyError.js.map
@@ -1 +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":[]}
1
+ {"version":3,"file":"stringifyError.js","sources":["../src/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"],"names":["stringifyError","error","name","message","code","stack","data","JSON","process"],"mappings":"AAKO,MAAMA,iBAAiB,CAACC;IAC3B,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAE,GAAGL;IAC7C,OAAOM,KAAK,SAAS,CAAC;QAClB,GAAGN,KAAK;QACR,iBAAiBA,MAAM,WAAW,EAAE,QAAQ;QAC5C,MAAMC,QAAQ;QACd,SAASC,WAAW;QACpB,MAAMC,QAAQ;QACdE;QACA,OAAOE,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK,GAAcH,QAAQ;IAClD;AACJ"}
package/types.d.ts CHANGED
@@ -1,46 +1,24 @@
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";
5
- export interface RouteMethodOptions {
6
- override?: boolean;
1
+ import type { Container } from "@webiny/feature/api";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ export interface Request {
4
+ url?: string;
5
+ method?: string;
6
+ headers: Record<string, string | undefined>;
7
+ body?: unknown;
8
+ params?: Record<string, string>;
9
+ query?: Record<string, string | string[]>;
10
+ path?: string;
11
+ [key: string]: unknown;
7
12
  }
8
- export type RouteMethodPath = `/${string}` | "*";
9
- export interface RouteMethod {
10
- (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;
13
+ export interface Reply {
14
+ send(data?: unknown): void | Promise<void>;
15
+ code(statusCode: number): Reply;
16
+ headers(headers: Record<string, string>): Reply;
17
+ header(name: string, value: string): Reply;
18
+ setCookie(name: string, value: string, options?: Record<string, unknown>): Reply;
19
+ [key: string]: unknown;
11
20
  }
12
- export type Request = FastifyRequest;
13
- export type Reply = FastifyReply;
14
- export type HTTPMethods = Uppercase<BaseHttpMethods>;
15
- export type DefinedContextRoutes = Record<HTTPMethods, string[]>;
16
- export interface ContextRoutes {
17
- defined: DefinedContextRoutes;
18
- onGet: RouteMethod;
19
- onPost: RouteMethod;
20
- onPut: RouteMethod;
21
- onPatch: RouteMethod;
22
- onDelete: RouteMethod;
23
- onOptions: RouteMethod;
24
- onAll: RouteMethod;
25
- onHead: RouteMethod;
26
- }
27
- export interface Context extends ClientContext {
28
- /**
29
- * Current request. Must be set only once!
30
- */
31
- request: FastifyRequest;
32
- /**
33
- * Current reply. Must be set only once!
34
- */
35
- reply: FastifyReply;
36
- /**
37
- * @internal
38
- */
39
- routes: ContextRoutes;
40
- }
41
- declare module "fastify" {
42
- interface FastifyInstance {
43
- webiny: Context;
44
- __webiny_raw_result: any;
45
- }
21
+ export interface Context {
22
+ plugins: PluginsContainer;
23
+ container: Container;
46
24
  }
package/types.js CHANGED
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "FastifyInstance", {
7
- enumerable: true,
8
- get: function () {
9
- return _fastify.FastifyInstance;
10
- }
11
- });
12
- require("@fastify/cookie");
13
- var _fastify = require("fastify");
14
-
15
- //# sourceMappingURL=types.js.map
package/Context.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { ContextParams as BaseContextParams, ContextPluginCallable as BaseContextPluginCallable } from "@webiny/api";
2
- import { Context as BaseContext, ContextPlugin as BaseContextPlugin } from "@webiny/api";
3
- import type { Context as ContextInterface } from "./types";
4
- export interface ContextParams extends BaseContextParams {
5
- routes: ContextInterface["routes"];
6
- }
7
- export declare class Context extends BaseContext implements ContextInterface {
8
- readonly routes: ContextInterface["routes"];
9
- handlerClient: ContextInterface["handlerClient"];
10
- request: ContextInterface["request"];
11
- reply: ContextInterface["reply"];
12
- constructor(params: ContextParams);
13
- }
14
- /**
15
- * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
16
- *
17
- * This can be removed when we introduce the type augmentation.
18
- */
19
- export type ContextPluginCallable<T extends ContextInterface = ContextInterface> = BaseContextPluginCallable<T>;
20
- export declare class ContextPlugin<T extends ContextInterface = ContextInterface> extends BaseContextPlugin<T> {
21
- }
22
- export declare const createContextPlugin: <T extends ContextInterface = ContextInterface>(callable: ContextPluginCallable<T>) => BaseContextPlugin<T>;