@webiny/handler 5.24.0-beta.0 → 5.25.0-beta.1

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 CHANGED
@@ -92,6 +92,7 @@ async function handle(context) {
92
92
  return result;
93
93
  } catch (error) {
94
94
  // Log error to cloud, as these can be extremely annoying to debug!
95
+ console.log("@webiny/handler");
95
96
  console.log(error);
96
97
  const handlers = context.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type);
97
98
  const handler = (0, _middleware.default)(handlers.map(pl => {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["createHandler.ts"],"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","map","pl","next","Error","error","console","log","HandlerErrorPlugin"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;eAGe,CAAC,GAAGA,OAAJ,KACX,OAAO,GAAGC,IAAV,KAA6B;AACzB,QAAMC,OAAO,GAAG,IAAIC,gBAAJ,CAAY;AACxBH,IAAAA,OADwB;AAExBC,IAAAA,IAFwB;;AAGxB;AACZ;AACA;AACYG,IAAAA,cAAc,EAAEC,OAAO,CAACC,GAAR,CAAYF;AANJ,GAAZ,CAAhB;AASA,QAAMG,MAAM,GAAG,MAAMC,MAAM,CAACN,OAAD,CAA3B;AAEA,QAAMO,cAAc,GAAGP,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CACnBC,yCAAoBC,IADD,CAAvB;;AAGA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGJ,cAAc,CAACK,MAAnC,EAA2CD,CAAC,EAA5C,EAAgD;AAC5C,QAAI,CAACJ,cAAc,CAACI,CAAD,CAAd,CAAkBL,MAAvB,EAA+B;AAC3B;AACH;;A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EAAE,IAAI;AACf,aAAO,CAACxB,OAAD,EAAmByB,IAAnB,KAAsC;AACzC,eAAOD,EAAE,CAAClB,MAAH,CAAUN,OAAV,EAAmByB,IAAnB,CAAP;AACH,OAFD;AAGH,KAJD,CADY,CAAhB;AAOA,UAAMpB,MAAM,GAAG,MAAMiB,OAAO,CAACtB,OAAD,CAA5B;;AACA,QAAI,CAACK,MAAL,EAAa;AACT,YAAM,IAAIqB,KAAJ,CAAW,kDAAX,CAAN;AACH;;AAED,WAAOrB,MAAP;AACH,GAvCD,CAuCE,OAAOsB,KAAP,EAAc;AACZ;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAY,iBAAZ;AACAD,IAAAA,OAAO,CAACC,GAAR,CAAYF,KAAZ;AACA,UAAMP,QAAQ,GAAGpB,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CAA2CsB,uCAAmBpB,IAA9D,CAAjB;AACA,UAAMY,OAAO,GAAG,yBACZF,QAAQ,CAACG,GAAT,CAAaC,EAAE,IAAI;AACf,aAAO,CAACxB,OAAD,EAAmB2B,KAAnB,EAAiCF,IAAjC,KAAoD;AACvD,eAAOD,EAAE,CAAClB,MAAH,CAAUN,OAAV,EAAmB2B,KAAnB,EAA0BF,IAA1B,CAAP;AACH,OAFD;AAGH,KAJD,CADY,CAAhB;AAOA,WAAOH,OAAO,CAACtB,OAAD,EAAU2B,KAAV,CAAd;AACH;AACJ","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"]}
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","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"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["middleware.ts"],"names":["functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"mappings":";;;;;;;AAAA;AACA;AACA;eACe,CAACA,SAA0B,GAAG,EAA9B,KAA+C;AAC1D,SAAO,CAAC,GAAGC,IAAJ,KAAqC;AACxC,QAAI,CAACD,SAAS,CAACE,MAAf,EAAuB;AACnB,aAAOC,OAAO,CAACC,OAAR,EAAP;AACH,KAHuC,CAKxC;;;AACA,UAAMC,KAAK,GAAG,CAAC,GAAGL,SAAJ,CAAd;AACA,WAAO,IAAIG,OAAJ,CAAY,CAACG,aAAD,EAAqBC,YAArB,KAAsC;AACrD,YAAMC,IAAI,GAAG,YAA0B;AACnC,cAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAN,EAAX;;AACA,YAAI,CAACD,EAAL,EAAS;AACL,iBAAON,OAAO,CAACC,OAAR,EAAP;AACH;;AAED,eAAO,IAAID,OAAJ,CAAY,OAAOC,OAAP,EAAgBO,MAAhB,KAA2B;AAC1C,cAAI;AACA,kBAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAJ,EAAUG,OAAV,CAAvB;;AACA,gBAAI,OAAOQ,MAAP,KAAkB,WAAtB,EAAmC;AAC/B,qBAAON,aAAa,CAACM,MAAD,CAApB;AACH;AACJ,WALD,CAKE,OAAOC,CAAP,EAAU;AACRF,YAAAA,MAAM,CAACE,CAAD,CAAN;AACH;AACJ,SATM,EAUFC,IAVE,CAUG,MAAM;AACR,iBAAON,IAAI,EAAX;AACH,SAZE,EAaFM,IAbE,CAaG,MAAM;AACRR,UAAAA,aAAa,CAAC,GAAGL,IAAJ,CAAb;AACH,SAfE,EAgBFc,KAhBE,CAgBIF,CAAC,IAAI;AACRN,UAAAA,YAAY,CAACM,CAAD,CAAZ;AACH,SAlBE,CAAP;AAmBH,OAzBD;;AA2BA,aAAOL,IAAI,EAAX;AACH,KA7BM,CAAP;AA8BH,GArCD;AAsCH,C","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler",
3
- "version": "5.24.0-beta.0",
3
+ "version": "5.25.0-beta.1",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,18 +14,18 @@
14
14
  "Adrian Smijulj <adrian@webiny.com>"
15
15
  ],
16
16
  "dependencies": {
17
- "@babel/runtime": "7.16.7",
18
- "@webiny/plugins": "5.24.0-beta.0"
17
+ "@babel/runtime": "7.17.2",
18
+ "@webiny/plugins": "5.25.0-beta.1"
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.24.0-beta.0",
25
- "@webiny/project-utils": "^5.24.0-beta.0",
24
+ "@webiny/cli": "^5.25.0-beta.1",
25
+ "@webiny/project-utils": "^5.25.0-beta.1",
26
26
  "rimraf": "^3.0.2",
27
27
  "ttypescript": "^1.5.13",
28
- "typescript": "^4.1.3"
28
+ "typescript": "4.5.5"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public",
@@ -35,5 +35,5 @@
35
35
  "build": "yarn webiny run build",
36
36
  "watch": "yarn webiny run watch"
37
37
  },
38
- "gitHead": "05b90b92bbaf2ef3adf275d008c4641580cf5f42"
38
+ "gitHead": "c5cbc36b39a28e3f1c58de7d768fdcd113ad8e15"
39
39
  }
@@ -6,6 +6,6 @@ export interface BeforeHandlerCallable<T extends Context = Context> {
6
6
  export declare class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {
7
7
  static readonly type: string;
8
8
  private readonly _callable;
9
- constructor(callable?: BeforeHandlerCallable<T>);
10
- apply(context: T): void | Promise<void>;
9
+ constructor(callable: BeforeHandlerCallable<T>);
10
+ apply(context: T): Promise<void>;
11
11
  }
@@ -18,7 +18,7 @@ class BeforeHandlerPlugin extends _plugins.Plugin {
18
18
  this._callable = callable;
19
19
  }
20
20
 
21
- apply(context) {
21
+ async apply(context) {
22
22
  if (typeof this._callable !== "function") {
23
23
  throw Error(`Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
24
24
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["BeforeHandlerPlugin.ts"],"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;AAIzEC,EAAAA,WAAW,CAACC,QAAD,EAAqC;AAC5C;AAD4C;AAE5C,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEiB,QAALE,KAAK,CAACC,OAAD,EAA4B;AAC1C,QAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;AACtC,YAAMG,KAAK,CACN,6IADM,CAAX;AAGH;;AAED,WAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;AACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB","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"]}
@@ -133,6 +133,12 @@ class Context {
133
133
 
134
134
  this.waiters.push({
135
135
  targets,
136
+
137
+ /**
138
+ * TODO @ts-refactor
139
+ * Problem with possible subtype initialization
140
+ */
141
+ // @ts-ignore
136
142
  cb
137
143
  });
138
144
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Context.ts"],"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","fil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AACoB,eAAK,MAAMc,MAAX,IAAqB,KAAKC,OAA1B,EAAmC;AAC/B,gBAAID,MAAM,CAACP,OAAP,CAAeS,QAAf,CAAwBP,MAAxB,MAA8C,KAAlD,EAAyD;AACrD;AACH;AACD;AACxB;AACA;;;AACwBK,YAAAA,MAAM,CAACP,OAAP,GAAiBO,MAAM,CAACP,OAAP,CAAeU,MAAf,CAAsBC,CAAC,IAAIA,CAAC,KAAKT,MAAjC,CAAjB;AACA;AACxB;AACA;;AACwB,gBAAIK,MAAM,CAACP,OAAP,CAAeY,MAAf,GAAwB,CAA5B,EAA+B;AAC3B;AACH;AACD;AACxB;AACA;AACA;;;AACwBL,YAAAA,MAAM,CAACX,EAAP,CAAU,IAAV;AACH;AACJ,SAhC+B;;AAiChC;AAChB;AACA;AACgBiB,QAAAA,GAAG,EAAE,MAAW;AACZ,gBAAMP,YAAY,GAAI,KAAIJ,MAAO,IAAjC;AACA,iBAAO,KAAKI,YAAL,CAAP;AACH,SAvC+B;AAwChCQ,QAAAA,YAAY,EAAE;AAxCkB,OAApC;AA0CA;AACZ;AACA;;AACYd,MAAAA,OAAO,CAACe,IAAR,CAAab,MAAb;AACH;AACD;AACR;AACA;;;AACQ,QAAIF,OAAO,CAACY,MAAR,KAAmB,CAAvB,EAA0B;AACtBhB,MAAAA,EAAE,CAAC,IAAD,CAAF;AACA;AACH;AACD;AACR;AACA;;;AACQ,SAAKY,OAAL,CAAaO,IAAb,CAAkB;AACdf,MAAAA,OADc;;AAEd;AACZ;AACA;AACA;AACY;AACAJ,MAAAA;AAPc,KAAlB;AASH;;AAlH4C","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"]}
@@ -6,6 +6,6 @@ export interface ContextPluginCallable<T extends Context = Context> {
6
6
  export declare class ContextPlugin<T extends Context = Context> extends Plugin {
7
7
  static readonly type: string;
8
8
  private readonly _callable;
9
- constructor(callable?: ContextPluginCallable<T>);
10
- apply(context: T): void | Promise<void>;
9
+ constructor(callable: ContextPluginCallable<T>);
10
+ apply(context: T): Promise<void>;
11
11
  }
@@ -18,7 +18,7 @@ class ContextPlugin extends _plugins.Plugin {
18
18
  this._callable = callable;
19
19
  }
20
20
 
21
- apply(context) {
21
+ async apply(context) {
22
22
  if (typeof this._callable !== "function") {
23
23
  throw Error(`Missing callable in ContextPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
24
24
  }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ContextPlugin.ts"],"names":["ContextPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,aAAN,SAAyDC,eAAzD,CAAgE;AAInEC,EAAAA,WAAW,CAACC,QAAD,EAAqC;AAC5C;AAD4C;AAE5C,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEiB,QAALE,KAAK,CAACC,OAAD,EAA4B;AAC1C,QAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;AACtC,YAAMG,KAAK,CACN,uIADM,CAAX;AAGH;;AAED,WAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;AACH;;AAjBkE;;;8BAA1DN,a,UACsC,S","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"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["HandlerErrorPlugin.ts"],"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;AAKjEC,EAAAA,WAAW,CAACC,QAAD,EAAoC;AAClD;AADkD;AAElD,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEkB,QAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;AACxE,WAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;AACH;;AAZuE;;;8BAA/DR,kB,UACsC,e","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"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["HandlerPlugin.ts"],"names":["HandlerPlugin","Plugin","constructor","callable","_callable","handle","context","next"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,aAAN,SAAyDC,eAAzD,CAAgE;AAK5DC,EAAAA,WAAW,CAACC,QAAD,EAA+B;AAC7C;AAD6C;AAE7C,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEkB,QAANE,MAAM,CAACC,OAAD,EAAaC,IAAb,EAA2C;AAC1D,WAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,IAAxB,CAAP;AACH;;AAZkE;;;8BAA1DP,a,UACsC,S","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"]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["HandlerResultPlugin.ts"],"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;AAKlEC,EAAAA,WAAW,CAACC,QAAD,EAAqC;AACnD;AADmD;AAEnD,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEkB,QAANE,MAAM,CAACC,OAAD,EAAaC,MAAb,EAAwC;AACvD,WAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,MAAxB,CAAP;AACH;;AAZwE;;;8BAAhEP,mB,UACsC,gB","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"]}
package/types.d.ts CHANGED
@@ -44,7 +44,6 @@ export interface Context {
44
44
  /**
45
45
  * Left for backwards-compatibility.
46
46
  *
47
- * @internal
48
47
  * @deprecated
49
48
  */
50
49
  export declare type ContextPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
@@ -54,7 +53,6 @@ export declare type ContextPlugin<C0 = Context, C1 = Context, C2 = Context, C3 =
54
53
  /**
55
54
  * Left for backwards-compatibility.
56
55
  *
57
- * @internal
58
56
  * @deprecated
59
57
  */
60
58
  export declare type HandlerPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
@@ -64,7 +62,6 @@ export declare type HandlerPlugin<C0 = Context, C1 = Context, C2 = Context, C3 =
64
62
  /**
65
63
  * Left for backwards-compatibility.
66
64
  *
67
- * @internal
68
65
  * @deprecated
69
66
  */
70
67
  export declare type HandlerResultPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
@@ -74,7 +71,6 @@ export declare type HandlerResultPlugin<C0 = Context, C1 = Context, C2 = Context
74
71
  /**
75
72
  * Left for backwards-compatibility.
76
73
  *
77
- * @internal
78
74
  * @deprecated
79
75
  */
80
76
  export declare type HandlerErrorPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}