@pisell/pisellos 0.0.5
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/README.md +180 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +360 -0
- package/dist/effects/index.d.ts +17 -0
- package/dist/effects/index.js +162 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +17 -0
- package/dist/modules/Account/index.d.ts +21 -0
- package/dist/modules/Account/index.js +212 -0
- package/dist/modules/Account/types.d.ts +41 -0
- package/dist/modules/Account/types.js +19 -0
- package/dist/modules/BaseModule.d.ts +11 -0
- package/dist/modules/BaseModule.js +27 -0
- package/dist/modules/Cart/index.d.ts +33 -0
- package/dist/modules/Cart/index.js +242 -0
- package/dist/modules/Cart/types.d.ts +35 -0
- package/dist/modules/Cart/types.js +19 -0
- package/dist/modules/Date/index.d.ts +17 -0
- package/dist/modules/Date/index.js +133 -0
- package/dist/modules/Date/types.d.ts +32 -0
- package/dist/modules/Date/types.js +17 -0
- package/dist/modules/Guests/index.d.ts +17 -0
- package/dist/modules/Guests/index.js +259 -0
- package/dist/modules/Guests/types.d.ts +43 -0
- package/dist/modules/Guests/types.js +23 -0
- package/dist/modules/Order/index.d.ts +17 -0
- package/dist/modules/Order/index.js +228 -0
- package/dist/modules/Order/types.d.ts +57 -0
- package/dist/modules/Order/types.js +29 -0
- package/dist/modules/Payment/index.d.ts +18 -0
- package/dist/modules/Payment/index.js +243 -0
- package/dist/modules/Payment/types.d.ts +49 -0
- package/dist/modules/Payment/types.js +31 -0
- package/dist/modules/Product/index.d.ts +39 -0
- package/dist/modules/Product/index.js +118 -0
- package/dist/modules/Product/types.d.ts +387 -0
- package/dist/modules/Product/types.js +1 -0
- package/dist/modules/ProductList/index.d.ts +16 -0
- package/dist/modules/ProductList/index.js +158 -0
- package/dist/modules/ProductList/types.d.ts +9 -0
- package/dist/modules/ProductList/types.js +5 -0
- package/dist/modules/Resource/index.d.ts +15 -0
- package/dist/modules/Resource/index.js +219 -0
- package/dist/modules/Resource/types.d.ts +44 -0
- package/dist/modules/Resource/types.js +22 -0
- package/dist/modules/index.d.ts +3 -0
- package/dist/modules/index.js +3 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/request.d.ts +127 -0
- package/dist/plugins/request.js +592 -0
- package/dist/plugins/window.d.ts +115 -0
- package/dist/plugins/window.js +328 -0
- package/dist/solution/BookingByStep/index.d.ts +12 -0
- package/dist/solution/BookingByStep/index.js +77 -0
- package/dist/solution/BookingByStep/types.d.ts +27 -0
- package/dist/solution/BookingByStep/types.js +10 -0
- package/dist/solution/BuyTickets/index.d.ts +26 -0
- package/dist/solution/BuyTickets/index.js +339 -0
- package/dist/solution/BuyTickets/types.d.ts +24 -0
- package/dist/solution/BuyTickets/types.js +19 -0
- package/dist/solution/PlaceOrder/index.d.ts +0 -0
- package/dist/solution/PlaceOrder/index.js +54 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +1 -0
- package/dist/store/createStore.d.ts +3 -0
- package/dist/store/createStore.js +43 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/index.js +1 -0
- package/lib/core/index.d.ts +30 -0
- package/lib/core/index.js +212 -0
- package/lib/effects/index.d.ts +17 -0
- package/lib/effects/index.js +78 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +51 -0
- package/lib/modules/Account/index.d.ts +21 -0
- package/lib/modules/Account/index.js +93 -0
- package/lib/modules/Account/types.d.ts +41 -0
- package/lib/modules/Account/types.js +35 -0
- package/lib/modules/BaseModule.d.ts +11 -0
- package/lib/modules/BaseModule.js +40 -0
- package/lib/modules/Cart/index.d.ts +33 -0
- package/lib/modules/Cart/index.js +104 -0
- package/lib/modules/Cart/types.d.ts +35 -0
- package/lib/modules/Cart/types.js +35 -0
- package/lib/modules/Date/index.d.ts +17 -0
- package/lib/modules/Date/index.js +75 -0
- package/lib/modules/Date/types.d.ts +32 -0
- package/lib/modules/Date/types.js +33 -0
- package/lib/modules/Guests/index.d.ts +17 -0
- package/lib/modules/Guests/index.js +95 -0
- package/lib/modules/Guests/types.d.ts +43 -0
- package/lib/modules/Guests/types.js +35 -0
- package/lib/modules/Order/index.d.ts +17 -0
- package/lib/modules/Order/index.js +95 -0
- package/lib/modules/Order/types.d.ts +57 -0
- package/lib/modules/Order/types.js +35 -0
- package/lib/modules/Payment/index.d.ts +18 -0
- package/lib/modules/Payment/index.js +103 -0
- package/lib/modules/Payment/types.d.ts +49 -0
- package/lib/modules/Payment/types.js +35 -0
- package/lib/modules/Product/index.d.ts +39 -0
- package/lib/modules/Product/index.js +87 -0
- package/lib/modules/Product/types.d.ts +387 -0
- package/lib/modules/Product/types.js +17 -0
- package/lib/modules/ProductList/index.d.ts +16 -0
- package/lib/modules/ProductList/index.js +71 -0
- package/lib/modules/ProductList/types.d.ts +9 -0
- package/lib/modules/ProductList/types.js +33 -0
- package/lib/modules/Resource/index.d.ts +15 -0
- package/lib/modules/Resource/index.js +91 -0
- package/lib/modules/Resource/types.d.ts +44 -0
- package/lib/modules/Resource/types.js +34 -0
- package/lib/modules/index.d.ts +3 -0
- package/lib/modules/index.js +27 -0
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +25 -0
- package/lib/plugins/request.d.ts +127 -0
- package/lib/plugins/request.js +297 -0
- package/lib/plugins/window.d.ts +115 -0
- package/lib/plugins/window.js +252 -0
- package/lib/solution/BookingByStep/index.d.ts +12 -0
- package/lib/solution/BookingByStep/index.js +53 -0
- package/lib/solution/BookingByStep/types.d.ts +27 -0
- package/lib/solution/BookingByStep/types.js +38 -0
- package/lib/solution/BuyTickets/index.d.ts +26 -0
- package/lib/solution/BuyTickets/index.js +122 -0
- package/lib/solution/BuyTickets/types.d.ts +24 -0
- package/lib/solution/BuyTickets/types.js +40 -0
- package/lib/solution/PlaceOrder/index.d.ts +0 -0
- package/lib/solution/PlaceOrder/index.js +0 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +23 -0
- package/lib/store/createStore.d.ts +3 -0
- package/lib/store/createStore.js +46 -0
- package/lib/types/index.d.ts +85 -0
- package/lib/types/index.js +17 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# PisellOS 前端 SDK 框架
|
|
2
|
+
|
|
3
|
+
PisellOS 是一个灵活的、可扩展的前端 SDK 框架,专为构建模块化应用设计。它支持插件系统,允许在不同运行环境中无缝集成功能。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- **模块化架构**:支持各种功能模块(如购物车、结账流程等)的插入和管理
|
|
8
|
+
- **插件系统**:通过插件提供环境抽象,解决跨环境兼容性问题
|
|
9
|
+
- **事件驱动**:基于事件总线的模块间通信机制
|
|
10
|
+
- **类型安全**:使用 TypeScript 构建,提供完整的类型定义
|
|
11
|
+
- **轻量级**:核心框架轻量,按需加载模块
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install pisell-os
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
### 基本用法
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import PisellOSCore, { plugins, modules } from "pisell-os";
|
|
25
|
+
|
|
26
|
+
// 创建 PisellOS 实例
|
|
27
|
+
const pisellOS = new PisellOSCore({
|
|
28
|
+
debug: true, // 开启调试日志
|
|
29
|
+
plugins: [{ plugin: plugins.window }, { plugin: plugins.request }],
|
|
30
|
+
modules: [
|
|
31
|
+
{
|
|
32
|
+
module: modules.cart,
|
|
33
|
+
options: {
|
|
34
|
+
plugins: ["window", "request"], // 依赖的插件
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 获取购物车模块并使用
|
|
41
|
+
const cartModule = pisellOS.getModuleExports("cart");
|
|
42
|
+
await cartModule.addItem({
|
|
43
|
+
id: "product-001",
|
|
44
|
+
name: "商品1",
|
|
45
|
+
price: 99.9,
|
|
46
|
+
quantity: 1,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 使用插件
|
|
50
|
+
const windowPlugin = pisellOS.getPlugin("window");
|
|
51
|
+
windowPlugin.localStorage.setItem("key", "value");
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 架构
|
|
55
|
+
|
|
56
|
+
PisellOS 的核心架构包括四个主要部分:
|
|
57
|
+
|
|
58
|
+
1. **核心框架**:负责模块和插件的注册、管理和生命周期控制
|
|
59
|
+
2. **插件系统**:为不同环境提供统一接口,如 window、request 等
|
|
60
|
+
3. **模块系统**:提供业务功能实现,可依赖插件和其他模块
|
|
61
|
+
4. **解决方案**:解决方案是 pisell_os 中对业务流程层的抽象,用于将多个独立的模块(Module)编排成一个完整的业务解决方案。
|
|
62
|
+
它本质上是一个特殊的“业务 orchestrator”,负责协调模块调用、控制数据流动和处理统一状态管理。
|
|
63
|
+
|
|
64
|
+
### 核心 API
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// 创建实例
|
|
68
|
+
const pisellOS = new PisellOSCore(options);
|
|
69
|
+
|
|
70
|
+
// 注册插件
|
|
71
|
+
pisellOS.registerPlugin(plugin, options);
|
|
72
|
+
|
|
73
|
+
// 注册模块
|
|
74
|
+
pisellOS.registerModule(module, options);
|
|
75
|
+
|
|
76
|
+
// 获取插件
|
|
77
|
+
const plugin = pisellOS.getPlugin<PluginType>(name);
|
|
78
|
+
|
|
79
|
+
// 获取模块
|
|
80
|
+
const module = pisellOS.getModule<ModuleType>(name);
|
|
81
|
+
|
|
82
|
+
// 获取模块导出的 API
|
|
83
|
+
const api = pisellOS.getModuleExports<ApiType>(name);
|
|
84
|
+
|
|
85
|
+
// 事件机制
|
|
86
|
+
pisellOS.on(event, handler);
|
|
87
|
+
pisellOS.emit(event, data);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 内置插件
|
|
91
|
+
|
|
92
|
+
PisellOS 提供了几个内置插件以简化开发:
|
|
93
|
+
|
|
94
|
+
- **window**:提供 window 对象模拟,包括 localStorage、setTimeout 等
|
|
95
|
+
- **request**:提供网络请求功能,支持各种 HTTP 方法和拦截器
|
|
96
|
+
|
|
97
|
+
## 内置模块
|
|
98
|
+
|
|
99
|
+
- **cart**:购物车模块,提供商品管理、数量更新等功能
|
|
100
|
+
|
|
101
|
+
## 自定义扩展
|
|
102
|
+
|
|
103
|
+
### 创建自定义插件
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Plugin } from "pisell-os";
|
|
107
|
+
|
|
108
|
+
class MyPlugin implements Plugin {
|
|
109
|
+
name = "my-plugin";
|
|
110
|
+
version = "1.0.0";
|
|
111
|
+
|
|
112
|
+
initialize() {
|
|
113
|
+
console.log("My plugin initialized");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
destroy() {
|
|
117
|
+
console.log("My plugin destroyed");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 自定义方法
|
|
121
|
+
myMethod() {
|
|
122
|
+
return "Hello from my plugin";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export default new MyPlugin();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 创建自定义模块
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { Module, PisellCore } from "pisell-os";
|
|
133
|
+
|
|
134
|
+
class MyModule implements Module {
|
|
135
|
+
name = "my-module";
|
|
136
|
+
version = "1.0.0";
|
|
137
|
+
|
|
138
|
+
private core: PisellCore;
|
|
139
|
+
|
|
140
|
+
// 导出 API
|
|
141
|
+
exports = {
|
|
142
|
+
doSomething: () => this.doSomething(),
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
initialize(core: PisellCore) {
|
|
146
|
+
this.core = core;
|
|
147
|
+
console.log("My module initialized");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
destroy() {
|
|
151
|
+
console.log("My module destroyed");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private doSomething() {
|
|
155
|
+
return "Hello from my module";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default new MyModule();
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 开发
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# 安装依赖
|
|
166
|
+
npm install
|
|
167
|
+
|
|
168
|
+
# 构建项目
|
|
169
|
+
npm run build
|
|
170
|
+
|
|
171
|
+
# 运行示例
|
|
172
|
+
npm run example
|
|
173
|
+
|
|
174
|
+
# 开发模式
|
|
175
|
+
npm run dev
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## 许可
|
|
179
|
+
|
|
180
|
+
MIT License
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Plugin, PluginOptions, Module, ModuleOptions, PisellCore, PisellOSOptions, BusinessContext, ModuleContextConfig } from '../types';
|
|
2
|
+
import { EffectsManager } from '../effects';
|
|
3
|
+
/**
|
|
4
|
+
* pisell OS 核心实现
|
|
5
|
+
*/
|
|
6
|
+
declare class PisellOSCore implements PisellCore {
|
|
7
|
+
private plugins;
|
|
8
|
+
private modules;
|
|
9
|
+
private stores;
|
|
10
|
+
effects: EffectsManager;
|
|
11
|
+
private debug;
|
|
12
|
+
context: BusinessContext;
|
|
13
|
+
constructor(options?: PisellOSOptions);
|
|
14
|
+
private initialize;
|
|
15
|
+
private log;
|
|
16
|
+
registerPlugin(plugin: Plugin, options?: PluginOptions): void;
|
|
17
|
+
getPlugin<T extends Plugin>(name: string): T | null;
|
|
18
|
+
hasPlugin(name: string): boolean;
|
|
19
|
+
registerModule(module: Module, options?: ModuleOptions): void;
|
|
20
|
+
getModule<T extends Module>(name: string): T | null;
|
|
21
|
+
getModuleExports<T = any>(name: string): T | null;
|
|
22
|
+
hasModule(name: string): boolean;
|
|
23
|
+
destroy(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 验证上下文参数
|
|
26
|
+
*/
|
|
27
|
+
validateContext(config: ModuleContextConfig): boolean;
|
|
28
|
+
}
|
|
29
|
+
export { PisellOSCore };
|
|
30
|
+
export default PisellOSCore;
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
import { createStore } from "../store/createStore";
|
|
21
|
+
import { EffectsManager } from "../effects";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* pisell OS 核心实现
|
|
25
|
+
*/
|
|
26
|
+
var PisellOSCore = /*#__PURE__*/function () {
|
|
27
|
+
function PisellOSCore(options) {
|
|
28
|
+
_classCallCheck(this, PisellOSCore);
|
|
29
|
+
_defineProperty(this, "plugins", new Map());
|
|
30
|
+
_defineProperty(this, "modules", new Map());
|
|
31
|
+
_defineProperty(this, "stores", new Map());
|
|
32
|
+
_defineProperty(this, "effects", new EffectsManager());
|
|
33
|
+
_defineProperty(this, "debug", false);
|
|
34
|
+
_defineProperty(this, "context", {});
|
|
35
|
+
this.debug = (options === null || options === void 0 ? void 0 : options.debug) || false;
|
|
36
|
+
this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
|
|
37
|
+
this.initialize(options);
|
|
38
|
+
}
|
|
39
|
+
_createClass(PisellOSCore, [{
|
|
40
|
+
key: "initialize",
|
|
41
|
+
value: function initialize(options) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
if (options !== null && options !== void 0 && options.plugins) {
|
|
44
|
+
options.plugins.forEach(function (item) {
|
|
45
|
+
_this.registerPlugin(item.plugin, item.options);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (options !== null && options !== void 0 && options.modules) {
|
|
49
|
+
options.modules.forEach(function (item) {
|
|
50
|
+
_this.registerModule(item.module, item.options);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.log('PisellOS 核心初始化完成');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 日志方法
|
|
57
|
+
}, {
|
|
58
|
+
key: "log",
|
|
59
|
+
value: function log(message) {
|
|
60
|
+
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'info';
|
|
61
|
+
if (!this.debug && level === 'info') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var prefix = '[PisellOS]';
|
|
65
|
+
switch (level) {
|
|
66
|
+
case 'info':
|
|
67
|
+
console.log("".concat(prefix, " ").concat(message));
|
|
68
|
+
break;
|
|
69
|
+
case 'warn':
|
|
70
|
+
console.warn("".concat(prefix, " ").concat(message));
|
|
71
|
+
break;
|
|
72
|
+
case 'error':
|
|
73
|
+
console.error("".concat(prefix, " ").concat(message));
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// 插件相关方法
|
|
78
|
+
}, {
|
|
79
|
+
key: "registerPlugin",
|
|
80
|
+
value: function registerPlugin(plugin, options) {
|
|
81
|
+
var _this2 = this;
|
|
82
|
+
if (this.plugins.has(plugin.name)) {
|
|
83
|
+
this.log("\u63D2\u4EF6 ".concat(plugin.name, " \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6"), 'warn');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 检查依赖
|
|
87
|
+
if (options !== null && options !== void 0 && options.dependencies) {
|
|
88
|
+
var _iterator = _createForOfIteratorHelper(options.dependencies),
|
|
89
|
+
_step;
|
|
90
|
+
try {
|
|
91
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
92
|
+
var dep = _step.value;
|
|
93
|
+
if (!this.plugins.has(dep)) {
|
|
94
|
+
throw new Error("\u6CE8\u518C\u63D2\u4EF6 ".concat(plugin.name, " \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u63D2\u4EF6 ").concat(dep));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
_iterator.e(err);
|
|
99
|
+
} finally {
|
|
100
|
+
_iterator.f();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 初始化插件
|
|
105
|
+
try {
|
|
106
|
+
var result = plugin.initialize();
|
|
107
|
+
if (result instanceof Promise) {
|
|
108
|
+
result.catch(function (err) {
|
|
109
|
+
_this2.log("\u63D2\u4EF6 ".concat(plugin.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
|
|
110
|
+
throw err;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
this.plugins.set(plugin.name, plugin);
|
|
114
|
+
this.log("\u63D2\u4EF6 ".concat(plugin.name, " v").concat(plugin.version, " \u6CE8\u518C\u6210\u529F"));
|
|
115
|
+
} catch (error) {
|
|
116
|
+
this.log("\u63D2\u4EF6 ".concat(plugin.name, " \u521D\u59CB\u5316\u8FC7\u7A0B\u4E2D\u51FA\u9519: ").concat(error), 'error');
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "getPlugin",
|
|
122
|
+
value: function getPlugin(name) {
|
|
123
|
+
return this.plugins.get(name) || null;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "hasPlugin",
|
|
127
|
+
value: function hasPlugin(name) {
|
|
128
|
+
return this.plugins.has(name);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 模块相关方法
|
|
132
|
+
}, {
|
|
133
|
+
key: "registerModule",
|
|
134
|
+
value: function registerModule(module, options) {
|
|
135
|
+
var _this3 = this;
|
|
136
|
+
if (this.modules.has(module.name)) {
|
|
137
|
+
this.log("\u6A21\u5757 ".concat(module.name, " \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6"), 'warn');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 检查依赖模块
|
|
141
|
+
if (options !== null && options !== void 0 && options.dependencies) {
|
|
142
|
+
var _iterator2 = _createForOfIteratorHelper(options.dependencies),
|
|
143
|
+
_step2;
|
|
144
|
+
try {
|
|
145
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
146
|
+
var dep = _step2.value;
|
|
147
|
+
if (!this.modules.has(dep)) {
|
|
148
|
+
throw new Error("\u6CE8\u518C\u6A21\u5757 ".concat(module.name, " \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u6A21\u5757 ").concat(dep));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (err) {
|
|
152
|
+
_iterator2.e(err);
|
|
153
|
+
} finally {
|
|
154
|
+
_iterator2.f();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 检查依赖插件
|
|
159
|
+
if (options !== null && options !== void 0 && options.plugins) {
|
|
160
|
+
var _iterator3 = _createForOfIteratorHelper(options.plugins),
|
|
161
|
+
_step3;
|
|
162
|
+
try {
|
|
163
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
164
|
+
var plugin = _step3.value;
|
|
165
|
+
if (!this.plugins.has(plugin)) {
|
|
166
|
+
throw new Error("\u6CE8\u518C\u6A21\u5757 ".concat(module.name, " \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u63D2\u4EF6 ").concat(plugin));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} catch (err) {
|
|
170
|
+
_iterator3.e(err);
|
|
171
|
+
} finally {
|
|
172
|
+
_iterator3.f();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// 预先给模块初始化值系统
|
|
176
|
+
var _createStore = createStore((options === null || options === void 0 ? void 0 : options.initialState) || {}, module.name, function (path, value) {
|
|
177
|
+
console.log('core 检测到模块值更新', module.name, path, value);
|
|
178
|
+
_this3.effects.emit("".concat(module.name, ":changed"), value);
|
|
179
|
+
if (module.storeChange) module.storeChange(path, value);
|
|
180
|
+
}),
|
|
181
|
+
proxy = _createStore.proxy;
|
|
182
|
+
this.stores.set(module.name, proxy);
|
|
183
|
+
// 初始化模块
|
|
184
|
+
try {
|
|
185
|
+
var result = module.initialize(this, _objectSpread({
|
|
186
|
+
store: proxy
|
|
187
|
+
}, options));
|
|
188
|
+
if (result instanceof Promise) {
|
|
189
|
+
result.catch(function (err) {
|
|
190
|
+
_this3.log("\u6A21\u5757 ".concat(module.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
|
|
191
|
+
throw err;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
this.modules.set(module.name, module);
|
|
195
|
+
this.log("\u6A21\u5757 ".concat(module.name, " v").concat(module.version, " \u6CE8\u518C\u6210\u529F"));
|
|
196
|
+
} catch (error) {
|
|
197
|
+
this.log("\u6A21\u5757 ".concat(module.name, " \u521D\u59CB\u5316\u8FC7\u7A0B\u4E2D\u51FA\u9519: ").concat(error), 'error');
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}, {
|
|
202
|
+
key: "getModule",
|
|
203
|
+
value: function getModule(name) {
|
|
204
|
+
return this.modules.get(name) || null;
|
|
205
|
+
}
|
|
206
|
+
}, {
|
|
207
|
+
key: "getModuleExports",
|
|
208
|
+
value: function getModuleExports(name) {
|
|
209
|
+
var module = this.modules.get(name);
|
|
210
|
+
return (module === null || module === void 0 ? void 0 : module.exports) || null;
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "hasModule",
|
|
214
|
+
value: function hasModule(name) {
|
|
215
|
+
return this.modules.has(name);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 销毁方法
|
|
219
|
+
}, {
|
|
220
|
+
key: "destroy",
|
|
221
|
+
value: function () {
|
|
222
|
+
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
223
|
+
var _iterator4, _step4, _step4$value, name, module, _iterator5, _step5, _step5$value, _name, plugin;
|
|
224
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
225
|
+
while (1) switch (_context.prev = _context.next) {
|
|
226
|
+
case 0:
|
|
227
|
+
// 先销毁模块
|
|
228
|
+
_iterator4 = _createForOfIteratorHelper(this.modules.entries());
|
|
229
|
+
_context.prev = 1;
|
|
230
|
+
_iterator4.s();
|
|
231
|
+
case 3:
|
|
232
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
233
|
+
_context.next = 17;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
_step4$value = _slicedToArray(_step4.value, 2), name = _step4$value[0], module = _step4$value[1];
|
|
237
|
+
if (!module.destroy) {
|
|
238
|
+
_context.next = 15;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
_context.prev = 6;
|
|
242
|
+
_context.next = 9;
|
|
243
|
+
return Promise.resolve(module.destroy());
|
|
244
|
+
case 9:
|
|
245
|
+
this.log("\u6A21\u5757 ".concat(name, " \u5DF2\u9500\u6BC1"));
|
|
246
|
+
_context.next = 15;
|
|
247
|
+
break;
|
|
248
|
+
case 12:
|
|
249
|
+
_context.prev = 12;
|
|
250
|
+
_context.t0 = _context["catch"](6);
|
|
251
|
+
this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context.t0), 'error');
|
|
252
|
+
case 15:
|
|
253
|
+
_context.next = 3;
|
|
254
|
+
break;
|
|
255
|
+
case 17:
|
|
256
|
+
_context.next = 22;
|
|
257
|
+
break;
|
|
258
|
+
case 19:
|
|
259
|
+
_context.prev = 19;
|
|
260
|
+
_context.t1 = _context["catch"](1);
|
|
261
|
+
_iterator4.e(_context.t1);
|
|
262
|
+
case 22:
|
|
263
|
+
_context.prev = 22;
|
|
264
|
+
_iterator4.f();
|
|
265
|
+
return _context.finish(22);
|
|
266
|
+
case 25:
|
|
267
|
+
this.modules.clear();
|
|
268
|
+
|
|
269
|
+
// 再销毁插件
|
|
270
|
+
_iterator5 = _createForOfIteratorHelper(this.plugins.entries());
|
|
271
|
+
_context.prev = 27;
|
|
272
|
+
_iterator5.s();
|
|
273
|
+
case 29:
|
|
274
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
275
|
+
_context.next = 43;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
_step5$value = _slicedToArray(_step5.value, 2), _name = _step5$value[0], plugin = _step5$value[1];
|
|
279
|
+
if (!plugin.destroy) {
|
|
280
|
+
_context.next = 41;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
_context.prev = 32;
|
|
284
|
+
_context.next = 35;
|
|
285
|
+
return Promise.resolve(plugin.destroy());
|
|
286
|
+
case 35:
|
|
287
|
+
this.log("\u63D2\u4EF6 ".concat(_name, " \u5DF2\u9500\u6BC1"));
|
|
288
|
+
_context.next = 41;
|
|
289
|
+
break;
|
|
290
|
+
case 38:
|
|
291
|
+
_context.prev = 38;
|
|
292
|
+
_context.t2 = _context["catch"](32);
|
|
293
|
+
this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context.t2), 'error');
|
|
294
|
+
case 41:
|
|
295
|
+
_context.next = 29;
|
|
296
|
+
break;
|
|
297
|
+
case 43:
|
|
298
|
+
_context.next = 48;
|
|
299
|
+
break;
|
|
300
|
+
case 45:
|
|
301
|
+
_context.prev = 45;
|
|
302
|
+
_context.t3 = _context["catch"](27);
|
|
303
|
+
_iterator5.e(_context.t3);
|
|
304
|
+
case 48:
|
|
305
|
+
_context.prev = 48;
|
|
306
|
+
_iterator5.f();
|
|
307
|
+
return _context.finish(48);
|
|
308
|
+
case 51:
|
|
309
|
+
this.plugins.clear();
|
|
310
|
+
this.log('PisellOS 核心已销毁');
|
|
311
|
+
case 53:
|
|
312
|
+
case "end":
|
|
313
|
+
return _context.stop();
|
|
314
|
+
}
|
|
315
|
+
}, _callee, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
|
|
316
|
+
}));
|
|
317
|
+
function destroy() {
|
|
318
|
+
return _destroy.apply(this, arguments);
|
|
319
|
+
}
|
|
320
|
+
return destroy;
|
|
321
|
+
}()
|
|
322
|
+
/**
|
|
323
|
+
* 验证上下文参数
|
|
324
|
+
*/
|
|
325
|
+
}, {
|
|
326
|
+
key: "validateContext",
|
|
327
|
+
value: function validateContext(config) {
|
|
328
|
+
var _iterator6 = _createForOfIteratorHelper(config.validations),
|
|
329
|
+
_step6;
|
|
330
|
+
try {
|
|
331
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
332
|
+
var rule = _step6.value;
|
|
333
|
+
var value = this.context[rule.name];
|
|
334
|
+
|
|
335
|
+
// 检查必需参数
|
|
336
|
+
if (rule.required && (value === undefined || value === null)) {
|
|
337
|
+
this.log("\u6A21\u5757 ".concat(config.name, " \u7F3A\u5C11\u5FC5\u9700\u7684\u4E0A\u4E0B\u6587\u53C2\u6570: ").concat(rule.name), 'error');
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// 执行自定义验证
|
|
342
|
+
if (rule.validate && value !== undefined && value !== null) {
|
|
343
|
+
if (!rule.validate(value)) {
|
|
344
|
+
this.log("\u6A21\u5757 ".concat(config.name, " \u4E0A\u4E0B\u6587\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25: ").concat(rule.name, " - ").concat(rule.message || '验证失败'), 'error');
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} catch (err) {
|
|
350
|
+
_iterator6.e(err);
|
|
351
|
+
} finally {
|
|
352
|
+
_iterator6.f();
|
|
353
|
+
}
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}]);
|
|
357
|
+
return PisellOSCore;
|
|
358
|
+
}();
|
|
359
|
+
export { PisellOSCore };
|
|
360
|
+
export default PisellOSCore;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type EffectCallback = (payload: any) => void | Promise<void | {
|
|
2
|
+
status: boolean;
|
|
3
|
+
message?: string;
|
|
4
|
+
}>;
|
|
5
|
+
declare class EffectsManager {
|
|
6
|
+
private listeners;
|
|
7
|
+
on(event: string, callback: EffectCallback): void;
|
|
8
|
+
off(event: string, callback: EffectCallback): void;
|
|
9
|
+
offByModuleDestroy(module: string): void;
|
|
10
|
+
once(event: string, callback: EffectCallback): void;
|
|
11
|
+
emit(event: string, payload: any): Promise<{
|
|
12
|
+
status: boolean;
|
|
13
|
+
data: any;
|
|
14
|
+
}>;
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
|
17
|
+
export { EffectsManager };
|