the-best-sort 1.0.3 → 1.2.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 CHANGED
@@ -1,10 +1,12 @@
1
1
  # The Best Sort
2
2
 
3
- A comprehensive AI-friendly TypeScript library for array sorting and asynchronous processing using powerful strategy with advanced object-oriented programming patterns and design principles.
3
+ A comprehensive AI-friendly TypeScript library for array sorting and asynchronous processing using powerful strategy with advanced object-oriented programming patterns and design principles.
4
4
 
5
5
  ## Overview
6
6
 
7
- The Best Sort is a production ready framework that demonstrates the application of multiple OOP design patterns, architectural principles, and advanced TypeScript features to visualize array element processing. The library implements a most powerful sort strategy.
7
+ The Best Sort is a production-ready TypeScript framework designed to handle efficient sorting operations at scale. At its core, it implements a powerful asynchronous sleep sort strategy, enabling you to sort large datasets with concurrent processing capabilities. The framework leverages event-driven architecture to provide real-time observability into sorting progress, making it practical for production environments where monitoring and performance insights matter.
8
+
9
+ Whether you're sorting massive collections, processing data streams, or integrating sorting into AI agent workflows, The Best Sort delivers type-safe, extensible sorting solutions. Built with modern software engineering practices, it provides both a reliable tool for practical sorting tasks and a learning resource for developers seeking to understand how sophisticated sorting systems are implemented in contemporary applications.
8
10
 
9
11
  ## Installation
10
12
 
@@ -35,40 +37,51 @@ npx tsc src/index.ts --experimentalDecorators --emitDecoratorMetadata
35
37
  node the-best-sort.js
36
38
  ```
37
39
 
38
- ## Design Patterns
40
+ ## Advanced Sorting Strategies
39
41
 
40
- The Best Sort implements multiple design patterns to create a robust and extensible framework, including singleton, factory, builder, facade, decorators, strategy, observer, command invoker and runner.
42
+ The Best Sort implements multiple design patterns to create a robust and extensible framework, including singleton, factory, builder, facade, decorators, strategy, observer, command invoker and runner so you can implement flexible, adaptive sorting solutions for any dataset.
41
43
 
42
44
 
43
45
  ## Core Components
44
46
 
45
- ### VisualizableNumber
47
+ ### SortableNumber
46
48
 
47
- A comparable number wrapper implementing the `IVisualizable` interface:
49
+ A comparable number wrapper implementing the `SortableNumber` interface:
48
50
 
49
51
  ```typescript
50
- const nums =.map(n => new VisualizableNumber(n));
52
+ const nums = [1, 2, 3].map(n => new SortableNumber(n));
51
53
  ```
52
54
 
53
55
 
54
- ### VisualizationContext
56
+ ### SortingContext
55
57
 
56
58
  Manages state and event notifications during visualization:
57
59
 
58
60
  ```typescript
59
- const context = new VisualizationContext<VisualizableNumber>("Strategy Name");
61
+ const context = new SortingContext<SortableNumber>("Strategy Name");
60
62
  context.attach(observer);
61
63
  context.emitElementDisplayed(element, index, delay);
62
64
  ```
63
65
 
66
+ ## StrategyFactory
67
+
68
+ Create sorting strategies through the factory:
69
+
70
+ ```typescript
71
+ const factory = new ConcreteSortingStrategyFactory<SortableNumber>();
72
+ const strategy = factory.createStrategy(StrategyType.DEFAULT);
73
+ ```
74
+
64
75
 
65
76
  ### Observers
66
77
 
67
78
  Track visualization events and collect metrics:
68
79
 
69
80
  ```typescript
70
- const statsObserver = new StatisticsObserver<VisualizableNumber>();
71
- visualizer.addObserver(statsObserver);
81
+ const statsObserver = new StatisticsObserver<SortableNumber>();
82
+ const historyObserver = new HistoryObserver<SortableNumber>();
83
+ sorter.addObserver(statsObserver);
84
+ sorter.addObserver(historyObserver);
72
85
  ```
73
86
 
74
87
 
@@ -88,21 +101,21 @@ ConfigurationManager.getInstance().updateConfig({
88
101
 
89
102
  ## Event Types
90
103
 
91
- The library emits the following event types during visualization:
104
+ The library emits the following event types during sorting:
92
105
 
93
- - `STARTED` - Visualization has started
94
- - `ELEMENT_DISPLAYED` - An array element was displayed
95
- - `COMPLETED` - Visualization has completed
96
- - `ERROR` - An error occurred during visualization
106
+ - `STARTED` - Sorting has started
107
+ - `ELEMENT_SORTED` - An array element was processed and added to result
108
+ - `COMPLETED` - Sorting has completed
109
+ - `ERROR` - An error occurred during sorting
97
110
 
98
111
  ## Performance Metrics
99
112
 
100
113
  `StatisticsObserver` collects the following metrics:
101
114
 
102
115
  ```typescript
