@webiny/handler 0.0.0-unstable.496cf268ac β†’ 0.0.0-unstable.5387e5f7c8

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 (55) 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 -10
  14. package/index.js +5 -135
  15. package/package.json +18 -29
  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 -46
  23. package/types.js +0 -19
  24. package/Context.d.ts +0 -14
  25. package/Context.js +0 -31
  26. package/Context.js.map +0 -1
  27. package/fastify.d.ts +0 -8
  28. package/fastify.js +0 -483
  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/HandlerOnRequestPlugin.d.ts +0 -20
  44. package/plugins/HandlerOnRequestPlugin.js +0 -34
  45. package/plugins/HandlerOnRequestPlugin.js.map +0 -1
  46. package/plugins/HandlerResultPlugin.d.ts +0 -12
  47. package/plugins/HandlerResultPlugin.js +0 -34
  48. package/plugins/HandlerResultPlugin.js.map +0 -1
  49. package/plugins/ModifyFastifyPlugin.d.ts +0 -13
  50. package/plugins/ModifyFastifyPlugin.js +0 -34
  51. package/plugins/ModifyFastifyPlugin.js.map +0 -1
  52. package/plugins/RoutePlugin.d.ts +0 -23
  53. package/plugins/RoutePlugin.js +0 -30
  54. package/plugins/RoutePlugin.js.map +0 -1
  55. 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._
