plugin-tls 3.6.0 → 4.0.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.
Files changed (45) hide show
  1. package/dist/Destroyable-BqvuD4gL-Cmk1ocqj.cjs +1 -0
  2. package/dist/Destroyable-BqvuD4gL-D50ZO9eN.js +129 -0
  3. package/dist/createTierModeOptionsPluginHost-C3kmxB00.cjs +1 -0
  4. package/dist/createTierModeOptionsPluginHost-CeND_z6P.js +852 -0
  5. package/dist/index-node.cjs +1 -1
  6. package/dist/index-node.d.ts +0 -1
  7. package/dist/index-node.d.ts.map +1 -1
  8. package/dist/index-node.js +254 -56
  9. package/dist/index-web.cjs +1 -1
  10. package/dist/index-web.d.ts +0 -1
  11. package/dist/index-web.d.ts.map +1 -1
  12. package/dist/index-web.js +324 -56
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.ts +4 -5
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +628 -60
  17. package/dist/options/index-node.d.ts +0 -1
  18. package/dist/options/index-node.d.ts.map +1 -1
  19. package/dist/options/index-web.d.ts +0 -1
  20. package/dist/options/index-web.d.ts.map +1 -1
  21. package/dist/options/{index-com.d.ts → index.d.ts} +1 -1
  22. package/dist/options/index.d.ts.map +1 -0
  23. package/dist/options/plugins/tier-mode-options/type.d.ts +1 -1
  24. package/dist/options/plugins/tier-mode-options/type.d.ts.map +1 -1
  25. package/dist/options/plugins/tier-options/type.d.ts +1 -1
  26. package/dist/options/plugins/tier-options/type.d.ts.map +1 -1
  27. package/dist/plugin-host/PluginHostEventEmitter.d.ts +2 -2
  28. package/dist/plugin-host/PluginHostEventEmitter.d.ts.map +1 -1
  29. package/dist/plugin-host/PluginHostEventTarget.d.ts +1 -1
  30. package/dist/plugin-host/PluginHostEventTarget.d.ts.map +1 -1
  31. package/dist/plugin-host/index-node.d.ts +0 -1
  32. package/dist/plugin-host/index-node.d.ts.map +1 -1
  33. package/dist/plugin-host/index-web.d.ts +0 -1
  34. package/dist/plugin-host/index-web.d.ts.map +1 -1
  35. package/dist/plugin-host/{index-com.d.ts → index.d.ts} +1 -1
  36. package/dist/plugin-host/index.d.ts.map +1 -0
  37. package/package.json +2 -7
  38. package/dist/TierOptionsPluginHostEventEmitter-BjGVIRN6.cjs +0 -1
  39. package/dist/TierOptionsPluginHostEventEmitter-DXTNpSmS.js +0 -131
  40. package/dist/TierOptionsPluginHostEventTarget-Bok_zzQ1.js +0 -131
  41. package/dist/TierOptionsPluginHostEventTarget-DqfVEP_L.cjs +0 -1
  42. package/dist/decorator-Culqv4k6.js +0 -1454
  43. package/dist/decorator-Wf_x4qDo.cjs +0 -1
  44. package/dist/options/index-com.d.ts.map +0 -1
  45. package/dist/plugin-host/index-com.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ "use strict";const n=require("com-tools");class h{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const s=this._destroyers.indexOf(e);return this._destroyers.splice(s,1),e}disposeObj(e,s){const t=s?function(){return e.destroySync()}:function(){return e.destroy()};return this.disposeFun(t),e.__destroyable_destroyer=t,e}cancelDisposeObj(e){const s=e.__destroyable_destroyer;return s&&this.cancelDisposeFun(s),e}dispose(e,s){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,s)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const s=this._destroyers[e];try{s()}catch(t){console.error("销毁函数在同步销毁时出错",this,s,t)}}this._destroyers.length=0;try{this.destroyThis()}catch(s){console.error("destroyThis 在异步销毁时出错",this,s)}return o(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const s=n.serialCallAllFuns(e,this,null,(t,i)=>{console.error("销毁函数在串行销毁时出错",this,i,t)});return s instanceof Promise?s.then(()=>(o(this),!0)):(o(this),!0)}}function c(){throw"已销毁"}function o(r){for(var e in r)!(e in h.prototype)&&typeof r[e]=="function"&&(r[e]=c);return r._isDestroyed=!0,!0}exports.i=o;
