@pisell/pisellos 1.0.142 → 1.0.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/model/strategy/adapter/index.d.ts +4 -0
  2. package/dist/model/strategy/adapter/index.js +4 -1
  3. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  4. package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
  5. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  6. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  7. package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  8. package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
  9. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  10. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  11. package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
  12. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  13. package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  14. package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
  15. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  16. package/dist/model/strategy/adapter/promotion/evaluator.js +1279 -0
  17. package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
  18. package/dist/model/strategy/adapter/promotion/examples.js +166 -0
  19. package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
  20. package/dist/model/strategy/adapter/promotion/index.js +0 -0
  21. package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
  22. package/dist/model/strategy/adapter/promotion/type.js +209 -0
  23. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  24. package/dist/model/strategy/adapter/walletPass/evaluator.js +67 -10
  25. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  26. package/dist/model/strategy/adapter/walletPass/type.d.ts +20 -2
  27. package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  28. package/dist/model/strategy/adapter/walletPass/utils.js +143 -103
  29. package/dist/model/strategy/engine.d.ts +119 -0
  30. package/dist/model/strategy/engine.js +711 -0
  31. package/dist/model/strategy/index.d.ts +2 -93
  32. package/dist/model/strategy/index.js +6 -549
  33. package/dist/model/strategy/type.d.ts +17 -0
  34. package/dist/model/strategy/type.js +4 -0
  35. package/dist/solution/BookingByStep/index.d.ts +1 -1
  36. package/dist/solution/BookingTicket/index.d.ts +1 -1
  37. package/lib/model/strategy/adapter/index.d.ts +4 -0
  38. package/lib/model/strategy/adapter/index.js +12 -0
  39. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  40. package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
  41. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  42. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  43. package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  44. package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
  45. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  46. package/lib/model/strategy/adapter/itemRule/index.js +60 -0
  47. package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
  48. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  49. package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  50. package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
  51. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  52. package/lib/model/strategy/adapter/promotion/evaluator.js +893 -0
  53. package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
  54. package/lib/model/strategy/adapter/promotion/examples.js +192 -0
  55. package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
  56. package/lib/model/strategy/adapter/promotion/index.js +0 -0
  57. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  58. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.js +38 -5
  61. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  62. package/lib/model/strategy/adapter/walletPass/type.d.ts +20 -2
  63. package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  64. package/lib/model/strategy/adapter/walletPass/utils.js +153 -82
  65. package/lib/model/strategy/engine.d.ts +119 -0
  66. package/lib/model/strategy/engine.js +514 -0
  67. package/lib/model/strategy/index.d.ts +2 -93
  68. package/lib/model/strategy/index.js +6 -381
  69. package/lib/model/strategy/type.d.ts +17 -0
  70. package/lib/solution/BookingByStep/index.d.ts +1 -1
  71. package/lib/solution/BookingTicket/index.d.ts +1 -1
  72. package/package.json +1 -1