@@ -0,0 +1,24 @@
1
+ import type * as http from "http";
2
+ type ExtraHeaders = {
3
+ "content-type"?: string | undefined;
4
+ "x-webiny-version"?: http.OutgoingHttpHeader | undefined;
5
+ };
6
+ type AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;
7
+ export type StandardHeaderValue = http.OutgoingHttpHeader | undefined;
8
+ export type StandardHeaders = {
9
+ [K in keyof AllHeaders as string extends K ? never : number extends K ? never : K]: http.OutgoingHttpHeaders[K];
10
+ } & {
11
+ [name: string]: StandardHeaderValue;
12
+ };
13
+ type Setter<T> = ((value: T) => T) | T;
14
+ export declare class ResponseHeaders {
15
+ private readonly headers;
16
+ private constructor();
17
+ set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>): this;
18
+ merge(headers: ResponseHeaders): ResponseHeaders;
19
+ getHeaders(): {
20
+ [k: string]: StandardHeaderValue;
21
+ };
22
+ static create(initialHeaders?: StandardHeaders): ResponseHeaders;
23
+ }
24
+ export {};
@@ -0,0 +1,36 @@
1
+ function isFunction(setter) {
2
+ return "function" == typeof setter;
3
+ }
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);
29
+ }
30
+ static create(initialHeaders) {
31
+ return new ResponseHeaders(initialHeaders);
32
+ }
33
+ }
34
+ export { ResponseHeaders };
35
+
36
+ //# sourceMappingURL=ResponseHeaders.js.map
@@ -0,0 +1 @@
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 [\n K in keyof AllHeaders as string extends K ? never : number extends K ? never : K\n ]: 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":"AAoBA,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,10 +1,6 @@
1
- export * from "@webiny/api/plugins/ContextPlugin";
2
- export * from "./fastify";
3
- export * from "./Context";
4
- export * from "./plugins/EventPlugin";
5
- export * from "./plugins/RoutePlugin";
6
- export * from "./plugins/BeforeHandlerPlugin";
7
- export * from "./plugins/HandlerErrorPlugin";
8
- export * from "./plugins/HandlerResultPlugin";
9
- export * from "./plugins/HandlerOnRequestPlugin";
10
- export * from "./plugins/ModifyFastifyPlugin";
1
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions, RegisterBuildParamPlugin, createRegisterBuildParamPlugin, registerBuildParams } 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,135 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _ContextPlugin = require("@webiny/api/plugins/ContextPlugin");
8
-
9
- Object.keys(_ContextPlugin).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _ContextPlugin[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _ContextPlugin[key];
16
- }
17
- });
18
- });
19
-
20
- var _fastify = require("./fastify");
21
-
22
- Object.keys(_fastify).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _fastify[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _fastify[key];
29
- }
30
- });
31
- });
32
-
33
- var _Context = require("./Context");
34
-
35
- Object.keys(_Context).forEach(function (key) {
36
- if (key === "default" || key === "__esModule") return;
37
- if (key in exports && exports[key] === _Context[key]) return;
38
- Object.defineProperty(exports, key, {
39
- enumerable: true,
40
- get: function () {
41
- return _Context[key];
42
- }
43
- });
44
- });
45
-
46
- var _EventPlugin = require("./plugins/EventPlugin");
47
-
48
- Object.keys(_EventPlugin).forEach(function (key) {
49
- if (key === "default" || key === "__esModule") return;
50
- if (key in exports && exports[key] === _EventPlugin[key]) return;
51
- Object.defineProperty(exports, key, {
52
- enumerable: true,
53
- get: function () {
54
- return _EventPlugin[key];
55
- }
56
- });
57
- });
58
-
59
- var _RoutePlugin = require("./plugins/RoutePlugin");
60
-
61
- Object.keys(_RoutePlugin).forEach(function (key) {
62
- if (key === "default" || key === "__esModule") return;
63
- if (key in exports && exports[key] === _RoutePlugin[key]) return;
64
- Object.defineProperty(exports, key, {
65
- enumerable: true,
66
- get: function () {
67
- return _RoutePlugin[key];
68
- }
69
- });
70
- });
71
-
72
- var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
73
-
74
- Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
75
- if (key === "default" || key === "__esModule") return;
76
- if (key in exports && exports[key] === _BeforeHandlerPlugin[key]) return;
77
- Object.defineProperty(exports, key, {
78
- enumerable: true,
79
- get: function () {
80
- return _BeforeHandlerPlugin[key];
81
- }
82
- });
83
- });
84
-
85
- var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
86
-
87
- Object.keys(_HandlerErrorPlugin).forEach(function (key) {
88
- if (key === "default" || key === "__esModule") return;
89
- if (key in exports && exports[key] === _HandlerErrorPlugin[key]) return;
90
- Object.defineProperty(exports, key, {
91
- enumerable: true,
92
- get: function () {
93
- return _HandlerErrorPlugin[key];
94
- }
95
- });
96
- });
97
-
98
- var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
99
-
100
- Object.keys(_HandlerResultPlugin).forEach(function (key) {
101
- if (key === "default" || key === "__esModule") return;
102
- if (key in exports && exports[key] === _HandlerResultPlugin[key]) return;
103
- Object.defineProperty(exports, key, {
104
- enumerable: true,
105
- get: function () {
106
- return _HandlerResultPlugin[key];
107
- }
108
- });
109
- });
110
-
111
- var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
112
-
113
- Object.keys(_HandlerOnRequestPlugin).forEach(function (key) {
114
- if (key === "default" || key === "__esModule") return;
115
- if (key in exports && exports[key] === _HandlerOnRequestPlugin[key]) return;
116
- Object.defineProperty(exports, key, {
117
- enumerable: true,
118
- get: function () {
119
- return _HandlerOnRequestPlugin[key];
120
- }
121
- });
122
- });
123
-
124
- var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
125
-
126
- Object.keys(_ModifyFastifyPlugin).forEach(function (key) {
127
- if (key === "default" || key === "__esModule") return;
128
- if (key in exports && exports[key] === _ModifyFastifyPlugin[key]) return;
129
- Object.defineProperty(exports, key, {
130
- enumerable: true,
131
- get: function () {
132
- return _ModifyFastifyPlugin[key];
133
- }
134
- });
135
- });
1
+ export { RegisterBuildParamPlugin, RegisterExtensionPlugin, createRegisterBuildParamPlugin, createRegisterExtensionPlugin, registerBuildParams, 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.496cf268ac",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.5387e5f7c8",
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,36 +16,21 @@
12
16
  ],
13
17
  "license": "MIT",
