gdmb 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gdmb.es.js +245 -130
- package/dist/gdmb.umd.js +1 -1
- package/dist/skills/gdmb/SKILL.md +29 -1
- package/dist/src/command/Command.d.ts +29 -0
- package/dist/src/command/CommandParser.d.ts +12 -0
- package/dist/src/command/CommandRegistry.d.ts +27 -0
- package/dist/src/command/CommandSystem.d.ts +32 -2
- package/dist/src/command/ConcreteCommand.d.ts +13 -2
- package/dist/src/command/index.d.ts +1 -1
- package/dist/src/type.d.ts +6 -2
- package/package.json +1 -1
package/dist/gdmb.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { container as l, Lifecycle as
|
|
2
|
-
class
|
|
1
|
+
import { container as l, Lifecycle as c, predicateAwareClassFactory as d, instancePerContainerCachingFactory as m, instanceCachingFactory as g } from "tsyringe";
|
|
2
|
+
class p {
|
|
3
3
|
/**
|
|
4
4
|
* 事件容器
|
|
5
5
|
*/
|
|
@@ -23,19 +23,19 @@ class m {
|
|
|
23
23
|
* @param handler 处理器
|
|
24
24
|
* @returns 监听句柄
|
|
25
25
|
*/
|
|
26
|
-
on(e,
|
|
26
|
+
on(e, t) {
|
|
27
27
|
const r = this._mapper[e];
|
|
28
|
-
r ? r.push(
|
|
28
|
+
r ? r.push(t) : (this.register(e), this.on(e, t));
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* 移出指定监听函数监听
|
|
32
32
|
* @param eventName 事件名称
|
|
33
33
|
* @param handler 监听函数
|
|
34
34
|
*/
|
|
35
|
-
off(e,
|
|
35
|
+
off(e, t) {
|
|
36
36
|
const r = this._mapper[e];
|
|
37
37
|
if (r) {
|
|
38
|
-
const i = r.indexOf(
|
|
38
|
+
const i = r.indexOf(t);
|
|
39
39
|
i !== -1 && r.splice(i, 1);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -44,11 +44,11 @@ class m {
|
|
|
44
44
|
* @param eventName 事件名称
|
|
45
45
|
* @param args 时间回调参数
|
|
46
46
|
*/
|
|
47
|
-
trigger(e, ...
|
|
47
|
+
trigger(e, ...t) {
|
|
48
48
|
const r = this._mapper[e];
|
|
49
49
|
r && setTimeout(() => {
|
|
50
50
|
for (const i of Object.values(r))
|
|
51
|
-
i(...
|
|
51
|
+
i(...t);
|
|
52
52
|
}, 0);
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -57,9 +57,9 @@ class m {
|
|
|
57
57
|
constructor() {
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
class
|
|
60
|
+
class q {
|
|
61
61
|
}
|
|
62
|
-
class
|
|
62
|
+
class k {
|
|
63
63
|
/**
|
|
64
64
|
* @summary 领域内部依赖注入容器
|
|
65
65
|
* @description 领域内部依赖注入容器,用于注册和解析领域服务、实体、值对象等。
|
|
@@ -68,7 +68,7 @@ class w {
|
|
|
68
68
|
/**
|
|
69
69
|
* @description 领域事件句柄,用于触发、监听、取消监听领域事件
|
|
70
70
|
*/
|
|
71
|
-
e = new
|
|
71
|
+
e = new p();
|
|
72
72
|
/**
|
|
73
73
|
* @description 向领域依赖注入容器中注册一个或多个领域服务
|
|
74
74
|
* @param service 单个领域服务类或数组
|
|
@@ -92,22 +92,22 @@ class w {
|
|
|
92
92
|
* domain.registerService(ServiceOne, { beforeResolution: ServiceOne.beforeResolution, afterResolution: ServiceOne.afterResolution })
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
|
-
registerService(e,
|
|
96
|
-
const r = Array.isArray(e) ? e : [e], i =
|
|
97
|
-
for (let
|
|
98
|
-
const
|
|
99
|
-
if (this.dic.isRegistered(
|
|
100
|
-
console.warn(`服务 ${
|
|
95
|
+
registerService(e, t) {
|
|
96
|
+
const r = Array.isArray(e) ? e : [e], i = t ? Array.isArray(t) ? t : [t] : [];
|
|
97
|
+
for (let o = 0; o < r.length; o += 1) {
|
|
98
|
+
const s = r[o], a = i[o];
|
|
99
|
+
if (this.dic.isRegistered(s.name) || this.dic.isRegistered(s)) {
|
|
100
|
+
console.warn(`服务 ${s.name} 已注册,跳过注册`);
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
this.dic.register(
|
|
104
|
-
frequency:
|
|
105
|
-
}), this.dic.beforeResolution(
|
|
106
|
-
frequency:
|
|
107
|
-
})),
|
|
108
|
-
frequency:
|
|
109
|
-
}), this.dic.afterResolution(
|
|
110
|
-
frequency:
|
|
103
|
+
this.dic.register(s.name, { useClass: s }), this.dic.register(s, { useClass: s }), a?.beforeResolution && (this.dic.beforeResolution(s.name, a.beforeResolution, {
|
|
104
|
+
frequency: a?.beforeResolutionFrequency || "Always"
|
|
105
|
+
}), this.dic.beforeResolution(s, a.beforeResolution, {
|
|
106
|
+
frequency: a?.beforeResolutionFrequency || "Always"
|
|
107
|
+
})), a?.afterResolution && (this.dic.afterResolution(s.name, a.afterResolution, {
|
|
108
|
+
frequency: a?.afterResolutionFrequency || "Always"
|
|
109
|
+
}), this.dic.afterResolution(s, a?.afterResolution, {
|
|
110
|
+
frequency: a?.afterResolutionFrequency || "Always"
|
|
111
111
|
}));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -134,36 +134,36 @@ class w {
|
|
|
134
134
|
* domain.registerEntity(EntityOne, { cachePolicy: 'cache', beforeResolution: EntityOne.beforeResolution, afterResolution: EntityOne.afterResolution })
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
registerEntity(e,
|
|
138
|
-
const r = Array.isArray(e) ? e : [e], i =
|
|
139
|
-
for (let
|
|
140
|
-
const
|
|
141
|
-
if (this.dic.isRegistered(
|
|
142
|
-
console.warn(`实体 ${
|
|
137
|
+
registerEntity(e, t) {
|
|
138
|
+
const r = Array.isArray(e) ? e : [e], i = t ? Array.isArray(t) ? t : [t] : [];
|
|
139
|
+
for (let o = 0; o < r.length; o += 1) {
|
|
140
|
+
const s = r[o], a = i[o];
|
|
141
|
+
if (this.dic.isRegistered(s.name) || this.dic.isRegistered(s)) {
|
|
142
|
+
console.warn(`实体 ${s.name} 已注册,跳过注册`);
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
|
-
if (
|
|
146
|
-
switch (
|
|
145
|
+
if (a?.cachePolicy)
|
|
146
|
+
switch (a.cachePolicy) {
|
|
147
147
|
case "cache":
|
|
148
|
-
l.register(
|
|
148
|
+
l.register(s.name, { useClass: s }, { lifecycle: c.Singleton }), l.register(s, { useClass: s }, { lifecycle: c.Singleton });
|
|
149
149
|
break;
|
|
150
150
|
case "containerCache":
|
|
151
|
-
this.dic.register(
|
|
151
|
+
this.dic.register(s.name, { useClass: s }, { lifecycle: c.ContainerScoped }), this.dic.register(s, { useClass: s }, { lifecycle: c.ContainerScoped });
|
|
152
152
|
break;
|
|
153
153
|
case "resolution":
|
|
154
|
-
this.dic.register(
|
|
154
|
+
this.dic.register(s.name, { useClass: s }, { lifecycle: c.ResolutionScoped }), this.dic.register(s, { useClass: s }, { lifecycle: c.ResolutionScoped });
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
else
|
|
158
|
-
this.dic.register(
|
|
159
|
-
|
|
160
|
-
frequency: "Always"
|
|
161
|
-
}), this.dic.beforeResolution(
|
|
162
|
-
frequency: "Always"
|
|
163
|
-
})),
|
|
164
|
-
frequency: "Always"
|
|
165
|
-
}), this.dic.afterResolution(
|
|
166
|
-
frequency: "Always"
|
|
158
|
+
this.dic.register(s.name, { useClass: s }, { lifecycle: c.Transient }), this.dic.register(s, { useClass: s }, { lifecycle: c.Transient });
|
|
159
|
+
a?.beforeResolution && (this.dic.beforeResolution(s.name, a.beforeResolution, {
|
|
160
|
+
frequency: a?.beforeResolutionFrequency || "Always"
|
|
161
|
+
}), this.dic.beforeResolution(s, a.beforeResolution, {
|
|
162
|
+
frequency: a?.beforeResolutionFrequency || "Always"
|
|
163
|
+
})), a?.afterResolution && (this.dic.afterResolution(s.name, a.afterResolution, {
|
|
164
|
+
frequency: a?.afterResolutionFrequency || "Always"
|
|
165
|
+
}), this.dic.afterResolution(s, a.afterResolution, {
|
|
166
|
+
frequency: a?.afterResolutionFrequency || "Always"
|
|
167
167
|
}));
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -181,21 +181,21 @@ class w {
|
|
|
181
181
|
* ```
|
|
182
182
|
*/
|
|
183
183
|
registerVO(e) {
|
|
184
|
-
const
|
|
185
|
-
for (let r = 0; r <
|
|
186
|
-
const i =
|
|
187
|
-
for (let
|
|
188
|
-
const
|
|
184
|
+
const t = Array.isArray(e) ? e : [e];
|
|
185
|
+
for (let r = 0; r < t.length; r += 1) {
|
|
186
|
+
const i = t[r], o = Array.isArray(i.token) ? i.token : [i.token];
|
|
187
|
+
for (let s = 0; s < o.length; s += 1) {
|
|
188
|
+
const a = o[s];
|
|
189
189
|
switch (i.factoryType) {
|
|
190
190
|
case "cache":
|
|
191
|
-
l.register(
|
|
191
|
+
l.register(a, { useFactory: g(i.resolveFactory) });
|
|
192
192
|
break;
|
|
193
193
|
case "containerCache":
|
|
194
|
-
this.dic.register(
|
|
194
|
+
this.dic.register(a, { useFactory: m(i.resolveFactory) });
|
|
195
195
|
break;
|
|
196
196
|
case "predicate":
|
|
197
|
-
this.dic.register(
|
|
198
|
-
useFactory:
|
|
197
|
+
this.dic.register(a, {
|
|
198
|
+
useFactory: d(
|
|
199
199
|
i.resolveFactory,
|
|
200
200
|
i.positiveTarget,
|
|
201
201
|
i.negativeTarget
|
|
@@ -203,7 +203,7 @@ class w {
|
|
|
203
203
|
});
|
|
204
204
|
break;
|
|
205
205
|
default:
|
|
206
|
-
this.dic.register(
|
|
206
|
+
this.dic.register(a, { useFactory: i.resolveFactory });
|
|
207
207
|
break;
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -215,8 +215,8 @@ class w {
|
|
|
215
215
|
* @returns 领域服务实例对象
|
|
216
216
|
*/
|
|
217
217
|
services(e) {
|
|
218
|
-
const
|
|
219
|
-
return
|
|
218
|
+
const t = this.dic.resolve(e);
|
|
219
|
+
return t && !t?.e && (t.e = this.e), t;
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
222
|
* @description 从依赖注入容器中获取领域实体实例对象
|
|
@@ -224,11 +224,11 @@ class w {
|
|
|
224
224
|
* @param adapter 领域实体适配器,将 DEF 类型转换为 DE 类型
|
|
225
225
|
* @returns 领域实体实例对象
|
|
226
226
|
*/
|
|
227
|
-
entities(e,
|
|
227
|
+
entities(e, t) {
|
|
228
228
|
let r;
|
|
229
|
-
if (
|
|
229
|
+
if (t) {
|
|
230
230
|
const i = this.dic.resolve(e);
|
|
231
|
-
r =
|
|
231
|
+
r = t.transform(i);
|
|
232
232
|
} else
|
|
233
233
|
r = this.dic.resolve(e);
|
|
234
234
|
return r && !r?.e && (r.e = this.e), r;
|
|
@@ -239,10 +239,10 @@ class w {
|
|
|
239
239
|
* @param adapter 领域值对象适配器,将 VF 类型转换为 V 类型
|
|
240
240
|
* @returns 领域值对象实例对象
|
|
241
241
|
*/
|
|
242
|
-
vos(e,
|
|
243
|
-
if (
|
|
242
|
+
vos(e, t) {
|
|
243
|
+
if (t) {
|
|
244
244
|
const r = this.dic.resolve(e);
|
|
245
|
-
return
|
|
245
|
+
return t.transform(r);
|
|
246
246
|
} else
|
|
247
247
|
return this.dic.resolve(e);
|
|
248
248
|
}
|
|
@@ -252,17 +252,17 @@ class w {
|
|
|
252
252
|
constructor() {
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
const
|
|
255
|
+
const f = (n) => (n.prototype.$ins = null, class extends n {
|
|
256
256
|
constructor(...e) {
|
|
257
|
-
return super(...e),
|
|
257
|
+
return super(...e), n.prototype.$ins || (n.prototype.$ins = this), n.prototype.$ins;
|
|
258
258
|
}
|
|
259
259
|
});
|
|
260
|
-
var
|
|
261
|
-
for (var i = r > 1 ? void 0 : r ?
|
|
262
|
-
(
|
|
260
|
+
var C = Object.getOwnPropertyDescriptor, R = (n, e, t, r) => {
|
|
261
|
+
for (var i = r > 1 ? void 0 : r ? C(e, t) : e, o = n.length - 1, s; o >= 0; o--)
|
|
262
|
+
(s = n[o]) && (i = s(i) || i);
|
|
263
263
|
return i;
|
|
264
264
|
};
|
|
265
|
-
let
|
|
265
|
+
let h = class {
|
|
266
266
|
/** 事件句柄 */
|
|
267
267
|
e = void 0;
|
|
268
268
|
/**
|
|
@@ -271,10 +271,10 @@ let u = class {
|
|
|
271
271
|
constructor() {
|
|
272
272
|
}
|
|
273
273
|
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
],
|
|
277
|
-
class
|
|
274
|
+
h = R([
|
|
275
|
+
f
|
|
276
|
+
], h);
|
|
277
|
+
class I {
|
|
278
278
|
/** 事件句柄 */
|
|
279
279
|
e = void 0;
|
|
280
280
|
/**
|
|
@@ -283,7 +283,7 @@ class F {
|
|
|
283
283
|
constructor() {
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
class
|
|
286
|
+
class v {
|
|
287
287
|
/**
|
|
288
288
|
* 命令历史记录
|
|
289
289
|
*/
|
|
@@ -335,7 +335,7 @@ class R {
|
|
|
335
335
|
* @param commands 要执行的命令数组
|
|
336
336
|
*/
|
|
337
337
|
executeBatch(e) {
|
|
338
|
-
e.forEach((
|
|
338
|
+
e.forEach((t) => this.execute(t));
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* 清空命令历史
|
|
@@ -379,7 +379,7 @@ class R {
|
|
|
379
379
|
this.maxHistoryDepth = e?.maxHistoryDepth || 1 / 0, this.maxUndoHistoryDepth = e?.maxUndoHistoryDepth || 1 / 0;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
class
|
|
382
|
+
class H {
|
|
383
383
|
/**
|
|
384
384
|
* 命令接收者
|
|
385
385
|
*/
|
|
@@ -396,15 +396,20 @@ class C {
|
|
|
396
396
|
* 命令描述
|
|
397
397
|
*/
|
|
398
398
|
description;
|
|
399
|
+
/**
|
|
400
|
+
* 原始命令字符串
|
|
401
|
+
*/
|
|
402
|
+
commandString;
|
|
399
403
|
/**
|
|
400
404
|
* 构造函数
|
|
401
405
|
* @param receiver 命令接收者
|
|
402
406
|
* @param executeFn 执行操作的函数
|
|
403
407
|
* @param undoFn 撤销操作的函数
|
|
404
408
|
* @param description 命令描述
|
|
409
|
+
* @param commandString 原始命令字符串
|
|
405
410
|
*/
|
|
406
|
-
constructor(e,
|
|
407
|
-
this.receiver = e, this.executeFn =
|
|
411
|
+
constructor(e, t, r, i, o = "") {
|
|
412
|
+
this.receiver = e, this.executeFn = t, this.undoFn = r, this.description = i, this.commandString = o;
|
|
408
413
|
}
|
|
409
414
|
/**
|
|
410
415
|
* 执行命令
|
|
@@ -425,32 +430,136 @@ class C {
|
|
|
425
430
|
getDescription() {
|
|
426
431
|
return this.description;
|
|
427
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* 获取原始命令字符串
|
|
435
|
+
* @returns 命令字符串
|
|
436
|
+
*/
|
|
437
|
+
getCommandString() {
|
|
438
|
+
return this.commandString;
|
|
439
|
+
}
|
|
428
440
|
}
|
|
429
|
-
function
|
|
430
|
-
return new
|
|
441
|
+
function b(n, e, t, r, i = "") {
|
|
442
|
+
return new H(n, e, t, r, i);
|
|
431
443
|
}
|
|
432
444
|
class D {
|
|
445
|
+
/** 命令注册映射 */
|
|
446
|
+
commands = /* @__PURE__ */ new Map();
|
|
447
|
+
/**
|
|
448
|
+
* 注册命令
|
|
449
|
+
* @param name 命令名
|
|
450
|
+
* @param receiver 命令接收者
|
|
451
|
+
* @param creator 命令创建函数
|
|
452
|
+
* @param description 命令描述
|
|
453
|
+
*/
|
|
454
|
+
register(e, t, r) {
|
|
455
|
+
this.commands.set(e, { receiver: t, description: r });
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* 获取命令注册信息
|
|
459
|
+
*/
|
|
460
|
+
get(e) {
|
|
461
|
+
return this.commands.get(e);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* 列出所有已注册的命令
|
|
465
|
+
*/
|
|
466
|
+
listCommands() {
|
|
467
|
+
return [...this.commands.entries()].map(([e, t]) => ({
|
|
468
|
+
name: e,
|
|
469
|
+
description: t.description
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
class x {
|
|
474
|
+
/**
|
|
475
|
+
* 解析命令字符串
|
|
476
|
+
* @param commandString 命令字符串,如 "add -a 10 -b 5"
|
|
477
|
+
* @returns ParsedCommand 对象
|
|
478
|
+
*/
|
|
479
|
+
parse(e) {
|
|
480
|
+
const t = e.trim().split(/\s+/g), r = t[0], i = /* @__PURE__ */ new Map();
|
|
481
|
+
for (let o = 1; o < t.length; o++) {
|
|
482
|
+
const s = t[o];
|
|
483
|
+
if (s.startsWith("-")) {
|
|
484
|
+
const a = s.slice(1);
|
|
485
|
+
if (o + 1 >= t.length || t[o + 1].startsWith("-"))
|
|
486
|
+
i.set(a, !0);
|
|
487
|
+
else {
|
|
488
|
+
const u = t[o + 1];
|
|
489
|
+
isNaN(Number(u)) ? i.set(a, u) : i.set(a, Number(u)), o++;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
commandName: r,
|
|
495
|
+
options: i,
|
|
496
|
+
args: t.slice(1)
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
class w {
|
|
433
501
|
/**
|
|
434
502
|
* 命令调用者
|
|
435
503
|
*/
|
|
436
504
|
invoker;
|
|
505
|
+
/**
|
|
506
|
+
* 命令解析器
|
|
507
|
+
*/
|
|
508
|
+
parser = new x();
|
|
509
|
+
/**
|
|
510
|
+
* 命令注册器
|
|
511
|
+
*/
|
|
512
|
+
registry = new D();
|
|
513
|
+
/**
|
|
514
|
+
* 注册命令
|
|
515
|
+
* @param name 命令名称
|
|
516
|
+
* @param receiver 命令接收者
|
|
517
|
+
*/
|
|
518
|
+
register(e) {
|
|
519
|
+
this.registry.register(e.name, e, e.description);
|
|
520
|
+
}
|
|
437
521
|
/**
|
|
438
522
|
* 创建命令
|
|
439
523
|
* @param receiver 命令接收者
|
|
440
524
|
* @param executeFn 执行操作的函数
|
|
441
525
|
* @param undoFn 撤销操作的函数
|
|
442
526
|
* @param description 命令描述
|
|
527
|
+
* @param commandString 原始命令字符串
|
|
443
528
|
* @returns 命令对象
|
|
444
529
|
*/
|
|
445
|
-
create(e,
|
|
446
|
-
return
|
|
530
|
+
create(e, t, r, i, o = "") {
|
|
531
|
+
return b(e, t, r, i, o);
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* 从命令字符串创建 Command
|
|
535
|
+
* @param commandString 命令字符串
|
|
536
|
+
* @param description 针对本次命令描述
|
|
537
|
+
* @returns Command 实例,失败返回 undefined
|
|
538
|
+
*/
|
|
539
|
+
createFromCommandString(e, t) {
|
|
540
|
+
const r = this.parser.parse(e), i = this.registry.get(r.commandName);
|
|
541
|
+
if (!i) {
|
|
542
|
+
console.warn(`命令 ${r.commandName} 未注册`);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
return i.receiver.creator?.(
|
|
546
|
+
r.options,
|
|
547
|
+
r.args,
|
|
548
|
+
t || i.description,
|
|
549
|
+
e
|
|
550
|
+
);
|
|
447
551
|
}
|
|
448
552
|
/**
|
|
449
553
|
* 执行命令
|
|
450
554
|
* @param command 要执行的命令
|
|
555
|
+
* @param description 针对本次命令描述
|
|
451
556
|
*/
|
|
452
|
-
execute(e) {
|
|
453
|
-
|
|
557
|
+
execute(e, t) {
|
|
558
|
+
if (typeof e == "string") {
|
|
559
|
+
const r = this.createFromCommandString(e, t);
|
|
560
|
+
r && this.invoker.execute(r);
|
|
561
|
+
} else
|
|
562
|
+
this.invoker.execute(e);
|
|
454
563
|
}
|
|
455
564
|
/**
|
|
456
565
|
* 撤销上一个命令
|
|
@@ -507,23 +616,29 @@ class D {
|
|
|
507
616
|
getUndoHistoryCount() {
|
|
508
617
|
return this.invoker.getUndoHistoryCount();
|
|
509
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* 列出所有可用命令
|
|
621
|
+
*/
|
|
622
|
+
listCommands() {
|
|
623
|
+
return this.registry.listCommands();
|
|
624
|
+
}
|
|
510
625
|
/**
|
|
511
626
|
* 构造函数
|
|
512
627
|
* @param option 配置参数
|
|
513
628
|
*/
|
|
514
629
|
constructor(e) {
|
|
515
|
-
this.invoker = new
|
|
630
|
+
this.invoker = new v({
|
|
516
631
|
maxHistoryDepth: e?.maxHistoryDepth,
|
|
517
632
|
maxUndoHistoryDepth: e?.maxUndoHistoryDepth
|
|
518
633
|
});
|
|
519
634
|
}
|
|
520
635
|
}
|
|
521
|
-
var
|
|
522
|
-
for (var i = r > 1 ? void 0 : r ?
|
|
523
|
-
(
|
|
636
|
+
var A = Object.getOwnPropertyDescriptor, F = (n, e, t, r) => {
|
|
637
|
+
for (var i = r > 1 ? void 0 : r ? A(e, t) : e, o = n.length - 1, s; o >= 0; o--)
|
|
638
|
+
(s = n[o]) && (i = s(i) || i);
|
|
524
639
|
return i;
|
|
525
640
|
};
|
|
526
|
-
let
|
|
641
|
+
let y = class {
|
|
527
642
|
/** 全局 DIC */
|
|
528
643
|
globalDIC = l;
|
|
529
644
|
/** 命令系统 */
|
|
@@ -531,71 +646,71 @@ let h = class {
|
|
|
531
646
|
/**
|
|
532
647
|
* 注册领域对象
|
|
533
648
|
*/
|
|
534
|
-
registerDomain(
|
|
535
|
-
const
|
|
536
|
-
for (let i = 0; i <
|
|
537
|
-
const
|
|
538
|
-
if (this.globalDIC.isRegistered(
|
|
539
|
-
console.warn(`领域 ${
|
|
649
|
+
registerDomain(n, e) {
|
|
650
|
+
const t = Array.isArray(n) ? n : [n], r = e ? Array.isArray(e) ? e : [e] : [];
|
|
651
|
+
for (let i = 0; i < t.length; i += 1) {
|
|
652
|
+
const o = t[i], s = r[i];
|
|
653
|
+
if (this.globalDIC.isRegistered(o.name)) {
|
|
654
|
+
console.warn(`领域 ${o.name} 已注册,无法重复注册`);
|
|
540
655
|
return;
|
|
541
656
|
}
|
|
542
|
-
const
|
|
543
|
-
this.globalDIC.register(
|
|
544
|
-
frequency:
|
|
545
|
-
}), this.globalDIC.beforeResolution(
|
|
546
|
-
frequency:
|
|
547
|
-
})),
|
|
548
|
-
frequency:
|
|
549
|
-
}), this.globalDIC.afterResolution(
|
|
550
|
-
frequency:
|
|
657
|
+
const a = new o(...s?.args || []);
|
|
658
|
+
this.globalDIC.register(o.name, { useValue: a }), this.globalDIC.register(o, { useValue: a }), s?.beforeResolution && (this.globalDIC.beforeResolution(o.name, s.beforeResolution, {
|
|
659
|
+
frequency: s.beforeResolutionFrequency || "Always"
|
|
660
|
+
}), this.globalDIC.beforeResolution(o, s.beforeResolution, {
|
|
661
|
+
frequency: s.afterResolutionFrequency || "Always"
|
|
662
|
+
})), s?.afterResolution && (this.globalDIC.afterResolution(o.name, s.afterResolution, {
|
|
663
|
+
frequency: s.afterResolutionFrequency || "Always"
|
|
664
|
+
}), this.globalDIC.afterResolution(o, s.afterResolution, {
|
|
665
|
+
frequency: s.afterResolutionFrequency || "Always"
|
|
551
666
|
}));
|
|
552
667
|
}
|
|
553
668
|
}
|
|
554
669
|
/**
|
|
555
670
|
* 获取领域对象
|
|
556
671
|
*/
|
|
557
|
-
domains(
|
|
558
|
-
return this.globalDIC.resolve(
|
|
672
|
+
domains(n) {
|
|
673
|
+
return this.globalDIC.resolve(n);
|
|
559
674
|
}
|
|
560
675
|
/**
|
|
561
676
|
* 提供全局的转换方法
|
|
562
677
|
*/
|
|
563
|
-
transform(
|
|
564
|
-
return e.transform(
|
|
678
|
+
transform(n, e) {
|
|
679
|
+
return e.transform(n);
|
|
565
680
|
}
|
|
566
681
|
/**
|
|
567
682
|
* 提供全局的转换方法,支持批量转换
|
|
568
683
|
*/
|
|
569
|
-
transformAll(
|
|
570
|
-
const
|
|
571
|
-
for (let r = 0; r <
|
|
572
|
-
const i = e.transform(
|
|
573
|
-
i != null &&
|
|
684
|
+
transformAll(n, e) {
|
|
685
|
+
const t = [];
|
|
686
|
+
for (let r = 0; r < n.length; r += 1) {
|
|
687
|
+
const i = e.transform(n[r]);
|
|
688
|
+
i != null && t.push(i);
|
|
574
689
|
}
|
|
575
|
-
return
|
|
690
|
+
return t;
|
|
576
691
|
}
|
|
577
692
|
/**
|
|
578
693
|
* 构造函数
|
|
579
694
|
* @param option 配置参数
|
|
580
695
|
*/
|
|
581
|
-
constructor(
|
|
582
|
-
this.c = new
|
|
583
|
-
maxHistoryDepth:
|
|
584
|
-
maxUndoHistoryDepth:
|
|
696
|
+
constructor(n) {
|
|
697
|
+
this.c = new w({
|
|
698
|
+
maxHistoryDepth: n?.maxHistoryDepth,
|
|
699
|
+
maxUndoHistoryDepth: n?.maxUndoHistoryDepth
|
|
585
700
|
});
|
|
586
701
|
}
|
|
587
702
|
};
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
],
|
|
703
|
+
y = F([
|
|
704
|
+
f
|
|
705
|
+
], y);
|
|
591
706
|
export {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
707
|
+
q as Adapter,
|
|
708
|
+
v as CommandInvoker,
|
|
709
|
+
w as CommandSystem,
|
|
710
|
+
H as ConcreteCommand,
|
|
711
|
+
k as Domain,
|
|
712
|
+
I as DomainEntity,
|
|
713
|
+
h as DomainService,
|
|
714
|
+
y as GDMB,
|
|
715
|
+
b as createCommand
|
|
601
716
|
};
|
package/dist/gdmb.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("tsyringe")):typeof define=="function"&&define.amd?define(["exports","tsyringe"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.gdmb={},l.tsyringe))})(this,(function(l,a){"use strict";class g{_mapper={};register(e){e in this._mapper||(this._mapper[e]=[])}remove(e){e in this._mapper&&delete this._mapper[e]}on(e,
|
|
1
|
+
(function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("tsyringe")):typeof define=="function"&&define.amd?define(["exports","tsyringe"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.gdmb={},l.tsyringe))})(this,(function(l,a){"use strict";class g{_mapper={};register(e){e in this._mapper||(this._mapper[e]=[])}remove(e){e in this._mapper&&delete this._mapper[e]}on(e,t){const s=this._mapper[e];s?s.push(t):(this.register(e),this.on(e,t))}off(e,t){const s=this._mapper[e];if(s){const i=s.indexOf(t);i!==-1&&s.splice(i,1)}}trigger(e,...t){const s=this._mapper[e];s&&setTimeout(()=>{for(const i of Object.values(s))i(...t)},0)}constructor(){}}class p{}class C{dic=a.container.createChildContainer();e=new g;registerService(e,t){const s=Array.isArray(e)?e:[e],i=t?Array.isArray(t)?t:[t]:[];for(let n=0;n<s.length;n+=1){const r=s[n],o=i[n];if(this.dic.isRegistered(r.name)||this.dic.isRegistered(r)){console.warn(`服务 ${r.name} 已注册,跳过注册`);continue}this.dic.register(r.name,{useClass:r}),this.dic.register(r,{useClass:r}),o?.beforeResolution&&(this.dic.beforeResolution(r.name,o.beforeResolution,{frequency:o?.beforeResolutionFrequency||"Always"}),this.dic.beforeResolution(r,o.beforeResolution,{frequency:o?.beforeResolutionFrequency||"Always"})),o?.afterResolution&&(this.dic.afterResolution(r.name,o.afterResolution,{frequency:o?.afterResolutionFrequency||"Always"}),this.dic.afterResolution(r,o?.afterResolution,{frequency:o?.afterResolutionFrequency||"Always"}))}}registerEntity(e,t){const s=Array.isArray(e)?e:[e],i=t?Array.isArray(t)?t:[t]:[];for(let n=0;n<s.length;n+=1){const r=s[n],o=i[n];if(this.dic.isRegistered(r.name)||this.dic.isRegistered(r)){console.warn(`实体 ${r.name} 已注册,跳过注册`);continue}if(o?.cachePolicy)switch(o.cachePolicy){case"cache":a.container.register(r.name,{useClass:r},{lifecycle:a.Lifecycle.Singleton}),a.container.register(r,{useClass:r},{lifecycle:a.Lifecycle.Singleton});break;case"containerCache":this.dic.register(r.name,{useClass:r},{lifecycle:a.Lifecycle.ContainerScoped}),this.dic.register(r,{useClass:r},{lifecycle:a.Lifecycle.ContainerScoped});break;case"resolution":this.dic.register(r.name,{useClass:r},{lifecycle:a.Lifecycle.ResolutionScoped}),this.dic.register(r,{useClass:r},{lifecycle:a.Lifecycle.ResolutionScoped});break}else this.dic.register(r.name,{useClass:r},{lifecycle:a.Lifecycle.Transient}),this.dic.register(r,{useClass:r},{lifecycle:a.Lifecycle.Transient});o?.beforeResolution&&(this.dic.beforeResolution(r.name,o.beforeResolution,{frequency:o?.beforeResolutionFrequency||"Always"}),this.dic.beforeResolution(r,o.beforeResolution,{frequency:o?.beforeResolutionFrequency||"Always"})),o?.afterResolution&&(this.dic.afterResolution(r.name,o.afterResolution,{frequency:o?.afterResolutionFrequency||"Always"}),this.dic.afterResolution(r,o.afterResolution,{frequency:o?.afterResolutionFrequency||"Always"}))}}registerVO(e){const t=Array.isArray(e)?e:[e];for(let s=0;s<t.length;s+=1){const i=t[s],n=Array.isArray(i.token)?i.token:[i.token];for(let r=0;r<n.length;r+=1){const o=n[r];switch(i.factoryType){case"cache":a.container.register(o,{useFactory:a.instanceCachingFactory(i.resolveFactory)});break;case"containerCache":this.dic.register(o,{useFactory:a.instancePerContainerCachingFactory(i.resolveFactory)});break;case"predicate":this.dic.register(o,{useFactory:a.predicateAwareClassFactory(i.resolveFactory,i.positiveTarget,i.negativeTarget)});break;default:this.dic.register(o,{useFactory:i.resolveFactory});break}}}}services(e){const t=this.dic.resolve(e);return t&&!t?.e&&(t.e=this.e),t}entities(e,t){let s;if(t){const i=this.dic.resolve(e);s=t.transform(i)}else s=this.dic.resolve(e);return s&&!s?.e&&(s.e=this.e),s}vos(e,t){if(t){const s=this.dic.resolve(e);return t.transform(s)}else return this.dic.resolve(e)}constructor(){}}const h=c=>(c.prototype.$ins=null,class extends c{constructor(...e){return super(...e),c.prototype.$ins||(c.prototype.$ins=this),c.prototype.$ins}});var v=Object.getOwnPropertyDescriptor,R=(c,e,t,s)=>{for(var i=s>1?void 0:s?v(e,t):e,n=c.length-1,r;n>=0;n--)(r=c[n])&&(i=r(i)||i);return i};l.DomainService=class{e=void 0;constructor(){}},l.DomainService=R([h],l.DomainService);class D{e=void 0;constructor(){}}class f{history=[];undoHistory=[];maxHistoryDepth;maxUndoHistoryDepth;execute(e){e.execute(),this.history.push({command:e,timestamp:Date.now()}),this.undoHistory=[],this.history.length>this.maxHistoryDepth&&this.history.shift()}undo(){if(this.history.length===0)return!1;const e=this.history.pop();return e?(e.command.undo(),this.undoHistory.push(e),this.undoHistory.length>this.maxUndoHistoryDepth&&this.undoHistory.shift(),!0):!1}redo(){if(this.undoHistory.length===0)return!1;const e=this.undoHistory.pop();return e?(e.command.execute(),this.history.push(e),this.history.length>this.maxHistoryDepth&&this.history.shift(),!0):!1}executeBatch(e){e.forEach(t=>this.execute(t))}clearHistory(){this.history=[],this.undoHistory=[]}getHistory(){return[...this.history]}getUndoHistory(){return[...this.undoHistory]}getHistoryCount(){return this.history.length}getUndoHistoryCount(){return this.undoHistory.length}constructor(e){this.maxHistoryDepth=e?.maxHistoryDepth||1/0,this.maxUndoHistoryDepth=e?.maxUndoHistoryDepth||1/0}}class y{receiver;executeFn;undoFn;description;commandString;constructor(e,t,s,i,n=""){this.receiver=e,this.executeFn=t,this.undoFn=s,this.description=i,this.commandString=n}execute(){this.executeFn(this.receiver)}undo(){this.undoFn(this.receiver)}getDescription(){return this.description}getCommandString(){return this.commandString}}function d(c,e,t,s,i=""){return new y(c,e,t,s,i)}class b{commands=new Map;register(e,t,s){this.commands.set(e,{receiver:t,description:s})}get(e){return this.commands.get(e)}listCommands(){return[...this.commands.entries()].map(([e,t])=>({name:e,description:t.description}))}}class H{parse(e){const t=e.trim().split(/\s+/g),s=t[0],i=new Map;for(let n=1;n<t.length;n++){const r=t[n];if(r.startsWith("-")){const o=r.slice(1);if(n+1>=t.length||t[n+1].startsWith("-"))i.set(o,!0);else{const u=t[n+1];isNaN(Number(u))?i.set(o,u):i.set(o,Number(u)),n++}}}return{commandName:s,options:i,args:t.slice(1)}}}class m{invoker;parser=new H;registry=new b;register(e){this.registry.register(e.name,e,e.description)}create(e,t,s,i,n=""){return d(e,t,s,i,n)}createFromCommandString(e,t){const s=this.parser.parse(e),i=this.registry.get(s.commandName);if(!i){console.warn(`命令 ${s.commandName} 未注册`);return}return i.receiver.creator?.(s.options,s.args,t||i.description,e)}execute(e,t){if(typeof e=="string"){const s=this.createFromCommandString(e,t);s&&this.invoker.execute(s)}else this.invoker.execute(e)}undo(){return this.invoker.undo()}redo(){return this.invoker.redo()}executeBatch(e){this.invoker.executeBatch(e)}clearHistory(){this.invoker.clearHistory()}getHistory(){return this.invoker.getHistory()}getUndoHistory(){return this.invoker.getUndoHistory()}getHistoryCount(){return this.invoker.getHistoryCount()}getUndoHistoryCount(){return this.invoker.getUndoHistoryCount()}listCommands(){return this.registry.listCommands()}constructor(e){this.invoker=new f({maxHistoryDepth:e?.maxHistoryDepth,maxUndoHistoryDepth:e?.maxUndoHistoryDepth})}}var w=Object.getOwnPropertyDescriptor,A=(c,e,t,s)=>{for(var i=s>1?void 0:s?w(e,t):e,n=c.length-1,r;n>=0;n--)(r=c[n])&&(i=r(i)||i);return i};l.GDMB=class{globalDIC=a.container;c;registerDomain(e,t){const s=Array.isArray(e)?e:[e],i=t?Array.isArray(t)?t:[t]:[];for(let n=0;n<s.length;n+=1){const r=s[n],o=i[n];if(this.globalDIC.isRegistered(r.name)){console.warn(`领域 ${r.name} 已注册,无法重复注册`);return}const u=new r(...o?.args||[]);this.globalDIC.register(r.name,{useValue:u}),this.globalDIC.register(r,{useValue:u}),o?.beforeResolution&&(this.globalDIC.beforeResolution(r.name,o.beforeResolution,{frequency:o.beforeResolutionFrequency||"Always"}),this.globalDIC.beforeResolution(r,o.beforeResolution,{frequency:o.afterResolutionFrequency||"Always"})),o?.afterResolution&&(this.globalDIC.afterResolution(r.name,o.afterResolution,{frequency:o.afterResolutionFrequency||"Always"}),this.globalDIC.afterResolution(r,o.afterResolution,{frequency:o.afterResolutionFrequency||"Always"}))}}domains(e){return this.globalDIC.resolve(e)}transform(e,t){return t.transform(e)}transformAll(e,t){const s=[];for(let i=0;i<e.length;i+=1){const n=t.transform(e[i]);n!=null&&s.push(n)}return s}constructor(e){this.c=new m({maxHistoryDepth:e?.maxHistoryDepth,maxUndoHistoryDepth:e?.maxUndoHistoryDepth})}},l.GDMB=A([h],l.GDMB),l.Adapter=p,l.CommandInvoker=f,l.CommandSystem=m,l.ConcreteCommand=y,l.Domain=C,l.DomainEntity=D,l.createCommand=d,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -155,11 +155,35 @@ const voOne = domainObject.vos<IVOOne>('IVOOne'); // { text: 'text', num: 1 }
|
|
|
155
155
|
### 命令系统(Command System)
|
|
156
156
|
```typescript
|
|
157
157
|
import { GDMB } from 'gdmb';
|
|
158
|
-
import type { Command, CommandReceiver } from 'gdmb';
|
|
158
|
+
import type { Command, CommandReceiver, CommandCreator } from 'gdmb';
|
|
159
159
|
// 实例化全局对象
|
|
160
160
|
const gdmb = new GDMB();
|
|
161
161
|
// 定义命令接受者作为命令执行者
|
|
162
162
|
class CounterReceiver implements CounterReceiver {
|
|
163
|
+
// 命令名称,用于命令注册和执行(必要)
|
|
164
|
+
name: 'counter';
|
|
165
|
+
// 命令描述,说明命令作用和支持的参数
|
|
166
|
+
description: `
|
|
167
|
+
计算器命令,支持参数:
|
|
168
|
+
-type increment | decrement
|
|
169
|
+
-value number
|
|
170
|
+
`;
|
|
171
|
+
// 命令创建器,返回一个Command对象(必要)
|
|
172
|
+
creator: CommandCreator = (
|
|
173
|
+
options: Map<string, string | number | boolean>,
|
|
174
|
+
args: string[],
|
|
175
|
+
description: string,
|
|
176
|
+
commandString: string
|
|
177
|
+
) => {
|
|
178
|
+
const value = (options.get('value') as number) || 0;
|
|
179
|
+
return gdmb.c.create(
|
|
180
|
+
this,
|
|
181
|
+
(r) => r.executeOperation(value),
|
|
182
|
+
(r) => r.undoOperation(),
|
|
183
|
+
description,
|
|
184
|
+
commandString
|
|
185
|
+
);
|
|
186
|
+
};
|
|
163
187
|
// 执行函数(必要)
|
|
164
188
|
executeOperation({ type, value = 1 }: { type: string; value?: number }): void {
|
|
165
189
|
// 执行函数实现
|
|
@@ -178,6 +202,10 @@ const command = gdmb.c.create(
|
|
|
178
202
|
);
|
|
179
203
|
// 执行命令
|
|
180
204
|
gdmb.c.execute(command);
|
|
205
|
+
// 撤销命令
|
|
206
|
+
gdmb.c.undo(command);
|
|
207
|
+
// 执行字符串命令
|
|
208
|
+
gdmb.c.execute('counter -type increment -value 5');
|
|
181
209
|
```
|
|
182
210
|
|
|
183
211
|
## 代码检查清单(Code Review Checklist)
|
|
@@ -15,6 +15,29 @@ export interface Command {
|
|
|
15
15
|
* 获取命令描述
|
|
16
16
|
*/
|
|
17
17
|
getDescription(): string;
|
|
18
|
+
/**
|
|
19
|
+
* 获取原始命令字符串
|
|
20
|
+
*/
|
|
21
|
+
getCommandString(): string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 解析后的命令参数
|
|
25
|
+
*/
|
|
26
|
+
export interface ParsedCommand {
|
|
27
|
+
commandName: string;
|
|
28
|
+
options: Map<string, string | number | boolean>;
|
|
29
|
+
args: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 命令创建函数类型
|
|
33
|
+
*/
|
|
34
|
+
export type CommandCreator = (options: Map<string, string | number | boolean>, args: string[], description: string, commandString: string) => Command;
|
|
35
|
+
/**
|
|
36
|
+
* 命令注册项
|
|
37
|
+
*/
|
|
38
|
+
export interface CommandRegistration<R extends CommandReceiver> {
|
|
39
|
+
receiver: R;
|
|
40
|
+
description: string;
|
|
18
41
|
}
|
|
19
42
|
/**
|
|
20
43
|
* 命令历史记录项
|
|
@@ -28,6 +51,12 @@ export interface CommandHistoryItem {
|
|
|
28
51
|
* 定义命令接收者的标准接口
|
|
29
52
|
*/
|
|
30
53
|
export interface CommandReceiver {
|
|
54
|
+
/** 命名名称 */
|
|
55
|
+
name: string;
|
|
56
|
+
/** 命令描述 */
|
|
57
|
+
description: string;
|
|
58
|
+
/** 创建器 */
|
|
59
|
+
creator?: CommandCreator;
|
|
31
60
|
/**
|
|
32
61
|
* 执行命令操作
|
|
33
62
|
* @param args 命令参数
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParsedCommand } from './Command';
|
|
2
|
+
/**
|
|
3
|
+
* 命令解析器
|
|
4
|
+
*/
|
|
5
|
+
export declare class CommandParser {
|
|
6
|
+
/**
|
|
7
|
+
* 解析命令字符串
|
|
8
|
+
* @param commandString 命令字符串,如 "add -a 10 -b 5"
|
|
9
|
+
* @returns ParsedCommand 对象
|
|
10
|
+
*/
|
|
11
|
+
parse(commandString: string): ParsedCommand;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CommandRegistration, CommandReceiver } from './Command';
|
|
2
|
+
/**
|
|
3
|
+
* 命令注册器
|
|
4
|
+
*/
|
|
5
|
+
export declare class CommandRegistry<R extends CommandReceiver> {
|
|
6
|
+
/** 命令注册映射 */
|
|
7
|
+
private commands;
|
|
8
|
+
/**
|
|
9
|
+
* 注册命令
|
|
10
|
+
* @param name 命令名
|
|
11
|
+
* @param receiver 命令接收者
|
|
12
|
+
* @param creator 命令创建函数
|
|
13
|
+
* @param description 命令描述
|
|
14
|
+
*/
|
|
15
|
+
register(name: string, receiver: R, description: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* 获取命令注册信息
|
|
18
|
+
*/
|
|
19
|
+
get(name: string): CommandRegistration<R> | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* 列出所有已注册的命令
|
|
22
|
+
*/
|
|
23
|
+
listCommands(): Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
@@ -4,20 +4,43 @@ export declare class CommandSystem {
|
|
|
4
4
|
* 命令调用者
|
|
5
5
|
*/
|
|
6
6
|
private invoker;
|
|
7
|
+
/**
|
|
8
|
+
* 命令解析器
|
|
9
|
+
*/
|
|
10
|
+
private parser;
|
|
11
|
+
/**
|
|
12
|
+
* 命令注册器
|
|
13
|
+
*/
|
|
14
|
+
private registry;
|
|
15
|
+
/**
|
|
16
|
+
* 注册命令
|
|
17
|
+
* @param name 命令名称
|
|
18
|
+
* @param receiver 命令接收者
|
|
19
|
+
*/
|
|
20
|
+
register<R extends CommandReceiver>(receiver: R): void;
|
|
7
21
|
/**
|
|
8
22
|
* 创建命令
|
|
9
23
|
* @param receiver 命令接收者
|
|
10
24
|
* @param executeFn 执行操作的函数
|
|
11
25
|
* @param undoFn 撤销操作的函数
|
|
12
26
|
* @param description 命令描述
|
|
27
|
+
* @param commandString 原始命令字符串
|
|
13
28
|
* @returns 命令对象
|
|
14
29
|
*/
|
|
15
|
-
create<R extends CommandReceiver>(receiver: R, executeFn: (receiver: R) => void, undoFn: (receiver: R) => void, description: string): Command;
|
|
30
|
+
create<R extends CommandReceiver>(receiver: R, executeFn: (receiver: R) => void, undoFn: (receiver: R) => void, description: string, commandString?: string): Command;
|
|
31
|
+
/**
|
|
32
|
+
* 从命令字符串创建 Command
|
|
33
|
+
* @param commandString 命令字符串
|
|
34
|
+
* @param description 针对本次命令描述
|
|
35
|
+
* @returns Command 实例,失败返回 undefined
|
|
36
|
+
*/
|
|
37
|
+
createFromCommandString(commandString: string, description?: string): Command | undefined;
|
|
16
38
|
/**
|
|
17
39
|
* 执行命令
|
|
18
40
|
* @param command 要执行的命令
|
|
41
|
+
* @param description 针对本次命令描述
|
|
19
42
|
*/
|
|
20
|
-
execute(command: Command): void;
|
|
43
|
+
execute(command: Command | string, description?: string): void;
|
|
21
44
|
/**
|
|
22
45
|
* 撤销上一个命令
|
|
23
46
|
* @returns 是否成功撤销
|
|
@@ -57,6 +80,13 @@ export declare class CommandSystem {
|
|
|
57
80
|
* @returns 撤销历史记录数量
|
|
58
81
|
*/
|
|
59
82
|
getUndoHistoryCount(): number;
|
|
83
|
+
/**
|
|
84
|
+
* 列出所有可用命令
|
|
85
|
+
*/
|
|
86
|
+
listCommands(): Array<{
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
}>;
|
|
60
90
|
/**
|
|
61
91
|
* 构造函数
|
|
62
92
|
* @param option 配置参数
|
|
@@ -16,14 +16,19 @@ export declare class ConcreteCommand<R extends CommandReceiver> implements Comma
|
|
|
16
16
|
* 命令描述
|
|
17
17
|
*/
|
|
18
18
|
private description;
|
|
19
|
+
/**
|
|
20
|
+
* 原始命令字符串
|
|
21
|
+
*/
|
|
22
|
+
private commandString;
|
|
19
23
|
/**
|
|
20
24
|
* 构造函数
|
|
21
25
|
* @param receiver 命令接收者
|
|
22
26
|
* @param executeFn 执行操作的函数
|
|
23
27
|
* @param undoFn 撤销操作的函数
|
|
24
28
|
* @param description 命令描述
|
|
29
|
+
* @param commandString 原始命令字符串
|
|
25
30
|
*/
|
|
26
|
-
constructor(receiver: R, executeFn: (receiver: R) => void, undoFn: (receiver: R) => void, description: string);
|
|
31
|
+
constructor(receiver: R, executeFn: (receiver: R) => void, undoFn: (receiver: R) => void, description: string, commandString?: string);
|
|
27
32
|
/**
|
|
28
33
|
* 执行命令
|
|
29
34
|
*/
|
|
@@ -37,6 +42,11 @@ export declare class ConcreteCommand<R extends CommandReceiver> implements Comma
|
|
|
37
42
|
* @returns 命令描述
|
|
38
43
|
*/
|
|
39
44
|
getDescription(): string;
|
|
45
|
+
/**
|
|
46
|
+
* 获取原始命令字符串
|
|
47
|
+
* @returns 命令字符串
|
|
48
|
+
*/
|
|
49
|
+
getCommandString(): string;
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
* 创建命令的工厂函数
|
|
@@ -44,6 +54,7 @@ export declare class ConcreteCommand<R extends CommandReceiver> implements Comma
|
|
|
44
54
|
* @param executeFn 执行操作的函数
|
|
45
55
|
* @param undoFn 撤销操作的函数
|
|
46
56
|
* @param description 命令描述
|
|
57
|
+
* @param commandString 原始命令字符串
|
|
47
58
|
* @returns 命令对象
|
|
48
59
|
*/
|
|
49
|
-
export declare function createCommand<R extends CommandReceiver>(receiver: R, executeFn: (receiver: R) => void, undoFn: (receiver: R) => void, description: string): Command;
|
|
60
|
+
export declare function createCommand<R extends CommandReceiver>(receiver: R, executeFn: (receiver: R) => void, undoFn: (receiver: R) => void, description: string, commandString?: string): Command;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
export { CommandInvoker } from './CommandInvoker';
|
|
5
5
|
export { CommandSystem } from './CommandSystem';
|
|
6
6
|
export { ConcreteCommand, createCommand } from './ConcreteCommand';
|
|
7
|
-
export type
|
|
7
|
+
export type * from './Command';
|
package/dist/src/type.d.ts
CHANGED
|
@@ -34,11 +34,11 @@ export interface IDomainRegisterOption<D extends Domain> {
|
|
|
34
34
|
args?: any[];
|
|
35
35
|
/** token 为领域名称的 before resolve拦截函数 */
|
|
36
36
|
beforeResolution?: (token: InjectionToken, resolutionType: string) => void;
|
|
37
|
-
/**
|
|
37
|
+
/** before resolve 拦截器触发评率 */
|
|
38
38
|
beforeResolutionFrequency?: 'Always' | 'Once';
|
|
39
39
|
/** token 为领域名称的 after resolve拦截函数 */
|
|
40
40
|
afterResolution?: (token: InjectionToken, result: D | D[], resolutionType: string) => void;
|
|
41
|
-
/**
|
|
41
|
+
/** after resolve 拦截器触发评率 */
|
|
42
42
|
afterResolutionFrequency?: 'Always' | 'Once';
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -49,8 +49,12 @@ export interface IRegisterEntityOption<E extends DomainEntity> {
|
|
|
49
49
|
cachePolicy?: 'cache' | 'containerCache' | 'resolution';
|
|
50
50
|
/** before 拦截器函数 */
|
|
51
51
|
beforeResolution?: (token: InjectionToken, resolutionType: string) => void;
|
|
52
|
+
/** before 拦截器触发评率 */
|
|
53
|
+
beforeResolutionFrequency?: 'Always' | 'Once';
|
|
52
54
|
/** after 拦截器函数 */
|
|
53
55
|
afterResolution?: (token: InjectionToken, result: E | E[], resolutionType: string) => void;
|
|
56
|
+
/** after 拦截器触发评率 */
|
|
57
|
+
afterResolutionFrequency?: 'Always' | 'Once';
|
|
54
58
|
}
|
|
55
59
|
/** 值对象注册配置类型 - 全局缓存缓存 */
|
|
56
60
|
export interface IRegisterVoOptionCache<V extends VO<any> = any> {
|