universal-agent-memory 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -20
- package/dist/cli/memory.js +27 -0
- package/dist/cli/memory.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +2 -2
- package/dist/cli/update.js.map +1 -1
- package/dist/memory/adaptive-context.d.ts +100 -0
- package/dist/memory/adaptive-context.d.ts.map +1 -0
- package/dist/memory/adaptive-context.js +456 -0
- package/dist/memory/adaptive-context.js.map +1 -0
- package/dist/utils/calculate-average.d.ts +15 -0
- package/dist/utils/calculate-average.d.ts.map +1 -0
- package/dist/utils/calculate-average.js +21 -0
- package/dist/utils/calculate-average.js.map +1 -0
- package/dist/utils/config-manager.d.ts +30 -0
- package/dist/utils/config-manager.d.ts.map +1 -0
- package/dist/utils/config-manager.js +41 -0
- package/dist/utils/config-manager.js.map +1 -0
- package/dist/utils/fetch-with-retry.d.ts +5 -0
- package/dist/utils/fetch-with-retry.d.ts.map +1 -0
- package/dist/utils/fetch-with-retry.js +61 -0
- package/dist/utils/fetch-with-retry.js.map +1 -0
- package/dist/utils/order-processor-refactored.d.ts +126 -0
- package/dist/utils/order-processor-refactored.d.ts.map +1 -0
- package/dist/utils/order-processor-refactored.js +165 -0
- package/dist/utils/order-processor-refactored.js.map +1 -0
- package/dist/utils/order-processor-strategy.d.ts +72 -0
- package/dist/utils/order-processor-strategy.d.ts.map +1 -0
- package/dist/utils/order-processor-strategy.js +158 -0
- package/dist/utils/order-processor-strategy.js.map +1 -0
- package/dist/utils/order-processor.d.ts +242 -0
- package/dist/utils/order-processor.d.ts.map +1 -0
- package/dist/utils/order-processor.js +370 -0
- package/dist/utils/order-processor.js.map +1 -0
- package/dist/utils/rate-limiter-simple.d.ts +58 -0
- package/dist/utils/rate-limiter-simple.d.ts.map +1 -0
- package/dist/utils/rate-limiter-simple.js +100 -0
- package/dist/utils/rate-limiter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UAAU,CAAC;QACnB,CAAC;IACH,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,KAAK,CAC9B,OAAO,MAAM,CAAC,UAAU,GAAG,CAAC,wBAAwB,GAAG,EAAE,CAM1D,CAAC;IACF,cAAc,CAAC,IAAI,GAAG,iBAAiB,CAAC;IACxC,cAAc,CAAC,GAAG,GAAG,GAAG,CAAC;IACzB,cAAc,CAAC,QAAQ,GAAG,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC;IAChD,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC;IAC3C,cAAc,CAAC,SAAS,GAAG,SAAS,CAAC;IACrC,MAAM,cAAc,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Processing - Refactored using SOLID Principles
|
|
3
|
+
*
|
|
4
|
+
* This implementation follows:
|
|
5
|
+
* - Single Responsibility Principle: Each strategy handles one order type
|
|
6
|
+
* - Open/Closed Principle: New order types can be added without modifying existing code
|
|
7
|
+
* - Liskov Substitution Principle: All strategies are interchangeable
|
|
8
|
+
* - Interface Segregation Principle: Focused interfaces for specific behaviors
|
|
9
|
+
* - Dependency Inversion Principle: High-level module depends on abstractions
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Represents the possible statuses an order can have
|
|
13
|
+
*/
|
|
14
|
+
export type OrderStatus = 'pending' | 'delivered' | 'shipped' | 'active' | 'cancelled';
|
|
15
|
+
/**
|
|
16
|
+
* Represents the supported order types
|
|
17
|
+
*/
|
|
18
|
+
export type OrderType = 'digital' | 'physical' | 'subscription';
|
|
19
|
+
/**
|
|
20
|
+
* Base order interface with common properties
|
|
21
|
+
*/
|
|
22
|
+
export interface Order {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly type: OrderType;
|
|
25
|
+
status: OrderStatus;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Digital order with download-specific properties
|
|
29
|
+
*/
|
|
30
|
+
export interface DigitalOrder extends Order {
|
|
31
|
+
readonly type: 'digital';
|
|
32
|
+
readonly downloadUrl?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Physical order with shipping-specific properties
|
|
36
|
+
*/
|
|
37
|
+
export interface PhysicalOrder extends Order {
|
|
38
|
+
readonly type: 'physical';
|
|
39
|
+
readonly shippingAddress?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Subscription order with subscription-specific properties
|
|
43
|
+
*/
|
|
44
|
+
export interface SubscriptionOrder extends Order {
|
|
45
|
+
readonly type: 'subscription';
|
|
46
|
+
readonly subscriptionPlan?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Union type for all order types
|
|
50
|
+
*/
|
|
51
|
+
export type AnyOrder = DigitalOrder | PhysicalOrder | SubscriptionOrder;
|
|
52
|
+
/**
|
|
53
|
+
* Result of processing an order
|
|
54
|
+
*/
|
|
55
|
+
export interface ProcessingResult {
|
|
56
|
+
readonly success: boolean;
|
|
57
|
+
readonly order: AnyOrder;
|
|
58
|
+
readonly message: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Logger interface for dependency injection
|
|
62
|
+
*/
|
|
63
|
+
export interface Logger {
|
|
64
|
+
log(message: string): void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Strategy interface for processing orders (Open/Closed Principle)
|
|
68
|
+
*/
|
|
69
|
+
export interface OrderProcessingStrategy {
|
|
70
|
+
/**
|
|
71
|
+
* Check if this strategy can handle the given order type
|
|
72
|
+
*/
|
|
73
|
+
canHandle(orderType: OrderType): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Process the order and return the result
|
|
76
|
+
*/
|
|
77
|
+
process(order: AnyOrder, logger: Logger): ProcessingResult;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Strategy for processing digital orders
|
|
81
|
+
*/
|
|
82
|
+
export declare class DigitalOrderStrategy implements OrderProcessingStrategy {
|
|
83
|
+
canHandle(orderType: OrderType): boolean;
|
|
84
|
+
process(order: AnyOrder, logger: Logger): ProcessingResult;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Strategy for processing physical orders
|
|
88
|
+
*/
|
|
89
|
+
export declare class PhysicalOrderStrategy implements OrderProcessingStrategy {
|
|
90
|
+
canHandle(orderType: OrderType): boolean;
|
|
91
|
+
process(order: AnyOrder, logger: Logger): ProcessingResult;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Strategy for processing subscription orders
|
|
95
|
+
*/
|
|
96
|
+
export declare class SubscriptionOrderStrategy implements OrderProcessingStrategy {
|
|
97
|
+
canHandle(orderType: OrderType): boolean;
|
|
98
|
+
process(order: AnyOrder, logger: Logger): ProcessingResult;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Console-based logger implementation
|
|
102
|
+
*/
|
|
103
|
+
export declare class ConsoleLogger implements Logger {
|
|
104
|
+
log(message: string): void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Main order processor that uses strategies to handle different order types
|
|
108
|
+
*/
|
|
109
|
+
export declare class OrderProcessor {
|
|
110
|
+
private readonly strategies;
|
|
111
|
+
private readonly logger;
|
|
112
|
+
constructor(strategies: OrderProcessingStrategy[], logger: Logger);
|
|
113
|
+
/**
|
|
114
|
+
* Process an order using the appropriate strategy
|
|
115
|
+
*/
|
|
116
|
+
processOrder(order: AnyOrder): ProcessingResult;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Factory function to create a fully configured OrderProcessor
|
|
120
|
+
*/
|
|
121
|
+
export declare function createOrderProcessor(logger?: Logger): OrderProcessor;
|
|
122
|
+
/**
|
|
123
|
+
* Example usage demonstrating the refactored code
|
|
124
|
+
*/
|
|
125
|
+
export declare function exampleUsage(): void;
|
|
126
|
+
//# sourceMappingURL=order-processor-refactored.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order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nC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Processing - Refactored using SOLID Principles
|
|
3
|
+
*
|
|
4
|
+
* This implementation follows:
|
|
5
|
+
* - Single Responsibility Principle: Each strategy handles one order type
|
|
6
|
+
* - Open/Closed Principle: New order types can be added without modifying existing code
|
|
7
|
+
* - Liskov Substitution Principle: All strategies are interchangeable
|
|
8
|
+
* - Interface Segregation Principle: Focused interfaces for specific behaviors
|
|
9
|
+
* - Dependency Inversion Principle: High-level module depends on abstractions
|
|
10
|
+
*/
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Strategy Implementations (Single Responsibility Principle)
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Strategy for processing digital orders
|
|
16
|
+
*/
|
|
17
|
+
export class DigitalOrderStrategy {
|
|
18
|
+
canHandle(orderType) {
|
|
19
|
+
return orderType === 'digital';
|
|
20
|
+
}
|
|
21
|
+
process(order, logger) {
|
|
22
|
+
logger.log('Sending email with download link');
|
|
23
|
+
const processedOrder = {
|
|
24
|
+
...order,
|
|
25
|
+
status: 'delivered',
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
order: processedOrder,
|
|
30
|
+
message: 'Digital order delivered via email',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Strategy for processing physical orders
|
|
36
|
+
*/
|
|
37
|
+
export class PhysicalOrderStrategy {
|
|
38
|
+
canHandle(orderType) {
|
|
39
|
+
return orderType === 'physical';
|
|
40
|
+
}
|
|
41
|
+
process(order, logger) {
|
|
42
|
+
logger.log('Creating shipping label');
|
|
43
|
+
const processedOrder = {
|
|
44
|
+
...order,
|
|
45
|
+
status: 'shipped',
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
success: true,
|
|
49
|
+
order: processedOrder,
|
|
50
|
+
message: 'Physical order shipped',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Strategy for processing subscription orders
|
|
56
|
+
*/
|
|
57
|
+
export class SubscriptionOrderStrategy {
|
|
58
|
+
canHandle(orderType) {
|
|
59
|
+
return orderType === 'subscription';
|
|
60
|
+
}
|
|
61
|
+
process(order, logger) {
|
|
62
|
+
logger.log('Activating subscription');
|
|
63
|
+
const processedOrder = {
|
|
64
|
+
...order,
|
|
65
|
+
status: 'active',
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
success: true,
|
|
69
|
+
order: processedOrder,
|
|
70
|
+
message: 'Subscription activated',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Default Logger Implementation
|
|
76
|
+
// ============================================================================
|
|
77
|
+
/**
|
|
78
|
+
* Console-based logger implementation
|
|
79
|
+
*/
|
|
80
|
+
export class ConsoleLogger {
|
|
81
|
+
log(message) {
|
|
82
|
+
console.log(message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// ============================================================================
|
|
86
|
+
// Order Processor (Dependency Inversion Principle)
|
|
87
|
+
// ============================================================================
|
|
88
|
+
/**
|
|
89
|
+
* Main order processor that uses strategies to handle different order types
|
|
90
|
+
*/
|
|
91
|
+
export class OrderProcessor {
|
|
92
|
+
strategies;
|
|
93
|
+
logger;
|
|
94
|
+
constructor(strategies, logger) {
|
|
95
|
+
this.strategies = strategies;
|
|
96
|
+
this.logger = logger;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Process an order using the appropriate strategy
|
|
100
|
+
*/
|
|
101
|
+
processOrder(order) {
|
|
102
|
+
const strategy = this.strategies.find((s) => s.canHandle(order.type));
|
|
103
|
+
if (!strategy) {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
order,
|
|
107
|
+
message: `No strategy found for order type: ${order.type}`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const result = strategy.process(order, this.logger);
|
|
111
|
+
this.logger.log(`Order processed: ${order.id}`);
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// ============================================================================
|
|
116
|
+
// Factory for Easy Setup
|
|
117
|
+
// ============================================================================
|
|
118
|
+
/**
|
|
119
|
+
* Factory function to create a fully configured OrderProcessor
|
|
120
|
+
*/
|
|
121
|
+
export function createOrderProcessor(logger) {
|
|
122
|
+
const strategies = [
|
|
123
|
+
new DigitalOrderStrategy(),
|
|
124
|
+
new PhysicalOrderStrategy(),
|
|
125
|
+
new SubscriptionOrderStrategy(),
|
|
126
|
+
];
|
|
127
|
+
return new OrderProcessor(strategies, logger ?? new ConsoleLogger());
|
|
128
|
+
}
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// Usage Example
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* Example usage demonstrating the refactored code
|
|
134
|
+
*/
|
|
135
|
+
export function exampleUsage() {
|
|
136
|
+
const processor = createOrderProcessor();
|
|
137
|
+
const digitalOrder = {
|
|
138
|
+
id: 'order-001',
|
|
139
|
+
type: 'digital',
|
|
140
|
+
status: 'pending',
|
|
141
|
+
downloadUrl: 'https://example.com/download/abc',
|
|
142
|
+
};
|
|
143
|
+
const physicalOrder = {
|
|
144
|
+
id: 'order-002',
|
|
145
|
+
type: 'physical',
|
|
146
|
+
status: 'pending',
|
|
147
|
+
shippingAddress: '123 Main St, City, Country',
|
|
148
|
+
};
|
|
149
|
+
const subscriptionOrder = {
|
|
150
|
+
id: 'order-003',
|
|
151
|
+
type: 'subscription',
|
|
152
|
+
status: 'pending',
|
|
153
|
+
subscriptionPlan: 'premium-monthly',
|
|
154
|
+
};
|
|
155
|
+
console.log('Processing digital order:');
|
|
156
|
+
const digitalResult = processor.processOrder(digitalOrder);
|
|
157
|
+
console.log('Result:', digitalResult);
|
|
158
|
+
console.log('\nProcessing physical order:');
|
|
159
|
+
const physicalResult = processor.processOrder(physicalOrder);
|
|
160
|
+
console.log('Result:', physicalResult);
|
|
161
|
+
console.log('\nProcessing subscription order:');
|
|
162
|
+
const subscriptionResult = processor.processOrder(subscriptionOrder);
|
|
163
|
+
console.log('Result:', subscriptionResult);
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=order-processor-refactored.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-processor-refactored.js","sourceRoot":"","sources":["../../src/utils/order-processor-refactored.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0FH,+EAA+E;AAC/E,6DAA6D;AAC7D,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAC/B,SAAS,CAAC,SAAoB;QAC5B,OAAO,SAAS,KAAK,SAAS,CAAC;IACjC,CAAC;IAED,OAAO,CAAC,KAAe,EAAE,MAAc;QACrC,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;QAC/C,MAAM,cAAc,GAAiB;YACnC,GAAI,KAAsB;YAC1B,MAAM,EAAE,WAAW;SACpB,CAAC;QACF,OAAO;YACL,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,cAAc;YACrB,OAAO,EAAE,mCAAmC;SAC7C,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAChC,SAAS,CAAC,SAAoB;QAC5B,OAAO,SAAS,KAAK,UAAU,CAAC;IAClC,CAAC;IAED,OAAO,CAAC,KAAe,EAAE,MAAc;QACrC,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QACtC,MAAM,cAAc,GAAkB;YACpC,GAAI,KAAuB;YAC3B,MAAM,EAAE,SAAS;SAClB,CAAC;QACF,OAAO;YACL,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,cAAc;YACrB,OAAO,EAAE,wBAAwB;SAClC,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACpC,SAAS,CAAC,SAA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;IAC7D,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAEvC,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,MAAM,kBAAkB,GAAG,SAAS,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;IACrE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy Pattern Implementation for Order Processing
|
|
3
|
+
*
|
|
4
|
+
* The Strategy pattern allows defining a family of algorithms, encapsulating each one,
|
|
5
|
+
* and making them interchangeable. This refactoring replaces conditional logic with
|
|
6
|
+
* polymorphic behavior.
|
|
7
|
+
*/
|
|
8
|
+
type OrderType = 'digital' | 'physical' | 'subscription';
|
|
9
|
+
interface Order {
|
|
10
|
+
type: OrderType;
|
|
11
|
+
status?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* OrderProcessingStrategy defines the contract for all order processing strategies.
|
|
16
|
+
* Each concrete strategy implements the process method according to its specific logic.
|
|
17
|
+
*/
|
|
18
|
+
interface OrderProcessingStrategy {
|
|
19
|
+
process(order: Order): Order;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DigitalOrderStrategy handles digital product orders.
|
|
23
|
+
* Digital orders are immediately delivered upon processing.
|
|
24
|
+
*/
|
|
25
|
+
declare class DigitalOrderStrategy implements OrderProcessingStrategy {
|
|
26
|
+
process(order: Order): Order;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* PhysicalOrderStrategy handles physical product orders.
|
|
30
|
+
* Physical orders require shipping and physical delivery.
|
|
31
|
+
*/
|
|
32
|
+
declare class PhysicalOrderStrategy implements OrderProcessingStrategy {
|
|
33
|
+
process(order: Order): Order;
|
|
34
|
+
private estimateDelivery;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* SubscriptionOrderStrategy handles subscription orders.
|
|
38
|
+
* Subscriptions activate immediately and require ongoing billing.
|
|
39
|
+
*/
|
|
40
|
+
declare class SubscriptionOrderStrategy implements OrderProcessingStrategy {
|
|
41
|
+
process(order: Order): Order;
|
|
42
|
+
private calculateNextBilling;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* OrderProcessor acts as the context that uses strategies to process orders.
|
|
46
|
+
* It maintains a strategy registry and delegates order processing to the appropriate strategy.
|
|
47
|
+
*/
|
|
48
|
+
declare class OrderProcessor {
|
|
49
|
+
private strategies;
|
|
50
|
+
constructor();
|
|
51
|
+
/**
|
|
52
|
+
* Process an order using the appropriate strategy based on its type.
|
|
53
|
+
* @param order The order to process
|
|
54
|
+
* @returns The processed order with status and additional metadata
|
|
55
|
+
* @throws Error if no strategy is found for the order type
|
|
56
|
+
*/
|
|
57
|
+
processOrder(order: Order): Order;
|
|
58
|
+
/**
|
|
59
|
+
* Register a custom strategy for a specific order type.
|
|
60
|
+
* This allows extending the processor with new order types at runtime.
|
|
61
|
+
* @param orderType The order type this strategy handles
|
|
62
|
+
* @param strategy The strategy to register
|
|
63
|
+
*/
|
|
64
|
+
registerStrategy(orderType: string, strategy: OrderProcessingStrategy): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get all registered order types.
|
|
67
|
+
* @returns Array of supported order types
|
|
68
|
+
*/
|
|
69
|
+
getSupportedOrderTypes(): OrderType[];
|
|
70
|
+
}
|
|
71
|
+
export { Order, OrderType, OrderProcessingStrategy, DigitalOrderStrategy, PhysicalOrderStrategy, SubscriptionOrderStrategy, OrderProcessor };
|
|
72
|
+
//# sourceMappingURL=order-processor-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-processor-strategy.d.ts","sourceRoot":"","sources":["../../src/utils/order-processor-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,KAAK,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,cAAc,CAAC;AAGzD,UAAU,KAAK;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAMD;;;GAGG;AACH,UAAU,uBAAuB;IAC/B,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC;CAC9B;AAMD;;;GAGG;AACH,cAAM,oBAAqB,YAAW,uBAAuB;IAC3D,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;CAQ7B;AAED;;;GAGG;AACH,cAAM,qBAAsB,YAAW,uBAAuB;IAC5D,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IAU5B,OAAO,CAAC,gBAAgB;CAKzB;AAED;;;GAGG;AACH,cAAM,yBAA0B,YAAW,uBAAuB;IAChE,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IAW5B,OAAO,CAAC,oBAAoB;CAK7B;AAMD;;;GAGG;AACH,cAAM,cAAc;IAClB,OAAO,CAAC,UAAU,CAA0C;;IAW5D;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IAUjC;;;;;OAKG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,uBAAuB,GAAG,IAAI;IAI5E;;;OAGG;IACH,sBAAsB,IAAI,SAAS,EAAE;CAGtC;AAgDD,OAAO,EACL,KAAK,EACL,SAAS,EACT,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,cAAc,EACf,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy Pattern Implementation for Order Processing
|
|
3
|
+
*
|
|
4
|
+
* The Strategy pattern allows defining a family of algorithms, encapsulating each one,
|
|
5
|
+
* and making them interchangeable. This refactoring replaces conditional logic with
|
|
6
|
+
* polymorphic behavior.
|
|
7
|
+
*/
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// CONCRETE STRATEGIES
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* DigitalOrderStrategy handles digital product orders.
|
|
13
|
+
* Digital orders are immediately delivered upon processing.
|
|
14
|
+
*/
|
|
15
|
+
class DigitalOrderStrategy {
|
|
16
|
+
process(order) {
|
|
17
|
+
return {
|
|
18
|
+
...order,
|
|
19
|
+
status: 'delivered',
|
|
20
|
+
deliveryMethod: 'digital',
|
|
21
|
+
deliveryTimestamp: new Date().toISOString()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* PhysicalOrderStrategy handles physical product orders.
|
|
27
|
+
* Physical orders require shipping and physical delivery.
|
|
28
|
+
*/
|
|
29
|
+
class PhysicalOrderStrategy {
|
|
30
|
+
process(order) {
|
|
31
|
+
return {
|
|
32
|
+
...order,
|
|
33
|
+
status: 'shipped',
|
|
34
|
+
deliveryMethod: 'physical',
|
|
35
|
+
shippingDate: new Date().toISOString(),
|
|
36
|
+
estimatedDelivery: this.estimateDelivery()
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
estimateDelivery() {
|
|
40
|
+
const date = new Date();
|
|
41
|
+
date.setDate(date.getDate() + 5); // 5 business days
|
|
42
|
+
return date.toISOString();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* SubscriptionOrderStrategy handles subscription orders.
|
|
47
|
+
* Subscriptions activate immediately and require ongoing billing.
|
|
48
|
+
*/
|
|
49
|
+
class SubscriptionOrderStrategy {
|
|
50
|
+
process(order) {
|
|
51
|
+
return {
|
|
52
|
+
...order,
|
|
53
|
+
status: 'active',
|
|
54
|
+
subscriptionType: 'recurring',
|
|
55
|
+
billingCycle: 'monthly',
|
|
56
|
+
activationDate: new Date().toISOString(),
|
|
57
|
+
nextBilling: this.calculateNextBilling()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
calculateNextBilling() {
|
|
61
|
+
const date = new Date();
|
|
62
|
+
date.setMonth(date.getMonth() + 1);
|
|
63
|
+
return date.toISOString();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// CONTEXT (ORDER PROCESSOR)
|
|
68
|
+
// ============================================================================
|
|
69
|
+
/**
|
|
70
|
+
* OrderProcessor acts as the context that uses strategies to process orders.
|
|
71
|
+
* It maintains a strategy registry and delegates order processing to the appropriate strategy.
|
|
72
|
+
*/
|
|
73
|
+
class OrderProcessor {
|
|
74
|
+
strategies;
|
|
75
|
+
constructor() {
|
|
76
|
+
// Initialize the strategy registry
|
|
77
|
+
this.strategies = new Map([
|
|
78
|
+
['digital', new DigitalOrderStrategy()],
|
|
79
|
+
['physical', new PhysicalOrderStrategy()],
|
|
80
|
+
['subscription', new SubscriptionOrderStrategy()]
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Process an order using the appropriate strategy based on its type.
|
|
85
|
+
* @param order The order to process
|
|
86
|
+
* @returns The processed order with status and additional metadata
|
|
87
|
+
* @throws Error if no strategy is found for the order type
|
|
88
|
+
*/
|
|
89
|
+
processOrder(order) {
|
|
90
|
+
const strategy = this.strategies.get(order.type);
|
|
91
|
+
if (!strategy) {
|
|
92
|
+
throw new Error(`No processing strategy found for order type: ${order.type}`);
|
|
93
|
+
}
|
|
94
|
+
return strategy.process(order);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Register a custom strategy for a specific order type.
|
|
98
|
+
* This allows extending the processor with new order types at runtime.
|
|
99
|
+
* @param orderType The order type this strategy handles
|
|
100
|
+
* @param strategy The strategy to register
|
|
101
|
+
*/
|
|
102
|
+
registerStrategy(orderType, strategy) {
|
|
103
|
+
this.strategies.set(orderType, strategy);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get all registered order types.
|
|
107
|
+
* @returns Array of supported order types
|
|
108
|
+
*/
|
|
109
|
+
getSupportedOrderTypes() {
|
|
110
|
+
return Array.from(this.strategies.keys());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// USAGE EXAMPLE
|
|
115
|
+
// ============================================================================
|
|
116
|
+
/**
|
|
117
|
+
* Example usage demonstrating the Strategy pattern in action.
|
|
118
|
+
*/
|
|
119
|
+
function demonstrateOrderProcessing() {
|
|
120
|
+
const processor = new OrderProcessor();
|
|
121
|
+
// Example orders
|
|
122
|
+
const digitalOrder = {
|
|
123
|
+
type: 'digital',
|
|
124
|
+
id: 'DIG-001',
|
|
125
|
+
product: 'Premium Software License',
|
|
126
|
+
price: 99.99
|
|
127
|
+
};
|
|
128
|
+
const physicalOrder = {
|
|
129
|
+
type: 'physical',
|
|
130
|
+
id: 'PHY-001',
|
|
131
|
+
product: 'Office Chair',
|
|
132
|
+
price: 249.99,
|
|
133
|
+
shippingAddress: '123 Main St, City, State'
|
|
134
|
+
};
|
|
135
|
+
const subscriptionOrder = {
|
|
136
|
+
type: 'subscription',
|
|
137
|
+
id: 'SUB-001',
|
|
138
|
+
product: 'Cloud Storage Pro',
|
|
139
|
+
price: 19.99
|
|
140
|
+
};
|
|
141
|
+
// Process orders
|
|
142
|
+
console.log('Processing Digital Order:');
|
|
143
|
+
console.log(JSON.stringify(processor.processOrder(digitalOrder), null, 2));
|
|
144
|
+
console.log('\nProcessing Physical Order:');
|
|
145
|
+
console.log(JSON.stringify(processor.processOrder(physicalOrder), null, 2));
|
|
146
|
+
console.log('\nProcessing Subscription Order:');
|
|
147
|
+
console.log(JSON.stringify(processor.processOrder(subscriptionOrder), null, 2));
|
|
148
|
+
// Show supported order types
|
|
149
|
+
console.log('\nSupported Order Types:', processor.getSupportedOrderTypes());
|
|
150
|
+
}
|
|
151
|
+
// Export for use in other modules
|
|
152
|
+
export { DigitalOrderStrategy, PhysicalOrderStrategy, SubscriptionOrderStrategy, OrderProcessor };
|
|
153
|
+
// Run demo if executed directly
|
|
154
|
+
const isMainModule = import.meta.url === `file://${process.argv[1]}`;
|
|
155
|
+
if (isMainModule) {
|
|
156
|
+
demonstrateOrderProcessing();
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=order-processor-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-processor-strategy.js","sourceRoot":"","sources":["../../src/utils/order-processor-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwBH,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,oBAAoB;IACxB,OAAO,CAAC,KAAY;QAClB,OAAO;YACL,GAAG,KAAK;YACR,MAAM,EAAE,WAAW;YACnB,cAAc,EAAE,SAAS;YACzB,iBAAiB,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SAC5C,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,qBAAqB;IACzB,OAAO,CAAC,KAAY;QAClB,OAAO;YACL,GAAG,KAAK;YACR,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,UAAU;YAC1B,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACtC,iBAAiB,EAAE,IAAI,CAAC,gBAAgB,EAAE;SAC3C,CAAC;IACJ,CAAC;IAEO,gBAAgB;QACtB,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,kBAAkB;QACpD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,yBAAyB;IAC7B,OAAO,CAAC,KAAY;QAClB,OAAO;YACL,GAAG,KAAK;YACR,MAAM,EAAE,QAAQ;YAChB,gBAAgB,EAAE,WAAW;YAC7B,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,IAAI,IAAI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