14
18
  "dependencies": {
15
- "@babel/runtime": "7.20.13",
16
- "@fastify/compress": "6.2.0",
17
- "@fastify/cookie": "8.3.0",
18
- "@webiny/api": "0.0.0-unstable.496cf268ac",
19
- "@webiny/error": "0.0.0-unstable.496cf268ac",
20
- "@webiny/handler-client": "0.0.0-unstable.496cf268ac",
21
- "@webiny/plugins": "0.0.0-unstable.496cf268ac",
22
- "@webiny/utils": "0.0.0-unstable.496cf268ac",
23
- "fastify": "4.11.0"
19
+ "@webiny/di": "2.0.0",
20
+ "@webiny/feature": "0.0.0-unstable.5387e5f7c8",
21
+ "@webiny/plugins": "0.0.0-unstable.5387e5f7c8"
24
22
  },
25
23
  "devDependencies": {
26
- "@babel/cli": "^7.19.3",
27
- "@babel/core": "^7.19.3",
28
- "@babel/preset-env": "^7.19.4",
29
- "@babel/preset-typescript": "^7.18.6",
30
- "@webiny/cli": "^0.0.0-unstable.496cf268ac",
31
- "@webiny/project-utils": "^0.0.0-unstable.496cf268ac",
32
- "babel-plugin-lodash": "^3.3.4",
33
- "merge": "^1.2.1",
34
- "rimraf": "^3.0.2",
35
- "ttypescript": "^1.5.13",
36
- "typescript": "4.7.4"
24
+ "@webiny/build-tools": "0.0.0-unstable.5387e5f7c8",
25
+ "rimraf": "6.1.3",
26
+ "typescript": "7.0.2",
27
+ "vitest": "4.1.11"
37
28
  },
38
29
  "publishConfig": {
39
- "access": "public",
40
- "directory": "dist"
41
- },
42
- "scripts": {
43
- "build": "yarn webiny run build",
44
- "watch": "yarn webiny run watch"
30
+ "access": "public"
45
31
  },
46
- "gitHead": "496cf268acd5b092c860b62d75c7d765c9472043"
32
+ "gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
33
+ "webiny": {
34
+ "publishFrom": "dist"
35
+ }
47
36
  }
