@webiny/handler 0.0.0-unstable.3c5210ad37 → 0.0.0-unstable.3fddf667ea
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.
- package/ResponseHeaders.js +29 -32
- package/ResponseHeaders.js.map +1 -1
- package/abstractions/Reply.js +2 -1
- package/abstractions/Reply.js.map +1 -1
- package/abstractions/Request.js +2 -1
- package/abstractions/Request.js.map +1 -1
- package/exports/api.d.ts +0 -0
- package/exports/api.js +0 -0
- package/index.d.ts +4 -15
- package/index.js +3 -18
- package/package.json +16 -17
- package/plugins/RegisterExtensionPlugin.d.ts +36 -0
- package/plugins/RegisterExtensionPlugin.js +38 -0
- package/plugins/RegisterExtensionPlugin.js.map +1 -0
- package/stringifyError.js +12 -17
- package/stringifyError.js.map +1 -1
- package/types.d.ts +21 -43
- package/types.js +0 -3
- package/Context.d.ts +0 -22
- package/Context.js +0 -26
- package/Context.js.map +0 -1
- package/PreHandler/IPreHandler.d.ts +0 -9
- package/PreHandler/IPreHandler.js +0 -7
- package/PreHandler/IPreHandler.js.map +0 -1
- package/PreHandler/IfNotOptionsRequest.d.ts +0 -9
- package/PreHandler/IfNotOptionsRequest.js +0 -21
- package/PreHandler/IfNotOptionsRequest.js.map +0 -1
- package/PreHandler/IfOptionsRequest.d.ts +0 -9
- package/PreHandler/IfOptionsRequest.js +0 -21
- package/PreHandler/IfOptionsRequest.js.map +0 -1
- package/PreHandler/PreHandler.d.ts +0 -9
- package/PreHandler/PreHandler.js +0 -17
- package/PreHandler/PreHandler.js.map +0 -1
- package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +0 -10
- package/PreHandler/ProcessBeforeHandlerPlugins.js +0 -24
- package/PreHandler/ProcessBeforeHandlerPlugins.js.map +0 -1
- package/PreHandler/ProcessContextPlugins.d.ts +0 -10
- package/PreHandler/ProcessContextPlugins.js +0 -24
- package/PreHandler/ProcessContextPlugins.js.map +0 -1
- package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +0 -10
- package/PreHandler/ProcessHandlerOnRequestPlugins.js +0 -26
- package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +0 -1
- package/PreHandler/SendEarlyOptionsResponse.d.ts +0 -9
- package/PreHandler/SendEarlyOptionsResponse.js +0 -31
- package/PreHandler/SendEarlyOptionsResponse.js.map +0 -1
- package/PreHandler/SetDefaultHeaders.d.ts +0 -9
- package/PreHandler/SetDefaultHeaders.js +0 -57
- package/PreHandler/SetDefaultHeaders.js.map +0 -1
- package/fastify.d.ts +0 -11
- package/fastify.js +0 -443
- package/fastify.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/BeforeHandlerPlugin.d.ts +0 -12
- package/plugins/BeforeHandlerPlugin.js +0 -19
- package/plugins/BeforeHandlerPlugin.js.map +0 -1
- package/plugins/EventPlugin.d.ts +0 -25
- package/plugins/EventPlugin.js +0 -21
- package/plugins/EventPlugin.js.map +0 -1
- package/plugins/HandlerErrorPlugin.d.ts +0 -15
- package/plugins/HandlerErrorPlugin.js +0 -16
- package/plugins/HandlerErrorPlugin.js.map +0 -1
- package/plugins/HandlerOnRequestPlugin.d.ts +0 -21
- package/plugins/HandlerOnRequestPlugin.js +0 -24
- package/plugins/HandlerOnRequestPlugin.js.map +0 -1
- package/plugins/HandlerResultPlugin.d.ts +0 -12
- package/plugins/HandlerResultPlugin.js +0 -16
- package/plugins/HandlerResultPlugin.js.map +0 -1
- package/plugins/ModifyFastifyPlugin.d.ts +0 -13
- package/plugins/ModifyFastifyPlugin.js +0 -16
- package/plugins/ModifyFastifyPlugin.js.map +0 -1
- package/plugins/ModifyResponseHeadersPlugin.d.ts +0 -14
- package/plugins/ModifyResponseHeadersPlugin.js +0 -16
- package/plugins/ModifyResponseHeadersPlugin.js.map +0 -1
- package/plugins/OnRequestResponseSendPlugin.d.ts +0 -26
- package/plugins/OnRequestResponseSendPlugin.js +0 -31
- package/plugins/OnRequestResponseSendPlugin.js.map +0 -1
- package/plugins/OnRequestTimeoutPlugin.d.ts +0 -12
- package/plugins/OnRequestTimeoutPlugin.js +0 -16
- package/plugins/OnRequestTimeoutPlugin.js.map +0 -1
- package/plugins/RoutePlugin.d.ts +0 -23
- package/plugins/RoutePlugin.js +0 -13
- package/plugins/RoutePlugin.js.map +0 -1
- package/suppressPunycodeWarnings.d.ts +0 -1
- package/suppressPunycodeWarnings.js +0 -10
- package/suppressPunycodeWarnings.js.map +0 -1
- package/types.js.map +0 -1
package/ResponseHeaders.js
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
// Extract known standard headers, and remove all non-string keys.
|
|
2
|
-
|
|
3
1
|
function isFunction(setter) {
|
|
4
|
-
|
|
2
|
+
return "function" == typeof setter;
|
|
5
3
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
package/ResponseHeaders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
package/abstractions/Reply.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
package/abstractions/Request.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
package/exports/api.d.ts
ADDED
|
File without changes
|
package/exports/api.js
ADDED
|
File without changes
|
package/index.d.ts
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export * from "./Context.js";
|
|
4
|
-
export * from "./ResponseHeaders.js";
|
|
5
|
-
export * from "./plugins/EventPlugin.js";
|
|
6
|
-
export * from "./plugins/RoutePlugin.js";
|
|
7
|
-
export * from "./plugins/BeforeHandlerPlugin.js";
|
|
8
|
-
export * from "./plugins/HandlerErrorPlugin.js";
|
|
9
|
-
export * from "./plugins/HandlerResultPlugin.js";
|
|
10
|
-
export * from "./plugins/HandlerOnRequestPlugin.js";
|
|
11
|
-
export * from "./plugins/ModifyFastifyPlugin.js";
|
|
12
|
-
export * from "./plugins/ModifyResponseHeadersPlugin.js";
|
|
13
|
-
export * from "./plugins/OnRequestResponseSendPlugin.js";
|
|
14
|
-
export * from "./plugins/OnRequestTimeoutPlugin.js";
|
|
15
|
-
export * from "./ResponseHeaders.js";
|
|
1
|
+
export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions, RegisterBuildParamPlugin, createRegisterBuildParamPlugin, registerBuildParams } from "./plugins/RegisterExtensionPlugin.js";
|
|
2
|
+
export { stringifyError } from "./stringifyError.js";
|
|
16
3
|
export { Request } from "./abstractions/Request.js";
|
|
17
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,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export * from "./fastify.js";
|
|
4
|
-
export * from "./Context.js";
|
|
5
|
-
export * from "./ResponseHeaders.js";
|
|
6
|
-
export * from "./plugins/EventPlugin.js";
|
|
7
|
-
export * from "./plugins/RoutePlugin.js";
|
|
8
|
-
export * from "./plugins/BeforeHandlerPlugin.js";
|
|
9
|
-
export * from "./plugins/HandlerErrorPlugin.js";
|
|
10
|
-
export * from "./plugins/HandlerResultPlugin.js";
|
|
11
|
-
export * from "./plugins/HandlerOnRequestPlugin.js";
|
|
12
|
-
export * from "./plugins/ModifyFastifyPlugin.js";
|
|
13
|
-
export * from "./plugins/ModifyResponseHeadersPlugin.js";
|
|
14
|
-
export * from "./plugins/OnRequestResponseSendPlugin.js";
|
|
15
|
-
export * from "./plugins/OnRequestTimeoutPlugin.js";
|
|
16
|
-
export * from "./ResponseHeaders.js";
|
|
1
|
+
export { RegisterBuildParamPlugin, RegisterExtensionPlugin, createRegisterBuildParamPlugin, createRegisterExtensionPlugin, registerBuildParams, registerExtensions } from "./plugins/RegisterExtensionPlugin.js";
|
|
2
|
+
export { stringifyError } from "./stringifyError.js";
|
|
17
3
|
export { Request } from "./abstractions/Request.js";
|
|
18
4
|
export { Reply } from "./abstractions/Reply.js";
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
5
|
+
export { ResponseHeaders } from "./ResponseHeaders.js";
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.3fddf667ea",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -13,25 +16,21 @@
|
|
|
13
16
|
],
|
|
14
17
|
"license": "MIT",
|
|
15
18
|
"dependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"@webiny/
|
|
19
|
-
"@webiny/error": "0.0.0-unstable.3c5210ad37",
|
|
20
|
-
"@webiny/feature": "0.0.0-unstable.3c5210ad37",
|
|
21
|
-
"@webiny/handler-client": "0.0.0-unstable.3c5210ad37",
|
|
22
|
-
"@webiny/plugins": "0.0.0-unstable.3c5210ad37",
|
|
23
|
-
"@webiny/utils": "0.0.0-unstable.3c5210ad37",
|
|
24
|
-
"fastify": "5.7.4"
|
|
19
|
+
"@webiny/di": "2.0.0",
|
|
20
|
+
"@webiny/feature": "0.0.0-unstable.3fddf667ea",
|
|
21
|
+
"@webiny/plugins": "0.0.0-unstable.3fddf667ea"
|
|
25
22
|
},
|
|
26
23
|
"devDependencies": {
|
|
27
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
24
|
+
"@webiny/build-tools": "0.0.0-unstable.3fddf667ea",
|
|
28
25
|
"rimraf": "6.1.3",
|
|
29
|
-
"typescript": "
|
|
30
|
-
"vitest": "
|
|
26
|
+
"typescript": "7.0.2",
|
|
27
|
+
"vitest": "5.0.5"
|
|
31
28
|
},
|
|
32
29
|
"publishConfig": {
|
|
33
|
-
"access": "public"
|
|
34
|
-
"directory": "dist"
|
|
30
|
+
"access": "public"
|
|
35
31
|
},
|
|
36
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
33
|
+
"webiny": {
|
|
34
|
+
"publishFrom": "dist"
|
|
35
|
+
}
|
|
37
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"}
|
package/stringifyError.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
name: name || "No error name",
|
|
13
|
-
message: message || "No error message",
|
|
14
|
-
code: code || "NO_CODE",
|
|
15
|
-
data,
|
|
16
|
-
stack: process.env.DEBUG === "true" ? stack : "Turn on the debug flag to see the stack."
|
|
17
|
-
});
|
|
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
|
+
});
|
|
18
12
|
};
|
|
13
|
+
export { stringifyError };
|
|
19
14
|
|
|
20
15
|
//# sourceMappingURL=stringifyError.js.map
|
package/stringifyError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 "@
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
9
|
-
|
|
10
|
-
(
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
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
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.js";
|
|
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>;
|
package/Context.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Context as BaseContext, ContextPlugin as BaseContextPlugin, createContextPlugin as baseCreateContextPlugin } from "@webiny/api";
|
|
2
|
-
export class Context extends BaseContext {
|
|
3
|
-
// @ts-expect-error
|
|
4
|
-
|
|
5
|
-
// @ts-expect-error
|
|
6
|
-
|
|
7
|
-
// @ts-expect-error
|
|
8
|
-
|
|
9
|
-
constructor(params) {
|
|
10
|
-
super(params);
|
|
11
|
-
this.routes = params.routes;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
|
|
17
|
-
*
|
|
18
|
-
* This can be removed when we introduce the type augmentation.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
export class ContextPlugin extends BaseContextPlugin {}
|
|
22
|
-
export const createContextPlugin = callable => {
|
|
23
|
-
return baseCreateContextPlugin(callable);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=Context.js.map
|
package/Context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Context","BaseContext","ContextPlugin","BaseContextPlugin","createContextPlugin","baseCreateContextPlugin","constructor","params","routes","callable"],"sources":["Context.ts"],"sourcesContent":["import type {\n ContextParams as BaseContextParams,\n ContextPluginCallable as BaseContextPluginCallable\n} from \"@webiny/api\";\nimport {\n Context as BaseContext,\n ContextPlugin as BaseContextPlugin,\n createContextPlugin as baseCreateContextPlugin\n} from \"@webiny/api\";\nimport type { Context as ContextInterface } from \"~/types.js\";\n\nexport interface ContextParams extends BaseContextParams {\n routes: ContextInterface[\"routes\"];\n}\n\nexport class Context extends BaseContext implements ContextInterface {\n public readonly routes: ContextInterface[\"routes\"];\n // @ts-expect-error\n public handlerClient: ContextInterface[\"handlerClient\"];\n // @ts-expect-error\n public request: ContextInterface[\"request\"];\n // @ts-expect-error\n public reply: ContextInterface[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.routes = params.routes;\n }\n}\n\n/**\n * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.\n *\n * This can be removed when we introduce the type augmentation.\n */\nexport type ContextPluginCallable<T extends ContextInterface = ContextInterface> =\n BaseContextPluginCallable<T>;\n\nexport class ContextPlugin<\n T extends ContextInterface = ContextInterface\n> extends BaseContextPlugin<T> {}\n\nexport const createContextPlugin = <T extends ContextInterface = ContextInterface>(\n callable: ContextPluginCallable<T>\n) => {\n return baseCreateContextPlugin<T>(callable);\n};\n"],"mappings":"AAIA,SACIA,OAAO,IAAIC,WAAW,EACtBC,aAAa,IAAIC,iBAAiB,EAClCC,mBAAmB,IAAIC,uBAAuB,QAC3C,aAAa;AAOpB,OAAO,MAAML,OAAO,SAASC,WAAW,CAA6B;EAEjE;;EAEA;;EAEA;;EAGOK,WAAWA,CAACC,MAAqB,EAAE;IACtC,KAAK,CAACA,MAAM,CAAC;IACb,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;AACJ;;AAEA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAMN,aAAa,SAEhBC,iBAAiB,CAAI;AAE/B,OAAO,MAAMC,mBAAmB,GAC5BK,QAAkC,IACjC;EACD,OAAOJ,uBAAuB,CAAII,QAAQ,CAAC;AAC/C,CAAC","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
-
import type { Context } from "../types.js";
|
|
3
|
-
export declare enum Action {
|
|
4
|
-
CONTINUE = "continue",
|
|
5
|
-
DONE = "done"
|
|
6
|
-
}
|
|
7
|
-
export interface IPreHandler {
|
|
8
|
-
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> | Action;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Action"],"sources":["IPreHandler.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { Context } from \"~/types.js\";\n\nexport enum Action {\n CONTINUE = \"continue\",\n DONE = \"done\"\n}\n\nexport interface IPreHandler {\n execute(\n request: FastifyRequest,\n reply: FastifyReply,\n context: Context\n ): Promise<Action> | Action;\n}\n"],"mappings":"AAGA,WAAYA,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
-
import type { IPreHandler } from "./IPreHandler.js";
|
|
3
|
-
import { Action } from "./IPreHandler.js";
|
|
4
|
-
import type { Context } from "../types.js";
|
|
5
|
-
export declare class IfNotOptionsRequest implements IPreHandler {
|
|
6
|
-
private readonly handlers;
|
|
7
|
-
constructor(handlers: IPreHandler[]);
|
|
8
|
-
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Action } from "./IPreHandler.js";
|
|
2
|
-
export class IfNotOptionsRequest {
|
|
3
|
-
constructor(handlers) {
|
|
4
|
-
this.handlers = handlers;
|
|
5
|
-
}
|
|
6
|
-
async execute(request, reply, context) {
|
|
7
|
-
const isOptionsRequest = request.method === "OPTIONS";
|
|
8
|
-
if (isOptionsRequest) {
|
|
9
|
-
return Action.CONTINUE;
|
|
10
|
-
}
|
|
11
|
-
for (const handler of this.handlers) {
|
|
12
|
-
const action = await handler.execute(request, reply, context);
|
|
13
|
-
if (action === Action.DONE) {
|
|
14
|
-
return Action.DONE;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return Action.CONTINUE;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=IfNotOptionsRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Action","IfNotOptionsRequest","constructor","handlers","execute","request","reply","context","isOptionsRequest","method","CONTINUE","handler","action","DONE"],"sources":["IfNotOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class IfNotOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAGf,OAAO,MAAMC,mBAAmB,CAAwB;EAGpDC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;IAC3F,MAAMC,gBAAgB,GAAGH,OAAO,CAACI,MAAM,KAAK,SAAS;IACrD,IAAID,gBAAgB,EAAE;MAClB,OAAOR,MAAM,CAACU,QAAQ;IAC1B;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACR,QAAQ,EAAE;MACjC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACP,OAAO,CAACC,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;MAC7D,IAAIK,MAAM,KAAKZ,MAAM,CAACa,IAAI,EAAE;QACxB,OAAOb,MAAM,CAACa,IAAI;MACtB;IACJ;IAEA,OAAOb,MAAM,CAACU,QAAQ;EAC1B;AACJ","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
-
import type { IPreHandler } from "./IPreHandler.js";
|
|
3
|
-
import { Action } from "./IPreHandler.js";
|
|
4
|
-
import type { Context } from "../types.js";
|
|
5
|
-
export declare class IfOptionsRequest implements IPreHandler {
|
|
6
|
-
private readonly handlers;
|
|
7
|
-
constructor(handlers: IPreHandler[]);
|
|
8
|
-
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Action } from "./IPreHandler.js";
|
|
2
|
-
export class IfOptionsRequest {
|
|
3
|
-
constructor(handlers) {
|
|
4
|
-
this.handlers = handlers;
|
|
5
|
-
}
|
|
6
|
-
async execute(request, reply, context) {
|
|
7
|
-
const isOptionsRequest = request.method === "OPTIONS";
|
|
8
|
-
if (!isOptionsRequest) {
|
|
9
|
-
return Action.CONTINUE;
|
|
10
|
-
}
|
|
11
|
-
for (const handler of this.handlers) {
|
|
12
|
-
const action = await handler.execute(request, reply, context);
|
|
13
|
-
if (action === Action.DONE) {
|
|
14
|
-
return Action.DONE;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return Action.CONTINUE;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=IfOptionsRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Action","IfOptionsRequest","constructor","handlers","execute","request","reply","context","isOptionsRequest","method","CONTINUE","handler","action","DONE"],"sources":["IfOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class IfOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (!isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAGf,OAAO,MAAMC,gBAAgB,CAAwB;EAGjDC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;IAC3F,MAAMC,gBAAgB,GAAGH,OAAO,CAACI,MAAM,KAAK,SAAS;IACrD,IAAI,CAACD,gBAAgB,EAAE;MACnB,OAAOR,MAAM,CAACU,QAAQ;IAC1B;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACR,QAAQ,EAAE;MACjC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACP,OAAO,CAACC,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;MAC7D,IAAIK,MAAM,KAAKZ,MAAM,CAACa,IAAI,EAAE;QACxB,OAAOb,MAAM,CAACa,IAAI;MACtB;IACJ;IAEA,OAAOb,MAAM,CAACU,QAAQ;EAC1B;AACJ","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
-
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
3
|
-
import { Action } from "../PreHandler/IPreHandler.js";
|
|
4
|
-
import type { Context } from "../types.js";
|
|
5
|
-
export declare class PreHandler implements IPreHandler {
|
|
6
|
-
private readonly handlers;
|
|
7
|
-
constructor(handlers: IPreHandler[]);
|
|
8
|
-
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
9
|
-
}
|
package/PreHandler/PreHandler.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Action } from "./IPreHandler.js";
|
|
2
|
-
export class PreHandler {
|
|
3
|
-
constructor(handlers) {
|
|
4
|
-
this.handlers = handlers;
|
|
5
|
-
}
|
|
6
|
-
async execute(request, reply, context) {
|
|
7
|
-
for (const handler of this.handlers) {
|
|
8
|
-
const action = await handler.execute(request, reply, context);
|
|
9
|
-
if (action === Action.DONE) {
|
|
10
|
-
return Action.DONE;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return Action.CONTINUE;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=PreHandler.js.map
|