plugin-tls 0.0.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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -0
  3. package/dist/OptionsPluginHost.d.ts +49 -0
  4. package/dist/PluginHost.d.ts +96 -0
  5. package/dist/PluginManager.d.ts +76 -0
  6. package/dist/defaultOptions.d.ts +33 -0
  7. package/dist/index.d.ts +22 -0
  8. package/dist/plugin-tls.es.js +170 -0
  9. package/dist/plugin-tls.umd.js +1 -0
  10. package/doc/index.md +12 -0
  11. package/doc/plugin-tls.adddefaultoptions.md +30 -0
  12. package/doc/plugin-tls.addinstoptions.md +31 -0
  13. package/doc/plugin-tls.createoptionspluginhost.md +29 -0
  14. package/doc/plugin-tls.createpluginhost.md +30 -0
  15. package/doc/plugin-tls.hostinst.md +13 -0
  16. package/doc/plugin-tls.idefaultoptionshost.defaultoptions.md +11 -0
  17. package/doc/plugin-tls.idefaultoptionshost.md +20 -0
  18. package/doc/plugin-tls.iidefaultoptionshostconstructor.md +13 -0
  19. package/doc/plugin-tls.ioptionspluginhost.defaultoptions.md +11 -0
  20. package/doc/plugin-tls.ioptionspluginhost.md +21 -0
  21. package/doc/plugin-tls.ioptionspluginhostconstructor.md +15 -0
  22. package/doc/plugin-tls.iplugin.created.md +25 -0
  23. package/doc/plugin-tls.iplugin.md +21 -0
  24. package/doc/plugin-tls.iplugin.used.md +25 -0
  25. package/doc/plugin-tls.ipluginhost.md +20 -0
  26. package/doc/plugin-tls.ipluginhost.use.md +26 -0
  27. package/doc/plugin-tls.ipluginhostconstructor.md +20 -0
  28. package/doc/plugin-tls.ipluginhostconstructor.use.md +25 -0
  29. package/doc/plugin-tls.md +53 -0
  30. package/doc/plugin-tls.optionspluginhost._defaultoptions.md +11 -0
  31. package/doc/plugin-tls.optionspluginhost.defaultoptions.md +13 -0
  32. package/doc/plugin-tls.optionspluginhost.md +21 -0
  33. package/doc/plugin-tls.plugincreatedreturntype.md +15 -0
  34. package/doc/plugin-tls.pluginhost._constructor_.md +13 -0
  35. package/doc/plugin-tls.pluginhost._pluginmanager.md +11 -0
  36. package/doc/plugin-tls.pluginhost.md +25 -0
  37. package/doc/plugin-tls.pluginhost.pluginmanager.md +13 -0
  38. package/doc/plugin-tls.pluginhost.use.md +25 -0
  39. package/doc/plugin-tls.pluginmanager.created.md +28 -0
  40. package/doc/plugin-tls.pluginmanager.host.md +13 -0
  41. package/doc/plugin-tls.pluginmanager.instuse.md +30 -0
  42. package/doc/plugin-tls.pluginmanager.md +34 -0
  43. package/doc/plugin-tls.pluginmanager.pluginoptsmap.md +13 -0
  44. package/doc/plugin-tls.pluginmanager.plugins.md +13 -0
  45. package/doc/plugin-tls.pluginmanager.use.md +25 -0
  46. package/doc/plugin-tls.pluginoptions.md +11 -0
  47. package/doc/plugin-tls.pluginusereturntype.md +15 -0
  48. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 郭斌勇
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ [教程]: ./docs/教程.md
2
+ [API接口文档]: ./doc/index.md
3
+
4
+ [GitHub仓库]: https://github.com/GuoBinyong/library-vite-template
5
+ [发行地址]: https://github.com/GuoBinyong/library-vite-template/releases
6
+ [issues]: https://github.com/GuoBinyong/library-vite-template/issues
7
+
8
+ [码云仓库]: https://gitee.com/guobinyong/library-vite-template
9
+
10
+
11
+
12
+ > 目录
13
+
14
+ - [1. 背景](#1-背景)
15
+ - [2. 简介](#2-简介)
16
+ - [3. 安装方式](#3-安装方式)
17
+ - [3.1. 方式1:通过 npm 安装](#31-方式1通过-npm-安装)
18
+ - [3.2. 方式3:通过`<script>`标签引入](#32-方式3通过script标签引入)
19
+ - [4. 教程](#4-教程)
20
+ - [5. API接口文档](#5-api接口文档)
21
+
22
+
23
+
24
+ # 1. 背景
25
+
26
+ # 2. 简介
27
+ 库的简单介绍
28
+
29
+ **具有以下特性:**
30
+ - 特性1
31
+ - 特性2
32
+ - 特性3
33
+
34
+ **详情请看:**
35
+ - 主页:<https://github.com/GuoBinyong/library-vite-template>
36
+ - [GitHub仓库][]
37
+ - [码云仓库][]
38
+ - [教程][]
39
+ - [API接口文档][]
40
+
41
+
42
+ **如果您在使用的过程中遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:**
43
+ - 给该仓库提交 [issues][]
44
+ - 给我 Pull requests
45
+ - 邮箱:<guobinyong@qq.com>
46
+ - QQ:guobinyong@qq.com
47
+ - 微信:keyanzhe
48
+
49
+
50
+
51
+
52
+
53
+ # 3. 安装方式
54
+ 目前,安装方式有以下几种:
55
+
56
+
57
+ ## 3.1. 方式1:通过 npm 安装
58
+ ```
59
+ npm install library-vite-template
60
+ ```
61
+
62
+
63
+
64
+
65
+ ## 3.2. 方式3:通过`<script>`标签引入
66
+ 您可直接从项目的 [发行地址][] 中下载以 `.iife.js` 作为缀的文件,然后使用如下代码引用 和 使用 library-vite-template:
67
+
68
+
69
+ 1. 引用 library-vite-template
70
+ ```
71
+ <script src="path/to/package/library-vite-template.iife.js"></script>
72
+ ```
73
+
74
+ 2. 使用全局的 `library-vite-template`
75
+ ```
76
+ <script>
77
+ // 使用全局的 library-vite-template
78
+ </script>
79
+ ```
80
+
81
+ # 4. 教程
82
+ 详情跳转至[教程][]
83
+
84
+ # 5. API接口文档
85
+ 详情跳转至[API接口文档][]
86
+
87
+
88
+
89
+ --------------------
90
+
91
+ > 有您的支持,我会在开源的道路上,越走越远
92
+
93
+ ![赞赏码](https://i.loli.net/2020/04/08/PGsAEqdJCin1oQL.jpg)
@@ -0,0 +1,49 @@
1
+ import { PluginHost, IPluginHost, IPluginHostConstructor } from "./PluginHost";
2
+ /**
3
+ * 选项插件宿主接口
4
+ */
5
+ export interface IOptionsPluginHost<Options, HOST> extends IPluginHost<HOST> {
6
+ readonly defaultOptions: Options;
7
+ }
8
+ /**
9
+ * 选项插件宿主的构建函数接口
10
+ */
11
+ export interface IOptionsPluginHostConstructor<Options, HOST> extends IPluginHostConstructor<HOST> {
12
+ get defaultOptions(): Options;
13
+ }
14
+ export declare class OptionsPluginHost<Options = any> extends PluginHost {
15
+ /**
16
+ * 全局级别的默认选项
17
+ */
18
+ static readonly defaultOptions: any;
19
+ /**
20
+ * 实例级的默认选项
21
+ */
22
+ get defaultOptions(): Options;
23
+ protected _defaultOptions: Options;
24
+ }
25
+ /**
26
+ * 创建带有选项机制的插件宿主类
27
+ * @remakers
28
+ * 比 直接使用 OptionsPluginHost 提供了完善的类型推导
29
+ *
30
+ * @returns
31
+ */
32
+ export declare function createOptionsPluginHost<HOST, Options>(): {
33
+ new (): {
34
+ /**
35
+ * 实例级的默认选项
36
+ */
37
+ readonly defaultOptions: Options;
38
+ _defaultOptions: Options;
39
+ readonly pluginManager: import("./PluginManager").PluginManager<HOST>;
40
+ use<Options_1 extends unknown, Plugin_1 extends import("./PluginManager").IPlugin<HOST, Options_1>>(plugin: Plugin_1, options?: Options_1 | undefined): import("./PluginManager").PluginCreatedReturnType<Plugin_1> | undefined;
41
+ };
42
+ /**
43
+ * 全局级别的默认选项
44
+ */
45
+ readonly defaultOptions: Options;
46
+ readonly pluginManager: import("./PluginManager").PluginManager<HOST>;
47
+ _pluginManager: import("./PluginManager").PluginManager<HOST>;
48
+ use<Options_2>(plugin: import("./PluginManager").IPlugin<HOST, Options_2>, options: Options_2): any;
49
+ };
@@ -0,0 +1,96 @@
1
+ import { PluginManager, IPlugin, PluginOptions, PluginCreatedReturnType, PluginUseReturnType } from "./PluginManager";
2
+ /**
3
+ * 插件宿主的接口
4
+ */
5
+ export interface IPluginHost<HOST> {
6
+ /**
7
+ * PluginHost 的插件管理器
8
+ */
9
+ get pluginManager(): PluginManager<HOST>;
10
+ /**
11
+ * 实例的注册插件的方法
12
+ * @param plugin
13
+ * @param options
14
+ * @returns
15
+ */
16
+ use<Options extends PluginOptions, Plugin extends IPlugin<HOST, Options>>(plugin: Plugin, options?: Options): PluginCreatedReturnType<Plugin> | undefined;
17
+ }
18
+ /**
19
+ * 插件宿主构造函数的接口
20
+ */
21
+ export interface IPluginHostConstructor<HOST> {
22
+ /**
23
+ * PluginHost 的插件管理器
24
+ */
25
+ get pluginManager(): PluginManager<HOST>;
26
+ /**
27
+ * {@inheritDoc PluginManager.use}
28
+ */
29
+ use<Plugin extends IPlugin<HOST, Options>, Options>(plugin: Plugin, options: Options): PluginUseReturnType<Plugin> | undefined;
30
+ }
31
+ /**
32
+ * 插件的宿主
33
+ *
34
+ * @remarks
35
+ * 插件宿主 就是 拥有插件机制的宿主
36
+ */
37
+ export declare class PluginHost {
38
+ /**
39
+ * 插件管理器
40
+ */
41
+ static get pluginManager(): PluginManager<any>;
42
+ static _pluginManager: PluginManager<any>;
43
+ /**
44
+ * 插件管理器 {@link PluginHost.pluginManager}
45
+ */
46
+ get pluginManager(): PluginManager<any>;
47
+ /**
48
+ * {@inheritDoc PluginManager.use}
49
+ */
50
+ static use<Plugin extends IPlugin<HOST, Options>, Options extends PluginOptions, HOST = typeof PluginHost>(plugin: Plugin, options: Options): ReturnType<Plugin["used"]> | undefined;
51
+ constructor();
52
+ /**
53
+ * 实例的注册插件的方法
54
+ * @param plugin
55
+ * @param options
56
+ * @returns
57
+ */
58
+ use<Options extends PluginOptions, Plugin extends IPlugin<typeof PluginHost, Options>>(plugin: Plugin, options?: Options): PluginCreatedReturnType<Plugin> | undefined;
59
+ }
60
+ /**
61
+ * 创建插件的缩主类
62
+ *
63
+ * @remarks
64
+ * 比 直接使用 PluginHost 提供了完善的类型推导
65
+ * @returns
66
+ */
67
+ export declare function createPluginHost<HOST>(): {
68
+ new (): {
69
+ /**
70
+ * 插件管理器 {@link CEarth.pluginManager}
71
+ */
72
+ readonly pluginManager: PluginManager<HOST>;
73
+ /**
74
+ * 实例的注册插件的方法
75
+ * @param plugin
76
+ * @param options
77
+ * @returns
78
+ */
79
+ use<Options extends unknown, Plugin_1 extends IPlugin<HOST, Options>>(plugin: Plugin_1, options?: Options | undefined): PluginCreatedReturnType<Plugin_1> | undefined;
80
+ };
81
+ /**
82
+ * PluginHost 的插件管理器
83
+ */
84
+ readonly pluginManager: PluginManager<HOST>;
85
+ _pluginManager: PluginManager<HOST>;
86
+ /**
87
+ * {@inheritDoc PluginManager.use}
88
+ */
89
+ use<Options_1>(plugin: IPlugin<HOST, Options_1>, options: Options_1): any;
90
+ };
91
+ /**
92
+ * 插件缩主类的装饰器
93
+ * @param target
94
+ * @returns
95
+ */
96
+ export declare function pluginHost<HOST extends new (...args: any) => any>(target: HOST): HOST;
@@ -0,0 +1,76 @@
1
+ import { AnyFunction } from "type-tls";
2
+ /**
3
+ * 插件宿主的实例类型
4
+ */
5
+ export declare type HostInst<H> = H extends new (...args: any) => any ? InstanceType<H> : H;
6
+ /**
7
+ * 插件的接口
8
+ *
9
+ * @typeParam HOST - 插件宿主的类类型
10
+ * @typeParam Options - 插件的选项类型
11
+ */
12
+ export interface IPlugin<HOST, Options = any> {
13
+ /**
14
+ * 当插件被注册时调用
15
+ * @param Host - 宿主的类型
16
+ * @param options - 注册插件时的选项
17
+ */
18
+ used(Host: HOST, options?: Options): any;
19
+ /**
20
+ * 当宿主实例被创建时调用
21
+ * @param host - 新建的宿主实例
22
+ * @param options - 注册插件时的选项
23
+ */
24
+ created?(host: HostInst<HOST>, options?: Options): any;
25
+ }
26
+ export declare type PluginOptions = any;
27
+ /**
28
+ * 插件的 used 方法的返回值类型
29
+ */
30
+ export declare type PluginUseReturnType<P extends IPlugin<any>> = ReturnType<P["used"]>;
31
+ /**
32
+ * 插件的 created 方法的返回值类型
33
+ */
34
+ export declare type PluginCreatedReturnType<P extends IPlugin<any>> = P["created"] extends AnyFunction ? ReturnType<P["created"]> : void;
35
+ /**
36
+ * 插件管理者
37
+ *
38
+ * @remarks
39
+ * 负责管理插件的注册、应用 等
40
+ */
41
+ export declare class PluginManager<HOST> {
42
+ /**
43
+ * 插件的宿主
44
+ */
45
+ host: HOST;
46
+ /**
47
+ * 插件与插件选项的映射
48
+ */
49
+ pluginOptsMap: Map<IPlugin<HOST, any>, any>;
50
+ /**
51
+ * 注册的插件
52
+ */
53
+ plugins: IPlugin<HOST>[];
54
+ /**
55
+ * 使用插件、注册插件
56
+ * @param plugin - 插件
57
+ * @param options - 传递给插件的选项
58
+ */
59
+ use<Options extends PluginOptions, Plugin extends IPlugin<HOST, Options>>(plugin: Plugin, options?: Options): PluginUseReturnType<Plugin> | undefined;
60
+ /**
61
+ * 插件宿主创建实例时调用
62
+ *
63
+ * @remarks
64
+ * 会调用每个插件的 {@link IPlugin.created | IPlugin.created()} 方法
65
+ * @param hostInst - 插件宿主的新实例
66
+ */
67
+ created(hostInst: HostInst<HOST>): void;
68
+ /**
69
+ * 插件宿主实例的注册插件的方法
70
+ *
71
+ * @remarks
72
+ * 会调用每个插件的 {@link IPlugin.created | IPlugin.created()} 方法
73
+ * @param hostInst - 插件宿主的新实例
74
+ */
75
+ instUse<Options extends PluginOptions, Plugin extends IPlugin<HOST, Options>>(hostInst: HostInst<HOST>, plugin: Plugin, options?: Options): PluginCreatedReturnType<Plugin> | undefined;
76
+ }
@@ -0,0 +1,33 @@
1
+ import { Optional } from "type-tls";
2
+ /**
3
+ * 默认选项宿主接口
4
+ */
5
+ export interface IDefaultOptionsHost<Options> {
6
+ readonly defaultOptions: Options;
7
+ }
8
+ /**
9
+ * 默认选项宿主的构建函数接口
10
+ */
11
+ export interface IIDefaultOptionsHostConstructor<Options> {
12
+ get defaultOptions(): Options;
13
+ }
14
+ /**
15
+ * 创建增加带有选项机制的装饰器
16
+ *
17
+ * @remarks
18
+ * 类装饰器的工厂函数
19
+ *
20
+ * @param options - 选项内容
21
+ * @returns
22
+ */
23
+ export declare function addDefaultOptions<Options>(options: Options, name?: Optional<string>): <Clas extends new (...args: any) => any>(target: Clas) => void;
24
+ /**
25
+ * 创建增加带有选项机制的装饰器
26
+ *
27
+ * @remarks
28
+ * 静态属性装饰器
29
+ *
30
+ * @param options - 选项内容
31
+ * @returns
32
+ */
33
+ export declare function addInstOptions<Clas extends new (...args: any) => any>(target: Clas, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 插件系统
3
+ *
4
+ * @remarks
5
+ * 主要负责 SDK 的插件机制的实现
6
+ * 插件系统应该具备以下功能:
7
+ * - 注册插件
8
+ * - 可扩展类的静态级功能
9
+ * - 可扩展类的实例级功能
10
+ * - 可自定义暴露的功能
11
+ * - 可拥有私有自身的API
12
+ *
13
+ * 额外的也提供了其它的功能
14
+ * - 全局选项
15
+ * - 实例选项
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ export * from "./PluginManager";
20
+ export * from "./PluginHost";
21
+ export * from "./OptionsPluginHost";
22
+ export * from "./defaultOptions";
@@ -0,0 +1,170 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { mixinTarget, extendTarget } from "type-tls";
8
+ import { deepCopy } from "@gby/deep-copy";
9
+ class PluginManager {
10
+ constructor() {
11
+ __publicField(this, "host");
12
+ __publicField(this, "pluginOptsMap", /* @__PURE__ */ new Map());
13
+ __publicField(this, "plugins", []);
14
+ }
15
+ use(plugin, options) {
16
+ const pluginOptsMap = this.pluginOptsMap;
17
+ if (pluginOptsMap.has(plugin)) {
18
+ return;
19
+ }
20
+ this.plugins.push(plugin);
21
+ pluginOptsMap.set(plugin, options);
22
+ return plugin.used(this.host, options);
23
+ }
24
+ created(hostInst) {
25
+ var _a;
26
+ for (const plugin of this.plugins) {
27
+ const options = this.pluginOptsMap.get(plugin);
28
+ (_a = plugin.created) == null ? void 0 : _a.call(plugin, hostInst, options);
29
+ }
30
+ }
31
+ instUse(hostInst, plugin, options) {
32
+ var _a;
33
+ const pluginOptsMap = this.pluginOptsMap;
34
+ if (pluginOptsMap.has(plugin)) {
35
+ return;
36
+ }
37
+ this.use(plugin, options);
38
+ return (_a = plugin.created) == null ? void 0 : _a.call(plugin, hostInst, options);
39
+ }
40
+ }
41
+ class PluginHost {
42
+ static get pluginManager() {
43
+ let pluginManager = this._pluginManager;
44
+ if (!pluginManager) {
45
+ pluginManager = new PluginManager();
46
+ pluginManager.host = this;
47
+ this._pluginManager = pluginManager;
48
+ }
49
+ return pluginManager;
50
+ }
51
+ get pluginManager() {
52
+ return this.constructor.pluginManager;
53
+ }
54
+ static use(plugin, options) {
55
+ return this.pluginManager.use(plugin, options);
56
+ }
57
+ constructor() {
58
+ this.pluginManager.created(this);
59
+ }
60
+ use(plugin, options) {
61
+ return this.constructor.pluginManager.instUse(this, plugin, options);
62
+ }
63
+ }
64
+ __publicField(PluginHost, "_pluginManager");
65
+ function createPluginHost() {
66
+ var _a;
67
+ return _a = class {
68
+ static get pluginManager() {
69
+ let pluginManager = this._pluginManager;
70
+ if (!pluginManager) {
71
+ pluginManager = new PluginManager();
72
+ pluginManager.host = this;
73
+ this._pluginManager = pluginManager;
74
+ }
75
+ return pluginManager;
76
+ }
77
+ get pluginManager() {
78
+ return this.constructor.pluginManager;
79
+ }
80
+ static use(plugin, options) {
81
+ return this.pluginManager.use(plugin, options);
82
+ }
83
+ constructor() {
84
+ this.pluginManager.created(this);
85
+ }
86
+ use(plugin, options) {
87
+ return this.pluginManager.instUse(this, plugin, options);
88
+ }
89
+ }, __publicField(_a, "_pluginManager"), _a;
90
+ }
91
+ function pluginHost(target) {
92
+ const newTarget = mixinTarget(target, {
93
+ get pluginManager() {
94
+ let pluginManager = this._pluginManager;
95
+ if (!pluginManager) {
96
+ pluginManager = new PluginManager();
97
+ pluginManager.host = this;
98
+ this._pluginManager = pluginManager;
99
+ }
100
+ return pluginManager;
101
+ },
102
+ use(plugin, options) {
103
+ return this.pluginManager.use(plugin, options);
104
+ }
105
+ });
106
+ mixinTarget(newTarget.prototype, {
107
+ get pluginManager() {
108
+ return this.constructor.pluginManager;
109
+ },
110
+ use(plugin, options) {
111
+ return this.pluginManager.instUse(this, plugin, options);
112
+ }
113
+ });
114
+ return new Proxy(target, {
115
+ construct: function(target2, argumentsList, receiver) {
116
+ const obj = new target2(...argumentsList);
117
+ newTarget.pluginManager.created(this);
118
+ return obj;
119
+ }
120
+ });
121
+ }
122
+ class OptionsPluginHost extends PluginHost {
123
+ constructor() {
124
+ super(...arguments);
125
+ __publicField(this, "_defaultOptions");
126
+ }
127
+ get defaultOptions() {
128
+ return this._defaultOptions || (this._defaultOptions = deepCopy(this.constructor.defaultOptions));
129
+ }
130
+ }
131
+ __publicField(OptionsPluginHost, "defaultOptions", {});
132
+ function createOptionsPluginHost() {
133
+ var _a;
134
+ const PluginHost2 = createPluginHost();
135
+ return _a = class extends PluginHost2 {
136
+ constructor() {
137
+ super(...arguments);
138
+ __publicField(this, "_defaultOptions");
139
+ }
140
+ get defaultOptions() {
141
+ return this._defaultOptions || (this._defaultOptions = deepCopy(this.constructor.defaultOptions));
142
+ }
143
+ }, __publicField(_a, "defaultOptions", {}), _a;
144
+ }
145
+ function addDefaultOptions(options, name) {
146
+ const propName = name != null ? name : "defaultOptions";
147
+ const priName = `_${propName}`;
148
+ return function defaultOptions(target) {
149
+ const newTarget = mixinTarget(target, {
150
+ get [propName]() {
151
+ return options;
152
+ }
153
+ });
154
+ extendTarget(newTarget, {
155
+ get [propName]() {
156
+ return this[priName] || (this[priName] = structuredClone(newTarget.defaultOptions));
157
+ }
158
+ });
159
+ };
160
+ }
161
+ function addInstOptions(target, propertyKey, descriptor) {
162
+ const priName = `_${propertyKey}`;
163
+ extendTarget(target, {
164
+ get [propertyKey]() {
165
+ return this[priName] || (this[priName] = structuredClone(target[propertyKey]));
166
+ }
167
+ });
168
+ return descriptor;
169
+ }
170
+ export { OptionsPluginHost, PluginHost, PluginManager, addDefaultOptions, addInstOptions, createOptionsPluginHost, createPluginHost, pluginHost };
@@ -0,0 +1 @@
1
+ (function(s,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("type-tls"),require("@gby/deep-copy")):typeof define=="function"&&define.amd?define(["exports","type-tls","@gby/deep-copy"],i):(s=typeof globalThis!="undefined"?globalThis:s||self,i(s.pluginTls={},s.typeTls,s.deepCopy))})(this,function(s,i,a){"use strict";var P=Object.defineProperty;var H=(s,i,a)=>i in s?P(s,i,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[i]=a;var r=(s,i,a)=>(H(s,typeof i!="symbol"?i+"":i,a),a);class o{constructor(){r(this,"host");r(this,"pluginOptsMap",new Map);r(this,"plugins",[])}use(n,t){const e=this.pluginOptsMap;if(!e.has(n))return this.plugins.push(n),e.set(n,t),n.used(this.host,t)}created(n){var t;for(const e of this.plugins){const p=this.pluginOptsMap.get(e);(t=e.created)==null||t.call(e,n,p)}}instUse(n,t,e){var g;if(!this.pluginOptsMap.has(t))return this.use(t,e),(g=t.created)==null?void 0:g.call(t,n,e)}}class l{static get pluginManager(){let n=this._pluginManager;return n||(n=new o,n.host=this,this._pluginManager=n),n}get pluginManager(){return this.constructor.pluginManager}static use(n,t){return this.pluginManager.use(n,t)}constructor(){this.pluginManager.created(this)}use(n,t){return this.constructor.pluginManager.instUse(this,n,t)}}r(l,"_pluginManager");function c(){var u;return u=class{static get pluginManager(){let t=this._pluginManager;return t||(t=new o,t.host=this,this._pluginManager=t),t}get pluginManager(){return this.constructor.pluginManager}static use(t,e){return this.pluginManager.use(t,e)}constructor(){this.pluginManager.created(this)}use(t,e){return this.pluginManager.instUse(this,t,e)}},r(u,"_pluginManager"),u}function f(u){const n=i.mixinTarget(u,{get pluginManager(){let t=this._pluginManager;return t||(t=new o,t.host=this,this._pluginManager=t),t},use(t,e){return this.pluginManager.use(t,e)}});return i.mixinTarget(n.prototype,{get pluginManager(){return this.constructor.pluginManager},use(t,e){return this.pluginManager.instUse(this,t,e)}}),new Proxy(u,{construct:function(t,e,p){const g=new t(...e);return n.pluginManager.created(this),g}})}class h extends l{constructor(){super(...arguments);r(this,"_defaultOptions")}get defaultOptions(){return this._defaultOptions||(this._defaultOptions=a.deepCopy(this.constructor.defaultOptions))}}r(h,"defaultOptions",{});function M(){var n;const u=c();return n=class extends u{constructor(){super(...arguments);r(this,"_defaultOptions")}get defaultOptions(){return this._defaultOptions||(this._defaultOptions=a.deepCopy(this.constructor.defaultOptions))}},r(n,"defaultOptions",{}),n}function O(u,n){const t=n!=null?n:"defaultOptions",e=`_${t}`;return function(g){const d=i.mixinTarget(g,{get[t](){return u}});i.extendTarget(d,{get[t](){return this[e]||(this[e]=structuredClone(d.defaultOptions))}})}}function _(u,n,t){const e=`_${n}`;return i.extendTarget(u,{get[n](){return this[e]||(this[e]=structuredClone(u[n]))}}),t}s.OptionsPluginHost=h,s.PluginHost=l,s.PluginManager=o,s.addDefaultOptions=O,s.addInstOptions=_,s.createOptionsPluginHost=M,s.createPluginHost=c,s.pluginHost=f,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/doc/index.md ADDED
@@ -0,0 +1,12 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md)
4
+
5
+ ## API Reference
6
+
7
+ ## Packages
8
+
9
+ | Package | Description |
10
+ | --- | --- |
11
+ | [plugin-tls](./plugin-tls.md) | 插件系统 |
12
+
@@ -0,0 +1,30 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [plugin-tls](./plugin-tls.md) &gt; [addDefaultOptions](./plugin-tls.adddefaultoptions.md)
4
+
5
+ ## addDefaultOptions() function
6
+
7
+ 创建增加带有选项机制的装饰器
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare function addDefaultOptions<Options>(options: Options, name?: Optional<string>): <Clas extends new (...args: any) => any>(target: Clas) => void;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | options | Options | 选项内容 |
20
+ | name | Optional&lt;string&gt; | <i>(Optional)</i> |
21
+
22
+ <b>Returns:</b>
23
+
24
+ &lt;Clas extends new (...args: any) =&gt; any&gt;(target: Clas) =&gt; void
25
+
26
+
27
+ ## Remarks
28
+
29
+ 类装饰器的工厂函数
30
+
@@ -0,0 +1,31 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [plugin-tls](./plugin-tls.md) &gt; [addInstOptions](./plugin-tls.addinstoptions.md)
4
+
5
+ ## addInstOptions() function
6
+
7
+ 创建增加带有选项机制的装饰器
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare function addInstOptions<Clas extends new (...args: any) => any>(target: Clas, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | target | Clas | |
20
+ | propertyKey | string | |
21
+ | descriptor | PropertyDescriptor | |
22
+
23
+ <b>Returns:</b>
24
+
25
+ PropertyDescriptor
26
+
27
+
28
+ ## Remarks
29
+
30
+ 静态属性装饰器
31
+
@@ -0,0 +1,29 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [plugin-tls](./plugin-tls.md) &gt; [createOptionsPluginHost](./plugin-tls.createoptionspluginhost.md)
4
+
5
+ ## createOptionsPluginHost() function
6
+
7
+ 创建带有选项机制的插件宿主类 比 直接使用 OptionsPluginHost 提供了完善的类型推导
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare function createOptionsPluginHost<HOST, Options>(): {
13
+ new (): {
14
+ readonly defaultOptions: Options;
15
+ _defaultOptions: Options;
16
+ readonly pluginManager: import("./PluginManager").PluginManager<HOST>;
17
+ use<Options_1 extends unknown, Plugin_1 extends import("./PluginManager").IPlugin<HOST, Options_1>>(plugin: Plugin_1, options?: Options_1 | undefined): import("./PluginManager").PluginCreatedReturnType<Plugin_1> | undefined;
18
+ };
19
+ readonly defaultOptions: Options;
20
+ readonly pluginManager: import("./PluginManager").PluginManager<HOST>;
21
+ _pluginManager: import("./PluginManager").PluginManager<HOST>;
22
+ use<Options_2>(plugin: import("./PluginManager").IPlugin<HOST, Options_2>, options: Options_2): any;
23
+ };
24
+ ```
25
+ <b>Returns:</b>
26
+
27
+ { new (): { readonly defaultOptions: Options; \_defaultOptions: Options; readonly pluginManager: import("./PluginManager").[PluginManager](./plugin-tls.pluginmanager.md)<!-- -->&lt;HOST&gt;; use&lt;Options\_1 extends unknown, Plugin\_1 extends import("./PluginManager").[IPlugin](./plugin-tls.iplugin.md)<!-- -->&lt;HOST, Options\_1&gt;&gt;(plugin: Plugin\_1, options?: Options\_1 \| undefined): import("./PluginManager").[PluginCreatedReturnType](./plugin-tls.plugincreatedreturntype.md)<!-- -->&lt;Plugin\_1&gt; \| undefined; }; readonly defaultOptions: Options; readonly pluginManager: import("./PluginManager").[PluginManager](./plugin-tls.pluginmanager.md)<!-- -->&lt;HOST&gt;; \_pluginManager: import("./PluginManager").[PluginManager](./plugin-tls.pluginmanager.md)<!-- -->&lt;HOST&gt;; use&lt;Options\_2&gt;(plugin: import("./PluginManager").[IPlugin](./plugin-tls.iplugin.md)<!-- -->&lt;HOST, Options\_2&gt;, options: Options\_2): any; }
28
+
29
+