@@ -0,0 +1,129 @@
1
+ import { serialCallAllFuns as n } from "com-tools";
2
+ class h {
3
+ /**
4
+ * 引用计数
5
+ * @remarks
6
+ * 引用计数为 0 时,对象才会被销毁
7
+ */
8
+ refCount = 0;
9
+ /**
10
+ * 是否已经销毁
11
+ */
12
+ get isDestroyed() {
13
+ return this._isDestroyed;
14
+ }
15
+ _isDestroyed = !1;
16
+ /**
17
+ * 是否可以销毁
18
+ */
19
+ get canDestroy() {
20
+ return !this.isDestroyed && this.refCount <= 0;
21
+ }
22
+ /**
23
+ * 销毁者
24
+ */
25
+ _destroyers = [];
26
+ /**
27
+ * 添加销毁者
28
+ * @param fun
29
+ * @returns 返回销毁者的顺序
30
+ */
31
+ disposeFun(e) {
32
+ return this._destroyers.push(e), e;
33
+ }
34
+ /**
35
+ * 取消销毁者函数
36
+ * @param fun
37
+ * @returns
38
+ */
39
+ cancelDisposeFun(e) {
40
+ const s = this._destroyers.indexOf(e);
41
+ return this._destroyers.splice(s, 1), e;
42
+ }
43
+ /**
44
+ * 添加销毁对象
45
+ * @param obj
46
+ * @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
47
+ * @returns
48
+ */
49
+ disposeObj(e, s) {
50
+ const t = s ? function() {
51
+ return e.destroySync();
52
+ } : function() {
53
+ return e.destroy();
54
+ };
55
+ return this.disposeFun(t), e.__destroyable_destroyer = t, e;
56
+ }
57
+ /**
58
+ * 取消销毁者函数
59
+ * @param fun
60
+ * @returns
61
+ */
62
+ cancelDisposeObj(e) {
63
+ const s = e.__destroyable_destroyer;
64
+ return s && this.cancelDisposeFun(s), e;
65
+ }
66
+ dispose(e, s) {
67
+ return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, s);
68
+ }
69
+ cancelDispose(e) {
70
+ return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
71
+ }
72
+ /**
73
+ * 自己的销毁方法
74
+ * @remarks
75
+ * 子类根据需要进行重载
76
+ */
77
+ destroyThis() {
78
+ }
79
+ /**
80
+ * 同步销毁
81
+ * @remarks
82
+ * 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
83
+ */
84
+ destroySync() {
85
+ if (!this.canDestroy) return this.isDestroyed;
86
+ let e = this._destroyers.length;
87
+ for (; --e >= 0; ) {
88
+ const s = this._destroyers[e];
89
+ try {
90
+ s();
91
+ } catch (t) {
92
+ console.error("销毁函数在同步销毁时出错", this, s, t);
93
+ }
94
+ }
95
+ this._destroyers.length = 0;
96
+ try {
97
+ this.destroyThis();
98
+ } catch (s) {
99
+ console.error("destroyThis 在异步销毁时出错", this, s);
100
+ }
101
+ return o(this), !0;
102
+ }
103
+ /**
104
+ * 串行销毁
105
+ * @remarks
106
+ * 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
107
+ * @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
108
+ */
109
+ destroy() {
110
+ if (!this.canDestroy) return this.isDestroyed;
111
+ const e = this._destroyers.toReversed();
112
+ e.push(this.destroyThis), this._destroyers.length = 0;
113
+ const s = n(e, this, null, (t, i) => {
114
+ console.error("销毁函数在串行销毁时出错", this, i, t);
115
+ });
116
+ return s instanceof Promise ? s.then(() => (o(this), !0)) : (o(this), !0);
117
+ }
118
+ }
119
+ function c() {
120
+ throw "已销毁";
121
+ }
122
+ function o(r) {
123
+ for (var e in r)
124
+ !(e in h.prototype) && typeof r[e] == "function" && (r[e] = c);
125
+ return r._isDestroyed = !0, !0;
126
+ }
127
+ export {
128
+ o as i
129
+ };
@@ -0,0 +1 @@
1
+ "use strict";const O=require("@gby/destroyable"),d=require("deepmerge-ts"),g=require("com-tools"),_=["onCreate","onInit","onDestroy"];function w(i){const t={...i};for(const e of _)typeof t[e]=="function"&&delete t[e];return t}function F(i,t){let e=Object.getOwnPropertyDescriptors(t);for(const n of _)typeof t[n]=="function"&&delete e[n];return Object.defineProperties(i,e),i}function b(i){return i&&typeof i.onUse=="function"}const l=Symbol("extend");class p extends O.Destroyable{host;plugins=new Map;constructor(t){super(),t&&(this.host=t)}destroyThis(){return this.plugins.clear(),this.host=null,super.destroyThis()}hasUsed(t){return this.plugins.has(t)}isPlugin(t){const{plugins:e}=this;return e.has(t)?e.get(t)!==l:b(t)}useExtend(t){const{plugins:e}=this;return e.has(t)?e.get(t):(F(this.host.prototype,t),e.set(t,l),t)}instUseExtend(t,e,...n){const{plugins:s}=this;return s.has(e)?s.get(e):(this.useExtend(e),e.onCreate?.call(t,t,...n),e)}usePlugin(t,...e){const{plugins:n}=this;if(n.has(t))return n.get(t);const s=t.onUse(this.host,...e);return n.set(t,s),s}instUsePlugin(t,e,...n){const{plugins:s}=this;if(s.has(e))return s.get(e);const o=this.usePlugin(e,...n);return e.onCreate?.(t),o}onCreate(t,...e){const n=[];for(const[s,o]of this.plugins)if(s.onCreate){const r=o===l?s.onCreate:s.onCreate.bind(s);n.push(r)}return g.serialCallFuns(n,t,[t,...e])}onInit(t,...e){const n=[];for(const[s,o]of this.plugins)if(s.onInit){const r=o===l?s.onInit:s.onInit.bind(s);n.push(r)}return g.serialCallFuns(n,t,[t,...e])}onDestroy(t){const e=[];for(const[n,s]of this.plugins)if(n.onDestroy){const o=s===l?n.onDestroy:n.onDestroy.bind(n);e.push(o)}return e.reverse(),g.serialCallFuns(e,t,[t])}}function m(i){const t=i.split(".");return t[0]===""&&t.shift(),t}function h(i,t){for(const e of t)if(i=i[e],i==null)return;return i}function V(i,t){return h(i,m(t))}function M(i,t,e){const n=t.pop(),s=t.length;let o=0;for(;o<s;){const r=i[t[o]];if(r==null)break;i=r,o++}t=t.slice(o);for(const r of t)i=i[r]={};return i[n]=e,i}function N(i,t,e){return M(i,m(t),e)}const f={UndefinedAndNull:function(t){return t==null},Undefined:function(t){return t===void 0},Null:function(t){return t===null}};class U{freezeMember=!0;fullOption=new Proxy(this,{get:function(t,e,n){const s=t.plainFullOption[e];return t.freezeMember?Object.freeze(s):s},set:function(t,e,n,s){return t.setMember(e,n,!1),!0},has:function(t,e){return e in t.plainFullOption},getOwnPropertyDescriptor:function(t,e){return Object.getOwnPropertyDescriptor(t.plainFullOption,e)},ownKeys:function(t){return Reflect.ownKeys(t.plainFullOption)},deleteProperty:function(t,e){return t.setMember(e,void 0),!0},defineProperty:function(t,e,n){return Object.defineProperty(t.option,e,n),!0}});setOption(t,e){const n=e?d.deepmergeInto(this.option,t):Object.assign(this.option,t);return this.updateFullOption(),n}get undefinedValue(){return this._undefinedValue}set undefinedValue(t){this._undefinedValue=t,this.isUndefined=f[t]||f.UndefinedAndNull}_undefinedValue="UndefinedAndNull";isUndefined=f.UndefinedAndNull;getMember(t){return this.option[t]}setMember(t,e,n){const s=this.option;if(e===void 0)delete s[t];else{const o=s[t];n&&o&&typeof o=="object"?d.deepmergeInto(o,e):s[t]=e}this.updateFullOption()}getValue(t){return h(this.option,t)}setValue(t,e,n){const s=this.option;let o;n&&(o=h(s,t))&&typeof o=="object"?d.deepmergeInto(o,e):M(this.option,t,e),this.updateFullOption()}}class u extends U{constructor(t,e){super(),t&&(this.option=t),e&&(this.extends=e)}get extends(){return this._extends}set extends(t){this._extends=t,this.updateFullOption()}_extends=null;option={};get plainFullOption(){let t=this._plainFullOption;if(t)return t;const{extends:e,option:n}=this;if(t=n,e){const s=e.plainFullOption;t=d.deepmerge(s,n)}return this._plainFullOption=t}_plainFullOption=null;updateFullOption(){this._plainFullOption=null}getMember(t){const e=this.option[t];if(!this.isUndefined(e))return e;const n=this.extends;if(n)return n.getMember(t)}getValue(t){const e=super.getValue(t);if(!this.isUndefined(e))return e;const n=this.extends;if(n)return n.getValue(t)}}function D(i,t){const{name:e}=t,n=`_${e}`;return{get:function(){return this[n]||(this[n]=new u(void 0,this.constructor[e]))}}}class T extends U{constructor(t,e){super(),e&&this.setModeOption(t,e),this.mode=t}modes={};get mode(){return this._mode||(this.mode=this.modeNames[0])}set mode(t){this._mode=t,this.hasMode(t)||this.setModeOption(t,{}),this.updateFullOption()}_mode;get modeNames(){return this._modeNames||(this._modeNames=this.getModeNames())}_modeNames=null;getModeNames(){return Object.keys(this.modes)}hasMode(t){return!!this.modes[t]}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(t){return this.modes[t].option}getFullModeOption(t){return this.modes[t]?.plainFullOption}setModeOption(t,e,n,s){const{modes:o}=this,r=o[t]||(o[t]=new u);if(r.setOption(e,n),s){const y=o[s];y&&(r.extends=y)}return this.updateFullOption(),r}}class a extends T{constructor(t,e,n){super(t,e),n&&(this.extends=n)}get extends(){return this._extends}set extends(t){this._extends=t,this.updateFullOption()}_extends=null;getFullModeOption(t){const{modes:e,extends:n}=this,s=e[t]?.plainFullOption;if(n){const o=n.getFullModeOption(t);return s?d.deepmerge(o,s):o}return s}getModeNames(){const{modes:t,extends:e}=this,n=Object.keys(t);if(!e)return n;const s=e.getModeNames();return[...new Set([...n,...s])]}hasModeOnTier(t){if(this.hasMode(t))return!0;const e=this.extends;return e?e.hasModeOnTier(t):!1}get optionManager(){return this.getModeOptionManager(this.mode)}getModeOptionManager(t){const e=this.modes[t];return e||(this.extends?.getModeOptionManager(t)?this.setModeOption(t,{}):null)}getMember(t){const e=this.optionManager.getMember(t);if(!this.isUndefined(e))return e;const n=this.extends;if(n)return n.getMember(t)}getValue(t){const e=this.optionManager.getValue(t);if(!this.isUndefined(e))return e;const n=this.extends;if(n)return n.getValue(t)}}function H(i,t){const{name:e}=t,n=`_${e}`;return{get:function(){return this[n]||(this[n]=new a(this.constructor[e].mode,void 0,this.constructor[e]))}}}class P extends O.Destroyable{static isolatedPluginManager=!1;static get pluginManager(){return this.isolatedPluginManager&&!this.hasOwnProperty("_pluginManager")&&(this._pluginManager=new p(this)),this._pluginManager}static _pluginManager=new p(this);get pluginManager(){return this.constructor.pluginManager}static usePlugin(t,...e){return this.pluginManager.usePlugin(t,...e)}static useExtend(t){return this.pluginManager.useExtend(t)}static hasUsed(t){return this.pluginManager.hasUsed(t)}usePlugin(t,...e){return this.pluginManager.instUsePlugin(this,t,...e)}useExtend(t,...e){return this.pluginManager.instUseExtend(this,t,...e)}init(...t){return this.pluginManager.onInit(this,...t)}destroyThis(){const t=this.pluginManager.onDestroy(this);return t instanceof Promise?t.finally(()=>super.destroyThis()):super.destroyThis()}}class v extends P{static defaultOptions=new u;get defaultOptions(){return this._defaultOptions||(this._defaultOptions=new u(void 0,this.constructor.defaultOptions))}_defaultOptions;constructor(t){super(),this.defaultOptions.option=t}}function x(i){const t=O.createDestroyableSubClass(i);return class extends t{static isolatedPluginManager=!1;static get pluginManager(){return this.isolatedPluginManager&&!this.hasOwnProperty("_pluginManager")&&(this._pluginManager=new p(this)),this._pluginManager}static _pluginManager=new p(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 E(i){const t=x(i);return class extends t{static defaultOptions=new u;get defaultOptions(){return this._defaultOptions||(this._defaultOptions=new u(void 0,this.constructor.defaultOptions))}_defaultOptions;constructor(n){super(),this.defaultOptions.option=n}}}const c="common";class k extends P{static modeOptions=new a(c);get modeOptions(){return this._modeOptions||(this._modeOptions=new a(c,void 0,this.constructor.modeOptions))}_modeOptions;get mode(){return this.modeOptions.mode}set mode(t){this.modeOptions.mode=t}get options(){return this.modeOptions.plainFullOption}constructor(t){super(),this.modeOptions.setOption(t)}}function C(i){const t=x(i);return class extends t{static modeOptions=new a(c);get modeOptions(){return this._modeOptions||(this._modeOptions=new a(c,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=T;exports.PluginExtendManager=p;exports.PluginHost=P;exports.TierModeOptions=a;exports.TierModeOptionsPluginHost=k;exports.TierOptions=u;exports.TierOptionsPluginHost=v;exports.commonModeName=c;exports.createPluginHost=x;exports.createTierModeOptionsPluginHost=C;exports.createTierOptionsPluginHost=E;exports.extendMark=l;exports.getPropertyValue=h;exports.getPropertyValueByPath=V;exports.isPlugin=b;exports.mixinIExtend=F;exports.parsePropertyPath=m;exports.pickHostExtendMembers=w;exports.setPropertyValue=M;exports.setPropertyValueByPath=N;exports.tierModeOptionsDecorator=H;exports.tierOptionsDecorator=D;