@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
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/core/index.ts
|
|
20
|
+
var core_exports = {};
|
|
21
|
+
__export(core_exports, {
|
|
22
|
+
PisellOSCore: () => PisellOSCore,
|
|
23
|
+
default: () => core_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(core_exports);
|
|
26
|
+
var import_createStore = require("../store/createStore");
|
|
27
|
+
var import_effects = require("../effects");
|
|
28
|
+
var PisellOSCore = class {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.plugins = /* @__PURE__ */ new Map();
|
|
31
|
+
this.modules = /* @__PURE__ */ new Map();
|
|
32
|
+
this.stores = /* @__PURE__ */ new Map();
|
|
33
|
+
this.effects = new import_effects.EffectsManager();
|
|
34
|
+
this.debug = false;
|
|
35
|
+
this.context = {};
|
|
36
|
+
this.debug = (options == null ? void 0 : options.debug) || false;
|
|
37
|
+
this.context = (options == null ? void 0 : options.context) || {};
|
|
38
|
+
this.initialize(options);
|
|
39
|
+
}
|
|
40
|
+
initialize(options) {
|
|
41
|
+
if (options == null ? void 0 : options.plugins) {
|
|
42
|
+
options.plugins.forEach((item) => {
|
|
43
|
+
this.registerPlugin(item.plugin, item.options);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (options == null ? void 0 : options.modules) {
|
|
47
|
+
options.modules.forEach((item) => {
|
|
48
|
+
this.registerModule(item.module, item.options);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
this.log("PisellOS 核心初始化完成");
|
|
52
|
+
}
|
|
53
|
+
// 日志方法
|
|
54
|
+
log(message, level = "info") {
|
|
55
|
+
if (!this.debug && level === "info") {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const prefix = "[PisellOS]";
|
|
59
|
+
switch (level) {
|
|
60
|
+
case "info":
|
|
61
|
+
console.log(`${prefix} ${message}`);
|
|
62
|
+
break;
|
|
63
|
+
case "warn":
|
|
64
|
+
console.warn(`${prefix} ${message}`);
|
|
65
|
+
break;
|
|
66
|
+
case "error":
|
|
67
|
+
console.error(`${prefix} ${message}`);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// 插件相关方法
|
|
72
|
+
registerPlugin(plugin, options) {
|
|
73
|
+
if (this.plugins.has(plugin.name)) {
|
|
74
|
+
this.log(`插件 ${plugin.name} 已经注册过,将被覆盖`, "warn");
|
|
75
|
+
}
|
|
76
|
+
if (options == null ? void 0 : options.dependencies) {
|
|
77
|
+
for (const dep of options.dependencies) {
|
|
78
|
+
if (!this.plugins.has(dep)) {
|
|
79
|
+
throw new Error(`注册插件 ${plugin.name} 失败:缺少依赖插件 ${dep}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const result = plugin.initialize();
|
|
85
|
+
if (result instanceof Promise) {
|
|
86
|
+
result.catch((err) => {
|
|
87
|
+
this.log(`插件 ${plugin.name} 初始化失败: ${err.message}`, "error");
|
|
88
|
+
throw err;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
this.plugins.set(plugin.name, plugin);
|
|
92
|
+
this.log(`插件 ${plugin.name} v${plugin.version} 注册成功`);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
this.log(`插件 ${plugin.name} 初始化过程中出错: ${error}`, "error");
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
getPlugin(name) {
|
|
99
|
+
return this.plugins.get(name) || null;
|
|
100
|
+
}
|
|
101
|
+
hasPlugin(name) {
|
|
102
|
+
return this.plugins.has(name);
|
|
103
|
+
}
|
|
104
|
+
// 模块相关方法
|
|
105
|
+
registerModule(module2, options) {
|
|
106
|
+
if (this.modules.has(module2.name)) {
|
|
107
|
+
this.log(`模块 ${module2.name} 已经注册过,将被覆盖`, "warn");
|
|
108
|
+
}
|
|
109
|
+
if (options == null ? void 0 : options.dependencies) {
|
|
110
|
+
for (const dep of options.dependencies) {
|
|
111
|
+
if (!this.modules.has(dep)) {
|
|
112
|
+
throw new Error(`注册模块 ${module2.name} 失败:缺少依赖模块 ${dep}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (options == null ? void 0 : options.plugins) {
|
|
117
|
+
for (const plugin of options.plugins) {
|
|
118
|
+
if (!this.plugins.has(plugin)) {
|
|
119
|
+
throw new Error(`注册模块 ${module2.name} 失败:缺少依赖插件 ${plugin}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const { proxy } = (0, import_createStore.createStore)(
|
|
124
|
+
(options == null ? void 0 : options.initialState) || {},
|
|
125
|
+
module2.name,
|
|
126
|
+
(path, value) => {
|
|
127
|
+
console.log("core 检测到模块值更新", module2.name, path, value);
|
|
128
|
+
this.effects.emit(`${module2.name}:changed`, value);
|
|
129
|
+
if (module2.storeChange)
|
|
130
|
+
module2.storeChange(path, value);
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
this.stores.set(module2.name, proxy);
|
|
134
|
+
try {
|
|
135
|
+
const result = module2.initialize(this, { store: proxy, ...options });
|
|
136
|
+
if (result instanceof Promise) {
|
|
137
|
+
result.catch((err) => {
|
|
138
|
+
this.log(`模块 ${module2.name} 初始化失败: ${err.message}`, "error");
|
|
139
|
+
throw err;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
this.modules.set(module2.name, module2);
|
|
143
|
+
this.log(`模块 ${module2.name} v${module2.version} 注册成功`);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
this.log(`模块 ${module2.name} 初始化过程中出错: ${error}`, "error");
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
getModule(name) {
|
|
150
|
+
return this.modules.get(name) || null;
|
|
151
|
+
}
|
|
152
|
+
getModuleExports(name) {
|
|
153
|
+
const module2 = this.modules.get(name);
|
|
154
|
+
return (module2 == null ? void 0 : module2.exports) || null;
|
|
155
|
+
}
|
|
156
|
+
hasModule(name) {
|
|
157
|
+
return this.modules.has(name);
|
|
158
|
+
}
|
|
159
|
+
// 销毁方法
|
|
160
|
+
async destroy() {
|
|
161
|
+
for (const [name, module2] of this.modules.entries()) {
|
|
162
|
+
if (module2.destroy) {
|
|
163
|
+
try {
|
|
164
|
+
await Promise.resolve(module2.destroy());
|
|
165
|
+
this.log(`模块 ${name} 已销毁`);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
this.log(`销毁模块 ${name} 时出错: ${error}`, "error");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.modules.clear();
|
|
172
|
+
for (const [name, plugin] of this.plugins.entries()) {
|
|
173
|
+
if (plugin.destroy) {
|
|
174
|
+
try {
|
|
175
|
+
await Promise.resolve(plugin.destroy());
|
|
176
|
+
this.log(`插件 ${name} 已销毁`);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
this.log(`销毁插件 ${name} 时出错: ${error}`, "error");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
this.plugins.clear();
|
|
183
|
+
this.log("PisellOS 核心已销毁");
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 验证上下文参数
|
|
187
|
+
*/
|
|
188
|
+
validateContext(config) {
|
|
189
|
+
for (const rule of config.validations) {
|
|
190
|
+
const value = this.context[rule.name];
|
|
191
|
+
if (rule.required && (value === void 0 || value === null)) {
|
|
192
|
+
this.log(`模块 ${config.name} 缺少必需的上下文参数: ${rule.name}`, "error");
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (rule.validate && value !== void 0 && value !== null) {
|
|
196
|
+
if (!rule.validate(value)) {
|
|
197
|
+
this.log(
|
|
198
|
+
`模块 ${config.name} 上下文参数验证失败: ${rule.name} - ${rule.message || "验证失败"}`,
|
|
199
|
+
"error"
|
|
200
|
+
);
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var core_default = PisellOSCore;
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
PisellOSCore
|
|
212
|
+
});
|
|
@@ -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 };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/effects/index.ts
|
|
20
|
+
var effects_exports = {};
|
|
21
|
+
__export(effects_exports, {
|
|
22
|
+
EffectsManager: () => EffectsManager
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(effects_exports);
|
|
25
|
+
var EffectsManager = class {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
28
|
+
}
|
|
29
|
+
on(event, callback) {
|
|
30
|
+
var _a;
|
|
31
|
+
if (!this.listeners.has(event))
|
|
32
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
33
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.add(callback);
|
|
34
|
+
}
|
|
35
|
+
off(event, callback) {
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.delete(callback);
|
|
38
|
+
}
|
|
39
|
+
// 模块销毁时,删除所有以模块名开头的监听
|
|
40
|
+
offByModuleDestroy(module2) {
|
|
41
|
+
Array.from(this.listeners.keys()).forEach((item) => {
|
|
42
|
+
if (item.startsWith(module2)) {
|
|
43
|
+
this.listeners.delete(item);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
once(event, callback) {
|
|
48
|
+
const wrapper = async (payload) => {
|
|
49
|
+
await callback(payload);
|
|
50
|
+
this.off(event, wrapper);
|
|
51
|
+
};
|
|
52
|
+
this.on(event, wrapper);
|
|
53
|
+
}
|
|
54
|
+
async emit(event, payload) {
|
|
55
|
+
const callbacks = this.listeners.get(event);
|
|
56
|
+
if (!callbacks)
|
|
57
|
+
return { status: true, data: [] };
|
|
58
|
+
return new Promise(async (resolve) => {
|
|
59
|
+
const res = [];
|
|
60
|
+
for (const cb of callbacks) {
|
|
61
|
+
const result = await cb(payload);
|
|
62
|
+
if (result !== void 0 && typeof result === "object" && "status" in result) {
|
|
63
|
+
res.push(result);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
console.log(res);
|
|
67
|
+
const isAllPass = res.every((r) => (r == null ? void 0 : r.status) !== false);
|
|
68
|
+
resolve({ status: isAllPass, data: res });
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
clear() {
|
|
72
|
+
this.listeners.clear();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
EffectsManager
|
|
78
|
+
});
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PisellOS 前端SDK框架
|
|
3
|
+
* 提供可扩展的模块化架构,支持插件系统
|
|
4
|
+
*/
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './modules';
|
|
7
|
+
export * from './plugins';
|
|
8
|
+
export * from './solution';
|
|
9
|
+
export { PisellOSCore } from './core';
|
|
10
|
+
import PisellOSCore from './core';
|
|
11
|
+
export default PisellOSCore;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
PisellOSCore: () => import_core.PisellOSCore,
|
|
34
|
+
default: () => src_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
38
|
+
__reExport(src_exports, require("./modules"), module.exports);
|
|
39
|
+
__reExport(src_exports, require("./plugins"), module.exports);
|
|
40
|
+
__reExport(src_exports, require("./solution"), module.exports);
|
|
41
|
+
var import_core = require("./core");
|
|
42
|
+
var import_core2 = __toESM(require("./core"));
|
|
43
|
+
var src_default = import_core2.default;
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
PisellOSCore,
|
|
47
|
+
...require("./types"),
|
|
48
|
+
...require("./modules"),
|
|
49
|
+
...require("./plugins"),
|
|
50
|
+
...require("./solution")
|
|
51
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
|
+
import { BaseModule } from '../BaseModule';
|
|
3
|
+
import { Account, AccountModuleAPI } from './types';
|
|
4
|
+
export declare class AccountModule extends BaseModule implements Module, AccountModuleAPI {
|
|
5
|
+
protected defaultName: string;
|
|
6
|
+
protected defaultVersion: string;
|
|
7
|
+
private state;
|
|
8
|
+
constructor(name?: string, version?: string);
|
|
9
|
+
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
10
|
+
login(credentials: {
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
logout(): Promise<void>;
|
|
15
|
+
register(account: Omit<Account, 'id'>): Promise<void>;
|
|
16
|
+
getCurrentAccount(): Account | null;
|
|
17
|
+
updateProfile(updates: Partial<Account>): Promise<void>;
|
|
18
|
+
isLoggedIn(): boolean;
|
|
19
|
+
resetPassword(email: string): Promise<void>;
|
|
20
|
+
updatePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/Account/index.ts
|
|
20
|
+
var Account_exports = {};
|
|
21
|
+
__export(Account_exports, {
|
|
22
|
+
AccountModule: () => AccountModule
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Account_exports);
|
|
25
|
+
var import_BaseModule = require("../BaseModule");
|
|
26
|
+
var import_types = require("./types");
|
|
27
|
+
var AccountModule = class extends import_BaseModule.BaseModule {
|
|
28
|
+
constructor(name, version) {
|
|
29
|
+
super(name, version);
|
|
30
|
+
this.defaultName = "account";
|
|
31
|
+
this.defaultVersion = "1.0.0";
|
|
32
|
+
this.state = {
|
|
33
|
+
currentAccount: null,
|
|
34
|
+
isLoggedIn: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async initialize(core, options) {
|
|
38
|
+
this.core = core;
|
|
39
|
+
if (options == null ? void 0 : options.initialState) {
|
|
40
|
+
this.state = { ...this.state, ...options.initialState };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async login(credentials) {
|
|
44
|
+
const account = {
|
|
45
|
+
id: "1",
|
|
46
|
+
// 实际应该从 API 返回
|
|
47
|
+
username: credentials.username,
|
|
48
|
+
email: `${credentials.username}@example.com`,
|
|
49
|
+
name: credentials.username
|
|
50
|
+
};
|
|
51
|
+
this.state.currentAccount = account;
|
|
52
|
+
this.state.isLoggedIn = true;
|
|
53
|
+
await this.core.effects.emit(import_types.AccountHooks.OnLogin, account);
|
|
54
|
+
}
|
|
55
|
+
async logout() {
|
|
56
|
+
this.state.currentAccount = null;
|
|
57
|
+
this.state.isLoggedIn = false;
|
|
58
|
+
await this.core.effects.emit(import_types.AccountHooks.OnLogout, {});
|
|
59
|
+
}
|
|
60
|
+
async register(account) {
|
|
61
|
+
const newAccount = {
|
|
62
|
+
id: "1",
|
|
63
|
+
// 实际应该从 API 返回
|
|
64
|
+
...account
|
|
65
|
+
};
|
|
66
|
+
this.state.currentAccount = newAccount;
|
|
67
|
+
this.state.isLoggedIn = true;
|
|
68
|
+
await this.core.effects.emit(import_types.AccountHooks.OnRegister, newAccount);
|
|
69
|
+
}
|
|
70
|
+
getCurrentAccount() {
|
|
71
|
+
return this.state.currentAccount;
|
|
72
|
+
}
|
|
73
|
+
async updateProfile(updates) {
|
|
74
|
+
if (!this.state.currentAccount)
|
|
75
|
+
return;
|
|
76
|
+
this.state.currentAccount = {
|
|
77
|
+
...this.state.currentAccount,
|
|
78
|
+
...updates
|
|
79
|
+
};
|
|
80
|
+
await this.core.effects.emit(import_types.AccountHooks.OnProfileUpdate, this.state.currentAccount);
|
|
81
|
+
}
|
|
82
|
+
isLoggedIn() {
|
|
83
|
+
return this.state.isLoggedIn;
|
|
84
|
+
}
|
|
85
|
+
async resetPassword(email) {
|
|
86
|
+
}
|
|
87
|
+
async updatePassword(oldPassword, newPassword) {
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
AccountModule
|
|
93
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare enum AccountHooks {
|
|
2
|
+
OnLogin = "account:onLogin",
|
|
3
|
+
OnLogout = "account:onLogout",
|
|
4
|
+
OnRegister = "account:onRegister",
|
|
5
|
+
OnProfileUpdate = "account:onProfileUpdate"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 用户账户信息
|
|
9
|
+
*/
|
|
10
|
+
export interface Account {
|
|
11
|
+
id: string;
|
|
12
|
+
username: string;
|
|
13
|
+
email: string;
|
|
14
|
+
phone?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
avatar?: string;
|
|
17
|
+
metadata?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 账户模块状态
|
|
21
|
+
*/
|
|
22
|
+
export interface AccountState {
|
|
23
|
+
currentAccount: Account | null;
|
|
24
|
+
isLoggedIn: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 账户模块 API
|
|
28
|
+
*/
|
|
29
|
+
export interface AccountModuleAPI {
|
|
30
|
+
login: (credentials: {
|
|
31
|
+
username: string;
|
|
32
|
+
password: string;
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
logout: () => Promise<void>;
|
|
35
|
+
register: (account: Omit<Account, 'id'>) => Promise<void>;
|
|
36
|
+
getCurrentAccount: () => Account | null;
|
|
37
|
+
updateProfile: (updates: Partial<Account>) => Promise<void>;
|
|
38
|
+
isLoggedIn: () => boolean;
|
|
39
|
+
resetPassword: (email: string) => Promise<void>;
|
|
40
|
+
updatePassword: (oldPassword: string, newPassword: string) => Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/Account/types.ts
|
|
20
|
+
var types_exports = {};
|
|
21
|
+
__export(types_exports, {
|
|
22
|
+
AccountHooks: () => AccountHooks
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(types_exports);
|
|
25
|
+
var AccountHooks = /* @__PURE__ */ ((AccountHooks2) => {
|
|
26
|
+
AccountHooks2["OnLogin"] = "account:onLogin";
|
|
27
|
+
AccountHooks2["OnLogout"] = "account:onLogout";
|
|
28
|
+
AccountHooks2["OnRegister"] = "account:onRegister";
|
|
29
|
+
AccountHooks2["OnProfileUpdate"] = "account:onProfileUpdate";
|
|
30
|
+
return AccountHooks2;
|
|
31
|
+
})(AccountHooks || {});
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
AccountHooks
|
|
35
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PisellCore } from "../types";
|
|
2
|
+
export declare class BaseModule {
|
|
3
|
+
protected defaultName: string;
|
|
4
|
+
protected defaultVersion: string;
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
isSolution: boolean;
|
|
8
|
+
protected core: PisellCore;
|
|
9
|
+
constructor(name?: string, version?: string);
|
|
10
|
+
destory(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/modules/BaseModule.ts
|
|
20
|
+
var BaseModule_exports = {};
|
|
21
|
+
__export(BaseModule_exports, {
|
|
22
|
+
BaseModule: () => BaseModule
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(BaseModule_exports);
|
|
25
|
+
var BaseModule = class {
|
|
26
|
+
constructor(name, version) {
|
|
27
|
+
this.defaultName = "baseModule";
|
|
28
|
+
this.defaultVersion = "1.0.0";
|
|
29
|
+
this.isSolution = false;
|
|
30
|
+
this.name = name || this.defaultName;
|
|
31
|
+
this.version = version || this.defaultVersion;
|
|
32
|
+
}
|
|
33
|
+
destory() {
|
|
34
|
+
this.core.effects.offByModuleDestroy(this.name);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
BaseModule
|
|
40
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
|
+
import { BaseModule } from '../BaseModule';
|
|
3
|
+
import { CartItem, CartModuleAPI } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
/**
|
|
6
|
+
* 购物车模块实现
|
|
7
|
+
*/
|
|
8
|
+
export declare class CartModule extends BaseModule implements Module {
|
|
9
|
+
protected defaultName: string;
|
|
10
|
+
protected defaultVersion: string;
|
|
11
|
+
private request;
|
|
12
|
+
private window;
|
|
13
|
+
private store;
|
|
14
|
+
exports: CartModuleAPI;
|
|
15
|
+
constructor(name?: string, version?: string);
|
|
16
|
+
/**
|
|
17
|
+
* 初始化购物车模块
|
|
18
|
+
*/
|
|
19
|
+
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* 模块销毁
|
|
22
|
+
*/
|
|
23
|
+
destroy(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 添加商品到购物车
|
|
26
|
+
*/
|
|
27
|
+
addItem(item: CartItem): Promise<void>;
|
|
28
|
+
getItemCount(): number;
|
|
29
|
+
getTotalPrice(): number;
|
|
30
|
+
getItems(): Promise<CartItem[]>;
|
|
31
|
+
updateItemQuantity(id: string, quantity: number): Promise<void>;
|
|
32
|
+
removeItem(id: string): Promise<void>;
|
|
33
|
+
}
|