@wxn0brp/falcon-frame-plugin 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# FalconFrame Plugin System
|
|
2
|
+
|
|
3
|
+
A flexible plugin system for the **FalconFrame** framework, allowing developers to register, sort, and execute plugins in a specific order based on dependencies.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The **FalconFrame Plugin System** provides a robust way to manage plugins for FalconFrame applications. It supports dependency management using `before` and `after` constraints, ensuring that plugins are executed in the correct order. The system uses a **topological sort** algorithm to handle complex dependency chains and detect circular dependencies.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @wxn0brp/falcon-frame-plugin
|
|
13
|
+
# and FalconFrame if not already installed
|
|
14
|
+
npm install @wxn0brp/falcon-frame
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
* **Plugin Registration** – Register plugins with optional dependency constraints.
|
|
20
|
+
* **Dependency Management** – Specify `before` and `after` relationships between plugins.
|
|
21
|
+
* **Automatic Sorting** – Plugins are automatically ordered based on dependencies.
|
|
22
|
+
* **Circular Dependency Detection** – Throws errors when circular dependencies are detected.
|
|
23
|
+
* **Route Handler Integration** – Seamless integration with FalconFrame's routing system.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Basic Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { PluginSystem } from "@wxn0brp/falcon-frame-plugin";
|
|
31
|
+
import { FalconFrame } from "@wxn0brp/falcon-frame";
|
|
32
|
+
|
|
33
|
+
const app = new FalconFrame();
|
|
34
|
+
const pluginSystem = new PluginSystem();
|
|
35
|
+
|
|
36
|
+
// Register a plugin
|
|
37
|
+
pluginSystem.register({
|
|
38
|
+
id: "my-plugin",
|
|
39
|
+
process: (req, res, next) => {
|
|
40
|
+
console.log("Executing my plugin");
|
|
41
|
+
next();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Register multiple plugins
|
|
46
|
+
app.use(pluginSystem);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Plugin with Dependencies
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
pluginSystem.register({
|
|
53
|
+
id: "auth-plugin",
|
|
54
|
+
process: (req, res, next) => {
|
|
55
|
+
// Authentication logic
|
|
56
|
+
next();
|
|
57
|
+
},
|
|
58
|
+
before: "data-plugin" // Runs before "data-plugin"
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
pluginSystem.register({
|
|
62
|
+
id: "data-plugin",
|
|
63
|
+
process: (req, res, next) => {
|
|
64
|
+
// Data processing logic
|
|
65
|
+
next();
|
|
66
|
+
},
|
|
67
|
+
after: "auth-plugin" // Runs after "auth-plugin"
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Plugin Interface
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
interface Plugin {
|
|
75
|
+
id: string; // Unique identifier for the plugin
|
|
76
|
+
process: RouteHandler; // Function executed when the plugin runs
|
|
77
|
+
before?: string | string[]; // Plugin(s) that should run after this one
|
|
78
|
+
after?: string | string[]; // Plugin(s) that should run before this one
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API
|
|
83
|
+
|
|
84
|
+
### `PluginSystem.register(plugin: Plugin, opts?: PSOpts)`
|
|
85
|
+
|
|
86
|
+
Registers a plugin with the system. If `opts.after` or `opts.before` are provided, they will define the execution order. Plugins are re-sorted automatically after registration.
|
|
87
|
+
|
|
88
|
+
### `PluginSystem.getRouteHandler(): RouteHandler`
|
|
89
|
+
|
|
90
|
+
Returns a **RouteHandler** that executes all registered plugins in the correct order. It will sort the plugins if they haven’t been sorted yet, then execute them recursively.
|
|
91
|
+
|
|
92
|
+
## Sorting Algorithm
|
|
93
|
+
|
|
94
|
+
The system uses a **topological sort** to:
|
|
95
|
+
|
|
96
|
+
* Detect circular dependencies and throw errors
|
|
97
|
+
* Ensure correct execution order based on dependencies
|
|
98
|
+
* Prevent duplicate plugin IDs
|
|
99
|
+
|
|
100
|
+
## Contributing
|
|
101
|
+
|
|
102
|
+
Contributions are welcome! Please open an issue or pull request for bug reports, feature requests, or improvements.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT License – see the [LICENSE](LICENSE) file for details.
|
package/package.json
CHANGED