@webiny/handler 5.27.0 → 5.28.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createHandler.js.map +1 -1
- package/index.js.map +1 -1
- package/middleware.js.map +1 -1
- package/package.json +6 -6
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/Context.js.map +1 -1
- package/plugins/ContextPlugin.js.map +1 -1
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/types.js.map +1 -1
package/createHandler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["plugins","args","context","Context","WEBINY_VERSION","process","env","result","handle","handlerPlugins","byType","HandlerResultPlugin","type","i","length","contextPlugins","ContextPlugin","apply","hasResult","getResult","beforeHandlerPlugins","BeforeHandlerPlugin","handlers","HandlerPlugin","handler","middleware","map","pl","next","Error","error","console","log","HandlerErrorPlugin"],"sources":["createHandler.ts"],"sourcesContent":["import middleware from \"./middleware\";\nimport { HandlerPlugin } from \"~/plugins/HandlerPlugin\";\nimport { ContextPlugin } from \"~/plugins/ContextPlugin\";\nimport { BeforeHandlerPlugin } from \"~/plugins/BeforeHandlerPlugin\";\nimport { Context } from \"~/plugins/Context\";\nimport { HandlerErrorPlugin } from \"~/plugins/HandlerErrorPlugin\";\nimport { HandlerResultPlugin } from \"~/plugins/HandlerResultPlugin\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\n\nexport default (...plugins: PluginCollection) =>\n async (...args: string[]) => {\n const context = new Context({\n plugins,\n args,\n /**\n * Inserted via webpack on build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string\n });\n\n const result = await handle(context);\n\n const handlerPlugins = context.plugins.byType<HandlerResultPlugin>(\n HandlerResultPlugin.type\n );\n for (let i = 0; i < handlerPlugins.length; i++) {\n if (!handlerPlugins[i].handle) {\n continue;\n }\n await handlerPlugins[i].handle(context, result);\n }\n\n return result;\n };\n\nasync function handle(context: Context) {\n try {\n const contextPlugins = context.plugins.byType<ContextPlugin>(ContextPlugin.type);\n for (let i = 0; i < contextPlugins.length; i++) {\n if (!contextPlugins[i].apply) {\n continue;\n }\n await contextPlugins[i].apply(context);\n if (context.hasResult()) {\n return context.getResult();\n }\n }\n\n const beforeHandlerPlugins = context.plugins.byType<BeforeHandlerPlugin>(\n BeforeHandlerPlugin.type\n );\n for (let i = 0; i < beforeHandlerPlugins.length; i++) {\n if (!beforeHandlerPlugins[i].apply) {\n continue;\n }\n await beforeHandlerPlugins[i].apply(context);\n if (context.hasResult()) {\n return context.getResult();\n }\n }\n\n const handlers = context.plugins.byType<HandlerPlugin>(HandlerPlugin.type);\n const handler = middleware(\n handlers.map(pl => {\n return (context: Context, next: Function) => {\n return pl.handle(context, next);\n };\n })\n );\n const result = await handler(context);\n if (!result) {\n throw new Error(`No result was returned from registered handlers.`);\n }\n\n return result;\n } catch (error) {\n // Log error to cloud, as these can be extremely annoying to debug!\n console.log(\"@webiny/handler\");\n console.log(error);\n const handlers = context.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n const handler = middleware(\n handlers.map(pl => {\n return (context: Context, error: Error, next: Function) => {\n return pl.handle(context, error, next);\n };\n })\n );\n return handler(context, error);\n }\n}\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;eAGe,CAAC,GAAGA,OAAJ,KACX,OAAO,GAAGC,IAAV,KAA6B;EACzB,MAAMC,OAAO,GAAG,IAAIC,gBAAJ,CAAY;IACxBH,OADwB;IAExBC,IAFwB;;IAGxB;AACZ;AACA;IACYG,cAAc,EAAEC,OAAO,CAACC,GAAR,CAAYF;EANJ,CAAZ,CAAhB;EASA,MAAMG,MAAM,GAAG,MAAMC,MAAM,CAACN,OAAD,CAA3B;EAEA,MAAMO,cAAc,GAAGP,OAAO,CAACF,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
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as createHandler } from \"~/createHandler\";\nexport * from \"~/plugins/ContextPlugin\";\nexport * from \"~/plugins/Context\";\nexport * from \"~/plugins/HandlerPlugin\";\nexport * from \"~/plugins/HandlerErrorPlugin\";\nexport * from \"~/plugins/HandlerResultPlugin\";\nexport * from \"~/plugins/BeforeHandlerPlugin\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"sources":["middleware.ts"],"sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport default (functions: Array<Function> = []): Function => {\n return (...args: string[]): Promise<any> => {\n if (!functions.length) {\n return Promise.resolve();\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n const chain = [...functions];\n return new Promise((parentResolve: any, parentReject) => {\n const next = async (): Promise<any> => {\n const fn = chain.shift();\n if (!fn) {\n return Promise.resolve();\n }\n\n return new Promise(async (resolve, reject) => {\n try {\n const result = await fn(...args, resolve);\n if (typeof result !== \"undefined\") {\n return parentResolve(result);\n }\n } catch (e) {\n reject(e);\n }\n })\n .then(() => {\n return next();\n })\n .then(() => {\n parentResolve(...args);\n })\n .catch(e => {\n parentReject(e);\n });\n };\n\n return next();\n });\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;eACe,CAACA,SAA0B,GAAG,EAA9B,KAA+C;EAC1D,OAAO,CAAC,GAAGC,IAAJ,KAAqC;IACxC,IAAI,CAACD,SAAS,CAACE,MAAf,EAAuB;MACnB,OAAOC,OAAO,CAACC,OAAR,EAAP;IACH,CAHuC,CAKxC;;;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAJ,CAAd;IACA,OAAO,IAAIG,OAAJ,CAAY,CAACG,aAAD,EAAqBC,YAArB,KAAsC;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAN,EAAX;;QACA,IAAI,CAACD,EAAL,EAAS;UACL,OAAON,OAAO,CAACC,OAAR,EAAP;QACH;;QAED,OAAO,IAAID,OAAJ,CAAY,OAAOC,OAAP,EAAgBO,MAAhB,KAA2B;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAJ,EAAUG,OAAV,CAAvB;;YACA,IAAI,OAAOQ,MAAP,KAAkB,WAAtB,EAAmC;cAC/B,OAAON,aAAa,CAACM,MAAD,CAApB;YACH;UACJ,CALD,CAKE,OAAOC,CAAP,EAAU;YACRF,MAAM,CAACE,CAAD,CAAN;UACH;QACJ,CATM,EAUFC,IAVE,CAUG,MAAM;UACR,OAAON,IAAI,EAAX;QACH,CAZE,EAaFM,IAbE,CAaG,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAJ,CAAb;QACH,CAfE,EAgBFc,KAhBE,CAgBIF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAD,CAAZ;QACH,CAlBE,CAAP;MAmBH,CAzBD;;MA2BA,OAAOL,IAAI,EAAX;IACH,CA7BM,CAAP;EA8BH,CArCD;AAsCH,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.28.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "7.
|
|
18
|
-
"@webiny/plugins": "5.
|
|
17
|
+
"@babel/runtime": "7.18.3",
|
|
18
|
+
"@webiny/plugins": "5.28.0-beta.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@babel/cli": "^7.16.0",
|
|
22
22
|
"@babel/core": "^7.16.0",
|
|
23
23
|
"@babel/preset-env": "^7.16.4",
|
|
24
|
-
"@webiny/cli": "^5.
|
|
25
|
-
"@webiny/project-utils": "^5.
|
|
24
|
+
"@webiny/cli": "^5.28.0-beta.0",
|
|
25
|
+
"@webiny/project-utils": "^5.28.0-beta.0",
|
|
26
26
|
"rimraf": "^3.0.2",
|
|
27
27
|
"ttypescript": "^1.5.13",
|
|
28
28
|
"typescript": "4.5.5"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"build": "yarn webiny run build",
|
|
36
36
|
"watch": "yarn webiny run watch"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6503c7f86cfc90660f005acf72049505bfd4fb76"
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAIzEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,6IADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB"}
|
package/plugins/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["Context","constructor","params","plugins","args","WEBINY_VERSION","PluginsContainer","getResult","_result","hasResult","setResult","value","waitFor","obj","cb","initialTargets","Array","isArray","targets","key","target","Object","defineProperty","set","newTargetKey","waiter","waiters","includes","filter","t","length","get","configurable","push"],"sources":["Context.ts"],"sourcesContent":["import { Context as ContextInterface, HandlerArgs } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\n\ninterface Waiter {\n targets: string[];\n cb: (context: ContextInterface) => void;\n}\n\nexport interface ContextParams {\n args?: HandlerArgs;\n plugins?: PluginCollection;\n WEBINY_VERSION: string;\n}\nexport class Context implements ContextInterface {\n public _result: any;\n public readonly plugins: PluginsContainer;\n public readonly args: HandlerArgs;\n public readonly WEBINY_VERSION: string;\n\n private readonly waiters: Waiter[] = [];\n\n public constructor(params: ContextParams) {\n const { plugins, args, WEBINY_VERSION } = params;\n this.plugins = new PluginsContainer(plugins || []);\n this.args = args || [];\n this.WEBINY_VERSION = WEBINY_VERSION;\n }\n\n public getResult(): any {\n return this._result;\n }\n\n public hasResult(): boolean {\n return !!this._result;\n }\n\n public setResult(value: any): void {\n this._result = value;\n }\n\n public waitFor<T extends ContextInterface = ContextInterface>(\n obj: string | string[],\n cb: (context: T) => void\n ): void {\n const initialTargets = Array.isArray(obj) ? obj : [obj];\n const targets: string[] = [];\n /**\n * We go only through the first level properties\n */\n for (const key in initialTargets) {\n const target = initialTargets[key] as keyof this;\n /**\n * If property already exists, there is no need to wait for it, so we just continue the loop.\n */\n if (this[target]) {\n continue;\n }\n /**\n * Since there is no property, we must define it with its setter and getter.\n * We could not know when it got defined otherwise.\n */\n Object.defineProperty(this, target, {\n /**\n * Setter sets the given value to this object.\n * We cannot set it on exact property name it is defined because it would go into loop of setting itself.\n * And that is why we add __ around the property name.\n */\n set: (value: any) => {\n const newTargetKey = `__${target}__` as keyof this;\n this[newTargetKey] = value;\n /**\n * WWhen the property is set, we will go through all the waiters and, if any of them include currently set property, act on it.\n */\n for (const waiter of this.waiters) {\n if (waiter.targets.includes(target as string) === false) {\n continue;\n }\n /**\n * Remove currently set property so we know if there are any more to be waited for.\n */\n waiter.targets = waiter.targets.filter(t => t !== target);\n /**\n * If there are more to be waited, eg. user added [cms, pageBuilder] as waited properties, we just continue the loop.\n */\n if (waiter.targets.length > 0) {\n continue;\n }\n /**\n * And if there is nothing more to be waited for, we execute the callable.\n * Note that this callable is not async.\n */\n waiter.cb(this);\n }\n },\n /**\n * As we have set property with __ around it, we must get it as well.\n */\n get: (): any => {\n const newTargetKey = `__${target}__` as keyof this;\n return this[newTargetKey];\n },\n configurable: false\n });\n /**\n * We add the target to be awaited.\n */\n targets.push(target as string);\n }\n /**\n * If there are no targets to be awaited, just fire the callable.\n */\n if (targets.length === 0) {\n cb(this as any);\n return;\n }\n /**\n * Otherwise add the waiter for the target properties.\n */\n this.waiters.push({\n targets,\n /**\n * TODO @ts-refactor\n * Problem with possible subtype initialization\n */\n // @ts-ignore\n cb\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;;AAaO,MAAMA,OAAN,CAA0C;EAQtCC,WAAW,CAACC,MAAD,EAAwB;IAAA;IAAA;IAAA;IAAA;IAAA,+CAFL,EAEK;IACtC,MAAM;MAAEC,OAAF;MAAWC,IAAX;MAAiBC;IAAjB,IAAoCH,MAA1C;IACA,KAAKC,OAAL,GAAe,IAAIG,yBAAJ,CAAqBH,OAAO,IAAI,EAAhC,CAAf;IACA,KAAKC,IAAL,GAAYA,IAAI,IAAI,EAApB;IACA,KAAKC,cAAL,GAAsBA,cAAtB;EACH;;EAEME,SAAS,GAAQ;IACpB,OAAO,KAAKC,OAAZ;EACH;;EAEMC,SAAS,GAAY;IACxB,OAAO,CAAC,CAAC,KAAKD,OAAd;EACH;;EAEME,SAAS,CAACC,KAAD,EAAmB;IAC/B,KAAKH,OAAL,GAAeG,KAAf;EACH;;EAEMC,OAAO,CACVC,GADU,EAEVC,EAFU,EAGN;IACJ,MAAMC,cAAc,GAAGC,KAAK,CAACC,OAAN,CAAcJ,GAAd,IAAqBA,GAArB,GAA2B,CAACA,GAAD,CAAlD;IACA,MAAMK,OAAiB,GAAG,EAA1B;IACA;AACR;AACA;;IACQ,KAAK,MAAMC,GAAX,IAAkBJ,cAAlB,EAAkC;MAC9B,MAAMK,MAAM,GAAGL,cAAc,CAACI,GAAD,CAA7B;MACA;AACZ;AACA;;MACY,IAAI,KAAKC,MAAL,CAAJ,EAAkB;QACd;MACH;MACD;AACZ;AACA;AACA;;;MACYC,MAAM,CAACC,cAAP,CAAsB,IAAtB,EAA4BF,MAA5B,EAAoC;QAChC;AAChB;AACA;AACA;AACA;QACgBG,GAAG,EAAGZ,KAAD,IAAgB;UACjB,MAAMa,YAAY,GAAI,KAAIJ,MAAO,IAAjC;UACA,KAAKI,YAAL,IAAqBb,KAArB;UACA;AACpB;AACA;;UACoB,KAAK,MAAMc,MAAX,IAAqB,KAAKC,OAA1B,EAAmC;YAC/B,IAAID,MAAM,CAACP,OAAP,CAAeS,QAAf,CAAwBP,MAAxB,MAA8C,KAAlD,EAAyD;cACrD;YACH;YACD;AACxB;AACA;;;YACwBK,MAAM,CAACP,OAAP,GAAiBO,MAAM,CAACP,OAAP,CAAeU,MAAf,CAAsBC,CAAC,IAAIA,CAAC,KAAKT,MAAjC,CAAjB;YACA;AACxB;AACA;;YACwB,IAAIK,MAAM,CAACP,OAAP,CAAeY,MAAf,GAAwB,CAA5B,EAA+B;cAC3B;YACH;YACD;AACxB;AACA;AACA;;;YACwBL,MAAM,CAACX,EAAP,CAAU,IAAV;UACH;QACJ,CAhC+B;;QAiChC;AAChB;AACA;QACgBiB,GAAG,EAAE,MAAW;UACZ,MAAMP,YAAY,GAAI,KAAIJ,MAAO,IAAjC;UACA,OAAO,KAAKI,YAAL,CAAP;QACH,CAvC+B;QAwChCQ,YAAY,EAAE;MAxCkB,CAApC;MA0CA;AACZ;AACA;;MACYd,OAAO,CAACe,IAAR,CAAab,MAAb;IACH;IACD;AACR;AACA;;;IACQ,IAAIF,OAAO,CAACY,MAAR,KAAmB,CAAvB,EAA0B;MACtBhB,EAAE,CAAC,IAAD,CAAF;MACA;IACH;IACD;AACR;AACA;;;IACQ,KAAKY,OAAL,CAAaO,IAAb,CAAkB;MACdf,OADc;;MAEd;AACZ;AACA;AACA;MACY;MACAJ;IAPc,CAAlB;EASH;;AAlH4C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["ContextPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"sources":["ContextPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface ContextPluginCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class ContextPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"context\";\n private readonly _callable: ContextPluginCallable<T>;\n\n constructor(callable: ContextPluginCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in ContextPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,aAAN,SAAyDC,eAAzD,CAAgE;EAInEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,uIADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBkE;;;8BAA1DN,a,UACsC,S"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;EAKjEC,WAAW,CAACC,QAAD,EAAoC;IAClD;IADkD;IAElD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;IACxE,OAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;EACH;;AAZuE;;;8BAA/DR,kB,UACsC,e"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["HandlerPlugin","Plugin","constructor","callable","_callable","handle","context","next"],"sources":["HandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerCallable<T extends Context = Context> {\n (context: T, next: Function): Promise<any>;\n}\n\nexport class HandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler\";\n\n private readonly _callable: HandlerCallable<T>;\n\n public constructor(callable: HandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, next: Function): Promise<any> {\n return this._callable(context, next);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,aAAN,SAAyDC,eAAzD,CAAgE;EAK5DC,WAAW,CAACC,QAAD,EAA+B;IAC7C;IAD6C;IAE7C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,IAAb,EAA2C;IAC1D,OAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,IAAxB,CAAP;EACH;;AAZkE;;;8BAA1DP,a,UACsC,S"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result"],"sources":["HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerResultCallable<T extends Context = Context> {\n (context: T, result: any): Promise<any>;\n}\n\nexport class HandlerResultPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-result\";\n\n private readonly _callable: HandlerResultCallable<T>;\n\n public constructor(callable: HandlerResultCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, result: any): Promise<any> {\n return this._callable(context, result);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAKlEC,WAAW,CAACC,QAAD,EAAqC;IACnD;IADmD;IAEnD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,MAAb,EAAwC;IACvD,OAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,MAAxB,CAAP;EACH;;AAZwE;;;8BAAhEP,mB,UACsC,gB"}
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins/types\";\n\nexport type HandlerArgs = any[];\n/**\n * Left for backwards compatibility.\n * @deprecated\n */\nexport type HandlerContext = Context;\n\n/**\n * The main context which is constructed on every request.\n * All other contexts should extend this one.\n */\nexport interface Context {\n plugins: PluginsContainer;\n args: HandlerArgs;\n readonly WEBINY_VERSION: string;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n hasResult: () => boolean;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n *\n * @private\n */\n _result?: any;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n setResult: (value: any) => void;\n /**\n * Not to be used outside of Webiny internal code.\n * @internal\n */\n getResult: () => void;\n /**\n * Wait for property to be defined on the object and then execute the callable.\n * In case of multiple objects defined, wait for all of them.\n */\n waitFor: <T extends Context = Context>(\n obj: string[] | string,\n cb: (context: T) => void\n ) => void;\n}\n\n/**\n * Left for backwards-compatibility.\n *\n * @deprecated\n */\nexport type ContextPlugin<\n C0 = Context,\n C1 = Context,\n C2 = Context,\n C3 = Context,\n C4 = Context,\n C5 = Context,\n C6 = Context,\n C7 = Context,\n C8 = Context,\n C9 = Context\n> = Plugin & {\n type: \"context\";\n apply(context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9): Promise<void>;\n};\n/**\n * Left for backwards-compatibility.\n *\n * @deprecated\n */\nexport type HandlerPlugin<\n C0 = Context,\n C1 = Context,\n C2 = Context,\n C3 = Context,\n C4 = Context,\n C5 = Context,\n C6 = Context,\n C7 = Context,\n C8 = Context,\n C9 = Context\n> = Plugin & {\n type: \"handler\";\n handle(\n context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9,\n next: () => Promise<void>\n ): any;\n};\n/**\n * Left for backwards-compatibility.\n *\n * @deprecated\n */\nexport type HandlerResultPlugin<\n C0 = Context,\n C1 = Context,\n C2 = Context,\n C3 = Context,\n C4 = Context,\n C5 = Context,\n C6 = Context,\n C7 = Context,\n C8 = Context,\n C9 = Context\n> = Plugin & {\n type: \"handler-result\";\n handle(context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9, result: any): any;\n};\n/**\n * Left for backwards-compatibility.\n *\n * @deprecated\n */\nexport type HandlerErrorPlugin<\n C0 = Context,\n C1 = Context,\n C2 = Context,\n C3 = Context,\n C4 = Context,\n C5 = Context,\n C6 = Context,\n C7 = Context,\n C8 = Context,\n C9 = Context\n> = Plugin & {\n type: \"handler-error\";\n handle(\n context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9,\n error: any,\n next: Function\n ): Promise<any>;\n};\n"],"mappings":""}
|