@@ -0,0 +1,36 @@
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 anything lists the model set. 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): the first
19
+ * request-time listing (e.g. the ACO folder schema) caches the model set for the rest of the
20
+ * request, so any model registered after that point is silently missing.
21
+ */
22
+ export declare function registerExtensions(container: Container, plugins: unknown | unknown[]): Promise<void>;
23
+ /**
24
+ * Registers a BuildParam. A separate type from RegisterExtensionPlugin so the request stack can apply
25
+ * build params BEFORE any feature registers: features gate themselves on FeatureFlags (a BuildParam)
26
+ * at register() time, and would otherwise read an empty flag set. `registerExtensions` skips these.
27
+ */
28
+ export declare class RegisterBuildParamPlugin<C extends Context = Context> extends RegisterExtensionPlugin<C> {
29
+ static readonly type: string;
30
+ }
31
+ export declare const createRegisterBuildParamPlugin: <C extends Context = Context>(cb: IRegisterExtensionPluginCb<C>) => RegisterBuildParamPlugin<C>;
32
+ /**
33
+ * Apply RegisterBuildParamPlugins. Call this before registering any feature that reads BuildParams
34
+ * (e.g. FeatureFlags) at register() time.
35
+ */
36
+ export declare function registerBuildParams(container: Container, plugins: unknown | unknown[]): Promise<void>;
@@ -0,0 +1,38 @@
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
+ class RegisterBuildParamPlugin extends RegisterExtensionPlugin {
23
+ static{
24
+ this.type = "handler.register.buildParam";
25
+ }
26
+ }
27
+ const createRegisterBuildParamPlugin = (cb)=>new RegisterBuildParamPlugin(cb);
28
+ async function registerBuildParams(container, plugins) {
29
+ const flat = [
30
+ plugins
31
+ ].flat(1 / 0).filter(Boolean);
32
+ for (const plugin of flat)if (plugin?.type === RegisterBuildParamPlugin.type && "function" == typeof plugin.apply) await plugin.apply({
33
+ container
34
+ });
35
+ }
36
+ export { RegisterBuildParamPlugin, RegisterExtensionPlugin, createRegisterBuildParamPlugin, createRegisterExtensionPlugin, registerBuildParams, registerExtensions };
37
+
38
+ //# 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 anything lists the model set. 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): the first\n * request-time listing (e.g. the ACO folder schema) caches the model set for the rest of the\n * request, so any model registered after that point is 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\n/**\n * Registers a BuildParam. A separate type from RegisterExtensionPlugin so the request stack can apply\n * build params BEFORE any feature registers: features gate themselves on FeatureFlags (a BuildParam)\n * at register() time, and would otherwise read an empty flag set. `registerExtensions` skips these.\n */\nexport class RegisterBuildParamPlugin<\n C extends Context = Context\n> extends RegisterExtensionPlugin<C> {\n public static override readonly type: string = \"handler.register.buildParam\";\n}\n\nexport const createRegisterBuildParamPlugin = <C extends Context = Context>(\n cb: IRegisterExtensionPluginCb<C>\n) => {\n return new RegisterBuildParamPlugin<C>(cb);\n};\n\n/**\n * Apply RegisterBuildParamPlugins. Call this before registering any feature that reads BuildParams\n * (e.g. FeatureFlags) at register() time.\n */\nexport async function registerBuildParams(\n container: Container,\n plugins: unknown | unknown[]\n): Promise<void> {\n const flat = [plugins].flat(Infinity as 1).filter(Boolean) as RegisterBuildParamPlugin[];\n for (const plugin of flat) {\n if (plugin?.type === RegisterBuildParamPlugin.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","RegisterBuildParamPlugin","createRegisterBuildParamPlugin","registerBuildParams"],"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,KAAQ,EAAO,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;AAOO,MAAMM,iCAEHZ;;aAC0B,IAAI,GAAW;;AACnD;AAEO,MAAMa,iCAAiC,CAC1CX,KAEO,IAAIU,yBAA4BV;AAOpC,eAAeY,oBAClBR,SAAoB,EACpBC,OAA4B;IAE5B,MAAMC,OAAO;QAACD;KAAQ,CAAC,IAAI,CAACE,KAAQ,EAAO,MAAM,CAACC;IAClD,KAAK,MAAMC,UAAUH,KACjB,IAAIG,QAAQ,SAASC,yBAAyB,IAAI,IAAI,AAAwB,cAAxB,OAAOD,OAAO,KAAK,EACrE,MAAMA,OAAO,KAAK,CAAC;QAAEL;IAAU;AAG3C"}
@@ -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,15 @@
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
+ });
12
+ };
13
+ export { stringifyError };
14
+
15
+ //# sourceMappingURL=stringifyError.js.map
@@ -0,0 +1 @@
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,49 +1,24 @@
1
- import { FastifyInstance, FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
2
- export { FastifyInstance, HTTPMethods } from "fastify";
3
- import { ClientContext } from "@webiny/handler-client/types";
4
- export interface RouteMethodOptions {
5
- 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;
6
12
  }
7
- export declare type RouteMethodPath = `/${string}` | "*";
8
- export interface RouteMethod {
9
- (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;
10
20
  }
11
- export declare type Request = FastifyRequest;
12
- export declare type Reply = FastifyReply;
13
- export declare type DefinedContextRoutes = Record<HTTPMethods, string[]>;
14
- export interface ContextRoutes {
15
- defined: DefinedContextRoutes;
16
- onGet: RouteMethod;
17
- onPost: RouteMethod;
18
- onPut: RouteMethod;
19
- onPatch: RouteMethod;
20
- onDelete: RouteMethod;
21
- onOptions: RouteMethod;
22
- onAll: RouteMethod;
23
- onHead: RouteMethod;
24
- }
25
- 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
- /**
33
- * Current request. Must be set only once!
34
- */
35
- request: FastifyRequest;
36
- /**
37
- * Current reply. Must be set only once!
38
- */
39
- reply: FastifyReply;
40
- /**
41
- * @internal
42
- */
43
- routes: ContextRoutes;
44
- }
45
- declare module "fastify" {
46
- interface FastifyInstance {
47
- webiny: Context;
48
- }
21
+ export interface Context {
22
+ plugins: PluginsContainer;
23
+ container: Container;
49
24
  }
package/types.js CHANGED
@@ -1,19 +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
- Object.defineProperty(exports, "HTTPMethods", {
13
- enumerable: true,
14
- get: function () {
15
- return _fastify.HTTPMethods;
16
- }
17
- });
18
-
19
- var _fastify = require("fastify");
package/Context.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Context as BaseContext, ContextParams as BaseContextParams } from "@webiny/api";
2
- import { Context as BaseContextType } from "./types";
3
- export interface ContextParams extends BaseContextParams {
4
- server: BaseContextType["server"];
5
- routes: BaseContextType["routes"];
6
- }
7
- export declare class Context extends BaseContext implements BaseContextType {
8
- readonly server: BaseContextType["server"];
9
- readonly routes: BaseContextType["routes"];
10
- handlerClient: BaseContextType["handlerClient"];
11
- request: BaseContextType["request"];
12
- reply: BaseContextType["reply"];
13
- constructor(params: ContextParams);
14
- }
package/Context.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.Context = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _api = require("@webiny/api");
13
-
14
- class Context extends _api.Context {
15
- // @ts-ignore
16
- // @ts-ignore
17
- // @ts-ignore
18
- constructor(params) {
19
- super(params);
20
- (0, _defineProperty2.default)(this, "server", void 0);
21
- (0, _defineProperty2.default)(this, "routes", void 0);
22
- (0, _defineProperty2.default)(this, "handlerClient", void 0);
23
- (0, _defineProperty2.default)(this, "request", void 0);
24
- (0, _defineProperty2.default)(this, "reply", void 0);
25
- this.server = params.server;
26
- this.routes = params.routes;
27
- }
28
-
29
- }
30
-
31
- exports.Context = Context;
package/Context.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["Context","BaseContext","constructor","params","server","routes"],"sources":["Context.ts"],"sourcesContent":["import { Context as BaseContext, ContextParams as BaseContextParams } from \"@webiny/api\";\nimport { Context as BaseContextType } from \"~/types\";\n\nexport interface ContextParams extends BaseContextParams {\n server: BaseContextType[\"server\"];\n routes: BaseContextType[\"routes\"];\n}\n\nexport class Context extends BaseContext implements BaseContextType {\n public readonly server: BaseContextType[\"server\"];\n public readonly routes: BaseContextType[\"routes\"];\n // @ts-ignore\n public handlerClient: BaseContextType[\"handlerClient\"];\n // @ts-ignore\n public request: BaseContextType[\"request\"];\n // @ts-ignore\n public reply: BaseContextType[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.server = params.server;\n this.routes = params.routes;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAQO,MAAMA,OAAN,SAAsBC,YAAtB,CAA6D;EAGhE;EAEA;EAEA;EAGOC,WAAW,CAACC,MAAD,EAAwB;IACtC,MAAMA,MAAN;IADsC;IAAA;IAAA;IAAA;IAAA;IAEtC,KAAKC,MAAL,GAAcD,MAAM,CAACC,MAArB;IACA,KAAKC,MAAL,GAAcF,MAAM,CAACE,MAArB;EACH;;AAd+D"}
package/fastify.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import { PluginCollection } from "@webiny/plugins/types";
3
- import { FastifyServerOptions as ServerOptions } from "fastify";
4
- export interface CreateHandlerParams {
5
- plugins: PluginCollection;
6
- options?: ServerOptions;
7
- }
8
- export declare const createHandler: (params: CreateHandlerParams) => import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;