plugin-tls 4.6.0 → 4.7.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/dist/{createTierModeOptionsPluginHost-3jPWAW92.js → createTierModeOptionsPluginHost-D-fKYlcA.js} +202 -188
- package/dist/createTierModeOptionsPluginHost-DyDtXKNW.cjs +1 -0
- package/dist/index-node.cjs +1 -1
- package/dist/index-node.js +3 -3
- package/dist/index-web.cjs +1 -1
- package/dist/index-web.js +10 -10
- package/dist/index.cjs +1 -1
- package/dist/index.js +146 -120
- package/dist/plugin-manager/ExtendManager.d.ts +15 -5
- package/dist/plugin-manager/ExtendManager.d.ts.map +1 -1
- package/dist/plugin-manager/PluginExtendManager.d.ts +20 -5
- package/dist/plugin-manager/PluginExtendManager.d.ts.map +1 -1
- package/dist/plugin-manager/PluginManager.d.ts +20 -6
- package/dist/plugin-manager/PluginManager.d.ts.map +1 -1
- package/dist/plugin-manager/index.d.ts +1 -0
- package/dist/plugin-manager/index.d.ts.map +1 -1
- package/dist/plugin-manager/type.d.ts +2 -0
- package/dist/plugin-manager/type.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/createTierModeOptionsPluginHost-GosxwlJk.cjs +0 -1
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type AbstractClassType } from "type-tls";
|
|
2
2
|
import type { AnyIPlugin, IPlugin, PluginUseArgs, PluginUseReturn } from "./IPlugin";
|
|
3
3
|
import { Destroyable } from "@gby/destroyable";
|
|
4
|
+
import type { AsyncableArray } from "./type";
|
|
4
5
|
/**
|
|
5
6
|
* 插件管理者
|
|
6
7
|
*
|
|
7
8
|
* @remarks
|
|
8
9
|
* 负责管理插件的注册、应用 等
|
|
9
|
-
*
|
|
10
|
+
* 支持插件的级联(通过 parent):当子类创建了子类插件管理者时,为了能让父类插件管理者的插件生效,需要将父类插件管理者设置为其 parent
|
|
10
11
|
*/
|
|
11
12
|
export declare class PluginManager<Host, HostClass = AbstractClassType<Host>> extends Destroyable {
|
|
13
|
+
/**
|
|
14
|
+
* 父级插件管理者
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* 当子类创建了子类插件管理者时,为了能让父类插件管理者的插件生效,需要将父类插件管理者设置为其 parent
|
|
18
|
+
*/
|
|
19
|
+
parent?: PluginManager<Host, HostClass> | null;
|
|
12
20
|
/**
|
|
13
21
|
* 插件的宿主
|
|
14
22
|
*/
|
|
@@ -20,7 +28,7 @@ export declare class PluginManager<Host, HostClass = AbstractClassType<Host>> ex
|
|
|
20
28
|
/**
|
|
21
29
|
* @param host - 插件的宿主
|
|
22
30
|
*/
|
|
23
|
-
constructor(host?: HostClass);
|
|
31
|
+
constructor(host?: HostClass, parent?: PluginManager<Host, HostClass> | null);
|
|
24
32
|
destroyThis(): any;
|
|
25
33
|
/**
|
|
26
34
|
* 是否注册了插件
|
|
@@ -28,6 +36,12 @@ export declare class PluginManager<Host, HostClass = AbstractClassType<Host>> ex
|
|
|
28
36
|
* @returns 是否注册了插件
|
|
29
37
|
*/
|
|
30
38
|
hasUsed(plugin: any): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 获取插件 或 扩展 的 use 的返回值
|
|
41
|
+
* @param plugin
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
getUseReturn(plugin: any): any;
|
|
31
45
|
/**
|
|
32
46
|
* 使用插件、注册插件
|
|
33
47
|
* @param plugin - 插件
|
|
@@ -50,7 +64,7 @@ export declare class PluginManager<Host, HostClass = AbstractClassType<Host>> ex
|
|
|
50
64
|
* 如果插件的 created 方法返回 Promise,则会等待 Promise resolve
|
|
51
65
|
* @param hostInst - 插件宿主的新实例
|
|
52
66
|
*/
|
|
53
|
-
onCreate(hostInst: Host, ...args: any):
|
|
67
|
+
onCreate(hostInst: Host, ...args: any): AsyncableArray;
|
|
54
68
|
/**
|
|
55
69
|
* 插件宿主创建实例时调用
|
|
56
70
|
*
|
|
@@ -59,7 +73,7 @@ export declare class PluginManager<Host, HostClass = AbstractClassType<Host>> ex
|
|
|
59
73
|
* @param hostInst - 插件宿主的新实例
|
|
60
74
|
* @param args - 初始化宿主实例时的参数
|
|
61
75
|
*/
|
|
62
|
-
onInit(hostInst: Host, ...args: any):
|
|
76
|
+
onInit(hostInst: Host, ...args: any): AsyncableArray;
|
|
63
77
|
/**
|
|
64
78
|
* 插件宿主被销毁时调用
|
|
65
79
|
*
|
|
@@ -67,6 +81,6 @@ export declare class PluginManager<Host, HostClass = AbstractClassType<Host>> ex
|
|
|
67
81
|
* 会调用每个插件的 {@link IPlugin.onDestroy} 方法
|
|
68
82
|
* @param hostInst - 被销毁的插件实例
|
|
69
83
|
*/
|
|
70
|
-
onDestroy(hostInst: Host):
|
|
84
|
+
onDestroy(hostInst: Host): AsyncableArray;
|
|
71
85
|
}
|
|
72
86
|
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/plugin-manager/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/plugin-manager/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,iBAAiB,EAAiB,MAAM,UAAU,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAE7C;;;;;;GAMG;AACH,qBAAa,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAE,SAAQ,WAAW;IACrF;;;;;OAKG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,G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AA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin-manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/plugin-manager/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,GAAG,EAAE,GAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const m=require("@gby/destroyable"),c=require("deepmerge-ts"),d=require("com-tools");function u(i,...e){for(const t of e){const n=Object.getOwnPropertyDescriptors(t);Object.defineProperties(i,n)}return i}function E(i,e,t){let n=Object.getOwnPropertyDescriptors(e);return t&&d.omitMembers(n,t),Object.defineProperties(i,n),i}function U(i,e,t){let n=Object.getOwnPropertyDescriptors(e);return t?Object.defineProperties(i,d.removeUndefined(d.pickMembers(n,t))):Object.defineProperties(i,n),i}function V(i,e){return e}function N(i){return function(t){return t}}function I(i,e){return u(i,e),e}function v(i){return function(t){return u(i,t),t}}function H(i,e){return u(i,e),i}function k(i){return function(t){return u(i,t),i}}const b=["onCreate","onInit","onDestroy"];function C(i){const e={...i};for(const t of b)typeof e[t]=="function"&&delete e[t];return e}function T(i,e){let t=Object.getOwnPropertyDescriptors(e);for(const n of b)typeof e[n]=="function"&&delete t[n];return Object.defineProperties(i,t),i}function j(i,e){return e}function S(i){return function(t){return t}}function B(i,e){return u(i.prototype,e),e}function A(i){return function(t){return u(i.prototype,t),t}}function q(i,e){return u(i.prototype,e),i}function z(i){return function(t){return u(i.prototype,t),i}}function F(i){return i&&typeof i.onUse=="function"}const l=Symbol("extend");class g extends m.Destroyable{host;plugins=new Map;constructor(e){super(),e&&(this.host=e)}destroyThis(){return this.plugins.clear(),this.host=null,super.destroyThis()}hasUsed(e){return this.plugins.has(e)}isPlugin(e){const{plugins:t}=this;return t.has(e)?t.get(e)!==l:F(e)}useExtend(e){const{plugins:t}=this;return t.has(e)?t.get(e):(T(this.host.prototype,e),t.set(e,l),e)}instUseExtend(e,t,...n){const{plugins:s}=this;return s.has(t)?s.get(t):(this.useExtend(t),t.onCreate?.call(e,e,...n),t)}usePlugin(e,...t){const{plugins:n}=this;if(n.has(e))return n.get(e);const s=e.onUse(this.host,...t);return n.set(e,s),s}instUsePlugin(e,t,...n){const{plugins:s}=this;if(s.has(t))return s.get(t);const r=this.usePlugin(t,...n);return t.onCreate?.(e),r}onCreate(e,...t){const n=[];for(const[s,r]of this.plugins)if(s.onCreate){const o=r===l?s.onCreate:s.onCreate.bind(s);n.push(o)}return d.serialCallFuns(n,e,[e,...t])}onInit(e,...t){const n=[];for(const[s,r]of this.plugins)if(s.onInit){const o=r===l?s.onInit:s.onInit.bind(s);n.push(o)}return d.serialCallFuns(n,e,[e,...t])}onDestroy(e){const t=[];for(const[n,s]of this.plugins)if(n.onDestroy){const r=s===l?n.onDestroy:n.onDestroy.bind(n);t.push(r)}return t.reverse(),d.serialCallFuns(t,e,[e])}}function M(i){const e=i.split(".");return e[0]===""&&e.shift(),e}function f(i,e){for(const t of e)if(i=i[t],i==null)return;return i}function K(i,e){return f(i,M(e))}function x(i,e,t){const n=e.pop(),s=e.length;let r=0;for(;r<s;){const o=i[e[r]];if(o==null)break;i=o,r++}e=e.slice(r);for(const o of e)i=i[o]={};return i[n]=t,i}function $(i,e,t){return x(i,M(e),t)}const O={UndefinedAndNull:function(e){return e==null},Undefined:function(e){return e===void 0},Null:function(e){return e===null}};class w{freezeMember=!0;fullOption=new Proxy(this,{get:function(e,t,n){const s=e.plainFullOption[t];return e.freezeMember?Object.freeze(s):s},set:function(e,t,n,s){return e.setMember(t,n,!1),!0},has:function(e,t){return t in e.plainFullOption},getOwnPropertyDescriptor:function(e,t){return Object.getOwnPropertyDescriptor(e.plainFullOption,t)},ownKeys:function(e){return Reflect.ownKeys(e.plainFullOption)},deleteProperty:function(e,t){return e.setMember(t,void 0),!0},defineProperty:function(e,t,n){return Object.defineProperty(e.option,t,n),!0}});setOption(e,t){const n=t?c.deepmergeInto(this.option,e):Object.assign(this.option,e);return this.updateFullOption(),n}get undefinedValue(){return this._undefinedValue}set undefinedValue(e){this._undefinedValue=e,this.isUndefined=O[e]||O.UndefinedAndNull}_undefinedValue="UndefinedAndNull";isUndefined=O.UndefinedAndNull;getMember(e){return this.option[e]}setMember(e,t,n){const s=this.option;if(t===void 0)delete s[e];else{const r=s[e];n&&r&&typeof r=="object"?c.deepmergeInto(r,t):s[e]=t}this.updateFullOption()}getValue(e){return f(this.option,e)}setValue(e,t,n){const s=this.option;let r;n&&(r=f(s,e))&&typeof r=="object"?c.deepmergeInto(r,t):x(this.option,e,t),this.updateFullOption()}}class a extends w{constructor(e,t){super(),e&&(this.option=e),t&&(this.extends=t)}get extends(){return this._extends}set extends(e){this._extends=e,this.updateFullOption()}_extends=null;option={};get plainFullOption(){let e=this._plainFullOption;if(e)return e;const{extends:t,option:n}=this;if(e=n,t){const s=t.plainFullOption;e=c.deepmerge(s,n)}return this._plainFullOption=e}_plainFullOption=null;updateFullOption(){this._plainFullOption=null}getMember(e){const t=this.option[e];if(!this.isUndefined(t))return t;const n=this.extends;if(n)return n.getMember(e)}getValue(e){const t=super.getValue(e);if(!this.isUndefined(t))return t;const n=this.extends;if(n)return n.getValue(e)}}function L(i,e){const{name:t}=e,n=`_${t}`;return{get:function(){return this[n]||(this[n]=new a(void 0,this.constructor[t]))}}}class D extends w{constructor(e,t){super(),t&&this.setModeOption(e,t),this.mode=e}modes={};get mode(){return this._mode||(this.mode=this.modeNames[0])}set mode(e){this._mode=e,this.hasMode(e)||this.setModeOption(e,{}),this.updateFullOption()}_mode;get modeNames(){return this._modeNames||(this._modeNames=this.getModeNames())}_modeNames=null;getModeNames(){return Object.keys(this.modes)}hasMode(e){return!!this.modes[e]}get optionManager(){return this.modes[this.mode]}get option(){return this.optionManager.option}get plainFullOption(){return this._plainFullOption??(this._plainFullOption=this.getFullModeOption(this.mode))}_plainFullOption=null;updateFullOption(){this._plainFullOption=null,this._modeNames=null}getModeOption(e){return this.modes[e].option}getFullModeOption(e){return this.modes[e]?.plainFullOption}setModeOption(e,t,n,s){const{modes:r}=this,o=r[e]||(r[e]=new a);if(o.setOption(t,n),s){const _=r[s];_&&(o.extends=_)}return this.updateFullOption(),o}}class p extends D{constructor(e,t,n){super(e,t),n&&(this.extends=n)}get extends(){return this._extends}set extends(e){this._extends=e,this.updateFullOption()}_extends=null;getFullModeOption(e){const{modes:t,extends:n}=this,s=t[e]?.plainFullOption;if(n){const r=n.getFullModeOption(e);return s?c.deepmerge(r,s):r}return s}getModeNames(){const{modes:e,extends:t}=this,n=Object.keys(e);if(!t)return n;const s=t.getModeNames();return[...new Set([...n,...s])]}hasModeOnTier(e){if(this.hasMode(e))return!0;const t=this.extends;return t?t.hasModeOnTier(e):!1}get optionManager(){return this.getModeOptionManager(this.mode)}getModeOptionManager(e){const t=this.modes[e];return t||(this.extends?.getModeOptionManager(e)?this.setModeOption(e,{}):null)}getMember(e){const t=this.optionManager.getMember(e);if(!this.isUndefined(t))return t;const n=this.extends;if(n)return n.getMember(e)}getValue(e){const t=this.optionManager.getValue(e);if(!this.isUndefined(t))return t;const n=this.extends;if(n)return n.getValue(e)}}function R(i,e){const{name:t}=e,n=`_${t}`;return{get:function(){return this[n]||(this[n]=new p(this.constructor[t].mode,void 0,this.constructor[t]))}}}class y extends m.Destroyable{static isolatedPluginManager=!1;static get pluginManager(){return this.isolatedPluginManager&&!this.hasOwnProperty("_pluginManager")&&(this._pluginManager=new g(this)),this._pluginManager}static _pluginManager=new g(this);get pluginManager(){return this.constructor.pluginManager}static usePlugin(e,...t){return this.pluginManager.usePlugin(e,...t)}static useExtend(e){return this.pluginManager.useExtend(e)}static hasUsed(e){return this.pluginManager.hasUsed(e)}usePlugin(e,...t){return this.pluginManager.instUsePlugin(this,e,...t)}useExtend(e,...t){return this.pluginManager.instUseExtend(this,e,...t)}init(...e){return this.pluginManager.onInit(this,...e)}destroyThis(){const e=this.pluginManager.onDestroy(this);return e instanceof Promise?e.finally(()=>super.destroyThis()):super.destroyThis()}}class G extends y{static defaultOptions=new a;get defaultOptions(){return this._defaultOptions||(this._defaultOptions=new a(void 0,this.constructor.defaultOptions))}_defaultOptions;constructor(e){super(),this.defaultOptions.option=e}}function P(i){const e=m.createDestroyableSubClass(i);return class extends e{static isolatedPluginManager=!1;static get pluginManager(){return this.isolatedPluginManager&&!this.hasOwnProperty("_pluginManager")&&(this._pluginManager=new g(this)),this._pluginManager}static _pluginManager=new g(this);get pluginManager(){return this.constructor.pluginManager}static usePlugin(n,...s){return this.pluginManager.usePlugin(n,...s)}static useExtend(n){return this.pluginManager.useExtend(n)}static hasUsed(n){return this.pluginManager.hasUsed(n)}usePlugin(n,...s){return this.pluginManager.instUsePlugin(this,n,...s)}useExtend(n,...s){return this.pluginManager.instUseExtend(this,n,...s)}init(...n){return this.pluginManager.onInit(this,...n)}destroyThis(){const n=this.pluginManager.onDestroy(this);return n instanceof Promise?n.finally(()=>super.destroyThis()):super.destroyThis()}}}function J(i){const e=P(i);return class extends e{static defaultOptions=new a;get defaultOptions(){return this._defaultOptions||(this._defaultOptions=new a(void 0,this.constructor.defaultOptions))}_defaultOptions;constructor(n){super(),this.defaultOptions.option=n}}}const h="common";class Q extends y{static modeOptions=new p(h);get modeOptions(){return this._modeOptions||(this._modeOptions=new p(h,void 0,this.constructor.modeOptions))}_modeOptions;get mode(){return this.modeOptions.mode}set mode(e){this.modeOptions.mode=e}get options(){return this.modeOptions.plainFullOption}constructor(e){super(),this.modeOptions.setOption(e)}}function W(i){const e=P(i);return class extends e{static modeOptions=new p(h);get modeOptions(){return this._modeOptions||(this._modeOptions=new p(h,void 0,this.constructor.modeOptions))}_modeOptions;get mode(){return this.modeOptions.mode}set mode(n){this.modeOptions.mode=n}get options(){return this.modeOptions.plainFullOption}constructor(n){super(),this.modeOptions.setOption(n)}}}exports.ModeOptions=D;exports.PluginExtendManager=g;exports.PluginHost=y;exports.TierModeOptions=p;exports.TierModeOptionsPluginHost=Q;exports.TierOptions=a;exports.TierOptionsPluginHost=G;exports.commonModeName=h;exports.createDefineIExtend=S;exports.createDefineMixin=N;exports.createIExtendTarget=z;exports.createMixinTarget=k;exports.createPluginHost=P;exports.createTargetIExtend=A;exports.createTargetMixin=v;exports.createTierModeOptionsPluginHost=W;exports.createTierOptionsPluginHost=J;exports.defineIExtend=j;exports.defineMixin=V;exports.extendMark=l;exports.getPropertyValue=f;exports.getPropertyValueByPath=K;exports.iextendTarget=q;exports.isPlugin=F;exports.mixin=u;exports.mixinByOmit=E;exports.mixinByPick=U;exports.mixinIExtend=T;exports.mixinTarget=H;exports.parsePropertyPath=M;exports.pickHostExtendMembers=C;exports.setPropertyValue=x;exports.setPropertyValueByPath=$;exports.targetIExtend=B;exports.targetMixin=I;exports.tierModeOptionsDecorator=R;exports.tierOptionsDecorator=L;
|