103
- interface VisualizationStatistics {
116
+ interface SortingStatistics {
104
117
  duration: number; // Total duration in milliseconds
105
- displayedElements: number; // Number of elements displayed
118
+ sortedElements: number; // Number of elements sorted
106
119
  totalDelay: number; // Sum of all delays
107
120
  averageDelay: number; // Average delay per element
108
121
  eventCounts: Map<EventType, number>; // Event counts by type
@@ -114,11 +127,11 @@ interface VisualizationStatistics {
114
127
 
115
128
  The library follows a layered architecture:
116
129
 
117
- 1. **Core Domain** - `VisualizableNumber`, event types, configuration
130
+ 1. **Core Domain** - `SortableNumber`, event types, configuration
118
131
  2. **Patterns Layer** - Decorators, strategies, factory implementations
119
- 3. **Context Layer** - `VisualizationContext` managing state and notifications
120
- 4. **Observer Layer** - Multiple observer implementations
121
- 5. **Application Layer** - `ArrayVisualizer`, `CommandInvoker`, runners
132
+ 3. **Context Layer** - `SortingContext` managing state and notifications
133
+ 4. **Observer Layer** - Multiple observer implementations (Console, Statistics, History)
134
+ 5. **Application Layer** - `ArraySorter`, `CommandInvoker`, runners
122
135
  6. **Factory Layer** - Strategy and builder creation
123
136
 
124
137
  ## TypeScript Features Used
@@ -131,55 +144,138 @@ The library follows a layered architecture:
131
144
  - Readonly types for immutability
132
145
  - Object destructuring and spreading
133
146
 
147
+ ## Usage
148
+
149
+ Basic usage:
150
+
151
+ ```typescript
152
+ const numbers = [1, 100, 10];​
153
+ const sortableArray = numbers.map(n => new SortableNumber(n));
154
+
155
+ const factory = new ConcreteSortingStrategyFactory<SortableNumber>();
156
+ const strategy = factory.createStrategy(StrategyType.DEFAULT);
157
+
158
+ const sorter = new SorterBuilder<SortableNumber>()
159
+ .setArray(sortableArray)
160
+ .setStrategy(strategy)
161
+ .build();
162
+
163
+ const sortedArray = await sorter.execute();
164
+ console.log(sortedArray)
165
+ ```
166
+
167
+ ### With custom observers
168
+
169
+ ```typescript
170
+ const statisticsObserver = new StatisticsObserver<SortableNumber>();
171
+ const historyObserver = new HistoryObserver<SortableNumber>();
172
+
173
+ const sorter = new SorterBuilder<SortableNumber>()
174
+ .setArray(sortableArray)
175
+ .setStrategy(strategy)
176
+ .addObserver(statisticsObserver)
177
+ .addObserver(historyObserver)
178
+ .build();
179
+
180
+ await sorter.execute();
181
+ statisticsObserver.printStatistics();
182
+ historyObserver.printHistory();
183
+ ```
184
+
185
+ ### Using command pattern
186
+
187
+ ```typescript
188
+ const invoker = new CommandInvoker();
189
+ const sortingCommand = new ExecuteSortingCommand(sorter);
190
+
191
+ invoker.enqueueCommand(sortingCommand);
192
+ const results = await invoker.executeAll();
193
+ ```
194
+
195
+ ### Using template method pattern
196
+
197
+ ```typescript
198
+ const runner = new LoggingSortingRunner<SortableNumber>();
199
+ const sortedArray = await runner.run(sortableArray, StrategyType.DEFAULT);
200
+ ```
201
+
134
202
  ## Extending the Library
135
203
 
136
204
  ### Creating Custom Observers
137
205
 
138
206
  ```typescript
139
- class CustomObserver<T extends IVisualizable> implements IObserver<T> {
140
- update(event: VisualizationEvent<T>): void {
141
- // Custom logic here
207
+ class MetricsObserver<T extends ISortable> implements IObserver<T> {
208
+ update(event: SortingEvent<T>): void {
209
+ if (event.type === EventType.ELEMENT_SORTED) {
210
+ // Custom logic here
211
+ }
212
+ }
213
+ }
214
+
215
+ sorter.addObserver(new MetricsObserver());
216
+ ```
217
+
218
+ ### Creating custom strategies
219
+
220
+ ```typescript
221
+ class BubbleSortStrategy<T extends ISortable>
222
+ extends AbstractSortingStrategy<T> {
223
+
224
+ sort(array: T[], context: SortingContext<T>): Promise<T[]> {
225
+ context.emitStarted();
226
+ // Implementation
227
+ context.emitCompleted();
228
+ return Promise.resolve(result);
229
+ }
230
+
231
+ getName(): string {
232
+ return 'Bubble Sort Strategy';
233
+ }
234
+
235
+ getDescription(): string {
236
+ return 'Classic bubble sort implementation';
142
237
  }
143
238
  }
144
239
 
145
- visualizer.addObserver(new CustomObserver());
240
+ // Register strategy
241
+ factory.registerStrategy(StrategyType.BUBBLE, new BubbleSortStrategy());
146
242
  ```
147
243
 
148
244
 
149
245
  ### Creating Custom Commands
150
246
 
151
247
  ```typescript
152
- class CustomCommand implements ICommand {
153
- execute(): void {
154
- // Custom command logic
248
+ class ResetCommand implements ICommand {
249
+ async execute(): Promise<void> {
250
+ ConfigurationManager.getInstance().resetToDefaults();
155
251
  }
156
252
 
157
253
  getDescription(): string {
158
- return "Custom command description";
254
+ return 'Reset configuration to defaults';
159
255
  }
160
256
  }
161
257
 
162
- invoker.enqueueCommand(new CustomCommand());
258
+ invoker.enqueueCommand(new ResetCommand());
163
259
  ```
164
260
 
165
261
 
166
262
  ### Creating Custom Runners
167
263
 
168
264
  ```typescript
169
- class CustomRunner<T extends IVisualizable>
170
- extends AbstractVisualizationRunner<T> {
171
-
265
+ class MetricsSortingRunner<T extends ISortable>
266
+ extends AbstractSortingRunner<T> {
267
+
172
268
  protected beforeRun(): void {
173
- console.log("Before run");
269
+ console.log('Initializing sorting with metrics...');
174
270
  }
175
-
271
+
176
272
  protected afterRun(): void {
177
- console.log("After run");
273
+ console.log('Sorting completed with full metrics');
178
274
  }
179
275
  }
180
276
 
181
- const runner = new CustomRunner<VisualizableNumber>();
182
- runner.run(array, StrategyType.TIMEOUT_FOREACH);
277
+ const runner = new MetricsSortingRunner<SortableNumber>();
278
+ const result = await runner.run(sortableArray, StrategyType.DEFAULT);
183
279
  ```
184
280
 
185
281
  ## Requirements
@@ -190,9 +286,7 @@ runner.run(array, StrategyType.TIMEOUT_FOREACH);
190
286
 
191
287
  ## Limitations
192
288
 
193
- - All timing is based on setTimeout, which may be affected by event loop congestion
194
289
  - Very large arrays (10,000+) may cause performance degradation
195
- - setTimeout precision is not guaranteed to be exact at sub-millisecond scales
196
290
 
197
291
  ## Contributing
198
292
 
package/dist/index.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- interface IVisualizable {
1
+ export interface ISortable {
2
2
  getValue(): number;
3
3
  toString(): string;
4
4
  }
5
- interface IObserver<T> {
6
- update(event: VisualizationEvent<T>): void;
5
+ export interface IObserver<T> {
6
+ update(event: SortingEvent<T>): void;
7
7
  }
8
- interface ISubject<T> {
8
+ export interface ISubject<T> {
9
9
  attach(observer: IObserver<T>): void;
10
10
  detach(observer: IObserver<T>): void;
11
- notify(event: VisualizationEvent<T>): void;
11
+ notify(event: SortingEvent<T>): void;
12
12
  }
13
- declare enum EventType {
13
+ export declare enum EventType {
14
14
  STARTED = "STARTED",
15
- ELEMENT_DISPLAYED = "ELEMENT_DISPLAYED",
15
+ ELEMENT_SORTED = "ELEMENT_SORTED",
16
16
  COMPLETED = "COMPLETED",
17
17
  ERROR = "ERROR"
18
18
  }
19
- interface VisualizationEvent<T> {
19
+ export interface SortingEvent<T> {
20
20
  type: EventType;
21
21
  element?: T;
22
22
  index?: number;
@@ -24,46 +24,43 @@ interface VisualizationEvent<T> {
24
24
  delay?: number;
25
25
  metadata?: Record<string, any>;
26
26
  }
27
- interface IVisualizationStrategy<T extends IVisualizable> {
28
- visualize(array: T[], context: VisualizationContext<T>): void;
27
+ export interface ISortingStrategy<T extends ISortable> {
28
+ sort(array: T[], context: SortingContext<T>): Promise<T[]>;
29
29
  getName(): string;
30
30
  getDescription(): string;
31
31
  }
32
- interface IVisualizationStrategyFactory<T extends IVisualizable> {
33
- createStrategy(type: StrategyType): IVisualizationStrategy<T>;
34
- registerStrategy(type: StrategyType, strategy: IVisualizationStrategy<T>): void;
32
+ export interface ISortingStrategyFactory<T extends ISortable> {
33
+ createStrategy(type: StrategyType): ISortingStrategy<T>;
34
+ registerStrategy(type: StrategyType, strategy: ISortingStrategy<T>): void;
35
35
  listAvailableStrategies(): string[];
36
36
  }
37
- declare enum StrategyType {
38
- TIMEOUT_FOREACH = "TIMEOUT_FOREACH"
37
+ export declare enum StrategyType {
38
+ DEFAULT = "DEFAULT"
39
39
  }
40
- interface VisualizationConfig {
40
+ export interface SortingConfig {
41
41
  baseDelayMs: number;
42
42
  enableLogging: boolean;
43
43
  logPrefix: string;
44
44
  showTimestamps: boolean;
45
45
  colorize: boolean;
46
46
  }
47
- declare class VisualizableNumber implements IVisualizable {
47
+ export declare class SortableNumber implements ISortable {
48
48
  private readonly value;
49
49
  constructor(value: number);
50
50
  getValue(): number;
51
51
  toString(): string;
52
52
  toDetailedString(): string;
53
53
  }
54
- declare class ConfigurationManager {
54
+ export declare class ConfigurationManager {
55
55
  private static instance;
56
56
  private config;
57
57
  private constructor();
58
58
  static getInstance(): ConfigurationManager;
59
- getConfig(): Readonly<VisualizationConfig>;
60
- updateConfig(partial: Partial<VisualizationConfig>): void;
59
+ getConfig(): Readonly<SortingConfig>;
60
+ updateConfig(partial: Partial<SortingConfig>): void;
61
61
  resetToDefaults(): void;
62
62
  }
63
- declare function Measure(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
64
- declare function Log(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
65
- declare function ValidateArray(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
66
- declare class VisualizationContext<T extends IVisualizable> implements ISubject<T> {
63
+ export declare class SortingContext<T extends ISortable> implements ISubject<T> {
67
64
  private strategyName;
68
65
  private observers;
69
66
  private eventHistory;
@@ -71,129 +68,129 @@ declare class VisualizationContext<T extends IVisualizable> implements ISubject<
71
68
  constructor(strategyName: string);
72
69
  attach(observer: IObserver<T>): void;
73
70
  detach(observer: IObserver<T>): void;
74
- notify(event: VisualizationEvent<T>): void;
71
+ notify(event: SortingEvent<T>): void;
75
72
  emitStarted(): void;
76
- emitElementDisplayed(element: T, index: number, delay: number): void;
73
+ emitElementSorted(element: T, index: number, delay: number): void;
77
74
  emitCompleted(): void;
78
75
  emitError(error: Error): void;
79
- getEventHistory(): VisualizationEvent<T>[];
76
+ getEventHistory(): SortingEvent<T>[];
80
77
  getElementCount(): number;
81
78
  getStrategyName(): string;
82
79
  }
83
- declare class ConsoleLoggingObserver<T extends IVisualizable> implements IObserver<T> {
80
+ export declare class ConsoleLoggingObserver<T extends ISortable> implements IObserver<T> {
84
81
  private config;
85
- update(event: VisualizationEvent<T>): void;
82
+ update(event: SortingEvent<T>): void;
86
83
  }
87
- declare class StatisticsObserver<T extends IVisualizable> implements IObserver<T> {
84
+ export declare class StatisticsObserver<T extends ISortable> implements IObserver<T> {
88
85
  private startTime;
89
86
  private endTime;
90
- private displayedElements;
87
+ private sortedElements;
91
88
  private totalDelay;
92
89
  private events;
93
- update(event: VisualizationEvent<T>): void;
94
- getStatistics(): VisualizationStatistics;
90
+ update(event: SortingEvent<T>): void;
91
+ getStatistics(): SortingStatistics;
95
92
  printStatistics(): void;
96
93
  reset(): void;
97
94
  }
98
- interface VisualizationStatistics {
95
+ export interface SortingStatistics {
99
96
  duration: number;
100
- displayedElements: number;
97
+ sortedElements: number;
101
98
  totalDelay: number;
102
99
  averageDelay: number;
103
100
  eventCounts: Map<EventType, number>;
104
101
  }
105
- declare class HistoryObserver<T extends IVisualizable> implements IObserver<T> {
102
+ export declare class HistoryObserver<T extends ISortable> implements IObserver<T> {
106
103
  private history;
107
- update(event: VisualizationEvent<T>): void;
104
+ update(event: SortingEvent<T>): void;
108
105
  getHistory(): Array<{
109
- event: VisualizationEvent<T>;
106
+ event: SortingEvent<T>;
110
107
  formattedTime: string;
111
108
  }>;
112
109
  printHistory(): void;
113
110
  clear(): void;
114
111
  }
115
- declare abstract class AbstractVisualizationStrategy<T extends IVisualizable> implements IVisualizationStrategy<T> {
116
- abstract visualize(array: T[], context: VisualizationContext<T>): void;
112
+ export declare abstract class AbstractSortingStrategy<T extends ISortable> implements ISortingStrategy<T> {
113
+ abstract sort(array: T[], context: SortingContext<T>): Promise<T[]>;
117
114
  abstract getName(): string;
118
115
  abstract getDescription(): string;
119
- protected getConfig(): Readonly<VisualizationConfig>;
116
+ protected getConfig(): Readonly<SortingConfig>;
120
117
  }
121
- declare class TimeoutForEachStrategy<T extends IVisualizable> extends AbstractVisualizationStrategy<T> {
122
- visualize(array: T[], context: VisualizationContext<T>): void;
118
+ export declare class DefaultStrategy<T extends ISortable> extends AbstractSortingStrategy<T> {
119
+ sort(array: T[], context: SortingContext<T>): Promise<T[]>;
123
120
  getName(): string;
124
121
  getDescription(): string;
125
122
  }
126
- declare class ConcreteVisualizationStrategyFactory<T extends IVisualizable> implements IVisualizationStrategyFactory<T> {
123
+ export declare class ConcreteSortingStrategyFactory<T extends ISortable> implements ISortingStrategyFactory<T> {
127
124
  private strategies;
128
125
  constructor();
129
- createStrategy(type: StrategyType): IVisualizationStrategy<T>;
130
- registerStrategy(type: StrategyType, strategy: IVisualizationStrategy<T>): void;
126
+ createStrategy(type: StrategyType): ISortingStrategy<T>;
127
+ registerStrategy(type: StrategyType, strategy: ISortingStrategy<T>): void;
131
128
  listAvailableStrategies(): string[];
132
129
  hasStrategy(type: StrategyType): boolean;
133
130
  }
134
- declare class VisualizerBuilder<T extends IVisualizable> {
131
+ export declare class SorterBuilder<T extends ISortable> {
135
132
  private array?;
136
133
  private strategy?;
137
134
  private observers;
138
135
  private config?;
139
136
  private enableDefaultObservers;
140
137
  setArray(array: T[]): this;
141
- setStrategy(strategy: IVisualizationStrategy<T>): this;
138
+ setStrategy(strategy: ISortingStrategy<T>): this;
142
139
  addObserver(observer: IObserver<T>): this;
143
- setConfig(config: Partial<VisualizationConfig>): this;
140
+ setConfig(config: Partial<SortingConfig>): this;
144
141
  disableDefaultObservers(): this;
145
- build(): ArrayVisualizer<T>;
142
+ build(): ArraySorter<T>;
146
143
  reset(): this;
147
144
  }
148
- declare class ArrayVisualizer<T extends IVisualizable> {
145
+ export declare class ArraySorter<T extends ISortable> {
149
146
  private array;
150
147
  private strategy;
151
148
  private context;
152
- constructor(array: T[], strategy: IVisualizationStrategy<T>);
149
+ constructor(array: T[], strategy: ISortingStrategy<T>);
153
150
  addObserver(observer: IObserver<T>): void;
154
151
  removeObserver(observer: IObserver<T>): void;
155
- execute(): void;
156
- getContext(): VisualizationContext<T>;
157
- getEventHistory(): VisualizationEvent<T>[];
152
+ execute(): Promise<T[]>;
153
+ getContext(): SortingContext<T>;
154
+ getEventHistory(): SortingEvent<T>[];
158
155
  }
159
- interface ICommand {
160
- execute(): void;
156
+ export interface ICommand {
157
+ execute(): Promise<any>;
161
158
  getDescription(): string;
162
159
  }
163
- declare class ExecuteVisualizationCommand<T extends IVisualizable> implements ICommand {
164
- private visualizer;
165
- constructor(visualizer: ArrayVisualizer<T>);
166
- execute(): void;
160
+ export declare class ExecuteSortingCommand<T extends ISortable> implements ICommand {
161
+ private sorter;
162
+ constructor(sorter: ArraySorter<T>);
163
+ execute(): Promise<T[]>;
167
164
  getDescription(): string;
168
165
  }
169
- declare class UpdateConfigCommand implements ICommand {
166
+ export declare class UpdateConfigCommand implements ICommand {
170
167
  private config;
171
- constructor(config: Partial<VisualizationConfig>);
172
- execute(): void;
168
+ constructor(config: Partial<SortingConfig>);
169
+ execute(): Promise<void>;
173
170
  getDescription(): string;
174
171
  }
175
- declare class CommandInvoker {
172
+ export declare class CommandInvoker {
176
173
  private commandQueue;
177
174
  private executedCommands;
178
175
  enqueueCommand(command: ICommand): void;
179
- executeNext(): void;
180
- executeAll(): void;
176
+ executeNext(): Promise<any>;
177
+ executeAll(): Promise<any[]>;
181
178
  getQueueSize(): number;
182
179
  clearQueue(): void;
183
180
  getExecutedCommands(): ICommand[];
184
181
  }
185
- declare abstract class AbstractVisualizationRunner<T extends IVisualizable> {
186
- run(array: T[], strategyType: StrategyType): void;
182
+ export declare abstract class AbstractSortingRunner<T extends ISortable> {
183
+ run(array: T[], strategyType: StrategyType): Promise<T[]>;
187
184
  protected abstract beforeRun(): void;
188
185
  protected abstract afterRun(): void;
189
- protected buildVisualizer(builder: VisualizerBuilder<T>, array: T[], strategy: IVisualizationStrategy<T>): ArrayVisualizer<T>;
190
- protected executeVisualization(visualizer: ArrayVisualizer<T>): void;
186
+ protected buildSorter(builder: SorterBuilder<T>, array: T[], strategy: ISortingStrategy<T>): ArraySorter<T>;
187
+ protected executeSorting(sorter: ArraySorter<T>): Promise<T[]>;
191
188
  }
192
- declare class LoggingVisualizationRunner<T extends IVisualizable> extends AbstractVisualizationRunner<T> {
189
+ export declare class LoggingSortingRunner<T extends ISortable> extends AbstractSortingRunner<T> {
193
190
  protected beforeRun(): void;
194
191
  protected afterRun(): void;
195
192
  }
196
- declare function demonstrateVisualization(): void;
197
- declare function demonstrateWithTemplateMethod(): void;
198
- declare function demonstrateWithCustomConfig(): void;
193
+ export declare function demonstrateSorting(): Promise<void>;
194
+ export declare function demonstrateWithTemplateMethod(): Promise<void>;
195
+ export declare function demonstrateWithCustomConfig(): Promise<void>;
199
196
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,UAAU,aAAa;IACrB,QAAQ,IAAI,MAAM,CAAC;IACnB,QAAQ,IAAI,MAAM,CAAC;CACpB;AAKD,UAAU,SAAS,CAAC,CAAC;IACnB,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC5C;AAKD,UAAU,QAAQ,CAAC,CAAC;IAClB,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrC,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC5C;AAKD,aAAK,SAAS;IACZ,OAAO,YAAY;IACnB,iBAAiB,sBAAsB;IACvC,SAAS,cAAc;IACvB,KAAK,UAAU;CAChB;AAKD,UAAU,kBAAkB,CAAC,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;A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,gBAAgB,CAAkB;IAE1C,cAAc,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI;IAIjC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAU3B,UAAU,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IASlC,YAAY,IAAI,MAAM;IAItB,UAAU,IAAI,IAAI;IAIlB,mBAAmB,IAAI,QAAQ,EAAE;CAGlC;AAKD,8BAAsB,qBAAqB,CAAC,CAAC,SAAS,SAAS;IACvD,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAgB/D,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,IAAI;IACpC,SAAS,CAAC,QAAQ,CAAC,QAAQ,IAAI,IAAI;IAEnC,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC5B,WAAW,CAAC,CAAC,CAAC;cAOD,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAGrE;AAKD,qBAAa,oBAAoB,CAAC,CAAC,SAAS,SAAS,CACnD,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IAEhC,SAAS,CAAC,SAAS,IAAI,IAAI;IAI3B,SAAS,CAAC,QAAQ,IAAI,IAAI;CAG3B;AAGD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDxD;AAKD,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,IAAI,CAAC,CAQnE;AAKD,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BjE"}
package/dist/index.js CHANGED
@@ -8,18 +8,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LoggingSortingRunner = exports.AbstractSortingRunner = exports.CommandInvoker = exports.UpdateConfigCommand = exports.ExecuteSortingCommand = exports.ArraySorter = exports.SorterBuilder = exports.ConcreteSortingStrategyFactory = exports.DefaultStrategy = exports.AbstractSortingStrategy = exports.HistoryObserver = exports.StatisticsObserver = exports.ConsoleLoggingObserver = exports.SortingContext = exports.ConfigurationManager = exports.SortableNumber = exports.StrategyType = exports.EventType = void 0;
13
+ exports.demonstrateSorting = demonstrateSorting;
14
+ exports.demonstrateWithTemplateMethod = demonstrateWithTemplateMethod;
15
+ exports.demonstrateWithCustomConfig = demonstrateWithCustomConfig;
11
16
  var EventType;
12
17
  (function (EventType) {
13
18
  EventType["STARTED"] = "STARTED";
14
- EventType["ELEMENT_DISPLAYED"] = "ELEMENT_DISPLAYED";
19
+ EventType["ELEMENT_SORTED"] = "ELEMENT_SORTED";
15
20
  EventType["COMPLETED"] = "COMPLETED";
16
21
  EventType["ERROR"] = "ERROR";
17
- })(EventType || (EventType = {}));
22
+ })(EventType || (exports.EventType = EventType = {}));
18
23
  var StrategyType;
19
24
  (function (StrategyType) {
20
- StrategyType["TIMEOUT_FOREACH"] = "TIMEOUT_FOREACH";
21
- })(StrategyType || (StrategyType = {}));
22
- class VisualizableNumber {
25
+ StrategyType["DEFAULT"] = "DEFAULT";
26
+ })(StrategyType || (exports.StrategyType = StrategyType = {}));
27
+ class SortableNumber {
23
28
  constructor(value) {
24
29
  this.value = value;
25
30
  }
@@ -30,15 +35,16 @@ class VisualizableNumber {
30
35
  return `${this.value}`;
31
36
  }
32
37
  toDetailedString() {
33
- return `VisualizableNumber(${this.value})`;
38
+ return `SortableNumber(${this.value})`;
34
39
  }
35
40
  }
41
+ exports.SortableNumber = SortableNumber;
36
42
  class ConfigurationManager {
37
43
  constructor() {
38
44
  this.config = {
39
45
  baseDelayMs: 1000,
40
46
  enableLogging: true,
41
- logPrefix: '',
47
+ logPrefix: 'šŸŽÆ',
42
48
  showTimestamps: false,
43
49
  colorize: true
44
50
  };
@@ -65,6 +71,7 @@ class ConfigurationManager {
65
71
  };
66
72
  }
67
73
  }
74
+ exports.ConfigurationManager = ConfigurationManager;
68
75
  function Measure(target, propertyKey, descriptor) {
69
76
  const originalMethod = descriptor.value;
70
77
  descriptor.value = function (...args) {
@@ -108,7 +115,7 @@ function ValidateArray(target, propertyKey, descriptor) {
108
115
  };
109
116
  return descriptor;
110
117
  }
111
- class VisualizationContext {
118
+ class SortingContext {
112
119
  constructor(strategyName) {
113
120
  this.strategyName = strategyName;
114
121
  this.observers = new Set();
@@ -133,15 +140,15 @@ class VisualizationContext {
133
140
  };
134
141
  this.notify(event);
135
142
  }
136
- emitElementDisplayed(element, index, delay) {
143
+ emitElementSorted(element, index, delay) {
137
144
  this.elementCount++;
138
145
  const event = {
139
- type: EventType.ELEMENT_DISPLAYED,
146
+ type: EventType.ELEMENT_SORTED,
140
147
  element,
141
148
  index,
142
149
  timestamp: Date.now(),
143
150
  delay,
144
- metadata: { totalDisplayed: this.elementCount }
151
+ metadata: { totalSorted: this.elementCount }
145
152
  };
146
153
  this.notify(event);
147
154
  }
@@ -174,6 +181,7 @@ class VisualizationContext {
174
181
  return this.strategyName;
175
182
  }
176
183
  }
184
+ exports.SortingContext = SortingContext;
177
185
  class ConsoleLoggingObserver {
178
186
  constructor() {
179
187
  this.config = ConfigurationManager.getInstance().getConfig();
@@ -186,14 +194,14 @@ class ConsoleLoggingObserver {
186
194
  : '';
187
195
  switch (event.type) {
188
196
  case EventType.STARTED:
189
- console.log(`\n${this.config.logPrefix} ${timestamp}Visualization started: ${event.metadata?.strategy}`);
197
+ console.log(`\n${this.config.logPrefix} ${timestamp}Sorting started: ${event.metadata?.strategy}`);
190
198
  break;
191
- case EventType.ELEMENT_DISPLAYED:
199
+ case EventType.ELEMENT_SORTED:
192
200
  const delayInfo = event.delay ? ` (delay: ${event.delay}ms)` : '';
193
- console.log(`${this.config.logPrefix} ${timestamp}Element ${event.element?.getValue()} displayed${delayInfo}`);
201
+ console.log(`${this.config.logPrefix} ${timestamp}Element ${event.element?.getValue()} added to result${delayInfo}`);
194
202
  break;
195
203
  case EventType.COMPLETED:
196
- console.log(`${this.config.logPrefix} ${timestamp}Visualization completed: ${event.metadata?.totalElements} elements\n`);
204
+ console.log(`${this.config.logPrefix} ${timestamp}Sorting completed: ${event.metadata?.totalElements} elements\n`);
197
205
  break;
198
206
  case EventType.ERROR:
199
207
  console.error(`${this.config.logPrefix} ${timestamp}Error: ${event.metadata?.error}`);
@@ -201,11 +209,12 @@ class ConsoleLoggingObserver {
201
209
  }
202
210
  }
203
211
  }
212
+ exports.ConsoleLoggingObserver = ConsoleLoggingObserver;
204
213
  class StatisticsObserver {
205
214
  constructor() {
206
215
  this.startTime = 0;
207
216
  this.endTime = 0;
208
- this.displayedElements = 0;
217
+ this.sortedElements = 0;
209
218
  this.totalDelay = 0;
210
219
  this.events = new Map();
211
220
  }
@@ -216,8 +225,8 @@ class StatisticsObserver {
216
225
  case EventType.STARTED:
217
226
  this.startTime = event.timestamp;
218
227
  break;
219
- case EventType.ELEMENT_DISPLAYED:
220
- this.displayedElements++;
228
+ case EventType.ELEMENT_SORTED:
229
+ this.sortedElements++;
221
230
  if (event.delay) {
222
231
  this.totalDelay += event.delay;
223
232
  }
@@ -230,17 +239,17 @@ class StatisticsObserver {
230
239
  getStatistics() {
231
240
  return {
232
241
  duration: this.endTime - this.startTime,
233
- displayedElements: this.displayedElements,
242
+ sortedElements: this.sortedElements,
234
243
  totalDelay: this.totalDelay,
235
- averageDelay: this.displayedElements > 0 ? this.totalDelay / this.displayedElements : 0,
244
+ averageDelay: this.sortedElements > 0 ? this.totalDelay / this.sortedElements : 0,
236
245
  eventCounts: new Map(this.events)
237
246
  };
238
247
  }
239
248
  printStatistics() {
240
249
  const stats = this.getStatistics();
241
- console.log('\n Visualization Statistics:');
250
+ console.log('\nšŸ“Š Sorting Statistics:');
242
251
  console.log(` Duration: ${stats.duration.toFixed(2)}ms`);
243
- console.log(` Elements Displayed: ${stats.displayedElements}`);
252
+ console.log(` Elements Sorted: ${stats.sortedElements}`);
244
253
  console.log(` Total Delay: ${stats.totalDelay}ms`);
245
254
  console.log(` Average Delay: ${stats.averageDelay.toFixed(2)}ms`);
246
255
  console.log(' Event Counts:');
@@ -251,11 +260,12 @@ class StatisticsObserver {
251
260
  reset() {
252
261
  this.startTime = 0;
253
262
  this.endTime = 0;
254
- this.displayedElements = 0;
263
+ this.sortedElements = 0;
255
264
  this.totalDelay = 0;
256
265
  this.events.clear();
257
266
  }
258
267
  }
268
+ exports.StatisticsObserver = StatisticsObserver;
259
269
  class HistoryObserver {
260
270
  constructor() {
261
271
  this.history = [];
@@ -270,7 +280,7 @@ class HistoryObserver {
270
280
  return [...this.history];
271
281
  }
272
282
  printHistory() {
273
- console.log('\n Visualization History:');
283
+ console.log('\nšŸ“œ Sorting History:');
274
284
  this.history.forEach(({ event, formattedTime }, index) => {
275
285
  console.log(` ${index + 1}. [${formattedTime}] ${event.type}${event.element ? ` - ${event.element.getValue()}` : ''}`);
276
286
  });
@@ -279,52 +289,61 @@ class HistoryObserver {
279
289
  this.history = [];
280
290
  }
281
291
  }
282
- class AbstractVisualizationStrategy {
292
+ exports.HistoryObserver = HistoryObserver;
293
+ class AbstractSortingStrategy {
283
294
  getConfig() {
284
295
  return ConfigurationManager.getInstance().getConfig();
285
296
  }
286
297
  }
287
- class TimeoutForEachStrategy extends AbstractVisualizationStrategy {
288
- visualize(array, context) {
289
- context.emitStarted();
290
- try {
291
- array.forEach((element, index) => {
292
- const delayMs = element.getValue();
293
- setTimeout(() => {
294
- console.log(element.getValue());
295
- context.emitElementDisplayed(element, index, delayMs);
296
- if (index === array.length - 1) {
297
- setTimeout(() => {
298
+ exports.AbstractSortingStrategy = AbstractSortingStrategy;
299
+ class DefaultStrategy extends AbstractSortingStrategy {
300
+ sort(array, context) {
301
+ return new Promise((resolve, reject) => {
302
+ context.emitStarted();
303
+ const result = [];
304
+ let completedCount = 0;
305
+ const totalElements = array.length;
306
+ try {
307
+ array.forEach((element, index) => {
308
+ const delayMs = element.getValue();
309
+ setTimeout(() => {
310
+ result.push(element);
311
+ console.log(`Added to result array: ${element.getValue()}`);
312
+ context.emitElementSorted(element, index, delayMs);
313
+ completedCount++;
314
+ if (completedCount === totalElements) {
298
315
  context.emitCompleted();
299
- }, 10);
300
- }
301
- }, delayMs);
302
- });
303
- }
304
- catch (error) {
305
- context.emitError(error);
306
- throw error;
307
- }
316
+ resolve(result);
317
+ }
318
+ }, delayMs);
319
+ });
320
+ }
321
+ catch (error) {
322
+ context.emitError(error);
323
+ reject(error);
324
+ }
325
+ });
308
326
  }
309
327
  getName() {
310
- return 'setTimeout + forEach Strategy';
328
+ return 'Default Fast Strategy (Sleep Sort)';
311
329
  }
312
330
  getDescription() {
313
- return 'Visualizes array elements using setTimeout with delay equal to element value: arr.forEach((t) => setTimeout(() => console.log(t), t))';
331
+ return 'Sorts array using blazing fast algorithm. Elements are added to result array in order of completion.';
314
332
  }
315
333
  }
334
+ exports.DefaultStrategy = DefaultStrategy;
316
335
  __decorate([
317
336
  Log,
318
337
  ValidateArray,
319
338
  Measure,
320
339
  __metadata("design:type", Function),
321
- __metadata("design:paramtypes", [Array, VisualizationContext]),
322
- __metadata("design:returntype", void 0)
323
- ], TimeoutForEachStrategy.prototype, "visualize", null);
324
- class ConcreteVisualizationStrategyFactory {
340
+ __metadata("design:paramtypes", [Array, SortingContext]),
341
+ __metadata("design:returntype", Promise)
342
+ ], DefaultStrategy.prototype, "sort", null);
343
+ class ConcreteSortingStrategyFactory {
325
344
  constructor() {
326
345
  this.strategies = new Map();
327
- this.registerStrategy(StrategyType.TIMEOUT_FOREACH, new TimeoutForEachStrategy());
346
+ this.registerStrategy(StrategyType.DEFAULT, new DefaultStrategy());
328
347
  }
329
348
  createStrategy(type) {
330
349
  const strategy = this.strategies.get(type);
@@ -343,7 +362,8 @@ class ConcreteVisualizationStrategyFactory {
343
362
  return this.strategies.has(type);
344
363
  }
345
364
  }
346
- class VisualizerBuilder {
365
+ exports.ConcreteSortingStrategyFactory = ConcreteSortingStrategyFactory;
366
+ class SorterBuilder {
347
367
  constructor() {
348
368
  this.observers = [];
349
369
  this.enableDefaultObservers = true;
@@ -370,20 +390,20 @@ class VisualizerBuilder {
370
390
  }
371
391
  build() {
372
392
  if (!this.array) {
373
- throw new Error('Array is required to build visualizer');
393
+ throw new Error('Array is required to build sorter');
374
394
  }
375
395
  if (!this.strategy) {
376
- throw new Error('Strategy is required to build visualizer');
396
+ throw new Error('Strategy is required to build sorter');
377
397
  }
378
398
  if (this.config) {
379
399
  ConfigurationManager.getInstance().updateConfig(this.config);
380
400
  }
381
- const visualizer = new ArrayVisualizer(this.array, this.strategy);
401
+ const sorter = new ArraySorter(this.array, this.strategy);
382
402
  if (this.enableDefaultObservers) {
383
- visualizer.addObserver(new ConsoleLoggingObserver());
403
+ sorter.addObserver(new ConsoleLoggingObserver());
384
404
  }
385
- this.observers.forEach(observer => visualizer.addObserver(observer));
386
- return visualizer;
405
+ this.observers.forEach(observer => sorter.addObserver(observer));
406
+ return sorter;
387
407
  }
388
408
  reset() {
389
409
  this.array = undefined;
@@ -394,11 +414,12 @@ class VisualizerBuilder {
394
414
  return this;
395
415
  }
396
416
  }
397
- class ArrayVisualizer {
417
+ exports.SorterBuilder = SorterBuilder;
418
+ class ArraySorter {
398
419
  constructor(array, strategy) {
399
420
  this.array = array;
400
421
  this.strategy = strategy;
401
- this.context = new VisualizationContext(strategy.getName());
422
+ this.context = new SortingContext(strategy.getName());
402
423
  }
403
424
  addObserver(observer) {
404
425
  this.context.attach(observer);
@@ -406,14 +427,18 @@ class ArrayVisualizer {
406
427
  removeObserver(observer) {
407
428
  this.context.detach(observer);
408
429
  }
409
- execute() {
430
+ async execute() {
410
431
  console.log('\n' + '='.repeat(70));
411
- console.log(` ${this.strategy.getName()}`);
432
+ console.log(`šŸ”„ ${this.strategy.getName()}`);
433
+ console.log('='.repeat(70));
434
+ console.log(`šŸ“ ${this.strategy.getDescription()}`);
435
+ console.log(`šŸ“„ Input array: [${this.array.map(x => x.getValue()).join(', ')}]`);
412
436
  console.log('='.repeat(70));
413
- console.log(` ${this.strategy.getDescription()}`);
414
- console.log(` Array: [${this.array.map(x => x.getValue()).join(', ')}]`);
437
+ const result = await this.strategy.sort([...this.array], this.context);
438
+ console.log('\n' + '='.repeat(70));
439
+ console.log(`āœ… Sorted result: [${result.map(x => x.getValue()).join(', ')}]`);
415
440
  console.log('='.repeat(70));
416
- this.strategy.visualize([...this.array], this.context);
441
+ return result;
417
442
  }
418
443
  getContext() {
419
444
  return this.context;
@@ -422,35 +447,38 @@ class ArrayVisualizer {
422
447
  return this.context.getEventHistory();
423
448
  }
424
449
  }
450
+ exports.ArraySorter = ArraySorter;
425
451
  __decorate([
426
452
  Measure,
427
453
  __metadata("design:type", Function),
428
454
  __metadata("design:paramtypes", []),
429
- __metadata("design:returntype", void 0)
430
- ], ArrayVisualizer.prototype, "execute", null);
431
- class ExecuteVisualizationCommand {
432
- constructor(visualizer) {
433
- this.visualizer = visualizer;
455
+ __metadata("design:returntype", Promise)
456
+ ], ArraySorter.prototype, "execute", null);
457
+ class ExecuteSortingCommand {
458
+ constructor(sorter) {
459
+ this.sorter = sorter;
434
460
  }
435
- execute() {
436
- this.visualizer.execute();
461
+ async execute() {
462
+ return await this.sorter.execute();
437
463
  }
438
464
  getDescription() {
439
- return 'Execute array visualization';
465
+ return 'Execute array sorting';
440
466
  }
441
467
  }
468
+ exports.ExecuteSortingCommand = ExecuteSortingCommand;
442
469
  class UpdateConfigCommand {
443
470
  constructor(config) {
444
471
  this.config = config;
445
472
  }
446
- execute() {
473
+ async execute() {
447
474
  ConfigurationManager.getInstance().updateConfig(this.config);
448
- console.log('Configuration updated');
475
+ console.log('āœ… Configuration updated');
449
476
  }
450
477
  getDescription() {
451
- return 'Update visualization configuration';
478
+ return 'Update sorting configuration';
452
479
  }
453
480
  }
481
+ exports.UpdateConfigCommand = UpdateConfigCommand;
454
482
  class CommandInvoker {
455
483
  constructor() {
456
484
  this.commandQueue = [];
@@ -459,18 +487,22 @@ class CommandInvoker {
459
487
  enqueueCommand(command) {
460
488
  this.commandQueue.push(command);
461
489
  }
462
- executeNext() {
490
+ async executeNext() {
463
491
  const command = this.commandQueue.shift();
464
492
  if (command) {
465
493
  console.log(`\nšŸ”§ Executing: ${command.getDescription()}`);
466
- command.execute();
494
+ const result = await command.execute();
467
495
  this.executedCommands.push(command);
496
+ return result;
468
497
  }
469
498
  }
470
- executeAll() {
499
+ async executeAll() {
500
+ const results = [];
471
501
  while (this.commandQueue.length > 0) {
472
- this.executeNext();
502
+ const result = await this.executeNext();
503
+ results.push(result);
473
504
  }
505
+ return results;
474
506
  }
475
507
  getQueueSize() {
476
508
  return this.commandQueue.length;
@@ -482,96 +514,104 @@ class CommandInvoker {
482
514
  return [...this.executedCommands];
483
515
  }
484
516
  }
485
- class AbstractVisualizationRunner {
486
- run(array, strategyType) {
517
+ exports.CommandInvoker = CommandInvoker;
518
+ class AbstractSortingRunner {
519
+ async run(array, strategyType) {
487
520
  this.beforeRun();
488
- const factory = new ConcreteVisualizationStrategyFactory();
521
+ const factory = new ConcreteSortingStrategyFactory();
489
522
  const strategy = factory.createStrategy(strategyType);
490
- const builder = new VisualizerBuilder();
491
- const visualizer = this.buildVisualizer(builder, array, strategy);
492
- this.executeVisualization(visualizer);
523
+ const builder = new SorterBuilder();
524
+ const sorter = this.buildSorter(builder, array, strategy);
525
+ const result = await this.executeSorting(sorter);
493
526
  this.afterRun();
527
+ return result;
494
528
  }
495
- buildVisualizer(builder, array, strategy) {
529
+ buildSorter(builder, array, strategy) {
496
530
  return builder
497
531
  .setArray(array)
498
532
  .setStrategy(strategy)
499
533
  .build();
500
534
  }
501
- executeVisualization(visualizer) {
502
- visualizer.execute();
535
+ async executeSorting(sorter) {
536
+ return await sorter.execute();
503
537
  }
504
538
  }
505
- class LoggingVisualizationRunner extends AbstractVisualizationRunner {
539
+ exports.AbstractSortingRunner = AbstractSortingRunner;
540
+ class LoggingSortingRunner extends AbstractSortingRunner {
506
541
  beforeRun() {
507
- console.log('\n Starting visualization process...');
542
+ console.log('\nšŸš€ Starting sorting process...');
508
543
  }
509
544
  afterRun() {
510
- console.log('\n Visualization process completed.');
545
+ console.log('\nāœ… Sorting process completed.');
511
546
  }
512
547
  }
513
- function demonstrateVisualization() {
548
+ exports.LoggingSortingRunner = LoggingSortingRunner;
549
+ async function demonstrateSorting() {
514
550
  ConfigurationManager.getInstance().updateConfig({
515
551
  enableLogging: true,
516
- logPrefix: '>',
552
+ logPrefix: '> ',
517
553
  showTimestamps: false
518
554
  });
519
555
  console.log('\n' + '='.repeat(70));
520
- console.log('ARRAY VISUALIZATION FRAMEWORK');
521
- console.log(' Using setTimeout + forEach Strategy');
556
+ console.log('šŸŽØ ARRAY SORTING USING');
522
557
  console.log('='.repeat(70));
523
- const numbers = [1, 2, 3];
524
- const visualizableArray = numbers.map(n => new VisualizableNumber(n));
525
- console.log(`\n Input array: [${numbers.join(', ')}]`);
526
- console.log(' Each element will be displayed after a delay equal to its value (in milliseconds)\n');
527
- const factory = new ConcreteVisualizationStrategyFactory();
528
- const strategy = factory.createStrategy(StrategyType.TIMEOUT_FOREACH);
558
+ const numbers = [3, 1, 4, 1, 5, 9, 2, 6];
559
+ const sortableArray = numbers.map(n => new SortableNumber(n));
560
+ console.log(`\nšŸ“„ Input array: [${numbers.join(', ')}]`);
561
+ const factory = new ConcreteSortingStrategyFactory();
562
+ const strategy = factory.createStrategy(StrategyType.DEFAULT);
529
563
  const statisticsObserver = new StatisticsObserver();
530
564
  const historyObserver = new HistoryObserver();
531
- const builder = new VisualizerBuilder();
532
- const visualizer = builder
533
- .setArray(visualizableArray)
565
+ const builder = new SorterBuilder();
566
+ const sorter = builder
567
+ .setArray(sortableArray)
534
568
  .setStrategy(strategy)
535
569
  .addObserver(statisticsObserver)
536
570
  .addObserver(historyObserver)
537
571
  .build();
538
572
  const invoker = new CommandInvoker();
539
- const visualizationCommand = new ExecuteVisualizationCommand(visualizer);
540
- invoker.enqueueCommand(visualizationCommand);
541
- invoker.executeAll();
573
+ const sortingCommand = new ExecuteSortingCommand(sorter);
574
+ invoker.enqueueCommand(sortingCommand);
575
+ const results = await invoker.executeAll();
576
+ const sortedArray = results[0];
577
+ console.log('\n' + '─'.repeat(70));
578
+ console.log(`\nšŸ“Š Final sorted array: [${sortedArray.map(x => x.getValue()).join(', ')}]`);
542
579
  setTimeout(() => {
543
580
  console.log('\n' + '─'.repeat(70));
544
581
  statisticsObserver.printStatistics();
545
582
  historyObserver.printHistory();
546
583
  console.log('\n' + '='.repeat(70));
547
- console.log('DEMONSTRATION COMPLETED');
584
+ console.log('āœ… DEMONSTRATION COMPLETED');
548
585
  console.log('='.repeat(70) + '\n');
549
- }, 5000);
586
+ }, 100);
550
587
  }
551
- function demonstrateWithTemplateMethod() {
552
- const numbers = [1, 2, 3];
553
- const visualizableArray = numbers.map(n => new VisualizableNumber(n));
554
- const runner = new LoggingVisualizationRunner();
555
- runner.run(visualizableArray, StrategyType.TIMEOUT_FOREACH);
588
+ async function demonstrateWithTemplateMethod() {
589
+ const numbers = [5, 2, 8, 1, 9];
590
+ const sortableArray = numbers.map(n => new SortableNumber(n));
591
+ const runner = new LoggingSortingRunner();
592
+ const sortedArray = await runner.run(sortableArray, StrategyType.DEFAULT);
593
+ console.log(`\nāœ… Template Method result: [${sortedArray.map(x => x.getValue()).join(', ')}]`);
556
594
  }
557
- function demonstrateWithCustomConfig() {
558
- const numbers = [100, 200, 300];
559
- const visualizableArray = numbers.map(n => new VisualizableNumber(n));
595
+ async function demonstrateWithCustomConfig() {
596
+ const numbers = [10, 5, 15, 3, 20];
597
+ const sortableArray = numbers.map(n => new SortableNumber(n));
560
598
  const invoker = new CommandInvoker();
561
599
  const configCommand = new UpdateConfigCommand({
562
- logPrefix: '[TIMEOUT_FOREACH FRAMEWORK] ',
600
+ logPrefix: '[SLEEP SORT] ',
563
601
  showTimestamps: true
564
602
  });
565
603
  invoker.enqueueCommand(configCommand);
566
- const factory = new ConcreteVisualizationStrategyFactory();
567
- const strategy = factory.createStrategy(StrategyType.TIMEOUT_FOREACH);
568
- const visualizer = new VisualizerBuilder()
569
- .setArray(visualizableArray)
604
+ const factory = new ConcreteSortingStrategyFactory();
605
+ const strategy = factory.createStrategy(StrategyType.DEFAULT);
606
+ const sorter = new SorterBuilder()
607
+ .setArray(sortableArray)
570
608
  .setStrategy(strategy)
571
609
  .build();
572
- const visualizationCommand = new ExecuteVisualizationCommand(visualizer);
573
- invoker.enqueueCommand(visualizationCommand);
574
- invoker.executeAll();
610
+ const sortingCommand = new ExecuteSortingCommand(sorter);
611
+ invoker.enqueueCommand(sortingCommand);
612
+ const results = await invoker.executeAll();
613
+ const sortedArray = results[1];
614
+ console.log(`\nāœ… Custom config result: [${sortedArray.map(x => x.getValue()).join(', ')}]`);
575
615
  }
576
- console.log('\n Starting demonstration...\n');
577
- demonstrateVisualization();
616
+ console.log('\nšŸŽ¬ Starting demonstration...\n');
617
+ demonstrateSorting();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "the-best-sort",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
4
  "description": "Sorting framework basid on best design patterns with the most powerful sort strategies in TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,13 +39,13 @@
39
39
  "bugs": {
40
40
  "url": "https://github.com/danilasar/the-best-sort/issues"
41
41
  },
42
- "homepage": "https://github.com/danilasar/the-best-sort#readme",
42
+ "homepage": "https://sort.danilasar.ru",
43
43
  "engines": {
44
44
  "node": ">=18.0.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^20.10.0",
48
- "typescript": "^5.3.0",
49
- "tsx": "^4.20.6"
48
+ "tsx": "^4.20.6",
49
+ "typescript": "^5.3.0"
50
50
  }
51
51
  }