@@ -0,0 +1,514 @@
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/model/strategy/engine.ts
20
+ var engine_exports = {};
21
+ __export(engine_exports, {
22
+ StrategyEngine: () => StrategyEngine,
23
+ createStrategyEngine: () => createStrategyEngine,
24
+ evaluate: () => evaluate
25
+ });
26
+ module.exports = __toCommonJS(engine_exports);
27
+ var import_type = require("./type");
28
+ var StrategyEngine = class {
29
+ constructor(options = {}) {
30
+ this.options = {
31
+ debug: options.debug ?? false,
32
+ enableTrace: options.enableTrace ?? false,
33
+ operatorHandlers: options.operatorHandlers ?? {},
34
+ errorHandler: options.errorHandler ?? ((error) => console.error(error))
35
+ };
36
+ this.operatorHandlers = new Map(
37
+ Object.entries(this.options.operatorHandlers)
38
+ );
39
+ this.initializeBuiltInOperators();
40
+ }
41
+ /**
42
+ * 评估策略
43
+ */
44
+ evaluate(config, context) {
45
+ var _a, _b;
46
+ const startTime = Date.now();
47
+ const trace = {
48
+ steps: [],
49
+ duration: 0,
50
+ errors: []
51
+ };
52
+ try {
53
+ this.validateConfig(config);
54
+ if (this.options.enableTrace) {
55
+ trace.steps.push({
56
+ step: "validate_config",
57
+ status: "success",
58
+ duration: Date.now() - startTime
59
+ });
60
+ }
61
+ const evaluateStart = Date.now();
62
+ const evaluationResult = this.evaluateConditionGroup(
63
+ config.conditions,
64
+ context
65
+ );
66
+ if (this.options.enableTrace) {
67
+ trace.steps.push({
68
+ step: "evaluate_conditions",
69
+ status: "success",
70
+ duration: Date.now() - evaluateStart,
71
+ details: {
72
+ satisfied: evaluationResult.satisfied,
73
+ collectedActionIds: evaluationResult.actionIds
74
+ }
75
+ });
76
+ }
77
+ const actionStart = Date.now();
78
+ const matchedActions = this.getActionsByIds(
79
+ evaluationResult.actionIds,
80
+ config.actions
81
+ );
82
+ if (this.options.enableTrace) {
83
+ trace.steps.push({
84
+ step: "get_actions",
85
+ status: "success",
86
+ duration: Date.now() - actionStart,
87
+ details: { matchedCount: matchedActions.length }
88
+ });
89
+ }
90
+ const sortStart = Date.now();
91
+ const sortedActions = this.sortActionsByPriority(matchedActions);
92
+ if (this.options.enableTrace) {
93
+ trace.steps.push({
94
+ step: "sort_actions",
95
+ status: "success",
96
+ duration: Date.now() - sortStart
97
+ });
98
+ }
99
+ const applicable = evaluationResult.satisfied;
100
+ const result = {
101
+ success: true,
102
+ applicable,
103
+ code: applicable ? import_type.SUCCESS_CODES.SUCCESS : import_type.NOT_APPLICABLE_CODES.CONDITION_NOT_MET,
104
+ message: applicable ? "Strategy is applicable" : "Conditions not met",
105
+ matched: {
106
+ conditions: applicable,
107
+ actionIds: evaluationResult.actionIds,
108
+ details: {},
109
+ ...applicable ? {} : {
110
+ failedField: (_a = evaluationResult.failedRules[0]) == null ? void 0 : _a.field,
111
+ failedRules: evaluationResult.failedRules
112
+ }
113
+ },
114
+ matchedActions: sortedActions,
115
+ outputs: {},
116
+ config
117
+ };
118
+ trace.duration = Date.now() - startTime;
119
+ if (this.options.enableTrace) {
120
+ result.trace = trace;
121
+ }
122
+ return result;
123
+ } catch (error) {
124
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
125
+ if (this.options.enableTrace) {
126
+ (_b = trace.errors) == null ? void 0 : _b.push({
127
+ step: "evaluation",
128
+ error: errorMessage,
129
+ timestamp: Date.now()
130
+ });
131
+ trace.duration = Date.now() - startTime;
132
+ }
133
+ this.options.errorHandler(error, context);
134
+ return {
135
+ success: false,
136
+ applicable: false,
137
+ code: import_type.ERROR_CODES.EVALUATION_ERROR,
138
+ message: errorMessage,
139
+ matched: {
140
+ conditions: false,
141
+ actionIds: [],
142
+ details: {}
143
+ },
144
+ matchedActions: [],
145
+ outputs: {},
146
+ trace: this.options.enableTrace ? trace : void 0,
147
+ config
148
+ };
149
+ }
150
+ }
151
+ /**
152
+ * 递归评估条件组
153
+ *
154
+ * @param group 条件组
155
+ * @param context 运行时上下文
156
+ * @returns 评估结果对象,包含条件是否满足、收集到的 actionIds、以及失败的原子规则信息
157
+ */
158
+ evaluateConditionGroup(group, context) {
159
+ const collectedActionIds = [];
160
+ const { satisfied, failedRules } = this.evaluateGroupLogicDetailed(
161
+ group,
162
+ context
163
+ );
164
+ if (satisfied) {
165
+ collectedActionIds.push(...group.actionIds);
166
+ for (const rule of group.rules) {
167
+ if (this.isConditionGroup(rule)) {
168
+ const nestedResult = this.evaluateConditionGroup(rule, context);
169
+ collectedActionIds.push(...nestedResult.actionIds);
170
+ }
171
+ }
172
+ }
173
+ return {
174
+ satisfied,
175
+ actionIds: collectedActionIds,
176
+ failedRules
177
+ };
178
+ }
179
+ /**
180
+ * 评估条件组的逻辑运算(带失败规则收集)
181
+ *
182
+ * 失败规则收集策略:
183
+ * - `and`:返回第一个失败的原子规则(嵌套 group 递归取其首个失败原子规则)
184
+ * - `or`:所有分支失败时,聚合每个分支的失败规则
185
+ * - `not`:被取反规则实际通过时,记录该规则
186
+ */
187
+ evaluateGroupLogicDetailed(group, context) {
188
+ const { operator, rules } = group;
189
+ switch (operator) {
190
+ case "and": {
191
+ for (const rule of rules) {
192
+ const ruleResult = this.evaluateRuleDetailed(rule, context);
193
+ if (!ruleResult.satisfied) {
194
+ return {
195
+ satisfied: false,
196
+ failedRules: ruleResult.failedRules
197
+ };
198
+ }
199
+ }
200
+ return { satisfied: true, failedRules: [] };
201
+ }
202
+ case "or": {
203
+ const aggregated = [];
204
+ for (const rule of rules) {
205
+ const ruleResult = this.evaluateRuleDetailed(rule, context);
206
+ if (ruleResult.satisfied) {
207
+ return { satisfied: true, failedRules: [] };
208
+ }
209
+ aggregated.push(...ruleResult.failedRules);
210
+ }
211
+ return { satisfied: false, failedRules: aggregated };
212
+ }
213
+ case "not": {
214
+ if (rules.length === 0) {
215
+ return { satisfied: false, failedRules: [] };
216
+ }
217
+ const ruleResult = this.evaluateRuleDetailed(rules[0], context);
218
+ if (ruleResult.satisfied) {
219
+ const failed = this.isConditionGroup(rules[0]) ? [] : [this.buildFailedRuleInfo(rules[0], context)];
220
+ return { satisfied: false, failedRules: failed };
221
+ }
222
+ return { satisfied: true, failedRules: [] };
223
+ }
224
+ default:
225
+ throw new Error(`Unknown operator: ${operator}`);
226
+ }
227
+ }
228
+ /**
229
+ * 评估单个规则(带失败规则收集)
230
+ */
231
+ evaluateRuleDetailed(rule, context) {
232
+ if (this.isConditionGroup(rule)) {
233
+ return this.evaluateGroupLogicDetailed(rule, context);
234
+ }
235
+ const conditionRule = rule;
236
+ const satisfied = this.evaluateAtomicRule(conditionRule, context);
237
+ if (satisfied) {
238
+ return { satisfied: true, failedRules: [] };
239
+ }
240
+ return {
241
+ satisfied: false,
242
+ failedRules: [this.buildFailedRuleInfo(conditionRule, context)]
243
+ };
244
+ }
245
+ /**
246
+ * 评估原子规则(不收集失败信息,仅返回布尔结果)
247
+ */
248
+ evaluateAtomicRule(conditionRule, context) {
249
+ if (conditionRule.type === "code" && conditionRule.code) {
250
+ return this.evaluateCodeCondition(conditionRule.code, context);
251
+ }
252
+ return this.evaluateOperatorCondition(conditionRule, context);
253
+ }
254
+ /**
255
+ * 构建失败规则信息
256
+ */
257
+ buildFailedRuleInfo(conditionRule, context) {
258
+ const actualValue = conditionRule.field ? this.getFieldValue(conditionRule.field, context) : void 0;
259
+ return {
260
+ field: conditionRule.field,
261
+ operator: conditionRule.operator,
262
+ value: conditionRule.value,
263
+ actualValue
264
+ };
265
+ }
266
+ /**
267
+ * 评估代码模式条件
268
+ */
269
+ evaluateCodeCondition(code, context) {
270
+ try {
271
+ const { entities, attributes, metadata } = context;
272
+ const evalFunc = new Function(
273
+ "entities",
274
+ "attributes",
275
+ "metadata",
276
+ `return (${code})`
277
+ );
278
+ const result = evalFunc(entities, attributes, metadata);
279
+ return Boolean(result);
280
+ } catch (error) {
281
+ if (this.options.debug) {
282
+ console.error("Code evaluation error:", error);
283
+ }
284
+ return false;
285
+ }
286
+ }
287
+ /**
288
+ * 评估运算符模式条件
289
+ */
290
+ evaluateOperatorCondition(rule, context) {
291
+ const { field, operator, value } = rule;
292
+ if (!field || !operator) {
293
+ return false;
294
+ }
295
+ const fieldValue = this.getFieldValue(field, context);
296
+ const handler = this.operatorHandlers.get(operator);
297
+ if (handler) {
298
+ return handler(fieldValue, value, rule);
299
+ }
300
+ return this.evaluateBuiltInOperator(fieldValue, operator, value);
301
+ }
302
+ /**
303
+ * 获取字段值
304
+ */
305
+ getFieldValue(field, context) {
306
+ const path = field.split(".");
307
+ let value = context.attributes;
308
+ for (const key of path) {
309
+ if (value && typeof value === "object" && key in value) {
310
+ value = value[key];
311
+ } else {
312
+ return void 0;
313
+ }
314
+ }
315
+ return value;
316
+ }
317
+ /**
318
+ * 评估内置运算符
319
+ */
320
+ evaluateBuiltInOperator(fieldValue, operator, compareValue) {
321
+ switch (operator) {
322
+ case "=":
323
+ case "==":
324
+ return fieldValue == compareValue;
325
+ case "!=":
326
+ return fieldValue != compareValue;
327
+ case ">":
328
+ return fieldValue > compareValue;
329
+ case ">=":
330
+ return fieldValue >= compareValue;
331
+ case "<":
332
+ return fieldValue < compareValue;
333
+ case "<=":
334
+ return fieldValue <= compareValue;
335
+ case "in":
336
+ return Array.isArray(compareValue) && compareValue.includes(fieldValue);
337
+ case "not_in":
338
+ return Array.isArray(compareValue) && !compareValue.includes(fieldValue);
339
+ case "contains":
340
+ if (Array.isArray(fieldValue)) {
341
+ return fieldValue.includes(compareValue);
342
+ }
343
+ if (typeof fieldValue === "string") {
344
+ return fieldValue.includes(compareValue);
345
+ }
346
+ return false;
347
+ case "not_contains":
348
+ if (Array.isArray(fieldValue)) {
349
+ return !fieldValue.includes(compareValue);
350
+ }
351
+ if (typeof fieldValue === "string") {
352
+ return !fieldValue.includes(compareValue);
353
+ }
354
+ return true;
355
+ case "starts_with":
356
+ return typeof fieldValue === "string" && fieldValue.startsWith(compareValue);
357
+ case "ends_with":
358
+ return typeof fieldValue === "string" && fieldValue.endsWith(compareValue);
359
+ case "regex":
360
+ return typeof fieldValue === "string" && new RegExp(compareValue).test(fieldValue);
361
+ case "between":
362
+ if (!Array.isArray(compareValue) || compareValue.length !== 2)
363
+ return false;
364
+ return fieldValue >= compareValue[0] && fieldValue <= compareValue[1];
365
+ case "is_null":
366
+ return fieldValue === null || fieldValue === void 0;
367
+ case "is_not_null":
368
+ return fieldValue !== null && fieldValue !== void 0;
369
+ case "is_empty":
370
+ if (Array.isArray(fieldValue))
371
+ return fieldValue.length === 0;
372
+ if (typeof fieldValue === "string")
373
+ return fieldValue.length === 0;
374
+ if (typeof fieldValue === "object")
375
+ return Object.keys(fieldValue).length === 0;
376
+ return !fieldValue;
377
+ case "is_not_empty":
378
+ if (Array.isArray(fieldValue))
379
+ return fieldValue.length > 0;
380
+ if (typeof fieldValue === "string")
381
+ return fieldValue.length > 0;
382
+ if (typeof fieldValue === "object")
383
+ return Object.keys(fieldValue).length > 0;
384
+ return Boolean(fieldValue);
385
+ case "product_match":
386
+ return this.evaluateProductMatch(fieldValue, compareValue);
387
+ case "object_in":
388
+ return this.evaluateProductMatch(fieldValue, compareValue);
389
+ default:
390
+ throw new Error(`Unsupported operator: ${operator}`);
391
+ }
392
+ }
393
+ /**
394
+ * 根据 actionIds 获取 ActionEffect 对象
395
+ */
396
+ getActionsByIds(actionIds, actions) {
397
+ const matchedActions = [];
398
+ const actionMap = new Map(actions.map((action) => [action.id, action]));
399
+ for (const id of actionIds) {
400
+ const action = actionMap.get(id);
401
+ if (action) {
402
+ matchedActions.push(action);
403
+ } else {
404
+ if (this.options.debug) {
405
+ console.warn(`Action with id "${id}" not found in actions array`);
406
+ }
407
+ }
408
+ }
409
+ return matchedActions;
410
+ }
411
+ /**
412
+ * 按 priority 排序(降序)
413
+ */
414
+ sortActionsByPriority(actions) {
415
+ return [...actions].sort((a, b) => {
416
+ const priorityA = a.priority ?? 0;
417
+ const priorityB = b.priority ?? 0;
418
+ return priorityB - priorityA;
419
+ });
420
+ }
421
+ /**
422
+ * 判断是否为条件组
423
+ */
424
+ isConditionGroup(rule) {
425
+ return "operator" in rule && "rules" in rule && Array.isArray(rule.rules);
426
+ }
427
+ /**
428
+ * 验证配置
429
+ */
430
+ validateConfig(config) {
431
+ if (!config) {
432
+ throw new Error("Strategy config is required");
433
+ }
434
+ if (!config.metadata || !config.metadata.id) {
435
+ throw new Error("Strategy metadata.id is required");
436
+ }
437
+ if (!config.conditions) {
438
+ throw new Error("Strategy conditions is required");
439
+ }
440
+ if (!Array.isArray(config.actions)) {
441
+ throw new Error("Strategy actions must be an array");
442
+ }
443
+ }
444
+ /**
445
+ * 初始化内置运算符处理器
446
+ */
447
+ initializeBuiltInOperators() {
448
+ }
449
+ /**
450
+ * 评估商品匹配运算符
451
+ *
452
+ * 匹配规则:
453
+ * - 首先匹配 product_id
454
+ * - 如果配置的 product_variant_id = 0,只需要 product_id 匹配(表示任意变体)
455
+ * - 如果配置的 product_variant_id != 0,还需要 product_variant_id 精确匹配
456
+ *
457
+ * @param fieldValue 实际商品 { product_id: number, product_variant_id: number }
458
+ * @param configValue 配置的商品列表 Array<{ product_id: number, product_variant_id: number }>
459
+ * @returns 是否匹配
460
+ */
461
+ evaluateProductMatch(fieldValue, configValue) {
462
+ if (!Array.isArray(configValue)) {
463
+ return false;
464
+ }
465
+ if (!fieldValue || typeof fieldValue !== "object" || typeof fieldValue.product_id !== "number") {
466
+ return false;
467
+ }
468
+ const actualProductId = fieldValue.product_id;
469
+ const actualVariantId = fieldValue.product_variant_id ?? 0;
470
+ return configValue.some((item) => {
471
+ if (!item || typeof item.product_id !== "number") {
472
+ return false;
473
+ }
474
+ const configProductId = item.product_id;
475
+ const configVariantId = item.product_variant_id ?? 0;
476
+ if (configProductId !== actualProductId) {
477
+ return false;
478
+ }
479
+ if (configVariantId === 0) {
480
+ return true;
481
+ }
482
+ return configVariantId === actualVariantId;
483
+ });
484
+ }
485
+ /**
486
+ * 注册自定义运算符
487
+ */
488
+ registerOperator(operator, handler) {
489
+ this.operatorHandlers.set(operator, handler);
490
+ }
491
+ /**
492
+ * 获取调试信息
493
+ */
494
+ getDebugInfo() {
495
+ return {
496
+ debug: this.options.debug,
497
+ enableTrace: this.options.enableTrace,
498
+ registeredOperators: Array.from(this.operatorHandlers.keys())
499
+ };
500
+ }
501
+ };
502
+ function createStrategyEngine(options) {
503
+ return new StrategyEngine(options);
504
+ }
505
+ function evaluate(config, context) {
506
+ const engine = new StrategyEngine();
507
+ return engine.evaluate(config, context);
508
+ }
509
+ // Annotate the CommonJS export names for ESM import in node:
510
+ 0 && (module.exports = {
511
+ StrategyEngine,
512
+ createStrategyEngine,
513
+ evaluate
514
+ });
@@ -1,94 +1,3 @@
1
- import { StrategyConfig, RuntimeContext, EvaluationResult, EngineOptions, OperatorHandler } from './type';
2
- /**
3
- * 策略模型 - 核心实现
4
- *
5
- * 完全业务无关的通用策略引擎
6
- * 支持条件评估、动作匹配、结果返回
7
- */
8
- /**
9
- * 策略引擎
10
- *
11
- * 核心职责:
12
- * 1. 递归评估条件组
13
- * 2. 收集满足条件的 actionIds
14
- * 3. 根据 actionIds 获取 ActionEffect 对象
15
- * 4. 按 priority 排序返回
16
- */
17
- export declare class StrategyEngine {
18
- private options;
19
- private operatorHandlers;
20
- constructor(options?: EngineOptions);
21
- /**
22
- * 评估策略
23
- */
24
- evaluate(config: StrategyConfig, context: RuntimeContext): EvaluationResult;
25
- /**
26
- * 递归评估条件组
27
- *
28
- * @param group 条件组
29
- * @param context 运行时上下文
30
- * @returns 评估结果对象,包含条件是否满足和收集到的 actionIds
31
- */
32
- private evaluateConditionGroup;
33
- /**
34
- * 评估条件组的逻辑运算
35
- */
36
- private evaluateGroupLogic;
37
- /**
38
- * 评估单个规则
39
- */
40
- private evaluateRule;
41
- /**
42
- * 评估代码模式条件
43
- */
44
- private evaluateCodeCondition;
45
- /**
46
- * 评估运算符模式条件
47
- */
48
- private evaluateOperatorCondition;
49
- /**
50
- * 获取字段值
51
- */
52
- private getFieldValue;
53
- /**
54
- * 评估内置运算符
55
- */
56
- private evaluateBuiltInOperator;
57
- /**
58
- * 根据 actionIds 获取 ActionEffect 对象
59
- */
60
- private getActionsByIds;
61
- /**
62
- * 按 priority 排序(降序)
63
- */
64
- private sortActionsByPriority;
65
- /**
66
- * 判断是否为条件组
67
- */
68
- private isConditionGroup;
69
- /**
70
- * 验证配置
71
- */
72
- private validateConfig;
73
- /**
74
- * 初始化内置运算符处理器
75
- */
76
- private initializeBuiltInOperators;
77
- /**
78
- * 注册自定义运算符
79
- */
80
- registerOperator(operator: string, handler: OperatorHandler): void;
81
- /**
82
- * 获取调试信息
83
- */
84
- getDebugInfo(): Record<string, any>;
85
- }
1
+ export { StrategyEngine, createStrategyEngine, evaluate } from './engine';
2
+ export * from './type';
86
3
  export * from './adapter';
87
- /**
88
- * 创建策略引擎实例
89
- */
90
- export declare function createStrategyEngine(options?: EngineOptions): StrategyEngine;
91
- /**
92
- * 快速评估(使用默认引擎配置)
93
- */
94
- export declare function evaluate(config: StrategyConfig, context: RuntimeContext): EvaluationResult;