@webiny/plugins 6.3.0-beta.4 → 6.4.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.
@@ -1,33 +1,34 @@
1
1
  import { PluginsContainer } from "./types.js";
2
- const isPluginLoader = value => {
3
- return typeof value === "function";
4
- };
5
- export class AsyncPluginsContainer {
6
- constructor(plugins) {
7
- this.plugins = plugins instanceof PluginsContainer ? plugins.all() : plugins;
8
- }
9
- async init() {
10
- if (this.pluginsContainer) {
11
- return this.pluginsContainer;
2
+ const isPluginLoader = (value)=>"function" == typeof value;
3
+ class AsyncPluginsContainer {
4
+ constructor(plugins){
5
+ this.plugins = plugins instanceof PluginsContainer ? plugins.all() : plugins;
12
6
  }
13
- const plugins = await this.traverseAndLoadPlugins(this.plugins);
14
- this.pluginsContainer = new PluginsContainer(plugins);
15
- return this.pluginsContainer;
16
- }
17
- async traverseAndLoadPlugins(plugins) {
18
- if (!Array.isArray(plugins)) {
19
- return [plugins];
7
+ async init() {
8
+ if (this.pluginsContainer) return this.pluginsContainer;
9
+ const plugins = await this.traverseAndLoadPlugins(this.plugins);
10
+ this.pluginsContainer = new PluginsContainer(plugins);
11
+ return this.pluginsContainer;
12
+ }
13
+ async traverseAndLoadPlugins(plugins) {
14
+ if (!Array.isArray(plugins)) return [
15
+ plugins
16
+ ];
17
+ return plugins.reduce((acc, item)=>acc.then(async (plugins)=>{
18
+ if (isPluginLoader(item)) {
19
+ const lazyPlugins = await item();
20
+ return [
21
+ ...plugins,
22
+ ...await this.traverseAndLoadPlugins(lazyPlugins)
23
+ ];
24
+ }
25
+ return [
26
+ ...plugins,
27
+ ...await this.traverseAndLoadPlugins(item)
28
+ ];
29
+ }), Promise.resolve([]));
20
30
  }
21
- return plugins.reduce((acc, item) => {
22
- return acc.then(async plugins => {
23
- if (isPluginLoader(item)) {
24
- const lazyPlugins = await item();
25
- return [...plugins, ...(await this.traverseAndLoadPlugins(lazyPlugins))];
26
- }
27
- return [...plugins, ...(await this.traverseAndLoadPlugins(item))];
28
- });
29
- }, Promise.resolve([]));
30
- }
31
31
  }
32
+ export { AsyncPluginsContainer };
32
33
 
33
34
  //# sourceMappingURL=AsyncPluginsContainer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["PluginsContainer","isPluginLoader","value","AsyncPluginsContainer","constructor","plugins","all","init","pluginsContainer","traverseAndLoadPlugins","Array","isArray","reduce","acc","item","then","lazyPlugins","Promise","resolve"],"sources":["AsyncPluginsContainer.ts"],"sourcesContent":["import type { Plugin, PluginCollection, PluginFactory } from \"~/types.js\";\nimport { PluginsContainer } from \"~/types.js\";\n\nconst isPluginLoader = (value: unknown): value is PluginFactory => {\n return typeof value === \"function\";\n};\n\nexport class AsyncPluginsContainer {\n private readonly plugins: PluginCollection;\n private pluginsContainer: PluginsContainer | undefined;\n\n constructor(plugins: PluginCollection | PluginsContainer) {\n this.plugins = plugins instanceof PluginsContainer ? plugins.all() : plugins;\n }\n\n async init() {\n if (this.pluginsContainer) {\n return this.pluginsContainer;\n }\n\n const plugins = await this.traverseAndLoadPlugins(this.plugins);\n this.pluginsContainer = new PluginsContainer(plugins);\n\n return this.pluginsContainer;\n }\n\n private async traverseAndLoadPlugins(plugins: Plugin | PluginCollection): Promise<Plugin[]> {\n if (!Array.isArray(plugins)) {\n return [plugins];\n }\n\n return plugins.reduce<Promise<Plugin[]>>((acc, item) => {\n return acc.then(async plugins => {\n if (isPluginLoader(item)) {\n const lazyPlugins = await item();\n return [...plugins, ...(await this.traverseAndLoadPlugins(lazyPlugins))];\n }\n\n return [...plugins, ...(await this.traverseAndLoadPlugins(item))];\n });\n }, Promise.resolve([]));\n }\n}\n"],"mappings":"AACA,SAASA,gBAAgB;AAEzB,MAAMC,cAAc,GAAIC,KAAc,IAA6B;EAC/D,OAAO,OAAOA,KAAK,KAAK,UAAU;AACtC,CAAC;AAED,OAAO,MAAMC,qBAAqB,CAAC;EAI/BC,WAAWA,CAACC,OAA4C,EAAE;IACtD,IAAI,CAACA,OAAO,GAAGA,OAAO,YAAYL,gBAAgB,GAAGK,OAAO,CAACC,GAAG,CAAC,CAAC,GAAGD,OAAO;EAChF;EAEA,MAAME,IAAIA,CAAA,EAAG;IACT,IAAI,IAAI,CAACC,gBAAgB,EAAE;MACvB,OAAO,IAAI,CAACA,gBAAgB;IAChC;IAEA,MAAMH,OAAO,GAAG,MAAM,IAAI,CAACI,sBAAsB,CAAC,IAAI,CAACJ,OAAO,CAAC;IAC/D,IAAI,CAACG,gBAAgB,GAAG,IAAIR,gBAAgB,CAACK,OAAO,CAAC;IAErD,OAAO,IAAI,CAACG,gBAAgB;EAChC;EAEA,MAAcC,sBAAsBA,CAACJ,OAAkC,EAAqB;IACxF,IAAI,CAACK,KAAK,CAACC,OAAO,CAACN,OAAO,CAAC,EAAE;MACzB,OAAO,CAACA,OAAO,CAAC;IACpB;IAEA,OAAOA,OAAO,CAACO,MAAM,CAAoB,CAACC,GAAG,EAAEC,IAAI,KAAK;MACpD,OAAOD,GAAG,CAACE,IAAI,CAAC,MAAMV,OAAO,IAAI;QAC7B,IAAIJ,cAAc,CAACa,IAAI,CAAC,EAAE;UACtB,MAAME,WAAW,GAAG,MAAMF,IAAI,CAAC,CAAC;UAChC,OAAO,CAAC,GAAGT,OAAO,EAAE,IAAI,MAAM,IAAI,CAACI,sBAAsB,CAACO,WAAW,CAAC,CAAC,CAAC;QAC5E;QAEA,OAAO,CAAC,GAAGX,OAAO,EAAE,IAAI,MAAM,IAAI,CAACI,sBAAsB,CAACK,IAAI,CAAC,CAAC,CAAC;MACrE,CAAC,CAAC;IACN,CAAC,EAAEG,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC,CAAC;EAC3B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"AsyncPluginsContainer.js","sources":["../src/AsyncPluginsContainer.ts"],"sourcesContent":["import type { Plugin, PluginCollection, PluginFactory } from \"~/types.js\";\nimport { PluginsContainer } from \"~/types.js\";\n\nconst isPluginLoader = (value: unknown): value is PluginFactory => {\n return typeof value === \"function\";\n};\n\nexport class AsyncPluginsContainer {\n private readonly plugins: PluginCollection;\n private pluginsContainer: PluginsContainer | undefined;\n\n constructor(plugins: PluginCollection | PluginsContainer) {\n this.plugins = plugins instanceof PluginsContainer ? plugins.all() : plugins;\n }\n\n async init() {\n if (this.pluginsContainer) {\n return this.pluginsContainer;\n }\n\n const plugins = await this.traverseAndLoadPlugins(this.plugins);\n this.pluginsContainer = new PluginsContainer(plugins);\n\n return this.pluginsContainer;\n }\n\n private async traverseAndLoadPlugins(plugins: Plugin | PluginCollection): Promise<Plugin[]> {\n if (!Array.isArray(plugins)) {\n return [plugins];\n }\n\n return plugins.reduce<Promise<Plugin[]>>((acc, item) => {\n return acc.then(async plugins => {\n if (isPluginLoader(item)) {\n const lazyPlugins = await item();\n return [...plugins, ...(await this.traverseAndLoadPlugins(lazyPlugins))];\n }\n\n return [...plugins, ...(await this.traverseAndLoadPlugins(item))];\n });\n }, Promise.resolve([]));\n }\n}\n"],"names":["isPluginLoader","value","AsyncPluginsContainer","plugins","PluginsContainer","Array","acc","item","lazyPlugins","Promise"],"mappings":";AAGA,MAAMA,iBAAiB,CAACC,QACb,AAAiB,cAAjB,OAAOA;AAGX,MAAMC;IAIT,YAAYC,OAA4C,CAAE;QACtD,IAAI,CAAC,OAAO,GAAGA,mBAAmBC,mBAAmBD,QAAQ,GAAG,KAAKA;IACzE;IAEA,MAAM,OAAO;QACT,IAAI,IAAI,CAAC,gBAAgB,EACrB,OAAO,IAAI,CAAC,gBAAgB;QAGhC,MAAMA,UAAU,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO;QAC9D,IAAI,CAAC,gBAAgB,GAAG,IAAIC,iBAAiBD;QAE7C,OAAO,IAAI,CAAC,gBAAgB;IAChC;IAEA,MAAc,uBAAuBA,OAAkC,EAAqB;QACxF,IAAI,CAACE,MAAM,OAAO,CAACF,UACf,OAAO;YAACA;SAAQ;QAGpB,OAAOA,QAAQ,MAAM,CAAoB,CAACG,KAAKC,OACpCD,IAAI,IAAI,CAAC,OAAMH;gBAClB,IAAIH,eAAeO,OAAO;oBACtB,MAAMC,cAAc,MAAMD;oBAC1B,OAAO;2BAAIJ;2BAAa,MAAM,IAAI,CAAC,sBAAsB,CAACK;qBAAc;gBAC5E;gBAEA,OAAO;uBAAIL;uBAAa,MAAM,IAAI,CAAC,sBAAsB,CAACI;iBAAO;YACrE,IACDE,QAAQ,OAAO,CAAC,EAAE;IACzB;AACJ"}
package/Plugin.js CHANGED
@@ -1,12 +1,11 @@
1
- export class Plugin {
2
- constructor() {
3
- if (!this.constructor.type) {
4
- throw Error(`Missing "type" definition in "${this.constructor.name}"!`);
1
+ class Plugin {
2
+ constructor(){
3
+ if (!this.constructor.type) throw Error(`Missing "type" definition in "${this.constructor.name}"!`);
4
+ }
5
+ get type() {
6
+ return this.constructor.type;
5
7
  }
6
- }
7
- get type() {
8
- return this.constructor.type;
9
- }
10
8
  }
9
+ export { Plugin };
11
10
 
12
11
  //# sourceMappingURL=Plugin.js.map
package/Plugin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Plugin","constructor","type","Error","name"],"sources":["Plugin.ts"],"sourcesContent":["export abstract class Plugin {\n public static readonly type: string;\n public name?: string;\n\n constructor() {\n if (!(this.constructor as typeof Plugin).type) {\n throw Error(`Missing \"type\" definition in \"${this.constructor.name}\"!`);\n }\n }\n\n get type() {\n return (this.constructor as typeof Plugin).type;\n }\n}\n"],"mappings":"AAAA,OAAO,MAAeA,MAAM,CAAC;EAIzBC,WAAWA,CAAA,EAAG;IACV,IAAI,CAAE,IAAI,CAACA,WAAW,CAAmBC,IAAI,EAAE;MAC3C,MAAMC,KAAK,CAAC,iCAAiC,IAAI,CAACF,WAAW,CAACG,IAAI,IAAI,CAAC;IAC3E;EACJ;EAEA,IAAIF,IAAIA,CAAA,EAAG;IACP,OAAQ,IAAI,CAACD,WAAW,CAAmBC,IAAI;EACnD;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"Plugin.js","sources":["../src/Plugin.ts"],"sourcesContent":["export abstract class Plugin {\n public static readonly type: string;\n public name?: string;\n\n constructor() {\n if (!(this.constructor as typeof Plugin).type) {\n throw Error(`Missing \"type\" definition in \"${this.constructor.name}\"!`);\n }\n }\n\n get type() {\n return (this.constructor as typeof Plugin).type;\n }\n}\n"],"names":["Plugin","Error"],"mappings":"AAAO,MAAeA;IAIlB,aAAc;QACV,IAAI,CAAE,IAAI,CAAC,WAAW,CAAmB,IAAI,EACzC,MAAMC,MAAM,CAAC,8BAA8B,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;IAE9E;IAEA,IAAI,OAAO;QACP,OAAQ,IAAI,CAAC,WAAW,CAAmB,IAAI;IACnD;AACJ"}
@@ -1,106 +1,82 @@
1
1
  import uniqid from "uniqid";
2
- const isOptionsObject = item => item && !Array.isArray(item) && !item.type && !item.name;
3
- const normalizeArgs = args => {
4
- let options = {};
5
-
6
- // Check if last item in the plugins array is actually an options object.
7
- if (isOptionsObject(args[args.length - 1])) {
8
- [options] = args.splice(-1, 1);
9
- }
10
- return [args, options];
2
+ const isOptionsObject = (item)=>item && !Array.isArray(item) && !item.type && !item.name;
3
+ const normalizeArgs = (args)=>{
4
+ let options = {};
5
+ if (isOptionsObject(args[args.length - 1])) [options] = args.splice(-1, 1);
6
+ return [
7
+ args,
8
+ options
9
+ ];
11
10
  };
12
- const assign = (plugins, options, target) => {
13
- for (const plugin of plugins) {
14
- if (Array.isArray(plugin)) {
15
- assign(plugin, options, target);
16
- continue;
11
+ const PluginsContainer_assign = (plugins, options, target)=>{
12
+ for (const plugin of plugins){
13
+ if (Array.isArray(plugin)) {
14
+ PluginsContainer_assign(plugin, options, target);
15
+ continue;
16
+ }
17
+ if ("object" != typeof plugin) throw new Error(`Could not register plugin. Expected an object, but got ${typeof plugin}.`);
18
+ if (!plugin.type) {
19
+ let name = "";
20
+ if (plugin.name) name = ` "${plugin.name}"`;
21
+ throw new Error(`Could not register plugin${name}. Missing "type" definition.`);
22
+ }
23
+ let name = plugin._name || plugin.name;
24
+ if (!name) plugin.name = name = uniqid(plugin.type + "-");
25
+ if (!options.skipExisting || !target[name]) {
26
+ target[name] = plugin;
27
+ plugin.init && plugin.init();
28
+ }
17
29
  }
18
- if (typeof plugin !== "object") {
19
- throw new Error(`Could not register plugin. Expected an object, but got ${typeof plugin}.`);
30
+ };
31
+ class PluginsContainer {
32
+ constructor(...args){
33
+ this.plugins = {};
34
+ this._byTypeCache = {};
35
+ this.register(...args);
20
36
  }
21
- if (!plugin.type) {
22
- let name = "";
23
- if (plugin.name) {
24
- name = ` "${plugin.name}"`;
25
- }
26
- throw new Error(`Could not register plugin${name}. Missing "type" definition.`);
37
+ byName(name) {
38
+ if (!name) return null;
39
+ return this.plugins[name];
27
40
  }
28
- let name = plugin._name || plugin.name;
29
- if (!name) {
30
- plugin.name = name = uniqid(plugin.type + "-");
41
+ byType(type) {
42
+ if (this._byTypeCache[type]) return Array.from(this._byTypeCache[type]);
43
+ const plugins = this.findByType(type);
44
+ this._byTypeCache[type] = plugins;
45
+ return Array.from(plugins);
31
46
  }
32
-
33
- // If skip existing was set to true, and a plugin with the same name was already registered, skip registration.
34
- if (!options.skipExisting || !target[name]) {
35
- target[name] = plugin;
36
- plugin.init && plugin.init();
47
+ atLeastOneByType(type) {
48
+ const list = this.byType(type);
49
+ if (0 === list.length) throw new Error(`There are no plugins by type "${type}".`);
50
+ return list;
37
51
  }
38
- }
39
- };
40
- export class PluginsContainer {
41
- plugins = {};
42
- _byTypeCache = {};
43
- constructor(...args) {
44
- this.register(...args);
45
- }
46
- byName(name) {
47
- if (!name) {
48
- return null;
52
+ oneByType(type) {
53
+ const list = this.atLeastOneByType(type);
54
+ if (list.length > 1) throw new Error(`There is a requirement for plugin of type "${type}" to be only one registered.`);
55
+ return list[0];
56
+ }
57
+ merge(input) {
58
+ if (input instanceof PluginsContainer) return void this.register(...input.all());
59
+ this.register(input);
60
+ }
61
+ mergeByType(container, type) {
62
+ this.register(...container.byType(type));
49
63
  }
50
- /**
51
- * We can safely cast name as string, we know it is so.
52
- */
53
- return this.plugins[name];
54
- }
55
- byType(type) {
56
- if (this._byTypeCache[type]) {
57
- return Array.from(this._byTypeCache[type]);
64
+ all() {
65
+ return Object.values(this.plugins);
58
66
  }
59
- const plugins = this.findByType(type);
60
- this._byTypeCache[type] = plugins;
61
- return Array.from(plugins);
62
- }
63
- atLeastOneByType(type) {
64
- const list = this.byType(type);
65
- if (list.length === 0) {
66
- throw new Error(`There are no plugins by type "${type}".`);
67
+ register(...args) {
68
+ this._byTypeCache = {};
69
+ const [plugins, options] = normalizeArgs(args);
70
+ PluginsContainer_assign(plugins, options, this.plugins);
67
71
  }
68
- return list;
69
- }
70
- oneByType(type) {
71
- const list = this.atLeastOneByType(type);
72
- if (list.length > 1) {
73
- throw new Error(`There is a requirement for plugin of type "${type}" to be only one registered.`);
72
+ unregister(name) {
73
+ this._byTypeCache = {};
74
+ delete this.plugins[name];
74
75
  }
75
- return list[0];
76
- }
77
- merge(input) {
78
- if (input instanceof PluginsContainer) {
79
- this.register(...input.all());
80
- return;
76
+ findByType(type) {
77
+ return Object.values(this.plugins).filter((pl)=>pl.type === type);
81
78
  }
82
- this.register(input);
83
- }
84
- mergeByType(container, type) {
85
- this.register(...container.byType(type));
86
- }
87
- all() {
88
- return Object.values(this.plugins);
89
- }
90
- register(...args) {
91
- // reset the cache when adding new plugins
92
- this._byTypeCache = {};
93
- const [plugins, options] = normalizeArgs(args);
94
- assign(plugins, options, this.plugins);
95
- }
96
- unregister(name) {
97
- // reset the cache when removing a plugin
98
- this._byTypeCache = {};
99
- delete this.plugins[name];
100
- }
101
- findByType(type) {
102
- return Object.values(this.plugins).filter(pl => pl.type === type);
103
- }
104
79
  }
80
+ export { PluginsContainer };
105
81
 
106
82
  //# sourceMappingURL=PluginsContainer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["uniqid","isOptionsObject","item","Array","isArray","type","name","normalizeArgs","args","options","length","splice","assign","plugins","target","plugin","Error","_name","skipExisting","init","PluginsContainer","_byTypeCache","constructor","register","byName","byType","from","findByType","atLeastOneByType","list","oneByType","merge","input","all","mergeByType","container","Object","values","unregister","filter","pl"],"sources":["PluginsContainer.ts"],"sourcesContent":["import type { Plugin, PluginCollection } from \"./types.js\";\nimport uniqid from \"uniqid\";\n\nexport type WithName<T extends Plugin> = T & { name: string };\n\nconst isOptionsObject = (item?: any) => item && !Array.isArray(item) && !item.type && !item.name;\nconst normalizeArgs = (args: any[]): [Plugin[], any] => {\n let options = {};\n\n // Check if last item in the plugins array is actually an options object.\n if (isOptionsObject(args[args.length - 1])) {\n [options] = args.splice(-1, 1);\n }\n\n return [args, options];\n};\n\nconst assign = (\n plugins: Plugin[] | Plugin[][],\n options: any,\n target: Record<string, any>\n): void => {\n for (const plugin of plugins) {\n if (Array.isArray(plugin)) {\n assign(plugin, options, target);\n continue;\n }\n\n if (typeof plugin !== \"object\") {\n throw new Error(\n `Could not register plugin. Expected an object, but got ${typeof plugin}.`\n );\n }\n\n if (!plugin.type) {\n let name = \"\";\n if (plugin.name) {\n name = ` \"${plugin.name}\"`;\n }\n throw new Error(`Could not register plugin${name}. Missing \"type\" definition.`);\n }\n\n let name = plugin._name || plugin.name;\n if (!name) {\n plugin.name = name = uniqid(plugin.type + \"-\");\n }\n\n // If skip existing was set to true, and a plugin with the same name was already registered, skip registration.\n if (!options.skipExisting || !target[name]) {\n target[name] = plugin;\n plugin.init && plugin.init();\n }\n }\n};\n\nexport class PluginsContainer {\n private plugins: Record<string, Plugin> = {};\n private _byTypeCache: Record<string, WithName<Plugin>[]> = {};\n\n constructor(...args: PluginCollection) {\n this.register(...args);\n }\n\n public byName<T extends Plugin>(name: T[\"name\"]) {\n if (!name) {\n return null;\n }\n /**\n * We can safely cast name as string, we know it is so.\n */\n return this.plugins[name as string] as WithName<T>;\n }\n\n public byType<T extends Plugin>(type: T[\"type\"]) {\n if (this._byTypeCache[type]) {\n return Array.from(this._byTypeCache[type]) as WithName<T>[];\n }\n const plugins = this.findByType<T>(type);\n this._byTypeCache[type] = plugins;\n return Array.from(plugins);\n }\n\n public atLeastOneByType<T extends Plugin>(type: T[\"type\"]) {\n const list = this.byType<T>(type);\n if (list.length === 0) {\n throw new Error(`There are no plugins by type \"${type}\".`);\n }\n return list;\n }\n\n public oneByType<T extends Plugin>(type: T[\"type\"]) {\n const list = this.atLeastOneByType<T>(type);\n if (list.length > 1) {\n throw new Error(\n `There is a requirement for plugin of type \"${type}\" to be only one registered.`\n );\n }\n return list[0];\n }\n\n public merge(input: PluginsContainer | PluginCollection): void {\n if (input instanceof PluginsContainer) {\n this.register(...input.all());\n return;\n }\n this.register(input);\n }\n\n public mergeByType(container: PluginsContainer, type: string): void {\n this.register(...container.byType(type));\n }\n\n public all<T extends Plugin>(): T[] {\n return Object.values(this.plugins) as T[];\n }\n\n public register(...args: any): void {\n // reset the cache when adding new plugins\n this._byTypeCache = {};\n const [plugins, options] = normalizeArgs(args);\n assign(plugins, options, this.plugins);\n }\n\n public unregister(name: string): void {\n // reset the cache when removing a plugin\n this._byTypeCache = {};\n delete this.plugins[name];\n }\n\n private findByType<T extends Plugin>(type: T[\"type\"]) {\n return Object.values(this.plugins).filter(\n (pl): pl is T => pl.type === type\n ) as WithName<T>[];\n }\n}\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,QAAQ;AAI3B,MAAMC,eAAe,GAAIC,IAAU,IAAKA,IAAI,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,IAAI,CAACA,IAAI,CAACG,IAAI,IAAI,CAACH,IAAI,CAACI,IAAI;AAChG,MAAMC,aAAa,GAAIC,IAAW,IAAsB;EACpD,IAAIC,OAAO,GAAG,CAAC,CAAC;;EAEhB;EACA,IAAIR,eAAe,CAACO,IAAI,CAACA,IAAI,CAACE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE;IACxC,CAACD,OAAO,CAAC,GAA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AC,GAAGS,KAAK,CAACC,GAAG,CAAC,CAAC,CAAC;MAC7B;IACJ;IACA,IAAI,CAACV,QAAQ,CAACS,KAAK,CAAC;EACxB;EAEOE,WAAWA,CAACC,SAA2B,EAAE9B,IAAY,EAAQ;IAChE,IAAI,CAACkB,QAAQ,CAAC,GAAGY,SAAS,CAACV,MAAM,CAACpB,IAAI,CAAC,CAAC;EAC5C;EAEO4B,GAAGA,CAAA,EAA0B;IAChC,OAAOG,MAAM,CAACC,MAAM,CAAC,IAAI,CAACxB,OAAO,CAAC;EACtC;EAEOU,QAAQA,CAAC,GAAGf,IAAS,EAAQ;IAChC;IACA,IAAI,CAACa,YAAY,GAAG,CAAC,CAAC;IACtB,MAAM,CAACR,OAAO,EAAEJ,OAAO,CAAC,GAAGF,aAAa,CAACC,IAAI,CAAC;IAC9CI,MAAM,CAACC,OAAO,EAAEJ,OAAO,EAAE,IAAI,CAACI,OAAO,CAAC;EAC1C;EAEOyB,UAAUA,CAAChC,IAAY,EAAQ;IAClC;IACA,IAAI,CAACe,YAAY,GAAG,CAAC,CAAC;IACtB,OAAO,IAAI,CAACR,OAAO,CAACP,IAAI,CAAC;EAC7B;EAEQqB,UAAUA,CAAmBtB,IAAe,EAAE;IAClD,OAAO+B,MAAM,CAACC,MAAM,CAAC,IAAI,CAACxB,OAAO,CAAC,CAAC0B,MAAM,CACpCC,EAAE,IAAcA,EAAE,CAACnC,IAAI,KAAKA,IACjC,CAAC;EACL;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PluginsContainer.js","sources":["../src/PluginsContainer.ts"],"sourcesContent":["import type { Plugin, PluginCollection } from \"./types.js\";\nimport uniqid from \"uniqid\";\n\nexport type WithName<T extends Plugin> = T & { name: string };\n\nconst isOptionsObject = (item?: any) => item && !Array.isArray(item) && !item.type && !item.name;\nconst normalizeArgs = (args: any[]): [Plugin[], any] => {\n let options = {};\n\n // Check if last item in the plugins array is actually an options object.\n if (isOptionsObject(args[args.length - 1])) {\n [options] = args.splice(-1, 1);\n }\n\n return [args, options];\n};\n\nconst assign = (\n plugins: Plugin[] | Plugin[][],\n options: any,\n target: Record<string, any>\n): void => {\n for (const plugin of plugins) {\n if (Array.isArray(plugin)) {\n assign(plugin, options, target);\n continue;\n }\n\n if (typeof plugin !== \"object\") {\n throw new Error(\n `Could not register plugin. Expected an object, but got ${typeof plugin}.`\n );\n }\n\n if (!plugin.type) {\n let name = \"\";\n if (plugin.name) {\n name = ` \"${plugin.name}\"`;\n }\n throw new Error(`Could not register plugin${name}. Missing \"type\" definition.`);\n }\n\n let name = plugin._name || plugin.name;\n if (!name) {\n plugin.name = name = uniqid(plugin.type + \"-\");\n }\n\n // If skip existing was set to true, and a plugin with the same name was already registered, skip registration.\n if (!options.skipExisting || !target[name]) {\n target[name] = plugin;\n plugin.init && plugin.init();\n }\n }\n};\n\nexport class PluginsContainer {\n private plugins: Record<string, Plugin> = {};\n private _byTypeCache: Record<string, WithName<Plugin>[]> = {};\n\n constructor(...args: PluginCollection) {\n this.register(...args);\n }\n\n public byName<T extends Plugin>(name: T[\"name\"]) {\n if (!name) {\n return null;\n }\n /**\n * We can safely cast name as string, we know it is so.\n */\n return this.plugins[name as string] as WithName<T>;\n }\n\n public byType<T extends Plugin>(type: T[\"type\"]) {\n if (this._byTypeCache[type]) {\n return Array.from(this._byTypeCache[type]) as WithName<T>[];\n }\n const plugins = this.findByType<T>(type);\n this._byTypeCache[type] = plugins;\n return Array.from(plugins);\n }\n\n public atLeastOneByType<T extends Plugin>(type: T[\"type\"]) {\n const list = this.byType<T>(type);\n if (list.length === 0) {\n throw new Error(`There are no plugins by type \"${type}\".`);\n }\n return list;\n }\n\n public oneByType<T extends Plugin>(type: T[\"type\"]) {\n const list = this.atLeastOneByType<T>(type);\n if (list.length > 1) {\n throw new Error(\n `There is a requirement for plugin of type \"${type}\" to be only one registered.`\n );\n }\n return list[0];\n }\n\n public merge(input: PluginsContainer | PluginCollection): void {\n if (input instanceof PluginsContainer) {\n this.register(...input.all());\n return;\n }\n this.register(input);\n }\n\n public mergeByType(container: PluginsContainer, type: string): void {\n this.register(...container.byType(type));\n }\n\n public all<T extends Plugin>(): T[] {\n return Object.values(this.plugins) as T[];\n }\n\n public register(...args: any): void {\n // reset the cache when adding new plugins\n this._byTypeCache = {};\n const [plugins, options] = normalizeArgs(args);\n assign(plugins, options, this.plugins);\n }\n\n public unregister(name: string): void {\n // reset the cache when removing a plugin\n this._byTypeCache = {};\n delete this.plugins[name];\n }\n\n private findByType<T extends Plugin>(type: T[\"type\"]) {\n return Object.values(this.plugins).filter(\n (pl): pl is T => pl.type === type\n ) as WithName<T>[];\n }\n}\n"],"names":["isOptionsObject","item","Array","normalizeArgs","args","options","assign","plugins","target","plugin","Error","name","uniqid","PluginsContainer","type","list","input","container","Object","pl"],"mappings":";AAKA,MAAMA,kBAAkB,CAACC,OAAeA,QAAQ,CAACC,MAAM,OAAO,CAACD,SAAS,CAACA,KAAK,IAAI,IAAI,CAACA,KAAK,IAAI;AAChG,MAAME,gBAAgB,CAACC;IACnB,IAAIC,UAAU,CAAC;IAGf,IAAIL,gBAAgBI,IAAI,CAACA,KAAK,MAAM,GAAG,EAAE,GACrC,CAACC,QAAQ,GAAGD,KAAK,MAAM,CAAC,IAAI;IAGhC,OAAO;QAACA;QAAMC;KAAQ;AAC1B;AAEA,MAAMC,0BAAS,CACXC,SACAF,SACAG;IAEA,KAAK,MAAMC,UAAUF,QAAS;QAC1B,IAAIL,MAAM,OAAO,CAACO,SAAS;YACvBH,wBAAOG,QAAQJ,SAASG;YACxB;QACJ;QAEA,IAAI,AAAkB,YAAlB,OAAOC,QACP,MAAM,IAAIC,MACN,CAAC,uDAAuD,EAAE,OAAOD,OAAO,CAAC,CAAC;QAIlF,IAAI,CAACA,OAAO,IAAI,EAAE;YACd,IAAIE,OAAO;YACX,IAAIF,OAAO,IAAI,EACXE,OAAO,CAAC,EAAE,EAAEF,OAAO,IAAI,CAAC,CAAC,CAAC;YAE9B,MAAM,IAAIC,MAAM,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;IAClB;IAEO,MAAMC,KAA0C,EAAQ;QAC3D,IAAIA,iBAAiBH,kBAAkB,YACnC,IAAI,CAAC,QAAQ,IAAIG,MAAM,GAAG;QAG9B,IAAI,CAAC,QAAQ,CAACA;IAClB;IAEO,YAAYC,SAA2B,EAAEH,IAAY,EAAQ;QAChE,IAAI,CAAC,QAAQ,IAAIG,UAAU,MAAM,CAACH;IACtC;IAEO,MAA6B;QAChC,OAAOI,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO;IACrC;IAEO,SAAS,GAAGd,IAAS,EAAQ;QAEhC,IAAI,CAAC,YAAY,GAAG,CAAC;QACrB,MAAM,CAACG,SAASF,QAAQ,GAAGF,cAAcC;QACzCE,wBAAOC,SAASF,SAAS,IAAI,CAAC,OAAO;IACzC;IAEO,WAAWM,IAAY,EAAQ;QAElC,IAAI,CAAC,YAAY,GAAG,CAAC;QACrB,OAAO,IAAI,CAAC,OAAO,CAACA,KAAK;IAC7B;IAEQ,WAA6BG,IAAe,EAAE;QAClD,OAAOI,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CACrC,CAACC,KAAgBA,GAAG,IAAI,KAAKL;IAErC;AACJ"}
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PluginsContainer } from "./PluginsContainer.js";
2
- import { AsyncPluginsContainer } from "./AsyncPluginsContainer.js";
3
- import { Plugin } from "./Plugin.js";
4
2
  const plugins = new PluginsContainer();
5
- export { Plugin, PluginsContainer, plugins, AsyncPluginsContainer };
3
+ export { AsyncPluginsContainer } from "./AsyncPluginsContainer.js";
4
+ export { Plugin } from "./Plugin.js";
5
+ export { PluginsContainer, plugins };
6
6
 
7
7
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["PluginsContainer","AsyncPluginsContainer","Plugin","plugins"],"sources":["index.ts"],"sourcesContent":["import { PluginsContainer } from \"./PluginsContainer.js\";\nimport { AsyncPluginsContainer } from \"./AsyncPluginsContainer.js\";\nimport { Plugin } from \"./Plugin.js\";\n\nconst plugins = new PluginsContainer();\n\nexport { Plugin, PluginsContainer, plugins, AsyncPluginsContainer };\n"],"mappings":"AAAA,SAASA,gBAAgB;AACzB,SAASC,qBAAqB;AAC9B,SAASC,MAAM;AAEf,MAAMC,OAAO,GAAG,IAAIH,gBAAgB,CAAC,CAAC;AAEtC,SAASE,MAAM,EAAEF,gBAAgB,EAAEG,OAAO,EAAEF,qBAAqB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { PluginsContainer } from \"./PluginsContainer.js\";\nimport { AsyncPluginsContainer } from \"./AsyncPluginsContainer.js\";\nimport { Plugin } from \"./Plugin.js\";\n\nconst plugins = new PluginsContainer();\n\nexport { Plugin, PluginsContainer, plugins, AsyncPluginsContainer };\n"],"names":["plugins","PluginsContainer"],"mappings":";AAIA,MAAMA,UAAU,IAAIC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/plugins",
3
- "version": "6.3.0-beta.4",
3
+ "version": "6.4.0-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -21,14 +21,14 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/uniqid": "5.3.4",
24
- "@webiny/build-tools": "6.3.0-beta.4",
24
+ "@webiny/build-tools": "6.4.0-beta.0",
25
25
  "rimraf": "6.1.3",
26
26
  "typescript": "6.0.3",
27
- "vitest": "4.1.5"
27
+ "vitest": "4.1.6"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public",
31
31
  "directory": "dist"
32
32
  },
33
- "gitHead": "7cefe15431dbd65504e1f58147dc9e55bcbfa693"
33
+ "gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
34
34
  }
package/types.js CHANGED
@@ -1,3 +1 @@
1
1
  export { PluginsContainer } from "./PluginsContainer.js";
2
-
3
- //# sourceMappingURL=types.js.map
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["PluginsContainer"],"sources":["types.ts"],"sourcesContent":["export { PluginsContainer } from \"./PluginsContainer.js\";\n\nexport type Plugin<T = Record<string, any>> = {\n type: string;\n name?: string;\n init?: () => void;\n [key: string]: any;\n} & T;\n\nexport type PluginCollection = (Plugin | PluginFactory | PluginCollection)[];\n\nexport type PluginFactory = () => Promise<Plugin | PluginCollection>;\n"],"mappings":"AAAA,SAASA,gBAAgB","ignoreList":[]}