@webiny/api
Advanced tools
+27
-0
| "use strict"; | ||
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
| Object.defineProperty(exports, "__esModule", { | ||
@@ -8,4 +9,7 @@ value: true | ||
| exports.Context = void 0; | ||
| var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
| var _plugins = require("@webiny/plugins"); | ||
| class Context { | ||
@@ -25,11 +29,15 @@ constructor(params) { | ||
| } | ||
| getResult() { | ||
| return this._result; | ||
| } | ||
| hasResult() { | ||
| return !!this._result; | ||
| } | ||
| setResult(value) { | ||
| this._result = value; | ||
| } | ||
| waitFor(obj, cb) { | ||
@@ -41,2 +49,3 @@ const initialTargets = Array.isArray(obj) ? obj : [obj]; | ||
| */ | ||
| for (const key in initialTargets) { | ||
@@ -48,2 +57,3 @@ const target = initialTargets[key]; | ||
| */ | ||
| if (this[target]) { | ||
@@ -58,2 +68,4 @@ continue; | ||
| */ | ||
| Object.defineProperty(this, target, { | ||
@@ -71,2 +83,3 @@ /** | ||
| */ | ||
| for (const waiter of this.waiters) { | ||
@@ -79,2 +92,4 @@ if (waiter.targets.includes(target) === false) { | ||
| */ | ||
| waiter.targets = waiter.targets.filter(t => t !== target); | ||
@@ -84,2 +99,3 @@ /** | ||
| */ | ||
| if (waiter.targets.length > 0) { | ||
@@ -92,5 +108,8 @@ continue; | ||
| */ | ||
| waiter.cb(this); | ||
| } | ||
| }, | ||
| /** | ||
@@ -108,2 +127,3 @@ * As we have set property with __ around it, we must get it as well. | ||
| */ | ||
| targets.push(target); | ||
@@ -114,2 +134,4 @@ } | ||
| */ | ||
| if (targets.length === 0) { | ||
@@ -122,4 +144,7 @@ cb(this); | ||
| */ | ||
| this.waiters.push({ | ||
| targets, | ||
| /** | ||
@@ -133,3 +158,5 @@ * TODO @ts-refactor | ||
| } | ||
| } | ||
| exports.Context = Context; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"names":["Context","constructor","params","plugins","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 } 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 plugins?: PluginCollection;\n WEBINY_VERSION: string;\n}\nexport class Context implements ContextInterface {\n public _result: any;\n public args: any;\n public readonly plugins: PluginsContainer;\n public readonly WEBINY_VERSION: string;\n\n private readonly waiters: Waiter[] = [];\n\n public constructor(params: ContextParams) {\n const { plugins, WEBINY_VERSION } = params;\n this.plugins = new PluginsContainer(plugins || []);\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 * Also, if target is not a string, skip this property as it will fail to convert properly during the runtime.\n */\n if (this[target]) {\n continue;\n } else if (typeof target !== \"string\") {\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) === 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;AAYO,MAAMA,OAAO,CAA6B;EAQtCC,WAAW,CAACC,MAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAAA,+CAFL,EAAE;IAGnC,MAAM;MAAEC,OAAO;MAAEC;IAAe,CAAC,GAAGF,MAAM;IAC1C,IAAI,CAACC,OAAO,GAAG,IAAIE,yBAAgB,CAACF,OAAO,IAAI,EAAE,CAAC;IAClD,IAAI,CAACC,cAAc,GAAGA,cAAc;EACxC;EAEOE,SAAS,GAAQ;IACpB,OAAO,IAAI,CAACC,OAAO;EACvB;EAEOC,SAAS,GAAY;IACxB,OAAO,CAAC,CAAC,IAAI,CAACD,OAAO;EACzB;EAEOE,SAAS,CAACC,KAAU,EAAQ;IAC/B,IAAI,CAACH,OAAO,GAAGG,KAAK;EACxB;EAEOC,OAAO,CACVC,GAAsB,EACtBC,EAAwB,EACpB;IACJ,MAAMC,cAAc,GAAGC,KAAK,CAACC,OAAO,CAACJ,GAAG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CAACb,MAAM,CAAW;IAClC;IACA;AACR;AACA;IACQ,IAAIF,OAAO,CAACY,MAAM,KAAK,CAAC,EAAE;MACtBhB,EAAE,CAAC,IAAI,CAAQ;MACf;IACJ;IACA;AACR;AACA;IACQ,IAAI,CAACY,OAAO,CAACO,IAAI,CAAC;MACdf,OAAO;MACP;AACZ;AACA;AACA;MACY;MACAJ;IACJ,CAAC,CAAC;EACN;AACJ;AAAC"} | ||
| {"version":3,"names":["Context","constructor","params","plugins","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 } 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 plugins?: PluginCollection;\n WEBINY_VERSION: string;\n}\nexport class Context implements ContextInterface {\n public _result: any;\n public args: any;\n public readonly plugins: PluginsContainer;\n public readonly WEBINY_VERSION: string;\n\n private readonly waiters: Waiter[] = [];\n\n public constructor(params: ContextParams) {\n const { plugins, WEBINY_VERSION } = params;\n this.plugins = new PluginsContainer(plugins || []);\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 * Also, if target is not a string, skip this property as it will fail to convert properly during the runtime.\n */\n if (this[target]) {\n continue;\n } else if (typeof target !== \"string\") {\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) === 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;;AAYO,MAAMA,OAAN,CAA0C;EAQtCC,WAAW,CAACC,MAAD,EAAwB;IAAA;IAAA;IAAA;IAAA;IAAA,+CAFL,EAEK;IACtC,MAAM;MAAEC,OAAF;MAAWC;IAAX,IAA8BF,MAApC;IACA,KAAKC,OAAL,GAAe,IAAIE,yBAAJ,CAAqBF,OAAO,IAAI,EAAhC,CAAf;IACA,KAAKC,cAAL,GAAsBA,cAAtB;EACH;;EAEME,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B;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;;AApH4C"} |
+4
-0
@@ -6,3 +6,5 @@ "use strict"; | ||
| }); | ||
| var _Context = require("./Context"); | ||
| Object.keys(_Context).forEach(function (key) { | ||
@@ -18,3 +20,5 @@ if (key === "default" || key === "__esModule") return; | ||
| }); | ||
| var _ContextPlugin = require("./plugins/ContextPlugin"); | ||
| Object.keys(_ContextPlugin).forEach(function (key) { | ||
@@ -21,0 +25,0 @@ if (key === "default" || key === "__esModule") return; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/Context\";\nexport * from \"~/plugins/ContextPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"} | ||
| {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/Context\";\nexport * from \"~/plugins/ContextPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"} |
+6
-6
| { | ||
| "name": "@webiny/api", | ||
| "version": "0.0.0-unstable.990c3ab1b6", | ||
| "version": "0.0.0-unstable.aad28a72ae", | ||
| "main": "index.js", | ||
@@ -15,4 +15,4 @@ "repository": { | ||
| "dependencies": { | ||
| "@babel/runtime": "7.20.1", | ||
| "@webiny/plugins": "0.0.0-unstable.990c3ab1b6" | ||
| "@babel/runtime": "7.19.0", | ||
| "@webiny/plugins": "0.0.0-unstable.aad28a72ae" | ||
| }, | ||
@@ -24,4 +24,4 @@ "devDependencies": { | ||
| "@babel/preset-typescript": "^7.18.6", | ||
| "@webiny/cli": "^0.0.0-unstable.990c3ab1b6", | ||
| "@webiny/project-utils": "^0.0.0-unstable.990c3ab1b6", | ||
| "@webiny/cli": "^0.0.0-unstable.aad28a72ae", | ||
| "@webiny/project-utils": "^0.0.0-unstable.aad28a72ae", | ||
| "rimraf": "^3.0.2", | ||
@@ -39,3 +39,3 @@ "ttypescript": "^1.5.13", | ||
| }, | ||
| "gitHead": "87e7b4d0a643f65b31d029d6bf2a81902fb940a8" | ||
| "gitHead": "aad28a72ae72f19b80a3196d2b4439399acc67ad" | ||
| } |
| "use strict"; | ||
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
| Object.defineProperty(exports, "__esModule", { | ||
@@ -8,4 +9,7 @@ value: true | ||
| exports.createContextPlugin = exports.ContextPlugin = void 0; | ||
| var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
| var _plugins = require("@webiny/plugins"); | ||
| class ContextPlugin extends _plugins.Plugin { | ||
@@ -17,2 +21,3 @@ constructor(callable) { | ||
| } | ||
| async apply(context) { | ||
@@ -22,10 +27,15 @@ if (typeof this._callable !== "function") { | ||
| } | ||
| return this._callable(context); | ||
| } | ||
| } | ||
| exports.ContextPlugin = ContextPlugin; | ||
| (0, _defineProperty2.default)(ContextPlugin, "type", "context"); | ||
| const createContextPlugin = callable => { | ||
| return new ContextPlugin(callable); | ||
| }; | ||
| exports.createContextPlugin = createContextPlugin; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"names":["ContextPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createContextPlugin"],"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\nexport const createContextPlugin = <T extends Context = Context>(\n callable: ContextPluginCallable<T>\n): ContextPlugin<T> => {\n return new ContextPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;AAAA;AAOO,MAAMA,aAAa,SAAsCC,eAAM,CAAC;EAInEC,WAAW,CAACC,QAAkC,EAAE;IAC5C,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,KAAK,CAACC,OAAU,EAAiB;IAC1C,IAAI,OAAO,IAAI,CAACF,SAAS,KAAK,UAAU,EAAE;MACtC,MAAMG,KAAK,CACN,uIAAsI,CAC1I;IACL;IAEA,OAAO,IAAI,CAACH,SAAS,CAACE,OAAO,CAAC;EAClC;AACJ;AAAC;AAAA,8BAlBYN,aAAa,UACyB,SAAS;AAmBrD,MAAMQ,mBAAmB,GAC5BL,QAAkC,IACf;EACnB,OAAO,IAAIH,aAAa,CAAIG,QAAQ,CAAC;AACzC,CAAC;AAAC"} | ||
| {"version":3,"names":["ContextPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createContextPlugin"],"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\nexport const createContextPlugin = <T extends Context = Context>(\n callable: ContextPluginCallable<T>\n): ContextPlugin<T> => {\n return new ContextPlugin<T>(callable);\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;;AAmB5C,MAAMQ,mBAAmB,GAC5BL,QAD+B,IAEZ;EACnB,OAAO,IAAIH,aAAJ,CAAqBG,QAArB,CAAP;AACH,CAJM"} |
21230
-0.05%+ Added
+ Added
- Removed
- Removed
Updated